Skip to contentSkip to conversation

ntfs: use kvfree when ascending an index tree

PATCH Applied Dandan Wu 3 participants 3 messages Nov 20 NTFS filesystem

lore
Share & tools
lore

Dandan Wu

author
#0 lore raw

PATCH 1/1 ntfs: use kvfree when ascending an index tree

From: Dandan Wu <[email protected]>

ntfs_index_walk_down() allocates the index block with kvzalloc(), which may return vmalloc memory. When traversal ascends back to the root, ntfs_index_walk_up() passes that block to kfree(), which cannot free a vmalloc allocation.

Use kvfree(), as the index context cleanup already does, to handle both allocation types.

Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")
---
 fs/ntfs/index.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/index.c +1 -1
index b4462f760e3b..d565accb05d5 100644
@@ -2274,7 +2274,7 @@ static struct index_entry *ntfs_index_walk_up(struct index_entry *ie,
 		ictx->pindex--;
 		if (!ictx->pindex) {
 			/* we have reached the root */
-			kfree(ictx->ib);
+			kvfree(ictx->ib);
 			ictx->ib = NULL;
 			ictx->is_in_root = true;
 			/* a new search context is to be allocated */
Signature · 1 line
2.25.1
Reviewed-by Baolin Liu on v1 1/1
#1 lore raw
Quoted 21 lines · Dandan Wu

From: Dandan Wu <[email protected]>

ntfs_index_walk_down() allocates the index block with kvzalloc(), which may return vmalloc memory. When traversal ascends back to the root, ntfs_index_walk_up() passes that block to kfree(), which cannot free a vmalloc allocation.

Use kvfree(), as the index context cleanup already does, to handle both allocation types.

Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")
---
  fs/ntfs/index.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
fs/ntfs/index.c +0 -0
index b4462f760e3b..d565accb05d5 100644

fs/ntfs/index.c static struct index_entry *ntfs_index_walk_up(struct index_entry *ie, · line 2280

Quoted 8 lines
fs/ntfs/index.c +1 -1
@@ -2274,7 +2274,7 @@ static struct index_entry *ntfs_index_walk_up(struct index_entry *ie,
  		ictx->pindex--;
  		if (!ictx->pindex) {
  			/* we have reached the root */
-			kfree(ictx->ib);
+			kvfree(ictx->ib);
  			ictx->ib = NULL;
  			ictx->is_in_root = true;
  			/* a new search context is to be allocated */

Looks good to me.

maintainer Applied
#2 lore raw
In reply to Dandan Wu
Quoted 8 lines · Dandan Wu

From: Dandan Wu <[email protected]>

ntfs_index_walk_down() allocates the index block with kvzalloc(), which may return vmalloc memory. When traversal ascends back to the root, ntfs_index_walk_up() passes that block to kfree(), which cannot free a vmalloc allocation.

Quoted 5 lines

Use kvfree(), as the index context cleanup already does, to handle both allocation types.

Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")

Applied it to #ntfs-next.
Thanks!