From patchwork Tue Nov 17 13:05:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 324583 Delivered-To: patch@linaro.org Received: by 2002:a17:906:d156:0:0:0:0 with SMTP id br22csp4946625ejb; Tue, 17 Nov 2020 05:13:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxyNp/qkz/KDnkay40EqmTrgQJSyo/RJfB943cdvlUmrSDPbSxDuVuLkOCe4NlwZ3mLlfaq X-Received: by 2002:a50:ab15:: with SMTP id s21mr20551322edc.88.1605618788368; Tue, 17 Nov 2020 05:13:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605618788; cv=none; d=google.com; s=arc-20160816; b=v6kYlp7Pdd4SbMQBRuL5bKrblZN0ZG/A9ZGdLgkCW2YZrQRTMDsdVm2pwan7RldA+H VMTA1PhfUVXTah4pxetN3cPNn/AlOOSQKHi0rjqEGGwPf6nd0QI10mJa/IMoLnEP/0PI nzrzOcV46r1rc9c9Fkz9eYh0bMdySr3dgUPgS0grAlgqsTpH8/XyiJzXO1TPD7xyK5TK 4mAMbUEw2suaHYCK/D1Um8zIvDfjb+htjs0Dk2ClqVmflzvDck+85n6yorY6fVjSfpaV 5/PXLZqC4+Ac1WFMFkBMnEfOqjYitVzoNRgi16WFBBrIWVda4+WKRUepabwA1wkzB3bT FL2Q== 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=fagJEq/Mk5Zs1fxpRWDZp2EK0lUtxx5yo2j5Ft6L72o=; b=I2uF51q07VIkD8iK4eCxL9wEBA6XVZJEgD6UchPLm1kNnpLLN6AdfxshnuPeK/SloE oyUlG1A9zSudxeJJvwQlcLWB2kZhqfipbkSJ7WoYVymx/8tgO7a7L4hFRDxQK/93iDzy JcI2Vk154FdFkMLOlohab8x0V+R3LQS/a24nNmEuHcziN7choNTkSDefIf1YvGL1OjG8 1+9G3pPBX5ch7xYETe5Ws0eAAX53yoQrFEDivUcDc3JO04cxbGgIU2OQZd7tv1XVk4k6 9RQo9Um3WFi13QbYJbFIgWUH2KYvLImJq/jGYkLec/pHf/PxwhvVUunAgZOnTyQ/3UxZ jg7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="bcgp/ZiA"; 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 k11si13103195ejb.369.2020.11.17.05.13.08; Tue, 17 Nov 2020 05:13:08 -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="bcgp/ZiA"; 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 S1729742AbgKQNLy (ORCPT + 14 others); Tue, 17 Nov 2020 08:11:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:41790 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729258AbgKQNLw (ORCPT ); Tue, 17 Nov 2020 08:11:52 -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 405E624199; Tue, 17 Nov 2020 13:11:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618711; bh=xTAXFNREFzNiLURv6XXd01JKeNZ3ZXa4zHUHpNhRLEY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcgp/ZiAgHQunXzaE5k4cI56XDg5fbNRGqWsDP1U/6GL17q3SoWhPraSFnCNpCLcG dMOeUJrBXPIZsnlWc4wEWrrsao/kK51yrjlpIveHNXSkgEZKbdNsmXMnDUzrfwGKl1 SSHv51Z/dkf5EPGaRK79DPAP+OUQ0iiRzsHFHiwM= 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.9 60/78] perf/core: Fix crash when using HW tracing kernel filters Date: Tue, 17 Nov 2020 14:05:26 +0100 Message-Id: <20201117122112.038248140@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122109.116890262@linuxfoundation.org> References: <20201117122109.116890262@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 @@ -6814,6 +6814,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;