๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #10118

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

#10118
From: netdev-bot+sashiko
Date: Tue, 03 Nov 2026 08:05
144 lines
12569 bytes
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 ยท High: 0 ยท Medium: 1 ยท Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] This is a regression at this commit only, and a later patch in
  the series fixes it.
- [Low] At this commit, XFRM_MSG_ALLOCSPI still accepts XFRMA_MARK
  without calling verify_mark().

--

xfrm: state: reject mark with bits outside its mask on add

This commit adds verify_mark(), which rejects an XFRMA_MARK whose value
has bits outside its mask. It is called from verify_newsa_info() and
xfrm_do_migrate_state(). The commit also removes the mark sanitization
from __xfrm_state_insert(), so such marks are rejected instead of being
silently truncated.

> diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
> index e45aa1ed5b965..602404ffc4d4b 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;
> -

[Severity: Low]
At this commit, can a mark with bits outside its mask still get into the
SAD through XFRM_MSG_ALLOCSPI?

xfrm_alloc_userspi() does not call verify_mark(). xfrm_mark_get() masks
only its return value, and m keeps the raw attribute:

net/xfrm/xfrm_user.c:xfrm_alloc_userspi() {
    ...
	mark = xfrm_mark_get(attrs, &m);
    ...
}

xfrm_find_acq() -> __find_acq_core() then stores the mark unchanged and
adds the larval state to the hash tables directly:

net/xfrm/xfrm_state.c:__find_acq_core() {
    ...
		x->mark.v = m->v;
		x->mark.m = m->m;
    ...
}

So ALLOCSPI with XFRMA_MARK {0x101, 0xff} creates a larval SA that no
masked lookup can match. That part is older than this patch, because
__find_acq_core() never went through __xfrm_state_insert().

The legacy XFRM_MSG_MIGRATE path is newly affected.
xfrm_migrate_copy_old() copies the existing SA's mark into the clone:

net/xfrm/xfrm_policy.c:xfrm_migrate_copy_old() {
    ...
	mp->new_mark               = &x->mark;
}

Before this patch, __xfrm_state_insert() trimmed the clone's mark. With
the sanitization removed, the clone keeps 0x101/0xff.

The next commit in the series, "xfrm: state: reject mark with bits
outside its mask on ALLOCSPI", adds a verify_mark() call to
xfrm_alloc_userspi() before xfrm_mark_get(), which closes this. Could
that change be folded into this patch, or moved ahead of it?

[ ... ]

> diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
> index a2587c7e796b4..0723d791b8b70 100644
> --- a/net/xfrm/xfrm_user.c
> +++ b/net/xfrm/xfrm_user.c

[ ... ]

> @@ -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,

[Severity: Medium]
verify_mark() checks only attrs[XFRMA_MARK] and returns 0 when that
attribute is absent. Is um->old_mark left unchecked here?

copy_from_user_migrate_state() copies it unchanged:

	ma->old_mark = um->old_mark;

The old SA is looked up with the masked value. So old_mark
{v=0x101, m=0xff} still finds an existing 0x01/0xff SA.

If XFRMA_MARK is not supplied, xfrm_state_clone_and_setup() gives the
clone the raw old_mark:

net/xfrm/xfrm_state.c:xfrm_state_clone_and_setup() {
    ...
	x->mark = m->new_mark ? *m->new_mark : m->old_mark;
    ...
}

Before this patch, __xfrm_state_insert() trimmed that to 0x01/0xff. With
the sanitization removed, the path
xfrm_state_migrate_install() -> xfrm_state_insert() stores the clone as
0x101/0xff.

The masked lookups test (mark & x->mark.m) == x->mark.v, which can never
be true for that mark. Does that leave the original SA deleted and the
migrated SA unreachable?

The later commit "xfrm: state: exact mark/mask match for SPI-keyed
control-plane SA lookups" changes this to
xfrm_state_lookup_exact(net, &m.old_mark, ...). After that change, an
old_mark with bits outside its mask matches no stored SA, and the
request fails with -ESRCH.

That limits the problem to the commits between this one and that one.
Even so, could um->old_mark be checked here too, or could the exact
lookup patch be placed earlier in the series?

-- 
Sashiko AI review ยท https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261102100451.2505200-2-steffen.klassert%40secunet.com
Technical Details
Message-ID: <179369310218.488856.16451031083235649768@kernel.org>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-355274-linux-kernel-netdev=dewy.ru
References: <20261102100451.2505200-6-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-355274-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH 05/14] xfrm: state: reject mark with bits outside its mask on add
Date: Tue, 03 Nov 2026 08:05:02 +0000
Organization: Usenet Network
Message-ID: <179369310218.488856.16451031083235649768@kernel.org>
References: <20261102100451.2505200-6-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="3119865"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:/IA+Bo8PTmAGSlod1PZ/d1Zhj8c= sha256:pXdghCJfM+9Ojn9FLjeFrx7PPeKLlwbRVHjP/mcj87o=
	sha1:QxTbze3tsdZ/D7LlooOKXP+xBW4= sha256:sV/fIo5DsHbxjkRLeLA51z8B4D9/3ByKUwy7y85mOSQ=
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 1F0D411276F; Tue,  3 Nov 2026 11:10:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.401
X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31
	tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=kernel.org
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 K0MnZjVtDuUQ;
	Tue,  3 Nov 2026 11:10:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-355274-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org
