Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4928654rdb; Tue, 12 Dec 2023 13:28:29 -0800 (PST) X-Google-Smtp-Source: AGHT+IGGaQT9BRfRzn2Rg5IbUi+Czf+0Occ216p4eU2w0khm0wnKLwMZT23dYgnY/17K2nDgYbtR X-Received: by 2002:a17:90a:d504:b0:28a:ce15:b851 with SMTP id t4-20020a17090ad50400b0028ace15b851mr865680pju.65.1702416508878; Tue, 12 Dec 2023 13:28:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702416508; cv=none; d=google.com; s=arc-20160816; b=ayALUiiNtvCObTnZNIJ/9SrttnWLmoKsEiBzcYMltymnnBiOuYXt7/m5khwefinXb0 RT+Fxfp9NPjXg4gQh+RlSpWXfIzOrvh6mbBYvIcrk/mDRUjzb3t00J5YXEE862jGkf+F rdHf0z0iqexOM3PKDdRUO8V49pyrDUP4UtHAtsuDrdDA6trfUxnjuINMvL6VCE+l53R/ xUJpwaXqSlJWQzLgZbIXIS9nYBnKaN8JFj9Fxd5sD9nV2JaRhH+T/Bv3VWcvXH81AXvE VtxOBBZDkm/2Cx0QLRW3SS1H+lvHfbKDno/3m+uNBE19KhCLbXDC5FCvo6iEiCNErMpf JdkQ== 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=xMWCFeEilpyi5Ac7Brep5JSzMOQ0AtnLLpOVe467uSo=; fh=IoFRKyVlUXDl9l2V+xHVBV/3U3Y1ckVX4s1qog+Dw0g=; b=CAiAGeSF5sV03JuvXbj7+EqnQrV3sr53nyi2q4reDo9N+KRB9LebduGpbFiGvtm8Gx kjIhyTiYKAxHpkn/+czlBLMdpNWIyXk3R05SYGo8d2myl8zj8TsoTLaWRKD1r5Jzf33s cQV90XP+oWDWFDCeqHeEpKUsz+248Ty7mcO1cHTWv0bF7PZPCXGw0S7mVDYdfRb6KEva sHKG81TKPGQtK4BuKHyJwR949/IonTL6vaBidJpuaiqrIBfaobNTctHYoLxGmCC04dc0 cN+aqJomJjE6wD8A7ZxFuV+JGDH0ngWfC3DjskWa17Rux8vJt4B75zlVD6m3xhQ91o8V TVDQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YjG2mwyE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id qc15-20020a17090b288f00b0028ae26639c0si7878pjb.60.2023.12.12.13.28.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:28:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=YjG2mwyE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 4CA8C807F4A4; Tue, 12 Dec 2023 13:27:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377344AbjLLV1l (ORCPT + 99 others); Tue, 12 Dec 2023 16:27:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235191AbjLLV1f (ORCPT ); Tue, 12 Dec 2023 16:27:35 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25486111 for ; Tue, 12 Dec 2023 13:27:38 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id 98e67ed59e1d1-28abb389323so955591a91.2 for ; Tue, 12 Dec 2023 13:27:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1702416457; x=1703021257; 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=xMWCFeEilpyi5Ac7Brep5JSzMOQ0AtnLLpOVe467uSo=; b=YjG2mwyEofdEFA+8fIhlpT2lC2Ie4VWo3Ue9ae+Gy1Kq24N5K4jfDYZYARfuSS0t9k jGkl0R0llkYoZrMi3JrOUUXriAMIAPX0x+bY4a1MCqkHNIuGZLITki/d9bfKjj4QmkH6 5W1OHshD/bc+xc0a3ouSMReLdcp19iQfdIYZE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702416457; x=1703021257; 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=xMWCFeEilpyi5Ac7Brep5JSzMOQ0AtnLLpOVe467uSo=; b=Q0US17ZUsdrhrm0oquCGv5EgfyEr8Mj6d8Drohnn4qJOJYc/BnMTavSLBjot0yheLn DdhWtg4QADlwvzrp2oXisBzhz8DcBCIOV6udh95N3AA3KsQNx1Kfy5CxB8VmoNLuOBz4 BEGgunfln/F0RObcdOByLM32Whtb+GiLFUfIesVsGV4o9QZopJFWBc4abonrMIZ3t+i9 K+9yqHfnPQGO1DR9OMM4Ln3da2oQD4zB4dQWunE859kIRzCKCLx/z54XhgqmwyASESpE Ngv6gJgxN9+/vJTcWnqkVZUqQHtQmqfCNFyMwgQ2C1U0TR9P+dFwIqF2DGdH0OSSvC68 u2Jg== X-Gm-Message-State: AOJu0YyVth9ohh7Y/8Bxlpt3emdYCQjZAWfBmPgWD+vIR3dTObOmjmJ0 3tqBfAsTLDqUXn0Ih9UHgaVgvQ== X-Received: by 2002:a17:902:cec5:b0:1d0:6ffd:f217 with SMTP id d5-20020a170902cec500b001d06ffdf217mr4199501plg.109.1702416457607; Tue, 12 Dec 2023 13:27:37 -0800 (PST) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id be3-20020a170902aa0300b001cfc6838e30sm9003034plb.308.2023.12.12.13.27.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:27:37 -0800 (PST) Date: Tue, 12 Dec 2023 13:27:36 -0800 From: Kees Cook To: Justin Stitt Cc: Andrew Lunn , Heiner Kallweit , Russell King , "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 v3] net: mdio-gpio: replace deprecated strncpy with strscpy Message-ID: <202312121327.3A71BECDF1@keescook> References: <20231211-strncpy-drivers-net-mdio-mdio-gpio-c-v3-1-76dea53a1a52@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231211-strncpy-drivers-net-mdio-mdio-gpio-c-v3-1-76dea53a1a52@google.com> X-Spam-Status: No, score=-0.9 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Tue, 12 Dec 2023 13:27:56 -0800 (PST) On Mon, Dec 11, 2023 at 07:10:00PM +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 new_bus->id to be NUL-terminated but not NUL-padded based on > its prior assignment through snprintf: > | snprintf(new_bus->id, MII_BUS_ID_SIZE, "gpio-%x", bus_id); > > Due to this, a suitable replacement is `strscpy` [2] due to the fact > that it guarantees NUL-termination on the destination buffer without > unnecessarily NUL-padding. > > We can also use sizeof() instead of a length macro as this more closely > ties the maximum buffer size to the destination buffer. Do this for two > instances. > > 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 like a clean replacement. (And a nice sizeof cleanup.) Reviewed-by: Kees Cook -- Kees Cook