Message ID | 20240806160626.1248317-1-jchapman@katalix.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 86a41ea9fd79ddb6145cb8ebf5aeafceabca6f7d |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [net] l2tp: fix lockdep splat | expand |
Hello: This patch was applied to netdev/net.git (main) by Jakub Kicinski <kuba@kernel.org>: On Tue, 6 Aug 2024 17:06:26 +0100 you wrote: > When l2tp tunnels use a socket provided by userspace, we can hit > lockdep splats like the below when data is transmitted through another > (unrelated) userspace socket which then gets routed over l2tp. > > This issue was previously discussed here: > https://lore.kernel.org/netdev/87sfialu2n.fsf@cloudflare.com/ > > [...] Here is the summary with links: - [net] l2tp: fix lockdep splat https://git.kernel.org/netdev/net/c/86a41ea9fd79 You are awesome, thank you!
On Tue, Aug 06, 2024 at 05:06:26PM +0100, James Chapman wrote: > diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c > index c80ab3f26084..2e86f520f799 100644 > --- a/net/l2tp/l2tp_core.c > +++ b/net/l2tp/l2tp_core.c > @@ -86,6 +86,11 @@ > /* Default trace flags */ > #define L2TP_DEFAULT_DEBUG_FLAGS 0 > > +#define L2TP_DEPTH_NESTING 2 > +#if L2TP_DEPTH_NESTING == SINGLE_DEPTH_NESTING > +#error "L2TP requires its own lockdep subclass" > +#endif This looks a bit over-engineering. Why not just #define L2TP_DEPTH_NESTING SINGLE_DEPTH_NESTING+1? Thanks.
diff --git a/net/l2tp/l2tp_core.c b/net/l2tp/l2tp_core.c index c80ab3f26084..2e86f520f799 100644 --- a/net/l2tp/l2tp_core.c +++ b/net/l2tp/l2tp_core.c @@ -86,6 +86,11 @@ /* Default trace flags */ #define L2TP_DEFAULT_DEBUG_FLAGS 0 +#define L2TP_DEPTH_NESTING 2 +#if L2TP_DEPTH_NESTING == SINGLE_DEPTH_NESTING +#error "L2TP requires its own lockdep subclass" +#endif + /* Private data stored for received packets in the skb. */ struct l2tp_skb_cb { @@ -1124,7 +1129,13 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED | IPSKB_REROUTED); nf_reset_ct(skb); - bh_lock_sock_nested(sk); + /* L2TP uses its own lockdep subclass to avoid lockdep splats caused by + * nested socket calls on the same lockdep socket class. This can + * happen when data from a user socket is routed over l2tp, which uses + * another userspace socket. + */ + spin_lock_nested(&sk->sk_lock.slock, L2TP_DEPTH_NESTING); + if (sock_owned_by_user(sk)) { kfree_skb(skb); ret = NET_XMIT_DROP; @@ -1176,7 +1187,7 @@ static int l2tp_xmit_core(struct l2tp_session *session, struct sk_buff *skb, uns ret = l2tp_xmit_queue(tunnel, skb, &inet->cork.fl); out_unlock: - bh_unlock_sock(sk); + spin_unlock(&sk->sk_lock.slock); return ret; }