Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp34485rdb; Thu, 5 Oct 2023 15:47:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFkNb7EeAKQ/57Ecygng04agxS+84acK9VVLYzPWmlRIt8vDPEhn1ParCvb+0Jb0o4xDSmf X-Received: by 2002:a05:6a20:565b:b0:166:cb8a:9831 with SMTP id is27-20020a056a20565b00b00166cb8a9831mr5983490pzc.20.1696546042379; Thu, 05 Oct 2023 15:47:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696546042; cv=none; d=google.com; s=arc-20160816; b=UcHt7nmS8QicZgSx1eEcatF8QNqgK/R7y2bR78iqWqYvYZ1lVEZM4TBUFm3LBf/4Jx d0m0vSem/u+WSwLkFvAKirU2r8Ao4I9ldiuZ5QmeUZu1RSOrV6y/gIm7C8VvGI+yIwWi 0mcNv07v485bYCkfCS9oiRdVk51dLSW7VbK6raFMFh4P8aWMeCe4zP4j1Bt+aok7zPcF WeJ8zCS68VFtLKXz3ieKQrU2auOc+9vzTvxgrdJPw+Jozg7T93wEY90eLSr4UXTeu4Q+ jGhOTPPkzWWUv2dbaisy3kn7G7eCrTVnKBEJ48K0U543p5EhGXIIcGfsdg1ng+JQLbVN oaGA== 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=ePyskiEJCEOltRf//00HdVQ4cJ67D/wO+W+PB1Wu8iw=; fh=YTomHt3TDNdusqbDoTLIA25BCpJ5Jgaq5sT/Yscdx+4=; b=noTmQC8s+B/gAJyQfUBDirDD611ELAlbtJE9XXw0vZqGcdL5Yt5aNQWULaDaP9N79T 4LmPSjAKprI+cbk/msR7na9K0NwP49QtmNXwH7XC4zzIig1z+CZFKPlox1ZsvA0E6PT1 px4wsuzyiN71iEP3suqU9qZVMtw/miiorl1DDeam00cnik+LsD0gcAwGPDhQAP6IqqJh hQ4ai2cRfBTEibBmBJ3jWnbA3KIvrEebhArhy+xxw8bgTllEiVum42dvSRA/+rAZLWfw n5VoMr6XWQL/s6fjsRCpyzd34gzE5hj2tkkMDXo3WnCkYmSNvYTCm+lMg+lyI5zXBKBu watQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iuROY2lN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id cn12-20020a056a020a8c00b00574006acf67si2392275pgb.17.2023.10.05.15.47.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 15:47:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iuROY2lN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 52CC8807FD56; Thu, 5 Oct 2023 15:46:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230357AbjJEWqO (ORCPT + 99 others); Thu, 5 Oct 2023 18:46:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjJEWqN (ORCPT ); Thu, 5 Oct 2023 18:46:13 -0400 Received: from mail-oi1-x230.google.com (mail-oi1-x230.google.com [IPv6:2607:f8b0:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21E4DD6 for ; Thu, 5 Oct 2023 15:46:10 -0700 (PDT) Received: by mail-oi1-x230.google.com with SMTP id 5614622812f47-3af8b498d31so1070085b6e.1 for ; Thu, 05 Oct 2023 15:46:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696545969; x=1697150769; 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=ePyskiEJCEOltRf//00HdVQ4cJ67D/wO+W+PB1Wu8iw=; b=iuROY2lNaoGjIIE9uohhCqFE4Q/gSKmQAQnrfz2eaypGCLHwS6nnLVL46Qily4BlHV CddSMA+7bcZY5bNhiBO+tmSUpHOWNQAsp9HuqcOr7d2dyQ6jrXa/tGKUZA5ue7FtXGQ0 fqSokBtGSpL3/tcooiE5689m5uIwx+1w3XmTI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696545969; x=1697150769; 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=ePyskiEJCEOltRf//00HdVQ4cJ67D/wO+W+PB1Wu8iw=; b=p7JNHrCamVq3fr6TipMVjCnPW736tHnIDvU4b2LVgl53OeoHsEfEAUB+P+x+4UvkFH Nq8/VPpzBvrAuUTQJRzTHQww+QdyCPtgK8Zo+6E3UJwDWEbkI5Kurweq9Xxo8hbvbpwM qIl2j8DT8E74aPSgyf5N5dBzdNyGssC+zNCYXE7zDwmrmQYYxdXgrkQez6BMkfPW+6RB IhiwhXsaf6g12yp+lV+XSuE2TiTJieTpbeOs8urtBC8OUAqvVuYYUEDDfCrTrEp1khlg Qt6VicLLzgfTYuWm/xoP64iJkwgV00Mv0qiSBVGbfNgbXzWpDCXzJqaRBfOHufnla2EZ dD6A== X-Gm-Message-State: AOJu0YwFqY4dOfoMClZyb7RbWSWHjF6/mRy1aYwFXBFPcGU/foCbToJC KmmOarLtqLnN/Uh7MgCnnYVROg== X-Received: by 2002:a05:6808:110:b0:3ae:87c8:437e with SMTP id b16-20020a056808011000b003ae87c8437emr6462389oie.41.1696545969449; Thu, 05 Oct 2023 15:46:09 -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 p19-20020a639513000000b00585391d0aafsm1984306pgd.6.2023.10.05.15.46.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 15:46:08 -0700 (PDT) Date: Thu, 5 Oct 2023 15:46:08 -0700 From: Kees Cook To: Justin Stitt Cc: "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] bcm63xx_enet: replace deprecated strncpy with strscpy Message-ID: <202310051544.822967F55@keescook> References: <20231005-strncpy-drivers-net-ethernet-broadcom-bcm63xx_enet-c-v1-1-6823b3c3c443@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231005-strncpy-drivers-net-ethernet-broadcom-bcm63xx_enet-c-v1-1-6823b3c3c443@google.com> X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,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 pete.vger.email 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 (pete.vger.email [0.0.0.0]); Thu, 05 Oct 2023 15:46:24 -0700 (PDT) On Thu, Oct 05, 2023 at 08:51:40PM +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. > > A suitable replacement is strscpy() [2] due to the fact that it > guarantees NUL-termination on the destination buffer without > unnecessarily NUL-padding. > > bcm_enet_get_drvinfo() already uses strscpy(), let's match it's > implementation: > | static void bcm_enet_get_drvinfo(struct net_device *netdev, > | struct ethtool_drvinfo *drvinfo) > | { > | strscpy(drvinfo->driver, bcm_enet_driver_name, sizeof(drvinfo->driver)); > | strscpy(drvinfo->bus_info, "bcm63xx", sizeof(drvinfo->bus_info)); > | } > > Note that now bcm_enet_get_drvinfo() and bcm_enetsw_get_drvinfo() do the > exact same thing. > > 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 good. Other writers to drvinfo, as you saw, do the same strscpy, so this looks correct to me. Reviewed-by: Kees Cook -- Kees Cook