Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 905302 - sys-auth/pambase: pam_limits don't get applied after login from tty when enforcing
Summary: sys-auth/pambase: pam_limits don't get applied after login from tty when enfo...
Status: UNCONFIRMED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: SELinux (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: SE Linux Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-04-29 17:31 UTC by Nikita Romaniuk
Modified: 2024-01-19 05:48 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Nikita Romaniuk 2023-04-29 17:31:28 UTC
The rules from /etc/security/limits.conf (or /etc/security/limits.d/*.conf) don't get applied after logging in with SELinux enforcing, but they do with permissive.

This is not a bug in PAM because if you change this line from /etc/pam.d/system-auth:
  session		required	pam_limits.so
to:
  session		required	pam_limits.so debug
in /var/log/auth.log will be log entries that confirm that PAM has tried to set the limits. And it works in permissive mode. So that's a bug in the policy.

By default no AVC denials are being written into /var/log/audit/audit.log because of a dontaudit rule. If you clean them out by running `semodule -DB`, the AVCs will be in the log.

I fixed this by creating a policy:
  allow local_login_t unconfined_t:process { noatsecure rlimitinh siginh };

If you try to login into a shell and run `ulimit -a` you'll see your changed values. This applies to all unconfined children of the shell.

Reproducible: Always

Steps to Reproduce:
1. Add a rule to /etc/security/limits.conf:
   @users - nofile 1000000

   This will set the count of maximum open file descriptors to 1000000 for `users` group.
2. Ensure SELinux is enforcing
3. Reboot
4. Log into your user
5. Run `ulimit -n`
6. See that the value is the default (1024)
Actual Results:  
The rules from /etc/security/limits.conf OR|AND /etc/security/limits.d/*.conf don't get applied. The limits are the default values.

Expected Results:  
The rules from /etc/security/limits.conf OR|AND /etc/security/limits.d/*.conf should be applied. So, if you changed the `nofile` property, `ulimit -n` should print your value and not 1024 (the default one).

Portage 3.0.46 (python 3.10.11-final-0, default/linux/amd64/17.0/musl/hardened/selinux, gcc-13, musl-1.2.3-r8, 6.2.12-gentoo-kelvium-musl x86_64)
=================================================================
System uname: Linux-6.2.12-gentoo-kelvium-musl-x86_64-Intel-R-_Xeon-R-_CPU_E5-2650_v3_@_2.30GHz-with-libc
KiB Mem:    16240752 total,    703324 free
KiB Swap:    4194300 total,   4190172 free
Timestamp of repository gentoo: Fri, 28 Apr 2023 19:45:01 +0000
Head commit of repository gentoo: 3c33fb6e89517d53a2ca8e1fb380e59d4a9585ac
Timestamp of repository guru: Fri, 28 Apr 2023 18:03:53 +0000
Head commit of repository guru: d800ba3887fa124f49febeba37b6d882e65b31b3

Timestamp of repository musl: Tue, 25 Apr 2023 02:04:23 +0000
Head commit of repository musl: c1bfa2317eb7780ca57fbd93acc01df5df737e9f

Head commit of repository polymc: f219527ba3c921fc82605105be9d09272c773e2a

sh bash 5.2_p15-r2
ld GNU ld (Gentoo 2.40 p4) 2.40.0
ccache version 4.8 [disabled]
app-misc/pax-utils:        1.3.7::gentoo
app-shells/bash:           5.2_p15-r2::gentoo
dev-java/java-config:      2.3.1::gentoo
dev-lang/perl:             5.36.0-r2::gentoo
dev-lang/python:           3.10.11::gentoo, 3.11.3::gentoo
dev-lang/rust:             1.69.0-r1::gentoo
dev-util/ccache:           4.8::gentoo
dev-util/cmake:            3.26.3::gentoo
dev-util/meson:            1.1.0::gentoo
sec-policy/selinux-base:   2.20221101-r4::gentoo
sys-apps/baselayout:       2.13-r1::gentoo
sys-apps/openrc:           0.47.1::gentoo
sys-apps/sandbox:          2.30-r1::gentoo
sys-devel/autoconf:        2.13-r8::gentoo, 2.71-r6::gentoo
sys-devel/automake:        1.16.5-r1::gentoo
sys-devel/binutils:        2.40-r4::gentoo
sys-devel/binutils-config: 5.5::gentoo
sys-devel/clang:           15.0.7-r1::gentoo, 16.0.2::gentoo
sys-devel/gcc:             13.1.0-r1::gentoo
sys-devel/gcc-config:      2.10::gentoo
sys-devel/libtool:         2.4.7-r1::gentoo
sys-devel/llvm:            15.0.7::gentoo, 16.0.2::gentoo
sys-devel/make:            4.4.1::gentoo
sys-kernel/linux-headers:  6.2::gentoo (virtual/os-headers)
sys-libs/libselinux:       3.5::gentoo
sys-libs/musl:             1.2.3-r8::gentoo
Repositories:

gentoo
    location: /var/db/repos/gentoo
    sync-type: rsync
    sync-uri: rsync://rsync.ru.gentoo.org/gentoo-portage
    priority: -1000
    volatile: False
    sync-rsync-verify-max-age: 24
    sync-rsync-extra-opts:
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-jobs: 1

guru
    location: /var/db/repos/guru
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/guru.git
    masters: gentoo
    volatile: False

kelvium
    location: /home/kelvium/src/gentoo-overlay
    masters: gentoo
    volatile: True

musl
    location: /var/db/repos/musl
    sync-type: git
    sync-uri: https://github.com/gentoo-mirror/musl.git
    masters: gentoo
    volatile: False

polymc
    location: /var/db/repos/polymc
    sync-type: git
    sync-uri: https://git.swurl.xyz/PolyMC/overlay.git
    masters: gentoo
    volatile: True

ACCEPT_KEYWORDS="amd64 ~amd64"
ACCEPT_LICENSE="@FREE"
CBUILD="x86_64-gentoo-linux-musl"
CFLAGS="-march=haswell -O2 -pipe"
CHOST="x86_64-gentoo-linux-musl"
CONFIG_PROTECT="/etc /usr/share/gnupg/qualified.txt"
CONFIG_PROTECT_MASK="/etc/ca-certificates.conf /etc/dconf /etc/env.d /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/revdep-rebuild /etc/sandbox.d /etc/terminfo"
CXXFLAGS="-march=haswell -O2 -pipe"
DISTDIR="/var/cache/distfiles"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY GDK_PIXBUF_MODULE_FILE GOBIN GOPATH PERL5LIB PERL5OPT PERLPREFIX PERL_CORE PERL_MB_OPT PERL_MM_OPT XAUTHORITY XDG_CACHE_HOME XDG_CONFIG_HOME XDG_DATA_HOME XDG_RUNTIME_DIR XDG_STATE_HOME"
FCFLAGS="-march=haswell -O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg-live config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync network-sandbox news parallel-fetch preserve-libs protect-owned qa-unresolved-soname-deps sandbox selinux sesandbox sfperms strict unknown-features-warn unmerge-logs unmerge-orphans userfetch userpriv usersandbox usersync xattr"
FFLAGS="-march=haswell -O2 -pipe"
GENTOO_MIRRORS="https://mirror.yandex.ru/gentoo-distfiles/"
INSTALL_MASK="charset.alias /usr/share/locale/locale.alias"
LANG="C.UTF8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
LEX="flex"
MAKEOPTS="-j18"
PKGDIR="/var/cache/binpkgs"
PORTAGE_CONFIGROOT="/"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --omit-dir-times --compress --force --whole-file --delete --stats --human-readable --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --exclude=/.git"
PORTAGE_TMPDIR="/var/tmp"
RUSTFLAGS="-C target-cpu=haswell -C opt-level=2"
SHELL="/usr/local/bin/dinitsh"
USE="acl alsa amd64 audit bzip2 caps cet cli crypt dbus dri egl fortran hardened iconv ipv6 libglvnd libtirpc ncurses nls nptl opengl openmp pam pcre peer_perms pie pipewire readline screencast seatd seccomp selinux split-usr ssl ssp test-rust ubac udev unconfined unicode vulkan wayland xattr xtpax zeroconf zlib" ABI_X86="64" ADA_TARGET="gnat_2021" APACHE2_MODULES="authn_core authz_core socache_shmcb unixd actions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache cgi cgid dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file_cache filter headers include info log_config logio mem_cache mime mime_magic negotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alias" CALLIGRA_FEATURES="karbon sheets words" COLLECTD_PLUGINS="df interface irq load memory rrdtool swap syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt rdrand sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="musl" GPSD_PROTOCOLS="ashtech aivdm earthmate evermore fv18 garmin garmintxt gpsclock greis isync itrax mtk3301 nmea ntrip navcom oceanserver oldstyle oncore rtcm104v2 rtcm104v3 sirf skytraq superstar2 timing tsip tripmate tnt ublox ubx" INPUT_DEVICES="libinput" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIBREOFFICE_EXTENSIONS="presenter-console presenter-minimizer" LUA_SINGLE_TARGET="lua5-1" LUA_TARGETS="lua5-1" OFFICE_IMPLEMENTATION="libreoffice" PHP_TARGETS="php7-4 php8-0" POSTGRES_TARGETS="postgres12 postgres13" PYTHON_SINGLE_TARGET="python3_10" PYTHON_TARGETS="python3_10" QEMU_SOFTMMU_TARGETS="x86_64" RUBY_TARGETS="ruby30" USERLAND="GNU" VIDEO_CARDS="nouveau" XTABLES_ADDONS="quota2 psd pknock lscan length2 ipv4options ipset ipp2p iface geoip fuzzy condition tee tarpit sysrq proto steal rawnat logmark ipmark dhcpmac delude chaos account"
Unset:  ADDR2LINE, AR, ARFLAGS, AS, ASFLAGS, CC, CCLD, CONFIG_SHELL, CPP, CPPFLAGS, CTARGET, CXX, CXXFILT, ELFEDIT, EMERGE_DEFAULT_OPTS, EXTRA_ECONF, F77FLAGS, FC, GCOV, GPROF, LC_ALL, LD, LFLAGS, LIBTOOL, LINGUAS, MAKE, MAKEFLAGS, NM, OBJCOPY, OBJDUMP, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS, RANLIB, READELF, SIZE, STRINGS, STRIP, YACC, YFLAGS
Comment 1 Nikita Romaniuk 2023-04-29 17:31:50 UTC
Real-world examples that a user would expect to work:

PipeWire provides a group (`pipewire`) that changes some limits:
  @pipewire - rtprio  95
  @pipewire - nice    -19
  @pipewire - memlock 4194304
  *         - memlock 8192

sys-auth/realtime-base provides a group (`realtime`) that changes some limits:
  @realtime - rtprio  99
  @realtime - memlock unlimited
Comment 2 Nikita Romaniuk 2023-04-29 17:33:12 UTC
This is very similar to #662738.