From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 20C4415C9 for ; Thu, 5 Oct 2023 04:57:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Bx4pv63u" Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09FDC469D for ; Wed, 4 Oct 2023 21:57:40 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id 41be03b00d2f7-577fb90bb76so296257a12.2 for ; Wed, 04 Oct 2023 21:57:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696481859; x=1697086659; 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=ou7qEyDSpNR2vhTsDc3jo4hVQ4chmkItyDd1XYYoY9o=; b=Bx4pv63uBmHtJMi9oE7YWaAe2LXWmUYg4hXLP5NhaWdj+DpaNDFshrBE+s72WBckAj byXbNKSpj+Axb8bLarJOhD/hyj8vyv1pLDQdaf1RQSBY8FMMSOA/Vr4OlhsB1vDF25em FdgpcND3QzuUpV5mJEOnw4yNRmLgwIkCJomzw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696481859; x=1697086659; 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=ou7qEyDSpNR2vhTsDc3jo4hVQ4chmkItyDd1XYYoY9o=; b=adcCwXv5h3MLcmmnJzDzu6Rj5Dtw2oGAQ7Oz2Q5uJGmGcwjj5m+AkA9uONltqb0woR yV4NrHYVwmKpnwAOYz3V00T0kimAyv1R2vgbirLD8UbHpx3prOM1zVIMzxWQzGPjfGTv CNhSNU6ljzUF6pcLe9pV13vDzWyQQgUmlY4tHmyrMf1ydgvqArTVTrS75ezIBbYzKW/Q OKz9vXyY1OEEgxSXrXgxUxSGoy2cK/JkdP5GMq7jMYQ5Ly5DxcXPgmAh7X+7EEQS4cxH 8YL5XIvqVP91mSQKk+V+eMzPtMyfwflcjV+1brVHxp41bEFDabVVjhOgxn2+JfDIqmH5 TYvw== X-Gm-Message-State: AOJu0YyX3/dWUtKEo2F9X5ttHxdgexLBxvFz0/TfVy7i6odNgEed8L6m XIhHQ4T0o+g53aR4RkgbgzI6DQ== X-Google-Smtp-Source: AGHT+IHfFzAk3jZc8/kmyYED56n0qFpH0frjgyDXlmQrCoyoXKErciD3RmqNnW4gsjvX/+xSlxs3fA== X-Received: by 2002:a05:6a20:8e05:b0:154:bfaf:a710 with SMTP id y5-20020a056a208e0500b00154bfafa710mr4952481pzj.41.1696481859488; Wed, 04 Oct 2023 21:57:39 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id bu3-20020a632943000000b005657495b03bsm435576pgb.38.2023.10.04.21.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Oct 2023 21:57:38 -0700 (PDT) Date: Wed, 4 Oct 2023 21:57:38 -0700 From: Kees Cook To: Justin Stitt Cc: Chris Snook , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: [PATCH] net: atheros: replace deprecated strncpy with strscpy Message-ID: <202310042157.D314C6D7EF@keescook> References: <20231005-strncpy-drivers-net-ethernet-atheros-atlx-atl2-c-v1-1-493f113ebfc7@google.com> Precedence: bulk X-Mailing-List: linux-hardening@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231005-strncpy-drivers-net-ethernet-atheros-atlx-atl2-c-v1-1-493f113ebfc7@google.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On Thu, Oct 05, 2023 at 01:29:45AM +0000, Justin Stitt wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > We expect netdev->name to be NUL-terminated based on its use with format > strings and dev_info(): > | dev_info(&adapter->pdev->dev, > | "%s link is up %d Mbps %s\n", > | netdev->name, adapter->link_speed, > | adapter->link_duplex == FULL_DUPLEX ? > | "full duplex" : "half duplex"); > > Furthermore, NUL-padding is not required as netdev is already > zero-initialized through alloc_etherdev(). > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt Looks right; destination length correctly updated. Reviewed-by: Kees Cook -- Kees Cook