mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Griffin Kroah-Hartman <griffin@kroah.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Griffin Kroah-Hartman <griffin@kroah.com>
Subject: [PATCH 2/2] usb: gadget: function: rndis: add length check for header
Date: Wed, 08 Jul 2026 13:08:59 +0200	[thread overview]
Message-ID: <20260708-usb-gadget-rndis-v1-2-e77e026dcc6a@kroah.com> (raw)
In-Reply-To: <20260708-usb-gadget-rndis-v1-0-e77e026dcc6a@kroah.com>

Add a length check for the rndis header in rndis_rm_hdr, to ensure that
MessageType, MessageLength, DataOffset, and DataLength fields are
present before they are accessed.

Assisted-by: gkh_clanker_2000
Signed-off-by: Griffin Kroah-Hartman <griffin@kroah.com>
---
 drivers/usb/gadget/function/rndis.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c
index fe2018ff071a..a2fd239b7ad3 100644
--- a/drivers/usb/gadget/function/rndis.c
+++ b/drivers/usb/gadget/function/rndis.c
@@ -1080,6 +1080,12 @@ int rndis_rm_hdr(struct gether *port,
 	/* tmp points to a struct rndis_packet_msg_type */
 	__le32 *tmp = (void *)skb->data;
 
+	/* Need at least MessageType, MessageLength, DataOffset, DataLength */
+	if (skb->len < 16) {
+		dev_kfree_skb_any(skb);
+		return -EINVAL;
+	}
+
 	/* MessageType, MessageLength */
 	if (cpu_to_le32(RNDIS_MSG_PACKET)
 			!= get_unaligned(tmp++)) {

-- 
2.55.0


      parent reply	other threads:[~2026-07-08 11:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08 11:08 [PATCH 0/2] Error checking in rndis Griffin Kroah-Hartman
2026-07-08 11:08 ` [PATCH 1/2] usb: gadget: function: rndis: add length check to response query Griffin Kroah-Hartman
2026-07-08 16:24   ` Oliver Neukum
2026-07-09  5:34     ` Greg Kroah-Hartman
2026-07-08 11:08 ` Griffin Kroah-Hartman [this message]

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=20260708-usb-gadget-rndis-v1-2-e77e026dcc6a@kroah.com \
    --to=griffin@kroah.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@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

all inboxes | Powered by JetHome®