Skip to contentSkip to conversation

mptcp: fix setsockopt(IP_TOS) subflow locking

PATCH In review Paolo Abeni 4 participants 5 messages Nov 8, 2023 – Nov 9, 2023

Subsystems (2)
lore
Share & tools
lore

Paolo Abeni

author maintainer
#0 lore raw

PATCH 1/1 mptcp: fix setsockopt(IP_TOS) subflow locking

The mptcp implementation of the IP_TOS socket option uses the lockless variant of the TOS manipulation helper and does not hold suck lock at the helper invocation time.

Add the required locking.

Fixes ffcacff87cd6 ("mptcp: Support for IP_TOS for MPTCP setsockopt()")
---
 net/mptcp/sockopt.c | 3 +++
 1 file changed, 3 insertions(+)
net/mptcp/sockopt.c +3 -0
index 8d485c40585a..cabe856b2a45 100644
@@ -738,8 +738,11 @@ static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock *msk, int optname,
 	val = READ_ONCE(inet_sk(sk)->tos);
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		bool slow;
 
+		slow = lock_sock_fast(ssk);
 		__ip_sock_set_tos(ssk, val);
+		unlock_sock_fast(ssk, slow);
 	}
 	release_sock(sk);
 
Signature · 1 line
2.41.0
#1 lore raw

Re: mptcp: fix setsockopt(IP_TOS) subflow locking: Tests Results

Hi Paolo,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6206547924090880
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6206547924090880/summary/summary.txt

- KVM Validation: debug (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5925072947380224
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5925072947380224/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4799173040537600
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4799173040537600/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5362122993958912
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5362122993958912/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/76fad834de5b

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-debug

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)

maintainer Reviewed-by on v1 1/1
#2 lore raw
In reply to Paolo Abeni
Quoted 2 lines · Paolo Abeni

The mptcp implementation of the IP_TOS socket option uses the lockless variant of the TOS manipulation helper and does not hold suck lock at

(matttbe: please fix "such" typo when applying)

Quoted 17 lines

the helper invocation time.

Add the required locking.

Fixes ffcacff87cd6 ("mptcp: Support for IP_TOS for MPTCP setsockopt()")

---
net/mptcp/sockopt.c | 3 +++

1 file changed, 3 insertions(+)
net/mptcp/sockopt.c +0 -0
index 8d485c40585a..cabe856b2a45 100644
@@ -738,8 +738,11 @@ static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock *msk, int optname,
 	val = READ_ONCE(inet_sk(sk)->tos);

net/mptcp/sockopt.c static int mptcp_setsockopt_v4_set_tos(struct mptcp_sock *msk, int optname, · line 748

Quoted 10 lines
net/mptcp/sockopt.c +3 -0
 	mptcp_for_each_subflow(msk, subflow) {
 		struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+		bool slow;
 
+		slow = lock_sock_fast(ssk);
 		__ip_sock_set_tos(ssk, val);
+		unlock_sock_fast(ssk, slow);
 	}
 	release_sock(sk);
 

Looks good to me with commit message typo fix:

#3 lore raw

Re: mptcp: fix setsockopt(IP_TOS) subflow locking: Tests Results

In reply to Paolo Abeni

Hi Paolo,

Thank you for your modifications, that's great!

Our CI did some validations and here is its report:

- KVM Validation: normal (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/6216342865444864
- Summary: https://api.cirrus-ci.com/v1/artifact/task/6216342865444864/summary/summary.txt

- KVM Validation: normal (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/4808967981891584
- Summary: https://api.cirrus-ci.com/v1/artifact/task/4808967981891584/summary/summary.txt

- KVM Validation: debug (only selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5371917935312896
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5371917935312896/summary/summary.txt

- KVM Validation: debug (except selftest_mptcp_join):
- Success! ✅:
- Task: https://cirrus-ci.com/task/5934867888734208
- Summary: https://api.cirrus-ci.com/v1/artifact/task/5934867888734208/summary/summary.txt

Initiator: Patchew Applier
Commits: https://github.com/multipath-tcp/mptcp_net-next/commits/f0a09d7ba823

If there are some issues, you can reproduce them using the same environment as the one used by the CI thanks to a docker image, e.g.:

    $ cd [kernel source code]
    $ docker run -v "${PWD}:${PWD}:rw" -w "${PWD}" --privileged --rm -it \
        --pull always mptcp/mptcp-upstream-virtme-docker:latest \
        auto-debug

For more details:

https://github.com/multipath-tcp/mptcp-upstream-virtme-docker

Please note that despite all the efforts that have been already done to have a stable tests suite when executed on a public CI like here, it is possible some reported issues are not due to your modifications. Still, do not hesitate to help us improve that ;-)

Cheers,
MPTCP GH Action bot
Bot operated by Matthieu Baerts (Tessares)

maintainer
#4 lore raw
In reply to Paolo Abeni

Hi Paolo, Mat,

Quoted 5 lines · Paolo Abeni

The mptcp implementation of the IP_TOS socket option uses the lockless variant of the TOS manipulation helper and does not hold suck lock at the helper invocation time.

Add the required locking.

Thank you for the patch and the review!

Now in our tree (fixes for -net), with 's/suck/such/', because typos suck...:

New patches for t/upstream-net and t/upstream:
- c69c00a783ed: mptcp: fix setsockopt(IP_TOS) subflow locking
- Results: 688025cbce11..52a2364fffc9 (export-net)
- Results: 4d89b70d7306..351099187dd4 (export)

Tests are now in progress:

https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export-net/20231109T161702
https://cirrus-ci.com/github/multipath-tcp/mptcp_net-next/export/20231109T161702

Cheers,
Matt