Skip to content

Commit d9ea8d4

Browse files
darkyellowcatopsiff
authored andcommitted
netfilter: reject zero shift in nft_bitwise
commit fe11e5c40817b84abaa5d83bfb6586d8412bfd07 upstream. 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: 567d746 ("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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> (cherry picked from commit 6f820139d16a4c9865a145d4a9cf9c92cc632c14) Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
1 parent 2f73305 commit d9ea8d4

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

net/netfilter/nft_bitwise.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ static int nft_bitwise_init_shift(struct nft_bitwise *priv,
196196
if (err < 0)
197197
return err;
198198

199-
if (priv->data.data[0] >= BITS_PER_TYPE(u32)) {
199+
if (!priv->data.data[0] ||
200+
priv->data.data[0] >= BITS_PER_TYPE(u32)) {
200201
nft_data_release(&priv->data, desc.type);
201202
return -EINVAL;
202203
}

0 commit comments

Comments
 (0)