Skip to content

Commit c87a851

Browse files
amlutokees
authored andcommitted
x86/entry: Get rid of two-phase syscall entry work
I added two-phase syscall entry work back when the entry slow path was very slow. Nowadays, the entry slow path is fast and two-phase entry work serves no purpose. Remove it. Signed-off-by: Andy Lutomirski <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent 2f275de commit c87a851

File tree

2 files changed

+8
-82
lines changed

2 files changed

+8
-82
lines changed

arch/x86/entry/common.c

Lines changed: 8 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,13 @@ static void do_audit_syscall_entry(struct pt_regs *regs, u32 arch)
6464
}
6565

6666
/*
67-
* We can return 0 to resume the syscall or anything else to go to phase
68-
* 2. If we resume the syscall, we need to put something appropriate in
69-
* regs->orig_ax.
70-
*
71-
* NB: We don't have full pt_regs here, but regs->orig_ax and regs->ax
72-
* are fully functional.
73-
*
74-
* For phase 2's benefit, our return value is:
75-
* 0: resume the syscall
76-
* 1: go to phase 2; no seccomp phase 2 needed
77-
* anything else: go to phase 2; pass return value to seccomp
67+
* Returns the syscall nr to run (which should match regs->orig_ax) or -1
68+
* to skip the syscall.
7869
*/
79-
unsigned long syscall_trace_enter_phase1(struct pt_regs *regs, u32 arch)
70+
static long syscall_trace_enter(struct pt_regs *regs)
8071
{
72+
u32 arch = in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
73+
8174
struct thread_info *ti = pt_regs_to_thread_info(regs);
8275
unsigned long ret = 0;
8376
u32 work;
@@ -118,59 +111,9 @@ unsigned long syscall_trace_enter_phase1(struct pt_regs *regs, u32 arch)
118111
sd.args[5] = regs->bp;
119112
}
120113

121-
BUILD_BUG_ON(SECCOMP_PHASE1_OK != 0);
122-
BUILD_BUG_ON(SECCOMP_PHASE1_SKIP != 1);
123-
124-
ret = seccomp_phase1(&sd);
125-
if (ret == SECCOMP_PHASE1_SKIP) {
126-
regs->orig_ax = -1;
127-
ret = 0;
128-
} else if (ret != SECCOMP_PHASE1_OK) {
129-
return ret; /* Go directly to phase 2 */
130-
}
131-
132-
work &= ~_TIF_SECCOMP;
133-
}
134-
#endif
135-
136-
/* Do our best to finish without phase 2. */
137-
if (work == 0)
138-
return ret; /* seccomp and/or nohz only (ret == 0 here) */
139-
140-
#ifdef CONFIG_AUDITSYSCALL
141-
if (work == _TIF_SYSCALL_AUDIT) {
142-
/*
143-
* If there is no more work to be done except auditing,
144-
* then audit in phase 1. Phase 2 always audits, so, if
145-
* we audit here, then we can't go on to phase 2.
146-
*/
147-
do_audit_syscall_entry(regs, arch);
148-
return 0;
149-
}
150-
#endif
151-
152-
return 1; /* Something is enabled that we can't handle in phase 1 */
153-
}
154-
155-
/* Returns the syscall nr to run (which should match regs->orig_ax). */
156-
long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
157-
unsigned long phase1_result)
158-
{
159-
struct thread_info *ti = pt_regs_to_thread_info(regs);
160-
long ret = 0;
161-
u32 work = ACCESS_ONCE(ti->flags) & _TIF_WORK_SYSCALL_ENTRY;
162-
163-
if (IS_ENABLED(CONFIG_DEBUG_ENTRY))
164-
BUG_ON(regs != task_pt_regs(current));
165-
166-
#ifdef CONFIG_SECCOMP
167-
/*
168-
* Call seccomp_phase2 before running the other hooks so that
169-
* they can see any changes made by a seccomp tracer.
170-
*/
171-
if (phase1_result > 1 && seccomp_phase2(phase1_result)) {
172-
/* seccomp failures shouldn't expose any additional code. */
173-
return -1;
114+
ret = __secure_computing(&sd);
115+
if (ret == -1)
116+
return ret;
174117
}
175118
#endif
176119

@@ -189,17 +132,6 @@ long syscall_trace_enter_phase2(struct pt_regs *regs, u32 arch,
189132
return ret ?: regs->orig_ax;
190133
}
191134

192-
long syscall_trace_enter(struct pt_regs *regs)
193-
{
194-
u32 arch = in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
195-
unsigned long phase1_result = syscall_trace_enter_phase1(regs, arch);
196-
197-
if (phase1_result == 0)
198-
return regs->orig_ax;
199-
else
200-
return syscall_trace_enter_phase2(regs, arch, phase1_result);
201-
}
202-
203135
#define EXIT_TO_USERMODE_LOOP_FLAGS \
204136
(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
205137
_TIF_NEED_RESCHED | _TIF_USER_RETURN_NOTIFY)

arch/x86/include/asm/ptrace.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,6 @@ extern void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
8383
int error_code, int si_code);
8484

8585

86-
extern unsigned long syscall_trace_enter_phase1(struct pt_regs *, u32 arch);
87-
extern long syscall_trace_enter_phase2(struct pt_regs *, u32 arch,
88-
unsigned long phase1_result);
89-
90-
extern long syscall_trace_enter(struct pt_regs *);
91-
9286
static inline unsigned long regs_return_value(struct pt_regs *regs)
9387
{
9488
return regs->ax;

0 commit comments

Comments
 (0)