diff mbox series

fs/ntfs3: Don't clear upper bits accidentally in log_replay()

Message ID YnjY58EpRzaZP+YC@kili (mailing list archive)
State New, archived
Headers show
Series fs/ntfs3: Don't clear upper bits accidentally in log_replay() | expand

Commit Message

Dan Carpenter May 9, 2022, 9:03 a.m. UTC
The "vcn" variable is a 64 bit.  The "log->clst_per_page" variable is a
u32.  This means that the mask accidentally clears out the high 32 bits
when it was only supposed to clear some low bits.  Fix this by adding a
cast to u64.

Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Why am I getting new Smatch warnings in old ntfs3 code?  It is a mystery.

 fs/ntfs3/fslog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Namjae Jeon May 19, 2022, 12:55 a.m. UTC | #1
2022-05-09 18:03 GMT+09:00, Dan Carpenter <dan.carpenter@oracle.com>:
> The "vcn" variable is a 64 bit.  The "log->clst_per_page" variable is a
> u32.  This means that the mask accidentally clears out the high 32 bits
> when it was only supposed to clear some low bits.  Fix this by adding a
> cast to u64.
>
> Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Namjae Jeon <linkinjeon@kernel.org>

> ---
> Why am I getting new Smatch warnings in old ntfs3 code?  It is a mystery.
>
>  fs/ntfs3/fslog.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
> index 915f42cf07bc..0da339fda2f4 100644
> --- a/fs/ntfs3/fslog.c
> +++ b/fs/ntfs3/fslog.c
> @@ -5057,7 +5057,7 @@ int log_replay(struct ntfs_inode *ni, bool
> *initialized)
>  		goto add_allocated_vcns;
>
>  	vcn = le64_to_cpu(lrh->target_vcn);
> -	vcn &= ~(log->clst_per_page - 1);
> +	vcn &= ~(u64)(log->clst_per_page - 1);
>
>  add_allocated_vcns:
>  	for (i = 0, vcn = le64_to_cpu(lrh->target_vcn),
> --
> 2.35.1
>
>
>
Konstantin Komarov June 10, 2022, 4:21 p.m. UTC | #2
On 5/9/22 12:03, Dan Carpenter wrote:
> The "vcn" variable is a 64 bit.  The "log->clst_per_page" variable is a
> u32.  This means that the mask accidentally clears out the high 32 bits
> when it was only supposed to clear some low bits.  Fix this by adding a
> cast to u64.
> 
> Fixes: b46acd6a6a62 ("fs/ntfs3: Add NTFS journal")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Why am I getting new Smatch warnings in old ntfs3 code?  It is a mystery.
> 
>   fs/ntfs3/fslog.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
> index 915f42cf07bc..0da339fda2f4 100644
> --- a/fs/ntfs3/fslog.c
> +++ b/fs/ntfs3/fslog.c
> @@ -5057,7 +5057,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)
>   		goto add_allocated_vcns;
>   
>   	vcn = le64_to_cpu(lrh->target_vcn);
> -	vcn &= ~(log->clst_per_page - 1);
> +	vcn &= ~(u64)(log->clst_per_page - 1);
>   
>   add_allocated_vcns:
>   	for (i = 0, vcn = le64_to_cpu(lrh->target_vcn),

Thanks for patch, applied!
diff mbox series

Patch

diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c
index 915f42cf07bc..0da339fda2f4 100644
--- a/fs/ntfs3/fslog.c
+++ b/fs/ntfs3/fslog.c
@@ -5057,7 +5057,7 @@  int log_replay(struct ntfs_inode *ni, bool *initialized)
 		goto add_allocated_vcns;
 
 	vcn = le64_to_cpu(lrh->target_vcn);
-	vcn &= ~(log->clst_per_page - 1);
+	vcn &= ~(u64)(log->clst_per_page - 1);
 
 add_allocated_vcns:
 	for (i = 0, vcn = le64_to_cpu(lrh->target_vcn),