public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Oliver Neukum <oliver@neukum.org>
To: Greg KH <greg@kroah.com>
Cc: linux-usb@vger.kernel.org, Stefan Kopp <stefan_kopp@agilent.com>,
	Marcel Janssen <korgull@home.nl>,
	Felipe Balbi <me@felipebalbi.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] USB: add USB test and measurement class driver
Date: Wed, 27 Aug 2008 10:08:24 +0200	[thread overview]
Message-ID: <200808271008.25779.oliver@neukum.org> (raw)
In-Reply-To: <20080827000501.GA29570@kroah.com>

Am Mittwoch 27 August 2008 02:05:01 schrieb Greg KH:
> +       intf = usb_find_interface(&usbtmc_driver, iminor(inode));
> +       if (!intf) {
> +               printk(KERN_ERR KBUILD_MODNAME
> +                      ": can not find device for minor %d", iminor(inode));
> +               return -ENODEV;
> +       }
> +
> +       data = usb_get_intfdata(intf);
> +       kref_get(&data->kref);
> +
> +       /* Store pointer in file structure's private data field */
> +       filp->private_data = data;
> +
> +       dev = &data->intf->dev;

> +static void usbtmc_delete(struct kref *kref)
> +{
> +       struct usbtmc_device_data *data = to_usbtmc_data(kref);
> +
> +       usb_put_dev(data->usb_dev);
> +       kfree(data->buffer);
> +       kfree(data);
> +}
> +

This is a race condition.

CPU A					CPU B
open()
usb_find_interface()
						disconnect()
						kref_put()
						usbtmc_delete()
						kfree()
kref_get()

You can write to free memory. You must use a static mutex for
mutual exclusion between open() and disconnect()

	Regards
		Oliver


  parent reply	other threads:[~2008-08-27  8:07 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-27  0:05 [PATCH] USB: add USB test and measurement class driver Greg KH
2008-08-27  3:12 ` Greg KH
2008-08-27 16:36   ` Greg KH
2008-08-27  6:22 ` Marcel Janssen
2008-08-27 17:21   ` Greg KH
2008-08-27  8:08 ` Oliver Neukum [this message]
2008-08-27 15:40   ` Greg KH
2008-08-27 16:06   ` Alan Stern
2008-08-27 17:05     ` Oliver Neukum
2008-08-27  8:13 ` Oliver Neukum
2008-08-27 16:08   ` Greg KH
2008-08-27  8:56 ` Oliver Neukum
2008-08-27 15:28   ` Greg KH
2008-08-27 15:44     ` Oliver Neukum
2008-08-27 16:02       ` Greg KH
2008-08-27 16:11   ` Greg KH
2008-08-27 16:15   ` Greg KH

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=200808271008.25779.oliver@neukum.org \
    --to=oliver@neukum.org \
    --cc=greg@kroah.com \
    --cc=korgull@home.nl \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=me@felipebalbi.com \
    --cc=stefan_kopp@agilent.com \
    /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