From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Paris Subject: Re: [PATCH V2 1/6] namespaces: assign each namespace instance a serial number Date: Sat, 10 May 2014 11:01:59 -0400 Message-ID: <1399734119.3558.16.camel@localhost> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: 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: Richard Guy Briggs Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org, linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-audit-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org, ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org, sgrubb-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org List-Id: linux-audit@redhat.com On Fri, 2014-05-09 at 20:27 -0400, Richard Guy Briggs wrote: > Generate and assign a serial number per namespace instance since boot. > > Use a serial number per namespace (unique across one boot of one kernel) > instead of the inode number (which is claimed to have had the right to change > reserved and is not necessarily unique if there is more than one proc fs) to > uniquely identify it per kernel boot. > > Signed-off-by: Richard Guy Briggs > --- > +/** > + * ns_serial - compute a serial number for the namespace > + * > + * Compute a serial number for the namespace to uniquely identify it in > + * audit records. > + */ > +unsigned long long ns_serial(void) > +{ > + static DEFINE_SPINLOCK(serial_lock); > + static unsigned long long serial = 4; /* reserved for IPC, UTS, user, PID */ > + unsigned long flags; > + > + spin_lock_irqsave(&serial_lock, flags); > + ++serial; > + spin_unlock_irqrestore(&serial_lock, flags); > + BUG_ON(!serial); > + > + return serial; > +} > + > static inline struct nsproxy *create_nsproxy(void) > { > struct nsproxy *nsproxy; atomic64_t instead of doing it yourself? and why _irqsave() ? Can we seriously create new namespaces in irq context? If you use the atomic though, you don't have to worry about it...