coredump.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. #include <linux/slab.h>
  2. #include <linux/file.h>
  3. #include <linux/fdtable.h>
  4. #include <linux/mm.h>
  5. #include <linux/stat.h>
  6. #include <linux/fcntl.h>
  7. #include <linux/swap.h>
  8. #include <linux/string.h>
  9. #include <linux/init.h>
  10. #include <linux/pagemap.h>
  11. #include <linux/perf_event.h>
  12. #include <linux/highmem.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/key.h>
  15. #include <linux/personality.h>
  16. #include <linux/binfmts.h>
  17. #include <linux/coredump.h>
  18. #include <linux/utsname.h>
  19. #include <linux/pid_namespace.h>
  20. #include <linux/module.h>
  21. #include <linux/namei.h>
  22. #include <linux/mount.h>
  23. #include <linux/security.h>
  24. #include <linux/syscalls.h>
  25. #include <linux/tsacct_kern.h>
  26. #include <linux/cn_proc.h>
  27. #include <linux/audit.h>
  28. #include <linux/tracehook.h>
  29. #include <linux/kmod.h>
  30. #include <linux/fsnotify.h>
  31. #include <linux/fs_struct.h>
  32. #include <linux/pipe_fs_i.h>
  33. #include <linux/oom.h>
  34. #include <linux/compat.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/mmu_context.h>
  37. #include <asm/tlb.h>
  38. #include <asm/exec.h>
  39. #include <trace/events/task.h>
  40. #include "internal.h"
  41. #include "coredump.h"
  42. #include <trace/events/sched.h>
  43. int core_uses_pid;
  44. unsigned int core_pipe_limit;
  45. char core_pattern[CORENAME_MAX_SIZE] = "core";
  46. static int core_name_size = CORENAME_MAX_SIZE;
  47. struct core_name {
  48. char *corename;
  49. int used, size;
  50. };
  51. /* The maximal length of core_pattern is also specified in sysctl.c */
  52. static int expand_corename(struct core_name *cn, int size)
  53. {
  54. char *corename = krealloc(cn->corename, size, GFP_KERNEL);
  55. if (!corename)
  56. return -ENOMEM;
  57. if (size > core_name_size) /* racy but harmless */
  58. core_name_size = size;
  59. cn->size = ksize(corename);
  60. cn->corename = corename;
  61. return 0;
  62. }
  63. static int cn_vprintf(struct core_name *cn, const char *fmt, va_list arg)
  64. {
  65. int free, need;
  66. again:
  67. free = cn->size - cn->used;
  68. need = vsnprintf(cn->corename + cn->used, free, fmt, arg);
  69. if (need < free) {
  70. cn->used += need;
  71. return 0;
  72. }
  73. if (!expand_corename(cn, cn->size + need - free + 1))
  74. goto again;
  75. return -ENOMEM;
  76. }
  77. static int cn_printf(struct core_name *cn, const char *fmt, ...)
  78. {
  79. va_list arg;
  80. int ret;
  81. va_start(arg, fmt);
  82. ret = cn_vprintf(cn, fmt, arg);
  83. va_end(arg);
  84. return ret;
  85. }
  86. static int cn_esc_printf(struct core_name *cn, const char *fmt, ...)
  87. {
  88. int cur = cn->used;
  89. va_list arg;
  90. int ret;
  91. va_start(arg, fmt);
  92. ret = cn_vprintf(cn, fmt, arg);
  93. va_end(arg);
  94. for (; cur < cn->used; ++cur) {
  95. if (cn->corename[cur] == '/')
  96. cn->corename[cur] = '!';
  97. }
  98. return ret;
  99. }
  100. static int cn_print_exe_file(struct core_name *cn)
  101. {
  102. struct file *exe_file;
  103. char *pathbuf, *path;
  104. int ret;
  105. exe_file = get_mm_exe_file(current->mm);
  106. if (!exe_file)
  107. return cn_esc_printf(cn, "%s (path unknown)", current->comm);
  108. pathbuf = kmalloc(PATH_MAX, GFP_TEMPORARY);
  109. if (!pathbuf) {
  110. ret = -ENOMEM;
  111. goto put_exe_file;
  112. }
  113. path = d_path(&exe_file->f_path, pathbuf, PATH_MAX);
  114. if (IS_ERR(path)) {
  115. ret = PTR_ERR(path);
  116. goto free_buf;
  117. }
  118. ret = cn_esc_printf(cn, "%s", path);
  119. free_buf:
  120. kfree(pathbuf);
  121. put_exe_file:
  122. fput(exe_file);
  123. return ret;
  124. }
  125. /* format_corename will inspect the pattern parameter, and output a
  126. * name into corename, which must have space for at least
  127. * CORENAME_MAX_SIZE bytes plus one byte for the zero terminator.
  128. */
  129. static int format_corename(struct core_name *cn, struct coredump_params *cprm)
  130. {
  131. const struct cred *cred = current_cred();
  132. const char *pat_ptr = core_pattern;
  133. int ispipe = (*pat_ptr == '|');
  134. int pid_in_pattern = 0;
  135. int err = 0;
  136. cn->used = 0;
  137. cn->corename = NULL;
  138. if (expand_corename(cn, core_name_size))
  139. return -ENOMEM;
  140. cn->corename[0] = '\0';
  141. if (ispipe)
  142. ++pat_ptr;
  143. /* Repeat as long as we have more pattern to process and more output
  144. space */
  145. while (*pat_ptr) {
  146. if (*pat_ptr != '%') {
  147. err = cn_printf(cn, "%c", *pat_ptr++);
  148. } else {
  149. switch (*++pat_ptr) {
  150. /* single % at the end, drop that */
  151. case 0:
  152. goto out;
  153. /* Double percent, output one percent */
  154. case '%':
  155. err = cn_printf(cn, "%c", '%');
  156. break;
  157. /* pid */
  158. case 'p':
  159. pid_in_pattern = 1;
  160. err = cn_printf(cn, "%d",
  161. task_tgid_vnr(current));
  162. break;
  163. /* uid */
  164. case 'u':
  165. err = cn_printf(cn, "%d", cred->uid);
  166. break;
  167. /* gid */
  168. case 'g':
  169. err = cn_printf(cn, "%d", cred->gid);
  170. break;
  171. case 'd':
  172. err = cn_printf(cn, "%d",
  173. __get_dumpable(cprm->mm_flags));
  174. break;
  175. /* signal that caused the coredump */
  176. case 's':
  177. err = cn_printf(cn, "%ld", cprm->siginfo->si_signo);
  178. break;
  179. /* UNIX time of coredump */
  180. case 't': {
  181. struct timeval tv;
  182. do_gettimeofday(&tv);
  183. err = cn_printf(cn, "%lu", tv.tv_sec);
  184. break;
  185. }
  186. /* hostname */
  187. case 'h':
  188. down_read(&uts_sem);
  189. err = cn_esc_printf(cn, "%s",
  190. utsname()->nodename);
  191. up_read(&uts_sem);
  192. break;
  193. /* executable */
  194. case 'e':
  195. err = cn_esc_printf(cn, "%s", current->comm);
  196. break;
  197. case 'E':
  198. err = cn_print_exe_file(cn);
  199. break;
  200. /* core limit size */
  201. case 'c':
  202. err = cn_printf(cn, "%lu",
  203. rlimit(RLIMIT_CORE));
  204. break;
  205. default:
  206. break;
  207. }
  208. ++pat_ptr;
  209. }
  210. if (err)
  211. return err;
  212. }
  213. out:
  214. /* Backward compatibility with core_uses_pid:
  215. *
  216. * If core_pattern does not include a %p (as is the default)
  217. * and core_uses_pid is set, then .%pid will be appended to
  218. * the filename. Do not do this for piped commands. */
  219. if (!ispipe && !pid_in_pattern && core_uses_pid) {
  220. err = cn_printf(cn, ".%d", task_tgid_vnr(current));
  221. if (err)
  222. return err;
  223. }
  224. return ispipe;
  225. }
  226. static int zap_process(struct task_struct *start, int exit_code)
  227. {
  228. struct task_struct *t;
  229. int nr = 0;
  230. start->signal->group_exit_code = exit_code;
  231. start->signal->group_stop_count = 0;
  232. t = start;
  233. do {
  234. task_clear_jobctl_pending(t, JOBCTL_PENDING_MASK);
  235. if (t != current && t->mm) {
  236. sigaddset(&t->pending.signal, SIGKILL);
  237. signal_wake_up(t, 1);
  238. nr++;
  239. }
  240. } while_each_thread(start, t);
  241. return nr;
  242. }
  243. static int zap_threads(struct task_struct *tsk, struct mm_struct *mm,
  244. struct core_state *core_state, int exit_code)
  245. {
  246. struct task_struct *g, *p;
  247. unsigned long flags;
  248. int nr = -EAGAIN;
  249. spin_lock_irq(&tsk->sighand->siglock);
  250. if (!signal_group_exit(tsk->signal)) {
  251. mm->core_state = core_state;
  252. nr = zap_process(tsk, exit_code);
  253. tsk->signal->group_exit_task = tsk;
  254. /* ignore all signals except SIGKILL, see prepare_signal() */
  255. tsk->signal->flags = SIGNAL_GROUP_COREDUMP;
  256. clear_tsk_thread_flag(tsk, TIF_SIGPENDING);
  257. }
  258. spin_unlock_irq(&tsk->sighand->siglock);
  259. if (unlikely(nr < 0))
  260. return nr;
  261. tsk->flags = PF_DUMPCORE;
  262. if (atomic_read(&mm->mm_users) == nr + 1)
  263. goto done;
  264. /*
  265. * We should find and kill all tasks which use this mm, and we should
  266. * count them correctly into ->nr_threads. We don't take tasklist
  267. * lock, but this is safe wrt:
  268. *
  269. * fork:
  270. * None of sub-threads can fork after zap_process(leader). All
  271. * processes which were created before this point should be
  272. * visible to zap_threads() because copy_process() adds the new
  273. * process to the tail of init_task.tasks list, and lock/unlock
  274. * of ->siglock provides a memory barrier.
  275. *
  276. * do_exit:
  277. * The caller holds mm->mmap_sem. This means that the task which
  278. * uses this mm can't pass exit_mm(), so it can't exit or clear
  279. * its ->mm.
  280. *
  281. * de_thread:
  282. * It does list_replace_rcu(&leader->tasks, &current->tasks),
  283. * we must see either old or new leader, this does not matter.
  284. * However, it can change p->sighand, so lock_task_sighand(p)
  285. * must be used. Since p->mm != NULL and we hold ->mmap_sem
  286. * it can't fail.
  287. *
  288. * Note also that "g" can be the old leader with ->mm == NULL
  289. * and already unhashed and thus removed from ->thread_group.
  290. * This is OK, __unhash_process()->list_del_rcu() does not
  291. * clear the ->next pointer, we will find the new leader via
  292. * next_thread().
  293. */
  294. rcu_read_lock();
  295. for_each_process(g) {
  296. if (g == tsk->group_leader)
  297. continue;
  298. if (g->flags & PF_KTHREAD)
  299. continue;
  300. p = g;
  301. do {
  302. if (p->mm) {
  303. if (unlikely(p->mm == mm)) {
  304. lock_task_sighand(p, &flags);
  305. nr += zap_process(p, exit_code);
  306. p->signal->flags = SIGNAL_GROUP_EXIT;
  307. unlock_task_sighand(p, &flags);
  308. }
  309. break;
  310. }
  311. } while_each_thread(g, p);
  312. }
  313. rcu_read_unlock();
  314. done:
  315. atomic_set(&core_state->nr_threads, nr);
  316. return nr;
  317. }
  318. static int coredump_wait(int exit_code, struct core_state *core_state)
  319. {
  320. struct task_struct *tsk = current;
  321. struct mm_struct *mm = tsk->mm;
  322. int core_waiters = -EBUSY;
  323. init_completion(&core_state->startup);
  324. core_state->dumper.task = tsk;
  325. core_state->dumper.next = NULL;
  326. down_write(&mm->mmap_sem);
  327. if (!mm->core_state)
  328. core_waiters = zap_threads(tsk, mm, core_state, exit_code);
  329. up_write(&mm->mmap_sem);
  330. if (core_waiters > 0) {
  331. struct core_thread *ptr;
  332. wait_for_completion(&core_state->startup);
  333. /*
  334. * Wait for all the threads to become inactive, so that
  335. * all the thread context (extended register state, like
  336. * fpu etc) gets copied to the memory.
  337. */
  338. ptr = core_state->dumper.next;
  339. while (ptr != NULL) {
  340. wait_task_inactive(ptr->task, 0);
  341. ptr = ptr->next;
  342. }
  343. }
  344. return core_waiters;
  345. }
  346. static void coredump_finish(struct mm_struct *mm, bool core_dumped)
  347. {
  348. struct core_thread *curr, *next;
  349. struct task_struct *task;
  350. spin_lock_irq(&current->sighand->siglock);
  351. if (core_dumped && !__fatal_signal_pending(current))
  352. current->signal->group_exit_code |= 0x80;
  353. current->signal->group_exit_task = NULL;
  354. current->signal->flags = SIGNAL_GROUP_EXIT;
  355. spin_unlock_irq(&current->sighand->siglock);
  356. next = mm->core_state->dumper.next;
  357. while ((curr = next) != NULL) {
  358. next = curr->next;
  359. task = curr->task;
  360. /*
  361. * see exit_mm(), curr->task must not see
  362. * ->task == NULL before we read ->next.
  363. */
  364. smp_mb();
  365. curr->task = NULL;
  366. wake_up_process(task);
  367. }
  368. mm->core_state = NULL;
  369. }
  370. static bool dump_interrupted(void)
  371. {
  372. /*
  373. * SIGKILL or freezing() interrupt the coredumping. Perhaps we
  374. * can do try_to_freeze() and check __fatal_signal_pending(),
  375. * but then we need to teach dump_write() to restart and clear
  376. * TIF_SIGPENDING.
  377. */
  378. return signal_pending(current);
  379. }
  380. static void wait_for_dump_helpers(struct file *file)
  381. {
  382. struct pipe_inode_info *pipe = file->private_data;
  383. pipe_lock(pipe);
  384. pipe->readers++;
  385. pipe->writers--;
  386. wake_up_interruptible_sync(&pipe->wait);
  387. kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
  388. pipe_unlock(pipe);
  389. /*
  390. * We actually want wait_event_freezable() but then we need
  391. * to clear TIF_SIGPENDING and improve dump_interrupted().
  392. */
  393. wait_event_interruptible(pipe->wait, pipe->readers == 1);
  394. pipe_lock(pipe);
  395. pipe->readers--;
  396. pipe->writers++;
  397. pipe_unlock(pipe);
  398. }
  399. /*
  400. * umh_pipe_setup
  401. * helper function to customize the process used
  402. * to collect the core in userspace. Specifically
  403. * it sets up a pipe and installs it as fd 0 (stdin)
  404. * for the process. Returns 0 on success, or
  405. * PTR_ERR on failure.
  406. * Note that it also sets the core limit to 1. This
  407. * is a special value that we use to trap recursive
  408. * core dumps
  409. */
  410. static int umh_pipe_setup(struct subprocess_info *info, struct cred *new)
  411. {
  412. struct file *files[2];
  413. struct coredump_params *cp = (struct coredump_params *)info->data;
  414. int err = create_pipe_files(files, 0);
  415. if (err)
  416. return err;
  417. cp->file = files[1];
  418. err = replace_fd(0, files[0], 0);
  419. fput(files[0]);
  420. /* and disallow core files too */
  421. current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1};
  422. return err;
  423. }
  424. void do_coredump(siginfo_t *siginfo)
  425. {
  426. struct core_state core_state;
  427. struct core_name cn;
  428. struct mm_struct *mm = current->mm;
  429. struct linux_binfmt * binfmt;
  430. const struct cred *old_cred;
  431. struct cred *cred;
  432. int retval = 0;
  433. int flag = 0;
  434. int ispipe;
  435. struct files_struct *displaced;
  436. bool need_nonrelative = false;
  437. bool core_dumped = false;
  438. static atomic_t core_dump_count = ATOMIC_INIT(0);
  439. struct coredump_params cprm = {
  440. .siginfo = siginfo,
  441. .regs = signal_pt_regs(),
  442. .limit = rlimit(RLIMIT_CORE),
  443. /*
  444. * We must use the same mm->flags while dumping core to avoid
  445. * inconsistency of bit flags, since this flag is not protected
  446. * by any locks.
  447. */
  448. .mm_flags = mm->flags,
  449. };
  450. audit_core_dumps(siginfo->si_signo);
  451. binfmt = mm->binfmt;
  452. if (!binfmt || !binfmt->core_dump)
  453. goto fail;
  454. if (!__get_dumpable(cprm.mm_flags))
  455. goto fail;
  456. cred = prepare_creds();
  457. if (!cred)
  458. goto fail;
  459. /*
  460. * We cannot trust fsuid as being the "true" uid of the process
  461. * nor do we know its entire history. We only know it was tainted
  462. * so we dump it as root in mode 2, and only into a controlled
  463. * environment (pipe handler or fully qualified path).
  464. */
  465. if (__get_dumpable(cprm.mm_flags) == SUID_DUMP_ROOT) {
  466. /* Setuid core dump mode */
  467. flag = O_EXCL; /* Stop rewrite attacks */
  468. cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
  469. need_nonrelative = true;
  470. }
  471. retval = coredump_wait(siginfo->si_signo, &core_state);
  472. if (retval < 0)
  473. goto fail_creds;
  474. old_cred = override_creds(cred);
  475. ispipe = format_corename(&cn, &cprm);
  476. if (ispipe) {
  477. int dump_count;
  478. char **helper_argv;
  479. struct subprocess_info *sub_info;
  480. if (ispipe < 0) {
  481. printk(KERN_WARNING "format_corename failed\n");
  482. printk(KERN_WARNING "Aborting core\n");
  483. goto fail_unlock;
  484. }
  485. if (cprm.limit == 1) {
  486. /* See umh_pipe_setup() which sets RLIMIT_CORE = 1.
  487. *
  488. * Normally core limits are irrelevant to pipes, since
  489. * we're not writing to the file system, but we use
  490. * cprm.limit of 1 here as a speacial value, this is a
  491. * consistent way to catch recursive crashes.
  492. * We can still crash if the core_pattern binary sets
  493. * RLIM_CORE = !1, but it runs as root, and can do
  494. * lots of stupid things.
  495. *
  496. * Note that we use task_tgid_vnr here to grab the pid
  497. * of the process group leader. That way we get the
  498. * right pid if a thread in a multi-threaded
  499. * core_pattern process dies.
  500. */
  501. printk(KERN_WARNING
  502. "Process %d(%s) has RLIMIT_CORE set to 1\n",
  503. task_tgid_vnr(current), current->comm);
  504. printk(KERN_WARNING "Aborting core\n");
  505. goto fail_unlock;
  506. }
  507. cprm.limit = RLIM_INFINITY;
  508. dump_count = atomic_inc_return(&core_dump_count);
  509. if (core_pipe_limit && (core_pipe_limit < dump_count)) {
  510. printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
  511. task_tgid_vnr(current), current->comm);
  512. printk(KERN_WARNING "Skipping core dump\n");
  513. goto fail_dropcount;
  514. }
  515. helper_argv = argv_split(GFP_KERNEL, cn.corename, NULL);
  516. if (!helper_argv) {
  517. printk(KERN_WARNING "%s failed to allocate memory\n",
  518. __func__);
  519. goto fail_dropcount;
  520. }
  521. retval = -ENOMEM;
  522. sub_info = call_usermodehelper_setup(helper_argv[0],
  523. helper_argv, NULL, GFP_KERNEL,
  524. umh_pipe_setup, NULL, &cprm);
  525. if (sub_info)
  526. retval = call_usermodehelper_exec(sub_info,
  527. UMH_WAIT_EXEC);
  528. argv_free(helper_argv);
  529. if (retval) {
  530. printk(KERN_INFO "Core dump to |%s pipe failed\n",
  531. cn.corename);
  532. goto close_fail;
  533. }
  534. } else {
  535. struct inode *inode;
  536. if (cprm.limit < binfmt->min_coredump)
  537. goto fail_unlock;
  538. if (need_nonrelative && cn.corename[0] != '/') {
  539. printk(KERN_WARNING "Pid %d(%s) can only dump core "\
  540. "to fully qualified path!\n",
  541. task_tgid_vnr(current), current->comm);
  542. printk(KERN_WARNING "Skipping core dump\n");
  543. goto fail_unlock;
  544. }
  545. cprm.file = filp_open(cn.corename,
  546. O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
  547. 0600);
  548. if (IS_ERR(cprm.file))
  549. goto fail_unlock;
  550. inode = file_inode(cprm.file);
  551. if (inode->i_nlink > 1)
  552. goto close_fail;
  553. if (d_unhashed(cprm.file->f_path.dentry))
  554. goto close_fail;
  555. /*
  556. * AK: actually i see no reason to not allow this for named
  557. * pipes etc, but keep the previous behaviour for now.
  558. */
  559. if (!S_ISREG(inode->i_mode))
  560. goto close_fail;
  561. /*
  562. * Dont allow local users get cute and trick others to coredump
  563. * into their pre-created files.
  564. */
  565. if (!uid_eq(inode->i_uid, current_fsuid()))
  566. goto close_fail;
  567. if (!cprm.file->f_op || !cprm.file->f_op->write)
  568. goto close_fail;
  569. if (do_truncate(cprm.file->f_path.dentry, 0, 0, cprm.file))
  570. goto close_fail;
  571. }
  572. /* get us an unshared descriptor table; almost always a no-op */
  573. retval = unshare_files(&displaced);
  574. if (retval)
  575. goto close_fail;
  576. if (displaced)
  577. put_files_struct(displaced);
  578. if (!dump_interrupted()) {
  579. file_start_write(cprm.file);
  580. core_dumped = binfmt->core_dump(&cprm);
  581. file_end_write(cprm.file);
  582. }
  583. if (ispipe && core_pipe_limit)
  584. wait_for_dump_helpers(cprm.file);
  585. close_fail:
  586. if (cprm.file)
  587. filp_close(cprm.file, NULL);
  588. fail_dropcount:
  589. if (ispipe)
  590. atomic_dec(&core_dump_count);
  591. fail_unlock:
  592. kfree(cn.corename);
  593. coredump_finish(mm, core_dumped);
  594. revert_creds(old_cred);
  595. fail_creds:
  596. put_cred(cred);
  597. fail:
  598. return;
  599. }
  600. /*
  601. * Core dumping helper functions. These are the only things you should
  602. * do on a core-file: use only these functions to write out all the
  603. * necessary info.
  604. */
  605. int dump_write(struct file *file, const void *addr, int nr)
  606. {
  607. return !dump_interrupted() &&
  608. access_ok(VERIFY_READ, addr, nr) &&
  609. file->f_op->write(file, addr, nr, &file->f_pos) == nr;
  610. }
  611. EXPORT_SYMBOL(dump_write);
  612. int dump_seek(struct file *file, loff_t off)
  613. {
  614. int ret = 1;
  615. if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
  616. if (dump_interrupted() ||
  617. file->f_op->llseek(file, off, SEEK_CUR) < 0)
  618. return 0;
  619. } else {
  620. char *buf = (char *)get_zeroed_page(GFP_KERNEL);
  621. if (!buf)
  622. return 0;
  623. while (off > 0) {
  624. unsigned long n = off;
  625. if (n > PAGE_SIZE)
  626. n = PAGE_SIZE;
  627. if (!dump_write(file, buf, n)) {
  628. ret = 0;
  629. break;
  630. }
  631. off -= n;
  632. }
  633. free_page((unsigned long)buf);
  634. }
  635. return ret;
  636. }
  637. EXPORT_SYMBOL(dump_seek);