Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp2885714rdh; Mon, 30 Oct 2023 10:20:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGFa+oopNSelIb9Fo1ZHDE95UUZiTQOGrF4iRvZ/GEL0pns7EFKoH4WTMyIBbf1lPhzicqI X-Received: by 2002:a17:90a:db92:b0:27d:4f1f:47f5 with SMTP id h18-20020a17090adb9200b0027d4f1f47f5mr8270613pjv.23.1698686456996; Mon, 30 Oct 2023 10:20:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698686456; cv=none; d=google.com; s=arc-20160816; b=uDyAp9ecod9RGXo9DiF6iiHJJYapKCulOIhHkMdGNef+CopwLNBBmLqf3QmW84nR7v akZIPOUQG1dXa4oHQWtrkym44OD29pgAslE038OWItawLnFlqRe0Za2y/oU9a/+886NX cEIEECs+y4d57EaS1T6zWPzcecWdHtNjjRJYYQJKecP/0eMKOTrg/jODuEmBqc1tAOGT AWywx36Qx+FpSsj+ue80Me2YhAA4QJ7Sp4eCdcSEE0fksowsCFi9EH8Yj83Gz6gbkXDH fq4NzgfDWmWnUWy/MYMwE/6J6STx/iGGWEYkfnLXySbnYgBqygVnO1SlGUvV5NXjUUOy ECXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:date:message-id:user-agent:cc:to:references :in-reply-to:from:subject:content-transfer-encoding:mime-version :dkim-signature; bh=nXSQ0e/0gO8tB+gzz4g8lqdAsSx9w0keOykio/3FGsY=; fh=+1IBcS3Mlk8aftp9Va3Xee7Fh/MKicG8VB9FSblRPak=; b=vpKH8K8LZch/1Egb8GPe4RvpM/BOit5cydPl4kMas2sH1D0IhV2Dqb5m0e8LBaQoRf +QI91VOMSY2Ek4nqrgnP2A/a4Gk9gUjFekIRHJeS9Jc5/VdthPfcCro2c8M5QhAbJPRj nXjcILe+HBqn/gPQ7ZeqqCTaf44Jj/kvE4gHIKzn8YhlrSsCrRfpb/1YAurPyp11xyQf /agGKxQAmtcZTRGct8YwRi8/G40xQ+NFNvIV6O8L7EzqYwBooyWhFaGucqzMOIerToPg AqQoHmT38eAwWvLFU3DwaxOBfbkvtacQ41kRM+8eHa23IQIbCMSuwzEK5Eo2JQQaSBvA aY+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rde9Dv9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id rm6-20020a17090b3ec600b0027d29e618f7si5210025pjb.78.2023.10.30.10.20.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Oct 2023 10:20:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Rde9Dv9j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 048E3802D508; Mon, 30 Oct 2023 10:20:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232897AbjJ3RUx (ORCPT + 99 others); Mon, 30 Oct 2023 13:20:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229587AbjJ3RUw (ORCPT ); Mon, 30 Oct 2023 13:20:52 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A63FF8E; Mon, 30 Oct 2023 10:20:48 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3464BC433C8; Mon, 30 Oct 2023 17:20:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698686448; bh=J/BDKDmt4ytWYut9+XphDd+OA2xYRaH3LWnmAbLoFQE=; h=Subject:From:In-Reply-To:References:To:Cc:Date:From; b=Rde9Dv9j3N672wNfHkJUA0SIvXLKmsAIx2651HHsMohDpXIk6yRPthyTABuWJqL7w f5Ap7RlKuHXOqxPJmFFyk+TfPHMGPnmRezQAwe6eWsZR0WZ2rOW7e+Hmn2Gr2YRDad Q/DAoBJ6qX62/83GIuNVYlNHJx3OpOm5E2PRmI/wd5w1ZSeOd96daq/Drl1bLvIuT5 VbVMISEFqX6DH1gdc70xHkV4OHXJZgEQknZ/IbYQhemtpNBXaQNvwjqxTyGzrtjn3u 1KJvTE8ELQVZJDfDOK8NiBz4C/ngUgWlVV0tvfOTRI7Rj7RSMcWMFuvoTr0vNlIyzY ro/6w+2ZpJemA== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PATCH v3 1/2] wifi: brcm80211: replace deprecated strncpy with strscpy From: Kalle Valo In-Reply-To: <20231017-strncpy-drivers-net-wireless-broadcom-brcm80211-brcmfmac-cfg80211-c-v3-1-af780d74ae38@google.com> References: <20231017-strncpy-drivers-net-wireless-broadcom-brcm80211-brcmfmac-cfg80211-c-v3-1-af780d74ae38@google.com> To: Justin Stitt Cc: Arend van Spriel , Franky Lin , Hante Meuleman , 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, Justin Stitt User-Agent: pwcli/0.1.1-git (https://github.com/kvalo/pwcli/) Python/3.11.2 Message-ID: <169868644429.1993746.5520695482478737730.kvalo@kernel.org> Date: Mon, 30 Oct 2023 17:20:45 +0000 (UTC) X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Mon, 30 Oct 2023 10:20:56 -0700 (PDT) Justin Stitt wrote: > Let's move away from using strncpy and instead favor a less ambiguous > and more robust interface. > > For ifp->ndev->name, we expect ifp->ndev->name to be NUL-terminated based > on its use in format strings within core.c: > 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 *skb, > 289 | struct net_device *ndev) { > ... > 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)); > > For di->name, we expect di->name to be NUL-terminated based on its usage > with format strings: > | brcms_dbg_dma(di->core, > | "%s: DMA64 tx doesn't have AE set\n", > | di->name); > > Looking at its allocation we can see that it is already zero-allocated > which means NUL-padding is not required: > | di = kzalloc(sizeof(struct dma_info), GFP_ATOMIC); > > For wlc->modulecb[i].name, we expect each name in wlc->modulecb to be > NUL-terminated based on their usage with strcmp(): > | if (!strcmp(wlc->modulecb[i].name, name) && > > NUL-padding is not required as wlc is zero-allocated in: > brcms_c_attach_malloc() -> > | wlc = kzalloc(sizeof(struct brcms_c_info), GFP_ATOMIC); > > For all these cases, a suitable replacement is `strscpy` due to the fact > that it guarantees NUL-termination on the destination buffer without > unnecessarily NUL-padding. > > Signed-off-by: Justin Stitt > Reviewed-by: Kees Cook 2 patches applied to wireless-next.git, thanks. 9d0d0a207040 wifi: brcm80211: replace deprecated strncpy with strscpy a614f9579705 wifi: brcmsmac: replace deprecated strncpy with memcpy -- https://patchwork.kernel.org/project/linux-wireless/patch/20231017-strncpy-drivers-net-wireless-broadcom-brcm80211-brcmfmac-cfg80211-c-v3-1-af780d74ae38@google.com/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches