From 43727da90ec8955f1351ad582c6bc8f1c1ab8ab8 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 13 May 2017 18:22:53 -0400 Subject: [PATCH] do_ipv6_setsockopt(): don't open-code memdup_user() Signed-off-by: Al Viro --- net/ipv6/ipv6_sockglue.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c index a531ba032b85..f8298c9a3160 100644 --- a/net/ipv6/ipv6_sockglue.c +++ b/net/ipv6/ipv6_sockglue.c @@ -735,14 +735,9 @@ done: retv = -ENOBUFS; break; } - gsf = kmalloc(optlen, GFP_KERNEL); - if (!gsf) { - retv = -ENOBUFS; - break; - } - retv = -EFAULT; - if (copy_from_user(gsf, optval, optlen)) { - kfree(gsf); + gsf = memdup_user(optval, optlen); + if (IS_ERR(gsf)) { + retv = PTR_ERR(gsf); break; } /* numsrc >= (4G-140)/128 overflow in 32 bits */