|
|
Message-Id: <20190410131726.250295-4-glider@google.com>
Date: Wed, 10 Apr 2019 15:17:26 +0200
From: Alexander Potapenko <glider@...gle.com>
To: yamada.masahiro@...ionext.com, jmorris@...ei.org, serge@...lyn.com
Cc: linux-security-module@...r.kernel.org, linux-kbuild@...r.kernel.org,
ndesaulniers@...gle.com, kcc@...gle.com, dvyukov@...gle.com,
keescook@...omium.org, sspatil@...roid.com, labbott@...hat.com,
kernel-hardening@...ts.openwall.com
Subject: [PATCH 3/3] net: make sk_prot_alloc() work with CONFIG_INIT_ALL_HEAP
Rename sk_prot_clear_nulls() to sk_prot_clear() and introduce an extra
init_byte parameter to be passed to memset() when initializing struct sock.
In the case CONFIG_INIT_ALL_HEAP is on, initialize newly created struct
sock with 0xAA.
Signed-off-by: Alexander Potapenko <glider@...gle.com>
Cc: Eric Dumazet <edumazet@...gle.com>
Cc: David S. Miller <davem@...emloft.net>
Cc: Masahiro Yamada <yamada.masahiro@...ionext.com>
Cc: James Morris <jmorris@...ei.org>
Cc: "Serge E. Hallyn" <serge@...lyn.com>
Cc: Nick Desaulniers <ndesaulniers@...gle.com>
Cc: Kostya Serebryany <kcc@...gle.com>
Cc: Dmitry Vyukov <dvyukov@...gle.com>
Cc: Kees Cook <keescook@...omium.org>
Cc: Sandeep Patil <sspatil@...roid.com>
Cc: Laura Abbott <labbott@...hat.com>
Cc: Randy Dunlap <rdunlap@...radead.org>
Cc: Jann Horn <jannh@...gle.com>
Cc: Mark Rutland <mark.rutland@....com>
Cc: linux-security-module@...r.kernel.org
Cc: netdev@...r.kernel.org
Cc: linux-kbuild@...r.kernel.org
Cc: kernel-hardening@...ts.openwall.com
---
include/net/sock.h | 8 ++++----
net/core/sock.c | 5 +++--
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/include/net/sock.h b/include/net/sock.h
index 8de5ee258b93..a49c1f1c71c1 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -1044,13 +1044,13 @@ struct module;
/*
* caches using SLAB_TYPESAFE_BY_RCU should let .next pointer from nulls nodes
- * un-modified. Special care is taken when initializing object to zero.
+ * un-modified. Special care is taken when initializing object.
*/
-static inline void sk_prot_clear_nulls(struct sock *sk, int size)
+static inline void sk_prot_clear(struct sock *sk, int size, int init_byte)
{
if (offsetof(struct sock, sk_node.next) != 0)
- memset(sk, 0, offsetof(struct sock, sk_node.next));
- memset(&sk->sk_node.pprev, 0,
+ memset(sk, init_byte, offsetof(struct sock, sk_node.next));
+ memset(&sk->sk_node.pprev, init_byte,
size - offsetof(struct sock, sk_node.pprev));
}
diff --git a/net/core/sock.c b/net/core/sock.c
index 782343bb925b..1ad855e99512 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1601,8 +1601,9 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
sk = kmem_cache_alloc(slab, priority & ~__GFP_ZERO);
if (!sk)
return sk;
- if (priority & __GFP_ZERO)
- sk_prot_clear_nulls(sk, prot->obj_size);
+ if (GFP_INIT_ALWAYS_ON || (priority & __GFP_ZERO))
+ sk_prot_clear(sk, prot->obj_size,
+ INITMEM_FILL_BYTE(priority));
} else
sk = kmalloc(prot->obj_size, priority);
--
2.21.0.392.gf8f6787159e-goog
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.