All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next][V2] fs/jfs: fix potential integer overflow on shift of a int
@ 2021-02-11 13:01 ` Colin King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin King @ 2021-02-11 13:01 UTC (permalink / raw)
  To: Dave Kleikamp, jfs-discussion; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
arithmetic and then assigned to a signed 64 bit integer. In the case where
l2nb is 32 or more this can lead to an overflow.  Avoid this by shifting
the value 1LL instead.

Addresses-Coverity: ("Uninitentional integer overflow")
Fixes: b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: shift 1LL rather than using BIT_ULL macro as suggested by
    Dave Kleikamp.

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

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 94b7c1cb5ceb..7aee15608619 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -1656,7 +1656,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
 		} else if (rc == -ENOSPC) {
 			/* search for next smaller log2 block */
 			l2nb = BLKSTOL2(nblocks) - 1;
-			nblocks = 1 << l2nb;
+			nblocks = 1LL << l2nb;
 		} else {
 			/* Trim any already allocated blocks */
 			jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH][next][V2] fs/jfs: fix potential integer overflow on shift of a int
@ 2021-02-11 13:01 ` Colin King
  0 siblings, 0 replies; 4+ messages in thread
From: Colin King @ 2021-02-11 13:01 UTC (permalink / raw)
  To: Dave Kleikamp, jfs-discussion; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
arithmetic and then assigned to a signed 64 bit integer. In the case where
l2nb is 32 or more this can lead to an overflow.  Avoid this by shifting
the value 1LL instead.

Addresses-Coverity: ("Uninitentional integer overflow")
Fixes: b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---

V2: shift 1LL rather than using BIT_ULL macro as suggested by
    Dave Kleikamp.

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

diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
index 94b7c1cb5ceb..7aee15608619 100644
--- a/fs/jfs/jfs_dmap.c
+++ b/fs/jfs/jfs_dmap.c
@@ -1656,7 +1656,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
 		} else if (rc = -ENOSPC) {
 			/* search for next smaller log2 block */
 			l2nb = BLKSTOL2(nblocks) - 1;
-			nblocks = 1 << l2nb;
+			nblocks = 1LL << l2nb;
 		} else {
 			/* Trim any already allocated blocks */
 			jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
-- 
2.30.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH][next][V2] fs/jfs: fix potential integer overflow on shift of a int
  2021-02-11 13:01 ` Colin King
@ 2021-02-11 17:49   ` Dave Kleikamp
  -1 siblings, 0 replies; 4+ messages in thread
From: Dave Kleikamp @ 2021-02-11 17:49 UTC (permalink / raw)
  To: Colin King, jfs-discussion; +Cc: kernel-janitors, linux-kernel

On 2/11/21 7:01 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
> arithmetic and then assigned to a signed 64 bit integer. In the case where
> l2nb is 32 or more this can lead to an overflow.  Avoid this by shifting
> the value 1LL instead.
> 
> Addresses-Coverity: ("Uninitentional integer overflow")
> Fixes: b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Looks good. I'll include it in the next jfs drop.

Thanks,
Shaggy

> ---
> 
> V2: shift 1LL rather than using BIT_ULL macro as suggested by
>      Dave Kleikamp.
> 
> ---
>   fs/jfs/jfs_dmap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
> index 94b7c1cb5ceb..7aee15608619 100644
> --- a/fs/jfs/jfs_dmap.c
> +++ b/fs/jfs/jfs_dmap.c
> @@ -1656,7 +1656,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
>   		} else if (rc == -ENOSPC) {
>   			/* search for next smaller log2 block */
>   			l2nb = BLKSTOL2(nblocks) - 1;
> -			nblocks = 1 << l2nb;
> +			nblocks = 1LL << l2nb;
>   		} else {
>   			/* Trim any already allocated blocks */
>   			jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH][next][V2] fs/jfs: fix potential integer overflow on shift of a int
@ 2021-02-11 17:49   ` Dave Kleikamp
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Kleikamp @ 2021-02-11 17:49 UTC (permalink / raw)
  To: Colin King, jfs-discussion; +Cc: kernel-janitors, linux-kernel

On 2/11/21 7:01 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> The left shift of int 32 bit integer constant 1 is evaluated using 32 bit
> arithmetic and then assigned to a signed 64 bit integer. In the case where
> l2nb is 32 or more this can lead to an overflow.  Avoid this by shifting
> the value 1LL instead.
> 
> Addresses-Coverity: ("Uninitentional integer overflow")
> Fixes: b40c2e665cd5 ("fs/jfs: TRIM support for JFS Filesystem")
> Signed-off-by: Colin Ian King <colin.king@canonical.com>

Looks good. I'll include it in the next jfs drop.

Thanks,
Shaggy

> ---
> 
> V2: shift 1LL rather than using BIT_ULL macro as suggested by
>      Dave Kleikamp.
> 
> ---
>   fs/jfs/jfs_dmap.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/fs/jfs/jfs_dmap.c b/fs/jfs/jfs_dmap.c
> index 94b7c1cb5ceb..7aee15608619 100644
> --- a/fs/jfs/jfs_dmap.c
> +++ b/fs/jfs/jfs_dmap.c
> @@ -1656,7 +1656,7 @@ s64 dbDiscardAG(struct inode *ip, int agno, s64 minlen)
>   		} else if (rc = -ENOSPC) {
>   			/* search for next smaller log2 block */
>   			l2nb = BLKSTOL2(nblocks) - 1;
> -			nblocks = 1 << l2nb;
> +			nblocks = 1LL << l2nb;
>   		} else {
>   			/* Trim any already allocated blocks */
>   			jfs_error(bmp->db_ipbmap->i_sb, "-EIO\n");
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-11 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-11 13:01 [PATCH][next][V2] fs/jfs: fix potential integer overflow on shift of a int Colin King
2021-02-11 13:01 ` Colin King
2021-02-11 17:49 ` Dave Kleikamp
2021-02-11 17:49   ` Dave Kleikamp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.