Received: by 10.192.165.148 with SMTP id m20csp4157689imm; Mon, 30 Apr 2018 12:52:45 -0700 (PDT) X-Google-Smtp-Source: AB8JxZqyezehZ+24W6qL+ebmc8ns4iaEWG+oVWZQFavUvf/8GNeDaq+vdzuWBcrVMvyhYTbZE1kB X-Received: by 2002:a17:902:41:: with SMTP id 59-v6mr13726050pla.345.1525117965102; Mon, 30 Apr 2018 12:52:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525117965; cv=none; d=google.com; s=arc-20160816; b=VeqBy8miilunltGMcCvujZxZOXJTOoXi8qk5Y9bytEvqJwxA2fLPyz82bBNxpSM0K5 kbwqOp75GbE3e5bFsMfHM9MNaQiUQTqsXe9exmVICG9nhCFYvMy+p/tZsnbNDXFuGzx1 Kc94KLE83PwwTeA8NOnW2YmgxmJ+Q1D687sxSbi+hnanc9Zr3AWOrU5bkaSxZFizDagb 7yxgm9PKxQNtA1obi+ePS+yAE6puJN2gpv43tYbbAlM1UKF0rbV29+kAdcAmdoT32NHq nxYSTdzTS6NKcl0IytQN7OBVyZQVDFgHc6JN0AqkVRU8M7w155+XTPPkTvcKljUnuJm2 xJUA== 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=TdzXt4zBeFPCie1Gcxvc3H6OpJzKcMsuGOPQMAlZFkk=; b=oWt6DWogMWTyvHgb4wIaj50NfYzJJFN4XCgwcDxUB2oqoSDo5LHnr3ikor6YhMp1pb diK55NGgAm5byEknGvrUxUmaWa2TmMgvhC3H+PYi6YH06WYTF8UBspbExSfTR6+YMtBD laG3WOm2TwADl737idiXLhPq6BZ42HFz3jxtruaB+VMQdJwwyLpLtQck8TQ97apl+Mie XWiPABuGJ3KzLFEFpScBnzwXFN18gf8puIZs6N5iJcQKsBRv4fxlqPcq857o6HxmsgtE 7qaZ6f7Op9aB40N0XRdVmd/miDegHQQPSq1jFIoPlaWlokk2GkmSr4NPBkA3QELBGAWJ N6xw== 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 k185-v6si6660661pgk.2.2018.04.30.12.52.01; Mon, 30 Apr 2018 12:52:45 -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 S1756670AbeD3Trf (ORCPT + 99 others); Mon, 30 Apr 2018 15:47:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:35834 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755763AbeD3T2S (ORCPT ); Mon, 30 Apr 2018 15:28:18 -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 C66C922DAC; Mon, 30 Apr 2018 19:28:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C66C922DAC 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.16 050/113] ALSA: hda: Hardening for potential Spectre v1 Date: Mon, 30 Apr 2018 12:24:21 -0700 Message-Id: <20180430184017.174230376@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180430184015.043892819@linuxfoundation.org> References: <20180430184015.043892819@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.16-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;