From patchwork Tue Nov 17 13:05:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 325504 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:5ce:0:0:0:0 with SMTP id l14csp4190877ils; Tue, 17 Nov 2020 06:01:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwf1HFu+nLi7JWn+S6POjztM/5C4QGFUtVNgaI2zVkbM8QetGDxGnqkkxlf0//t0WMeBXb3 X-Received: by 2002:a17:906:eb46:: with SMTP id mc6mr2559106ejb.54.1605621719078; Tue, 17 Nov 2020 06:01:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621719; cv=none; d=google.com; s=arc-20160816; b=EuyYfgera+EUISynYXvIWmK0LCr2CvGhh/DrvYesgj1zvBvAhaYjoVgCvUJuZKiQTN ByarqTyaW4r8b8uEO3gQEuNweGq7S/TgbAg1++r2H7CY4vwueB47sY5RcyULynTzmXZA KhzX6lGVyHf8XULb9AE77T5QV/U7B+kAUE9QZvxEC8DnEapoYZxwfw5HMGLbDXlOQs01 vXUsMKWfcXTYJzT0ftARa6fWXVdLaxni0Qu9vYbT0pYWizFUttXMW8CLipYtl8bczYYm spNri1iY2J2BGssOEcjm0NKnb6cdD2CJKuCw0TyUZsONW/kS7399Q+yxYe5CiP7bfMIC 5MUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zcRcTlUuZwmygsVrsyno13OCauYp1NQYfWXQbX84pc4=; b=OdrkyTgkYHbMWbZIjB0L3lgvSMZF1ivngNd+bMqqZ0EyVcQYen68F6OTjYZ1XOCfQr A/CKg3y/RBzAHi2Q8/EKJrTDmMAbM1ZZl4TcaIBY9dDORju5fIqG4jWh/d6ePzdK6xc4 CHm2BPjGqKKEv0YUI+j98NbuONbOgwekdviF9uxcMbJITqDpwxGEP2Y4GhiddNZqClzw 8ssmzZo4OvDiXef+fhRMoSDV9LU31pPjERYCbGWsh5ouVc/Ck2765bZ3l3zGTpGDowhW tTMaq+JBHJzEYjtMXyfFfIm1yjIiYylxcfPEVQp6gmBZ3Mzn6FJe91Re7IiIy4B5aQ7U tPCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qRYxdSU3; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o25si15056752edz.20.2020.11.17.06.01.58; Tue, 17 Nov 2020 06:01:59 -0800 (PST) Received-SPF: pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qRYxdSU3; spf=pass (google.com: domain of stable-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=stable-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731321AbgKQOAL (ORCPT + 14 others); Tue, 17 Nov 2020 09:00:11 -0500 Received: from mail.kernel.org ([198.145.29.99]:48952 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729221AbgKQNQx (ORCPT ); Tue, 17 Nov 2020 08:16:53 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (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 7A9D2241A5; Tue, 17 Nov 2020 13:16:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619012; bh=sH4NVl1JYehCiLD5BPGU+ZvloVF/+5g8V5eNToulZNI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qRYxdSU3HqsIuzisqkcPlcY1INHyJVfQp0kWy0pPU0Xi+ix3CvIY84bNdbw9FYI0P 8VO0pG/FXAnDD4+bks6strnoW3pHXpn7CsoHvNtKAwiKz61lG+TcwB3XNRFoIVazWq kxmg7HSd3Dr6w8GaFRsiQ2B7l/fRdgphdekF3LkI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mathieu Poirier , "Peter Zijlstra (Intel)" , Alexander Shishkin , Arnaldo Carvalho de Melo , Jiri Olsa , Linus Torvalds , Stephane Eranian , Thomas Gleixner , Vince Weaver , acme@kernel.org, miklos@szeredi.hu, namhyung@kernel.org, songliubraving@fb.com, Ingo Molnar , Sudip Mukherjee Subject: [PATCH 4.14 67/85] perf/core: Fix crash when using HW tracing kernel filters Date: Tue, 17 Nov 2020 14:05:36 +0100 Message-Id: <20201117122114.313330905@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122111.018425544@linuxfoundation.org> References: <20201117122111.018425544@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Mathieu Poirier commit 7f635ff187ab6be0b350b3ec06791e376af238ab upstream In function perf_event_parse_addr_filter(), the path::dentry of each struct perf_addr_filter is left unassigned (as it should be) when the pattern being parsed is related to kernel space. But in function perf_addr_filter_match() the same dentries are given to d_inode() where the value is not expected to be NULL, resulting in the following splat: Unable to handle kernel NULL pointer dereference at virtual address 0000000000000058 pc : perf_event_mmap+0x2fc/0x5a0 lr : perf_event_mmap+0x2c8/0x5a0 Process uname (pid: 2860, stack limit = 0x000000001cbcca37) Call trace: perf_event_mmap+0x2fc/0x5a0 mmap_region+0x124/0x570 do_mmap+0x344/0x4f8 vm_mmap_pgoff+0xe4/0x110 vm_mmap+0x2c/0x40 elf_map+0x60/0x108 load_elf_binary+0x450/0x12c4 search_binary_handler+0x90/0x290 __do_execve_file.isra.13+0x6e4/0x858 sys_execve+0x3c/0x50 el0_svc_naked+0x30/0x34 This patch is fixing the problem by introducing a new check in function perf_addr_filter_match() to see if the filter's dentry is NULL. Signed-off-by: Mathieu Poirier Signed-off-by: Peter Zijlstra (Intel) Acked-by: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Cc: acme@kernel.org Cc: miklos@szeredi.hu Cc: namhyung@kernel.org Cc: songliubraving@fb.com Fixes: 9511bce9fe8e ("perf/core: Fix bad use of igrab()") Link: http://lkml.kernel.org/r/1531782831-1186-1-git-send-email-mathieu.poirier@linaro.org Signed-off-by: Ingo Molnar Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7124,6 +7124,10 @@ static bool perf_addr_filter_match(struc struct file *file, unsigned long offset, unsigned long size) { + /* d_inode(NULL) won't be equal to any mapped user-space file */ + if (!filter->path.dentry) + return false; + if (d_inode(filter->path.dentry) != file_inode(file)) return false;