inetdevice: fixed signed integer overflow
authorVincent BENAYOUN <vincent.benayoun@trust-in-soft.com>
Thu, 13 Nov 2014 12:47:26 +0000 (13:47 +0100)
committerDanny Wood <danwood76@gmail.com>
Tue, 29 Jan 2019 13:05:10 +0000 (13:05 +0000)
[ Upstream commit 84bc88688e3f6ef843aa8803dbcd90168bb89faf ]

There could be a signed overflow in the following code.

The expression, (32-logmask) is comprised between 0 and 31 included.
It may be equal to 31.
In such a case the left shift will produce a signed integer overflow.
According to the C99 Standard, this is an undefined behavior.
A simple fix is to replace the signed int 1 with the unsigned int 1U.

Signed-off-by: Vincent BENAYOUN <vincent.benayoun@trust-in-soft.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/linux/inetdevice.h

index a5da21a6669ffb46701032ac3c5588602f9dfe92..95527f46c6b1bf408b752507d433f318d7033b66 100644 (file)
@@ -263,7 +263,7 @@ static inline void in_dev_put(struct in_device *idev)
 static __inline__ __be32 inet_make_mask(int logmask)
 {
        if (logmask)
-               return htonl(~((1<<(32-logmask))-1));
+               return htonl(~((1U<<(32-logmask))-1));
        return 0;
 }