sctp: pass a kernel pointer to sctp_setsockopt_context
authorChristoph Hellwig <hch@lst.de>
Sun, 19 Jul 2020 07:21:58 +0000 (09:21 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Jul 2020 01:26:42 +0000 (18:26 -0700)
Use the kernel pointer that sctp_setsockopt has available instead of
directly handling the user pointer.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/sctp/socket.c

index b29452f..2862047 100644 (file)
@@ -3362,40 +3362,38 @@ static int sctp_setsockopt_adaptation_layer(struct sock *sk,
  * received messages from the peer and does not effect the value that is
  * saved with outbound messages.
  */
-static int sctp_setsockopt_context(struct sock *sk, char __user *optval,
+static int sctp_setsockopt_context(struct sock *sk,
+                                  struct sctp_assoc_value *params,
                                   unsigned int optlen)
 {
        struct sctp_sock *sp = sctp_sk(sk);
-       struct sctp_assoc_value params;
        struct sctp_association *asoc;
 
        if (optlen != sizeof(struct sctp_assoc_value))
                return -EINVAL;
-       if (copy_from_user(&params, optval, optlen))
-               return -EFAULT;
 
-       asoc = sctp_id2assoc(sk, params.assoc_id);
-       if (!asoc && params.assoc_id > SCTP_ALL_ASSOC &&
+       asoc = sctp_id2assoc(sk, params->assoc_id);
+       if (!asoc && params->assoc_id > SCTP_ALL_ASSOC &&
            sctp_style(sk, UDP))
                return -EINVAL;
 
        if (asoc) {
-               asoc->default_rcv_context = params.assoc_value;
+               asoc->default_rcv_context = params->assoc_value;
 
                return 0;
        }
 
        if (sctp_style(sk, TCP))
-               params.assoc_id = SCTP_FUTURE_ASSOC;
+               params->assoc_id = SCTP_FUTURE_ASSOC;
 
-       if (params.assoc_id == SCTP_FUTURE_ASSOC ||
-           params.assoc_id == SCTP_ALL_ASSOC)
-               sp->default_rcv_context = params.assoc_value;
+       if (params->assoc_id == SCTP_FUTURE_ASSOC ||
+           params->assoc_id == SCTP_ALL_ASSOC)
+               sp->default_rcv_context = params->assoc_value;
 
-       if (params.assoc_id == SCTP_CURRENT_ASSOC ||
-           params.assoc_id == SCTP_ALL_ASSOC)
+       if (params->assoc_id == SCTP_CURRENT_ASSOC ||
+           params->assoc_id == SCTP_ALL_ASSOC)
                list_for_each_entry(asoc, &sp->ep->asocs, asocs)
-                       asoc->default_rcv_context = params.assoc_value;
+                       asoc->default_rcv_context = params->assoc_value;
 
        return 0;
 }
@@ -4700,7 +4698,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
                retval = sctp_setsockopt_adaptation_layer(sk, kopt, optlen);
                break;
        case SCTP_CONTEXT:
-               retval = sctp_setsockopt_context(sk, optval, optlen);
+               retval = sctp_setsockopt_context(sk, kopt, optlen);
                break;
        case SCTP_FRAGMENT_INTERLEAVE:
                retval = sctp_setsockopt_fragment_interleave(sk, optval, optlen);