From nobody Thu Feb 12 02:58:34 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 08353C77B60 for ; Sat, 29 Apr 2023 10:11:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231201AbjD2KLF (ORCPT ); Sat, 29 Apr 2023 06:11:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229948AbjD2KLA (ORCPT ); Sat, 29 Apr 2023 06:11:00 -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 0B20219A0 for ; Sat, 29 Apr 2023 03:10:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682763013; 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=vXxBktH3cHV7+Leg2kx7Rf8co9gFb3d5SPKnMmXtxww=; b=gkhNynjryF6T+18W7Sxqtgx7FkGtblTfXw8f7oernrG3eKH8bKXnchfdRUm5tmqrDUqH+S v8Abcsmn+jIt1vq4EdTW84Cso80unXXHT/tWlUjXEJK/XMb9iFsUYPrOHAbZVs7DWV/yRx 1+13uHvjqOMDUHVrCO2PHE8mVFuvLbA= 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-656-sBBlU5ESOEqv14wyfl36og-1; Sat, 29 Apr 2023 06:10:09 -0400 X-MC-Unique: sBBlU5ESOEqv14wyfl36og-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5B0AD811E7B; Sat, 29 Apr 2023 10:10:09 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.224.26]) by smtp.corp.redhat.com (Postfix) with SMTP id E08C72166B26; Sat, 29 Apr 2023 10:10:07 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sat, 29 Apr 2023 12:09:57 +0200 (CEST) Date: Sat, 29 Apr 2023 12:09:55 +0200 From: Oleg Nesterov To: Josh Poimboeuf , Peter Zijlstra , Thomas Gleixner Cc: Vernon Lovejoy , linux-kernel@vger.kernel.org Subject: [PATCH v2] x86/show_trace_log_lvl: ensure stack pointer is aligned, again Message-ID: <20230429100955.GA20567@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.6 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 --- arch/x86/kernel/dumpstack.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c index 0bf6779187dd..f82d896eb99d 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,7 +213,10 @@ 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 PTR_ALIGN(stack ?: get_stack_pointer(task, regs), sizeof(l= ong)); + stack; + stack =3D PTR_ALIGN(stack_info.next_sp, sizeof(long))) + { const char *stack_name; =20 if (get_stack_info(stack, task, &stack_info, &visit_mask)) { --=20 2.25.1.362.g51ebf55