Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp705134ybk; Sat, 9 May 2020 16:08:16 -0700 (PDT) X-Google-Smtp-Source: APiQypLijdkrluiSct1CHFoVNz3hoLkS9jgEldj4oLWNKRuDczMFi8h0iGmx6yDfuIMG1nFROcaI X-Received: by 2002:a50:ef14:: with SMTP id m20mr3109648eds.47.1589065695895; Sat, 09 May 2020 16:08:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589065695; cv=none; d=google.com; s=arc-20160816; b=nMbCLSBDRovUcPdSKNifRjDqffOrp0MlShyYX3uOdEf0Pr0leqU3wtCIm0fGnpLUid ibAM9YiH7gBwhF93tApfh+GB5UT1EGNTYCKn8DhTxpQMxmehILAKoLSf5ZelodjOWgVV hzwXKVnSM2M7aSH7oov1g/5X6sGksKeza7dIj5bMe4qjtyg4XxI5h/qhqptGs2zLVAoi I4KjEKQT04uhc7h8+lqGx4lFUGhPe1b8Vqrtd4BdUQFKuK7/jC+t1ZrD/yNwxhHvudqM nhO+Msim3sCsR9acSNaPvtBiKlnHLmVTfTeaZGH7jbb130c/zheskSqJJmkALNGgbD+f LRaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=rNy4JOtG+nCRfsj1WL1vWdLxzYPRX62nRZqLhv1rCGQ=; b=PE2T0ScFHnEhNFZnn5R+z2sJw+6pUT0RSUvz+HT68qU6z+c7NEd7IGeP0YukLkvldT aknRdYKPULThvfc7xXkrExWdMUX+/m5G2AFJZfFjELq0yQAdZjVmZAhtDo1TcvQtRY8f 39Opo1QlB1TuaaZDeW3ieQHowHJEtGGT6+azpwgmYZZ0uZ7B5hSJXktcCPeMIW7iNk0L /IOGGGED8zlvZgTEtXMVyK8hGFHDf3lKwAkyXTmcKdOBqZ+tbRP2d0pRFJAD05EPcn9Y S9Bv7yk5HfzfEs/Rkzi727/zjm4PVv90CUeQaMM9XiYtIdmOlzJib28KXyEFWkJn+8ak jDuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=ZBrXz5ss; 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 p3si3474886edr.391.2020.05.09.16.07.52; Sat, 09 May 2020 16:08: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=fail header.i=@gmail.com header.s=20161025 header.b=ZBrXz5ss; 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 S1726763AbgEIXGa (ORCPT + 99 others); Sat, 9 May 2020 19:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725927AbgEIXGa (ORCPT ); Sat, 9 May 2020 19:06:30 -0400 Received: from mail-qk1-x741.google.com (mail-qk1-x741.google.com [IPv6:2607:f8b0:4864:20::741]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C75AC061A0C; Sat, 9 May 2020 15:57:39 -0700 (PDT) Received: by mail-qk1-x741.google.com with SMTP id c64so5875461qkf.12; Sat, 09 May 2020 15:57:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=rNy4JOtG+nCRfsj1WL1vWdLxzYPRX62nRZqLhv1rCGQ=; b=ZBrXz5ssxM8itMJvIuhpryRMrVoN3j3run4YUAz9kEkOoLcLITpSlYjkDQ7w9RSvP1 HojOEGvaQDlHZxwbT5lZPfEogQgu8nZ9xiQG2LBJjr6pQw6jEdLZYdyThxAK7iKXAKQd h/ZPs7oYkGx6MLK5yVck7arft1mrtTZBmumNr8P/oEV1EECn43KBNnYn9M0Js1dGFp4/ XCMz5qTkq1i2i4WFKcSfdsO9C55aV/5BpbJMQyj6IU0Bc0RLAujCsLkqDy6X9S3W2oQb AQ2oKK+CDVfbfZdfdssvS6OZ+Pbo0E5iwtFQcPKP978sryTITGs/XquTmjhclfNGtfNe WE+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=rNy4JOtG+nCRfsj1WL1vWdLxzYPRX62nRZqLhv1rCGQ=; b=Yy9wwTkrsCkCCdK/SEGFZ/9XCdJsUvNThzOpqsIJ6ynIrpGarSL3vIQgtrSUMb+Zp5 keJBoj5cFqtncidKtiadBb26qhSZsJb6RVs1QH8Mf8ijaKeHaoq50uwIJ/oROmIdiCM2 0RYDQ66udbpGIfO0vLsnFr0v7sPZ6BumbhXOdusm9Sbat2iLdpSZUK0XE1sSkgUgbE/F YDgCgSF+tz2+2RVAk7RMSFHLDaEsryrQQkNLLuMpmDPZ+rdBWpXCrV1U1WhAfJQH0iwH NgtQyqn5iteYJEdPktWBGvbAnf9xI45+zC4Hh5Hh1RgbqFwniCQUMrfE/mcPsy2eoIHh BsEw== X-Gm-Message-State: AGi0PuZqBRYOtfM8JQaQbXDB6pXI2kF5mE0dAkLeFJ1dsS4jo+DVHaud 9cwnaA02eZ596WiRCPE4k5s= X-Received: by 2002:a05:620a:1495:: with SMTP id w21mr9365964qkj.81.1589065058181; Sat, 09 May 2020 15:57:38 -0700 (PDT) Received: from localhost ([199.96.181.106]) by smtp.gmail.com with ESMTPSA id e26sm4537648qka.85.2020.05.09.15.57.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 May 2020 15:57:37 -0700 (PDT) Date: Sat, 9 May 2020 18:57:36 -0400 From: Tejun Heo To: Zefan Li Cc: David Miller , yangyingliang , Kefeng Wang , huawei.libin@huawei.com, guofan5@huawei.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, Linux Kernel Network Developers Subject: Re: [PATCH v2] netprio_cgroup: Fix unlimited memory leak of v2 cgroups Message-ID: <20200509225736.GA16815@mtj.duckdns.org> 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-Disposition: inline In-Reply-To: <2fcd921d-8f42-9d33-951c-899d0bbdd92d@huawei.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 09, 2020 at 11:32:10AM +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") > Reported-by: Yang Yingliang > Tested-by: Yang Yingliang > Signed-off-by: Zefan Li Acked-by: Tejun Heo Thanks. -- tejun