From patchwork Sat Aug 20 16:45:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SF Markus Elfring X-Patchwork-Id: 9291767 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AE779600CB for ; Sat, 20 Aug 2016 16:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B01C28BE0 for ; Sat, 20 Aug 2016 16:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8E71B28BE4; Sat, 20 Aug 2016 16:45:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D58B28BE0 for ; Sat, 20 Aug 2016 16:45:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753943AbcHTQpO (ORCPT ); Sat, 20 Aug 2016 12:45:14 -0400 Received: from mout.web.de ([212.227.15.4]:58396 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752844AbcHTQpN (ORCPT ); Sat, 20 Aug 2016 12:45:13 -0400 Received: from [192.168.1.3] ([77.181.94.18]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0MTxth-1bkKMG225p-00QlGj; Sat, 20 Aug 2016 18:45:09 +0200 Subject: [PATCH 1/3] hostap: Use memdup_user() rather than duplicating its implementation To: linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Jouni Malinen , Kalle Valo References: <566ABCD9.1060404@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: Date: Sat, 20 Aug 2016 18:45:08 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2 MIME-Version: 1.0 In-Reply-To: X-Provags-ID: V03:K0:N//zojhAnoRS1VqNGEqoiuUgFLt39nb4rqs5QP58M1x+q2MwWIX ZynmsOpelPi6ju54crNKyGvfISMfa6ClTvfylIMxkh3Wc2oo7Hahehv7megxqQ/a2oJnZyZ 9+IUP3XkaW9lxikbyYN/kjIR1XiqNWU8ZQRCdVjks6uqLF++ciMVSb3wk6hDIeC0chyYCbe gRRiUd4dpajTnN6lyNuSg== X-UI-Out-Filterresults: notjunk:1; V01:K0:nrmPIWVzO/k=:elC2xXB0ZZCYBJAfs7raYU wCKRC6eZJINJ3bo3LXl9Wd9t47PjL/t2hmf8/EKOW4mX/ViW8NSIv6IRKCtVs0daHRBon/Akx 85jeHRzBlcHDMQCrw8+cpy8TPudzTcm+U9iJ5YhmSdOH0JpUhc/Y6aMB7S+s7zvesr6Z4IUQV NIxG5dSzAMIE5yrFyZM7XGiMWF+vuNqIKPVgYRoksFLuqEolyjsAOYjv+afXgoILuKX4X5ljz xTqTLz/Gc+4rHklsnHnRePiy6z8dPPButR5TH11eIMzNlQ43MaDxJRTMO6EY/TAqzYnYG7+op gCmog78WRlpg0tayWyWkpsKgr5PPz76T/e6GnNz+NiZeelq/m3M0iKTBWrARsY7QcJ2IkQd+P 5dT50not6dOEgUDq2CEo9Mzc8BFC6aLkHZyWASuEiO4iJHXkuPXRwS1qZDk1NRPqxAX9T3+bH 5OrZKRfBOzcTy4uAhGudkwCOAHOKz5NeFlABTsAVoZ0YUbRNIMdsq5qLKAe9vtBZ2AQXSiwYr zBxkQSZm6BhdhWS3WdUZsgoIxZc7S9NUOidQQ+DHlVPtp7t1h9tG1RdML+4CQJj39fo6hRza6 0do2qLPIA3DLUSyl5Clt15eloimdAhLWwLigr57O6Y6OqSyG01UQVqJ+PyJoXLeHufcisBFXX /JCzuiRJ0jXY66eLThJ3zz+hcbmsu1fiG6gpdr4pcVOtSeprtcQiyoRwS17DV2fkjVvCNkvmr O6EEs1PpJlMUo7P9/hZZVpJrcI5dtJq+YQ2AspihXpuXxTwySfwDP4qbWQl9y/9ipBXECniJz TiRHu/6 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sat, 20 Aug 2016 18:19:43 +0200 Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. Signed-off-by: Markus Elfring --- .../net/wireless/intersil/hostap/hostap_ioctl.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/intersil/hostap/hostap_ioctl.c b/drivers/net/wireless/intersil/hostap/hostap_ioctl.c index 3e5fa78..4e271f9 100644 --- a/drivers/net/wireless/intersil/hostap/hostap_ioctl.c +++ b/drivers/net/wireless/intersil/hostap/hostap_ioctl.c @@ -3041,14 +3041,9 @@ static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p) p->length > 1024 || !p->pointer) return -EINVAL; - param = kmalloc(p->length, GFP_KERNEL); - if (param == NULL) - return -ENOMEM; - - if (copy_from_user(param, p->pointer, p->length)) { - ret = -EFAULT; - goto out; - } + param = memdup_user(p->pointer, p->length); + if (IS_ERR(param)) + return PTR_ERR(param); if (p->length < sizeof(struct prism2_download_param) + param->num_areas * sizeof(struct prism2_download_area)) { @@ -3803,14 +3798,9 @@ static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p) p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) return -EINVAL; - param = kmalloc(p->length, GFP_KERNEL); - if (param == NULL) - return -ENOMEM; - - if (copy_from_user(param, p->pointer, p->length)) { - ret = -EFAULT; - goto out; - } + param = memdup_user(p->pointer, p->length); + if (IS_ERR(param)) + return PTR_ERR(param); switch (param->cmd) { case PRISM2_SET_ENCRYPTION: