linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] odd check in ceph_encode_encrypted_dname()
@ 2025-02-14  2:47 Al Viro
  2025-02-14  3:28 ` Al Viro
  2025-02-14 15:30 ` Jeff Layton
  0 siblings, 2 replies; 21+ messages in thread
From: Al Viro @ 2025-02-14  2:47 UTC (permalink / raw)
  To: Luís Henriques; +Cc: ceph-devel, linux-fsdevel, Ilya Dryomov

AFAICS, this

        /* To understand the 240 limit, see CEPH_NOHASH_NAME_MAX comments */
        WARN_ON(elen > 240);
        if ((elen > 0) && (dir != parent)) {
                char tmp_buf[NAME_MAX];

                elen = snprintf(tmp_buf, sizeof(tmp_buf), "_%.*s_%ld",
                                elen, buf, dir->i_ino);
                memcpy(buf, tmp_buf, elen);
        }

could drop the (elen > 0) part of the test.  elen comes from
        elen = ceph_base64_encode(cryptbuf, len, buf);
and that can't return a non-positive unless the second argument is 0 or
above 1G.  The latter is flat-out impossible - right before that call
we have
        /* hash the end if the name is long enough */
        if (len > CEPH_NOHASH_NAME_MAX) {
                u8 hash[SHA256_DIGEST_SIZE];
                u8 *extra = cryptbuf + CEPH_NOHASH_NAME_MAX;

                /*
                 * hash the extra bytes and overwrite crypttext beyond that
                 * point with it
                 */
                sha256(extra, len - CEPH_NOHASH_NAME_MAX, hash);
                memcpy(extra, hash, SHA256_DIGEST_SIZE);
                len = CEPH_NOHASH_NAME_MAX + SHA256_DIGEST_SIZE;
        }
which obviously caps it with CEPH_NOHASH_NAME_MAX + SHA256_DIGEST_SIZE,
i.e. (180 - SHA256_DIGEST_SIZE) + SHA256_DIGEST_SIZE.

The former would have to come from
        if (!fscrypt_fname_encrypted_size(dir, iname.len, NAME_MAX, &len)) {
                elen = -ENAMETOOLONG;
                goto out;
        }
and since fscrypt_fname_encrypted_size() must've returned true, we have
len no less than FSCRYPT_FNAME_MIN_MSG_LEN, i.e. it's 16 or greater.

That stuff went into the tree in dd66df0053ef8 "ceph: add support for encrypted
snapshot names" and as far as I can tell, everything above had been applicable
back then too.

Am I missing something subtle here?  Can elen be non-positive at that point?

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2025-02-21  1:21 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-14  2:47 [RFC] odd check in ceph_encode_encrypted_dname() Al Viro
2025-02-14  3:28 ` Al Viro
2025-02-14 14:05   ` Luis Henriques
2025-02-14 15:41   ` Jeff Layton
2025-02-14 16:05     ` Luis Henriques
2025-02-15  4:46       ` Al Viro
2025-02-15  4:47         ` [PATCH 1/2] prep for ceph_encode_encrypted_fname() fixes Al Viro
2025-02-15 12:41           ` Jeff Layton
2025-02-15  4:47         ` [PATCH 2/2] ceph: fix a race with rename() in ceph_mdsc_build_path() Al Viro
2025-02-15 12:42           ` Jeff Layton
2025-02-15 15:39         ` [RFC] odd check in ceph_encode_encrypted_dname() Luis Henriques
2025-02-17 17:56           ` Viacheslav Dubeyko
2025-02-17 18:48             ` Luis Henriques
2025-02-17 22:04               ` Viacheslav Dubeyko
2025-02-18  1:21                 ` Al Viro
2025-02-18 23:52                   ` Al Viro
2025-02-19  0:58                     ` Viacheslav Dubeyko
2025-02-19  2:18                       ` Al Viro
2025-02-19 23:22                         ` Viacheslav Dubeyko
2025-02-21  1:21                         ` Viacheslav Dubeyko
2025-02-14 15:30 ` Jeff Layton

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).