Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm: correct sign-extension issue in MMF_* flag masks

There is an issue with the mask declarations in linux/mm_types.h, which
naively do (1 << bit) operations. Unfortunately this results in the 1
being defaulted as a signed (32-bit) integer.

When the compiler expands the MMF_INIT_MASK bitmask it comes up with:

(((1 << 2) - 1) | (((1 << 9) - 1) << 2) | (1 << 24) | (1 << 28) | (1 << 30)
| (1 << 31))

Which overflows the signed integer to -788,527,105. Implicitly casting
this to an unsigned integer results in sign-expansion, and thus this value
becomes 0xffffffffd10007ff, rather than the intended 0xd10007ff.

While we're limited to a maximum of 32 bits in mm->flags, this isn't an
issue as the remaining bits being masked will always be zero.

However, now we are moving towards having more bits in this flag, this
becomes an issue.

Simply resolve this by using the _BITUL() helper to cast the shifted value
to an unsigned long.

[lorenzo.stoakes@oracle.com: prefer BIT() to _BITUL()]
Link: https://lkml.kernel.org/r/a0290c77-cd88-46d6-8d9a-073be7600d88@lucifer.local
Link: https://lkml.kernel.org/r/f92194bee8c92a04fd4c9b2c14c7e65229639300.1755012943.git.lorenzo.stoakes@oracle.com
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Barry Song <baohua@kernel.org>
Cc: Ben Segall <bsegall@google.com>
Cc: Borislav Betkov <bp@alien8.de>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dev Jain <dev.jain@arm.com>
Cc: Dietmar Eggemann <dietmar.eggemann@arm.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jann Horn <jannh@google.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Juri Lelli <juri.lelli@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Kees Cook <kees@kernel.org>
Cc: Marc Rutland <mark.rutland@arm.com>
Cc: Mariano Pache <npache@redhat.com>
Cc: "Masami Hiramatsu (Google)" <mhiramat@kernel.org>
Cc: Mateusz Guzik <mjguzik@gmail.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Mel Gorman <mgorman <mgorman@suse.de>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Namhyung kim <namhyung@kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Xu <peterx@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Sven Schnelle <svens@linux.ibm.com>
Cc: Thomas Gleinxer <tglx@linutronix.de>
Cc: Valentin Schneider <vschneid@redhat.com>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincent Guittot <vincent.guittot@linaro.org>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: xu xin <xu.xin16@zte.com.cn>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Lorenzo Stoakes and committed by
Andrew Morton
01f86753 39f8049c

+9 -10
+9 -10
include/linux/mm_types.h
··· 1767 1767 * the modes are SUID_DUMP_* defined in linux/sched/coredump.h 1768 1768 */ 1769 1769 #define MMF_DUMPABLE_BITS 2 1770 - #define MMF_DUMPABLE_MASK ((1 << MMF_DUMPABLE_BITS) - 1) 1770 + #define MMF_DUMPABLE_MASK (BIT(MMF_DUMPABLE_BITS) - 1) 1771 1771 /* coredump filter bits */ 1772 1772 #define MMF_DUMP_ANON_PRIVATE 2 1773 1773 #define MMF_DUMP_ANON_SHARED 3 ··· 1782 1782 #define MMF_DUMP_FILTER_SHIFT MMF_DUMPABLE_BITS 1783 1783 #define MMF_DUMP_FILTER_BITS 9 1784 1784 #define MMF_DUMP_FILTER_MASK \ 1785 - (((1 << MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT) 1785 + ((BIT(MMF_DUMP_FILTER_BITS) - 1) << MMF_DUMP_FILTER_SHIFT) 1786 1786 #define MMF_DUMP_FILTER_DEFAULT \ 1787 - ((1 << MMF_DUMP_ANON_PRIVATE) | (1 << MMF_DUMP_ANON_SHARED) |\ 1788 - (1 << MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF) 1787 + (BIT(MMF_DUMP_ANON_PRIVATE) | BIT(MMF_DUMP_ANON_SHARED) | \ 1788 + BIT(MMF_DUMP_HUGETLB_PRIVATE) | MMF_DUMP_MASK_DEFAULT_ELF) 1789 1789 1790 1790 #ifdef CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS 1791 - # define MMF_DUMP_MASK_DEFAULT_ELF (1 << MMF_DUMP_ELF_HEADERS) 1791 + # define MMF_DUMP_MASK_DEFAULT_ELF BIT(MMF_DUMP_ELF_HEADERS) 1792 1792 #else 1793 1793 # define MMF_DUMP_MASK_DEFAULT_ELF 0 1794 1794 #endif ··· 1808 1808 #define MMF_UNSTABLE 22 /* mm is unstable for copy_from_user */ 1809 1809 #define MMF_HUGE_ZERO_FOLIO 23 /* mm has ever used the global huge zero folio */ 1810 1810 #define MMF_DISABLE_THP 24 /* disable THP for all VMAs */ 1811 - #define MMF_DISABLE_THP_MASK (1 << MMF_DISABLE_THP) 1811 + #define MMF_DISABLE_THP_MASK BIT(MMF_DISABLE_THP) 1812 1812 #define MMF_OOM_REAP_QUEUED 25 /* mm was queued for oom_reaper */ 1813 1813 #define MMF_MULTIPROCESS 26 /* mm is shared between processes */ 1814 1814 /* ··· 1821 1821 #define MMF_HAS_PINNED 27 /* FOLL_PIN has run, never cleared */ 1822 1822 1823 1823 #define MMF_HAS_MDWE 28 1824 - #define MMF_HAS_MDWE_MASK (1 << MMF_HAS_MDWE) 1825 - 1824 + #define MMF_HAS_MDWE_MASK BIT(MMF_HAS_MDWE) 1826 1825 1827 1826 #define MMF_HAS_MDWE_NO_INHERIT 29 1828 1827 1829 1828 #define MMF_VM_MERGE_ANY 30 1830 - #define MMF_VM_MERGE_ANY_MASK (1 << MMF_VM_MERGE_ANY) 1829 + #define MMF_VM_MERGE_ANY_MASK BIT(MMF_VM_MERGE_ANY) 1831 1830 1832 1831 #define MMF_TOPDOWN 31 /* mm searches top down by default */ 1833 - #define MMF_TOPDOWN_MASK (1 << MMF_TOPDOWN) 1832 + #define MMF_TOPDOWN_MASK BIT(MMF_TOPDOWN) 1834 1833 1835 1834 #define MMF_INIT_MASK (MMF_DUMPABLE_MASK | MMF_DUMP_FILTER_MASK |\ 1836 1835 MMF_DISABLE_THP_MASK | MMF_HAS_MDWE_MASK |\