Skip to content

gcc-plugins: Introduce stackinit plugin

Kees Cook dri-devel intel-gfx intel-wired-lan kernel-hardening linux-fsdevel linux-kbuild linux-mm linux-security-module linux-usb lkml netdev xen-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest3 patches 32 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3treewide: Lift switch variables out of switchesarch/x86/xen/enlighten_pv.c drivers/char/pcmcia/cm4000_cs.c drivers/char/ppdev.c +15 more+45 -4627 replies
1/3treewide: Lift switch variables out of switchesarch/x86/xen/enlighten_pv.c drivers/char/pcmcia/cm4000_cs.c drivers/char/ppdev.c +15 more+45 -460 replies
2/3gcc-plugins: Introduce stackinit pluginscripts/Makefile.gcc-plugins scripts/gcc-plugins/Kconfig scripts/gcc-plugins/gcc-common.h +1 more+102 -30 replies
2/3gcc-plugins: Introduce stackinit pluginscripts/Makefile.gcc-plugins scripts/gcc-plugins/Kconfig scripts/gcc-plugins/gcc-common.h +1 more+102 -30 replies
3/3lib: Introduce test_stackinit modulelib/Kconfig.debug lib/Makefile lib/test_stackinit.c+337 -00 replies
3/3lib: Introduce test_stackinit modulelib/Kconfig.debug lib/Makefile lib/test_stackinit.c+337 -00 replies

Reviews trailers per patch

2 of 6 patches have a Reviewed-by or Acked-by.

PatchJani NikulaJeff Kirsher
1/3R-b A-b R-b A-b A-b A-b
1/3R-b A-b R-b A-b A-b A-b
2/3
2/3
3/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/3] gcc-plugins: Introduce stackinit plugin

This adds a new plugin "stackinit" that attempts to perform unconditional initialization of all stack variables[1]. It has wider effects than GCC_PLUGIN_STRUCTLEAK_BYREF_ALL=y since BYREF_ALL does not consider non-structures. A notable weakness is that padding bytes in many cases remain uninitialized since GCC treats these bytes as "undefined". I'm hoping we can improve the compiler (or the plugin) to cover that too. (It's worth noting that BYREF_ALL actually does handle the padding -- I think this is due to the different method of detecting if initialization is needed.)

Included is a tree-wide change to move switch variables up and out of their switch and into the top-level variable declarations.

Included is a set of test cases for evaluating stack initialization, which checks for padding, different types, etc.

Feedback welcome! :)

-Kees

[1] https://lkml.kernel.org/r/CA+55aFykZL+cSBJjBBts7ebEFfyGPdMzTmLSxKnT_29=j942dA@mail.gmail.com

Kees Cook (3):
treewide: Lift switch variables out of switches
gcc-plugins: Introduce stackinit plugin
lib: Introduce test_stackinit module

 arch/x86/xen/enlighten_pv.c                   |   7 +-
 drivers/char/pcmcia/cm4000_cs.c               |   2 +-
 drivers/char/ppdev.c                          |  20 +-
 drivers/gpu/drm/drm_edid.c                    |   4 +-
 drivers/gpu/drm/i915/intel_display.c          |   2 +-
 drivers/gpu/drm/i915/intel_pm.c               |   4 +-
 drivers/net/ethernet/intel/e1000/e1000_main.c |   3 +-
 drivers/tty/n_tty.c                           |   3 +-
 drivers/usb/gadget/udc/net2280.c              |   5 +-
 fs/fcntl.c                                    |   3 +-
 lib/Kconfig.debug                             |   9 +
 lib/Makefile                                  |   1 +
 lib/test_stackinit.c                          | 327 ++++++++++++++++++
 mm/shmem.c                                    |   5 +-
 net/core/skbuff.c                             |   4 +-
 net/ipv6/ip6_gre.c                            |   4 +-
 net/ipv6/ip6_tunnel.c                         |   4 +-
 net/openvswitch/flow_netlink.c                |   7 +-
 scripts/Makefile.gcc-plugins                  |   6 +
 scripts/gcc-plugins/Kconfig                   |   9 +
 scripts/gcc-plugins/gcc-common.h              |  11 +-
 scripts/gcc-plugins/stackinit_plugin.c        |  79 +++++
 security/tomoyo/common.c                      |   3 +-
 security/tomoyo/condition.c                   |   7 +-
 security/tomoyo/util.c                        |   4 +-
 25 files changed, 484 insertions(+), 49 deletions(-)
 create mode 100644 lib/test_stackinit.c
 create mode 100644 scripts/gcc-plugins/stackinit_plugin.c
Signature · 1 line
2.17.1