Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp1019232ybe; Wed, 4 Sep 2019 11:13:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzkYCfRuOIYBv6TdZmTHcYq4GZkQ1rumfM4DEQmwziyNIrNj6Bo9RP4dJ3mVOCvm5P7cvuB X-Received: by 2002:a17:902:8492:: with SMTP id c18mr42881602plo.279.1567620837588; Wed, 04 Sep 2019 11:13:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567620837; cv=none; d=google.com; s=arc-20160816; b=csq/WA3I2S+HloAojqnPK7UgxwKO2WunB9urm5hvdHcBkGbnVqESxjeWJwlfukemT+ loVMw7XZzFY6v309aCxqu+PzaJiB8OBKLL/6INmWfq+G1xjPIAlecd2NX6SPjKTn/IEG fZCLh6yzYlJ+YyvdgnfN1jXU8ruIWLc10n/mC4kDw5K4jxrMV23IycRtPWsJ0vpjwiu/ eNL6vaNskINnOUSijvkrb2kJe4FfR/BXt2b5v32ruBVdt78d5u3SetWs/Ih6nES69gbR 8S88yBIcT01EAhtBf3UzFkHlRphViOB2o8hnql5wFAqBZjx02UFQmxxBes6n51pQ8PkU GaYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vnq3i1f+ULGotYGXZ9mgLXk1q0ulFA0v3u9y3H3YzAk=; b=A+e18Ewd20ePpJ4w/qXtxtDifV/GfkPOGiyd+o8rQ5kUjzk5cpLKsXIlJ/yZXV12gl V+6gqEk0f0CdTBEKClXGKeFusG8X47lpgFI2nh7fYJdbMNR0ZJMkc00lYEzRtuistS81 wKy1JhmPpmo8i+/wMw2E5mgDWywt8nE5XSrsWqsu+34W3uaAZNVHuOophONtUfKp5MnA 8USR7y4Kulc7u82KoukB8kyM7ej4kf5XR5pYXEphNHOv2rC4Co3Qq/z5FlA15gRHYJcG m7z+yC48Te+Rga0puK74OkB4EzOHgZ7IdkI81zty+2Yw0ZvmPbzlmFFUzD+KXAOGphPR O5QA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1775vYJM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si5858056plb.392.2019.09.04.11.13.41; Wed, 04 Sep 2019 11:13:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=1775vYJM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390472AbfIDSMP (ORCPT + 99 others); Wed, 4 Sep 2019 14:12:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:56556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389430AbfIDSMO (ORCPT ); Wed, 4 Sep 2019 14:12:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 90EFF206BA; Wed, 4 Sep 2019 18:12:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567620734; bh=eI4hu126fYRh5Hr+mcgswRePFZWBv0CZeGJNpqBIEi8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1775vYJMthaefgC91PVVRlaQNda5ru8rkpp/l8dYZEjfK3JTWw7UqjiqTgGZeyNv8 D+7IGEhnmRaRJYb6hWM2EXoUqJ9bDzK0M2YRst5NYoGDuSaxN0zW2HE95GRcZuFkWW CBEXygmYH9qjuOXHMDpO8XIgzenN6vK0Lj707Hy8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Naveen N. Rao" , "Steven Rostedt (VMware)" Subject: [PATCH 5.2 075/143] ftrace: Fix NULL pointer dereference in t_probe_next() Date: Wed, 4 Sep 2019 19:53:38 +0200 Message-Id: <20190904175316.987390600@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190904175314.206239922@linuxfoundation.org> References: <20190904175314.206239922@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Naveen N. Rao commit 7bd46644ea0f6021dc396a39a8bfd3a58f6f1f9f upstream. LTP testsuite on powerpc results in the below crash: Unable to handle kernel paging request for data at address 0x00000000 Faulting instruction address: 0xc00000000029d800 Oops: Kernel access of bad area, sig: 11 [#1] LE SMP NR_CPUS=2048 NUMA PowerNV ... CPU: 68 PID: 96584 Comm: cat Kdump: loaded Tainted: G W NIP: c00000000029d800 LR: c00000000029dac4 CTR: c0000000001e6ad0 REGS: c0002017fae8ba10 TRAP: 0300 Tainted: G W MSR: 9000000000009033 CR: 28022422 XER: 20040000 CFAR: c00000000029d90c DAR: 0000000000000000 DSISR: 40000000 IRQMASK: 0 ... NIP [c00000000029d800] t_probe_next+0x60/0x180 LR [c00000000029dac4] t_mod_start+0x1a4/0x1f0 Call Trace: [c0002017fae8bc90] [c000000000cdbc40] _cond_resched+0x10/0xb0 (unreliable) [c0002017fae8bce0] [c0000000002a15b0] t_start+0xf0/0x1c0 [c0002017fae8bd30] [c0000000004ec2b4] seq_read+0x184/0x640 [c0002017fae8bdd0] [c0000000004a57bc] sys_read+0x10c/0x300 [c0002017fae8be30] [c00000000000b388] system_call+0x5c/0x70 The test (ftrace_set_ftrace_filter.sh) is part of ftrace stress tests and the crash happens when the test does 'cat $TRACING_PATH/set_ftrace_filter'. The address points to the second line below, in t_probe_next(), where filter_hash is dereferenced: hash = iter->probe->ops.func_hash->filter_hash; size = 1 << hash->size_bits; This happens due to a race with register_ftrace_function_probe(). A new ftrace_func_probe is created and added into the func_probes list in trace_array under ftrace_lock. However, before initializing the filter, we drop ftrace_lock, and re-acquire it after acquiring regex_lock. If another process is trying to read set_ftrace_filter, it will be able to acquire ftrace_lock during this window and it will end up seeing a NULL filter_hash. Fix this by just checking for a NULL filter_hash in t_probe_next(). If the filter_hash is NULL, then this probe is just being added and we can simply return from here. Link: http://lkml.kernel.org/r/05e021f757625cbbb006fad41380323dbe4e3b43.1562249521.git.naveen.n.rao@linux.vnet.ibm.com Cc: stable@vger.kernel.org Fixes: 7b60f3d876156 ("ftrace: Dynamically create the probe ftrace_ops for the trace_array") Signed-off-by: Naveen N. Rao Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/ftrace.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -3095,6 +3095,10 @@ t_probe_next(struct seq_file *m, loff_t hnd = &iter->probe_entry->hlist; hash = iter->probe->ops.func_hash->filter_hash; + + if (!hash) + return NULL; + size = 1 << hash->size_bits; retry: