Skip to content

Commit

Permalink
fs: Limit sys_mount to only request filesystem modules.
Browse files Browse the repository at this point in the history
Modify the request_module to prefix the file system type with "fs-"
and add aliases to all of the filesystems that can be built as modules
to match.

A common practice is to build all of the kernel code and leave code
that is not commonly needed as modules, with the result that many
users are exposed to any bug anywhere in the kernel.

Looking for filesystems with a fs- prefix limits the pool of possible
modules that can be loaded by mount to just filesystems trivially
making things safer with no real cost.

Using aliases means user space can control the policy of which
filesystem modules are auto-loaded by editing /etc/modprobe.d/*.conf
with blacklist and alias directives.  Allowing simple, safe,
well understood work-arounds to known problematic software.

This also addresses a rare but unfortunate problem where the filesystem
name is not the same as it's module name and module auto-loading
would not work.  While writing this patch I saw a handful of such
cases.  The most significant being autofs that lives in the module
autofs4.

This is relevant to user namespaces because we can reach the request
module in get_fs_type() without having any special permissions, and
people get uncomfortable when a user specified string (in this case
the filesystem type) goes all of the way to request_module.

After having looked at this issue I don't think there is any
particular reason to perform any filtering or permission checks beyond
making it clear in the module request that we want a filesystem
module.  The common pattern in the kernel is to call request_module()
without regards to the users permissions.  In general all a filesystem
module does once loaded is call register_filesystem() and go to sleep.
Which means there is not much attack surface exposed by loading a
filesytem module unless the filesystem is mounted.  In a user
namespace filesystems are not mounted unless .fs_flags = FS_USERNS_MOUNT,
which most filesystems do not set today.

Acked-by: Serge Hallyn <[email protected]>
Acked-by: Kees Cook <[email protected]>
Reported-by: Kees Cook <[email protected]>
Signed-off-by: "Eric W. Biederman" <[email protected]>
  • Loading branch information
ebiederm committed Mar 4, 2013
1 parent ba0e342 commit 7f78e03
Show file tree
Hide file tree
Showing 69 changed files with 77 additions and 12 deletions.
1 change: 1 addition & 0 deletions arch/ia64/kernel/perfmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ static struct file_system_type pfm_fs_type = {
.mount = pfmfs_mount,
.kill_sb = kill_anon_super,
};
MODULE_ALIAS_FS("pfmfs");

DEFINE_PER_CPU(unsigned long, pfm_syst_info);
DEFINE_PER_CPU(struct task_struct *, pmu_owner);
Expand Down
1 change: 1 addition & 0 deletions arch/powerpc/platforms/cell/spufs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ static struct file_system_type spufs_type = {
.mount = spufs_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("spufs");

static int __init spufs_init(void)
{
Expand Down
1 change: 1 addition & 0 deletions arch/s390/hypfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ static struct file_system_type hypfs_type = {
.mount = hypfs_mount,
.kill_sb = hypfs_kill_super
};
MODULE_ALIAS_FS("s390_hypfs");

static const struct super_operations hypfs_s_ops = {
.statfs = simple_statfs,
Expand Down
1 change: 1 addition & 0 deletions drivers/firmware/efivars.c
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ static struct file_system_type efivarfs_type = {
.mount = efivarfs_mount,
.kill_sb = efivarfs_kill_sb,
};
MODULE_ALIAS_FS("efivarfs");

/*
* Handle negative dentry.
Expand Down
1 change: 1 addition & 0 deletions drivers/infiniband/hw/ipath/ipath_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ static struct file_system_type ipathfs_fs_type = {
.mount = ipathfs_mount,
.kill_sb = ipathfs_kill_super,
};
MODULE_ALIAS_FS("ipathfs");

int __init ipath_init_ipathfs(void)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/infiniband/hw/qib/qib_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ static struct file_system_type qibfs_fs_type = {
.mount = qibfs_mount,
.kill_sb = qibfs_kill_super,
};
MODULE_ALIAS_FS("ipathfs");

int __init qib_init_qibfs(void)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/misc/ibmasm/ibmasmfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ static struct file_system_type ibmasmfs_type = {
.mount = ibmasmfs_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("ibmasmfs");

static int ibmasmfs_fill_super (struct super_block *sb, void *data, int silent)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/mtd/mtdchar.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,7 @@ static struct file_system_type mtd_inodefs_type = {
.mount = mtd_inodefs_mount,
.kill_sb = kill_anon_super,
};
MODULE_ALIAS_FS("mtd_inodefs");

static int __init init_mtdchar(void)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/oprofile/oprofilefs.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ static struct file_system_type oprofilefs_type = {
.mount = oprofilefs_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("oprofilefs");


int __init oprofilefs_register(void)
Expand Down
1 change: 1 addition & 0 deletions drivers/staging/ccg/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,7 @@ static struct file_system_type ffs_fs_type = {
.mount = ffs_fs_mount,
.kill_sb = ffs_fs_kill_sb,
};
MODULE_ALIAS_FS("functionfs");


/* Driver's main init/cleanup functions *************************************/
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/f_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,7 @@ static struct file_system_type ffs_fs_type = {
.mount = ffs_fs_mount,
.kill_sb = ffs_fs_kill_sb,
};
MODULE_ALIAS_FS("functionfs");


