On Thu, Oct 11, 2018 at 08:14:28AM +0300, Leon Romanovsky wrote: > On Wed, Oct 10, 2018 at 09:39:05PM +0000, Parav Pandit wrote: > > > > > > > From: linux-rdma-owner@xxxxxxxxxxxxxxx <linux-rdma- > > > owner@xxxxxxxxxxxxxxx> On Behalf Of Leon Romanovsky > > > Sent: Wednesday, October 10, 2018 1:19 AM > > > To: Doug Ledford <dledford@xxxxxxxxxx>; Jason Gunthorpe > > > <jgg@xxxxxxxxxxxx> > > > Cc: Leon Romanovsky <leonro@xxxxxxxxxxxx>; RDMA mailing list <linux- > > > rdma@xxxxxxxxxxxxxxx> > > > Subject: [PATCH rdma-next v3 2/2] RDMA/nldev: Allow IB device rename > > > through RDMA netlink > > > > > > From: Leon Romanovsky <leonro@xxxxxxxxxxxx> > > > > > > Provide an option to rename IB device name through RDMA netlink and limit > > > it to users with ADMIN capability only. > > > > > > Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> > > > drivers/infiniband/core/nldev.c | 34 > > > ++++++++++++++++++++++++++++++++++ > > > include/uapi/rdma/rdma_netlink.h | 3 ++- > > > 2 files changed, 36 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/infiniband/core/nldev.c b/drivers/infiniband/core/nldev.c > > > index ba5403fbcd88..573399e3ccc1 100644 > > > +++ b/drivers/infiniband/core/nldev.c > > > @@ -646,6 +646,36 @@ static int nldev_get_doit(struct sk_buff *skb, struct > > > nlmsghdr *nlh, > > > return err; > > > } > > > > > > +static int nldev_set_doit(struct sk_buff *skb, struct nlmsghdr *nlh, > > > + struct netlink_ext_ack *extack) > > > +{ > > > + struct nlattr *tb[RDMA_NLDEV_ATTR_MAX]; > > > + struct ib_device *device; > > > + u32 index; > > > + int err; > > > + > > > + err = nlmsg_parse(nlh, 0, tb, RDMA_NLDEV_ATTR_MAX - 1, > > > nldev_policy, > > > + extack); > > > + if (err || !tb[RDMA_NLDEV_ATTR_DEV_INDEX]) > > > + return -EINVAL; > > > + > > > + index = nla_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); > > > + device = ib_device_get_by_index(index); > > > + if (!device) > > > + return -EINVAL; > > > + > > > + if (tb[RDMA_NLDEV_ATTR_DEV_NAME]) { > > > + char name[IB_DEVICE_NAME_MAX] = {}; > > > + > > > + nla_strlcpy(name, tb[RDMA_NLDEV_ATTR_DEV_NAME], > > > + IB_DEVICE_NAME_MAX); > > > > I prefer sizeof(name) instead of IB_DEVICE_NAME_MAX in nla_strlcpy(). But its ok. > > IB_DEVICE_NAME_MAX and name are part of KAPI, it won't be changed > without introduction of new define and usage here emphasize it. strlcpy is the wrong thing here, if userspace provides a string too long for the kernel then it should fail not truncate. Jason