From nobody Wed Feb 11 06:30:18 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F9EFC77B7C for ; Fri, 12 May 2023 10:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240809AbjELKnm (ORCPT ); Fri, 12 May 2023 06:43:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240134AbjELKnj (ORCPT ); Fri, 12 May 2023 06:43:39 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5478269E for ; Fri, 12 May 2023 03:42:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1683888171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=4Ins6rSTGkuS9vQ3+W4aJZgNFWbwMvuVrsqaenjKcTo=; b=D7UJ7ZeveF5xTuYAZlaHgYoziU4U3TOLbG95QJsFUpbrKvgw2eT8X29J6ZUyZDAc+/HBh0 afgQYXEZhZWq+cED2s6BOsx8Q8LyDEZKCC1nig9KBQ+dGXHarrd5MulE+lLzI3nOzC6Jyo z9TmyGw+FYJK+fFVJgOUjI9WLOi5oOY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-390-AEle9h5RN96obliCs5BAvg-1; Fri, 12 May 2023 06:42:48 -0400 X-MC-Unique: AEle9h5RN96obliCs5BAvg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E8029868A00; Fri, 12 May 2023 10:42:47 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.40]) by smtp.corp.redhat.com (Postfix) with SMTP id C45F7400E89; Fri, 12 May 2023 10:42:46 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Fri, 12 May 2023 12:42:34 +0200 (CEST) Date: Fri, 12 May 2023 12:42:32 +0200 From: Oleg Nesterov To: Peter Zijlstra , Thomas Gleixner Cc: Vernon Lovejoy , linux-kernel@vger.kernel.org, David Laight , Josh Poimboeuf Subject: [PATCH v3] x86/show_trace_log_lvl: ensure stack pointer is aligned, again Message-ID: <20230512104232.GA10227@redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Vernon Lovejoy The commit e335bb51cc15 ("x86/unwind: Ensure stack pointer is aligned") tried to align the stack pointer in show_trace_log_lvl(), otherwise the "stack < stack_info.end" check can't guarantee that the last read does not go past the end of the stack. However, we have the same problem with the initial value of the stack pointer, it can also be unaligned. So without this patch this trivial kernel module #include static int init(void) { asm volatile("sub $0x4,%rsp"); dump_stack(); asm volatile("add $0x4,%rsp"); return -EAGAIN; } module_init(init); MODULE_LICENSE("GPL"); crashes the kernel. Fixes: e335bb51cc15 ("x86/unwind: Ensure stack pointer is aligned") Signed-off-by: Vernon Lovejoy Signed-off-by: Oleg Nesterov Acked-by: Josh Poimboeuf --- arch/x86/kernel/dumpstack.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 0bf6779187dd..f18ca44c904b 100644 --- a/arch/x86/kernel/dumpstack.c +++ b/arch/x86/kernel/dumpstack.c @@ -195,7 +195,6 @@ static void show_trace_log_lvl(struct task_struct *task= , struct pt_regs *regs, printk("%sCall Trace:\n", log_lvl); =20 unwind_start(&state, task, regs, stack); - stack =3D stack ? : get_stack_pointer(task, regs); regs =3D unwind_get_entry_regs(&state, &partial); =20 /* @@ -214,9 +213,13 @@ static void show_trace_log_lvl(struct task_struct *tas= k, struct pt_regs *regs, * - hardirq stack * - entry stack */ - for ( ; stack; stack =3D PTR_ALIGN(stack_info.next_sp, sizeof(long))) { + for (stack =3D stack ?: get_stack_pointer(task, regs); + stack; + stack =3D stack_info.next_sp) { const char *stack_name; =20 + stack =3D PTR_ALIGN(stack, sizeof(long)); + if (get_stack_info(stack, task, &stack_info, &visit_mask)) { /* * We weren't on a valid stack. It's possible that --=20 2.25.1.362.g51ebf55