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,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable 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 E71FDC43613 for ; Thu, 20 Jun 2019 18:15:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BF1E2205F4 for ; Thu, 20 Jun 2019 18:15:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054558; bh=EFiKdPtI86pvDNJdhQceHHjfLf9fToe07ZNhuIIYQmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=zXraFaEtyxmvqfKzLBylN9gjcjMn8VeOV39UqDbxlH4qjWMiZrSSDR25A72FPIrG+ xmE3+TUlU9GPXWaXKbeLQnlSMRs/X/mqTg6OuOfIdNLz04zVkqlR8SLLrJsQVqKMYp E9IButmDB9zQedcME0y90jPoosieyoROf7bx6UIg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729696AbfFTSP5 (ORCPT ); Thu, 20 Jun 2019 14:15:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:44914 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729687AbfFTSPy (ORCPT ); Thu, 20 Jun 2019 14:15:54 -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 801B32166E; Thu, 20 Jun 2019 18:15:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561054554; bh=EFiKdPtI86pvDNJdhQceHHjfLf9fToe07ZNhuIIYQmI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YLyKIJpMbJUsiapjzUZzMSem0wmgg6Pc/VjxhrrDoT3/iMpSftWAmbLu3nZ14fq5Q 50btMH12eSqWg0hReDzC03HVBbs7F+Mj2vhzmjLFEMYOna0NvGmbZ5wCj+p/DLuLfI 3/fuFIFr39MtUfcGaDEV75PvurcfpjOPj6/6GGJk= 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 5.1 68/98] perf namespace: Protect reading threads namespace Date: Thu, 20 Jun 2019 19:57:35 +0200 Message-Id: <20190620174352.564754038@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190620174349.443386789@linuxfoundation.org> References: <20190620174349.443386789@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 [ 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 50678d318185..b800752745af 100644 --- a/tools/perf/util/thread.c +++ b/tools/perf/util/thread.c @@ -132,7 +132,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; @@ -140,10 +140,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