From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796497871; b=oQ3jesfXJ42D+WzWjBTvJ21NT+PxVya6ui0KyYmNNxX3pCs113ynfxBzVfK0sDzu9Fdb 3m3UUfsIcltWAz255TD9uGaz4Kk+Hyh0jS7hvj1RqcOTnPsS561fhoiWPMBwrLzG2G/Sc 1lkbUUMtB4W1M0MPafcRFj2UnmtIoDxR4omiCrXbMWUhK6ahHAN+LeeSh+Va56RiMJ+Vw NFVuKjrdsfH1qkF//Hg2d0s/xyKqD9V2y9n56dYqyXkEchb4n6AIsTflQ3fFqbwrIrRXX ZlSUZOZjOwkJ9bEZCBEyOevQhxYYddktWhRhNtDtsmEmerfUrsGZNOqd7SvhY6iYyJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796497871; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=iy1BduMzkwSg6uPM8kH5Ns5bSlus5dMk12YZry7SDPY=; b=GExS2MW3n5wiGhUnJPW4y7jEDh/XH4NaCTPzJSenBOcJjOz8RyYAGjT4wpfKspAOyWw5 JOGqKERICmu+uhqvd1SB98gRkH1zYb5wn5E005hpvWmmxU15mD28YqCWvuhy0KOa/gjnT 5MMmfoZSCTH5z7F5KV5eD9G1K19zQoGx4RiSiXhETlGOzDclePw+6b4wcoJaPo5HjMhuF YuJkJxJpLRwdwoMDW+OUb2RKemP4HtQjBLXkAq4EaICgCr1Xjx+OFkgQ+ZCR+mZRBGlMn yZa8RUNxeOJe6OOlOTDyReIWV39C451NmCGaISYBjSRH5bWmTUSV7tzXCUnVZseJqZA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fL+uvN8R; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0219E606A31F for ; Sat, 5 Dec 2026 19:11:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=fL+uvN8R Received: by smtp.kernel.org (Postfix) with ESMTPSA id 875941F00A07; Sat, 5 Dec 2026 19:11:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796497870; bh=iy1BduMzkwSg6uPM8kH5Ns5bSlus5dMk12YZry7SDPY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=fL+uvN8RwPqfRsEaz50rs2aDNzrJYcZnMcw3/5EtH+LAgaMMNDHYn8FM9aUCUbpUW /8AqU0R1eZS/1cXXj41jf9va9lvfA2J68PLAS3jAPuOQv9+qQAe9/t7rjvCBeQONCU MsmJJVz9/rXrUu9EQiLb/PcO7O9YlstxRgOQS4Vc4yWkLmHIWQOkLtzfcgrwhPdh4j St0N3asJz8ZRvPyMARbsBiPzl6UajBy3L2Meh4WO6OyAzBJF3hbInNvGq31TJw9paP HdaoPS7hoiFYB8j2ryiKup15aXxCxogqRPmnoVwo325t7tqVSGPqXb3lBn0S+Wutpy WH4srupi/MC2A== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v7 06/13] HID: haptic: Convert to a loadable plugin module Reply-To: sashiko-reviews@lists.linux.dev To: "Rong Zhang" Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com In-Reply-To: <20261206-hid-haptic-kmod-v7-6-3eea47035836@rong.moe> References: <20261206-hid-haptic-kmod-v7-0-3eea47035836@rong.moe> <20261206-hid-haptic-kmod-v7-6-3eea47035836@rong.moe> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 19:11:10 +0000 X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [Medium] HID: hidinput_connect() misses driver EV_FF registered on non-first input - [Medium] HID: haptic: deferred input_ff_destroy() races with hid_plugin_cleanup() - [Low] HID: hidinput_connect() checks >=3D 0 instead of > 0 on haptic setup - [Low] hid: undocumented struct hid_device plugins type fixup belongs in prior commit -- commit 12dbd9791931128158828d6e3e2e142a60955399 Author: Rong Zhang HID: haptic: Convert to a loadable plugin module This commit converts hid-haptic into a loadable hid-plugin module and moves its feature mapping, input mapping, and FF registration hooks into hid-input. Link: https://lore.kernel.org/linux-input/auypydfkhx2eg7vp764way4batdilzc35= inqda3exwzs3tk3ff@oagat6g46zto/ > diff --git a/drivers/hid/hid-haptic.c b/drivers/hid/hid-haptic.c > index 43e9aa60fca9d..ab2366a58de4b 100644 > --- a/drivers/hid/hid-haptic.c > +++ b/drivers/hid/hid-haptic.c [ ... ] > +static bool hid_haptic_plugin_bound(struct hid_device *hdev, void *data) > +{ > + struct hid_haptic_device *haptic =3D data; > + > + return !!haptic->wq; > } > -EXPORT_SYMBOL_GPL(hid_haptic_pressure_increase); > + > +static void hid_haptic_plugin_disconnect(struct hid_device *hdev, void *= data) > +{ > + /* > + * The FF device must have been destroyed when we reach here, but if > + * something goes wrong, leak our private data and pray... > + */ > + if (!WARN_ON(hid_haptic_plugin_bound(hdev, data))) > + kfree(data); > +} [Severity: Medium] Can deferred input_ff_destroy() race with hid_plugin_cleanup() and cause a use-after-free on haptic or on unloaded hid-haptic module text? If hidinput_connect() fails after hid_haptic_init() (for example input_register_device() fails with -EINTR after device_add()), hidinput_disconnect() calls input_free_device() on the unregistered hidinput->input without calling input_ff_destroy(). When a concurrent device_for_each_child() iterator still holds a reference on &dev->dev (or under CONFIG_DEBUG_KOBJECT_RELEASE), input_dev_release() and hid_haptic_destroy() are deferred past hidinput_disconnect(). CPU0 CPU1 hidinput_disconnect() input_free_device() /* klist iter still holds ref */ put_device(&dev->dev) input_dev_release() hid_haptic_destroy() destroy_workqueue(haptic->wq) haptic->wq =3D NULL hid_plugin_cleanup() hid_haptic_plugin_disconnect() !hid_haptic_plugin_bound() kfree(haptic) module_put(plugin->owner) kfree(haptic->stop_effect...) <-- use-after-free If hid_plugin_cleanup() runs before haptic->wq is cleared, hid_haptic_plugin_disconnect() hits the WARN_ON() and leaks haptic, while hid_plugin_disconnect_with_err() still drops the module reference, allowing hid-haptic to be unloaded before hid_haptic_destroy() executes. Calling input_ff_destroy(hidinput->input) before input_free_device(hidinput->input) in hidinput_disconnect(), and clearing haptic->wq last in hid_haptic_destroy(), would avoid both races. > diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c > index 80cdd2f2beffe..05025746c80e3 100644 > --- a/drivers/hid/hid-input.c > +++ b/drivers/hid/hid-input.c [ ... ] > @@ -2409,21 +2424,43 @@ int hidinput_connect(struct hid_device *hid, unsi= gned int connect_mask) > =20 > hidinput_change_resolution_multipliers(hid); > =20 > + /* > + * If the driver manages haptic, honor its choice and do not register > + * any FF device ourselves. > + */ > + driver_ff =3D hid_haptic_connected_to_input(hid, NULL); > + haptic_ff =3D !driver_ff && hid_haptic_input_configured(hid, NULL) >=3D= 0; > + > list_for_each_entry_safe(hidinput, next, &hid->inputs, list) { > + bool first =3D list_is_first(&hidinput->list, &hid->inputs); > + > if (drv->input_configured && > drv->input_configured(hid, hidinput)) > goto out_unwind; > =20 > + if (first && !driver_ff) { > + driver_ff =3D hid_has_ff_input(hid) || !(connect_mask & HID_CONNECT_F= F); > + if (haptic_ff && driver_ff) { > + hid_info(hid, "prefer driver's FF over haptic\n"); > + haptic_ff =3D false; > + } > + } [Severity: Medium] Can this clobber and leak a driver's ff_device when a multi-input HID device registers EV_FF in drv->input_configured() on a non-first hidinput? Because the hid_has_ff_input(hid) check is gated on first, driver_ff stays false and haptic_ff stays true on later hidinput entries. If hid_haptic_input_configured() then calls hid_haptic_init() -> input_ff_create() on that same input_dev, input_ff_create() unconditionally overwrites dev->ff without destroying the driver's existing ff_device. Also, deferring !(connect_mask & HID_CONNECT_FF) until inside the loop runs hid_haptic_input_configured(hid, NULL) unnecessarily and logs "prefer driver's FF over haptic" when the driver simply omitted HID_CONNECT_FF. Checking !(connect_mask & HID_CONNECT_FF) before the loop and checking hid_has_ff_input(hid) on each iteration while !driver_ff would handle both. > if (!hidinput_has_been_populated(hidinput)) { > /* no need to register an input device not populated */ > hidinput_cleanup_hidinput(hid, hidinput); > continue; > } > =20 > - if (list_is_first(&hidinput->list, &hid->inputs) && > - (connect_mask & HID_CONNECT_FF) && hid->ff_init && > - !hid_has_ff_input(hid)) > - hid->ff_init(hid); > + if (first && !driver_ff && hid->ff_init) > + driver_ff =3D !hid->ff_init(hid); > + > + if (haptic_ff && driver_ff) { > + hid_info(hid, "prefer PIDFF over haptic\n"); > + haptic_ff =3D false; > + } else if (haptic_ff) { > + haptic_ff =3D hid_haptic_input_configured(hid, hidinput) >=3D 0; > + } [Severity: Low] Should this check > 0 instead of >=3D 0? __hid_haptic_input_configured() returns 0 once haptic FF is bound and 1 while still waiting for the target hidinput. Using >=3D 0 leaves haptic_ff true after binding succeeds, so every remaining hidinput on a multi-input device keeps calling hid_haptic_input_configured(). > diff --git a/include/linux/hid.h b/include/linux/hid.h > index f881f5631cfe5..4ea9cb4b49f9a 100644 > --- a/include/linux/hid.h > +++ b/include/linux/hid.h [ ... ] > @@ -765,7 +771,7 @@ struct hid_device { > struct hid_bpf bpf; /* hid-bpf data */ > #endif /* CONFIG_HID_BPF */ > =20 > - struct hid_plugin_private *plugins[NR_HID_PLUGINS]; > + void *plugins[NR_HID_PLUGINS]; > }; [Severity: Low] This type fixup isn't mentioned in the commit message and is unrelated to converting hid-haptic. Should it be squashed into commit "HID: Add hid-plugin framework for loadable plugin modules", which introduced struct hid_plugin_private? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-hid-haptic= -kmod-v7-0-3eea47035836@rong.moe?part=3D6