Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2363057rdh; Tue, 26 Sep 2023 23:31:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfX+m4SKcJgjL8GlEpWNC+ztGpgP/oislKigInrP3CfSojb+cq8wkQ5MHBSouH8owYGATu X-Received: by 2002:a05:6870:3409:b0:1dc:cd20:1e9a with SMTP id g9-20020a056870340900b001dccd201e9amr1166052oah.35.1695796265442; Tue, 26 Sep 2023 23:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695796265; cv=none; d=google.com; s=arc-20160816; b=jbOLZqRgk4/dPYrbCsb5TaE9UsJrSUjwhRxcp3XjiXlAsBIsnE0rxL++dh7uHRi85g P/E3TkUd224WkKNyQPoT4RyWxaAJas0ELlt2oBni6tTqls2bSbmzpulGky3B8Yvm8RyI TsT0//X7i1sehRLFJ+SEmuQU6o8ax72HF5lFStw/uUk0KkWqguJxxQPBpb7KAj+9HJNh acbkBqqz7Nz3T6VzVHhkaB5oifFR/xyi59Wh/cWhzl3bpdz9FG8zJVJV7NuXF9NdKMuF ELMXCPO/tM9RGU4canZNmFtPLlVqXZDHb4qadvUsT17eBThZ90amWjQL/3aYxyTYVRf7 LpGw== 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=aru77dJHpDYoQpT8/24nvfz2nt6AIFvt/5w/FoDAb0Q=; fh=93SW0raXijv6LTxrcPG7ucs/XrlHJ0MgJrZPs2xQMDA=; b=uif2kSqEL6AK9hJydDSqDJtvoN99wUKo2wiNiRPCPxYZdjEMxGzfbJrS8yTCXwJgcx fFCTLe0Y8PNn0SZxrPa5UGsSt1yKDVXDfcwOJYs8Den8wwa+3/mfPGeUtvOOB0tpeI+Z 9HryBRW4lfiPCGV8VK/h4t1zL5C9tP3CnhTuwen+0igORCp9n2ayfNlxUxgk4RwQdlbt DZ0+WuPQnQzGWlvC73pIYUH4SZS08ihCgy1ZhudELfsKm8EB4x63gqhDr/YS3esUwkAj 41wckIsNOxDz47pWxzk/hKnPiTgwr9drDBndeJ0y4n7/KIEVYhtgCV/Ghy8Qq8/xOgJo ZjNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UeW8blat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id r5-20020a63fc45000000b0057744d09d1bsi14927986pgk.251.2023.09.26.23.31.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 23:31:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=UeW8blat; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 2343D819DFDF; Tue, 26 Sep 2023 22:19:57 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbjI0FTy (ORCPT + 99 others); Wed, 27 Sep 2023 01:19:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229721AbjI0FTE (ORCPT ); Wed, 27 Sep 2023 01:19:04 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB221423A for ; Tue, 26 Sep 2023 22:10:55 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d7fd4c23315so16315182276.2 for ; Tue, 26 Sep 2023 22:10:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695791455; x=1696396255; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=aru77dJHpDYoQpT8/24nvfz2nt6AIFvt/5w/FoDAb0Q=; b=UeW8blatAFvIko7YsZsMb8BuKsL+xd0whILJkAwRaMQYEQ4MDcKJm3U+BGplv3krOG W22LnM/Nds9AQcQxXgeQL087uRqC1W9aDLFb9i9GpjrRmb4v0lke0+LTNOPukoSpQMpo 9ftGlygWF3pT9yzwCzUyouLAU6i2A/Nz68kBdNEA6LsQ/bGjGWMfEWwyUEK92jlyiNil w0ywGYvLZNSjgm+rkTuHcmzs+3EBtRV5VSXNarHRx9CEXowMJXZqxBjQ5cX+d8VVwJJZ 4oQcFvdDhAKwhVV9nRs8/iVWUerW161i8i8yK24k/qMWK/smvZ4vtM2Fq1eFJnF6Rqpq e5Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695791455; x=1696396255; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aru77dJHpDYoQpT8/24nvfz2nt6AIFvt/5w/FoDAb0Q=; b=PcxXxXCxdF6PsMOxI3fsttco47IeMsIxH8mv87405sFHA5x+VLX6Z9MgTy7hzO4Chk yoDT6vrPG8g7z+ER2S7oNxMPrY/a4bThFNVBwM64dOhd+ER9dMhlbPzFbLv8i+YqsFV+ jkhck3+T4Qdx2vx5io4VBFRmbK0nNqGszYx3BErU2rHgD5l5ML49E4FLt1jFgHRHZp8f LcajIMa23Z5npTZa/MPnR83b1WhGNWsCssQ+h/PwI9aA9aymvIVeK3sUN2VVCPDPd1p0 gcMMikMGRlbbdkBmYbz0GA9DVOEqRJ4DjNIz0m8CvDF9ZPxhlN1oooI54g2LbyIYMC8E RdAg== X-Gm-Message-State: AOJu0Yw6slnin1vi0SnBUvghau4/ei5MPIDpWnE9pz+xC8MZ4AmtMdGG zeZ1a4YS7+FKr5+724dexwS6fQITsagfQyjyBw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:b91:0:b0:d81:8e4d:b681 with SMTP id 139-20020a250b91000000b00d818e4db681mr9870ybl.12.1695791455116; Tue, 26 Sep 2023 22:10:55 -0700 (PDT) Date: Wed, 27 Sep 2023 05:10:54 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAF25E2UC/x3NQQ6CQAxA0auQrm1ShqDoVYwL6HS0C8ZJiwRDu LsTl2/z/w4upuJwa3YwWdX1nSvaUwP8GvNTUGM1BAodXcMFfbHM5YvRdBVznFPEOA09ERbj+YO Mo0hK57afeCCooWKSdPtP7o/j+AGnvRbcdAAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1695791453; l=2189; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=fXXhr7E2ROv3mcXLZOf8/x1Ki4LsCzf8WOLlQCbDXpg=; b=MM7Zkg9rR+jOqbymVKilqLSpPNnDQPJSrb9+9Iw2lOmis4kPr3Pbyx1d5BrMPSINjL+a4xdg6 gCzFjdWEfdHC4PS+w7F+tgsSrtjfD3FLHGUNbJQR9XT4eh4JvcWMvxJ X-Mailer: b4 0.12.3 Message-ID: <20230927-strncpy-drivers-mfd-db8500-prcmu-c-v1-1-db9693f92a68@google.com> Subject: [PATCH] mfd: db8500-prcmu: replace deprecated strncpy with strscpy From: Justin Stitt To: Linus Walleij , Lee Jones 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" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 26 Sep 2023 22:19:57 -0700 (PDT) `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 project_name to be NUL-terminated based on its use with pr_info: | pr_info("PRCMU firmware: %s(%d), version %d.%d.%d\n", | fw_info.version.project_name, | fw_info.version.project, | fw_info.version.api_version, | fw_info.version.func_version, | fw_info.version.errata); Moreover, NUL-padding does not seem to be needed. 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. Let's also change `PRCMU_FW_PROJECT_NAME_LEN` to just sizeof(fw_info.version.project_name) as this is more idiomatic strscpy usage. 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 --- drivers/mfd/db8500-prcmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/db8500-prcmu.c b/drivers/mfd/db8500-prcmu.c index 27a881da4d6e..5b3e355e78f6 100644 --- a/drivers/mfd/db8500-prcmu.c +++ b/drivers/mfd/db8500-prcmu.c @@ -2639,9 +2639,9 @@ static void dbx500_fw_version_init(struct device_node *np) fw_info.version.api_version = (version >> 8) & 0xFF; fw_info.version.func_version = (version >> 16) & 0xFF; fw_info.version.errata = (version >> 24) & 0xFF; - strncpy(fw_info.version.project_name, + strscpy(fw_info.version.project_name, fw_project_name(fw_info.version.project), - PRCMU_FW_PROJECT_NAME_LEN); + sizeof(fw_info.version.project_name)); fw_info.valid = true; pr_info("PRCMU firmware: %s(%d), version %d.%d.%d\n", fw_info.version.project_name, --- base-commit: 6465e260f48790807eef06b583b38ca9789b6072 change-id: 20230927-strncpy-drivers-mfd-db8500-prcmu-c-aeeff615bc80 Best regards, -- Justin Stitt