Bug 1222978

Summary: [SELinux] gnome-control-center (users) unable to set AutoLogin
Product: [openSUSE] openSUSE Tumbleweed Reporter: Richard Brown <rbrown>
Component: SecurityAssignee: xiaoguang wang <xiaoguang.wang>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: cathy.hu, filippo.bonazzi, hpj, jsegitz, nigorioust, xiaoguang.wang
Version: Current   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Richard Brown 2024-04-17 14:48:13 UTC
GNOME Control Center has the ability to set autologin, as button in a users account,  requiring Polkit escalation in order to be able to set it

Polkit is doing it's thing fine..but SELinux blocks it :)

Audit.log output below

type=USER_ACCT msg=audit(1713364967.267:211): pid=23024 uid=1000 auid=1000 ses=3 subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 msg='op=PAM:accounting grantors=pam_unix acct="ilmehtar" exe="/usr/libexec/polkit-1/polkit-agent-helper-1" hostname=? addr=? terminal=? res=success'
type=AVC msg=audit(1713364970.590:212): avc:  denied  { write } for  pid=1269 comm="accounts-daemon" name="sysconfig" dev="overlay" ino=283 scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1713364970.590:213): avc:  denied  { add_name } for  pid=1269 comm="accounts-daemon" name="displaymanager.new.1025417169" scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1713364970.590:214): avc:  denied  { create } for  pid=1269 comm="accounts-daemon" name="displaymanager.new.1025417169" scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=1
type=AVC msg=audit(1713364970.593:215): avc:  denied  { write } for  pid=1269 comm="accounts-daemon" path="/etc/sysconfig/displaymanager.new.1025417169" dev="overlay" ino=1179107 scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=1
type=AVC msg=audit(1713364970.593:216): avc:  denied  { remove_name } for  pid=1269 comm="accounts-daemon" name="displaymanager.new.1025417169" dev="overlay" ino=1179107 scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=dir permissive=1
type=AVC msg=audit(1713364970.593:217): avc:  denied  { rename } for  pid=1269 comm="accounts-daemon" name="displaymanager.new.1025417169" dev="overlay" ino=1179107 scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=1
type=AVC msg=audit(1713364970.593:218): avc:  denied  { unlink } for  pid=1269 comm="accounts-daemon" name="displaymanager" dev="overlay" ino=31627 scontext=system_u:system_r:accountsd_t:s0 tcontext=system_u:object_r:etc_t:s0 tclass=file permissive=1

Not the most severe issue in the world (I personally dislike the feature)..but I have users who are super passionate about it, so at least I can now say the issue is filed in the right place :)
Comment 1 Richard Brown 2024-04-17 14:52:08 UTC
*** Bug 1221272 has been marked as a duplicate of this bug. ***
Comment 2 Cathy Hu 2024-05-14 08:56:56 UTC
I am having some issues that are related to our custom patches in gdm.

When the autologin setting is changed, gdm first writes a temporary file in /etc/sysconfig/displaymanager.new.<randomnumber> and writes it back into /etc/sysconfig/displaymanager.

This is done in our custom patch: https://build.opensuse.org/projects/openSUSE:Factory/packages/gdm/files/gdm-sysconfig-settings.patch?expand=1

```
+static gboolean
+save_settings_file (const gchar *file_name, gchar **lines)
+{
+        GIOStatus   last_status = G_IO_STATUS_ERROR;
+        GIOChannel *channel     = NULL;
+        gchar      *temp_file_name;
+        gint        i;
+
+        temp_file_name = g_strdup_printf ("%s.new.%u", file_name, g_random_int ());
+
+        channel = g_io_channel_new_file (temp_file_name, "w", NULL);
...
```

The problem is that selinux can not easily set the correct type to displaymanager.new.<randomnumber> as we can not easily file transition to a wildcard.

There are 2 options to fix this:
1) We remove the <randomnumber>, which should be okay as we are not in /tmp and /etc/sysconfig is not world writable (please correct me if i am wrong @Johannes). Then i can add a transition to the correct type of displaymanager.new in the policy
2) We make the patch selinux-aware to set the correct types (needs probably a lot of changes)

