From: David Howells <dhowells@redhat.com>
To: keyrings@vger.kernel.org
Cc: David Woodhouse <David.Woodhouse@intel.com>,
Arnd Bergmann <arnd@arndb.de>,
linux-kernel@vger.kernel.org, stable@vger.kernel.org,
dhowells@redhat.com, linux-security-module@vger.kernel.org,
Rudolf Polzer <rpolzer@google.com>,
John Stultz <john.stultz@linaro.org>
Subject: [PATCH 5/5] X.509: Handle midnight alternative notation in GeneralizedTime
Date: Fri, 18 Dec 2015 00:02:24 +0000 [thread overview]
Message-ID: <20151218000224.29483.61861.stgit@warthog.procyon.org.uk> (raw)
In-Reply-To: <20151218000148.29483.67155.stgit@warthog.procyon.org.uk>
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;
prev parent reply other threads:[~2015-12-18 0:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20151218000148.29483.67155.stgit@warthog.procyon.org.uk>
2015-12-18 0:01 ` [PATCH 1/5] X.509: Fix leap year handling again David Howells
2015-12-18 0:02 ` [PATCH 2/5] Handle leap seconds in mktime64() David Howells
2015-12-18 9:09 ` Arnd Bergmann
2015-12-18 0:02 ` [PATCH 3/5] X.509: Support leap seconds David Howells
2015-12-18 9:10 ` Arnd Bergmann
2015-12-18 0:02 ` [PATCH 4/5] Handle both ISO 8601 encodings of midnight in mktime64() David Howells
2015-12-18 9:11 ` Arnd Bergmann
2015-12-18 0:02 ` David Howells [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151218000224.29483.61861.stgit@warthog.procyon.org.uk \
--to=dhowells@redhat.com \
--cc=David.Woodhouse@intel.com \
--cc=arnd@arndb.de \
--cc=john.stultz@linaro.org \
--cc=keyrings@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=rpolzer@google.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox