Re: [GIT PULL] tracing: Fix double free bug

From: Steven Rostedt
Date: Wed Nov 17 2021 - 19:00:48 EST


On Wed, 17 Nov 2021 15:38:59 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Wed, Nov 17, 2021 at 3:19 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
> >
> > On error, the operands and the histogram expression are destroyed,
> > but since the destruction is recursive, do not destroy the operands
> > if they already belong to the expression that is about to be destroyed.
>
> Honestly, this seems horribly ugly.

I guess we have a difference in opinion to what is ugly, as the v1 version
of Kalesh's patch was closer to yours, and I hated the complexity of having
to know when to to call what. Because the logic is not that simple.

See https://lore.kernel.org/all/20211117021223.2137117-1-kaleshsingh@xxxxxxxxxx/

>
> The problem seems to be that the "goto error" cases are simply just wrong.
>
> Why isn't the fix to make the error cases be the right ones, instead
> of having one odd error case that then has to do some magic things to
> not free the wrong things?
>
> The patch ends up a bit bigger, mainly because I renamed the different
> "free" cases, and because I made the non-freeing ones just return the
> error directly.

I agree with the first part of your patch, which was not the reason for
being the cause of the bug.

>
> Something like this (UNTESTED!) patch, IOW?

But the part after the expr is allocated gets a bit more tricky, and that
is why I requested that logic, namely due to the "combine_consts" case. But
as the expr->operand[]s are NULL'd and the operand*s are destroyed, I guess
it's still fine with just freeing the expr if we add an error case there.

Kalesh, care to spin a v3 implementing Linus's solution?

-- Steve