CVE-2025-40254: net: openvswitch: remove never-working support for setting nsh fields
In the Linux kernel, the following vulnerability has been resolved:
net: openvswitch: remove never-working support for setting nsh fields
The validation of the set(nsh(...)) action is completely wrong. It runs through the nshkeyputfromnlattr() function that is the same function that validates NSH keys for the flow match and the pushnsh() action. However, the set(nsh(...)) has a very different memory layout. Nested attributes in there are doubled in size in case of the masked set(). That makes proper validation impossible.
There is also confusion in the code between the 'masked' flag, that says that the nested attributes are doubled in size containing both the value and the mask, and the 'ismask' that says that the value we're parsing is the mask. This is causing kernel crash on trying to write into mask part of the match with SWFLOWKEYPUT() during validation, while validatensh() doesn't allocate any memory for it:
BUG: kernel NULL pointer dereference, address: 0000000000000018 #PF: supervisor read access in kernel mode #PF: errorcode(0x0000) - not-present page PGD 1c2383067 P4D 1c2383067 PUD 20b703067 PMD 0 Oops: Oops: 0000 [#1] SMP NOPTI CPU: 8 UID: 0 Kdump: loaded Not tainted 6.17.0-rc4+ #107 PREEMPT(voluntary) RIP: 0010:nshkeyputfromnlattr+0x19d/0x610 [openvswitch] Call Trace: <TASK> validatensh+0x60/0x90 [openvswitch] validateset.constprop.0+0x270/0x3c0 [openvswitch] ovsnlacopyactions+0x477/0x860 [openvswitch] ovsnlacopyactions+0x8d/0x100 [openvswitch] ovspacketcmdexecute+0x1cc/0x310 [openvswitch] genlfamilyrcvmsgdoit+0xdb/0x130 genlfamilyrcvmsg+0x14b/0x220 genlrcvmsg+0x47/0xa0 netlinkrcvskb+0x53/0x100 genlrcv+0x24/0x40 netlinkunicast+0x280/0x3b0 netlinksendmsg+0x1f7/0x430 syssendmsg+0x36b/0x3a0 syssendmsg+0x87/0xd0 syssendmsg+0x6d/0xd0 dosyscall64+0x7b/0x2c0 entrySYSCALL64afterhwframe+0x76/0x7e
The third issue with this process is that while trying to convert the non-masked set into masked one, validateset() copies and doubles the size of the OVSKEYATTRNSH as if it didn't have any nested attributes. It should be copying each nested attribute and doubling them in size independently. And the process must be properly reversed during the conversion back from masked to a non-masked variant during the flow dump.
In the end, the only two outcomes of trying to use this action are either validation failure or a kernel crash. And if somehow someone manages to install a flow with such an action, it will most definitely not do what it is supposed to, since all the keys and the masks are mixed up.
Fixing all the issues is a complex task as it requires re-writing most of the validation code.
Given that and the fact that this functionality never worked since introduction, let's just remove it altogether. It's better to re-introduce it later with a proper implementation instead of trying to fix it in stable releases.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Remove
Remove
openvswitch kernel module: set(nsh(...)) action supportfrom your environment.Ensure the kernel/Open vSwitch installation does not include the never-working set(nsh(...)) action: apply the upstream change that removes support for setting NSH fields from the Open vSwitch kernel code or install a kernel that contains this removal.
- Operational
Audit Open vSwitch flows and remove any flows that include the set(nsh(...)) action. Do not use the set(nsh(...)) action until it is reintroduced with a proper implementation; replace or reconfigure flows to avoid relying on this action.
Event History
Frequently Asked Questions
What is the severity of CVE-2025-40254?
CVE-2025-40254 has a potential severity that requires monitoring, particularly in networking environments using the affected Open vSwitch functionality.
How do I fix CVE-2025-40254?
To fix CVE-2025-40254, update the Linux kernel to the latest stable version that includes the patch addressing this vulnerability.
What systems are impacted by CVE-2025-40254?
CVE-2025-40254 primarily affects systems running the Linux kernel with implementations of Open vSwitch.
Is CVE-2025-40254 exploitable remotely?
The specifics of CVE-2025-40254 indicate that exploitation may depend on network configurations, making it potentially exploitable in certain scenarios.
What are the symptoms of being affected by CVE-2025-40254?
Symptoms of CVE-2025-40254 may include abnormal network behavior or failures in traffic processing features that utilize the Open vSwitch.