From: Andrei Gherzan <andrei.gherzan@canonical.com>
To: Jakub Kicinski <kuba@kernel.org>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Shuah Khan <shuah@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-kselftest@vger.kernel.org,
Kleber Sacilotto de Souza <kleber.souza@canonical.com>,
Hangbin Liu <liuhangbin@gmail.com>,
Andrei Gherzan <andrei.gherzan@canonical.com>
Subject: [PATCH net 1/2] netdevsim: print IPsec salt/key in network byte order
Date: Tue, 8 Sep 2026 15:03:24 +0100 [thread overview]
Message-ID: <20260908140325.13367-2-andrei.gherzan@canonical.com> (raw)
In-Reply-To: <20260908140325.13367-1-andrei.gherzan@canonical.com>
nsim_sa.key[] and nsim_sa.salt hold raw key material in network byte
order, but are typed as plain u32 and printed with "%08x" in the
debugfs read handler. This prints host-endian, so output differs
between little- and big-endian hosts for the same key:
little-endian: salt=0x61626364 key=0x34333231 38373635 32313039 36353433
big-endian: salt=0x64636261 key=0x31323334 35363738 39303132 33343536
This breaks selftests/net/rtnetlink.sh's ipsec_offload subtest on
big-endian (e.g. s390x), which hardcodes the little-endian output.
Retype key[]/salt to __be32, matching ipaddr[], and convert with
be32_to_cpu() before printing. Output is now network-order on every
host, independent of endianness.
A similar fix was proposed in 2022 but kept the u32 typing, so sparse
couldn't validate the added ntohl() calls and it stalled in review.
Retyping first avoids that problem. `make C=2` on netdevsim reports
the same zero warnings as before this change.
Selftest update follows in the next patch.
Fixes: 7699353da875 ("netdevsim: add ipsec offload testing")
Reported-by: Kleber Sacilotto de Souza <kleber.souza@canonical.com>
Link: https://lore.kernel.org/netdev/20220308135106.890270-1-kleber.souza@canonical.com/
Signed-off-by: Andrei Gherzan <andrei.gherzan@canonical.com>
---
drivers/net/netdevsim/ipsec.c | 10 +++++-----
drivers/net/netdevsim/netdevsim.h | 4 ++--
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/drivers/net/netdevsim/ipsec.c b/drivers/net/netdevsim/ipsec.c
index 36a1be4923d61..5722837bcda36 100644
--- a/drivers/net/netdevsim/ipsec.c
+++ b/drivers/net/netdevsim/ipsec.c
@@ -50,11 +50,11 @@ static ssize_t nsim_dbg_netdev_ops_read(struct file *filp,
p += scnprintf(p, bufsize - (p - buf),
"sa[%i] spi=0x%08x proto=0x%x salt=0x%08x crypt=%d\n",
i, be32_to_cpu(sap->xs->id.spi),
- sap->xs->id.proto, sap->salt, sap->crypt);
+ sap->xs->id.proto, be32_to_cpu(sap->salt), sap->crypt);
p += scnprintf(p, bufsize - (p - buf),
"sa[%i] key=0x%08x %08x %08x %08x\n",
- i, sap->key[0], sap->key[1],
- sap->key[2], sap->key[3]);
+ i, be32_to_cpu(sap->key[0]), be32_to_cpu(sap->key[1]),
+ be32_to_cpu(sap->key[2]), be32_to_cpu(sap->key[3]));
}
len = simple_read_from_buffer(buffer, count, ppos, buf, p - buf);
@@ -87,7 +87,7 @@ static int nsim_ipsec_find_empty_idx(struct nsim_ipsec *ipsec)
static int nsim_ipsec_parse_proto_keys(struct net_device *dev,
struct xfrm_state *xs,
- u32 *mykey, u32 *mysalt)
+ __be32 *mykey, __be32 *mysalt)
{
const char aes_gcm_name[] = "rfc4106(gcm(aes))";
unsigned char *key_data;
@@ -117,7 +117,7 @@ static int nsim_ipsec_parse_proto_keys(struct net_device *dev,
/* 160 accounts for 16 byte key and 4 byte salt */
if (key_len > NSIM_IPSEC_AUTH_BITS) {
- *mysalt = ((u32 *)key_data)[4];
+ *mysalt = ((__be32 *)key_data)[4];
} else if (key_len == NSIM_IPSEC_AUTH_BITS) {
*mysalt = 0;
} else {
diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h
index 55aec41237b9b..a82a685384e6d 100644
--- a/drivers/net/netdevsim/netdevsim.h
+++ b/drivers/net/netdevsim/netdevsim.h
@@ -42,8 +42,8 @@
struct nsim_sa {
struct xfrm_state *xs;
__be32 ipaddr[4];
- u32 key[4];
- u32 salt;
+ __be32 key[4];
+ __be32 salt;
bool used;
bool crypt;
bool rx;
--
2.43.0
next prev parent reply other threads:[~2026-09-08 14:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-08 14:03 [PATCH net 0/2] netdevsim: fix IPsec debugfs byte order Andrei Gherzan
2026-09-08 14:03 ` Andrei Gherzan [this message]
2026-09-08 14:03 ` [PATCH net 2/2] selftests: rtnetlink: update ipsec_offload expected output Andrei Gherzan
2026-09-09 13:37 ` [PATCH net 0/2] netdevsim: fix IPsec debugfs byte order Andrei Gherzan
2026-09-09 20:38 ` Jakub Kicinski
2026-09-09 20:40 ` patchwork-bot+netdevbpf
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=20260908140325.13367-2-andrei.gherzan@canonical.com \
--to=andrei.gherzan@canonical.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kleber.souza@canonical.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=liuhangbin@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=shuah@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox