Received: by 2002:a05:7412:f690:b0:e2:908c:2ebd with SMTP id ej16csp519957rdb; Thu, 19 Oct 2023 10:45:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFXwwoiSEp+0ehSGzQxQ7Uc/n84tCL9zHVSJGsdZ12cUOBxvHCyLAV+6y/ybRkeg8HGHj9z X-Received: by 2002:a17:902:d3c6:b0:1ca:79b6:ce42 with SMTP id w6-20020a170902d3c600b001ca79b6ce42mr2355015plb.47.1697737553447; Thu, 19 Oct 2023 10:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697737553; cv=none; d=google.com; s=arc-20160816; b=RSIvsyKA6QM7GInl00Wk1h61kb2CWeC9N3o85KROuHK8F+9W/JSQTg1vlpnF8e9UVh d60coPRnnlUl1H121rgHe9pifOGG+NfEMEMrehrXfwiZpBaPM+8YF/cewASHK77Re67s TeiSaQX2eNGDH94Sw+7c/jTn2er/YIKSMezAXLSNLnDvBlXWsm4OscrS/5Mlv1YZQ1FJ YchDz5thYfUeU4Ure3veucgZJq0kU/Sy02OZn+wf/fyABK8JLRECisshmcmdecrDxgXI /n1CZ2c8UfCX1xzDTxmeeLCyYQWtJnkBmmDq/nzPKs+985IIzHHUyuArPfJMs4vOG3pt V/4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=qg+otgUOPQR+8G/4uV/TUAnZUyW51Jn+plgzCktzBuA=; fh=ofafhIboOh+sgBMhlYeEa39ZlWLvHC6+eMJOf1uOJgM=; b=Ioo92KCQ8Gx4+KDvVlI3nprJhGXb0G43/glc23a5BdJiKakigHDvUFt5zFtf3sxUYB 0LYlxzywdTrB7IEXPuivC221PPKAVWYzuH8ntL9KDJuU2n1P/kc8jy6aaSqfQYgZwCt2 3UFHPqpzXoLVD9ByJSbS2weSPD22bzO3w8K3B8vuCeoZm22m9A0Ow1rGPjpYyahPnyNc yXxBucU0h8aBJvH5WWBH572P25Em2EoE8Op8I/e+Vs1K4rV25luy+CujzC/9zlc6WMc4 D05YBjwuGdHVqz6vYGlwzWs7Py/MjaDe22RIuTiQehwkyFJmwhb7zd0oLg+zKDGkmiSb Gghw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="XDrru/Ap"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id k11-20020a170902694b00b001c78345f376si2424596plt.241.2023.10.19.10.45.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Oct 2023 10:45:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="XDrru/Ap"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id 7C0B1823579F; Thu, 19 Oct 2023 10:45:45 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345994AbjJSRpG (ORCPT + 52 others); Thu, 19 Oct 2023 13:45:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235484AbjJSRpF (ORCPT ); Thu, 19 Oct 2023 13:45:05 -0400 Received: from mail-oo1-xc49.google.com (mail-oo1-xc49.google.com [IPv6:2607:f8b0:4864:20::c49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3699114 for ; Thu, 19 Oct 2023 10:45:02 -0700 (PDT) Received: by mail-oo1-xc49.google.com with SMTP id 006d021491bc7-583eeba3d76so1580671eaf.1 for ; Thu, 19 Oct 2023 10:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697737502; x=1698342302; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=qg+otgUOPQR+8G/4uV/TUAnZUyW51Jn+plgzCktzBuA=; b=XDrru/ApZi0UXweUD7gr35ntg23Lt6QbrC+gaMYzlj6SB+gYOAjz3t7R5ockw+MHY5 nAI8oYvVYUrtmsr7HZwamZqKxvQqafGaVIb0TBm9XjC5nGmARMH2nIyJL/D9g1OERy2K 2qlHmwyJ01x9qs5JsEZlpmr7+T05U7DMFoySaqPshFPCbwRuKld6h/hDhCGLtYHvuafi To94gucsbTQwVuDc6Q3VzoDuh92fNEzpiGUAFO3ti0fBGfIA/d+ECCCbs2vGNZXXiNvM j9q9D5SlqVSP2b3IJJYv4SNXHZGOgdTOnAXFMwmbZcFIHf7guo/8duT4QwWtp6qXC0GJ xZ6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697737502; x=1698342302; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=qg+otgUOPQR+8G/4uV/TUAnZUyW51Jn+plgzCktzBuA=; b=GODQyz9wfuFjxuDe+9LQ+c0fab1JJmdTkrxRpzAka3qPa9ugLlBIvTLvNHSk703FUB vrdtDDsXcDzdNvoOfqsAbCbSNlhOFXCi1VNB0UIJDVibAIAM+kiuy8UWtg+hDe7XBtzS itryND1TqFOQ4M2dwlw68PICGz0/9jGfzNBjqb9pYhsyzcPgeM7kARQrMW2Tk/FETqlf slQZ/WF/fWPqU4kiA+jL8KvkqBSS779ZlzKdMbit7+U8AgAQ4hXyltlZiqeCZRZij4JY 1H6lSIwENs7169jGYoFzw82/quDpTabmB7I2QF/QiPJYE0RspP7joIJJU3EUKWL6QCg0 +37g== X-Gm-Message-State: AOJu0Yx9RKKvQG5Rr6QQkG0Vxrrwj77C3NnrIdKEl9Kw/V8a8/LL3Et9 aStT24i6tQ/q2K7FfbcNoNkZjcSt2KjHZNmO+g== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a4a:6c15:0:b0:581:f8d7:e4af with SMTP id q21-20020a4a6c15000000b00581f8d7e4afmr1090598ooc.0.1697737502309; Thu, 19 Oct 2023 10:45:02 -0700 (PDT) Date: Thu, 19 Oct 2023 17:44:59 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIABtrMWUC/6WOQQ6CMBBFr0K6dgytRsSV9zAsoExhktqSadNKC He3cgWX7y3++5sIyIRBPKpNMCYK5F0BdaqEnns3IdBYWKhaXWQtGwiRnV5WGJkScgCHETIxWgw ByEW0QNlmMgQmwzhMoEGaa2vqerj3CkVZXhgNfY7qqys8U4ie1+NEkj/7Xy9JkDCYW4u6GeXQN s/J+8niWfu36PZ9/wL0GBhH9wAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697737501; l=2408; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=+j1ZR4eOwaN2eWhtI6Or7popX8JK/RP2CN1CNyJtMuM=; b=BJyGQKERL2LGGUnreMt73sxdVT2rdOk9iwAulRF+/ouCnd05D/W3ZTM6a5zobWDvA04d1pUyB RMDmJtVuIm/DdGrXlkpaGZ8jYNcg5qsjcAjsQrDmYemRAMmAxa9iYGi X-Mailer: b4 0.12.3 Message-ID: <20231019-strncpy-drivers-net-wireless-intel-iwlwifi-fw-dbg-c-v2-1-179b211a374b@google.com> Subject: [PATCH v2] wifi: iwlwifi: fw: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: Gregory Greenman , Kalle Valo Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Content-Type: text/plain; charset="utf-8" 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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 19 Oct 2023 10:45:45 -0700 (PDT) strncpy() is deprecated for use on NUL-terminated destination strings [1] and as such we should prefer more robust and less ambiguous string interfaces. Based on the deliberate `sizeof(dest) ... - 1` pattern we can see that both dump_info->dev_human_readable and dump_info->bus_human_readable are intended to be NUL-terminated. Moreover, since this seems to cross the file boundary let's NUL-pad to ensure no behavior change. strscpy_pad() covers both the NUL-termination and NUL-padding, let's use it. 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 --- Changes in v2: - prefer strscpy_pad (thanks Kees) - Link to v1: https://lore.kernel.org/r/20231017-strncpy-drivers-net-wireless-intel-iwlwifi-fw-dbg-c-v1-1-bf69ec7d1b97@google.com --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/net/wireless/intel/iwlwifi/fw/dbg.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c index 3ab6a68f1e9f..7aa282592cdc 100644 --- a/drivers/net/wireless/intel/iwlwifi/fw/dbg.c +++ b/drivers/net/wireless/intel/iwlwifi/fw/dbg.c @@ -880,10 +880,10 @@ iwl_fw_error_dump_file(struct iwl_fw_runtime *fwrt, cpu_to_le32(fwrt->trans->hw_rev_step); memcpy(dump_info->fw_human_readable, fwrt->fw->human_readable, sizeof(dump_info->fw_human_readable)); - strncpy(dump_info->dev_human_readable, fwrt->trans->name, - sizeof(dump_info->dev_human_readable) - 1); - strncpy(dump_info->bus_human_readable, fwrt->dev->bus->name, - sizeof(dump_info->bus_human_readable) - 1); + strscpy_pad(dump_info->dev_human_readable, fwrt->trans->name, + sizeof(dump_info->dev_human_readable)); + strscpy_pad(dump_info->bus_human_readable, fwrt->dev->bus->name, + sizeof(dump_info->bus_human_readable)); dump_info->num_of_lmacs = fwrt->smem_cfg.num_lmacs; dump_info->lmac_err_id[0] = cpu_to_le32(fwrt->dump.lmac_err_id[0]); --- base-commit: 58720809f52779dc0f08e53e54b014209d13eebb change-id: 20231017-strncpy-drivers-net-wireless-intel-iwlwifi-fw-dbg-c-1f49f00b8a2e Best regards, -- Justin Stitt