Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3534751pxb; Mon, 1 Mar 2021 12:34:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeaEy8DW2dXPG76u2A3TbA8A0JoSgWQaDrLh9OCwAeJb946+TrQ411vEIyx82k/kGh8wJS X-Received: by 2002:a17:906:37db:: with SMTP id o27mr16988245ejc.60.1614630887271; Mon, 01 Mar 2021 12:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614630887; cv=none; d=google.com; s=arc-20160816; b=kRSMlpCLj2FM4WRAub5c8+gJIdH+gD+DF4b5z3me28tG9aLJB3ZOdJl8CKm05t7ob/ GLSuZ9thNWwbMVCV59r8GnnHy/Xn0W9KYiXyp6Xs/DeOMiX1ghWid18lNjU/XOUId2wU IkzKGkKGa04xMEPBOw/5yCqecQ9LzJZo/9Eg0L2us2Hau8aYY389uCXlGHMeQ0kE2BZT g9ExQoPsW9UoW036SHbc4ByEN4yDbEaCuFrjAtdNv5/5OsEPQ4ED6XlWN5XS6g6S/fET +0wbNZ27+gdg4J/q7R84WzI5idpHAxmUgYwRDeEwJzv5IUmodU3Y/vM5GFI4IPrZZ8WT Ve2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jsSltU8C5HHchzYsRFy/ltOZ/d0kIowqvQG0QsggufY=; b=BwnLOkDQ03QPOIL3Q2lUkyYi2JwpujXxD6YsFy6IG37bGUmlQeMxyuAM4RG+tpXjhE TScdAercXMgtL+o7WVeazZ5YuRd4lNtK8T4azaDgiRT4XF66B5BrVoCOi0gVd/ASqYqz PaFXrLoL4trsGctDQy/W0vMXeBIAW/NcYJlU5HyrPFlL1S2V21s6JtGdHjHV/RoOgIac DsR6AwEymzUCx0kjFFoxtLuBLLgUYUxfTV2YtA5b2Pm8aKOX9HEFaGBq+DNYMwh9mTp6 zi04O7J+nX5iHhk4BtNgtjkZK58HtSDafPxhZATZKiAQkjXJAu79s50lH+xveQd0CTPh ObMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q3O0JBEp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id yd6si8416886ejb.302.2021.03.01.12.34.23; Mon, 01 Mar 2021 12:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=q3O0JBEp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243405AbhCAUcs (ORCPT + 99 others); Mon, 1 Mar 2021 15:32:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:36106 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236783AbhCARHG (ORCPT ); Mon, 1 Mar 2021 12:07:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0010564F79; Mon, 1 Mar 2021 16:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1614616837; bh=s//kz97nON8nvzw4MNeeNZmq/9waPmgrwHCSQPCHk1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q3O0JBEpC3k/J+eyXLidP87PC+6x9vJaUsMB8ywTC/Z13+SnuCnTsPwFdTiQcUisg 9Du1hNI4yhrXRta4JeWTQHQ832KiBsDjlRl0Ztv69GkL/pcVZey6e5nRKnOit9bgQv eKGEoUkE63wBlEMEr1EMcULs/3G3A1Ifh/1Q2QWk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Randy Dunlap , syzbot+1e911ad71dd4ea72e04a@syzkaller.appspotmail.com, Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, Jiri Kosina , Sasha Levin Subject: [PATCH 4.19 112/247] HID: core: detect and skip invalid inputs to snto32() Date: Mon, 1 Mar 2021 17:12:12 +0100 Message-Id: <20210301161037.154110947@linuxfoundation.org> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210301161031.684018251@linuxfoundation.org> References: <20210301161031.684018251@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Randy Dunlap [ Upstream commit a0312af1f94d13800e63a7d0a66e563582e39aec ] Prevent invalid (0, 0) inputs to hid-core's snto32() function. Maybe it is just the dummy device here that is causing this, but there are hundreds of calls to snto32(0, 0). Having n (bits count) of 0 is causing the current UBSAN trap with a shift value of 0xffffffff (-1, or n - 1 in this function). Either of the value to shift being 0 or the bits count being 0 can be handled by just returning 0 to the caller, avoiding the following complex shift + OR operations: return value & (1 << (n - 1)) ? value | (~0U << n) : value; Fixes: dde5845a529f ("[PATCH] Generic HID layer - code split") Signed-off-by: Randy Dunlap Reported-by: syzbot+1e911ad71dd4ea72e04a@syzkaller.appspotmail.com Cc: Jiri Kosina Cc: Benjamin Tissoires Cc: linux-input@vger.kernel.org Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-core.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c index bde5cef3290f5..9b66eb1d42c2d 100644 --- a/drivers/hid/hid-core.c +++ b/drivers/hid/hid-core.c @@ -1128,6 +1128,9 @@ EXPORT_SYMBOL_GPL(hid_open_report); static s32 snto32(__u32 value, unsigned n) { + if (!value || !n) + return 0; + switch (n) { case 8: return ((__s8)value); case 16: return ((__s16)value); -- 2.27.0