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

Submitted by Andrey Ryabinin on April 27, 2020, 5:14 p.m.

Details

Message ID 20200427171458.7838-1-aryabinin@virtuozzo.com
State New
Series "mm/gup: Mark lock taken only after a successful retake"
Headers show

Commit Message

Andrey Ryabinin April 27, 2020, 5:14 p.m.
From: Peter Xu <peterx@redhat.com>

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: 71335f37c5e8 ("mm/gup: allow to react to fatal signals")
Reported-by: syzbot+a8c70b7f3579fc0587dc@syzkaller.appspotmail.com
Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit c7b6a566b98524baea6a244186e665d22b633545)
Signed-off-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
---
 mm/gup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/mm/gup.c b/mm/gup.c
index 049e05960e1e..21d6c80d9405 100644
--- a/mm/gup.c
+++ b/mm/gup.c
@@ -947,7 +947,6 @@  static __always_inline long __get_user_pages_locked(struct task_struct *tsk,
 			break;
 		}
 
-		*locked = 1;
 		ret = down_read_killable(&mm->mmap_sem);
 		if (ret) {
 			BUG_ON(ret > 0);
@@ -956,6 +955,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) {