X-Received: from sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id B43411126DB; Tue,  3 Nov 2026 11:10:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sin.lore.kernel.org (Postfix) with ESMTP id B5E292A9EE; Tue,  3 Nov 2026 08:05:15 +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=1793693109;
	b=ER3zH0eknraoy+w1s24reYN6BmNbXXeKzZgd/DEfooL2/Ax+vSBFNab+uuMKGD3/ISL2
	 vrePGc3I4QQyZNdkPiLzoM8fsqChi/vFSjFNDy6MMl/GIZkbqKO2w8EBHOLjmYWo/XQZs
	 QUwoI81Ln1hC30rcXqbbSwZPbb1MEgE9cVyEH8HFnFU3bLu1XY7/i6HT5+O7tno2HafTN
	 bsk+yZRffZUXoj6hzznkULCjikUK24Fo45cLhdwwqPJnuPDBSUZuwb3neODCwc7w9r4+X
	 LWsC8sJJtnMOd4PqfBg/ddqI6L1c/5uPTIdUvsN2QrFltii+BchT2jtflVz06QLfneg==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793693109;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=C4FRiEF3XHC29fyAyxPUAdACL1J9ejaADAa4/bfxtTg=;
	b=IVphAfq04UABSjva2gd7o2AQjXA9Xwf+dlQya6mbkz4EnOPhS7Ic7uLDkWRUOAx7f1Qk
	 S7d++KlgR2Fqh61ilv73DuUXhcl0yofowZZkBg9lko+uMmxXUlvB1pC3AaEu70ecxaaM0
	 Cr3JrgleoknwyU628yMh6vYrHT+I7uZtXsnIhaixDMjDodpiipILNHG5ADJ1QQgJghsig
	 nbG93/Wt6wXeKWqlYsgabQFSKGMkxMLYWqJG1zh5Ckvh7BS4jFRylRF/BKyQApGgoXvm9
	 hJV9/HkhDykapdKRFQQ7bsNXwVFUXl/ivFpsr/pIOzcEwVPvRR2LcV5uYQ2CDtwpeOg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dQR9Cek1;
	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 3A3E2606D80B;
	Tue,  3 Nov 2026 08:05:09 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dQR9Cek1
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1793693103;
	b=FilmQsgwTsMCLl1dk64Z3ttxydFCusTJzBTgDh5Qj/x01Pybzx85uG5zuyO46/4tHZfJ
	 m5pX13vHue7D5LgqyFYhL7M8pgSOSiB9zIjVxF7FctqTwSAsTA2VS0OOT5vXzxyjUinxh
	 Q/dWymll6UytTjNulI2RLBwI/R3RW3m0bMoumUHpv1N5JIJQd+nqT4VNtiwCDsoc+vd70
	 GIw/Rl/gSFFkJ58mb2yaLcYmPhMnGaShP8MeuhX5TbsBlNjbPbyLC2GIGBpFadY1OyJbT
	 s+IrTFdHY3VyvOUWhyyRHbhBm6oeho91/Da9qnKz0ZEg9n1LfWP3gvjSRbRLLWX4y+A==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1793693103;
	h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID:
	 In-Reply-To:References:X-sashiko-severity:Content-Type:
	 Content-Transfer-Encoding:MIME-Version;
	bh=C4FRiEF3XHC29fyAyxPUAdACL1J9ejaADAa4/bfxtTg=;
	b=RZX9Em7ZSYrQzPXrGzegj18UdszzF00KXaK8uSvPSd+88el5LF3rtmsduE9qBKkfqqWM
	 wFyNVq9PjkCFi0RRH++L8gjOE2wKXO/kVsOVvk/452fMcYupKxw3fhjBdB5Mqj7SIBAds
	 YY+xmy/DwCZ/PwEqa7QJ9s+K5UqptjJhSw+jicLlLynLlt3IUG9IAUPA5dfyXTGW0lfXN
	 gvaESkk+oQpKe8EQdIZaYDoLJhtGwWAEa5PveAs1xeS5e72TJhloYzAth6zpbakn9TyhW
	 FNPeQxhXZICqpUZwogMReDh2ILfSQFlF2eA5hqjWvOls53CfFK0ZXkdWMmr+8jIQUWg==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=dQR9Cek1;
	arc=none smtp.remote-ip=100.103.45.18
X-Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1))
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1788B606A335
	for <netdev@vger.kernel.org>; Tue,  3 Nov 2026 08:05:03 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9ECDC1F000C1;
	Tue,  3 Nov 2026 08:05:02 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1793693102;
	bh=C4FRiEF3XHC29fyAyxPUAdACL1J9ejaADAa4/bfxtTg=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=dQR9Cek1St3uwl/UF/jJlox2RMlAJ7/lbrI+WxnMK1TLjNwSAYww2TgUY0q5BDIbV
	 JSlOtGJ7Xv2ZpxvFzAB2+QXDgbQ2Md1lGM6OgAy+GTsoPE6hlzow3dQDc/a7pxu7xz
	 2A2UzOxR7NfFrn5JRdmT5pgv7IgNbpQ4+oXGss2z3Yv91de0bD1cAAYj3ReKBepC/r
	 sbi5E1IL+HgJrFrAKi5+l/c5AZkQTVsdIc+RWnlshyLAVrXofePH0rBX6cQu3vMdb3
	 ADRK473bS0iB7cLwtYoHo2qDzzakgGxmh/VmKaHe8qQAvgFnKG7HlSkuCqvKfJQ7ST
	 H+/odQ6UDK6PQ==
X-Cc: davem@davemloft.net, kuba@kernel.org, herbert@gondor.apana.org.au,
 netdev@vger.kernel.org
X-In-Reply-To: <20261102100451.2505200-6-steffen.klassert@secunet.com>
X-sashiko-severity: Medium
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