From patchwork Wed Oct 18 21:15:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Stitt X-Patchwork-Id: 736188 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C33C6CDB483 for ; Wed, 18 Oct 2023 21:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231894AbjJRVP3 (ORCPT ); Wed, 18 Oct 2023 17:15:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230119AbjJRVP1 (ORCPT ); Wed, 18 Oct 2023 17:15:27 -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 575BB115 for ; Wed, 18 Oct 2023 14:15:24 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d9cad450d5fso273243276.1 for ; Wed, 18 Oct 2023 14:15:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1697663723; x=1698268523; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=DWFdITK9FYnC6ndQyLKptFhv/4XAT9ljqHM/fNT7TZM=; b=OHA9bpChmrzhXQ0BWjrKQKkp/9+hMPyiDE8UJgC4rg8W7Lnu2OQadEKaLF9ebIptmv 6WPZif1jBHClBCzQMsj0tYvPwZ3I+ZEeqAWtwjp8pA93esxzXYkhGYu5jMaRfI4AjOKr E7M3WLQiho9dRH8XeN5xS7t+sjMdKUvFLdaNsa6KasV629qTboz1II3Dpi+oYP8ech/t sPlJvjdwXJRteDxEbO3D7Vk5GX/beZFZE1ewC2oAfhweZKOGhp3iogi8LCLWR2qiuzZH Atics1pSevmExBk0TkkVxzU2IWWprGyBlxnAqyFuQhy3Q0gipUDHV+b3hvw+od3wrtkm d16w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697663723; x=1698268523; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=DWFdITK9FYnC6ndQyLKptFhv/4XAT9ljqHM/fNT7TZM=; b=KBjzuEd6Jk+MdDUrwLJ+OHUbd9dl/PsnWuwCfnpeScHSMm2uGQvZudAaMj5n4MFCXM xfe6F237LA0duzly2mdTW0n71ysMM6+rX4KAtfeeukdf4mG4iIb8eZDIcYwOifq1RKuB DixgRswATxr1chcYyTLxAcw7KSBPHFsdPdZNEQ1whQUL+dTwyPPzcfLLW/+pkbQcAcL3 Xbz7nOrwfu8jpyOYNnM4OWYKI92r90pe2GubovTPBfK+FnB/V6shlMoIw4H6nkmx41St 96MVfeRXKDRL4RnaJMQvWZFH+pTuxZx7SSw4ZpcdwvB7sdc15hhkjkodjwWyZ46fLFiB JvZg== X-Gm-Message-State: AOJu0YwmPVaKUpmrPNQ7FisGEXdRUWxHjyB3VovJgndeTKCW1KtNJi3U kbC1Y1V93SVKda4wo9SHjjdFrpjXHtMDfKqTJg== X-Google-Smtp-Source: AGHT+IE98FBPpehxuSmAoDMMyrPO6eIxEf9m+v4GafxR/P68phKpdYLKbL9enPw6AIvI9BgsiyIo3/p7t7gXzQzvYg== X-Received: from jstitt-linux1.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:23b5]) (user=justinstitt job=sendgmr) by 2002:a25:4215:0:b0:d9a:47ea:69a5 with SMTP id p21-20020a254215000000b00d9a47ea69a5mr13155yba.1.1697663723500; Wed, 18 Oct 2023 14:15:23 -0700 (PDT) Date: Wed, 18 Oct 2023 21:15:23 +0000 Mime-Version: 1.0 X-B4-Tracking: v=1; b=H4sIAOpKMGUC/52NQQ6CMBBFr0K6dgxTghJX3sOwqO0Ik0BLpk2RE O5u9Qgu30/+e7uKJExR3apdCWWOHHwBfaqUHY0fCNgVVrrWDdZ4hZjE22UDJ5xJInhKsLLQRDF CYlgn1C3CbNiDhctTO9MhWWucKs5F6MXvX+/RFx45piDbL5/xu/5byggIjWltuXeamvY+hDBMd LZhVv1xHB9Bi0CG6wAAAA== X-Developer-Key: i=justinstitt@google.com; a=ed25519; pk=tC3hNkJQTpNX/gLKxTNQKDmiQl6QjBNCGKJINqAdJsE= X-Developer-Signature: v=1; a=ed25519-sha256; t=1697663722; l=2913; i=justinstitt@google.com; s=20230717; h=from:subject:message-id; bh=yDbQL0fT5ECag/Hfa0melicYIqMQ//3xY2/rpNFfZOo=; b=iw2u/dbT5NFr1oMNr8mHNhtfVVlrHVDEyj+xyEAXaQhj7NdVCgY6R2c/BwjBfl2BSF93w/vCD qIz4P8kmKrDDoiAx7rQaljqwJ7AqZn07VHLp/I67Ngu6B4/Hxt+OECV X-Mailer: b4 0.12.3 Message-ID: <20231018-strncpy-drivers-net-wireless-ti-wl1251-main-c-v2-1-67b63dfcb1b8@google.com> Subject: [PATCH v2] wifi: wl1251: replace deprecated strncpy with strscpy From: Justin Stitt To: Kalle Valo Cc: linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org, Justin Stitt Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 other assignments of similar fw_version fields we can see that NUL-termination is required but not NUL-padding: ethernet/intel/ixgbe/ixgbe_ethtool.c 1111: strscpy(drvinfo->fw_version, adapter->eeprom_id, 1112: sizeof(drvinfo->fw_version)); ethernet/intel/igc/igc_ethtool.c 147: scnprintf(adapter->fw_version, 148: sizeof(adapter->fw_version), 153: strscpy(drvinfo->fw_version, adapter->fw_version, 154: sizeof(drvinfo->fw_version)); wireless/broadcom/brcm80211/brcmfmac/core.c 569: strscpy(info->fw_version, drvr->fwver, sizeof(info->fw_version)); wireless/broadcom/brcm80211/brcmsmac/main.c 7867: snprintf(wlc->wiphy->fw_version, 7868: sizeof(wlc->wiphy->fw_version), "%u.%u", rev, patch); wireless/broadcom/b43legacy/main.c 1765: snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "%u.%u", wireless/broadcom/b43/main.c 2730: snprintf(wiphy->fw_version, sizeof(wiphy->fw_version), "%u.%u", wireless/intel/iwlwifi/dvm/main.c 1465: snprintf(priv->hw->wiphy->fw_version, 1466: sizeof(priv->hw->wiphy->fw_version), wireless/intel/ipw2x00/ipw2100.c 5905: snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s", A suitable replacement is `strscpy` due to the fact that it guarantees NUL-termination on the destination buffer without unnecessarily NUL-padding. 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 Reviewed-by: Kees Cook --- Changes in v2: - fix subject (thanks Jeff) - Link to v1: https://lore.kernel.org/r/20231017-strncpy-drivers-net-wireless-ti-wl1251-main-c-v1-1-3a5c02382e35@google.com --- Note: build-tested only. Found with: $ rg "strncpy\(" --- drivers/net/wireless/ti/wl1251/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: 58720809f52779dc0f08e53e54b014209d13eebb change-id: 20231017-strncpy-drivers-net-wireless-ti-wl1251-main-c-6b2da81eccad Best regards, -- Justin Stitt diff --git a/drivers/net/wireless/ti/wl1251/main.c b/drivers/net/wireless/ti/wl1251/main.c index eded284af600..cd9a41f59f32 100644 --- a/drivers/net/wireless/ti/wl1251/main.c +++ b/drivers/net/wireless/ti/wl1251/main.c @@ -404,7 +404,7 @@ static int wl1251_op_start(struct ieee80211_hw *hw) /* update hw/fw version info in wiphy struct */ wiphy->hw_version = wl->chip_id; - strncpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version)); + strscpy(wiphy->fw_version, wl->fw_ver, sizeof(wiphy->fw_version)); out: if (ret < 0)