Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp753547rdh; Thu, 26 Oct 2023 15:03:40 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHyOhDWQM8njVsbh9y4lneRmoxfUgBlWPcLgDzg65DvUfNLHRwRpGc0D+G/yBceonkIhqfK X-Received: by 2002:a17:907:b68a:b0:9ae:50c4:4df9 with SMTP id vm10-20020a170907b68a00b009ae50c44df9mr741142ejc.61.1698357819910; Thu, 26 Oct 2023 15:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698357819; cv=none; d=google.com; s=arc-20160816; b=N0xFxGp+LWwKPT0D43QPH2h04m5UrDz9dCnjfxKvsu/tmLVFFT3CvFolCOrEbo8aRq EUaN7kszz8Z607t1mkO9SrKvoW6+v7wh8FJNJCS9egVAid55zgD0/b/ZUO1dPlqmtp+n nBDRb9NuqtMgHB3QQtCRHlOiDFZc6kjeT0IS4R37QflKKlZkA38aGNhuD8nrTnPcjd3Q HXM8ojvNE9iCUCDOWS6mFDdV0h76oSRzpAU1hWJIdlrRaMwi1vqPlvwNwBIqWBGQ9r2l tf6FmNlN5pPJUJaBHYzN2jquvjMv7nLV+lVpDF/XEEQ8Zoep8Ti/PKQL6/xi/OW8N4Ga vldw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=DEmmsMUNDXrHxbfE3Ce3REr5A6wqcO3bgGi92YBCkzI=; fh=xzPyy3q+aPAXO76Rguf9rNXUiiKy6fDHqvgXVAnaNHQ=; b=ZxXffCRTHwo3zBfpqW8wKhVzW/vCLiBczoLpZBlFDMEiBIze11tVdfiI0svqNmw+UO grktSf6fY7mjnVHyfJGr/uIWpXbwG0u+2cyKFUNgNSv7z/4VVBzPl6b6AEpngOj3UXbI ptZi7MTXioMKR+eYdbw2Yta19kyu3jymRbjsJ/HlFfnW3d13dZvLbgl4Edo0qKeNX4jy qftIaDRJTVsJyN2zilY73l01iN/doLmKZ7NxaqwMp3Oiz8VYYXReS/kdPqEieDVSFhIK HG4dM9BKs4VllJfp8uMxDQ/00P58PvQPNQr0q8j5DK8MDVo/PnuzmH56XaDArQUGTNFW 5VXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=b6py9JZy; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id do6-20020a170906c10600b009c7642a8a3esi150647ejc.293.2023.10.26.15.03.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 15:03:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=b6py9JZy; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id E547981A7D23; Thu, 26 Oct 2023 15:03:30 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344898AbjJZWDa (ORCPT + 52 others); Thu, 26 Oct 2023 18:03:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230186AbjJZWD3 (ORCPT ); Thu, 26 Oct 2023 18:03:29 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 227A81B5 for ; Thu, 26 Oct 2023 15:03:26 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9ba081173a3so225814066b.1 for ; Thu, 26 Oct 2023 15:03:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698357804; x=1698962604; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=DEmmsMUNDXrHxbfE3Ce3REr5A6wqcO3bgGi92YBCkzI=; b=b6py9JZyfVMrZlL9Jrva7w5VfIiGgteU73GfhFfG4sEaLJkxrbhpfZa81w21gz8eeW en3F3GdHCHMu7EIqMWDcUXl0qOPghFnoNDPulKM+K93DeQyP98eZpO9zlmLbF0h+oZKk ZPicbXWat17VSNxEdTf4WXBTxlYUelUZ65MvCdS8+M4CnwA1/yO18V+jnjFCnCw1ZR45 4txR3ytLNXZXOa4EJzP4IQmYGxIPbQwjjlZsmNlaZu52ZFE5A9VhjxAugf7cBifOcHwz ES/+bXdZc5nzF29ZsVXdRJMEkfmNWUxOAyW/3epHKVbERIDuF18t0UAOt1RiP33TLzUu WuPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698357804; x=1698962604; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DEmmsMUNDXrHxbfE3Ce3REr5A6wqcO3bgGi92YBCkzI=; b=HK7Cn6fQtvX6zAdoGjzWGFxax6Cc/R58yPi/+OFCsEA81rEVWhNToyMvDhzol4tszW ULzZk8zsYYlhHJFCEuuobhcreFrd8LiLNkwH51hu2S/5qy3mQSUifVgJJHk/n19BXnan KGjYNg72umb62yW1+YR4iFuvljDL77xSBLMJi6ewnLLjI/ttSnEcM3m6sQAo99D9+gFH ZZcuPjl8ZIFwXNbjNIbD2Op7g4J1oPgjiRY8kV5Cv7+4Sgy1vlHLlD8u0E5JciNU7cNF 4t5yUiKsGbHBgS0SeoL5b6S9OrKEAlhc4dJ5qvnBWPTaJ3fLxY0UivBvSOaFdJ14sBp+ RCtQ== X-Gm-Message-State: AOJu0Yw80rO2+DLzI+lcnxnbq0nbKV9DhgvQTa+9+L9/EvUYtfX/d86H W2R3LFCos3OeXXEX0sekx/o4hvJJkdjQhm6W25PjHg== X-Received: by 2002:a17:906:6a24:b0:9c5:ea33:7bf9 with SMTP id qw36-20020a1709066a2400b009c5ea337bf9mr701118ejc.51.1698357804394; Thu, 26 Oct 2023 15:03:24 -0700 (PDT) MIME-Version: 1.0 References: <20231026171349.work.928-kees@kernel.org> In-Reply-To: <20231026171349.work.928-kees@kernel.org> From: Justin Stitt Date: Thu, 26 Oct 2023 15:03:11 -0700 Message-ID: Subject: Re: [RFC][PATCH] wifi: wil6210: Replace strlcat() usage with seq_buf To: Kees Cook Cc: Kalle Valo , Johannes Berg , Max Chen , Yang Shen , Steven Rostedt , "Matthew Wilcox (Oracle)" , Christoph Hellwig , 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Thu, 26 Oct 2023 15:03:31 -0700 (PDT) On Thu, Oct 26, 2023 at 10:13=E2=80=AFAM Kees Cook = 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 > 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/ 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/wireles= s/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_s= ize) > +static void resume_triggers2string(u32 triggers, struct seq_buf *s) > { > - string[0] =3D '\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 =3D 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), st= ring, > - 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