Daniel Borkmann
5ccb071e97
bpf: fix overflow in prog accounting
...
Commit aaac3ba95e ("bpf: charge user for creation of BPF maps and
programs") made a wrong assumption of charging against prog->pages.
Unlike map->pages, prog->pages are still subject to change when we
need to expand the program through bpf_prog_realloc().
This can for example happen during verification stage when we need to
expand and rewrite parts of the program. Should the required space
cross a page boundary, then prog->pages is not the same anymore as
its original value that we used to bpf_prog_charge_memlock() on. Thus,
we'll hit a wrap-around during bpf_prog_uncharge_memlock() when prog
is freed eventually. I noticed this that despite having unlimited
memlock, programs suddenly refused to load with EPERM error due to
insufficient memlock.
There are two ways to fix this issue. One would be to add a cached
variable to struct bpf_prog that takes a snapshot of prog->pages at the
time of charging. The other approach is to also account for resizes. I
chose to go with the latter for a couple of reasons: i) We want accounting
rather to be more accurate instead of further fooling limits, ii) adding
yet another page counter on struct bpf_prog would also be a waste just
for this purpose. We also do want to charge as early as possible to
avoid going into the verifier just to find out later on that we crossed
limits. The only place that needs to be fixed is bpf_prog_realloc(),
since only here we expand the program, so we try to account for the
needed delta and should we fail, call-sites check for outcome anyway.
On cBPF to eBPF migrations, we don't grab a reference to the user as
they are charged differently. With that in place, my test case worked
fine.
Fixes: aaac3ba95e ("bpf: charge user for creation of BPF maps and programs")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-12-17 21:27:44 -05:00
..
bpf
bpf: fix overflow in prog accounting
2016-12-17 21:27:44 -05:00
configs
config: android: enable CONFIG_SECCOMP
2016-10-11 15:06:32 -07:00
debug
events
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
2016-12-10 16:21:55 -05:00
gcov
gcov: add support for gcc version >= 6
2016-07-15 14:54:27 +09:00
irq
genirq: Use irq type from irqdata instead of irqdesc
2016-11-08 15:15:19 +01:00
livepatch
livepatch/module: make TAINT_LIVEPATCH module-specific
2016-08-26 14:42:08 +02:00
locking
lockdep: Fix report formatting
2016-12-06 10:40:08 +01:00
power
PM / sleep: fix device reference leak in test_suspend
2016-11-02 05:10:04 +01:00
printk
Revert "printk: make reading the kernel log flush pending lines"
2016-11-14 09:31:52 -08:00
rcu
This adds a new gcc plugin named "latent_entropy". It is designed to
2016-10-15 10:03:15 -07:00
sched
sched/autogroup: Fix 64-bit kernel nice level adjustment
2016-11-24 05:45:02 +01:00
time
clocksource: export the clocks_calc_mult_shift to use by timestamp code
2016-12-07 11:13:48 -05:00
trace
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
2016-11-22 13:27:16 -05:00
.gitignore
acct.c
async.c
audit.c
audit: remove useless synchronize_net()
2016-12-01 11:29:02 -05:00
audit.h
Merge branch 'stable-4.8' of git://git.infradead.org/users/pcmoore/audit
2016-07-29 17:54:17 -07:00
audit_fsnotify.c
audit_tree.c
audit: cleanup prune_tree_thread
2016-04-04 09:46:47 -04:00
audit_watch.c
Merge branch 'stable-4.8' of git://git.infradead.org/users/pcmoore/audit
2016-09-01 15:55:56 -07:00
auditfilter.c
audit: add fields to exclude filter by reusing user filter
2016-06-27 11:01:00 -04:00
auditsc.c
Merge branch 'stable-4.9' of git://git.infradead.org/users/pcmoore/audit
2016-10-04 14:21:41 -07:00
backtracetest.c
bounds.c
capability.c
kernel: Add noaudit variant of ns_capable()
2016-06-06 20:16:18 +10:00
cgroup.c
cgroup: add support for eBPF programs
2016-11-25 16:25:52 -05:00
cgroup_freezer.c
cgroup_pids.c
cgroup: Use lld instead of ld when printing pids controller events_limit
2016-06-21 15:03:36 -04:00
compat.c
configs.c
context_tracking.c
cpu.c
cpu/hotplug: Use distinct name for cpu_hotplug.dep_map
2016-10-16 11:09:32 +02:00
cpu_pm.c
cpuset.c
Merge branch 'for-4.9' of git://git.kernel.org/pub/scm/linux/kernel/git/tj/cgroup
2016-10-14 12:18:50 -07:00
crash_dump.c
cred.c
cred: Reject inodes with invalid ids in set_create_file_as()
2016-06-30 18:05:09 -05:00
delayacct.c
dma.c
elfcore.c
exec_domain.c
exit.c
sched/autogroup: Do not use autogroup->tg in zombie threads
2016-11-22 12:33:43 +01:00
extable.c
fork.c
fork: Add task stack refcounting sanity check and prevent premature task stack freeing
2016-11-01 07:39:17 +01:00
freezer.c
freezer, oom: check TIF_MEMDIE on the correct task
2016-07-28 16:07:41 -07:00
futex.c
futex: Add some more function commentry
2016-09-05 17:20:18 +02:00
futex_compat.c
groups.c
cred: simpler, 1D supplementary groups
2016-10-07 18:46:30 -07:00
hung_task.c
hung_task: allow hung_task_panic when hung_task_warnings is 0
2016-10-11 15:06:33 -07:00
irq_work.c
jump_label.c
powerpc updates for 4.8 #2
2016-08-05 09:00:54 -04:00
kallsyms.c
kallsyms: add support for relative offsets in kallsyms address table
2016-03-15 16:55:16 -07:00
kcmp.c
Kconfig.freezer
Kconfig.hz
Kconfig.locks
Kconfig.preempt
kcov.c
kcov: add missing #include <linux/sched.h>
2016-12-07 17:10:00 -08:00
kexec.c
kexec: allow architectures to override boot mapping
2016-08-02 19:35:27 -04:00
kexec_core.c
kexec: add restriction on kexec_load() segment sizes
2016-08-02 19:35:31 -04:00
kexec_file.c
kexec: fix double-free when failing to relocate the purgatory
2016-09-01 17:52:01 -07:00
kexec_internal.h
kmod.c
kprobes.c
kprobes: include <asm/sections.h> instead of <asm-generic/sections.h>
2016-10-11 15:06:31 -07:00
ksysfs.c
kexec: add a kexec_crash_loaded() function
2016-08-02 19:35:30 -04:00
kthread.c
kthread: better support freezable kthread workers
2016-10-11 15:06:33 -07:00
latencytop.c
Makefile
userns: Add per user namespace sysctls.
2016-08-08 13:18:58 -05:00
membarrier.c
memremap.c
mm: fix cache mode of dax pmd mappings
2016-09-09 17:34:46 -07:00
module-internal.h
module.c
Re-enable CONFIG_MODVERSIONS in a slightly weaker form
2016-11-29 16:01:30 -08:00
module_signing.c
KEYS: Move the point of trust determination to __key_link()
2016-04-11 22:43:43 +01:00
notifier.c
nsproxy.c
padata.c
padata: Convert to hotplug state machine
2016-09-19 21:44:30 +02:00
panic.c
x86/panic: replace smp_send_stop() with kdump friendly version in panic path
2016-10-11 15:06:32 -07:00
params.c
pid.c
remove lots of IS_ERR_VALUE abuses
2016-05-27 15:26:11 -07:00
pid_namespace.c
Merge branch 'nsfs-ioctls' into HEAD
2016-09-22 20:00:36 -05:00
profile.c
profile: Convert to hotplug state machine
2016-07-15 10:41:42 +02:00
ptrace.c
mm: replace access_process_vm() write parameter with gup_flags
2016-10-19 08:31:25 -07:00
range.c
reboot.c
relay.c
relay: Use irq_work instead of plain timer for deferred wakeup
2016-10-11 15:06:32 -07:00
resource.c
/proc/iomem: only expose physical resource addresses to privileged users
2016-04-14 12:56:09 -07:00
seccomp.c
bpf: drop unnecessary context cast from BPF_PROG_RUN
2016-11-27 20:38:47 -05:00
signal.c
x86/signal: Add SA_{X32,IA32}_ABI sa_flags
2016-09-14 21:28:11 +02:00
smp.c
smp: Allocate smp_call_on_cpu() workqueue on stack too
2016-09-22 14:49:10 +02:00
smpboot.c
kthread/smpboot: do not park in kthread_create_on_cpu()
2016-10-11 15:06:33 -07:00
smpboot.h
softirq.c
softirq: Display IRQ_POLL for irq-poll statistics
2016-10-21 15:45:47 -06:00
stacktrace.c
stop_machine.c
Merge branch 'sched-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
2016-10-03 13:39:00 -07:00
sys.c
prctl: make PR_SET_THP_DISABLE wait for mmap_sem killable
2016-05-23 17:04:14 -07:00
sys_ni.c
x86/pkeys: Fix pkeys build breakage for some non-x86 arches
2016-09-13 14:41:36 +02:00
sysctl.c
Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
2016-10-10 13:04:49 -07:00
sysctl_binary.c
kernel/sysctl_binary.c: use generic UUID library
2016-05-20 17:58:30 -07:00
task_work.c
task_work: use READ_ONCE/lockless_dereference, avoid pi_lock if !task_works
2016-08-02 19:35:02 -04:00
taskstats.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net
2016-11-15 10:54:36 -05:00
test_kprobes.c
torture.c
torture: Convert torture_shutdown() to hrtimer
2016-08-22 10:01:49 -07:00
tracepoint.c
kernel/...: convert pr_warning to pr_warn
2016-03-22 15:36:02 -07:00
tsacct.c
ucount.c
mntns: Add a limit on the number of mount namespaces.
2016-08-31 07:28:35 -05:00
uid16.c
cred: simpler, 1D supplementary groups
2016-10-07 18:46:30 -07:00
up.c
smp: Add function to execute a function synchronously on a CPU
2016-09-05 13:52:39 +02:00
user-return-notifier.c
user.c
user_namespace.c
Merge branch 'nsfs-ioctls' into HEAD
2016-09-22 20:00:36 -05:00
utsname.c
Merge branch 'nsfs-ioctls' into HEAD
2016-09-22 20:00:36 -05:00
utsname_sysctl.c
watchdog.c
Revert "perf/x86/intel, watchdog: Switch NMI watchdog to ref cycles on x86"
2016-07-10 20:58:36 +02:00
workqueue.c
kthread: rename probe_kthread_data() to kthread_probe_data()
2016-10-11 15:06:33 -07:00
workqueue_internal.h