At last, the iPhone Dev Team has released Ultrasn0w version 1.2.5 to unlock the iPhone 4 and iPhone 3GS on iOS 5.0.1. Before unlocking, the iPhone will require a tethered jailbreak on iOS 5.0.1 by using the recently released redsn0w 0.9.9b9[download link is below] or sn0wbreeze. A tethered jailbreak requires the iPhone to be connected to a Mac or PC each time it needs to be rebooted, in order to boot it back into a jailbroken state.
Ultrasn0w can be accessed on jailbroken devices by adding the repository “http://repo666.ultrasn0w.com” to the sources list in Cydia. The utility does not currently support newer iPhone basebands, however, so only the following older ones will work: 01.59.00, 04.26.08, 05.11.07, 05.13.01, 05.12.01, 06.15.00.
redsn0w 0.9.9b9 [Redsn0w Mac, Windows]
COMPELETE guide here