* [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
@ 2022-04-01 15:12 Guenter Roeck
2022-04-01 18:40 ` Larry Finger
0 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2022-04-01 15:12 UTC (permalink / raw)
To: Larry Finger
Cc: Phillip Potter, Greg Kroah-Hartman, linux-staging, linux-kernel,
Guenter Roeck
In __nat25_add_pppoe_tag(), the tag length is read from the tag data
structure. The value is kept in network format, but read as raw value.
With -Warray-bounds, this results in the following gcc error/warning
when building the driver on a big endian system such as alpha.
In function '__nat25_add_pppoe_tag',
inlined from 'nat25_db_handle' at
drivers/staging/r8188eu/core/rtw_br_ext.c:479:11:
arch/alpha/include/asm/string.h:22:16: error:
'__builtin_memcpy' forming offset [40, 2051] is out of the bounds
[0, 40] of object 'tag_buf' with type 'unsigned char[40]'
Add the missing ntohs().
Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
Cc: Phillip Potter <phil@philpotter.co.uk>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
drivers/staging/r8188eu/core/rtw_br_ext.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
index d68611ef22f8..31bcd495ec04 100644
--- a/drivers/staging/r8188eu/core/rtw_br_ext.c
+++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
@@ -70,7 +70,7 @@ static int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
int data_len;
- data_len = tag->tag_len + TAG_HDR_LEN;
+ data_len = htons(tag->tag_len) + TAG_HDR_LEN;
if (skb_tailroom(skb) < data_len)
return -1;
--
2.35.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
2022-04-01 15:12 [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems Guenter Roeck
@ 2022-04-01 18:40 ` Larry Finger
2022-04-01 19:25 ` Guenter Roeck
0 siblings, 1 reply; 7+ messages in thread
From: Larry Finger @ 2022-04-01 18:40 UTC (permalink / raw)
To: Guenter Roeck
Cc: Phillip Potter, Greg Kroah-Hartman, linux-staging, linux-kernel
On 4/1/22 10:12, Guenter Roeck wrote:
> In __nat25_add_pppoe_tag(), the tag length is read from the tag data
> structure. The value is kept in network format, but read as raw value.
> With -Warray-bounds, this results in the following gcc error/warning
> when building the driver on a big endian system such as alpha.
>
> In function '__nat25_add_pppoe_tag',
> inlined from 'nat25_db_handle' at
> drivers/staging/r8188eu/core/rtw_br_ext.c:479:11:
> arch/alpha/include/asm/string.h:22:16: error:
> '__builtin_memcpy' forming offset [40, 2051] is out of the bounds
> [0, 40] of object 'tag_buf' with type 'unsigned char[40]'
>
> Add the missing ntohs().
>
> Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
> Cc: Phillip Potter <phil@philpotter.co.uk>
> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
> ---
> drivers/staging/r8188eu/core/rtw_br_ext.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
> index d68611ef22f8..31bcd495ec04 100644
> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
> @@ -70,7 +70,7 @@ static int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
> struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
> int data_len;
>
> - data_len = tag->tag_len + TAG_HDR_LEN;
> + data_len = htons(tag->tag_len) + TAG_HDR_LEN;
> if (skb_tailroom(skb) < data_len)
> return -1;
>
Strange that a BE compiler would generate a warning for what is actually an
execution error on LE platforms.
I prefer be16_to_cpu() to htons() as the former makes it clearer what is
happening, but I suppose that is a matter of choice.
Reviewed_by: Larry Finger <Larry.Finger@lwfinger.net>
Incidentally, Sparse shows 3 more __be16 problems in this routine. I leave their
fixing to you.
Larry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
2022-04-01 18:40 ` Larry Finger
@ 2022-04-01 19:25 ` Guenter Roeck
2022-04-01 20:25 ` Larry Finger
0 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2022-04-01 19:25 UTC (permalink / raw)
To: Larry Finger
Cc: Phillip Potter, Greg Kroah-Hartman, linux-staging, linux-kernel
On 4/1/22 11:40, Larry Finger wrote:
> On 4/1/22 10:12, Guenter Roeck wrote:
>> In __nat25_add_pppoe_tag(), the tag length is read from the tag data
>> structure. The value is kept in network format, but read as raw value.
>> With -Warray-bounds, this results in the following gcc error/warning
>> when building the driver on a big endian system such as alpha.
>>
>> In function '__nat25_add_pppoe_tag',
>> inlined from 'nat25_db_handle' at
>> drivers/staging/r8188eu/core/rtw_br_ext.c:479:11:
>> arch/alpha/include/asm/string.h:22:16: error:
>> '__builtin_memcpy' forming offset [40, 2051] is out of the bounds
>> [0, 40] of object 'tag_buf' with type 'unsigned char[40]'
>>
>> Add the missing ntohs().
>>
>> Fixes: 15865124feed ("staging: r8188eu: introduce new core dir for RTL8188eu driver")
>> Cc: Phillip Potter <phil@philpotter.co.uk>
>> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
>> ---
>> drivers/staging/r8188eu/core/rtw_br_ext.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/staging/r8188eu/core/rtw_br_ext.c b/drivers/staging/r8188eu/core/rtw_br_ext.c
>> index d68611ef22f8..31bcd495ec04 100644
>> --- a/drivers/staging/r8188eu/core/rtw_br_ext.c
>> +++ b/drivers/staging/r8188eu/core/rtw_br_ext.c
>> @@ -70,7 +70,7 @@ static int __nat25_add_pppoe_tag(struct sk_buff *skb, struct pppoe_tag *tag)
>> struct pppoe_hdr *ph = (struct pppoe_hdr *)(skb->data + ETH_HLEN);
>> int data_len;
>> - data_len = tag->tag_len + TAG_HDR_LEN;
>> + data_len = htons(tag->tag_len) + TAG_HDR_LEN;
Wonder where my brain was. That should have been ntohs().
>> if (skb_tailroom(skb) < data_len)
>> return -1;
>
> Strange that a BE compiler would generate a warning for what is actually an execution error on LE platforms.
>
> I prefer be16_to_cpu() to htons() as the former makes it clearer what is happening, but I suppose that is a matter of choice.
>
The rest of the code uses htons/ntohs, so I prefer to follow that lead.
> Reviewed_by: Larry Finger <Larry.Finger@lwfinger.net>
>
> Incidentally, Sparse shows 3 more __be16 problems in this routine. I leave their fixing to you.
>
I'll need to resend anyway, so I'll track those down and fix them as well.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
2022-04-01 19:25 ` Guenter Roeck
@ 2022-04-01 20:25 ` Larry Finger
2022-04-02 21:18 ` Guenter Roeck
0 siblings, 1 reply; 7+ messages in thread
From: Larry Finger @ 2022-04-01 20:25 UTC (permalink / raw)
To: Guenter Roeck
Cc: Phillip Potter, Greg Kroah-Hartman, linux-staging, linux-kernel
On 4/1/22 14:25, Guenter Roeck wrote:
> The rest of the code uses htons/ntohs, so I prefer to follow that lead.
You just proved my point. It is hard to get be16_to_cpu() wrong. Sparse will
flag the error when you use cpu_to_be16() instead. I expect that your
htons/ntohs problem would also have shown up with Sparse.
Larry
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
2022-04-01 20:25 ` Larry Finger
@ 2022-04-02 21:18 ` Guenter Roeck
2022-04-04 9:53 ` Dan Carpenter
0 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2022-04-02 21:18 UTC (permalink / raw)
To: Larry Finger
Cc: Phillip Potter, Greg Kroah-Hartman, linux-staging, linux-kernel
On 4/1/22 13:25, Larry Finger wrote:
> On 4/1/22 14:25, Guenter Roeck wrote:
>> The rest of the code uses htons/ntohs, so I prefer to follow that lead.
>
> You just proved my point. It is hard to get be16_to_cpu() wrong. Sparse will flag the error when you use cpu_to_be16() instead. I expect that your htons/ntohs problem would also have shown up with Sparse.
>
Ok, you made your point. I'll use be16_to_cpu() - the driver
already uses it elsewhere anyway. As for the other problems,
I am not sure if the driver ever worked. The function we are
looking at can't really have worked on a little endian system
because of the missing conversion, and the same is true for the
other code flagged by sparse. I think I'll just add a note
to this patch and let the driver authors decide what to do
about those problems.
Guenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
2022-04-02 21:18 ` Guenter Roeck
@ 2022-04-04 9:53 ` Dan Carpenter
2022-04-04 13:47 ` Guenter Roeck
0 siblings, 1 reply; 7+ messages in thread
From: Dan Carpenter @ 2022-04-04 9:53 UTC (permalink / raw)
To: Guenter Roeck
Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman, linux-staging,
linux-kernel
On Sat, Apr 02, 2022 at 02:18:22PM -0700, Guenter Roeck wrote:
> On 4/1/22 13:25, Larry Finger wrote:
> > On 4/1/22 14:25, Guenter Roeck wrote:
> > > The rest of the code uses htons/ntohs, so I prefer to follow that lead.
> >
> > You just proved my point. It is hard to get be16_to_cpu() wrong. Sparse will flag the error when you use cpu_to_be16() instead. I expect that your htons/ntohs problem would also have shown up with Sparse.
> >
>
> Ok, you made your point. I'll use be16_to_cpu() - the driver
> already uses it elsewhere anyway. As for the other problems,
> I am not sure if the driver ever worked. The function we are
> looking at can't really have worked on a little endian system
> because of the missing conversion, and the same is true for the
> other code flagged by sparse. I think I'll just add a note
> to this patch and let the driver authors decide what to do
> about those problems.
>
> Guenter
This is already fixed along with a couple related bugs in commit
2d959a842a8f ("staging: r8188eu: Fix sparse endianness warnings.").
https://lore.kernel.org/r/YkPK/QmLAp3BkygY@sckzor-linux.localdomain
It's in staging-next but hasn't hit linux-next yet.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems
2022-04-04 9:53 ` Dan Carpenter
@ 2022-04-04 13:47 ` Guenter Roeck
0 siblings, 0 replies; 7+ messages in thread
From: Guenter Roeck @ 2022-04-04 13:47 UTC (permalink / raw)
To: Dan Carpenter
Cc: Larry Finger, Phillip Potter, Greg Kroah-Hartman, linux-staging,
linux-kernel
On 4/4/22 02:53, Dan Carpenter wrote:
> On Sat, Apr 02, 2022 at 02:18:22PM -0700, Guenter Roeck wrote:
>> On 4/1/22 13:25, Larry Finger wrote:
>>> On 4/1/22 14:25, Guenter Roeck wrote:
>>>> The rest of the code uses htons/ntohs, so I prefer to follow that lead.
>>>
>>> You just proved my point. It is hard to get be16_to_cpu() wrong. Sparse will flag the error when you use cpu_to_be16() instead. I expect that your htons/ntohs problem would also have shown up with Sparse.
>>>
>>
>> Ok, you made your point. I'll use be16_to_cpu() - the driver
>> already uses it elsewhere anyway. As for the other problems,
>> I am not sure if the driver ever worked. The function we are
>> looking at can't really have worked on a little endian system
>> because of the missing conversion, and the same is true for the
>> other code flagged by sparse. I think I'll just add a note
>> to this patch and let the driver authors decide what to do
>> about those problems.
>>
>> Guenter
>
> This is already fixed along with a couple related bugs in commit
> 2d959a842a8f ("staging: r8188eu: Fix sparse endianness warnings.").
>
> https://lore.kernel.org/r/YkPK/QmLAp3BkygY@sckzor-linux.localdomain
>
> It's in staging-next but hasn't hit linux-next yet.
>
Good to hear. Too bad I got it a minute too late - I just sent v3.
Guenter
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-04-04 14:07 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 15:12 [PATCH] staging: r8188eu: Fix PPPoE tag insertion on big endian systems Guenter Roeck
2022-04-01 18:40 ` Larry Finger
2022-04-01 19:25 ` Guenter Roeck
2022-04-01 20:25 ` Larry Finger
2022-04-02 21:18 ` Guenter Roeck
2022-04-04 9:53 ` Dan Carpenter
2022-04-04 13:47 ` Guenter Roeck
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.