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: 738647 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05BB2C25B67 for ; Thu, 26 Oct 2023 17:14:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231844AbjJZROB (ORCPT ); Thu, 26 Oct 2023 13:14:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345342AbjJZRNz (ORCPT ); Thu, 26 Oct 2023 13:13:55 -0400 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AD08194 for ; Thu, 26 Oct 2023 10:13:52 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6b26a3163acso1090578b3a.2 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=bJGZsm6sbB+ps8XvVdbg12GZ140LOUnEe9Ao+WpgQJbJHB3YW9dv1f1Phxk6GZHCmS WNHI6MDwREls3zeOzR+NMEeneodwSPcv1DLIa4Xr7INerqovMp3aOOqqlmQNYbMfVKj2 N8bfAl/ZO6V80PHw3j1W7praCJ6jURITmS9gQT+df6btRCge9RHDUXSE+nqlEDS1Vl2r 55DZl9X0Xf1XCRSpo4G1reY9qC9zOmT4CF4VVBxlir5W+4fAXD/tFaacTCWqdJM9iBG1 3dHwCwD45ObU4WV6ZLGYfFEa46m/NWczycQedoa6nhbs0FaCq9XbcMHfKzTTVKSuPMk5 Nd3Q== X-Gm-Message-State: AOJu0YzP3gw3/jLIZ3hJ6QnX0bbWBiaUgBSaGbPncn2qIy/+K6/7Gqa8 wPJ3L5JVl0Kc3EJ8MLnqNg24CA== 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 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 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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;