]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commit455283942ee91929c7e3ad2dc262ad4fb1a8b479
treec7c63d85dc439593a18bbfb6a0f024dc5eada359
parent8c8caefb1a7e6a477bc705b356f712a1ddfc6178
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: 8545b91cac6a ("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