mips, mips64 signal trampoline
PATCH 1/1 mips, mips64 signal trampoline
It looks like the RA setup by setup_frame and setup_rt_frame in arch/mips64/kernel/signal.c and signal32.c can be wrong. Same for arch/mips/kernel/signal.c
signal32.c, 32-bit signal.c: sa_restorer is overriden signal.c: regs->regs[31] is pointed at the sigframe's code, even though there isn't code in the frame, and a comment says that sa_restorer is always used.
Patch for 2.4 attached.
Kip
Index: arch/mips64/kernel/signal.c
===================================================================
RCS file: /home/cvs/linux/arch/mips64/kernel/signal.c,v retrieving revision 1.19.2.5
mips64/kernel/signal.c +2 -4
@@ -338,13 +338,12 @@ regs->regs[5 ] =0 ; regs->regs[6 ] = (unsigned long ) &frame->sf_sc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->sf_code; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->sf_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
@@ -402,13 +401,12 @@ regs->regs[5 ] = (unsigned long ) &frame->rs_info; regs->regs[6 ] = (unsigned long ) &frame->rs_uc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->rs_code; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->rs_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
Index: arch/mips64/kernel/signal32.c
===================================================================
RCS file: /home/cvs/linux/arch/mips64/kernel/signal32.c,v retrieving revision 1.20.2.9
mips64/kernel/signal32.c +2 -2
@@ -589,6 +589,7 @@ err |=__put_user (0x0000000c , frame->sf_code +1 );flush_cache_sigtramp ((unsigned long ) frame->sf_code); + regs->regs[31 ] = (unsigned long ) frame->sf_code; } err |=setup_sigcontext (regs, &frame->sf_sc);
@@ -610,7 +611,6 @@ regs->regs[5 ] =0 ; regs->regs[6 ] = (unsigned long ) &frame->sf_sc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->sf_code; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG
@@ -653,6 +653,7 @@ err |=__put_user (0x0000000c , frame->rs_code +1 );flush_cache_sigtramp ((unsigned long ) frame->rs_code); + regs->regs[31 ] = (unsigned long ) frame->rs_code; }/* Convert (siginfo_t -> siginfo_t32) and copy to user. */
@@ -687,7 +688,6 @@ regs->regs[5 ] = (unsigned long ) &frame->rs_info; regs->regs[6 ] = (unsigned long ) &frame->rs_uc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->rs_code; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG
OK, the patch was broken because it changed regs->regs[31] before the setup_sigcontext. I think this one actually fixes a problem instead of introducing one. :-) Somebody sent the 32-bit part of the patch around a long time ago, but it doesn't seem to have gotten into CVS yet.
Kip
Quoted 5 lines · Kip Walker
It looks like the RA setup by
setup_frameandsetup_rt_frameinarch/mips64/kernel/signal.candsignal32.ccan be wrong. Same forarch/mips/kernel/signal.c
Quoted 7 lines
signal32.c, 32-bitsignal.c:sa_restoreris overridensignal.c: regs->regs[31] is pointed at the sigframe's code, even though there isn't code in the frame, and a comment says thatsa_restoreris always used.Patch for 2.4 attached.
Index: arch/mips/kernel/signal.c
===================================================================
RCS file: /home/cvs/linux/arch/mips/kernel/signal.c,v retrieving revision 1.39.2.9
mips/kernel/signal.c +10 -6
@@ -461,6 +461,7 @@ int signr, sigset_t *set) { struct sigframe *frame; +unsigned long ra;int err =0 ; frame =get_sigframe (ka, regs,sizeof (*frame));
@@ -470,7 +471,7 @@/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags &SA_RESTORER ) - regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; + ra = (unsigned long ) ka->sa.sa_restorer;else {/* * Set up the return code ...
@@ -483,6 +484,7 @@ err |=__put_user (0x0000000c , frame->sf_code +1 );flush_cache_sigtramp ((unsigned long ) frame->sf_code); + ra = (unsigned long ) frame->sf_code; } err |=setup_sigcontext (regs, &frame->sf_sc);
@@ -504,13 +506,13 @@ regs->regs[5 ] =0 ; regs->regs[6 ] = (unsigned long ) &frame->sf_sc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->sf_code; + regs->regs[31 ] = ra; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->sf_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
@@ -524,6 +526,7 @@ int signr, sigset_t *set, siginfo_t *info) { struct rt_sigframe *frame; +unsigned long ra;int err =0 ; frame =get_sigframe (ka, regs,sizeof (*frame));
@@ -533,7 +536,7 @@/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags &SA_RESTORER ) - regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; + ra = (unsigned long ) ka->sa.sa_restorer;else {/* * Set up the return code ...
@@ -546,6 +549,7 @@ err |=__put_user (0x0000000c , frame->rs_code +1 );flush_cache_sigtramp ((unsigned long ) frame->rs_code); + ra = (unsigned long ) frame->rs_code; }/* Create siginfo. */
@@ -580,13 +584,13 @@ regs->regs[5 ] = (unsigned long ) &frame->rs_info; regs->regs[6 ] = (unsigned long ) &frame->rs_uc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->rs_code; + regs->regs[31 ] = ra; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->rs_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
Index: arch/mips64/kernel/signal.c
===================================================================
RCS file: /home/cvs/linux/arch/mips64/kernel/signal.c,v retrieving revision 1.19.2.5
mips64/kernel/signal.c +9 -19
@@ -313,12 +313,6 @@if (!access_ok (VERIFY_WRITE , frame,sizeof (*frame))) goto give_sigsegv; -/* -* Set up to return from userspace. On mips64 we always use a stub -* already provided by userspace and ignore SA_RESTORER. -*/ - regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; - err |=setup_sigcontext (regs, &frame->sf_sc); err |=__copy_to_user (&frame->sf_mask, set,sizeof (*set));if (err)
@@ -331,20 +325,21 @@* a1 = 0 (should be cause) * a2 = pointer to struct sigcontext * -* $25 and c0_epc point to the signal handler, $29 points to the -* struct sigframe. +* $25 and c0_epc point to the signal handler, $29 points to +* the struct sigframe. On mips64 we always use a stub +* already provided by userspace and ignore SA_RESTORER. */ regs->regs[4 ] = signr; regs->regs[5 ] =0 ; regs->regs[6 ] = (unsigned long ) &frame->sf_sc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->sf_code; + regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->sf_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
@@ -364,12 +359,6 @@if (!access_ok (VERIFY_WRITE , frame,sizeof (*frame))) goto give_sigsegv; -/* -* Set up to return from userspace. On mips64 we always use a stub -* already provided by userspace and ignore SA_RESTORER. -*/ - regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; -/* Create siginfo. */ err |=copy_siginfo_to_user (&frame->rs_info, info);
@@ -396,19 +385,20 @@* a2 = pointer to ucontext * * $25 and c0_epc point to the signal handler, $29 points to -* the struct rt_sigframe. +* the struct rt_sigframe. On mips64 we always use a stub +* already provided by userspace and ignore SA_RESTORER. */ regs->regs[4 ] = signr; regs->regs[5 ] = (unsigned long ) &frame->rs_info; regs->regs[6 ] = (unsigned long ) &frame->rs_uc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->rs_code; + regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->rs_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
Index: arch/mips64/kernel/signal32.c
===================================================================
RCS file: /home/cvs/linux/arch/mips64/kernel/signal32.c,v retrieving revision 1.20.2.9
mips64/kernel/signal32.c +10 -6
@@ -567,6 +567,7 @@ int signr, sigset_t *set) { struct sigframe *frame; +unsigned long ra;int err =0 ; frame =get_sigframe (ka, regs,sizeof (*frame));
@@ -576,7 +577,7 @@/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags &SA_RESTORER ) - regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; + ra = (unsigned long ) ka->sa.sa_restorer;else {/* * Set up the return code ...
@@ -589,6 +590,7 @@ err |=__put_user (0x0000000c , frame->sf_code +1 );flush_cache_sigtramp ((unsigned long ) frame->sf_code); + ra = (unsigned long ) frame->sf_code; } err |=setup_sigcontext (regs, &frame->sf_sc);
@@ -610,13 +612,13 @@ regs->regs[5 ] =0 ; regs->regs[6 ] = (unsigned long ) &frame->sf_sc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->sf_code; + regs->regs[31 ] = ra; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->sf_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;
@@ -631,6 +633,7 @@ sigset_t *set, siginfo_t *info) {struct rt_sigframe32 *frame; +unsigned long ra;int err =0 ; frame =get_sigframe (ka, regs,sizeof (*frame));
@@ -640,7 +643,7 @@/* Set up to return from userspace. If provided, use a stub already in userspace. */ if (ka->sa.sa_flags &SA_RESTORER ) - regs->regs[31 ] = (unsigned long ) ka->sa.sa_restorer; + ra = (unsigned long ) ka->sa.sa_restorer;else {/* * Set up the return code ...
@@ -653,6 +656,7 @@ err |=__put_user (0x0000000c , frame->rs_code +1 );flush_cache_sigtramp ((unsigned long ) frame->rs_code); + ra = (unsigned long ) frame->rs_code; }/* Convert (siginfo_t -> siginfo_t32) and copy to user. */
@@ -687,13 +691,13 @@ regs->regs[5 ] = (unsigned long ) &frame->rs_info; regs->regs[6 ] = (unsigned long ) &frame->rs_uc; regs->regs[29 ] = (unsigned long ) frame; - regs->regs[31 ] = (unsigned long ) frame->rs_code; + regs->regs[31 ] = ra; regs->cp0_epc = regs->regs[25 ] = (unsigned long ) ka->sa.sa_handler;#if DEBUG_SIG printk ("SIG deliver (%s:%d): sp=0x%p pc=0x%lx ra=0x%p\n" , current->comm, current->pid, - frame, regs->cp0_epc, frame->rs_code); + frame, regs->cp0_epc, regs->regs[31 ]);#endif return ;