[PATCH v14 3/9] x86/arch_prctl: Add do_arch_prctl_common

From: Kyle Huey
Date: Wed Feb 08 2017 - 03:11:31 EST


Add do_arch_prctl_common() to handle arch_prctls that are not specific to 64
bit mode. Call it from the syscall entry point, but not any of the other
callsites in the kernel, which all want one of the existing 64 bit only
arch_prctls.

Signed-off-by: Kyle Huey <khuey@xxxxxxxxxxxx>
---
arch/x86/include/asm/proto.h | 3 +++
arch/x86/kernel/process.c | 6 ++++++
arch/x86/kernel/process_64.c | 8 +++++++-
3 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/proto.h b/arch/x86/include/asm/proto.h
index f8e9194e100c..99836d9a893a 100644
--- a/arch/x86/include/asm/proto.h
+++ b/arch/x86/include/asm/proto.h
@@ -26,9 +26,12 @@ void entry_SYSCALL_compat(void);
void entry_INT80_compat(void);
#endif

void x86_configure_nx(void);
void x86_report_nx(void);

extern int reboot_force;

+long do_arch_prctl_common(struct task_struct *task, int code,
+ unsigned long cpuid_enabled);
+
#endif /* _ASM_X86_PROTO_H */
diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
index 4f76b17045cc..edf645e331d0 100644
--- a/arch/x86/kernel/process.c
+++ b/arch/x86/kernel/process.c
@@ -519,8 +519,14 @@ unsigned long get_wchan(struct task_struct *p)
}
fp = READ_ONCE_NOCHECK(*(unsigned long *)fp);
} while (count++ < 16 && p->state != TASK_RUNNING);

out:
put_task_stack(p);
return ret;
}
+
+long do_arch_prctl_common(struct task_struct *task, int code,
+ unsigned long cpuid_enabled)
+{
+ return -EINVAL;
+}
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index 83e011566db0..4db1ebcf18e0 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -619,15 +619,21 @@ long do_arch_prctl_64(struct task_struct *task, int code, unsigned long arg2)
break;
}

return ret;
}

SYSCALL_DEFINE2(arch_prctl, int, code, unsigned long, arg2)
{
- return do_arch_prctl_64(current, code, arg2);
+ long ret;
+
+ ret = do_arch_prctl_64(current, code, arg2);
+ if (ret == -EINVAL)
+ ret = do_arch_prctl_common(current, code, arg2);
+
+ return ret;
}

unsigned long KSTK_ESP(struct task_struct *task)
{
return task_pt_regs(task)->sp;
}
--
2.11.0