From patchwork Tue Sep 1 15:10:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 310451 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=-13.0 required=3.0 tests=BAYES_00,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=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 55847C433E2 for ; Tue, 1 Sep 2020 15:42:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0FB32207D3 for ; Tue, 1 Sep 2020 15:42:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974974; bh=X2DGoTfYqQ05LHE37QFTcsOpw/4x131sy9zxpFv050A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=JHCN68UBgjimLWjl+LbQDVcUGr7k9mfqYZeLCEk0nMBMtu5WZyIRK2hrrnivzWGlC q/mgYDQWOZ7eV5+6kHxhqu+Wkf/ZM8zo3PMKhmRrGyLyHR1GUbiPRaGgymKBtjV1xj R/bTJ9Cwwj9hdlDeUZXe8qC73WPhDBY6j/BfXwh4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728717AbgIAPmx (ORCPT ); Tue, 1 Sep 2020 11:42:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:56192 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731508AbgIAPmu (ORCPT ); Tue, 1 Sep 2020 11:42:50 -0400 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 F2EFE2064B; Tue, 1 Sep 2020 15:42:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1598974970; bh=X2DGoTfYqQ05LHE37QFTcsOpw/4x131sy9zxpFv050A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Nv58xKhOzEytl/jthtk43WzV5KPlcSm2LpTaahmsIe5WfDDqD2Ekgd6NYi9JCKY9e JH8L0GY/glEKBoHAgUdV9Elxl36dQ3Yfs58mTAjxIhNpuK7jQn+0WYHFxAL+nWPSfW vcuig86ll4Xr429vo0PQsJU6ULjKE+I3lHvxlA7c= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yonghong Song , Alexei Starovoitov , Rik van Riel , Sasha Levin Subject: [PATCH 5.8 160/255] bpf: Avoid visit same object multiple times Date: Tue, 1 Sep 2020 17:10:16 +0200 Message-Id: <20200901151008.357190893@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200901151000.800754757@linuxfoundation.org> References: <20200901151000.800754757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Yonghong Song [ Upstream commit e60572b8d4c39572be6857d1ec91fdf979f8775f ] Currently when traversing all tasks, the next tid is always increased by one. This may result in visiting the same task multiple times in a pid namespace. This patch fixed the issue by seting the next tid as pid_nr_ns(pid, ns) + 1, similar to funciton next_tgid(). Signed-off-by: Yonghong Song Signed-off-by: Alexei Starovoitov Cc: Rik van Riel Link: https://lore.kernel.org/bpf/20200818222310.2181500-1-yhs@fb.com Signed-off-by: Sasha Levin --- kernel/bpf/task_iter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/task_iter.c b/kernel/bpf/task_iter.c index a4a0fb4f94cc1..323def936be24 100644 --- a/kernel/bpf/task_iter.c +++ b/kernel/bpf/task_iter.c @@ -28,8 +28,9 @@ static struct task_struct *task_seq_get_next(struct pid_namespace *ns, rcu_read_lock(); retry: - pid = idr_get_next(&ns->idr, tid); + pid = find_ge_pid(*tid, ns); if (pid) { + *tid = pid_nr_ns(pid, ns); task = get_pid_task(pid, PIDTYPE_PID); if (!task) { ++*tid;