From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.1 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 26235 invoked from network); 22 Jan 2021 18:16:44 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 22 Jan 2021 18:16:44 -0000 Received: (qmail 13574 invoked by uid 550); 22 Jan 2021 18:16:41 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 11669 invoked from network); 22 Jan 2021 18:13:33 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=pp1; bh=U39dKNINpnszgtsPTvaqB2w1RkgTyKzE9aUcGPHcAis=; b=dqJBpCoYDvcGmOq+YwIRsloxnfwgO/fTlaj6tZNzyTAzey5twN/pQc/Pb/1biPB20sJ7 29OIwfuYaceRSgo6SveHHb8i/wmNM87CIQpls70/AE/+WGVKTT9MH8eNhlzfWT3by8v8 /BRIta9eJiS2xVTPcb7ALoWnhUKKK1elloWWkKjYzNMrVSY8c298Wdzc3ADUlxBbSWYS SOPudhlTmr4t5kCxWFvmLUiqQTK/n65wjcA26sRBl+xxXqchf1iLObJxZoJ7AFqY2oWn Lc+J56O2vXlQxWpW9JKDxECSVp7KarrYkoqpjKgcpicx8ZvANVGj6ze3H/Y0iio2xSmp 8A== Date: Fri, 22 Jan 2021 15:13:13 -0300 From: Raoni Fassina Firmino To: Florian Weimer Cc: Nicholas Piggin , musl@lists.openwall.com, libc-alpha@sourceware.org, linuxppc-dev@lists.ozlabs.org, Alan Modra Message-ID: <20210122181313.nk7ttzjujyqwjmpe@work-tp> Mail-Followup-To: Florian Weimer , Nicholas Piggin , musl@lists.openwall.com, libc-alpha@sourceware.org, linuxppc-dev@lists.ozlabs.org, Alan Modra References: <20200511101952.1463138-1-npiggin@gmail.com> <87im7pp5yl.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87im7pp5yl.fsf@oldenburg.str.redhat.com> X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-22_13:2021-01-22,2021-01-22 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1011 malwarescore=0 spamscore=0 priorityscore=1501 bulkscore=0 phishscore=0 mlxscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101220091 Subject: [musl] Re: [PATCH v2] powerpc/64/signal: balance return predictor stack in signal trampoline On Fri, Jan 22, 2021 at 12:27:14PM +0100, AL glibc-alpha wrote: > * Nicholas Piggin: > > > diff --git a/arch/powerpc/kernel/vdso64/sigtramp.S b/arch/powerpc/kernel/vdso64/sigtramp.S > > index a8cc0409d7d2..bbf68cd01088 100644 > > --- a/arch/powerpc/kernel/vdso64/sigtramp.S > > +++ b/arch/powerpc/kernel/vdso64/sigtramp.S > > @@ -6,6 +6,7 @@ > > * Copyright (C) 2004 Benjamin Herrenschmuidt (benh@kernel.crashing.org), IBM Corp. > > * Copyright (C) 2004 Alan Modra (amodra@au.ibm.com)), IBM Corp. > > */ > > +#include /* IFETCH_ALIGN_BYTES */ > > #include > > #include > > #include > > @@ -14,21 +15,17 @@ > > > > .text > > > > -/* The nop here is a hack. The dwarf2 unwind routines subtract 1 from > > - the return address to get an address in the middle of the presumed > > - call instruction. Since we don't have a call here, we artificially > > - extend the range covered by the unwind info by padding before the > > - real start. */ > > - nop > > .balign 8 > > + .balign IFETCH_ALIGN_BYTES > > V_FUNCTION_BEGIN(__kernel_sigtramp_rt64) > > -.Lsigrt_start = . - 4 > > +.Lsigrt_start: > > + bctrl /* call the handler */ > > addi r1, r1, __SIGNAL_FRAMESIZE > > li r0,__NR_rt_sigreturn > > sc > > .Lsigrt_end: > > V_FUNCTION_END(__kernel_sigtramp_rt64) > > -/* The ".balign 8" above and the following zeros mimic the old stack > > +/* The .balign 8 above and the following zeros mimic the old stack > > trampoline layout. The last magic value is the ucontext pointer, > > chosen in such a way that older libgcc unwind code returns a zero > > for a sigcontext pointer. */ > > As far as I understand it, this breaks cancellation handling on musl and > future glibc because it is necessary to look at the signal delivery > location to see if a system call sequence has result in an action, and > that location is no longer in user code after this change. > > We have a glibc test in preparation of our change, and it started > failing: > > Linux 5.10 breaks sigcontext_get_pc on powerpc64 > > > Isn't it possible to avoid the return predictor desynchronization by > adding the appropriate hint? I also caught this regression, I believe it was introduced in the kernel 5.9. I don't know enough to comment on Florian suggestion, but I am working on some possible fixes: On the kernel side we can keep `__kernel_sigtramp_rt64` in the original place after `bctrl` and add a new symbol so the kernel can jump to the right place before `bctrl`. This would ensure backward compatibility. On the other side, this change exposed how fragile `backtrace()` is to any changes in the trampoline code, which the libc has no control over in this case. So maybe there is something that can be improved in how backtrace decides that the return-address is to the trampoline. My fist option is to test a range, after `__kernel_sigtramp_rt64` so see if the address is inside the routine. This would be better if we can know the size of the function, I know that the vdso.so has this info in the elf but I don't know if it is exposed to the glibc. As Nicholas mentioned in his patch, GDB seems to keep working just fine, it is seems that GDB uses some heuristics to match the surround code of the return address to identify that it is the trampoline code. So maybe other option is to do something similar. o/ Raoni Fassina