Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752295AbdLLTXu (ORCPT ); Tue, 12 Dec 2017 14:23:50 -0500 Received: from mail-ua0-f178.google.com ([209.85.217.178]:41557 "EHLO mail-ua0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751554AbdLLTXt (ORCPT ); Tue, 12 Dec 2017 14:23:49 -0500 X-Google-Smtp-Source: ACJfBouAE0G0uZ6RKbosNp2GZcklbDtr/bD38vQHkYgcoR39z1NFjLZwuBr+uVVXTG9n/+eBRPA6DyCOR3MzUKFMYJg= MIME-Version: 1.0 In-Reply-To: <4229475.4Lp8rLWMsd@electra> References: <4229475.4Lp8rLWMsd@electra> From: Kees Cook Date: Tue, 12 Dec 2017 11:23:47 -0800 X-Google-Sender-Auth: NktfRgVdvUtpeP0K5pAAnI9MerE Message-ID: Subject: Re: System-wide hard RLIMIT_STACK in 4.14.4+ w/ SELinux To: =?UTF-8?B?VG9tw6HFoSBUcm5rYQ==?= Cc: LKML , Stephen Smalley , Paul Moore , Linus Torvalds , Laura Abbott Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by nfs id vBCJNsMk004670 Content-Length: 2045 Lines: 56 On Tue, Dec 12, 2017 at 2:58 AM, Tomáš Trnka wrote: > Hello, > > Commit 04e35f4495dd560db30c25efca4eecae8ec8c375 "exec: avoid RLIMIT_STACK > races with prlimit()" that made it into 4.14.4 effectively changes the default > hard RLIMIT_STACK on machines with SELinux (seen on Fedora 27). > > selinux_bprm_set_creds() sets bprm->secureexec for any SELinux domain > transition that does not have the "noatsecure" permission. The secureexec > logic thus kicks in for virtually every process launched by PID 1 systemd > (init_t), including gettys, display managers, etc. Uuugh. Okay, we need to revert that commit. I'll send a patch for 4.15 (with a fix for -stable too). I will design an alternative, which was considered much earlier: keeping a copy of the rlimits in the bprm during exec so it can't change out from under the execing process. This will avoid needing to set the hard limit, avoid the locking race that commit was trying to fix, etc. This is an interesting state for the system to be in, though, it means AT_SECURE is being set for virtually all processes too? I would expect that might break a lot too (but clearly it hasn't). > > I can see that 8 MiB "should be enough for everyone" using normal software, > but sadly the HPC stuff around here tends to need a little more (due to a > deficiency in gfortran). > > Minimal example (the actual types are not too important): > > # /bin/ulimit -Hs > unlimited > # runcon -r system_r -t sysadm_t runcon -t rpm_script_t /bin/ulimit -Hs > 8192 > > Of course this can be somewhat worked around by adjusting the SELinux policy > (allowing blanket noatsecure permission for init_t and possibly others) or by > pam_limits (for components using PAM). Unfortunately, systemd's LimitSTACK= is > also broken (calls setrlimit before exec). Anyway, I wasn't expecting any of > that in connection with the 4.14.3->.4 upgrade. > > -- > Best regards, > > Tomáš Trnka > Software for Chemistry & Materials Thanks for the report and examples! -Kees -- Kees Cook Pixel Security