public inbox for linux-ext4@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] ext4: Fix an error handling path in ext4_mb_init_cache()
@ 2025-01-03 13:59 Christophe JAILLET
  2025-01-03 13:59 ` [PATCH 2/3] ext4: Remove some useless assignments " Christophe JAILLET
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Christophe JAILLET @ 2025-01-03 13:59 UTC (permalink / raw)
  To: Theodore Ts'o, Andreas Dilger, Alex Tomas, Eric Sandeen,
	Aneesh Kumar K.V
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, Andreas Dilger,
	linux-ext4

'bhs' is an un-initialized pointer.
If 'groups_per_page' == 1, 'bh' is assigned its address.

Then, in the for loop below, if we early exit, either because
"group >= ngroups" or if ext4_get_group_info() fails, then it is still left
un-initialized.

It can then be used.
NULL tests could fail and lead to unexpected behavior. Also, should the
error handling path be called, brelse() would be passed a potentially
invalid value.

Better safe than sorry, just make sure it is correctly initialized to NULL.

Fixes: c9de560ded61 ("ext4: Add multi block allocator for ext4")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only.

The scenario looks possible, but I don't know if it can really happen...
---
 fs/ext4/mballoc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index b25a27c86696..ff9a124f439b 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -1285,7 +1285,7 @@ static int ext4_mb_init_cache(struct folio *folio, char *incore, gfp_t gfp)
 	ext4_group_t first_group, group;
 	int first_block;
 	struct super_block *sb;
-	struct buffer_head *bhs;
+	struct buffer_head *bhs = NULL;
 	struct buffer_head **bh = NULL;
 	struct inode *inode;
 	char *data;
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-01-07  8:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-03 13:59 [PATCH 1/3] ext4: Fix an error handling path in ext4_mb_init_cache() Christophe JAILLET
2025-01-03 13:59 ` [PATCH 2/3] ext4: Remove some useless assignments " Christophe JAILLET
2025-01-03 13:59 ` [PATCH 3/3] ext4: Remove some dead code in the error handling path of ext4_mb_init_cache() Christophe JAILLET
2025-01-06 14:20   ` Markus Elfring
2025-01-06 11:35 ` [PATCH 1/3] ext4: Fix an error handling path in ext4_mb_init_cache() Dan Carpenter
2025-01-06 19:16   ` Christophe JAILLET
2025-01-07  8:09     ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox