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 194B0354ED for ; Tue, 10 Oct 2023 23:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MNV0Y+cv" Received: from mail-ot1-x334.google.com (mail-ot1-x334.google.com [IPv6:2607:f8b0:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F79091 for ; Tue, 10 Oct 2023 16:58:17 -0700 (PDT) Received: by mail-ot1-x334.google.com with SMTP id 46e09a7af769-6c665b2469dso4137945a34.0 for ; Tue, 10 Oct 2023 16:58:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696982296; x=1697587096; 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=FOb3GWppFGUQUo6fDVKv/7BVVJ3kmc+fs0b3MYzsoHo=; b=MNV0Y+cvtkfIb8P5OLrIntPSq+CZzdI+ENcqpvT5vQRX5QnU7q7e0QZ30G6hjAZJVZ IkSsLh3zl77N+MiaBPRB3MPo9L28AR9Dm1Vs3MoWFIdPKwKdqVzVx/8Ar+BUxYin3cj4 nVQx1vfzYowHReeA48KQXXqRm7yrNaRzGdi2E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696982296; x=1697587096; 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=FOb3GWppFGUQUo6fDVKv/7BVVJ3kmc+fs0b3MYzsoHo=; b=nbA0BG+A4G3R+sjsUK89c3OSwIPziDq8h4l2zxrvwrEn16sCZIhN9YYzLLwNbI5L8a EWpCMM4ADuJM/yVmJHobr+iMmJrrSNmVCgXd+LyKXV8f7coSxX6+Q5vTHRtRJzH5yt6f C2ny0WmEnos0jVV3G0rSh6UmcMJUBjxoXnTWKEY5yCVwba6HxFaCJvKustOSHKkOb1U1 pKnqoQq1rFGZkRBiGSAlCRx5vQFWNDL5GY5ZI4y2Zq6tlMe3E/rR0RZLoA7M15sG+MIS M+VVIjdQyDPB+UqzZmtVjuY4dFrz+p4y6LmxnkcapFrqgEYAGBDKl9IK8u2lLSIjwkxj JEpA== X-Gm-Message-State: AOJu0YzyvF3n8r57+S+12JcJsVmdSB3HGg1ODqpXVGJ/eO5qEAMEg0bf MvkcL+JUbPQHxDxT3CMHwalyuw== X-Google-Smtp-Source: AGHT+IFpqAZvTTfdymMa3R5nbAmknFwysoqVA/dwXwkjpL1QCgv8PmS1IKni1deEEaUquQKaMJYecw== X-Received: by 2002:a05:6830:1da7:b0:6b9:4d79:e08a with SMTP id z7-20020a0568301da700b006b94d79e08amr19908023oti.32.1696982296583; Tue, 10 Oct 2023 16:58:16 -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 l4-20020a63be04000000b00565e96d9874sm9441495pgf.89.2023.10.10.16.58.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 16:58:16 -0700 (PDT) Date: Tue, 10 Oct 2023 16:58:14 -0700 From: Kees Cook To: Justin Stitt Cc: Andrew Lunn , Florian Fainelli , Vladimir Oltean , "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 v2] net: dsa: vsc73xx: replace deprecated strncpy with ethtool_sprintf Message-ID: <202310101658.84E1C724@keescook> References: <20231010-strncpy-drivers-net-dsa-vitesse-vsc73xx-core-c-v2-1-ba4416a9ff23@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: <20231010-strncpy-drivers-net-dsa-vitesse-vsc73xx-core-c-v2-1-ba4416a9ff23@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_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net On Tue, Oct 10, 2023 at 10:32:35PM +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. > > ethtool_sprintf() is designed specifically for get_strings() usage. > Let's replace strncpy in favor of this more robust and easier to > understand interface. > > This change could result in misaligned strings when if(cnt) fails. To > combat this, use ternary to place empty string in buffer and properly > increment pointer to next string slot. > > 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 Nice; much more readable. Reviewed-by: Kees Cook -- Kees Cook