Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1482769

[PATCH 2/7] AGPGART: Use memdup_user() rather than duplicating its implementation

From SF Markus Elfring <elfring@users.sourceforge.net>
Newsgroups linux.kernel
Subject [PATCH 2/7] AGPGART: Use memdup_user() rather than duplicating its implementation
Date 2016-09-13 22:50 +0200
Message-ID <sh2Ou-6TO-29@gated-at.bofh.it> (permalink)
References <qEuGl-43C-5@gated-at.bofh.it> <sh2EN-6PW-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 13 Sep 2016 21:00:44 +0200

* Reuse existing functionality from memdup_user() instead of keeping
  duplicate source code.

* Try this copy operation before allocating memory for the local
  variable "ksegment".

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/char/agp/compat_ioctl.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
index a2b69db..68d4dc7 100644
--- a/drivers/char/agp/compat_ioctl.c
+++ b/drivers/char/agp/compat_ioctl.c
@@ -98,11 +98,10 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
 		if (ureserve.seg_count >= 16384)
 			return -EINVAL;
 
-		usegment = kmalloc_array(ureserve.seg_count,
-					 sizeof(*usegment),
-					 GFP_KERNEL);
-		if (!usegment)
-			return -ENOMEM;
+		usegment = memdup_user((void __user *) ureserve.seg_list,
+				       sizeof(*usegment) * ureserve.seg_count);
+		if (IS_ERR(usegment))
+			return PTR_ERR(usegment);
 
 		ksegment = kmalloc_array(kreserve.seg_count,
 					 sizeof(*ksegment),
@@ -112,13 +111,6 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
 			return -ENOMEM;
 		}
 
-		if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
-				   sizeof(*usegment) * ureserve.seg_count)) {
-			kfree(usegment);
-			kfree(ksegment);
-			return -EFAULT;
-		}
-
 		for (seg = 0; seg < ureserve.seg_count; seg++) {
 			ksegment[seg].pg_start = usegment[seg].pg_start;
 			ksegment[seg].pg_count = usegment[seg].pg_count;
-- 
2.10.0

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/7] AGPGART: Fine-tuning for four function implementations SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:40 +0200
  [PATCH 6/7] AGPGART-UniNorth: Rename a jump label in  uninorth_create_gatt_table() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:50 +0200
    Re: [PATCH 6/7] AGPGART-UniNorth: Rename a jump label in  uninorth_create_gatt_table() kbuild test robot <lkp@intel.com> - 2016-09-15 19:40 +0200
      Re: [PATCH 6/7] AGPGART-UniNorth: Rename a jump label in  uninorth_create_gatt_table() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-15 20:30 +0200
  [PATCH 1/7] AGPGART: Use kmalloc_array() in  compat_agpioc_reserve_wrap() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:50 +0200
  [PATCH 4/7] AGPGART-SGI: Use kmalloc_array() in agp_sgi_init() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:50 +0200
  [PATCH 5/7] AGPGART-UniNorth: Use kmalloc_array() in  uninorth_create_gatt_table() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:50 +0200
  [PATCH 2/7] AGPGART: Use memdup_user() rather than duplicating its  implementation SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:50 +0200
  [PATCH 3/7] AGPGART: Rename jump labels in compat_agp_ioctl() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 22:50 +0200
  [PATCH 7/7] AGPGART-UniNorth: Delete an unnecessary check in  uninorth_create_gatt_table() SF Markus Elfring <elfring@users.sourceforge.net> - 2016-09-13 23:00 +0200

csiph-web