Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp106302yba; Mon, 20 May 2019 05:49:35 -0700 (PDT) X-Google-Smtp-Source: APXvYqwcGB53jWiHrOmGdhBL/HpUwkQI9nhnet7Eq4Lbl4jR4sjdYIIcVewheIQvTjNOw6uK3Mti X-Received: by 2002:a62:2643:: with SMTP id m64mr33228207pfm.46.1558356575189; Mon, 20 May 2019 05:49:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558356575; cv=none; d=google.com; s=arc-20160816; b=bFY3FBfV2aoFLhgQEvFBox5CFXbOZGeiuVBlwI9pDy9ammIHzVbQrU3Py85LtNDfNa 7L4IUL4W9SzIJ3iWCtkrtmJR6dY/bcD4u6tvt9qclvRTNRMxPdPKr1mGDT13v07TIC8U JC4TEx8u/QIrojb8nfm0g7HkQhopLW5UwaZ03EFLOk7RorI6tk42TzbJITu2DK/8p29f 0w+7IagoHQkQN99i2lkQmWMYQl/pbB4g5BDQlzjR37j8UgQ3y5K7yQ56d7zfp4nM5vv1 0+xuVReX9w5fgpe1JTP9apQgonEsNDw2L+QmweXj/P3fMoIDNT4WkdXtXKvD6E3XEe8G alGQ== 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=pi9H4JBtkF08w3SexnvwS+ogg+ZKoiJnuoGOzGVRG88=; b=z2q3xhVBl8Iz7e+DKV4MFgRW9JDN41VZnEulR97QPJy/DM/htLq/Pf1iDz2FqcI8t7 vx+gI/KCBYm+Tv4ZccFuWa6ZnyvrvlB6OzcpxJzdbfKM4WjkkyCd1xIvPtpJbPI9Q2mb NpMr7JQ6M+qpJluRmOXpSfcnOdOMclkH7ojIQQqtvuZ72efQEGoznHkH52V33auovUET cR4aw5C0pGitfIwHtz14QAtrNTc9OqzjHlH8HwWniHvP1EpMh3m6HxmO0XHy5tbkUSyN 3IppCrGbNoqnYKBjA8JKaoUBkhnPDGdE2c8JRsHYF280OIel9eJ5DtthpFdEHd3MMnSX O5fw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="d1JZS/QV"; 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 q17si16680817pll.285.2019.05.20.05.49.20; Mon, 20 May 2019 05:49:35 -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; dkim=pass header.i=@kernel.org header.s=default header.b="d1JZS/QV"; 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 S2389891AbfETMrp (ORCPT + 99 others); Mon, 20 May 2019 08:47:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:38500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388637AbfETMXu (ORCPT ); Mon, 20 May 2019 08:23:50 -0400 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 62095216FD; Mon, 20 May 2019 12:23:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558355029; bh=1JwKsE2PPxh7DmKGmEaNZC+p3l/r7snwtIEcRD+3ubM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d1JZS/QV1S0Z7BW+6qbAH37b1L1UjmN+PFgEDljLCrXlYrktMMi8h1DJJ4e3UTYCF fYKOAhggFmjhE3FKSZeOi5WSQXTLjrsJrpPEOuGjhMtMRFaNBsKSPJqozyZzOoODPG PtVqx6oPzXoaNFU9eOBl+XIs10l4RlMoZXq9X6Fc= 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 Subject: [PATCH 4.19 070/105] ext4: fix use-after-free race with debug_want_extra_isize Date: Mon, 20 May 2019 14:14:16 +0200 Message-Id: <20190520115252.018980500@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190520115247.060821231@linuxfoundation.org> References: <20190520115247.060821231@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 Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 58 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 24 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3514,6 +3514,37 @@ 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 == 0) { + 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; @@ -4388,30 +4419,7 @@ no_journal: } else if (ret) goto failed_mount4a; - /* 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 == 0) { - 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); @@ -5197,6 +5205,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 "