From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f73.google.com (mail-wm1-f73.google.com [209.85.128.73]) (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 0A1283A963E for ; Wed, 15 Apr 2026 13:31:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.73 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776259865; cv=none; b=HkMr62tAaj5cletsG8bGK0OPxADt/Q9F+QhPJhTILNo2C8h9eee9QFiK0clpsAo27mIhTBnj9piV34QNRJ9crA5rRsxbTIv0wb0wiHQqp3N3YIhsFBArotl+MODJ2zVmJtKye4HhuFqzO5iPQo7VkW2FaW9rUW3m/yTzQr31piA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776259865; c=relaxed/simple; bh=fTjkDp0Z1Hjcc0C44b4TxKYtNPLhb/vV+PSFEyJ4VYQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=NuQRtR5NkFuRZSSbBc2C80I7le80NenWQzaZPHj3hMUgfmxfD4h0SVHu/jvrrxi0f5VsIcrUYoaw8wUXEQ7XP9oWxtY7iu0WmgLDRqLRa0FTj6v1ix68owchxbiOPu3WCU///cId4iFaf9qDmllmRefv3JUHj8JQblxtK3sVvs4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--gnoack.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=axnfvue+; arc=none smtp.client-ip=209.85.128.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--gnoack.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="axnfvue+" Received: by mail-wm1-f73.google.com with SMTP id 5b1f17b1804b1-488e097a270so27568235e9.1 for ; Wed, 15 Apr 2026 06:31:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1776259862; x=1776864662; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=7HNDFVvgUDGXTzqXu6LqB4466F8xaXbUgZDZ5jwpbPs=; b=axnfvue+xvcdoVEnlseRHsvwIQ1BO4F0b+E1xL7/z/vO5VoaQvRy5palj2RYJzk/mC yIIPaxCr0iwzvhjybqVqdhNYvoWXJEnXBjjutMOd96onUUYctsIkWM8Tfa8TxX8wumfm Oi9JHosUziZko0+uJ73fBCIM/yesBAGgUZTAnf5eOHCEIbQ5kbjNptxl0paJxq2ut+oW 4Ng2KWu1RDhtE/eEaqJQSbK/uZq+dXRl4Y18ypTMJgZgQrF9+uE7ZR/nA7UtSoyBww/B e+GBQOOlw/h9b4Wny+DqDfTHA8Oy+hWa3/Jrs1G3V79J91pSOJg1c0IHocLq2qfXzxbD luVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776259862; x=1776864662; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=7HNDFVvgUDGXTzqXu6LqB4466F8xaXbUgZDZ5jwpbPs=; b=nnYC+Zfr5AGXoiu1WIOuat4ZP7dbcSoId9S2CL8QwU/RKcUiGW/L/IyAeeNKl+BjOu jJQzHaroUXfUQAh4uHW9Areha88j+LB6CZHt1ONRrXzbqHBm4JH8lsuSwwebXvgLwzgX EDeZRLAwrkMC4PGgCjSqc8/iTB0x1e5rm1/fhb8LJ87Q89VwBBGgkdXHF2qwk2umqHJ4 3Jq93WEisDlWX5l16Tfw9RaGRF8AwRcTWAfb+Lk5R90UzEHZdUcCE/L98gdB8lEVgtww tTFyAP3SI6rhx828unJR9JJazhByCLWvnZ7SSY+zkJYMlsur+h4ikmKm+rkXDy+2Ta0O OWkQ== X-Forwarded-Encrypted: i=1; AFNElJ+/Kzi3CGHEiL922xFGryT4xpkxUehKzZoLuNa35RxiNF87qCE9QwOLXG6BRfJOKOohSMS+P0BiZPG16Q8=@vger.kernel.org X-Gm-Message-State: AOJu0YzGqiiEIiKWo7+B70ftB2ZwbKGNmzvWUWELzoqqk1dGPnaPeoyT xKhr9WFmpjLAlhVUYxNa/aYhMbPtmK4zMn3r6vCC9wzq24JXCSMJPdKBU24udGcKYbodDHLSMtk lYsK4hw== X-Received: from wmow5.prod.google.com ([2002:a05:600c:4745:b0:488:c1c7:501e]) (user=gnoack job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600d:4:b0:480:69b6:dfed with SMTP id 5b1f17b1804b1-488d68ab2bfmr247041005e9.24.1776259861869; Wed, 15 Apr 2026 06:31:01 -0700 (PDT) Date: Wed, 15 Apr 2026 15:30:52 +0200 In-Reply-To: <20260414143238.1177080-1-lee@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260414143238.1177080-1-lee@kernel.org> Message-ID: Subject: Re: [PATCH 1/1] HID: magicmouse: Prevent out-of-bounds (OOB) read during DOUBLE_REPORT_ID From: "=?utf-8?Q?G=C3=BCnther?= Noack" To: Lee Jones Cc: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Hello Lee! On Tue, Apr 14, 2026 at 03:32:38PM +0100, Lee Jones wrote: > It is currently possible for a malicious or misconfigured USB device to > cause an out-of-bounds (OOB) read when submitting reports using > DOUBLE_REPORT_ID by specifying a large report length and providing a > smaller one. >=20 > Let's prevent that by comparing the specified report length with the > actual size of the data read in from userspace. If the actual data > length ends up being smaller than specified, we'll politely warn the > user and prevent any further processing. >=20 > Signed-off-by: Lee Jones > --- > drivers/hid/hid-magicmouse.c | 8 ++++++++ > 1 file changed, 8 insertions(+) >=20 > diff --git a/drivers/hid/hid-magicmouse.c b/drivers/hid/hid-magicmouse.c > index 91f621ceb924..5f44129e6dcc 100644 > --- a/drivers/hid/hid-magicmouse.c > +++ b/drivers/hid/hid-magicmouse.c > @@ -490,6 +490,14 @@ static int magicmouse_raw_event(struct hid_device *h= dev, > /* Sometimes the trackpad sends two touch reports in one > * packet. > */ > + > + if (size < data[1] + 2) { > + hid_warn(hdev, > + "received report length (%d) was smaller than specified (%d)", > + size, data[1] + 2); > + return 0; > + } > + > magicmouse_raw_event(hdev, report, data + 2, data[1]); > magicmouse_raw_event(hdev, report, data + 2 + data[1], > size - 2 - data[1]); > --=20 > 2.54.0.rc0.605.g598a273b03-goog I am afraid this still looks buggy to me. With your check, size can still be *equal* to data[1] + 2. In that case, t= he second recursive call becomes magicmouse_raw_event(hdev, report, data + size, 0); so this points just after the original "data" buffer with zero size. But the magicmouse_raw_event() function accesses data[0] directly at the beginning. It assumes that size is >=3D 1, but it does not check that befo= re that first access. =E2=80=94G=C3=BCnther