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: <20250704133332.GA1410929@nvidia.com>
Date: Fri, 4 Jul 2025 10:33:32 -0300
From: Jason Gunthorpe <jgg@...dia.com>
To: Nicolin Chen <nicolinc@...dia.com>
Cc: kevin.tian@...el.com, corbet@....net, will@...nel.org,
	bagasdotme@...il.com, robin.murphy@....com, joro@...tes.org,
	thierry.reding@...il.com, vdumpa@...dia.com, jonathanh@...dia.com,
	shuah@...nel.org, jsnitsel@...hat.com, nathan@...nel.org,
	peterz@...radead.org, yi.l.liu@...el.com, mshavit@...gle.com,
	praan@...gle.com, zhangzekun11@...wei.com, iommu@...ts.linux.dev,
	linux-doc@...r.kernel.org, linux-kernel@...r.kernel.org,
	linux-arm-kernel@...ts.infradead.org, linux-tegra@...r.kernel.org,
	linux-kselftest@...r.kernel.org, patches@...ts.linux.dev,
	mochs@...dia.com, alok.a.tiwari@...cle.com, vasant.hegde@....com,
	dwmw2@...radead.org, baolu.lu@...ux.intel.com
Subject: Re: [PATCH v7 13/28] iommufd/viommu: Add IOMMUFD_CMD_HW_QUEUE_ALLOC
 ioctl

On Fri, Jul 04, 2025 at 10:26:02AM -0300, Jason Gunthorpe wrote:

> /* DIV_ROUND_UP(offset + cmd->length, PAGE_SIZE) */
> if (check_add_overflow(offset, cmd->length, &length))
>    return -ERANGE;
> if (check_add_overflow(length, PAGE_SIZE-1, &length))
>    return -ERANGE;
> if (length > SIZE_MAX)
>    return -ERANGE;
> max_npages = length / PAGE_SIZE;

Actually I see now that overflow.h supports mixed types, so this can
be simplified:

 size_t max_npages;
 size_t length;
 u64 offset;
 size_t i;

 offset = cmd->nesting_parent_iova - PAGE_ALIGN(cmd->nesting_parent_iova);

 /* DIV_ROUND_UP(offset + cmd->length, PAGE_SIZE) */
 if (check_add_overflow(offset, cmd->length, &length))
    return -ERANGE;
 if (check_add_overflow(length, PAGE_SIZE-1, &length))
    return -ERANGE;
 max_npages = length / PAGE_SIZE;

Then the kcvalloc takes in size_t:

kvmalloc_array_node_noprof(size_t n, size_t size, gfp_t flags, int node)

So there is no silent cast and truncation.

Jason

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