diff mbox series

[net] ipv6: Fix out-of-bounds access in ipv6_find_tlv()

Message ID 20230523082903.117626-1-Ilia.Gavrilov@infotecs.ru (mailing list archive)
State Accepted
Commit 878ecb0897f4737a4c9401f3523fd49589025671
Delegated to: Netdev Maintainers
Headers show
Series [net] ipv6: Fix out-of-bounds access in ipv6_find_tlv() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 10 this patch: 10
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 8 this patch: 8
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 10 this patch: 10
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Gavrilov Ilia May 23, 2023, 8:29 a.m. UTC
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 <Ilia.Gavrilov@infotecs.ru>
---
 net/ipv6/exthdrs_core.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Jiri Pirko May 23, 2023, 1:26 p.m. UTC | #1
Tue, May 23, 2023 at 10:29:44AM CEST, Ilia.Gavrilov@infotecs.ru 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 <Ilia.Gavrilov@infotecs.ru>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
David Ahern May 23, 2023, 3:21 p.m. UTC | #2
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 <Ilia.Gavrilov@infotecs.ru>
> ---
>  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 <dsahern@kernel.org>
patchwork-bot+netdevbpf@kernel.org May 24, 2023, 7:50 a.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:

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 <Ilia.Gavrilov@infotecs.ru>
> 
> [...]

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!
diff mbox series

Patch

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;