提交 272ddc8b 编写于 作者: L Linus Torvalds

proc: don't use FOLL_FORCE for reading cmdline and environment

Now that Lorenzo cleaned things up and made the FOLL_FORCE users
explicit, it becomes obvious how some of them don't really need
FOLL_FORCE at all.

So remove FOLL_FORCE from the proc code that reads the command line and
arguments from user space.

The mem_rw() function actually does want FOLL_FORCE, because gdd (and
possibly many other debuggers) use it as a much more convenient version
of PTRACE_PEEKDATA, but we should consider making the FOLL_FORCE part
conditional on actually being a ptracer.  This does not actually do
that, just moves adds a comment to that effect and moves the gup_flags
settings next to each other.
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 07d9a380
...@@ -252,7 +252,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, ...@@ -252,7 +252,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
* Inherently racy -- command line shares address space * Inherently racy -- command line shares address space
* with code and data. * with code and data.
*/ */
rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_FORCE); rv = access_remote_vm(mm, arg_end - 1, &c, 1, 0);
if (rv <= 0) if (rv <= 0)
goto out_free_page; goto out_free_page;
...@@ -270,8 +270,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, ...@@ -270,8 +270,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
int nr_read; int nr_read;
_count = min3(count, len, PAGE_SIZE); _count = min3(count, len, PAGE_SIZE);
nr_read = access_remote_vm(mm, p, page, _count, nr_read = access_remote_vm(mm, p, page, _count, 0);
FOLL_FORCE);
if (nr_read < 0) if (nr_read < 0)
rv = nr_read; rv = nr_read;
if (nr_read <= 0) if (nr_read <= 0)
...@@ -306,8 +305,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, ...@@ -306,8 +305,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
bool final; bool final;
_count = min3(count, len, PAGE_SIZE); _count = min3(count, len, PAGE_SIZE);
nr_read = access_remote_vm(mm, p, page, _count, nr_read = access_remote_vm(mm, p, page, _count, 0);
FOLL_FORCE);
if (nr_read < 0) if (nr_read < 0)
rv = nr_read; rv = nr_read;
if (nr_read <= 0) if (nr_read <= 0)
...@@ -356,8 +354,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf, ...@@ -356,8 +354,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
bool final; bool final;
_count = min3(count, len, PAGE_SIZE); _count = min3(count, len, PAGE_SIZE);
nr_read = access_remote_vm(mm, p, page, _count, nr_read = access_remote_vm(mm, p, page, _count, 0);
FOLL_FORCE);
if (nr_read < 0) if (nr_read < 0)
rv = nr_read; rv = nr_read;
if (nr_read <= 0) if (nr_read <= 0)
...@@ -835,7 +832,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf, ...@@ -835,7 +832,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
unsigned long addr = *ppos; unsigned long addr = *ppos;
ssize_t copied; ssize_t copied;
char *page; char *page;
unsigned int flags = FOLL_FORCE; unsigned int flags;
if (!mm) if (!mm)
return 0; return 0;
...@@ -848,6 +845,8 @@ static ssize_t mem_rw(struct file *file, char __user *buf, ...@@ -848,6 +845,8 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
if (!atomic_inc_not_zero(&mm->mm_users)) if (!atomic_inc_not_zero(&mm->mm_users))
goto free; goto free;
/* Maybe we should limit FOLL_FORCE to actual ptrace users? */
flags = FOLL_FORCE;
if (write) if (write)
flags |= FOLL_WRITE; flags |= FOLL_WRITE;
...@@ -971,8 +970,7 @@ static ssize_t environ_read(struct file *file, char __user *buf, ...@@ -971,8 +970,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
max_len = min_t(size_t, PAGE_SIZE, count); max_len = min_t(size_t, PAGE_SIZE, count);
this_len = min(max_len, this_len); this_len = min(max_len, this_len);
retval = access_remote_vm(mm, (env_start + src), retval = access_remote_vm(mm, (env_start + src), page, this_len, 0);
page, this_len, FOLL_FORCE);
if (retval <= 0) { if (retval <= 0) {
ret = retval; ret = retval;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册