Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3879282pxb; Tue, 17 Nov 2020 06:04:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJxSSEmq3NmCbYYozU414c4Oq/vl4ARFsTATqqydZB2rATRA7vvcYipkg2JlVEQStn7T0YtZ X-Received: by 2002:a19:4043:: with SMTP id n64mr1628316lfa.366.1605621882274; Tue, 17 Nov 2020 06:04:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605621882; cv=none; d=google.com; s=arc-20160816; b=CulNLRsSvBxbadmxvxL+mQp7aYdC2y6GYLg/snKzB9BqaQhLYe6B4W6E/TtMPzmhF8 jWT904jMV23Oltb9NTS4FND2641UmV9/CfK7PFW/Yz/jh585KhsPji9aACdm9NN4LhFn bUR9VYQvdHsaWwQwmi+ZkY3FP+PG1mSLPA/3wlsd76atBprV4SrOsHEmfiRqmRkAdSHj mqPr/o2NgpCBGjH2maCplb661VCKnczI40Qc/F7vu/xnKLL0EJvXzWdLQ/WCiSHNl2lI fulAE6/6Egx9rHjS88CvHl8qywUsgH8dvkHYcKRPSOCV36ddj8va/8wsAPbxAA38lHTZ ZWOA== 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=EXkDyC48wTfB3QHsXOun52YDxlOPekxpMhlbO+wJZ2oOG0s8nOxEymGL7Vg6+4YByz 4t2ZgoF5MG4bpY/7SfCWXccYNOeMD9j51xDH8g9pcCyFGJd9TFGg6uJvbbN7Tfb43r1s CB+901qQ6Vv6Jlpwc5KBQWrxt1s1Wn4Hu18JVOxttSlweQ88z6LETaEjvQGirYyk5Q6E FPI5tpPSu8vM2n/mR+WQcB3gk8TeOf5QdGM5XSrAcGfoNMHG3h1eQD6klN/IPvnn2HYP uZEdo4yvK7RzLCzMFOWrtcwFxbzvr8R0Xr55Ba4CDIOIzHZgXE1bX6Evcl+V88CmIIHr yNIw== 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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 i9si13323237eje.410.2020.11.17.06.04.13; Tue, 17 Nov 2020 06:04:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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 linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-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 S2387487AbgKQOAN (ORCPT + 99 others); Tue, 17 Nov 2020 09:00:13 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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;