All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yishai Hadas <yishaih@dev.mellanox.co.il>
To: Knut Omang <knut.omang@oracle.com>
Cc: Doug Ledford <dledford@redhat.com>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org,
	Sean Hefty <sean.hefty@intel.com>,
	Hal Rosenstock <hal.rosenstock@gmail.com>,
	Matan Barak <matanb@mellanox.com>,
	Sagi Grimberg <sagi@grimberg.me>,
	Yishai Hadas <yishaih@mellanox.com>,
	Leon Romanovsky <leonro@mellanox.com>,
	Majd Dibbiny <majd@mellanox.com>,
	Eran Ben Elisha <eranbe@mellanox.com>,
	Or Gerlitz <ogerlitz@mellanox.com>
Subject: Re: [PATCH v2 5/8] ib_uverbs: Add padding to end align ib_uverbs_reg_mr_resp
Date: Tue, 20 Sep 2016 13:45:34 +0300	[thread overview]
Message-ID: <f049462a-5cd0-10bf-320b-c5bc634e93b9@dev.mellanox.co.il> (raw)
In-Reply-To: <aafa787a72e9df9a40b292fb33833e67ffb46c6a.1474049924.git-series.knut.omang@oracle.com>

On 9/16/2016 9:31 PM, Knut Omang wrote:
> The ib_uverbs_reg_mr_resp structure was not 64 bit end aligned
> as required by the protocol. This causes alignment issues
> if a device specific driver needs to transfer extra response
> arguments.
>
> Avoid breaking backward compatibility by improving the handling
> of the length checking in ib_uverbs_reg_mr to consider the case
> where the kernel has been updated, but user space still has
> the old length without padding.
>
> Signed-off-by: Knut Omang <knut.omang@oracle.com>
> ---
>  drivers/infiniband/core/uverbs_cmd.c | 10 ++++++----
>  include/uapi/rdma/ib_user_verbs.h    |  1 +
>  2 files changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/infiniband/core/uverbs_cmd.c b/drivers/infiniband/core/uverbs_cmd.c
> index dbc5885..fa8a717 100644
> --- a/drivers/infiniband/core/uverbs_cmd.c
> +++ b/drivers/infiniband/core/uverbs_cmd.c
> @@ -967,16 +967,18 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
>  	struct ib_pd                *pd;
>  	struct ib_mr                *mr;
>  	int                          ret;
> +	size_t resp_size = sizeof resp;
>
> -	if (out_len < sizeof resp)
> -		return -ENOSPC;
> +	if (out_len < resp_size) {
> +		resp_size = out_len;
> +	}

You don't preserve the minimum response size error checking in your code 
(i.e  -ENOSPC). We can expect an error if outlen is less than the
offset of rkey in ib_uverbs_reg_mr_resp.

Please note that below call to copy_to_user will succeed as it copies 
now based on resp_size and won't return the basic mandatory output.


