netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
@ 2009-10-10 21:22 Roel Kluin
       [not found] ` <4AD34D3C.1060206@bfs.de>
  0 siblings, 1 reply; 7+ messages in thread
From: Roel Kluin @ 2009-10-10 21:22 UTC (permalink / raw)
  To: Joerg Reuter, linux-hams, Andrew Morton, netdev

struct ax25_ctl_struct member `arg' is unsigned and cannot be less
than 0.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
If the ax25_ctl.arg limit is known to be lower, please suggest
other values.

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index f454607..0d99704 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -398,14 +398,14 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
 		break;
 
 	case AX25_T1:
-		if (ax25_ctl.arg < 1)
+		if (ax25_ctl.arg < 1 || ax25_ctl.arg * HZ > ULONG_MAX)
 			goto einval_put;
 		ax25->rtt = (ax25_ctl.arg * HZ) / 2;
 		ax25->t1  = ax25_ctl.arg * HZ;
 		break;
 
 	case AX25_T2:
-		if (ax25_ctl.arg < 1)
+		if (ax25_ctl.arg < 1 || ax25_ctl.arg * HZ > ULONG_MAX)
 			goto einval_put;
 		ax25->t2 = ax25_ctl.arg * HZ;
 		break;
@@ -418,13 +418,13 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
 		break;
 
 	case AX25_T3:
-		if (ax25_ctl.arg < 0)
+		if (ax25_ctl.arg * HZ > ULONG_MAX)
 			goto einval_put;
 		ax25->t3 = ax25_ctl.arg * HZ;
 		break;
 
 	case AX25_IDLE:
-		if (ax25_ctl.arg < 0)
+		if (ax25_ctl.arg * 60 * HZ > ULONG_MAX)
 			goto einval_put;
 		ax25->idle = ax25_ctl.arg * 60 * HZ;
 		break;

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

