It does not hold for arbitrary topological spaces if $m>1$: there are spaces $X$ with the property that every real-valued continuous function on $X$ is constant. Thus, if $x$ and $y$ are distinct points of such a space $X$, $r$ and $s$ are distinct real numbers, $f'(x)=r$, and $f'(y)=s$, there is no continuous function $f:X\to\Bbb R$ extending $f'$. It’s not hard to construct such counterexamples if we don’t impose any ‘niceness’ conditions on $X$ — just give $X$ the indiscrete topology, for instance — but in this answer I describe a construction, due to Eric van Douwen, of such spaces starting with any $T_3$-space containing two points that cannot be separated by a continuous real-valued function; in this answer I describe such a $T_3$-space, due to John Thomas.
If $X$ is a $T_4$-space, the Tietze extension theorem ensures that every real-valued function on a finite subset of $X$ has a continuous extension to $X$.
The accepted answer to this question is also relevant.