]> git.ipfire.org Git - people/arne_f/kernel.git/commitdiff
xfrm6_tunnel: Fix spi check in __xfrm6_tunnel_alloc_spi
authorYueHaibing <yuehaibing@huawei.com>
Wed, 19 Dec 2018 06:45:09 +0000 (14:45 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 12 Feb 2019 18:44:56 +0000 (19:44 +0100)
[ Upstream commit fa89a4593b927b3f59c3b69379f31d3b22272e4e ]

gcc warn this:

net/ipv6/xfrm6_tunnel.c:143 __xfrm6_tunnel_alloc_spi() warn:
 always true condition '(spi <= 4294967295) => (0-u32max <= u32max)'

'spi' is u32, which always not greater than XFRM6_TUNNEL_SPI_MAX
because of wrap around. So the second forloop will never reach.

Signed-off-by: YueHaibing <yuehaibing@huawei.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
net/ipv6/xfrm6_tunnel.c

index e1c0bbe7996cf8ca00374db26488bd85e02a36ad..3a2701d42f471c3317a43c5bf7cf8f71be3daef6 100644 (file)
@@ -144,6 +144,9 @@ static u32 __xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr)
                index = __xfrm6_tunnel_spi_check(net, spi);
                if (index >= 0)
                        goto alloc_spi;
+
+               if (spi == XFRM6_TUNNEL_SPI_MAX)
+                       break;
        }
        for (spi = XFRM6_TUNNEL_SPI_MIN; spi < xfrm6_tn->spi; spi++) {
                index = __xfrm6_tunnel_spi_check(net, spi);