Linux-RDMA Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH for-next] RDMA/core: Fix storing node description
@ 2020-01-13 19:12 Kamal Heib
  2020-01-13 20:16 ` Jason Gunthorpe
  0 siblings, 1 reply; 3+ messages in thread
From: Kamal Heib @ 2020-01-13 19:12 UTC (permalink / raw)
  To: linux-rdma; +Cc: Jason Gunthorpe, Doug Ledford, Kamal Heib

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
--- a/drivers/infiniband/core/sysfs.c
+++ 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);
 	ret = ib_modify_device(dev, IB_DEVICE_MODIFY_NODE_DESC, &desc);
 	if (ret)
 		return ret;
-- 
2.21.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for-next] RDMA/core: Fix storing node description
  2020-01-13 19:12 [PATCH for-next] RDMA/core: Fix storing node description Kamal Heib
@ 2020-01-13 20:16 ` Jason Gunthorpe
  2020-01-14  8:12   ` Kamal Heib
  0 siblings, 1 reply; 3+ messages in thread
From: Jason Gunthorpe @ 2020-01-13 20:16 UTC (permalink / raw)
  To: Kamal Heib; +Cc: linux-rdma, Doug Ledford

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH for-next] RDMA/core: Fix storing node description
  2020-01-13 20:16 ` Jason Gunthorpe
@ 2020-01-14  8:12   ` Kamal Heib
  0 siblings, 0 replies; 3+ messages in thread
From: Kamal Heib @ 2020-01-14  8:12 UTC (permalink / raw)
  To: Jason Gunthorpe; +Cc: linux-rdma, Doug Ledford

On Mon, Jan 13, 2020 at 04:16:42PM -0400, Jason Gunthorpe wrote:
> 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;
>

OK, I'll send a V2 soon.

> Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-13 19:12 [PATCH for-next] RDMA/core: Fix storing node description Kamal Heib
2020-01-13 20:16 ` Jason Gunthorpe
2020-01-14  8:12   ` Kamal Heib

Linux-RDMA Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rdma/0 linux-rdma/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rdma linux-rdma/ https://lore.kernel.org/linux-rdma \
		linux-rdma@vger.kernel.org
	public-inbox-index linux-rdma

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rdma


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git