Re: [PATCH for-4.14-rc] RDMA/netlink: Restore nlmsg_len calculation in ibnl_put_attr

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 28, 2017 at 06:49:53AM -0500, Shiraz Saleem wrote:
> Commit 1a1c116f3dcf removes nlmsg_len calculation in
> ibnl_put_attr causing netlink messages to be rejected due
> to incorrect length.
>
> Restore the netlink message header length calculation
> to include the added attribute.
>
> Fixes: 1a1c116f3dcf ("RDMA/netlink: Simplify the put_msg and put_attr")
> Signed-off-by: Shiraz Saleem <shiraz.saleem@xxxxxxxxx>
> Signed-off-by: Tatyana Nikolova <tatyana.e.nikolova@xxxxxxxxx>
> ---
>  drivers/infiniband/core/netlink.c | 4 ++++
>  1 file changed, 4 insertions(+)
>

The length supposed to be updated in ibnl_put_msg, where you should
supply correct length from the beginning. The suggested way to supply
length for unknown data is to provide NLMSG_DEFAULT_SIZE while allocating
new netlink message.

NLMSG_DEFAULT_SIZE ensures that netlink fits into one page.

It is better to avoid messing with message length after allocations,
especially for the attributes.

Thanks

> diff --git a/drivers/infiniband/core/netlink.c b/drivers/infiniband/core/netlink.c
> index e685148..889d091 100644
> --- a/drivers/infiniband/core/netlink.c
> +++ b/drivers/infiniband/core/netlink.c
> @@ -150,10 +150,14 @@ EXPORT_SYMBOL(ibnl_put_msg);
>  int ibnl_put_attr(struct sk_buff *skb, struct nlmsghdr *nlh,
>  		  int len, void *data, int type)
>  {
> +	unsigned char *prev_tail;
> +
> +	prev_tail = skb_tail_pointer(skb);
>  	if (nla_put(skb, type, len, data)) {
>  		nlmsg_cancel(skb, nlh);
>  		return -EMSGSIZE;
>  	}
> +	nlh->nlmsg_len += skb_tail_pointer(skb) - prev_tail;
>  	return 0;
>  }
>  EXPORT_SYMBOL(ibnl_put_attr);
> --
> 2.8.3
>

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux