lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <202301271824.851168A@keescook>
Date:   Tue, 31 Jan 2023 17:01:56 -0800
From:   Kees Cook <keescook@...omium.org>
To:     Jason Gunthorpe <jgg@...pe.ca>
Cc:     Kevin Tian <kevin.tian@...el.com>, Joerg Roedel <joro@...tes.org>,
        Will Deacon <will@...nel.org>,
        Robin Murphy <robin.murphy@....com>, iommu@...ts.linux.dev,
        linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH] iommufd: Add top-level bounds check on kernel buffer size

On Fri, Jan 27, 2023 at 09:13:31PM -0400, Jason Gunthorpe wrote:
> On Fri, Jan 27, 2023 at 04:57:26PM -0800, Kees Cook wrote:
> > On Fri, Jan 27, 2023 at 08:47:34PM -0400, Jason Gunthorpe wrote:
> > > On Fri, Jan 27, 2023 at 02:38:17PM -0800, Kees Cook wrote:
> > > > While the op->size assignments are already bounds-checked at static
> > > > initializer time, these limits aren't aggregated and tracked when doing
> > > > later variable range checking under -Warray-bounds. Help the compiler
> > > > see that we know what we're talking about, and we'll never ask to
> > > > write more that sizeof(ucmd.cmd) bytes during the memset() inside
> > > > copy_struct_from_user(). Seen under GCC 13:
> > > > 
> > > > In function 'copy_struct_from_user',
> > > >     inlined from 'iommufd_fops_ioctl' at ../drivers/iommu/iommufd/main.c:333:8:
> > > > ../include/linux/fortify-string.h:59:33: warning: '__builtin_memset' offset [57, 4294967294] is out of the bounds [0, 56] of object 'buf' with type 'union ucmd_buffer' [-Warray-bounds=]
> > > >    59 | #define __underlying_memset     __builtin_memset
> > > 
> > > This seems strange to me
> > > 
> > > I thought the way gcc handled this was if it knew the value must be in
> > > a certain range then it would check it
> > > 
> > > If it couldn't figure out any ranges it would not make a warning.
> > > 
> > > So why did it decide "rest" was in that really weird range?
> > 
> > It's because it got bounds-checked at the lower end (for the minimum
> > size test).
> 
> Where? There is no sizeof(ucmd.ubuffer) in this code.

memset() is internally doing that via __builtin_object_size(dst + size, 1).

> There are no statically computable constants at all.

I think it's some logic that excludes a range based on ucmd.user_size
internally to the additional checks in copy_struct_from_user().

Regardless, I think the correct fix should be with
copy_struct_from_user(), so please disregard this patch. :)

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