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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue, 26 Oct 2010 10:09:27 -0400 (EDT)
From:	Alan Stern <stern@...land.harvard.edu>
To:	Michal Nazarewicz <m.nazarewicz@...sung.com>
cc:	Greg Kroah-Hartman <gregkh@...e.de>, <linux-usb@...r.kernel.org>,
	<linux-kernel@...r.kernel.org>,
	Michal Nazarewicz <mina86@...a86.com>
Subject: Re: [PATCH 1/7] USB: gadget: file_storage: put_device() in error
 recovery

On Tue, 26 Oct 2010, Michal Nazarewicz wrote:

> From: Michal Nazarewicz <mina86@...a86.com>
> 
> This commit fixes some issues with File-backed Storage Gadget
> error recovery when registering LUN's devices.
> 
> First of all, when device_register() fails the device still
> needs to be put.  However, because lun_release() decreases
> fsg->ref reference counter the counter must be incremented
> beforehand.

Correct.

> Second of all, after any of the device_create_file()s fails,
> device_unregister() is called which in turn (indirectly) calls
> lun_release() which decrements fsg->ref.  So, again, the
> reference counter must be incremented beforehand.

Correct.

> Lastly, if the first or the second device_create_file()
> succeeds, the files are never removed.  To fix it,
> device_remove_file() needs to be called.  This is done by
> simply marking LUN as registered prior to creating files so
> that fsg_unbind() can handle removing files.

Correct.

> Signed-off-by: Michal Nazarewicz <mina86@...a86.com>
> Reported-by: Rahul Ruikar <rahul.ruikar@...il.com>
> Cc: Alan Stern <stern@...land.harvard.edu>
> ---
>  drivers/usb/gadget/file_storage.c |   20 +++++++++-----------
>  1 files changed, 9 insertions(+), 11 deletions(-)
> 
> Rahul sent an invalid fix for the missing put_device() problem some time
> ago.  This is, I believe, a correct one.  It also fixes the problem with
> device files not being removed (as described in commit message); not sure
> if the latter is a big issue though.
> 
> Hope I'm not late for 37?

No doubt it is too late to get into the merge window.  But it's not
too late for bug fixes to get into 2.6.37 -- there are still eight or
nine -rc's to go.  :-)

> diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
> index d4fdf65..e0504a1 100644
> --- a/drivers/usb/gadget/file_storage.c
> +++ b/drivers/usb/gadget/file_storage.c
> @@ -3392,21 +3392,19 @@ static int __init fsg_bind(struct usb_gadget *gadget)
>  		dev_set_name(&curlun->dev,"%s-lun%d",
>  			     dev_name(&gadget->dev), i);
>  
> -		if ((rc = device_register(&curlun->dev)) != 0) {
> +		kref_get(&fsg->ref);
> +		rc = device_register(&curlun->dev);
> +		if (rc) {
>  			INFO(fsg, "failed to register LUN%d: %d\n", i, rc);
> -			goto out;
> -		}
> -		if ((rc = device_create_file(&curlun->dev,
> -					&dev_attr_ro)) != 0 ||
> -				(rc = device_create_file(&curlun->dev,
> -					&dev_attr_nofua)) != 0 ||
> -				(rc = device_create_file(&curlun->dev,
> -					&dev_attr_file)) != 0) {
> -			device_unregister(&curlun->dev);
> +			put_device(&curlun->dev);
>  			goto out;
>  		}
>  		curlun->registered = 1;
> -		kref_get(&fsg->ref);
> +
> +		if ((rc = device_create_file(&curlun->dev, &dev_attr_ro))  ||
> +		    (rc = device_create_file(&curlun->dev, &dev_attr_nofua)) ||
> +		    (rc = device_create_file(&curlun->dev, &dev_attr_file)))
> +			goto out;

As long as you're changing these anyway, you may as well use the style
most developers seem to prefer:

		rc = device_create_file(&curlun->dev, &dev_attr_ro);
		if (rc)
			goto out;
		...

After all, you did the same thing in the device_register() call above.
Apart from this small matter, ACK.

Alan Stern

--
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