From: Greg KH <gregkh@linuxfoundation.org>
To: Anirudh Rayabharam <mail@anirudhrb.com>
Cc: shaggy@kernel.org, jfs-discussion@lists.sourceforge.net,
linux-kernel@vger.kernel.org,
linux-kernel-mentees@lists.linuxfoundation.org,
syzbot+5d2008bd1f1b722ba94e@syzkaller.appspotmail.com,
Hillf Danton <hdanton@sina.com>
Subject: Re: [PATCH resend] jfs: fix use-after-free in lbmIODone
Date: Fri, 26 Mar 2021 14:56:30 +0100 [thread overview]
Message-ID: <YF3oDrnN3RJBFQ0P@kroah.com> (raw)
In-Reply-To: <20210322161147.5593-1-mail@anirudhrb.com>
On Mon, Mar 22, 2021 at 09:41:47PM +0530, Anirudh Rayabharam wrote:
> Fix use-after-free by waiting for ongoing IO to complete before freeing
> lbufs in lbmLogShutdown. Add a counter in struct jfs_log to keep track
> of the number of in-flight IO operations and a wait queue to wait on for
> the IO operations to complete.
>
> Reported-by: syzbot+5d2008bd1f1b722ba94e@syzkaller.appspotmail.com
> Suggested-by: Hillf Danton <hdanton@sina.com>
> Signed-off-by: Anirudh Rayabharam <mail@anirudhrb.com>
> ---
> fs/jfs/jfs_logmgr.c | 17 ++++++++++++++---
> fs/jfs/jfs_logmgr.h | 2 ++
> 2 files changed, 16 insertions(+), 3 deletions(-)
>
> diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c
> index 9330eff210e0..82d20c4687aa 100644
> --- a/fs/jfs/jfs_logmgr.c
> +++ b/fs/jfs/jfs_logmgr.c
> @@ -1815,6 +1815,8 @@ static int lbmLogInit(struct jfs_log * log)
> */
> init_waitqueue_head(&log->free_wait);
>
> + init_waitqueue_head(&log->io_waitq);
> +
> log->lbuf_free = NULL;
>
> for (i = 0; i < LOGPAGES;) {
> @@ -1864,6 +1866,7 @@ static void lbmLogShutdown(struct jfs_log * log)
> struct lbuf *lbuf;
>
> jfs_info("lbmLogShutdown: log:0x%p", log);
> + wait_event(log->io_waitq, !atomic_read(&log->io_inflight));
>
> lbuf = log->lbuf_free;
> while (lbuf) {
> @@ -1990,6 +1993,8 @@ static int lbmRead(struct jfs_log * log, int pn, struct lbuf ** bpp)
> bio->bi_end_io = lbmIODone;
> bio->bi_private = bp;
> bio->bi_opf = REQ_OP_READ;
> +
> + atomic_inc(&log->io_inflight);
> /*check if journaling to disk has been disabled*/
> if (log->no_integrity) {
> bio->bi_iter.bi_size = 0;
> @@ -2135,6 +2140,7 @@ static void lbmStartIO(struct lbuf * bp)
> bio->bi_private = bp;
> bio->bi_opf = REQ_OP_WRITE | REQ_SYNC;
>
> + atomic_inc(&log->io_inflight);
Why use an atomic for this? The value can change after you test for it,
as there's no lock involved.
Do you really need to keep track of all of these "inflight"? That feels
very "heavy" to me.
jfs developers, any ideas?
thanks,
greg k-h
prev parent reply other threads:[~2021-03-26 13:57 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-22 16:11 Anirudh Rayabharam
2021-03-26 13:56 ` Greg KH [this message]
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=YF3oDrnN3RJBFQ0P@kroah.com \
--to=gregkh@linuxfoundation.org \
--cc=hdanton@sina.com \
--cc=jfs-discussion@lists.sourceforge.net \
--cc=linux-kernel-mentees@lists.linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@anirudhrb.com \
--cc=shaggy@kernel.org \
--cc=syzbot+5d2008bd1f1b722ba94e@syzkaller.appspotmail.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®