Return-Path: Received: from mail-by2nam03on0107.outbound.protection.outlook.com ([104.47.42.107]:4912 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S934310AbeCSQAv (ORCPT ); Mon, 19 Mar 2018 12:00:51 -0400 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Stephen Smalley , Paul Moore , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 097/281] selinux: do not check open permission on sockets Date: Mon, 19 Mar 2018 15:59:47 +0000 Message-ID: <20180319155742.13731-97-alexander.levin@microsoft.com> References: <20180319155742.13731-1-alexander.levin@microsoft.com> In-Reply-To: <20180319155742.13731-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Stephen Smalley [ Upstream commit ccb544781d34afdb73a9a73ae53035d824d193bf ] open permission is currently only defined for files in the kernel (COMMON_FILE_PERMS rather than COMMON_FILE_SOCK_PERMS). Construction of an artificial test case that tries to open a socket via /proc/pid/fd will generate a recvfrom avc denial because recvfrom and open happen to map to the same permission bit in socket vs file classes. open of a socket via /proc/pid/fd is not supported by the kernel regardless and will ultimately return ENXIO. But we hit the permission check first and can thus produce these odd/misleading denials. Omit the open check when operating on a socket. Signed-off-by: Stephen Smalley Signed-off-by: Paul Moore Signed-off-by: Sasha Levin --- security/selinux/hooks.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c index c2da45ae5b2a..a3d2db613974 100644 --- a/security/selinux/hooks.c +++ b/security/selinux/hooks.c @@ -2049,8 +2049,9 @@ static inline u32 file_to_av(struct file *file) static inline u32 open_file_to_av(struct file *file) { u32 av =3D file_to_av(file); + struct inode *inode =3D file_inode(file); =20 - if (selinux_policycap_openperm) + if (selinux_policycap_openperm && inode->i_sb->s_magic !=3D SOCKFS_MAGIC) av |=3D FILE__OPEN; =20 return av; @@ -3047,6 +3048,7 @@ static int selinux_inode_permission(struct inode *ino= de, int mask) static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iatt= r) { const struct cred *cred =3D current_cred(); + struct inode *inode =3D d_backing_inode(dentry); unsigned int ia_valid =3D iattr->ia_valid; __u32 av =3D FILE__WRITE; =20 @@ -3062,8 +3064,10 @@ static int selinux_inode_setattr(struct dentry *dent= ry, struct iattr *iattr) ATTR_ATIME_SET | ATTR_MTIME_SET | ATTR_TIMES_SET)) return dentry_has_perm(cred, dentry, FILE__SETATTR); =20 - if (selinux_policycap_openperm && (ia_valid & ATTR_SIZE) - && !(ia_valid & ATTR_FILE)) + if (selinux_policycap_openperm && + inode->i_sb->s_magic !=3D SOCKFS_MAGIC && + (ia_valid & ATTR_SIZE) && + !(ia_valid & ATTR_FILE)) av |=3D FILE__OPEN; =20 return dentry_has_perm(cred, dentry, av); --=20 2.14.1