[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHC9VhQeo6_mie65AH5bzV9484UWsPQA6kz67ZR7_WSfBQ-3cQ@mail.gmail.com>
Date: Tue, 16 Jun 2020 20:27:54 -0400
From: Paul Moore <paul@...l-moore.com>
To: trix@...hat.com
Cc: Stephen Smalley <stephen.smalley.work@...il.com>,
Eric Paris <eparis@...isplace.org>,
Ondrej Mosnacek <omosnace@...hat.com>, weiyongjun1@...wei.com,
selinux@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v3] selinux: fix another double free
On Mon, Jun 15, 2020 at 4:45 PM <trix@...hat.com> wrote:
> From: Tom Rix <trix@...hat.com>
>
> Clang static analysis reports this double free error
>
> security/selinux/ss/conditional.c:139:2: warning: Attempt to free released memory [unix.Malloc]
> kfree(node->expr.nodes);
> ^~~~~~~~~~~~~~~~~~~~~~~
>
> When cond_read_node fails, it calls cond_node_destroy which frees the
> node but does not poison the entry in the node list. So when it
> returns to its caller cond_read_list, cond_read_list deletes the
> partial list. The latest entry in the list will be deleted twice.
>
> So instead of freeing the node in cond_read_node, let list freeing in
> code_read_list handle the freeing the problem node along with all of the
> earlier nodes.
>
> Because cond_read_node no longer does any error handling, the goto's
> the error case are redundant. Instead just return the error code.
>
> Fixes: 60abd3181db2 ("selinux: convert cond_list to array")
>
> Signed-off-by: Tom Rix <trix@...hat.com>
> ---
> v3: simplify returns
>
> security/selinux/ss/conditional.c | 18 +++++-------------
> 1 file changed, 5 insertions(+), 13 deletions(-)
Merged into selinux/stable-5.8 with a better subject line. Thanks for
catching this and submitting the fix. Assuming everything goes well
I'll send this up to Linus later this week.
It might be nice to do a follow-up patch for selinux/next which folds
cond_node_destroy() into cond_list_destroy() as there is no longer a
need for that code to be in a separate function.
--
paul moore
www.paul-moore.com
Powered by blists - more mailing lists