Received: by 2002:a05:7412:251c:b0:e2:908c:2ebd with SMTP id w28csp1372252rda; Mon, 23 Oct 2023 10:27:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGzIPRWPxYY/+z3DGiYCuay2yE3gVFOYEBoVPBvZmT2MG7mVJkKwON1sJ7ilT3iQW6YgnpL X-Received: by 2002:a05:6a21:6810:b0:171:4f38:b475 with SMTP id wr16-20020a056a21681000b001714f38b475mr216298pzb.58.1698082020772; Mon, 23 Oct 2023 10:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698082020; cv=none; d=google.com; s=arc-20160816; b=lTu/2nTV4B67c46ra7PuFwC4mfMJS/06tA9fL1QVFqftWEAAmxUHo0ukEvg17T5rz6 pQJ8kU1EH2H702ssXjNP8TrF9xjiVXG+lOCNWGD07aQTYCWAY8UNkDRdNOA55G6MA6Il Av5uf+Ju5667WT8H9IAbWnJL9/PkOUzE3ApsE842zAggh6ueJo1emGAc/FWDRTvt+Bhr DGXm//ECdh+xu0W0Ez33orSGcfWZiejaE8jsPDUeXWJQJNzi7kMsyVLszSGFoiix4XoQ eHQcAc4Wwh4vKC/f4wHcwck6QPIq1OLKq6tiN7SRX2OPcGKc4Lp0jAWIB/QPozQFNY3l 2QVQ== 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=yWDAmjwOp43aE+/WIoElYf6LppfE9rGQ40v68qWTdEE=; fh=qe1AMwMWnechksWSwao/V+JMgMH2s87Q34R1zn6N9/0=; b=lkk37TzQFbIiHidiOH47D2R9p10isn5Vlpqe7cNv6pD8+5vM32xsdc4HMnVjOfdMJz qgtpCTmb+Rp6NpUx02Yci5c0HL6PvDugyw/frXr2owMYbw148uRdWsPO2MKJVilDGb0r 4MXVbP3Kxu/hl/Wh3ROhvNAE85/w24Lc2hdppniEpkXJGCQslr0Pp9pE+tf+MnRB7D1H IW8qB4nTc5k5svea6jjSeOo8SoBB785QU45T2etfROlVr31hwX91p3ERdTqSTIznbuYK JmUMssXyKsJatJv1WgAZ8xgb6pgFgH4VatdGI29KiPkO8Hp4zmztacX4ixfotTRKf2tC fPlw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u2QXvS5I; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id l24-20020a637018000000b005898e10f9b9si6556595pgc.213.2023.10.23.10.27.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Oct 2023 10:27:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=u2QXvS5I; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id 0297E8035127; Mon, 23 Oct 2023 10:26:55 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232052AbjJWR0y (ORCPT + 52 others); Mon, 23 Oct 2023 13:26:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41304 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229662AbjJWR0x (ORCPT ); Mon, 23 Oct 2023 13:26:53 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E23D127; Mon, 23 Oct 2023 10:26:51 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66675C433C8; Mon, 23 Oct 2023 17:26:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698082010; bh=N0T7cOgCbINrOXJ2SVCDOAHG/2PRx25LOpY5Fkz1Gk4=; h=Subject:From:In-Reply-To:References:To:Cc:Date:From; b=u2QXvS5IZazJ+Om2SJK9qimi0fz7wYBRKR6LUZODW6csSKeVGy8/V4BnRchYeyyev vHMm3Xna0eh6/tkWAVIiID7436mKW1UamEvtL3uLzOV2KU8WIf045HHchPa2NfEkwv pi8JKiaWajd5O2SQksuay03/s9Kp4nlBkXa/Mi7jq8Td/To80hquCMOiTNzIzuTmx4 OpRuHqly4RVxj3yuHcPbT27a2m9PQc4VSc9UpHMHwrZCuDMBli9CAYoy6MYcTweDWA qg5XMukhS3IuXGhd/lT7fQ8dpwOB9E3I9mBrl4yzH7oTydWE66TPHUUKAS8aTQFvTa rap6oEjpmEjrA== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [PATCH v2] wifi: ipw2x00: replace deprecated strncpy with strscpy_pad From: Kalle Valo In-Reply-To: <20231017-strncpy-drivers-net-wireless-intel-ipw2x00-ipw2200-c-v2-1-465e10dc817c@google.com> References: <20231017-strncpy-drivers-net-wireless-intel-ipw2x00-ipw2200-c-v2-1-465e10dc817c@google.com> To: Justin Stitt Cc: Stanislav Yakovlev , 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: <169808200764.695306.10833187895555987178.kvalo@kernel.org> Date: Mon, 23 Oct 2023 17:26:49 +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 lipwig.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 (lipwig.vger.email [0.0.0.0]); Mon, 23 Oct 2023 10:26:55 -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. > > `extra` is intended to be NUL-terminated which is evident by the manual > assignment of a NUL-byte as well as its immediate usage with strlen(). > > Moreover, many of these getters and setters are NUL-padding buffers with > memset(): > 2439 | memset(&tx_power, 0, sizeof(tx_power)); > 9998 | memset(sys_config, 0, sizeof(struct ipw_sys_config)); > 10084 | memset(tfd, 0, sizeof(*tfd)); > 10261 | memset(&dummystats, 0, sizeof(dummystats)); > ... let's maintain this behavior and NUL-pad our destination buffer. > > Considering the above, a suitable replacement is `strscpy_pad` due to > the fact that it guarantees both NUL-termination and NUL-padding on the > destination buffer. > > To be clear, there is no bug in the current implementation as > MAX_WX_STRING is much larger than the size of the string literals being > copied from. Also, strncpy() does NUL-pad the destination buffer and > using strscpy_pad() simply matches that behavior. All in all, there > should be no functional change but we are one step closer to eliminating > usage of strncpy(). > > Do note that we cannot use the more idiomatic strscpy invocation of > (dest, src, sizeof(dest)) as the destination buffer cannot have its size > determined at compile time. So, let's stick with (dest, src, LEN). > > Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] > 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. 8890b9bca38f wifi: ipw2x00: replace deprecated strncpy with strscpy_pad -- https://patchwork.kernel.org/project/linux-wireless/patch/20231017-strncpy-drivers-net-wireless-intel-ipw2x00-ipw2200-c-v2-1-465e10dc817c@google.com/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches