rpms/kernel/devel linux-2.6-audit-git.patch, NONE, 1.1.6.1 linux-2.6-audit-promisc.patch, NONE, 1.1.2.1 linux-2.6-audit-rule-log.patch, NONE, 1.1.2.1 linux-2.6-audit-string-1.patch, NONE, 1.1.2.1 linux-2.6-audit-string-2.patch, NONE, 1.1.2.1 linux-2.6-audit-tty.patch, NONE, 1.1.2.1 linux-2.6-unshare-1.patch, NONE, 1.1.2.1 linux-2.6-unshare-10.patch, NONE, 1.1.2.1 linux-2.6-unshare-2.patch, NONE, 1.1.2.1 linux-2.6-unshare-3.patch, NONE, 1.1.2.1 linux-2.6-unshare-4.patch, NONE, 1.1.2.1 linux-2.6-unshare-5.patch, NONE, 1.1.2.1 linux-2.6-unshare-6.patch, NONE, 1.1.2.1 linux-2.6-unshare-7.patch, NONE, 1.1.2.1 linux-2.6-unshare-8.patch, NONE, 1.1.2.1 linux-2.6-unshare-9.patch, NONE, 1.1.2.1 kernel-2.6.spec, 1.1826.2.10, 1.1826.2.10.2.1

fedora-cvs-commits at redhat.com fedora-cvs-commits at redhat.com
Fri Jan 13 17:17:19 UTC 2006


Author: dwmw2

Update of /cvs/dist/rpms/kernel/devel
In directory cvs.devel.redhat.com:/tmp/cvs-serv26343

Modified Files:
      Tag: private-fc5-test2-lspp-branch
	kernel-2.6.spec 
Added Files:
      Tag: private-fc5-test2-lspp-branch
	linux-2.6-audit-git.patch linux-2.6-audit-promisc.patch 
	linux-2.6-audit-rule-log.patch linux-2.6-audit-string-1.patch 
	linux-2.6-audit-string-2.patch linux-2.6-audit-tty.patch 
	linux-2.6-unshare-1.patch linux-2.6-unshare-10.patch 
	linux-2.6-unshare-2.patch linux-2.6-unshare-3.patch 
	linux-2.6-unshare-4.patch linux-2.6-unshare-5.patch 
	linux-2.6-unshare-6.patch linux-2.6-unshare-7.patch 
	linux-2.6-unshare-8.patch linux-2.6-unshare-9.patch 
Log Message:
lspp.6 kernel

linux-2.6-audit-git.patch:
 arch/ia64/kernel/ptrace.c      |   10 
 fs/namei.c                     |   14 
 fs/open.c                      |    8 
 fs/xattr.c                     |   11 
 include/linux/audit.h          |   98 ++++-
 include/linux/fsnotify.h       |   14 
 include/linux/security.h       |   33 +
 ipc/msg.c                      |    5 
 ipc/sem.c                      |    5 
 ipc/shm.c                      |    4 
 ipc/util.c                     |    2 
 kernel/Makefile                |    2 
 kernel/audit.c                 |  142 +++++--
 kernel/audit.h                 |   70 +++
 kernel/auditfilter.c           |  375 +++++++++++++++++++
 kernel/auditsc.c               |  786 +++++++++++++++++++++--------------------
 security/dummy.c               |   14 
 security/selinux/hooks.c       |   98 ++---
 security/selinux/nlmsgtab.c    |    6 
 security/selinux/selinuxfs.c   |   11 
 security/selinux/ss/services.c |   15 
 21 files changed, 1204 insertions(+), 519 deletions(-)

