Smack: ignore private inode for file functions 80/104080/2 accepted/tizen/common/20161213.164744 accepted/tizen/ivi/20161214.014117 accepted/tizen/mobile/20161214.014022 accepted/tizen/tv/20161214.014040 accepted/tizen/wearable/20161214.014056 submit/tizen/20161213.001106
authorSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 12 Dec 2016 08:21:40 +0000 (17:21 +0900)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Mon, 12 Dec 2016 08:40:23 +0000 (17:40 +0900)
The access to fd from anon_inode is always failed because there is
no set xattr operations. So this patch fixes to ignore private
inode including anon_inode for file functions.

It was only ignored for smack_file_receive() to share dma-buf fd,
but dma-buf has other functions like ioctl and mmap.

Reference: https://lkml.org/lkml/2015/4/17/16

Change-Id: I1c6b93107c17e1ca3d96360c5cb8ec18a29ba45e
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
security/smack/smack_lsm.c

index 793c23a43b4ff3d155bdb4bed2f6a3b95903eba7..38135fc9b802edb7bf8be44e676cda1de0c98aba 100644 (file)
@@ -1632,6 +1632,9 @@ static int smack_file_ioctl(struct file *file, unsigned int cmd,
        struct smk_audit_info ad;
        struct inode *inode = file_inode(file);
 
+       if (unlikely(IS_PRIVATE(inode)))
+               return 0;
+
        smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
        smk_ad_setfield_u_fs_path(&ad, file->f_path);
 
@@ -1661,6 +1664,9 @@ static int smack_file_lock(struct file *file, unsigned int cmd)
        int rc;
        struct inode *inode = file_inode(file);
 
+       if (unlikely(IS_PRIVATE(inode)))
+               return 0;
+
        smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
        smk_ad_setfield_u_fs_path(&ad, file->f_path);
        rc = smk_curacc(smk_of_inode(inode), MAY_LOCK, &ad);
@@ -1687,6 +1693,9 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd,
        int rc = 0;
        struct inode *inode = file_inode(file);
 
+       if (unlikely(IS_PRIVATE(inode)))
+               return 0;
+
        switch (cmd) {
        case F_GETLK:
                break;
@@ -1739,6 +1748,9 @@ static int smack_mmap_file(struct file *file,
        if (file == NULL)
                return 0;
 
+       if (unlikely(IS_PRIVATE(file_inode(file))))
+               return 0;
+
        isp = file_inode(file)->i_security;
        if (isp->smk_mmap == NULL)
                return 0;