From: Eric Biggers <ebiggers@kernel.org>
To: "Ritesh Harjani (IBM)" <ritesh.list@gmail.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
linux-ext4@vger.kernel.org,
Harshad Shirwadkar <harshadshirwadkar@gmail.com>,
Wang Shilong <wshilong@ddn.com>,
Andreas Dilger <adilger.kernel@dilger.ca>, Li Xi <lixi@ddn.com>,
Sebastien Buisson <sbuisson@ddn.com>, Maloo <maloo@whamcloud.com>,
Li Dongyang <dongyangli@ddn.com>,
Andreas Dilger <adilger@whamcloud.com>
Subject: Re: [RFCv1 67/72] sec: support encrypted files handling in pfsck mode
Date: Mon, 7 Nov 2022 11:22:56 -0800 [thread overview]
Message-ID: <Y2lbEEtjhJwpbdRb@sol.localdomain> (raw)
In-Reply-To: <77a302b36f3576b9a9f7ef6e42bc1ef939227090.1667822612.git.ritesh.list@gmail.com>
On Mon, Nov 07, 2022 at 05:51:55PM +0530, Ritesh Harjani (IBM) wrote:
> sec: support encrypted files handling in pfsck mode
>
"sec:" => "e2fsck:".
> +/**
> + * Search policy matching @policy in @info->policies
> + * @ctx: e2fsck context
> + * @info: encrypted_file_info to look into
> + * @policy: the policy we are looking for
> + * @parent: (out) last known parent, useful to insert a new leaf
> + * in @info->policies
> + *
> + * Return: id of found policy on success, -1 if no matching policy found.
> + */
> +static inline int search_policy(e2fsck_t ctx, struct encrypted_file_info *info,
> + union fscrypt_policy policy,
> + struct rb_node **parent)
> +{
> + struct rb_node *n = info->policies.rb_node;
> + struct policy_map_entry *entry;
> +
> + while (n) {
> + int res;
> +
> + *parent = n;
> + entry = ext2fs_rb_entry(n, struct policy_map_entry, node);
> + res = cmp_fscrypt_policies(ctx, &policy, &entry->policy);
> + if (res < 0)
> + n = n->rb_left;
> + else if (res > 0)
> + n = n->rb_right;
> + else
> + return entry->policy_id;
> + }
> + return -1;
> +}
Can this rbtree search code be reused by get_encryption_policy_id()?
Also, please use the existing constant NO_ENCRYPTION_POLICY instead of -1.
> +/*
> + * Merge @src encrypted info into @dest
> + */
> +int e2fsck_merge_encrypted_info(e2fsck_t ctx, struct encrypted_file_info *src,
> + struct encrypted_file_info *dest)
> +{
> + struct rb_root *src_policies = &src->policies;
> + __u32 *policy_trans;
> + int i, rc = 0;
> +
> + if (dest->file_ranges[src->file_ranges_count - 1].last_ino >
> + src->file_ranges[0].first_ino) {
There is an off-by-one error here. How about writing it like the following so
that it looks like the check in append_ino_and_policy_id():
if (src->file_ranges[0].first_ino <=
dest->file_ranges[src->file_ranges_count - 1].last_ino) {
> + /* First, deal with the encryption policy => ID map.
My understanding is that e2fsprogs follows the kernel coding style, where block
comments are formatted like the following:
/*
* text
*/
> + * Compare encryption policies in src with policies already recorded
> + * in dest. It can be similar policies, but recorded with a different
"similar" => "the same"
> + while (!ext2fs_rb_empty_root(src_policies)) {
> + struct policy_map_entry *entry, *newentry;
> + struct rb_node *new, *parent = NULL;
> + int existing_polid;
> +
> + entry = ext2fs_rb_entry(src_policies->rb_node,
> + struct policy_map_entry, node);
> + existing_polid = search_policy(ctx, dest,
> + entry->policy, &parent);
> + if (existing_polid >= 0) {
existing_polid != NO_ENCRYPTION_POLICY
> + /* The policy in src is already recorded in dest,
> + * so just update its id.
> + */
> + policy_trans[entry->policy_id] = existing_polid;
> + } else {
> + /* The policy in src is new to dest, so insert it
> + * with the next available id (its original id could
> + * be already used in dest).
> + */
> + rc = ext2fs_get_mem(sizeof(*newentry), &newentry);
> + if (rc)
> + goto out_merge;
Use handle_nomem() for memory allocation failures?
> + newentry->policy_id = dest->next_policy_id++;
> + newentry->policy = entry->policy;
> + ext2fs_rb_link_node(&newentry->node, parent, &new);
> + ext2fs_rb_insert_color(&newentry->node,
> + &dest->policies);
> + policy_trans[entry->policy_id] = newentry->policy_id;
This code also appears in get_encryption_policy_id(). Should it be refactored
into a helper function?
> + /* Second, deal with the inode number => encryption policy ID map. */
> + if (dest->file_ranges_capacity <
> + dest->file_ranges_count + src->file_ranges_count) {
> + /* dest->file_ranges is too short, increase its capacity. */
> + size_t new_capacity = dest->file_ranges_count +
> + src->file_ranges_count;
> +
> + /* Make sure we at least double the capacity. */
> + if (new_capacity < (dest->file_ranges_capacity * 2))
> + new_capacity = dest->file_ranges_capacity * 2;
> +
> + /* We won't need more than the filesystem's inode count. */
> + if (new_capacity > ctx->fs->super->s_inodes_count)
> + new_capacity = ctx->fs->super->s_inodes_count;
> +
> + rc = ext2fs_resize_mem(dest->file_ranges_capacity *
> + sizeof(struct encrypted_file_range),
> + new_capacity *
> + sizeof(struct encrypted_file_range),
> + &dest->file_ranges);
> + if (rc) {
> + fix_problem(ctx, PR_1_ALLOCATE_ENCRYPTED_INODE_LIST,
> + NULL);
> + /* Should never get here */
> + ctx->flags |= E2F_FLAG_ABORT;
> + goto out_merge;
> + }
> +
> + dest->file_ranges_capacity = new_capacity;
> + }
The exact allocation size that is needed is
'dest->file_ranges_count + src->file_ranges_count', so much of the above logic
is unnecessary. Just reallocate that exact amount.
Also, handle_nomem() should be used.
> + /* Copy file ranges from src to dest. */
> + for (i = 0; i < src->file_ranges_count; i++) {
> + /* Make sure to convert policy ids in src. */
> + src->file_ranges[i].policy_id =
> + policy_trans[src->file_ranges[i].policy_id];
> + dest->file_ranges[dest->file_ranges_count++] =
> + src->file_ranges[i];
> + }
This needs to handle UNRECOGNIZED_ENCRYPTION_POLICY as a special case.
Also, shouldn't src->file_ranges be freed after this?
> +
> +out_merge:
I guess the "_merge" in "out_merge:" comes from the name of the containing
function? It's a bit confusing. Maybe just use "out:".
> diff --git a/e2fsck/pass1.c b/e2fsck/pass1.c
> index 7345c96d..e7dc017c 100644
> --- a/e2fsck/pass1.c
> +++ b/e2fsck/pass1.c
> @@ -2411,9 +2411,6 @@ void e2fsck_pass1_run(e2fsck_t ctx)
> ctx->ea_block_quota_inodes = 0;
> }
>
> - /* We don't need the encryption policy => ID map any more */
> - destroy_encryption_policy_map(ctx);
With this change, there are no callers of destroy_encryption_policy_map()
outside encrypted_files.c. So absent any other changes,
destroy_encryption_policy_map() should be made into a static function and the
'if (info)' check inside it removed.
But, isn't there still some point where pass 1 is fully done and the encryption
policy ID map can be destroyed? Maybe e2fsck_pass1_merge_encrypted_info()
should be calling destroy_encryption_policy_map() on the global_ctx after doing
the merge?
- Eric
next prev parent reply other threads:[~2022-11-07 19:23 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-07 12:20 [RFCv1 00/72] e2fsprogs: Parallel fsck support Ritesh Harjani (IBM)
2022-11-07 12:20 ` [RFCv1 01/72] e2fsck: Fix unbalanced mutex unlock for BOUNCE_MTX Ritesh Harjani (IBM)
2022-11-17 16:02 ` Theodore Ts'o
2022-11-17 18:45 ` Ritesh Harjani (IBM)
2022-11-18 10:34 ` Andreas Dilger
2022-11-18 11:37 ` Ritesh Harjani (IBM)
2022-11-18 13:20 ` Andreas Dilger
2022-11-19 3:46 ` Ritesh Harjani (IBM)
2023-01-24 16:40 ` Theodore Ts'o
2022-11-07 12:20 ` [RFCv1 02/72] gen_bitmaps: Fix ext2fs_compare_generic_bmap/bitmap logic Ritesh Harjani (IBM)
2022-11-23 5:04 ` Andreas Dilger
2023-01-24 16:59 ` Theodore Ts'o
2022-11-07 12:20 ` [RFCv1 03/72] blkmap64_ba: Add common helper for bits size calculation Ritesh Harjani (IBM)
2022-11-18 10:40 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 04/72] badblocks: Remove unused badblocks_flags Ritesh Harjani (IBM)
2022-11-18 13:26 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 05/72] badblocks: Add badblocks merge logic Ritesh Harjani (IBM)
2022-11-18 13:31 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 06/72] dblist: add dblist " Ritesh Harjani (IBM)
2022-11-18 13:34 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 07/72] libext2fs: Add rbtree bitmap " Ritesh Harjani (IBM)
2022-11-07 12:20 ` [RFCv1 08/72] libext2fs: Add bitmaps merge ops Ritesh Harjani (IBM)
2022-11-18 13:36 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 09/72] libext2fs: Add flush cleanup API Ritesh Harjani (IBM)
2022-11-18 13:39 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 10/72] libext2fs: merge icounts after thread finishes Ritesh Harjani (IBM)
2022-11-18 13:40 ` Andreas Dilger
2022-11-07 12:20 ` [RFCv1 11/72] libext2fs: merge quota context after threads finish Ritesh Harjani (IBM)
2022-11-18 13:42 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 12/72] libext2fs: dupfs: Add fs clone & merge api Ritesh Harjani (IBM)
2022-11-18 19:46 ` Andreas Dilger
2022-11-19 5:02 ` Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 13/72] tst_badblocks: Add unit test to verify badblocks list " Ritesh Harjani (IBM)
2022-12-12 20:35 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 14/72] tst_bitmaps_standalone: Add copy and merge bitmaps test Ritesh Harjani (IBM)
2022-12-12 20:40 ` Andreas Dilger
2022-12-14 5:12 ` Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 15/72] tst_bitmaps_pthread: Add merge bitmaps test using pthreads Ritesh Harjani (IBM)
2022-12-14 21:15 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 16/72] tst_libext2fs_pthread: Add libext2fs merge/clone unit tests Ritesh Harjani (IBM)
2022-12-14 21:17 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 17/72] libext2fs: Add support for ext2fs_test_block_bitmap_range2_valid() Ritesh Harjani (IBM)
2022-12-14 21:21 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 18/72] libext2fs: Add support to get average group count Ritesh Harjani (IBM)
2022-12-14 21:24 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 19/72] libext2fs: Misc fixes for struct_ext2_filsys Ritesh Harjani (IBM)
2022-12-14 21:22 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 20/72] libext2fs: avoid too much memory allocation in case fs_num_threads Ritesh Harjani (IBM)
2022-11-18 13:37 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 21/72] e2fsck: add -m option for multithread Ritesh Harjani (IBM)
2022-12-14 21:32 ` Andreas Dilger
2022-11-07 12:21 ` [RFCv1 22/72] e2fsck: copy context when using multi-thread fsck Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 23/72] e2fsck: create logs for multi-threads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 24/72] e2fsck: configure one pfsck thread Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 25/72] e2fsck: Add e2fsck_pass1_thread_join return value Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 26/72] e2fsck: Use merge/clone apis of libext2fs Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 27/72] e2fsck: Add e2fsck_pass1_merge_bitmap() api Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 28/72] e2fsck: Add asserts in open_channel_fs Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 29/72] e2fsck: add start/end group for thread Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 30/72] e2fsck: split groups to different threads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 31/72] e2fsck: print thread log properly Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 32/72] e2fsck: do not change global variables Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 33/72] e2fsck: optimize the inserting of dir_info_db Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 34/72] e2fsck: merge dir_info after thread finishes Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 35/72] e2fsck: rbtree bitmap for dir Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 36/72] e2fsck: merge icounts after thread finishes Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 37/72] e2fsck: add debug codes for multiple threads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 38/72] e2fsck: merge counts after threads finish Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 39/72] e2fsck: merge dx_dir_info " Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 40/72] e2fsck: merge dirs_to_hash when " Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 41/72] e2fsck: merge context flags properly Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 42/72] e2fsck: merge quota context after threads finish Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 43/72] e2fsck: serialize fix operations Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 44/72] e2fsck: move some fixes out of parallel pthreads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 45/72] e2fsck: split and merge invalid bitmaps Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 46/72] e2fsck: merge EA blocks properly Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 47/72] e2fsck: kickoff mutex lock for block found map Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 48/72] e2fsck: allow admin specify number of threads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 49/72] e2fsck: adjust " Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 50/72] e2fsck: fix readahead for pfsck of pass1 Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 51/72] e2fsck: merge options after threads finish Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 52/72] e2fsck: reset lost_and_found " Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 53/72] e2fsck: merge extent depth count " Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 54/72] e2fsck: simplify e2fsck context merging codes Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 55/72] e2fsck: set E2F_FLAG_ALLOC_OK after threads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 56/72] e2fsck: wait fix thread finish before checking Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 57/72] e2fsck: cleanup e2fsck_pass1_thread_join() Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 58/72] e2fsck: make default smallest RA size to 1M Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 59/72] e2fsck: update mmp block in one thread Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 60/72] e2fsck: reset @inodes_to_rebuild if restart Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 61/72] tests: add pfsck test Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 62/72] e2fsck: fix memory leaks with pfsck enabled Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 63/72] e2fsck: misc cleanups for pfsck Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 64/72] e2fsck: propagate number of threads Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 65/72] e2fsck: Annotating fields in e2fsck_struct Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 66/72] e2fsck: merge casefolded dir lists after thread finish Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 67/72] sec: support encrypted files handling in pfsck mode Ritesh Harjani (IBM)
2022-11-07 19:22 ` Eric Biggers [this message]
2022-11-07 12:21 ` [RFCv1 68/72] e2fsck: Fix io->align assert check Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 69/72] e2fsck: Fix double free of inodes_to_process Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 70/72] e2fsck: Fix and simplify update_mmp in case of pfsck Ritesh Harjani (IBM)
2022-11-07 12:21 ` [RFCv1 71/72] e2fsck: Make threads call log_out after pthread_join Ritesh Harjani (IBM)
2022-11-07 12:22 ` [RFCv1 72/72] tests/f_multithread: Fix f_multithread related tests Ritesh Harjani (IBM)
[not found] ` <B4ED1C86-D3EC-4A0A-97B3-CFCB46617E1A@dilger.ca>
2022-11-19 5:39 ` [RFCv1 00/72] e2fsprogs: Parallel fsck support Ritesh Harjani
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=Y2lbEEtjhJwpbdRb@sol.localdomain \
--to=ebiggers@kernel.org \
--cc=adilger.kernel@dilger.ca \
--cc=adilger@whamcloud.com \
--cc=dongyangli@ddn.com \
--cc=harshadshirwadkar@gmail.com \
--cc=linux-ext4@vger.kernel.org \
--cc=lixi@ddn.com \
--cc=maloo@whamcloud.com \
--cc=ritesh.list@gmail.com \
--cc=sbuisson@ddn.com \
--cc=tytso@mit.edu \
--cc=wshilong@ddn.com \
/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.