From mboxrd@z Thu Jan 1 00:00:00 1970 From: Florian Fainelli Subject: Re: [PATCH net 3/4] net: dsa: microchip: Utilize strncpy() for ethtool::get_strings Date: Fri, 2 Mar 2018 10:24:59 -0800 Message-ID: References: <20180302002529.15226-1-f.fainelli@gmail.com> <20180302002529.15226-4-f.fainelli@gmail.com> <5dfe389482c54437873d4c0ae29eca8a@AcuMS.aculab.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Cc: Andrew Lunn , Vivien Didelot , Woojung Huh , Microchip Linux Driver Support , open list To: David Laight , "netdev@vger.kernel.org" Return-path: In-Reply-To: <5dfe389482c54437873d4c0ae29eca8a@AcuMS.aculab.com> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On 03/02/2018 02:51 AM, David Laight wrote: > From: Florian Fainelli >> >> Do not use memcpy() which is not safe, but instead use strncpy() which >> will make sure that the string is NUL terminated (in the Linux >> implementation) if the string is smaller than the length specified. This >> fixes KASAN out of bounds warnings while fetching port statistics. > > You really ought to use a copy function that will truncate the > string if it is too long. > Just assuming the string isn't too long is asking for trouble. > You might (almost) just use strcpy(). > > strlcpy() will probably work best here. Right, or if we actually do size the statistics string to be ETH_GSTRING_LEN bytes, memcpy() can be used, provided that the strings are initialized correctly (which they are). -- Florian