Skip to content

Commit

Permalink
[JFFS2] Fix ACL vs. mode handling.
Browse files Browse the repository at this point in the history
When POSIX ACL support was enabled, we weren't writing correct
legacy modes to the medium on inode creation, or when the ACL was set.
This meant that the permissions would be incorrect after the file system
was remounted.

Signed-off-by: David Woodhouse <dwmw2@infradead.org>
  • Loading branch information
David Woodhouse committed Aug 22, 2007
1 parent 09b3fba commit 9ed437c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 30 deletions.
23 changes: 11 additions & 12 deletions fs/jffs2/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void jffs2_iset_acl(struct inode *inode, struct posix_acl **i_acl, struct
spin_unlock(&inode->i_lock);
}

static struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
{
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
struct posix_acl *acl;
Expand Down Expand Up @@ -247,8 +247,13 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
if (rc < 0)
return rc;
if (inode->i_mode != mode) {
inode->i_mode = mode;
jffs2_dirty_inode(inode);
struct iattr attr;

attr.ia_valid = ATTR_MODE;
attr.ia_mode = mode;
rc = jffs2_do_setattr(inode, &attr);
if (rc < 0)
return rc;
}
if (rc == 0)
acl = NULL;
Expand Down Expand Up @@ -307,22 +312,16 @@ int jffs2_permission(struct inode *inode, int mask, struct nameidata *nd)
return generic_permission(inode, mask, jffs2_check_acl);
}

int jffs2_init_acl(struct inode *inode, struct inode *dir)
int jffs2_init_acl(struct inode *inode, struct posix_acl *acl)
{
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
struct posix_acl *acl = NULL, *clone;
struct posix_acl *clone;
mode_t mode;
int rc = 0;

f->i_acl_access = JFFS2_ACL_NOT_CACHED;
f->i_acl_default = JFFS2_ACL_NOT_CACHED;
if (!S_ISLNK(inode->i_mode)) {
acl = jffs2_get_acl(dir, ACL_TYPE_DEFAULT);
if (IS_ERR(acl))
return PTR_ERR(acl);
if (!acl)
inode->i_mode &= ~current->fs->umask;
}

if (acl) {
if (S_ISDIR(inode->i_mode)) {
rc = jffs2_set_acl(inode, ACL_TYPE_DEFAULT, acl);
Expand Down
4 changes: 3 additions & 1 deletion fs/jffs2/acl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,18 @@ struct jffs2_acl_header {

#define JFFS2_ACL_NOT_CACHED ((void *)-1)

extern struct posix_acl *jffs2_get_acl(struct inode *inode, int type);
extern int jffs2_permission(struct inode *, int, struct nameidata *);
extern int jffs2_acl_chmod(struct inode *);
extern int jffs2_init_acl(struct inode *, struct inode *);
extern int jffs2_init_acl(struct inode *, struct posix_acl *);
extern void jffs2_clear_acl(struct jffs2_inode_info *);

extern struct xattr_handler jffs2_acl_access_xattr_handler;
extern struct xattr_handler jffs2_acl_default_xattr_handler;

#else

#define jffs2_get_acl(inode, type) (NULL)
#define jffs2_permission NULL
#define jffs2_acl_chmod(inode) (0)
#define jffs2_init_acl(inode,dir) (0)
Expand Down
33 changes: 23 additions & 10 deletions fs/jffs2/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
struct jffs2_inode_info *f, *dir_f;
struct jffs2_sb_info *c;
struct inode *inode;
struct posix_acl *acl;
int ret;

ri = jffs2_alloc_raw_inode();
Expand All @@ -192,7 +193,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,

D1(printk(KERN_DEBUG "jffs2_create()\n"));

inode = jffs2_new_inode(dir_i, mode, ri);
inode = jffs2_new_inode(dir_i, mode, ri, &acl);

if (IS_ERR(inode)) {
D1(printk(KERN_DEBUG "jffs2_new_inode() failed\n"));
Expand All @@ -212,12 +213,12 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
dentry->d_name.name, dentry->d_name.len);

if (ret)
goto fail;
goto fail_acl;

ret = jffs2_init_security(inode, dir_i);
if (ret)
goto fail;
ret = jffs2_init_acl(inode, dir_i);
goto fail_acl;
ret = jffs2_init_acl(inode, acl);
if (ret)
goto fail;

Expand All @@ -230,6 +231,8 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
inode->i_ino, inode->i_mode, inode->i_nlink, f->inocache->nlink, inode->i_mapping->nrpages));
return 0;

fail_acl:
posix_acl_release(acl);
fail:
make_bad_inode(inode);
iput(inode);
Expand Down Expand Up @@ -306,6 +309,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
struct jffs2_full_dirent *fd;
int namelen;
uint32_t alloclen;
struct posix_acl *acl;
int ret, targetlen = strlen(target);

/* FIXME: If you care. We'd need to use frags for the target
Expand All @@ -332,7 +336,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
return ret;
}

inode = jffs2_new_inode(dir_i, S_IFLNK | S_IRWXUGO, ri);
inode = jffs2_new_inode(dir_i, S_IFLNK | S_IRWXUGO, ri, &acl);

if (IS_ERR(inode)) {
jffs2_free_raw_inode(ri);
Expand Down Expand Up @@ -362,6 +366,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
up(&f->sem);
jffs2_complete_reservation(c);
jffs2_clear_inode(inode);
posix_acl_release(acl);
return PTR_ERR(fn);
}

Expand All @@ -372,6 +377,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
up(&f->sem);
jffs2_complete_reservation(c);
jffs2_clear_inode(inode);
posix_acl_release(acl);
return -ENOMEM;
}

Expand All @@ -389,9 +395,10 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
ret = jffs2_init_security(inode, dir_i);
if (ret) {
jffs2_clear_inode(inode);
posix_acl_release(acl);
return ret;
}
ret = jffs2_init_acl(inode, dir_i);
ret = jffs2_init_acl(inode, acl);
if (ret) {
jffs2_clear_inode(inode);
return ret;
Expand Down Expand Up @@ -469,6 +476,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
struct jffs2_full_dirent *fd;
int namelen;
uint32_t alloclen;
struct posix_acl *acl;
int ret;

mode |= S_IFDIR;
Expand All @@ -491,7 +499,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
return ret;
}

inode = jffs2_new_inode(dir_i, mode, ri);
inode = jffs2_new_inode(dir_i, mode, ri, &acl);

if (IS_ERR(inode)) {
jffs2_free_raw_inode(ri);
Expand All @@ -518,6 +526,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
up(&f->sem);
jffs2_complete_reservation(c);
jffs2_clear_inode(inode);
posix_acl_release(acl);
return PTR_ERR(fn);
}
/* No data here. Only a metadata node, which will be
Expand All @@ -531,9 +540,10 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
ret = jffs2_init_security(inode, dir_i);
if (ret) {
jffs2_clear_inode(inode);
posix_acl_release(acl);
return ret;
}
ret = jffs2_init_acl(inode, dir_i);
ret = jffs2_init_acl(inode, acl);
if (ret) {
jffs2_clear_inode(inode);
return ret;
Expand Down Expand Up @@ -629,6 +639,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
union jffs2_device_node dev;
int devlen = 0;
uint32_t alloclen;
struct posix_acl *acl;
int ret;

if (!new_valid_dev(rdev))
Expand All @@ -655,7 +666,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
return ret;
}

inode = jffs2_new_inode(dir_i, mode, ri);
inode = jffs2_new_inode(dir_i, mode, ri, &acl);

if (IS_ERR(inode)) {
jffs2_free_raw_inode(ri);
Expand Down Expand Up @@ -684,6 +695,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
up(&f->sem);
jffs2_complete_reservation(c);
jffs2_clear_inode(inode);
posix_acl_release(acl);
return PTR_ERR(fn);
}
/* No data here. Only a metadata node, which will be
Expand All @@ -697,9 +709,10 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
ret = jffs2_init_security(inode, dir_i);
if (ret) {
jffs2_clear_inode(inode);
posix_acl_release(acl);
return ret;
}
ret = jffs2_init_acl(inode, dir_i);
ret = jffs2_init_acl(inode, acl);
if (ret) {
jffs2_clear_inode(inode);
return ret;
Expand Down
32 changes: 26 additions & 6 deletions fs/jffs2/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

static int jffs2_flash_setup(struct jffs2_sb_info *c);

static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
{
struct jffs2_full_dnode *old_metadata, *new_metadata;
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
Expand All @@ -36,10 +36,8 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
unsigned int ivalid;
uint32_t alloclen;
int ret;

D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino));
ret = inode_change_ok(inode, iattr);
if (ret)
return ret;

/* Special cases - we don't want more than one data node
for these types on the medium at any time. So setattr
Expand Down Expand Up @@ -183,9 +181,14 @@ int jffs2_setattr(struct dentry *dentry, struct iattr *iattr)
{
int rc;

rc = inode_change_ok(dentry->d_inode, iattr);
if (rc)
return rc;

rc = jffs2_do_setattr(dentry->d_inode, iattr);
if (!rc && (iattr->ia_valid & ATTR_MODE))
rc = jffs2_acl_chmod(dentry->d_inode);

return rc;
}

Expand Down Expand Up @@ -399,7 +402,8 @@ void jffs2_write_super (struct super_block *sb)

/* jffs2_new_inode: allocate a new inode and inocache, add it to the hash,
fill in the raw_inode while you're at it. */
struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_inode *ri)
struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_inode *ri,
struct posix_acl **acl)
{
struct inode *inode;
struct super_block *sb = dir_i->i_sb;
Expand Down Expand Up @@ -431,7 +435,23 @@ struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_i
} else {
ri->gid = cpu_to_je16(current->fsgid);
}
ri->mode = cpu_to_jemode(mode);

