From patchwork Tue Jan 16 13:41:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gal Pressman X-Patchwork-Id: 861548 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zLWcq6kpYz9s1h for ; Wed, 17 Jan 2018 00:42:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751534AbeAPNmp (ORCPT ); Tue, 16 Jan 2018 08:42:45 -0500 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:58130 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751256AbeAPNmn (ORCPT ); Tue, 16 Jan 2018 08:42:43 -0500 Received: from Internal Mail-Server by MTLPINE1 (envelope-from galp@mellanox.com) with ESMTPS (AES256-SHA encrypted); 16 Jan 2018 15:42:39 +0200 Received: from reg-l-vrt-045-012.mtl.labs.mlnx (reg-l-vrt-045-012.mtl.labs.mlnx [10.135.45.12]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id w0GDgd1K016803; Tue, 16 Jan 2018 15:42:39 +0200 Received: from reg-l-vrt-045-012.mtl.labs.mlnx (localhost [127.0.0.1]) by reg-l-vrt-045-012.mtl.labs.mlnx (8.15.2/8.15.2/Debian-3) with ESMTP id w0GDgdU9032204; Tue, 16 Jan 2018 15:42:39 +0200 Received: (from galp@localhost) by reg-l-vrt-045-012.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id w0GDgdSl032203; Tue, 16 Jan 2018 15:42:39 +0200 From: Gal Pressman To: netdev@vger.kernel.org, Stephen Hemminger , David Ahern Cc: Leon Romanovsky , Eran Ben Elisha , Sucheta Chakraborty , Gal Pressman Subject: [PATCH iproute2 2/3] ipaddress: Make sure VF min/max rate API is supported before using it Date: Tue, 16 Jan 2018 15:41:59 +0200 Message-Id: <1516110120-32132-3-git-send-email-galp@mellanox.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516110120-32132-1-git-send-email-galp@mellanox.com> References: <1516110120-32132-1-git-send-email-galp@mellanox.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When using the new minimum rate API and providing only one parameter (minimum rate/maximum rate), we query the VF min and max rate regardless of kernel support. This resulted in segmentation fault in ipaddr_loop_each_vf, which tries to access NULL pointer. This patch identifies such cases by testing the VF table for NULL pointer in IFLA_VF_RATE, and aborts the operation. Aborting on the first VF is valid since if the kernel does not support the new API for the first VF, it will not support it for the other VFs as well. Fixes: f89a2a05ffa9 ("Add support to configure SR-IOV VF minimum and maximum Tx rate through ip tool") Cc: Sucheta Chakraborty Signed-off-by: Gal Pressman Reviewed-by: Eran Ben Elisha Reviewed-by: Leon Romanovsky --- ip/ipaddress.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ip/ipaddress.c b/ip/ipaddress.c index f150d91..953d673 100644 --- a/ip/ipaddress.c +++ b/ip/ipaddress.c @@ -2251,6 +2251,12 @@ ipaddr_loop_each_vf(struct rtattr *tb[], int vfnum, int *min, int *max) for (i = RTA_DATA(vflist); RTA_OK(i, rem); i = RTA_NEXT(i, rem)) { parse_rtattr_nested(vf, IFLA_VF_MAX, i); + + if (!vf[IFLA_VF_RATE]) { + fprintf(stderr, "VF min/max rate API not supported\n"); + exit(1); + } + vf_rate = RTA_DATA(vf[IFLA_VF_RATE]); if (vf_rate->vf == vfnum) { *min = vf_rate->min_tx_rate;