From patchwork Thu Apr 5 23:09:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Rivas Costa X-Patchwork-Id: 10325565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 092C160208 for ; Thu, 5 Apr 2018 23:10:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF86629425 for ; Thu, 5 Apr 2018 23:10:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E301C29427; Thu, 5 Apr 2018 23:10:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2E9129426 for ; Thu, 5 Apr 2018 23:09:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750852AbeDEXJ5 (ORCPT ); Thu, 5 Apr 2018 19:09:57 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:37904 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750786AbeDEXJ4 (ORCPT ); Thu, 5 Apr 2018 19:09:56 -0400 Received: by mail-wm0-f65.google.com with SMTP id i3so11578849wmf.3; Thu, 05 Apr 2018 16:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=VJtSBBKMrB6QWJusFUjlQeYZcLJEOGA6HSYH0hVKFUs=; b=sjhGIMiX+y9O+QJ4wbg7cbGIu8tw9yZ+JMuOL/PVH3fMuUrMzpEE3qTfBI5o4k4W7F Y4y2zoGlTFFTfAGNnl5LB/WXXqPqphVgeqo+p0UK/0mO/d8VWsxikuOrv11ZIyNKpcKY WbM4bklsVhgtQGVlkGZl6/RqKRYACQ2yTR+id5vDh6CS8kFiF7hepNysxMklgn3//i1M 36d5YkjckVyk7RmWmxNjpZ3MKrGPlD1pCnpw96lXJ0WXeshqzZjpVVuaZZFug4mE4OYn 1pQRr1iIuwxNUSfi/Miiq6TmtSuQoVdIwd+a6sS6JWEpfnt4RkUw6h+2tTS8S17yOTZY k8QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VJtSBBKMrB6QWJusFUjlQeYZcLJEOGA6HSYH0hVKFUs=; b=mJxBfBVXLqLE0rHHQP03zk8QEnHRhwVoL+gS9CMRAnoSvURdpCfk2gK69kZA5uOsIn LApFFIrSrBniB8D3Ii5kfhtalZ8CYiv3etnc/Fya45Ny3fa7Z6KH5FeMoCXxz3xt23/H //OQ+zLX4yTPeilVkHRPLKTonYsdk2UxFfePUTXJxyOEyOXI4evYQL/gwHbUTZ4fu40u VKKGjJvJyQj5TH2elTtRpycxB7/3C7fk2qqamenbpyQKzkN2zy9w2JPu8vNVujZLkkdm pYo0r3WE/LX6oSJ0v8FvMRqq8vM3cLbMX+eG/H3+wApxQMWD5zL1NbyNJMFl2+W9698l 8kwA== X-Gm-Message-State: ALQs6tCSKvnxM0Kqz3b8WHc+AT9GypD0aLXQMij66cRfQXiE1lHpEbX5 ktBCdRK1Sl+JNC7aEQIxA8Y= X-Google-Smtp-Source: AIpwx49nN92/sfVimD6/UcEVrqMXJBKgswrbOPSTw/PU2TlEY1NPEXID8g0S1gK4H61Imzu6DmCAJg== X-Received: by 10.28.202.26 with SMTP id a26mr7010367wmg.120.1522969794953; Thu, 05 Apr 2018 16:09:54 -0700 (PDT) Received: from localhost.localdomain ([2a01:c50e:5126:7a00:9d92:6e9b:364d:78a6]) by smtp.gmail.com with ESMTPSA id r19sm13890656wmd.32.2018.04.05.16.09.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Apr 2018 16:09:53 -0700 (PDT) From: Rodrigo Rivas Costa To: Jiri Kosina , Benjamin Tissoires , linux-input@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Rodrigo Rivas Costa Subject: [PATCH] hidraw: Fix crash on HIDIOCGFEATURE with a destroyed device Date: Fri, 6 Apr 2018 01:09:36 +0200 Message-Id: <20180405230936.4572-1-rodrigorivascosta@gmail.com> X-Mailer: git-send-email 2.16.3 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Rodrigo Rivas Costa --- drivers/hid/hidraw.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c index 5fbe0f81ab2e..01b5a9f01814 100644 --- a/drivers/hid/hidraw.c +++ b/drivers/hid/hidraw.c @@ -192,6 +192,11 @@ static ssize_t hidraw_get_report(struct file *file, char __user *buffer, size_t 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) {