History

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull second vfs pile from Al Viro: "The stuff in there: fsfreeze deadlock fixes by Jan (essentially, the deadlock reproduced by xfstests 068), symlink and hardlink restriction patches, plus assorted cleanups and fixes. Note that another fsfreeze deadlock (emergency thaw one) is *not* dealt with - the series by Fernando conflicts a lot with Jan's, breaks userland ABI (FIFREEZE semantics gets changed) and trades the deadlock for massive vfsmount leak; this is going to be handled next cycle. There probably will be another pull request, but that stuff won't be in it." Fix up trivial conflicts due to unrelated changes next to each other in drivers/{staging/gdm72xx/usb_boot.c, usb/gadget/storage_common.c} * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: (54 commits) delousing target_core_file a bit Documentation: Correct s_umount state for freeze_fs/unfreeze_fs fs: Remove old freezing mechanism ext2: Implement freezing btrfs: Convert to new freezing mechanism nilfs2: Convert to new freezing mechanism ntfs: Convert to new freezing mechanism fuse: Convert to new freezing mechanism gfs2: Convert to new freezing mechanism ocfs2: Convert to new freezing mechanism xfs: Convert to new freezing code ext4: Convert to new freezing mechanism fs: Protect write paths by sb_start_write - sb_end_write fs: Skip atime update on frozen filesystem fs: Add freezing handling to mnt_want_write() / mnt_drop_write() fs: Improve filesystem freezing handling switch the protection of percpu_counter list to spinlock nfsd: Push mnt_want_write() outside of i_mutex btrfs: Push mnt_want_write() outside of i_mutex fat: Push mnt_want_write() outside of i_mutex ...

Linus Torvalds committed 14 years ago

Commit a0e881b2 parents eff0d13 dbc6e0284 files · +1326 −639Browse files

Showing the changes to include/linux (6 of 84 files). Show all

Unified · Split

6 files
  1. include/linux/audit.h +4 −0
  2. include/linux/fs.h +142 −12
  3. include/linux/mm.h +1 −0
  4. include/linux/namei.h +1 −0
  5. include/linux/nfsd/nfsfh.h +1 −0
  6. include/linux/pipe_fs_i.h +2 −0
include/linux/audit.h+4−0
@@ -130,6 +130,7 @@ · 129 unmodified lines
130130 #define AUDIT_LAST_KERN_ANOM_MSG 1799
131131 #define AUDIT_ANOM_PROMISCUOUS 1700 /* Device changed promiscuous mode */
132132 #define AUDIT_ANOM_ABEND 1701 /* Process ended abnormally */
133+#define AUDIT_ANOM_LINK 1702 /* Suspicious use of file links */
133134 #define AUDIT_INTEGRITY_DATA 1800 /* Data integrity verification */
134135 #define AUDIT_INTEGRITY_METADATA 1801 /* Metadata integrity verification */
135136 #define AUDIT_INTEGRITY_STATUS 1802 /* Integrity enable status */
@@ -687,6 +688,8 @@ extern void audit_log_d_path(struct audit_buffer *ab, · 551 unmodified lines
687688 const struct path *path);
688689 extern void audit_log_key(struct audit_buffer *ab,
689690 char *key);
691+extern void audit_log_link_denied(const char *operation,
692+ struct path *link);
690693 extern void audit_log_lost(const char *message);
691694 #ifdef CONFIG_SECURITY
692695 extern void audit_log_secctx(struct audit_buffer *ab, u32 secid);
@@ -716,6 +719,7 @@ extern int audit_enabled; · 23 unmodified lines
716719 #define audit_log_untrustedstring(a,s) do { ; } while (0)
717720 #define audit_log_d_path(b, p, d) do { ; } while (0)
718721 #define audit_log_key(b, k) do { ; } while (0)
722+#define audit_log_link_denied(o, l) do { ; } while (0)
719723 #define audit_log_secctx(b,s) do { ; } while (0)
720724 #define audit_enabled 0
721725 #endif
include/linux/fs.h+142−12
@@ -414,6 +414,7 @@ struct inodes_stat_t { · 413 unmodified lines
414414 #include <linux/shrinker.h>
415415 #include <linux/migrate_mode.h>
416416 #include <linux/uidgid.h>
417+#include <linux/lockdep.h>
417418
418419 #include <asm/byteorder.h>
419420
@@ -440,6 +441,8 @@ extern unsigned long get_max_files(void); · 20 unmodified lines
440441 extern int sysctl_nr_open;
441442 extern struct inodes_stat_t inodes_stat;
442443 extern int leases_enable, lease_break_time;
444+extern int sysctl_protected_symlinks;
445+extern int sysctl_protected_hardlinks;
443446
444447 struct buffer_head;
445448 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
@@ -1445,6 +1448,8 @@ extern void f_delown(struct file *filp); · 999 unmodified lines
14451448 extern pid_t f_getown(struct file *filp);
14461449 extern int send_sigurg(struct fown_struct *fown);
14471450
1451+struct mm_struct;
1452+
14481453 /*
14491454 * Umount options
14501455 */
@@ -1458,6 +1463,31 @@ extern int send_sigurg(struct fown_struct *fown); · 7 unmodified lines
14581463 extern struct list_head super_blocks;
14591464 extern spinlock_t sb_lock;
14601465
1466+/* Possible states of 'frozen' field */
1467+enum {
1468+ SB_UNFROZEN = 0, /* FS is unfrozen */
1469+ SB_FREEZE_WRITE = 1, /* Writes, dir ops, ioctls frozen */
1470+ SB_FREEZE_PAGEFAULT = 2, /* Page faults stopped as well */
1471+ SB_FREEZE_FS = 3, /* For internal FS use (e.g. to stop
1472+ * internal threads if needed) */
1473+ SB_FREEZE_COMPLETE = 4, /* ->freeze_fs finished successfully */
1474+};
1475+
1476+#define SB_FREEZE_LEVELS (SB_FREEZE_COMPLETE - 1)
1477+
1478+struct sb_writers {
1479+ /* Counters for counting writers at each level */
1480+ struct percpu_counter counter[SB_FREEZE_LEVELS];
1481+ wait_queue_head_t wait; /* queue for waiting for
1482+ writers / faults to finish */
1483+ int frozen; /* Is sb frozen? */
1484+ wait_queue_head_t wait_unfrozen; /* queue for waiting for
1485+ sb to be thawed */
1486+#ifdef CONFIG_DEBUG_LOCK_ALLOC
1487+ struct lockdep_map lock_map[SB_FREEZE_LEVELS];
1488+#endif
1489+};
1490+
14611491 struct super_block {
14621492 struct list_head s_list; /* Keep this first */
14631493 dev_t s_dev; /* search index; _not_ kdev_t */
@@ -1505,8 +1535,7 @@ struct super_block { · 41 unmodified lines
15051535 struct hlist_node s_instances;
15061536 struct quota_info s_dquot; /* Diskquota specific options */
15071537
1508− int s_frozen;
1509− wait_queue_head_t s_wait_unfrozen;
1538+ struct sb_writers s_writers;
15101539
15111540 char s_id[32]; /* Informational name */
15121541 u8 s_uuid[16]; /* UUID */
@@ -1561,14 +1590,117 @@ extern struct timespec current_fs_time(struct super_block *sb); · 48 unmodified lines
15611590 /*
15621591 * Snapshotting support.
15631592 */
1564−enum {
1565− SB_UNFROZEN = 0,
1566− SB_FREEZE_WRITE = 1,
1567− SB_FREEZE_TRANS = 2,
1568−};
15691593
1570−#define vfs_check_frozen(sb, level) \
1571− wait_event((sb)->s_wait_unfrozen, ((sb)->s_frozen < (level)))
1594+void __sb_end_write(struct super_block *sb, int level);
1595+int __sb_start_write(struct super_block *sb, int level, bool wait);
1596+
1597+/**
1598+ * sb_end_write - drop write access to a superblock
1599+ * @sb: the super we wrote to
1600+ *
1601+ * Decrement number of writers to the filesystem. Wake up possible waiters
1602+ * wanting to freeze the filesystem.
1603+ */
1604+static inline void sb_end_write(struct super_block *sb)
1605+{
1606+ __sb_end_write(sb, SB_FREEZE_WRITE);
1607+}
1608+
1609+/**
1610+ * sb_end_pagefault - drop write access to a superblock from a page fault
1611+ * @sb: the super we wrote to
1612+ *
1613+ * Decrement number of processes handling write page fault to the filesystem.
1614+ * Wake up possible waiters wanting to freeze the filesystem.
1615+ */
1616+static inline void sb_end_pagefault(struct super_block *sb)
1617+{
1618+ __sb_end_write(sb, SB_FREEZE_PAGEFAULT);
1619+}
1620+
1621+/**
1622+ * sb_end_intwrite - drop write access to a superblock for internal fs purposes
1623+ * @sb: the super we wrote to
1624+ *
1625+ * Decrement fs-internal number of writers to the filesystem. Wake up possible
1626+ * waiters wanting to freeze the filesystem.
1627+ */
1628+static inline void sb_end_intwrite(struct super_block *sb)
1629+{
1630+ __sb_end_write(sb, SB_FREEZE_FS);
1631+}
1632+
1633+/**
1634+ * sb_start_write - get write access to a superblock
1635+ * @sb: the super we write to
1636+ *
1637+ * When a process wants to write data or metadata to a file system (i.e. dirty
1638+ * a page or an inode), it should embed the operation in a sb_start_write() -
1639+ * sb_end_write() pair to get exclusion against file system freezing. This
1640+ * function increments number of writers preventing freezing. If the file
1641+ * system is already frozen, the function waits until the file system is
1642+ * thawed.
1643+ *
1644+ * Since freeze protection behaves as a lock, users have to preserve
1645+ * ordering of freeze protection and other filesystem locks. Generally,
1646+ * freeze protection should be the outermost lock. In particular, we have:
1647+ *
1648+ * sb_start_write
1649+ * -> i_mutex (write path, truncate, directory ops, ...)
1650+ * -> s_umount (freeze_super, thaw_super)
1651+ */
1652+static inline void sb_start_write(struct super_block *sb)
1653+{
1654+ __sb_start_write(sb, SB_FREEZE_WRITE, true);
1655+}
1656+
1657+static inline int sb_start_write_trylock(struct super_block *sb)
1658+{
1659+ return __sb_start_write(sb, SB_FREEZE_WRITE, false);
1660+}
1661+
1662+/**
1663+ * sb_start_pagefault - get write access to a superblock from a page fault
1664+ * @sb: the super we write to
1665+ *
1666+ * When a process starts handling write page fault, it should embed the
1667+ * operation into sb_start_pagefault() - sb_end_pagefault() pair to get
1668+ * exclusion against file system freezing. This is needed since the page fault
1669+ * is going to dirty a page. This function increments number of running page
1670+ * faults preventing freezing. If the file system is already frozen, the
1671+ * function waits until the file system is thawed.
1672+ *
1673+ * Since page fault freeze protection behaves as a lock, users have to preserve
1674+ * ordering of freeze protection and other filesystem locks. It is advised to
1675+ * put sb_start_pagefault() close to mmap_sem in lock ordering. Page fault
1676+ * handling code implies lock dependency:
1677+ *
1678+ * mmap_sem
1679+ * -> sb_start_pagefault
1680+ */
1681+static inline void sb_start_pagefault(struct super_block *sb)
1682+{
1683+ __sb_start_write(sb, SB_FREEZE_PAGEFAULT, true);
1684+}
1685+
1686+/*
1687+ * sb_start_intwrite - get write access to a superblock for internal fs purposes
1688+ * @sb: the super we write to
1689+ *
1690+ * This is the third level of protection against filesystem freezing. It is
1691+ * free for use by a filesystem. The only requirement is that it must rank
1692+ * below sb_start_pagefault.
1693+ *
1694+ * For example filesystem can call sb_start_intwrite() when starting a
1695+ * transaction which somewhat eases handling of freezing for internal sources
1696+ * of filesystem changes (internal fs threads, discarding preallocation on file
1697+ * close, etc.).
1698+ */
1699+static inline void sb_start_intwrite(struct super_block *sb)
1700+{
1701+ __sb_start_write(sb, SB_FREEZE_FS, true);
1702+}
1703+
15721704
15731705 extern bool inode_owner_or_capable(const struct inode *inode);
15741706
@@ -1892,6 +2024,7 @@ struct file_system_type { · 317 unmodified lines
18922024 struct lock_class_key s_lock_key;
18932025 struct lock_class_key s_umount_key;
18942026 struct lock_class_key s_vfs_rename_key;
2027+ struct lock_class_key s_writers_key[SB_FREEZE_LEVELS];
18952028
18962029 struct lock_class_key i_lock_key;
18972030 struct lock_class_key i_mutex_key;
@@ -2334,9 +2467,6 @@ static inline void i_readcount_inc(struct inode *inode) · 436 unmodified lines
23342467 }
23352468 #endif
23362469 extern int do_pipe_flags(int *, int);
2337−extern struct file *create_read_pipe(struct file *f, int flags);
2338−extern struct file *create_write_pipe(int flags);
2339−extern void free_write_pipe(struct file *);
23402470
23412471 extern int kernel_read(struct file *, loff_t, char *, unsigned long);
23422472 extern struct file * open_exec(const char *);
include/linux/mm.h+1−0
@@ -1441,6 +1441,7 @@ extern void truncate_inode_pages_range(struct address_space *, · 1440 unmodified lines
14411441
14421442 /* generic vm_area_ops exported for stackable file systems */
14431443 extern int filemap_fault(struct vm_area_struct *, struct vm_fault *);
1444+extern int filemap_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
14441445
14451446 /* mm/page-writeback.c */
14461447 int write_one_page(struct page *page, int wait);
include/linux/namei.h+1−0
@@ -67,6 +67,7 @@ extern int kern_path(const char *, unsigned, struct path *); · 66 unmodified lines
6767
6868 extern struct dentry *kern_path_create(int, const char *, struct path *, int);
6969 extern struct dentry *user_path_create(int, const char __user *, struct path *, int);
70+extern void done_path_create(struct path *, struct dentry *);
7071 extern struct dentry *kern_path_locked(const char *, struct path *);
7172 extern int vfs_path_lookup(struct dentry *, struct vfsmount *,
7273 const char *, unsigned int, struct path *);
include/linux/nfsd/nfsfh.h+1−0
@@ -143,6 +143,7 @@ typedef struct svc_fh { · 142 unmodified lines
143143 int fh_maxsize; /* max size for fh_handle */
144144
145145 unsigned char fh_locked; /* inode locked by us */
146+ unsigned char fh_want_write; /* remount protection taken */
146147
147148 #ifdef CONFIG_NFSD_V3
148149 unsigned char fh_post_saved; /* post-op attrs saved */
include/linux/pipe_fs_i.h+2−0
@@ -160,4 +160,6 @@ void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *); · 159 unmodified lines
160160 long pipe_fcntl(struct file *, unsigned int, unsigned long arg);
161161 struct pipe_inode_info *get_pipe_info(struct file *file);
162162
163+int create_pipe_files(struct file **, int);
164+
163165 #endif