Received: by 10.223.164.202 with SMTP id h10csp420178wrb; Thu, 9 Nov 2017 08:20:25 -0800 (PST) X-Google-Smtp-Source: ABhQp+Q2Ng3jkgd+IMUuc5IPCZGia0/9RJSYDFXkZZ7PufX9SFFrxE3pC3c9ky84GV2k+L+0sPL0 X-Received: by 10.98.215.66 with SMTP id v2mr1019214pfl.24.1510244425689; Thu, 09 Nov 2017 08:20:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510244425; cv=none; d=google.com; s=arc-20160816; b=ExPg1Hj4Ye0euyJ6jvJACwZ7re6q5F0lutATut0OWh51qHXeR/tc9Ly5H5hIXVW466 8DnD1Ux6I3b1w8SwJjUz55r0djvR5LLtn4Kde3syDOOZyFa9PaI1pd4Y2Eu8Zrt0oQl5 tRULNuGMmA13mY6meAkc+dEsodOYuSKfoQZ8u+Hr60jAudJd4momuox8DHIMyLCPmCrC YPu5ykGsODy6Nsh4dHp7BkwRCeHjsKNLsHwO1IQol73uvlVTT1TPLUm61WZSQEspD7De ZoR3HOT3JSVLrHL68YAcAkvH3b28DpLhdW5UX9e/dKHyiA5q75dB1fnRq2t94XFdilEn XZOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=6B9x6W5lf1dUlALYg5vuda+b3N7UnIrUA7f5CkgkolQ=; b=OP9LhEtSgg5c/gnIj3RSk3ZIgHSj606ezODDA3egV/YIx6ra7HOlLSzQKjgevmr711 YTBJIBjoQlO8wqlRDBBcmJlAAaIBdztbUCgn53DK42gpSqTjXaEWsZgnXRgKCkiKUpuW NzjJuBtLNsDrzUqe41jJwdRkn+558N1IS6qINxlC5mMsdHYzWc2NHGlsTTPIqiugpmXB Xr+I4bxuOWo6g+O6tzF7+WI3VUejVuRKzDYCiDFHNvj1mhdZVCLjbdKgY/AHMPBA6FYL uLr9lgT64pDkVu2970YTQameb60kKj4DHSVDyWi6/FxsbXRHun5tnoGoYRBarqoXb7f+ hG9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G1ho3AbG; 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=pass (p=NONE sp=NONE 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 v187si1581574pfv.227.2017.11.09.08.20.14; Thu, 09 Nov 2017 08:20:25 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=G1ho3AbG; 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=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753500AbdKIQSE (ORCPT + 81 others); Thu, 9 Nov 2017 11:18:04 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:53163 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753321AbdKIQO0 (ORCPT ); Thu, 9 Nov 2017 11:14:26 -0500 Received: by mail-wm0-f66.google.com with SMTP id t139so18842059wmt.1; Thu, 09 Nov 2017 08:14:25 -0800 (PST) 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=6B9x6W5lf1dUlALYg5vuda+b3N7UnIrUA7f5CkgkolQ=; b=G1ho3AbGqeo7QWYE4Dw2JO972I+slWuqGkfrB1Dmi9UCqW9dS2ha54+VAaEXcz06Sa AWU8K8hsEaBn29E5o1wbfqcNzE33QUsh7CncSns7fKKDVd7CMLBftSVTirISCm7Lx9wX LwXu0tdvfnMuSNFndOHcq8mcYmUWsKWKMrOEyd1g93I1iMd/vqaKjMCipagElp3rxl2b 3uqtnWsLSEXEzgtc2jbcCs80Qjggs5yvHRO3E+Er5C1Ye/8j10HDFstUv3+9/23oTd8/ +KjJq3vd3mf3TSs3E+BxNmmgvdkiFGIA3FTkZvhY/brg4jP/ukATn23S4gcYWeaStWsL D+5w== 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=6B9x6W5lf1dUlALYg5vuda+b3N7UnIrUA7f5CkgkolQ=; b=pg9rFCCI+69GPWBn3/P8bWmH1NPEXXYCmj46Q8i9QdUGMR5s3nMHLl4uL6iD2lK8na 9DPrBNflcvzSDNpzZph+bNntiUr6f//ZS4d8rRyNmodxwESJrfxeBxiltaOMhZwA+UDS ljIs9PRi4p49FT01hj+8FVebLzR82NdNhsU8rbVh62MTNaNYGZjUDHYye7eIryjEI1T9 PgsQEde2rQzJXbNSiQYxUq11ikcAbNsfK0We6mLneVjLyxqUaDdeL0vb/WClEQz2N47n P8IkPlrDeb7pgxMTOXFdVjZCW6aPNT+W/TfjP7BtRI5k1mCGQyV3Zd1xNXN2HrhLro10 Yw5Q== X-Gm-Message-State: AJaThX7MFBkT7sWGgQiI6z7xqURmLcriQjcLSd0Pa6E6kMJ50cOkgiJ2 IFrwicPjWybt6jcVXL1YF44= X-Received: by 10.80.159.168 with SMTP id c37mr1390873edf.46.1510244065043; Thu, 09 Nov 2017 08:14:25 -0800 (PST) Received: from localhost.localdomain (ip-109-45-0-227.web.vodafone.de. [109.45.0.227]) by smtp.gmail.com with ESMTPSA id d3sm5826085edd.41.2017.11.09.08.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 09 Nov 2017 08:14:24 -0800 (PST) From: Djalal Harouni To: Kees Cook , Alexey Gladkov , 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 , me@tobin.cc, Oleg Nesterov , Jeff Layton , Ingo Molnar , Alexey Dobriyan , ebiederm@xmission.com, Linus Torvalds , Daniel Micay , Jonathan Corbet , bfields@fieldses.org, Stephen Rothwell , solar@openwall.com, Djalal Harouni Subject: [PATCH RFC v3 2/7] proc: move /proc/{self|thread-self} dentries to proc_fs_info Date: Thu, 9 Nov 2017 17:14:01 +0100 Message-Id: <1510244046-3256-3-git-send-email-tixxdz@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1510244046-3256-1-git-send-email-tixxdz@gmail.com> References: <1510244046-3256-1-git-send-email-tixxdz@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This is a preparation patch that moves /proc/{self|thread-self} dentries to be stored inside procfs proc_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, and we want to make sure that unmounting a private procfs won't clash with other procfs mounts. Cc: Kees Cook Cc: Greg Kroah-Hartman Suggested-by: Andy Lutomirski Signed-off-by: Alexey Gladkov 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 5fc2006..0d9b4214 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 43e2639..b225ae5 100644 --- a/fs/proc/root.c +++ b/fs/proc/root.c @@ -166,10 +166,10 @@ static void proc_kill_sb(struct super_block *sb) struct proc_fs_info *fs_info = proc_sb(sb); struct pid_namespace *ns = 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 f773301..8a67cf0 100644 --- a/fs/proc/self.c +++ b/fs/proc/self.c @@ -37,7 +37,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); @@ -64,7 +63,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 578887b..6e3225f 100644 --- a/fs/proc/thread_self.c +++ b/fs/proc/thread_self.c @@ -37,7 +37,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; @@ -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 9a3f6e9..8f89069 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; -- 2.7.4 From 1583924007500868104@xxx Mon Nov 13 04:34:05 +0000 2017 X-GM-THRID: 1583886800140293421 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread