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>
This commit is contained in:
committed by
Steffen Klassert
parent
a95cfad947
commit
a133d93054
@ -2023,13 +2023,9 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
|
|||||||
if (optlen <= 0 || optlen > PAGE_SIZE)
|
if (optlen <= 0 || optlen > PAGE_SIZE)
|
||||||
return -EMSGSIZE;
|
return -EMSGSIZE;
|
||||||
|
|
||||||
data = kmalloc(optlen, GFP_KERNEL);
|
data = memdup_user(optval, optlen);
|
||||||
if (!data)
|
if (IS_ERR(data))
|
||||||
return -ENOMEM;
|
return PTR_ERR(data);
|
||||||
|
|
||||||
err = -EFAULT;
|
|
||||||
if (copy_from_user(data, optval, optlen))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
err = -EINVAL;
|
err = -EINVAL;
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
@ -2047,7 +2043,6 @@ int xfrm_user_policy(struct sock *sk, int optname, u8 __user *optval, int optlen
|
|||||||
err = 0;
|
err = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
kfree(data);
|
kfree(data);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user