Received: by 10.192.165.148 with SMTP id m20csp4148238imm; Mon, 30 Apr 2018 12:40:15 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrUuNeV140MQgEIungHyTRftcFxc3B9CUNmQH3zFnApN8/lpilvdSEbfJa/O6+RaeqKOJnw X-Received: by 2002:a17:902:7596:: with SMTP id j22-v6mr13714713pll.334.1525117215146; Mon, 30 Apr 2018 12:40:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117215; cv=none; d=google.com; s=arc-20160816; b=cVNm/5oxyrm3bGqxepIMAPVey4NUTnhBCfYwmQXG+qLm4+ulusDEGz55aYYJsVuzX1 sT3v/YupX+NR/2pADMz9TklBJoyckPmDy/FklTsGcAstjwBUhmcrfTVTAY5E5YMsbVEp YHBwCEBqPsAm+GZLAnfzF/hLXtt199g7vXea352SWA6jUGns5SiBXd+mZSkgu5MNZGN2 aCUOjofBkbfjV/JizIIaxHgJ1sLyr9GMt996wLEcZH+E6jLw4Kqu+VQ7yEUnIpz44T8W 6KqWSX7lFEmC53Q14UFP2+uEpv4gDbDXVLrt+WXtdbiu1/07KrvNcuf5K7+uzzqhiMPF 0/+Q== 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=Ixqk4RTBdihBskGl5DhJbAwmfQ338VyBx3hTyUI8Tws=; b=eAkrVQIVi9sFYnTy0RJjU+fKH+2cAP9R/DLCrt1YQAGLJpzSmiuoe6oQ/NuGj3wJcE JVtXI/Ut5eW7mxd4GAv2LPkF4whd+YYgd9GA5sidbJx3nOTK4MzHAw81PfC6YRZGmndv 6fckanK7YTHsf5HcmRvRRZJ8e6opDjd/q3cq1MSj1kKHxYRGgEGlhM+Gkyk4JuuWO5s1 gR1NjyWTh8vcYVemvsemFwmWERGj/8K6x2l9GjmvxaYkhGhoxvxdWr650R3Zb56je3kv gwh9IK47jzQ/XC6cvsJNJeV4+qEqFaj/MsOLo3gBdU9/HLHae058pyJjwvIFg1X8z8N8 YuTw== 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 m2-v6si7759588plt.55.2018.04.30.12.40.01; Mon, 30 Apr 2018 12:40:15 -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 S1756416AbeD3Tjb (ORCPT + 99 others); Mon, 30 Apr 2018 15:39:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:36488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756302AbeD3T2g (ORCPT ); Mon, 30 Apr 2018 15:28:36 -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 9452F22DAC; Mon, 30 Apr 2018 19:28:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9452F22DAC 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.16 042/113] ALSA: asihpi: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:13 -0700 Message-Id: <20180430184016.830523146@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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"); @@ -186,7 +187,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,