Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp490354ybz; Wed, 15 Apr 2020 12:37:02 -0700 (PDT) X-Google-Smtp-Source: APiQypLZNgHY5l8vcILFC8bJBRmoTmTp4sEbbl37NJ8ydmUOHryvwUPBHDQxKaNiSbvNIMqxHXJf X-Received: by 2002:aa7:c5cf:: with SMTP id h15mr7155346eds.213.1586979422539; Wed, 15 Apr 2020 12:37:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586979422; cv=none; d=google.com; s=arc-20160816; b=0NDjPBpHxPneiruTzpmLbOVslTwFSh4a0rek5PZ0xTYeB23b0fuvrWv+jSTdENeHxd ichR7L4xDr9c+gQvFjBY9LYPOJXo+XnxvOhf5GFjcAC8fv65zne7RqimQac4bM3bMevA Z50p9vibcdprrI3udcPLG6e76BqyvfxeAKojlWAWLg67R0dzBp2Hx87c2bgsK+ERwvRD s1Z9r4xfIA8ETMzhjEfNWl0gXK1H02gy6OpLf7phE1XHFf2XoBkdE2epQx8V9QCigSeI B/RXftHTHt/B15D+TjodoR4o31AQJK1oMg//LdxH2hYe4Vdte9qSDEgSmnI/8+puJq24 a/uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=GKV7PvhQWNzwjnulmTMXzltQzV3yWxGe3KsuRDIQ1LU=; b=xV+DSrRLbLA+m/6Y8hSjVcAoqwCboTIkH37C1bXloc4/NTwX+SIOF9I1h1cuVscwPi gYYSw+a6aFdm4qopwUVwNfAwUh0RTPwUdkPkETticroogw1rHEYK/s9yC2Z2ZXdn7KvM MeO5KIY4+RrWFIBjgH2MkNBcXR/lULk5ktwfDymTTkBk+HjUOFY4VYP3AbanrWAYW1TN tiVtdEOjrhkFz8aFihdb/cFJq6sS+2+6SDM76t23l3G1Actl2xQqCRTOzedEb0/X3+YF 9e8/HL8/MgPHmKuhHJmDIWM7ghcVCVHY4WmwQ7HbuUXiJnsQSTQMS2EkWHSAstZTjZ/h QwJg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w26si8655850ejb.118.2020.04.15.12.36.38; Wed, 15 Apr 2020 12:37:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438367AbgDNKcP (ORCPT + 99 others); Tue, 14 Apr 2020 06:32:15 -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 Content-Type: text/plain X-Originating-IP: [10.175.103.112] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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++) { -- 2.6.2