* [PATCH -next] ax25: avoid overflows in ax25_setsockopt()
@ 2011-12-27 19:43 Xi Wang
2011-12-28 19:08 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: Xi Wang @ 2011-12-27 19:43 UTC (permalink / raw)
To: linux-hams; +Cc: David S. Miller, netdev, Xi Wang, Ralf Baechle
Commit be639ac6 ("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 <xi.wang@gmail.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
---
net/ax25/af_ax25.c | 11 ++++++-----
1 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/net/ax25/af_ax25.c b/net/ax25/af_ax25.c
index b863c18..3cd0a0d 100644
--- a/net/ax25/af_ax25.c
+++ b/net/ax25/af_ax25.c
@@ -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);
@@ -609,7 +610,7 @@ 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;
}
@@ -617,7 +618,7 @@ static int ax25_setsockopt(struct socket *sock, int level, int optname,
break;
case AX25_BACKOFF:
- if (opt < 0 || opt > 2) {
+ if (opt > 2) {
res = -EINVAL;
break;
}
--
1.7.5.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH -next] ax25: avoid overflows in ax25_setsockopt()
2011-12-27 19:43 [PATCH -next] ax25: avoid overflows in ax25_setsockopt() Xi Wang
@ 2011-12-28 19:08 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2011-12-28 19:08 UTC (permalink / raw)
To: xi.wang; +Cc: linux-hams, netdev, ralf
From: Xi Wang <xi.wang@gmail.com>
Date: Tue, 27 Dec 2011 14:43:19 -0500
> Commit be639ac6 ("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 <xi.wang@gmail.com>
> Cc: Ralf Baechle <ralf@linux-mips.org>
Applied.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-28 19:08 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-27 19:43 [PATCH -next] ax25: avoid overflows in ax25_setsockopt() Xi Wang
2011-12-28 19:08 ` 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).