public inbox for dccp@vger.kernel.org
 help / color / mirror / Atom feed
* get rid of the address_space override in setsockopt
@ 2020-07-20 12:47 Christoph Hellwig
  2020-07-20 16:38 ` Eric Biggers
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Christoph Hellwig @ 2020-07-20 12:47 UTC (permalink / raw)
  To: dccp

Hi Dave,

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 I could not get the eBPF selftests to work, so this 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, so we unfortunately
can't just always do the copy in the highlevel code, which would have
been much nicer.


Diffstt:
 crypto/af_alg.c                           |    7 
 drivers/crypto/chelsio/chtls/chtls_main.c |   18 -
 drivers/isdn/mISDN/socket.c               |    4 
 include/linux/bpfilter.h                  |    6 
 include/linux/filter.h                    |    3 
 include/linux/mroute.h                    |    5 
 include/linux/mroute6.h                   |    8 
 include/linux/net.h                       |    4 
 include/linux/netfilter.h                 |    6 
 include/linux/netfilter/x_tables.h        |    4 
 include/linux/sockptr.h                   |  121 +++++++++++
 include/net/inet_connection_sock.h        |    3 
 include/net/ip.h                          |    7 
 include/net/ipv6.h                        |    6 
 include/net/sctp/structs.h                |    2 
 include/net/sock.h                        |    7 
 include/net/tcp.h                         |    6 
 include/net/udp.h                         |    2 
 include/net/xfrm.h                        |    8 
 net/atm/common.c                          |    6 
 net/atm/common.h                          |    2 
 net/atm/pvc.c                             |    2 
 net/atm/svc.c                             |    6 
 net/ax25/af_ax25.c                        |    6 
 net/bluetooth/hci_sock.c                  |    8 
 net/bluetooth/l2cap_sock.c                |   22 +-
 net/bluetooth/rfcomm/sock.c               |   12 -
 net/bluetooth/sco.c                       |    6 
 net/bpfilter/bpfilter_kern.c              |   11 -
 net/bridge/netfilter/ebtables.c           |   46 +---
 net/caif/caif_socket.c                    |    8 
 net/can/j1939/socket.c                    |   12 -
 net/can/raw.c                             |   16 -
 net/core/filter.c                         |    6 
 net/core/sock.c                           |   36 +--
 net/dccp/dccp.h                           |    2 
 net/dccp/proto.c                          |   20 -
 net/decnet/af_decnet.c                    |   13 -
 net/ieee802154/socket.c                   |    6 
 net/ipv4/bpfilter/sockopt.c               |    8 
 net/ipv4/ip_options.c                     |   43 +---
 net/ipv4/ip_sockglue.c                    |   66 +++---
 net/ipv4/ipmr.c                           |   14 -
 net/ipv4/netfilter/arp_tables.c           |   33 +--
 net/ipv4/netfilter/ip_tables.c            |   29 +-
 net/ipv4/raw.c                            |    8 
 net/ipv4/tcp.c                            |   30 +-
 net/ipv4/tcp_ipv4.c                       |    4 
 net/ipv4/udp.c                            |   11 -
 net/ipv4/udp_impl.h                       |    4 
 net/ipv6/ip6_flowlabel.c                  |  317 ++++++++++++++++--------------
 net/ipv6/ip6mr.c                          |   17 -
 net/ipv6/ipv6_sockglue.c                  |  203 +++++++++----------
 net/ipv6/netfilter/ip6_tables.c           |   28 +-
 net/ipv6/raw.c                            |   10 
 net/ipv6/tcp_ipv6.c                       |    4 
 net/ipv6/udp.c                            |    7 
 net/ipv6/udp_impl.h                       |    4 
 net/iucv/af_iucv.c                        |    4 
 net/kcm/kcmsock.c                         |    6 
 net/l2tp/l2tp_ppp.c                       |    4 
 net/llc/af_llc.c                          |    4 
 net/mptcp/protocol.c                      |   12 -
 net/netfilter/ipvs/ip_vs_ctl.c            |    4 
 net/netfilter/nf_sockopt.c                |    2 
 net/netfilter/x_tables.c                  |   20 -
 net/netlink/af_netlink.c                  |    4 
 net/netrom/af_netrom.c                    |    4 
 net/nfc/llcp_sock.c                       |    6 
 net/packet/af_packet.c                    |   39 +--
 net/phonet/pep.c                          |    4 
 net/rds/af_rds.c                          |   30 +-
 net/rds/rdma.c                            |   14 -
 net/rds/rds.h                             |    6 
 net/rose/af_rose.c                        |    4 
 net/rxrpc/af_rxrpc.c                      |    8 
 net/rxrpc/ar-internal.h                   |    4 
 net/rxrpc/key.c                           |    9 
 net/sctp/socket.c                         |    4 
 net/smc/af_smc.c                          |    4 
 net/socket.c                              |   20 -
 net/tipc/socket.c                         |    8 
 net/tls/tls_main.c                        |   17 -
 net/vmw_vsock/af_vsock.c                  |    4 
 net/x25/af_x25.c                          |    4 
 net/xdp/xsk.c                             |    8 
 net/xfrm/xfrm_state.c                     |    6 
 87 files changed, 855 insertions(+), 721 deletions(-)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
@ 2020-07-20 16:38 ` Eric Biggers
  2020-07-20 17:43 ` Christoph Hellwig
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Eric Biggers @ 2020-07-20 16:38 UTC (permalink / raw)
  To: dccp

On Mon, Jul 20, 2020 at 02:47:13PM +0200, Christoph Hellwig wrote:
> Hi Dave,
> 
> 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 I could not get the eBPF selftests to work, so this 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, so we unfortunately
> can't just always do the copy in the highlevel code, which would have
> been much nicer.
> 

Please mention what git tree your patchset applies to.

- Eric

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
  2020-07-20 16:38 ` Eric Biggers
