Linux kernel -stable discussions
 help / color / mirror / Atom feed
From: Jinmo Yang <jinmo44.yang@gmail.com>
To: security@kernel.org
Cc: lains@riseup.net, hadess@hadess.net, jikos@kernel.org,
	bentiss@kernel.org, Jinmo Yang <jinmo44.yang@gmail.com>,
	stable@vger.kernel.org
Subject: [PATCH] HID: logitech-hidpp: fix slab-out-of-bounds write in HIDPP_FF_DESTROY_EFFECT
Date: Sun, 10 May 2026 22:31:18 +0900	[thread overview]
Message-ID: <20260510133118.337026-1-jinmo44.yang@gmail.com> (raw)
In-Reply-To: <20260510132917.335796-1-jinmo44.yang@gmail.com>

Add a missing bounds check in hidpp_ff_work_handler() for the
HIDPP_FF_DESTROY_EFFECT case.

When erasing a force-feedback effect that was never uploaded,
hidpp_ff_find_effect() returns 0 and this value is stored in
wd->params[0].  The handler then computes effect_ids[params[0] - 1],
i.e. effect_ids[-1], which is a slab-out-of-bounds write of -1.

The symmetric HIDPP_FF_DOWNLOAD_EFFECT case already guards the access
with `slot > 0 && slot <= data->num_effects`.  Apply the same bounds
check to HIDPP_FF_DESTROY_EFFECT.

KASAN report (on 7.0.5 with raw-gadget G920 emulation):

  BUG: KASAN: slab-out-of-bounds in hidpp_ff_work_handler+0x980/0x9d0
  Write of size 4 at addr ffff888003013afc by task kworker/u8:0/12

  The buggy address belongs to the object at ffff888003013ae0
   which belongs to the cache kmalloc-16 of size 16
  The buggy address is located 12 bytes to the right of
   allocated 16-byte region [ffff888003013ae0, ffff888003013af0)

Fixes: ff21a635dd1a ("HID: logitech-hidpp: Force feedback support for the Logitech G920")
Cc: stable@vger.kernel.org
Signed-off-by: Jinmo Yang <jinmo44.yang@gmail.com>
---
 drivers/hid/hid-logitech-hidpp.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2525,12 +2525,14 @@
 		}
 		break;
 	case HIDPP_FF_DESTROY_EFFECT:
-		if (wd->effect_id >= 0)
-			/* regular effect destroyed */
-			data->effect_ids[wd->params[0]-1] = -1;
-		else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER)
-			/* autocenter spring destoyed */
+		if (wd->effect_id >= 0) {
+			u8 slot = wd->params[0];
+
+			if (slot > 0 && slot <= data->num_effects)
+				data->effect_ids[slot - 1] = -1;
+		} else if (wd->effect_id >= HIDPP_FF_EFFECTID_AUTOCENTER) {
 			data->slot_autocenter = 0;
+		}
 		break;
 	case HIDPP_FF_SET_GLOBAL_GAINS:
 		data->gain = (wd->params[0] << 8) + wd->params[1];
--
2.39.2

       reply	other threads:[~2026-05-10 13:31 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20260510132917.335796-1-jinmo44.yang@gmail.com>
2026-05-10 13:31 ` Jinmo Yang [this message]
2026-05-10 16:19   ` [PATCH] HID: logitech-hidpp: fix slab-out-of-bounds write in HIDPP_FF_DESTROY_EFFECT Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260510133118.337026-1-jinmo44.yang@gmail.com \
    --to=jinmo44.yang@gmail.com \
    --cc=bentiss@kernel.org \
    --cc=hadess@hadess.net \
    --cc=jikos@kernel.org \
    --cc=lains@riseup.net \
    --cc=security@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox