Skip to content

Commit 9ed437c

Browse files
committed
[JFFS2] Fix ACL vs. mode handling.
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>
1 parent 09b3fba commit 9ed437c

5 files changed

Lines changed: 67 additions & 30 deletions

File tree

‎fs/jffs2/acl.c‎

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static void jffs2_iset_acl(struct inode *inode, struct posix_acl **i_acl, struct
176176
spin_unlock(&inode->i_lock);
177177
}
178178

179-
static struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
179+
struct posix_acl *jffs2_get_acl(struct inode *inode, int type)
180180
{
181181
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
182182
struct posix_acl *acl;
@@ -247,8 +247,13 @@ static int jffs2_set_acl(struct inode *inode, int type, struct posix_acl *acl)
247247
if (rc < 0)
248248
return rc;
249249
if (inode->i_mode != mode) {
250-
inode->i_mode = mode;
251-
jffs2_dirty_inode(inode);
250+
struct iattr attr;
251+
252+
attr.ia_valid = ATTR_MODE;
253+
attr.ia_mode = mode;
254+
rc = jffs2_do_setattr(inode, &attr);
255+
if (rc < 0)
256+
return rc;
252257
}
253258
if (rc == 0)
254259
acl = NULL;
@@ -307,22 +312,16 @@ int jffs2_permission(struct inode *inode, int mask, struct nameidata *nd)
307312
return generic_permission(inode, mask, jffs2_check_acl);
308313
}
309314

