lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9f28e3b3-a47d-4a83-911d-fd7a6b95fd60@os.amperecomputing.com>
Date: Fri, 4 Oct 2024 09:37:10 -0700
From: Yang Shi <yang@...amperecomputing.com>
To: Jason Gunthorpe <jgg@...pe.ca>
Cc: Nicolin Chen <nicolinc@...dia.com>, james.morse@....com, will@...nel.org,
 robin.murphy@....com, linux-arm-kernel@...ts.infradead.org,
 linux-kernel@...r.kernel.org
Subject: Re: [v2 PATCH] iommu/arm-smmu-v3: Fix L1 stream table index
 calculation for 32-bit sid size



On 10/4/24 9:29 AM, Yang Shi wrote:
>
>
> On 10/4/24 9:14 AM, Jason Gunthorpe wrote:
>> On Fri, Oct 04, 2024 at 09:05:46AM -0700, Yang Shi wrote:
>>>
>>> On 10/4/24 5:43 AM, Jason Gunthorpe wrote:
>>>> On Thu, Oct 03, 2024 at 08:31:23AM -0700, Yang Shi wrote:
>>>>> If I understand correctly, the check is mainly used to avoid the 
>>>>> u64 -> u32
>>>>> overflow. This check guarantee no overflow. If some crazy hardware 
>>>>> really
>>>>> requests that large memory, the allocation will fail.
>>>> Sure, the kalloc will print a warn on anyhow if it is too big
>>> Thank you. Will spin a new revision.
>> Oh wait a sec, it is not so simple, the 31 is too big because the
>> multiply will overflow or truncate to size_t too. This is why I picked
>> something lower.
>
> How about define the size as u64?
>
>  static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)
>  {
> -       u32 size;
> +       u64 size;
>         struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
>         u32 num_sids;
>
> It won't overflow and the large allocation will fail anyway.

The size parameter passed to dmam_alloc_coherent() is size_t type. We 
may do:

+#define SIZE_4G (4 * 1024 * 1024 * 1024ULL)
+
  static int arm_smmu_init_strtab_linear(struct arm_smmu_device *smmu)
  {
-       u32 size;
+       u64 size;
         struct arm_smmu_strtab_cfg *cfg = &smmu->strtab_cfg;
-       u32 num_sids;
+       u64 num_sids;

         /* It is not practical to have too large stream id size for 
linear */
         if (smmu->sid_bits > 31)
@@ -3667,6 +3669,9 @@ static int arm_smmu_init_strtab_linear(struct 
arm_smmu_device *smmu)
         num_sids = arm_smmu_strtab_num_sids(smmu);

         size = num_sids * sizeof(struct arm_smmu_ste);
+       if (size > SIZE_4G)
+               return -EINVAL;
+
         cfg->linear.table = dmam_alloc_coherent(smmu->dev, size,
&cfg->linear.ste_dma,
                                                 GFP_KERNEL);

>
>>
>> Jason
>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