How It Works
If Mario does a cape dive and immediately pulls up just as he fly against a ceiling he is able to stick to it while continuing to fly.
Note: This method only works on levels created before version 1.44.
Mario is able to fly against Bumpers if they're slightly offset.
Edge of the Screen
If Mario is wearing a shellmet he is able to fly against a ceiling of grinders.