Skip to content

Commit 7b3d341

Browse files
committed
grub: add patches
Signed-off-by: Jingwei Wang <jweiw@amazon.com>
1 parent ebbd8b6 commit 7b3d341

56 files changed

Lines changed: 5519 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From 90349c56c909fcbc250cc780f2db39c66f5254f8 Mon Sep 17 00:00:00 2001
2+
From: B Horn <b@horn.uk>
3+
Date: Sun, 12 May 2024 02:47:54 +0100
4+
Subject: [PATCH] fs/tar: Initialize name in grub_cpio_find_file()
5+
6+
It was possible to iterate through grub_cpio_find_file() without
7+
allocating name and not setting mode to GRUB_ARCHELP_ATTR_END, which
8+
would cause the uninitialized value for name to be used as an argument
9+
for canonicalize() in grub_archelp_dir().
10+
11+
Reported-by: B Horn <b@horn.uk>
12+
Signed-off-by: B Horn <b@horn.uk>
13+
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14+
---
15+
grub-core/fs/tar.c | 8 +++++++-
16+
1 file changed, 7 insertions(+), 1 deletion(-)
17+
18+
diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c
19+
index 63fda1c..898544c 100644
20+
--- a/grub-core/fs/tar.c
21+
+++ b/grub-core/fs/tar.c
22+
@@ -80,10 +80,12 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
23+
grub_size_t sz;
24+
25+
data->hofs = data->next_hofs;
26+
+ *name = NULL;
27+
28+
for (reread = 0; reread < 3; reread++)
29+
{
30+
- if (grub_disk_read (data->disk, 0, data->hofs, sizeof (hd), &hd))
31+
+ if (grub_cpio_find_file (struct grub_archelp_data *data, char
32+
+**name, sizeof (hd), &hd))
33+
return grub_errno;
34+
35+
if (!hd.name[0] && !hd.prefix[0])
36+
@@ -224,6 +226,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
37+
}
38+
return GRUB_ERR_NONE;
39+
}
40+
+
41+
+ if (*name == NULL)
42+
+ return grub_error (GRUB_ERR_BAD_FS, "invalid tar archive");
43+
+
44+
return GRUB_ERR_NONE;
45+
}
46+
47+
--
48+
2.47.0
49+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: B Horn <b@horn.uk>
3+
Date: Sun, 12 May 2024 06:15:03 +0100
4+
Subject: [PATCH] fs/f2fs: Set a grub_errno if mount fails
5+
6+
It was previously possible for grub_errno to not be set when
7+
grub_f2fs_mount() failed if nat_bitmap_ptr() returned NULL.
8+
9+
This issue is solved by ensuring a grub_errno is set in the fail case.
10+
11+
Reported-by: B Horn <b@horn.uk>
12+
Signed-off-by: B Horn <b@horn.uk>
13+
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
14+
---
15+
grub-core/fs/f2fs.c | 3 +++
16+
1 file changed, 3 insertions(+)
17+
18+
diff --git a/grub-core/fs/f2fs.c b/grub-core/fs/f2fs.c
19+
index df6beb544..f7daa9435 100644
20+
--- a/grub-core/fs/f2fs.c
21+
+++ b/grub-core/fs/f2fs.c
22+
@@ -872,6 +872,9 @@ grub_f2fs_mount (grub_disk_t disk)
23+
return data;
24+
25+
fail:
26+
+ if (grub_errno == GRUB_ERR_NONE)
27+
+ grub_error (GRUB_ERR_BAD_FS, "not a F2FS filesystem");
28+
+
29+
grub_free (data);
30+
31+
return NULL;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: B Horn <b@horn.uk>
3+
Date: Sun, 12 May 2024 06:37:08 +0100
4+
Subject: [PATCH] fs/iso9660: Set a grub_errno if mount fails
5+
6+
It was possible for a grub_errno to not be set if mount of an ISO 9660
7+
filesystem failed when set_rockridge() returned 0.
8+
9+
This isn't known to be exploitable as the other filesystems due to
10+
filesystem helper checking the requested file type. Though fixing
11+
as a precaution.
12+
13+
Reported-by: B Horn <b@horn.uk>
14+
Signed-off-by: B Horn <b@horn.uk>
15+
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
16+
---
17+
grub-core/fs/iso9660.c | 3 +++
18+
1 file changed, 3 insertions(+)
19+
20+
diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c
21+
index ac011950a..82cf1a271 100644
22+
--- a/grub-core/fs/iso9660.c
23+
+++ b/grub-core/fs/iso9660.c
24+
@@ -491,6 +491,9 @@ grub_iso9660_mount (grub_disk_t disk)
25+
return data;
26+
27+
fail:
28+
+ if (grub_errno == GRUB_ERR_NONE)
29+
+ grub_error (GRUB_ERR_BAD_FS, "not a ISO9660 filesystem");
30+
+
31+
grub_free (data);
32+
return 0;
33+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Michael Chang <mchang@suse.com>
3+
Date: Fri, 31 May 2024 15:14:42 +0800
4+
Subject: [PATCH] fs/iso9660: Fix invalid free
5+
6+
The ctx->filename can point to either a string literal or a dynamically
7+
allocated string. The ctx->filename_alloc field is used to indicate the
8+
type of allocation.
9+
10+
An issue has been identified where ctx->filename is reassigned to
11+
a string literal in susp_iterate_dir() but ctx->filename_alloc is not
12+
correctly handled. This oversight causes a memory leak and an invalid
13+
free operation later.
14+
15+
The fix involves checking ctx->filename_alloc, freeing the allocated
16+
string if necessary and clearing ctx->filename_alloc for string literals.
17+
18+
Reported-by: Daniel Axtens <dja@axtens.net>
19+
Signed-off-by: Michael Chang <mchang@suse.com>
20+
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
21+
---
22+
grub-core/fs/iso9660.c | 14 ++++++++++++--
23+
1 file changed, 12 insertions(+), 2 deletions(-)
24+
25+
diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c
26+
index 82cf1a271..7a59a65a5 100644
27+
--- a/grub-core/fs/iso9660.c
28+
+++ b/grub-core/fs/iso9660.c
29+
@@ -568,9 +568,19 @@ susp_iterate_dir (struct grub_iso9660_susp_entry *entry,
30+
filename type is stored. */
31+
/* FIXME: Fix this slightly improper cast. */
32+
if (entry->data[0] & GRUB_ISO9660_RR_DOT)
33+
- ctx->filename = (char *) ".";
34+
+ {
35+
+ if (ctx->filename_alloc)
36+
+ grub_free (ctx->filename);
37+
+ ctx->filename_alloc = 0;
38+
+ ctx->filename = (char *) ".";
39+
+ }
40+
else if (entry->data[0] & GRUB_ISO9660_RR_DOTDOT)
41+
- ctx->filename = (char *) "..";
42+
+ {
43+
+ if (ctx->filename_alloc)
44+
+ grub_free (ctx->filename);
45+
+ ctx->filename_alloc = 0;
46+
+ ctx->filename = (char *) "..";
47+
+ }
48+
else if (entry->len >= 5)
49+
{
50+
grub_size_t off = 0, csize = 1;
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Lidong Chen <lidong.chen@oracle.com>
3+
Date: Fri, 22 Nov 2024 06:27:59 +0000
4+
Subject: [PATCH] fs/jfs: Fix OOB read in jfs_getent()
5+
6+
The JFS fuzzing revealed an OOB read in grub_jfs_getent(). The crash
7+
was caused by an invalid leaf nodes count, diro->dirpage->header.count,
8+
which was larger than the maximum number of leaf nodes allowed in an
9+
inode. This fix is to ensure that the leaf nodes count is validated in
10+
grub_jfs_opendir() before calling grub_jfs_getent().
11+
12+
On the occasion replace existing raw numbers with newly defined constant.
13+
14+
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
15+
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
16+
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
17+
---
18+
grub-core/fs/jfs.c | 17 +++++++++++++++--
19+
1 file changed, 15 insertions(+), 2 deletions(-)
20+
21+
diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c
22+
index 6f7c43904..32dec7fb7 100644
23+
--- a/grub-core/fs/jfs.c
24+
+++ b/grub-core/fs/jfs.c
25+
@@ -41,6 +41,12 @@ GRUB_MOD_LICENSE ("GPLv3+");
26+
27+
#define GRUB_JFS_TREE_LEAF 2
28+
29+
+/*
30+
+ * Define max entries stored in-line in an inode.
31+
+ * https://jfs.sourceforge.net/project/pub/jfslayout.pdf
32+
+ */
33+
+#define GRUB_JFS_INODE_INLINE_ENTRIES 8
34+
+
35+
struct grub_jfs_sblock
36+
{
37+
/* The magic for JFS. It should contain the string "JFS1". */
38+
@@ -203,9 +209,9 @@ struct grub_jfs_inode
39+
grub_uint8_t freecnt;
40+
grub_uint8_t freelist;
41+
grub_uint32_t idotdot;
42+
- grub_uint8_t sorted[8];
43+
+ grub_uint8_t sorted[GRUB_JFS_INODE_INLINE_ENTRIES];
44+
} header;
45+
- struct grub_jfs_leaf_dirent dirents[8];
46+
+ struct grub_jfs_leaf_dirent dirents[GRUB_JFS_INODE_INLINE_ENTRIES];
47+
} GRUB_PACKED dir;
48+
/* Fast symlink. */
49+
struct
50+
@@ -453,6 +459,13 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
51+
/* Check if the entire tree is contained within the inode. */
52+
if (inode->file.tree.flags & GRUB_JFS_TREE_LEAF)
53+
{
54+
+ if (inode->dir.header.count > GRUB_JFS_INODE_INLINE_ENTRIES)
55+
+ {
56+
+ grub_free (diro);
57+
+ grub_error (GRUB_ERR_BAD_FS, N_("invalid JFS inode"));
58+
+ return 0;
59+
+ }
60+
+
61+
diro->leaf = inode->dir.dirents;
62+
diro->next_leaf = (struct grub_jfs_leaf_next_dirent *) de;
63+
diro->sorted = inode->dir.header.sorted;
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Lidong Chen <lidong.chen@oracle.com>
3+
Date: Fri, 22 Nov 2024 06:28:00 +0000
4+
Subject: [PATCH] fs/jfs: Fix OOB read caused by invalid dir slot index
5+
6+
While fuzz testing JFS with ASAN enabled an OOB read was detected in
7+
grub_jfs_opendir(). The issue occurred due to an invalid directory slot
8+
index in the first entry of the sorted directory slot array in the inode
9+
directory header. The fix ensures the slot index is validated before
10+
accessing it. Given that an internal or a leaf node in a directory B+
11+
tree is a 4 KiB in size and each directory slot is always 32 bytes, the
12+
max number of slots in a node is 128. The validation ensures that the
13+
slot index doesn't exceed this limit.
14+
15+
[1] https://jfs.sourceforge.net/project/pub/jfslayout.pdf
16+
17+
JFS will allocate 4K of disk space for an internal node of the B+ tree.
18+
An internal node looks the same as a leaf node.
19+
- page 10
20+
21+
Fixed number of Directory Slots depending on the size of the node. These are
22+
the slots to be used for storing the directory slot array and the directory
23+
entries or router entries. A directory slot is always 32 bytes.
24+
...
25+
A Directory Slot Array which is a sorted array of indices to the directory
26+
slots that are currently in use.
27+
...
28+
An internal or a leaf node in the directory B+ tree is a 4K page.
29+
- page 25
30+
31+
Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
32+
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
33+
Reviewed-by: Alec Brown <alec.r.brown@oracle.com>
34+
---
35+
grub-core/fs/jfs.c | 9 +++++++++
36+
1 file changed, 9 insertions(+)
37+
38+
diff --git a/grub-core/fs/jfs.c b/grub-core/fs/jfs.c
39+
index 32dec7fb7..88fb884df 100644
40+
--- a/grub-core/fs/jfs.c
41+
+++ b/grub-core/fs/jfs.c
42+
@@ -46,6 +46,7 @@ GRUB_MOD_LICENSE ("GPLv3+");
43+
* https://jfs.sourceforge.net/project/pub/jfslayout.pdf
44+
*/
45+
#define GRUB_JFS_INODE_INLINE_ENTRIES 8
46+
+#define GRUB_JFS_DIR_MAX_SLOTS 128
47+
48+
struct grub_jfs_sblock
49+
{
50+
@@ -481,6 +482,14 @@ grub_jfs_opendir (struct grub_jfs_data *data, struct grub_jfs_inode *inode)
51+
return 0;
52+
}
53+
54+
+ if (inode->dir.header.sorted[0] >= GRUB_JFS_DIR_MAX_SLOTS)
55+
+ {
56+
+ grub_error (GRUB_ERR_BAD_FS, N_("invalid directory slot index"));
57+
+ grub_free (diro->dirpage);
58+
+ grub_free (diro);
59+
+ return 0;
60+
+ }
61+
+
62+
blk = grub_le_to_cpu32 (de[inode->dir.header.sorted[0]].ex.blk2);
63+
blk <<= (grub_le_to_cpu16 (data->sblock.log2_blksz) - GRUB_DISK_SECTOR_BITS);
64+

0 commit comments

Comments
 (0)