[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Thu, 9 Sep 2021 15:51:23 -0700
From: Kees Cook <keescook@...omium.org>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: kernel test robot <lkp@...el.com>,
Matt Porter <mporter@...nel.crashing.org>,
Alexandre Bounine <alex.bou9@...il.com>,
Jing Xiangfeng <jingxiangfeng@...wei.com>,
Ira Weiny <ira.weiny@...el.com>,
John Hubbard <jhubbard@...dia.com>,
Souptick Joarder <jrdr.linux@...il.com>,
"Gustavo A . R . Silva" <gustavoars@...nel.org>,
Dan Carpenter <dan.carpenter@...cle.com>,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH] rapidio: Avoid bogus __alloc_size warning
On Thu, Sep 09, 2021 at 01:27:52PM -0700, Andrew Morton wrote:
> On Thu, 9 Sep 2021 09:14:09 -0700 Kees Cook <keescook@...omium.org> wrote:
>
> > GCC 9.3 (but not later) incorrectly evaluates the arguments to
> > check_copy_size(), getting seemingly confused by the size being returned
> > from array_size(). Instead, perform the calculation once, which both
> > makes the code more readable and avoids the bug in GCC.
> >
> > In file included from arch/x86/include/asm/preempt.h:7,
> > from include/linux/preempt.h:78,
> > from include/linux/spinlock.h:55,
> > from include/linux/mm_types.h:9,
> > from include/linux/buildid.h:5,
> > from include/linux/module.h:14,
> > from drivers/rapidio/devices/rio_mport_cdev.c:13:
> > In function 'check_copy_size',
> > inlined from 'copy_from_user' at include/linux/uaccess.h:191:6,
> > inlined from 'rio_mport_transfer_ioctl' at drivers/rapidio/devices/rio_mport_cdev.c:983:6:
> > include/linux/thread_info.h:213:4: error: call to '__bad_copy_to' declared with attribute error: copy destination size is too small
> > 213 | __bad_copy_to();
> > | ^~~~~~~~~~~~~~~
> >
> > But the allocation size and the copy size are identical:
> >
> > transfer = vmalloc(array_size(sizeof(*transfer), transaction.count));
> > if (!transfer)
> > return -ENOMEM;
> >
> > if (unlikely(copy_from_user(transfer,
> > (void __user *)(uintptr_t)transaction.block,
> > array_size(sizeof(*transfer), transaction.count)))) {
>
> That's an "error", not a warning. Or is this thanks to the new -Werror?
This is a "regular" error (__bad_copy_to() uses __compiletime_error()).
> Either way, I'm inclined to cc:stable on this, because use of gcc-9 on
> older kernels will be a common thing down the ages.
>
> If it's really an "error" on non-Werror kernels then definitely cc:stable.
I would expect that as only being needed if __alloc_size was backported
to -stable, which seems unlikely.
--
Kees Cook
Powered by blists - more mailing lists