Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp3107360rdb; Wed, 13 Sep 2023 02:07:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEEzxQs2Yr6NqAygw/LF9RKd4ngd87c2gBfds93C9ZUB0HJZs98zsqN2Jd+W1F0aUPbpiRd X-Received: by 2002:a05:6a00:39a5:b0:68c:d6f:212b with SMTP id fi37-20020a056a0039a500b0068c0d6f212bmr2146418pfb.19.1694596027492; Wed, 13 Sep 2023 02:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694596027; cv=none; d=google.com; s=arc-20160816; b=znSzFB7fmCAEcyL3ziW1r1lO325ZmWMjKTsNrb21BVifd3OQsz4NRJYukQKOe8l7kF izoSYDVKAZ0KjC4fSW75/g5BXMJP0NGVGMr9aQ0qlXaLU2weXQP0YJGMfAIPmONIbCeB HMgHM1xL527yfqh9FmO396ULixMJ8AQGDH/WvpRIIsoY0Hg1h8JHgSKWB5khxzHUeaoA XiFjCdcRWNl2H4ryHaLNk2bhQJrKUjB/3WmfC7ck4SDk9USkjiDf+XvphaPuu9sOhcty sFrD4+r+1NXlAWv3WwmfdQjWfHNHvxxC9oPtOMBZ6a8wlMbQKa3TwFqigL0MmU3mAnwm 5UQw== 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=DtPnDCTduCEq3Qr2ITLJnxh4c9FOD2gvVINJPxBbxIM=; fh=yqs1HYG6igK70OW5P8bO74CVtWmyfN5AzyYa3IY2+2E=; b=rpMjcqyK32HPXuNmIhWvr3tuvkjAz+CrofCmc1SR9gla6xaY7md3ftzJ8hbPEM5AJM SG1PrUdus5INQSBeHL0QfSAMaSoYAyU1Gn46rNSWrcBdhfNWpWG93uxWzyXcTICEVubT ovFNx9f+01YoZTf5Gmgas4HPj1b1cPOfPJYhkdmybvZA6x3NAHFHcHEYKBvmPCjRduX8 HW4DZH2bJ+LoRwTZqV5on9fCeNFAydA0yCn4A3Snw/OWP9nfFda1kTN0+yeb1eif6sTD ovBncop0SQMgDQU0ixuj5AgqtGJAb5qfJtZEdVe+XsFu1/YhDuduDU+321jDfxFzbjig 4FqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=M9HE9gpS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-crypto-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 s21-20020a63af55000000b0055c7eb53d7fsi9788385pgo.584.2023.09.13.02.07.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 02:07:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-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=M9HE9gpS; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-crypto-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 05B5C829F643; Tue, 12 Sep 2023 17:51:08 -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 S237580AbjIMAvK (ORCPT + 99 others); Tue, 12 Sep 2023 20:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbjIMAvK (ORCPT ); Tue, 12 Sep 2023 20:51:10 -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 6F90E125 for ; Tue, 12 Sep 2023 17:51:06 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-cf4cb742715so5997116276.2 for ; Tue, 12 Sep 2023 17:51:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1694566265; x=1695171065; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DtPnDCTduCEq3Qr2ITLJnxh4c9FOD2gvVINJPxBbxIM=; b=M9HE9gpSilLT/CYs0oWeMyB+mCD6/NQUz3ojVhqmGa3sHNL3qeDpQxnTxGrPn3HXVl 7wTZAFRNlH2BH65QvceQl7KpX8bC/u6SuqX9qlRWCLMXj13EAa1KuPHCalL2BOoeULLm kplnbB7z3Dq0+7lOZP7ctvBjuuFEq2JrSnP3mlfoFFlMVZ2+sqFQYmQvpGT+Juf3M227 SuN14b6S6wjEUi0UlnYMZLXuG8WJoCixjsM0zRH7hpWglM7pW3aNkZL5t0iq0aTsJdxc b98Gm4LsMdIXMBMdfJPFXXqYBy8lnPS6YG+R+0UMtqnx9V38ZEyDtL98BrivaH6R2nHM wZqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694566265; x=1695171065; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DtPnDCTduCEq3Qr2ITLJnxh4c9FOD2gvVINJPxBbxIM=; b=turg05QBBddf4yCFn6V+1+Y6pRDOpcCX2pVZY6G0OeUUdDxmivwXlp4dVWaogxTnkJ 2LTf1mQV/GVKm2X/CskgwjrmknABR8QDkamC4kDVY6ZvKsOARP8LX4k8eLVFnzEB0PVO IPssEzW+J7YQanPBida6osJKKdHkEGiVhL3+u24cqy4cNY2EXvHLoxmXnCnTLpShOwLV l5eoMLP7Um97A+zVXjGDsvXgF9wkTeJaU1PAOdT1P3R8ndTV3oyBQfdM1FVNSjGKVXYq pDOrZEmtp4/VcF7LnCb+cNMx3hAU1J3eArg6oA9KcpXr22qyVbZGyhAyrlXBV3OeEUrP AD+A== X-Gm-Message-State: AOJu0Yy1ZdRzm+yP4kHH3w18hM7phMflwtP5bS55SYKsgbQKz5ASUICI TTCHQy3oZXn5FHqjquaiSot5ZVKQ8p5x6KQ7NA== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:80cf:0:b0:d7a:8e37:6d4b with SMTP id c15-20020a2580cf000000b00d7a8e376d4bmr24345ybm.3.1694566265616; Tue, 12 Sep 2023 17:51:05 -0700 (PDT) Date: Wed, 13 Sep 2023 00:51:05 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAHgHAWUC/x2NQQ6CMBBFr0Jm7SQtVSNexRiDw1QngRamlUgId 7eyeMl/m/9WSKzCCa7VCsqzJImhiD1UQO82vBilKw61qZ1prMOUNdC4YKcysyYkXcYcUULmHqc 2/3lQHIYY9vmhPiKh8cenPV+c8acGyvmo7OW7h2/3bfsBsFNY4YgAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1694566264; l=1599; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=HFa7caLHh4Y4K31X6bYgfzu3rT5WKQkHKQH1LYS4bEc=; b=+lu5hyujktY6X9/cBe5+BmqWrHRCKzqDZdz0TNVSMtMZRhiU9xGmyaYaMN9EBmB1I+nNLMEz7 9VTSzTgoBnkDFy9+1xv8Sosc5rYEZRxUPDH1+VCngkJ7eL9yey6Slg7 X-Mailer: b4 0.12.3 Message-ID: <20230913-strncpy-drivers-crypto-intel-qat-qat_common-qat_uclo-c-v1-1-88a6c07fc924@google.com> Subject: [PATCH] crypto: qat - refactor deprecated strncpy From: Justin Stitt To: Giovanni Cabiddu , Herbert Xu , "David S. Miller" Cc: qat-linux@intel.com, linux-crypto@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-crypto@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 17:51:08 -0700 (PDT) `strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. `buf` is expected to be NUL-terminated for its eventual use in `kstrtoul()` and NUL-padding is not required. Due to the above, 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 only. --- drivers/crypto/intel/qat/qat_common/qat_uclo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/crypto/intel/qat/qat_common/qat_uclo.c b/drivers/crypto/intel/qat/qat_common/qat_uclo.c index ce837bcc1cab..e2f82128043e 100644 --- a/drivers/crypto/intel/qat/qat_common/qat_uclo.c +++ b/drivers/crypto/intel/qat/qat_common/qat_uclo.c @@ -200,7 +200,7 @@ static int qat_uclo_parse_num(char *str, unsigned int *num) unsigned long ae = 0; int i; - strncpy(buf, str, 15); + strscpy(buf, str, sizeof(buf)); for (i = 0; i < 16; i++) { if (!isdigit(buf[i])) { buf[i] = '\0'; --- base-commit: 2dde18cd1d8fac735875f2e4987f11817cc0bc2c change-id: 20230913-strncpy-drivers-crypto-intel-qat-qat_common-qat_uclo-c-0f4b16830f59 Best regards, -- Justin Stitt