All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Griffin Kroah-Hartman" <griffin@kroah.com>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2 2/3] Input: xpad - add packet length check for xpad_process_packet()
Date: Wed, 05 Aug 2026 10:11:02 +0000	[thread overview]
Message-ID: <20260805101103.6AA231F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260805-xpadone_length_checks-v2-2-f3e925e0280b@kroah.com>

Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:

New issues:
- [Low] Using `min(len, XPAD_PKT_LEN)` causes a compiler warning due to mismatched types.

Pre-existing issues:
- [High] The patch adds a packet length check to `xpad_process_packet` to prevent OOB reads, but misses identical vulnerabilities in `xpad360_process_packet` and `xpad360w_process_packet`.
- [High] The `xpad->work` workqueue item can execute after `xpad` is freed in the `xpad_probe()` error path for wireless Xbox 360 controllers.
--

--- Patch [2]: [PATCH v2 2/3] Input: xpad - add packet length check for xpad_process_packet() ---
commit 871137dca87547e72930981b59cce6b2b69f5992
Author: Griffin Kroah-Hartman <griffin@kroah.com>

Input: xpad - add packet length check for xpad_process_packet()

This patch adds a bounds check to xpad_process_packet() to ensure that the
processed packet is at least 20 bytes long. This prevents a potential
out-of-bounds read if a shorter packet is received.

> diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
> index 9ce792503b3a4..83bc361b15f76 100644
> --- a/drivers/input/joystick/xpad.c
> +++ b/drivers/input/joystick/xpad.c
[ ... ]
> @@ -1259,7 +1262,7 @@ static void xpad_irq_in(struct urb *urb)
>  		xpadone_process_packet(xpad, 0, xpad->idata, urb->actual_length);

[Severity: Low]
Does the min() check in xpadone_process_packet() cause a compiler warning?

Comparing a u32 (len) with a literal 64 (XPAD_PKT_LEN) using min() causes a
'comparison of distinct pointer types lacks a cast' warning due to strict
type checking. Would min_t(u32, len, XPAD_PKT_LEN) be more appropriate here
to avoid build failures when compiled with -Werror?

>  		break;
>  	default:
> -		xpad_process_packet(xpad, 0, xpad->idata);
> +		xpad_process_packet(xpad, 0, xpad->idata, urb->actual_length);

[Severity: High]
This isn't a bug introduced by this patch, but does this same vulnerability
exist for the Xbox 360 packet handlers?

In xpad_irq_in(), a malicious or malfunctioning USB device sending short
interrupt packets can cause xpad360_process_packet() or
xpad360w_process_packet() to be called without passing or verifying
urb->actual_length. This allows unconditional reads of up to 14 bytes
from the xpad->idata buffer, potentially reading stale data in the same
way this patch prevents for xpad_process_packet().

[Severity: High]
This isn't a bug introduced by this patch, but can the xpad->work workqueue
execute after xpad is freed in the xpad_probe() error path?

If an XTYPE_XBOX360W controller is detected during probe,
xpad360w_start_input() submits xpad->irq_in and then calls
xpad_inquiry_pad_presence(). If this fails, it kills the URB and returns
an error, causing xpad_probe() to free xpad via kfree().

However, if the USB device completes an interrupt transfer immediately
after irq_in is submitted, xpad_irq_in() will call
xpad360w_process_packet(), which schedules xpad->work:

drivers/input/joystick/xpad.c:xpad360w_process_packet() {
    ...
    if (xpad->pad_present != present) {
        xpad->pad_present = present;
        schedule_work(&xpad->work);
    }
    ...
}

Since the error path doesn't call cancel_work_sync(&xpad->work), can this
result in a use-after-free when xpad_presence_work() dereferences the freed
xpad struct?

>  	}
>  
>  exit:

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260805-xpadone_length_checks-v2-0-f3e925e0280b@kroah.com?part=2

  reply	other threads:[~2026-08-05 10:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-05  9:56 [PATCH v2 0/3] xpad packet size checks Griffin Kroah-Hartman
2026-08-05  9:56 ` [PATCH v2 1/3] Input: xpad - add out-of-bounds checks for xpadone Griffin Kroah-Hartman
2026-08-05 10:10   ` sashiko-bot
2026-08-05  9:56 ` [PATCH v2 2/3] Input: xpad - add packet length check for xpad_process_packet() Griffin Kroah-Hartman
2026-08-05 10:11   ` sashiko-bot [this message]
2026-08-05  9:56 ` [PATCH v2 3/3] Input: xpad - add size checks to xpad360 packet processing Griffin Kroah-Hartman
2026-08-05 10:08   ` sashiko-bot

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=20260805101103.6AA231F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=griffin@kroah.com \
    --cc=linux-input@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.