Suppose $Z$ is distributed $N(0,\Sigma)$, where $\Sigma$ is a $k\times k$ variance matrix and singular, with eigenvalues $\lambda_j>0$ for $j=1,2,3...,r$ and $\lambda_j=0$ for $j=r+1,...,k$ and $\Sigma$ has spectral decomposition $\Sigma=B M B^t$, where $M=Diag\{\lambda_1,...,\lambda_k\}$. The moore-penrose generalize inverse of $\Sigma$ is $\Sigma^+=BM^+B^t$, where $M^+=Diag\{\lambda_1^{-1},...,\lambda_r^{-1},0,...,0\}$.
So what is the distribution of $Z^tM^+Z$? Intuitively, it is chi-spuared with r degrees of freedom. But how to prove it?
$Z\sim N(0,\Sigma)$ iff $Z\sim BM^{1/2}G$, where $G\sim N(0,I_k)$ is standard normal and $M^{1/2}=diag(\lambda_1^{1/2},\ldots,\lambda_k^{1/2})$ (so $M^{1/2}B^t$ is a square root of $\Sigma$). So $Z^t\Sigma^+Z =Z^tBM^+B^tZ=A^TA$, where $$ A=(M^+)^{1/2}B^tZ\sim (M^+)^{1/2}B^tBM^{1/2}G=diag(\underbrace{1,1,\ldots,}_{\text{r times}}0,\ldots,0)G\sim N(0,I_r), $$ giving $A^TA\sim \chi^2_r$.