Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp1212548rdg; Fri, 13 Oct 2023 13:53:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHcQBYaRx+yONIKEK9iv/kdPJjtmyAo3LfDH43FHdgHqunCTAGuur6+uV6MSoy7H7/KxLJ9 X-Received: by 2002:a05:6e02:d03:b0:351:5a77:f169 with SMTP id g3-20020a056e020d0300b003515a77f169mr28428466ilj.29.1697230424655; Fri, 13 Oct 2023 13:53:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697230424; cv=none; d=google.com; s=arc-20160816; b=Swq6qixXW2DJ09e8/FCiNvInBKxlk6EL+dO8teHJQCyd0mhQs0qBslPSmZraD4ojKa v5ctRi99/De3YKDyc1u8+fyvTbyY0jxOETFQk53XDZz9NRGiFC7x2VVeEjn8Xg6kzUJ8 pM2aqR2Wn91dGNp1g3FDHpgMjCjN+X/fsMZB4RSepEwENUZxYVWfHyjNM38m4nBra1yV Ib2wWdMk77sjbG9mfjvXrEaYbYMiMbHsunXRRW++iTXrY3uehPW6wDO5Vzgj0Op69Fgp jJNp3fCvh8ZYXvQMVbhBahrm2ZM9TnGr28HCmPsdNb6lio4I0gQhrypQoVbSraMfdmeN qv1A== 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=OzZl4+HNDCRg4UbOKbkT7uBUITuj6sL+WIkS7NUKeRU=; fh=o7SX2WdgIox4WVsDDV12JlFeV4rJMXM7xozTvpwPFL0=; b=oAz7FoknYflebha5pwLAkUAwMWcey2RBwyY8woNxuiBkd07S+wGdx99B5FP2TD+Myb 4CoJpX2/qLuOFHhSRQYK1to0mTyyo4RyTWKO25sq7mSpHx0VtkDcoeAdh4FhheiWoRt3 ltjJwK28OhmKAZJVA08gM4XEZnUkX47DPnP8cAe504u0xgG7gexA4h8UlYO3x8PMO0R/ 21FsjrBKWi3WfKoXHJJdDzYRre2HOWYKuJuABYQroAphUMO3HR2S5+4vj1UZPjVgx/Rj +y3lddtWwUq6eeN5bRccd3udn9E5nkHpuNPW24J8vUD60VNDsKobjWDh7gCV0DjF4tJC jz8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=VFS9rzlm; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id cn11-20020a056a00340b00b0068c01fba736si17462178pfb.301.2023.10.13.13.53.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Oct 2023 13:53:44 -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=@google.com header.s=20230601 header.b=VFS9rzlm; 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=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 63D718038915; Fri, 13 Oct 2023 13:53:39 -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 S231788AbjJMUxi (ORCPT + 51 others); Fri, 13 Oct 2023 16:53:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229958AbjJMUxh (ORCPT ); Fri, 13 Oct 2023 16:53:37 -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 B3872BE for ; Fri, 13 Oct 2023 13:53:34 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a7c4e10594so39315077b3.1 for ; Fri, 13 Oct 2023 13:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697230414; x=1697835214; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=OzZl4+HNDCRg4UbOKbkT7uBUITuj6sL+WIkS7NUKeRU=; b=VFS9rzlmbYywzA+6iwwLGKwQrfyVafuWixsnnz88rIowp1FR2GwcNYnh87iT9MFtf3 s3Z0ZsyepACmEG6LZD1+DceH6NBaOGb1mbSJwKRNigyolIlKNP1Kk20CTDr21yat3C0B XMjpEq+Ep68MIKYnSlYWFhManYhg4yratCd26dzH77DWz4DdfC7htsA00XNGAbvy/FLR neL6QIeF3XSqWHXR/cwUCl9H55EeIwQ7kZxJwA+Bbs2XtqkM7oMYxAO6keaRIEaWvVuM BULlKvRNS9xaxCJ6et2hZmAuvp3GhUt/8EHjl8pjyEgDOzMJcCAf+7yMzsQ7eFUtoXgV Ii3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697230414; x=1697835214; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=OzZl4+HNDCRg4UbOKbkT7uBUITuj6sL+WIkS7NUKeRU=; b=lNCX8c48LQmgNK5it425a48vE0BQoi+Jq3fBq5VvJvLUOwAVBJRsLKnsnEgbtA2CV0 Db/rTgG5nmMzwo1pl7r37XCbuI+HVqkRUPlzeBTcJagVyzQxHgI77N4mxLB7aHRh8944 Rq7q2eHDe0HgPIhbKy3FrwPZeQ1Pu8GYzoCL7yzoY8IDV/wYerT3KqgERhx4NCCnL3nB 15DlWu1QLJdWKSwGRijVcIHapbRAwy3c5cN0Q+8DpWu3GYgxitP3+wOS1iFgAIr6xOeQ 9gpIxfTE+JMFqVbL8b86A5/ZeHYROl5TOz8IEwtUv/BmgXnUpOV32uhkGCIREVf71zrh ++4Q== X-Gm-Message-State: AOJu0YwD6xWXWr7IJkfBFqWtCYA+Wk4Ww73O4dU/w+THk29osrhxsqja KYjD4MDDenVgHrYIKpOPTAogZzirepqy1CFRjg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a81:a150:0:b0:5a8:28be:bf86 with SMTP id y77-20020a81a150000000b005a828bebf86mr62498ywg.5.1697230413988; Fri, 13 Oct 2023 13:53:33 -0700 (PDT) Date: Fri, 13 Oct 2023 20:53:33 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAEyuKWUC/x2NzQ6CMBAGX4Xs2U1oi/HnVYwHaD9lI6lkt0EN4 d2tHuYwl5mVDCowOjcrKRYxeeYqbtdQHPt8B0uqTr71wbUusBXNcf5wUlmgxhmFX6KYYMZ9GX/ sHzwhcWTnu+MhAqcwgGpyVtzk/d9drtv2BccyB/Z+AAAA X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697230412; l=2121; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=AwGkauBF747GZlKSLUDSAGULd+jPXO4eamh/1mrnOow=; b=jbmxFb3nNGqErXN238ktXtN+UHQuPKfn2bj7BMuyW8p3jYgRrpqT8otgeIeuvlOaf5YY2ER3u gfPL8Fjoz8sDgfubNhmKQ4vUxROcTIYlWSY6BhbY42kdlqtcmZbo5a/ X-Mailer: b4 0.12.3 Message-ID: <20231013-strncpy-drivers-net-wireless-ath-ath5k-led-c-v1-1-3acb0b5a21f2@google.com> Subject: [PATCH] ath5k: replace deprecated strncpy with strscpy From: Justin Stitt To: Jiri Slaby , Nick Kossifidis , Luis Chamberlain , 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 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]); Fri, 13 Oct 2023 13:53:39 -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. We expect led->name to be NUL-terminated based on the presence of a manual NUL-byte assignment. This NUL-byte assignment was added in Commit daf9669bea30aa22 ("ath5k: ensure led name is null terminated"). If strscpy() had existed and had been used back when this code was written then potential bugs and the need to manually NUL-terminate could have been avoided. Since we now have the technology, let's use it :) Considering the above, a suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. If NUL-padding is required let's opt for strscpy_pad(). Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] 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/ath/ath5k/led.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/net/wireless/ath/ath5k/led.c b/drivers/net/wireless/ath/ath5k/led.c index 33e9928af363..439052984796 100644 --- a/drivers/net/wireless/ath/ath5k/led.c +++ b/drivers/net/wireless/ath/ath5k/led.c @@ -131,8 +131,7 @@ ath5k_register_led(struct ath5k_hw *ah, struct ath5k_led *led, int err; led->ah = ah; - strncpy(led->name, name, sizeof(led->name)); - led->name[sizeof(led->name)-1] = 0; + strscpy(led->name, name, sizeof(led->name)); led->led_dev.name = led->name; led->led_dev.default_trigger = trigger; led->led_dev.brightness_set = ath5k_led_brightness_set; --- base-commit: cbf3a2cb156a2c911d8f38d8247814b4c07f49a2 change-id: 20231013-strncpy-drivers-net-wireless-ath-ath5k-led-c-12487cee93be Best regards, -- Justin Stitt