All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ritesh Harjani <riteshh@linux.ibm.com>
To: linux-ext4@vger.kernel.org
Cc: linux-fsdevel@vger.kernel.org, Jan Kara <jack@suse.com>,
	tytso@mit.edu, "Aneesh Kumar K . V" <aneesh.kumar@linux.ibm.com>,
	Ritesh Harjani <riteshh@linux.ibm.com>
Subject: [RFC 09/16] ext4: mballoc: Fix possible NULL ptr & remove BUG_ONs from DOUBLE_CHECK
Date: Sun, 10 May 2020 11:54:49 +0530	[thread overview]
Message-ID: <9a54f8a696ff17c057cd571be3d15ac3ec1407f1.1589086800.git.riteshh@linux.ibm.com> (raw)
In-Reply-To: <cover.1589086800.git.riteshh@linux.ibm.com>

Make sure to check for e4b->bd_info->bb_bitmap == NULL, in
mb_cmp_bitmaps() and return if NULL, to avoid possible NULL ptr
dereference. Similar to how we do this in other ifdef DOUBLE_CHECK
functions.

Also remove the BUG_ON() logic if kmalloc() or ext4_read_block_bitmap()
fails. We should simply mark grp->bb_bitmap as NULL if above happens.
In fact ext4_read_block_bitmap() may even return an error in case of resize
ioctl. Hence remove this BUG_ON logic (fstests ext4/032 may trigger
this).

---
Signed-off-by: Ritesh Harjani <riteshh@linux.ibm.com>
---
 fs/ext4/mballoc.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 3555e72f149c..c713d06e70b7 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -493,6 +493,8 @@ static void mb_mark_used_double(struct ext4_buddy *e4b, int first, int count)
 
 static void mb_cmp_bitmaps(struct ext4_buddy *e4b, void *bitmap)
 {
+	if (unlikely(e4b->bd_info->bb_bitmap == NULL))
+		return;
 	if (memcmp(e4b->bd_info->bb_bitmap, bitmap, e4b->bd_sb->s_blocksize)) {
 		unsigned char *b1, *b2;
 		int i;
@@ -517,10 +519,15 @@ static void mb_group_bb_bitmap_alloc(struct super_block *sb,
 	struct buffer_head *bh;
 
 	grp->bb_bitmap = kmalloc(sb->s_blocksize, GFP_NOFS);
-	BUG_ON(grp->bb_bitmap == NULL);
+	if (!grp->bb_bitmap)
+		return;
 
 	bh = ext4_read_block_bitmap(sb, group);
-	BUG_ON(IS_ERR_OR_NULL(bh));
+	if (IS_ERR_OR_NULL(bh)) {
+		kfree(grp->bb_bitmap);
+		grp->bb_bitmap = NULL;
+		return;
+	}
 
 	memcpy(grp->bb_bitmap, bh->b_data, sb->s_blocksize);
 	put_bh(bh);
-- 
2.21.0


  parent reply	other threads:[~2020-05-10  6:25 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-10  6:24 [RFC 00/16] ext4: mballoc/extents: Code cleanup and debug improvements Ritesh Harjani
2020-05-10  6:24 ` [RFC 01/16] ext4: mballoc: Do print bb_free info even when it is 0 Ritesh Harjani
2020-05-10  6:24 ` [RFC 02/16] ext4: mballoc: Refactor ext4_mb_show_ac() Ritesh Harjani
2020-05-10  6:24 ` [RFC 03/16] ext4: mballoc: Add more mb_debug() msgs Ritesh Harjani
2020-05-10  6:24 ` [RFC 04/16] ext4: mballoc: Correct the mb_debug() format specifier for pa_len var Ritesh Harjani
2020-05-10  6:24 ` [RFC 05/16] ext4: mballoc: Fix few other format specifier in mb_debug() Ritesh Harjani
2020-05-10  6:24 ` [RFC 06/16] ext4: mballoc: Simplify error handling in ext4_init_mballoc() Ritesh Harjani
2020-05-10  6:24 ` [RFC 07/16] ext4: mballoc: Make ext4_mb_use_preallocated() return type as bool Ritesh Harjani
2020-05-10  6:24 ` [RFC 08/16] ext4: mballoc: Refactor code inside DOUBLE_CHECK into separate function Ritesh Harjani
2020-05-10  6:24 ` Ritesh Harjani [this message]
2020-05-10  6:24 ` [RFC 10/16] ext4: balloc: Use task_pid_nr() helper Ritesh Harjani
2020-05-10  6:24 ` [RFC 11/16] ext4: Use BIT() macro for BH_** state bits Ritesh Harjani
2020-05-10  6:24 ` [RFC 12/16] ext4: Improve ext_debug() msg in case of block allocation failure Ritesh Harjani
2020-05-10  6:24 ` [RFC 13/16] ext4: Replace EXT_DEBUG with __maybe_unused in ext4_ext_handle_unwritten_extents() Ritesh Harjani
2020-05-10  6:24 ` [RFC 14/16] ext4: mballoc: Make mb_debug() implementation to use pr_debug() Ritesh Harjani
2020-05-10  6:24 ` [RFC 15/16] ext4: Make ext_debug() " Ritesh Harjani
2020-05-10  6:24 ` [RFC 16/16] ext4: Add process name and pid in ext4_msg() Ritesh Harjani
2020-05-21 18:26   ` Theodore Y. Ts'o
2020-06-02  5:00     ` Ritesh Harjani
2020-05-28 14:20 ` [RFC 00/16] ext4: mballoc/extents: Code cleanup and debug improvements Theodore Y. Ts'o

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=9a54f8a696ff17c057cd571be3d15ac3ec1407f1.1589086800.git.riteshh@linux.ibm.com \
    --to=riteshh@linux.ibm.com \
    --cc=aneesh.kumar@linux.ibm.com \
    --cc=jack@suse.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.