mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 02:01:24 +01:00
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>
This commit is contained in:
1 parent
f04da199a9
commit
c0e548d920
1 file changed
+3
-2
@@ -3184,11 +3184,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
|
||||
|
||||