From patchwork Tue Sep 1 15:11:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 264612 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B74E5C43461 for ; Tue, 1 Sep 2020 16:14:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7594C204EC for ; Tue, 1 Sep 2020 16:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598976856; bh=7HKd/IscGoK7CQQqMS7/I9PwnB6S63WqRDGkpK4y1JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=uitt1ZXzYy16CyZAN/QNVEbi3KqlzIKyE+yTQbDFe76nokDhrLwrIpAqEDdvCq1c1 IQF3ryQHKK2d8WhomYuVE76mDmhLdKygK+wWF0of765yuGtDnSzFeb8Y30OwxRnwG7 JueNbJIkmm3hkxnScV2q36DtCk/Bm8XPYdR9USOg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730107AbgIAQOM (ORCPT ); Tue, 1 Sep 2020 12:14:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:41400 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730704AbgIAPfc (ORCPT ); Tue, 1 Sep 2020 11:35:32 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8200C20866; Tue, 1 Sep 2020 15:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974532; bh=7HKd/IscGoK7CQQqMS7/I9PwnB6S63WqRDGkpK4y1JU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uCIgw+APxmSK79utouvJ6psQllUF3FTARaEIHmDj6lPjRrQ7Fwqdie5A3aCfwz+m2 sw+KLnTNXed/EFsC+V+DMBmQeYjWsUYRHfnDn4Dbk6CuYeeJiSEjrS03oPj4265gE8 a4P4DxMbJ0wE0rIPI9K8h1cy+73UfgNEEohz/io4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+34ee1b45d88571c2fa8b@syzkaller.appspotmail.com, Dan Carpenter , Peilin Ye , Jiri Kosina Subject: [PATCH 5.4 212/214] HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage() Date: Tue, 1 Sep 2020 17:11:32 +0200 Message-Id: <20200901151003.081654281@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150952.963606936@linuxfoundation.org> References: <20200901150952.963606936@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Peilin Ye commit 25a097f5204675550afb879ee18238ca917cba7a upstream. `uref->usage_index` is not always being properly checked, causing hiddev_ioctl_usage() to go out of bounds under some cases. Fix it. Reported-by: syzbot+34ee1b45d88571c2fa8b@syzkaller.appspotmail.com Link: https://syzkaller.appspot.com/bug?id=f2aebe90b8c56806b050a20b36f51ed6acabe802 Reviewed-by: Dan Carpenter Signed-off-by: Peilin Ye Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/usbhid/hiddev.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/drivers/hid/usbhid/hiddev.c +++ b/drivers/hid/usbhid/hiddev.c @@ -519,12 +519,16 @@ static noinline int hiddev_ioctl_usage(s switch (cmd) { case HIDIOCGUSAGE: + if (uref->usage_index >= field->report_count) + goto inval; uref->value = field->value[uref->usage_index]; if (copy_to_user(user_arg, uref, sizeof(*uref))) goto fault; goto goodreturn; case HIDIOCSUSAGE: + if (uref->usage_index >= field->report_count) + goto inval; field->value[uref->usage_index] = uref->value; goto goodreturn;