* [PATCH 0/2] Error checking in rndis
@ 2026-07-08 11:08 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 11:08 ` [PATCH 2/2] usb: gadget: function: rndis: add length check for header Griffin Kroah-Hartman
0 siblings, 2 replies; 5+ messages in thread
From: Griffin Kroah-Hartman @ 2026-07-08 11:08 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Griffin Kroah-Hartman
Small patch series for two changes in
drivers/usb/gadget/function/rndis.c, both related to error checking.
Signed-off-by: Griffin Kroah-Hartman <griffin@kroah.com>
---
Griffin Kroah-Hartman (2):
usb: gadget: function: rndis: add length check to response query
usb: gadget: function: rndis: add length check for header
drivers/usb/gadget/function/rndis.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
---
base-commit: 8cdeaa50eae8dad34885515f62559ee83e7e8dda
change-id: 20260708-usb-gadget-rndis-b80cbb3b4572
Best regards,
--
Griffin Kroah-Hartman <griffin@kroah.com>
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH 1/2] usb: gadget: function: rndis: add length check to response query 2026-07-08 11:08 [PATCH 0/2] Error checking in rndis Griffin Kroah-Hartman @ 2026-07-08 11:08 ` Griffin Kroah-Hartman 2026-07-08 16:24 ` Oliver Neukum 2026-07-08 11:08 ` [PATCH 2/2] usb: gadget: function: rndis: add length check for header Griffin Kroah-Hartman 1 sibling, 1 reply; 5+ messages in thread From: Griffin Kroah-Hartman @ 2026-07-08 11:08 UTC (permalink / raw) To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Griffin Kroah-Hartman Add variable representations for BufLength and BufOffset in rndis_query_response(), and perform a length check on them. This is identical to how rndis_set_response() handles these parameters. Assisted-by: gkh_clanker_2000 Signed-off-by: Griffin Kroah-Hartman <griffin@kroah.com> --- drivers/usb/gadget/function/rndis.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/function/rndis.c b/drivers/usb/gadget/function/rndis.c index 3da54a7d7aba..fe2018ff071a 100644 --- a/drivers/usb/gadget/function/rndis.c +++ b/drivers/usb/gadget/function/rndis.c @@ -591,6 +591,7 @@ static int rndis_init_response(struct rndis_params *params, static int rndis_query_response(struct rndis_params *params, rndis_query_msg_type *buf) { + u32 BufLength, BufOffset; rndis_query_cmplt_type *resp; rndis_resp_t *r; @@ -598,6 +599,13 @@ static int rndis_query_response(struct rndis_params *params, if (!params->dev) return -ENOTSUPP; + BufLength = le32_to_cpu(buf->InformationBufferLength); + BufOffset = le32_to_cpu(buf->InformationBufferOffset); + if ((BufLength > RNDIS_MAX_TOTAL_SIZE) || + (BufOffset > RNDIS_MAX_TOTAL_SIZE) || + (BufOffset + 8 >= RNDIS_MAX_TOTAL_SIZE)) + return -EINVAL; + /* * we need more memory: * gen_ndis_query_resp expects enough space for @@ -614,10 +622,8 @@ static int rndis_query_response(struct rndis_params *params, resp->RequestID = buf->RequestID; /* Still LE in msg buffer */ if (gen_ndis_query_resp(params, le32_to_cpu(buf->OID), - le32_to_cpu(buf->InformationBufferOffset) - + 8 + (u8 *)buf, - le32_to_cpu(buf->InformationBufferLength), - r)) { + BufOffset + 8 + (u8 *)buf, + BufLength, r)) { /* OID not supported */ resp->Status = cpu_to_le32(RNDIS_STATUS_NOT_SUPPORTED); resp->MessageLength = cpu_to_le32(sizeof *resp); -- 2.55.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] usb: gadget: function: rndis: add length check to response query 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 0 siblings, 1 reply; 5+ messages in thread From: Oliver Neukum @ 2026-07-08 16:24 UTC (permalink / raw) To: Griffin Kroah-Hartman, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel Hi, On 08.07.26 13:08, Griffin Kroah-Hartman wrote: > @@ -598,6 +599,13 @@ static int rndis_query_response(struct rndis_params *params, > if (!params->dev) > return -ENOTSUPP; > > + BufLength = le32_to_cpu(buf->InformationBufferLength); > + BufOffset = le32_to_cpu(buf->InformationBufferOffset); > + if ((BufLength > RNDIS_MAX_TOTAL_SIZE) || > + (BufOffset > RNDIS_MAX_TOTAL_SIZE) || > + (BufOffset + 8 >= RNDIS_MAX_TOTAL_SIZE)) Wouldn't those last two lines be more efficiently done with: BufOffset >= RNDIS_MAX_TOTAL_SIZE - 8 Regards Oliver ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] usb: gadget: function: rndis: add length check to response query 2026-07-08 16:24 ` Oliver Neukum @ 2026-07-09 5:34 ` Greg Kroah-Hartman 0 siblings, 0 replies; 5+ messages in thread From: Greg Kroah-Hartman @ 2026-07-09 5:34 UTC (permalink / raw) To: Oliver Neukum; +Cc: Griffin Kroah-Hartman, linux-usb, linux-kernel On Wed, Jul 08, 2026 at 06:24:16PM +0200, Oliver Neukum wrote: > Hi, > > On 08.07.26 13:08, Griffin Kroah-Hartman wrote: > > @@ -598,6 +599,13 @@ static int rndis_query_response(struct rndis_params *params, > > if (!params->dev) > > return -ENOTSUPP; > > + BufLength = le32_to_cpu(buf->InformationBufferLength); > > + BufOffset = le32_to_cpu(buf->InformationBufferOffset); > > + if ((BufLength > RNDIS_MAX_TOTAL_SIZE) || > > + (BufOffset > RNDIS_MAX_TOTAL_SIZE) || > > + (BufOffset + 8 >= RNDIS_MAX_TOTAL_SIZE)) > > Wouldn't those last two lines be more efficiently done with: > > BufOffset >= RNDIS_MAX_TOTAL_SIZE - 8 Probably, but doesn't the compiler turn them into the same result? Also, rndis_set_response() has this same check, so at least everything is consistent :) thanks, greg k-h ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/2] usb: gadget: function: rndis: add length check for header 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 11:08 ` Griffin Kroah-Hartman 1 sibling, 0 replies; 5+ messages in thread From: Griffin Kroah-Hartman @ 2026-07-08 11:08 UTC (permalink / raw) To: Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel, Griffin Kroah-Hartman 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 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-07-09 5:34 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 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 ` [PATCH 2/2] usb: gadget: function: rndis: add length check for header Griffin Kroah-Hartman
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox