Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1BFF4A7C95 for ; Tue, 13 Oct 2026 23:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791932704; cv=none; b=M2aBcNC0Ag8UPSslnLJXZASOlWK5rhCC5/6DSEwfgrrabxE6qSTYOzr6CrbM67lQ9XYpyXzis2pgPSIM+dvoZR9cl5MijMBrT/H5pzEYatQV3KaZ0qD5oGLv7uWVqJKP98VJdORjTAKYFceK4TzG4lkAzhGZrqEBoghf4eohVVo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1791932704; c=relaxed/simple; bh=SkIPOGple8dkYvlIPN+jFTIGwPSLOhXZpZ8RjCO1Raw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H+IO0cWkHMNGw8jLKA0cJ69MucUEuEkMkKaucfFy8JOPwkA0vmJdpI0H+HYKBxlgy4TFQ/ihdbMK3QChZLyMKYjhJCKqcuQuPanarK6JZX8tEqZbAiP/8AV3bR7FPyR4jqA5Hz7dhGP0sPK6AG0nCefTT46FCCv8rCYZcuNxsXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CPTr7vaY; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CPTr7vaY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 16A201F000FF; Tue, 13 Oct 2026 23:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1791932702; bh=cHgUSfg10SrNUvasgD6ScpIgH0kacQL+3+ofOQydi80=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=CPTr7vaYH0kD3PXQ5Yq5ao5+WhHaR78hLBlIDjExo4WK6g/VMv3plsSWFxe6N9Z1Q 0EP5ykcRH1CZTcSZe7qaIt+RF1a75/pBRjsFPwQZQC4CMfa4gMT+BvDBZdORNxj14t JJY+8+CaPu1XmFntU3WH3v/tGCJOLFvNEB4OQZY5qKgIkxVmhLrI3zSLXdA2d2s1eO QtbTm0UC5yVS0QZvnNeip5ws3mJyW6Q3J7AH7sIZjOcbKefUX8ayOXh1d+ArZdbhZ0 zAz8W30TSLFSsbiJGf2WCCU/xu/GH6v+3ogWRW9GVkusSaidqsY6EE2ywxkSV38E5J AIRHvTjpTX/eg== From: Sasha Levin To: stable@vger.kernel.org Cc: Christian Brauner , Sasha Levin Subject: [PATCH 7.2.y 1/2] nullfs: refuse file locks Date: Tue, 13 Oct 2026 19:05:00 -0400 Message-ID: <20261013230336.829040-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026101206-reexamine-jolliness-5e12@gregkh> References: <2026101206-reexamine-jolliness-5e12@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Christian Brauner [ Upstream commit 31a1fb90624d7e275db775a29a0e00a7f8b3df63 ] Refuse flock() and POSIX locks on nullfs. Its one inode is the root of every kernel thread and the following patches make it the directory that stands in for an unmounted mount, so a lock taken through one such directory would block the locks of every other holder and F_GETLK would tell them the pid of the holder. Give the directory file operations of its own: what libfs gives an empty directory plus ->lock and ->flock that fail with ENOLCK, the way a filesystem without lock support does. Link: https://patch.msgid.link/20261002-work-mount-fixes-4-v1-17-dd44b89d44ce@kernel.org Signed-off-by: Christian Brauner (Amutable) Stable-dep-of: e08f57a7dcb8 ("readdir: take no inode lock on an immutable directory") Signed-off-by: Sasha Levin --- fs/nullfs.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/fs/nullfs.c b/fs/nullfs.c index 20d3aa627a47d..fc79ca42bb178 100644 --- a/fs/nullfs.c +++ b/fs/nullfs.c @@ -8,6 +8,34 @@ static const struct super_operations nullfs_super_operations = { .statfs = simple_statfs, }; +static loff_t nullfs_dir_llseek(struct file *file, loff_t offset, int whence) +{ + /* an empty directory has two entries . and .. at offsets 0 and 1 */ + return generic_file_llseek_size(file, offset, whence, 2, 2); +} + +static int nullfs_dir_readdir(struct file *file, struct dir_context *ctx) +{ + dir_emit_dots(file, ctx); + return 0; +} + +/* the one inode of nullfs is shared by every holder, so no locks on it */ +static int nullfs_nolock(struct file *file, int cmd, struct file_lock *fl) +{ + return -ENOLCK; +} + +/* what libfs gives an empty directory, plus the refusal of file locks */ +static const struct file_operations nullfs_dir_operations = { + .llseek = nullfs_dir_llseek, + .read = generic_read_dir, + .iterate_shared = nullfs_dir_readdir, + .fsync = noop_fsync, + .lock = nullfs_nolock, + .flock = nullfs_nolock, +}; + static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc) { struct inode *inode; @@ -28,6 +56,7 @@ static int nullfs_fs_fill_super(struct super_block *s, struct fs_context *fc) /* nullfs is permanently empty... */ make_empty_dir_inode(inode); + inode->i_fop = &nullfs_dir_operations; simple_inode_init_ts(inode); inode->i_ino = 1; /* ... and immutable, reading it leaves no trace either. */ -- 2.53.0