2003-06-16 17:59:52

by Ross Biro

[permalink] [raw]
Subject: [PATCH] 2.4.21 /proc/<pid>/cmdline overflow

diff -urbBd linux-2.4.21-1/fs/proc/base.c linux-2.4.21-2/fs/proc/base.c
--- linux-2.4.21-1/fs/proc/base.c Fri Jun 13 07:51:37 2003
+++ linux-2.4.21-2/fs/proc/base.c Mon Jun 16 11:08:09 2003
@@ -26,6 +26,15 @@
#include <linux/seq_file.h>
#include <linux/namespace.h>

+ /*
+ * What to put in the command line when we truncat them.
+ *
+ */
+#define DOTS "..."
+// includes the trailing null.
+#define DOTLEN 4
+
+
/*
* For hysterical raisins we keep the same inumbers as in the old procfs.
* Feel free to change the macro below - just keep the range distinct from
@@ -154,11 +163,23 @@
task_unlock(task);
if (mm) {
int len = mm->arg_end - mm->arg_start;
- if (len > PAGE_SIZE)
+ if (len > PAGE_SIZE) {
len = PAGE_SIZE;
- res = access_process_vm(task, mm->arg_start, buffer, len, 0);
+ res = access_process_vm(task, mm->arg_start,
+ buffer, len, 0);
+ if (res > 0) {
+ memcpy(buffer + PAGE_SIZE - DOTLEN,
+ DOTS, DOTLEN);
+ res = PAGE_SIZE;
+ }
+ } else {
+ res = access_process_vm(task, mm->arg_start,
+ buffer, len, 0);
+ }
+
// If the nul at the end of args has been overwritten, then
// assume application is using setproctitle(3).
+
if ( res > 0 && buffer[res-1] != '\0' )
{
len = strnlen( buffer, res );


Attachments:
4kcmdline.patch (1.25 kB)