From: Christoph Hellwig Subject: Re: Remount read-only races? Date: Tue, 2 Aug 2011 08:31:21 -0400 Message-ID: <20110802123121.GA27390@infradead.org> References: <20110802120931.GC18545@quack.suse.cz> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Al Viro , mszeredi@suse.cz, linux-fsdevel@vger.kernel.org, Toshiyuki Okajima To: Jan Kara Return-path: Received: from 173-166-109-252-newengland.hfc.comcastbusiness.net ([173.166.109.252]:60437 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754178Ab1HBMb1 (ORCPT ); Tue, 2 Aug 2011 08:31:27 -0400 Content-Disposition: inline In-Reply-To: <20110802120931.GC18545@quack.suse.cz> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Tue, Aug 02, 2011 at 02:09:31PM +0200, Jan Kara wrote: > Hello, > > Toshiyuki reported an ext3 error message which implies that we can have > unlinked but open files on read-only filesystem. Apparently open+unlink > races with remount in some way. Looking at code in do_remount_sb() I don't > see what prevents open("file", O_WRONLY) to happen after the check > fs_may_remount_ro() and before the filesystem is marked as read-only. > So are we expected to prevent these races? If yes, do I just miss something > or the above race is really there? Thanks for reply in advance. remount r/o is completely racy. It only updates the superblock to r/o state once ->remount_fs has returned. So you can easily open new files after the check for r/w files, or in the middle of remount_fs. We have an assert that we had to tone down to an WARN_ON in xfs that can be triggered fairly easily due to this. The fix is to have some sort of transient r/o state before calling into ->remount_fs. I've been thinking about it for a while, and one thing I considered was to freeze the fs when entering do_remount_sb, and then operate on a frozen fs. This sounds easier than it is as all remount_fs instances need to know about it to not deadlock against the frozen fs checks.