>  	if (copy_from_user(&cmd, buf, sizeof cmd))
>  		return -EFAULT;
>
>  	INIT_UDATA(&udata, buf + sizeof cmd,
>  		   (unsigned long) cmd.response + sizeof resp,
> -		   in_len - sizeof cmd, out_len - sizeof resp);
> +		   in_len - sizeof cmd, out_len - resp_size);
>
>  	if ((cmd.start & ~PAGE_MASK) != (cmd.hca_va & ~PAGE_MASK))
>  		return -EINVAL;
> @@ -1030,7 +1032,7 @@ ssize_t ib_uverbs_reg_mr(struct ib_uverbs_file *file,
>  	resp.mr_handle = uobj->id;
>
>  	if (copy_to_user((void __user *) (unsigned long) cmd.response,
> -			 &resp, sizeof resp)) {
> +			 &resp, resp_size)) {
>  		ret = -EFAULT;
>  		goto err_copy;
>  	}
> diff --git a/include/uapi/rdma/ib_user_verbs.h b/include/uapi/rdma/ib_user_verbs.h
> index 7f035f4..6b8c9c0 100644
> --- a/include/uapi/rdma/ib_user_verbs.h
> +++ b/include/uapi/rdma/ib_user_verbs.h
> @@ -307,6 +307,7 @@ struct ib_uverbs_reg_mr_resp {
>  	__u32 mr_handle;
>  	__u32 lkey;
>  	__u32 rkey;
> +	__u32 reserved;
>  };
>
>  struct ib_uverbs_rereg_mr {
>

  reply	other threads:[~2016-09-20 10:45 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-16 18:31 [PATCH v2 0/8] SIF related verbs patches Knut Omang
2016-09-16 18:31 ` [PATCH v2 1/8] ib_mad: incoming sminfo SMPs gets discarded if no process_mad function is registered Knut Omang
     [not found]   ` <66d69383a3376018d99c025cd188150f6673b209.1474049924.git-series.knut.omang-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-09-16 20:28     ` Santosh Shilimkar
2016-09-16 20:28       ` Santosh Shilimkar
     [not found]       ` <b57491e1-e36b-c331-8360-557310d15002-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-09-16 20:40         ` Knut Omang
2016-09-16 20:40           ` Knut Omang
     [not found] ` <cover.15d71ac2c57534f1170c2c48374d3841ed75e676.1474049924.git-series.knut.omang-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-09-16 18:31   ` [PATCH v2 2/8] ib_umem: Add a new, more generic ib_umem_get_attrs Knut Omang
2016-09-16 18:31     ` Knut Omang
     [not found]     ` <53550a232af32c5c97ba9fb70faacc2c64d8fceb.1474049924.git-series.knut.omang-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2017-04-05 15:20       ` Knut Omang
2017-04-05 15:20         ` Knut Omang
2016-09-16 18:31   ` [PATCH v2 3/8] ib_umem: With the new ib_umem_get_attrs, simplify ib_umem_get Knut Omang
2016-09-16 18:31     ` Knut Omang
2016-09-16 18:31   ` [PATCH v2 4/8] ib: Add udata argument to create_ah Knut Omang
2016-09-16 18:31     ` Knut Omang
2016-09-16 18:31   ` [PATCH v2 6/8] ib_uverbs: Avoid vendor specific masking of attributes in query_qp Knut Omang
2016-09-16 18:31     ` Knut Omang
2016-09-16 18:31   ` [PATCH v2 7/8] ib_{uverbs/core}: add new ib_create_qp_ex with udata arg Knut Omang
2016-09-16 18:31     ` Knut Omang
2016-09-16 20:30   ` [PATCH v2 0/8] SIF related verbs patches Santosh Shilimkar
2016-09-16 20:30     ` Santosh Shilimkar
2016-09-16 20:42     ` Knut Omang
2016-09-16 18:31 ` [PATCH v2 5/8] ib_uverbs: Add padding to end align ib_uverbs_reg_mr_resp Knut Omang
2016-09-20 10:45   ` Yishai Hadas [this message]
2016-09-20 11:02     ` Knut Omang
2016-09-16 18:31 ` [PATCH v2 8/8] ib_uverbs: Support for kernel implementation of XRC Knut Omang
     [not found]   ` <88ffb8c9407a71069b52e155dde308a36dfaf247.1474049924.git-series.knut.omang-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2016-09-16 19:31     ` Jason Gunthorpe
2016-09-16 19:31       ` Jason Gunthorpe
     [not found]       ` <20160916193102.GB28859-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-09-16 19:49         ` Knut Omang
2016-09-16 19:49           ` Knut Omang

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=f049462a-5cd0-10bf-320b-c5bc634e93b9@dev.mellanox.co.il \
    --to=yishaih@dev.mellanox.co.il \
    --cc=dledford@redhat.com \
    --cc=eranbe@mellanox.com \
    --cc=hal.rosenstock@gmail.com \
    --cc=knut.omang@oracle.com \
    --cc=leonro@mellanox.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=majd@mellanox.com \
    --cc=matanb@mellanox.com \
    --cc=ogerlitz@mellanox.com \
    --cc=sagi@grimberg.me \
    --cc=sean.hefty@intel.com \
    --cc=yishaih@mellanox.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.