]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
netfilter: nft_payload: sanitize offset and length before calling skb_checksum()
authorPablo Neira Ayuso <pablo@netfilter.org>
Wed, 30 Oct 2024 22:13:48 +0000 (23:13 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Thu, 31 Oct 2024 09:54:49 +0000 (10:54 +0100)
If access to offset + length is larger than the skbuff length, then
skb_checksum() triggers BUG_ON().

skb_checksum() internally subtracts the length parameter while iterating
over skbuff, BUG_ON(len) at the end of it checks that the expected
length to be included in the checksum calculation is fully consumed.

Fixes: 7ec3f7b47b8d ("netfilter: nft_payload: add packet mangling support")
Reported-by: Slavin Liu <slavin-ayu@qq.com>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nft_payload.c

index 330609a76fb202f7f8c54d2c695f16df3016f118..7dfc5343dae46f3d117092667272175de9346819 100644 (file)
@@ -904,6 +904,9 @@ static void nft_payload_set_eval(const struct nft_expr *expr,
            ((priv->base != NFT_PAYLOAD_TRANSPORT_HEADER &&
              priv->base != NFT_PAYLOAD_INNER_HEADER) ||
             skb->ip_summed != CHECKSUM_PARTIAL)) {
+               if (offset + priv->len > skb->len)
+                       goto err;
+
                fsum = skb_checksum(skb, offset, priv->len, 0);
                tsum = csum_partial(src, priv->len, 0);