Hilchos Lashon Hara chapter 6, section 5
When we said that even listening to lashon hara is forbidden, that means going on purpose to listen. But what if he is already sitting with a group of people who met for some reason, and they start speaking lashon hara, and he thinks that correcting them will not make them stop? That depends on the details:
If he can leave, or block his ears, he is doing a great mitzvah.
But if he cannot get away from them, and he feels it is very hard for him to block his ears because he does not want them to make fun of him, then at least he must fight with himself not to fall into the sin of accepting lashon hara. For this he needs three things:
1. He decides for himself that he does not believe any of the stories.
2. He does not enjoy their forbidden talk.
3. He does not make any movement that shows he agrees with the stories. If he can, he should make an angry face that shows he does not like the stories.