History

Merge branch 'exit-cleanups-for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace

Pull exit cleanups from Eric Biederman: "In preparation of doing something about PTRACE_EVENT_EXIT I have started cleaning up various pieces of code related to do_exit. Most of that code I did not manage to get tested and reviewed before the merge window opened but a handful of very useful cleanups are ready to be merged. The first change is simply the removal of the bdflush system call. The code has now been disabled long enough that even the oldest userspace working userspace setups anyone can find to test are fine with the bdflush system call being removed. Changing m68k fsp040_die to use force_sigsegv(SIGSEGV) instead of calling do_exit directly is interesting only in that it is nearly the most difficult of the incorrect uses of do_exit to remove. The change to the seccomp code to simply send a signal instead of calling do_coredump directly is a very nice little cleanup made possible by realizing the existing signal sending helpers were missing a little bit of functionality that is easy to provide" * 'exit-cleanups-for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace: signal/seccomp: Dump core when there is only one live thread signal/seccomp: Refactor seccomp signal and coredump generation signal/m68k: Use force_sigsegv(SIGSEGV) in fpsp040_die exit/bdflush: Remove the deprecated bdflush system call

Linus Torvalds committed 5 years ago

Commit bcfeebb2 parents 4898370 d21918e25 files · +53 −87Browse files

Unified · Split

25 files
  1. arch/alpha/kernel/syscalls/syscall.tbl +1 −1
  2. arch/arm/tools/syscall.tbl +1 −1
  3. arch/arm64/include/asm/unistd32.h +1 −1
  4. arch/ia64/kernel/syscalls/syscall.tbl +1 −1
  5. arch/m68k/fpsp040/skeleton.S +2 −1
  6. arch/m68k/kernel/syscalls/syscall.tbl +1 −1
  7. arch/m68k/kernel/traps.c +1 −1
  8. arch/microblaze/kernel/syscalls/syscall.tbl +1 −1
  9. arch/mips/kernel/syscalls/syscall_o32.tbl +1 −1
  10. arch/parisc/kernel/syscalls/syscall.tbl +1 −1
  11. arch/powerpc/kernel/syscalls/syscall.tbl +1 −1
  12. arch/s390/kernel/syscalls/syscall.tbl +1 −1
  13. arch/sh/kernel/syscalls/syscall.tbl +1 −1
  14. arch/sparc/kernel/syscalls/syscall.tbl +1 −1
  15. arch/x86/entry/syscalls/syscall_32.tbl +1 −1
  16. arch/xtensa/kernel/syscalls/syscall.tbl +1 −1
  17. fs/buffer.c +0 −27
  18. include/linux/sched/signal.h +1 −0
  19. include/linux/syscalls.h +0 −1
  20. include/uapi/linux/capability.h +0 −1
  21. kernel/seccomp.c +7 −35
  22. kernel/signal.c +26 −4
  23. kernel/sys_ni.c +0 −1
  24. tools/perf/arch/powerpc/entry/syscalls/syscall.tbl +1 −1
  25. tools/perf/arch/s390/entry/syscalls/syscall.tbl +1 −1
