From patchwork Thu Jan 26 00:24:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13116431 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51864C54EAA for ; Thu, 26 Jan 2023 00:25:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbjAZAZV (ORCPT ); Wed, 25 Jan 2023 19:25:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjAZAZU (ORCPT ); Wed, 25 Jan 2023 19:25:20 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E6F64684 for ; Wed, 25 Jan 2023 16:25:18 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id az20so1184156ejc.1 for ; Wed, 25 Jan 2023 16:25:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=uOYadJvP8u49K2x2oSYl+EYqiXssZ4idBGq/e4Tz9NY=; b=O4V0DOQaxPn+3nnvaVO3+OedTg4H8gEUR2e+X840qxeB1rz3lPMUCUHPlScsQb9ImT yOEROGe1pUIaxqUwsrMKjOB9Mqj5b6UOwVGFASYzb0AVOwqDbZnExHiTorFoOWeZPaWV 5K0fcSdfaRny3eW0RpfddFm2xA7FOcBDNEvRc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uOYadJvP8u49K2x2oSYl+EYqiXssZ4idBGq/e4Tz9NY=; b=thhHItLnTTDvocaSbabGfEXJVdCdih/Z+qrLfTdhSCpqrFzHm+srog8uw0o6pWyxox qViZvBYYYvdD79OMDi4uDDUediMCDR6gQinYP1XnES+Xw6NIVNaPBlI6JXiQzVZNef+4 qiTRjF+RU3VZNqC1V6w5YCT115CODHsq0+Oy9rPab5JMu5PL4nzHrsM9IBKT5AtmdGAW miGe7WolrjtNbyka+g6pOsDKM/cqmWfK6OLgyVGhkxKJIquOg+T7tbFn+oMeN5xssH80 Bh5AWKwpvqVf41C1kYAgVxkqG4HR0Jbb5OQsLvmB1DDKtlrSPe44MGm1pMGBOfK6zX0y WpuQ== X-Gm-Message-State: AFqh2kozzEptrI/6tTZKmQU5Lc9pB2TorrRqmAKKOjsUAAE7MzMkzvBm 0BlrYX8+Kn7zyqYeIRPr9Wg2KA== X-Google-Smtp-Source: AMrXdXuntbpvN+806ZegH5ixi1SfuWScLJxEwEMFaUWL58CNZT81ZcYZ2PCbsG6v0BxwZvZ7PsRBtQ== X-Received: by 2002:a17:907:76b0:b0:7c1:7045:1a53 with SMTP id jw16-20020a17090776b000b007c170451a53mr32550663ejc.15.1674692716489; Wed, 25 Jan 2023 16:25:16 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id jy12-20020a170907762c00b008784e808553sm555707ejc.6.2023.01.25.16.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 16:25:16 -0800 (PST) From: Pietro Borrello Date: Thu, 26 Jan 2023 00:24:53 +0000 Subject: [PATCH 1/5] HID: bigben_remove: manually unregister leds MIME-Version: 1.0 Message-Id: <20230125-hid-unregister-leds-v1-1-9a5192dcef16@diag.uniroma1.it> References: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> In-Reply-To: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Hanno Zulla , Carlo Caione , Pavel Machek , Lee Jones , Roderick Colenbrander , Sven Eckelmann Cc: linux-leds@vger.kernel.org, Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Roderick Colenbrander , Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674692715; l=1037; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=wlU1zbXd7qFTSbVqYvqS9BOVrqglVS3eHD1ePCtISHc=; b=GeizybQArtv4+HBTakrKxETsSVRvGKMNeRue1tkG2U0KcYshHgneXwski3bWn3Wnk7Dda4OEQvQ1 jAU9iMk1B2kBNODa9HOqbXggvFc3nR73/XdctsvKQ04xtFJglhqI X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Unregister the LED controllers before device removal, as bigben_set_led() may schedule bigben->worker after the structure has been freed, causing a use-after-free. Fixes: 4eb1b01de5b9 ("HID: hid-bigbenff: fix race condition for scheduled work during removal") Signed-off-by: Pietro Borrello --- drivers/hid/hid-bigbenff.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hid-bigbenff.c b/drivers/hid/hid-bigbenff.c index e8b16665860d..d3201b755595 100644 --- a/drivers/hid/hid-bigbenff.c +++ b/drivers/hid/hid-bigbenff.c @@ -306,9 +306,14 @@ static enum led_brightness bigben_get_led(struct led_classdev *led) static void bigben_remove(struct hid_device *hid) { + int n; struct bigben_device *bigben = hid_get_drvdata(hid); bigben->removed = true; + for (n = 0; n < NUM_LEDS; n++) { + if (bigben->leds[n]) + devm_led_classdev_unregister(&hid->dev, bigben->leds[n]); + } cancel_work_sync(&bigben->worker); hid_hw_stop(hid); } From patchwork Thu Jan 26 00:24:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13116433 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5E2CC61DA2 for ; Thu, 26 Jan 2023 00:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229647AbjAZAZX (ORCPT ); Wed, 25 Jan 2023 19:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjAZAZV (ORCPT ); Wed, 25 Jan 2023 19:25:21 -0500 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87C5915CBF for ; Wed, 25 Jan 2023 16:25:18 -0800 (PST) Received: by mail-ej1-x62d.google.com with SMTP id bk15so1074490ejb.9 for ; Wed, 25 Jan 2023 16:25:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=OtVGZ8lsHwJ47yfcKnn1bRe6oeChLHMzfzZSc6Gf3Bk=; b=FhM1PUIfGfe6DUD16IChGWJaU6LERUdgiPksp6xjaJUAOtm0035y/Tsd6cq+yHu7tt qT76ljpv39GRfaDNSrayfQdofiyBe9lV9P1CGOhrpAy8XokyeAoyQUTp43e+ebGlnlCR rUGXnHKg3PpjJ7CS0MsENo5zvI78JnrV1gRFQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OtVGZ8lsHwJ47yfcKnn1bRe6oeChLHMzfzZSc6Gf3Bk=; b=GGcvwbUnn9yp1rPccrRmXvdsff4oKh67IfGFWg+XRroEI1fU8PvkVZlGGgRMXMVswF WolWaNPt2MQ2wIjd9wQPbWxyXJNxmJTtNv9BE61qZ0v5xu4Osaj2XVr5KMXl4Cu3Z/u4 00ZjA31tUGYazUQ7f1FJXxaVlzbTSIsp6HSECDw/F+uYkVTAqgvtSTheXGMSHn7LXZ4y 6khzyXGUOTj9zt2mlof7ftEht4Y9zEkl6bIA2cG93RuGnhWE5tYsvTi3Y9hVbec4KP9r 6ePySwHFBfFyod7YRLBxTw4K5m88/l5oXCE/l9OYH00GKs0TzCZPIbGeKI/8Oz3WOmDD pW2g== X-Gm-Message-State: AFqh2kopgUE5k9aAMOlgbahEJBLpi8AYuMjPtNBHEDRQ5rTmwRcO418H Gsj49gzfG4H3403/bfNpwkc5uQ== X-Google-Smtp-Source: AMrXdXtDF/mhpij5N8QZ7WduZ2JyEuoRZqc/BP6mFLcsVZ5G65OUA8CUxVO1bcXYcAWmtKisdo+Lpw== X-Received: by 2002:a17:906:774f:b0:870:94e:13f9 with SMTP id o15-20020a170906774f00b00870094e13f9mr36103029ejn.0.1674692717095; Wed, 25 Jan 2023 16:25:17 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id jy12-20020a170907762c00b008784e808553sm555707ejc.6.2023.01.25.16.25.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 16:25:16 -0800 (PST) From: Pietro Borrello Date: Thu, 26 Jan 2023 00:24:54 +0000 Subject: [PATCH 2/5] HID: asus_remove: manually unregister led MIME-Version: 1.0 Message-Id: <20230125-hid-unregister-leds-v1-2-9a5192dcef16@diag.uniroma1.it> References: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> In-Reply-To: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Hanno Zulla , Carlo Caione , Pavel Machek , Lee Jones , Roderick Colenbrander , Sven Eckelmann Cc: linux-leds@vger.kernel.org, Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Roderick Colenbrander , Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674692715; l=841; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=6oFA70DnzD6hxYzPyFU4oYw2osDEjulwpyTezPO1v4g=; b=LanraiZGbk3yNg4MlXZkhk/27dt0SorHwntfu9nVSjCCqJi6acwSDXB4OPEZrVMyTlOv0T7cuAF5 Y31n2QKECy5DcyMwxWkrtks5NJOh29fDMmZpo8w47onA6s9bTu0/ X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Unregister the LED controller before device removal, as asus_kbd_backlight_set() may schedule led->work after the structure has been freed, causing a use-after-free. Fixes: af22a610bc38 ("HID: asus: support backlight on USB keyboards") Signed-off-by: Pietro Borrello --- drivers/hid/hid-asus.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c index f99752b998f3..0f274c8d1bef 100644 --- a/drivers/hid/hid-asus.c +++ b/drivers/hid/hid-asus.c @@ -1122,6 +1122,7 @@ static void asus_remove(struct hid_device *hdev) if (drvdata->kbd_backlight) { drvdata->kbd_backlight->removed = true; + devm_led_classdev_unregister(&hdev->dev, &drvdata->kbd_backlight->cdev); cancel_work_sync(&drvdata->kbd_backlight->work); } From patchwork Thu Jan 26 00:24:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13116434 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C4EC9C27C76 for ; Thu, 26 Jan 2023 00:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230253AbjAZAZX (ORCPT ); Wed, 25 Jan 2023 19:25:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235501AbjAZAZW (ORCPT ); Wed, 25 Jan 2023 19:25:22 -0500 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DA521F909 for ; Wed, 25 Jan 2023 16:25:19 -0800 (PST) Received: by mail-ej1-x633.google.com with SMTP id kt14so1152819ejc.3 for ; Wed, 25 Jan 2023 16:25:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=KVEYvFEMrraWoQ7QT2wXIP7h3ryQSGtMxUMhn5j85to=; b=C3EeXIM8zZRnu5xNrA8Gc9HN0F5GlwEdD02/sPoHMzFozJ4magY30282G8iG5H4zIz b9x68i45tj+rOwlZUFjohp1XpW6SLbEjZEuTPXhU1JuMzYSgRCGrPYya4yNm20NuH8jP aKgcw26/1izrmQj6m5B8CdqbErUk+2l8pTrCE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KVEYvFEMrraWoQ7QT2wXIP7h3ryQSGtMxUMhn5j85to=; b=RuaQTO+Zc6Jq7mNpDiY43f1tVWC+fdr1Bujdp+RFDGnKrLDLPECO/55UxelUPjk5Cd khV5RGIODwFYb+0TdyhAEUOsQZ/Uye2RqKLeTz9ox+X9E4k+oHz38sYbCDeOc6gOpW/W 6+o+smk1uEXxRO4kS6ErYuqBiekOnc2ZCYmZpKe4fj6IJhY7HagKSb+SmdyfelnQiHGT VMXkQWKsv+mTkMCJ2xT/nEg6sq04pe05d9Qc/jOhDWy/bJK9sb08yGBgSzf+dq0IskQj T1vewfKkwpUfWBcZBgiRNSPmFcJyzdBK8OP6lLYoU0qRL5ZCPa/zU6lTn8+p6Sl37nEH j5Kw== X-Gm-Message-State: AFqh2kr0Ns+cPBSV+J+WliMDGtV+u9Cvue/tYCyz8WFCxNzjustOssoo mkjSyO7iJbyiDV/O348xvBUCUw== X-Google-Smtp-Source: AMrXdXvNB5ebPAPHq8AehhbAuiTcZz8be6ERSXcRmw+xrVEERM1j2n0aZM4LEzaB6iG8VQieBFZAqg== X-Received: by 2002:a17:906:a058:b0:84d:4e9b:ace5 with SMTP id bg24-20020a170906a05800b0084d4e9bace5mr32825179ejb.67.1674692717739; Wed, 25 Jan 2023 16:25:17 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id jy12-20020a170907762c00b008784e808553sm555707ejc.6.2023.01.25.16.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 16:25:17 -0800 (PST) From: Pietro Borrello Date: Thu, 26 Jan 2023 00:24:55 +0000 Subject: [PATCH 3/5] HID: dualsense_remove: manually unregister leds MIME-Version: 1.0 Message-Id: <20230125-hid-unregister-leds-v1-3-9a5192dcef16@diag.uniroma1.it> References: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> In-Reply-To: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Hanno Zulla , Carlo Caione , Pavel Machek , Lee Jones , Roderick Colenbrander , Sven Eckelmann Cc: linux-leds@vger.kernel.org, Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Roderick Colenbrander , Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674692715; l=1139; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=SvER2QR/buwN2h3b+3BWIArkM0IQ7m++XDGtEXQz+9g=; b=qW9+bWMaNmKhDr6NQKingzmD9HAWuZOqvux3OkWnb+BMnkHySl4U1rk2fuaF+vhNLEyXt1df4IWn +5poktuVDNCULHaugZqS3T8NwCRpB0Dm0fX+dmcfj3crVpz6EHU1 X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Unregister the LED controller before device removal, as dualsense_player_led_set_brightness() may schedule output_worker after the structure has been freed, causing a use-after-free. Fixes: 8c0ab553b072 ("HID: playstation: expose DualSense player LEDs through LED class.") Signed-off-by: Pietro Borrello --- drivers/hid/hid-playstation.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 27c40894acab..9e23860b7e95 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -1503,11 +1503,15 @@ static void dualsense_remove(struct ps_device *ps_dev) { struct dualsense *ds = container_of(ps_dev, struct dualsense, base); unsigned long flags; + int i; spin_lock_irqsave(&ds->base.lock, flags); ds->output_worker_initialized = false; spin_unlock_irqrestore(&ds->base.lock, flags); + for (i = 0; i < ARRAY_SIZE(ds->player_leds); i++) + devm_led_classdev_unregister(&ps_dev->hdev->dev, &ds->player_leds[i]); + cancel_work_sync(&ds->output_worker); } From patchwork Thu Jan 26 00:24:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13116436 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63B1AC61D9D for ; Thu, 26 Jan 2023 00:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235501AbjAZAZ0 (ORCPT ); Wed, 25 Jan 2023 19:25:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35262 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbjAZAZW (ORCPT ); Wed, 25 Jan 2023 19:25:22 -0500 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A987F64687 for ; Wed, 25 Jan 2023 16:25:19 -0800 (PST) Received: by mail-ej1-x634.google.com with SMTP id bk15so1074601ejb.9 for ; Wed, 25 Jan 2023 16:25:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=IWJPaMXoH2PrQS6MMYyiTrpadygd8fEOfJS6Z2yu7Wk=; b=GVfiLyBjO/3PtwYrQ9lPdzDSU16lro04OGdbj/pvVeutN4lQQ/RlpnuTRuK1UVP2iS Xc/i6ZRqCLD1KyXf3DQ5g5yQ2GnuXG3sDADkCtXL7X544EQa++Ma4S5cyS/NKUPQj3NB rVBQ+Kt4N4x5cy9btk3nuMpSnkQYsB9RpZlio= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=IWJPaMXoH2PrQS6MMYyiTrpadygd8fEOfJS6Z2yu7Wk=; b=v1JkE2j8UHMjRk5X4IaxIc1g4dczwwIkQ0ICLlvfs3lrGOLRGziEMgwZcTOR/6hYQe oOALm5rBnl9B8bWMP162Q9HD8Lr++Ax5hpWP4KWAldipwHIDgwDvxvDmw8xiTHWWG1fz X2JpHK3KfRv4cbgZ2lGw2A5DgmFkWaQn819sqJFLQXIhLnumarjDgeZbG2Lp3E1ZWKsM r7byLU8YMRxh/t0zCLDTmOYcQdB0dLV9fvJb1na/NLNn0zX68YzpKX4kbnATARoIshOE PkqMCDRYOdN/GVdunWooS8BZOJPU/Q6aW6vtg/3FJSEmAQRVUVecwoiCXqyzUiJjV/FI FFQQ== X-Gm-Message-State: AFqh2kptFF7dJkYRUR7p5F+KRQTUK8TeGrCxMu/0GOhu8TwoD5OnQkP8 Txp5EWLOtNZrHRSIsddIqZ9XEA== X-Google-Smtp-Source: AMrXdXv+0BffhjLuqkEBd9lTBLw8uv8bcIerolRnD+gWDGLAHMoX4oyLDYgnS4xQpZ51+Q09mCh2Rw== X-Received: by 2002:a17:906:d9db:b0:86e:2c11:9bd5 with SMTP id qk27-20020a170906d9db00b0086e2c119bd5mr37329496ejb.56.1674692718215; Wed, 25 Jan 2023 16:25:18 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id jy12-20020a170907762c00b008784e808553sm555707ejc.6.2023.01.25.16.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 16:25:17 -0800 (PST) From: Pietro Borrello Date: Thu, 26 Jan 2023 00:24:56 +0000 Subject: [PATCH 4/5] HID: dualshock4_remove: manually unregister leds MIME-Version: 1.0 Message-Id: <20230125-hid-unregister-leds-v1-4-9a5192dcef16@diag.uniroma1.it> References: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> In-Reply-To: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Hanno Zulla , Carlo Caione , Pavel Machek , Lee Jones , Roderick Colenbrander , Sven Eckelmann Cc: linux-leds@vger.kernel.org, Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Roderick Colenbrander , Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674692715; l=1198; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=LeHfl1tt40cP85uXQcC/duWnRACVmqzbUtWz/wcGE/A=; b=xsUYK5juv7Wd5lxRVyEZM0ZE5k03Jar9TWnZDsr7679SNhg6ZPP9DAsElhLipGvZoG+8NpBp9OjA +it8s7MyANzuraxYDILrnI0OGpiH11w71JNTPyFZts88djtiHerU X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Unregister the LED controller before device removal, as dualshock4_led_set_brightness() may schedule output_worker after the structure has been freed, causing a use-after-free. Fixes: 4521109a8f40 ("HID: playstation: support DualShock4 lightbar.") Signed-off-by: Pietro Borrello --- drivers/hid/hid-playstation.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c index 9e23860b7e95..6fae5a24eaad 100644 --- a/drivers/hid/hid-playstation.c +++ b/drivers/hid/hid-playstation.c @@ -2432,11 +2432,15 @@ static void dualshock4_remove(struct ps_device *ps_dev) { struct dualshock4 *ds4 = container_of(ps_dev, struct dualshock4, base); unsigned long flags; + int i; spin_lock_irqsave(&ds4->base.lock, flags); ds4->output_worker_initialized = false; spin_unlock_irqrestore(&ds4->base.lock, flags); + for (i = 0; i < ARRAY_SIZE(ds4->lightbar_leds); i++) + devm_led_classdev_unregister(&ps_dev->hdev->dev, &ds4->lightbar_leds[i]); + cancel_work_sync(&ds4->output_worker); if (ps_dev->hdev->product == USB_DEVICE_ID_SONY_PS4_CONTROLLER_DONGLE) From patchwork Thu Jan 26 00:24:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pietro Borrello X-Patchwork-Id: 13116435 X-Patchwork-Delegate: jikos@jikos.cz Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85A6BC54EAA for ; Thu, 26 Jan 2023 00:25:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229876AbjAZAZY (ORCPT ); Wed, 25 Jan 2023 19:25:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235840AbjAZAZW (ORCPT ); Wed, 25 Jan 2023 19:25:22 -0500 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 340F864683 for ; Wed, 25 Jan 2023 16:25:20 -0800 (PST) Received: by mail-ej1-x62c.google.com with SMTP id ud5so1139596ejc.4 for ; Wed, 25 Jan 2023 16:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=diag.uniroma1.it; s=google; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=rBEBor+gnsfUYPOUW+OLBqnWMEjDoXQsh85+8ApHEhw=; b=kYwY+kVYV/Q1HAOK4nSWSqU2aS/vnszT5DoWgnuvCPJlFXba9yQLFA32M1r81JvmLW k1po+3OJS2h04DoboLdK9AkYAfNIgjf6/OU6G6hwVSzXajteF2EdZ9HvGJFRvNheNsBh r938rP9fDZbvnBT/zlgk1G3bNX5iZ4ZLw0/Qg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rBEBor+gnsfUYPOUW+OLBqnWMEjDoXQsh85+8ApHEhw=; b=V/+p4yjN8MOs6aD073xSA1TYBQ8XccVxX0ZmPNBTmaNx/Iv/mfW/QDF2JcUrp3K0Sw BIoA3amACau6INYm2NJYQfSk/CN9PjceIb3KoowBs+dHpF+vDgnt6KrmMRVJGehQOh1+ gT4golws+/f0ixFY2IrWipXHT5S5rZHyE1p7h4tRjisMutFUD86/PV5FOpMb78qX2H8T myt1lTdpFu6Ar3Vrx5j20kFHuql9fpZWFib0I63m9Kqb0TXGxQ7B4yXmuCAeUsTy/1vK jeqWjCXaxkNJkmObS5nu4ZeZkydl6e7UUa5H5b0PQFt4162eE61U2RsR1bX/YBwDuDHg qBmA== X-Gm-Message-State: AFqh2kq66i4c3YmUnpw9dS6MPWqEEaQcqbZpt0uST4FfIIYBYQDakPiV kBiHTQBJOpX02cWvLBSEy4Zdzg== X-Google-Smtp-Source: AMrXdXvJIC2UGnr/1hfI3axwW49AFykjf04VfF8qw+mj4LupHpC31heF7B0mpWUctTgn/O1q9rIN/A== X-Received: by 2002:a17:906:6c97:b0:870:34c:97cd with SMTP id s23-20020a1709066c9700b00870034c97cdmr36269656ejr.25.1674692718718; Wed, 25 Jan 2023 16:25:18 -0800 (PST) Received: from [192.168.17.2] (wolkje-127.labs.vu.nl. [130.37.198.127]) by smtp.gmail.com with ESMTPSA id jy12-20020a170907762c00b008784e808553sm555707ejc.6.2023.01.25.16.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Jan 2023 16:25:18 -0800 (PST) From: Pietro Borrello Date: Thu, 26 Jan 2023 00:24:57 +0000 Subject: [PATCH 5/5] HID: sony_remove: manually unregister leds MIME-Version: 1.0 Message-Id: <20230125-hid-unregister-leds-v1-5-9a5192dcef16@diag.uniroma1.it> References: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> In-Reply-To: <20230125-hid-unregister-leds-v1-0-9a5192dcef16@diag.uniroma1.it> To: Jiri Kosina , Benjamin Tissoires , Hanno Zulla , Carlo Caione , Pavel Machek , Lee Jones , Roderick Colenbrander , Sven Eckelmann Cc: linux-leds@vger.kernel.org, Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Roderick Colenbrander , Pietro Borrello X-Mailer: b4 0.11.1 X-Developer-Signature: v=1; a=ed25519-sha256; t=1674692715; l=1310; i=borrello@diag.uniroma1.it; s=20221223; h=from:subject:message-id; bh=ZOrIdJOdwJPCFoQ8po11GD9ZIwbv+SiF+0joUOhG2lc=; b=yDx0s+P1ZVx5mqJlSm2mB+LHUgB4rhTcR2ZrYHpbnNZXiW2UzAypHnRsFGPsPUP2VDdK7g70wdPh 6a6ui0PpAfe1uO8u0jYA4LK0oT6VyntdmYWUHPnsYRHg9jDtnQJr X-Developer-Key: i=borrello@diag.uniroma1.it; a=ed25519; pk=4xRQbiJKehl7dFvrG33o2HpveMrwQiUPKtIlObzKmdY= Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org Unregister the LED controller before device removal, as sony_led_set_brightness() may schedule sc->state_worker after the structure has been freed, causing a use-after-free. Fixes: 0a286ef27852 ("HID: sony: Add LED support for Sixaxis/Dualshock3 USB") Signed-off-by: Pietro Borrello Reviewed-by: Sven Eckelmann --- drivers/hid/hid-sony.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index 13125997ab5e..146677c8319c 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c @@ -3083,6 +3083,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) static void sony_remove(struct hid_device *hdev) { struct sony_sc *sc = hid_get_drvdata(hdev); + int n; if (sc->quirks & (GHL_GUITAR_PS3WIIU | GHL_GUITAR_PS4)) { del_timer_sync(&sc->ghl_poke_timer); @@ -3100,6 +3101,13 @@ static void sony_remove(struct hid_device *hdev) if (sc->hw_version_created) device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); + if (sc->quirks & SONY_LED_SUPPORT) { + for (n = 0; n < sc->led_count; n++) { + if (sc->leds[n]) + devm_led_classdev_unregister(&hdev->dev, sc->leds[n]); + } + } + sony_cancel_work_sync(sc); sony_remove_dev_list(sc);