Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2011325imm; Tue, 10 Jul 2018 11:33:37 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdqEhiQnWZPK//62GnHCFvSvQV9aZtxEXf6EUizeb5yc59Z8/Dh8kBBo88/cnIHyvmJMWFI X-Received: by 2002:a17:902:ac1:: with SMTP id 59-v6mr25058129plp.36.1531247617752; Tue, 10 Jul 2018 11:33:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531247617; cv=none; d=google.com; s=arc-20160816; b=Xux3eEEoFGamJonWZRBf6ssDeNcKHbqsFm6XOq/tBKkV4HqULDpvAUABEEmj3V7vCP oOwaopSwQ376Zg3WdpUbwvjkAXFrCwW7V0kNS+uCvg+NZpvrx/bXCzbe3UVmeQknCxfb Mfhg/TmuujfiHAc/gIt28Fcf4rLSBlpvKuMtMKAeLuNrrhQN8emXJpzMJeA/WNScroDx NrAUABxsSSydVdy1SbWUoIuopjcyZ9KwzCbNarcwUG8UqAAuXMVOmGgPO5PsHmHypT+E gDSZpYgrjG/dHP0aWTqwJTQ0fslDIH85n2n30EGE+4yQcX6FmicmOzyQxLNSO/q5HuBj G0FQ== 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=kWoXyI4rFDT0clpZL6YwVwR3oTxG1fTI1O78Fsrs7Ss=; b=V3ieBS8e+SOLTLHzp9lecorH7g8XKMaQWof5mfXM0rhqk0LQ0kpECjZELiIn9Gn3cZ Tgt+u87mOyNMbq+ZOie20EuCY0ypRI3D9S8RhCq7GdAiKQ+BGI+aNw6K/EdEuSP++Eki kbmqsBPUMoazEg5b4B6e0Z5ToUm9W+QBUrRFIjfH0Y741LDqGQzCL1svqJWK7jpSwOnt J98xKuxaZMeIzHkjwggqOUz14qounjXu5KZ5MhTjH0p5rAdeV8n8aJ4Vx6g7U7vFtkW6 l9DFStn7vigAshBul6QRHAWHCu0LDmJTc3nodDVO6HNpCVj3atiQ8nKVMds/8dVjypev Gubw== 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 h3-v6si17795466pgc.122.2018.07.10.11.33.22; Tue, 10 Jul 2018 11:33:37 -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 S2388440AbeGJSbp (ORCPT + 99 others); Tue, 10 Jul 2018 14:31:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46156 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387591AbeGJSbo (ORCPT ); Tue, 10 Jul 2018 14:31: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 99D08EE2; Tue, 10 Jul 2018 18:31:31 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Jiri Kosina Subject: [PATCH 4.9 38/52] HID: hiddev: fix potential Spectre v1 Date: Tue, 10 Jul 2018 20:25:06 +0200 Message-Id: <20180710182452.860076552@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180710182449.285532226@linuxfoundation.org> References: <20180710182449.285532226@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: Gustavo A. R. Silva commit 4f65245f2d178b9cba48350620d76faa4a098841 upstream. uref->field_index, uref->usage_index, finfo.field_index and cinfo.index can be indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: drivers/hid/usbhid/hiddev.c:473 hiddev_ioctl_usage() warn: potential spectre issue 'report->field' (local cap) drivers/hid/usbhid/hiddev.c:477 hiddev_ioctl_usage() warn: potential spectre issue 'field->usage' (local cap) drivers/hid/usbhid/hiddev.c:757 hiddev_ioctl() warn: potential spectre issue 'report->field' (local cap) drivers/hid/usbhid/hiddev.c:801 hiddev_ioctl() warn: potential spectre issue 'hid->collection' (local cap) Fix this by sanitizing such structure fields before using them to index report->field, field->usage and hid->collection Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva Signed-off-by: Jiri Kosina Signed-off-by: Greg Kroah-Hartman --- drivers/hid/usbhid/hiddev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) --- a/drivers/hid/usbhid/hiddev.c +++ b/drivers/hid/usbhid/hiddev.c @@ -35,6 +35,7 @@ #include #include #include +#include #include "usbhid.h" #ifdef CONFIG_USB_DYNAMIC_MINORS @@ -478,10 +479,14 @@ static noinline int hiddev_ioctl_usage(s if (uref->field_index >= report->maxfield) goto inval; + uref->field_index = array_index_nospec(uref->field_index, + report->maxfield); field = report->field[uref->field_index]; if (uref->usage_index >= field->maxusage) goto inval; + uref->usage_index = array_index_nospec(uref->usage_index, + field->maxusage); uref->usage_code = field->usage[uref->usage_index].hid; @@ -508,6 +513,8 @@ static noinline int hiddev_ioctl_usage(s if (uref->field_index >= report->maxfield) goto inval; + uref->field_index = array_index_nospec(uref->field_index, + report->maxfield); field = report->field[uref->field_index]; @@ -761,6 +768,8 @@ static long hiddev_ioctl(struct file *fi if (finfo.field_index >= report->maxfield) break; + finfo.field_index = array_index_nospec(finfo.field_index, + report->maxfield); field = report->field[finfo.field_index]; memset(&finfo, 0, sizeof(finfo)); @@ -801,6 +810,8 @@ static long hiddev_ioctl(struct file *fi if (cinfo.index >= hid->maxcollection) break; + cinfo.index = array_index_nospec(cinfo.index, + hid->maxcollection); cinfo.type = hid->collection[cinfo.index].type; cinfo.usage = hid->collection[cinfo.index].usage;