From mboxrd@z Thu Jan 1 00:00:00 1970 From: Al Viro Subject: Re: Q: check_unsafe_exec() races (Was: [PATCH 2/4] fix setuid sometimes doesn't) Date: Sun, 29 Mar 2009 23:20:22 +0100 Message-ID: <20090329222022.GJ28946@ZenIV.linux.org.uk> References: <20090329005343.GA12139@redhat.com> <20090329041022.GF28946@ZenIV.linux.org.uk> <20090329045206.GA15519@redhat.com> <20090329055513.GH28946@ZenIV.linux.org.uk> <20090329060118.GI28946@ZenIV.linux.org.uk> <20090329213635.GA21820@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: Hugh Dickins , Linus Torvalds , Andrew Morton , Joe Malicki , Michael Itz , Kenneth Baker , Chris Wright , David Howells , Alexey Dobriyan , Greg Kroah-Hartman , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org To: Oleg Nesterov Return-path: Received: from zeniv.linux.org.uk ([195.92.253.2]:53802 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750799AbZC2WVc (ORCPT ); Sun, 29 Mar 2009 18:21:32 -0400 Content-Disposition: inline In-Reply-To: <20090329213635.GA21820@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Sun, Mar 29, 2009 at 11:36:35PM +0200, Oleg Nesterov wrote: > > ... or just do that to fs_struct. After finding that there's no outside > > users. Commenst? > > This is even worse. Not only we race with our sub-threads, we race > with CLONE_FS processes. > > We can't mark fs_struct after finding that there's no outside users > lockless. Because we can't know whether this is "after" or not, we > can't trust "atomic_read(fs->count) <= n_fs". We can lock fs_struct in question, go through the threads, then mark or bail out. With cloning a reference to fs_struct protected by the same lock. FWIW, I'm not at all sure that we want atomic_t for refcount in that case...