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 B67F8328610; Tue, 16 Jun 2026 17:02:08 +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=1781629329; cv=none; b=poZ/j9I/1ffYvgd6oEBSpQDPHe5x02QWkZKe5ztyMEzk/aHu/WfMJGAXgzEfj1ZfWgjC10VMiLB7nQqbtSyTmzIdE5yuWqsQC/D0fZ429sJvphFkjOH10fF31fC5dySd0MOT1N7pplx15E/xduEGiuG42ENbF4DjvifoPDlSUyc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781629329; c=relaxed/simple; bh=yiJFZleikrZYS8Udk9TNCJZL1CIJtnGrTIJz9eoEBU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qg8bGjIBtNHvqLeS0SjhTLXUxiubh7ayJQIa0vNNWOKqjh/fUTEkAkgTi67mw+D63woxrVIjJu42Hannc8qUFSw3q+YPTHR8kW4mpk3MsVKeAo6PMDwup7AqB2Ln1+WrBkhYHVqtPrD11+D1q0ejQ/cB32JLYqyG9q5oBw1k1sM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=WKoodeEL; 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="WKoodeEL" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BD5C61F000E9; Tue, 16 Jun 2026 17:02:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1781629328; bh=E9YE749YHYQ8JTffSzX8e21Rm51zgNH3r0Y0crZuWvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=WKoodeEL5fdOsGNC64HKi5e1+VlWVwTzhv2TvQZTSN8mrhn6kbivKYdGGg7vmPx34 76/NL3cHYiOLPYgFiNgnySMR3T5DsXBzpUyKj4LJndM5lC7OqV36krzGuirrQb21we 2SyIMLo/yg9tHUrZ6gT2eN2vmOtppakMVqQMFfOM= 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.6 265/452] net/mlx4: avoid GCC 10 __bad_copy_from() false positive Date: Tue, 16 Jun 2026 20:28:12 +0530 Message-ID: <20260616145131.526272527@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260616145117.796205997@linuxfoundation.org> References: <20260616145117.796205997@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.6-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 4d4f9cf9facb87..fb83d8af8dcb9c 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