@ 2020-07-20 17:43 ` Christoph Hellwig
  2020-07-20 20:47 ` Alexei Starovoitov
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2020-07-20 17:43 UTC (permalink / raw)
  To: dccp

On Mon, Jul 20, 2020 at 09:38:36AM -0700, Eric Biggers wrote:
> Please mention what git tree your patchset applies to.

net-next/master

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
  2020-07-20 16:38 ` Eric Biggers
  2020-07-20 17:43 ` Christoph Hellwig
@ 2020-07-20 20:47 ` Alexei Starovoitov
  2020-07-21  9:38 ` David Laight
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Alexei Starovoitov @ 2020-07-20 20:47 UTC (permalink / raw)
  To: dccp

On Mon, Jul 20, 2020 at 02:47:13PM +0200, Christoph Hellwig wrote:
> Hi Dave,
> 
> 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 I could not get the eBPF selftests to work, so this 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, so we unfortunately
> can't just always do the copy in the highlevel code, which would have
> been much nicer.

could you rebase on bpf-next tree and we can route it this way then?
we'll also test the whole thing before applying.

sounds like v2 is needed anyway to address Eric's addr space concern?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (2 preceding siblings ...)
  2020-07-20 20:47 ` Alexei Starovoitov
@ 2020-07-21  9:38 ` David Laight
  2020-07-21 10:26 ` David Laight
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2020-07-21  9:38 UTC (permalink / raw)
  To: dccp

From: Christoph Hellwig
> Sent: 20 July 2020 13:47
>
> 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.

Are you planning to make the equivalent change to getsockopt()?
Having mismatched interfaces would be very strange.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (3 preceding siblings ...)
  2020-07-21  9:38 ` David Laight
@ 2020-07-21 10:26 ` David Laight
  2020-07-22  7:56 ` Christoph Hellwig
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2020-07-21 10:26 UTC (permalink / raw)
  To: dccp

From: Christoph Hellwig
> Sent: 20 July 2020 13:47
> 
> 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.

Another 'gotcha' ...

On an least some architectures (possibly only m68k) IIRC all structures
are actually passed by reference.
(This used to be true for sparc - but it may have changed in the
last 30 years.)

	David
 

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (4 preceding siblings ...)
  2020-07-21 10:26 ` David Laight
@ 2020-07-22  7:56 ` Christoph Hellwig
  2020-07-22  8:06 ` 'Christoph Hellwig'
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2020-07-22  7:56 UTC (permalink / raw)
  To: dccp

On Mon, Jul 20, 2020 at 01:47:56PM -0700, Alexei Starovoitov wrote:
> > 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, so we unfortunately
> > can't just always do the copy in the highlevel code, which would have
> > been much nicer.
> 
> could you rebase on bpf-next tree and we can route it this way then?
> we'll also test the whole thing before applying.

The bpf-next tree is missing all my previous setsockopt cleanups, so
there series won't apply.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (5 preceding siblings ...)
  2020-07-22  7:56 ` Christoph Hellwig
@ 2020-07-22  8:06 ` 'Christoph Hellwig'
  2020-07-22  8:07 ` 'Christoph Hellwig'
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: 'Christoph Hellwig' @ 2020-07-22  8:06 UTC (permalink / raw)
  To: dccp

