Skip to contentSkip to conversation

packet: allow MSG_NOSIGNAL in recvmsg

PATCH In review David Lamparter 3 participants 10 messages Feb 24, 2023

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

PATCH 1/1 packet: allow MSG_NOSIGNAL in recvmsg

packet_recvmsg() whitelists a bunch of MSG_* flags, which notably does not include MSG_NOSIGNAL. Unfortunately, io_uring always sets MSG_NOSIGNAL, meaning AF_PACKET sockets can't be used in io_uring recvmsg().

As AF_PACKET sockets never generate SIGPIPE to begin with, MSG_NOSIGNAL is a no-op and can simply be ignored.

Cc Willem de Bruijn <[email protected]>
---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
index d4e76e2ae153..67c0a57e6dd8 100644
@@ -3410,7 +3410,7 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 	unsigned int origlen = 0;
 
 	err = -EINVAL;
-	if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT|MSG_ERRQUEUE))
+	if (flags & ~(MSG_PEEK|MSG_DONTWAIT|MSG_TRUNC|MSG_CMSG_COMPAT|MSG_ERRQUEUE|MSG_NOSIGNAL))
 		goto out;
 
 #if 0
Signature · 1 line
2.39.2
#1 lore raw
Quoted 6 lines · David Lamparter

packet_recvmsg() whitelists a bunch of MSG_* flags, which notably does not include MSG_NOSIGNAL. Unfortunately, io_uring always sets MSG_NOSIGNAL, meaning AF_PACKET sockets can't be used in io_uring recvmsg().

Quoted 9 lines

As AF_PACKET sockets never generate SIGPIPE to begin with, MSG_NOSIGNAL is a no-op and can simply be ignored.

Cc Willem de Bruijn <[email protected]>
---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

This is odd... I think MSG_NOSIGNAL flag has a meaning for sendmsg() (or write sides in general)

EPIPE is not supposed to be generated at the receiving side ?

So I would rather make io_uring slightly faster :

io_uring/net.c +0 -0
index cbd4b725f58c98e5bc5bf88d5707db5c8302e071..b7f190ca528e6e259eb2b072d7a16aaba98848cb

100644

io_uring/net.c +0 -0
@@ -567,7 +567,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const

struct io_uring_sqe *sqe)

        sr->flags = READ_ONCE(sqe->ioprio);
        if (sr->flags & ~(RECVMSG_FLAGS))
                return -EINVAL;
-       sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
+       sr->msg_flags = READ_ONCE(sqe->msg_flags);
        if (sr->msg_flags & MSG_DONTWAIT)
                req->flags |= REQ_F_NOWAIT;
        if (sr->msg_flags & MSG_ERRQUEUE)
#2 lore raw
Quoted 1 line · Eric Dumazet

On Fri, Feb 24, 2023 at 8:18 AM David Lamparter <[email protected]> wrote:

[...]

Quoted 9 lines
Quoted 4 lines

packet_recvmsg() whitelists a bunch of MSG_* flags, which notably does not include MSG_NOSIGNAL. Unfortunately, io_uring always sets MSG_NOSIGNAL, meaning AF_PACKET sockets can't be used in io_uring recvmsg().

This is odd... I think MSG_NOSIGNAL flag has a meaning for sendmsg() (or write sides in general)

EPIPE is not supposed to be generated at the receiving side ?

I would agree, but then again the behavior is inconsistent between socket types. (AF_INET6, SOCK_RAW, ...) works fine with io_uring/MSG_NOSIGNAL, meanwhile setting MSG_NOSIGNAL on (AF_PACKET, SOCK_RAW, ...) gives EINVAL.

Just to get consistency, MSG_NOSIGNAL might be worth ignoring in AF_PACKET recvmsg? Independent of dropping it from io_uring...

Quoted 1 line

So I would rather make io_uring slightly faster :

[...]

Quoted 2 lines
(quoted diff) +1 -1
-       sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
+       sr->msg_flags = READ_ONCE(sqe->msg_flags);
#3 lore raw
Quoted 14 lines · David Lamparter
Quoted 1 line · Eric Dumazet

On Fri, Feb 24, 2023 at 8:18 AM David Lamparter <[email protected]> wrote:

[...]

Quoted 9 lines
Quoted 4 lines

packet_recvmsg() whitelists a bunch of MSG_* flags, which notably does not include MSG_NOSIGNAL. Unfortunately, io_uring always sets MSG_NOSIGNAL, meaning AF_PACKET sockets can't be used in io_uring recvmsg().

This is odd... I think MSG_NOSIGNAL flag has a meaning for sendmsg() (or write sides in general)

EPIPE is not supposed to be generated at the receiving side ?

Quoted 8 lines

I would agree, but then again the behavior is inconsistent between socket types. (AF_INET6, SOCK_RAW, ...) works fine with io_uring/MSG_NOSIGNAL, meanwhile setting MSG_NOSIGNAL on (AF_PACKET, SOCK_RAW, ...) gives EINVAL.

Just to get consistency, MSG_NOSIGNAL might be worth ignoring in AF_PACKET recvmsg? Independent of dropping it from io_uring...

Probably because rawv6_recvmsg() never bothered to reject unknown flags. (Maybe the reason for that was that RAW sockets were privileged ones back in linux-2.6)
It is too late to add a check there, it might break some applications mistakenly adding MSG_NOSIGNAL (or any currently ignored bits)

Consistency would be to make sure no recvmsg() handler pretends MSG_NOSIGNAL has a meaning.

Your patch would prevent us using this bit for a future purpose in af_packet.

