Skip to content

Commit 718e6b5

Browse files
q2vendavem330
authored andcommitted
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. Fixes: 5e2ff67 ("scm: add SO_PASSPIDFD and SCM_PIDFD") Reported-by: Heiko Carstens <[email protected]> Closes: https://lore.kernel.org/netdev/[email protected]/ Signed-off-by: Kuniyuki Iwashima <[email protected]> Tested-by: Heiko Carstens <[email protected]> Reviewed-by: Alexander Mikhalitsyn <[email protected]> Reviewed-by: Michal Swiatkowski <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5245008 commit 718e6b5

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

include/net/scm.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/pid.h>
1010
#include <linux/nsproxy.h>
1111
#include <linux/sched/signal.h>
12+
#include <net/compat.h>
1213

1314
/* Well, we should have at least one descriptor open
1415
* to accept passed FDs 8)
@@ -123,14 +124,17 @@ static inline bool scm_has_secdata(struct socket *sock)
123124
static __inline__ void scm_pidfd_recv(struct msghdr *msg, struct scm_cookie *scm)
124125
{
125126
struct file *pidfd_file = NULL;
126-
int pidfd;
127+
int len, pidfd;
127128

128-
/*
129-
* put_cmsg() doesn't return an error if CMSG is truncated,
129+
/* put_cmsg() doesn't return an error if CMSG is truncated,
130130
* that's why we need to opencode these checks here.
131131
*/
132-
if ((msg->msg_controllen <= sizeof(struct cmsghdr)) ||
133-
(msg->msg_controllen - sizeof(struct cmsghdr)) < sizeof(int)) {
132+
if (msg->msg_flags & MSG_CMSG_COMPAT)
133+
len = sizeof(struct compat_cmsghdr) + sizeof(int);
134+
else
135+
len = sizeof(struct cmsghdr) + sizeof(int);
136+
137+
if (msg->msg_controllen < len) {
134138
msg->msg_flags |= MSG_CTRUNC;
135139
return;
136140
}

0 commit comments

Comments
 (0)