From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796042115; b=oIjszGOn9Q7CKte+5jzGmS0mt9QN6l3RWtDskVERbomfHWmgLEhSmo+d0wKVBEXIzkeW fdSTzNJ5Wn6wZcrODOQZutQKH2quoBdkONl6+2s6j50wvjq6uk7DRfA9yoqdue6D+mPh1 yJN6TAgGWjkemwC71UElcl8bs4ugpXd9SZfEzCTsb9qxC1Bn7qA1jlWGD9orZjkuHdOqd TJPGT8PI/GTfYdeBkA6+CUQmXzstTzMaQL9D1+rF0PIT2svg3ziC7s89aY2zS3u6W2lQX XgtLAJIXIRgPPNIqe3nbEo8/Hw0V3U4RtvvKULcX7jJemjFlplX0iltFuug6R6jr8oA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796042115; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:Date:From:To: Cc:Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:Content-Transfer-Encoding:In-Reply-To; bh=+KXHZeba7pXIVz42evidt8b5S1UaVwwuZYyNZNpxoMU=; b=r/o6OSTades0rRyUgoLdt9pPFBHbFAC7GC3/C+vnB9r3VNJtzfGp0p2/fLiyba3S/ORh uxkujShosFXElWrcj2uof40FIBcMJfSA0MU2tc1Q0Oxs5A+kyatUHdguldXRWaAscE0ap xlypeAX91mTKRTM7nKexaO2X15JaajoMMO0n5lRWCcmPIuS9PjsOapnJ4Vbd8heVr3c06 ndcC4dL9a5NisnKE9teS1yCr5MTWK8mnPZULL4YIYneUuYMYgd5qBPbz38nt4C1lh0AE0 XeUt6OloXOe9dOwakc9aHKFdnZ3VIc+7EkuAK0qPdj2OGvRaLXUu+4BE9oiA87ILR1w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=OhYkkHYT; arc=none smtp.remote-ip=198.175.65.9 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85190606A320; Mon, 30 Nov 2026 12:35:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 85190606A320 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=OhYkkHYT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796042115; x=1827578115; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=+KXHZeba7pXIVz42evidt8b5S1UaVwwuZYyNZNpxoMU=; b=OhYkkHYTl/vVOsXTwMQweretxVhquPwQbuo6y3Xsebmp4ut1qP2ViOME /bBKEiAHk9ku9IOqj7qyvB1Lma8dqzRLQ/Xi7xzRmy0ioUvVq3A3Qv7xh lGX6vVHLk2bwrXuhTdPJdOxUNVTOFREfY6YhWHH6D0HgOz2g2c8bl1d20 dIZkSba3iI1QCR7vyg7VS3yNcDr6aq9vcxGljhF+HlfyMp9qasNT2BIDg 1P/nORW0Tty4ojhW3DVDpERkC2hjxahmCgt/3RHi/7sqoYAZd+weujB89 61XZ+OR6fX+waO41SEtGx+aP7FEoP7B+chwR4ZytvfbZZDalvpoBGBWqs w==; X-CSE-ConnectionGUID: uiD3a7o/SNaBmySZNzu80w== X-CSE-MsgGUID: 11VGVuNQSXKIBKgX2lThzA== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4776878" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4776878" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 04:35:14 -0800 X-CSE-ConnectionGUID: xdUQ34MfR0ypITAVmtQewQ== X-CSE-MsgGUID: URQ28Wm6QAej40SbHgPZJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12920358" Received: from black.igk.intel.com ([10.91.253.5]) by orviesa007.jf.intel.com with ESMTP; 30 Nov 2026 04:35:10 -0800 Received: by black.igk.intel.com (Postfix, from userid 1008) id B0A6799; Mon, 30 Nov 2026 13:35:09 +0100 (CET) Date: Mon, 30 Nov 2026 13:35:09 +0100 From: Heikki Krogerus To: =?iso-8859-1?Q?Andr=E9?= Draszik Cc: Greg Kroah-Hartman , Badhri Jagan Sridharan , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Peter Griffin , Tudor Ambarus , Juan Yescas , Amit Sunil Dhamne , kernel-team@android.com, linux-usb@vger.kernel.org, linux-rt-devel@lists.linux.dev, stable@vger.kernel.org Subject: Re: [PATCH v2 3/4] usb: typec: tcpm/tcpci_maxim: fix vbus regulator UAF on unbind Message-ID: References: <20261125-max77759-wait-v2-0-9914b985c00b@linaro.org> <20261125-max77759-wait-v2-3-9914b985c00b@linaro.org> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20261125-max77759-wait-v2-3-9914b985c00b@linaro.org> On Wed, Nov 25, 2026 at 12:16:57PM +0000, André Draszik wrote: > Unbinding the tcpci_maxim driver triggers a use-after-free in > regulator_disable() if the driver has acquired the vbus regulator: > > Unable to handle kernel paging request at virtual address > 006b6b6b6b6b6bb7 > pc : regulator_lock_recursive+0x20/0x218 > lr : regulator_lock_dependent+0x198/0x2c0 > Call trace: > regulator_lock_recursive+0x20/0x218 (P) > regulator_lock_dependent+0x198/0x2c0 > regulator_disable+0x4c/0x100 > max_tcpci_set_vbus+0x70/0x108 [tcpci_maxim] > tcpci_set_vbus+0x44/0x100 [tcpci] > tcpm_reset_port+0x13c/0x288 [tcpm] > tcpm_unregister_port+0x70/0x120 [tcpm] > tcpci_unregister_port+0x24/0x68 [tcpci] > max_tcpci_unregister_tcpci_port+0x18/0x30 [tcpci_maxim] > devm_action_release+0x1c/0x30 > > max_tcpci_set_vbus() obtains chip->vbus_reg lazily via > devm_regulator_get_exclusive(). When the regulator is acquired after > max_tcpci_probe() has queued max_tcpci_unregister_tcpci_port() with > devm_add_action_or_reset(), devres releases resources in reverse order > and frees the regulator handle before max_tcpci_unregister_tcpci_port() > unregisters the port and max_tcpci_set_vbus() accesses chip->vbus_reg. > > Switch to regulator_get_exclusive() and register a devres cleanup action > for regulator_put() before tcpci_register_port(), so the port is > unregistered and tcpm_reset_port() disables VBUS before the regulator > handle is released. > > Fixes: 0c8935642cb0 ("usb: typec: tcpm/tcpci_maxim: deprecate WAR for setting charger mode") > Cc: stable@vger.kernel.org > Signed-off-by: André Draszik Acked-by: Heikki Krogerus > --- > drivers/usb/typec/tcpm/tcpci_maxim_core.c | 16 ++++++++++++++-- > 1 file changed, 14 insertions(+), 2 deletions(-) > > diff --git a/drivers/usb/typec/tcpm/tcpci_maxim_core.c b/drivers/usb/typec/tcpm/tcpci_maxim_core.c > index 2bb306b6b1f9..2e6a8906fb32 100644 > --- a/drivers/usb/typec/tcpm/tcpci_maxim_core.c > +++ b/drivers/usb/typec/tcpm/tcpci_maxim_core.c > @@ -209,8 +209,7 @@ static void process_rx(struct max_tcpci_chip *chip, u16 status) > static int get_vbus_regulator_handle(struct max_tcpci_chip *chip) > { > if (IS_ERR_OR_NULL(chip->vbus_reg)) { > - chip->vbus_reg = devm_regulator_get_exclusive(chip->dev, > - "vbus"); > + chip->vbus_reg = regulator_get_exclusive(chip->dev, "vbus"); > if (IS_ERR_OR_NULL(chip->vbus_reg)) { > dev_err(chip->dev, > "Failed to get vbus regulator handle\n"); > @@ -221,6 +220,14 @@ static int get_vbus_regulator_handle(struct max_tcpci_chip *chip) > return 0; > } > > +static void max_tcpci_put_vbus_regulator(void *data) > +{ > + struct max_tcpci_chip *chip = data; > + > + if (!IS_ERR_OR_NULL(chip->vbus_reg)) > + regulator_put(chip->vbus_reg); > +} > + > static int max_tcpci_set_vbus(struct tcpci *tcpci, struct tcpci_data *tdata, bool source, bool sink) > { > struct max_tcpci_chip *chip = tdata_to_max_tcpci(tdata); > @@ -514,6 +521,11 @@ static int max_tcpci_probe(struct i2c_client *client) > chip->data.cable_comm_capable = true; > chip->data.attempt_vconn_swap_discovery = max_tcpci_attempt_vconn_swap_discovery; > > + ret = devm_add_action_or_reset(&client->dev, > + max_tcpci_put_vbus_regulator, chip); > + if (ret) > + return ret; > + > max_tcpci_init_regs(chip); > chip->tcpci = tcpci_register_port(chip->dev, &chip->data); > if (IS_ERR(chip->tcpci)) > > -- > 2.56.1.831.g720f3f5937-goog > -- heikki