From patchwork Tue Sep 1 15:11:19 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: 264532 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=unavailable 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 AF917C43461 for ; Tue, 1 Sep 2020 16:50:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 845A1208CA for ; Tue, 1 Sep 2020 16:50:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598979032; bh=KZqOG/D8Kv+NwvA7W2O63q9QsMqSBbOK6JsY9OwhER8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=M0A0YbyS4AQESbytsTtDPh2LpTlbo4cm15E7u2TZh9Vw1dELCpkPGY5oUpD9KYQOj faClCtRT/RKu2rqikUt+wwzDJUFTYmIW4JIjAV7xhBZx3F82lPafAIQe7S9ISQupQc lMZP3LX6eC0d7y+PpgQS5cEklqCsAr19YkqKAgJc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732311AbgIAQuT (ORCPT ); Tue, 1 Sep 2020 12:50:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:52032 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730104AbgIAP00 (ORCPT ); Tue, 1 Sep 2020 11:26:26 -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 A9901206FA; Tue, 1 Sep 2020 15:26:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598973986; bh=KZqOG/D8Kv+NwvA7W2O63q9QsMqSBbOK6JsY9OwhER8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bh+omNmYvpJBcj5KC1h+pXuCWwjsSwE4A0dNA0LBxRbi7RJcALQpR1wAY3k7jdwno 23PL3nVewpprYjnafTWpKWlmZPVPbbUdhYMige8H9xlEDRoN/YbHDYPXVjNjb4QTuf kBxMzIleB1Dzi1v9MtdGbceeHxE3mRaK85Jcupt0= 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 4.19 124/125] HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage() Date: Tue, 1 Sep 2020 17:11:19 +0200 Message-Id: <20200901150940.687698839@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901150934.576210879@linuxfoundation.org> References: <20200901150934.576210879@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 @@ -532,12 +532,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;