Skip to contentSkip to conversation

xen: xenfs: privcmd: check put_user() return code

PATCH In review Vasiliy Kulikov 3 participants 5 messages Oct 28, 2010 – Oct 29, 2010

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: xenfs: privcmd: check put_user() return code

put_user() may fail. In this case propagate error code from privcmd_ioctl_mmap_batch().

---
Compile tested.

 drivers/xen/xenfs/privcmd.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/xen/xenfs/privcmd.c +2 -6
index f80be7f..2eb04c8 100644
@@ -266,9 +266,7 @@ static int mmap_return_errors(void *data, void *state)
 	xen_pfn_t *mfnp = data;
 	struct mmap_batch_state *st = state;
 
-	put_user(*mfnp, st->user++);
-
-	return 0;
+	return put_user(*mfnp, st->user++);
 }
 
 static struct vm_operations_struct privcmd_vm_ops;
@@ -323,10 +321,8 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
 	up_write(&mm->mmap_sem);
 
 	if (state.err > 0) {
-		ret = 0;
-
 		state.user = m.arr;
-		traverse_pages(m.num, sizeof(xen_pfn_t),
+		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
 			       &pagelist,
 			       mmap_return_errors, &state);
 	}
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 2 lines · Vasiliy Kulikov

put_user() may fail. In this case propagate error code from privcmd_ioctl_mmap_batch().

Thanks for looking at this. I'm in two minds about this; the existing logic is such that these put_users can only fail if something else has already failed and its returning an error. I guess it would be useful to get an EFAULT if you've got a problem writing back the results.

IanC, any opinion?

Thanks,
J

Quoted 34 lines

---
Compile tested.

 drivers/xen/xenfs/privcmd.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/xen/xenfs/privcmd.c +2 -6
index f80be7f..2eb04c8 100644
@@ -266,9 +266,7 @@ static int mmap_return_errors(void *data, void *state)
 	xen_pfn_t *mfnp = data;
 	struct mmap_batch_state *st = state;
 
-	put_user(*mfnp, st->user++);
-
-	return 0;
+	return put_user(*mfnp, st->user++);
 }
 
 static struct vm_operations_struct privcmd_vm_ops;
@@ -323,10 +321,8 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
 	up_write(&mm->mmap_sem);
 
 	if (state.err > 0) {
-		ret = 0;
-
 		state.user = m.arr;
-		traverse_pages(m.num, sizeof(xen_pfn_t),
+		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
 			       &pagelist,
 			       mmap_return_errors, &state);
 	}
#2 lore raw
Quoted 10 lines · Jeremy Fitzhardinge
Quoted 2 lines · Vasiliy Kulikov

put_user() may fail. In this case propagate error code from privcmd_ioctl_mmap_batch().

Thanks for looking at this. I'm in two minds about this; the existing logic is such that these put_users can only fail if something else has already failed and its returning an error. I guess it would be useful to get an EFAULT if you've got a problem writing back the results.

IanC, any opinion?

Not a strong one.

Perhaps what we really want in this case is for traverse_pages to return the total number of callback failures it encountered rather than aborting after the first failure?

On the other hand you are correct that gather_array() has already touched all the pages which we are going to be touching here so how likely is a new failure at this point anyway?

Ian.

Quoted 39 lines

Thanks,
J

Quoted 34 lines

---
Compile tested.

 drivers/xen/xenfs/privcmd.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/xen/xenfs/privcmd.c +2 -6
index f80be7f..2eb04c8 100644
@@ -266,9 +266,7 @@ static int mmap_return_errors(void *data, void *state)
 	xen_pfn_t *mfnp = data;
 	struct mmap_batch_state *st = state;
 
-	put_user(*mfnp, st->user++);
-
-	return 0;
+	return put_user(*mfnp, st->user++);
 }
 
 static struct vm_operations_struct privcmd_vm_ops;
@@ -323,10 +321,8 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
 	up_write(&mm->mmap_sem);
 
 	if (state.err > 0) {
-		ret = 0;
-
 		state.user = m.arr;
-		traverse_pages(m.num, sizeof(xen_pfn_t),
+		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
 			       &pagelist,
 			       mmap_return_errors, &state);
 	}
