Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3555844rdb; Wed, 13 Sep 2023 16:14:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsF4Xvhl9F9Wtt7oUb4Be2gsm+SLhpG17vJA60Iwv9t7m6fgshXNf6OKofsXWWVrZJQpLa X-Received: by 2002:aa7:888e:0:b0:68f:cb69:8e7f with SMTP id z14-20020aa7888e000000b0068fcb698e7fmr4568921pfe.7.1694646857640; Wed, 13 Sep 2023 16:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694646857; cv=none; d=google.com; s=arc-20160816; b=Xs2PsQfsyfyyTMZcnmF/b1ROJ8B8hkKCNkaHRr7gfPfi1ZyZMU2qJJHDRL26curfek crSvHmFt7Y2CmyV5o2V1zY9RYHus3f0NYib6LvXmQMxLXsUPfhjR8UJTs2i5N8rJQJWX ugpnJJjtaEaHnJBjhJ0wFLA6jyNyRgT0Urv/9nlBUYoU9QzqZDd2skocXd/RMNl45Wiq ZoTfiKNgajLSVxKc13BfX3g2gsJaoSnUBh9WsNFaw26RTeBz742tbnUe2uCNbbZJQl9q xhk4b0L34sUBH9m6njINItsEuvDZcsSnPGdmaUOT/wTzq/c3c9thn7R4gOFxJO5vjiOF n6JA== 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=iTSTWXZd+Qc8kQEsl400yBzqT1y2zESnQaxG1xsvJaA=; fh=z8dvGh0g0tIXvSSwqeFooryPVn+NNzd0xywAFY3ItoU=; b=yIo2oyyGobj4uFWgWPBiGW9/XHXkGFs4LRLuuLxrsaoJRdE+effwlldk9vKSttECMK 2bmU4IspVoR6FR1ZLa9DZ7afkXwxgxA1IW9CbAa44D7O/sEeCFC1jU5f7ptWOYcDOOet e7DyOp6bBRBZy3al9o2cChbUbC4fbSTAXq16VghlJAHEN2j+6diMeSho2JkJJ/tffdVx Ws3UxA+kKV+iy8oO8X4Y+MWAMKTmYT/6WdktAp1NBwQBGv46qY9Pu3LNgl04lrgK1xSH y3PDwwyost8OCSLOTKgdQJXrFolMSIS20SEDL26b+o+gUduYmURvkE9cHaKi8JheDBVn 6Eew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HCwHyOru; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id bu4-20020a056a00410400b0069024c6a9a8si233054pfb.389.2023.09.13.16.14.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 16:14:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=HCwHyOru; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 107348320DD1; Tue, 12 Sep 2023 18:10:31 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238020AbjIMBKc (ORCPT + 99 others); Tue, 12 Sep 2023 21:10:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbjIMBK3 (ORCPT ); Tue, 12 Sep 2023 21:10:29 -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 AF0511721 for ; Tue, 12 Sep 2023 18:10:25 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81486a0382so257109276.0 for ; Tue, 12 Sep 2023 18:10:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694567425; x=1695172225; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=iTSTWXZd+Qc8kQEsl400yBzqT1y2zESnQaxG1xsvJaA=; b=HCwHyOruBRi9VfQqcfOpXo7xNrWnwmyCNr+69VzYRHfu53Oqu222sFRxJaeAf5zaar QRiJyS+cyrpqjvL64JpvN7PK3mQOUN9eiNQ/q4QTxmzDCJbJI8Aw0fzltvWBBeK6/vEY PnBSvVkkTVd8Kx7b1tMfTp4+OJ1ZJ/bVuRGWaUt1+Ugwcf0KV0yLxS7dw6jOAVOBQpAl o66sziDimCcXpLuewjtT4wiXNzXCsPMwiDhcr98DRWYwc37d9PJ1e4wsizmRArCqXc6K gSYrgnAaRTu4vPnHQ4pxAejGUJ+b3p3TknDt0Mm92283Wc5vYdQ9LsT4eBP/ThVlC9kA whWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694567425; x=1695172225; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=iTSTWXZd+Qc8kQEsl400yBzqT1y2zESnQaxG1xsvJaA=; b=aQwLux4UdTLqIutGUSAUfRN0tWvMcxjgBX7/xB3g5Avv7cv4ULgDeSLXi2I0gOiTsi 7ieK/1YCCbHPVPaQPuHaeMSFQZlFnmNP0U21BVXK4GjxSU+utuHSFReP9LUolPralUoG plcgxfZisuT0PBV3M0cYTvxCS82TZfBFbw3L2X6zEti5iKMJLdZsJe2StCrurzmsXDfd R+BnYsuy6evzYIZegztYO6qBwNQoFKMIjbEhW07/sZSW1T3E8Iq6FV5uY2PwO31lWVLZ mmEmeOuN7kdERutba+FEIF1i+fT02nuZKy/O52ZeT0mrSy+D9gvWsQQjjRWELMJqxYPw atdQ== X-Gm-Message-State: AOJu0Yznb8rOxUYPk4/xNcvR8MGsCrY23iFSHCKv6Kaw89YtNljY5d2+ ZCm9FnVOfJiNB3kZHC/j+uX8tDk6QTgZE62Q0Q== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:341:0:b0:d08:ea77:52d4 with SMTP id 62-20020a250341000000b00d08ea7752d4mr21572ybd.12.1694567424762; Tue, 12 Sep 2023 18:10:24 -0700 (PDT) Date: Wed, 13 Sep 2023 01:10:24 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAP8LAWUC/x3MQQ5AMBBA0avIrE2iLQuuIhbaDmZTMoMQcXeN5 Vv8/4CSMCl0xQNCJyuvKcOUBYRlTDMhx2ywlXVVaxzqLilsN0bhk0Qxjhf6QzHgZCw50ziqaw+ 534Qmvv53P7zvByxhMlhrAAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694567423; l=1658; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=XVfRHzQuTBImCvXBurgaSYSr/Vjhen73sLf0hYhbk6Y=; b=Nx9E2Hb33C+dWpKRT232WwVU71QYhrtm0y8h6goM40QFhf4jRRWy8F4BVjnwubJR1AIB0krEx FTrQFMQi11GBea3GQmmqXOBkt1UaYJlHxwHtukgb+LQAlVQEJL2lTSt X-Mailer: b4 0.12.3 Message-ID: <20230913-strncpy-drivers-dax-bus-c-v1-1-bee91f20825b@google.com> Subject: [PATCH] dax: refactor deprecated strncpy From: Justin Stitt To: Dan Williams , Vishal Verma , Dave Jiang Cc: nvdimm@lists.linux.dev, linux-cxl@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 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 18:10:31 -0700 (PDT) `strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. `dax_id->dev_name` is expected to be NUL-terminated and has been zero-allocated. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer. Moreover, due to `dax_id` being zero-allocated the padding behavior of `strncpy` is not needed and a simple 1:1 replacement of strncpy -> strscpy should suffice. 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 only. --- drivers/dax/bus.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c index 0ee96e6fc426..1659b787b65f 100644 --- a/drivers/dax/bus.c +++ b/drivers/dax/bus.c @@ -103,7 +103,7 @@ static ssize_t do_id_store(struct device_driver *drv, const char *buf, if (action == ID_ADD) { dax_id = kzalloc(sizeof(*dax_id), GFP_KERNEL); if (dax_id) { - strncpy(dax_id->dev_name, buf, DAX_NAME_LEN); + strscpy(dax_id->dev_name, buf, DAX_NAME_LEN); list_add(&dax_id->list, &dax_drv->ids); } else rc = -ENOMEM; --- base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c change-id: 20230913-strncpy-drivers-dax-bus-c-f12e3153e44b Best regards, -- Justin Stitt