From nobody Fri May 17 13:35:02 2024 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AC4C6C00140 for ; Wed, 24 Aug 2022 14:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239168AbiHXO1h (ORCPT ); Wed, 24 Aug 2022 10:27:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238421AbiHXO1e (ORCPT ); Wed, 24 Aug 2022 10:27:34 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDE794D4D9; Wed, 24 Aug 2022 07:27:33 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 8A88F20447; Wed, 24 Aug 2022 14:27:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1661351252; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=Yi2ZNad6kgMz/6PldXnNjKbyPX0uHyJxaAqhAA//dfo=; b=FUHgHgR1V9zX7w8l+rS/yI6QH5Cqpo1omm+unoLQLUz1Agf/U8G0GH+Rst0xcKAH7lzsjk WW2yUOBSNUBidc8jsqDa2505hNaY1Y3VQdrrVrKa3yfUZ9TqhJkdRLZZWorEiDi7CjwLT/ /fUsx7qp6AbarPHI8pxMGwt7b3Yzc/U= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 45DB313AC0; Wed, 24 Aug 2022 14:27:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HPKUD1Q1BmN+BgAAMHmgww (envelope-from ); Wed, 24 Aug 2022 14:27:32 +0000 From: Juergen Gross To: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org Cc: Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , stable@vger.kernel.org, Rustam Subkhankulov Subject: [PATCH] xen/privcmd: fix error exit of privcmd_ioctl_dm_op() Date: Wed, 24 Aug 2022 16:26:34 +0200 Message-Id: <20220824142634.20966-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The error exit of privcmd_ioctl_dm_op() is calling unlock_pages() potentially with pages being NULL, leading to a NULL dereference. Fix that by calling unlock_pages only if lock_pages() was at least partially successful. Cc: Fixes: ab520be8cd5d ("xen/privcmd: Add IOCTL_PRIVCMD_DM_OP") Reported-by: Rustam Subkhankulov Signed-off-by: Juergen Gross Reviewed-by: Jan Beulich Reviewed-by: Oleksandr Tyshchenko --- drivers/xen/privcmd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/xen/privcmd.c b/drivers/xen/privcmd.c index 3369734108af..ec87968b4459 100644 --- a/drivers/xen/privcmd.c +++ b/drivers/xen/privcmd.c @@ -679,7 +679,7 @@ static long privcmd_ioctl_dm_op(struct file *file, void= __user *udata) rc =3D lock_pages(kbufs, kdata.num, pages, nr_pages, &pinned); if (rc < 0) { nr_pages =3D pinned; - goto out; + goto unlock; } =20 for (i =3D 0; i < kdata.num; i++) { @@ -691,8 +691,9 @@ static long privcmd_ioctl_dm_op(struct file *file, void= __user *udata) rc =3D HYPERVISOR_dm_op(kdata.dom, kdata.num, xbufs); xen_preemptible_hcall_end(); =20 -out: + unlock: unlock_pages(pages, nr_pages); + out: kfree(xbufs); kfree(pages); kfree(kbufs); --=20 2.35.3