linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] f2fs: fix KMSAN uninit-value in extent_info usage
@ 2025-06-19 12:09 Abinash Singh
  2025-06-24 14:16 ` Chao Yu
  0 siblings, 1 reply; 6+ messages in thread
From: Abinash Singh @ 2025-06-19 12:09 UTC (permalink / raw)
  To: linux-f2fs-devel
  Cc: jaegeuk, chao, linux-kernel, Abinash Singh,
	syzbot+b8c1d60e95df65e827d4

KMSAN reported a use of uninitialized value in `__is_extent_mergeable()` and
`__is_back_mergeable()` via the read extent tree path.

The root cause is that `get_read_extent_info()` only initializes three fields
(`fofs`, `blk`, `len`) of `struct extent_info`, leaving the remaining fields
uninitialized. This leads to undefined behavior when those fields are accessed
later, especially during extent merging.

Fix it by zero-initializing the `extent_info` struct before population.

Reported-by: syzbot+b8c1d60e95df65e827d4@syzkaller.appspotmail.com
Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>

---
v2 : Corrected Author name
---
 fs/f2fs/extent_cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index cfe925a3d555..4ce19a310f38 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -414,7 +414,7 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
 	struct f2fs_extent *i_ext = &F2FS_INODE(&ifolio->page)->i_ext;
 	struct extent_tree *et;
 	struct extent_node *en;
-	struct extent_info ei;
+	struct extent_info ei = {0};
 
 	if (!__may_extent_tree(inode, EX_READ)) {
 		/* drop largest read extent */
-- 
2.43.0


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

* Re: [PATCH v2] f2fs: fix KMSAN uninit-value in extent_info usage
  2025-06-19 12:09 [PATCH v2] f2fs: fix KMSAN uninit-value in extent_info usage Abinash Singh
@ 2025-06-24 14:16 ` Chao Yu
  2025-06-24 17:09   ` [PATCH v3] " Abinash Singh
  0 siblings, 1 reply; 6+ messages in thread
From: Chao Yu @ 2025-06-24 14:16 UTC (permalink / raw)
  To: Abinash Singh, linux-f2fs-devel
  Cc: chao, jaegeuk, linux-kernel, Abinash Singh,
	syzbot+b8c1d60e95df65e827d4

On 2025/6/19 20:09, Abinash Singh wrote:
> KMSAN reported a use of uninitialized value in `__is_extent_mergeable()` and
> `__is_back_mergeable()` via the read extent tree path.
> 
> The root cause is that `get_read_extent_info()` only initializes three fields
> (`fofs`, `blk`, `len`) of `struct extent_info`, leaving the remaining fields
> uninitialized. This leads to undefined behavior when those fields are accessed
> later, especially during extent merging.
> 
> Fix it by zero-initializing the `extent_info` struct before population.
> 

It needs to add a fixes line, otherwise, it looks good to me.

Thanks,

> Reported-by: syzbot+b8c1d60e95df65e827d4@syzkaller.appspotmail.com
> Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
> 
> ---
> v2 : Corrected Author name
> ---
>   fs/f2fs/extent_cache.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> index cfe925a3d555..4ce19a310f38 100644
> --- a/fs/f2fs/extent_cache.c
> +++ b/fs/f2fs/extent_cache.c
> @@ -414,7 +414,7 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
>   	struct f2fs_extent *i_ext = &F2FS_INODE(&ifolio->page)->i_ext;
>   	struct extent_tree *et;
>   	struct extent_node *en;
> -	struct extent_info ei;
> +	struct extent_info ei = {0};
>   
>   	if (!__may_extent_tree(inode, EX_READ)) {
>   		/* drop largest read extent */


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

* [PATCH v3] f2fs: fix KMSAN uninit-value in extent_info usage
  2025-06-24 14:16 ` Chao Yu
@ 2025-06-24 17:09   ` Abinash Singh
  2025-06-25  2:19     ` Chao Yu
  0 siblings, 1 reply; 6+ messages in thread
