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 388863EDAC6; Wed, 20 May 2026 18:24:11 +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=1779301453; cv=none; b=Tul03PSyJ5A+uRNT7fMeJhSd6mvCPBn8KFf/ApE1z2+6Flw4YK5FRH+3FEh/4vWw0Vkw5QOjvuaSPvc3vcV4G3ERjufZFCzA/XC+2bU01e7JVIRkugmqgI+gf4t0uvmH1xR2XR1vT+tjNu6HoOgcAzvkXgJ/6lstn5iuSwisFRc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779301453; c=relaxed/simple; bh=MY9itdchDc9b3F1VsJTgVwWR1mO3TT7knrEh+DPZEKo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ea26GlHbeieQ5BkrtSqHGWt2c+RTKyRkmTJPXpWERnW8/5S89F2dOM5lDJX827B6Oc+z6pzPVfuMYrPMUJwglzGzPJyvaP6yfU2x1QSYKGO6dZpPvWPKGQm5x4H6jHMfECk1ZKrkrWQhbZT86faW5YquZJ8RwSurQdPVu1LerGw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dDWuAie1; 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="dDWuAie1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AE751F000E9; Wed, 20 May 2026 18:24:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1779301451; bh=KEe64E6TVduX7edfXi36HiMgfU7azf3ps/2aeMJwkQw=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dDWuAie1pzCYjD9NtsEiaiDav8tBav2YvWJPXVlagw1mF35Oh8Ry+WrxbSCf2DJFn bDqA89cklocQGUL1u7k2wEFfVjP3sAOhYt8cmGHRHfIkuqYGDJVBBCo7pRZJD2ZG19 U7rvnIwMupNJhHfWzriIK2/EUI7+FovJxdWMmwVI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yuan Tan , Yifan Wu , Juefei Pu , Xin Liu , Jiexun Wang , Ren Wei , Florian Westphal , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 6.12 523/666] netfilter: xt_policy: fix strict mode inbound policy matching Date: Wed, 20 May 2026 18:22:14 +0200 Message-ID: <20260520162122.599400309@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260520162111.222830634@linuxfoundation.org> References: <20260520162111.222830634@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.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiexun Wang [ Upstream commit 4b2b4d7d4e203c92db8966b163edfacb1f0e1e29 ] match_policy_in() walks sec_path entries from the last transform to the first one, but strict policy matching needs to consume info->pol[] in the same forward order as the rule layout. Derive the strict-match policy position from the number of transforms already consumed so that multi-element inbound rules are matched consistently. Fixes: c4b885139203 ("[NETFILTER]: x_tables: replace IPv4/IPv6 policy match by address family independant version") Reported-by: Yuan Tan Reported-by: Yifan Wu Reported-by: Juefei Pu Reported-by: Xin Liu Signed-off-by: Jiexun Wang Signed-off-by: Ren Wei Acked-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/xt_policy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/netfilter/xt_policy.c b/net/netfilter/xt_policy.c index cb6e8279010a4..b5fa65558318f 100644 --- a/net/netfilter/xt_policy.c +++ b/net/netfilter/xt_policy.c @@ -63,7 +63,7 @@ match_policy_in(const struct sk_buff *skb, const struct xt_policy_info *info, return 0; for (i = sp->len - 1; i >= 0; i--) { - pos = strict ? i - sp->len + 1 : 0; + pos = strict ? sp->len - i - 1 : 0; if (pos >= info->len) return 0; e = &info->pol[pos]; -- 2.53.0