Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp668969ybl; Wed, 14 Aug 2019 04:15:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOyU1ZRD2ceQbz1nQZWo6S96A+CQesZrgkiopZHDQ8sxA6qWY0lio7YklaAvpzQrrp8Tuw X-Received: by 2002:a17:90a:17e2:: with SMTP id q89mr851557pja.8.1565781313410; Wed, 14 Aug 2019 04:15:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565781313; cv=none; d=google.com; s=arc-20160816; b=HQqU8Zk4hpiJQxfH0ILyZLavBqaSyMGTgMXbjYU8mu/G59JLVTWnT7ykGbj/Cz8pBq Uzte7deB6+o4P0zRBL7+prtUwBLJEzXGtPTSzXTEW/E7hQyc3XJeiIUu2V2HUShsJ2f5 js7Hc/GWrUUhWrJ5SDygCJmk3Ocuy8vwpRCZYEyPvvPgchdNmfT6oN0bgabnsX8WPHj+ +KPGpD+8Fcj9J5f7+ce8TLVwWmloRO28qmBojmBl77Qd0re+qMr+sIMZaGVJStsjrmCG yzKeO5hkISJAILREUeew4Xxn/S6iy4Sv7nHKPeBlZ4+M6z9T7v5Gy9OfZbjsNRqoBtQl XOIQ== 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; bh=4RVC3k7KaEPY0/qZDN2soMRRNry8MqHjGhZk0B45l7A=; b=RBghNb84scXbdmJdKX8y5iGWg1ZTnXNzsNCHeVd8RcU3e7oaJV/WaWpg8MYl2H+Qcg mZMCdmDm1oV+X25DttU58QJDdI5bYYANGmRjLhV1Sm6H0DAK+K6nFP4wyC73Uey/8fUg 9FZ/yK7QqwoX4QmgMRkjY/fS7mUJknvEeC+EQLGHsxJK7MqPtUh5fbH6vE1UjENrCBjp opHAKhyisQ30H52TnbpkH1yuOr94vGChtu7JvL7YrvsptaYMkYEUAs0jvG+oOlzhlgHB j5eCgfBfCUgWFE/eLcEE0itQOArDFiqDSQbC8uO3MBNsvZLHv2yKQNv+AHnvSLTiYTXB 0PGQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 t63si65966293pfb.5.2019.08.14.04.14.45; Wed, 14 Aug 2019 04:15:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726951AbfHNLOL (ORCPT + 99 others); Wed, 14 Aug 2019 07:14:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:35574 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726265AbfHNLOL (ORCPT ); Wed, 14 Aug 2019 07:14:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id F260DACEC; Wed, 14 Aug 2019 11:14:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id ED2691E4200; Wed, 14 Aug 2019 13:14:08 +0200 (CEST) Date: Wed, 14 Aug 2019 13:14:08 +0200 From: Jan Kara To: "zhangyi (F)" Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, jack@suse.cz, adilger.kernel@dilger.ca Subject: Re: [PATCH v3] ext4: fix potential use after free in system zone via remount with noblock_validity Message-ID: <20190814111408.GC26273@quack2.suse.cz> References: <1565701547-146508-1-git-send-email-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1565701547-146508-1-git-send-email-yi.zhang@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue 13-08-19 21:05:47, zhangyi (F) wrote: > Remount process will release system zone which was allocated before if > "noblock_validity" is specified. If we mount an ext4 file system to two > mountpoints with default mount options, and then remount one of them > with "noblock_validity", it may trigger a use after free problem when > someone accessing the other one. > > # mount /dev/sda foo > # mount /dev/sda bar > > User access mountpoint "foo" | Remount mountpoint "bar" > | > ext4_map_blocks() | ext4_remount() > check_block_validity() | ext4_setup_system_zone() > ext4_data_block_valid() | ext4_release_system_zone() > | free system_blks rb nodes > access system_blks rb nodes | > trigger use after free | > > This problem can also be reproduced by one mountpint, At the same time, > add_system_zone() can get called during remount as well so there can be > racing ext4_data_block_valid() reading the rbtree at the same time. > > This patch add RCU to protect system zone from releasing or building > when doing a remount which inverse current "noblock_validity" mount > option. It assign the rbtree after the whole tree was complete and > do actual freeing after rcu grace period, avoid any intermediate state. > > Signed-off-by: zhangyi (F) > --- > Changes since v2: > - Remove seqlock, and assign the whole rbtree when finished assembling. > - Fix the sparse warning. Thanks for the patch! It looks great to me. Just one nit below and with that applied feel free to add: Reviewed-by: Jan Kara > int ext4_setup_system_zone(struct super_block *sb) ... > /* Called when the filesystem is unmounted */ > void ext4_release_system_zone(struct super_block *sb) Can you perhaps add a comment before ext4_setup_system_zone() and ext4_release_system_zone() explaining that these two functions are called under sb->s_umount semaphore protection which also serializes updates of sb->system_blks pointer? Thanks! Honza -- Jan Kara SUSE Labs, CR