Netdev List
 help / color / mirror / Atom feed
* [PATCH] net: block MSG_NO_SHARED_FRAGS in sendmsg()
@ 2026-05-12 14:02 Jann Horn
  2026-05-13  8:50 ` David Laight
  0 siblings, 1 reply; 2+ messages in thread
From: Jann Horn @ 2026-05-12 14:02 UTC (permalink / raw)
  To: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
	netdev
  Cc: linux-kernel, John Fastabend, Jann Horn

This change should cause no difference in behavior; it just cleans up some
hazardous code that could have become a problem in the future.

MSG_NO_SHARED_FRAGS is a kernel-internal flag that cancels the effect of
MSG_SPLICE_PAGES, another kernel-internal flag that influences the
data-sharing semantics of SKBs.

Prevent passing this flag in from userspace via sendmsg() by adding it to
MSG_INTERNAL_SENDMSG_FLAGS.

This is not currently an observable problem because MSG_NO_SHARED_FRAGS
only has an effect if kernel code adds MSG_SPLICE_PAGES to it.
The only codepath that adds MSG_SPLICE_PAGES to user-supplied flags from
which MSG_NO_SHARED_FRAGS hasn't been cleared is the path
tcp_bpf_sendmsg -> tcp_bpf_send_verdict -> tcp_bpf_push, and that is not a
problem because tcp_bpf_sendmsg always intentionally sets
MSG_NO_SHARED_FRAGS anyway.

Signed-off-by: Jann Horn <jannh@google.com>
---
 include/linux/socket.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/socket.h b/include/linux/socket.h
index ec4a0a025793..1a4d0d128a13 100644
--- a/include/linux/socket.h
+++ b/include/linux/socket.h
@@ -357,7 +357,7 @@ struct ucred {
 
 /* Flags to be cleared on entry by sendmsg and sendmmsg syscalls */
 #define MSG_INTERNAL_SENDMSG_FLAGS \
-	(MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_DECRYPTED)
+	(MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_DECRYPTED | MSG_NO_SHARED_FRAGS)
 
 /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
 #define SOL_IP		0

---
base-commit: 5d6919055dec134de3c40167a490f33c74c12581
change-id: 20260511-msg_no_shared_frags-d557c14e487b

--  
Jann Horn <jannh@google.com>


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: block MSG_NO_SHARED_FRAGS in sendmsg()
  2026-05-12 14:02 [PATCH] net: block MSG_NO_SHARED_FRAGS in sendmsg() Jann Horn
@ 2026-05-13  8:50 ` David Laight
  0 siblings, 0 replies; 2+ messages in thread
From: David Laight @ 2026-05-13  8:50 UTC (permalink / raw)
  To: Jann Horn
  Cc: Eric Dumazet, Kuniyuki Iwashima, Paolo Abeni, Willem de Bruijn,
	netdev, linux-kernel, John Fastabend

On Tue, 12 May 2026 16:02:03 +0200
Jann Horn <jannh@google.com> wrote:

> This change should cause no difference in behavior; it just cleans up some
> hazardous code that could have become a problem in the future.
> 
> MSG_NO_SHARED_FRAGS is a kernel-internal flag that cancels the effect of
> MSG_SPLICE_PAGES, another kernel-internal flag that influences the
> data-sharing semantics of SKBs.
> 
> Prevent passing this flag in from userspace via sendmsg() by adding it to
> MSG_INTERNAL_SENDMSG_FLAGS.
> 
> This is not currently an observable problem because MSG_NO_SHARED_FRAGS
> only has an effect if kernel code adds MSG_SPLICE_PAGES to it.
> The only codepath that adds MSG_SPLICE_PAGES to user-supplied flags from
> which MSG_NO_SHARED_FRAGS hasn't been cleared is the path
> tcp_bpf_sendmsg -> tcp_bpf_send_verdict -> tcp_bpf_push, and that is not a
> problem because tcp_bpf_sendmsg always intentionally sets
> MSG_NO_SHARED_FRAGS anyway.

Should that be inverted to an explicit list of valid flags?

Unfortunately it doesn't look like calls with unsupported flags can be
errored - which actually means that no new ones can be allocated for
new functionality.

-- David

> 
> Signed-off-by: Jann Horn <jannh@google.com>
> ---
>  include/linux/socket.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/include/linux/socket.h b/include/linux/socket.h
> index ec4a0a025793..1a4d0d128a13 100644
> --- a/include/linux/socket.h
> +++ b/include/linux/socket.h
> @@ -357,7 +357,7 @@ struct ucred {
>  
>  /* Flags to be cleared on entry by sendmsg and sendmmsg syscalls */
>  #define MSG_INTERNAL_SENDMSG_FLAGS \
> -	(MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_DECRYPTED)
> +	(MSG_SPLICE_PAGES | MSG_SENDPAGE_NOPOLICY | MSG_SENDPAGE_DECRYPTED | MSG_NO_SHARED_FRAGS)
>  
>  /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */
>  #define SOL_IP		0
> 
> ---
> base-commit: 5d6919055dec134de3c40167a490f33c74c12581
> change-id: 20260511-msg_no_shared_frags-d557c14e487b
> 
> --  
> Jann Horn <jannh@google.com>
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-05-13  8:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-12 14:02 [PATCH] net: block MSG_NO_SHARED_FRAGS in sendmsg() Jann Horn
2026-05-13  8:50 ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox