🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #25252

[PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len()

#25252
From: Steffen Klassert
Date: Tue, 01 Dec 2026 12:41
56 lines
11581 bytes
From: Yasuaki Torimaru <yasuakitorimaru@gmail.com>

xfrm_notify_sa() sizes its netlink message with xfrm_sa_len(), while
copy_to_user_state_extra() appends XFRMA_MARK whenever the state carries
a mark.  xfrm_sa_len() does not count that attribute.  Only the
XFRM_MSG_DELSA path adds it to the length separately, so for a marked
state the XFRM_MSG_NEWSA and XFRM_MSG_UPDSA messages are sized short by
nla_total_size(sizeof(struct xfrm_mark)), 12 bytes.  The other length
calculations in this file already account for the mark; xfrm_sa_len() is
the only one that does not.

Instrumenting xfrm_notify_sa() on an x86-64 KASAN build under qemu to
print the accounted length while adding a marked state confirms the gap:
accounting the mark raises the computed length by exactly 12 bytes
(348 -> 360), matching nla_total_size(sizeof(struct xfrm_mark)).

Whether the shortfall is reached depends on the skb allocation, which is
rounded up: xfrm_notify_sa() fails with -EMSGSIZE only when that slack is
exhausted.  km_state_notify() discards the return value, so such a
failure would be silent.  This was not reproduced.

Count the mark in xfrm_sa_len() for every event and drop the now
redundant addition in the DELSA path.  The message content is unchanged;
only the computed length changes.

Fixes: 6f26b61e177e ("xfrm: Allow user space config of SAD mark")
Signed-off-by: Yasuaki Torimaru <yasuakitorimaru@gmail.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
---
 net/xfrm/xfrm_user.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
index f802899d3d13..217f65faa2bd 100644
--- a/net/xfrm/xfrm_user.c
+++ b/net/xfrm/xfrm_user.c
@@ -4083,6 +4083,8 @@ static inline unsigned int xfrm_sa_len(struct xfrm_state *x)
 		l += nla_total_size(sizeof(*x->encap));
 	if (x->tfcpad)
 		l += nla_total_size(sizeof(x->tfcpad));
+	if (x->mark.v | x->mark.m)
+		l += nla_total_size(sizeof(struct xfrm_mark));
 	if (x->replay_esn)
 		l += nla_total_size(xfrm_replay_state_esn_len(x->replay_esn));
 	else
@@ -4138,7 +4140,6 @@ static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c)
 	if (c->event == XFRM_MSG_DELSA) {
 		len += nla_total_size(headlen);
 		headlen = sizeof(*id);
-		len += nla_total_size(sizeof(struct xfrm_mark));
 	}
 	len += NLMSG_ALIGN(headlen);
 
