Skip to content

Commit dc35616

Browse files
Dan Carpenterdavem330
authored andcommitted
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: 3087a6f ("netrom: fix copying in user data in nr_setsockopt") Signed-off-by: Dan Carpenter <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9371937 commit dc35616

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

net/netrom/af_netrom.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,26 +298,26 @@ static int nr_setsockopt(struct socket *sock, int level, int optname,
298298
{
299299
struct sock *sk = sock->sk;
300300
struct nr_sock *nr = nr_sk(sk);
301-
unsigned long opt;
301+
unsigned int opt;
302302

303303
if (level != SOL_NETROM)
304304
return -ENOPROTOOPT;
305305

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

309-
if (copy_from_sockptr(&opt, optval, sizeof(unsigned long)))
309+
if (copy_from_sockptr(&opt, optval, sizeof(opt)))
310310
return -EFAULT;
311311

312312
switch (optname) {
313313
case NETROM_T1:
314-
if (opt < 1 || opt > ULONG_MAX / HZ)
314+
if (opt < 1 || opt > UINT_MAX / HZ)
315315
return -EINVAL;
316316
nr->t1 = opt * HZ;
317317
return 0;
318318

319319
case NETROM_T2:
320-
if (opt < 1 || opt > ULONG_MAX / HZ)
320+
if (opt < 1 || opt > UINT_MAX / HZ)
321321
return -EINVAL;
322322
nr->t2 = opt * HZ;
323323
return 0;
@@ -329,13 +329,13 @@ static int nr_setsockopt(struct socket *sock, int level, int optname,
329329
return 0;
330330

331331
case NETROM_T4:
332-
if (opt < 1 || opt > ULONG_MAX / HZ)
332+
if (opt < 1 || opt > UINT_MAX / HZ)
333333
return -EINVAL;
334334
nr->t4 = opt * HZ;
335335
return 0;
336336

337337
case NETROM_IDLE:
338-
if (opt > ULONG_MAX / (60 * HZ))
338+
if (opt > UINT_MAX / (60 * HZ))
339339
return -EINVAL;
340340
nr->idle = opt * 60 * HZ;
341341
return 0;

0 commit comments

Comments
 (0)