From patchwork Sun Jan 28 17:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Markus Elfring X-Patchwork-Id: 13534542 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8BE28C47258 for ; Sun, 28 Jan 2024 17:09:54 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.672859.1046957 (Exim 4.92) (envelope-from ) id 1rU8f5-0001ic-W3; Sun, 28 Jan 2024 17:09:39 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 672859.1046957; Sun, 28 Jan 2024 17:09:39 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rU8f5-0001iV-TR; Sun, 28 Jan 2024 17:09:39 +0000 Received: by outflank-mailman (input) for mailman id 672859; Sun, 28 Jan 2024 17:09:38 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1rU8f4-0001iN-DW for xen-devel@lists.xenproject.org; Sun, 28 Jan 2024 17:09:38 +0000 Received: from mout.web.de (mout.web.de [212.227.17.12]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 03ad6345-be00-11ee-8a43-1f161083a0e0; Sun, 28 Jan 2024 18:09:36 +0100 (CET) Received: from [192.168.178.21] ([94.31.81.95]) by smtp.web.de (mrweb105 [213.165.67.124]) with ESMTPSA (Nemesis) id 1MuFD5-1rDqKJ2XxF-00uach; Sun, 28 Jan 2024 18:09:34 +0100 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 03ad6345-be00-11ee-8a43-1f161083a0e0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=s29768273; t=1706461774; x=1707066574; i=markus.elfring@web.de; bh=skl6m8d4+uXGtWa5IbVdYrFKC3oF+ITHrCIEfSyrSJw=; h=X-UI-Sender-Class:Date:To:Cc:From:Subject; b=JTzbCmuQAOJ1kPZq5j1qaYAsHcjBkpcnu2qhErvAN2LpefDUUeM8b2YxSueGD71B j3eef9Aa7lTg7dMClGwevaaI/naVIePVANvgwvsxllGUm2u4KQBiBZpEHsN3Ge9ET /olSkTUN96PGcHvaKkcFYx3KkJXJx/ggDHvxAy2e0PpH0dgdZ4koTAtljuvqJIqJD I95lUgxOg94U1tQgmlZ0bc5OwJ57nktLwYazqriKFh6Ef/EBYKc2zFaKNOnos3iVR K/J/lW4DLGoS6zIj6opNVr9FEH4OAba3LSfjiW4G6hk871iGmBZHEC0Kp5XTe6oqA BY/3ZEr14c52yJwQug== X-UI-Sender-Class: 814a7b36-bfc1-4dae-8640-3722d8ec6cd6 Message-ID: <41e333f7-1f3a-41b6-a121-a3c0ae54e36f@web.de> Date: Sun, 28 Jan 2024 18:09:30 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird To: xen-devel@lists.xenproject.org, kernel-janitors@vger.kernel.org, =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= , Oleksandr Tyshchenko , Stefano Stabellini Content-Language: en-GB Cc: LKML From: Markus Elfring Subject: [PATCH] xen/privcmd: Use memdup_array_user() in alloc_ioreq() X-Provags-ID: V03:K1:7yhNhlRvw29pkPL2ElLfqurRFvlr5JJnJHUrCA7cARjU+fJm2cn 3ujTOQNviQlobkUnrNwknyt+XzrmHGGoXkQ4NrRjmuViRPoSvBYWkVfI3o9b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YH1v10S3OYTwozdNHejdJEHqWYrh3/b438sDAwKqfdv4 3J8eOg== From: Markus Elfring Date: Sun, 28 Jan 2024 17:50:43 +0100 * The function “memdup_array_user” was added with the commit 313ebe47d75558511aa1237b6e35c663b5c0ec6f ("string.h: add array-wrappers for (v)memdup_user()"). Thus use it accordingly. This issue was detected by using the Coccinelle software. * Delete a label which became unnecessary with this refactoring. Signed-off-by: Markus Elfring Reviewed-by: Juergen Gross --- drivers/xen/privcmd.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) -- 2.43.0 diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 35b6e306026a..2c8f6d047c11 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -1223,18 +1223,13 @@ struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioeventfd) kioreq->ioreq = (struct ioreq *)(page_to_virt(pages[0])); mmap_write_unlock(mm); - size = sizeof(*ports) * kioreq->vcpus; - ports = kzalloc(size, GFP_KERNEL); - if (!ports) { - ret = -ENOMEM; + ports = memdup_array_user(u64_to_user_ptr(ioeventfd->ports), + kioreq->vcpus, sizeof(*ports)); + if (IS_ERR(ports) { + ret = PTR_ERR(ports); goto error_kfree; } - if (copy_from_user(ports, u64_to_user_ptr(ioeventfd->ports), size)) { - ret = -EFAULT; - goto error_kfree_ports; - } - for (i = 0; i < kioreq->vcpus; i++) { kioreq->ports[i].vcpu = i; kioreq->ports[i].port = ports[i]; @@ -1256,7 +1251,7 @@ struct privcmd_kernel_ioreq *alloc_ioreq(struct privcmd_ioeventfd *ioeventfd) error_unbind: while (--i >= 0) unbind_from_irqhandler(irq_from_evtchn(ports[i]), &kioreq->ports[i]); -error_kfree_ports: + kfree(ports); error_kfree: kfree(kioreq);