Quoted 4 lines
Quoted 1 line

So I would rather make io_uring slightly faster :

[...]

Quoted 2 lines
(quoted diff) +1 -1
-       sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
+       sr->msg_flags = READ_ONCE(sqe->msg_flags);
maintainer
#4 lore raw
In reply to Eric Dumazet
Quoted 39 lines · Eric Dumazet
Quoted 6 lines · David Lamparter

packet_recvmsg() whitelists a bunch of MSG_* flags, which notably does not include MSG_NOSIGNAL. Unfortunately, io_uring always sets MSG_NOSIGNAL, meaning AF_PACKET sockets can't be used in io_uring recvmsg().

Quoted 9 lines

As AF_PACKET sockets never generate SIGPIPE to begin with, MSG_NOSIGNAL is a no-op and can simply be ignored.

Cc Willem de Bruijn <[email protected]>
---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

This is odd... I think MSG_NOSIGNAL flag has a meaning for sendmsg() (or write sides in general)

EPIPE is not supposed to be generated at the receiving side ?

So I would rather make io_uring slightly faster :

io_uring/net.c +0 -0
index cbd4b725f58c98e5bc5bf88d5707db5c8302e071..b7f190ca528e6e259eb2b072d7a16aaba98848cb

100644

io_uring/net.c +1 -1
@@ -567,7 +567,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const
 struct io_uring_sqe *sqe)
        sr->flags = READ_ONCE(sqe->ioprio);
        if (sr->flags & ~(RECVMSG_FLAGS))
                return -EINVAL;
-       sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
+       sr->msg_flags = READ_ONCE(sqe->msg_flags);
        if (sr->msg_flags & MSG_DONTWAIT)
                req->flags |= REQ_F_NOWAIT;
Quoted 1 line
        if (sr->msg_flags & MSG_ERRQUEUE)

This looks fine to me. Do you want to send a "proper" patch for this?

Signature · 1 line
Jens Axboe
#5 lore raw
Quoted 3 lines · Jens Axboe

This looks fine to me. Do you want to send a "proper" patch for this?

Sure, or perhaps David wanted to take care of this.

Thanks.

#6 lore raw

PATCH 1/1 io_uring: remove MSG_NOSIGNAL from recvmsg

MSG_NOSIGNAL is not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET's packet_recvmsg() does enforce this, giving back EINVAL when MSG_NOSIGNAL is set - making it unuseable in io_uring's recvmsg.

Remove MSG_NOSIGNAL from io_recvmsg_prep().

Cc Eric Dumazet <[email protected]>
Cc Jens Axboe <[email protected]>

---

Quoted 1 line

Sure, or perhaps David wanted to take care of this.

Here you go. But maybe give me a few hours to test/confirm...

io_uring/net.c +1 -1
index cbd4b725f58c..b7f190ca528e 100644
@@ -567,7 +567,7 @@ int io_recvmsg_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe)
 	sr->flags = READ_ONCE(sqe->ioprio);
 	if (sr->flags & ~(RECVMSG_FLAGS))
 		return -EINVAL;
-	sr->msg_flags = READ_ONCE(sqe->msg_flags) | MSG_NOSIGNAL;
+	sr->msg_flags = READ_ONCE(sqe->msg_flags);
 	if (sr->msg_flags & MSG_DONTWAIT)
 		req->flags |= REQ_F_NOWAIT;
 	if (sr->msg_flags & MSG_ERRQUEUE)
Signature · 1 line
2.39.2
#7 lore raw

Re: [PATCH] io_uring: remove MSG_NOSIGNAL from recvmsg

Quoted 8 lines · David Lamparter

MSG_NOSIGNAL is not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET's packet_recvmsg() does enforce this, giving back EINVAL when MSG_NOSIGNAL is set - making it unuseable in io_uring's recvmsg.
---

Quoted 1 line

Sure, or perhaps David wanted to take care of this.

Here you go. But maybe give me a few hours to test/confirm...

Unsurprisingly, it works as expected.

Reviewed-by on v1 1/1
#8 lore raw

Re: [PATCH] io_uring: remove MSG_NOSIGNAL from recvmsg

In reply to David Lamparter
Quoted 8 lines · David Lamparter

MSG_NOSIGNAL is not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET's packet_recvmsg() does enforce this, giving back EINVAL when MSG_NOSIGNAL is set - making it unuseable in io_uring's recvmsg.

Remove MSG_NOSIGNAL from io_recvmsg_prep().

Quoted 9 lines
Cc Eric Dumazet <[email protected]>
Cc Jens Axboe <[email protected]>

---

Quoted 1 line

Sure, or perhaps David wanted to take care of this.

Here you go. But maybe give me a few hours to test/confirm...

Thanks !

maintainer Applied
#9 lore raw

Re: [PATCH] io_uring: remove MSG_NOSIGNAL from recvmsg

In reply to David Lamparter
Quoted 8 lines · David Lamparter

MSG_NOSIGNAL is not applicable for the receiving side, SIGPIPE is generated when trying to write to a "broken pipe". AF_PACKET's packet_recvmsg() does enforce this, giving back EINVAL when MSG_NOSIGNAL is set - making it unuseable in io_uring's recvmsg.

Remove MSG_NOSIGNAL from io_recvmsg_prep().

[...]

Applied, thanks!

[1/1] io_uring: remove MSG_NOSIGNAL from recvmsg

      commit: 4492575406d8592b623987cb36b8234d285cfa17

Best regards,

Signature · 1 line
Jens Axboe