The copy_to_user() function returns the number of bytes remaining to be
copied.  In this code, that positive return is checked at the end of the
function and we return zero/success.  What we should do instead is
return -EFAULT.

Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
Signed-off-by: Dan Carpenter <[email protected]>
---
 net/netfilter/ipset/ip_set_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/netfilter/ipset/ip_set_core.c 
b/net/netfilter/ipset/ip_set_core.c
index e64d5f9a89dd..15b8d4318207 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -2129,7 +2129,8 @@ ip_set_sockfn_get(struct sock *sk, int optval, void 
__user *user, int *len)
        }       /* end of switch(op) */
 
 copy:
-       ret = copy_to_user(user, data, copylen);
+       if (copy_to_user(user, data, copylen))
+               ret = -EFAULT;
 
 done:
        vfree(data);
-- 
2.20.1

Reply via email to