Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2571919yba; Mon, 6 May 2019 08:10:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwfoYQI2d5Nz4aarhy4wznaRShHbLye8rTLnvIiTeIEOc8lV+BCinouo9MW3xrGOc0Tez5G X-Received: by 2002:a62:2051:: with SMTP id g78mr26723610pfg.125.1557155425113; Mon, 06 May 2019 08:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557155425; cv=none; d=google.com; s=arc-20160816; b=FcXp/LD+HBCc354TGFshXCUO+BmiKsjc4AwhWkRCDBb3aKPxlyeY2DSzZjLdfCLGmD MRPX/fsQtr1jgOYToHnQ9D4oucGxfpTyL4qGKmQtNccDl0B3CGUYShPbNyuFKvsB3aLy H3WgrLBaRTshQbtZgE3uKdgdmeWkefWhpm46ZYC2llSkWYN5zxT7J3DKgHMg0ycxOoD1 RS5/Q6HMIzEDPUw8ThWqxBN+Mso/B9Wlgkt4pFD77yfozf5xBOUwhalg84dXw9BB0TT5 bl+B+7MQrIcouZIeIoGD55Q4QpB9H7VXWNgNJiDPbfIr07oseGEnbtDog+oi/29GDED+ ZsRw== 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=HxZTzQO1cabsk1xvUwMOy7f4gwIrH44PIPXtxcVrWHc=; b=wrp1i5ePOXilq85wax/oqtfXtCXeJNq9silG1X0SQ0m8ORDVuwayofXC8XyoO7cA1Z vmssyRgbxICRY+JFyjwZ0Z6dk+ybgPFEAL9NIWDVBEm/04drgYJPp5gZolKmuFisqrCa IdQiZdozZ0mUT20hExVlK+QeCmh8bqyIO7eslooGzj1k4yOa12INXvjbMGyYw0iG2zIk F520rZ7nvDWXBZ7LSUde9qyMWKFm4Rkldz94+O3iqTJzYQ67LNxOut9EuhaxzOtjrock 8v1XVt7g8VyVUWiAV4G3CNMRFvyQbjunjy+s6jUnhPy3BVj8vOuIzkcDjLZOZweNMubI AwKA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jCmNzWNU; 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 o14si15777804pgj.241.2019.05.06.08.10.08; Mon, 06 May 2019 08:10:25 -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=jCmNzWNU; 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 S1727447AbfEFPHw (ORCPT + 99 others); Mon, 6 May 2019 11:07:52 -0400 Received: from mail.kernel.org ([198.145.29.99]:38448 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727115AbfEFPHu (ORCPT ); Mon, 6 May 2019 11:07:50 -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 481C32087F; Mon, 6 May 2019 15:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557155269; bh=gIPycv8dbcn1JC3zOTMxaLgrxP4VVdplls7mNHRinzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jCmNzWNUc7uzzPuR3VCjw7I+hd7jaBr3SQCi0A2xFTJ/rkb3IompkjPx1exqOKJ+p B9XzLXU2O+gwVOaHef6MkuHM1bY1Jwe/48WGeAZzPOynr+BKp/OBEB3lzw1Hoabevb BOvaQmHciqG5rJU6YpTP6lVl4OLQWHXF2BwUo4Ek= 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 Subject: [PATCH 4.14 27/75] HID: debug: fix race condition with between rdesc_show() and device removal Date: Mon, 6 May 2019 16:32:35 +0200 Message-Id: <20190506143055.631670523@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190506143053.287515952@linuxfoundation.org> References: <20190506143053.287515952@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 --- 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 a90967cd4987..a0bcbb633b67 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