Message ID | 20230913-strncpy-drivers-firmware-ti_sci-c-v1-1-740db471110d@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp134158vqb; Wed, 13 Sep 2023 15:57:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEyt+v9W0WLoemdnnvEt7NHcMpUJiKaSPgMtSWmUrQzfZ6sZMJd/6UNcIjUhxW5uwvx1WNJ X-Received: by 2002:a17:90b:4a8c:b0:26d:d3a:5e48 with SMTP id lp12-20020a17090b4a8c00b0026d0d3a5e48mr180916pjb.15.1694645824777; Wed, 13 Sep 2023 15:57:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694645824; cv=none; d=google.com; s=arc-20160816; b=sc9w6dy7cVDupSRhFWXwk195LUAnLkD6irMkODleLw2UeoBZsxULMqLHREjCG1y2je LBNjCbOWHaFerXHlPhAtciELUErH6KcqchDqwH5b5q1aJWGPCi5k2P6RmpD0OYUQt1R2 mGHZnWyT/TqSQKZC1KP7ejt3QR4ZqDgwW05BCnh12RS2zZURZtDNCszetCJjjSkEgYwo QeHZWgUCJpbP9a+HKT/XRriZwI+NHd+dG2LYW40RKmiVZ7g9/jCRv976+tokD22vAlM6 n7Nm5wPCAZDc01reIsycTEYV5izW2pcCtZ5LliN7R7X5k8aU3StJZQyb1mNkRdQB+IUy oj3Q== 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 Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id y190-20020a638ac7000000b00577a9ed62e7si134038pgd.405.2023.09.13.15.57.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 15:57:04 -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 95E7F80E6C4E; Wed, 13 Sep 2023 13:23:17 -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 S232241AbjIMUXJ (ORCPT <rfc822;pwkd43@gmail.com> + 34 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 <rfc822;linux-kernel@vger.kernel.org>); 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 <linux-kernel@vger.kernel.org>; Wed, 13 Sep 2023 13:23:03 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59b52554914so2971297b3.0 for <linux-kernel@vger.kernel.org>; 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 <justinstitt@google.com> To: Nishanth Menon <nm@ti.com>, Tero Kristo <kristo@kernel.org>, Santosh Shilimkar <ssantosh@kernel.org> Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt <justinstitt@google.com> Content-Type: text/plain; charset="utf-8" Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> 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:17 -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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776964940134002074 X-GMAIL-MSGID: 1776964940134002074 |
Series |
firmware: ti_sci: refactor deprecated strncpy
|
|
Commit Message
Justin Stitt
Sept. 13, 2023, 8:23 p.m. UTC
`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 <justinstitt@google.com>
---
Note: build-tested only.
---
drivers/firmware/ti_sci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
---
base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec
change-id: 20230913-strncpy-drivers-firmware-ti_sci-c-22667413c18f
Best regards,
--
Justin Stitt <justinstitt@google.com>
Comments
On Wed, Sep 13, 2023 at 08:23:02PM +0000, Justin Stitt wrote: > `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 <justinstitt@google.com> Looks right to me. Reviewed-by: Kees Cook <keescook@chromium.org>
On 21:03-20230914, Kees Cook wrote: > On Wed, Sep 13, 2023 at 08:23:02PM +0000, Justin Stitt wrote: > > `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 <justinstitt@google.com> > > Looks right to me. > > Reviewed-by: Kees Cook <keescook@chromium.org> Does this belong to stable as well? If so, please add appropriate stable process.
On Fri, Sep 15, 2023 at 07:40:38AM -0500, Nishanth Menon wrote: > On 21:03-20230914, Kees Cook wrote: > > On Wed, Sep 13, 2023 at 08:23:02PM +0000, Justin Stitt wrote: > > > `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 <justinstitt@google.com> > > > > Looks right to me. > > > > Reviewed-by: Kees Cook <keescook@chromium.org> > > Does this belong to stable as well? If so, please add appropriate stable > process. No need. This is a refactoring only. :)
Hi Justin Stitt, On Wed, 13 Sep 2023 20:23:02 +0000, Justin Stitt wrote: > `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. > > [...] I have applied the following to branch ti-drivers-soc-next on [1]. Thank you! [1/1] firmware: ti_sci: refactor deprecated strncpy commit: d8cce0d5ba4a3157a7a549b9623d1ffc5820ef92 All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent up the chain during the next merge window (or sooner if it is a relevant bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. [1] https://git.kernel.org/pub/scm/linux/kernel/git/ti/linux.git
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: