From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932123AbbEHVcn (ORCPT ); Fri, 8 May 2015 17:32:43 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33196 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753124AbbEHVcj (ORCPT ); Fri, 8 May 2015 17:32:39 -0400 Date: Fri, 8 May 2015 14:32:38 -0700 From: Andrew Morton To: Alexey Dobriyan Cc: linux-kernel@vger.kernel.org, jarod@redhat.com Subject: Re: [PATCH try #4] proc: fix PAGE_SIZE limit of /proc/$PID/cmdline Message-Id: <20150508143238.0ee277dd71a6dcffa74f29b4@linux-foundation.org> In-Reply-To: <20150508122805.GA27370@p183.telecom.by> References: <20150508122805.GA27370@p183.telecom.by> 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 Fri, 8 May 2015 15:28:05 +0300 Alexey Dobriyan wrote: > /proc/$PID/cmdline truncates output at PAGE_SIZE. It is easy to see with > > $ cat /proc/self/cmdline $(seq 1037) 2>/dev/null > > However, command line size was never limited to PAGE_SIZE but to 128 KB and > relatively recently limitation was removed altogether. > > People noticed and ask questions: > http://stackoverflow.com/questions/199130/how-do-i-increase-the-proc-pid-cmdline-4096-byte-limit > > seq file interface is not OK, because it kmalloc's for whole output and > open + read(, 1) + sleep will pin arbitrary amounts of kernel memory. > To not do that, limit must be imposed which is incompatible with > arbitrary sized command lines. > > I apologize for hairy code, but this it direct consequence of command line > layout in memory and hacks to support things like "init [3]". > > The loops are "unrolled" otherwise it is either macros which hide > control flow or functions with 7-8 arguments with equal line count. > > There should be real setproctitle(2) or something. > > ... > > fs/proc/base.c | 203 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- > 1 file changed, 194 insertions(+), 9 deletions(-) I still hate your patch! Also, dude. i386: In file included from include/asm-generic/bug.h:13:0, from ./arch/x86/include/asm/bug.h:35, from include/linux/bug.h:4, from include/linux/thread_info.h:11, from ./arch/x86/include/asm/uaccess.h:8, from fs/proc/base.c:50: fs/proc/base.c: In function 'proc_pid_cmdline_read': include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:600:9: note: in definition of macro 'min' typeof(x) _min1 = (x); \ ^ include/linux/kernel.h:611:38: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:265:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:600:21: note: in definition of macro 'min' typeof(x) _min1 = (x); \ ^ include/linux/kernel.h:611:38: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:265:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:611:23: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:265:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:600:9: note: in definition of macro 'min' typeof(x) _min1 = (x); \ ^ include/linux/kernel.h:611:38: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:300:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:600:21: note: in definition of macro 'min' typeof(x) _min1 = (x); \ ^ include/linux/kernel.h:611:38: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:300:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:611:23: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:300:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:600:9: note: in definition of macro 'min' typeof(x) _min1 = (x); \ ^ include/linux/kernel.h:611:38: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:349:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:600:21: note: in definition of macro 'min' typeof(x) _min1 = (x); \ ^ include/linux/kernel.h:611:38: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:349:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ include/linux/kernel.h:602:17: warning: comparison of distinct pointer types lacks a cast [enabled by default] (void) (&_min1 == &_min2); \ ^ include/linux/kernel.h:611:23: note: in expansion of macro 'min' #define min3(x, y, z) min((typeof(x))min(x, y), z) ^ fs/proc/base.c:349:13: note: in expansion of macro 'min3' _count = min3(count, len, PAGE_SIZE); ^ --- a/fs/proc/base.c~proc-fix-page_size-limit-of-proc-pid-cmdline-fix +++ a/fs/proc/base.c @@ -197,11 +197,12 @@ static int proc_root_link(struct dentry } static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, - size_t count, loff_t *pos) + size_t _count, loff_t *pos) { struct task_struct *tsk; struct mm_struct *mm; char *page; + unsigned long count = _count; unsigned long arg_start, arg_end, env_start, env_end; unsigned long len1, len2, len; unsigned long p; _