[proofplan]
We build a smooth bump function on the real line starting from the classical non-analytic smooth function $\alpha(t) = e^{-1/t^2}$ for $t > 0$, use it to manufacture a smooth step function $\beta$ that transitions from $0$ to $1$ on $[0, 1]$, then form $\gamma(t) = \beta(2+t)\beta(2-t)$, which equals $1$ on $[-1, 1]$ and vanishes outside $(-2, 2)$. Taking a product of copies of $\gamma$ in each coordinate yields a cube-shaped bump on $\mathbb{R}^n$. We transport this bump to $M$ via a chart centred at $p$ and scale it so that the bump's support is contained in $U$ and the region where it equals $1$ is an open neighbourhood of $p$. Extension by zero outside the chart domain gives a globally defined smooth function on $M$.
[/proofplan]
[step:Construct the fundamental smooth non-analytic function $\alpha$ on $\mathbb{R}$]
Define
\begin{align*}
\alpha: \mathbb{R} &\to \mathbb{R} \\
t &\mapsto \begin{cases} e^{-1/t^2} & t > 0, \\ 0 & t \le 0. \end{cases}
\end{align*}
We claim $\alpha \in C^\infty(\mathbb{R})$. For $t > 0$ and $t < 0$ this is immediate: $\alpha$ is a composition of smooth functions on each open half-line. At $t = 0$ one verifies by induction on $k \in \mathbb{N}_0$ that for every $k$ there is a polynomial $P_k$ with $\alpha^{(k)}(t) = P_k(1/t) e^{-1/t^2}$ for $t > 0$, and consequently
\begin{align*}
\lim_{t \to 0^+} \alpha^{(k)}(t) = \lim_{t \to 0^+} P_k(1/t) e^{-1/t^2} = 0
\end{align*}
because $e^{-1/t^2}$ decays faster than any polynomial in $1/t$ as $t \to 0^+$. Since $\alpha^{(k)} \equiv 0$ on $(-\infty, 0]$, both one-sided limits of $\alpha^{(k)}$ at $0$ agree and equal $0$, so $\alpha^{(k)}(0) = 0$ for all $k$. Thus $\alpha$ is $C^\infty$.
Note also that $\alpha(t) > 0$ for $t > 0$ and $\alpha(t) = 0$ for $t \le 0$.
[/step]
[step:Build a smooth step function $\beta$ transitioning from $0$ on $(-\infty, 0]$ to $1$ on $[1, \infty)$]
Define
\begin{align*}
\beta: \mathbb{R} &\to \mathbb{R} \\
t &\mapsto \frac{\alpha(t)}{\alpha(t) + \alpha(1-t)}.
\end{align*}
The denominator $D(t) := \alpha(t) + \alpha(1-t)$ is strictly positive for every $t \in \mathbb{R}$. Indeed, if $t > 0$ then $\alpha(t) > 0$, and if $t \le 0$ then $1 - t \ge 1 > 0$ so $\alpha(1-t) > 0$. In either case $D(t) > 0$. Hence $\beta$ is the ratio of two smooth functions with non-vanishing denominator, so $\beta \in C^\infty(\mathbb{R})$.
Special values:
\begin{align*}
t \le 0 &\implies \alpha(t) = 0 \text{ and } \alpha(1-t) > 0 \implies \beta(t) = 0, \\
t \ge 1 &\implies \alpha(t) > 0 \text{ and } \alpha(1-t) = 0 \implies \beta(t) = 1.
\end{align*}
Moreover $0 \le \beta(t) \le 1$ for every $t \in \mathbb{R}$, since the numerator is non-negative and bounded above by the denominator.
[/step]
[step:Form a smooth cutoff $\gamma$ equal to $1$ on $[-1, 1]$ and supported in $[-2, 2]$]
Define
\begin{align*}
\gamma: \mathbb{R} &\to \mathbb{R} \\
t &\mapsto \beta(2 + t) \cdot \beta(2 - t).
\end{align*}
Then $\gamma \in C^\infty(\mathbb{R})$ as a product of smooth functions. We analyse $\gamma$ on three regions:
If $|t| \le 1$, then $2 + t \ge 1$ so $\beta(2+t) = 1$, and $2 - t \ge 1$ so $\beta(2-t) = 1$, giving $\gamma(t) = 1$.
If $t \ge 2$, then $2 - t \le 0$ so $\beta(2-t) = 0$, giving $\gamma(t) = 0$. Symmetrically, if $t \le -2$, then $2 + t \le 0$ so $\beta(2+t) = 0$, again giving $\gamma(t) = 0$.
Combining, $\gamma \equiv 1$ on $[-1, 1]$, $\gamma \equiv 0$ on $(-\infty, -2] \cup [2, \infty)$, and $0 \le \gamma \le 1$ everywhere (since $\beta$ takes values in $[0, 1]$). In particular, $\operatorname{supp}(\gamma) \subseteq [-2, 2]$.
[/step]
[step:Assemble a product bump on $\mathbb{R}^n$ adapted to the unit cube and the cube of side $4$]
Define
\begin{align*}
h: \mathbb{R}^n &\to \mathbb{R} \\
x = (x_1, \dots, x_n) &\mapsto \prod_{i=1}^{n} \gamma(x_i).
\end{align*}
Then $h \in C^\infty(\mathbb{R}^n)$ as a product of smooth functions, and $0 \le h(x) \le 1$ since each $\gamma(x_i) \in [0, 1]$.
If $x \in [-1, 1]^n$, every factor equals $1$, so $h(x) = 1$. If $x \notin (-2, 2)^n$, some coordinate $x_i$ satisfies $|x_i| \ge 2$, so $\gamma(x_i) = 0$ and $h(x) = 0$. Hence
\begin{align*}
h \equiv 1 \text{ on } (-1, 1)^n, \qquad \operatorname{supp}(h) \subseteq [-2, 2]^n.
\end{align*}
[/step]
[step:Transport the bump to the manifold $M$ via a chart centred at $p$ and scaled to fit inside $U$]
Choose a smooth chart $(W, \varphi)$ on $M$ with $p \in W \subseteq U$ and $\varphi(p) = 0 \in \mathbb{R}^n$. Since $\varphi(W)$ is open in $\mathbb{R}^n$ and contains $0$, there exists $r > 0$ with $\overline{B}(0, 2r\sqrt{n}) \subseteq \varphi(W)$, and in particular $[-2r, 2r]^n \subseteq \varphi(W)$.
Define the scaled bump
\begin{align*}
h_r: \mathbb{R}^n &\to \mathbb{R} \\
y &\mapsto h(y/r).
\end{align*}
Then $h_r \in C^\infty(\mathbb{R}^n)$, $0 \le h_r \le 1$, $h_r \equiv 1$ on $(-r, r)^n$, and $\operatorname{supp}(h_r) \subseteq [-2r, 2r]^n \subseteq \varphi(W)$.
Define the localised bump on $M$ by extension by zero:
\begin{align*}
f: M &\to \mathbb{R} \\
x &\mapsto \begin{cases} h_r(\varphi(x)) & x \in W, \\ 0 & x \in M \setminus \varphi^{-1}([-2r, 2r]^n). \end{cases}
\end{align*}
The two cases are compatible on their overlap: if $x \in W \setminus \varphi^{-1}([-2r, 2r]^n)$, then $\varphi(x) \notin [-2r, 2r]^n \supseteq \operatorname{supp}(h_r)$, so $h_r(\varphi(x)) = 0$, matching the second case.
[/step]
[step:Verify that $f$ is smooth on $M$ and satisfies the bump conditions]
Smoothness. On the open set $W$, $f = h_r \circ \varphi$ is a composition of smooth maps, hence smooth. On the open set $M \setminus K$ with $K := \varphi^{-1}([-2r, 2r]^n)$, $f \equiv 0$ is smooth. The set $K$ is the preimage of the compact set $[-2r, 2r]^n$ under the homeomorphism $\varphi: W \to \varphi(W)$, so $K$ is compact in $W$; since $M$ is Hausdorff, $K$ is closed in $M$. Thus $W$ and $M \setminus K$ are open, they cover $M$ (because $K \subseteq W$), and $f$ is smooth on each. Since smoothness is a local property, $f \in C^\infty(M)$.
Bump conditions. Let $V := \varphi^{-1}((-r, r)^n)$. Then $V$ is open in $M$ (as the preimage of an open set under a continuous chart map) and contains $p$ (since $\varphi(p) = 0 \in (-r, r)^n$). For $x \in V$ we have $\varphi(x) \in (-r, r)^n$, so $h_r(\varphi(x)) = 1$, giving $f(x) = 1$. Thus $f \equiv 1$ on $V$.
For $x \in M \setminus U$, we have $x \notin W$ (since $W \subseteq U$). Then $x \notin K$, so $f(x) = 0$ by the second case of the definition. Thus $f \equiv 0$ on $M \setminus U$. In particular $\operatorname{supp}(f) \subseteq K \subseteq W \subseteq U$, and $\overline{V} \subseteq \varphi^{-1}([-r, r]^n) \subseteq K \subseteq U$.
Finally, $0 \le f \le 1$ on $M$ because $h_r$ takes values in $[0, 1]$. This completes the construction.
[/step]