Received: by 10.192.165.148 with SMTP id m20csp2451812imm; Sun, 22 Apr 2018 07:20:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/R/AphkZFUWVhGFX0ZTUQRIpux0yomNEY/TUUYzKmhu+/QWOpAcmkJ6cjk68D1KO5D1nr9 X-Received: by 2002:a17:902:6c0b:: with SMTP id q11-v6mr6382398plk.135.1524406808750; Sun, 22 Apr 2018 07:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524406808; cv=none; d=google.com; s=arc-20160816; b=v5BnomTw1pSXme240FTyRoRft6TRvfmq7lWWo6F13GConJ+3eTHTsmJCrlFu4Ln4jC pHrMjsspIOgokx+OO6bppRhAJxm9b23gR0SNYAuI9OSWivPmwh99zP39wLq7X655QBCH Pq+33pYsA51KluO3cScq8d3XW3LkzYICzCWW1qJqu8yMZT7ywnCl136iDGTyhMbKJtB1 0s9zeldo+uB6XxzVSN12x8LXTGyLg25CS676OAg9L1DuXQAdnHDEJzTNpKrF+zZDFKWo XyU0DIbatwBrK92sQqwoPAk5GMQ/W+2gO0DoUxlz8cvbvEeN1253lc/POUUHM9D70g+s uMMQ== 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=kvxKr8ClEQgx20UWqYp9E/gpYHW1bkkG/5DdzZuDcfU=; b=kp56uRgeLtl69CSSUCUkP4rnG9mp1gLavzC4h3Cd69EyGmHTrduANXQKqYNm3ih8Hy /14SsmR+KxjZpa8PLuy6Jo9ic193UjSSFDdFBZ3hPP/pYzd8yEtTixT4Zei2+6fU6/kL g3AeVbJghFwQSLWf6usOoG781dGVAftw9VL6I22OkVBu5YPGK/DC65Q9fMMJjr4K/yUn DZAb2aGZXpX4jI3xBQLZdlHpfyWY1XU6NUVat1qngPnwdNcKuxKI3vJ1+6pZHoHpdZ+i OeRs7qEz3hfbziYX9QR2nkoZfSzabfS5IMd6UjTuRfp0LceYWvkeSFiuzt8wMME0EPPI KYRg== 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 v4-v6si9557294plo.476.2018.04.22.07.19.54; Sun, 22 Apr 2018 07:20:08 -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 S932513AbeDVOSt (ORCPT + 99 others); Sun, 22 Apr 2018 10:18:49 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59110 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932498AbeDVOSo (ORCPT ); Sun, 22 Apr 2018 10:18:44 -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 B784FD08; Sun, 22 Apr 2018 14:18:43 +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.4 81/97] HID: hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device Date: Sun, 22 Apr 2018 15:53:59 +0200 Message-Id: <20180422135309.635020694@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180422135304.577223025@linuxfoundation.org> References: <20180422135304.577223025@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.4-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 @@ -197,6 +197,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) {