net: get rid of an signed integer overflow in ip_idents_reserve()
authorEric Dumazet <edumazet@google.com>
Wed, 21 Sep 2016 01:06:17 +0000 (18:06 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 22 Sep 2016 06:41:17 +0000 (02:41 -0400)
commitadb03115f4590baa280ddc440a8eff08a6be0cb7
tree66b36cd6c485ea989a634ab49cc937dc5451ba3d
parentfba1296624bf95fc07057da1e26beee8a733180c
net: get rid of an signed integer overflow in ip_idents_reserve()

Jiri Pirko reported an UBSAN warning happening in ip_idents_reserve()

[] UBSAN: Undefined behaviour in ./arch/x86/include/asm/atomic.h:156:11
[] signed integer overflow:
[] -2117905507 + -695755206 cannot be represented in type 'int'

Since we do not have uatomic_add_return() yet, use atomic_cmpxchg()
so that the arithmetics can be done using unsigned int.

Fixes: 04ca6973f7c1 ("ip: make IP identifiers less predictable")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Reported-by: Jiri Pirko <jiri@resnulli.us>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/route.c