Received: by 10.192.165.148 with SMTP id m20csp4194531imm; Mon, 30 Apr 2018 13:36:22 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqX6XokpE13V1iZq1d1PdIlflOlN8Dsmt+OIMJXXUkkrteLdorqcgx1I1ylio2vOVXLc2+Q X-Received: by 2002:a63:10a:: with SMTP id 10-v6mr10998989pgb.444.1525120582129; Mon, 30 Apr 2018 13:36:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525120582; cv=none; d=google.com; s=arc-20160816; b=bLiWoxUtAoaNNC0iRV8++fzF8mxzTFKo/ZwKgFP1DDvpIq2/BOfDz46ptHnz8mNAJZ ALQx8cNs/F/pv7rNwVAZp4ep9BV5N68xLH1K6smOGXE80OsMK13KmQW2pDVmTwOSyYSh 9vuwVBZAIB8TT2soa5nKEFsd7hhZJ1iobvKxixsItX492z2rSPvRf7yfYD6p2Wxrc/0u LCo35FdSs0mbBNapJO0ISur9xtrPUHxmwjrfVffVz5lz736O88FeT43Z3h0x6gK+1ZWZ GlFPN+fuK/t8gqCgjTTv5x8LCzqcWh/I+Vr9TvAsmrkaWkhjSXUE91sW3jrtvTbi2WW0 vRIg== 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=/vobJAh7mvKmU/zDNRKLf/JdETdnIpzQLuI07Txzz7c=; b=FoI9rAMc4rl5l5U6Xby3sbRar3OJ9XTKwS3jQ32JjkYTS+rij4b4Z5c9O+auDleL1K LbfPYQFbqfbcploq5de5vmBIECxlmMTL82HVuUrUYfyAESSgrnGL2TfgI8T8K5iVCKr3 QsTuz+UFtoPy8O1REi9tCkUk9SqWNqVkhqul4SZ9yIE0a0rFazrjCev9DyMPV5htGlWS 4eVCrpSteX7u+s5cp4OKBzwDHNx4zq4ZYfXoIDGvsmBx6VHo6n4XzrvBg5vBkqsxq5s3 FwDX+58ZynVwLb//5vRKojj9YkMBKAeYWNGxdXIpssWlizfanMQ9YT2rxw4puzPPM0Hr K2ww== 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 x1si7852656pfm.32.2018.04.30.13.36.08; Mon, 30 Apr 2018 13:36: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 S1755597AbeD3Ufz (ORCPT + 99 others); Mon, 30 Apr 2018 16:35:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:58980 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755391AbeD3TZ5 (ORCPT ); Mon, 30 Apr 2018 15:25:57 -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 E921B22DAC; Mon, 30 Apr 2018 19:25:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E921B22DAC 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 28/44] ALSA: hda: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:39 -0700 Message-Id: <20180430190947.463498343@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 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;