diff mbox

libceph: use 64-bit arithmetic instead of 32-bit

Message ID 20180131052948.GA16419@embeddedgus (mailing list archive)
State New, archived
Headers show

Commit Message

Gustavo A. R. Silva Jan. 31, 2018, 5:29 a.m. UTC
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(-)

Comments

Ilya Dryomov Jan. 31, 2018, 9:39 a.m. UTC | #1
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
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Gustavo A. R. Silva Jan. 31, 2018, 12:02 p.m. UTC | #2
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





--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

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 */