There are no restrictions on foreigners buying property in Shanghai, but it remains relatively uncommon. Although the major international banks and many of the local banks will offer mortgages to foreigners, subject to proof of income, the banks' demands for a hefty 30% of the purchase price as a deposit for the purchase probably helps to discourage prospective buyers.
It is strongly recommended that you consult an experienced Chinese solicitor prior to contemplating buying property. He or she will be able to give you up to date advice on the current and proposed legislation regarding ownership of property by foreigners.
If you sell your property in China, you will be exempted from Capital Gains Tax provided you have owned it for more than five years.