Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp1049896ybg; Wed, 29 Jul 2020 04:39:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8JjRgiSrgoo8q57anSuXhN+Dyj++KtCLh5fj6yT/jNANJQWf5PuZzuKifAP7JMdGb5S3j X-Received: by 2002:a17:906:cc4a:: with SMTP id mm10mr27518035ejb.451.1596022767423; Wed, 29 Jul 2020 04:39:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596022767; cv=none; d=google.com; s=arc-20160816; b=SjfTfI1LEOdX6rg6/VaIabeLAoXrB632J221O7qrGcL0cMojdcA3Y3A5yDWNIA3TZh wE4lIkzbJmVQTGrK1jxv7bkxnASU/ECSM0hI3NQdsTSmWERglCbDIrwKSHNP2iBx+5aU fz31XHJE9dG2ZzTBIX137+33QT9jI4AZ4ZQq638q88nk0wD1COqGAUBjC9CK3INbYTEP p3WKLFXYTyfA15szo6NmB+4/uVPljThkRnFbmVwNaMUPGIKFvx9kapp9s9/vMwUBFvML WwdKC5GlZUXx9BhDD+k3R9zOo9CUzbDumlrcwlMNF6EgURorc0Gtw8CuAS1id7FhRlrE iT9w== 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=Kq86ugZ9Kh4uvA8FGJVxsQ+ntooQ4buHazTmCg4C02E=; b=Nx3svifEQbVNRMjmyNbkz0SniVpgiCXv2vdRbHBngCi968MPFC/FpLUNrdKgK6ABwv nhomxn2cNVIswQOtJuTGSfp688cFVrf2IN+1mfwbBW8KwplSckH5NzN0mkNUAfJeMsZV 0atvXOk0a91jkXyj5mXTsKE1M1dOyWjBbnRdNUF8s4wtrloHjafayEzdxnE8wTtQl2Zi dRK8FJ3i+cbH6KB265s6zL8FR0j3zbyDGrJs5m+wSnfZdvf2nt5W1IC9FhHd7MzN3Ksw T303BIMrCwxp3gRYB1/1jkxM+tdpneaPUGXvfe5RSdVPXR4/cVmQaeoOHEoxV8aHfzoc 68fg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=OugQUVzj; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e21si1101192edv.242.2020.07.29.04.39.05; Wed, 29 Jul 2020 04:39:27 -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=@gmail.com header.s=20161025 header.b=OugQUVzj; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726790AbgG2Li3 (ORCPT + 99 others); Wed, 29 Jul 2020 07:38:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726341AbgG2Li2 (ORCPT ); Wed, 29 Jul 2020 07:38:28 -0400 Received: from mail-qk1-x744.google.com (mail-qk1-x744.google.com [IPv6:2607:f8b0:4864:20::744]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A05ACC061794; Wed, 29 Jul 2020 04:38:27 -0700 (PDT) Received: by mail-qk1-x744.google.com with SMTP id e13so21801825qkg.5; Wed, 29 Jul 2020 04:38:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Kq86ugZ9Kh4uvA8FGJVxsQ+ntooQ4buHazTmCg4C02E=; b=OugQUVzjgJHFzjAaY04UeeW/f2lFj6q18wj/s6NeyGmXMYVBGC3HBg8OANBrExC4pu mWq6CmVr+2tY6l83HfJlAquylDRJqXkr01Lakt5ttkOPv+Mdbklyze+Rnjzizv2n5eia m1vbgF3jlB/ICPiYPKySvDDOz/sNBONWbBt/gc2rpwKTmudPpoTaZzGmMRhDX0B8/DxY u/cUVpQJv+HdEJFGzwy1A8HPtWVTPNrXGuVebR8iwrcHfjeWw9OsIstqAF0+cC/ExnE2 Kyg92WKivbuwrRp+tV+CWLkWbJHWz+TvANJu8/mfMVq3nR9Rc5WoVu9te07DnWGPYuwb Gcow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Kq86ugZ9Kh4uvA8FGJVxsQ+ntooQ4buHazTmCg4C02E=; b=pdjPRwGXDNaWkOWXmxIXq8fuVp+/kaaXs99lM02kNpwcpe9IcETj2DdVs3qWEPUKdR O9Y1iypv6JhMuwol2SBLnG7NddVxaH7Zwk8wyJcCEdmPsKWqjYSRcN9vtAXYX59ATvy5 Z/yTp0SWZGlJ+kDzYDlp3/sQzr2HT/aEOgTr8pLP5JVjboKyEsdoZJ/mAIBJx/dYNOs/ hLrm21ntr+spWtB3Xp3alxY7XIQAmvNMobLaPeQoWGDUXZKBn70U46iTz8TVs2IaaJnQ 7mEjcZIZrBRgk2HhduY+1bw3epn7uB/wuqG60TZSYo0oH67mI+KhtCdMGN4/ySbt6VRh vLoA== X-Gm-Message-State: AOAM532fHvF28egRJUKSuJh2pvYF5aSYQ4owcdKPtsgYIgKZmH+XjGpe 8RABVMz2ZX0ht3G6dnf2EA== X-Received: by 2002:a37:4048:: with SMTP id n69mr30825844qka.421.1596022706871; Wed, 29 Jul 2020 04:38:26 -0700 (PDT) Received: from localhost.localdomain (c-76-119-149-155.hsd1.ma.comcast.net. [76.119.149.155]) by smtp.gmail.com with ESMTPSA id k134sm1377330qke.60.2020.07.29.04.38.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Jul 2020 04:38:26 -0700 (PDT) From: Peilin Ye To: Jiri Kosina , Benjamin Tissoires Cc: Peilin Ye , Dan Carpenter , Greg Kroah-Hartman , syzkaller-bugs@googlegroups.com, linux-kernel-mentees@lists.linuxfoundation.org, linux-usb@vger.kernel.org, linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [Linux-kernel-mentees] [PATCH v2 RESEND] usbhid: Fix slab-out-of-bounds write in hiddev_ioctl_usage() Date: Wed, 29 Jul 2020 07:37:12 -0400 Message-Id: <20200729113712.8097-1-yepeilin.cs@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200718231218.170730-1-yepeilin.cs@gmail.com> References: <20200718231218.170730-1-yepeilin.cs@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org `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 --- Change in v2: - Add the same check for the `HIDIOCGUSAGE` case. (Suggested by Dan Carpenter ) 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 4140dea693e9..4f97e6c12059 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