sctp: pass a kernel pointer to sctp_setsockopt_maxseg

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:21:56 +02:00 коммит произвёл David S. Miller
Родитель ffc08f086a
Коммит dcd0357580
1 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -3215,11 +3215,13 @@ static int sctp_setsockopt_mappedv4(struct sock *sk, int *val,
* changed (effecting future associations only). * changed (effecting future associations only).
* assoc_value: This parameter specifies the maximum size in bytes. * assoc_value: This parameter specifies the maximum size in bytes.
*/ */
static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned int optlen) static int sctp_setsockopt_maxseg(struct sock *sk,
struct sctp_assoc_value *params,
unsigned int optlen)
{ {
struct sctp_sock *sp = sctp_sk(sk); struct sctp_sock *sp = sctp_sk(sk);
struct sctp_assoc_value params;
struct sctp_association *asoc; struct sctp_association *asoc;
sctp_assoc_t assoc_id;
int val; int val;
if (optlen == sizeof(int)) { if (optlen == sizeof(int)) {
@ -3228,19 +3230,17 @@ static int sctp_setsockopt_maxseg(struct sock *sk, char __user *optval, unsigned
"Use of int in maxseg socket option.\n" "Use of int in maxseg socket option.\n"
"Use struct sctp_assoc_value instead\n", "Use struct sctp_assoc_value instead\n",
current->comm, task_pid_nr(current)); current->comm, task_pid_nr(current));
if (copy_from_user(&val, optval, optlen)) assoc_id = SCTP_FUTURE_ASSOC;
return -EFAULT; val = *(int *)params;
params.assoc_id = SCTP_FUTURE_ASSOC;
} else if (optlen == sizeof(struct sctp_assoc_value)) { } else if (optlen == sizeof(struct sctp_assoc_value)) {
if (copy_from_user(&params, optval, optlen)) assoc_id = params->assoc_id;
return -EFAULT; val = params->assoc_value;
val = params.assoc_value;
} else { } else {
return -EINVAL; return -EINVAL;
} }
asoc = sctp_id2assoc(sk, params.assoc_id); asoc = sctp_id2assoc(sk, assoc_id);
if (!asoc && params.assoc_id != SCTP_FUTURE_ASSOC && if (!asoc && assoc_id != SCTP_FUTURE_ASSOC &&
sctp_style(sk, UDP)) sctp_style(sk, UDP))
return -EINVAL; return -EINVAL;
@ -4697,7 +4697,7 @@ static int sctp_setsockopt(struct sock *sk, int level, int optname,
retval = sctp_setsockopt_mappedv4(sk, kopt, optlen); retval = sctp_setsockopt_mappedv4(sk, kopt, optlen);
break; break;
case SCTP_MAXSEG: case SCTP_MAXSEG:
retval = sctp_setsockopt_maxseg(sk, optval, optlen); retval = sctp_setsockopt_maxseg(sk, kopt, optlen);
break; break;
case SCTP_ADAPTATION_LAYER: case SCTP_ADAPTATION_LAYER:
retval = sctp_setsockopt_adaptation_layer(sk, optval, optlen); retval = sctp_setsockopt_adaptation_layer(sk, optval, optlen);