Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754142AbdF1AIH (ORCPT ); Tue, 27 Jun 2017 20:08:07 -0400 Received: from mail-io0-f182.google.com ([209.85.223.182]:34970 "EHLO mail-io0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753975AbdF1AIC (ORCPT ); Tue, 27 Jun 2017 20:08:02 -0400 MIME-Version: 1.0 In-Reply-To: <773c52d0170a3fff971d03fc1ea8411541c4ece7.1493380763.git.geliangtang@gmail.com> References: <4db2a0ba17dc68d7bcfbd7d47b0eb22ad9a220c2.1493381463.git.geliangtang@gmail.com> <773c52d0170a3fff971d03fc1ea8411541c4ece7.1493380763.git.geliangtang@gmail.com> From: Kees Cook Date: Tue, 27 Jun 2017 17:08:00 -0700 X-Google-Sender-Auth: UIvS58gXb-nVVD_wfBb6Wl30rmM Message-ID: Subject: Re: [PATCH] powerpc/nvram: use memdup_user To: Geliang Tang Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , "linuxppc-dev@lists.ozlabs.org" , LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1323 Lines: 53 On Fri, Apr 28, 2017 at 6:45 PM, Geliang Tang wrote: > Use memdup_user() helper instead of open-coding to simplify the code. > > Signed-off-by: Geliang Tang Thanks! Applied for -next. -Kees > --- > arch/powerpc/kernel/nvram_64.c | 14 +++++--------- > 1 file changed, 5 insertions(+), 9 deletions(-) > > diff --git a/arch/powerpc/kernel/nvram_64.c b/arch/powerpc/kernel/nvram_64.c > index eae61b0..496d639 100644 > --- a/arch/powerpc/kernel/nvram_64.c > +++ b/arch/powerpc/kernel/nvram_64.c > @@ -792,21 +792,17 @@ static ssize_t dev_nvram_write(struct file *file, const char __user *buf, > count = min_t(size_t, count, size - *ppos); > count = min(count, PAGE_SIZE); > > - ret = -ENOMEM; > - tmp = kmalloc(count, GFP_KERNEL); > - if (!tmp) > - goto out; > - > - ret = -EFAULT; > - if (copy_from_user(tmp, buf, count)) > + tmp = memdup_user(buf, count); > + if (IS_ERR(tmp)) { > + ret = PTR_ERR(tmp); > goto out; > + } > > ret = ppc_md.nvram_write(tmp, count, ppos); > > -out: > kfree(tmp); > +out: > return ret; > - > } > > static long dev_nvram_ioctl(struct file *file, unsigned int cmd, > -- > 2.9.3 > -- Kees Cook Pixel Security