Re: [PATCH v3 10/16] x86/extable: Mark handlers __cficanonical

From: Sami Tolvanen
Date: Tue Sep 14 2021 - 16:39:01 EST


On Tue, Sep 14, 2021 at 12:37 PM Kees Cook <keescook@xxxxxxxxxxxx> wrote:
>
> On Tue, Sep 14, 2021 at 12:10:39PM -0700, Sami Tolvanen wrote:
> > Exception tables are populated in assembly code, but the handlers are
> > called in fixup_exception, which trips indirect call checking with
> > CONFIG_CFI_CLANG. Mark the handlers __cficanonical to allow addresses
> > taken in assembly to pass CFI checking.
> >
> > Signed-off-by: Sami Tolvanen <samitolvanen@xxxxxxxxxx>
> > ---
> > arch/x86/mm/extable.c | 64 ++++++++++++++++++++++++-------------------
> > 1 file changed, 36 insertions(+), 28 deletions(-)
> >
> > diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
> > index e1664e9f969c..d16912dcbb4e 100644
> > --- a/arch/x86/mm/extable.c
> > +++ b/arch/x86/mm/extable.c
> > @@ -24,16 +24,18 @@ ex_fixup_handler(const struct exception_table_entry *x)
> > return (ex_handler_t)((unsigned long)&x->handler + x->handler);
> > }
> >
> > -__visible bool ex_handler_default(const struct exception_table_entry *fixup,
> > - struct pt_regs *regs, int trapnr,
> > - unsigned long error_code,
> > - unsigned long fault_addr)
> > +__visible __cficanonical
> > +bool ex_handler_default(const struct exception_table_entry *fixup,
> > + struct pt_regs *regs, int trapnr,
> > + unsigned long error_code,
> > + unsigned long fault_addr)
> > {
> > regs->ip = ex_fixup_addr(fixup);
> > return true;
> > }
> > EXPORT_SYMBOL(ex_handler_default);
> >
> > +__visible __cficanonical
> > __visible bool ex_handler_fault(const struct exception_table_entry *fixup,
>
> Double __visible here, but with that fixed:

Ah, thanks for noticing that. I'll fix it in the next version.

>
> Reviewed-by: Kees Cook <keescook@xxxxxxxxxxxx>
>
> I would note that given Linus's recent comments on attribute locations,
> it does seem that __cficanonical is more a function behavior attribute
> than a storage class... I'm not really sure:
> https://lore.kernel.org/mm-commits/CAHk-=wiOCLRny5aifWNhr621kYrJwhfURsa0vFPeUEm8mF0ufg@xxxxxxxxxxxxxx

__visible is not really a storage class either, but I thought it would
make sense to keep these attributes together. I can certainly move
them if anyone has strong feelings about the location.

Sami