Commit 6d6e40ec authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files

Merge branch 'batch-1-annotate-structs-with-__counted_by'

Kees Cook says:

====================
Batch 1: Annotate structs with __counted_by

This is the batch 1 of patches touching netdev for preparing for
the coming implementation by GCC and Clang of the __counted_by
attribute. Flexible array members annotated with __counted_by can have
their accesses bounds-checked at run-time checking via CONFIG_UBSAN_BOUNDS
(for array indexing) and CONFIG_FORTIFY_SOURCE (for strcpy/memcpy-family
functions).

As found with Coccinelle[1], add __counted_by to structs that would
benefit from the annotation.

Since the element count member must be set before accessing the annotated
flexible array member, some patches also move the member's initialization
earlier. (These are noted in the individual patches.)

[1] https://github.com/kees/kernel-tools/blob/trunk/coccinelle/examples/counted_by.cocci
====================

Link: https://lore.kernel.org/r/20230922172449.work.906-kees@kernel.org


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 436e5f75 0d01cfe5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -381,7 +381,7 @@ struct mediatable {
	unsigned has_reset:6;
	u32 csr15dir;
	u32 csr15val;		/* 21143 NWay setting. */
	struct medialeaf mleaf[];
	struct medialeaf mleaf[] __counted_by(leafcount);
};


+1 −1
Original line number Diff line number Diff line
@@ -297,7 +297,7 @@ struct enetc_int_vector {
	char name[ENETC_INT_NAME_MAX];

	struct enetc_bdr rx_ring;
	struct enetc_bdr tx_ring[];
	struct enetc_bdr tx_ring[] __counted_by(count_tx_rings);
} ____cacheline_aligned_in_smp;

struct enetc_cls_rule {
+1 −1
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@ struct enetc_psfp_gate {
	u32 num_entries;
	refcount_t refcount;
	struct hlist_node node;
	struct action_gate_entry entries[];
	struct action_gate_entry entries[] __counted_by(num_entries);
};

/* Only enable the green color frame now
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ struct ppe_common_cb {
	u8 comm_index;   /*ppe_common index*/

	u32 ppe_num;
	struct hns_ppe_cb ppe_cb[];
	struct hns_ppe_cb ppe_cb[] __counted_by(ppe_num);

};

+1 −1
Original line number Diff line number Diff line
@@ -108,7 +108,7 @@ struct rcb_common_cb {
	u32 ring_num;
	u32 desc_num; /*  desc num per queue*/

	struct ring_pair_cb ring_pair_cb[];
	struct ring_pair_cb ring_pair_cb[] __counted_by(ring_num);
};

int hns_rcb_buf_size2type(u32 buf_size);
Loading