All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lv Zheng <lv.zheng@intel.com>
To: "Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Robert Moore <robert.moore@intel.com>,
	Len Brown <len.brown@intel.com>, Lv Zheng <lv.zheng@intel.com>,
	"David E . Box" <david.e.box@intel.com>
Cc: Lv Zheng <zetalog@gmail.com>,
	linux-acpi@vger.kernel.org, Seunghun Han <kkamagui@gmail.com>
Subject: [PATCH 05/15] ACPICA: Namespace: fix operand cache leak
Date: Wed, 26 Apr 2017 16:18:08 +0800	[thread overview]
Message-ID: <6584657e196b2259f3978f2598829bc22a0e22b1.1493194142.git.lv.zheng@intel.com> (raw)
In-Reply-To: <cover.1493194142.git.lv.zheng@intel.com>

From: Seunghun Han <kkamagui@gmail.com>

ACPICA commit a23325b2e583556eae88ed3f764e457786bf4df6

I found some ACPI operand cache leaks in ACPI early abort cases.

Boot log of ACPI operand cache leak is as follows:
>[    0.174332] ACPI: Added _OSI(Module Device)
>[    0.175504] ACPI: Added _OSI(Processor Device)
>[    0.176010] ACPI: Added _OSI(3.0 _SCP Extensions)
>[    0.177032] ACPI: Added _OSI(Processor Aggregator Device)
>[    0.178284] ACPI: SCI (IRQ16705) allocation failed
>[    0.179352] ACPI Exception: AE_NOT_ACQUIRED, Unable to install
System Control Interrupt handler (20160930/evevent-131)
>[    0.180008] ACPI: Unable to start the ACPI Interpreter
>[    0.181125] ACPI Error: Could not remove SCI handler
(20160930/evmisc-281)
>[    0.184068] kmem_cache_destroy Acpi-Operand: Slab cache still has
objects
>[    0.185358] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 4.10.0-rc3 #2
>[    0.186820] Hardware name: innotek gmb_h virtual_box/virtual_box, BIOS
virtual_box 12/01/2006
>[    0.188000] Call Trace:
>[    0.188000]  ? dump_stack+0x5c/0x7d
>[    0.188000]  ? kmem_cache_destroy+0x224/0x230
>[    0.188000]  ? acpi_sleep_proc_init+0x22/0x22
>[    0.188000]  ? acpi_os_delete_cache+0xa/0xd
>[    0.188000]  ? acpi_ut_delete_caches+0x3f/0x7b
>[    0.188000]  ? acpi_terminate+0x5/0xf
>[    0.188000]  ? acpi_init+0x288/0x32e
>[    0.188000]  ? __class_create+0x4c/0x80
>[    0.188000]  ? video_setup+0x7a/0x7a
>[    0.188000]  ? do_one_initcall+0x4e/0x1b0
>[    0.188000]  ? kernel_init_freeable+0x194/0x21a
>[    0.188000]  ? rest_init+0x80/0x80
>[    0.188000]  ? kernel_init+0xa/0x100
>[    0.188000]  ? ret_from_fork+0x25/0x30

When early abort is occurred due to invalid ACPI information, Linux kernel
terminates ACPI by calling acpi_terminate() function. The function calls
acpi_ns_terminate() function to delete namespace data and ACPI operand cache
(acpi_gbl_module_code_list).

But the deletion code in acpi_ns_terminate() function is wrapped in
ACPI_EXEC_APP definition, therefore the code is only executed when the
definition exists. If the define doesn't exist, ACPI operand cache
(acpi_gbl_module_code_list) is leaked, and stack dump is shown in kernel log.

This causes a security threat because the old kernel (<= 4.9) shows memory
locations of kernel functions in stack dump, therefore kernel ASLR can be
neutralized.

To fix ACPI operand leak for enhancing security, I made a patch which
removes the ACPI_EXEC_APP define in acpi_ns_terminate() function for
executing the deletion code unconditionally.

