[PATCH 3/3] ntfs: Fix possible deadlock

Ethan Tidmore posted 3 patches 1 month, 1 week ago
[PATCH 3/3] ntfs: Fix possible deadlock
Posted by Ethan Tidmore 1 month, 1 week ago
In the error path for ntfs_attr_map_whole_runlist() the lock is not
released.

Add release for lock.

Detected by Smatch:
fs/ntfs/attrib.c:5197 ntfs_non_resident_attr_collapse_range() warn:
inconsistent returns '&ni->runlist.lock'.

Fixes: 495e90fa33482 ("ntfs: update attrib operations")
Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>
---
 fs/ntfs/attrib.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
index 71ad870eceac..2af45df2aab1 100644
--- a/fs/ntfs/attrib.c
+++ b/fs/ntfs/attrib.c
@@ -5124,8 +5124,10 @@ int ntfs_non_resident_attr_collapse_range(struct ntfs_inode *ni, s64 start_vcn,
 
 	down_write(&ni->runlist.lock);
 	ret = ntfs_attr_map_whole_runlist(ni);
-	if (ret)
+	if (ret) {
+		up_write(&ni->runlist.lock);
 		return ret;
+	}
 
 	len = min(len, end_vcn - start_vcn);
 	for (rl = ni->runlist.rl, dst_cnt = 0; rl && rl->length; rl++)
-- 
2.53.0
Re: [PATCH 3/3] ntfs: Fix possible deadlock
Posted by Hyunchul Lee 1 month, 1 week ago
On Thu, Feb 26, 2026 at 10:09:06AM -0600, Ethan Tidmore wrote:
> In the error path for ntfs_attr_map_whole_runlist() the lock is not
> released.
> 
> Add release for lock.
> 
> Detected by Smatch:
> fs/ntfs/attrib.c:5197 ntfs_non_resident_attr_collapse_range() warn:
> inconsistent returns '&ni->runlist.lock'.
> 
> Fixes: 495e90fa33482 ("ntfs: update attrib operations")
> Signed-off-by: Ethan Tidmore <ethantidmore06@gmail.com>

Looks good to me. Thank for the patch

Reviewed-by: Hyunchul Lee <hyc.lee@gmail.com> 
> ---
>  fs/ntfs/attrib.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/ntfs/attrib.c b/fs/ntfs/attrib.c
> index 71ad870eceac..2af45df2aab1 100644
> --- a/fs/ntfs/attrib.c
> +++ b/fs/ntfs/attrib.c
> @@ -5124,8 +5124,10 @@ int ntfs_non_resident_attr_collapse_range(struct ntfs_inode *ni, s64 start_vcn,
>  
>  	down_write(&ni->runlist.lock);
>  	ret = ntfs_attr_map_whole_runlist(ni);
> -	if (ret)
> +	if (ret) {
> +		up_write(&ni->runlist.lock);
>  		return ret;
> +	}
>  
>  	len = min(len, end_vcn - start_vcn);
>  	for (rl = ni->runlist.rl, dst_cnt = 0; rl && rl->length; rl++)
> -- 
> 2.53.0
> 

-- 
Thanks,
Hyunchul