From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E7F8346AE8; Thu, 15 Jan 2026 17:56:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768499786; cv=none; b=JoRhFL2l8dZn7hYcfHat0Okbln+Gwu9SBC+e5ov+iRC0E4lX7XtpnoiLejhriLpwV1WlmrpBvLpB8EgB1HqHKM4R7sPFIdhxfDp6CW2UBVnuGYvCa4FqjK8UaOffeWd4l46s9YGOSO7NHc9thuV+Fe2H5HMOJslj+/XrXyMvayo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768499786; c=relaxed/simple; bh=UwJ7wJyEGgYCi9KJjN5ex0xz8S2Nz3bv0NR2Zvg1qEA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Xw2FoO2Os19DgtzWX64Dsv4Oz/PkkNZnNjfV2zeXrD5Ljh6pyIZ6QRjrRH2O+VbNThNUFmOKkh4rtBxwh4z3e9mxKtLqhYZJ1iPPowkQN5UIoXkpcJyzALjThHsHZD/BKXz8FR5cBrQD7L0WXQYjs9RjrKmNDPol1/2kyZt3FFA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=X9TvuXkU; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="X9TvuXkU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ACE30C116D0; Thu, 15 Jan 2026 17:56:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1768499786; bh=UwJ7wJyEGgYCi9KJjN5ex0xz8S2Nz3bv0NR2Zvg1qEA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X9TvuXkU3J6n74bQjiABPt7RFNQufLn6eVFPK7qQsYyaAACQPLP5jEugN1xbvBuBB wkQPw01ybvLd9EuggV7SA00gfngUxxPCo0YJymguaSdmncq7T6d2+cuoyRb84SI2CV z3I88Hgf8Pvb8lFdZobwRq3cbCVK37Ke002toRtI= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Alan Stern , syzbot+b63d677d63bcac06cf90@syzkaller.appspotmail.com, Benjamin Tissoires , Wenshan Lan Subject: [PATCH 5.10 350/451] HID: core: Harden s32ton() against conversion to 0 bits Date: Thu, 15 Jan 2026 17:49:11 +0100 Message-ID: <20260115164243.562342480@linuxfoundation.org> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260115164230.864985076@linuxfoundation.org> References: <20260115164230.864985076@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alan Stern [ Upstream commit a6b87bfc2ab5bccb7ad953693c85d9062aef3fdd ] Testing by the syzbot fuzzer showed that the HID core gets a shift-out-of-bounds exception when it tries to convert a 32-bit quantity to a 0-bit quantity. Ideally this should never occur, but there are buggy devices and some might have a report field with size set to zero; we shouldn't reject the report or the device just because of that. Instead, harden the s32ton() routine so that it returns a reasonable result instead of crashing when it is called with the number of bits set to 0 -- the same as what snto32() does. Signed-off-by: Alan Stern Reported-by: syzbot+b63d677d63bcac06cf90@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-usb/68753a08.050a0220.33d347.0008.GAE@google.com/ Tested-by: syzbot+b63d677d63bcac06cf90@syzkaller.appspotmail.com Fixes: dde5845a529f ("[PATCH] Generic HID layer - code split") Cc: stable@vger.kernel.org Link: https://patch.msgid.link/613a66cd-4309-4bce-a4f7-2905f9bce0c9@rowland.harvard.edu Signed-off-by: Benjamin Tissoires [ s32ton() was moved by c653ffc28340 ("HID: stop exporting hid_snto32()"). Minor context change fixed. ] Signed-off-by: Wenshan Lan Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hid-core.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1349,7 +1349,12 @@ EXPORT_SYMBOL_GPL(hid_snto32); static u32 s32ton(__s32 value, unsigned n) { - s32 a = value >> (n - 1); + s32 a; + + if (!value || !n) + return 0; + + a = value >> (n - 1); if (a && a != -1) return value < 0 ? 1 << (n - 1) : (1 << (n - 1)) - 1; return value & ((1 << n) - 1);