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] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGXu5j+_Ao_CU8DG9nrTbx5ioDkJUFw0cGcLBMWnvNLe_eFJ4A@mail.gmail.com>
Date:   Wed, 13 Mar 2019 08:35:33 -0700
From:   Kees Cook <keescook@...omium.org>
To:     Jan Kara <jack@...e.cz>
Cc:     syzbot <syzbot+2c49971e251e36216d1f@...kaller.appspotmail.com>,
        Amir Goldstein <amir73il@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>, cai@....pw,
        Chris von Recklinghausen <crecklin@...hat.com>,
        LKML <linux-kernel@...r.kernel.org>,
        Linux-MM <linux-mm@...ck.org>,
        syzkaller-bugs <syzkaller-bugs@...glegroups.com>
Subject: Re: WARNING: bad usercopy in fanotify_read

On Wed, Mar 13, 2019 at 7:35 AM Jan Kara <jack@...e.cz> wrote:
> On Tue 12-03-19 23:26:22, Kees Cook wrote:
> > On Mon, Mar 11, 2019 at 1:42 PM syzbot
> > <syzbot+2c49971e251e36216d1f@...kaller.appspotmail.com> wrote:
> > > C reproducer:   https://syzkaller.appspot.com/x/repro.c?x=17ee410b200000
> > > [...]
> > > ------------[ cut here ]------------
> > > Bad or missing usercopy whitelist? Kernel memory exposure attempt detected
> > > from SLAB object 'fanotify_event' (offset 40, size 8)!
> > > [...]
> > >   copy_to_user include/linux/uaccess.h:151 [inline]
> > >   copy_fid_to_user fs/notify/fanotify/fanotify_user.c:236 [inline]
> > >   copy_event_to_user fs/notify/fanotify/fanotify_user.c:294 [inline]
> >
> > Looks like this is the fh/ext_fh union in struct fanotify_fid, field
> > "fid" in struct fanotify_event. Given that "fid" is itself in a union
> > against a struct path, I think instead of a whitelist using
> > KMEM_CACHE_USERCOPY(), this should just use a bounce buffer to avoid
> > leaving a whitelist open for path or ext_fh exposure.
>
> Do you mean to protect it from a situation when some other code (i.e. not
> copy_fid_to_user()) would be tricked into copying ext_fh containing slab
> pointer to userspace?

Yes. That's the design around the usercopy hardening. The
"whitelisting" is either via code (with a bounce buffer, so only the
specific "expected" code path can copy it), with a
kmem_create_usercopy() range marking (generally best for areas that
are not unions or when bounce buffers would be too big/slow), or with
implicit whitelisting (via a constant copy size that cannot change at
run-time, like: copy_to_user(dst, src, 6)).

In this case, since there are multiple unions in place and
FANOTIFY_INLINE_FH_LEN is small, it seemed best to go with a bounce
buffer.

-- 
Kees Cook

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