From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: <kuniyu@amazon.com>
Cc: <aleksandr.mikhalitsyn@canonical.com>, <brauner@kernel.org>,
<davem@davemloft.net>, <edumazet@google.com>, <hca@linux.ibm.com>,
<kuba@kernel.org>, <kuni1840@gmail.com>, <netdev@vger.kernel.org>,
<pabeni@redhat.com>
Subject: Re: [PATCH v1 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
Date: Fri, 1 Sep 2023 15:51:47 -0700 [thread overview]
Message-ID: <20230901225147.76613-1-kuniyu@amazon.com> (raw)
In-Reply-To: <20230901222033.71400-1-kuniyu@amazon.com>
From: Kuniyuki Iwashima <kuniyu@amazon.com>
Date: Fri, 1 Sep 2023 15:20:33 -0700
> 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@linux.ibm.com>
> Closes: https://lore.kernel.org/netdev/20230901200517.8742-A-hca@linux.ibm.com/
> Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
> Tested-by: Heiko Carstens <hca@linux.ibm.com>
> Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@canonical.com>
> ---
> include/net/scm.h | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/include/net/scm.h b/include/net/scm.h
> index c5bcdf65f55c..c5608ca03a40 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 cmsghdr) + sizeof(int);
> + else
> + len = sizeof(struct compat_cmsghdr) + sizeof(int);
Ugh.. apparently I did wrong copy-and-paste while refactoring.
Will fix in v2.
pw-bot: cr
> +
> + if (msg->msg_controllen < len) {
> msg->msg_flags |= MSG_CTRUNC;
> return;
> }
> --
> 2.30.2
prev parent reply other threads:[~2023-09-01 22:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-01 22:20 [PATCH v1 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT Kuniyuki Iwashima
2023-09-01 22:51 ` Kuniyuki Iwashima [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230901225147.76613-1-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=aleksandr.mikhalitsyn@canonical.com \
--cc=brauner@kernel.org \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hca@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox