From: James Lee <james@codeconstruct.com.au>
To: Jeremy Kerr <jk@codeconstruct.com.au>,
Matt Johnston <matt@codeconstruct.com.au>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org,
James Lee <james@codeconstruct.com.au>
Subject: [PATCH 2/7] net: mctp: usblib: Add test for splits inside headers
Date: Mon, 31 Aug 2026 11:43:41 +0800 [thread overview]
Message-ID: <20260831-dev-mctp-usb-lib-test-v1-2-79699bf67a18@codeconstruct.com.au> (raw)
In-Reply-To: <20260831-dev-mctp-usb-lib-test-v1-0-79699bf67a18@codeconstruct.com.au>
Add test covering every possible split of a packet's headers between
transfers and remove parameterized tests that are now covered.
Signed-off-by: James Lee <james@codeconstruct.com.au>
---
drivers/net/mctp/mctp-usblib-test.c | 69 +++++++++++++++++++++++++++++++++----
1 file changed, 63 insertions(+), 6 deletions(-)
diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c
index 4c27307900fb6116572bc9d89f3def6f06c30397..1a6dd6d10daab314f5e082477ecd3b9518f6b50e 100644
--- a/drivers/net/mctp/mctp-usblib-test.c
+++ b/drivers/net/mctp/mctp-usblib-test.c
@@ -14,6 +14,8 @@
#include <net/mctpdevice.h>
#include <linux/usb/mctp-usb.h>
+#define HDR_LEN sizeof(struct mctp_usb_hdr)
+
struct mctp_usblib_test_dev {
struct net_device *ndev;
struct mctp_dev *mdev;
@@ -378,12 +380,6 @@ static const struct mctp_usblib_test_pkt_span mctp_usblib_test_pkt_spans[] = {
{ "1p1x-complete", 1, { 8 }, 1, { 8 } },
/* Two small packets combined within one transfer */
{ "2p1x-combined", 2, { 8, 8 }, 1, { 16 } },
- /* A packet split over two transfers, at the MCTP payload */
- { "1p2x-split-payload", 1, { 16 }, 2, { 8, 8 } },
- /* A packet split over two transfers, at the USB transport header */
- { "1p2x-split-usbhdr", 1, { 16 }, 2, { 2, 14 } },
- /* A packet split over two transfers, at the MCTP header */
- { "1p2x-split-mctphdr", 1, { 16 }, 2, { 6, 10 } },
/* Single packet split over 3 transfers, middle entirely continuation */
{ "1p3x-split", 1, { 12 }, 3, { 4, 4, 4 } },
/* A packet split over 5 transfers, splitting on and between each header. */
@@ -403,10 +399,71 @@ static const struct mctp_usblib_test_pkt_span mctp_usblib_test_pkt_spans[] = {
KUNIT_ARRAY_PARAM(mctp_usblib_test_rx_pkt_span, mctp_usblib_test_pkt_spans,
mctp_usblib_test_pkt_span_to_desc);
+static void mctp_usblib_test_rx_split_header(struct kunit *test, size_t offset,
+ struct mctp_usblib_test_dev *dev,
+ struct mctp_usblib_rx *rx)
+{
+ struct sk_buff *skb;
+ size_t buflen, len;
+ u8 packet[16];
+ void *buf;
+ int rc;
+
+ len = sizeof(packet);
+ mctp_usblib_test_init_pkt(packet, len, len);
+
+ rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen, GFP_KERNEL);
+ KUNIT_ASSERT_EQ(test, rc, 0);
+ KUNIT_ASSERT_GE(test, buflen, len);
+
+ memcpy(buf, packet, offset);
+ mctp_usblib_rx_complete(dev->ndev, rx, offset);
+
+ rc = mctp_usblib_rx_prepare(dev->ndev, rx, &buf, &buflen,
+ GFP_KERNEL);
+ KUNIT_ASSERT_EQ(test, rc, 0);
+ KUNIT_ASSERT_GE(test, buflen, len);
+ KUNIT_ASSERT_EQ(test, dev->rx_pkts.qlen, 0);
+
+ memcpy(buf, packet + offset, len - offset);
+ mctp_usblib_rx_complete(dev->ndev, rx, len - offset);
+ KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 1);
+
+ skb = __skb_dequeue(&dev->rx_pkts);
+ KUNIT_EXPECT_NOT_NULL(test, skb);
+ if (skb)
+ KUNIT_EXPECT_EQ(test, skb->len, len - HDR_LEN);
+}
+
+static void mctp_usblib_test_rx_header_splits(struct kunit *test)
+{
+ struct mctp_usblib_test_dev *dev;
+ struct mctp_usblib_test_ctx *ctx;
+ struct mctp_usblib_rx *rx;
+ size_t i;
+
+ ctx = mctp_usblib_test_init(test);
+ rx = mctp_usblib_test_rx_init(test, true);
+ dev = ctx->dev;
+
+ /* Unrolling here so stack traces point to the invocation with the
+ * failing length.
+ */
+ mctp_usblib_test_rx_split_header(test, 1, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 2, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 3, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 4, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 5, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 6, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 7, dev, rx);
+ mctp_usblib_test_rx_split_header(test, 8, dev, rx);
+}
+
static struct kunit_case mctp_usblib_test_cases[] = {
KUNIT_CASE(mctp_usblib_test_rx_single),
KUNIT_CASE_PARAM(mctp_usblib_test_rx_pkt_span,
mctp_usblib_test_rx_pkt_span_gen_params),
+ KUNIT_CASE(mctp_usblib_test_rx_header_splits),
{}
};
--
2.47.3
next prev parent reply other threads:[~2026-08-31 3:50 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 3:43 [PATCH 0/7] net: mctp: usblib: Increase coverage of kunit testing James Lee
2026-08-31 3:43 ` [PATCH 1/7] net: mctp: usblib: Add to parameterized kunit tests James Lee
2026-08-31 3:43 ` James Lee [this message]
2026-09-03 21:46 ` [2/7] net: mctp: usblib: Add test for splits inside headers netdev-bot+sashiko
2026-08-31 3:43 ` [PATCH 3/7] net: mctp: usblib: Add tests of invalid headers James Lee
2026-09-03 21:46 ` [3/7] " netdev-bot+sashiko
2026-08-31 3:43 ` [PATCH 4/7] net: mctp: usblib: Complete rx tests James Lee
2026-08-31 3:43 ` [PATCH 5/7] net: mctp: usblib: Simplify allocation logic in mctp_usblib_test_rx_init James Lee
2026-08-31 3:43 ` [PATCH 6/7] net: mctp: usblib: Add initial kunit tx tests James Lee
2026-09-03 21:46 ` [6/7] " netdev-bot+sashiko
2026-08-31 3:43 ` [PATCH 7/7] net: mctp: usblib: Add test for failing append James Lee
2026-09-03 21:46 ` [7/7] " netdev-bot+sashiko
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=20260831-dev-mctp-usb-lib-test-v1-2-79699bf67a18@codeconstruct.com.au \
--to=james@codeconstruct.com.au \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gustavoars@kernel.org \
--cc=jk@codeconstruct.com.au \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matt@codeconstruct.com.au \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.