History

Merge tag 'overflow-v5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux

Pull overflow updates from Kees Cook: "The end goal of the current buffer overflow detection work[0] is to gain full compile-time and run-time coverage of all detectable buffer overflows seen via array indexing or memcpy(), memmove(), and memset(). The str*() family of functions already have full coverage. While much of the work for these changes have been on-going for many releases (i.e. 0-element and 1-element array replacements, as well as avoiding false positives and fixing discovered overflows[1]), this series contains the foundational elements of several related buffer overflow detection improvements by providing new common helpers and FORTIFY_SOURCE changes needed to gain the introspection required for compiler visibility into array sizes. Also included are a handful of already Acked instances using the helpers (or related clean-ups), with many more waiting at the ready to be taken via subsystem-specific trees[2]. The new helpers are: - struct_group() for gaining struct member range introspection - memset_after() and memset_startat() for clearing to the end of structures - DECLARE_FLEX_ARRAY() for using flex arrays in unions or alone in structs Also included is the beginning of the refactoring of FORTIFY_SOURCE to support memcpy() introspection, fix missing and regressed coverage under GCC, and to prepare to fix the currently broken Clang support. Finishing this work is part of the larger series[0], but depends on all the false positives and buffer overflow bug fixes to have landed already and those that depend on this series to land. As part of the FORTIFY_SOURCE refactoring, a set of both a compile-time and run-time tests are added for FORTIFY_SOURCE and the mem*()-family functions respectively. The compile time tests have found a legitimate (though corner-case) bug[6] already. Please note that the appearance of "panic" and "BUG" in the FORTIFY_SOURCE refactoring are the result of relocating existing code, and no new use of those code-paths are expected nor desired. Finally, there are two tree-wide conversions for 0-element arrays and flexible array unions to gain sane compiler introspection coverage that result in no known object code differences. After this series (and the changes that have now landed via netdev and usb), we are very close to finally being able to build with -Warray-bounds and -Wzero-length-bounds. However, due corner cases in GCC[3] and Clang[4], I have not included the last two patches that turn on these options, as I don't want to introduce any known warnings to the build. Hopefully these can be solved soon" Link: https://lore.kernel.org/lkml/20210818060533.3569517-1-keescook@chromium.org/ [0] Link: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/log/?qt=grep&q=FORTIFY_SOURCE [1] Link: https://lore.kernel.org/lkml/202108220107.3E26FE6C9C@keescook/ [2] Link: https://lore.kernel.org/lkml/3ab153ec-2798-da4c-f7b1-81b0ac8b0c5b@roeck-us.net/ [3] Link: https://bugs.llvm.org/show_bug.cgi?id=51682 [4] Link: https://lore.kernel.org/lkml/202109051257.29B29745C0@keescook/ [5] Link: https://lore.kernel.org/lkml/20211020200039.170424-1-keescook@chromium.org/ [6] * tag 'overflow-v5.16-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: (30 commits) fortify: strlen: Avoid shadowing previous locals compiler-gcc.h: Define __SANITIZE_ADDRESS__ under hwaddress sanitizer treewide: Replace 0-element memcpy() destinations with flexible arrays treewide: Replace open-coded flex arrays in unions stddef: Introduce DECLARE_FLEX_ARRAY() helper btrfs: Use memset_startat() to clear end of struct string.h: Introduce memset_startat() for wiping trailing members and padding xfrm: Use memset_after() to clear padding string.h: Introduce memset_after() for wiping trailing members/padding lib: Introduce CONFIG_MEMCPY_KUNIT_TEST fortify: Add compile-time FORTIFY_SOURCE tests fortify: Allow strlen() and strnlen() to pass compile-time known lengths fortify: Prepare to improve strnlen() and strlen() warnings fortify: Fix dropped strcpy() compile-time write overflow check fortify: Explicitly disable Clang support fortify: Move remaining fortify helpers into fortify-string.h lib/string: Move helper functions out of string.c compiler_types.h: Remove __compiletime_object_size() cm4000_cs: Use struct_group() to zero struct cm4000_dev region can: flexcan: Use struct_group() to zero struct flexcan_regs regions ...

Linus Torvalds committed 5 years ago

Commit 2dc26d92 parents f594e28 95cadae76 files · +1160 −446Browse files

Showing the changes to include/uapi/linux (2 of 76 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/dlm_device.h +2 −2
  2. include/uapi/linux/stddef.h +37 −0
include/uapi/linux/dlm_device.h+2−2
@@ -45,13 +45,13 @@ struct dlm_lock_params { · 44 unmodified lines
45 void __user *bastaddr;45 void __user *bastaddr;
46 struct dlm_lksb __user *lksb;46 struct dlm_lksb __user *lksb;
47 char lvb[DLM_USER_LVB_LEN];47 char lvb[DLM_USER_LVB_LEN];
48 char name[0];48 char name[];
49};49};
50 50
51struct dlm_lspace_params {51struct dlm_lspace_params {
52 __u32 flags;52 __u32 flags;
53 __u32 minor;53 __u32 minor;
54 char name[0];54 char name[];
55};55};
56 56
57struct dlm_purge_params {57struct dlm_purge_params {
include/uapi/linux/stddef.h+37−0
@@ -4,3 +4,40 @@ · 3 unmodified lines
4#ifndef __always_inline4#ifndef __always_inline
5#define __always_inline inline5#define __always_inline inline
6#endif6#endif
7
8/**
9 * __struct_group() - Create a mirrored named and anonyomous struct
10 *
11 * @TAG: The tag name for the named sub-struct (usually empty)
12 * @NAME: The identifier name of the mirrored sub-struct
13 * @ATTRS: Any struct attributes (usually empty)
14 * @MEMBERS: The member declarations for the mirrored structs
15 *
16 * Used to create an anonymous union of two structs with identical layout
17 * and size: one anonymous and one named. The former's members can be used
18 * normally without sub-struct naming, and the latter can be used to
19 * reason about the start, end, and size of the group of struct members.
20 * The named struct can also be explicitly tagged for layer reuse, as well
21 * as both having struct attributes appended.
22 */
23#define __struct_group(TAG, NAME, ATTRS, MEMBERS...) \
24 union { \
25 struct { MEMBERS } ATTRS; \
26 struct TAG { MEMBERS } ATTRS NAME; \
27 }
28
29/**
30 * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union
31 *
32 * @TYPE: The type of each flexible array element
33 * @NAME: The name of the flexible array member
34 *
35 * In order to have a flexible array member in a union or alone in a
36 * struct, it needs to be wrapped in an anonymous struct with at least 1
37 * named member, but that member can be empty.
38 */
39#define __DECLARE_FLEX_ARRAY(TYPE, NAME) \
40 struct { \
41 struct { } __empty_ ## NAME; \
42 TYPE NAME[]; \
43 }