Re: [PATCH 2/3] kunit: Add kunit_move_action_to_top_or_reset() to reorder actions

Maxime Ripard
2023-09-25T10:13:45Z

Hi David,

On Fri, Sep 22, 2023 at 04:00:21PM +0800, David Gow wrote:
> On Wed, 20 Sept 2023 at 14:12, Arthur Grillo <arthurgrillo@riseup.net> wrote:
> >
> > On Kunit, if we allocate a resource A and B on this order, with its
> > deferred actions to free them. The resource stack would be something
> > like this:
> >
> > +---------+
> > | free(B) |
> > +---------+
> > | ... |
> > +---------+
> > | free(A) |
> > +---------+
> >
> > If the deferred action of A accesses B, this would cause a
> > use-after-free bug. To solve that, we need a way to change the order
> > of actions.
> >
> > Create a function to move an action to the top of the resource stack,
> > as shown in the diagram below.
> >
> > +---------+ +---------+
> > | free(B) | | free(A) |
> > +---------+ +---------+
> > | ... | -> | free(B) |
> > +---------+ +---------+
> > | free(A) | | ... |
> > +---------+ +---------+
> >
> > Signed-off-by: Arthur Grillo <arthurgrillo@riseup.net>
> > ---
>
> Thanks. This is a really interesting patch: my hope was that something
> like this wouldn't be necessary, as in most cases freeing things in
> the reverse order to which they were created is the right thing to do.
>
> It looks like, from the comments on patch 3, this may no longer be
> necessary? Is that so?

Yeah, it's no longer necessary

Maxime