linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@ziepe.ca>
To: Kamal Heib <kamalheib1@gmail.com>
Cc: linux-rdma@vger.kernel.org, Doug Ledford <dledford@redhat.com>
Subject: Re: [PATCH for-next] RDMA/core: Fix storing node description
Date: Mon, 13 Jan 2020 16:16:42 -0400	[thread overview]
Message-ID: <20200113201642.GC9861@ziepe.ca> (raw)
In-Reply-To: <20200113191226.14903-1-kamalheib1@gmail.com>

On Mon, Jan 13, 2020 at 09:12:26PM +0200, Kamal Heib wrote:
> Make sure to return -EINVAL when the supplied string is bigger then
> IB_DEVICE_NODE_DESC_MAX.
> 
> Fixes: c5bcbbb9fe00 ("IB: Allow userspace to set node description")
> Signed-off-by: Kamal Heib <kamalheib1@gmail.com>
>  drivers/infiniband/core/sysfs.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
> index 087682e6969e..55f4d7c1fcc9 100644
> +++ b/drivers/infiniband/core/sysfs.c
> @@ -1265,10 +1265,13 @@ static ssize_t node_desc_store(struct device *device,
>  	struct ib_device_modify desc = {};
>  	int ret;
>  
> +	if (count > IB_DEVICE_NODE_DESC_MAX)
> +		return -EINVAL;
> +
>  	if (!dev->ops.modify_device)
>  		return -EOPNOTSUPP;
>  
> -	memcpy(desc.node_desc, buf, min_t(int, count, IB_DEVICE_NODE_DESC_MAX));
> +	memcpy(desc.node_desc, buf, count);

I think this should just be written as

if (strscpy(desc.node_desc, buf, sizeof(desc.node_desc)) == -E2BIG)
    return -EINVAL;

Jason

  reply	other threads:[~2020-01-13 20:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-13 19:12 [PATCH for-next] RDMA/core: Fix storing node description Kamal Heib
2020-01-13 20:16 ` Jason Gunthorpe [this message]
2020-01-14  8:12   ` Kamal Heib

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=20200113201642.GC9861@ziepe.ca \
    --to=jgg@ziepe.ca \
    --cc=dledford@redhat.com \
    --cc=kamalheib1@gmail.com \
    --cc=linux-rdma@vger.kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).