linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org,
	syzbot+05f840f3b04f211bad55@syzkaller.appspotmail.com,
	Wei Wang <weiwan@google.com>, Martin KaFai Lau <kafai@fb.com>,
	Guillaume Nault <g.nault@alphalink.fr>,
	David Ahern <dsahern@gmail.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: [PATCH 4.18 01/35] l2tp: use sk_dst_check() to avoid race on sk->sk_dst_cache
Date: Tue, 21 Aug 2018 08:20:27 +0200	[thread overview]
Message-ID: <20180821055020.031044093@linuxfoundation.org> (raw)
In-Reply-To: <20180821055019.954904905@linuxfoundation.org>

4.18-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Wei Wang <weiwan@google.com>

[ Upstream commit 6d37fa49da1e8db8fb1995be22ac837ca41ac8a8 ]

In l2tp code, if it is a L2TP_UDP_ENCAP tunnel, tunnel->sk points to a
UDP socket. User could call sendmsg() on both this tunnel and the UDP
socket itself concurrently. As l2tp_xmit_skb() holds socket lock and call
__sk_dst_check() to refresh sk->sk_dst_cache, while udpv6_sendmsg() is
lockless and call sk_dst_check() to refresh sk->sk_dst_cache, there
could be a race and cause the dst cache to be freed multiple times.
So we fix l2tp side code to always call sk_dst_check() to garantee
xchg() is called when refreshing sk->sk_dst_cache to avoid race
conditions.

Syzkaller reported stack trace:
BUG: KASAN: use-after-free in atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
BUG: KASAN: use-after-free in atomic_fetch_add_unless include/linux/atomic.h:575 [inline]
BUG: KASAN: use-after-free in atomic_add_unless include/linux/atomic.h:597 [inline]
BUG: KASAN: use-after-free in dst_hold_safe include/net/dst.h:308 [inline]
BUG: KASAN: use-after-free in ip6_hold_safe+0xe6/0x670 net/ipv6/route.c:1029
Read of size 4 at addr ffff8801aea9a880 by task syz-executor129/4829

CPU: 0 PID: 4829 Comm: syz-executor129 Not tainted 4.18.0-rc7-next-20180802+ #30
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011
Call Trace:
 __dump_stack lib/dump_stack.c:77 [inline]
 dump_stack+0x1c9/0x2b4 lib/dump_stack.c:113
 print_address_description+0x6c/0x20b mm/kasan/report.c:256
 kasan_report_error mm/kasan/report.c:354 [inline]
 kasan_report.cold.7+0x242/0x30d mm/kasan/report.c:412
 check_memory_region_inline mm/kasan/kasan.c:260 [inline]
 check_memory_region+0x13e/0x1b0 mm/kasan/kasan.c:267
 kasan_check_read+0x11/0x20 mm/kasan/kasan.c:272
 atomic_read include/asm-generic/atomic-instrumented.h:21 [inline]
 atomic_fetch_add_unless include/linux/atomic.h:575 [inline]
 atomic_add_unless include/linux/atomic.h:597 [inline]
 dst_hold_safe include/net/dst.h:308 [inline]
 ip6_hold_safe+0xe6/0x670 net/ipv6/route.c:1029
 rt6_get_pcpu_route net/ipv6/route.c:1249 [inline]
 ip6_pol_route+0x354/0xd20 net/ipv6/route.c:1922
 ip6_pol_route_output+0x54/0x70 net/ipv6/route.c:2098
 fib6_rule_lookup+0x283/0x890 net/ipv6/fib6_rules.c:122
 ip6_route_output_flags+0x2c5/0x350 net/ipv6/route.c:2126
 ip6_dst_lookup_tail+0x1278/0x1da0 net/ipv6/ip6_output.c:978
 ip6_dst_lookup_flow+0xc8/0x270 net/ipv6/ip6_output.c:1079
 ip6_sk_dst_lookup_flow+0x5ed/0xc50 net/ipv6/ip6_output.c:1117
 udpv6_sendmsg+0x2163/0x36b0 net/ipv6/udp.c:1354
 inet_sendmsg+0x1a1/0x690 net/ipv4/af_inet.c:798
 sock_sendmsg_nosec net/socket.c:622 [inline]
 sock_sendmsg+0xd5/0x120 net/socket.c:632
 ___sys_sendmsg+0x51d/0x930 net/socket.c:2115
 __sys_sendmmsg+0x240/0x6f0 net/socket.c:2210
 __do_sys_sendmmsg net/socket.c:2239 [inline]
 __se_sys_sendmmsg net/socket.c:2236 [inline]
 __x64_sys_sendmmsg+0x9d/0x100 net/socket.c:2236
 do_syscall_64+0x1b9/0x820 arch/x86/entry/common.c:290
 entry_SYSCALL_64_after_hwframe+0x49/0xbe
