Skip to contentSkip to conversation

Coverity complaints about new crypto code

DISCUSSION Jan Kara 2 participants 2 messages May 5, 2015

lore
Share & tools
lore

Jan Kara

author
#0 lore raw

Hi,

Coverity complains about the new ext4 crypto code. The complaint is that
ext4_fname_crypto_alloc_buffer() and ext4_fname_crypto_namelen_on_disk() check for ctx being NULL but they dereference it before that check. I've checked and didn't find callers that would actually pass NULL into these functions so do we want to remove the unused check or move the dereference? I think it would be worth cleaning up just that we don't fall into the trap sometime later...

Honza

----- Forwarded message from [email protected] -----

** CID 1296585: Null pointer dereferences (REVERSE_INULL) /fs/ext4/crypto_fname.c: 500 in ext4_fname_crypto_alloc_buffer()

________________________________________________________________________________________________________
*** CID 1296585: Null pointer dereferences (REVERSE_INULL) /fs/ext4/crypto_fname.c: 500 in ext4_fname_crypto_alloc_buffer()

494     int ext4_fname_crypto_alloc_buffer(struct ext4_fname_crypto_ctx *ctx,
495     				   u32 ilen, struct ext4_str *crypto_str)
496     {
497     	unsigned int olen;
498     	int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK);

499

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1296585: Null pointer dereferences (REVERSE_INULL)
Null-checking "ctx" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.

500     	if (!ctx)
501     		return -EIO;
502     	if (padding < EXT4_CRYPTO_BLOCK_SIZE)
503     		padding = EXT4_CRYPTO_BLOCK_SIZE;
504     	olen = ext4_fname_crypto_round_up(ilen, padding);
505     	crypto_str->len = olen;

** CID 1296586: Null pointer dereferences (REVERSE_INULL) /fs/ext4/crypto_fname.c: 476 in ext4_fname_crypto_namelen_on_disk()

________________________________________________________________________________________________________
*** CID 1296586: Null pointer dereferences (REVERSE_INULL) /fs/ext4/crypto_fname.c: 476 in ext4_fname_crypto_namelen_on_disk()

470     int ext4_fname_crypto_namelen_on_disk(struct ext4_fname_crypto_ctx *ctx,
471     				      u32 namelen)
472     {
473     	u32 ciphertext_len;
474     	int padding = 4 << (ctx->flags & EXT4_POLICY_FLAGS_PAD_MASK);

475

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

CID 1296586: Null pointer dereferences (REVERSE_INULL)
Null-checking "ctx" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.

476     	if (ctx == NULL)
477     		return -EIO;
478     	if (!(ctx->has_valid_key))
479     		return -EACCES;
480     	ciphertext_len = (namelen < EXT4_CRYPTO_BLOCK_SIZE) ?
481     		EXT4_CRYPTO_BLOCK_SIZE : namelen;

________________________________________________________________________________________________________

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR
#1 lore raw
Quoted 8 lines · Jan Kara

Coverity complains about the new ext4 crypto code. The complaint is that
ext4_fname_crypto_alloc_buffer() and ext4_fname_crypto_namelen_on_disk() check for ctx being NULL but they dereference it before that check. I've checked and didn't find callers that would actually pass NULL into these functions so do we want to remove the unused check or move the dereference? I think it would be worth cleaning up just that we don't fall into the trap sometime later...

I'm going to be posting a performance patch shortly that drops ext4_fname_crypto_ctx entirely (and with it those checks, obviously). So that should take care of that.

Cheers,

- Ted