🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #2697

Re: [PATCH net-next v2 7/7] net: mctp: usblib: Add test for failing append

#2697
From: James Lee
Date: Tue, 13 Oct 2026 09:06
142 lines
10767 bytes
> [Severity: Low]
> This isn't a bug, but len = 200 and the loop count of 3 below
> silently
> encode a dependency on MCTP_USB_1_0_XFER_SIZE (512) and MCTP_USB_BTU,
> without referencing either constant.
> 
> I traced the intended path and it does run today with span=false:
> each skb
> becomes 204 bytes after mctp_usblib_tx_skb_prepare() pushes the 4-
> byte
> header, push 1 creates the 512-byte ctx, push 2 appends (len 408,
> avail
> 104), and push 3 hits mctp_usblib_tx_append():
> 
> 	if (mctp_usblib_tx_avail(ctx) < skb->len)
> 		return -ENOBUFS;
> 
> with avail 104 < skb->len 204.
> 
> Could len and the iteration count be derived from
> MCTP_USB_1_0_XFER_SIZE / MCTP_USB_BTU instead, so the case keeps
> hitting
> the append-failure branch if those change?
> 
> Also, would tx_overflow be better named after the append failure the
> commit subject describes?
> 
Valid catch, will rename and remove the magic constants.

> 
> [Severity: High]
> Can this sleep with preemption disabled?  get_cpu_ptr() expands to
> preempt_disable() plus this_cpu_ptr(), so the whole loop runs in
> atomic
> context, and mctp_usblib_test_init_skb() allocates with GFP_KERNEL:
> 
> drivers/net/mctp/mctp-usblib-test.c:mctp_usblib_test_init_skb() {
> 	skb = __netdev_alloc_skb(ndev, length, GFP_KERNEL);
> 	KUNIT_ASSERT_NOT_NULL(test, skb);
> 	...
> }
> 
> GFP_KERNEL sets __GFP_DIRECT_RECLAIM, so __netdev_alloc_skb() takes
> the
> blocking slab path:
> 
> net/core/skbuff.c:__netdev_alloc_skb() {
> 	if (len <= SKB_WITH_OVERHEAD(SKB_SMALL_HEAD_CACHE_SIZE) ||
> 	    len > SKB_WITH_OVERHEAD(PAGE_SIZE) ||
> 	    (gfp_mask & (__GFP_DIRECT_RECLAIM | GFP_DMA))) {
> 		skb = __alloc_skb(len, gfp_mask, SKB_ALLOC_RX,
> NUMA_NO_NODE);
> 	...
> }
> 
> With CONFIG_DEBUG_ATOMIC_SLEEP, wouldn't the might_sleep() in the
> allocator produce a "sleeping function called from invalid context"
> splat
> every time this case runs?
> 
> Two further consequences of the same region:
> 
> The KUNIT_ASSERT_NOT_NULL() in mctp_usblib_test_init_skb() and the
> KUnit
> failure reporting behind KUNIT_EXPECT_EQ() also allocate with
> GFP_KERNEL,
> and the assert variant does not return:
> 
> lib/kunit/try-catch.c:kunit_try_catch_throw() {
> 	try_catch->try_result = -EFAULT;
> 	kthread_exit(0);
> }
> 
> so put_cpu_ptr() below is skipped and the thread exits still in
> atomic
> context, which kernel/exit.c reports:
> 
> kernel/exit.c:do_exit() {
> 	if (unlikely(in_atomic())) {
> 		pr_info("note: %s[%d] exited with preempt_count
> %d\n",
> 			current->comm, task_pid_nr(current),
> 			preempt_count());
> 		preempt_count_set(PREEMPT_ENABLED);
> 	}
> 	...
> }
> 
> mctp_usblib_tx_push() also takes a spinlock_t here:
> 
> drivers/net/mctp/mctp-usblib.c:mctp_usblib_tx_push() {
> 	spin_lock_irqsave(&tx->lock, flags);
> 	...
> }
> 
> On PREEMPT_RT that is a sleeping lock, so is acquiring it from an
> explicitly preempt-disabled section valid?
> 
> Note the driver itself uses GFP_ATOMIC on this path
> (mctp_usblib_tx_ctx_create() uses kzalloc_flex(..., GFP_ATOMIC)), so
> only
> the test's own allocation is out of context.
> 
> Since mctp_usblib_tx_stats_update() picks the counter with
> get_cpu_ptr(dev->dstats), could the skb allocation and the assertions
> move
> outside the pinned region, leaving only the counter read inside
> get_cpu_ptr()/put_cpu_ptr(), or could tx_drops be summed over
> for_each_possible_cpu() instead?
Good catch, will correct.

> [Severity: Low]
> This is the same finding as the len = 200 comment above: this
> aggregate
> drop count is the only oracle in the case.
> 
> The append-failure path yields 2 drops from the detached two-skb
> context
> plus 1 from the single-skb context, but so do other paths: if the ctx
> buffer size grew, if the MCTP_USB_BTU margin in
> mctp_usblib_tx_should_send() changed so the ctx flushed after push 2,
> or
> if all three skbs fit one ctx, the append branch never runs and stats
> is
> still 3.
> 
> Neither the number of ops.send() invocations, nor tx->cur_ctx, nor
> ctx->tx_xfers is checked here, while the neighbouring
> mctp_usblib_test_tx_failing_send() does:
> 
> 	KUNIT_EXPECT_EQ(test, rc, 0);
> 	KUNIT_EXPECT_NULL(test, tx->cur_ctx);
> 	KUNIT_EXPECT_TRUE(test, list_empty(&ctx->tx_xfers));
> 
> Would checking tx_drops == 0 after the first two pushes and counting
> the
> send attempts (2 sends carrying 2 and 1 packets) pin down the branch
> under
> test?
Fair point, will begin checking for expected behaviour between sends as
well.
Technical Details
Message-ID: <09f81599d3272e23fb4cffbbff669021d9c9b204.camel@codeconstruct.com.au>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345488-linux-kernel-netdev=dewy.ru
References: <20260903-dev-mctp-usb-lib-test-v2-7-313cf15e0b56@codeconstruct.com.au> <178893260523.219967.7691706807394215121@kernel.org>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-345488-linux-kernel-netdev=dewy.ru
From: james@codeconstruct.com.au (James Lee)
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net-next v2 7/7] net: mctp: usblib: Add test for failing
 append
