From patchwork Tue Aug 1 19:16:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 9875271 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 7171760365 for ; Tue, 1 Aug 2017 19:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 633AF2871F for ; Tue, 1 Aug 2017 19:17:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5826828722; Tue, 1 Aug 2017 19:17:04 +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 D942A2871F for ; Tue, 1 Aug 2017 19:17:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752121AbdHATRC (ORCPT ); Tue, 1 Aug 2017 15:17:02 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:34186 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752340AbdHATQw (ORCPT ); Tue, 1 Aug 2017 15:16:52 -0400 Received: by mail-pf0-f175.google.com with SMTP id o86so8090500pfj.1 for ; Tue, 01 Aug 2017 12:16:52 -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=ZWiMdencHk3jeLOBVNOnF4u7imNUj0DWHhG5Lp6MXpg=; b=lhyQmWx3MJYIW27TL9p+TLPNa7xK+QW/fs0qOn5IkXz3p7H5WE74JKo1hY7QJLG93o WNBdPLKVXpXhFFndABVrlphV4LIKBOiGo+AWNq/OQOPjx3Tw79VaU/aqJkOjitXzXsIg x5VIUPnxl3ZqhIDF2eDjb/skFdv+wT3rX4lns= 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=ZWiMdencHk3jeLOBVNOnF4u7imNUj0DWHhG5Lp6MXpg=; b=BHk7VUoHhIekAKZ8mWs+dIHir2I+SMl0eofevNYmsD941N44yfY8nZcQNwvpQqRJlm ztZKs4QnRRELE6tb1qRlL0shQz41/95Xc7E0YRxxBj38y6tdNzzPlBNfQJHgZjQGTKn/ OY+VqAaIwo660aq3d9Mxb2sYl52Ufr9J99080vMlu6askJ9Mg96hygQ/xaHYTyqjRUXV Lu0b+DsZFHDgGM5ZQUiCKdfh2sYuDO15epmdqAnQUv7lksRwadsX9gqDCrGG2RHxPVFV 1fjVMPOwQt2/3y6QBxeC1TTfA73pDH2BCjEp46CDtCNB+Fbq7Afx61fgNEFFsaMzGNLk qWwg== X-Gm-Message-State: AIVw112GbeP54E6vx3rbyioFXHMGdvHs5vKLszaxAPOcVOH1UnIM/GTi kFNu4TXY4zXE+5w/ X-Received: by 10.98.81.194 with SMTP id f185mr19733043pfb.96.1501615012022; Tue, 01 Aug 2017 12:16:52 -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 j9sm11017159pfk.30.2017.08.01.12.16.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 01 Aug 2017 12:16:49 -0700 (PDT) From: Kees Cook To: linux-kernel@vger.kernel.org Cc: Kees Cook , Linus Torvalds , Andrew Morton , James Morris , "Serge E. Hallyn" , Andy Lutomirski , "Eric W. Biederman" , John Johansen , Paul Moore , Casey Schaufler , Stephen Smalley , Tetsuo Handa , David Howells , linux-fsdevel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: [PATCH v5 14/15] exec: Use sane stack rlimit under secureexec Date: Tue, 1 Aug 2017 12:16:37 -0700 Message-Id: <1501614998-62619-15-git-send-email-keescook@chromium.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501614998-62619-1-git-send-email-keescook@chromium.org> References: <1501614998-62619-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 Acked-by: Serge Hallyn --- fs/exec.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 3006c1c24304..3235cbd85efa 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1350,6 +1350,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;