/* POSIX ACLs have to be processed now, at least partly.
The umask is only applied if there's no default ACL */
if (!S_ISLNK(mode)) {
*acl = jffs2_get_acl(dir_i, ACL_TYPE_DEFAULT);
if (IS_ERR(*acl)) {
make_bad_inode(inode);
iput(inode);
inode = (void *)*acl;
*acl = NULL;
return inode;
}
if (!(*acl))
mode &= ~current->fs->umask;
} else {
*acl = NULL;
}
ret = jffs2_do_new_inode (c, f, mode, ri);
if (ret) {
make_bad_inode(inode);
Expand Down
5 changes: 4 additions & 1 deletion fs/jffs2/os-linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,15 @@ int jffs2_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
extern const struct inode_operations jffs2_symlink_inode_operations;

/* fs.c */
struct posix_acl;

int jffs2_setattr (struct dentry *, struct iattr *);
int jffs2_do_setattr (struct inode *, struct iattr *);
void jffs2_read_inode (struct inode *);
void jffs2_clear_inode (struct inode *);
void jffs2_dirty_inode(struct inode *inode);
struct inode *jffs2_new_inode (struct inode *dir_i, int mode,
struct jffs2_raw_inode *ri);
struct jffs2_raw_inode *ri, struct posix_acl **acl);
int jffs2_statfs (struct dentry *, struct kstatfs *);
void jffs2_write_super (struct super_block *);
int jffs2_remount_fs (struct super_block *, int *, char *);
Expand Down

0 comments on commit 9ed437c

Please sign in to comment.