Gustavo last played in the league game against Hamburg SV two weeks ago and had been nursing the injury ever since.
"The operation was successful," Bayern said in a statement. They did not say how long the Brazilian would be out of action.
Bayern are top of the Bundesliga with an eight-point lead and are in contention for a spot in the next round of the Champions League.
- Sports & Recreation