CVE-2024-26596 in Linux
Summary
by MITRE • 02/23/2024
In the Linux kernel, the following vulnerability has been resolved:
net: dsa: fix netdev_priv() dereference before check on non-DSA netdevice events
After the blamed commit, we started doing this dereference for every NETDEV_CHANGEUPPER and NETDEV_PRECHANGEUPPER event in the system.
static inline struct dsa_port *dsa_user_to_port(const struct net_device *dev) {
struct dsa_user_priv *p = netdev_priv(dev);
return p->dp; }
Which is obviously bogus, because not all net_devices have a netdev_priv() of type struct dsa_user_priv. But struct dsa_user_priv is fairly small, and p->dp means dereferencing 8 bytes starting with offset 16. Most drivers allocate that much private memory anyway, making our access not fault, and we discard the bogus data quickly afterwards, so this wasn't caught.
But the dummy interface is somewhat special in that it calls alloc_netdev() with a priv size of 0. So every netdev_priv() dereference is invalid, and we get this when we emit a NETDEV_PRECHANGEUPPER event with a VLAN as its new upper:
$ ip link add dummy1 type dummy $ ip link add link dummy1 name dummy1.100 type vlan id 100 [ 43.309174] ==================================================================
[ 43.316456] BUG: KASAN: slab-out-of-bounds in dsa_user_prechangeupper+0x30/0xe8
[ 43.323835] Read of size 8 at addr ffff3f86481d2990 by task ip/374
[ 43.330058]
[ 43.342436] Call trace:
[ 43.366542] dsa_user_prechangeupper+0x30/0xe8
[ 43.371024] dsa_user_netdevice_event+0xb38/0xee8
[ 43.375768] notifier_call_chain+0xa4/0x210
[ 43.379985] raw_notifier_call_chain+0x24/0x38
[ 43.384464] __netdev_upper_dev_link+0x3ec/0x5d8
[ 43.389120] netdev_upper_dev_link+0x70/0xa8
[ 43.393424] register_vlan_dev+0x1bc/0x310
[ 43.397554] vlan_newlink+0x210/0x248
[ 43.401247] rtnl_newlink+0x9fc/0xe30
[ 43.404942] rtnetlink_rcv_msg+0x378/0x580
Avoid the kernel oops by dereferencing after the type check, as customary.
VulDB is the best source for vulnerability data and more expert information about this specific topic.
Analysis
by VulDB Data Team • 12/14/2024
The vulnerability described in CVE-2024-26596 affects the Linux kernel's Distributed Switch Architecture implementation, specifically within the netdev_priv() function handling during network device events. This issue stems from improper memory dereferencing that occurs when processing NETDEV_CHANGEUPPER and NETDEV_PRECHANGEUPPER events, particularly in scenarios involving DSA (Distributed Switch Architecture) netdevices. The flaw manifests when the kernel attempts to access private data structures without first validating that the target net_device actually possesses the expected private data layout. This vulnerability falls under CWE-476 which represents a NULL pointer dereference, and more specifically aligns with improper access to memory resources in kernel space operations.
The technical root cause lies in the dsa_user_to_port function where the code assumes all net_devices have a netdev_priv() of type struct dsa_user_priv without performing proper type validation first. The problematic code directly dereferences p->dp without checking if the device actually has the expected private data structure, leading to out-of-bounds memory access. This pattern becomes particularly dangerous when dealing with special interfaces like the dummy interface that uses alloc_netdev() with a priv size of zero, creating a scenario where any netdev_priv() dereference results in invalid memory access. The kernel's memory safety mechanisms, such as KASAN (Kernel Address Sanitizer), detect this violation with a slab-out-of-bounds error, indicating that the code attempts to read 8 bytes at an address that falls outside the allocated memory boundaries.
The operational impact of this vulnerability is significant as it can lead to kernel oops, system crashes, and potential denial of service conditions within network switching environments. When processing network device events involving VLAN interfaces, the kernel's handling of upper device links triggers the faulty code path, resulting in immediate system instability. This vulnerability affects systems utilizing DSA networking capabilities where multiple network interfaces are managed through a distributed switching architecture, making it particularly relevant for enterprise networking equipment, routers, and network switches running Linux-based operating systems. The issue demonstrates how seemingly minor code ordering problems in kernel space can result in critical system failures, especially when combined with specific interface configurations that expose the memory access violation.
Mitigation strategies for this vulnerability involve correcting the code logic to perform type validation before memory dereferencing operations, which aligns with standard kernel development practices and security guidelines. The fix requires reordering the operations to check the device type or private data structure validity before attempting to access the dsa_user_priv fields. This approach follows the principle of defensive programming commonly recommended in secure coding standards and aligns with ATT&CK technique T1068 which involves privilege escalation through kernel vulnerabilities. System administrators should apply the relevant kernel patches as soon as they become available, particularly in environments running Linux kernel versions containing the vulnerable code. Organizations utilizing DSA networking features should prioritize patching to prevent potential exploitation that could lead to unauthorized access or service disruption in network infrastructure components.