A variational theorem in the theory of porous media