From: Leon Romanovsky <leon@kernel.org>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Kalesh AP <kalesh-anakkur.purayil@broadcom.com>,
linux-rdma@vger.kernel.org,
Selvin Xavier <selvin.xavier@broadcom.com>,
Sriharsha Basavapatna <sriharsha.basavapatna@broadcom.com>,
patches@lists.linux.dev
Subject: Re: [PATCH 03/10] RDMA: Add ib_respond_udata()
Date: Fri, 13 Feb 2026 12:10:53 +0200 [thread overview]
Message-ID: <20260213101053.GJ12887@unreal> (raw)
In-Reply-To: <3-v1-89ea7d615ba4+636-bnxt_re_uapi_jgg@nvidia.com>
On Thu, Feb 05, 2026 at 09:45:37PM -0400, Jason Gunthorpe wrote:
> Wrap the common copy_to_user() pattern used in drivers and enhance it
> to zero pad as well.
>
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
> ---
> include/rdma/ib_verbs.h | 32 ++++++++++++++++++++++++++++++++
> 1 file changed, 32 insertions(+)
>
> diff --git a/include/rdma/ib_verbs.h b/include/rdma/ib_verbs.h
> index bb61cab2ef9a06..c0dd82a77e7a13 100644
> --- a/include/rdma/ib_verbs.h
> +++ b/include/rdma/ib_verbs.h
> @@ -3177,6 +3177,38 @@ static inline int _ib_copy_validate_udata_in(struct ib_udata *udata, void *req,
> ret; \
> })
>
> +static inline int _ib_respond_udata(struct ib_udata *udata, const void *src,
> + size_t len)
> +{
> + size_t copy_len;
> +
> + copy_len = min(len, udata->outlen);
Don't you need to check that udata->outlen is larger than zero?
Thanks
> + if (copy_to_user(udata->outbuf, src, copy_len))
> + return -EFAULT;
> + if (copy_len < udata->outlen) {
> + if (clear_user(udata->outbuf + copy_len,
> + udata->outlen - copy_len))
> + return -EFAULT;
> + }
> + return 0;
> +}
> +
> +/**
> + * ib_respond_udata - Copy a driver data response to userspace
> + * @_udata: The system calls ib_udata struct
> + * @_rep: Kernel buffer containing the response driver data on the stack
> + *
> + * Copy driver data response structures back to userspace in a way that
> + * is forwards and backwards compatible. Longer kernel structs are truncated,
> + * userspace has made some kind of error if it needed the truncated information.
> + * Shorter structs are zero padded.
> + */
> +#define ib_respond_udata(_udata, _rep) \
> + ({ \
> + static_assert(__same_type(*(typeof(&(_rep)))0, (_rep))); \
> + _ib_respond_udata(_udata, &(_rep), sizeof(_rep)); \
> + })
> +
> /**
> * ib_modify_qp_is_ok - Check that the supplied attribute mask
> * contains all required attributes and no attributes not allowed for
> --
> 2.43.0
>
>
next prev parent reply other threads:[~2026-02-13 10:10 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-06 1:45 [PATCH 00/10] Provide udata helpers and use them in bnxt_re Jason Gunthorpe
2026-02-06 1:45 ` [PATCH 01/10] RDMA: Add ib_copy_validate_udata_in() Jason Gunthorpe
2026-02-09 6:11 ` Junxian Huang
2026-02-09 14:06 ` Jason Gunthorpe
2026-02-06 1:45 ` [PATCH 02/10] RDMA: Add ib_copy_validate_udata_in_cm() Jason Gunthorpe
2026-02-06 1:45 ` [PATCH 03/10] RDMA: Add ib_respond_udata() Jason Gunthorpe
2026-02-13 10:10 ` Leon Romanovsky [this message]
2026-02-13 12:43 ` Jason Gunthorpe
2026-02-13 15:37 ` Leon Romanovsky
2026-02-13 15:48 ` Jason Gunthorpe
2026-02-16 23:14 ` Jason Gunthorpe
2026-02-17 7:48 ` Leon Romanovsky
2026-02-06 1:45 ` [PATCH 04/10] RDMA: Add ib_is_udata_in_empty() Jason Gunthorpe
2026-02-13 10:22 ` Leon Romanovsky
2026-02-13 12:56 ` Jason Gunthorpe
2026-02-06 1:45 ` [PATCH 05/10] RDMA: Provide documentation about the uABI compatibility rules Jason Gunthorpe
2026-02-13 10:23 ` Leon Romanovsky
2026-02-13 12:56 ` Jason Gunthorpe
2026-02-13 15:57 ` Leon Romanovsky
2026-02-18 0:01 ` Jason Gunthorpe
2026-02-06 1:45 ` [PATCH 06/10] RDMA/bnxt_re: Add compatibility checks to the uapi path Jason Gunthorpe
2026-02-08 19:29 ` Zhu Yanjun
2026-02-06 1:45 ` [PATCH 07/10] RDMA/bnxt_re: Add compatibility checks to the uapi path for no data Jason Gunthorpe
2026-02-13 10:34 ` Leon Romanovsky
2026-02-06 1:45 ` [PATCH 08/10] RDMA/bnxt_re: Add missing comp_mask validation Jason Gunthorpe
2026-02-06 1:45 ` [PATCH 09/10] RDMA/bnxt_re: Use ib_respond_udata() Jason Gunthorpe
2026-02-13 10:40 ` Leon Romanovsky
2026-02-13 12:42 ` Jason Gunthorpe
2026-02-13 15:39 ` Leon Romanovsky
2026-02-06 1:45 ` [PATCH 10/10] RDMA/bnxt_re: Add BNXT_RE_UCNTX_CMASK_UAPI_COMPAT_SUPPORTED Jason Gunthorpe
2026-02-06 12:20 ` [PATCH 00/10] Provide udata helpers and use them in bnxt_re Sriharsha Basavapatna
2026-02-06 19:11 ` Jason Gunthorpe
2026-02-09 12:28 ` Sriharsha Basavapatna
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260213101053.GJ12887@unreal \
--to=leon@kernel.org \
--cc=jgg@nvidia.com \
--cc=kalesh-anakkur.purayil@broadcom.com \
--cc=linux-rdma@vger.kernel.org \
--cc=patches@lists.linux.dev \
--cc=selvin.xavier@broadcom.com \
--cc=sriharsha.basavapatna@broadcom.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox