From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org,
"Eric W. Biederman" <ebiederm@xmission.com>
Subject: [PATCH 4.1 08/65] mnt: Refactor the logic for mounting sysfs and proc in a user namespace
Date: Sun, 19 Jul 2015 12:07:27 -0700 [thread overview]
Message-ID: <20150719190809.764074568@linuxfoundation.org> (raw)
In-Reply-To: <20150719190809.469715936@linuxfoundation.org>
4.1-stable review patch. If anyone has any objections, please let me know.
------------------
From: "Eric W. Biederman" <ebiederm@xmission.com>
commit 1b852bceb0d111e510d1a15826ecc4a19358d512 upstream.
Fresh mounts of proc and sysfs are a very special case that works very
much like a bind mount. Unfortunately the current structure can not
preserve the MNT_LOCK... mount flags. Therefore refactor the logic
into a form that can be modified to preserve those lock bits.
Add a new filesystem flag FS_USERNS_VISIBLE that requires some mount
of the filesystem be fully visible in the current mount namespace,
before the filesystem may be mounted.
Move the logic for calling fs_fully_visible from proc and sysfs into
fs/namespace.c where it has greater access to mount namespace state.
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
fs/namespace.c | 8 +++++++-
fs/proc/root.c | 5 +----
fs/sysfs/mount.c | 5 +----
include/linux/fs.h | 2 +-
4 files changed, 10 insertions(+), 10 deletions(-)
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2332,6 +2332,8 @@ unlock:
return err;
}
+static bool fs_fully_visible(struct file_system_type *fs_type);
+
/*
* create a new mount for userspace and request it to be added into the
* namespace's tree
@@ -2363,6 +2365,10 @@ static int do_new_mount(struct path *pat
flags |= MS_NODEV;
mnt_flags |= MNT_NODEV | MNT_LOCK_NODEV;
}
+ if (type->fs_flags & FS_USERNS_VISIBLE) {
+ if (!fs_fully_visible(type))
+ return -EPERM;
+ }
}
mnt = vfs_kern_mount(type, flags, name, data);
@@ -3164,7 +3170,7 @@ bool current_chrooted(void)
return chrooted;
}
-bool fs_fully_visible(struct file_system_type *type)
+static bool fs_fully_visible(struct file_system_type *type)
{
struct mnt_namespace *ns = current->nsproxy->mnt_ns;
struct mount *mnt;
--- a/fs/proc/root.c
+++ b/fs/proc/root.c
@@ -112,9 +112,6 @@ static struct dentry *proc_mount(struct
ns = task_active_pid_ns(current);
options = data;
- if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
- return ERR_PTR(-EPERM);
-
/* Does the mounter have privilege over the pid namespace? */
if (!ns_capable(ns->user_ns, CAP_SYS_ADMIN))
return ERR_PTR(-EPERM);
@@ -159,7 +156,7 @@ static struct file_system_type proc_fs_t
.name = "proc",
.mount = proc_mount,
.kill_sb = proc_kill_sb,
- .fs_flags = FS_USERNS_MOUNT,
+ .fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT,
};
void __init proc_root_init(void)
--- a/fs/sysfs/mount.c
+++ b/fs/sysfs/mount.c
@@ -31,9 +31,6 @@ static struct dentry *sysfs_mount(struct
bool new_sb;
if (!(flags & MS_KERNMOUNT)) {
- if (!capable(CAP_SYS_ADMIN) && !fs_fully_visible(fs_type))
- return ERR_PTR(-EPERM);
-
if (!kobj_ns_current_may_mount(KOBJ_NS_TYPE_NET))
return ERR_PTR(-EPERM);
}
@@ -58,7 +55,7 @@ static struct file_system_type sysfs_fs_
.name = "sysfs",
.mount = sysfs_mount,
.kill_sb = sysfs_kill_sb,
- .fs_flags = FS_USERNS_MOUNT,
+ .fs_flags = FS_USERNS_VISIBLE | FS_USERNS_MOUNT,
};
int __init sysfs_init(void)
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -1897,6 +1897,7 @@ struct file_system_type {
#define FS_HAS_SUBTYPE 4
#define FS_USERNS_MOUNT 8 /* Can be mounted by userns root */
#define FS_USERNS_DEV_MOUNT 16 /* A userns mount does not imply MNT_NODEV */
+#define FS_USERNS_VISIBLE 32 /* FS must already be visible */
#define FS_RENAME_DOES_D_MOVE 32768 /* FS will handle d_move() during rename() internally. */
struct dentry *(*mount) (struct file_system_type *, int,
const char *, void *);
@@ -1984,7 +1985,6 @@ extern int vfs_ustat(dev_t, struct kstat
extern int freeze_super(struct super_block *super);
extern int thaw_super(struct super_block *super);
extern bool our_mnt(struct vfsmount *mnt);
-extern bool fs_fully_visible(struct file_system_type *);
extern int current_umask(void);
next prev parent reply other threads:[~2015-07-19 19:36 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-19 19:07 [PATCH 4.1 00/65] 4.1.3-stable review Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 01/65] fs: Add helper functions for permanently empty directories Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 02/65] sysctl: Allow creating permanently empty directories that serve as mountpoints Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 03/65] proc: Allow creating permanently empty directories that serve as mount points Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 04/65] kernfs: Add support for always empty directories Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 05/65] sysfs: Add support for permanently empty directories to serve as mount points Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 06/65] sysfs: Create mountpoints with sysfs_create_mount_point Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 07/65] mnt: Update fs_fully_visible to test for permanently empty directories Greg Kroah-Hartman
2015-07-19 19:07 ` Greg Kroah-Hartman [this message]
2015-07-19 19:07 ` [PATCH 4.1 09/65] mnt: Modify fs_fully_visible to deal with locked ro nodev and atime Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 10/65] gpio: crystalcove: set IRQCHIP_SKIP_SET_WAKE for the irqchip Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 11/65] gpio: rcar: Check for irq_set_irq_wake() failures Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 12/65] rcu: Correctly handle non-empty Tiny RCU callback list with none ready Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 13/65] ipr: Increase default adapter init stage change timeout Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 14/65] Disable write buffering on Toshiba ToPIC95 Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 15/65] ALSA: pcm: Fix pcm_class sysfs output Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 16/65] ALSA: hda - Fix Dock Headphone on Thinkpad X250 seen as a Line Out Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 17/65] ALSA: hda - set proper caps for newer AMD hda audio in KB/KV Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 18/65] ALSA: hda - Disable widget power-save for VIA codecs Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 19/65] ALSA: hda - restore the MIC FIXUP for some Dell machines Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 20/65] ALSA: hda - Add headset support to Acer Aspire V5 Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 21/65] ALSA: hda - Fix the dock headphone output on Fujitsu Lifebook E780 Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 22/65] ALSA: hda - Add a fixup for Dell E7450 Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 23/65] ACPI / init: Switch over platform to the ACPI mode later Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 24/65] ACPI / PM: Add missing pm_generic_complete() invocation Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 25/65] ACPI / PNP: Avoid conflicting resource reservations Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 26/65] iio: accel: kxcjk-1013: add the "KXCJ9000" ACPI id Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 27/65] tools selftests: Fix clean target with make 3.81 Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 28/65] ARC: add smp barriers around atomics per Documentation/atomic_ops.txt Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 29/65] ARC: add compiler barrier to LLSC based cmpxchg Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 30/65] arc: fix use of uninitialized arc_pmu Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 31/65] power_supply: Fix NULL pointer dereference during bq27x00_battery probe Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 32/65] power_supply: Fix possible NULL pointer dereference on early uevent Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 33/65] mei: me: wait for power gating exit confirmation Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 34/65] mei: txe: reduce suspend/resume time Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 35/65] arm64: Do not attempt to use init_mm in reset_context() Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 36/65] arm64: entry: fix context tracking for el0_sp_pc Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 37/65] arm64: mm: Fix freeing of the wrong memmap entries with !SPARSEMEM_VMEMMAP Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 38/65] arm64: vdso: work-around broken ELF toolchains in Makefile Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 39/65] mm: kmemleak: allow safe memory scanning during kmemleak disabling Greg Kroah-Hartman
2015-07-19 19:07 ` [PATCH 4.1 40/65] mm: kmemleak_alloc_percpu() should follow the gfp from per_alloc() Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 41/65] mm, thp: respect MPOL_PREFERRED policy with non-local node Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 42/65] regmap: Fix regmap_bulk_read in BE mode Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 43/65] regmap: Fix possible shift overflow in regmap_field_init() Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 44/65] regulator: max77686: fix gpio_enabled shift wrapping bug Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 45/65] regulator: core: fix constraints output buffer Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 46/65] livepatch: add module locking around kallsyms calls Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 48/65] spi: orion: Fix maximum baud rates for Armada 370/XP Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 49/65] spi: pl022: Specify num-cs property as required in devicetree binding Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 50/65] scsi_transport_srp: Introduce srp_wait_for_queuecommand() Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 51/65] scsi_transport_srp: Fix a race condition Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 52/65] IB/srp: Remove an extraneous scsi_host_put() from an error path Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 53/65] IB/srp: Fix a connection setup race Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 54/65] IB/srp: Fix connection state tracking Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 55/65] IB/srp: Fix reconnection failure handling Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 56/65] genirq: devres: Fix testing return value of request_any_context_irq() Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 57/65] video: mxsfb: Make sure axi clock is enabled when accessing registers Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 58/65] leds / PM: fix hibernation on arm when gpio-led used with CPU led trigger Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 59/65] mtd: fix: avoid race condition when accessing mtd->usecount Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 61/65] PCI: Propagate the "ignore hotplug" setting to parent Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 62/65] PCI: Add pci_bus_addr_t Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 63/65] PCI: pciehp: Wait for hotplug command completion where necessary Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 64/65] of/pci: Fix pci_address_to_pio() conversion of CPU address to I/O port Greg Kroah-Hartman
2015-07-19 19:08 ` [PATCH 4.1 65/65] Input: pixcir_i2c_ts - fix receive error Greg Kroah-Hartman
2015-07-20 3:19 ` [PATCH 4.1 00/65] 4.1.3-stable review Guenter Roeck
2015-07-20 19:26 ` Greg Kroah-Hartman
2015-07-20 6:33 ` Sudip Mukherjee
2015-07-20 19:27 ` Greg Kroah-Hartman
2015-07-20 17:17 ` Shuah Khan
2015-07-20 19:27 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150719190809.764074568@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=ebiederm@xmission.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).