From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933434AbcETNlT (ORCPT ); Fri, 20 May 2016 09:41:19 -0400 Received: from e06smtp06.uk.ibm.com ([195.75.94.102]:47818 "EHLO e06smtp06.uk.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933335AbcETNlO (ORCPT ); Fri, 20 May 2016 09:41:14 -0400 X-IBM-Helo: d06dlp02.portsmouth.uk.ibm.com X-IBM-MailFrom: heiko.carstens@de.ibm.com X-IBM-RcptTo: linux-kernel@vger.kernel.org;linux-s390@vger.kernel.org Date: Fri, 20 May 2016 15:41:06 +0200 From: Heiko Carstens To: Muhammad Falak R Wani Cc: Martin Schwidefsky , Jan Kara , linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] ks390/keyboard: use memdup_user_nul(). Message-ID: <20160520134106.GF3461@osiris> References: <1463750488-12565-1-git-send-email-falakreyaz@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1463750488-12565-1-git-send-email-falakreyaz@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16052013-0025-0000-0000-00001EFAAE43 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 20, 2016 at 06:51:20PM +0530, Muhammad Falak R Wani wrote: > Use memdup_user_nul to duplicate a memory region from user-space > to kernel-space and terminate with a NULL, instead of open coding > using kmalloc + copy_from_user and explicitly NULL terminating. > > Signed-off-by: Muhammad Falak R Wani > --- > drivers/s390/char/keyboard.c | 11 +++-------- > 1 file changed, 3 insertions(+), 8 deletions(-) > > diff --git a/drivers/s390/char/keyboard.c b/drivers/s390/char/keyboard.c > index ef04a9f..f82a7dc 100644 > --- a/drivers/s390/char/keyboard.c > +++ b/drivers/s390/char/keyboard.c > @@ -438,18 +438,13 @@ do_kdgkb_ioctl(struct kbd_data *kbd, struct kbsentry __user *u_kbs, > return -EFAULT; > if (len > sizeof(u_kbs->kb_string)) > return -EINVAL; > - p = kmalloc(len, GFP_KERNEL); > - if (!p) > - return -ENOMEM; > - if (copy_from_user(p, u_kbs->kb_string, len)) { > - kfree(p); > - return -EFAULT; > - } > + p = memdup_user_nul(u_kbs->kb_string, len); > + if (IS_ERR(p)) > + return PTR_ERR(p); > /* > * Make sure the string is terminated by 0. User could have > * modified it between us running strnlen_user() and copying it. > */ > - p[len - 1] = 0; I removed the comment above as well and folded that into your patch. Applied, thanks!