Re: [PATCH bpf] xdp: Prevent overflow in devmap_hash cost calculation for 32-bit builds

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jakub Kicinski <jakub.kicinski@xxxxxxxxxxxxx> writes:

> On Thu, 17 Oct 2019 12:57:02 +0200, Toke Høiland-Jørgensen wrote:
>> Tetsuo pointed out that without an explicit cast, the cost calculation for
>> devmap_hash type maps could overflow on 32-bit builds. This adds the
>> missing cast.
>> 
>> Fixes: 6f9d451ab1a3 ("xdp: Add devmap_hash map type for looking up devices by hashed index")
>> Reported-by: Tetsuo Handa <penguin-kernel@xxxxxxxxxxxxxxxxxxx>
>> Signed-off-by: Toke Høiland-Jørgensen <toke@xxxxxxxxxx>
>> ---
>>  kernel/bpf/devmap.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c
>> index a0a1153da5ae..e34fac6022eb 100644
>> --- a/kernel/bpf/devmap.c
>> +++ b/kernel/bpf/devmap.c
>> @@ -128,7 +128,7 @@ static int dev_map_init_map(struct bpf_dtab *dtab, union bpf_attr *attr)
>>  
>>  		if (!dtab->n_buckets) /* Overflow check */
>>  			return -EINVAL;
>> -		cost += sizeof(struct hlist_head) * dtab->n_buckets;
>> +		cost += (u64) sizeof(struct hlist_head) * dtab->n_buckets;
>
> array_size()?

Well, array_size does this:

	if (check_mul_overflow(a, b, &bytes))
		return SIZE_MAX;

However, we don't to return SIZE_MAX on overflow, we want the
calculation itself to be done in 64 bits so it won't overflow... Or?

-Toke





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux