From nobody Tue Nov 24 04:33:12 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971076; b=Zey1BXM5NEnqGDIDKR5AISCcLxlhXkPDlxWQNwH4s6nDyrYvBIUUgwPvB1FmS7suPdsi +sEm5BxW5g+X9Ho0RIx2kBAx1zD9DBoTakYFVa4k7iaUBYeB5eAHHIlVfU+Mn2vpin1aU wh3/4PTci3gxV9XrwqtCxgEpZLAfVy/5xff7HjwCpPdDWisikOJnhuIDkiJNvDVVTtw5X Pll+LFelK6y+aubJdTofIaM+mStrYl+29sqOF6sXWDGpK4yiygguvYWC0aHZ81XtMffkz aMrZsEzi7R2aV23svS8U4SQ4HQYEp5u26S3XWqVC1qRNHCd4YRU0GPZj1TGzvIONWCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971076; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=6/3GymnNJZRM/VrW+qCnWfq8A57o4eHJ5rqxoxFgvC4=; b=htYGsDtfhJNj1yUPSoIN1h93expjDxWqbJpETSLjMFv8E1bHLY8fVn9M5aLIdKjfK9TP T9AISt+ms1kpnlPqF+BNk1M/fjGfo0f5v7VvdRO5DcdAI6wQ/LudqUBEqMAIsGE1rV9hK 7MeLC2AyVVFUM/PTzIX6zRjZkpjMd/SEtoNZUj+xlj5m4qX/ooUiw0+wP2UfXgWV0JQ6+ so/SkgooqNju/zQxDrLVR63Wjo4agarZb4o9n0yz60BKQcYIqyzyiZEFFJo7WFQRhPN05 RK8W0Pu7F8f5FZJwXhTOLAdK1RT5bhVnAugvmWHIM8DaY31AqLPNHp4taSY99toqLuA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pLKJBcOV; arc=none smtp.remote-ip=209.85.215.180 Received: from mail-pg1-f180.google.com (mail-pg1-f180.google.com [209.85.215.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDCCE606A32C for ; Fri, 6 Nov 2026 13:17:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org CDCCE606A32C 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=pLKJBcOV Received: by mail-pg1-f180.google.com with SMTP id 41be03b00d2f7-cc7d154ec4fso234437a12.0 for ; Fri, 06 Nov 2026 05:17:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793971075; x=1794575875; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=6/3GymnNJZRM/VrW+qCnWfq8A57o4eHJ5rqxoxFgvC4=; b=pLKJBcOVib3l2IvbEA0fuRpzWS7HtxZFSOMT8uvd+t2Gig0EeaMFkEJrROdqrf8GbN 5Ez2dbXsBKz5TLbIUdyiOMTgmoZpKlaH/qa/nZvmyhmbcn1bSziNwIEuJCqHZnZTqbgL LvKj+kaNFpY5qE4SL55AnobiEhBwfTy/p7h/2fGSbVC89y+BUqJ6WdLgXrjmrGW50xls i2CP/DdiZMlp+aAj28N2uAijrmnNKZPNvSe7guccM0MhNX+PZQtFMDtygIkuKxe99dRJ 5s4MU7SqE8ZrcNwXi2dJK3bvXEQtZYjjoHWuglDx/cuhy8JmOIyBexYLILYcz9ylynaN iNdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793971075; x=1794575875; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=6/3GymnNJZRM/VrW+qCnWfq8A57o4eHJ5rqxoxFgvC4=; b=hqhRvMWOEUUe3Dv/57oVq+QAByCN5tScT34RKJLLj3hjPrCkcUShqs4hTbWW4+tSVp DMuInGB2r3RyTafPxjvAr5pRlG9wlly6As/DSaAtAHAz2ss7h7GIn8YTw7DX6ZRqzrDh N7R/uTRpqZq/+RdZ1YjMM1CbuUeiyGMf7/h9iBQEcWq1hWB7ROubK4qQCer5TzHsTB9w 7G9cztNe3nHiCKlbuGi8FvesTr3WQ7DmlBMZQ0eiXUQBWWYZnkM1mR0kKrwJVXUzJQls pUeTslglKe0+qhfNxgVI34BKHIQpBl/8bzxDdQmd/uh+F957O2vrmIa4OnY59Ty11SpC QRew== X-Gm-Message-State: APuU4Z9bXiA/ICIfklr3MZC3lietL8apG52tPOMghBs40YyeTLapICRc /G50AI60OW9we+2ryPACVg4UAIpsriRLvzfGxRaq0UeWolipWAuxsMP0 X-Gm-Gg: AYBFou0ilfC/zu28RtRqL6L8jkkoZXiEPEKVZk6fZdTTzeXQWF/pB/EITwsUujtxKwN 7hPNDRz2XQ3QA/a3lGR2uEsthCR2VMsEIK8JaghppYWbUUpQExkkAP7tMzqrFbrU6RyfnO0ViZm rSPL4+bEBgVZ+CBs8xPmqdjPvji/34bh8IQtUyLpk8gv/7RmC9RnZEj3oN9hAskzYSeAspfhoIf psUIm5OltrXcW2nLtU9Xp8vUajxefsjYWl+ynBPo218JMzxZZrngHHB7s19zECN5uXWte0MUWU1 aybIdxm7/e+4dhmpq8/KmuBaJHki3OSqjX5EZUWrjlDeJKKhy9+rbq+kRTibXmF+3cwIPsP2UUp yrf/fcfsBbhNsg/L5yZbtUQl53jiSfkef/A8lp9vrjayhOT2pRrTrW2YHFxQGbNzgdkfKi90VMk dUyEsySiskqJr4SFZfc8eiLqyFQ4oAXVUEgZuP03mLsn8e2GWO+yQoJeIhLCoy/+beBmRRaJDnN mrqOPbVxBd6JInIuIksFys4ioQvE85mKAx0Z3Z61qJj7BHMRjPcNeZjt1ZzcY95lafckaTA1adF 6Y+XXbcxzIjkGSPkmATkDDVJ+02EPJCmPO/uTdO0vp/xeHv5Iw== X-Received: by 2002:a17:90b:4c41:b0:3ac:4e18:238e with SMTP id 98e67ed59e1d1-3b0db6fe1cemr2426041a91.46.1793971075070; Fri, 06 Nov 2026 05:17:55 -0800 (PST) Received: from hj.. ([163.239.22.29]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0e2a8d6fbsm1025636a91.1.2026.11.06.05.17.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 05:17:54 -0800 (PST) From: hyunjungg To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, Hans de Goede , Hyunjung Ko , stable@vger.kernel.org Subject: [PATCH 1/5] extcon: intel-int3496: drain ID work before its GPIOs and extcon device are freed Date: Fri, 6 Nov 2026 22:17:26 +0900 Message-ID: <20261106131730.2633139-2-hj351016@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261106131730.2633139-1-hj351016@gmail.com> References: <20261106131730.2633139-1-hj351016@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hyunjung Ko int3496_probe() registers the debounce work for device-managed cancellation before it acquires any of the resources that the work handler dereferences: devm_delayed_work_autocancel(dev, &data->work, int3496_do_usb_id); ... data->gpio_usb_id =3D devm_gpiod_get(dev, "id", ...); data->gpio_vbus_en =3D devm_gpiod_get(dev, "vbus", ...); data->gpio_usb_mux =3D devm_gpiod_get(dev, "mux", ...); data->edev =3D devm_extcon_dev_allocate(dev, int3496_cable); devm_extcon_dev_register(dev, data->edev); devm_request_threaded_irq(dev, data->usb_id_irq, ...); devres releases resources in reverse registration order, so on unbind the extcon device and all three GPIO descriptors are released first and the work is cancelled last: /* free_irq() */ devm_extcon_dev_unregister() / extcon freed gpiod_put(mux) / gpiod_put(vbus_en) / gpiod_put(usb_id) ... cancel_delayed_work_sync(&data->work); /* too late */ int3496_thread_isr() arms the work with mod_delayed_work() on every ID pin edge, so a work instance can be pending or running at unbind. The handler int3496_do_usb_id() dereferences data->gpio_usb_id (gpiod_get_value_cansleep), data->gpio_usb_mux, data->gpio_vbus_en and data->edev (extcon_set_state_sync) with no guard. If it runs in the window after the GPIOs/extcon device have been released but before the work is cancelled, it operates on freed resources -> use-after-free. Register the work for cancellation after the GPIOs and extcon device are acquired and registered (and before the IRQ, which arms it), so devres (LIFO) frees the IRQ first, then cancels the work, and only then releases the GPIOs and extcon device. devm_delayed_work_autocancel() still performs INIT_DELAYED_WORK() before the work is first queued (queue_delayed_work() below, and the IRQ handler, both run after it). Found by static analysis / code review; compile-tested only, not reproduced on hardware (requires an INT3496 ACPI USB-ID mux device). Fixes: f94a5becabf4 ("extconn: Clean-up few drivers by using managed work i= nit") Cc: stable@vger.kernel.org Signed-off-by: Hyunjung Ko Reviewed-by: Hans de Goede --- diff --git a/drivers/extcon/extcon-intel-int3496.c b/drivers/extcon/extcon-= intel-int3496.c index 7d16d5b..40774fb 100644 --- a/drivers/extcon/extcon-intel-int3496.c +++ b/drivers/extcon/extcon-intel-int3496.c @@ -130,9 +130,6 @@ static int int3496_probe(struct platform_device *pdev) return -ENOMEM; =20 data->dev =3D dev; - ret =3D devm_delayed_work_autocancel(dev, &data->work, int3496_do_usb_id); - if (ret) - return ret; =20 data->gpio_usb_id =3D devm_gpiod_get(dev, "id", GPIOD_IN | GPIOD_FLAGS_BIT_NONEXCLUSIVE); @@ -169,6 +166,10 @@ static int int3496_probe(struct platform_device *pdev) return ret; } =20 + ret =3D devm_delayed_work_autocancel(dev, &data->work, int3496_do_usb_id); + if (ret) + return ret; + ret =3D devm_request_threaded_irq(dev, data->usb_id_irq, NULL, int3496_thread_isr, IRQF_SHARED | IRQF_ONESHOT | From nobody Tue Nov 24 04:33:12 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.48 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971081; b=xGMvZVajYV/AdGDek8qtlj6UE8L+FmfxEDEPyeJeyOq3GL1wU5rBPCqQ+Tml4gNXZMzb 22oX/I6DiQso3DMK6Vlo1wXGZOpDkF+qwiSGmkEyTRMzQslYyOHw1SoiatJkB1CV29vU9 hEo+jpn6KAsU6J58SFrVG+60HAO+KVWrkCQTToEwde1P1w6SEAPRMqdGIz1FUWpjwPFCa H520893wrFpZQCp3vKcghGHWm8Vuo030TpyJGU/xB1Rdk3hh3BxLj0Xg2dNX6fx3mnnnA KLWR9FGN7ueExLqDGS00OE4ORtDocWFYLX/8WHMcvAtJwfztZFfjq3khTv8KhVUrtwg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971081; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=QCmCUD5+cRAdCqiqdhrCpwSJ5tYiyygF2+7HyPzxiCw=; b=q03cSoX+gIBqeYBnfyx5Hb2Xrpp/05BRk95F5crxkex6kvzBJE239w4FxP6ETExA45iE jA6MveIYa6Tqo5DzxqvFW2xcLAmSMQdkDyB/087BlCv1eSPsL6ED7L59S2/wF20kHPgkO ELFqq54d63kiqUokBP3V/+/5zDeXjLk2DExChZLlKxzIIJRD5UnQ2PZHFKKoXfMTi2t1R 9ORhkWZ9DfGr2dnWqDCQfMbcfzS8+uW1LNBPaW3hnILDT9S006zZ6/iUFyg0bAf7TZCIs f/E2x+GFHZNrg4dM+F1F9TXOfKRkaO9t26tXu/oVPAbaRIhHqh1Zkca7nndOjjixYRA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eRQTt+3H; arc=none smtp.remote-ip=209.85.216.48 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2946B606A32C for ; Fri, 6 Nov 2026 13:18:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 2946B606A32C 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=eRQTt+3H Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-3b094e649d3so384923a91.0 for ; Fri, 06 Nov 2026 05:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793971080; x=1794575880; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QCmCUD5+cRAdCqiqdhrCpwSJ5tYiyygF2+7HyPzxiCw=; b=eRQTt+3HAcikpyyqip2eed0SNs12Pyb+897E3wzePXTtPxRx3tqIHGG/G8Len9CQD4 POSEb83IziCHdkZkdlc+CIvXOu4N0fZPjRFzetlotDbUC2nmtAc9aMG/RDnngQscifl2 TPtbBc6p+Y+5KG7Xps+yBXvOsNXkBCPPvvMut448592EshEjgD4PcuVIEV/dKVcSzo6M PKEBTOqraLbio9bEw0QeVZliR/FzT7TRrYuYPOIQcQCMUB5el5OfdmErKVAtaVK7EkUu 8KTpRZGdSQ5rbrhcsxf8C7GozNTjsttQmqZzmMciFOqGpb+YrqzulAGLHuaSwL0aOVmn GSkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793971080; x=1794575880; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QCmCUD5+cRAdCqiqdhrCpwSJ5tYiyygF2+7HyPzxiCw=; b=sFx4L2bL+hWXUeteMUtP/Kq1jGdbxBHobFmamrfktMgidn7SJ6qeOv1G684731wrOd hg+HJUvI0Rgpd/gavmw8NK6pr+uExUnUEMEm3/3i2ctlsi0oJhXExC//8k5uDHZvVcpA afM9oCDjl5gxiX/Lyovt6wb/ZkLW+5xidTgIsxJRmHkJOAYeGGHB5QOqUmtp0cwEDBFh 1DpdgtXS5f6tTqHsKsrTxxCWkZMK9MLxUZJDYGaLmZVEQw5wIuNLHeHaGvZ4KvbC9qyN ka2gsyPFiAG4rEQ3ZXQkojgpYvkQ6cEFoQRE/B7IL29tRiujgbWhLfVbihg6VFFlBKWs wn5w== X-Gm-Message-State: APuU4Z8g+fbYbW0zrTB798XaheLwTUegxWjWvEJXqDicOUhaY0owk8Qt Zv/MI9okZvuGV82wTRH+EvjN0LoyObAmVpAtCFUOCSyPxi+bB2HbVhwT X-Gm-Gg: AYBFou0/t/DgU/pEVoa6r54Aj+FlUzt1bsGQYyZPpVxfZCFjBQmyAyTNgze9w1zVyIX CJw9SWxc6clQGHZO1ujZJa0OGS45UjNBO4z/MySvgk0GzmI/zUB5m5mwjVDdzOE4me87K0MINrM uFQ2lcDwCm5D6QZ2VOFn8E76GGVq0GOxvOlShVm8UkAy/3LfOi/WMP+v5ZEklPIckHJoeInjUXW /R2dCbgObEYhoU5r4Ateu4a+61zS005Q7Aa5/0Rb2sc600sdW3KTOTLpGsiBYhkLNCOVlJ1+QQb bQOlc6MmOe8Y+O9EVPWG3flprA6GzIP3jS7yDEQtPbJxTu/kKquadtAuEX6tgoQLEbEu1ENpGKk Eti35OfHU9a+Jln5nfiKgYAofgrhQArKwMLNflmtuMuuLNrTRXaobsMNsX/QAH35q8zLFXFUAtt hxZq6pAMLgMydoyF+WjvBiUG7SkzYrh33WAnisn7cB7LRyPKfoBggzjdVhSS9C8JSY3ri8yM1Jg tDaQxGdJplrncQmcXwhG2kmW+eU0DBfmr/nkGAMm9P1xXXCojh4la92BsUZYOfpAl7zvktv09WN nhiJbG8gff/83JWIHLFVFpEMWDe5mU+4OOWAjFAnew9KJsowbIaduVpV4Y4NiSUviFvuLA== X-Received: by 2002:a17:90b:4a10:b0:3b0:a38a:6715 with SMTP id 98e67ed59e1d1-3b0db7109dfmr2536524a91.59.1793971080497; Fri, 06 Nov 2026 05:18:00 -0800 (PST) Received: from hj.. ([163.239.22.29]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0e2a8d6fbsm1025636a91.1.2026.11.06.05.17.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 05:18:00 -0800 (PST) From: hyunjungg To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, Hans de Goede , Hyunjung Ko , stable@vger.kernel.org Subject: [PATCH 2/5] extcon: palmas: drain ID-detect work before the extcon device is freed Date: Fri, 6 Nov 2026 22:17:27 +0900 Message-ID: <20261106131730.2633139-3-hj351016@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261106131730.2633139-1-hj351016@gmail.com> References: <20261106131730.2633139-1-hj351016@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hyunjung Ko palmas_usb_probe() registers the GPIO ID-detect work for device-managed cancellation before it allocates and registers the extcon device that the work handler dereferences: devm_delayed_work_autocancel(&pdev->dev, &palmas_usb->wq_detectid, palmas_gpio_id_detect); ... palmas_usb->edev =3D devm_extcon_dev_allocate(&pdev->dev, ...); devm_extcon_dev_register(&pdev->dev, palmas_usb->edev); ... devm_request_threaded_irq(..., palmas_gpio_id_irq_handler, ...); devres releases resources in reverse registration order, so on unbind the extcon device is torn down first and the work is cancelled last: /* free_irq() */ devm_extcon_dev_unregister() / extcon freed ... cancel_delayed_work_sync(&palmas_usb->wq_detectid); /* too late */ palmas_gpio_id_irq_handler() queues wq_detectid with a debounce delay on every ID GPIO edge, so a work instance can be pending at unbind. The handler palmas_gpio_id_detect() dereferences palmas_usb->edev via extcon_set_state_sync(). Its only early-return guard tests palmas_usb->id_gpiod (acquired before the work registration, so still valid), not ->edev, so it does not prevent the access. If the work runs in the window after the extcon device has been freed but before the work is cancelled, it dereferences freed memory -> use-after-free. Register the work for cancellation after the extcon device is allocated and registered (and before the IRQs, which queue it), so devres (LIFO) frees the IRQs first, then cancels the work, and only then frees the extcon device. The ID GPIO the handler also uses is acquired earlier and thus still outlives the work. devm_delayed_work_autocancel() still runs INIT_DELAYED_WORK() before the work is first queued (the IRQ handler and the explicit palmas_gpio_id_detect() call both run after it). Found by static analysis / code review; compile-tested only, not reproduced on hardware (requires a Palmas/TWL6035 USB PHY). Fixes: f94a5becabf4 ("extconn: Clean-up few drivers by using managed work i= nit") Cc: stable@vger.kernel.org Signed-off-by: Hyunjung Ko --- diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index d339b86..f7496e5 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -237,12 +237,6 @@ static int palmas_usb_probe(struct platform_device *pd= ev) palmas_usb->sw_debounce_jiffies =3D msecs_to_jiffies(debounce); } =20 - status =3D devm_delayed_work_autocancel(&pdev->dev, - &palmas_usb->wq_detectid, - palmas_gpio_id_detect); - if (status) - return status; - palmas->usb =3D palmas_usb; palmas_usb->palmas =3D palmas; =20 @@ -265,6 +259,12 @@ static int palmas_usb_probe(struct platform_device *pd= ev) return status; } =20 + status =3D devm_delayed_work_autocancel(&pdev->dev, + &palmas_usb->wq_detectid, + palmas_gpio_id_detect); + if (status) + return status; + if (palmas_usb->enable_id_detection) { palmas_usb->id_otg_irq =3D regmap_irq_get_virq(palmas->irq_data, PALMAS_ID_OTG_IRQ); From nobody Tue Nov 24 04:33:12 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.175 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971085; b=Vtg345/bw0RauWMxgdKY2Q/bgvJmD1moEHlwZxPMX8gnbCmZthc/AzkXqkr9zU/kwMDu QcqMnm+qlQZiynvCw/MokFrZExPR8YZLm02Obf4X1CBNzLKCwReCujpeyu+NRmRXbJnxK VMcLsEWuVN1Kox2NeIEw5VUQc69PaZ/yF2syOmJWcoUBRZom5mB85qvS9LiUqi3Fe60HX 21pcqSez2zv/BHfOuFQoZ7Wp6jPME+3RnXTcelQiqaGsFeuIm9v0pJUZ1jH0syDtnI99b 0KfCW1w0CJsHcgH8rNxzx3uO70hZB1OfkBCcHA3hFTfZMPPvyx49YC80XCFlp1iiJZw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971085; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=Dz7o2nl3YbVAvhy6+Qf4x0LfNDPFm8y7nAlJp4YSP1Q=; b=vKVCV975F8T4wtudZxZTvdvg3cMMMydBBm/jARTNL1yo+oGDzh20FVhAhpQMSQ7ra1ZT fWiM/7x6RltShuWb05X3Vxidh8ncOv88PfmJbKY6pEJSgw1hl2sXf7mWL4aV27hoFP4sY /vDohFaB/turvv2JdXsG9OJj9L0Apm7ZA0YiUPoGS8CCs/wc+ICuA5i9FuJ3QVeruiMPg doysQL2YTdKzgYiOjAuzP/2ZBzikHeWzIyY6C+e19BXERfzWKjhKADNu/YUC0pZ9Rsn9+ MYdTA2qRVVJskHFQmn5glME14M+P5m3TkHoEc60JoatMrSD1bgQgFGfoMkf3wXNpfKw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="A/CMeiFO"; arc=none smtp.remote-ip=209.85.214.175 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48EDC606A32D for ; Fri, 6 Nov 2026 13:18:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 48EDC606A32D 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=A/CMeiFO Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2ed06b725fdso10440345ad.0 for ; Fri, 06 Nov 2026 05:18:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793971084; x=1794575884; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Dz7o2nl3YbVAvhy6+Qf4x0LfNDPFm8y7nAlJp4YSP1Q=; b=A/CMeiFOpwChXu+gGgOnhDCfiXDypN1UICLSZACPhx5cv7EENCB7NnLkEnA+YSiAF3 OY3jcSURjpf6OO2+qspOv7CQTuoSUIqtWtOOuSJKTssTGtIZQO+Utdshl6kO+yVAYnFX 2jr96VKUbNi8h/xVMsog0LwbAS4BVHyci6ZQ7Pk94BlE2zlje9hq2bJfj68FneHdQZC/ vMh25aYAVS+CLD2xCJS8iQiQTjU3FX9ya8DZlSl/NsaB27ZFasPtQJG3wjOvwwqw785p EYWxeYuoDXleahTrASk0Z0stV8NR14gNs2wlOe0bj4lzHc3+xAV8kfocfrMnSsA1MpCQ ahxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793971084; x=1794575884; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Dz7o2nl3YbVAvhy6+Qf4x0LfNDPFm8y7nAlJp4YSP1Q=; b=RjDQf9Vg3k5P45MjSZ8YNY0dt7bc4yr0ANRO1GYGmodAC2gSjCQSWEpLQjC+QJBao+ wvaaNhhvvz4T/DdKuWu9ys4wpmolRlfV3+55d+z2fhOSzs2qcTpsdm+zdIQR7hM7QlZf VJYwjSvObhRmAG6/RzomHDjf5F8R8Q9OMzTaP8cQ7P+iiHITl7pHmM9ks2UPw1/x6eO3 mEQxMceutcmSqIeDxQWHx9iB9IAJpTyLMTrtE+Ggqgl9RE7mnoceh/v2ALcybq+QznRV wavMTlmx/7urjLlCoRjgvVXLdqWAtEL08kke6XJerv4my/FYodndBQf83BlX4mlFTezP PB1A== X-Gm-Message-State: APuU4Z/i6xduSAGrjEeOpw0v1qdssYZjk5YS/R3tUQHl1F2CtSGWmv3L GDSHlYM/Ee119/SP4EAeGxLjLBT5CXZ4xdcg08blrFfXpdjxRlBV/Gjl X-Gm-Gg: AYBFou22GkkhnicQhtw+xJ1bfpwrXn39rCcgW/IEjAEXCwFmHZ0qaeKvma4DWyCHlUr wDpeZ36XuN0dxtxXTbyJ/VEpBjzLr9OyAf89wyEnQUxv8lyMDrifr2k1+/a1VqhRyVf3HOwT6+y LAg79rhUDwRVGUzqo82tc3dszewVpUBh//H4Y2kfwk0ltcvLEx7mRhq2y+ywoy+t7VY9otzTAOw rlZL2il2+mvGgHV1G1sD6P1MwoCI+v0Yn5uH+Nhp3xUXPok3Jll3jF3ZWpRSnGucCB96TV44mK8 U1CrJT84JcNkFmNqdtz4acjb+oL0whamc0ZvWsVYQ2kDab2WslTZPmeUVGaSHISVd6DKqA4HTWN ZG/dn8YkYpHhk8ShUwGwC4vcSeWTsdzR5sbp5oBEpiEYtVsfNveK31faAvlNiM7lhAKJmBNi61o 9EI3wGFVNgqfT/z+vKHkLRU3BY5RqR09nE7zwSN2d63mI6othhPiS8w/XTlKOWIL1PhruUrcz/S gLyKntXuI+I1fYYBBmghcxPOAb6Il8PeX1N6QBzOupkvMNDi7rwJ7sH1Rie0vQKBSgEvwHQXXMz VB7p+SxNt5sy1jrXZB6beut1GZyLbBxDnMY8QNex2/H45iRqAmAPclMiC+ibSMN10Gs8jw== X-Received: by 2002:a17:90b:584e:b0:3a0:d82b:237b with SMTP id 98e67ed59e1d1-3b0db6e8c8cmr1498160a91.25.1793971084246; Fri, 06 Nov 2026 05:18:04 -0800 (PST) Received: from hj.. ([163.239.22.29]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0e2a8d6fbsm1025636a91.1.2026.11.06.05.18.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 05:18:03 -0800 (PST) From: hyunjungg To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, Hans de Goede , Hyunjung Ko , stable@vger.kernel.org Subject: [PATCH 3/5] extcon: max8997: drain MUIC IRQ work before extcon device is freed Date: Fri, 6 Nov 2026 22:17:28 +0900 Message-ID: <20261106131730.2633139-4-hj351016@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261106131730.2633139-1-hj351016@gmail.com> References: <20261106131730.2633139-1-hj351016@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hyunjung Ko max8997_muic_probe() registers the MUIC interrupt work for device-managed cancellation before it allocates and registers the extcon device that the work handler dereferences: INIT_WORK(&info->irq_work, max8997_muic_irq_work); devm_work_autocancel(&pdev->dev, &info->irq_work, ...); ... devm_request_threaded_irq(&pdev->dev, virq, ...); /* arms work */ ... info->edev =3D devm_extcon_dev_allocate(&pdev->dev, ...); devm_extcon_dev_register(&pdev->dev, info->edev); devres releases resources in reverse registration order, so on unbind the extcon device is torn down first and the work is cancelled last: /* free_irq() */ devm_extcon_dev_unregister() / extcon freed ... cancel_work_sync(&info->irq_work); /* too late */ max8997_muic_irq_handler() queues irq_work with schedule_work() on every MUIC interrupt, so a work instance can be pending or running at unbind. The handler max8997_muic_irq_work() dereferences info->edev via extcon_set_state_sync(). Its only early-return guard tests info->edev, but info is itself devm-allocated and freed last, so in the teardown window info->edev is a dangling (non-NULL) pointer rather than NULL and the guard does not fire. If the work runs after the extcon device has been freed but before the work is cancelled, it dereferences freed memory, i.e. a use-after-free. Allocate and register the extcon device before registering the work for cancellation (the redundant INIT_WORK() is moved up with it), so devres (LIFO) frees the IRQs first, then cancels the work, and only then frees the extcon device. devm_work_autocancel() still performs INIT_WORK() before the work is first queued (the IRQ handler, requested below, is the only queuing site). Found by static analysis / code review; compile-tested only, not reproduced on hardware (requires a MAX8997 MUIC). Fixes: 87ee8de23c9d ("extcon: extcon-max8997: Simplify driver using devm") Cc: stable@vger.kernel.org Signed-off-by: Hyunjung Ko --- diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max899= 7.c index 9cddf08..a54e7c4 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -650,6 +650,19 @@ static int max8997_muic_probe(struct platform_device *= pdev) platform_set_drvdata(pdev, info); mutex_init(&info->mutex); =20 + /* External connector */ + info->edev =3D devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable); + if (IS_ERR(info->edev)) { + dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); + return PTR_ERR(info->edev); + } + + ret =3D devm_extcon_dev_register(&pdev->dev, info->edev); + if (ret) { + dev_err(&pdev->dev, "failed to register extcon device\n"); + return ret; + } + INIT_WORK(&info->irq_work, max8997_muic_irq_work); ret =3D devm_work_autocancel(&pdev->dev, &info->irq_work, max8997_muic_irq_work); @@ -678,19 +691,6 @@ static int max8997_muic_probe(struct platform_device *= pdev) } } =20 - /* External connector */ - info->edev =3D devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable); - if (IS_ERR(info->edev)) { - dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); - return PTR_ERR(info->edev); - } - - ret =3D devm_extcon_dev_register(&pdev->dev, info->edev); - if (ret) { - dev_err(&pdev->dev, "failed to register extcon device\n"); - return ret; - } - if (pdata && pdata->muic_pdata) { struct max8997_muic_platform_data *muic_pdata =3D pdata->muic_pdata; From nobody Tue Nov 24 04:33:12 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971089; b=zc9sAR0B3uFr4KUYveRKAZsWUvZFgSlRvjMSvhISkhCY7ivPGiXM6UUAN2xTr7XZN1Bz w+LV1K/MUqBuf9ISZUojOhMCQTaut+FWhCo61J7WxjxrUBm8IGqIEMKbYgbjRxhJXCQ6S gfCtAfW6hrYjO4BD1iukv94MD730i1FvcDwTnFO0O7ESTfxtXO9x3DGgU70I2N8oozXso aCaKWWegdOvK02V9l6dJegIOjF/NcbEwACoXZ4rqg56BPkmZ2qDF2sOC3TMGPAw/LVMFW oj3DcKmqpdrue4qFEYvMrhc37ZcX50yGZJn+RDT1gCahk7pUtQknP5yQpK4bET6+pYg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971089; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=QSnpNaaEOoXXG2VcIJ6KvgGQC8uNyedzDQWKO1AUfXU=; b=idDx5bzqYuthCBQ1iOV+KtuU4NUsa6c4oYt7Uv041nSbAldJVnVWgM30zDrhVk4WWSZY RGxIqpckosQPVPBA1kOpbWnlqX+oWAmAmOJrYJPwHN3uEa96HMAGmKGnl5D7lom/3vs7U /BorIA0Yx4ArnXJG0icsj18OhTUVOphFr5wOO1dt0nmz1On11F4s67ya1bL8W1xmZH56m G+w6OVr01I2mfz4lqxZYk3WJS5v+R3cS0rey7cC8Kk5ZTfUYPpL9uS5zMEM97QXHavY2E LlN0FreDzBaC5ljKmXF+L6UaDYbhulnx/zi4WdkvqV/P7y83xtzxJ+nXusYvNgTSYUQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="cdtb/odZ"; arc=none smtp.remote-ip=209.85.215.176 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C3712606A32D for ; Fri, 6 Nov 2026 13:18:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C3712606A32D 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=cdtb/odZ Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-cd6a7b62ce8so199060a12.0 for ; Fri, 06 Nov 2026 05:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793971088; x=1794575888; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=QSnpNaaEOoXXG2VcIJ6KvgGQC8uNyedzDQWKO1AUfXU=; b=cdtb/odZNYPZvberehssdAp4j1PHi0Ykb+E1KuZluoXkDGqVL+KLjecettJ/jp6MTH g32DMbDG8ltUzJlxXitp0Uwo3aBQaw6PbodLg7XCOjpObfcsZBErr4KqKOXySnhpItMo Gjh2qHVPMhXT3YjyGc6/yVItgFbAsPRj2wLtt+zgNFwQU9k50RixcQXz6SdW7b4UbXWc 4i+oRJAhpQFVRaV0Rw8xIg7t+AUo69IqotbQHbV7Abiu+ApQbTWAeyiJsBMZXLqZkgc0 3cnqHd3ePQ7jTmXpsA6bJhy9Yxj+9WOkyB3PpYEm5pui1Jc+1taeYgbUGVl4ebtZLUUG QjGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793971088; x=1794575888; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=QSnpNaaEOoXXG2VcIJ6KvgGQC8uNyedzDQWKO1AUfXU=; b=Pw1LO9Zliaz2/DJqWZvQGa3ffdXuaXf9uJKD11Yrv3VFuUxKGMVQ9awM4kGYNqu7H9 jCPeyxKm39+lqFnZymHD0tlsIhlEej5RuGAxfQlb9sEz7pZTt7tTeEARopofoNZ7Z5xV bZ71iLLd8CLmWKObwk+KQqzsShrEvhXauaACCZ9Ac2qviCcokl06kbpd5Zf0IagiidRD ElC8Z3pbzvsmX3k8ygtoA/e6V9o0BbHvektzYiiPsFPo+p8wwHjc3L185/VpElTRze/+ eFWcdVXROYRv26q2jXeln7IWfa5l1Qgi1zN2SOZokPX4d7nTGq/5v9EDrRXnV5JhOuIo mZ3w== X-Gm-Message-State: APuU4Z93te8GgLr4AB893FnuF5hfu65MvFCCHVdan9nlUTJf2puJUB4A pXu5RqLFRpLU6ZSFlGeiRPhBkM4TjKPCuoYhejqln+h70OTp891v8jZa X-Gm-Gg: AYBFou1LCu71heyxKqwOuMmFGYYZZQwW1BKaxFLpFvhPOKEt2TPmlfcIQsmLpuB9m5O ZeFLtYCh6PUbX0sYfkZb2pEfraZJQpHKlLyKom4/+p3DeaUI9WX8laTuM21q4dzofLtCuuD5PE6 aWhDtXwity1hqgxwwNTiMVBubvTJbGg8rWLn+xyccdj66zy34YelK/ZcUD/noKzy3HZpOakKAx5 g4us0Hv5SrX3thBXHlJfJXxba6NY2cTfHSz1bkyVo+IZEyoIxsTGzWJbfM9gIFZlaR+lzY64/Hc Mt4+wjsufrJXZem53++YYKJxs3/SY9onIncoYzgocS7Z9iTRLKULxGbbbovMybEaQpkEEeHp8tj m0RCovron7657RFc264ghHY0ceirt4wYhfopl2OGZhnbBSDDgUyG1PTFjUZnqfTgJ89jGwScwJz w5YDNMKTSIFVB8qX+tFZ2ZFFTPO8BvF4E/az+AyPhi5udmUllY5m4CBUCGD1XlgO/e2tZASZ/gw dT8rIwIYtPHmnco4jBzNtpCvSqk0Xl0CGSEpnvM3rwqXGivu6Nj/THXYpp586TYx6d2HUOzrzYP MS6ZQ5sXgqqAXqEvcgYVpk6VSmeudO1oSi9tXLHnrjpKTFOk X-Received: by 2002:a17:90b:580b:b0:3ac:a203:e092 with SMTP id 98e67ed59e1d1-3b0db609a2emr2299339a91.1.1793971088077; Fri, 06 Nov 2026 05:18:08 -0800 (PST) Received: from hj.. ([163.239.22.29]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0e2a8d6fbsm1025636a91.1.2026.11.06.05.18.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 05:18:07 -0800 (PST) From: hyunjungg To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, Hans de Goede , Hyunjung Ko , stable@vger.kernel.org Subject: [PATCH 4/5] extcon: max14577: drain MUIC IRQ work before extcon device is freed Date: Fri, 6 Nov 2026 22:17:29 +0900 Message-ID: <20261106131730.2633139-5-hj351016@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261106131730.2633139-1-hj351016@gmail.com> References: <20261106131730.2633139-1-hj351016@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hyunjung Ko max14577_muic_probe() registers the MUIC interrupt work for device-managed cancellation before it allocates and registers the extcon device that the work handler dereferences: devm_work_autocancel(&pdev->dev, &info->irq_work, ...); ... devm_request_threaded_irq(&pdev->dev, virq, ...); /* arms work */ ... info->edev =3D devm_extcon_dev_allocate(&pdev->dev, ...); devm_extcon_dev_register(&pdev->dev, info->edev); devres releases resources in reverse registration order, so on unbind the extcon device is torn down first and the work is cancelled last: /* free_irq() */ devm_extcon_dev_unregister() / extcon freed ... cancel_work_sync(&info->irq_work); /* too late */ max14577_muic_irq_handler() queues irq_work with schedule_work() on every MUIC interrupt, so a work instance can be pending or running at unbind. The handler max14577_muic_irq_work() dereferences info->edev via extcon_set_state_sync(). Its only early-return guard tests info->edev, but info is itself devm-allocated and freed last, so in the teardown window info->edev is a dangling (non-NULL) pointer rather than NULL and the guard does not fire. If the work runs after the extcon device has been freed but before the work is cancelled, it dereferences freed memory, i.e. a use-after-free. Allocate and register the extcon device before registering the work for cancellation, so devres (LIFO) frees the IRQs first, then cancels the work, and only then frees the extcon device. devm_work_autocancel() still performs INIT_WORK() before the work is first queued (the IRQ handler, requested below, is the only queuing site). Found by static analysis / code review; compile-tested only, not reproduced on hardware (requires a MAX14577/MAX77836 MUIC). Fixes: 14ad76825f00 ("extcon: extcon-max14577: Fix potential work-queue can= cellation race") Cc: stable@vger.kernel.org Signed-off-by: Hyunjung Ko --- diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14= 577.c index 5476f48..1267769 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -674,6 +674,20 @@ static int max14577_muic_probe(struct platform_device = *pdev) platform_set_drvdata(pdev, info); mutex_init(&info->mutex); =20 + /* Initialize extcon device */ + info->edev =3D devm_extcon_dev_allocate(&pdev->dev, + max14577_extcon_cable); + if (IS_ERR(info->edev)) { + dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); + return PTR_ERR(info->edev); + } + + ret =3D devm_extcon_dev_register(&pdev->dev, info->edev); + if (ret) { + dev_err(&pdev->dev, "failed to register extcon device\n"); + return ret; + } + ret =3D devm_work_autocancel(&pdev->dev, &info->irq_work, max14577_muic_irq_work); if (ret) @@ -712,20 +726,6 @@ static int max14577_muic_probe(struct platform_device = *pdev) } } =20 - /* Initialize extcon device */ - info->edev =3D devm_extcon_dev_allocate(&pdev->dev, - max14577_extcon_cable); - if (IS_ERR(info->edev)) { - dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); - return PTR_ERR(info->edev); - } - - ret =3D devm_extcon_dev_register(&pdev->dev, info->edev); - if (ret) { - dev_err(&pdev->dev, "failed to register extcon device\n"); - return ret; - } - /* Default h/w line path */ info->path_usb =3D CTRL1_SW_USB; info->path_uart =3D CTRL1_SW_UART; From nobody Tue Nov 24 04:33:12 2026 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793971095; b=U3LGVxZS2yvbeOUnJxDbvALeSbWY+f+7aRKZDgGg8blvk3qVoGQq7fm6YtQ10v2nB4EG WgXqSp1W/sYvykyLu30vYn1at18eJnmi4f6BD3LvHMVwxn6B4FOoHPTgdELtQsfR/R46D 4/LXPb5xOuIIrumtOdy9cuXIcE+JgVA09RKVXgFZ12gtFkBcOgy/TFIV7ejbVogzwCzn5 eXjW3vg/H3rRSDIqV5X+5fzhM2ibILV3voddSE8V8Ruhfy+bWTEXyQNd6z3jnObpRyXgf WiVIh1JT7QSTxiL9M7ft0qt95FLqBfaoxaKpzBOSFZ/9AazYbGuP+7FUX5J5If20GNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793971095; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=lyVXxhqVdS/iGnj6NynJN3xUIHVLrLvXHKOHq+9pwkU=; b=HSBL8YXAV4QPR2mb21rVdWXYTmAxNxhWf6ppoVBX/JBWaIJQcaB+dAh3zcJyfPJQT1BB DRuNrkUR4hsWzmL67d+zJo4O4cmUhD1VMe5maV5xNgSxIudSi4mD5lwE6tOJvQDyhH5GH LxDMLlru4xfvnW5yIjVuesH5jkGJMGWsXowsVLsmyS1NZ8GtbTec6PRyNxRf4bLuJKVOt ZRcUYS34DMyTjVsAFz0pn00s52+oVpkywvrDfeRlcuxjSiX2uPAzPVqBi+ZkW80ySWslJ Bv5YDVHLPl2YLu4VCyIEpRurfAsyY4gB5NU04ISc7DQiGS8FV5kE+hqnD0XX7rrdfsA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=j7Dn4nS2; arc=none smtp.remote-ip=209.85.216.44 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72E43606A336 for ; Fri, 6 Nov 2026 13:18:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 72E43606A336 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=j7Dn4nS2 Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3b0ae87069dso280698a91.2 for ; Fri, 06 Nov 2026 05:18:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1793971094; x=1794575894; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=lyVXxhqVdS/iGnj6NynJN3xUIHVLrLvXHKOHq+9pwkU=; b=j7Dn4nS2FlTDkjtWUWwow620dude761rH0HztMU08Ws7MnpuJgtahTKaGW+wxQa6Xi t8Bw9fPSFTvs3qnx01Yrmo8pvJZloKokkDFR/hMUJkb5Hj8nUadMOspNIAhtVhccdjhT 3dlFxzhw2IabHdEp7i9bUqZ7AHYMgQAqy97E5WPoQqO6YA9Ol4x7kthmSxUOfDJMpHUy H8LFV/D8/ViViNYVEHiZ//WcpfY+F6aF6gp/fCPXHD2dssuwGgLgV4uKehiHxeCzaVyF EOMCZb0QlFJ3qFLPUIOjamEAOn7Npd26BFz1RbMHN7GnKFhYyCPGb8Og3ZUILArCcQpo 7YlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1793971094; x=1794575894; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=lyVXxhqVdS/iGnj6NynJN3xUIHVLrLvXHKOHq+9pwkU=; b=EVlA9mSisOFbfhHLu33spDenXYAcl2N/HrIqVauG/FQYA9KNlKs4/WTDMAU1SSv8aK aSYGYeVquoQ3nW9EEjOr54r3Hw/IE80dCkcMqbcu4/hYWAVEIWYm13CVOMO1MnOV8J7X NluFrg1Bg7aJ0rMenfds4I/lxYRc+r3LCawvPbRYhT64JXZ5CDyJ1ynVk0NgW4vGjw1g OZ9Vjkr+m9eJRTdCr07w4s4ZxvlYJvsBVYcLRq66kec/ekoNjTK8SNOQp4AQl5D0Vv9r /QfZIZnYrpntaqoirljalHiku9Jrg3CkHa2dXz4oc+djAZp8J6dxEdenAgOpOG4YG7Iw tmAg== X-Gm-Message-State: APuU4Z9Qe82dILOZNHackoxKA/ALQvVl/ppTTX0mK9uweHjlvX4BnUS1 x9Fvpg7jdJo52F0vQ/EePkt7uJnvM8ECZvTh6wHGa2Uew50v48DybqCB X-Gm-Gg: AYBFou0+FLD8G+G4KJOPgKbpv6TBQNP3+i1jvMYwqhm/1jpdA3IuULXz3BBIKutgW3h FjDyEVuWRhAhTbTHgy2CqfjzlEgLcJxm+lynln7kDpPO6xP5vWliXl4e+nH0j1HmMI/HxUillIA kUtroYGX2HYLfExiBH/hrluk0CUOkqAVe8gm+n16YtJVDf30MX2yyBNcPylrRN6xoUgjjidz/25 XJWXql+1ZkCaNlV7RiAwp/KTdcXGQpfiiD0Fv6e7HcW78WCfvW2OEYdtqbRv5q9TzzG5dhUpl60 G+rjbih1lMZuSR9Ops5KJZRIc6Z0hlcHUqlHSvQ8fdjKyntwuh3IkV5eVQnQU3pAv81dvNkOTjB TlqbG3HlhjYpKcrXfsSyXMNBNnqYV4PQ4WCu3TdBmcLIfk6v5cD4Mo++m1l77xjXMsTOwIU0l2f +pI/2ZoTVMttIvuldx1I3d5SorUd4M1iBn1QRlzTqUK510TAwwNsz/VL0o2g2/Dewf0FPTH2Eik 5iCtN/9M37p96kFMnZ53s3xeSXYCvgYDASbp08FkgjmRCCUUuuIpTUUz4kPVpN+9AY4RPpfUCIO aNfzELT/ycHiIhw+q+10t2qdRGv8O9gpjQ== X-Received: by 2002:a17:90b:1fc7:b0:3ab:b39f:41cd with SMTP id 98e67ed59e1d1-3b0db6ed2f0mr2460315a91.60.1793971093785; Fri, 06 Nov 2026 05:18:13 -0800 (PST) Received: from hj.. ([163.239.22.29]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b0e2a8d6fbsm1025636a91.1.2026.11.06.05.18.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Nov 2026 05:18:13 -0800 (PST) From: hyunjungg To: MyungJoo Ham , Chanwoo Choi Cc: linux-kernel@vger.kernel.org, Krzysztof Kozlowski , linux-samsung-soc@vger.kernel.org, Hans de Goede , Hyunjung Ko , stable@vger.kernel.org Subject: [PATCH 5/5] extcon: max77693: drain MUIC IRQ work before extcon device is freed Date: Fri, 6 Nov 2026 22:17:30 +0900 Message-ID: <20261106131730.2633139-6-hj351016@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261106131730.2633139-1-hj351016@gmail.com> References: <20261106131730.2633139-1-hj351016@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Hyunjung Ko max77693_muic_probe() registers the MUIC interrupt work for device-managed cancellation before it allocates and registers the extcon device that the work handler dereferences: devm_work_autocancel(&pdev->dev, &info->irq_work, ...); ... devm_request_threaded_irq(&pdev->dev, virq, ...); /* arms work */ ... info->edev =3D devm_extcon_dev_allocate(&pdev->dev, ...); devm_extcon_dev_register(&pdev->dev, info->edev); devres releases resources in reverse registration order, so on unbind the extcon device is torn down first and the work is cancelled last: /* free_irq() */ devm_extcon_dev_unregister() / extcon freed ... cancel_work_sync(&info->irq_work); /* too late */ max77693_muic_irq_handler() queues irq_work with schedule_work() on every MUIC interrupt, so a work instance can be pending or running at unbind. The handler max77693_muic_irq_work() dereferences info->edev via extcon_set_state_sync(). Its only early-return guard tests info->edev, but info is itself devm-allocated and freed last, so in the teardown window info->edev is a dangling (non-NULL) pointer rather than NULL and the guard does not fire. If the work runs after the extcon device has been freed but before the work is cancelled, it dereferences freed memory, i.e. a use-after-free. Allocate and register the extcon device before registering the work for cancellation, so devres (LIFO) frees the IRQs first, then cancels the work, and only then frees the extcon device. The dock input device the handler also uses is registered earlier and thus still outlives the work. devm_work_autocancel() still performs INIT_WORK() before the work is first queued (the IRQ handler, requested below, is the only queuing site). Found by static analysis / code review; compile-tested only, not reproduced on hardware (requires a MAX77693 MUIC). Fixes: 74047eaa2281 ("extcon: extcon-max77693.c: Fix potential work-queue c= ancellation race") Cc: stable@vger.kernel.org Signed-off-by: Hyunjung Ko --- diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77= 693.c index 2c567e0..f151787 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -1128,6 +1128,20 @@ static int max77693_muic_probe(struct platform_devic= e *pdev) platform_set_drvdata(pdev, info); mutex_init(&info->mutex); =20 + /* Initialize extcon device */ + info->edev =3D devm_extcon_dev_allocate(&pdev->dev, + max77693_extcon_cable); + if (IS_ERR(info->edev)) { + dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); + return PTR_ERR(info->edev); + } + + ret =3D devm_extcon_dev_register(&pdev->dev, info->edev); + if (ret) { + dev_err(&pdev->dev, "failed to register extcon device\n"); + return ret; + } + ret =3D devm_work_autocancel(&pdev->dev, &info->irq_work, max77693_muic_irq_work); if (ret) @@ -1156,20 +1170,6 @@ static int max77693_muic_probe(struct platform_devic= e *pdev) } } =20 - /* Initialize extcon device */ - info->edev =3D devm_extcon_dev_allocate(&pdev->dev, - max77693_extcon_cable); - if (IS_ERR(info->edev)) { - dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); - return PTR_ERR(info->edev); - } - - ret =3D devm_extcon_dev_register(&pdev->dev, info->edev); - if (ret) { - dev_err(&pdev->dev, "failed to register extcon device\n"); - return ret; - } - /* Initialize MUIC register by using platform data or default data */ if (pdata && pdata->muic_data) { init_data =3D pdata->muic_data->init_data;