Do not export PAGE_SIZE to userspace.
PATCH 1/1 Do not export PAGE_SIZE to userspace.
Userspace should use getpagesize() or sysconf(_SC_PAGESIZE) to get memory page size.
man 2 getpagesize:
... Generally, one uses binaries that are architecture but not machine model dependent, in order to have a single binary distribution per architecture. This means that a user program should not find PAGE_SIZE at compile time from a header file, but use an actual system call, at least for those architectures (like sun4) where this dependency exists.
--- include/asm-blackfin/page.h | 4 ++-- include/asm-m32r/page.h | 3 ++- include/asm-ppc/page.h | 4 ++-- include/asm-s390/page.h | 2 +- include/asm-sh64/page.h | 2 +- include/asm-um/page.h | 4 ++++ include/asm-x86/page_32.h | 3 ++- include/asm-x86/page_64.h | 3 ++- 8 files changed, 16 insertions(+), 9 deletions(-)
include/asm-blackfin/page.h +2 -2
@@ -1,6 +1,8 @@#ifndef _BLACKFIN_PAGE_H#define _BLACKFIN_PAGE_H +#ifdef __KERNEL__ +/* PAGE_SHIFT determines the page size */ #define PAGE_SHIFT 12
@@ -11,8 +13,6 @@#endif #define PAGE_MASK (~(PAGE_SIZE-1)) -#ifdef __KERNEL__ -#include <asm/setup.h> #ifndef __ASSEMBLY__
include/asm-m32r/page.h +2 -1
@@ -1,12 +1,13 @@#ifndef _ASM_M32R_PAGE_H#define _ASM_M32R_PAGE_H +#ifdef __KERNEL__ +/* PAGE_SHIFT determines the page size */ #define PAGE_SHIFT 12#define PAGE_SIZE (1UL << PAGE_SHIFT)#define PAGE_MASK (~(PAGE_SIZE-1)) -#ifdef __KERNEL__#ifndef __ASSEMBLY__extern void clear_page (void *to);
include/asm-ppc/page.h +2 -2
@@ -1,6 +1,8 @@#ifndef _PPC_PAGE_H#define _PPC_PAGE_H +#ifdef __KERNEL__ +#include <asm/asm-compat.h> /* PAGE_SHIFT determines the page size */
@@ -13,8 +15,6 @@*/ #define PAGE_MASK (~((1 << PAGE_SHIFT) - 1)) -#ifdef __KERNEL__ -/* This must match what is in arch/ppc/Makefile */ #define PAGE_OFFSET CONFIG_KERNEL_START#define KERNELBASE PAGE_OFFSET
include/asm-s390/page.h +1 -1
@@ -9,6 +9,7 @@#ifndef _S390_PAGE_H#define _S390_PAGE_H +#ifdef __KERNEL__#include <linux/const.h> #include <asm/types.h>
@@ -19,7 +20,6 @@#define PAGE_DEFAULT_ACC 0#define PAGE_DEFAULT_KEY (PAGE_DEFAULT_ACC << 4) -#ifdef __KERNEL__#include <asm/setup.h> #ifndef __ASSEMBLY__
include/asm-sh64/page.h +1 -1
@@ -17,6 +17,7 @@* */ +#ifdef __KERNEL__/* PAGE_SHIFT determines the page size */ #define PAGE_SHIFT 12
@@ -43,7 +44,6 @@#define ARCH_HAS_SETCLEAR_HUGE_PTE #endif -#ifdef __KERNEL__#ifndef __ASSEMBLY__extern struct page *mem_map;
include/asm-um/page.h +4 -0
@@ -7,6 +7,8 @@#ifndef __UM_PAGE_H#define __UM_PAGE_H +#ifdef __KERNEL__ +struct page ;#include <linux/types.h>
@@ -118,4 +120,6 @@ extern struct page *arch_validate(struct page *page, gfp_t mask, int order);#include <asm-generic/memory_model.h> #include <asm-generic/page.h> +#endif /* __KERNEL__ */ +#endif
include/asm-x86/page_32.h +2 -1
@@ -1,6 +1,8 @@#ifndef _I386_PAGE_H#define _I386_PAGE_H +#ifdef __KERNEL__ +/* PAGE_SHIFT determines the page size */ #define PAGE_SHIFT 12#define PAGE_SIZE (1UL << PAGE_SHIFT)
@@ -9,7 +11,6 @@#define LARGE_PAGE_MASK (~(LARGE_PAGE_SIZE-1))#define LARGE_PAGE_SIZE (1UL << PMD_SHIFT) -#ifdef __KERNEL__#ifndef __ASSEMBLY__#ifdef CONFIG_X86_USE_3DNOW
include/asm-x86/page_64.h +2 -1
@@ -1,6 +1,8 @@#ifndef _X86_64_PAGE_H#define _X86_64_PAGE_H +#ifdef __KERNEL__ +#include <linux/const.h> /* PAGE_SHIFT determines the page size */
@@ -37,7 +39,6 @@#define HPAGE_MASK (~(HPAGE_SIZE - 1))#define HUGETLB_PAGE_ORDER (HPAGE_SHIFT - PAGE_SHIFT) -#ifdef __KERNEL__#ifndef __ASSEMBLY__extern unsigned long end_pfn;
Signature · 4 lines
Regards, Kirill A. Shutemov + Belarus, Minsk + Velesys LLC, http://www.velesys.com/ + ALT Linux Team, http://www.altlinux.com/
Quoted 2 lines · Kirill A. Shutemov
Userspace should use
getpagesize()orsysconf(_SC_PAGESIZE)to get memory page size.
please go back through the archives and read the history here. we should work at dropping page.h completely, not making it an empty file.
-mike
Quoted 7 lines · Mike Frysinger
Quoted 2 lines · Kirill A. Shutemov
Userspace should use
getpagesize()orsysconf(_SC_PAGESIZE)to get memory page size.please go back through the archives and read the history here. we should work at dropping
page.hcompletely, not making it an empty file.
Do you mean page.h shouldn't be exported to userspace or should be dropped from kernelspace too?
Signature · 4 lines
Regards, Kirill A. Shutemov + Belarus, Minsk + Velesys LLC, http://www.velesys.com/ + ALT Linux Team, http://www.altlinux.com/
Quoted 10 lines · Kirill A. Shutemov
Quoted 7 lines · Mike Frysinger
Quoted 2 lines · Kirill A. Shutemov
Userspace should use
getpagesize()orsysconf(_SC_PAGESIZE)to get memory page size.please go back through the archives and read the history here. we should work at dropping
page.hcompletely, not making it an empty file.Do you mean
page.hshouldn't be exported to userspace
yes
Quoted 1 line
or should be dropped from kernelspace too?
noooooooooooooooooo
;)
-mike