I worked for a good B2B SaaS, and while I was able to tell myself I'm not doing anything unethical or immoral, and while some of the customers were indeed very valuable (in terms of value to their customers) Fortune 500 companies - a large chunk of customers were adtech, dodgy mobile gaming, etc.
So you're still just providing infrastructure for these guys and not really contributing anything useful to the world, you're just one level removed from that, and hopefully you have enough customers who actually do good.