From: Jan Kara <jack@suse.cz>
To: Paul Moore <paul@paul-moore.com>
Cc: Jan Kara <jack@suse.cz>, Gaosheng Cui <cuigaosheng1@huawei.com>,
eparis@redhat.com, mszeredi@redhat.com, amir73il@gmail.com,
linux-audit@redhat.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH next] audit: fix potential double free on error path from fsnotify_add_inode_mark
Date: Mon, 22 Aug 2022 17:20:55 +0200 [thread overview]
Message-ID: <20220822152055.hitwrvi3lmldhcgx@quack3> (raw)
In-Reply-To: <CAHC9VhSw0zJWQEm-GCzQy_-4-X-yVuzvX1wBFcYMkG1mOXy+BA@mail.gmail.com>
On Mon 22-08-22 10:34:15, Paul Moore wrote:
> On Mon, Aug 22, 2022 at 4:50 AM Jan Kara <jack@suse.cz> wrote:
> > On Mon 22-08-22 10:29:05, Gaosheng Cui wrote:
> > > Audit_alloc_mark() assign pathname to audit_mark->path, on error path
> > > from fsnotify_add_inode_mark(), fsnotify_put_mark will free memory
> > > of audit_mark->path, but the caller of audit_alloc_mark will free
> > > the pathname again, so there will be double free problem.
> > >
> > > Fix this by resetting audit_mark->path to NULL pointer on error path
> > > from fsnotify_add_inode_mark().
> > >
> > > Fixes: 7b1293234084d ("fsnotify: Add group pointer in fsnotify_init_mark()")
> > > Signed-off-by: Gaosheng Cui <cuigaosheng1@huawei.com>
> >
> > Good spotting! The patch looks good to me. Feel free to add:
> >
> > Reviewed-by: Jan Kara <jack@suse.cz>
> >
> > > ---
> > > kernel/audit_fsnotify.c | 1 +
> > > 1 file changed, 1 insertion(+)
> > >
> > > diff --git a/kernel/audit_fsnotify.c b/kernel/audit_fsnotify.c
> > > index 6432a37ac1c9..c565fbf66ac8 100644
> > > --- a/kernel/audit_fsnotify.c
> > > +++ b/kernel/audit_fsnotify.c
> > > @@ -102,6 +102,7 @@ struct audit_fsnotify_mark *audit_alloc_mark(struct audit_krule *krule, char *pa
> > >
> > > ret = fsnotify_add_inode_mark(&audit_mark->mark, inode, 0);
> > > if (ret < 0) {
> > > + audit_mark->path = NULL;
> > > fsnotify_put_mark(&audit_mark->mark);
>
> As I'm tracing the code path from audit through fsnotify, and back
> into audit, I'm wondering if we still have a problem. When
> fsnotify_add_inode_mark() fails it will end up freeing not just
> audit_mark->path, but audit_mark itself via audit_fsnotify_mark_free()
> (via a call into fsnotify_put_mark()), yes?
I don't think so. fsnotify_add_mark_locked() will call fsnotify_put_mark()
but that is just a counter part to fsnotify_get_mark() a few lines above.
The caller of fsnotify_add_inode_mark() still holds its own mark reference
which prevents mark from being freed.
Honza
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2022-08-22 15:25 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-22 2:29 Gaosheng Cui
2022-08-22 8:50 ` Jan Kara
2022-08-22 14:34 ` Paul Moore
2022-08-22 15:20 ` Jan Kara [this message]
2022-08-22 17:39 ` Paul Moore
2022-08-22 17:59 ` Jan Kara
2022-08-22 22:49 ` Paul Moore
2022-08-23 2:06 ` cuigaosheng
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=20220822152055.hitwrvi3lmldhcgx@quack3 \
--to=jack@suse.cz \
--cc=amir73il@gmail.com \
--cc=cuigaosheng1@huawei.com \
--cc=eparis@redhat.com \
--cc=linux-audit@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mszeredi@redhat.com \
--cc=paul@paul-moore.com \
/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
all inboxes | Powered by JetHome®