Skip to content

Commit

Permalink
sctp: copy the optval from user space in sctp_setsockopt
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Christoph Hellwig authored and davem330 committed Jul 20, 2020
1 parent 9aa0dfe commit ca84bd0
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -4677,6 +4677,7 @@ static int sctp_setsockopt_pf_expose(struct sock *sk,
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);
Expand All @@ -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) {
Expand Down Expand Up @@ -4878,6 +4885,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
}

release_sock(sk);
kfree(kopt);

out_nounlock:
return retval;
Expand Down

0 comments on commit ca84bd0

Please sign in to comment.