+ mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9.patch added to -mm tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The patch titled
     Subject: mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9
has been added to the -mm tree.  Its filename is
     mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9.patch

This patch should soon appear at
    http://ozlabs.org/~akpm/mmots/broken-out/mm-security-introduce-init_on_alloc%3D1-and-init_on_free%3D1-boot-options-v9.patch
and later at
    http://ozlabs.org/~akpm/mmotm/broken-out/mm-security-introduce-init_on_alloc%3D1-and-init_on_free%3D1-boot-options-v9.patch

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next and is updated
there every 3-4 working days

------------------------------------------------------
From: Alexander Potapenko <glider@xxxxxxxxxx>
Subject: mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9

  - picked up -mm fixes from Qian Cai and Andrew Morton (order of calls
    in free_pages_prepare(), export init_on_alloc)
  - exported init_on_free
  - allowed using init_on_alloc/init_on_free with SLUB poisoning and
    page poisoning. Poisoning supersedes zero-initialization, so some
    tests may behave differently with poisoning enabled.

Link: http://lkml.kernel.org/r/20190627130316.254309-2-glider@xxxxxxxxxx
Signed-off-by: Alexander Potapenko <glider@xxxxxxxxxx>
Acked-by: Kees Cook <keescook@xxxxxxxxxxxx>
Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
---

 include/linux/mm.h |    6 ++++--
 mm/page_alloc.c    |   18 +++++++++---------
 mm/slab.h          |    5 +++--
 mm/slub.c          |    4 +---
 4 files changed, 17 insertions(+), 16 deletions(-)

--- a/include/linux/mm.h~mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9
+++ a/include/linux/mm.h
@@ -2685,7 +2685,8 @@ DECLARE_STATIC_KEY_FALSE(init_on_alloc);
 #endif
 static inline bool want_init_on_alloc(gfp_t flags)
 {
-	if (static_branch_unlikely(&init_on_alloc))
+	if (static_branch_unlikely(&init_on_alloc) &&
+	    !page_poisoning_enabled())
 		return true;
 	return flags & __GFP_ZERO;
 }
@@ -2697,7 +2698,8 @@ DECLARE_STATIC_KEY_FALSE(init_on_free);
 #endif
 static inline bool want_init_on_free(void)
 {
-	return static_branch_unlikely(&init_on_free);
+	return static_branch_unlikely(&init_on_free) &&
+	       !page_poisoning_enabled();
 }
 
 #ifdef CONFIG_DEBUG_PAGEALLOC_ENABLE_DEFAULT
--- a/mm/page_alloc.c~mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9
+++ a/mm/page_alloc.c
@@ -140,11 +140,14 @@ DEFINE_STATIC_KEY_TRUE(init_on_alloc);
 #else
 DEFINE_STATIC_KEY_FALSE(init_on_alloc);
 #endif
+EXPORT_SYMBOL(init_on_alloc);
+
 #ifdef CONFIG_INIT_ON_FREE_DEFAULT_ON
 DEFINE_STATIC_KEY_TRUE(init_on_free);
 #else
 DEFINE_STATIC_KEY_FALSE(init_on_free);
 #endif
+EXPORT_SYMBOL(init_on_free);
 
 static int __init early_init_on_alloc(char *buf)
 {
@@ -154,10 +157,8 @@ static int __init early_init_on_alloc(ch
 	if (!buf)
 		return -EINVAL;
 	ret = kstrtobool(buf, &bool_result);
-	if (bool_result && IS_ENABLED(CONFIG_PAGE_POISONING)) {
-		pr_warn("mem auto-init: Disabling init_on_alloc: CONFIG_PAGE_POISONING is on\n");
-		bool_result = false;
-	}
+	if (bool_result && IS_ENABLED(CONFIG_PAGE_POISONING))
+		pr_warn("mem auto-init: CONFIG_PAGE_POISONING is on, will take precedence over init_on_alloc\n");
 	if (bool_result)
 		static_branch_enable(&init_on_alloc);
 	else
@@ -174,10 +175,8 @@ static int __init early_init_on_free(cha
 	if (!buf)
 		return -EINVAL;
 	ret = kstrtobool(buf, &bool_result);
-	if (bool_result && IS_ENABLED(CONFIG_PAGE_POISONING)) {
-		pr_warn("mem auto-init: Disabling init_on_free: CONFIG_PAGE_POISONING is on\n");
-		bool_result = false;
-	}
+	if (bool_result && IS_ENABLED(CONFIG_PAGE_POISONING))
+		pr_warn("mem auto-init: CONFIG_PAGE_POISONING is on, will take precedence over init_on_free\n");
 	if (bool_result)
 		static_branch_enable(&init_on_free);
 	else
@@ -1179,9 +1178,10 @@ static __always_inline bool free_pages_p
 					   PAGE_SIZE << order);
 	}
 	arch_free_page(page, order);
-	kernel_poison_pages(page, 1 << order, 0);
 	if (want_init_on_free())
 		kernel_init_free_pages(page, 1 << order);
+
+	kernel_poison_pages(page, 1 << order, 0);
 	if (debug_pagealloc_enabled())
 		kernel_map_pages(page, 1 << order, 0);
 
--- a/mm/slab.h~mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9
+++ a/mm/slab.h
@@ -612,7 +612,7 @@ static inline bool slab_want_init_on_all
 	if (static_branch_unlikely(&init_on_alloc)) {
 		if (c->ctor)
 			return false;
-		if (c->flags & SLAB_TYPESAFE_BY_RCU)
+		if (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON))
 			return flags & __GFP_ZERO;
 		return true;
 	}
@@ -622,7 +622,8 @@ static inline bool slab_want_init_on_all
 static inline bool slab_want_init_on_free(struct kmem_cache *c)
 {
 	if (static_branch_unlikely(&init_on_free))
-		return !(c->ctor || (c->flags & SLAB_TYPESAFE_BY_RCU));
+		return !(c->ctor ||
+			 (c->flags & (SLAB_TYPESAFE_BY_RCU | SLAB_POISON)));
 	return false;
 }
 
--- a/mm/slub.c~mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9
+++ a/mm/slub.c
@@ -1282,9 +1282,7 @@ out:
 	if ((static_branch_unlikely(&init_on_alloc) ||
 	     static_branch_unlikely(&init_on_free)) &&
 	    (slub_debug & SLAB_POISON)) {
-		pr_warn("mem auto-init: Disabling init_on_alloc/init_on_free: can't be used together with SLAB_POISON\n");
-		static_branch_disable(&init_on_alloc);
-		static_branch_disable(&init_on_free);
+		pr_warn("mem auto-init: SLAB_POISON will take precedence over init_on_alloc/init_on_free\n");
 	}
 	return 1;
 }
_

Patches currently in -mm which might be from glider@xxxxxxxxxx are

mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options.patch
mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v8.patch
mm-security-introduce-init_on_alloc=1-and-init_on_free=1-boot-options-v9.patch
mm-init-report-memory-auto-initialization-features-at-boot-time.patch
lib-introduce-test_meminit-module.patch
lib-test_meminitc-minor-test-fixes.patch




[Index of Archives]     [Kernel Archive]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]

  Powered by Linux