Skip to contentSkip to conversation

mm/slab: remove HAVE_HARDENED_USERCOPY_ALLOCATOR

PATCH In review Vlastimil Babka 6 participants 11 messages May 23, 2023 – May 24, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/slab: remove HAVE_HARDENED_USERCOPY_ALLOCATOR

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
 mm/Kconfig       | 2 --
 mm/slab.h        | 9 ---------
 security/Kconfig | 8 --------
 3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
 config SLAB
 	bool "SLAB"
 	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	  The regular slab allocator that is established and known to work
 	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
 config SLUB
 	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	   SLUB is a slab allocator that minimizes cache line usage
 	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -9
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
 void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
 #endif
 
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
 void __check_heap_object(const void *ptr, unsigned long n,
 			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif
-
 #ifdef CONFIG_SLUB_DEBUG
 void skip_orig_size_check(struct kmem_cache *s, const void *object);
 #endif
security/Kconfig +0 -8
index 97abeb9b9a19..52c9af08ad35 100644
@@ -127,16 +127,8 @@ config LSM_MMAP_MIN_ADDR
 	  this low address space will need the permission specific to the
 	  systems running LSM.
 
-config HAVE_HARDENED_USERCOPY_ALLOCATOR
-	bool
-	help
-	  The heap allocator implements __check_heap_object() for
-	  validating memory ranges against heap object sizes in
-	  support of CONFIG_HARDENED_USERCOPY.
-
 config HARDENED_USERCOPY
 	bool "Harden memory copies between kernel and userspace"
-	depends on HAVE_HARDENED_USERCOPY_ALLOCATOR
 	imply STRICT_DEVMEM
 	help
 	  This option checks for obviously wrong memory regions when
Signature · 1 line
2.40.1
#1 lore raw
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
 mm/Kconfig       | 2 --
 mm/slab.h        | 9 ---------
 security/Kconfig | 8 --------
 3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
 config SLAB
 	bool "SLAB"
 	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	  The regular slab allocator that is established and known to work
 	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
 config SLUB
 	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	   SLUB is a slab allocator that minimizes cache line usage
 	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
 void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
 #endif
 

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
 void __check_heap_object(const void *ptr, unsigned long n,
 			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype? Perhaps replacing with #ifdef CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Quoted 28 lines
mm/slab.h +0 -1
-
 #ifdef CONFIG_SLUB_DEBUG
 void skip_orig_size_check(struct kmem_cache *s, const void *object);
 #endif
security/Kconfig +0 -9
index 97abeb9b9a19..52c9af08ad35 100644
@@ -127,16 +127,8 @@ config LSM_MMAP_MIN_ADDR
 	  this low address space will need the permission specific to the
 	  systems running LSM.
 
-config HAVE_HARDENED_USERCOPY_ALLOCATOR
-	bool
-	help
-	  The heap allocator implements __check_heap_object() for
-	  validating memory ranges against heap object sizes in
-	  support of CONFIG_HARDENED_USERCOPY.
-
 config HARDENED_USERCOPY
 	bool "Harden memory copies between kernel and userspace"
-	depends on HAVE_HARDENED_USERCOPY_ALLOCATOR
 	imply STRICT_DEVMEM
 	help
 	  This option checks for obviously wrong memory regions when
--

2.40.1

#2 lore raw
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
 mm/Kconfig       | 2 --
 mm/slab.h        | 9 ---------
 security/Kconfig | 8 --------
 3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
 config SLAB
 	bool "SLAB"
 	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	  The regular slab allocator that is established and known to work
 	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
 config SLUB
 	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	   SLUB is a slab allocator that minimizes cache line usage
 	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
 void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
 #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
 void __check_heap_object(const void *ptr, unsigned long n,
 			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

#3 lore raw
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
 mm/Kconfig       | 2 --
 mm/slab.h        | 9 ---------
 security/Kconfig | 8 --------
 3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
 config SLAB
 	bool "SLAB"
 	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	  The regular slab allocator that is established and known to work
 	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
 config SLUB
 	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
 	help
 	   SLUB is a slab allocator that minimizes cache line usage
 	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
 void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
 #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
 void __check_heap_object(const void *ptr, unsigned long n,
 			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

Reviewed-by
#4 lore raw
Quoted 66 lines · Lorenzo Stoakes
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
  mm/Kconfig       | 2 --
  mm/slab.h        | 9 ---------
  security/Kconfig | 8 --------
  3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
  config SLAB
  	bool "SLAB"
  	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	  The regular slab allocator that is established and known to work
  	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
  config SLUB
  	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	   SLUB is a slab allocator that minimizes cache line usage
  	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
  void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
  #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
  void __check_heap_object(const void *ptr, unsigned long n,
  			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Quoted 7 lines

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Signature · 3 lines
Thanks,

David / dhildenb
#5 lore raw
Quoted 75 lines · David Hildenbrand
Quoted 66 lines · Lorenzo Stoakes
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
  mm/Kconfig       | 2 --
  mm/slab.h        | 9 ---------
  security/Kconfig | 8 --------
  3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
  config SLAB
  	bool "SLAB"
  	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	  The regular slab allocator that is established and known to work
  	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
  config SLUB
  	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	   SLUB is a slab allocator that minimizes cache line usage
  	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
  void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
  #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
  void __check_heap_object(const void *ptr, unsigned long n,
  			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Quoted 7 lines

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

Quoted 4 lines

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Yeah ugh at this sort of implicit thing. Anyway it'd be preferable to stick #ifdef CONFIG_HARDENED_USERCOPY around the prototype just so it's abundantly clear this function doesn't exist unless that is set.

Quoted 9 lines

--
Thanks,

David / dhildenb

#6 lore raw
Quoted 76 lines · Lorenzo Stoakes
Quoted 75 lines · David Hildenbrand
Quoted 73 lines · Lorenzo Stoakes
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
   mm/Kconfig       | 2 --
   mm/slab.h        | 9 ---------
   security/Kconfig | 8 --------
   3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
   config SLAB
   	bool "SLAB"
   	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
   	help
   	  The regular slab allocator that is established and known to work
   	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
   config SLUB
   	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
   	help
   	   SLUB is a slab allocator that minimizes cache line usage
   	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
   void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
   #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
   void __check_heap_object(const void *ptr, unsigned long n,
   			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

Quoted 8 lines
Quoted 4 lines

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Yeah ugh at this sort of implicit thing. Anyway it'd be preferable to stick #ifdef CONFIG_HARDENED_USERCOPY around the prototype just so it's abundantly clear this function doesn't exist unless that is set.

I recall that it is very common to not use ifdefs unless really required. Because less ifefs are obviously preferable ;)

Compilation+linking will fail in any case.

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by
#7 lore raw

On Tue, May 23, 2023 at 10:28:32AM +0200, David Hildenbrand wrote:
[snip]

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Quoted 9 lines
Quoted 3 lines

Yeah ugh at this sort of implicit thing. Anyway it'd be preferable to stick #ifdef CONFIG_HARDENED_USERCOPY around the prototype just so it's abundantly clear this function doesn't exist unless that is set.

I recall that it is very common to not use ifdefs unless really required. Because less ifefs are obviously preferable ;)

Compilation+linking will fail in any case.

I don't want to insist so hard on something that doesn't really matter, the bike shed can be blue, green or red it's fine :P

So,

Reviewed-by
#8 lore raw
In reply to David Hildenbrand
Quoted 75 lines · David Hildenbrand
Quoted 66 lines · Lorenzo Stoakes
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
  mm/Kconfig       | 2 --
  mm/slab.h        | 9 ---------
  security/Kconfig | 8 --------
  3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
  config SLAB
  	bool "SLAB"
  	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	  The regular slab allocator that is established and known to work
  	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
  config SLUB
  	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	   SLUB is a slab allocator that minimizes cache line usage
  	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
  void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
  #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
  void __check_heap_object(const void *ptr, unsigned long n,
  			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Quoted 7 lines

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

Quoted 3 lines

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Right.

Quoted 1 line

Thanks!

Signature · 1 line
Kees Cook
reviewer Acked-by
#9 lore raw
Quoted 80 lines · Kees Cook
Quoted 75 lines · David Hildenbrand
Quoted 66 lines · Lorenzo Stoakes
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
  mm/Kconfig       | 2 --
  mm/slab.h        | 9 ---------
  security/Kconfig | 8 --------
  3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
  config SLAB
  	bool "SLAB"
  	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	  The regular slab allocator that is established and known to work
  	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
  config SLUB
  	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	   SLUB is a slab allocator that minimizes cache line usage
  	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
  void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
  #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
  void __check_heap_object(const void *ptr, unsigned long n,
  			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Quoted 7 lines

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

Quoted 3 lines

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Quoted 8 lines

Right.

Quoted 1 line

Thanks!

Acked-by
#10 lore raw
Quoted 84 lines · David Rientjes
Quoted 82 lines · Kees Cook
Quoted 75 lines · David Hildenbrand
Quoted 66 lines · Lorenzo Stoakes
Quoted 57 lines · Vlastimil Babka
Quoted 39 lines · Lorenzo Stoakes
Quoted 38 lines · Vlastimil Babka

With SLOB removed, both remaining allocators support hardened usercopy, so remove the config and associated #ifdef.

---
  mm/Kconfig       | 2 --
  mm/slab.h        | 9 ---------
  security/Kconfig | 8 --------
  3 files changed, 19 deletions(-)
mm/Kconfig +0 -2
index 7672a22647b4..041f0da42f2b 100644
@@ -221,7 +221,6 @@ choice
  config SLAB
  	bool "SLAB"
  	depends on !PREEMPT_RT
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	  The regular slab allocator that is established and known to work
  	  well in all environments. It organizes cache hot objects in
@@ -229,7 +228,6 @@ config SLAB
 
  config SLUB
  	bool "SLUB (Unqueued Allocator)"
-	select HAVE_HARDENED_USERCOPY_ALLOCATOR
  	help
  	   SLUB is a slab allocator that minimizes cache line usage
  	   instead of managing queues of cached objects (SLAB approach).
mm/slab.h +0 -0
index f01ac256a8f5..695ef96b4b5b 100644
@@ -832,17 +832,8 @@ struct kmem_obj_info {
  void __kmem_obj_info(struct kmem_obj_info *kpp, void *object, struct slab *slab);
  #endif
 
Quoted 13 lines

mm/slab.h struct kmem_obj_info { · line 844

Quoted 10 lines
mm/slab.h +0 -8
-#ifdef CONFIG_HAVE_HARDENED_USERCOPY_ALLOCATOR
  void __check_heap_object(const void *ptr, unsigned long n,
  			 const struct slab *slab, bool to_user);
-#else
-static inline
-void __check_heap_object(const void *ptr, unsigned long n,
-			 const struct slab *slab, bool to_user)
-{
-}
-#endif

Hm, this is still defined in slab.c/slub.c and invoked in usercopy.c, do we not want the prototype?

Well I didn't delete the prototype, just the ifdef/else around, so now it's there unconditionally.

Quoted 7 lines
Quoted 2 lines

Perhaps replacing with #ifdef
CONFIG_HARDENED_USERCOPY instead? I may be missing something here :)

Putting it under that #ifdef would work and match that the implementations of that function are under that same ifdef, but maybe it's unnecessary noise in the header?

Quoted 7 lines

Yeah my brain inserted extra '-'s there, sorry!

Given we only define __check_heap_object() in sl[au]b.c if CONFIG_HARDENED_USERCOPY wouldn't we need to keep the empty version around if !CONFIG_HARDENED_USERCOPY since check_heap_object() appears to be called unconditionally?

Quoted 3 lines

The file is only compiled with CONFIG_HARDENED_USERCOPY:

mm/Makefile:obj-$(CONFIG_HARDENED_USERCOPY) += usercopy.o

Right.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Thanks!

looks fine to me,

Signature · 5 lines
Hyeonggon Yoo

Doing kernel stuff as a hobby
Undergraduate | Chungnam National University
Dept. Computer Science & Engineering