Message ID | 20240102192948.42392-1-lk@c--e.de |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-14773-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4644407dyb; Tue, 2 Jan 2024 11:31:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IH7oSniv1Zr5p3cWd2XSegst5PGWzKXD/F4RlDo3AlskHMXK2CO+Wo3tPg6+Eka3Qi5H3qf X-Received: by 2002:a50:999b:0:b0:553:a3c8:7aeb with SMTP id m27-20020a50999b000000b00553a3c87aebmr11163617edb.50.1704223865194; Tue, 02 Jan 2024 11:31:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704223865; cv=none; d=google.com; s=arc-20160816; b=Y2k18z3rXKT26NIaKTFJ35I8VfJwc7kEPaHOdbRUDNtlzrNPTOzHT4wMDPheyWavfz eqJnIEH1WlAIgPgR2fRaIq8yX7wnC/1dBMeoRNB7Kw6lPg2/9oBY0GpTG4fcJmPwhLoq 4kDAxNGpvOHHfcofK2P/FLHxcrBFUE3YpAozFNyGqbDGB4SRwH/+19HqMI7gBhETF46Y ktZVFTG4LASVHwlP+Y2KF/RQyv+BrcXRmt/6xDJDkWIL6E/o7p88eXlqXRMNG57Cs6n1 ss1eC+HWaa3/OmSfwVe2xfdVSvDKz46aDxotVl2LE3dRHYcN55daG4hMpZ9rYQ5DDYrK 90TQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=01JMDQzHOrUv8+Lb2SN2Za4eUzPNUxeltKYLdOzm5ZY=; fh=UyL10ZkN1TW7QDsmcCwcmN0osQl0vKAtbqrX2Xe0pEE=; b=lsQODDgvh77c3kd7M4lKLWIJZzc+2DHqM9KvkiwKEjS1+vmqtmLdj2EDSn0lUA2j+3 /7csJbuK6EQQDbGmSMD7dUkaHNf5ijbh4i9ZmkAbHKqoZnchmlsIz1BXn1pdS8RUgsrm wQKHG0X/6ffAbW3lwCXKkP4aL4Ckf071ndw8q0RIfP4b+zwbTQKCLkHsX0znLAl3mbjZ nYdQarsqxE9I/j4REbxoL5k+LkkMcgtBGclnd9R/DJwkbHUZuooP0SWYn6B4n9nwubqv E2AicIM9tzx76FTGfzy9Zv/4nkqneE8Z1M3bo7DiZQI+5lQ+d+PvyP1wO9MmI71SRnzL f5SA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14773-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14773-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t3-20020a50ab43000000b00555f3cb499bsi3279852edc.325.2024.01.02.11.31.05 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:31:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14773-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14773-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14773-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CD1411F21A00 for <ouuuleilei@gmail.com>; Tue, 2 Jan 2024 19:31:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 476D015EB9; Tue, 2 Jan 2024 19:30:49 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from cae.in-ulm.de (cae.in-ulm.de [217.10.14.231]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C15EE15AF8 for <linux-kernel@vger.kernel.org>; Tue, 2 Jan 2024 19:30:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=c--e.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=c--e.de Received: by cae.in-ulm.de (Postfix, from userid 1000) id 89F801408EF; Tue, 2 Jan 2024 20:30:37 +0100 (CET) From: "Christian A. Ehrhardt" <lk@c--e.de> To: linux-kernel@vger.kernel.org Cc: "Christian A. Ehrhardt" <lk@c--e.de>, Chris Bainbridge <chris.bainbridge@gmail.com>, RD Babiera <rdbabiera@google.com>, Heikki Krogerus <heikki.krogerus@linux.intel.com>, Greg Kroah-Hartman <gregkh@linuxfoundation.org> Subject: [PATCH] usb: typec: Fix double free in typec_altmode_put_partner Date: Tue, 2 Jan 2024 20:29:48 +0100 Message-Id: <20240102192948.42392-1-lk@c--e.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <CALzBnUG_8d-PLdhpHb4=mWUZ4oUguBqj3hBnE_HBHgdX1WoyVg@mail.gmail.com> References: <CALzBnUG_8d-PLdhpHb4=mWUZ4oUguBqj3hBnE_HBHgdX1WoyVg@mail.gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787008243603082163 X-GMAIL-MSGID: 1787008243603082163 |
Series |
usb: typec: Fix double free in typec_altmode_put_partner
|
|
Commit Message
Christian A. Ehrhardt
Jan. 2, 2024, 7:29 p.m. UTC
The altmode device nodes of a port partner and of cable
plugs hold a reference to the altmode of a port. The port's
altmode contains various back pointers but these do not
contribute to the reference count.
Thus, free the port's altmode device instead of doing a
double free on ourself.
Reported-By: Chris Bainbridge <chris.bainbridge@gmail.com>
Fixes: b17b7fe6dd5c (usb: typec: class: fix typec_altmode_put_partner to put plugs)
Cc: RD Babiera <rdbabiera@google.com>
Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
Signed-off-by: Christian A. Ehrhardt <lk@c--e.de>
---
drivers/usb/typec/class.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
Comments
Hi Christian, I believe commit 9c6b789e954fae73c548f39332bcc56bdf0d4373 would need to be reverted to apply this patch, but I'm not sure if that's preferred over submitting a new version of the problematic patch that combines this solution instead. Regardless I was able to verify the refcount on my setup. On Tue, Jan 2, 2024 at 11:30 AM Christian A. Ehrhardt <lk@c--e.de> wrote: > > The altmode device nodes of a port partner and of cable > plugs hold a reference to the altmode of a port. The port's > altmode contains various back pointers but these do not > contribute to the reference count. > > Thus, free the port's altmode device instead of doing a > double free on ourself. > > Reported-By: Chris Bainbridge <chris.bainbridge@gmail.com> > Fixes: b17b7fe6dd5c (usb: typec: class: fix typec_altmode_put_partner to put plugs) > Cc: RD Babiera <rdbabiera@google.com> > Cc: Heikki Krogerus <heikki.krogerus@linux.intel.com> > Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> > Cc: stable@vger.kernel.org > Signed-off-by: Christian A. Ehrhardt <lk@c--e.de> Tested-by: RD Babiera <rdbabiera@google.com> > --- > drivers/usb/typec/class.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c > index 16a670828dde..2da19feacd91 100644 > --- a/drivers/usb/typec/class.c > +++ b/drivers/usb/typec/class.c > @@ -263,11 +263,13 @@ static void typec_altmode_put_partner(struct altmode *altmode) > { > struct altmode *partner = altmode->partner; > struct typec_altmode *adev; > + struct typec_altmode *partner_adev; > > if (!partner) > return; > > adev = &altmode->adev; > + partner_adev = &partner->adev; > > if (is_typec_plug(adev->dev.parent)) { > struct typec_plug *plug = to_typec_plug(adev->dev.parent); > @@ -276,7 +278,7 @@ static void typec_altmode_put_partner(struct altmode *altmode) > } else { > partner->partner = NULL; > } > - put_device(&adev->dev); > + put_device(&partner_adev->dev); > } > > /** > -- > 2.40.1 > Thanks, --- rd
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 16a670828dde..2da19feacd91 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -263,11 +263,13 @@ static void typec_altmode_put_partner(struct altmode *altmode) { struct altmode *partner = altmode->partner; struct typec_altmode *adev; + struct typec_altmode *partner_adev; if (!partner) return; adev = &altmode->adev; + partner_adev = &partner->adev; if (is_typec_plug(adev->dev.parent)) { struct typec_plug *plug = to_typec_plug(adev->dev.parent); @@ -276,7 +278,7 @@ static void typec_altmode_put_partner(struct altmode *altmode) } else { partner->partner = NULL; } - put_device(&adev->dev); + put_device(&partner_adev->dev); } /**