From patchwork Tue Apr 25 12:23:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Djalal Harouni X-Patchwork-Id: 9698055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD39F6020A for ; Tue, 25 Apr 2017 12:24:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B86442857D for ; Tue, 25 Apr 2017 12:24:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ABF40285E9; Tue, 25 Apr 2017 12:24:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E466D2857D for ; Tue, 25 Apr 2017 12:24:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947490AbdDYMYs (ORCPT ); Tue, 25 Apr 2017 08:24:48 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34068 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1946589AbdDYMYZ (ORCPT ); Tue, 25 Apr 2017 08:24:25 -0400 Received: by mail-wm0-f66.google.com with SMTP id z129so24575364wmb.1; Tue, 25 Apr 2017 05:24:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=k7w+Wa2jJXCSpdG2oAlNxRmKw7GwuMdwijugCArwVT0=; b=JXVNjwV0LIwxCHx7uiVfvsK5wOmUxO8onknaBPb9LdSASHbVJARvMNGKc04mrL3NBb zR8o3LfjJhzST5MQTCnh6PIUapyhg/zYymNsvw8RNuH1g1RFxcDBduVsTNpH3c5hZIo3 aaCXqEEIsYbMrlfpjs0HU6PmEa38KJ1FGDNp7pituJvCL1rsiU4NErOJ5lTsPnUYcyS0 dl0HrKD+MHXLvnxbnhFJNikvysD2HLt787H7rvw2HsuqYARyGzSYbvx4D9PUBi820sC8 3/xbkxqmMrrva2/1pli5WHYWX+AcdOd5Yf6xX25Eyl6D+S/AWo1GaxnA/rX5elIgQUyh kVRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=k7w+Wa2jJXCSpdG2oAlNxRmKw7GwuMdwijugCArwVT0=; b=Ga8kNYjeO6F6FpwFS6oOWijbwNA64kUIyIwic+IUaVpkie6W/elNDfO68pDkLEgbqk 24HNBilsHC8+OagRrJwJw+SDnUK33TEsY2lygKzFIr7idElAz9QAlaI/1PLAS9tyzPly uJ4QjSfPUdP8jaCRLfwbq01CwoCjNSKHF9l6gu6VF6x3vF2axEnXUP3m1V4Z9RtzE3jB k+XRuX6zeVzPYt85ZvtCABnfopRiVh/M2SZnvoPDGMDFbE2zpX/GGKpJ5/AjHLpcb4Li eZyJvmg5HM2e7LMFqSv4uAe8JbnObQeoO+M981j8mbQSQ/qV80Jca6W9039Qou46RU2t WAzg== X-Gm-Message-State: AN3rC/4rlwPui/0jrs273W72OUlAU6puTtquRcnr5CFoppGQovomuS1D bkRARqj0q0qBWg== X-Received: by 10.80.181.161 with SMTP id a30mr4925504ede.85.1493123063656; Tue, 25 Apr 2017 05:24:23 -0700 (PDT) Received: from dztty2.localdomain ([2a02:8109:a4bf:e114:7e7a:91ff:fe9c:44e2]) by smtp.gmail.com with ESMTPSA id g12sm5037865eda.37.2017.04.25.05.24.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Apr 2017 05:24:23 -0700 (PDT) From: Djalal Harouni To: Linux Kernel Mailing List , Andy Lutomirski , Kees Cook , Andrew Morton , linux-fsdevel@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-security-module@vger.kernel.org Cc: Linux API , Dongsu Park , Casey Schaufler , James Morris , , Jeff Layton , , Alexander Viro , Alexey Dobriyan , Ingo Molnar , , Oleg Nesterov , Michal Hocko , Jonathan Corbet , Djalal Harouni Subject: [PATCH RFC v2 2/6] proc: move /proc/{self|thread-self} dentries to proc_fs_info Date: Tue, 25 Apr 2017 14:23:54 +0200 Message-Id: <1493123038-30590-3-git-send-email-tixxdz@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1493123038-30590-1-git-send-email-tixxdz@gmail.com> References: <1493123038-30590-1-git-send-email-tixxdz@gmail.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 This is a preparation patch that moves /proc/{self|thread-self} dentries to be stored inside procfs fs_info struct instead of making them per pid namespace. Since we want to support multiple procfs instances we need to make sure that these dentries are also per-superblock instead of per-pidns, unmounting a private procfs won't clash with other procfs mounts. Cc: Kees Cook Cc: Andy Lutomirski Signed-off-by: Djalal Harouni --- fs/proc/base.c | 4 ++-- fs/proc/root.c | 8 ++++---- fs/proc/self.c | 3 +-- fs/proc/thread_self.c | 5 ++--- include/linux/pid_namespace.h | 4 +--- include/linux/proc_fs.h | 2 ++ 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index fa7d725..c96a9c6 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3214,13 +3214,13 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx) return 0; if (pos == TGID_OFFSET - 2) { - struct inode *inode = d_inode(ns->proc_self); + struct inode *inode = d_inode(fs_info->proc_self); if (!dir_emit(ctx, "self", 4, inode->i_ino, DT_LNK)) return 0; ctx->pos = pos = pos + 1; } if (pos == TGID_OFFSET - 1) { - struct inode *inode = d_inode(ns->proc_thread_self); + struct inode *inode = d_inode(fs_info->proc_thread_self); if (!dir_emit(ctx, "thread-self", 11, inode->i_ino, DT_LNK)) return 0; ctx->pos = pos = pos + 1; diff --git a/fs/proc/root.c b/fs/proc/root.c index a625361..f44b864 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -161,10 +161,10 @@ static void proc_kill_sb(struct super_block *sb) struct proc_fs_info *fs_info = proc_sb(sb); struct pid_namespace *ns = (struct pid_namespace *)fs_info->pid_ns; - if (ns->proc_self) - dput(ns->proc_self); - if (ns->proc_thread_self) - dput(ns->proc_thread_self); + if (fs_info->proc_self) + dput(fs_info->proc_self); + if (fs_info->proc_thread_self) + dput(fs_info->proc_thread_self); kill_anon_super(sb); put_pid_ns(ns); kfree(fs_info); diff --git a/fs/proc/self.c b/fs/proc/self.c index 9f95174..d3aaf71 100644 --- a/fs/proc/self.c +++ b/fs/proc/self.c @@ -36,7 +36,6 @@ int proc_setup_self(struct super_block *s) { struct inode *root_inode = d_inode(s->s_root); struct proc_fs_info *fs_info = proc_sb(s); - struct pid_namespace *ns = fs_info->pid_ns; struct dentry *self; inode_lock(root_inode); @@ -63,7 +62,7 @@ int proc_setup_self(struct super_block *s) pr_err("proc_fill_super: can't allocate /proc/self\n"); return PTR_ERR(self); } - ns->proc_self = self; + fs_info->proc_self = self; return 0; } diff --git a/fs/proc/thread_self.c b/fs/proc/thread_self.c index 13d9aef..14ea8e6 100644 --- a/fs/proc/thread_self.c +++ b/fs/proc/thread_self.c @@ -36,7 +36,6 @@ static unsigned thread_self_inum; int proc_setup_thread_self(struct super_block *s) { struct proc_fs_info *fs_info = proc_sb(s); - struct pid_namespace *ns = fs_info->pid_ns; struct inode *root_inode = d_inode(s->s_root); struct dentry *thread_self; @@ -61,10 +60,10 @@ int proc_setup_thread_self(struct super_block *s) } inode_unlock(root_inode); if (IS_ERR(thread_self)) { - pr_err("proc_fill_super: can't allocate /proc/thread_self\n"); + pr_err("proc_fill_super: can't allocate /proc/thread-self\n"); return PTR_ERR(thread_self); } - ns->proc_thread_self = thread_self; + fs_info->proc_thread_self = thread_self; return 0; } diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h index c2a989d..306bdc6 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -38,9 +38,7 @@ struct pid_namespace { unsigned int level; struct pid_namespace *parent; #ifdef CONFIG_PROC_FS - struct vfsmount *proc_mnt; - struct dentry *proc_self; - struct dentry *proc_thread_self; + struct vfsmount *proc_mnt; /* Internal proc mounted during each new pidns */ #endif #ifdef CONFIG_BSD_PROCESS_ACCT struct fs_pin *bacct; diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h index dd1dadd..7ba8540 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -10,6 +10,8 @@ struct proc_fs_info { struct pid_namespace *pid_ns; + struct dentry *proc_self; /* For /proc/self */ + struct dentry *proc_thread_self; /* For /proc/thread-self/ */ }; struct proc_dir_entry;