]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.14-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 Apr 2022 15:46:14 +0000 (17:46 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 11 Apr 2022 15:46:14 +0000 (17:46 +0200)
added patches:
mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch

queue-4.14/mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch [new file with mode: 0644]
queue-4.14/series

diff --git a/queue-4.14/mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch b/queue-4.14/mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch
new file mode 100644 (file)
index 0000000..9da43b6
--- /dev/null
@@ -0,0 +1,77 @@
+From a431dbbc540532b7465eae4fc8b56a85a9fc7d17 Mon Sep 17 00:00:00 2001
+From: Waiman Long <longman@redhat.com>
+Date: Fri, 8 Apr 2022 13:09:01 -0700
+Subject: mm/sparsemem: fix 'mem_section' will never be NULL gcc 12 warning
+
+From: Waiman Long <longman@redhat.com>
+
+commit a431dbbc540532b7465eae4fc8b56a85a9fc7d17 upstream.
+
+The gcc 12 compiler reports a "'mem_section' will never be NULL" warning
+on the following code:
+
+    static inline struct mem_section *__nr_to_section(unsigned long nr)
+    {
+    #ifdef CONFIG_SPARSEMEM_EXTREME
+        if (!mem_section)
+                return NULL;
+    #endif
+        if (!mem_section[SECTION_NR_TO_ROOT(nr)])
+                return NULL;
+       :
+
+It happens with CONFIG_SPARSEMEM_EXTREME off.  The mem_section definition
+is
+
+    #ifdef CONFIG_SPARSEMEM_EXTREME
+    extern struct mem_section **mem_section;
+    #else
+    extern struct mem_section mem_section[NR_SECTION_ROOTS][SECTIONS_PER_ROOT];
+    #endif
+
+In the !CONFIG_SPARSEMEM_EXTREME case, mem_section is a static
+2-dimensional array and so the check "!mem_section[SECTION_NR_TO_ROOT(nr)]"
+doesn't make sense.
+
+Fix this warning by moving the "!mem_section[SECTION_NR_TO_ROOT(nr)]"
+check up inside the CONFIG_SPARSEMEM_EXTREME block and adding an
+explicit NR_SECTION_ROOTS check to make sure that there is no
+out-of-bound array access.
+
+Link: https://lkml.kernel.org/r/20220331180246.2746210-1-longman@redhat.com
+Fixes: 3e347261a80b ("sparsemem extreme implementation")
+Signed-off-by: Waiman Long <longman@redhat.com>
+Reported-by: Justin Forbes <jforbes@redhat.com>
+Cc: "Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>
+Cc: Ingo Molnar <mingo@kernel.org>
+Cc: Rafael Aquini <aquini@redhat.com>
+Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
+Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ include/linux/mmzone.h |   11 +++++++----
+ 1 file changed, 7 insertions(+), 4 deletions(-)
+
+--- a/include/linux/mmzone.h
++++ b/include/linux/mmzone.h
+@@ -1160,13 +1160,16 @@ extern struct mem_section mem_section[NR
+ static inline struct mem_section *__nr_to_section(unsigned long nr)
+ {
++      unsigned long root = SECTION_NR_TO_ROOT(nr);
++
++      if (unlikely(root >= NR_SECTION_ROOTS))
++              return NULL;
++
+ #ifdef CONFIG_SPARSEMEM_EXTREME
+-      if (!mem_section)
++      if (!mem_section || !mem_section[root])
+               return NULL;
+ #endif
+-      if (!mem_section[SECTION_NR_TO_ROOT(nr)])
+-              return NULL;
+-      return &mem_section[SECTION_NR_TO_ROOT(nr)][nr & SECTION_ROOT_MASK];
++      return &mem_section[root][nr & SECTION_ROOT_MASK];
+ }
+ extern int __section_nr(struct mem_section* ms);
+ extern unsigned long usemap_size(void);
index 28a59436ba673332df1fba7d57c91aadc21f8735..21a1fbd490075cad33ac4b932d8fe041eaa19439 100644 (file)
@@ -258,3 +258,4 @@ tools-build-use-shell-instead-of-to-get-embedded-libperl-s-ccopts.patch
 dmaengine-revert-dmaengine-shdma-fix-runtime-pm-imbalance-on-error.patch
 mm-don-t-skip-swap-entry-even-if-zap_details-specified.patch
 arm64-module-remove-noload-from-linker-script.patch
+mm-sparsemem-fix-mem_section-will-never-be-null-gcc-12-warning.patch