Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1374204rda; Mon, 23 Oct 2023 10:30:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF8jGx36Ta6yAD/0YNsoaJ2EDWa+Ks119yko8Fr+Kf0zPw9CkJWDJ1WCbwk7pQLXwZ00g9z X-Received: by 2002:a05:6a20:938e:b0:138:836c:5370 with SMTP id x14-20020a056a20938e00b00138836c5370mr272255pzh.42.1698082253046; Mon, 23 Oct 2023 10:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698082253; cv=none; d=google.com; s=arc-20160816; b=O6qTXcwfE4jWIJFg0D0HZ4OFZ1MlYOUs6tI06MT7eTi1e8T8AEyzkhxj7BdkiIQFpk Nv2F6+6oS5W/JjcQrBsQgRQNAMj5sdq43A+FhGjdo4U/SSrGvtmWHcleFui11ZZvFSsI KvqGa/KjX83P3ngx6iyvU6sUlnmYLvXp6EMdsjd5GtrG82a9WCW+b4t4+fGXs9Jsxc0d 9ooeETwUPjV4XpKOQMSl+49LdDH0HDebZQUVoMjREd8hc4aSpXfk2CF8NruaC7hH/HRA Vjy64dpXv+YwXmc8qTsSr8DO+WoYhB74hSTlky57mvWeGPMyl8G4O7QESt8Q6h9hg2Z0 ahzQ== 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=p2vF08k5PnRybh4+aE5Fvl8loucZcpEnkM5XZtdpVlI=; fh=/5Ctfx2ilDt7yiT0kTR9x2aGarm1cw3mbdZUCnlD9Bk=; b=EyrY8RXlknh3TMRG1zYNAaioc2myEr/T18fdHt20oUZszRiYzHxiF5FGwrdeRxf1rF cD7aQWvin+pot1+2ZKVDFv7GaVAJqv2raH8YyZftjiR8d7RYXXopQVYmrONFXVYK97rs ge6BN2IKHYJx4ONHPLHphT5MMbv3QLUrMzhSpBEEBpJEQ47LWOlQglam33OhlDDKt/kn acR5rOjNTj2wC+Ff7GxOf5G1qpBDBD0Ra74mMdsr30YMVqn30u8XUs4UNk/h9M5xbmN7 G23u82d7soNPdJivD5Js/wZCGCxh8R6DzHLnUgm+umX/xS4Thho0UlU1RD645JJT5nYf oTYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FR4CDg9m; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id i129-20020a639d87000000b00585ad175170si6761896pgd.69.2023.10.23.10.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 10:30:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FR4CDg9m; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-wireless-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 fry.vger.email (Postfix) with ESMTP id 50DBB8096A65; Mon, 23 Oct 2023 10:30:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233737AbjJWRas (ORCPT + 52 others); Mon, 23 Oct 2023 13:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233748AbjJWRa0 (ORCPT ); Mon, 23 Oct 2023 13:30:26 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 61E7B1FE7; Mon, 23 Oct 2023 10:29:34 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6BCFEC433C8; Mon, 23 Oct 2023 17:29:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698082173; bh=TFyddzODnA71wlttcWczDl2ULr/aiDXiJcRsmEttaXE=; h=Subject:From:In-Reply-To:References:To:Cc:Date:From; b=FR4CDg9m+SAmdKCzpr0yZ9kRTMHdtjdTtTLzAcWdAH2yo8eedoUNIFEorpJTshynG +YIHrRJaVeB96pyOq7vW2AX/P/YINun0pPUCFpCCio2CmrzoPavpNxejtI70mgOJ/5 vVFQGjBFuDNHix5xbmPTuwhcJ5KoMpeX40B4+FlKw/nvvY+i2I6+rZyuWuMWPUi3pf 5GXWapp8Py6yGmz/5vSyzP5pBPr0jVD8vtoT9tMu3OtsIqDm927tLF0BaKBi82fKDc c+IlEQDp6L/d55EOUO6VSwaas0pX/MYgeRVpkLcDJrjhH+MuHvT6gEKZRbmDORnX3O DtF8zDpM4/ZXQ== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: wifi: wlcore: boot: replace deprecated strncpy with strscpy From: Kalle Valo In-Reply-To: <20231018-strncpy-drivers-net-wireless-ti-wlcore-boot-c-v1-1-d3c6cc6b80fe@google.com> References: <20231018-strncpy-drivers-net-wireless-ti-wlcore-boot-c-v1-1-d3c6cc6b80fe@google.com> To: Justin Stitt Cc: linux-wireless@vger.kernel.org, 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: <169808217070.695306.9829944196418700359.kvalo@kernel.org> Date: Mon, 23 Oct 2023 17:29:32 +0000 (UTC) X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.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 (fry.vger.email [0.0.0.0]); Mon, 23 Oct 2023 10:30:50 -0700 (PDT) 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 wl->chip.fw_ver_str to be NUL-terminated based on its usage > with DRIVER_STATE_PRINT_STR() in debugfs.c: > 491 | DRIVER_STATE_PRINT_STR(chip.fw_ver_str); > ... which uses DRIVER_STATE_PRINT(): > 444 | #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s") > ... which relies on scnprintf: > 434 | #define DRIVER_STATE_PRINT(x, fmt) \ > 435 | (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\ > 436 | #x " = " fmt "\n", wl->x)) > > Moreover, NUL-padding is not required. > > 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#strncpy-on-nul-terminated-strings [1] > Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] > Link: https://github.com/KSPP/linux/issues/90 > Cc: linux-hardening@vger.kernel.org > Similar-to: https://lore.kernel.org/all/20231018-strncpy-drivers-net-wireless-ti-wl18xx-main-c-v2-1-ab828a491ce5@google.com/ > Signed-off-by: Justin Stitt > Reviewed-by: Kees Cook Patch applied to wireless-next.git, thanks. 75fdaa28f103 wifi: wlcore: boot: replace deprecated strncpy with strscpy -- https://patchwork.kernel.org/project/linux-wireless/patch/20231018-strncpy-drivers-net-wireless-ti-wlcore-boot-c-v1-1-d3c6cc6b80fe@google.com/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches