Received: by 10.192.165.148 with SMTP id m20csp4185245imm; Mon, 30 Apr 2018 13:25:31 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrXE/MQQwN9cLkfgrnXTUTfCHi9yhsVAv2hEMjoRLFNojDdtQpRQxKwYXcf1FVRBe2pllHc X-Received: by 2002:a63:9e12:: with SMTP id s18-v6mr384007pgd.207.1525119931574; Mon, 30 Apr 2018 13:25:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525119931; cv=none; d=google.com; s=arc-20160816; b=HRYPGBYhMOOSRPvO9+by46LVMsklEaAXKyf58oA0UxG14GN0v5xPMNpknqK32Q9rts 4tkOgZOzaSuyJB3+q8rOHnNd4RPE7O8uG1v9qqboVT+oCPQOLvS5s77oqEXrV6LD0WgN 0D+bUYgQz20k/NSV9mEZ3yfT6DAzFBM326aXbYJys4XbTy/4YGmB4H1cTcFsDnb+18oh RT+8MQ0ZrT/di58wU2R0xqeA5XRVXxK3J2ythPHkkOXduOmgMJQJGx3RQKjMPTadZNtl NyfRF/5rNFs+teecc6BFKe63yW8eY4M6ynijbP27inU8FnbCJ+7Dbh/1lfXB6o14kZqc 61ng== 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=phwFxakV5GV63epU6nFRAzJFJ9IemiHq4Gx3CMLkE6Q=; b=kximfvolJ4IvwY+Qx9go05BqIYUhaaZ2qo6Tx2I8f8aY528q/O7IRSfk2PGl1CYiCW VtD63tAoDrowh4avbnfpvCyBk8UVV08FPaCAF17ApcWlIK/V37IozU3gNr0/kmdBeSXM 9RAgnlZmy6KTMxsjyLvgK3CTPQEO1Cn6/oPZshkuGdl+EinfPxQ9na55FCdnXaGuqbO4 byu13xx55t6NLYSUdj+SapZ0rjQoqChHykh1/9w/nrTMPeqtgPy3DvtL2frONduExZsf rrSXa+8PnqyNdOn0FD14Uk74ND5RSAhh6pSBkaTzUIVyuwgbx5a8taDTWWxkUnAozfAP Fc5Q== 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 h3-v6si6570708pgf.314.2018.04.30.13.25.17; Mon, 30 Apr 2018 13:25:31 -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 S1756197AbeD3UYA (ORCPT + 99 others); Mon, 30 Apr 2018 16:24:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:60334 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755688AbeD3T0c (ORCPT ); Mon, 30 Apr 2018 15:26:32 -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 412F022DCB; Mon, 30 Apr 2018 19:26:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 412F022DCB 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 34/61] ALSA: hda: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:37 -0700 Message-Id: <20180430183954.289831998@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 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;