Received: by 10.192.165.148 with SMTP id m20csp4175073imm; Mon, 30 Apr 2018 13:12:35 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpRRjkLKBiFGo88R7MEQPBrjuJuhHgbu8cj3e/2F+ffts+iw3NvdoxTSQ2pM96wkdIvrMcW X-Received: by 2002:a17:902:aa97:: with SMTP id d23-v6mr13357165plr.293.1525119155000; Mon, 30 Apr 2018 13:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119154; cv=none; d=google.com; s=arc-20160816; b=a+/jUZ4jk9MfecOm2lJhj7bm6g2hH9CWXOjcjigx9VLEB7tRDygScvAdm4IA2RO4FL Ynv7lvYQ/pQAJiXhISBv7U2/wp7WWxBSJYBFVAB2RDfcpBsqe8bjyi9aIl2q2w1nu5ZK bd50z63qUm5odSqlhTbzjlo2htFAIEo7GP929HLIX60821sqRPhiRWizxA2KAu6rOzun orj/EcpearxgBvLdR2Kktz8MZnNEJTPx7H33eCZvilu8xhlFz0kdsZSQ4d7MjtnBk3/Y E5mEbKuO+7EqO3EPo0fJbwIZMjMoUuyPy+5vpOOGA0TS6MGHQApcJYOw0QfDUuoi8ZdU VndA== 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=+H4B1hVk29OhuNyMYAaMBlF6iliilSrI3KpPK5orw8U=; b=yknLpbeCa7hHfEfQUT1VoeymvuBcnZgT9d3RmBGTfDOLfaThInNteIZmgLUFNpFM7a qij8W+9rHpjWeHBQftabLIf9RbElcTsnX0BiswEZgIqJxxyFLrPhjaxryaASXdPv9S0D ZUmXcmT1Xnn1pVTfbc5A4mM2WFgs/GEDxUaqR2EZKBRIqrKxCK0z0qdi43fED0/MLUKZ kGToV7WpHb+MEyR/1tmYvZIlj1cU4TV7q/u0cDqyKIGhka5PCKBHbAjGuGimRNODttkt 460Sg76YiQGdI381XKh//x2VufovVNb/R/KFI8duAghC7hfkl/uZh20kcKS757QanzsV FqDw== 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 x25si8332496pfj.347.2018.04.30.13.12.20; Mon, 30 Apr 2018 13:12:34 -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 S1755913AbeD3UMC (ORCPT + 99 others); Mon, 30 Apr 2018 16:12:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:33442 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755147AbeD3T1N (ORCPT ); Mon, 30 Apr 2018 15:27:13 -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 D5CC522DCB; Mon, 30 Apr 2018 19:27:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D5CC522DCB 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.14 38/91] ALSA: asihpi: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:20 -0700 Message-Id: <20180430184006.150619209@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184004.216234025@linuxfoundation.org> References: <20180430184004.216234025@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.14-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,