Provide linux/set_memory.h
Subsystems (4)
RFC PATCH 1/4 Provide linux/set_memory.h
Currently code that wants to use set_memory_ro() etc, needs to include asm/set_memory.h, which doesn't exist on all arches. Some code knows it only builds on arches which have the header, other code guards the inclusion with an #ifdef, neither is ideal.
So create linux/set_memory.h. This always exists, so users don't need an #ifdef just to include the header.
When CONFIG_ARCH_HAS_SET_MEMORY=y it includes asm/set_memory.h, otherwise it provides empty non-failing implementations.
--- include/linux/set_memory.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 include/linux/set_memory.h
Does this look OK to people? If so it would be great if someone, Kees?, Andrew?, could pick up patch 1 (it's a nop by itself) and then we can send the conversions separately later in the merge window?
cheers
include/linux/set_memory.h new file +20 -0
@@ -0,0 +1,20 @@ +/* +* Copyright 2017, Michael Ellerman, IBM Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version +* 2 as published by the Free Software Foundation; +*/ +#ifndef _LINUX_SET_MEMORY_H_ +#define _LINUX_SET_MEMORY_H_ + +#ifdef CONFIG_ARCH_HAS_SET_MEMORY +#include <asm/set_memory.h> +#else +static inline int set_memory_ro (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_rw (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_x (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; } +#endif + +#endif /* _LINUX_SET_MEMORY_H_ */
Signature · 1 line
2.7.4
RFC PATCH 2/4 PM / hibernate: Use linux/set_memory.h
This header always exists, so doesn't require an ifdef around its inclusion. When CONFIG_ARCH_HAS_SET_MEMORY=y it includes the asm header, otherwise it provides empty versions of the set_memory_xx() routines.
--- kernel/power/snapshot.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/power/snapshot.c +1 -3
@@ -30,15 +30,13 @@#include <linux/slab.h> #include <linux/compiler.h> #include <linux/ktime.h> +#include <linux/set_memory.h> #include <linux/uaccess.h> #include <asm/mmu_context.h> #include <asm/pgtable.h> #include <asm/tlbflush.h> #include <asm/io.h> -#ifdef CONFIG_ARCH_HAS_SET_MEMORY -#include <asm/set_memory.h> -#endif #include "power.h"
Signature · 1 line
2.7.4
RFC PATCH 3/4 module: Use linux/set_memory.h
In reply to Michael EllermanThis header always exists, so doesn't require an ifdef around its inclusion. When CONFIG_ARCH_HAS_SET_MEMORY=y it includes the asm header, otherwise it provides empty versions of the set_memory_xx() routines.
The usages of set_memory_xx() are still guarded by CONFIG_STRICT_MODULE_RWX.
--- kernel/module.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
kernel/module.c +1 -3
@@ -49,9 +49,7 @@#include <linux/rculist.h> #include <linux/uaccess.h> #include <asm/cacheflush.h> -#ifdef CONFIG_STRICT_MODULE_RWX -#include <asm/set_memory.h> -#endif +#include <linux/set_memory.h> #include <asm/mmu_context.h> #include <linux/license.h> #include <asm/sections.h>
Signature · 1 line
2.7.4
RFC PATCH 4/4 bpf: Use linux/set_memory.h
In reply to Michael EllermanThis header always exists, so doesn't require an ifdef around its inclusion. When CONFIG_ARCH_HAS_SET_MEMORY=y it includes the asm header, otherwise it provides empty versions of the set_memory_xx() routines.
--- include/linux/filter.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
include/linux/filter.h +1 -4
@@ -16,13 +16,10 @@#include <linux/sched.h> #include <linux/capability.h> #include <linux/cryptohash.h> +#include <linux/set_memory.h> #include <net/sch_generic.h> -#ifdef CONFIG_ARCH_HAS_SET_MEMORY -#include <asm/set_memory.h> -#endif -#include <uapi/linux/filter.h> #include <uapi/linux/bpf.h>
Signature · 1 line
2.7.4
Re: [kernel-hardening] [RFC PATCH 4/4] bpf: Use linux/set_memory.h
Quoted 5 lines · Michael Ellerman
This header always exists, so doesn't require an ifdef around its inclusion. When
CONFIG_ARCH_HAS_SET_MEMORY=yit includes the asm header, otherwise it provides empty versions of theset_memory_xx()routines.Signed-off-by Michael Ellerman <[email protected]>
Quoted 5 lines · Michael Ellerman
Currently code that wants to use
set_memory_ro()etc, needs to includeasm/set_memory.h, which doesn't exist on all arches. Some code knows it only builds on arches which have the header, other code guards the inclusion with an #ifdef, neither is ideal.
Quoted 7 lines
So create
linux/set_memory.h. This always exists, so users don't need an #ifdef just to include the header.When
CONFIG_ARCH_HAS_SET_MEMORY=yit includesasm/set_memory.h, otherwise it provides empty non-failing implementations.Signed-off-by Michael Ellerman <[email protected]>
Looks good to me, thanks!
I'm fine if Andrew or Kees picks up the bpf patch as well, I think there shouldn't be any conflict with net-next on this one (and even if so, then looks trivial to resolve).
Kees Cook
Acked-byQuoted 16 lines · Daniel Borkmann
Quoted 6 lines · Michael Ellerman
Currently code that wants to use
set_memory_ro()etc, needs to includeasm/set_memory.h, which doesn't exist on all arches. Some code knows it only builds on arches which have the header, other code guards the inclusion with an #ifdef, neither is ideal.Quoted 7 lines
So create
linux/set_memory.h. This always exists, so users don't need an #ifdef just to include the header.When
CONFIG_ARCH_HAS_SET_MEMORY=yit includesasm/set_memory.h, otherwise it provides empty non-failing implementations.Signed-off-by Michael Ellerman <[email protected]>
Quoted 7 lines
Looks good to me, thanks!
Acked-by Daniel Borkmann <[email protected]>I'm fine if Andrew or Kees picks up the bpf patch as well, I think there shouldn't be any conflict with net-next on this one (and even if so, then looks trivial to resolve).
I nominate Andrew. ;) This should go in early in the merge window and the users can go late in the window. If Andrew has enough to do, I can carry it too; just say the word.
This is a sane addition and allows for lines-of-code reduction in a few places. Thanks!
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Quoted 25 lines · Kees Cook
Quoted 16 lines · Daniel Borkmann
Quoted 6 lines · Michael Ellerman
Currently code that wants to use
set_memory_ro()etc, needs to includeasm/set_memory.h, which doesn't exist on all arches. Some code knows it only builds on arches which have the header, other code guards the inclusion with an #ifdef, neither is ideal.Quoted 7 lines
So create
linux/set_memory.h. This always exists, so users don't need an #ifdef just to include the header.When
CONFIG_ARCH_HAS_SET_MEMORY=yit includesasm/set_memory.h, otherwise it provides empty non-failing implementations.Signed-off-by Michael Ellerman <[email protected]>Quoted 7 lines
Looks good to me, thanks!
Acked-by Daniel Borkmann <[email protected]>I'm fine if Andrew or Kees picks up the bpf patch as well, I think there shouldn't be any conflict with net-next on this one (and even if so, then looks trivial to resolve).
Quoted 6 lines
I nominate Andrew. ;) This should go in early in the merge window and the users can go late in the window. If Andrew has enough to do, I can carry it too; just say the word.
This is a sane addition and allows for lines-of-code reduction in a few places. Thanks!
Andrew's picked them up in mmotm, thanks everyone.
cheers
Quoted 18 lines · Michael Ellerman
Currently code that wants to use
set_memory_ro()etc, needs to includeasm/set_memory.h, which doesn't exist on all arches. Some code knows it only builds on arches which have the header, other code guards the inclusion with an #ifdef, neither is ideal.So create
linux/set_memory.h. This always exists, so users don't need an #ifdef just to include the header.When
CONFIG_ARCH_HAS_SET_MEMORY=yit includesasm/set_memory.h, otherwise it provides empty non-failing implementations.Signed-off-by Michael Ellerman <[email protected]>--- include/linux/set_memory.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 include/linux/set_memory.h
Quoted 4 lines
Does this look OK to people? If so it would be great if someone, Kees?, Andrew?, could pick up patch 1 (it's a nop by itself) and then we can send the conversions separately later in the merge window?
Quoted 29 lines
cheers
include/linux/set_memory.h new file +20
-0@@ -0,0 +1,20 @@ +/* +* Copyright 2017, Michael Ellerman, IBM Corporation. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License version +* 2 as published by the Free Software Foundation; +*/ +#ifndef _LINUX_SET_MEMORY_H_ +#define _LINUX_SET_MEMORY_H_ + +#ifdef CONFIG_ARCH_HAS_SET_MEMORY +#include <asm/set_memory.h> +#else +static inline int set_memory_ro (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_rw (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_x (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; } +#endif + +#endif /* _LINUX_SET_MEMORY_H_ */