Re: [RFC PATCH v3 11/11] mseal:add documentation

From: Theo de Raadt
Date: Sat Jan 20 2024 - 11:59:19 EST


Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Sat, 20 Jan 2024 at 07:23, Theo de Raadt <deraadt@xxxxxxxxxxx> wrote:
> >
> > There is an one large difference remainig between mimmutable() and mseal(),
> > which is how other system calls behave.
> >
> > We return EPERM for failures in all the system calls that fail upon
> > immutable memory (since Oct 2022).
> >
> > You are returning EACESS.
> >
> > Before it is too late, do you want to reconsider that return value, or
> > do you have a justification for the choice?
>
> I don't think there's any real reason for the difference.
>
> Jeff - mind changing the EACESS to EPERM, and we'll have something
> that is more-or-less compatible between Linux and OpenBSD?

(I tried to remember why I chose EPERM, replaying the view from the
German castle during kernel compiles...)

In mmap, EACCESS already means something.

[EACCES] The flag PROT_READ was specified as part of the prot
parameter and fd was not open for reading. The flags
MAP_SHARED and PROT_WRITE were specified as part of
the flags and prot parameters and fd was not open for
writing.

In mprotect, the situation is similar

[EACCES] The process does not have sufficient access to the
underlying memory object to provide the requested
protection.

immutable isn't an aspect of the underlying object, but an aspect of the
mapping.

Anyways, it is common for one errno value to have multiple causes.

But this error-aliasing can make it harder to figure things out when
studying a "system call trace" a program, and I strongly believe in
keeping systems are simple as possible.

For all the memory mapping control operations, EPERM was available and
unambiguous.