From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756066AbcETM1K (ORCPT ); Fri, 20 May 2016 08:27:10 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:8832 "EHLO mail2-relais-roc.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755982AbcETM1I (ORCPT ); Fri, 20 May 2016 08:27:08 -0400 X-IronPort-AV: E=Sophos;i="5.26,339,1459807200"; d="scan'208";a="219058521" Date: Fri, 20 May 2016 14:27:05 +0200 From: Samuel Thibault To: Muhammad Falak R Wani Cc: Greg Kroah-Hartman , Jiri Slaby , Dmitry Torokhov , Pavel Machek , linux-kernel@vger.kernel.org Subject: Re: [PATCH] tty/vt/keyboard: use memdup_user(). Message-ID: <20160520122705.GW10620@var.bordeaux.inria.fr> Mail-Followup-To: Samuel Thibault , Muhammad Falak R Wani , Greg Kroah-Hartman , Jiri Slaby , Dmitry Torokhov , Pavel Machek , linux-kernel@vger.kernel.org References: <1463747026-23968-1-git-send-email-falakreyaz@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1463747026-23968-1-git-send-email-falakreyaz@gmail.com> User-Agent: Mutt/1.5.21+34 (58baf7c9f32f) (2010-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Muhammad Falak R Wani, on Fri 20 May 2016 17:53:28 +0530, wrote: > Use memdup_user to duplicate a memory region from user-space to > kernel-space, instead of open coding using kmalloc & copy_from_user. > > Signed-off-by: Muhammad Falak R Wani Reviewed-by: Samuel Thibault > --- > drivers/tty/vt/keyboard.c | 14 ++++---------- > 1 file changed, 4 insertions(+), 10 deletions(-) > > diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c > index f973bfc..698ea43 100644 > --- a/drivers/tty/vt/keyboard.c > +++ b/drivers/tty/vt/keyboard.c > @@ -1745,16 +1745,10 @@ int vt_do_diacrit(unsigned int cmd, void __user *udp, int perm) > return -EINVAL; > > if (ct) { > - buf = kmalloc(ct * sizeof(struct kbdiacruc), > - GFP_KERNEL); > - if (buf == NULL) > - return -ENOMEM; > - > - if (copy_from_user(buf, a->kbdiacruc, > - ct * sizeof(struct kbdiacruc))) { > - kfree(buf); > - return -EFAULT; > - } > + buf = memdup_user(a->kbdiacruc, > + ct * sizeof(struct kbdiacruc)); > + if (IS_ERR(buf)) > + return PTR_ERR(buf); > } > spin_lock_irqsave(&kbd_event_lock, flags); > if (ct) > -- > 1.9.1 > -- Samuel (03:13:14) bon (03:13:19) il est tard :p (03:13:25) c'est l'heure de manger (03:13:38) hm j'ai mangé à 1h moi, j'ai des horaires raisonnables