fs/ntfs: Correct NULL Deref / Possible Infinite Loop
PATCH v3 1/1 fs/ntfs: Correct NULL Deref / Possible Infinite Loop
A regression was introduced recently as a part of the series of filesystem related patches to address some CVEs found in GRUB.
This issue may cause either an infinite loop at startup when accessing certain valid NTFS file systems, or may cause a crash due to a NULL pointer deference on systems where "NULL" address is invalid (such as may happen when calling grub-mount from the operating system level).
Correct this issue by checking that at->attr_cur is within bounds inside find_attr.
---
V2 -> V3: Changed NULL check to >= at->mft->buf
grub-core/fs/ntfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
grub-core/fs/ntfs.c +2 -1
@@ -387,7 +387,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) } at->attr_cur = at->attr_nxt; mft_end = at->mft->buf + (at->mft->data->mft_size <<GRUB_NTFS_BLK_SHR ); -while (at->attr_cur < mft_end && *at->attr_cur !=0xFF ) +while (at->attr_cur >= at->mft->buf && at->attr_cur < mft_end + && *at->attr_cur !=0xFF ) { at->attr_nxt =next_attribute (at->attr_cur, at->end);if (*at->attr_cur ==GRUB_NTFS_AT_ATTRIBUTE_LIST )
Signature · 7 lines
2.39.5 _______________________________________________ Grub-devel mailing list [email protected] https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 9 lines · Andrew Hamilton
A regression was introduced recently as a part of the series of filesystem related patches to address some CVEs found in GRUB.
This issue may cause either an infinite loop at startup when accessing certain valid NTFS file systems, or may cause a crash due to a NULL pointer deference on systems where "NULL" address is invalid (such as may happen when calling grub-mount from the operating system level).
Quoted 8 lines
Correct this issue by checking that
at->attr_curis within bounds insidefind_attr.Co-authored-by B Horn <[email protected]>Co-authored-by Andrew Hamilton <[email protected]>Signed-off-by Andrew Hamilton <[email protected]>
Daniel
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 38 lines · Andrew Hamilton
A regression was introduced recently as a part of the series of filesystem related patches to address some CVEs found in GRUB.
This issue may cause either an infinite loop at startup when accessing certain valid NTFS file systems, or may cause a crash due to a NULL pointer deference on systems where "NULL" address is invalid (such as may happen when calling grub-mount from the operating system level).
Correct this issue by checking that
at->attr_curis within bounds insidefind_attr.Co-authored-by B Horn <[email protected]>Co-authored-by Andrew Hamilton <[email protected]>Signed-off-by Andrew Hamilton <[email protected]>---
V2 -> V3: Changed NULL check to >=at->mft->bufgrub-core/fs/ntfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)grub-core/fs/ntfs.c +2
-1@@ -387,7 +387,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) } at->attr_cur = at->attr_nxt; mft_end = at->mft->buf + (at->mft->data->mft_size <<GRUB_NTFS_BLK_SHR ); -while (at->attr_cur < mft_end && *at->attr_cur !=0xFF ) +while (at->attr_cur >= at->mft->buf && at->attr_cur < mft_end + && *at->attr_cur !=0xFF ) { at->attr_nxt =next_attribute (at->attr_cur, at->end);if (*at->attr_cur == GRUB_NTFS_AT_ATTRIBUTE_LIST)
Quoted 4 lines
--
2.39.5
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 9 lines · On Thu, 20 Mar 2025 18:28:00 -0500 Andrew Hamilton <[email protected]> wrote:
A regression was introduced recently as a part of the series of filesystem related patches to address some CVEs found in GRUB.
This issue may cause either an infinite loop at startup when accessing certain valid NTFS file systems, or may cause a crash due to a NULL pointer deference on systems where "NULL" address is invalid (such as may happen when calling grub-mount from the operating system level).
Quoted 4 lines
Correct this issue by checking that
at->attr_curis within bounds insidefind_attr.
The NTFS filesystem test is failing even though this change is included. grub-fstest is failing to detect the generated NTFS filesystem as NTFS. The debug log shows these lines:
grub-core/kern/fs.c:56:fs: Detecting ntfs... grub-core/fs/ntfs.c:212:ntfs: spare=800 min_size=73 attr_size=72 grub-core/kern/fs.c:79:fs: error: no $INDEX_ROOT. grub-core/kern/fs.c:80:fs: ntfs detection failed.
Based on where this error message is generated, it looks like the issue is in find_attr(). So this change looks like a partial fix.
Glenn
Quoted 14 lines
Co-authored-by B Horn <[email protected]>Co-authored-by Andrew Hamilton <[email protected]>Signed-off-by Andrew Hamilton <[email protected]>---
V2 -> V3: Changed NULL check to >=at->mft->bufgrub-core/fs/ntfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)grub-core/fs/ntfs.c +0
-0
grub-core/fs/ntfs.c find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) · line 394
Quoted 9 lines
grub-core/fs/ntfs.c +2
-1@@ -387,7 +387,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr) } at->attr_cur = at->attr_nxt; mft_end = at->mft->buf + (at->mft->data->mft_size <<GRUB_NTFS_BLK_SHR ); -while (at->attr_cur < mft_end && *at->attr_cur !=0xFF ) +while (at->attr_cur >= at->mft->buf && at->attr_cur < mft_end + && *at->attr_cur !=0xFF ) { at->attr_nxt =next_attribute (at->attr_cur, at->end);if (*at->attr_cur ==GRUB_NTFS_AT_ATTRIBUTE_LIST )
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Hi Glenn,
This patch was focused on the most serious issue being seen by people where GRUB might hang during startup and grub-mount may crash.
There are remaining issues in NTFS, I saw the same failures you are seeing from the filesystem tests.
I have been working on fixing the rest of the grub-fstest failures, but it has turned out to be quite involved so it's taking some time. There are some issues in the validate_attribute function (like the run size calculation seems wrong) and also how validate_attribute is used in some places (I think it's being mixed between attributes and attribute-lists). It is complicated by trying to fix the regression while also trying to avoid reintroducing the fuzzing identified issues that were being fixed originally.
I'm still working at it, and intend to submit a new patch when I have it. Sorry for the slowness, it's something I try to do whenever I have some free time. If anyone is an NTFS expert I'd be more than happy to hand it off ;)
Thanks,
Andrew
Quoted 46 lines · Glenn Washburn
Quoted 9 lines · On Thu, 20 Mar 2025 18:28:00 -0500 Andrew Hamilton <[email protected]> wrote:
A regression was introduced recently as a part of the series of filesystem related patches to address some CVEs found in GRUB.
This issue may cause either an infinite loop at startup when accessing certain valid NTFS file systems, or may cause a crash due to a NULL pointer deference on systems where "NULL" address is invalid (such as may happen when calling grub-mount from the operating system level).
Quoted 4 lines
Correct this issue by checking that
at->attr_curis within bounds insidefind_attr.The NTFS filesystem test is failing even though this change is included. grub-fstest is failing to detect the generated NTFS filesystem as NTFS. The debug log shows these lines:
grub-core/kern/fs.c:56:fs: Detecting ntfs... grub-core/fs/ntfs.c:212:ntfs: spare=800 min_size=73 attr_size=72 grub-core/kern/fs.c:79:fs: error: no $INDEX_ROOT. grub-core/kern/fs.c:80:fs: ntfs detection failed.
Based on where this error message is generated, it looks like the issue is in
find_attr(). So this change looks like a partial fix.Glenn
grub-core/fs/ntfs.c find_attr (struct grub_ntfs_attr *at, grub_uint8_t
Quoted 14 lines
Co-authored-by B Horn <[email protected]>Co-authored-by Andrew Hamilton <[email protected]>Signed-off-by Andrew Hamilton <[email protected]>---
V2 -> V3: Changed NULL check to >=at->mft->bufgrub-core/fs/ntfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)grub-core/fs/ntfs.c +0
-0@@ -387,7 +387,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_tattr)
Quoted 11 lines
grub-core/fs/ntfs.c find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr)
Quoted 3 lines
grub-core/fs/ntfs.c +0
-0} at->attr_cur = at->attr_nxt; mft_end = at->mft->buf + (at->mft->data->mft_size <<
GRUB_NTFS_BLK_SHR);Quoted 6 lines
grub-core/fs/ntfs.c +2
-1-while (at->attr_cur < mft_end && *at->attr_cur !=0xFF ) +while (at->attr_cur >= at->mft->buf && at->attr_cur < mft_end + && *at->attr_cur !=0xFF ) { at->attr_nxt =next_attribute (at->attr_cur, at->end);if (*at->attr_cur ==GRUB_NTFS_AT_ATTRIBUTE_LIST )
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 17 lines · On Thu, 1 May 2025 19:24:33 -0500 Andrew Hamilton <[email protected]> wrote:
Hi Glenn,
This patch was focused on the most serious issue being seen by people where GRUB might hang during startup and grub-mount may crash.
There are remaining issues in NTFS, I saw the same failures you are seeing from the filesystem tests.
I have been working on fixing the rest of the grub-fstest failures, but it has turned out to be quite involved so it's taking some time. There are some issues in the
validate_attributefunction (like the run size calculation seems wrong) and also howvalidate_attributeis used in some places (I think it's being mixed between attributes and attribute-lists). It is complicated by trying to fix the regression while also trying to avoid reintroducing the fuzzing identified issues that were being fixed originally.
Quoted 4 lines
I'm still working at it, and intend to submit a new patch when I have it. Sorry for the slowness, it's something I try to do whenever I have some free time. If anyone is an NTFS expert I'd be more than happy to hand it off ;)
Thanks for the clarification. My email was send to raise awareness, as I hadn't seen this issue being discussed on the list. Glad to know that this issue is known and being worked on. Much appreciated, carry on.
Glenn
Quoted 65 lines
Thanks,
Andrewkernel/printk/printk.cQuoted 57 lines · Glenn Washburn
Quoted 9 lines · On Thu, 20 Mar 2025 18:28:00 -0500 Andrew Hamilton <[email protected]> wrote:
A regression was introduced recently as a part of the series of filesystem related patches to address some CVEs found in GRUB.
This issue may cause either an infinite loop at startup when accessing certain valid NTFS file systems, or may cause a crash due to a NULL pointer deference on systems where "NULL" address is invalid (such as may happen when calling grub-mount from the operating system level).
Quoted 4 lines
Correct this issue by checking that
at->attr_curis within bounds insidefind_attr.The NTFS filesystem test is failing even though this change is included. grub-fstest is failing to detect the generated NTFS filesystem as NTFS. The debug log shows these lines:
grub-core/kern/fs.c:56:fs: Detecting ntfs... grub-core/fs/ntfs.c:212:ntfs: spare=800 min_size=73 attr_size=72 grub-core/kern/fs.c:79:fs: error: no $INDEX_ROOT. grub-core/kern/fs.c:80:fs: ntfs detection failed.
Based on where this error message is generated, it looks like the issue is in
find_attr(). So this change looks like a partial fix.Glenn
grub-core/fs/ntfs.c find_attr (struct grub_ntfs_attr *at, grub_uint8_t
Quoted 14 lines
Co-authored-by B Horn <[email protected]>Co-authored-by Andrew Hamilton <[email protected]>Signed-off-by Andrew Hamilton <[email protected]>---
V2 -> V3: Changed NULL check to >=at->mft->bufgrub-core/fs/ntfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)grub-core/fs/ntfs.c +0
-0@@ -387,7 +387,8 @@ find_attr (struct grub_ntfs_attr *at, grub_uint8_tattr)
grub-core/fs/ntfs.c find_attr (struct grub_ntfs_attr *at, grub_uint8_t attr)
Quoted 3 lines
grub-core/fs/ntfs.c +0
-0} at->attr_cur = at->attr_nxt; mft_end = at->mft->buf + (at->mft->data->mft_size <<
GRUB_NTFS_BLK_SHR);Quoted 6 lines
grub-core/fs/ntfs.c +2
-1-while (at->attr_cur < mft_end && *at->attr_cur !=0xFF ) +while (at->attr_cur >= at->mft->buf && at->attr_cur < mft_end + && *at->attr_cur !=0xFF ) { at->attr_nxt =next_attribute (at->attr_cur, at->end);if (*at->attr_cur ==GRUB_NTFS_AT_ATTRIBUTE_LIST )
_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel