lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sun, 11 Oct 2009 14:41:15 +0200 (CEST)
From:	John Kacur <jkacur@...hat.com>
To:	Frederic Weisbecker <fweisbec@...il.com>
cc:	Alan Cox <alan@...rguk.ukuu.org.uk>, linux-kernel@...r.kernel.org,
	Thomas Gleixner <tglx@...utronix.de>,
	Jonathan Corbet <corbet@....net>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Christoph Hellwig <hch@...radead.org>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Vincent^M^J Sanders <vince@...tec.co.uk>,
	Ingo Molnar <mingo@...e.hu>
Subject: Re: [PATCH] sound_core.c: Remove BKL from soundcore_open



On Sun, 11 Oct 2009, Frederic Weisbecker wrote:

> On Sun, Oct 11, 2009 at 02:25:53AM +0200, John Kacur wrote:
> > 
> > 
> > On Sun, 11 Oct 2009, Alan Cox wrote:
> > 
> > > On Sun, 11 Oct 2009 01:24:14 +0200 (CEST)
> > > John Kacur <jkacur@...hat.com> wrote:
> > > 
> > > > >From 030af455d4f54482130c8eccb47fe90aaba8808c Mon Sep 17 00:00:00 2001
> > > > From: John Kacur <jkacur@...hat.com>
> > > > Date: Sat, 10 Oct 2009 23:39:56 +0200
> > > > Subject: [PATCH] This code is already protected by spin_lock, and doesn't require the bkl
> > > 
> > > Sorry but I don't think that is true becaue of:
> > > 
> > >            spin_unlock(&sound_loader_lock);
> > >                 if(file->f_op->open)
> > >                         err = file->f_op->open(inode,file);
> > > 
> > > 
> > > So the underlying driver open method expects lock_kernel status and you
> > > don't propogate it down. You really need to track down each thing that
> > > can be called into here and fix it, or maybe just punt for the moment and
> > > push it down to
> > > 
> > > 	{
> > > 		lock_kernel()
> > > 		err = file-f_op->open ...
> > > 		unlock_kernel()
> > > 	}
> > > 
> > > so its obvious to the next person who takes up the war on the BKL what is
> > > to be tackled.
> > > 
> > 
> > Yikes, I missed that. Still I'm loath to just push it down like that. I 
> > wonder if I can use a mutex there. What about the following patch?
> > 
> > From 8b0b91523ee2fcf60ccd82dba44b8da8bad34ce4 Mon Sep 17 00:00:00 2001
> > From: John Kacur <jkacur@...hat.com>
> > Date: Sun, 11 Oct 2009 02:14:44 +0200
> > Subject: [PATCH] Remove the bkl in soundcore_open
> > 
> > Remove the bkl in soundcore_open since it is mostly covered by the sound_loader_lock spin_lock
> > 
> > Protect the underlying driver open method with a mutex.
> > 
> > Signed-off-by: John Kacur <jkacur@...hat.com>
> > ---
> >  sound/sound_core.c |    8 ++++----
> >  1 files changed, 4 insertions(+), 4 deletions(-)
> > 
> > diff --git a/sound/sound_core.c b/sound/sound_core.c
> > index 49c9981..6afb6f1 100644
> > --- a/sound/sound_core.c
> > +++ b/sound/sound_core.c
> > @@ -14,6 +14,8 @@
> >  #include <linux/major.h>
> >  #include <sound/core.h>
> >  
> > +static DEFINE_MUTEX(osc_mutex);
> > +
> >  #ifdef CONFIG_SOUND_OSS_CORE
> >  static int __init init_oss_soundcore(void);
> >  static void cleanup_oss_soundcore(void);
> > @@ -576,8 +578,6 @@ static int soundcore_open(struct inode *inode, struct file *file)
> >  	struct sound_unit *s;
> >  	const struct file_operations *new_fops = NULL;
> >  
> > -	lock_kernel ();
> > -
> >  	chain=unit&0x0F;
> >  	if(chain==4 || chain==5)	/* dsp/audio/dsp16 */
> >  	{
> > @@ -631,17 +631,17 @@ static int soundcore_open(struct inode *inode, struct file *file)
> >  		file->f_op = new_fops;
> >  		spin_unlock(&sound_loader_lock);
> >  		if(file->f_op->open)
> > +			mutex_lock(&osc_mutex);
> >  			err = file->f_op->open(inode,file);
> > +			mutex_unlock(&osc_mutex);
> 
> 
> Yeah that's tempting, but I fear that also means this mutex will
> never be removed....
> 

Sigh... I do see your point - but on the otherhand if measurements don't
show that mutex as being too coarse grained, then is it a problem?

Never-the-less here is version 3 of the patch - like Alan suggested, 
punting, but at least reducing the area covered by the BKL.
>From ac9bdbdd192149e2498b6e16dc71f0a3933e1554 Mon Sep 17 00:00:00 2001
From: John Kacur <jkacur@...hat.com>
Date: Sun, 11 Oct 2009 14:25:46 +0200
Subject: [PATCH] soundcore_open: Reduce the area BKL coverage in this function.

Most of this function is protected by the sound_loader_lock.
We can push down the BKL to this call out err = file->f_op->open(inode,file);

Signed-off-by: John Kacur <jkacur@...hat.com>
---
 sound/sound_core.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/sound/sound_core.c b/sound/sound_core.c
index 49c9981..a7d6956 100644
--- a/sound/sound_core.c
+++ b/sound/sound_core.c
@@ -576,8 +576,6 @@ static int soundcore_open(struct inode *inode, struct file *file)
 	struct sound_unit *s;
 	const struct file_operations *new_fops = NULL;
 
-	lock_kernel ();
-
 	chain=unit&0x0F;
 	if(chain==4 || chain==5)	/* dsp/audio/dsp16 */
 	{
@@ -631,17 +629,17 @@ static int soundcore_open(struct inode *inode, struct file *file)
 		file->f_op = new_fops;
 		spin_unlock(&sound_loader_lock);
 		if(file->f_op->open)
+			lock_kernel();
 			err = file->f_op->open(inode,file);
+			unlock_kernel();
 		if (err) {
 			fops_put(file->f_op);
 			file->f_op = fops_get(old_fops);
 		}
 		fops_put(old_fops);
-		unlock_kernel();
 		return err;
 	}
 	spin_unlock(&sound_loader_lock);
-	unlock_kernel();
 	return -ENODEV;
 }
 
-- 
1.6.0.6


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