I seem to have encountered a contradiction when thinking about the directions of $\textbf{H}$ and $\textbf{B}$ inside and outside a bar magnet.
Suppose that a bar magnet has a roughly constant magnetisation M pointing along the positive z direction. Suppose also that the magnet is made from an isotropic material, i.e. $\textbf{M}=\chi_m \textbf{H}$ (1). Therefore $\textbf{H}$ should be pointing in the same direction as $\textbf{M}$, provided that $\chi_m$ is positive, which should be the case for most magnetic materials? From the definition $\textbf{H}=\frac{1}{\mu_0}\textbf{B}-\textbf{M}$ and substituting using (1), we get $\textbf{B}=\mu_0(1+\chi_m)\textbf{H}=\frac{\mu_0(1+\chi_m)}{\chi_m}\textbf{M}=\frac{\mu_0\mu_r}{\mu_r-1}\textbf{M}$. Unless $\mu_r$ is less than 1, $\textbf{B}$ should also be parallel to $\textbf{M}$. Therefore so far we get that both $\textbf{H}$ and $\textbf{B}$ should point in the same direction as direction as $\textbf{M}$ inside the magnet, that is along the positive z direction.
We know that $\nabla\cdot\textbf{B}=0$ and thus applying boundary conditions on the top and bottom surfaces of the magnet (normal to the z axis) using an infinitesimally thin gaussian pillbox, we get that $\textbf{B}^\perp_\textrm{outside}=\textbf{B}^\perp_\textrm{inside}$. Therefore $\textbf{B}$ immediately outside the top surface should also point in the positive z direction. Assuming that there are no free currents near the magnet, $\nabla\times\textbf{H}=\textbf{J}_\textrm{free}=\textbf{0}$. Applying boundary conditions to the side surfaces of the magnet (parallel to the z axis), $\textbf{H}^\parallel_\textrm{outside}=\textbf{H}^\parallel_\textrm{inside}$. Therefore $\textbf{H}$ immediately outside the side surfaces must also point along the positive z direction. However, the field lines must also curl around and meet the top surface of the magnet, where $\textbf{H}$ will therefore need to point in the negative z direction. Since $\textbf{M}=\textbf{0}$ outside, $\textbf{H}=\frac{1}{\mu_0}\textbf{B}-\textbf{M}=\frac{1}{\mu_0}\textbf{B}$ and $\textbf{H}$ needs to be parallel to $\textbf{B}$ but we just argued that they point in opposite directions due to the boundary conditions. How do we resolve this contradiction?