From: Bill O'Donnell <bodonnel@redhat.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: linux-xfs@vger.kernel.org, cem@kernel.org, djwong@kernel.org
Subject: Re: [PATCH] xfsdump: prevent use-after-free in fstab_commit()
Date: Thu, 29 Aug 2024 17:48:37 -0500 [thread overview]
Message-ID: <ZtD6xQmXRd9BF0HE@redhat.com> (raw)
In-Reply-To: <5e5e4f37-2cac-416c-844e-1b2bbb426f91@sandeen.net>
On Thu, Aug 29, 2024 at 04:56:01PM -0500, Eric Sandeen wrote:
> On 8/29/24 3:34 PM, Bill O'Donnell wrote:
> > On Thu, Aug 29, 2024 at 02:47:24PM -0500, Bill O'Donnell wrote:
>
> ...
>
> >>>> + free(list_cpy);
> >>>
> >>> and then this would double-free that same memory address.
> >>
> >> I see that now. This code is indeed difficult to grok.
> >>
> >> Perhaps (if this a legitimate finding of use after free), instead of having the memory
> >> freed in invidx_commit(), it should instead be freed once in fstab_commit() after the iterations
> >> of the for-loops in that function. I'll have a look at that possibility.
> >
> > i.e., Removing what Coverity tags as the culprit (node_free(list_del(dst_n)) from
> > invidx_commit(), and adding free(list) following the for-loop iteration in fstab_commit() may be
> > a better solution.
>
> I don't think that's the right approach.
>
> invidx_commit() has this while loop, which is where coverity thinks the passed-in "list"
> might get freed, before the caller uses it again:
>
> /* Clean up the mess we just created */
> /* find node for dst_fileidx */
> dst_n = find_invidx_node(list, dst_fileidx);
> tmp_parent = ((data_t *)(dst_n->data))->parent;
> while(dst_n != NULL) {
> node_t *tmp_n1;
>
> dst_d = dst_n->data;
>
> /* close affected invidx file and stobj files */
> for(i = 0; i < dst_d->nbr_children; i++) {
> close_stobj_file(((data_t *)(dst_d->children[i]->data))->file_idx, BOOL_FALSE);
> }
>
> /* free_all_children on that node */
> free_all_children(dst_n);
> tmp_n1 = find_invidx_node(dst_n->next, dst_fileidx);
> node_free(list_del(dst_n));
> dst_n = tmp_n1;
> }
>
> "list" is presumably the head of a list of items, and this is cleaning up / freeing items
> within that list. Coverity seems to think that the while loop can end up getting back to
> the head and freeing it, which the caller then uses again in a loop.
>
> My guess is that coverity is wrong, but I don't think you're going to be able to prove that
> (or fix this) without at least getting a sense of what this code is actually doing, and
> how this list is shaped and managed...
That's my take on it as well. I'm leaning towards a false positive. I'll have another look.
Thanks for reviewing.
-Bill
next prev parent reply other threads:[~2024-08-29 22:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-29 17:59 [PATCH] xfsdump: prevent use-after-free in fstab_commit() Bill O'Donnell
2024-08-29 19:35 ` Eric Sandeen
2024-08-29 19:47 ` Bill O'Donnell
2024-08-29 20:34 ` Bill O'Donnell
2024-08-29 21:56 ` Eric Sandeen
2024-08-29 22:48 ` Bill O'Donnell [this message]
[not found] ` <SA1PR10MB758637A0D3EE774C9DF5B94489972@SA1PR10MB7586.namprd10.prod.outlook.com>
2024-08-30 15:56 ` [External] : " Eric Sandeen
2024-08-30 15:48 ` Bill O'Donnell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZtD6xQmXRd9BF0HE@redhat.com \
--to=bodonnel@redhat.com \
--cc=cem@kernel.org \
--cc=djwong@kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox