Skip to content

net/rds: Fix use-after-free in RDS/IB for non-init namespaces

Allison Henderson linux-rdma netdev 2 versions – Applied

Status from this message: This series was applied to netdev/net.git (main)

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest2 patches 0 repliesApplied 2/2
  2. v12 patches 5 repliesSuperseded

Changes in v2 from the cover letter

[PATCH net v2 1/2] net/rds: Optimize rds_ib_laddr_check
- Added missing author sob
- Added ipv6_addr_v4mapped check

Patches in v2 All 2 applied

#Subject and filesSizeRepliesApplied
1/2net/rds: Optimize rds_ib_laddr_checknet/rds/ib.c net/rds/ib.h net/rds/ib_rdma.c+20 -30 repliesApplied
2/2net/rds: Restrict use of RDS/IB to the initial network namespacenet/rds/af_rds.c net/rds/ib.c+12 -20 repliesApplied

Reviews trailers per patch

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

Read the v2 thread

Cover letter [PATCH net v2 0/2] net/rds: Fix use-after-free in RDS/IB for non-init namespaces

This series fixes syzbot bug da8e060735ae02c8f3d1
https://syzkaller.appspot.com/bug?extid=da8e060735ae02c8f3d1

The report finds a use-after-free bug where ib connections access an invalid network namespace after it has been freed. The stack is:

    rds_rdma_cm_event_handler_cmn
      rds_conn_path_drop
        rds_destroy_pending
          check_net()  <-- use-after-free

This is initially introduced in:
d5a8ac28a7ff ("RDS-TCP: Make RDS-TCP work correctly when it is set up in a netns other than init_net").

Here, we made RDS aware of the namespace by storing a net pointer in each connection. But it is not explicitly restricted to init_net in the case of ib. The RDS/TCP transport has its own pernet exit handler (rds_tcp_exit_net) that destroys connections when a namespace is torn down. But RDS/IB does not support more than the initial namespace and has no such handler. The initial namespace is statically allocated, and never torn down, so it always has at least one reference.

Allowing non init namespaces that do not have a persistent reference means that when their refcounts drop to zero, they are released through cleanup_net(). Which would call any registered pernet clean up handlers if it had any, but since they don't in this case, the extra rds_connections remain with stale c_net pointers. Which are then accessed later causing the use-after-free bug.

So, the simple fix is to disallow more than the initial namespace to be created in the case of ib connections.

Fixes are ported from UEK patches found here:

https://github.com/oracle/linux-uek/commit/8ed9a82376b7
Patch 1 is a prerequisite optimization to rds_ib_laddr_check() that avoids excessive rdma_bind_addr() calls during transport probing by first checking rds_ib_get_device(). This is needed because patch 2 adds a namespace check at the top of the same function.

    UEK: 8ed9a82376b7 ("rds: ib: Optimize rds_ib_laddr_check")

https://github.com/oracle/linux-uek/commit/bd9489a08004
Patch 2 restricts RDS/IB to the initial network namespace. It adds checks in both rds_ib_laddr_check() and rds_set_transport() to reject IB use from non-init namespaces with -EPROTOTYPE. This prevents the use-after-free by ensuring IB connections cannot exist in namespaces that may be torn down.

UEK: bd9489a08004 ("net/rds: Restrict use of RDS/IB to the initial network namespace")

Questions, comments and feedback appreciated!

Thank you!
Allison

Change Log:
v2:
[PATCH net v2 1/2] net/rds: Optimize rds_ib_laddr_check
- Added missing author sob
- Added ipv6_addr_v4mapped check

[PATCH net v2 2/2] net/rds: Restrict use of RDS/IB to the initial
- Addressed comment consistency nits
- Addressed commit message nits

Greg Jumper (1):
net/rds: Restrict use of RDS/IB to the initial network namespace

Håkon Bugge (1):
net/rds: Optimize rds_ib_laddr_check

 net/rds/af_rds.c  | 10 ++++++++--
 net/rds/ib.c      | 24 ++++++++++++++++++++++--
 net/rds/ib.h      |  1 +
 net/rds/ib_rdma.c |  2 +-
 4 files changed, 32 insertions(+), 5 deletions(-)
Signature · 1 line
2.43.0