Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763589AbYCGMac (ORCPT ); Fri, 7 Mar 2008 07:30:32 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1757063AbYCGMaU (ORCPT ); Fri, 7 Mar 2008 07:30:20 -0500 Received: from sacred.ru ([62.205.161.221]:46289 "EHLO sacred.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754445AbYCGMaS (ORCPT ); Fri, 7 Mar 2008 07:30:18 -0500 Message-ID: <47D12EF8.8010801@openvz.org> Date: Fri, 07 Mar 2008 15:03:04 +0300 From: Pavel Emelyanov User-Agent: Thunderbird 2.0.0.12 (X11/20080213) MIME-Version: 1.0 To: Stephen Smalley CC: Andrew Morton , David Miller , Linux Kernel Mailing List , Linux Netdev List , "Eric W. Biederman" , "Paul E. McKenney" , James Morris , Eric Paris Subject: Re: [PATCH] Make /proc/net a symlink on /proc/self/net (v2) References: <47CFB6CA.8090001@openvz.org> <1204821325.1397.298.camel@moss-spartans.epoch.ncsc.mil> <47D01F98.5010609@openvz.org> <1204832619.1397.354.camel@moss-spartans.epoch.ncsc.mil> In-Reply-To: <1204832619.1397.354.camel@moss-spartans.epoch.ncsc.mil> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH authentication, not delayed by milter-greylist-3.0 (sacred.ru [62.205.161.221]); Fri, 07 Mar 2008 15:03:03 +0300 (MSK) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3096 Lines: 88 [snip] >>> Does this break SELinux labeling of /proc/net inodes and thus its access >>> controls on them? >> It should not, since the proc_dir_etries are still organized in >> a required hierarchy. > > Unfortunately, it does break selinux labeling of /proc/net inodes. > Easily seen by running ls -ZR /proc/net before and after the patch is > applied and comparing the results. > > Also, as a separate issue, a "find /proc/self/net ..." will show that > the hard link count is wrong for it. Oops... I've checked this thing explicitly before sending, but it looks like I used too old find version. I.e. 4.1.20 worked OK, but 4.2.23 reported the nlink discrepancy. Anyway, this is fixed now (see below). I override the getattr method for /proc/net directory and update one from the net->proc_net entry, which is calculated correctly. > Currently the inodes get labeled by selinux_proc_get_sid() by walking up > the proc_dir_entry tree to generate a name and prefix matching that name > in policy. Before the patch, we'd get names like "//net/tcp", i.e. > relative to the root of proc (the extra leading slash is due to the > earlier proc net rewrite which also broke selinux until we adjusted it > to ignore it). After the patch, we just get "//tcp", which is ambiguous > since we would also get that for a /proc/tcp inode if one existed. OK, got it. Is it good if we used to get the //net/tcp, but will /net/tcp (without the double slash)? The patch below does exactly this. It initializes the name for the net->proc_net entry and makes its parent be proc_root. Can you Ack this patch, so that I can merge it with the original one and re-post the combined v3? > Not trying to obstruct your proc net improvements, but just want to make > sure that selinux doesn't get broken in the process. diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c index 18d413c..4caa5f7 100644 --- a/fs/proc/proc_net.c +++ b/fs/proc/proc_net.c @@ -96,8 +96,27 @@ static struct dentry *proc_tgid_net_lookup(struct inode *dir, return de; } +static int proc_tgid_net_getattr(struct vfsmount *mnt, struct dentry *dentry, + struct kstat *stat) +{ + struct inode *inode = dentry->d_inode; + struct net *net; + + net = get_proc_task_net(inode); + + generic_fillattr(inode, stat); + + if (net != NULL) { + stat->nlink = net->proc_net->nlink; + put_net(net); + } + + return 0; +} + const struct inode_operations proc_net_inode_operations = { .lookup = proc_tgid_net_lookup, + .getattr = proc_tgid_net_getattr, }; static int proc_tgid_net_readdir(struct file *filp, void *dirent, @@ -162,6 +181,10 @@ static __net_init int proc_net_ns_init(struct net *net) goto out; netd->data = net; + netd->nlink = 2; + netd->name = "net"; + netd->namelen = 3; + netd->parent = &proc_root; err = -EEXIST; net_statd = proc_net_mkdir(net, "stat", netd); -- 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/