Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1373724rda; Mon, 23 Oct 2023 10:30:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/XpLdIBWel5RySbc0Hb8DyMIRLCEm/fJlmUkCjoh8OAZ6R8GJRvJBh/o/2ZWxKkcPc1iV X-Received: by 2002:a05:6358:9287:b0:168:dbbb:1a6 with SMTP id m7-20020a056358928700b00168dbbb01a6mr3574835rwa.12.1698082203208; Mon, 23 Oct 2023 10:30:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698082203; cv=none; d=google.com; s=arc-20160816; b=JVxaleMkJUR7HyyrY6J4oilKii06YV1OkMsub7nss+lmIYSpAjPydCnxg4CXNes4lS 4B/G/BvVhNqG5TiV1nsCB5u9+UQbOV19HogQiJg02BoJFT00R02doohyC0NgNKRL3v6A +4s3SNQNyML0UmCQnOUpg2XG2ahKs7f2Uyp20U/TxUdmbM/9rl+WiUooYuD8SacR+/t2 0Ce4cft/DdYqU3PrKcymvSN4yApy0LMTWyivWIwPRGDJPEipoSGsgBJVTwMdDTJB2Ai/ 4RH8FwZeiHEfsUQM8+IxMcoyOcqQ/MfzlVDw7dSMsWhJaS7rOCbs1tTFzKNuep6Cbaj7 3qVA== 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=Jszgwsw3GW4lQEyY47N6DCvTIx6Gtglurzg4nwUMs/Y=; fh=/5Ctfx2ilDt7yiT0kTR9x2aGarm1cw3mbdZUCnlD9Bk=; b=qhJsCxMlZSkxtkxGbl2xjOTMh8+An1D6ZuvQ++tFNOzhAy9GW+8RIsJfG64nPxOnz8 nZLRP7ve/mdQmBjI7T7TtmM6B+nq0SvBNnRqCx6QpGkYkY8fA8Cb77fDLcLRcT9UWRyN d3Tq1Gn+XOiQp1ydmwDE2D9TNSYfxbAl85/BKme3wgqgQ6L4hJZBIdEuyXQTCAfJLdj1 g2OWmr/2mZ8sOOH66vWZXbZCyAX7CrgImxVfiQheWsw8sNjoB8XMUlnb4P3j2RttvRh7 VyB/wNbPsW4lmyXC9UsTGmUrYxEKIjPg5IdschFWZ1KUraJAij6o+NOnn3lZURJhZ3jv MZcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FVgWfTu2; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id e7-20020a636907000000b0057851fc2b4asi6718211pgc.55.2023.10.23.10.30.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 10:30:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FVgWfTu2; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id 5917280569A5; Mon, 23 Oct 2023 10:30:00 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbjJWR3y (ORCPT + 52 others); Mon, 23 Oct 2023 13:29:54 -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 S233776AbjJWR3X (ORCPT ); Mon, 23 Oct 2023 13:29:23 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A812A1717; Mon, 23 Oct 2023 10:29:04 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4C05C433BF; Mon, 23 Oct 2023 17:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698082144; bh=QHFYOWlkGzWzBm8/TDgaH/NxaV2cslJrLINWwlJQA/s=; h=Subject:From:In-Reply-To:References:To:Cc:Date:From; b=FVgWfTu2X8tsb3prDb290Ls4nIJjC2E6e+STuJrtghR8sn4A7zuJHXf7ReOr7uRv9 X3vbQv5lLeOSahlR7Q0Uj6EQiFbDa7hbehu/4xm7jPh8xDXnKVgbO8Sbu5voHC9keB EdxUfDnK9RwbuZ/OmB0SSicqHWPu/CiDyPCWTd1pknVzWmra/gjOAW9JZ9B09Q9EgS PGJIpp9kqg5jS6OYM6k1RcRBTHhxtxrrWmEPo/DZ8SFeBrL7+3g2cVTmTXJ4LGRF4G FFpCqxIKSgvx6YfwS8Fy0h0HoG5xSVkkLb3Fx8Tbj1J8hx4kvIlHDBu6PJNW7cMbj9 uYIcOimdXRO/Q== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PATCH v2] wifi: wl18xx: replace deprecated strncpy with strscpy From: Kalle Valo In-Reply-To: <20231018-strncpy-drivers-net-wireless-ti-wl18xx-main-c-v2-1-ab828a491ce5@google.com> References: <20231018-strncpy-drivers-net-wireless-ti-wl18xx-main-c-v2-1-ab828a491ce5@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: <169808214096.695306.16867371927362677555.kvalo@kernel.org> Date: Mon, 23 Oct 2023 17:29:02 +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 morse.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 (morse.vger.email [0.0.0.0]); Mon, 23 Oct 2023 10:30:00 -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. > > wl->chip.phy_fw_ver_str is obviously intended to be NUL-terminated by > the deliberate comment telling us as much. Furthermore, its only use is > drivers/net/wireless/ti/wlcore/debugfs.c shows us it should be > NUL-terminated since its used in scnprintf: > 492 | DRIVER_STATE_PRINT_STR(chip.phy_fw_ver_str); > which is defined as: > | #define DRIVER_STATE_PRINT_STR(x) DRIVER_STATE_PRINT(x, "%s") > ... > | #define DRIVER_STATE_PRINT(x, fmt) \ > | (res += scnprintf(buf + res, DRIVER_STATE_BUF_LEN - res,\ > | #x " = " fmt "\n", wl->x)) > > We can also see that 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. > > The very fact that a plain-english comment had to be made alongside a > manual NUL-byte assignment for such a simple purpose shows why strncpy > is faulty. It has non-obvious behavior that has to be clarified every > time it is used (and if it isn't then the reader suffers). > > 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 > Signed-off-by: Justin Stitt > Reviewed-by: Kees Cook Patch applied to wireless-next.git, thanks. fb329e8b1d88 wifi: wl18xx: replace deprecated strncpy with strscpy -- https://patchwork.kernel.org/project/linux-wireless/patch/20231018-strncpy-drivers-net-wireless-ti-wl18xx-main-c-v2-1-ab828a491ce5@google.com/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches