Skip to contentSkip to conversation

rbtree: use designated initializers

PATCH Applied Kees Cook 2 participants 2 messages Dec 17, 2016 Library code

lore
Share & tools
lore

Kees Cook

author
#0 lore raw

PATCH 1/1 rbtree: use designated initializers

Prepare to mark sensitive kernel structures for randomization by making sure they're using designated initializers. These were identified during allyesconfig builds of x86, arm, and arm64, with most initializer fixes extracted from grsecurity.

---
 include/linux/rbtree_augmented.h | 4 +++-
 lib/rbtree.c                     | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/rbtree_augmented.h +3 -1
index d076183e49be..9702b6e183bc 100644
@@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new)	\
 	old->rbaugmented = rbcompute(old);				\
 }									\
 rbstatic const struct rb_augment_callbacks rbname = {			\
-	rbname ## _propagate, rbname ## _copy, rbname ## _rotate	\
+	.propagate = rbname ## _propagate,				\
+	.copy = rbname ## _copy,					\
+	.rotate = rbname ## _rotate					\
 };
 
 
lib/rbtree.c +3 -1
index 1f8b112a7c35..4ba2828a67c0 100644
@@ -427,7 +427,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
 
 static const struct rb_augment_callbacks dummy_callbacks = {
-	dummy_propagate, dummy_copy, dummy_rotate
+	.propagate = dummy_propagate,
+	.copy = dummy_copy,
+	.rotate = dummy_rotate
 };
 
 void rb_insert_color(struct rb_node *node, struct rb_root *root)
Signature · 6 lines
2.7.4


-- 
Kees Cook
Nexus Security
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Kees Cook

Prepare to mark sensitive kernel structures for randomization by making sure they're using designated initializers. These were identified during allyesconfig builds of x86, arm, and arm64, with most initializer fixes extracted from grsecurity.

Works for me.

One note on these structures, the intent is that GCC value propagation completely does away with everything and results in inlining the actual functions. Older versions of GCC had a wee bit of trouble with this, but recent versions do just that, not a single actual structure should end up being emitted in the object code.

Quoted 43 lines
---
 include/linux/rbtree_augmented.h | 4 +++-
 lib/rbtree.c                     | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
include/linux/rbtree_augmented.h +3 -1
index d076183e49be..9702b6e183bc 100644
@@ -90,7 +90,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new)	\
 	old->rbaugmented = rbcompute(old);				\
 }									\
 rbstatic const struct rb_augment_callbacks rbname = {			\
-	rbname ## _propagate, rbname ## _copy, rbname ## _rotate	\
+	.propagate = rbname ## _propagate,				\
+	.copy = rbname ## _copy,					\
+	.rotate = rbname ## _rotate					\
 };
 
 
lib/rbtree.c +3 -1
index 1f8b112a7c35..4ba2828a67c0 100644
@@ -427,7 +427,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
 
 static const struct rb_augment_callbacks dummy_callbacks = {
-	dummy_propagate, dummy_copy, dummy_rotate
+	.propagate = dummy_propagate,
+	.copy = dummy_copy,
+	.rotate = dummy_rotate
 };
 
 void rb_insert_color(struct rb_node *node, struct rb_root *root)
Signature · 6 lines
2.7.4


-- 
Kees Cook
Nexus Security