aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Layton <jeff.layton@primarydata.com>2015-11-16 09:49:34 -0500
committerJeff Layton <jeff.layton@primarydata.com>2015-11-16 09:49:34 -0500
commit9e8925b67a809bb27ce4b7d352d67f25cf1d7fc5 (patch)
tree3a349e8389f85f87c9c559f5e1860855694e6bae
parent8005c49d9aea74d382f474ce11afbbc7d7130bec (diff)
locks: Allow disabling mandatory locking at compile time
Mandatory locking appears to be almost unused and buggy and there appears no real interest in doing anything with it. Since effectively no one uses the code and since the code is buggy let's allow it to be disabled at compile time. I would just suggest removing the code but undoubtedly that will break some piece of userspace code somewhere. For the distributions that don't care about this piece of code this gives a nice starting point to make mandatory locking go away. Cc: Benjamin Coddington <bcodding@redhat.com> Cc: Dmitry Vyukov <dvyukov@google.com> Cc: Jeff Layton <jeff.layton@primarydata.com> Cc: J. Bruce Fields <bfields@fieldses.org> Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Jeff Layton <jeff.layton@primarydata.com>
-rw-r--r--fs/Kconfig10
-rw-r--r--fs/locks.c2
-rw-r--r--fs/namespace.c10
-rw-r--r--include/linux/fs.h74
4 files changed, 62 insertions, 34 deletions
diff --git a/fs/Kconfig b/fs/Kconfig
index da3f32f1a4e4..59322e6e76f4 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -67,6 +67,16 @@ config FILE_LOCKING
67 for filesystems like NFS and for the flock() system 67 for filesystems like NFS and for the flock() system
68 call. Disabling this option saves about 11k. 68 call. Disabling this option saves about 11k.
69 69
70config MANDATORY_FILE_LOCKING
71 bool "Enable Mandatory file locking"
72 depends on FILE_LOCKING
73 default y
74 help
75 This option enables files appropriately marked files on appropriely
76 mounted filesystems to support mandatory locking.
77
78 To the best of my knowledge this is dead code that no one cares about.
79
70source "fs/notify/Kconfig" 80source "fs/notify/Kconfig"
71 81
72source "fs/quota/Kconfig" 82source "fs/quota/Kconfig"
diff --git a/fs/locks.c b/fs/locks.c
index 0d2b3267e2a3..86c94674ab22 100644
--- a/fs/locks.c
+++ b/fs/locks.c
@@ -1191,6 +1191,7 @@ static int posix_lock_inode_wait(struct inode *inode, struct file_lock *fl)
1191 return error; 1191 return error;
1192} 1192}
1193 1193
1194#ifdef CONFIG_MANDATORY_FILE_LOCKING
1194/** 1195/**
1195 * locks_mandatory_locked - Check for an active lock 1196 * locks_mandatory_locked - Check for an active lock
1196 * @file: the file to check 1197 * @file: the file to check
@@ -1289,6 +1290,7 @@ int locks_mandatory_area(int read_write, struct inode *inode,
1289} 1290}
1290 1291
1291EXPORT_SYMBOL(locks_mandatory_area); 1292EXPORT_SYMBOL(locks_mandatory_area);
1293#endif /* CONFIG_MANDATORY_FILE_LOCKING */
1292 1294
1293static void lease_clear_pending(struct file_lock *fl, int arg) 1295static void lease_clear_pending(struct file_lock *fl, int arg)
1294{ 1296{
diff --git a/fs/namespace.c b/fs/namespace.c
index 0570729c87fd..4219885e9681 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1584,6 +1584,14 @@ static inline bool may_mount(void)
1584 return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN); 1584 return ns_capable(current->nsproxy->mnt_ns->user_ns, CAP_SYS_ADMIN);
1585} 1585}
1586 1586
1587static inline bool may_mandlock(void)
1588{
1589#ifndef CONFIG_MANDATORY_FILE_LOCKING
1590 return false;
1591#endif
1592 return true;
1593}
1594
1587/* 1595/*
1588 * Now umount can handle mount points as well as block devices. 1596 * Now umount can handle mount points as well as block devices.
1589 * This is important for filesystems which use unnamed block devices. 1597 * This is important for filesystems which use unnamed block devices.
@@ -2677,6 +2685,8 @@ long do_mount(const char *dev_name, const char __user *dir_name,
2677 type_page, flags, data_page); 2685 type_page, flags, data_page);
2678 if (!retval && !may_mount()) 2686 if (!retval && !may_mount())
2679 retval = -EPERM; 2687 retval = -EPERM;
2688 if (!retval && (flags & MS_MANDLOCK) && !may_mandlock())
2689 retval = -EPERM;
2680 if (retval) 2690 if (retval)
2681 goto dput_out; 2691 goto dput_out;
2682 2692
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 3aa514254161..cbf08d5c246e 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2030,7 +2030,7 @@ extern struct kobject *fs_kobj;
2030#define FLOCK_VERIFY_READ 1 2030#define FLOCK_VERIFY_READ 1
2031#define FLOCK_VERIFY_WRITE 2 2031#define FLOCK_VERIFY_WRITE 2
2032 2032
2033#ifdef CONFIG_FILE_LOCKING 2033#ifdef CONFIG_MANDATORY_FILE_LOCKING
2034extern int locks_mandatory_locked(struct file *); 2034extern int locks_mandatory_locked(struct file *);
2035extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t); 2035extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
2036 2036
@@ -2075,6 +2075,45 @@ static inline int locks_verify_truncate(struct inode *inode,
2075 return 0; 2075 return 0;
2076} 2076}
2077 2077
2078#else /* !CONFIG_MANDATORY_FILE_LOCKING */
2079
2080static inline int locks_mandatory_locked(struct file *file)
2081{
2082 return 0;
2083}
2084
2085static inline int locks_mandatory_area(int rw, struct inode *inode,
2086 struct file *filp, loff_t offset,
2087 size_t count)
2088{
2089 return 0;
2090}
2091
2092static inline int __mandatory_lock(struct inode *inode)
2093{
2094 return 0;
2095}
2096
2097static inline int mandatory_lock(struct inode *inode)
2098{
2099 return 0;
2100}
2101
2102static inline int locks_verify_locked(struct file *file)
2103{
2104 return 0;
2105}
2106
2107static inline int locks_verify_truncate(struct inode *inode, struct file *filp,
2108 size_t size)
2109{
2110 return 0;
2111}
2112
2113#endif /* CONFIG_MANDATORY_FILE_LOCKING */
2114
2115
2116#ifdef CONFIG_FILE_LOCKING
2078static inline int break_lease(struct inode *inode, unsigned int mode) 2117static inline int break_lease(struct inode *inode, unsigned int mode)
2079{ 2118{
2080 /* 2119 /*
@@ -2136,39 +2175,6 @@ static inline int break_layout(struct inode *inode, bool wait)
2136} 2175}
2137 2176
2138#else /* !CONFIG_FILE_LOCKING */ 2177#else /* !CONFIG_FILE_LOCKING */
2139static inline int locks_mandatory_locked(struct file *file)
2140{
2141 return 0;
2142}
2143
2144static inline int locks_mandatory_area(int rw, struct inode *inode,
2145 struct file *filp, loff_t offset,
2146 size_t count)
2147{
2148 return 0;
2149}
2150
2151static inline int __mandatory_lock(struct inode *inode)
2152{
2153 return 0;
2154}
2155
2156static inline int mandatory_lock(struct inode *inode)
2157{
2158 return 0;
2159}
2160
2161static inline int locks_verify_locked(struct file *file)
2162{
2163 return 0;
2164}
2165
2166static inline int locks_verify_truncate(struct inode *inode, struct file *filp,
2167 size_t size)
2168{
2169 return 0;
2170}
2171
2172static inline int break_lease(struct inode *inode, unsigned int mode) 2178static inline int break_lease(struct inode *inode, unsigned int mode)
2173{ 2179{
2174 return 0; 2180 return 0;