From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6A2B815B998; Tue, 16 Jun 2026 15:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781625217; cv=none; b=WtDtVhi2x7llP5C+eO5UKtUEmXCVxeZ+qL3+4EhiWo0FYclXKf61Emh8EPKBK5mhQl6MsyzUcXRdHCZ0XLMwDsez+2AW0Yxm0WgjW2KOCsjn+nBp0t8y9Z8YGlcxuusLNyJyx4+HsjQ2Mmax5nDf3+BOP1jSFlOixR87ZjhMr0Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781625217; c=relaxed/simple; bh=H+Mrixw+d5PzUmeMN/IqfHJxsme+catl2CqbhY9Efg0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mXors7FdFjChQkUhDHUv9m5+Y61TUgXIkciwqypJUdwts61yv6MtuNmeKA9wkKFqLc+tvhQMBnwQ1GL+dRZasmy/4gUChZU0qxY0Wh004wSs4y4KZO35Dq9EWwQupKMXTVL57RKzUFMRnmqkPH9US69ASpZ3WY3fSQQI+c1Y3do= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=UWwcXk8J; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="UWwcXk8J" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3865D1F00A3A; Tue, 16 Jun 2026 15:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781625216; bh=DN0Y3dKH0IP8fjmDVuMoNbRCoIRwSt9NISbF2G+S6pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=UWwcXk8JYNMCspnli7v6N7fSPlUyz6Ytw0kfZwgg7NqM4MWbxLtEmXUYW2e/OQV3D s3J/zotkkcVMtjwasfYkAqXKXXaihmWBivbYAO8e1a1mIYdcY9dAoVnwp+riDpQ5sU BcBzXBnqsOYo39zMRr9fvR4Jv0lK31DcDDWB5gz0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yao Sang , Jacob Keller , Jakub Kicinski , Sasha Levin Subject: [PATCH 6.18 099/325] net/mlx4: avoid GCC 10 __bad_copy_from() false positive Date: Tue, 16 Jun 2026 20:28:15 +0530 Message-ID: <20260616145102.625766739@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145057.827196531@linuxfoundation.org> References: <20260616145057.827196531@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yao Sang [ Upstream commit 2365343f4aad3e1b1e7a2e87e98cf66d5e590589 ] mlx4_init_user_cqes() fills a scratch buffer with the CQE initialization pattern and then copies from that buffer to userspace. In the single-copy path, the copy length is array_size(entries, cqe_size), but the scratch buffer is allocated with PAGE_SIZE. GCC 10 does not carry the branch invariant strongly enough through the object size checks and falsely triggers __bad_copy_from(). Size the scratch buffer to the actual copy length for the active path, keep array_size() for the single-copy case, and retain a WARN_ON_ONCE() guard for the PAGE_SIZE invariant before allocating the buffer. Fixes: f69bf5dee7ef ("net/mlx4: Use array_size() helper in copy_to_user()") Signed-off-by: Yao Sang Reviewed-by: Jacob Keller Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- drivers/net/ethernet/mellanox/mlx4/cq.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c index e130e7259275a3..5c55971abbf072 100644 --- a/drivers/net/ethernet/mellanox/mlx4/cq.c +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c @@ -290,6 +290,7 @@ static void mlx4_cq_free_icm(struct mlx4_dev *dev, int cqn) static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) { int entries_per_copy = PAGE_SIZE / cqe_size; + size_t copy_bytes; void *init_ents; int err = 0; int i; @@ -314,8 +315,14 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size) buf += PAGE_SIZE; } } else { + copy_bytes = array_size(entries, cqe_size); + if (WARN_ON_ONCE(copy_bytes > PAGE_SIZE)) { + err = -EINVAL; + goto out; + } + err = copy_to_user((void __user *)buf, init_ents, - array_size(entries, cqe_size)) ? + copy_bytes) ? -EFAULT : 0; } -- 2.53.0