Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2059006ybh; Fri, 24 Jul 2020 03:29:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzAAVWi2gY4nJpnuiUnM1f5zleetw8hu9O7SrZR0ycoIUtMy6b2dL+zAssPOb/Zd1Tcnm6 X-Received: by 2002:a17:906:374f:: with SMTP id e15mr1489841ejc.528.1595586566515; Fri, 24 Jul 2020 03:29:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595586566; cv=none; d=google.com; s=arc-20160816; b=e3+8gBmod9RHKgXATd1nKV0Xu2vLXFltpkXOCzlbSLFEmBtWaQ1qvM7DFzNAmgpbun /zGhKqgpvvQCOxDadS9bB4mJ5U9XI34Hoer64wydMNiQvZooVeZKEv98wNqAPJddDern NqFW3q1lZ45tf4J0zEoPaLRcOMXmY9smUN8czZaNAZxfZmovKZbFsGf689xHGpTfxKxf FP+rsQ0lDywog1ZQhaXDKcxo0iaDauZHIJhMlX0VXicp12xRY6FwBlwoLD6iJpzK9WEe uMDcRnLAy7JMkeSixxB9hOWxpM1odWQNbbNhUbRmlY5cPUKHflOPcdCVbqdQ2GnyEXeU 8dWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=6yHwZwP89MlZTsAhz1pFVoRgIm0CIl4OdUaxGMxSBK8=; b=jUuatm4TRCDJ1VTM58hmkkvZRCR/utwP2NyHy8DR3QbfT0NOhCYdcLwPgLX1RXAz1p TZWGTLIn1l5sv8AWtXPu6a0ywVofmaNVmyLxCqec2qqeVs2z3NZtmboJpUdAP4NsGMbG b57JWTyOHuBFkZdwz89mps5mUvf9BXBvXfGmx4QIlA+7IVcX+CO47ekHJaQ0DrqvzSw1 XiM3P+25SsHLl6cJScNTaINLcpiBshpfsvypZ49Nboh15dUtnDFAR4Njw36zAQCIDrAY loo7Iim0XkoktHA+hqhgFCGp2mjWHiTKPa8vWXxhPNBLX3ZM5IuCeQ4+gbcWM0tWFevl ojtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g14si285155edv.102.2020.07.24.03.29.04; Fri, 24 Jul 2020 03:29:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726807AbgGXK2v (ORCPT + 99 others); Fri, 24 Jul 2020 06:28:51 -0400 Received: from vmicros1.altlinux.org ([194.107.17.57]:57836 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726329AbgGXK2v (ORCPT ); Fri, 24 Jul 2020 06:28:51 -0400 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 34A2672CCDC; Fri, 24 Jul 2020 13:28:49 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 279C57CFF79; Fri, 24 Jul 2020 13:28:49 +0300 (MSK) Date: Fri, 24 Jul 2020 13:28:49 +0300 From: "Dmitry V. Levin" To: Arnd Bergmann Cc: Alexander Viro , Serge Hallyn , Andrei Vagin , "Eric W. Biederman" , =?utf-8?B?w4Frb3M=?= Uzonyi , Linux FS-devel Mailing List , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] fs/nsfs.c: fix ioctl support of compat processes Message-ID: <20200724102848.GA1654@altlinux.org> References: <20200724001248.GC25522@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 24, 2020 at 11:20:26AM +0200, Arnd Bergmann wrote: > On Fri, Jul 24, 2020 at 2:12 AM Dmitry V. Levin wrote: > > > > According to Documentation/driver-api/ioctl.rst, in order to support > > 32-bit user space running on a 64-bit kernel, each subsystem or driver > > that implements an ioctl callback handler must also implement the > > corresponding compat_ioctl handler. The compat_ptr_ioctl() helper can > > be used in place of a custom compat_ioctl file operation for drivers > > that only take arguments that are pointers to compatible data > > structures. > > > > In case of NS_* ioctls only NS_GET_OWNER_UID accepts an argument, and > > this argument is a pointer to uid_t type, which is universally defined > > to __kernel_uid32_t. > > This is potentially dangerous to rely on, as there are two parts that > are mismatched: > > - user space does not see the kernel's uid_t definition, but has its own, > which may be either the 16-bit or the 32-bit type. 32-bit uid_t was > introduced with linux-2.3.39 in back in 2000. glibc was already > using 32-bit uid_t at the time in user space, but uclibc only changed > in 2003, and others may have been even later. > > - the ioctl command number is defined (incorrectly) as if there was no > argument, so if there is any user space that happens to be built with > a 16-bit uid_t, this does not get caught. Note that NS_GET_OWNER_UID is provided on 32-bit architectures, too, so this 16-bit vs 32-bit uid_t issue was exposed to userspace long time ago when NS_GET_OWNER_UID was introduced, and making NS_GET_OWNER_UID available for compat processes won't make any difference, as the mismatch is not between native and compat types, but rather between 16-bit and 32-bit uid_t types. I agree it would be correct to define NS_GET_OWNER_UID as _IOR(NSIO, 0x4, uid_t) instead of _IO(NSIO, 0x4), but nobody Cc'ed me on this topic when NS_GET_OWNER_UID was discussed, and that ship has long sailed. > > This change fixes compat strace --pidns-translation. > > > > Note: when backporting this patch to stable kernels, commit > > "compat_ioctl: add compat_ptr_ioctl()" is needed as well. > > > > Reported-by: Ákos Uzonyi > > Fixes: 6786741dbf99 ("nsfs: add ioctl to get an owning user namespace for ns file descriptor") > > Cc: stable@vger.kernel.org # v4.9+ > > Signed-off-by: Dmitry V. Levin > > --- > > fs/nsfs.c | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/fs/nsfs.c b/fs/nsfs.c > > index 800c1d0eb0d0..a00236bffa2c 100644 > > --- a/fs/nsfs.c > > +++ b/fs/nsfs.c > > @@ -21,6 +21,7 @@ static long ns_ioctl(struct file *filp, unsigned int ioctl, > > static const struct file_operations ns_file_operations = { > > .llseek = no_llseek, > > .unlocked_ioctl = ns_ioctl, > > + .compat_ioctl = compat_ptr_ioctl, > > }; > > > > static char *ns_dname(struct dentry *dentry, char *buffer, int buflen) -- ldv