Skip to content

Commit f0d07a9

Browse files
committed
ubifs: don't trigger assertion on invalid no-key filename
If userspace provides an invalid fscrypt no-key filename which encodes a hash value with any of the UBIFS node type bits set (i.e. the high 3 bits), gracefully report ENOENT rather than triggering ubifs_assert(). Test case with kvm-xfstests shell: . fs/ubifs/config . ~/xfstests/common/encrypt dev=$(__blkdev_to_ubi_volume /dev/vdc) ubiupdatevol $dev -t mount $dev /mnt -t ubifs mkdir /mnt/edir xfs_io -c set_encpolicy /mnt/edir rm /mnt/edir/_,,,,,DAAAAAAAAAAAAAAAAAAAAAAAAAA With the bug, the following assertion fails on the 'rm' command: [ 19.066048] UBIFS error (ubi0:0 pid 379): ubifs_assert_failed: UBIFS assert failed: !(hash & ~UBIFS_S_KEY_HASH_MASK), in fs/ubifs/key.h:170 Fixes: f4f61d2 ("ubifs: Implement encrypted filenames") Cc: <[email protected]> # v4.10+ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]>
1 parent f592efe commit f0d07a9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

fs/ubifs/dir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ static struct dentry *ubifs_lookup(struct inode *dir, struct dentry *dentry,
228228
if (nm.hash) {
229229
ubifs_assert(c, fname_len(&nm) == 0);
230230
ubifs_assert(c, fname_name(&nm) == NULL);
231+
if (nm.hash & ~UBIFS_S_KEY_HASH_MASK)
232+
goto done; /* ENOENT */
231233
dent_key_init_hash(c, &key, dir->i_ino, nm.hash);
232234
err = ubifs_tnc_lookup_dh(c, &key, dent, nm.minor_hash);
233235
} else {

0 commit comments

Comments
 (0)