coredump.c 17 KB

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