Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4630174ybl; Wed, 22 Jan 2020 01:36:40 -0800 (PST) X-Google-Smtp-Source: APXvYqw+fUwtmItNaxrXDuzcQ45o4VVp3sudhRdACF+VmhxVHd3YNs2p6qzZUye1zmUE0rjz7qiJ X-Received: by 2002:a05:6830:158:: with SMTP id j24mr6918740otp.316.1579685800315; Wed, 22 Jan 2020 01:36:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579685800; cv=none; d=google.com; s=arc-20160816; b=cHIZTm7oqx2UAdeH0ZBkSsUIKbUvQ9153w34FbOBItZEmDBMVtyA9ilTBYmPkKemxG 1o6+qZWCv8IVUNQ2El4NBFp8FuPm8D2qPOPIwPsKOCc2zTBpX9GRLg7INBG93tn0Zzsl ZGV4VFswr8QLSfDKTgqnAfqfqdqh9uUFAMSGJ6oXaJUrcSoqSPHD6BHllydNQPE49/TG 4CMag0WMJ7O2FJjmNtPd6/1wtW1oS0EFzMVSPWChYIxAWlJbODoX1XJrWfDmY2eWocv5 bgNMKcRwTeJKDo0w4CqVn5awFq9QLvUXVWv3MeTFNe4w/OiKOCan021izCOWO1OU7dAU 5JXw== 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=VTOC3kqfqMQTnsp8tteDsKk3bHdrF2XMCyYFAbkONYw=; b=fQBVO2qZUyj4vQ/SHCTgafyBk9Kr5EC9gSHUy6C9bIUjEKRt60pQ0mNt7jTNQohTbx zXXtPb3MX8RjKelEKExXL0IaHurFiYbKBKykDdDbWtJoKZLNdibOfay1wThZPB9+sbWV oLlY66+3bOlNaATgQ4SqQnOp39ifmVcCvh78ittWw6m4A/rREXwVXpOloaxHkGnELdCq QlHbT2f4d5mgfKyPWLdkgP5Xt8JOb90WakFCLRdzJS+lK8x4I5sSCnQgjNdskH4DWFQD qlb4GCbuFwfecDnDbaTEI9zw4V8NiGT3vcs1cSQgdaXqUAIQ9WeRfU3eVLFha1uQgrVu 61NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CbhggdNC; 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 y24si20600852oih.24.2020.01.22.01.36.28; Wed, 22 Jan 2020 01:36:40 -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=CbhggdNC; 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 S1729785AbgAVJfZ (ORCPT + 99 others); Wed, 22 Jan 2020 04:35:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:50330 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731217AbgAVJfU (ORCPT ); Wed, 22 Jan 2020 04:35:20 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 B10D924680; Wed, 22 Jan 2020 09:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579685719; bh=SrODrwLjsbBCvo1hth7eSOv3o1qQTnBUiccMhKqJXW0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CbhggdNCUUhbbDLSysTb0IKeua/iA2bBNUIwm0RVdERUVoBFFSP59aHxxAN24qf6K SBY0zBUVFcpY9efwsKSgfkv9GqjegT58XT1WY69pz18fJ2GPo2/lnP/WJQhxsSGQWQ VxtRXc4P8iWrq8o8phOBUSiDqIHkEkaG4IQ7rrws= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+f584efa0ac7213c226b7@syzkaller.appspotmail.com, Jan Kara , Barret Rhoden , Theodore Tso , Ben Hutchings Subject: [PATCH 4.9 17/97] ext4: fix use-after-free race with debug_want_extra_isize Date: Wed, 22 Jan 2020 10:28:21 +0100 Message-Id: <20200122092758.736614924@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200122092755.678349497@linuxfoundation.org> References: <20200122092755.678349497@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Barret Rhoden commit 7bc04c5c2cc467c5b40f2b03ba08da174a0d5fa7 upstream. When remounting with debug_want_extra_isize, we were not performing the same checks that we do during a normal mount. That allowed us to set a value for s_want_extra_isize that reached outside the s_inode_size. Fixes: e2b911c53584 ("ext4: clean up feature test macros with predicate functions") Reported-by: syzbot+f584efa0ac7213c226b7@syzkaller.appspotmail.com Reviewed-by: Jan Kara Signed-off-by: Barret Rhoden Signed-off-by: Theodore Ts'o [bwh: Backported to 4.9: The debug_want_extra_isize mount option is not supported] Signed-off-by: Ben Hutchings Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 56 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 23 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3342,6 +3342,36 @@ int ext4_calculate_overhead(struct super return 0; } +static void ext4_clamp_want_extra_isize(struct super_block *sb) +{ + struct ext4_sb_info *sbi = EXT4_SB(sb); + struct ext4_super_block *es = sbi->s_es; + + /* determine the minimum size of new large inodes, if present */ + if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { + sbi->s_want_extra_isize = sizeof(struct ext4_inode) - + EXT4_GOOD_OLD_INODE_SIZE; + if (ext4_has_feature_extra_isize(sb)) { + if (sbi->s_want_extra_isize < + le16_to_cpu(es->s_want_extra_isize)) + sbi->s_want_extra_isize = + le16_to_cpu(es->s_want_extra_isize); + if (sbi->s_want_extra_isize < + le16_to_cpu(es->s_min_extra_isize)) + sbi->s_want_extra_isize = + le16_to_cpu(es->s_min_extra_isize); + } + } + /* Check if enough inode space is available */ + if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize > + sbi->s_inode_size) { + sbi->s_want_extra_isize = sizeof(struct ext4_inode) - + EXT4_GOOD_OLD_INODE_SIZE; + ext4_msg(sb, KERN_INFO, + "required extra inode space not available"); + } +} + static void ext4_set_resv_clusters(struct super_block *sb) { ext4_fsblk_t resv_clusters; @@ -4156,29 +4186,7 @@ no_journal: if (ext4_setup_super(sb, es, sb->s_flags & MS_RDONLY)) sb->s_flags |= MS_RDONLY; - /* determine the minimum size of new large inodes, if present */ - if (sbi->s_inode_size > EXT4_GOOD_OLD_INODE_SIZE) { - sbi->s_want_extra_isize = sizeof(struct ext4_inode) - - EXT4_GOOD_OLD_INODE_SIZE; - if (ext4_has_feature_extra_isize(sb)) { - if (sbi->s_want_extra_isize < - le16_to_cpu(es->s_want_extra_isize)) - sbi->s_want_extra_isize = - le16_to_cpu(es->s_want_extra_isize); - if (sbi->s_want_extra_isize < - le16_to_cpu(es->s_min_extra_isize)) - sbi->s_want_extra_isize = - le16_to_cpu(es->s_min_extra_isize); - } - } - /* Check if enough inode space is available */ - if (EXT4_GOOD_OLD_INODE_SIZE + sbi->s_want_extra_isize > - sbi->s_inode_size) { - sbi->s_want_extra_isize = sizeof(struct ext4_inode) - - EXT4_GOOD_OLD_INODE_SIZE; - ext4_msg(sb, KERN_INFO, "required extra inode space not" - "available"); - } + ext4_clamp_want_extra_isize(sb); ext4_set_resv_clusters(sb); @@ -4959,6 +4967,8 @@ static int ext4_remount(struct super_blo goto restore_opts; } + ext4_clamp_want_extra_isize(sb); + if ((old_opts.s_mount_opt & EXT4_MOUNT_JOURNAL_CHECKSUM) ^ test_opt(sb, JOURNAL_CHECKSUM)) { ext4_msg(sb, KERN_ERR, "changing journal_checksum "