In Hilchot Pesach, the Ben Ish Chai (Rav Yoseif Chaim ben Eliyahu 1835-1909), writes about drinking milk on Pesach from a cow owned by Goyim. When it comes to drinking such milk he is very Machmir, because there is suspicion that maybe the cow on Pesach ate Chametz, and Chametz is forbidden and therefore the milk is coming from something forbidden. So he says one should refrain from drinking such milk.
There are other Poskim besides the Ben Ish Chai that also agree to this stringency. It has been stated and known that it is forbidden on Pesach to gain benefit from Chametz, and therefore we can not allow ourselves to benefit from the Chametz that the cow ate. So since milk is a by product of Chametz, so it should be forbidden.
But it should be pointed out that Chacham Ovadia in Halichot Olam says that there are enough Poskim who hold differently, especially the Shut Bet Efrayim. He was asked this same question, and the Bet Efrayim said that there is no problem. He said that the subject of discussion is milk and not Chametz, and the Torah was forbidding Chametz and not milk. He also said that the cow eating the Chametz doesn’t belong to the Jew, but rather to the Goy, and therefore the Goy is doing it. What belongs to the Goy is not forbidden, so it was permissible when the cow ate Chametz. And also there is a concept called ‘Ze Vaze Gorem’, which means it’s coming from the Chametz that he ate and also other things, meaning the milk was not derived only from Chametz but it was derived from other things as well. Some want to use the concept of Bitul (invalid), and that it becomes Batel on the animal after he eats it. So there are enough reasons to be lenient.
In any event the Halacha, in the way Chacham Ovadia writes it, is that those that are lenient to drink milk on Pesach from the farms that belong to Goyim, definitely have what to rely on. But again, for those that want to be Machmir like the Ben Ish Chai in the usage of milk, there is what to say.
Those that want to be Machmir can buy milk before Pesach so they have it already from before the Holiday and it is not like we are enjoying from the Chametz on Pesach itself. We can apply the concept of ‘Batel’ before Pesach without a question. So they can stock up, and that would be a way out of the problem for those who want to be Machmir like the Ben Ish Chai.
However, Chacham Ovadia says there is enough room to be lenient on this to even buy milk on Pesach and rely on those Poskim, like the Bet Efrayim.