It's actually buggy in two ways that you need to be careful of:
1) If the incident involves more than one car, you will often get the penalty for passing the other car(s) involved in the incident, as the system only seems to recognize one car as causing the yellow. This happens a lot.
2) Sometimes you get dinged for making the overtake just before the yellow flag warning appears. It has happened to me twice, both at Interlagos and Brands Hatch. This is where watching the actual flaggers may come in handy, but I recall one incident where I definitely got the penalty even before the yellows were waving. This is more rare, as it's just a really unlucky bit of timing (you happen to pass someone right before a yellow is called for someone else).
Point is, it isn't perfect, and just following the rule isn't enough. PD should at least fix the first bug, as it is quite unfair to expect you to wait for all cars to return to track when more than one have gone off.