Commit dc35616e authored by Dan Carpenter's avatar Dan Carpenter Committed by David S. Miller

netrom: fix api breakage in nr_setsockopt()

This needs to copy an unsigned int from user space instead of a long to
avoid breaking user space with an API change.

I have updated all the integer overflow checks from ULONG to UINT as
well.  This is a slight API change but I do not expect it to affect
anything in real life.

Fixes: 3087a6f3 ("netrom: fix copying in user data in nr_setsockopt")
Signed-off-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 93719370
...@@ -298,7 +298,7 @@ static int nr_setsockopt(struct socket *sock, int level, int optname, ...@@ -298,7 +298,7 @@ static int nr_setsockopt(struct socket *sock, int level, int optname,
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
struct nr_sock *nr = nr_sk(sk); struct nr_sock *nr = nr_sk(sk);
unsigned long opt; unsigned int opt;
if (level != SOL_NETROM) if (level != SOL_NETROM)
return -ENOPROTOOPT; return -ENOPROTOOPT;
...@@ -306,18 +306,18 @@ static int nr_setsockopt(struct socket *sock, int level, int optname, ...@@ -306,18 +306,18 @@ static int nr_setsockopt(struct socket *sock, int level, int optname,
if (optlen < sizeof(unsigned int)) if (optlen < sizeof(unsigned int))
return -EINVAL; return -EINVAL;
if (copy_from_sockptr(&opt, optval, sizeof(unsigned long))) if (copy_from_sockptr(&opt, optval, sizeof(opt)))
return -EFAULT; return -EFAULT;
switch (optname) { switch (optname) {
case NETROM_T1: case NETROM_T1:
if (opt < 1 || opt > ULONG_MAX / HZ) if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL; return -EINVAL;
nr->t1 = opt * HZ; nr->t1 = opt * HZ;
return 0; return 0;
case NETROM_T2: case NETROM_T2:
if (opt < 1 || opt > ULONG_MAX / HZ) if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL; return -EINVAL;
nr->t2 = opt * HZ; nr->t2 = opt * HZ;
return 0; return 0;
...@@ -329,13 +329,13 @@ static int nr_setsockopt(struct socket *sock, int level, int optname, ...@@ -329,13 +329,13 @@ static int nr_setsockopt(struct socket *sock, int level, int optname,
return 0; return 0;
case NETROM_T4: case NETROM_T4:
if (opt < 1 || opt > ULONG_MAX / HZ) if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL; return -EINVAL;
nr->t4 = opt * HZ; nr->t4 = opt * HZ;
return 0; return 0;
case NETROM_IDLE: case NETROM_IDLE:
if (opt > ULONG_MAX / (60 * HZ)) if (opt > UINT_MAX / (60 * HZ))
return -EINVAL; return -EINVAL;
nr->idle = opt * 60 * HZ; nr->idle = opt * 60 * HZ;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment