Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5926908pxb; Mon, 14 Feb 2022 10:53:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJwk/kjBJX4XGgUj/qyQLTDGQoXxB9kJg9jeVC4DjYKyoxWPuz3Y2MBv3jAA+N5MGEwHsOOt X-Received: by 2002:a17:90a:eacb:b0:1b8:78a1:4d54 with SMTP id ev11-20020a17090aeacb00b001b878a14d54mr40986pjb.212.1644864796069; Mon, 14 Feb 2022 10:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644864796; cv=none; d=google.com; s=arc-20160816; b=Tlp9WMgWwRqMIdAIiAx5Jn4LUxzrqnQhN1jgWaqQPh4XGS1WJhajOFkSNkvHK56gfE Jy67QtgTE8Yv3Qtnvw2ARRu/AkWywfcqAPe3UKeD1DXO8qR2HPzhOMj/DCfccUPIjtmV E/2KNe6j9iknjprklulkhirssivesojPkKbLbIC9XXVA0CoNF45N/wMz6/TKVe3jMecV vIT3h9srRkEBN8eVCS52NSnUUHfgyXQmfVQqHzNhTQZvzWROp3rSWJjaiyNgMFonrKBG ZKlrMApF+S55kAaqQEka2rtzVUHh0qAWwyDSla2xdZn5JhLxtITG7dZsMRr3c6mDXxlp yxcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LqVuzv2uJLZmD/1GFnCdA514PqhE47Zi/9q7F2KxdTg=; b=G+9F7FgFjO60ll7iK0FzTyWRE7RJ8RSj3KsRmB1WFxpyDgpi1G3+1F6jXNQmoze7CB oweSwKOyTnGFSYawkgPSxa9tJUiWoIlX3r2sBWyhCDUjDJcYTyCFDWB9wuMRXNe2b84E Bk7lTBoibOia6JQYSOnK60bDkH/I1HTjqsJMiqeGbl3EZDghvLx6VRhziDTH99i8CmSI 5nCCoUp5ldEz/LtmMguF9y+meEzKioOW6ltp1FV3FBDHWIEeLuugTPIzpiqgPZFVIi1F Wox/I8N6aKU9OLetRiQs1x1finTzluzznyZk8rVvSrh1aHwajdEsO0325MDcy+AWrjsS F8iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kBRdar0f; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id y1si12024633pll.463.2022.02.14.10.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 10:53:16 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kBRdar0f; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 11659939F8; Mon, 14 Feb 2022 10:52:22 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244672AbiBNJpd (ORCPT + 99 others); Mon, 14 Feb 2022 04:45:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245068AbiBNJn6 (ORCPT ); Mon, 14 Feb 2022 04:43:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36C516CA6F; Mon, 14 Feb 2022 01:38:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B0E77B80D83; Mon, 14 Feb 2022 09:38:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7A53C340E9; Mon, 14 Feb 2022 09:38:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831485; bh=cTfUMZissMI9IeGEkEU24qJMhW+DUACGHuB3TU20yqw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kBRdar0fDwpt2qFV90w9R4GzguQjjCNUgUSHy3bxgIMfQszuEEx0yxwtJHii1Kvk6 9aJPhuvWtwqx2gda5TrW9fak8LP4L0tphBAE/3djsnp9dm0aBVE3dZhZXwI9vPZ8tE cX33KAhIjBmx/2al0fQBQzEDcONn4zFrz+1Lnx6s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Song Liu , Rik van Riel , "Peter Zijlstra (Intel)" Subject: [PATCH 5.4 70/71] perf: Fix list corruption in perf_cgroup_switch() Date: Mon, 14 Feb 2022 10:26:38 +0100 Message-Id: <20220214092454.390214911@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092452.020713240@linuxfoundation.org> References: <20220214092452.020713240@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Song Liu commit 5f4e5ce638e6a490b976ade4a40017b40abb2da0 upstream. There's list corruption on cgrp_cpuctx_list. This happens on the following path: perf_cgroup_switch: list_for_each_entry(cgrp_cpuctx_list) cpu_ctx_sched_in ctx_sched_in ctx_pinned_sched_in merge_sched_in perf_cgroup_event_disable: remove the event from the list Use list_for_each_entry_safe() to allow removing an entry during iteration. Fixes: 058fe1c0440e ("perf/core: Make cgroup switch visit only cpuctxs with cgroup events") Signed-off-by: Song Liu Reviewed-by: Rik van Riel Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20220204004057.2961252-1-song@kernel.org Signed-off-by: Greg Kroah-Hartman --- kernel/events/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -799,7 +799,7 @@ static DEFINE_PER_CPU(struct list_head, */ static void perf_cgroup_switch(struct task_struct *task, int mode) { - struct perf_cpu_context *cpuctx; + struct perf_cpu_context *cpuctx, *tmp; struct list_head *list; unsigned long flags; @@ -810,7 +810,7 @@ static void perf_cgroup_switch(struct ta local_irq_save(flags); list = this_cpu_ptr(&cgrp_cpuctx_list); - list_for_each_entry(cpuctx, list, cgrp_cpuctx_entry) { + list_for_each_entry_safe(cpuctx, tmp, list, cgrp_cpuctx_entry) { WARN_ON_ONCE(cpuctx->ctx.nr_cgroups == 0); perf_ctx_lock(cpuctx, cpuctx->task_ctx);