ftrace: Check for successful allocation of hash [Linux 4.19.70]

This Linux kernel change "ftrace: Check for successful allocation of hash" is included in the Linux 4.19.70 release. This change is authored by Naveen N. Rao <naveen.n.rao [at] linux.vnet.ibm.com> on Thu Jul 4 20:04:42 2019 +0530. The commit for this change in Linux stable tree is 9d98e0f (patch) which is from upstream commit 5b0022d. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 5b0022d.

ftrace: Check for successful allocation of hash

commit 5b0022dd32b7c2e15edf1827ba80aa1407edf9ff upstream.

In register_ftrace_function_probe(), we are not checking the return
value of alloc_and_copy_ftrace_hash(). The subsequent call to
ftrace_match_records() may end up dereferencing the same. Add a check to
ensure this doesn't happen.

Link: http://lkml.kernel.org/r/26e92574f25ad23e7cafa3cf5f7a819de1832cbe.1562249521.git.naveen.n.rao@linux.vnet.ibm.com

Cc: stable@vger.kernel.org
Fixes: 1ec3a81a0cf42 ("ftrace: Have each function probe use its own ftrace_ops")
Signed-off-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

There are 5 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 kernel/trace/ftrace.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 7d02a6e..fada893 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4317,6 +4317,11 @@ static void acquire_probe_locked(struct ftrace_func_probe *probe)
    old_hash = *orig_hash;
    hash = alloc_and_copy_ftrace_hash(FTRACE_HASH_DEFAULT_BITS, old_hash);

+   if (!hash) {
+       ret = -ENOMEM;
+       goto out;
+   }
+
    ret = ftrace_match_records(hash, glob, strlen(glob));

    /* Nothing found? */

Leave a Reply

Your email address will not be published. Required fields are marked *