Messages in this thread | | | Date | Wed, 18 May 2022 13:41:59 -0700 | Subject | Re: [PATCH bpf v3 1/2] bpf_trace: check size for overflow in bpf_kprobe_multi_link_attach | From | Yonghong Song <> |
| |
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.
| |