Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp2049724rdb; Mon, 9 Oct 2023 10:46:00 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+Z2lhtFJChY2gxB2vrupyXJ6f6xzGRVvp8HMcCxnxmXIXFjD6JFttgPikBdxDGhgL7kc/ X-Received: by 2002:a05:6a20:3d11:b0:16b:d137:de59 with SMTP id y17-20020a056a203d1100b0016bd137de59mr11187367pzi.28.1696873560044; Mon, 09 Oct 2023 10:46:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696873560; cv=none; d=google.com; s=arc-20160816; b=q2wHTL0nQIIcBjcEB9WzhEoyDz62+SvLly5rHyS/hccGYdFVA+X8/Gp9pp8nJiPTfW 498CcM/loZL/p5tK5k7vfmO0/btyD7BmROVxqgm+VquM22ibscWSRKSnrvHjdV3aiu/Q DFfAZBeYfDDvNapzazIKj8NPcfWoJ2pc/mLm2D72+7WV85UBD/r27VTpP81GBBu2qC8X pgO3XvKyaYvNpe1OmT/FKgKRBnJ+fOLV73+YHOxi5XBruFKrwjagOpkb8eRWvCNBqcIb liLyzgwysIdEqr9lGeXTyHj6gc29onqgmJnd5oSf7azKdTenm4ayWRad99GCgLm77kzl l73Q== 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=TJMcbXJ00xamkrBTzx3uHhqhQOKa6l6LGEaEK6gyhss=; fh=tpgR3Q6rr4pg1VcfCzi1hRJf4qvNknLFuIKl8Dy7+y8=; b=Lw9dHTGG1OtnCffLunYtpnT2XQfn18JcefEFnO328tfyVXOhuDwDoqaCgppZ6FIgb2 mBmBsPzNSkAgdQ3VXYrlgNjU1outcE3Ul4syiLco/8ONl0cScJtX+7LG84dsL2u/l9lk QlGYYx2agq6EFpjm/M0cYXgEUvViKqIZQ1eaX0M0+A0JFBxP3cThtJSBj+iC4wgWMZZ6 Qv7Y2mDkewcDEzSz4rzm0LoQ5IxEUVpZuCZRzkiFMnxVQqBYiVI6vY23kG8Dkmnl8K6m f0s+abAqKw4PjKfeJ079gH9N80RP4bVF+ohqaPh+kMEEdKkYAuEDV9q/SP6o/3uNdu2e wCgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KT+JLvte; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id p26-20020a056a0026da00b006930471d220si7291507pfw.397.2023.10.09.10.45.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 10:46:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KT+JLvte; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-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 lipwig.vger.email (Postfix) with ESMTP id 6D8B18039FC6; Mon, 9 Oct 2023 10:45:56 -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 S1346645AbjJIRpl (ORCPT + 99 others); Mon, 9 Oct 2023 13:45:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346640AbjJIRpg (ORCPT ); Mon, 9 Oct 2023 13:45:36 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E39EAF for ; Mon, 9 Oct 2023 10:45:35 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81646fcf3eso6485042276.0 for ; Mon, 09 Oct 2023 10:45:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696873534; x=1697478334; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=TJMcbXJ00xamkrBTzx3uHhqhQOKa6l6LGEaEK6gyhss=; b=KT+JLvtewnJlVx6OvCmKEA4L4q4pZMBpxbZ5bWzJJ+d0KoCUK9OFXYGqzs6N6uB9bw nLzQhLLIACr+UiTRwAsQ2exQ7cOmYKaDC1K4SqcWohJ37Djq8yhwTxDYxuaXzfEegBT5 BT77cwyfVO32xjMahyf4P+aRMZwmTjkkZogYVRADWyjuDKFc7YOfcsSONslVNkK/boz3 NKWj67Kon4tFohtbn8FRoTxo4RsebK7flcdQB0Z1nQX+oft23DSsjnEp2Pa70Cipekgu V2p0vumlHZR5Raal+1QL9MYZdiPi+DBZ3l0iF4Np/YPXhImCWSyjd0Y1dFlD0GnqCcRU drjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696873534; x=1697478334; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=TJMcbXJ00xamkrBTzx3uHhqhQOKa6l6LGEaEK6gyhss=; b=LVnS0b5TRzDTL+jPnpj5UZ4aBPLgzQDJ5LeR4w5kvPZ2vfQqSI0DqXYo7X1Gb8f5Ur tipd/o//al0lCcxHYNg/yAV3m6/kqxjiavqdFbqlMIogUO0noVtnrKBUEHxo3I61c3U8 06wYFlYTR3qkgHUpikhqu3ySBkb4z79ya7RtyadPsTxpOmkekq37xH2SUfVwJiuT3Fm8 pxgzmS5jkEpUZGEigqAL7A3UrM1nO5xuqKgvRWpy/rNa1MsduPatC0yVnPgJ27yNx6Fh NxTEfJgd0Qed1ZUbow87CNXM+QbXCg5vtavT5JsG6dGBk2ubHdeltjnuynXO9euatK1O 6aOA== X-Gm-Message-State: AOJu0Yz9GmQvpoDjhmhYygEfeX79gkjqlGTLjEuHvHypF1YMtxzcHNlQ Tn1dUFt0Wkt3uufoGoxrgOpR848ERLEaNbP03Q== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:870c:0:b0:d9a:3a25:36df with SMTP id a12-20020a25870c000000b00d9a3a2536dfmr30004ybl.8.1696873534723; Mon, 09 Oct 2023 10:45:34 -0700 (PDT) Date: Mon, 09 Oct 2023 17:45:33 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIADw8JGUC/6WOTQrCMBSEryJZ+yQ/WKIr7yFF0uSlDWhSXkKwl N7dtFdwN98s5puVZaSAmd1PKyOsIYcUG8jzidnJxBEhuMZMcqkE51fIhaKdF3AUKlKGiAWwTEh 7GChZ4xCGaGDw5hWSBQud9kLdus4rrVkbngl9+B7SZ994CrkkWo4PVeztX7oqQIB23ikupDLeP saUxjdebPqwftu2H8zbCaf1AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1696873533; l=2189; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=rM6KAt4nKSyIu5CIGMNGinHf3GlvjCeWH2JRJ+yYScw=; b=ya5WEHsKhKCZkEYwZpdgLyCPQhj6xLpDZPA5Qoa8ZjOcAvJXnXWyQJeSdlHbEnKh5PRgBQqhc LK7JbgGgbHhA8Za1Q1yBDoVGJwxeVsoaMSXxxhjeEN/x057SZY0u9ui X-Mailer: b4 0.12.3 Message-ID: <20231009-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-v2-1-78e0f47985d3@google.com> Subject: [PATCH v2] bna: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: Rasesh Mody , Sudarsana Kalluru , GR-Linux-NIC-Dev@marvell.com, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@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=-4.8 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL autolearn=no 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-kernel@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, 09 Oct 2023 10:45:56 -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. bfa_ioc_get_adapter_manufacturer() simply copies a string literal into `manufacturer`. Another implementation of bfa_ioc_get_adapter_manufacturer() from drivers/scsi/bfa/bfa_ioc.c uses memset + strscpy: | void | bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer) | { | memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN); | strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); | } Let's use `strscpy_pad` to eliminate some redundant work while still NUL-terminating and NUL-padding the destination buffer. 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: - don't use sizeof on ptr (thanks Kees) - strscpy -> strscpy_pad (thanks Kees) - change subject line + commit msg to reflect above - Link to v1: https://lore.kernel.org/r/20231005-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-v1-1-8dfd30123afc@google.com --- Note: build-tested only. --- drivers/net/ethernet/brocade/bna/bfa_ioc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/brocade/bna/bfa_ioc.c b/drivers/net/ethernet/brocade/bna/bfa_ioc.c index b07522ac3e74..9c80ab07a735 100644 --- a/drivers/net/ethernet/brocade/bna/bfa_ioc.c +++ b/drivers/net/ethernet/brocade/bna/bfa_ioc.c @@ -2839,7 +2839,7 @@ bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver) static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer) { - strncpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); + strscpy_pad(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); } static void --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231005-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-68f13966f388 Best regards, -- Justin Stitt