Given the case that a user is presented a modal dialog that displays an installation process (or something similar).
If the process would normally take a few seconds but can potentially take longer, should I offer a "Cancel" button to give the user full control? 

I've seen installers that disable the Cancel button and others that can do a rollback after Cancel is clicked. But what if one does not have the option of a full rollback? Should I ...

* trap the user in the dialog until the process is completed or a timeout is reached
* offer the Cancel button anyways, with the drawback of possibly generating data garbage or an invalid installation
['https://ux.stackexchange.com/questions/79016', 'https://ux.stackexchange.com', 'https://ux.stackexchange.com/users/19337/']
If there is no safe way for the user to leave the process then you really should make them wait until it is complete. Leaving them with a faulty system is potentially more damaging to the software's reputation than making them wait for an extra 20 minutes for a correct and perfect instal.

However, I assume that they've gone through some sort of process to get to that point (agree to EULA, select instal location, etc), that would be that time to clearly tell them how much time it is expected to take in the worst cases (this will also add a little expectation management giving users who don't experience worst case a pleasant surprise when the process completes more quickly than expected).

If you must offer a "cancel at any cost" option then you will need to clearly message the user about the cost to their system (bad data, disk errors, failing software, etc) with an "Are you sure?" dialogue so that they can make an informed choice. You might also need to include a legal disclaimer depending on the amount of damage you could potentially do to their system.
If possible, present the user with a "Finish Later" option on the dialog, instead of "Cancel". If the install takes longer than they want right now, or they have something important they need to do right now that the install process is interfering with, they can choose that option and then you let them continue the next time the install process is initiated.