In the Linux kernel, the following vulnerability has been resolved:
fs,hugetlb: fix NULL pointer dereference in hugetlbsfillsuper
When configuring a hugetlb filesystem via the fsconfig() syscall, there is a possible NULL dereference in hugetlbfsfillsuper() caused by assigning NULL to ctx->hstate in hugetlbfsparseparam() 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 Optpagesize: ps = memparse(param->string, &rest); ctx->hstate = h; if (!ctx->hstate) { prerr("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 hugetlbfsfillsuper()
... ... sb->sblocksize = hugepage_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: errorcode(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+ #22 5a47c3fef76212addcc6eb71344aabc35190ae8f kernel: Hardware name: Intel Corp. GROVEPORT/GROVEPORT, BIOS GVPRCRB1.86B.0016.D04.1705030402 05/03/2017 kernel: RIP: 0010:hugetlbfsfillsuper+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: ? _diebody+0x1a/0x60 kernel: ? pagefaultoops+0x16f/0x4a0 kernel: ? searchbpfextables+0x65/0x70 kernel: ? fixupexception+0x22/0x310 kernel: ? excpagefault+0x69/0x150 kernel: ? asmexcpagefault+0x22/0x30 kernel: ? _pfxhugetlbfsfillsuper+0x10/0x10 kernel: ? hugetlbfsfillsuper+0xb4/0x1a0 kernel: ? hugetlbfsfillsuper+0x28/0x1a0 kernel: ? _pfxhugetlbfsfillsuper+0x10/0x10 kernel: vfsgetsuper+0x40/0xa0 kernel: ? _pfxbpflsmcapable+0x10/0x10 kernel: vfsgettree+0x25/0xd0 kernel: vfscmdcreate+0x64/0xe0 kernel: _x64sysfsconfig+0x395/0x410 kernel: dosyscall64+0x80/0x160 kernel: ? syscallexittousermode+0x82/0x240 kernel: ? dosyscall64+0x8d/0x160 kernel: ? syscallexittousermode+0x82/0x240 kernel: ? dosyscall64+0x8d/0x160 kernel: ? excpagefault+0x69/0x150 kernel: entrySYSCALL64afterhwframe+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: fffffffffff ---truncated---
[
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@2e2c07104b4904aed1389a59b25799b95a85b5b9",
        "deprecated": false,
        "id": "CVE-2024-26688-0a9151da",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "332092115759885427922459585553888053689",
            "length": 1646.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@22850c9950a4e43a67299755d11498f3292d02ff",
        "deprecated": false,
        "id": "CVE-2024-26688-1283919a",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "165840437414336493009113771443682442736",
                "138483494862606234552671884747516100152",
                "107190008560705633628497357452298554625",
                "242523862048668556177506829187315563346",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@79d72c68c58784a3e1cd2378669d51bfd0cb7498",
        "deprecated": false,
        "id": "CVE-2024-26688-20dec32f",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "278793692546398223497976494882124631640",
                "235964747640161308772712354537177868340",
                "260687906092517146693315986886518685699",
                "132557047297811791746242024611381777644",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@80d852299987a8037be145a94f41874228f1a773",
        "deprecated": false,
        "id": "CVE-2024-26688-4fb4fd19",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "165840437414336493009113771443682442736",
                "138483494862606234552671884747516100152",
                "107190008560705633628497357452298554625",
                "242523862048668556177506829187315563346",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13c5a9fb07105557a1fa9efdb4f23d7ef30b7274",
        "deprecated": false,
        "id": "CVE-2024-26688-72473d14",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "332092115759885427922459585553888053689",
            "length": 1646.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ec78418801ef7b0c22cd6a30145ec480dd48db39",
        "deprecated": false,
        "id": "CVE-2024-26688-98f76464",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "332092115759885427922459585553888053689",
            "length": 1646.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@13c5a9fb07105557a1fa9efdb4f23d7ef30b7274",
        "deprecated": false,
        "id": "CVE-2024-26688-a932049c",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "278793692546398223497976494882124631640",
                "235964747640161308772712354537177868340",
                "260687906092517146693315986886518685699",
                "132557047297811791746242024611381777644",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@79d72c68c58784a3e1cd2378669d51bfd0cb7498",
        "deprecated": false,
        "id": "CVE-2024-26688-b5642225",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "332092115759885427922459585553888053689",
            "length": 1646.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@22850c9950a4e43a67299755d11498f3292d02ff",
        "deprecated": false,
        "id": "CVE-2024-26688-bc97a1a0",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "204017769949106098322000892797738633629",
            "length": 1644.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@ec78418801ef7b0c22cd6a30145ec480dd48db39",
        "deprecated": false,
        "id": "CVE-2024-26688-d6210efc",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "278793692546398223497976494882124631640",
                "235964747640161308772712354537177868340",
                "260687906092517146693315986886518685699",
                "132557047297811791746242024611381777644",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@80d852299987a8037be145a94f41874228f1a773",
        "deprecated": false,
        "id": "CVE-2024-26688-dd0b1309",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "204017769949106098322000892797738633629",
            "length": 1644.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1dde8ef4b7a749ae1bc73617c91775631d167557",
        "deprecated": false,
        "id": "CVE-2024-26688-df467d4b",
        "target": {
            "function": "hugetlbfs_parse_param",
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Function",
        "digest": {
            "function_hash": "247555206527345229810759182421313585569",
            "length": 1657.0
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@1dde8ef4b7a749ae1bc73617c91775631d167557",
        "deprecated": false,
        "id": "CVE-2024-26688-f24b1763",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "165840437414336493009113771443682442736",
                "138483494862606234552671884747516100152",
                "107190008560705633628497357452298554625",
                "242523862048668556177506829187315563346",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    },
    {
        "signature_version": "v1",
        "source": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git@2e2c07104b4904aed1389a59b25799b95a85b5b9",
        "deprecated": false,
        "id": "CVE-2024-26688-f8c7f218",
        "target": {
            "file": "fs/hugetlbfs/inode.c"
        },
        "signature_type": "Line",
        "digest": {
            "line_hashes": [
                "106311433668877377976296925698192440558",
                "161805215190715067064554381902187504510",
                "148236023071691178481130765911661412502",
                "98993658553252327308847063130989385873",
                "123179494371299088515375430091523185591",
                "172550501093217309978784790694644274356",
                "278793692546398223497976494882124631640",
                "235964747640161308772712354537177868340",
                "260687906092517146693315986886518685699",
                "132557047297811791746242024611381777644",
                "244302331500784155367712175156741790320",
                "37108251263384587795497618985143368812"
            ],
            "threshold": 0.9
        }
    }
]