Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2975292imu; Mon, 19 Nov 2018 08:51:45 -0800 (PST) X-Google-Smtp-Source: AJdET5fheRrIDEA6VqJUPQSBTRG+NP3G9cuGrrluMpJIdQlXxkYt2biLx7QkGjbnh3WLwvCMgHuj X-Received: by 2002:a17:902:4025:: with SMTP id b34-v6mr23348134pld.318.1542646305853; Mon, 19 Nov 2018 08:51:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542646305; cv=none; d=google.com; s=arc-20160816; b=BZeIZ8ZP3sO1U+CHb1mZ7mJLUyxtv5Av29grNmMevgj7JJdR7s/FmoUY97E38YzTOR zNiSit+kQXl3NR0yEwTYX4uMvTelDavtpZKxlLxsvpGqYtv6/HMxg2D56k2VcVfJZSBh vka2hzyFfr/wL4W4x/4QYAIZH1SgrN2MuYJFF2AFuxGVUQKD4+/lgpC8rbjK3FjhrNTu bnFFzMKcj+/+gVZyJFEjVPSPQ1x1EurG5PbZuQA7mU4DuxjElY/Iz41XBHo/Z4tosrNo qmq3+ygHfVRyQkq4Etc48BVscyHk0l3sxsXPX+j76eyspH3xIG+rYsHT5FRvRFhWFs3V MYuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=z/Ms8tixlCgJBoVAZPqbP5EMcBxFEoCZRCsxTV0VguY=; b=OD8NkTbCbC8tZu4jnuPCuqn4rUADSyhMz+YeT9bVHhPoX5DMLKnU0tYOUiUwlsPkz2 VIs3a4mRJk/uWoAnmqVDe4+QbZwG00DK/dDT64NG0YG0IKPS+ilf4H2rZN4wNnSmmIIv tmfP45Xg+u7z0ttEzCqT4HBtVooHjJ0B+qslOmKUVyCqpQlrI+UW2OYByK4ShCKIhrRE NdRcr5BYfbeN2PTLMIlPqsglxygLP84dcolMs6fnMFrQ1O5ESpkBhD9YJfEjC3QzBXgA DvoELn0fTPIaTxefNNAqktJ5c4SY3OeufIJVxfdkSxaL6ZHuhRGyMTqkob23+P2elJjY ECLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="ufY/ESbS"; 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 u64si38496965pgd.262.2018.11.19.08.51.30; Mon, 19 Nov 2018 08:51:45 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=default header.b="ufY/ESbS"; 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 S2390091AbeKTDOz (ORCPT + 99 others); Mon, 19 Nov 2018 22:14:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:52352 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388976AbeKTDOy (ORCPT ); Mon, 19 Nov 2018 22:14:54 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ADFA820C01; Mon, 19 Nov 2018 16:50:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1542646241; bh=zj+iYnpA/ndo/eDfJefLKNJ5Ixec5VGQz/tVR9Pjkk8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ufY/ESbS+mDDTY/TWwAIMzwVWaQMroZsLVVo+Rh8z1jgzhyqd4RnAPKJruQOn7z9u wLFIRig0JmXU0ceH0VfF7qHPFDmTpo55XuPyFEyq1EKJNB1GW10IDMH0nc93uirwg/ CyDE35GAsXs/wyoO/CKjGOCB0pDLyyh1BO5S++mI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jonathan Calmels , "Eric W. Biederman" Subject: [PATCH 4.14 091/124] mount: Dont allow copying MNT_UNBINDABLE|MNT_LOCKED mounts Date: Mon, 19 Nov 2018 17:29:05 +0100 Message-Id: <20181119162630.126709341@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181119162612.951907286@linuxfoundation.org> References: <20181119162612.951907286@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric W. Biederman commit df7342b240185d58d3d9665c0bbf0a0f5570ec29 upstream. Jonathan Calmels from NVIDIA reported that he's able to bypass the mount visibility security check in place in the Linux kernel by using a combination of the unbindable property along with the private mount propagation option to allow a unprivileged user to see a path which was purposefully hidden by the root user. Reproducer: # Hide a path to all users using a tmpfs root@castiana:~# mount -t tmpfs tmpfs /sys/devices/ root@castiana:~# # As an unprivileged user, unshare user namespace and mount namespace stgraber@castiana:~$ unshare -U -m -r # Confirm the path is still not accessible root@castiana:~# ls /sys/devices/ # Make /sys recursively unbindable and private root@castiana:~# mount --make-runbindable /sys root@castiana:~# mount --make-private /sys # Recursively bind-mount the rest of /sys over to /mnnt root@castiana:~# mount --rbind /sys/ /mnt # Access our hidden /sys/device as an unprivileged user root@castiana:~# ls /mnt/devices/ breakpoint cpu cstate_core cstate_pkg i915 intel_pt isa kprobe LNXSYSTM:00 msr pci0000:00 platform pnp0 power software system tracepoint uncore_arb uncore_cbox_0 uncore_cbox_1 uprobe virtual Solve this by teaching copy_tree to fail if a mount turns out to be both unbindable and locked. Cc: stable@vger.kernel.org Fixes: 5ff9d8a65ce8 ("vfs: Lock in place mounts from more privileged users") Reported-by: Jonathan Calmels Signed-off-by: "Eric W. Biederman" Signed-off-by: Greg Kroah-Hartman --- fs/namespace.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) --- a/fs/namespace.c +++ b/fs/namespace.c @@ -1814,8 +1814,14 @@ struct mount *copy_tree(struct mount *mn for (s = r; s; s = next_mnt(s, r)) { if (!(flag & CL_COPY_UNBINDABLE) && IS_MNT_UNBINDABLE(s)) { - s = skip_mnt_tree(s); - continue; + if (s->mnt.mnt_flags & MNT_LOCKED) { + /* Both unbindable and locked. */ + q = ERR_PTR(-EPERM); + goto out; + } else { + s = skip_mnt_tree(s); + continue; + } } if (!(flag & CL_COPY_MNT_NS_FILE) && is_mnt_ns_file(s->mnt.mnt_root)) {