Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4630198pxj; Wed, 12 May 2021 09:36:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeucVqKrcMc/hMNzjSjdwtNk/8H1F2gOqWM5zevYGSdISGrL+vcNNdYaRHTZQ3RB4tTHwO X-Received: by 2002:a17:906:8a51:: with SMTP id gx17mr38347063ejc.549.1620837389899; Wed, 12 May 2021 09:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620837389; cv=none; d=google.com; s=arc-20160816; b=POEbaRaDvNqFQZJJkhEhQKLM7EV4fr+0bNDSITQE0a6AVK7/xfXAtwJN4rqginmP97 XZnyKCwHaUuELMGaoNN0r4sN3rD6Z/An65rlQRxzD02HwTB+IgLB+kUqTAimZjgTNk/W K7zCPeQD/6gXpFgJQkt30ubA+MnT/3frx2pkDfOcWrfVQRi/2qYsUCO/spbN8hgqT77I aIboc5NudDall15DI8sKkmTztpsCJAcCKbXmlaJG2075GjaEUb4ODrNHveJmbcWcdsbs eoqWPPkgBUzNfvjNPKnUkerNCtf6JQj33tDTki/KxROdptvS8yXs2o5FknZS4BWVuVFa fRgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ykAVu/5yfZ2lRSfSZU34zkbE+2i0zJZK2Kcy6Z9vjps=; b=LzRbOIEE7cGpHx5ZLmTh6KNIk56Fz4xpQi6DzlQkwP68gt3WyFUFL2U0F7UaFEzA3h 2hWk8ZTL6WlwljNbasCy5K2M9m/B/mVW90xhJ8v+J1EcjuIltiHy9OdjSSxtBk0qhPrt FD4YzYMvKdGMddUamNuYwlqSrZ1f40DVIIJDZ4UyKljRczs3eYzV/xu7YPJz3/myI2qM yZf6X1umVCxYK7vEqQfl4hDWnQinhhCvgRykPlwLSIqAScdC8m4EPy4rQst68ZgyTI4+ lMUW74twedn226cGnldRmn1eSib3mx7kMqbk7PVKjGRsmlQ1/f6HRTvBXKk+fJiffprX NsQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kZrTfXAb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g20si339037ejz.520.2021.05.12.09.36.03; Wed, 12 May 2021 09:36:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kZrTfXAb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237242AbhELQYT (ORCPT + 99 others); Wed, 12 May 2021 12:24:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:57088 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236228AbhELPhW (ORCPT ); Wed, 12 May 2021 11:37:22 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4E8FB6198A; Wed, 12 May 2021 15:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832729; bh=QYHYkripwHaGR1tW7wMyF4+coN5sPnCg/WOWkblfgL4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kZrTfXAbr13TM5YYuHlGkbVyqy45+xGerVtklx9fgW7in/zLAkEVFSG9nHDZFe7/g hnjZZEry3J4DKdPWDMb+Du5fvs7A/hzTYPDfFXJ84LiIX6HKHGe3SQx4FUP/Z85MiZ M4fPBIaHUBIlrKB7au1f4kZ+nyItA3q4QZb9qPp4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Marek=20Beh=C3=BAn?= , Hans de Goede , Jiri Kosina , Sasha Levin Subject: [PATCH 5.10 398/530] HID: lenovo: Check hid_get_drvdata() returns non NULL in lenovo_event() Date: Wed, 12 May 2021 16:48:28 +0200 Message-Id: <20210512144832.850804275@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans de Goede [ Upstream commit 34348a8661e3cd67dcf6938f08c8bb77522301f7 ] The HID lenovo probe function only attaches drvdata to one of the USB interfaces, but lenovo_event() will get called for all USB interfaces to which hid-lenovo is bound. This allows a malicious device to fake being a device handled by hid-lenovo, which generates events for which lenovo_event() has special handling (and thus dereferences hid_get_drvdata()) on another interface triggering a NULL pointer exception. Add a check for hid_get_drvdata() returning NULL, avoiding this possible NULL pointer exception. Fixes: bc04b37ea0ec ("HID: lenovo: Add ThinkPad 10 Ultrabook Keyboard support") Reviewed-by: Marek BehĂșn Signed-off-by: Hans de Goede Signed-off-by: Jiri Kosina Signed-off-by: Sasha Levin --- drivers/hid/hid-lenovo.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/hid/hid-lenovo.c b/drivers/hid/hid-lenovo.c index ee175ab54281..b2596ed37880 100644 --- a/drivers/hid/hid-lenovo.c +++ b/drivers/hid/hid-lenovo.c @@ -508,6 +508,9 @@ static int lenovo_event_cptkbd(struct hid_device *hdev, static int lenovo_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { + if (!hid_get_drvdata(hdev)) + return 0; + switch (hdev->product) { case USB_DEVICE_ID_LENOVO_CUSBKBD: case USB_DEVICE_ID_LENOVO_CBTKBD: -- 2.30.2