ask-password: prevent buffer overflow when reading from keyring
authorMichael Biebl <biebl@debian.org>
Thu, 27 Jun 2019 13:02:40 +0000 (15:02 +0200)
committerMichael Biebl <biebl@debian.org>
Mon, 27 Apr 2020 17:02:57 +0000 (18:02 +0100)
When we read from keyring, a temporary buffer is allocated in order to
determine the size needed for the entire data. However, when zeroing that area,
we use the data size returned by the read instead of the lesser size allocate
for the buffer.

That will cause memory corruption that causes systemd-cryptsetup to crash
either when a single large password is used or when multiple passwords have
already been pushed to the keyring.

Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
(cherry picked from commit 59c55e73eaee345e1ee67c23eace8895ed499693)

Gbp-Pq: Name ask-password-prevent-buffer-overflow-when-reading-from-ke.patch

src/shared/ask-password-api.c

index 072bf72c5697b31545925a1babf8fd22c896dd2b..97a800f13270d367ed1ba52bff106af64d4a6733 100644 (file)
@@ -81,7 +81,7 @@ static int retrieve_key(key_serial_t serial, char ***ret) {
                 if (n < m)
                         break;
 
-                explicit_bzero_safe(p, n);
+                explicit_bzero_safe(p, m);
                 free(p);
                 m *= 2;
         }