Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3263418pxk; Mon, 21 Sep 2020 09:10:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxxrjXjhX0qRXk09QBMnu/Dmre+jDCsN22yQH5DM1Vr5PrGRVP6jCrcrlK1bo97Rwavc0t9 X-Received: by 2002:a05:6402:3c8:: with SMTP id t8mr394309edw.266.1600704618427; Mon, 21 Sep 2020 09:10:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600704618; cv=none; d=google.com; s=arc-20160816; b=wNVZ67PJP/vzhNvoWFNj+/lnqQVksCLDsLveTFFre7TCk7RGLXpR0jUHd2vammqtJp mCYONU8VDphjY69ohRLayi1f8viyEG+lb5rQ40aFyQiq8XLDDlybdTzRG/oPksAbn1BY 9R8sFy/XXzwmlJqZ0vfqI0PBE7tu7ACwlJP/yjMhfI1kouo3XknnzLCtO6Bet/G0oaVF xtUlajbPJvDw+F2AjRAfrAol2vdLAVzX1wLALfiZ4EFWge2n8x1wqU0o1l9t7zGkAQqm V/D56SauaYx40mRfdixjGsDBCS/ohAnvnQ4YBEg+2sAGCRRwv/YTZL/lyfVD8o/uOMhY qJEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=SABUEUknBHJI8XlIA/l+ZHp7zAzU1dU+58RVw/KjEuw=; b=mabNU/ahsT2HpY45cNDTZHAoayy8idJW38BApkwZ74P+5UhEeXpqDNBFIKl3blVe6Y TJqjiwUL60zfV69kQRzNlse4AcZ2lGVRMTTBmd9AjEW3KEU/Fez8S1UvCcwaGcIGkl7z oKJ10oAD+kcBh6UdBUxlLdcYotqOtV8ay5eU4x415babf/MruZWaE52/H3QYQo0ce4kb iCHbH24EoEpCPqtDd5dpFijktGHboTQNCD86aC1U+GAgGlLrI0qlJDIAD2mBEr8eB/qj OB7sEvLZXJF/ILiriF2/o3G0OPtNea0Q6dl5atCWua+2Ygag62gKf64v1tFgenX9ELeb MIog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=SWJS4DLz; 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=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f27si3792362ejf.129.2020.09.21.09.09.53; Mon, 21 Sep 2020 09:10:18 -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=@suse.com header.s=susede1 header.b=SWJS4DLz; 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=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727914AbgIUQGq (ORCPT + 99 others); Mon, 21 Sep 2020 12:06:46 -0400 Received: from mx2.suse.de ([195.135.220.15]:33304 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727671AbgIUQGq (ORCPT ); Mon, 21 Sep 2020 12:06:46 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1600704404; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=SABUEUknBHJI8XlIA/l+ZHp7zAzU1dU+58RVw/KjEuw=; b=SWJS4DLzBr1XYJsbzXBHxVnp3x0jngu5ZA9hjkytnwNEadMKiwGVK+863dDFiMMpweVD0j A30wgvwy9Ezspe+Jhctgg1TetRY+U//5LLP8Hk3YmRR5XfqHxXgxUlAMy1jlMu+FdbuCfF 4MHltGl/TtTmsBsRFH0q8WyeECFzuOw= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 036E5B2A7; Mon, 21 Sep 2020 16:07:21 +0000 (UTC) Date: Mon, 21 Sep 2020 18:06:43 +0200 From: Michal Hocko To: Christian Brauner Cc: Tejun Heo , Peter Xu , Linus Torvalds , Jason Gunthorpe , John Hubbard , Leon Romanovsky , Linux-MM , Linux Kernel Mailing List , "Maya B . Gokhale" , Yang Shi , Marty Mcfadden , Kirill Shutemov , Oleg Nesterov , Jann Horn , Jan Kara , Kirill Tkhai , Andrea Arcangeli , Christoph Hellwig , Andrew Morton Subject: Re: [PATCH 1/4] mm: Trial do_wp_page() simplification Message-ID: <20200921160643.GP12990@dhcp22.suse.cz> References: <20200917193824.GL8409@ziepe.ca> <20200918164032.GA5962@xz-x1> <20200921134200.GK12990@dhcp22.suse.cz> <20200921141830.GE5962@xz-x1> <20200921142834.GL12990@dhcp22.suse.cz> <20200921143847.GB4268@mtj.duckdns.org> <20200921144355.mrzc66lina3dkfjq@wittgenstein> <20200921145537.GM12990@dhcp22.suse.cz> <20200921150450.3mjjb3p3jwgatn4v@wittgenstein> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921150450.3mjjb3p3jwgatn4v@wittgenstein> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon 21-09-20 17:04:50, Christian Brauner wrote: > On Mon, Sep 21, 2020 at 04:55:37PM +0200, Michal Hocko wrote: > > On Mon 21-09-20 16:43:55, Christian Brauner wrote: > > > On Mon, Sep 21, 2020 at 10:38:47AM -0400, Tejun Heo wrote: > > > > Hello, > > > > > > > > On Mon, Sep 21, 2020 at 04:28:34PM +0200, Michal Hocko wrote: > > > > > Fundamentaly CLONE_INTO_CGROUP is similar to regular fork + move to the > > > > > target cgroup after the child gets executed. So in principle there > > > > > shouldn't be any big difference. Except that the move has to be explicit > > > > > and the the child has to have enough privileges to move itself. I am not > > > > > > > > Yeap, they're supposed to be the same operations. We've never clearly > > > > defined how the accounting gets split across moves because 1. it's > > > > inherently blurry and difficult 2. doesn't make any practical difference for > > > > the recommended and vast majority usage pattern which uses migration to seed > > > > the new cgroup. CLONE_INTO_CGROUP doesn't change any of that. > > > > > > > > > completely sure about CLONE_INTO_CGROUP model though. According to man > > > > > clone(2) it seems that O_RDONLY for the target cgroup directory is > > > > > sufficient. That seems much more relaxed IIUC and it would allow to fork > > > > > into a different cgroup while keeping a lot of resources in the parent's > > > > > proper. > > > > > > > > If the man page is documenting that, it's wrong. cgroup_css_set_fork() has > > > > an explicit cgroup_may_write() test on the destination cgroup. > > > > CLONE_INTO_CGROUP should follow exactly the same rules as regular > > > > migrations. > > > > > > Indeed! > > > The O_RDONLY mention on the manpage doesn't make sense but it is > > > explained that the semantics are exactly the same for moving via the > > > filesystem: > > > > OK, if the semantic is the same as for the task migration then I do not > > see any (new) problems. Care to point me where the actual check is > > enforced? For the migration you need a write access to cgroup.procs but > > if the API expects directory fd then I am not sure how that would expose > > the same behavior. > > kernel/cgroup/cgroup.c:cgroup_csset_fork() > > So there's which is the first check for inode_permission() essentially: > > /* > * Verify that we the target cgroup is writable for us. This is > * usually done by the vfs layer but since we're not going through > * the vfs layer here we need to do it "manually". > */ > ret = cgroup_may_write(dst_cgrp, sb); > if (ret) > goto err; > > and what you're referring to is checked right after in: > > ret = cgroup_attach_permissions(cset->dfl_cgrp, dst_cgrp, sb, > !(kargs->flags & CLONE_THREAD)); > if (ret) > goto err; > > which calls: > > ret = cgroup_procs_write_permission(src_cgrp, dst_cgrp, sb); > if (ret) > return ret; > > That should be what you're looking for. I've also added selftests as > always that verify this behavior under: > > tools/testing/selftests/cgroup/ > > as soon as CLONE_INTO_CGROUP is detected on the kernel than all the > usual tests are exercised using CLONE_INTO_CGROUP so we should've seen > any regression hopefully. Thanks a lot for this clarification! So I believe the only existing bug is in documentation which should be explicit that the cgroup fd read access is not sufficient because it also requires to have a write access for cgroup.procs in the same directory at the time of fork. I will send a patch if I find some time for that. Thanks! -- Michal Hocko SUSE Labs