Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2571397yba; Mon, 6 May 2019 08:10:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqyq+Y7rIUgH7jxxSZYiYFtmmfcXHaUK17w9iJAtRN4fArz5uevOjLJf1brNFnqI+nGk1R4y X-Received: by 2002:a63:7d03:: with SMTP id y3mr31624141pgc.8.1557155401283; Mon, 06 May 2019 08:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155401; cv=none; d=google.com; s=arc-20160816; b=nuJMU2XoUt+1mkLhcOL+a+JllNa70kkYY0bk65J9uw3Uy+fA6DlEphpyExH3h6UelJ pjryRxq/Vg7a1XBKoW32A9jSVvseqp6/FdtycjJVHmzU6wzPoZhkY6H/V+r763pJp4jv yn3a1zjyzk+b5/oR0iZzorXdp6SuIVA67jSNE6rds41GvcwqrvI44B3BAJX/pLUpWev3 WjS1l4pW0cwsGCfwvmf41ul7iFxfghCaKRZBwd6sbz8DtIER2VE8SprBpRRkgpgG4VNA 515nmuc5CRsjfEJ3hArtlzaWbJoe5jp4k29+iiCTu4Ev6K4eAZKwdjwbwCcjQBmLMiLt g/VQ== 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=ac2rQhUlX8ODkw1/BJWotqWw4Gw63QUjfkfTcIc1JpY=; b=FN9tW7Ho3x1wszsr96Ue5yev9IIYWx5O2QJa1pgG60mqYZZ4F4nVjFMTgkV6zx2OuE iAV305kyPLgp6ixB81ZFnADfq4LeLJsN0pbDvO55O/1n67J/beekrJkPSqyyHuyU4dxc DGMzcDRxGEzL8g1y+2Bvf8ODNcs84qIQ/YJSJfOxORwAwkUcuJdwwfLNe8OWHAP7uSgr p+xs9cg7vpBwEHSBASW9M5ttGJOStQqMcfS+e2v79MYQSoCapQoLbqh7Zi+wb1KqxPgi wFosgaUsOVfaxvNGj48t+rp26W6/37CvmM08AMcsOqFB3uYVByhg4JqBAqvguDQtFhuZ hIUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="f1noX/yN"; 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 20si16260033pgk.44.2019.05.06.08.09.45; Mon, 06 May 2019 08:10:01 -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="f1noX/yN"; 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 S1727701AbfEFPHF (ORCPT + 99 others); Mon, 6 May 2019 11:07:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:37692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726909AbfEFPHE (ORCPT ); Mon, 6 May 2019 11:07:04 -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 E07B42054F; Mon, 6 May 2019 15:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557155223; bh=B2nWR6WrKtnSORYpw4xwpJdjE5H+1A10CRTXv2nIBbg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f1noX/yNHihKbTSqpEpmUXiUSJ+aswhCvmWCtdsmfBKEmUp/ep338Sc3GIpI+GB3E R3GYZhA5LAIvZUD4A0dGKuPZTeevYbgeMP+oO4c5qCq/uRBelQkZsczRLZnxFJzBVw MMzN8ZigAtxg93/RZE9BwUV/MwaKzgg5ufGJoOe4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "he, bo" , "Zhang, Jun" , Jiri Kosina , "Sasha Levin (Microsoft)" Subject: [PATCH 5.0 028/122] HID: debug: fix race condition with between rdesc_show() and device removal Date: Mon, 6 May 2019 16:31:26 +0200 Message-Id: <20190506143057.281139555@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143054.670334917@linuxfoundation.org> References: <20190506143054.670334917@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 [ Upstream commit cef0d4948cb0a02db37ebfdc320e127c77ab1637 ] There is a race condition that could happen if hid_debug_rdesc_show() is running while hdev is in the process of going away (device removal, system suspend, etc) which could result in NULL pointer dereference: BUG: unable to handle kernel paging request at 0000000783316040 CPU: 1 PID: 1512 Comm: getevent Tainted: G U O 4.19.20-quilt-2e5dc0ac-00029-gc455a447dd55 #1 RIP: 0010:hid_dump_device+0x9b/0x160 Call Trace: hid_debug_rdesc_show+0x72/0x1d0 seq_read+0xe0/0x410 full_proxy_read+0x5f/0x90 __vfs_read+0x3a/0x170 vfs_read+0xa0/0x150 ksys_read+0x58/0xc0 __x64_sys_read+0x1a/0x20 do_syscall_64+0x55/0x110 entry_SYSCALL_64_after_hwframe+0x49/0xbe Grab driver_input_lock to make sure the input device exists throughout the whole process of dumping the rdesc. [jkosina@suse.cz: update changelog a bit] Signed-off-by: he, bo Signed-off-by: "Zhang, Jun" Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin (Microsoft) --- drivers/hid/hid-debug.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c index ac9fda1b5a72..1384e57182af 100644 --- a/drivers/hid/hid-debug.c +++ b/drivers/hid/hid-debug.c @@ -1060,10 +1060,15 @@ static int hid_debug_rdesc_show(struct seq_file *f, void *p) seq_printf(f, "\n\n"); /* dump parsed data and input mappings */ + if (down_interruptible(&hdev->driver_input_lock)) + return 0; + hid_dump_device(hdev, f); seq_printf(f, "\n"); hid_dump_input_mapping(hdev, f); + up(&hdev->driver_input_lock); + return 0; } -- 2.20.1