aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2012-12-21 23:38:00 -0500
committerEric W. Biederman <ebiederm@xmission.com>2012-12-25 19:23:12 -0500
commitdfb2ea45becb198beeb75350d0b7b7ad9076a38f (patch)
tree7efa7f2073cf0e0ce085dd78adea855df3033d50 /fs/proc
parentc876ad7682155958d0c9c27afe9017925c230d64 (diff)
proc: Allow proc_free_inum to be called from any context
While testing the pid namespace code I hit this nasty warning. [ 176.262617] ------------[ cut here ]------------ [ 176.263388] WARNING: at /home/eric/projects/linux/linux-userns-devel/kernel/softirq.c:160 local_bh_enable_ip+0x7a/0xa0() [ 176.265145] Hardware name: Bochs [ 176.265677] Modules linked in: [ 176.266341] Pid: 742, comm: bash Not tainted 3.7.0userns+ #18 [ 176.266564] Call Trace: [ 176.266564] [<ffffffff810a539f>] warn_slowpath_common+0x7f/0xc0 [ 176.266564] [<ffffffff810a53fa>] warn_slowpath_null+0x1a/0x20 [ 176.266564] [<ffffffff810ad9ea>] local_bh_enable_ip+0x7a/0xa0 [ 176.266564] [<ffffffff819308c9>] _raw_spin_unlock_bh+0x19/0x20 [ 176.266564] [<ffffffff8123dbda>] proc_free_inum+0x3a/0x50 [ 176.266564] [<ffffffff8111d0dc>] free_pid_ns+0x1c/0x80 [ 176.266564] [<ffffffff8111d195>] put_pid_ns+0x35/0x50 [ 176.266564] [<ffffffff810c608a>] put_pid+0x4a/0x60 [ 176.266564] [<ffffffff8146b177>] tty_ioctl+0x717/0xc10 [ 176.266564] [<ffffffff810aa4d5>] ? wait_consider_task+0x855/0xb90 [ 176.266564] [<ffffffff81086bf9>] ? default_spin_lock_flags+0x9/0x10 [ 176.266564] [<ffffffff810cab0a>] ? remove_wait_queue+0x5a/0x70 [ 176.266564] [<ffffffff811e37e8>] do_vfs_ioctl+0x98/0x550 [ 176.266564] [<ffffffff810b8a0f>] ? recalc_sigpending+0x1f/0x60 [ 176.266564] [<ffffffff810b9127>] ? __set_task_blocked+0x37/0x80 [ 176.266564] [<ffffffff810ab95b>] ? sys_wait4+0xab/0xf0 [ 176.266564] [<ffffffff811e3d31>] sys_ioctl+0x91/0xb0 [ 176.266564] [<ffffffff810a95f0>] ? task_stopped_code+0x50/0x50 [ 176.266564] [<ffffffff81939199>] system_call_fastpath+0x16/0x1b [ 176.266564] ---[ end trace 387af88219ad6143 ]--- It turns out that spin_unlock_bh(proc_inum_lock) is not safe when put_pid is called with another spinlock held and irqs disabled. For now take the easy path and use spin_lock_irqsave(proc_inum_lock) in proc_free_inum and spin_loc_irq in proc_alloc_inum(proc_inum_lock). Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/generic.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index e064f562b1f7..76ddae83daa5 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -352,18 +352,18 @@ retry:
352 if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL)) 352 if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL))
353 return -ENOMEM; 353 return -ENOMEM;
354 354
355 spin_lock_bh(&proc_inum_lock); 355 spin_lock_irq(&proc_inum_lock);
356 error = ida_get_new(&proc_inum_ida, &i); 356 error = ida_get_new(&proc_inum_ida, &i);
357 spin_unlock_bh(&proc_inum_lock); 357 spin_unlock_irq(&proc_inum_lock);
358 if (error == -EAGAIN) 358 if (error == -EAGAIN)
359 goto retry; 359 goto retry;
360 else if (error) 360 else if (error)
361 return error; 361 return error;
362 362
363 if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { 363 if (i > UINT_MAX - PROC_DYNAMIC_FIRST) {
364 spin_lock_bh(&proc_inum_lock); 364 spin_lock_irq(&proc_inum_lock);
365 ida_remove(&proc_inum_ida, i); 365 ida_remove(&proc_inum_ida, i);
366 spin_unlock_bh(&proc_inum_lock); 366 spin_unlock_irq(&proc_inum_lock);
367 return -ENOSPC; 367 return -ENOSPC;
368 } 368 }
369 *inum = PROC_DYNAMIC_FIRST + i; 369 *inum = PROC_DYNAMIC_FIRST + i;
@@ -372,9 +372,10 @@ retry:
372 372
373void proc_free_inum(unsigned int inum) 373void proc_free_inum(unsigned int inum)
374{ 374{
375 spin_lock_bh(&proc_inum_lock); 375 unsigned long flags;
376 spin_lock_irqsave(&proc_inum_lock, flags);
376 ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); 377 ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST);
377 spin_unlock_bh(&proc_inum_lock); 378 spin_unlock_irqrestore(&proc_inum_lock, flags);
378} 379}
379 380
380static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd) 381static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)