Instability of Ekman-Hartmann boundary layers, with application to the fluid flow near the core-mantle boundary