linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
@ 2011-11-23  4:28 Xi Wang
  2011-11-23 10:44 ` Alan Cox
  2011-11-23 17:09 ` Ralf Baechle
  0 siblings, 2 replies; 7+ messages in thread
From: Xi Wang @ 2011-11-23  4:28 UTC (permalink / raw)
  To: linux-kernel; +Cc: Joerg Reuter, Ralf Baechle, David Miller, linux-hams, netdev

ax25_setsockopt() misses several upper-bound checks on the
user-controlled value.


Reported-by: Fan Long <longfancn@gmail.com>
Signed-off-by: Xi Wang <xi.wang@gmail.com>
---
 net/ax25/af_ax25.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index e7c69f4..be6a8cf 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -571,7 +571,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
 		break;
 
 	case AX25_T1:
-		if (opt < 1) {
+		if (opt < 1 || opt > 30) {
 			res = -EINVAL;
 			break;
 		}
@@ -580,7 +580,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
 		break;
 
 	case AX25_T2:
-		if (opt < 1) {
+		if (opt < 1 || opt > 20) {
 			res = -EINVAL;
 			break;
 		}
@@ -596,7 +596,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
 		break;
 
 	case AX25_T3:
-		if (opt < 1) {
+		if (opt < 0 || opt > 3600) {
 			res = -EINVAL;
 			break;
 		}
@@ -604,7 +604,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
 		break;
 
 	case AX25_IDLE:
-		if (opt < 0) {
+		if (opt < 0 || opt > 65535) {
 			res = -EINVAL;
 			break;
 		}
-- 
1.7.5.4


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

* Re: [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
  2011-11-23  4:28 [PATCH 1/2] ax25: integer overflows in ax25_setsockopt() Xi Wang
@ 2011-11-23 10:44 ` Alan Cox
  2011-11-23 14:04   ` Xi Wang
  2011-11-23 17:09 ` Ralf Baechle
  1 sibling, 1 reply; 7+ messages in thread
From: Alan Cox @ 2011-11-23 10:44 UTC (permalink / raw)
  To: Xi Wang
  Cc: linux-kernel, Joerg Reuter, Ralf Baechle, David Miller,
	linux-hams, netdev

>  	case AX25_T1:
> -		if (opt < 1) {
> +		if (opt < 1 || opt > 30) {

Where do these values come from ? If they are from some 'standard' then
really we should avoid restricting needlessly to it, particularly as
AX.25 isn't well defined and is used for all sorts of crazy stuff where
the usual range of settings isn't useful.

Restricting to the point it would overflow makes sense however.

Alan


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

* Re: [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
  2011-11-23 10:44 ` Alan Cox
@ 2011-11-23 14:04   ` Xi Wang
  2011-11-23 14:39     ` Alan Cox
  0 siblings, 1 reply; 7+ messages in thread
From: Xi Wang @ 2011-11-23 14:04 UTC (permalink / raw)
  To: Alan Cox
  Cc: linux-kernel, Joerg Reuter, Ralf Baechle, David Miller,
	linux-hams, netdev

All these magic numbers come from net/ax25/sysctl_net_ax25.c, where
min/max values of each field are set for sysctl.  Is it okay to use
them?

- xi

On Wed, Nov 23, 2011 at 5:44 AM, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
>>       case AX25_T1:
>> -             if (opt < 1) {
>> +             if (opt < 1 || opt > 30) {
>
> Where do these values come from ? If they are from some 'standard' then
> really we should avoid restricting needlessly to it, particularly as
> AX.25 isn't well defined and is used for all sorts of crazy stuff where
> the usual range of settings isn't useful.
>
> Restricting to the point it would overflow makes sense however.
>
> Alan
>
>

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

* Re: [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
  2011-11-23 14:04   ` Xi Wang
@ 2011-11-23 14:39     ` Alan Cox
  2011-11-23 14:53       ` David Laight
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Cox @ 2011-11-23 14:39 UTC (permalink / raw)
  To: Xi Wang
  Cc: linux-kernel, Joerg Reuter, Ralf Baechle, David Miller,
	linux-hams, netdev

On Wed, 23 Nov 2011 09:04:11 -0500
Xi Wang <xi.wang@gmail.com> wrote:

> All these magic numbers come from net/ax25/sysctl_net_ax25.c, where
> min/max values of each field are set for sysctl.  Is it okay to use
> them?

The sysctl range is the 'standard' range, but it's always historically
been possible to override them in apps for special cases. I'm wary of
changing that because people do insane things like AX.25 bounced off the
moon where you need very long timeouts.

Alan

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

* RE: [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
  2011-11-23 14:39     ` Alan Cox
@ 2011-11-23 14:53       ` David Laight
  0 siblings, 0 replies; 7+ messages in thread
From: David Laight @ 2011-11-23 14:53 UTC (permalink / raw)
  To: Alan Cox, Xi Wang
  Cc: linux-kernel, Joerg Reuter, Ralf Baechle, David Miller,
	linux-hams, netdev

 
> > All these magic numbers come from net/ax25/sysctl_net_ax25.c, where
> > min/max values of each field are set for sysctl.  Is it okay to use
> > them?
> 
> The sysctl range is the 'standard' range, but it's always historically
> been possible to override them in apps for special cases. I'm wary of
> changing that because people do insane things like AX.25 
> bounced off the moon where you need very long timeouts.

It is a long time since I wrote any of the X.25 protocol
stack layers, but I would agree that limiting timers to the
values defined in the standard is probably not a good idea.

Even normal telco's may have decided to use values that
are outside the nominal range.

These timers are almost certainly either 'guard' timers
for missing responses or retransmit timers for 'keepalive'
messages - so allowing much larger values doesn't matter.
I'd only limit them in order to stop the code breaking.

The lower limit (1 second) will be below the limit for the
protocol - but exists to stop the code breaking.

	David



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

* Re: [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
  2011-11-23  4:28 [PATCH 1/2] ax25: integer overflows in ax25_setsockopt() Xi Wang
  2011-11-23 10:44 ` Alan Cox
@ 2011-11-23 17:09 ` Ralf Baechle
  2011-11-24 19:09   ` Xi Wang
  1 sibling, 1 reply; 7+ messages in thread
From: Ralf Baechle @ 2011-11-23 17:09 UTC (permalink / raw)
  To: Xi Wang
  Cc: linux-kernel, Joerg Reuter, David Miller, linux-hams, netdev,
	Thomas Osterried

On Tue, Nov 22, 2011 at 11:28:24PM -0500, Xi Wang wrote:

> ax25_setsockopt() misses several upper-bound checks on the
> user-controlled value.
> 
> 
> Reported-by: Fan Long <longfancn@gmail.com>
> Signed-off-by: Xi Wang <xi.wang@gmail.com>
> ---
>  net/ax25/af_ax25.c |    8 ++++----
>  1 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
> index e7c69f4..be6a8cf 100644
> --- a/net/ax25/af_ax25.c
> +++ b/net/ax25/af_ax25.c
> @@ -571,7 +571,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
>  		break;
>  
>  	case AX25_T1:
> -		if (opt < 1) {
> +		if (opt < 1 || opt > 30) {
>  			res = -EINVAL;
>  			break;
>  		}

30 seconds is definitively too low.  The TCP spec assumes that a RTT
of up to 120s is possible.  In slow packet radio networks 15 minutes are
easily possible in HF networks.

How about AX.25 to the P5A mars mission?

A silly value for T1 will be caught further down the road, so no damage
but an application really should receive a sensible return value when
trying something stupid.

If an apps wants to shoot itself into the foot there is nothing wrong with
being the arms dealer so an error check should be something like

	if (val > ULONG_MAX / HZ)
		bail_out;

which will do the right thing even on a 64-bit system and prevent an
overflow in the multiplication further down.

> @@ -580,7 +580,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
>  		break;
>  
>  	case AX25_T2:
> -		if (opt < 1) {
> +		if (opt < 1 || opt > 20) {
>  			res = -EINVAL;
>  			break;
>  		}

An excessive value here could result in a timer being set to expire in
the past similar in effect to setting a very low value.  Again it's ok
if a user tries to shoot himself into the other foot as well.

> @@ -596,7 +596,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
>  		break;
>  
>  	case AX25_T3:
> -		if (opt < 1) {
> +		if (opt < 0 || opt > 3600) {
>  			res = -EINVAL;
>  			break;
>  		}

For a stable link it should be possible to set a very high T3 value,
potencially high enough to effectively disable the T3 functionality.

> @@ -604,7 +604,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
>  		break;
>  
>  	case AX25_IDLE:
> -		if (opt < 0) {
> +		if (opt < 0 || opt > 65535) {
>  			res = -EINVAL;
>  			break;
>  		}

I have an updated patch which I'm testing right now.

  Ralf

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

* Re: [PATCH 1/2] ax25: integer overflows in ax25_setsockopt()
  2011-11-23 17:09 ` Ralf Baechle
@ 2011-11-24 19:09   ` Xi Wang
  0 siblings, 0 replies; 7+ messages in thread
From: Xi Wang @ 2011-11-24 19:09 UTC (permalink / raw)
  To: Ralf Baechle
  Cc: linux-kernel, Joerg Reuter, David Miller, linux-hams, netdev,
	Thomas Osterried

Thanks a lot for your comments!  Look forward to your patch.

- xi

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

end of thread, other threads:[~2011-11-24 19:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-23  4:28 [PATCH 1/2] ax25: integer overflows in ax25_setsockopt() Xi Wang
2011-11-23 10:44 ` Alan Cox
2011-11-23 14:04   ` Xi Wang
2011-11-23 14:39     ` Alan Cox
2011-11-23 14:53       ` David Laight
2011-11-23 17:09 ` Ralf Baechle
2011-11-24 19:09   ` Xi Wang

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