lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Fri, 1 Sep 2023 15:51:47 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <kuniyu@...zon.com>
CC: <aleksandr.mikhalitsyn@...onical.com>, <brauner@...nel.org>,
	<davem@...emloft.net>, <edumazet@...gle.com>, <hca@...ux.ibm.com>,
	<kuba@...nel.org>, <kuni1840@...il.com>, <netdev@...r.kernel.org>,
	<pabeni@...hat.com>
Subject: Re: [PATCH v1 net] af_unix: Fix msg_controllen test in scm_pidfd_recv() for MSG_CMSG_COMPAT.

From: Kuniyuki Iwashima <kuniyu@...zon.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@...ux.ibm.com>
> Closes: https://lore.kernel.org/netdev/20230901200517.8742-A-hca@linux.ibm.com/
> Signed-off-by: Kuniyuki Iwashima <kuniyu@...zon.com>
> Tested-by: Heiko Carstens <hca@...ux.ibm.com>
> Reviewed-by: Alexander Mikhalitsyn <aleksandr.mikhalitsyn@...onical.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