* [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv()
@ 2021-06-23 19:43 Eric Dumazet
2021-06-23 22:07 ` Jakub Kicinski
2021-06-24 9:49 ` Paolo Abeni
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2021-06-23 19:43 UTC (permalink / raw)
To: David S . Miller, Jakub Kicinski
Cc: netdev, Eric Dumazet, Eric Dumazet, Paolo Abeni, Tom Herbert
From: Eric Dumazet <edumazet@google.com>
First problem is that optlen is fetched without checking
there is more than one byte to parse.
Fix this by taking care of IPV6_TLV_PAD1 before
fetching optlen (under appropriate sanity checks against len)
Second problem is that IPV6_TLV_PADN checks of zero
padding are performed before the check of remaining length.
Fixes: c1412fce7ecc ("net/ipv6/exthdrs.c: Strict PadN option checking")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Tom Herbert <tom@herbertland.com>
---
Only compiled, I would appreciate a solid review of this patch before merging it, thanks !
net/ipv6/exthdrs.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
index 6f7da8f3e2e5849f917853984c69bf02a0f1e27c..007959d4d3748f1e21f83946024a9967d08b25b6 100644
--- a/net/ipv6/exthdrs.c
+++ b/net/ipv6/exthdrs.c
@@ -135,18 +135,24 @@ static bool ip6_parse_tlv(const struct tlvtype_proc *procs,
len -= 2;
while (len > 0) {
- int optlen = nh[off + 1] + 2;
- int i;
+ int optlen, i;
- switch (nh[off]) {
- case IPV6_TLV_PAD1:
+ if (nh[off] == IPV6_TLV_PAD1) {
optlen = 1;
padlen++;
if (padlen > 7)
goto bad;
- break;
+ off++;
+ len--;
+ continue;
+ }
+ if (len < 2)
+ goto bad;
+ optlen = nh[off + 1] + 2;
+ if (optlen > len)
+ goto bad;
- case IPV6_TLV_PADN:
+ if (nh[off] == IPV6_TLV_PADN) {
/* RFC 2460 states that the purpose of PadN is
* to align the containing header to multiples
* of 8. 7 is therefore the highest valid value.
@@ -163,12 +169,7 @@ static bool ip6_parse_tlv(const struct tlvtype_proc *procs,
if (nh[off + i] != 0)
goto bad;
}
- break;
-
- default: /* Other TLV code so scan list */
- if (optlen > len)
- goto bad;
-
+ } else {
tlv_count++;
if (tlv_count > max_count)
goto bad;
@@ -188,7 +189,6 @@ static bool ip6_parse_tlv(const struct tlvtype_proc *procs,
return false;
padlen = 0;
- break;
}
off += optlen;
len -= optlen;
--
2.32.0.288.g62a8d224e6-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv()
2021-06-23 19:43 [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv() Eric Dumazet
@ 2021-06-23 22:07 ` Jakub Kicinski
2021-06-24 9:49 ` Paolo Abeni
1 sibling, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2021-06-23 22:07 UTC (permalink / raw)
To: Eric Dumazet
Cc: David S . Miller, netdev, Eric Dumazet, Paolo Abeni, Tom Herbert
On Wed, 23 Jun 2021 12:43:53 -0700 Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> First problem is that optlen is fetched without checking
> there is more than one byte to parse.
>
> Fix this by taking care of IPV6_TLV_PAD1 before
> fetching optlen (under appropriate sanity checks against len)
>
> Second problem is that IPV6_TLV_PADN checks of zero
> padding are performed before the check of remaining length.
>
> Fixes: c1412fce7ecc ("net/ipv6/exthdrs.c: Strict PadN option checking")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Tom Herbert <tom@herbertland.com>
> ---
>
> Only compiled, I would appreciate a solid review of this patch before merging it, thanks !
Reviewed-by: Jakub Kicinski <kuba@kernel.org>
for what that's worth
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv()
2021-06-23 19:43 [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv() Eric Dumazet
2021-06-23 22:07 ` Jakub Kicinski
@ 2021-06-24 9:49 ` Paolo Abeni
2021-06-24 10:08 ` Eric Dumazet
1 sibling, 1 reply; 4+ messages in thread
From: Paolo Abeni @ 2021-06-24 9:49 UTC (permalink / raw)
To: Eric Dumazet, David S . Miller, Jakub Kicinski
Cc: netdev, Eric Dumazet, Tom Herbert
On Wed, 2021-06-23 at 12:43 -0700, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> First problem is that optlen is fetched without checking
> there is more than one byte to parse.
>
> Fix this by taking care of IPV6_TLV_PAD1 before
> fetching optlen (under appropriate sanity checks against len)
>
> Second problem is that IPV6_TLV_PADN checks of zero
> padding are performed before the check of remaining length.
>
> Fixes: c1412fce7ecc ("net/ipv6/exthdrs.c: Strict PadN option checking")
Perhaps even:
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
for the first issue?
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Cc: Paolo Abeni <pabeni@redhat.com>
> Cc: Tom Herbert <tom@herbertland.com>
> ---
>
> Only compiled, I would appreciate a solid review of this patch before merging it, thanks !
>
> net/ipv6/exthdrs.c | 26 +++++++++++++-------------
> 1 file changed, 13 insertions(+), 13 deletions(-)
>
> diff --git a/net/ipv6/exthdrs.c b/net/ipv6/exthdrs.c
> index 6f7da8f3e2e5849f917853984c69bf02a0f1e27c..007959d4d3748f1e21f83946024a9967d08b25b6 100644
> --- a/net/ipv6/exthdrs.c
> +++ b/net/ipv6/exthdrs.c
> @@ -135,18 +135,24 @@ static bool ip6_parse_tlv(const struct tlvtype_proc *procs,
> len -= 2;
>
> while (len > 0) {
> - int optlen = nh[off + 1] + 2;
> - int i;
> + int optlen, i;
>
> - switch (nh[off]) {
> - case IPV6_TLV_PAD1:
> + if (nh[off] == IPV6_TLV_PAD1) {
> optlen = 1;
It looks like the above assignment is not needed anymore.
Other than that LGTM,
Thanks!
Paolo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv()
2021-06-24 9:49 ` Paolo Abeni
@ 2021-06-24 10:08 ` Eric Dumazet
0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2021-06-24 10:08 UTC (permalink / raw)
To: Paolo Abeni
Cc: Eric Dumazet, David S . Miller, Jakub Kicinski, netdev, Tom Herbert
On Thu, Jun 24, 2021 at 11:49 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On Wed, 2021-06-23 at 12:43 -0700, Eric Dumazet wrote:
> > From: Eric Dumazet <edumazet@google.com>
> >
> > First problem is that optlen is fetched without checking
> > there is more than one byte to parse.
> >
> > Fix this by taking care of IPV6_TLV_PAD1 before
> > fetching optlen (under appropriate sanity checks against len)
> >
> > Second problem is that IPV6_TLV_PADN checks of zero
> > padding are performed before the check of remaining length.
> >
> > Fixes: c1412fce7ecc ("net/ipv6/exthdrs.c: Strict PadN option checking")
>
> Perhaps even:
>
> Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
>
> for the first issue?
>
> + if (nh[off] == IPV6_TLV_PAD1) {
> > optlen = 1;
>
> It looks like the above assignment is not needed anymore.
>
> Other than that LGTM,
>
Thanks for the review, I am sending the v2.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-06-24 10:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-23 19:43 [PATCH net] ipv6: fix out-of-bound access in ip6_parse_tlv() Eric Dumazet
2021-06-23 22:07 ` Jakub Kicinski
2021-06-24 9:49 ` Paolo Abeni
2021-06-24 10:08 ` Eric Dumazet
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.