[PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags

Lorenzo Stoakes posted 10 patches 1 month, 3 weeks ago
[PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by Lorenzo Stoakes 1 month, 3 weeks ago
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.

Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 fs/coredump.c                  |  4 +++-
 fs/exec.c                      |  2 +-
 fs/pidfs.c                     |  7 +++++--
 fs/proc/base.c                 |  8 +++++---
 include/linux/sched/coredump.h | 21 ++++++++++++++++++++-
 5 files changed, 34 insertions(+), 8 deletions(-)

diff --git a/fs/coredump.c b/fs/coredump.c
index fedbead956ed..e5d9d6276990 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -1103,8 +1103,10 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
 		 * We must use the same mm->flags while dumping core to avoid
 		 * inconsistency of bit flags, since this flag is not protected
 		 * by any locks.
+		 *
+		 * Note that we only care about MMF_DUMP* flags.
 		 */
-		.mm_flags = mm->flags,
+		.mm_flags = __mm_flags_get_dumpable(mm),
 		.vma_meta = NULL,
 		.cpu = raw_smp_processor_id(),
 	};
diff --git a/fs/exec.c b/fs/exec.c
index 2a1e5e4042a1..dbac0e84cc3e 100644
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -1999,7 +1999,7 @@ void set_dumpable(struct mm_struct *mm, int value)
 	if (WARN_ON((unsigned)value > SUID_DUMP_ROOT))
 		return;
 
-	set_mask_bits(&mm->flags, MMF_DUMPABLE_MASK, value);
+	__mm_flags_set_mask_dumpable(mm, value);
 }
 
 SYSCALL_DEFINE3(execve,
diff --git a/fs/pidfs.c b/fs/pidfs.c
index edc35522d75c..5148b7646b7f 100644
--- a/fs/pidfs.c
+++ b/fs/pidfs.c
@@ -357,8 +357,11 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
 
 	if ((kinfo.mask & PIDFD_INFO_COREDUMP) && !(kinfo.coredump_mask)) {
 		task_lock(task);
-		if (task->mm)
-			kinfo.coredump_mask = pidfs_coredump_mask(task->mm->flags);
+		if (task->mm) {
+			unsigned long flags = __mm_flags_get_dumpable(task->mm);
+
+			kinfo.coredump_mask = pidfs_coredump_mask(flags);
+		}
 		task_unlock(task);
 	}
 
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 62d35631ba8c..f0c093c58aaf 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2962,8 +2962,10 @@ static ssize_t proc_coredump_filter_read(struct file *file, char __user *buf,
 	ret = 0;
 	mm = get_task_mm(task);
 	if (mm) {
+		unsigned long flags = __mm_flags_get_dumpable(mm);
+
 		len = snprintf(buffer, sizeof(buffer), "%08lx\n",
-			       ((mm->flags & MMF_DUMP_FILTER_MASK) >>
+			       ((flags & MMF_DUMP_FILTER_MASK) >>
 				MMF_DUMP_FILTER_SHIFT));
 		mmput(mm);
 		ret = simple_read_from_buffer(buf, count, ppos, buffer, len);
@@ -3002,9 +3004,9 @@ static ssize_t proc_coredump_filter_write(struct file *file,
 
 	for (i = 0, mask = 1; i < MMF_DUMP_FILTER_BITS; i++, mask <<= 1) {
 		if (val & mask)
-			set_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
+			mm_flags_set(i + MMF_DUMP_FILTER_SHIFT, mm);
 		else
-			clear_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
+			mm_flags_clear(i + MMF_DUMP_FILTER_SHIFT, mm);
 	}
 
 	mmput(mm);
diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h
index 6eb65ceed213..19ecfcceb27a 100644
--- a/include/linux/sched/coredump.h
+++ b/include/linux/sched/coredump.h
@@ -2,12 +2,29 @@
 #ifndef _LINUX_SCHED_COREDUMP_H
 #define _LINUX_SCHED_COREDUMP_H
 
+#include <linux/compiler_types.h>
 #include <linux/mm_types.h>
 
 #define SUID_DUMP_DISABLE	0	/* No setuid dumping */
 #define SUID_DUMP_USER		1	/* Dump as user of process */
 #define SUID_DUMP_ROOT		2	/* Dump as root */
 
+static inline unsigned long __mm_flags_get_dumpable(struct mm_struct *mm)
+{
+	/*
+	 * By convention, dumpable bits are contained in first 32 bits of the
+	 * bitmap, so we can simply access this first unsigned long directly.
+	 */
+	return __mm_flags_get_word(mm);
+}
+
+static inline void __mm_flags_set_mask_dumpable(struct mm_struct *mm, int value)
+{
+	unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
+
+	set_mask_bits(bitmap, MMF_DUMPABLE_MASK, value);
+}
+
 extern void set_dumpable(struct mm_struct *mm, int value);
 /*
  * This returns the actual value of the suid_dumpable flag. For things
@@ -22,7 +39,9 @@ static inline int __get_dumpable(unsigned long mm_flags)
 
 static inline int get_dumpable(struct mm_struct *mm)
 {
-	return __get_dumpable(mm->flags);
+	unsigned long flags = __mm_flags_get_dumpable(mm);
+
+	return __get_dumpable(flags);
 }
 
 #endif /* _LINUX_SCHED_COREDUMP_H */
-- 
2.50.1
Re: [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by David Hildenbrand 1 month, 1 week ago
On 12.08.25 17:44, Lorenzo Stoakes wrote:
> 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.
> 
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
> ---

Incl. fixup LGTM

Acked-by: David Hildenbrand <david@redhat.com>

-- 
Cheers

David / dhildenb
Re: [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by Lorenzo Stoakes 1 month, 1 week ago
Hi Andrew,

The arc architecture with a specific randconfig does not like this, so I enclose
a fix-patch to satisfy this case.

From 04c8084551dbbac3cd1716164e5a19a367be652e Mon Sep 17 00:00:00 2001
From: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Date: Tue, 26 Aug 2025 12:25:16 +0100
Subject: [PATCH] mm: abstract set_mask_bits() invocation to mm_types.h to
 satisfy ARC

There's some horrible recursive header issue for ARCH whereby you can't
even apparently include very fundamental headers like compiler_types.h in
linux/sched/coredump.h.

So work around this by putting the thing that needs this (use of
ACCESS_PRIVATE()) into mm_types.h which presumably in some fashion avoids
this issue.

This also makes it consistent with __mm_flags_get_dumpable() so is a good
change to make things more consistent and neat anyway.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202508240502.frw1Krzo-lkp@intel.com/
Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
---
 include/linux/mm_types.h       | 12 ++++++++++++
 include/linux/sched/coredump.h |  5 +----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
index 0e001dbad455..205ec614171f 100644
--- a/include/linux/mm_types.h
+++ b/include/linux/mm_types.h
@@ -1255,6 +1255,18 @@ static inline unsigned long __mm_flags_get_word(const struct mm_struct *mm)
 	return bitmap_read(bitmap, 0, BITS_PER_LONG);
 }

+/*
+ * Update the first system word of mm flags ONLY, applying the specified mask to
+ * it, then setting all flags specified by bits.
+ */
+static inline void __mm_flags_set_mask_bits_word(struct mm_struct *mm,
+		unsigned long mask, unsigned long bits)
+{
+	unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
+
+	set_mask_bits(bitmap, mask, bits);
+}
+
 #define MM_MT_FLAGS	(MT_FLAGS_ALLOC_RANGE | MT_FLAGS_LOCK_EXTERN | \
 			 MT_FLAGS_USE_RCU)
 extern struct mm_struct init_mm;
diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h
index 19ecfcceb27a..b7fafe999073 100644
--- a/include/linux/sched/coredump.h
+++ b/include/linux/sched/coredump.h
@@ -2,7 +2,6 @@
 #ifndef _LINUX_SCHED_COREDUMP_H
 #define _LINUX_SCHED_COREDUMP_H

-#include <linux/compiler_types.h>
 #include <linux/mm_types.h>

 #define SUID_DUMP_DISABLE	0	/* No setuid dumping */
@@ -20,9 +19,7 @@ static inline unsigned long __mm_flags_get_dumpable(struct mm_struct *mm)

 static inline void __mm_flags_set_mask_dumpable(struct mm_struct *mm, int value)
 {
-	unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
-
-	set_mask_bits(bitmap, MMF_DUMPABLE_MASK, value);
+	__mm_flags_set_mask_bits_word(mm, MMF_DUMPABLE_MASK, value);
 }

 extern void set_dumpable(struct mm_struct *mm, int value);
--
2.50.1
Re: [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by Christian Brauner 1 month, 2 weeks ago
On Tue, Aug 12, 2025 at 04:44:15PM +0100, Lorenzo Stoakes wrote:
> 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

Why the double underscore here? Just looks a bit ugly so if we can avoid
it I would but if not:

Reviewed-by: Christian Brauner <brauner@kernel.org>
Re: [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by Lorenzo Stoakes 1 month, 2 weeks ago
On Fri, Aug 15, 2025 at 03:52:38PM +0200, Christian Brauner wrote:
> On Tue, Aug 12, 2025 at 04:44:15PM +0100, Lorenzo Stoakes wrote:
> > 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
>
> Why the double underscore here? Just looks a bit ugly so if we can avoid
> it I would but if not:
>
> Reviewed-by: Christian Brauner <brauner@kernel.org>

Thanks!

The double underscore is to fit the bitops convention of bitop() is atomic,
__bitop() is non-atomic. Obviously these operations were and are non-atomic
so this is where this came from.

I do that because the vast majority of operations on mm flags were atomic
bitops before so it is in keeping with.
Re: [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by Mike Rapoport 1 month, 3 weeks ago
On Tue, Aug 12, 2025 at 04:44:15PM +0100, Lorenzo Stoakes wrote:
> 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.
> 
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>

> ---
>  fs/coredump.c                  |  4 +++-
>  fs/exec.c                      |  2 +-
>  fs/pidfs.c                     |  7 +++++--
>  fs/proc/base.c                 |  8 +++++---
>  include/linux/sched/coredump.h | 21 ++++++++++++++++++++-
>  5 files changed, 34 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/coredump.c b/fs/coredump.c
> index fedbead956ed..e5d9d6276990 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -1103,8 +1103,10 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
>  		 * We must use the same mm->flags while dumping core to avoid
>  		 * inconsistency of bit flags, since this flag is not protected
>  		 * by any locks.
> +		 *
> +		 * Note that we only care about MMF_DUMP* flags.
>  		 */
> -		.mm_flags = mm->flags,
> +		.mm_flags = __mm_flags_get_dumpable(mm),
>  		.vma_meta = NULL,
>  		.cpu = raw_smp_processor_id(),
>  	};
> diff --git a/fs/exec.c b/fs/exec.c
> index 2a1e5e4042a1..dbac0e84cc3e 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1999,7 +1999,7 @@ void set_dumpable(struct mm_struct *mm, int value)
>  	if (WARN_ON((unsigned)value > SUID_DUMP_ROOT))
>  		return;
>  
> -	set_mask_bits(&mm->flags, MMF_DUMPABLE_MASK, value);
> +	__mm_flags_set_mask_dumpable(mm, value);
>  }
>  
>  SYSCALL_DEFINE3(execve,
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index edc35522d75c..5148b7646b7f 100644
> --- a/fs/pidfs.c
> +++ b/fs/pidfs.c
> @@ -357,8 +357,11 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
>  
>  	if ((kinfo.mask & PIDFD_INFO_COREDUMP) && !(kinfo.coredump_mask)) {
>  		task_lock(task);
> -		if (task->mm)
> -			kinfo.coredump_mask = pidfs_coredump_mask(task->mm->flags);
> +		if (task->mm) {
> +			unsigned long flags = __mm_flags_get_dumpable(task->mm);
> +
> +			kinfo.coredump_mask = pidfs_coredump_mask(flags);
> +		}
>  		task_unlock(task);
>  	}
>  
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 62d35631ba8c..f0c093c58aaf 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -2962,8 +2962,10 @@ static ssize_t proc_coredump_filter_read(struct file *file, char __user *buf,
>  	ret = 0;
>  	mm = get_task_mm(task);
>  	if (mm) {
> +		unsigned long flags = __mm_flags_get_dumpable(mm);
> +
>  		len = snprintf(buffer, sizeof(buffer), "%08lx\n",
> -			       ((mm->flags & MMF_DUMP_FILTER_MASK) >>
> +			       ((flags & MMF_DUMP_FILTER_MASK) >>
>  				MMF_DUMP_FILTER_SHIFT));
>  		mmput(mm);
>  		ret = simple_read_from_buffer(buf, count, ppos, buffer, len);
> @@ -3002,9 +3004,9 @@ static ssize_t proc_coredump_filter_write(struct file *file,
>  
>  	for (i = 0, mask = 1; i < MMF_DUMP_FILTER_BITS; i++, mask <<= 1) {
>  		if (val & mask)
> -			set_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
> +			mm_flags_set(i + MMF_DUMP_FILTER_SHIFT, mm);
>  		else
> -			clear_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
> +			mm_flags_clear(i + MMF_DUMP_FILTER_SHIFT, mm);
>  	}
>  
>  	mmput(mm);
> diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h
> index 6eb65ceed213..19ecfcceb27a 100644
> --- a/include/linux/sched/coredump.h
> +++ b/include/linux/sched/coredump.h
> @@ -2,12 +2,29 @@
>  #ifndef _LINUX_SCHED_COREDUMP_H
>  #define _LINUX_SCHED_COREDUMP_H
>  
> +#include <linux/compiler_types.h>
>  #include <linux/mm_types.h>
>  
>  #define SUID_DUMP_DISABLE	0	/* No setuid dumping */
>  #define SUID_DUMP_USER		1	/* Dump as user of process */
>  #define SUID_DUMP_ROOT		2	/* Dump as root */
>  
> +static inline unsigned long __mm_flags_get_dumpable(struct mm_struct *mm)
> +{
> +	/*
> +	 * By convention, dumpable bits are contained in first 32 bits of the
> +	 * bitmap, so we can simply access this first unsigned long directly.
> +	 */
> +	return __mm_flags_get_word(mm);
> +}
> +
> +static inline void __mm_flags_set_mask_dumpable(struct mm_struct *mm, int value)
> +{
> +	unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
> +
> +	set_mask_bits(bitmap, MMF_DUMPABLE_MASK, value);
> +}
> +
>  extern void set_dumpable(struct mm_struct *mm, int value);
>  /*
>   * This returns the actual value of the suid_dumpable flag. For things
> @@ -22,7 +39,9 @@ static inline int __get_dumpable(unsigned long mm_flags)
>  
>  static inline int get_dumpable(struct mm_struct *mm)
>  {
> -	return __get_dumpable(mm->flags);
> +	unsigned long flags = __mm_flags_get_dumpable(mm);
> +
> +	return __get_dumpable(flags);
>  }
>  
>  #endif /* _LINUX_SCHED_COREDUMP_H */
> -- 
> 2.50.1
> 

-- 
Sincerely yours,
Mike.
Re: [PATCH 06/10] mm: update coredump logic to correctly use bitmap mm flags
Posted by Liam R. Howlett 1 month, 3 weeks ago
* Lorenzo Stoakes <lorenzo.stoakes@oracle.com> [250812 11:47]:
> 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.
> 
> Signed-off-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>

Reviewed-by: Liam R. Howlett <Liam.Howlett@oracle.com>

> ---
>  fs/coredump.c                  |  4 +++-
>  fs/exec.c                      |  2 +-
>  fs/pidfs.c                     |  7 +++++--
>  fs/proc/base.c                 |  8 +++++---
>  include/linux/sched/coredump.h | 21 ++++++++++++++++++++-
>  5 files changed, 34 insertions(+), 8 deletions(-)
> 
> diff --git a/fs/coredump.c b/fs/coredump.c
> index fedbead956ed..e5d9d6276990 100644
> --- a/fs/coredump.c
> +++ b/fs/coredump.c
> @@ -1103,8 +1103,10 @@ void vfs_coredump(const kernel_siginfo_t *siginfo)
>  		 * We must use the same mm->flags while dumping core to avoid
>  		 * inconsistency of bit flags, since this flag is not protected
>  		 * by any locks.
> +		 *
> +		 * Note that we only care about MMF_DUMP* flags.
>  		 */
> -		.mm_flags = mm->flags,
> +		.mm_flags = __mm_flags_get_dumpable(mm),
>  		.vma_meta = NULL,
>  		.cpu = raw_smp_processor_id(),
>  	};
> diff --git a/fs/exec.c b/fs/exec.c
> index 2a1e5e4042a1..dbac0e84cc3e 100644
> --- a/fs/exec.c
> +++ b/fs/exec.c
> @@ -1999,7 +1999,7 @@ void set_dumpable(struct mm_struct *mm, int value)
>  	if (WARN_ON((unsigned)value > SUID_DUMP_ROOT))
>  		return;
>  
> -	set_mask_bits(&mm->flags, MMF_DUMPABLE_MASK, value);
> +	__mm_flags_set_mask_dumpable(mm, value);
>  }
>  
>  SYSCALL_DEFINE3(execve,
> diff --git a/fs/pidfs.c b/fs/pidfs.c
> index edc35522d75c..5148b7646b7f 100644
> --- a/fs/pidfs.c
> +++ b/fs/pidfs.c
> @@ -357,8 +357,11 @@ static long pidfd_info(struct file *file, unsigned int cmd, unsigned long arg)
>  
>  	if ((kinfo.mask & PIDFD_INFO_COREDUMP) && !(kinfo.coredump_mask)) {
>  		task_lock(task);
> -		if (task->mm)
> -			kinfo.coredump_mask = pidfs_coredump_mask(task->mm->flags);
> +		if (task->mm) {
> +			unsigned long flags = __mm_flags_get_dumpable(task->mm);
> +
> +			kinfo.coredump_mask = pidfs_coredump_mask(flags);
> +		}
>  		task_unlock(task);
>  	}
>  
> diff --git a/fs/proc/base.c b/fs/proc/base.c
> index 62d35631ba8c..f0c093c58aaf 100644
> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -2962,8 +2962,10 @@ static ssize_t proc_coredump_filter_read(struct file *file, char __user *buf,
>  	ret = 0;
>  	mm = get_task_mm(task);
>  	if (mm) {
> +		unsigned long flags = __mm_flags_get_dumpable(mm);
> +
>  		len = snprintf(buffer, sizeof(buffer), "%08lx\n",
> -			       ((mm->flags & MMF_DUMP_FILTER_MASK) >>
> +			       ((flags & MMF_DUMP_FILTER_MASK) >>
>  				MMF_DUMP_FILTER_SHIFT));
>  		mmput(mm);
>  		ret = simple_read_from_buffer(buf, count, ppos, buffer, len);
> @@ -3002,9 +3004,9 @@ static ssize_t proc_coredump_filter_write(struct file *file,
>  
>  	for (i = 0, mask = 1; i < MMF_DUMP_FILTER_BITS; i++, mask <<= 1) {
>  		if (val & mask)
> -			set_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
> +			mm_flags_set(i + MMF_DUMP_FILTER_SHIFT, mm);
>  		else
> -			clear_bit(i + MMF_DUMP_FILTER_SHIFT, &mm->flags);
> +			mm_flags_clear(i + MMF_DUMP_FILTER_SHIFT, mm);
>  	}
>  
>  	mmput(mm);
> diff --git a/include/linux/sched/coredump.h b/include/linux/sched/coredump.h
> index 6eb65ceed213..19ecfcceb27a 100644
> --- a/include/linux/sched/coredump.h
> +++ b/include/linux/sched/coredump.h
> @@ -2,12 +2,29 @@
>  #ifndef _LINUX_SCHED_COREDUMP_H
>  #define _LINUX_SCHED_COREDUMP_H
>  
> +#include <linux/compiler_types.h>
>  #include <linux/mm_types.h>
>  
>  #define SUID_DUMP_DISABLE	0	/* No setuid dumping */
>  #define SUID_DUMP_USER		1	/* Dump as user of process */
>  #define SUID_DUMP_ROOT		2	/* Dump as root */
>  
> +static inline unsigned long __mm_flags_get_dumpable(struct mm_struct *mm)
> +{
> +	/*
> +	 * By convention, dumpable bits are contained in first 32 bits of the
> +	 * bitmap, so we can simply access this first unsigned long directly.
> +	 */
> +	return __mm_flags_get_word(mm);
> +}
> +
> +static inline void __mm_flags_set_mask_dumpable(struct mm_struct *mm, int value)
> +{
> +	unsigned long *bitmap = ACCESS_PRIVATE(&mm->_flags, __mm_flags);
> +
> +	set_mask_bits(bitmap, MMF_DUMPABLE_MASK, value);
> +}
> +
>  extern void set_dumpable(struct mm_struct *mm, int value);
>  /*
>   * This returns the actual value of the suid_dumpable flag. For things
> @@ -22,7 +39,9 @@ static inline int __get_dumpable(unsigned long mm_flags)
>  
>  static inline int get_dumpable(struct mm_struct *mm)
>  {
> -	return __get_dumpable(mm->flags);
> +	unsigned long flags = __mm_flags_get_dumpable(mm);
> +
> +	return __get_dumpable(flags);
>  }
>  
>  #endif /* _LINUX_SCHED_COREDUMP_H */
> -- 
> 2.50.1
>