xen/privcmd: fix error exit of privcmd_ioctl_dm_op()
authorJuergen Gross <jgross@suse.com>
Thu, 25 Aug 2022 14:19:18 +0000 (16:19 +0200)
committerJuergen Gross <jgross@suse.com>
Thu, 25 Aug 2022 14:40:28 +0000 (16:40 +0200)
commitc5deb27895e017a0267de0a20d140ad5fcc55a54
treec7c63d85dc439593a18bbfb6a0f024dc5eada359
parent6bb79f5b4c84a09cd6bed46ef3e46ef4fc21407d
xen/privcmd: fix error exit of privcmd_ioctl_dm_op()

The error exit of privcmd_ioctl_dm_op() is calling unlock_pages()
potentially with pages being NULL, leading to a NULL dereference.

Additionally lock_pages() doesn't check for pin_user_pages_fast()
having been completely successful, resulting in potentially not
locking all pages into memory. This could result in sporadic failures
when using the related memory in user mode.

Fix all of that by calling unlock_pages() always with the real number
of pinned pages, which will be zero in case pages being NULL, and by
checking the number of pages pinned by pin_user_pages_fast() matching
the expected number of pages.

Cc: <stable@vger.kernel.org>
Fixes: ab520be8cd5d ("xen/privcmd: Add IOCTL_PRIVCMD_DM_OP")
Reported-by: Rustam Subkhankulov <subkhankulov@ispras.ru>
Signed-off-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Oleksandr Tyshchenko <oleksandr_tyshchenko@epam.com>
Link: https://lore.kernel.org/r/20220825141918.3581-1-jgross@suse.com
Signed-off-by: Juergen Gross <jgross@suse.com>
drivers/xen/privcmd.c