From: Paolo Abeni <pabeni@redhat.com>
To: Tariq Toukan <tariqt@nvidia.com>, Yao Sang <sangyao@kylinos.cn>,
"David S . Miller" <davem@davemloft.net>,
Jakub Kicinski <kuba@kernel.org>
Cc: Andrew Lunn <andrew+netdev@lunn.ch>,
Eric Dumazet <edumazet@google.com>,
"Gustavo A . R . Silva" <gustavoars@kernel.org>,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org
Subject: Re: [PATCH net] net/mlx4: avoid GCC 10 __bad_copy_from() false positive
Date: Tue, 26 May 2026 09:56:55 +0200 [thread overview]
Message-ID: <caa33c6c-2864-47c1-a111-06422d3723c9@redhat.com> (raw)
In-Reply-To: <31260e8f-15c3-4738-b5b6-67b0ea2d3b0e@nvidia.com>
On 5/25/26 12:47 PM, Tariq Toukan wrote:
> On 20/05/2026 13:21, Yao Sang wrote:
>> mlx4_init_user_cqes() allocates a single PAGE_SIZE buffer and fills it
>> with the CQE initialization pattern. When entries_per_copy >= entries,
>> the function copies array_size(entries, cqe_size) bytes from that buffer
>> to userspace.
>>
>> That copy is actually bounded by PAGE_SIZE in the else branch because
>> entries_per_copy >= entries implies entries * cqe_size <= PAGE_SIZE.
>> However, GCC 10 does not derive that constraint and falsely triggers
>> __bad_copy_from() in mlx4_init_user_cqes().
>>
>> Cap the single copy_to_user() length to PAGE_SIZE to make that bound
>> explicit and avoid the GCC 10 false positive.
>>
>> Fixes: f69bf5dee7ef ("net/mlx4: Use array_size() helper in copy_to_user()")
>> Signed-off-by: Yao Sang <sangyao@kylinos.cn>
>> ---
>> drivers/net/ethernet/mellanox/mlx4/cq.c | 5 ++++-
>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c
>> index e130e7259275..7b024a5e13c8 100644
>> --- a/drivers/net/ethernet/mellanox/mlx4/cq.c
>> +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c
>> @@ -314,8 +314,11 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size)
>> buf += PAGE_SIZE;
>> }
>> } else {
>> + size_t copy_bytes = min_t(size_t, array_size(entries, cqe_size),
>> + PAGE_SIZE);
>> +
>> err = copy_to_user((void __user *)buf, init_ents,
>> - array_size(entries, cqe_size)) ?
>> + copy_bytes) ?
>> -EFAULT : 0;
>> }
>>
>
> Thanks for your patch.
>
> This is a compiler issue.
> Did you try fixing it there first?
AFAICS gcc 10 is a supported version, the kernel should build correctly
with it, right?
Also AFAICS this is not fastpath so an additional check should not be
problematic? Perhaps a warn instead would be more palatable?
if (WARN_ON_ONCE(array_size(entries, cqe_size) > PAGE_SIZE))
// ...
/P
next prev parent reply other threads:[~2026-05-26 7:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-20 10:21 [PATCH net] net/mlx4: avoid GCC 10 __bad_copy_from() false positive Yao Sang
2026-05-25 10:47 ` Tariq Toukan
2026-05-26 7:56 ` Paolo Abeni [this message]
2026-05-26 10:09 ` David Laight
[not found] ` <1780035629778309.247.seg@mailgw.kylinos.cn>
2026-05-29 6:45 ` Yao Sang
2026-06-01 11:00 ` Tariq Toukan
2026-06-01 12:14 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=caa33c6c-2864-47c1-a111-06422d3723c9@redhat.com \
--to=pabeni@redhat.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gustavoars@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=sangyao@kylinos.cn \
--cc=tariqt@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).