From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796230674; b=GOs0cDG5llKwJFRAE/BTxBYgw537dWyMpazwZEJIuUZQLozp7jg+Jcm++AD9TylW9jbB rhZyzzqAbmqrAF0spQpv90LdWvYoGaWS9rJdSGJKQ2lzpin1/6W5nTw4FVh4INd4lcjsf cP3nEJhKkcegwoHU4cgMhuH11UENP+WakgAtOxs+l/jPoUKnqQvh+9Dk1/aif5dCsojnG S7cLaqdFeaHS9NsQ7avLYOFcLCAjWjQMfGiLTc4/GICinj5NbqdMhw1yRhkzv3TF0ENBl o4w55rvfjoje1ALspOxlVwrwVdGGyrZoa3EszJ683YCTadZklzYTI99aLo2p6M62AgA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796230674; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=twzlwyJ23NxxbtcE+HcFeHIhwUR8YWmq3G7IIGYHl9I=; b=vZOjNjdO7+7wSsy/oVp03Xi3j8A+ixSKE4GxYN5T3r/WMoeq55MLmc/x2Px0D5CggYZy aNWD/grKrHfmcQ+O2hjiMcvL16r45bZ+OcCBDZs1c/Q3Wh+8HXfcCRuvOftTrti0bZO4E u19fAe0djRBaCNqweDK2+mKv4uFqtrEiC7nh0k4/DZMN0wREFm+lw7DF99Mi2OfhE5JIz vvvPgt+yU0fiTyQ5+4yWRZKY+XaXSjjKNR4iGMexbC+xp9FTW3DJHu8nhLJHk7lPFZsyH PVBzLZw2Ja/qUrFTWQVW11VtrEdJHngovd8O697go1VybWzB8YTntYe/2/xc1ras6kA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Yr6cieyG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D9D35606A327; Wed, 2 Dec 2026 16:57:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Yr6cieyG Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB1F91F00896; Wed, 2 Dec 2026 16:57:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796230674; bh=twzlwyJ23NxxbtcE+HcFeHIhwUR8YWmq3G7IIGYHl9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Yr6cieyG8AwAA+mevNSF1nxzrn7VCpBN6TV9pAStc7p3/es21t4xCeq/1z9VR7h3n TP1iM2Xfh6O9hheNhUvAtLDk18EcdwhzzX+JKAa3zP/Xn4jpxxewiJn3R4/9QZFHj9 SPMYwQxNEd72PmBswYYXnYKY+zBr5i4XRSI6T11DT8J8vVomtHIye2KpZbYE3bd1gd J2JvRipR4a+lrxdFcet6f2gmXfJB/Bz8ZoAB/0NXBKJXAENDIr6nn8OpG/ReCLTmDj 3Jd+AllfgwATIdKF34UAfdhgakXfrevTfMJIdXY4fuikCqZ8ClEgyi2odlxaZFS2lr mI7Km/mIsNcHg== From: Andrey Albershteyn To: "fsdevel" , "linux-ext4" , "linux-btrfs" , "linux-f2fs" , "Eric Biggers" , "Christoph Hellwig" , "Carlos Maiolino" , "fsverity" , "linux-xfs" Cc: "Christian Brauner" , Andrey Albershteyn , david@fromorbit.com Subject: [PATCH v20 04/23] fs,fsverity: reject S_APPEND on fsverity inodes Date: Wed, 2 Dec 2026 17:56:34 +0100 Message-ID: <20261202165653.767961-5-aalbersh@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261202165653.767961-1-aalbersh@kernel.org> References: <20261202165653.767961-1-aalbersh@kernel.org> X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit fs-verity rejects enabling fsverity on append only files. However, there are two cases when FS_IOC_SETFLAGS can turn inode append only. The first one is right before the lock is taken in the enable_verity(), making original check useless. The second one is after lock in enable_verity() is unlocked, therefore, when merkle tree is being build and after fs-verity inode is sealed. This one is not critical, it just sets incompatible flags on inode but append-only inode will not get any writes anyway. Fix it by checking S_APPEND again under the lock, serializing this with vfs_fileattr_set() and reject S_APPEND on fsverity inodes. Fixes: 3fda4c617e84 ("fs-verity: implement FS_IOC_ENABLE_VERITY ioctl") Signed-off-by: Andrey Albershteyn --- fs/file_attr.c | 13 +++++++++++++ fs/verity/enable.c | 8 ++++++++ 2 files changed, 21 insertions(+) diff --git a/fs/file_attr.c b/fs/file_attr.c index 81bf55f9b255..a5e436711008 100644 --- a/fs/file_attr.c +++ b/fs/file_attr.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -209,6 +210,18 @@ static int fileattr_set_prepare(struct inode *inode, fa->flags &= ~FS_VERITY_FL; fa->fsx_xflags &= ~FS_XFLAG_VERITY; + /* + * FS_APPEND_FL is incompatible with fs-verity. FS_IOC_ENABLE_VERITY + * rejects append-only files, also reject turning a verity file + * append-only. + * + * Reject in both cases, after it has been sealed and while its Merkle + * tree is being built. + */ + if ((fa->flags & FS_APPEND_FL) && + ((old_ma->flags & FS_VERITY_FL) || fsverity_is_building(inode))) + return -EPERM; + /* * Project Quota ID state is only allowed to change from within the init * namespace. Enforce that restriction only if we are trying to change diff --git a/fs/verity/enable.c b/fs/verity/enable.c index d820c8d348ca..8a469ddf76ba 100644 --- a/fs/verity/enable.c +++ b/fs/verity/enable.c @@ -238,6 +238,14 @@ static int enable_verity(struct file *filp, err = -EEXIST; } else if (fsverity_is_building(inode)) { err = -EBUSY; + } else if (IS_APPEND(inode)) { + /* + * The check in fsverity_ioctl_enable() is done without the + * inode lock, so a concurrent FS_IOC_SETFLAGS could have set + * S_APPEND in the meantime. Recheck it here, serialized with + * ->fileattr_set(). + */ + err = -EPERM; } else { err = vops->begin_enable_verity(filp); if (!err) { -- 2.54.0