aboutsummaryrefslogtreecommitdiffstats
path: root/security/smack
diff options
context:
space:
mode:
authorCasey Schaufler <casey@schaufler-ca.com>2015-12-07 17:34:32 -0500
committerCasey Schaufler <casey@schaufler-ca.com>2015-12-09 19:10:55 -0500
commit79be093500791cc25cc31bcaec5a4db62e21497b (patch)
tree4cdbb37c73f0e8f4112d9780880b23c0fdfd7890 /security/smack
parentebd68df3f24b318d391d15c458d6f43f340ba36a (diff)
Smack: File receive for sockets
The existing file receive hook checks for access on the file inode even for UDS. This is not right, as the inode is not used by Smack to make access checks for sockets. This change checks for an appropriate access relationship between the receiving (current) process and the socket. If the process can't write to the socket's send label or the socket's receive label can't write to the process fail. This will allow the legitimate cases, where the socket sender and socket receiver can freely communicate. Only strangly set socket labels should cause a problem. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
Diffstat (limited to 'security/smack')
-rw-r--r--security/smack/smack_lsm.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index ff81026f6ddb..b20ef0602267 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1860,12 +1860,34 @@ static int smack_file_receive(struct file *file)
1860 int may = 0; 1860 int may = 0;
1861 struct smk_audit_info ad; 1861 struct smk_audit_info ad;
1862 struct inode *inode = file_inode(file); 1862 struct inode *inode = file_inode(file);
1863 struct socket *sock;
1864 struct task_smack *tsp;
1865 struct socket_smack *ssp;
1863 1866
1864 if (unlikely(IS_PRIVATE(inode))) 1867 if (unlikely(IS_PRIVATE(inode)))
1865 return 0; 1868 return 0;
1866 1869
1867 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH); 1870 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1868 smk_ad_setfield_u_fs_path(&ad, file->f_path); 1871 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1872
1873 if (S_ISSOCK(inode->i_mode)) {
1874 sock = SOCKET_I(inode);
1875 ssp = sock->sk->sk_security;
1876 tsp = current_security();
1877 /*
1878 * If the receiving process can't write to the
1879 * passed socket or if the passed socket can't
1880 * write to the receiving process don't accept
1881 * the passed socket.
1882 */
1883 rc = smk_access(tsp->smk_task, ssp->smk_out, MAY_WRITE, &ad);
1884 rc = smk_bu_file(file, may, rc);
1885 if (rc < 0)
1886 return rc;
1887 rc = smk_access(ssp->smk_in, tsp->smk_task, MAY_WRITE, &ad);
1888 rc = smk_bu_file(file, may, rc);
1889 return rc;
1890 }
1869 /* 1891 /*
1870 * This code relies on bitmasks. 1892 * This code relies on bitmasks.
1871 */ 1893 */