ANDROID: Incremental fs: Use ERR_CAST in handle_mapped_file()

When building android-mainline with a version of clang that supports
CONFIG_RANDSTRUCT, there are errors about casts from randomized
structures to non-randomized structures:

  fs/incfs/data_mgmt.c:240:10: error: casting from randomized structure pointer type 'struct dentry *' to 'struct data_file *'
                  return (struct data_file *)index_file_dentry;
                         ^
  fs/incfs/data_mgmt.c:257:12: error: casting from randomized structure pointer type 'struct file *' to 'struct data_file *'
                  result = (struct data_file *)bf;
                           ^
  2 errors generated.

As suggested by Kees on aosp/1995750, these casts should actually be
using the ERR_CAST macro, which is a more proper way to pass error
pointers around.

Change-Id: Iab73ac7503235f1147154a01a22ab8608e3daf8b
Fixes: 3f4938108a ("ANDROID: Incremental fs: Create mapped file")
Link: https://github.com/ClangBuiltLinux/linux/issues/1652
Suggested-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
This commit is contained in:
Nathan Chancellor 2022-06-23 12:54:22 -07:00
parent 0f0ddc32df
commit 483887d651
No known key found for this signature in database
GPG key ID: 1D6B269171C01A96

View file

@ -237,7 +237,7 @@ static struct data_file *handle_mapped_file(struct mount_info *mi,
if (!index_file_dentry)
return ERR_PTR(-ENOENT);
if (IS_ERR(index_file_dentry))
return (struct data_file *)index_file_dentry;
return ERR_CAST(index_file_dentry);
if (!d_really_is_positive(index_file_dentry)) {
result = ERR_PTR(-ENOENT);
goto out;
@ -254,7 +254,7 @@ static struct data_file *handle_mapped_file(struct mount_info *mi,
revert_creds(old_cred);
if (IS_ERR(bf)) {
result = (struct data_file *)bf;
result = ERR_CAST(bf);
goto out;
}