Re: [PATCH AUTOSEL 5.10 41/46] net/rds: Avoid potential use after free in rds_send_remove_from_sock
From: Pavel Machek
Date: Mon Apr 19 2021 - 04:49:59 EST
Hi!
> From: Aditya Pakki <pakki001@xxxxxxx>
>
> [ Upstream commit 0c85a7e87465f2d4cbc768e245f4f45b2f299b05 ]
>
> In case of rs failure in rds_send_remove_from_sock(), the 'rm' resource
> is freed and later under spinlock, causing potential use-after-free.
> Set the free pointer to NULL to avoid undefined behavior.
This patch is crazy. It adds dead code.
> +++ b/net/rds/message.c
> @@ -180,6 +180,7 @@ void rds_message_put(struct rds_message *rm)
> rds_message_purge(rm);
>
> kfree(rm);
> + rm = NULL;
> }
> }
We are already exiting function, changing local variable has no
effect.
> +++ b/net/rds/send.c
> @@ -665,7 +665,7 @@ static void rds_send_remove_from_sock(struct list_head *messages, int status)
> unlock_and_drop:
> spin_unlock_irqrestore(&rm->m_rs_lock, flags);
> rds_message_put(rm);
> - if (was_on_sock)
> + if (was_on_sock && rm)
> rds_message_put(rm);
> }
If rm was non-NULL calling first rds_message_put (and it was,
otherwise we oopsed), it is still non-NULL in second test.
Best regards,
Pavel
--
'DENX Software Engineering GmbH, Managing Director: Wolfgang Denk'
'HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany'
Attachment:
signature.asc
Description: Digital signature