From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.121.94.185 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796219844; b=ZWDNy4Mr07ZAMGzK3FMiIPwWYGJA9D74zzkdhfhpg6Fu9H47BkFSXG2pw4KCeM8MqBKq utCfuLZ+2fzRIUe0O2TaYpH2KPlSEvfbL7BQVtEybpYaWTxImPDGEnNrNlO5nYSJwjMSB mHgB66zCd0s2PLP5YRJuoWsQxECpFMJ6SGGH/hck2Cna4NRsxYI8nwl+DWoYS5QDvD4i9 +qD0KQqL4MXg+uTyZGJykLdCe4jirxPM+u2+0zWdZOeXnCVq6rsmglT4jwfF9SUHTQuNt d9Ln3vOCMgzkipKyvjsltv8xg/O30bvfP7gG7dt1lE9jQqfA8r12PObJUeuZGUwGCNQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796219844; h=DMARC-Filter:X-KPN-MessageId:Received:Received:DKIM-Signature: X-KPN-MID:X-CMASSUN:X-KPN-VerifiedSender:Received:Date:From:To:Cc: Message-ID:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:X-Priority:Importance:X-Originating-IP; bh=/XFdFeoLg3E0UDbNyC7e0/kN3DF6NhvOYfRs02ijuE8=; b=OJsx3vmBOKQI/OscdnWTdSwcRcU5WJGp2WH0hswikUz3kK3Wbv+v3dRJANggHxxQczIw MP0FxHmN0hWk2MogR0Sb4JbdAWJxUbHCI58cV+ursTYdGipUvLqV44c/q0mvuyfwlgAw/ wtI8cdR+ajAjH497YTM6mM0TbmT/bvAQrqr+b0oCKLwkKxsUfSbPTpvc+8gjT5xjqfr5K vFU534VmfBelO0I2c2rt0be7wilPjNxmieboypRS+z4M7cjqm79qztMq5wUK+BC3giTLt 690e1pvFoc9JINciGb8S4rmPWo0kww+k3hKuu+Pg4xcYtk0O+7lXi2ppRm/ZZFCOrOw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=xs4all.nl; spf=pass smtp.mailfrom=xs4all.nl; dkim=pass header.d=xs4all.nl header.i=@xs4all.nl header.a=rsa-sha256 header.s=xs4all01 header.b=eRfOm2iv; arc=none smtp.remote-ip=195.121.94.185 Received: from ewsoutbound.kpnmail.nl (ewsoutbound.kpnmail.nl [195.121.94.185]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67192606A322 for ; Wed, 2 Dec 2026 13:57:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 67192606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=xs4all.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=xs4all.nl Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=xs4all.nl header.i=@xs4all.nl header.a=rsa-sha256 header.s=xs4all01 header.b=eRfOm2iv X-KPN-MessageId: 440f9204-ee58-11f1-964d-005056999439 Received: from mta.kpnmail.nl (unknown [10.31.161.189]) by ewsoutbound.so.kpn.org (Halon) with ESMTPS id 440f9204-ee58-11f1-964d-005056999439; Wed, 02 Dec 2026 14:57:09 +0100 (CET) Received: from mtaoutbound.kpnmail.nl (unknown [10.128.135.190]) by mta.kpnmail.nl (Halon) with ESMTP id 44098e57-ee58-11f1-b7ab-0050569981f5; Wed, 02 Dec 2026 14:57:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xs4all.nl; s=xs4all01; h=content-type:mime-version:subject:message-id:to:from:date; bh=/XFdFeoLg3E0UDbNyC7e0/kN3DF6NhvOYfRs02ijuE8=; b=eRfOm2iv0HPBjGvrZLrrpTtDncJWYyrr34kRie0tAeinvU8+TFaQx2ygJgd5wYH7Tm69/FoaxrqS/ PigSeuaz+GWyYNKwxrEchye52OAKuwVxMZoRKWLp4Hl1yhEJXCR8r7qZ3oL2QxkXG6vBPbW4cfSWaP XHKQ/O4M1GQGGqatqzb652x92zReZgxuQ3RD7RknjswMqkAda/WzRXEg2QZM6pOGRiFsd2qkKY3IVr qm1BH5kF5bzH8vCg5FHKmMIpZdWqcXrIFPCOJQPZ0MCqceCuECghuOBcHSzSJffr6riUP7E4+uKON5 QuYwbSj6jWlzi6ARnlVHmagzUdQNzng== X-KPN-MID: 33|Bcys4V9R5ZwUGgaEJFR7r7CCcQ6bohqvm4AEh/7dDmKuXOOntXcvJbf5/S6wuaA j99cRzzUuaOVcUVg7itedCcbti3KozRCrro+VYZrP1r0= X-CMASSUN: 33|JOzWTCQbMYp9DkjGd+LbWHUCjDG9rLhBI7EZtPxjyNZWrZJa0f2531Vd6ug4aAJ KOAaLGkGp/lluekIX2qqSZQ== X-KPN-VerifiedSender: Yes Received: from cpxoxapps-mh01 (cpxoxapps-mh01.personalcloud.so.kpn.org [10.128.135.207]) by mtaoutbound.kpnmail.nl (Halon) with ESMTPSA id 43ffadb1-ee58-11f1-94bb-005056995d6c; Wed, 02 Dec 2026 14:57:09 +0100 (CET) Date: Wed, 2 Dec 2026 14:57:09 +0100 (CET) From: Jori Koolstra To: Christian Brauner Cc: viro@zeniv.linux.org.uk, jack@suse.cz, neil@brown.name, cyphar@cyphar.com, jlayton@kernel.org, amir73il@gmail.com, shakeel.butt@linux.dev, gregkh@linuxfoundation.org, tj@kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <1061093790.3487073.1796219829053@kpc.webmail.kpnmail.nl> Subject: Re: [PATCH v8 00/12] vfs: add O_CREAT|O_DIRECTORY to open*(2) X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Priority: 3 Importance: Normal > Op 30-11-2026 15:53 CET schreef Christian Brauner : > > > On Sun, Nov 22, 2026 at 10:20:23PM +0100, Jori Koolstra wrote: > > However, I am not sure that relying on holding the parent's i_rwsem is > > sufficient for the atomicity that we are trying to provide. Afaict nothing > > in the kernfs layer prevents you from removing a grandparent and a recursive > > kernfs_remove() of an ancestor never touches the immediate parent's i_rwsem. > > cgroup cannot hit it because cgroup_destroy_locked() refuses to remove a > group with online children. The only other case is resctrl. > > While an rmdir() of a control group removes mon_groups/ without > ever taking the i_rwsem of mon_groups it still can't hand out the wrong > directory. > > The lookup in kernfs_iop_mkdir() runs under kernfs_rwsem and either > finds nothing or finds an inactive node that kernfs_get_inode_locked() > refuses. And both end in -ESTALE. Hmm, yes, the draining may drop the kernfs_rwsem, but at that point all the kn descendants will have been deactivated under kernfs_rwsem and a racing mkdir will result in -ESTALE. Or mkdir reaches the lookup first and grabs the rwsem, and then the rmdir is as if it never raced but just happened after the mkdir, and you end up with an fd pointing to a removed dir. This is fine because it is still the dir the process created (although not much can be done with it, I think?) So if I am correct then, none of this is protected by the mutexes of cgroup and resctrl, and also not by the inode rwsem. The guarantees run of the kernfs locking itself. If that is true, I think the comment: /* * Find the node that ->mkdir() created. The parent's i_rwsem is * held, so only a removal from inside the kernel can make it go * away again, and then the open fails like one of a removed * directory. */ may be a bit misleading then. Userspace can trigger removal and race protection does not come from the i_rwsem at all. Can you clarify this? I must admit that I find the locking here not easy to grasp. I am just making sure I am on the same page. > > Afaict, nothign in between can grab that name: > > * kernfs_add_one() refuses a parent that is being removed > * a new node of that name under a live parent needs the i_rwsem we're holding > > So either you get the directory you created or the open fails. > > > Also, returning -ESTALE, if you set LOOKUP_REVAL, can make open(O_CREAT|O_DIRECTORY) > > return -ENOENT. Not sure if that is what you want. > > I think that's what we want. The retry runs after the removal so it > returns what you'd get if the rmdir() had won outright. OK, the point I wanted to make is stupid because this also happens when any part of the mkdir path does not exist. But, now that I reread all the code, I guess that removing a grandfather in resctrl might end you up with -ENODEV. I think we should get this in line with the -ESTALE return you've added. But this is another patch. Agree? Best, Jori.