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: update coredump logic to correctly use bitmap mm flags

The coredump logic is slightly different from other users in that it both
stores mm flags and additionally sets and gets using masks.

Since the MMF_DUMPABLE_* flags must remain as they are for uABI reasons,
and of course these are within the first 32-bits of the flags, it is
reasonable to provide access to these in the same fashion so this logic
can all still keep working as it has been.

Therefore, introduce coredump-specific helpers __mm_flags_get_dumpable()
and __mm_flags_set_mask_dumpable() for this purpose, and update all core
dump users of mm flags to use these.

[lorenzo.stoakes@oracle.com: abstract set_mask_bits() invocation to mm_types.h to satisfy ARC]
Link: https://lkml.kernel.org/r/0e7ad263-1ff7-446d-81fe-97cff9c0e7ed@lucifer.local
Link: https://lkml.kernel.org/r/2a5075f7e3c5b367d988178c79a3063d12ee53a9.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>
Reviewed-by: Christian Brauner <brauner@kernel.org>
Acked-by: David Hildenbrand <david@redhat.com>
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: 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
39f8049c c0951573

+43 -8
+3 -1
fs/coredump.c
··· 1103 1103 * We must use the same mm->flags while dumping core to avoid 1104 1104 * inconsistency of bit flags, since this flag is not protected 1105 1105 * by any locks. 1106 + * 1107 + * Note that we only care about MMF_DUMP* flags. 1106 1108 */ 1107 - .mm_flags = mm->flags, 1109 + .mm_flags = __mm_flags_get_dumpable(mm), 1108 1110 .vma_meta = NULL, 1109 1111 .cpu = raw_smp_processor_id(), 1110 1112 };
+1 -1
fs/exec.c
··· 1999 1999 if (WARN_ON((unsigned)value > SUID_DUMP_ROOT)) 2000 2000 return; 2001 2001 2002 - set_mask_bits(&mm->flags, MMF_DUMPABLE_MASK, value); 2002 + __mm_flags_set_mask_dumpable(mm, value); 2003 2003 } 2004 2004 2005 2005 SYSCALL_DEFINE3(execve,
+5 -2
fs/pidfs.c
··· 357 357 358 358 if ((kinfo.mask & PIDFD_INFO_COREDUMP) && !(kinfo.coredump_mask)) { 359 359 task_lock(task); 360 - if (task->mm) 361 - kinfo.coredump_mask = pidfs_coredump_mask(task->mm->flags); 360 + if (task->mm) { 361 + unsigned long flags = __mm_flags_get_dumpable(task->mm); 362 + 363 + kinfo.coredump_mask = pidfs_coredump_mask(flags); 364 + } 362 365 task_unlock(task); 363 366 } 364 367
+5 -3
fs/proc/base.c
··· 2962 2962 ret = 0; 2963 2963 mm = get_task_mm(task); 2964 2964 if (mm) { 2965 + unsigned long flags = __mm_flags_get_dumpable(mm); 2966 + 2965 2967 len = snprintf(buffer, sizeof(buffer), "%08lx\n", 2966 - ((mm->flags & MMF_DUMP_FILTER_MASK) >> 2968 + ((flags & MMF_DUMP_FILTER_MASK) >> 2967 2969 MMF_DUMP_FILTER_SHIFT)); 2968 2970 mmput(mm); 2969 2971 ret = simple_read_from_buffer(buf, count, ppos, buffer, len); ··· 3004 3002 3005 3003 for (i = 0, mask = 1; i < MMF_DUMP_FILTER_BITS; i++, mask <<= 1) { 3006 3004 if (val & mask) 3007 - set_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags); 3005 + mm_flags_set(i + MMF_DUMP_FILTER_SHIFT, mm); 3008 3006 else 3009 - clear_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags); 3007 + mm_flags_clear(i + MMF_DUMP_FILTER_SHIFT, mm); 3010 3008 } 3011 3009 3012 3010 mmput(mm);
+12
include/linux/mm_types.h
··· 1255 1255 return bitmap_read(bitmap, 0, BITS_PER_LONG); 1256 1256 } 1257 1257 1258 + /* 1259 + * Update the first system word of mm flags ONLY, applying the specified mask to 1260 + * it, then setting all flags specified by bits. 1261 + */ 1262 + static inline void __mm_flags_set_mask_bits_word(struct mm_struct *mm, 1263 + unsigned long mask, unsigned long bits) 1264 + { 1265 + unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags); 1266 + 1267 + set_mask_bits(bitmap, mask, bits); 1268 + } 1269 + 1258 1270 #define MM_MT_FLAGS (MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \ 1259 1271 MT_FLAGS_USE_RCU) 1260 1272 extern struct mm_struct init_mm;
+17 -1
include/linux/sched/coredump.h
··· 8 8 #define SUID_DUMP_USER 1 /* Dump as user of process */ 9 9 #define SUID_DUMP_ROOT 2 /* Dump as root */ 10 10 11 + static inline unsigned long __mm_flags_get_dumpable(struct mm_struct *mm) 12 + { 13 + /* 14 + * By convention, dumpable bits are contained in first 32 bits of the 15 + * bitmap, so we can simply access this first unsigned long directly. 16 + */ 17 + return __mm_flags_get_word(mm); 18 + } 19 + 20 + static inline void __mm_flags_set_mask_dumpable(struct mm_struct *mm, int value) 21 + { 22 + __mm_flags_set_mask_bits_word(mm, MMF_DUMPABLE_MASK, value); 23 + } 24 + 11 25 extern void set_dumpable(struct mm_struct *mm, int value); 12 26 /* 13 27 * This returns the actual value of the suid_dumpable flag. For things ··· 36 22 37 23 static inline int get_dumpable(struct mm_struct *mm) 38 24 { 39 - return __get_dumpable(mm->flags); 25 + unsigned long flags = __mm_flags_get_dumpable(mm); 26 + 27 + return __get_dumpable(flags); 40 28 } 41 29 42 30 #endif /* _LINUX_SCHED_COREDUMP_H */