All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Cc: linux-ext4@vger.kernel.org
Subject: Re: [PATCH v3 06/15] ext2fs: add new APIs needed for fast commits
Date: Thu, 21 Jan 2021 00:58:25 -0500	[thread overview]
Message-ID: <YAkYAeTL66Eq0OZE@mit.edu> (raw)
In-Reply-To: <20210120212641.526556-7-user@harshads-520.kir.corp.google.com>

On Wed, Jan 20, 2021 at 01:26:32PM -0800, Harshad Shirwadkar wrote:
> From: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
> 
> This patch adds the following new APIs:
> 
> Count the total number of blocks occupied by inode including
> intermediate extent tree nodes.
> extern blk64_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
>                                        struct ext2_inode *inode);

I wonder if this should be something like this instead:

extern errcode_t ext2fs_count_blocks(ext2_filsys fs, ext2_ino_t ino,
                                     struct ext2_inode *inode, blk64_t *ret_count);

The problem is that ext2fs_count_blocks() calls a whole series of
ext2fs functions which could return errors:

> +	errcode = ext2fs_extent_open2(fs, ino, inode, &handle);
> +	if (errcode)
> +		goto out;
> +
> +	errcode = ext2fs_extent_get(handle, EXT2_EXTENT_ROOT, &extent);
> +	if (errcode)
> +		goto out;

... and any of these functions could return an error.  So we need to
make sure errors are faithfully returned to the caller and handled
correctly, instead of just having ext2fs_count_blocks returning a
value of 0.


I then started taking a look at the users of ext2fs_count_blocks() in
e2fsck, and I ran into more concerns.  One of the problems here is
that some of these functions get called by kernel code --- and kernel
code has a different error handling convetion of negative errno's.

And in some cases, I see we are doing this:

static int ext4_fc_handle_inode(e2fsck_t ctx, struct ext4_fc_tl *tl)
{
	...
	
	ret = ext2fs_read_inode_full(ctx->fs, ino, (struct ext2_inode *)inode,
					inode_len);
	if (ret)
		goto out;
	...
out:
	ext2fs_free_mem(&inode);
	return ret;
}

The problem here is that ext2fs_read_inode_full() returns an
errcode_t, and this is getting cast to an int and returned as if it
were a kernel error code.

Also note that ext4_fc_replay() can return 0 or 1:

#define JBD2_FC_REPLAY_STOP		0
#define JBD2_FC_REPLAY_CONTINUE		1

Fortunately, none of the functions that ext4_fc_*() call seem to be
ones which could return in an ext2fs library returning EPERM (which is
errno 1), but you see the potential risks of conflating an errcode_t
and kernel negative errno convention.

This is going to be a bit tricky to deal with, since an errcode_t can
be a errno code, but it can also be one of the codes defined in
lib/ext2fs/ext2_err.et, which get translated to numbers like:

#define EXT2_ET_DIR_CORRUPTED                    (2133571363L)
#define EXT2_ET_SHORT_READ                       (2133571364L)
#define EXT2_ET_SHORT_WRITE                      (2133571365L)

(See lib/ext2fs/ext2_err.h in the build directory of e2fsprogs and the
com_err library found in lib/et.)

So what we may need to do is to create a function which does a simple
mapping of errcode_t values to negative errno's.  It doesn't need to
be exact; in fact, a first pass might just map all errcode_t's greater
than 256 to something like -EFAULT, and all normal errno's to -errno.

We might also want to have it print a diagnistic message to stderr
that prints error_message(retval) was encoutered in function __func__
at line __LINE__.  Hopefully in actual practice they won't happen
(unless a malicious attacker is feeding us a fuzzed file sytem), but
if it does, it would be good if there is a useful message so we can
actually debug what happened.

      	   	  	     	    	     - Ted

  reply	other threads:[~2021-01-21  5:59 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-20 21:26 [PATCH v3 00/15] Fast commit changes for e2fsprogs Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 01/15] ext2fs: move calculate_summary_stats to ext2fs lib Harshad Shirwadkar
2021-01-21 15:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 02/15] e2fsck: add kernel endian-ness conversion macros Harshad Shirwadkar
2021-01-21 15:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 03/15] e2fsck: port fc changes from kernel's recovery.c to e2fsck Harshad Shirwadkar
2021-01-21 15:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 04/15] libext2fs: provide APIs to configure fast commit blocks Harshad Shirwadkar
2021-01-21 15:56   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 05/15] e2fsprogs: make userspace tools number of fast commits blocks aware Harshad Shirwadkar
2021-01-21 15:58   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 06/15] ext2fs: add new APIs needed for fast commits Harshad Shirwadkar
2021-01-21  5:58   ` Theodore Ts'o [this message]
2021-01-20 21:26 ` [PATCH v3 07/15] e2fsck: add function to rewrite extent tree Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 08/15] e2fsck: add fast commit setup code Harshad Shirwadkar
2021-01-21 16:54   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 09/15] e2fsck: add fast commit scan pass Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 10/15] e2fsck: add fast commit replay skeleton Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 11/15] e2fsck: add fc replay for link, unlink, creat tags Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 12/15] e2fsck: add replay for add_range, del_range, and inode tags Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 13/15] debugfs: add fast commit support to logdump Harshad Shirwadkar
2021-01-21 16:49   ` Theodore Ts'o
2021-01-20 21:26 ` [PATCH v3 14/15] tests: add fast commit recovery tests Harshad Shirwadkar
2021-01-20 21:26 ` [PATCH v3 15/15] ext4: fix tests to account for new dumpe2fs output Harshad Shirwadkar
2021-01-21 16:01   ` Theodore Ts'o
2021-01-21  5:22 ` [PATCH v3 00/15] Fast commit changes for e2fsprogs Theodore Ts'o

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YAkYAeTL66Eq0OZE@mit.edu \
    --to=tytso@mit.edu \
    --cc=harshadshirwadkar@gmail.com \
    --cc=linux-ext4@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.