@xiaoguang.wang @hpj as maintainer of gdm / patch writers, is there a reason why we need the random number in /etc/sysconfig/displaymanager.new.<randomnumber>? and what would be your preferred solution?
Comment 3 xiaoguang wang 2024-05-20 07:32:48 UTC
(In reply to Cathy Hu from comment #2)
> There are 2 options to fix this:
> 1) We remove the <randomnumber>, which should be okay as we are not in /tmp
> and /etc/sysconfig is not world writable (please correct me if i am wrong
> @Johannes). Then i can add a transition to the correct type of
> displaymanager.new in the policy

It's possible there are two or more gdm processes at same time(When remote login with session management), so we use randomnumber to distinguish them.

> 2) We make the patch selinux-aware to set the correct types (needs probably
> a lot of changes)

I have no idea what is the best solution.
Comment 4 Filippo Bonazzi 2024-05-22 07:55:52 UTC
Hi @xiaoguang.wang, instead of writing the temp file to /etc/sysconfig/displaymanager.new.<somenumber>, could you write it to <some_private_temp_folder>/displaymanager.new?

If you do this, we can detect the file by name and assign it the proper SELinux context upon creation. This would be the easiest and cleanest solution for us.

The file context is retained when the temp file is then renamed (moved) to /etc/sysconfig/displaymanager.
Comment 5 xiaoguang wang 2024-05-27 02:49:05 UTC
(In reply to Filippo Bonazzi from comment #4)
> Hi @xiaoguang.wang, instead of writing the temp file to
> /etc/sysconfig/displaymanager.new.<somenumber>, could you write it to
> <some_private_temp_folder>/displaymanager.new?

Writing the temp file to /tmp/gdm.xxxxxx/displaymanager.new, xxxxxx is the random number. Does it work for SELinux context?
Comment 6 Filippo Bonazzi 2024-05-27 06:21:25 UTC
I think so. If you can build a GDM rpm with this change, we can test it and see what we need to change for SELinux.
Comment 7 xiaoguang wang 2024-05-29 01:14:42 UTC
The temp file is changed to /run/sysconfig.XXXXXX/displaymanager.new. My repo is https://build.opensuse.org/package/show/home:xiaoguang_wang:branches:GNOME:Factory:SELinux/gdm, you can test with it.
Comment 9 Filippo Bonazzi 2024-06-04 12:39:58 UTC
Any specific reason why you went with /run/sysconfig.XXXXXX/displaymanager.new instead of /tmp/sysconfig.XXXXXX/displaymanager.new?
Comment 10 xiaoguang wang 2024-06-05 00:58:05 UTC
(In reply to Filippo Bonazzi from comment #9)
> Any specific reason why you went with
> /run/sysconfig.XXXXXX/displaymanager.new instead of
> /tmp/sysconfig.XXXXXX/displaymanager.new?

The package gdm and accountsservice use the same way to write displaymanager. The accountsservice has no priority to write the /tmp, so I change it to /run.
Comment 11 Filippo Bonazzi 2024-06-17 10:45:58 UTC
/etc/sysconfig/displaymanager is managed in parallel at least by by (possibly several instances of) gdm and accountsservice.

These can access the file in several ways, but have been patched to specifically atomically replace the file with a new version with the /run/.../displaymanager.new mechanism described above. This is not actually fully atomic since /etc/sysconfig/displaymanager is hard-removed first, and /run/.../displaymanager.new is then moved to /etc/sysconfig/displaymanager.

The proposed solution in https://gitlab.suse.de/selinux/selinux-policy/-/merge_requests/61 takes into account this complexity of file access, removal, creation from scratch, etc. by both GDM and accountsservice.
Comment 12 Filippo Bonazzi 2024-06-18 09:07:34 UTC
Fix submitted in https://build.opensuse.org/request/show/1181332
Comment 14 OBSbugzilla Bot 2024-06-19 10:05:01 UTC
This is an autogenerated message for OBS integration:
This bug (1222978) was mentioned in
https://build.opensuse.org/request/show/1181710 Factory / gdm
https://build.opensuse.org/request/show/1181711 Factory / accountsservice
Comment 15 xiaoguang wang 2024-06-20 01:26:40 UTC
The change is sent to GNOME:Factory
https://build.opensuse.org/request/show/1181710 Factory / gdm
https://build.opensuse.org/request/show/1181711 Factory / accountsservice