Skip to content

Conversation

@xbharani
Copy link

  • Checks for fscryptctl binary presence
  • Creates a random sw encryption key
  • Applies and verifies encryption policy
  • Confirms functionality with a test file

@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. To prevent automatic closure in 7 days, remove the stale label or add a comment. You can reopen a closed pull request at any time.

@github-actions github-actions bot added the Stale label Sep 12, 2025
@smuppand
Copy link
Contributor

@xbharani Any update on the requested changes?

@github-actions github-actions bot removed the Stale label Sep 13, 2025
@github-actions
Copy link

This pull request has been marked as stale due to 30 days of inactivity. To prevent automatic closure in 7 days, remove the stale label or add a comment. You can reopen a closed pull request at any time.

@xbharani xbharani force-pushed the main branch 2 times, most recently from bd6eccf to 56d715d Compare November 20, 2025 09:52
@xbharani xbharani force-pushed the main branch 2 times, most recently from 686cf9f to 8f29437 Compare December 8, 2025 05:26
- Checks for fscryptctl binary presence
- Creates a random sw encryption key
- Applies and verifies encryption policy
- Confirms functionality with a test file
- Added yaml config

Signed-off-by: Bharani Bhuvanagiri <bbharani@qti.qualcomm.com>
Copy link
Contributor

@smuppand smuppand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the script is close, but a few things will bite in CI / reliability, plus a couple of correctness/safety issues.

exit 0
fi

if [ -z "$__INIT_ENV_LOADED" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the var is unset, some shells can still behave oddly, also it will trigger set -u issues if added later.
Use:
if [ -z "${__INIT_ENV_LOADED:-}" ]; then

fi

log_info "Checking if dependency binary is available"
check_dependencies "$FSCRYPTCTL"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if check_dependencies returns non-zero you currently don’t handle it (you just call it).
Better to have an safer pattern.


# Step 2: Create mount folder (this will create an unique folder under mnt)
log_info "Creating unique mount folder under /mnt"
MOUNT_DIR=$(mktemp -d /mnt/testing.XXXXXX)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mktemp under /mnt is not guaranteed to exist or be writable. On many images /mnt exists, but not always. Better:
Prefer ${TMPDIR:-/tmp} or ensure /mnt exists.
Example:
BASE_TMP="${TMPDIR:-/tmp}"
MOUNT_DIR="$(mktemp -d "$BASE_TMP/testing.XXXXXX")" || ...


# Step 6: Verify policy
log_info "Verifying encryption policy"
policy_output=$("$FSCRYPTCTL" get_policy "$MOUNT_DIR" 2>/dev/null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your “encryption validation” is too weak (it will pass even if nothing is encrypted)
Right now you:

  • set policy on an empty directory
  • write a file
  • read it back

That proves “filesystem writable”, not “data is encrypted”.

At minimum add one real validation:
Confirm the directory is marked encrypted via fscryptctl/lsattr output, OR
Check that get_policy returns non-empty + matches key id (you already do), and that encryption flags exist.

fi

if [ -n "$key_id" ]; then
"$FSCRYPTCTL" remove_key "$key_id" "$FS_PATH" >/dev/null 2>&1 || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleanup removes key even if FS_PATH is empty. If key_id is set but FS_PATH is empty (partial failure), you may call remove_key with bad args.

log_warn "Failed to delete test file: $MOUNT_DIR/file.txt"
fi

if rmdir "$MOUNT_DIR" 2>/dev/null; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rm / rmdir cleanup is fine, but you should not assume the file exists. Your logging is OK, but make it quieter.
Remove the “failed to delete” warnings when the file simply doesn’t exist.
Example:
[ -f "$MOUNT_DIR/file.txt" ] && rm -f "$MOUNT_DIR/file.txt" ...

file_content=$(cat "$MOUNT_DIR/file.txt")
if [ "$file_content" = "file" ]; then
log_pass "$TESTNAME : Test Passed"
echo "$TESTNAME PASS" > "$res_file"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add exit 0

# Step 3: Add the key to the filesystem
log_info "Adding encryption key to the filesystem"
key_id=$("$FSCRYPTCTL" add_key "$FS_PATH" < "$KEY_FILE" 2>/dev/null)
scan_dmesg_errors "$SCRIPT_DIR" "fscrypt" ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scan_dmesg_errors is aggressive, consider only scan at end, or scan with a narrow time window.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants