Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1840329rda; Tue, 24 Oct 2023 05:11:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIzjOXq9W9tNelfWVW2PyVpPRVYLzzQz31RAEMYlHT35/AjkHcApZLNU68lBe8kD8QWNhX X-Received: by 2002:a05:6a20:4320:b0:126:42ce:bd44 with SMTP id h32-20020a056a20432000b0012642cebd44mr3073594pzk.17.1698149467595; Tue, 24 Oct 2023 05:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698149467; cv=none; d=google.com; s=arc-20160816; b=w36I1L9215WFVqmNTwQeCBifaposaxUXWQhWWXUfFdE9hGyviU9EuugJHHnuYhUr22 8b/p7SRHWvtwT5Ne7EBH8MaXcYuSd21daLqUfpe1oHlUd6iYA4zl2oGkV8bhsy/tMT6Q tSa2JoaKCmf53bHwZvNfNXV98qjrb5PrSQaXkflBNqSYLVVrGJmKgR7+NWP5CliCuQzc /EtPgz7q/IPOcXTYnA7gVTLGpj6pWRRiHOExdcQL5oGcpyqhCdi9q3b4POeure711UeJ qHuCWVFQt7wDscHPwyU0x1BnoPUJt+eLXwEOfvySfh/LvaEY2v+pbw8JyKJ418wp4fxj JqUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=0RWXQ0JSSHfw7ZxzgnmVrVbqR4LpPWoOYLUETidht14=; fh=c6HOs8VQA/368uiI8tdiTrCM+hd0l9TVl6NFuf+hxI4=; b=ZbxG0WG0soDZKSZ9S6sywxHW+pAZpUZy1wnbAjAaVxGP68ozFoCTxAB4cNBmyidZa0 WkLwS0Gb8kN2Rlui/ccnOGIosl4a0iV66ZtDjO+uabvl5S24VDbgsirZ+O6U/cwrENwS 834tvzQeIAAwmUbJqYTTfnBVoAGB6WERnJe9OyLFaq38gPe9wbWmm5LugW7dbGajAfH0 swavmAK7jrkIF1cWQzaSMwDj4GE5rfBcAzjorhqja3p4bxL6Vq//Nf+lTXsGvySLW1bv fzXEPTdM8LMZ6zAip23NO623OmqaqHXD07Z8R1aMG0sb8IVco2DvmMjzGNaPqPjEYLoY 2pog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXU1X5lQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id u3-20020a656703000000b00578a9ea5686si8042360pgf.660.2023.10.24.05.11.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 05:11:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DXU1X5lQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 9F17C802FA70; Tue, 24 Oct 2023 05:11:06 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234349AbjJXMLC (ORCPT + 99 others); Tue, 24 Oct 2023 08:11:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234046AbjJXMLA (ORCPT ); Tue, 24 Oct 2023 08:11:00 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CC07128 for ; Tue, 24 Oct 2023 05:10:56 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4081ccf69dcso30952775e9.0 for ; Tue, 24 Oct 2023 05:10:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1698149454; x=1698754254; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0RWXQ0JSSHfw7ZxzgnmVrVbqR4LpPWoOYLUETidht14=; b=DXU1X5lQdJ0ZDhWmgePKdJTies3c5DI6VB4pkbWQMvqdbTlfPsKr9nq1kcj+K/hKgk L8MCfHBbiMFJ63cbpP6Dfm9xoV42Jhv0j+mfRQh+p2SZWxHJloqeJq66M2zvyD2RjGnS kWEOEJWVIqqyOu+/g5pgoj6oRmZYv40MMnmtD6JSt+Trsm8ykKQ4pGuhxaM//w+aXWyV 9ZOR3DUF+pg9LPopuEO1PgoZNO5dEOGw8YWYUgqV7KPEl1ueeboD0pkevQz6+VhOO89W qHxxTOSwtN9rnBZ5sog+ndZ8bHTWHTv4XyB2y9OrBuq/ZcWZg/pU807jtjFmfOMv5+tR Yeeg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698149454; x=1698754254; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0RWXQ0JSSHfw7ZxzgnmVrVbqR4LpPWoOYLUETidht14=; b=DevZX/C9dCGyzuCja2bqCey9MiLVsJhvkGiFRElEeMJs/5ixD/OkalimAcay07yjF+ /aSEu6+Ev8fdtnvgxnRpSje+alAV/fhFPc26OduZ3702cX3oseQRsBD4VBY2K38hvEvw FObD0jP76NPFWjpUe8QCrCeiQe4R6Z0h5tT/O7OPYF+u+rFY3Rr8UQ1GYoB9Ls48mlXQ HOXPQv+w0tCzXMzGll/A2T79xmaVsNE+8L3hC95Y0pIFvnXyG6vNJXDslUMjBkolh1aJ OKF6y/q6XoAZBZWPJKUveHZDXrWxvwfGtwHz/ZrncQh26HzMV4ypuxqns1PS3yFaf9M9 +UIQ== X-Gm-Message-State: AOJu0Yxwg+SBS9d8cAngmkGOqfz3MvQ4KaVKcVpmA0l2RCz0hAzxtoEN +HwZq9O4vMv9q82TXDYOSEPZDQ== X-Received: by 2002:a05:600c:4f94:b0:408:3e7a:82d8 with SMTP id n20-20020a05600c4f9400b004083e7a82d8mr11572709wmq.19.1698149454612; Tue, 24 Oct 2023 05:10:54 -0700 (PDT) Received: from localhost ([102.36.222.112]) by smtp.gmail.com with ESMTPSA id p12-20020a05600c358c00b00401b242e2e6sm16766305wmq.47.2023.10.24.05.10.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Oct 2023 05:10:54 -0700 (PDT) Date: Tue, 24 Oct 2023 15:10:50 +0300 From: Dan Carpenter To: Paolo Abeni Cc: Christophe JAILLET , dchickles@marvell.com, sburla@marvell.com, fmanlunas@marvell.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, veerasenareddy.burru@cavium.com, felix.manlunas@cavium.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: Re: [PATCH net 2/2] liquidio: Simplify octeon_download_firmware() Message-ID: <9a6d37de-14a4-483a-a515-ac30dbea4d4c@kadam.mountain> References: <0278c7dfbc23f78a2d85060369132782f8466090.1698007858.git.christophe.jaillet@wanadoo.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 24 Oct 2023 05:11:06 -0700 (PDT) On Tue, Oct 24, 2023 at 01:11:13PM +0200, Paolo Abeni wrote: > On Sun, 2023-10-22 at 22:59 +0200, Christophe JAILLET wrote: > > In order to remove the usage of strncat(), write directly at the rigth > > place in the 'h->bootcmd' array and check if the output is truncated. > > > > Signed-off-by: Christophe JAILLET > > --- > > The goal is to potentially remove the strncat() function from the kernel. > > Their are only few users and most of them use it wrongly. > > > > This patch is compile tested only. > > Then just switch to strlcat, would be less invasive. Linus was just complaining about strl* functions. https://lore.kernel.org/all/CAHk-=wj4BZei4JTiX9qsAwk8PEKnPrvkG5FU0i_HNkcDpy7NGQ@mail.gmail.com/ strlcat() does a strlen(src) so it's BROKEN BY DESIGN as Linus puts it. The advantage of strlcat() is that it always puts a NUL terminator in the dest buffer, but the disadvantage is that it introduces a read overflow. I would probably have written it like this: diff --git a/drivers/net/ethernet/cavium/liquidio/octeon_console.c b/drivers/net/ethernet/cavium/liquidio/octeon_console.c index 67c3570f875f..ebe9f7694d8b 100644 --- a/drivers/net/ethernet/cavium/liquidio/octeon_console.c +++ b/drivers/net/ethernet/cavium/liquidio/octeon_console.c @@ -899,13 +899,16 @@ int octeon_download_firmware(struct octeon_device *oct, const u8 *data, ret = snprintf(boottime, MAX_BOOTTIME_SIZE, " time_sec=%lld time_nsec=%ld", (s64)ts.tv_sec, ts.tv_nsec); - if ((sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))) < - ret) { + + len = strnlen(h->bootcmd, sizeof(h->bootcmd)); + len += snprintf(h->bootcmd + len, sizeof(h->bootcmd) - len, + " time_sec=%lld time_nsec=%ld", + (s64)ts.tv_sec, ts.tv_nsec); + if (len >= sizeof(h->bootcmd)) { + h->bootcmd[orig] = '\0'; dev_err(&oct->pci_dev->dev, "Boot command buffer too small\n"); return -EINVAL; } - strncat(h->bootcmd, boottime, - sizeof(h->bootcmd) - strnlen(h->bootcmd, sizeof(h->bootcmd))); dev_info(&oct->pci_dev->dev, "Writing boot command: %s\n", h->bootcmd); Don't involve the "ret" variable. Just len +=. In the original code, if there wasn't enough space they truncated it before the " time_sec=%lld time_nsec=%ld" but keeping that behavior seems needlessly complicated. They already created one bug by complicating stuff. regards, dan carpenter