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=-9.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,T_DKIMWL_WL_HIGH,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 B606EC28CC5 for ; Sat, 8 Jun 2019 11:44:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8CA92214AF for ; Sat, 8 Jun 2019 11:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559994254; bh=m+luN6qEmF3h2fswZDivEUsDDF+UzGpELW9rdmEPKZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=P/MOLfrJ5+xrfZRbRB98oU/KoD/NtAlhXksXk+7oDjfWmIHBGNa68mJJ1sJj7NM81 rFCI00qvfq82VMFvQZyl0J4VnmhVlNy/PzGwlSou3UeZzRsuwQTO0mDukKKKzsWQzg V12gZGKXYub4OPuz1coQwc2REiFaE2w6uiH8mGso= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728283AbfFHLoN (ORCPT ); Sat, 8 Jun 2019 07:44:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:33260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727369AbfFHLoK (ORCPT ); Sat, 8 Jun 2019 07:44:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0003A214DA; Sat, 8 Jun 2019 11:44:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1559994249; bh=m+luN6qEmF3h2fswZDivEUsDDF+UzGpELW9rdmEPKZg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HZdInRX+vE52Nr4pXwyNexB5Yo87GTZNn5/G0DAV2wbtl7YVNBzLXF7Q7fgLABSp5 VeL86M0Xe5PUjtXL1UPWRbkctMOt7Z2tKCAzmK40vIdjyn3Q/klLtFVVy8QmB6J7uY otOteRIKYrVpNpVxVFXRNj0rCSd9OYdQkVtJRN9k= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Namhyung Kim , Hari Bathini , Jiri Olsa , Krister Johansen , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH AUTOSEL 4.19 31/49] perf namespace: Protect reading thread's namespace Date: Sat, 8 Jun 2019 07:42:12 -0400 Message-Id: <20190608114232.8731-31-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190608114232.8731-1-sashal@kernel.org> References: <20190608114232.8731-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Namhyung Kim [ 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