From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796305378; b=0Vf576FHLfZ7wEmPPTcDqvLCW3ko/Q76nAT6qhOb0sB/DrVuCaNvTXiYJS8nhOFQRh/X rwZk5Dg5r+Nz3tOjLtaDh4m+7yneoZHVlcWGupXqr+LzvZNHPsYFCPmGpudc5quydW4ab m+3jko6cLMoNN8zlE9t5UmSgknW+V0AoF/X/VK1ArdRsE2m3qDORCR6DOuFveD3v+fZLF icjr5lBwPOc6EPjnKMz3GxFrNCZfVkfb80S+YGVO0RMt7BiZ9v+PzNO1TuQPLQCT2hkZK ULXbzq+jC2xYcuTJEPo0aagDavx/phO7BrxUL3E4R3v9gzxmos74XwTKYnrjZ441XVA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796305378; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=9Zcxg/ld+rslYJIzGUlG94ahil/DyMt+rPOVu3Ti6V4=; b=MQLwz0dOHkIci0SzI6CdWgaq3vh+TNj51DRueOgaYNCqXP+s/+dyl5XbQz4ThMA6t+Bn C/isNg+8wZbpf4WQ4vZQqpCHgUrvCHSo0mRI/f/fA2gu/y6MIABXs3i5Ejnun7yr0RKMa AGE7TkAbxzu/xlGbP5Tnp9nONoozd+Ju0EgKD27XUvS1WmzyF/YQR+s4ESFmUrLgmHDgX 59OkykSOX/0HtwWZxatUJQUnQpRnWLa7kL+p4ZNAcEOIfCgOPC6wwDMGnNZkbBV6iqyir STzNI5aAYl+6YdjlBUVIChYc3jdBIw5HeGSZKTMyjVbhqgj/rFiNwxp0n2GREn2W6BA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GeLpyQKt; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F123606A337 for ; Thu, 3 Dec 2026 13:42:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GeLpyQKt Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9EC561F0089A; Thu, 3 Dec 2026 13:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796305377; bh=9Zcxg/ld+rslYJIzGUlG94ahil/DyMt+rPOVu3Ti6V4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=GeLpyQKtl0Ljl+BZU1yF/xqvwvWx/kvk5jCf2Y2lRwzJZX+niTsZT7vkte+3bEH4z S0/FlCzoi5+z+a8D5DetGNPOeglDKqHXl4CzV8NUBmzm1CatWJdnDQNVHhRcYQUmaY yncnK/4v68E4rWLmyfgQX8OziWq1Dr5AhP9WhcuJpOmZXj0s+v9eJ5wM6H/hfQ8G+r uIx2Zb1rSL/TdXyIHKgG1PjcouBbLP5kliqwJiJRoH5iXhuMwo4BrOJO8nj+rgf5Zs pufDSYQNsi1aA945Xp8n/ZPNcra2utrrqX2fhIyK2vNMSeMQJtHMcNbtQOAmLgfKCT 9ieEqjDrCu2zQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH rdma v10 7/7] RDMA/zrdma: Implement context, PD, and mmap operations Reply-To: sashiko-reviews@lists.linux.dev To: "Yanze Zhang" Cc: linux-rdma@vger.kernel.org In-Reply-To: <20261203124928.48716-8-zhang.yanze@zte.com.cn> References: <20261203124928.48716-1-zhang.yanze@zte.com.cn> <20261203124928.48716-8-zhang.yanze@zte.com.cn> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Thu, 03 Dec 2026 13:42:57 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 6 potential issues to consider: - [High] RDMA/zrdma: missing disassociate_ucontext hangs device removal - [Medium] RDMA/zrdma: outlen < sizeof(uresp) breaks V1/V2 ucontext and UAPI growth - [Medium] RDMA/zrdma: unratelimited pr_err() reachable from userspace verbs - [Medium] RDMA/zrdma: zxdh_alloc_ucontext() reports unimplemented flags and zero limits - [Medium] RDMA/zrdma: zxdh_mmap() exposes adjacent BAR 0 MMIO on >4K PAGE_SIZE - [Low] RDMA/zrdma: missing zero check on reserved fields in zxdh_alloc_ucontext() -- commit ea4f0663a81787280ffe1f1f535dd9dec3ffd022 Author: Yanze Zhang RDMA/zrdma: Implement context, PD, and mmap operations This patch implements Protection Domain (PD) allocation and deallocation, user context allocation and deallocation, and doorbell mmap support for the zrdma driver. > diff --git a/drivers/infiniband/hw/zrdma/zrdma_verbs.c b/drivers/infiniba= nd/hw/zrdma/zrdma_verbs.c > index a410ef4521ad5..fb33bf1bde615 100644 > --- a/drivers/infiniband/hw/zrdma/zrdma_verbs.c > +++ b/drivers/infiniband/hw/zrdma/zrdma_verbs.c [ ... ] > + err =3D zxdh_alloc_rsrc(rf, rf->allocated_pds, rf->max_pd, &pd_id, > + &rf->next_pd, "PD"); > + if (err) { > + pr_warn_ratelimited("zrdma: PD allocation failed err=3D%d\n", > + err); > + return err; > + } [Severity: Medium] Can an unprivileged user flood the kernel log here once the PD pool is exhausted? zxdh_alloc_pd() ratelimits its own warning, but zxdh_alloc_rsrc() emits an unratelimited pr_err() on every failed allocation. The error paths in zxdh_alloc_ucontext() (when srq_db_mmap_entry is NULL) and zxdh_mmap() (when rdma_user_mmap_io() fails) also call unratelimited pr_err() despite neighboring checks using pr_err_ratelimited(). [ ... ] > +static int zxdh_alloc_ucontext(struct ib_ucontext *uctx, struct ib_udata= *udata) > +{ > + struct zxdh_ucontext *ucontext =3D to_ucontext(uctx); > + struct zxdh_alloc_ucontext_resp uresp =3D {}; > + struct ib_device *ibdev =3D uctx->device; > + struct zxdh_device *zdev =3D to_zdev(ibdev); > + struct zxdh_alloc_ucontext_req req =3D {}; > + u64 srq_db_mmap_size; > + int err; > + > + /* The request is validated against the size of the structure, so > + * that a truncated or an oversized buffer is rejected instead of > + * being read partially. > + */ > + err =3D ib_copy_validate_udata_in(udata, req, rsvd8); > + if (err) > + return err; [Severity: Low] Should zxdh_alloc_ucontext() reject non-zero values in req.rsvd32 and req.rsvd8? ib_copy_validate_udata_in() only checks trailing bytes beyond sizeof(req), not reserved fields inside the struct. Allowing uninitialized bytes in these fields will prevent repurposing them in future ABI revisions without breaking userspace. [ ... ] > + /* The response carries the keys of the doorbell mappings, so the > + * user has to provide a buffer for the whole of it. A short buffer > + * is reported instead of being silently truncated. > + */ > + if (udata->outlen < sizeof(uresp)) > + return -ENOSPC; [Severity: Medium] Does this sizeof(uresp) check break V1 and V2 userspace contexts and future response extensions? struct zxdh_alloc_ucontext_resp notes that V1 and V2 contexts do not have the trailing srq_db_mmap_size field, and zxdh_alloc_ucontext() later maps only PAGE_SIZE for them, yet this check rejects any response buffer shorter than the full V3 struct with -ENOSPC. Both zxdh_alloc_ucontext() and zxdh_alloc_pd() check udata->outlen against sizeof(uresp) instead of a fixed offsetofend() minimum, which also prevents extending either response struct without breaking existing userspace. [ ... ] > + uresp.rdma_tool_flags =3D > + ZXDH_QP_EXTEND_OP | ZXDH_CAPTURE | ZXDH_GET_HW_DATA | > + ZXDH_GET_HW_OBJECT_DATA | ZXDH_CHECK_HW_HEALTH | > + ZXDH_RDMA_TOOL_CFG_DEV_PARAM | ZXDH_RDMA_TOOL_READ_RAM | > + ZXDH_RDMA_TOOL_DEVX_MODIFY_CQ | ZXDH_RDMA_SET_CREDIT_CAP | > + ZXDH_RDMA_SWITCH | ZXDH_RDMA_TOOL_DEVX_EXT_MEM | > + ZXDH_RDMA_TOOL_PRIV_EXT | > + ZXDH_RDMA_TOOL_IOVA_CAP; > + > + uresp.feature_flags =3D ZXDH_FEATURE_RTS_AE | ZXDH_FEATURE_CQ_RESIZE | > + ZXDH_FEATURE_64_BYTE_CQE; [Severity: Medium] Why does zxdh_alloc_ucontext() advertise tool and feature flags for operations that are not implemented? None of the DEVX/tool ioctls or CQ/QP verbs (such as resize_cq) exist in zxdh_dev_ops or driver_def, which contradicts zxdh_query_device()'s policy of reporting only implemented capabilities and breaks userspace feature discovery once these bits are shipped. The ZXDH_FEATURE_* constants are also only in private zrdma_defs.h rather than the UAPI header, and the documented max_pds, max_qps, and wq_size response fields are always left zero. [ ... ] > + pfn =3D (entry->bar_offset + > + pci_resource_start(ucontext->zdev->rf->pcidev, 0)) >> > + PAGE_SHIFT; > + > + switch (entry->mmap_flag) { > + case ZXDH_MMAP_IO_NC: > + ret =3D rdma_user_mmap_io(context, vma, pfn, PAGE_SIZE, > + pgprot_noncached(vma->vm_page_prot), > + rdma_entry); > + break; > + case ZXDH_MMAP_IO_NC_BY_SIZE: > + ret =3D rdma_user_mmap_io(context, vma, pfn, > + vma->vm_end - vma->vm_start, > + pgprot_noncached(vma->vm_page_prot), > + rdma_entry); > + break; [Severity: Medium] Can this expose adjacent BAR 0 registers read/write to unprivileged userspace on 16K or 64K PAGE_SIZE kernels? CQ_DB_BAR_OFF (0x43000), SQ_DB_BAR_OFF (0x4c000), and SRQ_DB_BAR_OFF (0x62000) are only 4K-aligned, so shifting down by PAGE_SHIFT and mapping full host pages exposes up to 40 KB (16K pages) or 120 KB (64K pages) of surrounding BAR 0 MMIO space via /dev/infiniband/uverbsX. Unless hardware guarantees 64K isolation around those doorbell regions, consider rejecting PAGE_SIZE > SZ_4K or gating non-4K mappings behind capable(CAP_SYS_RAWIO). [ ... ] > const struct ib_device_ops zxdh_dev_ops =3D { > .owner =3D THIS_MODULE, > .driver_id =3D RDMA_DRIVER_ZRDMA, > .uverbs_abi_ver =3D ZXDH_ABI_VER, > .dealloc_driver =3D zxdh_ib_dealloc_device, > + .alloc_pd =3D zxdh_alloc_pd, > + .alloc_ucontext =3D zxdh_alloc_ucontext, > + .dealloc_pd =3D zxdh_dealloc_pd, > + .dealloc_ucontext =3D zxdh_dealloc_ucontext, > .query_device =3D zxdh_query_device, > .query_port =3D zxdh_query_port, > .query_pkey =3D zxdh_query_pkey, > .get_link_layer =3D zxdh_get_link_layer, > .get_port_immutable =3D zxdh_roce_port_immutable, > .get_dev_fw_str =3D zxdh_get_dev_fw_str, > + .mmap =3D zxdh_mmap, > + .mmap_free =3D zxdh_mmap_free, > + > + INIT_RDMA_OBJ_SIZE(ib_pd, zxdh_pd, ibpd), > + INIT_RDMA_OBJ_SIZE(ib_ucontext, zxdh_ucontext, ibucontext), > }; [Severity: High] Will omitting .disassociate_ucontext hang device removal whenever a userspace client holds a uverbs fd open? When .disassociate_ucontext is NULL, ib_uverbs_remove_one() skips ib_uverbs_free_hw_resources() and blocks indefinitely in wait_for_completion(&uverbs_dev->comp), wedging zxdh_remove() during PF reset, unbind, or PCI hot-unplug while leaving live BAR 0 MMIO mappings un-zapped. It also causes ib_device_set_netns_put() to reject network namespace moves with -EOPNOTSUPP. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203124928.4871= 6-1-zhang.yanze@zte.com.cn?part=3D7