From patchwork Thu Sep 14 23:10:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 13386197 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57785EEAA7A for ; Thu, 14 Sep 2023 23:10:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230113AbjINXKk (ORCPT ); Thu, 14 Sep 2023 19:10:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229725AbjINXKk (ORCPT ); Thu, 14 Sep 2023 19:10:40 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E19051BDD for ; Thu, 14 Sep 2023 16:10:35 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d7fd4c23315so1677058276.2 for ; Thu, 14 Sep 2023 16:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694733035; x=1695337835; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=KF0ypLEqc8BBDWzXbz6oiYZjtdi3CP4D2nc6vcNdwQ8=; b=dcm6mUs6NrlRr3+Bv4MU/6hRlV8JryV0LkFeM1Rs87sn8Y2hKrFJH9CBA3ZYg6rEUD qotPg+8AlWD4BihnV0IeVn/O0sWC0oxVgqBV4ekk6Bzmzm2sDZcR2AgQK+xCjswEcEZy T75X+lKpFPb5PZQtmkx43qdHMBMcauFmJa8ae3znI1T8xk2IMvOEajy+bVL5DlT3ILhx htKAqPXAcQg/+bAdrySOK2/MRvzieRTxrAiieZIi6qXaOd3rQHX9qJdItganmcF8SDAS 8iTPDSmgUGWVKOLNDMFTmhtwVzj4NT2mkVRriapokM5smLE69wGvGYgSg58bo+/ePLqh w+0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694733035; x=1695337835; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=KF0ypLEqc8BBDWzXbz6oiYZjtdi3CP4D2nc6vcNdwQ8=; b=hJSjEaOGsM+y5tekIy7QrWJrcOxdPQoOzWGkPGxGEhqrvAxPYLYjoW5IxQR2Imyhbw tnKUklZSFXMtqc8nUmm8W7e4IytQHU3d1BQbNvyhtQsl6BDzgnscH5u3ilBME2cWALnd Q0t9UX800aZxjHvrfWj8Ql2bRApvMd81Mrsj0ZvnmeG+z9xHcoJ2j690t44Irl8jYm1Q YTrsmO2FWkxnT7dDYTbD0iWo3C1SP/PfItwgziKqnyw+he5wXlNETRK/vS5SA31kOW6m HHPt6qv+9vVbtID1b9HyM319VxJaU212NEkDynNWhR5x/Ld1RX27lMFBQ5zgd/jsFRvk pGfA== X-Gm-Message-State: AOJu0Yz7F8CZj4Kgtbx+d2L6MdLjom9WaIj0C9c2wTlCchjNd7kHHOzT aExyxwB/CnqbcXQv1/V3aJIO6Tz2tMMqpMWF2w== X-Google-Smtp-Source: AGHT+IEILjzGGETs9OgY3sII6tzaC1e1gmqUd3mwSZtiyvhjJac1glb0Y6mJhrCOidnIMcdGRfBU+6AqAxMZUqgzow== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a05:6902:684:b0:d81:8e4d:b681 with SMTP id i4-20020a056902068400b00d818e4db681mr80330ybt.12.1694733035150; Thu, 14 Sep 2023 16:10:35 -0700 (PDT) Date: Thu, 14 Sep 2023 23:10:34 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOmSA2UC/x2NQQqDMBAAvyJ77kJiQ4v9SikSkm3dgxvZrVoR/ 27oceYws4ORMhk8mh2UFjYuUsFfGkhDlA8h58rQuvbqOh/Qvipp2jArL6SGwzoWwWiz9evIvZF YqToheUeuCzHc7hlqblJ68++/er6O4wQmV5npegAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694733034; l=1557; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=1iP5Kt48YlJbVGCF4UiawrlrXPZCOJ+oBhMz4zjhzn8=; b=STd1ZyVgYq02tF3XVQ/Irb/McEXI8g01pYBzaUJmsnLEJJxLiij7ySF3piV/6RfuxFPDTD0hi 6RSnhuI3LY9A89UlMBC96MAOPsGwzwiEx7mkwcGty1+A9V8bdZgr5gx X-Mailer: b4 0.12.3 Message-ID: <20230914-strncpy-drivers-hwmon-asus_wmi_sensors-c-v1-1-e1703cf91693@google.com> Subject: [PATCH] hwmon: (asus_wmi_sensors) refactor deprecated strncpy From: Justin Stitt To: Ed Brindley , Denis Pauk , Jean Delvare , Guenter Roeck Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org `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 without unnecessarily NUL-padding. If, for any reason, NUL-padding is needed 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 Reviewed-by: Kees Cook --- drivers/hwmon/asus_wmi_sensors.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 3669558bdf354cd352be955ef2764cde6a9bf5ec change-id: 20230914-strncpy-drivers-hwmon-asus_wmi_sensors-c-e10e094a467d Best regards, -- Justin Stitt diff --git a/drivers/hwmon/asus_wmi_sensors.c b/drivers/hwmon/asus_wmi_sensors.c index 6e8a908171f0..c2dd7ff882f2 100644 --- a/drivers/hwmon/asus_wmi_sensors.c +++ b/drivers/hwmon/asus_wmi_sensors.c @@ -300,7 +300,7 @@ static int asus_wmi_sensor_info(int index, struct asus_wmi_sensor_info *s) goto out_free_obj; } - strncpy(s->name, name_obj.string.pointer, sizeof(s->name) - 1); + strscpy(s->name, name_obj.string.pointer, sizeof(s->name)); data_type_obj = obj->package.elements[1]; if (data_type_obj.type != ACPI_TYPE_INTEGER) {