ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
Subsystems (2)
PATCH 1/1 ax25: unsigned cannot be less than 0 in ax25_ctl_ioctl()
struct ax25_ctl_struct member `arg' is unsigned and cannot be less than 0.
---
If the ax25_ctl.arg limit is known to be lower, please suggest other values.
net/ax25/af_ax25.c +4 -4
@@ -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 ;
what is about something like:
tmp_arg=ax25_ctl.arg * HZ;
if (arg == 0 || arg > ULONG_MAX )
goto einval_put;
re,
wh
Quoted 50 lines · Roel Kluin
struct
ax25_ctl_structmember `arg' is unsigned and cannot be less than 0.Signed-off-by Roel Kluin <[email protected]>---
If the ax25_ctl.arg limit is known to be lower, please suggest other values.net/ax25/af_ax25.c +4
-5@@ -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 ; --To unsubscribe from this list: send the line "unsubscribe linux-hams" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
struct ax25_ctl_struct member `arg' is unsigned and cannot be less than 0.
---
Quoted 5 lines
Quoted 2 lines
If the ax25_ctl.arg limit is known to be lower, please suggest other values.
what is about something like:
Quoted 7 lines
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?
net/ax25/af_ax25.c +3 -4
@@ -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 ;
Quoted 7 lines · Roel Kluin
Quoted 4 lines
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.
net/ax25/af_ax25.c static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg) · line 373
Quoted 2 lines
net/ax25/af_ax25.c +2
-0+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
Quoted 15 lines · Kevin Dawson
Quoted 7 lines · Roel Kluin
Quoted 4 lines
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.
net/ax25/af_ax25.c static int ax25_ctl_ioctl(const unsigned int cmd, void __user *arg) · line 373
Quoted 2 lines
net/ax25/af_ax25.c +2
-0+if (ax25_ctl.arg *HZ >ULONG_MAX && ax25_ctl.cmd !=AX25_KILL ) +return -EINVAL ;
Quoted 7 lines
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
Quoted 8 lines · walter harms
Quoted 2 lines · Kevin Dawson
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
struct ax25_ctl_struct member `arg' is unsigned and cannot be less than 0.
---
Op 12-10-09 23:58, Kevin Dawson schreef:
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
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.
Quoted 7 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ 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?
net/ax25/af_ax25.c +3 -4
@@ -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 ;
From: Roel Kluin <[email protected]>
Date: Wed, 14 Oct 2009 17:26:30 +0200
Quoted 4 lines
struct
ax25_ctl_structmember `arg' is unsigned and cannot be less than 0.Signed-off-by Roel Kluin <[email protected]>
Applied to net-next-2.6