net/unix: use consistent error code in SO_PEERPIDFD
Subsystems (3)
PATCH 1/1 net/unix: use consistent error code in SO_PEERPIDFD
Change the new (unreleased) SO_PEERPIDFD sockopt to return ENODATA rather than ESRCH if a socket type does not support remote peer-PID queries.
Currently, SO_PEERPIDFD returns ESRCH when the socket in question is not an AF_UNIX socket. This is quite unexpected, given that one would assume ESRCH means the peer process already exited and thus cannot be found. However, in that case the sockopt actually returns EINVAL (via pidfd_prepare()). This is rather inconsistent with other syscalls, which usually return ESRCH if a given PID refers to a non-existant process.
This changes SO_PEERPIDFD to return ENODATA instead. This is also what SO_PEERGROUPS returns, and thus keeps a consistent behavior across sockopts.
Note that this code is returned in 2 cases: First, if the socket type is not AF_UNIX, and secondly if the socket was not yet connected. In both cases ENODATA seems suitable.
---
Hi!
The SO_PEERPIDFD sockopt has been queued for 6.5, so hopefully we can get that in before the release?
Thanks
David
net/core/sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/sock.c +1 -1
@@ -1778,7 +1778,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,spin_unlock (&sk->sk_peer_lock);if (!peer_pid) -return -ESRCH ; +return -ENODATA ; pidfd =pidfd_prepare (peer_pid,0 , &pidfd_file);put_pid (peer_pid);
Signature · 1 line
2.41.0
Quoted 16 lines · David Rheinsberg
Change the new (unreleased)
SO_PEERPIDFDsockopt to return ENODATA rather than ESRCH if a socket type does not support remote peer-PID queries.Currently,
SO_PEERPIDFDreturns ESRCH when the socket in question is not anAF_UNIXsocket. This is quite unexpected, given that one would assume ESRCH means the peer process already exited and thus cannot be found. However, in that case the sockopt actually returns EINVAL (viapidfd_prepare()). This is rather inconsistent with other syscalls, which usually return ESRCH if a given PID refers to a non-existant process.This changes
SO_PEERPIDFDto return ENODATA instead. This is also whatSO_PEERGROUPSreturns, and thus keeps a consistent behavior across sockopts.
Quoted 5 lines
Note that this code is returned in 2 cases: First, if the socket type is not
AF_UNIX, and secondly if the socket was not yet connected. In both cases ENODATA seems suitable.Signed-off-by David Rheinsberg <[email protected]>
Hi David!
I generally agree with this. But just to be more precise, l2cap sockets (AF_BLUETOOTH) also properly
set ->sk_peer_pid and SO_PEERPIDFD will work just fine. This thing is not limited
only to AF_UNIX sockets.
Kind regards,
Alex
Quoted 28 lines
---
Hi!The
SO_PEERPIDFDsockopt has been queued for 6.5, so hopefully we can get that in before the release?Thanks
Davidnet/core/sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)net/core/sock.c +1
-2@@ -1778,7 +1778,7 @@ int sk_getsockopt(struct sock *sk, int level, int optname,spin_unlock (&sk->sk_peer_lock);if (!peer_pid) -return -ESRCH ; +return -ENODATA ; pidfd =pidfd_prepare (peer_pid,0 , &pidfd_file);put_pid (peer_pid); --2.41.0
Quoted 19 lines · David Rheinsberg
Change the new (unreleased)
SO_PEERPIDFDsockopt to return ENODATA rather than ESRCH if a socket type does not support remote peer-PID queries.Currently,
SO_PEERPIDFDreturns ESRCH when the socket in question is not anAF_UNIXsocket. This is quite unexpected, given that one would assume ESRCH means the peer process already exited and thus cannot be found. However, in that case the sockopt actually returns EINVAL (viapidfd_prepare()). This is rather inconsistent with other syscalls, which usually return ESRCH if a given PID refers to a non-existant process.This changes
SO_PEERPIDFDto return ENODATA instead. This is also whatSO_PEERGROUPSreturns, and thus keeps a consistent behavior across sockopts.Note that this code is returned in 2 cases: First, if the socket type is not
AF_UNIX, and secondly if the socket was not yet connected. In both cases ENODATA seems suitable.
Quoted 6 lines
Signed-off-by David Rheinsberg <[email protected]>---
Hi!The
SO_PEERPIDFDsockopt has been queued for 6.5, so hopefully we can get that in before the release?
Shouldn't be an issue afaict.
Looks good to me,
Quoted 24 lines · David Rheinsberg
Change the new (unreleased)
SO_PEERPIDFDsockopt to return ENODATA rather than ESRCH if a socket type does not support remote peer-PID queries.Currently,
SO_PEERPIDFDreturns ESRCH when the socket in question is not anAF_UNIXsocket. This is quite unexpected, given that one would assume ESRCH means the peer process already exited and thus cannot be found. However, in that case the sockopt actually returns EINVAL (viapidfd_prepare()). This is rather inconsistent with other syscalls, which usually return ESRCH if a given PID refers to a non-existant process.This changes
SO_PEERPIDFDto return ENODATA instead. This is also whatSO_PEERGROUPSreturns, and thus keeps a consistent behavior across sockopts.Note that this code is returned in 2 cases: First, if the socket type is not
AF_UNIX, and secondly if the socket was not yet connected. In both cases ENODATA seems suitable.Signed-off-by David Rheinsberg <[email protected]>---
Hi!
Quoted 8 lines
The
SO_PEERPIDFDsockopt has been queued for 6.5, so hopefully we can get that in before the release?Thanks
Davidnet/core/sock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
As one of the first users of this new API, I am fine with this for 6.5, thanks.
Simon Horman
reviewerQuoted 20 lines · David Rheinsberg
Change the new (unreleased)
SO_PEERPIDFDsockopt to return ENODATA rather than ESRCH if a socket type does not support remote peer-PID queries.Currently,
SO_PEERPIDFDreturns ESRCH when the socket in question is not anAF_UNIXsocket. This is quite unexpected, given that one would assume ESRCH means the peer process already exited and thus cannot be found. However, in that case the sockopt actually returns EINVAL (viapidfd_prepare()). This is rather inconsistent with other syscalls, which usually return ESRCH if a given PID refers to a non-existant process.This changes
SO_PEERPIDFDto return ENODATA instead. This is also whatSO_PEERGROUPSreturns, and thus keeps a consistent behavior across sockopts.Note that this code is returned in 2 cases: First, if the socket type is not
AF_UNIX, and secondly if the socket was not yet connected. In both cases ENODATA seems suitable.Signed-off-by David Rheinsberg <[email protected]>
Quoted 8 lines
---
Hi!The
SO_PEERPIDFDsockopt has been queued for 6.5, so hopefully we can get that in before the release?Thanks
David
As a fix, it should probably have a fixes tag.
This one seems appropriate.
And the patch should be targeted at net
Subject: [PATCH net] ...
It's probably not necessary to repost just to address these minor points. But please consider them if you need to post a v2 for some other reason.
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 4 lines · On Mon, 7 Aug 2023 10:12:25 +0200 you wrote:
Change the new (unreleased)
SO_PEERPIDFDsockopt to return ENODATA rather than ESRCH if a socket type does not support remote peer-PID queries.
Quoted 8 lines
Currently,
SO_PEERPIDFDreturns ESRCH when the socket in question is not anAF_UNIXsocket. This is quite unexpected, given that one would assume ESRCH means the peer process already exited and thus cannot be found. However, in that case the sockopt actually returns EINVAL (viapidfd_prepare()). This is rather inconsistent with other syscalls, which usually return ESRCH if a given PID refers to a non-existant process.[...]
Here is the summary with links:
- net/unix: use consistent error code in SO_PEERPIDFD
https://git.kernel.org/netdev/net/c/b6f79e826fbd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html