Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4069610imu; Mon, 28 Jan 2019 16:41:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN5VsD8OtiqH8PL1fuoLsv34zIPsWtjF870CGJSxPuDL2vj24zR5ISfRXhFr8sjMSbUqQkbW X-Received: by 2002:a17:902:6b87:: with SMTP id p7mr24278995plk.282.1548722469363; Mon, 28 Jan 2019 16:41:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548722469; cv=none; d=google.com; s=arc-20160816; b=HHRpZES1HiZRG3rLvqQtKc7+RXRK7gziTdeZS1YSUjbyBTzv20a+7UTY0h7khvlV7a oNYHGMDGKUMcrRY+VAIeZJRBoPmUHypRgiSA/mySJQEBjC+v/YisPgbMr0LS8yGfGkDP iWwj1WdKWFC+lq3SsOLomZv/wmdS2vRYzp5oarBZ+Lst4EqR2NPz2BqohLoaW6Jp65MD 69jKSXXM4xkoQ5UGrpJfaPbBxjtw+ZnDspIUrJZ5o77ejgAvkDedz9yJRb1wXZbh+QCS K4SoFLT1VwBj4JKBT5rTUBNs91qt6XyUQE3Em2uBj10S3FhcV2hHZYTJH5xBvWi5Gg3i xIyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=Vw4Tc9/qTce/ps387hTBEGuO1Y4CjbTaT+4DjGZJWvU=; b=xVkYDdDBjWExxbPtch935nuSYYHGbo5sONnBwjgmvdIGf+r4+wb0B06InBN45Tm0X2 35XAyJpdUjWEpqSyh8WUHBWfOkhklhma7yYxnOjZ9Zz5SDwLSk89HqPHEeSpp7OIha8+ pEYbLhNNSWEbGfwEsahWetawEYv5H6ZDyA6GhKqMHA8z2ffE8aMJEECwu0QyVKKhxHcy IVnbuuHMnozhFv9zhEL6V8x1sOkukOM6FhmYBpMaGevSjLkP/b6WU0HhlR2Q2CzGlrPL jjWXk7BGSLF1FagECzsL5+6lDpIw2x7Ll2pSedgeTVFc5FGa0SQNty5DcSQpJYNkHxQc rWUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7si1974822pls.326.2019.01.28.16.40.53; Mon, 28 Jan 2019 16:41:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727798AbfA2AjZ (ORCPT + 99 others); Mon, 28 Jan 2019 19:39:25 -0500 Received: from mga06.intel.com ([134.134.136.31]:5079 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfA2AjS (ORCPT ); Mon, 28 Jan 2019 19:39:18 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Jan 2019 16:39:12 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,535,1539673200"; d="scan'208";a="133921906" Received: from rpedgeco-desk5.jf.intel.com ([10.54.75.79]) by orsmga001.jf.intel.com with ESMTP; 28 Jan 2019 16:39:11 -0800 From: Rick Edgecombe To: Andy Lutomirski , Ingo Molnar Cc: linux-kernel@vger.kernel.org, x86@kernel.org, hpa@zytor.com, Thomas Gleixner , Borislav Petkov , Nadav Amit , Dave Hansen , Peter Zijlstra , linux_dti@icloud.com, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, akpm@linux-foundation.org, kernel-hardening@lists.openwall.com, linux-mm@kvack.org, will.deacon@arm.com, ard.biesheuvel@linaro.org, kristen@linux.intel.com, deneen.t.dock@intel.com, Nadav Amit , Steven Rostedt , Rick Edgecombe Subject: [PATCH v2 08/20] x86/ftrace: set trampoline pages as executable Date: Mon, 28 Jan 2019 16:34:10 -0800 Message-Id: <20190129003422.9328-9-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190129003422.9328-1-rick.p.edgecombe@intel.com> References: <20190129003422.9328-1-rick.p.edgecombe@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nadav Amit Since alloc_module() will not set the pages as executable soon, we need to do so for ftrace trampoline pages after they are allocated. For the time being, we do not change ftrace to use the text_poke() interface. As a result, ftrace breaks still breaks W^X. Cc: Steven Rostedt Signed-off-by: Nadav Amit Signed-off-by: Rick Edgecombe --- arch/x86/kernel/ftrace.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 8257a59704ae..13c8249b197f 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -742,6 +742,7 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) unsigned long end_offset; unsigned long op_offset; unsigned long offset; + unsigned long npages; unsigned long size; unsigned long retq; unsigned long *ptr; @@ -774,6 +775,7 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) return 0; *tramp_size = size + RET_SIZE + sizeof(void *); + npages = DIV_ROUND_UP(*tramp_size, PAGE_SIZE); /* Copy ftrace_caller onto the trampoline memory */ ret = probe_kernel_read(trampoline, (void *)start_offset, size); @@ -818,6 +820,12 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size) /* ALLOC_TRAMP flags lets us know we created it */ ops->flags |= FTRACE_OPS_FL_ALLOC_TRAMP; + /* + * Module allocation needs to be completed by making the page + * executable. The page is still writable, which is a security hazard, + * but anyhow ftrace breaks W^X completely. + */ + set_memory_x((unsigned long)trampoline, npages); return (unsigned long)trampoline; fail: tramp_free(trampoline, *tramp_size); -- 2.17.1