The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] Added PR_SET_PROCTITLE_AREA option for prctl()
@ 2009-10-02 21:23 Timo Sirainen
  2009-10-03  2:01 ` Bryan Donlan
  2009-10-03 11:18 ` matthieu castet
  0 siblings, 2 replies; 21+ messages in thread
From: Timo Sirainen @ 2009-10-02 21:23 UTC (permalink / raw)
  To: linux-kernel

PR_SET_PROCTITLE_AREA updates mm_struct->arg_start and arg_end to the
given pointers, which makes it possible for user space to implement
setproctitle(3) cleanly.


Signed-off-by: Timo Sirainen <tss@iki.fi>
---
 fs/proc/base.c        |    9 ++++++---
 include/linux/prctl.h |    2 ++
 kernel/sys.c          |   10 ++++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 837469a..43ef276 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -267,9 +267,12 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
  
 	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 < PAGE_SIZE) {
+	if (mm->arg_end != mm->env_start) {
+		// PR_SET_PROCTITLE_AREA used
+		res = strnlen(buffer, res);
+	} else if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) {
+		// If the nul at the end of args has been overwritten, then
+		// assume application is using old style setproctitle(3).
 		len = strnlen(buffer, res);
 		if (len < res) {
 		    res = len;
diff --git a/include/linux/prctl.h b/include/linux/prctl.h
index 9311505..c79ccc8 100644
--- a/include/linux/prctl.h
+++ b/include/linux/prctl.h
@@ -90,4 +90,6 @@
 
 #define PR_MCE_KILL	33
 
+#define PR_SET_PROCTITLE_AREA 34	/* Set process title memory area */
+
 #endif /* _LINUX_PRCTL_H */
diff --git a/kernel/sys.c b/kernel/sys.c
index 255475d..c216ae6 100644
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -1564,6 +1564,16 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
 			error = 0;
 			break;
 
+		case PR_SET_PROCTITLE_AREA: {
+			struct mm_struct *mm = current->mm;
+
+			if (arg2 >= arg3)
+				return -EINVAL;
+
+			mm->arg_start = arg2;
+			mm->arg_end = arg3;
+			return 0;
+		}
 		default:
 			error = -EINVAL;
 			break;
-- 
1.6.3.3



^ permalink raw reply related	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2009-10-06  2:57 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-02 21:23 [PATCH] Added PR_SET_PROCTITLE_AREA option for prctl() Timo Sirainen
2009-10-03  2:01 ` Bryan Donlan
2009-10-03  2:47   ` Timo Sirainen
2009-10-03  2:59     ` Bryan Donlan
2009-10-03  3:21       ` Timo Sirainen
2009-10-04 14:44       ` KOSAKI Motohiro
2009-10-04 18:05         ` Bryan Donlan
2009-10-05  0:55           ` KOSAKI Motohiro
2009-10-05  1:38             ` KOSAKI Motohiro
2009-10-05  1:44               ` Bryan Donlan
2009-10-05  1:59                 ` KOSAKI Motohiro
2009-10-05  2:21                   ` Bryan Donlan
2009-10-05  2:24                     ` KOSAKI Motohiro
2009-10-05  2:48                       ` KOSAKI Motohiro
2009-10-05  3:22                         ` Bryan Donlan
2009-10-05  3:29                           ` KOSAKI Motohiro
2009-10-05  3:39                             ` Bryan Donlan
2009-10-05  7:18                               ` KOSAKI Motohiro
2009-10-05 22:56                         ` Timo Sirainen
2009-10-03 11:18 ` matthieu castet
2009-10-04 15:10   ` KOSAKI Motohiro

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox