Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754928AbZC3AJX (ORCPT ); Sun, 29 Mar 2009 20:09:23 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754089AbZC3AJJ (ORCPT ); Sun, 29 Mar 2009 20:09:09 -0400 Received: from mx2.redhat.com ([66.187.237.31]:46714 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753951AbZC3AJI (ORCPT ); Sun, 29 Mar 2009 20:09:08 -0400 Date: Mon, 30 Mar 2009 02:03:38 +0200 From: Oleg Nesterov To: Al Viro 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 Subject: Re: Q: check_unsafe_exec() races (Was: [PATCH 2/4] fix setuid sometimes doesn't) Message-ID: <20090330000338.GB32199@redhat.com> 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> <20090329222022.GJ28946@ZenIV.linux.org.uk> <20090329235639.GA32199@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090329235639.GA32199@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1381 Lines: 38 On 03/30, Oleg Nesterov wrote: > > On 03/29, Al Viro wrote: > > > > 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. > > Yes, this is what I meant, copy_fs() needs this lock too, > > > FWIW, I'm not at all sure that we want atomic_t for refcount in that > > case... > > I think you are right, because exit_fs() should take fs->lock as well. > > But, again. What whould we do when check_unsafe_exec() takes fs->lock > and sees that this ->fs is already marked? Ah, I am stupid. There is no another process if this flag is set. Oleg. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/