Skip to content

Commit c1bc09d

Browse files
committed
Merge tag 'probes-fixes-v6.12-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull uprobe fix from Masami Hiramatsu: - uprobe: avoid out-of-bounds memory access of fetching args Uprobe trace events can cause out-of-bounds memory access when fetching user-space data which is bigger than one page, because it does not check the local CPU buffer size when reading the data. This checks the read data size and cut it down to the local CPU buffer size. * tag 'probes-fixes-v6.12-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: uprobe: avoid out-of-bounds memory access of fetching args
2 parents 7166c32 + 373b933 commit c1bc09d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

kernel/trace/trace_uprobe.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ struct uprobe_cpu_buffer {
875875
};
876876
static struct uprobe_cpu_buffer __percpu *uprobe_cpu_buffer;
877877
static int uprobe_buffer_refcnt;
878+
#define MAX_UCB_BUFFER_SIZE PAGE_SIZE
878879

879880
static int uprobe_buffer_init(void)
880881
{
@@ -979,6 +980,11 @@ static struct uprobe_cpu_buffer *prepare_uprobe_buffer(struct trace_uprobe *tu,
979980
ucb = uprobe_buffer_get();
980981
ucb->dsize = tu->tp.size + dsize;
981982

983+
if (WARN_ON_ONCE(ucb->dsize > MAX_UCB_BUFFER_SIZE)) {
984+
ucb->dsize = MAX_UCB_BUFFER_SIZE;
985+
dsize = MAX_UCB_BUFFER_SIZE - tu->tp.size;
986+
}
987+
982988
store_trace_args(ucb->buf, &tu->tp, regs, NULL, esize, dsize);
983989

984990
*ucbp = ucb;
@@ -998,9 +1004,6 @@ static void __uprobe_trace_func(struct trace_uprobe *tu,
9981004

9991005
WARN_ON(call != trace_file->event_call);
10001006

1001-
if (WARN_ON_ONCE(ucb->dsize > PAGE_SIZE))
1002-
return;
1003-
10041007
if (trace_trigger_soft_disabled(trace_file))
10051008
return;
10061009

0 commit comments

Comments
 (0)