From patchwork Thu May 14 17:34:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 6408781 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id F18E7C0433 for ; Thu, 14 May 2015 17:39:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1901D2027D for ; Thu, 14 May 2015 17:39:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0704D20452 for ; Thu, 14 May 2015 17:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933996AbbENRjH (ORCPT ); Thu, 14 May 2015 13:39:07 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:33404 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933105AbbENRjA (ORCPT ); Thu, 14 May 2015 13:39:00 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1Ysx63-0002kC-DT; Thu, 14 May 2015 11:38:59 -0600 Received: from 67-3-205-90.omah.qwest.net ([67.3.205.90] helo=x220.int.ebiederm.org.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.82) (envelope-from ) id 1Ysx62-0000h8-6m; Thu, 14 May 2015 11:38:59 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linux Containers Cc: , Linux API , "Serge E. Hallyn" , Andy Lutomirski , Richard Weinberger , Kenton Varda , Michael Kerrisk-manpages , =?utf-8?Q?St=C3=A9phane?= Graber , Eric Windisch , Greg Kroah-Hartman , Tejun Heo References: <87pp63jcca.fsf@x220.int.ebiederm.org> Date: Thu, 14 May 2015 12:34:10 -0500 In-Reply-To: <87pp63jcca.fsf@x220.int.ebiederm.org> (Eric W. Biederman's message of "Thu, 14 May 2015 12:30:45 -0500") Message-ID: <87r3qjhxm5.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-XM-AID: U2FsdGVkX19IEF76w2wABsRkkfN2uYUYQ88jjthIFT0= X-SA-Exim-Connect-IP: 67.3.205.90 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-DCC: XMission; sa06 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ***;Linux Containers X-Spam-Relay-Country: X-Spam-Timing: total 351 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 3.4 (1.0%), b_tie_ro: 2.6 (0.7%), parse: 0.81 (0.2%), extract_message_metadata: 12 (3.4%), get_uri_detail_list: 2.1 (0.6%), tests_pri_-1000: 6 (1.6%), tests_pri_-950: 1.24 (0.4%), tests_pri_-900: 1.10 (0.3%), tests_pri_-400: 26 (7.4%), check_bayes: 25 (7.0%), b_tokenize: 9 (2.6%), b_tok_get_all: 8 (2.2%), b_comp_prob: 2.1 (0.6%), b_tok_touch_all: 3.5 (1.0%), b_finish: 0.70 (0.2%), tests_pri_0: 292 (83.1%), tests_pri_500: 6 (1.8%), rewrite_mail: 0.00 (0.0%) Subject: [CFT][PATCH 06/10] proc: Allow creating permanently empty directories. X-SA-Exim-Version: 4.2.1 (built Wed, 24 Sep 2014 11:00:52 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a new function proc_mk_empty_dir that when used to creates a directory that can not be added to. Update the code to use make_empty_dir_inode when reporting a permanently empty directory to the vfs. Update the code to not allow adding to permanently empty directories. Update /proc/openprom and /proc/fs/nfsd to be permanently empty directories. Cc: stable@vger.kernel.org Signed-off-by: "Eric W. Biederman" --- fs/proc/generic.c | 23 +++++++++++++++++++++++ fs/proc/inode.c | 3 +++ fs/proc/internal.h | 1 + fs/proc/root.c | 4 ++-- 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/fs/proc/generic.c b/fs/proc/generic.c index df6327a2b865..e235c1544b22 100644 --- a/fs/proc/generic.c +++ b/fs/proc/generic.c @@ -373,6 +373,10 @@ static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, WARN(1, "create '/proc/%s' by hand\n", qstr.name); return NULL; } + if (S_ISDIR((*parent)->mode) && ((*parent)->proc_fops == NULL)) { + WARN(1, "attempt to add to permanently empty directory"); + return NULL; + } ent = kzalloc(sizeof(struct proc_dir_entry) + qstr.len + 1, GFP_KERNEL); if (!ent) @@ -455,6 +459,25 @@ struct proc_dir_entry *proc_mkdir(const char *name, } EXPORT_SYMBOL(proc_mkdir); +struct proc_dir_entry *proc_mk_empty_dir(const char *name) +{ + umode_t mode = S_IFDIR | S_IRUGO | S_IXUGO; + struct proc_dir_entry *ent, *parent = NULL; + + ent = __proc_create(&parent, name, mode, 2); + if (ent) { + ent->data = NULL; + ent->proc_fops = NULL; + ent->proc_iops = NULL; + if (proc_register(parent, ent) < 0) { + kfree(ent); + parent->nlink--; + ent = NULL; + } + } + return ent; +} + struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, struct proc_dir_entry *parent, const struct file_operations *proc_fops, diff --git a/fs/proc/inode.c b/fs/proc/inode.c index 8272aaba1bb0..b957ec618bda 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c @@ -445,6 +445,9 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de) inode->i_fop = &proc_reg_file_ops; } else { inode->i_fop = de->proc_fops; + if (S_ISDIR(inode->i_mode) && + (de->proc_fops == NULL)) + make_empty_dir_inode(inode); } } } else diff --git a/fs/proc/internal.h b/fs/proc/internal.h index c835b94c0cd3..6bc2e7a12912 100644 --- a/fs/proc/internal.h +++ b/fs/proc/internal.h @@ -190,6 +190,7 @@ static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde) return pde; } extern void pde_put(struct proc_dir_entry *); +struct proc_dir_entry *proc_mk_empty_dir(const char *name); /* * inode.c diff --git a/fs/proc/root.c b/fs/proc/root.c index 64e1ab64bde6..b031fc3991c3 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -179,10 +179,10 @@ void __init proc_root_init(void) #endif proc_mkdir("fs", NULL); proc_mkdir("driver", NULL); - proc_mkdir("fs/nfsd", NULL); /* somewhere for the nfsd filesystem to be mounted */ + proc_mk_empty_dir("fs/nfsd"); /* somewhere for the nfsd filesystem to be mounted */ #if defined(CONFIG_SUN_OPENPROMFS) || defined(CONFIG_SUN_OPENPROMFS_MODULE) /* just give it a mountpoint */ - proc_mkdir("openprom", NULL); + proc_mk_empty_dir("openprom"); #endif proc_tty_init(); proc_mkdir("bus", NULL);