netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netfilter: ipset: Fix an error code in ip_set_sockfn_get()
@ 2019-08-21  7:18 Dan Carpenter
  2019-08-22  9:11 ` Kadlecsik József
  0 siblings, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2019-08-21  7:18 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik
  Cc: Florian Westphal, Florent Fourcot, Kate Stewart, Allison Randal,
	Aditya Pakki, Qian Cai, Andrey Ryabinin, Johannes Berg,
	Stefano Brivio, netfilter-devel, coreteam, kernel-janitors

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 <dan.carpenter@oracle.com>
---
 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


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] netfilter: ipset: Fix an error code in ip_set_sockfn_get()
  2019-08-21  7:18 [PATCH] netfilter: ipset: Fix an error code in ip_set_sockfn_get() Dan Carpenter
@ 2019-08-22  9:11 ` Kadlecsik József
  2019-08-22  9:41   ` Dan Carpenter
  2019-08-24 14:49   ` [PATCH v2] " Dan Carpenter
  0 siblings, 2 replies; 5+ messages in thread
From: Kadlecsik József @ 2019-08-22  9:11 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	Florent Fourcot, Kate Stewart, Allison Randal, Aditya Pakki,
	Qian Cai, Andrey Ryabinin, Johannes Berg, Stefano Brivio,
	netfilter-devel, coreteam, kernel-janitors

Hi Dan,

On Wed, 21 Aug 2019, Dan Carpenter wrote:

> 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.

Yes, you are right. There's another usage of copy_to_user() in this 
function, could you fix it as well?

Best regards,
Jozsef
 
> Fixes: a7b4f989a629 ("netfilter: ipset: IP set core support")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  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
> 
> 

-
E-mail  : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.mta.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
          H-1525 Budapest 114, POB. 49, Hungary

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] netfilter: ipset: Fix an error code in ip_set_sockfn_get()
  2019-08-22  9:11 ` Kadlecsik József
@ 2019-08-22  9:41   ` Dan Carpenter
  2019-08-24 14:49   ` [PATCH v2] " Dan Carpenter
  1 sibling, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2019-08-22  9:41 UTC (permalink / raw)
  To: Kadlecsik József
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	Florent Fourcot, Kate Stewart, Allison Randal, Aditya Pakki,
	Qian Cai, Andrey Ryabinin, Johannes Berg, Stefano Brivio,
	netfilter-devel, coreteam, kernel-janitors

On Thu, Aug 22, 2019 at 11:11:56AM +0200, Kadlecsik József wrote:
> Hi Dan,
> 
> On Wed, 21 Aug 2019, Dan Carpenter wrote:
> 
> > 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.
> 
> Yes, you are right. There's another usage of copy_to_user() in this 
> function, could you fix it as well?
> 

Yes, of course.  Thanks for the review.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] netfilter: ipset: Fix an error code in ip_set_sockfn_get()
  2019-08-22  9:11 ` Kadlecsik József
  2019-08-22  9:41   ` Dan Carpenter
@ 2019-08-24 14:49   ` Dan Carpenter
  2019-08-27 18:21     ` Kadlecsik József
  1 sibling, 1 reply; 5+ messages in thread
From: Dan Carpenter @ 2019-08-24 14:49 UTC (permalink / raw)
  To: Pablo Neira Ayuso, Jozsef Kadlecsik
  Cc: Florian Westphal, Florent Fourcot, Greg Kroah-Hartman,
	Thomas Gleixner, Andrey Ryabinin, Aditya Pakki, Johannes Berg,
	Stefano Brivio, netfilter-devel, coreteam, kernel-janitors

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 <dan.carpenter@oracle.com>
---
v2: I missed the other instance of this issue

 net/netfilter/ipset/ip_set_core.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
index e64d5f9a89dd..e7288eab7512 100644
--- a/net/netfilter/ipset/ip_set_core.c
+++ b/net/netfilter/ipset/ip_set_core.c
@@ -2069,8 +2069,9 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
 		}
 
 		req_version->version = IPSET_PROTOCOL;
-		ret = copy_to_user(user, req_version,
-				   sizeof(struct ip_set_req_version));
+		if (copy_to_user(user, req_version,
+				 sizeof(struct ip_set_req_version)))
+			ret = -EFAULT;
 		goto done;
 	}
 	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) */
 
 copy:
-	ret = copy_to_user(user, data, copylen);
+	if (copy_to_user(user, data, copylen))
+		ret = -EFAULT;
 
 done:
 	vfree(data);
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] netfilter: ipset: Fix an error code in ip_set_sockfn_get()
  2019-08-24 14:49   ` [PATCH v2] " Dan Carpenter
@ 2019-08-27 18:21     ` Kadlecsik József
  0 siblings, 0 replies; 5+ messages in thread
From: Kadlecsik József @ 2019-08-27 18:21 UTC (permalink / raw)
  To: Dan Carpenter
  Cc: Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal,
	Florent Fourcot, Greg Kroah-Hartman, Thomas Gleixner,
	Andrey Ryabinin, Aditya Pakki, Johannes Berg, Stefano Brivio,
	netfilter-devel, coreteam, kernel-janitors


Hi Dan,

On Sat, 24 Aug 2019, Dan Carpenter wrote:

> 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 <dan.carpenter@oracle.com>
> ---
> v2: I missed the other instance of this issue
> 
>  net/netfilter/ipset/ip_set_core.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)

Patch is applied in the ipset git tree, thanks!

Best regards,
Jozsef

> diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
> index e64d5f9a89dd..e7288eab7512 100644
> --- a/net/netfilter/ipset/ip_set_core.c
> +++ b/net/netfilter/ipset/ip_set_core.c
> @@ -2069,8 +2069,9 @@ ip_set_sockfn_get(struct sock *sk, int optval, void __user *user, int *len)
>  		}
>  
>  		req_version->version = IPSET_PROTOCOL;
> -		ret = copy_to_user(user, req_version,
> -				   sizeof(struct ip_set_req_version));
> +		if (copy_to_user(user, req_version,
> +				 sizeof(struct ip_set_req_version)))
> +			ret = -EFAULT;
>  		goto done;
>  	}
>  	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) */
>  
>  copy:
> -	ret = copy_to_user(user, data, copylen);
> +	if (copy_to_user(user, data, copylen))
> +		ret = -EFAULT;
>  
>  done:
>  	vfree(data);
> -- 
> 2.11.0
> 
> 

-
E-mail  : kadlec@blackhole.kfki.hu, kadlecsik.jozsef@wigner.mta.hu
PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : Wigner Research Centre for Physics, Hungarian Academy of Sciences
          H-1525 Budapest 114, POB. 49, Hungary

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-08-27 18:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-21  7:18 [PATCH] netfilter: ipset: Fix an error code in ip_set_sockfn_get() Dan Carpenter
2019-08-22  9:11 ` Kadlecsik József
2019-08-22  9:41   ` Dan Carpenter
2019-08-24 14:49   ` [PATCH v2] " Dan Carpenter
2019-08-27 18:21     ` Kadlecsik József

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).