{
  "schema_version": "1.6.1",
  "id": "RPI-CVE-2024-50059",
  "modified": "2026-10-09T11:39:44Z",
  "upstream": [
    "CVE-2024-50059"
  ],
  "published": "2024-10-21T19:40:44Z",
  "summary": "ntb: ntb_hw_switchtec: Fix use after free vulnerability in switchtec_ntb_remove due to race condition",
  "details": "In the Linux kernel, the following vulnerability has been resolved:\n\nntb: ntb_hw_switchtec: Fix use after free vulnerability in switchtec_ntb_remove due to race condition\n\nIn the switchtec_ntb_add function, it can call switchtec_ntb_init_sndev\nfunction, then &sndev->check_link_status_work is bound with\ncheck_link_status_work. switchtec_ntb_link_notification may be called\nto start the work.\n\nIf we remove the module which will call switchtec_ntb_remove to make\ncleanup, it will free sndev through kfree(sndev), while the work\nmentioned above will be used. The sequence of operations that may lead\nto a UAF bug is as follows:\n\nCPU0                                 CPU1\n\n                        | check_link_status_work\nswitchtec_ntb_remove    |\nkfree(sndev);           |\n                        | if (sndev->link_force_down)\n                        | // use sndev\n\nFix it by ensuring that the work is canceled before proceeding with\nthe cleanup in switchtec_ntb_remove.",
  "severity": [
    {
      "type": "CVSS_V3",
      "score": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H"
    }
  ],
  "affected": [
    {
      "package": {
        "ecosystem": "Raspberry Pi OS:12",
        "name": "linux"
      },
      "versions": [
        "1:6.1.47-1+rpt4"
      ],
      "ecosystem_specific": {
        "binaries": [
          {
            "binary_name": "linux-image-6.1.0-rpi3-rpi-2712",
            "binary_version": "1:6.1.47-1+rpt4"
          },
          {
            "binary_name": "linux-image-6.1.0-rpi3-rpi-v6",
            "binary_version": "1:6.1.47-1+rpt4"
          },
          {
            "binary_name": "linux-image-6.1.0-rpi3-rpi-v7",
            "binary_version": "1:6.1.47-1+rpt4"
          },
          {
            "binary_name": "linux-image-6.1.0-rpi3-rpi-v7l",
            "binary_version": "1:6.1.47-1+rpt4"
          },
          {
            "binary_name": "linux-image-6.1.0-rpi3-rpi-v8",
            "binary_version": "1:6.1.47-1+rpt4"
          }
        ]
      },
      "database_specific": {
        "per_version": {
          "1:6.1.47-1+rpt4": {
            "linux_commit": "655fc658a15ae7a6f37103754adb39ba52a9a14e",
            "upstream_version": "6.1.47",
            "assessment": "commit ancestry (strak rule)",
            "upstream_fixed": "6.1.113",
            "compiled_filter": false
          }
        }
      }
    }
  ],
  "references": [
    {
      "type": "ADVISORY",
      "url": "https://www.cve.org/CVERecord?id=CVE-2024-50059"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/5126d8f5567f49b52e21fca320eaa97977055099"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/b650189687822b705711f0567a65a164a314d8df"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/92728fceefdaa2a0a3aae675f86193b006eeaa43"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/3ae45be8492460a35b5aebf6acac1f1d32708946"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/fa840ba4bd9f3bad7f104e5b32028ee73af8b3dd"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/177925d9c8715a897bb79eca62628862213ba956"
    },
    {
      "type": "FIX",
      "url": "https://git.kernel.org/stable/c/e51aded92d42784313ba16c12f4f88cc4f973bbb"
    }
  ],
  "database_specific": {
    "source": "https://git.kernel.org/pub/scm/linux/security/vulns.git",
    "upstream_modified": "2026-08-05T11:52:36Z",
    "severity": {
      "source": "kernel CNA",
      "cvss_v3_score": 7.8,
      "cvss_v3_severity": "High",
      "scenario": "AV:L - The freeing side of the race is driver teardown, entered only through local actions \u2014 `rmmod ntb_hw_switchtec`, a write to `/sys/bus/pci/drivers/switchtec/unbind`, or `/sys/bus/pci/devices/.../remove` \u2014 and the racing side arrives over the PCIe/NTB fabric rather than a network stack. No network or adjacent-network protocol reaches this code, so local system access is the entry point.\nAC:L - The attacker controls both sides: the NTB peer host (or a local user driving the Switchtec management device) can send `LINK_MESSAGE`/`MSG_LINK_FORCE_DOWN` continuously so `check_link_status_work` is always pending, and `switchtec_ntb_part_op()` then sleeps up to 1000\u00d750 ms inside the object, holding the window open for tens of seconds while teardown is triggered. Bind/unbind can also be repeated indefinitely, so success depends on nothing outside the attacker's influence.\nPR:L - The side that keeps the work item live requires no privilege \u2014 it is driven by the NTB peer host's link messages, by PCIe link-state events, or by non-CAP_SYS_ADMIN MRPC commands on `/dev/switchtecN` (the driver explicitly gates only GAS read/write on CAP_SYS_ADMIN) \u2014 while the `kfree()` occurs on any device removal, including surprise PCIe hot-remove and routine administrative unbind. Consistent with the scoring of the equivalent driver remove-path work-item UAFs (e.g. CVE-2024-57984), low local privileges are the defensible assumption.\nUI:N - The removal and the link-message traffic are both initiated by the attacker or generated autonomously by the PCIe hardware; no victim must mount a filesystem, open a file, or take any other action. Exploitation completes entirely from the attacker's own operations.\nS:U - The use-after-free corrupts kernel heap state and is exploited within the same kernel security authority that owns the driver. No hypervisor, IOMMU, or sandbox boundary is crossed by the vulnerability itself.\nC:H - After `kfree(sndev)` the worker reads `link_force_down`, `mmio_ntb`, `mmio_peer_ctrl`, `mmio_peer_dbmsg`, `self_shared_dma`, `peer_direct_mw_to_bar[]` and `stdev->dev` back out of freed memory, and the ~50-second sleep inside `switchtec_ntb_part_op()` makes slab reclaim by an attacker-sprayed object highly practical, converting the dangling object into a controlled kernel read primitive. Per use-after-free scoring guidance this is High.\nI:H - `ntb_link_event()` performs `ntb->ctx_ops->link_event(ntb->ctx)` \u2014 an indirect branch through a function pointer read from freed memory \u2014 and `config_rsvd_lut_win()` issues `iowrite32`/`iowrite64` to `&ctl->bar_entry[peer_bar]`/`&ctl->lut_entry[]` with base pointer, index and payload all taken from the freed object, giving both control-flow hijack and a controlled write (including reprogramming of the NTB DMA translation window) after heap spraying.\nA:H - Even without successful exploitation, the worker takes a spinlock in freed memory, dereferences freed `__iomem` pointers and touches the device after teardown, and the concurrent `link_notifier`/`sndev` NULL stores add a NULL-pointer dereference path \u2014 any of which produces a kernel oops or panic."
    }
  }
}
