From: "Jan Beulich" Subject: [PATCH] linux-2.6.18/gntdev: add range check for IOCTL_GNTDEV_UNMAP_GRANT_REF arguments, Date: Fri, 17 Dec 2010 09:48:24 +0000 Message-ID: <4D0B3FF80200007800028A4A@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartE7CBACF8.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartE7CBACF8.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline ..., move all user memory accesses out of semaphore protected region, simplify, clean up, and remove some bogus printk()-s in gntdev_ioctl() and its helpers. The purpose of free_list_sem seems questionable: It is only ever being acquired for write access, and always with grants_sem already held in write mode. Signed-off-by: Jan Beulich --- a/drivers/xen/gntdev/gntdev.c +++ b/drivers/xen/gntdev/gntdev.c @@ -203,19 +203,12 @@ static inline unsigned long get_kernel_v * value of *offset to the offset that should be mmap()-ed in order to = map the * grant reference. */ -static int add_grant_reference(struct file *flip, +static int add_grant_reference(gntdev_file_private_data_t *private_data, struct ioctl_gntdev_grant_ref *op, uint64_t *offset) { - gntdev_file_private_data_t *private_data=20 - =3D (gntdev_file_private_data_t *) flip->private_data; - uint32_t slot_index; =20 - if (unlikely(private_data->free_list_size =3D=3D 0)) { - return -ENOMEM; - } - slot_index =3D private_data->free_list[--private_data->free_list_si= ze]; private_data->free_list[private_data->free_list_size] =3D GNTDEV_FREE_LIST_INVALID; @@ -239,19 +232,17 @@ static int add_grant_reference(struct fi * previous invocation of find_contiguous_free_range(), during the same * invocation of the driver. */ -static int add_grant_references(struct file *flip, - int count, +static int add_grant_references(gntdev_file_private_data_t *private_data, + uint32_t count, struct ioctl_gntdev_grant_ref *ops, uint32_t first_slot) { - gntdev_file_private_data_t *private_data=20 - =3D (gntdev_file_private_data_t *) flip->private_data; - int i; + uint32_t i; =09 for (i =3D 0; i < count; ++i) { =20 /* First, mark the slot's entry in the free list as = invalid. */ - int free_list_index =3D=20 + uint32_t free_list_index =3D private_data->grants[first_slot+i].u.free_list_inde= x; private_data->free_list[free_list_index] =3D=20 GNTDEV_FREE_LIST_INVALID; @@ -271,16 +262,16 @@ static int add_grant_references(struct f * GNTDEV_SLOT_INVALID. This will reduce the recorded size of the free = list to * the number of valid entries. */ -static void compress_free_list(struct file *flip)=20 +static void compress_free_list(gntdev_file_private_data_t *private_data) { - gntdev_file_private_data_t *private_data=20 - =3D (gntdev_file_private_data_t *) flip->private_data; - int i, j =3D 0, old_size, slot_index; + uint32_t i, j =3D 0, old_size; =09 old_size =3D private_data->free_list_size; for (i =3D 0; i < old_size; ++i) { if (private_data->free_list[i] !=3D GNTDEV_FREE_LIST_INVALI= D) { if (i > j) { + int32_t slot_index; + slot_index =3D private_data->free_list[i]; private_data->free_list[j] =3D slot_index; private_data->grants[slot_index].u @@ -300,19 +291,11 @@ static void compress_free_list(struct fi * * Returns the index of the first slot if a range is found, otherwise = -ENOMEM. */ -static int find_contiguous_free_range(struct file *flip, +static int find_contiguous_free_range(gntdev_file_private_data_t = *private_data, uint32_t num_slots)=20 { - gntdev_file_private_data_t *private_data=20 - =3D (gntdev_file_private_data_t *) flip->private_data; -=09 - int i; - int start_index =3D private_data->next_fit_index; - int range_start =3D 0, range_length; - - if (private_data->free_list_size < num_slots) { - return -ENOMEM; - } + uint32_t i, start_index =3D private_data->next_fit_index; + uint32_t range_start =3D 0, range_length; =20 /* First search from the start_index to the end of the array. */ range_length =3D 0; @@ -872,89 +855,82 @@ private_data_initialised: case IOCTL_GNTDEV_MAP_GRANT_REF: { struct ioctl_gntdev_map_grant_ref op; + struct ioctl_gntdev_grant_ref *refs =3D NULL; + + if (copy_from_user(&op, (void __user *)arg, sizeof(op))) + return -EFAULT; + if (unlikely(op.count <=3D 0)) + return -EINVAL; + + if (op.count > 1 && op.count <=3D private_data->grants_size= ) { + struct ioctl_gntdev_grant_ref *u; + + refs =3D kmalloc(op.count * sizeof(*refs), = GFP_KERNEL); + if (!refs) + return -ENOMEM; + u =3D ((struct ioctl_gntdev_map_grant_ref = *)arg)->refs; + if (copy_from_user(refs, (void __user *)u, + sizeof(*refs) * op.count)) { + kfree(refs); + return -EFAULT; + } + } + down_write(&private_data->grants_sem); down_write(&private_data->free_list_sem); =20 - if ((rc =3D copy_from_user(&op, (void __user *) arg,=20 - sizeof(op)))) { - rc =3D -EFAULT; - goto map_out; - } - if (unlikely(op.count <=3D 0)) { - rc =3D -EINVAL; + if (unlikely(op.count > private_data->free_list_size)) { + rc =3D -ENOMEM; goto map_out; } =20 if (op.count =3D=3D 1) { - if ((rc =3D add_grant_reference(flip, &op.refs[0], + if ((rc =3D add_grant_reference(private_data, = op.refs, &op.index)) < 0) { printk(KERN_ERR "Adding grant reference " "failed (%d).\n", rc); goto map_out; } } else { - struct ioctl_gntdev_grant_ref *refs, *u; - refs =3D kmalloc(op.count * sizeof(*refs), = GFP_KERNEL); - if (!refs) { - rc =3D -ENOMEM; - goto map_out; - } - u =3D ((struct ioctl_gntdev_map_grant_ref = *)arg)->refs; - if ((rc =3D copy_from_user(refs, - (void __user *)u, - sizeof(*refs) * op.count))= ) { - printk(KERN_ERR "Copying refs from user = failed" - " (%d).\n", rc); - rc =3D -EINVAL; - goto map_out; - } - if ((rc =3D find_contiguous_free_range(flip, = op.count)) - < 0) { + if ((rc =3D find_contiguous_free_range(private_data= , + op.count)) < = 0) { printk(KERN_ERR "Finding contiguous range = " "failed (%d).\n", rc); - kfree(refs); goto map_out; } op.index =3D rc << PAGE_SHIFT; - if ((rc =3D add_grant_references(flip, op.count, + if ((rc =3D add_grant_references(private_data, = op.count, refs, rc))) { printk(KERN_ERR "Adding grant references " "failed (%d).\n", rc); - kfree(refs); goto map_out; } - compress_free_list(flip); - kfree(refs); - } - if ((rc =3D copy_to_user((void __user *) arg,=20 - &op,=20 - sizeof(op)))) { - printk(KERN_ERR "Copying result back to user = failed " - "(%d)\n", rc); - rc =3D -EFAULT; - goto map_out; + compress_free_list(private_data); } + map_out: - up_write(&private_data->grants_sem); up_write(&private_data->free_list_sem); + up_write(&private_data->grants_sem); + + kfree(refs); + + if (!rc && copy_to_user((void __user *)arg, &op, sizeof(op)= )) + rc =3D -EFAULT; return rc; } case IOCTL_GNTDEV_UNMAP_GRANT_REF: { struct ioctl_gntdev_unmap_grant_ref op; - int i, start_index; + uint32_t i, start_index; =20 - down_write(&private_data->grants_sem); - down_write(&private_data->free_list_sem); - - if ((rc =3D copy_from_user(&op,=20 - (void __user *) arg,=20 - sizeof(op)))) { - rc =3D -EFAULT; - goto unmap_out; - } + if (copy_from_user(&op, (void __user *)arg, sizeof(op))) + return -EFAULT; =20 start_index =3D op.index >> PAGE_SHIFT; + if (start_index + op.count > private_data->grants_size) + return -EINVAL; + + down_write(&private_data->grants_sem); =20 /* First, check that all pages are in the NOT_YET_MAPPED * state. @@ -984,6 +960,8 @@ private_data_initialised: } } =20 + down_write(&private_data->free_list_sem); + /* Unmap pages and add them to the free list. */ for (i =3D 0; i < op.count; ++i) { @@ -996,9 +974,9 @@ private_data_initialised: ++private_data->free_list_size; } =20 + up_write(&private_data->free_list_sem); unmap_out: up_write(&private_data->grants_sem); - up_write(&private_data->free_list_sem); return rc; } case IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR: @@ -1007,25 +985,16 @@ private_data_initialised: struct vm_area_struct *vma; unsigned long vaddr; =20 - if ((rc =3D copy_from_user(&op,=20 - (void __user *) arg,=20 - sizeof(op)))) { - rc =3D -EFAULT; - goto get_offset_out; - } + if (copy_from_user(&op, (void __user *)arg, sizeof(op))) + return -EFAULT; + vaddr =3D (unsigned long)op.vaddr; =20 down_read(¤t->mm->mmap_sem); =09 vma =3D find_vma(current->mm, vaddr); - if (vma =3D=3D NULL) { - rc =3D -EFAULT; - goto get_offset_unlock_out; - } - if ((!vma->vm_ops) || (vma->vm_ops !=3D &gntdev_vmops)) { - printk(KERN_ERR "The vaddr specified does not = belong " - "to a gntdev instance: %#lx\n", vaddr); + if (!vma || vma->vm_ops !=3D &gntdev_vmops) { rc =3D -EFAULT; - goto get_offset_unlock_out; + goto get_offset_out; } if (vma->vm_start !=3D vaddr) { printk(KERN_ERR "The vaddr specified in an " @@ -1034,45 +1003,31 @@ private_data_initialised: "%#lx; vaddr =3D %#lx\n", vma->vm_start, vaddr); rc =3D -EFAULT; - goto get_offset_unlock_out; + goto get_offset_out; } op.offset =3D vma->vm_pgoff << PAGE_SHIFT; op.count =3D (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; + get_offset_out: up_read(¤t->mm->mmap_sem); - if ((rc =3D copy_to_user((void __user *) arg,=20 - &op,=20 - sizeof(op)))) { + if (!rc && copy_to_user((void __user *)arg, &op, sizeof(op)= )) rc =3D -EFAULT; - goto get_offset_out; - } - goto get_offset_out; - get_offset_unlock_out: - up_read(¤t->mm->mmap_sem); - get_offset_out: return rc; } case IOCTL_GNTDEV_SET_MAX_GRANTS: { struct ioctl_gntdev_set_max_grants op; - if ((rc =3D copy_from_user(&op,=20 - (void __user *) arg,=20 - sizeof(op)))) { - rc =3D -EFAULT; - goto set_max_out; - } + + if (copy_from_user(&op, (void __user *)arg, sizeof(op))) + return -EFAULT; + if (op.count > MAX_GRANTS_LIMIT) + return -EINVAL; + down_write(&private_data->grants_sem); - if (private_data->grants) { + if (unlikely(private_data->grants)) rc =3D -EBUSY; - goto set_max_unlock_out; - } - if (op.count > MAX_GRANTS_LIMIT) { - rc =3D -EINVAL; - goto set_max_unlock_out; - } =20 - rc =3D init_private_data(private_data, op.count); - set_max_unlock_out: + else + rc =3D init_private_data(private_data, op.count); up_write(&private_data->grants_sem); - set_max_out: return rc; } default: --=__PartE7CBACF8.0__= Content-Type: text/plain; name="xen-gntdev-ioctl-checks.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="xen-gntdev-ioctl-checks.patch" Subject: xen/gntdev: add range check for IOCTL_GNTDEV_UNMAP_GRANT_REF = arguments,=0A=0A..., move all user memory accesses out of semaphore = protected region,=0Asimplify, clean up, and remove some bogus printk()-s = in gntdev_ioctl()=0Aand its helpers.=0A=0AThe purpose of free_list_sem = seems questionable: It is only ever being=0Aacquired for write access, and = always with grants_sem already held=0Ain write mode.=0A=0ASigned-off-by: = Jan Beulich =0A=0A--- a/drivers/xen/gntdev/gntdev.c=0A= +++ b/drivers/xen/gntdev/gntdev.c=0A@@ -203,19 +203,12 @@ static inline = unsigned long get_kernel_v=0A * value of *offset to the offset that = should be mmap()-ed in order to map the=0A * grant reference.=0A = */=0A-static int add_grant_reference(struct file *flip,=0A+static int = add_grant_reference(gntdev_file_private_data_t *private_data,=0A = struct ioctl_gntdev_grant_ref *op,=0A = uint64_t *offset)=0A {=0A- gntdev_file_private_data_t *private_data = =0A- =3D (gntdev_file_private_data_t *) flip->private_data;=0A-= =0A uint32_t slot_index;=0A =0A- if (unlikely(private_data->free_lis= t_size =3D=3D 0)) {=0A- return -ENOMEM;=0A- }=0A-=0A = slot_index =3D private_data->free_list[--private_data->free_list_size];=0A = private_data->free_list[private_data->free_list_size]=0A = =3D GNTDEV_FREE_LIST_INVALID;=0A@@ -239,19 +232,17 @@ static int add_grant_= reference(struct fi=0A * previous invocation of find_contiguous_free_range= (), during the same=0A * invocation of the driver.=0A */=0A-static int = add_grant_references(struct file *flip,=0A- = int count,=0A+static int add_grant_references(gntdev_file_private_data_t = *private_data,=0A+ uint32_t count,=0A = struct ioctl_gntdev_grant_ref *ops,=0A = uint32_t first_slot)=0A {=0A- gntdev_file_private_data_t *private_data = =0A- =3D (gntdev_file_private_data_t *) flip->private_data;=0A- = int i;=0A+ uint32_t i;=0A =0A for (i =3D 0; i < count; ++i) {=0A = =0A /* First, mark the slot's entry in the free list as = invalid. */=0A- int free_list_index =3D =0A+ uint32_t = free_list_index =3D=0A private_data->grants[first_slot+i].= u.free_list_index;=0A private_data->free_list[free_list_index] = =3D =0A GNTDEV_FREE_LIST_INVALID;=0A@@ -271,16 = +262,16 @@ static int add_grant_references(struct f=0A * GNTDEV_SLOT_INVAL= ID. This will reduce the recorded size of the free list to=0A * the = number of valid entries.=0A */=0A-static void compress_free_list(struct = file *flip) =0A+static void compress_free_list(gntdev_file_private_data_t = *private_data)=0A {=0A- gntdev_file_private_data_t *private_data =0A- = =3D (gntdev_file_private_data_t *) flip->private_data;=0A- int i, j = =3D 0, old_size, slot_index;=0A+ uint32_t i, j =3D 0, old_size;=0A = =0A old_size =3D private_data->free_list_size;=0A for (i =3D 0; i < = old_size; ++i) {=0A if (private_data->free_list[i] !=3D = GNTDEV_FREE_LIST_INVALID) {=0A if (i > j) {=0A+ = int32_t slot_index;=0A+=0A = slot_index =3D private_data->free_list[i];=0A = private_data->free_list[j] =3D slot_index;=0A = private_data->grants[slot_index].u=0A@@ -300,19 +291,11 @@ static void = compress_free_list(struct fi=0A *=0A * Returns the index of the first = slot if a range is found, otherwise -ENOMEM.=0A */=0A-static int = find_contiguous_free_range(struct file *flip,=0A+static int find_contiguous= _free_range(gntdev_file_private_data_t *private_data,=0A = uint32_t num_slots) =0A {=0A- gntdev_file_private_data_t = *private_data =0A- =3D (gntdev_file_private_data_t *) = flip->private_data;=0A- =0A- int i;=0A- int start_index =3D = private_data->next_fit_index;=0A- int range_start =3D 0, range_length= ;=0A-=0A- if (private_data->free_list_size < num_slots) {=0A- = return -ENOMEM;=0A- }=0A+ uint32_t i, start_index =3D private_data->n= ext_fit_index;=0A+ uint32_t range_start =3D 0, range_length;=0A =0A = /* First search from the start_index to the end of the array. */=0A = range_length =3D 0;=0A@@ -872,89 +855,82 @@ private_data_initialised:=0A = case IOCTL_GNTDEV_MAP_GRANT_REF:=0A {=0A struct ioctl_gntdev= _map_grant_ref op;=0A+ struct ioctl_gntdev_grant_ref *refs =3D = NULL;=0A+=0A+ if (copy_from_user(&op, (void __user *)arg, = sizeof(op)))=0A+ return -EFAULT;=0A+ if = (unlikely(op.count <=3D 0))=0A+ return -EINVAL;=0A+=0A+ = if (op.count > 1 && op.count <=3D private_data->grants_size) {=0A+ = struct ioctl_gntdev_grant_ref *u;=0A+=0A+ = refs =3D kmalloc(op.count * sizeof(*refs), GFP_KERNEL);=0A+ = if (!refs)=0A+ return -ENOMEM;=0A+ = u =3D ((struct ioctl_gntdev_map_grant_ref *)arg)->refs;=0A+ = if (copy_from_user(refs, (void __user *)u,=0A+ = sizeof(*refs) * op.count)) {=0A+ kfree(refs)= ;=0A+ return -EFAULT;=0A+ = }=0A+ }=0A+=0A down_write(&private_data->grants_se= m);=0A down_write(&private_data->free_list_sem);=0A =0A- = if ((rc =3D copy_from_user(&op, (void __user *) arg, =0A- = sizeof(op)))) {=0A- rc =3D -EFAULT;=0A-= goto map_out;=0A- }=0A- if = (unlikely(op.count <=3D 0)) {=0A- rc =3D -EINVAL;=0A+= if (unlikely(op.count > private_data->free_list_size)) = {=0A+ rc =3D -ENOMEM;=0A goto = map_out;=0A }=0A =0A if (op.count =3D=3D 1) = {=0A- if ((rc =3D add_grant_reference(flip, &op.refs[0],= =0A+ if ((rc =3D add_grant_reference(private_data, = op.refs,=0A &op.index)) = < 0) {=0A printk(KERN_ERR "Adding grant = reference "=0A "failed (%d).\n", rc);=0A = goto map_out;=0A }=0A = } else {=0A- struct ioctl_gntdev_grant_ref *refs, = *u;=0A- refs =3D kmalloc(op.count * sizeof(*refs), = GFP_KERNEL);=0A- if (!refs) {=0A- = rc =3D -ENOMEM;=0A- goto map_out;=0A- = }=0A- u =3D ((struct ioctl_gntdev_map_gra= nt_ref *)arg)->refs;=0A- if ((rc =3D copy_from_user(= refs,=0A- (void __user = *)u,=0A- sizeof(*refs) * = op.count))) {=0A- printk(KERN_ERR "Copying = refs from user failed"=0A- " (%d).\n", = rc);=0A- rc =3D -EINVAL;=0A- = goto map_out;=0A- }=0A- if = ((rc =3D find_contiguous_free_range(flip, op.count))=0A- = < 0) {=0A+ if ((rc =3D find_contiguous_free_range(priv= ate_data,=0A+ = op.count)) < 0) {=0A printk(KERN_ERR "Finding = contiguous range "=0A "failed (%d).\n", = rc);=0A- kfree(refs);=0A = goto map_out;=0A }=0A = op.index =3D rc << PAGE_SHIFT;=0A- if ((rc =3D = add_grant_references(flip, op.count,=0A+ if ((rc = =3D add_grant_references(private_data, op.count,=0A = refs, rc))) {=0A = printk(KERN_ERR "Adding grant references "=0A = "failed (%d).\n", rc);=0A- kfree(refs);=0A = goto map_out;=0A }=0A- = compress_free_list(flip);=0A- kfree(refs);=0A- = }=0A- if ((rc =3D copy_to_user((void __user *) arg, =0A- = &op, =0A- = sizeof(op)))) {=0A- printk(KERN_ERR "Copying result = back to user failed "=0A- "(%d)\n", rc);=0A- = rc =3D -EFAULT;=0A- goto map_out;=0A+ = compress_free_list(private_data);=0A }=0A+=0A = map_out:=0A- up_write(&private_data->grants_sem);=0A = up_write(&private_data->free_list_sem);=0A+ up_write(&private_d= ata->grants_sem);=0A+=0A+ kfree(refs);=0A+=0A+ if = (!rc && copy_to_user((void __user *)arg, &op, sizeof(op)))=0A+ = rc =3D -EFAULT;=0A return rc;=0A }=0A case IOCTL_GNTDEV_U= NMAP_GRANT_REF:=0A {=0A struct ioctl_gntdev_unmap_grant_ref= op;=0A- int i, start_index;=0A+ uint32_t i, = start_index;=0A =0A- down_write(&private_data->grants_sem);=0A- = down_write(&private_data->free_list_sem);=0A-=0A- if = ((rc =3D copy_from_user(&op, =0A- = (void __user *) arg, =0A- sizeof(op)= ))) {=0A- rc =3D -EFAULT;=0A- = goto unmap_out;=0A- }=0A+ if (copy_from_user(&op, = (void __user *)arg, sizeof(op)))=0A+ return -EFAULT;=0A = =0A start_index =3D op.index >> PAGE_SHIFT;=0A+ if = (start_index + op.count > private_data->grants_size)=0A+ = return -EINVAL;=0A+=0A+ down_write(&private_data->grants_sem);=0A = =0A /* First, check that all pages are in the NOT_YET_MAPPED=0A= * state.=0A@@ -984,6 +960,8 @@ private_data_initialised:= =0A }=0A }=0A =0A+ down_write(= &private_data->free_list_sem);=0A+=0A /* Unmap pages and add = them to the free list.=0A */=0A for (i =3D 0; i < = op.count; ++i) {=0A@@ -996,9 +974,9 @@ private_data_initialised:=0A = ++private_data->free_list_size;=0A }=0A =0A+ = up_write(&private_data->free_list_sem);=0A unmap_out:=0A = up_write(&private_data->grants_sem);=0A- up_write(&private_d= ata->free_list_sem);=0A return rc;=0A }=0A case = IOCTL_GNTDEV_GET_OFFSET_FOR_VADDR:=0A@@ -1007,25 +985,16 @@ private_data_in= itialised:=0A struct vm_area_struct *vma;=0A unsigned = long vaddr;=0A =0A- if ((rc =3D copy_from_user(&op, =0A- = (void __user *) arg, =0A- = sizeof(op)))) {=0A- rc =3D -EFAULT;=0A- = goto get_offset_out;=0A- }=0A+ if = (copy_from_user(&op, (void __user *)arg, sizeof(op)))=0A+ = return -EFAULT;=0A+=0A vaddr =3D (unsigned long)op.vaddr;=0A =0A = down_read(¤t->mm->mmap_sem); =0A = vma =3D find_vma(current->mm, vaddr);=0A- if (vma =3D=3D = NULL) {=0A- rc =3D -EFAULT;=0A- = goto get_offset_unlock_out;=0A- }=0A- if ((!vma->vm_ops) = || (vma->vm_ops !=3D &gntdev_vmops)) {=0A- printk(KERN= _ERR "The vaddr specified does not belong "=0A- "to = a gntdev instance: %#lx\n", vaddr);=0A+ if (!vma || vma->vm_ops = !=3D &gntdev_vmops) {=0A rc =3D -EFAULT;=0A- = goto get_offset_unlock_out;=0A+ goto get_offset_out= ;=0A }=0A if (vma->vm_start !=3D vaddr) {=0A = printk(KERN_ERR "The vaddr specified in an "=0A@@ -1034,45 = +1003,31 @@ private_data_initialised:=0A = "%#lx; vaddr =3D %#lx\n",=0A vma->vm_start, = vaddr);=0A rc =3D -EFAULT;=0A- = goto get_offset_unlock_out;=0A+ goto get_offset_out;=0A = }=0A op.offset =3D vma->vm_pgoff << PAGE_SHIFT;=0A = op.count =3D (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;=0A+ get_offset_= out:=0A up_read(¤t->mm->mmap_sem);=0A- if = ((rc =3D copy_to_user((void __user *) arg, =0A- = &op, =0A- sizeof(op)))) {=0A+ = if (!rc && copy_to_user((void __user *)arg, &op, sizeof(op)))=0A = rc =3D -EFAULT;=0A- goto get_offset_out;=0A- = }=0A- goto get_offset_out;=0A- get_offset_unlock_o= ut:=0A- up_read(¤t->mm->mmap_sem);=0A- get_offset_out:=0A = return rc;=0A }=0A case IOCTL_GNTDEV_SET_MAX_GRANTS:= =0A {=0A struct ioctl_gntdev_set_max_grants op;=0A- = if ((rc =3D copy_from_user(&op, =0A- = (void __user *) arg, =0A- sizeof(op)= ))) {=0A- rc =3D -EFAULT;=0A- = goto set_max_out;=0A- }=0A+=0A+ if (copy_from_user(= &op, (void __user *)arg, sizeof(op)))=0A+ return = -EFAULT;=0A+ if (op.count > MAX_GRANTS_LIMIT)=0A+ = return -EINVAL;=0A+=0A down_write(&private_data->grants_sem);=0A- = if (private_data->grants) {=0A+ if (unlikely(private_data->= grants))=0A rc =3D -EBUSY;=0A- = goto set_max_unlock_out;=0A- }=0A- if (op.count > = MAX_GRANTS_LIMIT) {=0A- rc =3D -EINVAL;=0A- = goto set_max_unlock_out;=0A- } = =0A- rc =3D init_private_data(private_data, op.count);= =0A- set_max_unlock_out:=0A+ else=0A+ rc = =3D init_private_data(private_data, op.count);=0A up_write(&p= rivate_data->grants_sem);=0A- set_max_out:=0A return = rc;=0A }=0A default:=0A --=__PartE7CBACF8.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__PartE7CBACF8.0__=--