Commit 4ba0ab98 authored by Cong Wang's avatar Cong Wang Committed by sanglipeng
Browse files

l2tp: close all race conditions in l2tp_tunnel_register()

stable inclusion
from stable-v5.10.166
commit 2d77e5c0ad79004b5ef901895437e9cce6dfcc7e
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I87FRA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=2d77e5c0ad79004b5ef901895437e9cce6dfcc7e



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

[ Upstream commit 0b2c5972 ]

The code in l2tp_tunnel_register() is racy in several ways:

1. It modifies the tunnel socket _after_ publishing it.

2. It calls setup_udp_tunnel_sock() on an existing socket without
   locking.

3. It changes sock lock class on fly, which triggers many syzbot
   reports.

This patch amends all of them by moving socket initialization code
before publishing and under sock lock. As suggested by Jakub, the
l2tp lockdep class is not necessary as we can just switch to
bh_lock_sock_nested().

Fixes: 37159ef2 ("l2tp: fix a lockdep splat")
Fixes: 6b9f3423 ("l2tp: fix races in tunnel creation")
Reported-by: default avatar <syzbot+52866e24647f9a23403f@syzkaller.appspotmail.com>
Reported-by: default avatar <syzbot+94cc2a66fc228b23f360@syzkaller.appspotmail.com>
Reported-by: default avatarTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Guillaume Nault <gnault@redhat.com>
Cc: Jakub Sitnicki <jakub@cloudflare.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Tom Parkin <tparkin@katalix.com>
Signed-off-by: default avatarCong Wang <cong.wang@bytedance.com>
Reviewed-by: default avatarGuillaume Nault <gnault@redhat.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent 39d5a3f1
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment