First we need to understand why $dU = m c_v dT$.
The definition of specific heat comes from the following formulation:
$$c_{y} = \frac{1}{m} \left(\frac{\delta Q}{d T} \right)_{y} $$
note that specific heat depends on the process $y$.
Let's now consider the first law of thermodynamics:
$$
\delta Q + \delta W = d U \\
\delta Q = d U - \delta W\\
\delta Q = d U - p d V
$$
Let's apply this for a constant volume ($dV=0$) process:
$$
(\delta Q)_v = d U
$$
dividing both sides by $dT$:
$$\left(\frac{\delta Q}{d T} \right)_v = \frac{d U}{d T}$$
the index $v$ is used because the process is for a constant volume.
Now, using the definition of specific heat, we arrive at:
$$
c_v = \frac{1}{m} \left(\frac{\delta Q}{d T} \right)_v \\
c_v = \frac{1}{m} \frac{d U}{d T}
$$
One should note that the specific heat at constant volume only depends on properties $U$ and $T$. Since it only depends on state properties, it means that it does not depend on the process. For this particular reason it can be applied to any process.
A similar procedure can be done to explain that the specific heat at constant pressure can also be applied to any process.
$$
c_p = \frac{1}{m} \frac{d H}{d T}
$$