I think that a nine year old is definitely old enough to have a talk with about the appropriateness of this behavior and the right place for this. He's probably been doing this for years, and just likes the pleasure feeling it gives him.
Tell him to do this privately and to wash his hands afterwards.
I don't think you need to worry about it. You can't tell him to stop because it isn't likely to get him to stop. Some children are much more aware of a physical pleasure of rubbing or touching themselves, many much younger than your son. It isn't necessarily sexual although by 9 maybe it could be with him. It doesn't really matter: it feels good, it can be soothing if they're anxious about something or bored. Your son is old enough to understand the concept of privacy so if he's doing it in front of the family then let him know that it's something he should do in private (in his room or the bathroom.) You don't want it to become a nervous or unconscious habit for him because that would become a problem if he started doing it in public. Hope this helps.