Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp2906671ybk; Mon, 18 May 2020 10:49:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwCWSprZjbOyoYNrHs2F31vh342SRSMn6C8dbvxXBXqPdsamWDsNxV0IiCSTtgLBF9xS0Un X-Received: by 2002:a17:906:6a18:: with SMTP id o24mr16323357ejr.66.1589824149557; Mon, 18 May 2020 10:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589824149; cv=none; d=google.com; s=arc-20160816; b=gclRUugvSc1S7PHr8HAyKE921xE5wgbB0pS7kyUv811zTLQ01ii9c/4F9hu/v2ft6M cdcKuF8RIXOlO4AoEyZSHFNEnPPphmXNJS5kEEJGng8r8VI1CIS2so2nL3/pW/zKy5Od +9sanxgfZGJS0+q1rIsdv8sO0D0Lar8hFj+b20hJpSupPtJNODpkUEBIJARE5e/ExW30 0xbpLn6FSCZxeeiddMZ6tIeaTz9obyOZB8yjDZGg8LE3Z7XIlhx/7o2HOZKdYtM3y2aN fDfef+laooJfjT73UAHY0PT5123QmbZwO+aGi6MrmXgwO3StJMOBiJYtLOKx55pCD0LN Jowg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kxYwfCHbPYj2Pz+9aIHbfFWDWC1e/dbt7Zn75Hz/Uo4=; b=DN6OdhW3wI3ZVM0ee4ErjQJ5mjIKoGjS6a2QQmyh7r0O/k6eSfBLZHh3STPMSrx6v1 APl/ZSbCNPy3mbBhM8wGLowenhpisVT+9PsSj8yM4H83ohiuwMCZmxhLtyUd9lQBTwGV DDQECG07Bbs5FFcnFDpWwB5+S66ydlvdVc/1HcXAxZbt4lHT9S1nEGowkLnJE7oUo1Z5 bbyLVHEcGMZuS5fburnMhG6AYpGppCUEWFI24NVCqwXoXAvd3PxACsQuFOZMeR6taLvt mm5KMS0L2xApO9JXWtxxLY/GiGP8hiWJd4pSYLlOgnn7PaO9uFd+BknZsorOPFJXryCy Ki4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H9OWNe60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qq25si3879868ejb.173.2020.05.18.10.48.46; Mon, 18 May 2020 10:49:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=H9OWNe60; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729961AbgERRpp (ORCPT + 99 others); Mon, 18 May 2020 13:45:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:44670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729433AbgERRpk (ORCPT ); Mon, 18 May 2020 13:45:40 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 5DF4E20657; Mon, 18 May 2020 17:45:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589823939; bh=mAPBp6yla25QDnZJasFgLtLiQLtE+XJaFTUczGYNvLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H9OWNe60YtNilLs6c1DND8aMShHOP/t3TeklCSQ9SgYkb81snbYXHofbjLMyRogwg zESkDRQ1pykCD72B7+AVnZtiyfLL398nuRyrNFHREFCcapqQoazfhfbSVfBeKEcBce ZCvWtA2VrMGssO3mvLpCvbpJLg3sFfxCjj0qfy8U= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yang Yingliang , Zefan Li , Tejun Heo , Jakub Kicinski Subject: [PATCH 4.9 72/90] netprio_cgroup: Fix unlimited memory leak of v2 cgroups Date: Mon, 18 May 2020 19:36:50 +0200 Message-Id: <20200518173505.923430661@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200518173450.930655662@linuxfoundation.org> References: <20200518173450.930655662@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zefan Li [ Upstream commit 090e28b229af92dc5b40786ca673999d59e73056 ] If systemd is configured to use hybrid mode which enables the use of both cgroup v1 and v2, systemd will create new cgroup on both the default root (v2) and netprio_cgroup hierarchy (v1) for a new session and attach task to the two cgroups. If the task does some network thing then the v2 cgroup can never be freed after the session exited. One of our machines ran into OOM due to this memory leak. In the scenario described above when sk_alloc() is called cgroup_sk_alloc() thought it's in v2 mode, so it stores the cgroup pointer in sk->sk_cgrp_data and increments the cgroup refcnt, but then sock_update_netprioidx() thought it's in v1 mode, so it stores netprioidx value in sk->sk_cgrp_data, so the cgroup refcnt will never be freed. Currently we do the mode switch when someone writes to the ifpriomap cgroup control file. The easiest fix is to also do the switch when a task is attached to a new cgroup. Fixes: bd1060a1d671 ("sock, cgroup: add sock->sk_cgroup") Reported-by: Yang Yingliang Tested-by: Yang Yingliang Signed-off-by: Zefan Li Acked-by: Tejun Heo Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- net/core/netprio_cgroup.c | 2 ++ 1 file changed, 2 insertions(+) --- a/net/core/netprio_cgroup.c +++ b/net/core/netprio_cgroup.c @@ -237,6 +237,8 @@ static void net_prio_attach(struct cgrou struct task_struct *p; struct cgroup_subsys_state *css; + cgroup_sk_alloc_disable(); + cgroup_taskset_for_each(p, css, tset) { void *v = (void *)(unsigned long)css->cgroup->id;