From: Kees Cook <keescook@chromium.org>
To: syzbot <syzbot+2c49971e251e36216d1f@syzkaller.appspotmail.com>,
Amir Goldstein <amir73il@gmail.com>, Jan Kara <jack@suse.cz>
Cc: Andrew Morton <akpm@linux-foundation.org>,
cai@lca.pw, Chris von Recklinghausen <crecklin@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
Linux-MM <linux-mm@kvack.org>,
syzkaller-bugs <syzkaller-bugs@googlegroups.com>
Subject: Re: WARNING: bad usercopy in fanotify_read
Date: Tue, 12 Mar 2019 23:26:22 -0700 [thread overview]
Message-ID: <CAGXu5jKjWwYk5N3mOH1A8fXX_0BT3r1At_3MzN9M+Ckg5irKXg@mail.gmail.com> (raw)
In-Reply-To: <00000000000016f7d40583d79bd9@google.com>
On Mon, Mar 11, 2019 at 1:42 PM syzbot
<syzbot+2c49971e251e36216d1f@syzkaller.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.
Maybe something like this (untested):
diff --git a/fs/notify/fanotify/fanotify_user.c
b/fs/notify/fanotify/fanotify_user.c
index 56992b32c6bb..b87da9580b3c 100644
--- a/fs/notify/fanotify/fanotify_user.c
+++ b/fs/notify/fanotify/fanotify_user.c
@@ -207,6 +207,7 @@ static int process_access_response(struct
fsnotify_group *group,
static int copy_fid_to_user(struct fanotify_event *event, char __user *buf)
{
struct fanotify_event_info_fid info = { };
+ unsigned char bounce[FANOTIFY_INLINE_FH_LEN], *fh;
struct file_handle handle = { };
size_t fh_len = event->fh_len;
size_t len = fanotify_event_info_len(event);
@@ -233,7 +234,18 @@ static int copy_fid_to_user(struct fanotify_event
*event, char __user *buf)
buf += sizeof(handle);
len -= sizeof(handle);
- if (copy_to_user(buf, fanotify_event_fh(event), fh_len))
+
+ /*
+ * For an inline fh, copy through stack to exclude the copy from
+ * usercopy hardening protections.
+ */
+ fh = fanotify_event_fh(event);
+ if (fh_len <= sizeof(bounce)) {
+ memcpy(bounce, fh, fh_len);
+ fh = bounce;
+ }
+
+ if (copy_to_user(buf, fh, fh_len))
return -EFAULT;
/* Pad with 0's */
--
Kees Cook
next prev parent reply other threads:[~2019-03-13 6:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-11 20:42 WARNING: bad usercopy in fanotify_read syzbot
2019-03-13 6:26 ` Kees Cook [this message]
2019-03-13 6:42 ` Amir Goldstein
2019-03-13 14:35 ` Jan Kara
2019-03-13 15:35 ` Kees Cook
2019-03-13 15:47 ` Jan Kara
2019-03-18 18:27 ` Kees Cook
2019-03-19 8:32 ` Jan Kara
2019-03-16 14:49 ` syzbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAGXu5jKjWwYk5N3mOH1A8fXX_0BT3r1At_3MzN9M+Ckg5irKXg@mail.gmail.com \
--to=keescook@chromium.org \
--cc=akpm@linux-foundation.org \
--cc=amir73il@gmail.com \
--cc=cai@lca.pw \
--cc=crecklin@redhat.com \
--cc=jack@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=syzbot+2c49971e251e36216d1f@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).