vfs: Fix crashes when reading /proc/mounts
Jan Kara
reviewerPATCH 1/2 vfs: Provide function to grab superblock reference
In reply to Jan KaraProvide function to hold superblock reference when we are sure the superblock is active. This function will get used by code reading /proc/mounts and friends.
--- fs/internal.h | 1 + fs/super.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+)
fs/internal.h +1 -0
@@ -104,6 +104,7 @@ extern bool trylock_super(struct super_block *sb);extern struct dentry *mount_fs (struct file_system_type *,int ,const char *,void *);extern struct super_block *user_get_super (dev_t ); +extern void hold_sb (struct super_block *sb);/* * open.c
fs/super.c +16 -0
@@ -775,6 +775,22 @@ struct super_block *get_super_exclusive_thawed(struct block_device *bdev) }EXPORT_SYMBOL (get_super_exclusive_thawed); +/** +* hold_sb - get superblock reference for active superblock +* @sb: superblock to get reference for +* +* Get reference to superblock. The caller must make sure the superblock +* is currently active by other means (e.g. holding an active reference +* itself or holding namespace_sem preventing unmount). +*/ +void hold_sb (struct super_block *sb) +{ +spin_lock (&sb_lock); +WARN_ON_ONCE (!atomic_read (&sb->s_active)); + sb->s_count++; +spin_unlock (&sb_lock); +} +/** * get_active_super - get an active reference to the superblock of a device * @bdev: device to get the superblock for
Signature · 1 line
2.16.4
Jan Kara
reviewercover vfs: Fix crashes when reading /proc/mounts
Hello,
this patch series aims at fixing possible races between functions formatting output for /proc/mounts and friends and remount. Especially ->show_options functions of filesystems are not counting with the fact that options can change under them and thus races can result in bogus output or outright crashes (like was the case with ext4 handling of quota mount option, or udf could crash when printing charset name, or xfs when printing log device name etc.).
Admittedly the patch 2/2 is somewhat ugly because namespace_sem ranks below sb->s_umount semaphore but I think it is bearable. Al, what do you think?
Honza
Jan Kara
reviewerPATCH 2/2 proc: Protect readers of /proc/mounts from remount
Readers of /proc/mounts (and similar files) are currently unprotected from concurrently running remount on the filesystem they are reporting. This can not only result in bogus reported information but also in confusion in filesystems ->show_options callbacks resulting in use-after-free issues or similar (for example ext4 handling of quota file names is prone to such races).
Fix the problem by protecting showing of mount information with sb->s_umount semaphore.
--- fs/mount.h | 1 + fs/namespace.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 4 deletions(-)
fs/mount.h +1 -0
@@ -134,6 +134,7 @@ struct proc_mounts {void *cached_mount;u64 cached_event;loff_t cached_index; +struct super_block *locked_sb; };extern const struct seq_operations mounts_op;
fs/namespace.c +55 -4
88 lines not on this page · raw message
Signature · 1 line
2.16.4