Skip to content

Commit 6bbfa44

Browse files
mhiramatrostedt
authored andcommitted
kprobes: Limit max data_size of the kretprobe instances
The 'kprobe::data_size' is unsigned, thus it can not be negative. But if user sets it enough big number (e.g. (size_t)-8), the result of 'data_size + sizeof(struct kretprobe_instance)' becomes smaller than sizeof(struct kretprobe_instance) or zero. In result, the kretprobe_instance are allocated without enough memory, and kretprobe accesses outside of allocated memory. To avoid this issue, introduce a max limitation of the kretprobe::data_size. 4KB per instance should be OK. Link: https://lkml.kernel.org/r/163836995040.432120.10322772773821182925.stgit@devnote2 Cc: [email protected] Fixes: f47cd9b ("kprobes: kretprobe user entry-handler") Reported-by: zhangyue <[email protected]> Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent f25667e commit 6bbfa44

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

include/linux/kprobes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ struct kretprobe {
153153
struct kretprobe_holder *rph;
154154
};
155155

156+
#define KRETPROBE_MAX_DATA_SIZE 4096
157+
156158
struct kretprobe_instance {
157159
union {
158160
struct freelist_node freelist;

kernel/kprobes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2086,6 +2086,9 @@ int register_kretprobe(struct kretprobe *rp)
20862086
}
20872087
}
20882088

2089+
if (rp->data_size > KRETPROBE_MAX_DATA_SIZE)
2090+
return -E2BIG;
2091+
20892092
rp->kp.pre_handler = pre_handler_kretprobe;
20902093
rp->kp.post_handler = NULL;
20912094

0 commit comments

Comments
 (0)