2007-09-26 00:54:31

by Al Viro

[permalink] [raw]
Subject: [PATCH] put_user() on struct is not nice


use copy_to_user() instead...

Signed-off-by: Al Viro <[email protected]>
---
drivers/lguest/hypercalls.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/drivers/lguest/hypercalls.c b/drivers/lguest/hypercalls.c
index db6caac..5ecd60b 100644
--- a/drivers/lguest/hypercalls.c
+++ b/drivers/lguest/hypercalls.c
@@ -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");
}
--
1.5.3.GIT



2007-09-26 02:06:18

by Rusty Russell

[permalink] [raw]
Subject: Re: [PATCH] put_user() on struct is not nice

On Wed, 2007-09-26 at 01:54 +0100, Al Viro wrote:
> 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.

Signed-off-by: Jes Sorensen <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
---
drivers/lguest/hypercalls.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

===================================================================
--- linux-2.6.23-rc4.orig/drivers/lguest/hypercalls.c
+++ linux-2.6.23-rc4/drivers/lguest/hypercalls.c
@@ -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");
}


2007-09-26 03:56:58

by Al Viro

[permalink] [raw]
Subject: Re: [PATCH] put_user() on struct is not nice

On Wed, Sep 26, 2007 at 12:05:46PM +1000, Rusty Russell wrote:
> On Wed, 2007-09-26 at 01:54 +0100, Al Viro wrote:
> > 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...