Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2429802ybh; Fri, 24 Jul 2020 12:35:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgIK1JMu/KpuAkd214GmideCSRZQkuYiV9jz6LEH9MElu6SxsLTy9PJ+mQggxSQ0uJsNmn X-Received: by 2002:a17:906:f24c:: with SMTP id gy12mr3874234ejb.275.1595619332765; Fri, 24 Jul 2020 12:35:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595619332; cv=none; d=google.com; s=arc-20160816; b=uBliGwwzWWw566b+Y+sRFrle4RNQHjMS/q2Tv1pxOVaPlnYbYqVII6NZKLLORGnQ/M o6HBaR+/MzbQqZwzJyYPynC4aN2empOgv06pL0F8dv69YiC7CPX9ObimfnLCIAgey2Fz t8WKm1JbW7Aqtj53wmCQfQStG7gs74g0RqYd5u++dBeObRAqnSJ0YKG6e7TFxOGmhI+F BiF2FQp2SZcN5FYddadb3rR6SNSOIYChgZEmVFzufL3kJfE9Vy87OOkrkRDk8kLLMyap O/0p7hp7ngdnoVH8QTBGjs7haKIEhj3pf+TbtQ9xW5Y83DvZsbffKskmASYCT+bFLmX9 u8vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:content-transfer-encoding :mime-version:user-agent:message-id:in-reply-to:date:references:cc :to:from; bh=cUo9ok8oKdSf+lWJ0JjgGIDQTigdgDsLmk80SqhPVk8=; b=xFe3a2PDb7GnZMaL/6AL0PbGpYixLBIKTTizXGKCu7NIdWiKcVjzYqXJzWq06YXtP4 KvdbWw6DsMZHB8hinjLLgauspOd2bRS4qO1Erp3276vZ+lfwFqR+A293/bDemNfsU+l7 5I1AdcfPxLHkKjB7D7dBC+GGdQ7vIPycoPSiZrCXIYtBiSQ+6IfpWrUzI2WZjOF7okqJ H74xfKNQGNZjz/MzsUycXvpnn8AON1hULNAXLwcLAxqEOun0zNvrhmVnsde6OPsLdUVy bn4rRHMfxbRIGZERvJPOzTp7NJ9nFkPs6M91+nidtfAVYKCJ6aqoG/BZ1fME7SoR3BEu gMvw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l17si211685eja.654.2020.07.24.12.35.10; Fri, 24 Jul 2020 12:35:32 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726811AbgGXTe0 convert rfc822-to-8bit (ORCPT + 99 others); Fri, 24 Jul 2020 15:34:26 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:38102 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726085AbgGXTe0 (ORCPT ); Fri, 24 Jul 2020 15:34:26 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jz3SY-0004V4-Rg; Fri, 24 Jul 2020 13:34:22 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jz3SX-0001HJ-4f; Fri, 24 Jul 2020 13:34:22 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Michael Kerrisk (man-pages) Cc: Arnd Bergmann , Alexander Viro , Serge Hallyn , Andrei Vagin , =?utf-8?Q?=C3=81kos?= Uzonyi , Linux FS-devel Mailing List , "linux-kernel\@vger.kernel.org" , "Dmitry V. Levin" References: <20200724001248.GC25522@altlinux.org> <20200724102848.GA1654@altlinux.org> Date: Fri, 24 Jul 2020 14:31:19 -0500 In-Reply-To: <20200724102848.GA1654@altlinux.org> (Dmitry V. Levin's message of "Fri, 24 Jul 2020 13:28:49 +0300") Message-ID: <878sf8ogl4.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT X-XM-SPF: eid=1jz3SX-0001HJ-4f;;;mid=<878sf8ogl4.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/cDxh9ZbG5MfX7w6erKvG5kP72UnbZSUY= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa06.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01,XMSubLong, XM_B_Unicode autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4996] * 0.7 XMSubLong Long Subject * 0.0 XM_B_Unicode BODY: Testing for specific types of unicode * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa06 0; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: ; sa06 0; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Michael Kerrisk (man-pages) X-Spam-Relay-Country: X-Spam-Timing: total 1241 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 11 (0.9%), b_tie_ro: 9 (0.8%), parse: 6 (0.5%), extract_message_metadata: 16 (1.3%), get_uri_detail_list: 2.5 (0.2%), tests_pri_-1000: 6 (0.5%), tests_pri_-950: 1.91 (0.2%), tests_pri_-900: 1.19 (0.1%), tests_pri_-90: 396 (31.9%), check_bayes: 394 (31.7%), b_tokenize: 10 (0.8%), b_tok_get_all: 39 (3.2%), b_comp_prob: 3.8 (0.3%), b_tok_touch_all: 337 (27.1%), b_finish: 1.23 (0.1%), tests_pri_0: 372 (30.0%), check_dkim_signature: 0.73 (0.1%), check_dkim_adsp: 2.4 (0.2%), poll_dns_idle: 407 (32.8%), tests_pri_10: 2.1 (0.2%), tests_pri_500: 423 (34.1%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH] fs/nsfs.c: fix ioctl support of compat processes X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Michael, As the original author of NS_GET_OWNER_UID can you take a look at this? "Dmitry V. Levin" writes: > 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) Thank you, Eric