Received: by 10.192.165.148 with SMTP id m20csp4185816imm; Mon, 30 Apr 2018 13:26:12 -0700 (PDT) X-Google-Smtp-Source: AB8JxZppOGPEHvAxQy5nBOrcvr1Rq5LtW/bB30m8D5PPzYD98Wu4CNVusmQL1w3FvI3DiiDBOo9a X-Received: by 2002:a17:902:bf08:: with SMTP id bi8-v6mr13578968plb.353.1525119972897; Mon, 30 Apr 2018 13:26:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119972; cv=none; d=google.com; s=arc-20160816; b=wEgxEhXskeHEInfaZu187JE6RJujNXJ+6QTjRRtvH2CM7lsGryaTeYFJa+XoxLTQgF UYzy7q0Eagz22hNIc/JFxqAA/22+287Mrq80bGIcWvAWycZ8hd3pid6HOLjZQ0QLTXdM Mi6FEo65atCEPeW8CCj1Ac8iLeBpfZp7PVz4OD/82Tyw5n8kDS7fpv3wumrCyJYK17kb QOFYB2JJj08I9jDqyeKPpns92hR0V2VxeNKhZdJMGOl3VlguZc0EvPdIvdpT1DAlVlez YiQytV+WCU9WdXaPe/6ZLrREmSDiauXKrgmo8j451T5g6KYOhkPqLfxFuO6LAkKoxfvW v1Jw== 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:dmarc-filter :arc-authentication-results; bh=EW2TPUBtaO7XayPYNm+DAcdwZcrE8Ppa55aCfKFEvbY=; b=pNbBULTYs483/was2rikAMYzLd4xgYxycKg1pIUiL6HwcWW4jBRg8ImJsky6zk+Z7c ej4AbSm0iwCWZfEpx4P6pjVVFzvzw2fz6NMagnaPCMkJ597L5NxG86J5glNtSrSRxnvH 2AmIDOZipPwp1H05Uk9TsX6QaVYYyaaDwR6bZO6en88u1MZRh62jbsYzg7OU0DjpLGJ5 Y9Nk0G+A84ns0TFhW9YzfKhofxvplKbXLW1GEN8rcQJm6PvTxgRl/aMU/JIZda8Ufu39 jZgNdadpfoBX8VoJMAIH+udiCT1iQYPBxXYMf1Cn3XfdKY63Ezov1yNexyVWXRmQFVvQ v1pA== 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 g9-v6si6520924pgo.214.2018.04.30.13.25.58; Mon, 30 Apr 2018 13:26:12 -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 S1755691AbeD3T0c (ORCPT + 99 others); Mon, 30 Apr 2018 15:26:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:60138 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755628AbeD3T01 (ORCPT ); Mon, 30 Apr 2018 15:26:27 -0400 Received: from localhost (unknown [104.132.1.102]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 266FF22DCB; Mon, 30 Apr 2018 19:26:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 266FF22DCB Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=linuxfoundation.org Authentication-Results: mail.kernel.org; spf=fail smtp.mailfrom=gregkh@linuxfoundation.org From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Takashi Iwai Subject: [PATCH 4.9 27/61] ALSA: asihpi: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:30 -0700 Message-Id: <20180430183953.719547376@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430183951.312721450@linuxfoundation.org> References: <20180430183951.312721450@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: Takashi Iwai commit f9d94b57e30fd1575b4935045b32d738668aa74b upstream. As recently Smatch suggested, a couple of places in ASIHPI driver may expand the array directly from the user-space value with speculation: sound/pci/asihpi/hpimsginit.c:70 hpi_init_response() warn: potential spectre issue 'res_size' (local cap) sound/pci/asihpi/hpioctl.c:189 asihpi_hpi_ioctl() warn: potential spectre issue 'adapters' This patch puts array_index_nospec() for hardening against them. BugLink: https://marc.info/?l=linux-kernel&m=152411496503418&w=2 Reported-by: Dan Carpenter Cc: Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/asihpi/hpimsginit.c | 13 +++++++++---- sound/pci/asihpi/hpioctl.c | 4 +++- 2 files changed, 12 insertions(+), 5 deletions(-) --- a/sound/pci/asihpi/hpimsginit.c +++ b/sound/pci/asihpi/hpimsginit.c @@ -23,6 +23,7 @@ #include "hpi_internal.h" #include "hpimsginit.h" +#include /* The actual message size for each object type */ static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT; @@ -39,10 +40,12 @@ static void hpi_init_message(struct hpi_ { u16 size; - if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) + if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) { + object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1); size = msg_size[object]; - else + } else { size = sizeof(*phm); + } memset(phm, 0, size); phm->size = size; @@ -66,10 +69,12 @@ void hpi_init_response(struct hpi_respon { u16 size; - if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) + if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) { + object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1); size = res_size[object]; - else + } else { size = sizeof(*phr); + } memset(phr, 0, sizeof(*phr)); phr->size = size; --- a/sound/pci/asihpi/hpioctl.c +++ b/sound/pci/asihpi/hpioctl.c @@ -33,6 +33,7 @@ #include #include #include +#include #ifdef MODULE_FIRMWARE MODULE_FIRMWARE("asihpi/dsp5000.bin"); @@ -182,7 +183,8 @@ long asihpi_hpi_ioctl(struct file *file, struct hpi_adapter *pa = NULL; if (hm->h.adapter_index < ARRAY_SIZE(adapters)) - pa = &adapters[hm->h.adapter_index]; + pa = &adapters[array_index_nospec(hm->h.adapter_index, + ARRAY_SIZE(adapters))]; if (!pa || !pa->adapter || !pa->adapter->type) { hpi_init_response(&hr->r0, hm->h.object,