From patchwork Sun Aug 21 18:26:15 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: 9292643 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 E5C38600CB for ; Sun, 21 Aug 2016 18:26:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D063C2872B for ; Sun, 21 Aug 2016 18:26:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE3F2289BE; Sun, 21 Aug 2016 18:26:33 +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 593A42872B for ; Sun, 21 Aug 2016 18:26:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752174AbcHUS0b (ORCPT ); Sun, 21 Aug 2016 14:26:31 -0400 Received: from mout.web.de ([212.227.15.3]:58276 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752011AbcHUS0b (ORCPT ); Sun, 21 Aug 2016 14:26:31 -0400 Received: from [192.168.1.3] ([77.181.85.179]) by smtp.web.de (mrweb004) with ESMTPSA (Nemesis) id 0MJZLX-1bZcZO1v91-0032S6; Sun, 21 Aug 2016 20:26:17 +0200 Subject: [PATCH] Smack: Use memdup_user() rather than duplicating its implementation References: <566ABCD9.1060404@users.sourceforge.net> Cc: LKML , kernel-janitors@vger.kernel.org, Julia Lawall , Nicolas Palix To: linux-security-module@vger.kernel.org, Casey Schaufler , James Morris , "Serge E. Hallyn" From: SF Markus Elfring Message-ID: Date: Sun, 21 Aug 2016 20:26:15 +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: <566ABCD9.1060404@users.sourceforge.net> X-Provags-ID: V03:K0:E0xR24v/KCZ/IM9Z+lSunHyS7QTj+uqKfHx8Yr7cPqaBA5zsrlg KJ+NiNM632BZlGq42dUBZHjTV5FYqHDnfwypyJBkqlSkmlYtcVie6x4W+wPX9GEZVViAb6n it88GNH51CTQt8GZaHxfo37NXA6JpM6RsLZSnmmKZoly0zu2m0PwdPBecAPuYVZgfOE9hws AZStnVpp0K4p8ktxj7ZEw== X-UI-Out-Filterresults: notjunk:1; V01:K0:LzxOnj2SZNA=:8EjfQBHxRtldvTkdPpLUTz ng/rUkpdGjwf4O1VQZUfR8L/OOSrAI2wkpDbGrtzasIQbWKlkDENYOXlfN0ArANM5KeyZRMH6 32nVVP8/UrLCozwfGlDE+wk3k1dCXL3NgZpY/1IUBHp4AJBPL1MVPXmFyeFK4ANxpr6uHioR9 2YtM9qsi+jouj8wdKVyRDZevdh1cg+ejYX197MnW4ZcLEuMN4osaiMMLfLOypjE+OMIIQgmtF CxO65aFKA8ybjDxn3hd3V1M8ziL6zgZsjfTxcKRgrSsU3XpYNiPJGb/GYKx5kTaBQ5Q6SgRPp Tpu6vgrAggJkZXj438M3qyGE5huxdC8TIobly2nfSvCwn9yAmyRctovYuBfjWzZATrc3AudED Evy6hLRrWMXoNxpN7h8m7jpj6CVZhvs155+7PUeVraskjApPoIUuTHh5bdhcgVGW1NlssrD9i KsseIMiaJ6ktluiJxqeq72KoNEhAeQ/8BhO9IBKzkFZpVdTSQ3mdMuOuK+aXfApwckW1DmqmO RGbigAMni2q1Gwf8BAEtuBAK8QTyNQVxzigrKpCHu4goCgcYm7nQnquYx/Z3qIMUtHy8lSm/c URMMPIf7FlmYLe9KaXZwMT1gj7yfdjXRL1MXNWQTfScxEdw/oXmt2j7MC3/zaZy7xVBiLWQgg NjRtUITfpOWfNKEo3D9yHgrecSZ2ZlbOcW7gJYHFA4wDqBCudSPdgpHuTfrVqZ8Go5duEQXFn X/NtsX4xcPWfA7TerirXGQ7P8r6a0rVYGISjMFaH2eP+2dy8qtKOhTqjt+gQgAkbEhxtjY/EL oGrn17F Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP From: Markus Elfring Date: Sun, 21 Aug 2016 20:17:36 +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 Acked-by: Casey Schaufler --- security/smack/smackfs.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index e249a66..6492fe9 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -2523,14 +2523,9 @@ static ssize_t smk_write_revoke_subj(struct file *file, const char __user *buf, if (count == 0 || count > SMK_LONGLABEL) return -EINVAL; - data = kzalloc(count, GFP_KERNEL); - if (data == NULL) - return -ENOMEM; - - if (copy_from_user(data, buf, count) != 0) { - rc = -EFAULT; - goto out_data; - } + data = memdup_user(buf, count); + if (IS_ERR(data)) + return PTR_ERR(data); cp = smk_parse_smack(data, count); if (IS_ERR(cp)) {