|
|
80913e |
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
80913e |
From: Daniel Axtens <dja@axtens.net>
|
|
|
80913e |
Date: Mon, 18 Jan 2021 14:34:58 +1100
|
|
|
80913e |
Subject: [PATCH] fs/sfs: Fix over-read of root object name
|
|
|
80913e |
|
|
|
80913e |
There's a read of the name of the root object that assumes that the name
|
|
|
80913e |
is nul-terminated within the root block. This isn't guaranteed - it seems
|
|
|
80913e |
SFS would require you to read multiple blocks to get a full name in general,
|
|
|
80913e |
but maybe that doesn't apply to the root object.
|
|
|
80913e |
|
|
|
80913e |
Either way, figure out how much space is left in the root block and don't
|
|
|
80913e |
over-read it. This fixes some OOB reads.
|
|
|
80913e |
|
|
|
80913e |
Signed-off-by: Daniel Axtens <dja@axtens.net>
|
|
|
80913e |
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
|
|
|
80913e |
---
|
|
|
80913e |
grub-core/fs/sfs.c | 9 ++++++++-
|
|
|
80913e |
1 file changed, 8 insertions(+), 1 deletion(-)
|
|
|
80913e |
|
|
|
80913e |
diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c
|
|
|
80913e |
index 3ddc6b5e287..61d6c303cb3 100644
|
|
|
80913e |
--- a/grub-core/fs/sfs.c
|
|
|
80913e |
+++ b/grub-core/fs/sfs.c
|
|
|
80913e |
@@ -373,6 +373,7 @@ grub_sfs_mount (grub_disk_t disk)
|
|
|
80913e |
struct grub_sfs_objc *rootobjc;
|
|
|
80913e |
char *rootobjc_data = 0;
|
|
|
80913e |
grub_uint32_t blk;
|
|
|
80913e |
+ unsigned int max_len;
|
|
|
80913e |
|
|
|
80913e |
data = grub_malloc (sizeof (*data));
|
|
|
80913e |
if (!data)
|
|
|
80913e |
@@ -421,7 +422,13 @@ grub_sfs_mount (grub_disk_t disk)
|
|
|
80913e |
data->diropen.data = data;
|
|
|
80913e |
data->diropen.cache = 0;
|
|
|
80913e |
data->disk = disk;
|
|
|
80913e |
- data->label = grub_strdup ((char *) (rootobjc->objects[0].filename));
|
|
|
80913e |
+
|
|
|
80913e |
+ /* We only read 1 block of data, so truncate the name if needed. */
|
|
|
80913e |
+ max_len = ((GRUB_DISK_SECTOR_SIZE << data->log_blocksize)
|
|
|
80913e |
+ - 24 /* offsetof (struct grub_sfs_objc, objects) */
|
|
|
80913e |
+ - 25); /* offsetof (struct grub_sfs_obj, filename) */
|
|
|
80913e |
+ data->label = grub_zalloc (max_len + 1);
|
|
|
80913e |
+ grub_strncpy (data->label, (char *) rootobjc->objects[0].filename, max_len);
|
|
|
80913e |
|
|
|
80913e |
grub_free (rootobjc_data);
|
|
|
80913e |
return data;
|