Commit 1aa646ac authored by Tom Parkin's avatar Tom Parkin Committed by David S. Miller

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: default avatarTom Parkin <tparkin@katalix.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent cd3e29b3
...@@ -163,8 +163,11 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk) ...@@ -163,8 +163,11 @@ static inline struct l2tp_session *pppol2tp_sock_to_session(struct sock *sk)
sock_put(sk); sock_put(sk);
goto out; goto out;
} }
if (WARN_ON(session->magic != L2TP_SESSION_MAGIC)) {
BUG_ON(session->magic != L2TP_SESSION_MAGIC); session = NULL;
sock_put(sk);
goto out;
}
out: out:
return session; return session;
...@@ -419,7 +422,8 @@ static void pppol2tp_session_destruct(struct sock *sk) ...@@ -419,7 +422,8 @@ static void pppol2tp_session_destruct(struct sock *sk)
if (session) { if (session) {
sk->sk_user_data = NULL; sk->sk_user_data = NULL;
BUG_ON(session->magic != L2TP_SESSION_MAGIC); if (WARN_ON(session->magic != L2TP_SESSION_MAGIC))
return;
l2tp_session_dec_refcount(session); l2tp_session_dec_refcount(session);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment