Fix CVE-2017-1000364 by backporting the patches for gen3