USB: gl620a: check for rx buffer overflow
Subsystems (4)
PATCH v2 1/1 USB: gl620a: check for rx buffer overflow
The driver checks for a single package overflowing maximum size. That needs to be done, but it is not enough. As a single transmission can contain a high number of packets, we also need to check whether the aggregate of messages in itself short enough overflow the buffer.
That is easiest done by checking that the current packet does not overflow the buffer.
---
v2: corrected typo in commit message
drivers/net/usb/gl620a.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/net/usb/gl620a.c +4 -0
@@ -104,6 +104,10 @@ static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)return 0 ; } +/* we also need to check for overflowing the buffer */ +if (size > skb->len) +return 0 ; +// allocate the skb for the individual packet gl_skb =alloc_skb (size,GFP_ATOMIC );if (gl_skb) {
Signature · 1 line
2.42.1
Quoted 1 line · Oliver Neukum
The driver checks for a single package overflowing
Maybe packet?
Quoted 9 lines
maximum size. That needs to be done, but it is not enough. As a single transmission can contain a high number of packets, we also need to check whether the aggregate of messages in itself short enough overflow the buffer.
That is easiest done by checking that the current packet does not overflow the buffer.Signed-off-by Oliver Neukum <[email protected]>
[...]
MBR, Sergey
Quoted 5 lines · Sergey Shtylyov
Quoted 1 line · Oliver Neukum
The driver checks for a single package overflowing
Maybe packet?
No, that would be read as network packet, which
is precisely what this not not and should not
be mistaken for.
Regards
Oliver
On 11/22/23 1:04 PM, Oliver Neukum wrote:
[...]
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
The driver checks for a single package overflowing
Maybe packet?
No, that would be read as network packet, which
is precisely what this not not and should not
be mistaken for.
But "package" hardly fits either. Is it a USB packet or something else?
Quoted 2 lines
Regards
Oliver
MBR, Sergey
Quoted 5 lines · Sergei Shtylyov
On 11/22/23 1:04 PM, Oliver Neukum wrote:
[...]
Quoted 2 lines
Quoted 2 lines
Quoted 1 line
The driver checks for a single package overflowing
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Maybe packet?
No, that would be read as network packet, which
is precisely what this not not and should not
be mistaken for.But "package" hardly fits either. Is it a USB packet or something else?
Technically the content of the buffer associated with a single URB. Which on USB physically can be multiple packets. The network packets arrive together in a package. That is how this and related drivers operate.
Regards
Oliver
Simon Horman
reviewerQuoted 14 lines · Oliver Neukum
Quoted 11 lines · Sergei Shtylyov
On 11/22/23 1:04 PM, Oliver Neukum wrote:
[...]
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
The driver checks for a single package overflowing
Maybe packet?
No, that would be read as network packet, which
is precisely what this not not and should not
be mistaken for.
Quoted 6 lines
Quoted 1 line
But "package" hardly fits either. Is it a USB packet or something else?
Technically the content of the buffer associated with a single URB. Which on USB physically can be multiple packets. The network packets arrive together in a package. That is how this and related drivers operate.
I think it would be useful to include information along the lines of the above in the patch description.
Quoted 4 lines · Simon Horman
I think it would be useful to include information along the lines of the above in the patch description.
Hi,
I see why you want this information to be available. So I thought about it and I think this should be either in Documentation or in a comment in usbnet, so that new drivers include the necessary checks from the start. What do you think?
Regards
Oliver
Quoted 6 lines · Oliver Neukum
Quoted 4 lines · Simon Horman
I think it would be useful to include information along the lines of the above in the patch description.
Quoted 7 lines
Hi,
I see why you want this information to be available. So I thought about it and I think this should be either in Documentation or in a comment in usbnet, so that new drivers include the necessary checks from the start. What do you think?
Hi Oliver,
yes, now you mention it that does seem appropriate. And I don't think that doing so gates this patch.
Signature · 1 line
pw-bot: under-review
Paolo Abeni
maintainerQuoted 10 lines · Oliver Neukum
The driver checks for a single package overflowing maximum size. That needs to be done, but it is not enough. As a single transmission can contain a high number of packets, we also need to check whether the aggregate of messages in itself short enough overflow the buffer.
That is easiest done by checking that the current packet does not overflow the buffer.Signed-off-by Oliver Neukum <[email protected]>
This looks like a bugfix, so a suitable Fixes tag should be included.
Quoted 12 lines
---
v2: corrected typo in commit message
drivers/net/usb/gl620a.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/net/usb/gl620a.c +0
-0
drivers/net/usb/gl620a.c static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb) · line 109
Quoted 6 lines
drivers/net/usb/gl620a.c +3
-0@@ -104,6 +104,10 @@ static int genelink_rx_fixup(struct usbnet *dev, struct sk_buff *skb)return 0 ; } +/* we also need to check for overflowing the buffer */ +if (size > skb->len) +return 0 ;
I think the above is not strict enough: at this point skb->data points to the gl_packet header. The first 4 bytes in skb are gl_packet-
Quoted 1 line
packet_length. To ensure an overflow is avoided you should check for:
if (size + 4 > skb->len)
likely with a describing comment.
Cheers,
Paolo
On 05.12.23 09:04, Paolo Abeni wrote:
Hi,
Quoted 7 lines
I think the above is not strict enough: at this point
skb->datapoints to thegl_packetheader. The first 4 bytes in skb are gl_packet-Quoted 1 line
packet_length. To ensure an overflow is avoided you should check for:if (size + 4 > skb->len)likely with a describing comment.
it seems to me that at the time of the check skb->len has already been adjusted by the skb_pull() before, respectively at the end, of the loop.
Regards
Oliver