From: Eric Biggers <ebiggers@kernel.org>
To: Alexander Larsson <alexl@redhat.com>
Cc: miklos@szeredi.hu, linux-unionfs@vger.kernel.org,
amir73il@gmail.com, tytso@mit.edu, fsverity@lists.linux.dev
Subject: Re: [PATCH 5/6] ovl: Validate verity xattr when resolving lowerdata
Date: Thu, 27 Apr 2023 17:58:20 +0000 [thread overview]
Message-ID: <ZEq3vN09rhEAr19w@gmail.com> (raw)
In-Reply-To: <CAL7ro1EYZXUQM+Ygp3aO8-rWD0ULZyaJH4rN_+88LNS4h5p78w@mail.gmail.com>
On Thu, Apr 27, 2023 at 09:22:57AM +0200, Alexander Larsson wrote:
> On Wed, Apr 26, 2023 at 11:47 PM Eric Biggers <ebiggers@kernel.org> wrote:
> >
> > On Thu, Apr 20, 2023 at 09:44:04AM +0200, Alexander Larsson wrote:
> > > + err = fsverity_get_digest(d_inode(datapath->dentry), actual_digest, &verity_algo);
> > > + if (err < 0) {
> > > + pr_warn_ratelimited("lower file '%pd' has no fs-verity digest\n", datapath->dentry);
> > > + return -EIO;
> > > + }
> > > +
> > > + if (digest_len != hash_digest_size[verity_algo] ||
> > > + memcmp(required_digest, actual_digest, digest_len) != 0) {
> > > + pr_warn_ratelimited("lower file '%pd' has the wrong fs-verity digest\n",
> > > + datapath->dentry);
> > > + return -EIO;
> > > + }
> > > +
> > > + return 0;
> >
> > This is incorrect because the digest algorithm is not being compared.
>
> This is actually an interesting question. How much are things weakened
> by comparing the digest size, but not comparing the digest type. Like,
> suppose the xattr has a sha256 digest (32 bytes), how likely is there
> to be another new supported verity algorithm of the same digest size
> where you can force it to produce matching digests?
It might actually be fairly likely, considering that whenever a system includes
a choice of cryptographic algorithm, it tends to grow to include many different
algorithms. Some of the reasons for this include:
- Algorithms can become outdated and broken, yet systems often have to
continue to support such algorithms for backwards compatibility.
- People sometimes insist on using "national pride" algorithms, e.g. due to
government regulations. For example, in China people can be required to use
Chinese algorithms instead of the U.S. / NIST algorithms. See e.g. the
existing support for SM3, SM4, Streebog, and Aria in the kernel crypto API
and various other kernel subsystems.
- Non-cryptographic algorithms might be added for use cases that don't
actually require cryptographic security, e.g. integrity-only.
I'd strongly discourage you from building something whose security critically
depends on every algorithm that may ever exist being cryptographically secure.
Also, two hash algorithms that are each secure individually are not necessarily
secure when used as alternatives sharing the same output space. E.g. consider
algorithm1 = SHA-256(data) and algorithm2 = SHA-256(data with all bits flipped).
>
> I ask because ideally we want to minimize the size of the xattrs,
> since they are stored for each file, and not having to specify the
> type for each saves space. Currently the only two supported algorithms
> (sha256 and sha512) are different sizes, so we essentially compare
> type by comparing the size.
>
> I see three options here:
> 1) Only compare digest + size (like now)
> 2) Assume size 32 means sha256, and 64 means sha512 and validate that
> 3) Use more space in the xattr to store an algorithm type
Just store the algorithm alongside the digest. It's just 1 extra byte.
- Eric
next prev parent reply other threads:[~2023-04-27 17:58 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 7:43 [PATCH 0/6] ovl: Add support for fs-verity checking of lowerdata Alexander Larsson
2023-04-20 7:44 ` [PATCH 1/6] fsverity: Export fsverity_get_digest Alexander Larsson
2023-04-20 7:44 ` [PATCH 2/6] ovl: Break out ovl_entry_path_real() from ovl_i_path_real() Alexander Larsson
2023-04-20 12:12 ` Amir Goldstein
2023-04-20 7:44 ` [PATCH 3/6] ovl: Break out ovl_entry_path_lowerdata() from ovl_path_lowerdata() Alexander Larsson
2023-04-20 12:14 ` Amir Goldstein
2023-04-20 7:44 ` [PATCH 4/6] ovl: Add framework for verity support Alexander Larsson
2023-04-20 8:39 ` Amir Goldstein
2023-04-25 11:19 ` Miklos Szeredi
2023-04-25 13:33 ` Alexander Larsson
2023-04-25 19:07 ` Miklos Szeredi
2023-04-20 7:44 ` [PATCH 5/6] ovl: Validate verity xattr when resolving lowerdata Alexander Larsson
2023-04-20 12:06 ` Amir Goldstein
2023-04-27 7:33 ` Alexander Larsson
2023-04-26 21:47 ` Eric Biggers
2023-04-27 7:22 ` Alexander Larsson
2023-04-27 17:58 ` Eric Biggers [this message]
2023-04-20 7:44 ` [PATCH 6/6] ovl: Handle verity during copy-up Alexander Larsson
2023-04-20 12:17 ` Amir Goldstein
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=ZEq3vN09rhEAr19w@gmail.com \
--to=ebiggers@kernel.org \
--cc=alexl@redhat.com \
--cc=amir73il@gmail.com \
--cc=fsverity@lists.linux.dev \
--cc=linux-unionfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=tytso@mit.edu \
/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