/* Driver's main init/cleanup functions *************************************/
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/gadget/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,7 @@ static struct file_system_type gadgetfs_type = {
.mount = gadgetfs_mount,
.kill_sb = gadgetfs_kill_sb,
};
MODULE_ALIAS_FS("gadgetfs");

/*----------------------------------------------------------------------*/

Expand Down
1 change: 1 addition & 0 deletions drivers/xen/xenfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ static struct file_system_type xenfs_type = {
.mount = xenfs_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("xenfs");

static int __init xenfs_init(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/9p/vfs_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,4 @@ struct file_system_type v9fs_fs_type = {
.owner = THIS_MODULE,
.fs_flags = FS_RENAME_DOES_D_MOVE,
};
MODULE_ALIAS_FS("9p");
1 change: 1 addition & 0 deletions fs/adfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,7 @@ static struct file_system_type adfs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("adfs");

static int __init init_adfs_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/affs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ static struct file_system_type affs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("affs");

static int __init init_affs_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/afs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct file_system_type afs_fs_type = {
.kill_sb = afs_kill_super,
.fs_flags = 0,
};
MODULE_ALIAS_FS("afs");

static const struct super_operations afs_super_ops = {
.statfs = afs_statfs,
Expand Down
1 change: 1 addition & 0 deletions fs/autofs4/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static struct file_system_type autofs_fs_type = {
.mount = autofs_mount,
.kill_sb = autofs4_kill_sb,
};
MODULE_ALIAS_FS("autofs");

static int __init init_autofs4_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/befs/linuxvfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ static struct file_system_type befs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("befs");

static int __init
init_befs_fs(void)
Expand Down
1 change: 1 addition & 0 deletions fs/bfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ static struct file_system_type bfs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("bfs");

static int __init init_bfs_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/binfmt_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ static struct file_system_type bm_fs_type = {
.mount = bm_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("binfmt_misc");

static int __init init_misc_binfmt(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/btrfs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,7 @@ static struct file_system_type btrfs_fs_type = {
.kill_sb = btrfs_kill_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("btrfs");

/*
* used by btrfsctl to scan devices when no FS is mounted
Expand Down
1 change: 1 addition & 0 deletions fs/ceph/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ static struct file_system_type ceph_fs_type = {
.kill_sb = ceph_kill_sb,
.fs_flags = FS_RENAME_DOES_D_MOVE,
};
MODULE_ALIAS_FS("ceph");

#define _STRINGIFY(x) #x
#define STRINGIFY(x) _STRINGIFY(x)
Expand Down
1 change: 1 addition & 0 deletions fs/coda/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,4 +329,5 @@ struct file_system_type coda_fs_type = {
.kill_sb = kill_anon_super,
.fs_flags = FS_BINARY_MOUNTDATA,
};
MODULE_ALIAS_FS("coda");

1 change: 1 addition & 0 deletions fs/configfs/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static struct file_system_type configfs_fs_type = {
.mount = configfs_do_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("configfs");

struct dentry *configfs_pin_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/cramfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,7 @@ static struct file_system_type cramfs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("cramfs");

static int __init init_cramfs_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/debugfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ static struct file_system_type debug_fs_type = {
.mount = debug_mount,
.kill_sb = kill_litter_super,
};
MODULE_ALIAS_FS("debugfs");

static struct dentry *__create_file(const char *name, umode_t mode,
struct dentry *parent, void *data,
Expand Down
1 change: 1 addition & 0 deletions fs/devpts/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ static struct file_system_type devpts_fs_type = {
.fs_flags = FS_USERNS_MOUNT | FS_USERNS_DEV_MOUNT,
#endif
};
MODULE_ALIAS_FS("devpts");

/*
* The normal naming convention is simply /dev/pts/<number>; this conforms
Expand Down
1 change: 1 addition & 0 deletions fs/ecryptfs/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ static struct file_system_type ecryptfs_fs_type = {
.kill_sb = ecryptfs_kill_block_super,
.fs_flags = 0
};
MODULE_ALIAS_FS("ecryptfs");

/**
* inode_info_init_once
Expand Down
1 change: 1 addition & 0 deletions fs/efs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static struct file_system_type efs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("efs");

static struct pt_types sgi_pt_types[] = {
{0x00, "SGI vh"},
Expand Down
1 change: 1 addition & 0 deletions fs/exofs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,7 @@ static struct file_system_type exofs_type = {
.mount = exofs_mount,
.kill_sb = generic_shutdown_super,
};
MODULE_ALIAS_FS("exofs");

static int __init init_exofs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/ext2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,7 @@ static struct file_system_type ext2_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("ext2");

static int __init init_ext2_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/ext3/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -3068,6 +3068,7 @@ static struct file_system_type ext3_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("ext3");

static int __init init_ext3_fs(void)
{
Expand Down
5 changes: 3 additions & 2 deletions fs/ext4/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ static struct file_system_type ext2_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("ext2");
#define IS_EXT2_SB(sb) ((sb)->s_bdev->bd_holder == &ext2_fs_type)
#else
#define IS_EXT2_SB(sb) (0)
Expand All @@ -104,6 +105,7 @@ static struct file_system_type ext3_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("ext3");
#define IS_EXT3_SB(sb) ((sb)->s_bdev->bd_holder == &ext3_fs_type)
#else
#define IS_EXT3_SB(sb) (0)
Expand Down Expand Up @@ -5152,7 +5154,6 @@ static inline int ext2_feature_set_ok(struct super_block *sb)
return 0;
return 1;
}
MODULE_ALIAS("ext2");
#else
static inline void register_as_ext2(void) { }
static inline void unregister_as_ext2(void) { }
Expand Down Expand Up @@ -5185,7 +5186,6 @@ static inline int ext3_feature_set_ok(struct super_block *sb)
return 0;
return 1;
}
MODULE_ALIAS("ext3");
#else
static inline void register_as_ext3(void) { }
static inline void unregister_as_ext3(void) { }
Expand All @@ -5199,6 +5199,7 @@ static struct file_system_type ext4_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("ext4");

static int __init ext4_init_feat_adverts(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/f2fs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ static struct file_system_type f2fs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("f2fs");

static int __init init_inodecache(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/fat/namei_msdos.c
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ static struct file_system_type msdos_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("msdos");

static int __init init_msdos_fs(void)
{
Expand Down
1 change: 1 addition & 0 deletions fs/fat/namei_vfat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,7 @@ static struct file_system_type vfat_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("vfat");

static int __init init_vfat_fs(void)
{
Expand Down
2 changes: 1 addition & 1 deletion fs/filesystems.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ struct file_system_type *get_fs_type(const char *name)
int len = dot ? dot - name : strlen(name);

fs = __get_fs_type(name, len);
if (!fs && (request_module("%.*s", len, name) == 0))
if (!fs && (request_module("fs-%.*s", len, name) == 0))
fs = __get_fs_type(name, len);

if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
Expand Down
2 changes: 1 addition & 1 deletion fs/freevxfs/vxfs_super.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ MODULE_AUTHOR("Christoph Hellwig");
MODULE_DESCRIPTION("Veritas Filesystem (VxFS) driver");
MODULE_LICENSE("Dual BSD/GPL");

MODULE_ALIAS("vxfs"); /* makes mount -t vxfs autoload the module */


static void vxfs_put_super(struct super_block *);
Expand Down Expand Up @@ -258,6 +257,7 @@ static struct file_system_type vxfs_fs_type = {
.kill_sb = kill_block_super,
.fs_flags = FS_REQUIRES_DEV,
};
MODULE_ALIAS_FS("vxfs"); /* makes mount -t vxfs autoload the module */

static int __init
vxfs_init(void)
Expand Down
1 change: 1 addition & 0 deletions fs/fuse/control.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ static struct file_system_type fuse_ctl_fs_type = {
.mount = fuse_ctl_mount,
.kill_sb = fuse_ctl_kill_sb,
};
MODULE_ALIAS_FS("fusectl");

int __init fuse_ctl_init(void)
{
Expand Down
2 changes: 2 additions & 0 deletions fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,7 @@ static struct file_system_type fuse_fs_type = {
.mount = fuse_mount,
.kill_sb = fuse_kill_sb_anon,
};
MODULE_ALIAS_FS("fuse");

#ifdef CONFIG_BLOCK
static struct dentry *fuse_mount_blk(struct file_system_type *fs_type,
Expand Down Expand Up @@ -1146,6 +1147,7 @@ static struct file_system_type fuseblk_fs_type = {
.kill_sb = fuse_kill_sb_blk,
.fs_flags = FS_REQUIRES_DEV | FS_HAS_SUBTYPE,
};
MODULE_ALIAS_FS("fuseblk");

static inline int register_fuseblk(void)
{
Expand Down
4 changes: 3 additions & 1 deletion fs/gfs2/ops_fstype.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <linux/gfs2_ondisk.h>
#include <linux/quotaops.h>
#include <linux/lockdep.h>
#include <linux/module.h>

#include "gfs2.h"
#include "incore.h"
Expand Down Expand Up @@ -1425,11 +1426,12 @@ struct file_system_type gfs2_fs_type = {
.kill_sb = gfs2_kill_sb,
.owner = THIS_MODULE,
};
MODULE_ALIAS_FS("gfs2");

struct file_system_type gfs2meta_fs_type = {
.name = "gfs2meta",
.fs_flags = FS_REQUIRES_DEV,
.mount = gfs2_mount_meta,
.owner = THIS_MODULE,
};

MODULE_ALIAS_FS("gfs2meta");
Loading

0 comments on commit 7f78e03

Please sign in to comment.