From: Eric Biggers <ebiggers@kernel.org>
To: Chao Yu <yuchao0@huawei.com>
Cc: jaegeuk@kernel.org, linux-kernel@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net
Subject: Re: [f2fs-dev] [PATCH 3/4] f2fs: fix NULL pointer dereference in f2fs_verity_work()
Date: Fri, 20 Mar 2020 12:11:49 -0700 [thread overview]
Message-ID: <20200320191149.GL851@sol.localdomain> (raw)
In-Reply-To: <20200319115800.108926-3-yuchao0@huawei.com>
On Thu, Mar 19, 2020 at 07:57:59PM +0800, Chao Yu wrote:
> If both compression and fsverity feature is on, generic/572 will
> report below NULL pointer dereference bug.
>
> BUG: kernel NULL pointer dereference, address: 0000000000000018
> RIP: 0010:f2fs_verity_work+0x60/0x90 [f2fs]
> #PF: supervisor read access in kernel mode
> Workqueue: fsverity_read_queue f2fs_verity_work [f2fs]
> RIP: 0010:f2fs_verity_work+0x60/0x90 [f2fs]
> Call Trace:
> process_one_work+0x16c/0x3f0
> worker_thread+0x4c/0x440
> ? rescuer_thread+0x350/0x350
> kthread+0xf8/0x130
> ? kthread_unpark+0x70/0x70
> ret_from_fork+0x35/0x40
>
> There are two issue in f2fs_verity_work():
> - it needs to traverse and verify all pages in bio.
> - if pages in bio belong to non-compressed cluster, accessing
> decompress IO context stored in page private will cause NULL
> pointer dereference.
>
> Fix them.
>
> Signed-off-by: Chao Yu <yuchao0@huawei.com>
> ---
> fs/f2fs/data.c | 35 ++++++++++++++++++++++++++++++-----
> 1 file changed, 30 insertions(+), 5 deletions(-)
>
> diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c
> index 5c5db09324b7..66e49fc1056e 100644
> --- a/fs/f2fs/data.c
> +++ b/fs/f2fs/data.c
> @@ -187,12 +187,37 @@ static void f2fs_verify_pages(struct page **rpages, unsigned int cluster_size)
>
> static void f2fs_verify_bio(struct bio *bio)
> {
> - struct page *page = bio_first_page_all(bio);
> - struct decompress_io_ctx *dic =
> - (struct decompress_io_ctx *)page_private(page);
> + struct bio_vec *bv;
> + struct bvec_iter_all iter_all;
> + struct decompress_io_ctx *dic, *pdic = NULL;
> +
> + bio_for_each_segment_all(bv, bio, iter_all) {
> + struct page *page = bv->bv_page;
> +
> + dic = (struct decompress_io_ctx *)page_private(page);
> +
> + if (dic) {
> + if (dic != pdic) {
> + f2fs_verify_pages(dic->rpages,
> + dic->cluster_size);
> + f2fs_free_dic(dic);
> + pdic = dic;
> + }
> + continue;
> + }
> + pdic = dic;
>
> - f2fs_verify_pages(dic->rpages, dic->cluster_size);
> - f2fs_free_dic(dic);
> + if (bio->bi_status || PageError(page)) {
> + ClearPageUptodate(page);
> + ClearPageError(page);
> + } else {
> + if (fsverity_verify_page(page))
> + SetPageUptodate(page);
> + else
> + SetPageError(page);
> + }
> + unlock_page(page);
> + }
I'm a bit confused why you added SetPageError() before unlocking the page.
The other error paths actually clear the Error flag, not set it. I thought
there's a reason for that?
- Eric
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2020-03-20 19:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-19 11:57 [f2fs-dev] [PATCH 1/4] f2fs: fix to avoid potential deadlock Chao Yu
2020-03-19 11:57 ` [f2fs-dev] [PATCH 2/4] f2fs: don't trigger data flush in foreground operation Chao Yu
2020-03-19 11:57 ` [f2fs-dev] [PATCH 3/4] f2fs: fix NULL pointer dereference in f2fs_verity_work() Chao Yu
2020-03-20 19:11 ` Eric Biggers [this message]
2020-03-21 12:16 ` Chao Yu
2020-03-19 11:58 ` [f2fs-dev] [PATCH 4/4] f2fs: fix NULL pointer dereference in f2fs_write_begin() Chao Yu
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=20200320191149.GL851@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
--cc=yuchao0@huawei.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;
as well as URLs for NNTP newsgroup(s).