From patchwork Wed Sep 27 05:10:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13399927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 51D95E80A86 for ; Wed, 27 Sep 2023 05:11:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID: Mime-Version:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=IxGAeIbMhLeP7p+pHnzjelOALs2PkFg4KMaOnufFQM8=; b=4Ez 9yeQoDaIHxzIeezAXIOopQ+9vHUad/df28LeNGRgDgfKXCyyVwJch/tvTGXyu59yWmToVg4zrA+HM 8agc6RqBpQctJBJykXRVwJux9pGjUuvgg4pvskVJtatVRnXu9V0ipjLUpg8GmYf9vECvJd1JKithI ItRJ2Q3noBD/26RzGJ2ccwHc5s/g2HgtnEUlf7S9uico9I+xeOeIXiYErQd8fqdneqJ7BKN1iA0VK GMiucyLkig0xBHKr9KNitv1nU5NjcJcJmlniULWBZevQacCa7iA0kQzIgy4Ywo5bBTiQv85sOrvuS t53oW4zEJ5/aO0e+2fpRDjVG52hndqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qlMp9-00HZjh-2n; Wed, 27 Sep 2023 05:10:59 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qlMp7-00HZj1-0x for linux-arm-kernel@lists.infradead.org; Wed, 27 Sep 2023 05:10:58 +0000 Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81486a0382so16355235276.0 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=lists.infradead.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=wJJ/45Zh3xDCtdAtzWr4CbisKXVJpFSvQXPyi6EsplbLV9+RKeCS9SGAukyNcqkKSU UaXxV/RgIt3W+8BpdhE/nieWGA801XxdAADRov+3nUgxBh1PgKrOb+2xct3Oh9DaIDw4 mS7PCebg7jpmj2UOueW4liR0ferRMQJOQ3f8SaAw+h+qrVED+F3y77udkqYtDXDAMDu1 EAz7w02kKwlTZuIc334zGIwe0zTHIcU3SdoE+6Sc+Mf0Eu7qtrE0EiPrERQYk2gXehHO 7agHF/SKr+ecnGxDarY+swFpRN+mu5kP5Umoyi2UzgquFfQGk0VcZFnHR3aNFdkcCdcQ KdBw== 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=MyHdSWtGbe+GvnCIS9jd36PVGK4CPU0340pAVnwx1u9fhoVWuoSyVTxuu3V+KaKxdt VDx/dHbS2G8Vdtdc/slOgg0fRNrVibxg6H29yRDJbp6xVND6FJyTPmWy8dgHOnblgWwL kHyADGWv86LuEr1/f+RagLixn9ygkLt+srxhdYum+bYAD97p3QPRhSOCbrsEzdZimZu0 G9MfvDWSadK2AMlDhtG5uOxp7lJkDo5va38LJjmBXBtzJqkul+IdaY/wRz0A7zkodXUo E8g5TDS6V4g0MAlwSew/LwUWdqoniLScJ4mnW/7O5/+rATQ9JgMLPEC3GEpS0VUaQqrr DoOw== X-Gm-Message-State: AOJu0Yw33Fs4T88HoFI16xGMsK7Sj9u0Jws192VOXvUxJnOdeZvJDiFb D3nOOa/fJ1LvvaNbQN4nuAL8b7+/iqs3zuSBHg== X-Google-Smtp-Source: AGHT+IFnVvg1PuAx77h/MFJ8ZakIWwiEpv1J0wKrBDySJuQK38qrLMc4naF2k1eQ4es0jmO9WoyZfFTZLI3IaiSF+w== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_221057_357177_F71BE206 X-CRM114-Status: GOOD ( 12.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org `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 Reviewed-by: Linus Walleij --- drivers/mfd/db8500-prcmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- base-commit: 6465e260f48790807eef06b583b38ca9789b6072 change-id: 20230927-strncpy-drivers-mfd-db8500-prcmu-c-aeeff615bc80 Best regards, -- Justin Stitt 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,