netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Marcelo Ricardo Leitner' <marcelo.leitner@gmail.com>
Cc: "netdev@vger.kernel.org" <netdev@vger.kernel.org>,
	"linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>,
	Neil Horman <nhorman@tuxdriver.com>
Subject: RE: [PATCH net-next] sctp: Pull the user copies out of the individual sockopt functions.
Date: Thu, 21 May 2020 07:32:14 +0000	[thread overview]
Message-ID: <e777874fbd0e4ccb813e08145f3c3359@AcuMS.aculab.com> (raw)
In-Reply-To: <20200521001725.GW2491@localhost.localdomain>

From: 'Marcelo Ricardo Leitner'
> Sent: 21 May 2020 01:17
> On Wed, May 20, 2020 at 03:08:13PM +0000, David Laight wrote:
> ...
> > Only SCTP_SOCKOPT_CONNECTX3 contains an indirect pointer.
> > It is also the only getsockopt() that wants to return a buffer
> > and an error code. It is also definitely abusing getsockopt().
> ...
> > @@ -1375,11 +1350,11 @@ struct compat_sctp_getaddrs_old {
> >  #endif
> >
> >  static int sctp_getsockopt_connectx3(struct sock *sk, int len,
> > -				     char __user *optval,
> > -				     int __user *optlen)
> > +				     struct sctp_getaddrs_old *param,
> > +				     int *optlen)
> >  {
> > -	struct sctp_getaddrs_old param;
> >  	sctp_assoc_t assoc_id = 0;
> > +	struct sockaddr *addrs;
> >  	int err = 0;
> >
> >  #ifdef CONFIG_COMPAT
..
> >  	} else
> >  #endif
> >  	{
> > -		if (len < sizeof(param))
> > +		if (len < sizeof(*param))
> >  			return -EINVAL;
> > -		if (copy_from_user(&param, optval, sizeof(param)))
> > -			return -EFAULT;
> >  	}
> >
> > -	err = __sctp_setsockopt_connectx(sk, (struct sockaddr __user *)
> > -					 param.addrs, param.addr_num,
> > +	addrs = memdup_user(param->addrs, param->addr_num);
> 
> I'm staring at this for a while now but I don't get this memdup_user.
> AFAICT, params->addrs is not __user anymore here, because
> sctp_getsockopt() copied the whole thing already, no?
> Also weird because it is being called from kernel_sctp_getsockopt(),
> which now has no knowledge of __user buffers.
> Maybe I didn't get something from the patch description.

The connectx3 sockopt buffer contains a pointer to the user buffer
that contains the actual addresses.
So a second copy_from_user() is needed.

This does mean that this option can only be actioned from userspace.

Kernel code can get the same functionality using one of the
other interfaces to connectx().

	David

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


  reply	other threads:[~2020-05-21  7:33 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-20 15:08 [PATCH net-next] sctp: Pull the user copies out of the individual sockopt functions David Laight
2020-05-20 23:33 ` kbuild test robot
2020-05-21  0:17 ` 'Marcelo Ricardo Leitner'
2020-05-21  7:32   ` David Laight [this message]
2020-05-21 14:36     ` 'Marcelo Ricardo Leitner'
2020-05-21 15:37 ` 'Marcelo Ricardo Leitner'
2020-05-21 15:39   ` Christoph Hellwig
2020-05-21 15:52     ` David Laight
2020-05-21 16:09   ` David Laight
2020-05-21 16:45     ` 'Marcelo Ricardo Leitner'

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=e777874fbd0e4ccb813e08145f3c3359@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=linux-sctp@vger.kernel.org \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.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).