summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeliang Tang <geliangtang@gmail.com>2017-05-06 23:42:21 +0800
committerSteffen Klassert <steffen.klassert@secunet.com>2017-05-16 07:32:25 +0200
commita133d93054fa063fb3bd328abdc3d09a7e687afe (patch)
tree060e597d655c08c6ad6470e888798f9125ab9de2
parenta95cfad947d5f40cfbf9ad3019575aac1d8ac7a6 (diff)
downloadlinux-stable-a133d93054fa063fb3bd328abdc3d09a7e687afe.tar.gz
linux-stable-a133d93054fa063fb3bd328abdc3d09a7e687afe.tar.bz2
linux-stable-a133d93054fa063fb3bd328abdc3d09a7e687afe.zip
xfrm: use memdup_user
Use memdup_user() helper instead of open-coding to simplify the code. Signed-off-by: Geliang Tang <geliangtang@gmail.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
-rw-r--r--net/xfrm/xfrm_state.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index fc3c5aa38754..5780cdad2260 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -2023,13 +2023,9 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
if (optlen <= 0 || optlen > PAGE_SIZE)
return -EMSGSIZE;
- data = kmalloc(optlen, GFP_KERNEL);
- if (!data)
- return -ENOMEM;
-
- err = -EFAULT;
- if (copy_from_user(data, optval, optlen))
- goto out;
+ data = memdup_user(optval, optlen);
+ if (IS_ERR(data))
+ return PTR_ERR(data);
err = -EINVAL;
rcu_read_lock();
@@ -2047,7 +2043,6 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
err = 0;
}
-out:
kfree(data);
return err;
}