Hi Jann, On Thu, Feb 13, 2020 at 03:08:59PM +0100, Jann Horn wrote: > On Thu, Feb 13, 2020 at 12:40 AM Minchan Kim <minchan@xxxxxxxxxx> wrote: > > To solve the issue, this patch introduces a new syscall process_madvise(2). > > It uses pidfd of an external process to give the hint. > [...] > > + mm = mm_access(task, PTRACE_MODE_ATTACH_FSCREDS); > > + if (IS_ERR_OR_NULL(mm)) { > > + ret = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH; > > + goto release_task; > > + } > > + > > + ret = do_madvise(task, start, len_in, behavior); > > When you're accessing another task, you should ensure that the other > task doesn't gain new privileges by executing a setuid binary in the > middle of being accessed. mm_access() does that for you; it holds the > ->cred_guard_mutex while it is looking up the task's ->mm and doing > the security check. mm_access() then returns you an mm pointer that > you're allowed to access without worrying about such things; an > mm_struct never gains privileges, since a setuid execution creates a > fresh mm_struct. However, the task may still execute setuid binaries > and such things. > > This means that after you've looked up the mm with mm_access(), you > have to actually *use* that pointer. You're not allowed to simply read > task->mm yourself. > > Therefore, I think you should: > > - change patch 1/8 ("mm: pass task to do_madvise") to also pass an > mm_struct* to do_madvise (but keep the task_struct* for patch 4/8) > - in this patch, pass the mm_struct* from mm_access() into do_madvise() > - drop patch 3/8 ("mm: validate mm in do_madvise"); it just papers > over a symptom without addressing the underlying problem Actually, it was what this patch series was doing until last version but I changed it to reduce just *a parameter* to do_madvise. And then, this time, I got a good advise I was not familiar. I will fix it again. Thanks for the review!