Stability of modified gravity models