Skip to content

Commit d3d7159

Browse files
committed
zpl_inode.c: Fix SMACK interoperability
closes: #11646 ref: #11646 (comment) ref: cschaufler/smack-next#1 SMACK needs to have the ZFS dentry security field setup before SMACK's d_instantiate() hook is called as it requires functioning '__vfs_getxattr()' calls to properly set the labels. Fixes: 1) file instantiation properly setting the object label to the subject's label 2) proper file labelling in a transmutable directory Functions Updated: 1) zpl_create() 2) zpl_mknod() 3) zpl_mkdir() 4) zpl_symlink() Signed-off-by: TerraTech <[email protected]>
1 parent ec58022 commit d3d7159

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

include/os/linux/zfs/sys/zpl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ extern const struct file_operations zpl_dir_file_operations;
5252

5353
/* zpl_super.c */
5454
extern void zpl_prune_sb(int64_t nr_to_scan, void *arg);
55+
extern void zpl_inode_destroy(struct inode *ip);
5556

5657
extern const struct super_operations zpl_super_operations;
5758
extern const struct export_operations zpl_export_operations;

module/os/linux/zfs/zpl_inode.c

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,16 @@ zpl_create(struct inode *dir, struct dentry *dentry, umode_t mode, bool flag)
149149
error = -zfs_create(ITOZ(dir), dname(dentry), vap, 0,
150150
mode, &zp, cr, 0, NULL);
151151
if (error == 0) {
152-
d_instantiate(dentry, ZTOI(zp));
153-
154152
error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
155153
if (error == 0)
156154
error = zpl_init_acl(ZTOI(zp), dir);
157155

158-
if (error)
156+
if (error) {
159157
(void) zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
158+
zpl_inode_destroy(ZTOI(zp));
159+
} else {
160+
d_instantiate(dentry, ZTOI(zp));
161+
}
160162
}
161163

162164
spl_fstrans_unmark(cookie);
@@ -198,14 +200,16 @@ zpl_mknod(struct inode *dir, struct dentry *dentry, umode_t mode,
198200
error = -zfs_create(ITOZ(dir), dname(dentry), vap, 0,
199201
mode, &zp, cr, 0, NULL);
200202
if (error == 0) {
201-
d_instantiate(dentry, ZTOI(zp));
202-
203203
error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
204204
if (error == 0)
205205
error = zpl_init_acl(ZTOI(zp), dir);
206206

207-
if (error)
207+
if (error) {
208208
(void) zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
209+
zpl_inode_destroy(ZTOI(zp));
210+
} else {
211+
d_instantiate(dentry, ZTOI(zp));
212+
}
209213
}
210214

211215
spl_fstrans_unmark(cookie);
@@ -308,14 +312,16 @@ zpl_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
308312
cookie = spl_fstrans_mark();
309313
error = -zfs_mkdir(ITOZ(dir), dname(dentry), vap, &zp, cr, 0, NULL);
310314
if (error == 0) {
311-
d_instantiate(dentry, ZTOI(zp));
312-
313315
error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
314316
if (error == 0)
315317
error = zpl_init_acl(ZTOI(zp), dir);
316318

317-
if (error)
319+
if (error) {
318320
(void) zfs_rmdir(ITOZ(dir), dname(dentry), NULL, cr, 0);
321+
zpl_inode_destroy(ZTOI(zp));
322+
} else {
323+
d_instantiate(dentry, ZTOI(zp));
324+
}
319325
}
320326

321327
spl_fstrans_unmark(cookie);
@@ -488,11 +494,13 @@ zpl_symlink(struct inode *dir, struct dentry *dentry, const char *name)
488494
error = -zfs_symlink(ITOZ(dir), dname(dentry), vap,
489495
(char *)name, &zp, cr, 0);
490496
if (error == 0) {
491-
d_instantiate(dentry, ZTOI(zp));
492-
493497
error = zpl_xattr_security_init(ZTOI(zp), dir, &dentry->d_name);
494-
if (error)
498+
if (error) {
495499
(void) zfs_remove(ITOZ(dir), dname(dentry), cr, 0);
500+
zpl_inode_destroy(ZTOI(zp));
501+
} else {
502+
d_instantiate(dentry, ZTOI(zp));
503+
}
496504
}
497505

498506
spl_fstrans_unmark(cookie);

module/os/linux/zfs/zpl_super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ zpl_inode_alloc(struct super_block *sb)
4141
return (ip);
4242
}
4343

44-
static void
44+
void
4545
zpl_inode_destroy(struct inode *ip)
4646
{
4747
ASSERT(atomic_read(&ip->i_count) == 0);

0 commit comments

Comments
 (0)