From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f177.google.com (mail-dy1-f177.google.com [74.125.82.177]) (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 0D4763D5246 for ; Sat, 10 Oct 2026 03:54:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791604478; cv=none; b=FNdPS5/SK9x74lt6jR0zPO5P8KKuRXwDpqCCVVLsPUyAkectHvTDRJ5tuk3hx/uGrC81FGLpa+frMRQSMXzZu1JwJg210wcNE8erEpczR1ZoblFKWE9TGtyksqSTPUIxe4Xdf2J88V/uaUSsdpDax2pzR7A6Zl0aQpfx03QW7ec= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791604478; c=relaxed/simple; bh=E3OfWjKgzWyDeHmbfWxXxs2nHwltc6oMVbabWzulk3M=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=ftyFqKc08CvEHs4DbDkmxe/UlnR2v4HWekAYKBzaLV/i/jZBgSzD5lT5Ay86i2+nnEQ7yEETWLV5jdB0MEw6BfHFNSm80MMrqw4YIu1KGJaYt8vP3FXOSKxXsTKyE+MHnz6q5R+5MrH/LW+7JQ5mEeBkAu381t7vPMEjoL8r8ms= 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=EvbBv8GY; arc=none smtp.client-ip=74.125.82.177 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="EvbBv8GY" Received: by mail-dy1-f177.google.com with SMTP id 5a478bee46e88-33bf40b0c8bso890192eec.0 for ; Fri, 09 Oct 2026 20:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1791604472; x=1792209272; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cBTVSE4A44sNti8mHWZCj/98x3Vgj4Pdkek4UKjOJg0=; b=EvbBv8GYgPwVDk9LU6NbZF1GTnfgNGB+sNr8ANrlopAqklyYbGRTj09I9GheojwWHu niA/k2kfn9cOX+64OVNjwl+wnETLBygSDpGXEt1QR6MSkD/zQqnTJWKotFA7SsczXEhd J4HgtgSsPpaUoB8PIplsfeRS/IspR8zKB7Poyx1cmpxjJTHORSlSJrM5mGJuSWHBAqgg fBS6oKVvj5QBnIwCdSTQcjyouLim0QxXcb16n3zt6SiR4E+JTghpw4WpyYMO+oOkYanc 1d/Vic6930ZfVaPCPLjVmA+Zt/ddEcahdQOYakD2TRuhGcZfkXRmnfsWaYEKU/uaxxPP cl+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1791604472; x=1792209272; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=cBTVSE4A44sNti8mHWZCj/98x3Vgj4Pdkek4UKjOJg0=; b=WOO8o5ZeLoZlw3OH1DoEWzAPK5ub6sPGEWnbUTPJ7WtlLJlfoAIE+QCe9lXSn9UvTf m1anxq5nkMqV2fLIIKCt5v6+KiN5Q+CIdgTnO7okECpiI8HEFlFjniTHj+NQW9w7+aLI He6q0cpzna2OP1EimZG118TwYpczgJM6D+WEv7GTN68KdbUcO3uOQTkA9c6WVDlFYWh+ jqMM6CnVk+JlA7ODM+jsDdLTLUpvoyV9rHORpzhMzynmQlga7uF5axon4JtQXs46/lKR 1gAzCYKJZeCQsqC1BX963UD+JTyTG8k2Pfcne0mTaMdEZp4Vmxt8GpZApbXKSh7NeQS+ CLow== X-Gm-Message-State: AFq9FYL75WtI/pmKDaRukeOe/D+oCyndNjF71e80V6a3kqjIgoDiqmeC erNS7eYWWjFWZI2HsnLajAcCf7feUfe7hQ+Qs1D77b64I5ziO7tH0uMQ X-Gm-Gg: AYBFou0vGKfLmOGF0fZ+lsbuFID5OXdpUcrE2CPVBxOqnWFt8tuUFItACr5PBGpZ5IR WH4KgLuimCwmHdOmbyl9szfcai64YhnsyXPbvnqXRuymmOl70lHJ6MlcCiRp23uZq188gL57LR7 q89PK7UvfoUst4OvYKhrZJ73dGk8jPpgiBfVeQn+Zcvmu83K11dLJyXozIGez+AdkgPBfL5oSSC 9y4cHWS3PCos2noNupsfhVGIrvNG1hZH+mXa+TJrSCXbGGRRCROhfA6V+gEuVrWsKNOAkmR4/ws cRt4Yn1EVysaLGN1JdMwEvsFPnKJnRExfDDW7YQmt+WLpJptJQBvEtm7/kOcqkRTouT9HdNRqSx mthwb2BSmmKhN9toyh5Q+PiMfFk0KLZo+iHgxfZwthaHpuUX5RwlKnoL/J0LLyz1jBuVgMW2l/x E81PV82DVDhdye9YRy4LqtBVrorY+7kOFWLUgsu/2tQOphErBVG0Uf77ZHOgTriEydnzLQ6ANsv wNcRdFU0/8MmGdCxebd19ozn8dYGzezQeiDwpMV X-Received: by 2002:a05:701b:4306:20b0:154:e9d2:d741 with SMTP id a92af1059eb24-16a6187e53bmr4626341c88.8.1791604471593; Fri, 09 Oct 2026 20:54:31 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:b7ea:19aa:c6f7:8c02]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-169a1dd57d0sm10171926c88.8.2026.10.09.20.54.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2026 20:54:30 -0700 (PDT) Date: Fri, 9 Oct 2026 20:54:28 -0700 From: Dmitry Torokhov To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Benjamin Tissoires , Jiri Kosina , Christian Lamparter Subject: [PATCH] Input: reject parent overrides on managed input devices Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline When an input device is allocated with devm_input_allocate_device(), the owner struct device is set as dev->dev.parent and holds the devm_input_device_release resource. Later, input_register_device() attaches the devm_input_device_unregister resource to dev->dev.parent. Clearing or overriding dev->dev.parent before registration splits devres ownership across different devices, which breaks managed lifetime assumptions. Verify via devres_find() that dev->dev.parent is non-NULL and still holds the matching devm_input_device_release entry before registering a managed input device, rejecting registration with -EINVAL otherwise. Also add KUnit test coverage in input_test.c verifying that reparented and NULL-parent managed input devices are rejected while preserving the owner parent succeeds. Assisted-by: LLM Signed-off-by: Dmitry Torokhov --- drivers/input/input.c | 8 ++++++++ drivers/input/tests/input_test.c | 34 ++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/drivers/input/input.c b/drivers/input/input.c index ac0369414687..76ed9ff40584 100644 --- a/drivers/input/input.c +++ b/drivers/input/input.c @@ -2417,6 +2417,14 @@ int input_register_device(struct input_dev *dev) } if (dev->devres_managed) { + if (!dev->dev.parent || + !devres_find(dev->dev.parent, devm_input_device_release, + devm_input_device_match, dev)) { + dev_err(&dev->dev, + "Parent of managed input device was overridden, refusing to register\n"); + return -EINVAL; + } + devres = devres_alloc(devm_input_device_unregister, sizeof(*devres), GFP_KERNEL); if (!devres) diff --git a/drivers/input/tests/input_test.c b/drivers/input/tests/input_test.c index e105ce71a920..b8c8f04c041b 100644 --- a/drivers/input/tests/input_test.c +++ b/drivers/input/tests/input_test.c @@ -8,6 +8,7 @@ #include #include +#include #include #define POLL_INTERVAL 100 @@ -161,11 +162,44 @@ static void input_test_grab(struct kunit *test) input_put_device(input_dev); } +static void input_test_managed_parent_override(struct kunit *test) +{ + struct device *owner, *other_dev; + struct input_dev *input_dev; + + owner = kunit_device_register(test, "input-test-owner"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, owner); + + other_dev = kunit_device_register(test, "input-test-other"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, other_dev); + + /* Overriding dev.parent to another device must be rejected */ + input_dev = devm_input_allocate_device(owner); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, input_dev); + input_dev->name = "Managed input device (reparented)"; + input_dev->dev.parent = other_dev; + KUNIT_EXPECT_EQ(test, input_register_device(input_dev), -EINVAL); + + /* Clearing dev.parent to NULL must be rejected */ + input_dev = devm_input_allocate_device(owner); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, input_dev); + input_dev->name = "Managed input device (null parent)"; + input_dev->dev.parent = NULL; + KUNIT_EXPECT_EQ(test, input_register_device(input_dev), -EINVAL); + + /* Preserving original owner as dev.parent succeeds */ + input_dev = devm_input_allocate_device(owner); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, input_dev); + input_dev->name = "Managed input device (valid parent)"; + KUNIT_EXPECT_EQ(test, input_register_device(input_dev), 0); +} + static struct kunit_case input_tests[] = { KUNIT_CASE(input_test_polling), KUNIT_CASE(input_test_timestamp), KUNIT_CASE(input_test_match_device_id), KUNIT_CASE(input_test_grab), + KUNIT_CASE(input_test_managed_parent_override), { /* sentinel */ } }; -- 2.56.0.385.gd3acb90ef8-goog -- Dmitry