Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp6023812pxb; Mon, 14 Feb 2022 13:21:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuMnuu8VKglSdecsbs9N12osibFwitwcKi3c3Kj333g8i+TE/dipsaQFbR9NwM0tqI6p8d X-Received: by 2002:a17:902:d3c6:: with SMTP id w6mr860429plb.4.1644873698774; Mon, 14 Feb 2022 13:21:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644873698; cv=none; d=google.com; s=arc-20160816; b=Xx6sVSFr9fdZSAPrmzgw/UPxXiuD7Umx+WcZvKeN4p5XA+MHb0LcBEeALWBJW/Vx8l EWf2hxFC0oNV1KBjR2LdVYidoUvTo0YZjWz6RFDHzuo2Tzat12CC7U1tOuroW9CHgXxi lvL2W+lhj2PBGFmX1eAscKb4Reufg3+PqvCKE57yQHWmxSRHbz8FkY8WVVKyxc9I1axR 1H8SqLnOcdvPCw0y6GPt39P7O81UggCdbWWAGlsd/ul3qj3b/GmwbWMF1BXaxBFcO4ZZ i04H1siOdnTyWEr1AeEvplf4ZaKBZyiqEYt1J8Hh2uyLxItLBkcQf1/otXl5AHxcOoEN uA8A== 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=59B0GSY5PGIEkK4gWdlBTbmlPPNsWtQT305jyaOLwWo=; b=GjWcJyT7iIVSt3Oy5L39Tt8bPalHWzGgAGW+Fbzi748kflsfrPgoVPr6Z5QCB8CZ8m qyhb16duh8ZakipfZFhMCMN+HIyHErtCIM4PfF9E1VAmOm1FUOsCfAJDm1UkIh2FGyNZ VkujZlymelxThgLO8ruZEUj8SlQzAdTxIJ2LZvDdEnwgSO33lOi3jSjTma0hjSgsqLg+ usvTFgR9Ec7y27qmo6kGKF7U498W1g0WHITyBAC0vQ/DkqazSvsd65NSizlra9TaaaPv dpYIZwRVxhZSdrWN8S5/1EOG0jCVDPB3HJHTNE5JhMuEzUkT4kvpmskfYytM0ubhzTat l1qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EZqV09Ka; 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 c8si12268563pjv.158.2022.02.14.13.21.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Feb 2022 13:21:38 -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=EZqV09Ka; 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 7245A164D31; Mon, 14 Feb 2022 12:38:04 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242949AbiBNJ7a (ORCPT + 99 others); Mon, 14 Feb 2022 04:59:30 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:33240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343651AbiBNJyQ (ORCPT ); Mon, 14 Feb 2022 04:54:16 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D72BC7D283; Mon, 14 Feb 2022 01:44:04 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 5E9AA6123A; Mon, 14 Feb 2022 09:44:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E4F4C340E9; Mon, 14 Feb 2022 09:44:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644831843; bh=7wbu+JjjKSQJY2T/WvuvhCEzGbAPUI20JEPNXp/cYBc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EZqV09Ka0rxHPQj4WMdiDnIouOrbCkQoNLSTuTxR+mQdTHyHiiYXVBKkfSTuvvnEX 8SYl8U9HfXfjTdg1ejCwc+lFqkQcnb+CD4aj7S48SGatbG2+nFT7aj5mZK+M4/xcoE u5vaTFGlFJzcPm4aiq5a8e/Z07XbdwoWBSKMNlGs= 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.10 115/116] perf: Fix list corruption in perf_cgroup_switch() Date: Mon, 14 Feb 2022 10:26:54 +0100 Message-Id: <20220214092502.767757919@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220214092458.668376521@linuxfoundation.org> References: <20220214092458.668376521@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 @@ -838,7 +838,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; @@ -849,7 +849,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);