From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DA5C27466A; Fri, 7 Aug 2026 15:17:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786115873; cv=none; b=sCdzg3flhZPBZ6i4aHA+JHp/yiS75xFy00kWk8r0v57qB6k+S/TsUnzQf7R6H3i8TOJ7m1rAJnK8As7nFXJEz2MvhkMdF1mLrG+v4tX3fIsP5oxqJlLS9/SrAyoBLDGWQCYVt9J3zbLL7UgzE/4FSlRjGQEFI6sKXToe3rSCt4E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786115873; c=relaxed/simple; bh=9oS3LrebIAZwbDOwZmNq8i5Dm2k+W+Z4KVux8M2k640=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SMcB/x65B/EooimwGiYNht70l7FjyajUflLH7HuIqDz+lBNZ+LPUmfAnQ3Adw0ospRCj1JJGOxMu1kJ1mchd4VPgLPwynrmQVfxvf7hR0c1TioJoAfi8j/i06xeAQ6X8vOMGsXo0MW/B+8jwcAwIA7w/xRINHjixZMI+b1AtHQs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=f7wdJJjH; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="f7wdJJjH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D45521F000E9; Fri, 7 Aug 2026 15:17:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786115872; bh=GQaR6VB02kJnwzo28D49G5r0Vu48UJC7uvJ9NSjwFVw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=f7wdJJjHU5u05ek2EFjA0faYEzhelmrUb/eLcR8M3JPDH0Wg64LNu/P+wpXlT0ZRP cm7EO0lAxWd8MbyqyQTFghT6+g3hig/DNgmlvVZfb8Y8RQ1wDtGpZnAcx9mbEpol3u AfsCsuq3D7pM9DlKoyqVo1uh/KOxHzBknew1eVnM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, AutonomousCodeSecurity@microsoft.com, "Xiang Mei (Microsoft)" , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.6 033/261] netfilter: nft_payload: fix mask build for partial field offload Date: Fri, 7 Aug 2026 16:36:30 +0200 Message-ID: <20260807143416.092929972@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143415.358597922@linuxfoundation.org> References: <20260807143415.358597922@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Xiang Mei (Microsoft) [ Upstream commit 39e88f28fb32bf02bd4b525c24c842c9cff5663d ] nft_payload_offload_mask() builds the offload match mask for a payload expression that covers only part of a header field. For a partial IPv6 address match (field_len = 16, priv_len = 1) that shift is 1 << 120, which is undefined on the 32-bit int operand. It also trims only one word, so the remaining words stay 0xffffffff (and when priv_len is a multiple of 4 the trim is skipped entirely), leaving the mask covering more bytes than the rule matches. UBSAN: shift-out-of-bounds in net/netfilter/nft_payload.c:278:20 shift exponent 120 is too large for 32-bit type 'int' ... The match is byte-granular and struct nft_data is zero-initialised, so the correct mask is simply the first priv_len bytes set to 0xff. Set those bytes directly and drop the word/shift trimming; this removes the undefined shift and no longer over-masks the trailing bytes. Fixes: a5d45bc0dc50 ("netfilter: nftables_offload: build mask based from the matching bytes") Reported-by: AutonomousCodeSecurity@microsoft.com Signed-off-by: Xiang Mei (Microsoft) Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nft_payload.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c index 36c31ad2d64c1..15feb49e0b663 100644 --- a/net/netfilter/nft_payload.c +++ b/net/netfilter/nft_payload.c @@ -253,9 +253,7 @@ static int nft_payload_dump(struct sk_buff *skb, static bool nft_payload_offload_mask(struct nft_offload_reg *reg, u32 priv_len, u32 field_len) { - unsigned int remainder, delta, k; struct nft_data mask = {}; - __be32 remainder_mask; if (priv_len == field_len) { memset(®->mask, 0xff, priv_len); @@ -264,15 +262,7 @@ static bool nft_payload_offload_mask(struct nft_offload_reg *reg, return false; } - memset(&mask, 0xff, field_len); - remainder = priv_len % sizeof(u32); - if (remainder) { - k = priv_len / sizeof(u32); - delta = field_len - priv_len; - remainder_mask = htonl(~((1 << (delta * BITS_PER_BYTE)) - 1)); - mask.data[k] = (__force u32)remainder_mask; - } - + memset(&mask, 0xff, priv_len); memcpy(®->mask, &mask, field_len); return true; -- 2.53.0