David Miller
2020-Jul-24 22:43 UTC
[Bridge] get rid of the address_space override in setsockopt v2
From: Christoph Hellwig <hch at lst.de> Date: Thu, 23 Jul 2020 08:08:42 +0200> setsockopt is the last place in architecture-independ code that still > uses set_fs to force the uaccess routines to operate on kernel pointers. > > This series adds a new sockptr_t type that can contained either a kernel > or user pointer, and which has accessors that do the right thing, and > then uses it for setsockopt, starting by refactoring some low-level > helpers and moving them over to it before finally doing the main > setsockopt method. > > Note that apparently the eBPF selftests do not even cover this path, so > the series has been tested with a testing patch that always copies the > data first and passes a kernel pointer. This is something that works for > most common sockopts (and is something that the ePBF support relies on), > but unfortunately in various corner cases we either don't use the passed > in length, or in one case actually copy data back from setsockopt, or in > case of bpfilter straight out do not work with kernel pointers at all. > > Against net-next/master. > > Changes since v1: > - check that users don't pass in kernel addresses > - more bpfilter cleanups > - cosmetic mptcp tweakSeries applied to net-next, I'm build testing and will push this out when that is done. Thanks.
Christoph Hellwig
2020-Jul-26 07:03 UTC
[Bridge] get rid of the address_space override in setsockopt v2
On Fri, Jul 24, 2020 at 03:43:42PM -0700, David Miller wrote:> > Changes since v1: > > - check that users don't pass in kernel addresses > > - more bpfilter cleanups > > - cosmetic mptcp tweak > > Series applied to net-next, I'm build testing and will push this out when > that is done.The buildbot found one warning with the isdn debug code after a few days, here is what I think is the best fix: --->From 6601732f7a54db5f04efba08f7e9224e5b757112 Mon Sep 17 00:00:00 2001From: Christoph Hellwig <hch at lst.de> Date: Sun, 26 Jul 2020 09:00:09 +0200 Subject: mISDN: remove a debug printk in data_sock_setsockopt The %p won't work with the new sockptr_t type. But in the times of ftrace, bpftrace and co these kinds of debug printks are pretty anyway, so just remove the whole debug printk. Signed-off-by: Christoph Hellwig <hch at lst.de> --- drivers/isdn/mISDN/socket.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drivers/isdn/mISDN/socket.c b/drivers/isdn/mISDN/socket.c index 1b2b91479107bc..2c58a6fe6d129e 100644 --- a/drivers/isdn/mISDN/socket.c +++ b/drivers/isdn/mISDN/socket.c @@ -406,10 +406,6 @@ static int data_sock_setsockopt(struct socket *sock, int level, int optname, struct sock *sk = sock->sk; int err = 0, opt = 0; - if (*debug & DEBUG_SOCKET) - printk(KERN_DEBUG "%s(%p, %d, %x, %p, %d)\n", __func__, sock, - level, optname, optval, len); - lock_sock(sk); switch (optname) { -- 2.27.0
David Laight
2020-Jul-27 09:51 UTC
[Bridge] get rid of the address_space override in setsockopt v2
From: David Miller> Sent: 24 July 2020 23:44 > > From: Christoph Hellwig <hch at lst.de> > Date: Thu, 23 Jul 2020 08:08:42 +0200 > > > setsockopt is the last place in architecture-independ code that still > > uses set_fs to force the uaccess routines to operate on kernel pointers. > > > > This series adds a new sockptr_t type that can contained either a kernel > > or user pointer, and which has accessors that do the right thing, and > > then uses it for setsockopt, starting by refactoring some low-level > > helpers and moving them over to it before finally doing the main > > setsockopt method. > > > > Note that apparently the eBPF selftests do not even cover this path, so > > the series has been tested with a testing patch that always copies the > > data first and passes a kernel pointer. This is something that works for > > most common sockopts (and is something that the ePBF support relies on), > > but unfortunately in various corner cases we either don't use the passed > > in length, or in one case actually copy data back from setsockopt, or in > > case of bpfilter straight out do not work with kernel pointers at all. > > > > Against net-next/master. > > > > Changes since v1: > > - check that users don't pass in kernel addresses > > - more bpfilter cleanups > > - cosmetic mptcp tweak > > Series applied to net-next, I'm build testing and will push this out when > that is done.Hmmm... this code does: int __sys_setsockopt(int fd, int level, int optname, char __user *user_optval, int optlen) { sockptr_t optval; char *kernel_optval = NULL; int err, fput_needed; struct socket *sock; if (optlen < 0) return -EINVAL; err = init_user_sockptr(&optval, user_optval); if (err) return err; And the called code does: if (copy_from_sockptr(&opt, optbuf, sizeof(opt))) return -EFAULT; Which means that only the base of the user's buffer is checked for being in userspace. I'm sure there is code that processes options in chunks. This probably means it is possible to put a chunk boundary at the end of userspace and continue processing the very start of kernel memory. At best this faults on the kernel copy code and crashes the system. Maybe there wasn't any code that actually incremented the user address. But it is hardly robust. David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)