Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753709AbXFSNwK (ORCPT ); Tue, 19 Jun 2007 09:52:10 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751189AbXFSNv5 (ORCPT ); Tue, 19 Jun 2007 09:51:57 -0400 Received: from mail.screens.ru ([213.234.233.54]:46012 "EHLO mail.screens.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750788AbXFSNv5 (ORCPT ); Tue, 19 Jun 2007 09:51:57 -0400 Date: Tue, 19 Jun 2007 17:51:29 +0400 From: Oleg Nesterov To: Andrew Morton Cc: Herbert Poetzl , pbadari@us.ibm.com, clg@fr.ibm.com, containers@lists.osdl.org, ebiederm@xmission.com, serue@us.ibm.com, linux-kernel@vger.kernel.org Subject: [PATCH] create_new_namespaces: fix improper return of NULL Message-ID: <20070619135129.GA27343@tv-sign.ru> References: <200705090245.l492jZwD008756@shell0.pdx.osdl.net> <20070616191742.GA13434@MAIL.13thfloor.at> <20070617143830.GA379@tv-sign.ru> <20070617163004.GA553@tv-sign.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20070617163004.GA553@tv-sign.ru> User-Agent: Mutt/1.5.11 Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1900 Lines: 61 Untested. dup_mnt_ns() and clone_uts_ns() return NULL on failure. This is wrong, create_new_namespaces() uses ERR_PTR() to catch an error. This means that the subsequent create_new_namespaces() will hit BUG_ON() in copy_mnt_ns() or copy_utsname(). Signed-off-by: Oleg Nesterov --- ns/fs/namespace.c~1_NS_NULL 2007-05-21 13:57:56.000000000 +0400 +++ ns/fs/namespace.c 2007-06-19 17:26:35.000000000 +0400 @@ -1457,7 +1457,7 @@ static struct mnt_namespace *dup_mnt_ns( new_ns = kmalloc(sizeof(struct mnt_namespace), GFP_KERNEL); if (!new_ns) - return NULL; + return ERR_PTR(-ENOMEM); atomic_set(&new_ns->count, 1); INIT_LIST_HEAD(&new_ns->list); @@ -1471,7 +1471,7 @@ static struct mnt_namespace *dup_mnt_ns( if (!new_ns->root) { up_write(&namespace_sem); kfree(new_ns); - return NULL; + return ERR_PTR(-ENOMEM); } spin_lock(&vfsmount_lock); list_add_tail(&new_ns->list, &new_ns->root->mnt_list); --- ns/kernel/utsname.c~1_NS_NULL 2007-05-21 13:57:59.000000000 +0400 +++ ns/kernel/utsname.c 2007-06-19 17:35:22.000000000 +0400 @@ -13,6 +13,7 @@ #include #include #include +#include /* * Clone a new ns copying an original utsname, setting refcount to 1 @@ -24,10 +25,11 @@ static struct uts_namespace *clone_uts_n struct uts_namespace *ns; ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL); - if (ns) { - memcpy(&ns->name, &old_ns->name, sizeof(ns->name)); - kref_init(&ns->kref); - } + if (!ns) + return ERR_PTR(-ENOMEM); + + memcpy(&ns->name, &old_ns->name, sizeof(ns->name)); + kref_init(&ns->kref); return ns; } - 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/