#3 lore raw
Quoted 12 lines · Ian Campbell
Quoted 9 lines · Jeremy Fitzhardinge
Quoted 2 lines · Vasiliy Kulikov

put_user() may fail. In this case propagate error code from privcmd_ioctl_mmap_batch().

Thanks for looking at this. I'm in two minds about this; the existing logic is such that these put_users can only fail if something else has already failed and its returning an error. I guess it would be useful to get an EFAULT if you've got a problem writing back the results.

IanC, any opinion?

Not a strong one.

Quoted 7 lines

Perhaps what we really want in this case is for traverse_pages to return the total number of callback failures it encountered rather than aborting after the first failure?

On the other hand you are correct that gather_array() has already touched all the pages which we are going to be touching here so how likely is a new failure at this point anyway?

I could think of two cases: the array is mapped RO, so only the writeback fails, or someone changes the mapping under our feet from another thread.

J

Quoted 40 lines

Ian.

Quoted 37 lines

Thanks,
J

Quoted 34 lines

---
Compile tested.

 drivers/xen/xenfs/privcmd.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/xen/xenfs/privcmd.c +2 -6
index f80be7f..2eb04c8 100644
@@ -266,9 +266,7 @@ static int mmap_return_errors(void *data, void *state)
 	xen_pfn_t *mfnp = data;
 	struct mmap_batch_state *st = state;
 
-	put_user(*mfnp, st->user++);
-
-	return 0;
+	return put_user(*mfnp, st->user++);
 }
 
 static struct vm_operations_struct privcmd_vm_ops;
@@ -323,10 +321,8 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
 	up_write(&mm->mmap_sem);
 
 	if (state.err > 0) {
-		ret = 0;
-
 		state.user = m.arr;
-		traverse_pages(m.num, sizeof(xen_pfn_t),
+		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
 			       &pagelist,
 			       mmap_return_errors, &state);
 	}
#4 lore raw
Quoted 17 lines · Jeremy Fitzhardinge
Quoted 16 lines · Ian Campbell
Quoted 9 lines · Jeremy Fitzhardinge
Quoted 2 lines · Vasiliy Kulikov

put_user() may fail. In this case propagate error code from privcmd_ioctl_mmap_batch().

Thanks for looking at this. I'm in two minds about this; the existing logic is such that these put_users can only fail if something else has already failed and its returning an error. I guess it would be useful to get an EFAULT if you've got a problem writing back the results.

IanC, any opinion?

Not a strong one.

Perhaps what we really want in this case is for traverse_pages to return the total number of callback failures it encountered rather than aborting after the first failure?

Quoted 7 lines
Quoted 3 lines

On the other hand you are correct that gather_array() has already touched all the pages which we are going to be touching here so how likely is a new failure at this point anyway?

I could think of two cases: the array is mapped RO, so only the writeback fails, or someone changes the mapping under our feet from another thread.

I guess in that case returning EFAULT and leaving the array in whatever partially updated state we got to is the right thing to do and the proposed patch is therefore correct.

Quoted 44 lines

J

Quoted 40 lines

Ian.

Quoted 37 lines

Thanks,
J

Quoted 34 lines

---
Compile tested.

 drivers/xen/xenfs/privcmd.c |    8 ++------
 1 files changed, 2 insertions(+), 6 deletions(-)
drivers/xen/xenfs/privcmd.c +2 -6
index f80be7f..2eb04c8 100644
@@ -266,9 +266,7 @@ static int mmap_return_errors(void *data, void *state)
 	xen_pfn_t *mfnp = data;
 	struct mmap_batch_state *st = state;
 
-	put_user(*mfnp, st->user++);
-
-	return 0;
+	return put_user(*mfnp, st->user++);
 }
 
 static struct vm_operations_struct privcmd_vm_ops;
@@ -323,10 +321,8 @@ static long privcmd_ioctl_mmap_batch(void __user *udata)
 	up_write(&mm->mmap_sem);
 
 	if (state.err > 0) {
-		ret = 0;
-
 		state.user = m.arr;
-		traverse_pages(m.num, sizeof(xen_pfn_t),
+		ret = traverse_pages(m.num, sizeof(xen_pfn_t),
 			       &pagelist,
 			       mmap_return_errors, &state);
 	}