2021-09-18 12:12:52

by CGEL

[permalink] [raw]
Subject: [PATCH] Add pointer check

From: Yang Guang <[email protected]>

The buf->stop_te pointer may be NULL.
Accessing buf->stop_te->stop buf->stop_te->intr might occer segmentation
fault. Same as buf->intr_te.

Signed-off-by: Yang Guang <[email protected]>
---
arch/x86/events/intel/pt.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/pt.c b/arch/x86/events/intel/pt.c
index 7f406c14715f..ec1c644fc83f 100644
--- a/arch/x86/events/intel/pt.c
+++ b/arch/x86/events/intel/pt.c
@@ -1118,9 +1118,12 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf,
buf->intr_te = pt_topa_prev_entry(buf, buf->intr_te);
}

- buf->stop_te->stop = 1;
- buf->stop_te->intr = 1;
- buf->intr_te->intr = 1;
+ if (buf->stop_te) {
+ buf->stop_te->stop = 1;
+ buf->stop_te->intr = 1;
+ }
+ if (buf->intr_te)
+ buf->intr_te->intr = 1;

return 0;
}
--
2.25.1


2021-09-20 15:20:16

by Alexander Shishkin

[permalink] [raw]
Subject: Re: [PATCH] Add pointer check

[email protected] writes:

> From: Yang Guang <[email protected]>
>
> The buf->stop_te pointer may be NULL.

[...]

> --- a/arch/x86/events/intel/pt.c
> +++ b/arch/x86/events/intel/pt.c
> @@ -1118,9 +1118,12 @@ static int pt_buffer_reset_markers(struct pt_buffer *buf,
> buf->intr_te = pt_topa_prev_entry(buf, buf->intr_te);
> }
>
> - buf->stop_te->stop = 1;
> - buf->stop_te->intr = 1;
> - buf->intr_te->intr = 1;
> + if (buf->stop_te) {

It really can't be NULL at this point.

Regards,
--
Alex