[RFC] Wayland Security Modules
Pekka Paalanen
pekka.paalanen at haloniitty.fi
Thu May 22 08:58:02 UTC 2025
On Tue, 20 May 2025 19:11:06 +0000
"Sloane, Brandon" <bsloane at owlcyberdefense.com> wrote:
> > -----Original Message-----
> > From: Pekka Paalanen <pekka.paalanen at haloniitty.fi>
> > Sent: Tuesday, May 20, 2025 4:58 AM
> > To: Sloane, Brandon <bsloane at owlcyberdefense.com>
> > Cc: wayland-devel at lists.freedesktop.org
> > Subject: Re: [RFC] Wayland Security Modules
> >
> > On Mon, 19 May 2025 15:48:04 +0000
> > "Sloane, Brandon" <bsloane at owlcyberdefense.com> wrote:
> >
> > > Hello,
> > >
> > > I've spent the past few months prototyping a security modules system
> > > for Wayland. Our specific motivation for this is to support SELinux
> > > integration to meet some rather unique security requirements.
> > > However, what we are proposing here is a rather general purpose
> > > security module system that provides high level hooks modules can then
> > > implement. Potential usecases for this system are:
> > >
> > > * Creating SELinux permissions for Wayland actions.
> > > * Integrating with non-SELinux Linux Security Modules
> > > (AppArmor/SMACK/etc).
> > > * Integrating with PolicyKit.
> > > * Disabling privileged protocols that a specific compositor
> > > implements.
> > > * Restricting privileged protocols to trusted clients.
> > > * Creating backends for wp_security_context_manager.
> >
> > Hi,
> >
> > from this and the readme I understand that the goal is to remove security
> > policies from compositors and place them outside of compositors and DE
> > projects, where they can be shared by many desktop and other environments.
> > Is that right?
> >
> > What is the reason for this goal?
> >
> > To unify policy configuration over all environments?
> >
> > To enforce policy where the compositor does not do so itself?
>
> I would say the goal is to move security policy out of the
> compositors to the system integrators. I tend to consider DE projects
> to be a form of system integration, so using them using this to
> implement their own security policies would be well within scope
> (although I would hope they do so in a way that allows downstream
> integrators to replace the security policy if needed). Our specific
> motivation is that we building systems with some rather niche
> security requirements that would not be suitable to implement in a
> general purpose DE. We also want to unify our policy configuration
> with a single environment, so our network policy, file access policy,
> device access policy, and GUI policy can all exist as a single
> unified security policy.
>
> The ability of have a common policy configuration work across
> different environments/compositors is nice, but was not a primary
> design goal. As we went to design this, we quickly found that, even
> if we were only concerned with a single compositor, the low-level IPC
> layer by far the most natural and simplest place to implement this.
>
> >
> > > Our current proof of concept is here:
> > > https://gitlab.freedesktop.org/bsloane1650/wayland. Some more
> > > in-depth technical discussion is available in the doc/WSM.md file
> > > in that repository.
> > >
> > > We also have some modules in development here:
> > > https://gitlab.freedesktop.org/bsloane1650/wayland-security-modules
> > > * Logger - a basic proof of concept that demonstrates
> > > instantiating a module and logging every access.
> > > * Allow-list - A basic proof of concept that demonstrates globally
> > > restricting what interfaces can be used.
> > > * SELinux - A more complex module that defers all access
> > > decisions to the system's SELinux policy (under active
> > > development)
> > >
> > > The overall design is to add hooks at key points in libwayland:
> > > * Creation and destruction of core libwayland objects: wl_client,
> > > wl_display, wl_global, wl_resource
> > > * Prior to sending an event to the client
> > > * Prior to invoking the request handler after receiving a request
> > > from a client.
> > > * Prior to publishing a global object
> > > * Prior to binding a global object.
> >
> > What about all the other Wayland protocol implementations that do
> > not use libwayland? Or those that bundle a libwayland without the
> > hooks?
>
> Our changes should only effect libwayland-server, and do not change
> the wire format at all. As such, non-libwayland clients should work
> just as well as libwayland clients.
>
> For compositors, a non-libwayland compositor would not see any change
> or benefit from this effort. If they want to be able to use a WSM,
> they would need to implement enough of the libwayland-server ABI to
> be compatible with whatever module(s) they want to use (or just the
> libwayland-server API if recompiling the module is acceptable).
> Originally, we had intended to have a WSM API that modules would be
> written against, which better enable sharing with non-libwayland
> compositors. However, we ultimately determined that such an API was
> not worth the effort.
>
> >
> >
> > > A security module is represented by a "struct wsm" object, which
> > > has void* for modules to use, and a function pointer for each
> > > hook. Compositors can instantiate these structs however they like
> > > and pass them into a new wl_display_create_with_wsms method. The
> > > existing wl_display_create method is modified to dynamically load
> > > shared object files based on the new WAYLAND_SECURITY_MODULES
> > > environmental variable. These shared objects are expected to
> > > export a wl_wsm_init symbol that instantiates a wsm structure.
> >
> > What's the failure mode of losing the environment variable by
> > accident, e.g. by a software update? Any security limitations just
> > won't be there and without notice? Isn't that too fragile and
> > invisible?
>
> Yes. Loosing the environmental variable would silently disable the
> security protections, which is certainly not ideal. How much of a
> risk this is would depend on how the DE developers or system
> integrators choose to set the environmental variable. I don't think
> there is a better option available from within libwayland. If a
> compositor wants to implement a more robust mechanism, it can do so
> by calling the new wl_display_create_with_wsms() method explicitly.
>
> >
> > > We have had success running this by linking unmodified compositors
> > > (mostly Weston) against an updated libwayland. Depending on what
> > > accesses the module blocks, existing compositors work without even
> > > needing a recompile. However, to be useful, we have found a
> > > couple of areas that additional compositor integration is needed.
> > > Mostly this has been shifting from wl_resourc_create to
> > > wl_resource_create_with_related in a few key places (such as
> > > creating a wl_data_offer) to allow the security modules to
> > > associated resources that are shared between clients.
> >
> > To me this sounds like aiming for unmodified compositors just won't
> > work. Would it not be better to aim for explicit integration?
>
> The actual design goal was maintaining backward compatibility.
> Updating to a WSM aware version of libwayland shouldn't break any
> existing system (unless they happened to have an environmental
> variable called WAYLAND_SECURITY_MODULES set).
Hi,
by explicit compositor integration I meant by not adding such hooks into
libwayland-server but have the compositor call into the WSM framework.
Libwayland-server can certainly be enhanced with supporting
functionality. The globals filtering is one that already exists. You
can get the client socket fd to ask the kernel about a security
context. What might be missing is asking which listening socket the
client connected to. These kind of things are fine.
> > Or, if unmodified compositors is an explicit design goal, make the
> > security layer a Wayland proxy? An independent man-in-the-middle
> > process.
> > > We have also found a need to modify compositors to deal with
> > > denials associated with new_id type requests. We think we have a
> > > workable solution implemented in libwsm_compositor that
> > > compositors can incorporate with a few library calls; but I still
> > > consider this the most questionable part of the project. This
> > > issue is discussed rather in much more detail in doc/WSM.md. Any
> > > input on this would be greatly appreciated.
> >
> > You cannot "deny" any request at will, not even those without new_id
> > arguments. The protocol specification defines the behaviour of each
> > request, and a security module cannot decide against the spec. It
> > would break the protocol, cause mismatching state between the
> > compositor and the client, likely lead to hard-to-debug failure
> > modes if it does not outright cause a protocol error soon after,
> > disconnecting the client. Some requests are specified so that the
> > compositor can decide to refuse, but those are very rare. In
> > general, it makes no sense to be able to gate each and every
> > request. No message can ever be ignored at will and expect the
> > application to continue working fine.
>
> I'm probably showing my roots as an SELinux developer here, but
> overly strict security modules causing applications to crash or
> misbehave in weird ways. My expectation is that general purpose
> systems would write their security policy to allow most accesses.
> Given how Wayland protocols are generally written, restricting access
> to global objects should be suitable for purposes, and that is
> already a well-supported concept. We are following the Linux Security
> Module model of 'let the security module decide what is or isn't a
> good idea'. If a module does this in a way that breaks things, that
> is up to the module. The goal here is simply to mitigate this issue
> as much as possible.
Linux system calls can return a failure. Programs are expected to check
for them.
X11 at least theoretically allows delivering recoverable errors to
clients.
Wayland requests allow neither. The only way to fail is to disconnect.
This makes me think that a security policy with this kind of an
implementation design will be much more prone to accidentally break
applications than LSM or XAce, up to a level where I wonder if it is
practical. What's worse is that in the client side, there is no way to
tell what failed. System calls can be traced to see their return
values, and X11 error events exist, but Wayland has neither unless you
disconnect the client.
> >
> > You also cannot really retrofit asynchronous access checks (that
> > may take more than, say, 100 ms) to interfaces or requests that
> > were not designed with that in mind. Wayland protocol stream
> > follows a strict execute-in-order model, so you would have to
> > freeze the whole client connection until an access decision is
> > available. This would make the application appear frozen, and the
> > application might get disconnected due to being unresponsive (even
> > though it would be the compositor's fault) or due to overflowing
> > socket buffers (less of a problem nowadays I guess).
>
> We are not particularly attached to asynchronous access checks. None
> of our users actually require it. I bring it up because most general
> purpose user systems have it nowadays. Our thinking for it was the
> initial behavior would be the same as a permission denial. However,
> we would introduce a wsm_manager global object that clients could
> bind to. This object would then send an event when a denial occurred
> because of an asynchronous check, and would send another event once
> the check is complete, allowing the client to retry the original
> action. Obviously, this does require the client to be aware of the
> new system, and assumes that the original "deny the request" behavior
> can be done in such a way that nothing outright breaks.
The first problem is that Wayland has no generic way to indicate a
gracefully failed request. This means that no client side code is
architected in a way that a failure might be possible to handle.
The problem with wsm_manager delivering failure events is that Wayland
is asynchronous. Since no request can gracefully fail, the protocol
interfaces are designed to take advantage of that, and allow clients to
send lots of requests before needing to wait for replies. Every request
carries a built-in assumption that the previous request succeeded. This
would bring a cascade failure.
There are a couple of problems with retry. The first is how to define
what actually should be retried. Wayland messages do not have any
message serial numbers to indicate which one we are talking about. The
second problem is the burden of implementation in a client to actually
prepare for failure and implement a retry. I cannot imagine that being
feasible, if it wasn't part of the original protocol interface
specification.
> This scheme should be implementable without any explicit support from
> libwayland. We have not done so because our usecases do not need it.
Could you explain more of your actual use cases? Maybe people would have
better ideas how to solve them. I'm curious about when does your WSM
design actually work.
You later wrote that e.g. with clipboard access, the security policy
would need to know not just the source and destination clients, but
also the destination wl_surface. Maybe you want to have even more
context. But can you really get this context reliably from
libwayland-server hooks?
I guess you would need to do a lot of protocol state tracking to have
an idea of the context. The compositor already does this state
tracking, so it could just tell the WSM if there was an API for it.
Thanks,
pq
> > Instead, developers try to account for the security requirements at
> > the protocol (extension) design. In the simplest form, the
> > interface offered through wl_registry either exists if granted, or
> > not.
>
> I think I've alluded to this before, but one of the hooks is in
> wl_global_is_visible, that would enable modules to implement exactly
> this form of access control.
>
>
> > When finer grained control
> > is necessary, the possibility to refuse and revoke is built into
> > the interface specification. Also the need for asynchronous access
> > checks is considered, allowing the application and the compositor
> > to continue their otherwise normal operations until the access
> > decision arrives.
> >
> > If there are security design issues with Wayland protocol
> > interfaces, I would hope they get fixed by revising the protocol.
> >
> > I am most sceptical about the hooking libwayland part of the
> > proposal. OTOH, offering compositors an API they can query in order
> > to determine access might be a good idea. It might need to be
> > decoupled from literal protocol interfaces, because there can be
> > many different interfaces, not all upstream wayland-protocols or
> > even Wayland at all, for applications to do things.
> >
> >
> > Thanks,
> > pq
> >
> >
> > > We have also experimented with per-surface screenshot
> > > restrictions in Weston, which needs to be implemented almost
> > > entirely in the compositor itself.
> > >
> > > We probably should have gone public with this far earlier in the
> > > design process. However, despite the late stage we find ourselves
> > > in, we are open to significant revisions based on community
> > > feedback.
> > >
> > > Thanks,
> > > Brandon
> > >
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20250522/e250920e/attachment.sig>
More information about the wayland-devel
mailing list