mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Morris <jmorris@namei.org>
To: linux-security-module@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 08/20] selinux: simplify ioctl checking
Date: Tue,  8 Jul 2008 01:42:10 +0900	[thread overview]
Message-ID: <1215448942-17581-9-git-send-email-jmorris@namei.org> (raw)
In-Reply-To: <1215448942-17581-1-git-send-email-jmorris@namei.org>

From: Stephen Smalley <sds@tycho.nsa.gov>

Simplify and improve the robustness of the SELinux ioctl checking by
using the "access mode" bits of the ioctl command to determine the
permission check rather than dealing with individual command values.
This removes any knowledge of specific ioctl commands from SELinux
and follows the same guidance we gave to Smack earlier.

Signed-off-by:  Stephen Smalley <sds@tycho.nsa.gov>
Signed-off-by: James Morris <jmorris@namei.org>
---
 security/selinux/hooks.c |   48 +++++++--------------------------------------
 1 files changed, 8 insertions(+), 40 deletions(-)

diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
index 91b666a..f530008 100644
--- a/security/selinux/hooks.c
+++ b/security/selinux/hooks.c
@@ -42,9 +42,7 @@
 #include <linux/fdtable.h>
 #include <linux/namei.h>
 #include <linux/mount.h>
-#include <linux/ext2_fs.h>
 #include <linux/proc_fs.h>
-#include <linux/kd.h>
 #include <linux/netfilter_ipv4.h>
 #include <linux/netfilter_ipv6.h>
 #include <linux/tty.h>
@@ -2903,46 +2901,16 @@ static void selinux_file_free_security(struct file *file)
 static int selinux_file_ioctl(struct file *file, unsigned int cmd,
 			      unsigned long arg)
 {
-	int error = 0;
-
-	switch (cmd) {
-	case FIONREAD:
-	/* fall through */
-	case FIBMAP:
-	/* fall through */
-	case FIGETBSZ:
-	/* fall through */
-	case EXT2_IOC_GETFLAGS:
-	/* fall through */
-	case EXT2_IOC_GETVERSION:
-		error = file_has_perm(current, file, FILE__GETATTR);
-		break;
-
-	case EXT2_IOC_SETFLAGS:
-	/* fall through */
-	case EXT2_IOC_SETVERSION:
-		error = file_has_perm(current, file, FILE__SETATTR);
-		break;
-
-	/* sys_ioctl() checks */
-	case FIONBIO:
-	/* fall through */
-	case FIOASYNC:
-		error = file_has_perm(current, file, 0);
-		break;
+	u32 av = 0;
 
-	case KDSKBENT:
-	case KDSKBSENT:
-		error = task_has_capability(current, CAP_SYS_TTY_CONFIG);
-		break;
+	if (_IOC_DIR(cmd) & _IOC_WRITE)
+		av |= FILE__WRITE;
+	if (_IOC_DIR(cmd) & _IOC_READ)
+		av |= FILE__READ;
+	if (!av)
+		av = FILE__IOCTL;
 
-	/* default case assumes that the command will go
-	 * to the file's ioctl() function.
-	 */
-	default:
-		error = file_has_perm(current, file, FILE__IOCTL);
-	}
-	return error;
+	return file_has_perm(current, file, av);
 }
 
 static int file_map_prot_check(struct file *file, unsigned long prot, int shared)
-- 
1.5.5.1


  parent reply	other threads:[~2008-07-07 16:52 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-07 16:42 SELinux patches for 2.6.26 James Morris
2008-07-07 16:42 ` [PATCH 01/20] selinux: support deferred mapping of contexts James Morris
2008-07-07 16:42 ` [PATCH 02/20] SELinux: fix sleeping allocation in security_context_to_sid James Morris
2008-07-07 16:42 ` [PATCH 03/20] SELinux: keep the code clean formating and syntax James Morris
2008-07-07 16:42 ` [PATCH 04/20] SELinux: reorder inode_security_struct to increase objs/slab on 64bit James Morris
2008-07-07 16:42 ` [PATCH 05/20] SELinux: remove inherit field from inode_security_struct James Morris
2008-07-07 16:42 ` [PATCH 06/20] Security: split proc ptrace checking into read vs. attach James Morris
2008-07-07 16:42 ` [PATCH 07/20] SELinux: enable processes with mac_admin to get the raw inode contexts James Morris
2008-07-07 16:42 ` James Morris [this message]
2008-07-07 16:42 ` [PATCH 09/20] selinux: fix endianness bug in network node address handling James Morris
2008-07-07 16:42 ` [PATCH 10/20] SELinux: open code policy_rwlock James Morris
2008-07-07 16:42 ` [PATCH 11/20] SELinux: open code load_mutex James Morris
2008-07-07 16:42 ` [PATCH 12/20] SELinux: open code sidtab lock James Morris
2008-07-07 16:42 ` [PATCH 13/20] SELinux: fix off by 1 reference of class_to_string in context_struct_compute_av James Morris
2008-07-07 16:42 ` [PATCH 14/20] SELinux: drop load_mutex in security_load_policy James Morris
2008-07-07 16:42 ` [PATCH 15/20] selinux: change handling of invalid classes (Was: Re: 2.6.26-rc5-mm1 selinux whine) James Morris
2008-07-07 16:42 ` [PATCH 16/20] SELinux: more user friendly unknown handling printk James Morris
2008-07-07 16:42 ` [PATCH 17/20] SELinux: remove unused and shadowed addrlen variable James Morris
2008-07-07 16:42 ` [PATCH 18/20] SELinux: use do_each_thread as a proper do/while block James Morris
2008-07-07 16:42 ` [PATCH 19/20] security: fix return of void-valued expressions James Morris
2008-07-07 16:42 ` [PATCH 20/20] SELinux: allow fstype unknown to policy to use xattrs if present James Morris
2008-07-07 18:23 ` SELinux patches for 2.6.26 Theodore Tso
2008-07-07 22:49   ` James Morris

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1215448942-17581-9-git-send-email-jmorris@namei.org \
    --to=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®