[net-next,v2,2/6] net: Block MSG_SENDPAGE_* from being passed to sendmsg() by userspace

Message ID 20230531124528.699123-3-dhowells@redhat.com
State New
Headers
Series splice, net: Handle MSG_SPLICE_PAGES in AF_TLS |

Commit Message

David Howells May 31, 2023, 12:45 p.m. UTC
  It is necessary to allow MSG_SENDPAGE_* to be passed into ->sendmsg() to
allow sendmsg(MSG_SPLICE_PAGES) to replace ->sendpage().  Unblocking them
in the network protocol, however, allows these flags to be passed in by
userspace too[1].

Fix this by marking MSG_SENDPAGE_NOPOLICY, MSG_SENDPAGE_NOTLAST and
MSG_SENDPAGE_DECRYPTED as internal flags, which causes sendmsg() to object
if they are passed to sendmsg() by userspace.  Network protocol ->sendmsg()
implementations can then allow them through.

Note that it should be possible to remove MSG_SENDPAGE_NOTLAST once
sendpage is removed as a whole slew of pages will be passed in in one go by
splice through sendmsg, with MSG_MORE being set if it has more data waiting
in the pipe.

Signed-off-by: David Howells <dhowells@redhat.com>
cc: Jakub Kicinski <kuba@kernel.org>
cc: Chuck Lever <chuck.lever@oracle.com>
cc: Boris Pismenny <borisp@nvidia.com>
cc: John Fastabend <john.fastabend@gmail.com>
cc: Eric Dumazet <edumazet@google.com>
cc: "David S. Miller" <davem@davemloft.net>
cc: Paolo Abeni <pabeni@redhat.com>
cc: Jens Axboe <axboe@kernel.dk>
cc: Matthew Wilcox <willy@infradead.org>
cc: netdev@vger.kernel.org
Link: https://lore.kernel.org/r/20230526181338.03a99016@kernel.org/ [1]
---
 include/linux/socket.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
  

Comments

Simon Horman May 31, 2023, 5:02 p.m. UTC | #1
On Wed, May 31, 2023 at 01:45:24PM +0100, David Howells wrote:
> It is necessary to allow MSG_SENDPAGE_* to be passed into ->sendmsg() to
> allow sendmsg(MSG_SPLICE_PAGES) to replace ->sendpage().  Unblocking them
> in the network protocol, however, allows these flags to be passed in by
> userspace too[1].
> 
> Fix this by marking MSG_SENDPAGE_NOPOLICY, MSG_SENDPAGE_NOTLAST and
> MSG_SENDPAGE_DECRYPTED as internal flags, which causes sendmsg() to object
> if they are passed to sendmsg() by userspace.  Network protocol ->sendmsg()
> implementations can then allow them through.
> 
> Note that it should be possible to remove MSG_SENDPAGE_NOTLAST once
> sendpage is removed as a whole slew of pages will be passed in in one go by

Hi David,

on the off-chance that you need to respin for some other reason:

	s/in in/in/

> splice through sendmsg, with MSG_MORE being set if it has more data waiting
> in the pipe.

...
  
David Howells May 31, 2023, 6:01 p.m. UTC | #2
Simon Horman <simon.horman@corigine.com> wrote:

> > sendpage is removed as a whole slew of pages will be passed in in one go by
> 
> on the off-chance that you need to respin for some other reason:
> 
> 	s/in in/in/

What I wrote is correct - there should be two ins.  I could write it as:

	... passed in [as an argument] in one go...

For your amusement, consider:

	All the faith he had had had had no effect on the outcome of his life.

	https://ell.stackexchange.com/questions/285066/explanation-for-had-had-had-had-being-grammatically-correct

David
  
Matthew Wilcox May 31, 2023, 6:30 p.m. UTC | #3
On Wed, May 31, 2023 at 07:01:12PM +0100, David Howells wrote:
> Simon Horman <simon.horman@corigine.com> wrote:
> 
> > > sendpage is removed as a whole slew of pages will be passed in in one go by
> > 
> > on the off-chance that you need to respin for some other reason:
> > 
> > 	s/in in/in/
> 
> What I wrote is correct - there should be two ins.  I could write it as:
> 
> 	... passed in [as an argument] in one go...
> 
> For your amusement, consider:
> 
> 	All the faith he had had had had no effect on the outcome of his life.
> 
> 	https://ell.stackexchange.com/questions/285066/explanation-for-had-had-had-had-being-grammatically-correct

Let's not buffalo Buffalo buffalo ...
  
Simon Horman May 31, 2023, 8:26 p.m. UTC | #4
On Wed, May 31, 2023 at 07:01:12PM +0100, David Howells wrote:
> Simon Horman <simon.horman@corigine.com> wrote:
> 
> > > sendpage is removed as a whole slew of pages will be passed in in one go by
> > 
> > on the off-chance that you need to respin for some other reason:
> > 
> > 	s/in in/in/
> 
> What I wrote is correct - there should be two ins.  I could write it as:

Thanks David, I see that now.

> 	... passed in [as an argument] in one go...
> 
> For your amusement, consider:
> 
> 	All the faith he had had had had no effect on the outcome of his life.
> 
> 	https://ell.stackexchange.com/questions/285066/explanation-for-had-had-had-had-being-grammatically-correct
> 
> David
>
  

Patch

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