mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jia-Ju Bai <baijiaju1990@gmail.com>
To: clm@fb.com, josef@toxicpanda.com, dsterba@suse.com
Cc: linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org,
	Jia-Ju Bai <baijiaju1990@gmail.com>
Subject: [PATCH] fs: btrfs: Fix a possible null-pointer dereference in insert_inline_extent()
Date: Wed, 24 Jul 2019 10:11:32 +0800	[thread overview]
Message-ID: <20190724021132.27378-1-baijiaju1990@gmail.com> (raw)

In insert_inline_extent(), there is an if statement on line 181 to check
whether compressed_pages is NULL:
    if (compressed_size && compressed_pages)

When compressed_pages is NULL, compressed_pages is used on line 215:
    cpage = compressed_pages[i];

Thus, a possible null-pointer dereference may occur.

To fix this possible bug, compressed_pages is checked on line 214.

This bug is found by a static analysis tool STCheck written by us.

Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 1af069a9a0c7..19182272fbd8 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -211,7 +211,7 @@ static int insert_inline_extent(struct btrfs_trans_handle *trans,
 	if (compress_type != BTRFS_COMPRESS_NONE) {
 		struct page *cpage;
 		int i = 0;
-		while (compressed_size > 0) {
+		while (compressed_size > 0 && compressed_pages) {
 			cpage = compressed_pages[i];
 			cur_size = min_t(unsigned long, compressed_size,
 				       PAGE_SIZE);
-- 
2.17.0


             reply	other threads:[~2019-07-24  2:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  2:11 Jia-Ju Bai [this message]
2019-07-24  2:21 ` Qu Wenruo
2019-07-24  2:33   ` Jia-Ju Bai
2019-07-24  2:57     ` Qu Wenruo
2019-07-26 15:06       ` David Sterba

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=20190724021132.27378-1-baijiaju1990@gmail.com \
    --to=baijiaju1990@gmail.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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®