mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] futex: Use user_write_access_begin/_end() in futex_put_value()
@ 2025-08-11 14:11 Waiman Long
  2025-08-11 15:58 ` [tip: locking/urgent] " tip-bot2 for Waiman Long
  0 siblings, 1 reply; 2+ messages in thread
From: Waiman Long @ 2025-08-11 14:11 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Peter Zijlstra, Darren Hart,
	Davidlohr Bueso, André Almeida, Sebastian Andrzej Siewior
  Cc: linux-kernel, Waiman Long

Commit cec199c5e39b ("futex: Implement FUTEX2_NUMA") introduces a new
futex_put_value() helper function to write a value to the given user
address. However, it uses user_read_access_begin() before the write.
For arches that differentiate between read and write accesses, like
powerpc, futex_put_value() fails with a -EFAULT return value.  Fix that
by using the user_write_access_begin/user_write_access_end() pair.

Fixes: cec199c5e39b ("futex: Implement FUTEX2_NUMA")
Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/futex/futex.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
index c74eac572acd..2cd57096c38e 100644
--- a/kernel/futex/futex.h
+++ b/kernel/futex/futex.h
@@ -319,13 +319,13 @@ static __always_inline int futex_put_value(u32 val, u32 __user *to)
 {
 	if (can_do_masked_user_access())
 		to = masked_user_access_begin(to);
-	else if (!user_read_access_begin(to, sizeof(*to)))
+	else if (!user_write_access_begin(to, sizeof(*to)))
 		return -EFAULT;
 	unsafe_put_user(val, to, Efault);
-	user_read_access_end();
+	user_write_access_end();
 	return 0;
 Efault:
-	user_read_access_end();
+	user_write_access_end();
 	return -EFAULT;
 }
 
-- 
2.50.1


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

* [tip: locking/urgent] futex: Use user_write_access_begin/_end() in futex_put_value()
  2025-08-11 14:11 [PATCH v3] futex: Use user_write_access_begin/_end() in futex_put_value() Waiman Long
@ 2025-08-11 15:58 ` tip-bot2 for Waiman Long
  0 siblings, 0 replies; 2+ messages in thread
From: tip-bot2 for Waiman Long @ 2025-08-11 15:58 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: Waiman Long, Thomas Gleixner, stable, x86, linux-kernel

The following commit has been merged into the locking/urgent branch of tip:

Commit-ID:     dfb36e4a8db0cd56f92d4cb445f54e85a9b40897
Gitweb:        https://git.kernel.org/tip/dfb36e4a8db0cd56f92d4cb445f54e85a9b40897
Author:        Waiman Long <longman@redhat.com>
AuthorDate:    Mon, 11 Aug 2025 10:11:47 -04:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Mon, 11 Aug 2025 17:53:21 +02:00

futex: Use user_write_access_begin/_end() in futex_put_value()

Commit cec199c5e39b ("futex: Implement FUTEX2_NUMA") introduced the
futex_put_value() helper to write a value to the given user
address.

However, it uses user_read_access_begin() before the write. For
architectures that differentiate between read and write accesses, like
PowerPC, futex_put_value() fails with -EFAULT.

Fix that by using the user_write_access_begin/user_write_access_end() pair
instead.

Fixes: cec199c5e39b ("futex: Implement FUTEX2_NUMA")
Signed-off-by: Waiman Long <longman@redhat.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20250811141147.322261-1-longman@redhat.com
---
 kernel/futex/futex.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
index c74eac5..2cd5709 100644
--- a/kernel/futex/futex.h
+++ b/kernel/futex/futex.h
@@ -319,13 +319,13 @@ static __always_inline int futex_put_value(u32 val, u32 __user *to)
 {
 	if (can_do_masked_user_access())
 		to = masked_user_access_begin(to);
-	else if (!user_read_access_begin(to, sizeof(*to)))
+	else if (!user_write_access_begin(to, sizeof(*to)))
 		return -EFAULT;
 	unsafe_put_user(val, to, Efault);
-	user_read_access_end();
+	user_write_access_end();
 	return 0;
 Efault:
-	user_read_access_end();
+	user_write_access_end();
 	return -EFAULT;
 }
 

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

end of thread, other threads:[~2025-08-11 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-11 14:11 [PATCH v3] futex: Use user_write_access_begin/_end() in futex_put_value() Waiman Long
2025-08-11 15:58 ` [tip: locking/urgent] " tip-bot2 for Waiman Long

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

all inboxes | Powered by JetHome®