From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=no 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 A9D0AC433DF for ; Thu, 13 Aug 2020 11:44:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8459120771 for ; Thu, 13 Aug 2020 11:44:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597319067; bh=fp5rvaq7NPsTUTrz3k3eLOHmPNbOzxflP+aP/tMnI8s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=XXrcx0ElW6hvXAbbzD33yNjgf0SUYmb+iDv3JGUvXzphRSzOevg8RVK734F7+TsSt LOiXjgSadsLGy9TOIVm6SfUxuRwLX57L4g1GitJGHMXWoRCLBlc1vMM8GXFUqd23mq H2CXLFJJgrfsHnld4eC8GQXP5hFr3VcAkBicXBNI= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbgHMLoZ (ORCPT ); Thu, 13 Aug 2020 07:44:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:39152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726192AbgHMLl3 (ORCPT ); Thu, 13 Aug 2020 07:41:29 -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 5328220771; Thu, 13 Aug 2020 11:41:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597318888; bh=fp5rvaq7NPsTUTrz3k3eLOHmPNbOzxflP+aP/tMnI8s=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KYj7rXs19Lz6LH2TFh6PXdj7TqS4MstDRdvp0d0TGAc3vpZcsYajEQrthDRsHBuyP NFeSg6VzPIr1KthHuXcB37fCPC/wslqBgQkZHM+IlhJKsxONjztCYDYdTz/SDNZGFs oytpTvC6KNesg+zoic/2U0HkUP6A6wj2dYHXxaXo= Date: Thu, 13 Aug 2020 13:41:38 +0200 From: Greg Kroah-Hartman To: Yang Yingliang Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org, Cameron Berkenpas , Peter Geis , Lu Fengqi , =?iso-8859-1?Q?Dani=EBl?= Sonck , Zhang Qiang , Thomas Lamprecht , Daniel Borkmann , Zefan Li , Tejun Heo , Roman Gushchin , Cong Wang , "David S. Miller" Subject: Re: [PATCH 4.19 016/133] cgroup: fix cgroup_sk_alloc() for sk_clone_lock() Message-ID: <20200813114138.GA3754843@kroah.com> References: <20200720152803.732195882@linuxfoundation.org> <20200720152804.513188610@linuxfoundation.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 13, 2020 at 07:30:55PM +0800, Yang Yingliang wrote: > Hi, > > On 2020/7/20 23:36, Greg Kroah-Hartman wrote: > > From: Cong Wang > > > > [ Upstream commit ad0f75e5f57ccbceec13274e1e242f2b5a6397ed ] > > > > When we clone a socket in sk_clone_lock(), its sk_cgrp_data is > > copied, so the cgroup refcnt must be taken too. And, unlike the > > sk_alloc() path, sock_update_netprioidx() is not called here. > > Therefore, it is safe and necessary to grab the cgroup refcnt > > even when cgroup_sk_alloc is disabled. > > > > sk_clone_lock() is in BH context anyway, the in_interrupt() > > would terminate this function if called there. And for sk_alloc() > > skcd->val is always zero. So it's safe to factor out the code > > to make it more readable. > > > > The global variable 'cgroup_sk_alloc_disabled' is used to determine > > whether to take these reference counts. It is impossible to make > > the reference counting correct unless we save this bit of information > > in skcd->val. So, add a new bit there to record whether the socket > > has already taken the reference counts. This obviously relies on > > kmalloc() to align cgroup pointers to at least 4 bytes, > > ARCH_KMALLOC_MINALIGN is certainly larger than that. > > > > This bug seems to be introduced since the beginning, commit > > d979a39d7242 ("cgroup: duplicate cgroup reference when cloning sockets") > > tried to fix it but not compeletely. It seems not easy to trigger until > > the recent commit 090e28b229af > > ("netprio_cgroup: Fix unlimited memory leak of v2 cgroups") was merged. > > > > Fixes: bd1060a1d671 ("sock, cgroup: add sock->sk_cgroup") > > Reported-by: Cameron Berkenpas > > Reported-by: Peter Geis > > Reported-by: Lu Fengqi > > Reported-by: Daniël Sonck > > Reported-by: Zhang Qiang > > Tested-by: Cameron Berkenpas > > Tested-by: Peter Geis > > Tested-by: Thomas Lamprecht > > Cc: Daniel Borkmann > > Cc: Zefan Li > > Cc: Tejun Heo > > Cc: Roman Gushchin > > Signed-off-by: Cong Wang > > Signed-off-by: David S. Miller > > Signed-off-by: Greg Kroah-Hartman > > --- > [...] > > +void cgroup_sk_clone(struct sock_cgroup_data *skcd) > > +{ > > + /* Socket clone path */ > > + if (skcd->val) { > > Compare to mainline patch, it's missing *if (skcd->no_refcnt)* check here. > > Is it a mistake here ? Possibly, it is in the cgroup_sk_free() call. Can you send a patch to fix this up? thanks, greg k-h