It seems to be a result of J-M Bony that every nonnegative function in $C^{2m}$ is a sum of squares of two $C^m$ functions, which means that every $C^\infty$ function is the sum of squares of two $C^m$ functions for any $m$ (which, I suppose, does not mean that you can do it with two $C^\infty$ functions -- the counterexamples are attributed to Paul Cohen and D.B.A. Epstein -- see references 1and 4 in the cited paper): the reference is:
Bony, Jean-Michel(F-POLY-CMT)
Sommes de carrés de fonctions dérivables. (French. English, French summary) [Sums of squares of derivable functions]
Bull. Soc. Math. France 133 (2005), no. 4, 619–639.
For functions from $\mathbb{R}^k \rightarrow \mathbb{R}_+$ these results are extended in:
Nonnegative functions as squares or sums of squares
Jean-Michel Bonya, Fabrizio Brogliab, Ferruccio Colombinib, Ludovico Pernazzac (J. Func. An, 2006)
EDIT I asked J-M Bony for the scoop, and his response is that no one seems to know what the counterexample actually is, P.J. Cohen was asked about this shortly before his death, but did not remember, Bony himself says he does not even know whether a counterexample exists, and would not know which way to wager. Given that he is THE expert in the field, I would say the problem is open.