mirror of
https://github.com/torvalds/linux.git
synced 2026-11-06 21:58:01 +01:00
mm: fix unmap_mapping_range() beyond 4 GiB on 32-bit
Commit9eab0421fa("mm: fix unmap_mapping_range high bits shift bug") made holebegin and holelen unsigned before they are shifted, by casting them to pgoff_t. That is an unsigned long: on a 32-bit kernel the cast cuts off the upper half of the two loff_t values, so a hole which begins at 4 GiB or beyond is taken for one in the first 4 GiB of the file. truncate_pagecache() passes the new size of the file and asks for private COWed pages to be unmapped as well. If a file of 6 GiB is truncated to 5 GiB, everything from 1 GiB on is unmapped, and what a process has written to a private mapping of the range between 1 GiB and 5 GiB is lost: it reads the contents of the file again. Where the range has an end, the wrong range is unmapped instead of the right one. The page cache copes with that, as it unmaps every folio that it removes. The callers which only have unmap_mapping_range() to get rid of user mappings do not, for example drm_vma_node_unmap(), whose fake offsets reach beyond 4 GiB on 32-bit, and revoke_iomem() with physical addresses of more than 32 bits. Cast to u64 instead. Nothing changes for 64-bit kernels. Fix generated by an LLM and sent by Josef Bacik in private. Fixes:9eab0421fa("mm: fix unmap_mapping_range high bits shift bug") Cc: stable@vger.kernel.org Signed-off-by: Josef Bacik <josef@toxicpanda.com> Acked-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Reviewed-by: Pedro Falcato <pfalcato@suse.de> Tested-by: Muhammad Usama Anjum <usama.anjum@arm.com> Link: https://patch.msgid.link/20261031-fixes_core-v3-36-d6437171ecc3@kernel.org Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
This commit is contained in:
parent
8db6921cc0
commit
7a81bc23da
|
|
@ -4649,8 +4649,8 @@ EXPORT_SYMBOL_GPL(unmap_mapping_pages);
|
|||
void unmap_mapping_range(struct address_space *mapping,
|
||||
loff_t const holebegin, loff_t const holelen, int even_cows)
|
||||
{
|
||||
pgoff_t hba = (pgoff_t)(holebegin) >> PAGE_SHIFT;
|
||||
pgoff_t hlen = ((pgoff_t)(holelen) + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||
pgoff_t hba = (u64)holebegin >> PAGE_SHIFT;
|
||||
pgoff_t hlen = ((u64)holelen + PAGE_SIZE - 1) >> PAGE_SHIFT;
|
||||
|
||||
/* Check for overflow. */
|
||||
if (sizeof(holelen) > sizeof(hlen)) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user