On Tue, Jul 21, 2020 at 09:38:23AM +0000, David Laight wrote:
> From: Christoph Hellwig
> > Sent: 20 July 2020 13:47
> >
> > 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.
> 
> Are you planning to make the equivalent change to getsockopt()?

No.  Only setsockopt can be fed kernel addresses from bpf-cgroup.
There is no point in complicating the read side interface when it
doesn't have that problem.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (6 preceding siblings ...)
  2020-07-22  8:06 ` 'Christoph Hellwig'
@ 2020-07-22  8:07 ` 'Christoph Hellwig'
  2020-07-22  8:21 ` David Laight
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: 'Christoph Hellwig' @ 2020-07-22  8:07 UTC (permalink / raw)
  To: dccp

On Tue, Jul 21, 2020 at 10:26:58AM +0000, David Laight wrote:
> From: Christoph Hellwig
> > Sent: 20 July 2020 13:47
> > 
> > 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.
> 
> Another 'gotcha' ...
> 
> On an least some architectures (possibly only m68k) IIRC all structures
> are actually passed by reference.
> (This used to be true for sparc - but it may have changed in the
> last 30 years.)

Tough luck for ABIs wit suboptimal calling conventions.  At least we can
do the right thing for those that do not have the problem.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (7 preceding siblings ...)
  2020-07-22  8:07 ` 'Christoph Hellwig'
@ 2020-07-22  8:21 ` David Laight
  2020-07-22 17:09 ` Alexei Starovoitov
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2020-07-22  8:21 UTC (permalink / raw)
  To: dccp

From: 'Christoph Hellwig'
> Sent: 22 July 2020 09:07
> On Tue, Jul 21, 2020 at 09:38:23AM +0000, David Laight wrote:
> > From: Christoph Hellwig
> > > Sent: 20 July 2020 13:47
> > >
> > > 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.
> >
> > Are you planning to make the equivalent change to getsockopt()?
> 
> No.  Only setsockopt can be fed kernel addresses from bpf-cgroup.
> There is no point in complicating the read side interface when it
> doesn't have that problem.

You realise that one of the SCTP getsockopt() is actually a command!
It is one of the requests that changes state and should probably
have been a separate system call.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (8 preceding siblings ...)
  2020-07-22  8:21 ` David Laight
@ 2020-07-22 17:09 ` Alexei Starovoitov
  2020-07-23  6:08 ` get rid of the address_space override in setsockopt v2 Christoph Hellwig
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Alexei Starovoitov @ 2020-07-22 17:09 UTC (permalink / raw)
  To: dccp

On Wed, Jul 22, 2020 at 12:56 AM Christoph Hellwig <hch@lst.de> wrote:
>
> On Mon, Jul 20, 2020 at 01:47:56PM -0700, Alexei Starovoitov wrote:
> > > 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, so we unfortunately
> > > can't just always do the copy in the highlevel code, which would have
> > > been much nicer.
> >
> > could you rebase on bpf-next tree and we can route it this way then?
> > we'll also test the whole thing before applying.
>
> The bpf-next tree is missing all my previous setsockopt cleanups, so
> there series won't apply.

Right. I've realized that after sending that email two days ago.
Now bpf-next->net-next PR is pending and as soon as it's merged
bpf-next will have all the recent bits.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (9 preceding siblings ...)
  2020-07-22 17:09 ` Alexei Starovoitov
@ 2020-07-23  6:08 ` Christoph Hellwig
  2020-07-24 22:43 ` David Miller
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2020-07-23  6:08 UTC (permalink / raw)
  To: dccp

Hi Dave,

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

