Skip to content

Commit 29ace97

Browse files
committed
fs,hugetlb: fix NULL pointer dereference in hugetlbs_fill_super
jira LE-1907 cve {CVE-2024-0841 cve RHEL-20617] cve [RHEL-20615 cve Mitchell) cve (Audra cve CVE-2024-0841 Rebuild_History Non-Buildable kernel-5.14.0-427.16.1.el9_4 Rebuild_CHGLOG: - fs,hugetlb: fix NULL pointer dereference in hugetlbs_fill_super {CVE-2024-0841} (Audra Mitchell) [RHEL-20615 RHEL-20617] {CVE-2024-0841} Rebuild_FUZZ: 88.73% commit-author Oscar Salvador <[email protected]> commit 79d72c6 Empty-Commit: Cherry-Pick Conflicts during history rebuild. Will be included in final tarball splat. Ref for failed cherry-pick at: ciq/ciq_backports/kernel-5.14.0-427.16.1.el9_4/79d72c68.failed When configuring a hugetlb filesystem via the fsconfig() syscall, there is a possible NULL dereference in hugetlbfs_fill_super() caused by assigning NULL to ctx->hstate in hugetlbfs_parse_param() when the requested pagesize is non valid. E.g: Taking the following steps: fd = fsopen("hugetlbfs", FSOPEN_CLOEXEC); fsconfig(fd, FSCONFIG_SET_STRING, "pagesize", "1024", 0); fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0); Given that the requested "pagesize" is invalid, ctxt->hstate will be replaced with NULL, losing its previous value, and we will print an error: ... ... case Opt_pagesize: ps = memparse(param->string, &rest); ctx->hstate = h; if (!ctx->hstate) { pr_err("Unsupported page size %lu MB\n", ps / SZ_1M); return -EINVAL; } return 0; ... ... This is a problem because later on, we will dereference ctxt->hstate in hugetlbfs_fill_super() ... ... sb->s_blocksize = huge_page_size(ctx->hstate); ... ... Causing below Oops. Fix this by replacing cxt->hstate value only when then pagesize is known to be valid. kernel: hugetlbfs: Unsupported page size 0 MB kernel: BUG: kernel NULL pointer dereference, address: 0000000000000028 kernel: #PF: supervisor read access in kernel mode kernel: #PF: error_code(0x0000) - not-present page kernel: PGD 800000010f66c067 P4D 800000010f66c067 PUD 1b22f8067 PMD 0 kernel: Oops: 0000 [#1] PREEMPT SMP PTI kernel: CPU: 4 PID: 5659 Comm: syscall Tainted: G E 6.8.0-rc2-default+ ctrliq#22 5a47c3fef76212addcc6eb71344aabc35190ae8f kernel: Hardware name: Intel Corp. GROVEPORT/GROVEPORT, BIOS GVPRCRB1.86B.0016.D04.1705030402 05/03/2017 kernel: RIP: 0010:hugetlbfs_fill_super+0xb4/0x1a0 kernel: Code: 48 8b 3b e8 3e c6 ed ff 48 85 c0 48 89 45 20 0f 84 d6 00 00 00 48 b8 ff ff ff ff ff ff ff 7f 4c 89 e7 49 89 44 24 20 48 8b 03 <8b> 48 28 b8 00 10 00 00 48 d3 e0 49 89 44 24 18 48 8b 03 8b 40 28 kernel: RSP: 0018:ffffbe9960fcbd48 EFLAGS: 00010246 kernel: RAX: 0000000000000000 RBX: ffff9af5272ae780 RCX: 0000000000372004 kernel: RDX: ffffffffffffffff RSI: ffffffffffffffff RDI: ffff9af555e9b000 kernel: RBP: ffff9af52ee66b00 R08: 0000000000000040 R09: 0000000000370004 kernel: R10: ffffbe9960fcbd48 R11: 0000000000000040 R12: ffff9af555e9b000 kernel: R13: ffffffffa66b86c0 R14: ffff9af507d2f400 R15: ffff9af507d2f400 kernel: FS: 00007ffbc0ba4740(0000) GS:ffff9b0bd7000000(0000) knlGS:0000000000000000 kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 kernel: CR2: 0000000000000028 CR3: 00000001b1ee0000 CR4: 00000000001506f0 kernel: Call Trace: kernel: <TASK> kernel: ? __die_body+0x1a/0x60 kernel: ? page_fault_oops+0x16f/0x4a0 kernel: ? search_bpf_extables+0x65/0x70 kernel: ? fixup_exception+0x22/0x310 kernel: ? exc_page_fault+0x69/0x150 kernel: ? asm_exc_page_fault+0x22/0x30 kernel: ? __pfx_hugetlbfs_fill_super+0x10/0x10 kernel: ? hugetlbfs_fill_super+0xb4/0x1a0 kernel: ? hugetlbfs_fill_super+0x28/0x1a0 kernel: ? __pfx_hugetlbfs_fill_super+0x10/0x10 kernel: vfs_get_super+0x40/0xa0 kernel: ? __pfx_bpf_lsm_capable+0x10/0x10 kernel: vfs_get_tree+0x25/0xd0 kernel: vfs_cmd_create+0x64/0xe0 kernel: __x64_sys_fsconfig+0x395/0x410 kernel: do_syscall_64+0x80/0x160 kernel: ? syscall_exit_to_user_mode+0x82/0x240 kernel: ? do_syscall_64+0x8d/0x160 kernel: ? syscall_exit_to_user_mode+0x82/0x240 kernel: ? do_syscall_64+0x8d/0x160 kernel: ? exc_page_fault+0x69/0x150 kernel: entry_SYSCALL_64_after_hwframe+0x6e/0x76 kernel: RIP: 0033:0x7ffbc0cb87c9 kernel: Code: 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 97 96 0d 00 f7 d8 64 89 01 48 kernel: RSP: 002b:00007ffc29d2f388 EFLAGS: 00000206 ORIG_RAX: 00000000000001af kernel: RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ffbc0cb87c9 kernel: RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000000000000003 kernel: RBP: 00007ffc29d2f3b0 R08: 0000000000000000 R09: 0000000000000000 kernel: R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000 kernel: R13: 00007ffc29d2f4c0 R14: 0000000000000000 R15: 0000000000000000 kernel: </TASK> kernel: Modules linked in: rpcsec_gss_krb5(E) auth_rpcgss(E) nfsv4(E) dns_resolver(E) nfs(E) lockd(E) grace(E) sunrpc(E) netfs(E) af_packet(E) bridge(E) stp(E) llc(E) iscsi_ibft(E) iscsi_boot_sysfs(E) intel_rapl_msr(E) intel_rapl_common(E) iTCO_wdt(E) intel_pmc_bxt(E) sb_edac(E) iTCO_vendor_support(E) x86_pkg_temp_thermal(E) intel_powerclamp(E) coretemp(E) kvm_intel(E) rfkill(E) ipmi_ssif(E) kvm(E) acpi_ipmi(E) irqbypass(E) pcspkr(E) igb(E) ipmi_si(E) mei_me(E) i2c_i801(E) joydev(E) intel_pch_thermal(E) i2c_smbus(E) dca(E) lpc_ich(E) mei(E) ipmi_devintf(E) ipmi_msghandler(E) acpi_pad(E) tiny_power_button(E) button(E) fuse(E) efi_pstore(E) configfs(E) ip_tables(E) x_tables(E) ext4(E) mbcache(E) jbd2(E) hid_generic(E) usbhid(E) sd_mod(E) t10_pi(E) crct10dif_pclmul(E) crc32_pclmul(E) crc32c_intel(E) polyval_clmulni(E) ahci(E) xhci_pci(E) polyval_generic(E) gf128mul(E) ghash_clmulni_intel(E) sha512_ssse3(E) sha256_ssse3(E) xhci_pci_renesas(E) libahci(E) ehci_pci(E) sha1_ssse3(E) xhci_hcd(E) ehci_hcd(E) libata(E) kernel: mgag200(E) i2c_algo_bit(E) usbcore(E) wmi(E) sg(E) dm_multipath(E) dm_mod(E) scsi_dh_rdac(E) scsi_dh_emc(E) scsi_dh_alua(E) scsi_mod(E) scsi_common(E) aesni_intel(E) crypto_simd(E) cryptd(E) kernel: Unloaded tainted modules: acpi_cpufreq(E):1 fjes(E):1 kernel: CR2: 0000000000000028 kernel: ---[ end trace 0000000000000000 ]--- kernel: RIP: 0010:hugetlbfs_fill_super+0xb4/0x1a0 kernel: Code: 48 8b 3b e8 3e c6 ed ff 48 85 c0 48 89 45 20 0f 84 d6 00 00 00 48 b8 ff ff ff ff ff ff ff 7f 4c 89 e7 49 89 44 24 20 48 8b 03 <8b> 48 28 b8 00 10 00 00 48 d3 e0 49 89 44 24 18 48 8b 03 8b 40 28 kernel: RSP: 0018:ffffbe9960fcbd48 EFLAGS: 00010246 kernel: RAX: 0000000000000000 RBX: ffff9af5272ae780 RCX: 0000000000372004 kernel: RDX: ffffffffffffffff RSI: ffffffffffffffff RDI: ffff9af555e9b000 kernel: RBP: ffff9af52ee66b00 R08: 0000000000000040 R09: 0000000000370004 kernel: R10: ffffbe9960fcbd48 R11: 0000000000000040 R12: ffff9af555e9b000 kernel: R13: ffffffffa66b86c0 R14: ffff9af507d2f400 R15: ffff9af507d2f400 kernel: FS: 00007ffbc0ba4740(0000) GS:ffff9b0bd7000000(0000) knlGS:0000000000000000 kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 kernel: CR2: 0000000000000028 CR3: 00000001b1ee0000 CR4: 00000000001506f0 Link: https://lkml.kernel.org/r/[email protected] Fixes: 3202198 ("hugetlbfs: Convert to fs_context") Signed-off-by: Michal Hocko <[email protected]> Signed-off-by: Oscar Salvador <[email protected]> Acked-by: Muchun Song <[email protected]> Cc: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> (cherry picked from commit 79d72c6) Signed-off-by: Jonathan Maple <[email protected]> # Conflicts: # fs/hugetlbfs/inode.c
1 parent c6888a8 commit 29ace97

