[PATCH 15/28] orangefs: Use seq_buf for debug help string generation
From: Bill Wendling
Date: Tue Sep 15 2026 - 05:00:39 EST
orangefs_prepare_debugfs_help_string() constructs the debugfs help text in
a dynamically allocated buffer using repeated strlcat() calls across
keyword loops, rescanning the buffer on every append.
In preparation for removing the deprecated strlcat() API[1], use struct
seq_buf to build the help string. This tracks the write position across
the loops, allows formatting each keyword line with a single
seq_buf_printf() call, and checks for truncation via
seq_buf_has_overflowed().
Additionally, replace the final strlcat() call that copies the completed
string into debug_help_string with strscpy().
Link: https://github.com/KSPP/linux/issues/370 [1]
Cc: codemender-patching+linux@xxxxxxxxxx
Assisted-by: Gemini:gemini-2.0-flash-exp [shell_command_run, editor_update_file]
Signed-off-by: Bill Wendling <morbo@xxxxxxxxxx>
---
Cc: Russell King <linux@xxxxxxxxxxxxxxx>
Cc: Huacai Chen <chenhuacai@xxxxxxxxxx>
Cc: WANG Xuerui <kernel@xxxxxxxxxx>
Cc: Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>
Cc: "James E.J. Bottomley" <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx>
Cc: Helge Deller <deller@xxxxxx>
Cc: Thomas Gleixner <tglx@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxxxx>
Cc: Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>
Cc: x86@xxxxxxxxxx
Cc: "H. Peter Anvin" <hpa@xxxxxxxxx>
Cc: Ian Abbott <abbotti@xxxxxxxxx>
Cc: H Hartley Sweeten <hsweeten@xxxxxxxxxxxxxxxxxxx>
Cc: Tony Luck <tony.luck@xxxxxxxxx>
Cc: Maarten Lankhorst <maarten.lankhorst@xxxxxxxxxxxxxxx>
Cc: Maxime Ripard <mripard@xxxxxxxxxx>
Cc: Thomas Zimmermann <tzimmermann@xxxxxxx>
Cc: David Airlie <airlied@xxxxxxxxx>
Cc: Simona Vetter <simona@xxxxxxxx>
Cc: Matthew Brost <matthew.brost@xxxxxxxxx>
Cc: "Thomas Hellström" <thomas.hellstrom@xxxxxxxxxxxxxxx>
Cc: Rodrigo Vivi <rodrigo.vivi@xxxxxxxxx>
Cc: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
Cc: Matthias Schwarzott <zzam@xxxxxxxxxx>
Cc: Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>
Cc: Tony Nguyen <anthony.l.nguyen@xxxxxxxxx>
Cc: Przemek Kitszel <przemyslaw.kitszel@xxxxxxxxx>
Cc: Andrew Lunn <andrew+netdev@xxxxxxx>
Cc: "David S. Miller" <davem@xxxxxxxxxxxxx>
Cc: Eric Dumazet <edumazet@xxxxxxxxxx>
Cc: Jakub Kicinski <kuba@xxxxxxxxxx>
Cc: Paolo Abeni <pabeni@xxxxxxxxxx>
Cc: Arend van Spriel <arend.vanspriel@xxxxxxxxxxxx>
Cc: Rob Herring <robh@xxxxxxxxxx>
Cc: Saravana Kannan <saravanak@xxxxxxxxxx>
Cc: Krzysztof Kozlowski <krzk@xxxxxxxxxx>
Cc: Sylwester Nawrocki <s.nawrocki@xxxxxxxxxxx>
Cc: Peter Griffin <peter.griffin@xxxxxxxxxx>
Cc: Alim Akhtar <alim.akhtar@xxxxxxxxxxx>
Cc: Linus Walleij <linusw@xxxxxxxxxx>
Cc: Anil Gurumurthy <anil.gurumurthy@xxxxxxxxxx>
Cc: Sudarsana Kalluru <sudarsana.kalluru@xxxxxxxxxx>
Cc: "Martin K. Petersen" <mkp@xxxxxxxxxx>
Cc: Trond Myklebust <trondmy@xxxxxxxxxx>
Cc: Anna Schumaker <anna@xxxxxxxxxx>
Cc: Mike Marshall <hubcap@xxxxxxxxxxxx>
Cc: Martin Brandenburg <martin@xxxxxxxxxxxx>
Cc: Kees Cook <kees@xxxxxxxxxx>
Cc: Jiri Pirko <jiri@xxxxxxxxxxx>
Cc: Simon Horman <horms@xxxxxxxxxx>
Cc: Chuck Lever <cel@xxxxxxxxxx>
Cc: Jeff Layton <jlayton@xxxxxxxxxx>
Cc: NeilBrown <neil@xxxxxxxxxx>
Cc: Olga Kornievskaia <okorniev@xxxxxxxxxx>
Cc: Dai Ngo <Dai.Ngo@xxxxxxxxxx>
Cc: Tom Talpey <tom@xxxxxxxxxx>
Cc: Jaroslav Kysela <perex@xxxxxxxx>
Cc: Takashi Iwai <tiwai@xxxxxxxx>
Cc: Bill Wendling <morbo@xxxxxxxxxx>
Cc: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: "Mike Rapoport (Microsoft)" <rppt@xxxxxxxxxx>
Cc: Kanglong Wang <wangkanglong@xxxxxxxxxxx>
Cc: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
Cc: Qiang Ma <maqianga@xxxxxxxxxxxxx>
Cc: Randy Dunlap <rdunlap@xxxxxxxxxxxxx>
Cc: Pengpeng Hou <pengpeng@xxxxxxxxxxx>
Cc: Ard Biesheuvel <ardb@xxxxxxxxxx>
Cc: Breno Leitao <leitao@xxxxxxxxxx>
Cc: Thorsten Blum <blum@xxxxxxxxxx>
Cc: Harshit Mogalapalli <harshit.m.mogalapalli@xxxxxxxxxx>
Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Cc: Lyude Paul <lyude@xxxxxxxxxx>
Cc: Ashutosh Desai <ashutoshdesai993@xxxxxxxxx>
Cc: Imre Deak <imre.deak@xxxxxxxxx>
Cc: Dmitry Baryshkov <dmitry.baryshkov@xxxxxxxxxxxxxxxx>
Cc: Johan Hovold <johan@xxxxxxxxxx>
Cc: Johannes Berg <johannes.berg@xxxxxxxxx>
Cc: Miri Korenblit <miriam.rachel.korenblit@xxxxxxxxx>
Cc: Alexander Stein <alexander.stein@xxxxxxxxxxxxxxx>
Cc: Cryolitia PukNgae <cryolitia@xxxxxxxxxxxxx>
Cc: Jiaming Zhang <r772577952@xxxxxxxxx>
Cc: Will Porter <mrwillporter@xxxxxxxxx>
Cc: Cen Zhang <zzzccc427@xxxxxxxxx>
Cc: "Cássio Gabriel" <cassiogabrielcontato@xxxxxxxxx>
Cc: Rong Zhang <i@xxxxxxxx>
Cc: Arun Raghavan <arunr@xxxxxxxxxxxxxxxxx>
Cc: linux-arm-kernel@xxxxxxxxxxxxxxxxxxx
Cc: linux-kernel@xxxxxxxxxxxxxxx
Cc: loongarch@xxxxxxxxxxxxxxx
Cc: linux-mips@xxxxxxxxxxxxxxx
Cc: linux-parisc@xxxxxxxxxxxxxxx
Cc: linux-edac@xxxxxxxxxxxxxxx
Cc: dri-devel@xxxxxxxxxxxxxxxxxxxxx
Cc: intel-xe@xxxxxxxxxxxxxxxxxxxxx
Cc: linux-input@xxxxxxxxxxxxxxx
Cc: linux-media@xxxxxxxxxxxxxxx
Cc: intel-wired-lan@xxxxxxxxxxxxxxxx
Cc: netdev@xxxxxxxxxxxxxxx
Cc: linux-wireless@xxxxxxxxxxxxxxx
Cc: brcm80211@xxxxxxxxxxxxxxx
Cc: brcm80211-dev-list.pdl@xxxxxxxxxxxx
Cc: devicetree@xxxxxxxxxxxxxxx
Cc: linux-samsung-soc@xxxxxxxxxxxxxxx
Cc: linux-gpio@xxxxxxxxxxxxxxx
Cc: linux-scsi@xxxxxxxxxxxxxxx
Cc: linux-nfs@xxxxxxxxxxxxxxx
Cc: devel@xxxxxxxxxxxxxxxxxx
Cc: linux-hardening@xxxxxxxxxxxxxxx
Cc: linux-sound@xxxxxxxxxxxxxxx
---
fs/orangefs/orangefs-debugfs.c | 36 +++++++++++++---------------------
1 file changed, 14 insertions(+), 22 deletions(-)
diff --git a/fs/orangefs/orangefs-debugfs.c b/fs/orangefs/orangefs-debugfs.c
index 9f94919a6bc6..6e2f9887eab4 100644
--- a/fs/orangefs/orangefs-debugfs.c
+++ b/fs/orangefs/orangefs-debugfs.c
@@ -37,6 +37,7 @@
*/
#include <linux/debugfs.h>
#include <linux/slab.h>
+#include <linux/seq_buf.h>
#include <linux/uaccess.h>
@@ -623,10 +624,10 @@ int orangefs_prepare_debugfs_help_string(int at_boot)
char *client_title = "Client Debug Keywords:\n";
char *kernel_title = "Kernel Debug Keywords:\n";
size_t string_size = DEBUG_HELP_STRING_SIZE;
- size_t result_size;
size_t i;
char *new;
int rc = -EINVAL;
+ struct seq_buf s;
gossip_debug(GOSSIP_UTILS_DEBUG, "%s: start\n", __func__);
@@ -640,17 +641,14 @@ int orangefs_prepare_debugfs_help_string(int at_boot)
goto out;
}
+ seq_buf_init(&s, new, string_size);
+
/*
- * strlcat(dst, src, size) will append at most
- * "size - strlen(dst) - 1" bytes of src onto dst,
- * null terminating the result, and return the total
- * length of the string it tried to create.
- *
* We'll just plow through here building our new debug
- * help string and let strlcat take care of assuring that
+ * help string and let seq_buf take care of assuring that
* dst doesn't overflow.
*/
- strlcat(new, client_title, string_size);
+ seq_buf_puts(&s, client_title);
if (!at_boot) {
@@ -665,24 +663,18 @@ int orangefs_prepare_debugfs_help_string(int at_boot)
goto out;
}
- for (i = 0; i < cdm_element_count; i++) {
- strlcat(new, "\t", string_size);
- strlcat(new, cdm_array[i].keyword, string_size);
- strlcat(new, "\n", string_size);
- }
+ for (i = 0; i < cdm_element_count; i++)
+ seq_buf_printf(&s, "\t%s\n", cdm_array[i].keyword);
}
- strlcat(new, "\n", string_size);
- strlcat(new, kernel_title, string_size);
+ seq_buf_puts(&s, "\n");
+ seq_buf_puts(&s, kernel_title);
- for (i = 0; i < num_kmod_keyword_mask_map; i++) {
- strlcat(new, "\t", string_size);
- strlcat(new, s_kmod_keyword_mask_map[i].keyword, string_size);
- result_size = strlcat(new, "\n", string_size);
- }
+ for (i = 0; i < num_kmod_keyword_mask_map; i++)
+ seq_buf_printf(&s, "\t%s\n", s_kmod_keyword_mask_map[i].keyword);
/* See if we tried to put too many bytes into "new"... */
- if (result_size >= string_size) {
+ if (seq_buf_has_overflowed(&s)) {
kfree(new);
goto out;
}
@@ -692,7 +684,7 @@ int orangefs_prepare_debugfs_help_string(int at_boot)
} else {
mutex_lock(&orangefs_help_file_lock);
memset(debug_help_string, 0, DEBUG_HELP_STRING_SIZE);
- strlcat(debug_help_string, new, string_size);
+ strscpy(debug_help_string, new, DEBUG_HELP_STRING_SIZE);
mutex_unlock(&orangefs_help_file_lock);
kfree(new);
}
--
2.55.0.1032.g73a4cd73de-goog