sctp: pass a kernel pointer to sctp_setsockopt_paddr_thresholds

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>
This commit is contained in:
Christoph Hellwig 2020-07-19 09:22:09 +02:00 committed by David S. Miller
parent c9abc2c1c2
commit b0ac3bb894
1 changed files with 26 additions and 29 deletions

View File

@ -3840,66 +3840,63 @@ static int sctp_setsockopt_auto_asconf(struct sock *sk, int *val,
* http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt * http://www.ietf.org/id/draft-nishida-tsvwg-sctp-failover-05.txt
*/ */
static int sctp_setsockopt_paddr_thresholds(struct sock *sk, static int sctp_setsockopt_paddr_thresholds(struct sock *sk,
char __user *optval, struct sctp_paddrthlds_v2 *val,
unsigned int optlen, bool v2) unsigned int optlen, bool v2)
{ {
struct sctp_paddrthlds_v2 val;
struct sctp_transport *trans; struct sctp_transport *trans;
struct sctp_association *asoc; struct sctp_association *asoc;
int len; int len;
len = v2 ? sizeof(val) : sizeof(struct sctp_paddrthlds); len = v2 ? sizeof(*val) : sizeof(struct sctp_paddrthlds);
if (optlen < len) if (optlen < len)
return -EINVAL; return -EINVAL;
if (copy_from_user(&val, optval, len))
return -EFAULT;
if (v2 && val.spt_pathpfthld > val.spt_pathcpthld) if (v2 && val->spt_pathpfthld > val->spt_pathcpthld)
return -EINVAL; return -EINVAL;
if (!sctp_is_any(sk, (const union sctp_addr *)&val.spt_address)) { if (!sctp_is_any(sk, (const union sctp_addr *)&val->spt_address)) {
trans = sctp_addr_id2transport(sk, &val.spt_address, trans = sctp_addr_id2transport(sk, &val->spt_address,
val.spt_assoc_id); val->spt_assoc_id);
if (!trans) if (!trans)
return -ENOENT; return -ENOENT;
if (val.spt_pathmaxrxt) if (val->spt_pathmaxrxt)
trans->pathmaxrxt = val.spt_pathmaxrxt; trans->pathmaxrxt = val->spt_pathmaxrxt;
if (v2) if (v2)
trans->ps_retrans = val.spt_pathcpthld; trans->ps_retrans = val->spt_pathcpthld;
trans->pf_retrans = val.spt_pathpfthld; trans->pf_retrans = val->spt_pathpfthld;
return 0; return 0;
} }
asoc = sctp_id2assoc(sk, val.spt_assoc_id); asoc = sctp_id2assoc(sk, val->spt_assoc_id);
if (!asoc && val.spt_assoc_id != SCTP_FUTURE_ASSOC && if (!asoc && val->spt_assoc_id != SCTP_FUTURE_ASSOC &&
sctp_style(sk, UDP)) sctp_style(sk, UDP))
return -EINVAL; return -EINVAL;
if (asoc) { if (asoc) {
list_for_each_entry(trans, &asoc->peer.transport_addr_list, list_for_each_entry(trans, &asoc->peer.transport_addr_list,
transports) { transports) {
if (val.spt_pathmaxrxt) if (val->spt_pathmaxrxt)
trans->pathmaxrxt = val.spt_pathmaxrxt; trans->pathmaxrxt = val->spt_pathmaxrxt;
if (v2) if (v2)
trans->ps_retrans = val.spt_pathcpthld; trans->ps_retrans = val->spt_pathcpthld;
trans->pf_retrans = val.spt_pathpfthld; trans->pf_retrans = val->spt_pathpfthld;
} }
if (val.spt_pathmaxrxt) if (val->spt_pathmaxrxt)
asoc->pathmaxrxt = val.spt_pathmaxrxt; asoc->pathmaxrxt = val->spt_pathmaxrxt;
if (v2) if (v2)
asoc->ps_retrans = val.spt_pathcpthld; asoc->ps_retrans = val->spt_pathcpthld;
asoc->pf_retrans = val.spt_pathpfthld; asoc->pf_retrans = val->spt_pathpfthld;
} else { } else {
struct sctp_sock *sp = sctp_sk(sk); struct sctp_sock *sp = sctp_sk(sk);
if (val.spt_pathmaxrxt) if (val->spt_pathmaxrxt)
sp->pathmaxrxt = val.spt_pathmaxrxt; sp->pathmaxrxt = val->spt_pathmaxrxt;
if (v2) if (v2)
sp->ps_retrans = val.spt_pathcpthld; sp->ps_retrans = val->spt_pathcpthld;
sp->pf_retrans = val.spt_pathpfthld; sp->pf_retrans = val->spt_pathpfthld;
} }
return 0; return 0;
@ -4690,11 +4687,11 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
retval = sctp_setsockopt_auto_asconf(sk, kopt, optlen); retval = sctp_setsockopt_auto_asconf(sk, kopt, optlen);
break; break;
case SCTP_PEER_ADDR_THLDS: case SCTP_PEER_ADDR_THLDS:
retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen, retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
false); false);
break; break;
case SCTP_PEER_ADDR_THLDS_V2: case SCTP_PEER_ADDR_THLDS_V2:
retval = sctp_setsockopt_paddr_thresholds(sk, optval, optlen, retval = sctp_setsockopt_paddr_thresholds(sk, kopt, optlen,
true); true);
break; break;
case SCTP_RECVRCVINFO: case SCTP_RECVRCVINFO: