Re: ABIs, syscall tables, and the AUDIT_ARCH_* defines

Paul Moore
2013-10-29T21:56:29Z

On Tuesday, October 29, 2013 05:29:41 PM Eric Paris wrote:
> On Tue, 2013-10-29 at 17:28 -0400, Paul Moore wrote:
> > Take x86_64 and x32 as an example (think of x32 as a 32-bit version of
> > x86_64). Both x32 and x86_64 use the AUDIT_ARCH_X86_64 value and general
> > calling convention, but they have a different syscall table.
>
> I guess a good question is "is that right" ?
>
> #define AUDIT_ARCH_X86_64 (EM_X86_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
>
> Would we not be better off with a:
>
> #define AUDIT_ARCH_X32 (EM_X86_64|__AUDIT_ARCH_LE) ?

If you look at the libseccomp code, that is exactly how we define
SCMP_ARCH_X32. To me it makes sense.

However, I think it may already be too late to change things in the kernel.
Support for x32 has been in mainline for a while now and userspace has already
had to deal with it; changing to AUDIT_ARCH_X32, while arguably The Right
Thing To Do, would likely involve userspace breakage. At least it would break
libseccomp :)

> Do x86_64 and x32 share the same syscall entry code?

I can't say off the top of my head, but if I had to guess, I would say yes.

UPDATE: I took a quick peek and while I'm not well versed on the syscall entry
code, it does appear that they share most of the important bits.

> Is there where the AUDIT_ARCH_X86_64 comes from?

I believe so. Depending on the state of CONFIG_AUDITSYSCALL it either gets
passed directly as the first argument to __audit_syscall_entry() in entry_64.S
or via syscall_trace_enter() which once again just uses AUDIT_ARCH_X86_64.

In both cases it should be possible to set it to a new AUDIT_ARCH_X32, but my
previous concerns about userspace breakage still apply.

> Is this similar for ARM? Right now, the only thing we have is:
>
> #define AUDIT_ARCH_ARM (EM_ARM|__AUDIT_ARCH_LE)
> #define AUDIT_ARCH_ARMEB (EM_ARM)
>
> Is this enough? Should we add more?

No idea really, I'm still getting up to speed on ARM. Personally, ARM OABI is
really weird and considering that most everything is EABI now, I don't think
I'm ever going to support ARM OABI in libseccomp.

The answer might not be as easy for audit since the kernel technically already
supports ARM OABI, but I'm guessing that if you haven't head anyone shouting
at you by now you might not have to worry too much about it.

> I'm way way way more ARM idiotic than I am about x86_64.

Me too. Although the more I learn about ARM the more it scares me.

> I know the ARM people at least told us that ARM wasn't going to work right
> with what we have today... So they added to the audit Kconfig:
>
> depends on AUDIT && (X86 || PPC || S390 || IA64 || UML || SPARC64 ||
> SUPERH || (ARM && AEABI && !OABI_COMPAT))

Hmm, so that might be your "out" here, unless you really want to deal with ARM
OABI :) I'm not even entirely sure if OABI works on the newer ARM hardware.

> Is fixing this with differentiated AUDIT_ARCH flags even possible? Am I
> just talking out of my bum?

/me shrugs

Sorry, still learning this stuff too.

--
paul moore
security and virtualization @ redhat