Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp2828140pxb; Mon, 6 Sep 2021 06:20:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylwONreVOF8z7BFtaEVKn1MYmZ+PKhVTx4ZaamEqE7vYiUWyKSgmGSHeUm6ldFwUeistF/ X-Received: by 2002:aa7:cc0b:: with SMTP id q11mr13244625edt.251.1630934422446; Mon, 06 Sep 2021 06:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630934422; cv=none; d=google.com; s=arc-20160816; b=MRoNHDb7vyPFpnjx41xE+AbAPUDHuPDHv6hUsBR2OoMqLXtzg6j5Blpcgz2PtYjWwb ubTdI9BPKqgPXu0L6qEFJzkLX5YL4qvhynb6Jfumi+ZIyqL3I1B/UDWknSZK/pvwOLji cD83O4IkEviduO//BO0vDEqDzzB1/uAkTZDkEUlC9lrnoXZLLKMmXJ5+p7BBpVW/CHEQ WIgJngoPNw03HSG31tnrPdgbPiAPovEerehHF/alnfFEPHJoAz8bzS2oaLFWOJJ1yzQU weWqfONTJNmqnyvljM5Z/om/w8vep5t1sOVi7K9M4/ldvsWwfPZfftm+IOzsMLvzBNkV SI3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=fbHqdEyRVKEJ9MvPWXKdGfrZIPmHdkPSlhMUrkbVYdg=; b=JlWAC+OiwXIBr3UqM5KWIOvLWfN+iyNgvEkGGnuIPHUGP6dCNSQN9ALfeVnbwQRYkf ejVwdgdU/L+g8sHBkJRPDbL6SpGeLhtDGuiY6/wkvTIV/z3hiJ4cseVK/WtkHVR1PNyP WxX+/OOofRP0OYQhhvMmhzI/K11EVyMSKnZuqdDnx1j3njRCo+4r+2qLz9l0Kf2twVHu 5uvchpy92DgQINKn2p9ebYaXhl7qhJX8QiF7KsdT3ls2wTJc7Wb6fzm/Wn68LFkTfycd NNvs7JHgWVqCkoRX58w9ya55yuZpVG0uOd5/BaPNaQ7lPy4V0LT1V8yQBAdQuO7m2jDM sdfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OjIvZZYJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 5si8055608eji.566.2021.09.06.06.19.57; Mon, 06 Sep 2021 06:20:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OjIvZZYJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242137AbhIFMpl (ORCPT + 99 others); Mon, 6 Sep 2021 08:45:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:50226 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242143AbhIFMpj (ORCPT ); Mon, 6 Sep 2021 08:45:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1EA0460EE6; Mon, 6 Sep 2021 12:44:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1630932275; bh=2LXqSReT8SHF8LfIKml+aOLX7rlWLst/LYZu0lXukhc=; h=From:To:Cc:Subject:Date:From; b=OjIvZZYJAPvK97M3PpNaRASfWP7+Kp2/rLXGUbvB7ocH0/0q288viavvI91HA45EL aHiUIQjKJcvXh9KHxnn1Xe4XMtK7ETp3rLOqZcPktGEvuJuqkoPuCaQlbvNF/U1dt+ whuOL84Ga1APMLmhjpod1ZXJsBC1UBsJjr8aFZdBzeDSPAsTQx1FCcZCbUSYACyEBJ hyxJHVTYpPBbWUCLoVexSRzgOvRHR8Q+yFQ+84y4wXi2HnOl7S4PPPwKfKDjLuCL1K bSaHnN0B6zgZYM0fZU4LOgtbkC1b92kQtxtnVviFTvcswBaOkrq1wqs2SW6xbN66Hh z56w29WXYR2MQ== Received: from johan by xi with local (Exim 4.94.2) (envelope-from ) id 1mNDz3-0005ny-Rk; Mon, 06 Sep 2021 14:44:22 +0200 From: Johan Hovold To: Oliver Neukum , Greg Kroah-Hartman Cc: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , stable@vger.kernel.org, Jaejoong Kim Subject: [PATCH] USB: cdc-acm: fix minor-number release Date: Mon, 6 Sep 2021 14:43:39 +0200 Message-Id: <20210906124339.22264-1-johan@kernel.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: Johan Hovold --- 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