Skip to content

Commit

Permalink
sctp: use memdup_user to copy data from userspace
Browse files Browse the repository at this point in the history
Use common function to simply code.

Signed-off-by: Shan Wei <shanwei@cn.fujitsu.com>
Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com>
Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Shan Wei authored and David S. Miller committed Apr 20, 2011
1 parent 6600992 commit 934253a
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions net/sctp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -3215,14 +3215,9 @@ static int sctp_setsockopt_hmac_ident(struct sock *sk,
if (optlen < sizeof(struct sctp_hmacalgo))
return -EINVAL;

hmacs = kmalloc(optlen, GFP_KERNEL);
if (!hmacs)
return -ENOMEM;

if (copy_from_user(hmacs, optval, optlen)) {
err = -EFAULT;
goto out;
}
hmacs= memdup_user(optval, optlen);
if (IS_ERR(hmacs))
return PTR_ERR(hmacs);

idents = hmacs->shmac_num_idents;
if (idents == 0 || idents > SCTP_AUTH_NUM_HMACS ||
Expand Down Expand Up @@ -3257,14 +3252,9 @@ static int sctp_setsockopt_auth_key(struct sock *sk,
if (optlen <= sizeof(struct sctp_authkey))
return -EINVAL;

authkey = kmalloc(optlen, GFP_KERNEL);
if (!authkey)
return -ENOMEM;

if (copy_from_user(authkey, optval, optlen)) {
ret = -EFAULT;
goto out;
}
authkey= memdup_user(optval, optlen);
if (IS_ERR(authkey))
return PTR_ERR(authkey);

if (authkey->sca_keylength > optlen - sizeof(struct sctp_authkey)) {
ret = -EINVAL;
Expand Down

0 comments on commit 934253a

Please sign in to comment.