From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753239AbbHMQco (ORCPT ); Thu, 13 Aug 2015 12:32:44 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54728 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752122AbbHMQcn (ORCPT ); Thu, 13 Aug 2015 12:32:43 -0400 Date: Thu, 13 Aug 2015 18:30:25 +0200 From: Oleg Nesterov To: "Eric W. Biederman" Cc: "Kirill A. Shutemov" , Andrew Morton , Kees Cook , David Howells , linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , "Kirill A. Shutemov" , Rik van Riel , Vladimir Davydov , Ricky Zhou , Julien Tinnes Subject: Re: [PATCH v2] unshare: Unsharing a thread does not require unsharing a vm Message-ID: <20150813163025.GA24027@redhat.com> References: <87wpx9sjhq.fsf@x220.int.ebiederm.org> <87614tr2jd.fsf@x220.int.ebiederm.org> <20150806130629.GA4728@redhat.com> <20150806134426.GA6843@redhat.com> <871tf9cnbi.fsf_-_@x220.int.ebiederm.org> <87vbclb8op.fsf_-_@x220.int.ebiederm.org> <20150812174847.GA6703@redhat.com> <87wpx046s6.fsf_-_@x220.int.ebiederm.org> <20150813125704.GB13984@redhat.com> <87k2szw51x.fsf@x220.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87k2szw51x.fsf@x220.int.ebiederm.org> 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 On 08/13, Eric W. Biederman wrote: > > Oleg Nesterov writes: > > > On 08/12, Eric W. Biederman wrote: > >> > >> + if (unshare_flags & (CLONE_SIGHAND | CLONE_VM)) { > >> + if (atomic_read(¤t->sighand->count) > 1) > >> + return -EINVAL; > >> + } > > > > I am still not sure we want this... please the the previous email. > > Reading your other email I did not see why you thought this check was > unnecessary. > > > But perhaps I missed something. > > In short: > clone(VM) --> mm_users > 1 && sighand_struct->count == 1 > followed by: > unshare(SIGHAND) > the unshare should succeed. > > Meanwhile: > clone(VM|SIGHAND) --> mm_users > 1 && sighand_struct->count > 1 > followed by: > unshare(SIGHAND) > the unshare should fail. Yes, yes, yes. But once again, I meant we can remove this sighand->count check if unshare(SIGHAND) checks current_is_single_threaded(). That is why I suggested to do if (unshare_flags & CLONE_SIGHAND) unshare_flags |= CLONE_VM; in sys_unshare(), or change check_unshare_flags() to check "unshare_flags & (CLONE_VM | CLONE_SIGHAND)" before current_is_single_threaded(). Damn. And this discussion makes me think that another cleanup makes sense too. Can't we move all these unshare_flags manipulations into check_unshare_flags? So that sys_unshare() will only do err = check_unshare_flags(&unshare_flags); and the reader of this code won't need to read 2 functions to understand whats going on. Oleg.