Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp4887611rdb; Fri, 15 Sep 2023 15:57:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2SsSojweTw+Ylx6aZT6oXuQOeG802ge8KUbXjtCH4C10a1sCRadAr/8/zjifqYH2oiQRv X-Received: by 2002:a17:90a:fb41:b0:26f:6f2a:a11 with SMTP id iq1-20020a17090afb4100b0026f6f2a0a11mr4003266pjb.12.1694818635255; Fri, 15 Sep 2023 15:57:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694818635; cv=none; d=google.com; s=arc-20160816; b=jFw1GTNr9PZGKIv3F4J1s7hP/HGn4tQcHGRceMrCV23wOGeVVKb1sQoX949fJw04ul RQjtmQaCtkj+Mlh6GgAySSYM4zNMmBqNGO4OHjuDzmA4+fzez5yBMjpFn4o3JGiR4ZHn aBZS7j6s9NR1e75X3QSPONRQz0vsl8jutaTsE76zDXCVByHpCVkgZhCKHhA/rhjPsBbR eUBM1JDTEHgbyWPVZGprGpYGPmuBgro7YH4ONQpZ/kWWG7BlJL5j0OH/evD5ou1SqBwZ DrmDL6Dc3ikXWfOSjPH7AvzXuhKpBwSd4tOj2MTs4ljgxbxQqsMo+JXDPaGUMV7faGuk Ud6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=XLVs+6bnfHlUZtqtSLrfEVAUEdElqt9QJcV0k0rrN6k=; fh=ypCrBxbZFK+faJyzQuhyrh8t/7mHap7A5uKCzxZ+LpI=; b=r46MuVxCKKt50b9iwniyRN8XLaIG+Pgrl+zR7hEzTM0E1H6p1oItkaScqwDqypz/1R WEXKWbiNCt58tC1Bxqi/Tr33GVzXfWvl5jQ8lThVeN9/onXK0sGCVaV+pQOcxQTtm7NJ u2+m2Lv1v6zomlrEgprdlAip/9Ae2shktBROpmoJYJaqizsE2cSQ4fMoDi88bvZFui+o q1qB4N7J0k8fwZPS0H1GQxcp1ITve/4u1gFVPmwhBjmV5A/upPXsRKYG6wDPxBjuDE3a WuvYxGfu5sI+6OqfNbmd/42Y3FoyCMELif/jMc1xc6TCAkwTu/nkrpLiosVTWFunof+5 LQHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Y6tP84ER; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id s8-20020a17090a13c800b00274b3ec1d99si692576pjf.78.2023.09.15.15.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 15:57:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Y6tP84ER; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 5D40981CB0CC; Wed, 13 Sep 2023 13:23:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231648AbjIMUXJ (ORCPT + 99 others); Wed, 13 Sep 2023 16:23:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229527AbjIMUXH (ORCPT ); Wed, 13 Sep 2023 16:23:07 -0400 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB2581BC8 for ; Wed, 13 Sep 2023 13:23:03 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59b52554914so2971297b3.0 for ; Wed, 13 Sep 2023 13:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694636583; x=1695241383; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=XLVs+6bnfHlUZtqtSLrfEVAUEdElqt9QJcV0k0rrN6k=; b=Y6tP84ERqkDKcGxAVmZeOsN/6uvjKSNey2wMz4IBgzyXgZnA6NqK3yiBSY1fvjrT3q lfRhCUMp6QUwQulGXeuOfctXBwaAK+ATBzSFvzR5f7N5ZRINgNOf2yooIho7Ruv1mMUs G3ROcRsoupfRYWqIjbp5Wq2D7X3u/wkAu6tXkogBjEsAtOEsgS5qc34Q15qD2bkalbjo nKEKkcZ2trK8dDXJmwQVJ1p2/95e0frU+k0KrXCzSwM3t3U4JlhhkGAaQimlDd/3kdV4 rBOZbQkns4oSbMcC7PxIDd4nuZzrWACFSBB8+wFg1Qb+wgpu1irK997WubD2WUVC5RoR yKpQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694636583; x=1695241383; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=XLVs+6bnfHlUZtqtSLrfEVAUEdElqt9QJcV0k0rrN6k=; b=w0L+WJkRohLrIRR6/buqVqzDTvOovF3soikjfO85RlF+FQd6tx3ehfHzHRBCmIUlmM fSmLkQNwk9KzOdIrvxoiPP22mMUBOYfhD1/H3BEV9D5fBXQNoPyZNG/F9D9Jqfbd44T7 EsLXL2JRv+aXRRBLVAVK7RrcSlSh4hdx66OrrQSKdzXAYmArbZy+dkF/+LhUK6YjIUq3 WWY47inW3Fx9zwetaA2StnvAl6APBPp0SQ83ap29zm2mz25lo7w0cVFFpl3iZlYYZZLJ EdTCpWWW7zJ61KMpVijx3NN99G4lxI7lqOdDPEBEruwMiYPnRGDaaZbHXTZ3oyjhKnNF rxxQ== X-Gm-Message-State: AOJu0Yy82eNbxoxqgVBgqZS53ZUhJgC/ucAg0I+Ha8pU2IqL1ge79CAk Oe+nrvY6kqQEZNwAwVfpNDaA1ddRqz6b/4n0Qg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:690c:3108:b0:59b:e97e:f7d7 with SMTP id fb8-20020a05690c310800b0059be97ef7d7mr10791ywb.1.1694636583064; Wed, 13 Sep 2023 13:23:03 -0700 (PDT) Date: Wed, 13 Sep 2023 20:23:02 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIACUaAmUC/x3NywrCQAxG4VcpWRvozJR6eRURKWlG/4VjSUpVS t/doctvc85KrgZ1ujQrmS5wvEtFODQkz6E8lDFWU2xjas8hsc9WZPrxaFjUnDPs9RlMecbdBSw cY98fu5AknDLVzmSa8d0f19u2/QEyILlDcwAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694636581; l=1662; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=SaJSLsGfiwN8Z9qDzVTnJDfBIIvce2p/HX14tKRLMrc=; b=isyfhr2IybzgbSgYpUiLNvFNLLapon+q44khS63C6lQdJpD07Owf7rFKWlnZSjXr/pvfX+d9M 0S8wXWPqEHHC6Q4LPImWcaxPhpnnxPUrHci8d0JQRBWvVp9SeWxgjZZ X-Mailer: b4 0.12.3 Message-ID: <20230913-strncpy-drivers-firmware-ti_sci-c-v1-1-740db471110d@google.com> Subject: [PATCH] firmware: ti_sci: refactor deprecated strncpy From: Justin Stitt To: Nishanth Menon , Tero Kristo , Santosh Shilimkar Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" 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 (morse.vger.email [0.0.0.0]); Wed, 13 Sep 2023 13:23:09 -0700 (PDT) X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email `strncpy` is deprecated for use on NUL-terminated destination strings [1]. 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. It does not seem like `ver->firmware_description` requires NUL-padding (which is a behavior that strncpy provides) but if it does let's opt for `strscpy_pad()`. 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 --- Note: build-tested only. --- drivers/firmware/ti_sci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/ti_sci.c b/drivers/firmware/ti_sci.c index 26a37f47f4ca..ce546f391959 100644 --- a/drivers/firmware/ti_sci.c +++ b/drivers/firmware/ti_sci.c @@ -485,7 +485,7 @@ static int ti_sci_cmd_get_revision(struct ti_sci_info *info) ver->abi_major = rev_info->abi_major; ver->abi_minor = rev_info->abi_minor; ver->firmware_revision = rev_info->firmware_revision; - strncpy(ver->firmware_description, rev_info->firmware_description, + strscpy(ver->firmware_description, rev_info->firmware_description, sizeof(ver->firmware_description)); fail: --- base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec change-id: 20230913-strncpy-drivers-firmware-ti_sci-c-22667413c18f Best regards, -- Justin Stitt