Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2944793rdb; Tue, 12 Sep 2023 18:13:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFi/VJKrVGhzDy8T79zkB5WR7Q6yWuwXX6bIY8VIygnLeL7rq6UymTxWgzP7ZtU+RXGmY6w X-Received: by 2002:a05:6a00:b4f:b0:68f:b72f:9aca with SMTP id p15-20020a056a000b4f00b0068fb72f9acamr1593408pfo.27.1694567635730; Tue, 12 Sep 2023 18:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694567635; cv=none; d=google.com; s=arc-20160816; b=IDZRWg9VKWl9LUXuC17PZa8R4ErWr4pY/HV2hEe4dHalhn7zNYv36qnqPry7h5/lg6 n6VdkXb0e6k3De9y8s7OBoyVp5D3GgY0W7fWct6tvGQCoQkNqj/iY0TaUVUYhVjYhLXw N74Gs2LD+qw15b1uMpRa+t9FNT9KwQKIC/+hng4TauWcpLYKiJ3HnlhWdbLSTNazMTRZ 8SAoVBDunJoAZ3YaGO1K7BG3/gt6edb58Jzvpsk/I/RnJBqKYuTuWp+kaZfqNxf1qGx/ SPT3MyqZr6TI8HDZC+J5e+NfmTDVtQoFCAmApfAXB+ZbO0jvisrGFWRMqEuZa8RDLT1p MNjw== 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=rS41v4+xCLukMHjrW3MQeGbkMoVH4JjPq9tKkeyfYe0=; fh=2TGKxm889jwumBaQIEptCydu9MljJ+amfRlEjvuA4+w=; b=rdNS5+aNRufYU8eBmuCHECbNQ0xYGVeDim7gPN7BYZ2QxN9pgFW9I/5UiabUo+b6uN WgdyLBOYBMDfmbcxiOBx3WAa+gVkCeK79pz/libdxnn94pBGjFfOC7140Lzno2fpBcJf DIhDo8Y97SD9U1qAh2kdBu3OayZfGRVnHLRqClnCWhP+YdAD59TXRpG4sjshfa5jI5ma UmrKRskK/n3lP1uWC1qhkdk/Ksc6C+JLV0vW5HerINxhyFNQ9u5ExwVdIWFOGlh1BjHw ROernD1ke35a0K1qqTtw1WqOD9awed7HS+dT91auBt9afp5o2dBuZheb2JCn7lLyK57Z u8ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="r/ms0Mah"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id a9-20020a656409000000b0057400cc5c62si8575366pgv.197.2023.09.12.18.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:13:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="r/ms0Mah"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 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 lipwig.vger.email (Postfix) with ESMTP id 7D427820D5CE; Tue, 12 Sep 2023 17:07:38 -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 S235236AbjIMAH1 (ORCPT + 99 others); Tue, 12 Sep 2023 20:07:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231166AbjIMAH0 (ORCPT ); Tue, 12 Sep 2023 20:07:26 -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 C2A7F1705 for ; Tue, 12 Sep 2023 17:07:22 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-cf4cb742715so5970550276.2 for ; Tue, 12 Sep 2023 17:07:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694563642; x=1695168442; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rS41v4+xCLukMHjrW3MQeGbkMoVH4JjPq9tKkeyfYe0=; b=r/ms0MahvvLg1nsm9lhDohSbOVvs1L7d74dODp2hppTOQ/vw9bEW0QyMN/JiWDaFEk 29nLDqYTg/nGjJqyEj7+fTr/jVsRNLhbZR+brsIbzh5wdg7LlhxtDbtSGHVeCAJYIovc c542UyNxiJixMZ0XRRGna+q/kdEA5vysSLkERBDF3BM/5i/P9wbynsJf8FKRXaWNSpTf 2cM2SI1pUNyAxTIurK3nPFahSpTgDs+ZqZmT0z8a+FeLdcYVEKEHZKKfzkw79n7zh/DB 5vewTu+5WTTaThk4ZsdPR62caPvKiUwGWDQXOHWwC7v4+HMJHgfUHZ/KiYZ0gV+EO6K0 mZCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694563642; x=1695168442; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rS41v4+xCLukMHjrW3MQeGbkMoVH4JjPq9tKkeyfYe0=; b=jJQH1Jguhj0tONqIyPFHawOvZcg+vC68WU9AljJVaZrn22x6OkHj/R84CaNVdxs6v+ RguxWPbTpyO51AxDC4JadlTkaUkjy1Oyhb+XkCJ4SEqn2vSIsKODnR46sdx2m31jCf5i Qop32F0KufM4tGa40EmBzhtt5BvPLOlbfpi/9Qi2VkD+iM+hn8qeLaPJEYUC+7fqo9lJ emO5yW9r/eL9em9LA9NrgjrZA2ee1dhcU16o5T241PoXaYkRO0G2/sMBfooVTxd/AA4g uqGxYZ4Iprz14RLZn72RtDB6wWOfNt4pfGLclXD6RQ6fVoTTokWw6mMCLh+K7LQfcNLg xLrg== X-Gm-Message-State: AOJu0YzoUH4DFvYtgKdV7ZTgw6hkL5/PVHxi9W/OLBeXgJ8jhMDxQG64 Vb7P0MnGJ/cvtJ1epChIfmrIUGz5rO/q2x+OZw== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:c708:0:b0:d47:4b58:a19e with SMTP id w8-20020a25c708000000b00d474b58a19emr23433ybe.11.1694563642045; Tue, 12 Sep 2023 17:07:22 -0700 (PDT) Date: Wed, 13 Sep 2023 00:07:21 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIADj9AGUC/0WNMQ6DMAwAv4I815ITkIB+pepQEgNe0tQuqAjxd 6IuTKdb7nYwVmGDe7WD8iom71TE3SoI8ytNjBKLgydfU+882ldTyBtGlZXVMORlVP5cRBc7Imq agaiF0snKo/z+j8fzOE45Cw4wcwAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694563641; l=1848; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=d3eQRnRSox3gQAlO9beeck6HgLvQ+IwgKHU5fYXPsic=; b=jGth39PpsB/iSIfhy+Tf1rrdgm6kZNr+Tn0YEGuIUABXOvuFXngcCGXpB1DsuuWOFHCV0K07J SXvBj9oQFzDAQ3vAMxAu789ZhsgNqJwmeEHaN9k4hPqccCKoOLw2uBa X-Mailer: b4 0.12.3 Message-ID: <20230913-strncpy-drivers-cpufreq-cpufreq-c-v1-1-f1608bfeff63@google.com> Subject: [PATCH] cpufreq: refactor deprecated strncpy From: Justin Stitt To: "Rafael J. Wysocki" , Viresh Kumar Cc: linux-pm@vger.kernel.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 (lipwig.vger.email [0.0.0.0]); Tue, 12 Sep 2023 17:07:38 -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 lipwig.vger.email `strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. Both `policy->last_governor` and `default_governor` are expected to be NUL-terminated which is shown by their heavy usage with other string apis like `strcmp`. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer. 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 --- drivers/cpufreq/cpufreq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 50bbc969ffe5..3eb851a03fce 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -1607,7 +1607,7 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy) } if (has_target()) - strncpy(policy->last_governor, policy->governor->name, + strscpy(policy->last_governor, policy->governor->name, CPUFREQ_NAME_LEN); else policy->last_policy = policy->policy; @@ -2951,7 +2951,7 @@ static int __init cpufreq_core_init(void) BUG_ON(!cpufreq_global_kobject); if (!strlen(default_governor)) - strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN); + strscpy(default_governor, gov->name, CPUFREQ_NAME_LEN); return 0; } --- base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c change-id: 20230912-strncpy-drivers-cpufreq-cpufreq-c-1d800044b007 Best regards, -- Justin Stitt