Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1733530pxb; Thu, 16 Sep 2021 14:17:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqyLrB/821vVicHPYFeqnl0pCKy8NqlPoBpwJZkYV3uvNHjlkcXzKz/GmhxQKgIWj0ZAu1 X-Received: by 2002:a05:6638:1606:: with SMTP id x6mr6114320jas.25.1631827025654; Thu, 16 Sep 2021 14:17:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631827025; cv=none; d=google.com; s=arc-20160816; b=ZrH5IQISdctL2GRRDaifakqqJ4QVTjbkAMMlVQ6mQmVQEjTubRPnnIQbJosUE41cIT +j/MotUgsM+9PG8JBlr0VrgV43efLoNjDxyjiLstlW6t430/Xrs/gExz84OVggjtn99k O3UXmgYCJHU0yv5gN2sfdq4A6akuP6gcwqLdLEJ+jJklavol62uOAXDf/QfdrUwaB2Lg fzVEI8EQRZkKPpnE8Ts3i0HTfYcFVFgAzTfBvxfK6yjdchF76CZzmMuwP/PWwi3TbJLC o9C0YYF72gy0ZV/iBCxj2moQX2jMVq95LladQXni+Ly4YHOtL61q7GDp12ugc4bWTmIY QcLg== 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=AV8lA5s7DJTf6wt2UFKFxDj4nFKxwjW0DQ7Eg321djQ2SzjiXqSI1yithX/p85hEeN c+tzgkZkoIw87gJAWK34Qs3Hbtp/rFlQili0m6Izk1YWjAh9Hr6yO6gtmOQl0OLdOwy/ jcqH2P0QWA6QboHbBLKEbPBM4lmrbOJXTdzmHgf9iwROtu+KZugFzv8RaA+D/dzJvpc0 NszhsIeKF+byRiUEvyEmiAv/dnODcPFpgJVfrWZSYxwoQJ4ZRWsWaEgFU8FeeW9CY7h2 FMYBf2C0bkVM8Pq1fAyvOMi09ZSD/MktxfsbK+nFN6USAtNM38gLt4j6q17dUSJ6xTuc uAWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0AjuJBO8; 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 m1si3976916ilu.13.2021.09.16.14.16.52; Thu, 16 Sep 2021 14:17:05 -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=0AjuJBO8; 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 S241986AbhIPQcL (ORCPT + 99 others); Thu, 16 Sep 2021 12:32:11 -0400 Received: from mail.kernel.org ([198.145.29.99]:59316 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240690AbhIPQXs (ORCPT ); Thu, 16 Sep 2021 12:23:48 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E4E1F61356; Thu, 16 Sep 2021 16:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808964; bh=B+lmIPtsQ/2NkqwBSrlwIz/8L2llfIB2i2MRiu/q00A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0AjuJBO8e88N56ULOkDYZraU7yuBQgmpeYs4lY+jifoVU/WpG9l4ZyjM3R8QJ3++O LLVlCUmzyUwsg8jkYFd9N0m5bNT16ThaAiTxhcQi9Mfb84Upopu0caNopWYEtU9RxL BgvTo6WSCwg+POKCCxJfH2cUipJhUhVqfbI0lu5E= 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.10 280/306] parisc: fix crash with signals and alloca Date: Thu, 16 Sep 2021 18:00:25 +0200 Message-Id: <20210916155803.621703110@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@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));