Commit 39b3f4e0 authored by Linus Torvalds's avatar Linus Torvalds
Browse files
Pull hardening updates from Kees Cook:

 - lib/string_choices:
    - Add str_up_down() helper (Michal Wajdeczko)
    - Add str_true_false()/str_false_true() helper  (Hongbo Li)
    - Introduce several opposite string choice helpers  (Hongbo Li)

 - lib/string_helpers:
    - rework overflow-dependent code (Justin Stitt)

 - fortify: refactor test_fortify Makefile to fix some build problems
   (Masahiro Yamada)

 - string: Check for "nonstring" attribute on strscpy() arguments

 - virt: vbox: Replace 1-element arrays with flexible arrays

 - media: venus: hfi_cmds: Replace 1-element arrays with flexible arrays

* tag 'hardening-v6.12-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux:
  lib/string_choices: Add some comments to make more clear for string choices helpers.
  lib/string_choices: Introduce several opposite string choice helpers
  lib/string_choices: Add str_true_false()/str_false_true() helper
  string: Check for "nonstring" attribute on strscpy() arguments
  media: venus: hfi_cmds: struct hfi_session_release_buffer_pkt: Add __counted_by annotation
  media: venus: hfi_cmds: struct hfi_session_release_buffer_pkt: Replace 1-element array with flexible array
  virt: vbox: struct vmmdev_hgcm_pagelist: Replace 1-element array with flexible array
  lib/string_helpers: rework overflow-dependent code
  coccinelle: Add rules to find str_down_up() replacements
  string_choices: Add wrapper for str_down_up()
  coccinelle: Add rules to find str_up_down() replacements
  lib/string_choices: Add str_up_down() helper
  fortify: use if_changed_dep to record header dependency in *.cmd files
  fortify: move test_fortify.sh to lib/test_fortify/
  fortify: refactor test_fortify Makefile to fix some build problems
parents 667495de c121d5cc
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -8834,7 +8834,6 @@ F: include/linux/fortify-string.h
F:	lib/fortify_kunit.c
F:	lib/memcpy_kunit.c
F:	lib/test_fortify/*
F:	scripts/test_fortify.sh
K:	\b__NO_FORTIFY\b
FPGA DFL DRIVERS
+1 −1
Original line number Diff line number Diff line
@@ -227,7 +227,7 @@ struct hfi_session_release_buffer_pkt {
	u32 extradata_size;
	u32 response_req;
	u32 num_buffers;
	u32 buffer_info[1];
	u32 buffer_info[] __counted_by(num_buffers);
};

struct hfi_session_release_resources_pkt {
+3 −0
Original line number Diff line number Diff line
@@ -242,6 +242,9 @@ static inline void *offset_to_ptr(const int *off)
/* &a[0] degrades to a pointer: a different type from an array */
#define __must_be_array(a)	BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))

/* Require C Strings (i.e. NUL-terminated) lack the "nonstring" attribute. */
#define __must_be_cstr(p)	BUILD_BUG_ON_ZERO(__annotated(p, nonstring))

/*
 * This returns a constant expression while determining if an argument is
 * a constant expression, most importantly without evaluating the argument.
+7 −0
Original line number Diff line number Diff line
@@ -421,6 +421,13 @@ struct ftrace_likely_data {
#define __member_size(p)	__builtin_object_size(p, 1)
#endif

/* Determine if an attribute has been applied to a variable. */
#if __has_builtin(__builtin_has_attribute)
#define __annotated(var, attr)	__builtin_has_attribute(var, attr)
#else
#define __annotated(var, attr)	(false)
#endif

/*
 * Some versions of gcc do not mark 'asm goto' volatile:
 *
+8 −4
Original line number Diff line number Diff line
@@ -76,12 +76,16 @@ ssize_t sized_strscpy(char *, const char *, size_t);
 * known size.
 */
#define __strscpy0(dst, src, ...)	\
	sized_strscpy(dst, src, sizeof(dst) + __must_be_array(dst))
#define __strscpy1(dst, src, size)	sized_strscpy(dst, src, size)
	sized_strscpy(dst, src, sizeof(dst) + __must_be_array(dst) +	\
				__must_be_cstr(dst) + __must_be_cstr(src))
#define __strscpy1(dst, src, size)	\
	sized_strscpy(dst, src, size + __must_be_cstr(dst) + __must_be_cstr(src))

#define __strscpy_pad0(dst, src, ...)	\
	sized_strscpy_pad(dst, src, sizeof(dst) + __must_be_array(dst))
#define __strscpy_pad1(dst, src, size)	sized_strscpy_pad(dst, src, size)
	sized_strscpy_pad(dst, src, sizeof(dst) + __must_be_array(dst) +	\
				    __must_be_cstr(dst) + __must_be_cstr(src))
#define __strscpy_pad1(dst, src, size)	\
	sized_strscpy_pad(dst, src, size + __must_be_cstr(dst) + __must_be_cstr(src))

/**
 * strscpy - Copy a C-string into a sized buffer
Loading