Mode locking of the Hermite-Gaussian modes of a nanolaser