Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
db68ce1
Documentation
arch
alpha
arc
arm
arm64
avr32
blackfin
c6x
cris
frv
h8300
hexagon
ia64
m32r
m68k
metag
microblaze
mips
mn10300
nios2
openrisc
parisc
powerpc
s390
score
sh
sparc
tile
um
configs
drivers
include
kernel
skas
Makefile
clone.c
mmu.c
process.c
syscall.c
uaccess.c
Makefile
asm-offsets.c
config.c.in
dyn.lds.S
early_printk.c
exec.c
exitcode.c
gmon_syms.c
gprof_syms.c
initrd.c
irq.c
kmsg_dump.c
ksyms.c
maccess.c
mem.c
physmem.c
process.c
ptrace.c
reboot.c
sigio.c
signal.c
stacktrace.c
syscall.c
sysrq.c
time.c
tlb.c
trap.c
um_arch.c
umid.c
uml.lds.S
vmlinux.lds.S
os-Linux
scripts
.gitignore
Kconfig.char
Kconfig.common
Kconfig.debug
Kconfig.net
Kconfig.rest
Kconfig.um
Makefile
Makefile-os-Linux
Makefile-skas
unicore32
x86
xtensa
.gitignore
Kconfig
block
certs
crypto
drivers
firmware
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
tools
usr
virt
.cocciconfig
.get_maintainer.ignore
.gitattributes
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
Kconfig
MAINTAINERS
Makefile
README
Breadcrumbs
linux
/
arch
/
um
/
kernel
/
skas
/
uaccess.c
Copy path
Blame
Blame
Latest commit
History
History
246 lines (197 loc) · 4.78 KB
Breadcrumbs
linux
/
arch
/
um
/
kernel
/
skas
/
uaccess.c
Top
File metadata and controls
Code
Blame
246 lines (197 loc) · 4.78 KB
Raw
/* * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com) * Licensed under the GPL */ #include <linux/err.h> #include <linux/highmem.h> #include <linux/mm.h> #include <linux/module.h> #include <linux/sched.h> #include <asm/current.h> #include <asm/page.h> #include <asm/pgtable.h> #include <kern_util.h> #include <os.h> pte_t *virt_to_pte(struct mm_struct *mm, unsigned long addr) { pgd_t *pgd; pud_t *pud; pmd_t *pmd; if (mm == NULL) return NULL; pgd = pgd_offset(mm, addr); if (!pgd_present(*pgd)) return NULL; pud = pud_offset(pgd, addr); if (!pud_present(*pud)) return NULL; pmd = pmd_offset(pud, addr); if (!pmd_present(*pmd)) return NULL; return pte_offset_kernel(pmd, addr); } static pte_t *maybe_map(unsigned long virt, int is_write) { pte_t *pte = virt_to_pte(current->mm, virt); int err, dummy_code; if ((pte == NULL) || !pte_present(*pte) || (is_write && !pte_write(*pte))) { err = handle_page_fault(virt, 0, is_write, 1, &dummy_code); if (err) return NULL; pte = virt_to_pte(current->mm, virt); } if (!pte_present(*pte)) pte = NULL; return pte; } static int do_op_one_page(unsigned long addr, int len, int is_write, int (*op)(unsigned long addr, int len, void *arg), void *arg) { jmp_buf buf; struct page *page; pte_t *pte; int n, faulted; pte = maybe_map(addr, is_write); if (pte == NULL) return -1; page = pte_page(*pte); addr = (unsigned long) kmap_atomic(page) + (addr & ~PAGE_MASK); current->thread.fault_catcher = &buf; faulted = UML_SETJMP(&buf); if (faulted == 0) n = (*op)(addr, len, arg); else n = -1; current->thread.fault_catcher = NULL; kunmap_atomic((void *)addr); return n; } static long buffer_op(unsigned long addr, int len, int is_write, int (*op)(unsigned long, int, void *), void *arg) { long size, remain, n; size = min(PAGE_ALIGN(addr) - addr, (unsigned long) len); remain = len; n = do_op_one_page(addr, size, is_write, op, arg); if (n != 0) { remain = (n < 0 ? remain : 0); goto out; } addr += size; remain -= size; if (remain == 0) goto out; while (addr < ((addr + remain) & PAGE_MASK)) { n = do_op_one_page(addr, PAGE_SIZE, is_write, op, arg); if (n != 0) { remain = (n < 0 ? remain : 0); goto out; } addr += PAGE_SIZE; remain -= PAGE_SIZE; } if (remain == 0) goto out; n = do_op_one_page(addr, remain, is_write, op, arg); if (n != 0) { remain = (n < 0 ? remain : 0); goto out; } return 0; out: return remain; } static int copy_chunk_from_user(unsigned long from, int len, void *arg) { unsigned long *to_ptr = arg, to = *to_ptr; memcpy((void *) to, (void *) from, len); *to_ptr += len; return 0; } long __copy_from_user(void *to, const void __user *from, unsigned long n) { if (uaccess_kernel()) { memcpy(to, (__force void*)from, n); return 0; } return buffer_op((unsigned long) from, n, 0, copy_chunk_from_user, &to); } EXPORT_SYMBOL(__copy_from_user); static int copy_chunk_to_user(unsigned long to, int len, void *arg) { unsigned long *from_ptr = arg, from = *from_ptr; memcpy((void *) to, (void *) from, len); *from_ptr += len; return 0; } long __copy_to_user(void __user *to, const void *from, unsigned long n) { if (uaccess_kernel()) { memcpy((__force void *) to, from, n); return 0; } return buffer_op((unsigned long) to, n, 1, copy_chunk_to_user, &from); } EXPORT_SYMBOL(__copy_to_user); static int strncpy_chunk_from_user(unsigned long from, int len, void *arg) { char **to_ptr = arg, *to = *to_ptr; int n; strncpy(to, (void *) from, len); n = strnlen(to, len); *to_ptr += n; if (n < len) return 1; return 0; } long __strncpy_from_user(char *dst, const char __user *src, long count) { long n; char *ptr = dst; if (uaccess_kernel()) { strncpy(dst, (__force void *) src, count); return strnlen(dst, count); } n = buffer_op((unsigned long) src, count, 0, strncpy_chunk_from_user, &ptr); if (n != 0) return -EFAULT; return strnlen(dst, count); } EXPORT_SYMBOL(__strncpy_from_user); static int clear_chunk(unsigned long addr, int len, void *unused) { memset((void *) addr, 0, len); return 0; } unsigned long __clear_user(void __user *mem, unsigned long len) { if (uaccess_kernel()) { memset((__force void*)mem, 0, len); return 0; } return buffer_op((unsigned long) mem, len, 1, clear_chunk, NULL); } EXPORT_SYMBOL(__clear_user); static int strnlen_chunk(unsigned long str, int len, void *arg) { int *len_ptr = arg, n; n = strnlen((void *) str, len); *len_ptr += n; if (n < len) return 1; return 0; } long __strnlen_user(const void __user *str, long len) { int count = 0, n; if (uaccess_kernel()) return strnlen((__force char*)str, len) + 1; n = buffer_op((unsigned long) str, len, 0, strnlen_chunk, &count); if (n == 0) return count + 1; return 0; } EXPORT_SYMBOL(__strnlen_user);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
You can’t perform that action at this time.