I think that both examples are grammatical. If the preposition doesn't add to/change the meaning (i.e. it's not part of a phrasal verb), it usually can be omitted. You don't need a preposition with the adverb long. Including for adds nothing, so this is a style choice. There's no difference in meaning in your examples (or mine).
I say this because you can easily rephrase that into another question as a test:
[For] How long have you been waiting?
How long have you been waiting [for]?
You only need for if it were followed by a pronoun/noun like me/us/John.
Have you been waiting long for John?
Have you been waiting for long for John?
For how long have you been waiting for John?