From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 986003148BF for ; Mon, 20 Apr 2026 23:10:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776726641; cv=none; b=UbAa8OsMuSy+PIuoqvJYuXdeLGf7ROjDn4syvUs9zPVlaVECurnjWLPzEvgYHDw6uI5+u7Zi7LE89JFk/TSA3yXAlajQUNHWHx+bUXCNl6Pojp9hCrWVxCeWkKnm4sioBFWiwse1ZVEpO6umXwoz72OPanlXohfIY3lqGxPB35Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776726641; c=relaxed/simple; bh=tb2JNc5ynwajJeCuTzOWgJ2OezcFfgp4Ywh/smpSH0k=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=I31HNTIVylMbiI257jB/L6s2hVFU2m+q9h5ik8OmIypQJ77/tZi0yxN9YVMvDh5IH7RkJFpEtNcyEOskVXA4A5s1PVEI1HpBxEd7XTT434ZMBHMXJrt9g8O5I8iH17IcOpF7kLvpDDSRXzTUB6dwTIVHWdjsRwWR6BPyH51b+xk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FgWqZAxK; arc=none smtp.client-ip=209.85.128.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FgWqZAxK" Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4891cd41959so15905245e9.3 for ; Mon, 20 Apr 2026 16:10:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776726638; x=1777331438; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8BFbqe6zs9zdE69IPJo3pEdqtjhoEkNZOLj14gX1oP8=; b=FgWqZAxKPAoLr70ATzHprOwt7DYquMcK2F8RnWjl/ekBnRd88BfQKHSr03aGzh0eAZ 0RxhMZfIsx8elQv1s14gwrVeuDHKtzWc77hNqvBDF/5rfH03ueU/inMdGvMXUuznTSTV yAcpDIPP9d4lahiT204NqiUmnr1q6fqWond/9pwQgbUC3Yn/bGdnWHys/eZIeMDuzZ+E nvAMV0674iTwddH71Kv4gBm//v+W7j0SwkooTLeG620mB4EJqyhrf3ENn0/bYVrETFR9 mALria6epOsxx8+tagw8f7II+J50q8I9A/8bb7o/o+1m6k80lOmy6wTEtbKUXYMuiRGV gsug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776726638; x=1777331438; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=8BFbqe6zs9zdE69IPJo3pEdqtjhoEkNZOLj14gX1oP8=; b=dW5/DzjlD3f59NNVUmpTjqRl2bTfQJNgn8Yz+pjYDvNNhRYgzRRwNtYnkXpAHhRhV+ R26PK89utHo9OgQ+MrI3jBUgoJWznA9rlPTVKpkfYd57f8v41NIq8lIh502ppmI98NcN Qc1JugeSJoresRT3AByYQZyEQEWmkJ/zlyC7QhHO+p61YFRhvcCJ5zD+BBU6NAdDlCvl eTX5GD3xjD7inVck5XIU96kVr+rM1hiTxYSkqM4UGtiTMSR4v2/hZDaSDnHnzLCwy3PB +IYXYM3IZkOriWp0qj59U+gJgqS37LkEgMAmfn0oe9ovqGBCsbY2X2GeTxVDzGcYhHHZ XziA== X-Forwarded-Encrypted: i=1; AFNElJ8tege2LXYDAdVcXr9wQonn/k/IdBLlAgk4DGkW3+hRpA6aOBlPReqBrcZB0nbgMnuuh/ihQWIks50XeDc=@vger.kernel.org X-Gm-Message-State: AOJu0YwSkjBSNRBKXhnQlLezyuRlw6tSoAo/XHGjtXfv02n7UmVgrZ6u MItiD+a0Aho4OCPRl2cn9zkbq3EvNd/2RZzEcssI1mmF56pbGpOCodYS X-Gm-Gg: AeBDieuKvQIjTMN1rTRVNe1NXZKh7g+GCDJh+hFIzvmdOqay962ji/xxNbJmihl1GKG kno4pUMlWneLh2fUK+hYuVB2jamsmaGqdBLRBaB8mabATBB4+AyZ1MXI73J2t7qth5FnavoH0T5 9UnycbWsag5euC297qye3xnGYQUJ98uQo5bmzEh/+BmLqes+X8eSwllyWWDJcA3+N35slHVHpZp Dg1sD1GVP9aHEJSe8o8QnA2tw2lgr6V1bTX1ZFl5GCtHDWRjU6Nci8lyVKJH8sPelCE9lRHcem/ y+sdkUU0uF5G3QhRiB9NWrf7m1gK0eLJY/WqmvAi5NW3JJRQgowNQAUyZJ+5rd/0dQdIR8q8W+5 ETWbOqgtc5yv3BXylq6dn371qmGpzPC8NboQo5vc6FPBVKdREvjmJfpPxbAtGECB63llEHuuYEN FWyxc8thQiVD/khKtRD1C3LZEav61ALHK3PUkzfvBiO40cfS2zSMzn9S9JRqIFjwQN5bkp4E8El 2xZny3IewmGUSv3V2FFnQ== X-Received: by 2002:a05:6000:1acc:b0:43e:a70d:7622 with SMTP id ffacd0b85a97d-43fe3e0c612mr24008948f8f.22.1776726637610; Mon, 20 Apr 2026 16:10:37 -0700 (PDT) Received: from dohko.chello.ie (188-141-5-72.dynamic.upc.ie. [188.141.5.72]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43fe4e3a174sm36837571f8f.18.2026.04.20.16.10.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2026 16:10:37 -0700 (PDT) From: David Carlier To: Sven Peter , Janne Grunau , Neal Gompa , Vinod Koul , Neil Armstrong , Hector Martin , Philipp Zabel Cc: David Carlier , asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-phy@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH] phy: apple: atc: Fix typec switch/mux leak and UAF on unbind Date: Tue, 21 Apr 2026 00:10:13 +0100 Message-ID: <20260420231014.35462-1-devnexen@gmail.com> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit atcphy_probe_switch() and atcphy_probe_mux() discard the pointers returned by typec_switch_register() and typec_mux_register(). The platform driver has no .remove callback, so the registered switch and mux devices outlive the apple_atcphy struct, which is released by devm cleanup on driver unbind. A subsequent typec event (cable orientation change, alt-mode transition) then invokes the registered atcphy_sw_set() or atcphy_mux_set() callback, which retrieves the freed apple_atcphy and dereferences it. Unbind followed by a cable replug or alt-mode change is enough to trigger the use-after-free. Save the registered switch and mux and unregister them through devm_add_action_or_reset() so the framework references disappear in step with the driver's devm-allocated state. Drop the unused struct apple_atcphy::sw and ::mux fields, which were declared with the wrong consumer-side types and never assigned. Fixes: 8e98ca1e74db ("phy: apple: Add Apple Type-C PHY") Signed-off-by: David Carlier --- drivers/phy/apple/atc.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index e9d106f135c5..4156fabad742 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -628,9 +628,6 @@ struct apple_atcphy { struct reset_controller_dev rcdev; - struct typec_switch *sw; - struct typec_mux *mux; - struct mutex lock; }; @@ -2066,15 +2063,25 @@ static int atcphy_sw_set(struct typec_switch_dev *sw, enum typec_orientation ori return 0; } +static void atcphy_typec_switch_unregister(void *data) +{ + typec_switch_unregister(data); +} + static int atcphy_probe_switch(struct apple_atcphy *atcphy) { + struct typec_switch_dev *sw; struct typec_switch_desc sw_desc = { .drvdata = atcphy, .fwnode = atcphy->dev->fwnode, .set = atcphy_sw_set, }; - return PTR_ERR_OR_ZERO(typec_switch_register(atcphy->dev, &sw_desc)); + sw = typec_switch_register(atcphy->dev, &sw_desc); + if (IS_ERR(sw)) + return PTR_ERR(sw); + + return devm_add_action_or_reset(atcphy->dev, atcphy_typec_switch_unregister, sw); } static int atcphy_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) @@ -2146,15 +2153,25 @@ static int atcphy_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *sta return atcphy_configure(atcphy, target_mode); } +static void atcphy_typec_mux_unregister(void *data) +{ + typec_mux_unregister(data); +} + static int atcphy_probe_mux(struct apple_atcphy *atcphy) { + struct typec_mux_dev *mux; struct typec_mux_desc mux_desc = { .drvdata = atcphy, .fwnode = atcphy->dev->fwnode, .set = atcphy_mux_set, }; - return PTR_ERR_OR_ZERO(typec_mux_register(atcphy->dev, &mux_desc)); + mux = typec_mux_register(atcphy->dev, &mux_desc); + if (IS_ERR(mux)) + return PTR_ERR(mux); + + return devm_add_action_or_reset(atcphy->dev, atcphy_typec_mux_unregister, mux); } static int atcphy_load_tunables(struct apple_atcphy *atcphy) -- 2.53.0