1 /*
2 * Linux Socket Filter - Kernel level socket filtering
3 *
4 * Based on the design of the Berkeley Packet Filter. The new
5 * internal format has been designed by PLUMgrid:
6 *
7 * Copyright (c) 2011 - 2014 PLUMgrid, http://plumgrid.com
8 *
9 * Authors:
10 *
11 * Jay Schulist <jschlst@samba.org>
12 * Alexei Starovoitov <ast@plumgrid.com>
13 * Daniel Borkmann <dborkman@redhat.com>
14 *
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version
18 * 2 of the License, or (at your option) any later version.
19 *
20 * Andi Kleen - Fix a few bad bugs and races.
21 * Kris Katterjohn - Added many additional checks in bpf_check_classic()
22 */
23
24 #include <linux/filter.h>
25 #include <linux/skbuff.h>
26 #include <linux/vmalloc.h>
27 #include <linux/random.h>
28 #include <linux/moduleloader.h>
29 #include <linux/bpf.h>
30 #include <linux/frame.h>
31
32 #include <asm/unaligned.h>
33
34 /* Registers */
35 #define BPF_R0 regs[BPF_REG_0]
36 #define BPF_R1 regs[BPF_REG_1]
37 #define BPF_R2 regs[BPF_REG_2]
38 #define BPF_R3 regs[BPF_REG_3]
39 #define BPF_R4 regs[BPF_REG_4]
40 #define BPF_R5 regs[BPF_REG_5]
41 #define BPF_R6 regs[BPF_REG_6]
42 #define BPF_R7 regs[BPF_REG_7]
43 #define BPF_R8 regs[BPF_REG_8]
44 #define BPF_R9 regs[BPF_REG_9]
45 #define BPF_R10 regs[BPF_REG_10]
46
47 /* Named registers */
48 #define DST regs[insn->dst_reg]
49 #define SRC regs[insn->src_reg]
50 #define FP regs[BPF_REG_FP]
51 #define ARG1 regs[BPF_REG_ARG1]
52 #define CTX regs[BPF_REG_CTX]
53 #define IMM insn->imm
54
55 /* No hurry in this branch
56 *
57 * Exported for the bpf jit load helper.
58 */
bpf_internal_load_pointer_neg_helper(const struct sk_buff * skb,int k,unsigned int size)59 void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, unsigned int size)
60 {
61 u8 *ptr = NULL;
62
63 if (k >= SKF_NET_OFF)
64 ptr = skb_network_header(skb) + k - SKF_NET_OFF;
65 else if (k >= SKF_LL_OFF)
66 ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
67
68 if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
69 return ptr;
70
71 return NULL;
72 }
73
bpf_prog_alloc(unsigned int size,gfp_t gfp_extra_flags)74 struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
75 {
76 gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
77 gfp_extra_flags;
78 struct bpf_prog_aux *aux;
79 struct bpf_prog *fp;
80
81 size = round_up(size, PAGE_SIZE);
82 fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
83 if (fp == NULL)
84 return NULL;
85
86 kmemcheck_annotate_bitfield(fp, meta);
87
88 aux = kzalloc(sizeof(*aux), GFP_KERNEL | gfp_extra_flags);
89 if (aux == NULL) {
90 vfree(fp);
91 return NULL;
92 }
93
94 fp->pages = size / PAGE_SIZE;
95 fp->aux = aux;
96 fp->aux->prog = fp;
97
98 return fp;
99 }
100 EXPORT_SYMBOL_GPL(bpf_prog_alloc);
101
bpf_prog_realloc(struct bpf_prog * fp_old,unsigned int size,gfp_t gfp_extra_flags)102 struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
103 gfp_t gfp_extra_flags)
104 {
105 gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
106 gfp_extra_flags;
107 struct bpf_prog *fp;
108
109 BUG_ON(fp_old == NULL);
110
111 size = round_up(size, PAGE_SIZE);
112 if (size <= fp_old->pages * PAGE_SIZE)
113 return fp_old;
114
115 fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
116 if (fp != NULL) {
117 kmemcheck_annotate_bitfield(fp, meta);
118
119 memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
120 fp->pages = size / PAGE_SIZE;
121 fp->aux->prog = fp;
122
123 /* We keep fp->aux from fp_old around in the new
124 * reallocated structure.
125 */
126 fp_old->aux = NULL;
127 __bpf_prog_free(fp_old);
128 }
129
130 return fp;
131 }
132
__bpf_prog_free(struct bpf_prog * fp)133 void __bpf_prog_free(struct bpf_prog *fp)
134 {
135 kfree(fp->aux);
136 vfree(fp);
137 }
138
bpf_is_jmp_and_has_target(const struct bpf_insn * insn)139 static bool bpf_is_jmp_and_has_target(const struct bpf_insn *insn)
140 {
141 return BPF_CLASS(insn->code) == BPF_JMP &&
142 /* Call and Exit are both special jumps with no
143 * target inside the BPF instruction image.
144 */
145 BPF_OP(insn->code) != BPF_CALL &&
146 BPF_OP(insn->code) != BPF_EXIT;
147 }
148
bpf_adj_branches(struct bpf_prog * prog,u32 pos,u32 delta)149 static void bpf_adj_branches(struct bpf_prog *prog, u32 pos, u32 delta)
150 {
151 struct bpf_insn *insn = prog->insnsi;
152 u32 i, insn_cnt = prog->len;
153
154 for (i = 0; i < insn_cnt; i++, insn++) {
155 if (!bpf_is_jmp_and_has_target(insn))
156 continue;
157
158 /* Adjust offset of jmps if we cross boundaries. */
159 if (i < pos && i + insn->off + 1 > pos)
160 insn->off += delta;
161 else if (i > pos + delta && i + insn->off + 1 <= pos + delta)
162 insn->off -= delta;
163 }
164 }
165
bpf_patch_insn_single(struct bpf_prog * prog,u32 off,const struct bpf_insn * patch,u32 len)166 struct bpf_prog *bpf_patch_insn_single(struct bpf_prog *prog, u32 off,
167 const struct bpf_insn *patch, u32 len)
168 {
169 u32 insn_adj_cnt, insn_rest, insn_delta = len - 1;
170 struct bpf_prog *prog_adj;
171
172 /* Since our patchlet doesn't expand the image, we're done. */
173 if (insn_delta == 0) {
174 memcpy(prog->insnsi + off, patch, sizeof(*patch));
175 return prog;
176 }
177
178 insn_adj_cnt = prog->len + insn_delta;
179
180 /* Several new instructions need to be inserted. Make room
181 * for them. Likely, there's no need for a new allocation as
182 * last page could have large enough tailroom.
183 */
184 prog_adj = bpf_prog_realloc(prog, bpf_prog_size(insn_adj_cnt),
185 GFP_USER);
186 if (!prog_adj)
187 return NULL;
188
189 prog_adj->len = insn_adj_cnt;
190
191 /* Patching happens in 3 steps:
192 *
193 * 1) Move over tail of insnsi from next instruction onwards,
194 * so we can patch the single target insn with one or more
195 * new ones (patching is always from 1 to n insns, n > 0).
196 * 2) Inject new instructions at the target location.
197 * 3) Adjust branch offsets if necessary.
198 */
199 insn_rest = insn_adj_cnt - off - len;
200
201 memmove(prog_adj->insnsi + off + len, prog_adj->insnsi + off + 1,
202 sizeof(*patch) * insn_rest);
203 memcpy(prog_adj->insnsi + off, patch, sizeof(*patch) * len);
204
205 bpf_adj_branches(prog_adj, off, insn_delta);
206
207 return prog_adj;
208 }
209
210 #ifdef CONFIG_BPF_JIT
211 struct bpf_binary_header *
bpf_jit_binary_alloc(unsigned int proglen,u8 ** image_ptr,unsigned int alignment,bpf_jit_fill_hole_t bpf_fill_ill_insns)212 bpf_jit_binary_alloc(unsigned int proglen, u8 **image_ptr,
213 unsigned int alignment,
214 bpf_jit_fill_hole_t bpf_fill_ill_insns)
215 {
216 struct bpf_binary_header *hdr;
217 unsigned int size, hole, start;
218
219 /* Most of BPF filters are really small, but if some of them
220 * fill a page, allow at least 128 extra bytes to insert a
221 * random section of illegal instructions.
222 */
223 size = round_up(proglen + sizeof(*hdr) + 128, PAGE_SIZE);
224 hdr = module_alloc(size);
225 if (hdr == NULL)
226 return NULL;
227
228 /* Fill space with illegal/arch-dep instructions. */
229 bpf_fill_ill_insns(hdr, size);
230
231 hdr->pages = size / PAGE_SIZE;
232 hole = min_t(unsigned int, size - (proglen + sizeof(*hdr)),
233 PAGE_SIZE - sizeof(*hdr));
234 start = (get_random_int() % hole) & ~(alignment - 1);
235
236 /* Leave a random number of instructions before BPF code. */
237 *image_ptr = &hdr->image[start];
238
239 return hdr;
240 }
241
bpf_jit_binary_free(struct bpf_binary_header * hdr)242 void bpf_jit_binary_free(struct bpf_binary_header *hdr)
243 {
244 module_memfree(hdr);
245 }
246
247 int bpf_jit_harden __read_mostly;
248
bpf_jit_blind_insn(const struct bpf_insn * from,const struct bpf_insn * aux,struct bpf_insn * to_buff)249 static int bpf_jit_blind_insn(const struct bpf_insn *from,
250 const struct bpf_insn *aux,
251 struct bpf_insn *to_buff)
252 {
253 struct bpf_insn *to = to_buff;
254 u32 imm_rnd = get_random_int();
255 s16 off;
256
257 BUILD_BUG_ON(BPF_REG_AX + 1 != MAX_BPF_JIT_REG);
258 BUILD_BUG_ON(MAX_BPF_REG + 1 != MAX_BPF_JIT_REG);
259
260 if (from->imm == 0 &&
261 (from->code == (BPF_ALU | BPF_MOV | BPF_K) ||
262 from->code == (BPF_ALU64 | BPF_MOV | BPF_K))) {
263 *to++ = BPF_ALU64_REG(BPF_XOR, from->dst_reg, from->dst_reg);
264 goto out;
265 }
266
267 switch (from->code) {
268 case BPF_ALU | BPF_ADD | BPF_K:
269 case BPF_ALU | BPF_SUB | BPF_K:
270 case BPF_ALU | BPF_AND | BPF_K:
271 case BPF_ALU | BPF_OR | BPF_K:
272 case BPF_ALU | BPF_XOR | BPF_K:
273 case BPF_ALU | BPF_MUL | BPF_K:
274 case BPF_ALU | BPF_MOV | BPF_K:
275 case BPF_ALU | BPF_DIV | BPF_K:
276 case BPF_ALU | BPF_MOD | BPF_K:
277 *to++ = BPF_ALU32_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
278 *to++ = BPF_ALU32_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
279 *to++ = BPF_ALU32_REG(from->code, from->dst_reg, BPF_REG_AX);
280 break;
281
282 case BPF_ALU64 | BPF_ADD | BPF_K:
283 case BPF_ALU64 | BPF_SUB | BPF_K:
284 case BPF_ALU64 | BPF_AND | BPF_K:
285 case BPF_ALU64 | BPF_OR | BPF_K:
286 case BPF_ALU64 | BPF_XOR | BPF_K:
287 case BPF_ALU64 | BPF_MUL | BPF_K:
288 case BPF_ALU64 | BPF_MOV | BPF_K:
289 case BPF_ALU64 | BPF_DIV | BPF_K:
290 case BPF_ALU64 | BPF_MOD | BPF_K:
291 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
292 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
293 *to++ = BPF_ALU64_REG(from->code, from->dst_reg, BPF_REG_AX);
294 break;
295
296 case BPF_JMP | BPF_JEQ | BPF_K:
297 case BPF_JMP | BPF_JNE | BPF_K:
298 case BPF_JMP | BPF_JGT | BPF_K:
299 case BPF_JMP | BPF_JGE | BPF_K:
300 case BPF_JMP | BPF_JSGT | BPF_K:
301 case BPF_JMP | BPF_JSGE | BPF_K:
302 case BPF_JMP | BPF_JSET | BPF_K:
303 /* Accommodate for extra offset in case of a backjump. */
304 off = from->off;
305 if (off < 0)
306 off -= 2;
307 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
308 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
309 *to++ = BPF_JMP_REG(from->code, from->dst_reg, BPF_REG_AX, off);
310 break;
311
312 case BPF_LD | BPF_ABS | BPF_W:
313 case BPF_LD | BPF_ABS | BPF_H:
314 case BPF_LD | BPF_ABS | BPF_B:
315 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
316 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
317 *to++ = BPF_LD_IND(from->code, BPF_REG_AX, 0);
318 break;
319
320 case BPF_LD | BPF_IND | BPF_W:
321 case BPF_LD | BPF_IND | BPF_H:
322 case BPF_LD | BPF_IND | BPF_B:
323 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
324 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
325 *to++ = BPF_ALU32_REG(BPF_ADD, BPF_REG_AX, from->src_reg);
326 *to++ = BPF_LD_IND(from->code, BPF_REG_AX, 0);
327 break;
328
329 case BPF_LD | BPF_IMM | BPF_DW:
330 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ aux[1].imm);
331 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
332 *to++ = BPF_ALU64_IMM(BPF_LSH, BPF_REG_AX, 32);
333 *to++ = BPF_ALU64_REG(BPF_MOV, aux[0].dst_reg, BPF_REG_AX);
334 break;
335 case 0: /* Part 2 of BPF_LD | BPF_IMM | BPF_DW. */
336 *to++ = BPF_ALU32_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ aux[0].imm);
337 *to++ = BPF_ALU32_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
338 *to++ = BPF_ALU64_REG(BPF_OR, aux[0].dst_reg, BPF_REG_AX);
339 break;
340
341 case BPF_ST | BPF_MEM | BPF_DW:
342 case BPF_ST | BPF_MEM | BPF_W:
343 case BPF_ST | BPF_MEM | BPF_H:
344 case BPF_ST | BPF_MEM | BPF_B:
345 *to++ = BPF_ALU64_IMM(BPF_MOV, BPF_REG_AX, imm_rnd ^ from->imm);
346 *to++ = BPF_ALU64_IMM(BPF_XOR, BPF_REG_AX, imm_rnd);
347 *to++ = BPF_STX_MEM(from->code, from->dst_reg, BPF_REG_AX, from->off);
348 break;
349 }
350 out:
351 return to - to_buff;
352 }
353
bpf_prog_clone_create(struct bpf_prog * fp_other,gfp_t gfp_extra_flags)354 static struct bpf_prog *bpf_prog_clone_create(struct bpf_prog *fp_other,
355 gfp_t gfp_extra_flags)
356 {
357 gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
358 gfp_extra_flags;
359 struct bpf_prog *fp;
360
361 fp = __vmalloc(fp_other->pages * PAGE_SIZE, gfp_flags, PAGE_KERNEL);
362 if (fp != NULL) {
363 kmemcheck_annotate_bitfield(fp, meta);
364
365 /* aux->prog still points to the fp_other one, so
366 * when promoting the clone to the real program,
367 * this still needs to be adapted.
368 */
369 memcpy(fp, fp_other, fp_other->pages * PAGE_SIZE);
370 }
371
372 return fp;
373 }
374
bpf_prog_clone_free(struct bpf_prog * fp)375 static void bpf_prog_clone_free(struct bpf_prog *fp)
376 {
377 /* aux was stolen by the other clone, so we cannot free
378 * it from this path! It will be freed eventually by the
379 * other program on release.
380 *
381 * At this point, we don't need a deferred release since
382 * clone is guaranteed to not be locked.
383 */
384 fp->aux = NULL;
385 __bpf_prog_free(fp);
386 }
387
bpf_jit_prog_release_other(struct bpf_prog * fp,struct bpf_prog * fp_other)388 void bpf_jit_prog_release_other(struct bpf_prog *fp, struct bpf_prog *fp_other)
389 {
390 /* We have to repoint aux->prog to self, as we don't
391 * know whether fp here is the clone or the original.
392 */
393 fp->aux->prog = fp;
394 bpf_prog_clone_free(fp_other);
395 }
396
bpf_jit_blind_constants(struct bpf_prog * prog)397 struct bpf_prog *bpf_jit_blind_constants(struct bpf_prog *prog)
398 {
399 struct bpf_insn insn_buff[16], aux[2];
400 struct bpf_prog *clone, *tmp;
401 int insn_delta, insn_cnt;
402 struct bpf_insn *insn;
403 int i, rewritten;
404
405 if (!bpf_jit_blinding_enabled())
406 return prog;
407
408 clone = bpf_prog_clone_create(prog, GFP_USER);
409 if (!clone)
410 return ERR_PTR(-ENOMEM);
411
412 insn_cnt = clone->len;
413 insn = clone->insnsi;
414
415 for (i = 0; i < insn_cnt; i++, insn++) {
416 /* We temporarily need to hold the original ld64 insn
417 * so that we can still access the first part in the
418 * second blinding run.
419 */
420 if (insn[0].code == (BPF_LD | BPF_IMM | BPF_DW) &&
421 insn[1].code == 0)
422 memcpy(aux, insn, sizeof(aux));
423
424 rewritten = bpf_jit_blind_insn(insn, aux, insn_buff);
425 if (!rewritten)
426 continue;
427
428 tmp = bpf_patch_insn_single(clone, i, insn_buff, rewritten);
429 if (!tmp) {
430 /* Patching may have repointed aux->prog during
431 * realloc from the original one, so we need to
432 * fix it up here on error.
433 */
434 bpf_jit_prog_release_other(prog, clone);
435 return ERR_PTR(-ENOMEM);
436 }
437
438 clone = tmp;
439 insn_delta = rewritten - 1;
440
441 /* Walk new program and skip insns we just inserted. */
442 insn = clone->insnsi + i + insn_delta;
443 insn_cnt += insn_delta;
444 i += insn_delta;
445 }
446
447 return clone;
448 }
449 #endif /* CONFIG_BPF_JIT */
450
451 /* Base function for offset calculation. Needs to go into .text section,
452 * therefore keeping it non-static as well; will also be used by JITs
453 * anyway later on, so do not let the compiler omit it.
454 */
__bpf_call_base(u64 r1,u64 r2,u64 r3,u64 r4,u64 r5)455 noinline u64 __bpf_call_base(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
456 {
457 return 0;
458 }
459 EXPORT_SYMBOL_GPL(__bpf_call_base);
460
461 #ifndef CONFIG_BPF_JIT_ALWAYS_ON
462 /**
463 * __bpf_prog_run - run eBPF program on a given context
464 * @ctx: is the data we are operating on
465 * @insn: is the array of eBPF instructions
466 *
467 * Decode and execute eBPF instructions.
468 */
__bpf_prog_run(const struct sk_buff * ctx,const struct bpf_insn * insn)469 static unsigned int __bpf_prog_run(const struct sk_buff *ctx, const struct bpf_insn *insn)
470 {
471 u64 stack[MAX_BPF_STACK / sizeof(u64)];
472 u64 regs[MAX_BPF_REG], tmp;
473 static const void *jumptable[256] = {
474 [0 ... 255] = &&default_label,
475 /* Now overwrite non-defaults ... */
476 /* 32 bit ALU operations */
477 [BPF_ALU | BPF_ADD | BPF_X] = &&ALU_ADD_X,
478 [BPF_ALU | BPF_ADD | BPF_K] = &&ALU_ADD_K,
479 [BPF_ALU | BPF_SUB | BPF_X] = &&ALU_SUB_X,
480 [BPF_ALU | BPF_SUB | BPF_K] = &&ALU_SUB_K,
481 [BPF_ALU | BPF_AND | BPF_X] = &&ALU_AND_X,
482 [BPF_ALU | BPF_AND | BPF_K] = &&ALU_AND_K,
483 [BPF_ALU | BPF_OR | BPF_X] = &&ALU_OR_X,
484 [BPF_ALU | BPF_OR | BPF_K] = &&ALU_OR_K,
485 [BPF_ALU | BPF_LSH | BPF_X] = &&ALU_LSH_X,
486 [BPF_ALU | BPF_LSH | BPF_K] = &&ALU_LSH_K,
487 [BPF_ALU | BPF_RSH | BPF_X] = &&ALU_RSH_X,
488 [BPF_ALU | BPF_RSH | BPF_K] = &&ALU_RSH_K,
489 [BPF_ALU | BPF_XOR | BPF_X] = &&ALU_XOR_X,
490 [BPF_ALU | BPF_XOR | BPF_K] = &&ALU_XOR_K,
491 [BPF_ALU | BPF_MUL | BPF_X] = &&ALU_MUL_X,
492 [BPF_ALU | BPF_MUL | BPF_K] = &&ALU_MUL_K,
493 [BPF_ALU | BPF_MOV | BPF_X] = &&ALU_MOV_X,
494 [BPF_ALU | BPF_MOV | BPF_K] = &&ALU_MOV_K,
495 [BPF_ALU | BPF_DIV | BPF_X] = &&ALU_DIV_X,
496 [BPF_ALU | BPF_DIV | BPF_K] = &&ALU_DIV_K,
497 [BPF_ALU | BPF_MOD | BPF_X] = &&ALU_MOD_X,
498 [BPF_ALU | BPF_MOD | BPF_K] = &&ALU_MOD_K,
499 [BPF_ALU | BPF_NEG] = &&ALU_NEG,
500 [BPF_ALU | BPF_END | BPF_TO_BE] = &&ALU_END_TO_BE,
501 [BPF_ALU | BPF_END | BPF_TO_LE] = &&ALU_END_TO_LE,
502 /* 64 bit ALU operations */
503 [BPF_ALU64 | BPF_ADD | BPF_X] = &&ALU64_ADD_X,
504 [BPF_ALU64 | BPF_ADD | BPF_K] = &&ALU64_ADD_K,
505 [BPF_ALU64 | BPF_SUB | BPF_X] = &&ALU64_SUB_X,
506 [BPF_ALU64 | BPF_SUB | BPF_K] = &&ALU64_SUB_K,
507 [BPF_ALU64 | BPF_AND | BPF_X] = &&ALU64_AND_X,
508 [BPF_ALU64 | BPF_AND | BPF_K] = &&ALU64_AND_K,
509 [BPF_ALU64 | BPF_OR | BPF_X] = &&ALU64_OR_X,
510 [BPF_ALU64 | BPF_OR | BPF_K] = &&ALU64_OR_K,
511 [BPF_ALU64 | BPF_LSH | BPF_X] = &&ALU64_LSH_X,
512 [BPF_ALU64 | BPF_LSH | BPF_K] = &&ALU64_LSH_K,
513 [BPF_ALU64 | BPF_RSH | BPF_X] = &&ALU64_RSH_X,
514 [BPF_ALU64 | BPF_RSH | BPF_K] = &&ALU64_RSH_K,
515 [BPF_ALU64 | BPF_XOR | BPF_X] = &&ALU64_XOR_X,
516 [BPF_ALU64 | BPF_XOR | BPF_K] = &&ALU64_XOR_K,
517 [BPF_ALU64 | BPF_MUL | BPF_X] = &&ALU64_MUL_X,
518 [BPF_ALU64 | BPF_MUL | BPF_K] = &&ALU64_MUL_K,
519 [BPF_ALU64 | BPF_MOV | BPF_X] = &&ALU64_MOV_X,
520 [BPF_ALU64 | BPF_MOV | BPF_K] = &&ALU64_MOV_K,
521 [BPF_ALU64 | BPF_ARSH | BPF_X] = &&ALU64_ARSH_X,
522 [BPF_ALU64 | BPF_ARSH | BPF_K] = &&ALU64_ARSH_K,
523 [BPF_ALU64 | BPF_DIV | BPF_X] = &&ALU64_DIV_X,
524 [BPF_ALU64 | BPF_DIV | BPF_K] = &&ALU64_DIV_K,
525 [BPF_ALU64 | BPF_MOD | BPF_X] = &&ALU64_MOD_X,
526 [BPF_ALU64 | BPF_MOD | BPF_K] = &&ALU64_MOD_K,
527 [BPF_ALU64 | BPF_NEG] = &&ALU64_NEG,
528 /* Call instruction */
529 [BPF_JMP | BPF_CALL] = &&JMP_CALL,
530 [BPF_JMP | BPF_CALL | BPF_X] = &&JMP_TAIL_CALL,
531 /* Jumps */
532 [BPF_JMP | BPF_JA] = &&JMP_JA,
533 [BPF_JMP | BPF_JEQ | BPF_X] = &&JMP_JEQ_X,
534 [BPF_JMP | BPF_JEQ | BPF_K] = &&JMP_JEQ_K,
535 [BPF_JMP | BPF_JNE | BPF_X] = &&JMP_JNE_X,
536 [BPF_JMP | BPF_JNE | BPF_K] = &&JMP_JNE_K,
537 [BPF_JMP | BPF_JGT | BPF_X] = &&JMP_JGT_X,
538 [BPF_JMP | BPF_JGT | BPF_K] = &&JMP_JGT_K,
539 [BPF_JMP | BPF_JGE | BPF_X] = &&JMP_JGE_X,
540 [BPF_JMP | BPF_JGE | BPF_K] = &&JMP_JGE_K,
541 [BPF_JMP | BPF_JSGT | BPF_X] = &&JMP_JSGT_X,
542 [BPF_JMP | BPF_JSGT | BPF_K] = &&JMP_JSGT_K,
543 [BPF_JMP | BPF_JSGE | BPF_X] = &&JMP_JSGE_X,
544 [BPF_JMP | BPF_JSGE | BPF_K] = &&JMP_JSGE_K,
545 [BPF_JMP | BPF_JSET | BPF_X] = &&JMP_JSET_X,
546 [BPF_JMP | BPF_JSET | BPF_K] = &&JMP_JSET_K,
547 /* Program return */
548 [BPF_JMP | BPF_EXIT] = &&JMP_EXIT,
549 /* Store instructions */
550 [BPF_STX | BPF_MEM | BPF_B] = &&STX_MEM_B,
551 [BPF_STX | BPF_MEM | BPF_H] = &&STX_MEM_H,
552 [BPF_STX | BPF_MEM | BPF_W] = &&STX_MEM_W,
553 [BPF_STX | BPF_MEM | BPF_DW] = &&STX_MEM_DW,
554 [BPF_STX | BPF_XADD | BPF_W] = &&STX_XADD_W,
555 [BPF_STX | BPF_XADD | BPF_DW] = &&STX_XADD_DW,
556 [BPF_ST | BPF_MEM | BPF_B] = &&ST_MEM_B,
557 [BPF_ST | BPF_MEM | BPF_H] = &&ST_MEM_H,
558 [BPF_ST | BPF_MEM | BPF_W] = &&ST_MEM_W,
559 [BPF_ST | BPF_MEM | BPF_DW] = &&ST_MEM_DW,
560 /* Load instructions */
561 [BPF_LDX | BPF_MEM | BPF_B] = &&LDX_MEM_B,
562 [BPF_LDX | BPF_MEM | BPF_H] = &&LDX_MEM_H,
563 [BPF_LDX | BPF_MEM | BPF_W] = &&LDX_MEM_W,
564 [BPF_LDX | BPF_MEM | BPF_DW] = &&LDX_MEM_DW,
565 [BPF_LD | BPF_ABS | BPF_W] = &&LD_ABS_W,
566 [BPF_LD | BPF_ABS | BPF_H] = &&LD_ABS_H,
567 [BPF_LD | BPF_ABS | BPF_B] = &&LD_ABS_B,
568 [BPF_LD | BPF_IND | BPF_W] = &&LD_IND_W,
569 [BPF_LD | BPF_IND | BPF_H] = &&LD_IND_H,
570 [BPF_LD | BPF_IND | BPF_B] = &&LD_IND_B,
571 [BPF_LD | BPF_IMM | BPF_DW] = &&LD_IMM_DW,
572 };
573 u32 tail_call_cnt = 0;
574 void *ptr;
575 int off;
576
577 #define CONT ({ insn++; goto select_insn; })
578 #define CONT_JMP ({ insn++; goto select_insn; })
579
580 FP = (u64) (unsigned long) &stack[ARRAY_SIZE(stack)];
581 ARG1 = (u64) (unsigned long) ctx;
582
583 select_insn:
584 goto *jumptable[insn->code];
585
586 /* ALU */
587 #define ALU(OPCODE, OP) \
588 ALU64_##OPCODE##_X: \
589 DST = DST OP SRC; \
590 CONT; \
591 ALU_##OPCODE##_X: \
592 DST = (u32) DST OP (u32) SRC; \
593 CONT; \
594 ALU64_##OPCODE##_K: \
595 DST = DST OP IMM; \
596 CONT; \
597 ALU_##OPCODE##_K: \
598 DST = (u32) DST OP (u32) IMM; \
599 CONT;
600
601 ALU(ADD, +)
602 ALU(SUB, -)
603 ALU(AND, &)
604 ALU(OR, |)
605 ALU(LSH, <<)
606 ALU(RSH, >>)
607 ALU(XOR, ^)
608 ALU(MUL, *)
609 #undef ALU
610 ALU_NEG:
611 DST = (u32) -DST;
612 CONT;
613 ALU64_NEG:
614 DST = -DST;
615 CONT;
616 ALU_MOV_X:
617 DST = (u32) SRC;
618 CONT;
619 ALU_MOV_K:
620 DST = (u32) IMM;
621 CONT;
622 ALU64_MOV_X:
623 DST = SRC;
624 CONT;
625 ALU64_MOV_K:
626 DST = IMM;
627 CONT;
628 LD_IMM_DW:
629 DST = (u64) (u32) insn[0].imm | ((u64) (u32) insn[1].imm) << 32;
630 insn++;
631 CONT;
632 ALU64_ARSH_X:
633 (*(s64 *) &DST) >>= SRC;
634 CONT;
635 ALU64_ARSH_K:
636 (*(s64 *) &DST) >>= IMM;
637 CONT;
638 ALU64_MOD_X:
639 if (unlikely(SRC == 0))
640 return 0;
641 div64_u64_rem(DST, SRC, &tmp);
642 DST = tmp;
643 CONT;
644 ALU_MOD_X:
645 if (unlikely((u32)SRC == 0))
646 return 0;
647 tmp = (u32) DST;
648 DST = do_div(tmp, (u32) SRC);
649 CONT;
650 ALU64_MOD_K:
651 div64_u64_rem(DST, IMM, &tmp);
652 DST = tmp;
653 CONT;
654 ALU_MOD_K:
655 tmp = (u32) DST;
656 DST = do_div(tmp, (u32) IMM);
657 CONT;
658 ALU64_DIV_X:
659 if (unlikely(SRC == 0))
660 return 0;
661 DST = div64_u64(DST, SRC);
662 CONT;
663 ALU_DIV_X:
664 if (unlikely((u32)SRC == 0))
665 return 0;
666 tmp = (u32) DST;
667 do_div(tmp, (u32) SRC);
668 DST = (u32) tmp;
669 CONT;
670 ALU64_DIV_K:
671 DST = div64_u64(DST, IMM);
672 CONT;
673 ALU_DIV_K:
674 tmp = (u32) DST;
675 do_div(tmp, (u32) IMM);
676 DST = (u32) tmp;
677 CONT;
678 ALU_END_TO_BE:
679 switch (IMM) {
680 case 16:
681 DST = (__force u16) cpu_to_be16(DST);
682 break;
683 case 32:
684 DST = (__force u32) cpu_to_be32(DST);
685 break;
686 case 64:
687 DST = (__force u64) cpu_to_be64(DST);
688 break;
689 }
690 CONT;
691 ALU_END_TO_LE:
692 switch (IMM) {
693 case 16:
694 DST = (__force u16) cpu_to_le16(DST);
695 break;
696 case 32:
697 DST = (__force u32) cpu_to_le32(DST);
698 break;
699 case 64:
700 DST = (__force u64) cpu_to_le64(DST);
701 break;
702 }
703 CONT;
704
705 /* CALL */
706 JMP_CALL:
707 /* Function call scratches BPF_R1-BPF_R5 registers,
708 * preserves BPF_R6-BPF_R9, and stores return value
709 * into BPF_R0.
710 */
711 BPF_R0 = (__bpf_call_base + insn->imm)(BPF_R1, BPF_R2, BPF_R3,
712 BPF_R4, BPF_R5);
713 CONT;
714
715 JMP_TAIL_CALL: {
716 struct bpf_map *map = (struct bpf_map *) (unsigned long) BPF_R2;
717 struct bpf_array *array = container_of(map, struct bpf_array, map);
718 struct bpf_prog *prog;
719 u32 index = BPF_R3;
720
721 if (unlikely(index >= array->map.max_entries))
722 goto out;
723 if (unlikely(tail_call_cnt > MAX_TAIL_CALL_CNT))
724 goto out;
725
726 tail_call_cnt++;
727
728 prog = READ_ONCE(array->ptrs[index]);
729 if (!prog)
730 goto out;
731
732 /* ARG1 at this point is guaranteed to point to CTX from
733 * the verifier side due to the fact that the tail call is
734 * handeled like a helper, that is, bpf_tail_call_proto,
735 * where arg1_type is ARG_PTR_TO_CTX.
736 */
737 insn = prog->insnsi;
738 goto select_insn;
739 out:
740 CONT;
741 }
742 /* JMP */
743 JMP_JA:
744 insn += insn->off;
745 CONT;
746 JMP_JEQ_X:
747 if (DST == SRC) {
748 insn += insn->off;
749 CONT_JMP;
750 }
751 CONT;
752 JMP_JEQ_K:
753 if (DST == IMM) {
754 insn += insn->off;
755 CONT_JMP;
756 }
757 CONT;
758 JMP_JNE_X:
759 if (DST != SRC) {
760 insn += insn->off;
761 CONT_JMP;
762 }
763 CONT;
764 JMP_JNE_K:
765 if (DST != IMM) {
766 insn += insn->off;
767 CONT_JMP;
768 }
769 CONT;
770 JMP_JGT_X:
771 if (DST > SRC) {
772 insn += insn->off;
773 CONT_JMP;
774 }
775 CONT;
776 JMP_JGT_K:
777 if (DST > IMM) {
778 insn += insn->off;
779 CONT_JMP;
780 }
781 CONT;
782 JMP_JGE_X:
783 if (DST >= SRC) {
784 insn += insn->off;
785 CONT_JMP;
786 }
787 CONT;
788 JMP_JGE_K:
789 if (DST >= IMM) {
790 insn += insn->off;
791 CONT_JMP;
792 }
793 CONT;
794 JMP_JSGT_X:
795 if (((s64) DST) > ((s64) SRC)) {
796 insn += insn->off;
797 CONT_JMP;
798 }
799 CONT;
800 JMP_JSGT_K:
801 if (((s64) DST) > ((s64) IMM)) {
802 insn += insn->off;
803 CONT_JMP;
804 }
805 CONT;
806 JMP_JSGE_X:
807 if (((s64) DST) >= ((s64) SRC)) {
808 insn += insn->off;
809 CONT_JMP;
810 }
811 CONT;
812 JMP_JSGE_K:
813 if (((s64) DST) >= ((s64) IMM)) {
814 insn += insn->off;
815 CONT_JMP;
816 }
817 CONT;
818 JMP_JSET_X:
819 if (DST & SRC) {
820 insn += insn->off;
821 CONT_JMP;
822 }
823 CONT;
824 JMP_JSET_K:
825 if (DST & IMM) {
826 insn += insn->off;
827 CONT_JMP;
828 }
829 CONT;
830 JMP_EXIT:
831 return BPF_R0;
832
833 /* STX and ST and LDX*/
834 #define LDST(SIZEOP, SIZE) \
835 STX_MEM_##SIZEOP: \
836 *(SIZE *)(unsigned long) (DST + insn->off) = SRC; \
837 CONT; \
838 ST_MEM_##SIZEOP: \
839 *(SIZE *)(unsigned long) (DST + insn->off) = IMM; \
840 CONT; \
841 LDX_MEM_##SIZEOP: \
842 DST = *(SIZE *)(unsigned long) (SRC + insn->off); \
843 CONT;
844
845 LDST(B, u8)
846 LDST(H, u16)
847 LDST(W, u32)
848 LDST(DW, u64)
849 #undef LDST
850 STX_XADD_W: /* lock xadd *(u32 *)(dst_reg + off16) += src_reg */
851 atomic_add((u32) SRC, (atomic_t *)(unsigned long)
852 (DST + insn->off));
853 CONT;
854 STX_XADD_DW: /* lock xadd *(u64 *)(dst_reg + off16) += src_reg */
855 atomic64_add((u64) SRC, (atomic64_t *)(unsigned long)
856 (DST + insn->off));
857 CONT;
858 LD_ABS_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + imm32)) */
859 off = IMM;
860 load_word:
861 /* BPF_LD + BPD_ABS and BPF_LD + BPF_IND insns are
862 * only appearing in the programs where ctx ==
863 * skb. All programs keep 'ctx' in regs[BPF_REG_CTX]
864 * == BPF_R6, bpf_convert_filter() saves it in BPF_R6,
865 * internal BPF verifier will check that BPF_R6 ==
866 * ctx.
867 *
868 * BPF_ABS and BPF_IND are wrappers of function calls,
869 * so they scratch BPF_R1-BPF_R5 registers, preserve
870 * BPF_R6-BPF_R9, and store return value into BPF_R0.
871 *
872 * Implicit input:
873 * ctx == skb == BPF_R6 == CTX
874 *
875 * Explicit input:
876 * SRC == any register
877 * IMM == 32-bit immediate
878 *
879 * Output:
880 * BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
881 */
882
883 ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
884 if (likely(ptr != NULL)) {
885 BPF_R0 = get_unaligned_be32(ptr);
886 CONT;
887 }
888
889 return 0;
890 LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
891 off = IMM;
892 load_half:
893 ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
894 if (likely(ptr != NULL)) {
895 BPF_R0 = get_unaligned_be16(ptr);
896 CONT;
897 }
898
899 return 0;
900 LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
901 off = IMM;
902 load_byte:
903 ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
904 if (likely(ptr != NULL)) {
905 BPF_R0 = *(u8 *)ptr;
906 CONT;
907 }
908
909 return 0;
910 LD_IND_W: /* BPF_R0 = ntohl(*(u32 *) (skb->data + src_reg + imm32)) */
911 off = IMM + SRC;
912 goto load_word;
913 LD_IND_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + src_reg + imm32)) */
914 off = IMM + SRC;
915 goto load_half;
916 LD_IND_B: /* BPF_R0 = *(u8 *) (skb->data + src_reg + imm32) */
917 off = IMM + SRC;
918 goto load_byte;
919
920 default_label:
921 /* If we ever reach this, we have a bug somewhere. */
922 WARN_RATELIMIT(1, "unknown opcode %02x\n", insn->code);
923 return 0;
924 }
925 STACK_FRAME_NON_STANDARD(__bpf_prog_run); /* jump table */
926
927 #else
__bpf_prog_ret0(void * ctx,const struct bpf_insn * insn)928 static unsigned int __bpf_prog_ret0(void *ctx, const struct bpf_insn *insn)
929 {
930 return 0;
931 }
932 #endif
933
bpf_prog_array_compatible(struct bpf_array * array,const struct bpf_prog * fp)934 bool bpf_prog_array_compatible(struct bpf_array *array,
935 const struct bpf_prog *fp)
936 {
937 if (!array->owner_prog_type) {
938 /* There's no owner yet where we could check for
939 * compatibility.
940 */
941 array->owner_prog_type = fp->type;
942 array->owner_jited = fp->jited;
943
944 return true;
945 }
946
947 return array->owner_prog_type == fp->type &&
948 array->owner_jited == fp->jited;
949 }
950
bpf_check_tail_call(const struct bpf_prog * fp)951 static int bpf_check_tail_call(const struct bpf_prog *fp)
952 {
953 struct bpf_prog_aux *aux = fp->aux;
954 int i;
955
956 for (i = 0; i < aux->used_map_cnt; i++) {
957 struct bpf_map *map = aux->used_maps[i];
958 struct bpf_array *array;
959
960 if (map->map_type != BPF_MAP_TYPE_PROG_ARRAY)
961 continue;
962
963 array = container_of(map, struct bpf_array, map);
964 if (!bpf_prog_array_compatible(array, fp))
965 return -EINVAL;
966 }
967
968 return 0;
969 }
970
971 /**
972 * bpf_prog_select_runtime - select exec runtime for BPF program
973 * @fp: bpf_prog populated with internal BPF program
974 * @err: pointer to error variable
975 *
976 * Try to JIT eBPF program, if JIT is not available, use interpreter.
977 * The BPF program will be executed via BPF_PROG_RUN() macro.
978 */
bpf_prog_select_runtime(struct bpf_prog * fp,int * err)979 struct bpf_prog *bpf_prog_select_runtime(struct bpf_prog *fp, int *err)
980 {
981 #ifndef CONFIG_BPF_JIT_ALWAYS_ON
982 fp->bpf_func = (void *) __bpf_prog_run;
983 #else
984 fp->bpf_func = (void *) __bpf_prog_ret0;
985 #endif
986
987 /* eBPF JITs can rewrite the program in case constant
988 * blinding is active. However, in case of error during
989 * blinding, bpf_int_jit_compile() must always return a
990 * valid program, which in this case would simply not
991 * be JITed, but falls back to the interpreter.
992 */
993 fp = bpf_int_jit_compile(fp);
994 #ifdef CONFIG_BPF_JIT_ALWAYS_ON
995 if (!fp->jited) {
996 *err = -ENOTSUPP;
997 return fp;
998 }
999 #endif
1000 bpf_prog_lock_ro(fp);
1001
1002 /* The tail call compatibility check can only be done at
1003 * this late stage as we need to determine, if we deal
1004 * with JITed or non JITed program concatenations and not
1005 * all eBPF JITs might immediately support all features.
1006 */
1007 *err = bpf_check_tail_call(fp);
1008
1009 return fp;
1010 }
1011 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
1012
bpf_prog_free_deferred(struct work_struct * work)1013 static void bpf_prog_free_deferred(struct work_struct *work)
1014 {
1015 struct bpf_prog_aux *aux;
1016
1017 aux = container_of(work, struct bpf_prog_aux, work);
1018 bpf_jit_free(aux->prog);
1019 }
1020
1021 /* Free internal BPF program */
bpf_prog_free(struct bpf_prog * fp)1022 void bpf_prog_free(struct bpf_prog *fp)
1023 {
1024 struct bpf_prog_aux *aux = fp->aux;
1025
1026 INIT_WORK(&aux->work, bpf_prog_free_deferred);
1027 schedule_work(&aux->work);
1028 }
1029 EXPORT_SYMBOL_GPL(bpf_prog_free);
1030
1031 /* RNG for unpriviledged user space with separated state from prandom_u32(). */
1032 static DEFINE_PER_CPU(struct rnd_state, bpf_user_rnd_state);
1033
bpf_user_rnd_init_once(void)1034 void bpf_user_rnd_init_once(void)
1035 {
1036 prandom_init_once(&bpf_user_rnd_state);
1037 }
1038
BPF_CALL_0(bpf_user_rnd_u32)1039 BPF_CALL_0(bpf_user_rnd_u32)
1040 {
1041 /* Should someone ever have the rather unwise idea to use some
1042 * of the registers passed into this function, then note that
1043 * this function is called from native eBPF and classic-to-eBPF
1044 * transformations. Register assignments from both sides are
1045 * different, f.e. classic always sets fn(ctx, A, X) here.
1046 */
1047 struct rnd_state *state;
1048 u32 res;
1049
1050 state = &get_cpu_var(bpf_user_rnd_state);
1051 res = prandom_u32_state(state);
1052 put_cpu_var(bpf_user_rnd_state);
1053
1054 return res;
1055 }
1056
1057 /* Weak definitions of helper functions in case we don't have bpf syscall. */
1058 const struct bpf_func_proto bpf_map_lookup_elem_proto __weak;
1059 const struct bpf_func_proto bpf_map_update_elem_proto __weak;
1060 const struct bpf_func_proto bpf_map_delete_elem_proto __weak;
1061
1062 const struct bpf_func_proto bpf_get_prandom_u32_proto __weak;
1063 const struct bpf_func_proto bpf_get_smp_processor_id_proto __weak;
1064 const struct bpf_func_proto bpf_ktime_get_ns_proto __weak;
1065
1066 const struct bpf_func_proto bpf_get_current_pid_tgid_proto __weak;
1067 const struct bpf_func_proto bpf_get_current_uid_gid_proto __weak;
1068 const struct bpf_func_proto bpf_get_current_comm_proto __weak;
1069
bpf_get_trace_printk_proto(void)1070 const struct bpf_func_proto * __weak bpf_get_trace_printk_proto(void)
1071 {
1072 return NULL;
1073 }
1074
1075 u64 __weak
bpf_event_output(struct bpf_map * map,u64 flags,void * meta,u64 meta_size,void * ctx,u64 ctx_size,bpf_ctx_copy_t ctx_copy)1076 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
1077 void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy)
1078 {
1079 return -ENOTSUPP;
1080 }
1081
1082 /* Always built-in helper functions. */
1083 const struct bpf_func_proto bpf_tail_call_proto = {
1084 .func = NULL,
1085 .gpl_only = false,
1086 .ret_type = RET_VOID,
1087 .arg1_type = ARG_PTR_TO_CTX,
1088 .arg2_type = ARG_CONST_MAP_PTR,
1089 .arg3_type = ARG_ANYTHING,
1090 };
1091
1092 /* For classic BPF JITs that don't implement bpf_int_jit_compile(). */
bpf_int_jit_compile(struct bpf_prog * prog)1093 struct bpf_prog * __weak bpf_int_jit_compile(struct bpf_prog *prog)
1094 {
1095 return prog;
1096 }
1097
bpf_helper_changes_skb_data(void * func)1098 bool __weak bpf_helper_changes_skb_data(void *func)
1099 {
1100 return false;
1101 }
1102
1103 /* To execute LD_ABS/LD_IND instructions __bpf_prog_run() may call
1104 * skb_copy_bits(), so provide a weak definition of it for NET-less config.
1105 */
skb_copy_bits(const struct sk_buff * skb,int offset,void * to,int len)1106 int __weak skb_copy_bits(const struct sk_buff *skb, int offset, void *to,
1107 int len)
1108 {
1109 return -EFAULT;
1110 }
1111