From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754041AbeAJTfx (ORCPT + 1 other); Wed, 10 Jan 2018 14:35:53 -0500 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:39506 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753646AbeAJTfv (ORCPT ); Wed, 10 Jan 2018 14:35:51 -0500 From: Willy Tarreau To: linux-kernel@vger.kernel.org, x86@kernel.org Cc: Willy Tarreau , Andy Lutomirski , Borislav Petkov , Brian Gerst , Dave Hansen , Ingo Molnar , Linus Torvalds , Peter Zijlstra , Thomas Gleixner , Josh Poimboeuf , "H. Peter Anvin" , Kees Cook , Alexander Viro Subject: [RFC PATCH v3 5/8] exec: take care of disabling PTI upon execve() Date: Wed, 10 Jan 2018 20:28:17 +0100 Message-Id: <1515612500-14505-6-git-send-email-w@1wt.eu> X-Mailer: git-send-email 2.8.0.rc2.1.gbe9624a In-Reply-To: <1515612500-14505-1-git-send-email-w@1wt.eu> References: <1515612500-14505-1-git-send-email-w@1wt.eu> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Return-Path: Here's what we do here : - TIF_DISABLE_PTI_NOW is always cleared as we don't want an unprotected process to pass its lack of protection to any possible other program it could exec. - TIF_DISABLE_PTI_NEXT is copied into TIF_DISABLE_PTI_NOW and cleared, this is used by wrappers to disable PTI for a single exec call. Thanks to this, PTI-aware programs can adjust TIF_DISABLE_PTI_NOW for themselves, and a simple wrapper can be implemented by setting TIF_DISABLE_PTI_NEXT to manage those unable to set TIF_DISABLE_PTI_NOW themselves. Signed-off-by: Willy Tarreau Cc: Andy Lutomirski Cc: Borislav Petkov Cc: Brian Gerst Cc: Dave Hansen Cc: Ingo Molnar Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Josh Poimboeuf Cc: "H. Peter Anvin" Cc: Kees Cook Cc: Alexander Viro --- fs/exec.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/exec.c b/fs/exec.c index 7eb8d21..cf42ddc 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1814,6 +1814,16 @@ static int do_execveat_common(int fd, struct filename *filename, putname(filename); if (displaced) put_files_struct(displaced); + +#ifdef CONFIG_PER_PROCESS_PTI + /* + * TIF_DISABLE_PTI_NOW doesn't pass execve(). TIF_DISABLE_PTI_NEXT + * turns into TIF_DISABLE_PTI_NOW and disappears. + */ + clear_thread_flag(TIF_DISABLE_PTI_NOW); + if (test_and_clear_thread_flag(TIF_DISABLE_PTI_NEXT)) + set_thread_flag(TIF_DISABLE_PTI_NOW); +#endif return retval; out: -- 1.7.12.1