Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1432713yba; Tue, 2 Apr 2019 08:45:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqy7qwLDs88+zU+a3+ARU5393fO/NCpe0vKg1FKBrjlWfaHshywwyOLXUU4hgkutfXAHxBYh X-Received: by 2002:a17:902:7841:: with SMTP id e1mr12037160pln.303.1554219954384; Tue, 02 Apr 2019 08:45:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554219954; cv=none; d=google.com; s=arc-20160816; b=ErUQlmWHZS1HKtWRJRU/NMyFRqrbStFv62F9EBaZezWsU3GKFW7zRniaD4J8DDQqeg WY4Rk4WFKkv/lqq+TZ4UTDy6iDIrNs5QKgEu9JG4IW9amvLrhQtqSY9IerBe40CRqaxd tVf6O6rqzMwvpwKbBu7Qt8xor8J/x16OXgWnmyd3SbDmYHQEFBg40bCTRnVDRz1VWjUz IQRpvb9fNQvIHNnRjfVkaHwmhFyo+MbFhqmB+u/r7QGiqopMsVL4uXlnXbN7bya3Udcu +oKWyTlsIB1CFgfuXKnxX53xItxbmYCBXbZ6perQEdCaCfGpxRPVdKvSjBi7LjyT1XEq j0OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=BmhFTo3nitG1YEL3Yn3H8NpiFQ6VDYYVFl6JykMPNoA=; b=A60STh5h/E60k5p9sUDfwuEc+/0nU3Ox9r+UbniIzWD2IbzxvnRcLYMAylyud0Kag5 lZQRjr4LjXryZOEhLaO+0LgWQcPKzxzM2cR5viUfLV8aWn5VTgRYV+pVcKBBZgnPKyLp Us6b6SV7GcWoR9pdh/Rupn2Tsl49llgZ8xlf/yITiDqt/MFXeAxFn87ldpW/f9MTQGoL MhFl5V+NMV3GbTQ5XTm+mlH3gZc/hZr/872vjTvIfd8xTIcPqtuJyl49HsNz7LWuI4T/ FPMJ0a3af3ZJTGGnzISBfbb7IpPt2ecGVVFsf1hpiQu97xi3kdxCerRgx+kD/QbkYz37 i6hg== 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 a17si10187141pgk.572.2019.04.02.08.45.39; Tue, 02 Apr 2019 08:45:54 -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 S1732316AbfDBNsd (ORCPT + 99 others); Tue, 2 Apr 2019 09:48:33 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:42900 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731201AbfDBNkC (ORCPT ); Tue, 2 Apr 2019 09:40:02 -0400 Received: from [167.98.27.226] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hBJdw-0002nY-3w; Tue, 02 Apr 2019 14:40:00 +0100 Received: from ben by deadeye with local (Exim 4.92) (envelope-from ) id 1hBJdv-0004sq-7Y; Tue, 02 Apr 2019 14:39:59 +0100 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, Denis Kirjanov , "Takashi Iwai" , "Gustavo A. R. Silva" Date: Tue, 02 Apr 2019 14:38:27 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 30/99] ALSA: emux: Fix potential Spectre v1 vulnerabilities In-Reply-To: X-SA-Exim-Connect-IP: 167.98.27.226 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.65-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: "Gustavo A. R. Silva" commit 4aea96f4237cea0c51a8bc87c0db31f0f932f1f0 upstream. info.mode and info.port are indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. These issues were detected with the help of Smatch: sound/synth/emux/emux_hwdep.c:72 snd_emux_hwdep_misc_mode() warn: potential spectre issue 'emu->portptrs[i]->ctrls' [w] (local cap) sound/synth/emux/emux_hwdep.c:75 snd_emux_hwdep_misc_mode() warn: potential spectre issue 'emu->portptrs' [w] (local cap) sound/synth/emux/emux_hwdep.c:75 snd_emux_hwdep_misc_mode() warn: potential spectre issue 'emu->portptrs[info.port]->ctrls' [w] (local cap) Fix this by sanitizing both info.mode and info.port before using them to index emu->portptrs[i]->ctrls, emu->portptrs[info.port]->ctrls and emu->portptrs. Notice that given that speculation windows are large, the policy is to kill the speculation on the first load and not worry if it can be completed with a dependent load/store [1]. [1] https://marc.info/?l=linux-kernel&m=152449131114778&w=2 Signed-off-by: Gustavo A. R. Silva Signed-off-by: Takashi Iwai [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- sound/synth/emux/emux_hwdep.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/sound/synth/emux/emux_hwdep.c +++ b/sound/synth/emux/emux_hwdep.c @@ -22,9 +22,9 @@ #include #include #include +#include #include "emux_voice.h" - #define TMP_CLIENT_ID 0x1001 /* @@ -66,13 +66,16 @@ snd_emux_hwdep_misc_mode(struct snd_emux return -EFAULT; if (info.mode < 0 || info.mode >= EMUX_MD_END) return -EINVAL; + info.mode = array_index_nospec(info.mode, EMUX_MD_END); if (info.port < 0) { for (i = 0; i < emu->num_ports; i++) emu->portptrs[i]->ctrls[info.mode] = info.value; } else { - if (info.port < emu->num_ports) + if (info.port < emu->num_ports) { + info.port = array_index_nospec(info.port, emu->num_ports); emu->portptrs[info.port]->ctrls[info.mode] = info.value; + } } return 0; }