--- NEW FILE linux-2.6-audit-git.patch ---
diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
index 4b19d04..49fd3f6 100644
--- a/arch/ia64/kernel/ptrace.c
+++ b/arch/ia64/kernel/ptrace.c
@@ -1663,8 +1663,14 @@ syscall_trace_leave (long arg0, long arg
 		     long arg4, long arg5, long arg6, long arg7,
 		     struct pt_regs regs)
 {
-	if (unlikely(current->audit_context))
-		audit_syscall_exit(current, AUDITSC_RESULT(regs.r10), regs.r8);
+	if (unlikely(current->audit_context)) {
+		int success = AUDITSC_RESULT(regs.r10);
+		long result = regs.r8;
+
+		if (success != AUDITSC_SUCCESS)
+			result = -result;
+		audit_syscall_exit(current, success, result);
+	}
 
 	if (test_thread_flag(TIF_SYSCALL_TRACE)
 	    && (current->ptrace & PT_PTRACED))
diff --git a/fs/namei.c b/fs/namei.c
index 6dbbd42..55798c3 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1090,8 +1090,7 @@ int fastcall path_lookup(const char *nam
 	current->total_link_count = 0;
 	retval = link_path_walk(name, nd);
 out:
-	if (unlikely(current->audit_context
-		     && nd && nd->dentry && nd->dentry->d_inode))
+	if (nd && nd->dentry && nd->dentry->d_inode)
 		audit_inode(name, nd->dentry->d_inode, flags);
 	return retval;
 }
@@ -1301,6 +1300,7 @@ static inline int may_delete(struct inod
 		return -ENOENT;
 
 	BUG_ON(victim->d_parent->d_inode != dir);
+	audit_inode_child(victim->d_name.name, victim->d_inode, dir->i_ino);
 
 	error = permission(dir,MAY_WRITE | MAY_EXEC, NULL);
 	if (error)
@@ -1420,7 +1420,7 @@ int vfs_create(struct inode *dir, struct
 	DQUOT_INIT(dir);
 	error = dir->i_op->create(dir, dentry, mode, nd);
 	if (!error)
-		fsnotify_create(dir, dentry->d_name.name);
+		fsnotify_create(dir, dentry);
 	return error;
 }
 
@@ -1739,7 +1739,7 @@ int vfs_mknod(struct inode *dir, struct 
 	DQUOT_INIT(dir);
 	error = dir->i_op->mknod(dir, dentry, mode, dev);
 	if (!error)
-		fsnotify_create(dir, dentry->d_name.name);
+		fsnotify_create(dir, dentry);
 	return error;
 }
 
@@ -1810,7 +1810,7 @@ int vfs_mkdir(struct inode *dir, struct 
 	DQUOT_INIT(dir);
 	error = dir->i_op->mkdir(dir, dentry, mode);
 	if (!error)
-		fsnotify_mkdir(dir, dentry->d_name.name);
+		fsnotify_mkdir(dir, dentry);
 	return error;
 }
 
@@ -2047,7 +2047,7 @@ int vfs_symlink(struct inode *dir, struc
 	DQUOT_INIT(dir);
 	error = dir->i_op->symlink(dir, dentry, oldname);
 	if (!error)
-		fsnotify_create(dir, dentry->d_name.name);
+		fsnotify_create(dir, dentry);
 	return error;
 }
 
@@ -2118,7 +2118,7 @@ int vfs_link(struct dentry *old_dentry, 
 	error = dir->i_op->link(old_dentry, dir, new_dentry);
 	up(&old_dentry->d_inode->i_sem);
 	if (!error)
-		fsnotify_create(dir, new_dentry->d_name.name);
+		fsnotify_create(dir, new_dentry);
 	return error;
 }
 
diff --git a/fs/open.c b/fs/open.c
index f53a5b9..3231a67 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -25,6 +25,7 @@
 #include <linux/pagemap.h>
 #include <linux/syscalls.h>
 #include <linux/rcupdate.h>
+#include <linux/audit.h>
 
 #include <asm/unistd.h>
 
@@ -613,6 +614,8 @@ asmlinkage long sys_fchmod(unsigned int 
 	dentry = file->f_dentry;
 	inode = dentry->d_inode;
 
+	audit_inode(NULL, inode, 0);
+
 	err = -EROFS;
 	if (IS_RDONLY(inode))
 		goto out_putf;
@@ -736,7 +739,10 @@ asmlinkage long sys_fchown(unsigned int 
 
 	file = fget(fd);
 	if (file) {
-		error = chown_common(file->f_dentry, user, group);
+		struct dentry * dentry;
+		dentry = file->f_dentry;
+		audit_inode(NULL, dentry->d_inode, 0);
+		error = chown_common(dentry, user, group);
 		fput(file);
 	}
 	return error;
diff --git a/fs/xattr.c b/fs/xattr.c
index bcc2156..8f40edf 100644
--- a/fs/xattr.c
+++ b/fs/xattr.c
@@ -17,6 +17,7 @@
 #include <linux/syscalls.h>
 #include <linux/module.h>
 #include <linux/fsnotify.h>
+#include <linux/audit.h>
 #include <asm/uaccess.h>
 
 /*
@@ -113,12 +114,15 @@ sys_fsetxattr(int fd, char __user *name,
 	      size_t size, int flags)
 {
 	struct file *f;
+	struct dentry *dentry;
 	int error = -EBADF;
 
 	f = fget(fd);
 	if (!f)
 		return error;
-	error = setxattr(f->f_dentry, name, value, size, flags);
+	dentry = f->f_dentry;
+	audit_inode(NULL, dentry->d_inode, 0);
+	error = setxattr(dentry, name, value, size, flags);
 	fput(f);
 	return error;
 }
@@ -365,12 +369,15 @@ asmlinkage long
 sys_fremovexattr(int fd, char __user *name)
 {
 	struct file *f;
+	struct dentry *dentry;
 	int error = -EBADF;
 
 	f = fget(fd);
 	if (!f)
 		return error;
-	error = removexattr(f->f_dentry, name);
+	dentry = f->f_dentry;
+	audit_inode(NULL, dentry->d_inode, 0);
+	error = removexattr(dentry, name);
 	fput(f);
 	return error;
 }
diff --git a/include/linux/audit.h b/include/linux/audit.h
index da3c019..a485639 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -33,11 +33,20 @@
  * 1200 - 1299 messages internal to the audit daemon
  * 1300 - 1399 audit event messages
  * 1400 - 1499 SE Linux use
- * 1500 - 1999 future use
- * 2000 is for otherwise unclassified kernel audit messages
+ * 1500 - 1599 kernel LSPP events
+ * 1600 - 1699 kernel crypto events
+ * 1700 - 1999 future kernel use (maybe integrity labels and related events)
+ * 2000 is for otherwise unclassified kernel audit messages (legacy)
+ * 2001 - 2099 unused (kernel)
+ * 2100 - 2199 user space anomaly records
+ * 2200 - 2299 user space actions taken in response to anomalies
+ * 2300 - 2399 user space generated LSPP events
+ * 2400 - 2499 user space crypto events
+ * 2500 - 2999 future user space (maybe integrity labels and related events)
  *
- * Messages from 1000-1199 are bi-directional. 1200-1299 are exclusively user
- * space. Anything over that is kernel --> user space communication.
+ * Messages from 1000-1199 are bi-directional. 1200-1299 & 2100 - 2999 are
+ * exclusively user space. 1300-2099 is kernel --> user space 
+ * communication.
  */
 #define AUDIT_GET		1000	/* Get status */
 #define AUDIT_SET		1001	/* Set status (enable/disable/auditd) */
@@ -54,6 +63,8 @@
 #define AUDIT_FIRST_USER_MSG	1100	/* Userspace messages mostly uninteresting to kernel */
 #define AUDIT_USER_AVC		1107	/* We filter this differently */
[...2439 lines suppressed...]
-		rc = -EOPNOTSUPP;
-		goto out;
-	}
-
-	rc = security_sid_to_context(isec->sid, &context, &len);
-	if (rc)
-		goto out;
-
-	/* Probe for required buffer size */
-	if (!buffer || !size) {
-		rc = len;
-		goto out_free;
-	}
 
-	if (size < len) {
-		rc = -ERANGE;
-		goto out_free;
-	}
+	if (strcmp(name, XATTR_SELINUX_SUFFIX))
+		return -EOPNOTSUPP;
 
-	if (err > 0) {
-		if ((len == err) && !(memcmp(context, buffer, len))) {
-			/* Don't need to canonicalize value */
-			rc = err;
-			goto out_free;
-		}
-		memset(buffer, 0, size);
-	}
-	memcpy(buffer, context, len);
-	rc = len;
-out_free:
-	kfree(context);
-out:
-	return rc;
+	return selinux_getsecurity(isec->sid, buffer, size);
 }
 
 static int selinux_inode_setsecurity(struct inode *inode, const char *name,
@@ -4054,6 +4052,13 @@ static int selinux_ipc_permission(struct
 	return ipc_has_perm(ipcp, av);
 }
 
+static int selinux_ipc_getsecurity(struct kern_ipc_perm *ipcp, void *buffer, size_t size)
+{
+	struct ipc_security_struct *isec = ipcp->security;
+
+	return selinux_getsecurity(isec->sid, buffer, size);
+}
+
 /* module stacking operations */
 static int selinux_register_security (const char *name, struct security_operations *ops)
 {
@@ -4095,8 +4100,7 @@ static int selinux_getprocattr(struct ta
 			       char *name, void *value, size_t size)
 {
 	struct task_security_struct *tsec;
-	u32 sid, len;
-	char *context;
+	u32 sid;
 	int error;
 
 	if (current != p) {
@@ -4105,9 +4109,6 @@ static int selinux_getprocattr(struct ta
 			return error;
 	}
 
-	if (!size)
-		return -ERANGE;
-
 	tsec = p->security;
 
 	if (!strcmp(name, "current"))
@@ -4124,16 +4125,7 @@ static int selinux_getprocattr(struct ta
 	if (!sid)
 		return 0;
 
-	error = security_sid_to_context(sid, &context, &len);
-	if (error)
-		return error;
-	if (len > size) {
-		kfree(context);
-		return -ERANGE;
-	}
-	memcpy(value, context, len);
-	kfree(context);
-	return len;
+	return selinux_getsecurity(sid, value, size);
 }
 
 static int selinux_setprocattr(struct task_struct *p,
@@ -4291,6 +4283,7 @@ static struct security_operations selinu
 	.inode_getxattr =		selinux_inode_getxattr,
 	.inode_listxattr =		selinux_inode_listxattr,
 	.inode_removexattr =		selinux_inode_removexattr,
+	.inode_xattr_getsuffix =        selinux_inode_xattr_getsuffix,
 	.inode_getsecurity =            selinux_inode_getsecurity,
 	.inode_setsecurity =            selinux_inode_setsecurity,
 	.inode_listsecurity =           selinux_inode_listsecurity,
@@ -4328,6 +4321,7 @@ static struct security_operations selinu
 	.task_to_inode =                selinux_task_to_inode,
 
 	.ipc_permission =		selinux_ipc_permission,
+	.ipc_getsecurity =		selinux_ipc_getsecurity,
 
 	.msg_msg_alloc_security =	selinux_msg_msg_alloc_security,
 	.msg_msg_free_security =	selinux_msg_msg_free_security,
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c
index 69b9329..d7c0e91 100644
--- a/security/selinux/nlmsgtab.c
+++ b/security/selinux/nlmsgtab.c
@@ -145,8 +145,10 @@ int selinux_nlmsg_lookup(u16 sclass, u16
 		break;
 
 	case SECCLASS_NETLINK_AUDIT_SOCKET:
-		if (nlmsg_type >= AUDIT_FIRST_USER_MSG &&
-		    nlmsg_type <= AUDIT_LAST_USER_MSG) {
+		if ((nlmsg_type >= AUDIT_FIRST_USER_MSG &&
+		     nlmsg_type <= AUDIT_LAST_USER_MSG) ||
+		    (nlmsg_type >= AUDIT_FIRST_USER_MSG2 &&
+                     nlmsg_type <= AUDIT_LAST_USER_MSG2)) {
 			*perm = NETLINK_AUDIT_SOCKET__NLMSG_RELAY;
 		} else {
 			err = nlmsg_perm(nlmsg_type, perm, nlmsg_audit_perms,
diff --git a/security/selinux/selinuxfs.c b/security/selinux/selinuxfs.c
index 0e1352a..e64923b 100644
--- a/security/selinux/selinuxfs.c
+++ b/security/selinux/selinuxfs.c
@@ -21,6 +21,7 @@
 #include <linux/major.h>
 #include <linux/seq_file.h>
 #include <linux/percpu.h>
+#include <linux/audit.h>
 #include <asm/uaccess.h>
 #include <asm/semaphore.h>
 
@@ -126,6 +127,10 @@ static ssize_t sel_write_enforce(struct 
 		length = task_has_security(current, SECURITY__SETENFORCE);
 		if (length)
 			goto out;
+		audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_STATUS,
+			"enforcing=%d old_enforcing=%d auid=%u", new_value, 
+			selinux_enforcing,
+			audit_get_loginuid(current->audit_context));
 		selinux_enforcing = new_value;
 		if (selinux_enforcing)
 			avc_ss_reset(0);
@@ -176,6 +181,9 @@ static ssize_t sel_write_disable(struct 
 		length = selinux_disable();
 		if (length < 0)
 			goto out;
+		audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_STATUS,
+			"selinux=0 auid=%u",
+			audit_get_loginuid(current->audit_context));
 	}
 
 	length = count;
@@ -261,6 +269,9 @@ static ssize_t sel_write_load(struct fil
 		length = ret;
 	else
 		length = count;
+	audit_log(current->audit_context, GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
+		"policy loaded auid=%u",
+		audit_get_loginuid(current->audit_context));
 out:
 	up(&sel_sem);
 	vfree(data);
diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
index 44eb4d7..2311255 100644
--- a/security/selinux/ss/services.c
+++ b/security/selinux/ss/services.c
@@ -1758,19 +1758,22 @@ int security_set_bools(int len, int *val
 		goto out;
 	}
 
-	printk(KERN_INFO "security: committed booleans { ");
 	for (i = 0; i < len; i++) {
+		if (!!values[i] != policydb.bool_val_to_struct[i]->state) {
+			audit_log(current->audit_context, GFP_ATOMIC,
+				AUDIT_MAC_CONFIG_CHANGE,
+				"bool=%s val=%d old_val=%d auid=%u",
+				policydb.p_bool_val_to_name[i],
+				!!values[i],
+				policydb.bool_val_to_struct[i]->state,
+				audit_get_loginuid(current->audit_context));
+		}
 		if (values[i]) {
 			policydb.bool_val_to_struct[i]->state = 1;
 		} else {
 			policydb.bool_val_to_struct[i]->state = 0;
 		}
-		if (i != 0)
-			printk(", ");
-		printk("%s:%d", policydb.p_bool_val_to_name[i],
-		       policydb.bool_val_to_struct[i]->state);
 	}
-	printk(" }\n");
 
 	for (cur = policydb.cond_list; cur != NULL; cur = cur->next) {
 		rc = evaluate_cond_node(&policydb, cur);

linux-2.6-audit-promisc.patch:
 include/linux/audit.h |    7 ++++++-
 net/core/dev.c        |    7 +++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

--- NEW FILE linux-2.6-audit-promisc.patch ---
>From linux-audit-bounces at redhat.com Sat Dec  3 13:39:07 2005
Return-path: <linux-audit-bounces at redhat.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Sat, 03 Dec 2005 13:39:07 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EiXbW-0003Ra-S4 for dwmw2 at baythorne.infradead.org; Sat, 03 Dec 2005
	13:39:07 +0000
Received: from hormel.redhat.com ([209.132.177.30]) by
	pentafluge.infradead.org with esmtp (Exim 4.54 #1 (Red Hat Linux)) id
	1EiXbU-0006dw-2W for dwmw2 at infradead.org; Sat, 03 Dec 2005 13:39:06 +0000
Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com
	[10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 18B39732FF; Sat,
	 3 Dec 2005 08:39:03 -0500 (EST)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com
	[172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP
	id jB3Dd1du018704; Sat, 3 Dec 2005 08:39:01 -0500
Received: from mail.boston.redhat.com (mail.boston.redhat.com
	[172.16.76.12]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id
	jB3Dd1V16833; Sat, 3 Dec 2005 08:39:01 -0500
Received: from vpn83-123.boston.redhat.com (vpn83-123.boston.redhat.com
	[172.16.83.123]) by mail.boston.redhat.com (8.12.8/8.12.8) with ESMTP id
	jB3Dd0EW010094;  Sat, 3 Dec 2005 08:39:00 -0500
From: Steve Grubb <sgrubb at redhat.com>
To: Linux Audit Discussion <linux-audit at redhat.com>
Date: Sat, 3 Dec 2005 08:39:35 -0500
User-Agent: KMail/1.7.2
MIME-Version: 1.0
Content-Type: Multipart/Mixed; boundary="Boundary-00=_XAakD2Qt0krjnKY"
Message-Id: <200512030839.35344.sgrubb at redhat.com>
X-loop: linux-audit at redhat.com
Cc: lspp-list <redhat-lspp at redhat.com>
Subject: [PATCH] promiscuous mode
X-BeenThere: linux-audit at redhat.com
X-Mailman-Version: 2.1.5
Precedence: junk
List-Id: Linux Audit Discussion <linux-audit.redhat.com>
List-Unsubscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=unsubscribe>
List-Archive: <https://www.redhat.com/archives/linux-audit>
List-Post: <mailto:linux-audit at redhat.com>
List-Help: <mailto:linux-audit-request at redhat.com?subject=help>
List-Subscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=subscribe>
Sender: linux-audit-bounces at redhat.com
Errors-To: linux-audit-bounces at redhat.com
X-Spam-Score: 0.0 (/)
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/


--Boundary-00=_XAakD2Qt0krjnKY
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

Hi,

When a network interface goes into promiscuous mode, its an important security 
issue. The attached patch is intended to capture that action and send an 
event to the audit system.

The patch carves out a new block of numbers for kernel detected anomalies. 
These are events that may indicate suspicious activity. Other examples of 
potential kernel anomalies would be: exceeding disk quota, rlimit violations, 
changes to syscall entry table.

Signed-off-by: Steve Grubb <sgrubb at redhat.com>


--Boundary-00=_XAakD2Qt0krjnKY
Content-Type: text/x-diff; charset="us-ascii"; name="linux-2.6.14-audit-promiscuous.patch"
Content-Disposition: attachment; filename="linux-2.6.14-audit-promiscuous.patch"
Content-Transfer-Encoding: 8bit

diff -urp linux-2.6.14.orig/include/linux/audit.h linux-2.6.14/include/linux/audit.h
--- linux-2.6.14.orig/include/linux/audit.h	2005-12-02 15:28:34.000000000 -0500
+++ linux-2.6.14/include/linux/audit.h	2005-12-02 15:28:22.000000000 -0500
@@ -35,7 +35,8 @@
  * 1400 - 1499 SE Linux use
  * 1500 - 1599 kernel LSPP events
  * 1600 - 1699 kernel crypto events
- * 1700 - 1999 future kernel use (maybe integrity labels and related events)
+ * 1700 - 1799 kernel anomaly records
+ * 1800 - 1999 future kernel use (maybe integrity labels and related events)
  * 2000 is for otherwise unclassified kernel audit messages (legacy)
  * 2001 - 2099 unused (kernel)
  * 2100 - 2199 user space anomaly records
@@ -87,6 +88,10 @@
 #define AUDIT_MAC_STATUS	1404	/* Changed enforcing,permissive,off */
 #define AUDIT_MAC_CONFIG_CHANGE	1405	/* Changes to booleans */
 
+#define AUDIT_FIRST_KERN_ANOM_MSG   1700
+#define AUDIT_LAST_KERN_ANOM_MSG    1799
+#define AUDIT_ANOM_PROMISCUOUS      1700 /* Device changed promiscuous mode */
+
 #define AUDIT_KERNEL		2000	/* Asynchronous audit record. NOT A REQUEST. */
 
 /* Rule flags */
diff -urp linux-2.6.14.orig/net/core/dev.c linux-2.6.14/net/core/dev.c
--- linux-2.6.14.orig/net/core/dev.c	2005-12-02 14:22:10.000000000 -0500
+++ linux-2.6.14/net/core/dev.c	2005-12-02 15:23:27.000000000 -0500
@@ -114,6 +114,7 @@
 #include <net/iw_handler.h>
 #endif	/* CONFIG_NET_RADIO */
 #include <asm/current.h>
+#include <linux/audit.h>
 
 /*
  *	The list of packet types we will receive (as opposed to discard)
@@ -2121,6 +2122,12 @@ void dev_set_promiscuity(struct net_devi
 		printk(KERN_INFO "device %s %s promiscuous mode\n",
 		       dev->name, (dev->flags & IFF_PROMISC) ? "entered" :
 		       					       "left");
+		audit_log(current->audit_context, GFP_KERNEL,
+			AUDIT_ANOM_PROMISCUOUS,
+			"dev=%s prom=%d old_prom=%d auid=%u",
+			dev->name, (dev->flags & IFF_PROMISC),
+			(old_flags & IFF_PROMISC),
+			audit_get_loginuid(current->audit_context)); 
 	}
 }
 

--Boundary-00=_XAakD2Qt0krjnKY
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

--
Linux-audit mailing list
Linux-audit at redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit
--Boundary-00=_XAakD2Qt0krjnKY--

linux-2.6-audit-rule-log.patch:
 include/linux/audit.h |    2 +-
 kernel/auditfilter.c  |   14 +++++++-------
 2 files changed, 8 insertions(+), 8 deletions(-)

--- NEW FILE linux-2.6-audit-rule-log.patch ---
>From linux-audit-bounces at redhat.com Mon Jan  9 14:48:00 2006
Return-path: <linux-audit-bounces at redhat.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Mon, 09 Jan 2006 14:48:00 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EvyJU-0008Ah-Ie for dwmw2 at baythorne.infradead.org; Mon, 09 Jan 2006
	14:48:00 +0000
Received: from hormel.redhat.com ([209.132.177.30]) by
	pentafluge.infradead.org with esmtp (Exim 4.54 #1 (Red Hat Linux)) id
	1EvyJS-00083r-Ac for dwmw2 at infradead.org; Mon, 09 Jan 2006 14:47:59 +0000
Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com
	[10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 0081172F6B; Mon,
	 9 Jan 2006 09:47:57 -0500 (EST)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com
	[172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP
	id k09Els3H012878 for <linux-audit at listman.util.phx.redhat.com>; Mon, 9 Jan
	2006 09:47:55 -0500
Received: from mail.boston.redhat.com (mail.boston.redhat.com
	[172.16.76.12]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id
	k09Els116875 for <linux-audit at int-mx1.corp.redhat.com>; Mon, 9 Jan 2006
	09:47:54 -0500
Received: from discovery.boston.redhat.com (discovery.boston.redhat.com
	[172.16.80.171]) by mail.boston.redhat.com (8.12.8/8.12.8) with ESMTP id
	k09ElsEg002852 for <linux-audit at redhat.com>; Mon, 9 Jan 2006 09:47:54 -0500
From: Steve Grubb <sgrubb at redhat.com>
Organization: Red Hat
To: Linux Audit Discussion <linux-audit at redhat.com>
Date: Mon, 9 Jan 2006 09:48:17 -0500
User-Agent: KMail/1.9.1
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
Message-Id: <200601090948.17487.sgrubb at redhat.com>
X-loop: linux-audit at redhat.com
Subject: [PATCH] add/remove rule update
X-BeenThere: linux-audit at redhat.com
X-Mailman-Version: 2.1.5
Precedence: junk
List-Id: Linux Audit Discussion <linux-audit.redhat.com>
List-Unsubscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=unsubscribe>
List-Archive: <https://www.redhat.com/archives/linux-audit>
List-Post: <mailto:linux-audit at redhat.com>
List-Help: <mailto:linux-audit-request at redhat.com?subject=help>
List-Subscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=subscribe>
Sender: linux-audit-bounces at redhat.com
Errors-To: linux-audit-bounces at redhat.com
X-Spam-Score: 0.0 (/)
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

Hi,

The following patch adds a little more information to the add/remove rule message emitted 
by the kernel.

Signed-off-by: Steve Grubb <sgrubb at redhat.com>



diff -urp linux-2.6.14.orig/include/linux/audit.h linux-2.6.14/include/linux/audit.h
--- linux-2.6.14.orig/include/linux/audit.h	2006-01-05 10:13:30.000000000 -0500
+++ linux-2.6.14/include/linux/audit.h	2006-01-05 10:12:09.000000000 -0500
@@ -238,7 +238,7 @@ struct audit_rule {		/* for AUDIT_LIST, 
 	__u32		flags;	/* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
 	__u32		action;	/* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
 	__u32		field_count;
-	__u32		mask[AUDIT_BITMASK_SIZE];
+	__u32		mask[AUDIT_BITMASK_SIZE]; /* syscall(s) affected */
 	__u32		fields[AUDIT_MAX_FIELDS];
 	__u32		values[AUDIT_MAX_FIELDS];
 };
diff -urp linux-2.6.14.orig/kernel/auditfilter.c linux-2.6.14/kernel/auditfilter.c
--- linux-2.6.14.orig/kernel/auditfilter.c	2006-01-05 10:13:40.000000000 -0500
+++ linux-2.6.14/kernel/auditfilter.c	2006-01-05 10:11:29.000000000 -0500
@@ -571,10 +571,10 @@ int audit_receive_filter(int type, int p
 
 		err = audit_add_rule(entry,
 				     &audit_filter_list[entry->rule.listnr]);
-		if (!err)
-			audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
-				  "auid=%u added an audit rule\n", loginuid);
-		else {
+		audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
+			  "auid=%u added rule to list=%d res=%d\n",
+			  loginuid, entry->rule.listnr, !err);
+		if (err) {
 			audit_free_watch(entry->rule.watch);
 			kfree(entry);
 		}
@@ -590,9 +590,9 @@ int audit_receive_filter(int type, int p
 
 		err = audit_del_rule(entry,
 				     &audit_filter_list[entry->rule.listnr]);
-		if (!err)
-			audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
-				  "auid=%u removed an audit rule\n", loginuid);
+		audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
+			  "auid=%u removed rule from list=%d res=%d\n",
+			  loginuid, entry->rule.listnr, !err);
 		audit_free_watch(entry->rule.watch);
 		kfree(entry);
 		break;

--
Linux-audit mailing list
Linux-audit at redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit

linux-2.6-audit-string-1.patch:
 include/linux/audit.h       |   31 ++-
 kernel/audit.c              |   19 +
 kernel/audit.h              |   23 ++
 kernel/auditfilter.c        |  434 +++++++++++++++++++++++++++++++++-----------
 kernel/auditsc.c            |   50 ++---
 security/selinux/nlmsgtab.c |    3 
 6 files changed, 424 insertions(+), 136 deletions(-)

--- NEW FILE linux-2.6-audit-string-1.patch ---
>From linux-audit-bounces at redhat.com Wed Jan 11 19:03:09 2006
Return-path: <linux-audit-bounces at redhat.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Wed, 11 Jan 2006 19:03:09 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwlFV-00027M-Bu for dwmw2 at baythorne.infradead.org; Wed, 11 Jan 2006
	19:03:09 +0000
Received: from hormel.redhat.com ([209.132.177.30]) by
	pentafluge.infradead.org with esmtp (Exim 4.54 #1 (Red Hat Linux)) id
	1EwlFP-0002O8-AR for dwmw2 at infradead.org; Wed, 11 Jan 2006 19:03:08 +0000
Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com
	[10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 4BE3F72F9A; Wed,
	11 Jan 2006 14:03:02 -0500 (EST)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com
	[172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP
	id k0BJ2xCK027396 for <linux-audit at listman.util.phx.redhat.com>; Wed, 11
	Jan 2006 14:03:00 -0500
Received: from mx3.redhat.com (mx3.redhat.com [172.16.48.32]) by
	int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id k0BJ2x104580 for
	<linux-audit at redhat.com>; Wed, 11 Jan 2006 14:02:59 -0500
Received: from ccerelbas03.cce.hp.com (ccerelbas03.cce.hp.com
	[161.114.21.106]) by mx3.redhat.com (8.13.1/8.13.1) with ESMTP id
	k0BJ2jBE023986 for <linux-audit at redhat.com>; Wed, 11 Jan 2006 14:02:51 -0500
Received: from ccerelint01.cce.cpqcorp.net (ccerelint01.cce.cpqcorp.net
	[16.110.74.103]) by ccerelbas03.cce.hp.com (Postfix) with ESMTP id
	8ADFA346F4; Wed, 11 Jan 2006 13:02:32 -0600 (CST)
Received: from dill.zko.hp.com (dill.zko.hp.com [16.116.104.162]) by
	ccerelint01.cce.cpqcorp.net (Postfix) with ESMTP id 40E2334005; Wed, 11 Jan
	2006 13:02:32 -0600 (CST)
Received: by dill.zko.hp.com (Postfix, from userid 10412) id 0352E30BA1DD;
	Wed, 11 Jan 2006 14:02:31 -0500 (EST)
Date: Wed, 11 Jan 2006 14:02:31 -0500
From: Amy Griffis <amy.griffis at hp.com>
To: linux-audit at redhat.com
Message-ID: <20060111190231.GB24489 at zk3.dec.com>
Mail-Followup-To: linux-audit at redhat.com, Stephen Smalley
	<sds at tycho.nsa.gov>
References: <20060111185921.GA24489 at zk3.dec.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20060111185921.GA24489 at zk3.dec.com>
X-Mailer: Mutt http://www.mutt.org/
X-Editor: Vim http://www.vim.org/
User-Agent: Mutt/1.5.10i
X-RedHat-Spam-Score: -100 
X-loop: linux-audit at redhat.com
Cc: 
Subject: Re: [PATCH 1/2] audit string fields interface + consumer
X-BeenThere: linux-audit at redhat.com
X-Mailman-Version: 2.1.5
Precedence: junk
List-Id: Linux Audit Discussion <linux-audit.redhat.com>
List-Unsubscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=unsubscribe>
List-Archive: <https://www.redhat.com/archives/linux-audit>
List-Post: <mailto:linux-audit at redhat.com>
List-Help: <mailto:linux-audit-request at redhat.com?subject=help>
List-Subscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=subscribe>
Sender: linux-audit-bounces at redhat.com
Errors-To: linux-audit-bounces at redhat.com
X-Spam-Score: 0.0 (/)
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

Modify audit's kernel-userspace interface to allow the specification
of string fields in audit rules.

Signed-off-by: Amy Griffis <amy.griffis at hp.com>

---

 include/linux/audit.h       |   31 +++
 kernel/audit.c              |   19 ++
 kernel/audit.h              |   23 ++
 kernel/auditfilter.c        |  434 +++++++++++++++++++++++++++++++++----------
 kernel/auditsc.c            |   50 ++---
 security/selinux/nlmsgtab.c |    3 
 6 files changed, 424 insertions(+), 136 deletions(-)

e637a0b9ed7b52263d9a687bbff0c45ae281e2d4
diff --git a/include/linux/audit.h b/include/linux/audit.h
index a485639..c208554 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -50,15 +50,18 @@
  */
 #define AUDIT_GET		1000	/* Get status */
 #define AUDIT_SET		1001	/* Set status (enable/disable/auditd) */
-#define AUDIT_LIST		1002	/* List syscall filtering rules */
-#define AUDIT_ADD		1003	/* Add syscall filtering rule */
-#define AUDIT_DEL		1004	/* Delete syscall filtering rule */
+#define AUDIT_LIST		1002	/* List syscall rules -- deprecated */
+#define AUDIT_ADD		1003	/* Add syscall rule -- deprecated */
+#define AUDIT_DEL		1004	/* Delete syscall rule -- deprecated */
 #define AUDIT_USER		1005	/* Message from userspace -- deprecated */
 #define AUDIT_LOGIN		1006	/* Define the login id and information */
 #define AUDIT_WATCH_INS		1007	/* Insert file/dir watch entry */
 #define AUDIT_WATCH_REM		1008	/* Remove file/dir watch entry */
 #define AUDIT_WATCH_LIST	1009	/* List all file/dir watches */
 #define AUDIT_SIGNAL_INFO	1010	/* Get info about sender of signal to auditd */
+#define AUDIT_ADD_RULE		1011	/* Add syscall filtering rule */
+#define AUDIT_DEL_RULE		1012	/* Delete syscall filtering rule */
+#define AUDIT_LIST_RULES	1013	/* List syscall filtering rules */
 
 #define AUDIT_FIRST_USER_MSG	1100	/* Userspace messages mostly uninteresting to kernel */
 #define AUDIT_USER_AVC		1107	/* We filter this differently */
@@ -229,6 +232,26 @@ struct audit_status {
 	__u32		backlog;	/* messages waiting in queue */
 };
 
+/* audit_rule_data supports filter rules with both integer and string
+ * fields.  It corresponds with AUDIT_ADD_RULE, AUDIT_DEL_RULE and
+ * AUDIT_LIST_RULES requests.
+ */
+struct audit_rule_data {
+	__u32		flags;	/* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
+	__u32		action;	/* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
+	__u32		field_count;
+	__u32		mask[AUDIT_BITMASK_SIZE];
+	__u32		fields[AUDIT_MAX_FIELDS];
+	__u32		values[AUDIT_MAX_FIELDS];
+	__u32		fieldflags[AUDIT_MAX_FIELDS];
+	__u32		buflen;	/* total length of string fields */
+	char		buf[0];	/* string fields buffer */
+};
+
+/* audit_rule is supported to maintain backward compatibility with
+ * userspace.  It supports integer fields only and corresponds to
+ * AUDIT_ADD, AUDIT_DEL and AUDIT_LIST requests.
+ */
 struct audit_rule {		/* for AUDIT_LIST, AUDIT_ADD, and AUDIT_DEL */
 	__u32		flags;	/* AUDIT_PER_{TASK,CALL}, AUDIT_PREPEND */
 	__u32		action;	/* AUDIT_NEVER, AUDIT_POSSIBLE, AUDIT_ALWAYS */
@@ -340,7 +363,7 @@ extern void		    audit_log_d_path(struct
 extern int audit_filter_user(struct netlink_skb_parms *cb, int type);
 extern int audit_filter_type(int type);
 extern int  audit_receive_filter(int type, int pid, int uid, int seq,
-				 void *data, uid_t loginuid);
+				 void *data, size_t datasz, uid_t loginuid);
 #else
 #define audit_log(c,g,t,f,...) do { ; } while (0)
 #define audit_log_start(c,g,t) ({ NULL; })
diff --git a/kernel/audit.c b/kernel/audit.c
index d95efd6..bdda766 100644
--- a/kernel/audit.c
+++ b/kernel/audit.c
@@ -52,6 +52,7 @@
 #include <linux/audit.h>
 
 #include <net/sock.h>
+#include <net/netlink.h>
 #include <linux/skbuff.h>
 #include <linux/netlink.h>
 
@@ -361,9 +362,12 @@ static int audit_netlink_ok(kernel_cap_t
 	switch (msg_type) {
 	case AUDIT_GET:
 	case AUDIT_LIST:
+	case AUDIT_LIST_RULES:
 	case AUDIT_SET:
 	case AUDIT_ADD:
+	case AUDIT_ADD_RULE:
 	case AUDIT_DEL:
+	case AUDIT_DEL_RULE:
 	case AUDIT_SIGNAL_INFO:
 		if (!cap_raised(eff_cap, CAP_AUDIT_CONTROL))
 			err = -EPERM;
@@ -470,12 +474,23 @@ static int audit_receive_msg(struct sk_b
 		break;
 	case AUDIT_ADD:
 	case AUDIT_DEL:
-		if (nlh->nlmsg_len < sizeof(struct audit_rule))
+		if (nlmsg_len(nlh) < sizeof(struct audit_rule))
 			return -EINVAL;
 		/* fallthrough */
 	case AUDIT_LIST:
 		err = audit_receive_filter(nlh->nlmsg_type, NETLINK_CB(skb).pid,
-					   uid, seq, data, loginuid);
+					   uid, seq, data, nlmsg_len(nlh),
+					   loginuid);
+		break;
+	case AUDIT_ADD_RULE:
+	case AUDIT_DEL_RULE:
+		if (nlmsg_len(nlh) < sizeof(struct audit_rule_data))
+			return -EINVAL;
+		/* fallthrough */
+	case AUDIT_LIST_RULES:
+		err = audit_receive_filter(nlh->nlmsg_type, NETLINK_CB(skb).pid,
+					   uid, seq, data, nlmsg_len(nlh),
+					   loginuid);
 		break;
 	case AUDIT_SIGNAL_INFO:
 		sig_data.uid = audit_sig_uid;
diff --git a/kernel/audit.h b/kernel/audit.h
index 7643e46..f3b2a00 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -52,10 +52,27 @@ enum audit_state {
 };
 
 /* Rule lists */
+struct audit_field {
+	u32			type;
+	u32			val;
+	u32			op;
+};
+
+struct audit_krule {
+	int			vers_ops;
+	u32			flags;
+	u32			listnr;
+	u32			action;
+	u32			mask[AUDIT_BITMASK_SIZE];
+	u32			buflen; /* for data alloc on list rules */
+	u32			field_count;
+	struct audit_field	fields[AUDIT_MAX_FIELDS];
+};
+
 struct audit_entry {
-	struct list_head  list;
-	struct rcu_head   rcu;
-	struct audit_rule rule;
+	struct list_head	list;
+	struct rcu_head		rcu;
+	struct audit_krule	rule;
 };
 
 
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index a3a3275..9c8865e 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -40,52 +40,258 @@ struct list_head audit_filter_list[AUDIT
 #endif
 };
 
-/* Copy rule from user-space to kernel-space.  Called from 
- * audit_add_rule during AUDIT_ADD. */
-static inline int audit_copy_rule(struct audit_rule *d, struct audit_rule *s)
+/* Unpack a filter field's string representation from user-space
+ * buffer. */
+static char *audit_unpack_string(void **bufp, size_t *remain, size_t len)
 {
+	char *str;
+
+	if (!*bufp || (len == 0) || (len > *remain))
+		return ERR_PTR(-EINVAL);
+
+	/* Of the currently implemented string fields, PATH_MAX
+	 * defines the longest valid length.
+	 */
+	if (len > PATH_MAX)
+		return ERR_PTR(-ENAMETOOLONG);
+
+	str = kmalloc(len + 1, GFP_KERNEL);
+	if (!str)
+		return ERR_PTR(-ENOMEM);
+
+	memcpy(str, *bufp, len);
+	str[len] = 0;
+	*bufp += len;
+	*remain -= len;
+
+	return str;
+}
+
+/* Common user-space to kernel rule translation. */
+static inline struct audit_entry *audit_to_entry_common(struct audit_rule *rule)
+{
+	unsigned listnr;
+	struct audit_entry *entry;
+	int i, err;
+
+	err = -EINVAL;
+	listnr = rule->flags & ~AUDIT_FILTER_PREPEND;
+	switch(listnr) {
+	default:
+		goto exit_err;
+	case AUDIT_FILTER_USER:
+	case AUDIT_FILTER_TYPE:
+#ifdef CONFIG_AUDITSYSCALL
+	case AUDIT_FILTER_ENTRY:
+	case AUDIT_FILTER_EXIT:
+	case AUDIT_FILTER_TASK:
+#endif
+		;
+	}
+	if (rule->action != AUDIT_NEVER && rule->action != AUDIT_POSSIBLE &&
+	    rule->action != AUDIT_ALWAYS)
+		goto exit_err;
+	if (rule->field_count > AUDIT_MAX_FIELDS)
+		goto exit_err;
+
+	err = -ENOMEM;
+	entry = kmalloc(sizeof(*entry), GFP_KERNEL);
+	if (!entry)
+		goto exit_err;
+	memset(&entry->rule, 0, sizeof(struct audit_krule));
+
+	entry->rule.flags = rule->flags & AUDIT_FILTER_PREPEND;
+	entry->rule.listnr = listnr;
+	entry->rule.action = rule->action;
+	entry->rule.field_count = rule->field_count;
+
+	for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
+		entry->rule.mask[i] = rule->mask[i];
+
+	return entry;
+
+exit_err:
+	return ERR_PTR(err);
+}
+
+/* Translate struct audit_rule to kernel's rule respresentation.
+ * Exists for backward compatibility with userspace. */
+static struct audit_entry *audit_rule_to_entry(struct audit_rule *rule)
+{
+	struct audit_entry *entry;
+	int err = 0;
 	int i;
 
-	if (s->action != AUDIT_NEVER
-	    && s->action != AUDIT_POSSIBLE
-	    && s->action != AUDIT_ALWAYS)
-		return -1;
-	if (s->field_count < 0 || s->field_count > AUDIT_MAX_FIELDS)
-		return -1;
-	if ((s->flags & ~AUDIT_FILTER_PREPEND) >= AUDIT_NR_FILTERS)
-		return -1;
-
-	d->flags	= s->flags;
-	d->action	= s->action;
-	d->field_count	= s->field_count;
-	for (i = 0; i < d->field_count; i++) {
-		d->fields[i] = s->fields[i];
-		d->values[i] = s->values[i];
+	entry = audit_to_entry_common(rule);
+	if (IS_ERR(entry))
+		goto exit_nofree;
+
+	for (i = 0; i < rule->field_count; i++) {
+		struct audit_field *f = &entry->rule.fields[i];
+
+		if (rule->fields[i] & AUDIT_UNUSED_BITS) {
+			err = -EINVAL;
+			goto exit_free;
+		}
+
+		f->op = rule->fields[i] & (AUDIT_NEGATE|AUDIT_OPERATORS);
+		f->type = rule->fields[i] & (~AUDIT_NEGATE|AUDIT_OPERATORS);
+		f->val = rule->values[i];
+
+		entry->rule.vers_ops = (f->op & AUDIT_OPERATORS) ? 2 : 1;
+		if (f->op & AUDIT_NEGATE)
+			f->op |= AUDIT_NOT_EQUAL;
+		else if (!(f->op & AUDIT_OPERATORS))
+			f->op |= AUDIT_EQUAL;
+		f->op &= ~AUDIT_NEGATE;
 	}
-	for (i = 0; i < AUDIT_BITMASK_SIZE; i++) d->mask[i] = s->mask[i];
-	return 0;
+
+exit_nofree:
+	return entry;
+
+exit_free:
+	kfree(entry);
+	return ERR_PTR(err);
 }
 
-/* Check to see if two rules are identical.  It is called from
- * audit_add_rule during AUDIT_ADD and 
- * audit_del_rule during AUDIT_DEL. */
-static int audit_compare_rule(struct audit_rule *a, struct audit_rule *b)
+/* Translate struct audit_rule_data to kernel's rule respresentation. */
+static struct audit_entry *audit_data_to_entry(struct audit_rule_data *data,
+					       size_t datasz)
 {
+	int err = 0;
+	struct audit_entry *entry;
+	void *bufp;
+	/* size_t remain = datasz - sizeof(struct audit_rule_data); */
 	int i;
 
-	if (a->flags != b->flags)
-		return 1;
+	entry = audit_to_entry_common((struct audit_rule *)data);
+	if (IS_ERR(entry))
+		goto exit_nofree;
+
+	bufp = data->buf;
+	entry->rule.vers_ops = 2;
+	for (i = 0; i < data->field_count; i++) {
+		struct audit_field *f = &entry->rule.fields[i];
+
+		err = -EINVAL;
+		if (!(data->fieldflags[i] & AUDIT_OPERATORS) ||
+		    data->fieldflags[i] & ~AUDIT_OPERATORS)
+			goto exit_free;
+
+		f->op = data->fieldflags[i] & AUDIT_OPERATORS;
+		f->type = data->fields[i];
+		switch(f->type) {
+		/* call type-specific conversion routines here */
+		default:
+			f->val = data->values[i];
+		}
+	}
 
-	if (a->action != b->action)
-		return 1;
+exit_nofree:
+	return entry;
+
+exit_free:
+	kfree(entry);
+	return ERR_PTR(err);
+}
+
+/* Pack a filter field's string representation into data block. */
+static inline size_t audit_pack_string(void **bufp, char *str)
+{
+	size_t len = strlen(str);
+
+	memcpy(*bufp, str, len);
+	*bufp += len;
+
+	return len;
+}
+
+/* Translate kernel rule respresentation to struct audit_rule.
+ * Exists for backward compatibility with userspace. */
+static struct audit_rule *audit_krule_to_rule(struct audit_krule *krule)
+{
+	struct audit_rule *rule;
+	int i;
+
+	rule = kmalloc(sizeof(*rule), GFP_KERNEL);
+	if (!rule)
+		return ERR_PTR(-ENOMEM);
+	memset(rule, 0, sizeof(*rule));
+
+	rule->flags = krule->flags | krule->listnr;
+	rule->action = krule->action;
+	rule->field_count = krule->field_count;
+	for (i = 0; i < rule->field_count; i++) {
+		rule->values[i] = krule->fields[i].val;
+		rule->fields[i] = krule->fields[i].type;
+
+		if (krule->vers_ops == 1) {
+			if (krule->fields[i].op & AUDIT_NOT_EQUAL)
+				rule->fields[i] |= AUDIT_NEGATE;
+		} else {
+			rule->fields[i] |= krule->fields[i].op;
+		}
+	}
+	for (i = 0; i < AUDIT_BITMASK_SIZE; i++) rule->mask[i] = krule->mask[i];
+
+	return rule;
+}
+
+/* Translate kernel rule respresentation to struct audit_rule_data. */
+static struct audit_rule_data *audit_krule_to_data(struct audit_krule *krule)
+{
+	struct audit_rule_data *data;
+	void *bufp;
+	int i;
+
+	data = kmalloc(sizeof(*data) + krule->buflen, GFP_KERNEL);
+	if (!data)
+		return ERR_PTR(-ENOMEM);
+	memset(data, 0, sizeof(*data));
+
+	data->flags = krule->flags | krule->listnr;
+	data->action = krule->action;
+	data->field_count = krule->field_count;
+	bufp = data->buf;
+	for (i = 0; i < data->field_count; i++) {
+		struct audit_field *f = &krule->fields[i];
+
+		data->fields[i] = f->type;
+		data->fieldflags[i] = f->op;
+		switch(f->type) {
+		/* call type-specific conversion routines here */
+		default:
+			data->values[i] = f->val;
+		}
+	}
+	for (i = 0; i < AUDIT_BITMASK_SIZE; i++) data->mask[i] = krule->mask[i];
+
+	return data;
+}
 
-	if (a->field_count != b->field_count)
+/* Compare two rules in kernel format.  Considered success if rules
+ * don't match. */
+static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
+{
+	int i;
+
+	if (a->flags != b->flags ||
+	    a->listnr != b->listnr ||
+	    a->action != b->action ||
+	    a->field_count != b->field_count)
 		return 1;
 
 	for (i = 0; i < a->field_count; i++) {
-		if (a->fields[i] != b->fields[i]
-		    || a->values[i] != b->values[i])
+		if (a->fields[i].type != b->fields[i].type ||
+		    a->fields[i].op != b->fields[i].op)
 			return 1;
+
+		switch(a->fields[i].type) {
+		/* call type-specific comparison routines here */
+		default:
+			if (a->fields[i].val != b->fields[i].val)
+				return 1;
+		}
 	}
 
 	for (i = 0; i < AUDIT_BITMASK_SIZE; i++)
@@ -95,41 +301,21 @@ static int audit_compare_rule(struct aud
 	return 0;
 }
 
-/* Note that audit_add_rule and audit_del_rule are called via
- * audit_receive() in audit.c, and are protected by
+/* Add rule to given filterlist if not a duplicate.  Protected by
  * audit_netlink_sem. */
-static inline int audit_add_rule(struct audit_rule *rule,
+static inline int audit_add_rule(struct audit_entry *entry,
 				  struct list_head *list)
 {
-	struct audit_entry  *entry;
-	int i;
+	struct audit_entry *e;
 
 	/* Do not use the _rcu iterator here, since this is the only
 	 * addition routine. */
-	list_for_each_entry(entry, list, list) {
-		if (!audit_compare_rule(rule, &entry->rule))
+	list_for_each_entry(e, list, list) {
+		if (!audit_compare_rule(&entry->rule, &e->rule))
 			return -EEXIST;
 	}
 
-	for (i = 0; i < rule->field_count; i++) {
-		if (rule->fields[i] & AUDIT_UNUSED_BITS)
-			return -EINVAL;
-		if ( rule->fields[i] & AUDIT_NEGATE)
-			rule->fields[i] |= AUDIT_NOT_EQUAL;
-		else if ( (rule->fields[i] & AUDIT_OPERATORS) == 0 )
-			rule->fields[i] |= AUDIT_EQUAL;
-		rule->fields[i] &= ~AUDIT_NEGATE;
-	}
-
-	if (!(entry = kmalloc(sizeof(*entry), GFP_KERNEL)))
-		return -ENOMEM;
-	if (audit_copy_rule(&entry->rule, rule)) {
-		kfree(entry);
-		return -EINVAL;
-	}
-
 	if (entry->rule.flags & AUDIT_FILTER_PREPEND) {
-		entry->rule.flags &= ~AUDIT_FILTER_PREPEND;
 		list_add_rcu(&entry->list, list);
 	} else {
 		list_add_tail_rcu(&entry->list, list);
@@ -144,10 +330,9 @@ static inline void audit_free_rule(struc
 	kfree(e);
 }
 
-/* Note that audit_add_rule and audit_del_rule are called via
- * audit_receive() in audit.c, and are protected by
+/* Remove an existing rule from filterlist.  Protected by
  * audit_netlink_sem. */
-static inline int audit_del_rule(struct audit_rule *rule,
+static inline int audit_del_rule(struct audit_entry *entry,
 				 struct list_head *list)
 {
 	struct audit_entry  *e;
@@ -155,7 +340,7 @@ static inline int audit_del_rule(struct 
 	/* Do not use the _rcu iterator here, since this is the only
 	 * deletion routine. */
 	list_for_each_entry(e, list, list) {
-		if (!audit_compare_rule(rule, &e->rule)) {
+		if (!audit_compare_rule(&entry->rule, &e->rule)) {
 			list_del_rcu(&e->list);
 			call_rcu(&e->rcu, audit_free_rule);
 			return 0;
@@ -164,7 +349,9 @@ static inline int audit_del_rule(struct 
 	return -ENOENT;		/* No matching rule */
 }
 
-static int audit_list_rules(void *_dest)
+/* List rules using struct audit_rule.  Exists for backward
+ * compatibility with userspace. */
+static int audit_list(void *_dest)
 {
 	int pid, seq;
 	int *dest = _dest;
@@ -180,9 +367,16 @@ static int audit_list_rules(void *_dest)
 	/* The *_rcu iterators not needed here because we are
 	   always called with audit_netlink_sem held. */
 	for (i=0; i<AUDIT_NR_FILTERS; i++) {
-		list_for_each_entry(entry, &audit_filter_list[i], list)
+		list_for_each_entry(entry, &audit_filter_list[i], list) {
+			struct audit_rule *rule;
+
+			rule = audit_krule_to_rule(&entry->rule);
+			if (!rule)
+				break;
 			audit_send_reply(pid, seq, AUDIT_LIST, 0, 1,
-					 &entry->rule, sizeof(entry->rule));
+					 rule, sizeof(*rule));
+			kfree(rule);
+		}
 	}
 	audit_send_reply(pid, seq, AUDIT_LIST, 1, 1, NULL, 0);
 	
@@ -190,6 +384,40 @@ static int audit_list_rules(void *_dest)
 	return 0;
 }
 
+/* List rules using struct audit_rule_data. */
+static int audit_list_rules(void *_dest)
+{
+	int pid, seq;
+	int *dest = _dest;
+	struct audit_entry *e;
+	int i;
+
+	pid = dest[0];
+	seq = dest[1];
+	kfree(dest);
+
+	down(&audit_netlink_sem);
+
+	/* The *_rcu iterators not needed here because we are
+	   always called with audit_netlink_sem held. */
+	for (i=0; i<AUDIT_NR_FILTERS; i++) {
+		list_for_each_entry(e, &audit_filter_list[i], list) {
+			struct audit_rule_data *data;
+
+			data = audit_krule_to_data(&e->rule);
+			if (!data)
+				break;
+			audit_send_reply(pid, seq, AUDIT_LIST_RULES, 0, 1,
+					 data, sizeof(*data));
+			kfree(data);
+		}
+	}
+	audit_send_reply(pid, seq, AUDIT_LIST_RULES, 1, 1, NULL, 0);
+
+	up(&audit_netlink_sem);
+	return 0;
+}
+
 /**
  * audit_receive_filter - apply all rules to the specified message type
  * @type: audit message type
@@ -197,18 +425,20 @@ static int audit_list_rules(void *_dest)
  * @uid: target uid for netlink audit messages
  * @seq: netlink audit message sequence (serial) number
  * @data: payload data
+ * @datasz: size of payload data
  * @loginuid: loginuid of sender
  */
 int audit_receive_filter(int type, int pid, int uid, int seq, void *data,
-							uid_t loginuid)
+			 size_t datasz, uid_t loginuid)
 {
 	struct task_struct *tsk;
 	int *dest;
-	int		   err = 0;
-	unsigned listnr;
+	int err = 0;
+	struct audit_entry *entry;
 
 	switch (type) {
 	case AUDIT_LIST:
+	case AUDIT_LIST_RULES:
 		/* We can't just spew out the rules here because we might fill
 		 * the available socket buffer space and deadlock waiting for
 		 * auditctl to read from it... which isn't ever going to
@@ -221,41 +451,48 @@ int audit_receive_filter(int type, int p
 		dest[0] = pid;
 		dest[1] = seq;
 
-		tsk = kthread_run(audit_list_rules, dest, "audit_list_rules");
+		if (type == AUDIT_LIST)
+			tsk = kthread_run(audit_list, dest, "audit_list");
+		else
+			tsk = kthread_run(audit_list_rules, dest,
+					  "audit_list_rules");
 		if (IS_ERR(tsk)) {
 			kfree(dest);
 			err = PTR_ERR(tsk);
 		}
 		break;
 	case AUDIT_ADD:
-		listnr = ((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND;
-		switch(listnr) {
-		default:
-			return -EINVAL;
+	case AUDIT_ADD_RULE:
+		if (type == AUDIT_ADD)
+			entry = audit_rule_to_entry(data);
+		else
+			entry = audit_data_to_entry(data, datasz);
+		if (IS_ERR(entry))
+			return PTR_ERR(entry);
 
-		case AUDIT_FILTER_USER:
-		case AUDIT_FILTER_TYPE:
-#ifdef CONFIG_AUDITSYSCALL
-		case AUDIT_FILTER_ENTRY:
-		case AUDIT_FILTER_EXIT:
-		case AUDIT_FILTER_TASK:
-#endif
-			;
-		}
-		err = audit_add_rule(data, &audit_filter_list[listnr]);
+		err = audit_add_rule(entry,
+				     &audit_filter_list[entry->rule.listnr]);
 		if (!err)
 			audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
 				  "auid=%u added an audit rule\n", loginuid);
+		else
+			kfree(entry);
 		break;
 	case AUDIT_DEL:
-		listnr =((struct audit_rule *)data)->flags & ~AUDIT_FILTER_PREPEND;
-		if (listnr >= AUDIT_NR_FILTERS)
-			return -EINVAL;
+	case AUDIT_DEL_RULE:
+		if (type == AUDIT_DEL)
+			entry = audit_rule_to_entry(data);
+		else
+			entry = audit_data_to_entry(data, datasz);
+		if (IS_ERR(entry))
+			return PTR_ERR(entry);
 
-		err = audit_del_rule(data, &audit_filter_list[listnr]);
+		err = audit_del_rule(entry,
+				     &audit_filter_list[entry->rule.listnr]);
 		if (!err)
 			audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
 				  "auid=%u removed an audit rule\n", loginuid);
+		kfree(entry);
 		break;
 	default:
 		return -EINVAL;
@@ -287,29 +524,27 @@ int audit_comparator(const u32 left, con
 
 
 static int audit_filter_user_rules(struct netlink_skb_parms *cb,
-				   struct audit_rule *rule,
+				   struct audit_krule *rule,
 				   enum audit_state *state)
 {
 	int i;
 
 	for (i = 0; i < rule->field_count; i++) {
-		u32 field  = rule->fields[i] & ~AUDIT_OPERATORS;
-		u32 op  = rule->fields[i] & AUDIT_OPERATORS;
-		u32 value  = rule->values[i];
+		struct audit_field *f = &rule->fields[i];
 		int result = 0;
 
-		switch (field) {
+		switch (f->type) {
 		case AUDIT_PID:
-			result = audit_comparator(cb->creds.pid, op, value);
+			result = audit_comparator(cb->creds.pid, f->op, f->val);
 			break;
 		case AUDIT_UID:
-			result = audit_comparator(cb->creds.uid, op, value);
+			result = audit_comparator(cb->creds.uid, f->op, f->val);
 			break;
 		case AUDIT_GID:
-			result = audit_comparator(cb->creds.gid, op, value);
+			result = audit_comparator(cb->creds.gid, f->op, f->val);
 			break;
 		case AUDIT_LOGINUID:
-			result = audit_comparator(cb->loginuid, op, value);
+			result = audit_comparator(cb->loginuid, f->op, f->val);
 			break;
 		}
 
@@ -354,14 +589,11 @@ int audit_filter_type(int type)
 
 	list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TYPE],
 				list) {
-		struct audit_rule *rule = &e->rule;
 		int i;
-		for (i = 0; i < rule->field_count; i++) {
-			u32 field  = rule->fields[i] & ~AUDIT_OPERATORS;
-			u32 op  = rule->fields[i] & AUDIT_OPERATORS;
-			u32 value  = rule->values[i];
-			if ( field == AUDIT_MSGTYPE ) {
-				result = audit_comparator(type, op, value); 
+		for (i = 0; i < e->rule.field_count; i++) {
+			struct audit_field *f = &e->rule.fields[i];
+			if (f->type == AUDIT_MSGTYPE) {
+				result = audit_comparator(type, f->op, f->val);
 				if (!result)
 					break;
 			}
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 8f0a61c..e4f7096 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -161,70 +161,68 @@ struct audit_context {
 /* Compare a task_struct with an audit_rule.  Return 1 on match, 0
  * otherwise. */
 static int audit_filter_rules(struct task_struct *tsk,
-			      struct audit_rule *rule,
+			      struct audit_krule *rule,
 			      struct audit_context *ctx,
 			      enum audit_state *state)
 {
 	int i, j;
 
 	for (i = 0; i < rule->field_count; i++) {
-		u32 field  = rule->fields[i] & ~AUDIT_OPERATORS;
-		u32 op  = rule->fields[i] & AUDIT_OPERATORS;
-		u32 value  = rule->values[i];
+		struct audit_field *f = &rule->fields[i];
 		int result = 0;
 
-		switch (field) {
+		switch (f->type) {
 		case AUDIT_PID:
-			result = audit_comparator(tsk->pid, op, value);
+			result = audit_comparator(tsk->pid, f->op, f->val);
 			break;
 		case AUDIT_UID:
-			result = audit_comparator(tsk->uid, op, value);
+			result = audit_comparator(tsk->uid, f->op, f->val);
 			break;
 		case AUDIT_EUID:
-			result = audit_comparator(tsk->euid, op, value);
+			result = audit_comparator(tsk->euid, f->op, f->val);
 			break;
 		case AUDIT_SUID:
-			result = audit_comparator(tsk->suid, op, value);
+			result = audit_comparator(tsk->suid, f->op, f->val);
 			break;
 		case AUDIT_FSUID:
-			result = audit_comparator(tsk->fsuid, op, value);
+			result = audit_comparator(tsk->fsuid, f->op, f->val);
 			break;
 		case AUDIT_GID:
-			result = audit_comparator(tsk->gid, op, value);
+			result = audit_comparator(tsk->gid, f->op, f->val);
 			break;
 		case AUDIT_EGID:
-			result = audit_comparator(tsk->egid, op, value);
+			result = audit_comparator(tsk->egid, f->op, f->val);
 			break;
 		case AUDIT_SGID:
-			result = audit_comparator(tsk->sgid, op, value);
+			result = audit_comparator(tsk->sgid, f->op, f->val);
 			break;
 		case AUDIT_FSGID:
-			result = audit_comparator(tsk->fsgid, op, value);
+			result = audit_comparator(tsk->fsgid, f->op, f->val);
 			break;
 		case AUDIT_PERS:
-			result = audit_comparator(tsk->personality, op, value);
+			result = audit_comparator(tsk->personality, f->op, f->val);
 			break;
 		case AUDIT_ARCH:
  			if (ctx)
-				result = audit_comparator(ctx->arch, op, value);
+				result = audit_comparator(ctx->arch, f->op, f->val);
 			break;
 
 		case AUDIT_EXIT:
 			if (ctx && ctx->return_valid)
-				result = audit_comparator(ctx->return_code, op, value);
+				result = audit_comparator(ctx->return_code, f->op, f->val);
 			break;
 		case AUDIT_SUCCESS:
 			if (ctx && ctx->return_valid) {
-				if (value)
-					result = audit_comparator(ctx->return_valid, op, AUDITSC_SUCCESS);
+				if (f->val)
+					result = audit_comparator(ctx->return_valid, f->op, AUDITSC_SUCCESS);
 				else
-					result = audit_comparator(ctx->return_valid, op, AUDITSC_FAILURE);
+					result = audit_comparator(ctx->return_valid, f->op, AUDITSC_FAILURE);
 			}
 			break;
 		case AUDIT_DEVMAJOR:
 			if (ctx) {
 				for (j = 0; j < ctx->name_count; j++) {
-					if (audit_comparator(MAJOR(ctx->names[j].dev),	op, value)) {
+					if (audit_comparator(MAJOR(ctx->names[j].dev),	f->op, f->val)) {
 						++result;
 						break;
 					}
@@ -234,7 +232,7 @@ static int audit_filter_rules(struct tas
 		case AUDIT_DEVMINOR:
 			if (ctx) {
 				for (j = 0; j < ctx->name_count; j++) {
-					if (audit_comparator(MINOR(ctx->names[j].dev), op, value)) {
+					if (audit_comparator(MINOR(ctx->names[j].dev), f->op, f->val)) {
 						++result;
 						break;
 					}
@@ -244,8 +242,8 @@ static int audit_filter_rules(struct tas
 		case AUDIT_INODE:
 			if (ctx) {
 				for (j = 0; j < ctx->name_count; j++) {
-					if (audit_comparator(ctx->names[j].ino, op, value) ||
-					    audit_comparator(ctx->names[j].pino, op, value)) {
+					if (audit_comparator(ctx->names[j].ino, f->op, f->val) ||
+					    audit_comparator(ctx->names[j].pino, f->op, f->val)) {
 						++result;
 						break;
 					}
@@ -255,14 +253,14 @@ static int audit_filter_rules(struct tas
 		case AUDIT_LOGINUID:
 			result = 0;
 			if (ctx)
-				result = audit_comparator(ctx->loginuid, op, value);
+				result = audit_comparator(ctx->loginuid, f->op, f->val);
 			break;
 		case AUDIT_ARG0:
 		case AUDIT_ARG1:
 		case AUDIT_ARG2:
 		case AUDIT_ARG3:
 			if (ctx)
-				result = audit_comparator(ctx->argv[field-AUDIT_ARG0], op, value);
+				result = audit_comparator(ctx->argv[f->type-AUDIT_ARG0], f->op, f->val);
 			break;
 		}
 
diff --git a/security/selinux/nlmsgtab.c b/security/selinux/nlmsgtab.c
index d7c0e91..7315824 100644
--- a/security/selinux/nlmsgtab.c
+++ b/security/selinux/nlmsgtab.c
@@ -99,6 +99,9 @@ static struct nlmsg_perm nlmsg_audit_per
 	{ AUDIT_LIST,		NETLINK_AUDIT_SOCKET__NLMSG_READPRIV },
 	{ AUDIT_ADD,		NETLINK_AUDIT_SOCKET__NLMSG_WRITE    },
 	{ AUDIT_DEL,		NETLINK_AUDIT_SOCKET__NLMSG_WRITE    },
+	{ AUDIT_LIST_RULES,	NETLINK_AUDIT_SOCKET__NLMSG_READPRIV },
+	{ AUDIT_ADD_RULE,	NETLINK_AUDIT_SOCKET__NLMSG_WRITE    },
+	{ AUDIT_DEL_RULE,	NETLINK_AUDIT_SOCKET__NLMSG_WRITE    },
 	{ AUDIT_USER,		NETLINK_AUDIT_SOCKET__NLMSG_RELAY    },
 	{ AUDIT_SIGNAL_INFO,	NETLINK_AUDIT_SOCKET__NLMSG_READ     },
 };
-- 
0.99.9n

--
Linux-audit mailing list
Linux-audit at redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit

linux-2.6-audit-string-2.patch:
 include/linux/audit.h |    1 
 kernel/audit.h        |    8 +++
 kernel/auditfilter.c  |  122 +++++++++++++++++++++++++++++++++++++++++++++-----
 kernel/auditsc.c      |    3 -
 4 files changed, 123 insertions(+), 11 deletions(-)

--- NEW FILE linux-2.6-audit-string-2.patch ---
>From linux-audit-bounces at redhat.com Wed Jan 11 19:05:06 2006
Return-path: <linux-audit-bounces at redhat.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Wed, 11 Jan 2006 19:05:06 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwlHN-000282-Px for dwmw2 at baythorne.infradead.org; Wed, 11 Jan 2006
	19:05:06 +0000
Received: from hormel.redhat.com ([209.132.177.30]) by
	pentafluge.infradead.org with esmtp (Exim 4.54 #1 (Red Hat Linux)) id
	1EwlHK-0002Oq-Vt for dwmw2 at infradead.org; Wed, 11 Jan 2006 19:05:05 +0000
Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com
	[10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 1BEB17346A; Wed,
	11 Jan 2006 14:05:02 -0500 (EST)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com
	[172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP
	id k0BJ50Zj027646 for <linux-audit at listman.util.phx.redhat.com>; Wed, 11
	Jan 2006 14:05:00 -0500
Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by
	int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id k0BJ50105987 for
	<linux-audit at redhat.com>; Wed, 11 Jan 2006 14:05:00 -0500
Received: from tayrelbas04.tay.hp.com (tayrelbas04.tay.hp.com
	[161.114.80.247]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id
	k0BJ4wwY013947 for <linux-audit at redhat.com>; Wed, 11 Jan 2006 14:04:58 -0500
Received: from tayrelint01.nz-tay.cpqcorp.net
	(tayrelint01.nz-tay.cpqcorp.net [16.47.5.6]) by tayrelbas04.tay.hp.com
	(Postfix) with ESMTP id B1B8434236; Wed, 11 Jan 2006 14:04:53 -0500 (EST)
Received: from dill.zko.hp.com (dill.zko.hp.com [16.116.104.162]) by
	tayrelint01.nz-tay.cpqcorp.net (Postfix) with ESMTP id 94A9E34004; Wed, 11
	Jan 2006 14:04:53 -0500 (EST)
Received: by dill.zko.hp.com (Postfix, from userid 10412) id 7910D30BA1DD;
	Wed, 11 Jan 2006 14:04:53 -0500 (EST)
Date: Wed, 11 Jan 2006 14:04:53 -0500
From: Amy Griffis <amy.griffis at hp.com>
To: linux-audit at redhat.com
Message-ID: <20060111190453.GC24489 at zk3.dec.com>
Mail-Followup-To: linux-audit at redhat.com, Stephen Smalley
	<sds at tycho.nsa.gov>
References: <20060111185921.GA24489 at zk3.dec.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <20060111185921.GA24489 at zk3.dec.com>
X-Mailer: Mutt http://www.mutt.org/
X-Editor: Vim http://www.vim.org/
User-Agent: Mutt/1.5.10i
X-RedHat-Spam-Score: -100 
X-loop: linux-audit at redhat.com
Cc: 
Subject: Re: [PATCH 2/2] audit string fields interface + consumer
X-BeenThere: linux-audit at redhat.com
X-Mailman-Version: 2.1.5
Precedence: junk
List-Id: Linux Audit Discussion <linux-audit.redhat.com>
List-Unsubscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=unsubscribe>
List-Archive: <https://www.redhat.com/archives/linux-audit>
List-Post: <mailto:linux-audit at redhat.com>
List-Help: <mailto:linux-audit-request at redhat.com?subject=help>
List-Subscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=subscribe>
Sender: linux-audit-bounces at redhat.com
Errors-To: linux-audit-bounces at redhat.com
X-Spam-Score: 0.0 (/)
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

Add AUDIT_WATCH field type and associated helpers.

Signed-off-by: Amy Griffis <amy.griffis at hp.com>

---

 include/linux/audit.h |    1 
 kernel/audit.h        |    8 +++
 kernel/auditfilter.c  |  122 +++++++++++++++++++++++++++++++++++++++++++++----
 kernel/auditsc.c      |    3 +
 4 files changed, 123 insertions(+), 11 deletions(-)

d7ade2dd92b0ff7a3c6488b068f77089c9952d93
diff --git a/include/linux/audit.h b/include/linux/audit.h
index c208554..d76fa58 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -148,6 +148,7 @@
 #define AUDIT_INODE	102
 #define AUDIT_EXIT	103
 #define AUDIT_SUCCESS   104	/* exit >= 0; value ignored */
+#define AUDIT_WATCH	105
 
 #define AUDIT_ARG0      200
 #define AUDIT_ARG1      (AUDIT_ARG0+1)
diff --git a/kernel/audit.h b/kernel/audit.h
index f3b2a00..cc979e9 100644
--- a/kernel/audit.h
+++ b/kernel/audit.h
@@ -52,6 +52,12 @@ enum audit_state {
 };
 
 /* Rule lists */
+struct audit_watch {
+	char			*path; /* watch insertion path */
+	struct list_head	mlist; /* entry in master_watchlist */
+	struct list_head	rules; /* associated rules */
+};
+
 struct audit_field {
 	u32			type;
 	u32			val;
@@ -67,6 +73,8 @@ struct audit_krule {
 	u32			buflen; /* for data alloc on list rules */
 	u32			field_count;
 	struct audit_field	fields[AUDIT_MAX_FIELDS];
+	struct audit_watch	*watch; /* associated watch */
+	struct list_head	rlist; /* entry in audit_watch.rules list */
 };
 
 struct audit_entry {
diff --git a/kernel/auditfilter.c b/kernel/auditfilter.c
index 9c8865e..8ea0a14 100644
--- a/kernel/auditfilter.c
+++ b/kernel/auditfilter.c
@@ -22,6 +22,8 @@
 #include <linux/kernel.h>
 #include <linux/audit.h>
 #include <linux/kthread.h>
+#include <linux/fs.h>
+#include <linux/namei.h>
 #include <linux/netlink.h>
 #include "audit.h"
 
@@ -40,6 +42,8 @@ struct list_head audit_filter_list[AUDIT
 #endif
 };
 
+static LIST_HEAD(master_watchlist);
+
 /* Unpack a filter field's string representation from user-space
  * buffer. */
 static char *audit_unpack_string(void **bufp, size_t *remain, size_t len)
@@ -67,6 +71,34 @@ static char *audit_unpack_string(void **
 	return str;
 }
 
+/* Translate a watch string to kernel respresentation. */
+static int audit_to_watch(char *path, struct audit_krule *krule, int fidx)
+{
+	int err;
+	struct audit_field *f = &krule->fields[fidx];
+	struct nameidata nd;
+	struct audit_watch *watch;
+
+	err = -EINVAL;
+	if (path[0] != '/' || krule->listnr != AUDIT_FILTER_EXIT ||
+	    f->op & ~AUDIT_EQUAL)
+		return err;
+
+	if (path_lookup(path, 0, &nd) == 0)
+		f->val = nd.dentry->d_inode->i_ino;
+	else
+		f->val = (unsigned int)-1;
+
+	err = -ENOMEM;
+	watch = kmalloc(sizeof(*watch), GFP_KERNEL);
+	if (!watch)
+		return err;
+	watch->path = path;
+	krule->watch = watch;
+
+	return 0;
+}
+
 /* Common user-space to kernel rule translation. */
 static inline struct audit_entry *audit_to_entry_common(struct audit_rule *rule)
 {
@@ -161,8 +193,9 @@ static struct audit_entry *audit_data_to
 	int err = 0;
 	struct audit_entry *entry;
 	void *bufp;
-	/* size_t remain = datasz - sizeof(struct audit_rule_data); */
-	int i;
+	size_t remain = datasz - sizeof(struct audit_rule_data);
+	int i, len;
+	char *path;
 
 	entry = audit_to_entry_common((struct audit_rule *)data);
 	if (IS_ERR(entry))
@@ -181,7 +214,19 @@ static struct audit_entry *audit_data_to
 		f->op = data->fieldflags[i] & AUDIT_OPERATORS;
 		f->type = data->fields[i];
 		switch(f->type) {
-		/* call type-specific conversion routines here */
+		case AUDIT_WATCH:
+			len = data->values[i];
+			path = audit_unpack_string(&bufp, &remain, len);
+			if (IS_ERR(path))
+				goto exit_free;
+			entry->rule.buflen += len;
+
+			err = audit_to_watch(path, &entry->rule, i);
+			if (err) {
+				kfree(path);
+				goto exit_free;
+			}
+			break;
 		default:
 			f->val = data->values[i];
 		}
@@ -259,7 +304,10 @@ static struct audit_rule_data *audit_kru
 		data->fields[i] = f->type;
 		data->fieldflags[i] = f->op;
 		switch(f->type) {
-		/* call type-specific conversion routines here */
+		case AUDIT_WATCH:
+			data->buflen += data->values[i] =
+				audit_pack_string(&bufp, krule->watch->path);
+			break;
 		default:
 			data->values[i] = f->val;
 		}
@@ -269,6 +317,12 @@ static struct audit_rule_data *audit_kru
 	return data;
 }
 
+/* Compare two watches.  Considered success if rules don't match. */
+static inline int audit_compare_watch(struct audit_watch *a, struct audit_watch *b)
+{
+	return strcmp(a->path, b->path);
+}
+
 /* Compare two rules in kernel format.  Considered success if rules
  * don't match. */
 static int audit_compare_rule(struct audit_krule *a, struct audit_krule *b)
@@ -287,7 +341,10 @@ static int audit_compare_rule(struct aud
 			return 1;
 
 		switch(a->fields[i].type) {
-		/* call type-specific comparison routines here */
+		case AUDIT_WATCH:
+			if (audit_compare_watch(a->watch, b->watch))
+				return 1;
+			break;
 		default:
 			if (a->fields[i].val != b->fields[i].val)
 				return 1;
@@ -301,6 +358,38 @@ static int audit_compare_rule(struct aud
 	return 0;
 }
 
+static inline void audit_free_watch(struct audit_watch *watch)
+{
+	kfree(watch->path);
+	kfree(watch);
+}
+
+static inline void audit_free_rule(struct rcu_head *head)
+{
+	struct audit_entry *e = container_of(head, struct audit_entry, rcu);
+	kfree(e);
+}
+
+/* Attach krule's watch to master_watchlist, using existing watches
+ * when possible. */
+static inline void audit_add_watch(struct audit_krule *krule)
+{
+	struct audit_watch *w;
+
+	list_for_each_entry(w, &master_watchlist, mlist) {
+		if (strcmp(w->path, krule->watch->path) != 0)
+			continue;
+
+		audit_free_watch(krule->watch);
+		krule->watch = w;
+		list_add(&krule->rlist, &w->rules);
+		return;
+	}
+	INIT_LIST_HEAD(&krule->watch->rules);
+	list_add(&krule->rlist, &krule->watch->rules);
+	list_add(&krule->watch->mlist, &master_watchlist);
+}
+
 /* Add rule to given filterlist if not a duplicate.  Protected by
  * audit_netlink_sem. */
 static inline int audit_add_rule(struct audit_entry *entry,
@@ -315,6 +404,7 @@ static inline int audit_add_rule(struct 
 			return -EEXIST;
 	}
 
+	audit_add_watch(&entry->rule);
 	if (entry->rule.flags & AUDIT_FILTER_PREPEND) {
 		list_add_rcu(&entry->list, list);
 	} else {
@@ -324,10 +414,18 @@ static inline int audit_add_rule(struct 
 	return 0;
 }
 
-static inline void audit_free_rule(struct rcu_head *head)
+/* Detach watch from krule, freeing if it has no associated rules. */
+static inline void audit_remove_watch(struct audit_krule *krule)
 {
-	struct audit_entry *e = container_of(head, struct audit_entry, rcu);
-	kfree(e);
+	struct audit_watch *watch = krule->watch;
+
+	list_del(&krule->rlist);
+	krule->watch = NULL;
+
+	if (list_empty(&watch->rules)) {
+		list_del(&watch->mlist);
+		audit_free_watch(watch);
+	}
 }
 
 /* Remove an existing rule from filterlist.  Protected by
@@ -342,6 +440,7 @@ static inline int audit_del_rule(struct 
 	list_for_each_entry(e, list, list) {
 		if (!audit_compare_rule(&entry->rule, &e->rule)) {
 			list_del_rcu(&e->list);
+			audit_remove_watch(&e->rule);
 			call_rcu(&e->rcu, audit_free_rule);
 			return 0;
 		}
@@ -408,7 +507,7 @@ static int audit_list_rules(void *_dest)
 			if (!data)
 				break;
 			audit_send_reply(pid, seq, AUDIT_LIST_RULES, 0, 1,
-					 data, sizeof(*data));
+					 data, sizeof(*data) + data->buflen);
 			kfree(data);
 		}
 	}
@@ -475,8 +574,10 @@ int audit_receive_filter(int type, int p
 		if (!err)
 			audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
 				  "auid=%u added an audit rule\n", loginuid);
-		else
+		else {
+			audit_free_watch(entry->rule.watch);
 			kfree(entry);
+		}
 		break;
 	case AUDIT_DEL:
 	case AUDIT_DEL_RULE:
@@ -492,6 +593,7 @@ int audit_receive_filter(int type, int p
 		if (!err)
 			audit_log(NULL, GFP_KERNEL, AUDIT_CONFIG_CHANGE,
 				  "auid=%u removed an audit rule\n", loginuid);
+		audit_free_watch(entry->rule.watch);
 		kfree(entry);
 		break;
 	default:
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index e4f7096..8e98b65 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -240,7 +240,8 @@ static int audit_filter_rules(struct tas
 			}
 			break;
 		case AUDIT_INODE:
-			if (ctx) {
+		case AUDIT_WATCH:
+			if (ctx && f->val != (unsigned int)-1) {
 				for (j = 0; j < ctx->name_count; j++) {
 					if (audit_comparator(ctx->names[j].ino, f->op, f->val) ||
 					    audit_comparator(ctx->names[j].pino, f->op, f->val)) {
-- 
0.99.9n

--
Linux-audit mailing list
Linux-audit at redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit

linux-2.6-audit-tty.patch:
 auditsc.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)

--- NEW FILE linux-2.6-audit-tty.patch ---
>From linux-audit-bounces at redhat.com Sun Jan  1 19:07:06 2006
Return-path: <linux-audit-bounces at redhat.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Sun, 01 Jan 2006 19:07:06 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Et8Xq-0006yT-4F for dwmw2 at baythorne.infradead.org; Sun, 01 Jan 2006
	19:07:06 +0000
Received: from hormel.redhat.com ([209.132.177.30]) by
	pentafluge.infradead.org with esmtp (Exim 4.54 #1 (Red Hat Linux)) id
	1Et8Xo-0000N4-CS for dwmw2 at infradead.org; Sun, 01 Jan 2006 19:07:05 +0000
Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com
	[10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id 2C86D72EB7; Sun,
	 1 Jan 2006 14:07:02 -0500 (EST)
Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com
	[172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP
	id k01J71MX011720 for <linux-audit at listman.util.phx.redhat.com>; Sun, 1 Jan
	2006 14:07:01 -0500
Received: from mail.boston.redhat.com (mail.boston.redhat.com
	[172.16.76.12]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id
	k01J70127937 for <linux-audit at int-mx1.corp.redhat.com>; Sun, 1 Jan 2006
	14:07:00 -0500
Received: from vpn50-34.rdu.redhat.com (vpn50-34.rdu.redhat.com
	[172.16.50.34]) by mail.boston.redhat.com (8.12.8/8.12.8) with ESMTP id
	k01J6xa3016921 for <linux-audit at redhat.com>; Sun, 1 Jan 2006 14:07:00 -0500
From: Steve Grubb <sgrubb at redhat.com>
Organization: Red Hat
To: linux-audit at redhat.com
Date: Sun, 1 Jan 2006 14:07:00 -0500
User-Agent: KMail/1.9
MIME-Version: 1.0
Content-Type: text/plain; charset="us-ascii"
Content-Disposition: inline
Message-Id: <200601011407.00175.sgrubb at redhat.com>
X-MIME-Autoconverted: from quoted-printable to 8bit by
	listman.util.phx.redhat.com id k01J71MX011720
X-loop: linux-audit at redhat.com
Subject: Add tty to syscall audit records
X-BeenThere: linux-audit at redhat.com
X-Mailman-Version: 2.1.5
Precedence: junk
List-Id: Linux Audit Discussion <linux-audit.redhat.com>
List-Unsubscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=unsubscribe>
List-Archive: <https://www.redhat.com/archives/linux-audit>
List-Post: <mailto:linux-audit at redhat.com>
List-Help: <mailto:linux-audit-request at redhat.com?subject=help>
List-Subscribe: <https://www.redhat.com/mailman/listinfo/linux-audit>,
	<mailto:linux-audit-request at redhat.com?subject=subscribe>
Sender: linux-audit-bounces at redhat.com
Errors-To: linux-audit-bounces at redhat.com
X-Spam-Score: 0.0 (/)
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

Hi,

>From the RBAC specs:

FAU_SAR.1.1 The TSF shall provide the set of authorized 
RBAC administrators with the capability to read the following
audit information from the audit records:

<snip>
(e) The User Session Identifier or Terminal Type 

A patch adding the tty for all syscalls is included in this email.
Please apply.

Signed-off-by: Steve Grubb <sgrubb at redhat.com>



diff -urp linux-2.6.14.orig/kernel/auditsc.c linux-2.6.14/kernel/auditsc.c
--- linux-2.6.14.orig/kernel/auditsc.c	2005-12-28 10:39:04.000000000 -0500
+++ linux-2.6.14/kernel/auditsc.c	2005-12-28 10:40:28.000000000 -0500
@@ -56,6 +56,7 @@
 #include <asm/unistd.h>
 #include <linux/security.h>
 #include <linux/list.h>
+#include <linux/tty.h>
 
 #include "audit.h"
 
@@ -567,6 +568,7 @@ static void audit_log_exit(struct audit_
 	int i;
 	struct audit_buffer *ab;
 	struct audit_aux_data *aux;
+	const char *tty;
 
 	ab = audit_log_start(context, gfp_mask, AUDIT_SYSCALL);
 	if (!ab)
@@ -579,11 +581,15 @@ static void audit_log_exit(struct audit_
 		audit_log_format(ab, " success=%s exit=%ld", 
 				 (context->return_valid==AUDITSC_SUCCESS)?"yes":"no",
 				 context->return_code);
+	if (current->signal->tty && current->signal->tty->name)
+		tty = current->signal->tty->name;
+	else
+		tty = "(none)";
 	audit_log_format(ab,
 		  " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
 		  " pid=%d auid=%u uid=%u gid=%u"
 		  " euid=%u suid=%u fsuid=%u"
-		  " egid=%u sgid=%u fsgid=%u",
+		  " egid=%u sgid=%u fsgid=%u tty=%s",
 		  context->argv[0],
 		  context->argv[1],
 		  context->argv[2],
@@ -594,7 +600,7 @@ static void audit_log_exit(struct audit_
 		  context->uid,
 		  context->gid,
 		  context->euid, context->suid, context->fsuid,
-		  context->egid, context->sgid, context->fsgid);
+		  context->egid, context->sgid, context->fsgid, tty);
 	audit_log_task_info(ab);
 	audit_log_end(ab);
 

--
Linux-audit mailing list
Linux-audit at redhat.com
https://www.redhat.com/mailman/listinfo/linux-audit

linux-2.6-unshare-1.patch:
 unshare.txt |  295 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 295 insertions(+)

--- NEW FILE linux-2.6-unshare-1.patch ---
>From janak at us.ibm.com Thu Jan 12 04:15:28 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:15:28 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts0-0004Oy-6U for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:15:28 +0000
Received: from e6.ny.us.ibm.com ([32.97.182.146]) by
	pentafluge.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewtrt-0001mJ-W4 for dwmw2 at infradead.org; Thu, 12 Jan 2006 04:15:26 +0000
Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com
	[9.56.227.236]) by e6.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FJoe010866 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:19 -0500
Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by
	d01relay04.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FJ4f110076
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:19 -0500
Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by
	d01av01.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FJo9027950 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:19 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av01.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FHq3027907; Wed, 11 Jan 2006 23:15:17 -0500
Subject: [PATCH -mm 1/10] unshare system call -v5 : Documentation file
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137038987.7488.204.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:44 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on pentafluge.infradead.org
	summary: Content analysis details:   (0.4 points, 5.0 required) pts rule
	name              description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 1/10] unshare system call: Documentation file

Documents the new feature, why it is needed, it's cost, design,
implementation, and test plan.

Changes since -v4 submitted on 12/13/05:
	- New patch in the patch series that adds unshare.txt file.

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 unshare.txt |  295 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 295 insertions(+)

diff -Naurp 2.6.15-mm3/Documentation/unshare.txt 2.6.15-mm3+unsh-doc/Documentation/unshare.txt
--- 2.6.15-mm3/Documentation/unshare.txt	1970-01-01 00:00:00.000000000 +0000
+++ 2.6.15-mm3+unsh-doc/Documentation/unshare.txt	2006-01-11 22:27:01.000000000 +0000
@@ -0,0 +1,295 @@
+
+unshare system call:
+--------------------
+This document describes the new system call, unshare. The document
+provides an overview of the feature, why it is needed, how it can
+be used, its interface specification, design, implementation and
+how it can be tested.
+
+Change Log:
+-----------
+version 0.1  Initial document, Janak Desai (janak at us.ibm.com), Jan 11, 2006
+
+Contents:
+---------
+	1) Overview
+	2) Benefits
+	3) Cost
+	4) Requirements
+	5) Functional Specification
+	6) High Level Design
+	7) Low Level Design
+	8) Test Specification
+	9) Future Work
+
+1) Overview
+-----------
+Most legacy operating system kernels support an abstraction of threads
+as multiple execution contexts within a process. These kernels provide
+special resources and mechanisms to maintain these "threads". The Linux
+kernel, in a clever and simple manner, does not make distinction
+between processes and "threads". The kernel allows processes to share
+resources and thus they can achieve legacy "threads" behavior without
+requiring additional data structures and mechanisms in the kernel. The
+power of implementing threads in this manner comes not only from
+its simplicity but also from allowing application programmers to work
+outside the confinement of all-or-nothing shared resources of legacy
+threads. On Linux, at the time of thread creation using the clone system
+call, applications can selectively choose which resources to share
+between threads.
+
+unshare system call adds a primitive to the Linux thread model that
+allows threads to selectively 'unshare' any resources that were being
+shared at the time of their creation. unshare was conceptualized by
+Al Viro in the August of 2000, on the Linux-Kernel mailing list, as part
+of the discussion on POSIX threads on Linux.  unshare augments the
+usefulness of Linux threads for applications that would like to control
+shared resources without creating a new process. unshare is a natural
+addition to the set of available primitives on Linux that implement
+the concept of process/thread as a virtual machine.
+
+2) Benefits
+-----------
+unshare would be useful to large application frameworks such as PAM
+where creating a new process to control sharing/unsharing of process
+resources is not possible. Since namespaces are shared by default
+when creating a new process using fork or clone, unshare can benefit
+even non-threaded applications if they have a need to disassociate
+from default shared namespace. The following lists two use-cases
+where unshare can be used.
+
+2.1 Per-security context namespaces
+-----------------------------------
+unshare can be used to implement polyinstantiated directories using
+the kernel's per-process namespace mechanism. Polyinstantiated directories,
+such as per-user and/or per-security context instance of /tmp, /var/tmp or
+per-security context instance of a user's home directory, isolate user
+processes when working with these directories. Using unshare, a PAM
+module can easily setup a private namespace for a user at login.
+Polyinstantiated directories are required for Common Criteria certification
+with Labeled System Protection Profile, however, with the availability
+of shared-tree feature in the Linux kernel, even regular Linux systems
+can benefit from setting up private namespaces at login and
+polyinstantiating /tmp, /var/tmp and other directories deemed
+appropriate by system administrators.
+
+2.2 unsharing of virtual memory and/or open files
+-------------------------------------------------
+Consider a client/server application where the server is processing
+client requests by creating processes that share resources such as
+virtual memory and open files. Without unshare, the server has to
+decide what needs to be shared at the time of creating the process
+which services the request. unshare allows the server an ability to
+disassociate parts of the context during the servicing of the
+request. For large and complex middleware application frameworks, this
+ability to unshare after the process was created can be very
+useful.
+
+3) Cost
+-------
+In order to not duplicate code and to handle the fact that unshare
+works on an active task (as opposed to clone/fork working on a newly
+allocated inactive task) unshare had to make minor reorganizational
+changes to copy_* functions utilized by clone/fork system call.
+There is a cost associated with altering existing, well tested and
+stable code to implement a new feature that may not get exercised
+extensively in the beginning. However, with proper design and code
+review of the changes and creation of an unshare test for the LTP
+the benefits of this new feature can exceed its cost.
+
+4) Requirements
+---------------
+unshare reverses sharing that was done using clone(2) system call,
+so unshare should have a similar interface as clone(2). That is,
+since flags in clone(int flags, void *stack) specifies what should
+be shared, similar flags in unshare(int flags) should specify
+what should be unshared. Unfortunately, this may appear to invert
+the meaning of the flags from the way they are used in clone(2).
+However, there was no easy solution that was less confusing and that
+allowed incremental context unsharing in future without an ABI change.
+
+unshare interface should accommodate possible future addition of
+new context flags without requiring a rebuild of old applications.
+If and when new context flags are added, unshare design should allow
+incremental unsharing of those resources on an as needed basis.
+
+5) Functional Specification
+---------------------------
+NAME
+	unshare - disassociate parts of the process execution context
+
+SYNOPSIS
+	#include <sched.h>
+
+	int unshare(int flags);
+
+DESCRIPTION
+	unshare allows a process to disassociate parts of its execution
+	context that are currently being shared with other processes. Part
+	of execution context, such as the namespace, is shared by default
+	when a new process is created using fork(2), while other parts,
+	such as the virtual memory, open file descriptors, etc, may be
+	shared by explicit request to share them when creating a process
+	using clone(2).
+
+	The main use of unshare is to allow a process to control its
+	shared execution context without creating a new process.
+
+	The flags argument specifies one or bitwise-or'ed of several of
+	the following constants.
+
+	CLONE_FS
+		If CLONE_FS is set, file system information of the caller
+		is disassociated from the shared file system information.
+
+	CLONE_FILES
+		If CLONE_FILES is set, the file descriptor table of the
+		caller is disassociated from the shared file descriptor
+		table.
+
+	CLONE_NEWNS
+		If CLONE_NEWNS is set, the namespace of the caller is
+		disassociated from the shared namespace.
+
+	CLONE_VM
+		If CLONE_VM is set, the virtual memory of the caller is
+		disassociated from the shared virtual memory.
+
+RETURN VALUE
+	On success, zero returned. On failure, -1 is returned and errno is
+
+ERRORS
+	EPERM	CLONE_NEWNS was specified by a non-root process (process
+		without CAP_SYS_ADMIN).
+
+	ENOMEM	Cannot allocate sufficient memory to copy parts of caller's
+		context that need to be unshared.
+
+	EINVAL	Invalid flag was specified as an argument.
+
+CONFORMING TO
+	The unshare() call is Linux-specific and  should  not be used
+	in programs intended to be portable.
+
+SEE ALSO
+	clone(2), fork(2)
+
+6) High Level Design
+--------------------
+Depending on the flags argument, the unshare system call allocates
+appropriate process context structures, populates it with values from
+the current shared version, associates newly duplicated structures
+with the current task structure and releases corresponding shared
+versions. Helper functions of clone (copy_*) could not be used
+directly by unshare because of the following two reasons.
+  1) clone operates on a newly allocated not-yet-active task
+     structure, where as unshare operates on the current active
+     task. Therefore unshare has to take appropriate task_lock()
+     before associating newly duplicated context structures
+  2) unshare has to allocate and duplicate all context structures
+     that are being unshared, before associating them with the
+     current task and releasing older shared structures. Failure
+     do so will create race conditions and/or oops when trying
+     to backout due to an error. Consider the case of unsharing
+     both virtual memory and namespace. After successfully unsharing
+     vm, if the system call encounters an error while allocating
+     new namespace structure, the error return code will have to
+     reverse the unsharing of vm. As part of the reversal the
+     system call will have to go back to older, shared, vm
+     structure, which may not exist anymore.
+
+Therefore code from copy_* functions that allocated and duplicated
+current context structure was moved into new dup_* functions. Now,
+copy_* functions call dup_* functions to allocate and duplicate
+appropriate context structures and then associate them with the
+task structure that is being constructed. unshare system call on
+the other hand performs the following:
+  1) Check flags to force missing, but implied, flags
+  2) For each context structure, call the corresponding unshare
+     helper function to allocate and duplicate a new context
+     structure, if the appropriate bit is set in the flags argument.
+  3) If there is no error in allocation and duplication and there
+     are new context structures then lock the current task structure,
+     associate new context structures with the current task structure,
+     and release the lock on the current task structure.
+  4) Appropriately release older, shared, context structures.
+
+7) Low Level Design
+-------------------
+Implementation of unshare can be grouped in the following 4 different
+items:
+  a) Reorganization of existing copy_* functions
+  b) unshare system call service function
+  c) unshare helper functions for each different process context
+  d) Registration of system call number for different architectures
+
+  7.1) Reorganization of copy_* functions
+       Each copy function such as copy_mm, copy_namespace, copy_files,
+       etc, had roughly two components. The first component allocated
+       and duplicated the appropriate structure and the second component
+       linked it to the task structure passed in as an argument to the copy
+       function. The first component was split into its own function.
+       These dup_* functions allocated and duplicated the appropriate
+       context structure. The reorganized copy_* functions invoked
+       their corresponding dup_* functions and then linked the newly
+       duplicated structures to the task structure with which the
+       copy function was called.
+
+  7.2) unshare system call service function
+       * Check flags
+	 Force implied flags. If CLONE_THREAD is set force CLONE_VM.
+	 If CLONE_VM is set, force CLONE_SIGHAND. If CLONE_SIGHAND is
+	 set and signals are also being shared, force CLONE_THREAD. If
+	 CLONE_NEWNS is set, force CLONE_FS.
+       * For each context flag, invoke the corresponding unshare_*
+	 helper routine with flags passed into the system call and a
+	 reference to pointer pointing the new unshared structure
+       * If any new structures are created by unshare_* helper
+	 functions, take the task_lock() on the current task,
+	 modify appropriate context pointers, and release the
+         task lock.
+       * For all newly unshared structures, release the corresponding
+         older, shared, structures.
+
+  7.3) unshare_* helper functions
+       For unshare_* helpers corresponding to CLONE_SYSVSEM, CLONE_SIGHAND,
+       and CLONE_THREAD, return -EINVAL since they are not implemented yet.
+       For others, check the flag value to see if the unsharing is
+       required for that structure. If it is, invoke the corresponding
+       dup_* function to allocate and duplicate the structure and return
+       a pointer to it.
+
+  7.4) Appropriately modify architecture specific code to register the
+       the new system call.
+
+8) Test Specification
+---------------------
+The test for unshare should test the following:
+  1) Valid flags: Test to check that clone flags for signal and
+	signal handlers, for which unsharing is not implemented
+	yet, return -EINVAL.
+  2) Missing/implied flags: Test to make sure that if unsharing
+	namespace without specifying unsharing of filesystem, correctly
+	unshares both namespace and filesystem information.
+  3) For each of the four (namespace, filesystem, files and vm)
+	supported unsharing, verify that the system call correctly
+	unshares the appropriate structure. Verify that unsharing
+	them individually as well as in combination with each
+	other works as expected.
+  4) Concurrent execution: Use shared memory segments and futex on
+	an address in the shm segment to synchronize execution of
+	about 10 threads. Have a couple of threads execute execve,
+	a couple _exit and the rest unshare with different combination
+	of flags. Verify that unsharing is performed as expected and
+	that there are no oops or hangs.
+
+9) Future Work
+--------------
+The current implementation of unshare does not allow unsharing of
+signals and signal handlers. Signals are complex to begin with and
+to unshare signals and/or signal handlers of a currently running
+process is even more complex. If in the future there is a specific
+need to allow unsharing of signals and/or signal handlers, it can
+be incrementally added to unshare without affecting legacy
+applications using unshare.
+



linux-2.6-unshare-10.patch:
 arch/x86_64/ia32/ia32entry.S     |    1 +
 include/asm-x86_64/ia32_unistd.h |    3 ++-
 include/asm-x86_64/unistd.h      |    4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)

--- NEW FILE linux-2.6-unshare-10.patch ---
>From janak at us.ibm.com Thu Jan 12 04:16:00 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:16:00 +0000
Received: from canuck.infradead.org ([2001:8b0:10b:4::1]) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwtsU-0004QB-SW for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:16:00 +0000
Received: from e34.co.us.ibm.com ([32.97.110.152]) by canuck.infradead.org
	with esmtps (Exim 4.54 #1 (Red Hat Linux)) id 1EwtsK-0000Cy-F2 for
	dwmw2 at infradead.org; Wed, 11 Jan 2006 23:15:51 -0500
Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com
	[9.17.195.106]) by e34.co.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FcAo003973 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:38 -0500
Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com
	[9.17.195.169]) by d03relay04.boulder.ibm.com (8.12.10/NCO/VERS6.8) with
	ESMTP id k0C4HgX5147072 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006
	21:17:42 -0700
Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by
	d03av03.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FbPq023652 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 21:15:37 -0700
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d03av03.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FZMp023601; Wed, 11 Jan 2006 21:15:36 -0700
Subject: [PATCH -mm 10/10] unshare system call -v5 : system call
	registration for x86_64
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137039015.7488.222.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:11:03 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on canuck.infradead.org summary:
	Content analysis details:   (0.4 points, 5.0 required) pts rule name       
	      description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 10/10] unshare system call: system call registration for x86_64

Registers system call for the x86_64 architecture.

Changes since -v4 of this patch submitted on 12/13/05:
        - Forward ported to 2.6.15-mm3 which modified the syscall number.

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 arch/x86_64/ia32/ia32entry.S     |    1 +
 include/asm-x86_64/ia32_unistd.h |    3 ++-
 include/asm-x86_64/unistd.h      |    4 +++-
 3 files changed, 6 insertions(+), 2 deletions(-)

diff -Naurp 2.6.15-mm3/arch/x86_64/ia32/ia32entry.S 2.6.15-mm3+unsh-x86_64/arch/x86_64/ia32/ia32entry.S
--- 2.6.15-mm3/arch/x86_64/ia32/ia32entry.S	2006-01-11 20:21:49.000000000 +0000
+++ 2.6.15-mm3+unsh-x86_64/arch/x86_64/ia32/ia32entry.S	2006-01-12 00:49:51.000000000 +0000
@@ -685,6 +685,7 @@ ia32_sys_call_table:
 	.quad sys_inotify_init
 	.quad sys_inotify_add_watch
 	.quad sys_inotify_rm_watch
+	.quad sys_unshare
 ia32_syscall_end:		
 	.rept IA32_NR_syscalls-(ia32_syscall_end-ia32_sys_call_table)/8
 		.quad ni_syscall
diff -Naurp 2.6.15-mm3/include/asm-x86_64/ia32_unistd.h 2.6.15-mm3+unsh-x86_64/include/asm-x86_64/ia32_unistd.h
--- 2.6.15-mm3/include/asm-x86_64/ia32_unistd.h	2006-01-11 20:22:17.000000000 +0000
+++ 2.6.15-mm3+unsh-x86_64/include/asm-x86_64/ia32_unistd.h	2006-01-12 00:51:13.000000000 +0000
@@ -313,7 +313,8 @@
 define __NR_ia32_inotify_init		291
 #define __NR_ia32_inotify_add_watch	292
 #define __NR_ia32_inotify_rm_watch	293
+#define __NR_ia32_unshare		294
 
-#define IA32_NR_syscalls 294	/* must be > than biggest syscall! */
+#define IA32_NR_syscalls 295	/* must be > than biggest syscall! */
 
 #endif /* _ASM_X86_64_IA32_UNISTD_H_ */
diff -Naurp 2.6.15-mm3/include/asm-x86_64/unistd.h 2.6.15-mm3+unsh-x86_64/include/asm-x86_64/unistd.h
--- 2.6.15-mm3/include/asm-x86_64/unistd.h	2006-01-11 20:22:17.000000000 +0000
+++ 2.6.15-mm3+unsh-x86_64/include/asm-x86_64/unistd.h	2006-01-12 00:54:02.000000000 +0000
@@ -599,7 +599,9 @@ __SYSCALL(__NR_readlinkat, sys_readlinka
 __SYSCALL(__NR_inotify_add_watch, sys_inotify_add_watch)
 #define __NR_inotify_rm_watch	255
 __SYSCALL(__NR_inotify_rm_watch, sys_inotify_rm_watch)
+#define __NR_unshare		256
+__SYSCALL(__NR_unshare, sys_unshare)
 
-#define __NR_syscall_max __NR_inotify_rm_watch
+#define __NR_syscall_max __NR_unshare
 #ifndef __NO_STUBS
 



linux-2.6-unshare-2.patch:
 fork.c |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 232 insertions(+)

--- NEW FILE linux-2.6-unshare-2.patch ---
>From janak at us.ibm.com Thu Jan 12 04:16:00 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:16:00 +0000
Received: from canuck.infradead.org ([2001:8b0:10b:4::1]) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwtsU-0004QC-NQ for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:16:00 +0000
Received: from e4.ny.us.ibm.com ([32.97.182.144]) by canuck.infradead.org
	with esmtps (Exim 4.54 #1 (Red Hat Linux)) id 1Ewts7-0000Cq-MA for
	dwmw2 at infradead.org; Wed, 11 Jan 2006 23:15:54 -0500
Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com
	[9.56.227.234]) by e4.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FLVs014352 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:21 -0500
Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by
	d01relay02.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FLYs133248
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:21 -0500
Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by
	d01av01.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FLU5028010 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:21 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av01.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FJBb027961; Wed, 11 Jan 2006 23:15:19 -0500
Subject: [PATCH -mm 2/10] unshare system call -v5 : system call handler
	function
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137038992.7488.206.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:46 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on canuck.infradead.org summary:
	Content analysis details:   (0.4 points, 5.0 required) pts rule name       
	      description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 2/10] unshare system call: system call handler function

sys_unshare system call handler function accepts the same flags as
clone system call, checks constraints on each of the flags and invokes
corresponding unshare functions to disassociate respective process
context if it was being shared with another task.

Changes since the -v4 submitted on 12/13/05:
	- none

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 fork.c |  232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 232 insertions(+)

diff -Naurp 2.6.15-mm3/kernel/fork.c 2.6.15-mm3+unsh-base/kernel/fork.c
--- 2.6.15-mm3/kernel/fork.c	2006-01-11 20:22:20.000000000 +0000
+++ 2.6.15-mm3+unsh-base/kernel/fork.c	2006-01-11 22:46:49.000000000 +0000
@@ -1323,3 +1323,235 @@ void __init proc_caches_init(void)
 			sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
 			SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL, NULL);
 }
+
+
+/*
+ * Check constraints on flags passed to the unshare system call and
+ * force unsharing of additional process context as appropriate.
+ */
+static inline void check_unshare_flags(unsigned long *flags_ptr)
+{
+	/*
+	 * If unsharing a thread from a thread group, must also
+	 * unshare vm.
+	 */
+	if (*flags_ptr & CLONE_THREAD)
+		*flags_ptr |= CLONE_VM;
+
+	/*
+	 * If unsharing vm, must also unshare signal handlers.
+	 */
+	if (*flags_ptr & CLONE_VM)
+		*flags_ptr |= CLONE_SIGHAND;
+
+	/*
+	 * If unsharing signal handlers and the task was created
+	 * using CLONE_THREAD, then must unshare the thread
+	 */
+	if ((*flags_ptr & CLONE_SIGHAND) &&
+	    (atomic_read(&current->signal->count) > 1))
+		*flags_ptr |= CLONE_THREAD;
+
+	/*
+	 * If unsharing namespace, must also unshare filesystem information.
+	 */
+	if (*flags_ptr & CLONE_NEWNS)
+		*flags_ptr |= CLONE_FS;
+}
+
+/*
+ * Unsharing of tasks created with CLONE_THREAD is not supported yet
+ */
+static int unshare_thread(unsigned long unshare_flags)
+{
+	if (unshare_flags & CLONE_THREAD)
+		return -EINVAL;
+
+	return 0;
+}
+
+/*
+ * Unsharing of fs info for tasks created with CLONE_FS is not supported yet
+ */
+static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
+{
+	struct fs_struct *fs = current->fs;
+
+	if ((unshare_flags & CLONE_FS) &&
+	    (fs && atomic_read(&fs->count) > 1))
+		return -EINVAL;
+
+	return 0;
+}
+
+/*
+ * Unsharing of namespace for tasks created without CLONE_NEWNS is not
+ * supported yet
+ */
+static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp)
+{
+	struct namespace *ns = current->namespace;
+
+	if ((unshare_flags & CLONE_NEWNS) &&
+	    (ns && atomic_read(&ns->count) > 1))
+		return -EINVAL;
+
+	return 0;
+}
+
+/*
+ * Unsharing of sighand for tasks created with CLONE_SIGHAND is not
+ * supported yet
+ */
+static int unshare_sighand(unsigned long unshare_flags, struct sighand_struct **new_sighp)
+{
+	struct sighand_struct *sigh = current->sighand;
+
+	if ((unshare_flags & CLONE_SIGHAND) &&
+	    (sigh && atomic_read(&sigh->count) > 1))
+		return -EINVAL;
+	else
+		return 0;
+}
+
+/*
+ * Unsharing of vm for tasks created with CLONE_VM is not supported yet
+ */
+static int unshare_vm(unsigned long unshare_flags, struct mm_struct **new_mmp)
+{
+	struct mm_struct *mm = current->mm;
+
+	if ((unshare_flags & CLONE_VM) &&
+	    (mm && atomic_read(&mm->mm_users) > 1))
+		return -EINVAL;
+
+	return 0;
+
+}
+
+/*
+ * Unsharing of files for tasks created with CLONE_FILES is not supported yet
+ */
+static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
+{
+	struct files_struct *fd = current->files;
+
+	if ((unshare_flags & CLONE_FILES) &&
+	    (fd && atomic_read(&fd->count) > 1))
+		return -EINVAL;
+
+	return 0;
+}
+
+/*
+ * Unsharing of semundo for tasks created with CLONE_SYSVSEM is not
+ * supported yet
+ */
+static int unshare_semundo(unsigned long unshare_flags, struct sem_undo_list **new_ulistp)
+{
+	if (unshare_flags & CLONE_SYSVSEM)
+		return -EINVAL;
+
+	return 0;
+}
+
+/*
+ * unshare allows a process to 'unshare' part of the process
+ * context which was originally shared using clone.  copy_*
+ * functions used by do_fork() cannot be used here directly
+ * because they modify an inactive task_struct that is being
+ * constructed. Here we are modifying the current, active,
+ * task_struct.
+ */
+asmlinkage long sys_unshare(unsigned long unshare_flags)
+{
+	int err = 0;
+	struct fs_struct *fs, *new_fs = NULL;
+	struct namespace *ns, *new_ns = NULL;
+	struct sighand_struct *sigh, *new_sigh = NULL;
+	struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL;
+	struct files_struct *fd, *new_fd = NULL;
+	struct sem_undo_list *new_ulist = NULL;
+
+	check_unshare_flags(&unshare_flags);
+
+	if ((err = unshare_thread(unshare_flags)))
+		goto bad_unshare_out;
+	if ((err = unshare_fs(unshare_flags, &new_fs)))
+		goto bad_unshare_cleanup_thread;
+	if ((err = unshare_namespace(unshare_flags, &new_ns)))
+		goto bad_unshare_cleanup_fs;
+	if ((err = unshare_sighand(unshare_flags, &new_sigh)))
+		goto bad_unshare_cleanup_ns;
+	if ((err = unshare_vm(unshare_flags, &new_mm)))
+		goto bad_unshare_cleanup_sigh;
+	if ((err = unshare_fd(unshare_flags, &new_fd)))
+		goto bad_unshare_cleanup_vm;
+	if ((err = unshare_semundo(unshare_flags, &new_ulist)))
+		goto bad_unshare_cleanup_fd;
+
+	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist) {
+
+		task_lock(current);
+
+		if (new_fs) {
+			fs = current->fs;
+			current->fs = new_fs;
+			new_fs = fs;
+		}
+
+		if (new_ns) {
+			ns = current->namespace;
+			current->namespace = new_ns;
+			new_ns = ns;
+		}
+
+		if (new_sigh) {
+			sigh = current->sighand;
+			current->sighand = new_sigh;
+			new_sigh = sigh;
+		}
+
+		if (new_mm) {
+			mm = current->mm;
+			active_mm = current->active_mm;
+			current->mm = new_mm;
+			current->active_mm = new_mm;
+			activate_mm(active_mm, new_mm);
+			new_mm = mm;
+		}
+
+		if (new_fd) {
+			fd = current->files;
+			current->files = new_fd;
+			new_fd = fd;
+		}
+
+		task_unlock(current);
+	}
+
+bad_unshare_cleanup_fd:
+	if (new_fd)
+		put_files_struct(new_fd);
+
+bad_unshare_cleanup_vm:
+	if (new_mm)
+		mmput(new_mm);
+
+bad_unshare_cleanup_sigh:
+	if (new_sigh)
+		if (atomic_dec_and_test(&new_sigh->count))
+			kmem_cache_free(sighand_cachep, new_sigh);
+
+bad_unshare_cleanup_ns:
+	if (new_ns)
+		put_namespace(new_ns);
+
+bad_unshare_cleanup_fs:
+	if (new_fs)
+		put_fs_struct(new_fs);
+
+bad_unshare_cleanup_thread:
+bad_unshare_out:
+	return err;
+}



linux-2.6-unshare-3.patch:
 fork.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

--- NEW FILE linux-2.6-unshare-3.patch ---
>From janak at us.ibm.com Thu Jan 12 04:15:29 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:15:29 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts0-0004Oz-TD for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:15:29 +0000
Received: from e1.ny.us.ibm.com ([32.97.182.141]) by
	pentafluge.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewtry-0001mS-Uv for dwmw2 at infradead.org; Thu, 12 Jan 2006 04:15:28 +0000
Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com
	[9.56.227.236]) by e1.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FMos019206 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:22 -0500
Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by
	d01relay04.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FN4f124468
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:23 -0500
Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by
	d01av03.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FN7g008363 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:23 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av03.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FLJr008307; Wed, 11 Jan 2006 23:15:21 -0500
Subject: [PATCH -mm 3/10] unshare system call -v5 : unshare filesystem info
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137038994.7488.208.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:48 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on pentafluge.infradead.org
	summary: Content analysis details:   (0.4 points, 5.0 required) pts rule
	name              description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 3/10] unshare system call: allow unsharing of filesystem info

If filesystem structure is being shared, allocate a new one and
copy information from the current, shared, structure.

Changes since -v4 of this patch submitted on 12/13/05:
        - none

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 fork.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff -Naurp 2.6.15-mm3+unsh-base/kernel/fork.c 2.6.15-mm3+unsh-fs/kernel/fork.c
--- 2.6.15-mm3+unsh-base/kernel/fork.c	2006-01-11 22:46:49.000000000 +0000
+++ 2.6.15-mm3+unsh-fs/kernel/fork.c	2006-01-12 00:26:46.000000000 +0000
@@ -1371,15 +1371,18 @@ static int unshare_thread(unsigned long 
 }
 
 /*
- * Unsharing of fs info for tasks created with CLONE_FS is not supported yet
+ * Unshare the filesystem structure if it is being shared
  */
 static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
 {
 	struct fs_struct *fs = current->fs;
 
 	if ((unshare_flags & CLONE_FS) &&
-	    (fs && atomic_read(&fs->count) > 1))
-		return -EINVAL;
+	    (fs && atomic_read(&fs->count) > 1)) {
+		*new_fsp = __copy_fs_struct(current->fs);
+		if (!*new_fsp)
+			return -ENOMEM;
+	}
 
 	return 0;
 }



linux-2.6-unshare-4.patch:
 fs/namespace.c            |   56 +++++++++++++++++++++++++++++-----------------
 include/linux/namespace.h |    1 
 kernel/fork.c             |   17 +++++++++----
 3 files changed, 48 insertions(+), 26 deletions(-)

--- NEW FILE linux-2.6-unshare-4.patch ---
>From janak at us.ibm.com Thu Jan 12 04:16:00 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:16:00 +0000
Received: from canuck.infradead.org ([2001:8b0:10b:4::1]) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwtsU-0004QD-OA for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:16:00 +0000
Received: from e3.ny.us.ibm.com ([32.97.182.143]) by canuck.infradead.org
	with esmtps (Exim 4.54 #1 (Red Hat Linux)) id 1Ewts9-0000Cs-7c for
	dwmw2 at infradead.org; Wed, 11 Jan 2006 23:15:52 -0500
Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com
	[9.56.227.236]) by e3.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FPvZ012443 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:25 -0500
Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by
	d01relay04.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FP4f124472
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:25 -0500
Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by
	d01av04.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FPDU025965 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:25 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av04.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FN2D025924; Wed, 11 Jan 2006 23:15:23 -0500
Subject: [PATCH -mm 4/10] unshare system call -v5 : unshare namespace
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137038997.7488.210.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:50 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on canuck.infradead.org summary:
	Content analysis details:   (0.4 points, 5.0 required) pts rule name       
	      description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 4/10] unshare system call: allow unsharing of namespace

If the namespace structure is being shared, allocate a new one and
copy information from the current, shared, structure.

Changes since -v4 of this patch submitted on 12/13/05:
	- none

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 fs/namespace.c            |   56 +++++++++++++++++++++++++++++-----------------
 include/linux/namespace.h |    1 
 kernel/fork.c             |   17 +++++++++----
 3 files changed, 48 insertions(+), 26 deletions(-)

diff -Naurp 2.6.15-mm3+unsh-fs/fs/namespace.c 2.6.15-mm3+unsh-ns/fs/namespace.c
--- 2.6.15-mm3+unsh-fs/fs/namespace.c	2006-01-12 00:24:06.000000000 +0000
+++ 2.6.15-mm3+unsh-ns/fs/namespace.c	2006-01-12 00:39:49.000000000 +0000
@@ -1321,27 +1321,17 @@ dput_out:
 	return retval;
 }
 
-int copy_namespace(int flags, struct task_struct *tsk)
+/*
+ * Allocate a new namespace structure and populate it with contents
+ * copied from the namespace of the passed in task structure.
+ */
+struct namespace *dup_namespace(struct task_struct *tsk, struct fs_struct *fs)
 {
 	struct namespace *namespace = tsk->namespace;
 	struct namespace *new_ns;
 	struct vfsmount *rootmnt = NULL, *pwdmnt = NULL, *altrootmnt = NULL;
-	struct fs_struct *fs = tsk->fs;
 	struct vfsmount *p, *q;
 
-	if (!namespace)
-		return 0;
-
-	get_namespace(namespace);
-
-	if (!(flags & CLONE_NEWNS))
-		return 0;
-
-	if (!capable(CAP_SYS_ADMIN)) {
-		put_namespace(namespace);
-		return -EPERM;
-	}
-
 	new_ns = kmalloc(sizeof(struct namespace), GFP_KERNEL);
 	if (!new_ns)
 		goto out;
@@ -1392,8 +1382,6 @@ int copy_namespace(int flags, struct tas
 	}
 	up_write(&namespace_sem);
 
-	tsk->namespace = new_ns;
-
 	if (rootmnt)
 		mntput(rootmnt);
 	if (pwdmnt)
@@ -1401,12 +1389,40 @@ int copy_namespace(int flags, struct tas
 	if (altrootmnt)
 		mntput(altrootmnt);
 
-	put_namespace(namespace);
-	return 0;
+out:
+	return new_ns;
+}
+
+int copy_namespace(int flags, struct task_struct *tsk)
+{
+	struct namespace *namespace = tsk->namespace;
+	struct namespace *new_ns;
+	int err = 0;
+
+	if (!namespace)
+		return 0;
+
+	get_namespace(namespace);
+
+	if (!(flags & CLONE_NEWNS))
+		return 0;
+
+	if (!capable(CAP_SYS_ADMIN)) {
+		err = -EPERM;
+		goto out;
+	}
+
+	new_ns = dup_namespace(tsk, tsk->fs);
+	if (!new_ns) {
+		err = -ENOMEM;
+		goto out;
+	}
+
+	tsk->namespace = new_ns;
 
 out:
 	put_namespace(namespace);
-	return -ENOMEM;
+	return err;
 }
 
 asmlinkage long sys_mount(char __user * dev_name, char __user * dir_name,
diff -Naurp 2.6.15-mm3+unsh-fs/include/linux/namespace.h 2.6.15-mm3+unsh-ns/include/linux/namespace.h
--- 2.6.15-mm3+unsh-fs/include/linux/namespace.h	2006-01-12 00:25:13.000000000 +0000
+++ 2.6.15-mm3+unsh-ns/include/linux/namespace.h	2006-01-12 00:39:49.000000000 +0000
@@ -15,6 +15,7 @@ struct namespace {
 
 extern int copy_namespace(int, struct task_struct *);
 extern void __put_namespace(struct namespace *namespace);
+extern struct namespace *dup_namespace(struct task_struct *, struct fs_struct *);
 
 static inline void put_namespace(struct namespace *namespace)
 {
diff -Naurp 2.6.15-mm3+unsh-fs/kernel/fork.c 2.6.15-mm3+unsh-ns/kernel/fork.c
--- 2.6.15-mm3+unsh-fs/kernel/fork.c	2006-01-12 00:26:46.000000000 +0000
+++ 2.6.15-mm3+unsh-ns/kernel/fork.c	2006-01-12 00:39:49.000000000 +0000
@@ -1388,16 +1388,21 @@ static int unshare_fs(unsigned long unsh
 }
 
 /*
- * Unsharing of namespace for tasks created without CLONE_NEWNS is not
- * supported yet
+ * Unshare the namespace structure if it is being shared
  */
-static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp)
+static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp, struct fs_struct *new_fs)
 {
 	struct namespace *ns = current->namespace;
 
 	if ((unshare_flags & CLONE_NEWNS) &&
-	    (ns && atomic_read(&ns->count) > 1))
-		return -EINVAL;
+	    (ns && atomic_read(&ns->count) > 1)) {
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
+
+		*new_nsp = dup_namespace(current, new_fs ? new_fs : current->fs);
+		if (!*new_nsp)
+			return -ENOMEM;
+	}
 
 	return 0;
 }
@@ -1482,7 +1487,7 @@ asmlinkage long sys_unshare(unsigned lon
 		goto bad_unshare_out;
 	if ((err = unshare_fs(unshare_flags, &new_fs)))
 		goto bad_unshare_cleanup_thread;
-	if ((err = unshare_namespace(unshare_flags, &new_ns)))
+	if ((err = unshare_namespace(unshare_flags, &new_ns, new_fs)))
 		goto bad_unshare_cleanup_fs;
 	if ((err = unshare_sighand(unshare_flags, &new_sigh)))
 		goto bad_unshare_cleanup_ns;



linux-2.6-unshare-5.patch:
 fork.c |   87 +++++++++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 56 insertions(+), 31 deletions(-)

--- NEW FILE linux-2.6-unshare-5.patch ---
>From janak at us.ibm.com Thu Jan 12 04:16:00 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:16:00 +0000
Received: from canuck.infradead.org ([2001:8b0:10b:4::1]) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwtsU-0004QA-RL for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:16:00 +0000
Received: from e3.ny.us.ibm.com ([32.97.182.143]) by canuck.infradead.org
	with esmtps (Exim 4.54 #1 (Red Hat Linux)) id 1Ewts9-0000Ct-7Z for
	dwmw2 at infradead.org; Wed, 11 Jan 2006 23:15:49 -0500
Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com
	[9.56.227.236]) by e3.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FR0m012461 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:27 -0500
Received: from d01av01.pok.ibm.com (d01av01.pok.ibm.com [9.56.224.215]) by
	d01relay04.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FR4f061702
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:27 -0500
Received: from d01av01.pok.ibm.com (loopback [127.0.0.1]) by
	d01av01.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FQ4C028205 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:27 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av01.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FPr0028164; Wed, 11 Jan 2006 23:15:25 -0500
Subject: [PATCH -mm 5/10] unshare system call -v5 : unshare vm
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137039000.7488.212.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:52 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on canuck.infradead.org summary:
	Content analysis details:   (0.4 points, 5.0 required) pts rule name       
	      description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 5/10] unshare system call: allow unsharing of vm

If vm structure is being shared, allocate a new one and
copy information from the current, shared, structure.

Changes since -v4 of this patch submitted on 12/13/05:
	- none

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 fork.c |   87 +++++++++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 56 insertions(+), 31 deletions(-)

diff -Naurp 2.6.15-mm3+unsh-ns/kernel/fork.c 2.6.15-mm3+unsh-vm/kernel/fork.c
--- 2.6.15-mm3+unsh-ns/kernel/fork.c	2006-01-12 00:39:49.000000000 +0000
+++ 2.6.15-mm3+unsh-vm/kernel/fork.c	2006-01-12 00:47:33.000000000 +0000
@@ -446,6 +446,55 @@ void mm_release(struct task_struct *tsk,
 	}
 }
 
+/*
+ * Allocate a new mm structure and copy contents from the
+ * mm structure of the passed in task structure.
+ */
+static struct mm_struct *dup_mm(struct task_struct *tsk)
+{
+	struct mm_struct *mm, *oldmm = current->mm;
+	int err;
+
+	if (!oldmm)
+		return NULL;
+
+	mm = allocate_mm();
+	if (!mm)
+		goto fail_nomem;
+
+	memcpy(mm, oldmm, sizeof(*mm));
+
+	if (!mm_init(mm))
+		goto fail_nomem;
+
+	if (init_new_context(tsk, mm))
+		goto fail_nocontext;
+
+	err = dup_mmap(mm, oldmm);
+	if (err)
+		goto free_pt;
+
+	mm->hiwater_rss = get_mm_rss(mm);
+	mm->hiwater_vm = mm->total_vm;
+
+	return mm;
+
+free_pt:
+	mmput(mm);
+
+fail_nomem:
+	return NULL;
+
+fail_nocontext:
+	/*
+	 * If init_new_context() failed, we cannot use mmput() to free the mm
+	 * because it calls destroy_context()
+	 */
+	mm_free_pgd(mm);
+	free_mm(mm);
+	return NULL;
+}
+
 static int copy_mm(unsigned long clone_flags, struct task_struct * tsk)
 {
 	struct mm_struct * mm, *oldmm;
@@ -473,43 +522,17 @@ static int copy_mm(unsigned long clone_f
 	}
 
 	retval = -ENOMEM;
-	mm = allocate_mm();
+	mm = dup_mm(tsk);
 	if (!mm)
 		goto fail_nomem;
 
-	/* Copy the current MM stuff.. */
-	memcpy(mm, oldmm, sizeof(*mm));
-	if (!mm_init(mm))
-		goto fail_nomem;
-
-	if (init_new_context(tsk,mm))
-		goto fail_nocontext;
-
-	retval = dup_mmap(mm, oldmm);
-	if (retval)
-		goto free_pt;
-
-	mm->hiwater_rss = get_mm_rss(mm);
-	mm->hiwater_vm = mm->total_vm;
-
 good_mm:
 	tsk->mm = mm;
 	tsk->active_mm = mm;
 	return 0;
 
-free_pt:
-	mmput(mm);
 fail_nomem:
 	return retval;
-
-fail_nocontext:
-	/*
-	 * If init_new_context() failed, we cannot use mmput() to free the mm
-	 * because it calls destroy_context()
-	 */
-	mm_free_pgd(mm);
-	free_mm(mm);
-	return retval;
 }
 
 static inline struct fs_struct *__copy_fs_struct(struct fs_struct *old)
@@ -1423,18 +1446,20 @@ static int unshare_sighand(unsigned long
 }
 
 /*
- * Unsharing of vm for tasks created with CLONE_VM is not supported yet
+ * Unshare vm if it is being shared
  */
 static int unshare_vm(unsigned long unshare_flags, struct mm_struct **new_mmp)
 {
 	struct mm_struct *mm = current->mm;
 
 	if ((unshare_flags & CLONE_VM) &&
-	    (mm && atomic_read(&mm->mm_users) > 1))
-		return -EINVAL;
+	    (mm && atomic_read(&mm->mm_users) > 1)) {
+		*new_mmp = dup_mm(current);
+		if (!*new_mmp)
+			return -ENOMEM;
+	}
 
 	return 0;
-
 }
 
 /*



linux-2.6-unshare-6.patch:
 fork.c |   81 ++++++++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 51 insertions(+), 30 deletions(-)

--- NEW FILE linux-2.6-unshare-6.patch ---
>From janak at us.ibm.com Thu Jan 12 04:15:33 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:15:33 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts4-0004P6-Rd for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:15:33 +0000
Received: from e1.ny.us.ibm.com ([32.97.182.141]) by
	pentafluge.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts2-0001mm-GZ for dwmw2 at infradead.org; Thu, 12 Jan 2006 04:15:32 +0000
Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com
	[9.56.227.234]) by e1.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FSZ2019328 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:28 -0500
Received: from d01av03.pok.ibm.com (d01av03.pok.ibm.com [9.56.224.217]) by
	d01relay02.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FTYs133286
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:29 -0500
Received: from d01av03.pok.ibm.com (loopback [127.0.0.1]) by
	d01av03.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FTxR008567 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:29 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av03.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FRYC008536; Wed, 11 Jan 2006 23:15:27 -0500
Subject: [PATCH -mm 6/10] unshare system call -v5 : unshare files
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137039003.7488.214.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:54 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on pentafluge.infradead.org
	summary: Content analysis details:   (0.4 points, 5.0 required) pts rule
	name              description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 6/10] unshare system call: allow unsharing of files

If the file descriptor structure is being shared, allocate a new one and
copy information from the current, shared, structure.

Changes since -v4 of this patch submitted on 12/13/05:
	- Fixed intermittent oops encountered when starting wine applications.
	  Instead of passing current task structure to dup_fd and obtaining
	  files pointer from it, pass the old files pointer because
	  copy_files, when called from unshare_files, clears the
	  current->files pointer.

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 fork.c |   81 ++++++++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 51 insertions(+), 30 deletions(-)

diff -Naurp 2.6.15-mm3+unsh-vm/kernel/fork.c 2.6.15-mm3+unsh-fd/kernel/fork.c
--- 2.6.15-mm3+unsh-vm/kernel/fork.c	2006-01-12 00:47:33.000000000 +0000
+++ 2.6.15-mm3+unsh-fd/kernel/fork.c	2006-01-12 00:56:53.000000000 +0000
@@ -620,32 +620,17 @@ out:
 	return newf;
 }
 
-static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
+/*
+ * Allocate a new files structure and copy contents from the
+ * passed in files structure.
+ */
+static struct files_struct *dup_fd(struct files_struct *oldf, int *errorp)
 {
-	struct files_struct *oldf, *newf;
+	struct files_struct *newf;
 	struct file **old_fds, **new_fds;
-	int open_files, size, i, error = 0, expand;
+	int open_files, size, i, expand;
 	struct fdtable *old_fdt, *new_fdt;
 
-	/*
-	 * A background process may not have any files ...
-	 */
-	oldf = current->files;
-	if (!oldf)
-		goto out;
-
-	if (clone_flags & CLONE_FILES) {
-		atomic_inc(&oldf->count);
-		goto out;
-	}
-
-	/*
-	 * Note: we may be using current for both targets (See exec.c)
-	 * This works because we cache current->files (old) as oldf. Don't
-	 * break this.
-	 */
-	tsk->files = NULL;
-	error = -ENOMEM;
 	newf = alloc_files();
 	if (!newf)
 		goto out;
@@ -674,9 +659,9 @@ static int copy_files(unsigned long clon
 	if (expand) {
 		spin_unlock(&oldf->file_lock);
 		spin_lock(&newf->file_lock);
-		error = expand_files(newf, open_files-1);
+		*errorp = expand_files(newf, open_files-1);
 		spin_unlock(&newf->file_lock);
-		if (error < 0)
+		if (*errorp < 0)
 			goto out_release;
 		new_fdt = files_fdtable(newf);
 		/*
@@ -725,10 +710,8 @@ static int copy_files(unsigned long clon
 		memset(&new_fdt->close_on_exec->fds_bits[start], 0, left);
 	}
 
-	tsk->files = newf;
-	error = 0;
 out:
-	return error;
+	return newf;
 
 out_release:
 	free_fdset (new_fdt->close_on_exec, new_fdt->max_fdset);
@@ -738,6 +721,40 @@ out_release:
 	goto out;
 }
 
+static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
+{
+	struct files_struct *oldf, *newf;
+	int error = 0;
+
+	/*
+	 * A background process may not have any files ...
+	 */
+	oldf = current->files;
+	if (!oldf)
+		goto out;
+
+	if (clone_flags & CLONE_FILES) {
+		atomic_inc(&oldf->count);
+		goto out;
+	}
+
+	/*
+	 * Note: we may be using current for both targets (See exec.c)
+	 * This works because we cache current->files (old) as oldf. Don't
+	 * break this.
+	 */
+	tsk->files = NULL;
+	error = -ENOMEM;
+	newf = dup_fd(oldf, &error);
+	if (!newf)
+		goto out;
+
+	tsk->files = newf;
+	error = 0;
+out:
+	return error;
+}
+
 /*
  *	Helper to unshare the files of the current task.
  *	We don't want to expose copy_files internals to
@@ -1463,15 +1480,19 @@ static int unshare_vm(unsigned long unsh
 }
 
 /*
- * Unsharing of files for tasks created with CLONE_FILES is not supported yet
+ * Unshare file descriptor table if it is being shared
  */
 static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
 {
 	struct files_struct *fd = current->files;
+	int error = 0;
 
 	if ((unshare_flags & CLONE_FILES) &&
-	    (fd && atomic_read(&fd->count) > 1))
-		return -EINVAL;
+	    (fd && atomic_read(&fd->count) > 1)) {
+		*new_fdp = dup_fd(fd, &error);
+		if (!*new_fdp)
+			return error;
+	}
 
 	return 0;
 }



linux-2.6-unshare-7.patch:
 arch/i386/kernel/syscall_table.S |    1 +
 include/asm-i386/unistd.h        |    3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

--- NEW FILE linux-2.6-unshare-7.patch ---
>From janak at us.ibm.com Thu Jan 12 04:15:34 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:15:34 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts6-0004PB-GB for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:15:34 +0000
Received: from e5.ny.us.ibm.com ([32.97.182.145]) by
	pentafluge.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts4-0001mp-H8 for dwmw2 at infradead.org; Thu, 12 Jan 2006 04:15:33 +0000
Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com
	[9.56.227.234]) by e5.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FVHr013497 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:31 -0500
Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by
	d01relay02.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FVYs113402
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:31 -0500
Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by
	d01av04.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FULG026136 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:31 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av04.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FTOp026107; Wed, 11 Jan 2006 23:15:29 -0500
Subject: [PATCH -mm 7/10] unshare system call -v5 : system call
	registration for i386
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137039006.7488.216.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:56 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on pentafluge.infradead.org
	summary: Content analysis details:   (0.4 points, 5.0 required) pts rule
	name              description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 7/10] unshare system call: system call registration for i386

Registers system call for the i386 architecture.

Changes since -v4 of this patch submitted on 12/13/05:
	- Forward ported to 2.6.15-mm3 which modified the syscall number.

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 arch/i386/kernel/syscall_table.S |    1 +
 include/asm-i386/unistd.h        |    3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff -Naurp 2.6.15-mm3/arch/i386/kernel/syscall_table.S 2.6.15-mm3+unsh-i386/arch/i386/kernel/syscall_table.S
--- 2.6.15-mm3/arch/i386/kernel/syscall_table.S	2006-01-11 20:21:43.000000000 +0000
+++ 2.6.15-mm3+unsh-i386/arch/i386/kernel/syscall_table.S	2006-01-12 00:32:53.000000000 +0000
@@ -301,3 +301,4 @@ ENTRY(sys_call_table)
 	.long sys_inotify_init
 	.long sys_inotify_add_watch
 	.long sys_inotify_rm_watch
+	.long sys_unshare
diff -Naurp 2.6.15-mm3/include/asm-i386/unistd.h 2.6.15-mm3+unsh-i386/include/asm-i386/unistd.h
--- 2.6.15-mm3/include/asm-i386/unistd.h	2006-01-11 20:22:16.000000000 +0000
+++ 2.6.15-mm3+unsh-i386/include/asm-i386/unistd.h	2006-01-12 00:33:21.000000000 +0000
@@ -313,8 +313,9 @@
 #define __NR_inotify_init	291
 #define __NR_inotify_add_watch	292
 #define __NR_inotify_rm_watch	293
+#define __NR_unshare		294
 
-#define NR_syscalls 294
+#define NR_syscalls 295
 
 /*
  * user-visible error numbers are in the range -1 - -128: see



linux-2.6-unshare-8.patch:
 arch/powerpc/kernel/systbl.S |    1 +
 include/asm-powerpc/unistd.h |    3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

--- NEW FILE linux-2.6-unshare-8.patch ---
>From janak at us.ibm.com Thu Jan 12 04:16:00 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:16:00 +0000
Received: from canuck.infradead.org ([2001:8b0:10b:4::1]) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwtsU-0004Q8-PH for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:16:00 +0000
Received: from e3.ny.us.ibm.com ([32.97.182.143]) by canuck.infradead.org
	with esmtps (Exim 4.54 #1 (Red Hat Linux)) id 1EwtsB-0000Cv-Ns for
	dwmw2 at infradead.org; Wed, 11 Jan 2006 23:15:49 -0500
Received: from d01relay02.pok.ibm.com (d01relay02.pok.ibm.com
	[9.56.227.234]) by e3.ny.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FXvn012503 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:33 -0500
Received: from d01av04.pok.ibm.com (d01av04.pok.ibm.com [9.56.224.64]) by
	d01relay02.pok.ibm.com (8.12.10/NCO/VERS6.8) with ESMTP id k0C4FXYs118788
	for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:33 -0500
Received: from d01av04.pok.ibm.com (loopback [127.0.0.1]) by
	d01av04.pok.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FWix026174 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:32 -0500
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d01av04.pok.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FVoB026147; Wed, 11 Jan 2006 23:15:31 -0500
Subject: [PATCH -mm 8/10] unshare system call -v5 : system call
	registration for powerpc
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137039008.7488.218.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:10:58 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on canuck.infradead.org summary:
	Content analysis details:   (0.4 points, 5.0 required) pts rule name       
	      description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 8/10] unshare system call: system call registration for powerpc

Registers system call for the powerpc architecture.

Changes since -v4 of this patch submitted on 12/13/05:
        - Forward ported to 2.6.15-mm3 which modified the syscall number.

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 arch/powerpc/kernel/systbl.S |    1 +
 include/asm-powerpc/unistd.h |    3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff -Naurp 2.6.15-mm3/arch/powerpc/kernel/systbl.S 2.6.15-mm3+unsh-powerpc/arch/powerpc/kernel/systbl.S
--- 2.6.15-mm3/arch/powerpc/kernel/systbl.S	2006-01-11 20:21:45.000000000 +0000
+++ 2.6.15-mm3+unsh-powerpc/arch/powerpc/kernel/systbl.S	2006-01-12 00:36:51.000000000 +0000
@@ -321,1 +321,2 @@ SYSCALL(inotify_add_watch)
 SYSCALL(inotify_rm_watch)
+SYSCALL(unshare)
diff -Naurp 2.6.15-mm3/include/asm-powerpc/unistd.h 2.6.15-mm3+unsh-powerpc/include/asm-powerpc/unistd.h
--- 2.6.15-mm3/include/asm-powerpc/unistd.h	2006-01-11 20:22:17.000000000 +0000
+++ 2.6.15-mm3+unsh-powerpc/include/asm-powerpc/unistd.h	2006-01-12 00:37:40.000000000 +0000
@@ -298,8 +298,9 @@
 #define __NR_inotify_init	275
 #define __NR_inotify_add_watch	276
 #define __NR_inotify_rm_watch	277
+#define __NR_unshare		278
 
-#define __NR_syscalls		278
+#define __NR_syscalls		279
 
 #ifdef __KERNEL__
 #define __NR__exit __NR_exit



linux-2.6-unshare-9.patch:
 misc.S |    1 +
 1 files changed, 1 insertion(+)

--- NEW FILE linux-2.6-unshare-9.patch ---
>From janak at us.ibm.com Thu Jan 12 04:15:40 2006
Return-path: <janak at us.ibm.com>
Envelope-to: dwmw2 at baythorne.infradead.org
Delivery-date: Thu, 12 Jan 2006 04:15:40 +0000
Received: from [2002:d592:9a28::1] (helo=pentafluge.infradead.org) by
	baythorne.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1EwtsB-0004PG-Rf for dwmw2 at baythorne.infradead.org; Thu, 12 Jan 2006
	04:15:40 +0000
Received: from e36.co.us.ibm.com ([32.97.110.154]) by
	pentafluge.infradead.org with esmtps (Exim 4.54 #1 (Red Hat Linux)) id
	1Ewts9-0001mw-SP for dwmw2 at infradead.org; Thu, 12 Jan 2006 04:15:39 +0000
Received: from westrelay02.boulder.ibm.com (westrelay02.boulder.ibm.com
	[9.17.195.11]) by e36.co.us.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4Fa0C030711 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006 23:15:36 -0500
Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com
	[9.17.195.168]) by westrelay02.boulder.ibm.com (8.12.10/NCO/VERS6.8) with
	ESMTP id k0C4E7Cb246748 for <dwmw2 at infradead.org>; Wed, 11 Jan 2006
	21:14:07 -0700
Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by
	d03av02.boulder.ibm.com (8.12.11/8.13.3) with ESMTP id k0C4FZE0024290 for
	<dwmw2 at infradead.org>; Wed, 11 Jan 2006 21:15:35 -0700
Received: from sig-9-65-207-107.mts.ibm.com (sig-9-65-207-107.mts.ibm.com
	[9.65.207.107]) by d03av02.boulder.ibm.com (8.12.11/8.12.11) with ESMTP id
	k0C4FXs4024235; Wed, 11 Jan 2006 21:15:33 -0700
Subject: [PATCH -mm 9/10] unshare system call -v5 : system call
	registration for ppc
From: JANAK DESAI <janak at us.ibm.com>
Reply-To: janak at us.ibm.com
To: akpm at osdl.org, viro at ftp.linux.org.uk, dwmw2 at infradead.org
Cc: chrisw at sous-sol.org, jamie at shareable.org, serue at us.ibm.com, sds at tycho.nsa.gov, sgrubb at redhat.com, ebiederm at xmission.com, janak at us.ibm.com, linux-kernel at vger.kernel.org
Content-Type: text/plain
Message-Id: <1137039010.7488.220.camel at hobbes.atlanta.ibm.com>
Mime-Version: 1.0
X-Mailer: Ximian Evolution 1.4.5 (1.4.5-9) 
Date: Wed, 11 Jan 2006 23:11:00 -0500
X-Spam-Score: 0.4 (/)
X-Spam-Report: SpamAssassin version 3.0.4 on pentafluge.infradead.org
	summary: Content analysis details:   (0.4 points, 5.0 required) pts rule
	name              description ---- ----------------------
	-------------------------------------------------- 0.4 DNS_FROM_RFC_ABUSE  
	  RBL: Envelope sender in abuse.rfc-ignorant.org
X-Evolution-Source: imap://dwmw2@pentafluge.infradead.org/
Content-Transfer-Encoding: 8bit

[PATCH -mm 9/10] unshare system call: system call registration for ppc

Registers system call for the ppc architecture.

Changes since -v4 of this patch submitted on 12/13/05:
        - Forward ported to 2.6.15-mm3 which modified the syscall number.

Signed-off-by: Janak Desai <janak at us.ibm.com>

---

 misc.S |    1 +
 1 files changed, 1 insertion(+)

diff -Naurp 2.6.15-mm3/arch/ppc/kernel/misc.S 2.6.15-mm3+unsh-ppc/arch/ppc/kernel/misc.S
--- 2.6.15-mm3/arch/ppc/kernel/misc.S	2006-01-11 20:21:46.000000000 +0000
+++ 2.6.15-mm3+unsh-ppc/arch/ppc/kernel/misc.S	2006-01-12 00:44:16.000000000 +0000
@@ -1403,3 +1403,4 @@ _GLOBAL(sys_call_table)
 	.long sys_inotify_init		/* 275 */
 	.long sys_inotify_add_watch
 	.long sys_inotify_rm_watch
+	.long sys_unshare




Index: kernel-2.6.spec
===================================================================
RCS file: /cvs/dist/rpms/kernel/devel/kernel-2.6.spec,v
retrieving revision 1.1826.2.10
retrieving revision 1.1826.2.10.2.1
diff -u -r1.1826.2.10 -r1.1826.2.10.2.1
--- kernel-2.6.spec	11 Jan 2006 22:13:27 -0000	1.1826.2.10
+++ kernel-2.6.spec	13 Jan 2006 17:17:15 -0000	1.1826.2.10.2.1
@@ -20,7 +20,7 @@
 %define sublevel 15
 %define kversion 2.6.%{sublevel}
 %define rpmversion 2.6.%{sublevel}
-%define rhbsys  %([ -r /etc/beehive-root -o -n "%{?__beehive_build}" ] && echo || echo .`whoami`)
+%define rhbsys  ,lspp.6
 %define release %(R="$Revision$"; RR="${R##: }"; echo ${RR%%?})_FC5%{rhbsys}
 %define signmodules 0
 %define make_target bzImage
@@ -403,6 +403,24 @@
 Patch10003: linux-2.6-gcc41.patch
 Patch10004: linux-2.6-compile-fixes.patch
 
+Patch20000: linux-2.6-audit-git.patch
+Patch20001: linux-2.6-unshare-1.patch
+Patch20002: linux-2.6-unshare-2.patch
+Patch20003: linux-2.6-unshare-3.patch
+Patch20004: linux-2.6-unshare-4.patch
+Patch20005: linux-2.6-unshare-5.patch
+Patch20006: linux-2.6-unshare-6.patch
+Patch20007: linux-2.6-unshare-7.patch
+Patch20008: linux-2.6-unshare-8.patch
+Patch20009: linux-2.6-unshare-9.patch
+Patch20010: linux-2.6-unshare-10.patch
+
+Patch20020: linux-2.6-audit-string-1.patch
+Patch20021: linux-2.6-audit-string-2.patch
+Patch20022: linux-2.6-audit-promisc.patch
+Patch20023: linux-2.6-audit-tty.patch
+Patch20024: linux-2.6-audit-rule-log.patch
+
 # END OF PATCH DEFINITIONS
 
 BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root
@@ -939,6 +957,23 @@
 %patch10003 -p1
 #%patch10004 -p1
 
+%patch20000 -p1
+%patch20001 -p1
+%patch20002 -p1
+%patch20003 -p1
+%patch20004 -p1
+%patch20005 -p1
+%patch20006 -p1
+%patch20007 -p1
+%patch20008 -p1
+%patch20009 -p1
+%patch20010 -p1
+
+%patch20020 -p1
+%patch20021 -p1
+%patch20022 -p1
+%patch20023 -p1
+%patch20024 -p1
 
 # END OF PATCH APPLICATIONS
 




More information about the fedora-cvs-commits mailing list