Re: [PATCH] keys/keyctl: Use kfree_rcu instead of kfree

From: Greg KH
Date: Sat Jul 23 2022 - 10:43:24 EST


On Sat, Jul 23, 2022 at 08:05:27PM +0530, Siddh Raman Pant wrote:
> On Sat, 23 Jul 2022 19:35:16 +0530 Greg KH <gregkh@xxxxxxxxxxxxxxxxxxx> wrote:
> > That does not explain why this change is needed. What problem does this
> > solve? Why use RCU if you don't have to? What functionality did you
> > just change in this commit and why?
>
> We can avoid a race condition wherein some process tries to access them while
> they are being freed. For instance, the comment on `watch_queue_clear()` also
> states that:
> /*
> * Remove all the watches that are contributory to a queue. This has the
> * potential to race with removal of the watches by the destruction of the
> * objects being watched or with the distribution of notifications.
> */
> And an RCU read critical section is initiated in that function, so we should
> use kfree_rcu() to not unintentionally free it while it is in the critical
> section.

You need to explain all of this in a changelog text. Don't say what you
do, but say why you are doing it.

> > And how was this tested?
>
> It compiles locally for me, and I used syzbot on this along with testing the
> other `watch_queue_clear` patch, which generated no errors.

How does the watch queue stuff relate to this keyctl logic?

Again, be specific as to why you are doing things.

thanks,

greg k-h