Skip to contentSkip to conversation

net/smc: fix limit_smc_hs sysctl on big-endian architecture

PATCH Applied Fernando Fernandez Mancera 3 participants 3 messages Oct 28 – Oct 31

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/smc: fix limit_smc_hs sysctl on big-endian architecture

net->smc.limit_smc_hs is a bool, but its sysctl entry uses proc_dointvec_minmax() with .maxlen = sizeof(int), so the handler accesses four bytes at the address of a one-byte field.

On little-endian this works with the extra bytes being written in struct padding. On big-endian (tested on s390x) the bool sits at the most significant byte of the int therefore the bool stays false and the "1" goes into padding. The sysctl reads back 1 but SMC sockets created afterwards see limit_smc_hs as disabled.

Fix this by using proc_dobool() handler and adjust the maxlen to the right value.

Fixes f8406a2fd279 ("net/smc: add sysctl for smc_limit_hs")

---
Note: After reviewing another patch fixing sysctls, I decided to review more of them and found this. I have tested the fix on a s390x system.

---
 net/smc/smc_sysctl.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/smc/smc_sysctl.c +2 -4
index 09dad48337f6..f58cf256f61a 100644
@@ -160,11 +160,9 @@ static const struct ctl_table smc_table[] = {
 	{
 		.procname	= "limit_smc_hs",
 		.data		= &init_net.smc.limit_smc_hs,
-		.maxlen		= sizeof(int),
+		.maxlen		= sizeof(bool),
 		.mode		= 0644,
-		.proc_handler	= proc_dointvec_minmax,
-		.extra1		= SYSCTL_ZERO,
-		.extra2		= SYSCTL_ONE,
+		.proc_handler	= proc_dobool,
 	},
 	{
 		.procname	= "smcr_max_send_wr",
Signature · 1 line
2.56.0
#1 lore raw
Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

net->smc.limit_smc_hs is a bool, but its sysctl entry uses proc_dointvec_minmax() with .maxlen = sizeof(int), so the handler accesses four bytes at the address of a one-byte field.

On little-endian this works with the extra bytes being written in struct padding. On big-endian (tested on s390x) the bool sits at the most significant byte of the int therefore the bool stays false and the "1" goes into padding. The sysctl reads back 1 but SMC sockets created afterwards see limit_smc_hs as disabled.

Quoted 5 lines

Fix this by using proc_dobool() handler and adjust the maxlen to the right value.

Fixes f8406a2fd279 ("net/smc: add sysctl for smc_limit_hs")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Fernando Fernandez Mancera
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Wed, 28 Oct 2026 23:53:50 +0100 you wrote:

net->smc.limit_smc_hs is a bool, but its sysctl entry uses proc_dointvec_minmax() with .maxlen = sizeof(int), so the handler accesses four bytes at the address of a one-byte field.

On little-endian this works with the extra bytes being written in struct padding. On big-endian (tested on s390x) the bool sits at the most significant byte of the int therefore the bool stays false and the "1" goes into padding. The sysctl reads back 1 but SMC sockets created afterwards see limit_smc_hs as disabled.

[...]

Here is the summary with links:
- [net] net/smc: fix limit_smc_hs sysctl on big-endian architecture

    https://git.kernel.org/netdev/net/c/162cf592b577

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html