xen/gnttab: Fix TOCTOU race in gnttab_set_version()

Move first read of gt->gt_version inside the critical region of the
rwlock, otherwise concurrent gnttab operations (silly as they would be)
may get mutually confused as to the actual current version.

Fixes: c1488502c949("grant-tables: do not fail attempts to...")
Reported-by: Oleksandr Tyshchenko <Oleksandr_Tyshchenko@epam.com>
Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: c0e548d920
master date: 2026-05-22 13:32:44 +0200
This commit is contained in:
Alejandro Vallejo authored and Jan Beulich committed 2026-06-03 11:37:15 +02:00
1 parent 4d6e6ed016
commit 04db4dc2a2
1 file changed
+3 -2
+3 -2
View File
@@ -3185,11 +3185,12 @@ gnttab_set_version(XEN_GUEST_HANDLE_PARAM(gnttab_set_version_t) uop)
if ( op.version == 2 && gt->max_version == 1 )
goto out; /* Behave as before set_version was introduced. */
grant_write_lock(gt);
res = 0;
if ( gt->gt_version == op.version )
goto out;
goto out_unlock;
grant_write_lock(gt);
/*
* Make sure that the grant table isn't currently in use when we
* change the version number, except for the first 8 entries which
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.