lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <BFC2DE9E-82FA-4F76-9BD2-B505324F3557@dilger.ca>
Date:   Tue, 7 Apr 2020 11:21:01 -0600
From:   Andreas Dilger <adilger@...ger.ca>
To:     Harshad Shirwadkar <harshadshirwadkar@...il.com>,
        Jan Kara <jack@...e.cz>
Cc:     linux-ext4@...r.kernel.org
Subject: Re: [PATCH v2 3/3] ext4: reimplement ext4_empty_dir() using
 is_dirent_block_empty

On Apr 7, 2020, at 12:46 AM, Harshad Shirwadkar <harshadshirwadkar@...il.com> wrote:
> 
> The new function added in this patchset adds an efficient way to
> check if a dirent block is empty. Based on that, reimplement
> ext4_empty_dir().
> 
> This is a new patch added in V2.
> 
> Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@...il.com>

Again, a very minor style change iff patch is refreshed.

Reviewed-by: Andreas Dilger <adilger@...ger.ca>


While looking at this code, I noticed that ext4_empty_dir() considers a
directory without a "." or ".." entry to be empty.  I see this was changed
in 64d4ce8923 ("ext4: fix ext4_empty_dir() for directories with holes").
I can understand that we want to not die on corrupted leaf blocks, but it
isn't clear to me that it is a good idea to allow deleting an entire
directory tree if the first block has an error (missing "." or ".." as the
first and second entries) but is otherwise valid.  There were definitely
bugs in the past that made "." or ".." not be the first and second entries.

That isn't a problem in this patch, but seems dangerous in general.  It
doesn't seem like the directory shrinking would trigger this case, since it
is checking for individual empty blocks rather than using ext4_empty_dir().

> diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
> @@ -3218,34 +3219,26 @@ bool ext4_empty_dir(struct inode *inode)
> 		brelse(bh);
> 		return true;
> 	}
> +	de = ext4_next_entry(de, sb->s_blocksize);
> +	if (!is_empty_dirent_block(inode, bh, de)) {
> +		brelse(bh);
> +		return false;
> +	}
> +	brelse(bh);
> +
> +	for (lblk = 1; lblk < inode->i_size >> EXT4_BLOCK_SIZE_BITS(sb);
> +			lblk++) {

(style) should be aligned after '(' on previous line

> +		bh = ext4_read_dirblock(inode, lblk, EITHER);
> +		if (bh == NULL)
> 			continue;
> -		}
> -		if (le32_to_cpu(de->inode)) {
> +		if (IS_ERR(bh))
> +			return true;
> +		if (!is_empty_dirent_block(inode, bh, NULL)) {
> 			brelse(bh);
> 			return false;
> 		}
> -		offset += ext4_rec_len_from_disk(de->rec_len, sb->s_blocksize);
> +		brelse(bh);
> 	}
> -	brelse(bh);
> 	return true;
> }

Cheers, Andreas






Download attachment "signature.asc" of type "application/pgp-signature" (874 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