The general rule of thumb is, use companies and place names all you want, unless you're specifically attacking the organization (or suggesting they'd act less than honorable). In that case, switch to either fictional locations or fictitious companies (i.e. write the same story, but call it something else so everyone knows who you're talking about).
Pretty much this. Major government agencies aren't likely to sue you, although they may find other ways to make you hate life. Non-Governmental entities are very much in the tread carefully category, even public personalities to a large degree.
If you do decide to use a company name, or a celebrities name/persona in a work of fiction you better do your homework and make sure the way you use them won't be considered objectionable by them and likely to incur a lawsuit.
For some companies and persons, that means not linking certain things together, even if you believe or know them to be true, or don't think it actually matters.
The Transformers Movies encountered this with some of the characters "human disguise" where they had to change the make/model of a few characters car forms due to both licensing issues, and assertions from the relevant automaker that IIRC they didn't want their brand associated with acts of destruction/warfare or something to that effect going forward. (Basically, "even if it was in our power to give you permission to do so, we would still say no")
Of course, where your writing ends up also plays a role in what you can get away with. Someone writing for mass market publication is going to have a different bar to clear due to the larger exposure their work gets when compared to say, posting on SOL. The mass market publication gets wider exposure, and also being a commercial work, opens it to attentions that freely available stories online don't generally get.