Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3416117rdg; Tue, 17 Oct 2023 14:12:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEa/TdPSa8hRnlUR7+uudKi1NTaydaGk8eY6cRPNyY5kCb+Fe/XYBY6aC5w3hQi7bFHI1LC X-Received: by 2002:a17:902:e5cb:b0:1ca:200b:8dce with SMTP id u11-20020a170902e5cb00b001ca200b8dcemr3812573plf.41.1697577159009; Tue, 17 Oct 2023 14:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697577158; cv=none; d=google.com; s=arc-20160816; b=KLhDZRq5EugmuV68G/922TNLT/nvfrvYsHoud0Ym84CTBvBR+S088CUy90MHOMKM/e y7YWyVumEUrL4k96MPmob6AGbcde/rH5oQhLdsynMEemEaIAODa3LSYfMzDGh+pK5FCq RDxPDfCvGz0MdIfQTBvk4KBqdXUqtybSYflSzfz45Z7ii9LMhrU6o4IW/0HOa+CxYKXh 4a8HJVg1ulYqnFbSjPWExBjFpJYCf1g5folVGYtSM9PLS2T9lpJk6yd+3tKMKI+o/oJn lxkUtFYwI/mQs1anCAY/vtrIgfhBedI4C7Cc7GoIGqWfUODgN770VhxaFQgqc1Hdc1PR BXkw== 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=QXzsHVghZ/vMgKxfKM1dzjkgTQebO8rvy+/S6SScf3k=; fh=JWAO1fAe+Wf5O2DamUx86WOaLpB0s7CTfUExwjP/ICk=; b=PLNGUlWIypzzeUnZEvTalymG1RYzcnCZgEapEMMJIVQjI5cJOAEUceR1UuVkGKZMBI 2FBytd+cpeZvL/kaM15fvsGlf1wKNBhePUNz+uV70lksopLOX/RvZ1Mha6SrFhL2+acW 5rKFnYXF9ZZT5d1ZmvusI4eJhMk3zzJvRJQ0a+1SH0Ml//tNCtyl+Oy5qaxjKWBEa/mk xtH/Q7N4EcaAlYdLwqkAHfpp1K2N0a8a4NgD8Qo2RXusmz9XWNg1FiZZeabZ4pgRCm/T pAeZ3kx4aEo8WssaS7xmUgLlgydD1C9VBJ3JtLc/NtYXKNm4U4kUuazN4CsGU9BPSp4e x7hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="R8PcU1W/"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id l12-20020a170902d34c00b001b81fe65fa3si2402566plk.569.2023.10.17.14.12.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 14:12:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="R8PcU1W/"; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 0841A80E068E; Tue, 17 Oct 2023 14:12:38 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343507AbjJQVMf (ORCPT + 52 others); Tue, 17 Oct 2023 17:12:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231868AbjJQVMe (ORCPT ); Tue, 17 Oct 2023 17:12:34 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7526D9F for ; Tue, 17 Oct 2023 14:12:31 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7af69a4baso94019357b3.0 for ; Tue, 17 Oct 2023 14:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697577150; x=1698181950; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=QXzsHVghZ/vMgKxfKM1dzjkgTQebO8rvy+/S6SScf3k=; b=R8PcU1W/5S6bkm52VpK5VdZMnRhqeBQROS+TV0xwjTr3e5M8njGi0/o/xDNUgFSb7f tCbuWaUyV1DcwjlSSEX4Td/o7Z6dIJFzoN0EFoAD3EsjH9mFR/ZIbQAWZWBgTub09g64 uBFlugYflg80KZjjhQz1p6Fa3WsFRaZJio8kUums336YvMxizo9Lv6gltosa/ZO/JLaI 1sIVidDOS/jisgt2f5VUqDg+OOPVgrS18BvURi/zCx2MKNvWu9HwNFrtQmvUFkbNhoGi h/9KG9c4Nb7oD96XogqxK8WmyQAbBue/Q6yvvbxKaZlJUwzYRs9QUOaUycYrfTp7K3FR Skog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697577150; x=1698181950; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=QXzsHVghZ/vMgKxfKM1dzjkgTQebO8rvy+/S6SScf3k=; b=ai4d4fWUg+JTKRGCGqGlc7v4yfDFXZ98hw3NCHteC7PJqNeLT9q629yDyCGikMrO+d SZ105gUSRVV3jP+Pitb9ialFRSHbh960QCn6iAmqeeGz6HUSkhAoyuK57UfdH/FXHe+N aGWb9Pk7YCKE1W+eqPYvUcACdpaGtxNo5pFu6BaiJ64g4PzPedFNLtKDdAMegCkiu8sP u20XJtSmv0DbIdv4bKnqEAsrYLD8ytXtrzG0QRDLum3YWle3m9GhzOTyF3eTu415WGn2 qwpmNHInwnxB1O1O9qdQu3jAGlyHZpoa06BJmcEL3u7ug1ikXOtjR5QTj/FiYO1jDcE7 Ek8g== X-Gm-Message-State: AOJu0YwTXXMtpwQG+jv6Ytnc+8ta2mUTuzcfq5DL6rQuwUwEqXKSZgFZ RHVeOq2v8gKGW6Y+2n7cB4LDRjhhSx9us6RqDg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:b118:0:b0:d9a:6b49:433d with SMTP id g24-20020a25b118000000b00d9a6b49433dmr61099ybj.6.1697577150758; Tue, 17 Oct 2023 14:12:30 -0700 (PDT) Date: Tue, 17 Oct 2023 21:12:30 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAL34LmUC/x3NQQrCQAxG4auUrA1kKip6FXExZH41IDMlKVUpv buDy2/z3koBNwRdhpUci4W12pF2A+kz1wfYSjeNMu6TpBPH7FWnLxe3BR5cMfPbHC9EsFpo42z eWLnIWYscRPIR1HuT426f/+t627YfhUfv7HsAAAA= X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697577149; l=2545; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=iByoXcEl+/fTj7qfxJpQSjCOu1SG80zw46SDN1JdAVA=; b=422phc1KfoxKuZOVw01uw/lgnVEOwbLB9bZNBj3xD+nmrWlmWo1VFxb4TdilgcB/yQ/FizVWk oopegqE63ZDB+soiysSjOYI6D+ByXbd4dx2ld1FM64ecTwR85Ll2K55 X-Mailer: b4 0.12.3 Message-ID: <20231017-strncpy-drivers-net-wireless-cisco-airo-c-v1-1-e34d5b3b7e37@google.com> Subject: [PATCH] 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=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Tue, 17 Oct 2023 14:12:38 -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. Technically, we can now copy one less byte into `extra` as we cannot determine the sizeof `extra` at compile time and the hard-coded value of 16 means that strscpy_pad() will automatically truncate and set the byte at offset 15 to NUL. However, the current code manually sets a NUL-byte at offset 16. If this is an issue, the solution is to change the hard-coded magic number to 17 instead of 16. I didn't do this in this patch because a hard-coded 17 seems bad (even more so than 16). 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 --- 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..8cfb1de5933e 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, 16); dwrq->length = strlen(extra); return 0; --- base-commit: 58720809f52779dc0f08e53e54b014209d13eebb change-id: 20231017-strncpy-drivers-net-wireless-cisco-airo-c-d09cd0500a6e Best regards, -- Justin Stitt