Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 777717 - [SELinux and gcc] Compiling failed if not "eselect gcc set 1"
Summary: [SELinux and gcc] Compiling failed if not "eselect gcc set 1"
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: Hardened (show other bugs)
Hardware: AMD64 Linux
: Normal blocker (vote)
Assignee: SE Linux Bugs
URL:
Whiteboard: 2.20210908-r1
Keywords: PATCH, PullRequest
Depends on: 823203
Blocks:
  Show dependency tree
 
Reported: 2021-03-22 13:15 UTC by yesi
Modified: 2022-08-20 00:16 UTC (History)
1 user (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 yesi 2021-03-22 13:15:37 UTC
Hi,

I met some trouble to compile somes packages and after having a look from the logs, i noticed that the "gcc" is not unknown :

>>> Configuring source in /var/tmp/portage/sys-devel/llvm-11.1.0/work/llvm ...
 * abi_x86_64.amd64: running multilib-minimal_abi_src_configure
ccache: error: Could not find compiler "x86_64-pc-linux-gnu-g++" in PATH
ccache: error: Could not find compiler "x86_64-pc-linux-gnu-gcc" in PATH
 * Working in BUILD_DIR: "/var/tmp/portage/sys-devel/llvm-11.1.0/work/llvm-11.1.0_build-abi_x86_64.amd64"
cmake -C /var/tmp/portage/sys-devel/llvm-11.1.0/work/llvm-11.1.0_build-abi_x86_64.amd64/gentoo_common_config.cmake -G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DLLVM_APPEND_VC_REV=OFF -DCMAKE_INSTALL_PREFIX=/usr/lib/llvm/11 -DLLVM_LIBDIR_SUFFIX=6
4 -DBUILD_SHARED_LIBS=OFF -DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON -DLLVM_DISTRIBUTION_COMPONENTS=LLVM;LTO;Remarks;llvm-config;cmake-exports;llvm-headers;LLVMDemangle;LLVMSupport;LLVMTableGen;llvm-tblgen;FileCheck;llvm-PerfectS
huffle;count;not;yaml-bench;bugpoint;dsymutil;llc;lli;lli-child-target;llvm-addr2line;llvm-ar;llvm-as;llvm-bcanalyzer;llvm-c-test;llvm-cat;llvm-cfi-verify;llvm-config;llvm-cov;llvm-cvtres;llvm-cxxdump;llvm-cxxfilt;llvm-cxxmap;llvm-diff;llv
m-dis;llvm-dlltool;llvm-dwarfdump;llvm-dwp;llvm-elfabi;llvm-exegesis;llvm-extract;llvm-gsymutil;llvm-ifs;llvm-install-name-tool;llvm-jitlink;llvm-lib;llvm-link;llvm-lipo;llvm-lto;llvm-lto2;llvm-mc;llvm-mca;llvm-ml;llvm-modextract;llvm-mt;l
lvm-nm;llvm-objcopy;llvm-objdump;llvm-opt-report;llvm-pdbutil;llvm-profdata;llvm-ranlib;llvm-rc;llvm-readelf;llvm-readobj;llvm-reduce;llvm-rtdyld;llvm-size;llvm-split;llvm-stress;llvm-strings;llvm-strip;llvm-symbolizer;llvm-undname;llvm-xr
ay;obj2yaml;opt;sancov;sanstats;verify-uselistorder;yaml2obj;opt-viewer; -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=X86;NVPTX;BPF;AMDGPU -DLLVM_BUILD_TESTS=no -DLLVM_ENABLE_FFI=yes -DLLVM_ENABLE_LIBEDIT=no -DLLVM_ENABLE_
TERMINFO=yes -DLLVM_ENABLE_LIBXML2=yes -DLLVM_ENABLE_ASSERTIONS=no -DLLVM_ENABLE_LIBPFM=no -DLLVM_ENABLE_EH=ON -DLLVM_ENABLE_RTTI=ON -DLLVM_ENABLE_Z3_SOLVER=no -DLLVM_HOST_TRIPLE=x86_64-pc-linux-gnu -DFFI_INCLUDE_DIR=/usr/lib64/libffi/incl
ude -DFFI_LIBRARY_DIR= -DHAVE_LIBXAR=0 -DPython3_EXECUTABLE=/usr/bin/python3.9 -DOCAMLFIND=NO -DGO_EXECUTABLE=GO_EXECUTABLE-NOTFOUND -DLLVM_BUILD_DOCS=OFF -DLLVM_ENABLE_OCAMLDOC=OFF -DLLVM_ENABLE_SPHINX=OFF -DLLVM_ENABLE_DOXYGEN=OFF -DLLVM
_INSTALL_UTILS=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_TOOLCHAIN_FILE=/var/tmp/portage/sys-devel/llvm-11.1.0/work/llvm-11.1.0_build-abi_x86_64.amd64/gentoo_toolchain.cmake  /var/tmp/portage/sys-devel/llvm-11.1.0/work/llvm
loading initial cache file /var/tmp/portage/sys-devel/llvm-11.1.0/work/llvm-11.1.0_build-abi_x86_64.amd64/gentoo_common_config.cmake
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- The ASM compiler identification is unknown
-- Found assembler: /usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: /usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc
-- Check for working C compiler: /usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc - broken
CMake Error at /usr/share/cmake/Modules/CMakeTestCCompiler.cmake:66 (message):
  The C compiler

    "/usr/lib/ccache/bin/x86_64-pc-linux-gnu-gcc"


Then, i tried to choose again the gcc in the list :

> eselect gcc list
 [1] x86_64-pc-linux-gnu-10.2.0 *
But it met some trouble to link e.g. :

> mv: cannot move '/usr/bin/.gcc.config.x86_64-pc-linux-gnu-c++' to '/usr/bin/x86_64-pc-linux-gnu-c++': Permission denied
> mv: cannot move '/usr/bin/.gcc.config.x86_64-pc-linux-gnu-cpp' to '/usr/bin/x86_64-pc-linux-gnu-cpp': Permission denied
> mv: cannot move '/usr/bin/.gcc.config.x86_64-pc-linux-gnu-g++' to '/usr/bin/x86_64-pc-linux-gnu-g++': Permission denied
> mv: cannot move '/usr/bin/.gcc.config.x86_64-pc-linux-gnu-gcc' to '/usr/bin/x86_64-pc-linux-gnu-gcc': Permission denied


It is the first time that i meet this error.
To resolved this, i allowed from my SELinux module :

# impossible to do "eselect gcc set"
#============= gcc_config_t ==============
allow gcc_config_t bin_t:lnk_file create;
allow gcc_config_t lib_t:lnk_file create;
allow gcc_config_t self:capability dac_read_search;
allow gcc_config_t self:process getsched;
allow gcc_config_t tmpfs_t:filesystem getattr;
allow gcc_config_t bin_t:lnk_file { rename unlink };
allow gcc_config_t lib_t:lnk_file { rename unlink };

I re-emerge again and it is successfull.

--
> emerge --info

Portage 3.0.17 (python 3.8.8-final-0, default/linux/amd64/17.1/hardened/selinux, gcc-10.2.0, glibc-2.32-r7, 5.11.6-gentoo x86_64)
=================================================================
System uname: Linux-5.11.6-gentoo-x86_64-Intel-R-_Core-TM-_i7-5557U_CPU_@_3.10GHz-with-glibc2.2.5
KiB Mem:    16266576 total,    436984 free
KiB Swap:    8388604 total,   8387308 free
Timestamp of repository gentoo: Mon, 22 Mar 2021 00:45:01 +0000
Head commit of repository gentoo: ecdb8802af3a726b11669d0657d05bc7e60e7a0c
sh bash 5.0_p18
ld GNU ld (Gentoo 2.35.1 p2) 2.35.1
ccache version 4.1 [enabled]
app-shells/bash:          5.0_p18::gentoo
dev-java/java-config:     2.3.1::gentoo
dev-lang/perl:            5.30.3::gentoo
dev-lang/python:          2.7.18_p7::gentoo, 3.6.13::gentoo, 3.8.8::gentoo, 3.9.2::gentoo
dev-util/ccache:          4.1::gentoo
dev-util/cmake:           3.18.5::gentoo
dev-util/pkgconfig:       0.29.2::gentoo
sys-apps/baselayout:      2.7::gentoo
sys-apps/openrc:          0.42.1-r1::gentoo
sys-apps/sandbox:         2.20::gentoo
sys-devel/autoconf:       2.13-r1::gentoo, 2.69-r5::gentoo
sys-devel/automake:       1.16.2-r1::gentoo
sys-devel/binutils:       2.35.1-r1::gentoo
sys-devel/gcc:            10.2.0-r5::gentoo
sys-devel/gcc-config:     2.3.3::gentoo
sys-devel/libtool:        2.4.6-r6::gentoo
sys-devel/make:           4.3::gentoo
sys-kernel/linux-headers: 5.10::gentoo (virtual/os-headers)
sys-libs/glibc:           2.32-r7::gentoo
Repositories:

gentoo
    location: /usr/portage
    sync-type: rsync
    sync-uri: rsync://rsync.gentoo.org/gentoo-portage
    priority: -1000
    sync-rsync-verify-metamanifest: yes
    sync-rsync-verify-max-age: 24
    sync-rsync-verify-jobs: 1
    sync-rsync-extra-opts:

local
    location: /usr/local/portage
    masters: gentoo
    priority: 10
ACCEPT_KEYWORDS="amd64"
ACCEPT_LICENSE="@FREE"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=haswell -O2 -fforce-addr -pipe"
CHOST="x86_64-pc-linux-gnu"
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 -fforce-addr -pipe"
DISTDIR="/usr/portage/distfiles"
EMERGE_DEFAULT_OPTS="--jobs=4 --load-average=4.0 --keep-going=y --with-bdeps=y --complete-graph"
ENV_UNSET="CARGO_HOME DBUS_SESSION_BUS_ADDRESS DISPLAY 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"
FCFLAGS="-O2 -pipe"
FEATURES="assume-digests binpkg-docompress binpkg-dostrip binpkg-logs binpkg-multi-instance buildpkg ccache config-protect-if-modified distlocks ebuild-locks fixlafiles ipc-sandbox merge-sync multilib-strict network-sandbox news parallel-fetch parallel-install 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="-O2 -pipe"
GENTOO_MIRRORS="http://local"
LANG="fr_FR.utf8"
LDFLAGS="-Wl,-O1 -Wl,--as-needed"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
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"
USE="X acl amd64 branding bzip2 chroot crypt cryptsetup elogind ffmpeg gnutls hardened iconv icu ipv6 jpeg libglvnd libtirpc logrotate lzma mmx modplug multilib ncurses nls nptl opengl openmp pam pax_kernel pcre perl pic pie png python readline seccomp secure_delete selinux snmp split-usr sse sse2 ssl ssp symlink tcpd unicode wavpack webrsync-gpg xattr xml xtpax zlib" ABI_X86="64" ADA_TARGET="gnat_2018" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" 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="load memory syslog" CPU_FLAGS_X86="aes avx avx2 f16c fma3 mmx mmxext pclmul popcnt sse sse2 sse3 sse4_1 sse4_2 ssse3" ELIBC="glibc" 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" GRUB_PLATFORMS="efi-64" 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-3 php7-4" POSTGRES_TARGETS="postgres10 postgres11" PYTHON_SINGLE_TARGET="python3_8" PYTHON_TARGETS="python3_8" QEMU_SOFTMMU_TARGETS="arm x86_64 sparc" QEMU_USER_TARGETS="x86_64" RUBY_TARGETS="ruby26" USERLAND="GNU" VIDEO_CARDS="intel i915 fbdev vesa" 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:  CC, CPPFLAGS, CTARGET, CXX, INSTALL_MASK, LC_ALL, LINGUAS, PORTAGE_BINHOST, PORTAGE_BUNZIP2_COMMAND, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Jonathan Davies 2021-06-22 16:30:24 UTC
I fixed this in https://github.com/perfinion/hardened-refpolicy/pull/20
Comment 2 yesi 2021-07-08 13:06:54 UTC
Hi,

Thank you for your work.

To reproduce this :

I removed my previous rules : 

# impossible to do "eselect gcc set"
#============= gcc_config_t ==============
allow gcc_config_t bin_t:lnk_file create;
allow gcc_config_t lib_t:lnk_file create;
allow gcc_config_t self:capability dac_read_search;
allow gcc_config_t self:process getsched;
allow gcc_config_t tmpfs_t:filesystem getattr;
allow gcc_config_t bin_t:lnk_file { rename unlink };
allow gcc_config_t lib_t:lnk_file { rename unlink };

And i gave a try to compile again sys-process/htop and sys-devel/llvm.
There is no errors.
:-)


But i noticed this behaviour :

> eselect gcc list
 [1] x86_64-pc-linux-gnu-10.3.0 *

> eselect gcc set 1
 * gcc-config: need write access to /

Hmm...
What do you think about this ?

> mount
/dev/mapper/gnu-rootfs on / type btrfs (rw,noatime,seclabel,compress=lzo,ssd,discard,space_cache,autodefrag,subvolid=257,subvol=/@)




Peace.
Comment 3 yesi 2021-07-08 13:13:58 UTC
My apologies :

> eselect gcc set 1
 * gcc-config: need write access to /

With or without my rules, i get the same message when i am in Enforcing mode.
Comment 4 yesi 2021-07-08 13:21:27 UTC
I'd like to have your return before closing this bug.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2021-11-21 04:36:05 UTC
We fixed the ${EROOT} writability check in bug 823203 but looks like we still need to fix the symlink part?
Comment 6 Jason Zaman gentoo-dev 2021-11-22 01:26:18 UTC
The policy parts of this were added in 2.20210908-r1
Comment 7 yesi 2022-01-17 15:04:30 UTC
> emerge -av @selinux-rebuild

> rlpkg acct aide apm arpwatch avahi base base-policy cgmanager consolekit cups dante dbus devicekit dirmngr dmidecode dracut fail2ban gnome gpg gpm java kerberos ldap logrotate ldp mandb mozilla ntp openrc policykit pulseaudio rpc rpcbind samba sasl screen shutdown snmp snort sudo sysstat unconfined vmware wireshark xserver

> eselect gcc list
[1] x86_64-pc-linux-gnu-11.2.0 *

> eselect gcc set 1
 * Switching native-compiler to x86_64-pc-linux-gnu-11.2.0 ...

There is no error.

:-)

Thanks.