Skip to content

Commit d640627

Browse files
Nikita Zhandarovichkuba-moo
Nikita Zhandarovich
authored andcommitted
net/rose: prevent integer overflows in rose_setsockopt()
In case of possible unpredictably large arguments passed to rose_setsockopt() and multiplied by extra values on top of that, integer overflows may occur. Do the safest minimum and fix these issues by checking the contents of 'opt' and returning -EINVAL if they are too large. Also, switch to unsigned int and remove useless check for negative 'opt' in ROSE_IDLE case. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Nikita Zhandarovich <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 25c1a9c commit d640627

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

net/rose/af_rose.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ static int rose_setsockopt(struct socket *sock, int level, int optname,
397397
{
398398
struct sock *sk = sock->sk;
399399
struct rose_sock *rose = rose_sk(sk);
400-
int opt;
400+
unsigned int opt;
401401

402402
if (level != SOL_ROSE)
403403
return -ENOPROTOOPT;
404404

405-
if (optlen < sizeof(int))
405+
if (optlen < sizeof(unsigned int))
406406
return -EINVAL;
407407

408-
if (copy_from_sockptr(&opt, optval, sizeof(int)))
408+
if (copy_from_sockptr(&opt, optval, sizeof(unsigned int)))
409409
return -EFAULT;
410410

411411
switch (optname) {
@@ -414,31 +414,31 @@ static int rose_setsockopt(struct socket *sock, int level, int optname,
414414
return 0;
415415

416416
case ROSE_T1:
417-
if (opt < 1)
417+
if (opt < 1 || opt > UINT_MAX / HZ)
418418
return -EINVAL;
419419
rose->t1 = opt * HZ;
420420
return 0;
421421

422422
case ROSE_T2:
423-
if (opt < 1)
423+
if (opt < 1 || opt > UINT_MAX / HZ)
424424
return -EINVAL;
425425
rose->t2 = opt * HZ;
426426
return 0;
427427

428428
case ROSE_T3:
429-
if (opt < 1)
429+
if (opt < 1 || opt > UINT_MAX / HZ)
430430
return -EINVAL;
431431
rose->t3 = opt * HZ;
432432
return 0;
433433

434434
case ROSE_HOLDBACK:
435-
if (opt < 1)
435+
if (opt < 1 || opt > UINT_MAX / HZ)
436436
return -EINVAL;
437437
rose->hb = opt * HZ;
438438
return 0;
439439

440440
case ROSE_IDLE:
441-
if (opt < 0)
441+
if (opt > UINT_MAX / (60 * HZ))
442442
return -EINVAL;
443443
rose->idle = opt * 60 * HZ;
444444
return 0;

0 commit comments

Comments
 (0)