It's mostly just practise. You should be able to
- Play a downward stroke hitting exactly the right string first, in any musical context
- Play a single upward stroke catching only the strings you want.
By "single" I mean, you should be able to do it after concentrating on that very stroke, with time to prepare for it. Both of these strokes can be practised, there's not really much to say about it. I don't find them particularly hard to perform with nails, which from you nylonstring pictures I assume is what you also do; with a pick (which I never use) it's probably a bit harder.
In a fast strumming pattern, there's not really any need for catching all the right strings with an upward stroke: the bass strings are mostly "carrier" notes in such patterns, so it's enough to hit them with each downward stroke, the actual fast rythm is mainly heard from the treble strings, so it's fine if you just concentrate on hitting all the trebles with both up- and downward strokes and maybe also the right bass strings (and when you, accidentally, slightly touch e.g. the A-string in a D-major chord, it's usually also not a big problem), which should again be quite doable, and leave the bass strings a job mainly for the downward strokes.