{"id":"CVE-2026-139346","state":"PUBLISHED","title":"bpf: Fix NULL task dereference in task work cancellation","description":"In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Fix NULL task dereference in task work cancellation\n\nbpf_task_work_irq() publishes ctx->work with task_work_add() before\nchanging the context from SCHEDULING to SCHEDULED.  The target task can\nrun the callback on another CPU before the handler reaches its final\nstate transition.\n\nThe handler then reloads ctx->task for cancellation if its final cmpxchg\nobserves FREED.  By that point the callback or context destruction may\nalready have cleared ctx->task, causing task_work_cancel() to dereference\na NULL task pointer.\n\nOne concrete interleaving is:\n\n  1. CPU 0 changes PENDING to SCHEDULING and successfully queues\n     ctx->work with task_work_add(), but has not attempted the final\n     state cmpxchg.\n\n  2. The target task on CPU 1 runs the callback.  It changes SCHEDULING\n     to RUNNING, executes the BPF subprogram, resets ctx->task,\n     publishes STANDBY and drops the callback's context reference.\n\n  3. CPU 2 deletes the map value.  It changes STANDBY to FREED and drops\n     the map's context reference without queuing asynchronous\n     cancellation.\n\n  4. CPU 0 resumes.  Its SCHEDULING-to-SCHEDULED cmpxchg observes FREED,\n     and the cancellation attempt passes NULL to task_work_cancel().\n\nIf deletion publishes FREED before the callback claims RUNNING, the\ncallback takes its FREED exit and drops its context reference.  Context\ndestruction can then clear ctx->task before CPU 0 attempts cancellation.\n\nA controlled reproducer with a delay before the final cmpxchg triggered\nthe following fault on a v7.3-rc3 based x86-64 KVM guest:\n\n  BUG: kernel NULL pointer dereference, address: 0000000000000890\n  RIP: 0010:task_work_cancel+0xd/0xa0\n  RDI: 0000000000000000\n  CR2: 0000000000000890\n  Call Trace:\n   <IRQ>\n   bpf_task_work_irq+0x95/0x100\n   irq_work_run_list+0x4f/0x90\n   irq_work_run+0x18/0x50\n   </IRQ>\n\n0x890 is the task_struct::task_works offset in that build, read through\nthe NULL task argument.\n\nCapture ctx->task before task_work_add() publishes the callback and use\nthat pointer for the handler's cancellation attempt.  The round still\nholds its task reference when the pointer is captured.  Releasing that\nreference uses bpf_task_release(), which calls put_task_struct_rcu_user(),\nso the handler's existing RCU read-side section keeps the captured task\nalive even if ctx->task is subsequently cleared.\n\nThe asynchronous cancellation path reads ctx->task directly, which is\nsafe there: queuing it requires deletion to observe SCHEDULED, and that\nxchg wins against the callback's transition to RUNNING, so the callback\ntakes its FREED exit without resetting ctx->task, while the map\nreference transferred to the cancellation handler prevents context\ndestruction until cancellation completes.\n\nThe handler-tail and asynchronous cancellation attempts are mutually\nexclusive: asynchronous cancellation is queued only if deletion observes\nSCHEDULED after the scheduling handler's final cmpxchg has succeeded.\nIf that cmpxchg instead observes FREED, the scheduling handler attempts\ncancellation with the captured pointer.","publishedAt":"2026-11-30T13:33:54.743Z","updatedAt":"2026-11-30T13:33:54.743Z","severity":null,"assigner":"Linux","products":["Linux Linux"],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"38aa7003e369802f81a078f6673d10d97013f04f","status":"affected","lessThan":"fd91c41b1d4ab85ce806d61c8e5b7add292046dc","versionType":"git"},{"version":"38aa7003e369802f81a078f6673d10d97013f04f","status":"affected","lessThan":"2fd1c3f2128a59d118e6656dcbd065a588a5aac7","versionType":"git"},{"version":"38aa7003e369802f81a078f6673d10d97013f04f","status":"affected","lessThan":"c961f7b41a108313a4705baac7b27d2174cc8035","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["kernel/bpf/helpers.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.18","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.18","versionType":"semver"},{"version":"6.18.65","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/helpers.c"]}],"references":["https://git.kernel.org/stable/c/fd91c41b1d4ab85ce806d61c8e5b7add292046dc","https://git.kernel.org/stable/c/2fd1c3f2128a59d118e6656dcbd065a588a5aac7","https://git.kernel.org/stable/c/c961f7b41a108313a4705baac7b27d2174cc8035"],"weaknesses":[],"ingestedAt":"2026-11-30T13:48:04.491Z","source":{"repository":"CVEProject/cvelistV5","path":"cves/2026/139xxx/CVE-2026-139346.json","commit":"8c2c22940a0de21d18737df980299c0488d5dc73","baselineCommit":"556c9d3a8cd17e218bb8e452ba7cd619a384ff47"},"raw":{"dataType":"CVE_RECORD","dataVersion":"5.2","cveMetadata":{"cveId":"CVE-2026-139346","state":"PUBLISHED","datePublished":"2026-11-30T13:33:54.743Z","dateUpdated":"2026-11-30T13:33:54.743Z","assignerShortName":"Linux","assignerOrgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateReserved":"2026-11-30T13:22:15.928Z"},"containers":{"cna":{"title":"bpf: Fix NULL task dereference in task work cancellation","descriptions":[{"lang":"en","value":"In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Fix NULL task dereference in task work cancellation\n\nbpf_task_work_irq() publishes ctx->work with task_work_add() before\nchanging the context from SCHEDULING to SCHEDULED.  The target task can\nrun the callback on another CPU before the handler reaches its final\nstate transition.\n\nThe handler then reloads ctx->task for cancellation if its final cmpxchg\nobserves FREED.  By that point the callback or context destruction may\nalready have cleared ctx->task, causing task_work_cancel() to dereference\na NULL task pointer.\n\nOne concrete interleaving is:\n\n  1. CPU 0 changes PENDING to SCHEDULING and successfully queues\n     ctx->work with task_work_add(), but has not attempted the final\n     state cmpxchg.\n\n  2. The target task on CPU 1 runs the callback.  It changes SCHEDULING\n     to RUNNING, executes the BPF subprogram, resets ctx->task,\n     publishes STANDBY and drops the callback's context reference.\n\n  3. CPU 2 deletes the map value.  It changes STANDBY to FREED and drops\n     the map's context reference without queuing asynchronous\n     cancellation.\n\n  4. CPU 0 resumes.  Its SCHEDULING-to-SCHEDULED cmpxchg observes FREED,\n     and the cancellation attempt passes NULL to task_work_cancel().\n\nIf deletion publishes FREED before the callback claims RUNNING, the\ncallback takes its FREED exit and drops its context reference.  Context\ndestruction can then clear ctx->task before CPU 0 attempts cancellation.\n\nA controlled reproducer with a delay before the final cmpxchg triggered\nthe following fault on a v7.3-rc3 based x86-64 KVM guest:\n\n  BUG: kernel NULL pointer dereference, address: 0000000000000890\n  RIP: 0010:task_work_cancel+0xd/0xa0\n  RDI: 0000000000000000\n  CR2: 0000000000000890\n  Call Trace:\n   <IRQ>\n   bpf_task_work_irq+0x95/0x100\n   irq_work_run_list+0x4f/0x90\n   irq_work_run+0x18/0x50\n   </IRQ>\n\n0x890 is the task_struct::task_works offset in that build, read through\nthe NULL task argument.\n\nCapture ctx->task before task_work_add() publishes the callback and use\nthat pointer for the handler's cancellation attempt.  The round still\nholds its task reference when the pointer is captured.  Releasing that\nreference uses bpf_task_release(), which calls put_task_struct_rcu_user(),\nso the handler's existing RCU read-side section keeps the captured task\nalive even if ctx->task is subsequently cleared.\n\nThe asynchronous cancellation path reads ctx->task directly, which is\nsafe there: queuing it requires deletion to observe SCHEDULED, and that\nxchg wins against the callback's transition to RUNNING, so the callback\ntakes its FREED exit without resetting ctx->task, while the map\nreference transferred to the cancellation handler prevents context\ndestruction until cancellation completes.\n\nThe handler-tail and asynchronous cancellation attempts are mutually\nexclusive: asynchronous cancellation is queued only if deletion observes\nSCHEDULED after the scheduling handler's final cmpxchg has succeeded.\nIf that cmpxchg instead observes FREED, the scheduling handler attempts\ncancellation with the captured pointer."}],"affected":[{"vendor":"Linux","product":"Linux","defaultStatus":"unaffected","versions":[{"version":"38aa7003e369802f81a078f6673d10d97013f04f","status":"affected","lessThan":"fd91c41b1d4ab85ce806d61c8e5b7add292046dc","versionType":"git"},{"version":"38aa7003e369802f81a078f6673d10d97013f04f","status":"affected","lessThan":"2fd1c3f2128a59d118e6656dcbd065a588a5aac7","versionType":"git"},{"version":"38aa7003e369802f81a078f6673d10d97013f04f","status":"affected","lessThan":"c961f7b41a108313a4705baac7b27d2174cc8035","versionType":"git"}],"repo":"https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git","programFiles":["kernel/bpf/helpers.c"]},{"vendor":"Linux","product":"Linux","defaultStatus":"affected","versions":[{"version":"6.18","status":"affected"},{"version":"0","status":"unaffected","lessThan":"6.18","versionType":"semver"},{"version":"6.18.65","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/helpers.c"]}],"references":[{"url":"https://git.kernel.org/stable/c/fd91c41b1d4ab85ce806d61c8e5b7add292046dc"},{"url":"https://git.kernel.org/stable/c/2fd1c3f2128a59d118e6656dcbd065a588a5aac7"},{"url":"https://git.kernel.org/stable/c/c961f7b41a108313a4705baac7b27d2174cc8035"}],"providerMetadata":{"shortName":"Linux","orgId":"416baaa9-dc9f-4396-8d5f-8c081fb06d67","dateUpdated":"2026-11-30T13:33:54.743Z"},"cpeApplicability":[{"nodes":[{"operator":"OR","negate":false,"cpeMatch":[{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.18","versionEndExcluding":"6.18.65"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.18","versionEndExcluding":"7.3.6"},{"vulnerable":true,"criteria":"cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*","versionStartIncluding":"6.18","versionEndExcluding":"7.4-rc1"}]}]}],"x_generator":{"engine":"bippy-1.2.0"}}}}}