2023-10-26 22:03:40

by Justin Stitt

[permalink] [raw]
Subject: Re: [RFC][PATCH] wifi: wil6210: Replace strlcat() usage with seq_buf

On Thu, Oct 26, 2023 at 10:13 AM Kees Cook <[email protected]> wrote:
>
> The use of strlcat() is fragile at best, and we'd like to remove it from
> the available string APIs in the kernel. Instead, use the safer seq_buf
> APIs.
>
> Cc: Kalle Valo <[email protected]>
> Cc: Johannes Berg <[email protected]>
> Cc: Max Chen <[email protected]>
> Cc: Yang Shen <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: "Matthew Wilcox (Oracle)" <[email protected]>
> Cc: Christoph Hellwig <[email protected]>
> Cc: Justin Stitt <[email protected]>
> Cc: Kent Overstreet <[email protected]>
> Cc: Petr Mladek <[email protected]>
> Cc: Andy Shevchenko <[email protected]>
> Cc: Rasmus Villemoes <[email protected]>
> Cc: Sergey Senozhatsky <[email protected]>
> Cc: Masami Hiramatsu <[email protected]>
> Cc: Greg Kroah-Hartman <[email protected]>
> Cc: Arnd Bergmann <[email protected]>
> Cc: Jonathan Corbet <[email protected]>
> Cc: Yun Zhou <[email protected]>
> Cc: Jacob Keller <[email protected]>
> Cc: Zhen Lei <[email protected]>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Kees Cook <[email protected]>
> ---
> This is mainly an example of where/how to use the ongoing seq_buf
> refactoring happening in the tracing tree:
> https://lore.kernel.org/lkml/[email protected]/

I like it. C-strings and many of their associated apis are dodgy. This
looks like a worthwhile replacement.

I think many of my strncpy -> strscpy replacements could've easily
been something along these lines as well.

Happy to see robustness increasing in the kernel by means
of replacing sketchy C-string stuff.

> ---
> drivers/net/wireless/ath/wil6210/wmi.c | 23 ++++++++++-------------
> 1 file changed, 10 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/wireless/ath/wil6210/wmi.c b/drivers/net/wireless/ath/wil6210/wmi.c
> index 6fdb77d4c59e..45b8c651b8e2 100644
> --- a/drivers/net/wireless/ath/wil6210/wmi.c
> +++ b/drivers/net/wireless/ath/wil6210/wmi.c
> @@ -3159,36 +3159,34 @@ int wmi_suspend(struct wil6210_priv *wil)
> return rc;
> }
>
> -static void resume_triggers2string(u32 triggers, char *string, int str_size)
> +static void resume_triggers2string(u32 triggers, struct seq_buf *s)
> {
> - string[0] = '\0';
> -
> if (!triggers) {
> - strlcat(string, " UNKNOWN", str_size);
> + seq_buf_puts(s, " UNKNOWN");
> return;
> }
>
> if (triggers & WMI_RESUME_TRIGGER_HOST)
> - strlcat(string, " HOST", str_size);
> + seq_buf_puts(s, " HOST")
>
> if (triggers & WMI_RESUME_TRIGGER_UCAST_RX)
> - strlcat(string, " UCAST_RX", str_size);
> + seq_buf_puts(s, " UCAST_RX");
>
> if (triggers & WMI_RESUME_TRIGGER_BCAST_RX)
> - strlcat(string, " BCAST_RX", str_size);
> + seq_buf_puts(s, " BCAST_RX");
>
> if (triggers & WMI_RESUME_TRIGGER_WMI_EVT)
> - strlcat(string, " WMI_EVT", str_size);
> + seq_buf_puts(s, " WMI_EVT");
>
> if (triggers & WMI_RESUME_TRIGGER_DISCONNECT)
> - strlcat(string, " DISCONNECT", str_size);
> + seq_buf_puts(s, " DISCONNECT");
> }
>
> int wmi_resume(struct wil6210_priv *wil)
> {
> struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
> int rc;
> - char string[100];
> + DECLARE_SEQ_BUF(s, 100);
> struct {
> struct wmi_cmd_hdr wmi;
> struct wmi_traffic_resume_event evt;
> @@ -3203,10 +3201,9 @@ int wmi_resume(struct wil6210_priv *wil)
> WIL_WAIT_FOR_SUSPEND_RESUME_COMP);
> if (rc)
> return rc;
> - resume_triggers2string(le32_to_cpu(reply.evt.resume_triggers), string,
> - sizeof(string));
> + resume_triggers2string(le32_to_cpu(reply.evt.resume_triggers), s);
> wil_dbg_pm(wil, "device resume %s, resume triggers:%s (0x%x)\n",
> - reply.evt.status ? "failed" : "passed", string,
> + reply.evt.status ? "failed" : "passed", seq_buf_cstr(s),
> le32_to_cpu(reply.evt.resume_triggers));
>
> return reply.evt.status;
> --
> 2.34.1
>

Thanks
Justin