From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753798AbbGOWVw (ORCPT ); Wed, 15 Jul 2015 18:21:52 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57810 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752007AbbGOWVu (ORCPT ); Wed, 15 Jul 2015 18:21:50 -0400 Date: Wed, 15 Jul 2015 15:21:49 -0700 From: Andrew Morton To: Calvin Owens Cc: Alexey Dobriyan , "Eric W. Biederman" , Al Viro , Miklos Szeredi , Zefan Li , Oleg Nesterov , Joe Perches , David Howells , , , , Andy Lutomirski , Cyrill Gorcunov , "Kirill A. Shutemov" Subject: Re: [PATCH v7] procfs: Always expose /proc//map_files/ and make it readable Message-Id: <20150715152149.0f6158c2c2f806d0be44c110@linux-foundation.org> In-Reply-To: <1434681138-2968009-1-git-send-email-calvinowens@fb.com> References: <1433821173-2804704-1-git-send-email-calvinowens@fb.com> <1434681138-2968009-1-git-send-email-calvinowens@fb.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 18 Jun 2015 19:32:18 -0700 Calvin Owens wrote: > Currently, /proc//map_files/ is restricted to CAP_SYS_ADMIN, and > is only exposed if CONFIG_CHECKPOINT_RESTORE is set. > > Each mapped file region gets a symlink in /proc//map_files/ > corresponding to the virtual address range at which it is mapped. The > symlinks work like the symlinks in /proc//fd/, so you can follow > them to the backing file even if that backing file has been unlinked. > > Currently, files which are mapped, unlinked, and closed are impossible > to stat() from userspace. Exposing /proc//map_files/ closes this > functionality "hole". > > Not being able to stat() such files makes noticing and explicitly > accounting for the space they use on the filesystem impossible. You can > work around this by summing up the space used by every file in the > filesystem and subtracting that total from what statfs() tells you, but > that obviously isn't great, and it becomes unworkable once your > filesystem becomes large enough. > > This patch moves map_files/ out from behind CONFIG_CHECKPOINT_RESTORE, > and adjusts the permissions enforced on it as follows: proc_pid_follow_link() got changed while you weren't looking, causing fs/proc/base.c: In function 'proc_map_files_follow_link': fs/proc/base.c:1963: warning: passing argument 2 of 'proc_pid_follow_link' from incompatible pointer type fs/proc/base.c:1578: note: expected 'void **' but argument is of type 'struct nameidata *' fs/proc/base.c:1963: warning: return discards qualifiers from pointer target type fs/proc/base.c: At top level: fs/proc/base.c:1971: warning: initialization from incompatible pointer type I just changed it to pass NULL: --- a/fs/proc/base.c~procfs-always-expose-proc-pid-map_files-and-make-it-readable-fix +++ a/fs/proc/base.c @@ -1955,12 +1955,13 @@ struct map_files_info { * symlinks may be used to bypass permissions on ancestor directories in the * path to the file in question. */ -static void *proc_map_files_follow_link(struct dentry *dentry, struct nameidata *nd) +static void * +proc_map_files_follow_link(struct dentry *dentry, struct nameidata *nd) { if (!capable(CAP_SYS_ADMIN)) return ERR_PTR(-EPERM); - return proc_pid_follow_link(dentry, nd); + return proc_pid_follow_link(dentry, NULL); } /* _