{
    "dataType": "CVE_RECORD",
    "dataVersion": "5.2",
    "cveMetadata": {
        "cveId": "CVE-2025-21825",
        "assignerOrgId": "416baaa9-dc9f-4396-8d5f-8c081fb06d67",
        "state": "PUBLISHED",
        "assignerShortName": "Linux",
        "dateReserved": "2024-12-29T08:45:45.775Z",
        "datePublished": "2025-03-06T16:04:31.576Z",
        "dateUpdated": "2026-08-05T11:54:42.159Z"
    },
    "containers": {
        "cna": {
            "providerMetadata": {
                "orgId": "416baaa9-dc9f-4396-8d5f-8c081fb06d67",
                "shortName": "Linux",
                "dateUpdated": "2026-08-05T11:54:42.159Z"
            },
            "descriptions": [
                {
                    "lang": "en",
                    "value": "In the Linux kernel, the following vulnerability has been resolved:\n\nbpf: Cancel the running bpf_timer through kworker for PREEMPT_RT\n\nDuring the update procedure, when overwrite element in a pre-allocated\nhtab, the freeing of old_element is protected by the bucket lock. The\nreason why the bucket lock is necessary is that the old_element has\nalready been stashed in htab->extra_elems after alloc_htab_elem()\nreturns. If freeing the old_element after the bucket lock is unlocked,\nthe stashed element may be reused by concurrent update procedure and the\nfreeing of old_element will run concurrently with the reuse of the\nold_element. However, the invocation of check_and_free_fields() may\nacquire a spin-lock which violates the lockdep rule because its caller\nhas already held a raw-spin-lock (bucket lock). The following warning\nwill be reported when such race happens:\n\n  BUG: scheduling while atomic: test_progs/676/0x00000003\n  3 locks held by test_progs/676:\n  #0: ffffffff864b0240 (rcu_read_lock_trace){....}-{0:0}, at: bpf_prog_test_run_syscall+0x2c0/0x830\n  #1: ffff88810e961188 (&htab->lockdep_key){....}-{2:2}, at: htab_map_update_elem+0x306/0x1500\n  #2: ffff8881f4eac1b8 (&base->softirq_expiry_lock){....}-{2:2}, at: hrtimer_cancel_wait_running+0xe9/0x1b0\n  Modules linked in: bpf_testmod(O)\n  Preemption disabled at:\n  [<ffffffff817837a3>] htab_map_update_elem+0x293/0x1500\n  CPU: 0 UID: 0 PID: 676 Comm: test_progs Tainted: G ... 6.12.0+ #11\n  Tainted: [W]=WARN, [O]=OOT_MODULE\n  Hardware name: QEMU Standard PC (i440FX + PIIX, 1996)...\n  Call Trace:\n  <TASK>\n  dump_stack_lvl+0x57/0x70\n  dump_stack+0x10/0x20\n  __schedule_bug+0x120/0x170\n  __schedule+0x300c/0x4800\n  schedule_rtlock+0x37/0x60\n  rtlock_slowlock_locked+0x6d9/0x54c0\n  rt_spin_lock+0x168/0x230\n  hrtimer_cancel_wait_running+0xe9/0x1b0\n  hrtimer_cancel+0x24/0x30\n  bpf_timer_delete_work+0x1d/0x40\n  bpf_timer_cancel_and_free+0x5e/0x80\n  bpf_obj_free_fields+0x262/0x4a0\n  check_and_free_fields+0x1d0/0x280\n  htab_map_update_elem+0x7fc/0x1500\n  bpf_prog_9f90bc20768e0cb9_overwrite_cb+0x3f/0x43\n  bpf_prog_ea601c4649694dbd_overwrite_timer+0x5d/0x7e\n  bpf_prog_test_run_syscall+0x322/0x830\n  __sys_bpf+0x135d/0x3ca0\n  __x64_sys_bpf+0x75/0xb0\n  x64_sys_call+0x1b5/0xa10\n  do_syscall_64+0x3b/0xc0\n  entry_SYSCALL_64_after_hwframe+0x4b/0x53\n  ...\n  </TASK>\n\nIt seems feasible to break the reuse and refill of per-cpu extra_elems\ninto two independent parts: reuse the per-cpu extra_elems with bucket\nlock being held and refill the old_element as per-cpu extra_elems after\nthe bucket lock is unlocked. However, it will make the concurrent\noverwrite procedures on the same CPU return unexpected -E2BIG error when\nthe map is full.\n\nTherefore, the patch fixes the lock problem by breaking the cancelling\nof bpf_timer into two steps for PREEMPT_RT:\n1) use hrtimer_try_to_cancel() and check its return value\n2) if the timer is running, use hrtimer_cancel() through a kworker to\n   cancel it again\nConsidering that the current implementation of hrtimer_cancel() will try\nto acquire a being held softirq_expiry_lock when the current timer is\nrunning, these steps above are reasonable. However, it also has\ndownside. When the timer is running, the cancelling of the timer is\ndelayed when releasing the last map uref. The delay is also fixable\n(e.g., break the cancelling of bpf timer into two parts: one part in\nlocked scope, another one in unlocked scope), it can be revised later if\nnecessary.\n\nIt is a bit hard to decide the right fix tag. One reason is that the\nproblem depends on PREEMPT_RT which is enabled in v6.12. Considering the\nsoftirq_expiry_lock lock exists since v5.4 and bpf_timer is introduced\nin v5.15, the bpf_timer commit is used in the fixes tag and an extra\ndepends-on tag is added to state the dependency on PREEMPT_RT.\n\nDepends-on: v6.12+ with PREEMPT_RT enabled"
                }
            ],
            "metrics": [
                {
                    "cvssV3_1": {
                        "version": "3.1",
                        "vectorString": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H",
                        "baseScore": 7.8,
                        "baseSeverity": "HIGH"
                    },
                    "scenarios": [
                        {
                            "lang": "en",
                            "value": "AV:L - The vulnerable path is entered through the bpf() syscall (BPF_MAP_UPDATE_ELEM / BPF_MAP_DELETE_ELEM on a preallocated hash map, or a BPF program performing the update), which requires local access to the system. There is no remote or adjacent-network trigger.\nAC:L - The attacker controls both sides of the race: it arms the bpf_timer, authors the callback (which can be made to run for milliseconds via bpf_loop, keeping softirq_expiry_lock held and hrtimer_try_to_cancel() returning -1 the whole time), and hammers map_update_elem from another CPU, making the hit near-deterministic — as the upstream selftest demonstrates.\nPR:L - The bpf_timer helpers and map creation are gated on bpf_token_capable(CAP_BPF), which resolves to bpf_ns_capable() and is therefore delegable into an unprivileged user namespace via a BPF token, and the overwrite itself only needs write access to the map fd (e.g. a bpffs-pinned map). This is consistent with the CNA's PR:L treatment of other BPF-subsystem CVEs.\nUI:N - The attacker performs every step itself — creating the map, arming the timer, and issuing the overwriting update. No action by any other user or administrator is needed.\nS:U - The corruption and the lockup are confined to kernel memory and the kernel's own scheduling state, within the same security authority. No VM, IOMMU, or sandbox boundary is crossed.\nC:H - Sleeping mid-bpf_obj_free_fields() breaks the non-preemptible window that protects htab->extra_elems, letting another task on the same CPU re-install the element while its special fields are still being torn down — yielding a use-after-free on kptr-referenced kernel objects that can be leveraged for arbitrary kernel memory disclosure.\nI:H - The same reuse window causes bpf_obj_free_fields() to xchg-and-drop kptrs and cancel timers belonging to a live map element, producing refcount underflow and double-free of refcounted kernel objects — a classic heap-corruption write primitive usable for control-flow hijack.\nA:H - The immediate symptom is a \"BUG: scheduling while atomic\" splat (a panic under panic_on_warn), and the task deschedules while holding the bucket raw spinlock with hardirqs disabled, so other CPUs spin on it indefinitely — leading to hard lockup, deadlock against the timer softirq thread, or panic from the resulting UAF."
                        }
                    ]
                }
            ],
            "affected": [
                {
                    "product": "Linux",
                    "vendor": "Linux",
                    "defaultStatus": "unaffected",
                    "repo": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git",
                    "programFiles": [
                        "kernel/bpf/helpers.c"
                    ],
                    "versions": [
                        {
                            "version": "b00628b1c7d595ae5b544e059c27b1f5828314b4",
                            "lessThan": "33e47d9573075342a41783a55c8c67bc71246fc1",
                            "status": "affected",
                            "versionType": "git"
                        },
                        {
                            "version": "b00628b1c7d595ae5b544e059c27b1f5828314b4",
                            "lessThan": "fbeda3d939ca10063aafa7a77cc0f409d82cda88",
                            "status": "affected",
                            "versionType": "git"
                        },
                        {
                            "version": "b00628b1c7d595ae5b544e059c27b1f5828314b4",
                            "lessThan": "58f038e6d209d2dd862fcf5de55407855856794d",
                            "status": "affected",
                            "versionType": "git"
                        }
                    ]
                },
                {
                    "product": "Linux",
                    "vendor": "Linux",
                    "defaultStatus": "affected",
                    "repo": "https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git",
                    "programFiles": [
                        "kernel/bpf/helpers.c"
                    ],
                    "versions": [
                        {
                            "version": "5.15",
                            "status": "affected"
                        },
                        {
                            "version": "0",
                            "lessThan": "5.15",
                            "status": "unaffected",
                            "versionType": "semver"
                        },
                        {
                            "version": "6.12.13",
                            "lessThanOrEqual": "6.12.*",
                            "status": "unaffected",
                            "versionType": "semver"
                        },
                        {
                            "version": "6.13.2",
                            "lessThanOrEqual": "6.13.*",
                            "status": "unaffected",
                            "versionType": "semver"
                        },
                        {
                            "version": "6.14",
                            "lessThanOrEqual": "*",
                            "status": "unaffected",
                            "versionType": "original_commit_for_fix"
                        }
                    ]
                }
            ],
            "cpeApplicability": [
                {
                    "nodes": [
                        {
                            "operator": "OR",
                            "negate": false,
                            "cpeMatch": [
                                {
                                    "vulnerable": true,
                                    "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*",
                                    "versionStartIncluding": "5.15",
                                    "versionEndExcluding": "6.12.13"
                                },
                                {
                                    "vulnerable": true,
                                    "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*",
                                    "versionStartIncluding": "5.15",
                                    "versionEndExcluding": "6.13.2"
                                },
                                {
                                    "vulnerable": true,
                                    "criteria": "cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*",
                                    "versionStartIncluding": "5.15",
                                    "versionEndExcluding": "6.14"
                                }
                            ]
                        }
                    ]
                }
            ],
            "references": [
                {
                    "url": "https://git.kernel.org/stable/c/33e47d9573075342a41783a55c8c67bc71246fc1"
                },
                {
                    "url": "https://git.kernel.org/stable/c/fbeda3d939ca10063aafa7a77cc0f409d82cda88"
                },
                {
                    "url": "https://git.kernel.org/stable/c/58f038e6d209d2dd862fcf5de55407855856794d"
                }
            ],
            "title": "bpf: Cancel the running bpf_timer through kworker for PREEMPT_RT",
            "x_generator": {
                "engine": "bippy-1.2.0"
            }
        }
    }
}