Skip to contentSkip to conversation

netfs: Fix a KMSAN uninit-value error in netfs_clear_buffer

PATCH Superseded Chang Yu 2 participants 4 messages Sep 21, 2024 – Oct 1, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Chang Yu

author
#0 lore raw

PATCH 1/1 netfs: Fix a KMSAN uninit-value error in netfs_clear_buffer

Use kzalloc instead of kmalloc in netfs_buffer_append_folio to fix a KMSAN uninit-value error in netfs_clear_buffer

Reported-by [email protected]
Fixes cd0277ed0c18 ("netfs: Use new folio_queue data type and iterator instead of xarray iter")
---
 fs/netfs/misc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/netfs/misc.c +1 -1
index 0ad0982ce0e2..6f967b6d30b6 100644
@@ -22,7 +22,7 @@ int netfs_buffer_append_folio(struct netfs_io_request *rreq, struct folio *folio
 		return -EIO;
 
 	if (!tail || folioq_full(tail)) {
-		tail = kmalloc(sizeof(*tail), GFP_NOFS);
+		tail = kzalloc(sizeof(*tail), GFP_NOFS);
 		if (!tail)
 			return -ENOMEM;
 		netfs_stat(&netfs_n_folioq);
Signature · 1 line
2.46.0
maintainer
#1 lore raw

fs/netfs/misc.c int netfs_buffer_append_folio(struct netfs_io_request *rreq, struct folio *folio · line 25

Quoted 2 lines · Chang Yu
fs/netfs/misc.c +1 -1
-		tail = kmalloc(sizeof(*tail), GFP_NOFS);
+		tail = kzalloc(sizeof(*tail), GFP_NOFS);

I'm deliberately not doing that because of the performance hit. That's 31 pointers of which, in many cases, we're only going to use the first couple. There's a bitmask indicating which pointers need putting and a counter that indicates how many are used.

David

maintainer
#2 lore raw
In reply to Chang Yu
Quoted 2 lines · Chang Yu

Use kzalloc instead of kmalloc in netfs_buffer_append_folio to fix a KMSAN uninit-value error in netfs_clear_buffer

Btw, is this a theoretical error or are you actually seeing an uninitialised pointer being dereferenced?

David

author
#3 lore raw
Quoted 7 lines · David Howells
Quoted 2 lines · Chang Yu

Use kzalloc instead of kmalloc in netfs_buffer_append_folio to fix a KMSAN uninit-value error in netfs_clear_buffer

Btw, is this a theoretical error or are you actually seeing an uninitialised pointer being dereferenced?

Apologies for the late reply. Yes this bug was reported by syzbot
(https://syzkaller.appspot.com/bug?extid=921873345a95f4dae7e9) and I was able to reproduce it locally on my machine. I've just tested it with the latest upstream and confirmed that the bug is still present. I will send a revised patch shortly, please feel free to take a look.

Chang