This is a note to let you know that I've just added the patch titled af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT. to the 6.5-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: af_unix-fix-msg_controllen-test-in-scm_pidfd_recv-fo.patch and it can be found in the queue-6.5 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. commit 80c87260ca4afe5783fc347125857c90aa9012ac Author: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx> Date: Fri Sep 1 16:46:04 2023 -0700 af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT. [ Upstream commit 718e6b51298e0f254baca0d40ab52a00e004e014 ] 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. Fixes: 5e2ff6704a27 ("scm: add SO_PASSPIDFD and SCM_PIDFD") Reported-by: Heiko Carstens <hca@xxxxxxxxxxxxx> Closes: https://lore.kernel.org/netdev/20230901200517.8742-A-hca@xxxxxxxxxxxxx/ Signed-off-by: Kuniyuki Iwashima <kuniyu@xxxxxxxxxx> Tested-by: Heiko Carstens <hca@xxxxxxxxxxxxx> Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@xxxxxxxxxxxxx> Reviewed-by: Michal Swiatkowski <michal.swiatkowski@xxxxxxxxxxxxxxx> Acked-by: Christian Brauner <brauner@xxxxxxxxxx> Signed-off-by: David S. Miller <davem@xxxxxxxxxxxxx> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx> diff --git a/include/net/scm.h b/include/net/scm.h index c5bcdf65f55c9..e8c76b4be2fe7 100644 --- a/include/net/scm.h +++ b/include/net/scm.h @@ -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; }