{"id":"CVE-2026-139325","state":"PUBLISHED","title":"bpf: Forbid sleeping in hash map for_each callbacks","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Forbid sleeping in hash map for_each callbacks\n\nA sleepable program (e.g. SEC(\"syscall\"), lsm.s, fentry.s) can pass a\ncallback to bpf_for_each_map_elem() on a hash map and call a sleepable\nhelper or kfunc such as bpf_copy_from_user() from it. The verifier\naccepts this, but at run time the callback is invoked from inside an RCU\nread-side critical section:\n\n    bpf_for_each_hash_elem()\n      rcu_read_lock();\n      callback_fn(map, key, val, ctx, 0);\n        bpf_copy_from_user()       <- may fault and sleep\n      rcu_read_unlock();\n\nbpf_each_rhash_elem() does the same for BPF_MAP_TYPE_RHASH. Sleeping\nthere triggers the \"Voluntary context switch within RCU read-side\ncritical section!\" warning, delays grace periods, and with\nCONFIG_PREEMPT_RCU=n silently ends the read-side critical section that\nthe bucket walk relies on.\n\nSynchronous callbacks are verified with the caller's state, so\nkernel/bpf/verifier.c:in_sleepable_context() only looks at the program's\nsleepability and the locks the program took itself, and does not know\nthat the helper holds rcu_read_lock() around the callback.\n\nWith a SEC(\"syscall\") program whose callback reads a page that has to be\nread from disk first:\n\n  BUG: sleeping function called from invalid context at include/linux/uaccess.h:169\n  RCU nest depth: 1, expected: 0\n   __might_fault+0x29/0x80\n   _copy_from_user+0x26/0x90\n   bpf_copy_from_user+0x23/0x60\n   bpf_prog_17d44fa39eebd6cc_cb+0x35/0x46\n   bpf_for_each_hash_elem+0xdb/0x280\n\nFix by marking the callback frame of hash map iteration as running under\nRCU and making in_sleepable_context() false while such a frame is on the\ncall stack, so sleepable helpers, kfuncs and global functions are\nrejected there as inside bpf_rcu_read_lock(). The rules for trusting RCU\nprotected pointers are left alone, which is conservative and keeps\ncallbacks that verify today and do not sleep working. The flag is\ncompared in func_states_equal() so that pruning never mixes the two\ncontexts. Array map callbacks run without any lock and keep the caller's\ncontext.","publishedAt":"2026-11-30T13:33:43.168Z","updatedAt":"2026-11-30T13:33:43.168Z","severity":null,"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"314ee05e2fc601a7bece14376547d2b7a04bab67","status":"affected","lessThan":"b13b93f264ec9a700e22f91ada8313acc44ada2a","versionType":"git"},{"version":"314ee05e2fc601a7bece14376547d2b7a04bab67","status":"affected","lessThan":"9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["include/linux/bpf_verifier.h","kernel/bpf/states.c","kernel/bpf/verifier.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"5.13","status":"affected"},{"version":"0","status":"unaffected","lessThan":"5.13","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":["include/linux/bpf_verifier.h","kernel/bpf/states.c","kernel/bpf/verifier.c"]}],"references":["https://git.kernel.org/stable/c/b13b93f264ec9a700e22f91ada8313acc44ada2a","https://git.kernel.org/stable/c/9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6"],"weaknesses":[],"ingestedAt":"2026-11-30T13:46:04.484Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2026/139xxx/CVE-2026-139325.json","commit":"8c2c22940a0de21d18737df980299c0488d5dc73","baselineCommit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2026-139325","state":"PUBLISHED","datePublished":"2026-11-30T13:33:43.168Z","dateUpdated":"2026-11-30T13:33:43.168Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2026-11-30T13:22:15.927Z"},"containers":{"cna":{"title":"bpf: Forbid sleeping in hash map for_each callbacks","descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Forbid sleeping in hash map for_each callbacks\n\nA sleepable program (e.g. SEC(\"syscall\"), lsm.s, fentry.s) can pass a\ncallback to bpf_for_each_map_elem() on a hash map and call a sleepable\nhelper or kfunc such as bpf_copy_from_user() from it. The verifier\naccepts this, but at run time the callback is invoked from inside an RCU\nread-side critical section:\n\n    bpf_for_each_hash_elem()\n      rcu_read_lock();\n      callback_fn(map, key, val, ctx, 0);\n        bpf_copy_from_user()       <- may fault and sleep\n      rcu_read_unlock();\n\nbpf_each_rhash_elem() does the same for BPF_MAP_TYPE_RHASH. Sleeping\nthere triggers the \"Voluntary context switch within RCU read-side\ncritical section!\" warning, delays grace periods, and with\nCONFIG_PREEMPT_RCU=n silently ends the read-side critical section that\nthe bucket walk relies on.\n\nSynchronous callbacks are verified with the caller's state, so\nkernel/bpf/verifier.c:in_sleepable_context() only looks at the program's\nsleepability and the locks the program took itself, and does not know\nthat the helper holds rcu_read_lock() around the callback.\n\nWith a SEC(\"syscall\") program whose callback reads a page that has to be\nread from disk first:\n\n  BUG: sleeping function called from invalid context at include/linux/uaccess.h:169\n  RCU nest depth: 1, expected: 0\n   __might_fault+0x29/0x80\n   _copy_from_user+0x26/0x90\n   bpf_copy_from_user+0x23/0x60\n   bpf_prog_17d44fa39eebd6cc_cb+0x35/0x46\n   bpf_for_each_hash_elem+0xdb/0x280\n\nFix by marking the callback frame of hash map iteration as running under\nRCU and making in_sleepable_context() false while such a frame is on the\ncall stack, so sleepable helpers, kfuncs and global functions are\nrejected there as inside bpf_rcu_read_lock(). The rules for trusting RCU\nprotected pointers are left alone, which is conservative and keeps\ncallbacks that verify today and do not sleep working. The flag is\ncompared in func_states_equal() so that pruning never mixes the two\ncontexts. Array map callbacks run without any lock and keep the caller's\ncontext."}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"314ee05e2fc601a7bece14376547d2b7a04bab67","status":"affected","lessThan":"b13b93f264ec9a700e22f91ada8313acc44ada2a","versionType":"git"},{"version":"314ee05e2fc601a7bece14376547d2b7a04bab67","status":"affected","lessThan":"9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["include/linux/bpf_verifier.h","kernel/bpf/states.c","kernel/bpf/verifier.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"5.13","status":"affected"},{"version":"0","status":"unaffected","lessThan":"5.13","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":["include/linux/bpf_verifier.h","kernel/bpf/states.c","kernel/bpf/verifier.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/b13b93f264ec9a700e22f91ada8313acc44ada2a"},{"url":"https://git.kernel.org/stable/c/9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6"}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-11-30T13:33:43.168Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.13","versionEndExcluding":"7.3.6"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"5.13","versionEndExcluding":"7.4-rc1"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}