Skip to content

net: openvswitch: fix a feature leak on a failed change

Minxi Hou linux-kselftest netdev stable 5 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest2 patches 4 repliesIn review
  2. v42 patches 4 repliesSuperseded
  3. v32 patches 0 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v22 patches2 repliesSuperseded
v12 patches2 repliesSuperseded

Changes in v5 from the cover letter

- Rebased onto current net.
- The two teardown paths clear only OVS_DP_F_TC_RECIRC_SHARING, so a datapath on its way out keeps the bits an upcall in flight still reads. A whole-field store clears OVS_DP_F_UNALIGNED between the two reads in queue_userspace_packet() and pad_packet() (reported by Sashiko).
- queue_userspace_packet() reads the features once and gives that value to pad_packet(), so OVS_DP_CMD_SET cannot split the head room decision from the padding decision either.
- The tests write their diagnostics to stderr, the skip message included. A copy of stdout stayed open in the daemons the suite starts, which kept the kselftest runner reading a pipe that never reached EOF, so the run hung after the last subtest (reported by Matthieu Baerts).
- A datapath that cannot be read, and one that reports no features, are told apart and reported as such instead of as a feature mismatch, and a failed expectation carries its own description.
- checkpatch reports nothing for either patch.

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2net: openvswitch: do not record user features when the change failsnet/openvswitch/datapath.c net/openvswitch/datapath.h+47 -181 reply
2/2selftests/net/openvswitch: check that a failed set keeps the featurestools/testing/selftests/net/openvswitch/config tools/testing/selftests/net/openvswitch/openvswitch.sh tools/testing/selftests/net/openvswitch/ovs-dpctl.py+263 -03 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH net v5 0/2] net: openvswitch: fix a feature leak on a failed change

ovs_dp_change() records the requested user features before it calls the update that can fail, so a request rejected for an empty per-cpu-pids leaves the datapath claiming a feature it never enabled. The tc skb extension key is a reference count shared with cls_flower, and the code that would keep it in step is skipped on that path.

Patch 1 fixes the ordering, and drops the reference on the two other paths that take one and never give it back. Patch 2 adds a set-dp command to the openvswitch selftest tool, and two tests that send such a request and check the features the datapath reports afterwards. They fail without the fix and pass with it.

The problem turned up while the YNL spec for this family was being
written: describing the ovs_datapath set command meant reading ovs_dp_change(), where the ordering stands out.

v5:
- Rebased onto current net.
- The two teardown paths clear only OVS_DP_F_TC_RECIRC_SHARING, so a datapath on its way out keeps the bits an upcall in flight still reads. A whole-field store clears OVS_DP_F_UNALIGNED between the two reads in queue_userspace_packet() and pad_packet() (reported by Sashiko).
- queue_userspace_packet() reads the features once and gives that value to pad_packet(), so OVS_DP_CMD_SET cannot split the head room decision from the padding decision either.
- The tests write their diagnostics to stderr, the skip message included. A copy of stdout stayed open in the daemons the suite starts, which kept the kselftest runner reading a pipe that never reached EOF, so the run hung after the last subtest (reported by Matthieu Baerts).
- A datapath that cannot be read, and one that reports no features, are told apart and reported as such instead of as a feature mismatch, and a failed expectation carries its own description.
- checkpatch reports nothing for either patch.

v4: https://lore.kernel.org/netdev/[email protected]/
- Rebased onto current main, the tests say why they failed, and a datapath that cannot be read is no longer reported as a feature mismatch.

v3: https://lore.kernel.org/netdev/[email protected]/
- Cover the recirc bit as well as the dispatch bit.

v2: https://lore.kernel.org/netdev/[email protected]/
- Name the two paths that leaked a reference and fix both.

v1: https://lore.kernel.org/netdev/[email protected]/

Neither leak has a test of its own. The reference count behind the bit is not visible from user space, so the tests read back the features a datapath reports: the reset drops them to zero where a test can see it, and a datapath freed after a failed creation leaves no state to check. The alignment race has no test either, because it needs a set or a destroy to land between two reads of the field on another CPU, which a functional test cannot schedule; the patch removes the second read instead.

One thing this series leaves alone: ovs_add_dp() returns the status of the last command in its body rather than of the add, so the "|| return 1" that follows its calls cannot fail. That predates this series and every OVS test that uses it.

Minxi Hou (2):
net: openvswitch: do not record user features when the change fails selftests/net/openvswitch: check that a failed set keeps the features

 net/openvswitch/datapath.c                    |  58 ++++--
 net/openvswitch/datapath.h                    |   7 +-
 .../testing/selftests/net/openvswitch/config  |   3 +
 .../selftests/net/openvswitch/openvswitch.sh  | 195 ++++++++++++++++++
 .../selftests/net/openvswitch/ovs-dpctl.py    |  65 ++++++
 5 files changed, 310 insertions(+), 18 deletions(-)

base-commit: 2a324a58a084c5cfd7e5a2f55e0786bee170a4a5

Signature · 1 line
2.56.1