From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pavel Emelyanov Subject: Re: [PATCH] Make access to task's nsproxy liter Date: Fri, 10 Aug 2007 19:09:32 +0400 Message-ID: <46BC7FAC.2080208@openvz.org> References: <46BAE3A3.7030608@openvz.org> <20070810134003.GA22368@sergelap.austin.ibm.com> <20070810140545.GA74@tv-sign.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20070810140545.GA74-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org Errors-To: containers-bounces-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org To: Oleg Nesterov Cc: Linux Kernel Mailing List , "Eric W. Biederman" , Linux Containers , "Paul E. McKenney" List-Id: containers.vger.kernel.org Oleg Nesterov wrote: > On 08/10, Serge E. Hallyn wrote: >> Quoting Pavel Emelyanov (xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org): >>> +/* >>> + * the namespaces access rules are: >>> + * >>> + * 1. only current task is allowed to change tsk->nsproxy pointer or >>> + * any pointer on the nsproxy itself >>> + * >>> + * 2. when accessing (i.e. reading) current task's namespaces - no >>> + * precautions should be taken - just dereference the pointers >>> + * >>> + * 3. the access to other task namespaces is performed like this >>> + * rcu_read_lock(); >>> + * nsproxy = task_nsproxy(tsk); >>> + * if (nsproxy != NULL) { >>> + * / * >>> + * * work with the namespaces here >>> + * * e.g. get the reference on one of them >>> + * * / >>> + * } / * >>> + * * NULL task_nsproxy() means that this task is >>> + * * almost dead (zombie) >>> + * * / >>> + * rcu_read_unlock(); >> And lastly, I guess that the caller to switch_task_namespaces() has >> to ensure that new_nsproxy either (1) is the init namespace, (2) is a >> brand-new namespace to which noone else has a reference, or (3) the >> caller has to hold a reference to the new_nsproxy across the call to >> switch_task_namespaces(). >> >> As it happens the current calls fit (1) or (2). Again if we happen to >> jump into the game of switching a task into another task's nsproxy, >> we'll need to be mindful of (3) so that new_nsproxy can't be tossed into >> the bin between >> >> if (new) >> get_nsproxy(new); > > 4) Unless tsk == current, get_task_namespaces(tsk) and get_nsproxy(tsk) > are racy even if done under rcu_read_lock(). Yup :) It is already written in comment that only the current is allowed to change its nsproxy. I.e. when switch_task_nsproxy() is called for tsk other than current it's a BUG > Oleg. > > - > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in > the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > Please read the FAQ at http://www.tux.org/lkml/ >