Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7564132imu; Tue, 22 Jan 2019 08:00:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN6fJhRUXZaIvdzKU4A8SUBGhQYgdsGwT0WKAKveox2X68HkTmrcq01mpVtAaNN6padlWJBJ X-Received: by 2002:a63:c42:: with SMTP id 2mr32576434pgm.372.1548172809251; Tue, 22 Jan 2019 08:00:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548172809; cv=none; d=google.com; s=arc-20160816; b=EEdIdoqIHx//TRIMII6Nvndo+XkCx/ePx3y4Vyf8+QI9YAOnJ/R4eDPuRny78WEED9 b5oehPFzzDUqWkutkvw7ysQuvC88V+eXz/eMhBKCMQZq3wo51vuUwagAHvxtP/nCTJub AUWRwfubGncvifTHsveIOSTP+i4Zta0RBHJsZLwwtFdX4+2KdbUFptiUS19J3Ua4aYU3 U+vKSx0QaHGM1bZb+7WOqkwLwYV1TK8yB84h9KG2L29KEXblz27aefgHrcH7XMok65ek 06+BFHcZl2URcGFjct8MT6+PxwYkU7sjBJwUuC7iN0ozyEFL/2FbbDShJAK+Aqbjy0ow ukpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=xbTyVZ2TzEmMAPwm9E2U+zMYxGS9IL3Q+pSC3NRcyqI=; b=LKxxZfId2SptsSU5/MyNIxE4qM3Sg0HhsyiLu1qnOnnGEEj9xRN96QWJpFj7ucvvFq dwM2sKG3v5H4DWiFD5e5bLzFELZWgHBTVlE9K0Qzb8iwYh7fOntw8gQ9gydASh7VF/Y8 7M2v+LciAVndp62hvWGo0slrOW24lg6nGkkXt0rxsen8EPuMcCOfiBIH3qSVInTpLqMt F1nMn+miVgLPGpwtW0S3luLW+8iSNKrDeuTrLSOThEQHudO8gWwQEOtIKbQHL0FXMAoE lPZ+Qy+CRKc/V9Rw7e9FE5z7SvW1VZZpk37KKVlqvtxXX4PEgwNqVA3yx6V36UMgJM80 fskw== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si16342921pla.173.2019.01.22.07.59.53; Tue, 22 Jan 2019 08:00: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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729271AbfAVP5l (ORCPT + 99 others); Tue, 22 Jan 2019 10:57:41 -0500 Received: from mx1.redhat.com ([209.132.183.28]:47574 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729216AbfAVP5h (ORCPT ); Tue, 22 Jan 2019 10:57:37 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0E23829158; Tue, 22 Jan 2019 15:57:37 +0000 (UTC) Received: from jlaw-desktop.bos.redhat.com (dhcp-17-208.bos.redhat.com [10.18.17.208]) by smtp.corp.redhat.com (Postfix) with ESMTP id A151B1019633; Tue, 22 Jan 2019 15:57:34 +0000 (UTC) From: Joe Lawrence To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, live-patching@vger.kernel.org Cc: Balbir Singh , Jiri Kosina , Josh Poimboeuf , Michael Ellerman , Nicolai Stange , Torsten Duwe Subject: [PATCH 2/4] powerpc/livepatch: relax reliable stack tracer checks for first-frame Date: Tue, 22 Jan 2019 10:57:22 -0500 Message-Id: <20190122155724.27557-3-joe.lawrence@redhat.com> In-Reply-To: <20190122155724.27557-1-joe.lawrence@redhat.com> References: <20190122155724.27557-1-joe.lawrence@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 22 Jan 2019 15:57:37 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The bottom-most stack frame (the first to be unwound) may be largely uninitialized, for the "Power Architecture 64-Bit ELF V2 ABI" only requires its backchain pointer to be set. The reliable stack tracer should be careful when verifying this frame: skip checks on STACK_FRAME_LR_SAVE and STACK_FRAME_MARKER offsets that may contain uninitialized residual data. Fixes: df78d3f61480 ("powerpc/livepatch: Implement reliable stack tracing for the consistency model") Signed-off-by: Joe Lawrence --- arch/powerpc/kernel/stacktrace.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/kernel/stacktrace.c b/arch/powerpc/kernel/stacktrace.c index e2c50b55138f..06688f4d557b 100644 --- a/arch/powerpc/kernel/stacktrace.c +++ b/arch/powerpc/kernel/stacktrace.c @@ -84,6 +84,12 @@ save_stack_trace_regs(struct pt_regs *regs, struct stack_trace *trace) EXPORT_SYMBOL_GPL(save_stack_trace_regs); #ifdef CONFIG_HAVE_RELIABLE_STACKTRACE +/* + * This function returns an error if it detects any unreliable features of the + * stack. Otherwise it guarantees that the stack trace is reliable. + * + * If the task is not 'current', the caller *must* ensure the task is inactive. + */ int save_stack_trace_tsk_reliable(struct task_struct *tsk, struct stack_trace *trace) @@ -142,12 +148,6 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk, if (sp & 0xF) return 1; - /* Mark stacktraces with exception frames as unreliable. */ - if (sp <= stack_end - STACK_INT_FRAME_SIZE && - stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) { - return 1; - } - newsp = stack[0]; /* Stack grows downwards; unwinder may only go up. */ if (newsp <= sp) @@ -158,11 +158,26 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk, return 1; /* invalid backlink, too far up. */ } + /* + * We can only trust the bottom frame's backlink, the + * rest of the frame may be uninitialized, continue to + * the next. + */ + if (firstframe) { + firstframe = 0; + goto next; + } + + /* Mark stacktraces with exception frames as unreliable. */ + if (sp <= stack_end - STACK_INT_FRAME_SIZE && + stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) { + return 1; + } + /* Examine the saved LR: it must point into kernel code. */ ip = stack[STACK_FRAME_LR_SAVE]; - if (!firstframe && !__kernel_text_address(ip)) + if (!__kernel_text_address(ip)) return 1; - firstframe = 0; /* * FIXME: IMHO these tests do not belong in @@ -183,6 +198,7 @@ save_stack_trace_tsk_reliable(struct task_struct *tsk, else trace->skip--; +next: if (newsp == stack_end) break; -- 2.20.1