304 is nearly impervious, as well as some of the nitrogen alloyed stainless steels.
But guns almost always use a 410 series stainless, usually 416. These are 1) highly machinable and 2) martensitic (will harden)
The sulfur that aids in machinability increases susceptibility to corrosion by forming inclusions in the steel that give places for rust to form. Furthermore, Chromium content is in the 12% neighborhood, which is the bare minimum for a steel to be considered "stainless".