Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2328936imm; Fri, 7 Sep 2018 14:46:06 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYA0C81oaJl+bFoJPG+kE7LUNJx4IZscrXJN3nuMsrEScqKi6EKHeVQs/5PiGWO//NrOJRR X-Received: by 2002:a17:902:7e06:: with SMTP id b6-v6mr10255974plm.230.1536356766468; Fri, 07 Sep 2018 14:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536356766; cv=none; d=google.com; s=arc-20160816; b=h08tg5WTb8trjpcs3V9pho66iRJrda+85mHYw0CpOAG5yvlNrPUy1JVPtRI6nXaDAJ fe0xc9IhqOYLhb9abhxOVnIBQ7il1qPvLCCRZ2rOGws8eiu+iStQpmVN2knZUXhQzQd9 gbrbMoAP4e/hVrxu3pZgpj7dJWNH3Bdw4rOVHMYcWPzbHbUmr5kumOdMYOfEhxpkKpNj G3S+M4wHo9sgjYVqs92aSrm6cIvRuhxWBIED3ursEnOG9vSm3QAWecKxr7aRZbKcTgqg ENZke3pBbBdy3P73cTzOMF65GRsw/w1qcGQvHHCy0DBxuS+EqOfqNEM+G4NTyz+ZlJ9U LBjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from; bh=npjQsO9aiYg89aIPJoI8STufocCwJZUJ4igqYrAVY/0=; b=k6I8agcB9PVnVyLr335KwFyLJDXqNVTv6cZqzlQVUuNUQMhww1jmoIma7ku/nNq3ih DfZ8CQHF90xddA1RHjQ/UKjv5QUcuRd61fp3h65Nw4YI75CuneVych9fOIDPapPqH/T4 Dq1OIoBHFGx01cH3fP6BvVCnhWe5Sr4+Ek5Hvroj42JjZ1a+CALFria3CTfVH/E844Wk AYFm2kAvq6wEOjQ2gVpYT3TDnsBgNfTYtoW5yycf51HluDR9+b/U5dwtb7J4B96wSF9J VVvkovQNb7NsvwfrDsHBARfe0e8KR2gqX5GVUHFhkpPs198hIhqNox4j7BGwIFZ0VjWb oMRQ== 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 d130-v6si9736378pga.657.2018.09.07.14.45.51; Fri, 07 Sep 2018 14:46:06 -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 S1730937AbeIHC1P (ORCPT + 99 others); Fri, 7 Sep 2018 22:27:15 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57690 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727983AbeIHC1O (ORCPT ); Fri, 7 Sep 2018 22:27:14 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 9A4D31026; Fri, 7 Sep 2018 21:44:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , Christian Brauner , Serge Hallyn , "Eric W. Biederman" Subject: [PATCH 3.18 21/29] userns: move user access out of the mutex Date: Fri, 7 Sep 2018 23:10:42 +0200 Message-Id: <20180907210910.974712079@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180907210909.523240901@linuxfoundation.org> References: <20180907210909.523240901@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.18-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 @@ -602,7 +602,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'; /* * The userns_state_mutex serializes all writes to any given map. @@ -643,17 +652,6 @@ static ssize_t map_write(struct file *fi if (!page) goto out; - /* Only allow < page size writes at the beginning of the file */ - ret = -EINVAL; - if ((*ppos != 0) || (count >= PAGE_SIZE)) - goto out; - - /* Slurp in the user data */ - ret = -EFAULT; - if (copy_from_user(kbuf, buf, count)) - goto out; - kbuf[count] = '\0'; - /* Parse the user data */ ret = -EINVAL; pos = kbuf;