Skip to content

Commit b4df2b9

Browse files
author
Alexey Dobriyan
committed
proc: stop using BKL
There are four BKL users in proc: de_put(), proc_lookup_de(), proc_readdir_de(), proc_root_readdir(), 1) de_put() ----------- de_put() is classic atomic_dec_and_test() refcount wrapper -- no BKL needed. BKL doesn't matter to possible refcount leak as well. 2) proc_lookup_de() ------------------- Walking PDE list is protected by proc_subdir_lock(), proc_get_inode() is potentially blocking, all callers of proc_lookup_de() eventually end up from ->lookup hooks which is protected by directory's ->i_mutex -- BKL doesn't protect anything. 3) proc_readdir_de() -------------------- "." and ".." part doesn't need BKL, walking PDE list is under proc_subdir_lock, calling filldir callback is potentially blocking because it writes to luserspace. All proc_readdir_de() callers eventually come from ->readdir hook which is under directory's ->i_mutex -- BKL doesn't protect anything. 4) proc_root_readdir_de() ------------------------- proc_root_readdir_de is ->readdir hook, see (3). Since readdir hooks doesn't use BKL anymore, switch to generic_file_llseek, since it also takes directory's i_mutex. Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
1 parent fe0bdec commit b4df2b9

4 files changed

Lines changed: 4 additions & 17 deletions

File tree

‎fs/proc/generic.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#include <linux/stat.h>
1515
#include <linux/module.h>
1616
#include <linux/mount.h>
17-
#include <linux/smp_lock.h>
1817
#include <linux/init.h>
1918
#include <linux/idr.h>
2019
#include <linux/namei.h>
@@ -379,7 +378,6 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir,
379378
struct inode *inode = NULL;
380379
int error = -ENOENT;
381380

382-
lock_kernel();
383381
spin_lock(&proc_subdir_lock);
384382
for (de = de->subdir; de ; de = de->next) {
385383
if (de->namelen != dentry->d_name.len)
@@ -397,7 +395,6 @@ struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir,
397395
}
398396
spin_unlock(&proc_subdir_lock);
399397
out_unlock:
400-
unlock_kernel();
401398

402399
if (inode) {
403400
dentry->d_op = &proc_dentry_operations;
@@ -432,8 +429,6 @@ int proc_readdir_de(struct proc_dir_entry *de, struct file *filp, void *dirent,
432429
struct inode *inode = filp->f_path.dentry->d_inode;
433430
int ret = 0;
434431

435-
lock_kernel();
436-
437432
ino = inode->i_ino;
438433
i = filp->f_pos;
439434
switch (i) {
@@ -487,7 +482,7 @@ int proc_readdir_de(struct proc_dir_entry *de, struct file *filp, void *dirent,
487482
spin_unlock(&proc_subdir_lock);
488483
}
489484
ret = 1;
490-
out: unlock_kernel();
485+
out:
491486
return ret;
492487
}
493488

@@ -504,6 +499,7 @@ int proc_readdir(struct file *filp, void *dirent, filldir_t filldir)
504499
* the /proc directory.
505500
*/
506501
static const struct file_operations proc_dir_operations = {
502+
.llseek = generic_file_llseek,
507503
.read = generic_read_dir,
508504
.readdir = proc_readdir,
509505
};

‎fs/proc/inode.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,13 @@ struct proc_dir_entry *de_get(struct proc_dir_entry *de)
3535
*/
3636
void de_put(struct proc_dir_entry *de)
3737
{
38-
lock_kernel();
3938
if (!atomic_read(&de->count)) {
4039
printk("de_put: entry %s already free!\n", de->name);
41-
unlock_kernel();
4240
return;
4341
}
4442

4543
if (atomic_dec_and_test(&de->count))
4644
free_proc_entry(de);
47-
unlock_kernel();
4845
}
4946

5047
/*

‎fs/proc/proc_net.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <linux/sched.h>
1919
#include <linux/module.h>
2020
#include <linux/bitops.h>
21-
#include <linux/smp_lock.h>
2221
#include <linux/mount.h>
2322
#include <linux/nsproxy.h>
2423
#include <net/net_namespace.h>
@@ -172,6 +171,7 @@ static int proc_tgid_net_readdir(struct file *filp, void *dirent,
172171
}
173172

174173
const struct file_operations proc_net_operations = {
174+
.llseek = generic_file_llseek,
175175
.read = generic_read_dir,
176176
.readdir = proc_tgid_net_readdir,
177177
};

‎fs/proc/root.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include <linux/sched.h>
1717
#include <linux/module.h>
1818
#include <linux/bitops.h>
19-
#include <linux/smp_lock.h>
2019
#include <linux/mount.h>
2120
#include <linux/pid_namespace.h>
2221

@@ -162,17 +161,12 @@ static int proc_root_readdir(struct file * filp,
162161
unsigned int nr = filp->f_pos;
163162
int ret;
164163

165-
lock_kernel();
166-
167164
if (nr < FIRST_PROCESS_ENTRY) {
168165
int error = proc_readdir(filp, dirent, filldir);
169-
if (error <= 0) {
170-
unlock_kernel();
166+
if (error <= 0)
171167
return error;
172-
}
173168
filp->f_pos = FIRST_PROCESS_ENTRY;
174169
}
175-
unlock_kernel();
176170

177171
ret = proc_pid_readdir(filp, dirent, filldir);
178172
return ret;

0 commit comments

Comments
 (0)