From patchwork Sun Jun 5 10:37:35 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Al Viro X-Patchwork-Id: 98758 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9397FB6F7F for ; Sun, 5 Jun 2011 20:37:46 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755912Ab1FEKhk (ORCPT ); Sun, 5 Jun 2011 06:37:40 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:39045 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755604Ab1FEKhj (ORCPT ); Sun, 5 Jun 2011 06:37:39 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.76 #1 (Red Hat Linux)) id 1QTAi8-0003fg-07; Sun, 05 Jun 2011 10:37:36 +0000 Date: Sun, 5 Jun 2011 11:37:35 +0100 From: Al Viro To: netdev@vger.kernel.org Cc: "Eric W. Biederman" , linux-fsdevel@vger.kernel.org, Linus Torvalds Subject: [PATCH] get_net_ns_by_fd() oopses if proc_ns_fget() returns an error Message-ID: <20110605103735.GB11521@ZenIV.linux.org.uk> References: <20110604222531.GA11521@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20110604222531.GA11521@ZenIV.linux.org.uk> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org BTW, looking through the code related to struct net lifetime rules has caught something else: struct net *get_net_ns_by_fd(int fd) { ... file = proc_ns_fget(fd); if (!file) goto out; ei = PROC_I(file->f_dentry->d_inode); while in proc_ns_fget() we have two return ERR_PTR(...) and not a single path that would return NULL. The other caller of proc_ns_fget() treats ERR_PTR() correctly... Signed-off-by: Al Viro --- [I don't know which tree should that go through; I'm throwing that into vfs-2.6 #for-linus, but if networking folks prefer that to go through their tree...] -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 6c6b86d..e41e511 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -310,19 +310,17 @@ struct net *get_net_ns_by_fd(int fd) struct file *file; struct net *net; - net = ERR_PTR(-EINVAL); file = proc_ns_fget(fd); - if (!file) - goto out; + if (IS_ERR(file)) + return ERR_CAST(file); ei = PROC_I(file->f_dentry->d_inode); - if (ei->ns_ops != &netns_operations) - goto out; + if (ei->ns_ops == &netns_operations) + net = get_net(ei->ns); + else + net = ERR_PTR(-EINVAL); - net = get_net(ei->ns); -out: - if (file) - fput(file); + fput(file); return net; }