Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2231274ybi; Thu, 20 Jun 2019 11:16:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrMqU7iR2NDp1ThON54AqIJnLZD9tlgzgTbrtGvo1N1N/Xh9ZiHiJANET5FesmfR1Tl9UV X-Received: by 2002:a62:58c4:: with SMTP id m187mr73648646pfb.147.1561054575989; Thu, 20 Jun 2019 11:16:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561054575; cv=none; d=google.com; s=arc-20160816; b=evTI9TRQSf03yo4DMIKfossvXBL99HLyuB/75lPfspiqgEcF1k8AA1+RW7I65DAidd M5sLhlKc1Jt9ZeEGZOdqhdxjMLP7fgNFfxjQ2eD86WwNeWdcx4436oE8QRSjV8z0TquA Q/SdcYAI56rgl1UGH1jJ21Z/hEEkIj0iVXvMUoKRz1CKAyANUHMh1bR77GIaKYabDn0Q 3XkGIcukC9+fjkq9e0N0RQP1/q03axcH2eRzME8cQ8+VVcMBlybo/G2Cg76QiMuPqrD9 WJ1XimgzhYVbqWIPXMV5LaxAIQH3v7kBcQNY6Qu5hYJxFQkFzjB0wu2d/iTj+ofYD53T 7tbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h6Varmi2vWcVzQDxpCtClF/XC9IExWmhvU+uGQZKwSQ=; b=GQBSRj+R4cfn1WorDYHLotTD6ojyCsoH1NTqF848FPge5PfP97V4Dpe3FWQB6HcPmf u9si4GGPumlg6WAGxINmQTYXk1ugvDZD2O+wvsdVRiqhPJA1jAhoyYxw082W2JfwqVJf TZAKQudQcO76CzdR2YWWybWnu+BWbAna8aS6+eIlQtlVVEIJ/P5tpgAEdWjVtPAlzk7Y bwsOS9/1K9Xh78Qwor9Vlg1ceIwalG0wc+zqLr+VescgF0FRNjuc81kw21jMMgKkI+YH PIwcrPekrT8Oc1N3saoxhUWy6UaBtQenOl7pclukDpuods/STDoVVqZ5CbXifoXKJDoi 6uAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YLyKIJpM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j25si176140pfr.11.2019.06.20.11.16.00; Thu, 20 Jun 2019 11:16:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YLyKIJpM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729693AbfFTSP4 (ORCPT + 99 others); Thu, 20 Jun 2019 14:15:56 -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