linux-can.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] can: fix a potential UAF access in j1939_session_deactivate()
@ 2021-07-13 20:21 Xiaochen Zou
  2021-07-14  6:49 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaochen Zou @ 2021-07-13 20:21 UTC (permalink / raw)
  To: greg; +Cc: stable, netdev, linux-can

[-- Attachment #1: Type: text/plain, Size: 1126 bytes --]


Xiaochen Zou (1):
  can: fix a potential UAF access in j1939_session_deactivate(). Both
    session and session->priv may be freed in
    j1939_session_deactivate_locked(). It leads to potential UAF read
    and write in j1939_session_list_unlock(). The free chain is

j1939_session_deactivate_locked()->j1939_session_put()->__j1939_session_release()->j1939_session_destroy().
    To fix this bug, I moved j1939_session_put() behind
    j1939_session_deactivate_locked(), and guarded it with a check of
    active since the session would be freed only if active is true.

 net/can/j1939/transport.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

-- 
2.17.1

From 9c4733d093e05db22eb89825579c83e020c3c1a6 Mon Sep 17 00:00:00 2001
From: Xiaochen Zou <xzou017@ucr.edu>
Date: Tue, 13 Jul 2021 13:15:59 -0700
Subject: [PATCH 1/1] can: fix a potential UAF access in
 j1939_session_deactivate().
To: greg@kroah.com
Cc: stable@vger.kernel.org,netdev@vger.kernel.org,linux-can@vger.kernel.org
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.17.1"

This is a multi-part message in MIME format.

[-- Attachment #2: Attached Message Part --]
[-- Type: text/plain, Size: 620 bytes --]

Both session and session->priv may be freed in
j1939_session_deactivate_locked(). It leads to potential UAF read and write
in j1939_session_list_unlock(). The free chain is
j1939_session_deactivate_locked()->j1939_session_put()->__j1939_session_release()->j1939_session_destroy().
To fix this bug, I moved j1939_session_put() behind
j1939_session_deactivate_locked(), and guarded it with a check of active
since the session would be freed only if active is true.
 
Signed-off-by: Xiaochen Zou <xzou017@ucr.edu>
---
 net/can/j1939/transport.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)



[-- Attachment #3: 0001-can-fix-a-potential-UAF-access-in-j1939_session_deac.patch --]
[-- Type: text/x-patch, Size: 1387 bytes --]

diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index c3946c355882..c64bd5e8118a 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -1067,7 +1067,6 @@ static bool j1939_session_deactivate_locked(struct j1939_session *session)
 
 		list_del_init(&session->active_session_list_entry);
 		session->state = J1939_SESSION_DONE;
-		j1939_session_put(session);
 	}
 
 	return active;
@@ -1080,6 +1079,8 @@ static bool j1939_session_deactivate(struct j1939_session *session)
 	j1939_session_list_lock(session->priv);
 	active = j1939_session_deactivate_locked(session);
 	j1939_session_list_unlock(session->priv);
+	if (active)
+		j1939_session_put(session);
 
 	return active;
 }
@@ -2127,6 +2128,7 @@ void j1939_simple_recv(struct j1939_priv *priv, struct sk_buff *skb)
 int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk)
 {
 	struct j1939_session *session, *saved;
+	bool active;
 
 	netdev_dbg(priv->ndev, "%s, sk: %p\n", __func__, sk);
 	j1939_session_list_lock(priv);
@@ -2140,7 +2142,9 @@ int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk)
 				j1939_session_put(session);
 
 			session->err = ESHUTDOWN;
-			j1939_session_deactivate_locked(session);
+			active = j1939_session_deactivate_locked(session);
+			if (active)
+				j1939_session_put(session);
 		}
 	}
 	j1939_session_list_unlock(priv);


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 0/1] can: fix a potential UAF access in j1939_session_deactivate()
  2021-07-13 20:21 [PATCH 0/1] can: fix a potential UAF access in j1939_session_deactivate() Xiaochen Zou
@ 2021-07-14  6:49 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2021-07-14  6:49 UTC (permalink / raw)
  To: Xiaochen Zou; +Cc: stable, netdev, linux-can

On Tue, Jul 13, 2021 at 01:21:44PM -0700, Xiaochen Zou wrote:
> 
> Xiaochen Zou (1):
>   can: fix a potential UAF access in j1939_session_deactivate(). Both
>     session and session->priv may be freed in
>     j1939_session_deactivate_locked(). It leads to potential UAF read
>     and write in j1939_session_list_unlock(). The free chain is
> 
> j1939_session_deactivate_locked()->j1939_session_put()->__j1939_session_release()->j1939_session_destroy().
>     To fix this bug, I moved j1939_session_put() behind
>     j1939_session_deactivate_locked(), and guarded it with a check of
>     active since the session would be freed only if active is true.
> 
>  net/can/j1939/transport.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> -- 
> 2.17.1


Hi,

This is the friendly patch-bot of Greg Kroah-Hartman.  You have sent him
a patch that has triggered this response.  He used to manually respond
to these common problems, but in order to save his sanity (he kept
writing the same thing over and over, yet to different people), I was
created.  Hopefully you will not take offence and will fix the problem
in your patch and resubmit it so that it can be accepted into the Linux
kernel tree.

You are receiving this message because of the following common error(s)
as indicated below:

- Your patch was attached, please place it inline so that it can be
  applied directly from the email message itself.

If you wish to discuss this problem further, or you have questions about
how to resolve this issue, please feel free to respond to this email and
Greg will reply once he has dug out from the pending patches received
from other developers.

thanks,

greg k-h's patch email bot

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-07-14  6:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 20:21 [PATCH 0/1] can: fix a potential UAF access in j1939_session_deactivate() Xiaochen Zou
2021-07-14  6:49 ` Greg KH

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).