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

Andrey Ryabinin aryabinin at virtuozzo.com
Mon Apr 27 20:14:58 MSK 2020


From: Peter Xu <peterx at 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 at syzkaller.appspotmail.com
Signed-off-by: Peter Xu <peterx at redhat.com>
Signed-off-by: Linus Torvalds <torvalds at linux-foundation.org>
(cherry picked from commit c7b6a566b98524baea6a244186e665d22b633545)
Signed-off-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
---
 mm/gup.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

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) {
-- 
2.26.2



More information about the Devel mailing list