On Wed, 13 Aug 2025 02:30:43 +0000
Tengda Wu <wuten...@huaweicloud.com> wrote:


> The free_ftrace_hash call is just unnecessary in this context since
> we shouldn't free the global hash that we don't own. Remove this call
> to fix the issue.

This is incorrect as it is only unnecessary if it's a read.

The code above is:

        if (file->f_mode & FMODE_WRITE) {
                const int size_bits = FTRACE_HASH_DEFAULT_BITS;

                if (file->f_flags & O_TRUNC) {
                        iter->hash = alloc_ftrace_hash(size_bits);
                        clear_ftrace_mod_list(mod_head);
                } else {
                        iter->hash = alloc_and_copy_ftrace_hash(size_bits, 
hash);
                }

                if (!iter->hash) {
                        trace_parser_put(&iter->parser);
                        goto out_unlock;
                }
        } else
                iter->hash = hash;

Where if the file was open for write, the hash must be freed.


> 
> Fixes: c20489dad156 ("ftrace: Assign iter->hash to filter or notrace hashes 
> on seq read")


> Signed-off-by: Tengda Wu <wuten...@huaweicloud.com>
> ---
>  kernel/trace/ftrace.c | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 00b76d450a89..cade13595b08 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -4680,7 +4680,6 @@ ftrace_regex_open(struct ftrace_ops *ops, int flag,
>                       m->private = iter;
>               } else {
>                       /* Failed */
> -                     free_ftrace_hash(iter->hash);

The real fix is:

                        if (file->f_mode & FMODE_WRITE)
                                free_ftrace_hash(iter->hash);

-- Steve



>                       trace_parser_put(&iter->parser);
>               }
>       } else


Reply via email to