Skip to content

Commit

Permalink
net/rose: prevent integer overflows in rose_setsockopt()
Browse files Browse the repository at this point in the history
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 <n.zhandarovich@fintech.ru>
Link: https://patch.msgid.link/20250115164220.19954-1-n.zhandarovich@fintech.ru
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Nikita Zhandarovich authored and Jakub Kicinski committed Jan 21, 2025
1 parent 25c1a9c commit d640627
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions net/rose/af_rose.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,15 +397,15 @@ static int rose_setsockopt(struct socket *sock, int level, int optname,
{
struct sock *sk = sock->sk;
struct rose_sock *rose = rose_sk(sk);
int opt;
unsigned int opt;

if (level != SOL_ROSE)
return -ENOPROTOOPT;

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

if (copy_from_sockptr(&opt, optval, sizeof(int)))
if (copy_from_sockptr(&opt, optval, sizeof(unsigned int)))
return -EFAULT;

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

case ROSE_T1:
if (opt < 1)
if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL;
rose->t1 = opt * HZ;
return 0;

case ROSE_T2:
if (opt < 1)
if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL;
rose->t2 = opt * HZ;
return 0;

case ROSE_T3:
if (opt < 1)
if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL;
rose->t3 = opt * HZ;
return 0;

case ROSE_HOLDBACK:
if (opt < 1)
if (opt < 1 || opt > UINT_MAX / HZ)
return -EINVAL;
rose->hb = opt * HZ;
return 0;

case ROSE_IDLE:
if (opt < 0)
if (opt > UINT_MAX / (60 * HZ))
return -EINVAL;
rose->idle = opt * 60 * HZ;
return 0;
Expand Down

0 comments on commit d640627

Please sign in to comment.