Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp834128ybk; Sat, 9 May 2020 21:04:04 -0700 (PDT) X-Google-Smtp-Source: APiQypI3DpCX5gaWg8T+rlBcc6PS51qFjXTfhf5xV2vT98eUpFOIISgx6gAHgenM+YUBXtMgTA/D X-Received: by 2002:a50:de02:: with SMTP id z2mr7934432edk.292.1589083443836; Sat, 09 May 2020 21:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589083443; cv=none; d=google.com; s=arc-20160816; b=0CG72jlDGd4sz4A0S1oXqw9rW3ous/G1meveSefOTYroQqT/XXt9XMhxP7iM1cdu1O XKWmv6Sdt4sksdUJTbaFZPou5Od/QBLD6yEkcE6cSYhp2C5EmzV/rSunlYQSmMJ62rYF Tk2rUHdfxhH8mB9vMFYUymxjwHHTGz8Vr8pu2FWnQWcrePxo3SE2uYtDcMvy5HznIg8P t4Ua21BZylpzxaqZ1LFDtReuMFUqh7w9Ulkl4t0xbTgQcNqegGoWgr6RSfRC00g1fj5e MvPKnd7SrKkNF2axMliPaN+xpxpyI8n195fut96bkYhphhIVfxFf+11z1uASUCoIRdud FJQg== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=0fB8lAUT/uv7/JqYJGOTugZNFEzyBOccVy2m0LxOUJU=; b=wx7hi7kVq6ZLpH5PbnfNfBsQhbX+lK/YbDAjTwsJiipn1jOjUAJl9iz3S5mpmEfdPT 98elLKFiBqKWIVdqBSM1VSrQfXWmzj/PZ9SKnsVQ1bUUGJlz3j1UtXHONwSv46uEgxMp 3WP/6jsIIxdAV20a5FP/AVCbabY2Qa1I9UdC3xUJUylEqvxoQckm20tuAvsGkYHt63Qi oiA6MdJQqIrMvcNY9Pk+wPUKUAxPTMuTglTSlLhs/pbwwk9VrM+SQRbtwx1AXMAyvfnH VZRDNjd3yAX87gv76OQMf97iCfjo0NulhZ9lG6pDG2pgr2+XVnU376WDghGS5UX+NnLO EfCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="jt/Lu4Mp"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x61si3565970ede.604.2020.05.09.21.03.39; Sat, 09 May 2020 21:04:03 -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="jt/Lu4Mp"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725811AbgEJECR (ORCPT + 99 others); Sun, 10 May 2020 00:02:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:36848 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725308AbgEJECR (ORCPT ); Sun, 10 May 2020 00:02:17 -0400 Received: from kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com (c-67-180-217-166.hsd1.ca.comcast.net [67.180.217.166]) (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 70FA020801; Sun, 10 May 2020 04:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589083336; bh=iIlip5Pvd+/nd22NeY8yhi15wbomwAP7PKDtjMfhDj4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=jt/Lu4MpG2XiLOF+j8YPcqZ4sHVm+vw975QlQVLhxR2U4bY7oXARENrwmZCyuzPr6 zFdhJhlfElJeK4kEP4G3Teypdvui3NPeLMLlqE26xrQjZ5nexhMPbWUN0Tiu7bxTvM xGyXC1XUZ7RA2Bc3pdE+POWvblB2W29X4MnUmmXc= Date: Sat, 9 May 2020 21:02:14 -0700 From: Jakub Kicinski To: Zefan Li Cc: Tejun Heo , David Miller , yangyingliang , Kefeng Wang , , , , , Linux Kernel Network Developers Subject: Re: [PATCH v2] netprio_cgroup: Fix unlimited memory leak of v2 cgroups Message-ID: <20200509210214.408e847a@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: <20200508225829.0880cf8b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> References: <939566f5-abe3-3526-d4ff-ec6bf8e8c138@huawei.com> <2fcd921d-8f42-9d33-951c-899d0bbdd92d@huawei.com> <20200508225829.0880cf8b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 8 May 2020 22:58:29 -0700 Jakub Kicinski wrote: > On Sat, 9 May 2020 11:32:10 +0800 Zefan Li wrote: > > 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") > > ^ space missing here > > > Reported-by: Yang Yingliang > > Tested-by: Yang Yingliang > > Signed-off-by: Zefan Li Fixed up the commit message and applied, thank you.