When you iPhone is locked with a passcode tap Emergency Call, then enter a non-emergency number such as ###. Next tap the call button and immediately hit the lock button. It should open up the Phone app where you can see all your contacts, call any number, etc.
I tried it out and it doesn’t work for me on iPhone 3GS (Model MC 132B) with iPhone 4.1 (8B117).(* see update)
The person who discovered the flaw mentioned that he used a jailbroken phone but some people claimed that they could reproduce it on non jailbroken versions.
I am now wondering if the flaw depends on specific hardware parameters(* see update ) like processor speed etc. and it currently can only be practised on the more powerfull iPhone 4.
*Update: Confirmed to be working on iPhone 3GS with iOS 4.0 (8A293) (model MC131B) and if you are quick enough it also works on iPhone 3GS (Model MC 132B) with iPhone 4.1 (8B117).