From: Al Viro <viro@ZenIV.linux.org.uk>
To: Alan Cox <alan@linux.intel.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Dan Williams <dan.j.williams@intel.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
linux-arch@vger.kernel.org, Andi Kleen <ak@linux.intel.com>,
Kees Cook <keescook@chromium.org>,
kernel-hardening@lists.openwall.com,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
the arch/x86 maintainers <x86@kernel.org>,
Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
Thomas Gleixner <tglx@linutronix.de>,
Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH v3 8/9] x86: use __uaccess_begin_nospec and ASM_IFENCE in get_user paths
Date: Wed, 17 Jan 2018 18:52:32 +0000 [thread overview]
Message-ID: <20180117185232.GW13338@ZenIV.linux.org.uk> (raw)
In-Reply-To: <1516198646.4184.13.camel@linux.intel.com>
On Wed, Jan 17, 2018 at 02:17:26PM +0000, Alan Cox wrote:
> On Tue, 2018-01-16 at 14:41 -0800, Linus Torvalds wrote:
> >
> >
> > On Jan 16, 2018 14:23, "Dan Williams" <dan.j.williams@intel.com>
> > wrote:
> > > That said, for get_user specifically, can we do something even
> > > cheaper. Dave H. reminds me that any valid user pointer that gets
> > > past
> > > the address limit check will have the high bit clear. So instead of
> > > calculating a mask, just unconditionally clear the high bit. It
> > > seems
> > > worse case userspace can speculatively leak something that's
> > > already
> > > in its address space.
> >
> > That's not at all true.
> >
> > The address may be a kernel address. That's the whole point of
> > 'set_fs()'.
>
> Can we kill off the remaining users of set_fs() ?
Not easily. They tend to come in pairs (the usual pattern is get_fs(),
save the result, set_fs(something), do work, set_fs(saved)), and
counting each such area as single instance we have (in my tree right
now) 121 locations. Some could be killed (and will eventually be -
the number of set_fs()/access_ok()/__{get,put}_user()/__copy_...()
call sites had been seriously decreasing during the last couple of
years), but some are really hard to kill off.
How, for example, would you deal with this one:
/*
* Receive a datagram from a UDP socket.
*/
static int svc_udp_recvfrom(struct svc_rqst *rqstp)
{
struct svc_sock *svsk =
container_of(rqstp->rq_xprt, struct svc_sock, sk_xprt);
struct svc_serv *serv = svsk->sk_xprt.xpt_server;
struct sk_buff *skb;
union {
struct cmsghdr hdr;
long all[SVC_PKTINFO_SPACE / sizeof(long)];
} buffer;
struct cmsghdr *cmh = &buffer.hdr;
struct msghdr msg = {
.msg_name = svc_addr(rqstp),
.msg_control = cmh,
.msg_controllen = sizeof(buffer),
.msg_flags = MSG_DONTWAIT,
};
...
err = kernel_recvmsg(svsk->sk_sock, &msg, NULL,
0, 0, MSG_PEEK | MSG_DONTWAIT);
With kernel_recvmsg() (and in my tree the above is its last surviving caller)
being
int kernel_recvmsg(struct socket *sock, struct msghdr *msg,
struct kvec *vec, size_t num, size_t size, int flags)
{
mm_segment_t oldfs = get_fs();
int result;
iov_iter_kvec(&msg->msg_iter, READ | ITER_KVEC, vec, num, size);
set_fs(KERNEL_DS);
result = sock_recvmsg(sock, msg, flags);
set_fs(oldfs);
return result;
}
EXPORT_SYMBOL(kernel_recvmsg);
We are asking for recvmsg() with zero data length; what we really want is
->msg_control. And _that_ is why we need that set_fs() - we want the damn
thing to go into local variable.
But note that filling ->msg_control will happen in put_cmsg(), called
from ip_cmsg_recv_pktinfo(), called from ip_cmsg_recv_offset(),
called from udp_recvmsg(), called from sock_recvmsg_nosec(), called
from sock_recvmsg(). Or in another path in case of IPv6.
Sure, we can arrange for propagation of that all way down those
call chains. My preference would be to try and mark that (one and
only) case in ->msg_flags, so that put_cmsg() would be able to
check. ___sys_recvmsg() sets that as
msg_sys->msg_flags = flags & (MSG_CMSG_CLOEXEC|MSG_CMSG_COMPAT);
so we ought to be free to use any bit other than those two. Since
put_cmsg() already checks ->msg_flags, that shouldn't put too much
overhead. But then we'll need to do something to prevent speculative
execution straying down that way, won't we? I'm not saying it can't
be done, but quite a few of the remaining call sites will take
serious work.
Incidentally, what about copy_to_iter() and friends? They
check iov_iter flavour and go either into the "copy to kernel buffer"
or "copy to userland" paths. Do we need to deal with mispredictions
there? We are calling a bunch of those on read()...
next prev parent reply other threads:[~2018-01-17 18:52 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-13 18:17 [PATCH v3 0/9] core, x86: prevent bounds-check bypass via speculative execution Dan Williams
2018-01-13 18:17 ` Dan Williams
2018-01-13 18:17 ` [PATCH v3 1/9] Documentation: document array_ptr Dan Williams
2018-01-13 18:17 ` Dan Williams
2018-01-13 18:17 ` [PATCH v3 2/9] arm64: implement ifence_array_ptr() Dan Williams
2018-01-13 18:17 ` [PATCH v3 3/9] arm: " Dan Williams
2018-01-13 18:17 ` Dan Williams
2018-01-13 18:17 ` [PATCH v3 4/9] x86: implement ifence() Dan Williams
2018-01-13 18:17 ` Dan Williams
2018-01-13 18:17 ` [PATCH v3 5/9] x86: implement ifence_array_ptr() and array_ptr_mask() Dan Williams
2018-01-13 18:17 ` Dan Williams
2018-01-13 18:17 ` [PATCH v3 6/9] asm/nospec: mask speculative execution flows Dan Williams
2018-01-13 18:17 ` Dan Williams
2018-01-13 18:18 ` [PATCH v3 7/9] x86: introduce __uaccess_begin_nospec and ASM_IFENCE Dan Williams
2018-01-13 18:18 ` Dan Williams
2018-01-13 18:18 ` [PATCH v3 8/9] x86: use __uaccess_begin_nospec and ASM_IFENCE in get_user paths Dan Williams
2018-01-13 18:18 ` Dan Williams
2018-01-13 19:05 ` Linus Torvalds
2018-01-13 19:33 ` Linus Torvalds
2018-01-13 20:22 ` Eric W. Biederman
2018-01-13 20:22 ` Eric W. Biederman
2018-01-16 22:23 ` Dan Williams
2018-01-16 22:23 ` Dan Williams
[not found] ` <CA+55aFxAFG5czVmCyhYMyHmXLNJ7pcXxWzusjZvLRh_qTGHj6Q@mail.gmail.com>
2018-01-16 22:41 ` Linus Torvalds
2018-01-17 14:17 ` Alan Cox
2018-01-17 18:52 ` Al Viro [this message]
2018-01-17 18:52 ` Al Viro
2018-01-17 19:54 ` Dan Williams
2018-01-17 19:54 ` Dan Williams
2018-01-17 20:05 ` Al Viro
2018-01-17 20:14 ` Dan Williams
2018-01-18 3:06 ` [RFC][PATCH] get rid of the use of set_fs() (by way of kernel_recvmsg()) in sunrpc Al Viro
2018-01-18 3:06 ` Al Viro
2018-01-18 3:16 ` Linus Torvalds
2018-01-18 3:16 ` Linus Torvalds
2018-01-18 4:43 ` Al Viro
2018-01-18 16:29 ` Christoph Hellwig
2018-01-18 16:29 ` Christoph Hellwig
2018-01-18 17:10 ` Al Viro
2018-01-18 19:31 ` Al Viro
2018-01-18 20:33 ` Al Viro
2018-01-19 3:27 ` Al Viro
2018-01-19 3:27 ` Al Viro
2018-01-17 19:26 ` [PATCH v3 8/9] x86: use __uaccess_begin_nospec and ASM_IFENCE in get_user paths Linus Torvalds
2018-01-17 20:01 ` Eric Dumazet
2018-01-17 20:01 ` Eric Dumazet
2018-01-18 16:38 ` Christoph Hellwig
2018-01-18 16:49 ` Linus Torvalds
2018-01-18 16:49 ` Linus Torvalds
2018-01-18 18:12 ` Al Viro
2018-01-17 4:30 ` Dan Williams
2018-01-17 6:28 ` Al Viro
2018-01-17 6:28 ` Al Viro
2018-01-17 6:50 ` Dan Williams
2018-01-17 6:50 ` Dan Williams
2018-01-17 10:07 ` David Laight
2018-01-17 10:07 ` David Laight
2018-01-17 18:12 ` Dan Williams
2018-01-17 19:16 ` Linus Torvalds
2018-01-17 19:16 ` Linus Torvalds
2018-01-13 18:18 ` [PATCH v3 9/9] vfs, fdtable: prevent bounds-check bypass via speculative execution Dan Williams
2018-01-13 18:18 ` Dan Williams
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=20180117185232.GW13338@ZenIV.linux.org.uk \
--to=viro@zeniv.linux.org.uk \
--cc=ak@linux.intel.com \
--cc=akpm@linux-foundation.org \
--cc=alan@linux.intel.com \
--cc=dan.j.williams@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=kernel-hardening@lists.openwall.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/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).