Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp6773434rdb; Tue, 2 Jan 2024 12:57:19 -0800 (PST) X-Google-Smtp-Source: AGHT+IF7g+JHjGPBJypVA4+fVc08kpslcg8Xpc/kspkVEwN9dch4BTWWKy9PBxZ1aFjeES0vTDQb X-Received: by 2002:a17:906:60a:b0:a22:dc72:afb1 with SMTP id s10-20020a170906060a00b00a22dc72afb1mr6654086ejb.118.1704229039605; Tue, 02 Jan 2024 12:57:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704229039; cv=none; d=google.com; s=arc-20160816; b=IxBDDoUC9eenlBiObMHuijDCWlcZJHvh0oc5OeJW8kycI5Lt2aWH2nqv68oGwBmp1I 1/GDWJwFXgfVCReJJj+dNtrx00nueAL9qONhoO68nsck9h7OIFYCy2QbQ2uBEPDPEt+i 3HgLxjCH93RMClIFDgYZoTCyD9Z0zrX+KW8lcVEZvmf+oa6y5FjpLXmmO/vWC+447dO+ /iP+JqOoWoAs4BsQySAZYFG17xHXn7ywx1dj7l62QHVu01MBrBhVyo3ThgfSAsL44EoU lGakn4YeXhnwgsBILYK3dxorgxFBCkHZFMnhyeZ4MdAc7ELB/jzbnsEAN2eTlCSO2zHV +xsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=69LArWSUroy5YqmK5YMwHPfYEDKw0sz24l9A6OuFmIw=; fh=adpBNr3umVtW2cS3pWCm+2aWAo0vX5vLOr8xFvSBmw4=; b=sux92VMv5tD+Jz1GLFRbGLcj+G890XWRRtM+2qSlTuHIXhD1ouG5TNJta5LEQpA33+ MGM/pN2pkKPxneI5+A4rtMnsjG6MYnp0SFGLm1YaWEEhclKnk7gDR5MXROcdnPiKfWIB WyLXw+WjbnuB1ZPW3KS1T2x16Jw7ieDCnf/FL/TkljEybvHiI3z1LEHI9ts8NLMaFHqX hTnGfnvFu4R6o+IuCUbZbt59t9nuw7GIcrhgIkQOQlcyt96oEja243rnkQvMNd4NR/zm v1kXmv4njaLeFUS7ik0K4e8ZJp4iaFXfXcVk6erukRC6glw2uycPgOL/3X4U5DO40cdC X7VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=c8sJ+WWb; spf=pass (google.com: domain of linux-kernel+bounces-14814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id p19-20020a170906141300b00a231657d374si10679640ejc.831.2024.01.02.12.57.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 12:57:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14814-linux.lists.archive=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; dkim=pass header.i=@google.com header.s=20230601 header.b=c8sJ+WWb; spf=pass (google.com: domain of linux-kernel+bounces-14814-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14814-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 5D9B31F23637 for ; Tue, 2 Jan 2024 20:57:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AAC3168B4; Tue, 2 Jan 2024 20:57:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c8sJ+WWb" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B3C3168AD for ; Tue, 2 Jan 2024 20:57:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5534180f0e9so240a12.1 for ; Tue, 02 Jan 2024 12:57:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704229024; x=1704833824; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=69LArWSUroy5YqmK5YMwHPfYEDKw0sz24l9A6OuFmIw=; b=c8sJ+WWb+B0pixL0ZvD4Eodpu9CnJ/2+VRZXmSUxm0bokRG/UuaHh3n6uDASQ//33S 7Fe2IYk4f+uRCNCud2t3u18rNVS0KaJKhAX2QPmatTMsLuIR+v76WAxgmUBOLyBZQMh9 /G5eXgS/B12YgXFqR/68kb5n2zzfqkRSU4HQt+z8Fde0HpEVtu2QkjHuJRwFBcZDAbFI PqqpnghYt1foT3zRTeBoVDGFPr/WsSxZlCJd38bbxu4CJqJFqIACqRIYjmRsc6IaTFxX 1Z9hNjE4v97SC9507dALObGpXHt0yuzvN5pv/EdIvlR80OBDzgTOYfE0BTPGSqCctjT8 GGUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704229024; x=1704833824; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=69LArWSUroy5YqmK5YMwHPfYEDKw0sz24l9A6OuFmIw=; b=E0q3uGfAAx4yKvdLHhZV/QUNyyqSEYt31X9XP8b0k6re1etTbiphP7WtwCtVifs2GE EWVUEl8vIW7QVCmZUiP4eO/NXKkibQr6My+r2OVrih3XEonZznS7tp8G3JsUkEjfzbeK v5TsaL+JX7cvxuw7O1FdHwfdCXqUBhy+OCgWF6SUogVNiNngBCQfZ36mVobjQpOYe+hM dBe53ewmN2laXSx273aIJBeJxWwnONI2fbQQMDfkZRUWresfak6jBL2dJKqJUwSs0Nih aafqHKqF7hTNUOtLkj6hjIItfQDyIkuLohhQO9DhdqvPyo6X3B8/k8cL7Zwctu8e9cqZ 7Tpw== X-Gm-Message-State: AOJu0Ywt9sCp8i2vXF7njgvHVdTO/P6WQyun0e21bWNw4kGjcYidhZs4 bqUZhKdJU9DPXnb5PN8yhbSqVstRxAt5jHcTjQgUPEJM1h9U X-Received: by 2002:a05:6402:395:b0:54c:f4fd:3427 with SMTP id o21-20020a056402039500b0054cf4fd3427mr10748edv.7.1704229024235; Tue, 02 Jan 2024 12:57:04 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240102192948.42392-1-lk@c--e.de> In-Reply-To: <20240102192948.42392-1-lk@c--e.de> From: RD Babiera Date: Tue, 2 Jan 2024 12:56:52 -0800 Message-ID: Subject: Re: [PATCH] usb: typec: Fix double free in typec_altmode_put_partner To: "Christian A. Ehrhardt" Cc: linux-kernel@vger.kernel.org, Chris Bainbridge , Heikki Krogerus , Greg Kroah-Hartman Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Christian, I believe commit 9c6b789e954fae73c548f39332bcc56bdf0d4373 would need to be reverted to apply this patch, but I'm not sure if that's preferr= ed 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=E2=80=AFAM Christian A. Ehrhardt = 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 > Fixes: b17b7fe6dd5c (usb: typec: class: fix typec_altmode_put_partner to = put plugs) > Cc: RD Babiera > Cc: Heikki Krogerus > Cc: Greg Kroah-Hartman > Cc: stable@vger.kernel.org > Signed-off-by: Christian A. Ehrhardt Tested-by: RD Babiera > --- > 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 altmod= e *altmode) > { > struct altmode *partner =3D altmode->partner; > struct typec_altmode *adev; > + struct typec_altmode *partner_adev; > > if (!partner) > return; > > adev =3D &altmode->adev; > + partner_adev =3D &partner->adev; > > if (is_typec_plug(adev->dev.parent)) { > struct typec_plug *plug =3D to_typec_plug(adev->dev.paren= t); > @@ -276,7 +278,7 @@ static void typec_altmode_put_partner(struct altmode = *altmode) > } else { > partner->partner =3D NULL; > } > - put_device(&adev->dev); > + put_device(&partner_adev->dev); > } > > /** > -- > 2.40.1 > Thanks, --- rd