Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp910266rdb; Fri, 1 Dec 2023 01:41:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFGS8/YteBkIN1wWXU9xZuX/+FKR+eFnVCfORyaoMGRLf3K9xtH/o5hv+9k3vcSWwniNt36 X-Received: by 2002:a05:6a00:39a3:b0:6b8:a6d6:f51a with SMTP id fi35-20020a056a0039a300b006b8a6d6f51amr28410988pfb.31.1701423694101; Fri, 01 Dec 2023 01:41:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701423694; cv=none; d=google.com; s=arc-20160816; b=L26hI5ZJZwfGoyGXH3HdfJs20lOMFwm6kMAGc+8t8ruZhXg1h//sYwyfbh2LagPrWf oT/9m8JUHt5QthZkjFDX52u4N1wJZ0MxOtj1X/6vk9pOpdR7dHeY5/8MNFjA3lX5VL92 3W2RlidGYFS/jN/0I+5/FISyDLBB7jNh/vKzkvSLVBdnQMaD8lnQ4sj1OA69etui/6Bk Rpsnbw9ARjs8Y0h+fe9xJJZi0C/K1qpvvmfXTVcMI4T4/lpMOGwKY9bDNXkmk/WntTrJ Jldx6surEuKDb7kkDPcUx159KaLL3fRVDLoeqXMD6vMDtRJaY9pQZoYcbvuQ6HAN9zze Lo5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=SCXwSfrAxD/vcI+luNSFDB5IfnqNmy8gsBQXv6JPB3w=; fh=20fZHoB1Xo156ejewletA44Ai1qqh9qBcuRkaa+MxUU=; b=pbg0qyubG56GBOvf4eXoFElpzs/lpukvTB5TXrqNiS2vgp94Bbv4dQ5xwa59DyW63W mSZGOHkBKeK775PYBcCkc5DqviEJr3wl0DaflWzWt2HOCrRGuRu9pGbnKa+5cTQ3nRKb mP1Q64H4RmE5bI/dcWn67hJKlqzRi6yPcTtXOis7lBBbzvt6lJAxVmE4FJAlwetO3Mwg AiRNzXvAWYsS1zHyjrUOrPYxpBLSeXO5PfQ279EaET9asI9HiOkma7kAi1z8TQJfcnCF z152lEEKUBwshyQbEtmSEYO0WNqPx6NhB+QA4pFjnwqJNMeTkNzwYYuJhNm5FCTExTLD /rpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=IIfeYu5L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id a2-20020a056a000c8200b006cdf615b690si1885247pfv.149.2023.12.01.01.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 01:41:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@ellerman.id.au header.s=201909 header.b=IIfeYu5L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 91723833AB31; Fri, 1 Dec 2023 01:41:31 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235242AbjLAJlS (ORCPT + 99 others); Fri, 1 Dec 2023 04:41:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjLAJlR (ORCPT ); Fri, 1 Dec 2023 04:41:17 -0500 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70DB710FA; Fri, 1 Dec 2023 01:41:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ellerman.id.au; s=201909; t=1701423678; bh=SCXwSfrAxD/vcI+luNSFDB5IfnqNmy8gsBQXv6JPB3w=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=IIfeYu5L/5RzK2f/xIVe9akYSPr9OUtIDCqF0ZSWukqAoxSbGvI47Q/IMUaFCc5NX eR0adi7iztkf7mgm/uta3inz5/CWd/gu+euafba3GosMPRgAuIf+MHDBOWn574T1m6 PjCMFpmeKFP4y0D2qWqpIjaaAdVksQf4SK2EngcfmtagQ472NxbKD9ofpGm7ssHsXN 4pDDGQsscGpo0FjRxRFNGMAu5QKkFlmzJfpiaREE4EP7sP+tKswZAMF7WsFSdcefnw dFCIRPMk7U2ojLzveYhueAfmIcBFapD5wEBdvAzBe7rqBptKMbPNXcD/enUkqJ/sRr tkny6rYrj9JMA== Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mail.ozlabs.org (Postfix) with ESMTPSA id 4ShSk61ydCz4xVP; Fri, 1 Dec 2023 20:41:18 +1100 (AEDT) From: Michael Ellerman To: Justin Stitt , Tyrel Datwyler , Nicholas Piggin , Christophe Leroy , "James E.J. Bottomley" , "Martin K. Petersen" Cc: linux-scsi@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Subject: Re: [PATCH] scsi: ibmvscsi: replace deprecated strncpy with strscpy In-Reply-To: <20231030-strncpy-drivers-scsi-ibmvscsi-ibmvscsi-c-v1-1-f8b06ae9e3d5@google.com> References: <20231030-strncpy-drivers-scsi-ibmvscsi-ibmvscsi-c-v1-1-f8b06ae9e3d5@google.com> Date: Fri, 01 Dec 2023 20:41:10 +1100 Message-ID: <87jzpy1cqx.fsf@mail.lhotse> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email 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 (morse.vger.email [0.0.0.0]); Fri, 01 Dec 2023 01:41:31 -0800 (PST) Justin Stitt writes: > 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 partition_name to be NUL-terminated based on its usage with > format strings: > | dev_info(hostdata->dev, "host srp version: %s, " > | "host partition %s (%d), OS %d, max io %u\n", > | hostdata->madapter_info.srp_version, > | hostdata->madapter_info.partition_name, > | be32_to_cpu(hostdata->madapter_info.partition_number), > | be32_to_cpu(hostdata->madapter_info.os_type), > | be32_to_cpu(hostdata->madapter_info.port_max_txu[0])); > ... > | len = snprintf(buf, PAGE_SIZE, "%s\n", > | hostdata->madapter_info.partition_name); > > Moreover, NUL-padding is not required as madapter_info is explicitly > memset to 0: > | memset(&hostdata->madapter_info, 0x00, > | sizeof(hostdata->madapter_info)); > > 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. > > 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. I gave it a quick boot, no issues. Tested-by: Michael Ellerman (powerpc) cheers