Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp20219imu; Thu, 8 Nov 2018 14:02:46 -0800 (PST) X-Google-Smtp-Source: AJdET5fdG5lHEbN5qxSr+0XwH5EEnPj8jmOwIMOrzZHvu1Vu7DzDMfHtfaNPyib70XUVMnDRuBPB X-Received: by 2002:a62:e10c:: with SMTP id q12-v6mr6150960pfh.75.1541714566508; Thu, 08 Nov 2018 14:02:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541714566; cv=none; d=google.com; s=arc-20160816; b=JnM+j3x6T3TMPfleYmKsVZuFSi6OhYOnIgA7W/PDzK5f3Db0tZT+/DPpwFGCpRtHSl uGv7MTI7cE7xBwWo20r3dayEIfai5IfX9Ob6pboEvGA31P1J9e6/MKPkS2alyJ6muORC BGTuWyLAnfNNtuXV+K+xeLu8/juR7Xa0sY4iU3rB6Twu6cOTJ5xqFx2CQaEqWFSfgJSO pSpvDsg3K5cwdoCGk1CYiAmngVcJWnEQzthWOLTXn4b343D2BjYeuuCIHOVcbycIl1qn pbw4p9wIwbdHe3WIdLOIuB0ZkOY3u7NuJzI3RbcxzlNEDL5jQvSHGy1PklqiiJtANqDJ ImAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=X6T5vwHUG3524oJ2mKSRgQ7akGHzCEVB+1dFy1kcze8=; b=Ynf0mV7DV6lbmPl+2x7z5eRitDRwLbWkZnujr6l4D7F8+bNVFxIOPMzCjiw49Sw2+W KPPIt/tqWdfX5J9o04DlWJVXmAvMr56o6dVqy2XfFh7rLHNcq7c5xtT1xXaH6Q0socf+ HDjU7ZFTcvsyOoGfusknNYhulmEzyUNSdrF2HRn/nbY8t/WthQRknlsEVqMNMk+q52t/ Z5ZTquF5WWKbgELzwaCJjWbsJ+Wx3Pw2g7NHTdJn3cc5HfuWN5TY5j+sNhvjX0gN2xki N7nQrBm/JoU+NOfyx2ZhZjCxzi94kX9aAoOjXz6Irbml19cBlYoISe9CBBC0p0AynKtt /EBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="vZspvF/l"; 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 o10-v6si4955464pgl.134.2018.11.08.14.02.30; Thu, 08 Nov 2018 14:02:46 -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; dkim=pass header.i=@kernel.org header.s=default header.b="vZspvF/l"; 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 S1730897AbeKIHjF (ORCPT + 99 others); Fri, 9 Nov 2018 02:39:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:58646 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728090AbeKIHjE (ORCPT ); Fri, 9 Nov 2018 02:39:04 -0500 Received: from localhost (unknown [208.72.13.198]) (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 8560C20892; Thu, 8 Nov 2018 22:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541714495; bh=VX3Dp+J9sbgHcEF8ms/W+ZtwfY3Tt5eilorz0gib4fs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vZspvF/lgqViOAUeKAOdBJsAE7xuwKeKS8q/0ynxAioKWN+SU5usoZPbTyp3AqINA LihbOHL85o5KpooN2oOi+O30O2sX0rvWoeq+JYEqGMLmm7V5GzKpdVm2OzciJQjohV MY/SQ3bOQ0AdgO5Zz5x6s6ZNV1LKf0qd3RTtjjkI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Gustavo A. R. Silva" , Felipe Balbi Subject: [PATCH 4.4 109/114] usb: gadget: storage: Fix Spectre v1 vulnerability Date: Thu, 8 Nov 2018 13:52:04 -0800 Message-Id: <20181108215110.618226295@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181108215059.051093652@linuxfoundation.org> References: <20181108215059.051093652@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: 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 Cc: stable@vger.kernel.org Signed-off-by: Gustavo A. R. Silva Acked-by: Felipe Balbi Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/f_mass_storage.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/gadget/function/f_mass_storage.c +++ b/drivers/usb/gadget/function/f_mass_storage.c @@ -220,6 +220,8 @@ #include #include +#include + #include "configfs.h" @@ -3260,6 +3262,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]) {