* Re: [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
       [not found] ` <4AD34D3C.1060206@bfs.de>
@ 2009-10-12 19:02   ` Roel Kluin
  2009-10-12 21:58     ` Kevin Dawson
  0 siblings, 1 reply; 7+ messages in thread
From: Roel Kluin @ 2009-10-12 19:02 UTC (permalink / raw)
  To: wharms; +Cc: linux-hams, netdev, Joerg Reuter, Andrew Morton

struct ax25_ctl_struct member `arg' is unsigned and cannot be less
than 0.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
>> If the ax25_ctl.arg limit is known to be lower, please suggest
>> other values.

> what is about something like:
> 
>  tmp_arg=ax25_ctl.arg * HZ;
> 
>   if (arg == 0 || arg >  ULONG_MAX )
> 		goto einval_put;
> 
> re,
>  wh

I'm not sure, I think this would only work if we made `arg' an
unsigned long long.

How about this?

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index f454607..20ff0f3 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -369,6 +369,9 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
 	if (ax25_ctl.digi_count > AX25_MAX_DIGIS)
 		return -EINVAL;
 
+	if (ax25_ctl.arg * HZ > ULONG_MAX && ax25_ctl.cmd != AX25_KILL)
+		return -EINVAL;
+
 	digi.ndigi = ax25_ctl.digi_count;
 	for (k = 0; k < digi.ndigi; k++)
 		digi.calls[k] = ax25_ctl.digi_addr[k];
@@ -418,14 +421,10 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
 		break;
 
 	case AX25_T3:
-		if (ax25_ctl.arg < 0)
-			goto einval_put;
 		ax25->t3 = ax25_ctl.arg * HZ;
 		break;
 
 	case AX25_IDLE:
-		if (ax25_ctl.arg < 0)
-			goto einval_put;
 		ax25->idle = ax25_ctl.arg * 60 * HZ;
 		break;
 

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

* Re: [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
  2009-10-12 19:02   ` Roel Kluin
@ 2009-10-12 21:58     ` Kevin Dawson
  2009-10-13  9:48       ` walter harms
  2009-10-14 15:26       ` Roel Kluin
  0 siblings, 2 replies; 7+ messages in thread
From: Kevin Dawson @ 2009-10-12 21:58 UTC (permalink / raw)
  To: Roel Kluin; +Cc: wharms, linux-hams, netdev, Joerg Reuter, Andrew Morton

Roel Kluin wrote:

>>  tmp_arg=ax25_ctl.arg * HZ;
>>
>>   if (arg == 0 || arg >  ULONG_MAX )
>> 		goto einval_put;
>
> I'm not sure, I think this would only work if we made `arg' an
> unsigned long long.

That depends on the possible values of ax25_ctl.arg.

> +	if (ax25_ctl.arg * HZ > ULONG_MAX && ax25_ctl.cmd != AX25_KILL)
> +		return -EINVAL;

Why the need to change arg before comparing it with a constant?  Let the 
compiler do the work:

	if (ax25_ctl.arg > ULONG_MAX / HZ && ...

Kevin

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

* Re: [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
  2009-10-12 21:58     ` Kevin Dawson
@ 2009-10-13  9:48       ` walter harms
  2009-10-13 21:50         ` Kevin Dawson
  2009-10-14 15:26       ` Roel Kluin
  1 sibling, 1 reply; 7+ messages in thread
From: walter harms @ 2009-10-13  9:48 UTC (permalink / raw)
  To: Kevin Dawson; +Cc: Roel Kluin, linux-hams, netdev, Joerg Reuter, Andrew Morton



Kevin Dawson schrieb:
> Roel Kluin wrote:
> 
>>>  tmp_arg=ax25_ctl.arg * HZ;
>>>
>>>   if (arg == 0 || arg >  ULONG_MAX )
>>>         goto einval_put;
>>
>> I'm not sure, I think this would only work if we made `arg' an
>> unsigned long long.
> 
> That depends on the possible values of ax25_ctl.arg.
> 
>> +    if (ax25_ctl.arg * HZ > ULONG_MAX && ax25_ctl.cmd != AX25_KILL)
>> +        return -EINVAL;
> 
> Why the need to change arg before comparing it with a constant?  Let the
> compiler do the work:
> 
>     if (ax25_ctl.arg > ULONG_MAX / HZ && ...
> 
> Kevin
> 

i like this because it prevents a wrap around for stupid ax25_ctl.arg values but will not help when
ax25_ctl.arg * HZ is used later. NTL i think HZ does not need to be constant these days but i am not an
expert on that area.

  re,
   wh



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

* Re: [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
  2009-10-13  9:48       ` walter harms
@ 2009-10-13 21:50         ` Kevin Dawson
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Dawson @ 2009-10-13 21:50 UTC (permalink / raw)
  To: wharms; +Cc: linux-hams, netdev, Andrew Morton

walter harms wrote:
> 
> Kevin Dawson schrieb:
>> 
>>     if (ax25_ctl.arg > ULONG_MAX / HZ && ...
> 
> i like this because it prevents a wrap around for stupid ax25_ctl.arg values but will not help when
> ax25_ctl.arg * HZ is used later. NTL i think HZ does not need to be constant these days but i am not an
> expert on that area.

I don't have a kernel source tree at the moment, so I haven't seen where 
it's used, but the same size-limiting principle using divisions would 
apply whether you have constants, variables or function calls.

If ax25_ctl.arg * HZ is used later, one should arrange that the thread 
won't get that far if it has already been deemed an excessive value.

Kevin

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

* Re: [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
  2009-10-12 21:58     ` Kevin Dawson
  2009-10-13  9:48       ` walter harms
@ 2009-10-14 15:26       ` Roel Kluin
  2009-10-30  6:06         ` David Miller
  1 sibling, 1 reply; 7+ messages in thread
From: Roel Kluin @ 2009-10-14 15:26 UTC (permalink / raw)
  To: Kevin Dawson; +Cc: wharms, linux-hams, netdev, Joerg Reuter, Andrew Morton

struct ax25_ctl_struct member `arg' is unsigned and cannot be less
than 0.

Signed-off-by: Roel Kluin <roel.kluin@gmail.com>
---
Op 12-10-09 23:58, Kevin Dawson schreef:

>>>  tmp_arg=ax25_ctl.arg * HZ;
>>>
>>>   if (arg == 0 || arg >  ULONG_MAX )
>>>         goto einval_put;
>>
>> I'm not sure, I think this would only work if we made `arg' an
>> unsigned long long.
> 
> That depends on the possible values of ax25_ctl.arg.
> 
>> +    if (ax25_ctl.arg * HZ > ULONG_MAX && ax25_ctl.cmd != AX25_KILL)
>> +        return -EINVAL;
> 
> Why the need to change arg before comparing it with a constant?  Let the
> compiler do the work:
> 
>     if (ax25_ctl.arg > ULONG_MAX / HZ && ...

Ok, How about this then?

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index f454607..d923ac4 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -369,6 +369,9 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
 	if (ax25_ctl.digi_count > AX25_MAX_DIGIS)
 		return -EINVAL;
 
+	if (ax25_ctl.arg > ULONG_MAX / HZ && ax25_ctl.cmd != AX25_KILL)
+		return -EINVAL;
+
 	digi.ndigi = ax25_ctl.digi_count;
 	for (k = 0; k < digi.ndigi; k++)
 		digi.calls[k] = ax25_ctl.digi_addr[k];
@@ -418,14 +421,10 @@ static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg)
 		break;
 
 	case AX25_T3:
-		if (ax25_ctl.arg < 0)
-			goto einval_put;
 		ax25->t3 = ax25_ctl.arg * HZ;
 		break;
 
 	case AX25_IDLE:
-		if (ax25_ctl.arg < 0)
-			goto einval_put;
 		ax25->idle = ax25_ctl.arg * 60 * HZ;
 		break;
 

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

* Re: [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
  2009-10-14 15:26       ` Roel Kluin
@ 2009-10-30  6:06         ` David Miller
  0 siblings, 0 replies; 7+ messages in thread
From: David Miller @ 2009-10-30  6:06 UTC (permalink / raw)
  To: roel.kluin; +Cc: kevind, wharms, linux-hams, netdev, jreuter, akpm

From: Roel Kluin <roel.kluin@gmail.com>
Date: Wed, 14 Oct 2009 17:26:30 +0200

> struct ax25_ctl_struct member `arg' is unsigned and cannot be less
> than 0.
> 
> Signed-off-by: Roel Kluin <roel.kluin@gmail.com>

Applied to net-next-2.6

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

end of thread, other threads:[~2009-10-30  6:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-10 21:22 [PATCH] ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl() Roel Kluin
     [not found] ` <4AD34D3C.1060206@bfs.de>
2009-10-12 19:02   ` Roel Kluin
2009-10-12 21:58     ` Kevin Dawson
2009-10-13  9:48       ` walter harms
2009-10-13 21:50         ` Kevin Dawson
2009-10-14 15:26       ` Roel Kluin
2009-10-30  6:06         ` David Miller

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