Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1e74a2eb authored by Linus Torvalds's avatar Linus Torvalds
Browse files

Merge tag 'gcc-plugins-v4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull gcc-plugins updates from Kees Cook:
 "This includes infrastructure updates and the structleak plugin, which
  performs forced initialization of certain structures to avoid possible
  information exposures to userspace.

  Summary:

   - infrastructure updates (gcc-common.h)

   - introduce structleak plugin for forced initialization of some
     structures"

* tag 'gcc-plugins-v4.11-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  gcc-plugins: Add structleak for more stack initialization
  gcc-plugins: consolidate on PASS_INFO macro
  gcc-plugins: add PASS_INFO and build_const_char_string()
parents 7bb03382 c054ee3b
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -410,6 +410,28 @@ config GCC_PLUGIN_LATENT_ENTROPY
	   * https://grsecurity.net/
	   * https://pax.grsecurity.net/

config GCC_PLUGIN_STRUCTLEAK
	bool "Force initialization of variables containing userspace addresses"
	depends on GCC_PLUGINS
	help
	  This plugin zero-initializes any structures that containing a
	  __user attribute. This can prevent some classes of information
	  exposures.

	  This plugin was ported from grsecurity/PaX. More information at:
	   * https://grsecurity.net/
	   * https://pax.grsecurity.net/

config GCC_PLUGIN_STRUCTLEAK_VERBOSE
	bool "Report forcefully initialized variables"
	depends on GCC_PLUGIN_STRUCTLEAK
	depends on !COMPILE_TEST
	help
	  This option will cause a warning to be printed each time the
	  structleak plugin finds a variable it thinks needs to be
	  initialized. Since not all existing initializers are detected
	  by the plugin, this can produce false positive warnings.

config HAVE_CC_STACKPROTECTOR
	bool
	help
+5 −1
Original line number Diff line number Diff line
@@ -27,7 +27,11 @@ extern void __chk_user_ptr(const volatile void __user *);
extern void __chk_io_ptr(const volatile void __iomem *);
# define ACCESS_PRIVATE(p, member) (*((typeof((p)->member) __force *) &(p)->member))
#else /* __CHECKER__ */
# ifdef STRUCTLEAK_PLUGIN
#  define __user __attribute__((user))
# else
#  define __user
# endif
# define __kernel
# define __safe
# define __force
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ ifdef CONFIG_GCC_PLUGINS
    endif
  endif

  gcc-plugin-$(CONFIG_GCC_PLUGIN_STRUCTLEAK)	+= structleak_plugin.so
  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK_VERBOSE)	+= -fplugin-arg-structleak_plugin-verbose
  gcc-plugin-cflags-$(CONFIG_GCC_PLUGIN_STRUCTLEAK)	+= -DSTRUCTLEAK_PLUGIN

  GCC_PLUGINS_CFLAGS := $(strip $(addprefix -fplugin=$(objtree)/scripts/gcc-plugins/, $(gcc-plugin-y)) $(gcc-plugin-cflags-y))

  export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGIN GCC_PLUGIN_SUBDIR
+1 −5
Original line number Diff line number Diff line
@@ -52,12 +52,8 @@ static unsigned int cyc_complexity_execute(void)
__visible int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
{
	const char * const plugin_name = plugin_info->base_name;
	struct register_pass_info cyc_complexity_pass_info;

	cyc_complexity_pass_info.pass				= make_cyc_complexity_pass();
	cyc_complexity_pass_info.reference_pass_name		= "ssa";
	cyc_complexity_pass_info.ref_pass_instance_number	= 1;
	cyc_complexity_pass_info.pos_op				= PASS_POS_INSERT_AFTER;
	PASS_INFO(cyc_complexity, "ssa", 1, PASS_POS_INSERT_AFTER);

	if (!plugin_default_version_check(version, &gcc_version)) {
		error(G_("incompatible gcc/plugin versions"));
+44 −11
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@
#include "except.h"
#include "function.h"
#include "toplev.h"
#if BUILDING_GCC_VERSION >= 5000
#include "expr.h"
#endif
#include "basic-block.h"
#include "intl.h"
#include "ggc.h"
@@ -80,6 +83,9 @@
#include "diagnostic.h"
#include "tree-dump.h"
#include "tree-pass.h"
#if BUILDING_GCC_VERSION >= 4009
#include "pass_manager.h"
#endif
#include "predict.h"
#include "ipa-utils.h"

@@ -119,20 +125,17 @@
#include "builtins.h"
#endif

/* #include "expr.h" where are you... */
extern rtx emit_move_insn(rtx x, rtx y);

/* missing from basic_block.h... */
extern void debug_dominance_info(enum cdi_direction dir);
extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
void debug_dominance_info(enum cdi_direction dir);
void debug_dominance_tree(enum cdi_direction dir, basic_block root);

#if BUILDING_GCC_VERSION == 4006
extern void debug_gimple_stmt(gimple);
extern void debug_gimple_seq(gimple_seq);
extern void print_gimple_seq(FILE *, gimple_seq, int, int);
extern void print_gimple_stmt(FILE *, gimple, int, int);
extern void print_gimple_expr(FILE *, gimple, int, int);
extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
void debug_gimple_stmt(gimple);
void debug_gimple_seq(gimple_seq);
void print_gimple_seq(FILE *, gimple_seq, int, int);
void print_gimple_stmt(FILE *, gimple, int, int);
void print_gimple_expr(FILE *, gimple, int, int);
void dump_gimple_stmt(pretty_printer *, gimple, int, int);
#endif

#define __unused __attribute__((__unused__))
@@ -146,6 +149,29 @@ extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
/* should come from c-tree.h if only it were installed for gcc 4.5... */
#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)

static inline tree build_const_char_string(int len, const char *str)
{
	tree cstr, elem, index, type;

	cstr = build_string(len, str);
	elem = build_type_variant(char_type_node, 1, 0);
	index = build_index_type(size_int(len - 1));
	type = build_array_type(elem, index);
	TREE_TYPE(cstr) = type;
	TREE_CONSTANT(cstr) = 1;
	TREE_READONLY(cstr) = 1;
	TREE_STATIC(cstr) = 1;
	return cstr;
}

#define PASS_INFO(NAME, REF, ID, POS)		\
struct register_pass_info NAME##_pass_info = {	\
	.pass = make_##NAME##_pass(),		\
	.reference_pass_name = REF,		\
	.ref_pass_instance_number = ID,		\
	.pos_op = POS,				\
}

#if BUILDING_GCC_VERSION == 4005
#define FOR_EACH_LOCAL_DECL(FUN, I, D)			\
	for (tree vars = (FUN)->local_decls, (I) = 0;	\
@@ -527,6 +553,8 @@ static inline const greturn *as_a_const_greturn(const_gimple stmt)
#define section_name_prefix LTO_SECTION_NAME_PREFIX
#define fatal_error(loc, gmsgid, ...) fatal_error((gmsgid), __VA_ARGS__)

rtx emit_move_insn(rtx x, rtx y);

typedef struct rtx_def rtx_insn;

static inline const char *get_decl_section_name(const_tree decl)
@@ -643,6 +671,11 @@ static inline const greturn *as_a_const_greturn(const_gimple stmt)
#define NODE_DECL(node) (node)->decl
#define cgraph_node_name(node) (node)->name()
#define NODE_IMPLICIT_ALIAS(node) (node)->cpp_implicit_alias

static inline opt_pass *get_pass_for_id(int id)
{
	return g->get_passes()->get_pass_for_id(id);
}
#endif

#if BUILDING_GCC_VERSION >= 5000 && BUILDING_GCC_VERSION < 6000
Loading