* [PATCH] tcp: fix compiler array bounds warning on selective_acks[]
@ 2014-04-10 21:30 Bjorn Helgaas
2014-04-11 8:59 ` David Laight
0 siblings, 1 reply; 3+ messages in thread
From: Bjorn Helgaas @ 2014-04-10 21:30 UTC (permalink / raw)
To: David S. Miller
Cc: Florian Fainelli, Hideaki YOSHIFUJI, netdev, James Morris,
linux-kernel, David Laight, Alexey Kuznetsov, Patrick McHardy
With -Werror=array-bounds, gcc v4.8.x warns that in tcp_sack_remove(), a
selective_acks[] "array subscript is above array bounds".
I don't understand how gcc figures this out, or why we don't see similar
problems many other places, but this is the only fix I can figure out.
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
net/ipv4/tcp_input.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
index 65cf90e063d5..65133b108236 100644
--- a/net/ipv4/tcp_input.c
+++ b/net/ipv4/tcp_input.c
@@ -4047,7 +4047,8 @@ static void tcp_sack_remove(struct tcp_sock *tp)
/* Zap this SACK, by moving forward any other SACKS. */
for (i = this_sack+1; i < num_sacks; i++)
- tp->selective_acks[i-1] = tp->selective_acks[i];
+ if (i < ARRAY_SIZE(tp->selective_acks))
+ tp->selective_acks[i-1] = tp->selective_acks[i];
num_sacks--;
continue;
}
^ permalink raw reply related [flat|nested] 3+ messages in thread
* RE: [PATCH] tcp: fix compiler array bounds warning on selective_acks[]
2014-04-10 21:30 [PATCH] tcp: fix compiler array bounds warning on selective_acks[] Bjorn Helgaas
@ 2014-04-11 8:59 ` David Laight
2014-04-11 16:12 ` Bjorn Helgaas
0 siblings, 1 reply; 3+ messages in thread
From: David Laight @ 2014-04-11 8:59 UTC (permalink / raw)
To: 'Bjorn Helgaas', David S. Miller
Cc: Florian Fainelli, Hideaki YOSHIFUJI, netdev, James Morris,
linux-kernel, Alexey Kuznetsov, Patrick McHardy
Bjorn Helgaas
> With -Werror=array-bounds, gcc v4.8.x warns that in tcp_sack_remove(), a
> selective_acks[] "array subscript is above array bounds".
>
> I don't understand how gcc figures this out, or why we don't see similar
> problems many other places, but this is the only fix I can figure out.
...
> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
> index 65cf90e063d5..65133b108236 100644
> --- a/net/ipv4/tcp_input.c
> +++ b/net/ipv4/tcp_input.c
> @@ -4047,7 +4047,8 @@ static void tcp_sack_remove(struct tcp_sock *tp)
>
> /* Zap this SACK, by moving forward any other SACKS. */
> for (i = this_sack+1; i < num_sacks; i++)
> - tp->selective_acks[i-1] = tp->selective_acks[i];
> + if (i < ARRAY_SIZE(tp->selective_acks))
> + tp->selective_acks[i-1] = tp->selective_acks[i];
> num_sacks--;
> continue;
> }
You really shouldn't add that test every time around the loop.
Try changing the loop so the assignment is:
tp->selective_acks[i] = tp->selective_acks[i + 1];
or the loop test to:
i <= num_sacks - 1;
Or beat up the gcc developers :-)
David
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tcp: fix compiler array bounds warning on selective_acks[]
2014-04-11 8:59 ` David Laight
@ 2014-04-11 16:12 ` Bjorn Helgaas
0 siblings, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2014-04-11 16:12 UTC (permalink / raw)
To: David Laight
Cc: David S. Miller, Florian Fainelli, Hideaki YOSHIFUJI, netdev,
James Morris, linux-kernel, Alexey Kuznetsov, Patrick McHardy
On Fri, Apr 11, 2014 at 2:59 AM, David Laight <David.Laight@aculab.com> wrote:
> Bjorn Helgaas
>> With -Werror=array-bounds, gcc v4.8.x warns that in tcp_sack_remove(), a
>> selective_acks[] "array subscript is above array bounds".
>>
>> I don't understand how gcc figures this out, or why we don't see similar
>> problems many other places, but this is the only fix I can figure out.
> ...
>> diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
>> index 65cf90e063d5..65133b108236 100644
>> --- a/net/ipv4/tcp_input.c
>> +++ b/net/ipv4/tcp_input.c
>> @@ -4047,7 +4047,8 @@ static void tcp_sack_remove(struct tcp_sock *tp)
>>
>> /* Zap this SACK, by moving forward any other SACKS. */
>> for (i = this_sack+1; i < num_sacks; i++)
>> - tp->selective_acks[i-1] = tp->selective_acks[i];
>> + if (i < ARRAY_SIZE(tp->selective_acks))
>> + tp->selective_acks[i-1] = tp->selective_acks[i];
>> num_sacks--;
>> continue;
>> }
>
> You really shouldn't add that test every time around the loop.
>
> Try changing the loop so the assignment is:
> tp->selective_acks[i] = tp->selective_acks[i + 1];
>
> or the loop test to:
> i <= num_sacks - 1;
>
> Or beat up the gcc developers :-)
You're right, that *is* ugly. And it seems that gcc-v4.9.x doesn't
complain about this, and that's good enough for my purposes, so I
withdraw this patch.
Thanks and sorry for the noise,
Bjorn
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-04-11 16:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-10 21:30 [PATCH] tcp: fix compiler array bounds warning on selective_acks[] Bjorn Helgaas
2014-04-11 8:59 ` David Laight
2014-04-11 16:12 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).