Skip to content

Commit 6572786

Browse files
committed
fprobe: Fix to allocate entry_data_size buffer with rethook instances
Fix to allocate fprobe::entry_data_size buffer with rethook instances. If fprobe doesn't allocate entry_data_size buffer for each rethook instance, fprobe entry handler can cause a buffer overrun when storing entry data in entry handler. Link: https://lore.kernel.org/all/170920576727.107552.638161246679734051.stgit@devnote2/ Reported-by: Jiri Olsa <olsajiri@gmail.com> Closes: https://lore.kernel.org/all/Zd9eBn2FTQzYyg7L@krava/ Fixes: 4bbd934 ("kprobes: kretprobe scalability improvement") Cc: stable@vger.kernel.org Tested-by: Jiri Olsa <olsajiri@gmail.com> Signed-off-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
1 parent b401b62 commit 6572786

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

kernel/trace/fprobe.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,23 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)
189189
{
190190
int size;
191191

192-
if (num <= 0)
193-
return -EINVAL;
194-
195192
if (!fp->exit_handler) {
196193
fp->rethook = NULL;
197194
return 0;
198195
}
199196

200197
/* Initialize rethook if needed */
201198
if (fp->nr_maxactive)
202-
size = fp->nr_maxactive;
199+
num = fp->nr_maxactive;
203200
else
204-
size = num * num_possible_cpus() * 2;
205-
if (size <= 0)
201+
num *= num_possible_cpus() * 2;
202+
if (num <= 0)
206203
return -EINVAL;
207204

205+
size = sizeof(struct fprobe_rethook_node) + fp->entry_data_size;
206+
208207
/* Initialize rethook */
209-
fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler,
210-
sizeof(struct fprobe_rethook_node), size);
208+
fp->rethook = rethook_alloc((void *)fp, fprobe_exit_handler, size, num);
211209
if (IS_ERR(fp->rethook))
212210
return PTR_ERR(fp->rethook);
213211

0 commit comments

Comments
 (0)