{"id":"CVE-2026-139629","state":"PUBLISHED","title":"bpf: Check fastcall stack contract once for all stack accesses","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Check fastcall stack contract once for all stack accesses\n\nWhen the verifier inlines a bpf_fastcall helper or kfunc, it removes the\nspill/fill pairs that clang emitted around the call and lowers the\nsubprogram's stack depth so that their slots are no longer part of the\nframe. This is only safe if nothing else accesses those slots or any slot\nbelow them. check_fastcall_stack_contract() enforces this: an access to\nthat region from outside a fastcall pattern disables the rewrite for the\nsubprogram. It is called from the four stack load and store paths, and\ntwo kinds of access escape it.\n\nStack buffers passed to helpers and kfuncs are validated by\ncheck_stack_range_initialized(), which does not call it. If such a buffer\nis the only other access to the region, the rewrite is still applied, the\nJIT reserves a frame that does not contain the buffer, and the helper\nreads or writes live kernel stack below the program's frame. For example,\nwithout CAP_PERFMON:\n\n\t*(u64 *)(r10 - 8) = r1;\n\tcall bpf_get_smp_processor_id;\n\tr1 = *(u64 *)(r10 - 8);\n\tr2 = 0;\n\tr3 = r10;\n\tr3 += -64;\n\tr4 = 8;\n\tcall bpf_skb_load_bytes;\n\nis accepted with a stack depth of 0 instead of 64.\n\nSome buffers got the check indirectly. For constant-sized outputs in raw\nmode, mark_raw_stack() marks the buffer initialized through ordinary\nbyte stores, which call the check. Commit 5da4a9f26fca (\"bpf: Preserve\nstack initialization for generic output buffers\") limited raw mode to\nprograms that may read uninitialized stack, so outputs of programs\nwithout CAP_PERFMON lost the check, as in the example above. Buffers\nthat never used raw mode have lacked the check since fastcall support\nwas added: helper inputs such as a map key whose only store is a fastcall\nspill, variable-sized outputs, and buffers at a variable stack offset.\n\ncheck_stack_read_fixed_off() applies the check to the current frame,\neven when the pointer targets a caller's stack. A callee can therefore\nread a caller's fastcall spill slot without disabling the caller's\nrewrite:\n\n\tcaller:\n\tr1 = 1;\n\t*(u64 *)(r10 - 8) = r1;\n\tcall bpf_get_smp_processor_id;\n\tr1 = *(u64 *)(r10 - 8);\n\tr1 = r10;\n\tr1 += -8;\n\tcall callee;\n\n\tcallee:\n\tr0 = *(u64 *)(r1 + 0);\n\nThe caller's spill and fill are removed and its stack depth drops to 0,\nbut the verifier still tracks the slot as holding the spilled constant.\nThe callee's load then reads kernel stack outside the caller's frame,\nwhile the verifier assumes r0 is 1.\n\nEvery stack access first goes through check_stack_access_within_bounds():\nloads and stores from check_mem_access(), helper and kfunc buffers from\ncheck_stack_range_initialized(), and the dynptr, iterator and irq flag\nslots that kfuncs initialize, whose handlers use check_mem_access(). It\nresolves the frame that owns the slots and the lowest offset the access\ncan touch, and it is the only place where a frame's stack depth grows.\nCheck the contract there, once for every access, and drop the calls from\nthe stack read and write paths. Zero-sized buffers touch no stack and\nleave the rewrite enabled.","publishedAt":"2026-11-30T13:36:31.012Z","updatedAt":"2026-11-30T13:36:31.012Z","severity":null,"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"6acd70ced460317eb8d0dd8b5907b65292c59a42","versionType":"git"},{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"31594d4872dfdbad767e67fcc74bcd0a31f02150","versionType":"git"},{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"f19a6264a62b910332a61523177b3cccf4bab46d","versionType":"git"},{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"ec3a69e7c021cd826be8886ba6af4ee3147788fb","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["kernel/bpf/verifier.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.12","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.12","versionType":"semver"},{"version":"6.12.120","status":"unaffected","lessThanOrEqual":"6.12.*","versionType":"semver"},{"version":"6.18.66","status":"unaffected","lessThanOrEqual":"6.18.*","versionType":"semver"},{"version":"7.3.6","status":"unaffected","lessThanOrEqual":"7.3.*","versionType":"semver"},{"version":"7.4-rc1","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["kernel/bpf/verifier.c"]}],"references":["https://git.kernel.org/stable/c/6acd70ced460317eb8d0dd8b5907b65292c59a42","https://git.kernel.org/stable/c/31594d4872dfdbad767e67fcc74bcd0a31f02150","https://git.kernel.org/stable/c/f19a6264a62b910332a61523177b3cccf4bab46d","https://git.kernel.org/stable/c/ec3a69e7c021cd826be8886ba6af4ee3147788fb"],"weaknesses":[],"ingestedAt":"2026-11-30T13:54:04.526Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2026/139xxx/CVE-2026-139629.json","commit":"8c2c22940a0de21d18737df980299c0488d5dc73","baselineCommit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2026-139629","state":"PUBLISHED","datePublished":"2026-11-30T13:36:31.012Z","dateUpdated":"2026-11-30T13:36:31.012Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2026-11-30T13:22:15.944Z"},"containers":{"cna":{"title":"bpf: Check fastcall stack contract once for all stack accesses","descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Check fastcall stack contract once for all stack accesses\n\nWhen the verifier inlines a bpf_fastcall helper or kfunc, it removes the\nspill/fill pairs that clang emitted around the call and lowers the\nsubprogram's stack depth so that their slots are no longer part of the\nframe. This is only safe if nothing else accesses those slots or any slot\nbelow them. check_fastcall_stack_contract() enforces this: an access to\nthat region from outside a fastcall pattern disables the rewrite for the\nsubprogram. It is called from the four stack load and store paths, and\ntwo kinds of access escape it.\n\nStack buffers passed to helpers and kfuncs are validated by\ncheck_stack_range_initialized(), which does not call it. If such a buffer\nis the only other access to the region, the rewrite is still applied, the\nJIT reserves a frame that does not contain the buffer, and the helper\nreads or writes live kernel stack below the program's frame. For example,\nwithout CAP_PERFMON:\n\n\t*(u64 *)(r10 - 8) = r1;\n\tcall bpf_get_smp_processor_id;\n\tr1 = *(u64 *)(r10 - 8);\n\tr2 = 0;\n\tr3 = r10;\n\tr3 += -64;\n\tr4 = 8;\n\tcall bpf_skb_load_bytes;\n\nis accepted with a stack depth of 0 instead of 64.\n\nSome buffers got the check indirectly. For constant-sized outputs in raw\nmode, mark_raw_stack() marks the buffer initialized through ordinary\nbyte stores, which call the check. Commit 5da4a9f26fca (\"bpf: Preserve\nstack initialization for generic output buffers\") limited raw mode to\nprograms that may read uninitialized stack, so outputs of programs\nwithout CAP_PERFMON lost the check, as in the example above. Buffers\nthat never used raw mode have lacked the check since fastcall support\nwas added: helper inputs such as a map key whose only store is a fastcall\nspill, variable-sized outputs, and buffers at a variable stack offset.\n\ncheck_stack_read_fixed_off() applies the check to the current frame,\neven when the pointer targets a caller's stack. A callee can therefore\nread a caller's fastcall spill slot without disabling the caller's\nrewrite:\n\n\tcaller:\n\tr1 = 1;\n\t*(u64 *)(r10 - 8) = r1;\n\tcall bpf_get_smp_processor_id;\n\tr1 = *(u64 *)(r10 - 8);\n\tr1 = r10;\n\tr1 += -8;\n\tcall callee;\n\n\tcallee:\n\tr0 = *(u64 *)(r1 + 0);\n\nThe caller's spill and fill are removed and its stack depth drops to 0,\nbut the verifier still tracks the slot as holding the spilled constant.\nThe callee's load then reads kernel stack outside the caller's frame,\nwhile the verifier assumes r0 is 1.\n\nEvery stack access first goes through check_stack_access_within_bounds():\nloads and stores from check_mem_access(), helper and kfunc buffers from\ncheck_stack_range_initialized(), and the dynptr, iterator and irq flag\nslots that kfuncs initialize, whose handlers use check_mem_access(). It\nresolves the frame that owns the slots and the lowest offset the access\ncan touch, and it is the only place where a frame's stack depth grows.\nCheck the contract there, once for every access, and drop the calls from\nthe stack read and write paths. Zero-sized buffers touch no stack and\nleave the rewrite enabled."}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"6acd70ced460317eb8d0dd8b5907b65292c59a42","versionType":"git"},{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"31594d4872dfdbad767e67fcc74bcd0a31f02150","versionType":"git"},{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"f19a6264a62b910332a61523177b3cccf4bab46d","versionType":"git"},{"version":"5b5f51bff1b66cedb62b5ba74a1878341204e057","status":"affected","lessThan":"ec3a69e7c021cd826be8886ba6af4ee3147788fb","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["kernel/bpf/verifier.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.12","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.12","versionType":"semver"},{"version":"6.12.120","status":"unaffected","lessThanOrEqual":"6.12.*","versionType":"semver"},{"version":"6.18.66","status":"unaffected","lessThanOrEqual":"6.18.*","versionType":"semver"},{"version":"7.3.6","status":"unaffected","lessThanOrEqual":"7.3.*","versionType":"semver"},{"version":"7.4-rc1","status":"unaffected","lessThanOrEqual":"*","versionType":"original_commit_for_fix"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["kernel/bpf/verifier.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/6acd70ced460317eb8d0dd8b5907b65292c59a42"},{"url":"https://git.kernel.org/stable/c/31594d4872dfdbad767e67fcc74bcd0a31f02150"},{"url":"https://git.kernel.org/stable/c/f19a6264a62b910332a61523177b3cccf4bab46d"},{"url":"https://git.kernel.org/stable/c/ec3a69e7c021cd826be8886ba6af4ee3147788fb"}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-11-30T13:36:31.012Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.12","versionEndExcluding":"6.12.120"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.12","versionEndExcluding":"6.18.66"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.12","versionEndExcluding":"7.3.6"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.12","versionEndExcluding":"7.4-rc1"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}