From patchwork Mon Apr 12 16:00:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yongjun X-Patchwork-Id: 12198411 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C428C43461 for ; Mon, 12 Apr 2021 15:50:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3296C61355 for ; Mon, 12 Apr 2021 15:50:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243101AbhDLPux (ORCPT ); Mon, 12 Apr 2021 11:50:53 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:15668 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240878AbhDLPuw (ORCPT ); Mon, 12 Apr 2021 11:50:52 -0400 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4FJtRJ1G7HzpXgv; Mon, 12 Apr 2021 23:47:40 +0800 (CST) Received: from localhost.localdomain (10.175.102.38) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Mon, 12 Apr 2021 23:50:22 +0800 From: Wei Yongjun To: , James Bottomley , "Jarkko Sakkinen" , Mimi Zohar , David Howells , James Morris , "Serge E. Hallyn" , Sumit Garg CC: , , , , Hulk Robot Subject: [PATCH -next] KEYS: trusted: Switch to kmemdup_nul() Date: Mon, 12 Apr 2021 16:00:22 +0000 Message-ID: <20210412160022.193460-1-weiyongjun1@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Originating-IP: [10.175.102.38] X-CFilter-Loop: Reflected Precedence: bulk List-ID: Use kmemdup_nul() helper instead of open-coding to simplify the code. Reported-by: Hulk Robot Signed-off-by: Wei Yongjun --- security/keys/trusted-keys/trusted_core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/security/keys/trusted-keys/trusted_core.c b/security/keys/trusted-keys/trusted_core.c index ec3a066a4b42..9430cba1f084 100644 --- a/security/keys/trusted-keys/trusted_core.c +++ b/security/keys/trusted-keys/trusted_core.c @@ -146,11 +146,9 @@ static int trusted_instantiate(struct key *key, if (datalen <= 0 || datalen > 32767 || !prep->data) return -EINVAL; - datablob = kmalloc(datalen + 1, GFP_KERNEL); + datablob = kmemdup_nul(prep->data, datalen, GFP_KERNEL); if (!datablob) return -ENOMEM; - memcpy(datablob, prep->data, datalen); - datablob[datalen] = '\0'; payload = trusted_payload_alloc(key); if (!payload) {