Commit c7b6a566 authored by Peter Xu's avatar Peter Xu Committed by Linus Torvalds

mm/gup: Mark lock taken only after a successful retake

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: 71335f37 ("mm/gup: allow to react to fatal signals")
Reported-by: syzbot+a8c70b7f3579fc0587dc@syzkaller.appspotmail.com
Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent ba841078
...@@ -1329,7 +1329,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, ...@@ -1329,7 +1329,6 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
if (fatal_signal_pending(current)) if (fatal_signal_pending(current))
break; break;
*locked = 1;
ret = down_read_killable(&mm->mmap_sem); ret = down_read_killable(&mm->mmap_sem);
if (ret) { if (ret) {
BUG_ON(ret > 0); BUG_ON(ret > 0);
...@@ -1338,6 +1337,7 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk, ...@@ -1338,6 +1337,7 @@ static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
break; break;
} }
*locked = 1;
ret = __get_user_pages(tsk, mm, start, 1, flags | FOLL_TRIED, ret = __get_user_pages(tsk, mm, start, 1, flags | FOLL_TRIED,
pages, NULL, locked); pages, NULL, locked);
if (!*locked) { if (!*locked) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment