Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2556460yba; Mon, 15 Apr 2019 14:21:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqziZ8L4Ofg9bsT9VwPMJNm6aHS4ISvHuQKtB16xfL8PRKbVQYdu7zL+lvT69mVLj3xWVNC7 X-Received: by 2002:a62:6587:: with SMTP id z129mr78686960pfb.88.1555363269917; Mon, 15 Apr 2019 14:21:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555363269; cv=none; d=google.com; s=arc-20160816; b=m6A0boj8bTtsBAd7QNr1sgeoLkCdzlmkh6JgDSvnS459fHocFw04DcYi2cRPD3a49P 9gelnhOt8EJK/XF5cOqMG0HFnrntIVBFkutPa7f1zyBEhBDFgFGrKf64R0DxBXtMjhB4 +dBZuF4yH3R6tfuPXpBw3HKcGJUmO4SWCB2YtIJS05DUF2wQ9lfCRv8a/K6qceXE+I82 POnryZE5GB12E6pSxRK9ioW2kaJXIVQkkP/4FB2bA3AvpPhkCPvlsiYtuvOc/LIZpxpY lUueG9TQI10bQSuUWXm37leQzzn+4KPfuQPntVucp1rKZ9/NnoPjqgNQftdWD//gzabr blUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:mime-version :message-id:date:dkim-signature; bh=NhZ7goTL5H91UJ+3++ZYwoqcRHsg3U/wejpAPhk1iYk=; b=isB6Kaj8hifoQ/+HHe+jhH3QTU5oxg9J/0hphZTp+u9O1mr3/wk4zimyoU+YoVzeZ6 pZZqU23JcaSDL4NcuRzfoK0N6RUaPhqHmm8PbhzAG4HIEu0/zLPY1WQyJV8aCeDCuE7w Bxfv3hbDUxBsXC6hyy6SfLHsoq+2Sc37X1NlOEyac8IFl7itGG/7hGTN7w0FTguQA+yl 1VaiyoX1HTIyOWaeHHV5ymuQO/vAnr72v9gSgGseYxQCxX+Hy1+LAax9YNHCFyJ4fsQj /FeTnQN+aJdV7IiERFvv6cx+VNbUqIGjxr4OVTWV+xs9saRZrnPHDnR1Na5wBNa6lCaf lllg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=CKfmCqhH; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 70si17482021pla.82.2019.04.15.14.20.53; Mon, 15 Apr 2019 14:21:09 -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=@google.com header.s=20161025 header.b=CKfmCqhH; 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=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727836AbfDOVUQ (ORCPT + 99 others); Mon, 15 Apr 2019 17:20:16 -0400 Received: from mail-qk1-f201.google.com ([209.85.222.201]:50383 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726041AbfDOVUQ (ORCPT ); Mon, 15 Apr 2019 17:20:16 -0400 Received: by mail-qk1-f201.google.com with SMTP id d8so15797725qkk.17 for ; Mon, 15 Apr 2019 14:20:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=NhZ7goTL5H91UJ+3++ZYwoqcRHsg3U/wejpAPhk1iYk=; b=CKfmCqhH+W2lhxEZ5cGHcF9qhX+Gw7GILjTEpH7JVI3Apo6hgBwoF6fxUmQYitLmP+ e0HsoSbS5D+CG8Xso7pLNRu9Kay3ZCAmRoaLZ5MvcgR3xO9TbU7JpZIhbKZPJ966DUXK sV4FwmULpVLUUiYpXn83c73QppDN7T7xJGoUOstxk/TTGuY302ad2DcZLQ+Y/1SiNL7P 8z7h7kY9Zj11hWm3JG3uBQRhnrC8nh/UCKO95eJTzIuWgLGE5SqgJgWyxZUfG6rIE2eD udV7hv1QymWzyKvM8QTAAwLbKB3S9IL9JhZF8nKzxMGKAh5rafy09MLfDStrQAbr4yDg BYfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=NhZ7goTL5H91UJ+3++ZYwoqcRHsg3U/wejpAPhk1iYk=; b=YAP3umtLFTMGcy4h1d1CimxqBELyZr/O7m4lLtqZTV2TWwsAY7Qax0Ih+EiwVeq+L3 Dr9HTF8YS85fkW86mCec/ysck3RNDRQnyAVl3RAcW2svKNmi0K0t0XzVwoCrh+SjidJS l2M4gGn70X395LsZKxdMqecR1DfFr4XZd8r+/Mn3e3JGzQjDYrhUJiEAhR110HpIM0uk yJpzQt4rFg+9BFoi5M4+AFEOCe6zewB/DEndjE9DjCiStGGHJrHbqZRMOZ7B73yF35+4 xeQMromC04XmpaCV9mUBG5TSwvXHPTpyH6GuYPBK1VS8tyE65+flecQQxRYbeaz7Cxqu SYzA== X-Gm-Message-State: APjAAAWquRmpMMiJJBqlK90l6/bZBqZbGrz5PpPH4D+041PiJgleFyNp +J5LtlizABV5bQP9BJqzyHXeYeji X-Received: by 2002:a0c:ad17:: with SMTP id u23mr9559639qvc.41.1555363215418; Mon, 15 Apr 2019 14:20:15 -0700 (PDT) Date: Mon, 15 Apr 2019 17:19:45 -0400 Message-Id: <20190415211945.27343-1-brho@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog Subject: [PATCH] ext4: fix use-after-free race with debug_want_extra_isize From: Barret Rhoden To: "Theodore Ts'o" , Andreas Dilger Cc: syzbot+f584efa0ac7213c226b7@syzkaller.appspotmail.com, stable@vger.kernel.org, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Reported-by: syzbot+f584efa0ac7213c226b7@syzkaller.appspotmail.com Signed-off-by: Barret Rhoden Cc: stable@vger.kernel.org --- - In the current code, it looks like someone could mount with want_extra_isize with some value > 0 but less than the minimums in the s_es. If that's a bug, I can submit a follow-on patch. - Similarly, on a failed remount, sbi->s_want_extra_isize is changed to the remounted value. I can fix that too if it's a problem. - Is it OK to remount with a smaller s_want_extra_isize than the previous mount? I thought it was, but figured I'd ask while I'm looking at it. fs/ext4/super.c | 58 +++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 6ed4eb81e674..184944d4d8d1 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3513,6 +3513,37 @@ int ext4_calculate_overhead(struct super_block *sb) 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; @@ -4387,30 +4418,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) } 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); @@ -5194,6 +5202,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) 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 " -- 2.21.0.392.gf8f6787159e-goog