Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp556327imm; Fri, 11 May 2018 02:45:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZom6w2HxjNMfo7UKhgO9ejrmW7GhoyWqsRYN0Jrxc+Rsbyoeoucbp9bUljh9B/8QHLOJ91+ X-Received: by 2002:a62:6e88:: with SMTP id j130-v6mr4743039pfc.111.1526031953841; Fri, 11 May 2018 02:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526031953; cv=none; d=google.com; s=arc-20160816; b=ENVZntMU6s9tP8M+5RrYCAZ1ihTTjINg++LzvWtwHh7D7WeKHSN5228LT5ccAgoQep VUbdaXWAYnizbfapwv3sEEDaemnR3s3yfwexLkAOQIrKzq0wuIhFk/kScyE7BajJD7dz h0pZOBUhHm6P4jeBqYaNeU96HuELZdfaREKiJFygSPJEDpdSXOEb32ZkMLkKZ2vpba90 k7e5vhaDXrA9oJY7Gk6L0UWwggfaeAsVN8OA4iPeGqT6RAu7VmCjp+RQWo/rvYnTOXCa rMT19Uz1IgE7f8xlxMkufLwc6AeDex8QA3uuzbvpB3cr3+AvMJeOL4tpPzUEOfFSiIUg RWyQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition:mime-version :message-id:subject:cc:to:from:date:arc-authentication-results; bh=y+wglGTRmkq6wNFgTQEL3gL6VCKmlF12aktH9CyRLj4=; b=H1RwkgHKrROWkNBqF+EFxIvs5BfXNMsl0BT1REXbfsUtfyrsWWzWakrN94KNRfmIQ8 FpeqC966PCxZ8mk8wS45ifiKdcgFGuj4komCqB52ypm7P8hzw/KnW4b2u0UBOO/gfPtK 5eBF+1aqw4IbFgAVpscw6tDtAu53OTA5eYDlZISbrEvK3l6c7iiHiYpME1J++SUujWMd g6sDTYBTNJZBd1CvHkYKKel8OGkAztTEAswM6uLctSVd6oBqiWK/QKGFGLdh4AO8kj4F oxVTYNNu6V+0/muEVHH8dcG1xMsb3uhQ6VyvUUDIb+Yp7VUyP12y1w9aov6AW55djnyK RfOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f96-v6si2801809plb.418.2018.05.11.02.45.39; Fri, 11 May 2018 02:45:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752779AbeEKJpJ (ORCPT + 99 others); Fri, 11 May 2018 05:45:09 -0400 Received: from monster.unsafe.ru ([5.9.28.80]:52824 "EHLO mail.unsafe.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752569AbeEKJpI (ORCPT ); Fri, 11 May 2018 05:45:08 -0400 Received: from comp-core-i7-2640m-0182e6 (nat-pool-brq-t.redhat.com [213.175.37.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.unsafe.ru (Postfix) with ESMTPSA id D5040C61A9A; Fri, 11 May 2018 09:45:05 +0000 (UTC) Date: Fri, 11 May 2018 11:35:08 +0200 From: Alexey Gladkov To: Kees Cook , Andy Lutomirski , Andrew Morton , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-hardening@lists.openwall.com, linux-security-module@vger.kernel.org, linux-api@vger.kernel.org Cc: Greg Kroah-Hartman , Alexander Viro , Akinobu Mita , Oleg Nesterov , Jeff Layton , Ingo Molnar , Alexey Dobriyan , "Eric W. Biederman" , Linus Torvalds , aniel Micay , Jonathan Corbet , bfields@fieldses.org, Stephen Rothwell , solar@openwall.com, "Dmitry V. Levin" , Djalal Harouni Subject: [PATCH v5 2/7] proc: move /proc/{self|thread-self} dentries to proc_fs_info Message-ID: <20180511093508.GA1107@comp-core-i7-2640m-0182e6> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Djalal Harouni 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 99a0f24..e0c2afc 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -3252,13 +3252,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 5d4c454..184c42b 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -162,10 +162,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 3f2a88f..9ad3c55 100644 --- a/fs/proc/self.c +++ b/fs/proc/self.c @@ -38,7 +38,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); @@ -65,7 +64,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 e80dd79..8db3503 100644 --- a/fs/proc/thread_self.c +++ b/fs/proc/thread_self.c @@ -37,7 +37,6 @@ static unsigned thread_self_inum __ro_after_init; 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; @@ -62,10 +61,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 49538b1..f91a8bf 100644 --- a/include/linux/pid_namespace.h +++ b/include/linux/pid_namespace.h @@ -31,9 +31,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 7c8cf3c..5e461f6 100644 --- a/include/linux/proc_fs.h +++ b/include/linux/proc_fs.h @@ -11,6 +11,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; -- 2.10.5