Skip to content

Commit 22af8ca

Browse files
lorenzo-stoakesakpm00
authored andcommitted
mm/madvise: process_madvise() drop capability check if same mm
In commit 96cfe2c ("mm/madvise: replace ptrace attach requirement for process_madvise") process_madvise() was updated to require the caller to possess the CAP_SYS_NICE capability to perform the operation, in addition to a check against PTRACE_MODE_READ performed by mm_access(). The mm_access() function explicitly checks to see if the address space of the process being referenced is the current one, in which case no check is performed. We, however, do not do this when checking the CAP_SYS_NICE capability. This means that we insist on the caller possessing this capability in order to perform madvise() operations on its own address space, which seems nonsensical. Simply add a check to allow for an invocation of this function with pidfd set to the current process without elevation. Link: https://lkml.kernel.org/r/[email protected] Fixes: 96cfe2c ("mm/madvise: replace ptrace attach requirement for process_madvise") Signed-off-by: Lorenzo Stoakes <[email protected]> Reviewed-by: Liam R. Howlett <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Acked-by: Shakeel Butt <[email protected]> Acked-by: David Rientjes <[email protected]> Cc: Kees Cook <[email protected]> Cc: Minchan Kim <[email protected]> Cc: Suren Baghdasaryan <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 2a1b864 commit 22af8ca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/madvise.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1527,7 +1527,7 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
15271527
* Require CAP_SYS_NICE for influencing process performance. Note that
15281528
* only non-destructive hints are currently supported.
15291529
*/
1530-
if (!capable(CAP_SYS_NICE)) {
1530+
if (mm != current->mm && !capable(CAP_SYS_NICE)) {
15311531
ret = -EPERM;
15321532
goto release_mm;
15331533
}

0 commit comments

Comments
 (0)