[PATCH v2 2/2] mm: fix boundary judgment issues in kernel/resource.c

From: Yaohui Wang
Date: Fri Jun 11 2021 - 00:23:01 EST


The original boundary judgment may ignore @end if @end equals @start. For
example, if we call ioremap(phys, 1), then @end == @start, and the memory
check will not be applied on the page where @end lives, which is
unexpected.

In kernel/resource.c:find_next_iomem_res, the mem region is a closed
interval (i.e. [@start..@end]). So @start == @end should be allowed.

In kernel/resource.c:__walk_iomem_res_desc, the mem region is a closed
interval (i.e. [@start..@end]). So @start == @end should be allowed.

Signed-off-by: Ben Luo <luoben@xxxxxxxxxxxxxxxxx>
Signed-off-by: Yahui Wang <yaohuiwang@xxxxxxxxxxxxxxxxx>
---
kernel/resource.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/resource.c b/kernel/resource.c
index 16e0c7e8e..b29c8c720 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -353,7 +353,7 @@ static int find_next_iomem_res(resource_size_t start, resource_size_t end,
if (!res)
return -EINVAL;

- if (start >= end)
+ if (start > end)
return -EINVAL;

read_lock(&resource_lock);
@@ -408,7 +408,7 @@ static int __walk_iomem_res_desc(resource_size_t start, resource_size_t end,
struct resource res;
int ret = -EINVAL;

- while (start < end &&
+ while (start <= end &&
!find_next_iomem_res(start, end, flags, desc, first_lvl, &res)) {
ret = (*func)(&res, arg);
if (ret)
--
2.25.1