Airplanes can fly upside down (i.e. airfoils can still generate lift upside-down) because the stagnation point changes.
(Unfortunately, this is compatible with the incorrect "the separated air must meet up with itself at the trailing edge, so the air taking the longer path must speed up" explanation).
Say you have an airfoil (symmetric or cambered, doesn't matter) moving through the air at some airspeed. Say that you pitch it to whatever angle of attack is necessary to supply a certain amount of lift (say, the lift force necessary to counter the weight of the airplane).
Some of the air moves over the airfoil. Some of the air moves under the airfoil. Some point on the leading edge of the airfoil will mark the spot where the air is split. That is the stagnation point. On the image, I marked it as a red dot.
Now say you turn your airfoil (e.g. the whole airplane) upside-down. Say that it's still moving with the same airspeed. Say that you pitch it to whatever angle of attack is necessary to supply a certain amount of lift (say, the lift force necessary to counter the weight of the airplane). If you have a symmetric airfoil, it will be the same angle of attack as before. If you have an asymmetric airfoil optimized for non-inverted flight, it will need a higher angle of attack to fly inverted, but that doesn't matter much right now.
You'll notice that the stagnation point will be further down than it was before. On the image, I marked it as a green dot. The airfoil naturally generates a "hump" out of the upper part of its leading edge when it's upside down (just as it does when it's not upside down).
As for what kinds of airplanes can sustain inverted flight for how long, there are five things to keep in mind:
1) An asymmetric airfoil is less efficient when inverted (i.e. it will produce more drag while generating the same lift at a given speed)
2) The engine is usually mounted so that it produces thrust in the straight-forward direction when the wing is at the angle of attack that, during cruise flight, causes the right amount of lift to be generated to overcome the weight of the airplane. So if you turn the airplane upside down and then pitch the nose up in order for the wing to work, the engine will no longer be pulling straight forward, it will be pulling forward and up. So you lose some component of thrust (since the horizontal component of the thrust is now the engine thrust times the cosine of the angle through which you had to pitch the nose up for the wing to keep working). Yes, there is a tiny component of the thrust pulling upwards, and you'd think that this would help the wings out, but most airplanes have small thrust-to-weight ratios so the vertical component of the thrust during inverted flight is pretty negligible, unless you're flying an inverted high-alpha airshow pass in a ridiculously overpowered airplane.
3) Engines, the fuel tank, the oil system, and other things (and the pilot!) might not function very well when inverted.
4) Some structures will be loaded in reverse during inverted flight. The tops of the wings which used to be in compression will be in tension, the bottoms of the wings which used to be in tension will be in compression (so any struts under the wings might buckle), etc.
5) The horizontal stabilizer, which is usually required to balance the airplane, is mounted at a different angle of incidence than the wing, for stability. So when you turn the whole airplane upside down, the horizontal will be at the wrong angle of attack, and the elevators will have to work very hard in order to make up for this.
All that numbers one and two mean is that you need more thrust to sustain inverted flight. Most airplanes have some excess thrust (i.e. the engines can produce a lot more than is needed for level flight) so no real problem there.
Number three and four mean that either your systems and structures are inverted-friendly (they can work properly in negative gs), or they are not. If they're not, they'll malfunction when you sustain negative gs, even if the airplane can aerodynamically do it.
Number five is the real reason why you can't fly inverted in a typical Cessna or airliner:
The CG is ahead of the wing (for stability), so the horizontal stabilizer needs to push downwards (for balance), so it is set at a negative angle of incidence (i.e. it's like a little wing, but upside down). If you flip the plane upside down (and then pitch the nose up so that the wings still lift upwards), the horizontal stabilizer will now be at a very high upwards angle of attack, and will try very hard to push the tail up and bring the nose back down. The only way to overcome this is if your elevators can overcome this stabilizing force. Cessnas and airliners have big stabilizers set at a significantly negative angle of incidence (which give these airplanes great stability) and small elevators (so the pilot can't maneuver too wildly), but fighters and aerobatic airplanes have the horizontal at almost the same angle of incidence as the wing (so they're not very stable) and big, powerful elevators, sometimes the whole stabilizer is one huge elevator (so that they can pitch up and down very fast, make tight turns, etc). So the elevators in fighters and aerobatic airplanes is powerful enough, and the stabilizers are weak enough, that when you roll inverted, the elevators can overcome the force of the stabilizers and keep the airplane at that nose-up angle that it needs for the wings to work while inverted. But airliners and general-aviation airplanes, not so much.
So if you roll a fighter or an aerobatic airplane inverted, and then push the stick, the nose will point upwards and the wings will work and you're golden. But in a typical general-aviation airplane or an airliner, if you somehow manage to roll it inverted, the nose will sink, no matter how hard you push that yoke, because the stabilizers are just too big and set at too great an angle and you don't have very powerful elevators to overcome the stabilizers' tail-up force.
Note that all this is in regards to airplanes "pulling negative gs", i.e. where the wing generates lift in the direction from the pilot's head to their butt rather than in the direction from the pilot's butt to their head. Many inverted maneuvers, like properly-executed loops and barrel-rolls, are positive-g maneuvers, i.e. the wing always works the normal way, and the pilot is always pressed against the seat and never hangs from the straps. (Whether this should be understood as a "centrifugal" effect or just as an airplane rolled inverted and pushing downwards against its own inertia... you can ask Mr Bond). The only real challenge in doing these positive-g rolls and loops is that the maneuver will have a "bottom" and a "top", and that difference in altitude means a difference in potential energy that comes right out of your kinetic energy, i.e. the airplane goes slower at the top than at the bottom (just like a roller coaster or a projectile - the engine will help a little but not much, since you have to pull off these maneuvers fairly quickly if you hope to keep the gs positive). But the range of speeds that an airplane can operate at is relatively narrow: There is a minimum stall speed below which the wings don't work, and a maximum speed dictated by engine thrust or by structural considerations. Most non-aerobatic airplanes can't do a loop because if you're flying at your maximum speed and you pull up, you'll get to your minimum speed before you get to the top of the loop, and the airplane will stall. (If you're inverted when this happens, i.e. if you make it more than 1/4 of the way around the loop and your nose has gone past the vertical, then stalling can put you in an inverted flat spin that some airplanes can't get out of. So don't try this at home). But almost any airplane can do a barrel roll, even (famously) a 707. You have to pull a couple of gs when you transition from level flight to going up the barrel roll, and then you have to pull a couple of gs again when you transition from going down the barrel roll back into level flight, but pretty much any airplane can handle that, and the altitude change will be relatively small so it won't take most airplanes from max speed to below stall speed.EDIT
: I think I was wrong in my "the elevators are probably not powerful enough to overcome the stabilizers' alpha-reducing nose-towards-the-horizon force" estimation. In my defense, I'm a structures guy. I can tell you how the airplane components are loaded very differently during -1g flight than they are during normal flight, and how they're still strong enough to take -1g flight, plus a 50% safety margin (just like the famous 50% safety margin
on the 2.5 positive gs that they're supposed to withstand), and which flight conditions load which components most heavily (not ALL of them, but most of the structurally important ones). I can give you numbers about stress levels, strengths, material thicknesses, how shear beams are configured, when buckling happens, how stringers and frames are shaped and why, and how far apart they are, and so on. (Well, I'd be fired if I did, but I could
). But when it comes to stability & control, what I know comes from a few classes in college, some experience flying Cessnas, some experience in Flight Simulator, and going to lots of airshows. It's a lot, but it's not as precise as what I know about structures. Anyways, over the weekend I got talking with someone who does deal with stability and control and airplane handling for a living, and he told me that an airliner should not only be able to survive a -1g manouver, in practice an airliner can actually be pushed over that hard on command. At the right speeds, with nose-down trim, etc, the elevators should be able to overcome the horizontal stabilizers' stabilizing force, and hold the airplane at the negative angle of attack necessary to sustain -1g flight. What I told him is that I've never been able to pull it off in Flight Simulator, but he insisted that it's doable. The only way to know for sure (other than taking an airliner up and flipping it, which is a bit beyond our means) is to try it in a REAL flight simulator. Now I really want to try it! But in any case, for the record, what I wrote above in this post (about how the elevators will not push down hard enough to keep the horizontal stabs from raising the tail and dropping the nose, so the wings can't be kept at enough of an angle to generate lift while inverted) is probably wrong.EDIT 2
: Yep, I was wrong