Skip to content

Commit 272ddc8

Browse files
committed
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: Linus Torvalds <[email protected]>
1 parent 07d9a38 commit 272ddc8

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

fs/proc/base.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
252252
* Inherently racy -- command line shares address space
253253
* with code and data.
254254
*/
255-
rv = access_remote_vm(mm, arg_end - 1, &c, 1, FOLL_FORCE);
255+
rv = access_remote_vm(mm, arg_end - 1, &c, 1, 0);
256256
if (rv <= 0)
257257
goto out_free_page;
258258

@@ -270,8 +270,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
270270
int nr_read;
271271

272272
_count = min3(count, len, PAGE_SIZE);
273-
nr_read = access_remote_vm(mm, p, page, _count,
274-
FOLL_FORCE);
273+
nr_read = access_remote_vm(mm, p, page, _count, 0);
275274
if (nr_read < 0)
276275
rv = nr_read;
277276
if (nr_read <= 0)
@@ -306,8 +305,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
306305
bool final;
307306

308307
_count = min3(count, len, PAGE_SIZE);
309-
nr_read = access_remote_vm(mm, p, page, _count,
310-
FOLL_FORCE);
308+
nr_read = access_remote_vm(mm, p, page, _count, 0);
311309
if (nr_read < 0)
312310
rv = nr_read;
313311
if (nr_read <= 0)
@@ -356,8 +354,7 @@ static ssize_t proc_pid_cmdline_read(struct file *file, char __user *buf,
356354
bool final;
357355

358356
_count = min3(count, len, PAGE_SIZE);
359-
nr_read = access_remote_vm(mm, p, page, _count,
360-
FOLL_FORCE);
357+
nr_read = access_remote_vm(mm, p, page, _count, 0);
361358
if (nr_read < 0)
362359
rv = nr_read;
363360
if (nr_read <= 0)
@@ -835,7 +832,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
835832
unsigned long addr = *ppos;
836833
ssize_t copied;
837834
char *page;
838-
unsigned int flags = FOLL_FORCE;
835+
unsigned int flags;
839836

840837
if (!mm)
841838
return 0;
@@ -848,6 +845,8 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
848845
if (!atomic_inc_not_zero(&mm->mm_users))
849846
goto free;
850847

848+
/* Maybe we should limit FOLL_FORCE to actual ptrace users? */
849+
flags = FOLL_FORCE;
851850
if (write)
852851
flags |= FOLL_WRITE;
853852

@@ -971,8 +970,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
971970
max_len = min_t(size_t, PAGE_SIZE, count);
972971
this_len = min(max_len, this_len);
973972

974-
retval = access_remote_vm(mm, (env_start + src),
975-
page, this_len, FOLL_FORCE);
973+
retval = access_remote_vm(mm, (env_start + src), page, this_len, 0);
976974

977975
if (retval <= 0) {
978976
ret = retval;

0 commit comments

Comments
 (0)