* [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user()
@ 2021-09-28 20:17 Gustavo A. R. Silva
2021-09-29 10:24 ` Tariq Toukan
0 siblings, 1 reply; 4+ messages in thread
From: Gustavo A. R. Silva @ 2021-09-28 20:17 UTC (permalink / raw)
To: Tariq Toukan, David S. Miller, Jakub Kicinski
Cc: netdev, linux-rdma, linux-kernel, Gustavo A. R. Silva, linux-hardening
Use array_size() helper instead of the open-coded version in
copy_to_user(). These sorts of multiplication factors need
to be wrapped in array_size().
Link: https://github.com/KSPP/linux/issues/160
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
drivers/net/ethernet/mellanox/mlx4/cq.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c
index f7053a74e6a8..4d4f9cf9facb 100644
--- a/drivers/net/ethernet/mellanox/mlx4/cq.c
+++ b/drivers/net/ethernet/mellanox/mlx4/cq.c
@@ -314,7 +314,8 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size)
buf += PAGE_SIZE;
}
} else {
- err = copy_to_user((void __user *)buf, init_ents, entries * cqe_size) ?
+ err = copy_to_user((void __user *)buf, init_ents,
+ array_size(entries, cqe_size)) ?
-EFAULT : 0;
}
--
2.27.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user()
2021-09-28 20:17 [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user() Gustavo A. R. Silva
@ 2021-09-29 10:24 ` Tariq Toukan
2021-09-29 17:21 ` Eric Dumazet
0 siblings, 1 reply; 4+ messages in thread
From: Tariq Toukan @ 2021-09-29 10:24 UTC (permalink / raw)
To: Gustavo A. R. Silva, Tariq Toukan, David S. Miller, Jakub Kicinski
Cc: netdev, linux-rdma, linux-kernel, linux-hardening
On 9/28/2021 11:17 PM, Gustavo A. R. Silva wrote:
> Use array_size() helper instead of the open-coded version in
> copy_to_user(). These sorts of multiplication factors need
> to be wrapped in array_size().
>
> Link: https://github.com/KSPP/linux/issues/160
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> drivers/net/ethernet/mellanox/mlx4/cq.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c
> index f7053a74e6a8..4d4f9cf9facb 100644
> --- a/drivers/net/ethernet/mellanox/mlx4/cq.c
> +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c
> @@ -314,7 +314,8 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size)
> buf += PAGE_SIZE;
> }
> } else {
> - err = copy_to_user((void __user *)buf, init_ents, entries * cqe_size) ?
> + err = copy_to_user((void __user *)buf, init_ents,
> + array_size(entries, cqe_size)) ?
> -EFAULT : 0;
> }
>
>
Thanks for your patch.
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user()
2021-09-29 10:24 ` Tariq Toukan
@ 2021-09-29 17:21 ` Eric Dumazet
2021-09-29 17:45 ` Tariq Toukan
0 siblings, 1 reply; 4+ messages in thread
From: Eric Dumazet @ 2021-09-29 17:21 UTC (permalink / raw)
To: Tariq Toukan, Gustavo A. R. Silva, Tariq Toukan, David S. Miller,
Jakub Kicinski
Cc: netdev, linux-rdma, linux-kernel, linux-hardening
On 9/29/21 3:24 AM, Tariq Toukan wrote:
>
>
> On 9/28/2021 11:17 PM, Gustavo A. R. Silva wrote:
>> Use array_size() helper instead of the open-coded version in
>> copy_to_user(). These sorts of multiplication factors need
>> to be wrapped in array_size().
>>
>> Link: https://github.com/KSPP/linux/issues/160
>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>> ---
>> drivers/net/ethernet/mellanox/mlx4/cq.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c
>> index f7053a74e6a8..4d4f9cf9facb 100644
>> --- a/drivers/net/ethernet/mellanox/mlx4/cq.c
>> +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c
>> @@ -314,7 +314,8 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size)
>> buf += PAGE_SIZE;
>> }
>> } else {
>> - err = copy_to_user((void __user *)buf, init_ents, entries * cqe_size) ?
>> + err = copy_to_user((void __user *)buf, init_ents,
>> + array_size(entries, cqe_size)) ?
>> -EFAULT : 0;
>> }
>>
>
> Thanks for your patch.
> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Not sure why avoiding size_t overflows would make this code safer.
init_ents contains PAGE_SIZE bytes...
BTW
Is @entries guaranteed to be a power of two ?
This function seems to either copy one chunk ( <= PAGE_SIZE),
or a number of full pages.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user()
2021-09-29 17:21 ` Eric Dumazet
@ 2021-09-29 17:45 ` Tariq Toukan
0 siblings, 0 replies; 4+ messages in thread
From: Tariq Toukan @ 2021-09-29 17:45 UTC (permalink / raw)
To: Eric Dumazet, Gustavo A. R. Silva, Tariq Toukan, David S. Miller,
Jakub Kicinski
Cc: netdev, linux-rdma, linux-kernel, linux-hardening
On 9/29/2021 8:21 PM, Eric Dumazet wrote:
>
>
> On 9/29/21 3:24 AM, Tariq Toukan wrote:
>>
>>
>> On 9/28/2021 11:17 PM, Gustavo A. R. Silva wrote:
>>> Use array_size() helper instead of the open-coded version in
>>> copy_to_user(). These sorts of multiplication factors need
>>> to be wrapped in array_size().
>>>
>>> Link: https://github.com/KSPP/linux/issues/160
>>> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
>>> ---
>>> drivers/net/ethernet/mellanox/mlx4/cq.c | 3 ++-
>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/drivers/net/ethernet/mellanox/mlx4/cq.c b/drivers/net/ethernet/mellanox/mlx4/cq.c
>>> index f7053a74e6a8..4d4f9cf9facb 100644
>>> --- a/drivers/net/ethernet/mellanox/mlx4/cq.c
>>> +++ b/drivers/net/ethernet/mellanox/mlx4/cq.c
>>> @@ -314,7 +314,8 @@ static int mlx4_init_user_cqes(void *buf, int entries, int cqe_size)
>>> buf += PAGE_SIZE;
>>> }
>>> } else {
>>> - err = copy_to_user((void __user *)buf, init_ents, entries * cqe_size) ?
>>> + err = copy_to_user((void __user *)buf, init_ents,
>>> + array_size(entries, cqe_size)) ?
>>> -EFAULT : 0;
>>> }
>>>
>>
>> Thanks for your patch.
>> Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
>
> Not sure why avoiding size_t overflows would make this code safer.
> init_ents contains PAGE_SIZE bytes...
>
> BTW
>
> Is @entries guaranteed to be a power of two ?
Yes.
>
> This function seems to either copy one chunk ( <= PAGE_SIZE),
> or a number of full pages.
>
Exactly. No remainder handling is needed, for the reason you mentioned
above.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-09-29 17:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 20:17 [PATCH][net-next] net/mlx4: Use array_size() helper in copy_to_user() Gustavo A. R. Silva
2021-09-29 10:24 ` Tariq Toukan
2021-09-29 17:21 ` Eric Dumazet
2021-09-29 17:45 ` Tariq Toukan
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).