Skip to content

Commit 1aa646a

Browse files
tomparkindavem330
authored andcommitted
l2tp: don't BUG_ON session magic checks in l2tp_ppp
checkpatch advises that WARN_ON and recovery code are preferred over BUG_ON which crashes the kernel. l2tp_ppp.c's BUG_ON checks of the l2tp session structure's "magic" field occur in code paths where it's reasonably easy to recover: * In the case of pppol2tp_sock_to_session, we can return NULL and the caller will bail out appropriately. There is no change required to any of the callsites of this function since they already handle pppol2tp_sock_to_session returning NULL. * In the case of pppol2tp_session_destruct we can just avoid decrementing the reference count on the suspect session structure. In the worst case scenario this results in a memory leak, which is preferable to a crash. Convert these uses of BUG_ON to WARN_ON accordingly. Signed-off-by: Tom Parkin <tparkin@katalix.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent cd3e29b commit 1aa646a

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

‎net/l2tp/l2tp_ppp.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
163163
sock_put(sk);
164164
goto out;
165165
}
166-
167-
BUG_ON(session->magic != L2TP_SESSION_MAGIC);
166+
if (WARN_ON(session->magic != L2TP_SESSION_MAGIC)) {
167+
session = NULL;
168+
sock_put(sk);
169+
goto out;
170+
}
168171

169172
out:
170173
return session;
@@ -419,7 +422,8 @@ static void pppol2tp_session_destruct(struct sock *sk)
419422

420423
if (session) {
421424
sk->sk_user_data = NULL;
422-
BUG_ON(session->magic != L2TP_SESSION_MAGIC);
425+
if (WARN_ON(session->magic != L2TP_SESSION_MAGIC))
426+
return;
423427
l2tp_session_dec_refcount(session);
424428
}
425429
}

0 commit comments

Comments
 (0)