linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: [PATCH] mm/nommu: Fix NULL mm dereference in __vmalloc_user_flags
  2025-01-28  7:22 [PATCH] mm/nommu: Fix NULL mm dereference in __vmalloc_user_flags sooraj
@ 2025-01-27 22:42 ` Matthew Wilcox
  0 siblings, 0 replies; 2+ messages in thread
From: Matthew Wilcox @ 2025-01-27 22:42 UTC (permalink / raw)
  To: sooraj; +Cc: linux-mm

On Tue, Jan 28, 2025 at 02:22:52AM -0500, sooraj wrote:
> Problem:
> The __vmalloc_user_flags() function attempts to acquire mmap_lock
> via current->mm without checking if the mm context exists. This causes
> a NULL pointer dereference when called from kernel threads (where
> current->mm == NULL), such as during filesystem operations.

I'm having a hard time thinking of a case where this could happen.
Could you provide a backtrace showing an example?

> Fix:
> Add a NULL check for current->mm before attempting mmap_lock operations.
> Kernel threads don't have user memory mappings, so VM_USERMAP flag
> setting can be safely skipped in this context.
> 
> Signed-off-by: sooraj <sooraj20636@gmail.com>

Do you sign cheques as 'sooraj'?  You need to use your real, legal name.

> +		struct mm_struct *mm = current->mm;
> +
> +		if(!mm){
> +			goto out;
> +		}

All kinds of whitespace problems here.  It should be:

		if (!mm)
			goto out;

>  		mmap_write_lock(current->mm);
>  		vma = find_vma(current->mm, (unsigned long)ret);

And since you've gone to the trouble of loading current->mm into
a local variable, you should use it throughout the function.

> @@ -160,6 +165,7 @@ static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
>  		mmap_write_unlock(current->mm);
>  	}
>  
> +	out:

and this should not be indented.

>  	return ret;



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] mm/nommu: Fix NULL mm dereference in __vmalloc_user_flags
@ 2025-01-28  7:22 sooraj
  2025-01-27 22:42 ` Matthew Wilcox
  0 siblings, 1 reply; 2+ messages in thread
From: sooraj @ 2025-01-28  7:22 UTC (permalink / raw)
  To: linux-mm; +Cc: sooraj

Problem:
The __vmalloc_user_flags() function attempts to acquire mmap_lock
via current->mm without checking if the mm context exists. This causes
a NULL pointer dereference when called from kernel threads (where
current->mm == NULL), such as during filesystem operations.

Fix:
Add a NULL check for current->mm before attempting mmap_lock operations.
Kernel threads don't have user memory mappings, so VM_USERMAP flag
setting can be safely skipped in this context.

Signed-off-by: sooraj <sooraj20636@gmail.com>
---
 mm/nommu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/nommu.c b/mm/nommu.c
index baa79abdaf03..df13c1c78d5b 100644
--- a/mm/nommu.c
+++ b/mm/nommu.c
@@ -152,6 +152,11 @@ static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
 	ret = __vmalloc(size, flags);
 	if (ret) {
 		struct vm_area_struct *vma;
+		struct mm_struct *mm = current->mm;
+
+		if(!mm){
+			goto out;
+		}
 
 		mmap_write_lock(current->mm);
 		vma = find_vma(current->mm, (unsigned long)ret);
@@ -160,6 +165,7 @@ static void *__vmalloc_user_flags(unsigned long size, gfp_t flags)
 		mmap_write_unlock(current->mm);
 	}
 
+	out:
 	return ret;
 }
 
-- 
2.45.2



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-01-27 22:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-01-28  7:22 [PATCH] mm/nommu: Fix NULL mm dereference in __vmalloc_user_flags sooraj
2025-01-27 22:42 ` Matthew Wilcox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox