From patchwork Tue Apr 14 10:35:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zou Wei X-Patchwork-Id: 11487193 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11D6D15AB for ; Tue, 14 Apr 2020 10:30:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 028302064A for ; Tue, 14 Apr 2020 10:30:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438332AbgDNK3y (ORCPT ); Tue, 14 Apr 2020 06:29:54 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:43032 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2438318AbgDNK3n (ORCPT ); Tue, 14 Apr 2020 06:29:43 -0400 Received: from DGGEMS408-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E20FCF51D61FC81688AE; Tue, 14 Apr 2020 18:29:11 +0800 (CST) Received: from linux-lmwb.huawei.com (10.175.103.112) by DGGEMS408-HUB.china.huawei.com (10.3.19.208) with Microsoft SMTP Server id 14.3.487.0; Tue, 14 Apr 2020 18:29:05 +0800 From: Zou Wei To: , , , , , , CC: Zou Wei Subject: [PATCH -next v2] IMA: fix memdup.cocci warnings Date: Tue, 14 Apr 2020 18:35:28 +0800 Message-ID: <1586860528-71897-1-git-send-email-zou_wei@huawei.com> X-Mailer: git-send-email 2.6.2 MIME-Version: 1.0 X-Originating-IP: [10.175.103.112] X-CFilter-Loop: Reflected Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: Fixes coccicheck warning: security/integrity/ima/ima_policy.c:272:10-17: WARNING opportunity for kmemdup Use kmemdup rather than duplicating its implementation Fixes: b16942455193 ("ima: use the lsm policy update notifier") Reported-by: Hulk Robot Signed-off-by: Zou Wei --- security/integrity/ima/ima_policy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index c334e0d..185f8d7 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c @@ -269,7 +269,7 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry) struct ima_rule_entry *nentry; int i; - nentry = kmalloc(sizeof(*nentry), GFP_KERNEL); + nentry = kmemdup(entry, sizeof(*nentry), GFP_KERNEL); if (!nentry) return NULL; @@ -277,7 +277,6 @@ static struct ima_rule_entry *ima_lsm_copy_rule(struct ima_rule_entry *entry) * Immutable elements are copied over as pointers and data; only * lsm rules can change */ - memcpy(nentry, entry, sizeof(*nentry)); memset(nentry->lsm, 0, sizeof_field(struct ima_rule_entry, lsm)); for (i = 0; i < MAX_LSM_RULES; i++) {