Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp34768723rwd; Sun, 9 Jul 2023 20:14:27 -0700 (PDT) X-Google-Smtp-Source: APBJJlECFUgeLw6UW7dyTEibY4ohsVxfyFpzXat8FttLennG75UOryMq/DiK0xKI2478hKb9KMYV X-Received: by 2002:a05:6358:705:b0:134:f070:d6b8 with SMTP id e5-20020a056358070500b00134f070d6b8mr13250039rwj.4.1688958867711; Sun, 09 Jul 2023 20:14:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688958867; cv=none; d=google.com; s=arc-20160816; b=Vjt85p4MM4vdx62VIpfcSKc/gMhZKMwZzixvZX8kFDqH+LZWclS4HqgqQqgCj+mkDK XHjnefbwgdPhrKiIaljqtKYbsX2CZSsJG6HzeEiT1eHqBzSRRIW5YOr/YSb/ubH69vXe IUvVu1eyTJGpVe2cCpTdUhEfGZY+5eZGzeAOsxufXvt75Q9dt0k1AhCKd3lUSH6BaJO6 Tra2zrgHpK91iJ2L2++0cr7ArECLne/GSaWE9Td0D1VF8c5nWX7UCEHCZTLgAdwSsgcW OsFfto3ZpWbo5i3FzYT96torih/mXieQgJA7sTYCjTMh+CpNOXeKYVzD+1mYFiV7Ge5+ ka2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=tzyqXosdnDO68LtdH9MXWVaSATpoziQrNIP/nKesUIU=; fh=zSWlyHzDvWSMCp8X96gkKE80M0WIdnN640Mlzep74EY=; b=kqLzqBHXFI4PNi/8bMKTmFFZb6czR4Roia5gbJT7z6mU1T1eSMhins25apGjFrKdDX i2Rl9KeSWbfsmcda7tuJlU3rbD9oefi3AVSpva9QspehHhq+8o+c6kwJQ5LunKwFRz5Z qAe9ZEWgNth+QMHMqFzwkJlu3dkO8AO2A7rpJObKmGXyafLdrmeuMHc0LYP6Aa5Clcth yEWBac62BB5HyzJWck/xl5fn/7VhRktKP65ZyjXbQmz8vCZwydpRmI/rg+9A4ezLfFQk MGIgFn76pTAx6TL55sPEU21dIhWHbBc8v7eWeWLR4SUTQKI2jH6gJVPKb+9rHxbcytAE 7fBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZgjBUwWk; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j13-20020a056a00234d00b00666e8e573a4si1918247pfj.241.2023.07.09.20.14.20; Sun, 09 Jul 2023 20:14:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=ZgjBUwWk; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230219AbjGJDGf (ORCPT + 60 others); Sun, 9 Jul 2023 23:06:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229680AbjGJDGe (ORCPT ); Sun, 9 Jul 2023 23:06:34 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A97B2F4; Sun, 9 Jul 2023 20:06:30 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id ca18e2360f4ac-78654448524so106913639f.2; Sun, 09 Jul 2023 20:06:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688958390; x=1691550390; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=tzyqXosdnDO68LtdH9MXWVaSATpoziQrNIP/nKesUIU=; b=ZgjBUwWkJkWTLTgZjnUl36bz4hxN+A/JDp2vGU5E8dlQ/+FtHwSQ4j5JH9bVccfcQx u/PQyu6P3cwxEXMM5oGk/aLjfuPLPTzvekiafWvtjc3mEpZW7Zppqrab3eslKKDccOlL b+xn9eO7dXiVFL6jpvp3S96xBPsrPU2fK/7qNE0+gK4Yr5osxV/R5pxBzyXnDlZ+BZvd tfmSVqcutKhiici1jMwMD4RmZik4S11EOfxtYlzBDKfjDpHy0Es4QygPcUi8+ayZoFX5 ULk6pjSUo36zNQphYyUAKZOMZ/9H/gzUMJyTjvred3eAhUfqPQ6n8ghcYf81hSkjGjbI 4awg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688958390; x=1691550390; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tzyqXosdnDO68LtdH9MXWVaSATpoziQrNIP/nKesUIU=; b=LHXy7eeEShiu9tJnGvFWNMNPdSQRRh+KRkbOSaQnN5/e1HrT51Ge7sN0Eb3h5wcsLx GzyjiCS/pLk+aJU598OOw3YlsnuBEhuL4W93SjVp3bU986mC13LrF9B022Vms+bDq93n y/L1IUsL8FAJdvtzVApJVLEgkK2MOa7hFDULncQBeuBS1oDS2D35MUckCT7enl4uynlM L6SLoRg/3wwHnwYpgLXyp2kRucxcpQFPaRwjOoH+UWOfzw6cvDuGu5+tOneiCMUntkvA iP11sszoZAdfuCsU5qF3U6f9c5z3c88pEFw2qLZZg1yj6ccqOhhbm2qz1vWNmV/XcGWu cE7g== X-Gm-Message-State: ABy/qLYvlGZvNvuhH83fMcsHF3LSjlmw3H8v8KkUgdNkWtuxaz4JtEPs FeocMIK43IMQ/Kbcg7Urqd8= X-Received: by 2002:a6b:7b49:0:b0:780:bf50:32ce with SMTP id m9-20020a6b7b49000000b00780bf5032cemr11185666iop.19.1688958389884; Sun, 09 Jul 2023 20:06:29 -0700 (PDT) Received: from azeems-kspp.c.googlers.com.com (54.70.188.35.bc.googleusercontent.com. [35.188.70.54]) by smtp.gmail.com with ESMTPSA id s11-20020a5eaa0b000000b00785cd25010esm3318732ioe.11.2023.07.09.20.06.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 09 Jul 2023 20:06:29 -0700 (PDT) From: Azeem Shaikh To: Amitkumar Karwar , Ganapathi Bhat , Sharvari Harisangam , Xinming Hu Cc: linux-hardening@vger.kernel.org, Azeem Shaikh , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Kalle Valo Subject: [PATCH] wifi: mwifiex: Replace strlcpy with strscpy Date: Mon, 10 Jul 2023 03:06:25 +0000 Message-ID: <20230710030625.812707-1-azeemshaikh38@gmail.com> X-Mailer: git-send-email 2.41.0.255.g8b1d071c50-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham 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 strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). Direct replacement is safe here since return value of -errno is used to check for truncation instead of sizeof(dest). [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] https://github.com/KSPP/linux/issues/89 Signed-off-by: Azeem Shaikh --- drivers/net/wireless/marvell/mwifiex/main.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/marvell/mwifiex/main.c b/drivers/net/wireless/marvell/mwifiex/main.c index 1cd9d20cca16..8d3c4bcf9c89 100644 --- a/drivers/net/wireless/marvell/mwifiex/main.c +++ b/drivers/net/wireless/marvell/mwifiex/main.c @@ -725,9 +725,8 @@ static int mwifiex_init_hw_fw(struct mwifiex_adapter *adapter, * manufacturing mode is enabled */ if (mfg_mode) { - if (strlcpy(adapter->fw_name, MFG_FIRMWARE, - sizeof(adapter->fw_name)) >= - sizeof(adapter->fw_name)) { + if (strscpy(adapter->fw_name, MFG_FIRMWARE, + sizeof(adapter->fw_name)) < 0) { pr_err("%s: fw_name too long!\n", __func__); return -1; } -- 2.41.0.255.g8b1d071c50-goog