From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1330AC48BE1 for ; Thu, 20 Jun 2019 18:12:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E41E82089C for ; Thu, 20 Jun 2019 18:12:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054362; bh=83W8VBRyEX7GIpNaDFAUc7mSOtpZrTJazLg+0O8uXns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=rGWO5j5wkFU7KMJlBgeVE1zhCbot1nriBRVbQqvnkjgdJG9dvielm1hWKCkkGpDWa e7pISRVnB3s746n+ZyayDdo6x8UYYoRjxQR8wJRVWpcH4Sl2AlujfpcfB8nUne3LHX JuYGXhvtBWOUs6YvkaSuYypDoB53T0I6nCHvOEbs= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728919AbfFTSMl (ORCPT ); Thu, 20 Jun 2019 14:12:41 -0400 Received: from mail.kernel.org ([198.145.29.99]:40542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728743AbfFTSMk (ORCPT ); Thu, 20 Jun 2019 14:12:40 -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 CB9F421530; Thu, 20 Jun 2019 18:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054359; bh=83W8VBRyEX7GIpNaDFAUc7mSOtpZrTJazLg+0O8uXns=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1SPmFIEjmg2EU2T+ReYRK0qvcBkZdcC68fdpiXMhLqfQk4EfWBHcE8nKCMdieNs5 jgFfERw694JF3OeBsfghX17W10Lp0HWBXzkcpgDRCzt8BNMxEHlfMwJgD/ZVUv4M+r eubT1ovJJnWhXEmqyQAEZDWRVM+6h8+f8KBSqm9Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Hari Bathini , Jiri Olsa , Krister Johansen , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 4.19 41/61] perf namespace: Protect reading threads namespace Date: Thu, 20 Jun 2019 19:57:36 +0200 Message-Id: <20190620174344.378337427@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174336.357373754@linuxfoundation.org> References: <20190620174336.357373754@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org [ Upstream commit 6584140ba9e6762dd7ec73795243289b914f31f9 ] It seems that the current code lacks holding the namespace lock in thread__namespaces(). Otherwise it can see inconsistent results. Signed-off-by: Namhyung Kim Cc: Hari Bathini Cc: Jiri Olsa Cc: Krister Johansen Link: http://lkml.kernel.org/r/20190522053250.207156-2-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/thread.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/thread.c b/tools/perf/util/thread.c index 2048d393ece6..56007a7e0b4d 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -128,7 +128,7 @@ void thread__put(struct thread *thread) } } -struct namespaces *thread__namespaces(const struct thread *thread) +static struct namespaces *__thread__namespaces(const struct thread *thread) { if (list_empty(&thread->namespaces_list)) return NULL; @@ -136,10 +136,21 @@ struct namespaces *thread__namespaces(const struct thread *thread) return list_first_entry(&thread->namespaces_list, struct namespaces, list); } +struct namespaces *thread__namespaces(const struct thread *thread) +{ + struct namespaces *ns; + + down_read((struct rw_semaphore *)&thread->namespaces_lock); + ns = __thread__namespaces(thread); + up_read((struct rw_semaphore *)&thread->namespaces_lock); + + return ns; +} + static int __thread__set_namespaces(struct thread *thread, u64 timestamp, struct namespaces_event *event) { - struct namespaces *new, *curr = thread__namespaces(thread); + struct namespaces *new, *curr = __thread__namespaces(thread); new = namespaces__new(event); if (!new) -- 2.20.1