Skip to content

Commit 15e2f65

Browse files
t-8chrobherring
authored andcommitted
of: address: Fix empty resource handling in __of_address_resource_bounds()
"resource->end" needs to always be equal to "resource->start + size - 1". The previous version of the function did not perform the "- 1" in case of an empty resource. Also make sure to allow an empty resource at address 0. Reported-by: Basharath Hussain Khaja <basharath@couthit.com> Closes: https://lore.kernel.org/lkml/20250108140414.13530-1-basharath@couthit.com/ Fixes: 1a52a09 ("of: address: Unify resource bounds overflow checking") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de> Link: https://lore.kernel.org/r/20250120-of-address-overflow-v1-1-dd68dbf47bce@linutronix.de Signed-off-by: Rob Herring (Arm) <robh@kernel.org>
1 parent 14bce18 commit 15e2f65

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

drivers/of/address.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,15 @@ static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns,
185185

186186
static int __of_address_resource_bounds(struct resource *r, u64 start, u64 size)
187187
{
188-
u64 end = start;
189-
190188
if (overflows_type(start, r->start))
191189
return -EOVERFLOW;
192-
if (size && check_add_overflow(end, size - 1, &end))
193-
return -EOVERFLOW;
194-
if (overflows_type(end, r->end))
195-
return -EOVERFLOW;
196190

197191
r->start = start;
198-
r->end = end;
192+
193+
if (!size)
194+
r->end = wrapping_sub(typeof(r->end), r->start, 1);
195+
else if (size && check_add_overflow(r->start, size - 1, &r->end))
196+
return -EOVERFLOW;
199197

200198
return 0;
201199
}

0 commit comments

Comments
 (0)