]> Git Repo - linux.git/commit
mm: split critical region in remap_file_pages() and invoke LSMs in between
authorKirill A. Shutemov <[email protected]>
Fri, 18 Oct 2024 16:14:15 +0000 (18:14 +0200)
committerAndrew Morton <[email protected]>
Tue, 29 Oct 2024 04:40:41 +0000 (21:40 -0700)
commit58a039e679fe72bd0efa8b2abe669a7914bb4429
treec2da504e5601694cd0faf93be3a3401328e7db3e
parentf2330b650e97a68c1afce66305f10651a9544037
mm: split critical region in remap_file_pages() and invoke LSMs in between

Commit ea7e2d5e49c0 ("mm: call the security_mmap_file() LSM hook in
remap_file_pages()") fixed a security issue, it added an LSM check when
trying to remap file pages, so that LSMs have the opportunity to evaluate
such action like for other memory operations such as mmap() and
mprotect().

However, that commit called security_mmap_file() inside the mmap_lock
lock, while the other calls do it before taking the lock, after commit
8b3ec6814c83 ("take security_mmap_file() outside of ->mmap_sem").

This caused lock inversion issue with IMA which was taking the mmap_lock
and i_mutex lock in the opposite way when the remap_file_pages() system
call was called.

Solve the issue by splitting the critical region in remap_file_pages() in
two regions: the first takes a read lock of mmap_lock, retrieves the VMA
and the file descriptor associated, and calculates the 'prot' and 'flags'
variables; the second takes a write lock on mmap_lock, checks that the VMA
flags and the VMA file descriptor are the same as the ones obtained in the
first critical region (otherwise the system call fails), and calls
do_mmap().

In between, after releasing the read lock and before taking the write
lock, call security_mmap_file(), and solve the lock inversion issue.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: ea7e2d5e49c0 ("mm: call the security_mmap_file() LSM hook in remap_file_pages()")
Signed-off-by: Kirill A. Shutemov <[email protected]>
Signed-off-by: Roberto Sassu <[email protected]>
Reported-by: [email protected]
Closes: https://lore.kernel.org/linux-security-module/[email protected]/
Tested-by: Roberto Sassu <[email protected]>
Reviewed-by: Roberto Sassu <[email protected]>
Reviewed-by: Jann Horn <[email protected]>
Reviewed-by: Lorenzo Stoakes <[email protected]>
Reviewed-by: Liam R. Howlett <[email protected]>
Reviewed-by: Paul Moore <[email protected]>
Tested-by: [email protected]
Cc: Jarkko Sakkinen <[email protected]>
Cc: Dmitry Kasatkin <[email protected]>
Cc: Eric Snowberg <[email protected]>
Cc: James Morris <[email protected]>
Cc: Mimi Zohar <[email protected]>
Cc: "Serge E. Hallyn" <[email protected]>
Cc: Shu Han <[email protected]>
Cc: Vlastimil Babka <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
mm/mmap.c
This page took 0.052885 seconds and 4 git commands to generate.