Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1294346 > unrolled thread
| Started by | David Howells <dhowells@redhat.com> |
|---|---|
| First post | 2015-12-18 01:10 +0100 |
| Last post | 2015-12-18 01:10 +0100 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 0/5] X.509: Fix time handling David Howells <dhowells@redhat.com> - 2015-12-18 01:10 +0100
[PATCH 4/5] Handle both ISO 8601 encodings of midnight in mktime64() David Howells <dhowells@redhat.com> - 2015-12-18 01:10 +0100
Re: [PATCH 4/5] Handle both ISO 8601 encodings of midnight in mktime64() Arnd Bergmann <arnd@arndb.de> - 2015-12-18 10:20 +0100
[PATCH 5/5] X.509: Handle midnight alternative notation in GeneralizedTime David Howells <dhowells@redhat.com> - 2015-12-18 01:10 +0100
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2015-12-18 01:10 +0100 |
| Subject | [PATCH 0/5] X.509: Fix time handling |
| Message-ID | <qGQMp-6FZ-3@gated-at.bofh.it> |
Here's a set of patches that fix X.509 time handling in three ways:
(1) Fix leap year handling.
(2) Add leap second handling (where you get a time of 23:59:60).
(3) Add end-of-day midnight encoding (where you get a time of 24:00:00).
David
---
David Howells (5):
X.509: Fix leap year handling again
Handle leap seconds in mktime64()
X.509: Support leap seconds
Handle both ISO 8601 encodings of midnight in mktime64()
X.509: Handle midnight alternative notation in GeneralizedTime
crypto/asymmetric_keys/x509_cert_parser.c | 24 +++++++++++++++++-------
include/linux/time.h | 13 ++++++-------
kernel/time/time.c | 19 +++++++++++++++----
3 files changed, 38 insertions(+), 18 deletions(-)
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2015-12-18 01:10 +0100 |
| Subject | [PATCH 4/5] Handle both ISO 8601 encodings of midnight in mktime64() |
| Message-ID | <qGQMp-6FZ-13@gated-at.bofh.it> |
| In reply to | #1294346 |
ISO 8601 format dates permit two different encodings of midnight - 00:00:00 and 24:00:00 - the first is midnight today and the second is midnight tomorrow and is exactly equivalent to the first with tomorrow's date. Note that the implementation of mktime64() doesn't actually need to be changed to handle this - the multiplication by 3600 of the hour will take care of it automatically. However, we should document that this handling is done in mktime64() and is thus in a common place in the kernel. This handling is required for X.509 certificate parsing which can be given ISO 8601 dates. Signed-off-by: David Howells <dhowells@redhat.com> cc: John Stultz <john.stultz@linaro.org> cc: Arnd Bergmann <arnd@arndb.de> cc: stable@vger.kernel.org --- kernel/time/time.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/kernel/time/time.c b/kernel/time/time.c index 1858b10602f5..56e7ada38471 100644 --- a/kernel/time/time.c +++ b/kernel/time/time.c @@ -326,6 +326,9 @@ EXPORT_SYMBOL(timespec_trunc); * A leap second can be indicated by calling this function with sec as * 60 (allowable under ISO 8601). The leap second is treated the same * as the preceding second since they don't exist in UNIX time. + * + * An encoding of midnight at the end of the day as 24:00:00 - ie. midnight + * tomorrow - (allowable under ISO 8601) is supported. */ time64_t mktime64(unsigned int year0, unsigned int mon0, unsigned int day, unsigned int hour, @@ -346,7 +349,7 @@ time64_t mktime64(unsigned int year0, unsigned int mon0, return ((((time64_t) (year/4 - year/100 + year/400 + 367*mon/12 + day) + year*365 - 719499 - )*24 + hour /* now have hours */ + )*24 + hour /* now have hours - midnight tomorrow handled here */ )*60 + min /* now have minutes */ )*60 + sec; /* finally seconds */ } -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | Arnd Bergmann <arnd@arndb.de> |
|---|---|
| Date | 2015-12-18 10:20 +0100 |
| Subject | Re: [PATCH 4/5] Handle both ISO 8601 encodings of midnight in mktime64() |
| Message-ID | <qGZmI-3IZ-47@gated-at.bofh.it> |
| In reply to | #1294347 |
On Friday 18 December 2015 00:02:17 David Howells wrote: > ISO 8601 format dates permit two different encodings of midnight - 00:00:00 > and 24:00:00 - the first is midnight today and the second is midnight > tomorrow and is exactly equivalent to the first with tomorrow's date. > > Note that the implementation of mktime64() doesn't actually need to be > changed to handle this - the multiplication by 3600 of the hour will take > care of it automatically. However, we should document that this handling > is done in mktime64() and is thus in a common place in the kernel. > > This handling is required for X.509 certificate parsing which can be given > ISO 8601 dates. > > Signed-off-by: David Howells <dhowells@redhat.com> > cc: John Stultz <john.stultz@linaro.org> > cc: Arnd Bergmann <arnd@arndb.de> > cc: stable@vger.kernel.org > Acked-by: Arnd Bergmann <arnd@arndb.de> -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | David Howells <dhowells@redhat.com> |
|---|---|
| Date | 2015-12-18 01:10 +0100 |
| Subject | [PATCH 5/5] X.509: Handle midnight alternative notation in GeneralizedTime |
| Message-ID | <qGQMq-6FZ-17@gated-at.bofh.it> |
| In reply to | #1294346 |
The ASN.1 GeneralizedTime object carries an ISO8601 format date and time.
The time is permitted to show midnight as 00:00 or 24:00 (the latter being
equivalent of 00:00 of the following day).
The permitted value is checked in x509_decode_time() but the actual
handling is left to mktime64().
Without this patch, certain X.509 certificates will be rejected and could
lead to an unbootable kernel.
Reported-by: Rudolf Polzer <rpolzer@google.com>
Signed-off-by: David Howells <dhowells@redhat.com>
cc: David Woodhouse <David.Woodhouse@intel.com>
cc: John Stultz <john.stultz@linaro.org>
cc: Arnd Bergmann <arnd@arndb.de>
cc: stable@vger.kernel.org
---
crypto/asymmetric_keys/x509_cert_parser.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/crypto/asymmetric_keys/x509_cert_parser.c b/crypto/asymmetric_keys/x509_cert_parser.c
index 9be2caebc57b..b9de251c419c 100644
--- a/crypto/asymmetric_keys/x509_cert_parser.c
+++ b/crypto/asymmetric_keys/x509_cert_parser.c
@@ -497,7 +497,7 @@ int x509_decode_time(time64_t *_t, size_t hdrlen,
static const unsigned char month_lengths[] = { 31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31 };
const unsigned char *p = value;
- unsigned year, mon, day, hour, min, sec, mon_len, max_sec;
+ unsigned year, mon, day, hour, min, sec, mon_len, max_sec, max_hour;
#define dec2bin(X) ({ unsigned char x = (X) - '0'; if (x > 9) goto invalid_time; x; })
#define DD2bin(P) ({ unsigned x = dec2bin(P[0]) * 10 + dec2bin(P[1]); P += 2; x; })
@@ -512,6 +512,7 @@ int x509_decode_time(time64_t *_t, size_t hdrlen,
else
year += 2000;
max_sec = 59;
+ max_hour = 23;
} else if (tag == ASN1_GENTIM) {
/* GenTime: YYYYMMDDHHMMSSZ */
if (vlen != 15)
@@ -520,6 +521,7 @@ int x509_decode_time(time64_t *_t, size_t hdrlen,
if (year >= 1950 && year <= 2049)
goto invalid_time;
max_sec = 60; /* ISO 8601 permits leap seconds [X.680 46.3] */
+ max_hour = 24;
} else {
goto unsupported_time;
}
@@ -550,11 +552,17 @@ int x509_decode_time(time64_t *_t, size_t hdrlen,
}
if (day < 1 || day > mon_len ||
- hour > 23 ||
+ hour > max_hour ||
min > 59 ||
sec > max_sec)
goto invalid_time;
+ /* GeneralizedTime, encoded as ISO 8601, also permits 24:00 today as an
+ * alternative for 00:00 tomorrow.
+ */
+ if (hour == 24 && (min != 0 || sec != 0))
+ goto invalid_time;
+
*_t = mktime64(year, mon, day, hour, min, sec);
return 0;
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web