Public bug reported:

[Impact]

This bug implements the enablement of CONFIG_SECURITY_DMESG_RESTRICT
feature by default for Groovy onward, proposed to ubuntu-devel:

https://lists.ubuntu.com/archives/ubuntu-devel/2020-June/041063.html

The kernel log buffer contains a wealth of sensitive information, such
as detailed call traces and kernel addresses found in register dumps in
kernel oops messages.

Exploit developers and attackers can leverage these information leaks to
get past KASLR, and they can use the kernel log buffer to get instant
feedback on their privilege escalation attacks, as failures will be
shown as further oops messages, which attackers can use to fix and tune
their programs until they work.

Currently, if I create a new, unprivileged user on a Focal system, they
cannot access /var/log/kern.log, /var/log/syslog or see system events in
journalctl. But yet, they are given free reign to the kernel log buffer.

$ sudo adduser dave
$ su dave
$ groups
dave
$ cat /var/log/kern.log
cat: /var/log/kern.log: Permission denied
$ cat /var/log/syslog
cat: /var/log/syslog: Permission denied
$ journalctl
Hint: You are currently not seeing messages from other users and the system.
      Users in groups 'adm', 'systemd-journal' can see all messages.
      Pass -q to turn off this notice.
Jun 16 23:44:59 ubuntu systemd[2328]: Reached target Main User Target.
Jun 16 23:44:59 ubuntu systemd[2328]: Startup finished in 69ms.
$ dmesg
[    0.000000] Linux version 5.4.0-34-generic (buildd at lcy01-amd64-014)
(gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #38-Ubuntu SMP Mon May 25 15:46:55
UTC 2020 (Ubuntu 5.4.0-34.38-generic 5.4.41)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.4.0-34-generic
root=UUID=f9f909c3-782a-43c2-a59d-c789656b4188 ro
...

I propose that we restrict access to dmesg to users in group 'adm' like
so:

1) CONFIG_SECURITY_DMESG_RESTRICT=y in the kernel.
2) Following changes to /bin/dmesg permissions in package 'util-linux'
    - Ownership changes to root:adm
    - Permissions changed to 0750 (-rwxr-x---)
    - Add cap_syslog capability to binary.
3) Add a commented out '# kernel.dmesg_restrict = 0' to
   /etc/sysctl.d/10-kernel-hardening.conf

For most users, they will use the initial admin account, which is in the
'adm' group already, and will see no impact to these changes. If a log
scraper type program needs access to dmesg, the user the daemon runs as
can simply be added to the 'adm' group.

[Testcase]

Currently, all users can run /usr/bin/dmesg to view the kernel log
buffer:

$ dmesg
[    0.000000] Linux version 5.4.0-34-generic (buildd at lcy01-amd64-014)
(gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #38-Ubuntu SMP Mon May 25 15:46:55
UTC 2020 (Ubuntu 5.4.0-34.38-generic 5.4.41)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.4.0-34-generic
root=UUID=f9f909c3-782a-43c2-a59d-c789656b4188 ro
...

When the changes are applied, the default admin user will be able to
view dmesg (since they are in group 'adm'), while new unprivileged users
will not.

$ whoami
ubuntu
$ groups
ubuntu adm cdrom sudo dip plugdev
$ dmesg
[    0.000000] Linux version 5.4.0-34-generic (buildd at lcy01-amd64-014)
(gcc version 9.3.0 (Ubuntu 9.3.0-10ubuntu2)) #38-Ubuntu SMP Mon May 25 15:46:55
UTC 2020 (Ubuntu 5.4.0-34.38-generic 5.4.41)
[    0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-5.4.0-34-generic
root=UUID=f9f909c3-782a-43c2-a59d-c789656b4188 ro
...

$ sudo adduser dave
$ su dave
$ groups
dave
$ dmesg
-bash: /usr/bin/dmesg: Permission denied

[Regression Potential]

Some users or log scraper type programs may need to view the kernel log
buffer, or have access to dmesg. In this case, the underlying service
user would need to be added to the 'adm' group.

Users have the ability to disable DMESG_RESTRICT by uncommenting the
sysctl in /etc/sysctl.d/10-kernel-hardening.conf.

** Affects: linux (Ubuntu)
     Importance: Undecided
         Status: Fix Committed

** Affects: procps (Ubuntu)
     Importance: Undecided
     Assignee: Matthew Ruffell (mruffell)
         Status: In Progress

** Affects: util-linux (Ubuntu)
     Importance: Undecided
     Assignee: Matthew Ruffell (mruffell)
         Status: In Progress

** Affects: linux (Ubuntu Groovy)
     Importance: Undecided
         Status: Fix Committed

** Affects: procps (Ubuntu Groovy)
     Importance: Undecided
     Assignee: Matthew Ruffell (mruffell)
         Status: In Progress

** Affects: util-linux (Ubuntu Groovy)
     Importance: Undecided
     Assignee: Matthew Ruffell (mruffell)
         Status: In Progress

** Also affects: linux (Ubuntu Groovy)
   Importance: Undecided
       Status: New

** Changed in: linux (Ubuntu Groovy)
       Status: New => Fix Committed

** Also affects: procps (Ubuntu)
   Importance: Undecided
       Status: New

** Changed in: procps (Ubuntu Groovy)
       Status: New => In Progress

** Changed in: procps (Ubuntu Groovy)
     Assignee: (unassigned) => Matthew Ruffell (mruffell)

** Also affects: util-linux (Ubuntu)
   Importance: Undecided
       Status: New

** Changed in: util-linux (Ubuntu Groovy)
       Status: New => In Progress

** Changed in: util-linux (Ubuntu Groovy)
     Assignee: (unassigned) => Matthew Ruffell (mruffell)

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1886112

Title:
  Enabling DMESG_RESTRICT in Groovy Onward

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1886112/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to