Skip to content

Commit 27e462c

Browse files
committed
Merge tag 'xtensa-20230523' of https://github.com/jcmvbkbc/linux-xtensa
Pull Xtensa fixes from Max Filippov: - fix signal delivery to FDPIC process - add __bswap{si,di}2 helpers * tag 'xtensa-20230523' of https://github.com/jcmvbkbc/linux-xtensa: xtensa: add __bswap{si,di}2 helpers xtensa: fix signal delivery to FDPIC process
2 parents 5fe326b + 034f4a7 commit 27e462c

File tree

5 files changed

+69
-9
lines changed

5 files changed

+69
-9
lines changed

arch/xtensa/kernel/signal.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,19 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set,
343343
struct rt_sigframe *frame;
344344
int err = 0, sig = ksig->sig;
345345
unsigned long sp, ra, tp, ps;
346+
unsigned long handler = (unsigned long)ksig->ka.sa.sa_handler;
347+
unsigned long handler_fdpic_GOT = 0;
346348
unsigned int base;
349+
bool fdpic = IS_ENABLED(CONFIG_BINFMT_ELF_FDPIC) &&
350+
(current->personality & FDPIC_FUNCPTRS);
351+
352+
if (fdpic) {
353+
unsigned long __user *fdpic_func_desc =
354+
(unsigned long __user *)handler;
355+
if (__get_user(handler, &fdpic_func_desc[0]) ||
356+
__get_user(handler_fdpic_GOT, &fdpic_func_desc[1]))
357+
return -EFAULT;
358+
}
347359

348360
sp = regs->areg[1];
349361

@@ -373,29 +385,34 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set,
373385
err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
374386

375387
if (ksig->ka.sa.sa_flags & SA_RESTORER) {
376-
ra = (unsigned long)ksig->ka.sa.sa_restorer;
388+
if (fdpic) {
389+
unsigned long __user *fdpic_func_desc =
390+
(unsigned long __user *)ksig->ka.sa.sa_restorer;
391+
392+
err |= __get_user(ra, fdpic_func_desc);
393+
} else {
394+
ra = (unsigned long)ksig->ka.sa.sa_restorer;
395+
}
377396
} else {
378397

379398
/* Create sys_rt_sigreturn syscall in stack frame */
380399

381400
err |= gen_return_code(frame->retcode);
382-
383-
if (err) {
384-
return -EFAULT;
385-
}
386401
ra = (unsigned long) frame->retcode;
387402
}
388403

389-
/*
404+
if (err)
405+
return -EFAULT;
406+
407+
/*
390408
* Create signal handler execution context.
391409
* Return context not modified until this point.
392410
*/
393411

394412
/* Set up registers for signal handler; preserve the threadptr */
395413
tp = regs->threadptr;
396414
ps = regs->ps;
397-
start_thread(regs, (unsigned long) ksig->ka.sa.sa_handler,
398-
(unsigned long) frame);
415+
start_thread(regs, handler, (unsigned long)frame);
399416

400417
/* Set up a stack frame for a call4 if userspace uses windowed ABI */
401418
if (ps & PS_WOE_MASK) {
@@ -413,6 +430,8 @@ static int setup_frame(struct ksignal *ksig, sigset_t *set,
413430
regs->areg[base + 4] = (unsigned long) &frame->uc;
414431
regs->threadptr = tp;
415432
regs->ps = ps;
433+
if (fdpic)
434+
regs->areg[base + 11] = handler_fdpic_GOT;
416435

417436
pr_debug("SIG rt deliver (%s:%d): signal=%d sp=%p pc=%08lx\n",
418437
current->comm, current->pid, sig, frame, regs->pc);

arch/xtensa/kernel/xtensa_ksyms.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ EXPORT_SYMBOL(empty_zero_page);
5656
*/
5757
extern long long __ashrdi3(long long, int);
5858
extern long long __ashldi3(long long, int);
59+
extern long long __bswapdi2(long long);
60+
extern int __bswapsi2(int);
5961
extern long long __lshrdi3(long long, int);
6062
extern int __divsi3(int, int);
6163
extern int __modsi3(int, int);
@@ -66,6 +68,8 @@ extern unsigned long long __umulsidi3(unsigned int, unsigned int);
6668

6769
EXPORT_SYMBOL(__ashldi3);
6870
EXPORT_SYMBOL(__ashrdi3);
71+
EXPORT_SYMBOL(__bswapdi2);
72+
EXPORT_SYMBOL(__bswapsi2);
6973
EXPORT_SYMBOL(__lshrdi3);
7074
EXPORT_SYMBOL(__divsi3);
7175
EXPORT_SYMBOL(__modsi3);

arch/xtensa/lib/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55

66
lib-y += memcopy.o memset.o checksum.o \
7-
ashldi3.o ashrdi3.o lshrdi3.o \
7+
ashldi3.o ashrdi3.o bswapdi2.o bswapsi2.o lshrdi3.o \
88
divsi3.o udivsi3.o modsi3.o umodsi3.o mulsi3.o umulsidi3.o \
99
usercopy.o strncpy_user.o strnlen_user.o
1010
lib-$(CONFIG_PCI) += pci-auto.o

arch/xtensa/lib/bswapdi2.S

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 */
2+
#include <linux/linkage.h>
3+
#include <asm/asmmacro.h>
4+
#include <asm/core.h>
5+
6+
ENTRY(__bswapdi2)
7+
8+
abi_entry_default
9+
ssai 8
10+
srli a4, a2, 16
11+
src a4, a4, a2
12+
src a4, a4, a4
13+
src a4, a2, a4
14+
srli a2, a3, 16
15+
src a2, a2, a3
16+
src a2, a2, a2
17+
src a2, a3, a2
18+
mov a3, a4
19+
abi_ret_default
20+
21+
ENDPROC(__bswapdi2)

arch/xtensa/lib/bswapsi2.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later WITH GCC-exception-2.0 */
2+
#include <linux/linkage.h>
3+
#include <asm/asmmacro.h>
4+
#include <asm/core.h>
5+
6+
ENTRY(__bswapsi2)
7+
8+
abi_entry_default
9+
ssai 8
10+
srli a3, a2, 16
11+
src a3, a3, a2
12+
src a3, a3, a3
13+
src a2, a2, a3
14+
abi_ret_default
15+
16+
ENDPROC(__bswapsi2)

0 commit comments

Comments
 (0)