From 4ed854ff97e96adb8b84caafbf2eae1a528f4b50 Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Thu, 29 Oct 2020 12:10:05 +1100 Subject: [PATCH] mm/gup: assert that the mmap lock is held in __get_user_pages() After having cleaned up all GUP callers (except for the atomisp staging driver, which currently gets mmap locking completely wrong [1]) to always ensure that they hold the mmap lock when calling into GUP (unless the mm is not yet globally visible), add an assertion to make sure it stays that way going forward. [1] https://lore.kernel.org/lkml/CAG48ez3tZAb9JVhw4T5e-i=h2_DUZxfNRTDsagSRCVazNXx5qA@mail.gmail.com/ Link: https://lkml.kernel.org/r/CAG48ez1GM==OnHpS=ghqZNJPn02FCDUEHc7GQmGRMXUD_aKudg@mail.gmail.com Signed-off-by: Jann Horn Reviewed-by: Jason Gunthorpe Acked-by: Michel Lespinasse Cc: "Eric W . Biederman" Cc: John Hubbard Cc: Mauro Carvalho Chehab Cc: Sakari Ailus Signed-off-by: Andrew Morton Signed-off-by: Stephen Rothwell --- mm/gup.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/gup.c b/mm/gup.c index 102877ed77a4..04e184068ccb 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1027,6 +1027,8 @@ static long __get_user_pages(struct mm_struct *mm, struct vm_area_struct *vma = NULL; struct follow_page_context ctx = { NULL }; + mmap_assert_locked(mm); + if (!nr_pages) return 0; -- 2.50.1