Skip to content

Commit

Permalink
mm/gup: Mark lock taken only after a successful retake
Browse files Browse the repository at this point in the history
It's definitely incorrect to mark the lock as taken even if
down_read_killable() failed.

This wass overlooked when we switched from down_read() to
down_read_killable() because down_read() won't fail while
down_read_killable() could.

Fixes: 71335f3 ("mm/gup: allow to react to fatal signals")
Reported-by: [email protected]
Signed-off-by: Peter Xu <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
xzpeter authored and torvalds committed Apr 8, 2020
1 parent ba84107 commit c7b6a56
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion mm/gup.c
Original file line number Diff line number Diff line change
Expand Up @@ -1329,7 +1329,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
if (fatal_signal_pending(current))
break;

*locked = 1;
ret = down_read_killable(&mm->mmap_sem);
if (ret) {
BUG_ON(ret > 0);
Expand All @@ -1338,6 +1337,7 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
break;
}

*locked = 1;
ret = __get_user_pages(tsk, mm, start, 1, flags | FOLL_TRIED,
pages, NULL, locked);
if (!*locked) {
Expand Down

0 comments on commit c7b6a56

Please sign in to comment.