310-
int jffs2_init_acl(struct inode *inode, struct inode *dir)
315+
int jffs2_init_acl(struct inode *inode, struct posix_acl *acl)
311316
{
312317
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
313-
struct posix_acl *acl = NULL, *clone;
318+
struct posix_acl *clone;
314319
mode_t mode;
315320
int rc = 0;
316321

317322
f->i_acl_access = JFFS2_ACL_NOT_CACHED;
318323
f->i_acl_default = JFFS2_ACL_NOT_CACHED;
319-
if (!S_ISLNK(inode->i_mode)) {
320-
acl = jffs2_get_acl(dir, ACL_TYPE_DEFAULT);
321-
if (IS_ERR(acl))
322-
return PTR_ERR(acl);
323-
if (!acl)
324-
inode->i_mode &= ~current->fs->umask;
325-
}
324+
326325
if (acl) {
327326
if (S_ISDIR(inode->i_mode)) {
328327
rc = jffs2_set_acl(inode, ACL_TYPE_DEFAULT, acl);

‎fs/jffs2/acl.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,18 @@ struct jffs2_acl_header {
2828

2929
#define JFFS2_ACL_NOT_CACHED ((void *)-1)
3030

31+
extern struct posix_acl *jffs2_get_acl(struct inode *inode, int type);
3132
extern int jffs2_permission(struct inode *, int, struct nameidata *);
3233
extern int jffs2_acl_chmod(struct inode *);
33-
extern int jffs2_init_acl(struct inode *, struct inode *);
34+
extern int jffs2_init_acl(struct inode *, struct posix_acl *);
3435
extern void jffs2_clear_acl(struct jffs2_inode_info *);
3536

3637
extern struct xattr_handler jffs2_acl_access_xattr_handler;
3738
extern struct xattr_handler jffs2_acl_default_xattr_handler;
3839

3940
#else
4041

42+
#define jffs2_get_acl(inode, type) (NULL)
4143
#define jffs2_permission NULL
4244
#define jffs2_acl_chmod(inode) (0)
4345
#define jffs2_init_acl(inode,dir) (0)

‎fs/jffs2/dir.c‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ static int jffs2_create(struct inode *dir_i, struct dentry *dentry, int mode,
182182
struct jffs2_inode_info *f, *dir_f;
183183
struct jffs2_sb_info *c;
184184
struct inode *inode;
185+
struct posix_acl *acl;
185186
int ret;
186187

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

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

195-
inode = jffs2_new_inode(dir_i, mode, ri);
196+
inode = jffs2_new_inode(dir_i, mode, ri, &acl);
196197

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

214215
if (ret)
215-
goto fail;
216+
goto fail_acl;
216217

217218
ret = jffs2_init_security(inode, dir_i);
218219
if (ret)
219-
goto fail;
220-
ret = jffs2_init_acl(inode, dir_i);
220+
goto fail_acl;
221+
ret = jffs2_init_acl(inode, acl);
221222
if (ret)
222223
goto fail;
223224

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

234+
fail_acl:
235+
posix_acl_release(acl);
233236
fail:
234237
make_bad_inode(inode);
235238
iput(inode);
@@ -306,6 +309,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
306309
struct jffs2_full_dirent *fd;
307310
int namelen;
308311
uint32_t alloclen;
312+
struct posix_acl *acl;
309313
int ret, targetlen = strlen(target);
310314

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

335-
inode = jffs2_new_inode(dir_i, S_IFLNK | S_IRWXUGO, ri);
339+
inode = jffs2_new_inode(dir_i, S_IFLNK | S_IRWXUGO, ri, &acl);
336340

337341
if (IS_ERR(inode)) {
338342
jffs2_free_raw_inode(ri);
@@ -362,6 +366,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
362366
up(&f->sem);
363367
jffs2_complete_reservation(c);
364368
jffs2_clear_inode(inode);
369+
posix_acl_release(acl);
365370
return PTR_ERR(fn);
366371
}
367372

@@ -372,6 +377,7 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
372377
up(&f->sem);
373378
jffs2_complete_reservation(c);
374379
jffs2_clear_inode(inode);
380+
posix_acl_release(acl);
375381
return -ENOMEM;
376382
}
377383

@@ -389,9 +395,10 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
389395
ret = jffs2_init_security(inode, dir_i);
390396
if (ret) {
391397
jffs2_clear_inode(inode);
398+
posix_acl_release(acl);
392399
return ret;
393400
}
394-
ret = jffs2_init_acl(inode, dir_i);
401+
ret = jffs2_init_acl(inode, acl);
395402
if (ret) {
396403
jffs2_clear_inode(inode);
397404
return ret;
@@ -469,6 +476,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
469476
struct jffs2_full_dirent *fd;
470477
int namelen;
471478
uint32_t alloclen;
479+
struct posix_acl *acl;
472480
int ret;
473481

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

494-
inode = jffs2_new_inode(dir_i, mode, ri);
502+
inode = jffs2_new_inode(dir_i, mode, ri, &acl);
495503

496504
if (IS_ERR(inode)) {
497505
jffs2_free_raw_inode(ri);
@@ -518,6 +526,7 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
518526
up(&f->sem);
519527
jffs2_complete_reservation(c);
520528
jffs2_clear_inode(inode);
529+
posix_acl_release(acl);
521530
return PTR_ERR(fn);
522531
}
523532
/* No data here. Only a metadata node, which will be
@@ -531,9 +540,10 @@ static int jffs2_mkdir (struct inode *dir_i, struct dentry *dentry, int mode)
531540
ret = jffs2_init_security(inode, dir_i);
532541
if (ret) {
533542
jffs2_clear_inode(inode);
543+
posix_acl_release(acl);
534544
return ret;
535545
}
536-
ret = jffs2_init_acl(inode, dir_i);
546+
ret = jffs2_init_acl(inode, acl);
537547
if (ret) {
538548
jffs2_clear_inode(inode);
539549
return ret;
@@ -629,6 +639,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
629639
union jffs2_device_node dev;
630640
int devlen = 0;
631641
uint32_t alloclen;
642+
struct posix_acl *acl;
632643
int ret;
633644

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

658-
inode = jffs2_new_inode(dir_i, mode, ri);
669+
inode = jffs2_new_inode(dir_i, mode, ri, &acl);
659670

660671
if (IS_ERR(inode)) {
661672
jffs2_free_raw_inode(ri);
@@ -684,6 +695,7 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
684695
up(&f->sem);
685696
jffs2_complete_reservation(c);
686697
jffs2_clear_inode(inode);
698+
posix_acl_release(acl);
687699
return PTR_ERR(fn);
688700
}
689701
/* No data here. Only a metadata node, which will be
@@ -697,9 +709,10 @@ static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, de
697709
ret = jffs2_init_security(inode, dir_i);
698710
if (ret) {
699711
jffs2_clear_inode(inode);
712+
posix_acl_release(acl);
700713
return ret;
701714
}
702-
ret = jffs2_init_acl(inode, dir_i);
715+
ret = jffs2_init_acl(inode, acl);
703716
if (ret) {
704717
jffs2_clear_inode(inode);
705718
return ret;

‎fs/jffs2/fs.c‎

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
static int jffs2_flash_setup(struct jffs2_sb_info *c);
2626

27-
static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
27+
int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
2828
{
2929
struct jffs2_full_dnode *old_metadata, *new_metadata;
3030
struct jffs2_inode_info *f = JFFS2_INODE_INFO(inode);
@@ -36,10 +36,8 @@ static int jffs2_do_setattr (struct inode *inode, struct iattr *iattr)
3636
unsigned int ivalid;
3737
uint32_t alloclen;
3838
int ret;
39+
3940
D1(printk(KERN_DEBUG "jffs2_setattr(): ino #%lu\n", inode->i_ino));
40-
ret = inode_change_ok(inode, iattr);
41-
if (ret)
42-
return ret;
4341

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

184+
rc = inode_change_ok(dentry->d_inode, iattr);
185+
if (rc)
186+
return rc;
187+
186188
rc = jffs2_do_setattr(dentry->d_inode, iattr);
187189
if (!rc && (iattr->ia_valid & ATTR_MODE))
188190
rc = jffs2_acl_chmod(dentry->d_inode);
191+
189192
return rc;
190193
}
191194

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

400403
/* jffs2_new_inode: allocate a new inode and inocache, add it to the hash,
401404
fill in the raw_inode while you're at it. */
402-
struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_inode *ri)
405+
struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_inode *ri,
406+
struct posix_acl **acl)
403407
{
404408
struct inode *inode;
405409
struct super_block *sb = dir_i->i_sb;
@@ -431,7 +435,23 @@ struct inode *jffs2_new_inode (struct inode *dir_i, int mode, struct jffs2_raw_i
431435
} else {
432436
ri->gid = cpu_to_je16(current->fsgid);
433437
}
434-
ri->mode = cpu_to_jemode(mode);
438+
439+
/* POSIX ACLs have to be processed now, at least partly.
440+
The umask is only applied if there's no default ACL */
441+
if (!S_ISLNK(mode)) {
442+
*acl = jffs2_get_acl(dir_i, ACL_TYPE_DEFAULT);
443+
if (IS_ERR(*acl)) {
444+
make_bad_inode(inode);
445+
iput(inode);
446+
inode = (void *)*acl;
447+
*acl = NULL;
448+
return inode;
449+
}
450+
if (!(*acl))
451+
mode &= ~current->fs->umask;
452+
} else {
453+
*acl = NULL;
454+
}
435455
ret = jffs2_do_new_inode (c, f, mode, ri);
436456
if (ret) {
437457
make_bad_inode(inode);

‎fs/jffs2/os-linux.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,15 @@ int jffs2_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
173173
extern const struct inode_operations jffs2_symlink_inode_operations;
174174

175175
/* fs.c */
176+
struct posix_acl;
177+
176178
int jffs2_setattr (struct dentry *, struct iattr *);
179+
int jffs2_do_setattr (struct inode *, struct iattr *);
177180
void jffs2_read_inode (struct inode *);
178181
void jffs2_clear_inode (struct inode *);
179182
void jffs2_dirty_inode(struct inode *inode);
180183
struct inode *jffs2_new_inode (struct inode *dir_i, int mode,
181-
struct jffs2_raw_inode *ri);
184+
struct jffs2_raw_inode *ri, struct posix_acl **acl);
182185
int jffs2_statfs (struct dentry *, struct kstatfs *);
183186
void jffs2_write_super (struct super_block *);
184187
int jffs2_remount_fs (struct super_block *, int *, char *);

0 commit comments

Comments
 (0)