coredump.c 17 KB

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