From: Steffen Klassert <steffen.klassert@secunet.com>
To: David Miller <davem@davemloft.net>, Jakub Kicinski <kuba@kernel.org>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
Steffen Klassert <steffen.klassert@secunet.com>,
<netdev@vger.kernel.org>
Subject: [PATCH 08/22] xfrm: account XFRMA_MARK in xfrm_sa_len()
Date: Tue, 1 Dec 2026 13:41:34 +0100 [thread overview]
Message-ID: <20261201124252.1163254-9-steffen.klassert@secunet.com> (raw)
In-Reply-To: <20261201124252.1163254-1-steffen.klassert@secunet.com>
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
next prev parent reply other threads:[~2026-12-01 12:44 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-01 12:41 [PATCH 0/22] pull request (net): ipsec 2026-12-01 Steffen Klassert
2026-12-01 12:41 ` [PATCH 01/22] xfrm: ipcomp: account full fragment pages in truesize Steffen Klassert
2026-12-01 13:36 ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 02/22] xfrm: esp: reset outer TCP GSO metadata on espintcp input Steffen Klassert
2026-12-01 12:41 ` [PATCH 03/22] xfrm: keep the mode module pinned until destroy_state returns Steffen Klassert
2026-12-01 12:41 ` [PATCH 04/22] xfrm: serialize SA activation with state deletion Steffen Klassert
2026-12-01 12:41 ` [PATCH 05/22] xfrm: keep old state references until migration deletion completes Steffen Klassert
2026-12-01 12:41 ` [PATCH 06/22] xfrm: hold migrated states through rollback Steffen Klassert
2026-12-01 12:41 ` [PATCH 07/22] xfrm: check inner family via skb_dst for small_ipv6 DF clearing Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` Steffen Klassert [this message]
2026-12-01 12:41 ` [PATCH 09/22] xfrm: replay: Fix late packet handling with ESN crypto offload Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 10/22] xfrm: fix IPv6 first-fragment protocol decode Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 11/22] xfrm: fix selector matching for IPv6 atomic fragments Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 12/22] xfrm: espintcp: read the socket error queue for MSG_ERRQUEUE Steffen Klassert
2026-12-01 12:41 ` [PATCH 13/22] xfrm: iptfs: force a dst reference before queueing an skb Steffen Klassert
2026-12-01 13:36 ` bot+bpf-ci
2026-12-01 12:41 ` [PATCH 14/22] xfrm: espintcp: select receive path by skb protocol Steffen Klassert
2026-12-01 12:41 ` [PATCH 15/22] net: xfrm: interface: restore dst_orig on every xfrm interface Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 16/22] xfrm: iptfs: make room before copying a continuation in reassembly Steffen Klassert
2026-12-01 12:41 ` [PATCH 17/22] xfrm/compat: pass on the translated length of a socket policy Steffen Klassert
2026-12-01 12:41 ` [PATCH 18/22] xfrm: Give GC list nodes their own storage Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 19/22] xfrm: Serialize device state teardown Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 20/22] xfrm: Wait for an RCU grace period before freeing device state Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 21/22] Revert "xfrm: serialize state GC with device state flush" Steffen Klassert
2026-12-02 13:12 ` netdev-bot+sashiko
2026-12-01 12:41 ` [PATCH 22/22] xfrm: Serialize offload stats updates with x->lock Steffen Klassert
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261201124252.1163254-9-steffen.klassert@secunet.com \
--to=steffen.klassert@secunet.com \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.