The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Alexander Gordeev <agordeev@linux.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: linux-arm-kernel@lists.infradead.org,
	Thierry Reding <treding@nvidia.com>,
	Arnd Bergmann <arnd@arndb.de>,
	Russell King <linux@armlinux.org.uk>
Subject: [PATCH] asm/sections: fix memory object end check
Date: Tue, 21 Dec 2021 08:06:24 +0100	[thread overview]
Message-ID: <20211221070624.1541842-1-agordeev@linux.ibm.com> (raw)

Function memory_contains() checks whether a memory object is
entirely contained within a memory region. The condition that
checks the upper bound of the object against the upper bound
of the region is inclusive. That does not correspond to the
similar checks in memory_intersects() friend function, nor
to the actual regions memory_contains() is called against.

In particular, __init_end address assumed do not belong to
the init section itself. Similarly, on ARM __idmap_text_end
and __entry_text_end are affected.

Fixes: 979559362516 ("asm/sections: add helpers to check for section data")
Cc: Thierry Reding <treding@nvidia.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Russell King <linux@armlinux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
---
 include/asm-generic/sections.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index 1dfadb2e878d..23f325cd2c66 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -78,7 +78,7 @@ extern __visible const void __nosave_begin, __nosave_end;
 static inline bool memory_contains(void *begin, void *end, void *virt,
 				   size_t size)
 {
-	return virt >= begin && virt + size <= end;
+	return virt >= begin && virt + size < end;
 }
 
 /**
-- 
2.32.0


             reply	other threads:[~2021-12-21  7:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-21  7:06 Alexander Gordeev [this message]
2021-12-21  9:56 ` [PATCH] asm/sections: fix memory object end check Russell King (Oracle)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211221070624.1541842-1-agordeev@linux.ibm.com \
    --to=agordeev@linux.ibm.com \
    --cc=arnd@arndb.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=treding@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox