Skip to content

Commit

Permalink
mptcp: Use struct_group() to avoid cross-field memset()
Browse files Browse the repository at this point in the history
In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memcpy(), memmove(), and memset(), avoid
intentionally writing across neighboring fields.

Use struct_group() to capture the fields to be reset, so that memset()
can be appropriately bounds-checked by the compiler.

Cc: Matthieu Baerts <[email protected]>
Cc: [email protected]
Signed-off-by: Kees Cook <[email protected]>
Reviewed-by: Mat Martineau <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
kees authored and kuba-moo committed Jan 22, 2022
1 parent 2c13c05 commit 63ec72b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions net/mptcp/protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ DECLARE_PER_CPU(struct mptcp_delegated_action, mptcp_delegated_actions);
struct mptcp_subflow_context {
struct list_head node;/* conn_list of subflows */

char reset_start[0];
struct_group(reset,

unsigned long avg_pacing_rate; /* protected by msk socket lock */
u64 local_key;
Expand Down Expand Up @@ -458,7 +458,7 @@ struct mptcp_subflow_context {

long delegated_status;

char reset_end[0];
);

struct list_head delegated_node; /* link into delegated_action, protected by local BH */

Expand Down Expand Up @@ -494,7 +494,7 @@ mptcp_subflow_tcp_sock(const struct mptcp_subflow_context *subflow)
static inline void
mptcp_subflow_ctx_reset(struct mptcp_subflow_context *subflow)
{
memset(subflow->reset_start, 0, subflow->reset_end - subflow->reset_start);
memset(&subflow->reset, 0, sizeof(subflow->reset));
subflow->request_mptcp = 1;
}

Expand Down

0 comments on commit 63ec72b

Please sign in to comment.