Date: Tue, 13 Oct 2026 17:06:06 +0800
Organization: Usenet Network
Message-ID: <09f81599d3272e23fb4cffbbff669021d9c9b204.camel@codeconstruct.com.au>
References: <20260903-dev-mctp-usb-lib-test-v2-7-313cf15e0b56@codeconstruct.com.au>
	 <178893260523.219967.7691706807394215121@kernel.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
	logging-data="2009053"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:1+LZqsjn6TlI1dBQwbjK8GZz2ho= sha256:iwjE7kS2bVKA00RCzg/3w8Gk3xk2H/YmNXjeM3rnzsc=
	sha1:nT4hig5Zeu3zqmVb5HqpHa9zk0c= sha256:KHDADJuVvfoWqEXyc4tgVcaLGoFsfOvwKYWADcRlNMw=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9722610FDCE; Tue, 13 Oct 2026 12:11:48 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -0.751
X-Spam-Status: No, score=-0.751 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001]
	autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=codeconstruct.com.au
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id qJS8LKdWyolo;
	Tue, 13 Oct 2026 12:11:45 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-345488-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=codeconstruct.com.au
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id 5F45510FD78; Tue, 13 Oct 2026 12:11:36 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1])
	by tor.lore.kernel.org (Postfix) with ESMTP id 0435822F5E; Tue, 13 Oct 2026 09:06:14 +0000 (UTC)