RIP: 0033:0x446a29
Code: e8 ac b8 02 00 48 83 c4 18 c3 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 eb 08 fc ff c3 66 2e 0f 1f 84 00 00 00 00
RSP: 002b:00007f4de5532db8 EFLAGS: 00000246 ORIG_RAX: 0000000000000133
RAX: ffffffffffffffda RBX: 00000000006dcc38 RCX: 0000000000446a29
RDX: 00000000000000b8 RSI: 0000000020001b00 RDI: 0000000000000003
RBP: 00000000006dcc30 R08: 00007f4de5533700 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 00000000006dcc3c
R13: 00007ffe2b830fdf R14: 00007f4de55339c0 R15: 0000000000000001

Fixes: 71b1391a4128 ("l2tp: ensure sk->dst is still valid")
Reported-by: syzbot+05f840f3b04f211bad55@syzkaller.appspotmail.com
Signed-off-by: Wei Wang <weiwan@google.com>
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Cc: Guillaume Nault <g.nault@alphalink.fr>
Cc: David Ahern <dsahern@gmail.com>
Cc: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 net/l2tp/l2tp_core.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/net/l2tp/l2tp_core.c
+++ b/net/l2tp/l2tp_core.c
@@ -1110,7 +1110,7 @@ int l2tp_xmit_skb(struct l2tp_session *s
 
 	/* Get routing info from the tunnel socket */
 	skb_dst_drop(skb);
-	skb_dst_set(skb, dst_clone(__sk_dst_check(sk, 0)));
+	skb_dst_set(skb, sk_dst_check(sk, 0));
 
 	inet = inet_sk(sk);
 	fl = &inet->cork.fl;



  reply	other threads:[~2018-08-21  6:22 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-21  6:20 [PATCH 4.18 00/35] 4.18.4-stable review Greg Kroah-Hartman
2018-08-21  6:20 ` Greg Kroah-Hartman [this message]
2018-08-21  6:20 ` [PATCH 4.18 02/35] net_sched: fix NULL pointer dereference when delete tcindex filter Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 03/35] net_sched: Fix missing res info when create new tc_index filter Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 04/35] r8169: dont use MSI-X on RTL8168g Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 05/35] ALSA: hda - Sleep for 10ms after entering D3 on Conexant codecs Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 06/35] ALSA: hda - Turn CX8200 into D3 as well upon reboot Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 07/35] ALSA: vx222: Fix invalid endian conversions Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 08/35] ALSA: virmidi: Fix too long output trigger loop Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 09/35] ALSA: cs5535audio: Fix invalid endian conversion Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 10/35] ALSA: dice: fix wrong copy to rx parameters for Alesis iO26 Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 11/35] ALSA: hda: Correct Asrock B85M-ITX power_save blacklist entry Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 12/35] ALSA: memalloc: Dont exceed over the requested size Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 13/35] ALSA: vxpocket: Fix invalid endian conversions Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 14/35] ALSA: seq: Fix poll() error return Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 16/35] USB: serial: sierra: fix potential deadlock at close Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 17/35] USB: serial: pl2303: add a new device id for ATEN Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 18/35] USB: option: add support for DW5821e Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 19/35] ACPI / PM: save NVS memory for ASUS 1025C laptop Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 20/35] tty: serial: 8250: Revert NXP SC16C2552 workaround Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 21/35] serial: 8250_exar: Read INT0 from slave device, too Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 22/35] serial: 8250_dw: always set baud rate in dw8250_set_termios Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 23/35] serial: 8250_dw: Add ACPI support for uart on Broadcom SoC Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 24/35] uio: fix wrong return value from uio_mmap() Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 25/35] misc: sram: fix resource leaks in probe error path Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 26/35] Revert "uio: use request_threaded_irq instead" Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 27/35] Bluetooth: avoid killing an already killed socket Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 28/35] isdn: Disable IIOCDBGVAR Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 29/35] net: sock_diag: Fix spectre v1 gadget in __sock_diag_cmd() Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 30/35] hv/netvsc: Fix NULL dereference at single queue mode fallback Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 31/35] r8169: dont use MSI-X on RTL8106e Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 32/35] ip_vti: fix a null pointer deferrence when create vti fallback tunnel Greg Kroah-Hartman
2018-08-21  6:20 ` [PATCH 4.18 33/35] net: ethernet: mvneta: Fix napi structure mixup on armada 3700 Greg Kroah-Hartman
2018-08-21  6:21 ` [PATCH 4.18 34/35] net: mvneta: fix mvneta_config_rss " Greg Kroah-Hartman
2018-08-21  6:21 ` [PATCH 4.18 35/35] cls_matchall: fix tcf_unbind_filter missing Greg Kroah-Hartman
2018-08-21 14:59 ` [PATCH 4.18 00/35] 4.18.4-stable review Guenter Roeck
2018-08-21 20:02   ` Greg Kroah-Hartman
2018-08-21 18:03 ` Naresh Kamboju
2018-08-21 20:03   ` Greg Kroah-Hartman
2018-08-21 19:43 ` Shuah Khan
2018-08-21 20:03   ` Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180821055020.031044093@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=g.nault@alphalink.fr \
    --cc=kafai@fb.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+05f840f3b04f211bad55@syzkaller.appspotmail.com \
    --cc=weiwan@google.com \
    --cc=xiyou.wangcong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).