Commit 1c09d7cb authored by Paolo Abeni's avatar Paolo Abeni Committed by David S. Miller

mptcp: annotate access for msk keys

Both the local and the remote key follow the same locking
schema, put in place the proper ONCE accessors.
Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Reviewed-by: default avatarMat Martineau <martineau@kernel.org>
Signed-off-by: default avatarMatthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1e082232
...@@ -689,8 +689,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff * ...@@ -689,8 +689,8 @@ static bool mptcp_established_options_add_addr(struct sock *sk, struct sk_buff *
opts->suboptions |= OPTION_MPTCP_ADD_ADDR; opts->suboptions |= OPTION_MPTCP_ADD_ADDR;
if (!echo) { if (!echo) {
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDRTX); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ADDADDRTX);
opts->ahmac = add_addr_generate_hmac(msk->local_key, opts->ahmac = add_addr_generate_hmac(READ_ONCE(msk->local_key),
msk->remote_key, READ_ONCE(msk->remote_key),
&opts->addr); &opts->addr);
} else { } else {
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADDTX); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_ECHOADDTX);
...@@ -792,7 +792,7 @@ static bool mptcp_established_options_fastclose(struct sock *sk, ...@@ -792,7 +792,7 @@ static bool mptcp_established_options_fastclose(struct sock *sk,
*size = TCPOLEN_MPTCP_FASTCLOSE; *size = TCPOLEN_MPTCP_FASTCLOSE;
opts->suboptions |= OPTION_MPTCP_FASTCLOSE; opts->suboptions |= OPTION_MPTCP_FASTCLOSE;
opts->rcvr_key = msk->remote_key; opts->rcvr_key = READ_ONCE(msk->remote_key);
pr_debug("FASTCLOSE key=%llu", opts->rcvr_key); pr_debug("FASTCLOSE key=%llu", opts->rcvr_key);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSETX);
...@@ -1099,8 +1099,8 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk, ...@@ -1099,8 +1099,8 @@ static bool add_addr_hmac_valid(struct mptcp_sock *msk,
if (mp_opt->echo) if (mp_opt->echo)
return true; return true;
hmac = add_addr_generate_hmac(msk->remote_key, hmac = add_addr_generate_hmac(READ_ONCE(msk->remote_key),
msk->local_key, READ_ONCE(msk->local_key),
&mp_opt->addr); &mp_opt->addr);
pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n", pr_debug("msk=%p, ahmac=%llu, mp_opt->ahmac=%llu\n",
...@@ -1147,7 +1147,7 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb) ...@@ -1147,7 +1147,7 @@ bool mptcp_incoming_options(struct sock *sk, struct sk_buff *skb)
if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) { if (unlikely(mp_opt.suboptions != OPTION_MPTCP_DSS)) {
if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) && if ((mp_opt.suboptions & OPTION_MPTCP_FASTCLOSE) &&
msk->local_key == mp_opt.rcvr_key) { READ_ONCE(msk->local_key) == mp_opt.rcvr_key) {
WRITE_ONCE(msk->rcv_fastclose, true); WRITE_ONCE(msk->rcv_fastclose, true);
mptcp_schedule_work((struct sock *)msk); mptcp_schedule_work((struct sock *)msk);
MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX); MPTCP_INC_STATS(sock_net(sk), MPTCP_MIB_MPFASTCLOSERX);
......
...@@ -3193,7 +3193,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk, ...@@ -3193,7 +3193,7 @@ struct sock *mptcp_sk_clone_init(const struct sock *sk,
__mptcp_init_sock(nsk); __mptcp_init_sock(nsk);
msk = mptcp_sk(nsk); msk = mptcp_sk(nsk);
msk->local_key = subflow_req->local_key; WRITE_ONCE(msk->local_key, subflow_req->local_key);
msk->token = subflow_req->token; msk->token = subflow_req->token;
msk->in_accept_queue = 1; msk->in_accept_queue = 1;
WRITE_ONCE(msk->fully_established, false); WRITE_ONCE(msk->fully_established, false);
......
...@@ -260,8 +260,10 @@ struct mptcp_data_frag { ...@@ -260,8 +260,10 @@ struct mptcp_data_frag {
struct mptcp_sock { struct mptcp_sock {
/* inet_connection_sock must be the first member */ /* inet_connection_sock must be the first member */
struct inet_connection_sock sk; struct inet_connection_sock sk;
u64 local_key; u64 local_key; /* protected by the first subflow socket lock
u64 remote_key; * lockless access read
*/
u64 remote_key; /* same as above */
u64 write_seq; u64 write_seq;
u64 bytes_sent; u64 bytes_sent;
u64 snd_nxt; u64 snd_nxt;
......
...@@ -75,7 +75,8 @@ static void subflow_req_create_thmac(struct mptcp_subflow_request_sock *subflow_ ...@@ -75,7 +75,8 @@ static void subflow_req_create_thmac(struct mptcp_subflow_request_sock *subflow_
get_random_bytes(&subflow_req->local_nonce, sizeof(u32)); get_random_bytes(&subflow_req->local_nonce, sizeof(u32));
subflow_generate_hmac(msk->local_key, msk->remote_key, subflow_generate_hmac(READ_ONCE(msk->local_key),
READ_ONCE(msk->remote_key),
subflow_req->local_nonce, subflow_req->local_nonce,
subflow_req->remote_nonce, hmac); subflow_req->remote_nonce, hmac);
...@@ -694,7 +695,8 @@ static bool subflow_hmac_valid(const struct request_sock *req, ...@@ -694,7 +695,8 @@ static bool subflow_hmac_valid(const struct request_sock *req,
if (!msk) if (!msk)
return false; return false;
subflow_generate_hmac(msk->remote_key, msk->local_key, subflow_generate_hmac(READ_ONCE(msk->remote_key),
READ_ONCE(msk->local_key),
subflow_req->remote_nonce, subflow_req->remote_nonce,
subflow_req->local_nonce, hmac); subflow_req->local_nonce, hmac);
...@@ -1530,8 +1532,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc, ...@@ -1530,8 +1532,8 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
mptcp_pm_get_flags_and_ifindex_by_id(msk, local_id, mptcp_pm_get_flags_and_ifindex_by_id(msk, local_id,
&flags, &ifindex); &flags, &ifindex);
subflow->remote_key_valid = 1; subflow->remote_key_valid = 1;
subflow->remote_key = msk->remote_key; subflow->remote_key = READ_ONCE(msk->remote_key);
subflow->local_key = msk->local_key; subflow->local_key = READ_ONCE(msk->local_key);
subflow->token = msk->token; subflow->token = msk->token;
mptcp_info2sockaddr(loc, &addr, ssk->sk_family); mptcp_info2sockaddr(loc, &addr, ssk->sk_family);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment