Skip to content

Commit c212956

Browse files
bryamzxzgregkh
authored andcommitted
Input: iforce - bound the device-reported force-feedback effect index
commit 0e9943d upstream. iforce_process_packet() handles a status report (packet id 0x02) by taking a force-feedback effect index straight from the device wire and using it to address the per-effect state array: i = data[1] & 0x7f; if (data[1] & 0x80) { if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) ... } else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) { ... } The index is masked only with 0x7f, so it ranges 0..127, but core_effects[] holds only IFORCE_EFFECTS_MAX (32) entries. For an index of 32..127 the test_and_set_bit()/test_and_clear_bit() is an out-of-bounds single-bit read-modify-write past the array. core_effects[] is the second-to-last member of struct iforce, so the write lands in the trailing members and beyond the embedding kzalloc()'d iforce_serio / iforce_usb object. data[1] is unvalidated device payload on both transports (the USB interrupt endpoint and serio), and the status path is not gated on force feedback being present, so a malicious or counterfeit device can set or clear a bit at an attacker-chosen offset past the object. Reject an out-of-range index instead of indexing with it. Bound against the array dimension IFORCE_EFFECTS_MAX rather than dev->ff->max_effects so the check guarantees memory safety regardless of how many effects the device registered. A legitimate "effect started/stopped" status always carries an index below IFORCE_EFFECTS_MAX, so well-formed devices are unaffected; the neighbouring mark_core_as_ready() loop is already bounded and is left untouched. Fixes: 1da177e ("Linux-2.6.12-rc2") Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me> Cc: stable@vger.kernel.org Link: https://patch.msgid.link/20260613-b4-disp-4828d263-v1-1-02320e1a89dd@proton.me Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 719d1a2 commit c212956

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

drivers/input/joystick/iforce/iforce-packets.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,18 @@ void iforce_process_packet(struct iforce *iforce,
192192

193193
/* Check if an effect was just started or stopped */
194194
i = data[1] & 0x7f;
195-
if (data[1] & 0x80) {
196-
if (!test_and_set_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
197-
/* Report play event */
198-
input_report_ff_status(dev, i, FF_STATUS_PLAYING);
195+
if (i < IFORCE_EFFECTS_MAX) {
196+
if (data[1] & 0x80) {
197+
if (!test_and_set_bit(FF_CORE_IS_PLAYED,
198+
iforce->core_effects[i].flags)) {
199+
/* Report play event */
200+
input_report_ff_status(dev, i, FF_STATUS_PLAYING);
201+
}
202+
} else if (test_and_clear_bit(FF_CORE_IS_PLAYED,
203+
iforce->core_effects[i].flags)) {
204+
/* Report stop event */
205+
input_report_ff_status(dev, i, FF_STATUS_STOPPED);
199206
}
200-
} else if (test_and_clear_bit(FF_CORE_IS_PLAYED, iforce->core_effects[i].flags)) {
201-
/* Report stop event */
202-
input_report_ff_status(dev, i, FF_STATUS_STOPPED);
203207
}
204208

205209
for (j = 3; j < len; j += 2)

0 commit comments

Comments
 (0)