{"id":"CVE-2026-139325","aliases":["CVE-2026-139325"],"related":[],"kind":"vulnerability","state":"published","title":"bpf: Forbid sleeping in hash map for_each callbacks","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"}],"published":"2026-11-30T13:33:43.168Z","modified":"2026-11-30T14:18:57.030Z","severities":[],"cwes":[],"affected":[{"ranges":[{"type":"git","introduced":"314ee05e2fc601a7bece14376547d2b7a04bab67","fixed":"b13b93f264ec9a700e22f91ada8313acc44ada2a","status":"affected"},{"type":"git","introduced":"314ee05e2fc601a7bece14376547d2b7a04bab67","fixed":"9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6","status":"affected"}],"vendor":"Linux","product":"Linux","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","source":"cvelist"},{"ranges":[{"version":"5.13","status":"affected"},{"type":"semver","introduced":"0","fixed":"5.13","status":"unaffected"},{"type":"semver","introduced":"7.3.6","lastAffected":"7.3.*","status":"unaffected"},{"type":"original_commit_for_fix","introduced":"7.4-rc1","lastAffected":"*","status":"unaffected"}],"vendor":"Linux","product":"Linux","repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","source":"cvelist"}],"references":[{"url":"https://git.kernel.org/stable/c/b13b93f264ec9a700e22f91ada8313acc44ada2a","tags":[],"sources":["cvelist","nvd"]},{"url":"https://git.kernel.org/stable/c/9bdd5e7f5d8313fa1f3a210621b4007bb5ad0ec6","tags":[],"sources":["cvelist","nvd"]}],"credits":[],"assigner":"Linux","sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-139325","url":"https://www.cve.org/CVERecord?id=CVE-2026-139325","licence":"CVE Terms of Use","modified":"2026-11-30T13:33:43.168Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-139325","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-139325","licence":"Public domain","modified":"2026-11-30T14:18:57.030Z"}],"updatedAt":"2026-11-30T14:32:53.961Z","epss":{"score":0.0019,"percentile":0.09092,"date":"2026-12-01T12:00:22.000Z"}}