Received: by 10.192.165.148 with SMTP id m20csp4171386imm; Mon, 30 Apr 2018 13:08:01 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqkKi5l7ufILCUVvgVgfUNzzz4pcDJtUUdoXIHD5PmWcfC9nDoZ0/nXdnzSF5dp3iGAwZaK X-Received: by 10.98.59.24 with SMTP id i24mr12995304pfa.246.1525118881492; Mon, 30 Apr 2018 13:08:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525118881; cv=none; d=google.com; s=arc-20160816; b=qRfMyB0OrKaJzHkKb+j8bJ3jjnsoAgjQAjtJixS/7/dJHMTr+PT+N/bw/OWkPPAENq KW44sdfYysUu6RsFaD86NmOFNYFhvKxhhYz8qgvPmW+mCpue9HVZpO50kHPjXBvumlob esUuJajksMyGsPHjncYNaRaeBiYIQqFU/6L6wKtgoV9lhRW6xinpBw/93Gbhbr17Mq4i N9fkDbMgY0F6GLqYxR5Ds6ruG/wYYkjlTPa8Dm9d6nZYVtg/1Uz5p27VQOmDFSnk/Qc/ ZB6e7CTctRbmU+DPYxg55/Q3fBaQPdboRdEByyXPqYIOhUD5Qv7gyKdgTLaeuuIl1yre R85Q== 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=DMrY/p/S+Xx52MZ2G0aUTOwanXobs1Qc7c0E76uf9E4=; b=XruRMZIvpDDYfNRTJ0yi16Zet77wjXAcymJJaziYr2IR94ajsRK1ZwhfYAI0g2/EjQ Tw38pDOY1kAx+3daHNnVcWNfP9sqf2znKvqx3IfbB1xWHSP+wT4ZZUpCyj8Ugc7MMCFC dPtaZT3ZHrCeASZrrWFSq6g1hFt6I1gEoKaQbpuyxLpkSZkXti0t/DtrBXOkyU0jjWq2 KN+l9HErLiA8+i+0Dh7hGTmQppdygchucz2I0K7bZeVCdfWF+fXDiiNW0D9Nx+yBSL1g JTiBwReNEof58n9PWPy7QFTxbeB/+K/VFs/HKGL5pXppAGt0YAFA3IFseMVgTGJ+bbbO 91wg== 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 b4-v6si6631966pgu.79.2018.04.30.13.07.47; Mon, 30 Apr 2018 13:08:01 -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 S932176AbeD3T1W (ORCPT + 99 others); Mon, 30 Apr 2018 15:27:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:33634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755284AbeD3T1T (ORCPT ); Mon, 30 Apr 2018 15:27:19 -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 5C00122DC1; Mon, 30 Apr 2018 19:27:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5C00122DC1 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 46/91] ALSA: hda: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:28 -0700 Message-Id: <20180430184006.585130167@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 69fa6f19b95597618ab30438a27b67ad93daa7c7 upstream. As recently Smatch suggested, one place in HD-audio hwdep ioctl codes may expand the array directly from the user-space value with speculation: sound/pci/hda/hda_local.h:467 get_wcaps() warn: potential spectre issue 'codec->wcaps' As get_wcaps() itself is a fairly frequently called inline function, and there is only one single call with a user-space value, we replace only the latter one to open-code locally with array_index_nospec() hardening in this patch. 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/hda/hda_hwdep.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/sound/pci/hda/hda_hwdep.c +++ b/sound/pci/hda/hda_hwdep.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "hda_codec.h" #include "hda_local.h" @@ -51,7 +52,16 @@ static int get_wcap_ioctl(struct hda_cod if (get_user(verb, &arg->verb)) return -EFAULT; - res = get_wcaps(codec, verb >> 24); + /* open-code get_wcaps(verb>>24) with nospec */ + verb >>= 24; + if (verb < codec->core.start_nid || + verb >= codec->core.start_nid + codec->core.num_nodes) { + res = 0; + } else { + verb -= codec->core.start_nid; + verb = array_index_nospec(verb, codec->core.num_nodes); + res = codec->wcaps[verb]; + } if (put_user(res, &arg->res)) return -EFAULT; return 0;