aboutsummaryrefslogtreecommitdiffstats
path: root/mm
diff options
context:
space:
mode:
authorWilliam Roberts <bill.c.roberts@gmail.com>2014-02-11 13:11:59 -0500
committerEric Paris <eparis@redhat.com>2014-03-07 11:52:45 -0500
commita90902531a06a030a252a07fbff7f45a189a64fe (patch)
tree676cd6bd7530f5187af569baf93a138d085737c0 /mm
parent147d2601d8fabf9451364f2d58098530a37eb3c9 (diff)
mm: Create utility function for accessing a tasks commandline value
introduce get_cmdline() for retreiving the value of a processes proc/self/cmdline value. Acked-by: David Rientjes <rientjes@google.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Acked-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: William Roberts <wroberts@tresys.com> Signed-off-by: Eric Paris <eparis@redhat.com>
Diffstat (limited to 'mm')
-rw-r--r--mm/util.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/mm/util.c b/mm/util.c
index 808f375648e7..43b44199c5e3 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -413,6 +413,54 @@ unsigned long vm_commit_limit(void)
413 * sysctl_overcommit_ratio / 100) + total_swap_pages; 413 * sysctl_overcommit_ratio / 100) + total_swap_pages;
414} 414}
415 415
416/**
417 * get_cmdline() - copy the cmdline value to a buffer.
418 * @task: the task whose cmdline value to copy.
419 * @buffer: the buffer to copy to.
420 * @buflen: the length of the buffer. Larger cmdline values are truncated
421 * to this length.
422 * Returns the size of the cmdline field copied. Note that the copy does
423 * not guarantee an ending NULL byte.
424 */
425int get_cmdline(struct task_struct *task, char *buffer, int buflen)
426{
427 int res = 0;
428 unsigned int len;
429 struct mm_struct *mm = get_task_mm(task);
430 if (!mm)
431 goto out;
432 if (!mm->arg_end)
433 goto out_mm; /* Shh! No looking before we're done */
434
435 len = mm->arg_end - mm->arg_start;
436
437 if (len > buflen)
438 len = buflen;
439
440 res = access_process_vm(task, mm->arg_start, buffer, len, 0);
441
442 /*
443 * If the nul at the end of args has been overwritten, then
444 * assume application is using setproctitle(3).
445 */
446 if (res > 0 && buffer[res-1] != '\0' && len < buflen) {
447 len = strnlen(buffer, res);
448 if (len < res) {
449 res = len;
450 } else {
451 len = mm->env_end - mm->env_start;
452 if (len > buflen - res)
453 len = buflen - res;
454 res += access_process_vm(task, mm->env_start,
455 buffer+res, len, 0);
456 res = strnlen(buffer, res);
457 }
458 }
459out_mm:
460 mmput(mm);
461out:
462 return res;
463}
416 464
417/* Tracepoints definitions. */ 465/* Tracepoints definitions. */
418EXPORT_TRACEPOINT_SYMBOL(kmalloc); 466EXPORT_TRACEPOINT_SYMBOL(kmalloc);