Thread (15 messages) 15 messages, 5 authors, 2024-10-08

Re: [PATCH v2 5/8] net: af_can: do not leave a dangling sk pointer in can_create()

flat view

From: Vincent MAILHOL <hidden>
Date: 2024-10-08 02:38:01
Also in: linux-bluetooth, linux-can, lkml

Hi Ignat,

Thanks for the patch.

On Tue. 8 Oct. 2024 at 06:37, Ignat Korchagin [off-list ref] wrote:
On error can_create() frees the allocated sk object, but sock_init_data()
has already attached it to the provided sock object. This will leave a
dangling sk pointer in the sock object and may cause use-after-free later.
I was about to suggest that this should be backported to stable, but
after reading the cover letter, I now understand that this patch is
more an improvement to avoid false positives on kmemleak & Cie. Maybe
the description could be a bit more nuanced? After patch 1/8 of this
series, it seems that the use-after-free is not possible anymore.
Signed-off-by: Ignat Korchagin <redacted>
See above comment as notwithstanding. This said:

Reviewed-by: Vincent Mailhol <redacted>

quoted hunk ↗ jump to hunk
---
 net/can/af_can.c | 1 +
 1 file changed, 1 insertion(+)
diff --git a/net/can/af_can.c b/net/can/af_can.c
index 707576eeeb58..01f3fbb3b67d 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -171,6 +171,7 @@ static int can_create(struct net *net, struct socket *sock, int protocol,
                /* release sk on errors */
                sock_orphan(sk);
                sock_put(sk);
+               sock->sk = NULL;
        }

  errout:
--
2.39.5
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help