Skip to contentSkip to conversation

put_user() on struct is not nice

PATCH In review Al Viro 2 participants 3 messages Sep 26, 2007

lore
Share & tools
lore

Al Viro

author
#0 lore raw

PATCH 1/1 put_user() on struct is not nice

use copy_to_user() instead...

---
 drivers/lguest/hypercalls.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/lguest/hypercalls.c +1 -1
index db6caac..5ecd60b 100644
@@ -295,6 +295,6 @@ void write_timestamp(struct lguest *lg)
 {
 	struct timespec now;
 	ktime_get_real_ts(&now);
-	if (put_user(now, &lg->lguest_data->time))
+	if (copy_to_user(&lg->lguest_data->time, &now, sizeof(struct timespec)))
 		kill_guest(lg, "Writing timestamp");
 }
Signature · 1 line
1.5.3.GIT
#1 lore raw
Quoted 1 line · Al Viro

use copy_to_user() instead...

Thanks Al, Jes sent me the same fix which I have queued for for 2.6.24:

From: Jes Sorensen <[email protected]>

Use copy_to_user() when copying a struct timespec to the guest - put_user() cannot handle two long's in one go on a 64bit arch.

---
 drivers/lguest/hypercalls.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

===================================================================

drivers/lguest/hypercalls.c +1 -1
@@ -243,6 +243,6 @@ void write_timestamp(struct lguest *lg)
 {
 	struct timespec now;
 	ktime_get_real_ts(&now);
-	if (put_user(now, &lg->lguest_data->time))
+	if (copy_to_user(&lg->lguest_data->time, &now, sizeof(struct timespec)))
 		kill_guest(lg, "Writing timestamp");
 }
author
#2 lore raw
Quoted 4 lines · Rusty Russell
Quoted 1 line · Al Viro

use copy_to_user() instead...

Thanks Al, Jes sent me the same fix which I have queued for for 2.6.24:

OK, decision on urgency is up to you - post .23 is fine by me...