Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1081514imm; Fri, 27 Jul 2018 10:48:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfVZEds0IWndm4kCl8sfdMpzzWkPOdOKaBgUU8FXZkYtPBOvqcaY9cOxzP4A6cKSBGIDegU X-Received: by 2002:a62:700a:: with SMTP id l10-v6mr7499923pfc.71.1532713685658; Fri, 27 Jul 2018 10:48:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532713685; cv=none; d=google.com; s=arc-20160816; b=ttJXBNQWUT17683vVTPPoAJLVNdN5wVNMY4poRCAV9fUHWQ41BrJRLcNfh7R0ccpiI jy/RUiBlkUgPvlTrgXaIqgaqBPmuK/k+SC4yoDe68XVMtLNni+zRJcjmeCRWsbAMz7MO ghhKh1bMrjMBMY58744etFqRvCAbsPPXaTIR7gD3UTfmpEXh3qD9aeurV3ZXxfOs/8ii UG92on72/aTvxhvwtOR0x+/RdZG0HlRpKw/IyxcBBoDYTW5kb3TT8ar0maOQd4R+2Xsl wYnWoAkHxPhuERHOj5UDV3VDq7gHxbDPZ3HbNIQjwO33snA1eDJ/ljRQMMTOk1LxqvU2 WijA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=+E6AAX1orXjlGtD5hiCp2RiCemmQZJG/dje0R24BJnA=; b=mExzDYHZDhdaZMFpbro6iwbHLer3BED0EHlZp4rgqyluskWiiSXkGGBHJJQJJi7gyR ie+PQHpiKlYRI6MKTxm52WnYLsmMydiiY1akILqsBCx7O+ok4LYpqttx2u4R7HgSpFQ7 H7N7NuklpP/VdsQD+6ED/2pUnV0Zr+loyqzKrkoHp1bn4HIlvEjoJ15O1pfagp9psF9S e2jwtWt1rP2MbWuWdHOtJN4VD+Mj61P9eB7RbHzj6In+jy7+TNWv+zB8F+rlkf2PHIrF m5LZfPLpafYdn8CcjCLzWQ25uV76OXj/y/hvXyhkzg7OmJFvBBdLy+RKTcbJpwgdaE+K rElQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n1-v6si4426312pfe.66.2018.07.27.10.47.50; Fri, 27 Jul 2018 10:48:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389049AbeG0TJy (ORCPT + 99 others); Fri, 27 Jul 2018 15:09:54 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42038 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388909AbeG0TJy (ORCPT ); Fri, 27 Jul 2018 15:09:54 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AB5C740216E5; Fri, 27 Jul 2018 17:46:56 +0000 (UTC) Received: from treble (ovpn-120-105.rdu2.redhat.com [10.10.120.105]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 475A12026D6B; Fri, 27 Jul 2018 17:46:56 +0000 (UTC) Date: Fri, 27 Jul 2018 12:46:54 -0500 From: Josh Poimboeuf To: Jeremy Cline Cc: Theodore Ts'o , Andreas Dilger , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH 1/3] ext4: super: Fix spectre gadget in ext4_quota_on Message-ID: <20180727174654.bnooz26puuo7456w@treble> References: <20180727162357.30801-1-jcline@redhat.com> <20180727162357.30801-2-jcline@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20180727162357.30801-2-jcline@redhat.com> User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 27 Jul 2018 17:46:56 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.5]); Fri, 27 Jul 2018 17:46:56 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jpoimboe@redhat.com' RCPT:'' Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jul 27, 2018 at 04:23:55PM +0000, Jeremy Cline wrote: > 'type' is a user-controlled value used to index into 's_qf_names', which > can be used in a Spectre v1 attack. Clamp 'type' to the size of the > array to avoid a speculative out-of-bounds read. > > Cc: Josh Poimboeuf > Cc: stable@vger.kernel.org > Signed-off-by: Jeremy Cline > --- > fs/ext4/super.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/fs/ext4/super.c b/fs/ext4/super.c > index 6480e763080f..c04a09b51742 100644 > --- a/fs/ext4/super.c > +++ b/fs/ext4/super.c > @@ -40,6 +40,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -5559,6 +5560,7 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id, > if (path->dentry->d_sb != sb) > return -EXDEV; > /* Journaling quota? */ > + type = array_index_nospec(type, EXT4_MAXQUOTAS); > if (EXT4_SB(sb)->s_qf_names[type]) { > /* Quotafile not in fs root? */ > if (path->dentry->d_parent != sb->s_root) Generally we try to put the array_index_nospec() close to the bounds check for which it's trying to prevent speculation past. In this case, I'd expect the EXT4_MAXQUOTAS bounds check to be in do_quotactl(), but it seems to be missing: if (type >= (XQM_COMMAND(cmd) ? XQM_MAXQUOTAS : MAXQUOTAS)) return -EINVAL; Also it looks like XQM_MAXQUOTAS, MAXQUOTAS, and EXT4_MAXQUOTAS all have the same value (3). Maybe they can be consolidated to just use MAXQUOTAS everywhere? Then the nospec would be simple: if (type >= MAXQUOTAS) return -EINVAL; type = array_index_nospec(type, MAXQUOTAS); Otherwise I think we may need to disperse the array_index_nospec calls deeper in the callchain. -- Josh