🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #9521

[PATCH 05/14] xfrm: state: reject mark with bits outside its mask on add

#9521
From: Steffen Klassert
Date: Mon, 02 Nov 2026 10:04
87 lines
11798 bytes
From: Antony Antony <antony.antony@secunet.com>

A mark/mask like 0x101/0xff is silently truncated to 0x01/0xff on
insert, so the exact-match lookups added later in this series (DELSA,
GETSA, GETAE, NEWAE, EXPIRE, MIGRATE_STATE) could not find the SA.
Reject it instead.

The mark is no longer sanitized on state add.

Also reject an invalid XFRMA_MARK (the new mark) in
XFRM_MSG_MIGRATE_STATE.

Fixes: 0b91fda3a1f0 ("xfrm: Sanitize marks before insert")
Cc: <stable+noautosel@kernel.org> # needs exact-match SA lookups from this series
Signed-off-by: Antony Antony <antony.antony@secunet.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_state.c |  3 ---
 net/xfrm/xfrm_user.c  | 24 ++++++++++++++++++++++++
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
index e45aa1ed5b96..602404ffc4d4 100644
--- a/net/xfrm/xfrm_state.c
+++ b/net/xfrm/xfrm_state.c
@@ -1732,9 +1732,6 @@ static void __xfrm_state_insert(struct xfrm_state *x)
 
 	list_add(&x->km.all, &net->xfrm.state_all);
 
-	/* Sanitize mark before store */
-	x->mark.v &= x->mark.m;
-
 	h = xfrm_dst_hash(net, &x->id.daddr, &x->props.saddr,
 			  x->props.reqid, x->props.family);
 	XFRM_STATE_INSERT(bydst, &x->bydst,
diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index a2587c7e796b..0723d791b8b7 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -314,6 +314,22 @@ static int verify_selector_prefixlen(u16 family,
 	}
 }
 
+static int verify_mark(struct nlattr **attrs, struct netlink_ext_ack *extack)
+{
+	const struct xfrm_mark *m;
+
+	if (!attrs[XFRMA_MARK])
+		return 0;
+
+	m = nla_data(attrs[XFRMA_MARK]);
+	if ((m->v & m->m) != m->v) {
+		NL_SET_ERR_MSG(extack, "Invalid mark value/mask combination");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static int verify_newsa_info(struct xfrm_usersa_info *p,
 			     struct nlattr **attrs,
 			     struct netlink_ext_ack *extack)
@@ -333,6 +349,10 @@ static int verify_newsa_info(struct xfrm_usersa_info *p,
 	if (err)
 		goto out;
 
+	err = verify_mark(attrs, extack);
+	if (err)
+		goto out;
+
 	err = -EINVAL;
 	switch (p->id.proto) {
 	case IPPROTO_AH:
@@ -3370,6 +3390,10 @@ static int xfrm_do_migrate_state(struct sk_buff *skb, struct nlmsghdr *nlh,
 			return err;
 	}
 
+	err = verify_mark(attrs, extack);
+	if (err)
+		return err;
+
 	copy_from_user_migrate_state(&m, um);
 
 	x = xfrm_state_lookup(net, m.old_mark.v & m.old_mark.m,
-- 
2.53.0
Technical Details
Message-ID: <20261102100451.2505200-6-steffen.klassert@secunet.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354524-linux-kernel-netdev=dewy.ru
References: <20261102100451.2505200-1-steffen.klassert@secunet.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-354524-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: [PATCH 05/14] xfrm: state: reject mark with bits outside its mask on add
Date: Mon, 2 Nov 2026 10:04:03 +0000
Organization: Usenet Network
Message-ID: <20261102100451.2505200-6-steffen.klassert@secunet.com>
References: <20261102100451.2505200-1-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="2878287"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:xG6BeLKF7nCd2KQbWks031/94wo= sha256:kA+vovsTujPJygwsuwZ5KZnGm0Ej3V6tBAEZZ16Z1dg=
	sha1:2EUZBlOXw/X0h7V4vZHJyanAg+g= sha256:XAxWOXaq1mI3JSzYzUl9TSIfvJUPE7loWh4gFDel+Tk=
List-ID: <netdev.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 9A2BC11245B; Mon,  2 Nov 2026 11:09:14 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.049
X-Spam-Status: No, score=-3.049 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1,
	DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.25,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=secunet.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id 7LlrTY7Jgq-Z;
	Mon,  2 Nov 2026 11:09:08 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-354524-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=secunet.com
X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114])
	by mail.dewy.ru (Postfix) with ESMTPS id D4C46112453; Mon,  2 Nov 2026 11:08:54 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by tor.lore.kernel.org (Postfix) with ESMTP id 564D728A58; Mon,  2 Nov 2026 08:05:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1793606697;
	b=yGmOmC5mo5835WkPNVbgc7qbbg7OdiTAe77rWkMEmBi0sS8VHP1ILAoxwVMlx8sNoPgS
	 zoRXNLBrym72Kw/C0/2T0kgb6ZVhY/4IADrDZIVGX2N2CHN9nGLjr/Fj+IA9Okey/av2E
	 G/XoBUI3bHQ/Xla15i/giEjzNymMk/RQRGdPZCX4wVNLHtOmyn3HgL7BDOuEM6xdscC4A
	 0NMrhrAS+iDPCkDgYkk5S/hKY4POPGdA7OTvn7nYcCsT3pEj8h0OojIh3WRVci3V7W7r7
	 HiVsDvTs1ANs5+bTaLMaUyRj6ucDmIVFqhbuQgv8T+0nBlhS/ExIM/KvvWIaWo4bM9g==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793606697;
	h=X-Original-To:Received:DMARC-Filter:Received:X-Virus-Scanned:
	 Received:Received:DKIM-Filter:DKIM-Signature:Received:Received:From:
	 To:CC:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:
	 X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe:
	 List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy;
	bh=pDweGw5HyLxVmwonenPClPBzGH11CJ0lFf5qOHMRBAI=;
	b=cbYp8e/fTeNlKEAnLMCypI8xAVbAkByItu29kgV6kGWFhLpnYhbXSxtXIQU30zGkxpxp
	 OgA1sqlxsrmqApP2kUsKzgTZEIhxsimiLYET1uO9Ejj4LcX9eYuu+p1/o7potxXbojZdT
	 yoxOzQMhlHjN/m1IB/JT6TgraPYI+AWLV1Qt7kocrh12oy9EeVvfcmSCoCWf9WXqLBOpH
	 TD5ctd5HkmvFAkKK24UFmj72K6B5DOCjLIOqvnpnB7jTLizjCQ+g10LusfyniDQ4tIq6u
	 RYox3nwEkgbtKRDKZCdaqw505gpjKoEsXSA80lTUmGieA84NkrRRvcDhTu5e2q05hKw==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b="p/kNYNh5";
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 5A21660A2615;
	Mon,  2 Nov 2026 08:04:57 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=p/kNYNh5
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793606696;
	b=GY6RG5v2h6jaKlyX3tZ5cUMws+CYcDhCkbLBMlXwDjrFsphOi3NF0XM85Gvo0lRzsdz3
	 j9OLp/zTuCtrbCWUn5J3aBQKLF13gipDoKMOeyXoLvu+lE5IyhUc9uMWQ8cYWlZWE2HXn
	 9L1FV/JWMJaK2HUuM5bmq6o+GwFxQ5WXewrU8kfAMKg7ANBkRpl//V/vZsTXAJ4y58F7M
	 BjcVbrs7zwZbronUOouHegVjTxkwY5K6QKKNrmn6WCSHpBkRkwms36ty8xzZ3YpM/30GT
	 Sz9h2nlrAgF8DUmk1xJFqEBwzYZwP+wjx5BJzBz3pyHEwBBAv7Y/whofgzu3t7b9Bgw==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793606696;
	h=DMARC-Filter:Received:X-Virus-Scanned:Received:Received:DKIM-Filter:
	 DKIM-Signature:Received:Received:From:To:CC:Subject:Date:Message-ID:
	 X-Mailer:In-Reply-To:References:MIME-Version:
	 Content-Transfer-Encoding:Content-Type:X-ClientProxiedBy;
	bh=pDweGw5HyLxVmwonenPClPBzGH11CJ0lFf5qOHMRBAI=;
	b=dVeAMyROZbg+7+vvb8c1K9SSt+1WFggj/7qVYRJes0zww9hv2oyjxPcvWuM5Q7AiO6AZ
	 +0yjzvoNtO2To8B71Eg4LFS/nXUNZOCR8I5deMio276csc88hWDp1lgyZM6OUQ53BaVWR
	 8RzD2Q/zxigCm/01BHs7CT5wkYUvZEUkSSEEA1ts5s01LgpUSaUWqjPkSMV0IOK7Le6Wj
	 E/5NP193ru9TRNkPqUWY9LEMODMjOUy0W7gf5Xayw/ONgkpx2KEh0EP12u2ELJIvYikNk
	 y9CrxWkTzsAzer/KsOu1yOfkiDHo4k1CbbcEYP35bHK7pos0ZxVhK7p4f/wioUCEMsg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=secunet.com;
	spf=pass smtp.mailfrom=secunet.com;
	dkim=pass header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b="p/kNYNh5";
	arc=none smtp.remote-ip=62.96.220.36
X-Received: from mx1.secunet.com (mx1.secunet.com [62.96.220.36])
	(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAE4A60A2600
	for <netdev@vger.kernel.org>; Mon,  2 Nov 2026 08:04:55 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DAE4A60A2600
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com
X-Received: from localhost (localhost [127.0.0.1])
	by mx1.secunet.com (Postfix) with ESMTP id 9612520520;
	Mon,  2 Nov 2026 09:04:54 +0100 (CET)
X-Virus-Scanned: by secunet
X-Received: from mx1.secunet.com ([127.0.0.1])
 by localhost (mx1.secunet.com [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id kXs2-Jq9b-In; Mon,  2 Nov 2026 09:04:54 +0100 (CET)
X-Received: from EXCH-01.secunet.de (rl1.secunet.de [10.32.0.231])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by mx1.secunet.com (Postfix) with ESMTPS id 043F1207B0;
	Mon,  2 Nov 2026 09:04:54 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 043F1207B0
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1793606694;
	bh=pDweGw5HyLxVmwonenPClPBzGH11CJ0lFf5qOHMRBAI=;
	h=From:To:CC:Subject:Date:In-Reply-To:References:From;
	b=p/kNYNh5mPoNclLqMVTdIlR2A6468NE7idS8cBB7BUC+3yFevOEtVN3CpH234PG9I
	 7rrNKmnBFUgxAxruFy1C6GCmkggvaBr8yifMnOVYo/8EUe3AvwV898EFz/w/08z6MV
	 FeTc4eJJ0HRpxjMtl9q/U/SHNNY5pVu5DKmuTLrNMhfRZohVzd+q++rMu9tjzjq80k
	 CgGa0AuxNKfuRb14F1QywKPrKZ0q7UaY0xxxPtQ1U/APE92OEJjUrBIG/1IDbeDNYJ
	 1I2/CGWuMdb8koVLl3dyVyIUyEu2g4le8wnU0duXQ6dK3XaODAOORZ3bnA7kE4rsRK
	 EnTgfvfaVUWWg==
X-Received: from gauss4 (10.182.7.102) by EXCH-01.secunet.de (10.32.0.171) with
 Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.49; Mon, 2 Nov
 2026 09:04:53 +0100
X-Received: (nullmailer pid 2505903 invoked by uid 1000);
	Mon, 02 Nov 2026 10:04:58 -0000
X-CC: Herbert Xu <herbert@gondor.apana.org.au>, Steffen Klassert
	<steffen.klassert@secunet.com>, <netdev@vger.kernel.org>
X-Mailer: git-send-email 2.53.0
X-In-Reply-To: <20261102100451.2505200-1-steffen.klassert@secunet.com>
X-Mailing-List: netdev@vger.kernel.org
X-List-Post: <mailto:netdev@vger.kernel.org>
X-List-Help: <mailto:netdev+help@vger.kernel.org>
X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:netdev+owner@vger.kernel.org>
X-Precedence: list
X-ClientProxiedBy: EXCH-02.secunet.de (10.32.0.172) To EXCH-01.secunet.de
 (10.32.0.171)