Skip to content
Commit eadd1bef authored by Aleksandr Nogikh's avatar Aleksandr Nogikh Committed by Jakub Kicinski
Browse files

netem: fix zero division in tabledist



Currently it is possible to craft a special netlink RTM_NEWQDISC
command that can result in jitter being equal to 0x80000000. It is
enough to set the 32 bit jitter to 0x02000000 (it will later be
multiplied by 2^6) or just set the 64 bit jitter via
TCA_NETEM_JITTER64. This causes an overflow during the generation of
uniformly distributed numbers in tabledist(), which in turn leads to
division by zero (sigma != 0, but sigma * 2 is 0).

The related fragment of code needs 32-bit division - see commit
9b0ed891 ("netem: remove unnecessary 64 bit modulus"), so switching to
64 bit is not an option.

Fix the issue by keeping the value of jitter within the range that can
be adequately handled by tabledist() - [0;INT_MAX]. As negative std
deviation makes no sense, take the absolute value of the passed value
and cap it at INT_MAX. Inside tabledist(), switch to unsigned 32 bit
arithmetic in order to prevent overflows.

Fixes: 1da177e4 ("Linux-2.6.12-rc2")
Signed-off-by: default avatarAleksandr Nogikh <nogikh@google.com>
Reported-by: default avatar <syzbot+ec762a6342ad0d3c0d8f@syzkaller.appspotmail.com>
Acked-by: default avatarStephen Hemminger <stephen@networkplumber.org>
Link: https://lore.kernel.org/r/20201028170731.1383332-1-aleksandrnogikh@gmail.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8fc3672a
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment