Skip to content

Commit

Permalink
CHROMIUM: esdfs: Clean up for Android
Browse files Browse the repository at this point in the history
Minor code cleanup to make it play nicely with our
tree. Some names are changed to avoid collisions
with sdcardfs, and the case insensitive lookups
are moved inside esdfs to avoid needing to asjust
all possible lower filesystems. Removed selinux
overriding. A few minor checkpatch fixes.

* Fix-up for 4.14: use dir_context for name match

 Conflicts:
       include/uapi/linux/magic.h

BUG=b:63876697
TEST=compilation, mount esdfs

Signed-off-by: Daniel Rosenberg <drosen@google.com>
Change-Id: I4ad7f3f6d1f110c4b0502259e1436bde8a2fac29
Reviewed-on: https://chromium-review.googlesource.com/791976
Commit-Ready: Sarthak Kukreti <sarthakkukreti@chromium.org>
Tested-by: Sarthak Kukreti <sarthakkukreti@chromium.org>
Reviewed-by: Gwendal Grignou <gwendal@chromium.org>
(cherry picked from commit 420a006)
Reviewed-on: https://chromium-review.googlesource.com/963410
  • Loading branch information
drosen-google authored and chrome-bot committed Jun 20, 2018
1 parent f38c414 commit b946d11
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 126 deletions.
1 change: 1 addition & 0 deletions fs/Kconfig
Expand Up @@ -228,6 +228,7 @@ source "fs/adfs/Kconfig"
source "fs/affs/Kconfig"
source "fs/ecryptfs/Kconfig"
source "fs/sdcardfs/Kconfig"
source "fs/esdfs/Kconfig"
source "fs/hfs/Kconfig"
source "fs/hfsplus/Kconfig"
source "fs/befs/Kconfig"
Expand Down
1 change: 1 addition & 0 deletions fs/Makefile
Expand Up @@ -85,6 +85,7 @@ obj-$(CONFIG_HFSPLUS_FS) += hfsplus/ # Before hfs to find wrapped HFS+
obj-$(CONFIG_HFS_FS) += hfs/
obj-$(CONFIG_ECRYPT_FS) += ecryptfs/
obj-$(CONFIG_SDCARD_FS) += sdcardfs/
obj-$(CONFIG_ESD_FS) += esdfs/
obj-$(CONFIG_VXFS_FS) += freevxfs/
obj-$(CONFIG_NFS_FS) += nfs/
obj-$(CONFIG_EXPORTFS) += exportfs/
Expand Down
4 changes: 2 additions & 2 deletions fs/esdfs/dentry.c
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2003-2014 Stony Brook University
* Copyright (c) 2003-2014 The Research Foundation of SUNY
* Copyright (C) 2013-2014 Motorola Mobility, LLC
* Copyright (C) 2017 Google, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down Expand Up @@ -139,8 +140,7 @@ static void esdfs_d_release(struct dentry *dentry)
/* release and reset the lower paths */
esdfs_put_reset_lower_paths(dentry);
esdfs_release_lower_parent(dentry);
free_dentry_private_data(dentry);
return;
esdfs_free_dentry_private_data(dentry);
}

const struct dentry_operations esdfs_dops = {
Expand Down
6 changes: 3 additions & 3 deletions fs/esdfs/derive.c
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2013-2014 Motorola Mobility LLC
* Copyright (C) 2017 Google, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
Expand All @@ -19,7 +20,6 @@
#include <linux/ctype.h>
#include <linux/vmalloc.h>
#include <linux/uaccess.h>
#include "../internal.h"
#include "esdfs.h"

#define PKG_NAME_MAX 128
Expand Down Expand Up @@ -461,8 +461,8 @@ static int lookup_link_source(struct dentry *dentry, struct dentry *parent)
esdfs_get_lower_path(parent, &lower_parent_path);

/* Check if the stub user profile obb is there. */
err = vfs_path_lookup(lower_parent_path.dentry, lower_parent_path.mnt,
dentry->d_name.name, LOOKUP_NOCASE, &lower_path);
err = esdfs_lookup_nocase(&lower_parent_path, &dentry->d_name,
&lower_path);
/* Remember it to handle renames and removal. */
if (!err)
esdfs_set_lower_stub_path(dentry, &lower_path);
Expand Down
57 changes: 10 additions & 47 deletions fs/esdfs/esdfs.h
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2003-2014 Stony Brook University
* Copyright (c) 2003-2014 The Research Foundation of SUNY
* Copyright (C) 2013-2014 Motorola Mobility, LLC
* Copyright (C) 2017 Google, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand All @@ -28,6 +29,7 @@
#include <linux/slab.h>
#include <linux/sched.h>
#include <linux/fs_struct.h>
#include <linux/pkglist.h>

/* the file system name */
#define ESDFS_NAME "esdfs"
Expand Down Expand Up @@ -110,8 +112,8 @@ extern int esdfs_init_inode_cache(void);
extern void esdfs_destroy_inode_cache(void);
extern int esdfs_init_dentry_cache(void);
extern void esdfs_destroy_dentry_cache(void);
extern int new_dentry_private_data(struct dentry *dentry);
extern void free_dentry_private_data(struct dentry *dentry);
extern int esdfs_new_dentry_private_data(struct dentry *dentry);
extern void esdfs_free_dentry_private_data(struct dentry *dentry);
extern struct dentry *esdfs_lookup(struct inode *dir, struct dentry *dentry,
unsigned int flags);
extern struct inode *esdfs_iget(struct super_block *sb,
Expand All @@ -127,6 +129,8 @@ extern int esdfs_derived_revalidate(struct dentry *dentry,
struct dentry *parent);
extern int esdfs_check_derived_permission(struct inode *inode, int mask);
extern int esdfs_derive_mkdir_contents(struct dentry *dentry);
extern int esdfs_lookup_nocase(struct path *lower_parent_path,
struct qstr *name, struct path *lower_path);

/* file private data */
struct esdfs_file_info {
Expand All @@ -147,7 +151,7 @@ struct esdfs_inode_info {
struct inode vfs_inode;
unsigned version; /* package list version this was derived from */
int tree; /* storage tree location */
uid_t userid; /* Android User ID (not Linux UID) */
uint32_t userid; /* Android User ID (not Linux UID) */
uid_t appid; /* Linux UID for this app/user combo */
};

Expand All @@ -164,7 +168,6 @@ struct esdfs_sb_info {
struct super_block *lower_sb;
struct super_block *s_sb;
struct list_head s_list;
u32 lower_secid;
struct esdfs_perms lower_perms;
struct esdfs_perms upper_perms; /* root in derived mode */
struct dentry *obb_parent; /* pinned dentry for obb link parent */
Expand Down Expand Up @@ -260,7 +263,6 @@ static inline void esdfs_get_lower_path(const struct dentry *dent,
pathcpy(lower_path, &ESDFS_D(dent)->lower_path);
path_get(lower_path);
spin_unlock(&ESDFS_D(dent)->lock);
return;
}
static inline void esdfs_get_lower_stub_path(const struct dentry *dent,
struct path *lower_stub_path)
Expand All @@ -269,29 +271,25 @@ static inline void esdfs_get_lower_stub_path(const struct dentry *dent,
pathcpy(lower_stub_path, &ESDFS_D(dent)->lower_stub_path);
path_get(lower_stub_path);
spin_unlock(&ESDFS_D(dent)->lock);
return;
}
static inline void esdfs_put_lower_path(const struct dentry *dent,
struct path *lower_path)
{
path_put(lower_path);
return;
}
static inline void esdfs_set_lower_path(const struct dentry *dent,
struct path *lower_path)
{
spin_lock(&ESDFS_D(dent)->lock);
pathcpy(&ESDFS_D(dent)->lower_path, lower_path);
spin_unlock(&ESDFS_D(dent)->lock);
return;
}
static inline void esdfs_set_lower_stub_path(const struct dentry *dent,
struct path *lower_stub_path)
{
spin_lock(&ESDFS_D(dent)->lock);
pathcpy(&ESDFS_D(dent)->lower_stub_path, lower_stub_path);
spin_unlock(&ESDFS_D(dent)->lock);
return;
}
static inline void esdfs_put_reset_lower_paths(const struct dentry *dent)
{
Expand All @@ -312,7 +310,6 @@ static inline void esdfs_put_reset_lower_paths(const struct dentry *dent)
path_put(&lower_path);
if (lower_stub_path.dentry)
path_put(&lower_stub_path);
return;
}
static inline void esdfs_get_lower_parent(const struct dentry *dent,
struct dentry *lower_dentry,
Expand All @@ -327,18 +324,17 @@ static inline void esdfs_get_lower_parent(const struct dentry *dent,
spin_unlock(&ESDFS_D(dent)->lock);
if (!*lower_parent)
*lower_parent = dget_parent(lower_dentry);
return;
}
static inline void esdfs_put_lower_parent(const struct dentry *dent,
struct dentry **lower_parent)
{
dput(*lower_parent);
return;
}
static inline void esdfs_set_lower_parent(const struct dentry *dent,
struct dentry *parent)
{
struct dentry *old_parent = NULL;

spin_lock(&ESDFS_D(dent)->lock);
if (ESDFS_DENTRY_IS_LINKED(dent))
old_parent = ESDFS_D(dent)->real_parent;
Expand All @@ -347,11 +343,11 @@ static inline void esdfs_set_lower_parent(const struct dentry *dent,
spin_unlock(&ESDFS_D(dent)->lock);
if (old_parent)
dput(old_parent);
return;
}
static inline void esdfs_release_lower_parent(const struct dentry *dent)
{
struct dentry *real_parent = NULL;

spin_lock(&ESDFS_D(dent)->lock);
if (ESDFS_DENTRY_IS_LINKED(dent)) {
real_parent = ESDFS_D(dent)->real_parent;
Expand All @@ -360,13 +356,13 @@ static inline void esdfs_release_lower_parent(const struct dentry *dent)
spin_unlock(&ESDFS_D(dent)->lock);
if (real_parent)
dput(real_parent);
return;
}

/* locking helpers */
static inline struct dentry *lock_parent(struct dentry *dentry)
{
struct dentry *dir = dget_parent(dentry);

inode_lock_nested(dir->d_inode, I_MUTEX_PARENT);
return dir;
}
Expand Down Expand Up @@ -402,7 +398,6 @@ static inline void esdfs_set_perms(struct inode *inode)
else
inode->i_mode = (inode->i_mode & S_IFMT) |
sbi->upper_perms.fmask;
return;
}

static inline void esdfs_revalidate_perms(struct dentry *dentry)
Expand Down Expand Up @@ -435,37 +430,6 @@ static inline void esdfs_copy_attr(struct inode *dest, const struct inode *src)
esdfs_set_perms(dest);
}

#ifdef CONFIG_SECURITY_SELINUX
/*
* Hard-code the lower source context to prevent anyone with mount permissions
* from doing something nasty.
*/
#define ESDFS_LOWER_SECCTX "u:r:sdcardd:s0"

/*
* Hack to be able to poke at the SID. The Linux Security API does not provide
* a way to change just the SID in the creds (probably on purpose).
*/
struct task_security_struct {
u32 osid; /* SID prior to last execve */
u32 sid; /* current SID */
u32 exec_sid; /* exec SID */
u32 create_sid; /* fscreate SID */
u32 keycreate_sid; /* keycreate SID */
u32 sockcreate_sid; /* fscreate SID */
};
static inline void esdfs_override_secid(struct esdfs_sb_info *sbi,
struct cred *creds)
{
struct task_security_struct *tsec = creds->security;

if (sbi->lower_secid)
tsec->sid = sbi->lower_secid;
}
#else
static inline void esdfs_override_secid(struct esdfs_sb_info *sbi,
struct cred *creds) {}
#endif
/*
* Based on nfs4_save_creds() and nfs4_reset_creds() in nfsd/nfs4recover.c.
* Returns NULL if prepare_creds() could not allocate heap, otherwise
Expand All @@ -486,7 +450,6 @@ static inline const struct cred *esdfs_override_creds(

creds->fsuid = make_kuid(&init_user_ns, sbi->lower_perms.uid);
creds->fsgid = make_kgid(&init_user_ns, sbi->lower_perms.gid);
esdfs_override_secid(sbi, creds);

/* this installs the new creds into current, which we must destroy */
return override_creds(creds);
Expand Down
1 change: 1 addition & 0 deletions fs/esdfs/file.c
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2003-2014 Stony Brook University
* Copyright (c) 2003-2014 The Research Foundation of SUNY
* Copyright (C) 2013-2014, 2016 Motorola Mobility, LLC
* Copyright (C) 2017 Google, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down
1 change: 1 addition & 0 deletions fs/esdfs/inode.c
Expand Up @@ -4,6 +4,7 @@
* Copyright (c) 2003-2014 Stony Brook University
* Copyright (c) 2003-2014 The Research Foundation of SUNY
* Copyright (C) 2013-2014 Motorola Mobility, LLC
* Copyright (C) 2017 Google, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
Expand Down

0 comments on commit b946d11

Please sign in to comment.