Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1572728pxb; Thu, 16 Sep 2021 10:09:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzg/JSQF6GzXNvgFs+xiBeGcsNPvtoU7Ys0QGglKL4c3BJI1U9aEpbZVtL+3JcFaGxHdPS X-Received: by 2002:adf:ea90:: with SMTP id s16mr7336926wrm.235.1631812196779; Thu, 16 Sep 2021 10:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631812196; cv=none; d=google.com; s=arc-20160816; b=Zx5Q6sH5/239AE9kEdtvwhAMIOYayu333viDJfHzBpSAdSvujWqOLvWKf72l8I/KoJ cXMukv3uvwYbfvOxbX0YvN11IRCPehP2nedw3AInsVqAnNAoclU9/UUJvALkUTiCHr0o 3Cw07A6uhoulVeqaQ1RVQAt4SjIs9AcCDWdX4sjX2jLMGqTjEjBi6pEido3RJGxj4S09 LYJqMrFlxTrVjKzlLyCJknrnoZM2ESSxd0F054Uw2ZsoY7wL73mSc6pwHXVOm+tSFlxD j0qqgMQtkmWkvbTtMxz2a4oWDGxMvykp/ylmxdeoc8zu+qryVrO11ksghzpjkYgXIIkV c/6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=EshPYzdVEGbK5nHGLOPZa6M3FtkrnFT28cXmwDszMpI=; b=pvHp2U1ezhMmRpdQr2WgfZ0p9xJJsy8AqsMWMycRs6Fk7412usgBrONdQn1i0EWjMu g41U4q1WtnqEvThIJdug7WiwES9aGyyom3dgdL4GMAir8oCBDPuGTCqTzdIVC3H4rdm7 jWr6dbIcOIeinh1bd7LiwkRDv7nS2arUiDvrH0m08huDr+akayAsv22HdvY8gMRgflvy ixgER6z7PRGhgdNSmBumog+sNrM1a7Wn0jVeIw52FLBcEK2sWFpVLxeyHvrR7zvhVlZ8 XsP5S7mcsQVTpoUujj39ouBGfDD83GO8b2hpTes1IbJx+ln/jAGbHI+AHUnbrf164r2T 3s3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P7J7aJ+A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q14si4031108edr.585.2021.09.16.10.09.30; Thu, 16 Sep 2021 10:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=P7J7aJ+A; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349513AbhIPRF5 (ORCPT + 99 others); Thu, 16 Sep 2021 13:05:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:34010 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347833AbhIPRAo (ORCPT ); Thu, 16 Sep 2021 13:00:44 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2557561A03; Thu, 16 Sep 2021 16:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631809961; bh=B+lmIPtsQ/2NkqwBSrlwIz/8L2llfIB2i2MRiu/q00A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P7J7aJ+AsHhC6ryzsYtLvejxNkqk9BCjT7+LUdshaAOql6dl+3G/nuWPNuU0cFneP U8P5p81fFF2MF55rHJ2Xm4cQ7+gqQGrrb4HIkGKKbyD/1meHafXbcc4dLsLj/gqSa1 wflNYRCk+xjnC0RAfQ7Cs5nYikz2ik3MAtG86xns= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Helge Deller Subject: [PATCH 5.13 346/380] parisc: fix crash with signals and alloca Date: Thu, 16 Sep 2021 18:01:43 +0200 Message-Id: <20210916155815.818636999@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155803.966362085@linuxfoundation.org> References: <20210916155803.966362085@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka commit 030f653078316a9cc9ca6bd1b0234dcf858be35d upstream. I was debugging some crashes on parisc and I found out that there is a crash possibility if a function using alloca is interrupted by a signal. The reason for the crash is that the gcc alloca implementation leaves garbage in the upper 32 bits of the sp register. This normally doesn't matter (the upper bits are ignored because the PSW W-bit is clear), however the signal delivery routine in the kernel uses full 64 bits of sp and it fails with -EFAULT if the upper 32 bits are not zero. I created this program that demonstrates the problem: #include #include #include #include static __attribute__((noinline,noclone)) void aa(int *size) { void * volatile p = alloca(-*size); while (1) ; } static void handler(int sig) { write(1, "signal delivered\n", 17); _exit(0); } int main(void) { int size = -0x100; signal(SIGALRM, handler); alarm(1); aa(&size); } If you compile it with optimizations, it will crash. The "aa" function has this disassembly: 000106a0 : 106a0: 08 03 02 41 copy r3,r1 106a4: 08 1e 02 43 copy sp,r3 106a8: 6f c1 00 80 stw,ma r1,40(sp) 106ac: 37 dc 3f c1 ldo -20(sp),ret0 106b0: 0c 7c 12 90 stw ret0,8(r3) 106b4: 0f 40 10 9c ldw 0(r26),ret0 ; ret0 = 0x00000000FFFFFF00 106b8: 97 9c 00 7e subi 3f,ret0,ret0 ; ret0 = 0xFFFFFFFF0000013F 106bc: d7 80 1c 1a depwi 0,31,6,ret0 ; ret0 = 0xFFFFFFFF00000100 106c0: 0b 9e 0a 1e add,l sp,ret0,sp ; sp = 0xFFFFFFFFxxxxxxxx 106c4: e8 1f 1f f7 b,l,n 106c4 ,r0 This patch fixes the bug by truncating the "usp" variable to 32 bits. Signed-off-by: Mikulas Patocka Cc: stable@vger.kernel.org Signed-off-by: Helge Deller Signed-off-by: Greg Kroah-Hartman --- arch/parisc/kernel/signal.c | 6 ++++++ 1 file changed, 6 insertions(+) --- a/arch/parisc/kernel/signal.c +++ b/arch/parisc/kernel/signal.c @@ -237,6 +237,12 @@ setup_rt_frame(struct ksignal *ksig, sig #endif usp = (regs->gr[30] & ~(0x01UL)); +#ifdef CONFIG_64BIT + if (is_compat_task()) { + /* The gcc alloca implementation leaves garbage in the upper 32 bits of sp */ + usp = (compat_uint_t)usp; + } +#endif /*FIXME: frame_size parameter is unused, remove it. */ frame = get_sigframe(&ksig->ka, usp, sizeof(*frame));