arch/alpha/kernel/syscalls/syscall.tbl+1−1
@@ -230,7 +230,7 @@ · 229 unmodified lines
230230 259 common osf_swapctl sys_ni_syscall
231231 260 common osf_memcntl sys_ni_syscall
232232 261 common osf_fdatasync sys_ni_syscall
233−300 common bdflush sys_bdflush
233+300 common bdflush sys_ni_syscall
234234 301 common sethae sys_sethae
235235 302 common mount sys_mount
236236 303 common old_adjtimex sys_old_adjtimex
arch/arm/tools/syscall.tbl+1−1
@@ -147,7 +147,7 @@ · 146 unmodified lines
147147 131 common quotactl sys_quotactl
148148 132 common getpgid sys_getpgid
149149 133 common fchdir sys_fchdir
150−134 common bdflush sys_bdflush
150+134 common bdflush sys_ni_syscall
151151 135 common sysfs sys_sysfs
152152 136 common personality sys_personality
153153 # 137 was sys_afs_syscall
arch/arm64/include/asm/unistd32.h+1−1
@@ -279,7 +279,7 @@ __SYSCALL(__NR_getpgid, sys_getpgid) · 278 unmodified lines
279279 #define __NR_fchdir 133
280280 __SYSCALL(__NR_fchdir, sys_fchdir)
281281 #define __NR_bdflush 134
282−__SYSCALL(__NR_bdflush, sys_bdflush)
282+__SYSCALL(__NR_bdflush, sys_ni_syscall)
283283 #define __NR_sysfs 135
284284 __SYSCALL(__NR_sysfs, sys_sysfs)
285285 #define __NR_personality 136
arch/ia64/kernel/syscalls/syscall.tbl+1−1
@@ -123,7 +123,7 @@ · 122 unmodified lines
123123 # 1135 was get_kernel_syms
124124 # 1136 was query_module
125125 113 common quotactl sys_quotactl
126−114 common bdflush sys_bdflush
126+114 common bdflush sys_ni_syscall
127127 115 common sysfs sys_sysfs
128128 116 common personality sys_personality
129129 117 common afs_syscall sys_ni_syscall
arch/m68k/fpsp040/skeleton.S+2−1
@@ -502,7 +502,8 @@ in_ea: · 501 unmodified lines
502502 .section .fixup,#alloc,#execinstr
503503 .even
504504 1:
505− jbra fpsp040_die
505+ jbsr fpsp040_die
506+ jbra .Lnotkern
506507
507508 .section __ex_table,#alloc
508509 .align 4
arch/m68k/kernel/syscalls/syscall.tbl+1−1
@@ -141,7 +141,7 @@ · 140 unmodified lines
141141 131 common quotactl sys_quotactl
142142 132 common getpgid sys_getpgid
143143 133 common fchdir sys_fchdir
144−134 common bdflush sys_bdflush
144+134 common bdflush sys_ni_syscall
145145 135 common sysfs sys_sysfs
146146 136 common personality sys_personality
147147 # 137 was afs_syscall
arch/m68k/kernel/traps.c+1−1
@@ -1150,7 +1150,7 @@ asmlinkage void set_esp0(unsigned long ssp) · 1149 unmodified lines
11501150 */
11511151 asmlinkage void fpsp040_die(void)
11521152 {
1153− do_exit(SIGSEGV);
1153+ force_sigsegv(SIGSEGV);
11541154 }
11551155
11561156 #ifdef CONFIG_M68KFPU_EMU
arch/microblaze/kernel/syscalls/syscall.tbl+1−1
@@ -141,7 +141,7 @@ · 140 unmodified lines
141141 131 common quotactl sys_quotactl
142142 132 common getpgid sys_getpgid
143143 133 common fchdir sys_fchdir
144−134 common bdflush sys_bdflush
144+134 common bdflush sys_ni_syscall
145145 135 common sysfs sys_sysfs
146146 136 common personality sys_personality
147147 137 common afs_syscall sys_ni_syscall
arch/mips/kernel/syscalls/syscall_o32.tbl+1−1
@@ -145,7 +145,7 @@ · 144 unmodified lines
145145 131 o32 quotactl sys_quotactl
146146 132 o32 getpgid sys_getpgid
147147 133 o32 fchdir sys_fchdir
148−134 o32 bdflush sys_bdflush
148+134 o32 bdflush sys_ni_syscall
149149 135 o32 sysfs sys_sysfs
150150 136 o32 personality sys_personality sys_32_personality
151151 137 o32 afs_syscall sys_ni_syscall
arch/parisc/kernel/syscalls/syscall.tbl+1−1
@@ -147,7 +147,7 @@ · 146 unmodified lines
147147 131 common quotactl sys_quotactl
148148 132 common getpgid sys_getpgid
149149 133 common fchdir sys_fchdir
150−134 common bdflush sys_bdflush
150+134 common bdflush sys_ni_syscall
151151 135 common sysfs sys_sysfs
152152 136 32 personality parisc_personality
153153 136 64 personality sys_personality
arch/powerpc/kernel/syscalls/syscall.tbl+1−1
@@ -176,7 +176,7 @@ · 175 unmodified lines
176176 131 nospu quotactl sys_quotactl
177177 132 common getpgid sys_getpgid
178178 133 common fchdir sys_fchdir
179−134 common bdflush sys_bdflush
179+134 common bdflush sys_ni_syscall
180180 135 common sysfs sys_sysfs
181181 136 32 personality sys_personality ppc64_personality
182182 136 64 personality ppc64_personality
arch/s390/kernel/syscalls/syscall.tbl+1−1
@@ -122,7 +122,7 @@ · 121 unmodified lines
122122 131 common quotactl sys_quotactl sys_quotactl
123123 132 common getpgid sys_getpgid sys_getpgid
124124 133 common fchdir sys_fchdir sys_fchdir
125−134 common bdflush sys_bdflush sys_bdflush
125+134 common bdflush sys_ni_syscall sys_ni_syscall
126126 135 common sysfs sys_sysfs sys_sysfs
127127 136 common personality sys_s390_personality sys_s390_personality
128128 137 common afs_syscall - -
arch/sh/kernel/syscalls/syscall.tbl+1−1
@@ -141,7 +141,7 @@ · 140 unmodified lines
141141 131 common quotactl sys_quotactl
142142 132 common getpgid sys_getpgid
143143 133 common fchdir sys_fchdir
144−134 common bdflush sys_bdflush
144+134 common bdflush sys_ni_syscall
145145 135 common sysfs sys_sysfs
146146 136 common personality sys_personality
147147 # 137 was afs_syscall
arch/sparc/kernel/syscalls/syscall.tbl+1−1
@@ -270,7 +270,7 @@ · 269 unmodified lines
270270 222 common delete_module sys_delete_module
271271 223 common get_kernel_syms sys_ni_syscall
272272 224 common getpgid sys_getpgid
273−225 common bdflush sys_bdflush
273+225 common bdflush sys_ni_syscall
274274 226 common sysfs sys_sysfs
275275 227 common afs_syscall sys_nis_syscall
276276 228 common setfsuid sys_setfsuid16
arch/x86/entry/syscalls/syscall_32.tbl+1−1
@@ -145,7 +145,7 @@ · 144 unmodified lines
145145 131 i386 quotactl sys_quotactl
146146 132 i386 getpgid sys_getpgid
147147 133 i386 fchdir sys_fchdir
148−134 i386 bdflush sys_bdflush
148+134 i386 bdflush sys_ni_syscall
149149 135 i386 sysfs sys_sysfs
150150 136 i386 personality sys_personality
151151 137 i386 afs_syscall
arch/xtensa/kernel/syscalls/syscall.tbl+1−1
@@ -223,7 +223,7 @@ · 222 unmodified lines
223223 # 205 was old nfsservctl
224224 205 common nfsservctl sys_ni_syscall
225225 206 common _sysctl sys_ni_syscall
226−207 common bdflush sys_bdflush
226+207 common bdflush sys_ni_syscall
227227 208 common uname sys_newuname
228228 209 common sysinfo sys_sysinfo
229229 210 common init_module sys_init_module
fs/buffer.c+0−27
@@ -3267,33 +3267,6 @@ out: · 3266 unmodified lines
32673267 }
32683268 EXPORT_SYMBOL(try_to_free_buffers);
32693269
3270−/*
3271− * There are no bdflush tunables left. But distributions are
3272− * still running obsolete flush daemons, so we terminate them here.
3273− *
3274− * Use of bdflush() is deprecated and will be removed in a future kernel.
3275− * The `flush-X' kernel threads fully replace bdflush daemons and this call.
3276− */
3277−SYSCALL_DEFINE2(bdflush, int, func, long, data)
3278−{
3279− static int msg_count;
3280−
3281− if (!capable(CAP_SYS_ADMIN))
3282− return -EPERM;
3283−
3284− if (msg_count < 5) {
3285− msg_count++;
3286− printk(KERN_INFO
3287− "warning: process `%s' used the obsolete bdflush"
3288− " system call\n", current->comm);
3289− printk(KERN_INFO "Fix your initscripts?\n");
3290− }
3291−
3292− if (func == 1)
3293− do_exit(0);
3294− return 0;
3295−}
3296−
32973270 /*
32983271 * Buffer-head allocation
32993272 */
include/linux/sched/signal.h+1−0
@@ -324,6 +324,7 @@ int force_sig_ptrace_errno_trap(int errno, void __user *addr); · 323 unmodified lines
324324 int force_sig_fault_trapno(int sig, int code, void __user *addr, int trapno);
325325 int send_sig_fault_trapno(int sig, int code, void __user *addr, int trapno,
326326 struct task_struct *t);
327+int force_sig_seccomp(int syscall, int reason, bool force_coredump);
327328
328329 extern int send_sig_info(int, struct kernel_siginfo *, struct task_struct *);
329330 extern void force_sigsegv(int sig);
include/linux/syscalls.h+0−1
@@ -1158,7 +1158,6 @@ asmlinkage long sys_ustat(unsigned dev, struct ustat __user *ubuf); · 1157 unmodified lines
11581158 asmlinkage long sys_vfork(void);
11591159 asmlinkage long sys_recv(int, void __user *, size_t, unsigned);
11601160 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
1161−asmlinkage long sys_bdflush(int func, long data);
11621161 asmlinkage long sys_oldumount(char __user *name);
11631162 asmlinkage long sys_uselib(const char __user *library);
11641163 asmlinkage long sys_sysfs(int option,
include/uapi/linux/capability.h+0−1
@@ -243,7 +243,6 @@ struct vfs_ns_cap_data { · 242 unmodified lines
243243 /* Allow examination and configuration of disk quotas */
244244 /* Allow setting the domainname */
245245 /* Allow setting the hostname */
246−/* Allow calling bdflush() */
247246 /* Allow mount() and umount(), setting up new smb connection */
248247 /* Allow some autofs root ioctls */
249248 /* Allow nfsservctl */
kernel/seccomp.c+7−35
@@ -922,30 +922,6 @@ void get_seccomp_filter(struct task_struct *tsk) · 921 unmodified lines
922922 refcount_inc(&orig->users);
923923 }
924924
925−static void seccomp_init_siginfo(kernel_siginfo_t *info, int syscall, int reason)
926−{
927− clear_siginfo(info);
928− info->si_signo = SIGSYS;
929− info->si_code = SYS_SECCOMP;
930− info->si_call_addr = (void __user *)KSTK_EIP(current);
931− info->si_errno = reason;
932− info->si_arch = syscall_get_arch(current);
933− info->si_syscall = syscall;
934−}
935−
936−/**
937− * seccomp_send_sigsys - signals the task to allow in-process syscall emulation
938− * @syscall: syscall number to send to userland
939− * @reason: filter-supplied reason code to send to userland (via si_errno)
940− *
941− * Forces a SIGSYS with a code of SYS_SECCOMP and related sigsys info.
942− */
943−static void seccomp_send_sigsys(int syscall, int reason)
944−{
945− struct kernel_siginfo info;
946− seccomp_init_siginfo(&info, syscall, reason);
947− force_sig_info(&info);
948−}
949925 #endif /* CONFIG_SECCOMP_FILTER */
950926
951927 /* For use with seccomp_actions_logged */
@@ -1218,7 +1194,7 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, · 266 unmodified lines
12181194 /* Show the handler the original registers. */
12191195 syscall_rollback(current, current_pt_regs());
12201196 /* Let the filter pass back 16 bits of data. */
1221− seccomp_send_sigsys(this_syscall, data);
1197+ force_sig_seccomp(this_syscall, data, false);
12221198 goto skip;
12231199
12241200 case SECCOMP_RET_TRACE:
@@ -1288,19 +1264,15 @@ static int __seccomp_filter(int this_syscall, const struct seccomp_data *sd, · 63 unmodified lines
12881264 seccomp_log(this_syscall, SIGSYS, action, true);
12891265 /* Dump core only if this is the last remaining thread. */
12901266 if (action != SECCOMP_RET_KILL_THREAD ||
1291− get_nr_threads(current) == 1) {
1292− kernel_siginfo_t info;
1293−
1267+ (atomic_read(&current->signal->live) == 1)) {
12941268 /* Show the original registers in the dump. */
12951269 syscall_rollback(current, current_pt_regs());
1296− /* Trigger a manual coredump since do_exit skips it. */
1297− seccomp_init_siginfo(&info, this_syscall, data);
1298− do_coredump(&info);
1299− }
1300− if (action == SECCOMP_RET_KILL_THREAD)
1270+ /* Trigger a coredump with SIGSYS */
1271+ force_sig_seccomp(this_syscall, data, true);
1272+ } else {
13011273 do_exit(SIGSYS);
1302− else
1303− do_group_exit(SIGSYS);
1274+ }
1275+ return -1; /* skip the syscall go directly to signal handling */
13041276 }
13051277
13061278 unreachable();
kernel/signal.c+26−4
@@ -54,6 +54,7 @@ · 53 unmodified lines
5454 #include <asm/unistd.h>
5555 #include <asm/siginfo.h>
5656 #include <asm/cacheflush.h>
57+#include <asm/syscall.h> /* for syscall_get_* */
5758
5859 /*
5960 * SLAB caches for signal bits.
@@ -1322,7 +1323,7 @@ int do_send_sig_info(int sig, struct kernel_siginfo *info, struct task_struct *p · 1262 unmodified lines
13221323 * that is why we also clear SIGNAL_UNKILLABLE.
13231324 */
13241325 static int
1325−force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t)
1326+force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t, bool sigdfl)
13261327 {
13271328 unsigned long int flags;
13281329 int ret, blocked, ignored;
@@ -1333,7 +1334,7 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t) · 4 unmodified lines
13331334 action = &t->sighand->action[sig-1];
13341335 ignored = action->sa.sa_handler == SIG_IGN;
13351336 blocked = sigismember(&t->blocked, sig);
1336− if (blocked || ignored) {
1337+ if (blocked || ignored || sigdfl) {
13371338 action->sa.sa_handler = SIG_DFL;
13381339 if (blocked) {
13391340 sigdelset(&t->blocked, sig);
@@ -1354,7 +1355,7 @@ force_sig_info_to_task(struct kernel_siginfo *info, struct task_struct *t) · 14 unmodified lines
13541355
13551356 int force_sig_info(struct kernel_siginfo *info)
13561357 {
1357− return force_sig_info_to_task(info, current);
1358+ return force_sig_info_to_task(info, current, false);
13581359 }
13591360
13601361 /*
@@ -1696,7 +1697,7 @@ int force_sig_fault_to_task(int sig, int code, void __user *addr · 335 unmodified lines
16961697 info.si_flags = flags;
16971698 info.si_isr = isr;
16981699 #endif
1699− return force_sig_info_to_task(&info, t);
1700+ return force_sig_info_to_task(&info, t, false);
17001701 }
17011702
17021703 int force_sig_fault(int sig, int code, void __user *addr
@@ -1798,6 +1799,27 @@ int force_sig_perf(void __user *addr, u32 type, u64 sig_data) · 95 unmodified lines
17981799 return force_sig_info(&info);
17991800 }
18001801
1802+/**
1803+ * force_sig_seccomp - signals the task to allow in-process syscall emulation
1804+ * @syscall: syscall number to send to userland
1805+ * @reason: filter-supplied reason code to send to userland (via si_errno)
1806+ *
1807+ * Forces a SIGSYS with a code of SYS_SECCOMP and related sigsys info.
1808+ */
1809+int force_sig_seccomp(int syscall, int reason, bool force_coredump)
1810+{
1811+ struct kernel_siginfo info;
1812+
1813+ clear_siginfo(&info);
1814+ info.si_signo = SIGSYS;
1815+ info.si_code = SYS_SECCOMP;
1816+ info.si_call_addr = (void __user *)KSTK_EIP(current);
1817+ info.si_errno = reason;
1818+ info.si_arch = syscall_get_arch(current);
1819+ info.si_syscall = syscall;
1820+ return force_sig_info_to_task(&info, current, force_coredump);
1821+}
1822+
18011823 /* For the crazy architectures that include trap information in
18021824 * the errno field, instead of an actual errno value.
18031825 */
kernel/sys_ni.c+0−1
@@ -416,7 +416,6 @@ COND_SYSCALL(epoll_wait); · 415 unmodified lines
416416 COND_SYSCALL(recv);
417417 COND_SYSCALL_COMPAT(recv);
418418 COND_SYSCALL(send);
419−COND_SYSCALL(bdflush);
420419 COND_SYSCALL(uselib);
421420
422421 /* optional: time32 */
tools/perf/arch/powerpc/entry/syscalls/syscall.tbl+1−1
@@ -176,7 +176,7 @@ · 175 unmodified lines
176176 131 nospu quotactl sys_quotactl
177177 132 common getpgid sys_getpgid
178178 133 common fchdir sys_fchdir
179−134 common bdflush sys_bdflush
179+134 common bdflush sys_ni_syscall
180180 135 common sysfs sys_sysfs
181181 136 32 personality sys_personality ppc64_personality
182182 136 64 personality ppc64_personality
tools/perf/arch/s390/entry/syscalls/syscall.tbl+1−1
@@ -122,7 +122,7 @@ · 121 unmodified lines
122122 131 common quotactl sys_quotactl sys_quotactl
123123 132 common getpgid sys_getpgid sys_getpgid
124124 133 common fchdir sys_fchdir sys_fchdir
125−134 common bdflush sys_bdflush sys_bdflush
125+134 common bdflush - -
126126 135 common sysfs sys_sysfs sys_sysfs
127127 136 common personality sys_s390_personality sys_s390_personality
128128 137 common afs_syscall - -