Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1053073pxk; Mon, 31 Aug 2020 08:33:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFrI2dsJmWupUIqF/Pf40ll+IW1y9GLuJepsRUAhFAIqPVfiirVWH5252XHkOh+Te/KsPC X-Received: by 2002:a17:906:c18d:: with SMTP id g13mr1566437ejz.239.1598887994118; Mon, 31 Aug 2020 08:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598887994; cv=none; d=google.com; s=arc-20160816; b=tEPiy7HeOTUSzswxAIf2TnkxKEz0B6K4PSRpJ7bLY7Y/Y5/kkWJq7CESsstz/eNHS3 OxgqzKFolP9xMzoE3IhZqwmYsuVVCRcmojw8pEGEAt0l5Oc1X98I5u+Rn9IyiNnJRyh+ JvEc+5SFhglGloMhiQre4ILnrj8VjoGDqxIUWCb/VHnLyDbf6+8L47h3bqCmeePR4yBq KHn2NhiEp0P9oKnBfD/jYKjv/06/oG0MbJH+RFF+jE9n34a5//70y/WR1YJmbpwbLzcZ N4DFxNmejFolXt9agEqSAkB7RtnImnNiSbXMBkFL7CTb7oB3iPiyJ6PAsbdmIf4mjA/P Tj+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F2RjDQGSgLWWdnmkybwfp0s2jwpI8O//oZ4IpWtmdXA=; b=HcxPDWNSn0WZx+zGBeaUg++8GMhzZZ2CsFOzCr6fTTyWJu43ieEvx6CdMWoMWrD+lS Sx05kVye2N9cawp8RuIMTH7AtUcK8Rg0T3GE82kcVO3eCIQnIIpURlvJI4gUtfpvnMu6 +NRax+Jub0dcnk9OTkffvwc7VSstUy5MXZTbjx+TLjpMhKEBvfq1Ajr39+fUW4fhST1W zEiviDi8rbt4CmfnvvKvTalgAHQtguGcEYBr+Q/2EMqKWdwpfuBGzhek1+NR7M5kq/m1 kpL7Bn4YetqeFFkxKVWQpPe+0qJnkZ/ZD/eOyPAVj6bnGHzrSlco9EIi4PLNrrfAmDvg L3yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=2R9OMzEH; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bz3si3159594ejc.81.2020.08.31.08.32.51; Mon, 31 Aug 2020 08:33:14 -0700 (PDT) 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=@kernel.org header.s=default header.b=2R9OMzEH; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbgHaP3x (ORCPT + 99 others); Mon, 31 Aug 2020 11:29:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:38234 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728356AbgHaP3k (ORCPT ); Mon, 31 Aug 2020 11:29:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0C31D20866; Mon, 31 Aug 2020 15:29:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598887780; bh=IUqMlpo21BBlXw7DHat6qPFNyPjNdosUchLhrYIjKO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2R9OMzEH9saCy0+9iQJCg+jy8AFFda0tEk7MHwQLLgsj++4DLEcSP92UJGLr7CZty vXPpCMu+5D2X9eRwyQhyAqn4tzEB2ZnjaNTZKCBK1arTPjRt/V5Ojn5d72nZIMP7+P ldg/q1OcX0+5HwkYyRA2Dzszgxa+018SSYviHp4g= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Peilin Ye , syzbot+34ee1b45d88571c2fa8b@syzkaller.appspotmail.com, Dan Carpenter , Jiri Kosina , Sasha Levin , linux-usb@vger.kernel.org, linux-input@vger.kernel.org Subject: [PATCH AUTOSEL 5.8 03/42] HID: hiddev: Fix slab-out-of-bounds write in hiddev_ioctl_usage() Date: Mon, 31 Aug 2020 11:28:55 -0400 Message-Id: <20200831152934.1023912-3-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200831152934.1023912-1-sashal@kernel.org> References: <20200831152934.1023912-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peilin Ye [ Upstream commit 25a097f5204675550afb879ee18238ca917cba7a ] `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: Sasha Levin --- drivers/hid/usbhid/hiddev.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c index 4140dea693e90..4f97e6c120595 100644 --- a/drivers/hid/usbhid/hiddev.c +++ b/drivers/hid/usbhid/hiddev.c @@ -519,12 +519,16 @@ static noinline int hiddev_ioctl_usage(struct hiddev *hiddev, unsigned int cmd, 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; -- 2.25.1