History log of /freebsd-current/sys/ofed/drivers/infiniband/core/ib_ucma.c
Revision Date Author Comments
# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 66a0bc21 13-Jun-2022 Hans Petter Selasky <hselasky@FreeBSD.org>

ibcore: Fix use-after-free access in ucma_close()

The error in ucma_create_id() left ctx in the list of contexts belong
to ucma file descriptor. The attempt to close this file descriptor causes
to use-after-free accesses while iterating over such list.

Linux commit:
ed65a4dc22083e73bac599ded6a262318cad7baf

PR: 264650
MFC after: 1 week
Sponsored by: NVIDIA Networking


# c6ccb086 16-Jun-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

ibcore: Fix a use-after-free in ucma_resolve_ip().

There is a race condition between ucma_close() and ucma_resolve_ip():

CPU0 CPU1
ucma_resolve_ip(): ucma_close():

ctx = ucma_get_ctx(file, cmd.id);

list_for_each_entry_safe(ctx, tmp, &file->ctx_list, list) {
mutex_lock(&mut);
idr_remove(&ctx_idr, ctx->id);
mutex_unlock(&mut);
...
mutex_lock(&mut);
if (!ctx->closing) {
mutex_unlock(&mut);
rdma_destroy_id(ctx->cm_id);
...
ucma_free_ctx(ctx);
}

ret = rdma_resolve_addr();
ucma_put_ctx(ctx);

Before idr_remove(), ucma_get_ctx() could still find the ctx
and after rdma_destroy_id(), rdma_resolve_addr() may still
access id_priv pointer. Also, ucma_put_ctx() may use ctx after
ucma_free_ctx() too.

ucma_close() should call ucma_put_ctx() too which tests the
refcnt and waits for the last one releasing it. The similar
pattern is already used by ucma_destroy_id().

Linux commit:
5fe23f262e0548ca7f19fb79f89059a60d087d22

MFC after: 1 week
Reviewed by: kib
Sponsored by: Mellanox Technologies // NVIDIA Networking


# 20fea7ac 16-Jun-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

ibcore: Define option to set ack timeout.

Define new option in 'rdma_set_option' to override calculated QP timeout
when requested to provide QP attributes to modify a QP.

At the same time, pack tos_set to be bitfield.

Linux commit:
2c1619edef61a03cb516efaa81750784c3071d10

MFC after: 1 week
Reviewed by: kib
Sponsored by: Mellanox Technologies // NVIDIA Networking


# 1866c98e 06-Jul-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Infiniband clients must be attached and detached in a specific order in ibcore.

Currently the linking order of the infiniband, IB, modules decide in which
order the clients are attached and detached. For example one IB client may
use resources from another IB client. This can lead to a potential deadlock
at shutdown. For example if the ipoib is unregistered after the ib_multicast
client is detached, then if ipoib is using multicast addresses a deadlock may
happen, because ib_multicast will wait for all its resources to be freed before
returning from the remove method.

Fix this by using module_xxx_order() instead of module_xxx().

Differential Revision: https://reviews.freebsd.org/D23973
MFC after: 1 week
Sponsored by: Mellanox Technologies


# cda1e10c 17-Jul-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Use __FBSDID() for RCS tags in ibcore.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 855ad7cf 17-Jul-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Check AF family prior resolving address and introduce safer rdma_addr_size() variants in ibcore.

Garbage supplied by user will cause to UCMA module provide zero
memory size for memcpy(), because it wasn't checked, it will
produce unpredictable results in rdma_resolve_addr().

There are several places in the ucma ABI where userspace can pass in a
sockaddr but set the address family to AF_IB. When that happens,
rdma_addr_size() will return a size bigger than sizeof struct sockaddr_in6,
and the ucma kernel code might end up copying past the end of a buffer
not sized for a struct sockaddr_ib.

Fix this by introducing new variants
int rdma_addr_size_in6(struct sockaddr_in6 *addr);
int rdma_addr_size_kss(struct __kernel_sockaddr_storage *addr);

that are type-safe for the types used in the ucma ABI and return 0 if the
size computed is bigger than the size of the type passed in. We can use
these new variants to check what size userspace has passed in before
copying any addresses.

Linux commit:
2975d5de6428ff6d9317e9948f0968f7d42e5d74
09abfe7b5b2f442a85f4c4d59ecf582ad76088d7
84652aefb347297aa08e91e283adf7b18f77c2d5

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 41decb45 17-Jul-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Check for a cm_id->device in all user calls that need it in ibcore.

This was done by auditing all callers of ucma_get_ctx and switching the
ones that unconditionally touch ->device to ucma_get_ctx_dev. This covers
a little less than half of the call sites.

The 11 remaining call sites to ucma_get_ctx() were manually audited.

Linux commit:
4b658d1bbc16605330694bb3ef2570c465ef383d
8b77586bd8fe600d97f922c79f7222c46f37c118

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 89a0812f 17-Jul-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Restore initialisation of ctx->uid in ucma_create_id() in ibcore.

This fixes a regression issue after r336373.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 7477a89a 17-Jul-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Ensure that CM_ID exists prior to access it in ibcore.

Prior to access UCMA commands, the context should be initialized
and connected to CM_ID with ucma_create_id(). In case user skips
this step, he can provide non-valid ctx without CM_ID and cause
to multiple NULL dereferences.

Also there are situations where the create_id can be raced with
other user access, ensure that the context is only shared to
other threads once it is fully initialized to avoid the races.

Linux commit:
e8980d67d6017c8eee8f9c35f782c4bd68e004c9

MFC after: 1 week
Sponsored by: Mellanox Technologies


# 09938b21 05-Mar-2018 Hans Petter Selasky <hselasky@FreeBSD.org>

Add missing FreeBSD tags and SVN properties to ibcore.

MFC after: 1 week
Sponsored by: Mellanox Technologies


# c4b28ce0 16-Sep-2017 Hans Petter Selasky <hselasky@FreeBSD.org>

Remove no longer needed linux_poll_wakeup() calls. This is now handled by
"wake_up()" in the LinuxKPI. Accessing the file pointer directly might cause
use after free issues.

Sponsored by: Mellanox Technologies


# 9f715dc1 03-Jul-2017 Hans Petter Selasky <hselasky@FreeBSD.org>

ibcore: Delete old files and add new ones missed in the initial commit
for this projects branch.

Sponsored by: Mellanox Technologies