All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: cdc-acm: fix minor-number release
@ 2021-09-06 12:43 Johan Hovold
  2021-09-06 13:02 ` Oliver Neukum
  0 siblings, 1 reply; 3+ messages in thread
From: Johan Hovold @ 2021-09-06 12:43 UTC (permalink / raw)
  To: Oliver Neukum, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Johan Hovold, stable, Jaejoong Kim

If the driver runs out of minor numbers it would release minor 0 and
allow another device to claim the minor while still in use.

Fortunately, registering the tty class device of the second device would
fail (with a stack dump) due to the sysfs name collision so no memory is
leaked.

Fixes: cae2bc768d17 ("usb: cdc-acm: Decrement tty port's refcount if probe() fail")
Cc: stable@vger.kernel.org      # 4.19
Cc: Jaejoong Kim <climbbb.kim@gmail.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/class/cdc-acm.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 4895325b16a4..5f0260bc4469 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -726,7 +726,8 @@ static void acm_port_destruct(struct tty_port *port)
 {
 	struct acm *acm = container_of(port, struct acm, port);
 
-	acm_release_minor(acm);
+	if (acm->minor != ACM_TTY_MINORS)
+		acm_release_minor(acm);
 	usb_put_intf(acm->control);
 	kfree(acm->country_codes);
 	kfree(acm);
@@ -1323,8 +1324,10 @@ static int acm_probe(struct usb_interface *intf,
 	usb_get_intf(acm->control); /* undone in destruct() */
 
 	minor = acm_alloc_minor(acm);
-	if (minor < 0)
+	if (minor < 0) {
+		acm->minor = ACM_TTY_MINORS;
 		goto err_put_port;
+	}
 
 	acm->minor = minor;
 	acm->dev = usb_dev;
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: cdc-acm: fix minor-number release
  2021-09-06 12:43 [PATCH] USB: cdc-acm: fix minor-number release Johan Hovold
@ 2021-09-06 13:02 ` Oliver Neukum
  2021-09-07  8:18   ` Johan Hovold
  0 siblings, 1 reply; 3+ messages in thread
From: Oliver Neukum @ 2021-09-06 13:02 UTC (permalink / raw)
  To: Johan Hovold, Oliver Neukum, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, stable, Jaejoong Kim


On 06.09.21 14:43, Johan Hovold wrote:
> @@ -1323,8 +1324,10 @@ static int acm_probe(struct usb_interface *intf,
>  	usb_get_intf(acm->control); /* undone in destruct() */
>  
>  	minor = acm_alloc_minor(acm);
> -	if (minor < 0)
> +	if (minor < 0) {
> +		acm->minor = ACM_TTY_MINORS;
>  		goto err_put_port;


Hi,

Congratulations for catching that one.

May I request to improve understandability of the code that you give
the constant a distinct name for this purpose? Something like

ACM_MINOR_POISON or ACM_INVALID_MINOR

so that normal people can understand the fixed code?

    Regards
        Oliver


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] USB: cdc-acm: fix minor-number release
  2021-09-06 13:02 ` Oliver Neukum
@ 2021-09-07  8:18   ` Johan Hovold
  0 siblings, 0 replies; 3+ messages in thread
From: Johan Hovold @ 2021-09-07  8:18 UTC (permalink / raw)
  To: Oliver Neukum
  Cc: Greg Kroah-Hartman, linux-usb, linux-kernel, stable, Jaejoong Kim

On Mon, Sep 06, 2021 at 03:02:43PM +0200, Oliver Neukum wrote:
> 
> On 06.09.21 14:43, Johan Hovold wrote:
> > @@ -1323,8 +1324,10 @@ static int acm_probe(struct usb_interface *intf,
> >  	usb_get_intf(acm->control); /* undone in destruct() */
> >  
> >  	minor = acm_alloc_minor(acm);
> > -	if (minor < 0)
> > +	if (minor < 0) {
> > +		acm->minor = ACM_TTY_MINORS;
> >  		goto err_put_port;

> Congratulations for catching that one.

Heh, thanks.

> May I request to improve understandability of the code that you give
> the constant a distinct name for this purpose? Something like
> 
> ACM_MINOR_POISON or ACM_INVALID_MINOR
> 
> so that normal people can understand the fixed code?

Sure, I'll use ACM_MINOR_INVALID.

Johan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-09-07  8:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-06 12:43 [PATCH] USB: cdc-acm: fix minor-number release Johan Hovold
2021-09-06 13:02 ` Oliver Neukum
2021-09-07  8:18   ` Johan Hovold

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.