Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp787674rdh; Thu, 26 Oct 2023 16:19:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHV5/5hG+xconWTcOXIGCEXI3mpnVJfJk+/eLcO7/+yzsdzT42iwi+Pi6GjV6WpvhzGd89d X-Received: by 2002:a0d:d846:0:b0:5af:abe1:3d4b with SMTP id a67-20020a0dd846000000b005afabe13d4bmr467981ywe.5.1698362372763; Thu, 26 Oct 2023 16:19:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698362372; cv=none; d=google.com; s=arc-20160816; b=RXlZnF+sdtmGBBBjo3LMd951z7FHhwr3GakFFg3osbddxzsDec9oGLCimJsmz+lrFh Bg917jtguEkYShvNCYhXMJED0OPfLOe4rKM97IsyARd1ko3N0gFTnllAgqiwfjy/jRs3 cN9wkjQadslJYsNvU9Hjukd+8g2enOwoHOu6AldvzYtzU8743wZnvljAOtqZZcL2NeZA H6JTQ8g45I4EWVz+IW57M2G01YF86B6I7j3MekbHdMaEztaoO5NcudoAsmWo1zyMRP2P lT0W57ydV48QJvJDcsuHNjdnMOBQTn3A56rr1CW5rTeE//545nydPqNCw+K6so2NCkyA u1/g== 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=rJUIaaq/oswhFA94o3ND9d9+Iexffy2MpltZ9TbSQQY=; fh=JWAO1fAe+Wf5O2DamUx86WOaLpB0s7CTfUExwjP/ICk=; b=C9szdpbxW3ViN3RvSQC2QpskzvJRtcmXYNOmNXVI0R6pYVl59RGkOLdjJs7ynFA58E 3WWSBzWasB2rE0veiDvaiq59eFQbhKrmLrFs2WZaTxmQGk+aOJA3N+s2jWRDdZewyRjK kTXCbkCrsnsLpOtXwI3PgJ6D6+gVJ2q+tXrcjPDJG6Var/xeYQUNXcrAZPokiMB6xfq1 njjR1RaqLX37nmdKmPIufs5w3FlRbKy6E6AUD7MJMi8Ewm0JJ1Yo1xQJcUo+a2lNA9Ad 3GyLDq/Vbp0PGoCGOqBUCLAIYOGX2Q9IZj149BKHYY9gobV9L5J8QHcOBNrh21X3kSQv T5dQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BC6d5eOU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id k4-20020a819304000000b005a7f768804asi603417ywg.349.2023.10.26.16.19.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 16:19:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=BC6d5eOU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.32 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 agentk.vger.email (Postfix) with ESMTP id 34F0381DDBE2; Thu, 26 Oct 2023 16:19:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345006AbjJZXTY (ORCPT + 52 others); Thu, 26 Oct 2023 19:19:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345001AbjJZXTW (ORCPT ); Thu, 26 Oct 2023 19:19:22 -0400 Received: from mail-oo1-xc4a.google.com (mail-oo1-xc4a.google.com [IPv6:2607:f8b0:4864:20::c4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB9941B9 for ; Thu, 26 Oct 2023 16:19:19 -0700 (PDT) Received: by mail-oo1-xc4a.google.com with SMTP id 006d021491bc7-581da174501so2327637eaf.2 for ; Thu, 26 Oct 2023 16:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1698362359; x=1698967159; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=rJUIaaq/oswhFA94o3ND9d9+Iexffy2MpltZ9TbSQQY=; b=BC6d5eOUbpZj2EhbDkCtoVPkarvXcccoL04DzKW8pl/jhqx1Q520C4Urca1Sko4OKp bavNq0XNv/2izUivQLIGWWR6M3faFCIa7rZ9ZBRM8mi8+aEFeTs5eNZzFR9nCX3wdkjF uThlr63OwueeAPgi/UTizMQ3P2jeEdcjoCj1Xo3+na26rAwqxQGfEgC9UtLPv3sarxqq v8LoUR9ZKTSAtLv0dBohaGBlqWXihME/P2Y9Mfis07mDh3MfCe8OfXfq2Zk1bk9hrAvQ sYWc9AEJeXa16H3UgQvsmPj+ARr2tgzjj9sTZ1AB+P6NQPJxhUWYKAFxA+HRDppn/Px8 KzNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698362359; x=1698967159; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rJUIaaq/oswhFA94o3ND9d9+Iexffy2MpltZ9TbSQQY=; b=X3LJBWE15+mRDOZACkiiyekzHwzeU8hMNUgui379houBkMkpYE9Ozt2MuRbnqqLtf7 mk9VTLkgy8tX0fgvbTyi7pOVWIr2U5c5n2e8s/h6rTMdA1A0JticDQk6N4MX/UN6JimX rZn1RwgXHgJf+Q/DO0ql51u561NOTDjK55T+KsuJRqUK/jvX/+EQGAjwaerg83Iq+pYp 4t/YpcDaucMan/Pyxejkq8HHB8MafFGgRjTUq5u8zdODX/5gdjXLrniuBLAemL9O5Pag kj1mzSUecaJVJTkB0fpGSg1HsyHzOkgSOmuZk2o6JZukBdPJyoujXOuaydU1ewiFsAXg Dv8g== X-Gm-Message-State: AOJu0Yz+e+8eEVSXoAykR+KCfGpbHzADEhyfg9sXj8/ygEhWDmkKupk9 MFJE2q2ZU7mhKxKWb1eeEFfwl52BFCD5NKMLRQ== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a4a:e658:0:b0:581:dbb1:219b with SMTP id q24-20020a4ae658000000b00581dbb1219bmr404827oot.0.1698362359119; Thu, 26 Oct 2023 16:19:19 -0700 (PDT) Date: Thu, 26 Oct 2023 23:19:18 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAPXzOmUC/53NQQ6CMBCF4auQrh3TUpHoinsYFtCOMAm2ZIZUC eHuVo7g8n+L921KkAlF3YtNMSYSiiFHeSqUG7swIJDPrUpdWqNNDbJwcPMKnikhCwRc4E2ME4q AI3EROuIIDry+Oa8rrbsrqvw3Mz7pc1iPNvdIskReDzqZ3/qPkgwYQHvxVW/7Gm3dDDEOE55df Kl23/cvKrGXxOMAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1698362358; l=2719; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=tC58vKAxLJm5cAdnZ9rYPmKDTa3guBZo7Oh8cfH/AXg=; b=xW/7pk2zSIdbdaANtOGtksyMjVeqD8M30IczBSFi365yP9f/D8GLqCR5vqlPF/2OcBvYQdmMr CAYKpl7GFTvD4/4vGd7LbAxPSijXKO8qWqRTUeMAOjbIl15/K3OHB/C X-Mailer: b4 0.12.3 Message-ID: <20231026-strncpy-drivers-net-wireless-cisco-airo-c-v2-1-413427249e47@google.com> Subject: [PATCH v2] airo: replace deprecated strncpy with strscpy_pad From: Justin Stitt To: 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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 26 Oct 2023 16:19:28 -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. `extra` is clearly supposed to be NUL-terminated which is evident by the manual NUL-byte assignment as well as its immediate usage with strlen(). Moreover, let's NUL-pad since there is deliberate effort (48 instances) made elsewhere to zero-out buffers in these getters and setters: 6050 | memset(local->config.nodeName, 0, sizeof(local->config.nodeName)); 6130 | memset(local->config.rates, 0, 8); 6139 | memset(local->config.rates, 0, 8); 6414 | memset(key.key, 0, MAX_KEY_SIZE); 6497 | memset(extra, 0, 16); (to be clear, strncpy also NUL-padded -- we are matching that behavior) 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. We can also replace the hard-coded size of "16" to IW_ESSID_MAX_SIZE because this function is a wext handler. In wext-core.c we have: static const struct iw_ioctl_description standard_ioctl[] = { ... [IW_IOCTL_IDX(SIOCGIWNICKN)] = { .header_type = IW_HEADER_TYPE_POINT, .token_size = 1, .max_tokens = IW_ESSID_MAX_SIZE, }, So the buffer size is (strangely) IW_ESSID_MAX_SIZE 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: - use IW_ESSID_MAX_SIZE (thanks Jeff, Kees) - Link to v1: https://lore.kernel.org/r/20231017-strncpy-drivers-net-wireless-cisco-airo-c-v1-1-e34d5b3b7e37@google.com --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/net/wireless/cisco/airo.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/wireless/cisco/airo.c b/drivers/net/wireless/cisco/airo.c index dbd13f7aa3e6..6a099642e854 100644 --- a/drivers/net/wireless/cisco/airo.c +++ b/drivers/net/wireless/cisco/airo.c @@ -6067,8 +6067,7 @@ static int airo_get_nick(struct net_device *dev, struct airo_info *local = dev->ml_priv; readConfigRid(local, 1); - strncpy(extra, local->config.nodeName, 16); - extra[16] = '\0'; + strscpy_pad(extra, local->config.nodeName, IW_ESSID_MAX_SIZE); dwrq->length = strlen(extra); return 0; --- base-commit: 58720809f52779dc0f08e53e54b014209d13eebb change-id: 20231017-strncpy-drivers-net-wireless-cisco-airo-c-d09cd0500a6e Best regards, -- Justin Stitt