Return-Path: Received: from orbyte.nwl.cc ([151.80.46.58]:52738 "EHLO orbyte.nwl.cc" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966675AbeCAJfY (ORCPT ); Thu, 1 Mar 2018 04:35:24 -0500 From: Phil Sutter To: Stephen Hemminger Cc: netdev@vger.kernel.org Subject: [iproute PATCH] ip-link: Fix use after free in nl_get_ll_addr_len() Date: Thu, 1 Mar 2018 10:35:12 +0100 Message-Id: <20180301093512.21254-1-phil@nwl.cc> Sender: netdev-owner@vger.kernel.org List-ID: Immediately after freeing the buffer returned from rtnl_talk(), it is accessed again via pointer in struct rtattr array. This leads to some builds not allowing to set an interface's MAC address because the expected length value is garbage. Fixes: 86bf43c7c2fdc ("lib/libnetlink: update rtnl_talk to support malloc buff at run time") Signed-off-by: Phil Sutter --- ip/iplink.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ip/iplink.c b/ip/iplink.c index 230f4c5377d9f..d401311bcad9f 100644 --- a/ip/iplink.c +++ b/ip/iplink.c @@ -276,8 +276,9 @@ static int nl_get_ll_addr_len(unsigned int dev_index) return -1; } + len = RTA_PAYLOAD(tb[IFLA_ADDRESS]); free(answer); - return RTA_PAYLOAD(tb[IFLA_ADDRESS]); + return len; } static void iplink_parse_vf_vlan_info(int vf, int *argcp, char ***argvp, -- 2.16.1