linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] futex: Fix fault_in_user_writeable()
@ 2021-08-16  6:54 Huacai Chen
  2021-08-16 18:27 ` Davidlohr Bueso
  0 siblings, 1 reply; 10+ messages in thread
From: Huacai Chen @ 2021-08-16  6:54 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, Thomas Bogendoerfer
  Cc: linux-mips, linux-kernel, Xuefeng Li, Huacai Chen, Jiaxun Yang,
	Huacai Chen, Hongchen Zhang

fault_in_user_writeable() should verify R/W access but only verify W. In
most archs W implies R, but not true in MIPS and LoongArch, so fix it.

Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 kernel/futex.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/kernel/futex.c b/kernel/futex.c
index 2ecb07575055..c3b68be31bf3 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -672,10 +672,15 @@ static int get_futex_key(u32 __user *uaddr, bool fshared, union futex_key *key,
  */
 static int fault_in_user_writeable(u32 __user *uaddr)
 {
-	struct mm_struct *mm = current->mm;
 	int ret;
+	struct mm_struct *mm = current->mm;
+	struct vm_area_struct *vma;
 
 	mmap_read_lock(mm);
+	vma = find_vma(mm, (unsigned long)uaddr);
+	if (!(vma->vm_flags & VM_READ))
+		ret = -EFAULT;
+
 	ret = fixup_user_fault(mm, (unsigned long)uaddr,
 			       FAULT_FLAG_WRITE, NULL);
 	mmap_read_unlock(mm);
-- 
2.27.0


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

end of thread, other threads:[~2021-08-17 12:27 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-16  6:54 [PATCH] futex: Fix fault_in_user_writeable() Huacai Chen
2021-08-16 18:27 ` Davidlohr Bueso
2021-08-16 19:03   ` Thomas Gleixner
2021-08-17  1:53     ` Huacai Chen
2021-08-17  7:07       ` Thomas Gleixner
2021-08-17  7:38         ` Huacai Chen
2021-08-17  9:05           ` Thomas Gleixner
2021-08-17  9:45             ` Peter Zijlstra
2021-08-17 12:27               ` Huacai Chen
2021-08-17  9:22       ` Peter Zijlstra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).