tech:compilation-kernel-grsecurity
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Prochaine révision | Révision précédente | ||
| tech:compilation-kernel-grsecurity [2025/03/24 15:06] – créée - modification externe 127.0.0.1 | tech:compilation-kernel-grsecurity [2026/07/16 15:22] (Version actuelle) – Jean-Baptiste | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | < | ||
| + | {{tag> | ||
| + | |||
| + | # Compilation Noyau patch Grsecurity PAX Linux sous Debian | ||
| + | |||
| + | |||
| + | Voir aussi : | ||
| + | * [[todo-debian-noyau-linux]] | ||
| + | * http:// | ||
| + | |||
| + | Comment compiler un noyau Linux < | ||
| + | |||
| + | |||
| + | ## Compile Noyau Linux, patch avec Grsecurity sous Debian | ||
| + | |||
| + | Vérif user_xattr ? | ||
| + | | ||
| + | ~~~bash | ||
| + | apt-get update | ||
| + | apt-get install kernel-package | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | $ gcc -v | ||
| + | Using built-in specs. | ||
| + | COLLECT_GCC=gcc | ||
| + | COLLECT_LTO_WRAPPER=/ | ||
| + | Target: x86_64-linux-gnu | ||
| + | Configured with: ../ | ||
| + | Thread model: posix | ||
| + | gcc version 4.9.1 (Debian 4.9.1-19) | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | apt-get install gcc-4.9-plugin-dev | ||
| + | apt-get install attr | ||
| + | ~~~ | ||
| + | |||
| + | Téléchargement du patch **grsecurity** | ||
| + | |||
| + | ~~~bash | ||
| + | wget https:// | ||
| + | wget https:// | ||
| + | gpg --verify grsecurity-3.0-3.2.64-201411062032.patch.sig grsecurity-3.0-3.2.64-201411062032.patch | ||
| + | ~~~ | ||
| + | |||
| + | Téléchargement des sources du noyau Linux | ||
| + | ~~~bash | ||
| + | wget https:// | ||
| + | wget https:// | ||
| + | 7z x linux-3.2.64.tar.xz | ||
| + | gpg --verify linux-3.2.64.tar.sign linux-3.2.64.tar | ||
| + | ~~~ | ||
| + | |||
| + | On va " | ||
| + | On test avant | ||
| + | |||
| + | ~~~bash | ||
| + | patch --dry-run -p1 < ../ | ||
| + | ~~~ | ||
| + | |||
| + | Allons-y | ||
| + | |||
| + | ~~~bash | ||
| + | patch -p1 < ../ | ||
| + | ~~~ | ||
| + | |||
| + | C'est fait. Compilons.... | ||
| + | Re | ||
| + | |||
| + | ~~~bash | ||
| + | ls -lrt / | ||
| + | cp / | ||
| + | make oldconfig | ||
| + | make menuconfig | ||
| + | ~~~ | ||
| + | |||
| + | ou | ||
| + | |||
| + | ~~~bash | ||
| + | make defconfig | ||
| + | ~~~ | ||
| + | |||
| + | Si vous avez un quadcore pas chargé | ||
| + | |||
| + | ~~~ | ||
| + | $ #getconf _NPROCESSORS_ONLN | ||
| + | $ nproc | ||
| + | 4 | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | export CONCURRENCY_LEVEL=4 | ||
| + | ~~~ | ||
| + | |||
| + | C'est l’équivalent du `make -j 4` ou de `export MAKEFLAGS=" | ||
| + | `unset MAKEFLAGS` si besion. | ||
| + | |||
| + | Voir http:// | ||
| + | |||
| + | Ou plus simple | ||
| + | |||
| + | ~~~bash | ||
| + | export CONCURRENCY_LEVEL=$(nproc) | ||
| + | ~~~ | ||
| + | |||
| + | Pour compiler le noyau Linux sous Debian | ||
| + | |||
| + | Ca y ai, on compile | ||
| + | |||
| + | ~~~bash | ||
| + | fakeroot make-kpkg --initrd --append-to-version=" | ||
| + | ~~~ | ||
| + | |||
| + | On va avoir besoin de changer des droits PAX (inclus avec Grsecurity) | ||
| + | Install du pachet attr qui inclue l' | ||
| + | |||
| + | |||
| + | ~~~bash | ||
| + | apt-get install attr | ||
| + | ~~~ | ||
| + | |||
| + | ## | ||
| + | Téléchargement du script fourni avec le projet Mempo | ||
| + | ~~~bash | ||
| + | wget https:// | ||
| + | chmod +x fs_attr_grsecurity_standard_debian.sh | ||
| + | sudo ./ | ||
| + | ~~~ | ||
| + | |||
| + | Personnellement, | ||
| + | |||
| + | ~~~bash | ||
| + | setfattr -n user.pax.flags -v " | ||
| + | setfattr -n user.pax.flags -v " | ||
| + | setfattr -n user.pax.flags -v " | ||
| + | setfattr -n user.pax.flags -v " | ||
| + | setfattr -n user.pax.flags -v " | ||
| + | setfattr -n user.pax.flags -v " | ||
| + | ~~~ | ||
| + | |||
| + | Ou avec paxctl | ||
| + | |||
| + | |||
| + | ### Configuration PAX paxctld.conf | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | #### | ||
| + | |||
| + | ~~~bash | ||
| + | gpg --verify paxctld_1.0-2_amd64.deb.sig paxctld_1.0-2_amd64.deb | ||
| + | ~~~ | ||
| + | |||
| + | ~~~ | ||
| + | gpg: Signature faite le jeu. 01 janv. 2015 18:09:39 CET | ||
| + | gpg: avec la clef RSA 0x44D1C0F82525FE49 | ||
| + | gpg: Bonne signature de « Bradley Spengler (spender) < | ||
| + | gpg: Attention : | ||
| + | gpg: Rien n' | ||
| + | Empreinte de clef principale : | ||
| + | ~~~ | ||
| + | |||
| + | ~~~bash | ||
| + | dpkg -i paxctld_1.0-2_amd64.deb | ||
| + | ~~~ | ||
| + | |||
| + | Plus rien à faire. La conf se trouve dans */ | ||
| + | Dans mon cas, la conf par défaut suffit. | ||
| + | |||
| + | **Il est important de vérifier (et de superviser) que le service paxctld soit bien démarré, et activé pour démarrer automatiquement.** | ||
| + | |||
| + | **En cas de mise à jour faut-il systématiquement redémarrer le service paxctld !?** | ||
| + | |||
| + | |||
| + | ## sysctl | ||
| + | |||
| + | Pour voir les propriétés modifiable à chaud | ||
| + | ~~~bash | ||
| + | sysctl -a | egrep " | ||
| + | ~~~ | ||
| + | |||
| + | Exemple de fichier de conf (ordi de bureau) | ||
| + | |||
| + | `/ | ||
| + | ~~~ini | ||
| + | kernel.grsecurity.linking_restrictions = 1 | ||
| + | kernel.grsecurity.enforce_symlinksifowner = 1 | ||
| + | kernel.grsecurity.deter_bruteforce = 1 | ||
| + | kernel.grsecurity.fifo_restrictions = 1 | ||
| + | kernel.grsecurity.ptrace_readexec = 1 | ||
| + | kernel.grsecurity.consistent_setxid = 1 | ||
| + | |||
| + | kernel.grsecurity.ip_blackhole = 1 | ||
| + | kernel.grsecurity.lastack_retries = 4 | ||
| + | |||
| + | kernel.grsecurity.chroot_deny_shmat = 1 | ||
| + | kernel.grsecurity.chroot_deny_unix = 1 | ||
| + | kernel.grsecurity.chroot_deny_mount = 1 | ||
| + | kernel.grsecurity.chroot_deny_fchdir = 1 | ||
| + | kernel.grsecurity.chroot_deny_chroot = 1 | ||
| + | kernel.grsecurity.chroot_deny_pivot = 1 | ||
| + | kernel.grsecurity.chroot_enforce_chdir = 1 | ||
| + | kernel.grsecurity.chroot_deny_chmod = 1 | ||
| + | kernel.grsecurity.chroot_deny_mknod = 1 | ||
| + | kernel.grsecurity.chroot_restrict_nice = 1 | ||
| + | kernel.grsecurity.chroot_caps = 1 | ||
| + | kernel.grsecurity.chroot_deny_sysctl = 1 | ||
| + | kernel.grsecurity.chroot_findtask = 1 | ||
| + | |||
| + | # TPE : Trusted Path Execution. | ||
| + | kernel.grsecurity.tpe = 1 | ||
| + | # Drastique. Plus d exec dans le home | ||
| + | kernel.grsecurity.tpe_restrict_all = 1 | ||
| + | |||
| + | # | ||
| + | # | ||
| + | # | ||
| + | kernel.grsecurity.harden_ptrace = 1 | ||
| + | |||
| + | # For mplayer2 with x11 drivers (full screen) | ||
| + | # else " | ||
| + | kernel.grsecurity.harden_ipc = 0 | ||
| + | |||
| + | # Drastique. Rebbot necessaire pour revenir en arriere | ||
| + | # Empeche ecryptfs de fonctionner | ||
| + | # | ||
| + | |||
| + | ## Desactiv | ||
| + | kernel.grsecurity.dmesg = 0 | ||
| + | kernel.grsecurity.deny_new_usb = 0 | ||
| + | |||
| + | ## Groupes | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | kernel.grsecurity.tpe_gid = 1005 | ||
| + | # | ||
| + | |||
| + | ## Audit | ||
| + | # | ||
| + | |||
| + | # Si activé vraiment bavard | ||
| + | kernel.grsecurity.audit_chdir = 0 | ||
| + | |||
| + | kernel.grsecurity.audit_mount = 1 | ||
| + | kernel.grsecurity.audit_ptrace = 1 | ||
| + | |||
| + | |||
| + | ## Logging | ||
| + | # | ||
| + | # | ||
| + | kernel.grsecurity.signal_logging = 1 | ||
| + | kernel.grsecurity.forkfail_logging = 1 | ||
| + | kernel.grsecurity.timechange_logging = 1 | ||
| + | # | ||
| + | # | ||
| + | |||
| + | # Test | ||
| + | kernel.grsecurity.disable_priv_io = 1 | ||
| + | |||
| + | ## Dernier parametre | ||
| + | # Drastique. Interdit toutes modifications de ces parametres. Reboot necessaire pour rechanger | ||
| + | # | ||
| + | ~~~ | ||
| + | |||
| + | Cette conf sera appliquée au démarrage du PC ou bien : | ||
| + | |||
| + | ~~~bash | ||
| + | sysctl -p / | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Exemple de changement de conf à chaud | ||
| + | La pluspart des problèmes sont résolut en abaissant la sécurité de la façon suivantes : | ||
| + | ~~~bash | ||
| + | sysctl -w kernel.pax.softmode=1 | ||
| + | sysctl -w kernel.grsecurity.tpe=0 | ||
| + | ~~~ | ||
| + | |||
| + | Plus de son ? | ||
| + | Pour un ordi de bureau : | ||
| + | CONFIG_GRKERNSEC_SYSFS_RESTRICT=n | ||
| + | |||
| + | http:// | ||
| + | |||
| + | Liens : | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | * http:// | ||
| + | * https:// | ||
| + | |||
| + | |||
| + | |||
| + | ## Pb | ||
| + | |||
| + | ### Pb Apache prefork fork bruteforce | ||
| + | |||
| + | Voir : | ||
| + | https:// | ||
| + | |||
| + | Symptôme : 30 seconde pour avoir la réponse HTTP d'un fichier statique : | ||
| + | ~~~bash | ||
| + | time curl http:// | ||
| + | ~~~ | ||
| + | |||
| + | |||
| + | Logs | ||
| + | `dmesg` ou `/ | ||
| + | |||
| + | ~~~ | ||
| + | # dmesg | ||
| + | bruteforce prevention initiated for the next 30 minutes or until service restarted, stalling each fork 30 seconds. | ||
| + | | ||
| + | ~~~ | ||
| + | |||
| + | `/ | ||
| + | ~~~ | ||
| + | [Thu Jan 17 11: | ||
| + | [Thu Jan 17 12: | ||
| + | [Thu Jan 17 12: | ||
| + | [Thu Jan 17 13: | ||
| + | [Thu Jan 17 14: | ||
| + | [Thu Jan 17 14: | ||
| + | [Thu Jan 17 14: | ||
| + | [Thu Jan 17 14: | ||
| + | [Thu Jan 17 14: | ||
| + | [Thu Jan 17 14: | ||
| + | [Thu Jan 17 14: | ||
| + | [crit] Memory allocation failed, aborting process. | ||
| + | ~~~ | ||
| + | |||
| + | Apache forkant souvent et rapidement grsec prend cela pour une tentative de bruteforce | ||
| + | |||
| + | Cela est dû à GRSecurity, à plus précisément à l' | ||
| + | `CONFIG_GRKERNSEC_BRUTE=y` | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | Solution possible : | ||
| + | * Passer Apache en mode worker ou lieu de prefork | ||
| + | * Désactiver grsec | ||
| + | * Modifier la conf Apache pour qu'il fork moins | ||
| + | * Maintenance palliative : chien de garde (A tester) | ||
| + | |||
| + | `/ | ||
| + | ~~~apache | ||
| + | < | ||
| + | # | ||
| + | StartServers | ||
| + | # | ||
| + | MinSpareServers | ||
| + | # | ||
| + | MaxSpareServers | ||
| + | MaxClients | ||
| + | MaxRequestsPerChild | ||
| + | </ | ||
| + | ~~~ | ||
| + | |||
| + | Tentative de chien de garde via crontab chaque minute | ||
| + | |||
| + | `/ | ||
| + | ~~~bash | ||
| + | #! /bin/bash | ||
| + | |||
| + | curl --resolve www.acme.fr: | ||
| + | |||
| + | if [[ $? == 28 ]] | ||
| + | then | ||
| + | date >> / | ||
| + | / | ||
| + | fi | ||
| + | ~~~ | ||
