From: Eric Biggers <ebiggers@kernel.org>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-fscrypt@vger.kernel.org, linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org,
linux-integrity@vger.kernel.org, Jaegeuk Kim <jaegeuk@kernel.org>,
"Theodore Y . Ts'o" <tytso@mit.edu>,
Victor Hsieh <victorhsieh@google.com>,
Chandan Rajendra <chandan@linux.vnet.ibm.com>,
Dave Chinner <david@fromorbit.com>,
Christoph Hellwig <hch@lst.de>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v5 14/16] ext4: add basic fs-verity support
Date: Thu, 20 Jun 2019 20:17:36 -0700 [thread overview]
Message-ID: <20190621031736.GA742@sol.localdomain> (raw)
In-Reply-To: <20190620235938.GE5375@magnolia>
Hi Darrick,
On Thu, Jun 20, 2019 at 04:59:38PM -0700, Darrick J. Wong wrote:
> > diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
> > index 1cb67859e0518b..5a1deea3fb3e37 100644
> > --- a/fs/ext4/ext4.h
> > +++ b/fs/ext4/ext4.h
> > @@ -41,6 +41,7 @@
> > #endif
> >
> > #include <linux/fscrypt.h>
> > +#include <linux/fsverity.h>
> >
> > #include <linux/compiler.h>
> >
> > @@ -395,6 +396,7 @@ struct flex_groups {
> > #define EXT4_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/
> > #define EXT4_HUGE_FILE_FL 0x00040000 /* Set to each huge file */
> > #define EXT4_EXTENTS_FL 0x00080000 /* Inode uses extents */
> > +#define EXT4_VERITY_FL 0x00100000 /* Verity protected inode */
>
> Hmm, a new inode flag, superblock rocompat feature flag, and
> (presumably) the Merkle tree has some sort of well defined format which
> starts at the next 64k boundary past EOF.
>
> Would you mind updating the relevant parts of the ondisk format
> documentation in Documentation/filesystems/ext4/, please?
>
> I saw that the Merkle tree and verity descriptor formats themselves are
> documented in the first patch, so you could simply link the ext4
> documentation to it.
>
Sure, I'll update the ext4 documentation.
> > +/*
> > + * Read some verity metadata from the inode. __vfs_read() can't be used because
> > + * we need to read beyond i_size.
> > + */
> > +static int pagecache_read(struct inode *inode, void *buf, size_t count,
> > + loff_t pos)
> > +{
> > + while (count) {
> > + size_t n = min_t(size_t, count,
> > + PAGE_SIZE - offset_in_page(pos));
> > + struct page *page;
> > + void *addr;
> > +
> > + page = read_mapping_page(inode->i_mapping, pos >> PAGE_SHIFT,
> > + NULL);
> > + if (IS_ERR(page))
> > + return PTR_ERR(page);
> > +
> > + addr = kmap_atomic(page);
> > + memcpy(buf, addr + offset_in_page(pos), n);
> > + kunmap_atomic(addr);
> > +
> > + put_page(page);
> > +
> > + buf += n;
> > + pos += n;
> > + count -= n;
> > + }
> > + return 0;
> > +}
> > +
> > +/*
> > + * Write some verity metadata to the inode for FS_IOC_ENABLE_VERITY.
> > + * kernel_write() can't be used because the file descriptor is readonly.
> > + */
> > +static int pagecache_write(struct inode *inode, const void *buf, size_t count,
> > + loff_t pos)
> > +{
> > + while (count) {
> > + size_t n = min_t(size_t, count,
> > + PAGE_SIZE - offset_in_page(pos));
> > + struct page *page;
> > + void *fsdata;
> > + void *addr;
> > + int res;
> > +
> > + res = pagecache_write_begin(NULL, inode->i_mapping, pos, n, 0,
> > + &page, &fsdata);
> > + if (res)
> > + return res;
> > +
> > + addr = kmap_atomic(page);
> > + memcpy(addr + offset_in_page(pos), buf, n);
> > + kunmap_atomic(addr);
> > +
> > + res = pagecache_write_end(NULL, inode->i_mapping, pos, n, n,
> > + page, fsdata);
> > + if (res < 0)
> > + return res;
> > + if (res != n)
> > + return -EIO;
> > +
> > + buf += n;
> > + pos += n;
> > + count -= n;
> > + }
> > + return 0;
> > +}
>
> This same code is duplicated in the f2fs patch. Is there a reason why
> they don't share this common code? Even if you have to hide it under
> fs/verity/ ?
>
Yes, pagecache_read() and pagecache_write() are identical between ext4 and f2fs.
I didn't put them in fs/verity/ because the "metadata past EOF" approach is a
choice of ext4 and f2fs and not intrinsic to the fs-verity feature itself, so to
avoid confusion I made the fs/verity/ support layer be completely clean of any
assumption that that's the way filesystems implement fs-verity.
Also, making the fsverity_operations call back into fs/verity/ adds a little
extra conceptual complexity about what belongs where, since then we'd have a
call stack of filesystem => fs/verity/ => filesystem => fs/verity/.
But if people would rather that ext4 and f2fs share these two functions anyway,
then sure, we could move them into fs/verity/, and other filesystems (if they
take a different approach to fs-verity) simply won't use them.
- Eric
next prev parent reply other threads:[~2019-06-21 3:17 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 20:50 [PATCH v5 00/16] fs-verity: read-only file-based authenticity protection Eric Biggers
2019-06-20 20:50 ` [PATCH v5 01/16] fs-verity: add a documentation file Eric Biggers
2019-06-22 22:10 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 02/16] fs-verity: add MAINTAINERS file entry Eric Biggers
2019-06-22 22:11 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 03/16] fs-verity: add UAPI header Eric Biggers
2019-06-22 22:11 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 04/16] fs: uapi: define verity bit for FS_IOC_GETFLAGS Eric Biggers
2019-06-22 22:11 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 05/16] fs-verity: add Kconfig and the helper functions for hashing Eric Biggers
2019-06-22 22:17 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 06/16] fs-verity: add inode and superblock fields Eric Biggers
2019-06-22 22:18 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 07/16] fs-verity: add the hook for file ->open() Eric Biggers
2019-06-22 22:28 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 08/16] fs-verity: add the hook for file ->setattr() Eric Biggers
2019-06-22 22:28 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 09/16] fs-verity: add data verification hooks for ->readpages() Eric Biggers
2019-06-22 22:32 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 10/16] fs-verity: implement FS_IOC_ENABLE_VERITY ioctl Eric Biggers
2019-06-22 22:43 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 11/16] fs-verity: implement FS_IOC_MEASURE_VERITY ioctl Eric Biggers
2019-06-22 22:43 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 12/16] fs-verity: add SHA-512 support Eric Biggers
2019-06-22 22:44 ` Jaegeuk Kim
2019-06-20 20:50 ` [PATCH v5 13/16] fs-verity: support builtin file signatures Eric Biggers
2019-06-20 20:50 ` [PATCH v5 14/16] ext4: add basic fs-verity support Eric Biggers
2019-06-20 23:59 ` Darrick J. Wong
2019-06-21 3:17 ` Eric Biggers [this message]
2019-06-20 20:50 ` [PATCH v5 15/16] ext4: add fs-verity read support Eric Biggers
2019-06-20 20:50 ` [PATCH v5 16/16] f2fs: add fs-verity support Eric Biggers
2019-06-22 23:12 ` Jaegeuk Kim
2019-06-25 7:55 ` Chao Yu
2019-06-25 17:52 ` Eric Biggers
2019-06-26 7:34 ` Chao Yu
2019-06-26 18:21 ` Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190621031736.GA742@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=chandan@linux.vnet.ibm.com \
--cc=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=hch@lst.de \
--cc=jaegeuk@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fscrypt@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-integrity@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=tytso@mit.edu \
--cc=victorhsieh@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).