fprobe: Fix to allocate entry_data_size buffer with rethook instances
Masami Hiramatsu (Google)
maintainerPATCH 1/1 fprobe: Fix to allocate entry_data_size buffer with rethook instances
From: Masami Hiramatsu (Google) <[email protected]>
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.
--- kernel/trace/fprobe.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
kernel/trace/fprobe.c +6 -8
@@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) {int size; -if (num <=0 ) -return -EINVAL ; -if (!fp->exit_handler) { fp->rethook =NULL ;return 0 ;
@@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)/* Initialize rethook if needed */ if (fp->nr_maxactive) - size = fp->nr_maxactive; + num = fp->nr_maxactive;else - size = num *num_possible_cpus () *2 ; -if (size <=0 ) + num *=num_possible_cpus () *2 ; +if (num <=0 )return -EINVAL ; + size =sizeof (struct fprobe_rethook_node ) + fp->entry_data_size; +/* Initialize rethook */ - fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, -sizeof (struct fprobe_rethook_node ), size); + fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, size, num);if (IS_ERR (fp->rethook))return PTR_ERR (fp->rethook);
Masami Hiramatsu (Google)
maintainerQuoted 7 lines · On Thu, 29 Feb 2024 20:22:47 +0900 "Masami Hiramatsu (Google)"…
From: Masami Hiramatsu (Google) <[email protected]>
Fix to allocate
fprobe::entry_data_sizebuffer with rethook instances. If fprobe doesn't allocateentry_data_sizebuffer for each rethook instance, fprobe entry handler can cause a buffer overrun when storing entry data in entry handler.
Oops, missed a URL.
Quoted 1 line
Reported-by Jiri Olsa <[email protected]>
Thanks,
Quoted 45 lines
Fixes 4bbd93455659 ("kprobes: kretprobe scalability improvement")Signed-off-by Masami Hiramatsu (Google) <[email protected]>--- kernel/trace/fprobe.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)kernel/trace/fprobe.c +6
-8@@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) {int size; -if (num <=0 ) -return -EINVAL ; -if (!fp->exit_handler) { fp->rethook =NULL ;return 0 ;@@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)/* Initialize rethook if needed */ if (fp->nr_maxactive) - size = fp->nr_maxactive; + num = fp->nr_maxactive;else - size = num *num_possible_cpus () *2 ; -if (size <=0 ) + num *=num_possible_cpus () *2 ; +if (num <=0 )return -EINVAL ; + size =sizeof (struct fprobe_rethook_node ) + fp->entry_data_size; +/* Initialize rethook */ - fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, -sizeof (struct fprobe_rethook_node ), size); + fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, size, num);if (IS_ERR (fp->rethook))return PTR_ERR (fp->rethook);
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>
Quoted 8 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
Fix to allocate
fprobe::entry_data_sizebuffer with rethook instances. If fprobe doesn't allocateentry_data_sizebuffer for each rethook instance, fprobe entry handler can cause a buffer overrun when storing entry data in entry handler.Reported-by Jiri Olsa <[email protected]>
thanks,
jirka
Quoted 44 lines
Fixes 4bbd93455659 ("kprobes: kretprobe scalability improvement")Signed-off-by Masami Hiramatsu (Google) <[email protected]>--- kernel/trace/fprobe.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)kernel/trace/fprobe.c +6
-8@@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) {int size; -if (num <=0 ) -return -EINVAL ; -if (!fp->exit_handler) { fp->rethook =NULL ;return 0 ;@@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)/* Initialize rethook if needed */ if (fp->nr_maxactive) - size = fp->nr_maxactive; + num = fp->nr_maxactive;else - size = num *num_possible_cpus () *2 ; -if (size <=0 ) + num *=num_possible_cpus () *2 ; +if (num <=0 )return -EINVAL ; + size =sizeof (struct fprobe_rethook_node ) + fp->entry_data_size; +/* Initialize rethook */ - fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, -sizeof (struct fprobe_rethook_node ), size); + fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, size, num);if (IS_ERR (fp->rethook))return PTR_ERR (fp->rethook);
Masami Hiramatsu (Google)
maintainerQuoted 11 lines · On Thu, 29 Feb 2024 22:58:54 +0100 Jiri Olsa <[email protected]> wrote:
Quoted 8 lines · Masami Hiramatsu (Google)
From: Masami Hiramatsu (Google) <[email protected]>
Fix to allocate
fprobe::entry_data_sizebuffer with rethook instances. If fprobe doesn't allocateentry_data_sizebuffer for each rethook instance, fprobe entry handler can cause a buffer overrun when storing entry data in entry handler.Reported-by Jiri Olsa <[email protected]>Tested-by Jiri Olsa <[email protected]>
Thanks for testing!
Let me pick this to probe/fixes.
Thank you,
Quoted 48 lines
thanks,
jirkaQuoted 44 lines
Fixes 4bbd93455659 ("kprobes: kretprobe scalability improvement")Signed-off-by Masami Hiramatsu (Google) <[email protected]>--- kernel/trace/fprobe.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)kernel/trace/fprobe.c +6
-8@@ -189,9 +189,6 @@ static int fprobe_init_rethook(struct fprobe *fp, int num) {int size; -if (num <=0 ) -return -EINVAL ; -if (!fp->exit_handler) { fp->rethook =NULL ;return 0 ;@@ -199,15 +196,16 @@ static int fprobe_init_rethook(struct fprobe *fp, int num)/* Initialize rethook if needed */ if (fp->nr_maxactive) - size = fp->nr_maxactive; + num = fp->nr_maxactive;else - size = num *num_possible_cpus () *2 ; -if (size <=0 ) + num *=num_possible_cpus () *2 ; +if (num <=0 )return -EINVAL ; + size =sizeof (struct fprobe_rethook_node ) + fp->entry_data_size; +/* Initialize rethook */ - fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, -sizeof (struct fprobe_rethook_node ), size); + fp->rethook =rethook_alloc ((void *)fp, fprobe_exit_handler, size, num);if (IS_ERR (fp->rethook))return PTR_ERR (fp->rethook);
Signature · 1 line
Masami Hiramatsu (Google) <[email protected]>