af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
Subsystems (2)
PATCH v2 1/1 af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
Heiko Carstens reported that SCM_PIDFD does not work with MSG_CMSG_COMPAT because scm_pidfd_recv() always checks msg_controllen against sizeof(struct cmsghdr).
We need to use sizeof(struct compat_cmsghdr) for the compat case.
---
v2:
* Correct len in compat/non-compat case
v1: https://lore.kernel.org/netdev/[email protected]/T/#u
--- include/net/scm.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
include/net/scm.h +9 -5
@@ -9,6 +9,7 @@#include <linux/pid.h> #include <linux/nsproxy.h> #include <linux/sched/signal.h> +#include <net/compat.h> /* Well, we should have at least one descriptor open * to accept passed FDs 8)
@@ -123,14 +124,17 @@ static inline bool scm_has_secdata(struct socket *sock)static __inline__void scm_pidfd_recv (struct msghdr *msg,struct scm_cookie *scm) {struct file *pidfd_file =NULL ; -int pidfd; +int len, pidfd; -/* -* put_cmsg() doesn't return an error if CMSG is truncated, +/* put_cmsg() doesn't return an error if CMSG is truncated, * that's why we need to opencode these checks here. */ -if ((msg->msg_controllen <=sizeof (struct cmsghdr )) || - (msg->msg_controllen -sizeof (struct cmsghdr )) <sizeof (int )) { +if (msg->msg_flags &MSG_CMSG_COMPAT ) + len =sizeof (struct compat_cmsghdr ) +sizeof (int ); +else + len =sizeof (struct cmsghdr ) +sizeof (int ); + +if (msg->msg_controllen < len) { msg->msg_flags |=MSG_CTRUNC ;return ; }
Signature · 1 line
2.30.2
Quoted 46 lines · Kuniyuki Iwashima
Heiko Carstens reported that
SCM_PIDFDdoes not work withMSG_CMSG_COMPATbecausescm_pidfd_recv()always checksmsg_controllenagainst sizeof(struct cmsghdr).We need to use
sizeof(struct compat_cmsghdr)for the compat case.Fixes 5e2ff6704a27 ("scm: add SO_PASSPIDFD and SCM_PIDFD")Reported-by Heiko Carstens <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>Tested-by Heiko Carstens <[email protected]>Reviewed-by Alexander Mikhalitsyn <[email protected]>---
v2:
* Correctlenin compat/non-compat casev1: https://lore.kernel.org/netdev/[email protected]/T/#u
--- include/net/scm.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)include/net/scm.h +3
-4@@ -9,6 +9,7 @@#include <linux/pid.h> #include <linux/nsproxy.h> #include <linux/sched/signal.h> +#include <net/compat.h> /* Well, we should have at least one descriptor open * to accept passed FDs 8) @@ -123,14 +124,17 @@ static inline bool scm_has_secdata(struct socket *sock)static __inline__void scm_pidfd_recv (struct msghdr *msg,struct scm_cookie *scm) {struct file *pidfd_file =NULL ; -int pidfd; +int len, pidfd; -/* -* put_cmsg() doesn't return an error if CMSG is truncated, +/* put_cmsg() doesn't return an error if CMSG is truncated, * that's why we need to opencode these checks here. */ - if ((msg->msg_controllen <= sizeof(struct cmsghdr)) ||
include/net/scm.h static inline bool scm_has_secdata(struct socket *sock) · line 140
Quoted 10 lines
include/net/scm.h +6
-1- (msg->msg_controllen - sizeof(struct cmsghdr)) < sizeof(int)) { +if (msg->msg_flags &MSG_CMSG_COMPAT ) + len =sizeof (struct compat_cmsghdr ) +sizeof (int ); +else + len =sizeof (struct cmsghdr ) +sizeof (int ); + +if (msg->msg_controllen < len) { msg->msg_flags |=MSG_CTRUNC ;return ; }
Seems fine, you can point out in commit message that you are merging both conditions into one (size comparation and this sizeof(int))
Thanks
Quoted 2 lines
Signature · 1 line
2.30.2
Quoted 12 lines · Kuniyuki Iwashima
Heiko Carstens reported that
SCM_PIDFDdoes not work withMSG_CMSG_COMPATbecausescm_pidfd_recv()always checksmsg_controllenagainst sizeof(struct cmsghdr).We need to use
sizeof(struct compat_cmsghdr)for the compat case.Fixes 5e2ff6704a27 ("scm: add SO_PASSPIDFD and SCM_PIDFD")Reported-by Heiko Carstens <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>Tested-by Heiko Carstens <[email protected]>Reviewed-by Alexander Mikhalitsyn <[email protected]>
Quoted 6 lines
---
v2:
* Correctlenin compat/non-compat casev1: https://lore.kernel.org/netdev/[email protected]/T/#u
---
This patch was applied to netdev/net.git (main) by David S. Miller <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <[email protected]>:
Quoted 6 lines · On Fri, 1 Sep 2023 16:46:04 -0700 you wrote:
Heiko Carstens reported that
SCM_PIDFDdoes not work withMSG_CMSG_COMPATbecausescm_pidfd_recv()always checksmsg_controllenagainst sizeof(struct cmsghdr).We need to use
sizeof(struct compat_cmsghdr)for the compat case.
Quoted 8 lines
Fixes 5e2ff6704a27 ("scm: add SO_PASSPIDFD and SCM_PIDFD")Reported-by Heiko Carstens <[email protected]>Signed-off-by Kuniyuki Iwashima <[email protected]>Tested-by Heiko Carstens <[email protected]>Reviewed-by Alexander Mikhalitsyn <[email protected]>[...]
Here is the summary with links:
- [v2,net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
https://git.kernel.org/netdev/net/c/718e6b51298e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html