| 0/0 |
2026/10/01 01:32 |
flow |
assessment-security |
44m
Results: map[DenialOfService:true Explanation:**Root Cause Analysis**
The bug is a `WARNING` triggered in `skb_transport_header()` when processing an
IPv6 packet in the Open vSwitch (OVS) datapath.
When OVS extracts the flow key for an IPv6 packet via `key_extract_l3l4()` ->
`parse_ipv6hdr()`, it parses the IPv6 extension headers. If the packet is a
*later fragment* (i.e., the fragment offset is non-zero), `parse_ipv6hdr()`
correctly identifies it, sets the flow key's L4 protocol to `NEXTHDR_FRAGMENT`
(44), and returns early. Crucially, because it returns early, it skips the call
to `skb_set_transport_header()`, leaving `skb->transport_header` uninitialized
at its default value of `~0U`.
If the OVS datapath is configured with an action to modify the IPv6 header
(e.g., `OVS_ACTION_ATTR_SET` with IPv6 attributes, commonly used for NAT), the
datapath executes `set_ipv6()` -> `set_ipv6_addr()` -> `update_ipv6_checksum()`.
At the very beginning of `update_ipv6_checksum()`, the code unconditionally
calculates the transport length:
```c
int transport_len = skb->len - skb_transport_offset(skb);
```
Calling `skb_transport_offset(skb)` invokes `skb_transport_header(skb)`, which
contains a `DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb))`. Since
the transport header was never set for the later fragment, the warning is
triggered.
**Exploitability**
Despite the uninitialized transport header leading to a bogus `transport_len`
calculation, this bug is **not exploitable** for memory corruption.
After calculating `transport_len`, `update_ipv6_checksum()` checks the
`l4_proto` (which was passed down from `flow_key->ip.proto`):
```c
if (l4_proto == NEXTHDR_TCP) {
// ...
} else if (l4_proto == NEXTHDR_UDP) {
// ...
} else if (l4_proto == NEXTHDR_ICMP) {
// ...
}
```
Because the packet is a later fragment, `l4_proto` is `NEXTHDR_FRAGMENT` (44).
It does not match TCP (6), UDP (17), or ICMP (58). Consequently, the function
simply returns without attempting to update any L4 checksums. No out-of-bounds
reads or writes occur. The issue is strictly a false-positive warning spam.
**Access Vectors**
- **User Namespace:** The syzbot reproducer triggers this by directly injecting
a packet and executing actions via the `OVS_PACKET_CMD_EXECUTE` netlink command.
This command requires `CAP_NET_ADMIN` in the user namespace
(`GENL_UNS_ADMIN_PERM`), making it accessible to unprivileged users who can
create user namespaces.
- **Network / VM Guest / Peripheral:** In a real-world scenario, if an OVS
bridge is configured by an administrator with a flow that modifies IPv6
addresses (like NAT) without explicitly dropping fragments, any remote attacker,
VM guest, or malicious peripheral can trigger the warning by simply sending a
crafted IPv6 later fragment over the network.
- **Denial of Service:** While it does not crash the kernel by default, the
warning can spam the kernel logs (causing a minor DoS) or halt the system if
`panic_on_warn` is enabled. Exploitable:false FilesystemTrigger:false NetworkTrigger:true PeripheralTrigger:true RemoteTrigger:true Unprivileged:false UserNamespace:true VMGuestTrigger:true VMHostTrigger:false]
|
| 1/1 |
2026/10/01 01:32 |
action |
syz-repro-to-c-repro |
0m
Results: map[SimplifiedCRepro:// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// socket$nl_generic arguments: [
// domain: const = 0x10 (8 bytes)
// type: const = 0x3 (8 bytes)
// proto: const = 0x10 (4 bytes)
// ]
// returns sock_nl_generic
res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0x10);
if (res != -1)
r[0] = res;
// sendmsg$nl_generic arguments: [
// fd: sock_nl_generic (resource)
// msg: ptr[in, msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: nil
// addrlen: len = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// vec: ptr[in, iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {34 00 00 00 3f 00 01 00 01 00 00 00 00 00 00 00 01 02 00 00 00 00 00 00 0c 00 01 00 6f 76 73 2d 64 70 30 00 08 00 02 00 00 00 00 00 08 00 09 00 42 42 00} (length 0x33)
// }
// }
// }
// len: len = 0x34 (8 bytes)
// }
// }
// vlen: const = 0x1 (8 bytes)
// ctrl: const = 0x0 (8 bytes)
// ctrllen: const = 0x0 (8 bytes)
// f: send_flags = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// }
// }
// f: send_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x200000000100 = 0;
*(uint32_t*)0x200000000108 = 0;
*(uint64_t*)0x200000000110 = 0x200000000180;
*(uint64_t*)0x200000000180 = 0x200000000b40;
memcpy((void*)0x200000000b40, "... [truncated large byte array] ...", 51);
*(uint64_t*)0x200000000188 = 0x34;
*(uint64_t*)0x200000000118 = 1;
*(uint64_t*)0x200000000120 = 0;
*(uint64_t*)0x200000000128 = 0;
*(uint32_t*)0x200000000130 = 0;
syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000100ul, /*f=*/0ul);
// sendmsg$nl_generic arguments: [
// fd: sock_nl_generic (resource)
// msg: ptr[in, msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: nil
// addrlen: len = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// vec: ptr[in, iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {c8 00 00 00 42 00 01 00 02 00 00 00 00 00 00 00 03 01 00 00 42 42 00 00 50 00 01 00 aa bb cc dd ee e1 aa bb cc dd ee e2 86 dd 60 00 00 00 00 14 2c 40 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 02 04 d2 00 50 00 00 00 00 00 00 00 00 50 02 10 00 00 00 00 00 00 00 04 00 02 00 5c 00 03 00 58 00 0b 00 54 00 08 00 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 99 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00} (length 0xb2)
// }
// }
// }
// len: len = 0xc8 (8 bytes)
// }
// }
// vlen: const = 0x1 (8 bytes)
// ctrl: const = 0x0 (8 bytes)
// ctrllen: const = 0x0 (8 bytes)
// f: send_flags = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// }
// }
// f: send_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x200000000040 = 0;
*(uint32_t*)0x200000000048 = 0;
*(uint64_t*)0x200000000050 = 0x200000000280;
*(uint64_t*)0x200000000280 = 0x200000000c40;
memcpy((void*)0x200000000c40, "... [truncated large byte array] ...", 178);
*(uint64_t*)0x200000000288 = 0xc8;
*(uint64_t*)0x200000000058 = 1;
*(uint64_t*)0x200000000060 = 0;
*(uint64_t*)0x200000000068 = 0;
*(uint32_t*)0x200000000070 = 0;
syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000040ul, /*f=*/0ul);
return 0;
}
]
|
| 2/1 |
2026/10/01 01:32 |
action |
kernel-checkouter |
0m
Results: map[KernelSrc:/app/workdir/cache/src/614dc76b1e7e3b2b23101132bdbfc47a3490f64e]
|
| 3/1 |
2026/10/01 01:32 |
action |
kernel-builder |
17m
Results: map[KernelObj:/app/workdir/cache/build/bbbd40e64a3829db270263f57e211367cc44963e]
|
| 4/1 |
2026/10/01 01:50 |
action |
codesearch-prepare |
12m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/10/01 02:02 |
agent |
expert |
13m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:true PeripheralTrigger:true RemoteTrigger:true Unprivileged:false UserNamespace:true VMGuestTrigger:true VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption, elevated privileges, or an information leak.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Information leaks are exploitable on their own and should be classified as such. A bug that copies kernel
memory contents to userspace (e.g. an out-of-bounds read whose result is returned to the caller, or
uninitialized stack/heap bytes written to a user buffer) is exploitable: it can reveal kernel pointer
values and defeat KASLR, expose sensitive data such as cryptographic keys or other processes' memory, and
serves as a necessary building block in most modern kernel privilege-escalation exploit chains. Do not classify
an information leak as non-exploitable solely because it does not directly cause a memory write or control-flow
hijack; the leak itself is the exploit primitive.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
ovs-dp0: entered promiscuous mode
------------[ cut here ]------------
!skb_transport_header_was_set(skb)
WARNING: ./include/linux/skbuff.h:3075 at skb_transport_header include/linux/skbuff.h:3075 [inline], CPU#1: syz-executor463/5635
WARNING: ./include/linux/skbuff.h:3075 at skb_transport_offset include/linux/skbuff.h:3250 [inline], CPU#1: syz-executor463/5635
WARNING: ./include/linux/skbuff.h:3075 at update_ipv6_checksum net/openvswitch/actions.c:361 [inline], CPU#1: syz-executor463/5635
WARNING: ./include/linux/skbuff.h:3075 at set_ipv6_addr+0x462/0x660 net/openvswitch/actions.c:399, CPU#1: syz-executor463/5635
Modules linked in:
CPU: 1 UID: 0 PID: 5635 Comm: syz-executor463 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 07/24/2026
RIP: 0010:skb_transport_header include/linux/skbuff.h:3075 [inline]
RIP: 0010:skb_transport_offset include/linux/skbuff.h:3250 [inline]
RIP: 0010:update_ipv6_checksum net/openvswitch/actions.c:361 [inline]
RIP: 0010:set_ipv6_addr+0x462/0x660 net/openvswitch/actions.c:399
Code: f6 e8 12 d3 05 00 ba 10 00 00 00 4c 89 ef 48 89 ee 48 83 c4 20 5b 41 5c 41 5d 41 5e 41 5f 5d e9 14 89 7a f6 e8 ff 80 0a f6 90 <0f> 0b 90 48 8b 44 24 10 42 0f b6 04 30 84 c0 0f 85 c8 01 00 00 41
RSP: 0018:ffffc90003b3ee68 EFLAGS: 00010293
RAX: ffffffff8bbd5b01 RBX: 000000000000ffff RCX: ffff8880780bbe80
RDX: 0000000000000000 RSI: 000000000000ffff RDI: 000000000000ffff
RBP: 000000000000004c R08: 0000000000000001 R09: 0000000000000011
R10: 000000000000001f R11: 0000000000000000 R12: ffff888071cdbd36
R13: ffff88802d028396 R14: dffffc0000000000 R15: ffff888071cdbc80
FS: 0000555579c36400(0000) GS:ffff888124dc5000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007ffd90696af0 CR3: 000000007065a000 CR4: 00000000003526f0
Call Trace:
<TASK>
set_ipv6 net/openvswitch/actions.c:531 [inline]
execute_masked_set_action net/openvswitch/actions.c:1073 [inline]
do_execute_actions+0x557e/0x8600 net/openvswitch/actions.c:1366
ovs_execute_actions+0xde/0x520 net/openvswitch/actions.c:1592
ovs_packet_cmd_execute+0xb4f/0xf10 net/openvswitch/datapath.c:705
genl_family_rcv_msg_doit+0x233/0x340 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0x614/0x7a0 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x226/0x4a0 net/netlink/af_netlink.c:2572
genl_rcv+0x28/0x40 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1335 [inline]
netlink_unicast+0x7bd/0x940 net/netlink/af_netlink.c:1361
netlink_sendmsg+0x813/0xb40 net/netlink/af_netlink.c:1916
sock_sendmsg_nosec+0x14e/0x190 net/socket.c:800
__sock_sendmsg net/socket.c:818 [inline]
____sys_sendmsg+0x54e/0x850 net/socket.c:2715
___sys_sendmsg+0x2a5/0x360 net/socket.c:2769
__sys_sendmsg net/socket.c:2801 [inline]
__do_sys_sendmsg net/socket.c:2806 [inline]
__se_sys_sendmsg net/socket.c:2804 [inline]
__x64_sys_sendmsg+0x1b1/0x290 net/socket.c:2804
do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
do_syscall_64+0x166/0x520 arch/x86/entry/syscall_64.c:84
entry_SYSCALL_64_after_hwframe+0x77/0x7f
RIP: 0033:0x7fe073a4fd39
Code: c0 79 93 eb d5 48 8d 7c 1d 00 eb 99 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 d8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffece969af8 EFLAGS: 00000246 ORIG_RAX: 000000000000002e
RAX: ffffffffffffffda RBX: 00007ffece969c28 RCX: 00007fe073a4fd39
RDX: 0000000000000000 RSI: 0000200000000040 RDI: 0000000000000003
RBP: 0000000000000001 R08: 00007ffece969c28 R09: 00007ffece969c28
R10: 0000000000000000 R11: 0000000000000246 R12: 00007ffece969c18
R13: 0000000000000002 R14: 00007fe073ae0ca0 R15: 0000000000000002
</TASK>
It is reproducible with the followint program.
Keep in mind that it may lack the precise threading, sandboxing, and some arguments of a working reproducer.
But it should give an idea of the involved syscalls.
// autogenerated by syzkaller (https://github.com/google/syzkaller)
#define _GNU_SOURCE
#include <endian.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mount.h>
#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
uint64_t r[1] = {0xffffffffffffffff};
int main(void)
{
syscall(__NR_mmap, /*addr=*/0x1ffffffff000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200000000000ul, /*len=*/0x1000000, /*prot=PROT_WRITE|PROT_READ|PROT_EXEC*/7ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
syscall(__NR_mmap, /*addr=*/0x200001000000ul, /*len=*/0x1000, /*prot=*/0ul, /*flags=MAP_FIXED|MAP_ANONYMOUS|MAP_PRIVATE*/0x32ul, /*fd=*/(intptr_t)-1, /*offset=*/0ul);
const char* reason;
(void)reason;
intptr_t res = 0;
if (write(1, "executing program\n", sizeof("executing program\n") - 1)) {}
// socket$nl_generic arguments: [
// domain: const = 0x10 (8 bytes)
// type: const = 0x3 (8 bytes)
// proto: const = 0x10 (4 bytes)
// ]
// returns sock_nl_generic
res = syscall(__NR_socket, /*domain=*/0x10ul, /*type=*/3ul, /*proto=*/0x10);
if (res != -1)
r[0] = res;
// sendmsg$nl_generic arguments: [
// fd: sock_nl_generic (resource)
// msg: ptr[in, msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: nil
// addrlen: len = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// vec: ptr[in, iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {34 00 00 00 3f 00 01 00 01 00 00 00 00 00 00 00 01 02 00 00 00 00 00 00 0c 00 01 00 6f 76 73 2d 64 70 30 00 08 00 02 00 00 00 00 00 08 00 09 00 42 42 00} (length 0x33)
// }
// }
// }
// len: len = 0x34 (8 bytes)
// }
// }
// vlen: const = 0x1 (8 bytes)
// ctrl: const = 0x0 (8 bytes)
// ctrllen: const = 0x0 (8 bytes)
// f: send_flags = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// }
// }
// f: send_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x200000000100 = 0;
*(uint32_t*)0x200000000108 = 0;
*(uint64_t*)0x200000000110 = 0x200000000180;
*(uint64_t*)0x200000000180 = 0x200000000b40;
memcpy((void*)0x200000000b40, "... [truncated large byte array] ...", 51);
*(uint64_t*)0x200000000188 = 0x34;
*(uint64_t*)0x200000000118 = 1;
*(uint64_t*)0x200000000120 = 0;
*(uint64_t*)0x200000000128 = 0;
*(uint32_t*)0x200000000130 = 0;
syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000100ul, /*f=*/0ul);
// sendmsg$nl_generic arguments: [
// fd: sock_nl_generic (resource)
// msg: ptr[in, msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// msghdr_netlink[netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: nil
// addrlen: len = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// vec: ptr[in, iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]]] {
// iovec[in, netlink_msg_t[netlink_random_msg_type, genlmsghdr, nl_generic_attr]] {
// addr: ptr[inout, array[ANYUNION]] {
// array[ANYUNION] {
// union ANYUNION {
// ANYBLOB: buffer: {c8 00 00 00 42 00 01 00 02 00 00 00 00 00 00 00 03 01 00 00 42 42 00 00 50 00 01 00 aa bb cc dd ee e1 aa bb cc dd ee e2 86 dd 60 00 00 00 00 14 2c 40 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 01 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 02 04 d2 00 50 00 00 00 00 00 00 00 00 50 02 10 00 00 00 00 00 00 00 04 00 02 00 5c 00 03 00 58 00 0b 00 54 00 08 00 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 99 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff 00 00} (length 0xb2)
// }
// }
// }
// len: len = 0xc8 (8 bytes)
// }
// }
// vlen: const = 0x1 (8 bytes)
// ctrl: const = 0x0 (8 bytes)
// ctrllen: const = 0x0 (8 bytes)
// f: send_flags = 0x0 (4 bytes)
// pad = 0x0 (4 bytes)
// }
// }
// f: send_flags = 0x0 (8 bytes)
// ]
*(uint64_t*)0x200000000040 = 0;
*(uint32_t*)0x200000000048 = 0;
*(uint64_t*)0x200000000050 = 0x200000000280;
*(uint64_t*)0x200000000280 = 0x200000000c40;
memcpy((void*)0x200000000c40, "... [truncated large byte array] ...", 178);
*(uint64_t*)0x200000000288 = 0xc8;
*(uint64_t*)0x200000000058 = 1;
*(uint64_t*)0x200000000060 = 0;
*(uint64_t*)0x200000000068 = 0;
*(uint32_t*)0x200000000070 = 0;
syscall(__NR_sendmsg, /*fd=*/r[0], /*msg=*/0x200000000040ul, /*f=*/0ul);
return 0;
}
Reply: **Root Cause Analysis**
The bug is a `WARNING` triggered in `skb_transport_header()` when processing an IPv6 packet in the Open vSwitch (OVS) datapath.
When OVS extracts the flow key for an IPv6 packet via `key_extract_l3l4()` -> `parse_ipv6hdr()`, it parses the IPv6 extension headers. If the packet is a *later fragment* (i.e., the fragment offset is non-zero), `parse_ipv6hdr()` correctly identifies it, sets the flow key's L4 protocol to `NEXTHDR_FRAGMENT` (44), and returns early. Crucially, because it returns early, it skips the call to `skb_set_transport_header()`, leaving `skb->transport_header` uninitialized at its default value of `~0U`.
If the OVS datapath is configured with an action to modify the IPv6 header (e.g., `OVS_ACTION_ATTR_SET` with IPv6 attributes, commonly used for NAT), the datapath executes `set_ipv6()` -> `set_ipv6_addr()` -> `update_ipv6_checksum()`.
At the very beginning of `update_ipv6_checksum()`, the code unconditionally calculates the transport length:
```c
int transport_len = skb->len - skb_transport_offset(skb);
```
Calling `skb_transport_offset(skb)` invokes `skb_transport_header(skb)`, which contains a `DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb))`. Since the transport header was never set for the later fragment, the warning is triggered.
**Exploitability**
Despite the uninitialized transport header leading to a bogus `transport_len` calculation, this bug is **not exploitable** for memory corruption.
After calculating `transport_len`, `update_ipv6_checksum()` checks the `l4_proto` (which was passed down from `flow_key->ip.proto`):
```c
if (l4_proto == NEXTHDR_TCP) {
// ...
} else if (l4_proto == NEXTHDR_UDP) {
// ...
} else if (l4_proto == NEXTHDR_ICMP) {
// ...
}
```
Because the packet is a later fragment, `l4_proto` is `NEXTHDR_FRAGMENT` (44). It does not match TCP (6), UDP (17), or ICMP (58). Consequently, the function simply returns without attempting to update any L4 checksums. No out-of-bounds reads or writes occur. The issue is strictly a false-positive warning spam.
**Access Vectors**
- **User Namespace:** The syzbot reproducer triggers this by directly injecting a packet and executing actions via the `OVS_PACKET_CMD_EXECUTE` netlink command. This command requires `CAP_NET_ADMIN` in the user namespace (`GENL_UNS_ADMIN_PERM`), making it accessible to unprivileged users who can create user namespaces.
- **Network / VM Guest / Peripheral:** In a real-world scenario, if an OVS bridge is configured by an administrator with a flow that modifies IPv6 addresses (like NAT) without explicitly dropping fragments, any remote attacker, VM guest, or malicious peripheral can trigger the warning by simply sending a crafted IPv6 later fragment over the network.
- **Denial of Service:** While it does not crash the kernel by default, the warning can spam the kernel logs (causing a minor DoS) or halt the system if `panic_on_warn` is enabled.
|
| 6/2 |
2026/10/01 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 9933
output: 39
thoughts: 81
Thoughts: **My Thought Process on the `skb_transport_header_was_set` Warning**
Right, so I'm digging into this `skb_transport_header_was_set` warning that's popping up in `update_ipv6_checksum`, which is located within `net/openvswitch/actions.c`. This isn't just some casual observation; it's a specific warning, and I'm trying to understand its implications. The warning itself, `!skb_transport_header_was_set(skb)`, clearly indicates that the transport header within the `skb` (socket buffer) has *not* been marked as set when `update_ipv6_checksum` expects it to be.
My immediate next step is to dive into the `update_ipv6_checksum` function itself. I need to see the context in which this check is happening. Why is `update_ipv6_checksum` relying on the transport header being pre-set? What operations is it performing, and how does the absence of a properly set transport header break those operations? Is it trying to access specific fields within the transport header that are simply not there or not properly initialized because the flag hasn't been flipped? Understanding the function's internal logic is crucial to diagnosing the root cause of this warning.
|
| 7/2 |
2026/10/01 02:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:update_ipv6_checksum]
Results: map[SourceCode: 358: static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
359: __be32 addr[4], const __be32 new_addr[4])
360: {
361: int transport_len = skb->len - skb_transport_offset(skb);
362:
363: if (l4_proto == NEXTHDR_TCP) {
364: if (likely(transport_len >= sizeof(struct tcphdr)))
365: inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
366: addr, new_addr, true);
367: } else if (l4_proto == NEXTHDR_UDP) {
368: if (likely(transport_len >= sizeof(struct udphdr))) {
369: struct udphdr *uh = udp_hdr(skb);
370:
371: if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
372: inet_proto_csum_replace16(&uh->check, skb,
373: addr, new_addr, true);
374: if (!uh->check)
375: uh->check = CSUM_MANGLED_0;
376: }
377: }
378: } else if (l4_proto == NEXTHDR_ICMP) {
379: if (likely(transport_len >= sizeof(struct icmp6hdr)))
380: inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
381: skb, addr, new_addr, true);
382: }
383: }
SourceFile:net/openvswitch/actions.c]
|
| 8/2 |
2026/10/01 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 10555
output: 39
thoughts: 98
Thoughts: **A Deep Dive into the `skb_transport_offset` Warning**
So, I'm noticing this warning pop up, and it's centered around `skb_transport_offset(skb)` on line 361. My first instinct is to trace the call chain. I see that `skb_transport_offset` is directly calling `skb_transport_header(skb)`. And within `skb_transport_header`, there's this `WARN_ON_ONCE(!skb_transport_header_was_set(skb))` macro. This immediately tells me the core of the issue: the transport header hasn't been properly set before we're trying to determine its offset.
My next step, naturally, is to investigate where this might be happening. I'm looking at the `set_ipv6_addr` function within `net/openvswitch/actions.c`. This seems like a plausible place for manipulation of network headers, and I suspect the problem lies in the sequence of operations within this function, or perhaps in how it's being called by other parts of the system. I need to scrutinize `set_ipv6_addr` to understand if it's correctly setting the transport header flags or pointers *before* any subsequent code attempts to access `skb_transport_offset`. It's likely that either the header is being skipped entirely, or it's being set in a way that `skb_transport_header_was_set` isn't recognizing, leading to this `WARN_ON_ONCE`.
|
| 9/2 |
2026/10/01 02:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:set_ipv6_addr]
Results: map[SourceCode: 394: static void set_ipv6_addr(struct sk_buff *skb, u8 l4_proto,
395: __be32 addr[4], const __be32 new_addr[4],
396: bool recalculate_csum)
397: {
398: if (recalculate_csum)
399: update_ipv6_checksum(skb, l4_proto, addr, new_addr);
400:
401: skb_clear_hash(skb);
402: ovs_ct_clear(skb, NULL);
403: memcpy(addr, new_addr, sizeof(__be32[4]));
404: }
SourceFile:net/openvswitch/actions.c]
|
| 10/2 |
2026/10/01 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 10902
output: 37
thoughts: 22
Thoughts: **My Thought Process Regarding `set_ipv6` in `net/openvswitch/actions.c`**
Okay, so my immediate impulse is to dive into the `net/openvswitch/actions.c` file and specifically examine the `set_ipv6` function. I'm assuming this function is the core logic for manipulating IPv6 header fields within Open vSwitch. My goal here is to understand *exactly* how it works, what parameters it takes, what fields it modifies, and importantly, what the implications of those modifications are. I'll be looking for things like:
* **How does it identify the target IPv6 field?** Is it by a specific header offset, a field name (like `ipv6_src` or `ipv6_dst`), or some other mechanism?
* **What kind of data does it expect as input for the new value?** Is it a raw byte string, a structured representation of an IPv6 address, or something else?
* **Does it handle any validation or error checking?** For instance, does it check if the provided address is syntactically valid, or if the modification would violate any IPv6 protocol rules?
* **What are the side effects of this operation?** Does it trigger recalculations of checksums, or impact other parts of the packet processing pipeline?
* **What is the context in which `set_ipv6` is typically called?** Is it part of a specific OpenFlow action (like `OFPAT_SET_FIELD`), or is it used internally for other purposes? Understanding its usage will give me a better grasp of its practical application.
Essentially, I want to get a granular, low-level understanding of the mechanics of `set_ipv6` so I can fully appreciate its role in shaping network traffic within the Open vSwitch environment. My expertise means I'm not just looking for a superficial description; I need to understand the underlying implementation details to confidently reason about packet transformations and potential network behavior.
|
| 11/2 |
2026/10/01 02:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:set_ipv6]
Results: map[SourceCode: 506: static int set_ipv6(struct sk_buff *skb, struct sw_flow_key *flow_key,
507: const struct ovs_key_ipv6 *key,
508: const struct ovs_key_ipv6 *mask)
509: {
510: struct ipv6hdr *nh;
511: int err;
512:
513: err = skb_ensure_writable(skb, skb_network_offset(skb) +
514: sizeof(struct ipv6hdr));
515: if (unlikely(err))
516: return err;
517:
518: nh = ipv6_hdr(skb);
519:
520: /* Setting an IP addresses is typically only a side effect of
521: * matching on them in the current userspace implementation, so it
522: * makes sense to check if the value actually changed.
523: */
524: if (is_ipv6_mask_nonzero(mask->ipv6_src)) {
525: __be32 *saddr = (__be32 *)&nh->saddr;
526: __be32 masked[4];
527:
528: mask_ipv6_addr(saddr, key->ipv6_src, mask->ipv6_src, masked);
529:
530: if (unlikely(memcmp(saddr, masked, sizeof(masked)))) {
531: set_ipv6_addr(skb, flow_key->ip.proto, saddr, masked,
532: true);
533: memcpy(&flow_key->ipv6.addr.src, masked,
534: sizeof(flow_key->ipv6.addr.src));
535: }
536: }
537: if (is_ipv6_mask_nonzero(mask->ipv6_dst)) {
538: unsigned int offset = 0;
539: int flags = IP6_FH_F_SKIP_RH;
540: bool recalc_csum = true;
541: __be32 *daddr = (__be32 *)&nh->daddr;
542: __be32 masked[4];
543:
544: mask_ipv6_addr(daddr, key->ipv6_dst, mask->ipv6_dst, masked);
545:
546: if (unlikely(memcmp(daddr, masked, sizeof(masked)))) {
547: if (ipv6_ext_hdr(nh->nexthdr))
548: recalc_csum = (ipv6_find_hdr(skb, &offset,
549: NEXTHDR_ROUTING,
550: NULL, &flags)
551: != NEXTHDR_ROUTING);
552:
553: set_ipv6_addr(skb, flow_key->ip.proto, daddr, masked,
554: recalc_csum);
555: memcpy(&flow_key->ipv6.addr.dst, masked,
556: sizeof(flow_key->ipv6.addr.dst));
557: }
558: }
559: if (mask->ipv6_tclass) {
560: set_ipv6_dsfield(skb, nh, key->ipv6_tclass, mask->ipv6_tclass);
561: flow_key->ip.tos = ipv6_get_dsfield(nh);
562: }
563: if (mask->ipv6_label) {
564: set_ipv6_fl(skb, nh, ntohl(key->ipv6_label),
565: ntohl(mask->ipv6_label));
566: flow_key->ipv6.label =
567: *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
568: }
569: if (mask->ipv6_hlimit) {
570: set_ipv6_ttl(skb, nh, key->ipv6_hlimit, mask->ipv6_hlimit);
571: flow_key->ip.ttl = nh->hop_limit;
572: }
573: return 0;
574: }
SourceFile:net/openvswitch/actions.c]
|
| 12/2 |
2026/10/01 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 12181
output: 38
thoughts: 261
Thoughts: **My Thought Process Regarding the `skb_transport_header_was_set` Warning**
Ah, I've encountered a warning, and I need to unpack precisely why it's firing. My immediate observation is that the condition `skb_transport_header_was_set(skb)` is evaluating to `false`. This tells me that the `skb->transport_header` field within the `sk_buff` structure is set to its sentinel value, `(u16)~0U`, which in practice means it's `0xffff`.
Now, I need to trace the code flow that leads to this state. I see that the `set_ipv6` function is being called. Following that down, I know `set_ipv6` invokes `set_ipv6_addr`, which in turn calls `update_ipv6_checksum`. It's within `update_ipv6_checksum` that I expect the problem to manifest.
Specifically, `update_ipv6_checksum` relies on `skb_transport_offset(skb)` to determine the `transport_len`. This is where the `0xffff` value of `skb->transport_header` becomes critical. Let's look at the definition of `skb_transport_offset(skb)`. My understanding is that it's calculated as either `skb->transport_header - skb->mac_header` or `skb->head + skb->transport_header - skb->data`. Given that `skb->transport_header` is `0xffff`, and assuming `skb->mac_header` or `skb->data` are more sensible, smaller values, this offset is going to be an extremely large positive number.
Consequently, when `transport_len` is calculated as `skb->len - skb_transport_offset(skb)`, this subtraction will result in a very large negative number. Since `transport_len` is declared as an `int`, it will indeed become negative. This unexpected negative value for the transport length is the root cause of the warning. I need to ensure that `skb->transport_header` is properly initialized before these functions are called.
|
| 13/2 |
2026/10/01 02:02 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/skbuff.h Name:skb_transport_offset]
Results: map[SourceCode:3248: static inline int skb_transport_offset(const struct sk_buff *skb)
3249: {
3250: return skb_transport_header(skb) - skb->data;
3251: }
SourceFile:include/linux/skbuff.h]
|
| 14/2 |
2026/10/01 02:02 |
llm |
expert |
0m
Model:
Tokens:
input: 12557
output: 38
thoughts: 9
Thoughts: **My Internal Monologue on `skb_transport_header`**
Ah, `skb_transport_header`. This is where things get really interesting, the nexus of where the packet is actually going, at least from the perspective of the transport layer. I'm thinking about how the `skb` (socket buffer) is this incredibly versatile structure, a fundamental building block in the Linux networking stack. It's not just a raw blob of bytes; it's a carefully managed entity, and its headers are meticulously organized to allow different layers of the network stack to efficiently access and manipulate the relevant data.
When I consider `skb_transport_header`, I'm immediately brought to the idea of abstraction and layering. This isn't the raw MAC layer frame, nor is it the application data itself. This is the header that defines the transport protocol in use – most commonly TCP or UDP. It's the layer that provides services like reliable delivery (TCP) or simple datagram transmission (UDP), and it's `skb_transport_header` that gives me a direct pointer into that specific part of the packet.
I'm thinking about the implications of this pointer. It's not just for reading; it's for *writing* too. When I'm processing incoming packets, this pointer allows me to quickly parse the TCP or UDP header, extract crucial information like source and destination ports, sequence numbers, acknowledgment numbers, flags, and length. This is essential for demultiplexing the packet to the correct socket and for performing error checking or reordering if it's TCP.
Conversely, when I'm constructing outgoing packets, I'll be using functions that effectively *set* `skb_transport_header`. This means I'm responsible for filling in the correct fields for the chosen transport protocol, ensuring that the packet will be correctly interpreted by the receiving end. It's about meticulously crafting that header, byte by byte, to convey the intended communication.
The elegance of `skb_transport_header` lies in its simplicity and directness. It cuts through the layers above and below, offering a focused view on the transport layer's concerns. It's a testament to the well-designed nature of the Linux networking stack, where key information is readily accessible through these carefully named pointers. It signifies the point where the packet transitions from being a network-level construct to something with more semantic meaning for the communicating endpoints. It's the gateway to understanding the actual *message* being sent.
|
| 15/2 |
2026/10/01 02:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/skbuff.h Name:skb_transport_header]
Results: map[SourceCode:3073: static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
3074: {
3075: DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb));
3076: return skb->head + skb->transport_header;
3077: }
SourceFile:include/linux/skbuff.h]
|
| 16/2 |
2026/10/01 02:03 |
llm |
expert |
0m
Model:
Tokens:
input: 12711
output: 84
thoughts: 583
Thoughts: **My Thought Process Regarding the `skb->transport_header` Issue**
Here's a breakdown of my internal deliberation on this potential bug:
My initial observation centered on the value of `skb->transport_header` being `0xffff`. I recalled that when this is the case, the `skb_transport_header` function simply returns `skb->head + 0xffff`.
Next, I examined `skb_transport_offset`. I understood this function as returning `skb->head + 0xffff - skb->data`.
Then, I looked at how `transport_len` is calculated within the `update_ipv6_checksum` function: `skb->len - skb_transport_offset(skb)`.
My first inclination was to assume `skb->data` is typically positioned just after `skb->head`, meaning `skb->head - skb->data` would be a negative offset. Consequently, `skb_transport_offset(skb)` would resolve to something like `0xffff - (skb->data - skb->head)`, which I roughly estimated to be around 65535 (since `0xffff` is 65535).
Given this, and knowing that `skb->len` is generally a much smaller value, I concluded that `transport_len` would be a small positive number minus a large number (65535). This would result in a negative `transport_len`.
My reasoning then led me to the conditional check: `if (likely(transport_len >= sizeof(struct tcphdr)))`. I reasoned that if `transport_len` is negative and `sizeof(struct tcphdr)` is a positive value, this condition would naturally be false.
However, a crucial realization dawned on me: the comparison is against `sizeof(struct tcphdr)`, which is of type `size_t` (an unsigned integer type). This meant that my negative `int` value for `transport_len` would be **promoted** to `size_t` for the comparison.
This promotion is the critical point. A negative integer, when converted to an unsigned type, wraps around to become a very large positive number. Therefore, a negative `transport_len` would, in fact, become a value significantly larger than `sizeof(struct tcphdr)`.
My analysis shifted: the condition `if (likely(transport_len >= sizeof(struct tcphdr)))` would now evaluate to **true**.
If this condition is true, the code proceeds to execute `inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb, addr, new_addr, true);`.
I then remembered that `tcp_hdr(skb)` internally relies on `skb_transport_header(skb)`. As established earlier, when `skb->transport_header` is `0xffff`, this resolves to `skb->head + 0xffff`.
This brings me to the core of the potential issue: the code is attempting to access memory at `skb->head + 0xffff` to get the `tcp_hdr(skb)`. Given that `skb->transport_header` being `0xffff` is an unusual configuration, and `skb->head` typically points to the start of the buffer, `skb->head + 0xffff` is highly likely to be an **out-of-bounds memory access**. This is because `0xffff` is a large offset, and the actual transport header (like TCP) is usually located much closer to `skb->data`.
My final step was to recognize the need to verify this line of reasoning by actually checking the code's behavior in the specified scenario.
|
| 17/2 |
2026/10/01 02:03 |
tool |
codeexpert |
1m
Args: map[Question:In `update_ipv6_checksum` (net/openvswitch/actions.c), `transport_len` is `int`. It is compared with `sizeof(struct tcphdr)`. Is this comparison signed or unsigned? If `transport_len` is negative, will it be greater than `sizeof(struct tcphdr)`?]
Results: map[Answer:The comparison is **unsigned**.
**Yes**, if `transport_len` is negative, it will evaluate as **greater than** `sizeof(struct tcphdr)`.
### Explanation:
1. **Unsigned Comparison**:
- In C, the `sizeof` operator yields a result of type `size_t`, which is an unsigned integer type (`unsigned long` on 64-bit architectures or `unsigned int` on 32-bit architectures).
- Under C's usual arithmetic conversions (C standard section 6.3.1.8), when an `int` (signed) is compared with `size_t` (unsigned type of equal or greater conversion rank), the `int` operand (`transport_len`) is implicitly converted to `size_t`.
- Therefore, the comparison `transport_len >= sizeof(struct tcphdr)` is performed as an **unsigned comparison**.
2. **Behavior when `transport_len` is negative**:
- When a negative signed integer is converted to an unsigned integer type of width $N$, the value is reduced modulo $2^N$ (i.e. interpreted as unsigned in two's complement).
- On a 64-bit system, a negative `int` converts to an `unsigned long` value $\ge 2^{64} - 2^{31}$ (for example, $-1$ converts to $2^{64} - 1 \approx 1.84 \times 10^{19}$).
- On a 32-bit system, a negative `int` converts to an `unsigned int` value $\ge 2^{31} \approx 2.15 \times 10^9$ (for example, $-1$ converts to $2^{32} - 1 \approx 4.29 \times 10^9$).
- Since `sizeof(struct tcphdr)` is only 20, any negative value of `transport_len` becomes an unsigned value vastly larger than 20. As a result, `transport_len >= sizeof(struct tcphdr)` evaluates to `true`.]
|
| 18/3 |
2026/10/01 02:03 |
agent |
codeexpert |
1m
Model:
Results: map[Answer:The comparison is **unsigned**.
**Yes**, if `transport_len` is negative, it will evaluate as **greater than** `sizeof(struct tcphdr)`.
### Explanation:
1. **Unsigned Comparison**:
- In C, the `sizeof` operator yields a result of type `size_t`, which is an unsigned integer type (`unsigned long` on 64-bit architectures or `unsigned int` on 32-bit architectures).
- Under C's usual arithmetic conversions (C standard section 6.3.1.8), when an `int` (signed) is compared with `size_t` (unsigned type of equal or greater conversion rank), the `int` operand (`transport_len`) is implicitly converted to `size_t`.
- Therefore, the comparison `transport_len >= sizeof(struct tcphdr)` is performed as an **unsigned comparison**.
2. **Behavior when `transport_len` is negative**:
- When a negative signed integer is converted to an unsigned integer type of width $N$, the value is reduced modulo $2^N$ (i.e. interpreted as unsigned in two's complement).
- On a 64-bit system, a negative `int` converts to an `unsigned long` value $\ge 2^{64} - 2^{31}$ (for example, $-1$ converts to $2^{64} - 1 \approx 1.84 \times 10^{19}$).
- On a 32-bit system, a negative `int` converts to an `unsigned int` value $\ge 2^{31} \approx 2.15 \times 10^9$ (for example, $-1$ converts to $2^{32} - 1 \approx 4.29 \times 10^9$).
- Since `sizeof(struct tcphdr)` is only 20, any negative value of `transport_len` becomes an unsigned value vastly larger than 20. As a result, `transport_len >= sizeof(struct tcphdr)` evaluates to `true`.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: In `update_ipv6_checksum` (net/openvswitch/actions.c), `transport_len` is `int`. It is compared with `sizeof(struct tcphdr)`. Is this comparison signed or unsigned? If `transport_len` is negative, will it be greater than `sizeof(struct tcphdr)`?
|
| 19/4 |
2026/10/01 02:03 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 3279
output: 39
thoughts: 125
Thoughts: **My Thought Process Regarding `update_ipv6_checksum` and Signed/Unsigned Comparisons**
My primary objective is to dissect the user's specific question about the `update_ipv6_checksum` function in the Open vSwitch codebase, focusing on the comparison between an `int` variable, `transport_len`, and `sizeof(struct tcphdr)`, which is an unsigned type. I need to determine the nature of this comparison and its implications, particularly when `transport_len` might hold a negative value.
To achieve this, my immediate action is to locate the relevant code. I'll use my established tools for code investigation, such as `codesearch-definition-source`, `grepper`, or a direct file read operation on `net/openvswitch/actions.c`, to pinpoint the `update_ipv6_checksum` function. My goal is to examine the exact line where `transport_len` is compared against `sizeof(struct tcphdr)`.
Once I have the code snippet, I'll analyze the data types involved. I know `sizeof()` returns a `size_t`, which is an unsigned integral type. The variable `transport_len` is explicitly stated as an `int`, which is a signed integral type. The core of the user's question lies in the behavior of the comparison operator (likely `<`, `>`, `<=`, or `>=`) when applied between these two different signedness types.
My understanding of C's type promotion rules dictates that when a signed and an unsigned integer type are used in an expression, the signed integer is typically converted to the unsigned type. This conversion is crucial. If `transport_len` is negative, its representation in the signed `int` type will, when converted to an unsigned type, result in a very large positive value.
Therefore, I anticipate that if `transport_len` is negative, it will indeed be *greater than* `sizeof(struct tcphdr)`, regardless of the actual value of `sizeof(struct tcphdr)` (which is typically a small, positive number representing the size of a TCP header in bytes). This is because the negative value, when reinterpreted as an unsigned integer, wraps around to a large positive number.
My summary will articulate this step-by-step analysis, confirming the presence of the `int transport_len` and its comparison with the unsigned `sizeof(struct tcphdr)`. I will explicitly state that this comparison, due to C's type promotion rules, will involve the conversion of the `int` to an unsigned type. I will then directly answer the user's question, explaining that a negative `transport_len` will, in this context, evaluate to a value larger than `sizeof(struct tcphdr)`. This provides the fulsome, first-person account of my reasoning as requested.
|
| 20/4 |
2026/10/01 02:03 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:update_ipv6_checksum]
Results: map[SourceCode: 358: static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
359: __be32 addr[4], const __be32 new_addr[4])
360: {
361: int transport_len = skb->len - skb_transport_offset(skb);
362:
363: if (l4_proto == NEXTHDR_TCP) {
364: if (likely(transport_len >= sizeof(struct tcphdr)))
365: inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
366: addr, new_addr, true);
367: } else if (l4_proto == NEXTHDR_UDP) {
368: if (likely(transport_len >= sizeof(struct udphdr))) {
369: struct udphdr *uh = udp_hdr(skb);
370:
371: if (uh->check || skb->ip_summed == CHECKSUM_PARTIAL) {
372: inet_proto_csum_replace16(&uh->check, skb,
373: addr, new_addr, true);
374: if (!uh->check)
375: uh->check = CSUM_MANGLED_0;
376: }
377: }
378: } else if (l4_proto == NEXTHDR_ICMP) {
379: if (likely(transport_len >= sizeof(struct icmp6hdr)))
380: inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
381: skb, addr, new_addr, true);
382: }
383: }
SourceFile:net/openvswitch/actions.c]
|
| 21/4 |
2026/10/01 02:03 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 3945
output: 56
thoughts: 98
Thoughts: **My Thought Process on Examining the `update_ipv6_checksum` Function**
My initial approach here is to dissect the problem by deeply understanding both the specific question posed and the underlying C language's behavior. I want to ensure my analysis is grounded in the established rules of the language. However, before diving straight into code implementation or abstract C principles, I recognize the critical value of context. Therefore, my immediate next step is to investigate the version control history, specifically focusing on Git. My intuition tells me that if there's a subtle issue or an interesting design choice at play, it's highly likely to be documented in commit messages or commit discussions.
This leads me to refine my investigation. Instead of a broad Git search, I'll focus my `git log` command on the `update_ipv6_checksum` function directly. This is a more targeted approach, aiming to uncover any specific commits that have modified this function, or perhaps even lines in its immediate vicinity (like line 364, or similar lines), that might be relevant to the question. The goal here is to see if a particular bug fix, performance optimization, or even a philosophical debate about C typing within the kernel has shaped this particular piece of code. I'm looking for evidence of a *deliberate* change or a known issue that was addressed, rather than just a generic C language quirk. Essentially, I'm trying to determine if this is a standard C typing puzzle or if it's a kernel-specific nuance that has been ironed out or debated through its commit history.
|
| 22/4 |
2026/10/01 02:03 |
tool |
git-log |
0m
Error:
Args: map[Count:5 PathPrefix:net/openvswitch/actions.c SourcePath:net/openvswitch/actions.c SymbolName:update_ipv6_checksum]
Results:
|
| 23/4 |
2026/10/01 02:03 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4099
output: 41
thoughts: 14
Thoughts: **My Thought Process on Debugging a Git-Related Issue**
My immediate instinct when encountering this issue is to leverage the power of `git log`. Specifically, I need to examine the commit history associated with a particular `SymbolName` and its corresponding `SourcePath`. This dual focus is crucial because I suspect the problem might lie in how changes to a specific symbol within a file are being tracked, or perhaps how a refactoring operation has affected the history of that particular code element and its location. By running `git log` with both these parameters, I'm aiming to isolate the relevant commits and scrutinize the sequence of changes, looking for any anomalies, unexpected modifications, or deviations from the expected development flow. This targeted approach will help me pinpoint the exact commit that introduced the problem or understand the evolution of the code that led to the current state.
|
| 24/4 |
2026/10/01 02:03 |
tool |
git-log |
0m
Args: map[Count:5 SourcePath:net/openvswitch/actions.c SymbolName:update_ipv6_checksum]
Results: map[Output:4b048d6d9d0b net: Change pseudohdr argument of inet_proto_csum_replace* to be a bool
856447d0209c openvswitch: Fix checksum calculation when modifying ICMPv6 packets.
3fdbd1ce11e5 openvswitch: add ipv6 'set' action
]
|
| 25/4 |
2026/10/01 02:03 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 4233
output: 27
thoughts: 23
Thoughts: **My Thought Process on Commit 856447d0209c (via git-show)**
Alright, so I've just pulled up commit `856447d0209c` using `git show`. My immediate goal is to get a comprehensive understanding of what this change entails, not just at a superficial level, but to really dig into the *why* behind it and its implications. As an expert in this domain, I'm looking for the underlying logic, the architectural considerations, and any potential ripple effects this commit might introduce.
First, I'm going to examine the commit message itself. Is it clear? Does it concisely explain the problem being solved and the approach taken? A good commit message, for someone like me, is a crucial starting point. It should offer context, hinting at the broader picture without getting bogged down in line-by-line explanations that the diff will provide. If it's vague or lacks detail, I know I'll need to spend more time scrutinizing the code.
Next, I'll dive into the diff. This is where the real meat is. I'm not just looking at what lines were added or removed; I'm mentally tracing the execution flow. What functions are being modified? Are new modules being introduced or existing ones refactored? I'm paying close attention to the *patterns* of change. Is this a small bug fix, a feature addition, a performance optimization, or a significant architectural shift? I'll be looking for how the change interacts with other parts of the codebase. Are there dependencies being introduced or altered? How does this impact the overall system's integrity and maintainability?
I'll also be considering the implications for existing functionality. Does this change introduce any regressions? Does it break any established contracts or APIs? Given my expertise, I'll be thinking about potential edge cases and error handling. Has the author considered all the scenarios, or are there blind spots that need to be addressed? I'll be scrutinizing the new logic for potential race conditions, memory leaks, or other subtle bugs that might not be immediately apparent.
Furthermore, I'll be evaluating the *quality* of the code itself. Is it idiomatic to the language and framework? Is it well-structured, readable, and maintainable? Are the variable names and function names descriptive? Is there appropriate commenting where necessary, without being excessive? This commit is a snapshot of the codebase, and I want to see if it aligns with our standards and best practices.
Finally, I'm considering the broader context of this commit. Where does it fit into the larger development roadmap? What problem is it ultimately trying to solve for the end-user or the system's stakeholders? By understanding the commit's purpose in relation to the project's goals, I can better assess its value and potential impact. It's about seeing the forest *and* the trees, understanding how this individual change contributes to the overall health and direction of the project. This commit, `856447d0209c`, is the lens through which I'm examining all these facets.
|
| 26/4 |
2026/10/01 02:03 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 856447d0209c2214d806b30bd3b0d873db5998bd
Author: Jesse Gross <jesse@nicira.com>
Date: Tue Nov 11 14:32:20 2014 -0800
openvswitch: Fix checksum calculation when modifying ICMPv6 packets.
The checksum of ICMPv6 packets uses the IP pseudoheader as part of
the calculation, unlike ICMP in IPv4. This was not implemented,
which means that modifying the IP addresses of an ICMPv6 packet
would cause the checksum to no longer be correct as the psuedoheader
did not match.
Introduced by commit 3fdbd1ce11e5 ("openvswitch: add ipv6 'set' action").
Reported-by: Neal Shrader <icosahedral@gmail.com>
Signed-off-by: Jesse Gross <jesse@nicira.com>
Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 00e447a17f64..8c4229b11c34 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -246,11 +246,11 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
{
int transport_len = skb->len - skb_transport_offset(skb);
- if (l4_proto == IPPROTO_TCP) {
+ if (l4_proto == NEXTHDR_TCP) {
if (likely(transport_len >= sizeof(struct tcphdr)))
inet_proto_csum_replace16(&tcp_hdr(skb)->check, skb,
addr, new_addr, 1);
- } else if (l4_proto == IPPROTO_UDP) {
+ } else if (l4_proto == NEXTHDR_UDP) {
if (likely(transport_len >= sizeof(struct udphdr))) {
struct udphdr *uh = udp_hdr(skb);
@@ -261,6 +261,10 @@ static void update_ipv6_checksum(struct sk_buff *skb, u8 l4_proto,
uh->check = CSUM_MANGLED_0;
}
}
+ } else if (l4_proto == NEXTHDR_ICMP) {
+ if (likely(transport_len >= sizeof(struct icmp6hdr)))
+ inet_proto_csum_replace16(&icmp6_hdr(skb)->icmp6_cksum,
+ skb, addr, new_addr, 1);
}
}
]
|
| 27/4 |
2026/10/01 02:03 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 5020
output: 33
thoughts: 29
Thoughts: **My Thought Process**
Right, so my immediate goal here is to understand the scope of changes related to the calculation of transport layer header size within the Open vSwitch codebase. Specifically, I'm looking for any instances where `sizeof(struct tcphdr)` or a variable named `transport_len` are being directly manipulated or referenced. My underlying assumption is that these are likely key indicators of how the system determines the size of transport headers, which is crucial for packet parsing and manipulation. By identifying all such occurrences, I can then analyze the context of each one to see if there are any potential inconsistencies, optimizations, or bugs related to this critical measurement. This approach allows me to systematically explore the code's handling of transport layer header sizing and gain a comprehensive understanding of its implementation details.
|
| 28/4 |
2026/10/01 02:03 |
tool |
git-log |
0m
Args: map[CodeRegexp:transport_len.*sizeof PathPrefix:net/openvswitch]
Results: map[Output:856447d0209c openvswitch: Fix checksum calculation when modifying ICMPv6 packets.
3fdbd1ce11e5 openvswitch: add ipv6 'set' action
81e5d41d7ed4 openvswitch: Fix checksum update for actions on UDP packets.
ccb1352e76cf net: Add Open vSwitch kernel components.
]
|
| 29/4 |
2026/10/01 02:03 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 5174
output: 35
thoughts: 1345
Thoughts: **A Deep Dive into the Nuances of Signed-Unsigned Comparisons in C, Specifically `transport_len >= sizeof(struct tcphdr)`**
When I look at a comparison like `transport_len >= sizeof(struct tcphdr)`, my initial thought might be a straightforward check of lengths. However, as an expert, I know that C's type system and its "usual arithmetic conversions" can introduce subtle but critical behaviors that demand careful consideration. My thought process here is to meticulously dissect the types involved and trace how the C standard dictates their interaction.
First, I need to understand the type of `sizeof(struct tcphdr)`. The `sizeof` operator in C, by definition, returns a value of type `size_t`. Crucially, `size_t` is an **unsigned** integer type. On common architectures like Linux, `size_t` will be either `unsigned long` (on 64-bit systems like x86_64) or `unsigned int` (on 32-bit systems). Regardless of the specific underlying type, it's guaranteed to be unsigned.
Next, I examine the type of `transport_len`. The provided definition tells me `transport_len` is declared as `int transport_len = skb->len - skb_transport_offset(skb);`. This clearly establishes `transport_len` as a **signed** integer type.
Now, the core of the issue: what happens when these two operands, one signed (`int`) and one unsigned (`size_t`), are compared using the `>=` operator? This is where the "usual arithmetic conversions" come into play. The C standard dictates that when operands of different arithmetic types are involved, integer promotions are performed first (which here don't change the fundamental signed/unsigned nature of `int` and `size_t`). Then, more significantly, if one operand is signed and the other is unsigned, and the unsigned type has a rank greater than or equal to the signed type's rank (which is almost always the case for `size_t` vs. `int`), the **signed operand is converted to the unsigned type**.
This conversion is the critical point. When a negative signed integer (`int`) is converted to an unsigned integer type (`size_t`), it doesn't retain its negative value. Instead, it undergoes a modular arithmetic conversion. Specifically, the value is reduced modulo $2^N$, where $N$ is the number of bits in the unsigned type. For example, a `transport_len` of `-1` will not be treated as negative; when converted to `unsigned long` (on a 64-bit system), it becomes a very large positive number (specifically, $2^{64}-1$, which is approximately $1.84 \times 10^{19}$). Similarly, on a 32-bit system, `-1` converted to `unsigned int` becomes $2^{32}-1$ (4,294,967,295).
Therefore, the comparison `transport_len >= sizeof(struct tcphdr)` is not a signed comparison at all. It's an **unsigned comparison**, after `transport_len` has been converted to `size_t`.
This leads to a potentially surprising outcome: **if `transport_len` is negative, it will almost certainly be evaluated as greater than `sizeof(struct tcphdr)`**. Since `sizeof(struct tcphdr)` is a fixed, relatively small positive value (I mentally note to verify this value later, but it's typically around 20 bytes), any negative `int` that converts to a large positive `size_t` will dwarf this value. Thus, a negative `transport_len` will result in the comparison evaluating to `true`. This is a common source of subtle bugs in code that deals with buffer lengths or packet headers.
|
| 30/4 |
2026/10/01 02:04 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:tcphdr]
Results: map[Fields:[map[Name:source OffsetBits:0 SizeBits:16] map[Name:dest OffsetBits:16 SizeBits:16] map[Name:seq OffsetBits:32 SizeBits:32] map[Name:ack_seq OffsetBits:64 SizeBits:32] map[Name:ae OffsetBits:96 SizeBits:1] map[Name:res1 OffsetBits:97 SizeBits:3] map[Name:doff OffsetBits:100 SizeBits:4] map[Name:fin OffsetBits:104 SizeBits:1] map[Name:syn OffsetBits:105 SizeBits:1] map[Name:rst OffsetBits:106 SizeBits:1] map[Name:psh OffsetBits:107 SizeBits:1] map[Name:ack OffsetBits:108 SizeBits:1] map[Name:urg OffsetBits:109 SizeBits:1] map[Name:ece OffsetBits:110 SizeBits:1] map[Name:cwr OffsetBits:111 SizeBits:1] map[Name:window OffsetBits:112 SizeBits:16] map[Name:check OffsetBits:128 SizeBits:16] map[Name:urg_ptr OffsetBits:144 SizeBits:16]]]
|
| 31/4 |
2026/10/01 02:04 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 6742
output: 478
thoughts: 1443
Thoughts: **Understanding the Signed vs. Unsigned Comparison in `update_ipv6_checksum`**
I've been examining a specific comparison within the `update_ipv6_checksum` function, specifically how `transport_len` (an `int`) interacts with `sizeof(struct tcphdr)` (which evaluates to `size_t`). The core of my thought process revolves around understanding the type promotions and conversions that C's standard dictates in such mixed-sign comparisons, and what the implications are for the logic, particularly when `transport_len` might be negative.
My initial observation was the static size of `struct tcphdr`, confirming it's indeed 20 bytes (160 bits). Then, I delved into the comparison: `transport_len >= sizeof(struct tcphdr)`.
Here's my breakdown of the thought process:
1. **Type of `sizeof(struct tcphdr)`**: I know that `sizeof` in C always returns a value of type `size_t`. Crucially, `size_t` is defined as an *unsigned* integer type. On 64-bit systems, it's `unsigned long`; on 32-bit systems, it's `unsigned int`.
2. **The Comparison**: The comparison is between `transport_len` (which is declared as `int`, a *signed* integer type) and `sizeof(struct tcphdr)` (an *unsigned* integer type).
3. **C's Usual Arithmetic Conversions**: This is where the subtlety lies. I recalled C's rules for mixed-sign arithmetic and comparisons (specifically, C99/C11/C23 §6.3.1.8). When a signed integer type is compared with an unsigned integer type of equal or greater rank:
* The signed operand is converted to the unsigned type.
* On 32-bit systems, `int` and `unsigned int` have the same rank. `transport_len` would be converted to `unsigned int`.
* On 64-bit systems (LP64), `size_t` (`unsigned long`) has a greater rank than `int`. `transport_len` would be converted to `unsigned long`.
4. **The Unsigned Nature of the Comparison**: Because `transport_len` is always converted to an unsigned type (`size_t`) before the comparison, the `>=` operator is effectively performing an **unsigned comparison**.
5. **Handling Negative `transport_len`**: This is the critical edge case. What happens if `transport_len` is negative? This can occur if `skb->len` is less than `skb_transport_offset(skb)`.
* When a negative signed integer is converted to an unsigned integer type, it "wraps around" modulo $2^N$, where $N$ is the bit-width of the unsigned type. This is standard behavior for two's complement representation.
* For example, on a 64-bit system, if `transport_len` is `-1`, it converts to `(unsigned long) -1`, which is $2^{64} - 1$, a very large positive number.
* On a 32-bit system, if `transport_len` is `-1`, it converts to `(unsigned int) -1`, which is $2^{32} - 1$, also a very large positive number.
* Even the most negative `int` (e.g., $-2^{31}$ on a 32-bit system) converts to a very large positive unsigned value.
6. **The Consequence for the Condition**: Since `sizeof(struct tcphdr)` is a small, fixed positive value (20), any negative `transport_len`, when converted to `size_t`, will result in a value that is vastly larger than 20. Therefore, the condition `transport_len >= sizeof(struct tcphdr)` will evaluate to **true** if `transport_len` is negative.
7. **Compiler Warnings**: I'm aware that compilers like GCC would flag this kind of mixed-sign comparison with a `-Wsign-compare` warning. However, in contexts like the Linux kernel, this warning is often disabled due to the prevalence of such patterns and the developer's understanding of these conversion rules.
In summary, my analysis confirms that the comparison in question is indeed performed as an **unsigned comparison**. Furthermore, I've concluded that if `transport_len` happens to be negative, it will be converted to a very large unsigned value, thus evaluating as greater than `sizeof(struct tcphdr)`, leading to the `if (likely(transport_len >= sizeof(struct tcphdr)))` condition being met.
|
| 32/4 |
2026/10/01 02:04 |
tool |
set-results |
0m
Args: map[Answer:The comparison is **unsigned**.
**Yes**, if `transport_len` is negative, it will evaluate as **greater than** `sizeof(struct tcphdr)`.
### Explanation:
1. **Unsigned Comparison**:
- In C, the `sizeof` operator yields a result of type `size_t`, which is an unsigned integer type (`unsigned long` on 64-bit architectures or `unsigned int` on 32-bit architectures).
- Under C's usual arithmetic conversions (C standard section 6.3.1.8), when an `int` (signed) is compared with `size_t` (unsigned type of equal or greater conversion rank), the `int` operand (`transport_len`) is implicitly converted to `size_t`.
- Therefore, the comparison `transport_len >= sizeof(struct tcphdr)` is performed as an **unsigned comparison**.
2. **Behavior when `transport_len` is negative**:
- When a negative signed integer is converted to an unsigned integer type of width $N$, the value is reduced modulo $2^N$ (i.e. interpreted as unsigned in two's complement).
- On a 64-bit system, a negative `int` converts to an `unsigned long` value $\ge 2^{64} - 2^{31}$ (for example, $-1$ converts to $2^{64} - 1 \approx 1.84 \times 10^{19}$).
- On a 32-bit system, a negative `int` converts to an `unsigned int` value $\ge 2^{31} \approx 2.15 \times 10^9$ (for example, $-1$ converts to $2^{32} - 1 \approx 4.29 \times 10^9$).
- Since `sizeof(struct tcphdr)` is only 20, any negative value of `transport_len` becomes an unsigned value vastly larger than 20. As a result, `transport_len >= sizeof(struct tcphdr)` evaluates to `true`.]
Results: map[Answer:The comparison is **unsigned**.
**Yes**, if `transport_len` is negative, it will evaluate as **greater than** `sizeof(struct tcphdr)`.
### Explanation:
1. **Unsigned Comparison**:
- In C, the `sizeof` operator yields a result of type `size_t`, which is an unsigned integer type (`unsigned long` on 64-bit architectures or `unsigned int` on 32-bit architectures).
- Under C's usual arithmetic conversions (C standard section 6.3.1.8), when an `int` (signed) is compared with `size_t` (unsigned type of equal or greater conversion rank), the `int` operand (`transport_len`) is implicitly converted to `size_t`.
- Therefore, the comparison `transport_len >= sizeof(struct tcphdr)` is performed as an **unsigned comparison**.
2. **Behavior when `transport_len` is negative**:
- When a negative signed integer is converted to an unsigned integer type of width $N$, the value is reduced modulo $2^N$ (i.e. interpreted as unsigned in two's complement).
- On a 64-bit system, a negative `int` converts to an `unsigned long` value $\ge 2^{64} - 2^{31}$ (for example, $-1$ converts to $2^{64} - 1 \approx 1.84 \times 10^{19}$).
- On a 32-bit system, a negative `int` converts to an `unsigned int` value $\ge 2^{31} \approx 2.15 \times 10^9$ (for example, $-1$ converts to $2^{32} - 1 \approx 4.29 \times 10^9$).
- Since `sizeof(struct tcphdr)` is only 20, any negative value of `transport_len` becomes an unsigned value vastly larger than 20. As a result, `transport_len >= sizeof(struct tcphdr)` evaluates to `true`.]
|
| 33/2 |
2026/10/01 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 13841
output: 34
thoughts: 40
Thoughts: **My Thought Process Regarding the Out-of-Bounds Write**
Right, so my immediate reaction to seeing this snippet of code is a jolt of alarm. The calculation clearly results in an out-of-bounds write, specifically to `skb->head + 0xffff`. This is a critical vulnerability, and my mind immediately goes to the potential consequences.
Before diving deeper, my first instinct is to verify the exact location within the `skb` structure that `tcp_hdr(skb)` points to. This is essential to understand the precise nature and impact of this out-of-bounds write. Is it overwriting metadata? Is it corrupting TCP header fields themselves? My next step, therefore, is to examine the definition and offset of `tcp_hdr(skb)` within the `skb` structure. This will tell me *where* exactly within the `skb`'s memory allocation this `0xffff` offset is being applied, and by extension, what critical data or control structures might be compromised.
|
| 34/2 |
2026/10/01 02:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:include/linux/tcp.h Name:tcp_hdr]
Results: map[SourceCode: 24: static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
25: {
26: return (struct tcphdr *)skb_transport_header(skb);
27: }
SourceFile:include/linux/tcp.h]
|
| 35/2 |
2026/10/01 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 13986
output: 42
thoughts: 414
Thoughts: **My Thought Process Regarding the TCP Checksum Vulnerability**
Okay, let me walk through my reasoning here. I've been digging into this `tcp_hdr(skb)` function and its implications. My initial realization is that `tcp_hdr(skb)` is essentially a direct alias for `skb_transport_header(skb)`. That's a straightforward mapping.
Now, `skb_transport_header(skb)`, as I understand it, resolves to `skb->head + skb->transport_header`. This is the core of where things get interesting. I'm focusing on a specific edge case: what happens if `skb->transport_header` is set to `0xffff`? In C, that's equivalent to `(u16)~0U`, a value that represents all bits set for an unsigned 16-bit integer.
If `skb->transport_header` holds this `0xffff` value, then the calculation `skb->head + skb->transport_header` would become `skb->head + 0xffff`. This immediately flags as a potential out-of-bounds access because `skb->transport_header` is an offset *within* the `skb` buffer, and `0xffff` is a very large offset, quite likely beyond the allocated memory for the packet.
But it gets worse. I'm not just looking at reads, but writes as well. I've identified that the `inet_proto_csum_replace16` function is involved. This function, crucially, will write to the `check` field within the TCP header. And where is `check` located? In the `struct tcphdr`, it's at offset 16.
So, if `inet_proto_csum_replace16` is called with the problematic `skb` where `skb->transport_header` is `0xffff`, the actual write operation will target the memory address `skb->head + 0xffff + 16`. This is unequivocally an out-of-bounds write. From my perspective as an expert, an out-of-bounds write of this nature is a significant security concern, and very likely exploitable.
My next step is to trace how we even get into this state, specifically how the `set_ipv6` function is being reached. I've been examining the provided stack trace, which shows the following sequence:
* `set_ipv6`
* `execute_masked_set_action`
* `do_execute_actions`
* `ovs_execute_actions`
* `ovs_packet_cmd_execute`
The call to `ovs_packet_cmd_execute` originates from a netlink communication, specifically using the `OVS_PACKET_FAMILY`. This is a critical point for exploitability. My immediate question is whether this netlink family and the associated command are accessible to unprivileged processes. If they are, then an unprivileged attacker could potentially trigger this vulnerability. I need to delve into the registration of the `OVS_PACKET_FAMILY` and the specific handler for `ovs_packet_cmd_execute` to confirm this accessibility.
|
| 36/2 |
2026/10/01 02:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/datapath.c Name:dp_packet_genl_family]
Results: map[SourceCode: 743: static struct genl_family dp_packet_genl_family __ro_after_init = {
744: .hdrsize = sizeof(struct ovs_header),
745: .name = OVS_PACKET_FAMILY,
746: .version = OVS_PACKET_VERSION,
747: .maxattr = OVS_PACKET_ATTR_MAX,
748: .policy = packet_policy,
749: .netnsok = true,
750: .parallel_ops = true,
751: .small_ops = dp_packet_genl_ops,
752: .n_small_ops = ARRAY_SIZE(dp_packet_genl_ops),
753: .resv_start_op = OVS_PACKET_CMD_EXECUTE + 1,
754: .module = THIS_MODULE,
755: };
SourceFile:net/openvswitch/datapath.c]
|
| 37/2 |
2026/10/01 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 14701
output: 42
thoughts: 14
Thoughts: **My Thought Process**
Right, the first thing I need to do is dive into the specifics of `dp_packet_genl_ops`. I'm really keen to understand its operational scope and how it interfaces within the broader data plane generation framework. My goal here is to thoroughly investigate its functionalities, particularly concerning netlink generic operations. I'm assuming it's a critical component for handling and processing generic netlink messages related to packet generation, and I want to confirm that assumption. This means I'll be looking for details on its registration, handling of specific commands, and any associated attributes or data structures it utilizes. Ultimately, I'm trying to get a clear picture of its role in the overall packet generation pipeline and any potential implications it might have on performance or behavior.
|
| 38/2 |
2026/10/01 02:04 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/datapath.c Name:dp_packet_genl_ops]
Results: map[SourceCode: 735: static const struct genl_small_ops dp_packet_genl_ops[] = {
736: { .cmd = OVS_PACKET_CMD_EXECUTE,
737: .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
738: .flags = GENL_UNS_ADMIN_PERM, /* Requires CAP_NET_ADMIN privilege. */
739: .doit = ovs_packet_cmd_execute
740: }
741: };
SourceFile:net/openvswitch/datapath.c]
|
| 39/2 |
2026/10/01 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 14920
output: 43
thoughts: 53
Thoughts: **My Thought Process**
Alright, so I'm looking at this `flags` field, and I see it's set to `GENL_UNS_ADMIN_PERM`. My immediate thought is, "Okay, what does *that* actually entail?" I know, from experience, that flags like these often translate to specific permission requirements. Specifically, my internal knowledge base immediately flags this as likely requiring elevated privileges.
I then connect this to the user namespace context. The presence of `GENL_UNS_ADMIN_PERM` strongly suggests a dependency on the `CAP_NET_ADMIN` capability. This is a standard pattern: certain generic netlink operations, especially those that modify network state or configuration, are guarded by this capability. The `UNS` in `GENL_UNS_ADMIN_PERM` is likely a hint towards "unsolicited" or "user-space" notifications or commands that require administrative backing.
To be absolutely sure, I need to confirm the exact definition and implication of `GENL_UNS_ADMIN_PERM`. My next logical step is to delve into the kernel documentation or source code to meticulously verify what `GENL_UNS_ADMIN_PERM` signifies and how it maps directly to the `CAP_NET_ADMIN` requirement within the user namespace. I need to understand the exact security boundaries this flag is designed to enforce.
|
| 40/2 |
2026/10/01 02:04 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:include/net/genetlink.h Name:GENL_UNS_ADMIN_PERM]
Results: map[SourceCode: SourceFile:]
|
| 41/2 |
2026/10/01 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 15021
output: 24
thoughts: 17
Thoughts: **My Thought Process on `GENL_UNS_ADMIN_PERM`**
Alright, so the immediate impulse, the first step in this investigation, is to pinpoint the exact location and context of this specific identifier: `GENL_UNS_ADMIN_PERM`. For me, that translates directly to a `grep` command. I need to scan through the codebase, or perhaps a set of relevant configuration files or documentation, to find every instance of this string. It's not about blind searching; it's about efficiently locating the artifact and understanding its immediate surroundings. This initial `grep` is the bedrock of any deeper analysis, providing the raw material from which I'll begin to infer meaning and relationships.
|
| 42/2 |
2026/10/01 02:04 |
tool |
grepper |
0m
Args: map[Expression:GENL_UNS_ADMIN_PERM]
Results: map[Output:
Full output is too long, showing 200 out of 835 lines.
Use more precise expression if possible.
drivers/net/ieee802154/mac802154_hwsim.c=754=static const struct genl_small_ops hwsim_nl_ops[] = {
--
drivers/net/ieee802154/mac802154_hwsim.c-758- .doit = hwsim_new_radio_nl,
drivers/net/ieee802154/mac802154_hwsim.c:759: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/ieee802154/mac802154_hwsim.c-760- },
--
drivers/net/ieee802154/mac802154_hwsim.c-764- .doit = hwsim_del_radio_nl,
drivers/net/ieee802154/mac802154_hwsim.c:765: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/ieee802154/mac802154_hwsim.c-766- },
--
drivers/net/ieee802154/mac802154_hwsim.c-776- .doit = hwsim_new_edge_nl,
drivers/net/ieee802154/mac802154_hwsim.c:777: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/ieee802154/mac802154_hwsim.c-778- },
--
drivers/net/ieee802154/mac802154_hwsim.c-782- .doit = hwsim_del_edge_nl,
drivers/net/ieee802154/mac802154_hwsim.c:783: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/ieee802154/mac802154_hwsim.c-784- },
--
drivers/net/ieee802154/mac802154_hwsim.c-788- .doit = hwsim_set_edge_lqi,
drivers/net/ieee802154/mac802154_hwsim.c:789: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/ieee802154/mac802154_hwsim.c-790- },
--
drivers/net/wireguard/generated/netlink.c=56=const struct genl_split_ops wireguard_nl_ops[2] = {
--
drivers/net/wireguard/generated/netlink.c-63- .maxattr = WGDEVICE_A_IFNAME,
drivers/net/wireguard/generated/netlink.c:64: .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DUMP,
drivers/net/wireguard/generated/netlink.c-65- },
--
drivers/net/wireguard/generated/netlink.c-70- .maxattr = WGDEVICE_A_PEERS,
drivers/net/wireguard/generated/netlink.c:71: .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DO,
drivers/net/wireguard/generated/netlink.c-72- },
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c=7164=static const struct genl_small_ops hwsim_ops[] = {
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7168- .doit = hwsim_register_received_nl,
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7169: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7170- },
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7184- .doit = hwsim_new_radio_nl,
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7185: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7186- },
--
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7190- .doit = hwsim_del_radio_nl,
drivers/net/wireless/virtual/mac80211_hwsim_main.c:7191: .flags = GENL_UNS_ADMIN_PERM,
drivers/net/wireless/virtual/mac80211_hwsim_main.c-7192- },
--
include/net/genetlink.h=173=enum genl_validate_flags {
--
include/net/genetlink.h-182- * @internal_flags: flags used by the family
include/net/genetlink.h:183: * @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM)
include/net/genetlink.h-184- * @validate: validation flags from enum genl_validate_flags
--
include/net/genetlink.h=191=struct genl_small_ops {
--
include/net/genetlink.h-203- * @internal_flags: flags used by the family
include/net/genetlink.h:204: * @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM)
include/net/genetlink.h-205- * @maxattr: maximum number of attributes supported
--
include/net/genetlink.h=213=struct genl_ops {
--
include/net/genetlink.h-231- * @internal_flags: flags used by the family
include/net/genetlink.h:232: * @flags: GENL_* flags (%GENL_ADMIN_PERM or %GENL_UNS_ADMIN_PERM)
include/net/genetlink.h-233- * @validate: validation flags from enum genl_validate_flags
--
include/uapi/linux/genetlink.h=13=struct genlmsghdr {
--
include/uapi/linux/genetlink.h-24-#define GENL_CMD_CAP_HASPOL 0x08
include/uapi/linux/genetlink.h:25:#define GENL_UNS_ADMIN_PERM 0x10
include/uapi/linux/genetlink.h-26-
--
net/batman-adv/netlink.c=1416=static const struct genl_small_ops batadv_netlink_ops[] = {
--
net/batman-adv/netlink.c-1426- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1427: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1428- .doit = batadv_netlink_tp_meter_start,
--
net/batman-adv/netlink.c-1433- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1434: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1435- .doit = batadv_netlink_tp_meter_cancel,
--
net/batman-adv/netlink.c-1440- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1441: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1442- .dumpit = batadv_algo_dump,
--
net/batman-adv/netlink.c-1455- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1456: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1457- .dumpit = batadv_tt_local_dump,
--
net/batman-adv/netlink.c-1461- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1462: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1463- .dumpit = batadv_tt_global_dump,
--
net/batman-adv/netlink.c-1467- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1468: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1469- .dumpit = batadv_orig_dump,
--
net/batman-adv/netlink.c-1473- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1474: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1475- .dumpit = batadv_hardif_neigh_dump,
--
net/batman-adv/netlink.c-1479- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1480: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1481- .dumpit = batadv_gw_dump,
--
net/batman-adv/netlink.c-1485- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1486: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1487- .dumpit = batadv_bla_claim_dump,
--
net/batman-adv/netlink.c-1491- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1492: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1493- .dumpit = batadv_bla_backbone_dump,
--
net/batman-adv/netlink.c-1497- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1498: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1499- .dumpit = batadv_dat_cache_dump,
--
net/batman-adv/netlink.c-1503- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1504: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1505- .dumpit = batadv_mcast_flags_dump,
--
net/batman-adv/netlink.c-1509- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1510: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1511- .doit = batadv_netlink_set_mesh,
--
net/batman-adv/netlink.c-1516- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1517: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1518- .doit = batadv_netlink_set_hardif,
--
net/batman-adv/netlink.c-1532- .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
net/batman-adv/netlink.c:1533: .flags = GENL_UNS_ADMIN_PERM,
net/batman-adv/netlink.c-1534- .doit = batadv_netlink_set_vlan,
--
net/core/netdev-genl-gen.c=145=static const struct genl_split_ops netdev_nl_ops[] = {
--
net/core/netdev-genl-gen.c-229- .maxattr = NETDEV_A_DMABUF_RX_PAGE_SIZE,
net/core/netdev-genl-gen.c:230: .flags = GENL_UNS_ADMIN_PERM | GENL_CMD_CAP_DO,
net/core/netdev-genl-gen.c-231- },
--
net/core/netdev-genl.c=1157=netdev_find_netmem_tx_dev(struct net_device *dev)
--
net/core/netdev-genl.c-1183-/* Note: NETDEV_CMD_BIND_TX is intentionally unprivileged (no
net/core/netdev-genl.c:1184: * GENL_ADMIN_PERM / GENL_UNS_ADMIN_PERM). Unlike bind-rx, which configures
net/core/netdev-genl.c-1185- * shared NIC RX queues, bind-tx only DMA-maps the caller's dmabuf so they can
--
net/ethtool/netlink.c=1161=static const struct genl_ops ethtool_genl_ops[] = {
--
net/ethtool/netlink.c-1181- .cmd = ETHTOOL_MSG_LINKINFO_SET,
net/ethtool/netlink.c:1182: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1183- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1197- .cmd = ETHTOOL_MSG_LINKMODES_SET,
net/ethtool/netlink.c:1198: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1199- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1222- .cmd = ETHTOOL_MSG_DEBUG_SET,
net/ethtool/netlink.c:1223: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1224- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1229- .cmd = ETHTOOL_MSG_WOL_GET,
net/ethtool/netlink.c:1230: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1231- .doit = ethnl_default_doit,
--
net/ethtool/netlink.c-1239- .cmd = ETHTOOL_MSG_WOL_SET,
net/ethtool/netlink.c:1240: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1241- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1255- .cmd = ETHTOOL_MSG_FEATURES_SET,
net/ethtool/netlink.c:1256: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1257- .doit = ethnl_set_features,
--
net/ethtool/netlink.c-1271- .cmd = ETHTOOL_MSG_PRIVFLAGS_SET,
net/ethtool/netlink.c:1272: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1273- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1287- .cmd = ETHTOOL_MSG_RINGS_SET,
net/ethtool/netlink.c:1288: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1289- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1303- .cmd = ETHTOOL_MSG_CHANNELS_SET,
net/ethtool/netlink.c:1304: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1305- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1319- .cmd = ETHTOOL_MSG_COALESCE_SET,
net/ethtool/netlink.c:1320: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1321- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1335- .cmd = ETHTOOL_MSG_PAUSE_SET,
net/ethtool/netlink.c:1336: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1337- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1351- .cmd = ETHTOOL_MSG_EEE_SET,
net/ethtool/netlink.c:1352: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1353- .doit = ethnl_default_set_doit,
--
net/ethtool/netlink.c-1367- .cmd = ETHTOOL_MSG_CABLE_TEST_ACT,
net/ethtool/netlink.c:1368: .flags = GENL_UNS_ADMIN_PERM,
net/ethtool/netlink.c-1369- .doit = ethnl_act_cable_test,
--
net/ethtool/netlink.c-1374- .cmd = ETHTOOL_MSG_CABLE_TEST_TDR_ACT,
net/ethtool/netlink.c:1375: .flags = GENL_UNS_ADMIN_PERM,
]
|
| 43/2 |
2026/10/01 02:04 |
llm |
expert |
0m
Model:
Tokens:
input: 20324
output: 46
thoughts: 98
Thoughts: **My Thought Process Regarding `GENL_UNS_ADMIN_PERM`**
Ah, so I'm digging into the `genetlink.h` header file, specifically looking at `include/uapi/linux/genetlink.h`, and I've come across this constant: `GENL_UNS_ADMIN_PERM`. My first observation is that it's defined with a numerical value of `0x10`.
Now, the name itself, `GENL_UNS_ADMIN_PERM`, immediately sparks a thought: "User Namespace Admin Perm." That seems like a pretty direct hint about its purpose. My immediate association is that this permission likely relates to administrative privileges within a user namespace context.
Given that it's a permission flag within the Netlink framework, my next logical step is to understand how it's actually *used*. To do that, I need to trace its application. I'll be looking for its usage within the core Netlink implementation, so I'm heading over to `net/netlink/genetlink.c` to see where and how `GENL_UNS_ADMIN_PERM` is referenced. This will be key to understanding the practical implications and the security context it operates within.
|
| 44/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/netlink/genetlink.c Name:genl_family_rcv_msg_doit]
Results: map[SourceCode:1081: static int genl_family_rcv_msg_doit(const struct genl_family *family,
1082: struct sk_buff *skb,
1083: struct nlmsghdr *nlh,
1084: struct netlink_ext_ack *extack,
1085: const struct genl_split_ops *ops,
1086: int hdrlen, struct net *net)
1087: {
1088: struct nlattr **attrbuf;
1089: struct genl_info info;
1090: int err;
1091:
1092: attrbuf = genl_family_rcv_msg_attrs_parse(family, nlh, extack,
1093: ops, hdrlen,
1094: GENL_DONT_VALIDATE_STRICT);
1095: if (IS_ERR(attrbuf))
1096: return PTR_ERR(attrbuf);
1097:
1098: info.snd_seq = nlh->nlmsg_seq;
1099: info.snd_portid = NETLINK_CB(skb).portid;
1100: info.family = family;
1101: info.nlhdr = nlh;
1102: info.genlhdr = nlmsg_data(nlh);
1103: info.attrs = attrbuf;
1104: info.extack = extack;
1105: genl_info_net_set(&info, net);
1106: memset(&info.ctx, 0, sizeof(info.ctx));
1107:
1108: if (ops->pre_doit) {
1109: err = ops->pre_doit(ops, skb, &info);
1110: if (err)
1111: goto out;
1112: }
1113:
1114: err = ops->doit(skb, &info);
1115:
1116: if (ops->post_doit)
1117: ops->post_doit(ops, skb, &info);
1118:
1119: out:
1120: genl_family_rcv_msg_attrs_free(attrbuf);
1121:
1122: return err;
1123: }
SourceFile:net/netlink/genetlink.c]
|
| 45/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 21135
output: 40
thoughts: 20
Thoughts: **My Thought Process**
My primary objective right now is to pinpoint the exact locations within the codebase where the `GENL_UNS_ADMIN_PERM` constant is being referenced, or more specifically, where its presence is being checked. This is crucial for understanding how administrative permissions are being enforced and validated within the system. I need to trace the execution flow and identify all code paths that involve this permission.
|
| 46/2 |
2026/10/01 02:05 |
tool |
grepper |
0m
Args: map[Expression:GENL_UNS_ADMIN_PERM PathPrefix:net/netlink/genetlink.c]
Results: map[Output:net/netlink/genetlink.c=1155=static int genl_family_rcv_msg(const struct genl_family *family,
--
net/netlink/genetlink.c-1185-
net/netlink/genetlink.c:1186: if ((op.flags & GENL_UNS_ADMIN_PERM) &&
net/netlink/genetlink.c-1187- !netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN))
]
|
| 47/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 21326
output: 42
thoughts: 405
Thoughts: **My Thought Process Regarding Netlink Accessibility**
My initial observation focuses on the `!netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)` check. This immediately tells me that the operation requires the `CAP_NET_ADMIN` capability, specifically within the context of the *network namespace's user namespace*. My immediate inference is that this makes the functionality accessible from within user namespaces.
However, I then recall the constraints provided in the prompt, which introduce a layer of complexity. I need to carefully disentangle the conditions for different scenarios:
1. **Unprivileged Processes:** The prompt explicitly states, "Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even within a new user namespace." This constraint is crucial. Since the check inherently requires `CAP_NET_ADMIN`, and under this assumption, an unprivileged process *cannot* obtain this capability, even by creating a new user namespace, I conclude that the bug is *not* accessible from unprivileged processes.
2. **User Namespaces (with full capabilities):** The prompt also asks, "Determine if the bug can be reached within a user-namespace where the process has all capabilities (including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON)." This is where my initial assessment about user namespace accessibility comes back into play. The `netlink_ns_capable(skb, net->user_ns, CAP_NET_ADMIN)` call specifically checks for `CAP_NET_ADMIN` *within the user namespace*. If a process can gain *all* capabilities, including `CAP_NET_ADMIN`, within a new user namespace, then this specific check will pass. Therefore, *yes*, the bug is accessible from a user namespace where the process has `CAP_NET_ADMIN` (and indeed, all other mentioned capabilities). This is confirmed by the `GENL_UNS_ADMIN_PERM` which points to this `netlink_ns_capable` check.
To further solidify my understanding, I decide to double-check the registration of `OVS_PACKET_FAMILY`. I note that it is registered with `.netnsok = true`. This is a good sign, indicating that the family itself is designed to operate correctly in non-initial network namespaces, which aligns with the idea of user namespace interaction.
Finally, I commit to ensuring I haven't missed any *other* capability checks within the `ovs_packet_cmd_execute` function. My process is to trace all relevant calls to confirm the sole dependency is on the `CAP_NET_ADMIN` within the user namespace context, as identified.
|
| 48/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/datapath.c Name:ovs_packet_cmd_execute]
Results: map[SourceCode: 614: static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
615: {
616: struct ovs_header *ovs_header = genl_info_userhdr(info);
617: struct net *net = sock_net(skb->sk);
618: struct nlattr **a = info->attrs;
619: struct sw_flow_actions *acts;
620: struct sk_buff *packet;
621: struct sw_flow *flow;
622: struct sw_flow_actions *sf_acts;
623: struct datapath *dp;
624: struct vport *input_vport;
625: u16 mru = 0;
626: u64 hash;
627: int len;
628: int err;
629: bool log = !a[OVS_PACKET_ATTR_PROBE];
630:
631: err = -EINVAL;
632: if (!a[OVS_PACKET_ATTR_PACKET] || !a[OVS_PACKET_ATTR_KEY] ||
633: !a[OVS_PACKET_ATTR_ACTIONS])
634: goto err;
635:
636: len = nla_len(a[OVS_PACKET_ATTR_PACKET]);
637: packet = __dev_alloc_skb(NET_IP_ALIGN + len, GFP_KERNEL);
638: err = -ENOMEM;
639: if (!packet)
640: goto err;
641: skb_reserve(packet, NET_IP_ALIGN);
642:
643: nla_memcpy(__skb_put(packet, len), a[OVS_PACKET_ATTR_PACKET], len);
644:
645: /* Set packet's mru */
646: if (a[OVS_PACKET_ATTR_MRU]) {
647: mru = nla_get_u16(a[OVS_PACKET_ATTR_MRU]);
648: packet->ignore_df = 1;
649: }
650: OVS_CB(packet)->mru = mru;
651: OVS_CB(packet)->cutlen = U32_MAX;
652:
653: if (a[OVS_PACKET_ATTR_HASH]) {
654: hash = nla_get_u64(a[OVS_PACKET_ATTR_HASH]);
655:
656: __skb_set_hash(packet, hash & 0xFFFFFFFFULL,
657: !!(hash & OVS_PACKET_HASH_SW_BIT),
658: !!(hash & OVS_PACKET_HASH_L4_BIT));
659: }
660:
661: OVS_CB(packet)->upcall_pid =
662: nla_get_u32_default(a[OVS_PACKET_ATTR_UPCALL_PID], 0);
663:
664: /* Build an sw_flow for sending this packet. */
665: flow = ovs_flow_alloc();
666: err = PTR_ERR(flow);
667: if (IS_ERR(flow))
668: goto err_kfree_skb;
669:
670: err = ovs_flow_key_extract_userspace(net, a[OVS_PACKET_ATTR_KEY],
671: packet, &flow->key, log);
672: if (err)
673: goto err_flow_free;
674:
675: err = ovs_nla_copy_actions(net, a[OVS_PACKET_ATTR_ACTIONS],
676: &flow->key, &acts, log);
677: if (err)
678: goto err_flow_free;
679:
680: rcu_assign_pointer(flow->sf_acts, acts);
681: packet->priority = flow->key.phy.priority;
682: packet->mark = flow->key.phy.skb_mark;
683:
684: rcu_read_lock();
685: dp = get_dp_rcu(net, ovs_header->dp_ifindex);
686: err = -ENODEV;
687: if (!dp)
688: goto err_unlock;
689:
690: input_vport = ovs_vport_rcu(dp, flow->key.phy.in_port);
691: if (!input_vport)
692: input_vport = ovs_vport_rcu(dp, OVSP_LOCAL);
693:
694: if (!input_vport)
695: goto err_unlock;
696:
697: packet->dev = input_vport->dev;
698: OVS_CB(packet)->input_vport = input_vport;
699: sf_acts = rcu_dereference(flow->sf_acts);
700:
701: local_bh_disable();
702: local_lock_nested_bh(&ovs_pcpu_storage->bh_lock);
703: if (IS_ENABLED(CONFIG_PREEMPT_RT))
704: this_cpu_write(ovs_pcpu_storage->owner, current);
705: err = ovs_execute_actions(dp, packet, sf_acts, &flow->key);
706: if (IS_ENABLED(CONFIG_PREEMPT_RT))
707: this_cpu_write(ovs_pcpu_storage->owner, NULL);
708: local_unlock_nested_bh(&ovs_pcpu_storage->bh_lock);
709: local_bh_enable();
710: rcu_read_unlock();
711:
712: ovs_flow_free(flow, false);
713: return err;
714:
715: err_unlock:
716: rcu_read_unlock();
717: err_flow_free:
718: ovs_flow_free(flow, false);
719: err_kfree_skb:
720: kfree_skb(packet);
721: err:
722: return err;
723: }
SourceFile:net/openvswitch/datapath.c]
|
| 49/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 23633
output: 47
thoughts: 131
Thoughts: **My Thought Process Regarding Packet Processing in OVS**
Alright, let's break down what's happening here. I'm looking at the `ovs_packet_cmd_execute` function, and my first observation is that it's allocating a new `skb` using `__dev_alloc_skb`. I note the size: `NET_IP_ALIGN + len`. This is a standard practice, ensuring proper alignment for IP headers, which is crucial for efficient network processing.
Following that, the function copies the actual packet data. It's pulling this data from `a[OVS_PACKET_ATTR_PACKET]`. This makes sense – we need the raw bytes of the packet to work with.
The next critical step is the call to `ovs_flow_key_extract_userspace`. My immediate thought upon seeing this is: "What exactly does this function do?" I understand its purpose is to parse the packet and populate `flow->key`. This `flow->key` is fundamental for OVS's core functionality, as it represents the packet's characteristics for flow matching.
However, a specific question pops into my mind: "Does `ovs_flow_key_extract_userspace` actually set the transport header information within the `flow->key`?" This is a significant detail. The transport layer (TCP/UDP) headers contain vital information like ports, which are frequently used for flow classification and policy enforcement. If this isn't being handled by `ovs_flow_key_extract_userspace`, then something else must be responsible, or there's a gap in how the transport layer is being represented in the flow key.
Given the importance of this detail, my immediate next step is to dive into the implementation of `ovs_flow_key_extract_userspace` itself. I need to confirm its exact behavior regarding transport header parsing to ensure my understanding of the overall packet processing pipeline is accurate.
|
| 50/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:ovs_flow_key_extract_userspace]
Results: map[SourceCode:1075: int ovs_flow_key_extract_userspace(struct net *net, const struct nlattr *attr,
1076: struct sk_buff *skb,
1077: struct sw_flow_key *key, bool log)
1078: {
1079: const struct nlattr *a[OVS_KEY_ATTR_MAX + 1];
1080: u64 attrs = 0;
1081: int err;
1082:
1083: err = parse_flow_nlattrs(attr, a, &attrs, log);
1084: if (err)
1085: return -EINVAL;
1086:
1087: /* Extract metadata from netlink attributes. */
1088: err = ovs_nla_get_flow_metadata(net, a, attrs, key, log);
1089: if (err)
1090: return err;
1091:
1092: /* key_extract assumes that skb->protocol is set-up for
1093: * layer 3 packets which is the case for other callers,
1094: * in particular packets received from the network stack.
1095: * Here the correct value can be set from the metadata
1096: * extracted above.
1097: * For L2 packet key eth type would be zero. skb protocol
1098: * would be set to correct value later during key-extact.
1099: */
1100:
1101: skb->protocol = key->eth.type;
1102: err = key_extract(skb, key);
1103: if (err)
1104: return err;
1105:
1106: /* Check that we have conntrack original direction tuple metadata only
1107: * for packets for which it makes sense. Otherwise the key may be
1108: * corrupted due to overlapping key fields.
1109: */
1110: if (attrs & (1 << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4) &&
1111: key->eth.type != htons(ETH_P_IP))
1112: return -EINVAL;
1113: if (attrs & (1 << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6) &&
1114: (key->eth.type != htons(ETH_P_IPV6) ||
1115: sw_flow_key_is_nd(key)))
1116: return -EINVAL;
1117:
1118: return 0;
1119: }
SourceFile:net/openvswitch/flow.c]
|
| 51/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 24545
output: 36
thoughts: 23
Thoughts: **My Thought Process on Examining `key_extract`**
Alright, so the first thing that caught my eye was the call to `key_extract(skb, key)`. My immediate instinct is to dive into that function, to understand exactly what it's doing. I need to get a clear picture of its internal workings, so that's precisely what I'll be doing next – checking out `key_extract`.
|
| 52/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow.c Name:key_extract]
Results: map[SourceCode: 886: /**
887: * key_extract - extracts a flow key from an Ethernet frame.
888: * @skb: sk_buff that contains the frame, with skb->data pointing to the
889: * Ethernet header
890: * @key: output flow key
891: *
892: * Initializes @skb header fields as follows:
893: *
894: * - skb->mac_header: the L2 header.
895: *
896: * - skb->network_header: just past the L2 header, or just past the
897: * VLAN header, to the first byte of the L2 payload.
898: *
899: * - skb->transport_header: If key->eth.type is ETH_P_IP or ETH_P_IPV6
900: * on output, then just past the IP header, if one is present and
901: * of a correct length, otherwise the same as skb->network_header.
902: * For other key->eth.type values it is left untouched.
903: *
904: * - skb->protocol: the type of the data starting at skb->network_header.
905: * Equals to key->eth.type.
906: *
907: * Return: %0 if successful, otherwise a negative errno value.
908: */
909: static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
910: {
911: /* Flags are always used as part of stats */
912: key->tp.flags = 0;
913:
914: skb_reset_mac_header(skb);
915:
916: /* Link layer. */
917: clear_vlan(key);
918: if (ovs_key_mac_proto(key) == MAC_PROTO_NONE) {
919: if (unlikely(eth_type_vlan(skb->protocol)))
920: return -EINVAL;
921:
922: skb_reset_network_header(skb);
923: key->eth.type = skb->protocol;
924: } else {
925: struct ethhdr *eth;
926: int err;
927:
928: err = check_header(skb, ETH_HLEN);
929: if (unlikely(err))
930: return err;
931:
932: eth = eth_hdr(skb);
933: ether_addr_copy(key->eth.src, eth->h_source);
934: ether_addr_copy(key->eth.dst, eth->h_dest);
935:
936: __skb_pull(skb, 2 * ETH_ALEN);
937: /* We are going to push all headers that we pull, so no need to
938: * update skb->csum here.
939: */
940:
941: if (unlikely(parse_vlan(skb, key)))
942: return -ENOMEM;
943:
944: key->eth.type = parse_ethertype(skb);
945: if (unlikely(key->eth.type == htons(0)))
946: return -ENOMEM;
947:
948: /* Multiple tagged packets need to retain TPID to satisfy
949: * skb_vlan_pop(), which will later shift the ethertype into
950: * skb->protocol.
951: */
952: if (key->eth.cvlan.tci & htons(VLAN_CFI_MASK))
953: skb->protocol = key->eth.cvlan.tpid;
954: else
955: skb->protocol = key->eth.type;
956:
957: skb_reset_network_header(skb);
958: __skb_push(skb, skb->data - skb_mac_header(skb));
959: }
960:
961: skb_reset_mac_len(skb);
962:
963: /* Fill out L3/L4 key info, if any */
964: return key_extract_l3l4(skb, key);
965: }
SourceFile:net/openvswitch/flow.c]
|
| 53/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 25892
output: 41
thoughts: 14
Thoughts: **My Thought Process on `key_extract_l3l4`**
Alright, my first inclination is to dive straight into the details of `key_extract_l3l4`. I'm assuming, given my expertise, that this function likely pertains to some form of hierarchical or layered key extraction. The "l3l4" nomenclature strongly suggests distinct levels, possibly representing different granularities or scopes of information within the keys. I'll be looking for patterns that indicate how these layers are defined, how the extraction process differentiates between them, and what the output format is for each layer. My hypothesis is that there's a distinct mechanism for extracting keys at level 3 and a separate, potentially related, mechanism for level 4. I want to understand the logic that governs this separation and whether there's any dependency or interplay between the two. Essentially, I'm trying to reverse-engineer the intended purpose and implementation of this function by dissecting its name.
|
| 54/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow.c Name:key_extract_l3l4]
Results: map[SourceCode: 671: /**
672: * key_extract_l3l4 - extracts L3/L4 header information.
673: * @skb: sk_buff that contains the frame, with skb->data pointing to the
674: * L3 header
675: * @key: output flow key
676: *
677: * Return: %0 if successful, otherwise a negative errno value.
678: */
679: static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key)
680: {
681: int error;
682:
683: /* Network layer. */
684: if (key->eth.type == htons(ETH_P_IP)) {
685: struct iphdr *nh;
686: __be16 offset;
687:
688: error = check_iphdr(skb);
689: if (unlikely(error)) {
690: memset(&key->ip, 0, sizeof(key->ip));
691: memset(&key->ipv4, 0, sizeof(key->ipv4));
692: if (error == -EINVAL) {
693: skb->transport_header = skb->network_header;
694: error = 0;
695: }
696: return error;
697: }
698:
699: nh = ip_hdr(skb);
700: key->ipv4.addr.src = nh->saddr;
701: key->ipv4.addr.dst = nh->daddr;
702:
703: key->ip.proto = nh->protocol;
704: key->ip.tos = nh->tos;
705: key->ip.ttl = nh->ttl;
706:
707: offset = nh->frag_off & htons(IP_OFFSET);
708: if (offset) {
709: key->ip.frag = OVS_FRAG_TYPE_LATER;
710: memset(&key->tp, 0, sizeof(key->tp));
711: return 0;
712: }
713: if (nh->frag_off & htons(IP_MF) ||
714: skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
715: key->ip.frag = OVS_FRAG_TYPE_FIRST;
716: else
717: key->ip.frag = OVS_FRAG_TYPE_NONE;
718:
719: /* Transport layer. */
720: if (key->ip.proto == IPPROTO_TCP) {
721: if (tcphdr_ok(skb)) {
722: struct tcphdr *tcp = tcp_hdr(skb);
723: key->tp.src = tcp->source;
724: key->tp.dst = tcp->dest;
725: key->tp.flags = TCP_FLAGS_BE16(tcp);
726: } else {
727: memset(&key->tp, 0, sizeof(key->tp));
728: }
729:
730: } else if (key->ip.proto == IPPROTO_UDP) {
731: if (udphdr_ok(skb)) {
732: struct udphdr *udp = udp_hdr(skb);
733: key->tp.src = udp->source;
734: key->tp.dst = udp->dest;
735: } else {
736: memset(&key->tp, 0, sizeof(key->tp));
737: }
738: } else if (key->ip.proto == IPPROTO_SCTP) {
739: if (sctphdr_ok(skb)) {
740: struct sctphdr *sctp = sctp_hdr(skb);
741: key->tp.src = sctp->source;
742: key->tp.dst = sctp->dest;
743: } else {
744: memset(&key->tp, 0, sizeof(key->tp));
745: }
746: } else if (key->ip.proto == IPPROTO_ICMP) {
747: if (icmphdr_ok(skb)) {
748: struct icmphdr *icmp = icmp_hdr(skb);
749: /* The ICMP type and code fields use the 16-bit
750: * transport port fields, so we need to store
751: * them in 16-bit network byte order. */
752: key->tp.src = htons(icmp->type);
753: key->tp.dst = htons(icmp->code);
754: } else {
755: memset(&key->tp, 0, sizeof(key->tp));
756: }
757: }
758:
759: } else if (key->eth.type == htons(ETH_P_ARP) ||
760: key->eth.type == htons(ETH_P_RARP)) {
761: struct arp_eth_header *arp;
762: bool arp_available = arphdr_ok(skb);
763:
764: arp = (struct arp_eth_header *)skb_network_header(skb);
765:
766: if (arp_available &&
767: arp->ar_hrd == htons(ARPHRD_ETHER) &&
768: arp->ar_pro == htons(ETH_P_IP) &&
769: arp->ar_hln == ETH_ALEN &&
770: arp->ar_pln == 4) {
771:
772: /* We only match on the lower 8 bits of the opcode. */
773: if (ntohs(arp->ar_op) <= 0xff)
774: key->ip.proto = ntohs(arp->ar_op);
775: else
776: key->ip.proto = 0;
777:
778: memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
779: memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
780: ether_addr_copy(key->ipv4.arp.sha, arp->ar_sha);
781: ether_addr_copy(key->ipv4.arp.tha, arp->ar_tha);
782: } else {
783: memset(&key->ip, 0, sizeof(key->ip));
784: memset(&key->ipv4, 0, sizeof(key->ipv4));
785: }
786: } else if (eth_p_mpls(key->eth.type)) {
787: size_t label_count = 1;
788:
789: memset(&key->mpls, 0, sizeof(key->mpls));
790: skb_set_inner_network_header(skb, skb->mac_len);
791: while (1) {
792: __be32 lse;
793:
794: error = check_header(skb, skb->mac_len +
795: label_count * MPLS_HLEN);
796: if (unlikely(error))
797: return 0;
798:
799: memcpy(&lse, skb_inner_network_header(skb), MPLS_HLEN);
800:
801: if (label_count <= MPLS_LABEL_DEPTH)
802: memcpy(&key->mpls.lse[label_count - 1], &lse,
803: MPLS_HLEN);
804:
805: skb_set_inner_network_header(skb, skb->mac_len +
806: label_count * MPLS_HLEN);
807: if (lse & htonl(MPLS_LS_S_MASK))
808: break;
809:
810: label_count++;
811: }
812: if (label_count > MPLS_LABEL_DEPTH)
813: label_count = MPLS_LABEL_DEPTH;
814:
815: key->mpls.num_labels_mask = GENMASK(label_count - 1, 0);
816: } else if (key->eth.type == htons(ETH_P_IPV6)) {
817: int nh_len; /* IPv6 Header + Extensions */
818:
819: nh_len = parse_ipv6hdr(skb, key);
820: if (unlikely(nh_len < 0)) {
821: switch (nh_len) {
822: case -EINVAL:
823: memset(&key->ip, 0, sizeof(key->ip));
824: memset(&key->ipv6.addr, 0, sizeof(key->ipv6.addr));
825: fallthrough;
826: case -EPROTO:
827: skb->transport_header = skb->network_header;
828: error = 0;
829: break;
830: default:
831: error = nh_len;
832: }
833: return error;
834: }
835:
836: if (key->ip.frag == OVS_FRAG_TYPE_LATER) {
837: memset(&key->tp, 0, sizeof(key->tp));
838: return 0;
839: }
840: if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
841: key->ip.frag = OVS_FRAG_TYPE_FIRST;
842:
843: /* Transport layer. */
844: if (key->ip.proto == NEXTHDR_TCP) {
845: if (tcphdr_ok(skb)) {
846: struct tcphdr *tcp = tcp_hdr(skb);
847: key->tp.src = tcp->source;
848: key->tp.dst = tcp->dest;
849: key->tp.flags = TCP_FLAGS_BE16(tcp);
850: } else {
851: memset(&key->tp, 0, sizeof(key->tp));
852: }
853: } else if (key->ip.proto == NEXTHDR_UDP) {
854: if (udphdr_ok(skb)) {
855: struct udphdr *udp = udp_hdr(skb);
856: key->tp.src = udp->source;
857: key->tp.dst = udp->dest;
858: } else {
859: memset(&key->tp, 0, sizeof(key->tp));
860: }
861: } else if (key->ip.proto == NEXTHDR_SCTP) {
862: if (sctphdr_ok(skb)) {
863: struct sctphdr *sctp = sctp_hdr(skb);
864: key->tp.src = sctp->source;
865: key->tp.dst = sctp->dest;
866: } else {
867: memset(&key->tp, 0, sizeof(key->tp));
868: }
869: } else if (key->ip.proto == NEXTHDR_ICMP) {
870: if (icmp6hdr_ok(skb)) {
871: error = parse_icmpv6(skb, key, nh_len);
872: if (error)
873: return error;
874: } else {
875: memset(&key->tp, 0, sizeof(key->tp));
876: }
877: }
878: } else if (key->eth.type == htons(ETH_P_NSH)) {
879: error = parse_nsh(skb, key);
880: if (error)
881: return error;
882: }
883: return 0;
884: }
SourceFile:net/openvswitch/flow.c]
|
| 55/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 29494
output: 38
thoughts: 38
Thoughts: **My Thought Process:**
Alright, so I'm looking at this `key_extract_l3l4` function, and I see it's making a call to `parse_ipv6hdr`. This immediately tells me that the IPv6 header parsing logic is encapsulated within `parse_ipv6hdr`. My next step, naturally, is to dive into `parse_ipv6hdr` itself to understand precisely how it's handling the IPv6 header. I need to see what information it's extracting, what the structure of the IPv6 header is in this context, and what the implications are for the overall key extraction process.
|
| 56/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow.c Name:parse_ipv6hdr]
Results: map[SourceCode: 381: static int parse_ipv6hdr(struct sk_buff *skb, struct sw_flow_key *key)
382: {
383: unsigned short frag_off;
384: unsigned int payload_ofs = 0;
385: unsigned int nh_ofs = skb_network_offset(skb);
386: unsigned int nh_len;
387: struct ipv6hdr *nh;
388: int err, nexthdr, flags = 0;
389:
390: err = check_header(skb, nh_ofs + sizeof(*nh));
391: if (unlikely(err))
392: return err;
393:
394: nh = ipv6_hdr(skb);
395:
396: get_ipv6_ext_hdrs(skb, nh, &key->ipv6.exthdrs);
397:
398: key->ip.proto = NEXTHDR_NONE;
399: key->ip.tos = ipv6_get_dsfield(nh);
400: key->ip.ttl = nh->hop_limit;
401: key->ipv6.label = *(__be32 *)nh & htonl(IPV6_FLOWINFO_FLOWLABEL);
402: key->ipv6.addr.src = nh->saddr;
403: key->ipv6.addr.dst = nh->daddr;
404:
405: nexthdr = ipv6_find_hdr(skb, &payload_ofs, -1, &frag_off, &flags);
406: if (flags & IP6_FH_F_FRAG) {
407: if (frag_off) {
408: key->ip.frag = OVS_FRAG_TYPE_LATER;
409: key->ip.proto = NEXTHDR_FRAGMENT;
410: return 0;
411: }
412: key->ip.frag = OVS_FRAG_TYPE_FIRST;
413: } else {
414: key->ip.frag = OVS_FRAG_TYPE_NONE;
415: }
416:
417: /* Delayed handling of error in ipv6_find_hdr() as it
418: * always sets flags and frag_off to a valid value which may be
419: * used to set key->ip.frag above.
420: */
421: if (unlikely(nexthdr < 0))
422: return -EPROTO;
423:
424: nh_len = payload_ofs - nh_ofs;
425: skb_set_transport_header(skb, nh_ofs + nh_len);
426: key->ip.proto = nexthdr;
427: return nh_len;
428: }
SourceFile:net/openvswitch/flow.c]
|
| 57/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 30386
output: 37
thoughts: 556
Thoughts: **My Thought Process Regarding IPv6 Header Parsing and Transport Header State**
Okay, so I was digging into the `parse_ipv6hdr` function and noticed something peculiar. It's supposed to set the transport header for the `skb` using `skb_set_transport_header(skb, nh_ofs + nh_len)`. However, this only happens if `nexthdr` comes back as a non-negative value. If `nexthdr` is less than zero, specifically `-EPROTO`, it signals a protocol error.
Now, I followed that `-EPROTO` return value to how `key_extract_l3l4` handles it. The code shows that if `parse_ipv6hdr` returns `-EPROTO`, the `key_extract_l3l4` function executes `skb->transport_header = skb->network_header;`. This seems to imply that the transport header *is* being set, albeit by copying the network header pointer.
This leads me to a contradiction: if the transport header is being set in this `-EPROTO` scenario, why is `skb_transport_header_was_set(skb)` returning `false`? It makes me wonder if there's another code path where `skb->transport_header` isn't being set, even when we expect it to be.
I decided to revisit `ovs_flow_key_extract_userspace`. It calls `key_extract(skb, key)` and returns early if there's an error. The implication is that if `key_extract` succeeds, the transport header *should* be set.
Then, a new scenario popped into my head: what if the initial `key->eth.type` isn't `ETH_P_IPV6` when `key_extract` is called, but a subsequent action modifies it to be IPv6? If `key->eth.type` isn't `ETH_P_IPV6` initially, then `key_extract_l3l4` wouldn't even call `parse_ipv6hdr`. For instance, if it's `ETH_P_IP` (IPv4), it would call `check_iphdr(skb)`. This prompts me to look closer at `check_iphdr` – specifically, how it sets the `skb->transport_header` in the IPv4 case. Does it actually set `skb->transport_header = skb->network_header + ip_hdr(skb)->ihl * 4`? I need to verify that.
|
| 58/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow.c Name:check_iphdr]
Results: map[SourceCode: 190: static int check_iphdr(struct sk_buff *skb)
191: {
192: unsigned int nh_ofs = skb_network_offset(skb);
193: unsigned int ip_len;
194: int err;
195:
196: err = check_header(skb, nh_ofs + sizeof(struct iphdr));
197: if (unlikely(err))
198: return err;
199:
200: ip_len = ip_hdrlen(skb);
201: if (unlikely(ip_len < sizeof(struct iphdr) ||
202: skb->len < nh_ofs + ip_len))
203: return -EINVAL;
204:
205: skb_set_transport_header(skb, nh_ofs + ip_len);
206: return 0;
207: }
SourceFile:net/openvswitch/flow.c]
|
| 59/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 31257
output: 38
thoughts: 288
Thoughts: **My Thought Process Regarding `check_iphdr` and ARP Packets**
So, I'm reviewing the `check_iphdr` function, and it seems straightforward enough – it's designed to set the transport header. My initial thought is, "Okay, that makes sense for typical IP traffic." But then a crucial question pops into my mind: what happens when the Ethernet type isn't what we'd expect for IP traffic? Specifically, what if `key->eth.type` is something like `ETH_P_ARP` (Address Resolution Protocol)?
I need to dig into how `key_extract_l3l4` behaves in this scenario. If `key->eth.type` is indeed `ETH_P_ARP`, my immediate concern is that `key_extract_l3l4` *won't* set the transport header. This would mean `skb->transport_header` would retain its default value, which is `~0U` (essentially an invalid or unset state) as allocated with the `skb`.
To confirm this, I'm going to specifically examine the `key_extract_l3l4` code when it encounters `ETH_P_ARP`. Looking at the relevant section:
```c
} else if (key->eth.type == htons(ETH_P_ARP) ||
key->eth.type == htons(ETH_P_RARP)) {
struct arp_eth_header *arp;
bool arp_available = arphdr_ok(skb);
// ...
```
As I suspected, this code path for ARP/RARP **does not set** `skb->transport_header`. This confirms my hypothesis that `skb->transport_header` will remain `~0U` if the packet is ARP.
Now, this leads to a potentially problematic situation. If the userspace logic then attempts to apply an action like `set_ipv6`, that action will likely delegate to `set_ipv6`, which in turn calls `set_ipv6_addr`, and finally `update_ipv6_checksum`.
This is where a critical logical flaw could arise. I need to ask myself: *can userspace even provide a `set_ipv6` action for a packet that is clearly identified as an ARP packet?* This seems like an illogical application of functionality. To resolve this, I need to trace the flow of control within `ovs_execute_actions` to understand if such a scenario is even permitted by the framework. The implications of trying to apply an IPv6-specific action to an ARP packet are significant and could lead to incorrect packet handling or errors.
|
| 60/2 |
2026/10/01 02:05 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:do_execute_actions]
Results: map[SourceCode:1254: /* Execute a list of actions against 'skb'. */
1255: static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
1256: struct sw_flow_key *key,
1257: const struct nlattr *attr, int len)
1258: {
1259: const struct nlattr *a;
1260: int rem;
1261:
1262: for (a = attr, rem = len; rem > 0;
1263: a = nla_next(a, &rem)) {
1264: int err = 0;
1265:
1266: if (trace_ovs_do_execute_action_enabled())
1267: trace_ovs_do_execute_action(dp, skb, key, a, rem);
1268:
1269: /* Actions that rightfully have to consume the skb should do it
1270: * and return directly.
1271: */
1272: switch (nla_type(a)) {
1273: case OVS_ACTION_ATTR_OUTPUT: {
1274: int port = nla_get_u32(a);
1275: struct sk_buff *clone;
1276:
1277: /* Every output action needs a separate clone
1278: * of 'skb', In case the output action is the
1279: * last action, cloning can be avoided.
1280: */
1281: if (nla_is_last(a, rem)) {
1282: do_output(dp, skb, port, key);
1283: /* 'skb' has been used for output.
1284: */
1285: return 0;
1286: }
1287:
1288: clone = skb_clone(skb, GFP_ATOMIC);
1289: if (clone)
1290: do_output(dp, clone, port, key);
1291: OVS_CB(skb)->cutlen = U32_MAX;
1292: break;
1293: }
1294:
1295: case OVS_ACTION_ATTR_TRUNC: {
1296: struct ovs_action_trunc *trunc = nla_data(a);
1297:
1298: OVS_CB(skb)->cutlen = trunc->max_len;
1299: break;
1300: }
1301:
1302: case OVS_ACTION_ATTR_USERSPACE:
1303: output_userspace(dp, skb, key, a, attr,
1304: len, OVS_CB(skb)->cutlen);
1305: OVS_CB(skb)->cutlen = U32_MAX;
1306: if (nla_is_last(a, rem)) {
1307: consume_skb(skb);
1308: return 0;
1309: }
1310: break;
1311:
1312: case OVS_ACTION_ATTR_HASH:
1313: execute_hash(skb, key, a);
1314: break;
1315:
1316: case OVS_ACTION_ATTR_PUSH_MPLS: {
1317: struct ovs_action_push_mpls *mpls = nla_data(a);
1318:
1319: err = push_mpls(skb, key, mpls->mpls_lse,
1320: mpls->mpls_ethertype, skb->mac_len);
1321: break;
1322: }
1323: case OVS_ACTION_ATTR_ADD_MPLS: {
1324: struct ovs_action_add_mpls *mpls = nla_data(a);
1325: __u16 mac_len = 0;
1326:
1327: if (mpls->tun_flags & OVS_MPLS_L3_TUNNEL_FLAG_MASK)
1328: mac_len = skb->mac_len;
1329:
1330: err = push_mpls(skb, key, mpls->mpls_lse,
1331: mpls->mpls_ethertype, mac_len);
1332: break;
1333: }
1334: case OVS_ACTION_ATTR_POP_MPLS:
1335: err = pop_mpls(skb, key, nla_get_be16(a));
1336: break;
1337:
1338: case OVS_ACTION_ATTR_PUSH_VLAN:
1339: err = push_vlan(skb, key, nla_data(a));
1340: break;
1341:
1342: case OVS_ACTION_ATTR_POP_VLAN:
1343: err = pop_vlan(skb, key);
1344: break;
1345:
1346: case OVS_ACTION_ATTR_RECIRC: {
1347: bool last = nla_is_last(a, rem);
1348:
1349: err = execute_recirc(dp, skb, key, a, last);
1350: if (last) {
1351: /* If this is the last action, the skb has
1352: * been consumed or freed.
1353: * Return immediately.
1354: */
1355: return err;
1356: }
1357: break;
1358: }
1359:
1360: case OVS_ACTION_ATTR_SET:
1361: err = execute_set_action(skb, key, nla_data(a));
1362: break;
1363:
1364: case OVS_ACTION_ATTR_SET_MASKED:
1365: case OVS_ACTION_ATTR_SET_TO_MASKED:
1366: err = execute_masked_set_action(skb, key, nla_data(a));
1367: break;
1368:
1369: case OVS_ACTION_ATTR_SAMPLE: {
1370: bool last = nla_is_last(a, rem);
1371:
1372: err = sample(dp, skb, key, a, last);
1373: if (last)
1374: return err;
1375:
1376: break;
1377: }
1378:
1379: case OVS_ACTION_ATTR_CT:
1380: if (!is_flow_key_valid(key)) {
1381: err = ovs_flow_key_update(skb, key);
1382: if (err)
1383: break;
1384: }
1385:
1386: err = ovs_ct_execute(ovs_dp_get_net(dp), skb, key,
1387: nla_data(a));
1388:
1389: /* Hide stolen IP fragments from user space. */
1390: if (err)
1391: return err == -EINPROGRESS ? 0 : err;
1392: break;
1393:
1394: case OVS_ACTION_ATTR_CT_CLEAR:
1395: err = ovs_ct_clear(skb, key);
1396: break;
1397:
1398: case OVS_ACTION_ATTR_PUSH_ETH:
1399: err = push_eth(skb, key, nla_data(a));
1400: break;
1401:
1402: case OVS_ACTION_ATTR_POP_ETH:
1403: err = pop_eth(skb, key);
1404: break;
1405:
1406: case OVS_ACTION_ATTR_PUSH_NSH:
1407: err = push_nsh(skb, key, nla_data(a));
1408: break;
1409:
1410: case OVS_ACTION_ATTR_POP_NSH:
1411: err = pop_nsh(skb, key);
1412: break;
1413:
1414: case OVS_ACTION_ATTR_METER:
1415: if (ovs_meter_execute(dp, skb, key, nla_get_u32(a))) {
1416: ovs_kfree_skb_reason(skb, OVS_DROP_METER);
1417: return 0;
1418: }
1419: break;
1420:
1421: case OVS_ACTION_ATTR_CLONE: {
1422: bool last = nla_is_last(a, rem);
1423:
1424: err = clone(dp, skb, key, a, last);
1425: if (last)
1426: return err;
1427:
1428: break;
1429: }
1430:
1431: case OVS_ACTION_ATTR_CHECK_PKT_LEN: {
1432: bool last = nla_is_last(a, rem);
1433:
1434: err = execute_check_pkt_len(dp, skb, key, a, last);
1435: if (last)
1436: return err;
1437:
1438: break;
1439: }
1440:
1441: case OVS_ACTION_ATTR_DEC_TTL:
1442: err = execute_dec_ttl(skb, key);
1443: if (err == -EHOSTUNREACH)
1444: return dec_ttl_exception_handler(dp, skb,
1445: key, a);
1446: break;
1447:
1448: case OVS_ACTION_ATTR_DROP: {
1449: enum ovs_drop_reason reason = nla_get_u32(a)
1450: ? OVS_DROP_EXPLICIT_WITH_ERROR
1451: : OVS_DROP_EXPLICIT;
1452:
1453: ovs_kfree_skb_reason(skb, reason);
1454: return 0;
1455: }
1456:
1457: case OVS_ACTION_ATTR_PSAMPLE:
1458: execute_psample(dp, skb, a);
1459: OVS_CB(skb)->cutlen = U32_MAX;
1460: if (nla_is_last(a, rem)) {
1461: consume_skb(skb);
1462: return 0;
1463: }
1464: break;
1465: }
1466:
1467: if (unlikely(err)) {
1468: ovs_kfree_skb_reason(skb, OVS_DROP_ACTION_ERROR);
1469: return err;
1470: }
1471: }
1472:
1473: ovs_kfree_skb_reason(skb, OVS_DROP_LAST_ACTION);
1474: return 0;
1475: }
SourceFile:net/openvswitch/actions.c]
|
| 61/2 |
2026/10/01 02:05 |
llm |
expert |
0m
Model:
Tokens:
input: 34837
output: 40
thoughts: 32
Thoughts: **A Deep Dive into the `execute_masked_set_action` and `set_ipv6` Relationship**
My initial thought process, upon encountering a certain code block, was one of immediate curiosity and a need for verification. I noticed a call to a function, `execute_masked_set_action`, and within that function, I observed it subsequently invoking another function: `set_ipv6`. This connection, while potentially straightforward, immediately triggered a desire to scrutinize it more closely. My expertise in this domain dictates that understanding the flow of control and the interdependencies between functions is paramount to grasping the system's behavior. Therefore, my immediate next step was to delve into the implementation details of `execute_masked_set_action` to confirm this observation and, more importantly, to understand the *why* behind this particular call chain. I needed to see, with my own eyes, the precise context in which `set_ipv6` is invoked by `execute_masked_set_action` to ensure I wasn't missing any nuances or subtle implications.
|
| 62/2 |
2026/10/01 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:execute_masked_set_action]
Results: map[SourceCode:1039: static int execute_masked_set_action(struct sk_buff *skb,
1040: struct sw_flow_key *flow_key,
1041: const struct nlattr *a)
1042: {
1043: int err = 0;
1044:
1045: switch (nla_type(a)) {
1046: case OVS_KEY_ATTR_PRIORITY:
1047: OVS_SET_MASKED(skb->priority, nla_get_u32(a),
1048: *get_mask(a, u32 *));
1049: flow_key->phy.priority = skb->priority;
1050: break;
1051:
1052: case OVS_KEY_ATTR_SKB_MARK:
1053: OVS_SET_MASKED(skb->mark, nla_get_u32(a), *get_mask(a, u32 *));
1054: flow_key->phy.skb_mark = skb->mark;
1055: break;
1056:
1057: case OVS_KEY_ATTR_TUNNEL_INFO:
1058: /* Masked data not supported for tunnel. */
1059: err = -EINVAL;
1060: break;
1061:
1062: case OVS_KEY_ATTR_ETHERNET:
1063: err = set_eth_addr(skb, flow_key, nla_data(a),
1064: get_mask(a, struct ovs_key_ethernet *));
1065: break;
1066:
1067: case OVS_KEY_ATTR_IPV4:
1068: err = set_ipv4(skb, flow_key, nla_data(a),
1069: get_mask(a, struct ovs_key_ipv4 *));
1070: break;
1071:
1072: case OVS_KEY_ATTR_IPV6:
1073: err = set_ipv6(skb, flow_key, nla_data(a),
1074: get_mask(a, struct ovs_key_ipv6 *));
1075: break;
1076:
1077: case OVS_KEY_ATTR_TCP:
1078: err = set_tcp(skb, flow_key, nla_data(a),
1079: get_mask(a, struct ovs_key_tcp *));
1080: break;
1081:
1082: case OVS_KEY_ATTR_UDP:
1083: err = set_udp(skb, flow_key, nla_data(a),
1084: get_mask(a, struct ovs_key_udp *));
1085: break;
1086:
1087: case OVS_KEY_ATTR_SCTP:
1088: err = set_sctp(skb, flow_key, nla_data(a),
1089: get_mask(a, struct ovs_key_sctp *));
1090: break;
1091:
1092: case OVS_KEY_ATTR_MPLS:
1093: err = set_mpls(skb, flow_key, nla_data(a), get_mask(a,
1094: __be32 *));
1095: break;
1096:
1097: case OVS_KEY_ATTR_CT_STATE:
1098: case OVS_KEY_ATTR_CT_ZONE:
1099: case OVS_KEY_ATTR_CT_MARK:
1100: case OVS_KEY_ATTR_CT_LABELS:
1101: case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4:
1102: case OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6:
1103: case OVS_KEY_ATTR_NSH:
1104: err = -EINVAL;
1105: break;
1106: }
1107:
1108: return err;
1109: }
SourceFile:net/openvswitch/actions.c]
|
| 63/2 |
2026/10/01 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 36096
output: 45
thoughts: 41
Thoughts: **My Thought Process**
My primary concern here is ensuring the integrity and correctness of how we handle IPv6-specific actions within our networking framework. I need to confirm that any attempt to set IPv6-related parameters is predicated on the packet actually being an IPv6 packet. This isn't just a matter of defensive programming; it's crucial for preventing malformed packets, unexpected behavior, and potential security vulnerabilities.
To address this, I'm going to delve into the `ovs_nla_copy_actions` function. My hypothesis is that within this function, or in closely related logic that it calls, there must be some form of validation. I'm looking for a check that inspects the packet's header or metadata to confirm its IP version before permitting any `set_ipv6` operations. If such a check isn't present, it would imply a potential gap that needs to be addressed. I expect to find a conditional branch or a specific validation routine that explicitly verifies the packet's IPv6 nature. The absence of this would be a red flag, indicating that an `set_ipv6` call could be mistakenly applied to an IPv4 packet, leading to unpredictable outcomes and a violation of expected packet processing rules.
|
| 64/2 |
2026/10/01 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:ovs_nla_copy_actions]
Results: map[SourceCode:3603: /* 'key' must be the masked key. */
3604: int ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
3605: const struct sw_flow_key *key,
3606: struct sw_flow_actions **sfa, bool log)
3607: {
3608: int err;
3609: u32 mpls_label_count = 0;
3610:
3611: *sfa = nla_alloc_flow_actions(nla_len(attr));
3612: if (IS_ERR(*sfa))
3613: return PTR_ERR(*sfa);
3614:
3615: if (eth_p_mpls(key->eth.type))
3616: mpls_label_count = hweight_long(key->mpls.num_labels_mask);
3617:
3618: (*sfa)->orig_len = nla_len(attr);
3619: err = __ovs_nla_copy_actions(net, attr, key, sfa, key->eth.type,
3620: key->eth.vlan.tci, mpls_label_count, log,
3621: 0);
3622: if (err)
3623: ovs_nla_free_flow_actions(*sfa);
3624:
3625: return err;
3626: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 65/2 |
2026/10/01 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 36603
output: 46
thoughts: 16
Thoughts: **My Thought Process Regarding `__ovs_nla_copy_actions`**
Alright, the immediate thought that comes to mind is a need to scrutinize the `__ovs_nla_copy_actions` function. This isn't just a casual glance; I need to dive deep into its mechanics. My objective here is to fully understand its role in handling Netlink Attributes (NLAs) specifically related to Open vSwitch (OVS) actions. I want to know *precisely* how it copies these action NLAs – what are the underlying mechanisms, what data structures are involved, and what are the potential pitfalls or edge cases during this copying process. I'm particularly interested in the efficiency and robustness of this operation, as any inefficiencies or vulnerabilities here could have cascading effects on OVS performance and security. Ultimately, I want to be able to articulate its function, its limitations, and any optimizations that might be possible.
|
| 66/2 |
2026/10/01 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:__ovs_nla_copy_actions]
Results: map[SourceCode:3260: static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
3261: const struct sw_flow_key *key,
3262: struct sw_flow_actions **sfa,
3263: __be16 eth_type, __be16 vlan_tci,
3264: u32 mpls_label_count, bool log,
3265: u32 depth)
3266: {
3267: u8 mac_proto = ovs_key_mac_proto(key);
3268: const struct nlattr *a;
3269: int rem, err;
3270:
3271: if (depth > OVS_COPY_ACTIONS_MAX_DEPTH)
3272: return -EOVERFLOW;
3273:
3274: nla_for_each_nested(a, attr, rem) {
3275: /* Expected argument lengths, (u32)-1 for variable length. */
3276: static const u32 action_lens[OVS_ACTION_ATTR_MAX + 1] = {
3277: [OVS_ACTION_ATTR_OUTPUT] = sizeof(u32),
3278: [OVS_ACTION_ATTR_RECIRC] = sizeof(u32),
3279: [OVS_ACTION_ATTR_USERSPACE] = (u32)-1,
3280: [OVS_ACTION_ATTR_PUSH_MPLS] = sizeof(struct ovs_action_push_mpls),
3281: [OVS_ACTION_ATTR_POP_MPLS] = sizeof(__be16),
3282: [OVS_ACTION_ATTR_PUSH_VLAN] = sizeof(struct ovs_action_push_vlan),
3283: [OVS_ACTION_ATTR_POP_VLAN] = 0,
3284: [OVS_ACTION_ATTR_SET] = (u32)-1,
3285: [OVS_ACTION_ATTR_SET_MASKED] = (u32)-1,
3286: [OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
3287: [OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash),
3288: [OVS_ACTION_ATTR_CT] = (u32)-1,
3289: [OVS_ACTION_ATTR_CT_CLEAR] = 0,
3290: [OVS_ACTION_ATTR_TRUNC] = sizeof(struct ovs_action_trunc),
3291: [OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
3292: [OVS_ACTION_ATTR_POP_ETH] = 0,
3293: [OVS_ACTION_ATTR_PUSH_NSH] = (u32)-1,
3294: [OVS_ACTION_ATTR_POP_NSH] = 0,
3295: [OVS_ACTION_ATTR_METER] = sizeof(u32),
3296: [OVS_ACTION_ATTR_CLONE] = (u32)-1,
3297: [OVS_ACTION_ATTR_CHECK_PKT_LEN] = (u32)-1,
3298: [OVS_ACTION_ATTR_ADD_MPLS] = sizeof(struct ovs_action_add_mpls),
3299: [OVS_ACTION_ATTR_DEC_TTL] = (u32)-1,
3300: [OVS_ACTION_ATTR_DROP] = sizeof(u32),
3301: [OVS_ACTION_ATTR_PSAMPLE] = (u32)-1,
3302: };
3303: const struct ovs_action_push_vlan *vlan;
3304: int type = nla_type(a);
3305: bool skip_copy;
3306:
3307: if (type > OVS_ACTION_ATTR_MAX ||
3308: (action_lens[type] != nla_len(a) &&
3309: action_lens[type] != (u32)-1))
3310: return -EINVAL;
3311:
3312: skip_copy = false;
3313: switch (type) {
3314: case OVS_ACTION_ATTR_UNSPEC:
3315: return -EINVAL;
3316:
3317: case OVS_ACTION_ATTR_USERSPACE:
3318: err = validate_userspace(a);
3319: if (err)
3320: return err;
3321: break;
3322:
3323: case OVS_ACTION_ATTR_OUTPUT:
3324: if (nla_get_u32(a) >= DP_MAX_PORTS)
3325: return -EINVAL;
3326: break;
3327:
3328: case OVS_ACTION_ATTR_TRUNC: {
3329: const struct ovs_action_trunc *trunc = nla_data(a);
3330:
3331: if (trunc->max_len < ETH_HLEN)
3332: return -EINVAL;
3333: break;
3334: }
3335:
3336: case OVS_ACTION_ATTR_HASH: {
3337: const struct ovs_action_hash *act_hash = nla_data(a);
3338:
3339: switch (act_hash->hash_alg) {
3340: case OVS_HASH_ALG_L4:
3341: fallthrough;
3342: case OVS_HASH_ALG_SYM_L4:
3343: break;
3344: default:
3345: return -EINVAL;
3346: }
3347:
3348: break;
3349: }
3350:
3351: case OVS_ACTION_ATTR_POP_VLAN:
3352: if (mac_proto != MAC_PROTO_ETHERNET)
3353: return -EINVAL;
3354: vlan_tci = htons(0);
3355: break;
3356:
3357: case OVS_ACTION_ATTR_PUSH_VLAN:
3358: if (mac_proto != MAC_PROTO_ETHERNET)
3359: return -EINVAL;
3360: vlan = nla_data(a);
3361: if (!eth_type_vlan(vlan->vlan_tpid))
3362: return -EINVAL;
3363: if (!(vlan->vlan_tci & htons(VLAN_CFI_MASK)))
3364: return -EINVAL;
3365: vlan_tci = vlan->vlan_tci;
3366: break;
3367:
3368: case OVS_ACTION_ATTR_RECIRC:
3369: break;
3370:
3371: case OVS_ACTION_ATTR_ADD_MPLS: {
3372: const struct ovs_action_add_mpls *mpls = nla_data(a);
3373:
3374: if (!eth_p_mpls(mpls->mpls_ethertype))
3375: return -EINVAL;
3376:
3377: if (mpls->tun_flags & OVS_MPLS_L3_TUNNEL_FLAG_MASK) {
3378: if (vlan_tci & htons(VLAN_CFI_MASK) ||
3379: (eth_type != htons(ETH_P_IP) &&
3380: eth_type != htons(ETH_P_IPV6) &&
3381: eth_type != htons(ETH_P_ARP) &&
3382: eth_type != htons(ETH_P_RARP) &&
3383: !eth_p_mpls(eth_type)))
3384: return -EINVAL;
3385: mpls_label_count++;
3386: } else {
3387: if (mac_proto == MAC_PROTO_ETHERNET) {
3388: mpls_label_count = 1;
3389: mac_proto = MAC_PROTO_NONE;
3390: } else {
3391: mpls_label_count++;
3392: }
3393: }
3394: eth_type = mpls->mpls_ethertype;
3395: break;
3396: }
3397:
3398: case OVS_ACTION_ATTR_PUSH_MPLS: {
3399: const struct ovs_action_push_mpls *mpls = nla_data(a);
3400:
3401: if (!eth_p_mpls(mpls->mpls_ethertype))
3402: return -EINVAL;
3403: /* Prohibit push MPLS other than to a white list
3404: * for packets that have a known tag order.
3405: */
3406: if (vlan_tci & htons(VLAN_CFI_MASK) ||
3407: (eth_type != htons(ETH_P_IP) &&
3408: eth_type != htons(ETH_P_IPV6) &&
3409: eth_type != htons(ETH_P_ARP) &&
3410: eth_type != htons(ETH_P_RARP) &&
3411: !eth_p_mpls(eth_type)))
3412: return -EINVAL;
3413: eth_type = mpls->mpls_ethertype;
3414: mpls_label_count++;
3415: break;
3416: }
3417:
3418: case OVS_ACTION_ATTR_POP_MPLS: {
3419: __be16 proto;
3420: if (vlan_tci & htons(VLAN_CFI_MASK) ||
3421: !eth_p_mpls(eth_type))
3422: return -EINVAL;
3423:
3424: /* Disallow subsequent L2.5+ set actions and mpls_pop
3425: * actions once the last MPLS label in the packet is
3426: * popped as there is no check here to ensure that
3427: * the new eth type is valid and thus set actions could
3428: * write off the end of the packet or otherwise corrupt
3429: * it.
3430: *
3431: * Support for these actions is planned using packet
3432: * recirculation.
3433: */
3434: proto = nla_get_be16(a);
3435:
3436: if (proto == htons(ETH_P_TEB) &&
3437: mac_proto != MAC_PROTO_NONE)
3438: return -EINVAL;
3439:
3440: mpls_label_count--;
3441:
3442: if (!eth_p_mpls(proto) || !mpls_label_count)
3443: eth_type = htons(0);
3444: else
3445: eth_type = proto;
3446:
3447: break;
3448: }
3449:
3450: case OVS_ACTION_ATTR_SET:
3451: err = validate_set(a, key, sfa,
3452: &skip_copy, mac_proto, eth_type,
3453: false, log);
3454: if (err)
3455: return err;
3456: break;
3457:
3458: case OVS_ACTION_ATTR_SET_MASKED:
3459: err = validate_set(a, key, sfa,
3460: &skip_copy, mac_proto, eth_type,
3461: true, log);
3462: if (err)
3463: return err;
3464: break;
3465:
3466: case OVS_ACTION_ATTR_SAMPLE: {
3467: bool last = nla_is_last(a, rem);
3468:
3469: err = validate_and_copy_sample(net, a, key, sfa,
3470: eth_type, vlan_tci,
3471: mpls_label_count,
3472: log, last, depth);
3473: if (err)
3474: return err;
3475: skip_copy = true;
3476: break;
3477: }
3478:
3479: case OVS_ACTION_ATTR_CT:
3480: err = ovs_ct_copy_action(net, a, key, sfa, log);
3481: if (err)
3482: return err;
3483: skip_copy = true;
3484: break;
3485:
3486: case OVS_ACTION_ATTR_CT_CLEAR:
3487: break;
3488:
3489: case OVS_ACTION_ATTR_PUSH_ETH:
3490: /* Disallow pushing an Ethernet header if one
3491: * is already present */
3492: if (mac_proto != MAC_PROTO_NONE)
3493: return -EINVAL;
3494: mac_proto = MAC_PROTO_ETHERNET;
3495: break;
3496:
3497: case OVS_ACTION_ATTR_POP_ETH:
3498: if (mac_proto != MAC_PROTO_ETHERNET)
3499: return -EINVAL;
3500: if (vlan_tci & htons(VLAN_CFI_MASK))
3501: return -EINVAL;
3502: mac_proto = MAC_PROTO_NONE;
3503: break;
3504:
3505: case OVS_ACTION_ATTR_PUSH_NSH:
3506: if (mac_proto != MAC_PROTO_ETHERNET) {
3507: u8 next_proto;
3508:
3509: next_proto = tun_p_from_eth_p(eth_type);
3510: if (!next_proto)
3511: return -EINVAL;
3512: }
3513: mac_proto = MAC_PROTO_NONE;
3514: if (!validate_push_nsh(a, log))
3515: return -EINVAL;
3516: break;
3517:
3518: case OVS_ACTION_ATTR_POP_NSH: {
3519: __be16 inner_proto;
3520:
3521: if (eth_type != htons(ETH_P_NSH))
3522: return -EINVAL;
3523: inner_proto = tun_p_to_eth_p(key->nsh.base.np);
3524: if (!inner_proto)
3525: return -EINVAL;
3526: if (key->nsh.base.np == TUN_P_ETHERNET)
3527: mac_proto = MAC_PROTO_ETHERNET;
3528: else
3529: mac_proto = MAC_PROTO_NONE;
3530: break;
3531: }
3532:
3533: case OVS_ACTION_ATTR_METER:
3534: /* Non-existent meters are simply ignored. */
3535: break;
3536:
3537: case OVS_ACTION_ATTR_CLONE: {
3538: bool last = nla_is_last(a, rem);
3539:
3540: err = validate_and_copy_clone(net, a, key, sfa,
3541: eth_type, vlan_tci,
3542: mpls_label_count,
3543: log, last, depth);
3544: if (err)
3545: return err;
3546: skip_copy = true;
3547: break;
3548: }
3549:
3550: case OVS_ACTION_ATTR_CHECK_PKT_LEN: {
3551: bool last = nla_is_last(a, rem);
3552:
3553: err = validate_and_copy_check_pkt_len(net, a, key, sfa,
3554: eth_type,
3555: vlan_tci,
3556: mpls_label_count,
3557: log, last,
3558: depth);
3559: if (err)
3560: return err;
3561: skip_copy = true;
3562: break;
3563: }
3564:
3565: case OVS_ACTION_ATTR_DEC_TTL:
3566: err = validate_and_copy_dec_ttl(net, a, key, sfa,
3567: eth_type, vlan_tci,
3568: mpls_label_count, log,
3569: depth);
3570: if (err)
3571: return err;
3572: skip_copy = true;
3573: break;
3574:
3575: case OVS_ACTION_ATTR_DROP:
3576: if (!nla_is_last(a, rem))
3577: return -EINVAL;
3578: break;
3579:
3580: case OVS_ACTION_ATTR_PSAMPLE:
3581: err = validate_psample(a);
3582: if (err)
3583: return err;
3584: break;
3585:
3586: default:
3587: OVS_NLERR(log, "Unknown Action type %d", type);
3588: return -EINVAL;
3589: }
3590: if (!skip_copy) {
3591: err = copy_action(a, sfa, log);
3592: if (err)
3593: return err;
3594: }
3595: }
3596:
3597: if (rem > 0)
3598: return -EINVAL;
3599:
3600: return 0;
3601: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 67/2 |
2026/10/01 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 41910
output: 39
thoughts: 42
Thoughts: **A Deep Dive into Validation Logic**
My thought process immediately fixated on the handling of the `OVS_ACTION_ATTR_SET` and `OVS_ACTION_ATTR_SET_MASKED` attributes within the OVS (Open vSwitch) framework. It's a natural progression to then examine the associated validation function, `validate_set`, as this is where the core logic for ensuring the integrity and correctness of these actions resides. My immediate next step, therefore, is to scrutinize the inner workings of `validate_set` itself.
|
| 68/2 |
2026/10/01 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:validate_set]
Results: map[SourceCode:2919: static int validate_set(const struct nlattr *a,
2920: const struct sw_flow_key *flow_key,
2921: struct sw_flow_actions **sfa, bool *skip_copy,
2922: u8 mac_proto, __be16 eth_type, bool masked, bool log)
2923: {
2924: const struct nlattr *ovs_key = nla_data(a);
2925: int key_type = nla_type(ovs_key);
2926: size_t key_len;
2927:
2928: /* There can be only one key in a action */
2929: if (!nla_ok(ovs_key, nla_len(a)) ||
2930: nla_total_size(nla_len(ovs_key)) != nla_len(a))
2931: return -EINVAL;
2932:
2933: key_len = nla_len(ovs_key);
2934: if (masked)
2935: key_len /= 2;
2936:
2937: if (key_type > OVS_KEY_ATTR_MAX ||
2938: !check_attr_len(key_len, ovs_key_lens[key_type].len))
2939: return -EINVAL;
2940:
2941: if (masked && !validate_masked(nla_data(ovs_key), key_len))
2942: return -EINVAL;
2943:
2944: switch (key_type) {
2945: case OVS_KEY_ATTR_PRIORITY:
2946: case OVS_KEY_ATTR_SKB_MARK:
2947: case OVS_KEY_ATTR_CT_MARK:
2948: case OVS_KEY_ATTR_CT_LABELS:
2949: break;
2950:
2951: case OVS_KEY_ATTR_ETHERNET:
2952: if (mac_proto != MAC_PROTO_ETHERNET)
2953: return -EINVAL;
2954: break;
2955:
2956: case OVS_KEY_ATTR_TUNNEL: {
2957: int err;
2958:
2959: if (masked)
2960: return -EINVAL; /* Masked tunnel set not supported. */
2961:
2962: *skip_copy = true;
2963: err = validate_and_copy_set_tun(a, sfa, log);
2964: if (err)
2965: return err;
2966: break;
2967: }
2968: case OVS_KEY_ATTR_IPV4: {
2969: const struct ovs_key_ipv4 *ipv4_key;
2970:
2971: if (eth_type != htons(ETH_P_IP))
2972: return -EINVAL;
2973:
2974: ipv4_key = nla_data(ovs_key);
2975:
2976: if (masked) {
2977: const struct ovs_key_ipv4 *mask = ipv4_key + 1;
2978:
2979: /* Non-writeable fields. */
2980: if (mask->ipv4_proto || mask->ipv4_frag)
2981: return -EINVAL;
2982: } else {
2983: if (ipv4_key->ipv4_proto != flow_key->ip.proto)
2984: return -EINVAL;
2985:
2986: if (ipv4_key->ipv4_frag != flow_key->ip.frag)
2987: return -EINVAL;
2988: }
2989: break;
2990: }
2991: case OVS_KEY_ATTR_IPV6: {
2992: const struct ovs_key_ipv6 *ipv6_key;
2993:
2994: if (eth_type != htons(ETH_P_IPV6))
2995: return -EINVAL;
2996:
2997: ipv6_key = nla_data(ovs_key);
2998:
2999: if (masked) {
3000: const struct ovs_key_ipv6 *mask = ipv6_key + 1;
3001:
3002: /* Non-writeable fields. */
3003: if (mask->ipv6_proto || mask->ipv6_frag)
3004: return -EINVAL;
3005:
3006: /* Invalid bits in the flow label mask? */
3007: if (ntohl(mask->ipv6_label) & 0xFFF00000)
3008: return -EINVAL;
3009: } else {
3010: if (ipv6_key->ipv6_proto != flow_key->ip.proto)
3011: return -EINVAL;
3012:
3013: if (ipv6_key->ipv6_frag != flow_key->ip.frag)
3014: return -EINVAL;
3015: }
3016: if (ntohl(ipv6_key->ipv6_label) & 0xFFF00000)
3017: return -EINVAL;
3018:
3019: break;
3020: }
3021: case OVS_KEY_ATTR_TCP:
3022: if ((eth_type != htons(ETH_P_IP) &&
3023: eth_type != htons(ETH_P_IPV6)) ||
3024: flow_key->ip.proto != IPPROTO_TCP)
3025: return -EINVAL;
3026:
3027: break;
3028:
3029: case OVS_KEY_ATTR_UDP:
3030: if ((eth_type != htons(ETH_P_IP) &&
3031: eth_type != htons(ETH_P_IPV6)) ||
3032: flow_key->ip.proto != IPPROTO_UDP)
3033: return -EINVAL;
3034:
3035: break;
3036:
3037: case OVS_KEY_ATTR_MPLS:
3038: if (!eth_p_mpls(eth_type))
3039: return -EINVAL;
3040: if (key_len != sizeof(struct ovs_key_mpls))
3041: return -EINVAL;
3042: break;
3043:
3044: case OVS_KEY_ATTR_SCTP:
3045: if ((eth_type != htons(ETH_P_IP) &&
3046: eth_type != htons(ETH_P_IPV6)) ||
3047: flow_key->ip.proto != IPPROTO_SCTP)
3048: return -EINVAL;
3049:
3050: break;
3051:
3052: default:
3053: return -EINVAL;
3054: }
3055:
3056: /* Convert non-masked non-tunnel set actions to masked set actions. */
3057: if (!masked && key_type != OVS_KEY_ATTR_TUNNEL) {
3058: int err, start, len = key_len * 2;
3059: struct nlattr *at;
3060:
3061: *skip_copy = true;
3062:
3063: start = add_nested_action_start(sfa,
3064: OVS_ACTION_ATTR_SET_TO_MASKED,
3065: log);
3066: if (start < 0)
3067: return start;
3068:
3069: at = __add_action(sfa, key_type, NULL, len, log);
3070: if (IS_ERR(at)) {
3071: err = PTR_ERR(at);
3072: (*sfa)->actions_len = start;
3073: return err;
3074: }
3075:
3076: memcpy(nla_data(at), nla_data(ovs_key), key_len); /* Key. */
3077: memset(nla_data(at) + key_len, 0xff, key_len); /* Mask. */
3078: /* Clear non-writeable bits from otherwise writeable fields. */
3079: if (key_type == OVS_KEY_ATTR_IPV6) {
3080: struct ovs_key_ipv6 *mask = nla_data(at) + key_len;
3081:
3082: mask->ipv6_label &= htonl(0x000FFFFF);
3083: }
3084: err = add_nested_action_end(*sfa, start);
3085: if (WARN_ON_ONCE(err)) {
3086: (*sfa)->actions_len = start;
3087: return err;
3088: }
3089: }
3090:
3091: return 0;
3092: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 69/2 |
2026/10/01 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 44630
output: 37
thoughts: 3097
Thoughts: **My Thought Process Regarding skb->transport_header and IPv6 Packets**
Okay, so I've been grappling with this specific scenario where `validate_set` is checking `eth_type != htons(ETH_P_IPV6)` for `OVS_KEY_ATTR_IPV6`. This logically implies that `set_ipv6` should *only* be executable if the Ethernet type is indeed `ETH_P_IPV6`.
Now, if the Ethernet type *is* `ETH_P_IPV6`, then `key_extract_l3l4` *must* have called `parse_ipv6hdr`. And I know for a fact that `parse_ipv6hdr` is supposed to set `skb->transport_header`. This is where my confusion arises: how can `skb_transport_header_was_set(skb)` possibly return false in this context?
I decided to re-examine `parse_ipv6hdr` itself.
```c
nexthdr = ipv6_find_hdr(skb, &payload_ofs, -1, &frag_off, &flags);
if (flags & IP6_FH_F_FRAG) {
if (frag_off) {
key->ip.frag = OVS_FRAG_TYPE_LATER;
key->ip.proto = NEXTHDR_FRAGMENT;
return 0;
}
key->ip.frag = OVS_FRAG_TYPE_FIRST;
} else {
key->ip.frag = OVS_FRAG_TYPE_NONE;
}
/* Delayed handling of error in ipv6_find_hdr() as it
* always sets flags and frag_off to a valid value which may be
* used to set key->ip.frag above.
*/
if (unlikely(nexthdr < 0))
return -EPROTO;
nh_len = payload_ofs - nh_ofs;
skb_set_transport_header(skb, nh_ofs + nh_len); // Ah, here it is!
key->ip.proto = nexthdr;
return nh_len;
```
The line `skb_set_transport_header(skb, nh_ofs + nh_len);` is clearly setting the transport header. So, if `parse_ipv6hdr` executes successfully (i.e., `nexthdr >= 0`), the transport header *should* be set.
Then I looked at how `key_extract_l3l4` handles the return values from `parse_ipv6hdr`.
```c
nh_len = parse_ipv6hdr(skb, key);
if (unlikely(nh_len < 0)) {
switch (nh_len) {
case -EINVAL:
memset(&key->ip, 0, sizeof(key->ip));
memset(&key->ipv6.addr, 0, sizeof(key->ipv6.addr));
fallthrough; // Important!
case -EPROTO:
skb->transport_header = skb->network_header; // Aha!
error = 0;
break;
default:
error = nh_len;
}
return error;
}
```
Here's the crucial part: if `parse_ipv6hdr` returns `-EINVAL` or `-EPROTO`, `key_extract_l3l4` explicitly sets `skb->transport_header = skb->network_header`. Since `skb->network_header` is not `~0U` in these scenarios, this *absolutely* means `skb->transport_header` is set. Therefore, `skb_transport_header_was_set(skb)` *should* return true. This still doesn't explain the paradox.
I started to wonder if there were any other paths where `eth_type` could be `ETH_P_IPV6`, but `parse_ipv6hdr` is either not called, or `skb->transport_header` gets reset afterward.
I then considered actions that might modify the packet's L2/L3 headers *before* the key extraction.
First, `OVS_ACTION_ATTR_POP_MPLS`. I looked at `__ovs_nla_copy_actions`:
```c
case OVS_ACTION_ATTR_POP_MPLS: {
__be16 proto;
// ...
proto = nla_get_be16(a);
// ...
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0); // This path makes eth_type not ETH_P_IPV6
else
eth_type = proto; // This path is interesting...
break;
}
```
My initial thought was that if `eth_type` becomes `htons(0)`, then `validate_set` for `OVS_KEY_ATTR_IPV6` would fail. However, if `proto` itself is `ETH_P_IPV6`, then `eth_type` would become `ETH_P_IPV6`. But what about `skb->transport_header` in this case? This action modifies `eth_type` *after* the original `eth_type` has been processed to determine if `parse_ipv6hdr` was called. This seems like a potential point of divergence, but the `validate_set` check happens *before* actions are applied.
I re-read the `__ovs_nla_copy_actions` logic for `POP_MPLS` and realized that in *newer* kernels, `eth_type` is indeed set to `proto`. This means if you POP an MPLS label and the inner protocol is IPv6, `eth_type` *could* become `ETH_P_IPV6`. However, this action happens *after* the initial key extraction. The critical question is what happens to `skb->transport_header` *after* POP_MPLS. I need to look into the `pop_mpls` function itself.
What about `OVS_ACTION_ATTR_POP_VLAN` and `OVS_ACTION_ATTR_POP_ETH`? These actions don't seem to modify `eth_type` in a way that would bypass the `ETH_P_IPV6` check, and they don't directly affect `skb->transport_header` in a way that would cause it to be unset for IPv6.
`OVS_ACTION_ATTR_POP_NSH` also doesn't change `eth_type` in `__ovs_nla_copy_actions`, so the `validate_set` for `OVS_KEY_ATTR_IPV6` would fail.
I then considered the case where the packet is initially IPv6, so `key->eth.type` is `ETH_P_IPV6`, but `parse_ipv6hdr` returns an error like `-EINVAL`. As seen above, this *still* leads to `skb->transport_header` being set to `skb->network_header`.
What if `parse_ipv6hdr` returns an error like `-ENOMEM`? This could happen if `pskb_may_pull` fails within `check_header`. If `parse_ipv6hdr` returns `-ENOMEM`, `key_extract_l3l4` returns that error, and the packet processing would fail before actions are executed, so `skb->transport_header` wouldn't be relevant in the context of actions.
The key point I'm still stuck on is how `skb_transport_header_was_set(skb)` can be false *when* `eth_type` is `ETH_P_IPV6`. The only possibility I'm seeing is if `key_extract_l3l4` is bypassed or if `skb->transport_header` is somehow reset to `~0U` *after* `parse_ipv6hdr` has set it, but *before* `skb_transport_header_was_set` is checked.
The other possibility I'm exploring is within `key_extract` itself. It calls `key_extract_l3l4`. It's always called.
However, my attention is now heavily drawn to MPLS encapsulation. If a packet is MPLS, `key_extract_l3l4` populates the `key->mpls` struct but *crucially does not set `skb->transport_header`*. If *after* this, the packet is then somehow treated as IPv6 (perhaps due to subsequent actions or a faulty assumption in a different part of the code), *and* the `OVS_KEY_ATTR_IPV6` is being validated, this could be the scenario. The `POP_MPLS` action's impact on the *protocol field after popping* and how that interacts with subsequent key extraction and validation is what I need to focus on next.
|
| 70/2 |
2026/10/01 02:06 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:pop_mpls]
Results: map[SourceCode: 146: static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
147: const __be16 ethertype)
148: {
149: int err;
150:
151: err = skb_mpls_pop(skb, ethertype, skb->mac_len,
152: ovs_key_mac_proto(key) == MAC_PROTO_ETHERNET);
153: if (err)
154: return err;
155:
156: if (ethertype == htons(ETH_P_TEB))
157: key->mac_proto = MAC_PROTO_ETHERNET;
158:
159: invalidate_flow_key(key);
160: return 0;
161: }
SourceFile:net/openvswitch/actions.c]
|
| 71/2 |
2026/10/01 02:06 |
llm |
expert |
0m
Model:
Tokens:
input: 48015
output: 38
thoughts: 31
Thoughts: **My Thought Process on `pop_mpls` and Flow Key Invalidation**
Okay, so I'm looking at the `pop_mpls` function, and I've just noticed that it's calling `invalidate_flow_key` with a `key`. This immediately raises a flag for me, given my expertise. My immediate next step, as a natural progression of understanding this code path, is to delve into the `invalidate_flow_key` function itself. I need to understand *precisely* what it does with that `key` passed to it, how it impacts the overall flow state, and what the implications are for subsequent operations that might rely on that flow's integrity or presence in any kind of cache or lookup table. This isn't just a superficial check; it's about tracing the impact of this specific call within the larger system.
|
| 72/2 |
2026/10/01 02:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/actions.c Name:invalidate_flow_key]
Results: map[SourceCode: 110: static void invalidate_flow_key(struct sw_flow_key *key)
111: {
112: key->mac_proto |= SW_FLOW_KEY_INVALID;
113: }
SourceFile:net/openvswitch/actions.c]
|
| 73/2 |
2026/10/01 02:07 |
llm |
expert |
0m
Model:
Tokens:
input: 48157
output: 39
thoughts: 270
Thoughts: **My Thought Process Unraveling a Flow Key Invalidation and Subsequent Action Execution**
Okay, so I'm tracing this flow where `invalidate_flow_key` is called. My initial thought is: what's the immediate consequence of that? The text clarifies that it sets `SW_FLOW_KEY_INVALID`. This is a crucial flag, obviously.
Then, I'm immediately wondering about the *next* logical step in the execution path. What happens when an action follows this invalidation? Specifically, I'm zeroing in on `OVS_ACTION_ATTR_SET`. This seems like a potential candidate for reacting to or being influenced by the invalidated key.
My train of thought then goes to how these actions are processed. I recall that `OVS_ACTION_ATTR_SET` ultimately leads to either `execute_set_action` or `execute_masked_set_action`. This is good, I'm getting closer to the actual logic.
However, a critical realization dawns on me: the validation of actions isn't *just* a runtime concern. I remember that `__ovs_nla_copy_actions` performs validation *at configuration time*. This is a significant point. What does this configuration-time validation entail?
The text indicates that during this configuration-time validation, `__ovs_nla_copy_actions` is tracking the `eth_type`. This is key information. Let's say, for instance, the action is `POP_MPLS`, and the `ethertype` is specified as `ETH_P_IPV6`. In this scenario, the `eth_type` variable is set to `ETH_P_IPV6`.
Now, this sets up a very specific condition for subsequent actions. If the `eth_type` is now `ETH_P_IPV6`, the next action could potentially be `SET_IPV6`. Why? Because the validation logic for `SET_IPV6`, specifically within `validate_set`, checks if `eth_type == htons(ETH_P_IPV6)`. And, as we've established, this condition *will be true* in this specific sequence of events. This is a potential path I need to be aware of.
But here's where the critical distinction arises, and where my focus shifts: the behavior at runtime might differ significantly from the configuration-time validation. I'm realizing that while `POP_MPLS` *might* have been validated based on `eth_type` at configuration, its *runtime* effect might not be what I initially assumed. Specifically, I'm noting that at runtime, `pop_mpls` does *not* set `skb->transport_header`.
This leads me to a direct question: does the underlying function called by `pop_mpls`, which is `skb_mpls_pop`, actually set `skb->transport_header`? I need to dig into the implementation of `skb_mpls_pop` to confirm this crucial detail. This is the next step in understanding the actual data plane behavior and potential vulnerabilities or unexpected outcomes.
|
| 74/2 |
2026/10/01 02:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/core/skbuff.c Name:skb_mpls_pop]
Results: map[SourceCode:6655: /**
6656: * skb_mpls_pop() - pop the outermost MPLS header
6657: *
6658: * @skb: buffer
6659: * @next_proto: ethertype of header after popped MPLS header
6660: * @mac_len: length of the MAC header
6661: * @ethernet: flag to indicate if the packet is ethernet
6662: *
6663: * Expects skb->data at mac header.
6664: *
6665: * Returns 0 on success, -errno otherwise.
6666: */
6667: int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
6668: bool ethernet)
6669: {
6670: int err;
6671:
6672: if (unlikely(!eth_p_mpls(skb->protocol)))
6673: return 0;
6674:
6675: err = skb_ensure_writable(skb, mac_len + MPLS_HLEN);
6676: if (unlikely(err))
6677: return err;
6678:
6679: skb_postpull_rcsum(skb, mpls_hdr(skb), MPLS_HLEN);
6680: memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
6681: mac_len);
6682:
6683: __skb_pull(skb, MPLS_HLEN);
6684: skb_reset_mac_header(skb);
6685: skb_set_network_header(skb, mac_len);
6686:
6687: if (ethernet && mac_len >= ETH_HLEN) {
6688: struct ethhdr *hdr;
6689:
6690: /* use mpls_hdr() to get ethertype to account for VLANs. */
6691: hdr = (struct ethhdr *)((void *)mpls_hdr(skb) - ETH_HLEN);
6692: skb_mod_eth_type(skb, hdr, next_proto);
6693: }
6694: skb->protocol = next_proto;
6695:
6696: /* The last label is gone, so the inner header recorded by
6697: * skb_mpls_push() no longer describes this packet. Drop it, or a
6698: * later push keeps the stale offset.
6699: */
6700: if (!eth_p_mpls(next_proto))
6701: skb->inner_protocol = 0;
6702:
6703: return 0;
6704: }
SourceFile:net/core/skbuff.c]
|
| 75/2 |
2026/10/01 02:07 |
llm |
expert |
0m
Model:
Tokens:
input: 49269
output: 41
thoughts: 442
Thoughts: **A Critical Flaw in Header Handling: My Realization**
I've just uncovered what appears to be a significant bug in how Open vSwitch handles certain packet manipulations, specifically involving MPLS and IPv6. My thought process went something like this:
I was analyzing the `skb_mpls_pop` function, and a crucial observation struck me: it *doesn't* set `skb->transport_header`. This immediately raised a red flag for me. I thought, "Okay, so if I have an MPLS packet and I pop the MPLS header, and the *next* protocol encapsulated within is IPv6, then `skb->transport_header` will still be at its default invalid value of `~0U`."
My mind immediately jumped to the potential consequences of this. What happens if the subsequent action in the flow rule is to *set* IPv6? I recalled that `execute_masked_set_action` is responsible for handling `SET_IPV6` actions.
Digging deeper into the `do_execute_actions` function, I found this logic:
```c
case OVS_ACTION_ATTR_SET_MASKED:
case OVS_ACTION_ATTR_SET_TO_MASKED:
err = execute_masked_set_action(skb, key, nla_data(a));
break;
```
This confirms that `execute_masked_set_action` is indeed called for `SET_MASKED` and `SET_TO_MASKED` operations, which would include setting IPv6. However, I noticed something even more concerning. The `do_execute_actions` function *doesn't* call `ovs_flow_key_update(skb, key)` when `OVS_ACTION_ATTR_SET_MASKED` is encountered.
This is in stark contrast to how it handles `OVS_ACTION_ATTR_CT` (connection tracking), where it explicitly checks if the `key` is valid and calls `ovs_flow_key_update` if it's not:
```c
case OVS_ACTION_ATTR_CT:
if (!is_flow_key_valid(key)) {
err = ovs_flow_key_update(skb, key);
if (err)
break;
}
```
So, the situation is: `key` is invalid (because `skb->transport_header` wasn't updated after the MPLS pop), but `execute_masked_set_action` is still called. And `execute_masked_set_action` then invokes `set_ipv6(skb, flow_key, nla_data(a), get_mask(a, struct ovs_key_ipv6 *))`. The critical piece is that `set_ipv6` relies on `skb_transport_offset(skb)`, which, in turn, uses `skb->transport_header`. Since `skb->transport_header` is still `~0U` from the previous MPLS pop, `skb_transport_offset(skb)` will be incorrect. This leads `set_ipv6` to operate on an incorrect offset, and the IPv6 header is effectively not being set correctly, or worse, being written over existing data at an unintended location.
This chain of events perfectly explains the observed bug!
My immediate next step is to verify this hypothesis by confirming whether `ovs_flow_key_update` is indeed the function responsible for setting `skb->transport_header` in scenarios like this. If it is, then its absence in the `SET_MASKED` path is the root cause.
|
| 76/2 |
2026/10/01 02:07 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow.c Name:ovs_flow_key_update]
Results: map[SourceCode: 975: int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key)
976: {
977: int res;
978:
979: res = key_extract(skb, key);
980: if (!res)
981: key->mac_proto &= ~SW_FLOW_KEY_INVALID;
982:
983: return res;
984: }
SourceFile:net/openvswitch/flow.c]
|
| 77/2 |
2026/10/01 02:07 |
llm |
expert |
1m
Model:
Tokens:
input: 49899
output: 175
thoughts: 3124
|
| 78/2 |
2026/10/01 02:09 |
tool |
codeexpert |
2m
Args: map[Question:In `__ovs_nla_copy_actions` (net/openvswitch/flow_netlink.c), for `OVS_ACTION_ATTR_POP_MPLS`, if `!eth_p_mpls(proto) || !mpls_label_count`, `eth_type` is set to `htons(0)`. Later, if there is an `OVS_ACTION_ATTR_SET` with `OVS_KEY_ATTR_IPV6`, `validate_set` checks `if (eth_type != htons(ETH_P_IPV6)) return -EINVAL;`. Does this mean that a `POP_MPLS` action followed by a `SET_IPV6` action will be rejected during validation?]
Results: map[Answer:Yes, a `POP_MPLS` action followed directly by a `SET_IPV6` action (or any other L3/L4 `SET` action) in the same action list will be rejected with `-EINVAL` during validation in `__ovs_nla_copy_actions`.
### Why this happens:
1. **Resetting `eth_type`:** In `__ovs_nla_copy_actions()` (`net/openvswitch/flow_netlink.c`), when processing `OVS_ACTION_ATTR_POP_MPLS`:
```c
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
```
If the inner protocol `proto` is IPv6 (`ETH_P_IPV6`), `!eth_p_mpls(proto)` evaluates to true (and/or `mpls_label_count` reaches 0), so `eth_type` is set to `htons(0)`. (Even if more MPLS labels remained, `eth_type` would be set to an MPLS ethertype, never `ETH_P_IPV6`).
2. **Validation failure:** When the subsequent `OVS_ACTION_ATTR_SET` (or `OVS_ACTION_ATTR_SET_MASKED`) with `OVS_KEY_ATTR_IPV6` is processed, `validate_set()` is invoked with `eth_type`:
```c
case OVS_KEY_ATTR_IPV6: {
...
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
Because `eth_type` is `htons(0)`, the check `eth_type != htons(ETH_P_IPV6)` is true, causing `validate_set()` to return `-EINVAL`, which fails action validation.
### Rationale and Intended Workflow:
This rejection is intentional. As the inline comment in `__ovs_nla_copy_actions()` notes:
> *"Disallow subsequent L2.5+ set actions and mpls_pop actions once the last MPLS label in the packet is popped as there is no check here to ensure that the new eth type is valid and thus set actions could write off the end of the packet or otherwise corrupt it. Support for these actions is planned using packet recirculation."*
Because the kernel datapath only extracted and verified the MPLS label stack during initial packet classification, modifying L3/L4 fields without re-parsing could access invalid packet offsets or corrupt memory. To modify IPv6 fields after popping MPLS, the action list must use recirculation (`OVS_ACTION_ATTR_RECIRC`) after `POP_MPLS`, allowing the kernel datapath to re-parse the inner IPv6 packet before applying the `SET_IPV6` action in the next flow.]
|
| 79/3 |
2026/10/01 02:09 |
agent |
codeexpert |
2m
Model:
Results: map[Answer:Yes, a `POP_MPLS` action followed directly by a `SET_IPV6` action (or any other L3/L4 `SET` action) in the same action list will be rejected with `-EINVAL` during validation in `__ovs_nla_copy_actions`.
### Why this happens:
1. **Resetting `eth_type`:** In `__ovs_nla_copy_actions()` (`net/openvswitch/flow_netlink.c`), when processing `OVS_ACTION_ATTR_POP_MPLS`:
```c
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
```
If the inner protocol `proto` is IPv6 (`ETH_P_IPV6`), `!eth_p_mpls(proto)` evaluates to true (and/or `mpls_label_count` reaches 0), so `eth_type` is set to `htons(0)`. (Even if more MPLS labels remained, `eth_type` would be set to an MPLS ethertype, never `ETH_P_IPV6`).
2. **Validation failure:** When the subsequent `OVS_ACTION_ATTR_SET` (or `OVS_ACTION_ATTR_SET_MASKED`) with `OVS_KEY_ATTR_IPV6` is processed, `validate_set()` is invoked with `eth_type`:
```c
case OVS_KEY_ATTR_IPV6: {
...
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
Because `eth_type` is `htons(0)`, the check `eth_type != htons(ETH_P_IPV6)` is true, causing `validate_set()` to return `-EINVAL`, which fails action validation.
### Rationale and Intended Workflow:
This rejection is intentional. As the inline comment in `__ovs_nla_copy_actions()` notes:
> *"Disallow subsequent L2.5+ set actions and mpls_pop actions once the last MPLS label in the packet is popped as there is no check here to ensure that the new eth type is valid and thus set actions could write off the end of the packet or otherwise corrupt it. Support for these actions is planned using packet recirculation."*
Because the kernel datapath only extracted and verified the MPLS label stack during initial packet classification, modifying L3/L4 fields without re-parsing could access invalid packet offsets or corrupt memory. To modify IPv6 fields after popping MPLS, the action list must use recirculation (`OVS_ACTION_ATTR_RECIRC`) after `POP_MPLS`, allowing the kernel datapath to re-parse the inner IPv6 packet before applying the `SET_IPV6` action in the next flow.]
Instruction:
You are a capable Linux kernel developer tasked with researching complex questions
about kernel source code. You will be given a concrete question, and need to provide
a concrete answer.
Research the question using targeted, efficient tool calls. Don't make assumptions,
or rely on your previous knowledge about the kernel source code, use available tools
to access the actual source code. Keep your tool calls focused and limited to the
scope of the question. Do not explore tangential code paths or perform unbounded searches.
Use all available sources of information:
- kernel source code
- documentation in the Documentation dir in the source tree
- git commits descriptions, git blame
Do not guess file names or file paths and attempt to read them without
verifying their existence first using content search or directory listing tools.
If a file, symbol, or directory is not found via content search (grepper) or
directory listing (codesearch-dir-index), treat it as completely absent.
Do not attempt to guess alternative names, extensions, or directories.
Tool Selection Guidelines:
1. For C functions, structs, and variables: Prefer codesearch-definition-source
or codesearch-struct-layout FIRST to retrieve clean, exact definitions
without line-number guessing.
2. If symbol lookup fails (e.g., preprocessor macros, macro-generated code, or
disabled #ifdef branches), fall back to read-file or grepper.
3. For file headers, #include directives, preprocessor macro definitions, and
non-C files (Kconfig, Makefiles, docs): Use read-file or grepper directly.
4. Be concise and targeted. Answer the question as directly and concisely as possible
once you have located the relevant code or definitions. If a symbol or function cannot
be found after targeted searches, conclude with the best available information rather
than continuing repetitive searches.
Do NOT use git-log to search for the presence or existence of files in the
repository. git-log is only for tracing commit history of files that are
already present in the current checkout. If a file does not exist in the
current checkout, it cannot be used for reproduction.
Avoid running broad git-log queries (such as searches on the entire repo)
without a specific 'PathPrefix' to restrict the scope, as these are very
expensive and will time out.
If a git-log tool call times out, do not retry the query with the same broad
scope. You must specify a tighter, narrower 'PathPrefix' for subsequent queries.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: In `__ovs_nla_copy_actions` (net/openvswitch/flow_netlink.c), for `OVS_ACTION_ATTR_POP_MPLS`, if `!eth_p_mpls(proto) || !mpls_label_count`, `eth_type` is set to `htons(0)`. Later, if there is an `OVS_ACTION_ATTR_SET` with `OVS_KEY_ATTR_IPV6`, `validate_set` checks `if (eth_type != htons(ETH_P_IPV6)) return -EINVAL;`. Does this mean that a `POP_MPLS` action followed by a `SET_IPV6` action will be rejected during validation?
|
| 80/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 3370
output: 46
thoughts: 231
Thoughts: **My Thought Process Regarding the `POP_MPLS` and `SET_IPV6` Interaction in Open vSwitch**
I'm grappling with a specific interaction within Open vSwitch's netlink handling, particularly concerning the `OVS_ACTION_ATTR_POP_MPLS` and `OVS_ACTION_ATTR_SET` actions when setting `OVS_KEY_ATTR_IPV6`. The core of my concern lies in how the `eth_type` is manipulated and subsequently validated.
My initial line of inquiry is triggered by the provided snippet from `__ovs_nla_copy_actions`. I notice that for `OVS_ACTION_ATTR_POP_MPLS`, if certain conditions related to MPLS proto and label count aren't met, the `eth_type` is explicitly set to `htons(0)`. This immediately raises a flag in my mind. Why would we be zeroing out the Ethernet type in this scenario? It seems counterintuitive, especially when we expect to be dealing with specific Ethernet types later in the packet processing pipeline.
Then, the question introduces the `validate_set` function. I see that within `validate_set`, when an `OVS_ACTION_ATTR_SET` action targets `OVS_KEY_ATTR_IPV6`, there's a check: `if (eth_type != htons(ETH_P_IPV6)) return -EINVAL;`. This is where the conflict becomes apparent to me. If, as a result of a preceding `POP_MPLS` action, `eth_type` has been set to `htons(0)`, this validation check will inevitably fail.
Therefore, my initial hypothesis is that a `POP_MPLS` action, under the specific conditions described (where `eth_type` is zeroed out), followed by a `SET_IPV6` action will indeed be rejected during validation. The zeroed `eth_type` from the `POP_MPLS` action will not match the expected `ETH_P_IPV6` in `validate_set`.
To solidify this understanding, my next logical step is to dive into the source code. I need to examine the precise implementation of `__ovs_nla_copy_actions` and `validate_set` within `net/openvswitch/flow_netlink.c`. I'll be using tools like `codesearch-definition-source` to locate these functions, ensuring I'm looking at the correct versions and can trace the flow of execution and variable assignments precisely. I'm particularly interested in understanding *why* `eth_type` is set to `htons(0)` in the `POP_MPLS` case and how the validation in `validate_set` is designed to interact with potentially altered Ethernet types from preceding actions. This detailed code inspection will be crucial for confirming or refuting my initial assessment.
|
| 81/4 |
2026/10/01 02:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:__ovs_nla_copy_actions]
Results: map[SourceCode:3260: static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
3261: const struct sw_flow_key *key,
3262: struct sw_flow_actions **sfa,
3263: __be16 eth_type, __be16 vlan_tci,
3264: u32 mpls_label_count, bool log,
3265: u32 depth)
3266: {
3267: u8 mac_proto = ovs_key_mac_proto(key);
3268: const struct nlattr *a;
3269: int rem, err;
3270:
3271: if (depth > OVS_COPY_ACTIONS_MAX_DEPTH)
3272: return -EOVERFLOW;
3273:
3274: nla_for_each_nested(a, attr, rem) {
3275: /* Expected argument lengths, (u32)-1 for variable length. */
3276: static const u32 action_lens[OVS_ACTION_ATTR_MAX + 1] = {
3277: [OVS_ACTION_ATTR_OUTPUT] = sizeof(u32),
3278: [OVS_ACTION_ATTR_RECIRC] = sizeof(u32),
3279: [OVS_ACTION_ATTR_USERSPACE] = (u32)-1,
3280: [OVS_ACTION_ATTR_PUSH_MPLS] = sizeof(struct ovs_action_push_mpls),
3281: [OVS_ACTION_ATTR_POP_MPLS] = sizeof(__be16),
3282: [OVS_ACTION_ATTR_PUSH_VLAN] = sizeof(struct ovs_action_push_vlan),
3283: [OVS_ACTION_ATTR_POP_VLAN] = 0,
3284: [OVS_ACTION_ATTR_SET] = (u32)-1,
3285: [OVS_ACTION_ATTR_SET_MASKED] = (u32)-1,
3286: [OVS_ACTION_ATTR_SAMPLE] = (u32)-1,
3287: [OVS_ACTION_ATTR_HASH] = sizeof(struct ovs_action_hash),
3288: [OVS_ACTION_ATTR_CT] = (u32)-1,
3289: [OVS_ACTION_ATTR_CT_CLEAR] = 0,
3290: [OVS_ACTION_ATTR_TRUNC] = sizeof(struct ovs_action_trunc),
3291: [OVS_ACTION_ATTR_PUSH_ETH] = sizeof(struct ovs_action_push_eth),
3292: [OVS_ACTION_ATTR_POP_ETH] = 0,
3293: [OVS_ACTION_ATTR_PUSH_NSH] = (u32)-1,
3294: [OVS_ACTION_ATTR_POP_NSH] = 0,
3295: [OVS_ACTION_ATTR_METER] = sizeof(u32),
3296: [OVS_ACTION_ATTR_CLONE] = (u32)-1,
3297: [OVS_ACTION_ATTR_CHECK_PKT_LEN] = (u32)-1,
3298: [OVS_ACTION_ATTR_ADD_MPLS] = sizeof(struct ovs_action_add_mpls),
3299: [OVS_ACTION_ATTR_DEC_TTL] = (u32)-1,
3300: [OVS_ACTION_ATTR_DROP] = sizeof(u32),
3301: [OVS_ACTION_ATTR_PSAMPLE] = (u32)-1,
3302: };
3303: const struct ovs_action_push_vlan *vlan;
3304: int type = nla_type(a);
3305: bool skip_copy;
3306:
3307: if (type > OVS_ACTION_ATTR_MAX ||
3308: (action_lens[type] != nla_len(a) &&
3309: action_lens[type] != (u32)-1))
3310: return -EINVAL;
3311:
3312: skip_copy = false;
3313: switch (type) {
3314: case OVS_ACTION_ATTR_UNSPEC:
3315: return -EINVAL;
3316:
3317: case OVS_ACTION_ATTR_USERSPACE:
3318: err = validate_userspace(a);
3319: if (err)
3320: return err;
3321: break;
3322:
3323: case OVS_ACTION_ATTR_OUTPUT:
3324: if (nla_get_u32(a) >= DP_MAX_PORTS)
3325: return -EINVAL;
3326: break;
3327:
3328: case OVS_ACTION_ATTR_TRUNC: {
3329: const struct ovs_action_trunc *trunc = nla_data(a);
3330:
3331: if (trunc->max_len < ETH_HLEN)
3332: return -EINVAL;
3333: break;
3334: }
3335:
3336: case OVS_ACTION_ATTR_HASH: {
3337: const struct ovs_action_hash *act_hash = nla_data(a);
3338:
3339: switch (act_hash->hash_alg) {
3340: case OVS_HASH_ALG_L4:
3341: fallthrough;
3342: case OVS_HASH_ALG_SYM_L4:
3343: break;
3344: default:
3345: return -EINVAL;
3346: }
3347:
3348: break;
3349: }
3350:
3351: case OVS_ACTION_ATTR_POP_VLAN:
3352: if (mac_proto != MAC_PROTO_ETHERNET)
3353: return -EINVAL;
3354: vlan_tci = htons(0);
3355: break;
3356:
3357: case OVS_ACTION_ATTR_PUSH_VLAN:
3358: if (mac_proto != MAC_PROTO_ETHERNET)
3359: return -EINVAL;
3360: vlan = nla_data(a);
3361: if (!eth_type_vlan(vlan->vlan_tpid))
3362: return -EINVAL;
3363: if (!(vlan->vlan_tci & htons(VLAN_CFI_MASK)))
3364: return -EINVAL;
3365: vlan_tci = vlan->vlan_tci;
3366: break;
3367:
3368: case OVS_ACTION_ATTR_RECIRC:
3369: break;
3370:
3371: case OVS_ACTION_ATTR_ADD_MPLS: {
3372: const struct ovs_action_add_mpls *mpls = nla_data(a);
3373:
3374: if (!eth_p_mpls(mpls->mpls_ethertype))
3375: return -EINVAL;
3376:
3377: if (mpls->tun_flags & OVS_MPLS_L3_TUNNEL_FLAG_MASK) {
3378: if (vlan_tci & htons(VLAN_CFI_MASK) ||
3379: (eth_type != htons(ETH_P_IP) &&
3380: eth_type != htons(ETH_P_IPV6) &&
3381: eth_type != htons(ETH_P_ARP) &&
3382: eth_type != htons(ETH_P_RARP) &&
3383: !eth_p_mpls(eth_type)))
3384: return -EINVAL;
3385: mpls_label_count++;
3386: } else {
3387: if (mac_proto == MAC_PROTO_ETHERNET) {
3388: mpls_label_count = 1;
3389: mac_proto = MAC_PROTO_NONE;
3390: } else {
3391: mpls_label_count++;
3392: }
3393: }
3394: eth_type = mpls->mpls_ethertype;
3395: break;
3396: }
3397:
3398: case OVS_ACTION_ATTR_PUSH_MPLS: {
3399: const struct ovs_action_push_mpls *mpls = nla_data(a);
3400:
3401: if (!eth_p_mpls(mpls->mpls_ethertype))
3402: return -EINVAL;
3403: /* Prohibit push MPLS other than to a white list
3404: * for packets that have a known tag order.
3405: */
3406: if (vlan_tci & htons(VLAN_CFI_MASK) ||
3407: (eth_type != htons(ETH_P_IP) &&
3408: eth_type != htons(ETH_P_IPV6) &&
3409: eth_type != htons(ETH_P_ARP) &&
3410: eth_type != htons(ETH_P_RARP) &&
3411: !eth_p_mpls(eth_type)))
3412: return -EINVAL;
3413: eth_type = mpls->mpls_ethertype;
3414: mpls_label_count++;
3415: break;
3416: }
3417:
3418: case OVS_ACTION_ATTR_POP_MPLS: {
3419: __be16 proto;
3420: if (vlan_tci & htons(VLAN_CFI_MASK) ||
3421: !eth_p_mpls(eth_type))
3422: return -EINVAL;
3423:
3424: /* Disallow subsequent L2.5+ set actions and mpls_pop
3425: * actions once the last MPLS label in the packet is
3426: * popped as there is no check here to ensure that
3427: * the new eth type is valid and thus set actions could
3428: * write off the end of the packet or otherwise corrupt
3429: * it.
3430: *
3431: * Support for these actions is planned using packet
3432: * recirculation.
3433: */
3434: proto = nla_get_be16(a);
3435:
3436: if (proto == htons(ETH_P_TEB) &&
3437: mac_proto != MAC_PROTO_NONE)
3438: return -EINVAL;
3439:
3440: mpls_label_count--;
3441:
3442: if (!eth_p_mpls(proto) || !mpls_label_count)
3443: eth_type = htons(0);
3444: else
3445: eth_type = proto;
3446:
3447: break;
3448: }
3449:
3450: case OVS_ACTION_ATTR_SET:
3451: err = validate_set(a, key, sfa,
3452: &skip_copy, mac_proto, eth_type,
3453: false, log);
3454: if (err)
3455: return err;
3456: break;
3457:
3458: case OVS_ACTION_ATTR_SET_MASKED:
3459: err = validate_set(a, key, sfa,
3460: &skip_copy, mac_proto, eth_type,
3461: true, log);
3462: if (err)
3463: return err;
3464: break;
3465:
3466: case OVS_ACTION_ATTR_SAMPLE: {
3467: bool last = nla_is_last(a, rem);
3468:
3469: err = validate_and_copy_sample(net, a, key, sfa,
3470: eth_type, vlan_tci,
3471: mpls_label_count,
3472: log, last, depth);
3473: if (err)
3474: return err;
3475: skip_copy = true;
3476: break;
3477: }
3478:
3479: case OVS_ACTION_ATTR_CT:
3480: err = ovs_ct_copy_action(net, a, key, sfa, log);
3481: if (err)
3482: return err;
3483: skip_copy = true;
3484: break;
3485:
3486: case OVS_ACTION_ATTR_CT_CLEAR:
3487: break;
3488:
3489: case OVS_ACTION_ATTR_PUSH_ETH:
3490: /* Disallow pushing an Ethernet header if one
3491: * is already present */
3492: if (mac_proto != MAC_PROTO_NONE)
3493: return -EINVAL;
3494: mac_proto = MAC_PROTO_ETHERNET;
3495: break;
3496:
3497: case OVS_ACTION_ATTR_POP_ETH:
3498: if (mac_proto != MAC_PROTO_ETHERNET)
3499: return -EINVAL;
3500: if (vlan_tci & htons(VLAN_CFI_MASK))
3501: return -EINVAL;
3502: mac_proto = MAC_PROTO_NONE;
3503: break;
3504:
3505: case OVS_ACTION_ATTR_PUSH_NSH:
3506: if (mac_proto != MAC_PROTO_ETHERNET) {
3507: u8 next_proto;
3508:
3509: next_proto = tun_p_from_eth_p(eth_type);
3510: if (!next_proto)
3511: return -EINVAL;
3512: }
3513: mac_proto = MAC_PROTO_NONE;
3514: if (!validate_push_nsh(a, log))
3515: return -EINVAL;
3516: break;
3517:
3518: case OVS_ACTION_ATTR_POP_NSH: {
3519: __be16 inner_proto;
3520:
3521: if (eth_type != htons(ETH_P_NSH))
3522: return -EINVAL;
3523: inner_proto = tun_p_to_eth_p(key->nsh.base.np);
3524: if (!inner_proto)
3525: return -EINVAL;
3526: if (key->nsh.base.np == TUN_P_ETHERNET)
3527: mac_proto = MAC_PROTO_ETHERNET;
3528: else
3529: mac_proto = MAC_PROTO_NONE;
3530: break;
3531: }
3532:
3533: case OVS_ACTION_ATTR_METER:
3534: /* Non-existent meters are simply ignored. */
3535: break;
3536:
3537: case OVS_ACTION_ATTR_CLONE: {
3538: bool last = nla_is_last(a, rem);
3539:
3540: err = validate_and_copy_clone(net, a, key, sfa,
3541: eth_type, vlan_tci,
3542: mpls_label_count,
3543: log, last, depth);
3544: if (err)
3545: return err;
3546: skip_copy = true;
3547: break;
3548: }
3549:
3550: case OVS_ACTION_ATTR_CHECK_PKT_LEN: {
3551: bool last = nla_is_last(a, rem);
3552:
3553: err = validate_and_copy_check_pkt_len(net, a, key, sfa,
3554: eth_type,
3555: vlan_tci,
3556: mpls_label_count,
3557: log, last,
3558: depth);
3559: if (err)
3560: return err;
3561: skip_copy = true;
3562: break;
3563: }
3564:
3565: case OVS_ACTION_ATTR_DEC_TTL:
3566: err = validate_and_copy_dec_ttl(net, a, key, sfa,
3567: eth_type, vlan_tci,
3568: mpls_label_count, log,
3569: depth);
3570: if (err)
3571: return err;
3572: skip_copy = true;
3573: break;
3574:
3575: case OVS_ACTION_ATTR_DROP:
3576: if (!nla_is_last(a, rem))
3577: return -EINVAL;
3578: break;
3579:
3580: case OVS_ACTION_ATTR_PSAMPLE:
3581: err = validate_psample(a);
3582: if (err)
3583: return err;
3584: break;
3585:
3586: default:
3587: OVS_NLERR(log, "Unknown Action type %d", type);
3588: return -EINVAL;
3589: }
3590: if (!skip_copy) {
3591: err = copy_action(a, sfa, log);
3592: if (err)
3593: return err;
3594: }
3595: }
3596:
3597: if (rem > 0)
3598: return -EINVAL;
3599:
3600: return 0;
3601: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 82/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 8892
output: 39
thoughts: 25
Thoughts: **My Thought Process Regarding `validate_set` in `net/openvswitch/flow_netlink.c`**
Alright, so I've been digging into the `net/openvswitch/flow_netlink.c` file, specifically looking at this `validate_set` function. My immediate goal is to get a really solid grasp on what it's doing, why it's there, and how it interacts with the broader Open vSwitch (OVS) netlink interface. Given my expertise, I'm not just looking for a surface-level description; I need to understand the nuances, the potential edge cases, and the underlying rationale for its design.
First off, I need to understand its primary purpose. What is `validate_set` *validating*? And what is it *setting*? The name suggests it's a check before something is applied or configured. I'll be dissecting the function's parameters and return values to understand the data it operates on and what constitutes a successful or failed validation. I anticipate it's likely involved in ensuring the integrity and legality of flow modifications or additions being communicated via netlink. This means I'm going to be scrutinizing the types of attributes it's expecting and the constraints it's enforcing on those attributes.
My next step is to trace the control flow within `validate_set`. I'll be looking for conditional branches, loops, and error handling mechanisms. What are the specific conditions under which validation might fail? Are there different validation rules depending on the type of netlink message or the specific fields being modified? I'll be paying close attention to any calls to other functions or any direct manipulation of OVS data structures. This will help me map out the dependencies and understand how this function fits into the larger picture of OVS flow management.
Crucially, I need to consider the context of netlink. Netlink is the kernel-userspace communication mechanism for OVS, and it's notoriously flexible and powerful, which also means it can be a source of errors if not handled carefully. Therefore, I'm assuming `validate_set` is a critical gatekeeper, designed to prevent malformed or malicious netlink requests from corrupting the OVS datapath or causing unpredictable behavior. This implies I should be looking for checks related to:
* **Attribute validity:** Are the attribute types and lengths correct?
* **Value ranges:** Are the values within acceptable bounds (e.g., port numbers, masks)?
* **Dependencies:** Are there dependencies between attributes that need to be satisfied? For example, does setting a certain flag require a specific tunnel type to be configured?
* **Security considerations:** Are there any checks to prevent denial-of-service or privilege escalation?
I'll also be keeping an eye out for any comments or documentation within the code itself. While sometimes sparse, these can offer invaluable insights into the developer's intent and the specific problems being solved. If the code is particularly complex, I might need to look at related functions that call `validate_set` or are called by it to get a more complete picture. Understanding *who* calls `validate_set` and *when* is just as important as understanding what it does internally.
Finally, I'll be thinking about potential performance implications. While validation is essential, overly complex or inefficient validation logic could impact the responsiveness of the OVS netlink interface, especially under heavy load. I'll be assessing whether the validation steps appear to be reasonably efficient or if there might be opportunities for optimization, though my primary focus at this stage is correctness and understanding. This thorough analysis will allow me to form a comprehensive mental model of `validate_set`'s role and behavior.
|
| 83/4 |
2026/10/01 02:09 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:validate_set]
Results: map[SourceCode:2919: static int validate_set(const struct nlattr *a,
2920: const struct sw_flow_key *flow_key,
2921: struct sw_flow_actions **sfa, bool *skip_copy,
2922: u8 mac_proto, __be16 eth_type, bool masked, bool log)
2923: {
2924: const struct nlattr *ovs_key = nla_data(a);
2925: int key_type = nla_type(ovs_key);
2926: size_t key_len;
2927:
2928: /* There can be only one key in a action */
2929: if (!nla_ok(ovs_key, nla_len(a)) ||
2930: nla_total_size(nla_len(ovs_key)) != nla_len(a))
2931: return -EINVAL;
2932:
2933: key_len = nla_len(ovs_key);
2934: if (masked)
2935: key_len /= 2;
2936:
2937: if (key_type > OVS_KEY_ATTR_MAX ||
2938: !check_attr_len(key_len, ovs_key_lens[key_type].len))
2939: return -EINVAL;
2940:
2941: if (masked && !validate_masked(nla_data(ovs_key), key_len))
2942: return -EINVAL;
2943:
2944: switch (key_type) {
2945: case OVS_KEY_ATTR_PRIORITY:
2946: case OVS_KEY_ATTR_SKB_MARK:
2947: case OVS_KEY_ATTR_CT_MARK:
2948: case OVS_KEY_ATTR_CT_LABELS:
2949: break;
2950:
2951: case OVS_KEY_ATTR_ETHERNET:
2952: if (mac_proto != MAC_PROTO_ETHERNET)
2953: return -EINVAL;
2954: break;
2955:
2956: case OVS_KEY_ATTR_TUNNEL: {
2957: int err;
2958:
2959: if (masked)
2960: return -EINVAL; /* Masked tunnel set not supported. */
2961:
2962: *skip_copy = true;
2963: err = validate_and_copy_set_tun(a, sfa, log);
2964: if (err)
2965: return err;
2966: break;
2967: }
2968: case OVS_KEY_ATTR_IPV4: {
2969: const struct ovs_key_ipv4 *ipv4_key;
2970:
2971: if (eth_type != htons(ETH_P_IP))
2972: return -EINVAL;
2973:
2974: ipv4_key = nla_data(ovs_key);
2975:
2976: if (masked) {
2977: const struct ovs_key_ipv4 *mask = ipv4_key + 1;
2978:
2979: /* Non-writeable fields. */
2980: if (mask->ipv4_proto || mask->ipv4_frag)
2981: return -EINVAL;
2982: } else {
2983: if (ipv4_key->ipv4_proto != flow_key->ip.proto)
2984: return -EINVAL;
2985:
2986: if (ipv4_key->ipv4_frag != flow_key->ip.frag)
2987: return -EINVAL;
2988: }
2989: break;
2990: }
2991: case OVS_KEY_ATTR_IPV6: {
2992: const struct ovs_key_ipv6 *ipv6_key;
2993:
2994: if (eth_type != htons(ETH_P_IPV6))
2995: return -EINVAL;
2996:
2997: ipv6_key = nla_data(ovs_key);
2998:
2999: if (masked) {
3000: const struct ovs_key_ipv6 *mask = ipv6_key + 1;
3001:
3002: /* Non-writeable fields. */
3003: if (mask->ipv6_proto || mask->ipv6_frag)
3004: return -EINVAL;
3005:
3006: /* Invalid bits in the flow label mask? */
3007: if (ntohl(mask->ipv6_label) & 0xFFF00000)
3008: return -EINVAL;
3009: } else {
3010: if (ipv6_key->ipv6_proto != flow_key->ip.proto)
3011: return -EINVAL;
3012:
3013: if (ipv6_key->ipv6_frag != flow_key->ip.frag)
3014: return -EINVAL;
3015: }
3016: if (ntohl(ipv6_key->ipv6_label) & 0xFFF00000)
3017: return -EINVAL;
3018:
3019: break;
3020: }
3021: case OVS_KEY_ATTR_TCP:
3022: if ((eth_type != htons(ETH_P_IP) &&
3023: eth_type != htons(ETH_P_IPV6)) ||
3024: flow_key->ip.proto != IPPROTO_TCP)
3025: return -EINVAL;
3026:
3027: break;
3028:
3029: case OVS_KEY_ATTR_UDP:
3030: if ((eth_type != htons(ETH_P_IP) &&
3031: eth_type != htons(ETH_P_IPV6)) ||
3032: flow_key->ip.proto != IPPROTO_UDP)
3033: return -EINVAL;
3034:
3035: break;
3036:
3037: case OVS_KEY_ATTR_MPLS:
3038: if (!eth_p_mpls(eth_type))
3039: return -EINVAL;
3040: if (key_len != sizeof(struct ovs_key_mpls))
3041: return -EINVAL;
3042: break;
3043:
3044: case OVS_KEY_ATTR_SCTP:
3045: if ((eth_type != htons(ETH_P_IP) &&
3046: eth_type != htons(ETH_P_IPV6)) ||
3047: flow_key->ip.proto != IPPROTO_SCTP)
3048: return -EINVAL;
3049:
3050: break;
3051:
3052: default:
3053: return -EINVAL;
3054: }
3055:
3056: /* Convert non-masked non-tunnel set actions to masked set actions. */
3057: if (!masked && key_type != OVS_KEY_ATTR_TUNNEL) {
3058: int err, start, len = key_len * 2;
3059: struct nlattr *at;
3060:
3061: *skip_copy = true;
3062:
3063: start = add_nested_action_start(sfa,
3064: OVS_ACTION_ATTR_SET_TO_MASKED,
3065: log);
3066: if (start < 0)
3067: return start;
3068:
3069: at = __add_action(sfa, key_type, NULL, len, log);
3070: if (IS_ERR(at)) {
3071: err = PTR_ERR(at);
3072: (*sfa)->actions_len = start;
3073: return err;
3074: }
3075:
3076: memcpy(nla_data(at), nla_data(ovs_key), key_len); /* Key. */
3077: memset(nla_data(at) + key_len, 0xff, key_len); /* Mask. */
3078: /* Clear non-writeable bits from otherwise writeable fields. */
3079: if (key_type == OVS_KEY_ATTR_IPV6) {
3080: struct ovs_key_ipv6 *mask = nla_data(at) + key_len;
3081:
3082: mask->ipv6_label &= htonl(0x000FFFFF);
3083: }
3084: err = add_nested_action_end(*sfa, start);
3085: if (WARN_ON_ONCE(err)) {
3086: (*sfa)->actions_len = start;
3087: return err;
3088: }
3089: }
3090:
3091: return 0;
3092: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 84/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 11595
output: 39
thoughts: 1320
Thoughts: **My Thought Process on the `POP_MPLS` and `SET_IPV6` Interaction**
I'm looking at this question about the interaction between `OVS_ACTION_ATTR_POP_MPLS` and `OVS_ACTION_ATTR_SET` with `OVS_KEY_ATTR_IPV6` in Open vSwitch. The core of the query is whether a `POP_MPLS` action immediately followed by a `SET_IPV6` action in the same action list would be rejected during validation.
My first instinct is to dive into the provided code snippet from `__ovs_nla_copy_actions` for `OVS_ACTION_ATTR_POP_MPLS`. I notice the following logic:
```c
case OVS_ACTION_ATTR_POP_MPLS: {
__be16 proto;
if (vlan_tci & htons(VLAN_CFI_MASK) ||
!eth_p_mpls(eth_type))
return -EINVAL;
/* Disallow subsequent L2.5+ set actions and mpls_pop
* actions once the last MPLS label in the packet is
* popped as there is no check here to ensure that
* the new eth type is valid and thus set actions could
* write off the end of the packet or otherwise corrupt
* it.
*
* Support for these actions is planned using packet
* recirculation.
*/
proto = nla_get_be16(a);
if (proto == htons(ETH_P_TEB) &&
mac_proto != MAC_PROTO_NONE)
return -EINVAL;
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
break;
}
```
The comment right there is extremely telling. It explicitly states: *"Disallow subsequent L2.5+ set actions and mpls_pop actions once the last MPLS label in the packet is popped..."* This immediately suggests that the behavior I'm investigating is intended. The reasoning provided is also crucial: the code lacks checks to ensure the *new* ethertype is valid after popping, potentially leading to corruption. Packet recirculation is mentioned as the planned solution for this.
Now, let's trace the `eth_type` variable:
When `POP_MPLS` is processed, `proto` gets the ethertype specified in the `POP_MPLS` action. The code then checks `if (!eth_p_mpls(proto) || !mpls_label_count)`.
Here's where the critical logic for the question comes into play:
1. **`!eth_p_mpls(proto)`**: If the `proto` obtained from the `POP_MPLS` action is *not* an MPLS ethertype (like `ETH_P_IPV6`), this condition evaluates to true. Even if the intention is to reveal IPv6, `ETH_P_IPV6` is not an MPLS ethertype, so `!eth_p_mpls(ETH_P_IPV6)` is indeed true.
2. **`!mpls_label_count`**: If this is the last MPLS label being popped, this condition also becomes true.
In either of these scenarios, the code sets `eth_type = htons(0)`.
Later, when a `SET_IPV6` action is encountered (within the `OVS_ACTION_ATTR_SET` case), the `validate_set` function is called. Inside `validate_set`, for `OVS_KEY_ATTR_IPV6`, there's this explicit check:
```c
case OVS_KEY_ATTR_IPV6: {
const struct ovs_key_ipv6 *ipv6_key;
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
Since, as we've established, `eth_type` was set to `htons(0)` by the preceding `POP_MPLS` action (because `htons(0)` is not equal to `htons(ETH_P_IPV6)`), this `if` condition `(eth_type != htons(ETH_P_IPV6))` becomes true. Consequently, `validate_set` returns `-EINVAL`. This error is then propagated back up through `__ovs_nla_copy_actions`, causing the entire action list validation to fail.
So, to answer the question directly: Yes, a `POP_MPLS` action followed by a `SET_IPV6` action *will* be rejected during validation in this specific context. The code is deliberately designed this way to prevent potential packet corruption, as highlighted by the comment, and it relies on packet recirculation to handle such transitions correctly. The question itself precisely describes the exact scenario that the code is built to prevent.
|
| 85/4 |
2026/10/01 02:09 |
tool |
git-log |
0m
Args: map[CodeRegexp:Disallow subsequent L2.5\+ set actions PathPrefix:net/openvswitch]
Results: map[Output:fbdcdd78da7c Change in Openvswitch to support MPLS label depth of 3 in ingress direction
]
|
| 86/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 12978
output: 24
thoughts: 23
Thoughts: **My Thought Process Regarding Commit fbdcdd78da7c**
Alright, my first inclination is to dig into the specifics of commit fbdcdd78da7c. I need to understand its exact changes, what it's trying to achieve, and its immediate impact. But that's just the starting point. For me, true understanding comes from placing it within its broader context. So, I'll be looking for any commits that *directly modified* fbdcdd78da7c after its creation. This is crucial because it tells me if the initial implementation had issues, needed refinement, or was part of an iterative development process. Equally important is identifying commits that *introduced* fbdcdd78da7c. This helps me grasp the "why" behind its existence – what problem was it solving, or what feature was it enabling at that particular stage of development? By tracing these relationships, I can build a comprehensive picture of this commit's journey, from its inception to its current state, and understand the evolutionary forces that shaped it.
|
| 87/4 |
2026/10/01 02:09 |
tool |
git-show |
0m
Args:
Results: map[Output:commit fbdcdd78da7c95f1b970d371e1b23cbd3aa990f3
Author: Martin Varghese <martin.varghese@nokia.com>
Date: Mon Nov 4 07:27:44 2019 +0530
Change in Openvswitch to support MPLS label depth of 3 in ingress direction
The openvswitch was supporting a MPLS label depth of 1 in the ingress
direction though the userspace OVS supports a max depth of 3 labels.
This change enables openvswitch module to support a max depth of
3 labels in the ingress.
Signed-off-by: Martin Varghese <martin.varghese@nokia.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 1c77f520f474..12936c151cc0 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -200,7 +200,7 @@ static int set_mpls(struct sk_buff *skb, struct sw_flow_key *flow_key,
if (err)
return err;
- flow_key->mpls.top_lse = lse;
+ flow_key->mpls.lse[0] = lse;
return 0;
}
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 38147e6a20f5..9d375e74b607 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -637,27 +637,35 @@ static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key)
memset(&key->ipv4, 0, sizeof(key->ipv4));
}
} else if (eth_p_mpls(key->eth.type)) {
- size_t stack_len = MPLS_HLEN;
+ u8 label_count = 1;
+ memset(&key->mpls, 0, sizeof(key->mpls));
skb_set_inner_network_header(skb, skb->mac_len);
while (1) {
__be32 lse;
- error = check_header(skb, skb->mac_len + stack_len);
+ error = check_header(skb, skb->mac_len +
+ label_count * MPLS_HLEN);
if (unlikely(error))
return 0;
memcpy(&lse, skb_inner_network_header(skb), MPLS_HLEN);
- if (stack_len == MPLS_HLEN)
- memcpy(&key->mpls.top_lse, &lse, MPLS_HLEN);
+ if (label_count <= MPLS_LABEL_DEPTH)
+ memcpy(&key->mpls.lse[label_count - 1], &lse,
+ MPLS_HLEN);
- skb_set_inner_network_header(skb, skb->mac_len + stack_len);
+ skb_set_inner_network_header(skb, skb->mac_len +
+ label_count * MPLS_HLEN);
if (lse & htonl(MPLS_LS_S_MASK))
break;
- stack_len += MPLS_HLEN;
+ label_count++;
}
+ if (label_count > MPLS_LABEL_DEPTH)
+ label_count = MPLS_LABEL_DEPTH;
+
+ key->mpls.num_labels_mask = GENMASK(label_count - 1, 0);
} else if (key->eth.type == htons(ETH_P_IPV6)) {
int nh_len; /* IPv6 Header + Extensions */
diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h
index 8080518ca5f2..fd8ed766bdd1 100644
--- a/net/openvswitch/flow.h
+++ b/net/openvswitch/flow.h
@@ -30,6 +30,7 @@ enum sw_flow_mac_proto {
MAC_PROTO_ETHERNET,
};
#define SW_FLOW_KEY_INVALID 0x80
+#define MPLS_LABEL_DEPTH 3
/* Store options at the end of the array if they are less than the
* maximum size. This allows us to get the benefits of variable length
@@ -84,9 +85,6 @@ struct sw_flow_key {
* protocol.
*/
union {
- struct {
- __be32 top_lse; /* top label stack entry */
- } mpls;
struct {
u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */
u8 tos; /* IP ToS. */
@@ -135,6 +133,11 @@ struct sw_flow_key {
} nd;
};
} ipv6;
+ struct {
+ u32 num_labels_mask; /* labels present bitmap of effective length MPLS_LABEL_DEPTH */
+ __be32 lse[MPLS_LABEL_DEPTH]; /* label stack entry */
+ } mpls;
+
struct ovs_key_nsh nsh; /* network service header */
};
struct {
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index d7559c64795d..65c2e3458ff5 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -424,7 +424,7 @@ static const struct ovs_len_tbl ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
[OVS_KEY_ATTR_DP_HASH] = { .len = sizeof(u32) },
[OVS_KEY_ATTR_TUNNEL] = { .len = OVS_ATTR_NESTED,
.next = ovs_tunnel_key_lens, },
- [OVS_KEY_ATTR_MPLS] = { .len = sizeof(struct ovs_key_mpls) },
+ [OVS_KEY_ATTR_MPLS] = { .len = OVS_ATTR_VARIABLE },
[OVS_KEY_ATTR_CT_STATE] = { .len = sizeof(u32) },
[OVS_KEY_ATTR_CT_ZONE] = { .len = sizeof(u16) },
[OVS_KEY_ATTR_CT_MARK] = { .len = sizeof(u32) },
@@ -1628,10 +1628,25 @@ static int ovs_key_from_nlattrs(struct net *net, struct sw_flow_match *match,
if (attrs & (1 << OVS_KEY_ATTR_MPLS)) {
const struct ovs_key_mpls *mpls_key;
+ u32 hdr_len;
+ u32 label_count, label_count_mask, i;
mpls_key = nla_data(a[OVS_KEY_ATTR_MPLS]);
- SW_FLOW_KEY_PUT(match, mpls.top_lse,
- mpls_key->mpls_lse, is_mask);
+ hdr_len = nla_len(a[OVS_KEY_ATTR_MPLS]);
+ label_count = hdr_len / sizeof(struct ovs_key_mpls);
+
+ if (label_count == 0 || label_count > MPLS_LABEL_DEPTH ||
+ hdr_len % sizeof(struct ovs_key_mpls))
+ return -EINVAL;
+
+ label_count_mask = GENMASK(label_count - 1, 0);
+
+ for (i = 0 ; i < label_count; i++)
+ SW_FLOW_KEY_PUT(match, mpls.lse[i],
+ mpls_key[i].mpls_lse, is_mask);
+
+ SW_FLOW_KEY_PUT(match, mpls.num_labels_mask,
+ label_count_mask, is_mask);
attrs &= ~(1 << OVS_KEY_ATTR_MPLS);
}
@@ -2114,13 +2129,18 @@ static int __ovs_nla_put_key(const struct sw_flow_key *swkey,
ether_addr_copy(arp_key->arp_sha, output->ipv4.arp.sha);
ether_addr_copy(arp_key->arp_tha, output->ipv4.arp.tha);
} else if (eth_p_mpls(swkey->eth.type)) {
+ u8 i, num_labels;
struct ovs_key_mpls *mpls_key;
- nla = nla_reserve(skb, OVS_KEY_ATTR_MPLS, sizeof(*mpls_key));
+ num_labels = hweight_long(output->mpls.num_labels_mask);
+ nla = nla_reserve(skb, OVS_KEY_ATTR_MPLS,
+ num_labels * sizeof(*mpls_key));
if (!nla)
goto nla_put_failure;
+
mpls_key = nla_data(nla);
- mpls_key->mpls_lse = output->mpls.top_lse;
+ for (i = 0; i < num_labels; i++)
+ mpls_key[i].mpls_lse = output->mpls.lse[i];
}
if ((swkey->eth.type == htons(ETH_P_IP) ||
@@ -2406,13 +2426,14 @@ static inline void add_nested_action_end(struct sw_flow_actions *sfa,
static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
const struct sw_flow_key *key,
struct sw_flow_actions **sfa,
- __be16 eth_type, __be16 vlan_tci, bool log);
+ __be16 eth_type, __be16 vlan_tci,
+ u32 mpls_label_count, bool log);
static int validate_and_copy_sample(struct net *net, const struct nlattr *attr,
const struct sw_flow_key *key,
struct sw_flow_actions **sfa,
__be16 eth_type, __be16 vlan_tci,
- bool log, bool last)
+ u32 mpls_label_count, bool log, bool last)
{
const struct nlattr *attrs[OVS_SAMPLE_ATTR_MAX + 1];
const struct nlattr *probability, *actions;
@@ -2463,7 +2484,7 @@ static int validate_and_copy_sample(struct net *net, const struct nlattr *attr,
return err;
err = __ovs_nla_copy_actions(net, actions, key, sfa,
- eth_type, vlan_tci, log);
+ eth_type, vlan_tci, mpls_label_count, log);
if (err)
return err;
@@ -2478,7 +2499,7 @@ static int validate_and_copy_clone(struct net *net,
const struct sw_flow_key *key,
struct sw_flow_actions **sfa,
__be16 eth_type, __be16 vlan_tci,
- bool log, bool last)
+ u32 mpls_label_count, bool log, bool last)
{
int start, err;
u32 exec;
@@ -2498,7 +2519,7 @@ static int validate_and_copy_clone(struct net *net,
return err;
err = __ovs_nla_copy_actions(net, attr, key, sfa,
- eth_type, vlan_tci, log);
+ eth_type, vlan_tci, mpls_label_count, log);
if (err)
return err;
@@ -2864,6 +2885,7 @@ static int validate_and_copy_check_pkt_len(struct net *net,
const struct sw_flow_key *key,
struct sw_flow_actions **sfa,
__be16 eth_type, __be16 vlan_tci,
+ u32 mpls_label_count,
bool log, bool last)
{
const struct nlattr *acts_if_greater, *acts_if_lesser_eq;
@@ -2912,7 +2934,7 @@ static int validate_and_copy_check_pkt_len(struct net *net,
return nested_acts_start;
err = __ovs_nla_copy_actions(net, acts_if_lesser_eq, key, sfa,
- eth_type, vlan_tci, log);
+ eth_type, vlan_tci, mpls_label_count, log);
if (err)
return err;
@@ -2925,7 +2947,7 @@ static int validate_and_copy_check_pkt_len(struct net *net,
return nested_acts_start;
err = __ovs_nla_copy_actions(net, acts_if_greater, key, sfa,
- eth_type, vlan_tci, log);
+ eth_type, vlan_tci, mpls_label_count, log);
if (err)
return err;
@@ -2952,7 +2974,8 @@ static int copy_action(const struct nlattr *from,
static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
const struct sw_flow_key *key,
struct sw_flow_actions **sfa,
- __be16 eth_type, __be16 vlan_tci, bool log)
+ __be16 eth_type, __be16 vlan_tci,
+ u32 mpls_label_count, bool log)
{
u8 mac_proto = ovs_key_mac_proto(key);
const struct nlattr *a;
@@ -3065,25 +3088,36 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
!eth_p_mpls(eth_type)))
return -EINVAL;
eth_type = mpls->mpls_ethertype;
+ mpls_label_count++;
break;
}
- case OVS_ACTION_ATTR_POP_MPLS:
+ case OVS_ACTION_ATTR_POP_MPLS: {
+ __be16 proto;
if (vlan_tci & htons(VLAN_CFI_MASK) ||
!eth_p_mpls(eth_type))
return -EINVAL;
- /* Disallow subsequent L2.5+ set and mpls_pop actions
- * as there is no check here to ensure that the new
- * eth_type is valid and thus set actions could
- * write off the end of the packet or otherwise
- * corrupt it.
+ /* Disallow subsequent L2.5+ set actions and mpls_pop
+ * actions once the last MPLS label in the packet is
+ * is popped as there is no check here to ensure that
+ * the new eth type is valid and thus set actions could
+ * write off the end of the packet or otherwise corrupt
+ * it.
*
* Support for these actions is planned using packet
* recirculation.
*/
- eth_type = htons(0);
+ proto = nla_get_be16(a);
+ mpls_label_count--;
+
+ if (!eth_p_mpls(proto) || !mpls_label_count)
+ eth_type = htons(0);
+ else
+ eth_type = proto;
+
break;
+ }
case OVS_ACTION_ATTR_SET:
err = validate_set(a, key, sfa,
@@ -3106,6 +3140,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
err = validate_and_copy_sample(net, a, key, sfa,
eth_type, vlan_tci,
+ mpls_label_count,
log, last);
if (err)
return err;
@@ -3176,6 +3211,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
err = validate_and_copy_clone(net, a, key, sfa,
eth_type, vlan_tci,
+ mpls_label_count,
log, last);
if (err)
return err;
@@ -3188,8 +3224,9 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
err = validate_and_copy_check_pkt_len(net, a, key, sfa,
eth_type,
- vlan_tci, log,
- last);
+ vlan_tci,
+ mpls_label_count,
+ log, last);
if (err)
return err;
skip_copy = true;
@@ -3219,14 +3256,18 @@ int ovs_nla_copy_actions(struct net *net, const struct nlattr *attr,
struct sw_flow_actions **sfa, bool log)
{
int err;
+ u32 mpls_label_count = 0;
*sfa = nla_alloc_flow_actions(min(nla_len(attr), MAX_ACTIONS_BUFSIZE));
if (IS_ERR(*sfa))
return PTR_ERR(*sfa);
+ if (eth_p_mpls(key->eth.type))
+ mpls_label_count = hweight_long(key->mpls.num_labels_mask);
+
(*sfa)->orig_len = nla_len(attr);
err = __ovs_nla_copy_actions(net, attr, key, sfa, key->eth.type,
- key->eth.vlan.tci, log);
+ key->eth.vlan.tci, mpls_label_count, log);
if (err)
ovs_nla_free_flow_actions(*sfa);
]
|
| 88/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 18139
output: 39
thoughts: 46
Thoughts: **Tracing the Genesis of MPLS Action Support in OVS**
My immediate priority is to pinpoint the exact commit that introduced the `OVS_ACTION_ATTR_POP_MPLS` functionality into Open vSwitch. To achieve this, I'll be performing a deep dive into the commit history, specifically utilizing `git-log` to meticulously track the origin and evolution of MPLS support within OVS. This investigative approach is crucial for understanding the foundational changes that enabled this capability.
|
| 89/4 |
2026/10/01 02:09 |
tool |
git-log |
0m
Args: map[CodeRegexp:OVS_ACTION_ATTR_POP_MPLS PathPrefix:net/openvswitch]
Results: map[Output:fbdcdd78da7c Change in Openvswitch to support MPLS label depth of 3 in ingress direction
798c166173ff openvswitch: Optimize sample action for the clone use cases
25cd9ba0abc0 openvswitch: Add basic MPLS support to kernel
]
|
| 90/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 18292
output: 23
thoughts: 15
Thoughts: **My Thought Process on Commit 25cd9ba0abc0**
Alright, so I'm looking at commit `25cd9ba0abc0`. My immediate goal is to understand what this commit changes, why it was made, and what its implications might be for the project. Given my expertise, I'm not just skimming; I'm trying to get to the *essence* of the change and evaluate its technical merit and potential impact.
First, I'd pull up the diff associated with this commit. I'm scanning the file names being modified. Are these core components, configuration files, documentation, tests? This gives me a high-level sense of the scope. A change touching a critical service will warrant more immediate scrutiny than a documentation update.
Then, I'm diving into the actual code changes. I'm looking for keywords, patterns, and the overall logic.
* **What's being added, removed, or modified?** Is it new functionality, bug fixes, refactoring, or performance optimizations? I'm paying close attention to the *nature* of the modification. For instance, a deletion of a significant chunk of code might signal a deprecation or a complete architectural shift. Addition of new code suggests a new feature or a solution to a problem. Modifications could be anything from minor tweaks to fundamental algorithm changes.
* **What's the *intent* behind the change?** This is where I try to infer the developer's reasoning. Often, commit messages are key here, but sometimes the code itself tells a story. I'm looking for clues like:
* Is this addressing a known issue? (e.g., "Fix for #1234", "Resolves race condition").
* Is this improving performance? (e.g., "Optimize query execution", "Reduce memory footprint").
* Is this enhancing existing functionality or adding new features? (e.g., "Add support for X", "Implement Y logic").
* Is this a refactoring effort to improve maintainability or readability? (e.g., "Clean up legacy code", "Extract common logic").
* **How complex is the change?** A few lines of code are usually straightforward. A large diff, especially across multiple files, suggests a more significant undertaking. I'm evaluating the *difficulty* of understanding and potentially debugging this change.
* **Are there any potential side effects?** This is crucial. Even a small change can have ripple effects. I'm thinking about:
* **Impact on other modules/services:** Does this change touch any dependencies or interfaces that other parts of the system rely on?
* **Performance implications:** Will this make things faster or slower? Could it introduce new bottlenecks?
* **Security concerns:** Does this change introduce any new vulnerabilities or weaken existing security measures?
* **Scalability issues:** Will this hold up under increased load?
* **Maintainability:** Does this make the code easier or harder to understand and modify in the future? Is it a clear, well-structured solution, or does it feel like a quick patch?
* **Is the code well-written?** As an expert, I have a keen eye for code quality. I'm looking at:
* **Readability:** Is it easy to follow? Are variable and function names clear and descriptive?
* **Simplicity:** Is the solution overly complicated? Could it be achieved more elegantly?
* **Adherence to coding standards/idioms:** Is it consistent with the project's established patterns?
* **Error handling:** Is it robust? Are potential errors caught and handled appropriately?
* **Testing:** If tests are included or modified, are they comprehensive? Do they actually *test* what the commit is supposed to achieve? Are they well-written and maintainable?
Finally, I'd consider the commit message itself. Is it informative? Does it clearly articulate the *why* and *what*? A good commit message is a condensed explanation that saves me time and provides context. A vague or absent message makes my job harder.
In essence, for commit `25cd9ba0abc0`, I'm performing a critical analysis, leveraging my domain knowledge to dissect the change, understand its purpose, and foresee its consequences. I'm essentially doing a mental code review, albeit a rapid one, to ensure the health and integrity of the codebase.
|
| 91/4 |
2026/10/01 02:09 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 25cd9ba0abc0749e5cb78e6493c6f6b3311ec6c5
Author: Simon Horman <horms@verge.net.au>
Date: Mon Oct 6 05:05:13 2014 -0700
openvswitch: Add basic MPLS support to kernel
Allow datapath to recognize and extract MPLS labels into flow keys
and execute actions which push, pop, and set labels on packets.
Based heavily on work by Leo Alterman, Ravi K, Isaku Yamahata and Joe Stringer.
Cc: Ravi K <rkerur@gmail.com>
Cc: Leo Alterman <lalterman@nicira.com>
Cc: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: Joe Stringer <joe@wand.net.nz>
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: Jesse Gross <jesse@nicira.com>
Signed-off-by: Pravin B Shelar <pshelar@nicira.com>
diff --git a/include/net/mpls.h b/include/net/mpls.h
new file mode 100644
index 000000000000..5b3b5addfb08
--- /dev/null
+++ b/include/net/mpls.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2014 Nicira, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ */
+
+#ifndef _NET_MPLS_H
+#define _NET_MPLS_H 1
+
+#include <linux/if_ether.h>
+#include <linux/netdevice.h>
+
+#define MPLS_HLEN 4
+
+static inline bool eth_p_mpls(__be16 eth_type)
+{
+ return eth_type == htons(ETH_P_MPLS_UC) ||
+ eth_type == htons(ETH_P_MPLS_MC);
+}
+
+/*
+ * For non-MPLS skbs this will correspond to the network header.
+ * For MPLS skbs it will be before the network_header as the MPLS
+ * label stack lies between the end of the mac header and the network
+ * header. That is, for MPLS skbs the end of the mac header
+ * is the top of the MPLS label stack.
+ */
+static inline unsigned char *skb_mpls_header(struct sk_buff *skb)
+{
+ return skb_mac_header(skb) + skb->mac_len;
+}
+#endif
diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h
index 435eabc5ffaa..631056b66f80 100644
--- a/include/uapi/linux/openvswitch.h
+++ b/include/uapi/linux/openvswitch.h
@@ -293,6 +293,9 @@ enum ovs_key_attr {
OVS_KEY_ATTR_DP_HASH, /* u32 hash value. Value 0 indicates the hash
is not computed by the datapath. */
OVS_KEY_ATTR_RECIRC_ID, /* u32 recirc id */
+ OVS_KEY_ATTR_MPLS, /* array of struct ovs_key_mpls.
+ * The implementation may restrict
+ * the accepted length of the array. */
#ifdef __KERNEL__
OVS_KEY_ATTR_TUNNEL_INFO, /* struct ovs_tunnel_info */
@@ -340,6 +343,10 @@ struct ovs_key_ethernet {
__u8 eth_dst[ETH_ALEN];
};
+struct ovs_key_mpls {
+ __be32 mpls_lse;
+};
+
struct ovs_key_ipv4 {
__be32 ipv4_src;
__be32 ipv4_dst;
@@ -483,6 +490,19 @@ enum ovs_userspace_attr {
#define OVS_USERSPACE_ATTR_MAX (__OVS_USERSPACE_ATTR_MAX - 1)
+/**
+ * struct ovs_action_push_mpls - %OVS_ACTION_ATTR_PUSH_MPLS action argument.
+ * @mpls_lse: MPLS label stack entry to push.
+ * @mpls_ethertype: Ethertype to set in the encapsulating ethernet frame.
+ *
+ * The only values @mpls_ethertype should ever be given are %ETH_P_MPLS_UC and
+ * %ETH_P_MPLS_MC, indicating MPLS unicast or multicast. Other are rejected.
+ */
+struct ovs_action_push_mpls {
+ __be32 mpls_lse;
+ __be16 mpls_ethertype; /* Either %ETH_P_MPLS_UC or %ETH_P_MPLS_MC */
+};
+
/**
* struct ovs_action_push_vlan - %OVS_ACTION_ATTR_PUSH_VLAN action argument.
* @vlan_tpid: Tag protocol identifier (TPID) to push.
@@ -534,6 +554,15 @@ struct ovs_action_hash {
* @OVS_ACTION_ATTR_POP_VLAN: Pop the outermost 802.1Q header off the packet.
* @OVS_ACTION_ATTR_SAMPLE: Probabilitically executes actions, as specified in
* the nested %OVS_SAMPLE_ATTR_* attributes.
+ * @OVS_ACTION_ATTR_PUSH_MPLS: Push a new MPLS label stack entry onto the
+ * top of the packets MPLS label stack. Set the ethertype of the
+ * encapsulating frame to either %ETH_P_MPLS_UC or %ETH_P_MPLS_MC to
+ * indicate the new packet contents.
+ * @OVS_ACTION_ATTR_POP_MPLS: Pop an MPLS label stack entry off of the
+ * packet's MPLS label stack. Set the encapsulating frame's ethertype to
+ * indicate the new packet contents. This could potentially still be
+ * %ETH_P_MPLS if the resulting MPLS label stack is not empty. If there
+ * is no MPLS label stack, as determined by ethertype, no action is taken.
*
* Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all
* fields within a header are modifiable, e.g. the IPv4 protocol and fragment
@@ -550,6 +579,9 @@ enum ovs_action_attr {
OVS_ACTION_ATTR_SAMPLE, /* Nested OVS_SAMPLE_ATTR_*. */
OVS_ACTION_ATTR_RECIRC, /* u32 recirc_id. */
OVS_ACTION_ATTR_HASH, /* struct ovs_action_hash. */
+ OVS_ACTION_ATTR_PUSH_MPLS, /* struct ovs_action_push_mpls. */
+ OVS_ACTION_ATTR_POP_MPLS, /* __be16 ethertype. */
+
__OVS_ACTION_ATTR_MAX
};
diff --git a/net/core/dev.c b/net/core/dev.c
index 40be481268de..70bb609c283d 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -118,6 +118,7 @@
#include <linux/if_vlan.h>
#include <linux/ip.h>
#include <net/ip.h>
+#include <net/mpls.h>
#include <linux/ipv6.h>
#include <linux/in.h>
#include <linux/jhash.h>
@@ -2530,7 +2531,7 @@ static netdev_features_t net_mpls_features(struct sk_buff *skb,
netdev_features_t features,
__be16 type)
{
- if (type == htons(ETH_P_MPLS_UC) || type == htons(ETH_P_MPLS_MC))
+ if (eth_p_mpls(type))
features &= skb->dev->mpls_features;
return features;
diff --git a/net/openvswitch/Kconfig b/net/openvswitch/Kconfig
index 2a9673e39ca1..454ce12efbbf 100644
--- a/net/openvswitch/Kconfig
+++ b/net/openvswitch/Kconfig
@@ -30,6 +30,7 @@ config OPENVSWITCH
config OPENVSWITCH_GRE
tristate "Open vSwitch GRE tunneling support"
+ select NET_MPLS_GSO
depends on INET
depends on OPENVSWITCH
depends on NET_IPGRE_DEMUX
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 922c133b1933..930b1b6e4cef 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -28,10 +28,12 @@
#include <linux/in6.h>
#include <linux/if_arp.h>
#include <linux/if_vlan.h>
+
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/checksum.h>
#include <net/dsfield.h>
+#include <net/mpls.h>
#include <net/sctp/checksum.h>
#include "datapath.h"
@@ -118,6 +120,92 @@ static int make_writable(struct sk_buff *skb, int write_len)
return pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
}
+static int push_mpls(struct sk_buff *skb,
+ const struct ovs_action_push_mpls *mpls)
+{
+ __be32 *new_mpls_lse;
+ struct ethhdr *hdr;
+
+ /* Networking stack do not allow simultaneous Tunnel and MPLS GSO. */
+ if (skb->encapsulation)
+ return -ENOTSUPP;
+
+ if (skb_cow_head(skb, MPLS_HLEN) < 0)
+ return -ENOMEM;
+
+ skb_push(skb, MPLS_HLEN);
+ memmove(skb_mac_header(skb) - MPLS_HLEN, skb_mac_header(skb),
+ skb->mac_len);
+ skb_reset_mac_header(skb);
+
+ new_mpls_lse = (__be32 *)skb_mpls_header(skb);
+ *new_mpls_lse = mpls->mpls_lse;
+
+ if (skb->ip_summed == CHECKSUM_COMPLETE)
+ skb->csum = csum_add(skb->csum, csum_partial(new_mpls_lse,
+ MPLS_HLEN, 0));
+
+ hdr = eth_hdr(skb);
+ hdr->h_proto = mpls->mpls_ethertype;
+
+ skb_set_inner_protocol(skb, skb->protocol);
+ skb->protocol = mpls->mpls_ethertype;
+
+ return 0;
+}
+
+static int pop_mpls(struct sk_buff *skb, const __be16 ethertype)
+{
+ struct ethhdr *hdr;
+ int err;
+
+ err = make_writable(skb, skb->mac_len + MPLS_HLEN);
+ if (unlikely(err))
+ return err;
+
+ if (skb->ip_summed == CHECKSUM_COMPLETE)
+ skb->csum = csum_sub(skb->csum,
+ csum_partial(skb_mpls_header(skb),
+ MPLS_HLEN, 0));
+
+ memmove(skb_mac_header(skb) + MPLS_HLEN, skb_mac_header(skb),
+ skb->mac_len);
+
+ __skb_pull(skb, MPLS_HLEN);
+ skb_reset_mac_header(skb);
+
+ /* skb_mpls_header() is used to locate the ethertype
+ * field correctly in the presence of VLAN tags.
+ */
+ hdr = (struct ethhdr *)(skb_mpls_header(skb) - ETH_HLEN);
+ hdr->h_proto = ethertype;
+ if (eth_p_mpls(skb->protocol))
+ skb->protocol = ethertype;
+ return 0;
+}
+
+static int set_mpls(struct sk_buff *skb, const __be32 *mpls_lse)
+{
+ __be32 *stack;
+ int err;
+
+ err = make_writable(skb, skb->mac_len + MPLS_HLEN);
+ if (unlikely(err))
+ return err;
+
+ stack = (__be32 *)skb_mpls_header(skb);
+ if (skb->ip_summed == CHECKSUM_COMPLETE) {
+ __be32 diff[] = { ~(*stack), *mpls_lse };
+
+ skb->csum = ~csum_partial((char *)diff, sizeof(diff),
+ ~skb->csum);
+ }
+
+ *stack = *mpls_lse;
+
+ return 0;
+}
+
/* remove VLAN header from packet and update csum accordingly. */
static int __pop_vlan_tci(struct sk_buff *skb, __be16 *current_tci)
{
@@ -140,10 +228,12 @@ static int __pop_vlan_tci(struct sk_buff *skb, __be16 *current_tci)
vlan_set_encap_proto(skb, vhdr);
skb->mac_header += VLAN_HLEN;
+
if (skb_network_offset(skb) < ETH_HLEN)
skb_set_network_header(skb, ETH_HLEN);
- skb_reset_mac_len(skb);
+ /* Update mac_len for subsequent MPLS actions */
+ skb_reset_mac_len(skb);
return 0;
}
@@ -186,6 +276,8 @@ static int push_vlan(struct sk_buff *skb, const struct ovs_action_push_vlan *vla
if (!__vlan_put_tag(skb, skb->vlan_proto, current_tag))
return -ENOMEM;
+ /* Update mac_len for subsequent MPLS actions */
+ skb->mac_len += VLAN_HLEN;
if (skb->ip_summed == CHECKSUM_COMPLETE)
skb->csum = csum_add(skb->csum, csum_partial(skb->data
@@ -612,6 +704,10 @@ static int execute_set_action(struct sk_buff *skb,
case OVS_KEY_ATTR_SCTP:
err = set_sctp(skb, nla_data(nested_attr));
break;
+
+ case OVS_KEY_ATTR_MPLS:
+ err = set_mpls(skb, nla_data(nested_attr));
+ break;
}
return err;
@@ -690,6 +786,14 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb,
execute_hash(skb, key, a);
break;
+ case OVS_ACTION_ATTR_PUSH_MPLS:
+ err = push_mpls(skb, nla_data(a));
+ break;
+
+ case OVS_ACTION_ATTR_POP_MPLS:
+ err = pop_mpls(skb, nla_get_be16(a));
+ break;
+
case OVS_ACTION_ATTR_PUSH_VLAN:
err = push_vlan(skb, nla_data(a));
if (unlikely(err)) /* skb already freed. */
diff --git a/net/openvswitch/datapath.c b/net/openvswitch/datapath.c
index f18302f32049..688cb9bc0ef1 100644
--- a/net/openvswitch/datapath.c
+++ b/net/openvswitch/datapath.c
@@ -560,7 +560,7 @@ static int ovs_packet_cmd_execute(struct sk_buff *skb, struct genl_info *info)
goto err_flow_free;
err = ovs_nla_copy_actions(a[OVS_PACKET_ATTR_ACTIONS],
- &flow->key, 0, &acts);
+ &flow->key, &acts);
if (err)
goto err_flow_free;
@@ -846,7 +846,7 @@ static int ovs_flow_cmd_new(struct sk_buff *skb, struct genl_info *info)
goto err_kfree_flow;
error = ovs_nla_copy_actions(a[OVS_FLOW_ATTR_ACTIONS], &new_flow->key,
- 0, &acts);
+ &acts);
if (error) {
OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
goto err_kfree_acts;
@@ -953,7 +953,7 @@ static struct sw_flow_actions *get_flow_actions(const struct nlattr *a,
return acts;
ovs_flow_mask_key(&masked_key, key, mask);
- error = ovs_nla_copy_actions(a, &masked_key, 0, &acts);
+ error = ovs_nla_copy_actions(a, &masked_key, &acts);
if (error) {
OVS_NLERR("Flow actions may not be safe on all matching packets.\n");
kfree(acts);
diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
index 2b78789ea7c5..90a21010fc8f 100644
--- a/net/openvswitch/flow.c
+++ b/net/openvswitch/flow.c
@@ -32,6 +32,7 @@
#include <linux/if_arp.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
+#include <linux/mpls.h>
#include <linux/sctp.h>
#include <linux/smp.h>
#include <linux/tcp.h>
@@ -42,6 +43,7 @@
#include <net/ip.h>
#include <net/ip_tunnels.h>
#include <net/ipv6.h>
+#include <net/mpls.h>
#include <net/ndisc.h>
#include "datapath.h"
@@ -480,6 +482,7 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
return -ENOMEM;
skb_reset_network_header(skb);
+ skb_reset_mac_len(skb);
__skb_push(skb, skb->data - skb_mac_header(skb));
/* Network layer. */
@@ -584,6 +587,33 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key)
memset(&key->ip, 0, sizeof(key->ip));
memset(&key->ipv4, 0, sizeof(key->ipv4));
}
+ } else if (eth_p_mpls(key->eth.type)) {
+ size_t stack_len = MPLS_HLEN;
+
+ /* In the presence of an MPLS label stack the end of the L2
+ * header and the beginning of the L3 header differ.
+ *
+ * Advance network_header to the beginning of the L3
+ * header. mac_len corresponds to the end of the L2 header.
+ */
+ while (1) {
+ __be32 lse;
+
+ error = check_header(skb, skb->mac_len + stack_len);
+ if (unlikely(error))
+ return 0;
+
+ memcpy(&lse, skb_network_header(skb), MPLS_HLEN);
+
+ if (stack_len == MPLS_HLEN)
+ memcpy(&key->mpls.top_lse, &lse, MPLS_HLEN);
+
+ skb_set_network_header(skb, skb->mac_len + stack_len);
+ if (lse & htonl(MPLS_LS_S_MASK))
+ break;
+
+ stack_len += MPLS_HLEN;
+ }
} else if (key->eth.type == htons(ETH_P_IPV6)) {
int nh_len; /* IPv6 Header + Extensions */
diff --git a/net/openvswitch/flow.h b/net/openvswitch/flow.h
index 71813318c8c7..4962bee81a11 100644
--- a/net/openvswitch/flow.h
+++ b/net/openvswitch/flow.h
@@ -102,12 +102,17 @@ struct sw_flow_key {
__be16 tci; /* 0 if no VLAN, VLAN_TAG_PRESENT set otherwise. */
__be16 type; /* Ethernet frame type. */
} eth;
- struct {
- u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */
- u8 tos; /* IP ToS. */
- u8 ttl; /* IP TTL/hop limit. */
- u8 frag; /* One of OVS_FRAG_TYPE_*. */
- } ip;
+ union {
+ struct {
+ __be32 top_lse; /* top label stack entry */
+ } mpls;
+ struct {
+ u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */
+ u8 tos; /* IP ToS. */
+ u8 ttl; /* IP TTL/hop limit. */
+ u8 frag; /* One of OVS_FRAG_TYPE_*. */
+ } ip;
+ };
struct {
__be16 src; /* TCP/UDP/SCTP source port. */
__be16 dst; /* TCP/UDP/SCTP destination port. */
diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c
index 939bcb32100f..569309c49cc0 100644
--- a/net/openvswitch/flow_netlink.c
+++ b/net/openvswitch/flow_netlink.c
@@ -46,6 +46,7 @@
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/ndisc.h>
+#include <net/mpls.h>
#include "flow_netlink.h"
@@ -134,7 +135,8 @@ static bool match_validate(const struct sw_flow_match *match,
| (1 << OVS_KEY_ATTR_ICMP)
| (1 << OVS_KEY_ATTR_ICMPV6)
| (1 << OVS_KEY_ATTR_ARP)
- | (1 << OVS_KEY_ATTR_ND));
+ | (1 << OVS_KEY_ATTR_ND)
+ | (1 << OVS_KEY_ATTR_MPLS));
/* Always allowed mask fields. */
mask_allowed |= ((1 << OVS_KEY_ATTR_TUNNEL)
@@ -149,6 +151,12 @@ static bool match_validate(const struct sw_flow_match *match,
mask_allowed |= 1 << OVS_KEY_ATTR_ARP;
}
+ if (eth_p_mpls(match->key->eth.type)) {
+ key_expected |= 1 << OVS_KEY_ATTR_MPLS;
+ if (match->mask && (match->mask->key.eth.type == htons(0xffff)))
+ mask_allowed |= 1 << OVS_KEY_ATTR_MPLS;
+ }
+
if (match->key->eth.type == htons(ETH_P_IP)) {
key_expected |= 1 << OVS_KEY_ATTR_IPV4;
if (match->mask && (match->mask->key.eth.type == htons(0xffff)))
@@ -266,6 +274,7 @@ static const int ovs_key_lens[OVS_KEY_ATTR_MAX + 1] = {
[OVS_KEY_ATTR_RECIRC_ID] = sizeof(u32),
[OVS_KEY_ATTR_DP_HASH] = sizeof(u32),
[OVS_KEY_ATTR_TUNNEL] = -1,
+ [OVS_KEY_ATTR_MPLS] = sizeof(struct ovs_key_mpls),
};
static bool is_all_zero(const u8 *fp, size_t size)
@@ -735,6 +744,16 @@ static int ovs_key_from_nlattrs(struct sw_flow_match *match, u64 attrs,
attrs &= ~(1 << OVS_KEY_ATTR_ARP);
}
+ if (attrs & (1 << OVS_KEY_ATTR_MPLS)) {
+ const struct ovs_key_mpls *mpls_key;
+
+ mpls_key = nla_data(a[OVS_KEY_ATTR_MPLS]);
+ SW_FLOW_KEY_PUT(match, mpls.top_lse,
+ mpls_key->mpls_lse, is_mask);
+
+ attrs &= ~(1 << OVS_KEY_ATTR_MPLS);
+ }
+
if (attrs & (1 << OVS_KEY_ATTR_TCP)) {
const struct ovs_key_tcp *tcp_key;
@@ -1140,6 +1159,14 @@ int ovs_nla_put_flow(const struct sw_flow_key *swkey,
arp_key->arp_op = htons(output->ip.proto);
ether_addr_copy(arp_key->arp_sha, output->ipv4.arp.sha);
ether_addr_copy(arp_key->arp_tha, output->ipv4.arp.tha);
+ } else if (eth_p_mpls(swkey->eth.type)) {
+ struct ovs_key_mpls *mpls_key;
+
+ nla = nla_reserve(skb, OVS_KEY_ATTR_MPLS, sizeof(*mpls_key));
+ if (!nla)
+ goto nla_put_failure;
+ mpls_key = nla_data(nla);
+ mpls_key->mpls_lse = output->mpls.top_lse;
}
if ((swkey->eth.type == htons(ETH_P_IP) ||
@@ -1336,9 +1363,15 @@ static inline void add_nested_action_end(struct sw_flow_actions *sfa,
a->nla_len = sfa->actions_len - st_offset;
}
+static int ovs_nla_copy_actions__(const struct nlattr *attr,
+ const struct sw_flow_key *key,
+ int depth, struct sw_flow_actions **sfa,
+ __be16 eth_type, __be16 vlan_tci);
+
static int validate_and_copy_sample(const struct nlattr *attr,
const struct sw_flow_key *key, int depth,
- struct sw_flow_actions **sfa)
+ struct sw_flow_actions **sfa,
+ __be16 eth_type, __be16 vlan_tci)
{
const struct nlattr *attrs[OVS_SAMPLE_ATTR_MAX + 1];
const struct nlattr *probability, *actions;
@@ -1375,7 +1408,8 @@ static int validate_and_copy_sample(const struct nlattr *attr,
if (st_acts < 0)
return st_acts;
- err = ovs_nla_copy_actions(actions, key, depth + 1, sfa);
+ err = ovs_nla_copy_actions__(actions, key, depth + 1, sfa,
+ eth_type, vlan_tci);
if (err)
return err;
@@ -1385,10 +1419,10 @@ static int validate_and_copy_sample(const struct nlattr *attr,
return 0;
}
-static int validate_tp_port(const struct sw_flow_key *flow_key)
+static int validate_tp_port(const struct sw_flow_key *flow_key,
+ __be16 eth_type)
{
- if ((flow_key->eth.type == htons(ETH_P_IP) ||
- flow_key->eth.type == htons(ETH_P_IPV6)) &&
+ if ((eth_type == htons(ETH_P_IP) || eth_type == htons(ETH_P_IPV6)) &&
(flow_key->tp.src || flow_key->tp.dst))
return 0;
@@ -1483,7 +1517,7 @@ static int validate_and_copy_set_tun(const struct nlattr *attr,
static int validate_set(const struct nlattr *a,
const struct sw_flow_key *flow_key,
struct sw_flow_actions **sfa,
- bool *set_tun)
+ bool *set_tun, __be16 eth_type)
{
const struct nlattr *ovs_key = nla_data(a);
int key_type = nla_type(ovs_key);
@@ -1508,6 +1542,9 @@ static int validate_set(const struct nlattr *a,
break;
case OVS_KEY_ATTR_TUNNEL:
+ if (eth_p_mpls(eth_type))
+ return -EINVAL;
+
*set_tun = true;
err = validate_and_copy_set_tun(a, sfa);
if (err)
@@ -1515,7 +1552,7 @@ static int validate_set(const struct nlattr *a,
break;
case OVS_KEY_ATTR_IPV4:
- if (flow_key->eth.type != htons(ETH_P_IP))
+ if (eth_type != htons(ETH_P_IP))
return -EINVAL;
if (!flow_key->ip.proto)
@@ -1531,7 +1568,7 @@ static int validate_set(const struct nlattr *a,
break;
case OVS_KEY_ATTR_IPV6:
- if (flow_key->eth.type != htons(ETH_P_IPV6))
+ if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
if (!flow_key->ip.proto)
@@ -1553,19 +1590,24 @@ static int validate_set(const struct nlattr *a,
if (flow_key->ip.proto != IPPROTO_TCP)
return -EINVAL;
- return validate_tp_port(flow_key);
+ return validate_tp_port(flow_key, eth_type);
case OVS_KEY_ATTR_UDP:
if (flow_key->ip.proto != IPPROTO_UDP)
return -EINVAL;
- return validate_tp_port(flow_key);
+ return validate_tp_port(flow_key, eth_type);
+
+ case OVS_KEY_ATTR_MPLS:
+ if (!eth_p_mpls(eth_type))
+ return -EINVAL;
+ break;
case OVS_KEY_ATTR_SCTP:
if (flow_key->ip.proto != IPPROTO_SCTP)
return -EINVAL;
- return validate_tp_port(flow_key);
+ return validate_tp_port(flow_key, eth_type);
default:
return -EINVAL;
@@ -1609,12 +1651,13 @@ static int copy_action(const struct nlattr *from,
return 0;
}
-int ovs_nla_copy_actions(const struct nlattr *attr,
- const struct sw_flow_key *key,
- int depth,
- struct sw_flow_actions **sfa)
+static int ovs_nla_copy_actions__(const struct nlattr *attr,
+ const struct sw_flow_key *key,
+ int depth, struct sw_flow_actions **sfa,
+ __be16 eth_type, __be16 vlan_tci)
{
const struct nlattr *a;
+ bool out_tnl_port = false;
int rem, err;
if (depth >= SAMPLE_ACTION_DEPTH)
@@ -1626,6 +1669,8 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
[OVS_ACTION_ATTR_OUTPUT] = sizeof(u32),
[OVS_ACTION_ATTR_RECIRC] = sizeof(u32),
[OVS_ACTION_ATTR_USERSPACE] = (u32)-1,
+ [OVS_ACTION_ATTR_PUSH_MPLS] = sizeof(struct ovs_action_push_mpls),
+ [OVS_ACTION_ATTR_POP_MPLS] = sizeof(__be16),
[OVS_ACTION_ATTR_PUSH_VLAN] = sizeof(struct ovs_action_push_vlan),
[OVS_ACTION_ATTR_POP_VLAN] = 0,
[OVS_ACTION_ATTR_SET] = (u32)-1,
@@ -1655,6 +1700,8 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
case OVS_ACTION_ATTR_OUTPUT:
if (nla_get_u32(a) >= DP_MAX_PORTS)
return -EINVAL;
+ out_tnl_port = false;
+
break;
case OVS_ACTION_ATTR_HASH: {
@@ -1671,6 +1718,7 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
}
case OVS_ACTION_ATTR_POP_VLAN:
+ vlan_tci = htons(0);
break;
case OVS_ACTION_ATTR_PUSH_VLAN:
@@ -1679,19 +1727,66 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
return -EINVAL;
if (!(vlan->vlan_tci & htons(VLAN_TAG_PRESENT)))
return -EINVAL;
+ vlan_tci = vlan->vlan_tci;
break;
case OVS_ACTION_ATTR_RECIRC:
break;
+ case OVS_ACTION_ATTR_PUSH_MPLS: {
+ const struct ovs_action_push_mpls *mpls = nla_data(a);
+
+ /* Networking stack do not allow simultaneous Tunnel
+ * and MPLS GSO.
+ */
+ if (out_tnl_port)
+ return -EINVAL;
+
+ if (!eth_p_mpls(mpls->mpls_ethertype))
+ return -EINVAL;
+ /* Prohibit push MPLS other than to a white list
+ * for packets that have a known tag order.
+ */
+ if (vlan_tci & htons(VLAN_TAG_PRESENT) ||
+ (eth_type != htons(ETH_P_IP) &&
+ eth_type != htons(ETH_P_IPV6) &&
+ eth_type != htons(ETH_P_ARP) &&
+ eth_type != htons(ETH_P_RARP) &&
+ !eth_p_mpls(eth_type)))
+ return -EINVAL;
+ eth_type = mpls->mpls_ethertype;
+ break;
+ }
+
+ case OVS_ACTION_ATTR_POP_MPLS:
+ if (vlan_tci & htons(VLAN_TAG_PRESENT) ||
+ !eth_p_mpls(eth_type))
+ return -EINVAL;
+
+ /* Disallow subsequent L2.5+ set and mpls_pop actions
+ * as there is no check here to ensure that the new
+ * eth_type is valid and thus set actions could
+ * write off the end of the packet or otherwise
+ * corrupt it.
+ *
+ * Support for these actions is planned using packet
+ * recirculation.
+ */
+ eth_type = htons(0);
+ break;
+
case OVS_ACTION_ATTR_SET:
- err = validate_set(a, key, sfa, &skip_copy);
+ err = validate_set(a, key, sfa,
+ &out_tnl_port, eth_type);
if (err)
return err;
+
+ skip_copy = out_tnl_port;
break;
case OVS_ACTION_ATTR_SAMPLE:
- err = validate_and_copy_sample(a, key, depth, sfa);
+ err = validate_and_copy_sample(a, key, depth, sfa,
+ eth_type, vlan_tci);
if (err)
return err;
skip_copy = true;
@@ -1713,6 +1808,14 @@ int ovs_nla_copy_actions(const struct nlattr *attr,
return 0;
}
+int ovs_nla_copy_actions(const struct nlattr *attr,
+ const struct sw_flow_key *key,
+ struct sw_flow_actions **sfa)
+{
+ return ovs_nla_copy_actions__(attr, key, 0, sfa, key->eth.type,
+ key->eth.tci);
+}
+
static int sample_action_to_attr(const struct nlattr *attr, struct sk_buff *skb)
{
const struct nlattr *a;
diff --git a/net/openvswitch/flow_netlink.h b/net/openvswitch/flow_netlink.h
index 206e45add888..6355b1d01329 100644
--- a/net/openvswitch/flow_netlink.h
+++ b/net/openvswitch/flow_netlink.h
@@ -49,7 +49,7 @@ int ovs_nla_get_match(struct sw_flow_match *match,
const struct nlattr *);
int ovs_nla_copy_actions(const struct nlattr *attr,
- const struct sw_flow_key *key, int depth,
+ const struct sw_flow_key *key,
struct sw_flow_actions **sfa);
int ovs_nla_put_actions(const struct nlattr *attr,
int len, struct sk_buff *skb);
]
|
| 92/4 |
2026/10/01 02:09 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 28931
output: 41
thoughts: 1749
Thoughts: **A Deep Dive into `POP_MPLS` and Subsequent `SET_IPV6` Actions**
As I trace the evolution of the `OVS_ACTION_ATTR_POP_MPLS` action and its interactions with subsequent `SET` actions, specifically `OVS_KEY_ATTR_IPV6`, I'm arriving at a definitive conclusion: a `POP_MPLS` action followed by a `SET_IPV6` action *will indeed be rejected during validation*. Let me lay out my thought process, connecting the code snippets and the underlying logic.
**Initial Observation: The `POP_MPLS` Transformation of `eth_type`**
I began by comparing the behavior of `POP_MPLS` across two commits, `25cd9ba0abc0` and `fbdcdd78da7c`. The core functionality seems to be about stripping an MPLS label and determining what the *next* ethertype should be.
In commit `fbdcdd78da7c`, which is more relevant to the current discussion due to its more detailed handling of MPLS label depth, the logic for updating `eth_type` after popping a label is critical:
```c
proto = nla_get_be16(a);
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
```
This logic clearly establishes two main outcomes for `eth_type` after a `POP_MPLS` action:
1. **`eth_type` becomes `htons(0)`**: This happens if the protocol (`proto`) following the popped label is *not* an MPLS ethertype (`!eth_p_mpls(proto)`) or if the popped label was the last MPLS label in the stack (`!mpls_label_count`).
2. **`eth_type` becomes `proto`**: This happens only if the protocol following the popped label *is* an MPLS ethertype (`eth_p_mpls(proto)`) AND there are still MPLS labels remaining (`mpls_label_count > 0`).
**The Crucial Validation Step: `SET_IPV6`**
Now, I consider what happens when a subsequent `OVS_ACTION_ATTR_SET` action targets `OVS_KEY_ATTR_IPV6`. The validation for this action is quite strict:
```c
case OVS_KEY_ATTR_IPV6: {
const struct ovs_key_ipv6 *ipv6_key;
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
This `if` statement is the linchpin. It demands that `eth_type` *must* be `htons(ETH_P_IPV6)` for the `SET_IPV6` action to be considered valid.
**Connecting the Dots: Why `POP_MPLS` Never Leads to `htons(ETH_P_IPV6)`**
This is where my analysis becomes sharp. I'm asking myself: can the `POP_MPLS` action, under any circumstances, result in `eth_type` being set to `htons(ETH_P_IPV6)`?
Let's re-examine the `POP_MPLS` logic:
* The `else` branch, where `eth_type` is set to `proto`, *requires* `eth_p_mpls(proto)` to be true. If `proto` were `ETH_P_IPV6`, then `eth_p_mpls(proto)` would be false. Therefore, `eth_type` can *never* be set to `ETH_P_IPV6` in this `else` branch.
* If `proto` were an MPLS ethertype (e.g., `ETH_P_MPLS_UC` or `ETH_P_MPLS_MC`), then `eth_type` would be set to that MPLS ethertype in the `else` branch. This is still *not* `ETH_P_IPV6`.
* The `if` branch sets `eth_type` to `htons(0)`. This is also clearly not `htons(ETH_P_IPV6)`.
So, after a `POP_MPLS` action, `eth_type` will *always* be either `htons(0)` (if the inner protocol isn't MPLS or it was the last label) or an MPLS ethertype (if more labels remain). In *neither* of these scenarios will `eth_type` equal `htons(ETH_P_IPV6)`.
**The Inevitable Rejection**
Given that `POP_MPLS` can never set `eth_type` to `htons(ETH_P_IPV6)`, and the `SET_IPV6` validation *strictly requires* `eth_type` to be `htons(ETH_P_IPV6)`, the validation check `if (eth_type != htons(ETH_P_IPV6)) return -EINVAL;` will *always* evaluate to true in this sequence of actions. Consequently, the `SET_IPV6` action will be rejected with an `EINVAL` error.
**The Rationale Behind This Restriction**
The comments within the `POP_MPLS` code provide the reasoning for this seemingly strict behavior:
```c
/* Disallow subsequent L2.5+ set actions and mpls_pop
* actions once the last MPLS label in the packet is
* popped as there is no check here to ensure that
* the new eth type is valid and thus set actions could
* write off the end of the packet or otherwise corrupt
* it.
*
* Support for these actions is planned using packet
* recirculation.
*/
```
This indicates a fundamental limitation: when OVS parses an MPLS packet on ingress, it extracts the MPLS labels into `key->mpls` but *does not* parse the L3/L4 headers *inside* or *after* the MPLS stack into the flow key. This means that if OVS were to allow a `SET_IPV6` action immediately after `POP_MPLS` without further processing, it wouldn't have the necessary context or checks to ensure the packet was validly formed after the pop operation. Setting arbitrary L3/L4 headers could easily lead to buffer overflows or corrupt packet structures. The comment explicitly mentions that support for these more complex transitions is planned via packet recirculation, which would allow for re-parsing and validation.
Therefore, to maintain packet integrity and avoid undefined behavior, OVS prevents this direct transition. My analysis confirms that the code correctly enforces this restriction.
|
| 93/4 |
2026/10/01 02:10 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow.c Name:key_extract_l3l4]
Results: map[SourceCode: 671: /**
672: * key_extract_l3l4 - extracts L3/L4 header information.
673: * @skb: sk_buff that contains the frame, with skb->data pointing to the
674: * L3 header
675: * @key: output flow key
676: *
677: * Return: %0 if successful, otherwise a negative errno value.
678: */
679: static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key)
680: {
681: int error;
682:
683: /* Network layer. */
684: if (key->eth.type == htons(ETH_P_IP)) {
685: struct iphdr *nh;
686: __be16 offset;
687:
688: error = check_iphdr(skb);
689: if (unlikely(error)) {
690: memset(&key->ip, 0, sizeof(key->ip));
691: memset(&key->ipv4, 0, sizeof(key->ipv4));
692: if (error == -EINVAL) {
693: skb->transport_header = skb->network_header;
694: error = 0;
695: }
696: return error;
697: }
698:
699: nh = ip_hdr(skb);
700: key->ipv4.addr.src = nh->saddr;
701: key->ipv4.addr.dst = nh->daddr;
702:
703: key->ip.proto = nh->protocol;
704: key->ip.tos = nh->tos;
705: key->ip.ttl = nh->ttl;
706:
707: offset = nh->frag_off & htons(IP_OFFSET);
708: if (offset) {
709: key->ip.frag = OVS_FRAG_TYPE_LATER;
710: memset(&key->tp, 0, sizeof(key->tp));
711: return 0;
712: }
713: if (nh->frag_off & htons(IP_MF) ||
714: skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
715: key->ip.frag = OVS_FRAG_TYPE_FIRST;
716: else
717: key->ip.frag = OVS_FRAG_TYPE_NONE;
718:
719: /* Transport layer. */
720: if (key->ip.proto == IPPROTO_TCP) {
721: if (tcphdr_ok(skb)) {
722: struct tcphdr *tcp = tcp_hdr(skb);
723: key->tp.src = tcp->source;
724: key->tp.dst = tcp->dest;
725: key->tp.flags = TCP_FLAGS_BE16(tcp);
726: } else {
727: memset(&key->tp, 0, sizeof(key->tp));
728: }
729:
730: } else if (key->ip.proto == IPPROTO_UDP) {
731: if (udphdr_ok(skb)) {
732: struct udphdr *udp = udp_hdr(skb);
733: key->tp.src = udp->source;
734: key->tp.dst = udp->dest;
735: } else {
736: memset(&key->tp, 0, sizeof(key->tp));
737: }
738: } else if (key->ip.proto == IPPROTO_SCTP) {
739: if (sctphdr_ok(skb)) {
740: struct sctphdr *sctp = sctp_hdr(skb);
741: key->tp.src = sctp->source;
742: key->tp.dst = sctp->dest;
743: } else {
744: memset(&key->tp, 0, sizeof(key->tp));
745: }
746: } else if (key->ip.proto == IPPROTO_ICMP) {
747: if (icmphdr_ok(skb)) {
748: struct icmphdr *icmp = icmp_hdr(skb);
749: /* The ICMP type and code fields use the 16-bit
750: * transport port fields, so we need to store
751: * them in 16-bit network byte order. */
752: key->tp.src = htons(icmp->type);
753: key->tp.dst = htons(icmp->code);
754: } else {
755: memset(&key->tp, 0, sizeof(key->tp));
756: }
757: }
758:
759: } else if (key->eth.type == htons(ETH_P_ARP) ||
760: key->eth.type == htons(ETH_P_RARP)) {
761: struct arp_eth_header *arp;
762: bool arp_available = arphdr_ok(skb);
763:
764: arp = (struct arp_eth_header *)skb_network_header(skb);
765:
766: if (arp_available &&
767: arp->ar_hrd == htons(ARPHRD_ETHER) &&
768: arp->ar_pro == htons(ETH_P_IP) &&
769: arp->ar_hln == ETH_ALEN &&
770: arp->ar_pln == 4) {
771:
772: /* We only match on the lower 8 bits of the opcode. */
773: if (ntohs(arp->ar_op) <= 0xff)
774: key->ip.proto = ntohs(arp->ar_op);
775: else
776: key->ip.proto = 0;
777:
778: memcpy(&key->ipv4.addr.src, arp->ar_sip, sizeof(key->ipv4.addr.src));
779: memcpy(&key->ipv4.addr.dst, arp->ar_tip, sizeof(key->ipv4.addr.dst));
780: ether_addr_copy(key->ipv4.arp.sha, arp->ar_sha);
781: ether_addr_copy(key->ipv4.arp.tha, arp->ar_tha);
782: } else {
783: memset(&key->ip, 0, sizeof(key->ip));
784: memset(&key->ipv4, 0, sizeof(key->ipv4));
785: }
786: } else if (eth_p_mpls(key->eth.type)) {
787: size_t label_count = 1;
788:
789: memset(&key->mpls, 0, sizeof(key->mpls));
790: skb_set_inner_network_header(skb, skb->mac_len);
791: while (1) {
792: __be32 lse;
793:
794: error = check_header(skb, skb->mac_len +
795: label_count * MPLS_HLEN);
796: if (unlikely(error))
797: return 0;
798:
799: memcpy(&lse, skb_inner_network_header(skb), MPLS_HLEN);
800:
801: if (label_count <= MPLS_LABEL_DEPTH)
802: memcpy(&key->mpls.lse[label_count - 1], &lse,
803: MPLS_HLEN);
804:
805: skb_set_inner_network_header(skb, skb->mac_len +
806: label_count * MPLS_HLEN);
807: if (lse & htonl(MPLS_LS_S_MASK))
808: break;
809:
810: label_count++;
811: }
812: if (label_count > MPLS_LABEL_DEPTH)
813: label_count = MPLS_LABEL_DEPTH;
814:
815: key->mpls.num_labels_mask = GENMASK(label_count - 1, 0);
816: } else if (key->eth.type == htons(ETH_P_IPV6)) {
817: int nh_len; /* IPv6 Header + Extensions */
818:
819: nh_len = parse_ipv6hdr(skb, key);
820: if (unlikely(nh_len < 0)) {
821: switch (nh_len) {
822: case -EINVAL:
823: memset(&key->ip, 0, sizeof(key->ip));
824: memset(&key->ipv6.addr, 0, sizeof(key->ipv6.addr));
825: fallthrough;
826: case -EPROTO:
827: skb->transport_header = skb->network_header;
828: error = 0;
829: break;
830: default:
831: error = nh_len;
832: }
833: return error;
834: }
835:
836: if (key->ip.frag == OVS_FRAG_TYPE_LATER) {
837: memset(&key->tp, 0, sizeof(key->tp));
838: return 0;
839: }
840: if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP)
841: key->ip.frag = OVS_FRAG_TYPE_FIRST;
842:
843: /* Transport layer. */
844: if (key->ip.proto == NEXTHDR_TCP) {
845: if (tcphdr_ok(skb)) {
846: struct tcphdr *tcp = tcp_hdr(skb);
847: key->tp.src = tcp->source;
848: key->tp.dst = tcp->dest;
849: key->tp.flags = TCP_FLAGS_BE16(tcp);
850: } else {
851: memset(&key->tp, 0, sizeof(key->tp));
852: }
853: } else if (key->ip.proto == NEXTHDR_UDP) {
854: if (udphdr_ok(skb)) {
855: struct udphdr *udp = udp_hdr(skb);
856: key->tp.src = udp->source;
857: key->tp.dst = udp->dest;
858: } else {
859: memset(&key->tp, 0, sizeof(key->tp));
860: }
861: } else if (key->ip.proto == NEXTHDR_SCTP) {
862: if (sctphdr_ok(skb)) {
863: struct sctphdr *sctp = sctp_hdr(skb);
864: key->tp.src = sctp->source;
865: key->tp.dst = sctp->dest;
866: } else {
867: memset(&key->tp, 0, sizeof(key->tp));
868: }
869: } else if (key->ip.proto == NEXTHDR_ICMP) {
870: if (icmp6hdr_ok(skb)) {
871: error = parse_icmpv6(skb, key, nh_len);
872: if (error)
873: return error;
874: } else {
875: memset(&key->tp, 0, sizeof(key->tp));
876: }
877: }
878: } else if (key->eth.type == htons(ETH_P_NSH)) {
879: error = parse_nsh(skb, key);
880: if (error)
881: return error;
882: }
883: return 0;
884: }
SourceFile:net/openvswitch/flow.c]
|
| 94/4 |
2026/10/01 02:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 34268
output: 38
thoughts: 58
Thoughts: **My Thought Process Regarding `struct sw_flow_key`**
Right, so I'm examining `struct sw_flow_key`, and the first thing that really jumps out at me is the structure of the `key` field. Specifically, I'm noticing that `key->mpls` is part of a union that also contains `key->ip`, `key->ipv4`, and `key->ipv6`. This immediately tells me that these fields cannot all be populated simultaneously within a single `sw_flow_key` instance. They are mutually exclusive storage locations. My next logical step, therefore, is to dive into the actual struct layout to understand precisely *how* this union is laid out and what the implications are for how different flow key types are represented and accessed. I need to see the byte offsets and sizes to fully grasp the memory footprint and potential aliasing issues.
|
| 95/4 |
2026/10/01 02:10 |
tool |
codesearch-struct-layout |
0m
Args: map[ContextFile:net/openvswitch/flow.h Name:sw_flow_key]
Results: map[Fields:[map[Name:tun_opts OffsetBits:0 SizeBits:2040] map[Name:tun_opts_len OffsetBits:2040 SizeBits:8] map[Name:tun_key OffsetBits:2048 SizeBits:512] map[Name:phy OffsetBits:2560 SizeBits:80] map[Name:mac_proto OffsetBits:2640 SizeBits:8] map[Name:tun_proto OffsetBits:2648 SizeBits:8] map[Name:ovs_flow_hash OffsetBits:2656 SizeBits:32] map[Name:recirc_id OffsetBits:2688 SizeBits:32] map[Name:eth OffsetBits:2720 SizeBits:176] map[Name:ct_state OffsetBits:2896 SizeBits:8] map[Name:ct_orig_proto OffsetBits:2904 SizeBits:8] map[Name: OffsetBits:2912 SizeBits:32] map[Name:ct_zone OffsetBits:2944 SizeBits:16] map[Name:tp OffsetBits:2960 SizeBits:48] map[Name: OffsetBits:3008 SizeBits:576] map[Name:ct OffsetBits:3584 SizeBits:192]]]
|
| 96/4 |
2026/10/01 02:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 34580
output: 36
thoughts: 43
Thoughts: **My Thought Process on `sw_flow_key` Structure Analysis**
Alright, let's dive into this. My first instinct is to get a solid grasp on the fundamental data structure I'll be working with: `struct sw_flow_key`. I know I need to understand its layout and purpose thoroughly, as it's central to how Open vSwitch handles flow matching.
So, my immediate action is to locate the definition of `struct sw_flow_key` within the `net/openvswitch/flow.h` header file. I'm not just going to skim it; I want to read around lines 80 to 140. This range is often where core data structures are defined, and I want to ensure I'm not missing any relevant fields or context that might be declared immediately before or after the primary definition.
As I read, I'll be looking for several key things:
* **Field Definitions:** What are the individual members of this structure? What are their types (integers, pointers, bitfields, arrays, etc.)? This will tell me what kind of information is being stored to represent a flow.
* **Purpose of Each Field:** For each field, I'll be trying to infer its role in the flow key. Is it representing a packet header field (like an IP address, port number, MAC address)? Is it metadata generated by the switch (like VLAN tags, tunnel IDs)? Or is it something else entirely?
* **Data Encoding:** How is the data within these fields encoded? For instance, are IP addresses stored as 32-bit or 128-bit integers? Are port numbers represented directly or through a bitmask? Are there any fields that use bitfields, which can be a source of complexity and potential confusion if not understood correctly?
* **Alignment and Padding:** While less critical for a high-level understanding, I'll be aware that the compiler might introduce padding for alignment. This is generally transparent, but understanding the overall size and structure can be helpful.
* **Relationships to Other Structures/Constants:** Are there any constants or other structures referenced within the `sw_flow_key` definition? This might point to external definitions or common representations of data.
* **Potential for Wildcards:** Given that this is a "flow key," I'm specifically looking for indicators that allow for wildcarding or don't-care values. This is crucial for understanding how flow rules are constructed and matched against actual packets.
My goal here is to build a mental model of `sw_flow_key`. I want to be able to visualize what a specific flow key looks like in memory and understand how its components map directly to observable packet or switch properties. This detailed examination is the bedrock for any further analysis or modification of Open vSwitch's flow handling logic.
|
| 97/4 |
2026/10/01 02:10 |
tool |
read-file |
0m
Args: map[File:net/openvswitch/flow.h FirstLine:80 LineCount:65]
Results: map[Contents: 80: u32 priority; /* Packet QoS priority. */
81: u32 skb_mark; /* SKB mark. */
82: u16 in_port; /* Input switch port (or DP_MAX_PORTS). */
83: } __packed phy; /* Safe when right after 'tun_key'. */
84: u8 mac_proto; /* MAC layer protocol (e.g. Ethernet). */
85: u8 tun_proto; /* Protocol of encapsulating tunnel. */
86: u32 ovs_flow_hash; /* Datapath computed hash value. */
87: u32 recirc_id; /* Recirculation ID. */
88: struct {
89: u8 src[ETH_ALEN]; /* Ethernet source address. */
90: u8 dst[ETH_ALEN]; /* Ethernet destination address. */
91: struct vlan_head vlan;
92: struct vlan_head cvlan;
93: __be16 type; /* Ethernet frame type. */
94: } eth;
95: /* Filling a hole of two bytes. */
96: u8 ct_state;
97: u8 ct_orig_proto; /* CT original direction tuple IP
98: * protocol.
99: */
100: union {
101: struct {
102: u8 proto; /* IP protocol or lower 8 bits of ARP opcode. */
103: u8 tos; /* IP ToS. */
104: u8 ttl; /* IP TTL/hop limit. */
105: u8 frag; /* One of OVS_FRAG_TYPE_*. */
106: } ip;
107: };
108: u16 ct_zone; /* Conntrack zone. */
109: struct {
110: __be16 src; /* TCP/UDP/SCTP source port. */
111: __be16 dst; /* TCP/UDP/SCTP destination port. */
112: __be16 flags; /* TCP flags. */
113: } tp;
114: union {
115: struct {
116: struct {
117: __be32 src; /* IP source address. */
118: __be32 dst; /* IP destination address. */
119: } addr;
120: union {
121: struct {
122: __be32 src;
123: __be32 dst;
124: } ct_orig; /* Conntrack original direction fields. */
125: struct {
126: u8 sha[ETH_ALEN]; /* ARP source hardware address. */
127: u8 tha[ETH_ALEN]; /* ARP target hardware address. */
128: } arp;
129: };
130: } ipv4;
131: struct {
132: struct {
133: struct in6_addr src; /* IPv6 source address. */
134: struct in6_addr dst; /* IPv6 destination address. */
135: } addr;
136: __be32 label; /* IPv6 flow label. */
137: u16 exthdrs; /* IPv6 extension header flags */
138: union {
139: struct {
140: struct in6_addr src;
141: struct in6_addr dst;
142: } ct_orig; /* Conntrack original direction fields. */
143: struct {
144: struct in6_addr target; /* ND target address. */
]
|
| 98/4 |
2026/10/01 02:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 35700
output: 37
thoughts: 20
Thoughts: **My Thought Process for Analyzing `flow.h`**
Alright, as an expert in this domain, my initial instinct upon encountering a code snippet like this is to get a handle on its overall purpose and context. The request specifically points to lines 145-165 in `flow.h`, so that's where I'm going to direct my immediate attention. I'm not just looking for a superficial understanding; I need to grasp the *intent* behind these lines and how they contribute to the larger `flow.h` functionality.
My first step is to mentally, or perhaps even by physically scanning, identify the core elements within that specific range. What are the keywords? Are there function calls, variable declarations, conditional statements, or perhaps data structure manipulations? I'm trying to build a mental model of what's happening at a high level within these lines.
Then, I'll start to break it down line by line, or in logical blocks. For each line or block, I'm asking myself:
* **What is this doing?** Is it assigning a value, performing a calculation, checking a condition, or invoking a subroutine?
* **Why is it doing it?** What problem is this code solving, or what state is it trying to achieve or maintain? This is where my domain expertise really kicks in. I'll be drawing on my knowledge of common patterns, algorithms, and potential pitfalls within this specific area of programming.
* **What are the inputs and outputs?** What information is being used, and what is being produced or modified? This helps me trace data flow.
* **Are there any dependencies?** Does this code rely on other parts of `flow.h`, or even other files? Understanding these connections is crucial for a holistic view.
Specifically for lines 145-165, I'm looking for any operations related to the "flow" itself – whatever that represents in this context. Is it a data flow, a control flow, a network flow? The name `flow.h` is a strong hint, so I'll be hyper-aware of anything that modifies, processes, or inspects this "flow."
I'll also be scrutinizing these lines for potential issues or areas of interest that a seasoned professional would spot. This includes:
* **Efficiency:** Is there a more optimal way to achieve the same result? Are there any redundant operations?
* **Clarity and Readability:** Is the code easy to understand for someone else (or for myself in the future)? Are variable names descriptive? Is the logic straightforward?
* **Robustness:** Does the code handle edge cases or unexpected inputs gracefully? Are there any potential for errors, overflows, or memory leaks?
* **Maintainability:** Is this code structured in a way that will be easy to modify or extend later?
In essence, I'm not just reading the code; I'm *interpreting* it through the lens of my experience. I'm trying to reverse-engineer the designer's intent, anticipate potential problems, and evaluate the quality of the implementation. The goal is to build a comprehensive understanding that goes beyond mere syntax, allowing me to discuss it with nuance and insight, as an expert would.
|
| 99/4 |
2026/10/01 02:10 |
tool |
read-file |
0m
Args: map[File:net/openvswitch/flow.h FirstLine:145 LineCount:25]
Results: map[Contents: 145: u8 sll[ETH_ALEN]; /* ND source link layer address. */
146: u8 tll[ETH_ALEN]; /* ND target link layer address. */
147: } nd;
148: };
149: } ipv6;
150: struct {
151: u32 num_labels_mask; /* labels present bitmap of effective length MPLS_LABEL_DEPTH */
152: __be32 lse[MPLS_LABEL_DEPTH]; /* label stack entry */
153: } mpls;
154:
155: struct ovs_key_nsh nsh; /* network service header */
156: };
157: struct {
158: /* Connection tracking fields not packed above. */
159: struct {
160: __be16 src; /* CT orig tuple tp src port. */
161: __be16 dst; /* CT orig tuple tp dst port. */
162: } orig_tp;
163: u32 mark;
164: struct ovs_key_ct_labels labels;
165: } ct;
166:
167: } __aligned(BITS_PER_LONG/8); /* Ensure that we can do comparisons as longs. */
168:
169: static inline bool sw_flow_key_is_nd(const struct sw_flow_key *key)
]
|
| 100/4 |
2026/10/01 02:10 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 36159
output: 30
thoughts: 1166
Thoughts: **A Deep Dive into the Nuances of MPLS Popping and IPv6 Handling in OVS Datapath**
I've been meticulously examining the Open vSwitch datapath, specifically focusing on how MPLS packets are processed and how subsequent actions interact with the underlying L3 headers. My initial observation, which has led me down this rabbit hole, concerns the `sw_flow_key` structure. I noticed that `ipv4`, `ipv6`, `mpls`, and `nsh` are all part of the same union, defined at line 114. This immediately raised a flag for me.
Then, I considered the packet parsing stage, specifically within the `key_extract_l3l4` function. My analysis revealed that when a packet is identified as MPLS (checked by `eth_p_mpls(key->eth.type)`), only the `key->mpls` field is populated. Crucially, the IPv6 header (`key->ipv6`) isn't parsed, nor is its validity or bounds checked at this point. This lack of pre-parsing for the IPv6 header, should it be the next layer, feels like a potential vulnerability.
My concerns were further amplified when I looked at the datapath action execution, particularly within `do_execute_actions` and the `pop_mpls` function in `actions.c`. When an `OVS_ACTION_ATTR_POP_MPLS` action is executed, the MPLS header is indeed popped from the `skb`. If, after this pop, the packet now contains an IPv6 packet, the datapath might attempt to modify IPv6 headers without re-parsing or recirculation. This is problematic because the kernel datapath hasn't yet verified the packet length, header validity, or other critical parameters of the newly exposed IPv6 header. The potential for accessing invalid memory or corrupting data is significant.
I then remembered a comment within `__ovs_nla_copy_actions` that precisely addresses this very rationale. It states:
```c
/* Disallow subsequent L2.5+ set actions and mpls_pop
* actions once the last MPLS label in the packet is
* popped as there is no check here to ensure that
* the new eth type is valid and thus set actions could
* write off the end of the packet or otherwise corrupt
* it.
*
* Support for these actions is planned using packet
* recirculation.
*/
```
This comment directly corroborates my suspicion. It also hints at how OVS enforces this safety mechanism. My investigation revealed that the enforcement happens by resetting the `eth_type` to `htons(0)` within `__ovs_nla_copy_actions`:
```c
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
```
Here's how I understand the logic: when `POP_MPLS` is invoked, the `proto` argument represents the inner protocol specified (e.g., `ETH_P_IPV6` or another MPLS protocol). If this `proto` is *not* MPLS (e.g., it's `ETH_P_IPV6`), the condition `!eth_p_mpls(proto)` becomes true. Similarly, if `!mpls_label_count` is true, meaning the last MPLS label has been popped, the condition also becomes true. In either of these scenarios, `eth_type` is set to `htons(0)`. It's important to note that even if `eth_p_mpls(proto)` were true and `mpls_label_count > 0`, `eth_type` would be set to `proto` (which would be an MPLS ethertype), *not* `htons(ETH_P_IPV6)`.
Subsequently, when the next action in the action list is processed by `__ovs_nla_copy_actions`: if that next action is an `OVS_ACTION_ATTR_SET` or `OVS_ACTION_ATTR_SET_MASKED` targeting the `OVS_KEY_ATTR_IPV6` type, the `validate_set()` function is called. Inside `validate_set`, there's a critical check:
```c
case OVS_KEY_ATTR_IPV6: {
const struct ovs_key_ipv6 *ipv6_key;
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
Because `eth_type` has been reset to `htons(0)` (or an MPLS ethertype) after the `POP_MPLS` action, the condition `eth_type != htons(ETH_P_IPV6)` evaluates to true. Consequently, `validate_set()` returns `-EINVAL`, and this error is propagated up through `__ovs_nla_copy_actions`, causing the validation to fail. This mechanism effectively prevents a `SET_IPV6` action from being applied directly after `POP_MPLS` if the inner protocol isn't MPLS.
I also briefly considered whether other actions like `clone`, `sample`, or `check_pkt_len` might bypass this validation. My review of `validate_and_copy_sample`, `validate_and_copy_clone`, and `validate_and_copy_check_pkt_len` indicates that they all pass the `eth_type` through to nested calls of `__ovs_nla_copy_actions`. Therefore, if `POP_MPLS` precedes them, `eth_type` will still be `htons(0)`.
This leads me to wonder about the userspace OVS handling of `pop_mpls` followed by `set_ipv6` fields. My understanding is that userspace OVS is designed to insert a `recirc(...)` action immediately after `pop_mpls` if subsequent actions require access to the inner L3/L4 fields. I intend to verify this by examining userspace OVS logic and searching through git commit messages for relevant discussions or changes.
|
| 101/4 |
2026/10/01 02:10 |
tool |
git-log |
0m
Args: map[Count:5 MessageRegexps:[pop_mpls recirc]]
Results: map[Output:040b5cfbcefa Fixed updating of ethertype in function skb_mpls_pop
]
|
| 102/4 |
2026/10/01 02:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 37375
output: 24
thoughts: 16
Thoughts: **My Thought Process on Commit 040b5cfbcefa**
Alright, let's dive into commit 040b5cfbcefa. My initial instinct is to understand the core change this commit introduces. What problem is it trying to solve, or what functionality is it adding/modifying? I'll be looking for the "why" behind this change, as that's crucial for any expert in our field.
Then, I'll dissect the actual code modifications. I'll pay close attention to the diff: what lines were added, removed, or changed? I'm particularly interested in the *nature* of these changes. Are we talking about a subtle refactor, a significant architectural shift, a bug fix, or the implementation of a new feature?
From there, I'll be thinking about the potential impact. What are the ripple effects of this commit? Does it introduce any new dependencies? Does it alter the existing API or interfaces in a way that might affect other parts of the system or downstream users? Given my expertise, I'll be considering things like performance implications, security vulnerabilities, and maintainability.
I'll also be considering the quality of the commit itself. Is the commit message clear and informative? Does it adequately explain the context and the solution? Are the code changes well-commented and readable? This reflects the overall craftsmanship and professionalism I expect in our domain.
Finally, I'll be forming an opinion on whether this commit represents a positive step forward. Does it align with our project's goals and architectural principles? Is it well-designed and robust? My goal is to have a comprehensive understanding of the commit's purpose, implementation, and implications, allowing me to assess its value and potential risks.
|
| 103/4 |
2026/10/01 02:11 |
tool |
git-show |
0m
Args:
Results: map[Output:commit 040b5cfbcefa263ccf2c118c4938308606bb7ed8
Author: Martin Varghese <martin.varghese@nokia.com>
Date: Mon Dec 2 10:49:51 2019 +0530
Fixed updating of ethertype in function skb_mpls_pop
The skb_mpls_pop was not updating ethertype of an ethernet packet if the
packet was originally received from a non ARPHRD_ETHER device.
In the below OVS data path flow, since the device corresponding to port 7
is an l3 device (ARPHRD_NONE) the skb_mpls_pop function does not update
the ethertype of the packet even though the previous push_eth action had
added an ethernet header to the packet.
recirc_id(0),in_port(7),eth_type(0x8847),
mpls(label=12/0xfffff,tc=0/0,ttl=0/0x0,bos=1/1),
actions:push_eth(src=00:00:00:00:00:00,dst=00:00:00:00:00:00),
pop_mpls(eth_type=0x800),4
Fixes: ed246cee09b9 ("net: core: move pop MPLS functionality from OvS to core helper")
Signed-off-by: Martin Varghese <martin.varghese@nokia.com>
Acked-by: Pravin B Shelar <pshelar@ovn.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 7af5bec7d3b0..5aea72fe8498 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -3530,7 +3530,8 @@ int skb_vlan_pop(struct sk_buff *skb);
int skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci);
int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto,
int mac_len);
-int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len);
+int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
+ bool ethernet);
int skb_mpls_update_lse(struct sk_buff *skb, __be32 mpls_lse);
int skb_mpls_dec_ttl(struct sk_buff *skb);
struct sk_buff *pskb_extract(struct sk_buff *skb, int off, int to_copy,
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 867e61df00db..312e80e86898 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -5529,12 +5529,14 @@ EXPORT_SYMBOL_GPL(skb_mpls_push);
* @skb: buffer
* @next_proto: ethertype of header after popped MPLS header
* @mac_len: length of the MAC header
+ * @ethernet: flag to indicate if ethernet header is present in packet
*
* Expects skb->data at mac header.
*
* Returns 0 on success, -errno otherwise.
*/
-int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len)
+int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len,
+ bool ethernet)
{
int err;
@@ -5553,7 +5555,7 @@ int skb_mpls_pop(struct sk_buff *skb, __be16 next_proto, int mac_len)
skb_reset_mac_header(skb);
skb_set_network_header(skb, mac_len);
- if (skb->dev && skb->dev->type == ARPHRD_ETHER) {
+ if (ethernet) {
struct ethhdr *hdr;
/* use mpls_hdr() to get ethertype to account for VLANs. */
diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c
index 12936c151cc0..91e210061bb3 100644
--- a/net/openvswitch/actions.c
+++ b/net/openvswitch/actions.c
@@ -179,7 +179,8 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key,
{
int err;
- err = skb_mpls_pop(skb, ethertype, skb->mac_len);
+ err = skb_mpls_pop(skb, ethertype, skb->mac_len,
+ ovs_key_mac_proto(key) == MAC_PROTO_ETHERNET);
if (err)
return err;
diff --git a/net/sched/act_mpls.c b/net/sched/act_mpls.c
index 325eddcc6621..a7d856203af1 100644
--- a/net/sched/act_mpls.c
+++ b/net/sched/act_mpls.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
/* Copyright (C) 2019 Netronome Systems, Inc. */
+#include <linux/if_arp.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
@@ -76,7 +77,8 @@ static int tcf_mpls_act(struct sk_buff *skb, const struct tc_action *a,
switch (p->tcfm_action) {
case TCA_MPLS_ACT_POP:
- if (skb_mpls_pop(skb, p->tcfm_proto, mac_len))
+ if (skb_mpls_pop(skb, p->tcfm_proto, mac_len,
+ skb->dev && skb->dev->type == ARPHRD_ETHER))
goto drop;
break;
case TCA_MPLS_ACT_PUSH:
]
|
| 104/4 |
2026/10/01 02:11 |
llm |
codeexpert |
0m
Model:
Tokens:
input: 39208
output: 668
thoughts: 1333
Thoughts: **My Thought Process Regarding `OVS_ACTION_ATTR_POP_MPLS` and Subsequent `OVS_ACTION_ATTR_SET` Actions**
Okay, I've been digging into the Open vSwitch code, specifically within `net/openvswitch/flow_netlink.c`, to understand the validation logic for Netlink actions, and I've focused on the `__ovs_nla_copy_actions` function.
My goal was to trace the execution path when dealing with `OVS_ACTION_ATTR_POP_MPLS` and to see what happens if a subsequent `OVS_ACTION_ATTR_SET` action targets an IPv6 key.
Here's how I see the flow unfolding based on my analysis:
1. **Entry Point:** The process begins when `__ovs_nla_copy_actions` is invoked to validate a list of Netlink actions. This is where the core logic resides for parsing and checking these actions.
2. **Iterating Through Actions:** Inside `__ovs_nla_copy_actions`, I observe a loop mechanism, specifically `nla_for_each_nested(a, attr, rem)`, which is used to iterate through the individual actions provided in the Netlink attributes.
3. **Handling `OVS_ACTION_ATTR_POP_MPLS`:** When the loop encounters an action of type `OVS_ACTION_ATTR_POP_MPLS`, a specific block of code (lines 3418-3448) is executed.
* My initial check is for `vlan_tci` and `eth_p_mpls(eth_type)`. If these conditions aren't met, it's an immediate `EINVAL`.
* The crucial part here is the comment explaining *why* certain subsequent actions are disallowed. It explicitly states that after popping the last MPLS label, there's no check to ensure the *new* ethertype is valid. This could lead to security issues like writing past the end of the packet or corrupting data. The plan is to handle this via packet recirculation later.
* Then, the protocol (`proto`) is retrieved using `nla_get_be16(a)`.
* There's a specific check: if `proto` is `ETH_P_TEB` (Ethernet Bridging Protocol) and `mac_proto` is not `MAC_PROTO_NONE`, it's rejected with `EINVAL`.
* The `mpls_label_count` is decremented.
* Now, the core of what I was looking for: `eth_type` is updated. If the popped protocol is *not* an MPLS ethertype (`!eth_p_mpls(proto)`) OR if there are no more MPLS labels left (`!mpls_label_count`), then `eth_type` is explicitly set to `htons(0)`. Otherwise, `eth_type` is updated to the `proto` of the next layer. This is a key observation: `eth_type` can become `htons(0)` if the last MPLS label is popped, indicating that the packet's immediate next layer is no longer an MPLS ethertype.
4. **Processing the Next Action (`OVS_ACTION_ATTR_SET`):** The loop continues to the next action. If this action happens to be `OVS_ACTION_ATTR_SET` (or `OVS_ACTION_ATTR_SET_MASKED`) and it targets `OVS_KEY_ATTR_IPV6`, the `validate_set` function is called. My analysis confirms that `validate_set` is called with the *current* value of `eth_type`, which might have been set to `htons(0)` in the previous `POP_MPLS` step.
5. **`validate_set` Logic:** I then examined the `validate_set` function (lines 2991-3020). Within its `case OVS_KEY_ATTR_IPV6:` block, I found this critical check:
```c
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
This is a direct validation. If the `eth_type` passed to `validate_set` is not exactly `htons(ETH_P_IPV6)`, the function returns `-EINVAL`.
6. **Propagating the Error:** Back in `__ovs_nla_copy_actions`, when `validate_set` returns `err` (which is `-EINVAL` in this scenario), the `case OVS_ACTION_ATTR_SET:` block handles it:
```c
err = validate_set(a, key, sfa,
&skip_copy, mac_proto, eth_type,
false, log);
if (err)
return err;
```
Since `err` is indeed `-EINVAL`, the `__ovs_nla_copy_actions` function immediately returns this error.
7. **The "Why":** The code comments I noted earlier explain the rationale behind this behavior perfectly. The design explicitly prevents immediate L3 modifications (like `SET_IPV6`) right after popping the last MPLS label without intermediate packet recirculation. The reasoning is that the packet's headers haven't been re-parsed, and blindly applying an L3 modification could be unsafe. The intended workflow is to pop MPLS, then recirculate the packet (`OVS_ACTION_ATTR_RECIRC`). Upon recirculation, the packet's headers (including the new ethertype) are re-evaluated, and *then* a `SET_IPV6` action can be safely applied in a subsequent flow table match.
In conclusion, my understanding is that yes, a `POP_MPLS` action that results in `eth_type` being set to `htons(0)` (or any value other than `htons(ETH_P_IPV6)`) followed by a `SET_IPV6` action *will* be rejected during validation by Open vSwitch due to this explicit check in `validate_set`. This is a deliberate design choice to ensure packet integrity and security in scenarios involving MPLS encapsulation. My analysis aligns perfectly with the source code and the documented intent.
|
| 105/4 |
2026/10/01 02:11 |
tool |
set-results |
0m
Args: map[Answer:Yes, a `POP_MPLS` action followed directly by a `SET_IPV6` action (or any other L3/L4 `SET` action) in the same action list will be rejected with `-EINVAL` during validation in `__ovs_nla_copy_actions`.
### Why this happens:
1. **Resetting `eth_type`:** In `__ovs_nla_copy_actions()` (`net/openvswitch/flow_netlink.c`), when processing `OVS_ACTION_ATTR_POP_MPLS`:
```c
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
```
If the inner protocol `proto` is IPv6 (`ETH_P_IPV6`), `!eth_p_mpls(proto)` evaluates to true (and/or `mpls_label_count` reaches 0), so `eth_type` is set to `htons(0)`. (Even if more MPLS labels remained, `eth_type` would be set to an MPLS ethertype, never `ETH_P_IPV6`).
2. **Validation failure:** When the subsequent `OVS_ACTION_ATTR_SET` (or `OVS_ACTION_ATTR_SET_MASKED`) with `OVS_KEY_ATTR_IPV6` is processed, `validate_set()` is invoked with `eth_type`:
```c
case OVS_KEY_ATTR_IPV6: {
...
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
Because `eth_type` is `htons(0)`, the check `eth_type != htons(ETH_P_IPV6)` is true, causing `validate_set()` to return `-EINVAL`, which fails action validation.
### Rationale and Intended Workflow:
This rejection is intentional. As the inline comment in `__ovs_nla_copy_actions()` notes:
> *"Disallow subsequent L2.5+ set actions and mpls_pop actions once the last MPLS label in the packet is popped as there is no check here to ensure that the new eth type is valid and thus set actions could write off the end of the packet or otherwise corrupt it. Support for these actions is planned using packet recirculation."*
Because the kernel datapath only extracted and verified the MPLS label stack during initial packet classification, modifying L3/L4 fields without re-parsing could access invalid packet offsets or corrupt memory. To modify IPv6 fields after popping MPLS, the action list must use recirculation (`OVS_ACTION_ATTR_RECIRC`) after `POP_MPLS`, allowing the kernel datapath to re-parse the inner IPv6 packet before applying the `SET_IPV6` action in the next flow.]
Results: map[Answer:Yes, a `POP_MPLS` action followed directly by a `SET_IPV6` action (or any other L3/L4 `SET` action) in the same action list will be rejected with `-EINVAL` during validation in `__ovs_nla_copy_actions`.
### Why this happens:
1. **Resetting `eth_type`:** In `__ovs_nla_copy_actions()` (`net/openvswitch/flow_netlink.c`), when processing `OVS_ACTION_ATTR_POP_MPLS`:
```c
mpls_label_count--;
if (!eth_p_mpls(proto) || !mpls_label_count)
eth_type = htons(0);
else
eth_type = proto;
```
If the inner protocol `proto` is IPv6 (`ETH_P_IPV6`), `!eth_p_mpls(proto)` evaluates to true (and/or `mpls_label_count` reaches 0), so `eth_type` is set to `htons(0)`. (Even if more MPLS labels remained, `eth_type` would be set to an MPLS ethertype, never `ETH_P_IPV6`).
2. **Validation failure:** When the subsequent `OVS_ACTION_ATTR_SET` (or `OVS_ACTION_ATTR_SET_MASKED`) with `OVS_KEY_ATTR_IPV6` is processed, `validate_set()` is invoked with `eth_type`:
```c
case OVS_KEY_ATTR_IPV6: {
...
if (eth_type != htons(ETH_P_IPV6))
return -EINVAL;
```
Because `eth_type` is `htons(0)`, the check `eth_type != htons(ETH_P_IPV6)` is true, causing `validate_set()` to return `-EINVAL`, which fails action validation.
### Rationale and Intended Workflow:
This rejection is intentional. As the inline comment in `__ovs_nla_copy_actions()` notes:
> *"Disallow subsequent L2.5+ set actions and mpls_pop actions once the last MPLS label in the packet is popped as there is no check here to ensure that the new eth type is valid and thus set actions could write off the end of the packet or otherwise corrupt it. Support for these actions is planned using packet recirculation."*
Because the kernel datapath only extracted and verified the MPLS label stack during initial packet classification, modifying L3/L4 fields without re-parsing could access invalid packet offsets or corrupt memory. To modify IPv6 fields after popping MPLS, the action list must use recirculation (`OVS_ACTION_ATTR_RECIRC`) after `POP_MPLS`, allowing the kernel datapath to re-parse the inner IPv6 packet before applying the `SET_IPV6` action in the next flow.]
|
| 106/2 |
2026/10/01 02:11 |
llm |
expert |
0m
Model:
Tokens:
input: 53851
output: 47
thoughts: 1034
Thoughts: **My Thought Process on the syzbot Reproducer and the POP_MPLS/SET_IPV6 Rejection**
This is rather perplexing. I've just observed that the sequence `POP_MPLS` followed by `SET_IPV6` is being REJECTED. This immediately raises a significant question in my mind: if this combination is disallowed, how could the syzbot reproducer possibly trigger it? My expertise demands I get to the bottom of this apparent contradiction.
My first step, naturally, is to meticulously examine the syzbot reproducer itself. I'm pulling it up and scanning its structure, looking for any clues that might explain this anomaly. I see the reproducer is constructing a `sendmsg` call targeting `sock_nl_generic` with a `netlink_msg_t` payload. This payload contains a `netlink_random_msg_type`, a `genlmsghdr`, and a series of `nl_generic_attr`. The critical part I'm focusing on is the `ANYBLOB` section, specifically the raw buffer data it contains.
As I dissect this `ANYBLOB`, my attention is drawn to the `OVS_PACKET_CMD_EXECUTE` command within the Netlink message. This command is designed for packet execution within the Open vSwitch kernel module. I recall that `OVS_PACKET_CMD_EXECUTE` expects specific attributes: `OVS_PACKET_ATTR_PACKET`, `OVS_PACKET_ATTR_KEY`, and `OVS_PACKET_ATTR_ACTIONS`.
Now, I'm zeroing in on how the `OVS_PACKET_ATTR_KEY` is handled. My knowledge tells me that `ovs_packet_cmd_execute` internally calls `ovs_flow_key_extract_userspace` to parse this `OVS_PACKET_ATTR_KEY`. This is where I anticipate finding the logic that might be leading to the rejection.
I then revisit the `ovs_flow_key_extract_userspace` function, scrutinizing its execution flow. I see it first calls `parse_flow_nlattrs` to process the flow key attributes. Following that, it invokes `ovs_nla_get_flow_metadata` to extract metadata. Finally, it uses `key_extract` to finalize the key construction, setting `skb->protocol` based on `key->eth.type`.
This is where the confusion deepens. I'm questioning how `ovs_flow_key_extract_userspace` uses `key->eth.type` from the METADATA. My understanding is that `ovs_nla_get_flow_metadata` is responsible for extracting *metadata* such as `in_port` and `skb_mark`, not the Ethernet type. The Ethernet type is typically derived from the packet data itself or a more direct flow key field.
Then, a crucial thought strikes me: `parse_flow_nlattrs` is the function that actually parses the `OVS_PACKET_ATTR_KEY`, which *is* the flow key. This is a critical distinction. My initial assumption that `ovs_nla_get_flow_metadata` was involved in extracting the Ethernet type might be misplaced. The real parsing of the flow key, where the Ethernet type would be determined and potentially lead to the `POP_MPLS` and `SET_IPV6` conflict, likely happens within `parse_flow_nlattrs`. My next step must be to examine the behavior of `ovs_nla_get_flow_metadata` more closely, to confirm what information it truly provides and how it interacts with the overall flow key construction.
|
| 107/2 |
2026/10/01 02:12 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:ovs_nla_get_flow_metadata]
Results: map[SourceCode:1927: int ovs_nla_get_flow_metadata(struct net *net,
1928: const struct nlattr *a[OVS_KEY_ATTR_MAX + 1],
1929: u64 attrs, struct sw_flow_key *key, bool log)
1930: {
1931: struct sw_flow_match match;
1932:
1933: memset(&match, 0, sizeof(match));
1934: match.key = key;
1935:
1936: key->ct_state = 0;
1937: key->ct_zone = 0;
1938: key->ct_orig_proto = 0;
1939: memset(&key->ct, 0, sizeof(key->ct));
1940: memset(&key->ipv4.ct_orig, 0, sizeof(key->ipv4.ct_orig));
1941: memset(&key->ipv6.ct_orig, 0, sizeof(key->ipv6.ct_orig));
1942:
1943: key->phy.in_port = DP_MAX_PORTS;
1944:
1945: return metadata_from_nlattrs(net, &match, &attrs, a, false, log);
1946: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 108/2 |
2026/10/01 02:12 |
llm |
expert |
0m
Model:
Tokens:
input: 55300
output: 42
thoughts: 12
Thoughts: **A Deep Dive into `metadata_from_nlattrs`**
Right, so I'm thinking about how we're handling metadata extraction. My immediate focus is on this specific function, `metadata_from_nlattrs`. I need to really dig into its current implementation and understand its role within the broader system. I'm going to be scrutinizing the code itself, looking at how it takes natural language attributes (nlattrs) as input and what kind of metadata it's designed to output. My goal here is to get a comprehensive grasp of its logic, any potential inefficiencies, and whether it's truly fulfilling its intended purpose. This isn't just a cursory glance; I'm aiming for a thorough understanding of its mechanics, the data transformations it performs, and its dependencies.
|
| 109/2 |
2026/10/01 02:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:metadata_from_nlattrs]
Results: map[SourceCode:1170: static int metadata_from_nlattrs(struct net *net, struct sw_flow_match *match,
1171: u64 *attrs, const struct nlattr **a,
1172: bool is_mask, bool log)
1173: {
1174: u8 mac_proto = MAC_PROTO_ETHERNET;
1175:
1176: if (*attrs & (1 << OVS_KEY_ATTR_DP_HASH)) {
1177: u32 hash_val = nla_get_u32(a[OVS_KEY_ATTR_DP_HASH]);
1178:
1179: SW_FLOW_KEY_PUT(match, ovs_flow_hash, hash_val, is_mask);
1180: *attrs &= ~(1 << OVS_KEY_ATTR_DP_HASH);
1181: }
1182:
1183: if (*attrs & (1 << OVS_KEY_ATTR_RECIRC_ID)) {
1184: u32 recirc_id = nla_get_u32(a[OVS_KEY_ATTR_RECIRC_ID]);
1185:
1186: SW_FLOW_KEY_PUT(match, recirc_id, recirc_id, is_mask);
1187: *attrs &= ~(1 << OVS_KEY_ATTR_RECIRC_ID);
1188: }
1189:
1190: if (*attrs & (1 << OVS_KEY_ATTR_PRIORITY)) {
1191: SW_FLOW_KEY_PUT(match, phy.priority,
1192: nla_get_u32(a[OVS_KEY_ATTR_PRIORITY]), is_mask);
1193: *attrs &= ~(1 << OVS_KEY_ATTR_PRIORITY);
1194: }
1195:
1196: if (*attrs & (1 << OVS_KEY_ATTR_IN_PORT)) {
1197: u32 in_port = nla_get_u32(a[OVS_KEY_ATTR_IN_PORT]);
1198:
1199: if (is_mask) {
1200: in_port = 0xffffffff; /* Always exact match in_port. */
1201: } else if (in_port >= DP_MAX_PORTS) {
1202: OVS_NLERR(log, "Port %d exceeds max allowable %d",
1203: in_port, DP_MAX_PORTS);
1204: return -EINVAL;
1205: }
1206:
1207: SW_FLOW_KEY_PUT(match, phy.in_port, in_port, is_mask);
1208: *attrs &= ~(1 << OVS_KEY_ATTR_IN_PORT);
1209: } else if (!is_mask) {
1210: SW_FLOW_KEY_PUT(match, phy.in_port, DP_MAX_PORTS, is_mask);
1211: }
1212:
1213: if (*attrs & (1 << OVS_KEY_ATTR_SKB_MARK)) {
1214: uint32_t mark = nla_get_u32(a[OVS_KEY_ATTR_SKB_MARK]);
1215:
1216: SW_FLOW_KEY_PUT(match, phy.skb_mark, mark, is_mask);
1217: *attrs &= ~(1 << OVS_KEY_ATTR_SKB_MARK);
1218: }
1219: if (*attrs & (1 << OVS_KEY_ATTR_TUNNEL)) {
1220: if (ip_tun_from_nlattr(a[OVS_KEY_ATTR_TUNNEL], match,
1221: is_mask, log) < 0)
1222: return -EINVAL;
1223: *attrs &= ~(1 << OVS_KEY_ATTR_TUNNEL);
1224: }
1225:
1226: if (*attrs & (1 << OVS_KEY_ATTR_CT_STATE) &&
1227: ovs_ct_verify(net, OVS_KEY_ATTR_CT_STATE)) {
1228: u32 ct_state = nla_get_u32(a[OVS_KEY_ATTR_CT_STATE]);
1229:
1230: if (ct_state & ~CT_SUPPORTED_MASK) {
1231: OVS_NLERR(log, "ct_state flags %08x unsupported",
1232: ct_state);
1233: return -EINVAL;
1234: }
1235:
1236: SW_FLOW_KEY_PUT(match, ct_state, ct_state, is_mask);
1237: *attrs &= ~(1ULL << OVS_KEY_ATTR_CT_STATE);
1238: }
1239: if (*attrs & (1 << OVS_KEY_ATTR_CT_ZONE) &&
1240: ovs_ct_verify(net, OVS_KEY_ATTR_CT_ZONE)) {
1241: u16 ct_zone = nla_get_u16(a[OVS_KEY_ATTR_CT_ZONE]);
1242:
1243: SW_FLOW_KEY_PUT(match, ct_zone, ct_zone, is_mask);
1244: *attrs &= ~(1ULL << OVS_KEY_ATTR_CT_ZONE);
1245: }
1246: if (*attrs & (1 << OVS_KEY_ATTR_CT_MARK) &&
1247: ovs_ct_verify(net, OVS_KEY_ATTR_CT_MARK)) {
1248: u32 mark = nla_get_u32(a[OVS_KEY_ATTR_CT_MARK]);
1249:
1250: SW_FLOW_KEY_PUT(match, ct.mark, mark, is_mask);
1251: *attrs &= ~(1ULL << OVS_KEY_ATTR_CT_MARK);
1252: }
1253: if (*attrs & (1 << OVS_KEY_ATTR_CT_LABELS) &&
1254: ovs_ct_verify(net, OVS_KEY_ATTR_CT_LABELS)) {
1255: const struct ovs_key_ct_labels *cl;
1256:
1257: cl = nla_data(a[OVS_KEY_ATTR_CT_LABELS]);
1258: SW_FLOW_KEY_MEMCPY(match, ct.labels, cl->ct_labels,
1259: sizeof(*cl), is_mask);
1260: *attrs &= ~(1ULL << OVS_KEY_ATTR_CT_LABELS);
1261: }
1262: if (*attrs & (1ULL << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4)) {
1263: const struct ovs_key_ct_tuple_ipv4 *ct;
1264:
1265: ct = nla_data(a[OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4]);
1266:
1267: SW_FLOW_KEY_PUT(match, ipv4.ct_orig.src, ct->ipv4_src, is_mask);
1268: SW_FLOW_KEY_PUT(match, ipv4.ct_orig.dst, ct->ipv4_dst, is_mask);
1269: SW_FLOW_KEY_PUT(match, ct.orig_tp.src, ct->src_port, is_mask);
1270: SW_FLOW_KEY_PUT(match, ct.orig_tp.dst, ct->dst_port, is_mask);
1271: SW_FLOW_KEY_PUT(match, ct_orig_proto, ct->ipv4_proto, is_mask);
1272: *attrs &= ~(1ULL << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4);
1273: }
1274: if (*attrs & (1ULL << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6)) {
1275: const struct ovs_key_ct_tuple_ipv6 *ct;
1276:
1277: ct = nla_data(a[OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6]);
1278:
1279: SW_FLOW_KEY_MEMCPY(match, ipv6.ct_orig.src, &ct->ipv6_src,
1280: sizeof(match->key->ipv6.ct_orig.src),
1281: is_mask);
1282: SW_FLOW_KEY_MEMCPY(match, ipv6.ct_orig.dst, &ct->ipv6_dst,
1283: sizeof(match->key->ipv6.ct_orig.dst),
1284: is_mask);
1285: SW_FLOW_KEY_PUT(match, ct.orig_tp.src, ct->src_port, is_mask);
1286: SW_FLOW_KEY_PUT(match, ct.orig_tp.dst, ct->dst_port, is_mask);
1287: SW_FLOW_KEY_PUT(match, ct_orig_proto, ct->ipv6_proto, is_mask);
1288: *attrs &= ~(1ULL << OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6);
1289: }
1290:
1291: /* For layer 3 packets the Ethernet type is provided
1292: * and treated as metadata but no MAC addresses are provided.
1293: */
1294: if (!(*attrs & (1ULL << OVS_KEY_ATTR_ETHERNET)) &&
1295: (*attrs & (1ULL << OVS_KEY_ATTR_ETHERTYPE)))
1296: mac_proto = MAC_PROTO_NONE;
1297:
1298: /* Always exact match mac_proto */
1299: SW_FLOW_KEY_PUT(match, mac_proto, is_mask ? 0xff : mac_proto, is_mask);
1300:
1301: if (mac_proto == MAC_PROTO_NONE)
1302: return parse_eth_type_from_nlattrs(match, attrs, a, is_mask,
1303: log);
1304:
1305: return 0;
1306: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 110/2 |
2026/10/01 02:13 |
llm |
expert |
0m
Model:
Tokens:
input: 58183
output: 46
thoughts: 98
|
| 111/2 |
2026/10/01 02:13 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/openvswitch/flow_netlink.c Name:parse_eth_type_from_nlattrs]
Results: map[SourceCode:1149: static int parse_eth_type_from_nlattrs(struct sw_flow_match *match,
1150: u64 *attrs, const struct nlattr **a,
1151: bool is_mask, bool log)
1152: {
1153: __be16 eth_type;
1154:
1155: eth_type = nla_get_be16(a[OVS_KEY_ATTR_ETHERTYPE]);
1156: if (is_mask) {
1157: /* Always exact match EtherType. */
1158: eth_type = htons(0xffff);
1159: } else if (!eth_proto_is_802_3(eth_type)) {
1160: OVS_NLERR(log, "EtherType %x is less than min %x",
1161: ntohs(eth_type), ETH_P_802_3_MIN);
1162: return -EINVAL;
1163: }
1164:
1165: SW_FLOW_KEY_PUT(match, eth.type, eth_type, is_mask);
1166: *attrs &= ~(1 << OVS_KEY_ATTR_ETHERTYPE);
1167: return 0;
1168: }
SourceFile:net/openvswitch/flow_netlink.c]
|
| 112/2 |
2026/10/01 02:13 |
llm |
expert |
1m
Model:
Tokens:
input: 58695
output: 43
thoughts: 5347
|
| 113/2 |
2026/10/01 02:14 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/ipv6/exthdrs_core.c Name:ipv6_find_hdr]
Results: map[SourceCode: 165: /*
166: * find the offset to specified header or the protocol number of last header
167: * if target < 0. "last header" is transport protocol header, ESP, or
168: * "No next header".
169: *
170: * Note that *offset is used as input/output parameter, and if it is not zero,
171: * then it must be a valid offset to an inner IPv6 header. This can be used
172: * to explore inner IPv6 header, eg. ICMPv6 error messages.
173: *
174: * If target header is found, its offset is set in *offset and return protocol
175: * number. Otherwise, return -1.
176: *
177: * If the first fragment doesn't contain the final protocol header or
178: * NEXTHDR_NONE it is considered invalid.
179: *
180: * Note that non-1st fragment is special case that "the protocol number
181: * of last header" is "next header" field in Fragment header. In this case,
182: * *offset is meaningless and fragment offset is stored in *fragoff if fragoff
183: * isn't NULL.
184: *
185: * if flags is not NULL and it's a fragment, then the frag flag
186: * IP6_FH_F_FRAG will be set. If it's an AH header, the
187: * IP6_FH_F_AUTH flag is set and target < 0, then this function will
188: * stop at the AH header. If IP6_FH_F_SKIP_RH flag was passed, then this
189: * function will skip all those routing headers, where segements_left was 0.
190: */
191: int ipv6_find_hdr(const struct sk_buff *skb, unsigned int *offset,
192: int target, unsigned short *fragoff, int *flags)
193: {
194: unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr);
195: u8 nexthdr = ipv6_hdr(skb)->nexthdr;
196: int exthdr_cnt = 0;
197: bool found;
198:
199: if (fragoff)
200: *fragoff = 0;
201:
202: if (*offset) {
203: struct ipv6hdr _ip6, *ip6;
204:
205: ip6 = skb_header_pointer(skb, *offset, sizeof(_ip6), &_ip6);
206: if (!ip6 || (ip6->version != 6))
207: return -EBADMSG;
208: start = *offset + sizeof(struct ipv6hdr);
209: nexthdr = ip6->nexthdr;
210: }
211:
212: do {
213: struct ipv6_opt_hdr _hdr, *hp;
214: unsigned int hdrlen;
215: found = (nexthdr == target);
216:
217: if ((!ipv6_ext_hdr(nexthdr)) || nexthdr == NEXTHDR_NONE) {
218: if (target < 0 || found)
219: break;
220: return -ENOENT;
221: }
222:
223: if (unlikely(exthdr_cnt++ >= IP6_MAX_EXT_HDRS_CNT))
224: return -EBADMSG;
225:
226: hp = skb_header_pointer(skb, start, sizeof(_hdr), &_hdr);
227: if (!hp)
228: return -EBADMSG;
229:
230: if (nexthdr == NEXTHDR_ROUTING) {
231: struct ipv6_rt_hdr _rh, *rh;
232:
233: rh = skb_header_pointer(skb, start, sizeof(_rh),
234: &_rh);
235: if (!rh)
236: return -EBADMSG;
237:
238: if (flags && (*flags & IP6_FH_F_SKIP_RH) &&
239: rh->segments_left == 0)
240: found = false;
241: }
242:
243: if (nexthdr == NEXTHDR_FRAGMENT) {
244: unsigned short _frag_off;
245: __be16 *fp;
246:
247: if (flags) /* Indicate that this is a fragment */
248: *flags |= IP6_FH_F_FRAG;
249: fp = skb_header_pointer(skb,
250: start+offsetof(struct frag_hdr,
251: frag_off),
252: sizeof(_frag_off),
253: &_frag_off);
254: if (!fp)
255: return -EBADMSG;
256:
257: _frag_off = ntohs(*fp) & ~0x7;
258: if (_frag_off) {
259: if (target < 0 &&
260: ((!ipv6_ext_hdr(hp->nexthdr)) ||
261: hp->nexthdr == NEXTHDR_NONE)) {
262: if (fragoff)
263: *fragoff = _frag_off;
264: return hp->nexthdr;
265: }
266: if (!found)
267: return -ENOENT;
268: if (fragoff)
269: *fragoff = _frag_off;
270: break;
271: }
272: hdrlen = 8;
273: } else if (nexthdr == NEXTHDR_AUTH) {
274: if (flags && (*flags & IP6_FH_F_AUTH) && (target < 0))
275: break;
276: hdrlen = ipv6_authlen(hp);
277: } else
278: hdrlen = ipv6_optlen(hp);
279:
280: if (!found) {
281: if (skb->len - start < hdrlen)
282: return -EBADMSG;
283:
284: nexthdr = hp->nexthdr;
285: start += hdrlen;
286: }
287: } while (!found);
288:
289: *offset = start;
290: return nexthdr;
291: }
SourceFile:net/ipv6/exthdrs_core.c]
|
| 114/2 |
2026/10/01 02:14 |
llm |
expert |
1m
Model:
Tokens:
input: 66052
output: 66
thoughts: 6793
Thoughts: **Analysis of a Potential IPv6 Fragment Handling Vulnerability**
I've been scrutinizing a specific scenario within the `ipv6_find_hdr` and subsequent packet parsing logic, particularly focusing on how IPv6 fragments are handled and how this interacts with checksum updates and potential out-of-bounds writes. My investigation started with observing that in `ipv6_find_hdr`, if a packet is a later fragment (`_frag_off != 0`), the function returns `hp->nexthdr`. This initially seemed straightforward, but the implications for the `parse_ipv6hdr` function are significant.
Specifically, if `hp->nexthdr` happens to be `NEXTHDR_TCP` (which is 6), `parse_ipv6hdr` would receive `NEXTHDR_TCP` as the `nexthdr`. However, `parse_ipv6hdr` then proceeds to check for the `IP6_FH_F_FRAG` flag. If it's a fragment and `frag_off` is non-zero (meaning it's a *later* fragment), it overrides `key->ip.proto` to `NEXTHDR_FRAGMENT` (44) and returns `0` without further processing of the L4 header. This means that `flow_key->ip.proto` ends up being `NEXTHDR_FRAGMENT`.
The subsequent call chain involves passing this `flow_key->ip.proto` to `set_ipv6_addr`, which in turn calls `update_ipv6_checksum`. Crucially, `update_ipv6_checksum` then receives `NEXTHDR_FRAGMENT` as its `l4_proto`. My analysis shows that `update_ipv6_checksum` has specific logic for `NEXTHDR_TCP`, `NEXTHDR_UDP`, and `NEXTHDR_ICMP`, but it performs **absolutely nothing** when `l4_proto` is `NEXTHDR_FRAGMENT`. This is where my initial concern about an out-of-bounds write originated.
However, upon deeper inspection, I realized that while the `update_ipv6_checksum` function does nothing for fragments, the warning itself is triggered by an earlier line: `int transport_len = skb->len - skb_transport_offset(skb);`. This line unconditionally calls `skb_transport_offset(skb)`, which internally calls `skb_transport_header` and then `skb_transport_header_was_set`. The `DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb))` check within `skb_transport_header` is what fires the warning. This happens because, in the case of a later IPv6 fragment, `skb_set_transport_header` is never called by `parse_ipv6hdr`, leaving `skb->transport_header` at its initial uninitialized state (`~0U`).
The critical point here is that even though `skb_transport_offset(skb)` is called and the warning is triggered, the subsequent calculation of `transport_len` is never actually used because `l4_proto` is `NEXTHDR_FRAGMENT`, and none of the `if` conditions within `update_ipv6_checksum` (for TCP, UDP, or ICMP) are met. Therefore, despite the warning, there is **no actual out-of-bounds write**, no memory corruption, and no information leak. The code simply proceeds without performing any checksum calculations.
I then spent considerable time investigating alternative paths where `l4_proto` could be `NEXTHDR_TCP` while `skb->transport_header` remained uninitialized (`~0U`). This would be the only scenario that could lead to an actual memory safety issue. I analyzed `parse_ipv6hdr` for cases where `frag_off == 0` (first fragment), errors from `ipv6_find_hdr`, and how `skb->transport_header` is set. In all these investigated IPv6 scenarios, `skb_set_transport_header` is indeed called, or the protocol is correctly identified as a fragment. I also examined IPv4 handling, MPLS, and other actions like `SET_IPV6` and `SET_MASKED`, and found that they either prevent such a state or correctly handle fragments.
My conclusion is that the root cause is a warning due to the defensive check `!skb_transport_header_was_set(skb)` in the `skb_transport_header` helper function, which is called by `skb_transport_offset`. This warning is triggered by the structure of how later IPv6 fragments are handled, leading to `skb->transport_header` not being set. However, the subsequent logic in `update_ipv6_checksum` correctly identifies the protocol as a fragment and performs no operations, thus preventing any actual memory corruption or exploitable behavior. The issue is effectively a false positive warning that does not pose a security risk in terms of memory safety, though it could contribute to log spam or a denial-of-service if `panic_on_warn` is enabled.
In summary, my thoughts confirm that while the observed behavior triggers a warning, it does not lead to an exploitable vulnerability. The system correctly identifies the packet as a fragment, and the checksum update logic, while defensively coded, appropriately does nothing for such packets, thus safeguarding against memory corruption.
|
| 115/2 |
2026/10/01 02:16 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:true PeripheralTrigger:true RemoteTrigger:true Unprivileged:false UserNamespace:true VMGuestTrigger:true VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:true PeripheralTrigger:true RemoteTrigger:true Unprivileged:false UserNamespace:true VMGuestTrigger:true VMHostTrigger:false]
|
| 116/2 |
2026/10/01 02:16 |
llm |
expert |
0m
Model:
Tokens:
input: 72931
output: 809
thoughts: 349
|
| 117/1 |
2026/10/01 02:16 |
action |
format-explanation |
0m
Results: map[Explanation:**Root Cause Analysis**
The bug is a `WARNING` triggered in `skb_transport_header()` when processing an
IPv6 packet in the Open vSwitch (OVS) datapath.
When OVS extracts the flow key for an IPv6 packet via `key_extract_l3l4()` ->
`parse_ipv6hdr()`, it parses the IPv6 extension headers. If the packet is a
*later fragment* (i.e., the fragment offset is non-zero), `parse_ipv6hdr()`
correctly identifies it, sets the flow key's L4 protocol to `NEXTHDR_FRAGMENT`
(44), and returns early. Crucially, because it returns early, it skips the call
to `skb_set_transport_header()`, leaving `skb->transport_header` uninitialized
at its default value of `~0U`.
If the OVS datapath is configured with an action to modify the IPv6 header
(e.g., `OVS_ACTION_ATTR_SET` with IPv6 attributes, commonly used for NAT), the
datapath executes `set_ipv6()` -> `set_ipv6_addr()` -> `update_ipv6_checksum()`.
At the very beginning of `update_ipv6_checksum()`, the code unconditionally
calculates the transport length:
```c
int transport_len = skb->len - skb_transport_offset(skb);
```
Calling `skb_transport_offset(skb)` invokes `skb_transport_header(skb)`, which
contains a `DEBUG_NET_WARN_ON_ONCE(!skb_transport_header_was_set(skb))`. Since
the transport header was never set for the later fragment, the warning is
triggered.
**Exploitability**
Despite the uninitialized transport header leading to a bogus `transport_len`
calculation, this bug is **not exploitable** for memory corruption.
After calculating `transport_len`, `update_ipv6_checksum()` checks the
`l4_proto` (which was passed down from `flow_key->ip.proto`):
```c
if (l4_proto == NEXTHDR_TCP) {
// ...
} else if (l4_proto == NEXTHDR_UDP) {
// ...
} else if (l4_proto == NEXTHDR_ICMP) {
// ...
}
```
Because the packet is a later fragment, `l4_proto` is `NEXTHDR_FRAGMENT` (44).
It does not match TCP (6), UDP (17), or ICMP (58). Consequently, the function
simply returns without attempting to update any L4 checksums. No out-of-bounds
reads or writes occur. The issue is strictly a false-positive warning spam.
**Access Vectors**
- **User Namespace:** The syzbot reproducer triggers this by directly injecting
a packet and executing actions via the `OVS_PACKET_CMD_EXECUTE` netlink command.
This command requires `CAP_NET_ADMIN` in the user namespace
(`GENL_UNS_ADMIN_PERM`), making it accessible to unprivileged users who can
create user namespaces.
- **Network / VM Guest / Peripheral:** In a real-world scenario, if an OVS
bridge is configured by an administrator with a flow that modifies IPv6
addresses (like NAT) without explicitly dropping fragments, any remote attacker,
VM guest, or malicious peripheral can trigger the warning by simply sending a
crafted IPv6 later fragment over the network.
- **Denial of Service:** While it does not crash the kernel by default, the
warning can spam the kernel logs (causing a minor DoS) or halt the system if
`panic_on_warn` is enabled.]
|