Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp173646ybk; Fri, 8 May 2020 23:00:15 -0700 (PDT) X-Google-Smtp-Source: APiQypIjO4S5Gh5oI5lm9zeiMYifGfXJrNdF79ZxdpLKLKzprMK6bcxD2t9evrOZe879G/mjM/Ay X-Received: by 2002:aa7:c499:: with SMTP id m25mr4910753edq.122.1589004015137; Fri, 08 May 2020 23:00:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589004015; cv=none; d=google.com; s=arc-20160816; b=vUg7oFeA3BEb/ZWNRhaQ0D8/xobM1qxOLhMIE3SRQb0c/mAqqs0EK6LNU4Ie6IySzX g2FUc0f3o/LAhAjGsYyuasH7cQ/ZGxF6PdWYA52rdejpdSAO/NDR17AiG0Y1w5imWz6z IdW+RUc3NJPuc3tNMimIcnGhETSjmEy85n8LMxPIHR8wROWe6VHRy/pBHyjQqnfyM2u3 fJ/idklGmoxJaXqj7hCdxzKyl+AwTKKjhrcH/TuDMD5SIvjCLOAK+Q3vPgpK2z4z2416 4yoi3igL4fC5dkCx3Xz2eoPPHWarmcPdWO99zsMxb1Ub6TFNWKzs9bnQoSNgnRvgQVMH cq8g== 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=+LYKEDqNHAH9uPwGuMhRTQnTKUkf3OkjlRrzISbqVnk=; b=r8pwvbz/bGWlqww6fOPQsSxoj/mvFHqWaZpWqsLNJySSivAOty55Zalfoz26vLIIdt M/83VNomGA5yKdXQc0xJucscR+odgmst+H7nsWMP/XuEyfnrQS2qtQR4TVhc/aSamTSg 52+JLonB3vH6h/s6hPpOhrc5LoQ9BHy6woqTatdbM6RTPVfkVLJnuuNkUxUsvrUKpMxg kmZfTkTAgRjdYffDLLojDflioJkcR8gPVXr4LmKvMdCMPsxZUbvddkiCQc+F9oBwMidw gHsl69j92rVMQYgYys40EuSPcKnLErYrDiO4Dbua6r948cXc9OdhUm3MZlbEE3CgJTuv bwUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lBypPstp; 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 n16si2155656edy.219.2020.05.08.22.59.51; Fri, 08 May 2020 23:00:15 -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=lBypPstp; 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 S1728858AbgEIF6c (ORCPT + 99 others); Sat, 9 May 2020 01:58:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:36514 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725822AbgEIF6b (ORCPT ); Sat, 9 May 2020 01:58:31 -0400 Received: from kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com (unknown [163.114.132.4]) (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 AF66D21582; Sat, 9 May 2020 05:58:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1589003911; bh=vEVp4ZM8+5FOQMgtlwLDv2fPcu5BE4CM5MCDTzrtfE4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=lBypPstpmdRtZHZEmvO6U1DLXwxBnjwFnjd4K4VnMet519UGRGbyTkkDgSOs8HLy+ A4CUz00w4gbYZvhcn5BzKZ4JZlO2aaOfl992Om+t5SF/kHDeTmh7NfM7nuK/VVtVWW YszoJzmGpLH39Ba6TbzBaTvLPTvkZN4a7ArAqW9w= Date: Fri, 8 May 2020 22:58:29 -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: <20200508225829.0880cf8b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: <2fcd921d-8f42-9d33-951c-899d0bbdd92d@huawei.com> References: <939566f5-abe3-3526-d4ff-ec6bf8e8c138@huawei.com> <2fcd921d-8f42-9d33-951c-899d0bbdd92d@huawei.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 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 > --- > > forgot to rebase to the latest kernel. > > --- > net/core/netprio_cgroup.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/net/core/netprio_cgroup.c b/net/core/netprio_cgroup.c > index 8881dd9..9bd4cab 100644 > --- a/net/core/netprio_cgroup.c > +++ b/net/core/netprio_cgroup.c > @@ -236,6 +236,8 @@ static void net_prio_attach(struct cgroup_taskset *tset) > 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->id; >