linux-sctp.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Vlad Yasevich <vyasevich@gmail.com>,
	Neil Horman <nhorman@tuxdriver.com>,
	Marcelo Ricardo Leitner <marcelo.leitner@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	David Laight <David.Laight@ACULAB.COM>,
	linux-sctp@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 07/49] sctp: pass a kernel pointer to sctp_setsockopt_peer_addr_params
Date: Thu, 21 May 2020 17:46:42 +0000	[thread overview]
Message-ID: <20200521174724.2635475-8-hch@lst.de> (raw)
In-Reply-To: <20200521174724.2635475-1-hch@lst.de>

Use the kernel pointer that sctp_setsockopt has available instead of
directly handling the user pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 net/sctp/socket.c | 44 +++++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 25 deletions(-)

diff --git a/net/sctp/socket.c b/net/sctp/socket.c
index 2fb3a5590a12e..0498cf21923e8 100644
--- a/net/sctp/socket.c
+++ b/net/sctp/socket.c
@@ -2586,48 +2586,42 @@ static int sctp_apply_peer_addr_params(struct sctp_paddrparams *params,
 }
 
 static int sctp_setsockopt_peer_addr_params(struct sock *sk,
-					    char __user *optval,
+					    struct sctp_paddrparams *params,
 					    unsigned int optlen)
 {
-	struct sctp_paddrparams  params;
 	struct sctp_transport   *trans = NULL;
 	struct sctp_association *asoc = NULL;
 	struct sctp_sock        *sp = sctp_sk(sk);
 	int error;
 	int hb_change, pmtud_change, sackdelay_change;
 
-	if (optlen = sizeof(params)) {
-		if (copy_from_user(&params, optval, optlen))
-			return -EFAULT;
-	} else if (optlen = ALIGN(offsetof(struct sctp_paddrparams,
+	if (optlen = ALIGN(offsetof(struct sctp_paddrparams,
 					    spp_ipv6_flowlabel), 4)) {
-		if (copy_from_user(&params, optval, optlen))
-			return -EFAULT;
-		if (params.spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
+		if (params->spp_flags & (SPP_DSCP | SPP_IPV6_FLOWLABEL))
 			return -EINVAL;
-	} else {
+	} else if (optlen != sizeof(*params)) {
 		return -EINVAL;
 	}
 
 	/* Validate flags and value parameters. */
-	hb_change        = params.spp_flags & SPP_HB;
-	pmtud_change     = params.spp_flags & SPP_PMTUD;
-	sackdelay_change = params.spp_flags & SPP_SACKDELAY;
+	hb_change        = params->spp_flags & SPP_HB;
+	pmtud_change     = params->spp_flags & SPP_PMTUD;
+	sackdelay_change = params->spp_flags & SPP_SACKDELAY;
 
 	if (hb_change        = SPP_HB ||
 	    pmtud_change     = SPP_PMTUD ||
 	    sackdelay_change = SPP_SACKDELAY ||
-	    params.spp_sackdelay > 500 ||
-	    (params.spp_pathmtu &&
-	     params.spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
+	    params->spp_sackdelay > 500 ||
+	    (params->spp_pathmtu &&
+	     params->spp_pathmtu < SCTP_DEFAULT_MINSEGMENT))
 		return -EINVAL;
 
 	/* If an address other than INADDR_ANY is specified, and
 	 * no transport is found, then the request is invalid.
 	 */
-	if (!sctp_is_any(sk, (union sctp_addr *)&params.spp_address)) {
-		trans = sctp_addr_id2transport(sk, &params.spp_address,
-					       params.spp_assoc_id);
+	if (!sctp_is_any(sk, (union sctp_addr *)&params->spp_address)) {
+		trans = sctp_addr_id2transport(sk, &params->spp_address,
+					       params->spp_assoc_id);
 		if (!trans)
 			return -EINVAL;
 	}
@@ -2636,19 +2630,19 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
 	 * socket is a one to many style socket, and an association
 	 * was not found, then the id was invalid.
 	 */
-	asoc = sctp_id2assoc(sk, params.spp_assoc_id);
-	if (!asoc && params.spp_assoc_id != SCTP_FUTURE_ASSOC &&
+	asoc = sctp_id2assoc(sk, params->spp_assoc_id);
+	if (!asoc && params->spp_assoc_id != SCTP_FUTURE_ASSOC &&
 	    sctp_style(sk, UDP))
 		return -EINVAL;
 
 	/* Heartbeat demand can only be sent on a transport or
 	 * association, but not a socket.
 	 */
-	if (params.spp_flags & SPP_HB_DEMAND && !trans && !asoc)
+	if (params->spp_flags & SPP_HB_DEMAND && !trans && !asoc)
 		return -EINVAL;
 
 	/* Process parameters. */
-	error = sctp_apply_peer_addr_params(&params, trans, asoc, sp,
+	error = sctp_apply_peer_addr_params(params, trans, asoc, sp,
 					    hb_change, pmtud_change,
 					    sackdelay_change);
 
@@ -2661,7 +2655,7 @@ static int sctp_setsockopt_peer_addr_params(struct sock *sk,
 	if (!trans && asoc) {
 		list_for_each_entry(trans, &asoc->peer.transport_addr_list,
 				transports) {
-			sctp_apply_peer_addr_params(&params, trans, asoc, sp,
+			sctp_apply_peer_addr_params(params, trans, asoc, sp,
 						    hb_change, pmtud_change,
 						    sackdelay_change);
 		}
@@ -4696,7 +4690,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
 		break;
 
 	case SCTP_PEER_ADDR_PARAMS:
-		retval = sctp_setsockopt_peer_addr_params(sk, optval, optlen);
+		retval = sctp_setsockopt_peer_addr_params(sk, kopt, optlen);
 		break;
 
 	case SCTP_DELAYED_SACK:
-- 
2.26.2

  parent reply	other threads:[~2020-05-21 17:46 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-21 17:46 do a single memdup_user in sctp_setsockopt Christoph Hellwig
2020-05-21 17:46 ` [PATCH 01/49] sctp: copy the optval from user space " Christoph Hellwig
2020-05-21 17:46 ` [PATCH 02/49] sctp: pass a kernel pointer to sctp_setsockopt_bindx Christoph Hellwig
2020-05-21 17:46 ` [PATCH 03/49] sctp: pass a kernel pointer to __sctp_setsockopt_connectx Christoph Hellwig
2020-05-21 17:46 ` [PATCH 04/49] sctp: pass a kernel pointer to sctp_setsockopt_disable_fragments Christoph Hellwig
2020-05-21 17:46 ` [PATCH 05/49] sctp: pass a kernel pointer to sctp_setsockopt_events Christoph Hellwig
2020-05-21 17:46 ` [PATCH 06/49] sctp: pass a kernel pointer to sctp_setsockopt_autoclose Christoph Hellwig
2020-05-21 17:46 ` Christoph Hellwig [this message]
2020-05-21 17:46 ` [PATCH 08/49] sctp: pass a kernel pointer to sctp_setsockopt_delayed_ack Christoph Hellwig
2020-05-21 17:46 ` [PATCH 09/49] sctp: pass a kernel pointer to sctp_setsockopt_partial_delivery_point Christoph Hellwig
2020-05-21 17:46 ` [PATCH 10/49] sctp: pass a kernel pointer to sctp_setsockopt_initmsg Christoph Hellwig
2020-05-21 17:46 ` [PATCH 11/49] sctp: pass a kernel pointer to sctp_setsockopt_default_send_param Christoph Hellwig
2020-05-21 17:46 ` [PATCH 12/49] sctp: pass a kernel pointer to sctp_setsockopt_default_sndinfo Christoph Hellwig
2020-05-21 17:46 ` [PATCH 13/49] sctp: pass a kernel pointer to sctp_setsockopt_primary_addr Christoph Hellwig
2020-05-21 17:46 ` [PATCH 14/49] sctp: pass a kernel pointer to sctp_setsockopt_peer_primary_addr Christoph Hellwig
2020-05-21 17:46 ` [PATCH 15/49] sctp: pass a kernel pointer to sctp_setsockopt_nodelay Christoph Hellwig
2020-05-21 17:46 ` [PATCH 16/49] sctp: pass a kernel pointer to sctp_setsockopt_rtoinfo Christoph Hellwig
2020-05-21 17:46 ` [PATCH 17/49] sctp: pass a kernel pointer to sctp_setsockopt_associnfo Christoph Hellwig
2020-05-21 17:46 ` [PATCH 18/49] sctp: pass a kernel pointer to sctp_setsockopt_mappedv4 Christoph Hellwig
2020-05-21 17:46 ` [PATCH 19/49] sctp: pass a kernel pointer to sctp_setsockopt_maxseg Christoph Hellwig
2020-05-21 17:46 ` [PATCH 20/49] sctp: pass a kernel pointer to sctp_setsockopt_adaptation_layer Christoph Hellwig
2020-05-21 17:46 ` [PATCH 21/49] sctp: pass a kernel pointer to sctp_setsockopt_context Christoph Hellwig
2020-05-21 17:46 ` [PATCH 22/49] sctp: pass a kernel pointer to sctp_setsockopt_fragment_interleave Christoph Hellwig
2020-05-21 17:46 ` [PATCH 23/49] sctp: pass a kernel pointer to sctp_setsockopt_maxburst Christoph Hellwig
2020-05-21 17:46 ` [PATCH 24/49] sctp: pass a kernel pointer to sctp_setsockopt_auth_chunk Christoph Hellwig
2020-05-21 17:47 ` [PATCH 25/49] sctp: pass a kernel pointer to sctp_setsockopt_hmac_ident Christoph Hellwig
2020-05-21 17:47 ` [PATCH 26/49] sctp: pass a kernel pointer to sctp_setsockopt_auth_key Christoph Hellwig
2020-05-21 17:47 ` [PATCH 27/49] sctp: pass a kernel pointer to sctp_setsockopt_active_key Christoph Hellwig
2020-05-21 17:47 ` [PATCH 28/49] sctp: pass a kernel pointer to sctp_setsockopt_del_key Christoph Hellwig
2020-05-21 17:47 ` [PATCH 29/49] sctp: pass a kernel pointer to sctp_setsockopt_deactivate_key Christoph Hellwig
2020-05-21 17:47 ` [PATCH 30/49] sctp: pass a kernel pointer to sctp_setsockopt_auto_asconf Christoph Hellwig
2020-05-21 17:47 ` [PATCH 31/49] sctp: pass a kernel pointer to sctp_setsockopt_paddr_thresholds Christoph Hellwig
2020-05-21 17:47 ` [PATCH 32/49] sctp: pass a kernel pointer to sctp_setsockopt_recvrcvinfo Christoph Hellwig
2020-05-21 17:47 ` [PATCH 33/49] sctp: pass a kernel pointer to sctp_setsockopt_recvnxtinfo Christoph Hellwig
2020-05-21 17:47 ` [PATCH 34/49] sctp: pass a kernel pointer to sctp_setsockopt_pr_supported Christoph Hellwig
2020-05-21 17:47 ` [PATCH 35/49] sctp: pass a kernel pointer to sctp_setsockopt_default_prinfo Christoph Hellwig
2020-05-21 17:47 ` [PATCH 36/49] sctp: pass a kernel pointer to sctp_setsockopt_reconfig_supported Christoph Hellwig
2020-05-21 17:47 ` [PATCH 37/49] sctp: pass a kernel pointer to sctp_setsockopt_enable_strreset Christoph Hellwig
2020-05-21 17:47 ` [PATCH 38/49] sctp: pass a kernel pointer to sctp_setsockopt_reset_streams Christoph Hellwig
2020-05-21 17:47 ` [PATCH 39/49] sctp: pass a kernel pointer to sctp_setsockopt_reset_assoc Christoph Hellwig
2020-05-21 17:47 ` [PATCH 40/49] sctp: pass a kernel pointer to sctp_setsockopt_add_streams Christoph Hellwig
2020-05-21 17:47 ` [PATCH 41/49] sctp: pass a kernel pointer to sctp_setsockopt_scheduler Christoph Hellwig
2020-05-21 17:47 ` [PATCH 42/49] sctp: pass a kernel pointer to sctp_setsockopt_scheduler_value Christoph Hellwig
2020-05-21 17:47 ` [PATCH 43/49] sctp: pass a kernel pointer to sctp_setsockopt_interleaving_supported Christoph Hellwig
2020-05-21 17:47 ` [PATCH 44/49] sctp: pass a kernel pointer to sctp_setsockopt_reuse_port Christoph Hellwig
2020-05-21 17:47 ` [PATCH 45/49] sctp: pass a kernel pointer to sctp_setsockopt_event Christoph Hellwig
2020-05-21 17:47 ` [PATCH 46/49] " Christoph Hellwig
2020-05-21 17:47 ` [PATCH 47/49] sctp: pass a kernel pointer to sctp_setsockopt_auth_supported Christoph Hellwig
2020-05-21 17:47 ` [PATCH 48/49] sctp: pass a kernel pointer to sctp_setsockopt_ecn_supported Christoph Hellwig
2020-05-21 17:47 ` [PATCH 49/49] sctp: pass a kernel pointer to sctp_setsockopt_pf_expose Christoph Hellwig
2020-05-22  8:02 ` do a single memdup_user in sctp_setsockopt David Laight
2020-05-22 14:36   ` Marcelo Ricardo Leitner
2020-05-22 15:52     ` David Laight
2020-05-23  7:19     ` 'Christoph Hellwig'
2020-05-25 19:37       ` David Laight
2020-05-25 20:59         ` Marcelo Ricardo Leitner
2020-05-25 21:18       ` Marcelo Ricardo Leitner
2020-05-22 23:11 ` David Miller
2020-07-19  7:21 ` do a single memdup_user in sctp_setsockopt v2 Christoph Hellwig
2020-07-19  7:21   ` [PATCH 01/51] sctp: copy the optval from user space in sctp_setsockopt Christoph Hellwig
2020-07-19  7:21   ` [PATCH 02/51] sctp: pass a kernel pointer to sctp_setsockopt_bindx Christoph Hellwig
2020-07-19  7:21   ` [PATCH 03/51] sctp: pass a kernel pointer to __sctp_setsockopt_connectx Christoph Hellwig
2020-07-19  7:21   ` [PATCH 04/51] sctp: pass a kernel pointer to sctp_setsockopt_disable_fragments Christoph Hellwig
2020-07-19  7:21   ` [PATCH 05/51] sctp: pass a kernel pointer to sctp_setsockopt_events Christoph Hellwig
2020-07-19  7:21   ` [PATCH 06/51] sctp: pass a kernel pointer to sctp_setsockopt_autoclose Christoph Hellwig
2020-07-19  7:21   ` [PATCH 07/51] sctp: pass a kernel pointer to sctp_setsockopt_peer_addr_params Christoph Hellwig
2020-07-19  7:21   ` [PATCH 08/51] sctp: pass a kernel pointer to sctp_setsockopt_delayed_ack Christoph Hellwig
2020-07-19  7:21   ` [PATCH 09/51] sctp: pass a kernel pointer to sctp_setsockopt_partial_delivery_point Christoph Hellwig
2020-07-19  7:21   ` [PATCH 10/51] sctp: pass a kernel pointer to sctp_setsockopt_initmsg Christoph Hellwig
2020-07-19  7:21   ` [PATCH 11/51] sctp: pass a kernel pointer to sctp_setsockopt_default_send_param Christoph Hellwig
2020-07-19  7:21   ` [PATCH 12/51] sctp: pass a kernel pointer to sctp_setsockopt_default_sndinfo Christoph Hellwig
2020-07-19  7:21   ` [PATCH 13/51] sctp: pass a kernel pointer to sctp_setsockopt_primary_addr Christoph Hellwig
2020-07-19  7:21   ` [PATCH 14/51] sctp: pass a kernel pointer to sctp_setsockopt_peer_primary_addr Christoph Hellwig
2020-07-19  7:21   ` [PATCH 15/51] sctp: pass a kernel pointer to sctp_setsockopt_nodelay Christoph Hellwig
2020-07-19  7:21   ` [PATCH 16/51] sctp: pass a kernel pointer to sctp_setsockopt_rtoinfo Christoph Hellwig
2020-07-19  7:21   ` [PATCH 17/51] sctp: pass a kernel pointer to sctp_setsockopt_associnfo Christoph Hellwig
2020-07-19  7:21   ` [PATCH 18/51] sctp: pass a kernel pointer to sctp_setsockopt_mappedv4 Christoph Hellwig
2020-07-19  7:21   ` [PATCH 19/51] sctp: pass a kernel pointer to sctp_setsockopt_maxseg Christoph Hellwig
2020-07-19  7:21   ` [PATCH 20/51] sctp: pass a kernel pointer to sctp_setsockopt_adaptation_layer Christoph Hellwig
2020-07-19  7:21   ` [PATCH 21/51] sctp: pass a kernel pointer to sctp_setsockopt_context Christoph Hellwig
2020-07-19  7:21   ` [PATCH 22/51] sctp: pass a kernel pointer to sctp_setsockopt_fragment_interleave Christoph Hellwig
2020-07-19  7:22   ` [PATCH 23/51] sctp: pass a kernel pointer to sctp_setsockopt_maxburst Christoph Hellwig
2020-07-19  7:22   ` [PATCH 24/51] sctp: pass a kernel pointer to sctp_setsockopt_auth_chunk Christoph Hellwig
2020-07-19  7:22   ` [PATCH 25/51] sctp: pass a kernel pointer to sctp_setsockopt_hmac_ident Christoph Hellwig
2020-07-19  7:22   ` [PATCH 26/51] sctp: switch sctp_setsockopt_auth_key to use memzero_explicit Christoph Hellwig
2020-07-19  7:22   ` [PATCH 27/51] sctp: pass a kernel pointer to sctp_setsockopt_auth_key Christoph Hellwig
2020-07-19  7:22   ` [PATCH 28/51] sctp: pass a kernel pointer to sctp_setsockopt_active_key Christoph Hellwig
2020-07-19  7:22   ` [PATCH 29/51] sctp: pass a kernel pointer to sctp_setsockopt_del_key Christoph Hellwig
2020-07-19  7:22   ` [PATCH 30/51] sctp: pass a kernel pointer to sctp_setsockopt_deactivate_key Christoph Hellwig
2020-07-19  7:22   ` [PATCH 31/51] sctp: pass a kernel pointer to sctp_setsockopt_auto_asconf Christoph Hellwig
2020-07-19  7:22   ` [PATCH 32/51] sctp: pass a kernel pointer to sctp_setsockopt_paddr_thresholds Christoph Hellwig
2020-07-19  7:22   ` [PATCH 33/51] sctp: pass a kernel pointer to sctp_setsockopt_recvrcvinfo Christoph Hellwig
2020-07-19  7:22   ` [PATCH 34/51] sctp: pass a kernel pointer to sctp_setsockopt_recvnxtinfo Christoph Hellwig
2020-07-19  7:22   ` [PATCH 35/51] sctp: pass a kernel pointer to sctp_setsockopt_pr_supported Christoph Hellwig
2020-07-19  7:22   ` [PATCH 36/51] sctp: pass a kernel pointer to sctp_setsockopt_default_prinfo Christoph Hellwig
2020-07-19  7:22   ` [PATCH 37/51] sctp: pass a kernel pointer to sctp_setsockopt_reconfig_supported Christoph Hellwig
2020-07-19  7:22   ` [PATCH 38/51] sctp: pass a kernel pointer to sctp_setsockopt_enable_strreset Christoph Hellwig
2020-07-19  7:22   ` [PATCH 39/51] sctp: pass a kernel pointer to sctp_setsockopt_reset_streams Christoph Hellwig
2020-07-19  7:22   ` [PATCH 40/51] sctp: pass a kernel pointer to sctp_setsockopt_reset_assoc Christoph Hellwig
2020-07-19  7:22   ` [PATCH 41/51] sctp: pass a kernel pointer to sctp_setsockopt_add_streams Christoph Hellwig
2020-07-19  7:22   ` [PATCH 42/51] sctp: pass a kernel pointer to sctp_setsockopt_scheduler Christoph Hellwig
2020-07-19  7:22   ` [PATCH 43/51] sctp: pass a kernel pointer to sctp_setsockopt_scheduler_value Christoph Hellwig
2020-07-19  7:22   ` [PATCH 44/51] sctp: pass a kernel pointer to sctp_setsockopt_interleaving_supported Christoph Hellwig
2020-07-19  7:22   ` [PATCH 45/51] sctp: pass a kernel pointer to sctp_setsockopt_reuse_port Christoph Hellwig
2020-07-19  7:22   ` [PATCH 46/51] sctp: pass a kernel pointer to sctp_setsockopt_event Christoph Hellwig
2020-07-19  7:22   ` [PATCH 47/51] " Christoph Hellwig
2020-07-19  7:22   ` [PATCH 48/51] sctp: pass a kernel pointer to sctp_setsockopt_auth_supported Christoph Hellwig
2020-07-19  7:22   ` [PATCH 49/51] sctp: pass a kernel pointer to sctp_setsockopt_ecn_supported Christoph Hellwig
2020-07-19  7:22   ` [PATCH 50/51] sctp: pass a kernel pointer to sctp_setsockopt_pf_expose Christoph Hellwig
2020-07-19  7:22   ` [PATCH 51/51] sctp: remove the out_nounlock label in sctp_setsockopt Christoph Hellwig
2020-07-20  1:27   ` do a single memdup_user in sctp_setsockopt v2 David Miller
2020-07-20 13:08     ` 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=20200521174724.2635475-8-hch@lst.de \
    --to=hch@lst.de \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=kuba@kernel.org \
    --cc=linux-sctp@vger.kernel.org \
    --cc=marcelo.leitner@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=vyasevich@gmail.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).