lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1576217705-2634-1-git-send-email-sunguoyun@loongson.cn>
Date:   Fri, 13 Dec 2019 14:15:05 +0800
From:   Guoyun Sun <sunguoyun@...ngson.cn>
To:     Ralf Baechle <ralf@...ux-mips.org>,
        Paul Burton <paulburton@...nel.org>,
        James Hogan <jhogan@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Christian Brauner <christian.brauner@...ntu.com>,
        Arnd Bergmann <arnd@...db.de>,
        Heiko Carstens <heiko.carstens@...ibm.com>,
        David Howells <dhowells@...hat.com>,
        Firoz Khan <firoz.khan@...aro.org>,
        Geert Uytterhoeven <geert@...ux-m68k.org>,
        Catalin Marinas <catalin.marinas@....com>,
        linux-mips@...r.kernel.org, linux-kernel@...r.kernel.org
Cc:     Guoyun Sun <sunguoyun@...ngson.cn>
Subject: [PATCH] MIPS: Add get_thread_area syscall

CRIU(https://criu.org/) tools will dump TLS(Thread Local Storage) by
get_thread_area during checkpoint and restore TLS by set_thread_area during
restore. without syscall get_thread_area, criu restore will fail on MIPS
platform.because a variable with GCC __thread is invalid.

The following function will be called when criu restore

static inline void restore_tls(tls_t *ptls) {
        asm volatile(
                     "move $4, %0                                   \n"
                     "li $2,  "__stringify(__NR_set_thread_area)"  \n"
                     "syscall                                       \n"
                     :
                     : "r"(*ptls)
                     : "$4","$2","memory");

With this patch, the *ptls can be obtained by get_thread_area on MIPS
platform when criu checkpoint. just like this:

static inline void arch_get_tls(tls_t *ptls)
{
	asm volatile(
		     "move $4, %0				    \n"
		     "li $2,  "__stringify(__NR_get_thread_area)"  \n"
		     "syscall					    \n"
		     :
		     : "r"(ptls)
		     : "$4","$2","memory");

}

Signed-off-by: Guoyun Sun <sunguoyun@...ngson.cn>
---
 arch/mips/kernel/syscall.c                | 10 ++++++++++
 arch/mips/kernel/syscalls/syscall_n32.tbl |  1 +
 arch/mips/kernel/syscalls/syscall_n64.tbl |  1 +
 arch/mips/kernel/syscalls/syscall_o32.tbl |  1 +
 4 files changed, 13 insertions(+)

diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index c333e57..20bf4c5 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -94,6 +94,16 @@ SYSCALL_DEFINE1(set_thread_area, unsigned long, addr)
 	return 0;
 }
 
+SYSCALL_DEFINE1(get_thread_area, unsigned long __user *, u_info)
+{
+	struct thread_info *ti = task_thread_info(current);
+
+	if (copy_to_user(u_info, &(ti->tp_value), sizeof(ti->tp_value)))
+		return -EFAULT;
+
+	return 0;
+}
+
 static inline int mips_atomic_set(unsigned long addr, unsigned long new)
 {
 	unsigned long old, tmp;
diff --git a/arch/mips/kernel/syscalls/syscall_n32.tbl b/arch/mips/kernel/syscalls/syscall_n32.tbl
index e7c5ab3..7da83d0 100644
--- a/arch/mips/kernel/syscalls/syscall_n32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n32.tbl
@@ -374,3 +374,4 @@
 433	n32	fspick				sys_fspick
 434	n32	pidfd_open			sys_pidfd_open
 435	n32	clone3				__sys_clone3
+436	n32	get_thread_area			sys_get_thread_area
diff --git a/arch/mips/kernel/syscalls/syscall_n64.tbl b/arch/mips/kernel/syscalls/syscall_n64.tbl
index 13cd665..4f04bf0 100644
--- a/arch/mips/kernel/syscalls/syscall_n64.tbl
+++ b/arch/mips/kernel/syscalls/syscall_n64.tbl
@@ -350,3 +350,4 @@
 433	n64	fspick				sys_fspick
 434	n64	pidfd_open			sys_pidfd_open
 435	n64	clone3				__sys_clone3
+436	n64	get_thread_area			sys_get_thread_area
diff --git a/arch/mips/kernel/syscalls/syscall_o32.tbl b/arch/mips/kernel/syscalls/syscall_o32.tbl
index 353539e..9d79abe 100644
--- a/arch/mips/kernel/syscalls/syscall_o32.tbl
+++ b/arch/mips/kernel/syscalls/syscall_o32.tbl
@@ -423,3 +423,4 @@
 433	o32	fspick				sys_fspick
 434	o32	pidfd_open			sys_pidfd_open
 435	o32	clone3				__sys_clone3
+436	o32	get_thread_area			sys_get_thread_area
-- 
2.1.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