Link: https://github.com/acpica/acpica/commit/a23325b2
Signed-off-by: Seunghun Han <kkamagui@gmail.com>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Bob Moore <robert.moore@intel.com>
---
 drivers/acpi/acpica/nsutils.c | 23 +++++++++--------------
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/acpi/acpica/nsutils.c b/drivers/acpi/acpica/nsutils.c
index 6616767..b5a2914 100644
--- a/drivers/acpi/acpica/nsutils.c
+++ b/drivers/acpi/acpica/nsutils.c
@@ -594,25 +594,20 @@ struct acpi_namespace_node *acpi_ns_validate_handle(acpi_handle handle)
 void acpi_ns_terminate(void)
 {
 	acpi_status status;
+	union acpi_operand_object *prev;
+	union acpi_operand_object *next;
 
 	ACPI_FUNCTION_TRACE(ns_terminate);
 
-#ifdef ACPI_EXEC_APP
-	{
-		union acpi_operand_object *prev;
-		union acpi_operand_object *next;
+	/* Delete any module-level code blocks */
 
-		/* Delete any module-level code blocks */
-
-		next = acpi_gbl_module_code_list;
-		while (next) {
-			prev = next;
-			next = next->method.mutex;
-			prev->method.mutex = NULL;	/* Clear the Mutex (cheated) field */
-			acpi_ut_remove_reference(prev);
-		}
+	next = acpi_gbl_module_code_list;
+	while (next) {
+		prev = next;
+		next = next->method.mutex;
+		prev->method.mutex = NULL;	/* Clear the Mutex (cheated) field */
+		acpi_ut_remove_reference(prev);
 	}
-#endif
 
 	/*
 	 * Free the entire namespace -- all nodes and all objects
-- 
2.7.4


  parent reply	other threads:[~2017-04-26  8:18 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-26  8:17 [PATCH 00/15] ACPICA 20170303 Release Lv Zheng
2017-04-26  8:17 ` [PATCH 01/15] ACPICA: Disassembler: Enhance resource descriptor detection Lv Zheng
2017-06-05 15:57   ` Linda Knippers
2017-06-05 18:21     ` Linda Knippers
2017-06-05 20:42       ` Rafael J. Wysocki
2017-06-05 20:51         ` Linda Knippers
2017-06-05 20:55           ` Rafael J. Wysocki
2017-06-09 20:29             ` Graeme Gregory
2017-06-13 13:42             ` Linda Knippers
2017-06-13 15:13               ` Rafael J. Wysocki
2017-06-13 20:22               ` Moore, Robert
2017-04-26  8:17 ` [PATCH 02/15] ACPICA: Update some function headers, no funtional change Lv Zheng
2017-04-26  8:17 ` [PATCH 03/15] ACPICA: Fix a module for excessive debug output Lv Zheng
2017-04-26  8:18 ` [PATCH 04/15] ACPICA: Fix several incorrect invocations of ACPICA return macro Lv Zheng
2017-04-26  8:18 ` Lv Zheng [this message]
2017-04-26  8:18 ` [PATCH 06/15] ACPICA: Update for automatic repair code for objects returned by evaluate_object Lv Zheng
2017-04-26  8:18 ` [PATCH 07/15] ACPICA: debugger: fix memory leak on Pathname Lv Zheng
2017-04-26  8:18 ` [PATCH 08/15] ACPICA: Debugger: Add interpreter blocking mark for single-step mode Lv Zheng
2017-04-26  8:18 ` [PATCH 09/15] ACPICA: Cleanup AML opcode definitions, no functional change Lv Zheng
2017-04-26  8:18 ` [PATCH 10/15] ACPICA: iasl: Fix IORT SMMU GSI disassembling Lv Zheng
2017-04-26  8:18 ` [PATCH 11/15] ACPICA: Disassembler: Do not unconditionally remove temporary names Lv Zheng
2017-04-26  8:19 ` [PATCH 12/15] ACPICA: iasl: add ASL conversion tool Lv Zheng
2017-04-26 19:45   ` kbuild test robot
2017-04-27  1:43     ` Zheng, Lv
2017-04-27 15:07       ` Rafael J. Wysocki
2017-04-26  8:19 ` [PATCH 13/15] ACPICA: Local cache support: Allow small cache objects Lv Zheng
2017-04-26  8:20 ` [PATCH 14/15] ACPICA: Fix build for FreeBSD kernel Lv Zheng
2017-04-26  8:20 ` [PATCH 15/15] ACPICA: Update version to 20170303 Lv Zheng
2017-04-28  0:53 ` [PATCH v2] ACPICA: iasl: add ASL conversion tool Lv Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6584657e196b2259f3978f2598829bc22a0e22b1.1493194142.git.lv.zheng@intel.com \
    --to=lv.zheng@intel.com \
    --cc=david.e.box@intel.com \
    --cc=kkamagui@gmail.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=robert.moore@intel.com \
    --cc=zetalog@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.