hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/fs/verity/enable.c
....@@ -391,25 +391,27 @@
391391 goto out_drop_write;
392392
393393 err = enable_verity(filp, &arg);
394
- if (err)
395
- goto out_allow_write_access;
396394
397395 /*
398
- * Some pages of the file may have been evicted from pagecache after
399
- * being used in the Merkle tree construction, then read into pagecache
400
- * again by another process reading from the file concurrently. Since
401
- * these pages didn't undergo verification against the file digest which
402
- * fs-verity now claims to be enforcing, we have to wipe the pagecache
403
- * to ensure that all future reads are verified.
396
+ * We no longer drop the inode's pagecache after enabling verity. This
397
+ * used to be done to try to avoid a race condition where pages could be
398
+ * evicted after being used in the Merkle tree construction, then
399
+ * re-instantiated by a concurrent read. Such pages are unverified, and
400
+ * the backing storage could have filled them with different content, so
401
+ * they shouldn't be used to fulfill reads once verity is enabled.
402
+ *
403
+ * But, dropping the pagecache has a big performance impact, and it
404
+ * doesn't fully solve the race condition anyway. So for those reasons,
405
+ * and also because this race condition isn't very important relatively
406
+ * speaking (especially for small-ish files, where the chance of a page
407
+ * being used, evicted, *and* re-instantiated all while enabling verity
408
+ * is quite small), we no longer drop the inode's pagecache.
404409 */
405
- filemap_write_and_wait(inode->i_mapping);
406
- invalidate_inode_pages2(inode->i_mapping);
407410
408411 /*
409412 * allow_write_access() is needed to pair with deny_write_access().
410413 * Regardless, the filesystem won't allow writing to verity files.
411414 */
412
-out_allow_write_access:
413415 allow_write_access(filp);
414416 out_drop_write:
415417 mnt_drop_write_file(filp);