ia64/xen-unstable

changeset 7469:f31494465fb0

Merged.
author emellor@leeni.uk.xensource.com
date Fri Oct 21 12:07:14 2005 +0100 (2005-10-21)
parents 19af31a59537 c3a0f492644c
children d8b35f72a587
files
line diff
     1.1 --- a/patches/linux-2.6.12/2.6.12.5.patch	Fri Oct 21 12:06:17 2005 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,1614 +0,0 @@
     1.4 -diff --git a/Makefile b/Makefile
     1.5 ---- a/Makefile
     1.6 -+++ b/Makefile
     1.7 -@@ -1,7 +1,7 @@
     1.8 - VERSION = 2
     1.9 - PATCHLEVEL = 6
    1.10 - SUBLEVEL = 12
    1.11 --EXTRAVERSION =
    1.12 -+EXTRAVERSION = .5
    1.13 - NAME=Woozy Numbat
    1.14 - 
    1.15 - # *DOCUMENTATION*
    1.16 -@@ -1149,7 +1149,7 @@ endif # KBUILD_EXTMOD
    1.17 - #(which is the most common case IMHO) to avoid unneeded clutter in the big tags file.
    1.18 - #Adding $(srctree) adds about 20M on i386 to the size of the output file!
    1.19 - 
    1.20 --ifeq ($(KBUILD_OUTPUT),)
    1.21 -+ifeq ($(src),$(obj))
    1.22 - __srctree =
    1.23 - else
    1.24 - __srctree = $(srctree)/
    1.25 -diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
    1.26 ---- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
    1.27 -+++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
    1.28 -@@ -44,7 +44,7 @@
    1.29 - 
    1.30 - #define PFX "powernow-k8: "
    1.31 - #define BFX PFX "BIOS error: "
    1.32 --#define VERSION "version 1.40.2"
    1.33 -+#define VERSION "version 1.40.4"
    1.34 - #include "powernow-k8.h"
    1.35 - 
    1.36 - /* serialize freq changes  */
    1.37 -@@ -978,7 +978,7 @@ static int __init powernowk8_cpu_init(st
    1.38 - {
    1.39 - 	struct powernow_k8_data *data;
    1.40 - 	cpumask_t oldmask = CPU_MASK_ALL;
    1.41 --	int rc;
    1.42 -+	int rc, i;
    1.43 - 
    1.44 - 	if (!check_supported_cpu(pol->cpu))
    1.45 - 		return -ENODEV;
    1.46 -@@ -1064,7 +1064,9 @@ static int __init powernowk8_cpu_init(st
    1.47 - 	printk("cpu_init done, current fid 0x%x, vid 0x%x\n",
    1.48 - 	       data->currfid, data->currvid);
    1.49 - 
    1.50 --	powernow_data[pol->cpu] = data;
    1.51 -+	for_each_cpu_mask(i, cpu_core_map[pol->cpu]) {
    1.52 -+		powernow_data[i] = data;
    1.53 -+	}
    1.54 - 
    1.55 - 	return 0;
    1.56 - 
    1.57 -diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
    1.58 ---- a/arch/i386/kernel/process.c
    1.59 -+++ b/arch/i386/kernel/process.c
    1.60 -@@ -827,6 +827,8 @@ asmlinkage int sys_get_thread_area(struc
    1.61 - 	if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
    1.62 - 		return -EINVAL;
    1.63 - 
    1.64 -+	memset(&info, 0, sizeof(info));
    1.65 -+
    1.66 - 	desc = current->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
    1.67 - 
    1.68 - 	info.entry_number = idx;
    1.69 -diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
    1.70 ---- a/arch/ia64/kernel/ptrace.c
    1.71 -+++ b/arch/ia64/kernel/ptrace.c
    1.72 -@@ -945,6 +945,13 @@ access_uarea (struct task_struct *child,
    1.73 - 				*data = (pt->cr_ipsr & IPSR_MASK);
    1.74 - 			return 0;
    1.75 - 
    1.76 -+		      case PT_AR_RSC:
    1.77 -+			if (write_access)
    1.78 -+				pt->ar_rsc = *data | (3 << 2); /* force PL3 */
    1.79 -+			else
    1.80 -+				*data = pt->ar_rsc;
    1.81 -+			return 0;
    1.82 -+
    1.83 - 		      case PT_AR_RNAT:
    1.84 - 			urbs_end = ia64_get_user_rbs_end(child, pt, NULL);
    1.85 - 			rnat_addr = (long) ia64_rse_rnat_addr((long *)
    1.86 -@@ -996,9 +1003,6 @@ access_uarea (struct task_struct *child,
    1.87 - 		      case PT_AR_BSPSTORE:
    1.88 - 			ptr = pt_reg_addr(pt, ar_bspstore);
    1.89 - 			break;
    1.90 --		      case PT_AR_RSC:
    1.91 --			ptr = pt_reg_addr(pt, ar_rsc);
    1.92 --			break;
    1.93 - 		      case PT_AR_UNAT:
    1.94 - 			ptr = pt_reg_addr(pt, ar_unat);
    1.95 - 			break;
    1.96 -@@ -1234,7 +1238,7 @@ ptrace_getregs (struct task_struct *chil
    1.97 - static long
    1.98 - ptrace_setregs (struct task_struct *child, struct pt_all_user_regs __user *ppr)
    1.99 - {
   1.100 --	unsigned long psr, ec, lc, rnat, bsp, cfm, nat_bits, val = 0;
   1.101 -+	unsigned long psr, rsc, ec, lc, rnat, bsp, cfm, nat_bits, val = 0;
   1.102 - 	struct unw_frame_info info;
   1.103 - 	struct switch_stack *sw;
   1.104 - 	struct ia64_fpreg fpval;
   1.105 -@@ -1267,7 +1271,7 @@ ptrace_setregs (struct task_struct *chil
   1.106 - 	/* app regs */
   1.107 - 
   1.108 - 	retval |= __get_user(pt->ar_pfs, &ppr->ar[PT_AUR_PFS]);
   1.109 --	retval |= __get_user(pt->ar_rsc, &ppr->ar[PT_AUR_RSC]);
   1.110 -+	retval |= __get_user(rsc, &ppr->ar[PT_AUR_RSC]);
   1.111 - 	retval |= __get_user(pt->ar_bspstore, &ppr->ar[PT_AUR_BSPSTORE]);
   1.112 - 	retval |= __get_user(pt->ar_unat, &ppr->ar[PT_AUR_UNAT]);
   1.113 - 	retval |= __get_user(pt->ar_ccv, &ppr->ar[PT_AUR_CCV]);
   1.114 -@@ -1365,6 +1369,7 @@ ptrace_setregs (struct task_struct *chil
   1.115 - 	retval |= __get_user(nat_bits, &ppr->nat);
   1.116 - 
   1.117 - 	retval |= access_uarea(child, PT_CR_IPSR, &psr, 1);
   1.118 -+	retval |= access_uarea(child, PT_AR_RSC, &rsc, 1);
   1.119 - 	retval |= access_uarea(child, PT_AR_EC, &ec, 1);
   1.120 - 	retval |= access_uarea(child, PT_AR_LC, &lc, 1);
   1.121 - 	retval |= access_uarea(child, PT_AR_RNAT, &rnat, 1);
   1.122 -diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
   1.123 ---- a/arch/ia64/kernel/signal.c
   1.124 -+++ b/arch/ia64/kernel/signal.c
   1.125 -@@ -94,7 +94,7 @@ sys_sigaltstack (const stack_t __user *u
   1.126 - static long
   1.127 - restore_sigcontext (struct sigcontext __user *sc, struct sigscratch *scr)
   1.128 - {
   1.129 --	unsigned long ip, flags, nat, um, cfm;
   1.130 -+	unsigned long ip, flags, nat, um, cfm, rsc;
   1.131 - 	long err;
   1.132 - 
   1.133 - 	/* Always make any pending restarted system calls return -EINTR */
   1.134 -@@ -106,7 +106,7 @@ restore_sigcontext (struct sigcontext __
   1.135 - 	err |= __get_user(ip, &sc->sc_ip);			/* instruction pointer */
   1.136 - 	err |= __get_user(cfm, &sc->sc_cfm);
   1.137 - 	err |= __get_user(um, &sc->sc_um);			/* user mask */
   1.138 --	err |= __get_user(scr->pt.ar_rsc, &sc->sc_ar_rsc);
   1.139 -+	err |= __get_user(rsc, &sc->sc_ar_rsc);
   1.140 - 	err |= __get_user(scr->pt.ar_unat, &sc->sc_ar_unat);
   1.141 - 	err |= __get_user(scr->pt.ar_fpsr, &sc->sc_ar_fpsr);
   1.142 - 	err |= __get_user(scr->pt.ar_pfs, &sc->sc_ar_pfs);
   1.143 -@@ -119,6 +119,7 @@ restore_sigcontext (struct sigcontext __
   1.144 - 	err |= __copy_from_user(&scr->pt.r15, &sc->sc_gr[15], 8);	/* r15 */
   1.145 - 
   1.146 - 	scr->pt.cr_ifs = cfm | (1UL << 63);
   1.147 -+	scr->pt.ar_rsc = rsc | (3 << 2); /* force PL3 */
   1.148 - 
   1.149 - 	/* establish new instruction pointer: */
   1.150 - 	scr->pt.cr_iip = ip & ~0x3UL;
   1.151 -diff --git a/arch/ppc/kernel/time.c b/arch/ppc/kernel/time.c
   1.152 ---- a/arch/ppc/kernel/time.c
   1.153 -+++ b/arch/ppc/kernel/time.c
   1.154 -@@ -89,6 +89,9 @@ unsigned long tb_to_ns_scale;
   1.155 - 
   1.156 - extern unsigned long wall_jiffies;
   1.157 - 
   1.158 -+/* used for timezone offset */
   1.159 -+static long timezone_offset;
   1.160 -+
   1.161 - DEFINE_SPINLOCK(rtc_lock);
   1.162 - 
   1.163 - EXPORT_SYMBOL(rtc_lock);
   1.164 -@@ -170,7 +173,7 @@ void timer_interrupt(struct pt_regs * re
   1.165 - 		     xtime.tv_sec - last_rtc_update >= 659 &&
   1.166 - 		     abs((xtime.tv_nsec / 1000) - (1000000-1000000/HZ)) < 500000/HZ &&
   1.167 - 		     jiffies - wall_jiffies == 1) {
   1.168 --		  	if (ppc_md.set_rtc_time(xtime.tv_sec+1 + time_offset) == 0)
   1.169 -+		  	if (ppc_md.set_rtc_time(xtime.tv_sec+1 + timezone_offset) == 0)
   1.170 - 				last_rtc_update = xtime.tv_sec+1;
   1.171 - 			else
   1.172 - 				/* Try again one minute later */
   1.173 -@@ -286,7 +289,7 @@ void __init time_init(void)
   1.174 - 	unsigned old_stamp, stamp, elapsed;
   1.175 - 
   1.176 -         if (ppc_md.time_init != NULL)
   1.177 --                time_offset = ppc_md.time_init();
   1.178 -+                timezone_offset = ppc_md.time_init();
   1.179 - 
   1.180 - 	if (__USE_RTC()) {
   1.181 - 		/* 601 processor: dec counts down by 128 every 128ns */
   1.182 -@@ -331,10 +334,10 @@ void __init time_init(void)
   1.183 - 	set_dec(tb_ticks_per_jiffy);
   1.184 - 
   1.185 - 	/* If platform provided a timezone (pmac), we correct the time */
   1.186 --        if (time_offset) {
   1.187 --		sys_tz.tz_minuteswest = -time_offset / 60;
   1.188 -+        if (timezone_offset) {
   1.189 -+		sys_tz.tz_minuteswest = -timezone_offset / 60;
   1.190 - 		sys_tz.tz_dsttime = 0;
   1.191 --		xtime.tv_sec -= time_offset;
   1.192 -+		xtime.tv_sec -= timezone_offset;
   1.193 -         }
   1.194 -         set_normalized_timespec(&wall_to_monotonic,
   1.195 -                                 -xtime.tv_sec, -xtime.tv_nsec);
   1.196 -diff --git a/arch/ppc64/boot/zlib.c b/arch/ppc64/boot/zlib.c
   1.197 ---- a/arch/ppc64/boot/zlib.c
   1.198 -+++ b/arch/ppc64/boot/zlib.c
   1.199 -@@ -1307,7 +1307,7 @@ local int huft_build(
   1.200 -   {
   1.201 -     *t = (inflate_huft *)Z_NULL;
   1.202 -     *m = 0;
   1.203 --    return Z_OK;
   1.204 -+    return Z_DATA_ERROR;
   1.205 -   }
   1.206 - 
   1.207 - 
   1.208 -@@ -1351,6 +1351,7 @@ local int huft_build(
   1.209 -     if ((j = *p++) != 0)
   1.210 -       v[x[j]++] = i;
   1.211 -   } while (++i < n);
   1.212 -+  n = x[g];			/* set n to length of v */
   1.213 - 
   1.214 - 
   1.215 -   /* Generate the Huffman codes and for each, make the table entries */
   1.216 -diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
   1.217 ---- a/arch/um/kernel/process.c
   1.218 -+++ b/arch/um/kernel/process.c
   1.219 -@@ -130,7 +130,7 @@ int start_fork_tramp(void *thread_arg, u
   1.220 - 	return(arg.pid);
   1.221 - }
   1.222 - 
   1.223 --static int ptrace_child(void)
   1.224 -+static int ptrace_child(void *arg)
   1.225 - {
   1.226 - 	int ret;
   1.227 - 	int pid = os_getpid(), ppid = getppid();
   1.228 -@@ -159,16 +159,20 @@ static int ptrace_child(void)
   1.229 - 	_exit(ret);
   1.230 - }
   1.231 - 
   1.232 --static int start_ptraced_child(void)
   1.233 -+static int start_ptraced_child(void **stack_out)
   1.234 - {
   1.235 -+	void *stack;
   1.236 -+	unsigned long sp;
   1.237 - 	int pid, n, status;
   1.238 - 	
   1.239 --	pid = fork();
   1.240 --	if(pid == 0)
   1.241 --		ptrace_child();
   1.242 --
   1.243 -+	stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
   1.244 -+		     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   1.245 -+	if(stack == MAP_FAILED)
   1.246 -+		panic("check_ptrace : mmap failed, errno = %d", errno);
   1.247 -+	sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
   1.248 -+	pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
   1.249 - 	if(pid < 0)
   1.250 --		panic("check_ptrace : fork failed, errno = %d", errno);
   1.251 -+		panic("check_ptrace : clone failed, errno = %d", errno);
   1.252 - 	CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
   1.253 - 	if(n < 0)
   1.254 - 		panic("check_ptrace : wait failed, errno = %d", errno);
   1.255 -@@ -176,6 +180,7 @@ static int start_ptraced_child(void)
   1.256 - 		panic("check_ptrace : expected SIGSTOP, got status = %d",
   1.257 - 		      status);
   1.258 - 
   1.259 -+	*stack_out = stack;
   1.260 - 	return(pid);
   1.261 - }
   1.262 - 
   1.263 -@@ -183,12 +188,12 @@ static int start_ptraced_child(void)
   1.264 -  * just avoid using sysemu, not panic, but only if SYSEMU features are broken.
   1.265 -  * So only for SYSEMU features we test mustpanic, while normal host features
   1.266 -  * must work anyway!*/
   1.267 --static int stop_ptraced_child(int pid, int exitcode, int mustexit)
   1.268 -+static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic)
   1.269 - {
   1.270 - 	int status, n, ret = 0;
   1.271 - 
   1.272 - 	if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
   1.273 --		panic("stop_ptraced_child : ptrace failed, errno = %d", errno);
   1.274 -+		panic("check_ptrace : ptrace failed, errno = %d", errno);
   1.275 - 	CATCH_EINTR(n = waitpid(pid, &status, 0));
   1.276 - 	if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
   1.277 - 		int exit_with = WEXITSTATUS(status);
   1.278 -@@ -199,13 +204,15 @@ static int stop_ptraced_child(int pid, i
   1.279 - 		printk("check_ptrace : child exited with exitcode %d, while "
   1.280 - 		      "expecting %d; status 0x%x", exit_with,
   1.281 - 		      exitcode, status);
   1.282 --		if (mustexit)
   1.283 -+		if (mustpanic)
   1.284 - 			panic("\n");
   1.285 - 		else
   1.286 - 			printk("\n");
   1.287 - 		ret = -1;
   1.288 - 	}
   1.289 - 
   1.290 -+	if(munmap(stack, PAGE_SIZE) < 0)
   1.291 -+		panic("check_ptrace : munmap failed, errno = %d", errno);
   1.292 - 	return ret;
   1.293 - }
   1.294 - 
   1.295 -@@ -227,11 +234,12 @@ __uml_setup("nosysemu", nosysemu_cmd_par
   1.296 - 
   1.297 - static void __init check_sysemu(void)
   1.298 - {
   1.299 -+	void *stack;
   1.300 - 	int pid, syscall, n, status, count=0;
   1.301 - 
   1.302 - 	printk("Checking syscall emulation patch for ptrace...");
   1.303 - 	sysemu_supported = 0;
   1.304 --	pid = start_ptraced_child();
   1.305 -+	pid = start_ptraced_child(&stack);
   1.306 - 
   1.307 - 	if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
   1.308 - 		goto fail;
   1.309 -@@ -249,7 +257,7 @@ static void __init check_sysemu(void)
   1.310 - 		panic("check_sysemu : failed to modify system "
   1.311 - 		      "call return, errno = %d", errno);
   1.312 - 
   1.313 --	if (stop_ptraced_child(pid, 0, 0) < 0)
   1.314 -+	if (stop_ptraced_child(pid, stack, 0, 0) < 0)
   1.315 - 		goto fail_stopped;
   1.316 - 
   1.317 - 	sysemu_supported = 1;
   1.318 -@@ -257,7 +265,7 @@ static void __init check_sysemu(void)
   1.319 - 	set_using_sysemu(!force_sysemu_disabled);
   1.320 - 
   1.321 - 	printk("Checking advanced syscall emulation patch for ptrace...");
   1.322 --	pid = start_ptraced_child();
   1.323 -+	pid = start_ptraced_child(&stack);
   1.324 - 	while(1){
   1.325 - 		count++;
   1.326 - 		if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
   1.327 -@@ -282,7 +290,7 @@ static void __init check_sysemu(void)
   1.328 - 			break;
   1.329 - 		}
   1.330 - 	}
   1.331 --	if (stop_ptraced_child(pid, 0, 0) < 0)
   1.332 -+	if (stop_ptraced_child(pid, stack, 0, 0) < 0)
   1.333 - 		goto fail_stopped;
   1.334 - 
   1.335 - 	sysemu_supported = 2;
   1.336 -@@ -293,17 +301,18 @@ static void __init check_sysemu(void)
   1.337 - 	return;
   1.338 - 
   1.339 - fail:
   1.340 --	stop_ptraced_child(pid, 1, 0);
   1.341 -+	stop_ptraced_child(pid, stack, 1, 0);
   1.342 - fail_stopped:
   1.343 - 	printk("missing\n");
   1.344 - }
   1.345 - 
   1.346 - void __init check_ptrace(void)
   1.347 - {
   1.348 -+	void *stack;
   1.349 - 	int pid, syscall, n, status;
   1.350 - 
   1.351 - 	printk("Checking that ptrace can change system call numbers...");
   1.352 --	pid = start_ptraced_child();
   1.353 -+	pid = start_ptraced_child(&stack);
   1.354 - 
   1.355 - 	if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
   1.356 - 		panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno);
   1.357 -@@ -330,7 +339,7 @@ void __init check_ptrace(void)
   1.358 - 			break;
   1.359 - 		}
   1.360 - 	}
   1.361 --	stop_ptraced_child(pid, 0, 1);
   1.362 -+	stop_ptraced_child(pid, stack, 0, 1);
   1.363 - 	printk("OK\n");
   1.364 - 	check_sysemu();
   1.365 - }
   1.366 -@@ -362,10 +371,11 @@ void forward_pending_sigio(int target)
   1.367 - static inline int check_skas3_ptrace_support(void)
   1.368 - {
   1.369 - 	struct ptrace_faultinfo fi;
   1.370 -+	void *stack;
   1.371 - 	int pid, n, ret = 1;
   1.372 - 
   1.373 - 	printf("Checking for the skas3 patch in the host...");
   1.374 --	pid = start_ptraced_child();
   1.375 -+	pid = start_ptraced_child(&stack);
   1.376 - 
   1.377 - 	n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
   1.378 - 	if (n < 0) {
   1.379 -@@ -380,7 +390,7 @@ static inline int check_skas3_ptrace_sup
   1.380 - 	}
   1.381 - 
   1.382 - 	init_registers(pid);
   1.383 --	stop_ptraced_child(pid, 1, 1);
   1.384 -+	stop_ptraced_child(pid, stack, 1, 1);
   1.385 - 
   1.386 - 	return(ret);
   1.387 - }
   1.388 -diff --git a/arch/x86_64/ia32/syscall32.c b/arch/x86_64/ia32/syscall32.c
   1.389 ---- a/arch/x86_64/ia32/syscall32.c
   1.390 -+++ b/arch/x86_64/ia32/syscall32.c
   1.391 -@@ -57,6 +57,7 @@ int syscall32_setup_pages(struct linux_b
   1.392 - 	int npages = (VSYSCALL32_END - VSYSCALL32_BASE) >> PAGE_SHIFT;
   1.393 - 	struct vm_area_struct *vma;
   1.394 - 	struct mm_struct *mm = current->mm;
   1.395 -+	int ret;
   1.396 - 
   1.397 - 	vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
   1.398 - 	if (!vma)
   1.399 -@@ -78,7 +79,11 @@ int syscall32_setup_pages(struct linux_b
   1.400 - 	vma->vm_mm = mm;
   1.401 - 
   1.402 - 	down_write(&mm->mmap_sem);
   1.403 --	insert_vm_struct(mm, vma);
   1.404 -+	if ((ret = insert_vm_struct(mm, vma))) {
   1.405 -+		up_write(&mm->mmap_sem);
   1.406 -+		kmem_cache_free(vm_area_cachep, vma);
   1.407 -+		return ret;
   1.408 -+	}
   1.409 - 	mm->total_vm += npages;
   1.410 - 	up_write(&mm->mmap_sem);
   1.411 - 	return 0;
   1.412 -diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c
   1.413 ---- a/arch/x86_64/kernel/setup.c
   1.414 -+++ b/arch/x86_64/kernel/setup.c
   1.415 -@@ -729,8 +729,6 @@ static void __init amd_detect_cmp(struct
   1.416 - 	int cpu = smp_processor_id();
   1.417 - 	int node = 0;
   1.418 - 	unsigned bits;
   1.419 --	if (c->x86_num_cores == 1)
   1.420 --		return;
   1.421 - 
   1.422 - 	bits = 0;
   1.423 - 	while ((1 << bits) < c->x86_num_cores)
   1.424 -diff --git a/arch/x86_64/kernel/smp.c b/arch/x86_64/kernel/smp.c
   1.425 ---- a/arch/x86_64/kernel/smp.c
   1.426 -+++ b/arch/x86_64/kernel/smp.c
   1.427 -@@ -284,6 +284,71 @@ struct call_data_struct {
   1.428 - static struct call_data_struct * call_data;
   1.429 - 
   1.430 - /*
   1.431 -+ * this function sends a 'generic call function' IPI to one other CPU
   1.432 -+ * in the system.
   1.433 -+ */
   1.434 -+static void __smp_call_function_single (int cpu, void (*func) (void *info), void *info,
   1.435 -+				int nonatomic, int wait)
   1.436 -+{
   1.437 -+	struct call_data_struct data;
   1.438 -+	int cpus = 1;
   1.439 -+
   1.440 -+	data.func = func;
   1.441 -+	data.info = info;
   1.442 -+	atomic_set(&data.started, 0);
   1.443 -+	data.wait = wait;
   1.444 -+	if (wait)
   1.445 -+		atomic_set(&data.finished, 0);
   1.446 -+
   1.447 -+	call_data = &data;
   1.448 -+	wmb();
   1.449 -+	/* Send a message to all other CPUs and wait for them to respond */
   1.450 -+	send_IPI_mask(cpumask_of_cpu(cpu), CALL_FUNCTION_VECTOR);
   1.451 -+
   1.452 -+	/* Wait for response */
   1.453 -+	while (atomic_read(&data.started) != cpus)
   1.454 -+		cpu_relax();
   1.455 -+
   1.456 -+	if (!wait)
   1.457 -+		return;
   1.458 -+
   1.459 -+	while (atomic_read(&data.finished) != cpus)
   1.460 -+		cpu_relax();
   1.461 -+}
   1.462 -+
   1.463 -+/*
   1.464 -+ * Run a function on another CPU
   1.465 -+ *  <func>	The function to run. This must be fast and non-blocking.
   1.466 -+ *  <info>	An arbitrary pointer to pass to the function.
   1.467 -+ *  <nonatomic>	Currently unused.
   1.468 -+ *  <wait>	If true, wait until function has completed on other CPUs.
   1.469 -+ *  [RETURNS]   0 on success, else a negative status code.
   1.470 -+ *
   1.471 -+ * Does not return until the remote CPU is nearly ready to execute <func>
   1.472 -+ * or is or has executed.
   1.473 -+ */
   1.474 -+
   1.475 -+int smp_call_function_single (int cpu, void (*func) (void *info), void *info, 
   1.476 -+	int nonatomic, int wait)
   1.477 -+{
   1.478 -+	
   1.479 -+	int me = get_cpu(); /* prevent preemption and reschedule on another processor */
   1.480 -+
   1.481 -+	if (cpu == me) {
   1.482 -+		printk("%s: trying to call self\n", __func__);
   1.483 -+		put_cpu();
   1.484 -+		return -EBUSY;
   1.485 -+	}
   1.486 -+	spin_lock_bh(&call_lock);
   1.487 -+
   1.488 -+	__smp_call_function_single(cpu, func,info,nonatomic,wait);	
   1.489 -+
   1.490 -+	spin_unlock_bh(&call_lock);
   1.491 -+	put_cpu();
   1.492 -+	return 0;
   1.493 -+}
   1.494 -+
   1.495 -+/*
   1.496 -  * this function sends a 'generic call function' IPI to all other CPUs
   1.497 -  * in the system.
   1.498 -  */
   1.499 -diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
   1.500 ---- a/arch/x86_64/kernel/smpboot.c
   1.501 -+++ b/arch/x86_64/kernel/smpboot.c
   1.502 -@@ -202,9 +202,6 @@ static __cpuinit void sync_master(void *
   1.503 - {
   1.504 - 	unsigned long flags, i;
   1.505 - 
   1.506 --	if (smp_processor_id() != boot_cpu_id)
   1.507 --		return;
   1.508 --
   1.509 - 	go[MASTER] = 0;
   1.510 - 
   1.511 - 	local_irq_save(flags);
   1.512 -@@ -253,7 +250,7 @@ get_delta(long *rt, long *master)
   1.513 - 	return tcenter - best_tm;
   1.514 - }
   1.515 - 
   1.516 --static __cpuinit void sync_tsc(void)
   1.517 -+static __cpuinit void sync_tsc(unsigned int master)
   1.518 - {
   1.519 - 	int i, done = 0;
   1.520 - 	long delta, adj, adjust_latency = 0;
   1.521 -@@ -267,9 +264,17 @@ static __cpuinit void sync_tsc(void)
   1.522 - 	} t[NUM_ROUNDS] __cpuinitdata;
   1.523 - #endif
   1.524 - 
   1.525 -+	printk(KERN_INFO "CPU %d: Syncing TSC to CPU %u.\n",
   1.526 -+		smp_processor_id(), master);
   1.527 -+
   1.528 - 	go[MASTER] = 1;
   1.529 - 
   1.530 --	smp_call_function(sync_master, NULL, 1, 0);
   1.531 -+	/* It is dangerous to broadcast IPI as cpus are coming up,
   1.532 -+	 * as they may not be ready to accept them.  So since
   1.533 -+	 * we only need to send the ipi to the boot cpu direct
   1.534 -+	 * the message, and avoid the race.
   1.535 -+	 */
   1.536 -+	smp_call_function_single(master, sync_master, NULL, 1, 0);
   1.537 - 
   1.538 - 	while (go[MASTER])	/* wait for master to be ready */
   1.539 - 		no_cpu_relax();
   1.540 -@@ -313,16 +318,14 @@ static __cpuinit void sync_tsc(void)
   1.541 - 	printk(KERN_INFO
   1.542 - 	       "CPU %d: synchronized TSC with CPU %u (last diff %ld cycles, "
   1.543 - 	       "maxerr %lu cycles)\n",
   1.544 --	       smp_processor_id(), boot_cpu_id, delta, rt);
   1.545 -+	       smp_processor_id(), master, delta, rt);
   1.546 - }
   1.547 - 
   1.548 - static void __cpuinit tsc_sync_wait(void)
   1.549 - {
   1.550 - 	if (notscsync || !cpu_has_tsc)
   1.551 - 		return;
   1.552 --	printk(KERN_INFO "CPU %d: Syncing TSC to CPU %u.\n", smp_processor_id(),
   1.553 --			boot_cpu_id);
   1.554 --	sync_tsc();
   1.555 -+	sync_tsc(0);
   1.556 - }
   1.557 - 
   1.558 - static __init int notscsync_setup(char *s)
   1.559 -diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
   1.560 ---- a/drivers/acpi/pci_irq.c
   1.561 -+++ b/drivers/acpi/pci_irq.c
   1.562 -@@ -433,8 +433,9 @@ acpi_pci_irq_enable (
   1.563 - 		printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI",
   1.564 - 			pci_name(dev), ('A' + pin));
   1.565 - 		/* Interrupt Line values above 0xF are forbidden */
   1.566 --		if (dev->irq >= 0 && (dev->irq <= 0xF)) {
   1.567 -+		if (dev->irq > 0 && (dev->irq <= 0xF)) {
   1.568 - 			printk(" - using IRQ %d\n", dev->irq);
   1.569 -+			acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
   1.570 - 			return_VALUE(0);
   1.571 - 		}
   1.572 - 		else {
   1.573 -diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
   1.574 ---- a/drivers/char/rocket.c
   1.575 -+++ b/drivers/char/rocket.c
   1.576 -@@ -277,7 +277,7 @@ static void rp_do_receive(struct r_port 
   1.577 - 		ToRecv = space;
   1.578 - 
   1.579 - 	if (ToRecv <= 0)
   1.580 --		return;
   1.581 -+		goto done;
   1.582 - 
   1.583 - 	/*
   1.584 - 	 * if status indicates there are errored characters in the
   1.585 -@@ -359,6 +359,7 @@ static void rp_do_receive(struct r_port 
   1.586 - 	}
   1.587 - 	/*  Push the data up to the tty layer */
   1.588 - 	ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
   1.589 -+done:
   1.590 - 	tty_ldisc_deref(ld);
   1.591 - }
   1.592 - 
   1.593 -diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
   1.594 ---- a/drivers/char/tpm/tpm.c
   1.595 -+++ b/drivers/char/tpm/tpm.c
   1.596 -@@ -32,12 +32,6 @@
   1.597 - 
   1.598 - #define	TPM_BUFSIZE			2048
   1.599 - 
   1.600 --/* PCI configuration addresses */
   1.601 --#define	PCI_GEN_PMCON_1			0xA0
   1.602 --#define	PCI_GEN1_DEC			0xE4
   1.603 --#define	PCI_LPC_EN			0xE6
   1.604 --#define	PCI_GEN2_DEC			0xEC
   1.605 --
   1.606 - static LIST_HEAD(tpm_chip_list);
   1.607 - static DEFINE_SPINLOCK(driver_lock);
   1.608 - static int dev_mask[32];
   1.609 -@@ -61,72 +55,6 @@ void tpm_time_expired(unsigned long ptr)
   1.610 - EXPORT_SYMBOL_GPL(tpm_time_expired);
   1.611 - 
   1.612 - /*
   1.613 -- * Initialize the LPC bus and enable the TPM ports
   1.614 -- */
   1.615 --int tpm_lpc_bus_init(struct pci_dev *pci_dev, u16 base)
   1.616 --{
   1.617 --	u32 lpcenable, tmp;
   1.618 --	int is_lpcm = 0;
   1.619 --
   1.620 --	switch (pci_dev->vendor) {
   1.621 --	case PCI_VENDOR_ID_INTEL:
   1.622 --		switch (pci_dev->device) {
   1.623 --		case PCI_DEVICE_ID_INTEL_82801CA_12:
   1.624 --		case PCI_DEVICE_ID_INTEL_82801DB_12:
   1.625 --			is_lpcm = 1;
   1.626 --			break;
   1.627 --		}
   1.628 --		/* init ICH (enable LPC) */
   1.629 --		pci_read_config_dword(pci_dev, PCI_GEN1_DEC, &lpcenable);
   1.630 --		lpcenable |= 0x20000000;
   1.631 --		pci_write_config_dword(pci_dev, PCI_GEN1_DEC, lpcenable);
   1.632 --
   1.633 --		if (is_lpcm) {
   1.634 --			pci_read_config_dword(pci_dev, PCI_GEN1_DEC,
   1.635 --					      &lpcenable);
   1.636 --			if ((lpcenable & 0x20000000) == 0) {
   1.637 --				dev_err(&pci_dev->dev,
   1.638 --					"cannot enable LPC\n");
   1.639 --				return -ENODEV;
   1.640 --			}
   1.641 --		}
   1.642 --
   1.643 --		/* initialize TPM registers */
   1.644 --		pci_read_config_dword(pci_dev, PCI_GEN2_DEC, &tmp);
   1.645 --
   1.646 --		if (!is_lpcm)
   1.647 --			tmp = (tmp & 0xFFFF0000) | (base & 0xFFF0);
   1.648 --		else
   1.649 --			tmp =
   1.650 --			    (tmp & 0xFFFF0000) | (base & 0xFFF0) |
   1.651 --			    0x00000001;
   1.652 --
   1.653 --		pci_write_config_dword(pci_dev, PCI_GEN2_DEC, tmp);
   1.654 --
   1.655 --		if (is_lpcm) {
   1.656 --			pci_read_config_dword(pci_dev, PCI_GEN_PMCON_1,
   1.657 --					      &tmp);
   1.658 --			tmp |= 0x00000004;	/* enable CLKRUN */
   1.659 --			pci_write_config_dword(pci_dev, PCI_GEN_PMCON_1,
   1.660 --					       tmp);
   1.661 --		}
   1.662 --		tpm_write_index(0x0D, 0x55);	/* unlock 4F */
   1.663 --		tpm_write_index(0x0A, 0x00);	/* int disable */
   1.664 --		tpm_write_index(0x08, base);	/* base addr lo */
   1.665 --		tpm_write_index(0x09, (base & 0xFF00) >> 8);	/* base addr hi */
   1.666 --		tpm_write_index(0x0D, 0xAA);	/* lock 4F */
   1.667 --		break;
   1.668 --	case PCI_VENDOR_ID_AMD:
   1.669 --		/* nothing yet */
   1.670 --		break;
   1.671 --	}
   1.672 --
   1.673 --	return 0;
   1.674 --}
   1.675 --
   1.676 --EXPORT_SYMBOL_GPL(tpm_lpc_bus_init);
   1.677 --
   1.678 --/*
   1.679 -  * Internal kernel interface to transmit TPM commands
   1.680 -  */
   1.681 - static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
   1.682 -@@ -590,10 +518,6 @@ int tpm_pm_resume(struct pci_dev *pci_de
   1.683 - 	if (chip == NULL)
   1.684 - 		return -ENODEV;
   1.685 - 
   1.686 --	spin_lock(&driver_lock);
   1.687 --	tpm_lpc_bus_init(pci_dev, chip->vendor->base);
   1.688 --	spin_unlock(&driver_lock);
   1.689 --
   1.690 - 	return 0;
   1.691 - }
   1.692 - 
   1.693 -diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
   1.694 ---- a/drivers/char/tpm/tpm.h
   1.695 -+++ b/drivers/char/tpm/tpm.h
   1.696 -@@ -79,8 +79,6 @@ static inline void tpm_write_index(int i
   1.697 - }
   1.698 - 
   1.699 - extern void tpm_time_expired(unsigned long);
   1.700 --extern int tpm_lpc_bus_init(struct pci_dev *, u16);
   1.701 --
   1.702 - extern int tpm_register_hardware(struct pci_dev *,
   1.703 - 				 struct tpm_vendor_specific *);
   1.704 - extern int tpm_open(struct inode *, struct file *);
   1.705 -diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
   1.706 ---- a/drivers/char/tpm/tpm_atmel.c
   1.707 -+++ b/drivers/char/tpm/tpm_atmel.c
   1.708 -@@ -22,7 +22,10 @@
   1.709 - #include "tpm.h"
   1.710 - 
   1.711 - /* Atmel definitions */
   1.712 --#define	TPM_ATML_BASE			0x400
   1.713 -+enum tpm_atmel_addr {
   1.714 -+	TPM_ATMEL_BASE_ADDR_LO = 0x08,
   1.715 -+	TPM_ATMEL_BASE_ADDR_HI = 0x09
   1.716 -+};
   1.717 - 
   1.718 - /* write status bits */
   1.719 - #define	ATML_STATUS_ABORT		0x01
   1.720 -@@ -127,7 +130,6 @@ static struct tpm_vendor_specific tpm_at
   1.721 - 	.cancel = tpm_atml_cancel,
   1.722 - 	.req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
   1.723 - 	.req_complete_val = ATML_STATUS_DATA_AVAIL,
   1.724 --	.base = TPM_ATML_BASE,
   1.725 - 	.miscdev = { .fops = &atmel_ops, },
   1.726 - };
   1.727 - 
   1.728 -@@ -136,14 +138,16 @@ static int __devinit tpm_atml_init(struc
   1.729 - {
   1.730 - 	u8 version[4];
   1.731 - 	int rc = 0;
   1.732 -+	int lo, hi;
   1.733 - 
   1.734 - 	if (pci_enable_device(pci_dev))
   1.735 - 		return -EIO;
   1.736 - 
   1.737 --	if (tpm_lpc_bus_init(pci_dev, TPM_ATML_BASE)) {
   1.738 --		rc = -ENODEV;
   1.739 --		goto out_err;
   1.740 --	}
   1.741 -+	lo = tpm_read_index( TPM_ATMEL_BASE_ADDR_LO );
   1.742 -+	hi = tpm_read_index( TPM_ATMEL_BASE_ADDR_HI );
   1.743 -+
   1.744 -+	tpm_atmel.base = (hi<<8)|lo;
   1.745 -+	dev_dbg( &pci_dev->dev, "Operating with base: 0x%x\n", tpm_atmel.base);
   1.746 - 
   1.747 - 	/* verify that it is an Atmel part */
   1.748 - 	if (tpm_read_index(4) != 'A' || tpm_read_index(5) != 'T'
   1.749 -diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
   1.750 ---- a/drivers/char/tpm/tpm_nsc.c
   1.751 -+++ b/drivers/char/tpm/tpm_nsc.c
   1.752 -@@ -24,6 +24,10 @@
   1.753 - /* National definitions */
   1.754 - #define	TPM_NSC_BASE			0x360
   1.755 - #define	TPM_NSC_IRQ			0x07
   1.756 -+#define	TPM_NSC_BASE0_HI		0x60
   1.757 -+#define	TPM_NSC_BASE0_LO		0x61
   1.758 -+#define	TPM_NSC_BASE1_HI		0x62
   1.759 -+#define	TPM_NSC_BASE1_LO		0x63
   1.760 - 
   1.761 - #define	NSC_LDN_INDEX			0x07
   1.762 - #define	NSC_SID_INDEX			0x20
   1.763 -@@ -234,7 +238,6 @@ static struct tpm_vendor_specific tpm_ns
   1.764 - 	.cancel = tpm_nsc_cancel,
   1.765 - 	.req_complete_mask = NSC_STATUS_OBF,
   1.766 - 	.req_complete_val = NSC_STATUS_OBF,
   1.767 --	.base = TPM_NSC_BASE,
   1.768 - 	.miscdev = { .fops = &nsc_ops, },
   1.769 - 	
   1.770 - };
   1.771 -@@ -243,15 +246,16 @@ static int __devinit tpm_nsc_init(struct
   1.772 - 				  const struct pci_device_id *pci_id)
   1.773 - {
   1.774 - 	int rc = 0;
   1.775 -+	int lo, hi;
   1.776 -+
   1.777 -+	hi = tpm_read_index(TPM_NSC_BASE0_HI);
   1.778 -+	lo = tpm_read_index(TPM_NSC_BASE0_LO);
   1.779 -+
   1.780 -+	tpm_nsc.base = (hi<<8) | lo;
   1.781 - 
   1.782 - 	if (pci_enable_device(pci_dev))
   1.783 - 		return -EIO;
   1.784 - 
   1.785 --	if (tpm_lpc_bus_init(pci_dev, TPM_NSC_BASE)) {
   1.786 --		rc = -ENODEV;
   1.787 --		goto out_err;
   1.788 --	}
   1.789 --
   1.790 - 	/* verify that it is a National part (SID) */
   1.791 - 	if (tpm_read_index(NSC_SID_INDEX) != 0xEF) {
   1.792 - 		rc = -ENODEV;
   1.793 -diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
   1.794 ---- a/drivers/char/tty_ioctl.c
   1.795 -+++ b/drivers/char/tty_ioctl.c
   1.796 -@@ -476,11 +476,11 @@ int n_tty_ioctl(struct tty_struct * tty,
   1.797 - 			ld = tty_ldisc_ref(tty);
   1.798 - 			switch (arg) {
   1.799 - 			case TCIFLUSH:
   1.800 --				if (ld->flush_buffer)
   1.801 -+				if (ld && ld->flush_buffer)
   1.802 - 					ld->flush_buffer(tty);
   1.803 - 				break;
   1.804 - 			case TCIOFLUSH:
   1.805 --				if (ld->flush_buffer)
   1.806 -+				if (ld && ld->flush_buffer)
   1.807 - 					ld->flush_buffer(tty);
   1.808 - 				/* fall through */
   1.809 - 			case TCOFLUSH:
   1.810 -diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
   1.811 ---- a/drivers/media/video/cx88/cx88-video.c
   1.812 -+++ b/drivers/media/video/cx88/cx88-video.c
   1.813 -@@ -261,7 +261,7 @@ static struct cx88_ctrl cx8800_ctls[] = 
   1.814 - 			.default_value = 0,
   1.815 - 			.type          = V4L2_CTRL_TYPE_INTEGER,
   1.816 - 		},
   1.817 --		.off                   = 0,
   1.818 -+		.off                   = 128,
   1.819 - 		.reg                   = MO_HUE,
   1.820 - 		.mask                  = 0x00ff,
   1.821 - 		.shift                 = 0,
   1.822 -diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
   1.823 ---- a/drivers/net/e1000/e1000_main.c
   1.824 -+++ b/drivers/net/e1000/e1000_main.c
   1.825 -@@ -2307,6 +2307,7 @@ e1000_xmit_frame(struct sk_buff *skb, st
   1.826 - 	tso = e1000_tso(adapter, skb);
   1.827 - 	if (tso < 0) {
   1.828 - 		dev_kfree_skb_any(skb);
   1.829 -+		spin_unlock_irqrestore(&adapter->tx_lock, flags);
   1.830 - 		return NETDEV_TX_OK;
   1.831 - 	}
   1.832 - 
   1.833 -diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
   1.834 ---- a/drivers/net/hamradio/Kconfig
   1.835 -+++ b/drivers/net/hamradio/Kconfig
   1.836 -@@ -17,7 +17,7 @@ config MKISS
   1.837 - 
   1.838 - config 6PACK
   1.839 - 	tristate "Serial port 6PACK driver"
   1.840 --	depends on AX25 && BROKEN_ON_SMP
   1.841 -+	depends on AX25
   1.842 - 	---help---
   1.843 - 	  6pack is a transmission protocol for the data exchange between your
   1.844 - 	  PC and your TNC (the Terminal Node Controller acts as a kind of
   1.845 -diff --git a/drivers/net/shaper.c b/drivers/net/shaper.c
   1.846 ---- a/drivers/net/shaper.c
   1.847 -+++ b/drivers/net/shaper.c
   1.848 -@@ -135,10 +135,8 @@ static int shaper_start_xmit(struct sk_b
   1.849 - {
   1.850 - 	struct shaper *shaper = dev->priv;
   1.851 -  	struct sk_buff *ptr;
   1.852 --   
   1.853 --	if (down_trylock(&shaper->sem))
   1.854 --		return -1;
   1.855 - 
   1.856 -+	spin_lock(&shaper->lock);
   1.857 -  	ptr=shaper->sendq.prev;
   1.858 -  	
   1.859 -  	/*
   1.860 -@@ -232,7 +230,7 @@ static int shaper_start_xmit(struct sk_b
   1.861 -                 shaper->stats.collisions++;
   1.862 -  	}
   1.863 - 	shaper_kick(shaper);
   1.864 --	up(&shaper->sem);
   1.865 -+	spin_unlock(&shaper->lock);
   1.866 -  	return 0;
   1.867 - }
   1.868 - 
   1.869 -@@ -271,11 +269,9 @@ static void shaper_timer(unsigned long d
   1.870 - {
   1.871 - 	struct shaper *shaper = (struct shaper *)data;
   1.872 - 
   1.873 --	if (!down_trylock(&shaper->sem)) {
   1.874 --		shaper_kick(shaper);
   1.875 --		up(&shaper->sem);
   1.876 --	} else
   1.877 --		mod_timer(&shaper->timer, jiffies);
   1.878 -+	spin_lock(&shaper->lock);
   1.879 -+	shaper_kick(shaper);
   1.880 -+	spin_unlock(&shaper->lock);
   1.881 - }
   1.882 - 
   1.883 - /*
   1.884 -@@ -332,21 +328,6 @@ static void shaper_kick(struct shaper *s
   1.885 - 
   1.886 - 
   1.887 - /*
   1.888 -- *	Flush the shaper queues on a closedown
   1.889 -- */
   1.890 -- 
   1.891 --static void shaper_flush(struct shaper *shaper)
   1.892 --{
   1.893 --	struct sk_buff *skb;
   1.894 --
   1.895 --	down(&shaper->sem);
   1.896 --	while((skb=skb_dequeue(&shaper->sendq))!=NULL)
   1.897 --		dev_kfree_skb(skb);
   1.898 --	shaper_kick(shaper);
   1.899 --	up(&shaper->sem);
   1.900 --}
   1.901 --
   1.902 --/*
   1.903 -  *	Bring the interface up. We just disallow this until a 
   1.904 -  *	bind.
   1.905 -  */
   1.906 -@@ -375,7 +356,15 @@ static int shaper_open(struct net_device
   1.907 - static int shaper_close(struct net_device *dev)
   1.908 - {
   1.909 - 	struct shaper *shaper=dev->priv;
   1.910 --	shaper_flush(shaper);
   1.911 -+	struct sk_buff *skb;
   1.912 -+
   1.913 -+	while ((skb = skb_dequeue(&shaper->sendq)) != NULL)
   1.914 -+		dev_kfree_skb(skb);
   1.915 -+
   1.916 -+	spin_lock_bh(&shaper->lock);
   1.917 -+	shaper_kick(shaper);
   1.918 -+	spin_unlock_bh(&shaper->lock);
   1.919 -+
   1.920 - 	del_timer_sync(&shaper->timer);
   1.921 - 	return 0;
   1.922 - }
   1.923 -@@ -576,6 +565,7 @@ static void shaper_init_priv(struct net_
   1.924 - 	init_timer(&sh->timer);
   1.925 - 	sh->timer.function=shaper_timer;
   1.926 - 	sh->timer.data=(unsigned long)sh;
   1.927 -+	spin_lock_init(&sh->lock);
   1.928 - }
   1.929 - 
   1.930 - /*
   1.931 -diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
   1.932 ---- a/drivers/pci/pci-driver.c
   1.933 -+++ b/drivers/pci/pci-driver.c
   1.934 -@@ -396,7 +396,7 @@ int pci_register_driver(struct pci_drive
   1.935 - 	/* FIXME, once all of the existing PCI drivers have been fixed to set
   1.936 - 	 * the pci shutdown function, this test can go away. */
   1.937 - 	if (!drv->driver.shutdown)
   1.938 --		drv->driver.shutdown = pci_device_shutdown,
   1.939 -+		drv->driver.shutdown = pci_device_shutdown;
   1.940 - 	drv->driver.owner = drv->owner;
   1.941 - 	drv->driver.kobj.ktype = &pci_driver_kobj_type;
   1.942 - 	pci_init_dynids(&drv->dynids);
   1.943 -diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
   1.944 ---- a/drivers/scsi/qla2xxx/qla_init.c
   1.945 -+++ b/drivers/scsi/qla2xxx/qla_init.c
   1.946 -@@ -1914,9 +1914,11 @@ qla2x00_reg_remote_port(scsi_qla_host_t 
   1.947 - 		rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
   1.948 - 
   1.949 - 	fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
   1.950 --	if (!rport)
   1.951 -+	if (!rport) {
   1.952 - 		qla_printk(KERN_WARNING, ha,
   1.953 - 		    "Unable to allocate fc remote port!\n");
   1.954 -+		return;
   1.955 -+	}
   1.956 - 
   1.957 - 	if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS)
   1.958 - 		fcport->os_target_id = rport->scsi_target_id;
   1.959 -diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
   1.960 ---- a/drivers/scsi/qla2xxx/qla_os.c
   1.961 -+++ b/drivers/scsi/qla2xxx/qla_os.c
   1.962 -@@ -1150,7 +1150,7 @@ iospace_error_exit:
   1.963 -  */
   1.964 - int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
   1.965 - {
   1.966 --	int	ret;
   1.967 -+	int	ret = -ENODEV;
   1.968 - 	device_reg_t __iomem *reg;
   1.969 - 	struct Scsi_Host *host;
   1.970 - 	scsi_qla_host_t *ha;
   1.971 -@@ -1161,7 +1161,7 @@ int qla2x00_probe_one(struct pci_dev *pd
   1.972 - 	fc_port_t *fcport;
   1.973 - 
   1.974 - 	if (pci_enable_device(pdev))
   1.975 --		return -1;
   1.976 -+		goto probe_out;
   1.977 - 
   1.978 - 	host = scsi_host_alloc(&qla2x00_driver_template,
   1.979 - 	    sizeof(scsi_qla_host_t));
   1.980 -@@ -1183,9 +1183,8 @@ int qla2x00_probe_one(struct pci_dev *pd
   1.981 - 
   1.982 - 	/* Configure PCI I/O space */
   1.983 - 	ret = qla2x00_iospace_config(ha);
   1.984 --	if (ret != 0) {
   1.985 --		goto probe_alloc_failed;
   1.986 --	}
   1.987 -+	if (ret)
   1.988 -+		goto probe_failed;
   1.989 - 
   1.990 - 	/* Sanitize the information from PCI BIOS. */
   1.991 - 	host->irq = pdev->irq;
   1.992 -@@ -1258,23 +1257,10 @@ int qla2x00_probe_one(struct pci_dev *pd
   1.993 - 		qla_printk(KERN_WARNING, ha,
   1.994 - 		    "[ERROR] Failed to allocate memory for adapter\n");
   1.995 - 
   1.996 --		goto probe_alloc_failed;
   1.997 -+		ret = -ENOMEM;
   1.998 -+		goto probe_failed;
   1.999 - 	}
  1.1000 - 
  1.1001 --	pci_set_drvdata(pdev, ha);
  1.1002 --	host->this_id = 255;
  1.1003 --	host->cmd_per_lun = 3;
  1.1004 --	host->unique_id = ha->instance;
  1.1005 --	host->max_cmd_len = MAX_CMDSZ;
  1.1006 --	host->max_channel = ha->ports - 1;
  1.1007 --	host->max_id = ha->max_targets;
  1.1008 --	host->max_lun = ha->max_luns;
  1.1009 --	host->transportt = qla2xxx_transport_template;
  1.1010 --	if (scsi_add_host(host, &pdev->dev))
  1.1011 --		goto probe_alloc_failed;
  1.1012 --
  1.1013 --	qla2x00_alloc_sysfs_attr(ha);
  1.1014 --
  1.1015 - 	if (qla2x00_initialize_adapter(ha) &&
  1.1016 - 	    !(ha->device_flags & DFLG_NO_CABLE)) {
  1.1017 - 
  1.1018 -@@ -1285,11 +1271,10 @@ int qla2x00_probe_one(struct pci_dev *pd
  1.1019 - 		    "Adapter flags %x.\n",
  1.1020 - 		    ha->host_no, ha->device_flags));
  1.1021 - 
  1.1022 -+		ret = -ENODEV;
  1.1023 - 		goto probe_failed;
  1.1024 - 	}
  1.1025 - 
  1.1026 --	qla2x00_init_host_attr(ha);
  1.1027 --
  1.1028 - 	/*
  1.1029 - 	 * Startup the kernel thread for this host adapter
  1.1030 - 	 */
  1.1031 -@@ -1299,17 +1284,26 @@ int qla2x00_probe_one(struct pci_dev *pd
  1.1032 - 		qla_printk(KERN_WARNING, ha,
  1.1033 - 		    "Unable to start DPC thread!\n");
  1.1034 - 
  1.1035 -+		ret = -ENODEV;
  1.1036 - 		goto probe_failed;
  1.1037 - 	}
  1.1038 - 	wait_for_completion(&ha->dpc_inited);
  1.1039 - 
  1.1040 -+	host->this_id = 255;
  1.1041 -+	host->cmd_per_lun = 3;
  1.1042 -+	host->unique_id = ha->instance;
  1.1043 -+	host->max_cmd_len = MAX_CMDSZ;
  1.1044 -+	host->max_channel = ha->ports - 1;
  1.1045 -+	host->max_lun = MAX_LUNS;
  1.1046 -+	host->transportt = qla2xxx_transport_template;
  1.1047 -+
  1.1048 - 	if (IS_QLA2100(ha) || IS_QLA2200(ha))
  1.1049 - 		ret = request_irq(host->irq, qla2100_intr_handler,
  1.1050 - 		    SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  1.1051 - 	else
  1.1052 - 		ret = request_irq(host->irq, qla2300_intr_handler,
  1.1053 - 		    SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  1.1054 --	if (ret != 0) {
  1.1055 -+	if (ret) {
  1.1056 - 		qla_printk(KERN_WARNING, ha,
  1.1057 - 		    "Failed to reserve interrupt %d already in use.\n",
  1.1058 - 		    host->irq);
  1.1059 -@@ -1363,9 +1357,18 @@ int qla2x00_probe_one(struct pci_dev *pd
  1.1060 - 		msleep(10);
  1.1061 - 	}
  1.1062 - 
  1.1063 -+	pci_set_drvdata(pdev, ha);
  1.1064 - 	ha->flags.init_done = 1;
  1.1065 - 	num_hosts++;
  1.1066 - 
  1.1067 -+	ret = scsi_add_host(host, &pdev->dev);
  1.1068 -+	if (ret)
  1.1069 -+		goto probe_failed;
  1.1070 -+
  1.1071 -+	qla2x00_alloc_sysfs_attr(ha);
  1.1072 -+
  1.1073 -+	qla2x00_init_host_attr(ha);
  1.1074 -+
  1.1075 - 	qla_printk(KERN_INFO, ha, "\n"
  1.1076 - 	    " QLogic Fibre Channel HBA Driver: %s\n"
  1.1077 - 	    "  QLogic %s - %s\n"
  1.1078 -@@ -1384,9 +1387,6 @@ int qla2x00_probe_one(struct pci_dev *pd
  1.1079 - probe_failed:
  1.1080 - 	fc_remove_host(ha->host);
  1.1081 - 
  1.1082 --	scsi_remove_host(host);
  1.1083 --
  1.1084 --probe_alloc_failed:
  1.1085 - 	qla2x00_free_device(ha);
  1.1086 - 
  1.1087 - 	scsi_host_put(host);
  1.1088 -@@ -1394,7 +1394,8 @@ probe_alloc_failed:
  1.1089 - probe_disable_device:
  1.1090 - 	pci_disable_device(pdev);
  1.1091 - 
  1.1092 --	return -1;
  1.1093 -+probe_out:
  1.1094 -+	return ret;
  1.1095 - }
  1.1096 - EXPORT_SYMBOL_GPL(qla2x00_probe_one);
  1.1097 - 
  1.1098 -diff --git a/fs/bio.c b/fs/bio.c
  1.1099 ---- a/fs/bio.c
  1.1100 -+++ b/fs/bio.c
  1.1101 -@@ -261,6 +261,7 @@ inline void __bio_clone(struct bio *bio,
  1.1102 - 	 */
  1.1103 - 	bio->bi_vcnt = bio_src->bi_vcnt;
  1.1104 - 	bio->bi_size = bio_src->bi_size;
  1.1105 -+	bio->bi_idx = bio_src->bi_idx;
  1.1106 - 	bio_phys_segments(q, bio);
  1.1107 - 	bio_hw_segments(q, bio);
  1.1108 - }
  1.1109 -diff --git a/fs/char_dev.c b/fs/char_dev.c
  1.1110 ---- a/fs/char_dev.c
  1.1111 -+++ b/fs/char_dev.c
  1.1112 -@@ -139,7 +139,7 @@ __unregister_chrdev_region(unsigned majo
  1.1113 - 	struct char_device_struct *cd = NULL, **cp;
  1.1114 - 	int i = major_to_index(major);
  1.1115 - 
  1.1116 --	up(&chrdevs_lock);
  1.1117 -+	down(&chrdevs_lock);
  1.1118 - 	for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
  1.1119 - 		if ((*cp)->major == major &&
  1.1120 - 		    (*cp)->baseminor == baseminor &&
  1.1121 -diff --git a/fs/exec.c b/fs/exec.c
  1.1122 ---- a/fs/exec.c
  1.1123 -+++ b/fs/exec.c
  1.1124 -@@ -649,6 +649,7 @@ static inline int de_thread(struct task_
  1.1125 - 	}
  1.1126 - 	sig->group_exit_task = NULL;
  1.1127 - 	sig->notify_count = 0;
  1.1128 -+	sig->real_timer.data = (unsigned long)current;
  1.1129 - 	spin_unlock_irq(lock);
  1.1130 - 
  1.1131 - 	/*
  1.1132 -diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
  1.1133 ---- a/fs/isofs/compress.c
  1.1134 -+++ b/fs/isofs/compress.c
  1.1135 -@@ -129,8 +129,14 @@ static int zisofs_readpage(struct file *
  1.1136 - 	cend = le32_to_cpu(*(__le32 *)(bh->b_data + (blockendptr & bufmask)));
  1.1137 - 	brelse(bh);
  1.1138 - 
  1.1139 -+	if (cstart > cend)
  1.1140 -+		goto eio;
  1.1141 -+		
  1.1142 - 	csize = cend-cstart;
  1.1143 - 
  1.1144 -+	if (csize > deflateBound(1UL << zisofs_block_shift))
  1.1145 -+		goto eio;
  1.1146 -+
  1.1147 - 	/* Now page[] contains an array of pages, any of which can be NULL,
  1.1148 - 	   and the locks on which we hold.  We should now read the data and
  1.1149 - 	   release the pages.  If the pages are NULL the decompressed data
  1.1150 -diff --git a/include/asm-i386/string.h b/include/asm-i386/string.h
  1.1151 ---- a/include/asm-i386/string.h
  1.1152 -+++ b/include/asm-i386/string.h
  1.1153 -@@ -116,7 +116,8 @@ __asm__ __volatile__(
  1.1154 - 	"orb $1,%%al\n"
  1.1155 - 	"3:"
  1.1156 - 	:"=a" (__res), "=&S" (d0), "=&D" (d1)
  1.1157 --		     :"1" (cs),"2" (ct));
  1.1158 -+	:"1" (cs),"2" (ct)
  1.1159 -+	:"memory");
  1.1160 - return __res;
  1.1161 - }
  1.1162 - 
  1.1163 -@@ -138,8 +139,9 @@ __asm__ __volatile__(
  1.1164 - 	"3:\tsbbl %%eax,%%eax\n\t"
  1.1165 - 	"orb $1,%%al\n"
  1.1166 - 	"4:"
  1.1167 --		     :"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
  1.1168 --		     :"1" (cs),"2" (ct),"3" (count));
  1.1169 -+	:"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
  1.1170 -+	:"1" (cs),"2" (ct),"3" (count)
  1.1171 -+	:"memory");
  1.1172 - return __res;
  1.1173 - }
  1.1174 - 
  1.1175 -@@ -158,7 +160,9 @@ __asm__ __volatile__(
  1.1176 - 	"movl $1,%1\n"
  1.1177 - 	"2:\tmovl %1,%0\n\t"
  1.1178 - 	"decl %0"
  1.1179 --	:"=a" (__res), "=&S" (d0) : "1" (s),"0" (c));
  1.1180 -+	:"=a" (__res), "=&S" (d0)
  1.1181 -+	:"1" (s),"0" (c)
  1.1182 -+	:"memory");
  1.1183 - return __res;
  1.1184 - }
  1.1185 - 
  1.1186 -@@ -175,7 +179,9 @@ __asm__ __volatile__(
  1.1187 - 	"leal -1(%%esi),%0\n"
  1.1188 - 	"2:\ttestb %%al,%%al\n\t"
  1.1189 - 	"jne 1b"
  1.1190 --	:"=g" (__res), "=&S" (d0), "=&a" (d1) :"0" (0),"1" (s),"2" (c));
  1.1191 -+	:"=g" (__res), "=&S" (d0), "=&a" (d1)
  1.1192 -+	:"0" (0),"1" (s),"2" (c)
  1.1193 -+	:"memory");
  1.1194 - return __res;
  1.1195 - }
  1.1196 - 
  1.1197 -@@ -189,7 +195,9 @@ __asm__ __volatile__(
  1.1198 - 	"scasb\n\t"
  1.1199 - 	"notl %0\n\t"
  1.1200 - 	"decl %0"
  1.1201 --	:"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffffu));
  1.1202 -+	:"=c" (__res), "=&D" (d0)
  1.1203 -+	:"1" (s),"a" (0), "0" (0xffffffffu)
  1.1204 -+	:"memory");
  1.1205 - return __res;
  1.1206 - }
  1.1207 - 
  1.1208 -@@ -333,7 +341,9 @@ __asm__ __volatile__(
  1.1209 - 	"je 1f\n\t"
  1.1210 - 	"movl $1,%0\n"
  1.1211 - 	"1:\tdecl %0"
  1.1212 --	:"=D" (__res), "=&c" (d0) : "a" (c),"0" (cs),"1" (count));
  1.1213 -+	:"=D" (__res), "=&c" (d0)
  1.1214 -+	:"a" (c),"0" (cs),"1" (count)
  1.1215 -+	:"memory");
  1.1216 - return __res;
  1.1217 - }
  1.1218 - 
  1.1219 -@@ -369,7 +379,7 @@ __asm__ __volatile__(
  1.1220 - 	"je 2f\n\t"
  1.1221 - 	"stosb\n"
  1.1222 - 	"2:"
  1.1223 --	: "=&c" (d0), "=&D" (d1)
  1.1224 -+	:"=&c" (d0), "=&D" (d1)
  1.1225 - 	:"a" (c), "q" (count), "0" (count/4), "1" ((long) s)
  1.1226 - 	:"memory");
  1.1227 - return (s);	
  1.1228 -@@ -392,7 +402,8 @@ __asm__ __volatile__(
  1.1229 - 	"jne 1b\n"
  1.1230 - 	"3:\tsubl %2,%0"
  1.1231 - 	:"=a" (__res), "=&d" (d0)
  1.1232 --	:"c" (s),"1" (count));
  1.1233 -+	:"c" (s),"1" (count)
  1.1234 -+	:"memory");
  1.1235 - return __res;
  1.1236 - }
  1.1237 - /* end of additional stuff */
  1.1238 -@@ -473,7 +484,8 @@ static inline void * memscan(void * addr
  1.1239 - 		"dec %%edi\n"
  1.1240 - 		"1:"
  1.1241 - 		: "=D" (addr), "=c" (size)
  1.1242 --		: "0" (addr), "1" (size), "a" (c));
  1.1243 -+		: "0" (addr), "1" (size), "a" (c)
  1.1244 -+		: "memory");
  1.1245 - 	return addr;
  1.1246 - }
  1.1247 - 
  1.1248 -diff --git a/include/asm-x86_64/smp.h b/include/asm-x86_64/smp.h
  1.1249 ---- a/include/asm-x86_64/smp.h
  1.1250 -+++ b/include/asm-x86_64/smp.h
  1.1251 -@@ -46,6 +46,8 @@ extern int pic_mode;
  1.1252 - extern int smp_num_siblings;
  1.1253 - extern void smp_flush_tlb(void);
  1.1254 - extern void smp_message_irq(int cpl, void *dev_id, struct pt_regs *regs);
  1.1255 -+extern int smp_call_function_single (int cpuid, void (*func) (void *info), void *info,
  1.1256 -+				     int retry, int wait);
  1.1257 - extern void smp_send_reschedule(int cpu);
  1.1258 - extern void smp_invalidate_rcv(void);		/* Process an NMI */
  1.1259 - extern void zap_low_mappings(void);
  1.1260 -diff --git a/include/linux/if_shaper.h b/include/linux/if_shaper.h
  1.1261 ---- a/include/linux/if_shaper.h
  1.1262 -+++ b/include/linux/if_shaper.h
  1.1263 -@@ -23,7 +23,7 @@ struct shaper
  1.1264 - 	__u32 shapeclock;
  1.1265 - 	unsigned long recovery;	/* Time we can next clock a packet out on
  1.1266 - 				   an empty queue */
  1.1267 --	struct semaphore sem;
  1.1268 -+	spinlock_t lock;
  1.1269 -         struct net_device_stats stats;
  1.1270 - 	struct net_device *dev;
  1.1271 - 	int  (*hard_start_xmit) (struct sk_buff *skb,
  1.1272 -diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
  1.1273 ---- a/include/linux/skbuff.h
  1.1274 -+++ b/include/linux/skbuff.h
  1.1275 -@@ -1192,7 +1192,7 @@ static inline void *skb_header_pointer(c
  1.1276 - {
  1.1277 - 	int hlen = skb_headlen(skb);
  1.1278 - 
  1.1279 --	if (offset + len <= hlen)
  1.1280 -+	if (hlen - offset >= len)
  1.1281 - 		return skb->data + offset;
  1.1282 - 
  1.1283 - 	if (skb_copy_bits(skb, offset, buffer, len) < 0)
  1.1284 -diff --git a/include/linux/zlib.h b/include/linux/zlib.h
  1.1285 ---- a/include/linux/zlib.h
  1.1286 -+++ b/include/linux/zlib.h
  1.1287 -@@ -506,6 +506,11 @@ extern int zlib_deflateReset (z_streamp 
  1.1288 -    stream state was inconsistent (such as zalloc or state being NULL).
  1.1289 - */
  1.1290 - 
  1.1291 -+static inline unsigned long deflateBound(unsigned long s)
  1.1292 -+{
  1.1293 -+	return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11;
  1.1294 -+}
  1.1295 -+
  1.1296 - extern int zlib_deflateParams (z_streamp strm, int level, int strategy);
  1.1297 - /*
  1.1298 -      Dynamically update the compression level and compression strategy.  The
  1.1299 -diff --git a/kernel/module.c b/kernel/module.c
  1.1300 ---- a/kernel/module.c
  1.1301 -+++ b/kernel/module.c
  1.1302 -@@ -249,13 +249,18 @@ static inline unsigned int block_size(in
  1.1303 - /* Created by linker magic */
  1.1304 - extern char __per_cpu_start[], __per_cpu_end[];
  1.1305 - 
  1.1306 --static void *percpu_modalloc(unsigned long size, unsigned long align)
  1.1307 -+static void *percpu_modalloc(unsigned long size, unsigned long align,
  1.1308 -+			     const char *name)
  1.1309 - {
  1.1310 - 	unsigned long extra;
  1.1311 - 	unsigned int i;
  1.1312 - 	void *ptr;
  1.1313 - 
  1.1314 --	BUG_ON(align > SMP_CACHE_BYTES);
  1.1315 -+	if (align > SMP_CACHE_BYTES) {
  1.1316 -+		printk(KERN_WARNING "%s: per-cpu alignment %li > %i\n",
  1.1317 -+		       name, align, SMP_CACHE_BYTES);
  1.1318 -+		align = SMP_CACHE_BYTES;
  1.1319 -+	}
  1.1320 - 
  1.1321 - 	ptr = __per_cpu_start;
  1.1322 - 	for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) {
  1.1323 -@@ -347,7 +352,8 @@ static int percpu_modinit(void)
  1.1324 - }	
  1.1325 - __initcall(percpu_modinit);
  1.1326 - #else /* ... !CONFIG_SMP */
  1.1327 --static inline void *percpu_modalloc(unsigned long size, unsigned long align)
  1.1328 -+static inline void *percpu_modalloc(unsigned long size, unsigned long align,
  1.1329 -+				    const char *name)
  1.1330 - {
  1.1331 - 	return NULL;
  1.1332 - }
  1.1333 -@@ -1554,7 +1560,8 @@ static struct module *load_module(void _
  1.1334 - 	if (pcpuindex) {
  1.1335 - 		/* We have a special allocation for this section. */
  1.1336 - 		percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size,
  1.1337 --					 sechdrs[pcpuindex].sh_addralign);
  1.1338 -+					 sechdrs[pcpuindex].sh_addralign,
  1.1339 -+					 mod->name);
  1.1340 - 		if (!percpu) {
  1.1341 - 			err = -ENOMEM;
  1.1342 - 			goto free_mod;
  1.1343 -diff --git a/lib/inflate.c b/lib/inflate.c
  1.1344 ---- a/lib/inflate.c
  1.1345 -+++ b/lib/inflate.c
  1.1346 -@@ -326,7 +326,7 @@ DEBG("huft1 ");
  1.1347 -   {
  1.1348 -     *t = (struct huft *)NULL;
  1.1349 -     *m = 0;
  1.1350 --    return 0;
  1.1351 -+    return 2;
  1.1352 -   }
  1.1353 - 
  1.1354 - DEBG("huft2 ");
  1.1355 -@@ -374,6 +374,7 @@ DEBG("huft5 ");
  1.1356 -     if ((j = *p++) != 0)
  1.1357 -       v[x[j]++] = i;
  1.1358 -   } while (++i < n);
  1.1359 -+  n = x[g];                   /* set n to length of v */
  1.1360 - 
  1.1361 - DEBG("h6 ");
  1.1362 - 
  1.1363 -@@ -410,12 +411,13 @@ DEBG1("1 ");
  1.1364 - DEBG1("2 ");
  1.1365 -           f -= a + 1;           /* deduct codes from patterns left */
  1.1366 -           xp = c + k;
  1.1367 --          while (++j < z)       /* try smaller tables up to z bits */
  1.1368 --          {
  1.1369 --            if ((f <<= 1) <= *++xp)
  1.1370 --              break;            /* enough codes to use up j bits */
  1.1371 --            f -= *xp;           /* else deduct codes from patterns */
  1.1372 --          }
  1.1373 -+          if (j < z)
  1.1374 -+            while (++j < z)       /* try smaller tables up to z bits */
  1.1375 -+            {
  1.1376 -+              if ((f <<= 1) <= *++xp)
  1.1377 -+                break;            /* enough codes to use up j bits */
  1.1378 -+              f -= *xp;           /* else deduct codes from patterns */
  1.1379 -+            }
  1.1380 -         }
  1.1381 - DEBG1("3 ");
  1.1382 -         z = 1 << j;             /* table entries for j-bit table */
  1.1383 -diff --git a/lib/zlib_inflate/inftrees.c b/lib/zlib_inflate/inftrees.c
  1.1384 ---- a/lib/zlib_inflate/inftrees.c
  1.1385 -+++ b/lib/zlib_inflate/inftrees.c
  1.1386 -@@ -141,7 +141,7 @@ static int huft_build(
  1.1387 -   {
  1.1388 -     *t = NULL;
  1.1389 -     *m = 0;
  1.1390 --    return Z_OK;
  1.1391 -+    return Z_DATA_ERROR;
  1.1392 -   }
  1.1393 - 
  1.1394 - 
  1.1395 -diff --git a/mm/memory.c b/mm/memory.c
  1.1396 ---- a/mm/memory.c
  1.1397 -+++ b/mm/memory.c
  1.1398 -@@ -1164,7 +1164,7 @@ int remap_pfn_range(struct vm_area_struc
  1.1399 - {
  1.1400 - 	pgd_t *pgd;
  1.1401 - 	unsigned long next;
  1.1402 --	unsigned long end = addr + size;
  1.1403 -+	unsigned long end = addr + PAGE_ALIGN(size);
  1.1404 - 	struct mm_struct *mm = vma->vm_mm;
  1.1405 - 	int err;
  1.1406 - 
  1.1407 -diff --git a/mm/mempolicy.c b/mm/mempolicy.c
  1.1408 ---- a/mm/mempolicy.c
  1.1409 -+++ b/mm/mempolicy.c
  1.1410 -@@ -409,7 +409,7 @@ asmlinkage long sys_set_mempolicy(int mo
  1.1411 - 	struct mempolicy *new;
  1.1412 - 	DECLARE_BITMAP(nodes, MAX_NUMNODES);
  1.1413 - 
  1.1414 --	if (mode > MPOL_MAX)
  1.1415 -+	if (mode < 0 || mode > MPOL_MAX)
  1.1416 - 		return -EINVAL;
  1.1417 - 	err = get_nodes(nodes, nmask, maxnode, mode);
  1.1418 - 	if (err)
  1.1419 -diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
  1.1420 ---- a/net/8021q/vlan.c
  1.1421 -+++ b/net/8021q/vlan.c
  1.1422 -@@ -578,6 +578,14 @@ static int vlan_device_event(struct noti
  1.1423 - 			if (!vlandev)
  1.1424 - 				continue;
  1.1425 - 
  1.1426 -+			if (netif_carrier_ok(dev)) {
  1.1427 -+				if (!netif_carrier_ok(vlandev))
  1.1428 -+					netif_carrier_on(vlandev);
  1.1429 -+			} else {
  1.1430 -+				if (netif_carrier_ok(vlandev))
  1.1431 -+					netif_carrier_off(vlandev);
  1.1432 -+			}
  1.1433 -+
  1.1434 - 			if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
  1.1435 - 				vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK) 
  1.1436 - 					| flgs;
  1.1437 -diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
  1.1438 ---- a/net/ipv4/ip_output.c
  1.1439 -+++ b/net/ipv4/ip_output.c
  1.1440 -@@ -111,7 +111,6 @@ static int ip_dev_loopback_xmit(struct s
  1.1441 - #ifdef CONFIG_NETFILTER_DEBUG
  1.1442 - 	nf_debug_ip_loopback_xmit(newskb);
  1.1443 - #endif
  1.1444 --	nf_reset(newskb);
  1.1445 - 	netif_rx(newskb);
  1.1446 - 	return 0;
  1.1447 - }
  1.1448 -@@ -196,8 +195,6 @@ static inline int ip_finish_output2(stru
  1.1449 - 	nf_debug_ip_finish_output2(skb);
  1.1450 - #endif /*CONFIG_NETFILTER_DEBUG*/
  1.1451 - 
  1.1452 --	nf_reset(skb);
  1.1453 --
  1.1454 - 	if (hh) {
  1.1455 - 		int hh_alen;
  1.1456 - 
  1.1457 -diff --git a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
  1.1458 ---- a/net/ipv4/netfilter/ip_conntrack_core.c
  1.1459 -+++ b/net/ipv4/netfilter/ip_conntrack_core.c
  1.1460 -@@ -1124,6 +1124,9 @@ void ip_conntrack_cleanup(void)
  1.1461 - 		schedule();
  1.1462 - 		goto i_see_dead_people;
  1.1463 - 	}
  1.1464 -+	/* wait until all references to ip_conntrack_untracked are dropped */
  1.1465 -+	while (atomic_read(&ip_conntrack_untracked.ct_general.use) > 1)
  1.1466 -+		schedule();
  1.1467 - 
  1.1468 - 	kmem_cache_destroy(ip_conntrack_cachep);
  1.1469 - 	kmem_cache_destroy(ip_conntrack_expect_cachep);
  1.1470 -diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
  1.1471 ---- a/net/ipv4/netfilter/ip_conntrack_standalone.c
  1.1472 -+++ b/net/ipv4/netfilter/ip_conntrack_standalone.c
  1.1473 -@@ -432,6 +432,13 @@ static unsigned int ip_conntrack_defrag(
  1.1474 - 				        const struct net_device *out,
  1.1475 - 				        int (*okfn)(struct sk_buff *))
  1.1476 - {
  1.1477 -+#if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
  1.1478 -+	/* Previously seen (loopback)?  Ignore.  Do this before
  1.1479 -+           fragment check. */
  1.1480 -+	if ((*pskb)->nfct)
  1.1481 -+		return NF_ACCEPT;
  1.1482 -+#endif
  1.1483 -+
  1.1484 - 	/* Gather fragments. */
  1.1485 - 	if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
  1.1486 - 		*pskb = ip_ct_gather_frags(*pskb,
  1.1487 -diff --git a/net/ipv4/netfilter/ip_nat_proto_tcp.c b/net/ipv4/netfilter/ip_nat_proto_tcp.c
  1.1488 ---- a/net/ipv4/netfilter/ip_nat_proto_tcp.c
  1.1489 -+++ b/net/ipv4/netfilter/ip_nat_proto_tcp.c
  1.1490 -@@ -40,7 +40,8 @@ tcp_unique_tuple(struct ip_conntrack_tup
  1.1491 - 		 enum ip_nat_manip_type maniptype,
  1.1492 - 		 const struct ip_conntrack *conntrack)
  1.1493 - {
  1.1494 --	static u_int16_t port, *portptr;
  1.1495 -+	static u_int16_t port;
  1.1496 -+	u_int16_t *portptr;
  1.1497 - 	unsigned int range_size, min, i;
  1.1498 - 
  1.1499 - 	if (maniptype == IP_NAT_MANIP_SRC)
  1.1500 -diff --git a/net/ipv4/netfilter/ip_nat_proto_udp.c b/net/ipv4/netfilter/ip_nat_proto_udp.c
  1.1501 ---- a/net/ipv4/netfilter/ip_nat_proto_udp.c
  1.1502 -+++ b/net/ipv4/netfilter/ip_nat_proto_udp.c
  1.1503 -@@ -41,7 +41,8 @@ udp_unique_tuple(struct ip_conntrack_tup
  1.1504 - 		 enum ip_nat_manip_type maniptype,
  1.1505 - 		 const struct ip_conntrack *conntrack)
  1.1506 - {
  1.1507 --	static u_int16_t port, *portptr;
  1.1508 -+	static u_int16_t port;
  1.1509 -+	u_int16_t *portptr;
  1.1510 - 	unsigned int range_size, min, i;
  1.1511 - 
  1.1512 - 	if (maniptype == IP_NAT_MANIP_SRC)
  1.1513 -diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
  1.1514 ---- a/net/ipv6/netfilter/ip6_queue.c
  1.1515 -+++ b/net/ipv6/netfilter/ip6_queue.c
  1.1516 -@@ -76,7 +76,9 @@ static DECLARE_MUTEX(ipqnl_sem);
  1.1517 - static void
  1.1518 - ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict)
  1.1519 - {
  1.1520 -+	local_bh_disable();
  1.1521 - 	nf_reinject(entry->skb, entry->info, verdict);
  1.1522 -+	local_bh_enable();
  1.1523 - 	kfree(entry);
  1.1524 - }
  1.1525 - 
  1.1526 -diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
  1.1527 ---- a/net/netlink/af_netlink.c
  1.1528 -+++ b/net/netlink/af_netlink.c
  1.1529 -@@ -315,8 +315,8 @@ err:
  1.1530 - static void netlink_remove(struct sock *sk)
  1.1531 - {
  1.1532 - 	netlink_table_grab();
  1.1533 --	nl_table[sk->sk_protocol].hash.entries--;
  1.1534 --	sk_del_node_init(sk);
  1.1535 -+	if (sk_del_node_init(sk))
  1.1536 -+		nl_table[sk->sk_protocol].hash.entries--;
  1.1537 - 	if (nlk_sk(sk)->groups)
  1.1538 - 		__sk_del_bind_node(sk);
  1.1539 - 	netlink_table_ungrab();
  1.1540 -@@ -429,7 +429,12 @@ retry:
  1.1541 - 	err = netlink_insert(sk, pid);
  1.1542 - 	if (err == -EADDRINUSE)
  1.1543 - 		goto retry;
  1.1544 --	return 0;
  1.1545 -+
  1.1546 -+	/* If 2 threads race to autobind, that is fine.  */
  1.1547 -+	if (err == -EBUSY)
  1.1548 -+		err = 0;
  1.1549 -+
  1.1550 -+	return err;
  1.1551 - }
  1.1552 - 
  1.1553 - static inline int netlink_capable(struct socket *sock, unsigned int flag) 
  1.1554 -diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
  1.1555 ---- a/net/packet/af_packet.c
  1.1556 -+++ b/net/packet/af_packet.c
  1.1557 -@@ -274,6 +274,9 @@ static int packet_rcv_spkt(struct sk_buf
  1.1558 - 	dst_release(skb->dst);
  1.1559 - 	skb->dst = NULL;
  1.1560 - 
  1.1561 -+	/* drop conntrack reference */
  1.1562 -+	nf_reset(skb);
  1.1563 -+
  1.1564 - 	spkt = (struct sockaddr_pkt*)skb->cb;
  1.1565 - 
  1.1566 - 	skb_push(skb, skb->data-skb->mac.raw);
  1.1567 -@@ -517,6 +520,9 @@ static int packet_rcv(struct sk_buff *sk
  1.1568 - 	dst_release(skb->dst);
  1.1569 - 	skb->dst = NULL;
  1.1570 - 
  1.1571 -+	/* drop conntrack reference */
  1.1572 -+	nf_reset(skb);
  1.1573 -+
  1.1574 - 	spin_lock(&sk->sk_receive_queue.lock);
  1.1575 - 	po->stats.tp_packets++;
  1.1576 - 	__skb_queue_tail(&sk->sk_receive_queue, skb);
  1.1577 -diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
  1.1578 ---- a/net/xfrm/xfrm_user.c
  1.1579 -+++ b/net/xfrm/xfrm_user.c
  1.1580 -@@ -1180,6 +1180,9 @@ static struct xfrm_policy *xfrm_compile_
  1.1581 - 	if (nr > XFRM_MAX_DEPTH)
  1.1582 - 		return NULL;
  1.1583 - 
  1.1584 -+	if (p->dir > XFRM_POLICY_OUT)
  1.1585 -+		return NULL;
  1.1586 -+
  1.1587 - 	xp = xfrm_policy_alloc(GFP_KERNEL);
  1.1588 - 	if (xp == NULL) {
  1.1589 - 		*dir = -ENOBUFS;
  1.1590 -diff --git a/security/keys/keyring.c b/security/keys/keyring.c
  1.1591 ---- a/security/keys/keyring.c
  1.1592 -+++ b/security/keys/keyring.c
  1.1593 -@@ -188,7 +188,11 @@ static void keyring_destroy(struct key *
  1.1594 - 
  1.1595 - 	if (keyring->description) {
  1.1596 - 		write_lock(&keyring_name_lock);
  1.1597 --		list_del(&keyring->type_data.link);
  1.1598 -+
  1.1599 -+		if (keyring->type_data.link.next != NULL &&
  1.1600 -+		    !list_empty(&keyring->type_data.link))
  1.1601 -+			list_del(&keyring->type_data.link);
  1.1602 -+
  1.1603 - 		write_unlock(&keyring_name_lock);
  1.1604 - 	}
  1.1605 - 
  1.1606 -diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
  1.1607 ---- a/security/keys/process_keys.c
  1.1608 -+++ b/security/keys/process_keys.c
  1.1609 -@@ -641,7 +641,7 @@ long join_session_keyring(const char *na
  1.1610 - 		keyring = keyring_alloc(name, tsk->uid, tsk->gid, 0, NULL);
  1.1611 - 		if (IS_ERR(keyring)) {
  1.1612 - 			ret = PTR_ERR(keyring);
  1.1613 --			goto error;
  1.1614 -+			goto error2;
  1.1615 - 		}
  1.1616 - 	}
  1.1617 - 	else if (IS_ERR(keyring)) {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/patches/linux-2.6.12/2.6.12.6.patch	Fri Oct 21 12:07:14 2005 +0100
     2.3 @@ -0,0 +1,1738 @@
     2.4 +diff --git a/Makefile b/Makefile
     2.5 +--- a/Makefile
     2.6 ++++ b/Makefile
     2.7 +@@ -1,7 +1,7 @@
     2.8 + VERSION = 2
     2.9 + PATCHLEVEL = 6
    2.10 + SUBLEVEL = 12
    2.11 +-EXTRAVERSION =
    2.12 ++EXTRAVERSION = .6
    2.13 + NAME=Woozy Numbat
    2.14 + 
    2.15 + # *DOCUMENTATION*
    2.16 +@@ -1149,7 +1149,7 @@ endif # KBUILD_EXTMOD
    2.17 + #(which is the most common case IMHO) to avoid unneeded clutter in the big tags file.
    2.18 + #Adding $(srctree) adds about 20M on i386 to the size of the output file!
    2.19 + 
    2.20 +-ifeq ($(KBUILD_OUTPUT),)
    2.21 ++ifeq ($(src),$(obj))
    2.22 + __srctree =
    2.23 + else
    2.24 + __srctree = $(srctree)/
    2.25 +diff --git a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
    2.26 +--- a/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
    2.27 ++++ b/arch/i386/kernel/cpu/cpufreq/powernow-k8.c
    2.28 +@@ -44,7 +44,7 @@
    2.29 + 
    2.30 + #define PFX "powernow-k8: "
    2.31 + #define BFX PFX "BIOS error: "
    2.32 +-#define VERSION "version 1.40.2"
    2.33 ++#define VERSION "version 1.40.4"
    2.34 + #include "powernow-k8.h"
    2.35 + 
    2.36 + /* serialize freq changes  */
    2.37 +@@ -978,7 +978,7 @@ static int __init powernowk8_cpu_init(st
    2.38 + {
    2.39 + 	struct powernow_k8_data *data;
    2.40 + 	cpumask_t oldmask = CPU_MASK_ALL;
    2.41 +-	int rc;
    2.42 ++	int rc, i;
    2.43 + 
    2.44 + 	if (!check_supported_cpu(pol->cpu))
    2.45 + 		return -ENODEV;
    2.46 +@@ -1064,7 +1064,9 @@ static int __init powernowk8_cpu_init(st
    2.47 + 	printk("cpu_init done, current fid 0x%x, vid 0x%x\n",
    2.48 + 	       data->currfid, data->currvid);
    2.49 + 
    2.50 +-	powernow_data[pol->cpu] = data;
    2.51 ++	for_each_cpu_mask(i, cpu_core_map[pol->cpu]) {
    2.52 ++		powernow_data[i] = data;
    2.53 ++	}
    2.54 + 
    2.55 + 	return 0;
    2.56 + 
    2.57 +diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
    2.58 +--- a/arch/i386/kernel/process.c
    2.59 ++++ b/arch/i386/kernel/process.c
    2.60 +@@ -827,6 +827,8 @@ asmlinkage int sys_get_thread_area(struc
    2.61 + 	if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
    2.62 + 		return -EINVAL;
    2.63 + 
    2.64 ++	memset(&info, 0, sizeof(info));
    2.65 ++
    2.66 + 	desc = current->thread.tls_array + idx - GDT_ENTRY_TLS_MIN;
    2.67 + 
    2.68 + 	info.entry_number = idx;
    2.69 +diff --git a/arch/ia64/kernel/ptrace.c b/arch/ia64/kernel/ptrace.c
    2.70 +--- a/arch/ia64/kernel/ptrace.c
    2.71 ++++ b/arch/ia64/kernel/ptrace.c
    2.72 +@@ -945,6 +945,13 @@ access_uarea (struct task_struct *child,
    2.73 + 				*data = (pt->cr_ipsr & IPSR_MASK);
    2.74 + 			return 0;
    2.75 + 
    2.76 ++		      case PT_AR_RSC:
    2.77 ++			if (write_access)
    2.78 ++				pt->ar_rsc = *data | (3 << 2); /* force PL3 */
    2.79 ++			else
    2.80 ++				*data = pt->ar_rsc;
    2.81 ++			return 0;
    2.82 ++
    2.83 + 		      case PT_AR_RNAT:
    2.84 + 			urbs_end = ia64_get_user_rbs_end(child, pt, NULL);
    2.85 + 			rnat_addr = (long) ia64_rse_rnat_addr((long *)
    2.86 +@@ -996,9 +1003,6 @@ access_uarea (struct task_struct *child,
    2.87 + 		      case PT_AR_BSPSTORE:
    2.88 + 			ptr = pt_reg_addr(pt, ar_bspstore);
    2.89 + 			break;
    2.90 +-		      case PT_AR_RSC:
    2.91 +-			ptr = pt_reg_addr(pt, ar_rsc);
    2.92 +-			break;
    2.93 + 		      case PT_AR_UNAT:
    2.94 + 			ptr = pt_reg_addr(pt, ar_unat);
    2.95 + 			break;
    2.96 +@@ -1234,7 +1238,7 @@ ptrace_getregs (struct task_struct *chil
    2.97 + static long
    2.98 + ptrace_setregs (struct task_struct *child, struct pt_all_user_regs __user *ppr)
    2.99 + {
   2.100 +-	unsigned long psr, ec, lc, rnat, bsp, cfm, nat_bits, val = 0;
   2.101 ++	unsigned long psr, rsc, ec, lc, rnat, bsp, cfm, nat_bits, val = 0;
   2.102 + 	struct unw_frame_info info;
   2.103 + 	struct switch_stack *sw;
   2.104 + 	struct ia64_fpreg fpval;
   2.105 +@@ -1267,7 +1271,7 @@ ptrace_setregs (struct task_struct *chil
   2.106 + 	/* app regs */
   2.107 + 
   2.108 + 	retval |= __get_user(pt->ar_pfs, &ppr->ar[PT_AUR_PFS]);
   2.109 +-	retval |= __get_user(pt->ar_rsc, &ppr->ar[PT_AUR_RSC]);
   2.110 ++	retval |= __get_user(rsc, &ppr->ar[PT_AUR_RSC]);
   2.111 + 	retval |= __get_user(pt->ar_bspstore, &ppr->ar[PT_AUR_BSPSTORE]);
   2.112 + 	retval |= __get_user(pt->ar_unat, &ppr->ar[PT_AUR_UNAT]);
   2.113 + 	retval |= __get_user(pt->ar_ccv, &ppr->ar[PT_AUR_CCV]);
   2.114 +@@ -1365,6 +1369,7 @@ ptrace_setregs (struct task_struct *chil
   2.115 + 	retval |= __get_user(nat_bits, &ppr->nat);
   2.116 + 
   2.117 + 	retval |= access_uarea(child, PT_CR_IPSR, &psr, 1);
   2.118 ++	retval |= access_uarea(child, PT_AR_RSC, &rsc, 1);
   2.119 + 	retval |= access_uarea(child, PT_AR_EC, &ec, 1);
   2.120 + 	retval |= access_uarea(child, PT_AR_LC, &lc, 1);
   2.121 + 	retval |= access_uarea(child, PT_AR_RNAT, &rnat, 1);
   2.122 +diff --git a/arch/ia64/kernel/signal.c b/arch/ia64/kernel/signal.c
   2.123 +--- a/arch/ia64/kernel/signal.c
   2.124 ++++ b/arch/ia64/kernel/signal.c
   2.125 +@@ -94,7 +94,7 @@ sys_sigaltstack (const stack_t __user *u
   2.126 + static long
   2.127 + restore_sigcontext (struct sigcontext __user *sc, struct sigscratch *scr)
   2.128 + {
   2.129 +-	unsigned long ip, flags, nat, um, cfm;
   2.130 ++	unsigned long ip, flags, nat, um, cfm, rsc;
   2.131 + 	long err;
   2.132 + 
   2.133 + 	/* Always make any pending restarted system calls return -EINTR */
   2.134 +@@ -106,7 +106,7 @@ restore_sigcontext (struct sigcontext __
   2.135 + 	err |= __get_user(ip, &sc->sc_ip);			/* instruction pointer */
   2.136 + 	err |= __get_user(cfm, &sc->sc_cfm);
   2.137 + 	err |= __get_user(um, &sc->sc_um);			/* user mask */
   2.138 +-	err |= __get_user(scr->pt.ar_rsc, &sc->sc_ar_rsc);
   2.139 ++	err |= __get_user(rsc, &sc->sc_ar_rsc);
   2.140 + 	err |= __get_user(scr->pt.ar_unat, &sc->sc_ar_unat);
   2.141 + 	err |= __get_user(scr->pt.ar_fpsr, &sc->sc_ar_fpsr);
   2.142 + 	err |= __get_user(scr->pt.ar_pfs, &sc->sc_ar_pfs);
   2.143 +@@ -119,6 +119,7 @@ restore_sigcontext (struct sigcontext __
   2.144 + 	err |= __copy_from_user(&scr->pt.r15, &sc->sc_gr[15], 8);	/* r15 */
   2.145 + 
   2.146 + 	scr->pt.cr_ifs = cfm | (1UL << 63);
   2.147 ++	scr->pt.ar_rsc = rsc | (3 << 2); /* force PL3 */
   2.148 + 
   2.149 + 	/* establish new instruction pointer: */
   2.150 + 	scr->pt.cr_iip = ip & ~0x3UL;
   2.151 +diff --git a/arch/ppc/kernel/time.c b/arch/ppc/kernel/time.c
   2.152 +--- a/arch/ppc/kernel/time.c
   2.153 ++++ b/arch/ppc/kernel/time.c
   2.154 +@@ -89,6 +89,9 @@ unsigned long tb_to_ns_scale;
   2.155 + 
   2.156 + extern unsigned long wall_jiffies;
   2.157 + 
   2.158 ++/* used for timezone offset */
   2.159 ++static long timezone_offset;
   2.160 ++
   2.161 + DEFINE_SPINLOCK(rtc_lock);
   2.162 + 
   2.163 + EXPORT_SYMBOL(rtc_lock);
   2.164 +@@ -170,7 +173,7 @@ void timer_interrupt(struct pt_regs * re
   2.165 + 		     xtime.tv_sec - last_rtc_update >= 659 &&
   2.166 + 		     abs((xtime.tv_nsec / 1000) - (1000000-1000000/HZ)) < 500000/HZ &&
   2.167 + 		     jiffies - wall_jiffies == 1) {
   2.168 +-		  	if (ppc_md.set_rtc_time(xtime.tv_sec+1 + time_offset) == 0)
   2.169 ++		  	if (ppc_md.set_rtc_time(xtime.tv_sec+1 + timezone_offset) == 0)
   2.170 + 				last_rtc_update = xtime.tv_sec+1;
   2.171 + 			else
   2.172 + 				/* Try again one minute later */
   2.173 +@@ -286,7 +289,7 @@ void __init time_init(void)
   2.174 + 	unsigned old_stamp, stamp, elapsed;
   2.175 + 
   2.176 +         if (ppc_md.time_init != NULL)
   2.177 +-                time_offset = ppc_md.time_init();
   2.178 ++                timezone_offset = ppc_md.time_init();
   2.179 + 
   2.180 + 	if (__USE_RTC()) {
   2.181 + 		/* 601 processor: dec counts down by 128 every 128ns */
   2.182 +@@ -331,10 +334,10 @@ void __init time_init(void)
   2.183 + 	set_dec(tb_ticks_per_jiffy);
   2.184 + 
   2.185 + 	/* If platform provided a timezone (pmac), we correct the time */
   2.186 +-        if (time_offset) {
   2.187 +-		sys_tz.tz_minuteswest = -time_offset / 60;
   2.188 ++        if (timezone_offset) {
   2.189 ++		sys_tz.tz_minuteswest = -timezone_offset / 60;
   2.190 + 		sys_tz.tz_dsttime = 0;
   2.191 +-		xtime.tv_sec -= time_offset;
   2.192 ++		xtime.tv_sec -= timezone_offset;
   2.193 +         }
   2.194 +         set_normalized_timespec(&wall_to_monotonic,
   2.195 +                                 -xtime.tv_sec, -xtime.tv_nsec);
   2.196 +diff --git a/arch/ppc64/boot/zlib.c b/arch/ppc64/boot/zlib.c
   2.197 +--- a/arch/ppc64/boot/zlib.c
   2.198 ++++ b/arch/ppc64/boot/zlib.c
   2.199 +@@ -1307,7 +1307,7 @@ local int huft_build(
   2.200 +   {
   2.201 +     *t = (inflate_huft *)Z_NULL;
   2.202 +     *m = 0;
   2.203 +-    return Z_OK;
   2.204 ++    return Z_DATA_ERROR;
   2.205 +   }
   2.206 + 
   2.207 + 
   2.208 +@@ -1351,6 +1351,7 @@ local int huft_build(
   2.209 +     if ((j = *p++) != 0)
   2.210 +       v[x[j]++] = i;
   2.211 +   } while (++i < n);
   2.212 ++  n = x[g];			/* set n to length of v */
   2.213 + 
   2.214 + 
   2.215 +   /* Generate the Huffman codes and for each, make the table entries */
   2.216 +diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
   2.217 +--- a/arch/um/kernel/process.c
   2.218 ++++ b/arch/um/kernel/process.c
   2.219 +@@ -130,7 +130,7 @@ int start_fork_tramp(void *thread_arg, u
   2.220 + 	return(arg.pid);
   2.221 + }
   2.222 + 
   2.223 +-static int ptrace_child(void)
   2.224 ++static int ptrace_child(void *arg)
   2.225 + {
   2.226 + 	int ret;
   2.227 + 	int pid = os_getpid(), ppid = getppid();
   2.228 +@@ -159,16 +159,20 @@ static int ptrace_child(void)
   2.229 + 	_exit(ret);
   2.230 + }
   2.231 + 
   2.232 +-static int start_ptraced_child(void)
   2.233 ++static int start_ptraced_child(void **stack_out)
   2.234 + {
   2.235 ++	void *stack;
   2.236 ++	unsigned long sp;
   2.237 + 	int pid, n, status;
   2.238 + 	
   2.239 +-	pid = fork();
   2.240 +-	if(pid == 0)
   2.241 +-		ptrace_child();
   2.242 +-
   2.243 ++	stack = mmap(NULL, PAGE_SIZE, PROT_READ | PROT_WRITE | PROT_EXEC,
   2.244 ++		     MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
   2.245 ++	if(stack == MAP_FAILED)
   2.246 ++		panic("check_ptrace : mmap failed, errno = %d", errno);
   2.247 ++	sp = (unsigned long) stack + PAGE_SIZE - sizeof(void *);
   2.248 ++	pid = clone(ptrace_child, (void *) sp, SIGCHLD, NULL);
   2.249 + 	if(pid < 0)
   2.250 +-		panic("check_ptrace : fork failed, errno = %d", errno);
   2.251 ++		panic("check_ptrace : clone failed, errno = %d", errno);
   2.252 + 	CATCH_EINTR(n = waitpid(pid, &status, WUNTRACED));
   2.253 + 	if(n < 0)
   2.254 + 		panic("check_ptrace : wait failed, errno = %d", errno);
   2.255 +@@ -176,6 +180,7 @@ static int start_ptraced_child(void)
   2.256 + 		panic("check_ptrace : expected SIGSTOP, got status = %d",
   2.257 + 		      status);
   2.258 + 
   2.259 ++	*stack_out = stack;
   2.260 + 	return(pid);
   2.261 + }
   2.262 + 
   2.263 +@@ -183,12 +188,12 @@ static int start_ptraced_child(void)
   2.264 +  * just avoid using sysemu, not panic, but only if SYSEMU features are broken.
   2.265 +  * So only for SYSEMU features we test mustpanic, while normal host features
   2.266 +  * must work anyway!*/
   2.267 +-static int stop_ptraced_child(int pid, int exitcode, int mustexit)
   2.268 ++static int stop_ptraced_child(int pid, void *stack, int exitcode, int mustpanic)
   2.269 + {
   2.270 + 	int status, n, ret = 0;
   2.271 + 
   2.272 + 	if(ptrace(PTRACE_CONT, pid, 0, 0) < 0)
   2.273 +-		panic("stop_ptraced_child : ptrace failed, errno = %d", errno);
   2.274 ++		panic("check_ptrace : ptrace failed, errno = %d", errno);
   2.275 + 	CATCH_EINTR(n = waitpid(pid, &status, 0));
   2.276 + 	if(!WIFEXITED(status) || (WEXITSTATUS(status) != exitcode)) {
   2.277 + 		int exit_with = WEXITSTATUS(status);
   2.278 +@@ -199,13 +204,15 @@ static int stop_ptraced_child(int pid, i
   2.279 + 		printk("check_ptrace : child exited with exitcode %d, while "
   2.280 + 		      "expecting %d; status 0x%x", exit_with,
   2.281 + 		      exitcode, status);
   2.282 +-		if (mustexit)
   2.283 ++		if (mustpanic)
   2.284 + 			panic("\n");
   2.285 + 		else
   2.286 + 			printk("\n");
   2.287 + 		ret = -1;
   2.288 + 	}
   2.289 + 
   2.290 ++	if(munmap(stack, PAGE_SIZE) < 0)
   2.291 ++		panic("check_ptrace : munmap failed, errno = %d", errno);
   2.292 + 	return ret;
   2.293 + }
   2.294 + 
   2.295 +@@ -227,11 +234,12 @@ __uml_setup("nosysemu", nosysemu_cmd_par
   2.296 + 
   2.297 + static void __init check_sysemu(void)
   2.298 + {
   2.299 ++	void *stack;
   2.300 + 	int pid, syscall, n, status, count=0;
   2.301 + 
   2.302 + 	printk("Checking syscall emulation patch for ptrace...");
   2.303 + 	sysemu_supported = 0;
   2.304 +-	pid = start_ptraced_child();
   2.305 ++	pid = start_ptraced_child(&stack);
   2.306 + 
   2.307 + 	if(ptrace(PTRACE_SYSEMU, pid, 0, 0) < 0)
   2.308 + 		goto fail;
   2.309 +@@ -249,7 +257,7 @@ static void __init check_sysemu(void)
   2.310 + 		panic("check_sysemu : failed to modify system "
   2.311 + 		      "call return, errno = %d", errno);
   2.312 + 
   2.313 +-	if (stop_ptraced_child(pid, 0, 0) < 0)
   2.314 ++	if (stop_ptraced_child(pid, stack, 0, 0) < 0)
   2.315 + 		goto fail_stopped;
   2.316 + 
   2.317 + 	sysemu_supported = 1;
   2.318 +@@ -257,7 +265,7 @@ static void __init check_sysemu(void)
   2.319 + 	set_using_sysemu(!force_sysemu_disabled);
   2.320 + 
   2.321 + 	printk("Checking advanced syscall emulation patch for ptrace...");
   2.322 +-	pid = start_ptraced_child();
   2.323 ++	pid = start_ptraced_child(&stack);
   2.324 + 	while(1){
   2.325 + 		count++;
   2.326 + 		if(ptrace(PTRACE_SYSEMU_SINGLESTEP, pid, 0, 0) < 0)
   2.327 +@@ -282,7 +290,7 @@ static void __init check_sysemu(void)
   2.328 + 			break;
   2.329 + 		}
   2.330 + 	}
   2.331 +-	if (stop_ptraced_child(pid, 0, 0) < 0)
   2.332 ++	if (stop_ptraced_child(pid, stack, 0, 0) < 0)
   2.333 + 		goto fail_stopped;
   2.334 + 
   2.335 + 	sysemu_supported = 2;
   2.336 +@@ -293,17 +301,18 @@ static void __init check_sysemu(void)
   2.337 + 	return;
   2.338 + 
   2.339 + fail:
   2.340 +-	stop_ptraced_child(pid, 1, 0);
   2.341 ++	stop_ptraced_child(pid, stack, 1, 0);
   2.342 + fail_stopped:
   2.343 + 	printk("missing\n");
   2.344 + }
   2.345 + 
   2.346 + void __init check_ptrace(void)
   2.347 + {
   2.348 ++	void *stack;
   2.349 + 	int pid, syscall, n, status;
   2.350 + 
   2.351 + 	printk("Checking that ptrace can change system call numbers...");
   2.352 +-	pid = start_ptraced_child();
   2.353 ++	pid = start_ptraced_child(&stack);
   2.354 + 
   2.355 + 	if (ptrace(PTRACE_OLDSETOPTIONS, pid, 0, (void *)PTRACE_O_TRACESYSGOOD) < 0)
   2.356 + 		panic("check_ptrace: PTRACE_SETOPTIONS failed, errno = %d", errno);
   2.357 +@@ -330,7 +339,7 @@ void __init check_ptrace(void)
   2.358 + 			break;
   2.359 + 		}
   2.360 + 	}
   2.361 +-	stop_ptraced_child(pid, 0, 1);
   2.362 ++	stop_ptraced_child(pid, stack, 0, 1);
   2.363 + 	printk("OK\n");
   2.364 + 	check_sysemu();
   2.365 + }
   2.366 +@@ -362,10 +371,11 @@ void forward_pending_sigio(int target)
   2.367 + static inline int check_skas3_ptrace_support(void)
   2.368 + {
   2.369 + 	struct ptrace_faultinfo fi;
   2.370 ++	void *stack;
   2.371 + 	int pid, n, ret = 1;
   2.372 + 
   2.373 + 	printf("Checking for the skas3 patch in the host...");
   2.374 +-	pid = start_ptraced_child();
   2.375 ++	pid = start_ptraced_child(&stack);
   2.376 + 
   2.377 + 	n = ptrace(PTRACE_FAULTINFO, pid, 0, &fi);
   2.378 + 	if (n < 0) {
   2.379 +@@ -380,7 +390,7 @@ static inline int check_skas3_ptrace_sup
   2.380 + 	}
   2.381 + 
   2.382 + 	init_registers(pid);
   2.383 +-	stop_ptraced_child(pid, 1, 1);
   2.384 ++	stop_ptraced_child(pid, stack, 1, 1);
   2.385 + 
   2.386 + 	return(ret);
   2.387 + }
   2.388 +diff --git a/arch/x86_64/ia32/syscall32.c b/arch/x86_64/ia32/syscall32.c
   2.389 +--- a/arch/x86_64/ia32/syscall32.c
   2.390 ++++ b/arch/x86_64/ia32/syscall32.c
   2.391 +@@ -57,6 +57,7 @@ int syscall32_setup_pages(struct linux_b
   2.392 + 	int npages = (VSYSCALL32_END - VSYSCALL32_BASE) >> PAGE_SHIFT;
   2.393 + 	struct vm_area_struct *vma;
   2.394 + 	struct mm_struct *mm = current->mm;
   2.395 ++	int ret;
   2.396 + 
   2.397 + 	vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
   2.398 + 	if (!vma)
   2.399 +@@ -78,7 +79,11 @@ int syscall32_setup_pages(struct linux_b
   2.400 + 	vma->vm_mm = mm;
   2.401 + 
   2.402 + 	down_write(&mm->mmap_sem);
   2.403 +-	insert_vm_struct(mm, vma);
   2.404 ++	if ((ret = insert_vm_struct(mm, vma))) {
   2.405 ++		up_write(&mm->mmap_sem);
   2.406 ++		kmem_cache_free(vm_area_cachep, vma);
   2.407 ++		return ret;
   2.408 ++	}
   2.409 + 	mm->total_vm += npages;
   2.410 + 	up_write(&mm->mmap_sem);
   2.411 + 	return 0;
   2.412 +diff --git a/arch/x86_64/kernel/setup.c b/arch/x86_64/kernel/setup.c
   2.413 +--- a/arch/x86_64/kernel/setup.c
   2.414 ++++ b/arch/x86_64/kernel/setup.c
   2.415 +@@ -729,8 +729,6 @@ static void __init amd_detect_cmp(struct
   2.416 + 	int cpu = smp_processor_id();
   2.417 + 	int node = 0;
   2.418 + 	unsigned bits;
   2.419 +-	if (c->x86_num_cores == 1)
   2.420 +-		return;
   2.421 + 
   2.422 + 	bits = 0;
   2.423 + 	while ((1 << bits) < c->x86_num_cores)
   2.424 +diff --git a/arch/x86_64/kernel/smp.c b/arch/x86_64/kernel/smp.c
   2.425 +--- a/arch/x86_64/kernel/smp.c
   2.426 ++++ b/arch/x86_64/kernel/smp.c
   2.427 +@@ -284,6 +284,71 @@ struct call_data_struct {
   2.428 + static struct call_data_struct * call_data;
   2.429 + 
   2.430 + /*
   2.431 ++ * this function sends a 'generic call function' IPI to one other CPU
   2.432 ++ * in the system.
   2.433 ++ */
   2.434 ++static void __smp_call_function_single (int cpu, void (*func) (void *info), void *info,
   2.435 ++				int nonatomic, int wait)
   2.436 ++{
   2.437 ++	struct call_data_struct data;
   2.438 ++	int cpus = 1;
   2.439 ++
   2.440 ++	data.func = func;
   2.441 ++	data.info = info;
   2.442 ++	atomic_set(&data.started, 0);
   2.443 ++	data.wait = wait;
   2.444 ++	if (wait)
   2.445 ++		atomic_set(&data.finished, 0);
   2.446 ++
   2.447 ++	call_data = &data;
   2.448 ++	wmb();
   2.449 ++	/* Send a message to all other CPUs and wait for them to respond */
   2.450 ++	send_IPI_mask(cpumask_of_cpu(cpu), CALL_FUNCTION_VECTOR);
   2.451 ++
   2.452 ++	/* Wait for response */
   2.453 ++	while (atomic_read(&data.started) != cpus)
   2.454 ++		cpu_relax();
   2.455 ++
   2.456 ++	if (!wait)
   2.457 ++		return;
   2.458 ++
   2.459 ++	while (atomic_read(&data.finished) != cpus)
   2.460 ++		cpu_relax();
   2.461 ++}
   2.462 ++
   2.463 ++/*
   2.464 ++ * Run a function on another CPU
   2.465 ++ *  <func>	The function to run. This must be fast and non-blocking.
   2.466 ++ *  <info>	An arbitrary pointer to pass to the function.
   2.467 ++ *  <nonatomic>	Currently unused.
   2.468 ++ *  <wait>	If true, wait until function has completed on other CPUs.
   2.469 ++ *  [RETURNS]   0 on success, else a negative status code.
   2.470 ++ *
   2.471 ++ * Does not return until the remote CPU is nearly ready to execute <func>
   2.472 ++ * or is or has executed.
   2.473 ++ */
   2.474 ++
   2.475 ++int smp_call_function_single (int cpu, void (*func) (void *info), void *info, 
   2.476 ++	int nonatomic, int wait)
   2.477 ++{
   2.478 ++	
   2.479 ++	int me = get_cpu(); /* prevent preemption and reschedule on another processor */
   2.480 ++
   2.481 ++	if (cpu == me) {
   2.482 ++		printk("%s: trying to call self\n", __func__);
   2.483 ++		put_cpu();
   2.484 ++		return -EBUSY;
   2.485 ++	}
   2.486 ++	spin_lock_bh(&call_lock);
   2.487 ++
   2.488 ++	__smp_call_function_single(cpu, func,info,nonatomic,wait);	
   2.489 ++
   2.490 ++	spin_unlock_bh(&call_lock);
   2.491 ++	put_cpu();
   2.492 ++	return 0;
   2.493 ++}
   2.494 ++
   2.495 ++/*
   2.496 +  * this function sends a 'generic call function' IPI to all other CPUs
   2.497 +  * in the system.
   2.498 +  */
   2.499 +diff --git a/arch/x86_64/kernel/smpboot.c b/arch/x86_64/kernel/smpboot.c
   2.500 +--- a/arch/x86_64/kernel/smpboot.c
   2.501 ++++ b/arch/x86_64/kernel/smpboot.c
   2.502 +@@ -202,9 +202,6 @@ static __cpuinit void sync_master(void *
   2.503 + {
   2.504 + 	unsigned long flags, i;
   2.505 + 
   2.506 +-	if (smp_processor_id() != boot_cpu_id)
   2.507 +-		return;
   2.508 +-
   2.509 + 	go[MASTER] = 0;
   2.510 + 
   2.511 + 	local_irq_save(flags);
   2.512 +@@ -253,7 +250,7 @@ get_delta(long *rt, long *master)
   2.513 + 	return tcenter - best_tm;
   2.514 + }
   2.515 + 
   2.516 +-static __cpuinit void sync_tsc(void)
   2.517 ++static __cpuinit void sync_tsc(unsigned int master)
   2.518 + {
   2.519 + 	int i, done = 0;
   2.520 + 	long delta, adj, adjust_latency = 0;
   2.521 +@@ -267,9 +264,17 @@ static __cpuinit void sync_tsc(void)
   2.522 + 	} t[NUM_ROUNDS] __cpuinitdata;
   2.523 + #endif
   2.524 + 
   2.525 ++	printk(KERN_INFO "CPU %d: Syncing TSC to CPU %u.\n",
   2.526 ++		smp_processor_id(), master);
   2.527 ++
   2.528 + 	go[MASTER] = 1;
   2.529 + 
   2.530 +-	smp_call_function(sync_master, NULL, 1, 0);
   2.531 ++	/* It is dangerous to broadcast IPI as cpus are coming up,
   2.532 ++	 * as they may not be ready to accept them.  So since
   2.533 ++	 * we only need to send the ipi to the boot cpu direct
   2.534 ++	 * the message, and avoid the race.
   2.535 ++	 */
   2.536 ++	smp_call_function_single(master, sync_master, NULL, 1, 0);
   2.537 + 
   2.538 + 	while (go[MASTER])	/* wait for master to be ready */
   2.539 + 		no_cpu_relax();
   2.540 +@@ -313,16 +318,14 @@ static __cpuinit void sync_tsc(void)
   2.541 + 	printk(KERN_INFO
   2.542 + 	       "CPU %d: synchronized TSC with CPU %u (last diff %ld cycles, "
   2.543 + 	       "maxerr %lu cycles)\n",
   2.544 +-	       smp_processor_id(), boot_cpu_id, delta, rt);
   2.545 ++	       smp_processor_id(), master, delta, rt);
   2.546 + }
   2.547 + 
   2.548 + static void __cpuinit tsc_sync_wait(void)
   2.549 + {
   2.550 + 	if (notscsync || !cpu_has_tsc)
   2.551 + 		return;
   2.552 +-	printk(KERN_INFO "CPU %d: Syncing TSC to CPU %u.\n", smp_processor_id(),
   2.553 +-			boot_cpu_id);
   2.554 +-	sync_tsc();
   2.555 ++	sync_tsc(0);
   2.556 + }
   2.557 + 
   2.558 + static __init int notscsync_setup(char *s)
   2.559 +diff --git a/drivers/acpi/pci_irq.c b/drivers/acpi/pci_irq.c
   2.560 +--- a/drivers/acpi/pci_irq.c
   2.561 ++++ b/drivers/acpi/pci_irq.c
   2.562 +@@ -433,8 +433,9 @@ acpi_pci_irq_enable (
   2.563 + 		printk(KERN_WARNING PREFIX "PCI Interrupt %s[%c]: no GSI",
   2.564 + 			pci_name(dev), ('A' + pin));
   2.565 + 		/* Interrupt Line values above 0xF are forbidden */
   2.566 +-		if (dev->irq >= 0 && (dev->irq <= 0xF)) {
   2.567 ++		if (dev->irq > 0 && (dev->irq <= 0xF)) {
   2.568 + 			printk(" - using IRQ %d\n", dev->irq);
   2.569 ++			acpi_register_gsi(dev->irq, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
   2.570 + 			return_VALUE(0);
   2.571 + 		}
   2.572 + 		else {
   2.573 +diff --git a/drivers/char/rocket.c b/drivers/char/rocket.c
   2.574 +--- a/drivers/char/rocket.c
   2.575 ++++ b/drivers/char/rocket.c
   2.576 +@@ -277,7 +277,7 @@ static void rp_do_receive(struct r_port 
   2.577 + 		ToRecv = space;
   2.578 + 
   2.579 + 	if (ToRecv <= 0)
   2.580 +-		return;
   2.581 ++		goto done;
   2.582 + 
   2.583 + 	/*
   2.584 + 	 * if status indicates there are errored characters in the
   2.585 +@@ -359,6 +359,7 @@ static void rp_do_receive(struct r_port 
   2.586 + 	}
   2.587 + 	/*  Push the data up to the tty layer */
   2.588 + 	ld->receive_buf(tty, tty->flip.char_buf, tty->flip.flag_buf, count);
   2.589 ++done:
   2.590 + 	tty_ldisc_deref(ld);
   2.591 + }
   2.592 + 
   2.593 +diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
   2.594 +--- a/drivers/char/tpm/tpm.c
   2.595 ++++ b/drivers/char/tpm/tpm.c
   2.596 +@@ -32,12 +32,6 @@
   2.597 + 
   2.598 + #define	TPM_BUFSIZE			2048
   2.599 + 
   2.600 +-/* PCI configuration addresses */
   2.601 +-#define	PCI_GEN_PMCON_1			0xA0
   2.602 +-#define	PCI_GEN1_DEC			0xE4
   2.603 +-#define	PCI_LPC_EN			0xE6
   2.604 +-#define	PCI_GEN2_DEC			0xEC
   2.605 +-
   2.606 + static LIST_HEAD(tpm_chip_list);
   2.607 + static DEFINE_SPINLOCK(driver_lock);
   2.608 + static int dev_mask[32];
   2.609 +@@ -61,72 +55,6 @@ void tpm_time_expired(unsigned long ptr)
   2.610 + EXPORT_SYMBOL_GPL(tpm_time_expired);
   2.611 + 
   2.612 + /*
   2.613 +- * Initialize the LPC bus and enable the TPM ports
   2.614 +- */
   2.615 +-int tpm_lpc_bus_init(struct pci_dev *pci_dev, u16 base)
   2.616 +-{
   2.617 +-	u32 lpcenable, tmp;
   2.618 +-	int is_lpcm = 0;
   2.619 +-
   2.620 +-	switch (pci_dev->vendor) {
   2.621 +-	case PCI_VENDOR_ID_INTEL:
   2.622 +-		switch (pci_dev->device) {
   2.623 +-		case PCI_DEVICE_ID_INTEL_82801CA_12:
   2.624 +-		case PCI_DEVICE_ID_INTEL_82801DB_12:
   2.625 +-			is_lpcm = 1;
   2.626 +-			break;
   2.627 +-		}
   2.628 +-		/* init ICH (enable LPC) */
   2.629 +-		pci_read_config_dword(pci_dev, PCI_GEN1_DEC, &lpcenable);
   2.630 +-		lpcenable |= 0x20000000;
   2.631 +-		pci_write_config_dword(pci_dev, PCI_GEN1_DEC, lpcenable);
   2.632 +-
   2.633 +-		if (is_lpcm) {
   2.634 +-			pci_read_config_dword(pci_dev, PCI_GEN1_DEC,
   2.635 +-					      &lpcenable);
   2.636 +-			if ((lpcenable & 0x20000000) == 0) {
   2.637 +-				dev_err(&pci_dev->dev,
   2.638 +-					"cannot enable LPC\n");
   2.639 +-				return -ENODEV;
   2.640 +-			}
   2.641 +-		}
   2.642 +-
   2.643 +-		/* initialize TPM registers */
   2.644 +-		pci_read_config_dword(pci_dev, PCI_GEN2_DEC, &tmp);
   2.645 +-
   2.646 +-		if (!is_lpcm)
   2.647 +-			tmp = (tmp & 0xFFFF0000) | (base & 0xFFF0);
   2.648 +-		else
   2.649 +-			tmp =
   2.650 +-			    (tmp & 0xFFFF0000) | (base & 0xFFF0) |
   2.651 +-			    0x00000001;
   2.652 +-
   2.653 +-		pci_write_config_dword(pci_dev, PCI_GEN2_DEC, tmp);
   2.654 +-
   2.655 +-		if (is_lpcm) {
   2.656 +-			pci_read_config_dword(pci_dev, PCI_GEN_PMCON_1,
   2.657 +-					      &tmp);
   2.658 +-			tmp |= 0x00000004;	/* enable CLKRUN */
   2.659 +-			pci_write_config_dword(pci_dev, PCI_GEN_PMCON_1,
   2.660 +-					       tmp);
   2.661 +-		}
   2.662 +-		tpm_write_index(0x0D, 0x55);	/* unlock 4F */
   2.663 +-		tpm_write_index(0x0A, 0x00);	/* int disable */
   2.664 +-		tpm_write_index(0x08, base);	/* base addr lo */
   2.665 +-		tpm_write_index(0x09, (base & 0xFF00) >> 8);	/* base addr hi */
   2.666 +-		tpm_write_index(0x0D, 0xAA);	/* lock 4F */
   2.667 +-		break;
   2.668 +-	case PCI_VENDOR_ID_AMD:
   2.669 +-		/* nothing yet */
   2.670 +-		break;
   2.671 +-	}
   2.672 +-
   2.673 +-	return 0;
   2.674 +-}
   2.675 +-
   2.676 +-EXPORT_SYMBOL_GPL(tpm_lpc_bus_init);
   2.677 +-
   2.678 +-/*
   2.679 +  * Internal kernel interface to transmit TPM commands
   2.680 +  */
   2.681 + static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
   2.682 +@@ -590,10 +518,6 @@ int tpm_pm_resume(struct pci_dev *pci_de
   2.683 + 	if (chip == NULL)
   2.684 + 		return -ENODEV;
   2.685 + 
   2.686 +-	spin_lock(&driver_lock);
   2.687 +-	tpm_lpc_bus_init(pci_dev, chip->vendor->base);
   2.688 +-	spin_unlock(&driver_lock);
   2.689 +-
   2.690 + 	return 0;
   2.691 + }
   2.692 + 
   2.693 +diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
   2.694 +--- a/drivers/char/tpm/tpm.h
   2.695 ++++ b/drivers/char/tpm/tpm.h
   2.696 +@@ -79,8 +79,6 @@ static inline void tpm_write_index(int i
   2.697 + }
   2.698 + 
   2.699 + extern void tpm_time_expired(unsigned long);
   2.700 +-extern int tpm_lpc_bus_init(struct pci_dev *, u16);
   2.701 +-
   2.702 + extern int tpm_register_hardware(struct pci_dev *,
   2.703 + 				 struct tpm_vendor_specific *);
   2.704 + extern int tpm_open(struct inode *, struct file *);
   2.705 +diff --git a/drivers/char/tpm/tpm_atmel.c b/drivers/char/tpm/tpm_atmel.c
   2.706 +--- a/drivers/char/tpm/tpm_atmel.c
   2.707 ++++ b/drivers/char/tpm/tpm_atmel.c
   2.708 +@@ -22,7 +22,10 @@
   2.709 + #include "tpm.h"
   2.710 + 
   2.711 + /* Atmel definitions */
   2.712 +-#define	TPM_ATML_BASE			0x400
   2.713 ++enum tpm_atmel_addr {
   2.714 ++	TPM_ATMEL_BASE_ADDR_LO = 0x08,
   2.715 ++	TPM_ATMEL_BASE_ADDR_HI = 0x09
   2.716 ++};
   2.717 + 
   2.718 + /* write status bits */
   2.719 + #define	ATML_STATUS_ABORT		0x01
   2.720 +@@ -127,7 +130,6 @@ static struct tpm_vendor_specific tpm_at
   2.721 + 	.cancel = tpm_atml_cancel,
   2.722 + 	.req_complete_mask = ATML_STATUS_BUSY | ATML_STATUS_DATA_AVAIL,
   2.723 + 	.req_complete_val = ATML_STATUS_DATA_AVAIL,
   2.724 +-	.base = TPM_ATML_BASE,
   2.725 + 	.miscdev = { .fops = &atmel_ops, },
   2.726 + };
   2.727 + 
   2.728 +@@ -136,14 +138,16 @@ static int __devinit tpm_atml_init(struc
   2.729 + {
   2.730 + 	u8 version[4];
   2.731 + 	int rc = 0;
   2.732 ++	int lo, hi;
   2.733 + 
   2.734 + 	if (pci_enable_device(pci_dev))
   2.735 + 		return -EIO;
   2.736 + 
   2.737 +-	if (tpm_lpc_bus_init(pci_dev, TPM_ATML_BASE)) {
   2.738 +-		rc = -ENODEV;
   2.739 +-		goto out_err;
   2.740 +-	}
   2.741 ++	lo = tpm_read_index( TPM_ATMEL_BASE_ADDR_LO );
   2.742 ++	hi = tpm_read_index( TPM_ATMEL_BASE_ADDR_HI );
   2.743 ++
   2.744 ++	tpm_atmel.base = (hi<<8)|lo;
   2.745 ++	dev_dbg( &pci_dev->dev, "Operating with base: 0x%x\n", tpm_atmel.base);
   2.746 + 
   2.747 + 	/* verify that it is an Atmel part */
   2.748 + 	if (tpm_read_index(4) != 'A' || tpm_read_index(5) != 'T'
   2.749 +diff --git a/drivers/char/tpm/tpm_nsc.c b/drivers/char/tpm/tpm_nsc.c
   2.750 +--- a/drivers/char/tpm/tpm_nsc.c
   2.751 ++++ b/drivers/char/tpm/tpm_nsc.c
   2.752 +@@ -24,6 +24,10 @@
   2.753 + /* National definitions */
   2.754 + #define	TPM_NSC_BASE			0x360
   2.755 + #define	TPM_NSC_IRQ			0x07
   2.756 ++#define	TPM_NSC_BASE0_HI		0x60
   2.757 ++#define	TPM_NSC_BASE0_LO		0x61
   2.758 ++#define	TPM_NSC_BASE1_HI		0x62
   2.759 ++#define	TPM_NSC_BASE1_LO		0x63
   2.760 + 
   2.761 + #define	NSC_LDN_INDEX			0x07
   2.762 + #define	NSC_SID_INDEX			0x20
   2.763 +@@ -234,7 +238,6 @@ static struct tpm_vendor_specific tpm_ns
   2.764 + 	.cancel = tpm_nsc_cancel,
   2.765 + 	.req_complete_mask = NSC_STATUS_OBF,
   2.766 + 	.req_complete_val = NSC_STATUS_OBF,
   2.767 +-	.base = TPM_NSC_BASE,
   2.768 + 	.miscdev = { .fops = &nsc_ops, },
   2.769 + 	
   2.770 + };
   2.771 +@@ -243,15 +246,16 @@ static int __devinit tpm_nsc_init(struct
   2.772 + 				  const struct pci_device_id *pci_id)
   2.773 + {
   2.774 + 	int rc = 0;
   2.775 ++	int lo, hi;
   2.776 ++
   2.777 ++	hi = tpm_read_index(TPM_NSC_BASE0_HI);
   2.778 ++	lo = tpm_read_index(TPM_NSC_BASE0_LO);
   2.779 ++
   2.780 ++	tpm_nsc.base = (hi<<8) | lo;
   2.781 + 
   2.782 + 	if (pci_enable_device(pci_dev))
   2.783 + 		return -EIO;
   2.784 + 
   2.785 +-	if (tpm_lpc_bus_init(pci_dev, TPM_NSC_BASE)) {
   2.786 +-		rc = -ENODEV;
   2.787 +-		goto out_err;
   2.788 +-	}
   2.789 +-
   2.790 + 	/* verify that it is a National part (SID) */
   2.791 + 	if (tpm_read_index(NSC_SID_INDEX) != 0xEF) {
   2.792 + 		rc = -ENODEV;
   2.793 +diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
   2.794 +--- a/drivers/char/tty_ioctl.c
   2.795 ++++ b/drivers/char/tty_ioctl.c
   2.796 +@@ -476,11 +476,11 @@ int n_tty_ioctl(struct tty_struct * tty,
   2.797 + 			ld = tty_ldisc_ref(tty);
   2.798 + 			switch (arg) {
   2.799 + 			case TCIFLUSH:
   2.800 +-				if (ld->flush_buffer)
   2.801 ++				if (ld && ld->flush_buffer)
   2.802 + 					ld->flush_buffer(tty);
   2.803 + 				break;
   2.804 + 			case TCIOFLUSH:
   2.805 +-				if (ld->flush_buffer)
   2.806 ++				if (ld && ld->flush_buffer)
   2.807 + 					ld->flush_buffer(tty);
   2.808 + 				/* fall through */
   2.809 + 			case TCOFLUSH:
   2.810 +diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
   2.811 +--- a/drivers/media/video/cx88/cx88-video.c
   2.812 ++++ b/drivers/media/video/cx88/cx88-video.c
   2.813 +@@ -261,7 +261,7 @@ static struct cx88_ctrl cx8800_ctls[] = 
   2.814 + 			.default_value = 0,
   2.815 + 			.type          = V4L2_CTRL_TYPE_INTEGER,
   2.816 + 		},
   2.817 +-		.off                   = 0,
   2.818 ++		.off                   = 128,
   2.819 + 		.reg                   = MO_HUE,
   2.820 + 		.mask                  = 0x00ff,
   2.821 + 		.shift                 = 0,
   2.822 +diff --git a/drivers/net/e1000/e1000_main.c b/drivers/net/e1000/e1000_main.c
   2.823 +--- a/drivers/net/e1000/e1000_main.c
   2.824 ++++ b/drivers/net/e1000/e1000_main.c
   2.825 +@@ -2307,6 +2307,7 @@ e1000_xmit_frame(struct sk_buff *skb, st
   2.826 + 	tso = e1000_tso(adapter, skb);
   2.827 + 	if (tso < 0) {
   2.828 + 		dev_kfree_skb_any(skb);
   2.829 ++		spin_unlock_irqrestore(&adapter->tx_lock, flags);
   2.830 + 		return NETDEV_TX_OK;
   2.831 + 	}
   2.832 + 
   2.833 +diff --git a/drivers/net/hamradio/Kconfig b/drivers/net/hamradio/Kconfig
   2.834 +--- a/drivers/net/hamradio/Kconfig
   2.835 ++++ b/drivers/net/hamradio/Kconfig
   2.836 +@@ -17,7 +17,7 @@ config MKISS
   2.837 + 
   2.838 + config 6PACK
   2.839 + 	tristate "Serial port 6PACK driver"
   2.840 +-	depends on AX25 && BROKEN_ON_SMP
   2.841 ++	depends on AX25
   2.842 + 	---help---
   2.843 + 	  6pack is a transmission protocol for the data exchange between your
   2.844 + 	  PC and your TNC (the Terminal Node Controller acts as a kind of
   2.845 +diff --git a/drivers/net/shaper.c b/drivers/net/shaper.c
   2.846 +--- a/drivers/net/shaper.c
   2.847 ++++ b/drivers/net/shaper.c
   2.848 +@@ -135,10 +135,8 @@ static int shaper_start_xmit(struct sk_b
   2.849 + {
   2.850 + 	struct shaper *shaper = dev->priv;
   2.851 +  	struct sk_buff *ptr;
   2.852 +-   
   2.853 +-	if (down_trylock(&shaper->sem))
   2.854 +-		return -1;
   2.855 + 
   2.856 ++	spin_lock(&shaper->lock);
   2.857 +  	ptr=shaper->sendq.prev;
   2.858 +  	
   2.859 +  	/*
   2.860 +@@ -232,7 +230,7 @@ static int shaper_start_xmit(struct sk_b
   2.861 +                 shaper->stats.collisions++;
   2.862 +  	}
   2.863 + 	shaper_kick(shaper);
   2.864 +-	up(&shaper->sem);
   2.865 ++	spin_unlock(&shaper->lock);
   2.866 +  	return 0;
   2.867 + }
   2.868 + 
   2.869 +@@ -271,11 +269,9 @@ static void shaper_timer(unsigned long d
   2.870 + {
   2.871 + 	struct shaper *shaper = (struct shaper *)data;
   2.872 + 
   2.873 +-	if (!down_trylock(&shaper->sem)) {
   2.874 +-		shaper_kick(shaper);
   2.875 +-		up(&shaper->sem);
   2.876 +-	} else
   2.877 +-		mod_timer(&shaper->timer, jiffies);
   2.878 ++	spin_lock(&shaper->lock);
   2.879 ++	shaper_kick(shaper);
   2.880 ++	spin_unlock(&shaper->lock);
   2.881 + }
   2.882 + 
   2.883 + /*
   2.884 +@@ -332,21 +328,6 @@ static void shaper_kick(struct shaper *s
   2.885 + 
   2.886 + 
   2.887 + /*
   2.888 +- *	Flush the shaper queues on a closedown
   2.889 +- */
   2.890 +- 
   2.891 +-static void shaper_flush(struct shaper *shaper)
   2.892 +-{
   2.893 +-	struct sk_buff *skb;
   2.894 +-
   2.895 +-	down(&shaper->sem);
   2.896 +-	while((skb=skb_dequeue(&shaper->sendq))!=NULL)
   2.897 +-		dev_kfree_skb(skb);
   2.898 +-	shaper_kick(shaper);
   2.899 +-	up(&shaper->sem);
   2.900 +-}
   2.901 +-
   2.902 +-/*
   2.903 +  *	Bring the interface up. We just disallow this until a 
   2.904 +  *	bind.
   2.905 +  */
   2.906 +@@ -375,7 +356,15 @@ static int shaper_open(struct net_device
   2.907 + static int shaper_close(struct net_device *dev)
   2.908 + {
   2.909 + 	struct shaper *shaper=dev->priv;
   2.910 +-	shaper_flush(shaper);
   2.911 ++	struct sk_buff *skb;
   2.912 ++
   2.913 ++	while ((skb = skb_dequeue(&shaper->sendq)) != NULL)
   2.914 ++		dev_kfree_skb(skb);
   2.915 ++
   2.916 ++	spin_lock_bh(&shaper->lock);
   2.917 ++	shaper_kick(shaper);
   2.918 ++	spin_unlock_bh(&shaper->lock);
   2.919 ++
   2.920 + 	del_timer_sync(&shaper->timer);
   2.921 + 	return 0;
   2.922 + }
   2.923 +@@ -576,6 +565,7 @@ static void shaper_init_priv(struct net_
   2.924 + 	init_timer(&sh->timer);
   2.925 + 	sh->timer.function=shaper_timer;
   2.926 + 	sh->timer.data=(unsigned long)sh;
   2.927 ++	spin_lock_init(&sh->lock);
   2.928 + }
   2.929 + 
   2.930 + /*
   2.931 +diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
   2.932 +--- a/drivers/pci/pci-driver.c
   2.933 ++++ b/drivers/pci/pci-driver.c
   2.934 +@@ -396,7 +396,7 @@ int pci_register_driver(struct pci_drive
   2.935 + 	/* FIXME, once all of the existing PCI drivers have been fixed to set
   2.936 + 	 * the pci shutdown function, this test can go away. */
   2.937 + 	if (!drv->driver.shutdown)
   2.938 +-		drv->driver.shutdown = pci_device_shutdown,
   2.939 ++		drv->driver.shutdown = pci_device_shutdown;
   2.940 + 	drv->driver.owner = drv->owner;
   2.941 + 	drv->driver.kobj.ktype = &pci_driver_kobj_type;
   2.942 + 	pci_init_dynids(&drv->dynids);
   2.943 +diff --git a/drivers/scsi/qla2xxx/qla_init.c b/drivers/scsi/qla2xxx/qla_init.c
   2.944 +--- a/drivers/scsi/qla2xxx/qla_init.c
   2.945 ++++ b/drivers/scsi/qla2xxx/qla_init.c
   2.946 +@@ -1914,9 +1914,11 @@ qla2x00_reg_remote_port(scsi_qla_host_t 
   2.947 + 		rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
   2.948 + 
   2.949 + 	fcport->rport = rport = fc_remote_port_add(ha->host, 0, &rport_ids);
   2.950 +-	if (!rport)
   2.951 ++	if (!rport) {
   2.952 + 		qla_printk(KERN_WARNING, ha,
   2.953 + 		    "Unable to allocate fc remote port!\n");
   2.954 ++		return;
   2.955 ++	}
   2.956 + 
   2.957 + 	if (rport->scsi_target_id != -1 && rport->scsi_target_id < MAX_TARGETS)
   2.958 + 		fcport->os_target_id = rport->scsi_target_id;
   2.959 +diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
   2.960 +--- a/drivers/scsi/qla2xxx/qla_os.c
   2.961 ++++ b/drivers/scsi/qla2xxx/qla_os.c
   2.962 +@@ -1150,7 +1150,7 @@ iospace_error_exit:
   2.963 +  */
   2.964 + int qla2x00_probe_one(struct pci_dev *pdev, struct qla_board_info *brd_info)
   2.965 + {
   2.966 +-	int	ret;
   2.967 ++	int	ret = -ENODEV;
   2.968 + 	device_reg_t __iomem *reg;
   2.969 + 	struct Scsi_Host *host;
   2.970 + 	scsi_qla_host_t *ha;
   2.971 +@@ -1161,7 +1161,7 @@ int qla2x00_probe_one(struct pci_dev *pd
   2.972 + 	fc_port_t *fcport;
   2.973 + 
   2.974 + 	if (pci_enable_device(pdev))
   2.975 +-		return -1;
   2.976 ++		goto probe_out;
   2.977 + 
   2.978 + 	host = scsi_host_alloc(&qla2x00_driver_template,
   2.979 + 	    sizeof(scsi_qla_host_t));
   2.980 +@@ -1183,9 +1183,8 @@ int qla2x00_probe_one(struct pci_dev *pd
   2.981 + 
   2.982 + 	/* Configure PCI I/O space */
   2.983 + 	ret = qla2x00_iospace_config(ha);
   2.984 +-	if (ret != 0) {
   2.985 +-		goto probe_alloc_failed;
   2.986 +-	}
   2.987 ++	if (ret)
   2.988 ++		goto probe_failed;
   2.989 + 
   2.990 + 	/* Sanitize the information from PCI BIOS. */
   2.991 + 	host->irq = pdev->irq;
   2.992 +@@ -1258,23 +1257,10 @@ int qla2x00_probe_one(struct pci_dev *pd
   2.993 + 		qla_printk(KERN_WARNING, ha,
   2.994 + 		    "[ERROR] Failed to allocate memory for adapter\n");
   2.995 + 
   2.996 +-		goto probe_alloc_failed;
   2.997 ++		ret = -ENOMEM;
   2.998 ++		goto probe_failed;
   2.999 + 	}
  2.1000 + 
  2.1001 +-	pci_set_drvdata(pdev, ha);
  2.1002 +-	host->this_id = 255;
  2.1003 +-	host->cmd_per_lun = 3;
  2.1004 +-	host->unique_id = ha->instance;
  2.1005 +-	host->max_cmd_len = MAX_CMDSZ;
  2.1006 +-	host->max_channel = ha->ports - 1;
  2.1007 +-	host->max_id = ha->max_targets;
  2.1008 +-	host->max_lun = ha->max_luns;
  2.1009 +-	host->transportt = qla2xxx_transport_template;
  2.1010 +-	if (scsi_add_host(host, &pdev->dev))
  2.1011 +-		goto probe_alloc_failed;
  2.1012 +-
  2.1013 +-	qla2x00_alloc_sysfs_attr(ha);
  2.1014 +-
  2.1015 + 	if (qla2x00_initialize_adapter(ha) &&
  2.1016 + 	    !(ha->device_flags & DFLG_NO_CABLE)) {
  2.1017 + 
  2.1018 +@@ -1285,11 +1271,10 @@ int qla2x00_probe_one(struct pci_dev *pd
  2.1019 + 		    "Adapter flags %x.\n",
  2.1020 + 		    ha->host_no, ha->device_flags));
  2.1021 + 
  2.1022 ++		ret = -ENODEV;
  2.1023 + 		goto probe_failed;
  2.1024 + 	}
  2.1025 + 
  2.1026 +-	qla2x00_init_host_attr(ha);
  2.1027 +-
  2.1028 + 	/*
  2.1029 + 	 * Startup the kernel thread for this host adapter
  2.1030 + 	 */
  2.1031 +@@ -1299,17 +1284,26 @@ int qla2x00_probe_one(struct pci_dev *pd
  2.1032 + 		qla_printk(KERN_WARNING, ha,
  2.1033 + 		    "Unable to start DPC thread!\n");
  2.1034 + 
  2.1035 ++		ret = -ENODEV;
  2.1036 + 		goto probe_failed;
  2.1037 + 	}
  2.1038 + 	wait_for_completion(&ha->dpc_inited);
  2.1039 + 
  2.1040 ++	host->this_id = 255;
  2.1041 ++	host->cmd_per_lun = 3;
  2.1042 ++	host->unique_id = ha->instance;
  2.1043 ++	host->max_cmd_len = MAX_CMDSZ;
  2.1044 ++	host->max_channel = ha->ports - 1;
  2.1045 ++	host->max_lun = MAX_LUNS;
  2.1046 ++	host->transportt = qla2xxx_transport_template;
  2.1047 ++
  2.1048 + 	if (IS_QLA2100(ha) || IS_QLA2200(ha))
  2.1049 + 		ret = request_irq(host->irq, qla2100_intr_handler,
  2.1050 + 		    SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  2.1051 + 	else
  2.1052 + 		ret = request_irq(host->irq, qla2300_intr_handler,
  2.1053 + 		    SA_INTERRUPT|SA_SHIRQ, ha->brd_info->drv_name, ha);
  2.1054 +-	if (ret != 0) {
  2.1055 ++	if (ret) {
  2.1056 + 		qla_printk(KERN_WARNING, ha,
  2.1057 + 		    "Failed to reserve interrupt %d already in use.\n",
  2.1058 + 		    host->irq);
  2.1059 +@@ -1363,9 +1357,18 @@ int qla2x00_probe_one(struct pci_dev *pd
  2.1060 + 		msleep(10);
  2.1061 + 	}
  2.1062 + 
  2.1063 ++	pci_set_drvdata(pdev, ha);
  2.1064 + 	ha->flags.init_done = 1;
  2.1065 + 	num_hosts++;
  2.1066 + 
  2.1067 ++	ret = scsi_add_host(host, &pdev->dev);
  2.1068 ++	if (ret)
  2.1069 ++		goto probe_failed;
  2.1070 ++
  2.1071 ++	qla2x00_alloc_sysfs_attr(ha);
  2.1072 ++
  2.1073 ++	qla2x00_init_host_attr(ha);
  2.1074 ++
  2.1075 + 	qla_printk(KERN_INFO, ha, "\n"
  2.1076 + 	    " QLogic Fibre Channel HBA Driver: %s\n"
  2.1077 + 	    "  QLogic %s - %s\n"
  2.1078 +@@ -1384,9 +1387,6 @@ int qla2x00_probe_one(struct pci_dev *pd
  2.1079 + probe_failed:
  2.1080 + 	fc_remove_host(ha->host);
  2.1081 + 
  2.1082 +-	scsi_remove_host(host);
  2.1083 +-
  2.1084 +-probe_alloc_failed:
  2.1085 + 	qla2x00_free_device(ha);
  2.1086 + 
  2.1087 + 	scsi_host_put(host);
  2.1088 +@@ -1394,7 +1394,8 @@ probe_alloc_failed:
  2.1089 + probe_disable_device:
  2.1090 + 	pci_disable_device(pdev);
  2.1091 + 
  2.1092 +-	return -1;
  2.1093 ++probe_out:
  2.1094 ++	return ret;
  2.1095 + }
  2.1096 + EXPORT_SYMBOL_GPL(qla2x00_probe_one);
  2.1097 + 
  2.1098 +diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
  2.1099 +--- a/drivers/scsi/sg.c
  2.1100 ++++ b/drivers/scsi/sg.c
  2.1101 +@@ -2969,23 +2969,22 @@ static void * dev_seq_start(struct seq_f
  2.1102 + {
  2.1103 + 	struct sg_proc_deviter * it = kmalloc(sizeof(*it), GFP_KERNEL);
  2.1104 + 
  2.1105 ++	s->private = it;
  2.1106 + 	if (! it)
  2.1107 + 		return NULL;
  2.1108 ++
  2.1109 + 	if (NULL == sg_dev_arr)
  2.1110 +-		goto err1;
  2.1111 ++		return NULL;
  2.1112 + 	it->index = *pos;
  2.1113 + 	it->max = sg_last_dev();
  2.1114 + 	if (it->index >= it->max)
  2.1115 +-		goto err1;
  2.1116 ++		return NULL;
  2.1117 + 	return it;
  2.1118 +-err1:
  2.1119 +-	kfree(it);
  2.1120 +-	return NULL;
  2.1121 + }
  2.1122 + 
  2.1123 + static void * dev_seq_next(struct seq_file *s, void *v, loff_t *pos)
  2.1124 + {
  2.1125 +-	struct sg_proc_deviter * it = (struct sg_proc_deviter *) v;
  2.1126 ++	struct sg_proc_deviter * it = s->private;
  2.1127 + 
  2.1128 + 	*pos = ++it->index;
  2.1129 + 	return (it->index < it->max) ? it : NULL;
  2.1130 +@@ -2993,7 +2992,9 @@ static void * dev_seq_next(struct seq_fi
  2.1131 + 
  2.1132 + static void dev_seq_stop(struct seq_file *s, void *v)
  2.1133 + {
  2.1134 +-	kfree (v);
  2.1135 ++	struct sg_proc_deviter * it = s->private;
  2.1136 ++
  2.1137 ++	kfree (it);
  2.1138 + }
  2.1139 + 
  2.1140 + static int sg_proc_open_dev(struct inode *inode, struct file *file)
  2.1141 +diff --git a/drivers/usb/net/usbnet.c b/drivers/usb/net/usbnet.c
  2.1142 +--- a/drivers/usb/net/usbnet.c
  2.1143 ++++ b/drivers/usb/net/usbnet.c
  2.1144 +@@ -1922,7 +1922,7 @@ static int genelink_rx_fixup (struct usb
  2.1145 + 
  2.1146 + 			// copy the packet data to the new skb
  2.1147 + 			memcpy(skb_put(gl_skb, size), packet->packet_data, size);
  2.1148 +-			skb_return (dev, skb);
  2.1149 ++			skb_return (dev, gl_skb);
  2.1150 + 		}
  2.1151 + 
  2.1152 + 		// advance to the next packet
  2.1153 +diff --git a/fs/bio.c b/fs/bio.c
  2.1154 +--- a/fs/bio.c
  2.1155 ++++ b/fs/bio.c
  2.1156 +@@ -261,6 +261,7 @@ inline void __bio_clone(struct bio *bio,
  2.1157 + 	 */
  2.1158 + 	bio->bi_vcnt = bio_src->bi_vcnt;
  2.1159 + 	bio->bi_size = bio_src->bi_size;
  2.1160 ++	bio->bi_idx = bio_src->bi_idx;
  2.1161 + 	bio_phys_segments(q, bio);
  2.1162 + 	bio_hw_segments(q, bio);
  2.1163 + }
  2.1164 +diff --git a/fs/char_dev.c b/fs/char_dev.c
  2.1165 +--- a/fs/char_dev.c
  2.1166 ++++ b/fs/char_dev.c
  2.1167 +@@ -139,7 +139,7 @@ __unregister_chrdev_region(unsigned majo
  2.1168 + 	struct char_device_struct *cd = NULL, **cp;
  2.1169 + 	int i = major_to_index(major);
  2.1170 + 
  2.1171 +-	up(&chrdevs_lock);
  2.1172 ++	down(&chrdevs_lock);
  2.1173 + 	for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
  2.1174 + 		if ((*cp)->major == major &&
  2.1175 + 		    (*cp)->baseminor == baseminor &&
  2.1176 +diff --git a/fs/exec.c b/fs/exec.c
  2.1177 +--- a/fs/exec.c
  2.1178 ++++ b/fs/exec.c
  2.1179 +@@ -649,6 +649,7 @@ static inline int de_thread(struct task_
  2.1180 + 	}
  2.1181 + 	sig->group_exit_task = NULL;
  2.1182 + 	sig->notify_count = 0;
  2.1183 ++	sig->real_timer.data = (unsigned long)current;
  2.1184 + 	spin_unlock_irq(lock);
  2.1185 + 
  2.1186 + 	/*
  2.1187 +diff --git a/fs/isofs/compress.c b/fs/isofs/compress.c
  2.1188 +--- a/fs/isofs/compress.c
  2.1189 ++++ b/fs/isofs/compress.c
  2.1190 +@@ -129,8 +129,14 @@ static int zisofs_readpage(struct file *
  2.1191 + 	cend = le32_to_cpu(*(__le32 *)(bh->b_data + (blockendptr & bufmask)));
  2.1192 + 	brelse(bh);
  2.1193 + 
  2.1194 ++	if (cstart > cend)
  2.1195 ++		goto eio;
  2.1196 ++		
  2.1197 + 	csize = cend-cstart;
  2.1198 + 
  2.1199 ++	if (csize > deflateBound(1UL << zisofs_block_shift))
  2.1200 ++		goto eio;
  2.1201 ++
  2.1202 + 	/* Now page[] contains an array of pages, any of which can be NULL,
  2.1203 + 	   and the locks on which we hold.  We should now read the data and
  2.1204 + 	   release the pages.  If the pages are NULL the decompressed data
  2.1205 +diff --git a/include/asm-i386/string.h b/include/asm-i386/string.h
  2.1206 +--- a/include/asm-i386/string.h
  2.1207 ++++ b/include/asm-i386/string.h
  2.1208 +@@ -116,7 +116,8 @@ __asm__ __volatile__(
  2.1209 + 	"orb $1,%%al\n"
  2.1210 + 	"3:"
  2.1211 + 	:"=a" (__res), "=&S" (d0), "=&D" (d1)
  2.1212 +-		     :"1" (cs),"2" (ct));
  2.1213 ++	:"1" (cs),"2" (ct)
  2.1214 ++	:"memory");
  2.1215 + return __res;
  2.1216 + }
  2.1217 + 
  2.1218 +@@ -138,8 +139,9 @@ __asm__ __volatile__(
  2.1219 + 	"3:\tsbbl %%eax,%%eax\n\t"
  2.1220 + 	"orb $1,%%al\n"
  2.1221 + 	"4:"
  2.1222 +-		     :"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
  2.1223 +-		     :"1" (cs),"2" (ct),"3" (count));
  2.1224 ++	:"=a" (__res), "=&S" (d0), "=&D" (d1), "=&c" (d2)
  2.1225 ++	:"1" (cs),"2" (ct),"3" (count)
  2.1226 ++	:"memory");
  2.1227 + return __res;
  2.1228 + }
  2.1229 + 
  2.1230 +@@ -158,7 +160,9 @@ __asm__ __volatile__(
  2.1231 + 	"movl $1,%1\n"
  2.1232 + 	"2:\tmovl %1,%0\n\t"
  2.1233 + 	"decl %0"
  2.1234 +-	:"=a" (__res), "=&S" (d0) : "1" (s),"0" (c));
  2.1235 ++	:"=a" (__res), "=&S" (d0)
  2.1236 ++	:"1" (s),"0" (c)
  2.1237 ++	:"memory");
  2.1238 + return __res;
  2.1239 + }
  2.1240 + 
  2.1241 +@@ -175,7 +179,9 @@ __asm__ __volatile__(
  2.1242 + 	"leal -1(%%esi),%0\n"
  2.1243 + 	"2:\ttestb %%al,%%al\n\t"
  2.1244 + 	"jne 1b"
  2.1245 +-	:"=g" (__res), "=&S" (d0), "=&a" (d1) :"0" (0),"1" (s),"2" (c));
  2.1246 ++	:"=g" (__res), "=&S" (d0), "=&a" (d1)
  2.1247 ++	:"0" (0),"1" (s),"2" (c)
  2.1248 ++	:"memory");
  2.1249 + return __res;
  2.1250 + }
  2.1251 + 
  2.1252 +@@ -189,7 +195,9 @@ __asm__ __volatile__(
  2.1253 + 	"scasb\n\t"
  2.1254 + 	"notl %0\n\t"
  2.1255 + 	"decl %0"
  2.1256 +-	:"=c" (__res), "=&D" (d0) :"1" (s),"a" (0), "0" (0xffffffffu));
  2.1257 ++	:"=c" (__res), "=&D" (d0)
  2.1258 ++	:"1" (s),"a" (0), "0" (0xffffffffu)
  2.1259 ++	:"memory");
  2.1260 + return __res;
  2.1261 + }
  2.1262 + 
  2.1263 +@@ -333,7 +341,9 @@ __asm__ __volatile__(
  2.1264 + 	"je 1f\n\t"
  2.1265 + 	"movl $1,%0\n"
  2.1266 + 	"1:\tdecl %0"
  2.1267 +-	:"=D" (__res), "=&c" (d0) : "a" (c),"0" (cs),"1" (count));
  2.1268 ++	:"=D" (__res), "=&c" (d0)
  2.1269 ++	:"a" (c),"0" (cs),"1" (count)
  2.1270 ++	:"memory");
  2.1271 + return __res;
  2.1272 + }
  2.1273 + 
  2.1274 +@@ -369,7 +379,7 @@ __asm__ __volatile__(
  2.1275 + 	"je 2f\n\t"
  2.1276 + 	"stosb\n"
  2.1277 + 	"2:"
  2.1278 +-	: "=&c" (d0), "=&D" (d1)
  2.1279 ++	:"=&c" (d0), "=&D" (d1)
  2.1280 + 	:"a" (c), "q" (count), "0" (count/4), "1" ((long) s)
  2.1281 + 	:"memory");
  2.1282 + return (s);	
  2.1283 +@@ -392,7 +402,8 @@ __asm__ __volatile__(
  2.1284 + 	"jne 1b\n"
  2.1285 + 	"3:\tsubl %2,%0"
  2.1286 + 	:"=a" (__res), "=&d" (d0)
  2.1287 +-	:"c" (s),"1" (count));
  2.1288 ++	:"c" (s),"1" (count)
  2.1289 ++	:"memory");
  2.1290 + return __res;
  2.1291 + }
  2.1292 + /* end of additional stuff */
  2.1293 +@@ -473,7 +484,8 @@ static inline void * memscan(void * addr
  2.1294 + 		"dec %%edi\n"
  2.1295 + 		"1:"
  2.1296 + 		: "=D" (addr), "=c" (size)
  2.1297 +-		: "0" (addr), "1" (size), "a" (c));
  2.1298 ++		: "0" (addr), "1" (size), "a" (c)
  2.1299 ++		: "memory");
  2.1300 + 	return addr;
  2.1301 + }
  2.1302 + 
  2.1303 +diff --git a/include/asm-x86_64/smp.h b/include/asm-x86_64/smp.h
  2.1304 +--- a/include/asm-x86_64/smp.h
  2.1305 ++++ b/include/asm-x86_64/smp.h
  2.1306 +@@ -46,6 +46,8 @@ extern int pic_mode;
  2.1307 + extern int smp_num_siblings;
  2.1308 + extern void smp_flush_tlb(void);
  2.1309 + extern void smp_message_irq(int cpl, void *dev_id, struct pt_regs *regs);
  2.1310 ++extern int smp_call_function_single (int cpuid, void (*func) (void *info), void *info,
  2.1311 ++				     int retry, int wait);
  2.1312 + extern void smp_send_reschedule(int cpu);
  2.1313 + extern void smp_invalidate_rcv(void);		/* Process an NMI */
  2.1314 + extern void zap_low_mappings(void);
  2.1315 +diff --git a/include/linux/if_shaper.h b/include/linux/if_shaper.h
  2.1316 +--- a/include/linux/if_shaper.h
  2.1317 ++++ b/include/linux/if_shaper.h
  2.1318 +@@ -23,7 +23,7 @@ struct shaper
  2.1319 + 	__u32 shapeclock;
  2.1320 + 	unsigned long recovery;	/* Time we can next clock a packet out on
  2.1321 + 				   an empty queue */
  2.1322 +-	struct semaphore sem;
  2.1323 ++	spinlock_t lock;
  2.1324 +         struct net_device_stats stats;
  2.1325 + 	struct net_device *dev;
  2.1326 + 	int  (*hard_start_xmit) (struct sk_buff *skb,
  2.1327 +diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
  2.1328 +--- a/include/linux/skbuff.h
  2.1329 ++++ b/include/linux/skbuff.h
  2.1330 +@@ -1192,7 +1192,7 @@ static inline void *skb_header_pointer(c
  2.1331 + {
  2.1332 + 	int hlen = skb_headlen(skb);
  2.1333 + 
  2.1334 +-	if (offset + len <= hlen)
  2.1335 ++	if (hlen - offset >= len)
  2.1336 + 		return skb->data + offset;
  2.1337 + 
  2.1338 + 	if (skb_copy_bits(skb, offset, buffer, len) < 0)
  2.1339 +diff --git a/include/linux/zlib.h b/include/linux/zlib.h
  2.1340 +--- a/include/linux/zlib.h
  2.1341 ++++ b/include/linux/zlib.h
  2.1342 +@@ -506,6 +506,11 @@ extern int zlib_deflateReset (z_streamp 
  2.1343 +    stream state was inconsistent (such as zalloc or state being NULL).
  2.1344 + */
  2.1345 + 
  2.1346 ++static inline unsigned long deflateBound(unsigned long s)
  2.1347 ++{
  2.1348 ++	return s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11;
  2.1349 ++}
  2.1350 ++
  2.1351 + extern int zlib_deflateParams (z_streamp strm, int level, int strategy);
  2.1352 + /*
  2.1353 +      Dynamically update the compression level and compression strategy.  The
  2.1354 +diff --git a/kernel/module.c b/kernel/module.c
  2.1355 +--- a/kernel/module.c
  2.1356 ++++ b/kernel/module.c
  2.1357 +@@ -249,13 +249,18 @@ static inline unsigned int block_size(in
  2.1358 + /* Created by linker magic */
  2.1359 + extern char __per_cpu_start[], __per_cpu_end[];
  2.1360 + 
  2.1361 +-static void *percpu_modalloc(unsigned long size, unsigned long align)
  2.1362 ++static void *percpu_modalloc(unsigned long size, unsigned long align,
  2.1363 ++			     const char *name)
  2.1364 + {
  2.1365 + 	unsigned long extra;
  2.1366 + 	unsigned int i;
  2.1367 + 	void *ptr;
  2.1368 + 
  2.1369 +-	BUG_ON(align > SMP_CACHE_BYTES);
  2.1370 ++	if (align > SMP_CACHE_BYTES) {
  2.1371 ++		printk(KERN_WARNING "%s: per-cpu alignment %li > %i\n",
  2.1372 ++		       name, align, SMP_CACHE_BYTES);
  2.1373 ++		align = SMP_CACHE_BYTES;
  2.1374 ++	}
  2.1375 + 
  2.1376 + 	ptr = __per_cpu_start;
  2.1377 + 	for (i = 0; i < pcpu_num_used; ptr += block_size(pcpu_size[i]), i++) {
  2.1378 +@@ -347,7 +352,8 @@ static int percpu_modinit(void)
  2.1379 + }	
  2.1380 + __initcall(percpu_modinit);
  2.1381 + #else /* ... !CONFIG_SMP */
  2.1382 +-static inline void *percpu_modalloc(unsigned long size, unsigned long align)
  2.1383 ++static inline void *percpu_modalloc(unsigned long size, unsigned long align,
  2.1384 ++				    const char *name)
  2.1385 + {
  2.1386 + 	return NULL;
  2.1387 + }
  2.1388 +@@ -1554,7 +1560,8 @@ static struct module *load_module(void _
  2.1389 + 	if (pcpuindex) {
  2.1390 + 		/* We have a special allocation for this section. */
  2.1391 + 		percpu = percpu_modalloc(sechdrs[pcpuindex].sh_size,
  2.1392 +-					 sechdrs[pcpuindex].sh_addralign);
  2.1393 ++					 sechdrs[pcpuindex].sh_addralign,
  2.1394 ++					 mod->name);
  2.1395 + 		if (!percpu) {
  2.1396 + 			err = -ENOMEM;
  2.1397 + 			goto free_mod;
  2.1398 +diff --git a/kernel/signal.c b/kernel/signal.c
  2.1399 +--- a/kernel/signal.c
  2.1400 ++++ b/kernel/signal.c
  2.1401 +@@ -686,7 +686,7 @@ static void handle_stop_signal(int sig, 
  2.1402 + {
  2.1403 + 	struct task_struct *t;
  2.1404 + 
  2.1405 +-	if (p->flags & SIGNAL_GROUP_EXIT)
  2.1406 ++	if (p->signal->flags & SIGNAL_GROUP_EXIT)
  2.1407 + 		/*
  2.1408 + 		 * The process is in the middle of dying already.
  2.1409 + 		 */
  2.1410 +diff --git a/lib/inflate.c b/lib/inflate.c
  2.1411 +--- a/lib/inflate.c
  2.1412 ++++ b/lib/inflate.c
  2.1413 +@@ -326,7 +326,7 @@ DEBG("huft1 ");
  2.1414 +   {
  2.1415 +     *t = (struct huft *)NULL;
  2.1416 +     *m = 0;
  2.1417 +-    return 0;
  2.1418 ++    return 2;
  2.1419 +   }
  2.1420 + 
  2.1421 + DEBG("huft2 ");
  2.1422 +@@ -374,6 +374,7 @@ DEBG("huft5 ");
  2.1423 +     if ((j = *p++) != 0)
  2.1424 +       v[x[j]++] = i;
  2.1425 +   } while (++i < n);
  2.1426 ++  n = x[g];                   /* set n to length of v */
  2.1427 + 
  2.1428 + DEBG("h6 ");
  2.1429 + 
  2.1430 +@@ -410,12 +411,13 @@ DEBG1("1 ");
  2.1431 + DEBG1("2 ");
  2.1432 +           f -= a + 1;           /* deduct codes from patterns left */
  2.1433 +           xp = c + k;
  2.1434 +-          while (++j < z)       /* try smaller tables up to z bits */
  2.1435 +-          {
  2.1436 +-            if ((f <<= 1) <= *++xp)
  2.1437 +-              break;            /* enough codes to use up j bits */
  2.1438 +-            f -= *xp;           /* else deduct codes from patterns */
  2.1439 +-          }
  2.1440 ++          if (j < z)
  2.1441 ++            while (++j < z)       /* try smaller tables up to z bits */
  2.1442 ++            {
  2.1443 ++              if ((f <<= 1) <= *++xp)
  2.1444 ++                break;            /* enough codes to use up j bits */
  2.1445 ++              f -= *xp;           /* else deduct codes from patterns */
  2.1446 ++            }
  2.1447 +         }
  2.1448 + DEBG1("3 ");
  2.1449 +         z = 1 << j;             /* table entries for j-bit table */
  2.1450 +diff --git a/mm/memory.c b/mm/memory.c
  2.1451 +--- a/mm/memory.c
  2.1452 ++++ b/mm/memory.c
  2.1453 +@@ -1164,7 +1164,7 @@ int remap_pfn_range(struct vm_area_struc
  2.1454 + {
  2.1455 + 	pgd_t *pgd;
  2.1456 + 	unsigned long next;
  2.1457 +-	unsigned long end = addr + size;
  2.1458 ++	unsigned long end = addr + PAGE_ALIGN(size);
  2.1459 + 	struct mm_struct *mm = vma->vm_mm;
  2.1460 + 	int err;
  2.1461 + 
  2.1462 +diff --git a/mm/mempolicy.c b/mm/mempolicy.c
  2.1463 +--- a/mm/mempolicy.c
  2.1464 ++++ b/mm/mempolicy.c
  2.1465 +@@ -409,7 +409,7 @@ asmlinkage long sys_set_mempolicy(int mo
  2.1466 + 	struct mempolicy *new;
  2.1467 + 	DECLARE_BITMAP(nodes, MAX_NUMNODES);
  2.1468 + 
  2.1469 +-	if (mode > MPOL_MAX)
  2.1470 ++	if (mode < 0 || mode > MPOL_MAX)
  2.1471 + 		return -EINVAL;
  2.1472 + 	err = get_nodes(nodes, nmask, maxnode, mode);
  2.1473 + 	if (err)
  2.1474 +diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
  2.1475 +--- a/net/8021q/vlan.c
  2.1476 ++++ b/net/8021q/vlan.c
  2.1477 +@@ -578,6 +578,14 @@ static int vlan_device_event(struct noti
  2.1478 + 			if (!vlandev)
  2.1479 + 				continue;
  2.1480 + 
  2.1481 ++			if (netif_carrier_ok(dev)) {
  2.1482 ++				if (!netif_carrier_ok(vlandev))
  2.1483 ++					netif_carrier_on(vlandev);
  2.1484 ++			} else {
  2.1485 ++				if (netif_carrier_ok(vlandev))
  2.1486 ++					netif_carrier_off(vlandev);
  2.1487 ++			}
  2.1488 ++
  2.1489 + 			if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
  2.1490 + 				vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK) 
  2.1491 + 					| flgs;
  2.1492 +diff --git a/net/ipv4/icmp.c b/net/ipv4/icmp.c
  2.1493 +--- a/net/ipv4/icmp.c
  2.1494 ++++ b/net/ipv4/icmp.c
  2.1495 +@@ -349,12 +349,12 @@ static void icmp_push_reply(struct icmp_
  2.1496 + {
  2.1497 + 	struct sk_buff *skb;
  2.1498 + 
  2.1499 +-	ip_append_data(icmp_socket->sk, icmp_glue_bits, icmp_param,
  2.1500 +-		       icmp_param->data_len+icmp_param->head_len,
  2.1501 +-		       icmp_param->head_len,
  2.1502 +-		       ipc, rt, MSG_DONTWAIT);
  2.1503 +-
  2.1504 +-	if ((skb = skb_peek(&icmp_socket->sk->sk_write_queue)) != NULL) {
  2.1505 ++	if (ip_append_data(icmp_socket->sk, icmp_glue_bits, icmp_param,
  2.1506 ++		           icmp_param->data_len+icmp_param->head_len,
  2.1507 ++		           icmp_param->head_len,
  2.1508 ++		           ipc, rt, MSG_DONTWAIT) < 0)
  2.1509 ++		ip_flush_pending_frames(icmp_socket->sk);
  2.1510 ++	else if ((skb = skb_peek(&icmp_socket->sk->sk_write_queue)) != NULL) {
  2.1511 + 		struct icmphdr *icmph = skb->h.icmph;
  2.1512 + 		unsigned int csum = 0;
  2.1513 + 		struct sk_buff *skb1;
  2.1514 +diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
  2.1515 +--- a/net/ipv4/ip_output.c
  2.1516 ++++ b/net/ipv4/ip_output.c
  2.1517 +@@ -111,7 +111,6 @@ static int ip_dev_loopback_xmit(struct s
  2.1518 + #ifdef CONFIG_NETFILTER_DEBUG
  2.1519 + 	nf_debug_ip_loopback_xmit(newskb);
  2.1520 + #endif
  2.1521 +-	nf_reset(newskb);
  2.1522 + 	netif_rx(newskb);
  2.1523 + 	return 0;
  2.1524 + }
  2.1525 +@@ -196,8 +195,6 @@ static inline int ip_finish_output2(stru
  2.1526 + 	nf_debug_ip_finish_output2(skb);
  2.1527 + #endif /*CONFIG_NETFILTER_DEBUG*/
  2.1528 + 
  2.1529 +-	nf_reset(skb);
  2.1530 +-
  2.1531 + 	if (hh) {
  2.1532 + 		int hh_alen;
  2.1533 + 
  2.1534 +diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
  2.1535 +--- a/net/ipv4/ip_sockglue.c
  2.1536 ++++ b/net/ipv4/ip_sockglue.c
  2.1537 +@@ -848,6 +848,9 @@ mc_msf_out:
  2.1538 +  
  2.1539 + 		case IP_IPSEC_POLICY:
  2.1540 + 		case IP_XFRM_POLICY:
  2.1541 ++			err = -EPERM;
  2.1542 ++			if (!capable(CAP_NET_ADMIN))
  2.1543 ++				break;
  2.1544 + 			err = xfrm_user_policy(sk, optname, optval, optlen);
  2.1545 + 			break;
  2.1546 + 
  2.1547 +diff --git a/net/ipv4/netfilter/ip_conntrack_core.c b/net/ipv4/netfilter/ip_conntrack_core.c
  2.1548 +--- a/net/ipv4/netfilter/ip_conntrack_core.c
  2.1549 ++++ b/net/ipv4/netfilter/ip_conntrack_core.c
  2.1550 +@@ -1124,6 +1124,9 @@ void ip_conntrack_cleanup(void)
  2.1551 + 		schedule();
  2.1552 + 		goto i_see_dead_people;
  2.1553 + 	}
  2.1554 ++	/* wait until all references to ip_conntrack_untracked are dropped */
  2.1555 ++	while (atomic_read(&ip_conntrack_untracked.ct_general.use) > 1)
  2.1556 ++		schedule();
  2.1557 + 
  2.1558 + 	kmem_cache_destroy(ip_conntrack_cachep);
  2.1559 + 	kmem_cache_destroy(ip_conntrack_expect_cachep);
  2.1560 +diff --git a/net/ipv4/netfilter/ip_conntrack_standalone.c b/net/ipv4/netfilter/ip_conntrack_standalone.c
  2.1561 +--- a/net/ipv4/netfilter/ip_conntrack_standalone.c
  2.1562 ++++ b/net/ipv4/netfilter/ip_conntrack_standalone.c
  2.1563 +@@ -432,6 +432,13 @@ static unsigned int ip_conntrack_defrag(
  2.1564 + 				        const struct net_device *out,
  2.1565 + 				        int (*okfn)(struct sk_buff *))
  2.1566 + {
  2.1567 ++#if !defined(CONFIG_IP_NF_NAT) && !defined(CONFIG_IP_NF_NAT_MODULE)
  2.1568 ++	/* Previously seen (loopback)?  Ignore.  Do this before
  2.1569 ++           fragment check. */
  2.1570 ++	if ((*pskb)->nfct)
  2.1571 ++		return NF_ACCEPT;
  2.1572 ++#endif
  2.1573 ++
  2.1574 + 	/* Gather fragments. */
  2.1575 + 	if ((*pskb)->nh.iph->frag_off & htons(IP_MF|IP_OFFSET)) {
  2.1576 + 		*pskb = ip_ct_gather_frags(*pskb,
  2.1577 +diff --git a/net/ipv4/netfilter/ip_nat_proto_tcp.c b/net/ipv4/netfilter/ip_nat_proto_tcp.c
  2.1578 +--- a/net/ipv4/netfilter/ip_nat_proto_tcp.c
  2.1579 ++++ b/net/ipv4/netfilter/ip_nat_proto_tcp.c
  2.1580 +@@ -40,7 +40,8 @@ tcp_unique_tuple(struct ip_conntrack_tup
  2.1581 + 		 enum ip_nat_manip_type maniptype,
  2.1582 + 		 const struct ip_conntrack *conntrack)
  2.1583 + {
  2.1584 +-	static u_int16_t port, *portptr;
  2.1585 ++	static u_int16_t port;
  2.1586 ++	u_int16_t *portptr;
  2.1587 + 	unsigned int range_size, min, i;
  2.1588 + 
  2.1589 + 	if (maniptype == IP_NAT_MANIP_SRC)
  2.1590 +diff --git a/net/ipv4/netfilter/ip_nat_proto_udp.c b/net/ipv4/netfilter/ip_nat_proto_udp.c
  2.1591 +--- a/net/ipv4/netfilter/ip_nat_proto_udp.c
  2.1592 ++++ b/net/ipv4/netfilter/ip_nat_proto_udp.c
  2.1593 +@@ -41,7 +41,8 @@ udp_unique_tuple(struct ip_conntrack_tup
  2.1594 + 		 enum ip_nat_manip_type maniptype,
  2.1595 + 		 const struct ip_conntrack *conntrack)
  2.1596 + {
  2.1597 +-	static u_int16_t port, *portptr;
  2.1598 ++	static u_int16_t port;
  2.1599 ++	u_int16_t *portptr;
  2.1600 + 	unsigned int range_size, min, i;
  2.1601 + 
  2.1602 + 	if (maniptype == IP_NAT_MANIP_SRC)
  2.1603 +diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
  2.1604 +--- a/net/ipv6/ip6_input.c
  2.1605 ++++ b/net/ipv6/ip6_input.c
  2.1606 +@@ -198,12 +198,13 @@ resubmit:
  2.1607 + 		if (!raw_sk) {
  2.1608 + 			if (xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
  2.1609 + 				IP6_INC_STATS_BH(IPSTATS_MIB_INUNKNOWNPROTOS);
  2.1610 +-				icmpv6_param_prob(skb, ICMPV6_UNK_NEXTHDR, nhoff);
  2.1611 ++				icmpv6_send(skb, ICMPV6_PARAMPROB,
  2.1612 ++				            ICMPV6_UNK_NEXTHDR, nhoff,
  2.1613 ++				            skb->dev);
  2.1614 + 			}
  2.1615 +-		} else {
  2.1616 ++		} else
  2.1617 + 			IP6_INC_STATS_BH(IPSTATS_MIB_INDELIVERS);
  2.1618 +-			kfree_skb(skb);
  2.1619 +-		}
  2.1620 ++		kfree_skb(skb);
  2.1621 + 	}
  2.1622 + 	rcu_read_unlock();
  2.1623 + 	return 0;
  2.1624 +diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
  2.1625 +--- a/net/ipv6/ipv6_sockglue.c
  2.1626 ++++ b/net/ipv6/ipv6_sockglue.c
  2.1627 +@@ -503,6 +503,9 @@ done:
  2.1628 + 		break;
  2.1629 + 	case IPV6_IPSEC_POLICY:
  2.1630 + 	case IPV6_XFRM_POLICY:
  2.1631 ++		retv = -EPERM;
  2.1632 ++		if (!capable(CAP_NET_ADMIN))
  2.1633 ++			break;
  2.1634 + 		retv = xfrm_user_policy(sk, optname, optval, optlen);
  2.1635 + 		break;
  2.1636 + 
  2.1637 +diff --git a/net/ipv6/netfilter/ip6_queue.c b/net/ipv6/netfilter/ip6_queue.c
  2.1638 +--- a/net/ipv6/netfilter/ip6_queue.c
  2.1639 ++++ b/net/ipv6/netfilter/ip6_queue.c
  2.1640 +@@ -76,7 +76,9 @@ static DECLARE_MUTEX(ipqnl_sem);
  2.1641 + static void
  2.1642 + ipq_issue_verdict(struct ipq_queue_entry *entry, int verdict)
  2.1643 + {
  2.1644 ++	local_bh_disable();
  2.1645 + 	nf_reinject(entry->skb, entry->info, verdict);
  2.1646 ++	local_bh_enable();
  2.1647 + 	kfree(entry);
  2.1648 + }
  2.1649 + 
  2.1650 +diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
  2.1651 +--- a/net/netlink/af_netlink.c
  2.1652 ++++ b/net/netlink/af_netlink.c
  2.1653 +@@ -315,8 +315,8 @@ err:
  2.1654 + static void netlink_remove(struct sock *sk)
  2.1655 + {
  2.1656 + 	netlink_table_grab();
  2.1657 +-	nl_table[sk->sk_protocol].hash.entries--;
  2.1658 +-	sk_del_node_init(sk);
  2.1659 ++	if (sk_del_node_init(sk))
  2.1660 ++		nl_table[sk->sk_protocol].hash.entries--;
  2.1661 + 	if (nlk_sk(sk)->groups)
  2.1662 + 		__sk_del_bind_node(sk);
  2.1663 + 	netlink_table_ungrab();
  2.1664 +@@ -429,7 +429,12 @@ retry:
  2.1665 + 	err = netlink_insert(sk, pid);
  2.1666 + 	if (err == -EADDRINUSE)
  2.1667 + 		goto retry;
  2.1668 +-	return 0;
  2.1669 ++
  2.1670 ++	/* If 2 threads race to autobind, that is fine.  */
  2.1671 ++	if (err == -EBUSY)
  2.1672 ++		err = 0;
  2.1673 ++
  2.1674 ++	return err;
  2.1675 + }
  2.1676 + 
  2.1677 + static inline int netlink_capable(struct socket *sock, unsigned int flag) 
  2.1678 +diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
  2.1679 +--- a/net/packet/af_packet.c
  2.1680 ++++ b/net/packet/af_packet.c
  2.1681 +@@ -274,6 +274,9 @@ static int packet_rcv_spkt(struct sk_buf
  2.1682 + 	dst_release(skb->dst);
  2.1683 + 	skb->dst = NULL;
  2.1684 + 
  2.1685 ++	/* drop conntrack reference */
  2.1686 ++	nf_reset(skb);
  2.1687 ++
  2.1688 + 	spkt = (struct sockaddr_pkt*)skb->cb;
  2.1689 + 
  2.1690 + 	skb_push(skb, skb->data-skb->mac.raw);
  2.1691 +@@ -517,6 +520,9 @@ static int packet_rcv(struct sk_buff *sk
  2.1692 + 	dst_release(skb->dst);
  2.1693 + 	skb->dst = NULL;
  2.1694 + 
  2.1695 ++	/* drop conntrack reference */
  2.1696 ++	nf_reset(skb);
  2.1697 ++
  2.1698 + 	spin_lock(&sk->sk_receive_queue.lock);
  2.1699 + 	po->stats.tp_packets++;
  2.1700 + 	__skb_queue_tail(&sk->sk_receive_queue, skb);
  2.1701 +diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
  2.1702 +--- a/net/xfrm/xfrm_user.c
  2.1703 ++++ b/net/xfrm/xfrm_user.c
  2.1704 +@@ -1180,6 +1180,9 @@ static struct xfrm_policy *xfrm_compile_
  2.1705 + 	if (nr > XFRM_MAX_DEPTH)
  2.1706 + 		return NULL;
  2.1707 + 
  2.1708 ++	if (p->dir > XFRM_POLICY_OUT)
  2.1709 ++		return NULL;
  2.1710 ++
  2.1711 + 	xp = xfrm_policy_alloc(GFP_KERNEL);
  2.1712 + 	if (xp == NULL) {
  2.1713 + 		*dir = -ENOBUFS;
  2.1714 +diff --git a/security/keys/keyring.c b/security/keys/keyring.c
  2.1715 +--- a/security/keys/keyring.c
  2.1716 ++++ b/security/keys/keyring.c
  2.1717 +@@ -188,7 +188,11 @@ static void keyring_destroy(struct key *
  2.1718 + 
  2.1719 + 	if (keyring->description) {
  2.1720 + 		write_lock(&keyring_name_lock);
  2.1721 +-		list_del(&keyring->type_data.link);
  2.1722 ++
  2.1723 ++		if (keyring->type_data.link.next != NULL &&
  2.1724 ++		    !list_empty(&keyring->type_data.link))
  2.1725 ++			list_del(&keyring->type_data.link);
  2.1726 ++
  2.1727 + 		write_unlock(&keyring_name_lock);
  2.1728 + 	}
  2.1729 + 
  2.1730 +diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
  2.1731 +--- a/security/keys/process_keys.c
  2.1732 ++++ b/security/keys/process_keys.c
  2.1733 +@@ -641,7 +641,7 @@ long join_session_keyring(const char *na
  2.1734 + 		keyring = keyring_alloc(name, tsk->uid, tsk->gid, 0, NULL);
  2.1735 + 		if (IS_ERR(keyring)) {
  2.1736 + 			ret = PTR_ERR(keyring);
  2.1737 +-			goto error;
  2.1738 ++			goto error2;
  2.1739 + 		}
  2.1740 + 	}
  2.1741 + 	else if (IS_ERR(keyring)) {
     3.1 --- a/tools/ioemu/exec-all.h	Fri Oct 21 12:06:17 2005 +0100
     3.2 +++ b/tools/ioemu/exec-all.h	Fri Oct 21 12:07:14 2005 +0100
     3.3 @@ -573,7 +573,7 @@ static inline target_ulong get_phys_addr
     3.4  }
     3.5  #endif
     3.6  
     3.7 -#define DEBUG_UNUSED_IOPORT
     3.8 -#define DEBUG_IOPORT
     3.9 +//#define DEBUG_UNUSED_IOPORT
    3.10 +//#define DEBUG_IOPORT
    3.11  #define TARGET_VMX
    3.12  
     4.1 --- a/tools/ioemu/hw/cirrus_vga_rop2.h	Fri Oct 21 12:06:17 2005 +0100
     4.2 +++ b/tools/ioemu/hw/cirrus_vga_rop2.h	Fri Oct 21 12:07:14 2005 +0100
     4.3 @@ -47,6 +47,11 @@ glue(glue(glue(cirrus_patternfill_, ROP_
     4.4      int x, y, pattern_y, pattern_pitch, pattern_x;
     4.5      unsigned int col;
     4.6      const uint8_t *src1;
     4.7 +#if DEPTH == 24
     4.8 +    int skipleft = s->gr[0x2f] & 0x1f;
     4.9 +#else
    4.10 +    int skipleft = (s->gr[0x2f] & 0x07) * (DEPTH / 8);
    4.11 +#endif
    4.12  
    4.13  #if DEPTH == 8
    4.14      pattern_pitch = 8;
    4.15 @@ -56,11 +61,11 @@ glue(glue(glue(cirrus_patternfill_, ROP_
    4.16      pattern_pitch = 32;
    4.17  #endif
    4.18      pattern_y = s->cirrus_blt_srcaddr & 7;
    4.19 -    pattern_x = 0;
    4.20      for(y = 0; y < bltheight; y++) {
    4.21 -        d = dst;
    4.22 +        pattern_x = skipleft;
    4.23 +        d = dst + skipleft;
    4.24          src1 = src + pattern_y * pattern_pitch;
    4.25 -        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
    4.26 +        for (x = skipleft; x < bltwidth; x += (DEPTH / 8)) {
    4.27  #if DEPTH == 8
    4.28              col = src1[pattern_x];
    4.29              pattern_x = (pattern_x + 1) & 7;
    4.30 @@ -99,7 +104,13 @@ glue(glue(glue(cirrus_colorexpand_transp
    4.31      unsigned int col;
    4.32      unsigned bitmask;
    4.33      unsigned index;
    4.34 -    int srcskipleft = 0;
    4.35 +#if DEPTH == 24
    4.36 +    int dstskipleft = s->gr[0x2f] & 0x1f;
    4.37 +    int srcskipleft = dstskipleft / 3;
    4.38 +#else
    4.39 +    int srcskipleft = s->gr[0x2f] & 0x07;
    4.40 +    int dstskipleft = srcskipleft * (DEPTH / 8);
    4.41 +#endif
    4.42  
    4.43      if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
    4.44          bits_xor = 0xff;
    4.45 @@ -112,8 +123,8 @@ glue(glue(glue(cirrus_colorexpand_transp
    4.46      for(y = 0; y < bltheight; y++) {
    4.47          bitmask = 0x80 >> srcskipleft;
    4.48          bits = *src++ ^ bits_xor;
    4.49 -        d = dst;
    4.50 -        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
    4.51 +        d = dst + dstskipleft;
    4.52 +        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
    4.53              if ((bitmask & 0xff) == 0) {
    4.54                  bitmask = 0x80;
    4.55                  bits = *src++ ^ bits_xor;
    4.56 @@ -142,15 +153,16 @@ glue(glue(glue(cirrus_colorexpand_, ROP_
    4.57      unsigned bits;
    4.58      unsigned int col;
    4.59      unsigned bitmask;
    4.60 -    int srcskipleft = 0;
    4.61 +    int srcskipleft = s->gr[0x2f] & 0x07;
    4.62 +    int dstskipleft = srcskipleft * (DEPTH / 8);
    4.63  
    4.64      colors[0] = s->cirrus_blt_bgcol;
    4.65      colors[1] = s->cirrus_blt_fgcol;
    4.66      for(y = 0; y < bltheight; y++) {
    4.67          bitmask = 0x80 >> srcskipleft;
    4.68          bits = *src++;
    4.69 -        d = dst;
    4.70 -        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
    4.71 +        d = dst + dstskipleft;
    4.72 +        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
    4.73              if ((bitmask & 0xff) == 0) {
    4.74                  bitmask = 0x80;
    4.75                  bits = *src++;
    4.76 @@ -175,6 +187,13 @@ glue(glue(glue(cirrus_colorexpand_patter
    4.77      int x, y, bitpos, pattern_y;
    4.78      unsigned int bits, bits_xor;
    4.79      unsigned int col;
    4.80 +#if DEPTH == 24
    4.81 +    int dstskipleft = s->gr[0x2f] & 0x1f;
    4.82 +    int srcskipleft = dstskipleft / 3;
    4.83 +#else
    4.84 +    int srcskipleft = s->gr[0x2f] & 0x07;
    4.85 +    int dstskipleft = srcskipleft * (DEPTH / 8);
    4.86 +#endif
    4.87  
    4.88      if (s->cirrus_blt_modeext & CIRRUS_BLTMODEEXT_COLOREXPINV) {
    4.89          bits_xor = 0xff;
    4.90 @@ -187,9 +206,9 @@ glue(glue(glue(cirrus_colorexpand_patter
    4.91  
    4.92      for(y = 0; y < bltheight; y++) {
    4.93          bits = src[pattern_y] ^ bits_xor;
    4.94 -        bitpos = 7;
    4.95 -        d = dst;
    4.96 -        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
    4.97 +        bitpos = 7 - srcskipleft;
    4.98 +        d = dst + dstskipleft;
    4.99 +        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
   4.100              if ((bits >> bitpos) & 1) {
   4.101                  PUTPIXEL();
   4.102              }
   4.103 @@ -213,6 +232,8 @@ glue(glue(glue(cirrus_colorexpand_patter
   4.104      int x, y, bitpos, pattern_y;
   4.105      unsigned int bits;
   4.106      unsigned int col;
   4.107 +    int srcskipleft = s->gr[0x2f] & 0x07;
   4.108 +    int dstskipleft = srcskipleft * (DEPTH / 8);
   4.109  
   4.110      colors[0] = s->cirrus_blt_bgcol;
   4.111      colors[1] = s->cirrus_blt_fgcol;
   4.112 @@ -220,9 +241,9 @@ glue(glue(glue(cirrus_colorexpand_patter
   4.113  
   4.114      for(y = 0; y < bltheight; y++) {
   4.115          bits = src[pattern_y];
   4.116 -        bitpos = 7;
   4.117 -        d = dst;
   4.118 -        for (x = 0; x < bltwidth; x += (DEPTH / 8)) {
   4.119 +        bitpos = 7 - srcskipleft;
   4.120 +        d = dst + dstskipleft;
   4.121 +        for (x = dstskipleft; x < bltwidth; x += (DEPTH / 8)) {
   4.122              col = colors[(bits >> bitpos) & 1];
   4.123              PUTPIXEL();
   4.124              d += (DEPTH / 8);
     5.1 --- a/tools/ioemu/hw/i8259.c	Fri Oct 21 12:06:17 2005 +0100
     5.2 +++ b/tools/ioemu/hw/i8259.c	Fri Oct 21 12:07:14 2005 +0100
     5.3 @@ -29,7 +29,7 @@
     5.4  //#define DEBUG_PIC
     5.5  
     5.6  //#define DEBUG_IRQ_LATENCY
     5.7 -#define DEBUG_IRQ_COUNT
     5.8 +//#define DEBUG_IRQ_COUNT
     5.9  
    5.10  extern void pit_reset_vmx_vectors();
    5.11  
     6.1 --- a/tools/ioemu/monitor.c	Fri Oct 21 12:06:17 2005 +0100
     6.2 +++ b/tools/ioemu/monitor.c	Fri Oct 21 12:07:14 2005 +0100
     6.3 @@ -232,6 +232,161 @@ static void do_quit(void)
     6.4      exit(0);
     6.5  }
     6.6  
     6.7 +typedef struct {
     6.8 +    int keycode;
     6.9 +    const char *name;
    6.10 +} KeyDef;
    6.11 +
    6.12 +static const KeyDef key_defs[] = {
    6.13 +    { 0x2a, "shift" },
    6.14 +    { 0x36, "shift_r" },
    6.15 +    
    6.16 +    { 0x38, "alt" },
    6.17 +    { 0xb8, "alt_r" },
    6.18 +    { 0x1d, "ctrl" },
    6.19 +    { 0x9d, "ctrl_r" },
    6.20 +
    6.21 +    { 0xdd, "menu" },
    6.22 +
    6.23 +    { 0x01, "esc" },
    6.24 +
    6.25 +    { 0x02, "1" },
    6.26 +    { 0x03, "2" },
    6.27 +    { 0x04, "3" },
    6.28 +    { 0x05, "4" },
    6.29 +    { 0x06, "5" },
    6.30 +    { 0x07, "6" },
    6.31 +    { 0x08, "7" },
    6.32 +    { 0x09, "8" },
    6.33 +    { 0x0a, "9" },
    6.34 +    { 0x0b, "0" },
    6.35 +    { 0x0e, "backspace" },
    6.36 +
    6.37 +    { 0x0f, "tab" },
    6.38 +    { 0x10, "q" },
    6.39 +    { 0x11, "w" },
    6.40 +    { 0x12, "e" },
    6.41 +    { 0x13, "r" },
    6.42 +    { 0x14, "t" },
    6.43 +    { 0x15, "y" },
    6.44 +    { 0x16, "u" },
    6.45 +    { 0x17, "i" },
    6.46 +    { 0x18, "o" },
    6.47 +    { 0x19, "p" },
    6.48 +
    6.49 +    { 0x1c, "ret" },
    6.50 +
    6.51 +    { 0x1e, "a" },
    6.52 +    { 0x1f, "s" },
    6.53 +    { 0x20, "d" },
    6.54 +    { 0x21, "f" },
    6.55 +    { 0x22, "g" },
    6.56 +    { 0x23, "h" },
    6.57 +    { 0x24, "j" },
    6.58 +    { 0x25, "k" },
    6.59 +    { 0x26, "l" },
    6.60 +
    6.61 +    { 0x2c, "z" },
    6.62 +    { 0x2d, "x" },
    6.63 +    { 0x2e, "c" },
    6.64 +    { 0x2f, "v" },
    6.65 +    { 0x30, "b" },
    6.66 +    { 0x31, "n" },
    6.67 +    { 0x32, "m" },
    6.68 +    
    6.69 +    { 0x39, "spc" },
    6.70 +    { 0x3a, "caps_lock" },
    6.71 +    { 0x3b, "f1" },
    6.72 +    { 0x3c, "f2" },
    6.73 +    { 0x3d, "f3" },
    6.74 +    { 0x3e, "f4" },
    6.75 +    { 0x3f, "f5" },
    6.76 +    { 0x40, "f6" },
    6.77 +    { 0x41, "f7" },
    6.78 +    { 0x42, "f8" },
    6.79 +    { 0x43, "f9" },
    6.80 +    { 0x44, "f10" },
    6.81 +    { 0x45, "num_lock" },
    6.82 +    { 0x46, "scroll_lock" },
    6.83 +
    6.84 +    { 0x56, "<" },
    6.85 +
    6.86 +    { 0x57, "f11" },
    6.87 +    { 0x58, "f12" },
    6.88 +
    6.89 +    { 0xb7, "print" },
    6.90 +
    6.91 +    { 0xc7, "home" },
    6.92 +    { 0xc9, "pgup" },
    6.93 +    { 0xd1, "pgdn" },
    6.94 +    { 0xcf, "end" },
    6.95 +
    6.96 +    { 0xcb, "left" },
    6.97 +    { 0xc8, "up" },
    6.98 +    { 0xd0, "down" },
    6.99 +    { 0xcd, "right" },
   6.100 +
   6.101 +    { 0xd2, "insert" },
   6.102 +    { 0xd3, "delete" },
   6.103 +    { 0, NULL },
   6.104 +};
   6.105 +
   6.106 +static int get_keycode(const char *key)
   6.107 +{
   6.108 +    const KeyDef *p;
   6.109 +
   6.110 +    for(p = key_defs; p->name != NULL; p++) {
   6.111 +        if (!strcmp(key, p->name))
   6.112 +            return p->keycode;
   6.113 +    }
   6.114 +    return -1;
   6.115 +}
   6.116 +
   6.117 +static void do_send_key(const char *string)
   6.118 +{
   6.119 +    char keybuf[16], *q;
   6.120 +    uint8_t keycodes[16];
   6.121 +    const char *p;
   6.122 +    int nb_keycodes, keycode, i;
   6.123 +    
   6.124 +    nb_keycodes = 0;
   6.125 +    p = string;
   6.126 +    while (*p != '\0') {
   6.127 +        q = keybuf;
   6.128 +        while (*p != '\0' && *p != '-') {
   6.129 +            if ((q - keybuf) < sizeof(keybuf) - 1) {
   6.130 +                *q++ = *p;
   6.131 +            }
   6.132 +            p++;
   6.133 +        }
   6.134 +        *q = '\0';
   6.135 +        keycode = get_keycode(keybuf);
   6.136 +        if (keycode < 0) {
   6.137 +            term_printf("unknown key: '%s'\n", keybuf);
   6.138 +            return;
   6.139 +        }
   6.140 +        keycodes[nb_keycodes++] = keycode;
   6.141 +        if (*p == '\0')
   6.142 +            break;
   6.143 +        p++;
   6.144 +    }
   6.145 +    /* key down events */
   6.146 +    for(i = 0; i < nb_keycodes; i++) {
   6.147 +        keycode = keycodes[i];
   6.148 +        if (keycode & 0x80)
   6.149 +            kbd_put_keycode(0xe0);
   6.150 +        kbd_put_keycode(keycode & 0x7f);
   6.151 +    }
   6.152 +    /* key up events */
   6.153 +    for(i = nb_keycodes - 1; i >= 0; i--) {
   6.154 +        keycode = keycodes[i];
   6.155 +        if (keycode & 0x80)
   6.156 +            kbd_put_keycode(0xe0);
   6.157 +        kbd_put_keycode(keycode | 0x80);
   6.158 +    }
   6.159 +}
   6.160 +
   6.161 +
   6.162  static int eject_device(BlockDriverState *bs, int force)
   6.163  {
   6.164      if (bdrv_is_inserted(bs)) {
   6.165 @@ -331,6 +486,8 @@ static term_cmd_t term_cmds[] = {
   6.166        "item1[,...]", "activate logging of the specified items to '/tmp/qemu.log'" },
   6.167      { "q|quit", "", do_quit,
   6.168        "", "quit the emulator" },
   6.169 +    { "sendkey", "s", do_send_key, 
   6.170 +      "keys", "send keys to the VM (e.g. 'sendkey ctrl-alt-f1')" },
   6.171      { NULL, NULL, }, 
   6.172  };
   6.173  
     7.1 --- a/tools/python/xen/xend/image.py	Fri Oct 21 12:06:17 2005 +0100
     7.2 +++ b/tools/python/xen/xend/image.py	Fri Oct 21 12:07:14 2005 +0100
     7.3 @@ -311,7 +311,8 @@ class VmxImageHandler(ImageHandler):
     7.4                    "-m", "%s" % (self.vm.getMemoryTarget() / 1024)])
     7.5          args = args + self.dmargs
     7.6          env = dict(os.environ)
     7.7 -        env['DISPLAY'] = self.display
     7.8 +        if self.display:
     7.9 +            env['DISPLAY'] = self.display
    7.10          log.info("spawning device models: %s %s", self.device_model, args)
    7.11          self.pid = os.spawnve(os.P_NOWAIT, self.device_model, args, env)
    7.12          log.info("device model pid: %d", self.pid)
     8.1 --- a/tools/security/Makefile	Fri Oct 21 12:06:17 2005 +0100
     8.2 +++ b/tools/security/Makefile	Fri Oct 21 12:07:14 2005 +0100
     8.3 @@ -43,6 +43,7 @@ endif
     8.4  build: mk-symlinks
     8.5  	$(MAKE) secpol_tool
     8.6  	$(MAKE) secpol_xml2bin
     8.7 +	$(MAKE) get_decision
     8.8  	chmod 700 ./setlabel.sh
     8.9  	chmod 700 ./updategrub.sh
    8.10  	chmod 700 ./getlabel.sh
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/security/get_decision.c	Fri Oct 21 12:07:14 2005 +0100
     9.3 @@ -0,0 +1,176 @@
     9.4 +/****************************************************************
     9.5 + * get_decision.c
     9.6 + *
     9.7 + * Copyright (C) 2005 IBM Corporation
     9.8 + *
     9.9 + * Authors:
    9.10 + * Reiner Sailer <sailer@watson.ibm.com>
    9.11 + *
    9.12 + * This program is free software; you can redistribute it and/or
    9.13 + * modify it under the terms of the GNU General Public License as
    9.14 + * published by the Free Software Foundation, version 2 of the
    9.15 + * License.
    9.16 + *
    9.17 + * An example program that shows how to retrieve an access control
    9.18 + * decision from the hypervisor ACM based on the currently active policy.
    9.19 + *
    9.20 + */
    9.21 +
    9.22 +#include <unistd.h>
    9.23 +#include <stdio.h>
    9.24 +#include <errno.h>
    9.25 +#include <fcntl.h>
    9.26 +#include <getopt.h>
    9.27 +#include <sys/mman.h>
    9.28 +#include <sys/types.h>
    9.29 +#include <sys/stat.h>
    9.30 +#include <stdlib.h>
    9.31 +#include <sys/ioctl.h>
    9.32 +#include <string.h>
    9.33 +#include <netinet/in.h>
    9.34 +#include <xen/acm.h>
    9.35 +#include <xen/acm_ops.h>
    9.36 +#include <xen/linux/privcmd.h>
    9.37 +
    9.38 +#define PERROR(_m, _a...) \
    9.39 +fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a ,	\
    9.40 +                errno, strerror(errno))
    9.41 +
    9.42 +void usage(char *progname)
    9.43 +{
    9.44 +    printf("Use: %s \n", progname);
    9.45 +    printf(" Test program illustrating the retrieval of\n");
    9.46 +    printf(" access control decisions from xen. At this time,\n");
    9.47 +    printf(" only sharing (STE) policy decisions are supported.\n");
    9.48 +    printf(" parameter options:\n");
    9.49 +    printf("\t -i domid -i domid\n");
    9.50 +    printf("\t -i domid -s ssidref\n");
    9.51 +    printf("\t -s ssidref -s ssidref\n\n");
    9.52 +    exit(-1);
    9.53 +}
    9.54 +
    9.55 +static inline int do_policycmd(int xc_handle, unsigned int cmd,
    9.56 +                               unsigned long data)
    9.57 +{
    9.58 +    return ioctl(xc_handle, cmd, data);
    9.59 +}
    9.60 +
    9.61 +static inline int do_xen_hypercall(int xc_handle,
    9.62 +                                   privcmd_hypercall_t * hypercall)
    9.63 +{
    9.64 +    return do_policycmd(xc_handle,
    9.65 +                        IOCTL_PRIVCMD_HYPERCALL,
    9.66 +                        (unsigned long) hypercall);
    9.67 +}
    9.68 +
    9.69 +static inline int do_acm_op(int xc_handle, struct acm_op *op)
    9.70 +{
    9.71 +    int ret = -1;
    9.72 +    privcmd_hypercall_t hypercall;
    9.73 +
    9.74 +    op->interface_version = ACM_INTERFACE_VERSION;
    9.75 +
    9.76 +    hypercall.op = __HYPERVISOR_acm_op;
    9.77 +    hypercall.arg[0] = (unsigned long) op;
    9.78 +
    9.79 +    if (mlock(op, sizeof(*op)) != 0) {
    9.80 +        PERROR("Could not lock memory for Xen policy hypercall");
    9.81 +        goto out1;
    9.82 +    }
    9.83 +
    9.84 +    if ((ret = do_xen_hypercall(xc_handle, &hypercall)) < 0) {
    9.85 +        if (errno == EACCES)
    9.86 +            fprintf(stderr, "ACM operation failed -- need to"
    9.87 +                    " rebuild the user-space tool set?\n");
    9.88 +        goto out2;
    9.89 +    }
    9.90 +
    9.91 +  out2:(void) munlock(op, sizeof(*op));
    9.92 +  out1:return ret;
    9.93 +}
    9.94 +
    9.95 +
    9.96 +/************************ get decision ******************************/
    9.97 +
    9.98 +/* this example uses two domain ids and retrieves the decision if these domains
    9.99 + * can share information (useful, i.e., to enforce policy onto network traffic in dom0
   9.100 + */
   9.101 +int acm_get_decision(int xc_handle, int argc, char *const argv[])
   9.102 +{
   9.103 +    struct acm_op op;
   9.104 +    int ret;
   9.105 +
   9.106 +    op.cmd = ACM_GETDECISION;
   9.107 +    op.interface_version = ACM_INTERFACE_VERSION;
   9.108 +    op.u.getdecision.get_decision_by1 = UNSET;
   9.109 +    op.u.getdecision.get_decision_by2 = UNSET;
   9.110 +    op.u.getdecision.hook = SHARING;
   9.111 +
   9.112 +    while (1) {
   9.113 +        int c = getopt(argc, argv, "i:s:");
   9.114 +        if (c == -1)
   9.115 +            break;
   9.116 +
   9.117 +        if (c == 'i') {
   9.118 +            if (op.u.getdecision.get_decision_by1 == UNSET) {
   9.119 +                op.u.getdecision.get_decision_by1 = DOMAINID;
   9.120 +                op.u.getdecision.id1.domainid = strtoul(optarg, NULL, 0);
   9.121 +            } else if (op.u.getdecision.get_decision_by2 == UNSET) {
   9.122 +                op.u.getdecision.get_decision_by2 = DOMAINID;
   9.123 +                op.u.getdecision.id2.domainid = strtoul(optarg, NULL, 0);
   9.124 +            } else
   9.125 +                usage(argv[0]);
   9.126 +        } else if (c == 's') {
   9.127 +            if (op.u.getdecision.get_decision_by1 == UNSET) {
   9.128 +                op.u.getdecision.get_decision_by1 = SSIDREF;
   9.129 +                op.u.getdecision.id1.ssidref = strtoul(optarg, NULL, 0);
   9.130 +            } else if (op.u.getdecision.get_decision_by2 == UNSET) {
   9.131 +                op.u.getdecision.get_decision_by2 = SSIDREF;
   9.132 +                op.u.getdecision.id2.ssidref = strtoul(optarg, NULL, 0);
   9.133 +            } else
   9.134 +                usage(argv[0]);
   9.135 +        } else
   9.136 +            usage(argv[0]);
   9.137 +    }
   9.138 +    if ((op.u.getdecision.get_decision_by1 == UNSET) ||
   9.139 +        (op.u.getdecision.get_decision_by2 == UNSET))
   9.140 +        usage(argv[0]);
   9.141 +
   9.142 +    if ((ret = do_acm_op(xc_handle, &op))) {
   9.143 +        printf("%s: Error getting decision (%d).\n", __func__, ret);
   9.144 +        printf("%s: decision = %s.\n", __func__,
   9.145 +               (op.u.getdecision.acm_decision ==
   9.146 +                ACM_ACCESS_PERMITTED) ? "PERMITTED" : ((op.u.getdecision.
   9.147 +                                                        acm_decision ==
   9.148 +                                                        ACM_ACCESS_DENIED)
   9.149 +                                                       ? "DENIED" :
   9.150 +                                                       "ERROR"));
   9.151 +        return ret;
   9.152 +    }
   9.153 +    return op.u.getdecision.acm_decision;
   9.154 +}
   9.155 +
   9.156 +/***************************** main **************************************/
   9.157 +
   9.158 +int main(int argc, char **argv)
   9.159 +{
   9.160 +
   9.161 +    int acm_cmd_fd, ret = 0;
   9.162 +
   9.163 +    if (argc < 5)
   9.164 +        usage(argv[0]);
   9.165 +
   9.166 +    if ((acm_cmd_fd = open("/proc/xen/privcmd", O_RDONLY)) <= 0) {
   9.167 +        printf("ERROR: Could not open xen privcmd device!\n");
   9.168 +        exit(-1);
   9.169 +    }
   9.170 +
   9.171 +    ret = acm_get_decision(acm_cmd_fd, argc, argv);
   9.172 +
   9.173 +    printf("Decision: %s (%d)\n",
   9.174 +           (ret == ACM_ACCESS_PERMITTED) ? "PERMITTED" :
   9.175 +           ((ret == ACM_ACCESS_DENIED) ? "DENIED" : "ERROR"), ret);
   9.176 +
   9.177 +    close(acm_cmd_fd);
   9.178 +    return ret;
   9.179 +}
    10.1 --- a/tools/security/secpol_tool.c	Fri Oct 21 12:06:17 2005 +0100
    10.2 +++ b/tools/security/secpol_tool.c	Fri Oct 21 12:07:14 2005 +0100
    10.3 @@ -67,7 +67,7 @@ static inline int do_xen_hypercall(int x
    10.4                          (unsigned long) hypercall);
    10.5  }
    10.6  
    10.7 -static inline int do_acm_op(int xc_handle, acm_op_t * op)
    10.8 +static inline int do_acm_op(int xc_handle, struct acm_op * op)
    10.9  {
   10.10      int ret = -1;
   10.11      privcmd_hypercall_t hypercall;
   10.12 @@ -275,10 +275,10 @@ void acm_dump_policy_buffer(void *buf, i
   10.13  /******************************* get policy ******************************/
   10.14  
   10.15  #define PULL_CACHE_SIZE		8192
   10.16 -u8 pull_buffer[PULL_CACHE_SIZE];
   10.17 +uint8_t pull_buffer[PULL_CACHE_SIZE];
   10.18  int acm_domain_getpolicy(int xc_handle)
   10.19  {
   10.20 -    acm_op_t op;
   10.21 +    struct acm_op op;
   10.22      int ret;
   10.23  
   10.24      memset(pull_buffer, 0x00, sizeof(pull_buffer));
   10.25 @@ -299,7 +299,7 @@ int acm_domain_loadpolicy(int xc_handle,
   10.26      struct stat mystat;
   10.27      int ret, fd;
   10.28      off_t len;
   10.29 -    u8 *buffer;
   10.30 +    uint8_t *buffer;
   10.31  
   10.32      if ((ret = stat(filename, &mystat)))
   10.33      {
   10.34 @@ -321,7 +321,7 @@ int acm_domain_loadpolicy(int xc_handle,
   10.35      }
   10.36      if (len == read(fd, buffer, len))
   10.37      {
   10.38 -        acm_op_t op;
   10.39 +        struct acm_op op;
   10.40          /* dump it and then push it down into xen/acm */
   10.41          acm_dump_policy_buffer(buffer, len);
   10.42          op.cmd = ACM_SETPOLICY;
   10.43 @@ -368,8 +368,8 @@ void dump_ste_stats(struct acm_ste_stats
   10.44  #define PULL_STATS_SIZE		8192
   10.45  int acm_domain_dumpstats(int xc_handle)
   10.46  {
   10.47 -    u8 stats_buffer[PULL_STATS_SIZE];
   10.48 -    acm_op_t op;
   10.49 +    uint8_t stats_buffer[PULL_STATS_SIZE];
   10.50 +    struct acm_op op;
   10.51      int ret;
   10.52      struct acm_stats_buffer *stats;
   10.53  
   10.54 @@ -442,7 +442,7 @@ int acm_domain_getssid(int xc_handle, in
   10.55      /* this includes header and a set of types */
   10.56      #define MAX_SSIDBUFFER  2000
   10.57      int ret, i;
   10.58 -    acm_op_t op;
   10.59 +    struct acm_op op;
   10.60      struct acm_ssid_buffer *hdr;
   10.61      unsigned char *buf;
   10.62  	int nice_print = 1;
    11.1 --- a/xen/acm/acm_chinesewall_hooks.c	Fri Oct 21 12:06:17 2005 +0100
    11.2 +++ b/xen/acm/acm_chinesewall_hooks.c	Fri Oct 21 12:07:14 2005 +0100
    11.3 @@ -26,7 +26,10 @@
    11.4   *    in which case all types of a new domain must be conflict-free
    11.5   *    with all types of already running domains.
    11.6   *
    11.7 + * indent -i4 -kr -nut
    11.8 + *
    11.9   */
   11.10 +
   11.11  #include <xen/config.h>
   11.12  #include <xen/errno.h>
   11.13  #include <xen/types.h>
   11.14 @@ -48,270 +51,333 @@ struct chwall_binary_policy chwall_bin_p
   11.15   */
   11.16  int acm_init_chwall_policy(void)
   11.17  {
   11.18 -	/* minimal startup policy; policy write-locked already */
   11.19 -	chwall_bin_pol.max_types = 1;
   11.20 -	chwall_bin_pol.max_ssidrefs = 2;
   11.21 -	chwall_bin_pol.max_conflictsets = 1;
   11.22 -	chwall_bin_pol.ssidrefs = (domaintype_t *)xmalloc_array(domaintype_t, chwall_bin_pol.max_ssidrefs*chwall_bin_pol.max_types);
   11.23 -	chwall_bin_pol.conflict_sets = (domaintype_t *)xmalloc_array(domaintype_t, chwall_bin_pol.max_conflictsets*chwall_bin_pol.max_types);
   11.24 -	chwall_bin_pol.running_types = (domaintype_t *)xmalloc_array(domaintype_t, chwall_bin_pol.max_types);
   11.25 -	chwall_bin_pol.conflict_aggregate_set = (domaintype_t *)xmalloc_array(domaintype_t, chwall_bin_pol.max_types);
   11.26 -	
   11.27 -	if ((chwall_bin_pol.conflict_sets == NULL) || (chwall_bin_pol.running_types == NULL) ||
   11.28 -	    (chwall_bin_pol.ssidrefs == NULL) || (chwall_bin_pol.conflict_aggregate_set == NULL))
   11.29 -		return ACM_INIT_SSID_ERROR;
   11.30 +    /* minimal startup policy; policy write-locked already */
   11.31 +    chwall_bin_pol.max_types = 1;
   11.32 +    chwall_bin_pol.max_ssidrefs = 2;
   11.33 +    chwall_bin_pol.max_conflictsets = 1;
   11.34 +    chwall_bin_pol.ssidrefs =
   11.35 +        (domaintype_t *) xmalloc_array(domaintype_t,
   11.36 +                                       chwall_bin_pol.max_ssidrefs *
   11.37 +                                       chwall_bin_pol.max_types);
   11.38 +    chwall_bin_pol.conflict_sets =
   11.39 +        (domaintype_t *) xmalloc_array(domaintype_t,
   11.40 +                                       chwall_bin_pol.max_conflictsets *
   11.41 +                                       chwall_bin_pol.max_types);
   11.42 +    chwall_bin_pol.running_types =
   11.43 +        (domaintype_t *) xmalloc_array(domaintype_t,
   11.44 +                                       chwall_bin_pol.max_types);
   11.45 +    chwall_bin_pol.conflict_aggregate_set =
   11.46 +        (domaintype_t *) xmalloc_array(domaintype_t,
   11.47 +                                       chwall_bin_pol.max_types);
   11.48  
   11.49 -	/* initialize state */
   11.50 -	memset((void *)chwall_bin_pol.ssidrefs, 0, chwall_bin_pol.max_ssidrefs*chwall_bin_pol.max_types*sizeof(domaintype_t));
   11.51 -	memset((void *)chwall_bin_pol.conflict_sets, 0, chwall_bin_pol.max_conflictsets*chwall_bin_pol.max_types*sizeof(domaintype_t));
   11.52 -	memset((void *)chwall_bin_pol.running_types, 0, chwall_bin_pol.max_types*sizeof(domaintype_t));
   11.53 -	memset((void *)chwall_bin_pol.conflict_aggregate_set, 0, chwall_bin_pol.max_types*sizeof(domaintype_t));	
   11.54 -	return ACM_OK;
   11.55 +    if ((chwall_bin_pol.conflict_sets == NULL)
   11.56 +        || (chwall_bin_pol.running_types == NULL)
   11.57 +        || (chwall_bin_pol.ssidrefs == NULL)
   11.58 +        || (chwall_bin_pol.conflict_aggregate_set == NULL))
   11.59 +        return ACM_INIT_SSID_ERROR;
   11.60 +
   11.61 +    /* initialize state */
   11.62 +    memset((void *) chwall_bin_pol.ssidrefs, 0,
   11.63 +           chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types *
   11.64 +           sizeof(domaintype_t));
   11.65 +    memset((void *) chwall_bin_pol.conflict_sets, 0,
   11.66 +           chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types *
   11.67 +           sizeof(domaintype_t));
   11.68 +    memset((void *) chwall_bin_pol.running_types, 0,
   11.69 +           chwall_bin_pol.max_types * sizeof(domaintype_t));
   11.70 +    memset((void *) chwall_bin_pol.conflict_aggregate_set, 0,
   11.71 +           chwall_bin_pol.max_types * sizeof(domaintype_t));
   11.72 +    return ACM_OK;
   11.73  }
   11.74  
   11.75 -static int
   11.76 -chwall_init_domain_ssid(void **chwall_ssid, ssidref_t ssidref)
   11.77 +static int chwall_init_domain_ssid(void **chwall_ssid, ssidref_t ssidref)
   11.78  {
   11.79 -	struct chwall_ssid *chwall_ssidp = xmalloc(struct chwall_ssid);
   11.80 -	traceprintk("%s.\n", __func__);
   11.81 -	if (chwall_ssidp == NULL)
   11.82 -		return ACM_INIT_SSID_ERROR;
   11.83 -	/* 
   11.84 -	 * depending on wheter chwall is primary or secondary, get the respective
   11.85 -	 * part of the global ssidref (same way we'll get the partial ssid pointer)
   11.86 -	 */
   11.87 -	chwall_ssidp->chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
   11.88 -	if ((chwall_ssidp->chwall_ssidref >= chwall_bin_pol.max_ssidrefs) ||
   11.89 -	    (chwall_ssidp->chwall_ssidref == ACM_DEFAULT_LOCAL_SSID)) {
   11.90 -		printkd("%s: ERROR chwall_ssidref(%x) undefined (>max) or unset (0).\n",
   11.91 -			__func__, chwall_ssidp->chwall_ssidref);
   11.92 -		xfree(chwall_ssidp);
   11.93 -		return ACM_INIT_SSID_ERROR;
   11.94 -	}
   11.95 -	(*chwall_ssid) = chwall_ssidp;
   11.96 -	printkd("%s: determined chwall_ssidref to %x.\n", 
   11.97 -	       __func__, chwall_ssidp->chwall_ssidref);
   11.98 -	return ACM_OK;
   11.99 +    struct chwall_ssid *chwall_ssidp = xmalloc(struct chwall_ssid);
  11.100 +    traceprintk("%s.\n", __func__);
  11.101 +    if (chwall_ssidp == NULL)
  11.102 +        return ACM_INIT_SSID_ERROR;
  11.103 +
  11.104 +    chwall_ssidp->chwall_ssidref =
  11.105 +        GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.106 +
  11.107 +    if ((chwall_ssidp->chwall_ssidref >= chwall_bin_pol.max_ssidrefs)
  11.108 +        || (chwall_ssidp->chwall_ssidref == ACM_DEFAULT_LOCAL_SSID))
  11.109 +    {
  11.110 +        printkd("%s: ERROR chwall_ssidref(%x) undefined (>max) or unset (0).\n",
  11.111 +                __func__, chwall_ssidp->chwall_ssidref);
  11.112 +        xfree(chwall_ssidp);
  11.113 +        return ACM_INIT_SSID_ERROR;
  11.114 +    }
  11.115 +    (*chwall_ssid) = chwall_ssidp;
  11.116 +    printkd("%s: determined chwall_ssidref to %x.\n",
  11.117 +            __func__, chwall_ssidp->chwall_ssidref);
  11.118 +    return ACM_OK;
  11.119  }
  11.120  
  11.121 -static void
  11.122 -chwall_free_domain_ssid(void *chwall_ssid)
  11.123 +static void chwall_free_domain_ssid(void *chwall_ssid)
  11.124  {
  11.125 -	traceprintk("%s.\n", __func__);
  11.126 -	if (chwall_ssid != NULL)
  11.127 -		xfree(chwall_ssid);
  11.128 -	return;
  11.129 +    traceprintk("%s.\n", __func__);
  11.130 +    if (chwall_ssid != NULL)
  11.131 +        xfree(chwall_ssid);
  11.132 +    return;
  11.133  }
  11.134  
  11.135  
  11.136  /* dump chinese wall cache; policy read-locked already */
  11.137 -static int
  11.138 -chwall_dump_policy(u8 *buf, u16 buf_size) {	
  11.139 -     struct acm_chwall_policy_buffer *chwall_buf = (struct acm_chwall_policy_buffer *)buf;
  11.140 -     int ret = 0;
  11.141 +static int chwall_dump_policy(u8 * buf, u32 buf_size)
  11.142 +{
  11.143 +    struct acm_chwall_policy_buffer *chwall_buf =
  11.144 +        (struct acm_chwall_policy_buffer *) buf;
  11.145 +    int ret = 0;
  11.146  
  11.147 -     chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types);
  11.148 -     chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs);
  11.149 -     chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
  11.150 -     chwall_buf->chwall_ssid_offset = htonl(sizeof(struct acm_chwall_policy_buffer));
  11.151 -     chwall_buf->chwall_max_conflictsets = htonl(chwall_bin_pol.max_conflictsets);
  11.152 -     chwall_buf->chwall_conflict_sets_offset =
  11.153 -	     htonl(
  11.154 -		   ntohl(chwall_buf->chwall_ssid_offset) +
  11.155 -		   sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs * 
  11.156 -		   chwall_bin_pol.max_types);
  11.157 -
  11.158 -     chwall_buf->chwall_running_types_offset = 
  11.159 -	     htonl(
  11.160 -		   ntohl(chwall_buf->chwall_conflict_sets_offset) +
  11.161 -		   sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets *
  11.162 -		   chwall_bin_pol.max_types);
  11.163 +    if (buf_size < sizeof(struct acm_chwall_policy_buffer))
  11.164 +        return -EINVAL;
  11.165  
  11.166 -     chwall_buf->chwall_conflict_aggregate_offset =
  11.167 -	     htonl(
  11.168 -		   ntohl(chwall_buf->chwall_running_types_offset) +
  11.169 -		   sizeof(domaintype_t) * chwall_bin_pol.max_types);
  11.170 +    chwall_buf->chwall_max_types = htonl(chwall_bin_pol.max_types);
  11.171 +    chwall_buf->chwall_max_ssidrefs = htonl(chwall_bin_pol.max_ssidrefs);
  11.172 +    chwall_buf->policy_code = htonl(ACM_CHINESE_WALL_POLICY);
  11.173 +    chwall_buf->chwall_ssid_offset =
  11.174 +        htonl(sizeof(struct acm_chwall_policy_buffer));
  11.175 +    chwall_buf->chwall_max_conflictsets =
  11.176 +        htonl(chwall_bin_pol.max_conflictsets);
  11.177 +    chwall_buf->chwall_conflict_sets_offset =
  11.178 +        htonl(ntohl(chwall_buf->chwall_ssid_offset) +
  11.179 +              sizeof(domaintype_t) * chwall_bin_pol.max_ssidrefs *
  11.180 +              chwall_bin_pol.max_types);
  11.181 +    chwall_buf->chwall_running_types_offset =
  11.182 +        htonl(ntohl(chwall_buf->chwall_conflict_sets_offset) +
  11.183 +              sizeof(domaintype_t) * chwall_bin_pol.max_conflictsets *
  11.184 +              chwall_bin_pol.max_types);
  11.185 +    chwall_buf->chwall_conflict_aggregate_offset =
  11.186 +        htonl(ntohl(chwall_buf->chwall_running_types_offset) +
  11.187 +              sizeof(domaintype_t) * chwall_bin_pol.max_types);
  11.188  
  11.189 -     ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) +
  11.190 -	     sizeof(domaintype_t) * chwall_bin_pol.max_types;
  11.191 -
  11.192 -     /* now copy buffers over */
  11.193 -     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_ssid_offset)),
  11.194 -	      chwall_bin_pol.ssidrefs,
  11.195 -	      chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types);
  11.196 +    ret = ntohl(chwall_buf->chwall_conflict_aggregate_offset) +
  11.197 +        sizeof(domaintype_t) * chwall_bin_pol.max_types;
  11.198  
  11.199 -     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_sets_offset)),
  11.200 -	      chwall_bin_pol.conflict_sets,
  11.201 -	      chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types);
  11.202 +    if (buf_size < ret)
  11.203 +        return -EINVAL;
  11.204 +
  11.205 +    /* now copy buffers over */
  11.206 +    arrcpy16((u16 *) (buf + ntohl(chwall_buf->chwall_ssid_offset)),
  11.207 +             chwall_bin_pol.ssidrefs,
  11.208 +             chwall_bin_pol.max_ssidrefs * chwall_bin_pol.max_types);
  11.209  
  11.210 -     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_running_types_offset)),
  11.211 -	      chwall_bin_pol.running_types,
  11.212 -	      chwall_bin_pol.max_types);
  11.213 +    arrcpy16((u16 *) (buf +
  11.214 +                      ntohl(chwall_buf->chwall_conflict_sets_offset)),
  11.215 +             chwall_bin_pol.conflict_sets,
  11.216 +             chwall_bin_pol.max_conflictsets * chwall_bin_pol.max_types);
  11.217  
  11.218 -     arrcpy16((u16 *)(buf + ntohl(chwall_buf->chwall_conflict_aggregate_offset)),
  11.219 -	      chwall_bin_pol.conflict_aggregate_set,
  11.220 -	      chwall_bin_pol.max_types);
  11.221 -     return ret;
  11.222 +    arrcpy16((u16 *) (buf +
  11.223 +                      ntohl(chwall_buf->chwall_running_types_offset)),
  11.224 +             chwall_bin_pol.running_types, chwall_bin_pol.max_types);
  11.225 +
  11.226 +    arrcpy16((u16 *) (buf +
  11.227 +                      ntohl(chwall_buf->chwall_conflict_aggregate_offset)),
  11.228 +             chwall_bin_pol.conflict_aggregate_set,
  11.229 +             chwall_bin_pol.max_types);
  11.230 +    return ret;
  11.231  }
  11.232  
  11.233  /* adapt security state (running_types and conflict_aggregate_set) to all running
  11.234   * domains; chwall_init_state is called when a policy is changed to bring the security
  11.235   * information into a consistent state and to detect violations (return != 0).
  11.236   * from a security point of view, we simulate that all running domains are re-started
  11.237 - */ 
  11.238 + */
  11.239  static int
  11.240 -chwall_init_state(struct acm_chwall_policy_buffer *chwall_buf, domaintype_t *ssidrefs, domaintype_t *conflict_sets,
  11.241 -		  domaintype_t *running_types, domaintype_t *conflict_aggregate_set)
  11.242 +chwall_init_state(struct acm_chwall_policy_buffer *chwall_buf,
  11.243 +                  domaintype_t * ssidrefs, domaintype_t * conflict_sets,
  11.244 +                  domaintype_t * running_types,
  11.245 +                  domaintype_t * conflict_aggregate_set)
  11.246  {
  11.247 -	int violation = 0, i, j;
  11.248 -	struct chwall_ssid *chwall_ssid;
  11.249 -	ssidref_t chwall_ssidref;
  11.250 -	struct domain **pd;
  11.251 +    int violation = 0, i, j;
  11.252 +    struct chwall_ssid *chwall_ssid;
  11.253 +    ssidref_t chwall_ssidref;
  11.254 +    struct domain **pd;
  11.255  
  11.256 -        write_lock(&domlist_lock);
  11.257 -	/* go through all domains and adjust policy as if this domain was started now */
  11.258 -        pd = &domain_list;
  11.259 -        for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
  11.260 -		chwall_ssid = GET_SSIDP(ACM_CHINESE_WALL_POLICY, (struct acm_ssid_domain *)(*pd)->ssid);
  11.261 -		chwall_ssidref = chwall_ssid->chwall_ssidref;
  11.262 -		traceprintk("%s: validating policy for domain %x (chwall-REF=%x).\n", 
  11.263 -			__func__, (*pd)->domain_id, chwall_ssidref);
  11.264 -		/* a) adjust types ref-count for running domains */
  11.265 -		for (i=0; i< chwall_buf->chwall_max_types; i++)
  11.266 -			running_types[i] +=
  11.267 -				ssidrefs[chwall_ssidref*chwall_buf->chwall_max_types + i];
  11.268 +    write_lock(&domlist_lock);
  11.269 +    /* go through all domains and adjust policy as if this domain was started now */
  11.270 +    pd = &domain_list;
  11.271 +    for (pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list)
  11.272 +    {
  11.273 +        chwall_ssid =
  11.274 +            GET_SSIDP(ACM_CHINESE_WALL_POLICY,
  11.275 +                      (struct acm_ssid_domain *) (*pd)->ssid);
  11.276 +        chwall_ssidref = chwall_ssid->chwall_ssidref;
  11.277 +        traceprintk("%s: validating policy for domain %x (chwall-REF=%x).\n",
  11.278 +                    __func__, (*pd)->domain_id, chwall_ssidref);
  11.279 +        /* a) adjust types ref-count for running domains */
  11.280 +        for (i = 0; i < chwall_buf->chwall_max_types; i++)
  11.281 +            running_types[i] +=
  11.282 +                ssidrefs[chwall_ssidref * chwall_buf->chwall_max_types + i];
  11.283  
  11.284 -		/* b) check for conflict */
  11.285 -		for (i=0; i< chwall_buf->chwall_max_types; i++)
  11.286 -			if (conflict_aggregate_set[i] && 
  11.287 -			    ssidrefs[chwall_ssidref*chwall_buf->chwall_max_types + i]) {
  11.288 -				printk("%s: CHINESE WALL CONFLICT in type %02x.\n", __func__, i);
  11.289 -				violation = 1;
  11.290 -				goto out;
  11.291 -			}
  11.292 -		/* set violation and break out of the loop */
  11.293 -		/* c) adapt conflict aggregate set for this domain (notice conflicts) */
  11.294 -		for (i=0; i<chwall_buf->chwall_max_conflictsets; i++) {
  11.295 -			int common = 0;
  11.296 -			/* check if conflict_set_i and ssidref have common types */
  11.297 -			for (j=0; j<chwall_buf->chwall_max_types; j++)
  11.298 -				if (conflict_sets[i*chwall_buf->chwall_max_types + j] &&
  11.299 -				    ssidrefs[chwall_ssidref*chwall_buf->chwall_max_types + j]) {
  11.300 -					common = 1;
  11.301 -					break;
  11.302 -				}
  11.303 -			if (common == 0)
  11.304 -				continue; /* try next conflict set */
  11.305 -			/* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.306 -			for (j=0; j<chwall_buf->chwall_max_types; j++)
  11.307 -				if (conflict_sets[i*chwall_buf->chwall_max_types + j] &&
  11.308 -				    !ssidrefs[chwall_ssidref*chwall_buf->chwall_max_types + j])
  11.309 -					conflict_aggregate_set[j]++;
  11.310 -		}	
  11.311 -	}
  11.312 +        /* b) check for conflict */
  11.313 +        for (i = 0; i < chwall_buf->chwall_max_types; i++)
  11.314 +            if (conflict_aggregate_set[i] &&
  11.315 +                ssidrefs[chwall_ssidref * chwall_buf->chwall_max_types + i])
  11.316 +            {
  11.317 +                printk("%s: CHINESE WALL CONFLICT in type %02x.\n",
  11.318 +                       __func__, i);
  11.319 +                violation = 1;
  11.320 +                goto out;
  11.321 +            }
  11.322 +        /* set violation and break out of the loop */
  11.323 +        /* c) adapt conflict aggregate set for this domain (notice conflicts) */
  11.324 +        for (i = 0; i < chwall_buf->chwall_max_conflictsets; i++)
  11.325 +        {
  11.326 +            int common = 0;
  11.327 +            /* check if conflict_set_i and ssidref have common types */
  11.328 +            for (j = 0; j < chwall_buf->chwall_max_types; j++)
  11.329 +                if (conflict_sets[i * chwall_buf->chwall_max_types + j] &&
  11.330 +                    ssidrefs[chwall_ssidref *
  11.331 +                            chwall_buf->chwall_max_types + j])
  11.332 +                {
  11.333 +                    common = 1;
  11.334 +                    break;
  11.335 +                }
  11.336 +            if (common == 0)
  11.337 +                continue;       /* try next conflict set */
  11.338 +            /* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.339 +            for (j = 0; j < chwall_buf->chwall_max_types; j++)
  11.340 +                if (conflict_sets[i * chwall_buf->chwall_max_types + j] &&
  11.341 +                    !ssidrefs[chwall_ssidref *
  11.342 +                             chwall_buf->chwall_max_types + j])
  11.343 +                    conflict_aggregate_set[j]++;
  11.344 +        }
  11.345 +    }
  11.346   out:
  11.347 -        write_unlock(&domlist_lock);
  11.348 -	return violation;
  11.349 -	/* returning "violation != 0" means that the currently running set of domains would 
  11.350 -	 * not be possible if the new policy had been enforced before starting them; for chinese
  11.351 -	 * wall, this means that the new policy includes at least one conflict set of which 
  11.352 -	 * more than one type is currently running */
  11.353 +    write_unlock(&domlist_lock);
  11.354 +    return violation;
  11.355 +    /* returning "violation != 0" means that the currently running set of domains would
  11.356 +     * not be possible if the new policy had been enforced before starting them; for chinese
  11.357 +     * wall, this means that the new policy includes at least one conflict set of which
  11.358 +     * more than one type is currently running */
  11.359  }
  11.360  
  11.361 -static int
  11.362 -chwall_set_policy(u8 *buf, u16 buf_size) 
  11.363 -{	
  11.364 -	/* policy write-locked already */
  11.365 -	struct acm_chwall_policy_buffer *chwall_buf = (struct acm_chwall_policy_buffer *)buf;
  11.366 -	void *ssids = NULL, *conflict_sets = NULL, *running_types = NULL, *conflict_aggregate_set = NULL;	
  11.367 +static int chwall_set_policy(u8 * buf, u32 buf_size)
  11.368 +{
  11.369 +    /* policy write-locked already */
  11.370 +    struct acm_chwall_policy_buffer *chwall_buf =
  11.371 +        (struct acm_chwall_policy_buffer *) buf;
  11.372 +    void *ssids = NULL, *conflict_sets = NULL, *running_types =
  11.373 +        NULL, *conflict_aggregate_set = NULL;
  11.374 +
  11.375 +    if (buf_size < sizeof(struct acm_chwall_policy_buffer))
  11.376 +        return -EINVAL;
  11.377  
  11.378 -        /* rewrite the policy due to endianess */
  11.379 -        chwall_buf->policy_code                      = ntohl(chwall_buf->policy_code);
  11.380 -        chwall_buf->policy_version                   = ntohl(chwall_buf->policy_version);
  11.381 -        chwall_buf->chwall_max_types                 = ntohl(chwall_buf->chwall_max_types);
  11.382 -        chwall_buf->chwall_max_ssidrefs              = ntohl(chwall_buf->chwall_max_ssidrefs);
  11.383 -        chwall_buf->chwall_max_conflictsets          = ntohl(chwall_buf->chwall_max_conflictsets);
  11.384 -        chwall_buf->chwall_ssid_offset               = ntohl(chwall_buf->chwall_ssid_offset);
  11.385 -        chwall_buf->chwall_conflict_sets_offset      = ntohl(chwall_buf->chwall_conflict_sets_offset);
  11.386 -        chwall_buf->chwall_running_types_offset      = ntohl(chwall_buf->chwall_running_types_offset);
  11.387 -        chwall_buf->chwall_conflict_aggregate_offset = ntohl(chwall_buf->chwall_conflict_aggregate_offset);
  11.388 +    /* rewrite the policy due to endianess */
  11.389 +    chwall_buf->policy_code = ntohl(chwall_buf->policy_code);
  11.390 +    chwall_buf->policy_version = ntohl(chwall_buf->policy_version);
  11.391 +    chwall_buf->chwall_max_types = ntohl(chwall_buf->chwall_max_types);
  11.392 +    chwall_buf->chwall_max_ssidrefs =
  11.393 +        ntohl(chwall_buf->chwall_max_ssidrefs);
  11.394 +    chwall_buf->chwall_max_conflictsets =
  11.395 +        ntohl(chwall_buf->chwall_max_conflictsets);
  11.396 +    chwall_buf->chwall_ssid_offset = ntohl(chwall_buf->chwall_ssid_offset);
  11.397 +    chwall_buf->chwall_conflict_sets_offset =
  11.398 +        ntohl(chwall_buf->chwall_conflict_sets_offset);
  11.399 +    chwall_buf->chwall_running_types_offset =
  11.400 +        ntohl(chwall_buf->chwall_running_types_offset);
  11.401 +    chwall_buf->chwall_conflict_aggregate_offset =
  11.402 +        ntohl(chwall_buf->chwall_conflict_aggregate_offset);
  11.403  
  11.404 -	/* policy type and version checks */
  11.405 -	if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) ||
  11.406 -	    (chwall_buf->policy_version != ACM_CHWALL_VERSION))
  11.407 -		return -EINVAL;
  11.408 -
  11.409 -	/* 1. allocate new buffers */
  11.410 -	ssids = xmalloc_array(domaintype_t, chwall_buf->chwall_max_types*chwall_buf->chwall_max_ssidrefs);
  11.411 -	conflict_sets = xmalloc_array(domaintype_t, chwall_buf->chwall_max_conflictsets*chwall_buf->chwall_max_types);
  11.412 -	running_types = xmalloc_array(domaintype_t,chwall_buf->chwall_max_types);
  11.413 -	conflict_aggregate_set = xmalloc_array(domaintype_t, chwall_buf->chwall_max_types);
  11.414 +    /* policy type and version checks */
  11.415 +    if ((chwall_buf->policy_code != ACM_CHINESE_WALL_POLICY) ||
  11.416 +        (chwall_buf->policy_version != ACM_CHWALL_VERSION))
  11.417 +        return -EINVAL;
  11.418  
  11.419 -	if ((ssids == NULL)||(conflict_sets == NULL)||(running_types == NULL)||(conflict_aggregate_set == NULL))
  11.420 -		goto error_free;
  11.421 +    /* 1. allocate new buffers */
  11.422 +    ssids =
  11.423 +        xmalloc_array(domaintype_t,
  11.424 +                      chwall_buf->chwall_max_types *
  11.425 +                      chwall_buf->chwall_max_ssidrefs);
  11.426 +    conflict_sets =
  11.427 +        xmalloc_array(domaintype_t,
  11.428 +                      chwall_buf->chwall_max_conflictsets *
  11.429 +                      chwall_buf->chwall_max_types);
  11.430 +    running_types =
  11.431 +        xmalloc_array(domaintype_t, chwall_buf->chwall_max_types);
  11.432 +    conflict_aggregate_set =
  11.433 +        xmalloc_array(domaintype_t, chwall_buf->chwall_max_types);
  11.434  
  11.435 -	/* 2. set new policy */
  11.436 -	if (chwall_buf->chwall_ssid_offset + sizeof(domaintype_t) * 
  11.437 -	    chwall_buf->chwall_max_types * chwall_buf->chwall_max_ssidrefs > buf_size)
  11.438 -		goto error_free;
  11.439 -	arrcpy(ssids, buf + chwall_buf->chwall_ssid_offset,
  11.440 -	       sizeof(domaintype_t),  
  11.441 -	       chwall_buf->chwall_max_types * chwall_buf->chwall_max_ssidrefs);
  11.442 +    if ((ssids == NULL) || (conflict_sets == NULL)
  11.443 +        || (running_types == NULL) || (conflict_aggregate_set == NULL))
  11.444 +        goto error_free;
  11.445  
  11.446 -	if (chwall_buf->chwall_conflict_sets_offset + sizeof(domaintype_t) * 
  11.447 -	    chwall_buf->chwall_max_types * chwall_buf->chwall_max_conflictsets > buf_size)
  11.448 -		goto error_free;
  11.449 +    /* 2. set new policy */
  11.450 +    if (chwall_buf->chwall_ssid_offset + sizeof(domaintype_t) *
  11.451 +        chwall_buf->chwall_max_types * chwall_buf->chwall_max_ssidrefs >
  11.452 +        buf_size)
  11.453 +        goto error_free;
  11.454  
  11.455 -	arrcpy(conflict_sets, buf + chwall_buf->chwall_conflict_sets_offset,
  11.456 -	       sizeof(domaintype_t),
  11.457 -	       chwall_buf->chwall_max_types * chwall_buf->chwall_max_conflictsets);
  11.458 +    arrcpy(ssids, buf + chwall_buf->chwall_ssid_offset,
  11.459 +           sizeof(domaintype_t),
  11.460 +           chwall_buf->chwall_max_types * chwall_buf->chwall_max_ssidrefs);
  11.461 +
  11.462 +    if (chwall_buf->chwall_conflict_sets_offset + sizeof(domaintype_t) *
  11.463 +        chwall_buf->chwall_max_types *
  11.464 +        chwall_buf->chwall_max_conflictsets > buf_size)
  11.465 +        goto error_free;
  11.466  
  11.467 -	/* we also use new state buffers since max_types can change */
  11.468 -	memset(running_types, 0, sizeof(domaintype_t)*chwall_buf->chwall_max_types);
  11.469 -	memset(conflict_aggregate_set, 0, sizeof(domaintype_t)*chwall_buf->chwall_max_types);
  11.470 +    arrcpy(conflict_sets, buf + chwall_buf->chwall_conflict_sets_offset,
  11.471 +           sizeof(domaintype_t),
  11.472 +           chwall_buf->chwall_max_types *
  11.473 +           chwall_buf->chwall_max_conflictsets);
  11.474 +
  11.475 +    /* we also use new state buffers since max_types can change */
  11.476 +    memset(running_types, 0,
  11.477 +           sizeof(domaintype_t) * chwall_buf->chwall_max_types);
  11.478 +    memset(conflict_aggregate_set, 0,
  11.479 +           sizeof(domaintype_t) * chwall_buf->chwall_max_types);
  11.480  
  11.481 -	/* 3. now re-calculate the state for the new policy based on running domains; 
  11.482 -	 *    this can fail if new policy is conflicting with running domains */
  11.483 -	if (chwall_init_state(chwall_buf, ssids, conflict_sets, running_types, conflict_aggregate_set)) {
  11.484 -		printk("%s: New policy conflicts with running domains. Policy load aborted.\n", __func__);
  11.485 -		goto error_free; /* new policy conflicts with running domains */
  11.486 -	}
  11.487 -	/* 4. free old policy buffers, replace with new ones */
  11.488 -	chwall_bin_pol.max_types = chwall_buf->chwall_max_types;
  11.489 -	chwall_bin_pol.max_ssidrefs = chwall_buf->chwall_max_ssidrefs;
  11.490 -	chwall_bin_pol.max_conflictsets = chwall_buf->chwall_max_conflictsets;
  11.491 -	if (chwall_bin_pol.ssidrefs != NULL) 
  11.492 -		xfree(chwall_bin_pol.ssidrefs);
  11.493 -	if (chwall_bin_pol.conflict_aggregate_set != NULL) 
  11.494 -		xfree(chwall_bin_pol.conflict_aggregate_set);
  11.495 -	if (chwall_bin_pol.running_types != NULL) 
  11.496 -		xfree(chwall_bin_pol.running_types);
  11.497 -	if (chwall_bin_pol.conflict_sets != NULL) 
  11.498 -		xfree(chwall_bin_pol.conflict_sets);
  11.499 -	chwall_bin_pol.ssidrefs = ssids;
  11.500 -	chwall_bin_pol.conflict_aggregate_set = conflict_aggregate_set;
  11.501 -	chwall_bin_pol.running_types = running_types;
  11.502 -	chwall_bin_pol.conflict_sets = conflict_sets;
  11.503 -	return ACM_OK;
  11.504 +    /* 3. now re-calculate the state for the new policy based on running domains;
  11.505 +     *    this can fail if new policy is conflicting with running domains */
  11.506 +    if (chwall_init_state(chwall_buf, ssids,
  11.507 +                          conflict_sets, running_types,
  11.508 +                          conflict_aggregate_set))
  11.509 +    {
  11.510 +        printk("%s: New policy conflicts with running domains. Policy load aborted.\n",
  11.511 +               __func__);
  11.512 +        goto error_free;        /* new policy conflicts with running domains */
  11.513 +    }
  11.514 +    /* 4. free old policy buffers, replace with new ones */
  11.515 +    chwall_bin_pol.max_types = chwall_buf->chwall_max_types;
  11.516 +    chwall_bin_pol.max_ssidrefs = chwall_buf->chwall_max_ssidrefs;
  11.517 +    chwall_bin_pol.max_conflictsets = chwall_buf->chwall_max_conflictsets;
  11.518 +    if (chwall_bin_pol.ssidrefs != NULL)
  11.519 +        xfree(chwall_bin_pol.ssidrefs);
  11.520 +    if (chwall_bin_pol.conflict_aggregate_set != NULL)
  11.521 +        xfree(chwall_bin_pol.conflict_aggregate_set);
  11.522 +    if (chwall_bin_pol.running_types != NULL)
  11.523 +        xfree(chwall_bin_pol.running_types);
  11.524 +    if (chwall_bin_pol.conflict_sets != NULL)
  11.525 +        xfree(chwall_bin_pol.conflict_sets);
  11.526 +    chwall_bin_pol.ssidrefs = ssids;
  11.527 +    chwall_bin_pol.conflict_aggregate_set = conflict_aggregate_set;
  11.528 +    chwall_bin_pol.running_types = running_types;
  11.529 +    chwall_bin_pol.conflict_sets = conflict_sets;
  11.530 +    return ACM_OK;
  11.531  
  11.532 -error_free:
  11.533 -	printk("%s: ERROR setting policy.\n", __func__);
  11.534 -	if (ssids != NULL) xfree(ssids);
  11.535 -	if (conflict_sets != NULL) xfree(conflict_sets);
  11.536 -	if (running_types != NULL) xfree(running_types);
  11.537 -	if (conflict_aggregate_set != NULL) xfree(conflict_aggregate_set);
  11.538 -	return -EFAULT;
  11.539 -}
  11.540 -	
  11.541 -static int 
  11.542 -chwall_dump_stats(u8 *buf, u16 len)
  11.543 -{
  11.544 -	/* no stats for Chinese Wall Policy */
  11.545 -	return 0;
  11.546 + error_free:
  11.547 +    printk("%s: ERROR setting policy.\n", __func__);
  11.548 +    if (ssids != NULL)
  11.549 +        xfree(ssids);
  11.550 +    if (conflict_sets != NULL)
  11.551 +        xfree(conflict_sets);
  11.552 +    if (running_types != NULL)
  11.553 +        xfree(running_types);
  11.554 +    if (conflict_aggregate_set != NULL)
  11.555 +        xfree(conflict_aggregate_set);
  11.556 +    return -EFAULT;
  11.557  }
  11.558  
  11.559 -static int
  11.560 -chwall_dump_ssid_types(ssidref_t ssidref, u8 *buf, u16 len)
  11.561 +static int chwall_dump_stats(u8 * buf, u16 len)
  11.562 +{
  11.563 +    /* no stats for Chinese Wall Policy */
  11.564 +    return 0;
  11.565 +}
  11.566 +
  11.567 +static int chwall_dump_ssid_types(ssidref_t ssidref, u8 * buf, u16 len)
  11.568  {
  11.569      int i;
  11.570  
  11.571 @@ -319,12 +385,14 @@ chwall_dump_ssid_types(ssidref_t ssidref
  11.572      if (chwall_bin_pol.max_types > len)
  11.573          return -EFAULT;
  11.574  
  11.575 -	if (ssidref >= chwall_bin_pol.max_ssidrefs)
  11.576 -		return -EFAULT;
  11.577 +    if (ssidref >= chwall_bin_pol.max_ssidrefs)
  11.578 +        return -EFAULT;
  11.579  
  11.580      /* read types for chwall ssidref */
  11.581 -    for(i=0; i< chwall_bin_pol.max_types; i++) {
  11.582 -        if (chwall_bin_pol.ssidrefs[ssidref * chwall_bin_pol.max_types + i])
  11.583 +    for (i = 0; i < chwall_bin_pol.max_types; i++)
  11.584 +    {
  11.585 +        if (chwall_bin_pol.
  11.586 +            ssidrefs[ssidref * chwall_bin_pol.max_types + i])
  11.587              buf[i] = 1;
  11.588          else
  11.589              buf[i] = 0;
  11.590 @@ -336,198 +404,239 @@ chwall_dump_ssid_types(ssidref_t ssidref
  11.591   * Authorization functions
  11.592   ***************************/
  11.593  
  11.594 -
  11.595  /* -------- DOMAIN OPERATION HOOKS -----------*/
  11.596  
  11.597 -static int 
  11.598 -chwall_pre_domain_create(void *subject_ssid, ssidref_t ssidref)
  11.599 +static int chwall_pre_domain_create(void *subject_ssid, ssidref_t ssidref)
  11.600  {
  11.601 -	ssidref_t chwall_ssidref;
  11.602 -	int i,j;
  11.603 -	traceprintk("%s.\n", __func__);
  11.604 +    ssidref_t chwall_ssidref;
  11.605 +    int i, j;
  11.606 +    traceprintk("%s.\n", __func__);
  11.607  
  11.608 -	read_lock(&acm_bin_pol_rwlock);
  11.609 -	chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.610 -	if (chwall_ssidref == ACM_DEFAULT_LOCAL_SSID) {
  11.611 -		printk("%s: ERROR CHWALL SSID is NOT SET but policy enforced.\n", __func__);
  11.612 -		read_unlock(&acm_bin_pol_rwlock);
  11.613 -		return ACM_ACCESS_DENIED; /* catching and indicating config error */
  11.614 -	}
  11.615 -	if (chwall_ssidref >= chwall_bin_pol.max_ssidrefs) {
  11.616 -		printk("%s: ERROR chwall_ssidref > max(%x).\n",
  11.617 -		       __func__, chwall_bin_pol.max_ssidrefs-1);
  11.618 -		read_unlock(&acm_bin_pol_rwlock);
  11.619 -		return ACM_ACCESS_DENIED;
  11.620 -	}
  11.621 -	/* A: chinese wall check for conflicts */
  11.622 -	for (i=0; i< chwall_bin_pol.max_types; i++)
  11.623 -		if (chwall_bin_pol.conflict_aggregate_set[i] && 
  11.624 -		    chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + i]) {
  11.625 -			printk("%s: CHINESE WALL CONFLICT in type %02x.\n", __func__, i);
  11.626 -			read_unlock(&acm_bin_pol_rwlock);
  11.627 -		        return ACM_ACCESS_DENIED;
  11.628 -		}
  11.629 +    read_lock(&acm_bin_pol_rwlock);
  11.630 +    chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.631 +    if (chwall_ssidref == ACM_DEFAULT_LOCAL_SSID)
  11.632 +    {
  11.633 +        printk("%s: ERROR CHWALL SSID is NOT SET but policy enforced.\n",
  11.634 +               __func__);
  11.635 +        read_unlock(&acm_bin_pol_rwlock);
  11.636 +        return ACM_ACCESS_DENIED;       /* catching and indicating config error */
  11.637 +    }
  11.638 +    if (chwall_ssidref >= chwall_bin_pol.max_ssidrefs)
  11.639 +    {
  11.640 +        printk("%s: ERROR chwall_ssidref > max(%x).\n",
  11.641 +               __func__, chwall_bin_pol.max_ssidrefs - 1);
  11.642 +        read_unlock(&acm_bin_pol_rwlock);
  11.643 +        return ACM_ACCESS_DENIED;
  11.644 +    }
  11.645 +    /* A: chinese wall check for conflicts */
  11.646 +    for (i = 0; i < chwall_bin_pol.max_types; i++)
  11.647 +        if (chwall_bin_pol.conflict_aggregate_set[i] &&
  11.648 +            chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.649 +                                   chwall_bin_pol.max_types + i])
  11.650 +        {
  11.651 +            printk("%s: CHINESE WALL CONFLICT in type %02x.\n", __func__, i);
  11.652 +            read_unlock(&acm_bin_pol_rwlock);
  11.653 +            return ACM_ACCESS_DENIED;
  11.654 +        }
  11.655  
  11.656 -	/* B: chinese wall conflict set adjustment (so that other 
  11.657 -	 *	other domains simultaneously created are evaluated against this new set)*/
  11.658 -	for (i=0; i<chwall_bin_pol.max_conflictsets; i++) {
  11.659 -		int common = 0;
  11.660 -		/* check if conflict_set_i and ssidref have common types */
  11.661 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.662 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.663 -			    chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j]) {
  11.664 -				common = 1;
  11.665 -				break;
  11.666 -			}
  11.667 -		if (common == 0)
  11.668 -			continue; /* try next conflict set */
  11.669 -		/* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.670 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.671 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.672 -			    !chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j])
  11.673 -				chwall_bin_pol.conflict_aggregate_set[j]++;
  11.674 -	}
  11.675 -	read_unlock(&acm_bin_pol_rwlock);
  11.676 -	return ACM_ACCESS_PERMITTED;
  11.677 +    /* B: chinese wall conflict set adjustment (so that other
  11.678 +     *      other domains simultaneously created are evaluated against this new set)*/
  11.679 +    for (i = 0; i < chwall_bin_pol.max_conflictsets; i++)
  11.680 +    {
  11.681 +        int common = 0;
  11.682 +        /* check if conflict_set_i and ssidref have common types */
  11.683 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.684 +            if (chwall_bin_pol.
  11.685 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.686 +                && chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.687 +                                          chwall_bin_pol.max_types + j])
  11.688 +            {
  11.689 +                common = 1;
  11.690 +                break;
  11.691 +            }
  11.692 +        if (common == 0)
  11.693 +            continue;           /* try next conflict set */
  11.694 +        /* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.695 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.696 +            if (chwall_bin_pol.
  11.697 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.698 +                && !chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.699 +                                           chwall_bin_pol.max_types + j])
  11.700 +                chwall_bin_pol.conflict_aggregate_set[j]++;
  11.701 +    }
  11.702 +    read_unlock(&acm_bin_pol_rwlock);
  11.703 +    return ACM_ACCESS_PERMITTED;
  11.704  }
  11.705  
  11.706 -static void
  11.707 -chwall_post_domain_create(domid_t domid, ssidref_t ssidref)
  11.708 +static void chwall_post_domain_create(domid_t domid, ssidref_t ssidref)
  11.709  {
  11.710 -	int i,j;
  11.711 -	ssidref_t chwall_ssidref;
  11.712 -	traceprintk("%s.\n", __func__);
  11.713 -	
  11.714 -	read_lock(&acm_bin_pol_rwlock);
  11.715 -	chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.716 -	/* adjust types ref-count for running domains */
  11.717 -	for (i=0; i< chwall_bin_pol.max_types; i++)
  11.718 -		chwall_bin_pol.running_types[i] +=
  11.719 -			chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + i];
  11.720 -	if (domid) {
  11.721 -		read_unlock(&acm_bin_pol_rwlock);
  11.722 -		return;
  11.723 -	}
  11.724 -	/* Xen does not call pre-create hook for DOM0;
  11.725 -	 * to consider type conflicts of any domain with DOM0, we need
  11.726 -	 * to adjust the conflict_aggregate for DOM0 here the same way it
  11.727 -	 * is done for non-DOM0 domains in the pre-hook */
  11.728 -	printkd("%s: adjusting security state for DOM0 (ssidref=%x, chwall_ssidref=%x).\n", 
  11.729 -		__func__, ssidref, chwall_ssidref);
  11.730 +    int i, j;
  11.731 +    ssidref_t chwall_ssidref;
  11.732 +    traceprintk("%s.\n", __func__);
  11.733 +
  11.734 +    read_lock(&acm_bin_pol_rwlock);
  11.735 +    chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.736 +    /* adjust types ref-count for running domains */
  11.737 +    for (i = 0; i < chwall_bin_pol.max_types; i++)
  11.738 +        chwall_bin_pol.running_types[i] +=
  11.739 +            chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.740 +                                   chwall_bin_pol.max_types + i];
  11.741 +    if (domid)
  11.742 +    {
  11.743 +        read_unlock(&acm_bin_pol_rwlock);
  11.744 +        return;
  11.745 +    }
  11.746 +    /* Xen does not call pre-create hook for DOM0;
  11.747 +     * to consider type conflicts of any domain with DOM0, we need
  11.748 +     * to adjust the conflict_aggregate for DOM0 here the same way it
  11.749 +     * is done for non-DOM0 domains in the pre-hook */
  11.750 +    printkd("%s: adjusting security state for DOM0 (ssidref=%x, chwall_ssidref=%x).\n",
  11.751 +            __func__, ssidref, chwall_ssidref);
  11.752  
  11.753 -	/* chinese wall conflict set adjustment (so that other 
  11.754 -	 *	other domains simultaneously created are evaluated against this new set)*/
  11.755 -	for (i=0; i<chwall_bin_pol.max_conflictsets; i++) {
  11.756 -		int common = 0;
  11.757 -		/* check if conflict_set_i and ssidref have common types */
  11.758 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.759 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.760 -			    chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j]) {
  11.761 -				common = 1;
  11.762 -				break;
  11.763 -			}
  11.764 -		if (common == 0)
  11.765 -			continue; /* try next conflict set */
  11.766 -		/* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.767 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.768 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.769 -			    !chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j])
  11.770 -				chwall_bin_pol.conflict_aggregate_set[j]++;
  11.771 -	}
  11.772 -	read_unlock(&acm_bin_pol_rwlock);
  11.773 -	return;
  11.774 +    /* chinese wall conflict set adjustment (so that other
  11.775 +     *      other domains simultaneously created are evaluated against this new set)*/
  11.776 +    for (i = 0; i < chwall_bin_pol.max_conflictsets; i++)
  11.777 +    {
  11.778 +        int common = 0;
  11.779 +        /* check if conflict_set_i and ssidref have common types */
  11.780 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.781 +            if (chwall_bin_pol.
  11.782 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.783 +                && chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.784 +                                          chwall_bin_pol.max_types + j])
  11.785 +            {
  11.786 +                common = 1;
  11.787 +                break;
  11.788 +            }
  11.789 +        if (common == 0)
  11.790 +            continue;           /* try next conflict set */
  11.791 +        /* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.792 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.793 +            if (chwall_bin_pol.
  11.794 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.795 +                && !chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.796 +                                           chwall_bin_pol.max_types + j])
  11.797 +                chwall_bin_pol.conflict_aggregate_set[j]++;
  11.798 +    }
  11.799 +    read_unlock(&acm_bin_pol_rwlock);
  11.800 +    return;
  11.801  }
  11.802  
  11.803  static void
  11.804  chwall_fail_domain_create(void *subject_ssid, ssidref_t ssidref)
  11.805  {
  11.806 -	int i, j;
  11.807 -	ssidref_t chwall_ssidref;
  11.808 -	traceprintk("%s.\n", __func__);
  11.809 +    int i, j;
  11.810 +    ssidref_t chwall_ssidref;
  11.811 +    traceprintk("%s.\n", __func__);
  11.812  
  11.813 -	read_lock(&acm_bin_pol_rwlock);
  11.814 -	chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.815 -	/* roll-back: re-adjust conflicting types aggregate */
  11.816 -	for (i=0; i<chwall_bin_pol.max_conflictsets; i++) {
  11.817 -		int common = 0;
  11.818 -		/* check if conflict_set_i and ssidref have common types */
  11.819 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.820 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.821 -			    chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j]) {
  11.822 -				common = 1;
  11.823 -				break;
  11.824 -			}
  11.825 -		if (common == 0)
  11.826 -			continue; /* try next conflict set, this one does not include any type of chwall_ssidref */
  11.827 -		/* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.828 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.829 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.830 -			    !chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j])
  11.831 -				chwall_bin_pol.conflict_aggregate_set[j]--;
  11.832 -	}
  11.833 -	read_unlock(&acm_bin_pol_rwlock);
  11.834 +    read_lock(&acm_bin_pol_rwlock);
  11.835 +    chwall_ssidref = GET_SSIDREF(ACM_CHINESE_WALL_POLICY, ssidref);
  11.836 +    /* roll-back: re-adjust conflicting types aggregate */
  11.837 +    for (i = 0; i < chwall_bin_pol.max_conflictsets; i++)
  11.838 +    {
  11.839 +        int common = 0;
  11.840 +        /* check if conflict_set_i and ssidref have common types */
  11.841 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.842 +            if (chwall_bin_pol.
  11.843 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.844 +                && chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.845 +                                          chwall_bin_pol.max_types + j])
  11.846 +            {
  11.847 +                common = 1;
  11.848 +                break;
  11.849 +            }
  11.850 +        if (common == 0)
  11.851 +            continue;           /* try next conflict set, this one does not include any type of chwall_ssidref */
  11.852 +        /* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.853 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.854 +            if (chwall_bin_pol.
  11.855 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.856 +                && !chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.857 +                                           chwall_bin_pol.max_types + j])
  11.858 +                chwall_bin_pol.conflict_aggregate_set[j]--;
  11.859 +    }
  11.860 +    read_unlock(&acm_bin_pol_rwlock);
  11.861  }
  11.862  
  11.863  
  11.864 -static void
  11.865 -chwall_post_domain_destroy(void *object_ssid, domid_t id) 
  11.866 +static void chwall_post_domain_destroy(void *object_ssid, domid_t id)
  11.867  {
  11.868 -	int i,j;
  11.869 -	struct chwall_ssid *chwall_ssidp = 
  11.870 -		GET_SSIDP(ACM_CHINESE_WALL_POLICY, (struct acm_ssid_domain *)object_ssid);
  11.871 -	ssidref_t chwall_ssidref = chwall_ssidp->chwall_ssidref;
  11.872 +    int i, j;
  11.873 +    struct chwall_ssid *chwall_ssidp = GET_SSIDP(ACM_CHINESE_WALL_POLICY,
  11.874 +                                                 (struct acm_ssid_domain *)
  11.875 +                                                 object_ssid);
  11.876 +    ssidref_t chwall_ssidref = chwall_ssidp->chwall_ssidref;
  11.877  
  11.878 -	traceprintk("%s.\n", __func__);
  11.879 +    traceprintk("%s.\n", __func__);
  11.880  
  11.881 -	read_lock(&acm_bin_pol_rwlock);
  11.882 -	/* adjust running types set */
  11.883 -	for (i=0; i< chwall_bin_pol.max_types; i++)
  11.884 -		chwall_bin_pol.running_types[i] -=
  11.885 -			chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + i];
  11.886 +    read_lock(&acm_bin_pol_rwlock);
  11.887 +    /* adjust running types set */
  11.888 +    for (i = 0; i < chwall_bin_pol.max_types; i++)
  11.889 +        chwall_bin_pol.running_types[i] -=
  11.890 +            chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.891 +                                   chwall_bin_pol.max_types + i];
  11.892  
  11.893 -	/* roll-back: re-adjust conflicting types aggregate */
  11.894 -	for (i=0; i<chwall_bin_pol.max_conflictsets; i++) {
  11.895 -		int common = 0;
  11.896 -		/* check if conflict_set_i and ssidref have common types */
  11.897 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.898 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.899 -			    chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j]) {
  11.900 -				common = 1;
  11.901 -				break;
  11.902 -			}
  11.903 -		if (common == 0)
  11.904 -			continue; /* try next conflict set, this one does not include any type of chwall_ssidref */
  11.905 -		/* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.906 -		for (j=0; j<chwall_bin_pol.max_types; j++)
  11.907 -			if (chwall_bin_pol.conflict_sets[i*chwall_bin_pol.max_types + j] &&
  11.908 -			    !chwall_bin_pol.ssidrefs[chwall_ssidref*chwall_bin_pol.max_types + j])
  11.909 -				chwall_bin_pol.conflict_aggregate_set[j]--;
  11.910 -	}
  11.911 -	read_unlock(&acm_bin_pol_rwlock);
  11.912 -	return;
  11.913 +    /* roll-back: re-adjust conflicting types aggregate */
  11.914 +    for (i = 0; i < chwall_bin_pol.max_conflictsets; i++)
  11.915 +    {
  11.916 +        int common = 0;
  11.917 +        /* check if conflict_set_i and ssidref have common types */
  11.918 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.919 +            if (chwall_bin_pol.
  11.920 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.921 +                && chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.922 +                                          chwall_bin_pol.max_types + j])
  11.923 +            {
  11.924 +                common = 1;
  11.925 +                break;
  11.926 +            }
  11.927 +        if (common == 0)
  11.928 +            continue;           /* try next conflict set, this one does not include any type of chwall_ssidref */
  11.929 +        /* now add types of the conflict set to conflict_aggregate_set (except types in chwall_ssidref) */
  11.930 +        for (j = 0; j < chwall_bin_pol.max_types; j++)
  11.931 +            if (chwall_bin_pol.
  11.932 +                conflict_sets[i * chwall_bin_pol.max_types + j]
  11.933 +                && !chwall_bin_pol.ssidrefs[chwall_ssidref *
  11.934 +                                           chwall_bin_pol.max_types + j])
  11.935 +                chwall_bin_pol.conflict_aggregate_set[j]--;
  11.936 +    }
  11.937 +    read_unlock(&acm_bin_pol_rwlock);
  11.938 +    return;
  11.939  }
  11.940  
  11.941  struct acm_operations acm_chinesewall_ops = {
  11.942 -	/* policy management services */
  11.943 -	.init_domain_ssid		= chwall_init_domain_ssid,
  11.944 -	.free_domain_ssid		= chwall_free_domain_ssid,
  11.945 -	.dump_binary_policy		= chwall_dump_policy,
  11.946 -	.set_binary_policy		= chwall_set_policy,
  11.947 -	.dump_statistics		= chwall_dump_stats,
  11.948 -    .dump_ssid_types        = chwall_dump_ssid_types,
  11.949 -	/* domain management control hooks */
  11.950 -	.pre_domain_create     		= chwall_pre_domain_create,
  11.951 -	.post_domain_create		= chwall_post_domain_create,
  11.952 -	.fail_domain_create		= chwall_fail_domain_create,
  11.953 -	.post_domain_destroy		= chwall_post_domain_destroy,
  11.954 -	/* event channel control hooks */
  11.955 -	.pre_eventchannel_unbound      	= NULL,
  11.956 -	.fail_eventchannel_unbound	= NULL,
  11.957 -	.pre_eventchannel_interdomain	= NULL,
  11.958 -	.fail_eventchannel_interdomain  = NULL,
  11.959 -	/* grant table control hooks */
  11.960 -	.pre_grant_map_ref       	= NULL,
  11.961 -	.fail_grant_map_ref		= NULL,
  11.962 -	.pre_grant_setup	       	= NULL,
  11.963 -	.fail_grant_setup		= NULL,
  11.964 +    /* policy management services */
  11.965 +    .init_domain_ssid = chwall_init_domain_ssid,
  11.966 +    .free_domain_ssid = chwall_free_domain_ssid,
  11.967 +    .dump_binary_policy = chwall_dump_policy,
  11.968 +    .set_binary_policy = chwall_set_policy,
  11.969 +    .dump_statistics = chwall_dump_stats,
  11.970 +    .dump_ssid_types = chwall_dump_ssid_types,
  11.971 +    /* domain management control hooks */
  11.972 +    .pre_domain_create = chwall_pre_domain_create,
  11.973 +    .post_domain_create = chwall_post_domain_create,
  11.974 +    .fail_domain_create = chwall_fail_domain_create,
  11.975 +    .post_domain_destroy = chwall_post_domain_destroy,
  11.976 +    /* event channel control hooks */
  11.977 +    .pre_eventchannel_unbound = NULL,
  11.978 +    .fail_eventchannel_unbound = NULL,
  11.979 +    .pre_eventchannel_interdomain = NULL,
  11.980 +    .fail_eventchannel_interdomain = NULL,
  11.981 +    /* grant table control hooks */
  11.982 +    .pre_grant_map_ref = NULL,
  11.983 +    .fail_grant_map_ref = NULL,
  11.984 +    .pre_grant_setup = NULL,
  11.985 +    .fail_grant_setup = NULL,
  11.986 +    /* generic domain-requested decision hooks */
  11.987 +    .sharing = NULL,
  11.988  };
  11.989 +
  11.990 +/*
  11.991 + * Local variables:
  11.992 + * mode: C
  11.993 + * c-set-style: "BSD"
  11.994 + * c-basic-offset: 4
  11.995 + * tab-width: 4
  11.996 + * indent-tabs-mode: nil
  11.997 + * End:
  11.998 + */
    12.1 --- a/xen/acm/acm_core.c	Fri Oct 21 12:06:17 2005 +0100
    12.2 +++ b/xen/acm/acm_core.c	Fri Oct 21 12:07:14 2005 +0100
    12.3 @@ -47,7 +47,7 @@ void acm_init_chwall_policy(void);
    12.4  void acm_init_ste_policy(void);
    12.5  
    12.6  extern struct acm_operations acm_chinesewall_ops, 
    12.7 -	acm_simple_type_enforcement_ops, acm_null_ops;
    12.8 +    acm_simple_type_enforcement_ops, acm_null_ops;
    12.9  
   12.10  /* global ops structs called by the hooks */
   12.11  struct acm_operations *acm_primary_ops = NULL;
   12.12 @@ -66,7 +66,7 @@ void acm_set_endian(void)
   12.13      u32 test = 1;
   12.14      if (*((u8 *)&test) == 1)
   12.15      {
   12.16 -      	printk("ACM module running in LITTLE ENDIAN.\n");
   12.17 +        printk("ACM module running in LITTLE ENDIAN.\n");
   12.18          little_endian = 1;
   12.19      }
   12.20      else
   12.21 @@ -80,10 +80,10 @@ void acm_set_endian(void)
   12.22  static void
   12.23  acm_init_binary_policy(void *primary, void *secondary)
   12.24  {
   12.25 -	acm_bin_pol.primary_policy_code = 0;
   12.26 -	acm_bin_pol.secondary_policy_code = 0;
   12.27 -	acm_bin_pol.primary_binary_policy = primary;
   12.28 -	acm_bin_pol.secondary_binary_policy = secondary;
   12.29 +    acm_bin_pol.primary_policy_code = 0;
   12.30 +    acm_bin_pol.secondary_policy_code = 0;
   12.31 +    acm_bin_pol.primary_binary_policy = primary;
   12.32 +    acm_bin_pol.secondary_binary_policy = secondary;
   12.33  }
   12.34  
   12.35  static int
   12.36 @@ -96,7 +96,7 @@ acm_setup(unsigned int *initrdidx,
   12.37      int rc = ACM_OK;
   12.38  
   12.39      if (mbi->mods_count > 1)
   12.40 -	    *initrdidx = 1;
   12.41 +        *initrdidx = 1;
   12.42  
   12.43      /*
   12.44       * Try all modules and see whichever could be the binary policy.
   12.45 @@ -115,14 +115,14 @@ acm_setup(unsigned int *initrdidx,
   12.46  #error Architecture unsupported by sHype
   12.47  #endif
   12.48          _policy_len   = mod[i].mod_end - mod[i].mod_start;
   12.49 -	if (_policy_len < sizeof(struct acm_policy_buffer))
   12.50 -		continue; /* not a policy */
   12.51 +        if (_policy_len < sizeof(struct acm_policy_buffer))
   12.52 +            continue; /* not a policy */
   12.53  
   12.54          pol = (struct acm_policy_buffer *)_policy_start;
   12.55          if (ntohl(pol->magic) == ACM_MAGIC)
   12.56          {
   12.57              rc = acm_set_policy((void *)_policy_start,
   12.58 -                                (u16)_policy_len,
   12.59 +                                (u32)_policy_len,
   12.60                                  0);
   12.61              if (rc == ACM_OK)
   12.62              {
   12.63 @@ -145,7 +145,7 @@ acm_setup(unsigned int *initrdidx,
   12.64              }
   12.65              else
   12.66              {
   12.67 -            	printk("Invalid policy. %d.th module line.\n", i+1);
   12.68 +                printk("Invalid policy. %d.th module line.\n", i+1);
   12.69              }
   12.70          } /* end if a binary policy definition, i.e., (ntohl(pol->magic) == ACM_MAGIC ) */
   12.71      }
   12.72 @@ -158,10 +158,10 @@ acm_init(unsigned int *initrdidx,
   12.73           const multiboot_info_t *mbi,
   12.74           unsigned long initial_images_start)
   12.75  {
   12.76 -	int ret = ACM_OK;
   12.77 +    int ret = ACM_OK;
   12.78  
   12.79      acm_set_endian();
   12.80 -	write_lock(&acm_bin_pol_rwlock);
   12.81 +    write_lock(&acm_bin_pol_rwlock);
   12.82      acm_init_binary_policy(NULL, NULL);
   12.83  
   12.84      /* set primary policy component */
   12.85 @@ -170,14 +170,14 @@ acm_init(unsigned int *initrdidx,
   12.86  
   12.87      case ACM_CHINESE_WALL_POLICY:
   12.88          acm_init_chwall_policy();
   12.89 -		acm_bin_pol.primary_policy_code = ACM_CHINESE_WALL_POLICY;
   12.90 -		acm_primary_ops = &acm_chinesewall_ops;
   12.91 +        acm_bin_pol.primary_policy_code = ACM_CHINESE_WALL_POLICY;
   12.92 +        acm_primary_ops = &acm_chinesewall_ops;
   12.93          break;
   12.94  
   12.95      case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
   12.96          acm_init_ste_policy();
   12.97 -		acm_bin_pol.primary_policy_code = ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY;
   12.98 -		acm_primary_ops = &acm_simple_type_enforcement_ops;
   12.99 +        acm_bin_pol.primary_policy_code = ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  12.100 +        acm_primary_ops = &acm_simple_type_enforcement_ops;
  12.101          break;
  12.102  
  12.103      default:
  12.104 @@ -190,9 +190,9 @@ acm_init(unsigned int *initrdidx,
  12.105      /* secondary policy component part */
  12.106      switch ((ACM_USE_SECURITY_POLICY) >> 4) {
  12.107      case ACM_NULL_POLICY:
  12.108 -		acm_bin_pol.secondary_policy_code = ACM_NULL_POLICY;
  12.109 -		acm_secondary_ops = &acm_null_ops;
  12.110 -		break;
  12.111 +        acm_bin_pol.secondary_policy_code = ACM_NULL_POLICY;
  12.112 +        acm_secondary_ops = &acm_null_ops;
  12.113 +        break;
  12.114  
  12.115      case ACM_CHINESE_WALL_POLICY:
  12.116          if (acm_bin_pol.primary_policy_code == ACM_CHINESE_WALL_POLICY)
  12.117 @@ -200,9 +200,9 @@ acm_init(unsigned int *initrdidx,
  12.118              ret = -EINVAL;
  12.119              goto out;
  12.120          }
  12.121 -		acm_init_chwall_policy();
  12.122 +        acm_init_chwall_policy();
  12.123          acm_bin_pol.secondary_policy_code = ACM_CHINESE_WALL_POLICY;
  12.124 -		acm_secondary_ops = &acm_chinesewall_ops;
  12.125 +        acm_secondary_ops = &acm_chinesewall_ops;
  12.126          break;
  12.127  
  12.128      case ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY:
  12.129 @@ -211,9 +211,9 @@ acm_init(unsigned int *initrdidx,
  12.130              ret = -EINVAL;
  12.131              goto out;
  12.132          }
  12.133 -		acm_init_ste_policy();
  12.134 -		acm_bin_pol.secondary_policy_code = ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  12.135 -		acm_secondary_ops = &acm_simple_type_enforcement_ops;
  12.136 +        acm_init_ste_policy();
  12.137 +        acm_bin_pol.secondary_policy_code = ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY;
  12.138 +        acm_secondary_ops = &acm_simple_type_enforcement_ops;
  12.139          break;
  12.140  
  12.141      default:
  12.142 @@ -222,96 +222,103 @@ acm_init(unsigned int *initrdidx,
  12.143      }
  12.144  
  12.145   out:
  12.146 -	write_unlock(&acm_bin_pol_rwlock);
  12.147 +    write_unlock(&acm_bin_pol_rwlock);
  12.148  
  12.149 -	if (ret != ACM_OK)
  12.150 +    if (ret != ACM_OK)
  12.151      {
  12.152 -        printk("%s: Error setting policies.\n", __func__);
  12.153 +        printk("%s: Error initializing policies.\n", __func__);
  12.154          /* here one could imagine a clean panic */
  12.155 -		return -EINVAL;
  12.156 -	}
  12.157 -	acm_setup(initrdidx, mbi, initial_images_start);
  12.158 -	printk("%s: Enforcing Primary %s, Secondary %s.\n", __func__, 
  12.159 -	       ACM_POLICY_NAME(acm_bin_pol.primary_policy_code),
  12.160 +        return -EINVAL;
  12.161 +    }
  12.162 +    if (acm_setup(initrdidx, mbi, initial_images_start) != ACM_OK)
  12.163 +    {
  12.164 +        printk("%s: Error loading policy at boot time.\n", __func__);
  12.165 +        /* ignore, just continue with the minimal hardcoded startup policy */
  12.166 +    }
  12.167 +    printk("%s: Enforcing Primary %s, Secondary %s.\n", __func__, 
  12.168 +           ACM_POLICY_NAME(acm_bin_pol.primary_policy_code),
  12.169             ACM_POLICY_NAME(acm_bin_pol.secondary_policy_code));
  12.170 -	return ret;
  12.171 +    return ret;
  12.172  }
  12.173  
  12.174  int
  12.175  acm_init_domain_ssid(domid_t id, ssidref_t ssidref)
  12.176  {
  12.177 -	struct acm_ssid_domain *ssid;
  12.178 -	struct domain *subj = find_domain_by_id(id);
  12.179 -	int ret1, ret2;
  12.180 -	
  12.181 -	if (subj == NULL)
  12.182 +    struct acm_ssid_domain *ssid;
  12.183 +    struct domain *subj = find_domain_by_id(id);
  12.184 +    int ret1, ret2;
  12.185 + 
  12.186 +    if (subj == NULL)
  12.187      {
  12.188 -		printk("%s: ACM_NULL_POINTER ERROR (id=%x).\n", __func__, id);
  12.189 -		return ACM_NULL_POINTER_ERROR;
  12.190 -	}
  12.191 -	if ((ssid = xmalloc(struct acm_ssid_domain)) == NULL)
  12.192 -		return ACM_INIT_SSID_ERROR;
  12.193 +        printk("%s: ACM_NULL_POINTER ERROR (id=%x).\n", __func__, id);
  12.194 +        return ACM_NULL_POINTER_ERROR;
  12.195 +    }
  12.196 +    if ((ssid = xmalloc(struct acm_ssid_domain)) == NULL)
  12.197 +        return ACM_INIT_SSID_ERROR;
  12.198  
  12.199 -	ssid->datatype       = DOMAIN;
  12.200 -	ssid->subject  	     = subj;
  12.201 -	ssid->domainid	     = subj->domain_id;
  12.202 -	ssid->primary_ssid   = NULL;
  12.203 -	ssid->secondary_ssid = NULL;
  12.204 +    ssid->datatype       = DOMAIN;
  12.205 +    ssid->subject        = subj;
  12.206 +    ssid->domainid      = subj->domain_id;
  12.207 +    ssid->primary_ssid   = NULL;
  12.208 +    ssid->secondary_ssid = NULL;
  12.209  
  12.210 -	if (ACM_USE_SECURITY_POLICY != ACM_NULL_POLICY)
  12.211 -		ssid->ssidref = ssidref;
  12.212 -	else
  12.213 -		ssid->ssidref = ACM_DEFAULT_SSID;
  12.214 +    if (ACM_USE_SECURITY_POLICY != ACM_NULL_POLICY)
  12.215 +        ssid->ssidref = ssidref;
  12.216 +    else
  12.217 +        ssid->ssidref = ACM_DEFAULT_SSID;
  12.218  
  12.219 -	subj->ssid           = ssid;
  12.220 -	/* now fill in primary and secondary parts; we only get here through hooks */
  12.221 -	if (acm_primary_ops->init_domain_ssid != NULL)
  12.222 -		ret1 = acm_primary_ops->init_domain_ssid(&(ssid->primary_ssid), ssidref);
  12.223 -	else
  12.224 -		ret1 = ACM_OK;
  12.225 +    subj->ssid           = ssid;
  12.226 +    /* now fill in primary and secondary parts; we only get here through hooks */
  12.227 +    if (acm_primary_ops->init_domain_ssid != NULL)
  12.228 +        ret1 = acm_primary_ops->init_domain_ssid(&(ssid->primary_ssid), ssidref);
  12.229 +    else
  12.230 +        ret1 = ACM_OK;
  12.231  
  12.232 -	if (acm_secondary_ops->init_domain_ssid != NULL)
  12.233 -		ret2 = acm_secondary_ops->init_domain_ssid(&(ssid->secondary_ssid), ssidref);
  12.234 -	else
  12.235 -		ret2 = ACM_OK;
  12.236 +    if (acm_secondary_ops->init_domain_ssid != NULL)
  12.237 +        ret2 = acm_secondary_ops->init_domain_ssid(&(ssid->secondary_ssid), ssidref);
  12.238 +    else
  12.239 +        ret2 = ACM_OK;
  12.240  
  12.241 -	if ((ret1 != ACM_OK) || (ret2 != ACM_OK))
  12.242 +    if ((ret1 != ACM_OK) || (ret2 != ACM_OK))
  12.243      {
  12.244 -		printk("%s: ERROR instantiating individual ssids for domain 0x%02x.\n",
  12.245 -		       __func__, subj->domain_id);
  12.246 -		acm_free_domain_ssid(ssid);	
  12.247 -	        put_domain(subj);
  12.248 -		return ACM_INIT_SSID_ERROR;
  12.249 -	}
  12.250 -	printk("%s: assigned domain %x the ssidref=%x.\n",
  12.251 +        printk("%s: ERROR instantiating individual ssids for domain 0x%02x.\n",
  12.252 +               __func__, subj->domain_id);
  12.253 +        acm_free_domain_ssid(ssid); 
  12.254 +        put_domain(subj);
  12.255 +        return ACM_INIT_SSID_ERROR;
  12.256 +    }
  12.257 +    printk("%s: assigned domain %x the ssidref=%x.\n",
  12.258             __func__, id, ssid->ssidref);
  12.259 -	put_domain(subj);
  12.260 -	return ACM_OK;
  12.261 +    put_domain(subj);
  12.262 +    return ACM_OK;
  12.263  }
  12.264  
  12.265  
  12.266 -int
  12.267 +void
  12.268  acm_free_domain_ssid(struct acm_ssid_domain *ssid)
  12.269  {
  12.270 -	domid_t id;
  12.271 -
  12.272 -	/* domain is already gone, just ssid is left */
  12.273 -	if (ssid == NULL)
  12.274 -    {
  12.275 -		printk("%s: ACM_NULL_POINTER ERROR.\n", __func__);
  12.276 -		return ACM_NULL_POINTER_ERROR;
  12.277 -	}
  12.278 -    id = ssid->domainid;
  12.279 -	ssid->subject  	     = NULL;
  12.280 +    /* domain is already gone, just ssid is left */
  12.281 +    if (ssid == NULL)
  12.282 +        return;
  12.283  
  12.284 -	if (acm_primary_ops->free_domain_ssid != NULL) /* null policy */
  12.285 -		acm_primary_ops->free_domain_ssid(ssid->primary_ssid);
  12.286 -	ssid->primary_ssid = NULL;
  12.287 -	if (acm_secondary_ops->free_domain_ssid != NULL)
  12.288 -		acm_secondary_ops->free_domain_ssid(ssid->secondary_ssid);
  12.289 -	ssid->secondary_ssid = NULL;
  12.290 -	xfree(ssid);
  12.291 -	printkd("%s: Freed individual domain ssid (domain=%02x).\n",
  12.292 +    ssid->subject = NULL;
  12.293 +    if (acm_primary_ops->free_domain_ssid != NULL) /* null policy */
  12.294 +        acm_primary_ops->free_domain_ssid(ssid->primary_ssid);
  12.295 +    ssid->primary_ssid = NULL;
  12.296 +    if (acm_secondary_ops->free_domain_ssid != NULL)
  12.297 +        acm_secondary_ops->free_domain_ssid(ssid->secondary_ssid);
  12.298 +    ssid->secondary_ssid = NULL;
  12.299 +    xfree(ssid);
  12.300 +    printkd("%s: Freed individual domain ssid (domain=%02x).\n",
  12.301              __func__, id);
  12.302 -	return ACM_OK;
  12.303  }
  12.304 +
  12.305 +/*
  12.306 + * Local variables:
  12.307 + * mode: C
  12.308 + * c-set-style: "BSD"
  12.309 + * c-basic-offset: 4
  12.310 + * tab-width: 4
  12.311 + * indent-tabs-mode: nil
  12.312 + * End:
  12.313 + */
    13.1 --- a/xen/acm/acm_null_hooks.c	Fri Oct 21 12:06:17 2005 +0100
    13.2 +++ b/xen/acm/acm_null_hooks.c	Fri Oct 21 12:07:14 2005 +0100
    13.3 @@ -11,37 +11,38 @@
    13.4   * published by the Free Software Foundation, version 2 of the
    13.5   * License.
    13.6   */
    13.7 +
    13.8  #include <acm/acm_hooks.h>
    13.9  
   13.10  static int
   13.11  null_init_domain_ssid(void **ssid, ssidref_t ssidref)
   13.12  {
   13.13 -	return ACM_OK;
   13.14 +    return ACM_OK;
   13.15  }
   13.16  
   13.17  static void
   13.18  null_free_domain_ssid(void *ssid)
   13.19  {
   13.20 -	return;
   13.21 +    return;
   13.22  }
   13.23  
   13.24  static int
   13.25 -null_dump_binary_policy(u8 *buf, u16 buf_size) 
   13.26 -{	
   13.27 -	return 0;
   13.28 +null_dump_binary_policy(u8 *buf, u32 buf_size)
   13.29 +{ 
   13.30 +    return 0;
   13.31  }
   13.32  
   13.33  static int
   13.34 -null_set_binary_policy(u8 *buf, u16 buf_size) 
   13.35 -{	
   13.36 -	return ACM_OK;
   13.37 +null_set_binary_policy(u8 *buf, u32 buf_size)
   13.38 +{ 
   13.39 +    return ACM_OK;
   13.40  }
   13.41 -	
   13.42 + 
   13.43  static int 
   13.44  null_dump_stats(u8 *buf, u16 buf_size)
   13.45  {
   13.46 -	/* no stats for NULL policy */
   13.47 -	return 0;
   13.48 +    /* no stats for NULL policy */
   13.49 +    return 0;
   13.50  }
   13.51  
   13.52  static int
   13.53 @@ -54,25 +55,35 @@ null_dump_ssid_types(ssidref_t ssidref, 
   13.54  
   13.55  /* now define the hook structure similarly to LSM */
   13.56  struct acm_operations acm_null_ops = {
   13.57 -	.init_domain_ssid		= null_init_domain_ssid,
   13.58 -	.free_domain_ssid		= null_free_domain_ssid,
   13.59 -	.dump_binary_policy           	= null_dump_binary_policy,
   13.60 -	.set_binary_policy		= null_set_binary_policy,
   13.61 -	.dump_statistics	        = null_dump_stats,
   13.62 -    .dump_ssid_types        = null_dump_ssid_types,
   13.63 -	/* domain management control hooks */
   13.64 -	.pre_domain_create     		= NULL,
   13.65 -	.post_domain_create		= NULL,
   13.66 -	.fail_domain_create		= NULL,
   13.67 -	.post_domain_destroy		= NULL,
   13.68 -	/* event channel control hooks */
   13.69 -	.pre_eventchannel_unbound      	= NULL,
   13.70 -	.fail_eventchannel_unbound	= NULL,
   13.71 -	.pre_eventchannel_interdomain	= NULL,
   13.72 -	.fail_eventchannel_interdomain	= NULL,
   13.73 -	/* grant table control hooks */
   13.74 -	.pre_grant_map_ref       	= NULL,
   13.75 -	.fail_grant_map_ref		= NULL,
   13.76 -	.pre_grant_setup	       	= NULL,
   13.77 -	.fail_grant_setup		= NULL
   13.78 +    .init_domain_ssid = null_init_domain_ssid,
   13.79 +    .free_domain_ssid = null_free_domain_ssid,
   13.80 +    .dump_binary_policy = null_dump_binary_policy,
   13.81 +    .set_binary_policy = null_set_binary_policy,
   13.82 +    .dump_statistics = null_dump_stats,
   13.83 +    .dump_ssid_types = null_dump_ssid_types,
   13.84 +    /* domain management control hooks */
   13.85 +    .pre_domain_create = NULL,
   13.86 +    .post_domain_create = NULL,
   13.87 +    .fail_domain_create = NULL,
   13.88 +    .post_domain_destroy = NULL,
   13.89 +    /* event channel control hooks */
   13.90 +    .pre_eventchannel_unbound = NULL,
   13.91 +    .fail_eventchannel_unbound = NULL,
   13.92 +    .pre_eventchannel_interdomain = NULL,
   13.93 +    .fail_eventchannel_interdomain = NULL,
   13.94 +    /* grant table control hooks */
   13.95 +    .pre_grant_map_ref = NULL,
   13.96 +    .fail_grant_map_ref = NULL,
   13.97 +    .pre_grant_setup = NULL,
   13.98 +    .fail_grant_setup = NULL
   13.99  };
  13.100 +
  13.101 +/*
  13.102 + * Local variables:
  13.103 + * mode: C
  13.104 + * c-set-style: "BSD"
  13.105 + * c-basic-offset: 4
  13.106 + * tab-width: 4
  13.107 + * indent-tabs-mode: nil
  13.108 + * End:
  13.109 + */
    14.1 --- a/xen/acm/acm_policy.c	Fri Oct 21 12:06:17 2005 +0100
    14.2 +++ b/xen/acm/acm_policy.c	Fri Oct 21 12:07:14 2005 +0100
    14.3 @@ -32,165 +32,166 @@
    14.4  #include <acm/acm_endian.h>
    14.5  
    14.6  int
    14.7 -acm_set_policy(void *buf, u16 buf_size, int isuserbuffer)
    14.8 +acm_set_policy(void *buf, u32 buf_size, int isuserbuffer)
    14.9  {
   14.10 -	u8 *policy_buffer = NULL;
   14.11 -	struct acm_policy_buffer *pol;
   14.12 -	
   14.13 +    u8 *policy_buffer = NULL;
   14.14 +    struct acm_policy_buffer *pol;
   14.15 + 
   14.16      if (buf_size < sizeof(struct acm_policy_buffer))
   14.17 -		return -EFAULT;
   14.18 +        return -EFAULT;
   14.19  
   14.20 -	/* 1. copy buffer from domain */
   14.21 -	if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
   14.22 -	    return -ENOMEM;
   14.23 +    /* 1. copy buffer from domain */
   14.24 +    if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
   14.25 +        return -ENOMEM;
   14.26  
   14.27 -	if (isuserbuffer) {
   14.28 -		if (copy_from_user(policy_buffer, buf, buf_size))
   14.29 +    if (isuserbuffer) {
   14.30 +        if (copy_from_user(policy_buffer, buf, buf_size))
   14.31          {
   14.32 -			printk("%s: Error copying!\n",__func__);
   14.33 -			goto error_free;
   14.34 -		}
   14.35 -	} else
   14.36 -		memcpy(policy_buffer, buf, buf_size);
   14.37 +            printk("%s: Error copying!\n",__func__);
   14.38 +            goto error_free;
   14.39 +        }
   14.40 +    } else
   14.41 +        memcpy(policy_buffer, buf, buf_size);
   14.42  
   14.43 -	/* 2. some sanity checking */
   14.44 -	pol = (struct acm_policy_buffer *)policy_buffer;
   14.45 +    /* 2. some sanity checking */
   14.46 +    pol = (struct acm_policy_buffer *)policy_buffer;
   14.47  
   14.48 -	if ((ntohl(pol->magic) != ACM_MAGIC) || 
   14.49 -	    (ntohl(pol->policy_version) != ACM_POLICY_VERSION) ||
   14.50 -	    (ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
   14.51 -	    (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code))
   14.52 +    if ((ntohl(pol->magic) != ACM_MAGIC) || 
   14.53 +        (ntohl(pol->policy_version) != ACM_POLICY_VERSION) ||
   14.54 +        (ntohl(pol->primary_policy_code) != acm_bin_pol.primary_policy_code) ||
   14.55 +        (ntohl(pol->secondary_policy_code) != acm_bin_pol.secondary_policy_code))
   14.56      {
   14.57 -		printkd("%s: Wrong policy magics or versions!\n", __func__);
   14.58 -		goto error_free;
   14.59 -	}
   14.60 -	if (buf_size != ntohl(pol->len))
   14.61 +        printkd("%s: Wrong policy magics or versions!\n", __func__);
   14.62 +        goto error_free;
   14.63 +    }
   14.64 +    if (buf_size != ntohl(pol->len))
   14.65      {
   14.66 -		printk("%s: ERROR in buf size.\n", __func__);
   14.67 -		goto error_free;
   14.68 -	}
   14.69 +        printk("%s: ERROR in buf size.\n", __func__);
   14.70 +        goto error_free;
   14.71 +    }
   14.72  
   14.73 -	/* get bin_policy lock and rewrite policy (release old one) */
   14.74 -	write_lock(&acm_bin_pol_rwlock);
   14.75 +    /* get bin_policy lock and rewrite policy (release old one) */
   14.76 +    write_lock(&acm_bin_pol_rwlock);
   14.77  
   14.78 -	/* 3. set primary policy data */
   14.79 -	if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset),
   14.80 -                                               ntohl(pol->secondary_buffer_offset) -
   14.81 -					       ntohl(pol->primary_buffer_offset)))
   14.82 -		goto error_lock_free;
   14.83 +    /* 3. set primary policy data */
   14.84 +    if (acm_primary_ops->set_binary_policy(buf + ntohl(pol->primary_buffer_offset),
   14.85 +                                           ntohl(pol->secondary_buffer_offset) -
   14.86 +                                           ntohl(pol->primary_buffer_offset)))
   14.87 +        goto error_lock_free;
   14.88  
   14.89 -	/* 4. set secondary policy data */
   14.90 -	if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset),
   14.91 -						 ntohl(pol->len) - 
   14.92 -						 ntohl(pol->secondary_buffer_offset)))
   14.93 -		goto error_lock_free;
   14.94 +    /* 4. set secondary policy data */
   14.95 +    if (acm_secondary_ops->set_binary_policy(buf + ntohl(pol->secondary_buffer_offset),
   14.96 +                                             ntohl(pol->len) - 
   14.97 +                                             ntohl(pol->secondary_buffer_offset)))
   14.98 +        goto error_lock_free;
   14.99  
  14.100 -	write_unlock(&acm_bin_pol_rwlock);
  14.101 -	xfree(policy_buffer);
  14.102 -	return ACM_OK;
  14.103 +    write_unlock(&acm_bin_pol_rwlock);
  14.104 +    xfree(policy_buffer);
  14.105 +    return ACM_OK;
  14.106  
  14.107   error_lock_free:
  14.108 -	write_unlock(&acm_bin_pol_rwlock);
  14.109 +    write_unlock(&acm_bin_pol_rwlock);
  14.110   error_free:
  14.111 -	printk("%s: Error setting policy.\n", __func__);
  14.112 +    printk("%s: Error setting policy.\n", __func__);
  14.113      xfree(policy_buffer);
  14.114 -	return -EFAULT;
  14.115 +    return -EFAULT;
  14.116  }
  14.117  
  14.118  int
  14.119 -acm_get_policy(void *buf, u16 buf_size)
  14.120 -{	
  14.121 -     u8 *policy_buffer;
  14.122 -     int ret;
  14.123 -     struct acm_policy_buffer *bin_pol;
  14.124 -	
  14.125 +acm_get_policy(void *buf, u32 buf_size)
  14.126 +{ 
  14.127 +    u8 *policy_buffer;
  14.128 +    int ret;
  14.129 +    struct acm_policy_buffer *bin_pol;
  14.130 + 
  14.131      if (buf_size < sizeof(struct acm_policy_buffer))
  14.132 -		return -EFAULT;
  14.133 +        return -EFAULT;
  14.134  
  14.135 -     if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
  14.136 -	    return -ENOMEM;
  14.137 +    if ((policy_buffer = xmalloc_array(u8, buf_size)) == NULL)
  14.138 +        return -ENOMEM;
  14.139  
  14.140 -     read_lock(&acm_bin_pol_rwlock);
  14.141 +    read_lock(&acm_bin_pol_rwlock);
  14.142  
  14.143 -     bin_pol = (struct acm_policy_buffer *)policy_buffer;
  14.144 -     bin_pol->magic = htonl(ACM_MAGIC);
  14.145 -     bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  14.146 -     bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  14.147 +    bin_pol = (struct acm_policy_buffer *)policy_buffer;
  14.148 +    bin_pol->magic = htonl(ACM_MAGIC);
  14.149 +    bin_pol->primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  14.150 +    bin_pol->secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  14.151  
  14.152 -     bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  14.153 -     bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
  14.154 -     bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  14.155 +    bin_pol->len = htonl(sizeof(struct acm_policy_buffer));
  14.156 +    bin_pol->primary_buffer_offset = htonl(ntohl(bin_pol->len));
  14.157 +    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  14.158       
  14.159 -     ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset),
  14.160 -				       buf_size - ntohl(bin_pol->primary_buffer_offset));
  14.161 -     if (ret < 0)
  14.162 -         goto error_free_unlock;
  14.163 +    ret = acm_primary_ops->dump_binary_policy (policy_buffer + ntohl(bin_pol->primary_buffer_offset),
  14.164 +                                               buf_size - ntohl(bin_pol->primary_buffer_offset));
  14.165 +    if (ret < 0)
  14.166 +        goto error_free_unlock;
  14.167  
  14.168 -     bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  14.169 -     bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  14.170 +    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  14.171 +    bin_pol->secondary_buffer_offset = htonl(ntohl(bin_pol->len));
  14.172  
  14.173 -     ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohl(bin_pol->secondary_buffer_offset),
  14.174 -				    buf_size - ntohl(bin_pol->secondary_buffer_offset));
  14.175 -     if (ret < 0)
  14.176 -         goto error_free_unlock;
  14.177 +    ret = acm_secondary_ops->dump_binary_policy(policy_buffer + ntohl(bin_pol->secondary_buffer_offset),
  14.178 +                                                buf_size - ntohl(bin_pol->secondary_buffer_offset));
  14.179 +    if (ret < 0)
  14.180 +        goto error_free_unlock;
  14.181  
  14.182 -     bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  14.183 -     if (copy_to_user(buf, policy_buffer, ntohl(bin_pol->len)))
  14.184 -	     goto error_free_unlock;
  14.185 +    bin_pol->len = htonl(ntohl(bin_pol->len) + ret);
  14.186 +    if (copy_to_user(buf, policy_buffer, ntohl(bin_pol->len)))
  14.187 +        goto error_free_unlock;
  14.188  
  14.189 -     read_unlock(&acm_bin_pol_rwlock);
  14.190 -     xfree(policy_buffer);
  14.191 -     return ACM_OK;
  14.192 +    read_unlock(&acm_bin_pol_rwlock);
  14.193 +    xfree(policy_buffer);
  14.194 +    return ACM_OK;
  14.195  
  14.196   error_free_unlock:
  14.197 -     read_unlock(&acm_bin_pol_rwlock);
  14.198 -     printk("%s: Error getting policy.\n", __func__);
  14.199 -     xfree(policy_buffer);
  14.200 -     return -EFAULT;
  14.201 +    read_unlock(&acm_bin_pol_rwlock);
  14.202 +    printk("%s: Error getting policy.\n", __func__);
  14.203 +    xfree(policy_buffer);
  14.204 +    return -EFAULT;
  14.205  }
  14.206  
  14.207  int
  14.208  acm_dump_statistics(void *buf, u16 buf_size)
  14.209 -{	
  14.210 +{ 
  14.211      /* send stats to user space */
  14.212 -     u8 *stats_buffer;
  14.213 -     int len1, len2;
  14.214 -     struct acm_stats_buffer acm_stats;
  14.215 +    u8 *stats_buffer;
  14.216 +    int len1, len2;
  14.217 +    struct acm_stats_buffer acm_stats;
  14.218  
  14.219 -     if ((stats_buffer = xmalloc_array(u8, buf_size)) == NULL)
  14.220 -	    return -ENOMEM;
  14.221 +    if ((stats_buffer = xmalloc_array(u8, buf_size)) == NULL)
  14.222 +        return -ENOMEM;
  14.223  
  14.224 -     read_lock(&acm_bin_pol_rwlock);
  14.225 +    read_lock(&acm_bin_pol_rwlock);
  14.226       
  14.227 -     len1 = acm_primary_ops->dump_statistics(stats_buffer + sizeof(struct acm_stats_buffer),
  14.228 -					     buf_size - sizeof(struct acm_stats_buffer));
  14.229 -     if (len1 < 0)
  14.230 -	     goto error_lock_free;
  14.231 -	     
  14.232 -     len2 = acm_secondary_ops->dump_statistics(stats_buffer + sizeof(struct acm_stats_buffer) + len1,
  14.233 -					       buf_size - sizeof(struct acm_stats_buffer) - len1);
  14.234 -     if (len2 < 0)
  14.235 -	     goto error_lock_free;
  14.236 +    len1 = acm_primary_ops->dump_statistics(stats_buffer + sizeof(struct acm_stats_buffer),
  14.237 +                                            buf_size - sizeof(struct acm_stats_buffer));
  14.238 +    if (len1 < 0)
  14.239 +        goto error_lock_free;
  14.240 +      
  14.241 +    len2 = acm_secondary_ops->dump_statistics(stats_buffer + sizeof(struct acm_stats_buffer) + len1,
  14.242 +                                              buf_size - sizeof(struct acm_stats_buffer) - len1);
  14.243 +    if (len2 < 0)
  14.244 +        goto error_lock_free;
  14.245  
  14.246 -     acm_stats.magic = htonl(ACM_MAGIC);
  14.247 -     acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  14.248 -     acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  14.249 -     acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer));
  14.250 -     acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + len1);
  14.251 -     acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2);
  14.252 -     memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer));
  14.253 +    acm_stats.magic = htonl(ACM_MAGIC);
  14.254 +    acm_stats.primary_policy_code = htonl(acm_bin_pol.primary_policy_code);
  14.255 +    acm_stats.secondary_policy_code = htonl(acm_bin_pol.secondary_policy_code);
  14.256 +    acm_stats.primary_stats_offset = htonl(sizeof(struct acm_stats_buffer));
  14.257 +    acm_stats.secondary_stats_offset = htonl(sizeof(struct acm_stats_buffer) + len1);
  14.258 +    acm_stats.len = htonl(sizeof(struct acm_stats_buffer) + len1 + len2);
  14.259  
  14.260 -     if (copy_to_user(buf, stats_buffer, sizeof(struct acm_stats_buffer) + len1 + len2))
  14.261 -	     goto error_lock_free;
  14.262 +    memcpy(stats_buffer, &acm_stats, sizeof(struct acm_stats_buffer));
  14.263  
  14.264 -     read_unlock(&acm_bin_pol_rwlock);
  14.265 -     xfree(stats_buffer);
  14.266 -     return ACM_OK;
  14.267 +    if (copy_to_user(buf, stats_buffer, sizeof(struct acm_stats_buffer) + len1 + len2))
  14.268 +        goto error_lock_free;
  14.269 +
  14.270 +    read_unlock(&acm_bin_pol_rwlock);
  14.271 +    xfree(stats_buffer);
  14.272 +    return ACM_OK;
  14.273  
  14.274   error_lock_free:
  14.275 -     read_unlock(&acm_bin_pol_rwlock);
  14.276 -     xfree(stats_buffer);
  14.277 -     return -EFAULT;
  14.278 +    read_unlock(&acm_bin_pol_rwlock);
  14.279 +    xfree(stats_buffer);
  14.280 +    return -EFAULT;
  14.281  }
  14.282  
  14.283  
  14.284 @@ -198,57 +199,88 @@ int
  14.285  acm_get_ssid(ssidref_t ssidref, u8 *buf, u16 buf_size)
  14.286  {
  14.287      /* send stats to user space */
  14.288 -     u8 *ssid_buffer;
  14.289 -     int ret;
  14.290 -     struct acm_ssid_buffer *acm_ssid;
  14.291 -     if (buf_size < sizeof(struct acm_ssid_buffer))
  14.292 -		return -EFAULT;
  14.293 +    u8 *ssid_buffer;
  14.294 +    int ret;
  14.295 +    struct acm_ssid_buffer *acm_ssid;
  14.296 +    if (buf_size < sizeof(struct acm_ssid_buffer))
  14.297 +        return -EFAULT;
  14.298  
  14.299 -     if ((ssid_buffer = xmalloc_array(u8, buf_size)) == NULL)
  14.300 -	    return -ENOMEM;
  14.301 +    if ((ssid_buffer = xmalloc_array(u8, buf_size)) == NULL)
  14.302 +        return -ENOMEM;
  14.303  
  14.304 -     read_lock(&acm_bin_pol_rwlock);
  14.305 +    read_lock(&acm_bin_pol_rwlock);
  14.306  
  14.307 -     acm_ssid = (struct acm_ssid_buffer *)ssid_buffer;
  14.308 -     acm_ssid->len = sizeof(struct acm_ssid_buffer);
  14.309 -     acm_ssid->ssidref = ssidref;
  14.310 -     acm_ssid->primary_policy_code = acm_bin_pol.primary_policy_code;
  14.311 -     acm_ssid->secondary_policy_code = acm_bin_pol.secondary_policy_code;
  14.312 -     acm_ssid->primary_types_offset = acm_ssid->len;
  14.313 +    acm_ssid = (struct acm_ssid_buffer *)ssid_buffer;
  14.314 +    acm_ssid->len = sizeof(struct acm_ssid_buffer);
  14.315 +    acm_ssid->ssidref = ssidref;
  14.316 +    acm_ssid->primary_policy_code = acm_bin_pol.primary_policy_code;
  14.317 +    acm_ssid->secondary_policy_code = acm_bin_pol.secondary_policy_code;
  14.318 +    acm_ssid->primary_types_offset = acm_ssid->len;
  14.319  
  14.320 -     /* ret >= 0 --> ret == max_types */
  14.321 -     ret = acm_primary_ops->dump_ssid_types(ACM_PRIMARY(ssidref),
  14.322 -                                            ssid_buffer + acm_ssid->primary_types_offset,
  14.323 -                                            buf_size - acm_ssid->primary_types_offset);
  14.324 -     if (ret < 0)
  14.325 -         goto error_free_unlock;
  14.326 +    /* ret >= 0 --> ret == max_types */
  14.327 +    ret = acm_primary_ops->dump_ssid_types(ACM_PRIMARY(ssidref),
  14.328 +                                           ssid_buffer + acm_ssid->primary_types_offset,
  14.329 +                                           buf_size - acm_ssid->primary_types_offset);
  14.330 +    if (ret < 0)
  14.331 +        goto error_free_unlock;
  14.332  
  14.333 -     acm_ssid->len += ret;
  14.334 -     acm_ssid->primary_max_types = ret;
  14.335 -
  14.336 -     acm_ssid->secondary_types_offset = acm_ssid->len;
  14.337 +    acm_ssid->len += ret;
  14.338 +    acm_ssid->primary_max_types = ret;
  14.339 +    acm_ssid->secondary_types_offset = acm_ssid->len;
  14.340  
  14.341 -     ret = acm_secondary_ops->dump_ssid_types(ACM_SECONDARY(ssidref),
  14.342 -                                              ssid_buffer + acm_ssid->secondary_types_offset,
  14.343 -                                              buf_size - acm_ssid->secondary_types_offset);
  14.344 -     if (ret < 0)
  14.345 -         goto error_free_unlock;
  14.346 +    ret = acm_secondary_ops->dump_ssid_types(ACM_SECONDARY(ssidref),
  14.347 +                                             ssid_buffer + acm_ssid->secondary_types_offset,
  14.348 +                                             buf_size - acm_ssid->secondary_types_offset);
  14.349 +    if (ret < 0)
  14.350 +        goto error_free_unlock;
  14.351  
  14.352 -     acm_ssid->len += ret;
  14.353 -     acm_ssid->secondary_max_types = ret;
  14.354 +    acm_ssid->len += ret;
  14.355 +    acm_ssid->secondary_max_types = ret;
  14.356  
  14.357 -     if (copy_to_user(buf, ssid_buffer, acm_ssid->len))
  14.358 -	     goto error_free_unlock;
  14.359 +    if (copy_to_user(buf, ssid_buffer, acm_ssid->len))
  14.360 +        goto error_free_unlock;
  14.361  
  14.362 -     read_unlock(&acm_bin_pol_rwlock);
  14.363 -     xfree(ssid_buffer);
  14.364 -     return ACM_OK;
  14.365 +    read_unlock(&acm_bin_pol_rwlock);
  14.366 +    xfree(ssid_buffer);
  14.367 +    return ACM_OK;
  14.368  
  14.369   error_free_unlock:
  14.370 -     read_unlock(&acm_bin_pol_rwlock);
  14.371 -     printk("%s: Error getting ssid.\n", __func__);
  14.372 -     xfree(ssid_buffer);
  14.373 -     return -ENOMEM;
  14.374 +    read_unlock(&acm_bin_pol_rwlock);
  14.375 +    printk("%s: Error getting ssid.\n", __func__);
  14.376 +    xfree(ssid_buffer);
  14.377 +    return -ENOMEM;
  14.378  }
  14.379  
  14.380 -/*eof*/
  14.381 +int
  14.382 +acm_get_decision(ssidref_t ssidref1, ssidref_t ssidref2,
  14.383 +                 enum acm_hook_type hook)
  14.384 +{
  14.385 +    int ret = ACM_ACCESS_DENIED;
  14.386 +    switch (hook) {
  14.387 +
  14.388 +    case SHARING:
  14.389 +        /* SHARING Hook restricts access in STE policy only */
  14.390 +        ret = acm_sharing(ssidref1, ssidref2);
  14.391 +        break;
  14.392 +
  14.393 +    default:
  14.394 +        /* deny */
  14.395 +        break;
  14.396 +    }
  14.397 +
  14.398 +    printkd("%s: ssid1=%x, ssid2=%x, decision=%s.\n",
  14.399 +            __func__, ssidref1, ssidref2,
  14.400 +            (ret == ACM_ACCESS_PERMITTED) ? "GRANTED" : "DENIED");
  14.401 +
  14.402 +    return ret;
  14.403 +}
  14.404 +
  14.405 +/*
  14.406 + * Local variables:
  14.407 + * mode: C
  14.408 + * c-set-style: "BSD"
  14.409 + * c-basic-offset: 4
  14.410 + * tab-width: 4
  14.411 + * indent-tabs-mode: nil
  14.412 + * End:
  14.413 + */
    15.1 --- a/xen/acm/acm_simple_type_enforcement_hooks.c	Fri Oct 21 12:06:17 2005 +0100
    15.2 +++ b/xen/acm/acm_simple_type_enforcement_hooks.c	Fri Oct 21 12:07:14 2005 +0100
    15.3 @@ -24,6 +24,7 @@
    15.4   *     share at least on common type.
    15.5   *
    15.6   */
    15.7 +
    15.8  #include <xen/lib.h>
    15.9  #include <asm/types.h>
   15.10  #include <asm/current.h>
   15.11 @@ -35,34 +36,34 @@
   15.12  struct ste_binary_policy ste_bin_pol;
   15.13  
   15.14  static inline int have_common_type (ssidref_t ref1, ssidref_t ref2) {
   15.15 -	int i;
   15.16 -	for(i=0; i< ste_bin_pol.max_types; i++)
   15.17 -		if ( ste_bin_pol.ssidrefs[ref1*ste_bin_pol.max_types + i] && 
   15.18 -		     ste_bin_pol.ssidrefs[ref2*ste_bin_pol.max_types + i]) {
   15.19 -			printkd("%s: common type #%02x.\n", __func__, i);
   15.20 -			return 1;
   15.21 -		}
   15.22 -	return 0;
   15.23 +    int i;
   15.24 +    for(i=0; i< ste_bin_pol.max_types; i++)
   15.25 +        if ( ste_bin_pol.ssidrefs[ref1*ste_bin_pol.max_types + i] && 
   15.26 +             ste_bin_pol.ssidrefs[ref2*ste_bin_pol.max_types + i]) {
   15.27 +            printkd("%s: common type #%02x.\n", __func__, i);
   15.28 +            return 1;
   15.29 +        }
   15.30 +    return 0;
   15.31  }
   15.32  
   15.33  /* Helper function: return = (subj and obj share a common type) */
   15.34  static int share_common_type(struct domain *subj, struct domain *obj)
   15.35  {
   15.36 -	ssidref_t ref_s, ref_o;
   15.37 -	int ret;
   15.38 +    ssidref_t ref_s, ref_o;
   15.39 +    int ret;
   15.40  
   15.41 -	if ((subj == NULL) || (obj == NULL) || (subj->ssid == NULL) || (obj->ssid == NULL))
   15.42 -		return 0;
   15.43 -	read_lock(&acm_bin_pol_rwlock);
   15.44 -	/* lookup the policy-local ssids */
   15.45 -	ref_s = ((struct ste_ssid *)(GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   15.46 -				    (struct acm_ssid_domain *)subj->ssid)))->ste_ssidref;
   15.47 -	ref_o = ((struct ste_ssid *)(GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   15.48 -				    (struct acm_ssid_domain *)obj->ssid)))->ste_ssidref;
   15.49 -        /* check whether subj and obj share a common ste type */
   15.50 -	ret = have_common_type(ref_s, ref_o);
   15.51 -	read_unlock(&acm_bin_pol_rwlock);
   15.52 -	return ret;
   15.53 +    if ((subj == NULL) || (obj == NULL) || (subj->ssid == NULL) || (obj->ssid == NULL))
   15.54 +        return 0;
   15.55 +    read_lock(&acm_bin_pol_rwlock);
   15.56 +    /* lookup the policy-local ssids */
   15.57 +    ref_s = ((struct ste_ssid *)(GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   15.58 +                                           (struct acm_ssid_domain *)subj->ssid)))->ste_ssidref;
   15.59 +    ref_o = ((struct ste_ssid *)(GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
   15.60 +                                           (struct acm_ssid_domain *)obj->ssid)))->ste_ssidref;
   15.61 +    /* check whether subj and obj share a common ste type */
   15.62 +    ret = have_common_type(ref_s, ref_o);
   15.63 +    read_unlock(&acm_bin_pol_rwlock);
   15.64 +    return ret;
   15.65  }
   15.66  
   15.67  /*
   15.68 @@ -71,26 +72,26 @@ static int share_common_type(struct doma
   15.69   */
   15.70  int acm_init_ste_policy(void)
   15.71  {
   15.72 -	/* minimal startup policy; policy write-locked already */
   15.73 -	ste_bin_pol.max_types = 1;
   15.74 -	ste_bin_pol.max_ssidrefs = 2;
   15.75 -	ste_bin_pol.ssidrefs = (domaintype_t *)xmalloc_array(domaintype_t, 2);
   15.76 -	memset(ste_bin_pol.ssidrefs, 0, 2);
   15.77 +    /* minimal startup policy; policy write-locked already */
   15.78 +    ste_bin_pol.max_types = 1;
   15.79 +    ste_bin_pol.max_ssidrefs = 2;
   15.80 +    ste_bin_pol.ssidrefs = (domaintype_t *)xmalloc_array(domaintype_t, 2);
   15.81 +    memset(ste_bin_pol.ssidrefs, 0, 2);
   15.82  
   15.83 -	if (ste_bin_pol.ssidrefs == NULL)
   15.84 -		return ACM_INIT_SSID_ERROR;
   15.85 +    if (ste_bin_pol.ssidrefs == NULL)
   15.86 +        return ACM_INIT_SSID_ERROR;
   15.87  
   15.88 -	/* initialize state so that dom0 can start up and communicate with itself */
   15.89 -	ste_bin_pol.ssidrefs[1] = 1;
   15.90 + /* initialize state so that dom0 can start up and communicate with itself */
   15.91 +    ste_bin_pol.ssidrefs[1] = 1;
   15.92  
   15.93 -	/* init stats */
   15.94 -	atomic_set(&(ste_bin_pol.ec_eval_count), 0);
   15.95 -	atomic_set(&(ste_bin_pol.ec_denied_count), 0); 
   15.96 -	atomic_set(&(ste_bin_pol.ec_cachehit_count), 0);
   15.97 -	atomic_set(&(ste_bin_pol.gt_eval_count), 0);
   15.98 -	atomic_set(&(ste_bin_pol.gt_denied_count), 0); 
   15.99 -	atomic_set(&(ste_bin_pol.gt_cachehit_count), 0);
  15.100 -	return ACM_OK;
  15.101 +    /* init stats */
  15.102 +    atomic_set(&(ste_bin_pol.ec_eval_count), 0);
  15.103 +    atomic_set(&(ste_bin_pol.ec_denied_count), 0); 
  15.104 +    atomic_set(&(ste_bin_pol.ec_cachehit_count), 0);
  15.105 +    atomic_set(&(ste_bin_pol.gt_eval_count), 0);
  15.106 +    atomic_set(&(ste_bin_pol.gt_denied_count), 0); 
  15.107 +    atomic_set(&(ste_bin_pol.gt_cachehit_count), 0);
  15.108 +    return ACM_OK;
  15.109  }
  15.110  
  15.111  
  15.112 @@ -98,62 +99,68 @@ int acm_init_ste_policy(void)
  15.113  static int
  15.114  ste_init_domain_ssid(void **ste_ssid, ssidref_t ssidref)
  15.115  {
  15.116 -	int i;
  15.117 -	struct ste_ssid *ste_ssidp = xmalloc(struct ste_ssid); 
  15.118 -	traceprintk("%s.\n", __func__);
  15.119 +    int i;
  15.120 +    struct ste_ssid *ste_ssidp = xmalloc(struct ste_ssid); 
  15.121 +    traceprintk("%s.\n", __func__);
  15.122  
  15.123 -	if (ste_ssidp == NULL)
  15.124 -		return ACM_INIT_SSID_ERROR;
  15.125 +    if (ste_ssidp == NULL)
  15.126 +        return ACM_INIT_SSID_ERROR;
  15.127  
  15.128 -	/* get policy-local ssid reference */
  15.129 -	ste_ssidp->ste_ssidref = GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref);
  15.130 -	if ((ste_ssidp->ste_ssidref >= ste_bin_pol.max_ssidrefs) ||
  15.131 -	    (ste_ssidp->ste_ssidref == ACM_DEFAULT_LOCAL_SSID))	{
  15.132 -		printkd("%s: ERROR ste_ssidref (%x) undefined or unset (0).\n",
  15.133 -			__func__, ste_ssidp->ste_ssidref);
  15.134 -		xfree(ste_ssidp);
  15.135 -		return ACM_INIT_SSID_ERROR;
  15.136 -	}
  15.137 -	/* clean ste cache */
  15.138 -	for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.139 -		ste_ssidp->ste_cache[i].valid = FREE;
  15.140 +    /* get policy-local ssid reference */
  15.141 +    ste_ssidp->ste_ssidref = GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref);
  15.142 +    if ((ste_ssidp->ste_ssidref >= ste_bin_pol.max_ssidrefs) ||
  15.143 +        (ste_ssidp->ste_ssidref == ACM_DEFAULT_LOCAL_SSID)) {
  15.144 +        printkd("%s: ERROR ste_ssidref (%x) undefined or unset (0).\n",
  15.145 +                __func__, ste_ssidp->ste_ssidref);
  15.146 +        xfree(ste_ssidp);
  15.147 +        return ACM_INIT_SSID_ERROR;
  15.148 +    }
  15.149 +    /* clean ste cache */
  15.150 +    for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.151 +        ste_ssidp->ste_cache[i].valid = FREE;
  15.152  
  15.153 -	(*ste_ssid) = ste_ssidp;
  15.154 -	printkd("%s: determined ste_ssidref to %x.\n", 
  15.155 -	       __func__, ste_ssidp->ste_ssidref);
  15.156 -	return ACM_OK;
  15.157 +    (*ste_ssid) = ste_ssidp;
  15.158 +    printkd("%s: determined ste_ssidref to %x.\n", 
  15.159 +            __func__, ste_ssidp->ste_ssidref);
  15.160 +    return ACM_OK;
  15.161  }
  15.162  
  15.163  
  15.164  static void
  15.165  ste_free_domain_ssid(void *ste_ssid)
  15.166  {
  15.167 -	traceprintk("%s.\n", __func__);
  15.168 -	if (ste_ssid != NULL)
  15.169 -		xfree(ste_ssid);
  15.170 -	return;
  15.171 +    traceprintk("%s.\n", __func__);
  15.172 +    if (ste_ssid != NULL)
  15.173 +        xfree(ste_ssid);
  15.174 +    return;
  15.175  }
  15.176  
  15.177  /* dump type enforcement cache; policy read-locked already */
  15.178  static int 
  15.179 -ste_dump_policy(u8 *buf, u16 buf_size) {
  15.180 -     struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf;
  15.181 -     int ret = 0;
  15.182 +ste_dump_policy(u8 *buf, u32 buf_size) {
  15.183 +    struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf;
  15.184 +    int ret = 0;
  15.185 +
  15.186 +    if (buf_size < sizeof(struct acm_ste_policy_buffer))
  15.187 +        return -EINVAL;
  15.188  
  15.189 -     ste_buf->ste_max_types = htonl(ste_bin_pol.max_types);
  15.190 -     ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs);
  15.191 -     ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  15.192 -     ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer));
  15.193 -     ret = ntohl(ste_buf->ste_ssid_offset) +
  15.194 -	     sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types;
  15.195 +    ste_buf->ste_max_types = htonl(ste_bin_pol.max_types);
  15.196 +    ste_buf->ste_max_ssidrefs = htonl(ste_bin_pol.max_ssidrefs);
  15.197 +    ste_buf->policy_code = htonl(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY);
  15.198 +    ste_buf->ste_ssid_offset = htonl(sizeof(struct acm_ste_policy_buffer));
  15.199 +    ret = ntohl(ste_buf->ste_ssid_offset) +
  15.200 +        sizeof(domaintype_t)*ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types;
  15.201  
  15.202 -     /* now copy buffer over */
  15.203 -     arrcpy(buf + ntohl(ste_buf->ste_ssid_offset),
  15.204 -	    ste_bin_pol.ssidrefs,
  15.205 -	    sizeof(domaintype_t),
  15.206 -             ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types);
  15.207 +    if (buf_size < ret)
  15.208 +        return -EINVAL;
  15.209  
  15.210 -     return ret;
  15.211 +    /* now copy buffer over */
  15.212 +    arrcpy(buf + ntohl(ste_buf->ste_ssid_offset),
  15.213 +           ste_bin_pol.ssidrefs,
  15.214 +           sizeof(domaintype_t),
  15.215 +           ste_bin_pol.max_ssidrefs*ste_bin_pol.max_types);
  15.216 +
  15.217 +    return ret;
  15.218  }
  15.219  
  15.220  /* ste_init_state is called when a policy is changed to detect violations (return != 0).
  15.221 @@ -176,83 +183,83 @@ ste_init_state(struct acm_ste_policy_buf
  15.222      /* go through all domains and adjust policy as if this domain was started now */
  15.223      pd = &domain_list;
  15.224      for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
  15.225 -	    ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.226 -				 (struct acm_ssid_domain *)(*pd)->ssid);
  15.227 -	    ste_ssidref = ste_ssid->ste_ssidref;
  15.228 -	    traceprintk("%s: validating policy for eventch domain %x (ste-Ref=%x).\n",
  15.229 -		    __func__, (*pd)->domain_id, ste_ssidref);
  15.230 -	    /* a) check for event channel conflicts */
  15.231 -	    for (port=0; port < NR_EVTCHN_BUCKETS; port++) {
  15.232 -		    spin_lock(&(*pd)->evtchn_lock);
  15.233 -		    if ((*pd)->evtchn[port] == NULL) {
  15.234 -                            spin_unlock(&(*pd)->evtchn_lock);
  15.235 -		            continue;
  15.236 -		    }
  15.237 -		    if ((*pd)->evtchn[port]->state == ECS_INTERDOMAIN) {
  15.238 -			    rdom = (*pd)->evtchn[port]->u.interdomain.remote_dom;
  15.239 -			    rdomid = rdom->domain_id;
  15.240 -			    /* rdom now has remote domain */
  15.241 -			    ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.242 -						  (struct acm_ssid_domain *)(rdom->ssid));
  15.243 -			    ste_rssidref = ste_rssid->ste_ssidref;
  15.244 -		    } else if ((*pd)->evtchn[port]->state == ECS_UNBOUND) {
  15.245 -			    rdomid = (*pd)->evtchn[port]->u.unbound.remote_domid;
  15.246 -			    if ((rdom = find_domain_by_id(rdomid)) == NULL) {
  15.247 -				    printk("%s: Error finding domain to id %x!\n", __func__, rdomid);
  15.248 -				    goto out;
  15.249 -			    }
  15.250 -			    /* rdom now has remote domain */
  15.251 -			    ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.252 -						  (struct acm_ssid_domain *)(rdom->ssid));
  15.253 -			    ste_rssidref = ste_rssid->ste_ssidref;
  15.254 -			    put_domain(rdom);
  15.255 -		    } else {
  15.256 -			    spin_unlock(&(*pd)->evtchn_lock);
  15.257 -			    continue; /* port unused */
  15.258 -		    }
  15.259 -		    spin_unlock(&(*pd)->evtchn_lock);
  15.260 +        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.261 +                             (struct acm_ssid_domain *)(*pd)->ssid);
  15.262 +        ste_ssidref = ste_ssid->ste_ssidref;
  15.263 +        traceprintk("%s: validating policy for eventch domain %x (ste-Ref=%x).\n",
  15.264 +                    __func__, (*pd)->domain_id, ste_ssidref);
  15.265 +        /* a) check for event channel conflicts */
  15.266 +        for (port=0; port < NR_EVTCHN_BUCKETS; port++) {
  15.267 +            spin_lock(&(*pd)->evtchn_lock);
  15.268 +            if ((*pd)->evtchn[port] == NULL) {
  15.269 +                spin_unlock(&(*pd)->evtchn_lock);
  15.270 +                continue;
  15.271 +            }
  15.272 +            if ((*pd)->evtchn[port]->state == ECS_INTERDOMAIN) {
  15.273 +                rdom = (*pd)->evtchn[port]->u.interdomain.remote_dom;
  15.274 +                rdomid = rdom->domain_id;
  15.275 +                /* rdom now has remote domain */
  15.276 +                ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.277 +                                      (struct acm_ssid_domain *)(rdom->ssid));
  15.278 +                ste_rssidref = ste_rssid->ste_ssidref;
  15.279 +            } else if ((*pd)->evtchn[port]->state == ECS_UNBOUND) {
  15.280 +                rdomid = (*pd)->evtchn[port]->u.unbound.remote_domid;
  15.281 +                if ((rdom = find_domain_by_id(rdomid)) == NULL) {
  15.282 +                    printk("%s: Error finding domain to id %x!\n", __func__, rdomid);
  15.283 +                    goto out;
  15.284 +                }
  15.285 +                /* rdom now has remote domain */
  15.286 +                ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.287 +                                      (struct acm_ssid_domain *)(rdom->ssid));
  15.288 +                ste_rssidref = ste_rssid->ste_ssidref;
  15.289 +                put_domain(rdom);
  15.290 +            } else {
  15.291 +                spin_unlock(&(*pd)->evtchn_lock);
  15.292 +                continue; /* port unused */
  15.293 +            }
  15.294 +            spin_unlock(&(*pd)->evtchn_lock);
  15.295  
  15.296 -		    /* rdom now has remote domain */
  15.297 -		    ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.298 -					     (struct acm_ssid_domain *)(rdom->ssid));
  15.299 -		    ste_rssidref = ste_rssid->ste_ssidref;
  15.300 -		    traceprintk("%s: eventch: domain %x (ssidref %x) --> domain %x (rssidref %x) used (port %x).\n", 
  15.301 -			    __func__, (*pd)->domain_id, ste_ssidref, rdom->domain_id, ste_rssidref, port);  
  15.302 -		    /* check whether on subj->ssid, obj->ssid share a common type*/
  15.303 -		    if (!have_common_type(ste_ssidref, ste_rssidref)) {
  15.304 -			    printkd("%s: Policy violation in event channel domain %x -> domain %x.\n",
  15.305 -				    __func__, (*pd)->domain_id, rdomid);
  15.306 -			    goto out;
  15.307 -		    }
  15.308 -	    }	
  15.309 -	    /* b) check for grant table conflicts on shared pages */
  15.310 -	    if ((*pd)->grant_table->shared == NULL) {
  15.311 -		    printkd("%s: Grant ... sharing for domain %x not setup!\n", __func__, (*pd)->domain_id);
  15.312 -		    continue;
  15.313 -	    }
  15.314 -	    for ( i = 0; i < NR_GRANT_ENTRIES; i++ ) {
  15.315 -		    sha_copy =  (*pd)->grant_table->shared[i];
  15.316 -		    if ( sha_copy.flags ) {
  15.317 -			    printkd("%s: grant dom (%hu) SHARED (%d) flags:(%hx) dom:(%hu) frame:(%lx)\n",
  15.318 -				    __func__, (*pd)->domain_id, i, sha_copy.flags, sha_copy.domid, 
  15.319 -				    (unsigned long)sha_copy.frame);
  15.320 -			    rdomid = sha_copy.domid;
  15.321 -			    if ((rdom = find_domain_by_id(rdomid)) == NULL) {
  15.322 -			    	    printkd("%s: domain not found ERROR!\n", __func__);
  15.323 -			    	    goto out;
  15.324 -			    };
  15.325 -			    /* rdom now has remote domain */
  15.326 -			    ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.327 -			    			  (struct acm_ssid_domain *)(rdom->ssid));
  15.328 -			    ste_rssidref = ste_rssid->ste_ssidref;
  15.329 -			    put_domain(rdom);
  15.330 -			    if (!have_common_type(ste_ssidref, ste_rssidref)) {
  15.331 -			    	    printkd("%s: Policy violation in grant table sharing domain %x -> domain %x.\n",
  15.332 -			    		    __func__, (*pd)->domain_id, rdomid);
  15.333 -			    	    goto out;
  15.334 -			    }
  15.335 -		    }
  15.336 -	    }
  15.337 +            /* rdom now has remote domain */
  15.338 +            ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.339 +                                  (struct acm_ssid_domain *)(rdom->ssid));
  15.340 +            ste_rssidref = ste_rssid->ste_ssidref;
  15.341 +            traceprintk("%s: eventch: domain %x (ssidref %x) --> domain %x (rssidref %x) used (port %x).\n", 
  15.342 +                        __func__, (*pd)->domain_id, ste_ssidref, rdom->domain_id, ste_rssidref, port);  
  15.343 +            /* check whether on subj->ssid, obj->ssid share a common type*/
  15.344 +            if (!have_common_type(ste_ssidref, ste_rssidref)) {
  15.345 +                printkd("%s: Policy violation in event channel domain %x -> domain %x.\n",
  15.346 +                        __func__, (*pd)->domain_id, rdomid);
  15.347 +                goto out;
  15.348 +            }
  15.349 +        } 
  15.350 +        /* b) check for grant table conflicts on shared pages */
  15.351 +        if ((*pd)->grant_table->shared == NULL) {
  15.352 +            printkd("%s: Grant ... sharing for domain %x not setup!\n", __func__, (*pd)->domain_id);
  15.353 +            continue;
  15.354 +        }
  15.355 +        for ( i = 0; i < NR_GRANT_ENTRIES; i++ ) {
  15.356 +            sha_copy =  (*pd)->grant_table->shared[i];
  15.357 +            if ( sha_copy.flags ) {
  15.358 +                printkd("%s: grant dom (%hu) SHARED (%d) flags:(%hx) dom:(%hu) frame:(%lx)\n",
  15.359 +                        __func__, (*pd)->domain_id, i, sha_copy.flags, sha_copy.domid, 
  15.360 +                        (unsigned long)sha_copy.frame);
  15.361 +                rdomid = sha_copy.domid;
  15.362 +                if ((rdom = find_domain_by_id(rdomid)) == NULL) {
  15.363 +                    printkd("%s: domain not found ERROR!\n", __func__);
  15.364 +                    goto out;
  15.365 +                };
  15.366 +                /* rdom now has remote domain */
  15.367 +                ste_rssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.368 +                                      (struct acm_ssid_domain *)(rdom->ssid));
  15.369 +                ste_rssidref = ste_rssid->ste_ssidref;
  15.370 +                put_domain(rdom);
  15.371 +                if (!have_common_type(ste_ssidref, ste_rssidref)) {
  15.372 +                    printkd("%s: Policy violation in grant table sharing domain %x -> domain %x.\n",
  15.373 +                            __func__, (*pd)->domain_id, rdomid);
  15.374 +                    goto out;
  15.375 +                }
  15.376 +            }
  15.377 +        }
  15.378      }
  15.379      violation = 0;
  15.380   out:
  15.381 @@ -267,69 +274,72 @@ ste_init_state(struct acm_ste_policy_buf
  15.382  
  15.383  /* set new policy; policy write-locked already */
  15.384  static int
  15.385 -ste_set_policy(u8 *buf, u16 buf_size) 
  15.386 +ste_set_policy(u8 *buf, u32 buf_size)
  15.387  {
  15.388 -     struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf;
  15.389 -     void *ssidrefsbuf;
  15.390 -     struct ste_ssid *ste_ssid;
  15.391 -     struct domain **pd;
  15.392 -     int i;
  15.393 +    struct acm_ste_policy_buffer *ste_buf = (struct acm_ste_policy_buffer *)buf;
  15.394 +    void *ssidrefsbuf;
  15.395 +    struct ste_ssid *ste_ssid;
  15.396 +    struct domain **pd;
  15.397 +    int i;
  15.398 +
  15.399 +    if (buf_size < sizeof(struct acm_ste_policy_buffer))
  15.400 +        return -EINVAL;
  15.401  
  15.402 -     /* Convert endianess of policy */
  15.403 -     ste_buf->policy_code = ntohl(ste_buf->policy_code);
  15.404 -     ste_buf->policy_version = ntohl(ste_buf->policy_version);
  15.405 -     ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types);
  15.406 -     ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs);
  15.407 -     ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset);
  15.408 +    /* Convert endianess of policy */
  15.409 +    ste_buf->policy_code = ntohl(ste_buf->policy_code);
  15.410 +    ste_buf->policy_version = ntohl(ste_buf->policy_version);
  15.411 +    ste_buf->ste_max_types = ntohl(ste_buf->ste_max_types);
  15.412 +    ste_buf->ste_max_ssidrefs = ntohl(ste_buf->ste_max_ssidrefs);
  15.413 +    ste_buf->ste_ssid_offset = ntohl(ste_buf->ste_ssid_offset);
  15.414  
  15.415 -     /* policy type and version checks */
  15.416 -     if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) ||
  15.417 -	 (ste_buf->policy_version != ACM_STE_VERSION))
  15.418 -	     return -EINVAL;
  15.419 +    /* policy type and version checks */
  15.420 +    if ((ste_buf->policy_code != ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY) ||
  15.421 +        (ste_buf->policy_version != ACM_STE_VERSION))
  15.422 +        return -EINVAL;
  15.423  
  15.424 -     /* 1. create and copy-in new ssidrefs buffer */
  15.425 -     ssidrefsbuf = xmalloc_array(u8, sizeof(domaintype_t)*ste_buf->ste_max_types*ste_buf->ste_max_ssidrefs);
  15.426 -     if (ssidrefsbuf == NULL) {
  15.427 -	     return -ENOMEM;
  15.428 -     }
  15.429 -     if (ste_buf->ste_ssid_offset + sizeof(domaintype_t) * ste_buf->ste_max_ssidrefs*ste_buf->ste_max_types > buf_size)
  15.430 -         goto error_free;
  15.431 +    /* 1. create and copy-in new ssidrefs buffer */
  15.432 +    ssidrefsbuf = xmalloc_array(u8, sizeof(domaintype_t)*ste_buf->ste_max_types*ste_buf->ste_max_ssidrefs);
  15.433 +    if (ssidrefsbuf == NULL) {
  15.434 +        return -ENOMEM;
  15.435 +    }
  15.436 +    if (ste_buf->ste_ssid_offset + sizeof(domaintype_t) * ste_buf->ste_max_ssidrefs*ste_buf->ste_max_types > buf_size)
  15.437 +        goto error_free;
  15.438  
  15.439 -     arrcpy(ssidrefsbuf, 
  15.440 -            buf + ste_buf->ste_ssid_offset,
  15.441 -            sizeof(domaintype_t),
  15.442 -	    ste_buf->ste_max_ssidrefs*ste_buf->ste_max_types);
  15.443 +    arrcpy(ssidrefsbuf, 
  15.444 +           buf + ste_buf->ste_ssid_offset,
  15.445 +           sizeof(domaintype_t),
  15.446 +           ste_buf->ste_max_ssidrefs*ste_buf->ste_max_types);
  15.447  
  15.448 -     /* 2. now re-calculate sharing decisions based on running domains; 
  15.449 -      *    this can fail if new policy is conflicting with sharing of running domains 
  15.450 -      *    now: reject violating new policy; future: adjust sharing through revoking sharing */
  15.451 -     if (ste_init_state(ste_buf, (domaintype_t *)ssidrefsbuf)) {
  15.452 -	     printk("%s: New policy conflicts with running domains. Policy load aborted.\n", __func__);
  15.453 -	     goto error_free; /* new policy conflicts with sharing of running domains */
  15.454 -     }
  15.455 -     /* 3. replace old policy (activate new policy) */
  15.456 -     ste_bin_pol.max_types = ste_buf->ste_max_types;
  15.457 -     ste_bin_pol.max_ssidrefs = ste_buf->ste_max_ssidrefs;
  15.458 -     if (ste_bin_pol.ssidrefs) 
  15.459 -	     xfree(ste_bin_pol.ssidrefs);
  15.460 -     ste_bin_pol.ssidrefs = (domaintype_t *)ssidrefsbuf;
  15.461 +    /* 2. now re-calculate sharing decisions based on running domains; 
  15.462 +     *    this can fail if new policy is conflicting with sharing of running domains 
  15.463 +     *    now: reject violating new policy; future: adjust sharing through revoking sharing */
  15.464 +    if (ste_init_state(ste_buf, (domaintype_t *)ssidrefsbuf)) {
  15.465 +        printk("%s: New policy conflicts with running domains. Policy load aborted.\n", __func__);
  15.466 +        goto error_free; /* new policy conflicts with sharing of running domains */
  15.467 +    }
  15.468 +    /* 3. replace old policy (activate new policy) */
  15.469 +    ste_bin_pol.max_types = ste_buf->ste_max_types;
  15.470 +    ste_bin_pol.max_ssidrefs = ste_buf->ste_max_ssidrefs;
  15.471 +    if (ste_bin_pol.ssidrefs) 
  15.472 +        xfree(ste_bin_pol.ssidrefs);
  15.473 +    ste_bin_pol.ssidrefs = (domaintype_t *)ssidrefsbuf;
  15.474  
  15.475 -     /* clear all ste caches */
  15.476 -     read_lock(&domlist_lock);
  15.477 -     pd = &domain_list;
  15.478 -     for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
  15.479 -	 ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.480 -			 (struct acm_ssid_domain *)(*pd)->ssid);
  15.481 - 	 for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.482 -		ste_ssid->ste_cache[i].valid = FREE;
  15.483 -     }
  15.484 -     read_unlock(&domlist_lock);
  15.485 -     return ACM_OK;
  15.486 +    /* clear all ste caches */
  15.487 +    read_lock(&domlist_lock);
  15.488 +    pd = &domain_list;
  15.489 +    for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
  15.490 +        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.491 +                             (struct acm_ssid_domain *)(*pd)->ssid);
  15.492 +        for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.493 +            ste_ssid->ste_cache[i].valid = FREE;
  15.494 +    }
  15.495 +    read_unlock(&domlist_lock);
  15.496 +    return ACM_OK;
  15.497  
  15.498 -error_free:
  15.499 -	printk("%s: ERROR setting policy.\n", __func__);
  15.500 -	if (ssidrefsbuf != NULL) xfree(ssidrefsbuf);
  15.501 -	return -EFAULT;
  15.502 + error_free:
  15.503 +    printk("%s: ERROR setting policy.\n", __func__);
  15.504 +    if (ssidrefsbuf != NULL) xfree(ssidrefsbuf);
  15.505 +    return -EFAULT;
  15.506  }
  15.507  
  15.508  static int 
  15.509 @@ -337,41 +347,6 @@ ste_dump_stats(u8 *buf, u16 buf_len)
  15.510  {
  15.511      struct acm_ste_stats_buffer stats;
  15.512  
  15.513 -#ifdef ACM_DEBUG
  15.514 -    int i;
  15.515 -    struct ste_ssid *ste_ssid;
  15.516 -    struct domain **pd;
  15.517 -
  15.518 -    printk("ste: Decision caches:\n");
  15.519 -    /* go through all domains and adjust policy as if this domain was started now */
  15.520 -    read_lock(&domlist_lock); /* go by domain? or directly by global? event/grant list */
  15.521 -    pd = &domain_list;
  15.522 -    for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
  15.523 -        printk("ste: Cache Domain %02x.\n", (*pd)->domain_id);
  15.524 -	ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.525 -			 (struct acm_ssid_domain *)(*pd)->ssid);
  15.526 -	for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.527 -		printk("\t\tcache[%02x] = %s, domid=%x.\n", i,
  15.528 -		       (ste_ssid->ste_cache[i].valid == VALID) ? 
  15.529 -		       "VALID" : "FREE",
  15.530 -		       (ste_ssid->ste_cache[i].valid == VALID) ? 
  15.531 -		       ste_ssid->ste_cache[i].id : 0xffffffff);
  15.532 -    }
  15.533 -    read_unlock(&domlist_lock);
  15.534 -    /* init stats */
  15.535 -    printk("STE-Policy Security Hook Statistics:\n");
  15.536 -    printk("ste: event_channel eval_count      = %x\n", atomic_read(&(ste_bin_pol.ec_eval_count)));
  15.537 -    printk("ste: event_channel denied_count    = %x\n", atomic_read(&(ste_bin_pol.ec_denied_count))); 
  15.538 -    printk("ste: event_channel cache_hit_count = %x\n", atomic_read(&(ste_bin_pol.ec_cachehit_count)));
  15.539 -    printk("ste:\n");
  15.540 -    printk("ste: grant_table   eval_count      = %x\n", atomic_read(&(ste_bin_pol.gt_eval_count)));
  15.541 -    printk("ste: grant_table   denied_count    = %x\n", atomic_read(&(ste_bin_pol.gt_denied_count))); 
  15.542 -    printk("ste: grant_table   cache_hit_count = %x\n", atomic_read(&(ste_bin_pol.gt_cachehit_count)));
  15.543 -#endif
  15.544 -
  15.545 -    if (buf_len < sizeof(struct acm_ste_stats_buffer))
  15.546 -	    return -ENOMEM;
  15.547 -
  15.548      /* now send the hook counts to user space */
  15.549      stats.ec_eval_count = htonl(atomic_read(&ste_bin_pol.ec_eval_count));
  15.550      stats.gt_eval_count = htonl(atomic_read(&ste_bin_pol.gt_eval_count));
  15.551 @@ -379,6 +354,10 @@ ste_dump_stats(u8 *buf, u16 buf_len)
  15.552      stats.gt_denied_count = htonl(atomic_read(&ste_bin_pol.gt_denied_count)); 
  15.553      stats.ec_cachehit_count = htonl(atomic_read(&ste_bin_pol.ec_cachehit_count));
  15.554      stats.gt_cachehit_count = htonl(atomic_read(&ste_bin_pol.gt_cachehit_count));
  15.555 +
  15.556 +    if (buf_len < sizeof(struct acm_ste_stats_buffer))
  15.557 +        return -ENOMEM;
  15.558 +
  15.559      memcpy(buf, &stats, sizeof(struct acm_ste_stats_buffer));
  15.560      return sizeof(struct acm_ste_stats_buffer);
  15.561  }
  15.562 @@ -392,12 +371,12 @@ ste_dump_ssid_types(ssidref_t ssidref, u
  15.563      if (ste_bin_pol.max_types > len)
  15.564          return -EFAULT;
  15.565  
  15.566 -	if (ssidref >= ste_bin_pol.max_ssidrefs)
  15.567 -		return -EFAULT;
  15.568 +    if (ssidref >= ste_bin_pol.max_ssidrefs)
  15.569 +        return -EFAULT;
  15.570  
  15.571      /* read types for chwall ssidref */
  15.572      for(i=0; i< ste_bin_pol.max_types; i++) {
  15.573 -		if (ste_bin_pol.ssidrefs[ssidref * ste_bin_pol.max_types + i])
  15.574 +        if (ste_bin_pol.ssidrefs[ssidref * ste_bin_pol.max_types + i])
  15.575              buf[i] = 1;
  15.576          else
  15.577              buf[i] = 0;
  15.578 @@ -409,40 +388,40 @@ ste_dump_ssid_types(ssidref_t ssidref, u
  15.579   * returns 1 == cache hit */
  15.580  static int inline
  15.581  check_cache(struct domain *dom, domid_t rdom) {
  15.582 -	struct ste_ssid *ste_ssid;
  15.583 -	int i;
  15.584 +    struct ste_ssid *ste_ssid;
  15.585 +    int i;
  15.586  
  15.587 -	printkd("checking cache: %x --> %x.\n", dom->domain_id, rdom);
  15.588 -	ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.589 -			 (struct acm_ssid_domain *)(dom)->ssid);
  15.590 +    printkd("checking cache: %x --> %x.\n", dom->domain_id, rdom);
  15.591 +    ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.592 +                         (struct acm_ssid_domain *)(dom)->ssid);
  15.593  
  15.594 -	for(i=0; i< ACM_TE_CACHE_SIZE; i++) {
  15.595 -		if ((ste_ssid->ste_cache[i].valid == VALID) &&
  15.596 -		    (ste_ssid->ste_cache[i].id == rdom)) {
  15.597 -			printkd("cache hit (entry %x, id= %x!\n", i, ste_ssid->ste_cache[i].id);
  15.598 -			return 1;
  15.599 -		}
  15.600 -	}
  15.601 -	return 0;
  15.602 +    for(i=0; i< ACM_TE_CACHE_SIZE; i++) {
  15.603 +        if ((ste_ssid->ste_cache[i].valid == VALID) &&
  15.604 +            (ste_ssid->ste_cache[i].id == rdom)) {
  15.605 +            printkd("cache hit (entry %x, id= %x!\n", i, ste_ssid->ste_cache[i].id);
  15.606 +            return 1;
  15.607 +        }
  15.608 +    }
  15.609 +    return 0;
  15.610  }
  15.611  
  15.612  
  15.613  /* we only get here if there is NO entry yet; no duplication check! */
  15.614  static void inline
  15.615  cache_result(struct domain *subj, struct domain *obj) {
  15.616 -	struct ste_ssid *ste_ssid;
  15.617 -	int i;
  15.618 -	printkd("caching from doms: %x --> %x.\n", subj->domain_id, obj->domain_id);
  15.619 -	ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.620 -			 (struct acm_ssid_domain *)(subj)->ssid);
  15.621 -	for(i=0; i< ACM_TE_CACHE_SIZE; i++)
  15.622 -		if (ste_ssid->ste_cache[i].valid == FREE)
  15.623 -			break;
  15.624 -	if (i< ACM_TE_CACHE_SIZE) {
  15.625 -		ste_ssid->ste_cache[i].valid = VALID;
  15.626 -		ste_ssid->ste_cache[i].id = obj->domain_id;
  15.627 -	} else
  15.628 -		printk ("Cache of dom %x is full!\n", subj->domain_id);
  15.629 +    struct ste_ssid *ste_ssid;
  15.630 +    int i;
  15.631 +    printkd("caching from doms: %x --> %x.\n", subj->domain_id, obj->domain_id);
  15.632 +    ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.633 +                         (struct acm_ssid_domain *)(subj)->ssid);
  15.634 +    for(i=0; i< ACM_TE_CACHE_SIZE; i++)
  15.635 +        if (ste_ssid->ste_cache[i].valid == FREE)
  15.636 +            break;
  15.637 +    if (i< ACM_TE_CACHE_SIZE) {
  15.638 +        ste_ssid->ste_cache[i].valid = VALID;
  15.639 +        ste_ssid->ste_cache[i].id = obj->domain_id;
  15.640 +    } else
  15.641 +        printk ("Cache of dom %x is full!\n", subj->domain_id);
  15.642  }
  15.643  
  15.644  /* deletes entries for domain 'id' from all caches (re-use) */
  15.645 @@ -458,12 +437,12 @@ clean_id_from_cache(domid_t id)
  15.646      read_lock(&domlist_lock); /* look through caches of all domains */
  15.647      pd = &domain_list;
  15.648      for ( pd = &domain_list; *pd != NULL; pd = &(*pd)->next_in_list ) {
  15.649 -	ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.650 -			 (struct acm_ssid_domain *)(*pd)->ssid);
  15.651 -	for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.652 -	    if ((ste_ssid->ste_cache[i].valid == VALID) &&
  15.653 -		(ste_ssid->ste_cache[i].id = id))
  15.654 -		    ste_ssid->ste_cache[i].valid = FREE;
  15.655 +        ste_ssid = GET_SSIDP(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, 
  15.656 +                             (struct acm_ssid_domain *)(*pd)->ssid);
  15.657 +        for (i=0; i<ACM_TE_CACHE_SIZE; i++)
  15.658 +            if ((ste_ssid->ste_cache[i].valid == VALID) &&
  15.659 +                (ste_ssid->ste_cache[i].id = id))
  15.660 +                ste_ssid->ste_cache[i].valid = FREE;
  15.661      }
  15.662      read_unlock(&domlist_lock);
  15.663  }
  15.664 @@ -482,15 +461,15 @@ ste_pre_domain_create(void *subject_ssid
  15.665      read_lock(&acm_bin_pol_rwlock);
  15.666      ste_ssidref = GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref);
  15.667      if (ste_ssidref == ACM_DEFAULT_LOCAL_SSID) {
  15.668 -	printk("%s: ERROR STE SSID is NOT SET but policy enforced.\n", __func__);
  15.669 -	read_unlock(&acm_bin_pol_rwlock);
  15.670 -	return ACM_ACCESS_DENIED; /* catching and indicating config error */
  15.671 +        printk("%s: ERROR STE SSID is NOT SET but policy enforced.\n", __func__);
  15.672 +        read_unlock(&acm_bin_pol_rwlock);
  15.673 +        return ACM_ACCESS_DENIED; /* catching and indicating config error */
  15.674      }
  15.675      if (ste_ssidref >= ste_bin_pol.max_ssidrefs) {
  15.676 -	printk("%s: ERROR ste_ssidref > max(%x).\n", 
  15.677 -	       __func__, ste_bin_pol.max_ssidrefs-1);
  15.678 -	read_unlock(&acm_bin_pol_rwlock);
  15.679 -	return ACM_ACCESS_DENIED;
  15.680 +        printk("%s: ERROR ste_ssidref > max(%x).\n", 
  15.681 +               __func__, ste_bin_pol.max_ssidrefs-1);
  15.682 +        read_unlock(&acm_bin_pol_rwlock);
  15.683 +        return ACM_ACCESS_DENIED;
  15.684      }
  15.685      read_unlock(&acm_bin_pol_rwlock);
  15.686      return ACM_ACCESS_PERMITTED;
  15.687 @@ -506,163 +485,193 @@ ste_post_domain_destroy(void *subject_ss
  15.688  /* -------- EVENTCHANNEL OPERATIONS -----------*/
  15.689  static int
  15.690  ste_pre_eventchannel_unbound(domid_t id) {
  15.691 -	struct domain *subj, *obj;
  15.692 -	int ret;
  15.693 -	traceprintk("%s: dom%x-->dom%x.\n", 
  15.694 -		    __func__, current->domain->domain_id, id);
  15.695 +    struct domain *subj, *obj;
  15.696 +    int ret;
  15.697 +    traceprintk("%s: dom%x-->dom%x.\n", 
  15.698 +                __func__, current->domain->domain_id, id);
  15.699  
  15.700 -	if (check_cache(current->domain, id)) {
  15.701 -		atomic_inc(&ste_bin_pol.ec_cachehit_count);
  15.702 -		return ACM_ACCESS_PERMITTED;
  15.703 -	}
  15.704 -	atomic_inc(&ste_bin_pol.ec_eval_count);
  15.705 -	subj = current->domain;
  15.706 -	obj = find_domain_by_id(id);
  15.707 +    if (check_cache(current->domain, id)) {
  15.708 +        atomic_inc(&ste_bin_pol.ec_cachehit_count);
  15.709 +        return ACM_ACCESS_PERMITTED;
  15.710 +    }
  15.711 +    atomic_inc(&ste_bin_pol.ec_eval_count);
  15.712 +    subj = current->domain;
  15.713 +    obj = find_domain_by_id(id);
  15.714  
  15.715 -	if (share_common_type(subj, obj)) {
  15.716 -		cache_result(subj, obj);
  15.717 -		ret = ACM_ACCESS_PERMITTED;
  15.718 -	} else {
  15.719 -		atomic_inc(&ste_bin_pol.ec_denied_count); 
  15.720 -		ret = ACM_ACCESS_DENIED;	
  15.721 -	}
  15.722 -	if (obj != NULL)
  15.723 -		put_domain(obj);
  15.724 -	return ret;
  15.725 +    if (share_common_type(subj, obj)) {
  15.726 +        cache_result(subj, obj);
  15.727 +        ret = ACM_ACCESS_PERMITTED;
  15.728 +    } else {
  15.729 +        atomic_inc(&ste_bin_pol.ec_denied_count); 
  15.730 +        ret = ACM_ACCESS_DENIED; 
  15.731 +    }
  15.732 +    if (obj != NULL)
  15.733 +        put_domain(obj);
  15.734 +    return ret;
  15.735  }
  15.736  
  15.737  static int
  15.738  ste_pre_eventchannel_interdomain(domid_t id1, domid_t id2)
  15.739  {
  15.740 -	struct domain *subj, *obj;
  15.741 -	int ret;
  15.742 -	traceprintk("%s: dom%x-->dom%x.\n", __func__,
  15.743 -		    (id1 == DOMID_SELF) ? current->domain->domain_id : id1,
  15.744 -		    (id2 == DOMID_SELF) ? current->domain->domain_id : id2);
  15.745 +    struct domain *subj, *obj;
  15.746 +    int ret;
  15.747 +    traceprintk("%s: dom%x-->dom%x.\n", __func__,
  15.748 +                (id1 == DOMID_SELF) ? current->domain->domain_id : id1,
  15.749 +                (id2 == DOMID_SELF) ? current->domain->domain_id : id2);
  15.750  
  15.751 -	/* following is a bit longer but ensures that we
  15.752 -         * "put" only domains that we where "find"-ing 
  15.753 -	 */
  15.754 -	if (id1 == DOMID_SELF) id1 = current->domain->domain_id;
  15.755 -	if (id2 == DOMID_SELF) id2 = current->domain->domain_id;
  15.756 +    /* following is a bit longer but ensures that we
  15.757 +     * "put" only domains that we where "find"-ing 
  15.758 +     */
  15.759 +    if (id1 == DOMID_SELF) id1 = current->domain->domain_id;
  15.760 +    if (id2 == DOMID_SELF) id2 = current->domain->domain_id;
  15.761  
  15.762 -	subj = find_domain_by_id(id1);
  15.763 -	obj  = find_domain_by_id(id2);
  15.764 -	if ((subj == NULL) || (obj == NULL)) {
  15.765 -		ret = ACM_ACCESS_DENIED;
  15.766 -		goto out;
  15.767 -	}
  15.768 -	/* cache check late, but evtchn is not on performance critical path */
  15.769 -	if (check_cache(subj, obj->domain_id)) {
  15.770 -		atomic_inc(&ste_bin_pol.ec_cachehit_count);
  15.771 -		ret = ACM_ACCESS_PERMITTED;
  15.772 -		goto out;
  15.773 -	}
  15.774 -	atomic_inc(&ste_bin_pol.ec_eval_count);
  15.775 +    subj = find_domain_by_id(id1);
  15.776 +    obj  = find_domain_by_id(id2);
  15.777 +    if ((subj == NULL) || (obj == NULL)) {
  15.778 +        ret = ACM_ACCESS_DENIED;
  15.779 +        goto out;
  15.780 +    }
  15.781 +    /* cache check late, but evtchn is not on performance critical path */
  15.782 +    if (check_cache(subj, obj->domain_id)) {
  15.783 +        atomic_inc(&ste_bin_pol.ec_cachehit_count);
  15.784 +        ret = ACM_ACCESS_PERMITTED;
  15.785 +        goto out;
  15.786 +    }
  15.787 +    atomic_inc(&ste_bin_pol.ec_eval_count);
  15.788  
  15.789 -	if (share_common_type(subj, obj)) {
  15.790 -		cache_result(subj, obj);
  15.791 -		ret = ACM_ACCESS_PERMITTED;
  15.792 -	} else {
  15.793 -		atomic_inc(&ste_bin_pol.ec_denied_count); 
  15.794 -		ret = ACM_ACCESS_DENIED;	
  15.795 -	}
  15.796 +    if (share_common_type(subj, obj)) {
  15.797 +        cache_result(subj, obj);
  15.798 +        ret = ACM_ACCESS_PERMITTED;
  15.799 +    } else {
  15.800 +        atomic_inc(&ste_bin_pol.ec_denied_count); 
  15.801 +        ret = ACM_ACCESS_DENIED; 
  15.802 +    }
  15.803   out:
  15.804 -	if (obj != NULL)
  15.805 -		put_domain(obj);
  15.806 -	if (subj != NULL)
  15.807 -		put_domain(subj);
  15.808 -	return ret;
  15.809 +    if (obj != NULL)
  15.810 +        put_domain(obj);
  15.811 +    if (subj != NULL)
  15.812 +        put_domain(subj);
  15.813 +    return ret;
  15.814  }
  15.815  
  15.816  /* -------- SHARED MEMORY OPERATIONS -----------*/
  15.817  
  15.818  static int
  15.819  ste_pre_grant_map_ref (domid_t id) {
  15.820 -	struct domain *obj, *subj;
  15.821 -	int ret;
  15.822 -	traceprintk("%s: dom%x-->dom%x.\n", __func__,
  15.823 -		    current->domain->domain_id, id);
  15.824 +    struct domain *obj, *subj;
  15.825 +    int ret;
  15.826 +    traceprintk("%s: dom%x-->dom%x.\n", __func__,
  15.827 +                current->domain->domain_id, id);
  15.828  
  15.829 -	if (check_cache(current->domain, id)) {
  15.830 -		atomic_inc(&ste_bin_pol.gt_cachehit_count);
  15.831 -		return ACM_ACCESS_PERMITTED;
  15.832 -	}
  15.833 -	atomic_inc(&ste_bin_pol.gt_eval_count);
  15.834 -	subj = current->domain;
  15.835 -	obj = find_domain_by_id(id);
  15.836 +    if (check_cache(current->domain, id)) {
  15.837 +        atomic_inc(&ste_bin_pol.gt_cachehit_count);
  15.838 +        return ACM_ACCESS_PERMITTED;
  15.839 +    }
  15.840 +    atomic_inc(&ste_bin_pol.gt_eval_count);
  15.841 +    subj = current->domain;
  15.842 +    obj = find_domain_by_id(id);
  15.843  
  15.844 -	if (share_common_type(subj, obj)) {
  15.845 -		cache_result(subj, obj);
  15.846 -		ret = ACM_ACCESS_PERMITTED;
  15.847 -	} else {
  15.848 -		atomic_inc(&ste_bin_pol.gt_denied_count); 
  15.849 -		printkd("%s: ACCESS DENIED!\n", __func__);
  15.850 -		ret = ACM_ACCESS_DENIED;	
  15.851 -	}
  15.852 -	if (obj != NULL)
  15.853 -		put_domain(obj);
  15.854 -	return ret;
  15.855 +    if (share_common_type(subj, obj)) {
  15.856 +        cache_result(subj, obj);
  15.857 +        ret = ACM_ACCESS_PERMITTED;
  15.858 +    } else {
  15.859 +        atomic_inc(&ste_bin_pol.gt_denied_count); 
  15.860 +        printkd("%s: ACCESS DENIED!\n", __func__);
  15.861 +        ret = ACM_ACCESS_DENIED; 
  15.862 +    }
  15.863 +    if (obj != NULL)
  15.864 +        put_domain(obj);
  15.865 +    return ret;
  15.866  }
  15.867  
  15.868 +
  15.869  /* since setting up grant tables involves some implicit information
  15.870     flow from the creating domain to the domain that is setup, we 
  15.871     check types in addition to the general authorization */
  15.872  static int
  15.873  ste_pre_grant_setup (domid_t id) {
  15.874 -	struct domain *obj, *subj;
  15.875 -	int ret;
  15.876 -	traceprintk("%s: dom%x-->dom%x.\n", __func__,
  15.877 -		    current->domain->domain_id, id);
  15.878 +    struct domain *obj, *subj;
  15.879 +    int ret;
  15.880 +    traceprintk("%s: dom%x-->dom%x.\n", __func__,
  15.881 +                current->domain->domain_id, id);
  15.882 +
  15.883 +    if (check_cache(current->domain, id)) {
  15.884 +        atomic_inc(&ste_bin_pol.gt_cachehit_count);
  15.885 +        return ACM_ACCESS_PERMITTED;
  15.886 +    }
  15.887 +    atomic_inc(&ste_bin_pol.gt_eval_count);
  15.888 +    /* a) check authorization (eventually use specific capabilities) */
  15.889 +    if (!IS_PRIV(current->domain)) {
  15.890 +        printk("%s: Grant table management authorization denied ERROR!\n", __func__);
  15.891 +        return ACM_ACCESS_DENIED;
  15.892 +    }
  15.893 +    /* b) check types */
  15.894 +    subj = current->domain;
  15.895 +    obj = find_domain_by_id(id);
  15.896  
  15.897 -	if (check_cache(current->domain, id)) {
  15.898 -		atomic_inc(&ste_bin_pol.gt_cachehit_count);
  15.899 -		return ACM_ACCESS_PERMITTED;
  15.900 -	}
  15.901 -	atomic_inc(&ste_bin_pol.gt_eval_count);
  15.902 -	/* a) check authorization (eventually use specific capabilities) */
  15.903 -	if (!IS_PRIV(current->domain)) {
  15.904 -		printk("%s: Grant table management authorization denied ERROR!\n", __func__);
  15.905 -		return ACM_ACCESS_DENIED;
  15.906 -	}
  15.907 -	/* b) check types */
  15.908 -	subj = current->domain;
  15.909 -	obj = find_domain_by_id(id);
  15.910 +    if (share_common_type(subj, obj)) {
  15.911 +        cache_result(subj, obj);
  15.912 +        ret = ACM_ACCESS_PERMITTED;
  15.913 +    } else {
  15.914 +        atomic_inc(&ste_bin_pol.gt_denied_count); 
  15.915 +        ret = ACM_ACCESS_DENIED; 
  15.916 +    }
  15.917 +    if (obj != NULL)
  15.918 +        put_domain(obj);
  15.919 +    return ret;
  15.920 +}
  15.921  
  15.922 -	if (share_common_type(subj, obj)) {
  15.923 -		cache_result(subj, obj);
  15.924 -		ret = ACM_ACCESS_PERMITTED;
  15.925 -	} else {
  15.926 -		atomic_inc(&ste_bin_pol.gt_denied_count); 
  15.927 -		ret = ACM_ACCESS_DENIED;	
  15.928 -	}
  15.929 -	if (obj != NULL)
  15.930 -		put_domain(obj);
  15.931 -	return ret;
  15.932 +/* -------- DOMAIN-Requested Decision hooks -----------*/
  15.933 +
  15.934 +static int
  15.935 +ste_sharing(ssidref_t ssidref1, ssidref_t ssidref2) {
  15.936 +    if (have_common_type (
  15.937 +        GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref1),
  15.938 +        GET_SSIDREF(ACM_SIMPLE_TYPE_ENFORCEMENT_POLICY, ssidref2)
  15.939 +        ))
  15.940 +        return ACM_ACCESS_PERMITTED;
  15.941 +    else
  15.942 +        return ACM_ACCESS_DENIED;
  15.943  }
  15.944  
  15.945 +
  15.946  /* now define the hook structure similarly to LSM */
  15.947  struct acm_operations acm_simple_type_enforcement_ops = {
  15.948 -	/* policy management services */
  15.949 -	.init_domain_ssid		= ste_init_domain_ssid,
  15.950 -	.free_domain_ssid		= ste_free_domain_ssid,
  15.951 -	.dump_binary_policy     = ste_dump_policy,
  15.952 -	.set_binary_policy      = ste_set_policy,
  15.953 -	.dump_statistics		= ste_dump_stats,
  15.954 +
  15.955 +    /* policy management services */
  15.956 +    .init_domain_ssid  = ste_init_domain_ssid,
  15.957 +    .free_domain_ssid  = ste_free_domain_ssid,
  15.958 +    .dump_binary_policy     = ste_dump_policy,
  15.959 +    .set_binary_policy      = ste_set_policy,
  15.960 +    .dump_statistics  = ste_dump_stats,
  15.961      .dump_ssid_types        = ste_dump_ssid_types,
  15.962 -	/* domain management control hooks */
  15.963 -	.pre_domain_create     		= ste_pre_domain_create,
  15.964 -	.post_domain_create	    = NULL,
  15.965 -	.fail_domain_create     = NULL,
  15.966 -	.post_domain_destroy    = ste_post_domain_destroy,
  15.967 -	/* event channel control hooks */
  15.968 -	.pre_eventchannel_unbound   = ste_pre_eventchannel_unbound,
  15.969 -	.fail_eventchannel_unbound	= NULL,
  15.970 -	.pre_eventchannel_interdomain	= ste_pre_eventchannel_interdomain,
  15.971 -	.fail_eventchannel_interdomain  = NULL,
  15.972 -	/* grant table control hooks */
  15.973 -	.pre_grant_map_ref      = ste_pre_grant_map_ref,
  15.974 -	.fail_grant_map_ref     = NULL,
  15.975 -	.pre_grant_setup        = ste_pre_grant_setup,
  15.976 -	.fail_grant_setup       = NULL,
  15.977 +
  15.978 +    /* domain management control hooks */
  15.979 +    .pre_domain_create       = ste_pre_domain_create,
  15.980 +    .post_domain_create     = NULL,
  15.981 +    .fail_domain_create     = NULL,
  15.982 +    .post_domain_destroy    = ste_post_domain_destroy,
  15.983 +
  15.984 +    /* event channel control hooks */
  15.985 +    .pre_eventchannel_unbound   = ste_pre_eventchannel_unbound,
  15.986 +    .fail_eventchannel_unbound = NULL,
  15.987 +    .pre_eventchannel_interdomain = ste_pre_eventchannel_interdomain,
  15.988 +    .fail_eventchannel_interdomain  = NULL,
  15.989 +
  15.990 +    /* grant table control hooks */
  15.991 +    .pre_grant_map_ref      = ste_pre_grant_map_ref,
  15.992 +    .fail_grant_map_ref     = NULL,
  15.993 +    .pre_grant_setup        = ste_pre_grant_setup,
  15.994 +    .fail_grant_setup       = NULL,
  15.995 +    .sharing                = ste_sharing,
  15.996  };
  15.997 +
  15.998 +/*
  15.999 + * Local variables:
 15.1000 + * mode: C
 15.1001 + * c-set-style: "BSD"
 15.1002 + * c-basic-offset: 4
 15.1003 + * tab-width: 4
 15.1004 + * indent-tabs-mode: nil
 15.1005 + * End:
 15.1006 + */
    16.1 --- a/xen/arch/x86/domain.c	Fri Oct 21 12:06:17 2005 +0100
    16.2 +++ b/xen/arch/x86/domain.c	Fri Oct 21 12:07:14 2005 +0100
    16.3 @@ -254,6 +254,7 @@ void free_perdomain_pt(struct domain *d)
    16.4  void arch_do_createdomain(struct vcpu *v)
    16.5  {
    16.6      struct domain *d = v->domain;
    16.7 +    l1_pgentry_t gdt_l1e;
    16.8      int vcpuid;
    16.9  
   16.10      if ( is_idle_task(d) )
   16.11 @@ -282,12 +283,10 @@ void arch_do_createdomain(struct vcpu *v
   16.12       * GDT, and the old VCPU# is invalid in the new domain, we would otherwise
   16.13       * try to load CS from an invalid table.
   16.14       */
   16.15 +    gdt_l1e = l1e_from_page(virt_to_page(gdt_table), PAGE_HYPERVISOR);
   16.16      for ( vcpuid = 0; vcpuid < MAX_VIRT_CPUS; vcpuid++ )
   16.17 -    {
   16.18          d->arch.mm_perdomain_pt[
   16.19 -            (vcpuid << PDPT_VCPU_SHIFT) + FIRST_RESERVED_GDT_PAGE] =
   16.20 -            l1e_from_page(virt_to_page(gdt_table), PAGE_HYPERVISOR);
   16.21 -    }
   16.22 +            (vcpuid << PDPT_VCPU_SHIFT) + FIRST_RESERVED_GDT_PAGE] = gdt_l1e;
   16.23  
   16.24      v->arch.guest_vtable  = __linear_l2_table;
   16.25      v->arch.shadow_vtable = __shadow_linear_l2_table;
    17.1 --- a/xen/arch/x86/setup.c	Fri Oct 21 12:06:17 2005 +0100
    17.2 +++ b/xen/arch/x86/setup.c	Fri Oct 21 12:07:14 2005 +0100
    17.3 @@ -141,7 +141,7 @@ static void __init do_initcalls(void)
    17.4  static void __init start_of_day(void)
    17.5  {
    17.6      int i;
    17.7 -    unsigned long vgdt;
    17.8 +    unsigned long vgdt, gdt_pfn;
    17.9  
   17.10      early_cpu_init();
   17.11  
   17.12 @@ -164,10 +164,10 @@ static void __init start_of_day(void)
   17.13       * noted in arch_do_createdomain(), we must map for every possible VCPU#.
   17.14       */
   17.15      vgdt = GDT_VIRT_START(current) + FIRST_RESERVED_GDT_BYTE;
   17.16 +    gdt_pfn = virt_to_phys(gdt_table) >> PAGE_SHIFT;
   17.17      for ( i = 0; i < MAX_VIRT_CPUS; i++ )
   17.18      {
   17.19 -        map_pages_to_xen(
   17.20 -            vgdt, virt_to_phys(gdt_table) >> PAGE_SHIFT, 1, PAGE_HYPERVISOR);
   17.21 +        map_pages_to_xen(vgdt, gdt_pfn, 1, PAGE_HYPERVISOR);
   17.22          vgdt += 1 << PDPT_VCPU_VA_SHIFT;
   17.23      }
   17.24  
    18.1 --- a/xen/common/acm_ops.c	Fri Oct 21 12:06:17 2005 +0100
    18.2 +++ b/xen/common/acm_ops.c	Fri Oct 21 12:07:14 2005 +0100
    18.3 @@ -31,22 +31,23 @@
    18.4  
    18.5  #if (ACM_USE_SECURITY_POLICY == ACM_NULL_POLICY)
    18.6  
    18.7 -long do_acm_op(acm_op_t * u_acm_op)
    18.8 +long do_acm_op(struct acm_op * u_acm_op)
    18.9  {
   18.10      return -ENOSYS;
   18.11  }
   18.12  
   18.13  #else
   18.14  
   18.15 -typedef enum acm_operation {
   18.16 +enum acm_operation {
   18.17      POLICY,                     /* access to policy interface (early drop) */
   18.18      GETPOLICY,                  /* dump policy cache */
   18.19      SETPOLICY,                  /* set policy cache (controls security) */
   18.20      DUMPSTATS,                  /* dump policy statistics */
   18.21 -    GETSSID                     /* retrieve ssidref for domain id */
   18.22 -} acm_operation_t;
   18.23 +    GETSSID,                    /* retrieve ssidref for domain id (decide inside authorized domains) */
   18.24 +    GETDECISION                 /* retrieve ACM decision from authorized domains */
   18.25 +};
   18.26  
   18.27 -int acm_authorize_acm_ops(struct domain *d, acm_operation_t pops)
   18.28 +int acm_authorize_acm_ops(struct domain *d, enum acm_operation pops)
   18.29  {
   18.30      /* all policy management functions are restricted to privileged domains,
   18.31       * soon we will introduce finer-grained privileges for policy operations
   18.32 @@ -59,10 +60,10 @@ int acm_authorize_acm_ops(struct domain 
   18.33      return ACM_ACCESS_PERMITTED;
   18.34  }
   18.35  
   18.36 -long do_acm_op(acm_op_t * u_acm_op)
   18.37 +long do_acm_op(struct acm_op * u_acm_op)
   18.38  {
   18.39      long ret = 0;
   18.40 -    acm_op_t curop, *op = &curop;
   18.41 +    struct acm_op curop, *op = &curop;
   18.42  
   18.43      /* check here policy decision for policy commands */
   18.44      /* for now allow DOM0 only, later indepedently    */
   18.45 @@ -78,81 +79,148 @@ long do_acm_op(acm_op_t * u_acm_op)
   18.46      switch (op->cmd)
   18.47      {
   18.48      case ACM_SETPOLICY:
   18.49 -        {
   18.50 -            if (acm_authorize_acm_ops(current->domain, SETPOLICY))
   18.51 -                return -EACCES;
   18.52 -            printkd("%s: setting policy.\n", __func__);
   18.53 -            ret = acm_set_policy(op->u.setpolicy.pushcache,
   18.54 -                                 op->u.setpolicy.pushcache_size, 1);
   18.55 -            if (ret == ACM_OK)
   18.56 -                ret = 0;
   18.57 -            else
   18.58 -                ret = -ESRCH;
   18.59 -        }
   18.60 -        break;
   18.61 +    {
   18.62 +        if (acm_authorize_acm_ops(current->domain, SETPOLICY))
   18.63 +            return -EACCES;
   18.64 +        printkd("%s: setting policy.\n", __func__);
   18.65 +        ret = acm_set_policy(op->u.setpolicy.pushcache,
   18.66 +                             op->u.setpolicy.pushcache_size, 1);
   18.67 +        if (ret == ACM_OK)
   18.68 +            ret = 0;
   18.69 +        else
   18.70 +            ret = -ESRCH;
   18.71 +    }
   18.72 +    break;
   18.73  
   18.74      case ACM_GETPOLICY:
   18.75 -        {
   18.76 -            if (acm_authorize_acm_ops(current->domain, GETPOLICY))
   18.77 -                return -EACCES;
   18.78 -            printkd("%s: getting policy.\n", __func__);
   18.79 -            ret = acm_get_policy(op->u.getpolicy.pullcache,
   18.80 -                                 op->u.getpolicy.pullcache_size);
   18.81 -            if (ret == ACM_OK)
   18.82 -                ret = 0;
   18.83 -            else
   18.84 -                ret = -ESRCH;
   18.85 -        }
   18.86 -        break;
   18.87 +    {
   18.88 +        if (acm_authorize_acm_ops(current->domain, GETPOLICY))
   18.89 +            return -EACCES;
   18.90 +        printkd("%s: getting policy.\n", __func__);
   18.91 +        ret = acm_get_policy(op->u.getpolicy.pullcache,
   18.92 +                             op->u.getpolicy.pullcache_size);
   18.93 +        if (ret == ACM_OK)
   18.94 +            ret = 0;
   18.95 +        else
   18.96 +            ret = -ESRCH;
   18.97 +    }
   18.98 +    break;
   18.99  
  18.100      case ACM_DUMPSTATS:
  18.101 -        {
  18.102 -            if (acm_authorize_acm_ops(current->domain, DUMPSTATS))
  18.103 -                return -EACCES;
  18.104 -            printkd("%s: dumping statistics.\n", __func__);
  18.105 -            ret = acm_dump_statistics(op->u.dumpstats.pullcache,
  18.106 -                                      op->u.dumpstats.pullcache_size);
  18.107 -            if (ret == ACM_OK)
  18.108 -                ret = 0;
  18.109 -            else
  18.110 -                ret = -ESRCH;
  18.111 -        }
  18.112 -        break;
  18.113 +    {
  18.114 +        if (acm_authorize_acm_ops(current->domain, DUMPSTATS))
  18.115 +            return -EACCES;
  18.116 +        printkd("%s: dumping statistics.\n", __func__);
  18.117 +        ret = acm_dump_statistics(op->u.dumpstats.pullcache,
  18.118 +                                  op->u.dumpstats.pullcache_size);
  18.119 +        if (ret == ACM_OK)
  18.120 +            ret = 0;
  18.121 +        else
  18.122 +            ret = -ESRCH;
  18.123 +    }
  18.124 +    break;
  18.125  
  18.126      case ACM_GETSSID:
  18.127 -        {
  18.128 -			ssidref_t ssidref;
  18.129 +    {
  18.130 +        ssidref_t ssidref;
  18.131  
  18.132 -            if (acm_authorize_acm_ops(current->domain, GETSSID))
  18.133 -                return -EACCES;
  18.134 +        if (acm_authorize_acm_ops(current->domain, GETSSID))
  18.135 +            return -EACCES;
  18.136 +        printkd("%s: getting SSID.\n", __func__);
  18.137 +        if (op->u.getssid.get_ssid_by == SSIDREF)
  18.138 +            ssidref = op->u.getssid.id.ssidref;
  18.139 +        else if (op->u.getssid.get_ssid_by == DOMAINID) {
  18.140 +            struct domain *subj = find_domain_by_id(op->u.getssid.id.domainid);
  18.141 +            if (!subj)
  18.142 +                return -ESRCH; /* domain not found */
  18.143  
  18.144 -			if (op->u.getssid.get_ssid_by == SSIDREF)
  18.145 -				ssidref = op->u.getssid.id.ssidref;
  18.146 -			else if (op->u.getssid.get_ssid_by == DOMAINID) {
  18.147 -				struct domain *subj = find_domain_by_id(op->u.getssid.id.domainid);
  18.148 -				if (!subj)
  18.149 -					return -ESRCH; /* domain not found */
  18.150 +            ssidref = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
  18.151 +            put_domain(subj);
  18.152 +        } else
  18.153 +            return -ESRCH;
  18.154 +
  18.155 +        ret = acm_get_ssid(ssidref,
  18.156 +                           op->u.getssid.ssidbuf,
  18.157 +                           op->u.getssid.ssidbuf_size);
  18.158 +        if (ret == ACM_OK)
  18.159 +            ret = 0;
  18.160 +        else
  18.161 +            ret = -ESRCH;
  18.162 +    }
  18.163 +    break;
  18.164 +
  18.165 +    case ACM_GETDECISION:
  18.166 +    {
  18.167 +        ssidref_t ssidref1, ssidref2;
  18.168  
  18.169 -				ssidref = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
  18.170 -				put_domain(subj);
  18.171 -			} else
  18.172 -				return -ESRCH;
  18.173 -
  18.174 -            ret = acm_get_ssid(ssidref,
  18.175 -                               op->u.getssid.ssidbuf,
  18.176 -                               op->u.getssid.ssidbuf_size);
  18.177 -            if (ret == ACM_OK)
  18.178 -                ret = 0;
  18.179 -            else
  18.180 -                ret = -ESRCH;
  18.181 +        if (acm_authorize_acm_ops(current->domain, GETDECISION)) {
  18.182 +            ret = -EACCES;
  18.183 +            goto out;
  18.184 +        }
  18.185 +        printkd("%s: getting access control decision.\n", __func__);
  18.186 +        if (op->u.getdecision.get_decision_by1 == SSIDREF) {
  18.187 +            ssidref1 = op->u.getdecision.id1.ssidref;
  18.188          }
  18.189 -        break;
  18.190 +        else if (op->u.getdecision.get_decision_by1 == DOMAINID) {
  18.191 +            struct domain *subj = find_domain_by_id(op->u.getdecision.id1.domainid);
  18.192 +            if (!subj) {
  18.193 +                ret = -ESRCH; /* domain not found */
  18.194 +                goto out;
  18.195 +            }
  18.196 +            ssidref1 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
  18.197 +            put_domain(subj);
  18.198 +        } else {
  18.199 +            ret = -ESRCH;
  18.200 +            goto out;
  18.201 +        }
  18.202 +        if (op->u.getdecision.get_decision_by2 == SSIDREF) {
  18.203 +            ssidref2 = op->u.getdecision.id2.ssidref;
  18.204 +        }
  18.205 +        else if (op->u.getdecision.get_decision_by2 == DOMAINID) {
  18.206 +            struct domain *subj = find_domain_by_id(op->u.getdecision.id2.domainid);
  18.207 +            if (!subj) {
  18.208 +                ret = -ESRCH; /* domain not found */
  18.209 +                goto out;
  18.210 +            }
  18.211 +            ssidref2 = ((struct acm_ssid_domain *)(subj->ssid))->ssidref;
  18.212 +            put_domain(subj);
  18.213 +        } else {
  18.214 +            ret = -ESRCH;
  18.215 +            goto out;
  18.216 +        }
  18.217 +        ret = acm_get_decision(ssidref1, ssidref2, op->u.getdecision.hook);
  18.218 +    }
  18.219 +    break;
  18.220  
  18.221      default:
  18.222          ret = -ESRCH;
  18.223 +    }
  18.224  
  18.225 + out:
  18.226 +    if (ret == ACM_ACCESS_PERMITTED) {
  18.227 +        op->u.getdecision.acm_decision = ACM_ACCESS_PERMITTED;
  18.228 +        ret = 0;
  18.229 +    } else if  (ret == ACM_ACCESS_DENIED) {
  18.230 +        op->u.getdecision.acm_decision = ACM_ACCESS_DENIED;
  18.231 +        ret = 0;
  18.232 +    } else {
  18.233 +        op->u.getdecision.acm_decision = ACM_ACCESS_DENIED;
  18.234 +        if (ret > 0)
  18.235 +            ret = -ret;
  18.236      }
  18.237 +    /* copy decision back to user space */
  18.238 +    copy_to_user(u_acm_op, op, sizeof(*op));
  18.239      return ret;
  18.240  }
  18.241  
  18.242  #endif
  18.243 +
  18.244 +/*
  18.245 + * Local variables:
  18.246 + * mode: C
  18.247 + * c-set-style: "BSD"
  18.248 + * c-basic-offset: 4
  18.249 + * tab-width: 4
  18.250 + * indent-tabs-mode: nil
  18.251 + * End:
  18.252 + */
    19.1 --- a/xen/common/dom0_ops.c	Fri Oct 21 12:06:17 2005 +0100
    19.2 +++ b/xen/common/dom0_ops.c	Fri Oct 21 12:07:14 2005 +0100
    19.3 @@ -199,7 +199,7 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
    19.4          /*
    19.5           * If we're on a HT system, we only use the first HT for dom0, other 
    19.6           * domains will all share the second HT of each CPU. Since dom0 is on 
    19.7 -	     * CPU 0, we favour high numbered CPUs in the event of a tie.
    19.8 +         * CPU 0, we favour high numbered CPUs in the event of a tie.
    19.9           */
   19.10          pro = smp_num_siblings - 1;
   19.11          for ( i = pro; i < num_online_cpus(); i += smp_num_siblings )
    20.1 --- a/xen/common/sched_sedf.c	Fri Oct 21 12:06:17 2005 +0100
    20.2 +++ b/xen/common/sched_sedf.c	Fri Oct 21 12:07:14 2005 +0100
    20.3 @@ -1150,7 +1150,7 @@ void sedf_wake(struct vcpu *d) {
    20.4      inf->block_tot++;
    20.5  #endif
    20.6      if (unlikely(now < PERIOD_BEGIN(inf))) {
    20.7 -    	PRINT(4,"extratime unblock\n");
    20.8 +        PRINT(4,"extratime unblock\n");
    20.9          /* unblocking in extra-time! */
   20.10  #if (EXTRA == EXTRA_BLOCK_WEIGHT)
   20.11          if (inf->status & EXTRA_WANT_PEN_Q) {
   20.12 @@ -1459,3 +1459,13 @@ struct scheduler sched_sedf_def = {
   20.13      .wake           = sedf_wake,
   20.14      .adjdom         = sedf_adjdom,
   20.15  };
   20.16 +
   20.17 +/*
   20.18 + * Local variables:
   20.19 + * mode: C
   20.20 + * c-set-style: "BSD"
   20.21 + * c-basic-offset: 4
   20.22 + * tab-width: 4
   20.23 + * indent-tabs-mode: nil
   20.24 + * End:
   20.25 + */
    21.1 --- a/xen/include/acm/acm_core.h	Fri Oct 21 12:06:17 2005 +0100
    21.2 +++ b/xen/include/acm/acm_core.h	Fri Oct 21 12:07:14 2005 +0100
    21.3 @@ -15,6 +15,7 @@
    21.4   *    for the access control module and relevant policies
    21.5   *
    21.6   */
    21.7 +
    21.8  #ifndef _ACM_CORE_H
    21.9  #define _ACM_CORE_H
   21.10  
   21.11 @@ -25,30 +26,30 @@
   21.12  
   21.13  /* Xen-internal representation of the binary policy */
   21.14  struct acm_binary_policy {
   21.15 -	u16 primary_policy_code;
   21.16 -	u16 secondary_policy_code;
   21.17 -	void *primary_binary_policy;                                 
   21.18 -	void *secondary_binary_policy;
   21.19 -	
   21.20 +    u16 primary_policy_code;
   21.21 +    u16 secondary_policy_code;
   21.22 +    void *primary_binary_policy;                                 
   21.23 +    void *secondary_binary_policy;
   21.24 + 
   21.25  };
   21.26  
   21.27  struct chwall_binary_policy {
   21.28 -	u16 max_types;
   21.29 -	u16 max_ssidrefs;
   21.30 -	u16 max_conflictsets;
   21.31 -	domaintype_t *ssidrefs;			/* [max_ssidrefs][max_types] 	*/
   21.32 -	domaintype_t *conflict_aggregate_set; 	/* [max_types] 			*/
   21.33 -	domaintype_t *running_types; 		/* [max_types] 			*/
   21.34 -	domaintype_t *conflict_sets;		/* [max_conflictsets][max_types]*/
   21.35 +    u32 max_types;
   21.36 +    u32 max_ssidrefs;
   21.37 +    u32 max_conflictsets;
   21.38 +    domaintype_t *ssidrefs;     /* [max_ssidrefs][max_types]  */
   21.39 +    domaintype_t *conflict_aggregate_set;  /* [max_types]      */
   21.40 +    domaintype_t *running_types;    /* [max_types]      */
   21.41 +    domaintype_t *conflict_sets;   /* [max_conflictsets][max_types]*/
   21.42  };
   21.43  
   21.44  struct ste_binary_policy {
   21.45 -	u16 max_types;
   21.46 -	u16 max_ssidrefs;
   21.47 -	domaintype_t *ssidrefs;			/* [max_ssidrefs][max_types] 	*/
   21.48 -	atomic_t ec_eval_count, gt_eval_count;
   21.49 -	atomic_t ec_denied_count, gt_denied_count; 
   21.50 -	atomic_t ec_cachehit_count, gt_cachehit_count;
   21.51 +    u32 max_types;
   21.52 +    u32 max_ssidrefs;
   21.53 +    domaintype_t *ssidrefs;     /* [max_ssidrefs][max_types]  */
   21.54 +    atomic_t ec_eval_count, gt_eval_count;
   21.55 +    atomic_t ec_denied_count, gt_denied_count; 
   21.56 +    atomic_t ec_cachehit_count, gt_cachehit_count;
   21.57  };
   21.58  
   21.59  /* global acm policy */
   21.60 @@ -63,7 +64,7 @@ enum acm_datatype { DOMAIN };
   21.61  
   21.62  /* defines number of access decisions to other domains can be cached
   21.63   * one entry per domain, TE does not distinguish evtchn or grant_table */
   21.64 -#define ACM_TE_CACHE_SIZE	8
   21.65 +#define ACM_TE_CACHE_SIZE 8
   21.66  enum acm_ste_flag { VALID, FREE };
   21.67  
   21.68  /* cache line:
   21.69 @@ -72,57 +73,67 @@ enum acm_ste_flag { VALID, FREE };
   21.70   *                 on domain cache_line.id
   21.71   */
   21.72  struct acm_ste_cache_line {
   21.73 -	enum acm_ste_flag valid;
   21.74 -	domid_t id;
   21.75 +    enum acm_ste_flag valid;
   21.76 +    domid_t id;
   21.77  };
   21.78  
   21.79  /* general definition of a subject security id */
   21.80  struct acm_ssid_domain {
   21.81 -	enum acm_datatype datatype;		/* type of subject (e.g., partition) */
   21.82 -	ssidref_t	  ssidref;		/* combined security reference */
   21.83 -	void           	  *primary_ssid; 	/* primary policy ssid part (e.g. chinese wall) */
   21.84 -	void	          *secondary_ssid;  	/* secondary policy ssid part (e.g. type enforcement) */
   21.85 -	struct domain     *subject;	       	/* backpointer to subject structure */
   21.86 -	domid_t		  domainid;		/* replicate id */
   21.87 +    enum acm_datatype datatype; /* type of subject (e.g., partition) */
   21.88 +    ssidref_t ssidref;   /* combined security reference */
   21.89 +    void *primary_ssid;   /* primary policy ssid part (e.g. chinese wall) */
   21.90 +    void *secondary_ssid;    /* secondary policy ssid part (e.g. type enforcement) */
   21.91 +    struct domain *subject;     /* backpointer to subject structure */
   21.92 +    domid_t domainid;   /* replicate id */
   21.93  };
   21.94  
   21.95  /* chinese wall ssid type */
   21.96  struct chwall_ssid {
   21.97 -	ssidref_t chwall_ssidref;
   21.98 +    ssidref_t chwall_ssidref;
   21.99  };
  21.100  
  21.101  /* simple type enforcement ssid type */
  21.102  struct ste_ssid {
  21.103 -	ssidref_t ste_ssidref;
  21.104 -	struct acm_ste_cache_line ste_cache[ACM_TE_CACHE_SIZE]; /* decision cache */
  21.105 +    ssidref_t ste_ssidref;
  21.106 +    struct acm_ste_cache_line ste_cache[ACM_TE_CACHE_SIZE]; /* decision cache */
  21.107  };
  21.108  
  21.109  /* macros to access ssidref for primary / secondary policy 
  21.110 - *	primary ssidref   = lower 16 bit
  21.111 - *      secondary ssidref = higher 16 bit
  21.112 + * primary ssidref   = lower 16 bit
  21.113 + *  secondary ssidref = higher 16 bit
  21.114   */
  21.115  #define ACM_PRIMARY(ssidref) \
  21.116 -	((ssidref) & 0xffff)
  21.117 + ((ssidref) & 0xffff)
  21.118  
  21.119  #define ACM_SECONDARY(ssidref) \
  21.120 -	((ssidref) >> 16)
  21.121 + ((ssidref) >> 16)
  21.122  
  21.123  #define GET_SSIDREF(POLICY, ssidref) \
  21.124 -	((POLICY) == acm_bin_pol.primary_policy_code) ? \
  21.125 -	ACM_PRIMARY(ssidref) : ACM_SECONDARY(ssidref)
  21.126 + ((POLICY) == acm_bin_pol.primary_policy_code) ? \
  21.127 + ACM_PRIMARY(ssidref) : ACM_SECONDARY(ssidref)
  21.128  
  21.129  /* macros to access ssid pointer for primary / secondary policy */
  21.130  #define GET_SSIDP(POLICY, ssid) \
  21.131 -	((POLICY) == acm_bin_pol.primary_policy_code) ? \
  21.132 -	((ssid)->primary_ssid) : ((ssid)->secondary_ssid)
  21.133 + ((POLICY) == acm_bin_pol.primary_policy_code) ? \
  21.134 + ((ssid)->primary_ssid) : ((ssid)->secondary_ssid)
  21.135  
  21.136  /* protos */
  21.137  int acm_init_domain_ssid(domid_t id, ssidref_t ssidref);
  21.138 -int acm_free_domain_ssid(struct acm_ssid_domain *ssid);
  21.139 -int acm_set_policy(void *buf, u16 buf_size, int isuserbuffer);
  21.140 -int acm_get_policy(void *buf, u16 buf_size);
  21.141 +void acm_free_domain_ssid(struct acm_ssid_domain *ssid);
  21.142 +int acm_set_policy(void *buf, u32 buf_size, int isuserbuffer);
  21.143 +int acm_get_policy(void *buf, u32 buf_size);
  21.144  int acm_dump_statistics(void *buf, u16 buf_size);
  21.145  int acm_get_ssid(ssidref_t ssidref, u8 *buf, u16 buf_size);
  21.146 +int acm_get_decision(ssidref_t ssidref1, ssidref_t ssidref2, enum acm_hook_type hook);
  21.147  
  21.148  #endif
  21.149  
  21.150 +/*
  21.151 + * Local variables:
  21.152 + * mode: C
  21.153 + * c-set-style: "BSD"
  21.154 + * c-basic-offset: 4
  21.155 + * tab-width: 4
  21.156 + * indent-tabs-mode: nil
  21.157 + * End:
  21.158 + */
    22.1 --- a/xen/include/acm/acm_endian.h	Fri Oct 21 12:06:17 2005 +0100
    22.2 +++ b/xen/include/acm/acm_endian.h	Fri Oct 21 12:07:14 2005 +0100
    22.3 @@ -18,6 +18,7 @@
    22.4   * big-endian policy interface
    22.5   *
    22.6   */
    22.7 +
    22.8  #ifndef _ACM_ENDIAN_H
    22.9  #define _ACM_ENDIAN_H
   22.10  
   22.11 @@ -30,10 +31,10 @@ static inline u32 ntohl(u32 x)
   22.12  {
   22.13      if (little_endian)
   22.14          return 
   22.15 -	    ( (((x) >> 24) & 0xff      )| 
   22.16 -	      (((x) >>  8) & 0xff00    )| 
   22.17 -	      (((x) <<  8) & 0xff0000  )|
   22.18 -	      (((x) << 24) & 0xff000000) );
   22.19 +            ( (((x) >> 24) & 0xff      )| 
   22.20 +              (((x) >>  8) & 0xff00    )| 
   22.21 +              (((x) <<  8) & 0xff0000  )|
   22.22 +              (((x) << 24) & 0xff000000) );
   22.23      else
   22.24          return x;
   22.25  }
   22.26 @@ -42,10 +43,10 @@ static inline u16 ntohs(u16 x)
   22.27  {
   22.28      if (little_endian)
   22.29          return 
   22.30 -	    ( (((x) >> 8) & 0xff   )|
   22.31 -	      (((x) << 8) & 0xff00 ) );
   22.32 +            ( (((x) >> 8) & 0xff   )|
   22.33 +              (((x) << 8) & 0xff00 ) );
   22.34      else
   22.35 -	return x;
   22.36 +        return x;
   22.37  }
   22.38  
   22.39  #define htonl(x) ntohl(x)
   22.40 @@ -55,8 +56,8 @@ static inline void arrcpy16(u16 *dest, c
   22.41  {
   22.42      unsigned int i = 0;
   22.43      while (i < n) {
   22.44 -       	dest[i] = htons(src[i]);
   22.45 -       	i++;
   22.46 +        dest[i] = htons(src[i]);
   22.47 +        i++;
   22.48      }
   22.49  }
   22.50  
   22.51 @@ -64,8 +65,8 @@ static inline void arrcpy32(u32 *dest, c
   22.52  {
   22.53      unsigned int i = 0;
   22.54      while (i < n) {
   22.55 -	dest[i] = htonl(src[i]);
   22.56 -	i++;
   22.57 +        dest[i] = htonl(src[i]);
   22.58 +        i++;
   22.59      }
   22.60  }
   22.61  
   22.62 @@ -86,3 +87,13 @@ static inline void arrcpy(void *dest, co
   22.63  }
   22.64  
   22.65  #endif
   22.66 +
   22.67 +/*
   22.68 + * Local variables:
   22.69 + * mode: C
   22.70 + * c-set-style: "BSD"
   22.71 + * c-basic-offset: 4
   22.72 + * tab-width: 4
   22.73 + * indent-tabs-mode: nil
   22.74 + * End:
   22.75 + */
    23.1 --- a/xen/include/acm/acm_hooks.h	Fri Oct 21 12:06:17 2005 +0100
    23.2 +++ b/xen/include/acm/acm_hooks.h	Fri Oct 21 12:07:14 2005 +0100
    23.3 @@ -15,6 +15,7 @@
    23.4   *      sHype hooks that are called throughout Xen.
    23.5   * 
    23.6   */
    23.7 +
    23.8  #ifndef _ACM_HOOKS_H
    23.9  #define _ACM_HOOKS_H
   23.10  
   23.11 @@ -89,8 +90,8 @@ struct acm_operations {
   23.12      /* policy management functions (must always be defined!) */
   23.13      int  (*init_domain_ssid)           (void **ssid, ssidref_t ssidref);
   23.14      void (*free_domain_ssid)           (void *ssid);
   23.15 -    int  (*dump_binary_policy)         (u8 *buffer, u16 buf_size);
   23.16 -    int  (*set_binary_policy)          (u8 *buffer, u16 buf_size);
   23.17 +    int  (*dump_binary_policy)         (u8 *buffer, u32 buf_size);
   23.18 +    int  (*set_binary_policy)          (u8 *buffer, u32 buf_size);
   23.19      int  (*dump_statistics)            (u8 *buffer, u16 buf_size);
   23.20      int  (*dump_ssid_types)            (ssidref_t ssidref, u8 *buffer, u16 buf_size);
   23.21      /* domain management control hooks (can be NULL) */
   23.22 @@ -108,6 +109,8 @@ struct acm_operations {
   23.23      void (*fail_grant_map_ref)         (domid_t id);
   23.24      int  (*pre_grant_setup)            (domid_t id);
   23.25      void (*fail_grant_setup)           (domid_t id);
   23.26 +    /* generic domain-requested decision hooks (can be NULL) */
   23.27 +    int (*sharing)                     (ssidref_t ssidref1, ssidref_t ssidref2);
   23.28  };
   23.29  
   23.30  /* global variables */
   23.31 @@ -144,6 +147,8 @@ static inline int acm_init(unsigned int 
   23.32  { return 0; }
   23.33  static inline void acm_post_domain0_create(domid_t domid) 
   23.34  { return; }
   23.35 +static inline int acm_sharing(ssidref_t ssidref1, ssidref_t ssidref2)
   23.36 +{ return 0; }
   23.37  
   23.38  #else
   23.39  
   23.40 @@ -281,7 +286,8 @@ static inline int acm_pre_event_channel(
   23.41          break;
   23.42      case EVTCHNOP_bind_interdomain:
   23.43          ret = acm_pre_eventchannel_interdomain(
   23.44 -            op->u.bind_interdomain.dom1, op->u.bind_interdomain.dom2);
   23.45 +            current->domain->domain_id,
   23.46 +            op->u.bind_interdomain.remote_dom);
   23.47          break;
   23.48      default:
   23.49          ret = 0; /* ok */
   23.50 @@ -341,6 +347,18 @@ static inline void acm_post_domain0_crea
   23.51      acm_post_domain_create(domid, ACM_DOM0_SSIDREF);
   23.52  }
   23.53  
   23.54 +static inline int acm_sharing(ssidref_t ssidref1, ssidref_t ssidref2)
   23.55 +{
   23.56 +    if ((acm_primary_ops->sharing != NULL) &&
   23.57 +        acm_primary_ops->sharing(ssidref1, ssidref2))
   23.58 +        return ACM_ACCESS_DENIED;
   23.59 +    else if ((acm_secondary_ops->sharing != NULL) &&
   23.60 +             acm_secondary_ops->sharing(ssidref1, ssidref2)) {
   23.61 +        return ACM_ACCESS_DENIED;
   23.62 +    } else
   23.63 +        return ACM_ACCESS_PERMITTED;
   23.64 +}
   23.65 +
   23.66  extern int acm_init(unsigned int *initrdidx,
   23.67                      const multiboot_info_t *mbi,
   23.68                      unsigned long start);
   23.69 @@ -348,3 +366,13 @@ extern int acm_init(unsigned int *initrd
   23.70  #endif
   23.71  
   23.72  #endif
   23.73 +
   23.74 +/*
   23.75 + * Local variables:
   23.76 + * mode: C
   23.77 + * c-set-style: "BSD"
   23.78 + * c-basic-offset: 4
   23.79 + * tab-width: 4
   23.80 + * indent-tabs-mode: nil
   23.81 + * End:
   23.82 + */
    24.1 --- a/xen/include/public/acm.h	Fri Oct 21 12:06:17 2005 +0100
    24.2 +++ b/xen/include/public/acm.h	Fri Oct 21 12:07:14 2005 +0100
    24.3 @@ -52,9 +52,9 @@
    24.4  #define ACM_ERROR          -4
    24.5  
    24.6  /* External ACCESS DECISIONS */
    24.7 -#define ACM_ACCESS_PERMITTED  0
    24.8 -#define ACM_ACCESS_DENIED  -111
    24.9 -#define ACM_NULL_POINTER_ERROR  -200
   24.10 +#define ACM_ACCESS_PERMITTED        0
   24.11 +#define ACM_ACCESS_DENIED           -111
   24.12 +#define ACM_NULL_POINTER_ERROR      -200
   24.13  
   24.14  /* primary policy in lower 4 bits */
   24.15  #define ACM_NULL_POLICY 0
   24.16 @@ -84,6 +84,9 @@
   24.17  /* defines a ssid reference used by xen */
   24.18  typedef uint32_t ssidref_t;
   24.19  
   24.20 +/* hooks that are known to domains */
   24.21 +enum acm_hook_type {NONE=0, SHARING};
   24.22 +
   24.23  /* -------security policy relevant type definitions-------- */
   24.24  
   24.25  /* type identifier; compares to "equal" or "not equal" */
    25.1 --- a/xen/include/public/acm_ops.h	Fri Oct 21 12:06:17 2005 +0100
    25.2 +++ b/xen/include/public/acm_ops.h	Fri Oct 21 12:07:14 2005 +0100
    25.3 @@ -27,36 +27,36 @@
    25.4   * This makes sure that old versions of acm tools will stop working in a
    25.5   * well-defined way (rather than crashing the machine, for instance).
    25.6   */
    25.7 -#define ACM_INTERFACE_VERSION   0xAAAA0004
    25.8 +#define ACM_INTERFACE_VERSION   0xAAAA0005
    25.9  
   25.10  /************************************************************************/
   25.11  
   25.12  #define ACM_SETPOLICY         4
   25.13 -typedef struct acm_setpolicy {
   25.14 +struct acm_setpolicy {
   25.15      /* OUT variables */
   25.16      void *pushcache;
   25.17 -    uint16_t pushcache_size;
   25.18 -} acm_setpolicy_t;
   25.19 +    uint32_t pushcache_size;
   25.20 +};
   25.21  
   25.22  
   25.23  #define ACM_GETPOLICY         5
   25.24 -typedef struct acm_getpolicy {
   25.25 +struct acm_getpolicy {
   25.26      /* OUT variables */
   25.27      void *pullcache;
   25.28 -    uint16_t pullcache_size;
   25.29 -} acm_getpolicy_t;
   25.30 +    uint32_t pullcache_size;
   25.31 +};
   25.32  
   25.33  
   25.34  #define ACM_DUMPSTATS         6
   25.35 -typedef struct acm_dumpstats {
   25.36 +struct acm_dumpstats {
   25.37      void *pullcache;
   25.38 -    uint16_t pullcache_size;
   25.39 -} acm_dumpstats_t;
   25.40 +    uint32_t pullcache_size;
   25.41 +};
   25.42  
   25.43  
   25.44  #define ACM_GETSSID           7
   25.45 -enum get_type {UNSET, SSIDREF, DOMAINID};
   25.46 -typedef struct acm_getssid {
   25.47 +enum get_type {UNSET=0, SSIDREF, DOMAINID};
   25.48 +struct acm_getssid {
   25.49      enum get_type get_ssid_by;
   25.50      union {
   25.51          domaintype_t domainid;
   25.52 @@ -64,18 +64,35 @@ typedef struct acm_getssid {
   25.53      } id;
   25.54      void *ssidbuf;
   25.55      uint16_t ssidbuf_size;
   25.56 -} acm_getssid_t;
   25.57 +};
   25.58  
   25.59 -typedef struct acm_op {
   25.60 +#define ACM_GETDECISION        8
   25.61 +struct acm_getdecision {
   25.62 +    enum get_type get_decision_by1; /* in */
   25.63 +    enum get_type get_decision_by2;
   25.64 +    union {
   25.65 +        domaintype_t domainid;
   25.66 +        ssidref_t    ssidref;
   25.67 +    } id1;
   25.68 +    union {
   25.69 +        domaintype_t domainid;
   25.70 +        ssidref_t    ssidref;
   25.71 +    } id2;
   25.72 +    enum acm_hook_type hook;
   25.73 +    int acm_decision;           /* out */
   25.74 +};
   25.75 +
   25.76 +struct acm_op {
   25.77      uint32_t cmd;
   25.78      uint32_t interface_version;      /* ACM_INTERFACE_VERSION */
   25.79      union {
   25.80 -        acm_setpolicy_t setpolicy;
   25.81 -        acm_getpolicy_t getpolicy;
   25.82 -        acm_dumpstats_t dumpstats;
   25.83 -        acm_getssid_t getssid;
   25.84 +        struct acm_setpolicy setpolicy;
   25.85 +        struct acm_getpolicy getpolicy;
   25.86 +        struct acm_dumpstats dumpstats;
   25.87 +        struct acm_getssid getssid;
   25.88 +        struct acm_getdecision getdecision;
   25.89      } u;
   25.90 -} acm_op_t;
   25.91 +};
   25.92  
   25.93  #endif                          /* __XEN_PUBLIC_ACM_OPS_H__ */
   25.94