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 net-next v3 3/7] net: mctp: usblib: Add tests of invalid headers
Date: Wed, 14 Oct 2026 12:47:33 +0800 [thread overview]
Message-ID: <20261014-dev-mctp-usb-lib-test-v3-3-ee5bc3ea1db1@codeconstruct.com.au> (raw)
In-Reply-To: <20261014-dev-mctp-usb-lib-test-v3-0-ee5bc3ea1db1@codeconstruct.com.au>
Add tests where the length field of the USB transport header is below
the minimum value, and where the DMTF ID is invalid.
Signed-off-by: James Lee <james@codeconstruct.com.au>
---
v3:
- Replace C99 comment with block comment
---
drivers/net/mctp/mctp-usblib-test.c | 68 +++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/drivers/net/mctp/mctp-usblib-test.c b/drivers/net/mctp/mctp-usblib-test.c
index 2d91cba9efeea55e15b2d13a0debd4586072b83c..44389c0451c1c915c282bbe3881efac772d9c4e1 100644
--- a/drivers/net/mctp/mctp-usblib-test.c
+++ b/drivers/net/mctp/mctp-usblib-test.c
@@ -461,11 +461,79 @@ static void mctp_usblib_test_rx_header_splits(struct kunit *test)
mctp_usblib_test_rx_split_header(test, 8, dev, rx);
}
+/* Test the submission of a packet with an impossibly small value in the
+ * header's length field. Values less than HDR_LEN are invalid.
+ */
+static void mctp_usblib_test_rx_short_packet(struct kunit *test)
+{
+ struct mctp_usblib_test_dev *dev;
+ struct mctp_usblib_test_ctx *ctx;
+ struct mctp_usblib_rx *rx;
+ size_t len, buflen;
+ u8 pktbuf[12];
+ void *buf;
+ int rc;
+
+ ctx = mctp_usblib_test_init(test);
+ rx = mctp_usblib_test_rx_init(test, true);
+ dev = ctx->dev;
+
+ len = sizeof(pktbuf);
+ mctp_usblib_test_init_pkt(pktbuf, len, HDR_LEN - 1);
+
+ buflen = 0;
+ 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, pktbuf, len);
+
+ rc = mctp_usblib_rx_complete(dev->ndev, rx, len);
+ KUNIT_EXPECT_EQ(test, rc, -EPROTO);
+ KUNIT_EXPECT_NULL(test, rx->skb);
+ KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0);
+}
+
+static void mctp_usblib_test_rx_invalid_dmtf_id(struct kunit *test)
+{
+ struct mctp_usblib_test_dev *dev;
+ struct mctp_usblib_test_ctx *ctx;
+ struct mctp_usblib_rx *rx;
+ size_t len, buflen;
+ u8 pktbuf[12];
+ void *buf;
+ int rc;
+
+ ctx = mctp_usblib_test_init(test);
+ rx = mctp_usblib_test_rx_init(test, true);
+ dev = ctx->dev;
+
+ len = sizeof(pktbuf);
+ mctp_usblib_test_init_pkt(pktbuf, len, len);
+
+ /* Make packet DMTF ID invalid */
+ pktbuf[1] = ~pktbuf[1];
+
+ buflen = 0;
+ 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, pktbuf, len);
+
+ rc = mctp_usblib_rx_complete(dev->ndev, rx, len);
+ KUNIT_EXPECT_EQ(test, rc, -EPROTO);
+ KUNIT_EXPECT_NULL(test, rx->skb);
+ KUNIT_EXPECT_EQ(test, dev->rx_pkts.qlen, 0);
+}
+
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),
+ KUNIT_CASE(mctp_usblib_test_rx_short_packet),
+ KUNIT_CASE(mctp_usblib_test_rx_invalid_dmtf_id),
{}
};
--
2.47.3
next prev parent reply other threads:[~2026-10-14 4:47 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-14 4:47 [PATCH net-next v3 0/7] net: mctp: usblib: Increase coverage of kunit testing James Lee
2026-10-14 4:47 ` [PATCH net-next v3 1/7] net: mctp: usblib: Add to parameterized kunit tests James Lee
2026-10-14 4:47 ` [PATCH net-next v3 2/7] net: mctp: usblib: Add test for splits inside headers James Lee
2026-10-14 4:47 ` James Lee [this message]
2026-10-14 4:47 ` [PATCH net-next v3 4/7] net: mctp: usblib: Complete rx tests James Lee
2026-10-14 4:47 ` [PATCH net-next v3 5/7] net: mctp: usblib: Simplify allocation logic in mctp_usblib_test_rx_init James Lee
2026-10-14 4:47 ` [PATCH net-next v3 6/7] net: mctp: usblib: Add initial kunit tx tests James Lee
2026-10-14 4:47 ` [PATCH net-next v3 7/7] net: mctp: usblib: Add test for failing append James Lee
2026-10-20 21:30 ` [PATCH net-next v3 0/7] net: mctp: usblib: Increase coverage of kunit testing patchwork-bot+netdevbpf
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=20261014-dev-mctp-usb-lib-test-v3-3-ee5bc3ea1db1@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.