From patchwork Mon Dec 28 12:47:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 354898 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=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_RED, 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 84A80C433DB for ; Mon, 28 Dec 2020 14:22:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5841A229C5 for ; Mon, 28 Dec 2020 14:22:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438153AbgL1OWK (ORCPT ); Mon, 28 Dec 2020 09:22:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:57716 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438156AbgL1OWJ (ORCPT ); Mon, 28 Dec 2020 09:22:09 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 582B42063A; Mon, 28 Dec 2020 14:21:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609165289; bh=gnELdCjELm98NJSssu0Y6p/tT9x6O8zCKJr0XYtKegc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kwMx1nf+BTK74P0qGNDeMa1Qnh0B8NYo/44IFeZ3gWRpC9JFLSWrf8i1iDBY1FhuD oGqcBeZ7xbBooNOYmq+678E8BEiV+PQKyaFyx7nKciaxtjtrylzbO8diHhnG6mWlUe hi5/vyIL8YMxNNlWf4pmHmEjN67iPJdVj6GW5uyo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Muchun Song , Roman Gushchin , Johannes Weiner , Michal Hocko , Vladimir Davydov , Shakeel Butt , Joonsoo Kim , Yafang Shao , Chris Down , Christian Brauner , Peter Zijlstra , Ingo Molnar , Kees Cook , Thomas Gleixner , Eugene Syromiatnikov , Suren Baghdasaryan , Adrian Reber , Marco Elver , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH 5.10 449/717] mm: memcg/slab: fix return of child memcg objcg for root memcg Date: Mon, 28 Dec 2020 13:47:27 +0100 Message-Id: <20201228125042.489584214@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228125020.963311703@linuxfoundation.org> References: <20201228125020.963311703@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Muchun Song [ Upstream commit 2f7659a314736b32b66273dbf91c19874a052fde ] Consider the following memcg hierarchy. root / \ A B If we failed to get the reference on objcg of memcg A, the get_obj_cgroup_from_current can return the wrong objcg for the root memcg. Link: https://lkml.kernel.org/r/20201029164429.58703-1-songmuchun@bytedance.com Fixes: bf4f059954dc ("mm: memcg/slab: obj_cgroup API") Signed-off-by: Muchun Song Acked-by: Roman Gushchin Cc: Johannes Weiner Cc: Michal Hocko Cc: Vladimir Davydov Cc: Shakeel Butt Cc: Joonsoo Kim Cc: Yafang Shao Cc: Chris Down Cc: Christian Brauner Cc: Peter Zijlstra Cc: Ingo Molnar Cc: Kees Cook Cc: Thomas Gleixner Cc: Eugene Syromiatnikov Cc: Suren Baghdasaryan Cc: Adrian Reber Cc: Marco Elver Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/memcontrol.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 29459a6ce1c7a..74b85077f89ad 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2987,6 +2987,7 @@ __always_inline struct obj_cgroup *get_obj_cgroup_from_current(void) objcg = rcu_dereference(memcg->objcg); if (objcg && obj_cgroup_tryget(objcg)) break; + objcg = NULL; } rcu_read_unlock();