Re: [PATCH bpf v3 1/2] bpf_trace: check size for overflow in bpf_kprobe_multi_link_attach

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

 





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.



[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