Commit 934253a7 authored by Shan Wei's avatar Shan Wei Committed by David S. Miller

sctp: use memdup_user to copy data from userspace

Use common function to simply code.
Signed-off-by: default avatarShan Wei <shanwei@cn.fujitsu.com>
Signed-off-by: default avatarVlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: default avatarWei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 66009927
...@@ -3215,14 +3215,9 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk, ...@@ -3215,14 +3215,9 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk,
if (optlen < sizeof(struct sctp_hmacalgo)) if (optlen < sizeof(struct sctp_hmacalgo))
return -EINVAL; return -EINVAL;
hmacs = kmalloc(optlen, GFP_KERNEL); hmacs= memdup_user(optval, optlen);
if (!hmacs) if (IS_ERR(hmacs))
return -ENOMEM; return PTR_ERR(hmacs);
if (copy_from_user(hmacs, optval, optlen)) {
err = -EFAULT;
goto out;
}
idents = hmacs->shmac_num_idents; idents = hmacs->shmac_num_idents;
if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS || if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||
...@@ -3257,14 +3252,9 @@ static int sctp_setsockopt_auth_key(struct sock *sk, ...@@ -3257,14 +3252,9 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
if (optlen <= sizeof(struct sctp_authkey)) if (optlen <= sizeof(struct sctp_authkey))
return -EINVAL; return -EINVAL;
authkey = kmalloc(optlen, GFP_KERNEL); authkey= memdup_user(optval, optlen);
if (!authkey) if (IS_ERR(authkey))
return -ENOMEM; return PTR_ERR(authkey);
if (copy_from_user(authkey, optval, optlen)) {
ret = -EFAULT;
goto out;
}
if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) { if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) {
ret = -EINVAL; ret = -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment