Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* Re: [RFC PATCH] libibverbs: add authorization plugin hook for QP creation
       [not found] ` <DS0PR06MB11128BECCB1916D97FFC8372D9F7D2@DS0PR06MB11128.namprd06.prod.outlook.com>
@ 2026-11-16 13:28   ` Leon Romanovsky
  0 siblings, 0 replies; only message in thread
From: Leon Romanovsky @ 2026-11-16 13:28 UTC (permalink / raw)
  To: david.lenrow@illumio.com
  Cc: linux-rdma@vger.kernel.org, yishaih@nvidia.com, jgg@nvidia.com

On Sun, Nov 15, 2026 at 03:38:54PM +0000, david.lenrow@illumio.com wrote:
> Hi,
> 
> I'd like to propose adding an optional authorization hook to
> ibv_create_qp in libibverbs.
> 
> ibv_create_qp dispatches directly to the provider with no
> interposition point.  Other parts of the stack have grown
> optional policy hooks over time, but QP creation — the point
> at which a process gains the ability to issue RDMA operations —
> has none.
> 
> Multi-tenant clusters and shared-fabric deployments increasingly
> need a way to enforce workload identity or access policy at QP
> creation time.  Today the only options are kernel-level hooks
> (eBPF, LSM) or LD_PRELOAD interposition, both of which have
> deployment and portability costs that a simple in-library plugin
> point would avoid.

1. Your email didn't reach the mailing list; you may have sent it as HTML.
2. There must be a very good reason to duplicate existing functionality in
   libibverbs. Deployment and portability costs aren't it.

Thanks


> 
> Proposed change:
> 
> A new environment variable IBV_AUTH_PLUGIN.  When set to a
> shared library path, libibverbs dlopen's it once (via
> pthread_once) and calls its exported symbol before every
> ibv_create_qp dispatch:
> 
>     int ibv_auth_check_qp_create(struct ibv_pd *pd,
>                                  struct ibv_qp_init_attr *attr);
> 
> Returns 0 to allow, non-zero to deny (ibv_create_qp returns
> NULL with errno = EPERM).
> 
> When IBV_AUTH_PLUGIN is unset, the overhead is one pthread_once
> (a memory barrier after the first call) and one NULL pointer
> check.  No new exported symbols, no ABI change, no functional
> change for existing users.
> 
> I chose a plugin over a built-in policy because the right
> policy varies by deployment — cgroup-based identity on
> Kubernetes, namespace checks on shared clusters, site-specific
> allowlists on bare metal.  libibverbs should not embed any of
> these; it just needs the hook.
> 
> I've tested this on SoftRoCE with a plugin that checks the
> calling process's cgroup ID against an allowlist.  Five test
> cases pass: no plugin (baseline), allowed, denied, empty
> allowlist, and invalid plugin path (graceful fallthrough).
> 
> The patch is below.  I'll open a GitHub PR once I have feedback
> on the approach.
> 
> Questions for maintainers:
> 
>   1. Is an env-var-triggered dlopen plugin acceptable, or would
>      you prefer a different configuration mechanism (e.g., a
>      config file in /etc/libibverbs.d/)?
> 
>   2. Should this also cover ibv_create_qp_ex?  The same pattern
>      applies; I kept the initial patch minimal.
> 
>   3. Any concerns about the dlopen happening inside pthread_once
>      on the ibv_create_qp path?  It runs exactly once, but it
>      is on the first call.
> 
> Thanks,
> Dave Lenrow
> Illumio
> 
> ---
> 
>  libibverbs/verbs.c | 57 +++++++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 56 insertions(+), 1 deletion(-)
> 
> diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c
> index 1959fcf..7390605 100644
> --- a/libibverbs/verbs.c
> +++ b/libibverbs/verbs.c
> @@ -54,6 +54,8 @@
>  #include <net/if.h>
>  #include <net/if_arp.h>
>  #include "neigh.h"
> +#include <dlfcn.h>
> +#include <pthread.h>
> 
>  #undef ibv_query_port
> 
> @@ -916,12 +918,65 @@ LATEST_SYMVER_FUNC(ibv_destroy_srq, 1_1, "IBVERBS_1.1",
>       return get_ops(srq->context)->destroy_srq(srq);
>  }
> 
> +/*
> + * Optional authorization plugin for QP creation.
> + *
> + * When IBV_AUTH_PLUGIN names a shared library, it is dlopen'd once and
> + * its ibv_auth_check_qp_create() symbol is called before every
> + * ibv_create_qp().  Returns 0 to allow, negative errno to deny.
> + *
> + * When the variable is unset, the overhead is a pthread_once and a
> + * NULL check per ibv_create_qp call.
> + */
> +typedef int (*ibv_auth_check_fn)(struct ibv_pd *pd,
> +                        struct ibv_qp_init_attr *attr);
> +
> +static ibv_auth_check_fn auth_check;
> +static pthread_once_t auth_once = PTHREAD_ONCE_INIT;
> +
> +static void auth_init(void)
> +{
> +     const char *plugin_path;
> +     void *handle;
> +
> +     plugin_path = getenv("IBV_AUTH_PLUGIN");
> +     if (!plugin_path || !*plugin_path)
> +           return;
> +
> +     handle = dlopen(plugin_path, RTLD_NOW | RTLD_LOCAL);
> +     if (!handle) {
> +           fprintf(stderr, "IBV_AUTH_PLUGIN: cannot load %s: %s\n",
> +                 plugin_path, dlerror());
> +           return;
> +     }
> +
> +     auth_check = (ibv_auth_check_fn)dlsym(handle,
> +                                    "ibv_auth_check_qp_create");
> +     if (!auth_check)
> +           fprintf(stderr, "IBV_AUTH_PLUGIN: %s missing "
> +                 "ibv_auth_check_qp_create symbol\n",
> +                 plugin_path);
> +}
> +
>  LATEST_SYMVER_FUNC(ibv_create_qp, 1_1, "IBVERBS_1.1",
>                struct ibv_qp *,
>                struct ibv_pd *pd,
>                struct ibv_qp_init_attr *qp_init_attr)
>  {
> -     struct ibv_qp *qp = get_ops(pd->context)->create_qp(pd, qp_init_attr);
> +     struct ibv_qp *qp;
> +
> +     pthread_once(&auth_once, auth_init);
> +
> +     if (auth_check) {
> +           int rc = auth_check(pd, qp_init_attr);
> +
> +           if (rc) {
> +                 errno = EPERM;
> +                 return NULL;
> +           }
> +     }
> +
> +     qp = get_ops(pd->context)->create_qp(pd, qp_init_attr);
> 
>       return qp;
>  }
> --
> 2.43.0
> 

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-16 13:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <DS0PR06MB111280BF26C8E962CC252A0669F7E2@DS0PR06MB11128.namprd06.prod.outlook.com>
     [not found] ` <DS0PR06MB11128BECCB1916D97FFC8372D9F7D2@DS0PR06MB11128.namprd06.prod.outlook.com>
2026-11-16 13:28   ` [RFC PATCH] libibverbs: add authorization plugin hook for QP creation Leon Romanovsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox