sparc64: Use arch_validate_flags() to validate ADI flag
authorKhalid Aziz <khalid.aziz@oracle.com>
Fri, 23 Oct 2020 17:56:11 +0000 (11:56 -0600)
committerDavid S. Miller <davem@davemloft.net>
Fri, 19 Feb 2021 00:37:42 +0000 (16:37 -0800)
commit147d8622f2a26ef34beacc60e1ed8b66c2fa457f
treeddba8acb7fcbf6b76353324504328bc3a7508d99
parent76962e03934e1a77795852c1d64bd8491a00fb52
sparc64: Use arch_validate_flags() to validate ADI flag

When userspace calls mprotect() to enable ADI on an address range,
do_mprotect_pkey() calls arch_validate_prot() to validate new
protection flags. arch_validate_prot() for sparc looks at the first
VMA associated with address range to verify if ADI can indeed be
enabled on this address range. This has two issues - (1) Address
range might cover multiple VMAs while arch_validate_prot() looks at
only the first VMA, (2) arch_validate_prot() peeks at VMA without
holding mmap lock which can result in race condition.

arch_validate_flags() from commit c462ac288f2c ("mm: Introduce
arch_validate_flags()") allows for VMA flags to be validated for all
VMAs that cover the address range given by user while holding mmap
lock. This patch updates sparc code to move the VMA check from
arch_validate_prot() to arch_validate_flags() to fix above two
issues.

Suggested-by: Jann Horn <jannh@google.com>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Khalid Aziz <khalid.aziz@oracle.com>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
arch/sparc/include/asm/mman.h