sctp: copy the optval from user space in sctp_setsockopt
authorChristoph Hellwig <hch@lst.de>
Sun, 19 Jul 2020 07:21:38 +0000 (09:21 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 20 Jul 2020 01:26:41 +0000 (18:26 -0700)
Prepare for for moving the copy_from_user from the individual sockopts
to the main setsockopt helper.  As of this commit the kopt variable
is not used yet, but the following commits will start using it.

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

index d57e1a0..af1ebc8 100644 (file)
@@ -4677,6 +4677,7 @@ out:
 static int sctp_setsockopt(struct sock *sk, int level, int optname,
                           char __user *optval, unsigned int optlen)
 {
+       void *kopt = NULL;
        int retval = 0;
 
        pr_debug("%s: sk:%p, optname:%d\n", __func__, sk, optname);
@@ -4693,6 +4694,12 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
                goto out_nounlock;
        }
 
+       if (optlen > 0) {
+               kopt = memdup_user(optval, optlen);
+               if (IS_ERR(kopt))
+                       return PTR_ERR(kopt);
+       }
+
        lock_sock(sk);
 
        switch (optname) {
@@ -4878,6 +4885,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
        }
 
        release_sock(sk);
+       kfree(kopt);
 
 out_nounlock:
        return retval;