]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
boot: do not truncate random seed file
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 16 Nov 2022 18:34:53 +0000 (19:34 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 17 Nov 2022 11:22:32 +0000 (12:22 +0100)
There are concerns about the FAT file system driver exploding if we try
to do this, so just leave the bytes zeroed out instead.

src/boot/efi/random-seed.c

index 02f4dfbc7f3f7e45369b7577373a9283aa4f1355..e6a317860d8bacd819933a19d647a11524749d23 100644 (file)
@@ -263,7 +263,7 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
         sha256_finish_ctx(&hash, random_bytes);
 
         size = sizeof(random_bytes);
-        /* If the file size is too large, zero out the remaining bytes on disk, and then truncate. */
+        /* If the file size is too large, zero out the remaining bytes on disk. */
         if (size < info->FileSize) {
                 err = handle->SetPosition(handle, size);
                 if (err != EFI_SUCCESS)
@@ -280,10 +280,17 @@ EFI_STATUS process_random_seed(EFI_FILE *root_dir, RandomSeedMode mode) {
                 err = handle->SetPosition(handle, 0);
                 if (err != EFI_SUCCESS)
                         return log_error_status_stall(err, L"Failed to seek to beginning of random seed file: %r", err);
-                info->FileSize = size;
-                err = handle->SetInfo(handle, &GenericFileInfo, info->Size, info);
-                if (err != EFI_SUCCESS)
-                        return log_error_status_stall(err, L"Failed to truncate random seed file: %r", err);
+
+                /* We could truncate the file here with something like:
+                 *
+                 *     info->FileSize = size;
+                 *     err = handle->SetInfo(handle, &GenericFileInfo, info->Size, info);
+                 *     if (err != EFI_SUCCESS)
+                 *             return log_error_status_stall(err, L"Failed to truncate random seed file: %r", err);
+                 *
+                 * But this is considered slightly risky, because EFI filesystem drivers are a little bit
+                 * flimsy. So instead we rely on userspace eventually truncating this when it writes a new
+                 * seed. For now the best we do is zero it. */
         }
         /* Update the random seed on disk before we use it */
         wsize = size;