mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Duncan Sands <baldrick@free.fr>
To: Oliver Neukum <oliver@neukum.org>, Greg KH <greg@kroah.com>
Cc: linux-usb-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, Frederic Detienne <fd@cisco.com>
Subject: Re: [linux-usb-devel] [PATCH 8/9] USB usbfs: missing lock in proc_getdriver
Date: Wed, 14 Apr 2004 13:37:28 +0200	[thread overview]
Message-ID: <200404141337.28631.baldrick@free.fr> (raw)
In-Reply-To: <200404141304.48641.oliver@neukum.org>

On Wednesday 14 April 2004 13:04, Oliver Neukum wrote:
> > +	down_read(&usb_bus_type.subsys.rwsem);
> > +	if (interface && interface->dev.driver) {
> > +		strncpy(gd.driver, interface->dev.driver->name, sizeof(gd.driver));
> > +		ret = copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0;
> > +	}
> > +	up_read(&usb_bus_type.subsys.rwsem);
> > +	return ret;
>
> IMHO you should drop the lock before you copy to userspace.

Hi Oliver, I wasn't particularly worried about it since it's a rwsem taken for
reading and writing is a rare event.  Do you think it really matters?  If so,
how about this instead (compiles but otherwise untested):

@@ -702,13 +708,15 @@
 		return -EFAULT;
 	if ((ret = findintfif(ps->dev, gd.interface)) < 0)
 		return ret;
+	down_read(&usb_bus_type.subsys.rwsem);
 	interface = ps->dev->actconfig->interface[ret];
-	if (!interface->dev.driver)
+	if (!interface || !interface->dev.driver) {
+		up_read(&usb_bus_type.subsys.rwsem);
 		return -ENODATA;
+	}
 	strncpy(gd.driver, interface->dev.driver->name, sizeof(gd.driver));
-	if (copy_to_user(arg, &gd, sizeof(gd)))
-		return -EFAULT;
-	return 0;
+	up_read(&usb_bus_type.subsys.rwsem);
+	return copy_to_user(arg, &gd, sizeof(gd)) ? -EFAULT : 0;
 }
 
 static int proc_connectinfo(struct dev_state *ps, void __user *arg)

  reply	other threads:[~2004-04-14 11:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-04-14 10:47 Duncan Sands
2004-04-14 11:04 ` [linux-usb-devel] " Oliver Neukum
2004-04-14 11:37   ` Duncan Sands [this message]
2004-04-14 13:29     ` Oliver Neukum
2004-04-14 14:04       ` Duncan Sands

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200404141337.28631.baldrick@free.fr \
    --to=baldrick@free.fr \
    --cc=fd@cisco.com \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb-devel@lists.sourceforge.net \
    --cc=oliver@neukum.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®