Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4FC2AC3F2D1 for ; Tue, 3 Mar 2020 18:04:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F81820CC7 for ; Tue, 3 Mar 2020 18:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388057AbgCCSE0 (ORCPT ); Tue, 3 Mar 2020 13:04:26 -0500 Received: from mga07.intel.com ([134.134.136.100]:25333 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387712AbgCCSAC (ORCPT ); Tue, 3 Mar 2020 13:00:02 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 Mar 2020 09:59:44 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,511,1574150400"; d="scan'208";a="229010049" Received: from jekeller-mobl1.amr.corp.intel.com (HELO [134.134.177.106]) ([134.134.177.106]) by orsmga007.jf.intel.com with ESMTP; 03 Mar 2020 09:59:44 -0800 Subject: Re: ip link vf info truncating with many VFs To: David Ahern , Jakub Kicinski Cc: "netdev@vger.kernel.org" , Florian Westphal , Thomas Graf References: <16b289f6-b025-5dd3-443d-92d4c167e79c@intel.com> <20200302151704.56fe3dd4@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> From: Jacob Keller Organization: Intel Corporation Message-ID: <40036e4e-be12-774e-ee84-f6aea6037128@intel.com> Date: Tue, 3 Mar 2020 09:59:44 -0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 3/3/2020 9:16 AM, David Ahern wrote: > On 3/2/20 4:21 PM, Jacob Keller wrote: >> On 3/2/2020 3:17 PM, Jakub Kicinski wrote: >>> On Fri, 28 Feb 2020 16:33:40 -0800 Jacob Keller wrote: >>>> Hi, >>>> >>>> I recently noticed an issue in the rtnetlink API for obtaining VF >>>> information. >>>> >>>> If a device creates 222 or more VF devices, the rtnl_fill_vf function >>>> will incorrectly label the size of the IFLA_VFINFO_LIST attribute. This >>>> occurs because rtnl_fill_vfinfo will have added more than 65k (maximum >>>> size of a single attribute since nla_len is a __u16). >>>> >>>> This causes the calculation in nla_nest_end to overflow and report a >>>> significantly shorter length value. Worse case, with 222 VFs, the "ip >>>> link show " reports no VF info at all. >>>> >>>> For some reason, the nla_put calls do not trigger an EMSGSIZE error, >>>> because the skb itself is capable of holding the data. >>>> >>>> I think the right thing is probably to do some sort of >>>> overflow-protected calculation and print a warning... or find a way to >>>> fix nla_put to error with -EMSGSIZE if we would exceed the nested >>>> attribute size limit... I am not sure how to do that at a glance. >>> >>> Making nla_nest_end() return an error on overflow seems like >>> the most reasonable way forward to me, FWIW. Simply compare >>> the result to U16_MAX, I don't think anything more clever is >>> needed. >>> >> >> Sure, I alto think that's the right approach to fix this. >> >> As long we calculate the value using something larger than a u16 first, >> that should work. >> > > Another pandora's box. > > Seems like there are a few other places that set nla_len that should be > checked as well - like __nla_reserve and that bleeds into __nla_put. > Yea, I bet. I'm working on a patch for this nla_nest_end first. Thanks, Jake