Skip to content

Commit

Permalink
mm: Add address parameter to arch_validate_prot()
Browse files Browse the repository at this point in the history
A protection flag may not be valid across entire address space and
hence arch_validate_prot() might need the address a protection bit is
being set on to ensure it is a valid protection flag. For example, sparc
processors support memory corruption detection (as part of ADI feature)
flag on memory addresses mapped on to physical RAM but not on PFN mapped
pages or addresses mapped on to devices. This patch adds address to the
parameters being passed to arch_validate_prot() so protection bits can
be validated in the relevant context.

Signed-off-by: Khalid Aziz <[email protected]>
Cc: Khalid Aziz <[email protected]>
Reviewed-by: Anthony Yznaga <[email protected]>
Acked-by: Michael Ellerman <[email protected]> (powerpc)
Acked-by: Andrew Morton <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
hikerockies authored and davem330 committed Mar 18, 2018
1 parent c6202ca commit 9035cf9
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions arch/powerpc/include/asm/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
}
#define arch_vm_get_page_prot(vm_flags) arch_vm_get_page_prot(vm_flags)

static inline bool arch_validate_prot(unsigned long prot)
static inline bool arch_validate_prot(unsigned long prot, unsigned long addr)
{
if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM | PROT_SAO))
return false;
if ((prot & PROT_SAO) && !cpu_has_feature(CPU_FTR_SAO))
return false;
return true;
}
#define arch_validate_prot(prot) arch_validate_prot(prot)
#define arch_validate_prot arch_validate_prot

#endif /* CONFIG_PPC64 */
#endif /* _ASM_POWERPC_MMAN_H */
2 changes: 1 addition & 1 deletion arch/powerpc/kernel/syscalls.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static inline long do_mmap2(unsigned long addr, size_t len,
{
long ret = -EINVAL;

if (!arch_validate_prot(prot))
if (!arch_validate_prot(prot, addr))
goto out;

if (shift) {
Expand Down
2 changes: 1 addition & 1 deletion include/linux/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static inline void vm_unacct_memory(long pages)
*
* Returns true if the prot flags are valid
*/
static inline bool arch_validate_prot(unsigned long prot)
static inline bool arch_validate_prot(unsigned long prot, unsigned long addr)
{
return (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC | PROT_SEM)) == 0;
}
Expand Down
2 changes: 1 addition & 1 deletion mm/mprotect.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len,
end = start + len;
if (end <= start)
return -ENOMEM;
if (!arch_validate_prot(prot))
if (!arch_validate_prot(prot, start))
return -EINVAL;

reqprot = prot;
Expand Down

0 comments on commit 9035cf9

Please sign in to comment.