All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH][next] io-wq: fix unintentional integer overflow on left shift
@ 2019-10-25 12:43 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2019-10-25 12:43 UTC (permalink / raw)
  To: Alexander Viro, Jens Axboe, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

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

Shifting the integer value 1U is evaluated with type unsigned int
using 32-bit arithmetic and then used in an expression that expects
a 64-bit value, so there is potentially an integer overflow. Fix this
by using the BIT_ULL macro to perform the shift and avoid the overflow.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 46134db8fdc5 ("io-wq: small threadpool implementation for io_uring")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/io-wq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/io-wq.c b/fs/io-wq.c
index 35e94792d47c..ea5d37193f31 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -228,8 +228,8 @@ static struct io_wq_work *io_get_next_work(struct io_wqe *wqe, unsigned *hash)
 
 		/* hashed, can run if not already running */
 		*hash = work->flags >> IO_WQ_HASH_SHIFT;
-		if (!(wqe->hash_map & (1U << *hash))) {
-			wqe->hash_map |= (1U << *hash);
+		if (!(wqe->hash_map & BIT_ULL(*hash))) {
+			wqe->hash_map |= BIT_ULL(*hash);
 			list_del(&work->list);
 			return work;
 		}
-- 
2.20.1

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

* [PATCH][next] io-wq: fix unintentional integer overflow on left shift
@ 2019-10-25 12:43 ` Colin King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin King @ 2019-10-25 12:43 UTC (permalink / raw)
  To: Alexander Viro, Jens Axboe, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

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

Shifting the integer value 1U is evaluated with type unsigned int
using 32-bit arithmetic and then used in an expression that expects
a 64-bit value, so there is potentially an integer overflow. Fix this
by using the BIT_ULL macro to perform the shift and avoid the overflow.

Addresses-Coverity: ("Unintentional integer overflow")
Fixes: 46134db8fdc5 ("io-wq: small threadpool implementation for io_uring")
Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 fs/io-wq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/io-wq.c b/fs/io-wq.c
index 35e94792d47c..ea5d37193f31 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -228,8 +228,8 @@ static struct io_wq_work *io_get_next_work(struct io_wqe *wqe, unsigned *hash)
 
 		/* hashed, can run if not already running */
 		*hash = work->flags >> IO_WQ_HASH_SHIFT;
-		if (!(wqe->hash_map & (1U << *hash))) {
-			wqe->hash_map |= (1U << *hash);
+		if (!(wqe->hash_map & BIT_ULL(*hash))) {
+			wqe->hash_map |= BIT_ULL(*hash);
 			list_del(&work->list);
 			return work;
 		}
-- 
2.20.1


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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
  2019-10-25 12:43 ` Colin King
@ 2019-10-25 12:54   ` Jens Axboe
  -1 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2019-10-25 12:54 UTC (permalink / raw)
  To: Colin King, Alexander Viro, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

On 10/25/19 6:43 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1U is evaluated with type unsigned int
> using 32-bit arithmetic and then used in an expression that expects
> a 64-bit value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the overflow.

Good catch, that should indeed have been 1ULL. I'll fold in your
fix, thanks!

-- 
Jens Axboe

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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
@ 2019-10-25 12:54   ` Jens Axboe
  0 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2019-10-25 12:54 UTC (permalink / raw)
  To: Colin King, Alexander Viro, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

On 10/25/19 6:43 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Shifting the integer value 1U is evaluated with type unsigned int
> using 32-bit arithmetic and then used in an expression that expects
> a 64-bit value, so there is potentially an integer overflow. Fix this
> by using the BIT_ULL macro to perform the shift and avoid the overflow.

Good catch, that should indeed have been 1ULL. I'll fold in your
fix, thanks!

-- 
Jens Axboe


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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
  2019-10-25 12:54   ` Jens Axboe
@ 2019-10-25 13:56     ` Jens Axboe
  -1 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2019-10-25 13:56 UTC (permalink / raw)
  To: Colin King, Alexander Viro, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

On 10/25/19 6:54 AM, Jens Axboe wrote:
> On 10/25/19 6:43 AM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Shifting the integer value 1U is evaluated with type unsigned int
>> using 32-bit arithmetic and then used in an expression that expects
>> a 64-bit value, so there is potentially an integer overflow. Fix this
>> by using the BIT_ULL macro to perform the shift and avoid the overflow.
> 
> Good catch, that should indeed have been 1ULL. I'll fold in your
> fix, thanks!

BTW, this missed the same issue on the clear side of it, in
io_worker_handle_work(). I've fixed that one up the same way.

-- 
Jens Axboe

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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
@ 2019-10-25 13:56     ` Jens Axboe
  0 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2019-10-25 13:56 UTC (permalink / raw)
  To: Colin King, Alexander Viro, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

On 10/25/19 6:54 AM, Jens Axboe wrote:
> On 10/25/19 6:43 AM, Colin King wrote:
>> From: Colin Ian King <colin.king@canonical.com>
>>
>> Shifting the integer value 1U is evaluated with type unsigned int
>> using 32-bit arithmetic and then used in an expression that expects
>> a 64-bit value, so there is potentially an integer overflow. Fix this
>> by using the BIT_ULL macro to perform the shift and avoid the overflow.
> 
> Good catch, that should indeed have been 1ULL. I'll fold in your
> fix, thanks!

BTW, this missed the same issue on the clear side of it, in
io_worker_handle_work(). I've fixed that one up the same way.

-- 
Jens Axboe


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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
  2019-10-25 13:56     ` Jens Axboe
@ 2019-10-25 13:59       ` Colin Ian King
  -1 siblings, 0 replies; 10+ messages in thread
From: Colin Ian King @ 2019-10-25 13:59 UTC (permalink / raw)
  To: Jens Axboe, Alexander Viro, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

On 25/10/2019 14:56, Jens Axboe wrote:
> On 10/25/19 6:54 AM, Jens Axboe wrote:
>> On 10/25/19 6:43 AM, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Shifting the integer value 1U is evaluated with type unsigned int
>>> using 32-bit arithmetic and then used in an expression that expects
>>> a 64-bit value, so there is potentially an integer overflow. Fix this
>>> by using the BIT_ULL macro to perform the shift and avoid the overflow.
>>
>> Good catch, that should indeed have been 1ULL. I'll fold in your
>> fix, thanks!
> 
> BTW, this missed the same issue on the clear side of it, in
> io_worker_handle_work(). I've fixed that one up the same way.
> 
Ah, good, somehow the scanner missed that.

Colin

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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
@ 2019-10-25 13:59       ` Colin Ian King
  0 siblings, 0 replies; 10+ messages in thread
From: Colin Ian King @ 2019-10-25 13:59 UTC (permalink / raw)
  To: Jens Axboe, Alexander Viro, linux-fsdevel; +Cc: kernel-janitors, linux-kernel

On 25/10/2019 14:56, Jens Axboe wrote:
> On 10/25/19 6:54 AM, Jens Axboe wrote:
>> On 10/25/19 6:43 AM, Colin King wrote:
>>> From: Colin Ian King <colin.king@canonical.com>
>>>
>>> Shifting the integer value 1U is evaluated with type unsigned int
>>> using 32-bit arithmetic and then used in an expression that expects
>>> a 64-bit value, so there is potentially an integer overflow. Fix this
>>> by using the BIT_ULL macro to perform the shift and avoid the overflow.
>>
>> Good catch, that should indeed have been 1ULL. I'll fold in your
>> fix, thanks!
> 
> BTW, this missed the same issue on the clear side of it, in
> io_worker_handle_work(). I've fixed that one up the same way.
> 
Ah, good, somehow the scanner missed that.

Colin

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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
  2019-10-25 13:59       ` Colin Ian King
@ 2019-10-25 13:59         ` Jens Axboe
  -1 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2019-10-25 13:59 UTC (permalink / raw)
  To: Colin Ian King, Alexander Viro, linux-fsdevel
  Cc: kernel-janitors, linux-kernel

On 10/25/19 7:59 AM, Colin Ian King wrote:
> On 25/10/2019 14:56, Jens Axboe wrote:
>> On 10/25/19 6:54 AM, Jens Axboe wrote:
>>> On 10/25/19 6:43 AM, Colin King wrote:
>>>> From: Colin Ian King <colin.king@canonical.com>
>>>>
>>>> Shifting the integer value 1U is evaluated with type unsigned int
>>>> using 32-bit arithmetic and then used in an expression that expects
>>>> a 64-bit value, so there is potentially an integer overflow. Fix this
>>>> by using the BIT_ULL macro to perform the shift and avoid the overflow.
>>>
>>> Good catch, that should indeed have been 1ULL. I'll fold in your
>>> fix, thanks!
>>
>> BTW, this missed the same issue on the clear side of it, in
>> io_worker_handle_work(). I've fixed that one up the same way.
>>
> Ah, good, somehow the scanner missed that.

Something to take a look at! :-)

-- 
Jens Axboe

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

* Re: [PATCH][next] io-wq: fix unintentional integer overflow on left shift
@ 2019-10-25 13:59         ` Jens Axboe
  0 siblings, 0 replies; 10+ messages in thread
From: Jens Axboe @ 2019-10-25 13:59 UTC (permalink / raw)
  To: Colin Ian King, Alexander Viro, linux-fsdevel
  Cc: kernel-janitors, linux-kernel

On 10/25/19 7:59 AM, Colin Ian King wrote:
> On 25/10/2019 14:56, Jens Axboe wrote:
>> On 10/25/19 6:54 AM, Jens Axboe wrote:
>>> On 10/25/19 6:43 AM, Colin King wrote:
>>>> From: Colin Ian King <colin.king@canonical.com>
>>>>
>>>> Shifting the integer value 1U is evaluated with type unsigned int
>>>> using 32-bit arithmetic and then used in an expression that expects
>>>> a 64-bit value, so there is potentially an integer overflow. Fix this
>>>> by using the BIT_ULL macro to perform the shift and avoid the overflow.
>>>
>>> Good catch, that should indeed have been 1ULL. I'll fold in your
>>> fix, thanks!
>>
>> BTW, this missed the same issue on the clear side of it, in
>> io_worker_handle_work(). I've fixed that one up the same way.
>>
> Ah, good, somehow the scanner missed that.

Something to take a look at! :-)

-- 
Jens Axboe


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

end of thread, other threads:[~2019-10-25 14:05 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-10-25 12:43 [PATCH][next] io-wq: fix unintentional integer overflow on left shift Colin King
2019-10-25 12:43 ` Colin King
2019-10-25 12:54 ` Jens Axboe
2019-10-25 12:54   ` Jens Axboe
2019-10-25 13:56   ` Jens Axboe
2019-10-25 13:56     ` Jens Axboe
2019-10-25 13:59     ` Colin Ian King
2019-10-25 13:59       ` Colin Ian King
2019-10-25 13:59       ` Jens Axboe
2019-10-25 13:59         ` Jens Axboe

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.