From: Timo Sirainen <tss@iki.fi>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] Added PR_SET_PROCTITLE_AREA option for prctl()
Date: Fri, 02 Oct 2009 17:23:22 -0400 [thread overview]
Message-ID: <1254518602.5050.4.camel@hurina> (raw)
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
next reply other threads:[~2009-10-03 1:23 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-02 21:23 Timo Sirainen [this message]
2009-10-03 2:01 ` [PATCH] Added PR_SET_PROCTITLE_AREA option for prctl() 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1254518602.5050.4.camel@hurina \
--to=tss@iki.fi \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox