diff mbox

[net] rtnetlink: Fix the IFLA_PHYS_PORT_NAME TLV to include terminating NULL

Message ID 1494331922-16451-1-git-send-email-yotamg@mellanox.com
State Not Applicable, archived
Delegated to: David Miller
Headers show

Commit Message

Yotam Gigi May 9, 2017, 12:12 p.m. UTC
The IFLA_PHYS_PORT_NAME rtnetlink TLV length does not include the
terminating NULL character, which is different from other string typed
TLVs. Due to the fact that libnl checks for the terminating NULL in every
string typed attribute, it crashes on every RTM_GETLINK response on
drivers that implement ndo_get_phys_port_name.

Make the fill_phys_port_name function include the terminating NULL in the
TLV size by using the nla_put_string helper function.

Fixes: db24a9044ee1 ("net: add support for phys_port_name")
Signed-off-by: Yotam Gigi <yotamg@mellanox.com>
Cc: David Ahern <dsa@cumulusnetworks.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Acked-by: Jiri Pirko <jiri@mellanox.com>
---
Please consider this for stable too. Thanks!
---
 net/core/rtnetlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tobias Klauser May 9, 2017, 12:31 p.m. UTC | #1
On 2017-05-09 at 14:12:02 +0200, Yotam Gigi <yotamg@mellanox.com> wrote:
> The IFLA_PHYS_PORT_NAME rtnetlink TLV length does not include the
> terminating NULL character, which is different from other string typed
> TLVs. Due to the fact that libnl checks for the terminating NULL in every
> string typed attribute, it crashes on every RTM_GETLINK response on
> drivers that implement ndo_get_phys_port_name.
> 
> Make the fill_phys_port_name function include the terminating NULL in the
> TLV size by using the nla_put_string helper function.
> 
> Fixes: db24a9044ee1 ("net: add support for phys_port_name")
> Signed-off-by: Yotam Gigi <yotamg@mellanox.com>
> Cc: David Ahern <dsa@cumulusnetworks.com>
> Reviewed-by: Ido Schimmel <idosch@mellanox.com>
> Acked-by: Jiri Pirko <jiri@mellanox.com>
> ---
> Please consider this for stable too. Thanks!

This is already fixed in commit 77ef033b687c ("rtnetlink: NUL-terminate
IFLA_PHYS_PORT_NAME string").
Yotam Gigi May 9, 2017, 12:48 p.m. UTC | #2
On 05/09/2017 03:31 PM, Tobias Klauser wrote:
> On 2017-05-09 at 14:12:02 +0200, Yotam Gigi <yotamg@mellanox.com> wrote:
>> The IFLA_PHYS_PORT_NAME rtnetlink TLV length does not include the
>> terminating NULL character, which is different from other string typed
>> TLVs. Due to the fact that libnl checks for the terminating NULL in every
>> string typed attribute, it crashes on every RTM_GETLINK response on
>> drivers that implement ndo_get_phys_port_name.
>>
>> Make the fill_phys_port_name function include the terminating NULL in the
>> TLV size by using the nla_put_string helper function.
>>
>> Fixes: db24a9044ee1 ("net: add support for phys_port_name")
>> Signed-off-by: Yotam Gigi <yotamg@mellanox.com>
>> Cc: David Ahern <dsa@cumulusnetworks.com>
>> Reviewed-by: Ido Schimmel <idosch@mellanox.com>
>> Acked-by: Jiri Pirko <jiri@mellanox.com>
>> ---
>> Please consider this for stable too. Thanks!
> This is already fixed in commit 77ef033b687c ("rtnetlink: NUL-terminate
> IFLA_PHYS_PORT_NAME string").


You are right. I forgot to rebase my net tree :)
diff mbox

Patch

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index c4e84c5..69daf39 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1056,7 +1056,7 @@  static int rtnl_phys_port_name_fill(struct sk_buff *skb, struct net_device *dev)
 		return err;
 	}
 
-	if (nla_put(skb, IFLA_PHYS_PORT_NAME, strlen(name), name))
+	if (nla_put_string(skb, IFLA_PHYS_PORT_NAME, name))
 		return -EMSGSIZE;
 
 	return 0;