| 0/0 |
2026/05/31 13:59 |
flow |
assessment-security |
59m
Results: map[DenialOfService:true Explanation:Based on the analysis of the bug report and the kernel source code, here is the
assessment of the bug:
**Bug Mechanism:**
The bug is an out-of-bounds read in `nci_core_init_rsp_packet_v2()` (and
similarly in `nci_core_init_rsp_packet_v1()`) located in `net/nfc/nci/rsp.c`.
When the kernel receives an `NCI_OP_CORE_INIT_RSP` response from an NFC
controller, it parses the packet without properly validating the length of the
`skb` buffer.
Specifically, the code casts `skb->data` to `struct nci_core_init_rsp_nci_ver2`
and reads `rsp->num_supported_rf_interfaces`. It then iterates over the
variable-length array `supported_rf_interfaces` at the end of the struct,
skipping over `rf_extension_cnt` bytes in each iteration. If a malicious NFC
controller sends a truncated initialization response, the kernel will read past
the end of the initialized data in the `skb` buffer, resulting in an
out-of-bounds read of uninitialized heap memory.
**Impact:**
1. **Denial of Service (DoS):** The `rf_extension_cnt` is read from the
uninitialized memory and can be up to 255. With `num_supported_rf_interfaces` up
to 4, the pointer can advance by over 1000 bytes. If the `skb` data buffer is
located near the end of a memory page, this out-of-bounds read can cross the
page boundary into an unmapped page, triggering a page fault and causing a
kernel panic (Denial of Service).
2. **Exploitability:** The bug is strictly an out-of-bounds read. The read data
is stored in `ndev->supported_rf_interfaces` and later used in a branch
condition in `nci_init_complete_req()`. This could theoretically leak a tiny
amount of information (1 bit per byte) back to the NFC controller, but it does
not corrupt memory or allow control-flow hijacking. Therefore, it is not
exploitable for privilege escalation or arbitrary code execution.
**Trigger Vectors:**
- **Peripheral Trigger:** The NCI frames are received directly from the NFC
hardware controller (e.g., via USB, I2C, SPI). A malicious USB NFC device
plugged into the system can send a malformed `NCI_OP_CORE_INIT_RSP` packet
during the device initialization phase to trigger this bug.
- **Unprivileged Access:** The bug cannot be triggered by an unprivileged user
on a system with a legitimate NFC device, because a legitimate device will not
send malformed responses. The syzkaller report triggered this via
`/dev/virtual_nci`, which is a simulation driver. However, `/dev/virtual_nci` is
created with `0600` permissions and is strictly accessible only to `root` in the
initial namespace. It is not accessible to unprivileged users or within user
namespaces.
**Conclusion:**
This is a Denial of Service vulnerability that can be triggered by a malicious
physical peripheral (e.g., a rogue USB NFC device). It is not reachable by
unprivileged local users or remote attackers, and it is not exploitable for
privilege escalation. Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 1/1 |
2026/05/31 13:59 |
action |
syz-repro-to-c-repro |
0m
Results:
|
| 2/1 |
2026/05/31 13:59 |
action |
kernel-checkouter |
1m
Results: map[KernelSrc:/app/workdir/cache/src/e7765ca6bdb9f78df484f7ace7eede902d6c9ad7]
|
| 3/1 |
2026/05/31 14:00 |
action |
kernel-builder |
29m
Results: map[KernelObj:/app/workdir/cache/build/10a5f0baaa5bbb0e55fa7a5486cbb7b292a2aa9e]
|
| 4/1 |
2026/05/31 14:30 |
action |
codesearch-prepare |
23m
Results: map[Index:codesearch-index]
|
| 5/1 |
2026/05/31 14:53 |
agent |
expert |
5m
Model:
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Instruction: You are an experienced Linux kernel security engineer. Your task is to analyze given kernel bug report
and determine its security impact based on the following dimensions.
Use the provided tools to examine the source code, check for capability checks (e.g., capable(), ns_capable()),
and understand the nature of the bug. Analyze the given kernel build and configuration.
You can check the kernel config by grepping ".config" file; you can check kernel cmdline by grepping
".config" file for "CONFIG_CMDLINE=". Assume sysctl parameters have default values.
But analyze for the corresponding production build w/o debugging tools enabled (like KASAN, KMSAN, UBSAN).
Try different strategies when analyzing the bug:
- think of ways in which the vulnerable code is unreachable
- or the other way around: try to come up with different ideas of how an unprivileged user can reach the bug
If still unsure err on the side of the bug being non-exploitable/not-accessible.
In the final reply, provide a reasoning for your assessment.
Analysis dimensions:
* Exploitable:
Determine if the bug can result in memory corruption or elevated privileges.
Memory safety issues are almost always exploitable (KASAN or UBSAN reports for use-after-free, out-of-bounds;
refcounting issues, corrupted lists, etc). When kernel is crashing on a completely wild pointer access
(e.g. user-space address, or non-canonical address, but not on NULL or address corresponding to KASAN shadow
for NULL address), including both data accesses and control transfers, that also usually implies possibility
of exploitation. Such reports usually say "unable to handle kernel paging request".
Uses of uninitialized values detected by KMSAN may be exploitable b/c attacker frequently can affect uninit
values with spraying techniques. However, for these exploitability depends on how exactly the uninit value
is used in the code, and what it affects.
Think of what happens after the bug is triggered. Some bugs cause kernel panic and halt execution,
they are harder to exploit. For example, BUG reports halts the kernel. However, WARNING reports don't halt
execution in production builds. Debug bug detection tools (like KASAN, KMSAN, KCSAN, UBSAN) are also not enabled
in production builds, so attacker can freely exploit these bugs w/o being detected by these tools.
If you see an integer overflow, think how the overflowed value used later (if it's used as allocation size,
or an array index). If you see an out-of-bounds read, think if it's followed by an out-of-bounds write as well.
Some KCSAN data-races may be exploitable by skilled attackers as well. Think what data structures got corrupted
as the result of data races and how. However, note that kernel has lots of "benign" data races that don't lead
to any runtime misbehavior at all.
* Denial Of Service:
Determine if the bug can result in denial-of-service. Most bugs can, since they cause system crash,
hangs, deadlocks, or resource leaks. This is mostly applicable to WARNING bugs that won't cause system crash
in production. For these think what will be consequences of the violation of the kernel assumptions flagged
by the WARNING. In some cases the unexpected condition is also properly handled by the normal control flow
(e.g. with "if (WARN_ON(...))"), these won't cause denial-of-service. If the condition is not handled,
then it may or may not cause denial-of-service.
* Accessible From Unprivileged Processes:
Determine if the bug can be reached from a typical (non-root) user process that does NOT have any special capabilities
(like CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON) or access to device nodes restricted to root.
Assume that unprivileged_bpf_disabled=1, that is eBPF loading is not accessible. However, cBPF (classical BPF)
is still accessible to non-root processes.
Assume that user namespaces are not accessible, that is, the process cannot get the mentioned capabilities even
within a new user namespace (checked by ns_capable() function in the kernel sources).
* Accessible From User Namespaces:
Determine if the bug can be reached within a user-namespace where the process has all capabilities
(including CAP_SYS_ADMIN, CAP_NET_ADMIN, CAP_NET_RAW, CAP_PERFMON). Such capabilities are checked with ns_capable()
function in the kernel sources.
* VM Guest Trigger:
Determine if the bug can be triggered from the context of a typical KVM guest (e.g., set up by a QEMU VMM).
Consider accesses to standard Linux host paravirtualized features (virtio-blk, virtio-net, etc.),
and handling of VM exits in the KVM code.
* VM Host Trigger in The Confidential Computing Context:
Determine if the bug can be triggered in a confidential computing guest kernel from the context of a KVM host.
Consider access to standard Linux guest paravirtualized features (virtio-blk, virtio-net, etc.).
* Ethernet Network Trigger:
Determine if the bug can be triggered by processing ingress network Ethernet traffic, either directly (network stack)
or via drivers exposed to network data.
* Other Remote Trigger:
Determine if the bug can be triggered by processing remote traffic other than Ethernet (Wifi, Bluetooth, NFC, etc).
* Peripheral Trigger:
Determine if the bug can be triggered via an untrusted peripheral device that can be physically plugged
into a system, such as a USB device or a niche hardware driver handling external hardware inputs.
This is particularly important for mobile and desktop environments where users can plug in unknown devices.
* Malicious Filesystem Trigger:
Determine if the bug can be triggered by the kernel mounting and parsing a malicious filesystem image.
This is highly critical for Desktop and Mobile environments where external media or downloaded images
might be auto-mounted.
Don't make assumptions about the kernel source code (it may be different from what you assume it is).
Extensively use the provided code access tools (codesearch-*, git-*, grepper, etc)
to examine the actual source code, and confirm any assumptions.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt:
The kernel bug report is:
=====================================================
BUG: KMSAN: uninit-value in nci_init_complete_req net/nfc/nci/core.c:192 [inline]
BUG: KMSAN: uninit-value in __nci_request net/nfc/nci/core.c:108 [inline]
BUG: KMSAN: uninit-value in nci_open_device net/nfc/nci/core.c:529 [inline]
BUG: KMSAN: uninit-value in nci_dev_up+0x1110/0x1bb0 net/nfc/nci/core.c:643
nci_init_complete_req net/nfc/nci/core.c:192 [inline]
__nci_request net/nfc/nci/core.c:108 [inline]
nci_open_device net/nfc/nci/core.c:529 [inline]
nci_dev_up+0x1110/0x1bb0 net/nfc/nci/core.c:643
nfc_dev_up+0x204/0x3d0 net/nfc/core.c:118
nfc_genl_dev_up+0xe9/0x1c0 net/nfc/netlink.c:775
genl_family_rcv_msg_doit+0x338/0x3f0 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0xac5/0xc00 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x54d/0x680 net/netlink/af_netlink.c:2550
genl_rcv+0x41/0x60 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0xee2/0x1290 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x10b2/0x1250 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:787 [inline]
__sock_sendmsg net/socket.c:802 [inline]
____sys_sendmsg+0xf37/0xfd0 net/socket.c:2698
___sys_sendmsg+0x271/0x3b0 net/socket.c:2752
__sys_sendmsg net/socket.c:2784 [inline]
__do_sys_sendmsg net/socket.c:2789 [inline]
__se_sys_sendmsg net/socket.c:2787 [inline]
__x64_sys_sendmsg+0x211/0x3e0 net/socket.c:2787
x64_sys_call+0x1e20/0x3ea0 arch/x86/include/generated/asm/syscalls_64.h:47
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x134/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Uninit was stored to memory at:
nci_init_complete_req net/nfc/nci/core.c:192 [inline]
__nci_request net/nfc/nci/core.c:108 [inline]
nci_open_device net/nfc/nci/core.c:529 [inline]
nci_dev_up+0x1109/0x1bb0 net/nfc/nci/core.c:643
nfc_dev_up+0x204/0x3d0 net/nfc/core.c:118
nfc_genl_dev_up+0xe9/0x1c0 net/nfc/netlink.c:775
genl_family_rcv_msg_doit+0x338/0x3f0 net/netlink/genetlink.c:1114
genl_family_rcv_msg net/netlink/genetlink.c:1194 [inline]
genl_rcv_msg+0xac5/0xc00 net/netlink/genetlink.c:1209
netlink_rcv_skb+0x54d/0x680 net/netlink/af_netlink.c:2550
genl_rcv+0x41/0x60 net/netlink/genetlink.c:1218
netlink_unicast_kernel net/netlink/af_netlink.c:1318 [inline]
netlink_unicast+0xee2/0x1290 net/netlink/af_netlink.c:1344
netlink_sendmsg+0x10b2/0x1250 net/netlink/af_netlink.c:1894
sock_sendmsg_nosec net/socket.c:787 [inline]
__sock_sendmsg net/socket.c:802 [inline]
____sys_sendmsg+0xf37/0xfd0 net/socket.c:2698
___sys_sendmsg+0x271/0x3b0 net/socket.c:2752
__sys_sendmsg net/socket.c:2784 [inline]
__do_sys_sendmsg net/socket.c:2789 [inline]
__se_sys_sendmsg net/socket.c:2787 [inline]
__x64_sys_sendmsg+0x211/0x3e0 net/socket.c:2787
x64_sys_call+0x1e20/0x3ea0 arch/x86/include/generated/asm/syscalls_64.h:47
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x134/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
Uninit was stored to memory at:
nci_core_init_rsp_packet_v2 net/nfc/nci/rsp.c:107 [inline]
nci_core_init_rsp_packet net/nfc/nci/rsp.c:131 [inline]
nci_rsp_packet+0x2c3b/0x2d70 net/nfc/nci/rsp.c:376
nci_rx_work+0x48f/0x850 net/nfc/nci/core.c:1579
process_one_work kernel/workqueue.c:3302 [inline]
process_scheduled_works+0xb65/0x1e40 kernel/workqueue.c:3385
worker_thread+0xee4/0x1590 kernel/workqueue.c:3466
kthread+0x53f/0x600 kernel/kthread.c:436
ret_from_fork+0x20f/0x8d0 arch/x86/kernel/process.c:158
ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
Uninit was created at:
slab_post_alloc_hook mm/slub.c:4576 [inline]
slab_alloc_node mm/slub.c:4898 [inline]
kmem_cache_alloc_node_noprof+0x3cd/0x12c0 mm/slub.c:4950
kmalloc_reserve net/core/skbuff.c:613 [inline]
__alloc_skb+0x855/0x1190 net/core/skbuff.c:713
alloc_skb include/linux/skbuff.h:1383 [inline]
virtual_ncidev_write+0x6b/0x2a0 drivers/nfc/virtual_ncidev.c:120
vfs_write+0x48a/0x15c0 fs/read_write.c:686
ksys_write+0x1d9/0x470 fs/read_write.c:740
__do_sys_write fs/read_write.c:751 [inline]
__se_sys_write fs/read_write.c:748 [inline]
__x64_sys_write+0x97/0xf0 fs/read_write.c:748
x64_sys_call+0x2ff0/0x3ea0 arch/x86/include/generated/asm/syscalls_64.h:2
do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline]
do_syscall_64+0x134/0xf80 arch/x86/entry/syscall_64.c:94
entry_SYSCALL_64_after_hwframe+0x77/0x7f
CPU: 1 UID: 0 PID: 7976 Comm: syz.2.570 Not tainted syzkaller #0 PREEMPT(full)
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 04/18/2026
=====================================================
Reply: Based on the analysis of the bug report and the kernel source code, here is the assessment of the bug:
**Bug Mechanism:**
The bug is an out-of-bounds read in `nci_core_init_rsp_packet_v2()` (and similarly in `nci_core_init_rsp_packet_v1()`) located in `net/nfc/nci/rsp.c`. When the kernel receives an `NCI_OP_CORE_INIT_RSP` response from an NFC controller, it parses the packet without properly validating the length of the `skb` buffer.
Specifically, the code casts `skb->data` to `struct nci_core_init_rsp_nci_ver2` and reads `rsp->num_supported_rf_interfaces`. It then iterates over the variable-length array `supported_rf_interfaces` at the end of the struct, skipping over `rf_extension_cnt` bytes in each iteration. If a malicious NFC controller sends a truncated initialization response, the kernel will read past the end of the initialized data in the `skb` buffer, resulting in an out-of-bounds read of uninitialized heap memory.
**Impact:**
1. **Denial of Service (DoS):** The `rf_extension_cnt` is read from the uninitialized memory and can be up to 255. With `num_supported_rf_interfaces` up to 4, the pointer can advance by over 1000 bytes. If the `skb` data buffer is located near the end of a memory page, this out-of-bounds read can cross the page boundary into an unmapped page, triggering a page fault and causing a kernel panic (Denial of Service).
2. **Exploitability:** The bug is strictly an out-of-bounds read. The read data is stored in `ndev->supported_rf_interfaces` and later used in a branch condition in `nci_init_complete_req()`. This could theoretically leak a tiny amount of information (1 bit per byte) back to the NFC controller, but it does not corrupt memory or allow control-flow hijacking. Therefore, it is not exploitable for privilege escalation or arbitrary code execution.
**Trigger Vectors:**
- **Peripheral Trigger:** The NCI frames are received directly from the NFC hardware controller (e.g., via USB, I2C, SPI). A malicious USB NFC device plugged into the system can send a malformed `NCI_OP_CORE_INIT_RSP` packet during the device initialization phase to trigger this bug.
- **Unprivileged Access:** The bug cannot be triggered by an unprivileged user on a system with a legitimate NFC device, because a legitimate device will not send malformed responses. The syzkaller report triggered this via `/dev/virtual_nci`, which is a simulation driver. However, `/dev/virtual_nci` is created with `0600` permissions and is strictly accessible only to `root` in the initial namespace. It is not accessible to unprivileged users or within user namespaces.
**Conclusion:**
This is a Denial of Service vulnerability that can be triggered by a malicious physical peripheral (e.g., a rogue USB NFC device). It is not reachable by unprivileged local users or remote attackers, and it is not exploitable for privilege escalation.
|
| 6/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 7952
output: 39
thoughts: 223
Thoughts: **Uninitialized Value Bug Hunt**
Okay, so I've got this bug report, and it looks like we've got an uninitialized value rearing its ugly head in `nci_init_complete_req`. Specifically, it's popping up in `net/nfc/nci/core.c:192`. Hmm, let me trace back how this thing is getting created and used.
Alright, the initial source of the issue seems to be in `virtual_ncidev_write` which then calls `alloc_skb`. So, this `alloc_skb` call is where the uninitialized data is coming from. Then, that data gets stored in memory, first in `net/nfc/nci/rsp.c:107` through the call chain `nci_core_init_rsp_packet_v2` -> `nci_core_init_rsp_packet` -> `nci_rsp_packet` -> `nci_rx_work`. Ok, got it. It's making its way from the initial allocation, to the response packet generation process.
And then, down the line, it is finally getting referenced in `nci_init_complete_req`. That function leads to `__nci_request`, which calls `nci_open_device`, which calls `nci_dev_up`, which calls `nfc_dev_up`, which calls `nfc_genl_dev_up`, and it finally surfaces, or is at least used, in `genl_family_rcv_msg_doit`.
So, it's making its way up through a chain of function calls before it shows up as an issue. Looks like I need to dig into the `alloc_skb` call, and the subsequent data copying in `nci_core_init_rsp_packet_v2` to figure out what's not being properly initialized. I'll need to look at the relevant data structures and make sure everything is being handled correctly. Time to crack open the source code and get to work.
|
| 7/2 |
2026/05/31 14:53 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/core.c FirstLine:180 LineCount:50]
Results: map[Contents: 180: static void nci_init_complete_req(struct nci_dev *ndev, const void *opt)
181: {
182: struct nci_rf_disc_map_cmd cmd;
183: struct disc_map_config *cfg = cmd.mapping_configs;
184: __u8 *num = &cmd.num_mapping_configs;
185: int i;
186:
187: /* set rf mapping configurations */
188: *num = 0;
189:
190: /* by default mapping is set to NCI_RF_INTERFACE_FRAME */
191: for (i = 0; i < ndev->num_supported_rf_interfaces; i++) {
192: if (ndev->supported_rf_interfaces[i] ==
193: NCI_RF_INTERFACE_ISO_DEP) {
194: cfg[*num].rf_protocol = NCI_RF_PROTOCOL_ISO_DEP;
195: cfg[*num].mode = NCI_DISC_MAP_MODE_POLL |
196: NCI_DISC_MAP_MODE_LISTEN;
197: cfg[*num].rf_interface = NCI_RF_INTERFACE_ISO_DEP;
198: (*num)++;
199: } else if (ndev->supported_rf_interfaces[i] ==
200: NCI_RF_INTERFACE_NFC_DEP) {
201: cfg[*num].rf_protocol = NCI_RF_PROTOCOL_NFC_DEP;
202: cfg[*num].mode = NCI_DISC_MAP_MODE_POLL |
203: NCI_DISC_MAP_MODE_LISTEN;
204: cfg[*num].rf_interface = NCI_RF_INTERFACE_NFC_DEP;
205: (*num)++;
206: }
207:
208: if (*num == NCI_MAX_NUM_MAPPING_CONFIGS)
209: break;
210: }
211:
212: nci_send_cmd(ndev, NCI_OP_RF_DISCOVER_MAP_CMD,
213: (1 + ((*num) * sizeof(struct disc_map_config))), &cmd);
214: }
215:
216: struct nci_set_config_param {
217: __u8 id;
218: size_t len;
219: const __u8 *val;
220: };
221:
222: static void nci_set_config_req(struct nci_dev *ndev, const void *opt)
223: {
224: const struct nci_set_config_param *param = opt;
225: struct nci_core_set_config_cmd cmd;
226:
227: BUG_ON(param->len > NCI_MAX_PARAM_LEN);
228:
229: cmd.num_params = 1;
]
|
| 8/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 9526
output: 38
thoughts: 122
Thoughts: **Investigating an Uninitialized Value in NFC Core**
Okay, so I'm seeing a potential issue here. The report points out an uninitialized value being used at `net/nfc/nci/core.c:192`. Specifically, the code checks `ndev->supported_rf_interfaces[i] == NCI_RF_INTERFACE_ISO_DEP`, and that relies on `ndev->supported_rf_interfaces` having valid data. It seems, based on the report, that this array might contain garbage.
My next move is to trace back where this `supported_rf_interfaces` array is actually initialized. The report mentions that it gets populated in `net/nfc/nci/rsp.c:107`, within the `nci_core_init_rsp_packet_v2` function. I'll need to dig into that function and understand the flow to see exactly how and what values are being written to `ndev->supported_rf_interfaces`. Hopefully, the initialization reveals the source of the unexpected behaviour.
|
| 9/2 |
2026/05/31 14:53 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/rsp.c FirstLine:90 LineCount:50]
Results: map[Contents: 90: const u8 *supported_rf_interface = rsp->supported_rf_interfaces;
91: u8 rf_interface_idx = 0;
92: u8 rf_extension_cnt = 0;
93:
94: pr_debug("status %x\n", rsp->status);
95:
96: if (rsp->status != NCI_STATUS_OK)
97: return rsp->status;
98:
99: ndev->nfcc_features = __le32_to_cpu(rsp->nfcc_features);
100: ndev->num_supported_rf_interfaces = rsp->num_supported_rf_interfaces;
101:
102: ndev->num_supported_rf_interfaces =
103: min((int)ndev->num_supported_rf_interfaces,
104: NCI_MAX_SUPPORTED_RF_INTERFACES);
105:
106: while (rf_interface_idx < ndev->num_supported_rf_interfaces) {
107: ndev->supported_rf_interfaces[rf_interface_idx++] = *supported_rf_interface++;
108:
109: /* skip rf extension parameters */
110: rf_extension_cnt = *supported_rf_interface++;
111: supported_rf_interface += rf_extension_cnt;
112: }
113:
114: ndev->max_logical_connections = rsp->max_logical_connections;
115: ndev->max_routing_table_size =
116: __le16_to_cpu(rsp->max_routing_table_size);
117: ndev->max_ctrl_pkt_payload_len =
118: rsp->max_ctrl_pkt_payload_len;
119: ndev->max_size_for_large_params = NCI_MAX_LARGE_PARAMS_NCI_v2;
120:
121: return NCI_STATUS_OK;
122: }
123:
124: static void nci_core_init_rsp_packet(struct nci_dev *ndev, const struct sk_buff *skb)
125: {
126: u8 status = 0;
127:
128: if (!(ndev->nci_ver & NCI_VER_2_MASK))
129: status = nci_core_init_rsp_packet_v1(ndev, skb);
130: else
131: status = nci_core_init_rsp_packet_v2(ndev, skb);
132:
133: if (status != NCI_STATUS_OK)
134: goto exit;
135:
136: pr_debug("nfcc_features 0x%x\n",
137: ndev->nfcc_features);
138: pr_debug("num_supported_rf_interfaces %d\n",
139: ndev->num_supported_rf_interfaces);
]
|
| 10/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 10776
output: 39
thoughts: 155
Thoughts: **Analyzing the NCI Core Initialization Response**
Okay, so I'm looking at `nci_core_init_rsp_packet_v2` and it seems to be responsible for parsing the response packet. The first thing I see is that it reads `rsp->num_supported_rf_interfaces` from the packet. Now it's iterating in a loop, `while (rf_interface_idx < ndev->num_supported_rf_interfaces)`, and reading `*supported_rf_interface++`. Wait a second... I see a potential vulnerability here. If the incoming packet is shorter than what we're expecting, it's possible that this code is reading uninitialized memory from the `skb` buffer.
Hmm, let's trace back where this `skb` buffer is coming from. Ah, it looks like it's allocated within `virtual_ncidev_write` using `alloc_skb`. Okay, now I remember, `virtual_ncidev_write` is the driver function that allows writing NCI packets from userspace, so it makes sense that it allocates the `skb`. Given this, I need to check out what the actual user-space input validation is like in `virtual_ncidev_write`. Time to take a closer look!
|
| 11/2 |
2026/05/31 14:53 |
tool |
read-file |
0m
Args: map[File:drivers/nfc/virtual_ncidev.c FirstLine:100 LineCount:50]
Results: map[Contents: 100: return -EFAULT;
101: }
102:
103: skb_pull(vdev->send_buff, actual_len);
104: if (vdev->send_buff->len == 0) {
105: consume_skb(vdev->send_buff);
106: vdev->send_buff = NULL;
107: }
108: mutex_unlock(&vdev->mtx);
109:
110: return actual_len;
111: }
112:
113: static ssize_t virtual_ncidev_write(struct file *file,
114: const char __user *buf,
115: size_t count, loff_t *ppos)
116: {
117: struct virtual_nci_dev *vdev = file->private_data;
118: struct sk_buff *skb;
119:
120: skb = alloc_skb(count, GFP_KERNEL);
121: if (!skb)
122: return -ENOMEM;
123:
124: if (copy_from_user(skb_put(skb, count), buf, count)) {
125: kfree_skb(skb);
126: return -EFAULT;
127: }
128:
129: nci_recv_frame(vdev->ndev, skb);
130: return count;
131: }
132:
133: static int virtual_ncidev_open(struct inode *inode, struct file *file)
134: {
135: int ret = 0;
136: struct virtual_nci_dev *vdev;
137:
138: vdev = kzalloc_obj(*vdev);
139: if (!vdev)
140: return -ENOMEM;
141: vdev->ndev = nci_allocate_device(&virtual_nci_ops,
142: VIRTUAL_NFC_PROTOCOLS, 0, 0);
143: if (!vdev->ndev) {
144: kfree(vdev);
145: return -ENOMEM;
146: }
147:
148: mutex_init(&vdev->mtx);
149: init_waitqueue_head(&vdev->wq);
]
|
| 12/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 11967
output: 38
thoughts: 158
Thoughts: **Analyzing a Potential Vulnerability in `virtual_ncidev_write`**
Okay, let me break this down. My initial thought is that `virtual_ncidev_write` is allocating an SKB with `alloc_skb` of size `count`, copying data of size `count` from user-space, and then passing it to `nci_recv_frame`. I'm immediately concerned because I know how `alloc_skb` works β it could very well allocate a buffer *larger* than `count`, maybe because of alignment requirements or slab sizes, and the extra memory beyond `count` would be uninitialized.
But hold on, `skb_put` is used, and that should set `skb->len` to `count`. That's important. The size of the received data should be `count` bytes.
The potential vulnerability is if `nci_core_init_rsp_packet_v2` *reads* beyond `skb->len`. If it does that, it would be reading that uninitialized memory I was thinking about earlier. It's time to check `nci_core_init_rsp_packet_v2` to confirm if it has this potential read out-of-bounds flaw! Let's see...
|
| 13/2 |
2026/05/31 14:53 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/rsp.c FirstLine:70 LineCount:50]
Results: map[Contents: 70:
71: ndev->max_logical_connections = rsp_2->max_logical_connections;
72: ndev->max_routing_table_size =
73: __le16_to_cpu(rsp_2->max_routing_table_size);
74: ndev->max_ctrl_pkt_payload_len =
75: rsp_2->max_ctrl_pkt_payload_len;
76: ndev->max_size_for_large_params =
77: __le16_to_cpu(rsp_2->max_size_for_large_params);
78: ndev->manufact_id =
79: rsp_2->manufact_id;
80: ndev->manufact_specific_info =
81: __le32_to_cpu(rsp_2->manufact_specific_info);
82:
83: return NCI_STATUS_OK;
84: }
85:
86: static u8 nci_core_init_rsp_packet_v2(struct nci_dev *ndev,
87: const struct sk_buff *skb)
88: {
89: const struct nci_core_init_rsp_nci_ver2 *rsp = (void *)skb->data;
90: const u8 *supported_rf_interface = rsp->supported_rf_interfaces;
91: u8 rf_interface_idx = 0;
92: u8 rf_extension_cnt = 0;
93:
94: pr_debug("status %x\n", rsp->status);
95:
96: if (rsp->status != NCI_STATUS_OK)
97: return rsp->status;
98:
99: ndev->nfcc_features = __le32_to_cpu(rsp->nfcc_features);
100: ndev->num_supported_rf_interfaces = rsp->num_supported_rf_interfaces;
101:
102: ndev->num_supported_rf_interfaces =
103: min((int)ndev->num_supported_rf_interfaces,
104: NCI_MAX_SUPPORTED_RF_INTERFACES);
105:
106: while (rf_interface_idx < ndev->num_supported_rf_interfaces) {
107: ndev->supported_rf_interfaces[rf_interface_idx++] = *supported_rf_interface++;
108:
109: /* skip rf extension parameters */
110: rf_extension_cnt = *supported_rf_interface++;
111: supported_rf_interface += rf_extension_cnt;
112: }
113:
114: ndev->max_logical_connections = rsp->max_logical_connections;
115: ndev->max_routing_table_size =
116: __le16_to_cpu(rsp->max_routing_table_size);
117: ndev->max_ctrl_pkt_payload_len =
118: rsp->max_ctrl_pkt_payload_len;
119: ndev->max_size_for_large_params = NCI_MAX_LARGE_PARAMS_NCI_v2;
]
|
| 14/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 13330
output: 49
thoughts: 160
Thoughts: **Vulnerability Analysis of `nci_core_init_rsp_packet_v2`**
Okay, so I'm looking at this `nci_core_init_rsp_packet_v2` function... and the first thing that jumps out at me is that it's casting `skb->data` directly to a `struct nci_core_init_rsp_nci_ver2 *`. That's fine, but there's a huge red flag: there's no check on `skb->len`! If the received packet, the Secure Kernel Buffer (`skb`), is shorter than the size of the `struct nci_core_init_rsp_nci_ver2` structure, we're going to read uninitialized memory, potentially exposing sensitive information or leading to unexpected behavior. That's classic memory corruption right there.
And then I see this `while` loop, which reads `supported_rf_interface`. Wait a minute... that's a variable-length array that's tacked on to the end of `struct nci_core_init_rsp_nci_ver2`. *facepalm*... Okay, yes, I'm now clear that the structure does have `supported_rf_interfaces` at the end... but still, the *lack* of a length check before we attempt to iterate over that array is a recipe for disaster. The potential for a buffer over-read is clear. We could easily crash the kernel or be used as a stepping stone. This needs to be addressed ASAP.
|
| 15/2 |
2026/05/31 14:53 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/nfc/nci/rsp.c Name:nci_core_init_rsp_nci_ver2]
Results: map[SourceCode: 347: /* To support NCI ver 2.x */
348: struct nci_core_init_rsp_nci_ver2 {
349: u8 status;
350: __le32 nfcc_features;
351: u8 max_logical_connections;
352: __le16 max_routing_table_size;
353: u8 max_ctrl_pkt_payload_len;
354: u8 max_data_pkt_hci_payload_len;
355: u8 number_of_hci_credit;
356: __le16 max_nfc_v_frame_size;
357: u8 num_supported_rf_interfaces;
358: u8 supported_rf_interfaces[];
359: } __packed;
SourceFile:include/net/nfc/nci.h]
|
| 16/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 14138
output: 38
thoughts: 106
Thoughts: **Analyzing the NCI Core Initialization Response Structure**
Okay, hold on a second. I'm looking at `nci_core_init_rsp_packet_v2` and it seems like it's pulling `max_logical_connections`, `max_routing_table_size`, and `max_ctrl_pkt_payload_len` right from the `rsp` structure. But something's not clicking. In the `struct nci_core_init_rsp_nci_ver2` definition, those specific fields appear *before* `num_supported_rf_interfaces`. I need to double-check that `nci_core_init_rsp_packet_v2` function. It seems there is a discrepency, and needs closer review.
|
| 17/2 |
2026/05/31 14:53 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/rsp.c FirstLine:86 LineCount:50]
Results: map[Contents: 86: static u8 nci_core_init_rsp_packet_v2(struct nci_dev *ndev,
87: const struct sk_buff *skb)
88: {
89: const struct nci_core_init_rsp_nci_ver2 *rsp = (void *)skb->data;
90: const u8 *supported_rf_interface = rsp->supported_rf_interfaces;
91: u8 rf_interface_idx = 0;
92: u8 rf_extension_cnt = 0;
93:
94: pr_debug("status %x\n", rsp->status);
95:
96: if (rsp->status != NCI_STATUS_OK)
97: return rsp->status;
98:
99: ndev->nfcc_features = __le32_to_cpu(rsp->nfcc_features);
100: ndev->num_supported_rf_interfaces = rsp->num_supported_rf_interfaces;
101:
102: ndev->num_supported_rf_interfaces =
103: min((int)ndev->num_supported_rf_interfaces,
104: NCI_MAX_SUPPORTED_RF_INTERFACES);
105:
106: while (rf_interface_idx < ndev->num_supported_rf_interfaces) {
107: ndev->supported_rf_interfaces[rf_interface_idx++] = *supported_rf_interface++;
108:
109: /* skip rf extension parameters */
110: rf_extension_cnt = *supported_rf_interface++;
111: supported_rf_interface += rf_extension_cnt;
112: }
113:
114: ndev->max_logical_connections = rsp->max_logical_connections;
115: ndev->max_routing_table_size =
116: __le16_to_cpu(rsp->max_routing_table_size);
117: ndev->max_ctrl_pkt_payload_len =
118: rsp->max_ctrl_pkt_payload_len;
119: ndev->max_size_for_large_params = NCI_MAX_LARGE_PARAMS_NCI_v2;
120:
121: return NCI_STATUS_OK;
122: }
123:
124: static void nci_core_init_rsp_packet(struct nci_dev *ndev, const struct sk_buff *skb)
125: {
126: u8 status = 0;
127:
128: if (!(ndev->nci_ver & NCI_VER_2_MASK))
129: status = nci_core_init_rsp_packet_v1(ndev, skb);
130: else
131: status = nci_core_init_rsp_packet_v2(ndev, skb);
132:
133: if (status != NCI_STATUS_OK)
134: goto exit;
135:
]
|
| 18/2 |
2026/05/31 14:53 |
llm |
expert |
0m
Model:
Tokens:
input: 15318
output: 39
thoughts: 40
Thoughts: Okay, let's see...
**Initial Assessment: Virtual NCI Device Vulnerability**
Wait a second... if `virtual_ncidev_write` lets unprivileged users inject NCI frames, that's a HUGE red flag. We need to immediately investigate the implications of that. The potential for malicious NCI frame injection is substantial, and this could lead to serious security breaches.
My immediate focus shifts to the lifecycle of this device and how it's being managed. I need to understand the entry points. Let's dig into `virtual_ncidev_open` and the entire device registration process. How is this device exposed? What checks, if any, are implemented during the open and registration phases? Is there any sandboxing or access control? This is the crucial point to understand before we can even begin to assess the scope of this potential vulnerability. We must confirm the claims about unprivileged user access.
|
| 19/2 |
2026/05/31 14:54 |
tool |
read-file |
0m
Args: map[File:drivers/nfc/virtual_ncidev.c FirstLine:130 LineCount:50]
Results: map[Contents: 130: return count;
131: }
132:
133: static int virtual_ncidev_open(struct inode *inode, struct file *file)
134: {
135: int ret = 0;
136: struct virtual_nci_dev *vdev;
137:
138: vdev = kzalloc_obj(*vdev);
139: if (!vdev)
140: return -ENOMEM;
141: vdev->ndev = nci_allocate_device(&virtual_nci_ops,
142: VIRTUAL_NFC_PROTOCOLS, 0, 0);
143: if (!vdev->ndev) {
144: kfree(vdev);
145: return -ENOMEM;
146: }
147:
148: mutex_init(&vdev->mtx);
149: init_waitqueue_head(&vdev->wq);
150: file->private_data = vdev;
151: nci_set_drvdata(vdev->ndev, vdev);
152:
153: ret = nci_register_device(vdev->ndev);
154: if (ret < 0) {
155: nci_free_device(vdev->ndev);
156: mutex_destroy(&vdev->mtx);
157: kfree(vdev);
158: return ret;
159: }
160:
161: return 0;
162: }
163:
164: static int virtual_ncidev_close(struct inode *inode, struct file *file)
165: {
166: struct virtual_nci_dev *vdev = file->private_data;
167:
168: nci_unregister_device(vdev->ndev);
169: nci_free_device(vdev->ndev);
170: mutex_destroy(&vdev->mtx);
171: kfree(vdev);
172:
173: return 0;
174: }
175:
176: static long virtual_ncidev_ioctl(struct file *file, unsigned int cmd,
177: unsigned long arg)
178: {
179: struct virtual_nci_dev *vdev = file->private_data;
]
|
| 20/2 |
2026/05/31 14:54 |
llm |
expert |
0m
Model:
Tokens:
input: 16305
output: 39
thoughts: 14
Thoughts: Okay, let's dive into this. Here's my thought process on how to summarize this:
**Initial Investigation into `virtual_ncidev` Registration**
Alright, so the first thing I need to do is figure out how this `virtual_ncidev` thing is registered. I'm going to start by getting a handle on the process. Where is it defined? What are the entry points? Are there configuration files that point to it? Is there some central registry, or is it more ad-hoc? My expert understanding tells me there are going to be a lot of possibilities here. I'll need to figure out the right keywords to search for. Knowing the general area it's operating in is going to be key. Okay, let's get started.
|
| 21/2 |
2026/05/31 14:54 |
tool |
read-file |
0m
Args: map[File:drivers/nfc/virtual_ncidev.c FirstLine:180 LineCount:50]
Results: map[Contents: 180: const struct nfc_dev *nfc_dev = vdev->ndev->nfc_dev;
181: void __user *p = (void __user *)arg;
182:
183: if (cmd != IOCTL_GET_NCIDEV_IDX)
184: return -ENOTTY;
185:
186: if (copy_to_user(p, &nfc_dev->idx, sizeof(nfc_dev->idx)))
187: return -EFAULT;
188:
189: return 0;
190: }
191:
192: static const struct file_operations virtual_ncidev_fops = {
193: .owner = THIS_MODULE,
194: .read = virtual_ncidev_read,
195: .write = virtual_ncidev_write,
196: .open = virtual_ncidev_open,
197: .release = virtual_ncidev_close,
198: .unlocked_ioctl = virtual_ncidev_ioctl
199: };
200:
201: static struct miscdevice miscdev = {
202: .minor = MISC_DYNAMIC_MINOR,
203: .name = "virtual_nci",
204: .fops = &virtual_ncidev_fops,
205: .mode = 0600,
206: };
207:
208: module_misc_device(miscdev);
209:
210: MODULE_LICENSE("GPL");
211: MODULE_DESCRIPTION("Virtual NCI device simulation driver");
212: MODULE_AUTHOR("Bongsu Jeon <bongsu.jeon@samsung.com>");
]
|
| 22/2 |
2026/05/31 14:54 |
llm |
expert |
0m
Model:
Tokens:
input: 17031
output: 20
thoughts: 172
Thoughts: **Analyzing the Vulnerability in `virtual_nci`**
Okay, so the `virtual_nci` device is created with a permissions setting of 0600. That's pretty restrictive; only root, or users with some serious capabilities like CAP_DAC_OVERRIDE or CAP_SYS_ADMIN, can directly interact with it. So, a standard unprivileged user can't just `open("/dev/virtual_nci")` and start messing around. Good. But wait⦠is there *another* way to trigger this bug? We need to think outside the standard file system interaction.
Right, the bug itself is deep inside `nci_core_init_rsp_packet_v2`. That function is crucial; it's the one parsing the response from the NFC controller when it first initializes. So, if an attacker can control the NFC controller itself and feed it a carefully crafted, malformed response to `NCI_OP_CORE_INIT_CMD`, we could be in trouble. Think about it: a malicious USB NFC device? Or, if this system uses an I2C connection to the NFC chip, an attacker could tamper with that I2C connection. The possibilities are numerous.
Now we need to consider how to exploit it. I'd better check for any USB NFC drivers that might be using NCI. That's the key.
|
| 23/2 |
2026/05/31 14:54 |
tool |
grepper |
0m
Args: map[Expression:nci_recv_frame]
Results: map[Output:drivers/nfc/fdp/i2c.c=195=static irqreturn_t fdp_nci_i2c_irq_thread_fn(int irq, void *phy_id)
--
drivers/nfc/fdp/i2c.c-211- if (skb != NULL)
drivers/nfc/fdp/i2c.c:212: nci_recv_frame(phy->ndev, skb);
drivers/nfc/fdp/i2c.c-213-
--
drivers/nfc/nfcmrvl/i2c.c=64=static irqreturn_t nfcmrvl_i2c_int_irq_thread_fn(int irq, void *drv_data_ptr)
--
drivers/nfc/nfcmrvl/i2c.c-86- default:
drivers/nfc/nfcmrvl/i2c.c:87: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/i2c.c-88- nfc_err(&drv_data->i2c->dev, "corrupted RX packet\n");
--
drivers/nfc/nfcmrvl/main.c=192=EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
drivers/nfc/nfcmrvl/main.c-193-
drivers/nfc/nfcmrvl/main.c:194:int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
drivers/nfc/nfcmrvl/main.c-195-{
--
drivers/nfc/nfcmrvl/main.c-213- if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
drivers/nfc/nfcmrvl/main.c:214: nci_recv_frame(priv->ndev, skb);
drivers/nfc/nfcmrvl/main.c-215- else {
--
drivers/nfc/nfcmrvl/main.c-222-}
drivers/nfc/nfcmrvl/main.c:223:EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
drivers/nfc/nfcmrvl/main.c-224-
--
drivers/nfc/nfcmrvl/nfcmrvl.h=119=void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
drivers/nfc/nfcmrvl/nfcmrvl.h:120:int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb);
drivers/nfc/nfcmrvl/nfcmrvl.h-121-struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
--
drivers/nfc/nfcmrvl/spi.c=27=static irqreturn_t nfcmrvl_spi_int_irq_thread_fn(int irq, void *drv_data_ptr)
--
drivers/nfc/nfcmrvl/spi.c-48-
drivers/nfc/nfcmrvl/spi.c:49: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/spi.c-50- nfc_err(&drv_data->spi->dev, "corrupted RX packet");
--
drivers/nfc/nfcmrvl/uart.c=152=static int nfcmrvl_nci_uart_recv(struct nci_uart *nu, struct sk_buff *skb)
drivers/nfc/nfcmrvl/uart.c-153-{
drivers/nfc/nfcmrvl/uart.c:154: return nfcmrvl_nci_recv_frame((struct nfcmrvl_private *)nu->drv_data,
drivers/nfc/nfcmrvl/uart.c-155- skb);
--
drivers/nfc/nfcmrvl/usb.c=57=static void nfcmrvl_bulk_complete(struct urb *urb)
--
drivers/nfc/nfcmrvl/usb.c-77- urb->actual_length);
drivers/nfc/nfcmrvl/usb.c:78: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/usb.c-79- nfc_err(&drv_data->udev->dev,
--
drivers/nfc/nxp-nci/i2c.c=189=static irqreturn_t nxp_nci_i2c_irq_thread_fn(int irq, void *phy_id)
--
drivers/nfc/nxp-nci/i2c.c-239- case NXP_NCI_MODE_NCI:
drivers/nfc/nxp-nci/i2c.c:240: nci_recv_frame(phy->ndev, skb);
drivers/nfc/nxp-nci/i2c.c-241- break;
--
drivers/nfc/s3fwrn5/core.c=210=int s3fwrn5_recv_frame(struct nci_dev *ndev, struct sk_buff *skb,
--
drivers/nfc/s3fwrn5/core.c-214- case S3FWRN5_MODE_NCI:
drivers/nfc/s3fwrn5/core.c:215: return nci_recv_frame(ndev, skb);
drivers/nfc/s3fwrn5/core.c-216- case S3FWRN5_MODE_FW:
--
drivers/nfc/st-nci/ndlc.c=147=static void llt_ndlc_rcv_queue(struct llt_ndlc *ndlc)
--
drivers/nfc/st-nci/ndlc.c-188- } else if ((pcb & PCB_TYPE_MASK) == PCB_TYPE_DATAFRAME) {
drivers/nfc/st-nci/ndlc.c:189: nci_recv_frame(ndlc->ndev, skb);
drivers/nfc/st-nci/ndlc.c-190- } else {
--
drivers/nfc/virtual_ncidev.c=113=static ssize_t virtual_ncidev_write(struct file *file,
--
drivers/nfc/virtual_ncidev.c-128-
drivers/nfc/virtual_ncidev.c:129: nci_recv_frame(vdev->ndev, skb);
drivers/nfc/virtual_ncidev.c-130- return count;
--
include/net/nfc/nci_core.h=291=int nci_core_init(struct nci_dev *ndev);
include/net/nfc/nci_core.h-292-
include/net/nfc/nci_core.h:293:int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
include/net/nfc/nci_core.h-294-int nci_send_frame(struct nci_dev *ndev, struct sk_buff *skb);
--
net/nfc/nci/core.c=1343=EXPORT_SYMBOL(nci_unregister_device);
--
net/nfc/nci/core.c-1345-/**
net/nfc/nci/core.c:1346: * nci_recv_frame - receive frame from NCI drivers
net/nfc/nci/core.c-1347- *
--
net/nfc/nci/core.c-1350- */
net/nfc/nci/core.c:1351:int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb)
net/nfc/nci/core.c-1352-{
--
net/nfc/nci/core.c-1366-}
net/nfc/nci/core.c:1367:EXPORT_SYMBOL(nci_recv_frame);
net/nfc/nci/core.c-1368-
]
|
| 24/2 |
2026/05/31 14:54 |
llm |
expert |
0m
Model:
Tokens:
input: 19710
output: 34
thoughts: 773
Thoughts: **Analyzing the NFC Driver Vulnerability**
Okay, so `nfcmrvl` has a USB driver, `drivers/nfc/nfcmrvl/usb.c`. My initial thought is that a rogue USB device could exploit this by sending a bad NCI response, triggering this uninitialized memory read. The key now is understanding the impact of this read.
The uninitialized memory, pulled from `skb`, gets written into `ndev->supported_rf_interfaces`. Then, in `nci_init_complete_req`, we iterate through this array. The code checks if the uninitialized value equals `NCI_RF_INTERFACE_ISO_DEP` or `NCI_RF_INTERFACE_NFC_DEP`. Based on these comparisons, the code populates `cfg[*num]` with constants and then sends an `NCI_OP_RF_DISCOVER_MAP_CMD` command to the NFC controller.
Initially, I thought we might be leaking the uninitialized memory directly back to the malicious device, which would be a serious issue. However, after careful review, it's NOT the contents of the uninitialized memory itself that get transmitted. Instead, the logic in `nci_init_complete_req` branches based on the *values* present in `ndev->supported_rf_interfaces`. So, the attacker (the USB device) can only infer whether a byte of uninitialized memory contained either `NCI_RF_INTERFACE_ISO_DEP` or `NCI_RF_INTERFACE_NFC_DEP` by examining the contents of the crafted command. This seems like a *very* weak information leak. It's essentially 1 bit of information per byte, and only if the byte happens to match one of two specific constants. I'll need to check if there are other usages of `ndev->supported_rf_interfaces` that might provide a more significant leakage.
|
| 25/2 |
2026/05/31 14:54 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:nci_dev::supported_rf_interfaces]
Results: map[References:[map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet SourceFile:net/nfc/nci/rsp.c SourceLine:140 SourceSnippet: 135:
136: pr_debug("nfcc_features 0x%x\n",
137: ndev->nfcc_features);
138: pr_debug("num_supported_rf_interfaces %d\n",
139: ndev->num_supported_rf_interfaces);
140: pr_debug("supported_rf_interfaces[0] 0x%x\n",
141: ndev->supported_rf_interfaces[0]);
142: pr_debug("supported_rf_interfaces[1] 0x%x\n",
143: ndev->supported_rf_interfaces[1]);
144: pr_debug("supported_rf_interfaces[2] 0x%x\n",
145: ndev->supported_rf_interfaces[2]);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet SourceFile:net/nfc/nci/rsp.c SourceLine:142 SourceSnippet: 137: ndev->nfcc_features);
138: pr_debug("num_supported_rf_interfaces %d\n",
139: ndev->num_supported_rf_interfaces);
140: pr_debug("supported_rf_interfaces[0] 0x%x\n",
141: ndev->supported_rf_interfaces[0]);
142: pr_debug("supported_rf_interfaces[1] 0x%x\n",
143: ndev->supported_rf_interfaces[1]);
144: pr_debug("supported_rf_interfaces[2] 0x%x\n",
145: ndev->supported_rf_interfaces[2]);
146: pr_debug("supported_rf_interfaces[3] 0x%x\n",
147: ndev->supported_rf_interfaces[3]);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet SourceFile:net/nfc/nci/rsp.c SourceLine:144 SourceSnippet: 139: ndev->num_supported_rf_interfaces);
140: pr_debug("supported_rf_interfaces[0] 0x%x\n",
141: ndev->supported_rf_interfaces[0]);
142: pr_debug("supported_rf_interfaces[1] 0x%x\n",
143: ndev->supported_rf_interfaces[1]);
144: pr_debug("supported_rf_interfaces[2] 0x%x\n",
145: ndev->supported_rf_interfaces[2]);
146: pr_debug("supported_rf_interfaces[3] 0x%x\n",
147: ndev->supported_rf_interfaces[3]);
148: pr_debug("max_logical_connections %d\n",
149: ndev->max_logical_connections);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet SourceFile:net/nfc/nci/rsp.c SourceLine:146 SourceSnippet: 141: ndev->supported_rf_interfaces[0]);
142: pr_debug("supported_rf_interfaces[1] 0x%x\n",
143: ndev->supported_rf_interfaces[1]);
144: pr_debug("supported_rf_interfaces[2] 0x%x\n",
145: ndev->supported_rf_interfaces[2]);
146: pr_debug("supported_rf_interfaces[3] 0x%x\n",
147: ndev->supported_rf_interfaces[3]);
148: pr_debug("max_logical_connections %d\n",
149: ndev->max_logical_connections);
150: pr_debug("max_routing_table_size %d\n",
151: ndev->max_routing_table_size);
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet_v1 SourceFile:net/nfc/nci/rsp.c SourceLine:65 SourceSnippet: 60:
61: ndev->num_supported_rf_interfaces =
62: min((int)ndev->num_supported_rf_interfaces,
63: NCI_MAX_SUPPORTED_RF_INTERFACES);
64:
65: memcpy(ndev->supported_rf_interfaces,
66: rsp_1->supported_rf_interfaces,
67: ndev->num_supported_rf_interfaces);
68:
69: rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
70:
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet_v1 SourceFile:net/nfc/nci/rsp.c SourceLine:65 SourceSnippet: 60:
61: ndev->num_supported_rf_interfaces =
62: min((int)ndev->num_supported_rf_interfaces,
63: NCI_MAX_SUPPORTED_RF_INTERFACES);
64:
65: memcpy(ndev->supported_rf_interfaces,
66: rsp_1->supported_rf_interfaces,
67: ndev->num_supported_rf_interfaces);
68:
69: rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
70:
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet_v1 SourceFile:net/nfc/nci/rsp.c SourceLine:65 SourceSnippet: 60:
61: ndev->num_supported_rf_interfaces =
62: min((int)ndev->num_supported_rf_interfaces,
63: NCI_MAX_SUPPORTED_RF_INTERFACES);
64:
65: memcpy(ndev->supported_rf_interfaces,
66: rsp_1->supported_rf_interfaces,
67: ndev->num_supported_rf_interfaces);
68:
69: rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
70:
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet_v2 SourceFile:net/nfc/nci/rsp.c SourceLine:107 SourceSnippet: 102: ndev->num_supported_rf_interfaces =
103: min((int)ndev->num_supported_rf_interfaces,
104: NCI_MAX_SUPPORTED_RF_INTERFACES);
105:
106: while (rf_interface_idx < ndev->num_supported_rf_interfaces) {
107: ndev->supported_rf_interfaces[rf_interface_idx++] = *supported_rf_interface++;
108:
109: /* skip rf extension parameters */
110: rf_extension_cnt = *supported_rf_interface++;
111: supported_rf_interface += rf_extension_cnt;
112: }
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_init_complete_req SourceFile:net/nfc/nci/core.c SourceLine:192 SourceSnippet: 187: /* set rf mapping configurations */
188: *num = 0;
189:
190: /* by default mapping is set to NCI_RF_INTERFACE_FRAME */
191: for (i = 0; i < ndev->num_supported_rf_interfaces; i++) {
192: if (ndev->supported_rf_interfaces[i] ==
193: NCI_RF_INTERFACE_ISO_DEP) {
194: cfg[*num].rf_protocol = NCI_RF_PROTOCOL_ISO_DEP;
195: cfg[*num].mode = NCI_DISC_MAP_MODE_POLL |
196: NCI_DISC_MAP_MODE_LISTEN;
197: cfg[*num].rf_interface = NCI_RF_INTERFACE_ISO_DEP;
] map[ReferenceKind:reads ReferencingEntityKind:function ReferencingEntityName:nci_init_complete_req SourceFile:net/nfc/nci/core.c SourceLine:199 SourceSnippet: 194: cfg[*num].rf_protocol = NCI_RF_PROTOCOL_ISO_DEP;
195: cfg[*num].mode = NCI_DISC_MAP_MODE_POLL |
196: NCI_DISC_MAP_MODE_LISTEN;
197: cfg[*num].rf_interface = NCI_RF_INTERFACE_ISO_DEP;
198: (*num)++;
199: } else if (ndev->supported_rf_interfaces[i] ==
200: NCI_RF_INTERFACE_NFC_DEP) {
201: cfg[*num].rf_protocol = NCI_RF_PROTOCOL_NFC_DEP;
202: cfg[*num].mode = NCI_DISC_MAP_MODE_POLL |
203: NCI_DISC_MAP_MODE_LISTEN;
204: cfg[*num].rf_interface = NCI_RF_INTERFACE_NFC_DEP;
]] TruncatedOutput:false]
|
| 26/2 |
2026/05/31 14:54 |
llm |
expert |
0m
Model:
Tokens:
input: 23683
output: 37
thoughts: 1046
Thoughts: **Analyzing a Potential Out-of-Bounds Read in NCI Core Initialization**
Okay, so I'm looking at this `nci_core_init_rsp_packet` function. I see that it debug-prints the first four elements of `ndev->supported_rf_interfaces`. It's a `pr_debug`, which means it's only active if dynamic debug is enabled or `DEBUG` is defined. This isn't a direct user-space leak, unless dmesg is readable and dynamic debug is on, so that's good to keep in mind, but not the core issue.
Now, the real issue seems to be an out-of-bounds read in `nci_core_init_rsp_packet_v2`. Let me break this down. The code casts `skb->data` to `nci_core_init_rsp_nci_ver2` and then extracts the `supported_rf_interfaces`. If `skb->len` is very small, say zero, then `rsp->num_supported_rf_interfaces` reads either uninitialized memory or goes out of bounds. The `skb->data` pointer points to the payload of the skb. When allocating the skb with `alloc_skb`, the size of the data buffer is determined by `count` rounded up to the next slab size. If `count` is small, then `rsp->num_supported_rf_interfaces` might read past the initialized data, but *within* the allocated skb buffer (since `alloc_skb` ensures a minimum size, and `skb_put` only increments `tail`). If `count` is zero, `skb_put` does nothing, and `skb->data` points to the start of the uninitialized buffer allocated by `alloc_skb`.
So, if `count` is small, it leads to reading uninitialized memory from the skb buffer. But can it go past the end of the buffer? `struct nci_core_init_rsp_nci_ver2` has a size of 14 bytes. If `num_supported_rf_interfaces` is large, the `while` loop advances `supported_rf_interface` by `1 + 1 + rf_extension_cnt` in each iteration. `rf_extension_cnt` is also read from uninitialized memory, potentially up to 255. So each iteration advances by a maximum of 257 bytes. If `num_supported_rf_interfaces` can reach the maximum `NCI_MAX_SUPPORTED_RF_INTERFACES` value (which is 4), that could advance the pointer by 4 * 257 = 1028 bytes. The skb buffer size is `count` rounded up. If `count` is small (say, 256 bytes), the `supported_rf_interface` pointer could absolutely go past the end of the allocated skb buffer! I'd better double-check the minimum size constraints for an skb buffer.
|
| 27/2 |
2026/05/31 14:54 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/core/skbuff.c Name:__alloc_skb]
Results: map[SourceCode: 655: /**
656: * __alloc_skb - allocate a network buffer
657: * @size: size to allocate
658: * @gfp_mask: allocation mask
659: * @flags: If SKB_ALLOC_FCLONE is set, allocate from fclone cache
660: * instead of head cache and allocate a cloned (child) skb.
661: * If SKB_ALLOC_RX is set, __GFP_MEMALLOC will be used for
662: * allocations in case the data is required for writeback
663: * @node: numa node to allocate memory on
664: *
665: * Allocate a new &sk_buff. The returned buffer has no headroom and a
666: * tail room of at least size bytes. The object has a reference count
667: * of one. The return is the buffer. On a failure the return is %NULL.
668: *
669: * Buffers may only be allocated from interrupts using a @gfp_mask of
670: * %GFP_ATOMIC.
671: */
672: struct sk_buff *__alloc_skb(unsigned int size, gfp_t gfp_mask,
673: int flags, int node)
674: {
675: struct sk_buff *skb = NULL;
676: struct kmem_cache *cache;
677: u8 *data;
678:
679: if (sk_memalloc_socks() && (flags & SKB_ALLOC_RX))
680: gfp_mask |= __GFP_MEMALLOC;
681:
682: if (flags & SKB_ALLOC_FCLONE) {
683: cache = net_hotdata.skbuff_fclone_cache;
684: goto fallback;
685: }
686: cache = net_hotdata.skbuff_cache;
687: if (unlikely(node != NUMA_NO_NODE && node != numa_mem_id()))
688: goto fallback;
689:
690: if (flags & SKB_ALLOC_NAPI) {
691: skb = napi_skb_cache_get(true);
692: if (unlikely(!skb))
693: return NULL;
694: } else if (!in_hardirq() && !irqs_disabled()) {
695: local_bh_disable();
696: skb = napi_skb_cache_get(false);
697: local_bh_enable();
698: }
699:
700: if (!skb) {
701: fallback:
702: skb = kmem_cache_alloc_node(cache, gfp_mask & ~GFP_DMA, node);
703: if (unlikely(!skb))
704: return NULL;
705: }
706: skbuff_clear(skb);
707:
708: /* We do our best to align skb_shared_info on a separate cache
709: * line. It usually works because kmalloc(X > SMP_CACHE_BYTES) gives
710: * aligned memory blocks, unless SLUB/SLAB debug is enabled.
711: * Both skb->head and skb_shared_info are cache line aligned.
712: */
713: data = kmalloc_reserve(&size, gfp_mask, node, skb);
714: if (unlikely(!data))
715: goto nodata;
716: /* kmalloc_size_roundup() might give us more room than requested.
717: * Put skb_shared_info exactly at the end of allocated zone,
718: * to allow max possible filling before reallocation.
719: */
720: __finalize_skb_around(skb, data, size);
721:
722: if (flags & SKB_ALLOC_FCLONE) {
723: struct sk_buff_fclones *fclones;
724:
725: fclones = container_of(skb, struct sk_buff_fclones, skb1);
726:
727: /* skb->fclone is a 2bits field.
728: * Replace expensive RMW (skb->fclone = SKB_FCLONE_ORIG)
729: * with a single OR.
730: */
731: BUILD_BUG_ON(SKB_FCLONE_UNAVAILABLE != 0);
732: DEBUG_NET_WARN_ON_ONCE(skb->fclone != SKB_FCLONE_UNAVAILABLE);
733: skb->fclone |= SKB_FCLONE_ORIG;
734:
735: refcount_set(&fclones->fclone_ref, 1);
736: }
737:
738: return skb;
739:
740: nodata:
741: kmem_cache_free(cache, skb);
742: return NULL;
743: }
SourceFile:net/core/skbuff.c]
|
| 28/2 |
2026/05/31 14:54 |
llm |
expert |
1m
Model:
Tokens:
input: 26917
output: 41
thoughts: 196
Thoughts: **Analyzing a Potential Heap Out-of-Bounds Read**
Okay, so I'm looking at this `kmalloc_reserve` function and it's grabbing `size` plus the size of the `skb_shared_info` structure, aligned, which makes sense for network buffers. But it seems like if `count` is small, we're talking about a small allocation β maybe 256 bytes or something like that. The problem lies with this `rf_extension_cnt` variable. If it gets set high enough, `supported_rf_interface` could march right past the end of that allocated buffer! And then when we dereference `*supported_rf_interface`, bam, we've got an out-of-bounds read on the heap. Classic!
But wait a minute... `virtual_ncidev_write` is the only place I see this actually *triggered*. And that function requires root privileges. That's a huge hurdle. So, how else can this be exploited? Is there *any* other way? My intuition tells me to consider a real NFC device and see if a malformed response could somehow trigger this vulnerability. Let's look at how NFC drivers typically handle incoming frames. Specifically, I'm thinking about `nfcmrvl_nci_recv_frame` in `drivers/nfc/nfcmrvl/main.c`. That's a good place to start digging.
|
| 29/2 |
2026/05/31 14:55 |
tool |
read-file |
0m
Args: map[File:drivers/nfc/nfcmrvl/main.c FirstLine:190 LineCount:50]
Results: map[Contents: 190: kfree(priv);
191: }
192: EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
193:
194: int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
195: {
196: if (priv->config.hci_muxed) {
197: if (skb->data[0] == NFCMRVL_HCI_EVENT_CODE &&
198: skb->data[1] == NFCMRVL_HCI_NFC_EVENT_CODE) {
199: /* Data packet, let's extract NCI payload */
200: skb_pull(skb, NFCMRVL_HCI_EVENT_HEADER_SIZE);
201: } else {
202: /* Skip this packet */
203: kfree_skb(skb);
204: return 0;
205: }
206: }
207:
208: if (priv->ndev->nfc_dev->fw_download_in_progress) {
209: nfcmrvl_fw_dnld_recv_frame(priv, skb);
210: return 0;
211: }
212:
213: if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
214: nci_recv_frame(priv->ndev, skb);
215: else {
216: /* Drop this packet since nobody wants it */
217: kfree_skb(skb);
218: return 0;
219: }
220:
221: return 0;
222: }
223: EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
224:
225: void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
226: {
227: /* Reset possible fault of previous session */
228: clear_bit(NFCMRVL_PHY_ERROR, &priv->flags);
229:
230: if (priv->config.reset_gpio) {
231: nfc_info(priv->dev, "reset the chip\n");
232: gpiod_set_value(priv->config.reset_gpio, 1);
233: usleep_range(5000, 10000);
234: gpiod_set_value(priv->config.reset_gpio, 0);
235: } else
236: nfc_info(priv->dev, "no reset available on this interface\n");
237: }
238:
239: void nfcmrvl_chip_halt(struct nfcmrvl_private *priv)
]
|
| 30/2 |
2026/05/31 14:55 |
llm |
expert |
0m
Model:
Tokens:
input: 28292
output: 40
thoughts: 37
Thoughts: Here's a summary of my understanding, framed from my perspective as an expert:
**Understanding the Data Flow in NFC Reception**
Okay, so I'm looking at this `nfcmrvl_nci_recv_frame` function, and it's pretty clear that it acts as the top-level receiver for NFC data, ultimately calling `nci_recv_frame`. This makes sense; it's the entry point for handling incoming frames. What's crucial here is recognizing the `skb` β that's the *socket buffer*. The critical piece is that the USB driver is responsible for its allocation. This tells me a lot. Since the USB driver has allocated the `skb`, it implies that this particular NFC implementation is tightly integrated with the USB interface for the data transfer. I'll need to remember this when I start tracing the flow later. That allocation choice dictates the memory management I'll need to keep in mind, alongside the timing considerations inherent with USB transfers. Got it.
|
| 31/2 |
2026/05/31 14:55 |
tool |
read-file |
0m
Args: map[File:drivers/nfc/nfcmrvl/usb.c FirstLine:50 LineCount:50]
Results: map[Contents: 50: if (!rv)
51: drv_data->tx_in_flight++;
52: spin_unlock_irqrestore(&drv_data->txlock, flags);
53:
54: return rv;
55: }
56:
57: static void nfcmrvl_bulk_complete(struct urb *urb)
58: {
59: struct nfcmrvl_usb_drv_data *drv_data = urb->context;
60: int err;
61:
62: dev_dbg(&drv_data->udev->dev, "urb %p status %d count %d\n",
63: urb, urb->status, urb->actual_length);
64:
65: if (!test_bit(NFCMRVL_NCI_RUNNING, &drv_data->flags))
66: return;
67:
68: if (!urb->status) {
69: struct sk_buff *skb;
70:
71: skb = nci_skb_alloc(drv_data->priv->ndev, urb->actual_length,
72: GFP_ATOMIC);
73: if (!skb) {
74: nfc_err(&drv_data->udev->dev, "failed to alloc mem\n");
75: } else {
76: skb_put_data(skb, urb->transfer_buffer,
77: urb->actual_length);
78: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
79: nfc_err(&drv_data->udev->dev,
80: "corrupted Rx packet\n");
81: }
82: }
83:
84: if (!test_bit(NFCMRVL_USB_BULK_RUNNING, &drv_data->flags))
85: return;
86:
87: usb_anchor_urb(urb, &drv_data->bulk_anchor);
88: usb_mark_last_busy(drv_data->udev);
89:
90: err = usb_submit_urb(urb, GFP_ATOMIC);
91: if (err) {
92: /* -EPERM: urb is being killed;
93: * -ENODEV: device got disconnected
94: */
95: if (err != -EPERM && err != -ENODEV)
96: nfc_err(&drv_data->udev->dev,
97: "urb %p failed to resubmit (%d)\n", urb, -err);
98: usb_unanchor_urb(urb);
99: }
]
|
| 32/2 |
2026/05/31 14:55 |
llm |
expert |
0m
Model:
Tokens:
input: 29340
output: 42
thoughts: 212
Thoughts: **Analyzing a Potential Vulnerability in NCI Packet Handling**
Okay, so I'm looking at this `nfcmrvl_bulk_complete` function, and my immediate concern is with the memory allocation and copying. The code calls `nci_skb_alloc` with `urb->actual_length`, then `skb_put_data` copies that many bytes from `urb->transfer_buffer` into the `skb`. That's standard, but it opens a door if the USB device sends a dodgy packet. Specifically, if `urb->actual_length` is smaller than expected for a valid NCI packet, `nci_core_init_rsp_packet_v2` is going to attempt to read beyond the actual data within the allocated `skb` buffer.
My initial thought was, since the `skb` memory is being allocated, this out-of-bounds read would likely grab some uninitialized memory from the heap, and that could lead to information leaks or unpredictable behavior. But now, I'm thinking about `rf_extension_cnt` potentially influencing this issue, if the allocated buffer is not large enough for the read that is going on, the heap can be overread.
But wait a minute, `nci_skb_alloc` allocates more than just `len`. It's `len + ndev->tx_headroom + ndev->tx_tailroom`, right? Okay, so the `headroom` and `tailroom` should provide some buffer for the NCI header and potentially other fields, even if the payload is malformed. I need to dig into the exact definition and usage of these `headroom` and `tailroom` variables. Let me check the source code for `nci_skb_alloc` and understand exactly what these values are. I need to determine if this extra allocation is sufficient to mitigate the potential out-of-bounds read and, if not, what the exact exploit scenario is.
|
| 33/2 |
2026/05/31 14:55 |
tool |
codesearch-definition-source |
0m
Args: map[ContextFile:net/nfc/nci/core.c Name:nci_skb_alloc]
Results: map[SourceCode: 324: static inline struct sk_buff *nci_skb_alloc(struct nci_dev *ndev,
325: unsigned int len,
326: gfp_t how)
327: {
328: struct sk_buff *skb;
329:
330: skb = alloc_skb(len + ndev->tx_headroom + ndev->tx_tailroom, how);
331: if (skb)
332: skb_reserve(skb, ndev->tx_headroom);
333:
334: return skb;
335: }
SourceFile:include/net/nfc/nci_core.h]
|
| 34/2 |
2026/05/31 14:55 |
llm |
expert |
0m
Model:
Tokens:
input: 30230
output: 38
thoughts: 808
Thoughts: **Analyzing a Potential Kernel Vulnerability**
Okay, so `alloc_skb` is definitely in play here. That immediately tells me a malicious USB device *could* potentially trigger an out-of-bounds read on the heap. My immediate next thought is always, what's the consequence? The data being read ends up in `ndev->supported_rf_interfaces`. I remember from my previous analysis that this variable feeds into `nci_init_complete_req`, specifically for constructing `NCI_OP_RF_DISCOVER_MAP_CMD`. But the read command only leaks whether those bytes match `NCI_RF_INTERFACE_ISO_DEP` (0x02) or `NCI_RF_INTERFACE_NFC_DEP` (0x03). Hmm, a very weak leak. Not a lot to play with there.
I need to expand my search. Is `ndev->supported_rf_interfaces` used *anywhere* else? Let me search... Ah, found it:
* `nci_core_init_rsp_packet` (reads for a `pr_debug`)
* `nci_core_init_rsp_packet_v1` (writes it)
* `nci_core_init_rsp_packet_v2` (writes it)
* `nci_init_complete_req` (reads it for that command)
Okay, so not much there either, just read/writes of the data. Could that out-of-bounds read actually lead to a crash? Could we leverage it for a Denial of Service?
Let's see. If `rf_extension_cnt` is large, `supported_rf_interface` advances quite a bit per iteration. Up to 257 bytes. And `num_supported_rf_interfaces` is up to 4, so it *could* advance up to 1028 bytes. Now, if the `skb->data` pointer is near the end of a page, reading 1028 bytes past it could mean crossing into an unmapped page. That would mean a page fault, which means kernel panic, a crash.
Okay, let's verify if `skb->data` can *indeed* be near the end of a page. `alloc_skb` allocates `len + tx_headroom + tx_tailroom`. If `len` is small, say 14 bytes, the overall allocation is small. `kmalloc` uses slab caches (like kmalloc-256). So the allocated chunk is aligned to that slab size. `skb->head` points to the start. Then `skb_reserve` moves `skb->data` by `tx_headroom`, which is usually small. So `skb->data` is normally near the *beginning* of the chunk. The chunk itself is at least 256 bytes, so any read up to 256 bytes will stay within the chunk, nothing is harmed.
However, if it reads up to 1028 bytes, that *will* read past the end of the chunk. The chunk is within a slab page, so that means the read will continue into other chunks within the same page. But can it cross a page boundary? Yes. The chunk *could* be right at the end of the page. Then a 1028 byte read past the start of the chunk *will* cross the page boundary. If that next page is unmapped, boom. Page fault. Crash.
So, in conclusion, a malicious USB device *could* cause a Denial of Service. A specially crafted NCI response that triggers an out-of-bounds read via `alloc_skb` could lead to a kernel panic by causing a page fault, if the allocation and read are carefully aligned. Wait, are we certain that `num_supported_rf_interfaces` is limited to 4? Let's go check `nci_core_init_rsp_packet_v2`...
|
| 35/2 |
2026/05/31 14:56 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/rsp.c FirstLine:95 LineCount:30]
Results: map[Contents: 95:
96: if (rsp->status != NCI_STATUS_OK)
97: return rsp->status;
98:
99: ndev->nfcc_features = __le32_to_cpu(rsp->nfcc_features);
100: ndev->num_supported_rf_interfaces = rsp->num_supported_rf_interfaces;
101:
102: ndev->num_supported_rf_interfaces =
103: min((int)ndev->num_supported_rf_interfaces,
104: NCI_MAX_SUPPORTED_RF_INTERFACES);
105:
106: while (rf_interface_idx < ndev->num_supported_rf_interfaces) {
107: ndev->supported_rf_interfaces[rf_interface_idx++] = *supported_rf_interface++;
108:
109: /* skip rf extension parameters */
110: rf_extension_cnt = *supported_rf_interface++;
111: supported_rf_interface += rf_extension_cnt;
112: }
113:
114: ndev->max_logical_connections = rsp->max_logical_connections;
115: ndev->max_routing_table_size =
116: __le16_to_cpu(rsp->max_routing_table_size);
117: ndev->max_ctrl_pkt_payload_len =
118: rsp->max_ctrl_pkt_payload_len;
119: ndev->max_size_for_large_params = NCI_MAX_LARGE_PARAMS_NCI_v2;
120:
121: return NCI_STATUS_OK;
122: }
123:
124: static void nci_core_init_rsp_packet(struct nci_dev *ndev, const struct sk_buff *skb)
]
|
| 36/2 |
2026/05/31 14:56 |
llm |
expert |
0m
Model:
Tokens:
input: 32475
output: 48
thoughts: 32
Thoughts: Okay, here's my interpretation of that thought process, summarized as you requested:
**Understanding Interface Limits**
Alright, let's see. My initial question was whether there's a practical limit on the number of supported RF interfaces. The key phrase here is `ndev->num_supported_rf_interfaces`. I've assessed that variable and the critical insight is that this is indeed constrained. This number is directly bounded by `NCI_MAX_SUPPORTED_RF_INTERFACES`. Therefore, the implementation accounts for a defined maximum number of radio frequency interfaces, and it's something I can use for designing the right solution.
|
| 37/2 |
2026/05/31 14:56 |
tool |
codesearch-definition-source |
0m
Error:
Args: map[ContextFile:net/nfc/nci/rsp.c Name:NCI_MAX_SUPPORTED_RF_INTERFACES]
Results: map[SourceCode: SourceFile:]
|
| 38/2 |
2026/05/31 14:56 |
llm |
expert |
0m
Model:
Tokens:
input: 32711
output: 27
thoughts: 20
Thoughts: Here's my thought process, summarized as you requested:
**Digging into Radio Interface Limits**
Okay, so I need to figure out what the maximum number of RF interfaces we support is, and I'm pretty sure I remember seeing a constant related to this somewhere. Time to get down to brass tacks. My initial thought is to use `grep`. It's my go-to tool for finding text patterns within code and config files, a real workhorse. I'll search for the constant that seems the most likely, and the name that pops into my head, is `NCI_MAX_SUPPORTED_RF_INTERFACES`. I'll run `grep` and see what comes up. That should quickly narrow down the location, if not immediately reveal the value itself, so I can continue my work on this problem. Let's see what `grep` unearths.
|
| 39/2 |
2026/05/31 14:56 |
tool |
grepper |
0m
Args: map[Expression:NCI_MAX_SUPPORTED_RF_INTERFACES]
Results: map[Output:include/net/nfc/nci_core.h=65=struct nci_ops {
--
include/net/nfc/nci_core.h-92-
include/net/nfc/nci_core.h:93:#define NCI_MAX_SUPPORTED_RF_INTERFACES 4
include/net/nfc/nci_core.h-94-#define NCI_MAX_DISCOVERED_TARGETS 10
--
include/net/nfc/nci_core.h=196=struct nci_dev {
--
include/net/nfc/nci_core.h-248- __u8 supported_rf_interfaces
include/net/nfc/nci_core.h:249: [NCI_MAX_SUPPORTED_RF_INTERFACES];
include/net/nfc/nci_core.h-250- __u8 max_logical_connections;
--
net/nfc/nci/rsp.c=47=static u8 nci_core_init_rsp_packet_v1(struct nci_dev *ndev,
--
net/nfc/nci/rsp.c-62- min((int)ndev->num_supported_rf_interfaces,
net/nfc/nci/rsp.c:63: NCI_MAX_SUPPORTED_RF_INTERFACES);
net/nfc/nci/rsp.c-64-
--
net/nfc/nci/rsp.c=86=static u8 nci_core_init_rsp_packet_v2(struct nci_dev *ndev,
--
net/nfc/nci/rsp.c-103- min((int)ndev->num_supported_rf_interfaces,
net/nfc/nci/rsp.c:104: NCI_MAX_SUPPORTED_RF_INTERFACES);
net/nfc/nci/rsp.c-105-
]
|
| 40/2 |
2026/05/31 14:56 |
llm |
expert |
0m
Model:
Tokens:
input: 33447
output: 37
thoughts: 404
Thoughts: **Analyzing a Potential Denial of Service Vulnerability**
Okay, so I'm digging into this code and thinking through a potential DoS vulnerability. I've confirmed that `NCI_MAX_SUPPORTED_RF_INTERFACES` is indeed 4. That means `supported_rf_interface` could potentially advance by a maximum of 1028 bytes (4 * 257). The problem arises if the data chunk resides at the very end of a page. If a read goes 1028 bytes past the beginning of that chunk, it's very possible that it would cross the page boundary.
Now, `alloc_skb` allocates memory for the packet's data plus the `skb_shared_info` structure, the latter being 320 bytes on 64-bit systems. The minimum allocation ends up being 334 bytes (14 + 320), rounded up to the nearest kmalloc slab size, which is 512 bytes. So a 512-byte chunk *could* be placed right at the end of a page. Let's say it's at offset 3584 in a 4096-byte page. Reading 1028 bytes beyond that would land at offset 4612. That's definitely over the 4096-byte boundary. If that next page isn't mapped, *boom*, page fault, Denial of Service. That seems pretty straightforward, it's vulnerable if the packet is crafted correctly.
But wait, I need to consider all the angles. Is there *another* way to trigger this? I have to consider the attack surface. What about `virtual_ncidev_write`? I remember checking the permissions on `/dev/virtual_nci`, and it was created with mode 0600. So, it's only accessible to root. That should be safe...unless something is missed, there's always a possibility.
However, can an unprivileged user send NCI frames through Netlink? I should check `nfc_genl_dev_up` to verify. I need to investigate that code path to be certain about the attack surface.
|
| 41/2 |
2026/05/31 14:56 |
tool |
read-file |
0m
Args: map[File:net/nfc/netlink.c FirstLine:760 LineCount:50]
Results: map[Contents: 760: static int nfc_genl_dev_up(struct sk_buff *skb, struct genl_info *info)
761: {
762: struct nfc_dev *dev;
763: int rc;
764: u32 idx;
765:
766: if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
767: return -EINVAL;
768:
769: idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
770:
771: dev = nfc_get_device(idx);
772: if (!dev)
773: return -ENODEV;
774:
775: rc = nfc_dev_up(dev);
776:
777: nfc_put_device(dev);
778: return rc;
779: }
780:
781: static int nfc_genl_dev_down(struct sk_buff *skb, struct genl_info *info)
782: {
783: struct nfc_dev *dev;
784: int rc;
785: u32 idx;
786:
787: if (!info->attrs[NFC_ATTR_DEVICE_INDEX])
788: return -EINVAL;
789:
790: idx = nla_get_u32(info->attrs[NFC_ATTR_DEVICE_INDEX]);
791:
792: dev = nfc_get_device(idx);
793: if (!dev)
794: return -ENODEV;
795:
796: rc = nfc_dev_down(dev);
797:
798: nfc_put_device(dev);
799: return rc;
800: }
801:
802: static int nfc_genl_start_poll(struct sk_buff *skb, struct genl_info *info)
803: {
804: struct nfc_dev *dev;
805: int rc;
806: u32 idx;
807: u32 im_protocols = 0, tm_protocols = 0;
808:
809: pr_debug("Poll start\n");
]
|
| 42/2 |
2026/05/31 14:56 |
llm |
expert |
0m
Model:
Tokens:
input: 35063
output: 20
thoughts: 270
Thoughts: **My Analysis of the NFC Initialization Sequence**
Okay, so `nfc_genl_dev_up` initiates the NFC device bring-up, calling `nfc_dev_up` which in turn calls `nci_dev_up`. My concern, as always, is security. It looks like `nci_dev_up` is the function that actually sends the `NCI_OP_CORE_INIT_CMD` to the NFC controller and then patiently waits for the response. That response, interestingly, isn't handled synchronously. It's received asynchronously through a driver-specific mechanism (like USB), and gets passed up to `nci_recv_frame`. Then `nci_rx_work` handles that and specifically calls `nci_core_init_rsp_packet_v2`.
So, `nfc_genl_dev_up` is just a trigger, a kickoff for the initialization. It doesn't seem to have a direct vulnerability allowing an unprivileged user to inject a malformed response β good. That malformed response *must* originate from the NFC controller itself (a potentially malicious USB device, for example), or from `/dev/virtual_nci`, which is root-only.
But wait a minute⦠is that the only place NCI frames are received? Are there any other ways to inject them? Could something like `nfc_genl_llc_sdreq` or other netlink commands be leveraged? My experience suggests Netlink is mostly for configuration, not raw frame injection, but I should verify. I need to exhaustively check for other potential users of `nci_recv_frame` in the code.
|
| 43/2 |
2026/05/31 14:56 |
tool |
grepper |
0m
Args: map[Expression:nci_recv_frame]
Results: map[Output:drivers/nfc/fdp/i2c.c=195=static irqreturn_t fdp_nci_i2c_irq_thread_fn(int irq, void *phy_id)
--
drivers/nfc/fdp/i2c.c-211- if (skb != NULL)
drivers/nfc/fdp/i2c.c:212: nci_recv_frame(phy->ndev, skb);
drivers/nfc/fdp/i2c.c-213-
--
drivers/nfc/nfcmrvl/i2c.c=64=static irqreturn_t nfcmrvl_i2c_int_irq_thread_fn(int irq, void *drv_data_ptr)
--
drivers/nfc/nfcmrvl/i2c.c-86- default:
drivers/nfc/nfcmrvl/i2c.c:87: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/i2c.c-88- nfc_err(&drv_data->i2c->dev, "corrupted RX packet\n");
--
drivers/nfc/nfcmrvl/main.c=192=EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
drivers/nfc/nfcmrvl/main.c-193-
drivers/nfc/nfcmrvl/main.c:194:int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
drivers/nfc/nfcmrvl/main.c-195-{
--
drivers/nfc/nfcmrvl/main.c-213- if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
drivers/nfc/nfcmrvl/main.c:214: nci_recv_frame(priv->ndev, skb);
drivers/nfc/nfcmrvl/main.c-215- else {
--
drivers/nfc/nfcmrvl/main.c-222-}
drivers/nfc/nfcmrvl/main.c:223:EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
drivers/nfc/nfcmrvl/main.c-224-
--
drivers/nfc/nfcmrvl/nfcmrvl.h=119=void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
drivers/nfc/nfcmrvl/nfcmrvl.h:120:int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb);
drivers/nfc/nfcmrvl/nfcmrvl.h-121-struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
--
drivers/nfc/nfcmrvl/spi.c=27=static irqreturn_t nfcmrvl_spi_int_irq_thread_fn(int irq, void *drv_data_ptr)
--
drivers/nfc/nfcmrvl/spi.c-48-
drivers/nfc/nfcmrvl/spi.c:49: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/spi.c-50- nfc_err(&drv_data->spi->dev, "corrupted RX packet");
--
drivers/nfc/nfcmrvl/uart.c=152=static int nfcmrvl_nci_uart_recv(struct nci_uart *nu, struct sk_buff *skb)
drivers/nfc/nfcmrvl/uart.c-153-{
drivers/nfc/nfcmrvl/uart.c:154: return nfcmrvl_nci_recv_frame((struct nfcmrvl_private *)nu->drv_data,
drivers/nfc/nfcmrvl/uart.c-155- skb);
--
drivers/nfc/nfcmrvl/usb.c=57=static void nfcmrvl_bulk_complete(struct urb *urb)
--
drivers/nfc/nfcmrvl/usb.c-77- urb->actual_length);
drivers/nfc/nfcmrvl/usb.c:78: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/usb.c-79- nfc_err(&drv_data->udev->dev,
--
drivers/nfc/nxp-nci/i2c.c=189=static irqreturn_t nxp_nci_i2c_irq_thread_fn(int irq, void *phy_id)
--
drivers/nfc/nxp-nci/i2c.c-239- case NXP_NCI_MODE_NCI:
drivers/nfc/nxp-nci/i2c.c:240: nci_recv_frame(phy->ndev, skb);
drivers/nfc/nxp-nci/i2c.c-241- break;
--
drivers/nfc/s3fwrn5/core.c=210=int s3fwrn5_recv_frame(struct nci_dev *ndev, struct sk_buff *skb,
--
drivers/nfc/s3fwrn5/core.c-214- case S3FWRN5_MODE_NCI:
drivers/nfc/s3fwrn5/core.c:215: return nci_recv_frame(ndev, skb);
drivers/nfc/s3fwrn5/core.c-216- case S3FWRN5_MODE_FW:
--
drivers/nfc/st-nci/ndlc.c=147=static void llt_ndlc_rcv_queue(struct llt_ndlc *ndlc)
--
drivers/nfc/st-nci/ndlc.c-188- } else if ((pcb & PCB_TYPE_MASK) == PCB_TYPE_DATAFRAME) {
drivers/nfc/st-nci/ndlc.c:189: nci_recv_frame(ndlc->ndev, skb);
drivers/nfc/st-nci/ndlc.c-190- } else {
--
drivers/nfc/virtual_ncidev.c=113=static ssize_t virtual_ncidev_write(struct file *file,
--
drivers/nfc/virtual_ncidev.c-128-
drivers/nfc/virtual_ncidev.c:129: nci_recv_frame(vdev->ndev, skb);
drivers/nfc/virtual_ncidev.c-130- return count;
--
include/net/nfc/nci_core.h=291=int nci_core_init(struct nci_dev *ndev);
include/net/nfc/nci_core.h-292-
include/net/nfc/nci_core.h:293:int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
include/net/nfc/nci_core.h-294-int nci_send_frame(struct nci_dev *ndev, struct sk_buff *skb);
--
net/nfc/nci/core.c=1343=EXPORT_SYMBOL(nci_unregister_device);
--
net/nfc/nci/core.c-1345-/**
net/nfc/nci/core.c:1346: * nci_recv_frame - receive frame from NCI drivers
net/nfc/nci/core.c-1347- *
--
net/nfc/nci/core.c-1350- */
net/nfc/nci/core.c:1351:int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb)
net/nfc/nci/core.c-1352-{
--
net/nfc/nci/core.c-1366-}
net/nfc/nci/core.c:1367:EXPORT_SYMBOL(nci_recv_frame);
net/nfc/nci/core.c-1368-
]
|
| 44/2 |
2026/05/31 14:56 |
llm |
expert |
0m
Model:
Tokens:
input: 37903
output: 39
thoughts: 671
Thoughts: **Analyzing the Attack Surface of `nci_recv_frame`**
Okay, so I'm digging into this `nci_recv_frame` function, trying to figure out how it can be triggered and whether there's a serious vulnerability. Let's see... the callers are: `fdp_nci_i2c_irq_thread_fn`, `nfcmrvl_nci_recv_frame`, `nxp_nci_i2c_irq_thread_fn`, `s3fwrn5_recv_frame`, `llt_ndlc_rcv_queue`, and `virtual_ncidev_write`. That's a pretty diverse set.
The immediate takeaway is that this bug seems to be triggered by malicious input from an NFC controller. That's the common denominator across all these drivers: I2C, SPI, UART, USB or a root-only misc device. A malicious USB device seems like the easiest vector for an attacker, since an unprivileged user (or someone with physical access) could plug one in. This looks like a Peripheral Trigger. It's not remotely triggerable, obviously. No from a VM guest unless the USB device is passed through. No from a VM host in confidential computing either. Unprivileged processes are also out, because `/dev/virtual_nci` is root-only. User namespaces are also a no-go, because that device node is not accessible to them.
Hold on... what about `nfc_genl_dev_up`? Ah, right. An unprivileged user *can* send a netlink message to bring up the NFC device. That will, in turn, cause the kernel to send `NCI_OP_CORE_INIT_CMD` to the NFC controller. So, an unprivileged user can *initiate* the sequence. If the controller is malicious and returns a malformed response, then the bug *is* triggered. This also indicates that the bug requires a malicious NFC controller to occur.
Since this needs a malicious peripheral, this is definitely a peripheral trigger.
Now, is this bug actually exploitable? The description says it's an out-of-bounds read on the heap. The read data is used in a branch condition, meaning it *could* leak a single bit of information per byte to the NFC controller. It could also lead to a Denial of Service if the read crosses a page boundary into an unmapped page. However, it *is* an out-of-bounds read, so it shouldn't corrupt memory. That means no privilege escalation or code execution, just DoS and a weak information leak. A very weak information leak. I should double check, though, to ensure there's no out-of-bounds write.
|
| 45/2 |
2026/05/31 14:56 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/rsp.c FirstLine:100 LineCount:20]
Results: map[Contents: 100: ndev->num_supported_rf_interfaces = rsp->num_supported_rf_interfaces;
101:
102: ndev->num_supported_rf_interfaces =
103: min((int)ndev->num_supported_rf_interfaces,
104: NCI_MAX_SUPPORTED_RF_INTERFACES);
105:
106: while (rf_interface_idx < ndev->num_supported_rf_interfaces) {
107: ndev->supported_rf_interfaces[rf_interface_idx++] = *supported_rf_interface++;
108:
109: /* skip rf extension parameters */
110: rf_extension_cnt = *supported_rf_interface++;
111: supported_rf_interface += rf_extension_cnt;
112: }
113:
114: ndev->max_logical_connections = rsp->max_logical_connections;
115: ndev->max_routing_table_size =
116: __le16_to_cpu(rsp->max_routing_table_size);
117: ndev->max_ctrl_pkt_payload_len =
118: rsp->max_ctrl_pkt_payload_len;
119: ndev->max_size_for_large_params = NCI_MAX_LARGE_PARAMS_NCI_v2;
]
|
| 46/2 |
2026/05/31 14:56 |
llm |
expert |
0m
Model:
Tokens:
input: 39594
output: 38
thoughts: 172
Thoughts: **Analyzing the RF Interface Write Operation**
Okay, let me break this down. I'm looking at a write operation, specifically targeting `ndev->supported_rf_interfaces[rf_interface_idx++]`. My immediate concern is always bounds checking. I need to ensure there are no buffer overflows or underflows.
I see that `rf_interface_idx` is acting as the index, starting at zero and incrementing. It seems to be iterating up to, but not including, `ndev->num_supported_rf_interfaces`. I know `ndev->num_supported_rf_interfaces` is itself bounded, courtesy of `NCI_MAX_SUPPORTED_RF_INTERFACES`, which I recall being defined as 4. And the target array, `ndev->supported_rf_interfaces`, is the same size.
Therefore, because `rf_interface_idx` increments from zero to a value *less* than the array's defined maximum size, this write *should* be strictly within bounds. I'm reasonably confident that this write is protected from causing an out-of-bounds error.
But wait a minute, I need to consider `nci_core_init_rsp_packet_v1`. Let me revisit my assumptions and ensure there's no subtle interaction or dependency I'm overlooking here that could influence the safety of this write...
|
| 47/2 |
2026/05/31 14:56 |
tool |
read-file |
0m
Args: map[File:net/nfc/nci/rsp.c FirstLine:45 LineCount:40]
Results: map[Contents: 45: }
46:
47: static u8 nci_core_init_rsp_packet_v1(struct nci_dev *ndev,
48: const struct sk_buff *skb)
49: {
50: const struct nci_core_init_rsp_1 *rsp_1 = (void *)skb->data;
51: const struct nci_core_init_rsp_2 *rsp_2;
52:
53: pr_debug("status 0x%x\n", rsp_1->status);
54:
55: if (rsp_1->status != NCI_STATUS_OK)
56: return rsp_1->status;
57:
58: ndev->nfcc_features = __le32_to_cpu(rsp_1->nfcc_features);
59: ndev->num_supported_rf_interfaces = rsp_1->num_supported_rf_interfaces;
60:
61: ndev->num_supported_rf_interfaces =
62: min((int)ndev->num_supported_rf_interfaces,
63: NCI_MAX_SUPPORTED_RF_INTERFACES);
64:
65: memcpy(ndev->supported_rf_interfaces,
66: rsp_1->supported_rf_interfaces,
67: ndev->num_supported_rf_interfaces);
68:
69: rsp_2 = (void *) (skb->data + 6 + rsp_1->num_supported_rf_interfaces);
70:
71: ndev->max_logical_connections = rsp_2->max_logical_connections;
72: ndev->max_routing_table_size =
73: __le16_to_cpu(rsp_2->max_routing_table_size);
74: ndev->max_ctrl_pkt_payload_len =
75: rsp_2->max_ctrl_pkt_payload_len;
76: ndev->max_size_for_large_params =
77: __le16_to_cpu(rsp_2->max_size_for_large_params);
78: ndev->manufact_id =
79: rsp_2->manufact_id;
80: ndev->manufact_specific_info =
81: __le32_to_cpu(rsp_2->manufact_specific_info);
82:
83: return NCI_STATUS_OK;
84: }
]
|
| 48/2 |
2026/05/31 14:56 |
llm |
expert |
1m
Model:
Tokens:
input: 40788
output: 37
thoughts: 1512
Thoughts: **My Analysis of the NCI Core Initialization Vulnerability**
Okay, let's break this down. In the `nci_core_init_rsp_packet_v1` function, I see a potential out-of-bounds read vulnerability. The size of the second response, `rsp_2`, is calculated based on `rsp_1->num_supported_rf_interfaces`, which isn't bounded before its use. If this value is large, I'm reading data beyond the allocated buffer. Specifically, I'm reading past the end of the `skb->data` buffer, potentially by up to 271 bytes. This is certainly an out-of-bounds read, albeit a controlled one in this version.
Now, can this be triggered? I immediately think about the attack vectors. A filesystem or network attack? No. That seems highly unlikely. An unprivileged user? Not directly. This function is typically triggered by responses from an NFC device. If a valid NFC device responds, it *shouldn't* send a malformed (too short) response, so that's a dead end for a normal system with real hardware. So, the attack vector has to be through a malicious NFC device. This makes it a peripheral trigger.
Reviewing the KMSAN report, it's clear syzkaller found the vulnerability through `/dev/virtual_nci`. This makes sense β syzkaller runs with root privileges and can craft packets to this virtual device. In a real-world scenario, however, this device is only accessible to root. The `virtual_ncidev_write` function is the point of entry here. So an unprivileged user can't exploit it this way in a normal system.
Thinking further, what if the NFC device is connected via I2C or SPI? Those are typically internal buses. An attacker can't just plug in a malicious I2C or SPI device, right? USB, though, is external and pluggable. Therefore, a peripheral trigger is the most relevant vector.
Could this be exploited for anything other than a denial of service? The out-of-bounds read *could* cause a page fault if it crosses a page boundary into an unmapped area. But it's just a read, so no memory corruption, no privilege escalation. Only a kernel panic, a Denial of Service. So, the exploitability is low.
Finally, let's confirm the security context. The virtual device node is mode 0600. Only the owner (root) can read/write to it. Even if a user somehow creates a user namespace (which is hard and restricted), they can't create device nodes without specific capabilities. And if the node *were* bind-mounted into a container, it would still be root-owned. It's not accessible to unprivileged users or within user namespaces.
I've checked the call sites of `nci_recv_frame` and `nci_core_init_rsp_packet_v2`, and there aren't any other obvious paths. It all comes back to NFC drivers and `virtual_ncidev`, all of which have access restrictions that prevent unprivileged users from triggering this bug.
|
| 49/2 |
2026/05/31 14:58 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:nci_core_init_rsp_packet_v2]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nci_core_init_rsp_packet SourceFile:net/nfc/nci/rsp.c SourceLine:131 SourceSnippet: 126: u8 status = 0;
127:
128: if (!(ndev->nci_ver & NCI_VER_2_MASK))
129: status = nci_core_init_rsp_packet_v1(ndev, skb);
130: else
131: status = nci_core_init_rsp_packet_v2(ndev, skb);
132:
133: if (status != NCI_STATUS_OK)
134: goto exit;
135:
136: pr_debug("nfcc_features 0x%x\n",
]] TruncatedOutput:false]
|
| 50/2 |
2026/05/31 14:58 |
llm |
expert |
0m
Model:
Tokens:
input: 43273
output: 34
thoughts: 41
Thoughts: Here's my thought process, summarized as you requested:
**Deconstructing `nci_core_init_rsp_packet`**
Okay, let's trace where this `nci_core_init_rsp_packet` function is being used. From the information provided, it looks like only one function calls it: `nci_core_init_rsp_packet`. And that function itself is called from `nci_rsp_packet`. This narrow usage pattern is interesting; it suggests a specific, potentially very focused, purpose within the overall framework of handling NCI response packets. I need to dig deeper into the functionality of `nci_rsp_packet` to understand the broader context. Understanding why this function is used only by those two functions will illuminate its core purpose. Are there any other initialization steps happening within `nci_rsp_packet`, or is the responsibility delegated? Knowing this, coupled with its singular direct caller, might reveal some design choices about the software architecture. I should check the implementation of `nci_core_init_rsp_packet` and those two functions.
|
| 51/2 |
2026/05/31 14:58 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:nci_core_init_rsp_packet]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nci_rsp_packet SourceFile:net/nfc/nci/rsp.c SourceLine:376 SourceSnippet: 371: case NCI_OP_CORE_RESET_RSP:
372: nci_core_reset_rsp_packet(ndev, skb);
373: break;
374:
375: case NCI_OP_CORE_INIT_RSP:
376: nci_core_init_rsp_packet(ndev, skb);
377: break;
378:
379: case NCI_OP_CORE_SET_CONFIG_RSP:
380: nci_core_set_config_rsp_packet(ndev, skb);
381: break;
]] TruncatedOutput:false]
|
| 52/2 |
2026/05/31 14:58 |
llm |
expert |
0m
Model:
Tokens:
input: 43835
output: 30
thoughts: 20
Thoughts: Okay, here's my interpretation of that.
**Analyzing the Data Flow**
Alright, let me break this down. From what I'm seeing, `nci_rsp_packet` is a function call. It's triggered, or more accurately *called from*, `nci_rx_work`. That's the core of the issue I need to explore. Essentially, I need to know why `nci_rsp_packet` is being called from within `nci_rx_work`, and the data flow between them. That tells me a lot about the response handling within the NCI stack. So `nci_rx_work` is processing incoming data (most likely NCI frames), and, somewhere along that chain, a response packet (perhaps an acknowledgement, or an event notification) is being handled by `nci_rsp_packet`. It's a critical point of interaction that warrants a deeper look. My next step will be mapping the calling context of `nci_rx_work` and the internal logic of `nci_rsp_packet` to fully grasp this interdependency. This is most likely a critical point for determining issues when dealing with response times or unexpected behavior during communications.
|
| 53/2 |
2026/05/31 14:58 |
tool |
codesearch-find-references |
0m
Args: map[IncludeSnippetLines:5 Name:nci_rsp_packet]
Results: map[References:[map[ReferenceKind:calls ReferencingEntityKind:function ReferencingEntityName:nci_rx_work SourceFile:net/nfc/nci/core.c SourceLine:1579 SourceSnippet:1574: }
1575:
1576: /* Process frame */
1577: switch (nci_mt(skb->data)) {
1578: case NCI_MT_RSP_PKT:
1579: nci_rsp_packet(ndev, skb);
1580: break;
1581:
1582: case NCI_MT_NTF_PKT:
1583: nci_ntf_packet(ndev, skb);
1584: break;
]] TruncatedOutput:false]
|
| 54/2 |
2026/05/31 14:58 |
llm |
expert |
0m
Model:
Tokens:
input: 44371
output: 20
thoughts: 312
Thoughts: **My Analysis of the NCI RX Workqueue Vulnerability**
Okay, so `nci_rx_work` is the function that handles the workqueue associated with `ndev->rx_work`. It's pretty straightforward: it processes SKBs (Socket Buffers) taken from `ndev->rx_q`. And, as I suspected, these SKBs get added to the queue via `nci_recv_frame`. The flow is exactly as I laid it out in my initial analysis, good.
Now, let's condense the assessment of the vulnerability itself.
* **Exploitability:** Definitely no on full-blown exploitation. This is an out-of-bounds read, leading to either a crash (DoS) or a very minimal information leak. No chance of memory corruption, which is the main thing.
* **Denial of Service:** Absolutely, yes. The out-of-bounds read has the potential to cross a page boundary and trigger a page fault, bringing things to a halt.
* **Privilege Level:** No, unprivileged processes can't reach this. Either a malicious USB device is necessary, or you'd need root access to `/dev/virtual_nci`.
* **User Namespaces:** Nope.
* **VM Guest/Host:** No, unless the USB device is explicitly passed through, which isn't the usual setup. That's a niche scenario.
* **Network/Remote Triggers:** Not triggered over Ethernet or any other remote interface.
* **Peripheral Trigger:** Yes, a malicious USB NFC device is a direct path to trigger this, which is the heart of the issue.
* **Filesystem:** No, this is not a malicious filesystem triggered vulnerability.
But wait, hold on, I need to consider all angles. Is there *any* other entry point? Could an unprivileged user use `AF_NFC` sockets to inject frames? That's the part that's bothering me and that I need to clarify to ensure my assessment is complete. I should check `net/nfc/rawsock.c` and `net/nfc/llcp_sock.c` to confirm my understanding of that aspect is correct.
|
| 55/2 |
2026/05/31 14:58 |
tool |
grepper |
0m
Args: map[Expression:nci_recv_frame]
Results: map[Output:drivers/nfc/fdp/i2c.c=195=static irqreturn_t fdp_nci_i2c_irq_thread_fn(int irq, void *phy_id)
--
drivers/nfc/fdp/i2c.c-211- if (skb != NULL)
drivers/nfc/fdp/i2c.c:212: nci_recv_frame(phy->ndev, skb);
drivers/nfc/fdp/i2c.c-213-
--
drivers/nfc/nfcmrvl/i2c.c=64=static irqreturn_t nfcmrvl_i2c_int_irq_thread_fn(int irq, void *drv_data_ptr)
--
drivers/nfc/nfcmrvl/i2c.c-86- default:
drivers/nfc/nfcmrvl/i2c.c:87: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/i2c.c-88- nfc_err(&drv_data->i2c->dev, "corrupted RX packet\n");
--
drivers/nfc/nfcmrvl/main.c=192=EXPORT_SYMBOL_GPL(nfcmrvl_nci_unregister_dev);
drivers/nfc/nfcmrvl/main.c-193-
drivers/nfc/nfcmrvl/main.c:194:int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
drivers/nfc/nfcmrvl/main.c-195-{
--
drivers/nfc/nfcmrvl/main.c-213- if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
drivers/nfc/nfcmrvl/main.c:214: nci_recv_frame(priv->ndev, skb);
drivers/nfc/nfcmrvl/main.c-215- else {
--
drivers/nfc/nfcmrvl/main.c-222-}
drivers/nfc/nfcmrvl/main.c:223:EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
drivers/nfc/nfcmrvl/main.c-224-
--
drivers/nfc/nfcmrvl/nfcmrvl.h=119=void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
drivers/nfc/nfcmrvl/nfcmrvl.h:120:int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb);
drivers/nfc/nfcmrvl/nfcmrvl.h-121-struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
--
drivers/nfc/nfcmrvl/spi.c=27=static irqreturn_t nfcmrvl_spi_int_irq_thread_fn(int irq, void *drv_data_ptr)
--
drivers/nfc/nfcmrvl/spi.c-48-
drivers/nfc/nfcmrvl/spi.c:49: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/spi.c-50- nfc_err(&drv_data->spi->dev, "corrupted RX packet");
--
drivers/nfc/nfcmrvl/uart.c=152=static int nfcmrvl_nci_uart_recv(struct nci_uart *nu, struct sk_buff *skb)
drivers/nfc/nfcmrvl/uart.c-153-{
drivers/nfc/nfcmrvl/uart.c:154: return nfcmrvl_nci_recv_frame((struct nfcmrvl_private *)nu->drv_data,
drivers/nfc/nfcmrvl/uart.c-155- skb);
--
drivers/nfc/nfcmrvl/usb.c=57=static void nfcmrvl_bulk_complete(struct urb *urb)
--
drivers/nfc/nfcmrvl/usb.c-77- urb->actual_length);
drivers/nfc/nfcmrvl/usb.c:78: if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
drivers/nfc/nfcmrvl/usb.c-79- nfc_err(&drv_data->udev->dev,
--
drivers/nfc/nxp-nci/i2c.c=189=static irqreturn_t nxp_nci_i2c_irq_thread_fn(int irq, void *phy_id)
--
drivers/nfc/nxp-nci/i2c.c-239- case NXP_NCI_MODE_NCI:
drivers/nfc/nxp-nci/i2c.c:240: nci_recv_frame(phy->ndev, skb);
drivers/nfc/nxp-nci/i2c.c-241- break;
--
drivers/nfc/s3fwrn5/core.c=210=int s3fwrn5_recv_frame(struct nci_dev *ndev, struct sk_buff *skb,
--
drivers/nfc/s3fwrn5/core.c-214- case S3FWRN5_MODE_NCI:
drivers/nfc/s3fwrn5/core.c:215: return nci_recv_frame(ndev, skb);
drivers/nfc/s3fwrn5/core.c-216- case S3FWRN5_MODE_FW:
--
drivers/nfc/st-nci/ndlc.c=147=static void llt_ndlc_rcv_queue(struct llt_ndlc *ndlc)
--
drivers/nfc/st-nci/ndlc.c-188- } else if ((pcb & PCB_TYPE_MASK) == PCB_TYPE_DATAFRAME) {
drivers/nfc/st-nci/ndlc.c:189: nci_recv_frame(ndlc->ndev, skb);
drivers/nfc/st-nci/ndlc.c-190- } else {
--
drivers/nfc/virtual_ncidev.c=113=static ssize_t virtual_ncidev_write(struct file *file,
--
drivers/nfc/virtual_ncidev.c-128-
drivers/nfc/virtual_ncidev.c:129: nci_recv_frame(vdev->ndev, skb);
drivers/nfc/virtual_ncidev.c-130- return count;
--
include/net/nfc/nci_core.h=291=int nci_core_init(struct nci_dev *ndev);
include/net/nfc/nci_core.h-292-
include/net/nfc/nci_core.h:293:int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb);
include/net/nfc/nci_core.h-294-int nci_send_frame(struct nci_dev *ndev, struct sk_buff *skb);
--
net/nfc/nci/core.c=1343=EXPORT_SYMBOL(nci_unregister_device);
--
net/nfc/nci/core.c-1345-/**
net/nfc/nci/core.c:1346: * nci_recv_frame - receive frame from NCI drivers
net/nfc/nci/core.c-1347- *
--
net/nfc/nci/core.c-1350- */
net/nfc/nci/core.c:1351:int nci_recv_frame(struct nci_dev *ndev, struct sk_buff *skb)
net/nfc/nci/core.c-1352-{
--
net/nfc/nci/core.c-1366-}
net/nfc/nci/core.c:1367:EXPORT_SYMBOL(nci_recv_frame);
net/nfc/nci/core.c-1368-
]
|
| 56/2 |
2026/05/31 14:58 |
llm |
expert |
0m
Model:
Tokens:
input: 47371
output: 66
thoughts: 106
Thoughts: **My Assessment of the NCI Frame Injection Vulnerability**
Okay, here's my understanding of this potential vulnerability: The crux of the matter is the `nci_recv_frame` function. That's *the* gatekeeper, the sole point of entry for injecting an NCI frame. I've traced the callers, and it seems the legitimate sources are limited to hardware drivers and `virtual_ncidev`. There's no other path that's possible. I'm feeling pretty solid about that conclusion.
Now, as for the impact. Let's see... Exploitable? No, I'm marking that as false. This seems geared towards disruption rather than allowing arbitrary code execution. Denial of Service, though? Definitely, True. It has that potential. Unprivileged access? Nope, False. This requires some level of system control. User namespaces? Also, False. And no VMGuest or VMHost triggers, so thatβs False on both. Network trigger? False. Remote? False. The trigger here is firmly rooted in the hardware and devices; it's a PeripheralTrigger, True. Finally, Filesystem? No, False.
|
| 57/2 |
2026/05/31 14:58 |
tool |
set-results |
0m
Args: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
Results: map[DenialOfService:true Exploitable:false FilesystemTrigger:false NetworkTrigger:false PeripheralTrigger:true RemoteTrigger:false Unprivileged:false UserNamespace:false VMGuestTrigger:false VMHostTrigger:false]
|
| 58/2 |
2026/05/31 14:58 |
llm |
expert |
0m
Model:
Tokens:
input: 47850
output: 716
thoughts: 13
Thoughts: Okay, here's the summary, tailored for an expert audience, in the first person:
**Finalizing the Analysis & Response**
Alright, the deep dive is done. The model is trained, the data is sliced, diced, and understood. The nuances, the edge cases, the correlations, all considered. I've wrung the information dry and now I'm ready to craft the final response. It's time to synthesize everything and present a coherent, defensible conclusion. No more iterations on the analytical side; my understanding is firm. Let's make sure I convey this with precision and clarity.
|
| 59/1 |
2026/05/31 14:58 |
action |
format-explanation |
0m
Results: map[Explanation:Based on the analysis of the bug report and the kernel source code, here is the
assessment of the bug:
**Bug Mechanism:**
The bug is an out-of-bounds read in `nci_core_init_rsp_packet_v2()` (and
similarly in `nci_core_init_rsp_packet_v1()`) located in `net/nfc/nci/rsp.c`.
When the kernel receives an `NCI_OP_CORE_INIT_RSP` response from an NFC
controller, it parses the packet without properly validating the length of the
`skb` buffer.
Specifically, the code casts `skb->data` to `struct nci_core_init_rsp_nci_ver2`
and reads `rsp->num_supported_rf_interfaces`. It then iterates over the
variable-length array `supported_rf_interfaces` at the end of the struct,
skipping over `rf_extension_cnt` bytes in each iteration. If a malicious NFC
controller sends a truncated initialization response, the kernel will read past
the end of the initialized data in the `skb` buffer, resulting in an
out-of-bounds read of uninitialized heap memory.
**Impact:**
1. **Denial of Service (DoS):** The `rf_extension_cnt` is read from the
uninitialized memory and can be up to 255. With `num_supported_rf_interfaces` up
to 4, the pointer can advance by over 1000 bytes. If the `skb` data buffer is
located near the end of a memory page, this out-of-bounds read can cross the
page boundary into an unmapped page, triggering a page fault and causing a
kernel panic (Denial of Service).
2. **Exploitability:** The bug is strictly an out-of-bounds read. The read data
is stored in `ndev->supported_rf_interfaces` and later used in a branch
condition in `nci_init_complete_req()`. This could theoretically leak a tiny
amount of information (1 bit per byte) back to the NFC controller, but it does
not corrupt memory or allow control-flow hijacking. Therefore, it is not
exploitable for privilege escalation or arbitrary code execution.
**Trigger Vectors:**
- **Peripheral Trigger:** The NCI frames are received directly from the NFC
hardware controller (e.g., via USB, I2C, SPI). A malicious USB NFC device
plugged into the system can send a malformed `NCI_OP_CORE_INIT_RSP` packet
during the device initialization phase to trigger this bug.
- **Unprivileged Access:** The bug cannot be triggered by an unprivileged user
on a system with a legitimate NFC device, because a legitimate device will not
send malformed responses. The syzkaller report triggered this via
`/dev/virtual_nci`, which is a simulation driver. However, `/dev/virtual_nci` is
created with `0600` permissions and is strictly accessible only to `root` in the
initial namespace. It is not accessible to unprivileged users or within user
namespaces.
**Conclusion:**
This is a Denial of Service vulnerability that can be triggered by a malicious
physical peripheral (e.g., a rogue USB NFC device). It is not reachable by
unprivileged local users or remote attackers, and it is not exploitable for
privilege escalation.]
|