File tree

1 file changed

+164
-0
lines changed

1 file changed

+164
-0
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
fs,hugetlb: fix NULL pointer dereference in hugetlbs_fill_super
2+
3+
jira LE-1907
4+
cve {CVE-2024-0841
5+
cve RHEL-20617]
6+
cve [RHEL-20615
7+
cve Mitchell)
8+
cve (Audra
9+
cve CVE-2024-0841
10+
Rebuild_History Non-Buildable kernel-5.14.0-427.16.1.el9_4
11+
Rebuild_CHGLOG: - fs,hugetlb: fix NULL pointer dereference in hugetlbs_fill_super {CVE-2024-0841} (Audra Mitchell) [RHEL-20615 RHEL-20617] {CVE-2024-0841}
12+
Rebuild_FUZZ: 88.73%
13+
commit-author Oscar Salvador <[email protected]>
14+
commit 79d72c68c58784a3e1cd2378669d51bfd0cb7498
15+
Empty-Commit: Cherry-Pick Conflicts during history rebuild.
16+
Will be included in final tarball splat. Ref for failed cherry-pick at:
17+
ciq/ciq_backports/kernel-5.14.0-427.16.1.el9_4/79d72c68.failed
18+
19+
When configuring a hugetlb filesystem via the fsconfig() syscall, there is
20+
a possible NULL dereference in hugetlbfs_fill_super() caused by assigning
21+
NULL to ctx->hstate in hugetlbfs_parse_param() when the requested pagesize
22+
is non valid.
23+
24+
E.g: Taking the following steps:
25+
26+
fd = fsopen("hugetlbfs", FSOPEN_CLOEXEC);
27+
fsconfig(fd, FSCONFIG_SET_STRING, "pagesize", "1024", 0);
28+
fsconfig(fd, FSCONFIG_CMD_CREATE, NULL, NULL, 0);
29+
30+
Given that the requested "pagesize" is invalid, ctxt->hstate will be replaced
31+
with NULL, losing its previous value, and we will print an error:
32+
33+
...
34+
...
35+
case Opt_pagesize:
36+
ps = memparse(param->string, &rest);
37+
ctx->hstate = h;
38+
if (!ctx->hstate) {
39+
pr_err("Unsupported page size %lu MB\n", ps / SZ_1M);
40+
return -EINVAL;
41+
}
42+
return 0;
43+
...
44+
...
45+
46+
This is a problem because later on, we will dereference ctxt->hstate in
47+
hugetlbfs_fill_super()
48+
49+
...
50+
...
51+
sb->s_blocksize = huge_page_size(ctx->hstate);
52+
...
53+
...
54+
55+
Causing below Oops.
56+
57+
Fix this by replacing cxt->hstate value only when then pagesize is known
58+
to be valid.
59+
60+
kernel: hugetlbfs: Unsupported page size 0 MB
61+
kernel: BUG: kernel NULL pointer dereference, address: 0000000000000028
62+
kernel: #PF: supervisor read access in kernel mode
63+
kernel: #PF: error_code(0x0000) - not-present page
64+
kernel: PGD 800000010f66c067 P4D 800000010f66c067 PUD 1b22f8067 PMD 0
65+
kernel: Oops: 0000 [#1] PREEMPT SMP PTI
66+
kernel: CPU: 4 PID: 5659 Comm: syscall Tainted: G E 6.8.0-rc2-default+ #22 5a47c3fef76212addcc6eb71344aabc35190ae8f
67+
kernel: Hardware name: Intel Corp. GROVEPORT/GROVEPORT, BIOS GVPRCRB1.86B.0016.D04.1705030402 05/03/2017
68+
kernel: RIP: 0010:hugetlbfs_fill_super+0xb4/0x1a0
69+
kernel: Code: 48 8b 3b e8 3e c6 ed ff 48 85 c0 48 89 45 20 0f 84 d6 00 00 00 48 b8 ff ff ff ff ff ff ff 7f 4c 89 e7 49 89 44 24 20 48 8b 03 <8b> 48 28 b8 00 10 00 00 48 d3 e0 49 89 44 24 18 48 8b 03 8b 40 28
70+
kernel: RSP: 0018:ffffbe9960fcbd48 EFLAGS: 00010246
71+
kernel: RAX: 0000000000000000 RBX: ffff9af5272ae780 RCX: 0000000000372004
72+
kernel: RDX: ffffffffffffffff RSI: ffffffffffffffff RDI: ffff9af555e9b000
73+
kernel: RBP: ffff9af52ee66b00 R08: 0000000000000040 R09: 0000000000370004
74+
kernel: R10: ffffbe9960fcbd48 R11: 0000000000000040 R12: ffff9af555e9b000
75+
kernel: R13: ffffffffa66b86c0 R14: ffff9af507d2f400 R15: ffff9af507d2f400
76+
kernel: FS: 00007ffbc0ba4740(0000) GS:ffff9b0bd7000000(0000) knlGS:0000000000000000
77+
kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
78+
kernel: CR2: 0000000000000028 CR3: 00000001b1ee0000 CR4: 00000000001506f0
79+
kernel: Call Trace:
80+
kernel: <TASK>
81+
kernel: ? __die_body+0x1a/0x60
82+
kernel: ? page_fault_oops+0x16f/0x4a0
83+
kernel: ? search_bpf_extables+0x65/0x70
84+
kernel: ? fixup_exception+0x22/0x310
85+
kernel: ? exc_page_fault+0x69/0x150
86+
kernel: ? asm_exc_page_fault+0x22/0x30
87+
kernel: ? __pfx_hugetlbfs_fill_super+0x10/0x10
88+
kernel: ? hugetlbfs_fill_super+0xb4/0x1a0
89+
kernel: ? hugetlbfs_fill_super+0x28/0x1a0
90+
kernel: ? __pfx_hugetlbfs_fill_super+0x10/0x10
91+
kernel: vfs_get_super+0x40/0xa0
92+
kernel: ? __pfx_bpf_lsm_capable+0x10/0x10
93+
kernel: vfs_get_tree+0x25/0xd0
94+
kernel: vfs_cmd_create+0x64/0xe0
95+
kernel: __x64_sys_fsconfig+0x395/0x410
96+
kernel: do_syscall_64+0x80/0x160
97+
kernel: ? syscall_exit_to_user_mode+0x82/0x240
98+
kernel: ? do_syscall_64+0x8d/0x160
99+
kernel: ? syscall_exit_to_user_mode+0x82/0x240
100+
kernel: ? do_syscall_64+0x8d/0x160
101+
kernel: ? exc_page_fault+0x69/0x150
102+
kernel: entry_SYSCALL_64_after_hwframe+0x6e/0x76
103+
kernel: RIP: 0033:0x7ffbc0cb87c9
104+
kernel: Code: 00 90 90 90 90 90 90 90 90 90 90 90 90 90 90 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 97 96 0d 00 f7 d8 64 89 01 48
105+
kernel: RSP: 002b:00007ffc29d2f388 EFLAGS: 00000206 ORIG_RAX: 00000000000001af
106+
kernel: RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007ffbc0cb87c9
107+
kernel: RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000000000000003
108+
kernel: RBP: 00007ffc29d2f3b0 R08: 0000000000000000 R09: 0000000000000000
109+
kernel: R10: 0000000000000000 R11: 0000000000000206 R12: 0000000000000000
110+
kernel: R13: 00007ffc29d2f4c0 R14: 0000000000000000 R15: 0000000000000000
111+
kernel: </TASK>
112+
kernel: Modules linked in: rpcsec_gss_krb5(E) auth_rpcgss(E) nfsv4(E) dns_resolver(E) nfs(E) lockd(E) grace(E) sunrpc(E) netfs(E) af_packet(E) bridge(E) stp(E) llc(E) iscsi_ibft(E) iscsi_boot_sysfs(E) intel_rapl_msr(E) intel_rapl_common(E) iTCO_wdt(E) intel_pmc_bxt(E) sb_edac(E) iTCO_vendor_support(E) x86_pkg_temp_thermal(E) intel_powerclamp(E) coretemp(E) kvm_intel(E) rfkill(E) ipmi_ssif(E) kvm(E) acpi_ipmi(E) irqbypass(E) pcspkr(E) igb(E) ipmi_si(E) mei_me(E) i2c_i801(E) joydev(E) intel_pch_thermal(E) i2c_smbus(E) dca(E) lpc_ich(E) mei(E) ipmi_devintf(E) ipmi_msghandler(E) acpi_pad(E) tiny_power_button(E) button(E) fuse(E) efi_pstore(E) configfs(E) ip_tables(E) x_tables(E) ext4(E) mbcache(E) jbd2(E) hid_generic(E) usbhid(E) sd_mod(E) t10_pi(E) crct10dif_pclmul(E) crc32_pclmul(E) crc32c_intel(E) polyval_clmulni(E) ahci(E) xhci_pci(E) polyval_generic(E) gf128mul(E) ghash_clmulni_intel(E) sha512_ssse3(E) sha256_ssse3(E) xhci_pci_renesas(E) libahci(E) ehci_pci(E) sha1_ssse3(E) xhci_hcd(E) ehci_hcd(E) libata(E)
113+
kernel: mgag200(E) i2c_algo_bit(E) usbcore(E) wmi(E) sg(E) dm_multipath(E) dm_mod(E) scsi_dh_rdac(E) scsi_dh_emc(E) scsi_dh_alua(E) scsi_mod(E) scsi_common(E) aesni_intel(E) crypto_simd(E) cryptd(E)
114+
kernel: Unloaded tainted modules: acpi_cpufreq(E):1 fjes(E):1
115+
kernel: CR2: 0000000000000028
116+
kernel: ---[ end trace 0000000000000000 ]---
117+
kernel: RIP: 0010:hugetlbfs_fill_super+0xb4/0x1a0
118+
kernel: Code: 48 8b 3b e8 3e c6 ed ff 48 85 c0 48 89 45 20 0f 84 d6 00 00 00 48 b8 ff ff ff ff ff ff ff 7f 4c 89 e7 49 89 44 24 20 48 8b 03 <8b> 48 28 b8 00 10 00 00 48 d3 e0 49 89 44 24 18 48 8b 03 8b 40 28
119+
kernel: RSP: 0018:ffffbe9960fcbd48 EFLAGS: 00010246
120+
kernel: RAX: 0000000000000000 RBX: ffff9af5272ae780 RCX: 0000000000372004
121+
kernel: RDX: ffffffffffffffff RSI: ffffffffffffffff RDI: ffff9af555e9b000
122+
kernel: RBP: ffff9af52ee66b00 R08: 0000000000000040 R09: 0000000000370004
123+
kernel: R10: ffffbe9960fcbd48 R11: 0000000000000040 R12: ffff9af555e9b000
124+
kernel: R13: ffffffffa66b86c0 R14: ffff9af507d2f400 R15: ffff9af507d2f400
125+
kernel: FS: 00007ffbc0ba4740(0000) GS:ffff9b0bd7000000(0000) knlGS:0000000000000000
126+
kernel: CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
127+
kernel: CR2: 0000000000000028 CR3: 00000001b1ee0000 CR4: 00000000001506f0
128+
129+
Link: https://lkml.kernel.org/r/[email protected]
130+
Fixes: 32021982a324 ("hugetlbfs: Convert to fs_context")
131+
Signed-off-by: Michal Hocko <[email protected]>
132+
Signed-off-by: Oscar Salvador <[email protected]>
133+
Acked-by: Muchun Song <[email protected]>
134+
135+
Signed-off-by: Andrew Morton <[email protected]>
136+
(cherry picked from commit 79d72c68c58784a3e1cd2378669d51bfd0cb7498)
137+
Signed-off-by: Jonathan Maple <[email protected]>
138+
139+
# Conflicts:
140+
# fs/hugetlbfs/inode.c
141+
diff --cc fs/hugetlbfs/inode.c
142+
index 30f9f68a002e,d746866ae3b6..000000000000
143+
--- a/fs/hugetlbfs/inode.c
144+
+++ b/fs/hugetlbfs/inode.c
145+
@@@ -1357,11 -1410,12 +1358,18 @@@ static int hugetlbfs_parse_param(struc
146+
147+
case Opt_pagesize:
148+
ps = memparse(param->string, &rest);
149+
++<<<<<<< HEAD
150+
+ ctx->hstate = size_to_hstate(ps);
151+
+ if (!ctx->hstate) {
152+
+ pr_err("Unsupported page size %lu MB\n", ps >> 20);
153+
++=======
154+
+ h = size_to_hstate(ps);
155+
+ if (!h) {
156+
+ pr_err("Unsupported page size %lu MB\n", ps / SZ_1M);
157+
++>>>>>>> 79d72c68c587 (fs,hugetlb: fix NULL pointer dereference in hugetlbs_fill_super)
158+
return -EINVAL;
159+
}
160+
+ ctx->hstate = h;
161+
return 0;
162+
163+
case Opt_min_size:
164+
* Unmerged path fs/hugetlbfs/inode.c

0 commit comments

Comments
 (0)