Skip to content

Commit

Permalink
ax25: avoid overflows in ax25_setsockopt()
Browse files Browse the repository at this point in the history
Commit be639ac ("NET: AX.25: Check ioctl arguments to avoid overflows
further down the road") rejects very large arguments, but doesn't
completely fix overflows on 64-bit systems.  Consider the AX25_T2 case.

	int opt;
	...
	if (opt < 1 || opt > ULONG_MAX / HZ) {
		res = -EINVAL;
		break;
	}
	ax25->t2 = opt * HZ;

The 32-bit multiplication opt * HZ would overflow before being assigned
to 64-bit ax25->t2.  This patch changes "opt" to unsigned long.

Signed-off-by: Xi Wang <[email protected]>
Cc: Ralf Baechle <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
xiw authored and davem330 committed Dec 28, 2011
1 parent fa84309 commit ba1cffe
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions net/ax25/af_ax25.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,16 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
ax25_cb *ax25;
struct net_device *dev;
char devname[IFNAMSIZ];
int opt, res = 0;
unsigned long opt;
int res = 0;

if (level != SOL_AX25)
return -ENOPROTOOPT;

if (optlen < sizeof(int))
if (optlen < sizeof(unsigned int))
return -EINVAL;

if (get_user(opt, (int __user *)optval))
if (get_user(opt, (unsigned int __user *)optval))
return -EFAULT;

lock_sock(sk);
Expand Down Expand Up @@ -609,15 +610,15 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
break;

case AX25_IDLE:
if (opt < 0 || opt > ULONG_MAX / (60 * HZ)) {
if (opt > ULONG_MAX / (60 * HZ)) {
res = -EINVAL;
break;
}
ax25->idle = opt * 60 * HZ;
break;

case AX25_BACKOFF:
if (opt < 0 || opt > 2) {
if (opt > 2) {
res = -EINVAL;
break;
}
Expand Down

0 comments on commit ba1cffe

Please sign in to comment.