RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 2097419 - usbguard-daemon gets way too easily killed by OOM killer
Summary: usbguard-daemon gets way too easily killed by OOM killer
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: usbguard
Version: 9.0
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Attila Lakatos
QA Contact: Dalibor Pospíšil
Petr Hybl
URL:
Whiteboard:
Depends On:
Blocks: 2159411
TreeView+ depends on / blocked
 
Reported: 2022-06-15 16:12 UTC by Jan Pazdziora
Modified: 2023-05-10 14:14 UTC (History)
5 users (show)

Fixed In Version: usbguard-1.0.0-13.el9
Doc Type: Bug Fix
Doc Text:
.OOM killer no longer terminates `usbguard` prematurely Previously, the `usbguard.service` file did not contain a definition of the `OOMScoreAdjust` option for the `systemd` service. Consequently, when the system was low on resources, the `usbguard-daemon` process could be terminated before other unprivileged processes. With this update, `usbguard.service` file now includes `OOMScoreAdjust` setting, which prevents the Out-of-Memory (OOM) killer terminate the `usbguard-daemon` process prematurely.
Clone Of:
: 2159411 (view as bug list)
Environment:
Last Closed: 2023-05-09 07:48:17 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Github USBGuard usbguard pull 563 0 None open Harden service file: Set OOMScoreAdjust to -1000 2022-11-01 11:15:15 UTC
Gitlab redhat/centos-stream/rpms usbguard merge_requests 10 0 None opened RHEL 9.2.0 ERRATUM 2022-11-28 11:44:03 UTC
Red Hat Issue Tracker RHELPLAN-125370 0 None None None 2022-06-15 16:18:48 UTC
Red Hat Issue Tracker SECENGSP-4640 0 None None None 2022-06-15 16:18:51 UTC
Red Hat Product Errata RHBA-2023:2351 0 None None None 2023-05-09 07:48:29 UTC

Description Jan Pazdziora 2022-06-15 16:12:40 UTC
Description of problem:

The usbguard is a security relevant service which authorizes new devices on a system. When it gets killed, the authorization suddenly is not available and anything is allowed to get plugged-in.

The out-of-memory killer in the kernel can easily kill the usbguard-daemon for example when unauthorized process creates many small processes, which causes the OOM algorithm to see usbguard-daemon as the best candidate to be killed, instead of aiming at some of those unprivileged processes.

Version-Release number of selected component (if applicable):

usbguard-1.0.0-10.el9

How reproducible:

Non deterministic but it is possible to get system to such state.

Steps to Reproduce:
1. Have machine with say 2.5 GB of memory.
2. Disable swap to put more pressure on the memory: swapoff -a
3. systemctl start usbguard
4. In /etc/security/limits.conf add

test		soft nproc	unlimited
test		hard nproc	unlimited
test		soft sigpending	unlimited
test		hard sigpending	unlimited

5. Compile program

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sched.h>
#include <sys/mman.h>

void alloc_memory(int len)
{
    void *ret = mmap(0, len, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
    if (ret == MAP_FAILED) {
        perror("mmap");
        return;
    }
    memset(ret, 'x', len);
}

int main(int argc, char **argv)
{
    if (argc < 3) {
        fprintf(stderr, "usage: %s <bytes> <processes>\n", argv[0]);
        return 1;
    }

    int bytes = atoi(argv[1]);
    int procs = atoi(argv[2]);

    while (procs-- > 0) {
        switch (fork()) {
            case -1:
                perror("first fork");
                return 1;
            case 0:
                switch (fork()) {
                    case -1:
                        perror("second fork");
                        return 1;
                    case 0:
                        alloc_memory(bytes);
                        sleep(1000);
                        return 0;
                    default:
                        return 0;
                }
            default:
                break;
        }
        sched_yield();  // be somewhat inconspicuous
    }
}

// Thanks to Jiří Jabůrek.

6. Log in as the user test.
7. As root, increase the maximum number of processes for the session, something like

   echo 1000000 > /sys/fs/cgroup/user.slice/user-1000.slice/pids.max

   On my system that value is 7039 by default and I did not find a way to increase it before the user logs in.
8. Run the testing program as user test with some reasonable parameters. On my system, running it a couple of times as

   ./test-alloc 10 10000

   will eventually exhaust the memory. You can also use

   systemctl status $$

   to see the memory used, and to poke the system in other ways as well.
   Eventually the system will get slow, OOM killer will kick in, and if sshd won't get killed, you will be able to check the journal.
9. As root, run journalctl -l | grep kill

Actual results:

Jun 15 18:10:15 machine.example.com kernel: oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/usbguard.service,task=usbguard-daemon,pid=338919,uid=0
Jun 15 18:10:15 machine.example.com kernel: Out of memory: Killed process 338919 (usbguard-daemon) total-vm:29264kB, anon-rss:552kB, file-rss:0kB, shmem-rss:0kB, UID:0 pgtables:68kB oom_score_adj:0

Expected results:

usbguard is a security and authorization relevant service, it should set its OOMScoreAdjust to some negative value to avoid being killed before the unprivileged processes.

Additional info:

Comment 1 Attila Lakatos 2022-07-27 08:48:19 UTC
Thank you for the detailed report and for the catch. I definitely agree that the OOMScoreAdjust process property should be set to some negative value. Maybe we could go with the same approach as bz2100089 - "OOMScoreAdjust=-1000"

Comment 17 errata-xmlrpc 2023-05-09 07:48:17 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (usbguard bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2351


Note You need to log in before you can comment on or make changes to this bug.