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.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.