Skip to contentSkip to conversation

68328serial: check return value of copy_*_user() instead of access_ok()

PATCH Superseded Kulikov Vasiliy 2 participants 3 messages Jul 31, 2010 – Aug 1, 2010 Kernel janitors

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/7 68328serial: check return value of copy_*_user() instead of access_ok()

As copy_*_user() calls access_ok() it should not be called explicitly.

---
 drivers/serial/68328serial.c |   29 ++++++++++-------------------
 1 files changed, 10 insertions(+), 19 deletions(-)
drivers/serial/68328serial.c +10 -19
index 7356a56..ab6ad8b 100644
@@ -869,7 +869,9 @@ static int get_serial_info(struct m68k_serial * info,
 	tmp.close_delay = info->close_delay;
 	tmp.closing_wait = info->closing_wait;
 	tmp.custom_divisor = info->custom_divisor;
-	copy_to_user(retinfo,&tmp,sizeof(*retinfo));
+	if (copy_to_user(retinfo, &tmp, sizeof(*retinfo)))
+		return -EFAULT;
+
 	return 0;
 }
 
@@ -882,7 +884,8 @@ static int set_serial_info(struct m68k_serial * info,
 
 	if (!new_info)
 		return -EFAULT;
-	copy_from_user(&new_serial,new_info,sizeof(new_serial));
+	if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
+		return -EFAULT;
 	old_info = *info;
 
 	if (!capable(CAP_SYS_ADMIN)) {
@@ -943,8 +946,7 @@ static int get_lsr_info(struct m68k_serial * info, unsigned int *value)
 	status = 0;
 #endif
 	local_irq_restore(flags);
-	put_user(status,value);
-	return 0;
+	return put_user(status, value);
 }
 
 /*
@@ -999,27 +1001,16 @@ static int rs_ioctl(struct tty_struct *tty, struct file * file,
 			send_break(info, arg ? arg*(100) : 250);
 			return 0;
 		case TIOCGSERIAL:
-			if (access_ok(VERIFY_WRITE, (void *) arg,
-						sizeof(struct serial_struct)))
-				return get_serial_info(info,
-					       (struct serial_struct *) arg);
-			return -EFAULT;
+			return get_serial_info(info,
+				       (struct serial_struct *) arg);
 		case TIOCSSERIAL:
 			return set_serial_info(info,
 					       (struct serial_struct *) arg);
 		case TIOCSERGETLSR: /* Get line status register */
-			if (access_ok(VERIFY_WRITE, (void *) arg,
-						sizeof(unsigned int)))
-				return get_lsr_info(info, (unsigned int *) arg);
-			return -EFAULT;
+			return get_lsr_info(info, (unsigned int *) arg);
 		case TIOCSERGSTRUCT:
-			if (!access_ok(VERIFY_WRITE, (void *) arg,
-						sizeof(struct m68k_serial)))
-				return -EFAULT;
-			copy_to_user((struct m68k_serial *) arg,
+			return copy_to_user((struct m68k_serial *) arg,
 				    info, sizeof(struct m68k_serial));
-			return 0;
-			
 		default:
 			return -ENOIOCTLCMD;
 		}
Signature · 1 line
1.7.0.4
#1 lore raw

drivers/serial/68328serial.c static int rs_ioctl(struct tty_struct *tty, struct file * file, · line 1013

Quoted 5 lines · Kulikov Vasiliy
drivers/serial/68328serial.c +1 -3
-						sizeof(struct m68k_serial)))
-				return -EFAULT;
-			copy_to_user((struct m68k_serial *) arg,
+			return copy_to_user((struct m68k_serial *) arg,
 				    info, sizeof(struct m68k_serial));

We should return if -EFAULT copy_to_user() failes here.

drivers/serial/68328serial.c static int rs_ioctl(struct tty_struct *tty, struct file * file, · line 1016

Quoted 5 lines
drivers/serial/68328serial.c +0 -2
-			return 0;
-			
 		default:
 			return -ENOIOCTLCMD;
 		}

Smatch would have caught that but I don't have a cross compile environment set up.

regards,
dan carpenter

#2 lore raw
Quoted 8 lines · Dan Carpenter

drivers/serial/68328serial.c static int rs_ioctl(struct tty_struct *tty, struct file * file, · line 1013

Quoted 5 lines · Kulikov Vasiliy
drivers/serial/68328serial.c +1 -3
-						sizeof(struct m68k_serial)))
-				return -EFAULT;
-			copy_to_user((struct m68k_serial *) arg,
+			return copy_to_user((struct m68k_serial *) arg,
 				    info, sizeof(struct m68k_serial));

We should return if -EFAULT copy_to_user() failes here.

Right, I was looking for this bug and made it myself :) Thank you.

Quoted 12 lines

drivers/serial/68328serial.c static int rs_ioctl(struct tty_struct *tty, struct file * file, · line 1016

Quoted 6 lines
drivers/serial/68328serial.c +0 -2
-			return 0;
-			
 		default:
 			return -ENOIOCTLCMD;
 		}

Smatch would have caught that but I don't have a cross compile environment set up.

regards,
dan carpenter