Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3016686imu; Sun, 9 Dec 2018 15:12:02 -0800 (PST) X-Google-Smtp-Source: AFSGD/VM5IQr3BfZ+JeL9MudpVb/h3k8CJL9TGwHaSobP7TJ7E3oBCxGLFUnYmtMN8l38duWKF3R X-Received: by 2002:a17:902:128c:: with SMTP id g12mr9577400pla.146.1544397122755; Sun, 09 Dec 2018 15:12:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544397122; cv=none; d=google.com; s=arc-20160816; b=CAWE2sI4+RtKtka0/Y55078JQ32/tfWpYH0bwEK15H7VL3CIYxva3BG7IbkIgyMD+p lgpD44GiJY+N6i0gvGHuegBVt3qSJ0u4Bj3wVK1YNWhlvjTcv+m+ksCLI1lOy4Gen2Pw 8ZxxljHzgapDfoCmslXFMkvW+ACjX0sm/0pSikI4WTtqzoJZ64wPCzIqdyfYQZlSY9ab 5wGTQUhBBR0DQkOAdlP/aqgq7nqKqoLmDOrAhB07K67U7Nv5fACxtXTkcrPDW5fLQkUZ J239tiOx/Pkn97AyLM4xRth4kuccJToQIIkxKQxytMKcqmly5jZuFaa9+Ojuj3V2p+GT 2pBw== 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=Zp3J72x9y1dOUC2giZJkBFcXiv27xgM4t3mwF3CLes4=; b=PVVBOXQUKv7wlET9vKuRJ/8WcMu0LFPXKUsCceI+JFtM6CrO5QsSH6RMvq/5sKZEss 8oyCZoqTS0Jy2xre5hsTbNWmMKhwHQP9AeSfinLmDu5xHAVwRbjgSflH4dc75Z9jIcML LWu4ppg0jRHPZUiS445SSGMfXIJRx60v6jTjbeqAwI0hSpX25/FYPXw7hzjGpuqW1d5k R2Kezzqv+TZnQwHkZ/37BJPYTvkA5SenmL6JX4jRR8f417q5+IVqP7z+zIooLQQcPKtl 1nLuWX+saX7dq0RDTgiTzbu0Ot7zap7PS1PKKCQm7HeMJnbKZnKOpazf4t8QKwIsHUiJ hyaw== 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 b15si8512563plm.431.2018.12.09.15.11.47; Sun, 09 Dec 2018 15:12:02 -0800 (PST) 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 S1727870AbeLIWUE (ORCPT + 99 others); Sun, 9 Dec 2018 17:20:04 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:35424 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726553AbeLIVzZ (ORCPT ); Sun, 9 Dec 2018 16:55:25 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW72o-0002iq-29; Sun, 09 Dec 2018 21:55:22 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72l-0003gt-EG; Sun, 09 Dec 2018 21:55:19 +0000 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, "Gustavo A. R. Silva" , "Greg Kroah-Hartman" , "Felipe Balbi" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 315/328] usb: gadget: storage: Fix Spectre v1 vulnerability In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 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.62-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: "Gustavo A. R. Silva" commit 9ae24af3669111d418242caec8dd4ebd9ba26860 upstream. num can be indirectly controlled by user-space, hence leading to a potential exploitation of the Spectre variant 1 vulnerability. This issue was detected with the help of Smatch: drivers/usb/gadget/function/f_mass_storage.c:3177 fsg_lun_make() warn: potential spectre issue 'fsg_opts->common->luns' [r] (local cap) Fix this by sanitizing num before using it to index fsg_opts->common->luns 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 Acked-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- drivers/usb/gadget/f_mass_storage.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/gadget/f_mass_storage.c +++ b/drivers/usb/gadget/f_mass_storage.c @@ -219,6 +219,8 @@ #include #include +#include + #include "gadget_chips.h" #include "configfs.h" @@ -3344,6 +3346,7 @@ static struct config_group *fsg_lun_make fsg_opts = to_fsg_opts(&group->cg_item); if (num >= FSG_MAX_LUNS) return ERR_PTR(-ERANGE); + num = array_index_nospec(num, FSG_MAX_LUNS); mutex_lock(&fsg_opts->lock); if (fsg_opts->refcnt || fsg_opts->common->luns[num]) {