ext4: fix memory leaks in ext4_fname_{setup_filename,prepare_lookup}

[ Upstream commit 7ca4b085f4 ]

If the filename casefolding fails, we'll be leaking memory from the
fscrypt_name struct, namely from the 'crypto_buf.name' member.

Make sure we free it in the error path on both ext4_fname_setup_filename()
and ext4_fname_prepare_lookup() functions.

Cc: stable@kernel.org
Fixes: 1ae98e295f ("ext4: optimize match for casefolded encrypted dirs")
Signed-off-by: Luís Henriques <lhenriques@suse.de>
Reviewed-by: Eric Biggers <ebiggers@google.com>
Link: https://lore.kernel.org/r/20230803091713.13239-1-lhenriques@suse.de
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
[ fs/ext4/crypto.c was removed by commit
  a7550b30ab ("ext4 crypto: migrate into vfs's crypto engine") since
  v4.8, so apply this patch to fs/ext4/ext4.h in v5.15. Move
  ext4_fname_free_filename() to the front of ext4_fname_setup_filename()
  to fix a build issue. ]
Signed-off-by: Bin Lan <lanbincn@139.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Luís Henriques 2026-01-28 11:07:20 +00:00 • committed by Greg Kroah-Hartman
commit 98fc9c2cc4