Audit system development
 help / color / mirror / Atom feed
* [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline
@ 2026-12-04  2:18 Chris Down
  2026-12-04  2:18 ` [PATCH v2 1/3] mm/util: don't let get_cmdline() stall on file-backed arguments Chris Down
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Chris Down @ 2026-12-04  2:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	Chris Mason, Paul Moore, Kees Cook, Willy Tarreau, audit,
	sashiko-bot, kernel-team

get_cmdline() reads a task's arguments for audit's proctitle record,
Yama's ptrace reports, loadpin and the msm and etnaviv GPU hang
messages. Unlike /proc/pid/cmdline, which has only read anonymous
memory since 7f7ccc2ccc2e ("proc: do not access cmdline nor environ
from file-backed areas"), it still reads whatever the task has mapped
at arg_start. That includes a file on a FUSE filesystem whose server
can take as long as it likes to answer, and some of those readers are
other tasks, or msm's hang recovery with gpu->lock held.

Patch 1 passes FOLL_ANON, so get_cmdline() reads the same memory as
/proc. This is the one for stable.

Patch 2 drops FOLL_FORCE, which get_cmdline() only has because it was
missed when 272ddc8b3735 ("proc: don't use FOLL_FORCE for reading
cmdline and environment") dropped it from /proc.

v2:

- Use a90902531a06 as the Fixes: target of patch 1
- Add patch 3, which makes get_cmdline() share one reader with
  /proc/pid/cmdline (David)

v1: https://lore.kernel.org/r/cover.1795891579.git.chris@chrisdown.name

Chris Down (3):
  mm/util: don't let get_cmdline() stall on file-backed arguments
  mm/util: drop FOLL_FORCE from get_cmdline()
  mm/util: make get_cmdline() and /proc/pid/cmdline share one reader

 fs/proc/base.c     | 134 ++--------------------------------
 include/linux/mm.h |   3 +
 mm/util.c          | 175 +++++++++++++++++++++++++++++++++++----------
 3 files changed, 147 insertions(+), 165 deletions(-)


base-commit: c6f53520f32302ea64cbcfd7cc25a31081e34548
-- 
2.56.1


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

* [PATCH v2 1/3] mm/util: don't let get_cmdline() stall on file-backed arguments
  2026-12-04  2:18 [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
@ 2026-12-04  2:18 ` Chris Down
  2026-12-04  2:18 ` [PATCH v2 2/3] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Down @ 2026-12-04  2:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	Chris Mason, Paul Moore, Kees Cook, Willy Tarreau, audit,
	sashiko-bot, kernel-team

get_cmdline() reads a task's arguments with access_process_vm(), and
in the setproctitle() case reads on into its environment. Since
commit 7f7ccc2ccc2e ("proc: do not access cmdline nor environ from
file-backed areas"), /proc/pid/cmdline and /proc/pid/environ pass
FOLL_ANON so that they only read anonymous memory, but get_cmdline()
was left alone and still faults in whatever is mapped there.

The task decides what is mapped at arg_start. It can mmap() a file
over its arguments, or move arg_start with prctl(PR_SET_MM_MAP), which
needs no capability. If that file is on a FUSE filesystem whose server
the user runs, the read blocks for as long as the server holds back
the reply.

That matters when the reader is somebody else. Yama reads the target's
command line when it reports a denied ptrace attach, and the msm and
etnaviv drivers read the command line of the task whose job hung the
GPU from their hang recovery path, msm with gpu->lock held. So the
task that hung the GPU can also hold up the recovery.

For example, take a FUSE server that waits three seconds before it
answers a read, and an unprivileged task that maps a file from it and
points arg_start there. When another of the user's tasks tries to
attach to it and Yama denies the attach, ptrace() takes the full three
seconds to fail:

    PTRACE_ATTACH returned -1 (Operation not permitted) after 3.002s
    ptrace attach of "FUSEARGS x"[109] was attempted by "/tmp/cmdtest file /tmp/fm/f"[110]

Let's pass FOLL_ANON here too, so that get_cmdline() reads the same
memory as /proc/pid/cmdline. A task whose arguments are not in
anonymous memory gets an empty command line (audit logs
proctitle=(null)), as /proc already shows it. The task decides what
its arguments say anyway, so this doesn't let it hide anything from
audit. With this applied, the attach above fails straight away.

Since commit 775abaa42585 ("mm: do not call vm_ops->access with
FOLL_ANON"), this also keeps get_cmdline() away from device mappings
with a vm_ops->access handler.

Fixes: a90902531a06 ("mm: Create utility function for accessing a tasks commandline value")
Cc: stable@vger.kernel.org
Signed-off-by: Chris Down <chris@chrisdown.name>
---
 mm/util.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index 338f259b0035..c250aa088046 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1048,7 +1048,8 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 	if (len > buflen)
 		len = buflen;
 
-	res = access_process_vm(task, arg_start, buffer, len, FOLL_FORCE);
+	res = access_process_vm(task, arg_start, buffer, len,
+				FOLL_FORCE | FOLL_ANON);
 
 	/*
 	 * If the nul at the end of args has been overwritten, then
@@ -1064,7 +1065,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 				len = buflen - res;
 			res += access_process_vm(task, env_start,
 						 buffer+res, len,
-						 FOLL_FORCE);
+						 FOLL_FORCE | FOLL_ANON);
 			res = strnlen(buffer, res);
 		}
 	}
-- 
2.56.1


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

* [PATCH v2 2/3] mm/util: drop FOLL_FORCE from get_cmdline()
  2026-12-04  2:18 [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
  2026-12-04  2:18 ` [PATCH v2 1/3] mm/util: don't let get_cmdline() stall on file-backed arguments Chris Down
@ 2026-12-04  2:18 ` Chris Down
  2026-12-04  2:18 ` [PATCH v2 3/3] mm/util: make get_cmdline() and /proc/pid/cmdline share one reader Chris Down
  2026-12-04  2:35 ` [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Down @ 2026-12-04  2:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	Chris Mason, Paul Moore, Kees Cook, Willy Tarreau, audit,
	sashiko-bot, kernel-team

get_cmdline() passes FOLL_FORCE, so it reads a task's arguments even
after the task has made them unreadable with mprotect(PROT_NONE).

It has done that from the start, because access_process_vm() used to
imply force, and commit f307ab6dcea0 ("mm: replace access_process_vm()
write parameter with gup_flags") only made that explicit. Right after
that, commit 272ddc8b3735 ("proc: don't use FOLL_FORCE for reading
cmdline and environment") dropped it again for /proc/pid/cmdline and
/proc/pid/environ, but get_cmdline() was missed.

None of the callers of get_cmdline() are debuggers, and there is no
reason for audit or Yama to see arguments that the task itself can't
read. Let's drop FOLL_FORCE, which leaves get_cmdline() with the same
flags as /proc/pid/cmdline.

Reviewed-by: David Hildenbrand (Arm) <david@kernel.org>
Signed-off-by: Chris Down <chris@chrisdown.name>
---
 mm/util.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/mm/util.c b/mm/util.c
index c250aa088046..8073af6708fb 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -1048,8 +1048,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 	if (len > buflen)
 		len = buflen;
 
-	res = access_process_vm(task, arg_start, buffer, len,
-				FOLL_FORCE | FOLL_ANON);
+	res = access_process_vm(task, arg_start, buffer, len, FOLL_ANON);
 
 	/*
 	 * If the nul at the end of args has been overwritten, then
@@ -1064,8 +1063,7 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 			if (len > buflen - res)
 				len = buflen - res;
 			res += access_process_vm(task, env_start,
-						 buffer+res, len,
-						 FOLL_FORCE | FOLL_ANON);
+						 buffer + res, len, FOLL_ANON);
 			res = strnlen(buffer, res);
 		}
 	}
-- 
2.56.1


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

* [PATCH v2 3/3] mm/util: make get_cmdline() and /proc/pid/cmdline share one reader
  2026-12-04  2:18 [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
  2026-12-04  2:18 ` [PATCH v2 1/3] mm/util: don't let get_cmdline() stall on file-backed arguments Chris Down
  2026-12-04  2:18 ` [PATCH v2 2/3] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
@ 2026-12-04  2:18 ` Chris Down
  2026-12-04  2:35 ` [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: Chris Down @ 2026-12-04  2:18 UTC (permalink / raw)
  To: Andrew Morton, David Hildenbrand
  Cc: Lorenzo Stoakes, Liam R. Howlett, Vlastimil Babka, Mike Rapoport,
	Suren Baghdasaryan, Michal Hocko, linux-mm, linux-kernel,
	Chris Mason, Paul Moore, Kees Cook, Willy Tarreau, audit,
	sashiko-bot, kernel-team

get_cmdline() and /proc/pid/cmdline each have their own code to read a
task's command line. In terms of archaeology, commit 21a6457a79a0
("proc: Update get proc_pid_cmdline() to use mm.h helpers") made /proc
call get_cmdline(), but get_cmdline() can only fill one buffer from the
start of the arguments, so commit c2c0bb44620d ("proc: fix PAGE_SIZE
limit of /proc/$PID/cmdline") gave /proc a reader of its own.

Unfortunately this has caused some divergences over the years. For
example, /proc dropped FOLL_FORCE in 2016 and started passing FOLL_ANON
in 2018, but get_cmdline() didn't catch up to that until now. The two
have also come to disagree about tasks that overwrite their arguments,
as setproctitle() does.

Let's move /proc's get_mm_cmdline() to mm/util.c and have it copy to an
iov_iter instead of a user buffer.

Here is a (I hope complete?) list of get_cmdline() changes made to match
it up with /proc:

- Before it would treat a task as having used setproctitle() when the
  last byte it read wasn't NUL, and only if the arguments were shorter
  than the buffer. Now it looks at the last byte of the arguments, as
  /proc does, so audit, which asks for 128 bytes, cuts a title in longer
  arguments at NUL instead of logging the old bytes behind it. A
  read that stops early at a file mapping is also no longer taken for a
  title.
- Before it would append the environment to a title wherever the
  environment was. Now it only reads on if the environment starts where
  the arguments end.
- Before it would leave the NUL out of the length it returned for a
  title. Now it counts the NUL, as it always has for ordinary arguments.
  Both of its callers trim trailing NULs.

get_cmdline() also reads through a bounce page now, as /proc does, and
returns 0 if it can't allocate one. Both of its callers allocate with
GFP_KERNEL right before they call it.

Signed-off-by: Chris Down <chris@chrisdown.name>
---
 fs/proc/base.c     | 134 ++--------------------------------
 include/linux/mm.h |   3 +
 mm/util.c          | 174 ++++++++++++++++++++++++++++++++++++---------
 3 files changed, 147 insertions(+), 164 deletions(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 7685660c3624..2a7897833333 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -49,6 +49,7 @@
  */
 
 #include <linux/uaccess.h>
+#include <linux/uio.h>
 
 #include <linux/errno.h>
 #include <linux/time.h>
@@ -239,145 +240,20 @@ static int proc_root_link(struct dentry *dentry, struct path *path,
 	return get_task_root(task, path);
 }
 
-/*
- * If the user used setproctitle(), we just get the string from
- * user space at arg_start, and limit it to a maximum of one page.
- */
-static ssize_t get_mm_proctitle(struct mm_struct *mm, char __user *buf,
-				size_t count, unsigned long pos,
-				unsigned long arg_start)
-{
-	char *page;
-	int ret, got;
-
-	if (pos >= PAGE_SIZE)
-		return 0;
-
-	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!page)
-		return -ENOMEM;
-
-	ret = 0;
-	got = access_remote_vm(mm, arg_start, page, PAGE_SIZE, FOLL_ANON);
-	if (got > 0) {
-		int len = strnlen(page, got);
-
-		/* Include the NUL character if it was found */
-		if (len < got)
-			len++;
-
-		if (len > pos) {
-			len -= pos;
-			if (len > count)
-				len = count;
-			len -= copy_to_user(buf, page+pos, len);
-			if (!len)
-				len = -EFAULT;
-			ret = len;
-		}
-	}
-	kfree(page);
-	return ret;
-}
-
-static ssize_t get_mm_cmdline(struct mm_struct *mm, char __user *buf,
-			      size_t count, loff_t *ppos)
-{
-	unsigned long arg_start, arg_end, env_start, env_end;
-	unsigned long pos, len;
-	char *page, c;
-
-	/* Check if process spawned far enough to have cmdline. */
-	if (!mm->env_end)
-		return 0;
-
-	spin_lock(&mm->arg_lock);
-	arg_start = mm->arg_start;
-	arg_end = mm->arg_end;
-	env_start = mm->env_start;
-	env_end = mm->env_end;
-	spin_unlock(&mm->arg_lock);
-
-	if (arg_start >= arg_end)
-		return 0;
-
-	/*
-	 * We allow setproctitle() to overwrite the argument
-	 * strings, and overflow past the original end. But
-	 * only when it overflows into the environment area.
-	 */
-	if (env_start != arg_end || env_end < env_start)
-		env_start = env_end = arg_end;
-	len = env_end - arg_start;
-
-	/* We're not going to care if "*ppos" has high bits set */
-	pos = *ppos;
-	if (pos >= len)
-		return 0;
-	if (count > len - pos)
-		count = len - pos;
-	if (!count)
-		return 0;
-
-	/*
-	 * Magical special case: if the argv[] end byte is not
-	 * zero, the user has overwritten it with setproctitle(3).
-	 *
-	 * Possible future enhancement: do this only once when
-	 * pos is 0, and set a flag in the 'struct file'.
-	 */
-	if (access_remote_vm(mm, arg_end-1, &c, 1, FOLL_ANON) == 1 && c)
-		return get_mm_proctitle(mm, buf, count, pos, arg_start);
-
-	/*
-	 * For the non-setproctitle() case we limit things strictly
-	 * to the [arg_start, arg_end[ range.
-	 */
-	pos += arg_start;
-	if (pos < arg_start || pos >= arg_end)
-		return 0;
-	if (count > arg_end - pos)
-		count = arg_end - pos;
-
-	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!page)
-		return -ENOMEM;
-
-	len = 0;
-	while (count) {
-		int got;
-		size_t size = min_t(size_t, PAGE_SIZE, count);
-
-		got = access_remote_vm(mm, pos, page, size, FOLL_ANON);
-		if (got <= 0)
-			break;
-		got -= copy_to_user(buf, page, got);
-		if (unlikely(!got)) {
-			if (!len)
-				len = -EFAULT;
-			break;
-		}
-		pos += got;
-		buf += got;
-		len += got;
-		count -= got;
-	}
-
-	kfree(page);
-	return len;
-}
-
 static ssize_t get_task_cmdline(struct task_struct *tsk, char __user *buf,
 				size_t count, loff_t *pos)
 {
 	struct mm_struct *mm;
+	struct iov_iter to;
 	ssize_t ret;
 
 	mm = get_task_mm(tsk);
 	if (!mm)
 		return 0;
 
-	ret = get_mm_cmdline(mm, buf, count, pos);
+	iov_iter_ubuf(&to, ITER_DEST, buf, count);
+	/* We're not going to care if "*pos" has high bits set */
+	ret = get_mm_cmdline(mm, &to, *pos);
 	mmput(mm);
 	return ret;
 }
diff --git a/include/linux/mm.h b/include/linux/mm.h
index d09173a94e9c..5ccbe4ba4e28 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3600,6 +3600,9 @@ bool folio_mark_dirty_lock(struct folio *folio);
 bool set_page_dirty(struct page *page);
 int set_page_dirty_lock(struct page *page);
 
+struct iov_iter;
+ssize_t get_mm_cmdline(struct mm_struct *mm, struct iov_iter *to,
+		       unsigned long pos);
 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
 
 /*
diff --git a/mm/util.c b/mm/util.c
index 8073af6708fb..bbc4f09d918c 100644
--- a/mm/util.c
+++ b/mm/util.c
@@ -28,6 +28,7 @@
 #include <linux/page_idle.h>
 
 #include <linux/uaccess.h>
+#include <linux/uio.h>
 
 #include <kunit/visibility.h>
 
@@ -1015,26 +1016,66 @@ error:
 	return -ENOMEM;
 }
 
+static ssize_t get_mm_proctitle(struct mm_struct *mm, struct iov_iter *to,
+				size_t count, unsigned long pos,
+				unsigned long arg_start)
+{
+	char *page;
+	int ret, got;
+
+	if (pos >= PAGE_SIZE)
+		return 0;
+
+	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!page)
+		return -ENOMEM;
+
+	ret = 0;
+	got = access_remote_vm(mm, arg_start, page, PAGE_SIZE, FOLL_ANON);
+	if (got > 0) {
+		int len = strnlen(page, got);
+
+		/* Include the NUL character if it was found */
+		if (len < got)
+			len++;
+
+		if (len > pos) {
+			len -= pos;
+			if (len > count)
+				len = count;
+			len = copy_to_iter(page + pos, len, to);
+			if (!len)
+				len = -EFAULT;
+			ret = len;
+		}
+	}
+	kfree(page);
+	return ret;
+}
+
 /**
- * get_cmdline() - copy the cmdline value to a buffer.
- * @task:     the task whose cmdline value to copy.
- * @buffer:   the buffer to copy to.
- * @buflen:   the length of the buffer. Larger cmdline values are truncated
- *            to this length.
+ * get_mm_cmdline() - read the command line of an mm.
+ * @mm:  the mm whose command line to read.
+ * @to:  where to copy it to.
+ * @pos: the offset in the command line to start reading at.
  *
- * Return: the size of the cmdline field copied. Note that the copy does
- * not guarantee an ending NULL byte.
+ * This is what /proc/pid/cmdline shows. The caller must hold an mm_users
+ * reference on @mm, as from get_task_mm().
+ *
+ * Return: the number of bytes copied, 0 at the end of the command line,
+ * or a negative error code if nothing was copied.
  */
-int get_cmdline(struct task_struct *task, char *buffer, int buflen)
+ssize_t get_mm_cmdline(struct mm_struct *mm, struct iov_iter *to,
+		       unsigned long pos)
 {
-	int res = 0;
-	unsigned int len;
-	struct mm_struct *mm = get_task_mm(task);
 	unsigned long arg_start, arg_end, env_start, env_end;
-	if (!mm)
-		goto out;
-	if (!mm->arg_end)
-		goto out_mm;	/* Shh! No looking before we're done */
+	size_t count = iov_iter_count(to);
+	unsigned long len;
+	char *page, c;
+
+	/* Check if process spawned far enough to have cmdline. */
+	if (!mm->env_end)
+		return 0;
 
 	spin_lock(&mm->arg_lock);
 	arg_start = mm->arg_start;
@@ -1043,34 +1084,97 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
 	env_end = mm->env_end;
 	spin_unlock(&mm->arg_lock);
 
-	len = arg_end - arg_start;
+	if (arg_start >= arg_end)
+		return 0;
 
-	if (len > buflen)
-		len = buflen;
+	/*
+	 * We allow setproctitle() to overwrite the argument
+	 * strings, and overflow past the original end. But
+	 * only when it overflows into the environment area.
+	 */
+	if (env_start != arg_end || env_end < env_start)
+		env_start = env_end = arg_end;
+	len = env_end - arg_start;
 
-	res = access_process_vm(task, arg_start, buffer, len, FOLL_ANON);
+	if (pos >= len)
+		return 0;
+	if (count > len - pos)
+		count = len - pos;
+	if (!count)
+		return 0;
 
 	/*
-	 * If the nul at the end of args has been overwritten, then
-	 * assume application is using setproctitle(3).
+	 * Magical special case: if the argv[] end byte is not
+	 * zero, the user has overwritten it with setproctitle(3).
 	 */
-	if (res > 0 && buffer[res-1] != '\0' && len < buflen) {
-		len = strnlen(buffer, res);
-		if (len < res) {
-			res = len;
-		} else {
-			len = env_end - env_start;
-			if (len > buflen - res)
-				len = buflen - res;
-			res += access_process_vm(task, env_start,
-						 buffer + res, len, FOLL_ANON);
-			res = strnlen(buffer, res);
+	if (access_remote_vm(mm, arg_end-1, &c, 1, FOLL_ANON) == 1 && c)
+		return get_mm_proctitle(mm, to, count, pos, arg_start);
+
+	/*
+	 * For the non-setproctitle() case we limit things strictly
+	 * to the [arg_start, arg_end[ range.
+	 */
+	pos += arg_start;
+	if (pos < arg_start || pos >= arg_end)
+		return 0;
+	if (count > arg_end - pos)
+		count = arg_end - pos;
+
+	page = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (!page)
+		return -ENOMEM;
+
+	len = 0;
+	while (count) {
+		int got;
+		size_t size = min_t(size_t, PAGE_SIZE, count);
+
+		got = access_remote_vm(mm, pos, page, size, FOLL_ANON);
+		if (got <= 0)
+			break;
+		got = copy_to_iter(page, got, to);
+		if (unlikely(!got)) {
+			if (!len)
+				len = -EFAULT;
+			break;
 		}
+		pos += got;
+		len += got;
+		count -= got;
 	}
-out_mm:
+
+	kfree(page);
+	return len;
+}
+
+/**
+ * get_cmdline() - copy the cmdline value to a buffer.
+ * @task:     the task whose cmdline value to copy.
+ * @buffer:   the buffer to copy to.
+ * @buflen:   the length of the buffer. Larger cmdline values are truncated
+ *            to this length.
+ *
+ * This copies the start of what /proc/pid/cmdline shows for @task.
+ *
+ * Return: the size of the cmdline field copied. Note that the copy does
+ * not guarantee an ending NULL byte.
+ */
+int get_cmdline(struct task_struct *task, char *buffer, int buflen)
+{
+	struct kvec kvec = { .iov_base = buffer, .iov_len = buflen };
+	struct mm_struct *mm;
+	struct iov_iter to;
+	ssize_t res;
+
+	mm = get_task_mm(task);
+	if (!mm)
+		return 0;
+
+	iov_iter_kvec(&to, ITER_DEST, &kvec, 1, buflen);
+	res = get_mm_cmdline(mm, &to, 0);
 	mmput(mm);
-out:
-	return res;
+
+	return res > 0 ? res : 0;
 }
 
 /**
-- 
2.56.1


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

* Re: [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline
  2026-12-04  2:18 [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
                   ` (2 preceding siblings ...)
  2026-12-04  2:18 ` [PATCH v2 3/3] mm/util: make get_cmdline() and /proc/pid/cmdline share one reader Chris Down
@ 2026-12-04  2:35 ` sashiko-bot
  3 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-04  2:35 UTC (permalink / raw)
  Cc: audit

Sashiko has reviewed this 3-patch series and found no issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1796349991.git.chris@chrisdown.name

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

end of thread, other threads:[~2026-12-04  2:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  2:18 [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline Chris Down
2026-12-04  2:18 ` [PATCH v2 1/3] mm/util: don't let get_cmdline() stall on file-backed arguments Chris Down
2026-12-04  2:18 ` [PATCH v2 2/3] mm/util: drop FOLL_FORCE from get_cmdline() Chris Down
2026-12-04  2:18 ` [PATCH v2 3/3] mm/util: make get_cmdline() and /proc/pid/cmdline share one reader Chris Down
2026-12-04  2:35 ` [PATCH v2 0/3] mm/util: use FOLL_ANON in get_cmdline() like /proc/pid/cmdline sashiko-bot

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