linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libceph: use 64-bit arithmetic instead of 32-bit
@ 2018-01-31  5:29 Gustavo A. R. Silva
  2018-01-31  9:39 ` Ilya Dryomov
  0 siblings, 1 reply; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-01-31  5:29 UTC (permalink / raw)
  To: Ilya Dryomov, Yan, Zheng, Sage Weil, David S. Miller
  Cc: ceph-devel, netdev, linux-kernel, Gustavo A. R. Silva

Cast objsetno to u64 in order to give the compiler complete
information about the proper arithmetic to use. Notice
that this variable is used in a context that expects an
expression of type u64 (64 bits, unsigned).

The expression objsetno * sc + stripepos is currently
being evaluated using 32-bit arithmetic.

In general, the use of incorrect arithmetic has security
implications.

Addresses-Coverity-ID: 200686
Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
---
 net/ceph/osdmap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
index 0da27c6..58dc965 100644
--- a/net/ceph/osdmap.c
+++ b/net/ceph/osdmap.c
@@ -2183,7 +2183,7 @@ int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
 	stripepos = bl % sc;
 	objsetno = stripeno / su_per_object;
 
-	*ono = objsetno * sc + stripepos;
+	*ono = (u64)objsetno * sc + stripepos;
 	dout("objset %u * sc %u = ono %u\n", objsetno, sc, (unsigned int)*ono);
 
 	/* *oxoff = *off % layout->fl_stripe_unit;  # offset in su */
-- 
2.7.4

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

* Re: [PATCH] libceph: use 64-bit arithmetic instead of 32-bit
  2018-01-31  5:29 [PATCH] libceph: use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
@ 2018-01-31  9:39 ` Ilya Dryomov
  2018-01-31 12:02   ` Gustavo A. R. Silva
  0 siblings, 1 reply; 3+ messages in thread
From: Ilya Dryomov @ 2018-01-31  9:39 UTC (permalink / raw)
  To: Gustavo A. R. Silva
  Cc: Yan, Zheng, Sage Weil, David S. Miller, Ceph Development, netdev,
	linux-kernel, Gustavo A. R. Silva

On Wed, Jan 31, 2018 at 6:29 AM, Gustavo A. R. Silva
<gustavo@embeddedor.com> wrote:
> Cast objsetno to u64 in order to give the compiler complete
> information about the proper arithmetic to use. Notice
> that this variable is used in a context that expects an
> expression of type u64 (64 bits, unsigned).
>
> The expression objsetno * sc + stripepos is currently
> being evaluated using 32-bit arithmetic.
>
> In general, the use of incorrect arithmetic has security
> implications.
>
> Addresses-Coverity-ID: 200686
> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
> ---
>  net/ceph/osdmap.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
> index 0da27c6..58dc965 100644
> --- a/net/ceph/osdmap.c
> +++ b/net/ceph/osdmap.c
> @@ -2183,7 +2183,7 @@ int ceph_calc_file_object_mapping(struct ceph_file_layout *layout,
>         stripepos = bl % sc;
>         objsetno = stripeno / su_per_object;
>
> -       *ono = objsetno * sc + stripepos;
> +       *ono = (u64)objsetno * sc + stripepos;
>         dout("objset %u * sc %u = ono %u\n", objsetno, sc, (unsigned int)*ono);
>
>         /* *oxoff = *off % layout->fl_stripe_unit;  # offset in su */

Hi Gustavo,

This (and other u32/u64 issues in this function, is this the only
warning?) is fixed in my striping v2 work branch.  I wasn't going to
push that patch separately, but I guess I should post it.

Thanks,

                Ilya

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

* Re: [PATCH] libceph: use 64-bit arithmetic instead of 32-bit
  2018-01-31  9:39 ` Ilya Dryomov
@ 2018-01-31 12:02   ` Gustavo A. R. Silva
  0 siblings, 0 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2018-01-31 12:02 UTC (permalink / raw)
  To: Ilya Dryomov
  Cc: Gustavo A. R. Silva, Yan, Zheng, Sage Weil, David S. Miller,
	Ceph Development, netdev, linux-kernel

Hello Ilya,

Quoting Ilya Dryomov <idryomov@gmail.com>:

> On Wed, Jan 31, 2018 at 6:29 AM, Gustavo A. R. Silva
> <gustavo@embeddedor.com> wrote:
>> Cast objsetno to u64 in order to give the compiler complete
>> information about the proper arithmetic to use. Notice
>> that this variable is used in a context that expects an
>> expression of type u64 (64 bits, unsigned).
>>
>> The expression objsetno * sc + stripepos is currently
>> being evaluated using 32-bit arithmetic.
>>
>> In general, the use of incorrect arithmetic has security
>> implications.
>>
>> Addresses-Coverity-ID: 200686
>> Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
>> ---
>>  net/ceph/osdmap.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/net/ceph/osdmap.c b/net/ceph/osdmap.c
>> index 0da27c6..58dc965 100644
>> --- a/net/ceph/osdmap.c
>> +++ b/net/ceph/osdmap.c
>> @@ -2183,7 +2183,7 @@ int ceph_calc_file_object_mapping(struct  
>> ceph_file_layout *layout,
>>         stripepos = bl % sc;
>>         objsetno = stripeno / su_per_object;
>>
>> -       *ono = objsetno * sc + stripepos;
>> +       *ono = (u64)objsetno * sc + stripepos;
>>         dout("objset %u * sc %u = ono %u\n", objsetno, sc,  
>> (unsigned int)*ono);
>>
>>         /* *oxoff = *off % layout->fl_stripe_unit;  # offset in su */
>
> Hi Gustavo,
>
> This (and other u32/u64 issues in this function, is this the only
> warning?) is fixed in my striping v2 work branch.  I wasn't going to
> push that patch separately, but I guess I should post it.
>

Yeah, this was the only one warning reported by Coverity in this  
particular module.

Thanks
--
Gustavo

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

end of thread, other threads:[~2018-01-31 12:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-31  5:29 [PATCH] libceph: use 64-bit arithmetic instead of 32-bit Gustavo A. R. Silva
2018-01-31  9:39 ` Ilya Dryomov
2018-01-31 12:02   ` Gustavo A. R. Silva

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).