From: Jaegyun Lee <dreams200260@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Neill Kapron <nkapron@google.com>
Cc: Jaegyun Lee <dreams200260@gmail.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: [PATCH 1/2] usb: gadget: f_ncm: drop datagrams larger than the NTB
Date: Sun, 29 Nov 2026 22:36:08 +0900 [thread overview]
Message-ID: <20261129133609.403044-1-dreams200260@gmail.com> (raw)
When no NTB is pending, ncm_wrap_ntb() starts a new one sized by the
NTB input size the host selected, and copies the datagram into it:
unsigned max_size = ncm->port.fixed_in_len;
...
ncm->skb_tx_data = alloc_skb(max_size, GFP_ATOMIC);
...
skb_put_data(ncm->skb_tx_data, skb->data, skb->len);
fixed_in_len comes from SET_NTB_INPUT_SIZE (ncm_ep0out_complete()
accepts 2048..16384). The size check in front of this only runs when
an NTB is already pending, so nothing checks that a datagram fits in an
empty NTB. With an MTU larger than fits in the selected input size, a
large frame is written past the end of the NTB skb and skb_put()
panics in the transmit path.
Reproduced with dummy_hcd and an ncm gadget with
max_segment_size=8000 and MTU 7986, a host that selects rx_max 2048,
and "ping -s 7900" from the gadget side:
[ 47.833862][ C0] skbuff: skb_over_panic: text:ffffffff87d15a83 len:7954 put:7942 head:ffff888047ad2000 data:ffff888047ad2000 tail:0x1f12 end:0xec0 dev:usb0
[ 47.834376][ C0] ------------[ cut here ]------------
[ 47.834380][ C0] kernel BUG at net/core/skbuff.c:215!
[ 47.834392][ C0] Oops: invalid opcode: 0000 [#1] SMP KASAN NOPTI
[ 47.837564][ C0] CPU: 0 UID: 0 PID: 0 Comm: swapper/0 Not tainted 7.4.0-rc3-g666539eecdf4 #1 PREEMPT(full)
[ 47.838571][ C0] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.15.0-1 04/01/2014
[ 47.839478][ C0] RIP: 0010:skb_panic+0x157/0x1d0
[ 47.839995][ C0] Code: b6 04 01 84 c0 74 04 3c 03 7e 21 41 56 8b 4b 70 45 89 e8 48 c7 c7 e0 0f 43 8d 41 57 56 48 89 ee 52 4c 89 e2 e8 8a e5 07 f8 90 <0f> 0b 4c 89 4c 24 10 48 89 54 24 08 48 89 34 24 e8 74 f5 a1 f8 4c
[ 47.841907][ C0] RSP: 0018:ffffc90000007390 EFLAGS: 00010082
[ 47.842510][ C0] RAX: 000000000000008a RBX: ffff888052e77000 RCX: 0000000000000303
[ 47.843297][ C0] RDX: 0000000000000000 RSI: ffffffff81a10b90 RDI: 0000000000000005
[ 47.844083][ C0] RBP: ffffffff8d433400 R08: ffffffff81a092f1 R09: 0000000000000000
[ 47.844869][ C0] R10: ffffc90000007167 R11: 0000000000000000 R12: ffffffff87d15a83
[ 47.845651][ C0] R13: 0000000000001f06 R14: ffff888027258120 R15: 0000000000000ec0
[ 47.846434][ C0] FS: 0000000000000000(0000) GS:ffff888095a93000(0000) knlGS:0000000000000000
[ 47.847322][ C0] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[ 47.847977][ C0] CR2: 00007ffd7a70ffb8 CR3: 0000000052c93000 CR4: 0000000000350ef0
[ 47.848770][ C0] Call Trace:
[ 47.849099][ C0] <IRQ>
[ 47.849387][ C0] ? ncm_wrap_ntb+0x5d3/0x11a0
[ 47.849873][ C0] skb_put+0x174/0x1b0
[ 47.850288][ C0] ncm_wrap_ntb+0x5d3/0x11a0
[ 47.850758][ C0] eth_start_xmit+0x3ac/0x1390
[ 47.851245][ C0] dev_hard_start_xmit+0x17f/0x790
[ 47.851763][ C0] sch_direct_xmit+0x1c6/0xe60
[ 47.852245][ C0] ? __pfx_sch_direct_xmit+0x10/0x10
[ 47.852801][ C0] ? lock_acquire+0x1bf/0x370
[ 47.853269][ C0] ? do_raw_spin_lock+0x12b/0x270
[ 47.853785][ C0] ? __pfx_do_raw_spin_lock+0x10/0x10
[ 47.854323][ C0] __dev_queue_xmit+0x3685/0x41d0
[ 47.854833][ C0] ? irqentry_exit+0x407/0xb40
[ 47.855319][ C0] ? __pfx___dev_queue_xmit+0x10/0x10
[ 47.855861][ C0] ? __lock_acquire+0x509/0x2110
[ 47.856364][ C0] ? lock_acquire+0x1bf/0x370
[ 47.856838][ C0] ? find_held_lock+0x2b/0x80
[ 47.857312][ C0] ? __asan_memcpy+0x3d/0x60
[ 47.857791][ C0] ? eth_header+0x11d/0x200
[ 47.858247][ C0] neigh_resolve_output+0x51e/0x8f0
[ 47.858776][ C0] __neigh_update+0x9cd/0x2b50
[ 47.859259][ C0] arp_process+0x96d/0x2540
[ 47.859731][ C0] ? nf_hook.constprop.0+0x453/0x720
[ 47.860265][ C0] ? __pfx_arp_process+0x10/0x10
[ 47.860771][ C0] ? __pfx_nf_hook.constprop.0+0x10/0x10
[ 47.861337][ C0] ? arch_stack_walk+0x86/0xf0
[ 47.861823][ C0] ? __lock_acquire+0x509/0x2110
[ 47.862329][ C0] arp_rcv+0x3c6/0x510
[ 47.862697][ C0] ? __pfx_arp_rcv+0x10/0x10
[ 47.863115][ C0] __netif_receive_skb_one_core+0x1b4/0x1e0
[ 47.863632][ C0] ? __pfx___netif_receive_skb_one_core+0x10/0x10
[ 47.864211][ C0] ? process_backlog+0x330/0x1540
[ 47.864657][ C0] ? process_backlog+0x330/0x1540
[ 47.865112][ C0] __netif_receive_skb+0x1d/0x160
[ 47.865557][ C0] process_backlog+0x382/0x1540
[ 47.865994][ C0] __napi_poll.constprop.0+0xb3/0x540
[ 47.866468][ C0] net_rx_action+0x9b1/0xea0
[ 47.866884][ C0] ? __pfx_net_rx_action+0x10/0x10
[ 47.867336][ C0] ? napi_skb_cache_put+0x31f/0x760
[ 47.867801][ C0] ? __pfx_xfrm_dev_backlog+0x10/0x10
[ 47.868275][ C0] ? napi_skb_cache_put+0x324/0x760
[ 47.868742][ C0] ? net_tx_action+0x83f/0xf30
[ 47.869167][ C0] handle_softirqs+0x20e/0x9e0
[ 47.869592][ C0] __irq_exit_rcu+0x184/0x240
[ 47.870022][ C0] irq_exit_rcu+0x9/0x30
[ 47.870403][ C0] sysvec_apic_timer_interrupt+0xa8/0xc0
[ 47.870907][ C0] </IRQ>
[ 47.871167][ C0] <TASK>
[ 47.871427][ C0] asm_sysvec_apic_timer_interrupt+0x1a/0x20
[ 47.871958][ C0] RIP: 0010:pv_native_safe_halt+0x1e/0x30
[ 47.872465][ C0] Code: 90 90 90 90 90 90 90 90 90 90 90 90 f3 0f 1e fa 0f 1f 44 00 00 eb 0c 0f 1f 44 00 00 0f 00 2d 29 f8 15 00 0f 1f 44 00 00 fb f4 <c3> cc cc cc cc 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 90 90 90 90
[ 47.874144][ C0] RSP: 0018:ffffffff8fa07ce8 EFLAGS: 00000206
[ 47.874676][ C0] RAX: 00000000000b725f RBX: ffffffff8fa91740 RCX: ffffffff8bd63249
[ 47.875366][ C0] RDX: 0000000000000000 RSI: 0000000000000001 RDI: 0000000000000000
[ 47.876065][ C0] RBP: fffffbfff1f522e8 R08: 0000000000000001 R09: ffffed1005686825
[ 47.876762][ C0] R10: ffff88802b43412b R11: 0000000000000001 R12: dffffc0000000000
[ 47.877448][ C0] R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000013bd0
[ 47.878142][ C0] ? ct_kernel_exit+0x1d9/0x240
[ 47.878572][ C0] default_idle+0xe/0x20
[ 47.878954][ C0] default_idle_call+0x6c/0xb0
[ 47.879377][ C0] do_idle+0x3c1/0x5c0
[ 47.879747][ C0] ? __pfx___schedule+0x10/0x10
[ 47.880182][ C0] ? __pfx_do_idle+0x10/0x10
[ 47.880592][ C0] cpu_startup_entry+0x4f/0x60
[ 47.881023][ C0] rest_init+0x1ee/0x330
[ 47.881400][ C0] ? __pfx_rest_init+0x10/0x10
[ 47.881837][ C0] ? acpi_ut_value_exit+0xff/0x180
[ 47.882293][ C0] ? __pfx_kernel_init+0x10/0x10
[ 47.882738][ C0] ? acpi_ut_status_exit+0x103/0x1c0
[ 47.883205][ C0] ? acpi_enable_subsystem+0x370/0x5b0
[ 47.883687][ C0] ? regulator_has_full_constraints+0x9/0x20
[ 47.884227][ C0] ? __pfx_x86_late_time_init+0x10/0x10
[ 47.884724][ C0] start_kernel+0x3f4/0x4d0
[ 47.885130][ C0] x86_64_start_reservations+0x18/0x30
[ 47.885614][ C0] x86_64_start_kernel+0x13c/0x1a0
[ 47.886074][ C0] common_startup_64+0x13e/0x158
[ 47.886515][ C0] </TASK>
[ 47.886790][ C0] Modules linked in:
[ 47.887137][ C0] ---[ end trace 0000000000000000 ]---
Drop a datagram that does not fit in an empty NTB and count it in
tx_dropped.
Fixes: 6d3865f9d41f ("usb: gadget: NCM: Add transmit multi-frame.")
Cc: stable@vger.kernel.org
Assisted-by: ZCode:GLM-5.4
Signed-off-by: Jaegyun Lee <dreams200260@gmail.com>
---
drivers/usb/gadget/function/f_ncm.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -1034,6 +1034,14 @@ static struct sk_buff *ncm_wrap_ntb(stru
put_unaligned_le32(crc, crc_pos);
}
+ if (ALIGN(ALIGN(opts->nth_size, div) + rem + skb->len,
+ ndp_align) + opts->ndp_size + 2 * dgram_idx_len >
+ max_size) {
+ skb->dev->stats.tx_dropped++;
+ dev_kfree_skb_any(skb);
+ return NULL;
+ }
+
/* If the new skb is too big for the current NCM NTB then
* set the current stored skb to be sent now and clear it
* ready for new data.
next reply other threads:[~2026-11-29 13:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 13:36 Jaegyun Lee [this message]
2026-11-29 13:36 ` [PATCH 2/2] usb: gadget: f_ncm: check pending NTB tailroom before appending Jaegyun Lee
2026-11-29 13:43 ` [PATCH 1/2] usb: gadget: f_ncm: drop datagrams larger than the NTB sashiko-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129133609.403044-1-dreams200260@gmail.com \
--to=dreams200260@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox