Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp2752845rdg; Mon, 16 Oct 2023 13:52:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGnXZ7cKnNEbzG9cNAU9jfkko34bDHllJlkyjE12MIPkCurRe7ceC28Qz1tr+Ns+4rgCEa8 X-Received: by 2002:a05:6830:3484:b0:6cc:d4f7:e37d with SMTP id c4-20020a056830348400b006ccd4f7e37dmr435995otu.5.1697489567226; Mon, 16 Oct 2023 13:52:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697489567; cv=none; d=google.com; s=arc-20160816; b=XZmeD1v3Gu2oaVp2v+pCTE7jYsT9+rMClTW5fvdYxU/VJK2blB2j5HnNa7cIRz0nj/ ISaM6z/xs9VyQ6TLKHK91/xHOMlYkP4aWjme30ArIUpVu7ssPtpciwoa/YKNR6f0efJx IoGgJsXE9hSJM4XQEm21fJ4/ZjelIFM9JlgJ0M3DPq6NYcSToXhr4c9mmrksnBcJYU3T qyGnRt4X4NsqQD35vYOwudtjOcP43/w/a72cFfOTsDqyauLJOndDCIxWt8aaAYvd3A3j SS7bXuqPJWfNWT2zgQ9ucrt30rRUfQMJE1UQnTM1hHDVWbesZzYJhrT5Jd+7TfoipOw1 oi7g== 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=+HU6cA1bWRfvIfBDvXUL6UUn9mAyVrw+2kF9P2luauc=; fh=b4LMKuM2AbnVqUV80CjdV1MGnFqE3zDBjTZEVavcPr4=; b=OIqIxqxnSKfXBvT+u1TaDkpaJJjuP+9dG65tAj/wnj0zhl6IrW4kDKFE0mHNCMxB4D ocMiPREh0q0np+nuLMqaQiDQz2qjcp2ntOIgxjpXKyt/bdnc8Hn1DpyTLA52taimKrZO eRavn/jj9YOdHHZZruxLFcMg/s8/jIA1H+hNfhTevrUSFOoZMLO45gwiEqPhjyC0vR22 d+wCOIhNmX9acFUGzQ+aTUHGd46tVJPDji9cc84tkf2JO8l9nObzZd83Dx1nwCU/Gpfv O2sp2DAeK9JC+ct4i+mQFlNTobzAuUASsmufmR3t+fOZMOE0+7SZR/goNviB9a2Q/CBU gxEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KnnpNBuR; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:6 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. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id h7-20020a056a001a4700b0068ace3816d7si623874pfv.387.2023.10.16.13.52.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 13:52:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KnnpNBuR; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:6 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 142BC80BF1C3; Mon, 16 Oct 2023 13:52:40 -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 S232365AbjJPUwj (ORCPT + 52 others); Mon, 16 Oct 2023 16:52:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229666AbjJPUwh (ORCPT ); Mon, 16 Oct 2023 16:52:37 -0400 Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46193A7 for ; Mon, 16 Oct 2023 13:52:35 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-53406799540so8707835a12.1 for ; Mon, 16 Oct 2023 13:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697489554; x=1698094354; 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=+HU6cA1bWRfvIfBDvXUL6UUn9mAyVrw+2kF9P2luauc=; b=KnnpNBuRS3Z6pzATlCxujnLGRaSu9lV4XhxQfLgAwBghl6D37pQuOmKoh4LTAOyLi5 tW/hXxzQtS2v9XHXBFdwlokEsBXt2eLnEaPH6w8SKbie3t7oTVGJqOcjSkswlSvYQDPp pW6B01HOZo6xhhraZBiBvE1lY1spjlDA3AZELF0cAX9qVXrE45wsJqyJm5ndI2ClPL6X E+hQIkq+RL7YGGI8lSDoR3WaDcRg3cGSIYr/cSo/wjMOb2dBK3vRry13dBXPYoXSGQX0 zcaBNL2dkl3iy8WQi+c3l/Q46e3T0LJeWTZyBV9pPeIyLkuq20CQSQG+2Uaw9r3cgz0t rjDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697489554; x=1698094354; 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=+HU6cA1bWRfvIfBDvXUL6UUn9mAyVrw+2kF9P2luauc=; b=mbwhxfhBwF/U+BXcQOTog1Z0Fu6LbTIq1ehCH19kSRNlSVx8dAlrmKIrPFTkMXIe0a ytbr9ZFHpTtRMrZUcVgBYQrrLJC4MDB5H3KEgdiYqx2oTthYgL6h3dX5DFO8N1KESkNF 6r2kjG7NML5mc4XEo6ITiJxI+1n9AB+N3utM+l5kAbDEuvEzhwjJudUbDVTl3NPk/P84 GCFnW3SUktp43gQttie5lNJXAeK3cBdtZrQINQLP+/SacAFP3UnKL+nQV97q4Umfcir6 QPRtwN9gTJAzEbvqWDtfoa5vU3nqY+LGVbGXoUk/Ff4MvR/g7utCk8yThaIy4T4GU3xr V26g== X-Gm-Message-State: AOJu0Yyh+V24Rs3AU0QNzc3MCzaBe5hcTPBQ6Xe6OZPjvpU7HPBd9SNj j4M43jjvtW0YvGRo0wNBXj2numJi3xJ3nI93BnqEcQ== X-Received: by 2002:a05:6402:5252:b0:53e:21f6:d784 with SMTP id t18-20020a056402525200b0053e21f6d784mr337922edd.8.1697489553657; Mon, 16 Oct 2023 13:52:33 -0700 (PDT) MIME-Version: 1.0 References: <20231016-strncpy-drivers-net-wireless-broadcom-brcm80211-brcmfmac-cfg80211-c-v1-1-4234807ca07e@google.com> In-Reply-To: <20231016-strncpy-drivers-net-wireless-broadcom-brcm80211-brcmfmac-cfg80211-c-v1-1-4234807ca07e@google.com> From: Justin Stitt Date: Mon, 16 Oct 2023 13:52:21 -0700 Message-ID: Subject: Re: [PATCH] brcmfmac: replace deprecated strncpy with strscpy To: Arend van Spriel , Franky Lin , Hante Meuleman , Kalle Valo Cc: linux-wireless@vger.kernel.org, brcm80211-dev-list.pdl@broadcom.com, SHA-cyfmac-dev-list@infineon.com, 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]); Mon, 16 Oct 2023 13:52:40 -0700 (PDT) On Mon, Oct 16, 2023 at 1:48=E2=80=AFPM Justin Stitt wrote: > > strncpy() is deprecated for use on NUL-terminated destination strings > [1] and as such we should prefer more robust and less ambiguous string > interfaces. > > We expect ifp->ndev->name to be NUL-terminated based on its use in > format strings within core.c: > via brcmf_ifname() -> > 67 | char *brcmf_ifname(struct brcmf_if *ifp) > 68 | { > 69 | if (!ifp) > 70 | return ""; > 71 | > 72 | if (ifp->ndev) > 73 | return ifp->ndev->name; > 74 | > 75 | return ""; > 76 | } > ... > 288 | static netdev_tx_t brcmf_netdev_start_xmit(struct sk_buff *sk= b, > 289 | struct net_device *nde= v) { > ... > 330 | brcmf_dbg(INFO, "%s: insufficient headroom (%d)\n", > 331 | brcmf_ifname(ifp), head_delta); > ... > 336 | bphy_err(drvr, "%s: failed to expand headroom\n", > 337 | brcmf_ifname(ifp)); > > Considering the above, a suitable replacement is `strscpy` [2] due to > the fact that it guarantees NUL-termination on the destination buffer > without unnecessarily NUL-padding. > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strn= cpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.h= tml [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Signed-off-by: Justin Stitt > --- > Note: build-tested only. > > Found with: $ rg "strncpy\(" > --- > drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c = b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > index 2a90bb24ba77..7daa418df877 100644 > --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/cfg80211.c > @@ -866,7 +866,7 @@ struct wireless_dev *brcmf_apsta_add_vif(struct wiphy= *wiphy, const char *name, > goto fail; > } > > - strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1); > + strscpy(ifp->ndev->name, name, sizeof(ifp->ndev->name)); > err =3D brcmf_net_attach(ifp, true); > if (err) { > bphy_err(drvr, "Registering netdevice failed\n"); > > --- > base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 > change-id: 20231016-strncpy-drivers-net-wireless-broadcom-brcm80211-brcmf= mac-cfg80211-c-a20108421685 > > Best regards, > -- > Justin Stitt > Ignore this patch. It will be rolled into a series with others. Just found some more strncpy uses in broadcom/brcm80211 so I will make a se= ries fixing them all at once. Thanks Justin