Received: by 10.192.165.148 with SMTP id m20csp4191392imm; Mon, 30 Apr 2018 13:32:39 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo/2Vz2aifKF34/1v8t05w2YjAwRhRzuYDUIM1zOwNY8OhmUaROTHTQvdjalRKd5CDNBmdT X-Received: by 2002:a17:902:7d92:: with SMTP id a18-v6mr13899259plm.331.1525120359929; Mon, 30 Apr 2018 13:32:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120359; cv=none; d=google.com; s=arc-20160816; b=0fEgqDC7PR8zGNc20UVDYTvVozSvvyczq01fxtdmo7jU4PZ3UpGmAlBX+3+K0RR4xy /M42ZLRiEa4/8EwC5XpuxfO7RKa2M5GEanKW9Vf4yusjLq/zZzbkhrgGXIkm8KhvzFtO E25Z4SioNh1dfkYc/k2sArCT7RZLVyvGyf9abqw61sn4yFOjaUdQc/+2YDgTSP0GwJ/M exBsmdjF2B51+GLPRoUuGlReIf9Ry4nVAUP9VyXYsbuDuubClyDF3KDu80qlQ0k61XUw QKyI7ST5sQQXwXSrVLZc0P7Hp+TOVkWQjkE7Q3UkV7dmaEDIN5/+CQxXVjDUWbmrpWdX 4YTQ== 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=LzDW5Hn56GEnfeOHzOGt1xed2ZWhhZGwBwC5qYbMcH8=; b=sA6mkkxX6F0Mw6ceauPHdSa2W1jILeyqJHaeZskayKk7wuELVKI57gdH3zA3Wm3k/b gRcZqsmrVK0bVJkhGKAISlVIACVseQyCp22Qs40UhPu5VsCPGybJn1VZXCJK9lJaEqs/ tJvXS5YQMXjgQeGzB1oFvqC+xU3kC0moXgRf9+Vc+7op8NZW5S99Txo7Uajuhy9wTXCl HBVkGy3x6DGBGIFTl0bpCzd/YTsMGjL4nFP0iRkCEUENkJY9aWTlM5qXcNhCAE8J2x9Q PaoOcMmBWKqn++DntQqgxsHoXVn8q41ge9MMbjQ60TwZherBEOfOgT/eDxaru5JQKR6B aDGw== 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 v29-v6si6761494pgn.510.2018.04.30.13.32.25; Mon, 30 Apr 2018 13:32:39 -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 S1755539AbeD3T0L (ORCPT + 99 others); Mon, 30 Apr 2018 15:26:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:59504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755528AbeD3T0J (ORCPT ); Mon, 30 Apr 2018 15:26:09 -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 6B52E22DBE; Mon, 30 Apr 2018 19:26:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B52E22DBE 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.4 21/44] ALSA: asihpi: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:32 -0700 Message-Id: <20180430190947.189947288@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430190946.093694747@linuxfoundation.org> References: <20180430190946.093694747@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.4-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,