]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
netfilter: reject zero shift in nft_bitwise
authorKai Ma <k4729.23098@gmail.com>
Wed, 22 Apr 2026 14:54:18 +0000 (22:54 +0800)
committerPablo Neira Ayuso <pablo@netfilter.org>
Fri, 24 Apr 2026 18:09:57 +0000 (20:09 +0200)
Reject zero shift operands for nft_bitwise left and right shift
expressions during initialization.

The carry propagation logic computes the carry from the adjacent 32-bit
word using BITS_PER_TYPE(u32) - shift. A zero shift operand turns this
into a 32-bit shift, which is undefined behaviour.

Reject zero shift operands in the control plane, alongside the existing
check for values greater than or equal to 32, so malformed rules never
reach the packet path.

Fixes: 567d746b55bc ("netfilter: bitwise: add support for shifts.")
Cc: stable@kernel.org
Reported-by: Yuan Tan <yuantan098@gmail.com>
Reported-by: Yifan Wu <yifanwucs@gmail.com>
Reported-by: Juefei Pu <tomapufckgml@gmail.com>
Reported-by: Xin Liu <bird@lzu.edu.cn>
Signed-off-by: Kai Ma <k4729.23098@gmail.com>
Signed-off-by: Ren Wei <n05ec@lzu.edu.cn>
Reviewed-by: Fernando Fernandez Mancera <fmancera@suse.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
net/netfilter/nft_bitwise.c

index 13808e9cd999335a374b864d134e24a2373809e1..94dccdcfa06bba6e439dd5e3240d5300380d247e 100644 (file)
@@ -196,7 +196,8 @@ static int nft_bitwise_init_shift(struct nft_bitwise *priv,
        if (err < 0)
                return err;
 
-       if (priv->data.data[0] >= BITS_PER_TYPE(u32)) {
+       if (!priv->data.data[0] ||
+           priv->data.data[0] >= BITS_PER_TYPE(u32)) {
                nft_data_release(&priv->data, desc.type);
                return -EINVAL;
        }