From patchwork Tue Apr 9 14:00:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 787548 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 966F3130ACF; Tue, 9 Apr 2024 14:01:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671273; cv=none; b=WQMtXTcj+B2/YUzi7QVbZO7nwoFQxSCNp/+KheKDscYkYNUYV6ezUtsDpSmK5KLAhu+ulz0hkUET1LTANZ/tPiZYby28r2rBuobnb44FfMwPPM0t1oXlYcMv5iceU9F0amtxm8LIFMP6gbWuV6w1kzO6kJihkQqYext/lzaKwKE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671273; c=relaxed/simple; bh=51Sfm2xp0PQT1gFODKUdeFbVWX58fUeGaMiFqFdRF90=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=G2XYJ2neX2oRO4Q2KyfznSQOrnoK5Fc5SlJabwKeD4pVdAV+TObloGw9D+W0S2PAO7aUPF4FlfyqF7rn9kPFeF986M5YJsA0O2YQaysJU45sjuv75oM1dcCmIUR0XY18RCcYiJh/8LFVrMA1S+HwWqLS53POBCQlh5qZmy+IrPU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f+sLbW0I; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f+sLbW0I" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D60BFC433B1; Tue, 9 Apr 2024 14:01:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712671273; bh=51Sfm2xp0PQT1gFODKUdeFbVWX58fUeGaMiFqFdRF90=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=f+sLbW0ImOrvVzf5VOnMgtlmcW5JlPVUKLm+TksiUIm87QHwts5XhrwCkeu0+a775 kucx+qagico8Y7FiqyDwpWV7aJYhNg/sBc4ij6yZwCml8OLedkqHfMy990NutRYSLo o2Q69k0HsodpvGjQC9oZW1jLG9QOQjoI8T30/2Tb3qIYnJoc1GfbYdKoVRbVrBsZ4S 7WCJGAMull3hGNt4lnfSrrA7+hz7p/FD8CRkT1Jz1k/HspEJOLrVwINHLlCQsYcUlp FiuuTQvX6PhA0pez7lzCebwbKsCQtj64D/VfLCV3Zq4Bx3KiNzr0BxVWhbtvcI4E/P SBVvxTGXuNKkQ== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , "Richard Russon" , Jens Axboe , Robert Moore , "Rafael J. Wysocki" , Len Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Lin Ming , Alexey Starikovskiy , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-trace-kernel@vger.kernel.org, Justin Stitt Subject: [PATCH 1/5] [v2] test_hexdump: avoid string truncation warning Date: Tue, 9 Apr 2024 16:00:54 +0200 Message-Id: <20240409140059.3806717-2-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409140059.3806717-1-arnd@kernel.org> References: <20240409140059.3806717-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann gcc can warn when a string is too long to fit into the strncpy() destination buffer, as it is here depending on the function arguments: inlined from 'test_hexdump_prepare_test.constprop' at /home/arnd/arm-soc/lib/test_hexdump.c:116:3: include/linux/fortify-string.h:108:33: error: '__builtin_strncpy' output truncated copying between 0 and 32 bytes from a string of length 32 [-Werror=stringop-truncation] 108 | #define __underlying_strncpy __builtin_strncpy | ^ include/linux/fortify-string.h:187:16: note: in expansion of macro '__underlying_strncpy' 187 | return __underlying_strncpy(p, q, size); | ^~~~~~~~~~~~~~~~~~~~ The intention here is to copy exactly 'l' bytes without any padding or NUL-termination, so the most logical change is to use memcpy(), just as a previous change adapted the other output from strncpy() to memcpy(). Cc: Justin Stitt Signed-off-by: Arnd Bergmann Acked-by: Justin Stitt --- --- lib/test_hexdump.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test_hexdump.c b/lib/test_hexdump.c index b916801f23a8..fe2682bb21e6 100644 --- a/lib/test_hexdump.c +++ b/lib/test_hexdump.c @@ -113,7 +113,7 @@ static void __init test_hexdump_prepare_test(size_t len, int rowsize, *p++ = ' '; } while (p < test + rs * 2 + rs / gs + 1); - strncpy(p, data_a, l); + memcpy(p, data_a, l); p += l; } From patchwork Tue Apr 9 14:00:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 787259 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AFB061311B9; Tue, 9 Apr 2024 14:01:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671278; cv=none; b=Vmv8bmuu7pOlNIa+PJck2V6glqOf7ucQ77BewfMtr+umtBuU5O+D1q9F57HgcJ0WdLZqa5P/0egdYdnboK2xC+vuORBFgiYcS2fNVJHH5H2ZyTD+xE9kTvJ2IscmzBx9HIJsJHD+s31A/8DZ6yimTiRhMK0lbHrXt6EUixdMppY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671278; c=relaxed/simple; bh=apx3gbxkYNqe3VpAmpZgPTdGN3/2cOQjfTIRYJyoYL8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ZrLuoZAmzLwDtERMC71+W/24VHTwqAPWZJJUqR6HeAjfOQx5Pwe1XFwakes2cd0aJ2aB1d692yV5NGp1OV2y9M72TVMLlPvpuSdSOHkN3dXC0yV5MLaFrHo7H7IxBJCQgyVr2rt2yi0ZX7NGVoPqOaexs3iFur1QyWnyYwg6fEs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MSSa5z1S; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="MSSa5z1S" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DD480C43142; Tue, 9 Apr 2024 14:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712671278; bh=apx3gbxkYNqe3VpAmpZgPTdGN3/2cOQjfTIRYJyoYL8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MSSa5z1S9ryJwrH6rhZwsfZ+WYHqk+DUN6umSYaSz9+PInQkEmLLg9HxlScb7SB66 INAABa+8rjj1c4bradO8L6DkDBPNDU7qPWK7URSSmUPTxK+4hefFZn2CZXuFgBrngb QdlQN775GdzBYwFXCsuI8v5PtJCTjL+tCs3wkzvRFaW5ly10uQ3/gpx0iQk6QTCQNL x3PysVOlaDEUIoyLnkd+Jm0Vi30mdh9slrYCeOOucTVTqixQKDXisg4oPy8r6K1xlD BcBWJB4mfLTtXNA4AAKEknHbTNgkfQrMFIZi1WJwSfYfbs/hZovigEojcExc6eLrtw S96r3fjZf4spg== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , "Richard Russon" , Jens Axboe , Robert Moore , "Rafael J. Wysocki" , Len Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Lin Ming , Alexey Starikovskiy , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-trace-kernel@vger.kernel.org Subject: [PATCH 2/5] [v2] acpi: disable -Wstringop-truncation Date: Tue, 9 Apr 2024 16:00:55 +0200 Message-Id: <20240409140059.3806717-3-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409140059.3806717-1-arnd@kernel.org> References: <20240409140059.3806717-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann gcc -Wstringop-truncation warns about copying a string that results in a missing nul termination: drivers/acpi/acpica/tbfind.c: In function 'acpi_tb_find_table': drivers/acpi/acpica/tbfind.c:60:9: error: 'strncpy' specified bound 6 equals destination size [-Werror=stringop-truncation] 60 | strncpy(header.oem_id, oem_id, ACPI_OEM_ID_SIZE); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ drivers/acpi/acpica/tbfind.c:61:9: error: 'strncpy' specified bound 8 equals destination size [-Werror=stringop-truncation] 61 | strncpy(header.oem_table_id, oem_table_id, ACPI_OEM_TABLE_ID_SIZE); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The code works as intended, and the warning could be addressed by using a memcpy(), but turning the warning off for this file works equally well and may be easir to merge. Fixes: 47c08729bf1c ("ACPICA: Fix for LoadTable operator, input strings") Link: https://lore.kernel.org/lkml/CAJZ5v0hoUfv54KW7y4223Mn9E7D4xvR7whRFNLTBqCZMUxT50Q@mail.gmail.com/#t Signed-off-by: Arnd Bergmann --- drivers/acpi/acpica/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/acpi/acpica/Makefile b/drivers/acpi/acpica/Makefile index 30f3fc13c29d..8d18af396de9 100644 --- a/drivers/acpi/acpica/Makefile +++ b/drivers/acpi/acpica/Makefile @@ -5,6 +5,7 @@ ccflags-y := -D_LINUX -DBUILDING_ACPICA ccflags-$(CONFIG_ACPI_DEBUG) += -DACPI_DEBUG_OUTPUT +CFLAGS_tbfind.o += $(call cc-disable-warning, stringop-truncation) # use acpi.o to put all files here into acpi.o modparam namespace obj-y += acpi.o From patchwork Tue Apr 9 14:00:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 787547 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF3D41311B9; Tue, 9 Apr 2024 14:01:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671283; cv=none; b=UCM1Vd5/tKR/jkD3QxamFkrGDgf9RRQyk17NWint7ykWeBCCwRr0IZ4rfvsHOyVM8X+pAxZQuaydphuD9W27xY3z0XbQl9H3j2GLF32d7oOunOvIKw1nA2xgxzSTlAaytTqNTYRxMJ9KnYCWKsGrHoCxZzP0tMgRSP0Fpaeax3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671283; c=relaxed/simple; bh=+6XHH0IKbKZJZfLuR8UiLY5DybHOF/uJqvg3k5VIrYY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Rd+fBWDsoEzUeYIgDJlqM1CRLCiazXSa6efWCLSO5Jofx0eR22avpH2ekLvuehnLfNiKziu02BL6lYqmAuvYnImN2nlV9aZvVAAyRiapLVn9iSSfowWAH3/82Y1bwZrergV1P9yV09SqAozTSswS7mmfUCp4SEd6SE0tKrxon9M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=seYFDBBN; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="seYFDBBN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB531C43601; Tue, 9 Apr 2024 14:01:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712671283; bh=+6XHH0IKbKZJZfLuR8UiLY5DybHOF/uJqvg3k5VIrYY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=seYFDBBNQDwm3rbyua/v8J3aR2fdaXaheTfVVTdXR7eE7sMrmz3miSMjwS+ALRTjO 3keDS7/WA23UgDKScxs2qbPxAnxQq5cKW2mqPPIzRmx4q+oajuSJYMhsI8NPbxIyDe r8JSc6Wgt3n9s+H0fYI8xAqv0qbNj5HjUi/CceuFaOYrBzwSHYdlvQtFE7HpZT7Icf Jg9mP/RwmYcvzfeiTgsNl/sQ7NDJHRRJBuPTy7r8unNf7A3LnopNDxu/rlBnjOOKP+ U7BAgVieDFa+2RczYDaBt0X77ALDKlU+jKCIDGhyluyaj9mTJOimEu/sG7GQGhji7S y15jJwN/Osm5Q== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , "Richard Russon" , Jens Axboe , Robert Moore , "Rafael J. Wysocki" , Len Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Lin Ming , Alexey Starikovskiy , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-trace-kernel@vger.kernel.org, Justin Stitt Subject: [PATCH 3/5] [v2] block/partitions/ldm: convert strncpy() to strscpy() Date: Tue, 9 Apr 2024 16:00:56 +0200 Message-Id: <20240409140059.3806717-4-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409140059.3806717-1-arnd@kernel.org> References: <20240409140059.3806717-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann The strncpy() here can cause a non-terminated string, which older gcc versions such as gcc-9 warn about: In function 'ldm_parse_tocblock', inlined from 'ldm_validate_tocblocks' at block/partitions/ldm.c:386:7, inlined from 'ldm_partition' at block/partitions/ldm.c:1457:7: block/partitions/ldm.c:134:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] 134 | strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ block/partitions/ldm.c:145:2: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation] 145 | strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ New versions notice that the code is correct after all because of the following termination, but replacing the strncpy() with strscpy_pad() or strcpy() avoids the warning and simplifies the code at the same time. Use the padding version here to keep the existing behavior, in case the code relies on not including uninitialized data. Reviewed-by: Justin Stitt Signed-off-by: Arnd Bergmann --- block/partitions/ldm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/partitions/ldm.c b/block/partitions/ldm.c index 38e58960ae03..2bd42fedb907 100644 --- a/block/partitions/ldm.c +++ b/block/partitions/ldm.c @@ -131,8 +131,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc) ldm_crit ("Cannot find TOCBLOCK, database may be corrupt."); return false; } - strncpy (toc->bitmap1_name, data + 0x24, sizeof (toc->bitmap1_name)); - toc->bitmap1_name[sizeof (toc->bitmap1_name) - 1] = 0; + strscpy_pad(toc->bitmap1_name, data + 0x24, sizeof(toc->bitmap1_name)); toc->bitmap1_start = get_unaligned_be64(data + 0x2E); toc->bitmap1_size = get_unaligned_be64(data + 0x36); @@ -142,8 +141,7 @@ static bool ldm_parse_tocblock (const u8 *data, struct tocblock *toc) TOC_BITMAP1, toc->bitmap1_name); return false; } - strncpy (toc->bitmap2_name, data + 0x46, sizeof (toc->bitmap2_name)); - toc->bitmap2_name[sizeof (toc->bitmap2_name) - 1] = 0; + strscpy_pad(toc->bitmap2_name, data + 0x46, sizeof(toc->bitmap2_name)); toc->bitmap2_start = get_unaligned_be64(data + 0x50); toc->bitmap2_size = get_unaligned_be64(data + 0x58); if (strncmp (toc->bitmap2_name, TOC_BITMAP2, From patchwork Tue Apr 9 14:00:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 787258 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E6551311B9; Tue, 9 Apr 2024 14:01:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671288; cv=none; b=pvQFcG8Bf6egaWtiHSbYfIaOtEiE74K54QyPfN+SY1ToQ3ZY0aKLnOFBrJfiXdMJBauFjO0xQSxjOSGFp/Q+vcWAZou9rdppscriwelBFT8IweUJ8Nth8ykaL6h4eTFAptAtQVntsrsXFuax6zFt7l1vtqxSfq96hnulINbyo78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671288; c=relaxed/simple; bh=pzK3De1dss+tVtAMUbtIdEjmw37wYh3hyKahO2Wukx4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K8Ya5jHkE2TEDUcs4dF2eOgVrp1d/e+4IQxQaeT234MgMEJU+6zRGRH8bXKQhoB/v+hs4WYA5GmyDIntR75lF4gZMBa80bl6QyqSe//YxXWIAHQuk2HKTXICcoibRpu4Ce7ty81o19THA+oSZmp1oKF65GSKaDAdUX78gdc+8mY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kROJxz2H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kROJxz2H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7EB6C433C7; Tue, 9 Apr 2024 14:01:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712671288; bh=pzK3De1dss+tVtAMUbtIdEjmw37wYh3hyKahO2Wukx4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kROJxz2HYgYmtGzuLOF1DPUe3tsYi9DEJ86893KsN4RG8ZJ2ez8cLLlpXAt1q+/Kl qsw9cy559op7Gxv7hDeh2gK/p4ba26iuHzPTC7VRjy8fdJqsEeWuiV5tQ46ZllP7S9 ZbUqQqTcngs3Ytvsbwu6cLLEvXW7Nxt/JPx3GQl+ZFB1AvwyGc2YMLAo/hvg8tvBen 9+cEIqTiHYc4GkmUn3bcMfpPwm+rwip2PT02QzrvVG9nPIOB5mO9PSmbiNRWl9VXLs FleNYGV2Q6GW30vC1shIToVxt1l6zXaHmiQ47V5iFp8JJYeekoGWzq1qZ5bqNjGgJK yhlh3nw+JpfcQ== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , "Richard Russon" , Jens Axboe , Robert Moore , "Rafael J. Wysocki" , Len Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Lin Ming , Alexey Starikovskiy , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-trace-kernel@vger.kernel.org Subject: [PATCH 4/5] [v2] blktrace: convert strncpy() to strscpy_pad() Date: Tue, 9 Apr 2024 16:00:57 +0200 Message-Id: <20240409140059.3806717-5-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409140059.3806717-1-arnd@kernel.org> References: <20240409140059.3806717-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann gcc-9 warns about a possibly non-terminated string copy: kernel/trace/blktrace.c: In function 'do_blk_trace_setup': kernel/trace/blktrace.c:527:2: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] Newer versions are fine here because they see the following explicit nul-termination. Using strscpy_pad() avoids the warning and simplifies the code a little. The padding helps give a clean buffer to userspace. Signed-off-by: Arnd Bergmann Acked-by: Justin Stitt --- v2: actually use padding version of strscpy. --- kernel/trace/blktrace.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c index d5d94510afd3..8fd292d34d89 100644 --- a/kernel/trace/blktrace.c +++ b/kernel/trace/blktrace.c @@ -524,8 +524,7 @@ static int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev, if (!buts->buf_size || !buts->buf_nr) return -EINVAL; - strncpy(buts->name, name, BLKTRACE_BDEV_SIZE); - buts->name[BLKTRACE_BDEV_SIZE - 1] = '\0'; + strscpy_pad(buts->name, name, BLKTRACE_BDEV_SIZE); /* * some device names have larger paths - convert the slashes From patchwork Tue Apr 9 14:00:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 787546 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 950DD12FF72; Tue, 9 Apr 2024 14:01:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671293; cv=none; b=qAfGlXafydH+9QFUKmeB6V/VJ2E9YJnOxjbuEqeyM6LZtgJcM7OhpDeaq+1Fpr4C67+mbefUA3KSkobN0Xx4flVl1ypGwkUTrykKismsrLCo9IFMLeGj4G7GHGHftGdx8Z1skysr2OZZ/SXJDLGhb3cLggibIYnN/TCYmPIejR4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712671293; c=relaxed/simple; bh=KBapuCoet5kfjziaVWML59WbPosua5uheV6EN7HL7cc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m/G94JFVwccTPueFjzUZp8PSydKD5IGEKTnAC1OIDaIqqYIPW5JQXWt5EXFX/i+SI9fixpv9VMuoKMZnXnmfIyFafDfwvBjEpTR8A/j/NndDQ53fMM87KLB/h8vpsasSqEDYVpGGBlWfaqmUA5nKKKvEN0tGfSx8JDydRXvbNJQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CI+tE9nq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CI+tE9nq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A5330C43390; Tue, 9 Apr 2024 14:01:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712671293; bh=KBapuCoet5kfjziaVWML59WbPosua5uheV6EN7HL7cc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CI+tE9nqa8mKqJOIqe+CfUonGLG1fsbzMR/Wd7a5I1Vi2laBO5bxr2CoMJV9PXJmW l3B5LTh7o9wALv4UUWeYM/t6wiBxQSugqqL1qMaxru2tX3syz5zQ1dsosUQsa29l8T p7IjRvBsv+ejS31ytc4jFbGqhglSJWpDfeCARtT2DuJQwR0l7vlr6MAVUGv1hn/+RL LYOEYFvgKimhfwTM29K1/o3+OR9G+feE3zRGY+tAuvl6i500jl0QwnR+iS9P/aFQXM zLfT5yP+z3QnvGF/tWNTahJ46H894mg0QFW7RX22FGXq0UqZrFoQ1e9EbWlVu3+fcI vfZrusQ178Ykg== From: Arnd Bergmann To: linux-kbuild@vger.kernel.org Cc: Arnd Bergmann , "Richard Russon" , Jens Axboe , Robert Moore , "Rafael J. Wysocki" , Len Brown , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Andrew Morton , Masahiro Yamada , Nathan Chancellor , Nicolas Schier , Lin Ming , Alexey Starikovskiy , linux-ntfs-dev@lists.sourceforge.net, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, acpica-devel@lists.linux.dev, linux-trace-kernel@vger.kernel.org Subject: [PATCH 5/5] [v2] kbuild: enable -Wstringop-truncation globally Date: Tue, 9 Apr 2024 16:00:58 +0200 Message-Id: <20240409140059.3806717-6-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240409140059.3806717-1-arnd@kernel.org> References: <20240409140059.3806717-1-arnd@kernel.org> Precedence: bulk X-Mailing-List: linux-acpi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Arnd Bergmann The remaining warnings of this type have been addressed, so it can now be enabled by default, rather than only for W=1. Signed-off-by: Arnd Bergmann --- v2: no changes --- scripts/Makefile.extrawarn | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/Makefile.extrawarn b/scripts/Makefile.extrawarn index 57edc80661fd..f4d69092698b 100644 --- a/scripts/Makefile.extrawarn +++ b/scripts/Makefile.extrawarn @@ -107,7 +107,6 @@ else KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow-non-kprintf) KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation-non-kprintf) endif -KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation) KBUILD_CFLAGS += -Wno-override-init # alias for -Wno-initializer-overrides in clang