From patchwork Thu Aug 18 09:55:04 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: 9287179 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 C7C43607FF for ; Thu, 18 Aug 2016 09:55:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7C0128F13 for ; Thu, 18 Aug 2016 09:55:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC48628FF1; Thu, 18 Aug 2016 09:55:45 +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=ham 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 54C1028F13 for ; Thu, 18 Aug 2016 09:55:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753705AbcHRJzb (ORCPT ); Thu, 18 Aug 2016 05:55:31 -0400 Received: from mout.web.de ([212.227.15.14]:52004 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752864AbcHRJza (ORCPT ); Thu, 18 Aug 2016 05:55:30 -0400 Received: from [192.168.1.3] ([77.182.223.38]) by smtp.web.de (mrweb002) with ESMTPSA (Nemesis) id 0LZvrx-1at3LU2OUP-00lk6M; Thu, 18 Aug 2016 11:55:17 +0200 Subject: [PATCH 1/5] block-cciss: Use memdup_user() rather than duplicating its implementation To: esc.storagedev@microsemi.com, iss_storagedev@hp.com, linux-scsi@vger.kernel.org, Don Brace References: <566ABCD9.1060404@users.sourceforge.net> <686a1f95-a76c-2624-50e1-9d0e59948e64@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall From: SF Markus Elfring Message-ID: <15b21d09-67ce-8d70-0d76-f0414e7c43f9@users.sourceforge.net> Date: Thu, 18 Aug 2016 11:55:04 +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: <686a1f95-a76c-2624-50e1-9d0e59948e64@users.sourceforge.net> X-Provags-ID: V03:K0:tHgq/3P/o7VDhLCdZkYn+YJgTpUmHaxHlhSD2QKhxhfrvvf3JpE aMByJnajqn5UOJAtAXB2nBDnhI1ZCS2XbeXkLAEczWlN1KMXh45+sGMpBAiG3eIqtF+IrK7 JcEPnSaz7nvpn7NyG3AJid2TqOEyi0vl9xxP+s6W7Gj5G+ojXwIIyPOrfH92y0ib892/7oz UbItlSX83i6UXxn2rzgPA== X-UI-Out-Filterresults: notjunk:1; V01:K0:VTzabKyDQk4=:9CkDe8L5/VWRiEuY3ftpml fMvoq9vC9m6eY1nhFjL5htD2qlTPiI8qYJfdxoewM7o4JQ/86tZ0FgqElNQ2/sY54kbaW91Mw 0Ef5gxCKTDjqlO5hTU+e4bGJ+bhj/H0IKCyyO6Yei2KxPhgPPmxPY2vbz2o6h+Tk04eVDQL0X L7oxlvHFABCeM850NW6rhUQzJrWspBDfj5KGDWSBdj6QoOzPje8VjzD7tYkiESNS/IUvhp1in pCLlguwPUmpq+qp210i/rsBhKG4px5UjTIUWP7iIcCEmidlVuR/4EDemIuW4OvGIY2JoUSplG O9nXjbJxlSLBvnnDjHsTrwTIJTS16DKbHu1e2dRuHTeDkCvt5oNwwdBpwJj2JedDp7rniLQNl iS9DBheO/3CdIEjDaa5Jph/Y7OhLeOmA1KIMqPzqm4aUnB2Z87b9NHvWOKRZlU5JbJUla3ex4 LZV3YSxz7gSOA9KSt10+sIwbO786guJv7PkwMOHlatZvYU4Dgzn7l32yVGEQI4gXD1oaXc5EC UdaW3P3n9XWINosgJScW0PZ1ZX6LdahOVtL8nOqDNfp6F6idn12rR4yOvHeCT2QWQMxYm+kNU rIFc0oyjb9ePfwvgE7WaSFR4sTaYMtQl/LvtTb7mK7V1FNOp/ZmOHLmQZ6c5HqjQ3P8p9csNg RvfGeqlf55m6Ebzgq72oySLNtvMpI/FrQQRKfHKUVUY09wZ9x/Xv4muPI+tcIWomO+9j1Xvki mfCSFpobeQi1CYhJk/5QejHQZX6PFKMBja9LAloZ1Q6YMs+k6BXhmRl/tUwQB3qKqlwcIBHSM rGWJn8v Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Wed, 17 Aug 2016 22:10:29 +0200 * Reuse existing functionality from memdup_user() instead of keeping duplicate source code. This issue was detected by using the Coccinelle software. * Return directly if this copy operation failed. Signed-off-by: Markus Elfring --- drivers/block/cciss.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index db9d6bb..e044342 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -1587,15 +1587,9 @@ static int cciss_bigpassthru(ctlr_info_t *h, void __user *argp) return -EINVAL; if (!capable(CAP_SYS_RAWIO)) return -EPERM; - ioc = kmalloc(sizeof(*ioc), GFP_KERNEL); - if (!ioc) { - status = -ENOMEM; - goto cleanup1; - } - if (copy_from_user(ioc, argp, sizeof(*ioc))) { - status = -EFAULT; - goto cleanup1; - } + ioc = memdup_user(argp, sizeof(*ioc)); + if (IS_ERR(ioc)) + return PTR_ERR(ioc); if ((ioc->buf_size < 1) && (ioc->Request.Type.Direction != XFER_NONE)) { status = -EINVAL;