Military officials in Pakistan say six soldiers and 40 militants were killed overnight in an attack on a paramilitary fort near the border with Afghanistan .