Received: by 10.192.165.148 with SMTP id m20csp2447206imm; Sun, 22 Apr 2018 07:15:39 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+KS+xQgjS6cxIeoR06XI+x3OxYog4Tik0WkHd4E4wwPrfsT/1a98zH/Bb38UrsQWRm46tq X-Received: by 10.99.116.8 with SMTP id p8mr14192773pgc.327.1524406539715; Sun, 22 Apr 2018 07:15:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406539; cv=none; d=google.com; s=arc-20160816; b=Nnt59AX5ZBIJ72y61KRPuSKHssXKRHjv9+7lpL9/4IUfYCvil5UAtVt9GPnUWdwZIN 40s+RmjSjl/IkLrrenAcbxBBWWdFVnBwQCpZ6iURnsXWl8nUvwCAMeULaGmGfrbXtSim xNW7rJExqU/NE9DMFWIxx6GonFv7JzblX3GhVXAec5JKlvR/BJ63N+od7zBJixmYhupq 2/zInP0nlAm1WjswCeEFpc2UvdvRz595FkANAE64ufO5fzvh8PSA1dWrHo+AuSOvsk0e uTanESIPVU3ihQPM9sJgQ3gCEwR+38hKteq5X/6YFJtoJxBbpTjUcudcF7v6AkcVDwBY 0IDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=x6AgQW90E7fp9F2cPYTvOeRZoTGtcYpGquEy+DIqRwM=; b=oxVCNSHXSo706Fm2vd/j6gNhqVcecQyglrNSzXooOZ6wogKDO327y4rn21BHjGQGnq MqKwQ4TH9bxdYCrwOJqUojrrldSH1mjaETZDissy14emGOkJZd3DEwqtrk1uQ2WX/jnz tiMnOtvxXW3waP6tgZP7Pu/hKVygZUeA15mhHlwNPVV/+9Nn/lOznefGcvBKCixD0j4s +fC35QJh1wKUJ4TKFGIR6RdPBmKw0HfaVYpCGTD9BjR8qxbbb1bpxzitr7QITOsFje1U QS0CDyfp1QNgHOzr2JQoxbtHMNTiqaqrOniUaeSE/bZqw0kdWlbmfOiDKe1++NUTNcQo lWqQ== ARC-Authentication-Results: i=1; mx.google.com; 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 c23-v6si9960303plk.245.2018.04.22.07.15.25; Sun, 22 Apr 2018 07:15:39 -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; 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 S1756973AbeDVOOS (ORCPT + 99 others); Sun, 22 Apr 2018 10:14:18 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:56318 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756922AbeDVOOO (ORCPT ); Sun, 22 Apr 2018 10:14:14 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id E311C12; Sun, 22 Apr 2018 14:14:13 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Rodrigo Rivas Costa , Jiri Kosina Subject: [PATCH 4.9 78/95] HID: hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device Date: Sun, 22 Apr 2018 15:53:47 +0200 Message-Id: <20180422135213.620479881@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135210.432103639@linuxfoundation.org> References: <20180422135210.432103639@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rodrigo Rivas Costa commit a955358d54695e4ad9f7d6489a7ac4d69a8fc711 upstream. Doing `ioctl(HIDIOCGFEATURE)` in a tight loop on a hidraw device and then disconnecting the device, or unloading the driver, can cause a NULL pointer dereference. When a hidraw device is destroyed it sets 0 to `dev->exist`. Most functions check 'dev->exist' before doing its work, but `hidraw_get_report()` was missing that check. Cc: stable@vger.kernel.org Signed-off-by: Rodrigo Rivas Costa Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/hidraw.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -192,6 +192,11 @@ static ssize_t hidraw_get_report(struct int ret = 0, len; unsigned char report_number; + if (!hidraw_table[minor] || !hidraw_table[minor]->exist) { + ret = -ENODEV; + goto out; + } + dev = hidraw_table[minor]->hid; if (!dev->ll_driver->raw_request) {