Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 93fa08e9 authored by Johan Hovold's avatar Johan Hovold Committed by Greg Kroah-Hartman
Browse files

USB: cdc-acm: fix minor-number release



commit 91fac0741d4817945c6ee0a17591421e7f5ecb86 upstream.

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: cae2bc76 ("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>
Acked-by: default avatarOliver Neukum <oneukum@suse.com>
Signed-off-by: default avatarJohan Hovold <johan@kernel.org>
Link: https://lore.kernel.org/r/20210907082318.7757-1-johan@kernel.org


Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 0dc1cfa7
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -725,6 +725,7 @@ static void acm_port_destruct(struct tty_port *port)
{
	struct acm *acm = container_of(port, struct acm, port);

	if (acm->minor != ACM_MINOR_INVALID)
		acm_release_minor(acm);
	usb_put_intf(acm->control);
	kfree(acm->country_codes);
@@ -1356,8 +1357,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_MINOR_INVALID;
		goto alloc_fail1;
	}

	acm->minor = minor;
	acm->dev = usb_dev;
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#define ACM_TTY_MAJOR		166
#define ACM_TTY_MINORS		256

#define ACM_MINOR_INVALID	ACM_TTY_MINORS

/*
 * Requests.
 */