netfilter: ipset: Fix an error code in ip_set_sockfn_get()

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: a7b4f989a6 ("netfilter: ipset: IP set core support")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Jozsef Kadlecsik <kadlec@netfilter.org>
This commit is contained in:
Dan Carpenter 2019-08-24 17:49:55 +03:00 committed by Jozsef Kadlecsik
parent 3da0966320
commit 30b7244d79
1 changed files with 5 additions and 3 deletions

View File

@ -2069,8 +2069,9 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
} }
req_version->version = IPSET_PROTOCOL; req_version->version = IPSET_PROTOCOL;
ret = copy_to_user(user, req_version, if (copy_to_user(user, req_version,
sizeof(struct ip_set_req_version)); sizeof(struct ip_set_req_version)))
ret = -EFAULT;
goto done; goto done;
} }
case IP_SET_OP_GET_BYNAME: { case IP_SET_OP_GET_BYNAME: {
@ -2129,7 +2130,8 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
} /* end of switch(op) */ } /* end of switch(op) */
copy: copy:
ret = copy_to_user(user, data, copylen); if (copy_to_user(user, data, copylen))
ret = -EFAULT;
done: done:
vfree(data); vfree(data);