* [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
@ 2023-09-01 23:46 Kuniyuki Iwashima
2023-09-04 5:22 ` Michal Swiatkowski
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Kuniyuki Iwashima @ 2023-09-01 23:46 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: Christian Brauner, Kuniyuki Iwashima, Kuniyuki Iwashima, netdev,
Heiko Carstens, Alexander Mikhalitsyn
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>
---
v2:
* Correct `len` in compat/non-compat case
v1: https://lore.kernel.org/netdev/20230901222033.71400-1-kuniyu@amazon.com/T/#u
---
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..e8c76b4be2fe 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;
}
--
2.30.2
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
2023-09-01 23:46 [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT Kuniyuki Iwashima
@ 2023-09-04 5:22 ` Michal Swiatkowski
2023-09-04 8:27 ` Christian Brauner
2023-09-04 10:12 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Michal Swiatkowski @ 2023-09-04 5:22 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Christian Brauner, Kuniyuki Iwashima, netdev, Heiko Carstens,
Alexander Mikhalitsyn
On Fri, Sep 01, 2023 at 04:46:04PM -0700, Kuniyuki Iwashima wrote:
> 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>
> ---
> v2:
> * Correct `len` in compat/non-compat case
>
> v1: https://lore.kernel.org/netdev/20230901222033.71400-1-kuniyu@amazon.com/T/#u
> ---
> 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..e8c76b4be2fe 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;
> }
Seems fine, you can point out in commit message that you are merging
both conditions into one (size comparation and this sizeof(int))
Reviewed-by: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
Thanks
> --
> 2.30.2
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
2023-09-01 23:46 [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT Kuniyuki Iwashima
2023-09-04 5:22 ` Michal Swiatkowski
@ 2023-09-04 8:27 ` Christian Brauner
2023-09-04 10:12 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2023-09-04 8:27 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Kuniyuki Iwashima, netdev, Heiko Carstens, Alexander Mikhalitsyn
On Fri, Sep 01, 2023 at 04:46:04PM -0700, Kuniyuki Iwashima wrote:
> 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>
> ---
> v2:
> * Correct `len` in compat/non-compat case
>
> v1: https://lore.kernel.org/netdev/20230901222033.71400-1-kuniyu@amazon.com/T/#u
> ---
Acked-by: Christian Brauner <brauner@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.
2023-09-01 23:46 [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT Kuniyuki Iwashima
2023-09-04 5:22 ` Michal Swiatkowski
2023-09-04 8:27 ` Christian Brauner
@ 2023-09-04 10:12 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-09-04 10:12 UTC (permalink / raw)
To: Kuniyuki Iwashima
Cc: davem, edumazet, kuba, pabeni, brauner, kuni1840, netdev, hca,
aleksandr.mikhalitsyn
Hello:
This patch was applied to netdev/net.git (main)
by David S. Miller <davem@davemloft.net>:
On Fri, 1 Sep 2023 16:46:04 -0700 you wrote:
> 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>
>
> [...]
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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-04 10:12 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-01 23:46 [PATCH v2 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT Kuniyuki Iwashima
2023-09-04 5:22 ` Michal Swiatkowski
2023-09-04 8:27 ` Christian Brauner
2023-09-04 10:12 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).