They are short for Game Master and Dungeon Master, respectively. The latter is the trademarked term for someone who runs a Dungeons and Dragons campaign. Another similar term is Storyteller, from World of Darkness and Exalted campaigns.
In general, it refers to someone who describes the rest of the world and narrates the story, versus the other players in the role-play who play a comparatively limited number of characters, usually one main and sometimes their followers depending.