From patchwork Thu Oct 26 17:13:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13437753 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 13E732E413 for ; Thu, 26 Oct 2023 17:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="LPcaEvY2" Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29974116 for ; Thu, 26 Oct 2023 10:13:52 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6b87c1edfd5so1103337b3a.1 for ; Thu, 26 Oct 2023 10:13:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1698340431; x=1698945231; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XaUboxRO1+viinf77RQ7N/zAs2SC9fz2QEeXcJMB0SE=; b=LPcaEvY2WsHosUhm9UNIJRboimWiVIPcEZY6bxci4+s3avWuyS4sveKrffJauIwfKm yQSXSgC85uNhJJLuvGgMSYwBiQnGKL8EVPH9MQotftHT5E0Xv+kTRjlQAJpvpn2ePGrz 6pxcxZtISeNS5i70ru+tglbKD6qdWO3BGMKQQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698340431; x=1698945231; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XaUboxRO1+viinf77RQ7N/zAs2SC9fz2QEeXcJMB0SE=; b=k2GOGlv0I2gihoDI5wg7WuNGInY1jo+mh9VS88XwZ6+RGQAyboOkOGEHzlh5yhrhDN hw9BiD7Awh8QVvV+544NZH/wdD7OZDT0noWJTfsuPUwbAZksy8r6q2yBfZFfy0zEaBj4 yf4UioYzJAbP5xiDs8yIM5bpXLCcMQw4JN0QuPQ+YNkNWsDK0Zn+T4uijptQk7UYIdbE YKubfapI5uxAa/f2akYYmP7zdIBuytRJ0SalAOnf7g/ROJytVBwUfhgXYiYHl0wA7rEg hAlnLYXOd/ZlRcQexRw4/WC87VGtMdxfRVXc8gkmafadQxGaWsykfD5s1BQllk7Nv1s3 /vNw== X-Gm-Message-State: AOJu0YyuLg5Rrkl8XStcoseE0o/QBMToOaCnFt0LXeyJZnkaoB9oCmql 7oho69CklbU1Y53gvwGyP+lbvg== X-Google-Smtp-Source: AGHT+IHyR59Pg2x487W+2yP92vC6UvozxH+Vq9jfsqmXLiUPD1h2P4QuTeIdk8oTKJcNWeUXyLwVqQ== X-Received: by 2002:a05:6a00:3924:b0:6be:43d5:6505 with SMTP id fh36-20020a056a00392400b006be43d56505mr84131pfb.6.1698340431616; Thu, 26 Oct 2023 10:13:51 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id d6-20020aa797a6000000b006b225011ee5sm11474423pfq.6.2023.10.26.10.13.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 10:13:51 -0700 (PDT) From: Kees Cook To: Kalle Valo Cc: Kees Cook , Johannes Berg , Max Chen , Yang Shen , Steven Rostedt , "Matthew Wilcox (Oracle)" , Christoph Hellwig , Justin Stitt , Kent Overstreet , Petr Mladek , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , Masami Hiramatsu , Greg Kroah-Hartman , Arnd Bergmann , Jonathan Corbet , Yun Zhou , Jacob Keller , Zhen Lei , linux-trace-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: [RFC][PATCH] wifi: wil6210: Replace strlcat() usage with seq_buf Date: Thu, 26 Oct 2023 10:13:49 -0700 Message-Id: <20231026171349.work.928-kees@kernel.org> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3544; i=keescook@chromium.org; h=from:subject:message-id; bh=D2vtiEKqUsGt/Z09LYNxtKXhUwmDCO+5281guVaf7GY=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlOp5NR+tMMbDVnVZsfav6ogCPxtfc/WTZ15nO2 QRMEDBKLY6JAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZTqeTQAKCRCJcvTf3G3A JqQzD/9l0E0xuPY6P0roZjkRSULXnrIXkTO42RKEmMgsVde2QhNfDm1jpgQwKYS79HR7MUy81R6 xuvxMMyhXUeRGa0rsA+6TA+heail3hcWvUUQjBz3mmibnTXjOleWcVee0TLju/NW4+Qi/i4VslT ss+3VmN0dnlToJW9TccwpeivyT3Zwx+ZTBbtu4c8nNeNwuexL3DzygCn0ERJpGqTaXv31L44t54 5CluQm2N4kAm97ajzuFbUJJup54tIxrVklY7yRjuagF8gIKfXtUmGuvENXj+wjOdIpwgFOpknt2 Strg8uN5CjXYpgRv8mhM+vDY7JNBAC9PqjbM8agfAHxWkEyDywHuv+RPz3cnTColqfnenVfPYl1 Oxbpvi4SQwK/fOsMTmnfiA/TN5Up9l031ukqov92TTse4SgYhCVO8i4hvWBhXylLBKgfKm/SwFk SbVfcwbNpUwx+ZicySY48xcf1i1EZ0ydWkL137rTlcJjdvV8q7U+gubWcorg7P0UYKb7JISAlhK OhAEcdoTkf8CodYwlFwOSx4/FUI84czwgddorDvN1nUkjSSg6YSzjFjqX+bNedUZYokvgv7/pMu v3B3kUPSVnQ3Czc6EwGf0reFM3YSfnbATzoKYVDYHLfCvxrFfdxbaZWbTmbtNIlVfKz+ocrFry8 ifQRSEE 3hfkIc6w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 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 Cc: Johannes Berg Cc: Max Chen Cc: Yang Shen Cc: Steven Rostedt Cc: "Matthew Wilcox (Oracle)" Cc: Christoph Hellwig Cc: Justin Stitt Cc: Kent Overstreet Cc: Petr Mladek Cc: Andy Shevchenko Cc: Rasmus Villemoes Cc: Sergey Senozhatsky Cc: Masami Hiramatsu Cc: Greg Kroah-Hartman Cc: Arnd Bergmann Cc: Jonathan Corbet Cc: Yun Zhou Cc: Jacob Keller Cc: Zhen Lei Cc: linux-trace-kernel@vger.kernel.org Cc: linux-wireless@vger.kernel.org Signed-off-by: Kees Cook --- 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/20231026170722.work.638-kees@kernel.org/ --- 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;