Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2557487ybl; Sat, 24 Aug 2019 20:50:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqyRy+1fjMnfOapWpTYRutW2usk8WbXtoIVDttP4FL2zqhUfkt6C2GEJxw7mvkVX55uAEHzr X-Received: by 2002:a63:c246:: with SMTP id l6mr10744361pgg.210.1566705019983; Sat, 24 Aug 2019 20:50:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566705019; cv=none; d=google.com; s=arc-20160816; b=Jg+3qOnzMoyZv7MUgCWKN7IqR1nVp2ArBkVnpe5kZX6aVcPziBl2irhRVhBg7QXrT+ M5l9SogkcKoMcVacJs9qNJ1799pFqz7+tWPynwkTTNtXA9O1ZTH8cG0VQUzuYORsUUNg vYRo7DcZpF6Z6gIXb6FfIEVW+ckhG6sCzGRo8LOkoKDhim8bkxPkRvV7z6IqxzcfccvE 0LN2amZvNzGKNismFwC1gd5zDkNGUgDOmizrhw/aT6FTlN+b4fEsP4mMKbJNlxf2wa+w WMCekJoHqatafVITAfe07qMh27N8ekXCBYbC3T8aSfyZaETNrHKW1eowTdzdUo3N85PX 0HyA== 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=uHb01X+btrRmnQbx0hSvPb1CMu+pdxmAPZST4LFWYuw=; b=P7pccZYQkbKfsrKWjZrzNMUe0e3r/JIkTG1jlqe5e6RKVoCVdrkMQ+HWdOKVUc9gPJ +K8/yC0RDF2f8oG6x9tca+gkIWEuNZ5XwpwhYaG2Usx66J5d9qcX5zPmwI7Jk1rUZMK7 yxAZSImcZCoaORn4g7gdBTRaUavZF8b2w9P25Oc9+2Z3D2mZkW4ZxOnPPpyLr+STlDJD S6Qu4F+S1qYTgM0ajsldfXRiMx9O++sXuykPfFmI1jMNkpfRbGDCAUTgX0F6l4AyT40N +PA+wdHa9R5nyrMKKNu8dUuujHyXQUSv457ytnYcMU8kk18LN6OrJ4ckr8R1Ydud5z0D rBAQ== 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 f17si6276132plj.17.2019.08.24.20.49.37; Sat, 24 Aug 2019 20:50:19 -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 S1728258AbfHYDkT (ORCPT + 99 others); Sat, 24 Aug 2019 23:40:19 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:42626 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728246AbfHYDkT (ORCPT ); Sat, 24 Aug 2019 23:40:19 -0400 Received: from callcc.thunk.org (guestnat-104-133-0-111.corp.google.com [104.133.0.111] (may be forged)) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id x7P3e1Ie031810 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 24 Aug 2019 23:40:02 -0400 Received: by callcc.thunk.org (Postfix, from userid 15806) id 13FD842049E; Sat, 24 Aug 2019 23:40:01 -0400 (EDT) Date: Sat, 24 Aug 2019 23:40:00 -0400 From: "Theodore Y. Ts'o" To: "zhangyi (F)" Cc: linux-ext4@vger.kernel.org, jack@suse.cz, adilger.kernel@dilger.ca Subject: Re: [PATCH v5] ext4: fix potential use after free in system zone via remount with noblock_validity Message-ID: <20190825034000.GE5163@mit.edu> References: <1565869639-105420-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: <1565869639-105420-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 Thu, Aug 15, 2019 at 07:47:19PM +0800, 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) > Reviewed-by: Jan Kara Applied, thanks! I changed the patch summary to: ext4: fix potential use after free after remounting with noblock_validity I also added: Reported-by: syzbot+1e470567330b7ad711d5@syzkaller.appspotmail.com since this had been noted by Syzkaller: https://syzkaller.appspot.com/bug?extid=1e470567330b7ad711d5 Cheers, - Ted