]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
ibcore: Fix a use-after-free in ucma_resolve_ip().
authorHans Petter Selasky <hselasky@FreeBSD.org>
Wed, 16 Jun 2021 13:01:47 +0000 (15:01 +0200)
committerHans Petter Selasky <hselasky@FreeBSD.org>
Mon, 12 Jul 2021 12:22:32 +0000 (14:22 +0200)
commitc6ccb08686f3b92c12778b4b903431b2ce71ec2c
treebbd3440740028010cb158eecd8f503d7b349b916
parent20fea7ac64683b064ffe4cefa750e46ba20de4f9
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
sys/ofed/drivers/infiniband/core/ib_ucma.c