fs/ntfs3: Fix memory and resource leak in indx_find_sort
Subsystems (3)
PATCH 1/1 fs/ntfs3: Fix memory and resource leak in indx_find_sort
The function indx_find_sort() incorrectly uses kfree(n) to cleanup the 'struct indx_node' instance in error paths.
The 'struct indx_node' is a container that manages internal allocations (n->index) and holds a reference to a buffer head (n->nb). Using kfree() directly on the node pointer only frees the container itself, resulting in a memory leak of the index buffer and a resource leak of the buffer head reference.
This patch replaces the incorrect kfree(n) calls with the specialized helper put_indx_node(n), which correctly releases the internal resources and the buffer head, consistent with other functions like indx_find_raw().
--- fs/ntfs3/index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ntfs3/index.c +3 -3
@@ -1248,7 +1248,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni, sizeof(struct NTFS_DE) + sizeof(u64)) {if (n) {fnd_pop (fnd); -kfree (n); +put_indx_node (n); }return -EINVAL ; }
@@ -1261,7 +1261,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni,/* Try next level. */ e =hdr_first_de (&n->index->ihdr);if (!e) { -kfree (n); +put_indx_node (n);return -EINVAL ; }
@@ -1281,7 +1281,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni,/* Pop one level. */ if (n) {fnd_pop (fnd); -kfree (n); +put_indx_node (n); } level = fnd->level;
Signature · 1 line
2.25.1
…
Quoted 1 line
This patch replaces the incorrect …
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94
How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?
Regards,
Markus
PATCH v2 1/1 fs/ntfs3: Fix memory and resource leak in indx_find_sort
The function indx_find_sort() incorrectly uses kfree(n) to cleanup the 'struct indx_node' instance in error paths.
The 'struct indx_node' is a container that manages internal allocations (n->index) and holds a reference to a buffer head (n->nb). Using kfree() directly on the node pointer only frees the container itself, resulting in a memory leak of the index buffer and a resource leak of the buffer head reference.
This patch replaces the incorrect kfree(n) calls with the specialized helper put_indx_node(n), which correctly releases the internal resources and the buffer head, consistent with other functions like indx_find_raw().
---
Changelog:
v1 -> v2:
1. Add a Fixes tag.
--- fs/ntfs3/index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/ntfs3/index.c +3 -3
@@ -1248,7 +1248,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni, sizeof(struct NTFS_DE) + sizeof(u64)) {if (n) {fnd_pop (fnd); -kfree (n); +put_indx_node (n); }return -EINVAL ; }
@@ -1261,7 +1261,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni,/* Try next level. */ e =hdr_first_de (&n->index->ihdr);if (!e) { -kfree (n); +put_indx_node (n);return -EINVAL ; }
@@ -1281,7 +1281,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni,/* Pop one level. */ if (n) {fnd_pop (fnd); -kfree (n); +put_indx_node (n); } level = fnd->level;
Signature · 1 line
2.25.1
Greg KH
maintainerQuoted 60 lines · Jiasheng Jiang
The function
indx_find_sort()incorrectly uses kfree(n) to cleanup the 'structindx_node' instance in error paths.The 'struct
indx_node' is a container that manages internal allocations (n->index) and holds a reference to a buffer head (n->nb). Usingkfree()directly on the node pointer only frees the container itself, resulting in a memory leak of the index buffer and a resource leak of the buffer head reference.This patch replaces the incorrect kfree(n) calls with the specialized helper
put_indx_node(n), which correctly releases the internal resources and the buffer head, consistent with other functions likeindx_find_raw().Fixes 82cae269cfa9 ("fs/ntfs3: Add initialization of super block")Signed-off-by Jiasheng Jiang <[email protected]>---
Changelog:v1 -> v2:
1. Add a Fixes tag.
--- fs/ntfs3/index.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)fs/ntfs3/index.c +3
-3@@ -1248,7 +1248,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni, sizeof(struct NTFS_DE) + sizeof(u64)) {if (n) {fnd_pop (fnd); -kfree (n); +put_indx_node (n); }return -EINVAL ; }@@ -1261,7 +1261,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni,/* Try next level. */ e =hdr_first_de (&n->index->ihdr);if (!e) { -kfree (n); +put_indx_node (n);return -EINVAL ; }@@ -1281,7 +1281,7 @@ int indx_find_sort(struct ntfs_index *indx, struct ntfs_inode *ni,/* Pop one level. */ if (n) {fnd_pop (fnd); -kfree (n); +put_indx_node (n); } level = fnd->level;Signature · 1 line
2.25.1
<formletter>
This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read:
https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.
</formletter>
…
Quoted 1 line
This patch replaces the incorrect kfree(n) calls …
Thanks for another contribution.
* Under which circumstances would you take the usage of imperative mood better into account for an improved change description?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc5#n94
* Can it be helpful to append parentheses to function names (also in the summary phrase)?
Regards,
Markus