Return-Path: Received: from www262.sakura.ne.jp ([202.181.97.72]:46435 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750834AbbLIMGG (ORCPT ); Wed, 9 Dec 2015 07:06:06 -0500 Subject: Re: [PATCH v4] fs: clear file privilege bits when mmap writing To: Kees Cook , Andrew Morton References: <20151208232818.GA29887@www.outflux.net> Cc: Jan Kara , yalin wang , Willy Tarreau , "Eric W. Biederman" , "Kirill A. Shutemov" , Oleg Nesterov , Rik van Riel , Chen Gang , Davidlohr Bueso , Andrea Arcangeli , Alexander Viro , linux-fsdevel@vger.kernel.org From: Tetsuo Handa Message-ID: <566818E5.7010308@I-love.SAKURA.ne.jp> Date: Wed, 9 Dec 2015 21:04:53 +0900 MIME-Version: 1.0 In-Reply-To: <20151208232818.GA29887@www.outflux.net> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On 2015/12/09 8:28, Kees Cook wrote: > Changing the bits requires holding inode->i_mutex, so it cannot be done > during the page fault (due to mmap_sem being held during the fault). We > could do this during vm_mmap_pgoff, but that would need coverage in > mprotect as well, but to check for MAP_SHARED, we'd need to hold mmap_sem > again. > > Instead, detect the need to clear the bits during the page fault, and > actually remove the bits during final fput. Since the file was open for > writing, it wouldn't have been possible to execute it yet. Did you check that inode->i_mutex is held when final fput() is called? Did you check a case where the file is copied between mmap() and final fput() (i.e. open() for write, mmap() for write, sleep forever waiting for the file owner to copy the content and attributes of the modified file)?