| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/09/29 08:43 | flow | patch-triage |
3mArgs:null Results: {
"EnableConfigs": [
"PACKET"
],
"FocusSymbols": [
"packet_rcv_spkt"
],
"KMSANReasoning": "The patch adds a check `if (dev_has_header(dev))` before calling `skb_push(skb, skb-\u003edata - skb_mac_header(skb))` in `packet_rcv_spkt()` to align it with `packet_rcv()` and `tpacket_rcv()`. This prevents invoking `skb_push()` on devices without link-layer headers where an unset/sentinel `mac_header` results in an invalid push offset triggering `skb_under_panic()`.\n\nThe change does not introduce any uninitialized memory allocations, padding leaks to userspace, or uninitialized branch conditions. The existing packet buffer data is already properly tracked and bounded. The issue addressed is a panic / bounds check failure (`skb_under_panic()`), which falls under standard bug detectors rather than KMSAN. Therefore, a dedicated KMSAN session is not required.",
"NeedsKMSAN": false,
"Reasoning": "The patch modifies the packet reception path in packet_rcv_spkt() for AF_PACKET SOCK_PACKET sockets to check dev_has_header(dev) before restoring the link-layer header via skb_push(). This alters reachable core networking logic and prevents skb_under_panic() when handling packets on devices without visible link-layer headers. It is directly testable and reachable in virtualized environments.",
"WorthFuzzing": true
} |
| 1/1 | 2026/09/29 08:43 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit 34a423dbdde5ac62b44ce70451475e6ef0596509\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Sep 29 08:43:10 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/net/packet/af_packet.c b/net/packet/af_packet.c\nindex 7c83e01526edc..40c67b86a1735 100644\n--- a/net/packet/af_packet.c\n+++ b/net/packet/af_packet.c\n@@ -1911,7 +1911,14 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,\n \n \tspkt = \u0026PACKET_SKB_CB(skb)-\u003esa.pkt;\n \n-\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n+\t/* Only a device with a visible ll header can have it restored, which is\n+\t * the test packet_rcv() and tpacket_rcv() already make. For the others\n+\t * the header is invisible and the subtraction has no meaning: a producer\n+\t * that left skb-\u003emac_header at its 0xFFFF sentinel turns it into a huge\n+\t * negative length that trips skb_under_panic() in softirq context.\n+\t */\n+\tif (dev_has_header(dev))\n+\t\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n \n \t/*\n \t *\tThe SOCK_PACKET socket receives _all_ frames.\n"
} |
| 2/1 | 2026/09/29 08:43 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"PACKET"
],
"FocusSymbols": [
"packet_rcv_spkt"
],
"Reasoning": "The patch modifies the packet reception path in packet_rcv_spkt() for AF_PACKET SOCK_PACKET sockets to check dev_has_header(dev) before restoring the link-layer header via skb_push(). This alters reachable core networking logic and prevents skb_under_panic() when handling packets on devices without visible link-layer headers. It is directly testable and reachable in virtualized environments.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
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: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 34a423dbdde5ac62b44ce70451475e6ef0596509
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Sep 29 08:43:10 2026 +0000
syz-cluster: applied patch under review
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 7c83e01526edc..40c67b86a1735 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1911,7 +1911,14 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
spkt = &PACKET_SKB_CB(skb)->sa.pkt;
- skb_push(skb, skb->data - skb_mac_header(skb));
+ /* Only a device with a visible ll header can have it restored, which is
+ * the test packet_rcv() and tpacket_rcv() already make. For the others
+ * the header is invisible and the subtraction has no meaning: a producer
+ * that left skb->mac_header at its 0xFFFF sentinel turns it into a huge
+ * negative length that trips skb_under_panic() in softirq context.
+ */
+ if (dev_has_header(dev))
+ skb_push(skb, skb->data - skb_mac_header(skb));
/*
* The SOCK_PACKET socket receives _all_ frames.
|
| 3/2 | 2026/09/29 08:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 3014 output: 38 thoughts: 406 Thoughts: **Analyzing the Patch to `net/packet/af_packet.c`** Okay, so this patch is aimed squarely at `net/packet/af_packet.c`, specifically around the `packet_rcv_spkt` function. I see the diff focuses on how the Socket Packet (SOCK_PACKET) receives all frames. The core of this seems to be about restoring the link-layer header in `skb`s. The original code was calling `skb_push` unconditionally, with an offset calculated as `skb->data - skb_mac_header(skb)`. My immediate thought is that this is a common pattern, and a careful optimization. However, it looks like this can lead to issues in cases where a link-layer header is *not* present or visible. The patch introduces a check using `dev_has_header(dev)`. That's smart. By only performing the `skb_push` if the device actually *has* a header, it's avoiding the potential for that calculation to go sideways and generate a huge negative length for `skb`, which then causes a panic. I can see how that could be a significant problem in softirq context. This definitely protects against the scenario with a sentinel value. This is a good, targeted fix. It's a clean check, guards against an edge case, and prevents a potential crash. The comment added is also spot on, explaining the reasoning concisely. Well done. |
| 4/2 | 2026/09/29 08:43 | tool | read-file |
0mArgs:{
"File": "net/packet/af_packet.c",
"FirstLine": 1890,
"LineCount": 60
}Results: {
"Contents": "1890:\t\t *\tpush it back.\n1891:\t\t *\n1892:\t\t *\tFor outgoing ones skb-\u003edata == skb_mac_header(skb)\n1893:\t\t *\tso that this procedure is noop.\n1894:\t\t */\n1895:\t\n1896:\t\tif (skb-\u003epkt_type == PACKET_LOOPBACK)\n1897:\t\t\tgoto out;\n1898:\t\n1899:\t\tif (!net_eq(dev_net(dev), sock_net(sk)))\n1900:\t\t\tgoto out;\n1901:\t\n1902:\t\tskb = skb_share_check(skb, GFP_ATOMIC);\n1903:\t\tif (skb == NULL)\n1904:\t\t\tgoto oom;\n1905:\t\n1906:\t\t/* drop any routing info */\n1907:\t\tskb_dst_drop(skb);\n1908:\t\n1909:\t\t/* drop conntrack reference */\n1910:\t\tnf_reset_ct(skb);\n1911:\t\n1912:\t\tspkt = \u0026PACKET_SKB_CB(skb)-\u003esa.pkt;\n1913:\t\n1914:\t\t/* Only a device with a visible ll header can have it restored, which is\n1915:\t\t * the test packet_rcv() and tpacket_rcv() already make. For the others\n1916:\t\t * the header is invisible and the subtraction has no meaning: a producer\n1917:\t\t * that left skb-\u003emac_header at its 0xFFFF sentinel turns it into a huge\n1918:\t\t * negative length that trips skb_under_panic() in softirq context.\n1919:\t\t */\n1920:\t\tif (dev_has_header(dev))\n1921:\t\t\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n1922:\t\n1923:\t\t/*\n1924:\t\t *\tThe SOCK_PACKET socket receives _all_ frames.\n1925:\t\t */\n1926:\t\n1927:\t\tspkt-\u003espkt_family = dev-\u003etype;\n1928:\t\tstrscpy(spkt-\u003espkt_device, dev-\u003ename, sizeof(spkt-\u003espkt_device));\n1929:\t\tspkt-\u003espkt_protocol = skb-\u003eprotocol;\n1930:\t\n1931:\t\t/*\n1932:\t\t *\tCharge the memory to the socket. This is done specifically\n1933:\t\t *\tto prevent sockets using all the memory up.\n1934:\t\t */\n1935:\t\n1936:\t\tif (sock_queue_rcv_skb(sk, skb) == 0)\n1937:\t\t\treturn 0;\n1938:\t\n1939:\tout:\n1940:\t\tkfree_skb(skb);\n1941:\toom:\n1942:\t\treturn 0;\n1943:\t}\n1944:\t\n1945:\tstatic void packet_parse_headers(struct sk_buff *skb, struct socket *sock)\n1946:\t{\n1947:\t\tint depth;\n1948:\t\n1949:\t\t/* On TX skb-\u003edata is the L2 header; anchor it for all socket types. */\n"
} |
| 5/2 | 2026/09/29 08:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 4669 output: 27 thoughts: 47 Thoughts: Here's my thought process, as requested: **Investigating the `packet_rcv_spkt` Function** Okay, so I need to understand how `packet_rcv_spkt` works within the networking stack. I know it's located within `net/packet/af_packet.c`. My immediate thought is, "What enables this AF_PACKET functionality?" Where's the configuration option? I need to figure out what's going on at the kernel build level. It's time to check the configuration files. My gut instinct is that the enabling configuration will likely be found in either `net/packet/Kconfig` which describes the configuration option or potentially in the relevant `Makefile` if it has some build-time dependency. I'll start with the Kconfig file, as that's generally where these options are defined. |
| 6/2 | 2026/09/29 08:43 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_PACKET",
"PathPrefix": "net/packet"
}Results: {
"Output": "net/packet/Makefile-5-\nnet/packet/Makefile:6:obj-$(CONFIG_PACKET) += af_packet.o\nnet/packet/Makefile:7:obj-$(CONFIG_PACKET_DIAG) += af_packet_diag.o\nnet/packet/Makefile-8-af_packet_diag-y += diag.o\n"
} |
| 7/2 | 2026/09/29 08:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 5017 output: 32 thoughts: 12 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the Kernel Packet Configuration** Alright, time to dig in. The initial thought here, as a seasoned kernel developer myself, is: let's get right to the source. The real meat of the `net/packet/` subsystem's configuration, the foundation for how we structure and use packet processing, has to be in the `Kconfig` file. It's the central hub for build-time options and dependencies. I'm thinking specifically about all of the kernel configuration possibilities for packet sockets, packet mmap, packet filter, etc.. We need to see what configuration options are available and their defaults. |
| 8/2 | 2026/09/29 08:43 | tool | read-file |
0mArgs:{
"File": "net/packet/Kconfig",
"FirstLine": 1,
"LineCount": 20
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\t#\n 3:\t# Packet configuration\n 4:\t#\n 5:\t\n 6:\tconfig PACKET\n 7:\t\ttristate \"Packet socket\"\n 8:\t\thelp\n 9:\t\t The Packet protocol is used by applications which communicate\n 10:\t\t directly with network devices without an intermediate network\n 11:\t\t protocol implemented in the kernel, e.g. tcpdump. If you want them\n 12:\t\t to work, choose Y.\n 13:\t\n 14:\t\t To compile this driver as a module, choose M here: the module will\n 15:\t\t be called af_packet.\n 16:\t\n 17:\t\t If unsure, say Y.\n 18:\t\n 19:\tconfig PACKET_DIAG\n 20:\t\ttristate \"Packet: sockets monitoring interface\"\n"
} |
| 9/2 | 2026/09/29 08:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 5455 output: 30 thoughts: 45 Thoughts: Okay, here's my summary, taking the role of the expert: **Investigating CONFIG_PACKET and Packet Reception** Alright, let's dive in. My initial thought is to zero in on `CONFIG_PACKET`. Right, that's *the* configuration option we're interested in. The immediate question is always dependencies. Does `CONFIG_PACKET` depend on anything else? A quick mental scan... nah, seems pretty standalone, or at least it inherits what it needs from the core `net/Kconfig` includes. Time to move on and see how it's used. Now, where are we *using* this functionality? I'm going to look for the key function, `packet_rcv_spkt`. I need to figure out where that's called or registered. That'll tell the story of how packet reception is handled with this config enabled. Time to dig into the code and see where that function hooks into the networking stack. Let's see... |
| 10/2 | 2026/09/29 08:43 | tool | grepper |
0mArgs:{
"Expression": "packet_rcv_spkt",
"PathPrefix": "net/packet"
}Results: {
"Output": "net/packet/af_packet.c=1870=static const struct proto_ops packet_ops_spkt;\nnet/packet/af_packet.c-1871-\nnet/packet/af_packet.c:1872:static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,\nnet/packet/af_packet.c-1873-\t\t\t struct packet_type *pt, struct net_device *orig_dev)\n--\nnet/packet/af_packet.c=3402=static int packet_create(struct net *net, struct socket *sock, int protocol,\n--\nnet/packet/af_packet.c-3451-\tif (sock-\u003etype == SOCK_PACKET)\nnet/packet/af_packet.c:3452:\t\tpo-\u003eprot_hook.func = packet_rcv_spkt;\nnet/packet/af_packet.c-3453-\n"
} |
| 11/2 | 2026/09/29 08:43 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 5990 output: 30 thoughts: 818 Thoughts: **Analysis of a SOCK_PACKET Receive Function Bug Fix** Okay, so I'm looking at this patch and my initial thought is, this `packet_rcv_spkt` function is the receiving function specifically for `SOCK_PACKET` sockets. I know this is fully accessible in syzkaller fuzzing, which means it should be pretty reachable. AF_PACKET sockets with SOCK_PACKET are easily created in userspace. And yeah, it's definitely reachable in standard QEMU; virtio-net, loopback, tun/tap, they all use `prot_hook`, so it will be called. The fix itself seems straightforward: it's adding a `dev_has_header(dev)` check before the `skb_push` call within `packet_rcv_spkt`. This is unlike the `packet_rcv` and `tpacket_rcv` functions. This is core networking code we're talking about here, specifically in `net/packet/af_packet.c`. The change modifies the packet receiving logic for `SOCK_PACKET`. So, the next question is, is this worth fuzzing? Let's go through the guidelines. First, reachability. The `SOCK_PACKET` packet receive path is definitely reachable, so check. Second, core subsystems. It's logic modifications in core networking, so check. This looks worth fuzzing. Now, what about focus symbols? Well, obviously, `packet_rcv_spkt` is the exact function being modified. Are there any other relevant functions, maybe `packet_create`? But `packet_rcv_spkt` is non-ubiquitous, specific to SOCK_PACKET receiving. Let me just quickly verify that the commit only touched `packet_rcv_spkt`. I'll check the diff itself... Yup, it's just that one function. And looking at the diff again, it's just the one function being modified. Okay. Since `packet_rcv_spkt` is a C function, not inlined (it has its address taken in `packet_create`: `po->prot_hook.func = packet_rcv_spkt;`), it will be a distinct symbol in vmlinux. Now, just to be completely sure, I'll quickly check the git log and diff to make absolutely certain that no other files or commits were included. |
| 12/2 | 2026/09/29 08:44 | tool | grepper |
0mArgs:{
"Expression": ".*",
"PathPrefix": "net/packet/af_packet.c"
}Results: {
"Output": "\nFull output is too long, showing 500 out of 4962 lines.\nUse more precise expression if possible.\n\nnet/packet/af_packet.c:1:// SPDX-License-Identifier: GPL-2.0-or-later\nnet/packet/af_packet.c:2:/*\nnet/packet/af_packet.c:3: * INET\t\tAn implementation of the TCP/IP protocol suite for the LINUX\nnet/packet/af_packet.c:4: *\t\toperating system. INET is implemented using the BSD Socket\nnet/packet/af_packet.c:5: *\t\tinterface as the means of communication with the user level.\nnet/packet/af_packet.c:6: *\nnet/packet/af_packet.c:7: *\t\tPACKET - implements raw packet sockets.\nnet/packet/af_packet.c:8: *\nnet/packet/af_packet.c:9: * Authors:\tRoss Biro\nnet/packet/af_packet.c:10: *\t\tFred N. van Kempen, \u003cwaltje@uWalt.NL.Mugnet.ORG\u003e\nnet/packet/af_packet.c:11: *\t\tAlan Cox, \u003cgw4pts@gw4pts.ampr.org\u003e\nnet/packet/af_packet.c:12: *\nnet/packet/af_packet.c:13: * Fixes:\nnet/packet/af_packet.c:14: *\t\tAlan Cox\t:\tverify_area() now used correctly\nnet/packet/af_packet.c:15: *\t\tAlan Cox\t:\tnew skbuff lists, look ma no backlogs!\nnet/packet/af_packet.c:16: *\t\tAlan Cox\t:\ttidied skbuff lists.\nnet/packet/af_packet.c:17: *\t\tAlan Cox\t:\tNow uses generic datagram routines I\nnet/packet/af_packet.c:18: *\t\t\t\t\tadded. Also fixed the peek/read crash\nnet/packet/af_packet.c:19: *\t\t\t\t\tfrom all old Linux datagram code.\nnet/packet/af_packet.c:20: *\t\tAlan Cox\t:\tUses the improved datagram code.\nnet/packet/af_packet.c:21: *\t\tAlan Cox\t:\tAdded NULL's for socket options.\nnet/packet/af_packet.c:22: *\t\tAlan Cox\t:\tRe-commented the code.\nnet/packet/af_packet.c:23: *\t\tAlan Cox\t:\tUse new kernel side addressing\nnet/packet/af_packet.c:24: *\t\tRob Janssen\t:\tCorrect MTU usage.\nnet/packet/af_packet.c:25: *\t\tDave Platt\t:\tCounter leaks caused by incorrect\nnet/packet/af_packet.c:26: *\t\t\t\t\tinterrupt locking and some slightly\nnet/packet/af_packet.c:27: *\t\t\t\t\tdubious gcc output. Can you read\nnet/packet/af_packet.c:28: *\t\t\t\t\tcompiler: it said _VOLATILE_\nnet/packet/af_packet.c:29: *\tRichard Kooijman\t:\tTimestamp fixes.\nnet/packet/af_packet.c:30: *\t\tAlan Cox\t:\tNew buffers. Use sk-\u003emac.raw.\nnet/packet/af_packet.c:31: *\t\tAlan Cox\t:\tsendmsg/recvmsg support.\nnet/packet/af_packet.c:32: *\t\tAlan Cox\t:\tProtocol setting support\nnet/packet/af_packet.c:33: *\tAlexey Kuznetsov\t:\tUntied from IPv4 stack.\nnet/packet/af_packet.c:34: *\tCyrus Durgin\t\t:\tFixed kerneld for kmod.\nnet/packet/af_packet.c:35: *\tMichal Ostrowski : Module initialization cleanup.\nnet/packet/af_packet.c:36: * Ulises Alonso : Frame number limit removal and\nnet/packet/af_packet.c:37: * packet_set_ring memory leak.\nnet/packet/af_packet.c:38: *\t\tEric Biederman\t:\tAllow for \u003e 8 byte hardware addresses.\nnet/packet/af_packet.c:39: *\t\t\t\t\tThe convention is that longer addresses\nnet/packet/af_packet.c:40: *\t\t\t\t\twill simply extend the hardware address\nnet/packet/af_packet.c:41: *\t\t\t\t\tbyte arrays at the end of sockaddr_ll\nnet/packet/af_packet.c:42: *\t\t\t\t\tand packet_mreq.\nnet/packet/af_packet.c:43: *\t\tJohann Baudy\t:\tAdded TX RING.\nnet/packet/af_packet.c:44: *\t\tChetan Loke\t:\tImplemented TPACKET_V3 block abstraction\nnet/packet/af_packet.c:45: *\t\t\t\t\tlayer.\nnet/packet/af_packet.c:46: *\t\t\t\t\tCopyright (C) 2011, \u003clokec@ccs.neu.edu\u003e\nnet/packet/af_packet.c:47: */\nnet/packet/af_packet.c:48:\nnet/packet/af_packet.c:49:#define pr_fmt(fmt) KBUILD_MODNAME \": \" fmt\nnet/packet/af_packet.c:50:\nnet/packet/af_packet.c:51:#include \u003clinux/ethtool.h\u003e\nnet/packet/af_packet.c:52:#include \u003clinux/uio.h\u003e\nnet/packet/af_packet.c:53:#include \u003clinux/filter.h\u003e\nnet/packet/af_packet.c:54:#include \u003clinux/types.h\u003e\nnet/packet/af_packet.c:55:#include \u003clinux/mm.h\u003e\nnet/packet/af_packet.c:56:#include \u003clinux/capability.h\u003e\nnet/packet/af_packet.c:57:#include \u003clinux/fcntl.h\u003e\nnet/packet/af_packet.c:58:#include \u003clinux/socket.h\u003e\nnet/packet/af_packet.c:59:#include \u003clinux/in.h\u003e\nnet/packet/af_packet.c:60:#include \u003clinux/inet.h\u003e\nnet/packet/af_packet.c:61:#include \u003clinux/netdevice.h\u003e\nnet/packet/af_packet.c:62:#include \u003clinux/if_packet.h\u003e\nnet/packet/af_packet.c:63:#include \u003clinux/wireless.h\u003e\nnet/packet/af_packet.c:64:#include \u003clinux/kernel.h\u003e\nnet/packet/af_packet.c:65:#include \u003clinux/kmod.h\u003e\nnet/packet/af_packet.c:66:#include \u003clinux/slab.h\u003e\nnet/packet/af_packet.c:67:#include \u003clinux/vmalloc.h\u003e\nnet/packet/af_packet.c:68:#include \u003cnet/net_namespace.h\u003e\nnet/packet/af_packet.c:69:#include \u003cnet/ip.h\u003e\nnet/packet/af_packet.c:70:#include \u003cnet/protocol.h\u003e\nnet/packet/af_packet.c:71:#include \u003clinux/skbuff.h\u003e\nnet/packet/af_packet.c:72:#include \u003cnet/sock.h\u003e\nnet/packet/af_packet.c:73:#include \u003clinux/errno.h\u003e\nnet/packet/af_packet.c:74:#include \u003clinux/timer.h\u003e\nnet/packet/af_packet.c:75:#include \u003clinux/uaccess.h\u003e\nnet/packet/af_packet.c:76:#include \u003casm/ioctls.h\u003e\nnet/packet/af_packet.c:77:#include \u003casm/page.h\u003e\nnet/packet/af_packet.c:78:#include \u003casm/cacheflush.h\u003e\nnet/packet/af_packet.c:79:#include \u003casm/io.h\u003e\nnet/packet/af_packet.c:80:#include \u003clinux/proc_fs.h\u003e\nnet/packet/af_packet.c:81:#include \u003clinux/seq_file.h\u003e\nnet/packet/af_packet.c:82:#include \u003clinux/poll.h\u003e\nnet/packet/af_packet.c:83:#include \u003clinux/module.h\u003e\nnet/packet/af_packet.c:84:#include \u003clinux/init.h\u003e\nnet/packet/af_packet.c:85:#include \u003clinux/mutex.h\u003e\nnet/packet/af_packet.c:86:#include \u003clinux/if_vlan.h\u003e\nnet/packet/af_packet.c:87:#include \u003clinux/virtio_net.h\u003e\nnet/packet/af_packet.c:88:#include \u003clinux/errqueue.h\u003e\nnet/packet/af_packet.c:89:#include \u003clinux/net_tstamp.h\u003e\nnet/packet/af_packet.c:90:#include \u003clinux/percpu.h\u003e\nnet/packet/af_packet.c:91:#include \u003clinux/workqueue.h\u003e\nnet/packet/af_packet.c:92:#ifdef CONFIG_INET\nnet/packet/af_packet.c:93:#include \u003cnet/inet_common.h\u003e\nnet/packet/af_packet.c:94:#endif\nnet/packet/af_packet.c:95:#include \u003clinux/bpf.h\u003e\nnet/packet/af_packet.c:96:#include \u003cnet/compat.h\u003e\nnet/packet/af_packet.c:97:#include \u003clinux/netfilter_netdev.h\u003e\nnet/packet/af_packet.c:98:\nnet/packet/af_packet.c:99:#include \"internal.h\"\nnet/packet/af_packet.c:100:\nnet/packet/af_packet.c:101:/*\nnet/packet/af_packet.c:102: Assumptions:\nnet/packet/af_packet.c:103: - If the device has no dev-\u003eheader_ops-\u003ecreate, there is no LL header\nnet/packet/af_packet.c:104: visible above the device. In this case, its hard_header_len should be 0.\nnet/packet/af_packet.c:105: The device may prepend its own header internally. In this case, its\nnet/packet/af_packet.c:106: needed_headroom should be set to the space needed for it to add its\nnet/packet/af_packet.c:107: internal header.\nnet/packet/af_packet.c:108: For example, a WiFi driver pretending to be an Ethernet driver should\nnet/packet/af_packet.c:109: set its hard_header_len to be the Ethernet header length, and set its\nnet/packet/af_packet.c:110: needed_headroom to be (the real WiFi header length - the fake Ethernet\nnet/packet/af_packet.c:111: header length).\nnet/packet/af_packet.c:112: - packet socket receives packets with pulled ll header,\nnet/packet/af_packet.c:113: so that SOCK_RAW should push it back.\nnet/packet/af_packet.c:114:\nnet/packet/af_packet.c:115:On receive:\nnet/packet/af_packet.c:116:-----------\nnet/packet/af_packet.c:117:\nnet/packet/af_packet.c:118:Incoming, dev_has_header(dev) == true\nnet/packet/af_packet.c:119: mac_header -\u003e ll header\nnet/packet/af_packet.c:120: data -\u003e data\nnet/packet/af_packet.c:121:\nnet/packet/af_packet.c:122:Outgoing, dev_has_header(dev) == true\nnet/packet/af_packet.c:123: mac_header -\u003e ll header\nnet/packet/af_packet.c:124: data -\u003e ll header\nnet/packet/af_packet.c:125:\nnet/packet/af_packet.c:126:Incoming, dev_has_header(dev) == false\nnet/packet/af_packet.c:127: mac_header -\u003e data\nnet/packet/af_packet.c:128: However drivers often make it point to the ll header.\nnet/packet/af_packet.c:129: This is incorrect because the ll header should be invisible to us.\nnet/packet/af_packet.c:130: data -\u003e data\nnet/packet/af_packet.c:131:\nnet/packet/af_packet.c:132:Outgoing, dev_has_header(dev) == false\nnet/packet/af_packet.c:133: mac_header -\u003e data. ll header is invisible to us.\nnet/packet/af_packet.c:134: data -\u003e data\nnet/packet/af_packet.c:135:\nnet/packet/af_packet.c:136:Resume\nnet/packet/af_packet.c:137: If dev_has_header(dev) == false we are unable to restore the ll header,\nnet/packet/af_packet.c:138: because it is invisible to us.\nnet/packet/af_packet.c:139:\nnet/packet/af_packet.c:140:\nnet/packet/af_packet.c:141:On transmit:\nnet/packet/af_packet.c:142:------------\nnet/packet/af_packet.c:143:\nnet/packet/af_packet.c:144:dev_has_header(dev) == true\nnet/packet/af_packet.c:145: mac_header -\u003e ll header\nnet/packet/af_packet.c:146: data -\u003e ll header\nnet/packet/af_packet.c:147:\nnet/packet/af_packet.c:148:dev_has_header(dev) == false (ll header is invisible to us)\nnet/packet/af_packet.c:149: mac_header -\u003e data\nnet/packet/af_packet.c:150: data -\u003e data\nnet/packet/af_packet.c:151:\nnet/packet/af_packet.c:152: We should set network_header on output to the correct position,\nnet/packet/af_packet.c:153: packet classifier depends on it.\nnet/packet/af_packet.c:154: */\nnet/packet/af_packet.c:155:\nnet/packet/af_packet.c:156:/* Private packet socket structures. */\nnet/packet/af_packet.c:157:\nnet/packet/af_packet.c:158:/* identical to struct packet_mreq except it has\nnet/packet/af_packet.c:159: * a longer address field.\nnet/packet/af_packet.c:160: */\nnet/packet/af_packet.c:161:struct packet_mreq_max {\nnet/packet/af_packet.c:162:\tint\t\tmr_ifindex;\nnet/packet/af_packet.c:163:\tunsigned short\tmr_type;\nnet/packet/af_packet.c:164:\tunsigned short\tmr_alen;\nnet/packet/af_packet.c:165:\tunsigned char\tmr_address[MAX_ADDR_LEN];\nnet/packet/af_packet.c:166:};\nnet/packet/af_packet.c:167:\nnet/packet/af_packet.c:168:union tpacket_uhdr {\nnet/packet/af_packet.c:169:\tstruct tpacket_hdr *h1;\nnet/packet/af_packet.c:170:\tstruct tpacket2_hdr *h2;\nnet/packet/af_packet.c:171:\tstruct tpacket3_hdr *h3;\nnet/packet/af_packet.c:172:\tvoid *raw;\nnet/packet/af_packet.c:173:};\nnet/packet/af_packet.c:174:\nnet/packet/af_packet.c:175:static int packet_set_ring(struct sock *sk, union tpacket_req_u *req_u,\nnet/packet/af_packet.c:176:\t\tint closing, int tx_ring);\nnet/packet/af_packet.c:177:\nnet/packet/af_packet.c:178:#define V3_ALIGNMENT\t(8)\nnet/packet/af_packet.c:179:\nnet/packet/af_packet.c:180:#define BLK_HDR_LEN\t(ALIGN(sizeof(struct tpacket_block_desc), V3_ALIGNMENT))\nnet/packet/af_packet.c:181:\nnet/packet/af_packet.c:182:#define BLK_PLUS_PRIV(sz_of_priv) \\\nnet/packet/af_packet.c:183:\t(BLK_HDR_LEN + ALIGN((sz_of_priv), V3_ALIGNMENT))\nnet/packet/af_packet.c:184:\nnet/packet/af_packet.c:185:#define BLOCK_STATUS(x)\t((x)-\u003ehdr.bh1.block_status)\nnet/packet/af_packet.c:186:#define BLOCK_NUM_PKTS(x)\t((x)-\u003ehdr.bh1.num_pkts)\nnet/packet/af_packet.c:187:#define BLOCK_O2FP(x)\t\t((x)-\u003ehdr.bh1.offset_to_first_pkt)\nnet/packet/af_packet.c:188:#define BLOCK_LEN(x)\t\t((x)-\u003ehdr.bh1.blk_len)\nnet/packet/af_packet.c:189:#define BLOCK_SNUM(x)\t\t((x)-\u003ehdr.bh1.seq_num)\nnet/packet/af_packet.c:190:#define BLOCK_O2PRIV(x)\t((x)-\u003eoffset_to_priv)\nnet/packet/af_packet.c:191:\nnet/packet/af_packet.c:192:struct packet_sock;\nnet/packet/af_packet.c:193:static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,\nnet/packet/af_packet.c:194:\t\t struct packet_type *pt, struct net_device *orig_dev);\nnet/packet/af_packet.c:195:\nnet/packet/af_packet.c:196:static void *packet_previous_frame(struct packet_sock *po,\nnet/packet/af_packet.c:197:\t\tstruct packet_ring_buffer *rb,\nnet/packet/af_packet.c:198:\t\tint status);\nnet/packet/af_packet.c:199:static void packet_increment_head(struct packet_ring_buffer *buff);\nnet/packet/af_packet.c:200:static int prb_curr_blk_in_use(struct tpacket_block_desc *);\nnet/packet/af_packet.c:201:static void *prb_dispatch_next_block(struct tpacket_kbdq_core *,\nnet/packet/af_packet.c:202:\t\t\tstruct packet_sock *);\nnet/packet/af_packet.c:203:static void prb_retire_current_block(struct tpacket_kbdq_core *,\nnet/packet/af_packet.c:204:\t\tstruct packet_sock *, unsigned int status);\nnet/packet/af_packet.c:205:static int prb_queue_frozen(struct tpacket_kbdq_core *);\nnet/packet/af_packet.c:206:static void prb_open_block(struct tpacket_kbdq_core *,\nnet/packet/af_packet.c:207:\t\tstruct tpacket_block_desc *);\nnet/packet/af_packet.c:208:static enum hrtimer_restart prb_retire_rx_blk_timer_expired(struct hrtimer *);\nnet/packet/af_packet.c:209:static void prb_fill_rxhash(struct tpacket_kbdq_core *, struct tpacket3_hdr *);\nnet/packet/af_packet.c:210:static void prb_clear_rxhash(struct tpacket_kbdq_core *,\nnet/packet/af_packet.c:211:\t\tstruct tpacket3_hdr *);\nnet/packet/af_packet.c:212:static void prb_fill_vlan_info(struct tpacket_kbdq_core *,\nnet/packet/af_packet.c:213:\t\tstruct tpacket3_hdr *);\nnet/packet/af_packet.c:214:static void packet_flush_mclist(struct sock *sk);\nnet/packet/af_packet.c:215:static u16 packet_pick_tx_queue(struct sk_buff *skb);\nnet/packet/af_packet.c:216:\nnet/packet/af_packet.c:217:struct packet_skb_cb {\nnet/packet/af_packet.c:218:\tunion {\nnet/packet/af_packet.c:219:\t\tstruct sockaddr_pkt pkt;\nnet/packet/af_packet.c:220:\t\tunion {\nnet/packet/af_packet.c:221:\t\t\t/* Trick: alias skb original length with\nnet/packet/af_packet.c:222:\t\t\t * ll.sll_family and ll.protocol in order\nnet/packet/af_packet.c:223:\t\t\t * to save room.\nnet/packet/af_packet.c:224:\t\t\t */\nnet/packet/af_packet.c:225:\t\t\tunsigned int origlen;\nnet/packet/af_packet.c:226:\t\t\tstruct sockaddr_ll ll;\nnet/packet/af_packet.c:227:\t\t};\nnet/packet/af_packet.c:228:\t} sa;\nnet/packet/af_packet.c:229:};\nnet/packet/af_packet.c:230:\nnet/packet/af_packet.c:231:#define vio_le() virtio_legacy_is_little_endian()\nnet/packet/af_packet.c:232:\nnet/packet/af_packet.c:233:#define PACKET_SKB_CB(__skb)\t((struct packet_skb_cb *)((__skb)-\u003ecb))\nnet/packet/af_packet.c:234:\nnet/packet/af_packet.c:235:#define GET_PBDQC_FROM_RB(x)\t((struct tpacket_kbdq_core *)(\u0026(x)-\u003eprb_bdqc))\nnet/packet/af_packet.c:236:#define GET_PBLOCK_DESC(x, bid)\t\\\nnet/packet/af_packet.c:237:\t((struct tpacket_block_desc *)((x)-\u003epkbdq[(bid)].buffer))\nnet/packet/af_packet.c:238:#define GET_CURR_PBLOCK_DESC_FROM_CORE(x)\t\\\nnet/packet/af_packet.c:239:\t((struct tpacket_block_desc *)((x)-\u003epkbdq[(x)-\u003ekactive_blk_num].buffer))\nnet/packet/af_packet.c:240:#define GET_NEXT_PRB_BLK_NUM(x) \\\nnet/packet/af_packet.c:241:\t(((x)-\u003ekactive_blk_num \u003c ((x)-\u003eknum_blocks-1)) ? \\\nnet/packet/af_packet.c:242:\t((x)-\u003ekactive_blk_num+1) : 0)\nnet/packet/af_packet.c:243:\nnet/packet/af_packet.c:244:static void __fanout_unlink(struct sock *sk, struct packet_sock *po);\nnet/packet/af_packet.c:245:static void __fanout_link(struct sock *sk, struct packet_sock *po);\nnet/packet/af_packet.c:246:\nnet/packet/af_packet.c:247:#ifdef CONFIG_NETFILTER_EGRESS\nnet/packet/af_packet.c:248:static noinline struct sk_buff *nf_hook_direct_egress(struct sk_buff *skb)\nnet/packet/af_packet.c:249:{\nnet/packet/af_packet.c:250:\tstruct sk_buff *next, *head = NULL, *tail;\nnet/packet/af_packet.c:251:\tint rc;\nnet/packet/af_packet.c:252:\nnet/packet/af_packet.c:253:\trcu_read_lock();\nnet/packet/af_packet.c:254:\tfor (; skb != NULL; skb = next) {\nnet/packet/af_packet.c:255:\t\tnext = skb-\u003enext;\nnet/packet/af_packet.c:256:\t\tskb_mark_not_on_list(skb);\nnet/packet/af_packet.c:257:\nnet/packet/af_packet.c:258:\t\tif (!nf_hook_egress(skb, \u0026rc, skb-\u003edev))\nnet/packet/af_packet.c:259:\t\t\tcontinue;\nnet/packet/af_packet.c:260:\nnet/packet/af_packet.c:261:\t\tif (!head)\nnet/packet/af_packet.c:262:\t\t\thead = skb;\nnet/packet/af_packet.c:263:\t\telse\nnet/packet/af_packet.c:264:\t\t\ttail-\u003enext = skb;\nnet/packet/af_packet.c:265:\nnet/packet/af_packet.c:266:\t\ttail = skb;\nnet/packet/af_packet.c:267:\t}\nnet/packet/af_packet.c:268:\trcu_read_unlock();\nnet/packet/af_packet.c:269:\nnet/packet/af_packet.c:270:\treturn head;\nnet/packet/af_packet.c:271:}\nnet/packet/af_packet.c:272:#endif\nnet/packet/af_packet.c:273:\nnet/packet/af_packet.c:274:static int packet_xmit(const struct packet_sock *po, struct sk_buff *skb)\nnet/packet/af_packet.c:275:{\nnet/packet/af_packet.c:276:\tif (!packet_sock_flag(po, PACKET_SOCK_QDISC_BYPASS))\nnet/packet/af_packet.c:277:\t\treturn dev_queue_xmit(skb);\nnet/packet/af_packet.c:278:\nnet/packet/af_packet.c:279:#ifdef CONFIG_NETFILTER_EGRESS\nnet/packet/af_packet.c:280:\tif (nf_hook_egress_active()) {\nnet/packet/af_packet.c:281:\t\tskb = nf_hook_direct_egress(skb);\nnet/packet/af_packet.c:282:\t\tif (!skb)\nnet/packet/af_packet.c:283:\t\t\treturn NET_XMIT_DROP;\nnet/packet/af_packet.c:284:\t}\nnet/packet/af_packet.c:285:#endif\nnet/packet/af_packet.c:286:\treturn dev_direct_xmit(skb, packet_pick_tx_queue(skb));\nnet/packet/af_packet.c:287:}\nnet/packet/af_packet.c:288:\nnet/packet/af_packet.c:289:static struct net_device *packet_cached_dev_get(struct packet_sock *po)\nnet/packet/af_packet.c:290:{\nnet/packet/af_packet.c:291:\tstruct net_device *dev;\nnet/packet/af_packet.c:292:\nnet/packet/af_packet.c:293:\trcu_read_lock();\nnet/packet/af_packet.c:294:\tdev = rcu_dereference(po-\u003ecached_dev);\nnet/packet/af_packet.c:295:\tdev_hold(dev);\nnet/packet/af_packet.c:296:\trcu_read_unlock();\nnet/packet/af_packet.c:297:\nnet/packet/af_packet.c:298:\treturn dev;\nnet/packet/af_packet.c:299:}\nnet/packet/af_packet.c:300:\nnet/packet/af_packet.c:301:static void packet_cached_dev_assign(struct packet_sock *po,\nnet/packet/af_packet.c:302:\t\t\t\t struct net_device *dev)\nnet/packet/af_packet.c:303:{\nnet/packet/af_packet.c:304:\trcu_assign_pointer(po-\u003ecached_dev, dev);\nnet/packet/af_packet.c:305:}\nnet/packet/af_packet.c:306:\nnet/packet/af_packet.c:307:static void packet_cached_dev_reset(struct packet_sock *po)\nnet/packet/af_packet.c:308:{\nnet/packet/af_packet.c:309:\tRCU_INIT_POINTER(po-\u003ecached_dev, NULL);\nnet/packet/af_packet.c:310:}\nnet/packet/af_packet.c:311:\nnet/packet/af_packet.c:312:static u16 packet_pick_tx_queue(struct sk_buff *skb)\nnet/packet/af_packet.c:313:{\nnet/packet/af_packet.c:314:\tstruct net_device *dev = skb-\u003edev;\nnet/packet/af_packet.c:315:\tconst struct net_device_ops *ops = dev-\u003enetdev_ops;\nnet/packet/af_packet.c:316:\tint cpu = raw_smp_processor_id();\nnet/packet/af_packet.c:317:\tu16 queue_index;\nnet/packet/af_packet.c:318:\nnet/packet/af_packet.c:319:#ifdef CONFIG_XPS\nnet/packet/af_packet.c:320:\tskb-\u003esender_cpu = cpu + 1;\nnet/packet/af_packet.c:321:#endif\nnet/packet/af_packet.c:322:\tskb_record_rx_queue(skb, cpu % dev-\u003ereal_num_tx_queues);\nnet/packet/af_packet.c:323:\tif (ops-\u003endo_select_queue) {\nnet/packet/af_packet.c:324:\t\tqueue_index = ops-\u003endo_select_queue(dev, skb, NULL);\nnet/packet/af_packet.c:325:\t\tqueue_index = netdev_cap_txqueue(dev, queue_index);\nnet/packet/af_packet.c:326:\t} else {\nnet/packet/af_packet.c:327:\t\tqueue_index = netdev_pick_tx(dev, skb, NULL);\nnet/packet/af_packet.c:328:\t}\nnet/packet/af_packet.c:329:\nnet/packet/af_packet.c:330:\treturn queue_index;\nnet/packet/af_packet.c:331:}\nnet/packet/af_packet.c:332:\nnet/packet/af_packet.c:333:/* __register_prot_hook must be invoked through register_prot_hook\nnet/packet/af_packet.c:334: * or from a context in which asynchronous accesses to the packet\nnet/packet/af_packet.c:335: * socket is not possible (packet_create()).\nnet/packet/af_packet.c:336: */\nnet/packet/af_packet.c:337:static void __register_prot_hook(struct sock *sk)\nnet/packet/af_packet.c:338:{\nnet/packet/af_packet.c:339:\tstruct packet_sock *po = pkt_sk(sk);\nnet/packet/af_packet.c:340:\nnet/packet/af_packet.c:341:\tif (!packet_sock_flag(po, PACKET_SOCK_RUNNING)) {\nnet/packet/af_packet.c:342:\t\tif (po-\u003efanout)\nnet/packet/af_packet.c:343:\t\t\t__fanout_link(sk, po);\nnet/packet/af_packet.c:344:\t\telse\nnet/packet/af_packet.c:345:\t\t\tdev_add_pack(\u0026po-\u003eprot_hook);\nnet/packet/af_packet.c:346:\nnet/packet/af_packet.c:347:\t\tsock_hold(sk);\nnet/packet/af_packet.c:348:\t\tpacket_sock_flag_set(po, PACKET_SOCK_RUNNING, 1);\nnet/packet/af_packet.c:349:\t}\nnet/packet/af_packet.c:350:}\nnet/packet/af_packet.c:351:\nnet/packet/af_packet.c:352:static void register_prot_hook(struct sock *sk)\nnet/packet/af_packet.c:353:{\nnet/packet/af_packet.c:354:\tlockdep_assert_held_once(\u0026pkt_sk(sk)-\u003ebind_lock);\nnet/packet/af_packet.c:355:\t__register_prot_hook(sk);\nnet/packet/af_packet.c:356:}\nnet/packet/af_packet.c:357:\nnet/packet/af_packet.c:358:/* If the sync parameter is true, we will temporarily drop\nnet/packet/af_packet.c:359: * the po-\u003ebind_lock and do a synchronize_net to make sure no\nnet/packet/af_packet.c:360: * asynchronous packet processing paths still refer to the elements\nnet/packet/af_packet.c:361: * of po-\u003eprot_hook. If the sync parameter is false, it is the\nnet/packet/af_packet.c:362: * callers responsibility to take care of this.\nnet/packet/af_packet.c:363: */\nnet/packet/af_packet.c:364:static void __unregister_prot_hook(struct sock *sk, bool sync)\nnet/packet/af_packet.c:365:{\nnet/packet/af_packet.c:366:\tstruct packet_sock *po = pkt_sk(sk);\nnet/packet/af_packet.c:367:\nnet/packet/af_packet.c:368:\tlockdep_assert_held_once(\u0026po-\u003ebind_lock);\nnet/packet/af_packet.c:369:\nnet/packet/af_packet.c:370:\tpacket_sock_flag_set(po, PACKET_SOCK_RUNNING, 0);\nnet/packet/af_packet.c:371:\nnet/packet/af_packet.c:372:\tif (po-\u003efanout)\nnet/packet/af_packet.c:373:\t\t__fanout_unlink(sk, po);\nnet/packet/af_packet.c:374:\telse\nnet/packet/af_packet.c:375:\t\t__dev_remove_pack(\u0026po-\u003eprot_hook);\nnet/packet/af_packet.c:376:\nnet/packet/af_packet.c:377:\t__sock_put(sk);\nnet/packet/af_packet.c:378:\nnet/packet/af_packet.c:379:\tif (sync) {\nnet/packet/af_packet.c:380:\t\tspin_unlock(\u0026po-\u003ebind_lock);\nnet/packet/af_packet.c:381:\t\tsynchronize_net();\nnet/packet/af_packet.c:382:\t\tspin_lock(\u0026po-\u003ebind_lock);\nnet/packet/af_packet.c:383:\t}\nnet/packet/af_packet.c:384:}\nnet/packet/af_packet.c:385:\nnet/packet/af_packet.c:386:static void unregister_prot_hook(struct sock *sk, bool sync)\nnet/packet/af_packet.c:387:{\nnet/packet/af_packet.c:388:\tstruct packet_sock *po = pkt_sk(sk);\nnet/packet/af_packet.c:389:\nnet/packet/af_packet.c:390:\tif (packet_sock_flag(po, PACKET_SOCK_RUNNING))\nnet/packet/af_packet.c:391:\t\t__unregister_prot_hook(sk, sync);\nnet/packet/af_packet.c:392:}\nnet/packet/af_packet.c:393:\nnet/packet/af_packet.c:394:static inline struct page * __pure pgv_to_page(void *addr)\nnet/packet/af_packet.c:395:{\nnet/packet/af_packet.c:396:\tif (is_vmalloc_addr(addr))\nnet/packet/af_packet.c:397:\t\treturn vmalloc_to_page(addr);\nnet/packet/af_packet.c:398:\treturn virt_to_page(addr);\nnet/packet/af_packet.c:399:}\nnet/packet/af_packet.c:400:\nnet/packet/af_packet.c:401:static void __packet_set_status(struct packet_sock *po, void *frame, int status)\nnet/packet/af_packet.c:402:{\nnet/packet/af_packet.c:403:\tunion tpacket_uhdr h;\nnet/packet/af_packet.c:404:\nnet/packet/af_packet.c:405:\t/* WRITE_ONCE() are paired with READ_ONCE() in __packet_get_status */\nnet/packet/af_packet.c:406:\nnet/packet/af_packet.c:407:\th.raw = frame;\nnet/packet/af_packet.c:408:\tswitch (po-\u003etp_version) {\nnet/packet/af_packet.c:409:\tcase TPACKET_V1:\nnet/packet/af_packet.c:410:\t\tWRITE_ONCE(h.h1-\u003etp_status, status);\nnet/packet/af_packet.c:411:\t\tflush_dcache_page(pgv_to_page(\u0026h.h1-\u003etp_status));\nnet/packet/af_packet.c:412:\t\tbreak;\nnet/packet/af_packet.c:413:\tcase TPACKET_V2:\nnet/packet/af_packet.c:414:\t\tWRITE_ONCE(h.h2-\u003etp_status, status);\nnet/packet/af_packet.c:415:\t\tflush_dcache_page(pgv_to_page(\u0026h.h2-\u003etp_status));\nnet/packet/af_packet.c:416:\t\tbreak;\nnet/packet/af_packet.c:417:\tcase TPACKET_V3:\nnet/packet/af_packet.c:418:\t\tWRITE_ONCE(h.h3-\u003etp_status, status);\nnet/packet/af_packet.c:419:\t\tflush_dcache_page(pgv_to_page(\u0026h.h3-\u003etp_status));\nnet/packet/af_packet.c:420:\t\tbreak;\nnet/packet/af_packet.c:421:\tdefault:\nnet/packet/af_packet.c:422:\t\tWARN(1, \"TPACKET version not supported.\\n\");\nnet/packet/af_packet.c:423:\t\tBUG();\nnet/packet/af_packet.c:424:\t}\nnet/packet/af_packet.c:425:\nnet/packet/af_packet.c:426:\tsmp_wmb();\nnet/packet/af_packet.c:427:}\nnet/packet/af_packet.c:428:\nnet/packet/af_packet.c:429:static int __packet_get_status(const struct packet_sock *po, void *frame)\nnet/packet/af_packet.c:430:{\nnet/packet/af_packet.c:431:\tunion tpacket_uhdr h;\nnet/packet/af_packet.c:432:\nnet/packet/af_packet.c:433:\tsmp_rmb();\nnet/packet/af_packet.c:434:\nnet/packet/af_packet.c:435:\t/* READ_ONCE() are paired with WRITE_ONCE() in __packet_set_status */\nnet/packet/af_packet.c:436:\nnet/packet/af_packet.c:437:\th.raw = frame;\nnet/packet/af_packet.c:438:\tswitch (po-\u003etp_version) {\nnet/packet/af_packet.c:439:\tcase TPACKET_V1:\nnet/packet/af_packet.c:440:\t\tflush_dcache_page(pgv_to_page(\u0026h.h1-\u003etp_status));\nnet/packet/af_packet.c:441:\t\treturn READ_ONCE(h.h1-\u003etp_status);\nnet/packet/af_packet.c:442:\tcase TPACKET_V2:\nnet/packet/af_packet.c:443:\t\tflush_dcache_page(pgv_to_page(\u0026h.h2-\u003etp_status));\nnet/packet/af_packet.c:444:\t\treturn READ_ONCE(h.h2-\u003etp_status);\nnet/packet/af_packet.c:445:\tcase TPACKET_V3:\nnet/packet/af_packet.c:446:\t\tflush_dcache_page(pgv_to_page(\u0026h.h3-\u003etp_status));\nnet/packet/af_packet.c:447:\t\treturn READ_ONCE(h.h3-\u003etp_status);\nnet/packet/af_packet.c:448:\tdefault:\nnet/packet/af_packet.c:449:\t\tWARN(1, \"TPACKET version not supported.\\n\");\nnet/packet/af_packet.c:450:\t\tBUG();\nnet/packet/af_packet.c:451:\t\treturn 0;\nnet/packet/af_packet.c:452:\t}\nnet/packet/af_packet.c:453:}\nnet/packet/af_packet.c:454:\nnet/packet/af_packet.c:455:static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts,\nnet/packet/af_packet.c:456:\t\t\t\t unsigned int flags)\nnet/packet/af_packet.c:457:{\nnet/packet/af_packet.c:458:\tstruct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);\nnet/packet/af_packet.c:459:\nnet/packet/af_packet.c:460:\tif (shhwtstamps \u0026\u0026\nnet/packet/af_packet.c:461:\t (flags \u0026 SOF_TIMESTAMPING_RAW_HARDWARE) \u0026\u0026\nnet/packet/af_packet.c:462:\t ktime_to_timespec64_cond(shhwtstamps-\u003ehwtstamp, ts))\nnet/packet/af_packet.c:463:\t\treturn TP_STATUS_TS_RAW_HARDWARE;\nnet/packet/af_packet.c:464:\nnet/packet/af_packet.c:465:\tif ((flags \u0026 SOF_TIMESTAMPING_SOFTWARE) \u0026\u0026\nnet/packet/af_packet.c:466:\t ktime_to_timespec64_cond(skb_tstamp(skb), ts))\nnet/packet/af_packet.c:467:\t\treturn TP_STATUS_TS_SOFTWARE;\nnet/packet/af_packet.c:468:\nnet/packet/af_packet.c:469:\treturn 0;\nnet/packet/af_packet.c:470:}\nnet/packet/af_packet.c:471:\nnet/packet/af_packet.c:472:static __u32 __packet_set_timestamp(struct packet_sock *po, void *frame,\nnet/packet/af_packet.c:473:\t\t\t\t struct sk_buff *skb)\nnet/packet/af_packet.c:474:{\nnet/packet/af_packet.c:475:\tunion tpacket_uhdr h;\nnet/packet/af_packet.c:476:\tstruct timespec64 ts;\nnet/packet/af_packet.c:477:\t__u32 ts_status;\nnet/packet/af_packet.c:478:\nnet/packet/af_packet.c:479:\tif (!(ts_status = tpacket_get_timestamp(skb, \u0026ts, READ_ONCE(po-\u003etp_tstamp))))\nnet/packet/af_packet.c:480:\t\treturn 0;\nnet/packet/af_packet.c:481:\nnet/packet/af_packet.c:482:\th.raw = frame;\nnet/packet/af_packet.c:483:\t/*\nnet/packet/af_packet.c:484:\t * versions 1 through 3 overflow the timestamps in y2106, since they\nnet/packet/af_packet.c:485:\t * all store the seconds in a 32-bit unsigned integer.\nnet/packet/af_packet.c:486:\t * If we create a version 4, that should have a 64-bit timestamp,\nnet/packet/af_packet.c:487:\t * either 64-bit seconds + 32-bit nanoseconds, or just 64-bit\nnet/packet/af_packet.c:488:\t * nanoseconds.\nnet/packet/af_packet.c:489:\t */\nnet/packet/af_packet.c:490:\tswitch (po-\u003etp_version) {\nnet/packet/af_packet.c:491:\tcase TPACKET_V1:\nnet/packet/af_packet.c:492:\t\th.h1-\u003etp_sec = ts.tv_sec;\nnet/packet/af_packet.c:493:\t\th.h1-\u003etp_usec = ts.tv_nsec / NSEC_PER_USEC;\nnet/packet/af_packet.c:494:\t\tbreak;\nnet/packet/af_packet.c:495:\tcase TPACKET_V2:\nnet/packet/af_packet.c:496:\t\th.h2-\u003etp_sec = ts.tv_sec;\nnet/packet/af_packet.c:497:\t\th.h2-\u003etp_nsec = ts.tv_nsec;\nnet/packet/af_packet.c:498:\t\tbreak;\nnet/packet/af_packet.c:499:\tcase TPACKET_V3:\nnet/packet/af_packet.c:500:\t\th.h3-\u003etp_sec = ts.tv_sec;\n\n"
} |
| 13/2 | 2026/09/29 08:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19394 output: 34 thoughts: 46 Thoughts: Here's my take on the thought process: **Diving into Packet Reception in AF_PACKET** Alright, let's get down to brass tacks. I need to understand how this `dev_has_header(dev)` function is being utilized within the packet reception routines, specifically within the context of the `AF_PACKET` socket family. To do this properly, I'm going to head straight into the `net/packet/af_packet.c` file. My focus will be on the core receive functions: `packet_rcv` and `tpacket_rcv`. By carefully examining how `dev_has_header(dev)` is called and used inside those routines, I should be able to deduce its exact role in the packet processing flow, and identify where the device's header capabilities come into play during packet reception. This granular analysis is crucial for understanding the intricacies of the driver interaction within the networking stack. |
| 14/2 | 2026/09/29 08:44 | tool | grepper |
0mArgs:{
"Expression": "dev_has_header",
"PathPrefix": "net/packet/af_packet.c"
}Results: {
"Output": "net/packet/af_packet.c=115=On receive:\n--\nnet/packet/af_packet.c-117-\nnet/packet/af_packet.c:118:Incoming, dev_has_header(dev) == true\nnet/packet/af_packet.c-119- mac_header -\u003e ll header\n--\nnet/packet/af_packet.c-121-\nnet/packet/af_packet.c:122:Outgoing, dev_has_header(dev) == true\nnet/packet/af_packet.c-123- mac_header -\u003e ll header\n--\nnet/packet/af_packet.c-125-\nnet/packet/af_packet.c:126:Incoming, dev_has_header(dev) == false\nnet/packet/af_packet.c-127- mac_header -\u003e data\n--\nnet/packet/af_packet.c-131-\nnet/packet/af_packet.c:132:Outgoing, dev_has_header(dev) == false\nnet/packet/af_packet.c-133- mac_header -\u003e data. ll header is invisible to us.\n--\nnet/packet/af_packet.c=136=Resume\nnet/packet/af_packet.c:137: If dev_has_header(dev) == false we are unable to restore the ll header,\nnet/packet/af_packet.c-138- because it is invisible to us.\n--\nnet/packet/af_packet.c=141=On transmit:\n--\nnet/packet/af_packet.c-143-\nnet/packet/af_packet.c:144:dev_has_header(dev) == true\nnet/packet/af_packet.c-145- mac_header -\u003e ll header\n--\nnet/packet/af_packet.c-147-\nnet/packet/af_packet.c:148:dev_has_header(dev) == false (ll header is invisible to us)\nnet/packet/af_packet.c-149- mac_header -\u003e data\n--\nnet/packet/af_packet.c=1872=static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-1919-\t */\nnet/packet/af_packet.c:1920:\tif (dev_has_header(dev))\nnet/packet/af_packet.c-1921-\t\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n--\nnet/packet/af_packet.c=2143=static int packet_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2164-\nnet/packet/af_packet.c:2165:\tif (dev_has_header(dev)) {\nnet/packet/af_packet.c-2166-\t\t/* The device has an explicit notion of ll header,\n--\nnet/packet/af_packet.c=2256=static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2291-\nnet/packet/af_packet.c:2292:\tif (dev_has_header(dev)) {\nnet/packet/af_packet.c-2293-\t\tif (sk-\u003esk_type != SOCK_DGRAM)\n"
} |
| 15/2 | 2026/09/29 08:44 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 20565 output: 132 thoughts: 684 Thoughts: **Analyzing a Network Packet Reception Vulnerability** Okay, here's the breakdown of what I've been looking at. It seems like `packet_rcv()` and `tpacket_rcv()` already had a critical check: `if (dev_has_header(dev))`. However, `packet_rcv_spkt()` was missing this, which led to a crash – specifically, `skb_push` with a massive negative length, triggering `skb_under_panic()`. The proposed fix simply adds that missing `if (dev_has_header(dev))` before the `skb_push` call. Now, let's critically analyze this. Is it a real vulnerability? Absolutely. `WorthFuzzing` is definitely true. `packet_rcv_spkt` is called when receiving packets through a `SOCK_PACKET` socket. That's core networking territory, meaning standard network fuzzing techniques (packet injection, using tun/tap, veth, etc.) can reach it. The change directly touches how the kernel handles packet reception and the underlying SKB manipulation logic. This is definitely something that needs fuzzing. For `FocusSymbols`, it’s clear that `packet_rcv_spkt` is the key function modified. It’s the only function where this logic was modified. Although `packet_create` is related, it is not modified. Given its specificity to `SOCK_PACKET`, it's not a function that's ubiquitous in the networking stack. So, let’s keep `FocusSymbols` as `["packet_rcv_spkt"]`. Regarding `EnableConfigs`, we need to determine the required configurations. `net/packet/Kconfig` points to `CONFIG_PACKET`. A quick sanity check of `net/packet/Makefile` shows that `CONFIG_PACKET` is all we need. Nothing else seems relevant. So, my `EnableConfigs` list is just `["PACKET"]`. Let's summarize my reasoning concisely: * The patch adds the `dev_has_header()` check in `packet_rcv_spkt()` before calling `skb_push()` to avoid an `skb_under_panic()` when receiving packets from devices without a visible link-layer header. Without the header, `mac_header` can remain uninitialized, which can lead to negative `skb_push` arguments. * The patch is worth fuzzing because it alters packet reception flow in the core AF_PACKET subsystem, which is reachable via standard networking techniques, such as SOCK_PACKET sockets and virtual netdevs. * The focus symbol is `packet_rcv_spkt`, and the required config is `PACKET`. Okay, I'm satisfied. Let's call `set-results`. |
| 16/2 | 2026/09/29 08:44 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"PACKET"
],
"FocusSymbols": [
"packet_rcv_spkt"
],
"Reasoning": "The patch modifies the packet reception path in packet_rcv_spkt() for AF_PACKET SOCK_PACKET sockets to check dev_has_header(dev) before restoring the link-layer header via skb_push(). This alters reachable core networking logic and prevents skb_under_panic() when handling packets on devices without visible link-layer headers. It is directly testable and reachable in virtualized environments.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"PACKET"
],
"FocusSymbols": [
"packet_rcv_spkt"
],
"Reasoning": "The patch modifies the packet reception path in packet_rcv_spkt() for AF_PACKET SOCK_PACKET sockets to check dev_has_header(dev) before restoring the link-layer header via skb_push(). This alters reachable core networking logic and prevents skb_under_panic() when handling packets on devices without visible link-layer headers. It is directly testable and reachable in virtualized environments.",
"WorthFuzzing": true
} |
| 17/1 | 2026/09/29 08:44 | action | If |
2mArgs:{
"WorthFuzzing": true
}Results: null |
| 18/2 | 2026/09/29 08:44 | agent | kmsan-evaluator |
2mModel:core Args: null Results: {
"KMSANReasoning": "The patch adds a check `if (dev_has_header(dev))` before calling `skb_push(skb, skb-\u003edata - skb_mac_header(skb))` in `packet_rcv_spkt()` to align it with `packet_rcv()` and `tpacket_rcv()`. This prevents invoking `skb_push()` on devices without link-layer headers where an unset/sentinel `mac_header` results in an invalid push offset triggering `skb_under_panic()`.\n\nThe change does not introduce any uninitialized memory allocations, padding leaks to userspace, or uninitialized branch conditions. The existing packet buffer data is already properly tracked and bounded. The issue addressed is a panic / bounds check failure (`skb_under_panic()`), which falls under standard bug detectors rather than KMSAN. Therefore, a dedicated KMSAN session is not required.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
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: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit 34a423dbdde5ac62b44ce70451475e6ef0596509
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Sep 29 08:43:10 2026 +0000
syz-cluster: applied patch under review
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 7c83e01526edc..40c67b86a1735 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1911,7 +1911,14 @@ static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,
spkt = &PACKET_SKB_CB(skb)->sa.pkt;
- skb_push(skb, skb->data - skb_mac_header(skb));
+ /* Only a device with a visible ll header can have it restored, which is
+ * the test packet_rcv() and tpacket_rcv() already make. For the others
+ * the header is invisible and the subtraction has no meaning: a producer
+ * that left skb->mac_header at its 0xFFFF sentinel turns it into a huge
+ * negative length that trips skb_under_panic() in softirq context.
+ */
+ if (dev_has_header(dev))
+ skb_push(skb, skb->data - skb_mac_header(skb));
/*
* The SOCK_PACKET socket receives _all_ frames.
|
| 19/3 | 2026/09/29 08:44 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 2226 output: 38 thoughts: 430 Thoughts: **Analyzing a Recent Patch in `af_packet.c`** Okay, so I'm looking at a patch within `net/packet/af_packet.c`, specifically the `packet_rcv_spkt` function. The key change seems to be around how the link-layer header is handled, specifically within the `skb_push()` operation. It appears we're now conditionally pushing the link layer header back onto the `skb` (socket buffer). The original code simply did `skb_push(skb, skb->data - skb_mac_header(skb))`. Now, there's a check: `if (dev_has_header(dev))`. This makes me think there was a problem with pushing the header back under some circumstances. The comment provides a crucial clue: "Only a device with a visible ll header can have it restored..." and there is a note about a previous check in `packet_rcv()` and `tpacket_rcv()`. In cases where the header is "invisible", the subtraction could create a nonsensical result, potentially a huge negative length, leading to a panic within a softirq context (likely `skb_under_panic()`). This sounds like it could be related to devices that don't have a standard link-layer header or are handled differently in this regard. The implication is that on certain device types, we *don't* want to restore the link-layer header because it's either not present or handled in a different way. The rest of the function remains the same, where all frames are received by `SOCK_PACKET`. Let me read this file with `read-file` to get a better understanding. |
| 20/3 | 2026/09/29 08:44 | tool | read-file |
0mArgs:{
"File": "net/packet/af_packet.c",
"FirstLine": 1890,
"LineCount": 80
}Results: {
"Contents": "1890:\t\t *\tpush it back.\n1891:\t\t *\n1892:\t\t *\tFor outgoing ones skb-\u003edata == skb_mac_header(skb)\n1893:\t\t *\tso that this procedure is noop.\n1894:\t\t */\n1895:\t\n1896:\t\tif (skb-\u003epkt_type == PACKET_LOOPBACK)\n1897:\t\t\tgoto out;\n1898:\t\n1899:\t\tif (!net_eq(dev_net(dev), sock_net(sk)))\n1900:\t\t\tgoto out;\n1901:\t\n1902:\t\tskb = skb_share_check(skb, GFP_ATOMIC);\n1903:\t\tif (skb == NULL)\n1904:\t\t\tgoto oom;\n1905:\t\n1906:\t\t/* drop any routing info */\n1907:\t\tskb_dst_drop(skb);\n1908:\t\n1909:\t\t/* drop conntrack reference */\n1910:\t\tnf_reset_ct(skb);\n1911:\t\n1912:\t\tspkt = \u0026PACKET_SKB_CB(skb)-\u003esa.pkt;\n1913:\t\n1914:\t\t/* Only a device with a visible ll header can have it restored, which is\n1915:\t\t * the test packet_rcv() and tpacket_rcv() already make. For the others\n1916:\t\t * the header is invisible and the subtraction has no meaning: a producer\n1917:\t\t * that left skb-\u003emac_header at its 0xFFFF sentinel turns it into a huge\n1918:\t\t * negative length that trips skb_under_panic() in softirq context.\n1919:\t\t */\n1920:\t\tif (dev_has_header(dev))\n1921:\t\t\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n1922:\t\n1923:\t\t/*\n1924:\t\t *\tThe SOCK_PACKET socket receives _all_ frames.\n1925:\t\t */\n1926:\t\n1927:\t\tspkt-\u003espkt_family = dev-\u003etype;\n1928:\t\tstrscpy(spkt-\u003espkt_device, dev-\u003ename, sizeof(spkt-\u003espkt_device));\n1929:\t\tspkt-\u003espkt_protocol = skb-\u003eprotocol;\n1930:\t\n1931:\t\t/*\n1932:\t\t *\tCharge the memory to the socket. This is done specifically\n1933:\t\t *\tto prevent sockets using all the memory up.\n1934:\t\t */\n1935:\t\n1936:\t\tif (sock_queue_rcv_skb(sk, skb) == 0)\n1937:\t\t\treturn 0;\n1938:\t\n1939:\tout:\n1940:\t\tkfree_skb(skb);\n1941:\toom:\n1942:\t\treturn 0;\n1943:\t}\n1944:\t\n1945:\tstatic void packet_parse_headers(struct sk_buff *skb, struct socket *sock)\n1946:\t{\n1947:\t\tint depth;\n1948:\t\n1949:\t\t/* On TX skb-\u003edata is the L2 header; anchor it for all socket types. */\n1950:\t\tskb_reset_mac_header(skb);\n1951:\t\n1952:\t\tif ((!skb-\u003eprotocol || skb-\u003eprotocol == htons(ETH_P_ALL)) \u0026\u0026\n1953:\t\t sock-\u003etype == SOCK_RAW)\n1954:\t\t\tskb-\u003eprotocol = dev_parse_header_protocol(skb);\n1955:\t\n1956:\t\tskb_probe_transport_header(skb);\n1957:\t\n1958:\t\t/* Move network header to the right position for VLAN tagged packets */\n1959:\t\tif (likely(skb-\u003edev-\u003etype == ARPHRD_ETHER) \u0026\u0026\n1960:\t\t eth_type_vlan(skb-\u003eprotocol) \u0026\u0026\n1961:\t\t vlan_get_protocol_and_depth(skb, skb-\u003eprotocol, \u0026depth) != 0)\n1962:\t\t\tskb_set_network_header(skb, depth);\n1963:\t}\n1964:\t\n1965:\t/*\n1966:\t *\tOutput a raw packet to a device layer. This bypasses all the other\n1967:\t *\tprotocol layers and you must therefore supply it with a complete frame\n1968:\t */\n1969:\t\n"
} |
| 21/3 | 2026/09/29 08:44 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 4284 output: 38 thoughts: 31 Thoughts: Here's my analysis of the provided request, assuming I'm an expert in network protocols and kernel internals: **Diving into Packet Reception Context** Okay, so I need to understand the function `packet_rcv_spkt` and its role within the larger system. The request explicitly points me to lines 1880-1910, which I immediately interpret as the critical context I need. My first step is to quickly pull up the relevant code snippet and begin by surveying the immediately surrounding code to establish the overall control flow. What functions call it? What functions does it call? What data structures are involved? What locks are held when it's called? Knowing the "who, what, when, and where" of the function's execution is paramount to comprehending its purpose. Within lines 1880-1910, I'll be looking for clues about where incoming packets are being processed in the networking stack. I'll pay close attention to the data structures being manipulated: things like `sk_buff` (the socket buffer), headers, checksums, and potentially any statistics being updated. I'll also be searching for references to network devices or socket objects; these will tell me where these packets are headed and who is consuming them. The presence of any error handling or congestion control logic within the region will be of great interest too, because it highlights the function's role in the network's reliability and performance. I know I have a limited window, but hopefully it's enough to get the core concepts. Based on the surrounding code, I'll build a mental model of how this function interacts with the rest of the packet processing pipeline. Does it perform initial packet filtering? Is it responsible for dispatching to higher-layer protocols? Is it responsible for pushing the data to the correct sockets? My expert knowledge means I can quickly infer what's missing and prioritize the important pieces of information. |
| 22/3 | 2026/09/29 08:44 | tool | read-file |
0mArgs:{
"File": "net/packet/af_packet.c",
"FirstLine": 1865,
"LineCount": 40
}Results: {
"Contents": "1865:\t\treturn likely(eth_hdr(skb)-\u003eh_proto == htons(ETH_P_8021Q));\n1866:\t}\n1867:\t\n1868:\tstatic const struct proto_ops packet_ops;\n1869:\t\n1870:\tstatic const struct proto_ops packet_ops_spkt;\n1871:\t\n1872:\tstatic int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,\n1873:\t\t\t\t struct packet_type *pt, struct net_device *orig_dev)\n1874:\t{\n1875:\t\tstruct sock *sk;\n1876:\t\tstruct sockaddr_pkt *spkt;\n1877:\t\n1878:\t\t/*\n1879:\t\t *\tWhen we registered the protocol we saved the socket in the data\n1880:\t\t *\tfield for just this event.\n1881:\t\t */\n1882:\t\n1883:\t\tsk = pt-\u003eaf_packet_priv;\n1884:\t\n1885:\t\t/*\n1886:\t\t *\tYank back the headers [hope the device set this\n1887:\t\t *\tright or kerboom...]\n1888:\t\t *\n1889:\t\t *\tIncoming packets have ll header pulled,\n1890:\t\t *\tpush it back.\n1891:\t\t *\n1892:\t\t *\tFor outgoing ones skb-\u003edata == skb_mac_header(skb)\n1893:\t\t *\tso that this procedure is noop.\n1894:\t\t */\n1895:\t\n1896:\t\tif (skb-\u003epkt_type == PACKET_LOOPBACK)\n1897:\t\t\tgoto out;\n1898:\t\n1899:\t\tif (!net_eq(dev_net(dev), sock_net(sk)))\n1900:\t\t\tgoto out;\n1901:\t\n1902:\t\tskb = skb_share_check(skb, GFP_ATOMIC);\n1903:\t\tif (skb == NULL)\n1904:\t\t\tgoto oom;\n"
} |
| 23/3 | 2026/09/29 08:44 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 5328 output: 29 thoughts: 31 Thoughts: Here's my attempt at summarizing the thought process, tailored for an expert audience: **Analyzing Packet Reception with Device Header Information** Okay, so I'm diving into the packet reception paths, specifically focusing on how `packet_rcv()` and `tpacket_rcv()` interact with `dev_has_header(dev)`. I need to understand the nuances of how these functions handle the presence or absence of a device-specific header. This is critical for performance tuning and, more importantly, understanding the implications for things like zero-copy reception and different NIC architectures. I'm thinking about the different scenarios. If `dev_has_header(dev)` returns true, does that mean the driver has already parsed and stripped the hardware header, or is it still present in the received buffer and expected to be handled later? How does this influence the way the packet is presented to the network stack, and does this flag dictate memory mapping choices. I’m particularly interested in looking at the paths where the presence of a hardware header affects how the packet is put into the sk_buff. This is where the differences between different types of network drivers become important. I should investigate the conditional compilation and how it affects the different pathways. Essentially, I want to map out how this function call impacts the data flow through the networking stack, and whether this impacts the type of zero-copy optimizations that may be employed. |
| 24/3 | 2026/09/29 08:44 | tool | grepper |
0mArgs:{
"Expression": "dev_has_header",
"PathPrefix": "net/packet/"
}Results: {
"Output": "net/packet/af_packet.c=115=On receive:\n--\nnet/packet/af_packet.c-117-\nnet/packet/af_packet.c:118:Incoming, dev_has_header(dev) == true\nnet/packet/af_packet.c-119- mac_header -\u003e ll header\n--\nnet/packet/af_packet.c-121-\nnet/packet/af_packet.c:122:Outgoing, dev_has_header(dev) == true\nnet/packet/af_packet.c-123- mac_header -\u003e ll header\n--\nnet/packet/af_packet.c-125-\nnet/packet/af_packet.c:126:Incoming, dev_has_header(dev) == false\nnet/packet/af_packet.c-127- mac_header -\u003e data\n--\nnet/packet/af_packet.c-131-\nnet/packet/af_packet.c:132:Outgoing, dev_has_header(dev) == false\nnet/packet/af_packet.c-133- mac_header -\u003e data. ll header is invisible to us.\n--\nnet/packet/af_packet.c=136=Resume\nnet/packet/af_packet.c:137: If dev_has_header(dev) == false we are unable to restore the ll header,\nnet/packet/af_packet.c-138- because it is invisible to us.\n--\nnet/packet/af_packet.c=141=On transmit:\n--\nnet/packet/af_packet.c-143-\nnet/packet/af_packet.c:144:dev_has_header(dev) == true\nnet/packet/af_packet.c-145- mac_header -\u003e ll header\n--\nnet/packet/af_packet.c-147-\nnet/packet/af_packet.c:148:dev_has_header(dev) == false (ll header is invisible to us)\nnet/packet/af_packet.c-149- mac_header -\u003e data\n--\nnet/packet/af_packet.c=1872=static int packet_rcv_spkt(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-1919-\t */\nnet/packet/af_packet.c:1920:\tif (dev_has_header(dev))\nnet/packet/af_packet.c-1921-\t\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n--\nnet/packet/af_packet.c=2143=static int packet_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2164-\nnet/packet/af_packet.c:2165:\tif (dev_has_header(dev)) {\nnet/packet/af_packet.c-2166-\t\t/* The device has an explicit notion of ll header,\n--\nnet/packet/af_packet.c=2256=static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2291-\nnet/packet/af_packet.c:2292:\tif (dev_has_header(dev)) {\nnet/packet/af_packet.c-2293-\t\tif (sk-\u003esk_type != SOCK_DGRAM)\n"
} |
| 25/3 | 2026/09/29 08:44 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 6573 output: 38 thoughts: 31 Thoughts: Okay, here's my interpretation of what's going on, thinking through those specific lines of code as if *I* were working through it: **Diving into Packet Reception** Alright, I'm zeroing in on the core of packet reception now. My focus is on understanding the interaction between `packet_rcv` (line 2165) and `tpacket_rcv` (line 2292). I need to figure out the roles each plays in the bigger picture of how network packets are processed when they arrive. Line 2165 in `packet_rcv` must be a crucial point where the standard networking stack interacts with the packet data. I suspect it's responsible for the initial processing, filtering, and potentially forwarding of the incoming packets. Conversely, I think line 2292 in `tpacket_rcv` is related to the more efficient, perhaps zero-copy, packet capturing using the `TPACKET` mechanism. My initial hypothesis is that `tpacket_rcv` is called, potentially from `packet_rcv`, to handle high-performance packet capture and buffering, which is likely a separate code path. But I'll need to confirm that. Essentially, I need to see how packets are funneled through the system, and where the performance-focused `tpacket_rcv` comes into play. I'll probably need to look at how these two routines are called and what data structures they're working with, paying close attention to any shared buffers or synchronization mechanisms. I bet I'll find an optimization strategy built into the overall design. |
| 26/3 | 2026/09/29 08:44 | tool | read-file |
0mArgs:{
"File": "net/packet/af_packet.c",
"FirstLine": 2160,
"LineCount": 30
}Results: {
"Contents": "2160:\t\tif (!net_eq(dev_net(dev), sock_net(sk)))\n2161:\t\t\tgoto drop;\n2162:\t\n2163:\t\tskb-\u003edev = dev;\n2164:\t\n2165:\t\tif (dev_has_header(dev)) {\n2166:\t\t\t/* The device has an explicit notion of ll header,\n2167:\t\t\t * exported to higher levels.\n2168:\t\t\t *\n2169:\t\t\t * Otherwise, the device hides details of its frame\n2170:\t\t\t * structure, so that corresponding packet head is\n2171:\t\t\t * never delivered to user.\n2172:\t\t\t */\n2173:\t\t\tif (sk-\u003esk_type != SOCK_DGRAM)\n2174:\t\t\t\tskb_push(skb, skb-\u003edata - skb_mac_header(skb));\n2175:\t\t\telse if (skb-\u003epkt_type == PACKET_OUTGOING) {\n2176:\t\t\t\t/* Special case: outgoing packets have ll header at head */\n2177:\t\t\t\tskb_pull(skb, skb_network_offset(skb));\n2178:\t\t\t}\n2179:\t\t}\n2180:\t\n2181:\t\tsnaplen = skb_frags_readable(skb) ? skb-\u003elen : skb_headlen(skb);\n2182:\t\n2183:\t\tres = run_filter(skb, sk, snaplen);\n2184:\t\tif (!res)\n2185:\t\t\tgoto drop_n_restore;\n2186:\t\tif (snaplen \u003e res)\n2187:\t\t\tsnaplen = res;\n2188:\t\n2189:\t\tif (atomic_read(\u0026sk-\u003esk_rmem_alloc) \u003e= sk-\u003esk_rcvbuf)\n"
} |
| 27/3 | 2026/09/29 08:44 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 7465 output: 30 thoughts: 230 Thoughts: **Analyzing the Potential Vulnerability in `packet_rcv_spkt`** Okay, let's break this down. I'm looking at `packet_rcv_spkt` and immediately see a potential issue. Before the patch, the code was doing this: ```c spkt = &PACKET_SKB_CB(skb)->sa.pkt; skb_push(skb, skb->data - skb_mac_header(skb)); ``` The problem jumps out at me right away, especially with devices where `dev_has_header(dev)` is false – devices like `tun` or some virtual IP setups, where the link-layer header is essentially invisible to the network stack. In these cases, `skb->mac_header` might be uninitialized, or worse, set to a sentinel value like `0xFFFF`. The subtraction, `skb->data - skb_mac_header(skb)`, becomes nonsensical and leads to a massive push or an underflow condition. This, of course, triggers `skb_under_panic()`, which is not something we want. The patch corrects this by inserting a straightforward check: `if (dev_has_header(dev))`. This makes sure we *only* perform the `skb_push` operation when it's appropriate, thereby avoiding the underflow. Next, I need to check how this function is used by socket recvmsg. I'll need to explore the `packet_recvmsg` function, or the related socket recvmsg functions for `SOCK_PACKET`. |
| 28/3 | 2026/09/29 08:44 | tool | grepper |
0mArgs:{
"Expression": "packet_ops_spkt",
"PathPrefix": "net/packet/"
}Results: {
"Output": "net/packet/af_packet.c=1868=static const struct proto_ops packet_ops;\nnet/packet/af_packet.c-1869-\nnet/packet/af_packet.c:1870:static const struct proto_ops packet_ops_spkt;\nnet/packet/af_packet.c-1871-\n--\nnet/packet/af_packet.c=3402=static int packet_create(struct net *net, struct socket *sock, int protocol,\n--\nnet/packet/af_packet.c-3424-\tif (sock-\u003etype == SOCK_PACKET)\nnet/packet/af_packet.c:3425:\t\tsock-\u003eops = \u0026packet_ops_spkt;\nnet/packet/af_packet.c-3426-\n--\nnet/packet/af_packet.c=4726=static int packet_mmap(struct file *file, struct socket *sock,\n--\nnet/packet/af_packet.c-4787-\nnet/packet/af_packet.c:4788:static const struct proto_ops packet_ops_spkt = {\nnet/packet/af_packet.c-4789-\t.family =\tPF_PACKET,\n"
} |
| 29/3 | 2026/09/29 08:44 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 8390 output: 28 thoughts: 10 Thoughts: Okay, here's my attempt at summarizing the thought process, tailored for an expert audience, and written in the first person: **Diving into `packet_recvmsg`** Alright, let's dissect this `packet_recvmsg` function. I'm immediately interested in the implementation details here. We're talking about receiving packets, and the implications of `recvmsg` are significant—it hints at gathering ancillary data along with the main payload. This suggests we're dealing with raw sockets or possibly a more advanced use case involving control messages. I need to be thinking about potential issues with buffer sizes, memory allocation, and the overall efficiency, especially if this is in a high-throughput environment. I'm mentally running through possible scenarios: Is this handling IPv4, IPv6, or both? What about different protocol families like Ethernet? I need to look for any logic related to address family checks and protocol demultiplexing. The `recvmsg` system call itself can be tricky. I'm wondering if there's any clever use of MSG_ERRQUEUE or MSG_PEEK flags here, or if we're doing a more standard blocking or non-blocking read. I'll be paying close attention to error handling. The return codes from `recvmsg` are crucial. What are the common error conditions we're looking for (EAGAIN, EWOULDBLOCK, EINTR, etc.)? And how is the code dealing with them? Are there retries with backoff? Are there any potentially unhandled edge cases that could lead to resource leaks or denial-of-service vulnerabilities? I also need to check how the ancillary data is handled. Are we safely parsing control messages and properly validating their contents? This is a prime spot for buffer overflows or format string vulnerabilities if not handled carefully. I need to see how the ancillary data is unpacked and interpreted, particularly anything related to timestamps, packet information, or even security-related attributes. My spider senses are tingling for potential race conditions if the ancillary data is being updated by another thread or process. Ultimately, I'm expecting this to be a well-optimized function. I'll be looking for any signs of performance bottlenecks, such as excessive memory copying or blocking operations that could impede responsiveness. Let's see what we've got. |
| 30/3 | 2026/09/29 08:45 | tool | grepper |
0mArgs:{
"Expression": "packet_recvmsg",
"PathPrefix": "net/packet/"
}Results: {
"Output": "net/packet/af_packet.c=2143=static int packet_rcv(struct sk_buff *skb, struct net_device *dev,\n--\nnet/packet/af_packet.c-2216-\nnet/packet/af_packet.c:2217:\t/* sll-\u003esll_family and sll-\u003esll_protocol are set in packet_recvmsg().\nnet/packet/af_packet.c-2218-\t * Use their space for storing the original skb length.\n--\nnet/packet/af_packet.c=3402=static int packet_create(struct net *net, struct socket *sock, int protocol,\n--\nnet/packet/af_packet.c-3479-\nnet/packet/af_packet.c:3480:static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,\nnet/packet/af_packet.c-3481-\t\t\t int flags)\n--\nnet/packet/af_packet.c=4788=static const struct proto_ops packet_ops_spkt = {\n--\nnet/packet/af_packet.c-4802-\t.sendmsg =\tpacket_sendmsg_spkt,\nnet/packet/af_packet.c:4803:\t.recvmsg =\tpacket_recvmsg,\nnet/packet/af_packet.c-4804-\t.mmap =\t\tsock_no_mmap,\n--\nnet/packet/af_packet.c=4807=static const struct proto_ops packet_ops = {\n--\nnet/packet/af_packet.c-4823-\t.sendmsg =\tpacket_sendmsg,\nnet/packet/af_packet.c:4824:\t.recvmsg =\tpacket_recvmsg,\nnet/packet/af_packet.c-4825-\t.mmap =\t\tpacket_mmap,\n"
} |
| 31/3 | 2026/09/29 08:45 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9398 output: 38 thoughts: 28 Thoughts: Here's a summary of my thought process, as requested: **Diving into Packet Reception for SOCK_PACKET** Alright, let's zero in on `packet_recvmsg`. I'm going to take a look at the code, specifically around line 3480, to understand how it's handling `SOCK_PACKET` sockets. I'm keen to see the details of how it's receiving messages, since that socket type involves direct access to the network interface's link layer. I need to understand this handling to improve how it handles certain packets. |
| 32/3 | 2026/09/29 08:45 | tool | read-file |
0mArgs:{
"File": "net/packet/af_packet.c",
"FirstLine": 3480,
"LineCount": 90
}Results: {
"Contents": "3480:\tstatic int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,\n3481:\t\t\t\t int flags)\n3482:\t{\n3483:\t\tstruct sock *sk = sock-\u003esk;\n3484:\t\tstruct sk_buff *skb;\n3485:\t\tint copied, err;\n3486:\t\tint vnet_hdr_len = READ_ONCE(pkt_sk(sk)-\u003evnet_hdr_sz);\n3487:\t\tunsigned int origlen = 0;\n3488:\t\n3489:\t\terr = -EINVAL;\n3490:\t\tif (flags \u0026 ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT|MSG_ERRQUEUE))\n3491:\t\t\tgoto out;\n3492:\t\n3493:\t#if 0\n3494:\t\t/* What error should we return now? EUNATTACH? */\n3495:\t\tif (pkt_sk(sk)-\u003eifindex \u003c 0)\n3496:\t\t\treturn -ENODEV;\n3497:\t#endif\n3498:\t\n3499:\t\tif (flags \u0026 MSG_ERRQUEUE) {\n3500:\t\t\terr = sock_recv_errqueue(sk, msg, len,\n3501:\t\t\t\t\t\t SOL_PACKET, PACKET_TX_TIMESTAMP);\n3502:\t\t\tgoto out;\n3503:\t\t}\n3504:\t\n3505:\t\t/*\n3506:\t\t *\tCall the generic datagram receiver. This handles all sorts\n3507:\t\t *\tof horrible races and re-entrancy so we can forget about it\n3508:\t\t *\tin the protocol layers.\n3509:\t\t *\n3510:\t\t *\tNow it will return ENETDOWN, if device have just gone down,\n3511:\t\t *\tbut then it will block.\n3512:\t\t */\n3513:\t\n3514:\t\tskb = skb_recv_datagram(sk, flags, \u0026err);\n3515:\t\n3516:\t\t/*\n3517:\t\t *\tAn error occurred so return it. Because skb_recv_datagram()\n3518:\t\t *\thandles the blocking we don't see and worry about blocking\n3519:\t\t *\tretries.\n3520:\t\t */\n3521:\t\n3522:\t\tif (skb == NULL)\n3523:\t\t\tgoto out;\n3524:\t\n3525:\t\tpacket_rcv_try_clear_pressure(pkt_sk(sk));\n3526:\t\n3527:\t\tif (vnet_hdr_len) {\n3528:\t\t\terr = packet_rcv_vnet(msg, skb, \u0026len, vnet_hdr_len);\n3529:\t\t\tif (err)\n3530:\t\t\t\tgoto out_free;\n3531:\t\t}\n3532:\t\n3533:\t\t/* You lose any data beyond the buffer you gave. If it worries\n3534:\t\t * a user program they can ask the device for its MTU\n3535:\t\t * anyway.\n3536:\t\t */\n3537:\t\tcopied = skb-\u003elen;\n3538:\t\tif (copied \u003e len) {\n3539:\t\t\tcopied = len;\n3540:\t\t\tmsg-\u003emsg_flags |= MSG_TRUNC;\n3541:\t\t}\n3542:\t\n3543:\t\terr = skb_copy_datagram_msg(skb, 0, msg, copied);\n3544:\t\tif (err)\n3545:\t\t\tgoto out_free;\n3546:\t\n3547:\t\tif (sock-\u003etype != SOCK_PACKET) {\n3548:\t\t\tstruct sockaddr_ll *sll = \u0026PACKET_SKB_CB(skb)-\u003esa.ll;\n3549:\t\n3550:\t\t\t/* Original length was stored in sockaddr_ll fields */\n3551:\t\t\toriglen = PACKET_SKB_CB(skb)-\u003esa.origlen;\n3552:\t\t\tsll-\u003esll_family = AF_PACKET;\n3553:\t\t\tsll-\u003esll_protocol = (sock-\u003etype == SOCK_DGRAM) ?\n3554:\t\t\t\tvlan_get_protocol_dgram(skb) : skb-\u003eprotocol;\n3555:\t\t}\n3556:\t\n3557:\t\tsock_recv_cmsgs(msg, sk, skb);\n3558:\t\n3559:\t\tif (msg-\u003emsg_name) {\n3560:\t\t\tconst size_t max_len = min(sizeof(skb-\u003ecb),\n3561:\t\t\t\t\t\t sizeof(struct sockaddr_storage));\n3562:\t\t\tint copy_len;\n3563:\t\n3564:\t\t\t/* If the address length field is there to be filled\n3565:\t\t\t * in, we fill it in now.\n3566:\t\t\t */\n3567:\t\t\tif (sock-\u003etype == SOCK_PACKET) {\n3568:\t\t\t\t__sockaddr_check_size(sizeof(struct sockaddr_pkt));\n3569:\t\t\t\tmsg-\u003emsg_namelen = sizeof(struct sockaddr_pkt);\n"
} |
| 33/3 | 2026/09/29 08:45 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 10956 output: 38 thoughts: 13 Thoughts: Okay, here's my interpretation of that thought process, tailored for an expert audience, and presented as if I'm thinking it: **Diving Deeper into `packet_recvmsg`** Alright, so we're looking at `packet_recvmsg`. I know the general flow, but let's see what's really happening a bit further down in the code. I'm going to focus on the core implementation details, not the boilerplate – I already have a handle on that. I'm particularly interested in the interaction with the underlying network interface. I expect we'll see a deep dive into buffer management and potentially some tricky interactions with hardware interrupts or DMA. The devil, as always, is in the details, especially in this area, so let's get into the specifics. Hopefully, we can see if it's got any interesting edge cases or optimization attempts that I can learn from. |
| 34/3 | 2026/09/29 08:45 | tool | read-file |
0mArgs:{
"File": "net/packet/af_packet.c",
"FirstLine": 3570,
"LineCount": 40
}Results: {
"Contents": "3570:\t\t\t\tcopy_len = msg-\u003emsg_namelen;\n3571:\t\t\t} else {\n3572:\t\t\t\tstruct sockaddr_ll *sll = \u0026PACKET_SKB_CB(skb)-\u003esa.ll;\n3573:\t\n3574:\t\t\t\tmsg-\u003emsg_namelen = sll-\u003esll_halen +\n3575:\t\t\t\t\toffsetof(struct sockaddr_ll, sll_addr);\n3576:\t\t\t\tcopy_len = msg-\u003emsg_namelen;\n3577:\t\t\t\tif (msg-\u003emsg_namelen \u003c sizeof(struct sockaddr_ll)) {\n3578:\t\t\t\t\tmemset(msg-\u003emsg_name +\n3579:\t\t\t\t\t offsetof(struct sockaddr_ll, sll_addr),\n3580:\t\t\t\t\t 0, sizeof(sll-\u003esll_addr));\n3581:\t\t\t\t\tmsg-\u003emsg_namelen = sizeof(struct sockaddr_ll);\n3582:\t\t\t\t}\n3583:\t\t\t}\n3584:\t\t\tif (WARN_ON_ONCE(copy_len \u003e max_len)) {\n3585:\t\t\t\tcopy_len = max_len;\n3586:\t\t\t\tmsg-\u003emsg_namelen = copy_len;\n3587:\t\t\t}\n3588:\t\t\tmemcpy(msg-\u003emsg_name, \u0026PACKET_SKB_CB(skb)-\u003esa, copy_len);\n3589:\t\t}\n3590:\t\n3591:\t\tif (packet_sock_flag(pkt_sk(sk), PACKET_SOCK_AUXDATA)) {\n3592:\t\t\tstruct tpacket_auxdata aux;\n3593:\t\n3594:\t\t\taux.tp_status = TP_STATUS_USER;\n3595:\t\t\tif (skb-\u003eip_summed == CHECKSUM_PARTIAL)\n3596:\t\t\t\taux.tp_status |= TP_STATUS_CSUMNOTREADY;\n3597:\t\t\telse if (skb-\u003epkt_type != PACKET_OUTGOING \u0026\u0026\n3598:\t\t\t\t skb_csum_unnecessary(skb))\n3599:\t\t\t\taux.tp_status |= TP_STATUS_CSUM_VALID;\n3600:\t\t\tif (skb_is_gso(skb) \u0026\u0026 skb_is_gso_tcp(skb))\n3601:\t\t\t\taux.tp_status |= TP_STATUS_GSO_TCP;\n3602:\t\n3603:\t\t\taux.tp_len = origlen;\n3604:\t\t\taux.tp_snaplen = skb-\u003elen;\n3605:\t\t\taux.tp_mac = 0;\n3606:\t\t\taux.tp_net = skb_network_offset(skb);\n3607:\t\t\tif (skb_vlan_tag_present(skb)) {\n3608:\t\t\t\taux.tp_vlan_tci = skb_vlan_tag_get(skb);\n3609:\t\t\t\taux.tp_vlan_tpid = ntohs(skb-\u003evlan_proto);\n"
} |
| 35/3 | 2026/09/29 08:45 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 11966 output: 28 thoughts: 191 Thoughts: **Analyzing the Structure of Network Packet Reception** Okay, let's break this down. My focus right now is on understanding how `spkt` is being handled, particularly within `packet_rcv_spkt`. It's pretty clear that `spkt` is being assigned to a member of the Socket Buffer Control Block (`skb`) - specifically `PACKET_SKB_CB(skb)->sa.pkt`. I see that the code is pushing data onto the SKB if the device has a header. Fine. Then I see that `SOCK_PACKET` sockets get _all_ frames. Got it. So, `spkt->spkt_family` gets the device type, `spkt->spkt_device` gets the device name (via `strscpy`), and `spkt->spkt_protocol` gets the SKB protocol. But... hang on. What exactly *is* `struct sockaddr_pkt`? I know it's related to the packet socket, but I need to see the definition to really grok this. Time to fire up `grepper` and find that definition. Need to understand the data structure behind this `spkt` and see what's actually being populated. |
| 36/3 | 2026/09/29 08:45 | tool | grepper |
0mArgs:{
"Expression": "struct sockaddr_pkt\\b",
"PathPrefix": "include/"
}Results: {
"Output": "include/uapi/linux/if_packet.h-7-\ninclude/uapi/linux/if_packet.h:8:struct sockaddr_pkt {\ninclude/uapi/linux/if_packet.h-9-\tunsigned short spkt_family;\n"
} |
| 37/3 | 2026/09/29 08:45 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 12518 output: 38 thoughts: 18 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Diving into the Network Interface Packet Header** Alright, let's get down to brass tacks and crack open `include/uapi/linux/if_packet.h`. I need to refresh my memory on the raw packet socket API, particularly around the `packet_mreq` and the `sockaddr_ll` structures. I'm especially interested in the nuances of how these define filtering and binding to specific network interfaces. I suspect there will be some subtle distinctions in how they handle multicast addresses versus unicast, and I want to verify if the implementation aligns with my understanding of the various packet types supported (ETH_P_ALL, ETH_P_ARP, ETH_P_IP, etc.). I want to make sure I grasp the finer points of how the kernel manages the packet interface indexes and their associated device drivers. Essentially, I need to know how the lower-level packet structure maps to the high-level features I'm working with right now. I'm hoping it's a quick refresher, but I know how the devil is in the details in these kernel headers. |
| 38/3 | 2026/09/29 08:45 | tool | read-file |
0mArgs:{
"File": "include/uapi/linux/if_packet.h",
"FirstLine": 1,
"LineCount": 30
}Results: {
"Contents": " 1:\t/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */\n 2:\t#ifndef _UAPI__LINUX_IF_PACKET_H\n 3:\t#define _UAPI__LINUX_IF_PACKET_H\n 4:\t\n 5:\t#include \u003casm/byteorder.h\u003e\n 6:\t#include \u003clinux/types.h\u003e\n 7:\t\n 8:\tstruct sockaddr_pkt {\n 9:\t\tunsigned short spkt_family;\n 10:\t\tunsigned char spkt_device[14];\n 11:\t\t__be16 spkt_protocol;\n 12:\t};\n 13:\t\n 14:\tstruct sockaddr_ll {\n 15:\t\tunsigned short\tsll_family;\n 16:\t\t__be16\t\tsll_protocol;\n 17:\t\tint\t\tsll_ifindex;\n 18:\t\tunsigned short\tsll_hatype;\n 19:\t\tunsigned char\tsll_pkttype;\n 20:\t\tunsigned char\tsll_halen;\n 21:\t\tunsigned char\tsll_addr[8];\n 22:\t};\n 23:\t\n 24:\t/* Packet types */\n 25:\t\n 26:\t#define PACKET_HOST\t\t0\t\t/* To us\t\t*/\n 27:\t#define PACKET_BROADCAST\t1\t\t/* To all\t\t*/\n 28:\t#define PACKET_MULTICAST\t2\t\t/* To group\t\t*/\n 29:\t#define PACKET_OTHERHOST\t3\t\t/* To someone else \t*/\n 30:\t#define PACKET_OUTGOING\t\t4\t\t/* Outgoing of any type */\n"
} |
| 39/3 | 2026/09/29 08:45 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 13257 output: 22 thoughts: 2579 Thoughts: **Analysis of the SOCK_PACKET Patch and KMSAN Justification** Okay, let's break this down. First, I'm looking at `struct sockaddr_pkt` – a simple structure, 18 bytes total. Nothing new there. The patch's core change is adding a `dev_has_header` check before `skb_push`. Initially, I was wondering about potential uninitialized memory risks, but it seems I was on the wrong track. The crucial thing here is understanding *why* this `dev_has_header` check is being introduced. The commit message explains it: the code previously assumed a visible link-layer header could *always* be restored using `skb_push`. This isn't true for all devices. When the header is invisible, the attempt to subtract `skb->mac_header` from `skb->data` results in a massive, likely negative length because `skb->mac_header` might be a sentinel value (e.g., 0xFFFF). This leads to `skb_under_panic`, the kernel's built-in bug detector. The patch is preventing that panic. Looking at `skb_push` specifically, I see how it works – it modifies `skb->data` and `skb->len`. If the calculated `len` is huge or negative, the check `skb->data < skb->head` triggers the panic. The patch simply avoids this calculation when the device doesn't have a header. Now, the question is, does *avoiding* `skb_push` introduce uninitialized memory? No. When the device doesn't have a header, the network layer or driver already sets `skb->data` and `skb->len` to point to the packet data and the packet length, respectively. Before the patch, the problematic calculation caused a panic. Now, the `skb_push` is skipped, leaving `skb->data` and `skb->len` correctly set to the initialized packet payload. Userspace receives the packet data as expected, via `skb_copy_datagram_msg`, using the initialized data from `skb`. I remember that `packet_rcv` and `tpacket_rcv` *already* have this `dev_has_header` check, so `SOCK_PACKET` is just catching up. Now I know that `packet_rcv_spkt` is legacy and didn't have the same checks! It's a fix, not a new problem. Let's carefully examine the KMSAN justification. Standard KASAN builds already catch out-of-bounds, use-after-free, and other memory issues. KMSAN is for catching *uninitialized* memory reads. The key is to avoid using KMSAN unless genuinely needed. Analyzing the criteria, the patch doesn't: 1. Introduce or modify kernel structures sent to userspace. 2. Introduce or modify conditional logic that depends on uninitialized variables. 3. Allocate or initialize new complex data structures. 4. Introduce changes to bounds checks that might expose uninitialized data. The change *prevents* a panic due to invalid calculations and prevents expanding `skb->data` backwards into unallocated/out-of-bounds memory. The data being delivered is the initialized payload itself. Therefore, the patch fixes a bounds check assertion. KASAN and existing kernel checks handle the existing skb bounds issues. There's no risk of uninitialized memory usage introduced by this patch. KMSAN isn't warranted here. |
| 40/3 | 2026/09/29 08:46 | tool | grepper |
0mArgs:{
"Expression": "static inline bool dev_has_header"
}Results: {
"Output": "include/linux/netdevice.h=3560=static inline bool dev_validate_header(const struct net_device *dev,\n--\ninclude/linux/netdevice.h-3573-\ninclude/linux/netdevice.h:3574:static inline bool dev_has_header(const struct net_device *dev)\ninclude/linux/netdevice.h-3575-{\n"
} |
| 41/3 | 2026/09/29 08:46 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 16734 output: 37 thoughts: 21 Thoughts: Here's my summary, as if I were thinking these thoughts: **Diving into the Network Device Header** Alright, let's get down to brass tacks. I need to refresh my memory on the specifics of network device structures, so I'm going to head straight into the source. Specifically, I'm thinking I should start digging around `include/linux/netdevice.h`. I recall that file being the central hub for a lot of the core definitions. I have a hunch that line 3574 will be particularly interesting, so that's where I will start, right in that area. I need to drill down into the low level details, and refresh my mental map of how these structs are arranged. |
| 42/3 | 2026/09/29 08:46 | tool | read-file |
0mArgs:{
"File": "include/linux/netdevice.h",
"FirstLine": 3570,
"LineCount": 15
}Results: {
"Contents": "3570:\t\n3571:\t\treturn false;\n3572:\t}\n3573:\t\n3574:\tstatic inline bool dev_has_header(const struct net_device *dev)\n3575:\t{\n3576:\t\treturn dev-\u003eheader_ops \u0026\u0026 dev-\u003eheader_ops-\u003ecreate;\n3577:\t}\n3578:\t\n3579:\tstruct numa_drop_counters {\n3580:\t\tatomic_t\tdrops0 ____cacheline_aligned_in_smp;\n3581:\t\tatomic_t\tdrops1 ____cacheline_aligned_in_smp;\n3582:\t};\n3583:\t\n3584:\tstatic inline int numa_drop_read(const struct numa_drop_counters *ndc)\n"
} |
| 43/3 | 2026/09/29 08:46 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 17164 output: 217 thoughts: 79 Thoughts: Here's my assessment of the situation: **Simple Change, No Surprises** Okay, this is pretty cut and dried. The core of it boils down to a simple safety check: `if (dev_has_header(dev))` before the `skb_push()`. This addition specifically addresses the potential for a `skb_under_panic()` and seems to be a solid preventative measure. I've scrutinized the code and there's no indication of the change introducing or exposing any new uninitialized memory problems, which is always my primary concern in situations like this. Given this minimal impact and well-defined purpose, setting `NeedsKMSAN=false` is definitely the right call. No need to overcomplicate things. Let's get the results set and move on. |
| 44/3 | 2026/09/29 08:46 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch adds a check `if (dev_has_header(dev))` before calling `skb_push(skb, skb-\u003edata - skb_mac_header(skb))` in `packet_rcv_spkt()` to align it with `packet_rcv()` and `tpacket_rcv()`. This prevents invoking `skb_push()` on devices without link-layer headers where an unset/sentinel `mac_header` results in an invalid push offset triggering `skb_under_panic()`.\n\nThe change does not introduce any uninitialized memory allocations, padding leaks to userspace, or uninitialized branch conditions. The existing packet buffer data is already properly tracked and bounded. The issue addressed is a panic / bounds check failure (`skb_under_panic()`), which falls under standard bug detectors rather than KMSAN. Therefore, a dedicated KMSAN session is not required.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch adds a check `if (dev_has_header(dev))` before calling `skb_push(skb, skb-\u003edata - skb_mac_header(skb))` in `packet_rcv_spkt()` to align it with `packet_rcv()` and `tpacket_rcv()`. This prevents invoking `skb_push()` on devices without link-layer headers where an unset/sentinel `mac_header` results in an invalid push offset triggering `skb_under_panic()`.\n\nThe change does not introduce any uninitialized memory allocations, padding leaks to userspace, or uninitialized branch conditions. The existing packet buffer data is already properly tracked and bounded. The issue addressed is a panic / bounds check failure (`skb_under_panic()`), which falls under standard bug detectors rather than KMSAN. Therefore, a dedicated KMSAN session is not required.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|