Skip to content

Commit b718713

Browse files
committed
Merge tag 'hardening-v6.9-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux
Pull more hardening updates from Kees Cook: - CONFIG_MEMCPY_SLOW_KUNIT_TEST is no longer needed (Guenter Roeck) - Fix needless UTF-8 character in arch/Kconfig (Liu Song) - Improve __counted_by warning message in LKDTM (Nathan Chancellor) - Refactor DEFINE_FLEX() for default use of __counted_by - Disable signed integer overflow sanitizer on GCC < 8 * tag 'hardening-v6.9-rc1-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/kees/linux: lkdtm/bugs: Improve warning message for compilers without counted_by support overflow: Change DEFINE_FLEX to take __counted_by member Revert "kunit: memcpy: Split slow memcpy tests into MEMCPY_SLOW_KUNIT_TEST" arch/Kconfig: eliminate needless UTF-8 character in Kconfig help ubsan: Disable signed integer overflow sanitizer on GCC < 8
2 parents bfa8f18 + 231dc3f commit b718713

File tree

13 files changed

+62
-39
lines changed

13 files changed

+62
-39
lines changed

arch/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ config CFI_CLANG
799799
depends on ARCH_SUPPORTS_CFI_CLANG
800800
depends on $(cc-option,-fsanitize=kcfi)
801801
help
802-
This option enables Clangs forward-edge Control Flow Integrity
802+
This option enables Clang's forward-edge Control Flow Integrity
803803
(CFI) checking, where the compiler injects a runtime check to each
804804
indirect function call to ensure the target is a valid function with
805805
the correct static type. This restricts possible call targets and

drivers/misc/lkdtm/bugs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ static void lkdtm_FAM_BOUNDS(void)
417417
pr_err("FAIL: survived access of invalid flexible array member index!\n");
418418

419419
if (!__has_attribute(__counted_by__))
420-
pr_warn("This is expected since this %s was built a compiler supporting __counted_by\n",
420+
pr_warn("This is expected since this %s was built with a compiler that does not support __counted_by\n",
421421
lkdtm_kernel_info);
422422
else if (IS_ENABLED(CONFIG_UBSAN_BOUNDS))
423423
pr_expected_config(CONFIG_UBSAN_TRAP);

drivers/net/ethernet/intel/ice/ice_base.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ ice_vsi_cfg_txq(struct ice_vsi *vsi, struct ice_tx_ring *ring,
956956
int ice_vsi_cfg_single_txq(struct ice_vsi *vsi, struct ice_tx_ring **tx_rings,
957957
u16 q_idx)
958958
{
959-
DEFINE_FLEX(struct ice_aqc_add_tx_qgrp, qg_buf, txqs, 1);
959+
DEFINE_RAW_FLEX(struct ice_aqc_add_tx_qgrp, qg_buf, txqs, 1);
960960

961961
if (q_idx >= vsi->alloc_txq || !tx_rings || !tx_rings[q_idx])
962962
return -EINVAL;
@@ -978,7 +978,7 @@ int ice_vsi_cfg_single_txq(struct ice_vsi *vsi, struct ice_tx_ring **tx_rings,
978978
static int
979979
ice_vsi_cfg_txqs(struct ice_vsi *vsi, struct ice_tx_ring **rings, u16 count)
980980
{
981-
DEFINE_FLEX(struct ice_aqc_add_tx_qgrp, qg_buf, txqs, 1);
981+
DEFINE_RAW_FLEX(struct ice_aqc_add_tx_qgrp, qg_buf, txqs, 1);
982982
int err = 0;
983983
u16 q_idx;
984984

drivers/net/ethernet/intel/ice/ice_common.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4695,7 +4695,7 @@ ice_dis_vsi_txq(struct ice_port_info *pi, u16 vsi_handle, u8 tc, u8 num_queues,
46954695
enum ice_disq_rst_src rst_src, u16 vmvf_num,
46964696
struct ice_sq_cd *cd)
46974697
{
4698-
DEFINE_FLEX(struct ice_aqc_dis_txq_item, qg_list, q_id, 1);
4698+
DEFINE_RAW_FLEX(struct ice_aqc_dis_txq_item, qg_list, q_id, 1);
46994699
u16 i, buf_size = __struct_size(qg_list);
47004700
struct ice_q_ctx *q_ctx;
47014701
int status = -ENOENT;
@@ -4917,7 +4917,7 @@ int
49174917
ice_dis_vsi_rdma_qset(struct ice_port_info *pi, u16 count, u32 *qset_teid,
49184918
u16 *q_id)
49194919
{
4920-
DEFINE_FLEX(struct ice_aqc_dis_txq_item, qg_list, q_id, 1);
4920+
DEFINE_RAW_FLEX(struct ice_aqc_dis_txq_item, qg_list, q_id, 1);
49214921
u16 qg_size = __struct_size(qg_list);
49224922
struct ice_hw *hw;
49234923
int status = 0;

drivers/net/ethernet/intel/ice/ice_ddp.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -1938,8 +1938,8 @@ static enum ice_ddp_state ice_init_pkg_info(struct ice_hw *hw,
19381938
*/
19391939
static enum ice_ddp_state ice_get_pkg_info(struct ice_hw *hw)
19401940
{
1941-
DEFINE_FLEX(struct ice_aqc_get_pkg_info_resp, pkg_info, pkg_info,
1942-
ICE_PKG_CNT);
1941+
DEFINE_RAW_FLEX(struct ice_aqc_get_pkg_info_resp, pkg_info, pkg_info,
1942+
ICE_PKG_CNT);
19431943
u16 size = __struct_size(pkg_info);
19441944
u32 i;
19451945

@@ -1990,8 +1990,8 @@ static enum ice_ddp_state ice_chk_pkg_compat(struct ice_hw *hw,
19901990
struct ice_pkg_hdr *ospkg,
19911991
struct ice_seg **seg)
19921992
{
1993-
DEFINE_FLEX(struct ice_aqc_get_pkg_info_resp, pkg, pkg_info,
1994-
ICE_PKG_CNT);
1993+
DEFINE_RAW_FLEX(struct ice_aqc_get_pkg_info_resp, pkg, pkg_info,
1994+
ICE_PKG_CNT);
19951995
u16 size = __struct_size(pkg);
19961996
enum ice_ddp_state state;
19971997
u32 i;

drivers/net/ethernet/intel/ice/ice_lag.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ static void
491491
ice_lag_move_vf_node_tc(struct ice_lag *lag, u8 oldport, u8 newport,
492492
u16 vsi_num, u8 tc)
493493
{
494-
DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
494+
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
495495
struct device *dev = ice_pf_to_dev(lag->pf);
496496
u16 numq, valq, num_moved, qbuf_size;
497497
u16 buf_size = __struct_size(buf);
@@ -849,7 +849,7 @@ static void
849849
ice_lag_reclaim_vf_tc(struct ice_lag *lag, struct ice_hw *src_hw, u16 vsi_num,
850850
u8 tc)
851851
{
852-
DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
852+
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
853853
struct device *dev = ice_pf_to_dev(lag->pf);
854854
u16 numq, valq, num_moved, qbuf_size;
855855
u16 buf_size = __struct_size(buf);
@@ -1873,7 +1873,7 @@ static void
18731873
ice_lag_move_vf_nodes_tc_sync(struct ice_lag *lag, struct ice_hw *dest_hw,
18741874
u16 vsi_num, u8 tc)
18751875
{
1876-
DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
1876+
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
18771877
struct device *dev = ice_pf_to_dev(lag->pf);
18781878
u16 numq, valq, num_moved, qbuf_size;
18791879
u16 buf_size = __struct_size(buf);

drivers/net/ethernet/intel/ice/ice_sched.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static int
237237
ice_sched_remove_elems(struct ice_hw *hw, struct ice_sched_node *parent,
238238
u32 node_teid)
239239
{
240-
DEFINE_FLEX(struct ice_aqc_delete_elem, buf, teid, 1);
240+
DEFINE_RAW_FLEX(struct ice_aqc_delete_elem, buf, teid, 1);
241241
u16 buf_size = __struct_size(buf);
242242
u16 num_groups_removed = 0;
243243
int status;
@@ -2219,7 +2219,7 @@ int
22192219
ice_sched_move_nodes(struct ice_port_info *pi, struct ice_sched_node *parent,
22202220
u16 num_items, u32 *list)
22212221
{
2222-
DEFINE_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
2222+
DEFINE_RAW_FLEX(struct ice_aqc_move_elem, buf, teid, 1);
22232223
u16 buf_len = __struct_size(buf);
22242224
struct ice_sched_node *node;
22252225
u16 i, grps_movd = 0;

drivers/net/ethernet/intel/ice/ice_switch.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ ice_aq_alloc_free_vsi_list(struct ice_hw *hw, u16 *vsi_list_id,
18121812
enum ice_sw_lkup_type lkup_type,
18131813
enum ice_adminq_opc opc)
18141814
{
1815-
DEFINE_FLEX(struct ice_aqc_alloc_free_res_elem, sw_buf, elem, 1);
1815+
DEFINE_RAW_FLEX(struct ice_aqc_alloc_free_res_elem, sw_buf, elem, 1);
18161816
u16 buf_len = __struct_size(sw_buf);
18171817
struct ice_aqc_res_elem *vsi_ele;
18181818
int status;
@@ -2081,7 +2081,7 @@ ice_aq_get_recipe_to_profile(struct ice_hw *hw, u32 profile_id, u8 *r_bitmap,
20812081
*/
20822082
int ice_alloc_recipe(struct ice_hw *hw, u16 *rid)
20832083
{
2084-
DEFINE_FLEX(struct ice_aqc_alloc_free_res_elem, sw_buf, elem, 1);
2084+
DEFINE_RAW_FLEX(struct ice_aqc_alloc_free_res_elem, sw_buf, elem, 1);
20852085
u16 buf_len = __struct_size(sw_buf);
20862086
int status;
20872087

@@ -4418,7 +4418,7 @@ int
44184418
ice_alloc_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
44194419
u16 *counter_id)
44204420
{
4421-
DEFINE_FLEX(struct ice_aqc_alloc_free_res_elem, buf, elem, 1);
4421+
DEFINE_RAW_FLEX(struct ice_aqc_alloc_free_res_elem, buf, elem, 1);
44224422
u16 buf_len = __struct_size(buf);
44234423
int status;
44244424

@@ -4446,7 +4446,7 @@ int
44464446
ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
44474447
u16 counter_id)
44484448
{
4449-
DEFINE_FLEX(struct ice_aqc_alloc_free_res_elem, buf, elem, 1);
4449+
DEFINE_RAW_FLEX(struct ice_aqc_alloc_free_res_elem, buf, elem, 1);
44504450
u16 buf_len = __struct_size(buf);
44514451
int status;
44524452

@@ -4476,7 +4476,7 @@ ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
44764476
*/
44774477
int ice_share_res(struct ice_hw *hw, u16 type, u8 shared, u16 res_id)
44784478
{
4479-
DEFINE_FLEX(struct ice_aqc_alloc_free_res_elem, buf, elem, 1);
4479+
DEFINE_RAW_FLEX(struct ice_aqc_alloc_free_res_elem, buf, elem, 1);
44804480
u16 buf_len = __struct_size(buf);
44814481
u16 res_type;
44824482
int status;

include/linux/overflow.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
398398
* @count: Number of elements in the array; must be compile-time const.
399399
* @initializer: initializer expression (could be empty for no init).
400400
*/
401-
#define _DEFINE_FLEX(type, name, member, count, initializer) \
401+
#define _DEFINE_FLEX(type, name, member, count, initializer...) \
402402
_Static_assert(__builtin_constant_p(count), \
403403
"onstack flex array members require compile-time const count"); \
404404
union { \
@@ -408,8 +408,8 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
408408
type *name = (type *)&name##_u
409409

410410
/**
411-
* DEFINE_FLEX() - Define an on-stack instance of structure with a trailing
412-
* flexible array member.
411+
* DEFINE_RAW_FLEX() - Define an on-stack instance of structure with a trailing
412+
* flexible array member, when it does not have a __counted_by annotation.
413413
*
414414
* @type: structure type name, including "struct" keyword.
415415
* @name: Name for a variable to define.
@@ -420,7 +420,24 @@ static inline size_t __must_check size_sub(size_t minuend, size_t subtrahend)
420420
* flexible array member.
421421
* Use __struct_size(@name) to get compile-time size of it afterwards.
422422
*/
423-
#define DEFINE_FLEX(type, name, member, count) \
423+
#define DEFINE_RAW_FLEX(type, name, member, count) \
424424
_DEFINE_FLEX(type, name, member, count, = {})
425425

426+
/**
427+
* DEFINE_FLEX() - Define an on-stack instance of structure with a trailing
428+
* flexible array member.
429+
*
430+
* @TYPE: structure type name, including "struct" keyword.
431+
* @NAME: Name for a variable to define.
432+
* @MEMBER: Name of the array member.
433+
* @COUNTER: Name of the __counted_by member.
434+
* @COUNT: Number of elements in the array; must be compile-time const.
435+
*
436+
* Define a zeroed, on-stack, instance of @TYPE structure with a trailing
437+
* flexible array member.
438+
* Use __struct_size(@NAME) to get compile-time size of it afterwards.
439+
*/
440+
#define DEFINE_FLEX(TYPE, NAME, MEMBER, COUNTER, COUNT) \
441+
_DEFINE_FLEX(TYPE, NAME, MEMBER, COUNT, = { .obj.COUNTER = COUNT, })
442+
426443
#endif /* __LINUX_OVERFLOW_H */

lib/Kconfig.debug

-12
Original file line numberDiff line numberDiff line change
@@ -2703,18 +2703,6 @@ config MEMCPY_KUNIT_TEST
27032703

27042704
If unsure, say N.
27052705

2706-
config MEMCPY_SLOW_KUNIT_TEST
2707-
bool "Include exhaustive memcpy tests"
2708-
depends on MEMCPY_KUNIT_TEST
2709-
default y
2710-
help
2711-
Some memcpy tests are quite exhaustive in checking for overlaps
2712-
and bit ranges. These can be very slow, so they are split out
2713-
as a separate config, in case they need to be disabled.
2714-
2715-
Note this config option will be replaced by the use of KUnit test
2716-
attributes.
2717-
27182706
config IS_SIGNED_TYPE_KUNIT_TEST
27192707
tristate "Test is_signed_type() macro" if !KUNIT_ALL_TESTS
27202708
depends on KUNIT

lib/Kconfig.ubsan

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ config UBSAN_SIGNED_WRAP
119119
bool "Perform checking for signed arithmetic wrap-around"
120120
default UBSAN
121121
depends on !COMPILE_TEST
122+
# The no_sanitize attribute was introduced in GCC with version 8.
123+
depends on !CC_IS_GCC || GCC_VERSION >= 80000
122124
depends on $(cc-option,-fsanitize=signed-integer-overflow)
123125
help
124126
This option enables -fsanitize=signed-integer-overflow which checks

lib/memcpy_kunit.c

-3
Original file line numberDiff line numberDiff line change
@@ -309,9 +309,6 @@ static void set_random_nonzero(struct kunit *test, u8 *byte)
309309

310310
static void init_large(struct kunit *test)
311311
{
312-
if (!IS_ENABLED(CONFIG_MEMCPY_SLOW_KUNIT_TEST))
313-
kunit_skip(test, "Slow test skipped. Enable with CONFIG_MEMCPY_SLOW_KUNIT_TEST=y");
314-
315312
/* Get many bit patterns. */
316313
get_random_bytes(large_src, ARRAY_SIZE(large_src));
317314

lib/overflow_kunit.c

+19
Original file line numberDiff line numberDiff line change
@@ -1172,6 +1172,24 @@ static void castable_to_type_test(struct kunit *test)
11721172
#undef TEST_CASTABLE_TO_TYPE
11731173
}
11741174

1175+
struct foo {
1176+
int a;
1177+
u32 counter;
1178+
s16 array[] __counted_by(counter);
1179+
};
1180+
1181+
static void DEFINE_FLEX_test(struct kunit *test)
1182+
{
1183+
DEFINE_RAW_FLEX(struct foo, two, array, 2);
1184+
DEFINE_FLEX(struct foo, eight, array, counter, 8);
1185+
DEFINE_FLEX(struct foo, empty, array, counter, 0);
1186+
1187+
KUNIT_EXPECT_EQ(test, __struct_size(two),
1188+
sizeof(struct foo) + sizeof(s16) + sizeof(s16));
1189+
KUNIT_EXPECT_EQ(test, __struct_size(eight), 24);
1190+
KUNIT_EXPECT_EQ(test, __struct_size(empty), sizeof(struct foo));
1191+
}
1192+
11751193
static struct kunit_case overflow_test_cases[] = {
11761194
KUNIT_CASE(u8_u8__u8_overflow_test),
11771195
KUNIT_CASE(s8_s8__s8_overflow_test),
@@ -1194,6 +1212,7 @@ static struct kunit_case overflow_test_cases[] = {
11941212
KUNIT_CASE(overflows_type_test),
11951213
KUNIT_CASE(same_type_test),
11961214
KUNIT_CASE(castable_to_type_test),
1215+
KUNIT_CASE(DEFINE_FLEX_test),
11971216
{}
11981217
};
11991218

0 commit comments

Comments
 (0)