fs: Support compiling out the pivot_root syscall
cover fs: Support compiling out the pivot_root syscall
From: Brian Ashworth <[email protected]>
This patch series will allow for the pivot_root syscall to be made optional. The first patch refactors the functions that are required by pivot_root so they can be accessed outside of fs/namespace.c. The second patch moves the pivot_root syscall to its own file. The third adds a Kconfig option and conditional compilation to the Makefile.
The pivot_root syscall is not needed on systems that do not use any intermediate filesystem. Allowing for pivot_root to be ommitted from the kernel will aid in the tinification efforts.
Brian Ashworth (3):
Makes functions used by pivot_root accessible
Extracts pivot_root so it can be made optional
Allows for the pivot_root syscall to be omitted
fs/Makefile | 2 + fs/mount.h | 24 +++++++++ fs/namespace.c | 150 +++----------------------------------------------------- fs/pivot_root.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ init/Kconfig | 10 ++++ kernel/sys_ni.c | 1 + 6 files changed, 172 insertions(+), 144 deletions(-) create mode 100644 fs/pivot_root.c
Signature · 1 line
2.11.1
PATCH 1/3 fs: Makes functions used by pivot_root accessible
From: Brian Ashworth <[email protected]>
add/remove: 1/0 grow/shrink: 0/2 up/down: 19/-44 (-25)
function old new delta
detach_mnt - 19 +19 attach_recursive_mnt 349 331 -18 sys_pivot_root 636 610 -26
Total: Before=1899598, After=1899573, chg -0.00%
--- fs/mount.h | 24 ++++++++++++++++++++++++ fs/namespace.c | 27 ++++++--------------------- 2 files changed, 30 insertions(+), 21 deletions(-)
fs/mount.h +24 -0
@@ -3,6 +3,7 @@#include <linux/poll.h> #include <linux/ns_common.h> #include <linux/fs_pin.h> +#include <linux/nsproxy.h> struct mnt_namespace {atomic_t count;
@@ -145,3 +146,26 @@ static inline bool is_local_mountpoint(struct dentry *dentry)return __is_local_mountpoint (dentry); } + +/* +* Is the caller allowed to modify his namespace? +*/ +static inline bool may_mount (void ) +{ +return ns_capable (current->nsproxy->mnt_ns->user_ns,CAP_SYS_ADMIN ); +} + +static inline int check_mnt (struct mount *mnt) +{ +return mnt->mnt_ns == current->nsproxy->mnt_ns; +} + +struct mountpoint *lock_mount (struct path *path); +void unlock_mount (struct mountpoint *where); + +void detach_mnt (struct mount *mnt,struct path *old_path); +void attach_mnt (struct mount *mnt,struct mount *parent,struct mountpoint *mp); + +void touch_mnt_namespace (struct mnt_namespace *ns); + +void put_mountpoint (struct mountpoint *mp);
fs/namespace.c +6 -21
@@ -789,7 +789,7 @@ static struct mountpoint *get_mountpoint(struct dentry *dentry)return mp; } -static void put_mountpoint (struct mountpoint *mp) +void put_mountpoint (struct mountpoint *mp) {if (!--mp->m_count) {struct dentry *dentry = mp->m_dentry;
@@ -802,15 +802,10 @@ static void put_mountpoint(struct mountpoint *mp) } } -static inline int check_mnt (struct mount *mnt) -{ -return mnt->mnt_ns == current->nsproxy->mnt_ns; -} -/* * vfsmount lock must be held for write */ -static void touch_mnt_namespace (struct mnt_namespace *ns) +void touch_mnt_namespace (struct mnt_namespace *ns) {if (ns) { ns->event = ++event;
@@ -846,7 +841,7 @@ static void unhash_mnt(struct mount *mnt)/* * vfsmount lock must be held for write */ -static void detach_mnt (struct mount *mnt,struct path *old_path) +void detach_mnt (struct mount *mnt,struct path *old_path) { old_path->dentry = mnt->mnt_mountpoint; old_path->mnt = &mnt->mnt_parent->mnt;
@@ -881,9 +876,7 @@ void mnt_set_mountpoint(struct mount *mnt,/* * vfsmount lock must be held for write */ -static void attach_mnt (struct mount *mnt, -struct mount *parent, -struct mountpoint *mp) +void attach_mnt (struct mount *mnt,struct mount *parent,struct mountpoint *mp) {mnt_set_mountpoint (parent, mp, mnt);hlist_add_head_rcu (&mnt->mnt_hash,m_hash (&parent->mnt, mp->m_dentry));
@@ -1639,14 +1632,6 @@ void __detach_mounts(struct dentry *dentry)namespace_unlock (); } -/* -* Is the caller allowed to modify his namespace? -*/ -static inline bool may_mount (void ) -{ -return ns_capable (current->nsproxy->mnt_ns->user_ns,CAP_SYS_ADMIN ); -} -static inline bool may_mandlock (void ) {#ifndef CONFIG_MANDATORY_FILE_LOCKING
@@ -2049,7 +2034,7 @@ static int attach_recursive_mnt(struct mount *source_mnt,return err; } -static struct mountpoint *lock_mount (struct path *path) +struct mountpoint *lock_mount (struct path *path) {struct vfsmount *mnt;struct dentry *dentry = path->dentry;
@@ -2078,7 +2063,7 @@ static struct mountpoint *lock_mount(struct path *path) goto retry; } -static void unlock_mount (struct mountpoint *where) +void unlock_mount (struct mountpoint *where) {struct dentry *dentry = where->m_dentry;
Signature · 1 line
2.11.1
PATCH 2/3 fs: Extracts pivot_root so it can be made optional
In reply to [email protected]From: Brian Ashworth <[email protected]>
add/remove: 0/0 grow/shrink: 1/0 up/down: 4/0 (4)
function old new delta sys_pivot_root 610 614 +4
Total: Before=1899573, After=1899577, chg +0.00%
Signed-off-by Brian Ashworth <[email protected]>
--- fs/Makefile | 2 +- fs/namespace.c | 123 ----------------------------------------------------- fs/pivot_root.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 124 deletions(-) create mode 100644 fs/pivot_root.c
fs/Makefile +1 -1
@@ -11,7 +11,7 @@ obj-y := open.o read_write.o file_table.o super.o \ attr.o bad_inode.o file.o filesystems.o namespace.o \ seq_file.o xattr.o libfs.o fs-writeback.o \ pnode.o splice.o sync.o utimes.o \ - stack.o fs_struct.o statfs.o fs_pin.o nsfs.o + stack.o fs_struct.o statfs.o fs_pin.o nsfs.o pivot_root.o ifeq ($(CONFIG_BLOCK),y) obj-y += buffer.o block_dev.o direct-io.o mpage.o
fs/namespace.c +0 -123
129 lines not on this page · raw message
fs/pivot_root.c new file +129 -0
129 lines not on this page · raw message
Signature · 1 line
2.11.1
PATCH 3/3 fs: Allows for the pivot_root syscall to be omitted
In reply to [email protected]From: Brian Ashworth <[email protected]>
The pivot_root syscall is not needed on systems that do not use any intermediate filesystem. Allowing for pivot_root to be ommitted from the kernel will aid in the tinification efforts.
Without CONFIG_PIVOT_ROOT_SYSCALL set add/remove: 0/1 grow/shrink: 0/0 up/down: 0/-614 (-614)
function old new deltasys_pivot_root 614 - -614
Total: Before=1899577, After=1898963, chg -0.03%
--- fs/Makefile | 4 +++- init/Kconfig | 10 ++++++++++ kernel/sys_ni.c | 1 + 3 files changed, 14 insertions(+), 1 deletion(-)
fs/Makefile +3 -1
@@ -11,7 +11,7 @@ obj-y := open.o read_write.o file_table.o super.o \ attr.o bad_inode.o file.o filesystems.o namespace.o \ seq_file.o xattr.o libfs.o fs-writeback.o \ pnode.o splice.o sync.o utimes.o \ - stack.o fs_struct.o statfs.o fs_pin.o nsfs.o pivot_root.o + stack.o fs_struct.o statfs.o fs_pin.o nsfs.o ifeq ($(CONFIG_BLOCK),y) obj-y += buffer.o block_dev.o direct-io.o mpage.o
@@ -19,6 +19,8 @@ else obj-y += no-block.o endif +obj-$(CONFIG_PIVOT_ROOT_SYSCALL) += pivot_root.o + obj-$(CONFIG_PROC_FS) += proc_namespace.o obj-y += notify/
init/Kconfig +10 -0
@@ -1462,6 +1462,16 @@ config SYSCTL_SYSCALL If unsure say N here. +config PIVOT_ROOT_SYSCALL + bool "Pivot_root syscall support" if EXPERT + default y + help + pivot_root is a system call that allows the root to be moved and + replaced by another root. This is needed for intermediate file + systems such as initrd. + + If unsure say Y here. + config POSIX_TIMERS bool "Posix Clocks & timers" if EXPERT default y
kernel/sys_ni.c +1 -0
@@ -178,6 +178,7 @@ cond_syscall(sys_setfsgid);cond_syscall (sys_capget);cond_syscall (sys_capset);cond_syscall (sys_copy_file_range); +cond_syscall (sys_pivot_root);/* arch-specific weak syscall entries */ cond_syscall (sys_pciconfig_read);
Signature · 1 line
2.11.1
Quoted 11 lines · On Fri, 24 Feb 2017, [email protected] wrote:
From: Brian Ashworth <[email protected]>
This patch series will allow for the
pivot_rootsyscall to be made optional. The first patch refactors the functions that are required bypivot_rootso they can be accessed outside offs/namespace.c. The second patch moves thepivot_rootsyscall to its own file. The third adds aKconfigoption and conditional compilation to theMakefile.The
pivot_rootsyscall is not needed on systems that do not use any intermediate filesystem. Allowing forpivot_rootto be ommitted from the kernel will aid in the tinification efforts.
This looks good. Every such tiny bits count, and besides the size reduction possibility this also makes the code clearer.
Quoted 18 lines
Brian Ashworth (3):
Makes functions used bypivot_rootaccessible
Extractspivot_rootso it can be made optional
Allows for thepivot_rootsyscall to be omittedfs/Makefile | 2 + fs/mount.h | 24 +++++++++ fs/namespace.c | 150 +++----------------------------------------------------- fs/pivot_root.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++ init/Kconfig | 10 ++++ kernel/sys_ni.c | 1 + 6 files changed, 172 insertions(+), 144 deletions(-) create mode 100644 fs/pivot_root.cSignature · 1 line
2.11.1
Re: [PATCH 2/3] fs: Extracts pivot_root so it can be made optional
In reply to [email protected]If you're only going to be removing a single function, instead of having to export a bunch of previously-static functions, my preference would be to just insert a pair of #ifdef CONFIG_PIVOT_ROOT_SYSCALL / #endif statements around the function in question.
Is it worth it to save 600-odd bytes? Shrug; but if that's what you are after, I'd suggest doing it the simplest and least-instrusive way possible.
Cheers,
- Ted
Al Viro
maintainerRe: [PATCH 2/3] fs: Extracts pivot_root so it can be made optional
Quoted 4 lines · Theodore Ts'o
If you're only going to be removing a single function, instead of having to export a bunch of previously-static functions, my preference would be to just insert a pair of #ifdef
CONFIG_PIVOT_ROOT_SYSCALL/ #endif statements around the function in question.
Quite. In this form: NAK for the reasons above.
PATCH 1/1 fs: Allows for the pivot_root syscall to be optional
In reply to Brian AshworthThe pivot_root syscall is not needed on systems that do not use any intermediate filesystem. Allowing for pivot_root to be ommitted from the kernel will aid in the tinification efforts.
Without CONFIG_PIVOT_ROOT_SYSCALL set add/remove: 0/2 grow/shrink: 1/0 up/down: 45/-707 (-662)
function old new delta attach_recursive_mnt 349 394 +45
attach_mnt 71 - -71sys_pivot_root 636 - -636
Total: Before=1899893, After=1899231, chg -0.03%
--- fs/namespace.c | 2 ++ init/Kconfig | 10 ++++++++++ kernel/sys_ni.c | 1 + 3 files changed, 13 insertions(+)
fs/namespace.c +2 -0
@@ -3058,6 +3058,7 @@ bool path_is_under(const struct path *path1, const struct path *path2) }EXPORT_SYMBOL (path_is_under); +#ifdef CONFIG_PIVOT_ROOT_SYSCALL /* * pivot_root Semantics: * Moves the root file system of the current process to the directory put_old,
@@ -3180,6 +3181,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, out0: return error; } +#endif /* CONFIG_PIVOT_ROOT_SYSCALL */ static void __init init_mount_tree (void ) {
init/Kconfig +10 -0
@@ -1450,6 +1450,16 @@ config SYSCTL_SYSCALL If unsure say N here. +config PIVOT_ROOT_SYSCALL + bool "Pivot_root syscall support" if EXPERT + default y + help + pivot_root is a system call that allows the root to be moved and + replaced by another root. This is needed for intermediate file + systems such as initrd. + + If unsure say Y here. + config POSIX_TIMERS bool "Posix Clocks & timers" if EXPERT default y
kernel/sys_ni.c +1 -0
@@ -178,6 +178,7 @@ cond_syscall(sys_setfsgid);cond_syscall (sys_capget);cond_syscall (sys_capset);cond_syscall (sys_copy_file_range); +cond_syscall (sys_pivot_root);/* arch-specific weak syscall entries */ cond_syscall (sys_pciconfig_read);
Signature · 1 line
2.11.1
cover fs: Support compiling out the pivot_root syscall
In reply to Al ViroThis patch will allow for the pivot_root syscall to be made optional. Based on feedback, this patch uses an ifdef in the source rather than conditional compilation in the Makefile.
The pivot_root syscall is not needed on systems that do not use any intermediate filesystem. Allowing for pivot_root to be ommitted from the kernel will aid in the tinification efforts.
Brian Ashworth (1):
Allows for the pivot_root syscall to be optional
fs/namespace.c | 2 ++ init/Kconfig | 10 ++++++++++ kernel/sys_ni.c | 1 + 3 files changed, 13 insertions(+)
Signature · 1 line
2.11.1
Re: [PATCH 1/1] fs: Allows for the pivot_root syscall to be optional
In reply to Brian AshworthQuoted 11 lines · Brian Ashworth
The
pivot_rootsyscall is not needed on systems that do not use any intermediate filesystem. Allowing forpivot_rootto be ommitted from the kernel will aid in the tinification efforts.Without
CONFIG_PIVOT_ROOT_SYSCALLset add/remove: 0/2 grow/shrink: 1/0 up/down: 45/-707 (-662)function old new delta attach_recursive_mnt 349 394 +45
attach_mnt71 - -71sys_pivot_root636 - -636
Total: Before=1899893, After=1899231, chg -0.03%
A -0.03% size difference doesn't seem much. To bring up a more realistic scenario for tinification statistics, you could start from "make tinyconfig" instead.
Quoted 6 lines
Signed-off-by Brian Ashworth <[email protected]>--- fs/namespace.c | 2 ++ init/Kconfig | 10 ++++++++++ kernel/sys_ni.c | 1 + 3 files changed, 13 insertions(+)
I agree that this is a much more interesting diffstat than the previous one.
Quoted 57 lines
fs/namespace.c +2
-0@@ -3058,6 +3058,7 @@ bool path_is_under(const struct path *path1, const struct path *path2) }EXPORT_SYMBOL (path_is_under); +#ifdef CONFIG_PIVOT_ROOT_SYSCALL /* * pivot_root Semantics: * Moves the root file system of the current process to the directory put_old, @@ -3180,6 +3181,7 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root, out0: return error; } +#endif /* CONFIG_PIVOT_ROOT_SYSCALL */ static void __init init_mount_tree (void ) {init/Kconfig +10
-0@@ -1450,6 +1450,16 @@ config SYSCTL_SYSCALL If unsure say N here. +config PIVOT_ROOT_SYSCALL + bool "Pivot_root syscall support" if EXPERT + default y + help + pivot_root is a system call that allows the root to be moved and + replaced by another root. This is needed for intermediate file + systems such as initrd. + + If unsure say Y here. + config POSIX_TIMERS bool "Posix Clocks & timers" if EXPERT default ykernel/sys_ni.c +1
-0@@ -178,6 +178,7 @@ cond_syscall(sys_setfsgid);cond_syscall (sys_capget);cond_syscall (sys_capset);cond_syscall (sys_copy_file_range); +cond_syscall (sys_pivot_root);/* arch-specific weak syscall entries */ cond_syscall (sys_pciconfig_read);Signature · 1 line
2.11.1
Re: [PATCH 1/1] fs: Allows for the pivot_root syscall to be optional
Thanks for the ack on this. Whose tree should this patch go through?