From: Al Viro Date: Sat, 13 May 2017 22:16:28 +0000 (-0400) Subject: xfrm_user_policy(): don't open-code memdup_user() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=7f2d17c67ae3a0954e35092564f1cf58726b2c44;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git xfrm_user_policy(): don't open-code memdup_user() Signed-off-by: Al Viro --- 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; }