Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2319480pxb; Mon, 20 Sep 2021 18:42:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz2tbyT9nfdfV8oJUrAs1BSxf2yoyDCgTm7Jz7QFGTD1f8HKS2PMBx4uEWWiGIRz4A8pcxH X-Received: by 2002:a02:601f:: with SMTP id i31mr13595252jac.80.1632188557238; Mon, 20 Sep 2021 18:42:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632188557; cv=none; d=google.com; s=arc-20160816; b=DBfUN/Ne9bxFP9zR8MNcAyRigOzjZbXjDl4Cwg8t4dTRWr2RwZODhF6bNVxkjM44Ut F3Z7X/JrJz7twCOSTpag0zVttF4l/VQ37sGBOEeui1Fw+6m1xPfr5C5aAtPR7Rm28E5Z 4kpm+IQn0TuE+qZWZAf/5gvmVpe4nkIuXKn8OaDWQKlkvu/SGcrxzZgO2gmfObdVEOwN MR1+d+rf80y69TEhybT9YNOX4E32gDoSzaRpbnwjL/jLWJHl1UWCIrGf2zVVTYUDErkq JQRYd+gtyNE2tBsrltzJw4j+EUYe6AFRIAbOCSoAYx6lFP6S1RY7s6KcI7VNJQbPr2Ar y5Vw== 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=/tJflk6+67xls0rm52MMAziqsPHm/2+4uHw2kmn3kxM=; b=J6p6hMAccTOSmNeBIWsQnELDyhMl1y22jfWfcBuORvZycLFrDzI95fJuGUGTSZ6sy8 SbO/DzMMIqY2IXFq/tnccJMZOVZP+ChbWK30vx9wLZh2BYzTzjc2jmmRv8e9Chk71As7 +NIAjFATyvKubeOkbIS8EzBe5tmspBFCVleKQz9u0lQ3cY89Od4Ndfb1kHAfYPSBFj9R MGLVOMjE52dAfgDUWkhEJPHg2MB7fWawZlEoTGwehYqT6182THd68rfRoNDY6qXprJgb 2ZWKFPUewNhI5YiPFzY/JzJjeyH/j56p7tKUwMaLV35khmn230oUQePeeUH4Xp3DwhFX tC0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=cj0RhDU7; 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 q15si10008596ilo.78.2021.09.20.18.42.26; Mon, 20 Sep 2021 18:42:37 -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=cj0RhDU7; 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 S242968AbhITQzM (ORCPT + 99 others); Mon, 20 Sep 2021 12:55:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:39212 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243466AbhITQuw (ORCPT ); Mon, 20 Sep 2021 12:50:52 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id AC630611AE; Mon, 20 Sep 2021 16:49:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632156563; bh=rSes+fkgNcdnRhQdFfMj5NVACGIdVJzrMcuJwL51u4I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cj0RhDU7tbFJuDBXm0DB0TCl3TQHLqPP5JEQnXUA7qeejzyWduDiN/qVTjJibpUry SYk8uP0pygibMNLYnp81D6DyYLk8vJ0CbTHF/pvlHepPAXnYwPW8rDUIFcGGFlTxO1 NHQ4BrY2Ww/E13CNK7lDMd07oEHAuusa6MntVScs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Helge Deller Subject: [PATCH 4.4 116/133] parisc: fix crash with signals and alloca Date: Mon, 20 Sep 2021 18:43:14 +0200 Message-Id: <20210920163916.419548729@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163912.603434365@linuxfoundation.org> References: <20210920163912.603434365@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 @@ -239,6 +239,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));