Re: [REGRESSION][BISECTED] erroneous buffer overflow detected in bch2_xattr_validate

From: Kees Cook
Date: Wed Oct 16 2024 - 16:44:45 EST


On Wed, Oct 16, 2024 at 04:18:19AM +0200, Jan Hendrik Farr wrote:
> On 15 18:22:50, Bill Wendling wrote:
> > On Thu, Oct 3, 2024 at 4:33 AM Jan Hendrik Farr <kernel@xxxxxxxx> wrote:
> > > On 02 11:18:57, Thorsten Blum wrote:
> > > > On 28. Sep 2024, at 22:34, Kees Cook <kees@xxxxxxxxxx> wrote:
> > > > > [...]
> > > > >
> > > > > Sorry, I've been out of commission with covid. Globally disabling this
> > > > > macro for clang is not the right solution (way too big a hammer).
> > > > >
> > > > > Until Bill has a fix, we can revert commit
> > > > > 86e92eeeb23741a072fe7532db663250ff2e726a, as the problem is limited to
> > > > > certain situations where 'counted_by' is in use.
> > > >
> > > > I already encountered two other related __counted_by() issues [1][2]
> > > > that are now being reverted. Would it be an option to disable it
> > > > globally, but only for Clang < v19 (where it looks like it'll be fixed)?
> > > >
> > > > Otherwise adding __counted_by() might be a slippery slope for a long
> > > > time and the edge cases don't seem to be that rare anymore.
> > > >
> > > > Thanks,
> > > > Thorsten
> > > >
> > > > [1] https://lore.kernel.org/all/20240909162725.1805-2-thorsten.blum@xxxxxxxxxx/
> > > > [2] https://lore.kernel.org/all/20240923213809.235128-2-thorsten.blum@xxxxxxxxx/
> > >
> > > This issue is now fixed on the llvm main branch:
> > > https://github.com/llvm/llvm-project/commit/882457a2eedbe6d53161b2f78fcf769fc9a93e8a
> > >
> > > So presumably this will go into 19.1.2, not sure what this means for
> > > distros that ship clang 18. Will they have to be notified to backport
> > > this?
> > >
> > FYI, Clang 19.1.2 shipped with your fix in it.
> >
>
> Thx for the info.
>
> How should we continue with the "off by 4" issue? The way I see it either
> the kernel has to change struct_size (lots of work) or clang has to get
> an option to follow the kernels behavior. I'm in favor of adding an
> option to clang.

I'm planning on checking how much impact there is on the kernel to fix
struct_size() to be precise. It really does need to match __bdos for
Clang and GCC.

-Kees

--
Kees Cook