Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp481911rdg; Tue, 10 Oct 2023 16:59:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IExa0/uaEIBOfLx+zq5ki2H+HCervqvQwQ1KUHzY495Hc9k40blUwF4kRT3W5k5DSE3ZRyp X-Received: by 2002:a05:6358:63aa:b0:143:864e:f96f with SMTP id k42-20020a05635863aa00b00143864ef96fmr21914011rwh.1.1696982363938; Tue, 10 Oct 2023 16:59:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696982363; cv=none; d=google.com; s=arc-20160816; b=ux6TnyF35Y1qAZ+3b1DA2pwC24XpbjEQ+RjpU9dkI0W+uqcEJUYIzrgV3qwglauuA0 lPJEn3QLLvXFmj8wYkbvwOlyPE5w0pz1Dm4CP6cGiZopy8QPupoiD8uDbENohGbRjKbx 8wo5dQvalDdkQini8mmD1P2Ey/kj4jAIQSk6FvKkBnP+OiQEMjLO/ioHWUFM0BR/GPZ3 8hOAv6v1e/uzjDGA4zq+xdsfdso4wHgww69meMueuDWAbJVNnHlPg/hNdkZCkW34rsFl plHYB9SnGTpt6acGAPriYD3pjddwEWdiO5eoAduymkCmR8DNntwxO0eyvVzKWn1nzoWi N8zQ== 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=VqSRijF5ocWf9llqvklQyW3Wi+0XOkmzW4XQNxfluyk=; fh=pbLjYvF01cyOjYk9YkSBRzge+cEzvZov949M2aUFS3Q=; b=HIPjYLxn5e+fbvWELs1nF0myaPW3kfCzZRNFyMfLJ5o8wX1IbYCICE9IcfNKc5i0Zt dewxBzSL+AA8/2i0/+Fl+J6q2hevcvSvvoQesYz1J63dR3qLZLWYPwWspwXEWSgw7XaC k+SzywivE2t0E0WCBPjLRJy1tkOcOvG3V/t24hRWIWCHdbM3JzoLvbZHKWsLu9Zbm5wq KLo4bb6oyN6+D6GYEwAxAB48tSzjxM4ZAyT3YR9n/ik0dXVIRVaOEQ/cMBGMi9EI5BA3 4VUcKOBXhjNaQpXArLK7N6/c8yoRQtOJN5iH6LqfxUawDw0eQNFj7Rg/k7zItb1vKU7k XsWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XR6IMS+g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id s198-20020a6377cf000000b0059c84b919adsi2252492pgc.51.2023.10.10.16.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 16:59:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XR6IMS+g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id AB11281CFF36; Tue, 10 Oct 2023 16:59:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344249AbjJJX7Q (ORCPT + 99 others); Tue, 10 Oct 2023 19:59:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344207AbjJJX7P (ORCPT ); Tue, 10 Oct 2023 19:59:15 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD32F91 for ; Tue, 10 Oct 2023 16:59:13 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1c5cd27b1acso49752995ad.2 for ; Tue, 10 Oct 2023 16:59:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1696982353; x=1697587153; 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=VqSRijF5ocWf9llqvklQyW3Wi+0XOkmzW4XQNxfluyk=; b=XR6IMS+gkfiwKqtsxSJF4Vcm0HKo0Y6oo38lcIgD6XeQqt7Yj559bQOm9TZEFE5Bg1 AkhxZYp2t44sJL9y0/NvxPko2qIXPffLLjRSA77ELSzQ4ZyWnRlf+7fXTqr398ieZ9PA vBqvf3Knf6mPaYByYrP3BkGXk0KJavVmQ6Q+U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696982353; x=1697587153; 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=VqSRijF5ocWf9llqvklQyW3Wi+0XOkmzW4XQNxfluyk=; b=dg8bFz9CFzh7xbrE022MeEVFgnt2U5USW5pDlLWQivYuYJNPo7T4WygVOz1bNZvfAh lWs1eL4Gi7n3avF0vRf6k/1IFgVDaQwe/OcoxYpo2SJeJWZ48pCnAK0FguUr/riyl8yf bygT4KRQP9lyv7D1Te6317WY00jjWp2BBcuY7x4Cg1a5rqxWndymW6PrGqzdkkp55G9D 3OQvPr2wK7Rt/3zwRHGXRV2x1fimhI4fuJkEijlvMJe3mikq3VpOv37IT14KmlzMn30i c6HlP1Jc4eFGLKZSzDcSCTa93FcbUWp9/+l0QKndVlQ7FGHjWd5qmIXGeaZ8HlHlQh7w 70UA== X-Gm-Message-State: AOJu0Yz0g1Yf16/otX+QuUDMEyzpqiv+KpHE8VwwyoIGEweyjW0jJtmF vEVb2d6D+Clag44wK/J71DjP+A== X-Received: by 2002:a17:902:7d92:b0:1c6:943:baca with SMTP id a18-20020a1709027d9200b001c60943bacamr19039967plm.28.1696982353259; Tue, 10 Oct 2023 16:59:13 -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 ij15-20020a170902ab4f00b001c9c47d6cb9sm940689plb.99.2023.10.10.16.59.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Oct 2023 16:59:12 -0700 (PDT) Date: Tue, 10 Oct 2023 16:59:10 -0700 From: Kees Cook To: Justin Stitt Cc: Marcin Wojtas , 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] net: mvpp2: replace deprecated strncpy with strscpy Message-ID: <202310101658.8D498F16F@keescook> References: <20231010-strncpy-drivers-net-ethernet-marvell-mvpp2-mvpp2_main-c-v1-1-51be96ad0324@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20231010-strncpy-drivers-net-ethernet-marvell-mvpp2-mvpp2_main-c-v1-1-51be96ad0324@google.com> X-Spam-Status: No, score=2.7 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Tue, 10 Oct 2023 16:59:21 -0700 (PDT) X-Spam-Level: ** On Tue, Oct 10, 2023 at 09:24:42PM +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 `irqname` to be NUL-terminated based on its use with > of_irq_get_byname() -> of_property_match_string() wherein it is used > with a format string and a `strcmp`: > | pr_debug("comparing %s with %s\n", string, p); > | if (strcmp(string, p) == 0) > | return i; /* Found it; return index */ > > NUL-padding is not required as is evident by other assignments to > `irqname` which do not NUL-pad: > | if (port->flags & MVPP2_F_DT_COMPAT) > | snprintf(irqname, sizeof(irqname), "tx-cpu%d", i); > | else > | snprintf(irqname, sizeof(irqname), "hif%d", i); > > 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 Yup, direct replacement. Reviewed-by: Kees Cook -- Kees Cook