Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1452027imm; Sun, 9 Sep 2018 02:18:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYULtrSqrZaFcSqBZBaEO2JWTS0bV2Kc7tspmTNJmBU4z+djC/juOR2XJaVBq9iENeLN3cs X-Received: by 2002:a63:6fca:: with SMTP id k193-v6mr16366909pgc.360.1536484739829; Sun, 09 Sep 2018 02:18:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536484739; cv=none; d=google.com; s=arc-20160816; b=nJCgtb84m9+0raZo6LkK5l8K8aOFrvO3oPmrO2vHkpoqyy75J3vY+bk4m4vcYR4lOf RXTSKUyeVkVSeCxLwa2yWjpS22xiWUsR0xvN7cVPMg/cxd5Ihx+UYTqCt/o8mAVPUU0s daUlg170a4ioslsNubhwrCKaIKSsAGdtx0NcJakCwUckFjcXXPqPD0fkLwGsqz4H4qqg q0XfsW9MeAKAnluqb4v5Sa8PKwHBiA58Rd72dZJNP3NKJ0DmvTdLhgURqIghcKW559wu QSBcj3mpKPWOtUo6LnoyWcMfBNoIClkM8bdlYXiYJ1hRfhtcpBAkIQ+uX8CrCMjz2CXU OGxw== 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=DdepZOab2DAMfTlftrtONBb6hGJBJ/9IsAOUkr2AB20=; b=TY1HW3dY6TtnIzty84sClMIsLJfQ5DlJym5rN37G6fifZD4c7Bps20N90YRF2+C2EV QvNHCOOKAOrY9qy8dFvU+43JKLQOvqrQbjeMJQEbo0lVNkUFP0ctyMtYpKljV8ZEGHTK 1K/02e5feQSS9YnJLfk5pkAdUst4KFilOMO3DPNKfH3VgAA/xuUIc7I9gkTE9QcZX9/M 8UwCw3SzbgKUR6gxCyONbmr4WSpBczuaZsPbLKLPgbV8fnIBm5TLmAKTcePc0bFO8waz IvRxluHjLSQRSEQRigKQSpvgyAKOZGzsuD/5xOzNFLWbG1g5w62JUcwV8sGEwq+dtnIu ZBcQ== 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 j64-v6si12263319pgd.199.2018.09.09.02.18.31; Sun, 09 Sep 2018 02:18:59 -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 S1726663AbeIIOFi (ORCPT + 99 others); Sun, 9 Sep 2018 10:05:38 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59856 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726609AbeIIOFi (ORCPT ); Sun, 9 Sep 2018 10:05:38 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 6481CAA6; Sun, 9 Sep 2018 09:16:36 +0000 (UTC) Date: Sun, 9 Sep 2018 11:16:33 +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: <20180909091633.GC4195@kroah.com> References: <20180907210904.607934824@linuxfoundation.org> <20180907210908.241189276@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 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. thanks, greg k-h