2023-05-23 08:51:23

by Gavrilov Ilia

[permalink] [raw]
Subject: [PATCH net] ipv6: Fix out-of-bounds access in ipv6_find_tlv()

optlen is fetched without checking whether there is more than one byte to parse.
It can lead to out-of-bounds access.

Found by InfoTeCS on behalf of Linux Verification Center
(linuxtesting.org) with SVACE.

Fixes: 3c73a0368e99 ("ipv6: Update ipv6 static library with newly needed functions")
Signed-off-by: Gavrilov Ilia <[email protected]>
---
net/ipv6/exthdrs_core.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
index da46c4284676..49e31e4ae7b7 100644
--- a/net/ipv6/exthdrs_core.c
+++ b/net/ipv6/exthdrs_core.c
@@ -143,6 +143,8 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type)
optlen = 1;
break;
default:
+ if (len < 2)
+ goto bad;
optlen = nh[offset + 1] + 2;
if (optlen > len)
goto bad;
--
2.30.2


2023-05-23 13:35:28

by Jiri Pirko

[permalink] [raw]
Subject: Re: [PATCH net] ipv6: Fix out-of-bounds access in ipv6_find_tlv()

Tue, May 23, 2023 at 10:29:44AM CEST, [email protected] wrote:
>optlen is fetched without checking whether there is more than one byte to parse.
>It can lead to out-of-bounds access.
>
>Found by InfoTeCS on behalf of Linux Verification Center
>(linuxtesting.org) with SVACE.
>
>Fixes: 3c73a0368e99 ("ipv6: Update ipv6 static library with newly needed functions")
>Signed-off-by: Gavrilov Ilia <[email protected]>

Reviewed-by: Jiri Pirko <[email protected]>

2023-05-23 15:33:24

by David Ahern

[permalink] [raw]
Subject: Re: [PATCH net] ipv6: Fix out-of-bounds access in ipv6_find_tlv()

On 5/23/23 2:29 AM, Gavrilov Ilia wrote:
> optlen is fetched without checking whether there is more than one byte to parse.
> It can lead to out-of-bounds access.
>
> Found by InfoTeCS on behalf of Linux Verification Center
> (linuxtesting.org) with SVACE.
>
> Fixes: 3c73a0368e99 ("ipv6: Update ipv6 static library with newly needed functions")

That is not the right Fixes tag; that commit only moved the code.

Fixes: c61a40432509 ("[IPV6]: Find option offset by type.")

> Signed-off-by: Gavrilov Ilia <[email protected]>
> ---
> net/ipv6/exthdrs_core.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/net/ipv6/exthdrs_core.c b/net/ipv6/exthdrs_core.c
> index da46c4284676..49e31e4ae7b7 100644
> --- a/net/ipv6/exthdrs_core.c
> +++ b/net/ipv6/exthdrs_core.c
> @@ -143,6 +143,8 @@ int ipv6_find_tlv(const struct sk_buff *skb, int offset, int type)
> optlen = 1;
> break;
> default:
> + if (len < 2)
> + goto bad;
> optlen = nh[offset + 1] + 2;
> if (optlen > len)
> goto bad;

Reviewed-by: David Ahern <[email protected]>


2023-05-24 08:04:10

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH net] ipv6: Fix out-of-bounds access in ipv6_find_tlv()

Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:

On Tue, 23 May 2023 08:29:44 +0000 you wrote:
> optlen is fetched without checking whether there is more than one byte to parse.
> It can lead to out-of-bounds access.
>
> Found by InfoTeCS on behalf of Linux Verification Center
> (linuxtesting.org) with SVACE.
>
> Fixes: 3c73a0368e99 ("ipv6: Update ipv6 static library with newly needed functions")
> Signed-off-by: Gavrilov Ilia <[email protected]>
>
> [...]

Here is the summary with links:
- [net] ipv6: Fix out-of-bounds access in ipv6_find_tlv()
https://git.kernel.org/netdev/net/c/878ecb0897f4

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html