From patchwork Tue Jul 18 22:25:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9849957 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DA22602BD for ; Tue, 18 Jul 2017 22:27:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 17BF328433 for ; Tue, 18 Jul 2017 22:27:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C6BC285B7; Tue, 18 Jul 2017 22:27:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7025C28433 for ; Tue, 18 Jul 2017 22:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752365AbdGRW1A (ORCPT ); Tue, 18 Jul 2017 18:27:00 -0400 Received: from mail-pf0-f176.google.com ([209.85.192.176]:33145 "EHLO mail-pf0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752682AbdGRWZz (ORCPT ); Tue, 18 Jul 2017 18:25:55 -0400 Received: by mail-pf0-f176.google.com with SMTP id s70so8661689pfs.0 for ; Tue, 18 Jul 2017 15:25:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=flsGEQ1Zr5EWIYLJE1KJPcpLCXDm5ll6AMaSUNhY1zY=; b=YeDVWy2tk74l9r85elfDeMkpC5AQVyEXRnor2THPiKp7xw+FRA3fxYxp+N0XYp7/QT oRf5JGa4f/7c91TeSl1Dz6APDQHB0I8c27LWKQ6dsoTSyv9Fu1DYl+BWpKEW1DyDj7kQ ScISm+qmAMmkA7YFE/tgfe4V53m/JrqIkIpU0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=flsGEQ1Zr5EWIYLJE1KJPcpLCXDm5ll6AMaSUNhY1zY=; b=kfi35TYfSKdAk1Xcz3V0tLnF3hRqa2YIr9d8/9y+0438mRhfmtVuU9EcK0m+qQLVdP a389EfUjNZhyZNIWl7gx0oED4J5ehWPXL4MTICNFSeQi1j/15Dx6c38EL094eEuSMBzk b4m0tLs3LCr+wwqz86QAq9SkiFXfIEftn9OvDvqpzSNEGABMQ+jF3yF3bE3ltAiiwyBq m2y5lROh1+6DyIMzqkp4Ua+AneLTXOpz/xLlPmTp/IxIRpeq2n3mYT4FaoBAVZqYdRmy 70Hnpqai859LJI9BLebFIwqBvAr4wHjUd8D2BS4Zq/lr/0zvbn94nxdPaVPHHOka/KBX igDg== X-Gm-Message-State: AIVw1101aevtV2kpp0+RWAao4ijw3qtASaegBMjNp8OnEw+/f1iAoetk uRyREjdNkjqV03pi X-Received: by 10.99.123.6 with SMTP id w6mr3855608pgc.71.1500416754511; Tue, 18 Jul 2017 15:25:54 -0700 (PDT) Received: from www.outflux.net (173-164-112-133-Oregon.hfc.comcastbusiness.net. [173.164.112.133]) by smtp.gmail.com with ESMTPSA id g73sm7404150pfk.19.2017.07.18.15.25.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 15:25:52 -0700 (PDT) From: Kees Cook To: Andrew Morton Cc: Kees Cook , Linus Torvalds , David Howells , "Eric W. Biederman" , John Johansen , "Serge E. Hallyn" , Paul Moore , Stephen Smalley , Casey Schaufler , Tetsuo Handa , James Morris , Andy Lutomirski , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 14/15] exec: Use sane stack rlimit under secureexec Date: Tue, 18 Jul 2017 15:25:35 -0700 Message-Id: <1500416736-49829-15-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500416736-49829-1-git-send-email-keescook@chromium.org> References: <1500416736-49829-1-git-send-email-keescook@chromium.org> Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP For a secureexec, before memory layout selection has happened, reset the stack rlimit to something sane to avoid the caller having control over the resulting layouts. $ ulimit -s 8192 $ ulimit -s unlimited $ /bin/sh -c 'ulimit -s' unlimited $ sudo /bin/sh -c 'ulimit -s' 8192 Cc: Linus Torvalds Signed-off-by: Kees Cook Reviewed-by: James Morris --- fs/exec.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 45418d6ec583..4227c1e56566 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1349,6 +1349,18 @@ void setup_new_exec(struct linux_binprm * bprm) */ bprm->secureexec |= bprm->cap_elevated; + if (bprm->secureexec) { + /* + * For secureexec, reset the stack limit to sane default to + * avoid bad behavior from the prior rlimits. This has to + * happen before arch_pick_mmap_layout(), which examines + * RLIMIT_STACK, but after the point of no return to avoid + * needing to clean up the change on failure. + */ + if (current->signal->rlim[RLIMIT_STACK].rlim_cur > _STK_LIM) + current->signal->rlim[RLIMIT_STACK].rlim_cur = _STK_LIM; + } + arch_pick_mmap_layout(current->mm); current->sas_ss_sp = current->sas_ss_size = 0;