Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=62.96.220.36 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== 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== 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 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 ; Tue, 1 Dec 2026 12:44:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 80C7C606A696 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=secunet.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=secunet.com 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 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 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) 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) DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.secunet.com 3491D207C6 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== 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 Received: (nullmailer pid 1165783 invoked by uid 1000); Tue, 01 Dec 2026 12:43:55 -0000 From: Steffen Klassert To: David Miller , Jakub Kicinski CC: Herbert Xu , Steffen Klassert , Subject: [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len() Date: Tue, 1 Dec 2026 13:41:34 +0100 Message-ID: <20261201124252.1163254-9-steffen.klassert@secunet.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com> References: <20261201124252.1163254-1-steffen.klassert@secunet.com> X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EXCH-04.secunet.de (10.32.0.184) To EXCH-01.secunet.de (10.32.0.171) From: Yasuaki Torimaru 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 Signed-off-by: Steffen Klassert --- 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