diff mbox series

[net] tunnels: fix out of bounds access when building IPv6 PMTU error

Message ID 20240201083817.12774-1-atenart@kernel.org (mailing list archive)
State Accepted
Commit d75abeec401f8c86b470e7028a13fcdc87e5dd06
Delegated to: Netdev Maintainers
Headers show
Series [net] tunnels: fix out of bounds access when building IPv6 PMTU error | 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/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
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: 1066 this patch: 1066
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 0 of 0 maintainers
netdev/build_clang success Errors and warnings before: 1082 this patch: 1082
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: 1083 this patch: 1083
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-02-02--15-00 (tests: 720)

Commit Message

Antoine Tenart Feb. 1, 2024, 8:38 a.m. UTC
If the ICMPv6 error is built from a non-linear skb we get the following
splat,

  BUG: KASAN: slab-out-of-bounds in do_csum+0x220/0x240
  Read of size 4 at addr ffff88811d402c80 by task netperf/820
  CPU: 0 PID: 820 Comm: netperf Not tainted 6.8.0-rc1+ #543
  ...
   kasan_report+0xd8/0x110
   do_csum+0x220/0x240
   csum_partial+0xc/0x20
   skb_tunnel_check_pmtu+0xeb9/0x3280
   vxlan_xmit_one+0x14c2/0x4080
   vxlan_xmit+0xf61/0x5c00
   dev_hard_start_xmit+0xfb/0x510
   __dev_queue_xmit+0x7cd/0x32a0
   br_dev_queue_push_xmit+0x39d/0x6a0

Use skb_checksum instead of csum_partial who cannot deal with non-linear
SKBs.

Fixes: 4cb47a8644cc ("tunnels: PMTU discovery support for directly bridged IP packets")
Signed-off-by: Antoine Tenart <atenart@kernel.org>
---
 net/ipv4/ip_tunnel_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jiri Pirko Feb. 1, 2024, 12:45 p.m. UTC | #1
Thu, Feb 01, 2024 at 09:38:15AM CET, atenart@kernel.org wrote:
>If the ICMPv6 error is built from a non-linear skb we get the following
>splat,
>
>  BUG: KASAN: slab-out-of-bounds in do_csum+0x220/0x240
>  Read of size 4 at addr ffff88811d402c80 by task netperf/820
>  CPU: 0 PID: 820 Comm: netperf Not tainted 6.8.0-rc1+ #543
>  ...
>   kasan_report+0xd8/0x110
>   do_csum+0x220/0x240
>   csum_partial+0xc/0x20
>   skb_tunnel_check_pmtu+0xeb9/0x3280
>   vxlan_xmit_one+0x14c2/0x4080
>   vxlan_xmit+0xf61/0x5c00
>   dev_hard_start_xmit+0xfb/0x510
>   __dev_queue_xmit+0x7cd/0x32a0
>   br_dev_queue_push_xmit+0x39d/0x6a0
>
>Use skb_checksum instead of csum_partial who cannot deal with non-linear
>SKBs.
>
>Fixes: 4cb47a8644cc ("tunnels: PMTU discovery support for directly bridged IP packets")
>Signed-off-by: Antoine Tenart <atenart@kernel.org>

Reviewed-by: Jiri Pirko <jiri@nvidia.com>
patchwork-bot+netdevbpf@kernel.org Feb. 3, 2024, 12:50 p.m. UTC | #2
Hello:

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

On Thu,  1 Feb 2024 09:38:15 +0100 you wrote:
> If the ICMPv6 error is built from a non-linear skb we get the following
> splat,
> 
>   BUG: KASAN: slab-out-of-bounds in do_csum+0x220/0x240
>   Read of size 4 at addr ffff88811d402c80 by task netperf/820
>   CPU: 0 PID: 820 Comm: netperf Not tainted 6.8.0-rc1+ #543
>   ...
>    kasan_report+0xd8/0x110
>    do_csum+0x220/0x240
>    csum_partial+0xc/0x20
>    skb_tunnel_check_pmtu+0xeb9/0x3280
>    vxlan_xmit_one+0x14c2/0x4080
>    vxlan_xmit+0xf61/0x5c00
>    dev_hard_start_xmit+0xfb/0x510
>    __dev_queue_xmit+0x7cd/0x32a0
>    br_dev_queue_push_xmit+0x39d/0x6a0
> 
> [...]

Here is the summary with links:
  - [net] tunnels: fix out of bounds access when building IPv6 PMTU error
    https://git.kernel.org/netdev/net/c/d75abeec401f

You are awesome, thank you!
diff mbox series

Patch

diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 586b1b3e35b8..80ccd6661aa3 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -332,7 +332,7 @@  static int iptunnel_pmtud_build_icmpv6(struct sk_buff *skb, int mtu)
 	};
 	skb_reset_network_header(skb);
 
-	csum = csum_partial(icmp6h, len, 0);
+	csum = skb_checksum(skb, skb_transport_offset(skb), len, 0);
 	icmp6h->icmp6_cksum = csum_ipv6_magic(&nip6h->saddr, &nip6h->daddr, len,
 					      IPPROTO_ICMPV6, csum);