Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1460416imm; Sun, 9 Sep 2018 02:31:26 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaYg0l1UwJa/DS3k10R/sqK7jDBV9sM97diC2a7hDumh3K4rf/vkOk65EkfEFzbR5U84qJS X-Received: by 2002:a63:e40d:: with SMTP id a13-v6mr16830027pgi.289.1536485486226; Sun, 09 Sep 2018 02:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536485486; cv=none; d=google.com; s=arc-20160816; b=cGBC/bsNPxe737sRef/jsBwpdsiPncdwGvVffgtYqIPHFmwuftL2lONyAv6CYravc4 PA7WTdWRy0nMPJXhMkRr1uYIRYkQNGHT6H6BUmjY4J1Mfc3Hp2C+jtHnf5sfMJF5UQA8 RQ58ZI0X8wdF00Npl09OlhJVmVdbYPzYSNZyu/02Cry2D3kmdvVfDDq/v+v7eRULwKad eFQFUU+CcfQ+M6Qlbtfj80h4J9Bd4w0pxTI9/gJbId3+/F5/8GcDMhErR2zfhkzTBEtq zUS2Gq11cypbNGIIF1ici46iFEMaJUd/VrB8yJgDfobX0gBsvYJXo2D//v3c/oMNQP1w x3cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=p0B1nCC+JIBaTfDQnVMZvqkJW2B6Zml2q65pQRKEvoA=; b=zuGNOun2GM0hlHkBn2CWIE+9ofOfFG8jJrExhDEIQnOvpA2a2f2wuaJvVh0g2zVxZt 5V4XjXaKcBAo54Sv9eOl04xIGNfsvQbNIS8KmWG9XnDUrn0x7yIIqgMlg7Du3Fz3/FsQ q92yc8mACSkzBQl1XgiYA9UpI7mN2csoLEeYjPVOVCpkxotJ+5VUSWB0YVKJc3Oim0Z2 DFWiXbllwQZ+UdwiTxbfvKsycaoZ3btAdY4P29pyZxCcb9J92JIKLaWjqfIKPlQlHnIM 5qGEcBnLZBImqsXhT4A5FyAHRty3bwve8YBPiT33jvwwNye6Lppw3xoll4XQMXEkkVb6 YNeQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v6-v6si14175605pgj.463.2018.09.09.02.31.03; Sun, 09 Sep 2018 02:31:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726705AbeIIOSZ (ORCPT + 99 others); Sun, 9 Sep 2018 10:18:25 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33250 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726590AbeIIOSZ (ORCPT ); Sun, 9 Sep 2018 10:18:25 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7BD4794B; Sun, 9 Sep 2018 09:29:20 +0000 (UTC) Date: Sun, 9 Sep 2018 11:29:18 +0200 From: Greg KH To: Rafael David Tinoco Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, jannh@google.com, christian@brauner.io, serge@hallyn.com, ebiederm@xmission.com, dan.rue@linaro.org, naresh.kamboju@linaro.org Subject: Re: [PATCH 4.4 34/47] userns: move user access out of the mutex Message-ID: <20180909092918.GB7927@kroah.com> References: <20180907210904.607934824@linuxfoundation.org> <20180907210908.241189276@linuxfoundation.org> <20180909091633.GC4195@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180909091633.GC4195@kroah.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Sep 09, 2018 at 11:16:33AM +0200, Greg KH wrote: > On Sun, Sep 09, 2018 at 12:56:45AM -0300, Rafael David Tinoco wrote: > > Greg, > > > > On Fri, Sep 7, 2018 at 6:41 PM Greg Kroah-Hartman > > wrote: > > > > > > 4.4-stable review patch. If anyone has any objections, please let me know. > > > > > > ------------------ > > > > > > From: Jann Horn > > > > > > commit 5820f140edef111a9ea2ef414ab2428b8cb805b1 upstream. > > > > > > The old code would hold the userns_state_mutex indefinitely if > > > memdup_user_nul stalled due to e.g. a userfault region. Prevent that by > > > moving the memdup_user_nul in front of the mutex_lock(). > > > > > > Note: This changes the error precedence of invalid buf/count/*ppos vs > > > map already written / capabilities missing. > > > > > > Fixes: 22d917d80e84 ("userns: Rework the user_namespace adding uid/gid...") > > > Cc: stable@vger.kernel.org > > > Signed-off-by: Jann Horn > > > Acked-by: Christian Brauner > > > Acked-by: Serge Hallyn > > > Signed-off-by: Eric W. Biederman > > > Signed-off-by: Greg Kroah-Hartman > > > > > > --- > > > kernel/user_namespace.c | 22 ++++++++++------------ > > > 1 file changed, 10 insertions(+), 12 deletions(-) > > > > > > --- a/kernel/user_namespace.c > > > +++ b/kernel/user_namespace.c > > > @@ -604,7 +604,16 @@ static ssize_t map_write(struct file *fi > > > struct uid_gid_extent *extent = NULL; > > > unsigned long page = 0; > > > char *kbuf, *pos, *next_line; > > > - ssize_t ret = -EINVAL; > > > + ssize_t ret; > > > + > > > + /* Only allow < page size writes at the beginning of the file */ > > > + if ((*ppos != 0) || (count >= PAGE_SIZE)) > > > + return -EINVAL; > > > + > > > + /* Slurp in the user data */ > > > + if (copy_from_user(kbuf, buf, count)) > > > + return -EFAULT; > > > + kbuf[count] = '\0'; > > > > Naresh will soon report issues found by LKFT on user_ns for 4.4 kernel > > for this review round. > > > > selftests: mount_run_tests.sh [FAIL] > > write to /proc/self/uid_map failed: Bad address > > > > LTP: user_namespace2 1 TBROK : safe_macros.c:452: userns02.c:95: > > write(6,0x7ffc133113d0,18446744073709551615) failed: errno=EFAULT(14): > > Bad address > > > > I believe the EFAULT was caused because when changing code from > > "memdup_user_nul" to "copy_from_user", for the older kernels, you > > missed allocating the slab object for "kbuf", like memdup_user_nul() > > does. > > > > Note: This likely applies to 3.18 as well. > > > > We are finishing functional tests without this patch, but we wanted to > > make you aware right away. > > Ok, should now be fixed up, thanks for finding this and noticing it. > I've pushed out a -rc3 with the fix. And I've fixed it up in 3.18 as well, pushing out a -rc2 with the fix. thanks, greg k-h