X-Received: from localhost.localdomain (localhost.localdomain [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id ECFEE3BADB2;
	Tue, 13 Oct 2026 09:06:12 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=codeconstruct.com.au header.i=@codeconstruct.com.au header.b="f3oR+A+z"
X-Received: from codeconstruct.com.au (pi.codeconstruct.com.au [203.29.241.158])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D46522EEE60;
	Tue, 13 Oct 2026 09:06:10 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.29.241.158
X-ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;
	t=1791882372; cv=none; b=gfnPM7hK1Pek609Vhs462XfW7kFhtUbOSd2W5Xb1RTM/S4o4Cqj7ONcgxoiozKrlhRe6oKzk2NJrurV4CavR2EDX6UIeZAwXs8hoQ4AjIXJwquPWXn6tYDfyd21utwRcwzBl/ZVNqvXVHseSEvOqI+BsQgdo4+2I2+KPwO8L7AQ=
X-ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org;
	s=arc-20240116; t=1791882372; c=relaxed/simple;
	bh=f3YbRRpgLvGIDJhlgxW1hH5ooXnf+mjazscQxi2bxXs=;
	h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References:
	 Content-Type:MIME-Version; b=BJrvMtVssCWfUuMpBFobCu+a1IeSPkeeEwbo8Zh27u35IGngqC/P6HJIkzcWCBfyRq2UOtWk04Xw6hdJLLyZXfS9Ql3/Vg8EU/i/L3DaQjH7aSlvNnIerE0l433hOS4U3oDK4OmKLSZy5FeqLj0vx6ZSG0uLkUTx7I62pVsv3zk=
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeconstruct.com.au; spf=pass smtp.mailfrom=codeconstruct.com.au; dkim=pass (2048-bit key) header.d=codeconstruct.com.au header.i=@codeconstruct.com.au header.b=f3oR+A+z; arc=none smtp.client-ip=203.29.241.158
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=codeconstruct.com.au
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=codeconstruct.com.au
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
	d=codeconstruct.com.au; s=2022a; t=1791882368;
	bh=r8qCmCeihUM0ETfYMNS7MCtzzdS2TGMfG+CaacKLVOc=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=f3oR+A+zo3fu9nRTCehlMftKh6WUfYtiigQLng4cuZSoJFyjUKlbg+TmoKGpu12N9
	 n+LZR2GyVT6R06Tq8/XgmlqkGtR7At9Nj9A2Qqf6e9KLEDKCyWySE+GHXzxCrayVZM
	 08+l+xt/ATPvU7OLUglxK15t8Ah1mYSy3kYUrj4SWjKgX8rCDZdKs2rMAEVgy6yrWm
	 J+tyx8ycZTbdwHl5Mo7kEiLTbFMuY31+MDj6wNVKJ2qFxdHlR4GKCZ1deQMbOVViFm
	 cD7jCS7pvC7kJ8w3hEjWGfRCHRkOId8y98mgoVuvl0o3g8N0L69vdVB9CODfRbewWc
	 ji9dUCj0sw7OA==
X-Received: from [192.168.72.170] (210-10-213-150.per.static-ipl.aapt.com.au [210.10.213.150])
	by mail.codeconstruct.com.au (Postfix) with ESMTPSA id 02AE06FB39;
	Tue, 13 Oct 2026 17:06:06 +0800 (AWST)
X-Cc: jk@codeconstruct.com.au, matt@codeconstruct.com.au,
 andrew+netdev@lunn.ch, 	davem@davemloft.net, edumazet@google.com,
 kuba@kernel.org, pabeni@redhat.com, 	kees@kernel.org,
 gustavoars@kernel.org, netdev@vger.kernel.org, 
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
X-In-Reply-To: <178893260523.219967.7691706807394215121@kernel.org>
X-User-Agent: Evolution 3.56.2-0+deb13u1 
X-Precedence: bulk
X-Mailing-List: netdev@vger.kernel.org
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>