Diffstat:
 crypto/af_alg.c                           |    7 
 drivers/crypto/chelsio/chtls/chtls_main.c |   18 -
 drivers/isdn/mISDN/socket.c               |    4 
 include/linux/bpfilter.h                  |    6 
 include/linux/filter.h                    |    3 
 include/linux/mroute.h                    |    5 
 include/linux/mroute6.h                   |    8 
 include/linux/net.h                       |    4 
 include/linux/netfilter.h                 |    6 
 include/linux/netfilter/x_tables.h        |    4 
 include/linux/sockptr.h                   |  132 ++++++++++++
 include/net/inet_connection_sock.h        |    3 
 include/net/ip.h                          |    7 
 include/net/ipv6.h                        |    6 
 include/net/sctp/structs.h                |    2 
 include/net/sock.h                        |    7 
 include/net/tcp.h                         |    6 
 include/net/udp.h                         |    2 
 include/net/xfrm.h                        |    8 
 net/atm/common.c                          |    6 
 net/atm/common.h                          |    2 
 net/atm/pvc.c                             |    2 
 net/atm/svc.c                             |    6 
 net/ax25/af_ax25.c                        |    6 
 net/bluetooth/hci_sock.c                  |    8 
 net/bluetooth/l2cap_sock.c                |   22 +-
 net/bluetooth/rfcomm/sock.c               |   12 -
 net/bluetooth/sco.c                       |    6 
 net/bpfilter/bpfilter_kern.c              |   55 ++---
 net/bridge/netfilter/ebtables.c           |   46 +---
 net/caif/caif_socket.c                    |    8 
 net/can/j1939/socket.c                    |   12 -
 net/can/raw.c                             |   16 -
 net/core/filter.c                         |    6 
 net/core/sock.c                           |   36 +--
 net/dccp/dccp.h                           |    2 
 net/dccp/proto.c                          |   20 -
 net/decnet/af_decnet.c                    |   13 -
 net/ieee802154/socket.c                   |    6 
 net/ipv4/bpfilter/sockopt.c               |   16 -
 net/ipv4/ip_options.c                     |   43 +---
 net/ipv4/ip_sockglue.c                    |   66 +++---
 net/ipv4/ipmr.c                           |   14 -
 net/ipv4/netfilter/arp_tables.c           |   33 +--
 net/ipv4/netfilter/ip_tables.c            |   29 +-
 net/ipv4/raw.c                            |    8 
 net/ipv4/tcp.c                            |   30 +-
 net/ipv4/tcp_ipv4.c                       |    4 
 net/ipv4/udp.c                            |   11 -
 net/ipv4/udp_impl.h                       |    4 
 net/ipv6/ip6_flowlabel.c                  |  317 ++++++++++++++++--------------
 net/ipv6/ip6mr.c                          |   17 -
 net/ipv6/ipv6_sockglue.c                  |  203 +++++++++----------
 net/ipv6/netfilter/ip6_tables.c           |   28 +-
 net/ipv6/raw.c                            |   10 
 net/ipv6/tcp_ipv6.c                       |    4 
 net/ipv6/udp.c                            |    7 
 net/ipv6/udp_impl.h                       |    4 
 net/iucv/af_iucv.c                        |    4 
 net/kcm/kcmsock.c                         |    6 
 net/l2tp/l2tp_ppp.c                       |    4 
 net/llc/af_llc.c                          |    4 
 net/mptcp/protocol.c                      |    6 
 net/netfilter/ipvs/ip_vs_ctl.c            |    4 
 net/netfilter/nf_sockopt.c                |    2 
 net/netfilter/x_tables.c                  |   20 -
 net/netlink/af_netlink.c                  |    4 
 net/netrom/af_netrom.c                    |    4 
 net/nfc/llcp_sock.c                       |    6 
 net/packet/af_packet.c                    |   39 +--
 net/phonet/pep.c                          |    4 
 net/rds/af_rds.c                          |   30 +-
 net/rds/rdma.c                            |   14 -
 net/rds/rds.h                             |    6 
 net/rose/af_rose.c                        |    4 
 net/rxrpc/af_rxrpc.c                      |    8 
 net/rxrpc/ar-internal.h                   |    4 
 net/rxrpc/key.c                           |    9 
 net/sctp/socket.c                         |    4 
 net/smc/af_smc.c                          |    4 
 net/socket.c                              |   24 --
 net/tipc/socket.c                         |    8 
 net/tls/tls_main.c                        |   17 -
 net/vmw_vsock/af_vsock.c                  |    4 
 net/x25/af_x25.c                          |    4 
 net/xdp/xsk.c                             |    8 
 net/xfrm/xfrm_state.c                     |    6 
 87 files changed, 894 insertions(+), 743 deletions(-)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (10 preceding siblings ...)
  2020-07-23  6:08 ` get rid of the address_space override in setsockopt v2 Christoph Hellwig
@ 2020-07-24 22:43 ` David Miller
  2020-07-26  7:03 ` Christoph Hellwig
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: David Miller @ 2020-07-24 22:43 UTC (permalink / raw)
  To: dccp

From: Christoph Hellwig <hch@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.

Thanks.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (11 preceding siblings ...)
  2020-07-24 22:43 ` David Miller
@ 2020-07-26  7:03 ` Christoph Hellwig
  2020-07-26  7:08 ` Andreas Schwab
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Christoph Hellwig @ 2020-07-26  7:03 UTC (permalink / raw)
  To: dccp

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 2001
From: Christoph Hellwig <hch@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@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

