Received: by 10.192.165.148 with SMTP id m20csp4185950imm; Mon, 30 Apr 2018 13:26:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpPkx0atIIp5nc7ESKfDjZp3M/xFXPl7ac9mR6165k+z2iXH/J78ZwNjttjIIID90vx8oe2 X-Received: by 2002:a17:902:8692:: with SMTP id g18-v6mr13694545plo.152.1525119982240; Mon, 30 Apr 2018 13:26:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119982; cv=none; d=google.com; s=arc-20160816; b=rmQ/7GLXLCuW6kv/vnPbNihw7ZMQZpqGajeh28AADFuSkCe84jS5zHjxzun2ZU6ZaC IJbTaHuHji1K1R4KUQkHuRivjogRbAMalLOhe2Fq3mtvmyq0OZs6FKvR2091LF9BWejR jFyUrvG6lBCaAOxD0ryzlh9Wnn8y4GF0XTb6zyiGmgl2zV83b/M4KSOj9LjPN2XyNC/7 CduEF4xQG7LIyfOv0kd6cXpswK5G0FwPW72loErRDOTBtvYRiKKSOcqt7E+XlGzTJ7CR FzWiSwE46dyMwsxv+pvfGmp+mlYKoUGosprUgIOoOhNO7I6HXHKV4qMiGwwGa30gK+or xiNA== 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=oeYfoFKC6NGW3hBgpSApsQWd42BR/eBusLPjnQeScYs=; b=PWUxc/nTmobKuggWRGgQ3uXY7HsQ9H63t2VAd2RTWxxVwS7j8KKEv4PrliqCAotP1S lYXzJYYgMgU+9BCTPnXHIA3DP1T6iu7XmqKgJaHrT86L+TXbZe4BqiTPnhvl5ioZMN+3 i+nst5c6G8UHa16S7GGdjN2AzKt8lr5KKiZPfy/wE7EFCkmWLJ8bDHRQWiM7q0mwmm3O 2DEk8W8Mxo2JbHywVQn+8KDsVKWcy6WZOBaFrWPGx8SSO+qSr2Kk+eO4iRqG3VN8iyZx 4JLqfjniw/qjwNcqxzmz+apbMPXM6nzyZ9k1VpDMw5ZUD7KXaiBVngJdCifUty/7Lzqx RA8A== 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 d16-v6si8605073pli.176.2018.04.30.13.26.08; Mon, 30 Apr 2018 13:26:22 -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 S1755827AbeD3U0B (ORCPT + 99 others); Mon, 30 Apr 2018 16:26:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:60220 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755647AbeD3T03 (ORCPT ); Mon, 30 Apr 2018 15:26:29 -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 165B522E72; Mon, 30 Apr 2018 19:26:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 165B522E72 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 30/61] ALSA: control: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:33 -0700 Message-Id: <20180430183953.959159000@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 088e861edffb84879cf0c0d1b02eda078c3a0ffe upstream. As recently Smatch suggested, a few places in ALSA control core codes may expand the array directly from the user-space value with speculation: sound/core/control.c:1003 snd_ctl_elem_lock() warn: potential spectre issue 'kctl->vd' sound/core/control.c:1031 snd_ctl_elem_unlock() warn: potential spectre issue 'kctl->vd' sound/core/control.c:844 snd_ctl_elem_info() warn: potential spectre issue 'kctl->vd' sound/core/control.c:891 snd_ctl_elem_read() warn: potential spectre issue 'kctl->vd' sound/core/control.c:939 snd_ctl_elem_write() warn: potential spectre issue 'kctl->vd' Although all these seem doing only the first load without further reference, we may want to stay in a safer side, so hardening with array_index_nospec() would still make sense. In this patch, we put array_index_nospec() to the common snd_ctl_get_ioff*() helpers instead of each caller. These helpers are also referred from some drivers, too, and basically all usages are to calculate the array index from the user-space value, hence it's better to cover there. 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 --- include/sound/control.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/include/sound/control.h +++ b/include/sound/control.h @@ -22,6 +22,7 @@ * */ +#include #include #define snd_kcontrol_chip(kcontrol) ((kcontrol)->private_data) @@ -147,12 +148,14 @@ int snd_ctl_get_preferred_subdevice(stru static inline unsigned int snd_ctl_get_ioffnum(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id) { - return id->numid - kctl->id.numid; + unsigned int ioff = id->numid - kctl->id.numid; + return array_index_nospec(ioff, kctl->count); } static inline unsigned int snd_ctl_get_ioffidx(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id) { - return id->index - kctl->id.index; + unsigned int ioff = id->index - kctl->id.index; + return array_index_nospec(ioff, kctl->count); } static inline unsigned int snd_ctl_get_ioff(struct snd_kcontrol *kctl, struct snd_ctl_elem_id *id)