Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp5853951ybn; Sun, 29 Sep 2019 07:07:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhpb3ltGR9rGuvZgLi5DohF31uQ3YPLofp+y/2huOBkWcj8YUjUAbBpsu9XJEkcQlgp2dp X-Received: by 2002:a50:93a4:: with SMTP id o33mr15147453eda.0.1569766041849; Sun, 29 Sep 2019 07:07:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569766041; cv=none; d=google.com; s=arc-20160816; b=cSgINSVqf7Gx50z0yF9jCaRw/9H1dyHYKPuPIzGeHrQpPfYDTxaoWdxYz79HXp0CHY xJC2YH+zFN2vj34yRN5ezMCDnPkZ1gi1MXU8oHnBOWTg7ZCj90kB70jfdz2uqpQzm671 sl38HHfrwX+5uKxfA7OR2y3vvha+oc3MJGCb3qCAvVJPhkxzz7byD5poP1XSa0ub5TUg qyPGlC7+ksBwBPScWAlGxhqwp4ap1hGyjOfVXhKupgDg/n61Nw56SjkBtVTQYuYf6bOr UX2UgQY/TGC+MP95LAE8hP8LhM9iFsDvu++DK9tZ70GkuqoyGOnZ7qURvFECDxhwoawg iIzg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tAwcRTavnPV/yxUFNQ3SwPkQqV+L5fg5B1KGl0Ftwec=; b=X8MXSw9XUoRM9a9irbHWMJoR6IV4LiaTZ7Qqa7jdQoHmED9guga6u1LOiHgALQAJaj u1vT5Fa5wXEoWrwJP0O01zVepiNb6F2L8UW3u1nNaI+p6dBk+V813rmrmlaeG7TVMnWn XgkcR5M5vfGQG41FwfjwjnONDxCuGNMwMAIeyMJBf9DP8yVRmhtERIacZJoaOzxamit4 BX4U4EGp8sf16canoblyUhzy0E/1VwJWEZyqb2BqyPlwFe2/zxGpc5mMctFlmCHFshmr Ad2n1Vgt2+NvX4RaDSPY8TsLAKQA0W9ZSkVS/QPKSgNFQ8iciIJJrDFbANtoOLChTWuf rJfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HGug0f9x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1si5177642ede.268.2019.09.29.07.06.57; Sun, 29 Sep 2019 07:07:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HGug0f9x; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729206AbfI2OFQ (ORCPT + 99 others); Sun, 29 Sep 2019 10:05:16 -0400 Received: from mail.kernel.org ([198.145.29.99]:42592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729096AbfI2OAm (ORCPT ); Sun, 29 Sep 2019 10:00:42 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 1463521882; Sun, 29 Sep 2019 14:00:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569765640; bh=mQw3sMDhmXb2Pm6+a32Ys92DGuDaiAOyAzDB4ci/bpk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HGug0f9xg5GAq9r8tyAtrg4SWM6t5Onp/kore58xq4z1rT7DM4saRkcGg2Km5TCT1 2tNwUMXkFXda3UgNvp3EzibBqk+1dWpk1g+vLcu3SWpVa+7TccW6wfymAiw0oooRdV Ubb04rVFVY9N1hCx1eBBIecOqsr2zrlAzYs5e6pI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alan Stern , Jiri Kosina , syzbot+5a6c4ec678a0c6ee84ba@syzkaller.appspotmail.com Subject: [PATCH 5.2 16/45] HID: hidraw: Fix invalid read in hidraw_ioctl Date: Sun, 29 Sep 2019 15:55:44 +0200 Message-Id: <20190929135028.883859509@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190929135024.387033930@linuxfoundation.org> References: <20190929135024.387033930@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alan Stern commit 416dacb819f59180e4d86a5550052033ebb6d72c upstream. The syzbot fuzzer has reported a pair of problems in the hidraw_ioctl() function: slab-out-of-bounds read and use-after-free read. An example of the first: BUG: KASAN: slab-out-of-bounds in strlen+0x79/0x90 lib/string.c:525 Read of size 1 at addr ffff8881c8035f38 by task syz-executor.4/2833 CPU: 1 PID: 2833 Comm: syz-executor.4 Not tainted 5.3.0-rc2+ #1 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0xca/0x13e lib/dump_stack.c:113 print_address_description+0x6a/0x32c mm/kasan/report.c:351 __kasan_report.cold+0x1a/0x33 mm/kasan/report.c:482 kasan_report+0xe/0x12 mm/kasan/common.c:612 strlen+0x79/0x90 lib/string.c:525 strlen include/linux/string.h:281 [inline] hidraw_ioctl+0x245/0xae0 drivers/hid/hidraw.c:446 vfs_ioctl fs/ioctl.c:46 [inline] file_ioctl fs/ioctl.c:509 [inline] do_vfs_ioctl+0xd2d/0x1330 fs/ioctl.c:696 ksys_ioctl+0x9b/0xc0 fs/ioctl.c:713 __do_sys_ioctl fs/ioctl.c:720 [inline] __se_sys_ioctl fs/ioctl.c:718 [inline] __x64_sys_ioctl+0x6f/0xb0 fs/ioctl.c:718 do_syscall_64+0xb7/0x580 arch/x86/entry/common.c:296 entry_SYSCALL_64_after_hwframe+0x49/0xbe RIP: 0033:0x459829 Code: fd b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 00 66 90 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 0f 83 cb b7 fb ff c3 66 2e 0f 1f 84 00 00 00 00 RSP: 002b:00007f7a68f6dc78 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 0000000000000003 RCX: 0000000000459829 RDX: 0000000000000000 RSI: 0000000080404805 RDI: 0000000000000004 RBP: 000000000075bf20 R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 00007f7a68f6e6d4 R13: 00000000004c21de R14: 00000000004d5620 R15: 00000000ffffffff The two problems have the same cause: hidraw_ioctl() fails to test whether the device has been removed. This patch adds the missing test. Reported-and-tested-by: syzbot+5a6c4ec678a0c6ee84ba@syzkaller.appspotmail.com Signed-off-by: Alan Stern CC: Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hidraw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -370,7 +370,7 @@ static long hidraw_ioctl(struct file *fi mutex_lock(&minors_lock); dev = hidraw_table[minor]; - if (!dev) { + if (!dev || !dev->exist) { ret = -ENODEV; goto out; }