Skip to content

Commit ee9955d

Browse files
author
Christian Brauner
committed
mm: use pidfd_get_task()
Instead of duplicating the same code in two places use the newly added pidfd_get_task() helper. This fixes an (unimportant for now) bug where PIDTYPE_PID is used whereas PIDTYPE_TGID should have been used. Link: https://lore.kernel.org/r/[email protected] Link: https://lore.kernel.org/r/[email protected] Cc: Vlastimil Babka <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Cc: Matthew Bobrowski <[email protected]> Cc: Alexander Duyck <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: Jan Kara <[email protected]> Cc: Minchan Kim <[email protected]> Reviewed-by: Matthew Bobrowski <[email protected]> Acked-by: David Hildenbrand <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent e9bdcdb commit ee9955d

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

mm/madvise.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
12351235
struct iovec iovstack[UIO_FASTIOV], iovec;
12361236
struct iovec *iov = iovstack;
12371237
struct iov_iter iter;
1238-
struct pid *pid;
12391238
struct task_struct *task;
12401239
struct mm_struct *mm;
12411240
size_t total_len;
@@ -1250,18 +1249,12 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
12501249
if (ret < 0)
12511250
goto out;
12521251

1253-
pid = pidfd_get_pid(pidfd, &f_flags);
1254-
if (IS_ERR(pid)) {
1255-
ret = PTR_ERR(pid);
1252+
task = pidfd_get_task(pidfd, &f_flags);
1253+
if (IS_ERR(task)) {
1254+
ret = PTR_ERR(task);
12561255
goto free_iov;
12571256
}
12581257

1259-
task = get_pid_task(pid, PIDTYPE_PID);
1260-
if (!task) {
1261-
ret = -ESRCH;
1262-
goto put_pid;
1263-
}
1264-
12651258
if (!process_madvise_behavior_valid(behavior)) {
12661259
ret = -EINVAL;
12671260
goto release_task;
@@ -1301,8 +1294,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
13011294
mmput(mm);
13021295
release_task:
13031296
put_task_struct(task);
1304-
put_pid:
1305-
put_pid(pid);
13061297
free_iov:
13071298
kfree(iov);
13081299
out:

mm/oom_kill.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,21 +1151,14 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
11511151
struct task_struct *p;
11521152
unsigned int f_flags;
11531153
bool reap = true;
1154-
struct pid *pid;
11551154
long ret = 0;
11561155

11571156
if (flags)
11581157
return -EINVAL;
11591158

1160-
pid = pidfd_get_pid(pidfd, &f_flags);
1161-
if (IS_ERR(pid))
1162-
return PTR_ERR(pid);
1163-
1164-
task = get_pid_task(pid, PIDTYPE_TGID);
1165-
if (!task) {
1166-
ret = -ESRCH;
1167-
goto put_pid;
1168-
}
1159+
task = pidfd_get_task(pidfd, &f_flags);
1160+
if (IS_ERR(task))
1161+
return PTR_ERR(task);
11691162

11701163
/*
11711164
* Make sure to choose a thread which still has a reference to mm
@@ -1204,8 +1197,6 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
12041197
mmdrop(mm);
12051198
put_task:
12061199
put_task_struct(task);
1207-
put_pid:
1208-
put_pid(pid);
12091200
return ret;
12101201
#else
12111202
return -ENOSYS;

0 commit comments

Comments
 (0)