Your description is correct - the UTXO set is reverted to the previous state and then updated for the blocks in the new chain branch. Reverting is done by means of "undo data" that is stored along each block by Bitcoin Core - and that keeps all the information necessary to revert changes made (e.g. outputs that have been spent in the block and were thus removed from the UTXO set, so that they can be added back in).