From: Abinash Singh @ 2025-06-24 17:09 UTC (permalink / raw)
  To: linux-f2fs-devel
  Cc: abinashlalotra, abinashsinghlalotra, chao, jaegeuk, linux-kernel,
	syzbot+b8c1d60e95df65e827d4

KMSAN reported a use of uninitialized value in `__is_extent_mergeable()`
 and `__is_back_mergeable()` via the read extent tree path.

The root cause is that `get_read_extent_info()` only initializes three
fields (`fofs`, `blk`, `len`) of `struct extent_info`, leaving the
remaining fields uninitialized. This leads to undefined behavior
when those fields are accessed later, especially during 
extent merging.

Fix it by zero-initializing the `extent_info` struct before population.

Reported-by: syzbot+b8c1d60e95df65e827d4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b8c1d60e95df65e827d4
Fixes: a28ef1f5aebe ("f2fs: maintain extent cache in separated file")
Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
---
v3 : Added Fixes and Closes tags
---
 fs/f2fs/extent_cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index cfe925a3d555..4ce19a310f38 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -414,7 +414,7 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
 	struct f2fs_extent *i_ext = &F2FS_INODE(&ifolio->page)->i_ext;
 	struct extent_tree *et;
 	struct extent_node *en;
-	struct extent_info ei;
+	struct extent_info ei = {0};
 
 	if (!__may_extent_tree(inode, EX_READ)) {
 		/* drop largest read extent */
-- 
2.43.0


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

* Re: [PATCH v3] f2fs: fix KMSAN uninit-value in extent_info usage
  2025-06-24 17:09   ` [PATCH v3] " Abinash Singh
@ 2025-06-25  2:19     ` Chao Yu
  2025-06-25 11:05       ` [PATCH v4] " Abinash Singh
  0 siblings, 1 reply; 6+ messages in thread
From: Chao Yu @ 2025-06-25  2:19 UTC (permalink / raw)
  To: Abinash Singh, linux-f2fs-devel
  Cc: chao, abinashsinghlalotra, jaegeuk, linux-kernel,
	syzbot+b8c1d60e95df65e827d4

On 6/25/25 01:09, Abinash Singh wrote:
> KMSAN reported a use of uninitialized value in `__is_extent_mergeable()`
>  and `__is_back_mergeable()` via the read extent tree path.
> 
> The root cause is that `get_read_extent_info()` only initializes three
> fields (`fofs`, `blk`, `len`) of `struct extent_info`, leaving the
> remaining fields uninitialized. This leads to undefined behavior
> when those fields are accessed later, especially during 
> extent merging.
> 
> Fix it by zero-initializing the `extent_info` struct before population.
> 
> Reported-by: syzbot+b8c1d60e95df65e827d4@syzkaller.appspotmail.com
> Closes: https://syzkaller.appspot.com/bug?extid=b8c1d60e95df65e827d4
> Fixes: a28ef1f5aebe ("f2fs: maintain extent cache in separated file")

Should use this instead?

Fixes: 94afd6d6e525 ("f2fs: extent cache: support unaligned extent")

Reviewed-by: Chao Yu <chao@kernel.org>

Thanks,

> Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
> ---
> v3 : Added Fixes and Closes tags
> ---
>  fs/f2fs/extent_cache.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
> index cfe925a3d555..4ce19a310f38 100644
> --- a/fs/f2fs/extent_cache.c
> +++ b/fs/f2fs/extent_cache.c
> @@ -414,7 +414,7 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
>  	struct f2fs_extent *i_ext = &F2FS_INODE(&ifolio->page)->i_ext;
>  	struct extent_tree *et;
>  	struct extent_node *en;
> -	struct extent_info ei;
> +	struct extent_info ei = {0};
>  
>  	if (!__may_extent_tree(inode, EX_READ)) {
>  		/* drop largest read extent */


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

* [PATCH v4] f2fs: fix KMSAN uninit-value in extent_info usage
  2025-06-25  2:19     ` Chao Yu
@ 2025-06-25 11:05       ` Abinash Singh
  2025-07-09 18:10         ` [f2fs-dev] " patchwork-bot+f2fs
  0 siblings, 1 reply; 6+ messages in thread
From: Abinash Singh @ 2025-06-25 11:05 UTC (permalink / raw)
  To: chao
  Cc: abinashlalotra, abinashsinghlalotra, jaegeuk, linux-f2fs-devel,
	linux-kernel, syzbot+b8c1d60e95df65e827d4

KMSAN reported a use of uninitialized value in `__is_extent_mergeable()`
 and `__is_back_mergeable()` via the read extent tree path.

The root cause is that `get_read_extent_info()` only initializes three
fields (`fofs`, `blk`, `len`) of `struct extent_info`, leaving the
remaining fields uninitialized. This leads to undefined behavior
when those fields are accessed later, especially during
extent merging.

Fix it by zero-initializing the `extent_info` struct before population.

Reported-by: syzbot+b8c1d60e95df65e827d4@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=b8c1d60e95df65e827d4
Fixes: 94afd6d6e525 ("f2fs: extent cache: support unaligned extent")
Reviewed-by: Chao Yu <chao@kernel.org>
Signed-off-by: Abinash Singh <abinashsinghlalotra@gmail.com>
---
v4 : Added Reviewed-by and Corrected Fixes
---
 fs/f2fs/extent_cache.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c
index cfe925a3d555..4ce19a310f38 100644
--- a/fs/f2fs/extent_cache.c
+++ b/fs/f2fs/extent_cache.c
@@ -414,7 +414,7 @@ void f2fs_init_read_extent_tree(struct inode *inode, struct folio *ifolio)
 	struct f2fs_extent *i_ext = &F2FS_INODE(&ifolio->page)->i_ext;
 	struct extent_tree *et;
 	struct extent_node *en;
-	struct extent_info ei;
+	struct extent_info ei = {0};
 
 	if (!__may_extent_tree(inode, EX_READ)) {
 		/* drop largest read extent */
-- 
2.43.0


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

* Re: [f2fs-dev] [PATCH v4] f2fs: fix KMSAN uninit-value in extent_info usage
  2025-06-25 11:05       ` [PATCH v4] " Abinash Singh
@ 2025-07-09 18:10         ` patchwork-bot+f2fs
  0 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+f2fs @ 2025-07-09 18:10 UTC (permalink / raw)
  To: Abinash Singh
  Cc: chao, syzbot+b8c1d60e95df65e827d4, abinashsinghlalotra,
	linux-kernel, linux-f2fs-devel, jaegeuk

Hello:

This patch was applied to jaegeuk/f2fs.git (dev)
by Jaegeuk Kim <jaegeuk@kernel.org>:

On Wed, 25 Jun 2025 16:35:37 +0530 you wrote:
> KMSAN reported a use of uninitialized value in `__is_extent_mergeable()`
>  and `__is_back_mergeable()` via the read extent tree path.
> 
> The root cause is that `get_read_extent_info()` only initializes three
> fields (`fofs`, `blk`, `len`) of `struct extent_info`, leaving the
> remaining fields uninitialized. This leads to undefined behavior
> when those fields are accessed later, especially during
> extent merging.
> 
> [...]

Here is the summary with links:
  - [f2fs-dev,v4] f2fs: fix KMSAN uninit-value in extent_info usage
    https://git.kernel.org/jaegeuk/f2fs/c/154467f4ad03

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

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

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-19 12:09 [PATCH v2] f2fs: fix KMSAN uninit-value in extent_info usage Abinash Singh
2025-06-24 14:16 ` Chao Yu
2025-06-24 17:09   ` [PATCH v3] " Abinash Singh
2025-06-25  2:19     ` Chao Yu
2025-06-25 11:05       ` [PATCH v4] " Abinash Singh
2025-07-09 18:10         ` [f2fs-dev] " patchwork-bot+f2fs

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).