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