-- 
2.53.0
Technical Details
Message-ID: <20261201124252.1163254-9-steffen.klassert@secunet.com>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375042-linux-kernel-netdev=dewy.ru
References: <20261201124252.1163254-1-steffen.klassert@secunet.com>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-375042-linux-kernel-netdev=dewy.ru
From: steffen.klassert@secunet.com (Steffen Klassert)
Newsgroups: linux.kernel.netdev
Subject: [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len()
Date: Tue, 1 Dec 2026 13:41:34 +0100
Organization: Usenet Network
Message-ID: <20261201124252.1163254-9-steffen.klassert@secunet.com>
References: <20261201124252.1163254-1-steffen.klassert@secunet.com>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1711884"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:6rnx6b4qYMXrEhhbD99tWR3Hi2s= sha256:jVjtSlMjrYPh4LyThc8dAqQWec7YS2FyBlmKtPHZIuA=
	sha1:7sh/uXUqE+QSK4unHjw6AcJrBjE= sha256:10okYeUyEjxdlUaaJZ5Z+q+kLZL8DPW0QE0nYjhnCb8=
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 EF8C4117387; Tue,  1 Dec 2026 15:44:37 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.05
X-Spam-Status: No, score=-3.05 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.249,
	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 91f8EM45JZax;
	Tue,  1 Dec 2026 15:44:35 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-375042-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4])
	by mail.dewy.ru (Postfix) with ESMTPS id BD907117384; Tue,  1 Dec 2026 15:44:26 +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 CC18224FA1; Tue,  1 Dec 2026 12:44:20 +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=1796129052;
	b=TqT+YQdgBUFH9HSJpY6I2hWOFKeM/EtakEMD5A2mtszbbLbFFvjfaPaUBo4KMp6sigJE
	 i99AOUdNnk2eIvpE0/kxROcIHEDHDYFjPKFCvlxvOmfY7lRlc8eqj3nvDKm+XL09qti6k
	 iaZMLpNQWNCV4xzT78x6HqNk3zYoiI/ObPq3MgZ2yc4K4kEkFn/gHkw4pve5UY/VM+yI7
	 vGVqlG+OreLvel8bf3WdJidbYdes3wxrBr7047ccIYFki1EH4M5U8yXUCbwZZror2rXsw
	 H08349axWh3AB4PrUW/5uMyxMs+IucL6vM9gy148h5uPmQ2/lOh+S+pASnuTEy/BpsA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796129052;
	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=XbZHkxp5v+1F9HjytpGlE3z8GDTJOglukbwynhkDorM=;
	b=CWm93sLsXPGw/MOcto7J+Fvxf/shFIyyUxGAZkrlWLa0yl8Vz4tyr6PvdXuqz8UAF1w5
	 PaVsoTDWToyht0cbq3PwZb718+GYG4q4OeeqrFca3VaEgAUZ4KFgDtzgG+7IAqH0IjR71
	 jqjjI6Ijf4Zwmx6GpdnZIKqglVrROoZnGOKkkFZuw2zXkxIRpS14XqAurfmiEAYbOHCfO
	 JJI+26Jjy3JVEQx9cd+1VHZ0Dm7C9ZB4W+You5W+afl7vxmoxTG6AMZLV8Z+QSOeMaBGu
	 h8Jec0mdWyWKC6To5XSfdq24138C0RyyP26z6hAfw8mfkP4bIxLAYQcyFAHj9IBR1mw==
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=akyAaDVJ;
	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 F2D92606A6B2;
	Tue,  1 Dec 2026 12:44:11 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=secunet.com header.i=@secunet.com header.a=rsa-sha256 header.s=202301 header.b=akyAaDVJ
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=1796129051;
	b=dtnIDBdg9SYOvGWlcU0n4PWzs6b4OmXiyi0FSGzXkjjEapTFR0Gj+m9yQocgswB5S/8v
	 8F7EH+8cjHTk9xQ2208mJjTlpqiO9xspKLQVtOiFLRMxV3OvwhpR9Qz+GSkTmYQxV95QQ
	 gb/xzUWZ+57Zwp2wZBPZqguW94FV+M1LpspNKdoAuD/Po0NH4BhcE6Q9moH5IpzPvxXWW
	 XdSt+wZ7wU3F1PqBDQMD6Q17gB7+B4yFZ2aEteP5MekFISdS4bYspZtVvszaMXvN3w5jY
	 9xlxqwpvs4yjd9HpPu8jReNXUjl8vACVLwu1KFLwgKWEdimSMXOfPtBC+bcmz8acaOg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1796129051;
	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=XbZHkxp5v+1F9HjytpGlE3z8GDTJOglukbwynhkDorM=;
	b=dfGv2pOjKSd0M8dod/ougJkmPQIzsDzMcMick224Nfdw7Q50CKWs2nsuH8PtqEJwk/nu
	 KHgQCxr+c8Uq1Imo92aJzLZDlLZ7ylT3mc55y+A8t+SgTZBIN1KHxQ0M8qBhEHkUw80If
	 c02a0nJoQpC/jBqZmT06RVZm1nBryvDMNM3TQbUeIJmAk36F6BqYOSVGOvYzh3c5upvSu
	 reNJzxYkM4VZSZ1Mua9l2O4/Q5z616iH2FHzb0/Hl80qBR0CvXIsGT/LBKwn9unNW+szM
	 djksDWhoqWKMeiBETjZFovTwr3WM3iPQJHllIgN5mYj4NPNptvEiNUZe280fIof2i6w==
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=akyAaDVJ;
	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 80C7C606A696
	for <netdev@vger.kernel.org>; Tue,  1 Dec 2026 12:44:09 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80C7C606A696
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 C459F207D1;
	Tue,  1 Dec 2026 13:44:08 +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 z-9HW3DK-7_Z; Tue,  1 Dec 2026 13:44:08 +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 3491D207C6;
	Tue,  1 Dec 2026 13:44:08 +0100 (CET)
X-DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 3491D207C6
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=secunet.com;
	s=202301; t=1796129048;
	bh=XbZHkxp5v+1F9HjytpGlE3z8GDTJOglukbwynhkDorM=;
	h=From:To:CC:Subject:Date:In-Reply-To:References:From;
	b=akyAaDVJ8vCW7C4eeRQU4oh7mEm5uV/JFLtDxOXxURaWSt+u8wXwaLyiziSdfmOWQ
	 UXtq8fLdFY1qdYQorJq3F3Ezh3bLQ6HL+5j63gs/61E1u0TKZUYDsui9DCHo7vKmfW
	 BAt2dTYN7hNThM/RcpvB96xL7/JWp8BYQl42SgxuJRcCBMf5H6FTtzJrFbtY5qu/oU
	 Ps5VU37M3ktPToCj13Z1EJQ5kRksl7YAbc580zoXLvq/5CKtd+dklBMMJUS6Pq7Vwc
	 eiNua//Vo4NsuKfFY1BJo+Q5717DJN0jWOUwoRzToByA2bnpvMhAfm5k2+CynoUSPh
	 Ehpv84eX1BvCg==
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; Tue, 1 Dec
 2026 13:44:07 +0100
X-Received: (nullmailer pid 1165783 invoked by uid 1000);
	Tue, 01 Dec 2026 12:43:55 -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: <20261201124252.1163254-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-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de
 (10.32.0.171)