lkml.org 
[lkml]   [2022]   [May]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH bpf v3 1/2] bpf_trace: check size for overflow in bpf_kprobe_multi_link_attach
From


On 5/18/22 1:00 PM, Eugene Syromiatnikov wrote:
> On Wed, May 18, 2022 at 09:34:22AM -0700, Yonghong Song wrote:
>> On 5/18/22 5:22 AM, Eugene Syromiatnikov wrote:
>>> - size = cnt * sizeof(*syms);
>>> + if (check_mul_overflow(cnt, (u32)sizeof(*syms), &size))
>>> + return -EOVERFLOW;
>>
>> In mm/util.c kvmalloc_node(), we have
>>
>> /* Don't even allow crazy sizes */
>> if (unlikely(size > INT_MAX)) {
>> WARN_ON_ONCE(!(flags & __GFP_NOWARN));
>> return NULL;
>> }
>>
>> Basically the maximum size to be allocated in INT_MAX.
>>
>> Here, we have 'size' as u32, which means if the size is 0xffff0000,
>> the check_mul_overflow will return false (no overflow) but
>> kvzalloc will still have a warning.
>>
>> I think we should change the type of 'size' to be 'int' which
>> should catch the above case and be consistent with
>> what kvmalloc_node() intends to warn.
>
> Huh, it's a bitmore complicated as check_mul_overflow requires types to
> match; what do you think about
>
> + if (check_mul_overflow(cnt, (u32)sizeof(*syms), &size) || size > INT_MAX)
>
> ?

This works for me.

\
 
 \ /
  Last update: 2022-05-18 22:50    [W:0.250 / U:0.184 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site