Skip to content

Commit

Permalink
mptcp: annotate lockless access for token
Browse files Browse the repository at this point in the history
The token field is manipulated under the msk socket lock
and accessed lockless in a few spots, add proper ONCE annotation

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Paolo Abeni authored and David S. Miller committed Feb 5, 2024
1 parent 9426ce4 commit b9f4554
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion net/mptcp/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void mptcp_pm_new_connection(struct mptcp_sock *msk, const struct sock *ssk, int
{
struct mptcp_pm_data *pm = &msk->pm;

pr_debug("msk=%p, token=%u side=%d", msk, msk->token, server_side);
pr_debug("msk=%p, token=%u side=%d", msk, READ_ONCE(msk->token), server_side);

WRITE_ONCE(pm->server_side, server_side);
mptcp_event(MPTCP_EVENT_CREATED, msk, ssk, GFP_ATOMIC);
Expand Down
10 changes: 5 additions & 5 deletions net/mptcp/pm_netlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ static int mptcp_event_put_token_and_ssk(struct sk_buff *skb,
const struct mptcp_subflow_context *sf;
u8 sk_err;

if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token)))
return -EMSGSIZE;

if (mptcp_event_add_subflow(skb, ssk))
Expand Down Expand Up @@ -2055,7 +2055,7 @@ static int mptcp_event_created(struct sk_buff *skb,
const struct mptcp_sock *msk,
const struct sock *ssk)
{
int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token);
int err = nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token));

if (err)
return err;
Expand Down Expand Up @@ -2083,7 +2083,7 @@ void mptcp_event_addr_removed(const struct mptcp_sock *msk, uint8_t id)
if (!nlh)
goto nla_put_failure;

if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token)))
goto nla_put_failure;

if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, id))
Expand Down Expand Up @@ -2118,7 +2118,7 @@ void mptcp_event_addr_announced(const struct sock *ssk,
if (!nlh)
goto nla_put_failure;

if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token))
if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token)))
goto nla_put_failure;

if (nla_put_u8(skb, MPTCP_ATTR_REM_ID, info->id))
Expand Down Expand Up @@ -2234,7 +2234,7 @@ void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
goto nla_put_failure;
break;
case MPTCP_EVENT_CLOSED:
if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, msk->token) < 0)
if (nla_put_u32(skb, MPTCP_ATTR_TOKEN, READ_ONCE(msk->token)) < 0)
goto nla_put_failure;
break;
case MPTCP_EVENT_ANNOUNCED:
Expand Down
2 changes: 1 addition & 1 deletion net/mptcp/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -3199,7 +3199,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,

msk = mptcp_sk(nsk);
WRITE_ONCE(msk->local_key, subflow_req->local_key);
msk->token = subflow_req->token;
WRITE_ONCE(msk->token, subflow_req->token);
msk->in_accept_queue = 1;
WRITE_ONCE(msk->fully_established, false);
if (mp_opt->suboptions & OPTION_MPTCP_CSUMREQD)
Expand Down

0 comments on commit b9f4554

Please sign in to comment.