^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (12 preceding siblings ...)
  2020-07-26  7:03 ` Christoph Hellwig
@ 2020-07-26  7:08 ` Andreas Schwab
  2020-07-26  7:46 ` David Miller
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Andreas Schwab @ 2020-07-26  7:08 UTC (permalink / raw)
  To: dccp

On Jul 26 2020, Christoph Hellwig wrote:

> From 6601732f7a54db5f04efba08f7e9224e5b757112 Mon Sep 17 00:00:00 2001
> From: Christoph Hellwig <hch@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,

I think there is a word missing after pretty.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (13 preceding siblings ...)
  2020-07-26  7:08 ` Andreas Schwab
@ 2020-07-26  7:46 ` David Miller
  2020-07-27  9:51 ` David Laight
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: David Miller @ 2020-07-26  7:46 UTC (permalink / raw)
  To: dccp

From: Christoph Hellwig <hch@lst.de>
Date: Sun, 26 Jul 2020 09:03:11 +0200

> 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:

I already fixed this in net-next.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (14 preceding siblings ...)
  2020-07-26  7:46 ` David Miller
@ 2020-07-27  9:51 ` David Laight
  2020-07-27 13:48 ` Al Viro
  2020-07-27 14:09 ` David Laight
  17 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2020-07-27  9:51 UTC (permalink / raw)
  To: dccp

From: David Miller
> Sent: 24 July 2020 23:44
> 
> From: Christoph Hellwig <hch@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)

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (15 preceding siblings ...)
  2020-07-27  9:51 ` David Laight
@ 2020-07-27 13:48 ` Al Viro
  2020-07-27 14:09 ` David Laight
  17 siblings, 0 replies; 19+ messages in thread
From: Al Viro @ 2020-07-27 13:48 UTC (permalink / raw)
  To: dccp

On Mon, Jul 27, 2020 at 09:51:45AM +0000, David Laight wrote:

> 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.

Really?  Care to provide some details, or is it another of your "I can't
be possibly arsed to check what I'm saying, but it stands for reason
that..." specials?

^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: get rid of the address_space override in setsockopt v2
  2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
                   ` (16 preceding siblings ...)
  2020-07-27 13:48 ` Al Viro
@ 2020-07-27 14:09 ` David Laight
  17 siblings, 0 replies; 19+ messages in thread
From: David Laight @ 2020-07-27 14:09 UTC (permalink / raw)
  To: dccp

From: Al Viro
> Sent: 27 July 2020 14:48
> 
> On Mon, Jul 27, 2020 at 09:51:45AM +0000, David Laight wrote:
> 
> > 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.
> 
> Really?  Care to provide some details, or is it another of your "I can't
> be possibly arsed to check what I'm saying, but it stands for reason
> that..." specials?

I did more 'homework' than sometimes :-)
Slightly difficult without a searchable net-next tree.
However, as has been pointed out is a different thread
this code is used to update IPv6 flow labels:

> > -		if (copy_from_user(fl->opt+1, optval+CMSG_ALIGN(sizeof(*freq)), olen))
> > +		sockptr_advance(optval, CMSG_ALIGN(sizeof(*freq)));
> > +		if (copy_from_sockptr(fl->opt + 1, optval, olen))
> >  			goto done;

and doesn't work because the advances are no longer cumulative.

Now access_ok() has to take the base address and length to stop
'running into' kernel space, but the code above can advance from
a valid user pointer (which won't fault) to a kernel address.

If there were always an unmapped 'guard' page in the user address
space the access_ok() check prior to copy_to/from_user() wouldn't
need the length.
So I surmise that no such guard page exists and so the above
can advance from user addresses into kernel ones.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2020-07-27 14:09 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-07-20 12:47 get rid of the address_space override in setsockopt Christoph Hellwig
2020-07-20 16:38 ` Eric Biggers
2020-07-20 17:43 ` Christoph Hellwig
2020-07-20 20:47 ` Alexei Starovoitov
2020-07-21  9:38 ` David Laight
2020-07-21 10:26 ` David Laight
2020-07-22  7:56 ` Christoph Hellwig
2020-07-22  8:06 ` 'Christoph Hellwig'
2020-07-22  8:07 ` 'Christoph Hellwig'
2020-07-22  8:21 ` David Laight
2020-07-22 17:09 ` Alexei Starovoitov
2020-07-23  6:08 ` get rid of the address_space override in setsockopt v2 Christoph Hellwig
2020-07-24 22:43 ` David Miller
2020-07-26  7:03 ` Christoph Hellwig
2020-07-26  7:08 ` Andreas Schwab
2020-07-26  7:46 ` David Miller
2020-07-27  9:51 ` David Laight
2020-07-27 13:48 ` Al Viro
2020-07-27 14:09 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox