🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Nandor Kracser Wed, 21 Oct 2026 07:32
[PATCH net] tls: avoid field-spanning write when copying crypto info
#5908
Author: Nandor Kracser
Date: Wed, 21 Oct 2026 07:32
50 lines
12733 bytes
do_tls_setsockopt_conf() copies the cipher-specific part of the crypto
info to crypto_info + 1, where crypto_info points at the 4-byte info
member of union tls_crypto_context. When optval is a kernel sockptr,
copy_from_sockptr_offset() is a memcpy(), and FORTIFY_SOURCE bounds the
destination by that member:

  [    6.948348] memcpy: detected field-spanning write (size 52) of single field "dst" at include/linux/sockptr.h:49 (size 0)
  [    6.948480] WARNING: include/linux/sockptr.h:49 at tls_setsockopt+0x9b2/0xa30, CPU#1: init/1
  [    7.001355] Call Trace:
  [    7.003146]  do_sock_setsockopt+0xb0/0x190
  [    7.003975]  __sys_setsockopt+0x76/0xc0
  [    7.005368]  do_syscall_64+0xda/0x4b0

tls_setsockopt() gets a kernel sockptr whenever a cgroup setsockopt BPF
program is attached, even one that leaves the option alone, because
__cgroup_bpf_run_filter_setsockopt() passes optval on in a kernel
buffer. With a no-op program on the root cgroup, a plain TLS_TX
setsockopt() with AES-GCM-256 triggers the warning above on an x86_64
build with CONFIG_FORTIFY_SOURCE.

Copy into the union at offset sizeof(struct tls_crypto_info) instead.
crypto_ctx already points at the right union for both the first set
and the TLS 1.3 rekey (tmp) case, and the address is unchanged.

Fixes: a7b75c5a8c41 ("net: pass a sockptr_t into ->setsockopt")
Signed-off-by: Nandor Kracser <nandor@riptides.io>
---
 net/tls/tls_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index fbb274287..9b07ef8cc 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -701,8 +701,8 @@ static int do_tls_setsockopt_conf(struct sock *sk, sockptr_t optval,
 		goto err_crypto_info;
 	}
 
-	rc = copy_from_sockptr_offset(crypto_info + 1, optval,
-				      sizeof(*crypto_info),
+	rc = copy_from_sockptr_offset((u8 *)crypto_ctx + sizeof(*crypto_info),
+				      optval, sizeof(*crypto_info),
 				      optlen - sizeof(*crypto_info));
 	if (rc) {
 		rc = -EFAULT;

base-commit: daac93975b8ff0a0a036a5e3562236c0b40c3e36
-- 
2.53.0
Re: [PATCH net] tls: avoid field-spanning write when copying crypto info
#6971
Author: patchwork-bot+netdevbpf
Date: Fri, 23 Oct 2026 23:10
30 lines
9026 bytes
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 21 Oct 2026 09:32:33 +0200 you wrote:
> do_tls_setsockopt_conf() copies the cipher-specific part of the crypto
> info to crypto_info + 1, where crypto_info points at the 4-byte info
> member of union tls_crypto_context. When optval is a kernel sockptr,
> copy_from_sockptr_offset() is a memcpy(), and FORTIFY_SOURCE bounds the
> destination by that member:
> 
>   [    6.948348] memcpy: detected field-spanning write (size 52) of single field "dst" at include/linux/sockptr.h:49 (size 0)
>   [    6.948480] WARNING: include/linux/sockptr.h:49 at tls_setsockopt+0x9b2/0xa30, CPU#1: init/1
>   [    7.001355] Call Trace:
>   [    7.003146]  do_sock_setsockopt+0xb0/0x190
>   [    7.003975]  __sys_setsockopt+0x76/0xc0
>   [    7.005368]  do_syscall_64+0xda/0x4b0
> 
> [...]

Here is the summary with links:
  - [net] tls: avoid field-spanning write when copying crypto info
    https://git.kernel.org/netdev/net/c/c43c1c24f3cd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads