Gentoo Archives: gentoo-commits

From: "Gordon Malm (gengor)" <gengor@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r1485 - in hardened/2.6/tags: . 2.6.27-8
Date: Sun, 25 Jan 2009 09:02:50
Message-Id: E1LR0s0-0007YW-4v@stork.gentoo.org
1 Author: gengor
2 Date: 2009-01-25 09:01:31 +0000 (Sun, 25 Jan 2009)
3 New Revision: 1485
4
5 Added:
6 hardened/2.6/tags/2.6.27-8/
7 hardened/2.6/tags/2.6.27-8/0000_README
8 hardened/2.6/tags/2.6.27-8/1012_linux-2.6.27.13.patch
9 hardened/2.6/tags/2.6.27-8/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
10 hardened/2.6/tags/2.6.27-8/4421_grsec-remove-localversion-grsec.patch
11 hardened/2.6/tags/2.6.27-8/4422_grsec-mute-warnings.patch
12 hardened/2.6/tags/2.6.27-8/4425_grsec-pax-without-grsec.patch
13 hardened/2.6/tags/2.6.27-8/4430_grsec-kconfig-default-gids.patch
14 hardened/2.6/tags/2.6.27-8/4435_grsec-kconfig-gentoo.patch
15 hardened/2.6/tags/2.6.27-8/4440_selinux-avc_audit-log-curr_ip.patch
16 hardened/2.6/tags/2.6.27-8/4445_disable-compat_vdso.patch
17 hardened/2.6/tags/2.6.27-8/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
18 hardened/2.6/tags/2.6.27-8/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
19 Log:
20 Tag 2.6.27-8 hardened-extras patchset
21
22 Added: hardened/2.6/tags/2.6.27-8/0000_README
23 ===================================================================
24 --- hardened/2.6/tags/2.6.27-8/0000_README (rev 0)
25 +++ hardened/2.6/tags/2.6.27-8/0000_README 2009-01-25 09:01:31 UTC (rev 1485)
26 @@ -0,0 +1,54 @@
27 +README
28 +-----------------------------------------------------------------------------
29 +
30 +Individual Patch Descriptions:
31 +-----------------------------------------------------------------------------
32 +Patch: 1012_linux-2.6.27.13.patch
33 +From: http://www.kernel.org
34 +Desc: Linux 2.6.27.13
35 +
36 +Patch: 4420_grsec-2.1.12-2.6.27.10-200812271347.patch
37 +From: http://www.grsecurity.net
38 +Desc: hardened-sources base patch from upstream grsecurity
39 +
40 +Patch: 4421_grsec-remove-localversion-grsec.patch
41 +From: Kerin Millar <kerframil@×××××.com>
42 +Desc: Removes grsecurity's localversion-grsec file
43 +
44 +Patch: 4422_grsec-mute-warnings.patch
45 +From: Alexander Gabert <gaberta@××××××××.de>
46 + Gordon Malm <gengor@g.o>
47 +Desc: Removes verbose compile warning settings from grsecurity, restores
48 + mainline Linux kernel behavior
49 +
50 +Patch: 4425_grsec-pax-without-grsec.patch
51 +From: Gordon Malm <gengor@g.o>
52 +Desc: Allows PaX features to be selected without enabling GRKERNSEC
53 +
54 +Patch: 4430_grsec-kconfig-default-gids.patch
55 +From: Kerin Millar <kerframil@×××××.com>
56 +Desc: Sets sane(r) default GIDs on various grsecurity group-dependent
57 + features
58 +
59 +Patch: 4435_grsec-kconfig-gentoo.patch
60 +From: Gordon Malm <gengor@g.o>
61 + Kerin Millar <kerframil@×××××.com>
62 +Desc: Adds Hardened Gentoo [server/workstation] security levels, sets
63 + Hardened Gentoo [workstation] as default
64 +
65 +Patch: 4440_selinux-avc_audit-log-curr_ip.patch
66 +From: Gordon Malm <gengor@g.o>
67 +Desc: Configurable option to add src IP address to SELinux log messages
68 +
69 +Patch: 4445_disable-compat_vdso.patch
70 +From: Gordon Malm <gengor@g.o>
71 + Kerin Millar <kerframil@×××××.com>
72 +Desc: Disables VDSO_COMPAT operation completely
73 +
74 +Patch: 4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
75 +From: Gordon Malm <gengor@g.o>
76 +Desc: Add offender's IP to PAX_REFCOUNT log messages if it is available
77 +
78 +Patch: 4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
79 +From: Gordon Malm <gengor@g.o>
80 +Desc: Revert RLIMIT_STACK false-positives-avoidance change in PaX
81
82 Added: hardened/2.6/tags/2.6.27-8/1012_linux-2.6.27.13.patch
83 ===================================================================
84 --- hardened/2.6/tags/2.6.27-8/1012_linux-2.6.27.13.patch (rev 0)
85 +++ hardened/2.6/tags/2.6.27-8/1012_linux-2.6.27.13.patch 2009-01-25 09:01:31 UTC (rev 1485)
86 @@ -0,0 +1,1730 @@
87 +diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
88 +index b117e42..90f718c 100644
89 +--- a/Documentation/sound/alsa/ALSA-Configuration.txt
90 ++++ b/Documentation/sound/alsa/ALSA-Configuration.txt
91 +@@ -960,9 +960,10 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
92 + 6stack 6-jack, separate surrounds (default)
93 + 3stack 3-stack, shared surrounds
94 + laptop 2-channel only (FSC V2060, Samsung M50)
95 +- laptop-eapd 2-channel with EAPD (Samsung R65, ASUS A6J)
96 ++ laptop-eapd 2-channel with EAPD (ASUS A6J)
97 + laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100)
98 + ultra 2-channel with EAPD (Samsung Ultra tablet PC)
99 ++ samsung 2-channel with EAPD (Samsung R65)
100 +
101 + AD1988/AD1988B/AD1989A/AD1989B
102 + 6stack 6-jack
103 +diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
104 +index 48e496f..fb7e69c 100644
105 +--- a/arch/ia64/Kconfig
106 ++++ b/arch/ia64/Kconfig
107 +@@ -15,6 +15,7 @@ config IA64
108 + select ACPI if (!IA64_HP_SIM)
109 + select PM if (!IA64_HP_SIM)
110 + select ARCH_SUPPORTS_MSI
111 ++ select HAVE_UNSTABLE_SCHED_CLOCK
112 + select HAVE_IDE
113 + select HAVE_OPROFILE
114 + select HAVE_KPROBES
115 +diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
116 +index db44e02..ba51948 100644
117 +--- a/arch/powerpc/mm/slice.c
118 ++++ b/arch/powerpc/mm/slice.c
119 +@@ -710,9 +710,18 @@ int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
120 + unsigned long len)
121 + {
122 + struct slice_mask mask, available;
123 ++ unsigned int psize = mm->context.user_psize;
124 +
125 + mask = slice_range_to_mask(addr, len);
126 +- available = slice_mask_for_size(mm, mm->context.user_psize);
127 ++ available = slice_mask_for_size(mm, psize);
128 ++#ifdef CONFIG_PPC_64K_PAGES
129 ++ /* We need to account for 4k slices too */
130 ++ if (psize == MMU_PAGE_64K) {
131 ++ struct slice_mask compat_mask;
132 ++ compat_mask = slice_mask_for_size(mm, MMU_PAGE_4K);
133 ++ or_mask(available, compat_mask);
134 ++ }
135 ++#endif
136 +
137 + #if 0 /* too verbose */
138 + slice_dbg("is_hugepage_only_range(mm=%p, addr=%lx, len=%lx)\n",
139 +diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
140 +index 13946eb..b4704e1 100644
141 +--- a/drivers/firmware/dell_rbu.c
142 ++++ b/drivers/firmware/dell_rbu.c
143 +@@ -576,7 +576,7 @@ static ssize_t read_rbu_image_type(struct kobject *kobj,
144 + {
145 + int size = 0;
146 + if (!pos)
147 +- size = sprintf(buffer, "%s\n", image_type);
148 ++ size = scnprintf(buffer, count, "%s\n", image_type);
149 + return size;
150 + }
151 +
152 +@@ -648,7 +648,7 @@ static ssize_t read_rbu_packet_size(struct kobject *kobj,
153 + int size = 0;
154 + if (!pos) {
155 + spin_lock(&rbu_data.lock);
156 +- size = sprintf(buffer, "%lu\n", rbu_data.packetsize);
157 ++ size = scnprintf(buffer, count, "%lu\n", rbu_data.packetsize);
158 + spin_unlock(&rbu_data.lock);
159 + }
160 + return size;
161 +diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
162 +index d9e7a49..58a5efb 100644
163 +--- a/drivers/hwmon/abituguru3.c
164 ++++ b/drivers/hwmon/abituguru3.c
165 +@@ -1153,7 +1153,7 @@ static int __init abituguru3_dmi_detect(void)
166 +
167 + static inline int abituguru3_dmi_detect(void)
168 + {
169 +- return -ENODEV;
170 ++ return 1;
171 + }
172 +
173 + #endif /* CONFIG_DMI */
174 +diff --git a/drivers/hwmon/hwmon-vid.c b/drivers/hwmon/hwmon-vid.c
175 +index c54eff9..bfc2961 100644
176 +--- a/drivers/hwmon/hwmon-vid.c
177 ++++ b/drivers/hwmon/hwmon-vid.c
178 +@@ -180,6 +180,7 @@ static struct vrm_model vrm_models[] = {
179 + {X86_VENDOR_AMD, 0x6, ANY, ANY, 90}, /* Athlon Duron etc */
180 + {X86_VENDOR_AMD, 0xF, 0x3F, ANY, 24}, /* Athlon 64, Opteron */
181 + {X86_VENDOR_AMD, 0xF, ANY, ANY, 25}, /* NPT family 0Fh */
182 ++ {X86_VENDOR_AMD, 0x10, ANY, ANY, 25}, /* NPT family 10h */
183 + {X86_VENDOR_INTEL, 0x6, 0x9, ANY, 13}, /* Pentium M (130 nm) */
184 + {X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */
185 + {X86_VENDOR_INTEL, 0x6, 0xD, ANY, 13}, /* Pentium M (90 nm) */
186 +diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
187 +index b4882cc..d32c1ee 100644
188 +--- a/drivers/misc/sgi-xp/xpc_sn2.c
189 ++++ b/drivers/misc/sgi-xp/xpc_sn2.c
190 +@@ -904,7 +904,7 @@ xpc_update_partition_info_sn2(struct xpc_partition *part, u8 remote_rp_version,
191 + dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
192 + part_sn2->remote_vars_pa);
193 +
194 +- part->last_heartbeat = remote_vars->heartbeat;
195 ++ part->last_heartbeat = remote_vars->heartbeat - 1;
196 + dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
197 + part->last_heartbeat);
198 +
199 +diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
200 +index b5d6b9a..b427978 100644
201 +--- a/drivers/net/irda/irda-usb.c
202 ++++ b/drivers/net/irda/irda-usb.c
203 +@@ -1075,7 +1075,7 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
204 + {
205 + unsigned int i;
206 + int ret;
207 +- char stir421x_fw_name[11];
208 ++ char stir421x_fw_name[12];
209 + const struct firmware *fw;
210 + const unsigned char *fw_version_ptr; /* pointer to version string */
211 + unsigned long fw_version = 0;
212 +diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c
213 +index 5d86281..c71982d 100644
214 +--- a/drivers/net/r6040.c
215 ++++ b/drivers/net/r6040.c
216 +@@ -49,8 +49,8 @@
217 + #include <asm/processor.h>
218 +
219 + #define DRV_NAME "r6040"
220 +-#define DRV_VERSION "0.18"
221 +-#define DRV_RELDATE "13Jul2008"
222 ++#define DRV_VERSION "0.19"
223 ++#define DRV_RELDATE "18Dec2008"
224 +
225 + /* PHY CHIP Address */
226 + #define PHY1_ADDR 1 /* For MAC1 */
227 +@@ -214,7 +214,7 @@ static int r6040_phy_read(void __iomem *ioaddr, int phy_addr, int reg)
228 + /* Wait for the read bit to be cleared */
229 + while (limit--) {
230 + cmd = ioread16(ioaddr + MMDIO);
231 +- if (cmd & MDIO_READ)
232 ++ if (!(cmd & MDIO_READ))
233 + break;
234 + }
235 +
236 +@@ -233,7 +233,7 @@ static void r6040_phy_write(void __iomem *ioaddr, int phy_addr, int reg, u16 val
237 + /* Wait for the write bit to be cleared */
238 + while (limit--) {
239 + cmd = ioread16(ioaddr + MMDIO);
240 +- if (cmd & MDIO_WRITE)
241 ++ if (!(cmd & MDIO_WRITE))
242 + break;
243 + }
244 + }
245 +@@ -681,8 +681,10 @@ static irqreturn_t r6040_interrupt(int irq, void *dev_id)
246 + struct net_device *dev = dev_id;
247 + struct r6040_private *lp = netdev_priv(dev);
248 + void __iomem *ioaddr = lp->base;
249 +- u16 status;
250 ++ u16 misr, status;
251 +
252 ++ /* Save MIER */
253 ++ misr = ioread16(ioaddr + MIER);
254 + /* Mask off RDC MAC interrupt */
255 + iowrite16(MSK_INT, ioaddr + MIER);
256 + /* Read MISR status and clear */
257 +@@ -702,7 +704,7 @@ static irqreturn_t r6040_interrupt(int irq, void *dev_id)
258 + dev->stats.rx_fifo_errors++;
259 +
260 + /* Mask off RX interrupt */
261 +- iowrite16(ioread16(ioaddr + MIER) & ~RX_INTS, ioaddr + MIER);
262 ++ misr &= ~RX_INTS;
263 + netif_rx_schedule(dev, &lp->napi);
264 + }
265 +
266 +@@ -710,6 +712,9 @@ static irqreturn_t r6040_interrupt(int irq, void *dev_id)
267 + if (status & TX_INTS)
268 + r6040_tx(dev);
269 +
270 ++ /* Restore RDC MAC interrupt */
271 ++ iowrite16(misr, ioaddr + MIER);
272 ++
273 + return IRQ_HANDLED;
274 + }
275 +
276 +diff --git a/drivers/net/wireless/ath9k/hw.c b/drivers/net/wireless/ath9k/hw.c
277 +index 6dbfed0..69120b5 100644
278 +--- a/drivers/net/wireless/ath9k/hw.c
279 ++++ b/drivers/net/wireless/ath9k/hw.c
280 +@@ -729,7 +729,7 @@ ath9k_hw_eeprom_set_board_values(struct ath_hal *ah,
281 + AR_AN_TOP2_LOCALBIAS,
282 + AR_AN_TOP2_LOCALBIAS_S,
283 + pModal->local_bias);
284 +- DPRINTF(ah->ah_sc, ATH_DBG_ANY, "ForceXPAon: %d\n",
285 ++ DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "ForceXPAon: %d\n",
286 + pModal->force_xpaon);
287 + REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
288 + pModal->force_xpaon);
289 +diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
290 +index cbaca23..bfff6b5 100644
291 +--- a/drivers/net/wireless/p54/p54usb.c
292 ++++ b/drivers/net/wireless/p54/p54usb.c
293 +@@ -53,6 +53,7 @@ static struct usb_device_id p54u_table[] __devinitdata = {
294 + {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */
295 + {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */
296 + {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */
297 ++ {USB_DEVICE(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */
298 + {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */
299 + {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */
300 + {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */
301 +diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
302 +index 9761eaa..45bf8f7 100644
303 +--- a/drivers/net/wireless/rt2x00/rt73usb.c
304 ++++ b/drivers/net/wireless/rt2x00/rt73usb.c
305 +@@ -2113,6 +2113,7 @@ static struct usb_device_id rt73usb_device_table[] = {
306 + /* Linksys */
307 + { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) },
308 + { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
309 ++ { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops) },
310 + /* MSI */
311 + { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
312 + { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
313 +diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
314 +index aa6fda1..8a82a62 100644
315 +--- a/drivers/pci/pcie/aspm.c
316 ++++ b/drivers/pci/pcie/aspm.c
317 +@@ -33,6 +33,11 @@ struct endpoint_state {
318 + struct pcie_link_state {
319 + struct list_head sibiling;
320 + struct pci_dev *pdev;
321 ++ bool downstream_has_switch;
322 ++
323 ++ struct pcie_link_state *parent;
324 ++ struct list_head children;
325 ++ struct list_head link;
326 +
327 + /* ASPM state */
328 + unsigned int support_state;
329 +@@ -125,7 +130,7 @@ static void pcie_set_clock_pm(struct pci_dev *pdev, int enable)
330 + link_state->clk_pm_enabled = !!enable;
331 + }
332 +
333 +-static void pcie_check_clock_pm(struct pci_dev *pdev)
334 ++static void pcie_check_clock_pm(struct pci_dev *pdev, int blacklist)
335 + {
336 + int pos;
337 + u32 reg32;
338 +@@ -149,10 +154,26 @@ static void pcie_check_clock_pm(struct pci_dev *pdev)
339 + if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN))
340 + enabled = 0;
341 + }
342 +- link_state->clk_pm_capable = capable;
343 + link_state->clk_pm_enabled = enabled;
344 + link_state->bios_clk_state = enabled;
345 +- pcie_set_clock_pm(pdev, policy_to_clkpm_state(pdev));
346 ++ if (!blacklist) {
347 ++ link_state->clk_pm_capable = capable;
348 ++ pcie_set_clock_pm(pdev, policy_to_clkpm_state(pdev));
349 ++ } else {
350 ++ link_state->clk_pm_capable = 0;
351 ++ pcie_set_clock_pm(pdev, 0);
352 ++ }
353 ++}
354 ++
355 ++static bool pcie_aspm_downstream_has_switch(struct pci_dev *pdev)
356 ++{
357 ++ struct pci_dev *child_dev;
358 ++
359 ++ list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
360 ++ if (child_dev->pcie_type == PCI_EXP_TYPE_UPSTREAM)
361 ++ return true;
362 ++ }
363 ++ return false;
364 + }
365 +
366 + /*
367 +@@ -419,9 +440,9 @@ static unsigned int pcie_aspm_check_state(struct pci_dev *pdev,
368 + {
369 + struct pci_dev *child_dev;
370 +
371 +- /* If no child, disable the link */
372 ++ /* If no child, ignore the link */
373 + if (list_empty(&pdev->subordinate->devices))
374 +- return 0;
375 ++ return state;
376 + list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
377 + if (child_dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
378 + /*
379 +@@ -462,6 +483,9 @@ static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state)
380 + int valid = 1;
381 + struct pcie_link_state *link_state = pdev->link_state;
382 +
383 ++ /* If no child, disable the link */
384 ++ if (list_empty(&pdev->subordinate->devices))
385 ++ state = 0;
386 + /*
387 + * if the downstream component has pci bridge function, don't do ASPM
388 + * now
389 +@@ -493,20 +517,52 @@ static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state)
390 + link_state->enabled_state = state;
391 + }
392 +
393 ++static struct pcie_link_state *get_root_port_link(struct pcie_link_state *link)
394 ++{
395 ++ struct pcie_link_state *root_port_link = link;
396 ++ while (root_port_link->parent)
397 ++ root_port_link = root_port_link->parent;
398 ++ return root_port_link;
399 ++}
400 ++
401 ++/* check the whole hierarchy, and configure each link in the hierarchy */
402 + static void __pcie_aspm_configure_link_state(struct pci_dev *pdev,
403 + unsigned int state)
404 + {
405 + struct pcie_link_state *link_state = pdev->link_state;
406 ++ struct pcie_link_state *root_port_link = get_root_port_link(link_state);
407 ++ struct pcie_link_state *leaf;
408 +
409 +- if (link_state->support_state == 0)
410 +- return;
411 + state &= PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1;
412 +
413 +- /* state 0 means disabling aspm */
414 +- state = pcie_aspm_check_state(pdev, state);
415 ++ /* check all links who have specific root port link */
416 ++ list_for_each_entry(leaf, &link_list, sibiling) {
417 ++ if (!list_empty(&leaf->children) ||
418 ++ get_root_port_link(leaf) != root_port_link)
419 ++ continue;
420 ++ state = pcie_aspm_check_state(leaf->pdev, state);
421 ++ }
422 ++ /* check root port link too in case it hasn't children */
423 ++ state = pcie_aspm_check_state(root_port_link->pdev, state);
424 ++
425 + if (link_state->enabled_state == state)
426 + return;
427 +- __pcie_aspm_config_link(pdev, state);
428 ++
429 ++ /*
430 ++ * we must change the hierarchy. See comments in
431 ++ * __pcie_aspm_config_link for the order
432 ++ **/
433 ++ if (state & PCIE_LINK_STATE_L1) {
434 ++ list_for_each_entry(leaf, &link_list, sibiling) {
435 ++ if (get_root_port_link(leaf) == root_port_link)
436 ++ __pcie_aspm_config_link(leaf->pdev, state);
437 ++ }
438 ++ } else {
439 ++ list_for_each_entry_reverse(leaf, &link_list, sibiling) {
440 ++ if (get_root_port_link(leaf) == root_port_link)
441 ++ __pcie_aspm_config_link(leaf->pdev, state);
442 ++ }
443 ++ }
444 + }
445 +
446 + /*
447 +@@ -570,6 +626,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
448 + unsigned int state;
449 + struct pcie_link_state *link_state;
450 + int error = 0;
451 ++ int blacklist;
452 +
453 + if (aspm_disabled || !pdev->is_pcie || pdev->link_state)
454 + return;
455 +@@ -580,29 +637,58 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
456 + if (list_empty(&pdev->subordinate->devices))
457 + goto out;
458 +
459 +- if (pcie_aspm_sanity_check(pdev))
460 +- goto out;
461 ++ blacklist = !!pcie_aspm_sanity_check(pdev);
462 +
463 + mutex_lock(&aspm_lock);
464 +
465 + link_state = kzalloc(sizeof(*link_state), GFP_KERNEL);
466 + if (!link_state)
467 + goto unlock_out;
468 +- pdev->link_state = link_state;
469 +
470 +- pcie_aspm_configure_common_clock(pdev);
471 ++ link_state->downstream_has_switch = pcie_aspm_downstream_has_switch(pdev);
472 ++ INIT_LIST_HEAD(&link_state->children);
473 ++ INIT_LIST_HEAD(&link_state->link);
474 ++ if (pdev->bus->self) {/* this is a switch */
475 ++ struct pcie_link_state *parent_link_state;
476 +
477 +- pcie_aspm_cap_init(pdev);
478 ++ parent_link_state = pdev->bus->parent->self->link_state;
479 ++ if (!parent_link_state) {
480 ++ kfree(link_state);
481 ++ goto unlock_out;
482 ++ }
483 ++ list_add(&link_state->link, &parent_link_state->children);
484 ++ link_state->parent = parent_link_state;
485 ++ }
486 +
487 +- /* config link state to avoid BIOS error */
488 +- state = pcie_aspm_check_state(pdev, policy_to_aspm_state(pdev));
489 +- __pcie_aspm_config_link(pdev, state);
490 ++ pdev->link_state = link_state;
491 +
492 +- pcie_check_clock_pm(pdev);
493 ++ if (!blacklist) {
494 ++ pcie_aspm_configure_common_clock(pdev);
495 ++ pcie_aspm_cap_init(pdev);
496 ++ } else {
497 ++ link_state->enabled_state = PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1;
498 ++ link_state->bios_aspm_state = 0;
499 ++ /* Set support state to 0, so we will disable ASPM later */
500 ++ link_state->support_state = 0;
501 ++ }
502 +
503 + link_state->pdev = pdev;
504 + list_add(&link_state->sibiling, &link_list);
505 +
506 ++ if (link_state->downstream_has_switch) {
507 ++ /*
508 ++ * If link has switch, delay the link config. The leaf link
509 ++ * initialization will config the whole hierarchy. but we must
510 ++ * make sure BIOS doesn't set unsupported link state
511 ++ **/
512 ++ state = pcie_aspm_check_state(pdev, link_state->bios_aspm_state);
513 ++ __pcie_aspm_config_link(pdev, state);
514 ++ } else
515 ++ __pcie_aspm_configure_link_state(pdev,
516 ++ policy_to_aspm_state(pdev));
517 ++
518 ++ pcie_check_clock_pm(pdev, blacklist);
519 ++
520 + unlock_out:
521 + if (error)
522 + free_link_state(pdev);
523 +@@ -635,6 +721,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
524 + /* All functions are removed, so just disable ASPM for the link */
525 + __pcie_aspm_config_one_dev(parent, 0);
526 + list_del(&link_state->sibiling);
527 ++ list_del(&link_state->link);
528 + /* Clock PM is for endpoint device */
529 +
530 + free_link_state(parent);
531 +diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c
532 +index d617e8a..f970b27 100644
533 +--- a/drivers/usb/storage/libusual.c
534 ++++ b/drivers/usb/storage/libusual.c
535 +@@ -46,6 +46,12 @@ static int usu_probe_thread(void *arg);
536 + { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
537 + .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
538 +
539 ++#define COMPLIANT_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
540 ++ vendorName, productName, useProtocol, useTransport, \
541 ++ initFunction, flags) \
542 ++{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
543 ++ .driver_info = (flags) }
544 ++
545 + #define USUAL_DEV(useProto, useTrans, useType) \
546 + { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
547 + .driver_info = ((useType)<<24) }
548 +@@ -57,6 +63,7 @@ struct usb_device_id storage_usb_ids [] = {
549 +
550 + #undef USUAL_DEV
551 + #undef UNUSUAL_DEV
552 ++#undef COMPLIANT_DEV
553 +
554 + MODULE_DEVICE_TABLE(usb, storage_usb_ids);
555 + EXPORT_SYMBOL_GPL(storage_usb_ids);
556 +diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
557 +index 09779f6..620c2b5 100644
558 +--- a/drivers/usb/storage/scsiglue.c
559 ++++ b/drivers/usb/storage/scsiglue.c
560 +@@ -59,6 +59,13 @@
561 + #include "transport.h"
562 + #include "protocol.h"
563 +
564 ++/* Vendor IDs for companies that seem to include the READ CAPACITY bug
565 ++ * in all their devices
566 ++ */
567 ++#define VENDOR_ID_NOKIA 0x0421
568 ++#define VENDOR_ID_NIKON 0x04b0
569 ++#define VENDOR_ID_MOTOROLA 0x22b8
570 ++
571 + /***********************************************************************
572 + * Host functions
573 + ***********************************************************************/
574 +@@ -134,6 +141,22 @@ static int slave_configure(struct scsi_device *sdev)
575 + * settings can't be overridden via the scsi devinfo mechanism. */
576 + if (sdev->type == TYPE_DISK) {
577 +
578 ++ /* Some vendors seem to put the READ CAPACITY bug into
579 ++ * all their devices -- primarily makers of cell phones
580 ++ * and digital cameras. Since these devices always use
581 ++ * flash media and can be expected to have an even number
582 ++ * of sectors, we will always enable the CAPACITY_HEURISTICS
583 ++ * flag unless told otherwise. */
584 ++ switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) {
585 ++ case VENDOR_ID_NOKIA:
586 ++ case VENDOR_ID_NIKON:
587 ++ case VENDOR_ID_MOTOROLA:
588 ++ if (!(us->fflags & (US_FL_FIX_CAPACITY |
589 ++ US_FL_CAPACITY_OK)))
590 ++ us->fflags |= US_FL_CAPACITY_HEURISTICS;
591 ++ break;
592 ++ }
593 ++
594 + /* Disk-type devices use MODE SENSE(6) if the protocol
595 + * (SubClass) is Transparent SCSI, otherwise they use
596 + * MODE SENSE(10). */
597 +@@ -196,6 +219,14 @@ static int slave_configure(struct scsi_device *sdev)
598 + * sector in a larger then 1 sector read, since the performance
599 + * impact is negible we set this flag for all USB disks */
600 + sdev->last_sector_bug = 1;
601 ++
602 ++ /* Enable last-sector hacks for single-target devices using
603 ++ * the Bulk-only transport, unless we already know the
604 ++ * capacity will be decremented or is correct. */
605 ++ if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
606 ++ US_FL_SCM_MULT_TARG)) &&
607 ++ us->protocol == US_PR_BULK)
608 ++ us->use_last_sector_hacks = 1;
609 + } else {
610 +
611 + /* Non-disk-type devices don't need to blacklist any pages
612 +diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
613 +index 3523a0b..861e308 100644
614 +--- a/drivers/usb/storage/transport.c
615 ++++ b/drivers/usb/storage/transport.c
616 +@@ -57,6 +57,9 @@
617 + #include "scsiglue.h"
618 + #include "debug.h"
619 +
620 ++#include <linux/blkdev.h>
621 ++#include "../../scsi/sd.h"
622 ++
623 +
624 + /***********************************************************************
625 + * Data transfer routines
626 +@@ -511,6 +514,80 @@ int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
627 + * Transport routines
628 + ***********************************************************************/
629 +
630 ++/* There are so many devices that report the capacity incorrectly,
631 ++ * this routine was written to counteract some of the resulting
632 ++ * problems.
633 ++ */
634 ++static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb)
635 ++{
636 ++ struct gendisk *disk;
637 ++ struct scsi_disk *sdkp;
638 ++ u32 sector;
639 ++
640 ++ /* To Report "Medium Error: Record Not Found */
641 ++ static unsigned char record_not_found[18] = {
642 ++ [0] = 0x70, /* current error */
643 ++ [2] = MEDIUM_ERROR, /* = 0x03 */
644 ++ [7] = 0x0a, /* additional length */
645 ++ [12] = 0x14 /* Record Not Found */
646 ++ };
647 ++
648 ++ /* If last-sector problems can't occur, whether because the
649 ++ * capacity was already decremented or because the device is
650 ++ * known to report the correct capacity, then we don't need
651 ++ * to do anything.
652 ++ */
653 ++ if (!us->use_last_sector_hacks)
654 ++ return;
655 ++
656 ++ /* Was this command a READ(10) or a WRITE(10)? */
657 ++ if (srb->cmnd[0] != READ_10 && srb->cmnd[0] != WRITE_10)
658 ++ goto done;
659 ++
660 ++ /* Did this command access the last sector? */
661 ++ sector = (srb->cmnd[2] << 24) | (srb->cmnd[3] << 16) |
662 ++ (srb->cmnd[4] << 8) | (srb->cmnd[5]);
663 ++ disk = srb->request->rq_disk;
664 ++ if (!disk)
665 ++ goto done;
666 ++ sdkp = scsi_disk(disk);
667 ++ if (!sdkp)
668 ++ goto done;
669 ++ if (sector + 1 != sdkp->capacity)
670 ++ goto done;
671 ++
672 ++ if (srb->result == SAM_STAT_GOOD && scsi_get_resid(srb) == 0) {
673 ++
674 ++ /* The command succeeded. We know this device doesn't
675 ++ * have the last-sector bug, so stop checking it.
676 ++ */
677 ++ us->use_last_sector_hacks = 0;
678 ++
679 ++ } else {
680 ++ /* The command failed. Allow up to 3 retries in case this
681 ++ * is some normal sort of failure. After that, assume the
682 ++ * capacity is wrong and we're trying to access the sector
683 ++ * beyond the end. Replace the result code and sense data
684 ++ * with values that will cause the SCSI core to fail the
685 ++ * command immediately, instead of going into an infinite
686 ++ * (or even just a very long) retry loop.
687 ++ */
688 ++ if (++us->last_sector_retries < 3)
689 ++ return;
690 ++ srb->result = SAM_STAT_CHECK_CONDITION;
691 ++ memcpy(srb->sense_buffer, record_not_found,
692 ++ sizeof(record_not_found));
693 ++ }
694 ++
695 ++ done:
696 ++ /* Don't reset the retry counter for TEST UNIT READY commands,
697 ++ * because they get issued after device resets which might be
698 ++ * caused by a failed last-sector access.
699 ++ */
700 ++ if (srb->cmnd[0] != TEST_UNIT_READY)
701 ++ us->last_sector_retries = 0;
702 ++}
703 ++
704 + /* Invoke the transport and basic error-handling/recovery methods
705 + *
706 + * This is used by the protocol layers to actually send the message to
707 +@@ -544,6 +621,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
708 + /* if the transport provided its own sense data, don't auto-sense */
709 + if (result == USB_STOR_TRANSPORT_NO_SENSE) {
710 + srb->result = SAM_STAT_CHECK_CONDITION;
711 ++ last_sector_hacks(us, srb);
712 + return;
713 + }
714 +
715 +@@ -667,6 +745,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
716 + scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow)
717 + srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24);
718 +
719 ++ last_sector_hacks(us, srb);
720 + return;
721 +
722 + /* Error and abort processing: try to resynchronize with the device
723 +@@ -694,6 +773,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
724 + us->transport_reset(us);
725 + }
726 + clear_bit(US_FLIDX_RESETTING, &us->dflags);
727 ++ last_sector_hacks(us, srb);
728 + }
729 +
730 + /* Stop the current URB transfer */
731 +diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
732 +index 476da5d..6fcb6d1 100644
733 +--- a/drivers/usb/storage/unusual_devs.h
734 ++++ b/drivers/usb/storage/unusual_devs.h
735 +@@ -27,7 +27,8 @@
736 +
737 + /* IMPORTANT NOTE: This file must be included in another file which does
738 + * the following thing for it to work:
739 +- * The macro UNUSUAL_DEV() must be defined before this file is included
740 ++ * The UNUSUAL_DEV, COMPLIANT_DEV, and USUAL_DEV macros must be defined
741 ++ * before this file is included.
742 + */
743 +
744 + /* If you edit this file, please try to keep it sorted first by VendorID,
745 +@@ -46,6 +47,12 @@
746 + * <usb-storage@××××××××××××××××××××.net>
747 + */
748 +
749 ++/* Note: If you add an entry only in order to set the CAPACITY_OK flag,
750 ++ * use the COMPLIANT_DEV macro instead of UNUSUAL_DEV. This is
751 ++ * because such entries mark devices which actually work correctly,
752 ++ * as opposed to devices that do something strangely or wrongly.
753 ++ */
754 ++
755 + /* patch submitted by Vivian Bregier <Vivian.Bregier@××××.fr>
756 + */
757 + UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100,
758 +@@ -160,20 +167,6 @@ UNUSUAL_DEV( 0x0421, 0x0019, 0x0592, 0x0592,
759 + US_SC_DEVICE, US_PR_DEVICE, NULL,
760 + US_FL_MAX_SECTORS_64 ),
761 +
762 +-/* Reported by Filip Joelsson <filip@××××××××××.nu> */
763 +-UNUSUAL_DEV( 0x0421, 0x005d, 0x0001, 0x0600,
764 +- "Nokia",
765 +- "Nokia 3110c",
766 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
767 +- US_FL_FIX_CAPACITY ),
768 +-
769 +-/* Patch for Nokia 5310 capacity */
770 +-UNUSUAL_DEV( 0x0421, 0x006a, 0x0000, 0x0701,
771 +- "Nokia",
772 +- "5310",
773 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
774 +- US_FL_FIX_CAPACITY ),
775 +-
776 + /* Reported by Mario Rettig <mariorettig@×××.de> */
777 + UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
778 + "Nokia",
779 +@@ -239,56 +232,6 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
780 + US_SC_DEVICE, US_PR_DEVICE, NULL,
781 + US_FL_MAX_SECTORS_64 ),
782 +
783 +-/* Reported by Cedric Godin <cedric@×××××××.be> */
784 +-UNUSUAL_DEV( 0x0421, 0x04b9, 0x0500, 0x0551,
785 +- "Nokia",
786 +- "5300",
787 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
788 +- US_FL_FIX_CAPACITY ),
789 +-
790 +-/* Reported by Paulo Fessel <pfessel@×××××.com> */
791 +-UNUSUAL_DEV( 0x0421, 0x04bd, 0x0000, 0x9999,
792 +- "Nokia",
793 +- "5200",
794 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
795 +- US_FL_FIX_CAPACITY ),
796 +-
797 +-/* Reported by Richard Nauber <RichardNauber@×××.de> */
798 +-UNUSUAL_DEV( 0x0421, 0x04fa, 0x0550, 0x0660,
799 +- "Nokia",
800 +- "6300",
801 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
802 +- US_FL_FIX_CAPACITY ),
803 +-
804 +-/* Reported by Ozan Sener <themgzzy@×××××.com> */
805 +-UNUSUAL_DEV( 0x0421, 0x0060, 0x0551, 0x0551,
806 +- "Nokia",
807 +- "3500c",
808 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
809 +- US_FL_FIX_CAPACITY ),
810 +-
811 +-/* Reported by CSECSY Laszlo <boobaa@××××××××××.org> */
812 +-UNUSUAL_DEV( 0x0421, 0x0063, 0x0001, 0x0601,
813 +- "Nokia",
814 +- "Nokia 3109c",
815 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
816 +- US_FL_FIX_CAPACITY ),
817 +-
818 +-/* Patch for Nokia 5310 capacity */
819 +-UNUSUAL_DEV( 0x0421, 0x006a, 0x0000, 0x0591,
820 +- "Nokia",
821 +- "5310",
822 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
823 +- US_FL_FIX_CAPACITY ),
824 +-
825 +-/* Submitted by Ricky Wong Yung Fei <evilbladewarrior@×××××.com> */
826 +-/* Nokia 7610 Supernova - Too many sectors reported in usb storage mode */
827 +-UNUSUAL_DEV( 0x0421, 0x00f5, 0x0000, 0x0470,
828 +- "Nokia",
829 +- "7610 Supernova",
830 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
831 +- US_FL_FIX_CAPACITY ),
832 +-
833 + /* Reported by Olaf Hering <olh@××××.de> from novell bug #105878 */
834 + UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
835 + "SMSC",
836 +@@ -692,6 +635,13 @@ UNUSUAL_DEV( 0x0525, 0xa140, 0x0100, 0x0100,
837 + US_SC_8070, US_PR_DEVICE, NULL,
838 + US_FL_FIX_INQUIRY ),
839 +
840 ++/* Added by Alan Stern <stern@×××××××××××××××.edu> */
841 ++COMPLIANT_DEV(0x0525, 0xa4a5, 0x0000, 0x9999,
842 ++ "Linux",
843 ++ "File-backed Storage Gadget",
844 ++ US_SC_DEVICE, US_PR_DEVICE, NULL,
845 ++ US_FL_CAPACITY_OK ),
846 ++
847 + /* Yakumo Mega Image 37
848 + * Submitted by Stephan Fuhrmann <atomenergie@××××××××.de> */
849 + UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100,
850 +diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
851 +index 27016fd..ceb8ac3 100644
852 +--- a/drivers/usb/storage/usb.c
853 ++++ b/drivers/usb/storage/usb.c
854 +@@ -126,6 +126,8 @@ MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
855 + { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
856 + .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
857 +
858 ++#define COMPLIANT_DEV UNUSUAL_DEV
859 ++
860 + #define USUAL_DEV(useProto, useTrans, useType) \
861 + { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
862 + .driver_info = (USB_US_TYPE_STOR<<24) }
863 +@@ -134,6 +136,7 @@ static struct usb_device_id storage_usb_ids [] = {
864 +
865 + # include "unusual_devs.h"
866 + #undef UNUSUAL_DEV
867 ++#undef COMPLIANT_DEV
868 + #undef USUAL_DEV
869 + /* Terminating entry */
870 + { }
871 +@@ -164,6 +167,8 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids);
872 + .initFunction = init_function, \
873 + }
874 +
875 ++#define COMPLIANT_DEV UNUSUAL_DEV
876 ++
877 + #define USUAL_DEV(use_protocol, use_transport, use_type) \
878 + { \
879 + .useProtocol = use_protocol, \
880 +@@ -173,6 +178,7 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids);
881 + static struct us_unusual_dev us_unusual_dev_list[] = {
882 + # include "unusual_devs.h"
883 + # undef UNUSUAL_DEV
884 ++# undef COMPLIANT_DEV
885 + # undef USUAL_DEV
886 +
887 + /* Terminating entry */
888 +diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
889 +index a4ad73b..2e995c9 100644
890 +--- a/drivers/usb/storage/usb.h
891 ++++ b/drivers/usb/storage/usb.h
892 +@@ -155,6 +155,10 @@ struct us_data {
893 + #ifdef CONFIG_PM
894 + pm_hook suspend_resume_hook;
895 + #endif
896 ++
897 ++ /* hacks for READ CAPACITY bug handling */
898 ++ int use_last_sector_hacks;
899 ++ int last_sector_retries;
900 + };
901 +
902 + /* Convert between us_data and the corresponding Scsi_Host */
903 +diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
904 +index 25adfc3..c8616a0 100644
905 +--- a/fs/fs-writeback.c
906 ++++ b/fs/fs-writeback.c
907 +@@ -421,9 +421,6 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
908 + * If we're a pdlfush thread, then implement pdflush collision avoidance
909 + * against the entire list.
910 + *
911 +- * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so
912 +- * that it can be located for waiting on in __writeback_single_inode().
913 +- *
914 + * If `bdi' is non-zero then we're being asked to writeback a specific queue.
915 + * This function assumes that the blockdev superblock's inodes are backed by
916 + * a variety of queues, so all inodes are searched. For other superblocks,
917 +@@ -443,6 +440,7 @@ void generic_sync_sb_inodes(struct super_block *sb,
918 + struct writeback_control *wbc)
919 + {
920 + const unsigned long start = jiffies; /* livelock avoidance */
921 ++ int sync = wbc->sync_mode == WB_SYNC_ALL;
922 +
923 + spin_lock(&inode_lock);
924 + if (!wbc->for_kupdate || list_empty(&sb->s_io))
925 +@@ -499,10 +497,6 @@ void generic_sync_sb_inodes(struct super_block *sb,
926 + __iget(inode);
927 + pages_skipped = wbc->pages_skipped;
928 + __writeback_single_inode(inode, wbc);
929 +- if (wbc->sync_mode == WB_SYNC_HOLD) {
930 +- inode->dirtied_when = jiffies;
931 +- list_move(&inode->i_list, &sb->s_dirty);
932 +- }
933 + if (current_is_pdflush())
934 + writeback_release(bdi);
935 + if (wbc->pages_skipped != pages_skipped) {
936 +@@ -523,7 +517,49 @@ void generic_sync_sb_inodes(struct super_block *sb,
937 + if (!list_empty(&sb->s_more_io))
938 + wbc->more_io = 1;
939 + }
940 +- spin_unlock(&inode_lock);
941 ++
942 ++ if (sync) {
943 ++ struct inode *inode, *old_inode = NULL;
944 ++
945 ++ /*
946 ++ * Data integrity sync. Must wait for all pages under writeback,
947 ++ * because there may have been pages dirtied before our sync
948 ++ * call, but which had writeout started before we write it out.
949 ++ * In which case, the inode may not be on the dirty list, but
950 ++ * we still have to wait for that writeout.
951 ++ */
952 ++ list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
953 ++ struct address_space *mapping;
954 ++
955 ++ if (inode->i_state & (I_FREEING|I_WILL_FREE))
956 ++ continue;
957 ++ mapping = inode->i_mapping;
958 ++ if (mapping->nrpages == 0)
959 ++ continue;
960 ++ __iget(inode);
961 ++ spin_unlock(&inode_lock);
962 ++ /*
963 ++ * We hold a reference to 'inode' so it couldn't have
964 ++ * been removed from s_inodes list while we dropped the
965 ++ * inode_lock. We cannot iput the inode now as we can
966 ++ * be holding the last reference and we cannot iput it
967 ++ * under inode_lock. So we keep the reference and iput
968 ++ * it later.
969 ++ */
970 ++ iput(old_inode);
971 ++ old_inode = inode;
972 ++
973 ++ filemap_fdatawait(mapping);
974 ++
975 ++ cond_resched();
976 ++
977 ++ spin_lock(&inode_lock);
978 ++ }
979 ++ spin_unlock(&inode_lock);
980 ++ iput(old_inode);
981 ++ } else
982 ++ spin_unlock(&inode_lock);
983 ++
984 + return; /* Leave any unwritten inodes on s_io */
985 + }
986 + EXPORT_SYMBOL_GPL(generic_sync_sb_inodes);
987 +@@ -588,8 +624,7 @@ restart:
988 +
989 + /*
990 + * writeback and wait upon the filesystem's dirty inodes. The caller will
991 +- * do this in two passes - one to write, and one to wait. WB_SYNC_HOLD is
992 +- * used to park the written inodes on sb->s_dirty for the wait pass.
993 ++ * do this in two passes - one to write, and one to wait.
994 + *
995 + * A finite limit is set on the number of pages which will be written.
996 + * To prevent infinite livelock of sys_sync().
997 +@@ -600,30 +635,21 @@ restart:
998 + void sync_inodes_sb(struct super_block *sb, int wait)
999 + {
1000 + struct writeback_control wbc = {
1001 +- .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_HOLD,
1002 ++ .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE,
1003 + .range_start = 0,
1004 + .range_end = LLONG_MAX,
1005 + };
1006 +- unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY);
1007 +- unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS);
1008 +
1009 +- wbc.nr_to_write = nr_dirty + nr_unstable +
1010 +- (inodes_stat.nr_inodes - inodes_stat.nr_unused) +
1011 +- nr_dirty + nr_unstable;
1012 +- wbc.nr_to_write += wbc.nr_to_write / 2; /* Bit more for luck */
1013 +- sync_sb_inodes(sb, &wbc);
1014 +-}
1015 ++ if (!wait) {
1016 ++ unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY);
1017 ++ unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS);
1018 +
1019 +-/*
1020 +- * Rather lame livelock avoidance.
1021 +- */
1022 +-static void set_sb_syncing(int val)
1023 +-{
1024 +- struct super_block *sb;
1025 +- spin_lock(&sb_lock);
1026 +- list_for_each_entry_reverse(sb, &super_blocks, s_list)
1027 +- sb->s_syncing = val;
1028 +- spin_unlock(&sb_lock);
1029 ++ wbc.nr_to_write = nr_dirty + nr_unstable +
1030 ++ (inodes_stat.nr_inodes - inodes_stat.nr_unused);
1031 ++ } else
1032 ++ wbc.nr_to_write = LONG_MAX; /* doesn't actually matter */
1033 ++
1034 ++ sync_sb_inodes(sb, &wbc);
1035 + }
1036 +
1037 + /**
1038 +@@ -652,9 +678,6 @@ static void __sync_inodes(int wait)
1039 + spin_lock(&sb_lock);
1040 + restart:
1041 + list_for_each_entry(sb, &super_blocks, s_list) {
1042 +- if (sb->s_syncing)
1043 +- continue;
1044 +- sb->s_syncing = 1;
1045 + sb->s_count++;
1046 + spin_unlock(&sb_lock);
1047 + down_read(&sb->s_umount);
1048 +@@ -672,13 +695,10 @@ restart:
1049 +
1050 + void sync_inodes(int wait)
1051 + {
1052 +- set_sb_syncing(0);
1053 + __sync_inodes(0);
1054 +
1055 +- if (wait) {
1056 +- set_sb_syncing(0);
1057 ++ if (wait)
1058 + __sync_inodes(1);
1059 +- }
1060 + }
1061 +
1062 + /**
1063 +diff --git a/fs/sync.c b/fs/sync.c
1064 +index 6cc8cb4..9e5f60d 100644
1065 +--- a/fs/sync.c
1066 ++++ b/fs/sync.c
1067 +@@ -287,7 +287,7 @@ int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
1068 +
1069 + if (flags & SYNC_FILE_RANGE_WRITE) {
1070 + ret = __filemap_fdatawrite_range(mapping, offset, endbyte,
1071 +- WB_SYNC_NONE);
1072 ++ WB_SYNC_ALL);
1073 + if (ret < 0)
1074 + goto out;
1075 + }
1076 +diff --git a/include/linux/fs.h b/include/linux/fs.h
1077 +index d621217..d1b3e22 100644
1078 +--- a/include/linux/fs.h
1079 ++++ b/include/linux/fs.h
1080 +@@ -1080,7 +1080,6 @@ struct super_block {
1081 + struct rw_semaphore s_umount;
1082 + struct mutex s_lock;
1083 + int s_count;
1084 +- int s_syncing;
1085 + int s_need_sync_fs;
1086 + atomic_t s_active;
1087 + #ifdef CONFIG_SECURITY
1088 +diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h
1089 +index d9a3bbe..bd414ec 100644
1090 +--- a/include/linux/usb_usual.h
1091 ++++ b/include/linux/usb_usual.h
1092 +@@ -52,8 +52,9 @@
1093 + US_FLAG(MAX_SECTORS_MIN,0x00002000) \
1094 + /* Sets max_sectors to arch min */ \
1095 + US_FLAG(BULK_IGNORE_TAG,0x00004000) \
1096 +- /* Ignore tag mismatch in bulk operations */
1097 +-
1098 ++ /* Ignore tag mismatch in bulk operations */ \
1099 ++ US_FLAG(CAPACITY_OK, 0x00010000) \
1100 ++ /* READ CAPACITY response is correct */
1101 +
1102 + #define US_FLAG(name, value) US_FL_##name = value ,
1103 + enum { US_DO_ALL_FLAGS };
1104 +diff --git a/include/linux/writeback.h b/include/linux/writeback.h
1105 +index 12b15c5..c2835bb 100644
1106 +--- a/include/linux/writeback.h
1107 ++++ b/include/linux/writeback.h
1108 +@@ -30,7 +30,6 @@ static inline int task_is_pdflush(struct task_struct *task)
1109 + enum writeback_sync_modes {
1110 + WB_SYNC_NONE, /* Don't wait on anything */
1111 + WB_SYNC_ALL, /* Wait on every mapping */
1112 +- WB_SYNC_HOLD, /* Hold the inode on sb_dirty for sys_sync() */
1113 + };
1114 +
1115 + /*
1116 +diff --git a/kernel/signal.c b/kernel/signal.c
1117 +index 6f06f43..3d161f0 100644
1118 +--- a/kernel/signal.c
1119 ++++ b/kernel/signal.c
1120 +@@ -1141,7 +1141,8 @@ static int kill_something_info(int sig, struct siginfo *info, pid_t pid)
1121 + struct task_struct * p;
1122 +
1123 + for_each_process(p) {
1124 +- if (p->pid > 1 && !same_thread_group(p, current)) {
1125 ++ if (task_pid_vnr(p) > 1 &&
1126 ++ !same_thread_group(p, current)) {
1127 + int err = group_send_sig_info(sig, info, p);
1128 + ++count;
1129 + if (err != -EPERM)
1130 +diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
1131 +index 4220a2e..521960b 100644
1132 +--- a/kernel/time/timekeeping.c
1133 ++++ b/kernel/time/timekeeping.c
1134 +@@ -61,27 +61,23 @@ struct clocksource *clock;
1135 +
1136 + #ifdef CONFIG_GENERIC_TIME
1137 + /**
1138 +- * __get_nsec_offset - Returns nanoseconds since last call to periodic_hook
1139 ++ * clocksource_forward_now - update clock to the current time
1140 + *
1141 +- * private function, must hold xtime_lock lock when being
1142 +- * called. Returns the number of nanoseconds since the
1143 +- * last call to update_wall_time() (adjusted by NTP scaling)
1144 ++ * Forward the current clock to update its state since the last call to
1145 ++ * update_wall_time(). This is useful before significant clock changes,
1146 ++ * as it avoids having to deal with this time offset explicitly.
1147 + */
1148 +-static inline s64 __get_nsec_offset(void)
1149 ++static void clocksource_forward_now(void)
1150 + {
1151 + cycle_t cycle_now, cycle_delta;
1152 +- s64 ns_offset;
1153 ++ s64 nsec;
1154 +
1155 +- /* read clocksource: */
1156 + cycle_now = clocksource_read(clock);
1157 +-
1158 +- /* calculate the delta since the last update_wall_time: */
1159 + cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
1160 ++ clock->cycle_last = cycle_now;
1161 +
1162 +- /* convert to nanoseconds: */
1163 +- ns_offset = cyc2ns(clock, cycle_delta);
1164 +-
1165 +- return ns_offset;
1166 ++ nsec = cyc2ns(clock, cycle_delta);
1167 ++ timespec_add_ns(&xtime, nsec);
1168 + }
1169 +
1170 + /**
1171 +@@ -92,6 +88,7 @@ static inline s64 __get_nsec_offset(void)
1172 + */
1173 + void getnstimeofday(struct timespec *ts)
1174 + {
1175 ++ cycle_t cycle_now, cycle_delta;
1176 + unsigned long seq;
1177 + s64 nsecs;
1178 +
1179 +@@ -101,7 +98,15 @@ void getnstimeofday(struct timespec *ts)
1180 + seq = read_seqbegin(&xtime_lock);
1181 +
1182 + *ts = xtime;
1183 +- nsecs = __get_nsec_offset();
1184 ++
1185 ++ /* read clocksource: */
1186 ++ cycle_now = clocksource_read(clock);
1187 ++
1188 ++ /* calculate the delta since the last update_wall_time: */
1189 ++ cycle_delta = (cycle_now - clock->cycle_last) & clock->mask;
1190 ++
1191 ++ /* convert to nanoseconds: */
1192 ++ nsecs = cyc2ns(clock, cycle_delta);
1193 +
1194 + } while (read_seqretry(&xtime_lock, seq));
1195 +
1196 +@@ -134,22 +139,22 @@ EXPORT_SYMBOL(do_gettimeofday);
1197 + */
1198 + int do_settimeofday(struct timespec *tv)
1199 + {
1200 ++ struct timespec ts_delta;
1201 + unsigned long flags;
1202 +- time_t wtm_sec, sec = tv->tv_sec;
1203 +- long wtm_nsec, nsec = tv->tv_nsec;
1204 +
1205 + if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC)
1206 + return -EINVAL;
1207 +
1208 + write_seqlock_irqsave(&xtime_lock, flags);
1209 +
1210 +- nsec -= __get_nsec_offset();
1211 ++ clocksource_forward_now();
1212 ++
1213 ++ ts_delta.tv_sec = tv->tv_sec - xtime.tv_sec;
1214 ++ ts_delta.tv_nsec = tv->tv_nsec - xtime.tv_nsec;
1215 ++ wall_to_monotonic = timespec_sub(wall_to_monotonic, ts_delta);
1216 +
1217 +- wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec);
1218 +- wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec);
1219 ++ xtime = *tv;
1220 +
1221 +- set_normalized_timespec(&xtime, sec, nsec);
1222 +- set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec);
1223 + update_xtime_cache(0);
1224 +
1225 + clock->error = 0;
1226 +@@ -175,22 +180,17 @@ EXPORT_SYMBOL(do_settimeofday);
1227 + static void change_clocksource(void)
1228 + {
1229 + struct clocksource *new;
1230 +- cycle_t now;
1231 +- u64 nsec;
1232 +
1233 + new = clocksource_get_next();
1234 +
1235 + if (clock == new)
1236 + return;
1237 +
1238 +- new->cycle_last = 0;
1239 +- now = clocksource_read(new);
1240 +- nsec = __get_nsec_offset();
1241 +- timespec_add_ns(&xtime, nsec);
1242 ++ clocksource_forward_now();
1243 +
1244 + clock = new;
1245 +- clock->cycle_last = now;
1246 +-
1247 ++ clock->cycle_last = 0;
1248 ++ clock->cycle_last = clocksource_read(new);
1249 + clock->error = 0;
1250 + clock->xtime_nsec = 0;
1251 + clocksource_calculate_interval(clock, NTP_INTERVAL_LENGTH);
1252 +@@ -205,8 +205,8 @@ static void change_clocksource(void)
1253 + */
1254 + }
1255 + #else
1256 ++static inline void clocksource_forward_now(void) { }
1257 + static inline void change_clocksource(void) { }
1258 +-static inline s64 __get_nsec_offset(void) { return 0; }
1259 + #endif
1260 +
1261 + /**
1262 +@@ -268,8 +268,6 @@ void __init timekeeping_init(void)
1263 +
1264 + /* time in seconds when suspend began */
1265 + static unsigned long timekeeping_suspend_time;
1266 +-/* xtime offset when we went into suspend */
1267 +-static s64 timekeeping_suspend_nsecs;
1268 +
1269 + /**
1270 + * timekeeping_resume - Resumes the generic timekeeping subsystem.
1271 +@@ -295,8 +293,6 @@ static int timekeeping_resume(struct sys_device *dev)
1272 + wall_to_monotonic.tv_sec -= sleep_length;
1273 + total_sleep_time += sleep_length;
1274 + }
1275 +- /* Make sure that we have the correct xtime reference */
1276 +- timespec_add_ns(&xtime, timekeeping_suspend_nsecs);
1277 + update_xtime_cache(0);
1278 + /* re-base the last cycle value */
1279 + clock->cycle_last = 0;
1280 +@@ -322,8 +318,7 @@ static int timekeeping_suspend(struct sys_device *dev, pm_message_t state)
1281 + timekeeping_suspend_time = read_persistent_clock();
1282 +
1283 + write_seqlock_irqsave(&xtime_lock, flags);
1284 +- /* Get the current xtime offset */
1285 +- timekeeping_suspend_nsecs = __get_nsec_offset();
1286 ++ clocksource_forward_now();
1287 + timekeeping_suspended = 1;
1288 + write_sequnlock_irqrestore(&xtime_lock, flags);
1289 +
1290 +@@ -464,10 +459,10 @@ void update_wall_time(void)
1291 + */
1292 + while (offset >= clock->cycle_interval) {
1293 + /* accumulate one interval */
1294 +- clock->xtime_nsec += clock->xtime_interval;
1295 +- clock->cycle_last += clock->cycle_interval;
1296 + offset -= clock->cycle_interval;
1297 ++ clock->cycle_last += clock->cycle_interval;
1298 +
1299 ++ clock->xtime_nsec += clock->xtime_interval;
1300 + if (clock->xtime_nsec >= (u64)NSEC_PER_SEC << clock->shift) {
1301 + clock->xtime_nsec -= (u64)NSEC_PER_SEC << clock->shift;
1302 + xtime.tv_sec++;
1303 +diff --git a/lib/idr.c b/lib/idr.c
1304 +index 1c4f928..21154ae 100644
1305 +--- a/lib/idr.c
1306 ++++ b/lib/idr.c
1307 +@@ -121,7 +121,7 @@ int idr_pre_get(struct idr *idp, gfp_t gfp_mask)
1308 + {
1309 + while (idp->id_free_cnt < IDR_FREE_MAX) {
1310 + struct idr_layer *new;
1311 +- new = kmem_cache_alloc(idr_layer_cache, gfp_mask);
1312 ++ new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
1313 + if (new == NULL)
1314 + return (0);
1315 + move_to_free_list(idp, new);
1316 +@@ -623,16 +623,10 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
1317 + }
1318 + EXPORT_SYMBOL(idr_replace);
1319 +
1320 +-static void idr_cache_ctor(void *idr_layer)
1321 +-{
1322 +- memset(idr_layer, 0, sizeof(struct idr_layer));
1323 +-}
1324 +-
1325 + void __init idr_init_cache(void)
1326 + {
1327 + idr_layer_cache = kmem_cache_create("idr_layer_cache",
1328 +- sizeof(struct idr_layer), 0, SLAB_PANIC,
1329 +- idr_cache_ctor);
1330 ++ sizeof(struct idr_layer), 0, SLAB_PANIC, NULL);
1331 + }
1332 +
1333 + /**
1334 +diff --git a/mm/filemap.c b/mm/filemap.c
1335 +index f3033d0..8a477d3 100644
1336 +--- a/mm/filemap.c
1337 ++++ b/mm/filemap.c
1338 +@@ -209,7 +209,7 @@ int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start,
1339 + int ret;
1340 + struct writeback_control wbc = {
1341 + .sync_mode = sync_mode,
1342 +- .nr_to_write = mapping->nrpages * 2,
1343 ++ .nr_to_write = LONG_MAX,
1344 + .range_start = start,
1345 + .range_end = end,
1346 + };
1347 +@@ -1304,7 +1304,8 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
1348 + goto out; /* skip atime */
1349 + size = i_size_read(inode);
1350 + if (pos < size) {
1351 +- retval = filemap_write_and_wait(mapping);
1352 ++ retval = filemap_write_and_wait_range(mapping, pos,
1353 ++ pos + iov_length(iov, nr_segs) - 1);
1354 + if (!retval) {
1355 + retval = mapping->a_ops->direct_IO(READ, iocb,
1356 + iov, pos, nr_segs);
1357 +@@ -2117,18 +2118,10 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
1358 + if (count != ocount)
1359 + *nr_segs = iov_shorten((struct iovec *)iov, *nr_segs, count);
1360 +
1361 +- /*
1362 +- * Unmap all mmappings of the file up-front.
1363 +- *
1364 +- * This will cause any pte dirty bits to be propagated into the
1365 +- * pageframes for the subsequent filemap_write_and_wait().
1366 +- */
1367 + write_len = iov_length(iov, *nr_segs);
1368 + end = (pos + write_len - 1) >> PAGE_CACHE_SHIFT;
1369 +- if (mapping_mapped(mapping))
1370 +- unmap_mapping_range(mapping, pos, write_len, 0);
1371 +
1372 +- written = filemap_write_and_wait(mapping);
1373 ++ written = filemap_write_and_wait_range(mapping, pos, pos + write_len - 1);
1374 + if (written)
1375 + goto out;
1376 +
1377 +@@ -2519,7 +2512,8 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
1378 + * the file data here, to try to honour O_DIRECT expectations.
1379 + */
1380 + if (unlikely(file->f_flags & O_DIRECT) && written)
1381 +- status = filemap_write_and_wait(mapping);
1382 ++ status = filemap_write_and_wait_range(mapping,
1383 ++ pos, pos + written - 1);
1384 +
1385 + return written ? written : status;
1386 + }
1387 +diff --git a/mm/page-writeback.c b/mm/page-writeback.c
1388 +index 24de8b6..8875822 100644
1389 +--- a/mm/page-writeback.c
1390 ++++ b/mm/page-writeback.c
1391 +@@ -872,9 +872,11 @@ int write_cache_pages(struct address_space *mapping,
1392 + int done = 0;
1393 + struct pagevec pvec;
1394 + int nr_pages;
1395 ++ pgoff_t uninitialized_var(writeback_index);
1396 + pgoff_t index;
1397 + pgoff_t end; /* Inclusive */
1398 +- int scanned = 0;
1399 ++ pgoff_t done_index;
1400 ++ int cycled;
1401 + int range_whole = 0;
1402 +
1403 + if (wbc->nonblocking && bdi_write_congested(bdi)) {
1404 +@@ -884,82 +886,134 @@ int write_cache_pages(struct address_space *mapping,
1405 +
1406 + pagevec_init(&pvec, 0);
1407 + if (wbc->range_cyclic) {
1408 +- index = mapping->writeback_index; /* Start from prev offset */
1409 ++ writeback_index = mapping->writeback_index; /* prev offset */
1410 ++ index = writeback_index;
1411 ++ if (index == 0)
1412 ++ cycled = 1;
1413 ++ else
1414 ++ cycled = 0;
1415 + end = -1;
1416 + } else {
1417 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
1418 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
1419 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
1420 + range_whole = 1;
1421 +- scanned = 1;
1422 ++ cycled = 1; /* ignore range_cyclic tests */
1423 + }
1424 + retry:
1425 +- while (!done && (index <= end) &&
1426 +- (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
1427 +- PAGECACHE_TAG_DIRTY,
1428 +- min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
1429 +- unsigned i;
1430 ++ done_index = index;
1431 ++ while (!done && (index <= end)) {
1432 ++ int i;
1433 ++
1434 ++ nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
1435 ++ PAGECACHE_TAG_DIRTY,
1436 ++ min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
1437 ++ if (nr_pages == 0)
1438 ++ break;
1439 +
1440 +- scanned = 1;
1441 + for (i = 0; i < nr_pages; i++) {
1442 + struct page *page = pvec.pages[i];
1443 +
1444 + /*
1445 +- * At this point we hold neither mapping->tree_lock nor
1446 +- * lock on the page itself: the page may be truncated or
1447 +- * invalidated (changing page->mapping to NULL), or even
1448 +- * swizzled back from swapper_space to tmpfs file
1449 +- * mapping
1450 ++ * At this point, the page may be truncated or
1451 ++ * invalidated (changing page->mapping to NULL), or
1452 ++ * even swizzled back from swapper_space to tmpfs file
1453 ++ * mapping. However, page->index will not change
1454 ++ * because we have a reference on the page.
1455 + */
1456 ++ if (page->index > end) {
1457 ++ /*
1458 ++ * can't be range_cyclic (1st pass) because
1459 ++ * end == -1 in that case.
1460 ++ */
1461 ++ done = 1;
1462 ++ break;
1463 ++ }
1464 ++
1465 ++ done_index = page->index + 1;
1466 ++
1467 + lock_page(page);
1468 +
1469 ++ /*
1470 ++ * Page truncated or invalidated. We can freely skip it
1471 ++ * then, even for data integrity operations: the page
1472 ++ * has disappeared concurrently, so there could be no
1473 ++ * real expectation of this data interity operation
1474 ++ * even if there is now a new, dirty page at the same
1475 ++ * pagecache address.
1476 ++ */
1477 + if (unlikely(page->mapping != mapping)) {
1478 ++continue_unlock:
1479 + unlock_page(page);
1480 + continue;
1481 + }
1482 +
1483 +- if (!wbc->range_cyclic && page->index > end) {
1484 +- done = 1;
1485 +- unlock_page(page);
1486 +- continue;
1487 ++ if (!PageDirty(page)) {
1488 ++ /* someone wrote it for us */
1489 ++ goto continue_unlock;
1490 + }
1491 +
1492 +- if (wbc->sync_mode != WB_SYNC_NONE)
1493 +- wait_on_page_writeback(page);
1494 +-
1495 +- if (PageWriteback(page) ||
1496 +- !clear_page_dirty_for_io(page)) {
1497 +- unlock_page(page);
1498 +- continue;
1499 ++ if (PageWriteback(page)) {
1500 ++ if (wbc->sync_mode != WB_SYNC_NONE)
1501 ++ wait_on_page_writeback(page);
1502 ++ else
1503 ++ goto continue_unlock;
1504 + }
1505 +
1506 ++ BUG_ON(PageWriteback(page));
1507 ++ if (!clear_page_dirty_for_io(page))
1508 ++ goto continue_unlock;
1509 ++
1510 + ret = (*writepage)(page, wbc, data);
1511 +
1512 +- if (unlikely(ret == AOP_WRITEPAGE_ACTIVATE)) {
1513 +- unlock_page(page);
1514 +- ret = 0;
1515 ++ if (unlikely(ret)) {
1516 ++ if (ret == AOP_WRITEPAGE_ACTIVATE) {
1517 ++ unlock_page(page);
1518 ++ ret = 0;
1519 ++ } else {
1520 ++ /*
1521 ++ * done_index is set past this page,
1522 ++ * so media errors will not choke
1523 ++ * background writeout for the entire
1524 ++ * file. This has consequences for
1525 ++ * range_cyclic semantics (ie. it may
1526 ++ * not be suitable for data integrity
1527 ++ * writeout).
1528 ++ */
1529 ++ done = 1;
1530 ++ break;
1531 ++ }
1532 ++ }
1533 ++
1534 ++ if (wbc->sync_mode == WB_SYNC_NONE) {
1535 ++ wbc->nr_to_write--;
1536 ++ if (wbc->nr_to_write <= 0) {
1537 ++ done = 1;
1538 ++ break;
1539 ++ }
1540 + }
1541 +- if (ret || (--(wbc->nr_to_write) <= 0))
1542 +- done = 1;
1543 + if (wbc->nonblocking && bdi_write_congested(bdi)) {
1544 + wbc->encountered_congestion = 1;
1545 + done = 1;
1546 ++ break;
1547 + }
1548 + }
1549 + pagevec_release(&pvec);
1550 + cond_resched();
1551 + }
1552 +- if (!scanned && !done) {
1553 ++ if (!cycled) {
1554 + /*
1555 ++ * range_cyclic:
1556 + * We hit the last page and there is more work to be done: wrap
1557 + * back to the start of the file
1558 + */
1559 +- scanned = 1;
1560 ++ cycled = 1;
1561 + index = 0;
1562 ++ end = writeback_index - 1;
1563 + goto retry;
1564 + }
1565 + if (wbc->range_cyclic || (range_whole && wbc->nr_to_write > 0))
1566 +- mapping->writeback_index = index;
1567 ++ mapping->writeback_index = done_index;
1568 +
1569 + if (wbc->range_cont)
1570 + wbc->range_start = index << PAGE_CACHE_SHIFT;
1571 +diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
1572 +index 1ab341e..f57d576 100644
1573 +--- a/net/ipv4/tcp.c
1574 ++++ b/net/ipv4/tcp.c
1575 +@@ -576,10 +576,6 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
1576 + else if (!ret) {
1577 + if (spliced)
1578 + break;
1579 +- if (flags & SPLICE_F_NONBLOCK) {
1580 +- ret = -EAGAIN;
1581 +- break;
1582 +- }
1583 + if (sock_flag(sk, SOCK_DONE))
1584 + break;
1585 + if (sk->sk_err) {
1586 +@@ -597,6 +593,10 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
1587 + ret = -ENOTCONN;
1588 + break;
1589 + }
1590 ++ if (flags & SPLICE_F_NONBLOCK) {
1591 ++ ret = -EAGAIN;
1592 ++ break;
1593 ++ }
1594 + if (!timeo) {
1595 + ret = -EAGAIN;
1596 + break;
1597 +diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
1598 +index 29c7c99..52ee1dc 100644
1599 +--- a/net/ipv6/ip6_fib.c
1600 ++++ b/net/ipv6/ip6_fib.c
1601 +@@ -298,6 +298,10 @@ static void fib6_dump_end(struct netlink_callback *cb)
1602 + struct fib6_walker_t *w = (void*)cb->args[2];
1603 +
1604 + if (w) {
1605 ++ if (cb->args[4]) {
1606 ++ cb->args[4] = 0;
1607 ++ fib6_walker_unlink(w);
1608 ++ }
1609 + cb->args[2] = 0;
1610 + kfree(w);
1611 + }
1612 +@@ -330,15 +334,12 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
1613 + read_lock_bh(&table->tb6_lock);
1614 + res = fib6_walk_continue(w);
1615 + read_unlock_bh(&table->tb6_lock);
1616 +- if (res != 0) {
1617 +- if (res < 0)
1618 +- fib6_walker_unlink(w);
1619 +- goto end;
1620 ++ if (res <= 0) {
1621 ++ fib6_walker_unlink(w);
1622 ++ cb->args[4] = 0;
1623 + }
1624 +- fib6_walker_unlink(w);
1625 +- cb->args[4] = 0;
1626 + }
1627 +-end:
1628 ++
1629 + return res;
1630 + }
1631 +
1632 +diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
1633 +index 246f906..ea51fcd 100644
1634 +--- a/net/sched/cls_u32.c
1635 ++++ b/net/sched/cls_u32.c
1636 +@@ -637,8 +637,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
1637 + break;
1638 +
1639 + n->next = *ins;
1640 +- wmb();
1641 ++ tcf_tree_lock(tp);
1642 + *ins = n;
1643 ++ tcf_tree_unlock(tp);
1644 +
1645 + *arg = (unsigned long)n;
1646 + return 0;
1647 +diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
1648 +index d14f020..d2943a4 100644
1649 +--- a/net/sched/sch_htb.c
1650 ++++ b/net/sched/sch_htb.c
1651 +@@ -924,6 +924,7 @@ static struct sk_buff *htb_dequeue(struct Qdisc *sch)
1652 + }
1653 + }
1654 + sch->qstats.overlimits++;
1655 ++ qdisc_watchdog_cancel(&q->watchdog);
1656 + qdisc_watchdog_schedule(&q->watchdog, next_event);
1657 + fin:
1658 + return skb;
1659 +diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
1660 +index 7c622af..649d174 100644
1661 +--- a/net/sctp/sm_statefuns.c
1662 ++++ b/net/sctp/sm_statefuns.c
1663 +@@ -3635,6 +3635,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
1664 + {
1665 + struct sctp_chunk *chunk = arg;
1666 + struct sctp_fwdtsn_hdr *fwdtsn_hdr;
1667 ++ struct sctp_fwdtsn_skip *skip;
1668 + __u16 len;
1669 + __u32 tsn;
1670 +
1671 +@@ -3664,6 +3665,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
1672 + if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
1673 + goto discard_noforce;
1674 +
1675 ++ /* Silently discard the chunk if stream-id is not valid */
1676 ++ sctp_walk_fwdtsn(skip, chunk) {
1677 ++ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
1678 ++ goto discard_noforce;
1679 ++ }
1680 ++
1681 + sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
1682 + if (len > sizeof(struct sctp_fwdtsn_hdr))
1683 + sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
1684 +@@ -3695,6 +3702,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
1685 + {
1686 + struct sctp_chunk *chunk = arg;
1687 + struct sctp_fwdtsn_hdr *fwdtsn_hdr;
1688 ++ struct sctp_fwdtsn_skip *skip;
1689 + __u16 len;
1690 + __u32 tsn;
1691 +
1692 +@@ -3724,6 +3732,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
1693 + if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
1694 + goto gen_shutdown;
1695 +
1696 ++ /* Silently discard the chunk if stream-id is not valid */
1697 ++ sctp_walk_fwdtsn(skip, chunk) {
1698 ++ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
1699 ++ goto gen_shutdown;
1700 ++ }
1701 ++
1702 + sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
1703 + if (len > sizeof(struct sctp_fwdtsn_hdr))
1704 + sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
1705 +diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
1706 +index 9b4e0e9..3c0f421 100644
1707 +--- a/security/keys/keyctl.c
1708 ++++ b/security/keys/keyctl.c
1709 +@@ -270,6 +270,7 @@ long keyctl_join_session_keyring(const char __user *_name)
1710 +
1711 + /* join the session */
1712 + ret = join_session_keyring(name);
1713 ++ kfree(name);
1714 +
1715 + error:
1716 + return ret;
1717 +diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
1718 +index 591f62f..8c857d5 100644
1719 +--- a/sound/pci/hda/patch_analog.c
1720 ++++ b/sound/pci/hda/patch_analog.c
1721 +@@ -629,6 +629,36 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
1722 + HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
1723 + HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
1724 + HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
1725 ++ HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
1726 ++ HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
1727 ++ HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1728 ++ HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1729 ++ HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
1730 ++ HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
1731 ++ HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
1732 ++ {
1733 ++ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1734 ++ .name = "Capture Source",
1735 ++ .info = ad198x_mux_enum_info,
1736 ++ .get = ad198x_mux_enum_get,
1737 ++ .put = ad198x_mux_enum_put,
1738 ++ },
1739 ++ {
1740 ++ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1741 ++ .name = "External Amplifier",
1742 ++ .info = ad198x_eapd_info,
1743 ++ .get = ad198x_eapd_get,
1744 ++ .put = ad198x_eapd_put,
1745 ++ .private_value = 0x1b | (1 << 8), /* port-D, inversed */
1746 ++ },
1747 ++ { } /* end */
1748 ++};
1749 ++
1750 ++static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
1751 ++ HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
1752 ++ HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
1753 ++ HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
1754 ++ HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
1755 + HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1756 + HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1757 + HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
1758 +@@ -917,6 +947,7 @@ enum {
1759 + AD1986A_LAPTOP_EAPD,
1760 + AD1986A_LAPTOP_AUTOMUTE,
1761 + AD1986A_ULTRA,
1762 ++ AD1986A_SAMSUNG,
1763 + AD1986A_MODELS
1764 + };
1765 +
1766 +@@ -927,6 +958,7 @@ static const char *ad1986a_models[AD1986A_MODELS] = {
1767 + [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
1768 + [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
1769 + [AD1986A_ULTRA] = "ultra",
1770 ++ [AD1986A_SAMSUNG] = "samsung",
1771 + };
1772 +
1773 + static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1774 +@@ -949,9 +981,9 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1775 + SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
1776 + SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1777 + SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1778 +- SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
1779 +- SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
1780 +- SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
1781 ++ SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_SAMSUNG),
1782 ++ SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_SAMSUNG),
1783 ++ SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_SAMSUNG),
1784 + SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1785 + SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
1786 + SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
1787 +@@ -1033,6 +1065,17 @@ static int patch_ad1986a(struct hda_codec *codec)
1788 + break;
1789 + case AD1986A_LAPTOP_EAPD:
1790 + spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1791 ++ spec->num_init_verbs = 2;
1792 ++ spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1793 ++ spec->multiout.max_channels = 2;
1794 ++ spec->multiout.num_dacs = 1;
1795 ++ spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1796 ++ if (!is_jack_available(codec, 0x25))
1797 ++ spec->multiout.dig_out_nid = 0;
1798 ++ spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1799 ++ break;
1800 ++ case AD1986A_SAMSUNG:
1801 ++ spec->mixers[0] = ad1986a_samsung_mixers;
1802 + spec->num_init_verbs = 3;
1803 + spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1804 + spec->init_verbs[2] = ad1986a_automic_verbs;
1805 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
1806 +index a1a3a34..7225f0f 100644
1807 +--- a/sound/pci/hda/patch_realtek.c
1808 ++++ b/sound/pci/hda/patch_realtek.c
1809 +@@ -9882,6 +9882,7 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
1810 + SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
1811 + SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
1812 + SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
1813 ++ SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
1814 + SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
1815 + SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
1816 + SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
1817
1818 Added: hardened/2.6/tags/2.6.27-8/4420_grsec-2.1.12-2.6.27.10-200812271347.patch
1819 ===================================================================
1820 --- hardened/2.6/tags/2.6.27-8/4420_grsec-2.1.12-2.6.27.10-200812271347.patch (rev 0)
1821 +++ hardened/2.6/tags/2.6.27-8/4420_grsec-2.1.12-2.6.27.10-200812271347.patch 2009-01-25 09:01:31 UTC (rev 1485)
1822 @@ -0,0 +1,37200 @@
1823 + !
1824 + -~*~-
1825 + /!\
1826 + /%;@\
1827 + o/@,%\o
1828 + /%;`@,\
1829 + o/@'%',\o
1830 + '^^^N^^^`
1831 +
1832 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/elf.h linux-2.6.27.10/arch/alpha/include/asm/elf.h
1833 +--- linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
1834 ++++ linux-2.6.27.10/arch/alpha/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
1835 +@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
1836 +
1837 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
1838 +
1839 ++#ifdef CONFIG_PAX_ASLR
1840 ++#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
1841 ++
1842 ++#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
1843 ++#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
1844 ++#endif
1845 ++
1846 + /* $0 is set by ld.so to a pointer to a function which might be
1847 + registered using atexit. This provides a mean for the dynamic
1848 + linker to call DT_FINI functions for shared libraries that have
1849 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h
1850 +--- linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
1851 ++++ linux-2.6.27.10/arch/alpha/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
1852 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
1853 + D(10) KM_IRQ1,
1854 + D(11) KM_SOFTIRQ0,
1855 + D(12) KM_SOFTIRQ1,
1856 +-D(13) KM_TYPE_NR
1857 ++D(13) KM_CLEARPAGE,
1858 ++D(14) KM_TYPE_NR
1859 + };
1860 +
1861 + #undef D
1862 +diff -urNp linux-2.6.27.10/arch/alpha/include/asm/pgtable.h linux-2.6.27.10/arch/alpha/include/asm/pgtable.h
1863 +--- linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
1864 ++++ linux-2.6.27.10/arch/alpha/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
1865 +@@ -101,6 +101,17 @@ struct vm_area_struct;
1866 + #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
1867 + #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1868 + #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
1869 ++
1870 ++#ifdef CONFIG_PAX_PAGEEXEC
1871 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
1872 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1873 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
1874 ++#else
1875 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
1876 ++# define PAGE_COPY_NOEXEC PAGE_COPY
1877 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
1878 ++#endif
1879 ++
1880 + #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
1881 +
1882 + #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
1883 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/module.c linux-2.6.27.10/arch/alpha/kernel/module.c
1884 +--- linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
1885 ++++ linux-2.6.27.10/arch/alpha/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
1886 +@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
1887 +
1888 + /* The small sections were sorted to the end of the segment.
1889 + The following should definitely cover them. */
1890 +- gp = (u64)me->module_core + me->core_size - 0x8000;
1891 ++ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
1892 + got = sechdrs[me->arch.gotsecindex].sh_addr;
1893 +
1894 + for (i = 0; i < n; i++) {
1895 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/osf_sys.c linux-2.6.27.10/arch/alpha/kernel/osf_sys.c
1896 +--- linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-07 12:55:34.000000000 -0500
1897 ++++ linux-2.6.27.10/arch/alpha/kernel/osf_sys.c 2008-11-18 03:38:43.000000000 -0500
1898 +@@ -1232,6 +1232,10 @@ arch_get_unmapped_area(struct file *filp
1899 + merely specific addresses, but regions of memory -- perhaps
1900 + this feature should be incorporated into all ports? */
1901 +
1902 ++#ifdef CONFIG_PAX_RANDMMAP
1903 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
1904 ++#endif
1905 ++
1906 + if (addr) {
1907 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
1908 + if (addr != (unsigned long) -ENOMEM)
1909 +@@ -1239,8 +1243,8 @@ arch_get_unmapped_area(struct file *filp
1910 + }
1911 +
1912 + /* Next, try allocating at TASK_UNMAPPED_BASE. */
1913 +- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
1914 +- len, limit);
1915 ++ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
1916 ++
1917 + if (addr != (unsigned long) -ENOMEM)
1918 + return addr;
1919 +
1920 +diff -urNp linux-2.6.27.10/arch/alpha/kernel/ptrace.c linux-2.6.27.10/arch/alpha/kernel/ptrace.c
1921 +--- linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
1922 ++++ linux-2.6.27.10/arch/alpha/kernel/ptrace.c 2008-11-18 03:38:43.000000000 -0500
1923 +@@ -15,6 +15,7 @@
1924 + #include <linux/slab.h>
1925 + #include <linux/security.h>
1926 + #include <linux/signal.h>
1927 ++#include <linux/grsecurity.h>
1928 +
1929 + #include <asm/uaccess.h>
1930 + #include <asm/pgtable.h>
1931 +@@ -266,6 +267,9 @@ long arch_ptrace(struct task_struct *chi
1932 + size_t copied;
1933 + long ret;
1934 +
1935 ++ if (gr_handle_ptrace(child, request))
1936 ++ return -EPERM;
1937 ++
1938 + switch (request) {
1939 + /* When I and D space are separate, these will need to be fixed. */
1940 + case PTRACE_PEEKTEXT: /* read word at location addr. */
1941 +diff -urNp linux-2.6.27.10/arch/alpha/mm/fault.c linux-2.6.27.10/arch/alpha/mm/fault.c
1942 +--- linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
1943 ++++ linux-2.6.27.10/arch/alpha/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
1944 +@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
1945 + __reload_thread(pcb);
1946 + }
1947 +
1948 ++#ifdef CONFIG_PAX_PAGEEXEC
1949 ++/*
1950 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
1951 ++ *
1952 ++ * returns 1 when task should be killed
1953 ++ * 2 when patched PLT trampoline was detected
1954 ++ * 3 when unpatched PLT trampoline was detected
1955 ++ */
1956 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
1957 ++{
1958 ++
1959 ++#ifdef CONFIG_PAX_EMUPLT
1960 ++ int err;
1961 ++
1962 ++ do { /* PaX: patched PLT emulation #1 */
1963 ++ unsigned int ldah, ldq, jmp;
1964 ++
1965 ++ err = get_user(ldah, (unsigned int *)regs->pc);
1966 ++ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
1967 ++ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
1968 ++
1969 ++ if (err)
1970 ++ break;
1971 ++
1972 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
1973 ++ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
1974 ++ jmp == 0x6BFB0000U)
1975 ++ {
1976 ++ unsigned long r27, addr;
1977 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
1978 ++ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
1979 ++
1980 ++ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
1981 ++ err = get_user(r27, (unsigned long *)addr);
1982 ++ if (err)
1983 ++ break;
1984 ++
1985 ++ regs->r27 = r27;
1986 ++ regs->pc = r27;
1987 ++ return 2;
1988 ++ }
1989 ++ } while (0);
1990 ++
1991 ++ do { /* PaX: patched PLT emulation #2 */
1992 ++ unsigned int ldah, lda, br;
1993 ++
1994 ++ err = get_user(ldah, (unsigned int *)regs->pc);
1995 ++ err |= get_user(lda, (unsigned int *)(regs->pc+4));
1996 ++ err |= get_user(br, (unsigned int *)(regs->pc+8));
1997 ++
1998 ++ if (err)
1999 ++ break;
2000 ++
2001 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
2002 ++ (lda & 0xFFFF0000U) == 0xA77B0000U &&
2003 ++ (br & 0xFFE00000U) == 0xC3E00000U)
2004 ++ {
2005 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
2006 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
2007 ++ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
2008 ++
2009 ++ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
2010 ++ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
2011 ++ return 2;
2012 ++ }
2013 ++ } while (0);
2014 ++
2015 ++ do { /* PaX: unpatched PLT emulation */
2016 ++ unsigned int br;
2017 ++
2018 ++ err = get_user(br, (unsigned int *)regs->pc);
2019 ++
2020 ++ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
2021 ++ unsigned int br2, ldq, nop, jmp;
2022 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
2023 ++
2024 ++ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
2025 ++ err = get_user(br2, (unsigned int *)addr);
2026 ++ err |= get_user(ldq, (unsigned int *)(addr+4));
2027 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2028 ++ err |= get_user(jmp, (unsigned int *)(addr+12));
2029 ++ err |= get_user(resolver, (unsigned long *)(addr+16));
2030 ++
2031 ++ if (err)
2032 ++ break;
2033 ++
2034 ++ if (br2 == 0xC3600000U &&
2035 ++ ldq == 0xA77B000CU &&
2036 ++ nop == 0x47FF041FU &&
2037 ++ jmp == 0x6B7B0000U)
2038 ++ {
2039 ++ regs->r28 = regs->pc+4;
2040 ++ regs->r27 = addr+16;
2041 ++ regs->pc = resolver;
2042 ++ return 3;
2043 ++ }
2044 ++ }
2045 ++ } while (0);
2046 ++#endif
2047 ++
2048 ++ return 1;
2049 ++}
2050 ++
2051 ++void pax_report_insns(void *pc, void *sp)
2052 ++{
2053 ++ unsigned long i;
2054 ++
2055 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2056 ++ for (i = 0; i < 5; i++) {
2057 ++ unsigned int c;
2058 ++ if (get_user(c, (unsigned int *)pc+i))
2059 ++ printk(KERN_CONT "???????? ");
2060 ++ else
2061 ++ printk(KERN_CONT "%08x ", c);
2062 ++ }
2063 ++ printk("\n");
2064 ++}
2065 ++#endif
2066 +
2067 + /*
2068 + * This routine handles page faults. It determines the address,
2069 +@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
2070 + good_area:
2071 + si_code = SEGV_ACCERR;
2072 + if (cause < 0) {
2073 +- if (!(vma->vm_flags & VM_EXEC))
2074 ++ if (!(vma->vm_flags & VM_EXEC)) {
2075 ++
2076 ++#ifdef CONFIG_PAX_PAGEEXEC
2077 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
2078 ++ goto bad_area;
2079 ++
2080 ++ up_read(&mm->mmap_sem);
2081 ++ switch (pax_handle_fetch_fault(regs)) {
2082 ++
2083 ++#ifdef CONFIG_PAX_EMUPLT
2084 ++ case 2:
2085 ++ case 3:
2086 ++ return;
2087 ++#endif
2088 ++
2089 ++ }
2090 ++ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
2091 ++ do_group_exit(SIGKILL);
2092 ++#else
2093 + goto bad_area;
2094 ++#endif
2095 ++
2096 ++ }
2097 + } else if (!cause) {
2098 + /* Allow reads even for write-only mappings */
2099 + if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
2100 +diff -urNp linux-2.6.27.10/arch/arm/include/asm/elf.h linux-2.6.27.10/arch/arm/include/asm/elf.h
2101 +--- linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
2102 ++++ linux-2.6.27.10/arch/arm/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
2103 +@@ -87,7 +87,14 @@ extern char elf_platform[];
2104 + the loader. We need to make sure that it is out of the way of the program
2105 + that it will "exec", and that there is sufficient room for the brk. */
2106 +
2107 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2108 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2109 ++
2110 ++#ifdef CONFIG_PAX_ASLR
2111 ++#define PAX_ELF_ET_DYN_BASE 0x00008000UL
2112 ++
2113 ++#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2114 ++#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2115 ++#endif
2116 +
2117 + /* When the program starts, a1 contains a pointer to a function to be
2118 + registered with atexit, as per the SVR4 ABI. A value of 0 means we
2119 +diff -urNp linux-2.6.27.10/arch/arm/include/asm/kmap_types.h linux-2.6.27.10/arch/arm/include/asm/kmap_types.h
2120 +--- linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2121 ++++ linux-2.6.27.10/arch/arm/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2122 +@@ -18,6 +18,7 @@ enum km_type {
2123 + KM_IRQ1,
2124 + KM_SOFTIRQ0,
2125 + KM_SOFTIRQ1,
2126 ++ KM_CLEARPAGE,
2127 + KM_TYPE_NR
2128 + };
2129 +
2130 +diff -urNp linux-2.6.27.10/arch/arm/mm/mmap.c linux-2.6.27.10/arch/arm/mm/mmap.c
2131 +--- linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
2132 ++++ linux-2.6.27.10/arch/arm/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
2133 +@@ -60,6 +60,10 @@ arch_get_unmapped_area(struct file *filp
2134 + if (len > TASK_SIZE)
2135 + return -ENOMEM;
2136 +
2137 ++#ifdef CONFIG_PAX_RANDMMAP
2138 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
2139 ++#endif
2140 ++
2141 + if (addr) {
2142 + if (do_align)
2143 + addr = COLOUR_ALIGN(addr, pgoff);
2144 +@@ -72,10 +76,10 @@ arch_get_unmapped_area(struct file *filp
2145 + return addr;
2146 + }
2147 + if (len > mm->cached_hole_size) {
2148 +- start_addr = addr = mm->free_area_cache;
2149 ++ start_addr = addr = mm->free_area_cache;
2150 + } else {
2151 +- start_addr = addr = TASK_UNMAPPED_BASE;
2152 +- mm->cached_hole_size = 0;
2153 ++ start_addr = addr = mm->mmap_base;
2154 ++ mm->cached_hole_size = 0;
2155 + }
2156 +
2157 + full_search:
2158 +@@ -91,8 +95,8 @@ full_search:
2159 + * Start a new search - just in case we missed
2160 + * some holes.
2161 + */
2162 +- if (start_addr != TASK_UNMAPPED_BASE) {
2163 +- start_addr = addr = TASK_UNMAPPED_BASE;
2164 ++ if (start_addr != mm->mmap_base) {
2165 ++ start_addr = addr = mm->mmap_base;
2166 + mm->cached_hole_size = 0;
2167 + goto full_search;
2168 + }
2169 +diff -urNp linux-2.6.27.10/arch/avr32/include/asm/elf.h linux-2.6.27.10/arch/avr32/include/asm/elf.h
2170 +--- linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
2171 ++++ linux-2.6.27.10/arch/avr32/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
2172 +@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
2173 + the loader. We need to make sure that it is out of the way of the program
2174 + that it will "exec", and that there is sufficient room for the brk. */
2175 +
2176 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2177 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2178 +
2179 ++#ifdef CONFIG_PAX_ASLR
2180 ++#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2181 ++
2182 ++#define PAX_DELTA_MMAP_LEN 15
2183 ++#define PAX_DELTA_STACK_LEN 15
2184 ++#endif
2185 +
2186 + /* This yields a mask that user programs can use to figure out what
2187 + instruction set this CPU supports. This could be done in user space,
2188 +diff -urNp linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h
2189 +--- linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2190 ++++ linux-2.6.27.10/arch/avr32/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2191 +@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2192 + D(11) KM_IRQ1,
2193 + D(12) KM_SOFTIRQ0,
2194 + D(13) KM_SOFTIRQ1,
2195 +-D(14) KM_TYPE_NR
2196 ++D(14) KM_CLEARPAGE,
2197 ++D(15) KM_TYPE_NR
2198 + };
2199 +
2200 + #undef D
2201 +diff -urNp linux-2.6.27.10/arch/avr32/mm/fault.c linux-2.6.27.10/arch/avr32/mm/fault.c
2202 +--- linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2203 ++++ linux-2.6.27.10/arch/avr32/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2204 +@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
2205 +
2206 + int exception_trace = 1;
2207 +
2208 ++#ifdef CONFIG_PAX_PAGEEXEC
2209 ++void pax_report_insns(void *pc, void *sp)
2210 ++{
2211 ++ unsigned long i;
2212 ++
2213 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2214 ++ for (i = 0; i < 20; i++) {
2215 ++ unsigned char c;
2216 ++ if (get_user(c, (unsigned char *)pc+i))
2217 ++ printk(KERN_CONT "???????? ");
2218 ++ else
2219 ++ printk(KERN_CONT "%02x ", c);
2220 ++ }
2221 ++ printk("\n");
2222 ++}
2223 ++#endif
2224 ++
2225 + /*
2226 + * This routine handles page faults. It determines the address and the
2227 + * problem, and then passes it off to one of the appropriate routines.
2228 +@@ -157,6 +174,16 @@ bad_area:
2229 + up_read(&mm->mmap_sem);
2230 +
2231 + if (user_mode(regs)) {
2232 ++
2233 ++#ifdef CONFIG_PAX_PAGEEXEC
2234 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2235 ++ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2236 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2237 ++ do_group_exit(SIGKILL);
2238 ++ }
2239 ++ }
2240 ++#endif
2241 ++
2242 + if (exception_trace && printk_ratelimit())
2243 + printk("%s%s[%d]: segfault at %08lx pc %08lx "
2244 + "sp %08lx ecr %lu\n",
2245 +diff -urNp linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h
2246 +--- linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2247 ++++ linux-2.6.27.10/arch/blackfin/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2248 +@@ -15,6 +15,7 @@ enum km_type {
2249 + KM_IRQ1,
2250 + KM_SOFTIRQ0,
2251 + KM_SOFTIRQ1,
2252 ++ KM_CLEARPAGE,
2253 + KM_TYPE_NR
2254 + };
2255 +
2256 +diff -urNp linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h
2257 +--- linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2258 ++++ linux-2.6.27.10/arch/h8300/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2259 +@@ -15,6 +15,7 @@ enum km_type {
2260 + KM_IRQ1,
2261 + KM_SOFTIRQ0,
2262 + KM_SOFTIRQ1,
2263 ++ KM_CLEARPAGE,
2264 + KM_TYPE_NR
2265 + };
2266 +
2267 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c
2268 +--- linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-07 12:55:34.000000000 -0500
2269 ++++ linux-2.6.27.10/arch/ia64/ia32/binfmt_elf32.c 2008-11-18 03:38:43.000000000 -0500
2270 +@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
2271 +
2272 + #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
2273 +
2274 ++#ifdef CONFIG_PAX_ASLR
2275 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2276 ++
2277 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2278 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2279 ++#endif
2280 ++
2281 + /* Ugly but avoids duplication */
2282 + #include "../../../fs/binfmt_elf.c"
2283 +
2284 +diff -urNp linux-2.6.27.10/arch/ia64/ia32/ia32priv.h linux-2.6.27.10/arch/ia64/ia32/ia32priv.h
2285 +--- linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-07 12:55:34.000000000 -0500
2286 ++++ linux-2.6.27.10/arch/ia64/ia32/ia32priv.h 2008-11-18 03:38:43.000000000 -0500
2287 +@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
2288 + #define ELF_DATA ELFDATA2LSB
2289 + #define ELF_ARCH EM_386
2290 +
2291 +-#define IA32_STACK_TOP IA32_PAGE_OFFSET
2292 ++#ifdef CONFIG_PAX_RANDUSTACK
2293 ++#define __IA32_DELTA_STACK (current->mm->delta_stack)
2294 ++#else
2295 ++#define __IA32_DELTA_STACK 0UL
2296 ++#endif
2297 ++
2298 ++#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
2299 ++
2300 + #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
2301 + #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
2302 +
2303 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/elf.h linux-2.6.27.10/arch/ia64/include/asm/elf.h
2304 +--- linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
2305 ++++ linux-2.6.27.10/arch/ia64/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
2306 +@@ -43,6 +43,13 @@
2307 + */
2308 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2309 +
2310 ++#ifdef CONFIG_PAX_ASLR
2311 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2312 ++
2313 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2314 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2315 ++#endif
2316 ++
2317 + #define PT_IA_64_UNWIND 0x70000001
2318 +
2319 + /* IA-64 relocations: */
2320 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h
2321 +--- linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2322 ++++ linux-2.6.27.10/arch/ia64/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2323 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
2324 + D(10) KM_IRQ1,
2325 + D(11) KM_SOFTIRQ0,
2326 + D(12) KM_SOFTIRQ1,
2327 +-D(13) KM_TYPE_NR
2328 ++D(13) KM_CLEARPAGE,
2329 ++D(14) KM_TYPE_NR
2330 + };
2331 +
2332 + #undef D
2333 +diff -urNp linux-2.6.27.10/arch/ia64/include/asm/pgtable.h linux-2.6.27.10/arch/ia64/include/asm/pgtable.h
2334 +--- linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-07 12:55:34.000000000 -0500
2335 ++++ linux-2.6.27.10/arch/ia64/include/asm/pgtable.h 2008-11-18 03:39:50.000000000 -0500
2336 +@@ -143,6 +143,17 @@
2337 + #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2338 + #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2339 + #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2340 ++
2341 ++#ifdef CONFIG_PAX_PAGEEXEC
2342 ++# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2343 ++# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2344 ++# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2345 ++#else
2346 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
2347 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
2348 ++# define PAGE_COPY_NOEXEC PAGE_COPY
2349 ++#endif
2350 ++
2351 + #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2352 + #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2353 + #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2354 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/module.c linux-2.6.27.10/arch/ia64/kernel/module.c
2355 +--- linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
2356 ++++ linux-2.6.27.10/arch/ia64/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
2357 +@@ -312,8 +312,7 @@ module_alloc (unsigned long size)
2358 + void
2359 + module_free (struct module *mod, void *module_region)
2360 + {
2361 +- if (mod && mod->arch.init_unw_table &&
2362 +- module_region == mod->module_init) {
2363 ++ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2364 + unw_remove_unwind_table(mod->arch.init_unw_table);
2365 + mod->arch.init_unw_table = NULL;
2366 + }
2367 +@@ -491,15 +490,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
2368 + }
2369 +
2370 + static inline int
2371 ++in_init_rx (const struct module *mod, uint64_t addr)
2372 ++{
2373 ++ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2374 ++}
2375 ++
2376 ++static inline int
2377 ++in_init_rw (const struct module *mod, uint64_t addr)
2378 ++{
2379 ++ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2380 ++}
2381 ++
2382 ++static inline int
2383 + in_init (const struct module *mod, uint64_t addr)
2384 + {
2385 +- return addr - (uint64_t) mod->module_init < mod->init_size;
2386 ++ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2387 ++}
2388 ++
2389 ++static inline int
2390 ++in_core_rx (const struct module *mod, uint64_t addr)
2391 ++{
2392 ++ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2393 ++}
2394 ++
2395 ++static inline int
2396 ++in_core_rw (const struct module *mod, uint64_t addr)
2397 ++{
2398 ++ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2399 + }
2400 +
2401 + static inline int
2402 + in_core (const struct module *mod, uint64_t addr)
2403 + {
2404 +- return addr - (uint64_t) mod->module_core < mod->core_size;
2405 ++ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2406 + }
2407 +
2408 + static inline int
2409 +@@ -683,7 +706,14 @@ do_reloc (struct module *mod, uint8_t r_
2410 + break;
2411 +
2412 + case RV_BDREL:
2413 +- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2414 ++ if (in_init_rx(mod, val))
2415 ++ val -= (uint64_t) mod->module_init_rx;
2416 ++ else if (in_init_rw(mod, val))
2417 ++ val -= (uint64_t) mod->module_init_rw;
2418 ++ else if (in_core_rx(mod, val))
2419 ++ val -= (uint64_t) mod->module_core_rx;
2420 ++ else if (in_core_rw(mod, val))
2421 ++ val -= (uint64_t) mod->module_core_rw;
2422 + break;
2423 +
2424 + case RV_LTV:
2425 +@@ -817,15 +847,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
2426 + * addresses have been selected...
2427 + */
2428 + uint64_t gp;
2429 +- if (mod->core_size > MAX_LTOFF)
2430 ++ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2431 + /*
2432 + * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2433 + * at the end of the module.
2434 + */
2435 +- gp = mod->core_size - MAX_LTOFF / 2;
2436 ++ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2437 + else
2438 +- gp = mod->core_size / 2;
2439 +- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2440 ++ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2441 ++ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2442 + mod->arch.gp = gp;
2443 + DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2444 + }
2445 +diff -urNp linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c
2446 +--- linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-07 12:55:34.000000000 -0500
2447 ++++ linux-2.6.27.10/arch/ia64/kernel/sys_ia64.c 2008-11-18 03:38:43.000000000 -0500
2448 +@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
2449 + if (REGION_NUMBER(addr) == RGN_HPAGE)
2450 + addr = 0;
2451 + #endif
2452 ++
2453 ++#ifdef CONFIG_PAX_RANDMMAP
2454 ++ if ((mm->pax_flags & MF_PAX_RANDMMAP) && addr && filp)
2455 ++ addr = mm->free_area_cache;
2456 ++ else
2457 ++#endif
2458 ++
2459 + if (!addr)
2460 + addr = mm->free_area_cache;
2461 +
2462 +@@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil
2463 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2464 + /* At this point: (!vma || addr < vma->vm_end). */
2465 + if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2466 +- if (start_addr != TASK_UNMAPPED_BASE) {
2467 ++ if (start_addr != mm->mmap_base) {
2468 + /* Start a new search --- just in case we missed some holes. */
2469 +- addr = TASK_UNMAPPED_BASE;
2470 ++ addr = mm->mmap_base;
2471 + goto full_search;
2472 + }
2473 + return -ENOMEM;
2474 +diff -urNp linux-2.6.27.10/arch/ia64/mm/fault.c linux-2.6.27.10/arch/ia64/mm/fault.c
2475 +--- linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2476 ++++ linux-2.6.27.10/arch/ia64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2477 +@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
2478 + return pte_present(pte);
2479 + }
2480 +
2481 ++#ifdef CONFIG_PAX_PAGEEXEC
2482 ++void pax_report_insns(void *pc, void *sp)
2483 ++{
2484 ++ unsigned long i;
2485 ++
2486 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2487 ++ for (i = 0; i < 8; i++) {
2488 ++ unsigned int c;
2489 ++ if (get_user(c, (unsigned int *)pc+i))
2490 ++ printk(KERN_CONT "???????? ");
2491 ++ else
2492 ++ printk(KERN_CONT "%08x ", c);
2493 ++ }
2494 ++ printk("\n");
2495 ++}
2496 ++#endif
2497 ++
2498 + void __kprobes
2499 + ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2500 + {
2501 +@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
2502 + mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2503 + | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2504 +
2505 +- if ((vma->vm_flags & mask) != mask)
2506 ++ if ((vma->vm_flags & mask) != mask) {
2507 ++
2508 ++#ifdef CONFIG_PAX_PAGEEXEC
2509 ++ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2510 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2511 ++ goto bad_area;
2512 ++
2513 ++ up_read(&mm->mmap_sem);
2514 ++ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2515 ++ do_group_exit(SIGKILL);
2516 ++ }
2517 ++#endif
2518 ++
2519 + goto bad_area;
2520 +
2521 ++ }
2522 ++
2523 + survive:
2524 + /*
2525 + * If for any reason at all we couldn't handle the fault, make
2526 +diff -urNp linux-2.6.27.10/arch/ia64/mm/init.c linux-2.6.27.10/arch/ia64/mm/init.c
2527 +--- linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-07 12:55:34.000000000 -0500
2528 ++++ linux-2.6.27.10/arch/ia64/mm/init.c 2008-11-18 03:38:43.000000000 -0500
2529 +@@ -122,6 +122,19 @@ ia64_init_addr_space (void)
2530 + vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2531 + vma->vm_end = vma->vm_start + PAGE_SIZE;
2532 + vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2533 ++
2534 ++#ifdef CONFIG_PAX_PAGEEXEC
2535 ++ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2536 ++ vma->vm_flags &= ~VM_EXEC;
2537 ++
2538 ++#ifdef CONFIG_PAX_MPROTECT
2539 ++ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2540 ++ vma->vm_flags &= ~VM_MAYEXEC;
2541 ++#endif
2542 ++
2543 ++ }
2544 ++#endif
2545 ++
2546 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2547 + down_write(&current->mm->mmap_sem);
2548 + if (insert_vm_struct(current->mm, vma)) {
2549 +diff -urNp linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h
2550 +--- linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
2551 ++++ linux-2.6.27.10/arch/m68knommu/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
2552 +@@ -15,6 +15,7 @@ enum km_type {
2553 + KM_IRQ1,
2554 + KM_SOFTIRQ0,
2555 + KM_SOFTIRQ1,
2556 ++ KM_CLEARPAGE,
2557 + KM_TYPE_NR
2558 + };
2559 +
2560 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c
2561 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-07 12:55:34.000000000 -0500
2562 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfn32.c 2008-11-18 03:38:43.000000000 -0500
2563 +@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2564 + #undef ELF_ET_DYN_BASE
2565 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2566 +
2567 ++#ifdef CONFIG_PAX_ASLR
2568 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2569 ++
2570 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2571 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2572 ++#endif
2573 ++
2574 + #include <asm/processor.h>
2575 + #include <linux/module.h>
2576 + #include <linux/elfcore.h>
2577 +diff -urNp linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c
2578 +--- linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-07 12:55:34.000000000 -0500
2579 ++++ linux-2.6.27.10/arch/mips/kernel/binfmt_elfo32.c 2008-11-18 03:38:43.000000000 -0500
2580 +@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2581 + #undef ELF_ET_DYN_BASE
2582 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2583 +
2584 ++#ifdef CONFIG_PAX_ASLR
2585 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2586 ++
2587 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2588 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2589 ++#endif
2590 ++
2591 + #include <asm/processor.h>
2592 + #include <linux/module.h>
2593 + #include <linux/elfcore.h>
2594 +diff -urNp linux-2.6.27.10/arch/mips/kernel/process.c linux-2.6.27.10/arch/mips/kernel/process.c
2595 +--- linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-07 12:55:34.000000000 -0500
2596 ++++ linux-2.6.27.10/arch/mips/kernel/process.c 2008-11-18 03:38:43.000000000 -0500
2597 +@@ -458,15 +458,3 @@ unsigned long get_wchan(struct task_stru
2598 + out:
2599 + return pc;
2600 + }
2601 +-
2602 +-/*
2603 +- * Don't forget that the stack pointer must be aligned on a 8 bytes
2604 +- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2605 +- */
2606 +-unsigned long arch_align_stack(unsigned long sp)
2607 +-{
2608 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2609 +- sp -= get_random_int() & ~PAGE_MASK;
2610 +-
2611 +- return sp & ALMASK;
2612 +-}
2613 +diff -urNp linux-2.6.27.10/arch/mips/kernel/syscall.c linux-2.6.27.10/arch/mips/kernel/syscall.c
2614 +--- linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-07 12:55:34.000000000 -0500
2615 ++++ linux-2.6.27.10/arch/mips/kernel/syscall.c 2008-11-18 03:38:43.000000000 -0500
2616 +@@ -100,6 +100,11 @@ unsigned long arch_get_unmapped_area(str
2617 + do_color_align = 0;
2618 + if (filp || (flags & MAP_SHARED))
2619 + do_color_align = 1;
2620 ++
2621 ++#ifdef CONFIG_PAX_RANDMMAP
2622 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
2623 ++#endif
2624 ++
2625 + if (addr) {
2626 + if (do_color_align)
2627 + addr = COLOUR_ALIGN(addr, pgoff);
2628 +@@ -110,7 +115,7 @@ unsigned long arch_get_unmapped_area(str
2629 + (!vmm || addr + len <= vmm->vm_start))
2630 + return addr;
2631 + }
2632 +- addr = TASK_UNMAPPED_BASE;
2633 ++ addr = current->mm->mmap_base;
2634 + if (do_color_align)
2635 + addr = COLOUR_ALIGN(addr, pgoff);
2636 + else
2637 +diff -urNp linux-2.6.27.10/arch/mips/mm/fault.c linux-2.6.27.10/arch/mips/mm/fault.c
2638 +--- linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2639 ++++ linux-2.6.27.10/arch/mips/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2640 +@@ -26,6 +26,23 @@
2641 + #include <asm/ptrace.h>
2642 + #include <asm/highmem.h> /* For VMALLOC_END */
2643 +
2644 ++#ifdef CONFIG_PAX_PAGEEXEC
2645 ++void pax_report_insns(void *pc)
2646 ++{
2647 ++ unsigned long i;
2648 ++
2649 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2650 ++ for (i = 0; i < 5; i++) {
2651 ++ unsigned int c;
2652 ++ if (get_user(c, (unsigned int *)pc+i))
2653 ++ printk(KERN_CONT "???????? ");
2654 ++ else
2655 ++ printk(KERN_CONT "%08x ", c);
2656 ++ }
2657 ++ printk("\n");
2658 ++}
2659 ++#endif
2660 ++
2661 + /*
2662 + * This routine handles page faults. It determines the address,
2663 + * and the problem, and then passes it off to one of the appropriate
2664 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/module.c linux-2.6.27.10/arch/parisc/kernel/module.c
2665 +--- linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
2666 ++++ linux-2.6.27.10/arch/parisc/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
2667 +@@ -75,16 +75,38 @@
2668 +
2669 + /* three functions to determine where in the module core
2670 + * or init pieces the location is */
2671 ++static inline int in_init_rx(struct module *me, void *loc)
2672 ++{
2673 ++ return (loc >= me->module_init_rx &&
2674 ++ loc < (me->module_init_rx + me->init_size_rx));
2675 ++}
2676 ++
2677 ++static inline int in_init_rw(struct module *me, void *loc)
2678 ++{
2679 ++ return (loc >= me->module_init_rw &&
2680 ++ loc < (me->module_init_rw + me->init_size_rw));
2681 ++}
2682 ++
2683 + static inline int in_init(struct module *me, void *loc)
2684 + {
2685 +- return (loc >= me->module_init &&
2686 +- loc <= (me->module_init + me->init_size));
2687 ++ return in_init_rx(me, loc) || in_init_rw(me, loc);
2688 ++}
2689 ++
2690 ++static inline int in_core_rx(struct module *me, void *loc)
2691 ++{
2692 ++ return (loc >= me->module_core_rx &&
2693 ++ loc < (me->module_core_rx + me->core_size_rx));
2694 ++}
2695 ++
2696 ++static inline int in_core_rw(struct module *me, void *loc)
2697 ++{
2698 ++ return (loc >= me->module_core_rw &&
2699 ++ loc < (me->module_core_rw + me->core_size_rw));
2700 + }
2701 +
2702 + static inline int in_core(struct module *me, void *loc)
2703 + {
2704 +- return (loc >= me->module_core &&
2705 +- loc <= (me->module_core + me->core_size));
2706 ++ return in_core_rx(me, loc) || in_core_rw(me, loc);
2707 + }
2708 +
2709 + static inline int in_local(struct module *me, void *loc)
2710 +@@ -298,21 +320,21 @@ int module_frob_arch_sections(CONST Elf_
2711 + }
2712 +
2713 + /* align things a bit */
2714 +- me->core_size = ALIGN(me->core_size, 16);
2715 +- me->arch.got_offset = me->core_size;
2716 +- me->core_size += gots * sizeof(struct got_entry);
2717 +-
2718 +- me->core_size = ALIGN(me->core_size, 16);
2719 +- me->arch.fdesc_offset = me->core_size;
2720 +- me->core_size += fdescs * sizeof(Elf_Fdesc);
2721 +-
2722 +- me->core_size = ALIGN(me->core_size, 16);
2723 +- me->arch.stub_offset = me->core_size;
2724 +- me->core_size += stubs * sizeof(struct stub_entry);
2725 +-
2726 +- me->init_size = ALIGN(me->init_size, 16);
2727 +- me->arch.init_stub_offset = me->init_size;
2728 +- me->init_size += init_stubs * sizeof(struct stub_entry);
2729 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
2730 ++ me->arch.got_offset = me->core_size_rw;
2731 ++ me->core_size_rw += gots * sizeof(struct got_entry);
2732 ++
2733 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
2734 ++ me->arch.fdesc_offset = me->core_size_rw;
2735 ++ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
2736 ++
2737 ++ me->core_size_rx = ALIGN(me->core_size_rx, 16);
2738 ++ me->arch.stub_offset = me->core_size_rx;
2739 ++ me->core_size_rx += stubs * sizeof(struct stub_entry);
2740 ++
2741 ++ me->init_size_rx = ALIGN(me->init_size_rx, 16);
2742 ++ me->arch.init_stub_offset = me->init_size_rx;
2743 ++ me->init_size_rx += init_stubs * sizeof(struct stub_entry);
2744 +
2745 + me->arch.got_max = gots;
2746 + me->arch.fdesc_max = fdescs;
2747 +@@ -332,7 +354,7 @@ static Elf64_Word get_got(struct module
2748 +
2749 + BUG_ON(value == 0);
2750 +
2751 +- got = me->module_core + me->arch.got_offset;
2752 ++ got = me->module_core_rw + me->arch.got_offset;
2753 + for (i = 0; got[i].addr; i++)
2754 + if (got[i].addr == value)
2755 + goto out;
2756 +@@ -350,7 +372,7 @@ static Elf64_Word get_got(struct module
2757 + #ifdef CONFIG_64BIT
2758 + static Elf_Addr get_fdesc(struct module *me, unsigned long value)
2759 + {
2760 +- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
2761 ++ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
2762 +
2763 + if (!value) {
2764 + printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
2765 +@@ -368,7 +390,7 @@ static Elf_Addr get_fdesc(struct module
2766 +
2767 + /* Create new one */
2768 + fdesc->addr = value;
2769 +- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2770 ++ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2771 + return (Elf_Addr)fdesc;
2772 + }
2773 + #endif /* CONFIG_64BIT */
2774 +@@ -388,12 +410,12 @@ static Elf_Addr get_stub(struct module *
2775 + if(init_section) {
2776 + i = me->arch.init_stub_count++;
2777 + BUG_ON(me->arch.init_stub_count > me->arch.init_stub_max);
2778 +- stub = me->module_init + me->arch.init_stub_offset +
2779 ++ stub = me->module_init_rx + me->arch.init_stub_offset +
2780 + i * sizeof(struct stub_entry);
2781 + } else {
2782 + i = me->arch.stub_count++;
2783 + BUG_ON(me->arch.stub_count > me->arch.stub_max);
2784 +- stub = me->module_core + me->arch.stub_offset +
2785 ++ stub = me->module_core_rx + me->arch.stub_offset +
2786 + i * sizeof(struct stub_entry);
2787 + }
2788 +
2789 +@@ -761,7 +783,7 @@ register_unwind_table(struct module *me,
2790 +
2791 + table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
2792 + end = table + sechdrs[me->arch.unwind_section].sh_size;
2793 +- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
2794 ++ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
2795 +
2796 + DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
2797 + me->arch.unwind_section, table, end, gp);
2798 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c
2799 +--- linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-07 12:55:34.000000000 -0500
2800 ++++ linux-2.6.27.10/arch/parisc/kernel/sys_parisc.c 2008-11-18 03:38:43.000000000 -0500
2801 +@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
2802 + if (flags & MAP_FIXED)
2803 + return addr;
2804 + if (!addr)
2805 +- addr = TASK_UNMAPPED_BASE;
2806 ++ addr = current->mm->mmap_base;
2807 +
2808 + if (filp) {
2809 + addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
2810 +diff -urNp linux-2.6.27.10/arch/parisc/kernel/traps.c linux-2.6.27.10/arch/parisc/kernel/traps.c
2811 +--- linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:36.000000000 -0500
2812 ++++ linux-2.6.27.10/arch/parisc/kernel/traps.c 2008-12-10 22:35:46.000000000 -0500
2813 +@@ -731,9 +731,7 @@ void handle_interruption(int code, struc
2814 +
2815 + down_read(&current->mm->mmap_sem);
2816 + vma = find_vma(current->mm,regs->iaoq[0]);
2817 +- if (vma && (regs->iaoq[0] >= vma->vm_start)
2818 +- && (vma->vm_flags & VM_EXEC)) {
2819 +-
2820 ++ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
2821 + fault_address = regs->iaoq[0];
2822 + fault_space = regs->iasq[0];
2823 +
2824 +diff -urNp linux-2.6.27.10/arch/parisc/mm/fault.c linux-2.6.27.10/arch/parisc/mm/fault.c
2825 +--- linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
2826 ++++ linux-2.6.27.10/arch/parisc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
2827 +@@ -16,6 +16,7 @@
2828 + #include <linux/sched.h>
2829 + #include <linux/interrupt.h>
2830 + #include <linux/module.h>
2831 ++#include <linux/unistd.h>
2832 +
2833 + #include <asm/uaccess.h>
2834 + #include <asm/traps.h>
2835 +@@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex
2836 + static unsigned long
2837 + parisc_acctyp(unsigned long code, unsigned int inst)
2838 + {
2839 +- if (code == 6 || code == 16)
2840 ++ if (code == 6 || code == 7 || code == 16)
2841 + return VM_EXEC;
2842 +
2843 + switch (inst & 0xf0000000) {
2844 +@@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign
2845 + }
2846 + #endif
2847 +
2848 ++#ifdef CONFIG_PAX_PAGEEXEC
2849 ++/*
2850 ++ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
2851 ++ *
2852 ++ * returns 1 when task should be killed
2853 ++ * 2 when rt_sigreturn trampoline was detected
2854 ++ * 3 when unpatched PLT trampoline was detected
2855 ++ */
2856 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2857 ++{
2858 ++
2859 ++#ifdef CONFIG_PAX_EMUPLT
2860 ++ int err;
2861 ++
2862 ++ do { /* PaX: unpatched PLT emulation */
2863 ++ unsigned int bl, depwi;
2864 ++
2865 ++ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
2866 ++ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
2867 ++
2868 ++ if (err)
2869 ++ break;
2870 ++
2871 ++ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
2872 ++ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
2873 ++
2874 ++ err = get_user(ldw, (unsigned int *)addr);
2875 ++ err |= get_user(bv, (unsigned int *)(addr+4));
2876 ++ err |= get_user(ldw2, (unsigned int *)(addr+8));
2877 ++
2878 ++ if (err)
2879 ++ break;
2880 ++
2881 ++ if (ldw == 0x0E801096U &&
2882 ++ bv == 0xEAC0C000U &&
2883 ++ ldw2 == 0x0E881095U)
2884 ++ {
2885 ++ unsigned int resolver, map;
2886 ++
2887 ++ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
2888 ++ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
2889 ++ if (err)
2890 ++ break;
2891 ++
2892 ++ regs->gr[20] = instruction_pointer(regs)+8;
2893 ++ regs->gr[21] = map;
2894 ++ regs->gr[22] = resolver;
2895 ++ regs->iaoq[0] = resolver | 3UL;
2896 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
2897 ++ return 3;
2898 ++ }
2899 ++ }
2900 ++ } while (0);
2901 ++#endif
2902 ++
2903 ++#ifdef CONFIG_PAX_EMUTRAMP
2904 ++
2905 ++#ifndef CONFIG_PAX_EMUSIGRT
2906 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
2907 ++ return 1;
2908 ++#endif
2909 ++
2910 ++ do { /* PaX: rt_sigreturn emulation */
2911 ++ unsigned int ldi1, ldi2, bel, nop;
2912 ++
2913 ++ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
2914 ++ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
2915 ++ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
2916 ++ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
2917 ++
2918 ++ if (err)
2919 ++ break;
2920 ++
2921 ++ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
2922 ++ ldi2 == 0x3414015AU &&
2923 ++ bel == 0xE4008200U &&
2924 ++ nop == 0x08000240U)
2925 ++ {
2926 ++ regs->gr[25] = (ldi1 & 2) >> 1;
2927 ++ regs->gr[20] = __NR_rt_sigreturn;
2928 ++ regs->gr[31] = regs->iaoq[1] + 16;
2929 ++ regs->sr[0] = regs->iasq[1];
2930 ++ regs->iaoq[0] = 0x100UL;
2931 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
2932 ++ regs->iasq[0] = regs->sr[2];
2933 ++ regs->iasq[1] = regs->sr[2];
2934 ++ return 2;
2935 ++ }
2936 ++ } while (0);
2937 ++#endif
2938 ++
2939 ++ return 1;
2940 ++}
2941 ++
2942 ++void pax_report_insns(void *pc, void *sp)
2943 ++{
2944 ++ unsigned long i;
2945 ++
2946 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2947 ++ for (i = 0; i < 5; i++) {
2948 ++ unsigned int c;
2949 ++ if (get_user(c, (unsigned int *)pc+i))
2950 ++ printk(KERN_CONT "???????? ");
2951 ++ else
2952 ++ printk(KERN_CONT "%08x ", c);
2953 ++ }
2954 ++ printk("\n");
2955 ++}
2956 ++#endif
2957 ++
2958 + void do_page_fault(struct pt_regs *regs, unsigned long code,
2959 + unsigned long address)
2960 + {
2961 +@@ -165,8 +276,33 @@ good_area:
2962 +
2963 + acc_type = parisc_acctyp(code,regs->iir);
2964 +
2965 +- if ((vma->vm_flags & acc_type) != acc_type)
2966 ++ if ((vma->vm_flags & acc_type) != acc_type) {
2967 ++
2968 ++#ifdef CONFIG_PAX_PAGEEXEC
2969 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
2970 ++ (address & ~3UL) == instruction_pointer(regs))
2971 ++ {
2972 ++ up_read(&mm->mmap_sem);
2973 ++ switch (pax_handle_fetch_fault(regs)) {
2974 ++
2975 ++#ifdef CONFIG_PAX_EMUPLT
2976 ++ case 3:
2977 ++ return;
2978 ++#endif
2979 ++
2980 ++#ifdef CONFIG_PAX_EMUTRAMP
2981 ++ case 2:
2982 ++ return;
2983 ++#endif
2984 ++
2985 ++ }
2986 ++ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
2987 ++ do_group_exit(SIGKILL);
2988 ++ }
2989 ++#endif
2990 ++
2991 + goto bad_area;
2992 ++ }
2993 +
2994 + /*
2995 + * If for any reason at all we couldn't handle the fault, make
2996 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/elf.h linux-2.6.27.10/arch/powerpc/include/asm/elf.h
2997 +--- linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-07 12:55:34.000000000 -0500
2998 ++++ linux-2.6.27.10/arch/powerpc/include/asm/elf.h 2008-11-18 03:39:50.000000000 -0500
2999 +@@ -180,6 +180,18 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
3000 +
3001 + #define ELF_ET_DYN_BASE (0x20000000)
3002 +
3003 ++#ifdef CONFIG_PAX_ASLR
3004 ++#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3005 ++
3006 ++#ifdef __powerpc64__
3007 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
3008 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
3009 ++#else
3010 ++#define PAX_DELTA_MMAP_LEN 15
3011 ++#define PAX_DELTA_STACK_LEN 15
3012 ++#endif
3013 ++#endif
3014 ++
3015 + /*
3016 + * Our registers are always unsigned longs, whether we're a 32 bit
3017 + * process or 64 bit, on either a 64 bit or 32 bit kernel.
3018 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h
3019 +--- linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
3020 ++++ linux-2.6.27.10/arch/powerpc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
3021 +@@ -26,6 +26,7 @@ enum km_type {
3022 + KM_SOFTIRQ1,
3023 + KM_PPC_SYNC_PAGE,
3024 + KM_PPC_SYNC_ICACHE,
3025 ++ KM_CLEARPAGE,
3026 + KM_TYPE_NR
3027 + };
3028 +
3029 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/page_64.h linux-2.6.27.10/arch/powerpc/include/asm/page_64.h
3030 +--- linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-07 12:55:34.000000000 -0500
3031 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page_64.h 2008-11-18 03:39:50.000000000 -0500
3032 +@@ -170,15 +170,18 @@ do { \
3033 + * stack by default, so in the absense of a PT_GNU_STACK program header
3034 + * we turn execute permission off.
3035 + */
3036 +-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3037 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3038 ++#define VM_STACK_DEFAULT_FLAGS32 \
3039 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3040 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3041 +
3042 + #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3043 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3044 +
3045 ++#ifndef CONFIG_PAX_PAGEEXEC
3046 + #define VM_STACK_DEFAULT_FLAGS \
3047 + (test_thread_flag(TIF_32BIT) ? \
3048 + VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3049 ++#endif
3050 +
3051 + #include <asm-generic/page.h>
3052 +
3053 +diff -urNp linux-2.6.27.10/arch/powerpc/include/asm/page.h linux-2.6.27.10/arch/powerpc/include/asm/page.h
3054 +--- linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-07 12:55:34.000000000 -0500
3055 ++++ linux-2.6.27.10/arch/powerpc/include/asm/page.h 2008-11-18 03:39:50.000000000 -0500
3056 +@@ -100,8 +100,9 @@ extern phys_addr_t kernstart_addr;
3057 + * and needs to be executable. This means the whole heap ends
3058 + * up being executable.
3059 + */
3060 +-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3061 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3062 ++#define VM_DATA_DEFAULT_FLAGS32 \
3063 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3064 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3065 +
3066 + #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3067 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3068 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/module_32.c linux-2.6.27.10/arch/powerpc/kernel/module_32.c
3069 +--- linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
3070 ++++ linux-2.6.27.10/arch/powerpc/kernel/module_32.c 2008-11-18 03:38:43.000000000 -0500
3071 +@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3072 + me->arch.core_plt_section = i;
3073 + }
3074 + if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3075 +- printk("Module doesn't contain .plt or .init.plt sections.\n");
3076 ++ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3077 + return -ENOEXEC;
3078 + }
3079 +
3080 +@@ -199,11 +199,16 @@ static uint32_t do_plt_call(void *locati
3081 +
3082 + DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3083 + /* Init, or core PLT? */
3084 +- if (location >= mod->module_core
3085 +- && location < mod->module_core + mod->core_size)
3086 ++ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3087 ++ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3088 + entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3089 +- else
3090 ++ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3091 ++ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3092 + entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3093 ++ else {
3094 ++ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3095 ++ return ~0UL;
3096 ++ }
3097 +
3098 + /* Find this entry, or if that fails, the next avail. entry */
3099 + while (entry->jump[0]) {
3100 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_32.c linux-2.6.27.10/arch/powerpc/kernel/signal_32.c
3101 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
3102 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_32.c 2008-11-18 03:38:43.000000000 -0500
3103 +@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
3104 + /* Save user registers on the stack */
3105 + frame = &rt_sf->uc.uc_mcontext;
3106 + addr = frame;
3107 +- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3108 ++ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3109 + if (save_user_regs(regs, frame, 0))
3110 + goto badframe;
3111 + regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3112 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/signal_64.c linux-2.6.27.10/arch/powerpc/kernel/signal_64.c
3113 +--- linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
3114 ++++ linux-2.6.27.10/arch/powerpc/kernel/signal_64.c 2008-11-18 03:38:43.000000000 -0500
3115 +@@ -434,7 +434,7 @@ int handle_rt_signal64(int signr, struct
3116 + current->thread.fpscr.val = 0;
3117 +
3118 + /* Set up to return from userspace. */
3119 +- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3120 ++ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3121 + regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3122 + } else {
3123 + err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3124 +diff -urNp linux-2.6.27.10/arch/powerpc/kernel/vdso.c linux-2.6.27.10/arch/powerpc/kernel/vdso.c
3125 +--- linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-07 12:55:34.000000000 -0500
3126 ++++ linux-2.6.27.10/arch/powerpc/kernel/vdso.c 2008-11-18 03:38:43.000000000 -0500
3127 +@@ -212,7 +212,7 @@ int arch_setup_additional_pages(struct l
3128 + vdso_base = VDSO32_MBASE;
3129 + #endif
3130 +
3131 +- current->mm->context.vdso_base = 0;
3132 ++ current->mm->context.vdso_base = ~0UL;
3133 +
3134 + /* vDSO has a problem and was disabled, just don't "enable" it for the
3135 + * process
3136 +@@ -229,7 +229,7 @@ int arch_setup_additional_pages(struct l
3137 + */
3138 + down_write(&mm->mmap_sem);
3139 + vdso_base = get_unmapped_area(NULL, vdso_base,
3140 +- vdso_pages << PAGE_SHIFT, 0, 0);
3141 ++ vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE);
3142 + if (IS_ERR_VALUE(vdso_base)) {
3143 + rc = vdso_base;
3144 + goto fail_mmapsem;
3145 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/fault.c linux-2.6.27.10/arch/powerpc/mm/fault.c
3146 +--- linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
3147 ++++ linux-2.6.27.10/arch/powerpc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
3148 +@@ -29,6 +29,10 @@
3149 + #include <linux/module.h>
3150 + #include <linux/kprobes.h>
3151 + #include <linux/kdebug.h>
3152 ++#include <linux/slab.h>
3153 ++#include <linux/pagemap.h>
3154 ++#include <linux/compiler.h>
3155 ++#include <linux/unistd.h>
3156 +
3157 + #include <asm/page.h>
3158 + #include <asm/pgtable.h>
3159 +@@ -62,6 +66,363 @@ static inline int notify_page_fault(stru
3160 + }
3161 + #endif
3162 +
3163 ++#ifdef CONFIG_PAX_EMUSIGRT
3164 ++void pax_syscall_close(struct vm_area_struct *vma)
3165 ++{
3166 ++ vma->vm_mm->call_syscall = 0UL;
3167 ++}
3168 ++
3169 ++static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
3170 ++{
3171 ++ unsigned int *kaddr;
3172 ++
3173 ++ vmf->page = alloc_page(GFP_HIGHUSER);
3174 ++ if (!vmf->page)
3175 ++ return VM_FAULT_OOM;
3176 ++
3177 ++ kaddr = kmap(vmf->page);
3178 ++ memset(kaddr, 0, PAGE_SIZE);
3179 ++ kaddr[0] = 0x44000002U; /* sc */
3180 ++ __flush_dcache_icache(kaddr);
3181 ++ kunmap(vmf->page);
3182 ++ return VM_FAULT_MAJOR;
3183 ++}
3184 ++
3185 ++static struct vm_operations_struct pax_vm_ops = {
3186 ++ .close = pax_syscall_close,
3187 ++ .fault = pax_syscall_fault
3188 ++};
3189 ++
3190 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
3191 ++{
3192 ++ int ret;
3193 ++
3194 ++ vma->vm_mm = current->mm;
3195 ++ vma->vm_start = addr;
3196 ++ vma->vm_end = addr + PAGE_SIZE;
3197 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
3198 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3199 ++ vma->vm_ops = &pax_vm_ops;
3200 ++
3201 ++ ret = insert_vm_struct(current->mm, vma);
3202 ++ if (ret)
3203 ++ return ret;
3204 ++
3205 ++ ++current->mm->total_vm;
3206 ++ return 0;
3207 ++}
3208 ++#endif
3209 ++
3210 ++#ifdef CONFIG_PAX_PAGEEXEC
3211 ++/*
3212 ++ * PaX: decide what to do with offenders (regs->nip = fault address)
3213 ++ *
3214 ++ * returns 1 when task should be killed
3215 ++ * 2 when patched GOT trampoline was detected
3216 ++ * 3 when patched PLT trampoline was detected
3217 ++ * 4 when unpatched PLT trampoline was detected
3218 ++ * 5 when sigreturn trampoline was detected
3219 ++ * 6 when rt_sigreturn trampoline was detected
3220 ++ */
3221 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
3222 ++{
3223 ++
3224 ++#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT)
3225 ++ int err;
3226 ++#endif
3227 ++
3228 ++#ifdef CONFIG_PAX_EMUPLT
3229 ++ do { /* PaX: patched GOT emulation */
3230 ++ unsigned int blrl;
3231 ++
3232 ++ err = get_user(blrl, (unsigned int *)regs->nip);
3233 ++
3234 ++ if (!err && blrl == 0x4E800021U) {
3235 ++ unsigned long temp = regs->nip;
3236 ++
3237 ++ regs->nip = regs->link & 0xFFFFFFFCUL;
3238 ++ regs->link = temp + 4UL;
3239 ++ return 2;
3240 ++ }
3241 ++ } while (0);
3242 ++
3243 ++ do { /* PaX: patched PLT emulation #1 */
3244 ++ unsigned int b;
3245 ++
3246 ++ err = get_user(b, (unsigned int *)regs->nip);
3247 ++
3248 ++ if (!err && (b & 0xFC000003U) == 0x48000000U) {
3249 ++ regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
3250 ++ return 3;
3251 ++ }
3252 ++ } while (0);
3253 ++
3254 ++ do { /* PaX: unpatched PLT emulation #1 */
3255 ++ unsigned int li, b;
3256 ++
3257 ++ err = get_user(li, (unsigned int *)regs->nip);
3258 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
3259 ++
3260 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
3261 ++ unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
3262 ++ unsigned long addr = b | 0xFC000000UL;
3263 ++
3264 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
3265 ++ err = get_user(rlwinm, (unsigned int *)addr);
3266 ++ err |= get_user(add, (unsigned int *)(addr+4));
3267 ++ err |= get_user(li2, (unsigned int *)(addr+8));
3268 ++ err |= get_user(addis2, (unsigned int *)(addr+12));
3269 ++ err |= get_user(mtctr, (unsigned int *)(addr+16));
3270 ++ err |= get_user(li3, (unsigned int *)(addr+20));
3271 ++ err |= get_user(addis3, (unsigned int *)(addr+24));
3272 ++ err |= get_user(bctr, (unsigned int *)(addr+28));
3273 ++
3274 ++ if (err)
3275 ++ break;
3276 ++
3277 ++ if (rlwinm == 0x556C083CU &&
3278 ++ add == 0x7D6C5A14U &&
3279 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
3280 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
3281 ++ mtctr == 0x7D8903A6U &&
3282 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
3283 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
3284 ++ bctr == 0x4E800420U)
3285 ++ {
3286 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3287 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3288 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
3289 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3290 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
3291 ++ regs->nip = regs->ctr;
3292 ++ return 4;
3293 ++ }
3294 ++ }
3295 ++ } while (0);
3296 ++
3297 ++#if 0
3298 ++ do { /* PaX: unpatched PLT emulation #2 */
3299 ++ unsigned int lis, lwzu, b, bctr;
3300 ++
3301 ++ err = get_user(lis, (unsigned int *)regs->nip);
3302 ++ err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
3303 ++ err |= get_user(b, (unsigned int *)(regs->nip+8));
3304 ++ err |= get_user(bctr, (unsigned int *)(regs->nip+12));
3305 ++
3306 ++ if (err)
3307 ++ break;
3308 ++
3309 ++ if ((lis & 0xFFFF0000U) == 0x39600000U &&
3310 ++ (lwzu & 0xU) == 0xU &&
3311 ++ (b & 0xFC000003U) == 0x48000000U &&
3312 ++ bctr == 0x4E800420U)
3313 ++ {
3314 ++ unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
3315 ++ unsigned long addr = b | 0xFC000000UL;
3316 ++
3317 ++ addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
3318 ++ err = get_user(addis, (unsigned int *)addr);
3319 ++ err |= get_user(addi, (unsigned int *)(addr+4));
3320 ++ err |= get_user(rlwinm, (unsigned int *)(addr+8));
3321 ++ err |= get_user(add, (unsigned int *)(addr+12));
3322 ++ err |= get_user(li2, (unsigned int *)(addr+16));
3323 ++ err |= get_user(addis2, (unsigned int *)(addr+20));
3324 ++ err |= get_user(mtctr, (unsigned int *)(addr+24));
3325 ++ err |= get_user(li3, (unsigned int *)(addr+28));
3326 ++ err |= get_user(addis3, (unsigned int *)(addr+32));
3327 ++ err |= get_user(bctr, (unsigned int *)(addr+36));
3328 ++
3329 ++ if (err)
3330 ++ break;
3331 ++
3332 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
3333 ++ (addi & 0xFFFF0000U) == 0x396B0000U &&
3334 ++ rlwinm == 0x556C083CU &&
3335 ++ add == 0x7D6C5A14U &&
3336 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
3337 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
3338 ++ mtctr == 0x7D8903A6U &&
3339 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
3340 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
3341 ++ bctr == 0x4E800420U)
3342 ++ {
3343 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3344 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3345 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
3346 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3347 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
3348 ++ regs->nip = regs->ctr;
3349 ++ return 4;
3350 ++ }
3351 ++ }
3352 ++ } while (0);
3353 ++#endif
3354 ++
3355 ++ do { /* PaX: unpatched PLT emulation #3 */
3356 ++ unsigned int li, b;
3357 ++
3358 ++ err = get_user(li, (unsigned int *)regs->nip);
3359 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
3360 ++
3361 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
3362 ++ unsigned int addis, lwz, mtctr, bctr;
3363 ++ unsigned long addr = b | 0xFC000000UL;
3364 ++
3365 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
3366 ++ err = get_user(addis, (unsigned int *)addr);
3367 ++ err |= get_user(lwz, (unsigned int *)(addr+4));
3368 ++ err |= get_user(mtctr, (unsigned int *)(addr+8));
3369 ++ err |= get_user(bctr, (unsigned int *)(addr+12));
3370 ++
3371 ++ if (err)
3372 ++ break;
3373 ++
3374 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
3375 ++ (lwz & 0xFFFF0000U) == 0x816B0000U &&
3376 ++ mtctr == 0x7D6903A6U &&
3377 ++ bctr == 0x4E800420U)
3378 ++ {
3379 ++ unsigned int r11;
3380 ++
3381 ++ addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3382 ++ addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3383 ++
3384 ++ err = get_user(r11, (unsigned int *)addr);
3385 ++ if (err)
3386 ++ break;
3387 ++
3388 ++ regs->gpr[PT_R11] = r11;
3389 ++ regs->ctr = r11;
3390 ++ regs->nip = r11;
3391 ++ return 4;
3392 ++ }
3393 ++ }
3394 ++ } while (0);
3395 ++#endif
3396 ++
3397 ++#ifdef CONFIG_PAX_EMUSIGRT
3398 ++ do { /* PaX: sigreturn emulation */
3399 ++ unsigned int li, sc;
3400 ++
3401 ++ err = get_user(li, (unsigned int *)regs->nip);
3402 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
3403 ++
3404 ++ if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) {
3405 ++ struct vm_area_struct *vma;
3406 ++ unsigned long call_syscall;
3407 ++
3408 ++ down_read(&current->mm->mmap_sem);
3409 ++ call_syscall = current->mm->call_syscall;
3410 ++ up_read(&current->mm->mmap_sem);
3411 ++ if (likely(call_syscall))
3412 ++ goto emulate;
3413 ++
3414 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
3415 ++
3416 ++ down_write(&current->mm->mmap_sem);
3417 ++ if (current->mm->call_syscall) {
3418 ++ call_syscall = current->mm->call_syscall;
3419 ++ up_write(&current->mm->mmap_sem);
3420 ++ if (vma)
3421 ++ kmem_cache_free(vm_area_cachep, vma);
3422 ++ goto emulate;
3423 ++ }
3424 ++
3425 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
3426 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
3427 ++ up_write(&current->mm->mmap_sem);
3428 ++ if (vma)
3429 ++ kmem_cache_free(vm_area_cachep, vma);
3430 ++ return 1;
3431 ++ }
3432 ++
3433 ++ if (pax_insert_vma(vma, call_syscall)) {
3434 ++ up_write(&current->mm->mmap_sem);
3435 ++ kmem_cache_free(vm_area_cachep, vma);
3436 ++ return 1;
3437 ++ }
3438 ++
3439 ++ current->mm->call_syscall = call_syscall;
3440 ++ up_write(&current->mm->mmap_sem);
3441 ++
3442 ++emulate:
3443 ++ regs->gpr[PT_R0] = __NR_sigreturn;
3444 ++ regs->nip = call_syscall;
3445 ++ return 5;
3446 ++ }
3447 ++ } while (0);
3448 ++
3449 ++ do { /* PaX: rt_sigreturn emulation */
3450 ++ unsigned int li, sc;
3451 ++
3452 ++ err = get_user(li, (unsigned int *)regs->nip);
3453 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
3454 ++
3455 ++ if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) {
3456 ++ struct vm_area_struct *vma;
3457 ++ unsigned int call_syscall;
3458 ++
3459 ++ down_read(&current->mm->mmap_sem);
3460 ++ call_syscall = current->mm->call_syscall;
3461 ++ up_read(&current->mm->mmap_sem);
3462 ++ if (likely(call_syscall))
3463 ++ goto rt_emulate;
3464 ++
3465 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
3466 ++
3467 ++ down_write(&current->mm->mmap_sem);
3468 ++ if (current->mm->call_syscall) {
3469 ++ call_syscall = current->mm->call_syscall;
3470 ++ up_write(&current->mm->mmap_sem);
3471 ++ if (vma)
3472 ++ kmem_cache_free(vm_area_cachep, vma);
3473 ++ goto rt_emulate;
3474 ++ }
3475 ++
3476 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
3477 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
3478 ++ up_write(&current->mm->mmap_sem);
3479 ++ if (vma)
3480 ++ kmem_cache_free(vm_area_cachep, vma);
3481 ++ return 1;
3482 ++ }
3483 ++
3484 ++ if (pax_insert_vma(vma, call_syscall)) {
3485 ++ up_write(&current->mm->mmap_sem);
3486 ++ kmem_cache_free(vm_area_cachep, vma);
3487 ++ return 1;
3488 ++ }
3489 ++
3490 ++ current->mm->call_syscall = call_syscall;
3491 ++ up_write(&current->mm->mmap_sem);
3492 ++
3493 ++rt_emulate:
3494 ++ regs->gpr[PT_R0] = __NR_rt_sigreturn;
3495 ++ regs->nip = call_syscall;
3496 ++ return 6;
3497 ++ }
3498 ++ } while (0);
3499 ++#endif
3500 ++
3501 ++ return 1;
3502 ++}
3503 ++
3504 ++void pax_report_insns(void *pc, void *sp)
3505 ++{
3506 ++ unsigned long i;
3507 ++
3508 ++ printk(KERN_ERR "PAX: bytes at PC: ");
3509 ++ for (i = 0; i < 5; i++) {
3510 ++ unsigned int c;
3511 ++ if (get_user(c, (unsigned int *)pc+i))
3512 ++ printk(KERN_CONT "???????? ");
3513 ++ else
3514 ++ printk(KERN_CONT "%08x ", c);
3515 ++ }
3516 ++ printk("\n");
3517 ++}
3518 ++#endif
3519 ++
3520 + /*
3521 + * Check whether the instruction at regs->nip is a store using
3522 + * an update addressing form which will update r1.
3523 +@@ -132,7 +493,7 @@ int __kprobes do_page_fault(struct pt_re
3524 + * indicate errors in DSISR but can validly be set in SRR1.
3525 + */
3526 + if (trap == 0x400)
3527 +- error_code &= 0x48200000;
3528 ++ error_code &= 0x58200000;
3529 + else
3530 + is_write = error_code & DSISR_ISSTORE;
3531 + #else
3532 +@@ -331,6 +692,37 @@ bad_area:
3533 + bad_area_nosemaphore:
3534 + /* User mode accesses cause a SIGSEGV */
3535 + if (user_mode(regs)) {
3536 ++
3537 ++#ifdef CONFIG_PAX_PAGEEXEC
3538 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3539 ++#ifdef CONFIG_PPC64
3540 ++ if (is_exec && (error_code & DSISR_PROTFAULT)) {
3541 ++#else
3542 ++ if (is_exec && regs->nip == address) {
3543 ++#endif
3544 ++ switch (pax_handle_fetch_fault(regs)) {
3545 ++
3546 ++#ifdef CONFIG_PAX_EMUPLT
3547 ++ case 2:
3548 ++ case 3:
3549 ++ case 4:
3550 ++ return 0;
3551 ++#endif
3552 ++
3553 ++#ifdef CONFIG_PAX_EMUSIGRT
3554 ++ case 5:
3555 ++ case 6:
3556 ++ return 0;
3557 ++#endif
3558 ++
3559 ++ }
3560 ++
3561 ++ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3562 ++ do_group_exit(SIGKILL);
3563 ++ }
3564 ++ }
3565 ++#endif
3566 ++
3567 + _exception(SIGSEGV, regs, code, address);
3568 + return 0;
3569 + }
3570 +diff -urNp linux-2.6.27.10/arch/powerpc/mm/mmap.c linux-2.6.27.10/arch/powerpc/mm/mmap.c
3571 +--- linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
3572 ++++ linux-2.6.27.10/arch/powerpc/mm/mmap.c 2008-11-18 03:38:43.000000000 -0500
3573 +@@ -75,10 +75,22 @@ void arch_pick_mmap_layout(struct mm_str
3574 + */
3575 + if (mmap_is_legacy()) {
3576 + mm->mmap_base = TASK_UNMAPPED_BASE;
3577 ++
3578 ++#ifdef CONFIG_PAX_RANDMMAP
3579 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
3580 ++ mm->mmap_base += mm->delta_mmap;
3581 ++#endif
3582 ++
3583 + mm->get_unmapped_area = arch_get_unmapped_area;
3584 + mm->unmap_area = arch_unmap_area;
3585 + } else {
3586 + mm->mmap_base = mmap_base();
3587 ++
3588 ++#ifdef CONFIG_PAX_RANDMMAP
3589 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
3590 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3591 ++#endif
3592 ++
3593 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3594 + mm->unmap_area = arch_unmap_area_topdown;
3595 + }
3596 +diff -urNp linux-2.6.27.10/arch/s390/include/asm/kmap_types.h linux-2.6.27.10/arch/s390/include/asm/kmap_types.h
3597 +--- linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
3598 ++++ linux-2.6.27.10/arch/s390/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
3599 +@@ -16,6 +16,7 @@ enum km_type {
3600 + KM_IRQ1,
3601 + KM_SOFTIRQ0,
3602 + KM_SOFTIRQ1,
3603 ++ KM_CLEARPAGE,
3604 + KM_TYPE_NR
3605 + };
3606 +
3607 +diff -urNp linux-2.6.27.10/arch/s390/kernel/module.c linux-2.6.27.10/arch/s390/kernel/module.c
3608 +--- linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
3609 ++++ linux-2.6.27.10/arch/s390/kernel/module.c 2008-11-18 03:38:43.000000000 -0500
3610 +@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3611 +
3612 + /* Increase core size by size of got & plt and set start
3613 + offsets for got and plt. */
3614 +- me->core_size = ALIGN(me->core_size, 4);
3615 +- me->arch.got_offset = me->core_size;
3616 +- me->core_size += me->arch.got_size;
3617 +- me->arch.plt_offset = me->core_size;
3618 +- me->core_size += me->arch.plt_size;
3619 ++ me->core_size_rw = ALIGN(me->core_size_rw, 4);
3620 ++ me->arch.got_offset = me->core_size_rw;
3621 ++ me->core_size_rw += me->arch.got_size;
3622 ++ me->arch.plt_offset = me->core_size_rx;
3623 ++ me->core_size_rx += me->arch.plt_size;
3624 + return 0;
3625 + }
3626 +
3627 +@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3628 + if (info->got_initialized == 0) {
3629 + Elf_Addr *gotent;
3630 +
3631 +- gotent = me->module_core + me->arch.got_offset +
3632 ++ gotent = me->module_core_rw + me->arch.got_offset +
3633 + info->got_offset;
3634 + *gotent = val;
3635 + info->got_initialized = 1;
3636 +@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3637 + else if (r_type == R_390_GOTENT ||
3638 + r_type == R_390_GOTPLTENT)
3639 + *(unsigned int *) loc =
3640 +- (val + (Elf_Addr) me->module_core - loc) >> 1;
3641 ++ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
3642 + else if (r_type == R_390_GOT64 ||
3643 + r_type == R_390_GOTPLT64)
3644 + *(unsigned long *) loc = val;
3645 +@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3646 + case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
3647 + if (info->plt_initialized == 0) {
3648 + unsigned int *ip;
3649 +- ip = me->module_core + me->arch.plt_offset +
3650 ++ ip = me->module_core_rx + me->arch.plt_offset +
3651 + info->plt_offset;
3652 + #ifndef CONFIG_64BIT
3653 + ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
3654 +@@ -316,7 +316,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3655 + val = me->arch.plt_offset - me->arch.got_offset +
3656 + info->plt_offset + rela->r_addend;
3657 + else
3658 +- val = (Elf_Addr) me->module_core +
3659 ++ val = (Elf_Addr) me->module_core_rx +
3660 + me->arch.plt_offset + info->plt_offset +
3661 + rela->r_addend - loc;
3662 + if (r_type == R_390_PLT16DBL)
3663 +@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3664 + case R_390_GOTOFF32: /* 32 bit offset to GOT. */
3665 + case R_390_GOTOFF64: /* 64 bit offset to GOT. */
3666 + val = val + rela->r_addend -
3667 +- ((Elf_Addr) me->module_core + me->arch.got_offset);
3668 ++ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
3669 + if (r_type == R_390_GOTOFF16)
3670 + *(unsigned short *) loc = val;
3671 + else if (r_type == R_390_GOTOFF32)
3672 +@@ -346,7 +346,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3673 + break;
3674 + case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
3675 + case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
3676 +- val = (Elf_Addr) me->module_core + me->arch.got_offset +
3677 ++ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
3678 + rela->r_addend - loc;
3679 + if (r_type == R_390_GOTPC)
3680 + *(unsigned int *) loc = val;
3681 +diff -urNp linux-2.6.27.10/arch/sh/include/asm/kmap_types.h linux-2.6.27.10/arch/sh/include/asm/kmap_types.h
3682 +--- linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
3683 ++++ linux-2.6.27.10/arch/sh/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
3684 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
3685 + D(10) KM_IRQ1,
3686 + D(11) KM_SOFTIRQ0,
3687 + D(12) KM_SOFTIRQ1,
3688 +-D(13) KM_TYPE_NR
3689 ++D(13) KM_CLEARPAGE,
3690 ++D(14) KM_TYPE_NR
3691 + };
3692 +
3693 + #undef D
3694 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/elf_32.h linux-2.6.27.10/arch/sparc/include/asm/elf_32.h
3695 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-07 12:55:34.000000000 -0500
3696 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_32.h 2008-11-18 03:39:50.000000000 -0500
3697 +@@ -119,6 +119,13 @@ typedef struct {
3698 +
3699 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
3700 +
3701 ++#ifdef CONFIG_PAX_ASLR
3702 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
3703 ++
3704 ++#define PAX_DELTA_MMAP_LEN 16
3705 ++#define PAX_DELTA_STACK_LEN 16
3706 ++#endif
3707 ++
3708 + /* This yields a mask that user programs can use to figure out what
3709 + instruction set this cpu supports. This can NOT be done in userspace
3710 + on Sparc. */
3711 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/elf_64.h linux-2.6.27.10/arch/sparc/include/asm/elf_64.h
3712 +--- linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-07 12:55:34.000000000 -0500
3713 ++++ linux-2.6.27.10/arch/sparc/include/asm/elf_64.h 2008-11-18 03:39:50.000000000 -0500
3714 +@@ -163,6 +163,12 @@ typedef struct {
3715 + #define ELF_ET_DYN_BASE 0x0000010000000000UL
3716 + #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
3717 +
3718 ++#ifdef CONFIG_PAX_ASLR
3719 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
3720 ++
3721 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28 )
3722 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29 )
3723 ++#endif
3724 +
3725 + /* This yields a mask that user programs can use to figure out what
3726 + instruction set this cpu supports. */
3727 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h
3728 +--- linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
3729 ++++ linux-2.6.27.10/arch/sparc/include/asm/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
3730 +@@ -19,6 +19,7 @@ enum km_type {
3731 + KM_IRQ1,
3732 + KM_SOFTIRQ0,
3733 + KM_SOFTIRQ1,
3734 ++ KM_CLEARPAGE,
3735 + KM_TYPE_NR
3736 + };
3737 +
3738 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h
3739 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
3740 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtable_32.h 2008-11-18 03:39:50.000000000 -0500
3741 +@@ -47,6 +47,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
3742 + BTFIXUPDEF_INT(page_none)
3743 + BTFIXUPDEF_INT(page_copy)
3744 + BTFIXUPDEF_INT(page_readonly)
3745 ++
3746 ++#ifdef CONFIG_PAX_PAGEEXEC
3747 ++BTFIXUPDEF_INT(page_shared_noexec)
3748 ++BTFIXUPDEF_INT(page_copy_noexec)
3749 ++BTFIXUPDEF_INT(page_readonly_noexec)
3750 ++#endif
3751 ++
3752 + BTFIXUPDEF_INT(page_kernel)
3753 +
3754 + #define PMD_SHIFT SUN4C_PMD_SHIFT
3755 +@@ -68,6 +75,16 @@ extern pgprot_t PAGE_SHARED;
3756 + #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
3757 + #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
3758 +
3759 ++#ifdef CONFIG_PAX_PAGEEXEC
3760 ++extern pgprot_t PAGE_SHARED_NOEXEC;
3761 ++# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
3762 ++# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
3763 ++#else
3764 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
3765 ++# define PAGE_COPY_NOEXEC PAGE_COPY
3766 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
3767 ++#endif
3768 ++
3769 + extern unsigned long page_kernel;
3770 +
3771 + #ifdef MODULE
3772 +diff -urNp linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h
3773 +--- linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-07 12:55:34.000000000 -0500
3774 ++++ linux-2.6.27.10/arch/sparc/include/asm/pgtsrmmu.h 2008-11-18 03:39:50.000000000 -0500
3775 +@@ -115,6 +115,13 @@
3776 + SRMMU_EXEC | SRMMU_REF)
3777 + #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
3778 + SRMMU_EXEC | SRMMU_REF)
3779 ++
3780 ++#ifdef CONFIG_PAX_PAGEEXEC
3781 ++#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
3782 ++#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3783 ++#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
3784 ++#endif
3785 ++
3786 + #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
3787 + SRMMU_DIRTY | SRMMU_REF)
3788 +
3789 +diff -urNp linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c
3790 +--- linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
3791 ++++ linux-2.6.27.10/arch/sparc/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
3792 +@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
3793 + if (ARCH_SUN4C_SUN4 && len > 0x20000000)
3794 + return -ENOMEM;
3795 + if (!addr)
3796 +- addr = TASK_UNMAPPED_BASE;
3797 ++ addr = current->mm->mmap_base;
3798 +
3799 + if (flags & MAP_SHARED)
3800 + addr = COLOUR_ALIGN(addr);
3801 +diff -urNp linux-2.6.27.10/arch/sparc/Makefile linux-2.6.27.10/arch/sparc/Makefile
3802 +--- linux-2.6.27.10/arch/sparc/Makefile 2008-11-07 12:55:34.000000000 -0500
3803 ++++ linux-2.6.27.10/arch/sparc/Makefile 2008-11-18 03:38:43.000000000 -0500
3804 +@@ -37,7 +37,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
3805 + # Renaming is done to avoid confusing pattern matching rules in 2.5.45 (multy-)
3806 + INIT_Y := $(patsubst %/, %/built-in.o, $(init-y))
3807 + CORE_Y := $(core-y)
3808 +-CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
3809 ++CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
3810 + CORE_Y := $(patsubst %/, %/built-in.o, $(CORE_Y))
3811 + DRIVERS_Y := $(patsubst %/, %/built-in.o, $(drivers-y))
3812 + NET_Y := $(patsubst %/, %/built-in.o, $(net-y))
3813 +diff -urNp linux-2.6.27.10/arch/sparc/mm/fault.c linux-2.6.27.10/arch/sparc/mm/fault.c
3814 +--- linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
3815 ++++ linux-2.6.27.10/arch/sparc/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
3816 +@@ -21,6 +21,9 @@
3817 + #include <linux/interrupt.h>
3818 + #include <linux/module.h>
3819 + #include <linux/kdebug.h>
3820 ++#include <linux/slab.h>
3821 ++#include <linux/pagemap.h>
3822 ++#include <linux/compiler.h>
3823 +
3824 + #include <asm/system.h>
3825 + #include <asm/page.h>
3826 +@@ -167,6 +170,249 @@ static unsigned long compute_si_addr(str
3827 + return safe_compute_effective_address(regs, insn);
3828 + }
3829 +
3830 ++#ifdef CONFIG_PAX_PAGEEXEC
3831 ++void pax_emuplt_close(struct vm_area_struct *vma)
3832 ++{
3833 ++ vma->vm_mm->call_dl_resolve = 0UL;
3834 ++}
3835 ++
3836 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
3837 ++{
3838 ++ unsigned int *kaddr;
3839 ++
3840 ++ vmf->page = alloc_page(GFP_HIGHUSER);
3841 ++ if (!vmf->page)
3842 ++ return VM_FAULT_OOM;
3843 ++
3844 ++ kaddr = kmap(vmf->page);
3845 ++ memset(kaddr, 0, PAGE_SIZE);
3846 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
3847 ++ flush_dcache_page(vmf->page);
3848 ++ kunmap(vmf->page);
3849 ++ return VM_FAULT_MAJOR;
3850 ++}
3851 ++
3852 ++static struct vm_operations_struct pax_vm_ops = {
3853 ++ .close = pax_emuplt_close,
3854 ++ .fault = pax_emuplt_fault
3855 ++};
3856 ++
3857 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
3858 ++{
3859 ++ int ret;
3860 ++
3861 ++ vma->vm_mm = current->mm;
3862 ++ vma->vm_start = addr;
3863 ++ vma->vm_end = addr + PAGE_SIZE;
3864 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
3865 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3866 ++ vma->vm_ops = &pax_vm_ops;
3867 ++
3868 ++ ret = insert_vm_struct(current->mm, vma);
3869 ++ if (ret)
3870 ++ return ret;
3871 ++
3872 ++ ++current->mm->total_vm;
3873 ++ return 0;
3874 ++}
3875 ++
3876 ++/*
3877 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
3878 ++ *
3879 ++ * returns 1 when task should be killed
3880 ++ * 2 when patched PLT trampoline was detected
3881 ++ * 3 when unpatched PLT trampoline was detected
3882 ++ */
3883 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
3884 ++{
3885 ++
3886 ++#ifdef CONFIG_PAX_EMUPLT
3887 ++ int err;
3888 ++
3889 ++ do { /* PaX: patched PLT emulation #1 */
3890 ++ unsigned int sethi1, sethi2, jmpl;
3891 ++
3892 ++ err = get_user(sethi1, (unsigned int *)regs->pc);
3893 ++ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
3894 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
3895 ++
3896 ++ if (err)
3897 ++ break;
3898 ++
3899 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
3900 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
3901 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
3902 ++ {
3903 ++ unsigned int addr;
3904 ++
3905 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
3906 ++ addr = regs->u_regs[UREG_G1];
3907 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
3908 ++ regs->pc = addr;
3909 ++ regs->npc = addr+4;
3910 ++ return 2;
3911 ++ }
3912 ++ } while (0);
3913 ++
3914 ++ { /* PaX: patched PLT emulation #2 */
3915 ++ unsigned int ba;
3916 ++
3917 ++ err = get_user(ba, (unsigned int *)regs->pc);
3918 ++
3919 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
3920 ++ unsigned int addr;
3921 ++
3922 ++ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
3923 ++ regs->pc = addr;
3924 ++ regs->npc = addr+4;
3925 ++ return 2;
3926 ++ }
3927 ++ }
3928 ++
3929 ++ do { /* PaX: patched PLT emulation #3 */
3930 ++ unsigned int sethi, jmpl, nop;
3931 ++
3932 ++ err = get_user(sethi, (unsigned int *)regs->pc);
3933 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
3934 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
3935 ++
3936 ++ if (err)
3937 ++ break;
3938 ++
3939 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
3940 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
3941 ++ nop == 0x01000000U)
3942 ++ {
3943 ++ unsigned int addr;
3944 ++
3945 ++ addr = (sethi & 0x003FFFFFU) << 10;
3946 ++ regs->u_regs[UREG_G1] = addr;
3947 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
3948 ++ regs->pc = addr;
3949 ++ regs->npc = addr+4;
3950 ++ return 2;
3951 ++ }
3952 ++ } while (0);
3953 ++
3954 ++ do { /* PaX: unpatched PLT emulation step 1 */
3955 ++ unsigned int sethi, ba, nop;
3956 ++
3957 ++ err = get_user(sethi, (unsigned int *)regs->pc);
3958 ++ err |= get_user(ba, (unsigned int *)(regs->pc+4));
3959 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
3960 ++
3961 ++ if (err)
3962 ++ break;
3963 ++
3964 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
3965 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
3966 ++ nop == 0x01000000U)
3967 ++ {
3968 ++ unsigned int addr, save, call;
3969 ++
3970 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
3971 ++ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
3972 ++ else
3973 ++ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
3974 ++
3975 ++ err = get_user(save, (unsigned int *)addr);
3976 ++ err |= get_user(call, (unsigned int *)(addr+4));
3977 ++ err |= get_user(nop, (unsigned int *)(addr+8));
3978 ++ if (err)
3979 ++ break;
3980 ++
3981 ++ if (save == 0x9DE3BFA8U &&
3982 ++ (call & 0xC0000000U) == 0x40000000U &&
3983 ++ nop == 0x01000000U)
3984 ++ {
3985 ++ struct vm_area_struct *vma;
3986 ++ unsigned long call_dl_resolve;
3987 ++
3988 ++ down_read(&current->mm->mmap_sem);
3989 ++ call_dl_resolve = current->mm->call_dl_resolve;
3990 ++ up_read(&current->mm->mmap_sem);
3991 ++ if (likely(call_dl_resolve))
3992 ++ goto emulate;
3993 ++
3994 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
3995 ++
3996 ++ down_write(&current->mm->mmap_sem);
3997 ++ if (current->mm->call_dl_resolve) {
3998 ++ call_dl_resolve = current->mm->call_dl_resolve;
3999 ++ up_write(&current->mm->mmap_sem);
4000 ++ if (vma)
4001 ++ kmem_cache_free(vm_area_cachep, vma);
4002 ++ goto emulate;
4003 ++ }
4004 ++
4005 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4006 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4007 ++ up_write(&current->mm->mmap_sem);
4008 ++ if (vma)
4009 ++ kmem_cache_free(vm_area_cachep, vma);
4010 ++ return 1;
4011 ++ }
4012 ++
4013 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
4014 ++ up_write(&current->mm->mmap_sem);
4015 ++ kmem_cache_free(vm_area_cachep, vma);
4016 ++ return 1;
4017 ++ }
4018 ++
4019 ++ current->mm->call_dl_resolve = call_dl_resolve;
4020 ++ up_write(&current->mm->mmap_sem);
4021 ++
4022 ++emulate:
4023 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4024 ++ regs->pc = call_dl_resolve;
4025 ++ regs->npc = addr+4;
4026 ++ return 3;
4027 ++ }
4028 ++ }
4029 ++ } while (0);
4030 ++
4031 ++ do { /* PaX: unpatched PLT emulation step 2 */
4032 ++ unsigned int save, call, nop;
4033 ++
4034 ++ err = get_user(save, (unsigned int *)(regs->pc-4));
4035 ++ err |= get_user(call, (unsigned int *)regs->pc);
4036 ++ err |= get_user(nop, (unsigned int *)(regs->pc+4));
4037 ++ if (err)
4038 ++ break;
4039 ++
4040 ++ if (save == 0x9DE3BFA8U &&
4041 ++ (call & 0xC0000000U) == 0x40000000U &&
4042 ++ nop == 0x01000000U)
4043 ++ {
4044 ++ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
4045 ++
4046 ++ regs->u_regs[UREG_RETPC] = regs->pc;
4047 ++ regs->pc = dl_resolve;
4048 ++ regs->npc = dl_resolve+4;
4049 ++ return 3;
4050 ++ }
4051 ++ } while (0);
4052 ++#endif
4053 ++
4054 ++ return 1;
4055 ++}
4056 ++
4057 ++void pax_report_insns(void *pc, void *sp)
4058 ++{
4059 ++ unsigned long i;
4060 ++
4061 ++ printk(KERN_ERR "PAX: bytes at PC: ");
4062 ++ for (i = 0; i < 5; i++) {
4063 ++ unsigned int c;
4064 ++ if (get_user(c, (unsigned int *)pc+i))
4065 ++ printk(KERN_CONT "???????? ");
4066 ++ else
4067 ++ printk(KERN_CONT "%08x ", c);
4068 ++ }
4069 ++ printk("\n");
4070 ++}
4071 ++#endif
4072 ++
4073 + asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
4074 + unsigned long address)
4075 + {
4076 +@@ -231,6 +477,24 @@ good_area:
4077 + if(!(vma->vm_flags & VM_WRITE))
4078 + goto bad_area;
4079 + } else {
4080 ++
4081 ++#ifdef CONFIG_PAX_PAGEEXEC
4082 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
4083 ++ up_read(&mm->mmap_sem);
4084 ++ switch (pax_handle_fetch_fault(regs)) {
4085 ++
4086 ++#ifdef CONFIG_PAX_EMUPLT
4087 ++ case 2:
4088 ++ case 3:
4089 ++ return;
4090 ++#endif
4091 ++
4092 ++ }
4093 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
4094 ++ do_group_exit(SIGKILL);
4095 ++ }
4096 ++#endif
4097 ++
4098 + /* Allow reads even for write-only mappings */
4099 + if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
4100 + goto bad_area;
4101 +diff -urNp linux-2.6.27.10/arch/sparc/mm/init.c linux-2.6.27.10/arch/sparc/mm/init.c
4102 +--- linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-07 12:55:34.000000000 -0500
4103 ++++ linux-2.6.27.10/arch/sparc/mm/init.c 2008-11-18 03:38:43.000000000 -0500
4104 +@@ -312,6 +312,9 @@ extern void device_scan(void);
4105 + pgprot_t PAGE_SHARED __read_mostly;
4106 + EXPORT_SYMBOL(PAGE_SHARED);
4107 +
4108 ++pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
4109 ++EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
4110 ++
4111 + void __init paging_init(void)
4112 + {
4113 + switch(sparc_cpu_model) {
4114 +@@ -337,17 +340,17 @@ void __init paging_init(void)
4115 +
4116 + /* Initialize the protection map with non-constant, MMU dependent values. */
4117 + protection_map[0] = PAGE_NONE;
4118 +- protection_map[1] = PAGE_READONLY;
4119 +- protection_map[2] = PAGE_COPY;
4120 +- protection_map[3] = PAGE_COPY;
4121 ++ protection_map[1] = PAGE_READONLY_NOEXEC;
4122 ++ protection_map[2] = PAGE_COPY_NOEXEC;
4123 ++ protection_map[3] = PAGE_COPY_NOEXEC;
4124 + protection_map[4] = PAGE_READONLY;
4125 + protection_map[5] = PAGE_READONLY;
4126 + protection_map[6] = PAGE_COPY;
4127 + protection_map[7] = PAGE_COPY;
4128 + protection_map[8] = PAGE_NONE;
4129 +- protection_map[9] = PAGE_READONLY;
4130 +- protection_map[10] = PAGE_SHARED;
4131 +- protection_map[11] = PAGE_SHARED;
4132 ++ protection_map[9] = PAGE_READONLY_NOEXEC;
4133 ++ protection_map[10] = PAGE_SHARED_NOEXEC;
4134 ++ protection_map[11] = PAGE_SHARED_NOEXEC;
4135 + protection_map[12] = PAGE_READONLY;
4136 + protection_map[13] = PAGE_READONLY;
4137 + protection_map[14] = PAGE_SHARED;
4138 +diff -urNp linux-2.6.27.10/arch/sparc/mm/srmmu.c linux-2.6.27.10/arch/sparc/mm/srmmu.c
4139 +--- linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-07 12:55:34.000000000 -0500
4140 ++++ linux-2.6.27.10/arch/sparc/mm/srmmu.c 2008-11-18 03:38:43.000000000 -0500
4141 +@@ -2163,6 +2163,13 @@ void __init ld_mmu_srmmu(void)
4142 + PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
4143 + BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
4144 + BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
4145 ++
4146 ++#ifdef CONFIG_PAX_PAGEEXEC
4147 ++ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
4148 ++ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
4149 ++ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
4150 ++#endif
4151 ++
4152 + BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
4153 + page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
4154 +
4155 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/Makefile linux-2.6.27.10/arch/sparc64/kernel/Makefile
4156 +--- linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-07 12:55:34.000000000 -0500
4157 ++++ linux-2.6.27.10/arch/sparc64/kernel/Makefile 2008-11-18 03:38:43.000000000 -0500
4158 +@@ -3,7 +3,7 @@
4159 + #
4160 +
4161 + EXTRA_AFLAGS := -ansi
4162 +-EXTRA_CFLAGS := -Werror
4163 ++#EXTRA_CFLAGS := -Werror
4164 +
4165 + extra-y := head.o init_task.o vmlinux.lds
4166 +
4167 +diff -urNp linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c
4168 +--- linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-07 12:55:34.000000000 -0500
4169 ++++ linux-2.6.27.10/arch/sparc64/kernel/sys_sparc.c 2008-11-18 03:38:43.000000000 -0500
4170 +@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
4171 + /* We do not accept a shared mapping if it would violate
4172 + * cache aliasing constraints.
4173 + */
4174 +- if ((flags & MAP_SHARED) &&
4175 ++ if ((filp || (flags & MAP_SHARED)) &&
4176 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4177 + return -EINVAL;
4178 + return addr;
4179 +@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
4180 + if (filp || (flags & MAP_SHARED))
4181 + do_color_align = 1;
4182 +
4183 ++#ifdef CONFIG_PAX_RANDMMAP
4184 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
4185 ++#endif
4186 ++
4187 + if (addr) {
4188 + if (do_color_align)
4189 + addr = COLOUR_ALIGN(addr, pgoff);
4190 +@@ -152,9 +156,9 @@ unsigned long arch_get_unmapped_area(str
4191 + }
4192 +
4193 + if (len > mm->cached_hole_size) {
4194 +- start_addr = addr = mm->free_area_cache;
4195 ++ start_addr = addr = mm->free_area_cache;
4196 + } else {
4197 +- start_addr = addr = TASK_UNMAPPED_BASE;
4198 ++ start_addr = addr = mm->mmap_base;
4199 + mm->cached_hole_size = 0;
4200 + }
4201 +
4202 +@@ -174,8 +178,8 @@ full_search:
4203 + vma = find_vma(mm, VA_EXCLUDE_END);
4204 + }
4205 + if (unlikely(task_size < addr)) {
4206 +- if (start_addr != TASK_UNMAPPED_BASE) {
4207 +- start_addr = addr = TASK_UNMAPPED_BASE;
4208 ++ if (start_addr != mm->mmap_base) {
4209 ++ start_addr = addr = mm->mmap_base;
4210 + mm->cached_hole_size = 0;
4211 + goto full_search;
4212 + }
4213 +@@ -215,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
4214 + /* We do not accept a shared mapping if it would violate
4215 + * cache aliasing constraints.
4216 + */
4217 +- if ((flags & MAP_SHARED) &&
4218 ++ if ((filp || (flags & MAP_SHARED)) &&
4219 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4220 + return -EINVAL;
4221 + return addr;
4222 +@@ -378,6 +382,12 @@ void arch_pick_mmap_layout(struct mm_str
4223 + current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
4224 + sysctl_legacy_va_layout) {
4225 + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4226 ++
4227 ++#ifdef CONFIG_PAX_RANDMMAP
4228 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
4229 ++ mm->mmap_base += mm->delta_mmap;
4230 ++#endif
4231 ++
4232 + mm->get_unmapped_area = arch_get_unmapped_area;
4233 + mm->unmap_area = arch_unmap_area;
4234 + } else {
4235 +@@ -392,6 +402,12 @@ void arch_pick_mmap_layout(struct mm_str
4236 + gap = (task_size / 6 * 5);
4237 +
4238 + mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4239 ++
4240 ++#ifdef CONFIG_PAX_RANDMMAP
4241 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
4242 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4243 ++#endif
4244 ++
4245 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4246 + mm->unmap_area = arch_unmap_area_topdown;
4247 + }
4248 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/fault.c linux-2.6.27.10/arch/sparc64/mm/fault.c
4249 +--- linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
4250 ++++ linux-2.6.27.10/arch/sparc64/mm/fault.c 2008-11-18 03:38:43.000000000 -0500
4251 +@@ -19,6 +19,9 @@
4252 + #include <linux/interrupt.h>
4253 + #include <linux/kprobes.h>
4254 + #include <linux/kdebug.h>
4255 ++#include <linux/slab.h>
4256 ++#include <linux/pagemap.h>
4257 ++#include <linux/compiler.h>
4258 +
4259 + #include <asm/page.h>
4260 + #include <asm/pgtable.h>
4261 +@@ -261,6 +264,367 @@ cannot_handle:
4262 + unhandled_fault (address, current, regs);
4263 + }
4264 +
4265 ++#ifdef CONFIG_PAX_PAGEEXEC
4266 ++#ifdef CONFIG_PAX_EMUPLT
4267 ++static void pax_emuplt_close(struct vm_area_struct *vma)
4268 ++{
4269 ++ vma->vm_mm->call_dl_resolve = 0UL;
4270 ++}
4271 ++
4272 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4273 ++{
4274 ++ unsigned int *kaddr;
4275 ++
4276 ++ vmf->page = alloc_page(GFP_HIGHUSER);
4277 ++ if (!vmf->page)
4278 ++ return VM_FAULT_OOM;
4279 ++
4280 ++ kaddr = kmap(vmf->page);
4281 ++ memset(kaddr, 0, PAGE_SIZE);
4282 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
4283 ++ flush_dcache_page(vmf->page);
4284 ++ kunmap(vmf->page);
4285 ++ return VM_FAULT_MAJOR;
4286 ++}
4287 ++
4288 ++static struct vm_operations_struct pax_vm_ops = {
4289 ++ .close = pax_emuplt_close,
4290 ++ .fault = pax_emuplt_fault
4291 ++};
4292 ++
4293 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4294 ++{
4295 ++ int ret;
4296 ++
4297 ++ vma->vm_mm = current->mm;
4298 ++ vma->vm_start = addr;
4299 ++ vma->vm_end = addr + PAGE_SIZE;
4300 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4301 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4302 ++ vma->vm_ops = &pax_vm_ops;
4303 ++
4304 ++ ret = insert_vm_struct(current->mm, vma);
4305 ++ if (ret)
4306 ++ return ret;
4307 ++
4308 ++ ++current->mm->total_vm;
4309 ++ return 0;
4310 ++}
4311 ++#endif
4312 ++
4313 ++/*
4314 ++ * PaX: decide what to do with offenders (regs->tpc = fault address)
4315 ++ *
4316 ++ * returns 1 when task should be killed
4317 ++ * 2 when patched PLT trampoline was detected
4318 ++ * 3 when unpatched PLT trampoline was detected
4319 ++ */
4320 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
4321 ++{
4322 ++
4323 ++#ifdef CONFIG_PAX_EMUPLT
4324 ++ int err;
4325 ++
4326 ++ do { /* PaX: patched PLT emulation #1 */
4327 ++ unsigned int sethi1, sethi2, jmpl;
4328 ++
4329 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
4330 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4331 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
4332 ++
4333 ++ if (err)
4334 ++ break;
4335 ++
4336 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4337 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
4338 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
4339 ++ {
4340 ++ unsigned long addr;
4341 ++
4342 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4343 ++ addr = regs->u_regs[UREG_G1];
4344 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4345 ++ regs->tpc = addr;
4346 ++ regs->tnpc = addr+4;
4347 ++ return 2;
4348 ++ }
4349 ++ } while (0);
4350 ++
4351 ++ { /* PaX: patched PLT emulation #2 */
4352 ++ unsigned int ba;
4353 ++
4354 ++ err = get_user(ba, (unsigned int *)regs->tpc);
4355 ++
4356 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4357 ++ unsigned long addr;
4358 ++
4359 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4360 ++ regs->tpc = addr;
4361 ++ regs->tnpc = addr+4;
4362 ++ return 2;
4363 ++ }
4364 ++ }
4365 ++
4366 ++ do { /* PaX: patched PLT emulation #3 */
4367 ++ unsigned int sethi, jmpl, nop;
4368 ++
4369 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
4370 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
4371 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4372 ++
4373 ++ if (err)
4374 ++ break;
4375 ++
4376 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4377 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4378 ++ nop == 0x01000000U)
4379 ++ {
4380 ++ unsigned long addr;
4381 ++
4382 ++ addr = (sethi & 0x003FFFFFU) << 10;
4383 ++ regs->u_regs[UREG_G1] = addr;
4384 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4385 ++ regs->tpc = addr;
4386 ++ regs->tnpc = addr+4;
4387 ++ return 2;
4388 ++ }
4389 ++ } while (0);
4390 ++
4391 ++ do { /* PaX: patched PLT emulation #4 */
4392 ++ unsigned int mov1, call, mov2;
4393 ++
4394 ++ err = get_user(mov1, (unsigned int *)regs->tpc);
4395 ++ err |= get_user(call, (unsigned int *)(regs->tpc+4));
4396 ++ err |= get_user(mov2, (unsigned int *)(regs->tpc+8));
4397 ++
4398 ++ if (err)
4399 ++ break;
4400 ++
4401 ++ if (mov1 == 0x8210000FU &&
4402 ++ (call & 0xC0000000U) == 0x40000000U &&
4403 ++ mov2 == 0x9E100001U)
4404 ++ {
4405 ++ unsigned long addr;
4406 ++
4407 ++ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
4408 ++ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
4409 ++ regs->tpc = addr;
4410 ++ regs->tnpc = addr+4;
4411 ++ return 2;
4412 ++ }
4413 ++ } while (0);
4414 ++
4415 ++ do { /* PaX: patched PLT emulation #5 */
4416 ++ unsigned int sethi1, sethi2, or1, or2, sllx, jmpl, nop;
4417 ++
4418 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
4419 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4420 ++ err |= get_user(or1, (unsigned int *)(regs->tpc+8));
4421 ++ err |= get_user(or2, (unsigned int *)(regs->tpc+12));
4422 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+16));
4423 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
4424 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
4425 ++
4426 ++ if (err)
4427 ++ break;
4428 ++
4429 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4430 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4431 ++ (or1 & 0xFFFFE000U) == 0x82106000U &&
4432 ++ (or2 & 0xFFFFE000U) == 0x8A116000U &&
4433 ++ sllx == 0x83287020 &&
4434 ++ jmpl == 0x81C04005U &&
4435 ++ nop == 0x01000000U)
4436 ++ {
4437 ++ unsigned long addr;
4438 ++
4439 ++ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
4440 ++ regs->u_regs[UREG_G1] <<= 32;
4441 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
4442 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
4443 ++ regs->tpc = addr;
4444 ++ regs->tnpc = addr+4;
4445 ++ return 2;
4446 ++ }
4447 ++ } while (0);
4448 ++
4449 ++ do { /* PaX: patched PLT emulation #6 */
4450 ++ unsigned int sethi1, sethi2, sllx, or, jmpl, nop;
4451 ++
4452 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
4453 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4454 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+8));
4455 ++ err |= get_user(or, (unsigned int *)(regs->tpc+12));
4456 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+16));
4457 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+20));
4458 ++
4459 ++ if (err)
4460 ++ break;
4461 ++
4462 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4463 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4464 ++ sllx == 0x83287020 &&
4465 ++ (or & 0xFFFFE000U) == 0x8A116000U &&
4466 ++ jmpl == 0x81C04005U &&
4467 ++ nop == 0x01000000U)
4468 ++ {
4469 ++ unsigned long addr;
4470 ++
4471 ++ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
4472 ++ regs->u_regs[UREG_G1] <<= 32;
4473 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
4474 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
4475 ++ regs->tpc = addr;
4476 ++ regs->tnpc = addr+4;
4477 ++ return 2;
4478 ++ }
4479 ++ } while (0);
4480 ++
4481 ++ do { /* PaX: patched PLT emulation #7 */
4482 ++ unsigned int sethi, ba, nop;
4483 ++
4484 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
4485 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
4486 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4487 ++
4488 ++ if (err)
4489 ++ break;
4490 ++
4491 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4492 ++ (ba & 0xFFF00000U) == 0x30600000U &&
4493 ++ nop == 0x01000000U)
4494 ++ {
4495 ++ unsigned long addr;
4496 ++
4497 ++ addr = (sethi & 0x003FFFFFU) << 10;
4498 ++ regs->u_regs[UREG_G1] = addr;
4499 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
4500 ++ regs->tpc = addr;
4501 ++ regs->tnpc = addr+4;
4502 ++ return 2;
4503 ++ }
4504 ++ } while (0);
4505 ++
4506 ++ do { /* PaX: unpatched PLT emulation step 1 */
4507 ++ unsigned int sethi, ba, nop;
4508 ++
4509 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
4510 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
4511 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4512 ++
4513 ++ if (err)
4514 ++ break;
4515 ++
4516 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4517 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4518 ++ nop == 0x01000000U)
4519 ++ {
4520 ++ unsigned long addr;
4521 ++ unsigned int save, call;
4522 ++
4523 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
4524 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4525 ++ else
4526 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
4527 ++
4528 ++ err = get_user(save, (unsigned int *)addr);
4529 ++ err |= get_user(call, (unsigned int *)(addr+4));
4530 ++ err |= get_user(nop, (unsigned int *)(addr+8));
4531 ++ if (err)
4532 ++ break;
4533 ++
4534 ++ if (save == 0x9DE3BFA8U &&
4535 ++ (call & 0xC0000000U) == 0x40000000U &&
4536 ++ nop == 0x01000000U)
4537 ++ {
4538 ++ struct vm_area_struct *vma;
4539 ++ unsigned long call_dl_resolve;
4540 ++
4541 ++ down_read(&current->mm->mmap_sem);
4542 ++ call_dl_resolve = current->mm->call_dl_resolve;
4543 ++ up_read(&current->mm->mmap_sem);
4544 ++ if (likely(call_dl_resolve))
4545 ++ goto emulate;
4546 ++
4547 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4548 ++
4549 ++ down_write(&current->mm->mmap_sem);
4550 ++ if (current->mm->call_dl_resolve) {
4551 ++ call_dl_resolve = current->mm->call_dl_resolve;
4552 ++ up_write(&current->mm->mmap_sem);
4553 ++ if (vma)
4554 ++ kmem_cache_free(vm_area_cachep, vma);
4555 ++ goto emulate;
4556 ++ }
4557 ++
4558 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4559 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4560 ++ up_write(&current->mm->mmap_sem);
4561 ++ if (vma)
4562 ++ kmem_cache_free(vm_area_cachep, vma);
4563 ++ return 1;
4564 ++ }
4565 ++
4566 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
4567 ++ up_write(&current->mm->mmap_sem);
4568 ++ kmem_cache_free(vm_area_cachep, vma);
4569 ++ return 1;
4570 ++ }
4571 ++
4572 ++ current->mm->call_dl_resolve = call_dl_resolve;
4573 ++ up_write(&current->mm->mmap_sem);
4574 ++
4575 ++emulate:
4576 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4577 ++ regs->tpc = call_dl_resolve;
4578 ++ regs->tnpc = addr+4;
4579 ++ return 3;
4580 ++ }
4581 ++ }
4582 ++ } while (0);
4583 ++
4584 ++ do { /* PaX: unpatched PLT emulation step 2 */
4585 ++ unsigned int save, call, nop;
4586 ++
4587 ++ err = get_user(save, (unsigned int *)(regs->tpc-4));
4588 ++ err |= get_user(call, (unsigned int *)regs->tpc);
4589 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
4590 ++ if (err)
4591 ++ break;
4592 ++
4593 ++ if (save == 0x9DE3BFA8U &&
4594 ++ (call & 0xC0000000U) == 0x40000000U &&
4595 ++ nop == 0x01000000U)
4596 ++ {
4597 ++ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
4598 ++
4599 ++ regs->u_regs[UREG_RETPC] = regs->tpc;
4600 ++ regs->tpc = dl_resolve;
4601 ++ regs->tnpc = dl_resolve+4;
4602 ++ return 3;
4603 ++ }
4604 ++ } while (0);
4605 ++#endif
4606 ++
4607 ++ return 1;
4608 ++}
4609 ++
4610 ++void pax_report_insns(void *pc, void *sp)
4611 ++{
4612 ++ unsigned long i;
4613 ++
4614 ++ printk(KERN_ERR "PAX: bytes at PC: ");
4615 ++ for (i = 0; i < 5; i++) {
4616 ++ unsigned int c;
4617 ++ if (get_user(c, (unsigned int *)pc+i))
4618 ++ printk(KERN_CONT "???????? ");
4619 ++ else
4620 ++ printk(KERN_CONT "%08x ", c);
4621 ++ }
4622 ++ printk("\n");
4623 ++}
4624 ++#endif
4625 ++
4626 + asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
4627 + {
4628 + struct mm_struct *mm = current->mm;
4629 +@@ -302,8 +666,10 @@ asmlinkage void __kprobes do_sparc64_fau
4630 + goto intr_or_no_mm;
4631 +
4632 + if (test_thread_flag(TIF_32BIT)) {
4633 +- if (!(regs->tstate & TSTATE_PRIV))
4634 ++ if (!(regs->tstate & TSTATE_PRIV)) {
4635 + regs->tpc &= 0xffffffff;
4636 ++ regs->tnpc &= 0xffffffff;
4637 ++ }
4638 + address &= 0xffffffff;
4639 + }
4640 +
4641 +@@ -320,6 +686,29 @@ asmlinkage void __kprobes do_sparc64_fau
4642 + if (!vma)
4643 + goto bad_area;
4644 +
4645 ++#ifdef CONFIG_PAX_PAGEEXEC
4646 ++ /* PaX: detect ITLB misses on non-exec pages */
4647 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
4648 ++ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
4649 ++ {
4650 ++ if (address != regs->tpc)
4651 ++ goto good_area;
4652 ++
4653 ++ up_read(&mm->mmap_sem);
4654 ++ switch (pax_handle_fetch_fault(regs)) {
4655 ++
4656 ++#ifdef CONFIG_PAX_EMUPLT
4657 ++ case 2:
4658 ++ case 3:
4659 ++ return;
4660 ++#endif
4661 ++
4662 ++ }
4663 ++ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
4664 ++ do_group_exit(SIGKILL);
4665 ++ }
4666 ++#endif
4667 ++
4668 + /* Pure DTLB misses do not tell us whether the fault causing
4669 + * load/store/atomic was a write or not, it only says that there
4670 + * was no match. So in such a case we (carefully) read the
4671 +diff -urNp linux-2.6.27.10/arch/sparc64/mm/Makefile linux-2.6.27.10/arch/sparc64/mm/Makefile
4672 +--- linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-07 12:55:34.000000000 -0500
4673 ++++ linux-2.6.27.10/arch/sparc64/mm/Makefile 2008-11-18 03:38:43.000000000 -0500
4674 +@@ -2,7 +2,7 @@
4675 + #
4676 +
4677 + EXTRA_AFLAGS := -ansi
4678 +-EXTRA_CFLAGS := -Werror
4679 ++#EXTRA_CFLAGS := -Werror
4680 +
4681 + obj-y := ultra.o tlb.o tsb.o fault.o init.o generic.o
4682 +
4683 +diff -urNp linux-2.6.27.10/arch/um/sys-i386/syscalls.c linux-2.6.27.10/arch/um/sys-i386/syscalls.c
4684 +--- linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-07 12:55:34.000000000 -0500
4685 ++++ linux-2.6.27.10/arch/um/sys-i386/syscalls.c 2008-11-18 03:38:43.000000000 -0500
4686 +@@ -10,6 +10,21 @@
4687 + #include "asm/uaccess.h"
4688 + #include "asm/unistd.h"
4689 +
4690 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
4691 ++{
4692 ++ unsigned long pax_task_size = TASK_SIZE;
4693 ++
4694 ++#ifdef CONFIG_PAX_SEGMEXEC
4695 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
4696 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
4697 ++#endif
4698 ++
4699 ++ if (len > pax_task_size || addr > pax_task_size - len)
4700 ++ return -EINVAL;
4701 ++
4702 ++ return 0;
4703 ++}
4704 ++
4705 + /*
4706 + * Perform the select(nd, in, out, ex, tv) and mmap() system
4707 + * calls. Linux/i386 didn't use to be able to handle more than
4708 +diff -urNp linux-2.6.27.10/arch/x86/boot/bitops.h linux-2.6.27.10/arch/x86/boot/bitops.h
4709 +--- linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-07 12:55:34.000000000 -0500
4710 ++++ linux-2.6.27.10/arch/x86/boot/bitops.h 2008-11-18 03:38:44.000000000 -0500
4711 +@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
4712 + u8 v;
4713 + const u32 *p = (const u32 *)addr;
4714 +
4715 +- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
4716 ++ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
4717 + return v;
4718 + }
4719 +
4720 +@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
4721 +
4722 + static inline void set_bit(int nr, void *addr)
4723 + {
4724 +- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
4725 ++ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
4726 + }
4727 +
4728 + #endif /* BOOT_BITOPS_H */
4729 +diff -urNp linux-2.6.27.10/arch/x86/boot/boot.h linux-2.6.27.10/arch/x86/boot/boot.h
4730 +--- linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-07 12:55:34.000000000 -0500
4731 ++++ linux-2.6.27.10/arch/x86/boot/boot.h 2008-11-18 03:38:44.000000000 -0500
4732 +@@ -80,7 +80,7 @@ static inline void io_delay(void)
4733 + static inline u16 ds(void)
4734 + {
4735 + u16 seg;
4736 +- asm("movw %%ds,%0" : "=rm" (seg));
4737 ++ asm volatile("movw %%ds,%0" : "=rm" (seg));
4738 + return seg;
4739 + }
4740 +
4741 +@@ -176,7 +176,7 @@ static inline void wrgs32(u32 v, addr_t
4742 + static inline int memcmp(const void *s1, const void *s2, size_t len)
4743 + {
4744 + u8 diff;
4745 +- asm("repe; cmpsb; setnz %0"
4746 ++ asm volatile("repe; cmpsb; setnz %0"
4747 + : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
4748 + return diff;
4749 + }
4750 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/head_32.S linux-2.6.27.10/arch/x86/boot/compressed/head_32.S
4751 +--- linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-07 12:55:34.000000000 -0500
4752 ++++ linux-2.6.27.10/arch/x86/boot/compressed/head_32.S 2008-11-18 03:38:44.000000000 -0500
4753 +@@ -70,7 +70,7 @@ startup_32:
4754 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
4755 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
4756 + #else
4757 +- movl $LOAD_PHYSICAL_ADDR, %ebx
4758 ++ movl $____LOAD_PHYSICAL_ADDR, %ebx
4759 + #endif
4760 +
4761 + /* Replace the compressed data size with the uncompressed size */
4762 +@@ -105,7 +105,7 @@ startup_32:
4763 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
4764 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
4765 + #else
4766 +- movl $LOAD_PHYSICAL_ADDR, %ebp
4767 ++ movl $____LOAD_PHYSICAL_ADDR, %ebp
4768 + #endif
4769 +
4770 + /*
4771 +@@ -159,16 +159,15 @@ relocated:
4772 + * and where it was actually loaded.
4773 + */
4774 + movl %ebp, %ebx
4775 +- subl $LOAD_PHYSICAL_ADDR, %ebx
4776 ++ subl $____LOAD_PHYSICAL_ADDR, %ebx
4777 + jz 2f /* Nothing to be done if loaded at compiled addr. */
4778 + /*
4779 + * Process relocations.
4780 + */
4781 +
4782 + 1: subl $4, %edi
4783 +- movl 0(%edi), %ecx
4784 +- testl %ecx, %ecx
4785 +- jz 2f
4786 ++ movl (%edi), %ecx
4787 ++ jecxz 2f
4788 + addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
4789 + jmp 1b
4790 + 2:
4791 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/misc.c linux-2.6.27.10/arch/x86/boot/compressed/misc.c
4792 +--- linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-07 12:55:34.000000000 -0500
4793 ++++ linux-2.6.27.10/arch/x86/boot/compressed/misc.c 2008-11-18 03:38:44.000000000 -0500
4794 +@@ -371,7 +371,7 @@ static void parse_elf(void *output)
4795 + case PT_LOAD:
4796 + #ifdef CONFIG_RELOCATABLE
4797 + dest = output;
4798 +- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
4799 ++ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
4800 + #else
4801 + dest = (void *)(phdr->p_paddr);
4802 + #endif
4803 +@@ -423,7 +423,7 @@ asmlinkage void decompress_kernel(void *
4804 + if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff))
4805 + error("Destination address too large");
4806 + #ifndef CONFIG_RELOCATABLE
4807 +- if ((u32)output != LOAD_PHYSICAL_ADDR)
4808 ++ if ((u32)output != ____LOAD_PHYSICAL_ADDR)
4809 + error("Wrong destination address");
4810 + #endif
4811 + #endif
4812 +diff -urNp linux-2.6.27.10/arch/x86/boot/compressed/relocs.c linux-2.6.27.10/arch/x86/boot/compressed/relocs.c
4813 +--- linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-07 12:55:34.000000000 -0500
4814 ++++ linux-2.6.27.10/arch/x86/boot/compressed/relocs.c 2008-11-18 03:38:44.000000000 -0500
4815 +@@ -10,8 +10,11 @@
4816 + #define USE_BSD
4817 + #include <endian.h>
4818 +
4819 ++#include "../../../../include/linux/autoconf.h"
4820 ++
4821 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
4822 + static Elf32_Ehdr ehdr;
4823 ++static Elf32_Phdr *phdr;
4824 + static unsigned long reloc_count, reloc_idx;
4825 + static unsigned long *relocs;
4826 +
4827 +@@ -245,6 +248,36 @@ static void read_ehdr(FILE *fp)
4828 + }
4829 + }
4830 +
4831 ++static void read_phdrs(FILE *fp)
4832 ++{
4833 ++ int i;
4834 ++
4835 ++ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
4836 ++ if (!phdr) {
4837 ++ die("Unable to allocate %d program headers\n",
4838 ++ ehdr.e_phnum);
4839 ++ }
4840 ++ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
4841 ++ die("Seek to %d failed: %s\n",
4842 ++ ehdr.e_phoff, strerror(errno));
4843 ++ }
4844 ++ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
4845 ++ die("Cannot read ELF program headers: %s\n",
4846 ++ strerror(errno));
4847 ++ }
4848 ++ for(i = 0; i < ehdr.e_phnum; i++) {
4849 ++ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
4850 ++ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
4851 ++ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
4852 ++ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
4853 ++ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
4854 ++ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
4855 ++ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
4856 ++ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
4857 ++ }
4858 ++
4859 ++}
4860 ++
4861 + static void read_shdrs(FILE *fp)
4862 + {
4863 + int i;
4864 +@@ -341,6 +374,8 @@ static void read_symtabs(FILE *fp)
4865 + static void read_relocs(FILE *fp)
4866 + {
4867 + int i,j;
4868 ++ uint32_t base;
4869 ++
4870 + for (i = 0; i < ehdr.e_shnum; i++) {
4871 + struct section *sec = &secs[i];
4872 + if (sec->shdr.sh_type != SHT_REL) {
4873 +@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
4874 + die("Cannot read symbol table: %s\n",
4875 + strerror(errno));
4876 + }
4877 ++ base = 0;
4878 ++ for (j = 0; j < ehdr.e_phnum; j++) {
4879 ++ if (phdr[j].p_type != PT_LOAD )
4880 ++ continue;
4881 ++ if (secs[secs[i].shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[secs[i].shdr.sh_info].shdr.sh_offset > phdr[j].p_offset + phdr[j].p_filesz)
4882 ++ continue;
4883 ++ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
4884 ++ break;
4885 ++ }
4886 + for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
4887 + Elf32_Rel *rel = &sec->reltab[j];
4888 +- rel->r_offset = elf32_to_cpu(rel->r_offset);
4889 ++ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
4890 + rel->r_info = elf32_to_cpu(rel->r_info);
4891 + }
4892 + }
4893 +@@ -504,6 +548,23 @@ static void walk_relocs(void (*visit)(El
4894 + if (sym->st_shndx == SHN_ABS) {
4895 + continue;
4896 + }
4897 ++ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
4898 ++ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strncmp(sym_name(sym_strtab, sym), "__per_cpu_", 10))
4899 ++ continue;
4900 ++#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
4901 ++ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
4902 ++ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
4903 ++ continue;
4904 ++ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
4905 ++ continue;
4906 ++ if (!strcmp(sec_name(sym->st_shndx), ".text.head")) {
4907 ++ if (strcmp(sym_name(sym_strtab, sym), "__init_end") &&
4908 ++ strcmp(sym_name(sym_strtab, sym), "KERNEL_TEXT_OFFSET"))
4909 ++ continue;
4910 ++ }
4911 ++ if (!strcmp(sec_name(sym->st_shndx), ".text"))
4912 ++ continue;
4913 ++#endif
4914 + if (r_type == R_386_PC32) {
4915 + /* PC relative relocations don't need to be adjusted */
4916 + }
4917 +@@ -631,6 +692,7 @@ int main(int argc, char **argv)
4918 + fname, strerror(errno));
4919 + }
4920 + read_ehdr(fp);
4921 ++ read_phdrs(fp);
4922 + read_shdrs(fp);
4923 + read_strtabs(fp);
4924 + read_symtabs(fp);
4925 +diff -urNp linux-2.6.27.10/arch/x86/boot/cpucheck.c linux-2.6.27.10/arch/x86/boot/cpucheck.c
4926 +--- linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-07 12:55:34.000000000 -0500
4927 ++++ linux-2.6.27.10/arch/x86/boot/cpucheck.c 2008-11-18 03:38:44.000000000 -0500
4928 +@@ -74,7 +74,7 @@ static int has_fpu(void)
4929 + u16 fcw = -1, fsw = -1;
4930 + u32 cr0;
4931 +
4932 +- asm("movl %%cr0,%0" : "=r" (cr0));
4933 ++ asm volatile("movl %%cr0,%0" : "=r" (cr0));
4934 + if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
4935 + cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
4936 + asm volatile("movl %0,%%cr0" : : "r" (cr0));
4937 +@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
4938 + {
4939 + u32 f0, f1;
4940 +
4941 +- asm("pushfl ; "
4942 ++ asm volatile("pushfl ; "
4943 + "pushfl ; "
4944 + "popl %0 ; "
4945 + "movl %0,%1 ; "
4946 +@@ -115,7 +115,7 @@ static void get_flags(void)
4947 + set_bit(X86_FEATURE_FPU, cpu.flags);
4948 +
4949 + if (has_eflag(X86_EFLAGS_ID)) {
4950 +- asm("cpuid"
4951 ++ asm volatile("cpuid"
4952 + : "=a" (max_intel_level),
4953 + "=b" (cpu_vendor[0]),
4954 + "=d" (cpu_vendor[1]),
4955 +@@ -124,7 +124,7 @@ static void get_flags(void)
4956 +
4957 + if (max_intel_level >= 0x00000001 &&
4958 + max_intel_level <= 0x0000ffff) {
4959 +- asm("cpuid"
4960 ++ asm volatile("cpuid"
4961 + : "=a" (tfms),
4962 + "=c" (cpu.flags[4]),
4963 + "=d" (cpu.flags[0])
4964 +@@ -136,7 +136,7 @@ static void get_flags(void)
4965 + cpu.model += ((tfms >> 16) & 0xf) << 4;
4966 + }
4967 +
4968 +- asm("cpuid"
4969 ++ asm volatile("cpuid"
4970 + : "=a" (max_amd_level)
4971 + : "a" (0x80000000)
4972 + : "ebx", "ecx", "edx");
4973 +@@ -144,7 +144,7 @@ static void get_flags(void)
4974 + if (max_amd_level >= 0x80000001 &&
4975 + max_amd_level <= 0x8000ffff) {
4976 + u32 eax = 0x80000001;
4977 +- asm("cpuid"
4978 ++ asm volatile("cpuid"
4979 + : "+a" (eax),
4980 + "=c" (cpu.flags[6]),
4981 + "=d" (cpu.flags[1])
4982 +@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
4983 + u32 ecx = MSR_K7_HWCR;
4984 + u32 eax, edx;
4985 +
4986 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
4987 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
4988 + eax &= ~(1 << 15);
4989 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
4990 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
4991 +
4992 + get_flags(); /* Make sure it really did something */
4993 + err = check_flags();
4994 +@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
4995 + u32 ecx = MSR_VIA_FCR;
4996 + u32 eax, edx;
4997 +
4998 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
4999 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5000 + eax |= (1<<1)|(1<<7);
5001 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5002 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5003 +
5004 + set_bit(X86_FEATURE_CX8, cpu.flags);
5005 + err = check_flags();
5006 +@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
5007 + u32 eax, edx;
5008 + u32 level = 1;
5009 +
5010 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5011 +- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
5012 +- asm("cpuid"
5013 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5014 ++ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
5015 ++ asm volatile("cpuid"
5016 + : "+a" (level), "=d" (cpu.flags[0])
5017 + : : "ecx", "ebx");
5018 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5019 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5020 +
5021 + err = check_flags();
5022 + }
5023 +diff -urNp linux-2.6.27.10/arch/x86/boot/edd.c linux-2.6.27.10/arch/x86/boot/edd.c
5024 +--- linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-07 12:55:34.000000000 -0500
5025 ++++ linux-2.6.27.10/arch/x86/boot/edd.c 2008-11-18 03:38:44.000000000 -0500
5026 +@@ -76,7 +76,7 @@ static int get_edd_info(u8 devno, struct
5027 + ax = 0x4100;
5028 + bx = EDDMAGIC1;
5029 + dx = devno;
5030 +- asm("pushfl; stc; int $0x13; setc %%al; popfl"
5031 ++ asm volatile("pushfl; stc; int $0x13; setc %%al; popfl"
5032 + : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx)
5033 + : : "esi", "edi");
5034 +
5035 +@@ -95,7 +95,7 @@ static int get_edd_info(u8 devno, struct
5036 + ei->params.length = sizeof(ei->params);
5037 + ax = 0x4800;
5038 + dx = devno;
5039 +- asm("pushfl; int $0x13; popfl"
5040 ++ asm volatile("pushfl; int $0x13; popfl"
5041 + : "+a" (ax), "+d" (dx), "=m" (ei->params)
5042 + : "S" (&ei->params)
5043 + : "ebx", "ecx", "edi");
5044 +@@ -106,7 +106,7 @@ static int get_edd_info(u8 devno, struct
5045 + ax = 0x0800;
5046 + dx = devno;
5047 + di = 0;
5048 +- asm("pushw %%es; "
5049 ++ asm volatile("pushw %%es; "
5050 + "movw %%di,%%es; "
5051 + "pushfl; stc; int $0x13; setc %%al; popfl; "
5052 + "popw %%es"
5053 +diff -urNp linux-2.6.27.10/arch/x86/boot/main.c linux-2.6.27.10/arch/x86/boot/main.c
5054 +--- linux-2.6.27.10/arch/x86/boot/main.c 2008-11-07 12:55:34.000000000 -0500
5055 ++++ linux-2.6.27.10/arch/x86/boot/main.c 2008-11-18 03:38:44.000000000 -0500
5056 +@@ -78,7 +78,7 @@ static void query_ist(void)
5057 + if (cpu.level < 6)
5058 + return;
5059 +
5060 +- asm("int $0x15"
5061 ++ asm volatile("int $0x15"
5062 + : "=a" (boot_params.ist_info.signature),
5063 + "=b" (boot_params.ist_info.command),
5064 + "=c" (boot_params.ist_info.event),
5065 +diff -urNp linux-2.6.27.10/arch/x86/boot/mca.c linux-2.6.27.10/arch/x86/boot/mca.c
5066 +--- linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-07 12:55:34.000000000 -0500
5067 ++++ linux-2.6.27.10/arch/x86/boot/mca.c 2008-11-18 03:38:44.000000000 -0500
5068 +@@ -19,7 +19,7 @@ int query_mca(void)
5069 + u8 err;
5070 + u16 es, bx, len;
5071 +
5072 +- asm("pushw %%es ; "
5073 ++ asm volatile("pushw %%es ; "
5074 + "int $0x15 ; "
5075 + "setc %0 ; "
5076 + "movw %%es, %1 ; "
5077 +diff -urNp linux-2.6.27.10/arch/x86/boot/memory.c linux-2.6.27.10/arch/x86/boot/memory.c
5078 +--- linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-07 12:55:34.000000000 -0500
5079 ++++ linux-2.6.27.10/arch/x86/boot/memory.c 2008-11-18 03:38:44.000000000 -0500
5080 +@@ -30,7 +30,7 @@ static int detect_memory_e820(void)
5081 + /* Important: %edx is clobbered by some BIOSes,
5082 + so it must be either used for the error output
5083 + or explicitly marked clobbered. */
5084 +- asm("int $0x15; setc %0"
5085 ++ asm volatile("int $0x15; setc %0"
5086 + : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
5087 + "=m" (*desc)
5088 + : "D" (desc), "d" (SMAP), "a" (0xe820));
5089 +@@ -65,7 +65,7 @@ static int detect_memory_e801(void)
5090 +
5091 + bx = cx = dx = 0;
5092 + ax = 0xe801;
5093 +- asm("stc; int $0x15; setc %0"
5094 ++ asm volatile("stc; int $0x15; setc %0"
5095 + : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
5096 +
5097 + if (err)
5098 +@@ -95,7 +95,7 @@ static int detect_memory_88(void)
5099 + u8 err;
5100 +
5101 + ax = 0x8800;
5102 +- asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
5103 ++ asm volatile("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
5104 +
5105 + boot_params.screen_info.ext_mem_k = ax;
5106 +
5107 +diff -urNp linux-2.6.27.10/arch/x86/boot/video.c linux-2.6.27.10/arch/x86/boot/video.c
5108 +--- linux-2.6.27.10/arch/x86/boot/video.c 2008-11-07 12:55:34.000000000 -0500
5109 ++++ linux-2.6.27.10/arch/x86/boot/video.c 2008-11-18 03:38:44.000000000 -0500
5110 +@@ -23,7 +23,7 @@ static void store_cursor_position(void)
5111 +
5112 + ax = 0x0300;
5113 + bx = 0;
5114 +- asm(INT10
5115 ++ asm volatile(INT10
5116 + : "=d" (curpos), "+a" (ax), "+b" (bx)
5117 + : : "ecx", "esi", "edi");
5118 +
5119 +@@ -38,7 +38,7 @@ static void store_video_mode(void)
5120 + /* N.B.: the saving of the video page here is a bit silly,
5121 + since we pretty much assume page 0 everywhere. */
5122 + ax = 0x0f00;
5123 +- asm(INT10
5124 ++ asm volatile(INT10
5125 + : "+a" (ax), "=b" (page)
5126 + : : "ecx", "edx", "esi", "edi");
5127 +
5128 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vesa.c linux-2.6.27.10/arch/x86/boot/video-vesa.c
5129 +--- linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-07 12:55:34.000000000 -0500
5130 ++++ linux-2.6.27.10/arch/x86/boot/video-vesa.c 2008-11-18 03:38:44.000000000 -0500
5131 +@@ -41,7 +41,7 @@ static int vesa_probe(void)
5132 +
5133 + ax = 0x4f00;
5134 + di = (size_t)&vginfo;
5135 +- asm(INT10
5136 ++ asm volatile(INT10
5137 + : "+a" (ax), "+D" (di), "=m" (vginfo)
5138 + : : "ebx", "ecx", "edx", "esi");
5139 +
5140 +@@ -68,7 +68,7 @@ static int vesa_probe(void)
5141 + ax = 0x4f01;
5142 + cx = mode;
5143 + di = (size_t)&vminfo;
5144 +- asm(INT10
5145 ++ asm volatile(INT10
5146 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
5147 + : : "ebx", "edx", "esi");
5148 +
5149 +@@ -123,7 +123,7 @@ static int vesa_set_mode(struct mode_inf
5150 + ax = 0x4f01;
5151 + cx = vesa_mode;
5152 + di = (size_t)&vminfo;
5153 +- asm(INT10
5154 ++ asm volatile(INT10
5155 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
5156 + : : "ebx", "edx", "esi");
5157 +
5158 +@@ -203,19 +203,20 @@ static void vesa_dac_set_8bits(void)
5159 + /* Save the VESA protected mode info */
5160 + static void vesa_store_pm_info(void)
5161 + {
5162 +- u16 ax, bx, di, es;
5163 ++ u16 ax, bx, cx, di, es;
5164 +
5165 + ax = 0x4f0a;
5166 +- bx = di = 0;
5167 +- asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
5168 +- : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
5169 +- : : "ecx", "esi");
5170 ++ bx = cx = di = 0;
5171 ++ asm volatile("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
5172 ++ : "=d" (es), "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
5173 ++ : : "esi");
5174 +
5175 + if (ax != 0x004f)
5176 + return;
5177 +
5178 + boot_params.screen_info.vesapm_seg = es;
5179 + boot_params.screen_info.vesapm_off = di;
5180 ++ boot_params.screen_info.vesapm_size = cx;
5181 + }
5182 +
5183 + /*
5184 +@@ -269,7 +270,7 @@ void vesa_store_edid(void)
5185 + /* Note: The VBE DDC spec is different from the main VESA spec;
5186 + we genuinely have to assume all registers are destroyed here. */
5187 +
5188 +- asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
5189 ++ asm volatile("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
5190 + : "+a" (ax), "+b" (bx)
5191 + : "c" (cx), "D" (di)
5192 + : "esi");
5193 +@@ -285,7 +286,7 @@ void vesa_store_edid(void)
5194 + cx = 0; /* Controller 0 */
5195 + dx = 0; /* EDID block number */
5196 + di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
5197 +- asm(INT10
5198 ++ asm volatile(INT10
5199 + : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
5200 + : "c" (cx), "D" (di)
5201 + : "esi");
5202 +diff -urNp linux-2.6.27.10/arch/x86/boot/video-vga.c linux-2.6.27.10/arch/x86/boot/video-vga.c
5203 +--- linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-07 12:55:34.000000000 -0500
5204 ++++ linux-2.6.27.10/arch/x86/boot/video-vga.c 2008-11-18 03:38:44.000000000 -0500
5205 +@@ -225,7 +225,7 @@ static int vga_probe(void)
5206 + };
5207 + u8 vga_flag;
5208 +
5209 +- asm(INT10
5210 ++ asm volatile(INT10
5211 + : "=b" (ega_bx)
5212 + : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
5213 + : "ecx", "edx", "esi", "edi");
5214 +@@ -237,7 +237,7 @@ static int vga_probe(void)
5215 + /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
5216 + if ((u8)ega_bx != 0x10) {
5217 + /* EGA/VGA */
5218 +- asm(INT10
5219 ++ asm volatile(INT10
5220 + : "=a" (vga_flag)
5221 + : "a" (0x1a00)
5222 + : "ebx", "ecx", "edx", "esi", "edi");
5223 +diff -urNp linux-2.6.27.10/arch/x86/boot/voyager.c linux-2.6.27.10/arch/x86/boot/voyager.c
5224 +--- linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-07 12:55:34.000000000 -0500
5225 ++++ linux-2.6.27.10/arch/x86/boot/voyager.c 2008-11-18 03:38:44.000000000 -0500
5226 +@@ -23,7 +23,7 @@ int query_voyager(void)
5227 +
5228 + data_ptr[0] = 0xff; /* Flag on config not found(?) */
5229 +
5230 +- asm("pushw %%es ; "
5231 ++ asm volatile("pushw %%es ; "
5232 + "int $0x15 ; "
5233 + "setc %0 ; "
5234 + "movw %%es, %1 ; "
5235 +diff -urNp linux-2.6.27.10/arch/x86/ia32/ia32_signal.c linux-2.6.27.10/arch/x86/ia32/ia32_signal.c
5236 +--- linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-07 12:55:34.000000000 -0500
5237 ++++ linux-2.6.27.10/arch/x86/ia32/ia32_signal.c 2008-11-18 03:38:44.000000000 -0500
5238 +@@ -535,6 +535,7 @@ int ia32_setup_rt_frame(int sig, struct
5239 + __NR_ia32_rt_sigreturn,
5240 + 0x80cd,
5241 + 0,
5242 ++ 0
5243 + };
5244 +
5245 + frame = get_sigframe(ka, regs, sizeof(*frame));
5246 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig linux-2.6.27.10/arch/x86/Kconfig
5247 +--- linux-2.6.27.10/arch/x86/Kconfig 2008-11-17 20:03:30.000000000 -0500
5248 ++++ linux-2.6.27.10/arch/x86/Kconfig 2008-11-18 03:38:44.000000000 -0500
5249 +@@ -912,7 +912,7 @@ config PAGE_OFFSET
5250 + hex
5251 + default 0xB0000000 if VMSPLIT_3G_OPT
5252 + default 0x80000000 if VMSPLIT_2G
5253 +- default 0x78000000 if VMSPLIT_2G_OPT
5254 ++ default 0x70000000 if VMSPLIT_2G_OPT
5255 + default 0x40000000 if VMSPLIT_1G
5256 + default 0xC0000000
5257 + depends on X86_32
5258 +@@ -1293,8 +1293,7 @@ config KEXEC_JUMP
5259 + config PHYSICAL_START
5260 + hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
5261 + default "0x1000000" if X86_NUMAQ
5262 +- default "0x200000" if X86_64
5263 +- default "0x100000"
5264 ++ default "0x200000"
5265 + help
5266 + This gives the physical address where the kernel is loaded.
5267 +
5268 +@@ -1386,9 +1385,9 @@ config HOTPLUG_CPU
5269 + suspend.
5270 +
5271 + config COMPAT_VDSO
5272 +- def_bool y
5273 ++ def_bool n
5274 + prompt "Compat VDSO support"
5275 +- depends on X86_32 || IA32_EMULATION
5276 ++ depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
5277 + help
5278 + Map the 32-bit VDSO to the predictable old-style address too.
5279 + ---help---
5280 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.cpu linux-2.6.27.10/arch/x86/Kconfig.cpu
5281 +--- linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-07 12:55:34.000000000 -0500
5282 ++++ linux-2.6.27.10/arch/x86/Kconfig.cpu 2008-11-18 03:38:44.000000000 -0500
5283 +@@ -340,7 +340,7 @@ config X86_PPRO_FENCE
5284 +
5285 + config X86_F00F_BUG
5286 + def_bool y
5287 +- depends on M586MMX || M586TSC || M586 || M486 || M386
5288 ++ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
5289 +
5290 + config X86_WP_WORKS_OK
5291 + def_bool y
5292 +@@ -360,7 +360,7 @@ config X86_POPAD_OK
5293 +
5294 + config X86_ALIGNMENT_16
5295 + def_bool y
5296 +- depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5297 ++ depends on MWINCHIP3D || MWINCHIP2 || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
5298 +
5299 + config X86_INTEL_USERCOPY
5300 + def_bool y
5301 +@@ -406,7 +406,7 @@ config X86_CMPXCHG64
5302 + # generates cmov.
5303 + config X86_CMOV
5304 + def_bool y
5305 +- depends on (MK7 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
5306 ++ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || X86_64)
5307 +
5308 + config X86_MINIMUM_CPU_FAMILY
5309 + int
5310 +diff -urNp linux-2.6.27.10/arch/x86/Kconfig.debug linux-2.6.27.10/arch/x86/Kconfig.debug
5311 +--- linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-07 12:55:34.000000000 -0500
5312 ++++ linux-2.6.27.10/arch/x86/Kconfig.debug 2008-11-18 03:38:44.000000000 -0500
5313 +@@ -94,7 +94,7 @@ config X86_PTDUMP
5314 + config DEBUG_RODATA
5315 + bool "Write protect kernel read-only data structures"
5316 + default y
5317 +- depends on DEBUG_KERNEL
5318 ++ depends on DEBUG_KERNEL && BROKEN
5319 + help
5320 + Mark the kernel read-only data as write-protected in the pagetables,
5321 + in order to catch accidental (and incorrect) writes to such const
5322 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/boot.c linux-2.6.27.10/arch/x86/kernel/acpi/boot.c
5323 +--- linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:36.000000000 -0500
5324 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/boot.c 2008-12-10 22:35:46.000000000 -0500
5325 +@@ -1640,7 +1640,7 @@ static struct dmi_system_id __initdata a
5326 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
5327 + },
5328 + },
5329 +- {}
5330 ++ { NULL, NULL, {{0, NULL}}, NULL}
5331 + };
5332 +
5333 + /*
5334 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S
5335 +--- linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-07 12:55:34.000000000 -0500
5336 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/realmode/wakeup.S 2008-11-18 03:38:44.000000000 -0500
5337 +@@ -104,7 +104,7 @@ _start:
5338 + movl %eax, %ecx
5339 + orl %edx, %ecx
5340 + jz 1f
5341 +- movl $0xc0000080, %ecx
5342 ++ mov $MSR_EFER, %ecx
5343 + wrmsr
5344 + 1:
5345 +
5346 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c
5347 +--- linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-07 12:55:34.000000000 -0500
5348 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/sleep.c 2008-11-18 11:45:34.000000000 -0500
5349 +@@ -37,6 +37,10 @@ int acpi_save_state_mem(void)
5350 + {
5351 + struct wakeup_header *header;
5352 +
5353 ++#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) && defined(CONFIG_PAX_KERNEXEC)
5354 ++ unsigned long cr0;
5355 ++#endif
5356 ++
5357 + if (!acpi_realmode) {
5358 + printk(KERN_ERR "Could not allocate memory during boot, "
5359 + "S3 disabled\n");
5360 +@@ -99,8 +103,18 @@ int acpi_save_state_mem(void)
5361 + header->trampoline_segment = setup_trampoline() >> 4;
5362 + #ifdef CONFIG_SMP
5363 + stack_start.sp = temp_stack + 4096;
5364 ++
5365 ++#ifdef CONFIG_PAX_KERNEXEC
5366 ++ pax_open_kernel(cr0);
5367 ++#endif
5368 ++
5369 + early_gdt_descr.address =
5370 + (unsigned long)get_cpu_gdt_table(smp_processor_id());
5371 ++
5372 ++#ifdef CONFIG_PAX_KERNEXEC
5373 ++ pax_close_kernel(cr0);
5374 ++#endif
5375 ++
5376 + #endif
5377 + initial_code = (unsigned long)wakeup_long64;
5378 + saved_magic = 0x123456789abcdef0;
5379 +diff -urNp linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S
5380 +--- linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-07 12:55:34.000000000 -0500
5381 ++++ linux-2.6.27.10/arch/x86/kernel/acpi/wakeup_32.S 2008-11-18 03:38:44.000000000 -0500
5382 +@@ -30,13 +30,11 @@ wakeup_pmode_return:
5383 + # and restore the stack ... but you need gdt for this to work
5384 + movl saved_context_esp, %esp
5385 +
5386 +- movl %cs:saved_magic, %eax
5387 +- cmpl $0x12345678, %eax
5388 ++ cmpl $0x12345678, saved_magic
5389 + jne bogus_magic
5390 +
5391 + # jump to place where we left off
5392 +- movl saved_eip, %eax
5393 +- jmp *%eax
5394 ++ jmp *(saved_eip)
5395 +
5396 + bogus_magic:
5397 + jmp bogus_magic
5398 +diff -urNp linux-2.6.27.10/arch/x86/kernel/alternative.c linux-2.6.27.10/arch/x86/kernel/alternative.c
5399 +--- linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-07 12:55:34.000000000 -0500
5400 ++++ linux-2.6.27.10/arch/x86/kernel/alternative.c 2008-11-18 03:38:44.000000000 -0500
5401 +@@ -393,7 +393,7 @@ void apply_paravirt(struct paravirt_patc
5402 +
5403 + BUG_ON(p->len > MAX_PATCH_LEN);
5404 + /* prep the buffer with the original instructions */
5405 +- memcpy(insnbuf, p->instr, p->len);
5406 ++ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
5407 + used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
5408 + (unsigned long)p->instr, p->len);
5409 +
5410 +@@ -473,11 +473,26 @@ void __init alternative_instructions(voi
5411 + * instructions. And on the local CPU you need to be protected again NMI or MCE
5412 + * handlers seeing an inconsistent instruction while you patch.
5413 + */
5414 +-void *text_poke_early(void *addr, const void *opcode, size_t len)
5415 ++void *__kprobes text_poke_early(void *addr, const void *opcode, size_t len)
5416 + {
5417 + unsigned long flags;
5418 ++
5419 ++#ifdef CONFIG_PAX_KERNEXEC
5420 ++ unsigned long cr0;
5421 ++#endif
5422 ++
5423 + local_irq_save(flags);
5424 +- memcpy(addr, opcode, len);
5425 ++
5426 ++#ifdef CONFIG_PAX_KERNEXEC
5427 ++ pax_open_kernel(cr0);
5428 ++#endif
5429 ++
5430 ++ memcpy(ktla_ktva(addr), opcode, len);
5431 ++
5432 ++#ifdef CONFIG_PAX_KERNEXEC
5433 ++ pax_close_kernel(cr0);
5434 ++#endif
5435 ++
5436 + local_irq_restore(flags);
5437 + sync_core();
5438 + /* Could also do a CLFLUSH here to speed up CPU recovery; but
5439 +@@ -498,33 +513,27 @@ void *text_poke_early(void *addr, const
5440 + */
5441 + void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
5442 + {
5443 +- unsigned long flags;
5444 +- char *vaddr;
5445 +- int nr_pages = 2;
5446 ++ unsigned char *vaddr = ktla_ktva(addr);
5447 + struct page *pages[2];
5448 +- int i;
5449 ++ size_t i;
5450 ++
5451 ++ if (!core_kernel_text((unsigned long)addr)
5452 +
5453 +- if (!core_kernel_text((unsigned long)addr)) {
5454 +- pages[0] = vmalloc_to_page(addr);
5455 +- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
5456 ++#if defined(CONFIG_X86_32) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
5457 ++ && (vaddr < MODULES_VADDR || MODULES_END < vaddr)
5458 ++#endif
5459 ++
5460 ++ ) {
5461 ++ pages[0] = vmalloc_to_page(vaddr);
5462 ++ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
5463 + } else {
5464 +- pages[0] = virt_to_page(addr);
5465 ++ pages[0] = virt_to_page(vaddr);
5466 + WARN_ON(!PageReserved(pages[0]));
5467 +- pages[1] = virt_to_page(addr + PAGE_SIZE);
5468 ++ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
5469 + }
5470 + BUG_ON(!pages[0]);
5471 +- if (!pages[1])
5472 +- nr_pages = 1;
5473 +- vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
5474 +- BUG_ON(!vaddr);
5475 +- local_irq_save(flags);
5476 +- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
5477 +- local_irq_restore(flags);
5478 +- vunmap(vaddr);
5479 +- sync_core();
5480 +- /* Could also do a CLFLUSH here to speed up CPU recovery; but
5481 +- that causes hangs on some VIA CPUs. */
5482 ++ text_poke_early(addr, opcode, len);
5483 + for (i = 0; i < len; i++)
5484 +- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
5485 ++ BUG_ON((vaddr)[i] != ((unsigned char *)opcode)[i]);
5486 + return addr;
5487 + }
5488 +diff -urNp linux-2.6.27.10/arch/x86/kernel/apm_32.c linux-2.6.27.10/arch/x86/kernel/apm_32.c
5489 +--- linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-07 12:55:34.000000000 -0500
5490 ++++ linux-2.6.27.10/arch/x86/kernel/apm_32.c 2008-11-18 03:38:44.000000000 -0500
5491 +@@ -408,7 +408,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitq
5492 + static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
5493 + static struct apm_user *user_list;
5494 + static DEFINE_SPINLOCK(user_list_lock);
5495 +-static const struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } };
5496 ++static const struct desc_struct bad_bios_desc = { { { 0, 0x00409300 } } };
5497 +
5498 + static const char driver_version[] = "1.16ac"; /* no spaces */
5499 +
5500 +@@ -603,19 +603,42 @@ static u8 apm_bios_call(u32 func, u32 eb
5501 + struct desc_struct save_desc_40;
5502 + struct desc_struct *gdt;
5503 +
5504 ++#ifdef CONFIG_PAX_KERNEXEC
5505 ++ unsigned long cr0;
5506 ++#endif
5507 ++
5508 + cpus = apm_save_cpus();
5509 +
5510 + cpu = get_cpu();
5511 + gdt = get_cpu_gdt_table(cpu);
5512 + save_desc_40 = gdt[0x40 / 8];
5513 ++
5514 ++#ifdef CONFIG_PAX_KERNEXEC
5515 ++ pax_open_kernel(cr0);
5516 ++#endif
5517 ++
5518 + gdt[0x40 / 8] = bad_bios_desc;
5519 +
5520 ++#ifdef CONFIG_PAX_KERNEXEC
5521 ++ pax_close_kernel(cr0);
5522 ++#endif
5523 ++
5524 + apm_irq_save(flags);
5525 + APM_DO_SAVE_SEGS;
5526 + apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi);
5527 + APM_DO_RESTORE_SEGS;
5528 + apm_irq_restore(flags);
5529 ++
5530 ++#ifdef CONFIG_PAX_KERNEXEC
5531 ++ pax_open_kernel(cr0);
5532 ++#endif
5533 ++
5534 + gdt[0x40 / 8] = save_desc_40;
5535 ++
5536 ++#ifdef CONFIG_PAX_KERNEXEC
5537 ++ pax_close_kernel(cr0);
5538 ++#endif
5539 ++
5540 + put_cpu();
5541 + apm_restore_cpus(cpus);
5542 +
5543 +@@ -646,19 +669,42 @@ static u8 apm_bios_call_simple(u32 func,
5544 + struct desc_struct save_desc_40;
5545 + struct desc_struct *gdt;
5546 +
5547 ++#ifdef CONFIG_PAX_KERNEXEC
5548 ++ unsigned long cr0;
5549 ++#endif
5550 ++
5551 + cpus = apm_save_cpus();
5552 +
5553 + cpu = get_cpu();
5554 + gdt = get_cpu_gdt_table(cpu);
5555 + save_desc_40 = gdt[0x40 / 8];
5556 ++
5557 ++#ifdef CONFIG_PAX_KERNEXEC
5558 ++ pax_open_kernel(cr0);
5559 ++#endif
5560 ++
5561 + gdt[0x40 / 8] = bad_bios_desc;
5562 +
5563 ++#ifdef CONFIG_PAX_KERNEXEC
5564 ++ pax_close_kernel(cr0);
5565 ++#endif
5566 ++
5567 + apm_irq_save(flags);
5568 + APM_DO_SAVE_SEGS;
5569 + error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax);
5570 + APM_DO_RESTORE_SEGS;
5571 + apm_irq_restore(flags);
5572 ++
5573 ++#ifdef CONFIG_PAX_KERNEXEC
5574 ++ pax_open_kernel(cr0);
5575 ++#endif
5576 ++
5577 + gdt[0x40 / 8] = save_desc_40;
5578 ++
5579 ++#ifdef CONFIG_PAX_KERNEXEC
5580 ++ pax_close_kernel(cr0);
5581 ++#endif
5582 ++
5583 + put_cpu();
5584 + apm_restore_cpus(cpus);
5585 + return error;
5586 +@@ -930,7 +976,7 @@ recalc:
5587 +
5588 + static void apm_power_off(void)
5589 + {
5590 +- unsigned char po_bios_call[] = {
5591 ++ const unsigned char po_bios_call[] = {
5592 + 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
5593 + 0x8e, 0xd0, /* movw ax,ss */
5594 + 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
5595 +@@ -1877,7 +1923,10 @@ static const struct file_operations apm_
5596 + static struct miscdevice apm_device = {
5597 + APM_MINOR_DEV,
5598 + "apm_bios",
5599 +- &apm_bios_fops
5600 ++ &apm_bios_fops,
5601 ++ {NULL, NULL},
5602 ++ NULL,
5603 ++ NULL
5604 + };
5605 +
5606 +
5607 +@@ -2198,7 +2247,7 @@ static struct dmi_system_id __initdata a
5608 + { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
5609 + },
5610 +
5611 +- { }
5612 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
5613 + };
5614 +
5615 + /*
5616 +@@ -2216,6 +2265,10 @@ static int __init apm_init(void)
5617 + struct desc_struct *gdt;
5618 + int err;
5619 +
5620 ++#ifdef CONFIG_PAX_KERNEXEC
5621 ++ unsigned long cr0;
5622 ++#endif
5623 ++
5624 + dmi_check_system(apm_dmi_table);
5625 +
5626 + if (apm_info.bios.version == 0 || paravirt_enabled() || machine_is_olpc()) {
5627 +@@ -2289,9 +2342,18 @@ static int __init apm_init(void)
5628 + * This is for buggy BIOS's that refer to (real mode) segment 0x40
5629 + * even though they are called in protected mode.
5630 + */
5631 ++
5632 ++#ifdef CONFIG_PAX_KERNEXEC
5633 ++ pax_open_kernel(cr0);
5634 ++#endif
5635 ++
5636 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
5637 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
5638 +
5639 ++#ifdef CONFIG_PAX_KERNEXEC
5640 ++ pax_close_kernel(cr0);
5641 ++#endif
5642 ++
5643 + /*
5644 + * Set up the long jump entry point to the APM BIOS, which is called
5645 + * from inline assembly.
5646 +@@ -2310,6 +2372,11 @@ static int __init apm_init(void)
5647 + * code to that CPU.
5648 + */
5649 + gdt = get_cpu_gdt_table(0);
5650 ++
5651 ++#ifdef CONFIG_PAX_KERNEXEC
5652 ++ pax_open_kernel(cr0);
5653 ++#endif
5654 ++
5655 + set_base(gdt[APM_CS >> 3],
5656 + __va((unsigned long)apm_info.bios.cseg << 4));
5657 + set_base(gdt[APM_CS_16 >> 3],
5658 +@@ -2317,6 +2384,10 @@ static int __init apm_init(void)
5659 + set_base(gdt[APM_DS >> 3],
5660 + __va((unsigned long)apm_info.bios.dseg << 4));
5661 +
5662 ++#ifdef CONFIG_PAX_KERNEXEC
5663 ++ pax_close_kernel(cr0);
5664 ++#endif
5665 ++
5666 + proc_create("apm", 0, NULL, &apm_file_ops);
5667 +
5668 + kapmd_task = kthread_create(apm, NULL, "kapmd");
5669 +diff -urNp linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c
5670 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-07 12:55:34.000000000 -0500
5671 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_32.c 2008-11-18 03:38:44.000000000 -0500
5672 +@@ -100,6 +100,7 @@ void foo(void)
5673 + DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
5674 + DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
5675 + DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
5676 ++ DEFINE(PERCPU_MODULE_RESERVE, PERCPU_MODULE_RESERVE);
5677 +
5678 + OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
5679 +
5680 +@@ -113,6 +114,7 @@ void foo(void)
5681 + OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
5682 + OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
5683 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
5684 ++ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
5685 + #endif
5686 +
5687 + #ifdef CONFIG_XEN
5688 +diff -urNp linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c
5689 +--- linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-07 12:55:34.000000000 -0500
5690 ++++ linux-2.6.27.10/arch/x86/kernel/asm-offsets_64.c 2008-11-18 03:38:44.000000000 -0500
5691 +@@ -122,6 +122,7 @@ int main(void)
5692 + ENTRY(cr8);
5693 + BLANK();
5694 + #undef ENTRY
5695 ++ DEFINE(TSS_size, sizeof(struct tss_struct));
5696 + DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
5697 + BLANK();
5698 + DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
5699 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c
5700 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-07 12:55:34.000000000 -0500
5701 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common_64.c 2008-11-18 03:38:44.000000000 -0500
5702 +@@ -37,22 +37,6 @@
5703 +
5704 + #include "cpu.h"
5705 +
5706 +-/* We need valid kernel segments for data and code in long mode too
5707 +- * IRET will check the segment types kkeil 2000/10/28
5708 +- * Also sysret mandates a special GDT layout
5709 +- */
5710 +-/* The TLS descriptors are currently at a different place compared to i386.
5711 +- Hopefully nobody expects them at a fixed place (Wine?) */
5712 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
5713 +- [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
5714 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
5715 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
5716 +- [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
5717 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
5718 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
5719 +-} };
5720 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
5721 +-
5722 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
5723 +
5724 + /* Current gdt points %fs at the "master" per-cpu area: after this,
5725 +@@ -457,15 +441,13 @@ cpumask_t cpu_initialized __cpuinitdata
5726 + struct x8664_pda **_cpu_pda __read_mostly;
5727 + EXPORT_SYMBOL(_cpu_pda);
5728 +
5729 +-struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
5730 ++struct desc_ptr idt_descr __read_only = { 256 * 16 - 1, (unsigned long) idt_table };
5731 +
5732 + char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
5733 +
5734 + unsigned long __supported_pte_mask __read_mostly = ~0UL;
5735 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
5736 +
5737 +-static int do_not_nx __cpuinitdata;
5738 +-
5739 + /* noexec=on|off
5740 + Control non executable mappings for 64bit processes.
5741 +
5742 +@@ -478,9 +460,7 @@ static int __init nonx_setup(char *str)
5743 + return -EINVAL;
5744 + if (!strncmp(str, "on", 2)) {
5745 + __supported_pte_mask |= _PAGE_NX;
5746 +- do_not_nx = 0;
5747 + } else if (!strncmp(str, "off", 3)) {
5748 +- do_not_nx = 1;
5749 + __supported_pte_mask &= ~_PAGE_NX;
5750 + }
5751 + return 0;
5752 +@@ -576,7 +556,7 @@ void __cpuinit check_efer(void)
5753 + unsigned long efer;
5754 +
5755 + rdmsrl(MSR_EFER, efer);
5756 +- if (!(efer & EFER_NX) || do_not_nx)
5757 ++ if (!(efer & EFER_NX))
5758 + __supported_pte_mask &= ~_PAGE_NX;
5759 + }
5760 +
5761 +@@ -598,7 +578,7 @@ DEFINE_PER_CPU(struct orig_ist, orig_ist
5762 + void __cpuinit cpu_init(void)
5763 + {
5764 + int cpu = stack_smp_processor_id();
5765 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
5766 ++ struct tss_struct *t = init_tss + cpu;
5767 + struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
5768 + unsigned long v;
5769 + char *estacks = NULL;
5770 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/common.c linux-2.6.27.10/arch/x86/kernel/cpu/common.c
5771 +--- linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-07 12:55:34.000000000 -0500
5772 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/common.c 2008-11-18 03:38:44.000000000 -0500
5773 +@@ -4,7 +4,6 @@
5774 + #include <linux/smp.h>
5775 + #include <linux/module.h>
5776 + #include <linux/percpu.h>
5777 +-#include <linux/bootmem.h>
5778 + #include <asm/processor.h>
5779 + #include <asm/i387.h>
5780 + #include <asm/msr.h>
5781 +@@ -22,42 +21,6 @@
5782 +
5783 + #include "cpu.h"
5784 +
5785 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
5786 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
5787 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
5788 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
5789 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
5790 +- /*
5791 +- * Segments used for calling PnP BIOS have byte granularity.
5792 +- * They code segments and data segments have fixed 64k limits,
5793 +- * the transfer segment sizes are set at run time.
5794 +- */
5795 +- /* 32-bit code */
5796 +- [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
5797 +- /* 16-bit code */
5798 +- [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
5799 +- /* 16-bit data */
5800 +- [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
5801 +- /* 16-bit data */
5802 +- [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
5803 +- /* 16-bit data */
5804 +- [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
5805 +- /*
5806 +- * The APM segments have byte granularity and their bases
5807 +- * are set at run time. All have 64k limits.
5808 +- */
5809 +- /* 32-bit code */
5810 +- [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
5811 +- /* 16-bit code */
5812 +- [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
5813 +- /* data */
5814 +- [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
5815 +-
5816 +- [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
5817 +- [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
5818 +-} };
5819 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
5820 +-
5821 + __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
5822 +
5823 + static int cachesize_override __cpuinitdata = -1;
5824 +@@ -493,6 +456,10 @@ static void __cpuinit identify_cpu(struc
5825 + * we do "generic changes."
5826 + */
5827 +
5828 ++#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
5829 ++ setup_clear_cpu_cap(X86_FEATURE_SEP);
5830 ++#endif
5831 ++
5832 + /* If the model name is still unset, do table lookup. */
5833 + if (!c->x86_model_id[0]) {
5834 + char *p;
5835 +@@ -629,7 +596,7 @@ static __init int setup_disablecpuid(cha
5836 + }
5837 + __setup("clearcpuid=", setup_disablecpuid);
5838 +
5839 +-cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
5840 ++cpumask_t cpu_initialized = CPU_MASK_NONE;
5841 +
5842 + void __init early_cpu_init(void)
5843 + {
5844 +@@ -658,7 +625,7 @@ void switch_to_new_gdt(void)
5845 + {
5846 + struct desc_ptr gdt_descr;
5847 +
5848 +- gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
5849 ++ gdt_descr.address = (unsigned long)get_cpu_gdt_table(smp_processor_id());
5850 + gdt_descr.size = GDT_SIZE - 1;
5851 + load_gdt(&gdt_descr);
5852 + asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory");
5853 +@@ -674,7 +641,7 @@ void __cpuinit cpu_init(void)
5854 + {
5855 + int cpu = smp_processor_id();
5856 + struct task_struct *curr = current;
5857 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
5858 ++ struct tss_struct *t = init_tss + cpu;
5859 + struct thread_struct *thread = &curr->thread;
5860 +
5861 + if (cpu_test_and_set(cpu, cpu_initialized)) {
5862 +@@ -729,7 +696,7 @@ void __cpuinit cpu_init(void)
5863 + }
5864 +
5865 + #ifdef CONFIG_HOTPLUG_CPU
5866 +-void __cpuinit cpu_uninit(void)
5867 ++void cpu_uninit(void)
5868 + {
5869 + int cpu = raw_smp_processor_id();
5870 + cpu_clear(cpu, cpu_initialized);
5871 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
5872 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-07 12:55:34.000000000 -0500
5873 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-11-18 03:38:44.000000000 -0500
5874 +@@ -560,7 +560,7 @@ static const struct dmi_system_id sw_any
5875 + DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
5876 + },
5877 + },
5878 +- { }
5879 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
5880 + };
5881 + #endif
5882 +
5883 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
5884 +--- linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-07 12:55:34.000000000 -0500
5885 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-11-18 03:38:44.000000000 -0500
5886 +@@ -225,7 +225,7 @@ static struct cpu_model models[] =
5887 + { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
5888 + { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
5889 +
5890 +- { NULL, }
5891 ++ { NULL, NULL, 0, NULL}
5892 + };
5893 + #undef _BANIAS
5894 + #undef BANIAS
5895 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/intel.c linux-2.6.27.10/arch/x86/kernel/cpu/intel.c
5896 +--- linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-07 12:55:34.000000000 -0500
5897 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/intel.c 2008-11-18 03:38:44.000000000 -0500
5898 +@@ -107,7 +107,7 @@ static void __cpuinit trap_init_f00f_bug
5899 + * Update the IDT descriptor and reload the IDT so that
5900 + * it uses the read-only mapped virtual address.
5901 + */
5902 +- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
5903 ++ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
5904 + load_idt(&idt_descr);
5905 + }
5906 + #endif
5907 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c
5908 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-07 12:55:34.000000000 -0500
5909 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-11-18 03:38:44.000000000 -0500
5910 +@@ -681,6 +681,7 @@ static struct miscdevice mce_log_device
5911 + MISC_MCELOG_MINOR,
5912 + "mcelog",
5913 + &mce_chrdev_ops,
5914 ++ {NULL, NULL}, NULL, NULL
5915 + };
5916 +
5917 + static unsigned long old_cr4 __initdata;
5918 +diff -urNp linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c
5919 +--- linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-07 12:55:34.000000000 -0500
5920 ++++ linux-2.6.27.10/arch/x86/kernel/cpu/mtrr/generic.c 2008-11-18 03:38:44.000000000 -0500
5921 +@@ -31,11 +31,11 @@ static struct fixed_range_block fixed_ra
5922 + { MTRRfix64K_00000_MSR, 1 }, /* one 64k MTRR */
5923 + { MTRRfix16K_80000_MSR, 2 }, /* two 16k MTRRs */
5924 + { MTRRfix4K_C0000_MSR, 8 }, /* eight 4k MTRRs */
5925 +- {}
5926 ++ { 0, 0 }
5927 + };
5928 +
5929 + static unsigned long smp_changes_mask;
5930 +-static struct mtrr_state mtrr_state = {};
5931 ++static struct mtrr_state mtrr_state;
5932 + static int mtrr_state_set;
5933 + u64 mtrr_tom2;
5934 +
5935 +diff -urNp linux-2.6.27.10/arch/x86/kernel/crash.c linux-2.6.27.10/arch/x86/kernel/crash.c
5936 +--- linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-07 12:55:34.000000000 -0500
5937 ++++ linux-2.6.27.10/arch/x86/kernel/crash.c 2008-11-18 03:38:44.000000000 -0500
5938 +@@ -59,7 +59,7 @@ static int crash_nmi_callback(struct not
5939 + local_irq_disable();
5940 +
5941 + #ifdef CONFIG_X86_32
5942 +- if (!user_mode_vm(regs)) {
5943 ++ if (!user_mode(regs)) {
5944 + crash_fixup_ss_esp(&fixed_regs, regs);
5945 + regs = &fixed_regs;
5946 + }
5947 +diff -urNp linux-2.6.27.10/arch/x86/kernel/doublefault_32.c linux-2.6.27.10/arch/x86/kernel/doublefault_32.c
5948 +--- linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-07 12:55:34.000000000 -0500
5949 ++++ linux-2.6.27.10/arch/x86/kernel/doublefault_32.c 2008-11-18 03:38:44.000000000 -0500
5950 +@@ -11,7 +11,7 @@
5951 +
5952 + #define DOUBLEFAULT_STACKSIZE (1024)
5953 + static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
5954 +-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
5955 ++#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
5956 +
5957 + #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
5958 +
5959 +@@ -21,7 +21,7 @@ static void doublefault_fn(void)
5960 + unsigned long gdt, tss;
5961 +
5962 + store_gdt(&gdt_desc);
5963 +- gdt = gdt_desc.address;
5964 ++ gdt = (unsigned long)gdt_desc.address;
5965 +
5966 + printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
5967 +
5968 +@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cach
5969 + /* 0x2 bit is always set */
5970 + .flags = X86_EFLAGS_SF | 0x2,
5971 + .sp = STACK_START,
5972 +- .es = __USER_DS,
5973 ++ .es = __KERNEL_DS,
5974 + .cs = __KERNEL_CS,
5975 + .ss = __KERNEL_DS,
5976 +- .ds = __USER_DS,
5977 ++ .ds = __KERNEL_DS,
5978 + .fs = __KERNEL_PERCPU,
5979 +
5980 + .__cr3 = __pa(swapper_pg_dir)
5981 +diff -urNp linux-2.6.27.10/arch/x86/kernel/efi_32.c linux-2.6.27.10/arch/x86/kernel/efi_32.c
5982 +--- linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-07 12:55:34.000000000 -0500
5983 ++++ linux-2.6.27.10/arch/x86/kernel/efi_32.c 2008-11-18 03:38:44.000000000 -0500
5984 +@@ -38,70 +38,38 @@
5985 + */
5986 +
5987 + static unsigned long efi_rt_eflags;
5988 +-static pgd_t efi_bak_pg_dir_pointer[2];
5989 ++static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
5990 +
5991 +-void efi_call_phys_prelog(void)
5992 ++void __init efi_call_phys_prelog(void)
5993 + {
5994 +- unsigned long cr4;
5995 +- unsigned long temp;
5996 + struct desc_ptr gdt_descr;
5997 +
5998 + local_irq_save(efi_rt_eflags);
5999 +
6000 +- /*
6001 +- * If I don't have PAE, I should just duplicate two entries in page
6002 +- * directory. If I have PAE, I just need to duplicate one entry in
6003 +- * page directory.
6004 +- */
6005 +- cr4 = read_cr4_safe();
6006 +
6007 +- if (cr4 & X86_CR4_PAE) {
6008 +- efi_bak_pg_dir_pointer[0].pgd =
6009 +- swapper_pg_dir[pgd_index(0)].pgd;
6010 +- swapper_pg_dir[0].pgd =
6011 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
6012 +- } else {
6013 +- efi_bak_pg_dir_pointer[0].pgd =
6014 +- swapper_pg_dir[pgd_index(0)].pgd;
6015 +- efi_bak_pg_dir_pointer[1].pgd =
6016 +- swapper_pg_dir[pgd_index(0x400000)].pgd;
6017 +- swapper_pg_dir[pgd_index(0)].pgd =
6018 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
6019 +- temp = PAGE_OFFSET + 0x400000;
6020 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
6021 +- swapper_pg_dir[pgd_index(temp)].pgd;
6022 +- }
6023 ++ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
6024 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
6025 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
6026 +
6027 + /*
6028 + * After the lock is released, the original page table is restored.
6029 + */
6030 + __flush_tlb_all();
6031 +
6032 +- gdt_descr.address = __pa(get_cpu_gdt_table(0));
6033 ++ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
6034 + gdt_descr.size = GDT_SIZE - 1;
6035 + load_gdt(&gdt_descr);
6036 + }
6037 +
6038 +-void efi_call_phys_epilog(void)
6039 ++void __init efi_call_phys_epilog(void)
6040 + {
6041 +- unsigned long cr4;
6042 + struct desc_ptr gdt_descr;
6043 +
6044 +- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
6045 ++ gdt_descr.address = get_cpu_gdt_table(0);
6046 + gdt_descr.size = GDT_SIZE - 1;
6047 + load_gdt(&gdt_descr);
6048 +
6049 +- cr4 = read_cr4_safe();
6050 +-
6051 +- if (cr4 & X86_CR4_PAE) {
6052 +- swapper_pg_dir[pgd_index(0)].pgd =
6053 +- efi_bak_pg_dir_pointer[0].pgd;
6054 +- } else {
6055 +- swapper_pg_dir[pgd_index(0)].pgd =
6056 +- efi_bak_pg_dir_pointer[0].pgd;
6057 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
6058 +- efi_bak_pg_dir_pointer[1].pgd;
6059 +- }
6060 ++ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
6061 +
6062 + /*
6063 + * After the lock is released, the original page table is restored.
6064 +diff -urNp linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S
6065 +--- linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-07 12:55:34.000000000 -0500
6066 ++++ linux-2.6.27.10/arch/x86/kernel/efi_stub_32.S 2008-11-18 03:38:44.000000000 -0500
6067 +@@ -6,6 +6,7 @@
6068 + */
6069 +
6070 + #include <linux/linkage.h>
6071 ++#include <linux/init.h>
6072 + #include <asm/page.h>
6073 +
6074 + /*
6075 +@@ -20,7 +21,7 @@
6076 + * service functions will comply with gcc calling convention, too.
6077 + */
6078 +
6079 +-.text
6080 ++__INIT
6081 + ENTRY(efi_call_phys)
6082 + /*
6083 + * 0. The function can only be called in Linux kernel. So CS has been
6084 +@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
6085 + * The mapping of lower virtual memory has been created in prelog and
6086 + * epilog.
6087 + */
6088 +- movl $1f, %edx
6089 +- subl $__PAGE_OFFSET, %edx
6090 +- jmp *%edx
6091 ++ jmp 1f-__PAGE_OFFSET
6092 + 1:
6093 +
6094 + /*
6095 +@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
6096 + * parameter 2, ..., param n. To make things easy, we save the return
6097 + * address of efi_call_phys in a global variable.
6098 + */
6099 +- popl %edx
6100 +- movl %edx, saved_return_addr
6101 +- /* get the function pointer into ECX*/
6102 +- popl %ecx
6103 +- movl %ecx, efi_rt_function_ptr
6104 +- movl $2f, %edx
6105 +- subl $__PAGE_OFFSET, %edx
6106 +- pushl %edx
6107 ++ popl (saved_return_addr)
6108 ++ popl (efi_rt_function_ptr)
6109 +
6110 + /*
6111 + * 3. Clear PG bit in %CR0.
6112 +@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
6113 + /*
6114 + * 5. Call the physical function.
6115 + */
6116 +- jmp *%ecx
6117 ++ call *(efi_rt_function_ptr-__PAGE_OFFSET)
6118 +
6119 +-2:
6120 + /*
6121 + * 6. After EFI runtime service returns, control will return to
6122 + * following instruction. We'd better readjust stack pointer first.
6123 +@@ -88,34 +80,27 @@ ENTRY(efi_call_phys)
6124 + movl %cr0, %edx
6125 + orl $0x80000000, %edx
6126 + movl %edx, %cr0
6127 +- jmp 1f
6128 +-1:
6129 ++
6130 + /*
6131 + * 8. Now restore the virtual mode from flat mode by
6132 + * adding EIP with PAGE_OFFSET.
6133 + */
6134 +- movl $1f, %edx
6135 +- jmp *%edx
6136 ++ jmp 1f+__PAGE_OFFSET
6137 + 1:
6138 +
6139 + /*
6140 + * 9. Balance the stack. And because EAX contain the return value,
6141 + * we'd better not clobber it.
6142 + */
6143 +- leal efi_rt_function_ptr, %edx
6144 +- movl (%edx), %ecx
6145 +- pushl %ecx
6146 ++ pushl (efi_rt_function_ptr)
6147 +
6148 + /*
6149 +- * 10. Push the saved return address onto the stack and return.
6150 ++ * 10. Return to the saved return address.
6151 + */
6152 +- leal saved_return_addr, %edx
6153 +- movl (%edx), %ecx
6154 +- pushl %ecx
6155 +- ret
6156 ++ jmpl *(saved_return_addr)
6157 + .previous
6158 +
6159 +-.data
6160 ++__INITDATA
6161 + saved_return_addr:
6162 + .long 0
6163 + efi_rt_function_ptr:
6164 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_32.S linux-2.6.27.10/arch/x86/kernel/entry_32.S
6165 +--- linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-07 12:55:34.000000000 -0500
6166 ++++ linux-2.6.27.10/arch/x86/kernel/entry_32.S 2008-11-18 03:38:44.000000000 -0500
6167 +@@ -101,7 +101,7 @@
6168 + #define resume_userspace_sig resume_userspace
6169 + #endif
6170 +
6171 +-#define SAVE_ALL \
6172 ++#define __SAVE_ALL(_DS) \
6173 + cld; \
6174 + pushl %fs; \
6175 + CFI_ADJUST_CFA_OFFSET 4;\
6176 +@@ -133,12 +133,26 @@
6177 + pushl %ebx; \
6178 + CFI_ADJUST_CFA_OFFSET 4;\
6179 + CFI_REL_OFFSET ebx, 0;\
6180 +- movl $(__USER_DS), %edx; \
6181 ++ movl $(_DS), %edx; \
6182 + movl %edx, %ds; \
6183 + movl %edx, %es; \
6184 + movl $(__KERNEL_PERCPU), %edx; \
6185 + movl %edx, %fs
6186 +
6187 ++#ifdef CONFIG_PAX_KERNEXEC
6188 ++#define SAVE_ALL \
6189 ++ __SAVE_ALL(__KERNEL_DS); \
6190 ++ GET_CR0_INTO_EDX; \
6191 ++ movl %edx, %esi; \
6192 ++ orl $X86_CR0_WP, %edx; \
6193 ++ xorl %edx, %esi; \
6194 ++ SET_CR0_FROM_EDX
6195 ++#elif defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
6196 ++#define SAVE_ALL __SAVE_ALL(__KERNEL_DS)
6197 ++#else
6198 ++#define SAVE_ALL __SAVE_ALL(__USER_DS)
6199 ++#endif
6200 ++
6201 + #define RESTORE_INT_REGS \
6202 + popl %ebx; \
6203 + CFI_ADJUST_CFA_OFFSET -4;\
6204 +@@ -229,6 +243,11 @@ ENTRY(ret_from_fork)
6205 + CFI_ADJUST_CFA_OFFSET 4
6206 + popfl
6207 + CFI_ADJUST_CFA_OFFSET -4
6208 ++
6209 ++#ifdef CONFIG_PAX_KERNEXEC
6210 ++ xorl %esi, %esi
6211 ++#endif
6212 ++
6213 + jmp syscall_exit
6214 + CFI_ENDPROC
6215 + END(ret_from_fork)
6216 +@@ -252,7 +271,17 @@ check_userspace:
6217 + movb PT_CS(%esp), %al
6218 + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
6219 + cmpl $USER_RPL, %eax
6220 ++
6221 ++#ifdef CONFIG_PAX_KERNEXEC
6222 ++ jae resume_userspace
6223 ++
6224 ++ GET_CR0_INTO_EDX
6225 ++ xorl %esi, %edx
6226 ++ SET_CR0_FROM_EDX
6227 ++ jmp resume_kernel
6228 ++#else
6229 + jb resume_kernel # not returning to v8086 or userspace
6230 ++#endif
6231 +
6232 + ENTRY(resume_userspace)
6233 + LOCKDEP_SYS_EXIT
6234 +@@ -314,10 +343,9 @@ sysenter_past_esp:
6235 + /*CFI_REL_OFFSET cs, 0*/
6236 + /*
6237 + * Push current_thread_info()->sysenter_return to the stack.
6238 +- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
6239 +- * pushed above; +8 corresponds to copy_thread's esp0 setting.
6240 + */
6241 +- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
6242 ++ GET_THREAD_INFO(%ebp)
6243 ++ pushl TI_sysenter_return(%ebp)
6244 + CFI_ADJUST_CFA_OFFSET 4
6245 + CFI_REL_OFFSET eip, 0
6246 +
6247 +@@ -330,9 +358,17 @@ sysenter_past_esp:
6248 + * Load the potential sixth argument from user stack.
6249 + * Careful about security.
6250 + */
6251 ++ movl PT_OLDESP(%esp),%ebp
6252 ++
6253 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
6254 ++ mov PT_OLDSS(%esp),%ds
6255 ++1: movl %ds:(%ebp),%ebp
6256 ++#else
6257 + cmpl $__PAGE_OFFSET-3,%ebp
6258 + jae syscall_fault
6259 + 1: movl (%ebp),%ebp
6260 ++#endif
6261 ++
6262 + movl %ebp,PT_EBP(%esp)
6263 + .section __ex_table,"a"
6264 + .align 4
6265 +@@ -356,12 +392,23 @@ sysenter_do_call:
6266 + testw $_TIF_ALLWORK_MASK, %cx
6267 + jne sysexit_audit
6268 + sysenter_exit:
6269 ++
6270 ++#ifdef CONFIG_PAX_RANDKSTACK
6271 ++ pushl %eax
6272 ++ CFI_ADJUST_CFA_OFFSET 4
6273 ++ call pax_randomize_kstack
6274 ++ popl %eax
6275 ++ CFI_ADJUST_CFA_OFFSET -4
6276 ++#endif
6277 ++
6278 + /* if something modifies registers it must also disable sysexit */
6279 + movl PT_EIP(%esp), %edx
6280 + movl PT_OLDESP(%esp), %ecx
6281 + xorl %ebp,%ebp
6282 + TRACE_IRQS_ON
6283 + 1: mov PT_FS(%esp), %fs
6284 ++2: mov PT_DS(%esp), %ds
6285 ++3: mov PT_ES(%esp), %es
6286 + ENABLE_INTERRUPTS_SYSEXIT
6287 +
6288 + #ifdef CONFIG_AUDITSYSCALL
6289 +@@ -404,11 +451,17 @@ sysexit_audit:
6290 +
6291 + CFI_ENDPROC
6292 + .pushsection .fixup,"ax"
6293 +-2: movl $0,PT_FS(%esp)
6294 ++4: movl $0,PT_FS(%esp)
6295 ++ jmp 1b
6296 ++5: movl $0,PT_DS(%esp)
6297 ++ jmp 1b
6298 ++6: movl $0,PT_ES(%esp)
6299 + jmp 1b
6300 + .section __ex_table,"a"
6301 + .align 4
6302 +- .long 1b,2b
6303 ++ .long 1b,4b
6304 ++ .long 2b,5b
6305 ++ .long 3b,6b
6306 + .popsection
6307 + ENDPROC(ia32_sysenter_target)
6308 +
6309 +@@ -438,6 +491,10 @@ syscall_exit:
6310 + testw $_TIF_ALLWORK_MASK, %cx # current->work
6311 + jne syscall_exit_work
6312 +
6313 ++#ifdef CONFIG_PAX_RANDKSTACK
6314 ++ call pax_randomize_kstack
6315 ++#endif
6316 ++
6317 + restore_all:
6318 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
6319 + # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
6320 +@@ -531,25 +588,19 @@ work_resched:
6321 +
6322 + work_notifysig: # deal with pending signals and
6323 + # notify-resume requests
6324 ++ movl %esp, %eax
6325 + #ifdef CONFIG_VM86
6326 + testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
6327 +- movl %esp, %eax
6328 +- jne work_notifysig_v86 # returning to kernel-space or
6329 ++ jz 1f # returning to kernel-space or
6330 + # vm86-space
6331 +- xorl %edx, %edx
6332 +- call do_notify_resume
6333 +- jmp resume_userspace_sig
6334 +
6335 +- ALIGN
6336 +-work_notifysig_v86:
6337 + pushl %ecx # save ti_flags for do_notify_resume
6338 + CFI_ADJUST_CFA_OFFSET 4
6339 + call save_v86_state # %eax contains pt_regs pointer
6340 + popl %ecx
6341 + CFI_ADJUST_CFA_OFFSET -4
6342 + movl %eax, %esp
6343 +-#else
6344 +- movl %esp, %eax
6345 ++1:
6346 + #endif
6347 + xorl %edx, %edx
6348 + call do_notify_resume
6349 +@@ -595,17 +646,24 @@ syscall_badsys:
6350 + END(syscall_badsys)
6351 + CFI_ENDPROC
6352 +
6353 +-#define FIXUP_ESPFIX_STACK \
6354 +- /* since we are on a wrong stack, we cant make it a C code :( */ \
6355 +- PER_CPU(gdt_page, %ebx); \
6356 +- GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
6357 +- addl %esp, %eax; \
6358 +- pushl $__KERNEL_DS; \
6359 +- CFI_ADJUST_CFA_OFFSET 4; \
6360 +- pushl %eax; \
6361 +- CFI_ADJUST_CFA_OFFSET 4; \
6362 +- lss (%esp), %esp; \
6363 ++.macro FIXUP_ESPFIX_STACK
6364 ++ /* since we are on a wrong stack, we cant make it a C code :( */
6365 ++#ifdef CONFIG_SMP
6366 ++ movl PER_CPU_VAR(cpu_number), %ebx;
6367 ++ shll $PAGE_SHIFT_asm, %ebx;
6368 ++ addl $cpu_gdt_table, %ebx;
6369 ++#else
6370 ++ movl $cpu_gdt_table, %ebx;
6371 ++#endif
6372 ++ GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah);
6373 ++ addl %esp, %eax;
6374 ++ pushl $__KERNEL_DS;
6375 ++ CFI_ADJUST_CFA_OFFSET 4;
6376 ++ pushl %eax;
6377 ++ CFI_ADJUST_CFA_OFFSET 4;
6378 ++ lss (%esp), %esp;
6379 + CFI_ADJUST_CFA_OFFSET -8;
6380 ++.endm
6381 + #define UNWIND_ESPFIX_STACK \
6382 + movl %ss, %eax; \
6383 + /* see if on espfix stack */ \
6384 +@@ -622,7 +680,7 @@ END(syscall_badsys)
6385 + * Build the entry stubs and pointer table with
6386 + * some assembler magic.
6387 + */
6388 +-.section .rodata,"a"
6389 ++.section .rodata,"a",@progbits
6390 + ENTRY(interrupt)
6391 + .text
6392 +
6393 +@@ -722,12 +780,21 @@ error_code:
6394 + popl %ecx
6395 + CFI_ADJUST_CFA_OFFSET -4
6396 + /*CFI_REGISTER es, ecx*/
6397 ++
6398 ++#ifdef CONFIG_PAX_KERNEXEC
6399 ++ GET_CR0_INTO_EDX
6400 ++ movl %edx, %esi
6401 ++ orl $X86_CR0_WP, %edx
6402 ++ xorl %edx, %esi
6403 ++ SET_CR0_FROM_EDX
6404 ++#endif
6405 ++
6406 + movl PT_FS(%esp), %edi # get the function address
6407 + movl PT_ORIG_EAX(%esp), %edx # get the error code
6408 + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
6409 + mov %ecx, PT_FS(%esp)
6410 + /*CFI_REL_OFFSET fs, ES*/
6411 +- movl $(__USER_DS), %ecx
6412 ++ movl $(__KERNEL_DS), %ecx
6413 + movl %ecx, %ds
6414 + movl %ecx, %es
6415 + movl %esp,%eax # pt_regs pointer
6416 +@@ -861,6 +928,13 @@ nmi_stack_correct:
6417 + xorl %edx,%edx # zero error code
6418 + movl %esp,%eax # pt_regs pointer
6419 + call do_nmi
6420 ++
6421 ++#ifdef CONFIG_PAX_KERNEXEC
6422 ++ GET_CR0_INTO_EDX
6423 ++ xorl %esi, %edx
6424 ++ SET_CR0_FROM_EDX
6425 ++#endif
6426 ++
6427 + jmp restore_nocheck_notrace
6428 + CFI_ENDPROC
6429 +
6430 +@@ -901,6 +975,13 @@ nmi_espfix_stack:
6431 + FIXUP_ESPFIX_STACK # %eax == %esp
6432 + xorl %edx,%edx # zero error code
6433 + call do_nmi
6434 ++
6435 ++#ifdef CONFIG_PAX_KERNEXEC
6436 ++ GET_CR0_INTO_EDX
6437 ++ xorl %esi, %edx
6438 ++ SET_CR0_FROM_EDX
6439 ++#endif
6440 ++
6441 + RESTORE_REGS
6442 + lss 12+4(%esp), %esp # back to espfix stack
6443 + CFI_ADJUST_CFA_OFFSET -24
6444 +@@ -1226,7 +1307,6 @@ END(mcount)
6445 + #endif /* CONFIG_DYNAMIC_FTRACE */
6446 + #endif /* CONFIG_FTRACE */
6447 +
6448 +-.section .rodata,"a"
6449 + #include "syscall_table_32.S"
6450 +
6451 + syscall_table_size=(.-sys_call_table)
6452 +diff -urNp linux-2.6.27.10/arch/x86/kernel/entry_64.S linux-2.6.27.10/arch/x86/kernel/entry_64.S
6453 +--- linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-07 12:55:34.000000000 -0500
6454 ++++ linux-2.6.27.10/arch/x86/kernel/entry_64.S 2008-11-18 03:38:44.000000000 -0500
6455 +@@ -930,17 +930,18 @@ END(spurious_interrupt)
6456 + xorl %ebx,%ebx
6457 + 1:
6458 + .if \ist
6459 +- movq %gs:pda_data_offset, %rbp
6460 ++ imul $TSS_size, %gs:pda_cpunumber, %ebp
6461 ++ lea init_tss(%rbp), %rbp
6462 + .endif
6463 + movq %rsp,%rdi
6464 + movq ORIG_RAX(%rsp),%rsi
6465 + movq $-1,ORIG_RAX(%rsp)
6466 + .if \ist
6467 +- subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
6468 ++ subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
6469 + .endif
6470 + call \sym
6471 + .if \ist
6472 +- addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
6473 ++ addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
6474 + .endif
6475 + DISABLE_INTERRUPTS(CLBR_NONE)
6476 + .if \irqtrace
6477 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ftrace.c linux-2.6.27.10/arch/x86/kernel/ftrace.c
6478 +--- linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-11-07 12:55:34.000000000 -0500
6479 ++++ linux-2.6.27.10/arch/x86/kernel/ftrace.c 2008-12-10 22:28:27.000000000 -0500
6480 +@@ -103,9 +103,9 @@ notrace int ftrace_update_ftrace_func(ft
6481 + unsigned char old[MCOUNT_INSN_SIZE], *new;
6482 + int ret;
6483 +
6484 +- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
6485 ++ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
6486 + new = ftrace_call_replace(ip, (unsigned long)func);
6487 +- ret = ftrace_modify_code(ip, old, new);
6488 ++ ret = ftrace_modify_code(ktla_ktva(ip), old, new);
6489 +
6490 + return ret;
6491 + }
6492 +@@ -120,9 +120,9 @@ notrace int ftrace_mcount_set(unsigned l
6493 + * Replace the mcount stub with a pointer to the
6494 + * ip recorder function.
6495 + */
6496 +- memcpy(old, &mcount_call, MCOUNT_INSN_SIZE);
6497 ++ memcpy(old, ktla_ktva(mcount_call), MCOUNT_INSN_SIZE);
6498 + new = ftrace_call_replace(ip, *addr);
6499 +- *addr = ftrace_modify_code(ip, old, new);
6500 ++ *addr = ftrace_modify_code(ktla_ktva(ip), old, new);
6501 +
6502 + return 0;
6503 + }
6504 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head32.c linux-2.6.27.10/arch/x86/kernel/head32.c
6505 +--- linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-07 12:55:34.000000000 -0500
6506 ++++ linux-2.6.27.10/arch/x86/kernel/head32.c 2008-11-18 03:38:44.000000000 -0500
6507 +@@ -12,10 +12,11 @@
6508 + #include <asm/sections.h>
6509 + #include <asm/e820.h>
6510 + #include <asm/bios_ebda.h>
6511 ++#include <asm/boot.h>
6512 +
6513 + void __init i386_start_kernel(void)
6514 + {
6515 +- reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
6516 ++ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&_end), "TEXT DATA BSS");
6517 +
6518 + #ifdef CONFIG_BLK_DEV_INITRD
6519 + /* Reserve INITRD */
6520 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_32.S linux-2.6.27.10/arch/x86/kernel/head_32.S
6521 +--- linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-07 12:55:34.000000000 -0500
6522 ++++ linux-2.6.27.10/arch/x86/kernel/head_32.S 2008-11-18 03:38:44.000000000 -0500
6523 +@@ -19,6 +19,7 @@
6524 + #include <asm/asm-offsets.h>
6525 + #include <asm/setup.h>
6526 + #include <asm/processor-flags.h>
6527 ++#include <asm/msr-index.h>
6528 +
6529 + /* Physical address */
6530 + #define pa(X) ((X) - __PAGE_OFFSET)
6531 +@@ -64,17 +65,22 @@ LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
6532 + LOW_PAGES = LOW_PAGES + 0x1000000
6533 + #endif
6534 +
6535 +-#if PTRS_PER_PMD > 1
6536 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
6537 +-#else
6538 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
6539 +-#endif
6540 ++PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PTE)
6541 + BOOTBITMAP_SIZE = LOW_PAGES / 8
6542 + ALLOCATOR_SLOP = 4
6543 +
6544 + INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
6545 +
6546 + /*
6547 ++ * Real beginning of normal "text" segment
6548 ++ */
6549 ++ENTRY(stext)
6550 ++ENTRY(_stext)
6551 ++
6552 ++.section .text.startup,"ax",@progbits
6553 ++ ljmp $(__BOOT_CS),$phys_startup_32
6554 ++
6555 ++/*
6556 + * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
6557 + * %esi points to the real-mode code as a 32-bit pointer.
6558 + * CS and DS must be 4 GB flat segments, but we don't depend on
6559 +@@ -82,6 +88,12 @@ INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE +
6560 + * can.
6561 + */
6562 + .section .text.head,"ax",@progbits
6563 ++
6564 ++#ifdef CONFIG_PAX_KERNEXEC
6565 ++/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
6566 ++.fill 4096,1,0xcc
6567 ++#endif
6568 ++
6569 + ENTRY(startup_32)
6570 + /* test KEEP_SEGMENTS flag to see if the bootloader is asking
6571 + us to not reload segments */
6572 +@@ -99,6 +111,56 @@ ENTRY(startup_32)
6573 + movl %eax,%gs
6574 + 2:
6575 +
6576 ++ movl $pa(cpu_gdt_table),%edi
6577 ++ movl $__per_cpu_start,%eax
6578 ++ movw %ax,__KERNEL_PERCPU + 2(%edi)
6579 ++ rorl $16,%eax
6580 ++ movb %al,__KERNEL_PERCPU + 4(%edi)
6581 ++ movb %ah,__KERNEL_PERCPU + 7(%edi)
6582 ++ movl $__per_cpu_end + PERCPU_MODULE_RESERVE - 1,%eax
6583 ++ subl $__per_cpu_start,%eax
6584 ++ movw %ax,__KERNEL_PERCPU + 0(%edi)
6585 ++
6586 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
6587 ++ /* check for VMware */
6588 ++ movl $0x564d5868,%eax
6589 ++ xorl %ebx,%ebx
6590 ++ movl $0xa,%ecx
6591 ++ movl $0x5658,%edx
6592 ++ in (%dx),%eax
6593 ++ cmpl $0x564d5868,%ebx
6594 ++ jz 2f
6595 ++
6596 ++ movl $NR_CPUS,%ecx
6597 ++ movl $pa(cpu_gdt_table),%edi
6598 ++1:
6599 ++ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
6600 ++ addl $PAGE_SIZE_asm,%edi
6601 ++ loop 1b
6602 ++2:
6603 ++#endif
6604 ++
6605 ++#ifdef CONFIG_PAX_KERNEXEC
6606 ++ movl $pa(boot_gdt),%edi
6607 ++ movl $KERNEL_TEXT_OFFSET,%eax
6608 ++ movw %ax,__BOOT_CS + 2(%edi)
6609 ++ rorl $16,%eax
6610 ++ movb %al,__BOOT_CS + 4(%edi)
6611 ++ movb %ah,__BOOT_CS + 7(%edi)
6612 ++ rorl $16,%eax
6613 ++
6614 ++ movl $NR_CPUS,%ecx
6615 ++ movl $pa(cpu_gdt_table),%edi
6616 ++1:
6617 ++ movw %ax,__KERNEL_CS + 2(%edi)
6618 ++ rorl $16,%eax
6619 ++ movb %al,__KERNEL_CS + 4(%edi)
6620 ++ movb %ah,__KERNEL_CS + 7(%edi)
6621 ++ rorl $16,%eax
6622 ++ addl $PAGE_SIZE_asm,%edi
6623 ++ loop 1b
6624 ++#endif
6625 ++
6626 + /*
6627 + * Clear BSS first so that there are no surprises...
6628 + */
6629 +@@ -142,9 +204,7 @@ ENTRY(startup_32)
6630 + cmpl $num_subarch_entries, %eax
6631 + jae bad_subarch
6632 +
6633 +- movl pa(subarch_entries)(,%eax,4), %eax
6634 +- subl $__PAGE_OFFSET, %eax
6635 +- jmp *%eax
6636 ++ jmp *pa(subarch_entries)(,%eax,4)
6637 +
6638 + bad_subarch:
6639 + WEAK(lguest_entry)
6640 +@@ -156,9 +216,9 @@ WEAK(xen_entry)
6641 + __INITDATA
6642 +
6643 + subarch_entries:
6644 +- .long default_entry /* normal x86/PC */
6645 +- .long lguest_entry /* lguest hypervisor */
6646 +- .long xen_entry /* Xen hypervisor */
6647 ++ .long pa(default_entry) /* normal x86/PC */
6648 ++ .long pa(lguest_entry) /* lguest hypervisor */
6649 ++ .long pa(xen_entry) /* Xen hypervisor */
6650 + num_subarch_entries = (. - subarch_entries) / 4
6651 + .previous
6652 + #endif /* CONFIG_PARAVIRT */
6653 +@@ -172,7 +232,7 @@ num_subarch_entries = (. - subarch_entri
6654 + *
6655 + * Note that the stack is not yet set up!
6656 + */
6657 +-#define PTE_ATTR 0x007 /* PRESENT+RW+USER */
6658 ++#define PTE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
6659 + #define PDE_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
6660 + #define PGD_ATTR 0x001 /* PRESENT (no other attributes) */
6661 +
6662 +@@ -224,8 +284,7 @@ default_entry:
6663 + movl %eax, pa(max_pfn_mapped)
6664 +
6665 + /* Do early initialization of the fixmap area */
6666 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
6667 +- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
6668 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
6669 + #else /* Not PAE */
6670 +
6671 + page_pde_offset = (__PAGE_OFFSET >> 20);
6672 +@@ -257,8 +316,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
6673 + movl %eax, pa(max_pfn_mapped)
6674 +
6675 + /* Do early initialization of the fixmap area */
6676 +- movl $pa(swapper_pg_fixmap)+PDE_ATTR,%eax
6677 +- movl %eax,pa(swapper_pg_dir+0xffc)
6678 ++ movl $pa(swapper_pg_fixmap)+PDE_ATTR,pa(swapper_pg_dir+0xffc)
6679 + #endif
6680 + jmp 3f
6681 + /*
6682 +@@ -322,13 +380,16 @@ ENTRY(startup_32_smp)
6683 + jnc 6f
6684 +
6685 + /* Setup EFER (Extended Feature Enable Register) */
6686 +- movl $0xc0000080, %ecx
6687 ++ movl $MSR_EFER, %ecx
6688 + rdmsr
6689 +
6690 + btsl $11, %eax
6691 + /* Make changes effective */
6692 + wrmsr
6693 +
6694 ++ btsl $63-32,pa(__supported_pte_mask+4)
6695 ++ movl $1,pa(nx_enabled)
6696 ++
6697 + 6:
6698 +
6699 + /*
6700 +@@ -354,9 +415,7 @@ ENTRY(startup_32_smp)
6701 +
6702 + #ifdef CONFIG_SMP
6703 + cmpb $0, ready
6704 +- jz 1f /* Initial CPU cleans BSS */
6705 +- jmp checkCPUtype
6706 +-1:
6707 ++ jnz checkCPUtype /* Initial CPU cleans BSS */
6708 + #endif /* CONFIG_SMP */
6709 +
6710 + /*
6711 +@@ -433,12 +492,12 @@ is386: movl $2,%ecx # set MP
6712 + ljmp $(__KERNEL_CS),$1f
6713 + 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
6714 + movl %eax,%ss # after changing gdt.
6715 +- movl %eax,%fs # gets reset once there's real percpu
6716 +-
6717 +- movl $(__USER_DS),%eax # DS/ES contains default USER segment
6718 + movl %eax,%ds
6719 + movl %eax,%es
6720 +
6721 ++ movl $(__KERNEL_PERCPU), %eax
6722 ++ movl %eax,%fs # set this cpu's percpu
6723 ++
6724 + xorl %eax,%eax # Clear GS and LDT
6725 + movl %eax,%gs
6726 + lldt %ax
6727 +@@ -448,12 +507,6 @@ is386: movl $2,%ecx # set MP
6728 + #ifdef CONFIG_SMP
6729 + movb ready, %cl
6730 + movb $1, ready
6731 +- cmpb $0,%cl # the first CPU calls start_kernel
6732 +- je 1f
6733 +- movl $(__KERNEL_PERCPU), %eax
6734 +- movl %eax,%fs # set this cpu's percpu
6735 +- movl (stack_start), %esp
6736 +-1:
6737 + #endif /* CONFIG_SMP */
6738 + jmp *(initial_code)
6739 +
6740 +@@ -539,15 +592,15 @@ early_page_fault:
6741 + jmp early_fault
6742 +
6743 + early_fault:
6744 +- cld
6745 + #ifdef CONFIG_PRINTK
6746 ++ cmpl $2,%ss:early_recursion_flag
6747 ++ je hlt_loop
6748 ++ incl %ss:early_recursion_flag
6749 ++ cld
6750 + pusha
6751 + movl $(__KERNEL_DS),%eax
6752 + movl %eax,%ds
6753 + movl %eax,%es
6754 +- cmpl $2,early_recursion_flag
6755 +- je hlt_loop
6756 +- incl early_recursion_flag
6757 + movl %cr2,%eax
6758 + pushl %eax
6759 + pushl %edx /* trapno */
6760 +@@ -557,8 +610,8 @@ early_fault:
6761 + #else
6762 + call printk
6763 + #endif
6764 +-#endif
6765 + call dump_stack
6766 ++#endif
6767 + hlt_loop:
6768 + hlt
6769 + jmp hlt_loop
6770 +@@ -566,8 +619,11 @@ hlt_loop:
6771 + /* This is the default interrupt "handler" :-) */
6772 + ALIGN
6773 + ignore_int:
6774 +- cld
6775 + #ifdef CONFIG_PRINTK
6776 ++ cmpl $2,%ss:early_recursion_flag
6777 ++ je hlt_loop
6778 ++ incl %ss:early_recursion_flag
6779 ++ cld
6780 + pushl %eax
6781 + pushl %ecx
6782 + pushl %edx
6783 +@@ -576,9 +632,6 @@ ignore_int:
6784 + movl $(__KERNEL_DS),%eax
6785 + movl %eax,%ds
6786 + movl %eax,%es
6787 +- cmpl $2,early_recursion_flag
6788 +- je hlt_loop
6789 +- incl early_recursion_flag
6790 + pushl 16(%esp)
6791 + pushl 24(%esp)
6792 + pushl 32(%esp)
6793 +@@ -603,36 +656,41 @@ ignore_int:
6794 + ENTRY(initial_code)
6795 + .long i386_start_kernel
6796 +
6797 +-.section .text
6798 +-/*
6799 +- * Real beginning of normal "text" segment
6800 +- */
6801 +-ENTRY(stext)
6802 +-ENTRY(_stext)
6803 +-
6804 + /*
6805 + * BSS section
6806 + */
6807 +-.section ".bss.page_aligned","wa"
6808 +- .align PAGE_SIZE_asm
6809 + #ifdef CONFIG_X86_PAE
6810 ++.section .swapper_pg_pmd,"a",@progbits
6811 + swapper_pg_pmd:
6812 + .fill 1024*KPMDS,4,0
6813 + #else
6814 ++.section .swapper_pg_dir,"a",@progbits
6815 + ENTRY(swapper_pg_dir)
6816 + .fill 1024,4,0
6817 + #endif
6818 + swapper_pg_fixmap:
6819 + .fill 1024,4,0
6820 ++
6821 ++.section .empty_zero_page,"a",@progbits
6822 + ENTRY(empty_zero_page)
6823 + .fill 4096,1,0
6824 ++
6825 ++/*
6826 ++ * The IDT has to be page-aligned to simplify the Pentium
6827 ++ * F0 0F bug workaround.. We have a special link segment
6828 ++ * for this.
6829 ++ */
6830 ++.section .idt,"a",@progbits
6831 ++ENTRY(idt_table)
6832 ++ .fill 256,8,0
6833 ++
6834 + /*
6835 + * This starts the data section.
6836 + */
6837 ++.data
6838 ++
6839 + #ifdef CONFIG_X86_PAE
6840 +-.section ".data.page_aligned","wa"
6841 +- /* Page-aligned for the benefit of paravirt? */
6842 +- .align PAGE_SIZE_asm
6843 ++.section .swapper_pg_dir,"a",@progbits
6844 + ENTRY(swapper_pg_dir)
6845 + .long pa(swapper_pg_pmd+PGD_ATTR),0 /* low identity map */
6846 + # if KPMDS == 3
6847 +@@ -655,11 +713,12 @@ ENTRY(swapper_pg_dir)
6848 +
6849 + .data
6850 + ENTRY(stack_start)
6851 +- .long init_thread_union+THREAD_SIZE
6852 ++ .long init_thread_union+THREAD_SIZE-8
6853 + .long __BOOT_DS
6854 +
6855 + ready: .byte 0
6856 +
6857 ++.section .rodata,"a",@progbits
6858 + early_recursion_flag:
6859 + .long 0
6860 +
6861 +@@ -695,7 +754,7 @@ fault_msg:
6862 + .word 0 # 32 bit align gdt_desc.address
6863 + boot_gdt_descr:
6864 + .word __BOOT_DS+7
6865 +- .long boot_gdt - __PAGE_OFFSET
6866 ++ .long pa(boot_gdt)
6867 +
6868 + .word 0 # 32-bit align idt_desc.address
6869 + idt_descr:
6870 +@@ -706,7 +765,7 @@ idt_descr:
6871 + .word 0 # 32 bit align gdt_desc.address
6872 + ENTRY(early_gdt_descr)
6873 + .word GDT_ENTRIES*8-1
6874 +- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
6875 ++ .long cpu_gdt_table /* Overwritten for secondary CPUs */
6876 +
6877 + /*
6878 + * The boot_gdt must mirror the equivalent in setup.S and is
6879 +@@ -715,5 +774,59 @@ ENTRY(early_gdt_descr)
6880 + .align L1_CACHE_BYTES
6881 + ENTRY(boot_gdt)
6882 + .fill GDT_ENTRY_BOOT_CS,8,0
6883 +- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
6884 +- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
6885 ++ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
6886 ++ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
6887 ++
6888 ++ .align PAGE_SIZE_asm
6889 ++ENTRY(cpu_gdt_table)
6890 ++ .rept NR_CPUS
6891 ++ .quad 0x0000000000000000 /* NULL descriptor */
6892 ++ .quad 0x0000000000000000 /* 0x0b reserved */
6893 ++ .quad 0x0000000000000000 /* 0x13 reserved */
6894 ++ .quad 0x0000000000000000 /* 0x1b reserved */
6895 ++ .quad 0x0000000000000000 /* 0x20 unused */
6896 ++ .quad 0x0000000000000000 /* 0x28 unused */
6897 ++ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
6898 ++ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
6899 ++ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
6900 ++ .quad 0x0000000000000000 /* 0x4b reserved */
6901 ++ .quad 0x0000000000000000 /* 0x53 reserved */
6902 ++ .quad 0x0000000000000000 /* 0x5b reserved */
6903 ++
6904 ++ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
6905 ++ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
6906 ++ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
6907 ++ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
6908 ++
6909 ++ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
6910 ++ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
6911 ++
6912 ++ /*
6913 ++ * Segments used for calling PnP BIOS have byte granularity.
6914 ++ * The code segments and data segments have fixed 64k limits,
6915 ++ * the transfer segment sizes are set at run time.
6916 ++ */
6917 ++ .quad 0x00409b000000ffff /* 0x90 32-bit code */
6918 ++ .quad 0x00009b000000ffff /* 0x98 16-bit code */
6919 ++ .quad 0x000093000000ffff /* 0xa0 16-bit data */
6920 ++ .quad 0x0000930000000000 /* 0xa8 16-bit data */
6921 ++ .quad 0x0000930000000000 /* 0xb0 16-bit data */
6922 ++
6923 ++ /*
6924 ++ * The APM segments have byte granularity and their bases
6925 ++ * are set at run time. All have 64k limits.
6926 ++ */
6927 ++ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
6928 ++ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
6929 ++ .quad 0x004093000000ffff /* 0xc8 APM DS data */
6930 ++
6931 ++ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
6932 ++ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
6933 ++ .quad 0x0000000000000000 /* 0xe0 - PCIBIOS_CS */
6934 ++ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_DS */
6935 ++ .quad 0x0000000000000000 /* 0xf0 - unused */
6936 ++ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
6937 ++
6938 ++ /* Be sure this is zeroed to avoid false validations in Xen */
6939 ++ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
6940 ++ .endr
6941 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head64.c linux-2.6.27.10/arch/x86/kernel/head64.c
6942 +--- linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-07 12:55:34.000000000 -0500
6943 ++++ linux-2.6.27.10/arch/x86/kernel/head64.c 2008-11-18 03:38:44.000000000 -0500
6944 +@@ -93,6 +93,8 @@ void __init x86_64_start_kernel(char * r
6945 + /* clear bss before set_intr_gate with early_idt_handler */
6946 + clear_bss();
6947 +
6948 ++ x86_64_init_pda();
6949 ++
6950 + /* Make NULL pointers segfault */
6951 + zap_identity_mappings();
6952 +
6953 +@@ -110,8 +112,6 @@ void __init x86_64_start_kernel(char * r
6954 +
6955 + early_printk("Kernel alive\n");
6956 +
6957 +- x86_64_init_pda();
6958 +-
6959 + early_printk("Kernel really alive\n");
6960 +
6961 + x86_64_start_reservations(real_mode_data);
6962 +diff -urNp linux-2.6.27.10/arch/x86/kernel/head_64.S linux-2.6.27.10/arch/x86/kernel/head_64.S
6963 +--- linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-07 12:55:34.000000000 -0500
6964 ++++ linux-2.6.27.10/arch/x86/kernel/head_64.S 2008-11-18 03:38:44.000000000 -0500
6965 +@@ -38,6 +38,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
6966 + L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
6967 + L4_START_KERNEL = pgd_index(__START_KERNEL_map)
6968 + L3_START_KERNEL = pud_index(__START_KERNEL_map)
6969 ++L4_VMALLOC_START = pgd_index(VMALLOC_START)
6970 ++L3_VMALLOC_START = pud_index(VMALLOC_START)
6971 ++L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
6972 ++L3_VMEMMAP_START = pud_index(VMEMMAP_START)
6973 +
6974 + .text
6975 + .section .text.head
6976 +@@ -85,14 +89,17 @@ startup_64:
6977 + */
6978 + addq %rbp, init_level4_pgt + 0(%rip)
6979 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
6980 ++ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
6981 ++ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
6982 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
6983 +
6984 + addq %rbp, level3_ident_pgt + 0(%rip)
6985 +
6986 +- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
6987 +- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
6988 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
6989 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
6990 +
6991 + addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
6992 ++ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
6993 +
6994 + /* Add an Identity mapping if I am above 1G */
6995 + leaq _text(%rip), %rdi
6996 +@@ -187,6 +194,10 @@ ENTRY(secondary_startup_64)
6997 + btl $20,%edi /* No Execute supported? */
6998 + jnc 1f
6999 + btsl $_EFER_NX, %eax
7000 ++ leaq init_level4_pgt(%rip), %rdi
7001 ++ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
7002 ++ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
7003 ++ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
7004 + 1: wrmsr /* Make changes effective */
7005 +
7006 + /* Setup cr0 */
7007 +@@ -257,16 +268,16 @@ ENTRY(secondary_startup_64)
7008 + .align 8
7009 + ENTRY(initial_code)
7010 + .quad x86_64_start_kernel
7011 +- __FINITDATA
7012 +
7013 + ENTRY(stack_start)
7014 + .quad init_thread_union+THREAD_SIZE-8
7015 + .word 0
7016 ++ __FINITDATA
7017 +
7018 + bad_address:
7019 + jmp bad_address
7020 +
7021 +- .section ".init.text","ax"
7022 ++ __INIT
7023 + #ifdef CONFIG_EARLY_PRINTK
7024 + .globl early_idt_handlers
7025 + early_idt_handlers:
7026 +@@ -311,18 +322,23 @@ ENTRY(early_idt_handler)
7027 + #endif /* EARLY_PRINTK */
7028 + 1: hlt
7029 + jmp 1b
7030 ++ .previous
7031 +
7032 + #ifdef CONFIG_EARLY_PRINTK
7033 ++ __INITDATA
7034 + early_recursion_flag:
7035 + .long 0
7036 ++ .previous
7037 +
7038 ++ .section .rodata,"a",@progbits
7039 + early_idt_msg:
7040 + .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
7041 + early_idt_ripmsg:
7042 + .asciz "RIP %s\n"
7043 +-#endif /* CONFIG_EARLY_PRINTK */
7044 + .previous
7045 ++#endif /* CONFIG_EARLY_PRINTK */
7046 +
7047 ++ .section .rodata,"a",@progbits
7048 + .balign PAGE_SIZE
7049 +
7050 + #define NEXT_PAGE(name) \
7051 +@@ -347,6 +363,10 @@ NEXT_PAGE(init_level4_pgt)
7052 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
7053 + .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
7054 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
7055 ++ .org init_level4_pgt + L4_VMALLOC_START*8, 0
7056 ++ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
7057 ++ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
7058 ++ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
7059 + .org init_level4_pgt + L4_START_KERNEL*8, 0
7060 + /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
7061 + .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
7062 +@@ -355,6 +375,12 @@ NEXT_PAGE(level3_ident_pgt)
7063 + .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
7064 + .fill 511,8,0
7065 +
7066 ++NEXT_PAGE(level3_vmalloc_pgt)
7067 ++ .fill 512,8,0
7068 ++
7069 ++NEXT_PAGE(level3_vmemmap_pgt)
7070 ++ .fill 512,8,0
7071 ++
7072 + NEXT_PAGE(level3_kernel_pgt)
7073 + .fill L3_START_KERNEL,8,0
7074 + /* (2^48-(2*1024*1024*1024)-((2^39)*511))/(2^30) = 510 */
7075 +@@ -364,12 +390,16 @@ NEXT_PAGE(level3_kernel_pgt)
7076 + NEXT_PAGE(level2_fixmap_pgt)
7077 + .fill 506,8,0
7078 + .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
7079 +- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
7080 +- .fill 5,8,0
7081 ++ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
7082 ++ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
7083 ++ .fill 4,8,0
7084 +
7085 + NEXT_PAGE(level1_fixmap_pgt)
7086 + .fill 512,8,0
7087 +
7088 ++NEXT_PAGE(level1_vsyscall_pgt)
7089 ++ .fill 512,8,0
7090 ++
7091 + NEXT_PAGE(level2_ident_pgt)
7092 + /* Since I easily can, map the first 1G.
7093 + * Don't set NX because code runs from these pages.
7094 +@@ -396,19 +426,39 @@ NEXT_PAGE(level2_spare_pgt)
7095 + #undef PMDS
7096 + #undef NEXT_PAGE
7097 +
7098 +- .data
7099 ++ .align PAGE_SIZE
7100 ++ENTRY(cpu_gdt_table)
7101 ++ .rept NR_CPUS
7102 ++ .quad 0x0000000000000000 /* NULL descriptor */
7103 ++ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
7104 ++ .quad 0x00af9b000000ffff /* __KERNEL_CS */
7105 ++ .quad 0x00cf93000000ffff /* __KERNEL_DS */
7106 ++ .quad 0x00cffb000000ffff /* __USER32_CS */
7107 ++ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
7108 ++ .quad 0x00affb000000ffff /* __USER_CS */
7109 ++ .quad 0x0 /* unused */
7110 ++ .quad 0,0 /* TSS */
7111 ++ .quad 0,0 /* LDT */
7112 ++ .quad 0,0,0 /* three TLS descriptors */
7113 ++ .quad 0x0000f40000000000 /* node/CPU stored in limit */
7114 ++ /* asm/segment.h:GDT_ENTRIES must match this */
7115 ++
7116 ++ /* zero the remaining page */
7117 ++ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
7118 ++ .endr
7119 ++
7120 + .align 16
7121 + .globl early_gdt_descr
7122 + early_gdt_descr:
7123 + .word GDT_ENTRIES*8-1
7124 +- .quad per_cpu__gdt_page
7125 ++ .quad cpu_gdt_table
7126 +
7127 + ENTRY(phys_base)
7128 + /* This must match the first entry in level2_kernel_pgt */
7129 + .quad 0x0000000000000000
7130 +
7131 + #include "../../x86/xen/xen-head.S"
7132 +-
7133 ++
7134 + .section .bss, "aw", @nobits
7135 + .align L1_CACHE_BYTES
7136 + ENTRY(idt_table)
7137 +diff -urNp linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c
7138 +--- linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-07 12:55:34.000000000 -0500
7139 ++++ linux-2.6.27.10/arch/x86/kernel/i386_ksyms_32.c 2008-11-18 03:38:44.000000000 -0500
7140 +@@ -10,8 +10,12 @@
7141 + EXPORT_SYMBOL(mcount);
7142 + #endif
7143 +
7144 ++EXPORT_SYMBOL_GPL(cpu_gdt_table);
7145 ++
7146 + /* Networking helper routines. */
7147 + EXPORT_SYMBOL(csum_partial_copy_generic);
7148 ++EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
7149 ++EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
7150 +
7151 + EXPORT_SYMBOL(__get_user_1);
7152 + EXPORT_SYMBOL(__get_user_2);
7153 +@@ -26,3 +30,7 @@ EXPORT_SYMBOL(strstr);
7154 +
7155 + EXPORT_SYMBOL(csum_partial);
7156 + EXPORT_SYMBOL(empty_zero_page);
7157 ++
7158 ++#ifdef CONFIG_PAX_KERNEXEC
7159 ++EXPORT_SYMBOL(KERNEL_TEXT_OFFSET);
7160 ++#endif
7161 +diff -urNp linux-2.6.27.10/arch/x86/kernel/init_task.c linux-2.6.27.10/arch/x86/kernel/init_task.c
7162 +--- linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-07 12:55:34.000000000 -0500
7163 ++++ linux-2.6.27.10/arch/x86/kernel/init_task.c 2008-11-18 03:38:44.000000000 -0500
7164 +@@ -42,5 +42,5 @@ EXPORT_SYMBOL(init_task);
7165 + * section. Since TSS's are completely CPU-local, we want them
7166 + * on exact cacheline boundaries, to eliminate cacheline ping-pong.
7167 + */
7168 +-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
7169 +-
7170 ++struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
7171 ++EXPORT_SYMBOL(init_tss);
7172 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ioport.c linux-2.6.27.10/arch/x86/kernel/ioport.c
7173 +--- linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-07 12:55:34.000000000 -0500
7174 ++++ linux-2.6.27.10/arch/x86/kernel/ioport.c 2008-11-18 03:38:44.000000000 -0500
7175 +@@ -14,6 +14,7 @@
7176 + #include <linux/slab.h>
7177 + #include <linux/thread_info.h>
7178 + #include <linux/syscalls.h>
7179 ++#include <linux/grsecurity.h>
7180 +
7181 + /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
7182 + static void set_bitmap(unsigned long *bitmap, unsigned int base,
7183 +@@ -40,6 +41,12 @@ asmlinkage long sys_ioperm(unsigned long
7184 +
7185 + if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
7186 + return -EINVAL;
7187 ++#ifdef CONFIG_GRKERNSEC_IO
7188 ++ if (turn_on) {
7189 ++ gr_handle_ioperm();
7190 ++ return -EPERM;
7191 ++ }
7192 ++#endif
7193 + if (turn_on && !capable(CAP_SYS_RAWIO))
7194 + return -EPERM;
7195 +
7196 +@@ -66,7 +73,7 @@ asmlinkage long sys_ioperm(unsigned long
7197 + * because the ->io_bitmap_max value must match the bitmap
7198 + * contents:
7199 + */
7200 +- tss = &per_cpu(init_tss, get_cpu());
7201 ++ tss = init_tss + get_cpu();
7202 +
7203 + set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
7204 +
7205 +@@ -121,8 +128,13 @@ static int do_iopl(unsigned int level, s
7206 + return -EINVAL;
7207 + /* Trying to gain more privileges? */
7208 + if (level > old) {
7209 ++#ifdef CONFIG_GRKERNSEC_IO
7210 ++ gr_handle_iopl();
7211 ++ return -EPERM;
7212 ++#else
7213 + if (!capable(CAP_SYS_RAWIO))
7214 + return -EPERM;
7215 ++#endif
7216 + }
7217 + regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
7218 +
7219 +diff -urNp linux-2.6.27.10/arch/x86/kernel/irq_32.c linux-2.6.27.10/arch/x86/kernel/irq_32.c
7220 +--- linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-07 12:55:34.000000000 -0500
7221 ++++ linux-2.6.27.10/arch/x86/kernel/irq_32.c 2008-11-18 03:38:44.000000000 -0500
7222 +@@ -116,7 +116,7 @@ execute_on_irq_stack(int overflow, struc
7223 + return 0;
7224 +
7225 + /* build the stack frame on the IRQ stack */
7226 +- isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
7227 ++ isp = (u32 *) ((char*)irqctx + sizeof(*irqctx) - 8);
7228 + irqctx->tinfo.task = curctx->tinfo.task;
7229 + irqctx->tinfo.previous_esp = current_stack_pointer;
7230 +
7231 +@@ -197,7 +197,7 @@ asmlinkage void do_softirq(void)
7232 + irqctx->tinfo.previous_esp = current_stack_pointer;
7233 +
7234 + /* build the stack frame on the softirq stack */
7235 +- isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
7236 ++ isp = (u32*) ((char*)irqctx + sizeof(*irqctx) - 8);
7237 +
7238 + call_on_stack(__do_softirq, isp);
7239 + /*
7240 +diff -urNp linux-2.6.27.10/arch/x86/kernel/kprobes.c linux-2.6.27.10/arch/x86/kernel/kprobes.c
7241 +--- linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
7242 ++++ linux-2.6.27.10/arch/x86/kernel/kprobes.c 2008-11-18 04:48:35.000000000 -0500
7243 +@@ -166,9 +166,24 @@ static void __kprobes set_jmp_op(void *f
7244 + char op;
7245 + s32 raddr;
7246 + } __attribute__((packed)) * jop;
7247 +- jop = (struct __arch_jmp_op *)from;
7248 ++
7249 ++#ifdef CONFIG_PAX_KERNEXEC
7250 ++ unsigned long cr0;
7251 ++#endif
7252 ++
7253 ++ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
7254 ++
7255 ++#ifdef CONFIG_PAX_KERNEXEC
7256 ++ pax_open_kernel(cr0);
7257 ++#endif
7258 ++
7259 + jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
7260 + jop->op = RELATIVEJUMP_INSTRUCTION;
7261 ++
7262 ++#ifdef CONFIG_PAX_KERNEXEC
7263 ++ pax_close_kernel(cr0);
7264 ++#endif
7265 ++
7266 + }
7267 +
7268 + /*
7269 +@@ -342,16 +357,29 @@ static void __kprobes fix_riprel(struct
7270 +
7271 + static void __kprobes arch_copy_kprobe(struct kprobe *p)
7272 + {
7273 +- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
7274 ++
7275 ++#ifdef CONFIG_PAX_KERNEXEC
7276 ++ unsigned long cr0;
7277 ++#endif
7278 ++
7279 ++#ifdef CONFIG_PAX_KERNEXEC
7280 ++ pax_open_kernel(cr0);
7281 ++#endif
7282 ++
7283 ++ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
7284 ++
7285 ++#ifdef CONFIG_PAX_KERNEXEC
7286 ++ pax_close_kernel(cr0);
7287 ++#endif
7288 +
7289 + fix_riprel(p);
7290 +
7291 +- if (can_boost(p->addr))
7292 ++ if (can_boost(ktla_ktva(p->addr)))
7293 + p->ainsn.boostable = 0;
7294 + else
7295 + p->ainsn.boostable = -1;
7296 +
7297 +- p->opcode = *p->addr;
7298 ++ p->opcode = *(ktla_ktva(p->addr));
7299 + }
7300 +
7301 + int __kprobes arch_prepare_kprobe(struct kprobe *p)
7302 +@@ -428,7 +456,7 @@ static void __kprobes prepare_singlestep
7303 + if (p->opcode == BREAKPOINT_INSTRUCTION)
7304 + regs->ip = (unsigned long)p->addr;
7305 + else
7306 +- regs->ip = (unsigned long)p->ainsn.insn;
7307 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
7308 + }
7309 +
7310 + void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
7311 +@@ -449,7 +477,7 @@ static void __kprobes setup_singlestep(s
7312 + if (p->ainsn.boostable == 1 && !p->post_handler) {
7313 + /* Boost up -- we can execute copied instructions directly */
7314 + reset_current_kprobe();
7315 +- regs->ip = (unsigned long)p->ainsn.insn;
7316 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
7317 + preempt_enable_no_resched();
7318 + return;
7319 + }
7320 +@@ -519,7 +547,7 @@ static int __kprobes kprobe_handler(stru
7321 + struct kprobe_ctlblk *kcb;
7322 +
7323 + addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
7324 +- if (*addr != BREAKPOINT_INSTRUCTION) {
7325 ++ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
7326 + /*
7327 + * The breakpoint instruction was removed right
7328 + * after we hit it. Another cpu has removed
7329 +@@ -770,7 +798,7 @@ static void __kprobes resume_execution(s
7330 + struct pt_regs *regs, struct kprobe_ctlblk *kcb)
7331 + {
7332 + unsigned long *tos = stack_addr(regs);
7333 +- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
7334 ++ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
7335 + unsigned long orig_ip = (unsigned long)p->addr;
7336 + kprobe_opcode_t *insn = p->ainsn.insn;
7337 +
7338 +@@ -953,7 +981,7 @@ int __kprobes kprobe_exceptions_notify(s
7339 + struct die_args *args = data;
7340 + int ret = NOTIFY_DONE;
7341 +
7342 +- if (args->regs && user_mode_vm(args->regs))
7343 ++ if (args->regs && user_mode(args->regs))
7344 + return ret;
7345 +
7346 + switch (val) {
7347 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ldt.c linux-2.6.27.10/arch/x86/kernel/ldt.c
7348 +--- linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-07 12:55:34.000000000 -0500
7349 ++++ linux-2.6.27.10/arch/x86/kernel/ldt.c 2008-11-18 03:38:44.000000000 -0500
7350 +@@ -63,13 +63,13 @@ static int alloc_ldt(mm_context_t *pc, i
7351 + if (reload) {
7352 + #ifdef CONFIG_SMP
7353 + preempt_disable();
7354 +- load_LDT(pc);
7355 ++ load_LDT_nolock(pc);
7356 + if (!cpus_equal(current->mm->cpu_vm_mask,
7357 + cpumask_of_cpu(smp_processor_id())))
7358 + smp_call_function(flush_ldt, current->mm, 1);
7359 + preempt_enable();
7360 + #else
7361 +- load_LDT(pc);
7362 ++ load_LDT_nolock(pc);
7363 + #endif
7364 + }
7365 + if (oldsize) {
7366 +@@ -108,6 +108,24 @@ int init_new_context(struct task_struct
7367 + retval = copy_ldt(&mm->context, &old_mm->context);
7368 + mutex_unlock(&old_mm->context.lock);
7369 + }
7370 ++
7371 ++ if (tsk == current) {
7372 ++ mm->context.vdso = ~0UL;
7373 ++
7374 ++#ifdef CONFIG_X86_32
7375 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
7376 ++ mm->context.user_cs_base = 0UL;
7377 ++ mm->context.user_cs_limit = ~0UL;
7378 ++
7379 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
7380 ++ cpus_clear(mm->context.cpu_user_cs_mask);
7381 ++#endif
7382 ++
7383 ++#endif
7384 ++#endif
7385 ++
7386 ++ }
7387 ++
7388 + return retval;
7389 + }
7390 +
7391 +@@ -221,6 +239,13 @@ static int write_ldt(void __user *ptr, u
7392 + }
7393 + }
7394 +
7395 ++#ifdef CONFIG_PAX_SEGMEXEC
7396 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
7397 ++ error = -EINVAL;
7398 ++ goto out_unlock;
7399 ++ }
7400 ++#endif
7401 ++
7402 + fill_ldt(&ldt, &ldt_info);
7403 + if (oldmode)
7404 + ldt.avl = 0;
7405 +diff -urNp linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c
7406 +--- linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-07 12:55:34.000000000 -0500
7407 ++++ linux-2.6.27.10/arch/x86/kernel/machine_kexec_32.c 2008-11-18 03:38:44.000000000 -0500
7408 +@@ -34,7 +34,7 @@ static u32 kexec_pmd1[1024] PAGE_ALIGNED
7409 + static u32 kexec_pte0[1024] PAGE_ALIGNED;
7410 + static u32 kexec_pte1[1024] PAGE_ALIGNED;
7411 +
7412 +-static void set_idt(void *newidt, __u16 limit)
7413 ++static void set_idt(struct desc_struct *newidt, __u16 limit)
7414 + {
7415 + struct desc_ptr curidt;
7416 +
7417 +@@ -46,7 +46,7 @@ static void set_idt(void *newidt, __u16
7418 + }
7419 +
7420 +
7421 +-static void set_gdt(void *newgdt, __u16 limit)
7422 ++static void set_gdt(struct desc_struct *newgdt, __u16 limit)
7423 + {
7424 + struct desc_ptr curgdt;
7425 +
7426 +@@ -145,7 +145,7 @@ void machine_kexec(struct kimage *image)
7427 + }
7428 +
7429 + control_page = page_address(image->control_code_page);
7430 +- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
7431 ++ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
7432 +
7433 + relocate_kernel_ptr = control_page;
7434 + page_list[PA_CONTROL_PAGE] = __pa(control_page);
7435 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_32.c linux-2.6.27.10/arch/x86/kernel/module_32.c
7436 +--- linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-07 12:55:34.000000000 -0500
7437 ++++ linux-2.6.27.10/arch/x86/kernel/module_32.c 2008-11-18 03:38:44.000000000 -0500
7438 +@@ -23,6 +23,9 @@
7439 + #include <linux/kernel.h>
7440 + #include <linux/bug.h>
7441 +
7442 ++#include <asm/desc.h>
7443 ++#include <asm/pgtable.h>
7444 ++
7445 + #if 0
7446 + #define DEBUGP printk
7447 + #else
7448 +@@ -33,9 +36,31 @@ void *module_alloc(unsigned long size)
7449 + {
7450 + if (size == 0)
7451 + return NULL;
7452 ++
7453 ++#ifdef CONFIG_PAX_KERNEXEC
7454 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
7455 ++#else
7456 + return vmalloc_exec(size);
7457 ++#endif
7458 ++
7459 + }
7460 +
7461 ++#ifdef CONFIG_PAX_KERNEXEC
7462 ++void *module_alloc_exec(unsigned long size)
7463 ++{
7464 ++ struct vm_struct *area;
7465 ++
7466 ++ if (size == 0)
7467 ++ return NULL;
7468 ++
7469 ++ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_VADDR, (unsigned long)&MODULES_END);
7470 ++ if (area)
7471 ++ return area->addr;
7472 ++
7473 ++ return NULL;
7474 ++}
7475 ++EXPORT_SYMBOL(module_alloc_exec);
7476 ++#endif
7477 +
7478 + /* Free memory returned from module_alloc */
7479 + void module_free(struct module *mod, void *module_region)
7480 +@@ -45,6 +70,45 @@ void module_free(struct module *mod, voi
7481 + table entries. */
7482 + }
7483 +
7484 ++#ifdef CONFIG_PAX_KERNEXEC
7485 ++void module_free_exec(struct module *mod, void *module_region)
7486 ++{
7487 ++ struct vm_struct **p, *tmp;
7488 ++
7489 ++ if (!module_region)
7490 ++ return;
7491 ++
7492 ++ if ((PAGE_SIZE-1) & (unsigned long)module_region) {
7493 ++ printk(KERN_ERR "Trying to module_free_exec() bad address (%p)\n", module_region);
7494 ++ WARN_ON(1);
7495 ++ return;
7496 ++ }
7497 ++
7498 ++ write_lock(&vmlist_lock);
7499 ++ for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next)
7500 ++ if (tmp->addr == module_region)
7501 ++ break;
7502 ++
7503 ++ if (tmp) {
7504 ++ unsigned long cr0;
7505 ++
7506 ++ pax_open_kernel(cr0);
7507 ++ memset(tmp->addr, 0xCC, tmp->size);
7508 ++ pax_close_kernel(cr0);
7509 ++
7510 ++ *p = tmp->next;
7511 ++ kfree(tmp);
7512 ++ }
7513 ++ write_unlock(&vmlist_lock);
7514 ++
7515 ++ if (!tmp) {
7516 ++ printk(KERN_ERR "Trying to module_free_exec() nonexistent vm area (%p)\n",
7517 ++ module_region);
7518 ++ WARN_ON(1);
7519 ++ }
7520 ++}
7521 ++#endif
7522 ++
7523 + /* We don't need anything special. */
7524 + int module_frob_arch_sections(Elf_Ehdr *hdr,
7525 + Elf_Shdr *sechdrs,
7526 +@@ -63,14 +127,20 @@ int apply_relocate(Elf32_Shdr *sechdrs,
7527 + unsigned int i;
7528 + Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
7529 + Elf32_Sym *sym;
7530 +- uint32_t *location;
7531 ++ uint32_t *plocation, location;
7532 ++
7533 ++#ifdef CONFIG_PAX_KERNEXEC
7534 ++ unsigned long cr0;
7535 ++#endif
7536 +
7537 + DEBUGP("Applying relocate section %u to %u\n", relsec,
7538 + sechdrs[relsec].sh_info);
7539 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
7540 + /* This is where to make the change */
7541 +- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
7542 +- + rel[i].r_offset;
7543 ++ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
7544 ++ location = (uint32_t)plocation;
7545 ++ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
7546 ++ plocation = ktla_ktva((void *)plocation);
7547 + /* This is the symbol it is referring to. Note that all
7548 + undefined symbols have been resolved. */
7549 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
7550 +@@ -78,12 +148,32 @@ int apply_relocate(Elf32_Shdr *sechdrs,
7551 +
7552 + switch (ELF32_R_TYPE(rel[i].r_info)) {
7553 + case R_386_32:
7554 ++
7555 ++#ifdef CONFIG_PAX_KERNEXEC
7556 ++ pax_open_kernel(cr0);
7557 ++#endif
7558 ++
7559 + /* We add the value into the location given */
7560 +- *location += sym->st_value;
7561 ++ *plocation += sym->st_value;
7562 ++
7563 ++#ifdef CONFIG_PAX_KERNEXEC
7564 ++ pax_close_kernel(cr0);
7565 ++#endif
7566 ++
7567 + break;
7568 + case R_386_PC32:
7569 ++
7570 ++#ifdef CONFIG_PAX_KERNEXEC
7571 ++ pax_open_kernel(cr0);
7572 ++#endif
7573 ++
7574 + /* Add the value, subtract its postition */
7575 +- *location += sym->st_value - (uint32_t)location;
7576 ++ *plocation += sym->st_value - location;
7577 ++
7578 ++#ifdef CONFIG_PAX_KERNEXEC
7579 ++ pax_close_kernel(cr0);
7580 ++#endif
7581 ++
7582 + break;
7583 + default:
7584 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
7585 +diff -urNp linux-2.6.27.10/arch/x86/kernel/module_64.c linux-2.6.27.10/arch/x86/kernel/module_64.c
7586 +--- linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-07 12:55:34.000000000 -0500
7587 ++++ linux-2.6.27.10/arch/x86/kernel/module_64.c 2008-11-18 03:38:44.000000000 -0500
7588 +@@ -40,7 +40,7 @@ void module_free(struct module *mod, voi
7589 + table entries. */
7590 + }
7591 +
7592 +-void *module_alloc(unsigned long size)
7593 ++static void *__module_alloc(unsigned long size, pgprot_t prot)
7594 + {
7595 + struct vm_struct *area;
7596 +
7597 +@@ -54,8 +54,31 @@ void *module_alloc(unsigned long size)
7598 + if (!area)
7599 + return NULL;
7600 +
7601 +- return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
7602 ++ return __vmalloc_area(area, GFP_KERNEL | __GFP_ZERO, prot);
7603 ++}
7604 ++
7605 ++#ifdef CONFIG_PAX_KERNEXEC
7606 ++void *module_alloc(unsigned long size)
7607 ++{
7608 ++ return __module_alloc(size, PAGE_KERNEL);
7609 ++}
7610 ++
7611 ++void module_free_exec(struct module *mod, void *module_region)
7612 ++{
7613 ++ module_free(mod, module_region);
7614 ++}
7615 ++
7616 ++void *module_alloc_exec(unsigned long size)
7617 ++{
7618 ++ return __module_alloc(size, PAGE_KERNEL_RX);
7619 + }
7620 ++#else
7621 ++void *module_alloc(unsigned long size)
7622 ++{
7623 ++ return __module_alloc(size, PAGE_KERNEL_EXEC);
7624 ++}
7625 ++#endif
7626 ++
7627 + #endif
7628 +
7629 + /* We don't need anything special. */
7630 +@@ -77,7 +100,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
7631 + Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
7632 + Elf64_Sym *sym;
7633 + void *loc;
7634 +- u64 val;
7635 ++ u64 val;
7636 ++
7637 ++#ifdef CONFIG_PAX_KERNEXEC
7638 ++ unsigned long cr0;
7639 ++#endif
7640 +
7641 + DEBUGP("Applying relocate section %u to %u\n", relsec,
7642 + sechdrs[relsec].sh_info);
7643 +@@ -101,21 +128,61 @@ int apply_relocate_add(Elf64_Shdr *sechd
7644 + case R_X86_64_NONE:
7645 + break;
7646 + case R_X86_64_64:
7647 ++
7648 ++#ifdef CONFIG_PAX_KERNEXEC
7649 ++ pax_open_kernel(cr0);
7650 ++#endif
7651 ++
7652 + *(u64 *)loc = val;
7653 ++
7654 ++#ifdef CONFIG_PAX_KERNEXEC
7655 ++ pax_close_kernel(cr0);
7656 ++#endif
7657 ++
7658 + break;
7659 + case R_X86_64_32:
7660 ++
7661 ++#ifdef CONFIG_PAX_KERNEXEC
7662 ++ pax_open_kernel(cr0);
7663 ++#endif
7664 ++
7665 + *(u32 *)loc = val;
7666 ++
7667 ++#ifdef CONFIG_PAX_KERNEXEC
7668 ++ pax_close_kernel(cr0);
7669 ++#endif
7670 ++
7671 + if (val != *(u32 *)loc)
7672 + goto overflow;
7673 + break;
7674 + case R_X86_64_32S:
7675 ++
7676 ++#ifdef CONFIG_PAX_KERNEXEC
7677 ++ pax_open_kernel(cr0);
7678 ++#endif
7679 ++
7680 + *(s32 *)loc = val;
7681 ++
7682 ++#ifdef CONFIG_PAX_KERNEXEC
7683 ++ pax_close_kernel(cr0);
7684 ++#endif
7685 ++
7686 + if ((s64)val != *(s32 *)loc)
7687 + goto overflow;
7688 + break;
7689 + case R_X86_64_PC32:
7690 + val -= (u64)loc;
7691 ++
7692 ++#ifdef CONFIG_PAX_KERNEXEC
7693 ++ pax_open_kernel(cr0);
7694 ++#endif
7695 ++
7696 + *(u32 *)loc = val;
7697 ++
7698 ++#ifdef CONFIG_PAX_KERNEXEC
7699 ++ pax_close_kernel(cr0);
7700 ++#endif
7701 ++
7702 + #if 0
7703 + if ((s64)val != *(s32 *)loc)
7704 + goto overflow;
7705 +diff -urNp linux-2.6.27.10/arch/x86/kernel/paravirt.c linux-2.6.27.10/arch/x86/kernel/paravirt.c
7706 +--- linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-07 12:55:34.000000000 -0500
7707 ++++ linux-2.6.27.10/arch/x86/kernel/paravirt.c 2008-11-18 03:38:44.000000000 -0500
7708 +@@ -44,7 +44,7 @@ void _paravirt_nop(void)
7709 + {
7710 + }
7711 +
7712 +-static void __init default_banner(void)
7713 ++static void default_banner(void)
7714 + {
7715 + printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
7716 + pv_info.name);
7717 +@@ -164,7 +164,7 @@ unsigned paravirt_patch_insns(void *insn
7718 + if (insn_len > len || start == NULL)
7719 + insn_len = len;
7720 + else
7721 +- memcpy(insnbuf, start, insn_len);
7722 ++ memcpy(insnbuf, ktla_ktva(start), insn_len);
7723 +
7724 + return insn_len;
7725 + }
7726 +@@ -279,21 +279,21 @@ void __init paravirt_use_bytelocks(void)
7727 + #endif
7728 + }
7729 +
7730 +-struct pv_info pv_info = {
7731 ++struct pv_info pv_info __read_only = {
7732 + .name = "bare hardware",
7733 + .paravirt_enabled = 0,
7734 + .kernel_rpl = 0,
7735 + .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
7736 + };
7737 +
7738 +-struct pv_init_ops pv_init_ops = {
7739 ++struct pv_init_ops pv_init_ops __read_only = {
7740 + .patch = native_patch,
7741 + .banner = default_banner,
7742 + .arch_setup = paravirt_nop,
7743 + .memory_setup = machine_specific_memory_setup,
7744 + };
7745 +
7746 +-struct pv_time_ops pv_time_ops = {
7747 ++struct pv_time_ops pv_time_ops __read_only = {
7748 + .time_init = hpet_time_init,
7749 + .get_wallclock = native_get_wallclock,
7750 + .set_wallclock = native_set_wallclock,
7751 +@@ -301,7 +301,7 @@ struct pv_time_ops pv_time_ops = {
7752 + .get_tsc_khz = native_calibrate_tsc,
7753 + };
7754 +
7755 +-struct pv_irq_ops pv_irq_ops = {
7756 ++struct pv_irq_ops pv_irq_ops __read_only = {
7757 + .init_IRQ = native_init_IRQ,
7758 + .save_fl = native_save_fl,
7759 + .restore_fl = native_restore_fl,
7760 +@@ -314,7 +314,7 @@ struct pv_irq_ops pv_irq_ops = {
7761 + #endif
7762 + };
7763 +
7764 +-struct pv_cpu_ops pv_cpu_ops = {
7765 ++struct pv_cpu_ops pv_cpu_ops __read_only = {
7766 + .cpuid = native_cpuid,
7767 + .get_debugreg = native_get_debugreg,
7768 + .set_debugreg = native_set_debugreg,
7769 +@@ -371,7 +371,7 @@ struct pv_cpu_ops pv_cpu_ops = {
7770 + },
7771 + };
7772 +
7773 +-struct pv_apic_ops pv_apic_ops = {
7774 ++struct pv_apic_ops pv_apic_ops __read_only = {
7775 + #ifdef CONFIG_X86_LOCAL_APIC
7776 + .apic_write = native_apic_write,
7777 + .apic_read = native_apic_read,
7778 +@@ -381,7 +381,7 @@ struct pv_apic_ops pv_apic_ops = {
7779 + #endif
7780 + };
7781 +
7782 +-struct pv_mmu_ops pv_mmu_ops = {
7783 ++struct pv_mmu_ops pv_mmu_ops __read_only = {
7784 + #ifndef CONFIG_X86_64
7785 + .pagetable_setup_start = native_pagetable_setup_start,
7786 + .pagetable_setup_done = native_pagetable_setup_done,
7787 +@@ -461,7 +461,7 @@ struct pv_mmu_ops pv_mmu_ops = {
7788 + .set_fixmap = native_set_fixmap,
7789 + };
7790 +
7791 +-struct pv_lock_ops pv_lock_ops = {
7792 ++struct pv_lock_ops pv_lock_ops __read_only = {
7793 + #ifdef CONFIG_SMP
7794 + .spin_is_locked = __ticket_spin_is_locked,
7795 + .spin_is_contended = __ticket_spin_is_contended,
7796 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_32.c linux-2.6.27.10/arch/x86/kernel/process_32.c
7797 +--- linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-07 12:55:34.000000000 -0500
7798 ++++ linux-2.6.27.10/arch/x86/kernel/process_32.c 2008-11-18 03:38:44.000000000 -0500
7799 +@@ -62,8 +62,10 @@ asmlinkage void ret_from_fork(void) __as
7800 + DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
7801 + EXPORT_PER_CPU_SYMBOL(current_task);
7802 +
7803 ++#ifdef CONFIG_SMP
7804 + DEFINE_PER_CPU(int, cpu_number);
7805 + EXPORT_PER_CPU_SYMBOL(cpu_number);
7806 ++#endif
7807 +
7808 + /*
7809 + * Return saved PC of a blocked thread.
7810 +@@ -71,6 +73,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
7811 + unsigned long thread_saved_pc(struct task_struct *tsk)
7812 + {
7813 + return ((unsigned long *)tsk->thread.sp)[3];
7814 ++//XXX return tsk->thread.eip;
7815 + }
7816 +
7817 + #ifdef CONFIG_HOTPLUG_CPU
7818 +@@ -162,7 +165,7 @@ void __show_registers(struct pt_regs *re
7819 + unsigned long sp;
7820 + unsigned short ss, gs;
7821 +
7822 +- if (user_mode_vm(regs)) {
7823 ++ if (user_mode(regs)) {
7824 + sp = regs->sp;
7825 + ss = regs->ss & 0xffff;
7826 + savesegment(gs, gs);
7827 +@@ -239,8 +242,8 @@ int kernel_thread(int (*fn)(void *), voi
7828 + regs.bx = (unsigned long) fn;
7829 + regs.dx = (unsigned long) arg;
7830 +
7831 +- regs.ds = __USER_DS;
7832 +- regs.es = __USER_DS;
7833 ++ regs.ds = __KERNEL_DS;
7834 ++ regs.es = __KERNEL_DS;
7835 + regs.fs = __KERNEL_PERCPU;
7836 + regs.orig_ax = -1;
7837 + regs.ip = (unsigned long) kernel_thread_helper;
7838 +@@ -262,7 +265,7 @@ void exit_thread(void)
7839 + struct task_struct *tsk = current;
7840 + struct thread_struct *t = &tsk->thread;
7841 + int cpu = get_cpu();
7842 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
7843 ++ struct tss_struct *tss = init_tss + cpu;
7844 +
7845 + kfree(t->io_bitmap_ptr);
7846 + t->io_bitmap_ptr = NULL;
7847 +@@ -283,6 +286,7 @@ void flush_thread(void)
7848 + {
7849 + struct task_struct *tsk = current;
7850 +
7851 ++ loadsegment(gs, 0);
7852 + tsk->thread.debugreg0 = 0;
7853 + tsk->thread.debugreg1 = 0;
7854 + tsk->thread.debugreg2 = 0;
7855 +@@ -322,7 +326,7 @@ int copy_thread(int nr, unsigned long cl
7856 + struct task_struct *tsk;
7857 + int err;
7858 +
7859 +- childregs = task_pt_regs(p);
7860 ++ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
7861 + *childregs = *regs;
7862 + childregs->ax = 0;
7863 + childregs->sp = sp;
7864 +@@ -351,6 +355,7 @@ int copy_thread(int nr, unsigned long cl
7865 + * Set a new TLS for the child thread?
7866 + */
7867 + if (clone_flags & CLONE_SETTLS)
7868 ++//XXX needs set_fs()?
7869 + err = do_set_thread_area(p, -1,
7870 + (struct user_desc __user *)childregs->si, 0);
7871 +
7872 +@@ -550,7 +555,7 @@ struct task_struct * __switch_to(struct
7873 + struct thread_struct *prev = &prev_p->thread,
7874 + *next = &next_p->thread;
7875 + int cpu = smp_processor_id();
7876 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
7877 ++ struct tss_struct *tss = init_tss + cpu;
7878 +
7879 + /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
7880 +
7881 +@@ -578,6 +583,11 @@ struct task_struct * __switch_to(struct
7882 + */
7883 + savesegment(gs, prev->gs);
7884 +
7885 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
7886 ++ if (!segment_eq(task_thread_info(prev_p)->addr_limit, task_thread_info(next_p)->addr_limit))
7887 ++ __set_fs(task_thread_info(next_p)->addr_limit, cpu);
7888 ++#endif
7889 ++
7890 + /*
7891 + * Load the per-thread Thread-Local Storage descriptor.
7892 + */
7893 +@@ -716,15 +726,27 @@ unsigned long get_wchan(struct task_stru
7894 + return 0;
7895 + }
7896 +
7897 +-unsigned long arch_align_stack(unsigned long sp)
7898 ++#ifdef CONFIG_PAX_RANDKSTACK
7899 ++asmlinkage void pax_randomize_kstack(void)
7900 + {
7901 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7902 +- sp -= get_random_int() % 8192;
7903 +- return sp & ~0xf;
7904 +-}
7905 ++ struct thread_struct *thread = &current->thread;
7906 ++ unsigned long time;
7907 +
7908 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
7909 +-{
7910 +- unsigned long range_end = mm->brk + 0x02000000;
7911 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
7912 ++ if (!randomize_va_space)
7913 ++ return;
7914 ++
7915 ++ rdtscl(time);
7916 ++
7917 ++ /* P4 seems to return a 0 LSB, ignore it */
7918 ++#ifdef CONFIG_MPENTIUM4
7919 ++ time &= 0x1EUL;
7920 ++ time <<= 2;
7921 ++#else
7922 ++ time &= 0xFUL;
7923 ++ time <<= 3;
7924 ++#endif
7925 ++
7926 ++ thread->sp0 ^= time;
7927 ++ load_sp0(init_tss + smp_processor_id(), thread);
7928 + }
7929 ++#endif
7930 +diff -urNp linux-2.6.27.10/arch/x86/kernel/process_64.c linux-2.6.27.10/arch/x86/kernel/process_64.c
7931 +--- linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-07 12:55:34.000000000 -0500
7932 ++++ linux-2.6.27.10/arch/x86/kernel/process_64.c 2008-11-18 03:38:44.000000000 -0500
7933 +@@ -119,6 +119,8 @@ static inline void play_dead(void)
7934 + void cpu_idle(void)
7935 + {
7936 + current_thread_info()->status |= TS_POLLING;
7937 ++ current->stack_canary = pax_get_random_long();
7938 ++ write_pda(stack_canary, current->stack_canary);
7939 + /* endless idle loop with no priority at all */
7940 + while (1) {
7941 + tick_nohz_stop_sched_tick(1);
7942 +@@ -228,7 +230,7 @@ void exit_thread(void)
7943 + struct thread_struct *t = &me->thread;
7944 +
7945 + if (me->thread.io_bitmap_ptr) {
7946 +- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
7947 ++ struct tss_struct *tss = init_tss + get_cpu();
7948 +
7949 + kfree(t->io_bitmap_ptr);
7950 + t->io_bitmap_ptr = NULL;
7951 +@@ -541,7 +543,7 @@ __switch_to(struct task_struct *prev_p,
7952 + struct thread_struct *prev = &prev_p->thread;
7953 + struct thread_struct *next = &next_p->thread;
7954 + int cpu = smp_processor_id();
7955 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
7956 ++ struct tss_struct *tss = init_tss + cpu;
7957 + unsigned fsindex, gsindex;
7958 +
7959 + /* we're going to use this soon, after a few expensive things */
7960 +@@ -630,7 +632,6 @@ __switch_to(struct task_struct *prev_p,
7961 + (unsigned long)task_stack_page(next_p) +
7962 + THREAD_SIZE - PDA_STACKOFFSET);
7963 + #ifdef CONFIG_CC_STACKPROTECTOR
7964 +- write_pda(stack_canary, next_p->stack_canary);
7965 + /*
7966 + * Build time only check to make sure the stack_canary is at
7967 + * offset 40 in the pda; this is a gcc ABI requirement
7968 +@@ -729,12 +730,11 @@ unsigned long get_wchan(struct task_stru
7969 + if (!p || p == current || p->state==TASK_RUNNING)
7970 + return 0;
7971 + stack = (unsigned long)task_stack_page(p);
7972 +- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
7973 ++ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64))
7974 + return 0;
7975 + fp = *(u64 *)(p->thread.sp);
7976 + do {
7977 +- if (fp < (unsigned long)stack ||
7978 +- fp >= (unsigned long)stack+THREAD_SIZE)
7979 ++ if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
7980 + return 0;
7981 + ip = *(u64 *)(fp+8);
7982 + if (!in_sched_functions(ip))
7983 +@@ -844,16 +844,3 @@ long sys_arch_prctl(int code, unsigned l
7984 + {
7985 + return do_arch_prctl(current, code, addr);
7986 + }
7987 +-
7988 +-unsigned long arch_align_stack(unsigned long sp)
7989 +-{
7990 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7991 +- sp -= get_random_int() % 8192;
7992 +- return sp & ~0xf;
7993 +-}
7994 +-
7995 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
7996 +-{
7997 +- unsigned long range_end = mm->brk + 0x02000000;
7998 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
7999 +-}
8000 +diff -urNp linux-2.6.27.10/arch/x86/kernel/ptrace.c linux-2.6.27.10/arch/x86/kernel/ptrace.c
8001 +--- linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
8002 ++++ linux-2.6.27.10/arch/x86/kernel/ptrace.c 2008-11-18 03:38:44.000000000 -0500
8003 +@@ -1369,7 +1369,7 @@ void send_sigtrap(struct task_struct *ts
8004 + info.si_code = TRAP_BRKPT;
8005 +
8006 + /* User-mode ip? */
8007 +- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
8008 ++ info.si_addr = user_mode(regs) ? (void __user *) regs->ip : NULL;
8009 +
8010 + /* Send us the fake SIGTRAP */
8011 + force_sig_info(SIGTRAP, &info, tsk);
8012 +diff -urNp linux-2.6.27.10/arch/x86/kernel/reboot.c linux-2.6.27.10/arch/x86/kernel/reboot.c
8013 +--- linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-07 12:55:34.000000000 -0500
8014 ++++ linux-2.6.27.10/arch/x86/kernel/reboot.c 2008-11-18 03:38:44.000000000 -0500
8015 +@@ -28,7 +28,7 @@ void (*pm_power_off)(void);
8016 + EXPORT_SYMBOL(pm_power_off);
8017 +
8018 + static const struct desc_ptr no_idt = {};
8019 +-static int reboot_mode;
8020 ++static unsigned short reboot_mode;
8021 + enum reboot_type reboot_type = BOOT_KBD;
8022 + int reboot_force;
8023 +
8024 +@@ -193,7 +193,7 @@ static struct dmi_system_id __initdata r
8025 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
8026 + },
8027 + },
8028 +- { }
8029 ++ { NULL, NULL, {{0, NULL}}, NULL}
8030 + };
8031 +
8032 + static int __init reboot_init(void)
8033 +@@ -209,12 +209,12 @@ core_initcall(reboot_init);
8034 + controller to pulse the CPU reset line, which is more thorough, but
8035 + doesn't work with at least one type of 486 motherboard. It is easy
8036 + to stop this code working; hence the copious comments. */
8037 +-static const unsigned long long
8038 +-real_mode_gdt_entries [3] =
8039 ++static struct desc_struct
8040 ++real_mode_gdt_entries [3] __read_only =
8041 + {
8042 +- 0x0000000000000000ULL, /* Null descriptor */
8043 +- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
8044 +- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
8045 ++ {{{0x00000000, 0x00000000}}}, /* Null descriptor */
8046 ++ {{{0x0000ffff, 0x00009b00}}}, /* 16-bit real-mode 64k code at 0x00000000 */
8047 ++ {{{0x0100ffff, 0x00009300}}} /* 16-bit real-mode 64k data at 0x00000100 */
8048 + };
8049 +
8050 + static const struct desc_ptr
8051 +@@ -263,7 +263,7 @@ static const unsigned char jump_to_bios
8052 + * specified by the code and length parameters.
8053 + * We assume that length will aways be less that 100!
8054 + */
8055 +-void machine_real_restart(const unsigned char *code, int length)
8056 ++void machine_real_restart(const unsigned char *code, unsigned int length)
8057 + {
8058 + local_irq_disable();
8059 +
8060 +@@ -283,8 +283,8 @@ void machine_real_restart(const unsigned
8061 + /* Remap the kernel at virtual address zero, as well as offset zero
8062 + from the kernel segment. This assumes the kernel segment starts at
8063 + virtual address PAGE_OFFSET. */
8064 +- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
8065 +- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
8066 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
8067 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
8068 +
8069 + /*
8070 + * Use `swapper_pg_dir' as our page directory.
8071 +@@ -296,16 +296,15 @@ void machine_real_restart(const unsigned
8072 + boot)". This seems like a fairly standard thing that gets set by
8073 + REBOOT.COM programs, and the previous reset routine did this
8074 + too. */
8075 +- *((unsigned short *)0x472) = reboot_mode;
8076 ++ *(unsigned short *)(__va(0x472)) = reboot_mode;
8077 +
8078 + /* For the switch to real mode, copy some code to low memory. It has
8079 + to be in the first 64k because it is running in 16-bit mode, and it
8080 + has to have the same physical and virtual address, because it turns
8081 + off paging. Copy it near the end of the first page, out of the way
8082 + of BIOS variables. */
8083 +- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
8084 +- real_mode_switch, sizeof (real_mode_switch));
8085 +- memcpy((void *)(0x1000 - 100), code, length);
8086 ++ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
8087 ++ memcpy(__va(0x1000 - 100), code, length);
8088 +
8089 + /* Set up the IDT for real mode. */
8090 + load_idt(&real_mode_idt);
8091 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup.c linux-2.6.27.10/arch/x86/kernel/setup.c
8092 +--- linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:11.000000000 -0500
8093 ++++ linux-2.6.27.10/arch/x86/kernel/setup.c 2008-12-21 01:18:21.000000000 -0500
8094 +@@ -578,6 +578,7 @@ static struct x86_quirks default_x86_qui
8095 +
8096 + struct x86_quirks *x86_quirks __initdata = &default_x86_quirks;
8097 +
8098 ++#ifdef CONFIG_X86_RESERVE_LOW_64K
8099 + static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
8100 + {
8101 + printk(KERN_NOTICE
8102 +@@ -589,6 +590,7 @@ static int __init dmi_low_memory_corrupt
8103 +
8104 + return 0;
8105 + }
8106 ++#endif
8107 +
8108 + /* List of systems that have known low memory corruption BIOS problems */
8109 + static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
8110 +@@ -685,8 +687,8 @@ void __init setup_arch(char **cmdline_p)
8111 +
8112 + if (!boot_params.hdr.root_flags)
8113 + root_mountflags &= ~MS_RDONLY;
8114 +- init_mm.start_code = (unsigned long) _text;
8115 +- init_mm.end_code = (unsigned long) _etext;
8116 ++ init_mm.start_code = ktla_ktva((unsigned long) _text);
8117 ++ init_mm.end_code = ktla_ktva((unsigned long) _etext);
8118 + init_mm.end_data = (unsigned long) _edata;
8119 + #ifdef CONFIG_X86_32
8120 + init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
8121 +@@ -694,9 +696,9 @@ void __init setup_arch(char **cmdline_p)
8122 + init_mm.brk = (unsigned long) &_end;
8123 + #endif
8124 +
8125 +- code_resource.start = virt_to_phys(_text);
8126 +- code_resource.end = virt_to_phys(_etext)-1;
8127 +- data_resource.start = virt_to_phys(_etext);
8128 ++ code_resource.start = virt_to_phys(ktla_ktva(_text));
8129 ++ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
8130 ++ data_resource.start = virt_to_phys(_data);
8131 + data_resource.end = virt_to_phys(_edata)-1;
8132 + bss_resource.start = virt_to_phys(&__bss_start);
8133 + bss_resource.end = virt_to_phys(&__bss_stop)-1;
8134 +diff -urNp linux-2.6.27.10/arch/x86/kernel/setup_percpu.c linux-2.6.27.10/arch/x86/kernel/setup_percpu.c
8135 +--- linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-07 12:55:34.000000000 -0500
8136 ++++ linux-2.6.27.10/arch/x86/kernel/setup_percpu.c 2008-11-18 03:38:44.000000000 -0500
8137 +@@ -166,7 +166,11 @@ void __init setup_per_cpu_areas(void)
8138 + else
8139 + ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
8140 + #endif
8141 ++#ifdef CONFIG_X86_32
8142 ++ __per_cpu_offset[cpu] = ptr - __per_cpu_start;
8143 ++#else
8144 + per_cpu_offset(cpu) = ptr - __per_cpu_start;
8145 ++#endif
8146 + memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
8147 +
8148 + }
8149 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_32.c linux-2.6.27.10/arch/x86/kernel/signal_32.c
8150 +--- linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-07 12:55:34.000000000 -0500
8151 ++++ linux-2.6.27.10/arch/x86/kernel/signal_32.c 2008-11-18 03:38:44.000000000 -0500
8152 +@@ -378,9 +378,9 @@ setup_frame(int sig, struct k_sigaction
8153 + }
8154 +
8155 + if (current->mm->context.vdso)
8156 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
8157 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
8158 + else
8159 +- restorer = &frame->retcode;
8160 ++ restorer = (void __user *)&frame->retcode;
8161 + if (ka->sa.sa_flags & SA_RESTORER)
8162 + restorer = ka->sa.sa_restorer;
8163 +
8164 +@@ -460,7 +460,7 @@ static int setup_rt_frame(int sig, struc
8165 + goto give_sigsegv;
8166 +
8167 + /* Set up to return from userspace. */
8168 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8169 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8170 + if (ka->sa.sa_flags & SA_RESTORER)
8171 + restorer = ka->sa.sa_restorer;
8172 + err |= __put_user(restorer, &frame->pretcode);
8173 +@@ -590,7 +590,7 @@ static void do_signal(struct pt_regs *re
8174 + * X86_32: vm86 regs switched out by assembly code before reaching
8175 + * here, so testing against kernel CS suffices.
8176 + */
8177 +- if (!user_mode(regs))
8178 ++ if (!user_mode_novm(regs))
8179 + return;
8180 +
8181 + if (current_thread_info()->status & TS_RESTORE_SIGMASK)
8182 +diff -urNp linux-2.6.27.10/arch/x86/kernel/signal_64.c linux-2.6.27.10/arch/x86/kernel/signal_64.c
8183 +--- linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-07 12:55:34.000000000 -0500
8184 ++++ linux-2.6.27.10/arch/x86/kernel/signal_64.c 2008-11-18 03:38:44.000000000 -0500
8185 +@@ -312,8 +312,8 @@ static int setup_rt_frame(int sig, struc
8186 + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
8187 + err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
8188 + if (sizeof(*set) == 16) {
8189 +- __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
8190 +- __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
8191 ++ err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
8192 ++ err |= __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
8193 + } else
8194 + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
8195 +
8196 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpboot.c linux-2.6.27.10/arch/x86/kernel/smpboot.c
8197 +--- linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:11.000000000 -0500
8198 ++++ linux-2.6.27.10/arch/x86/kernel/smpboot.c 2008-12-21 01:18:21.000000000 -0500
8199 +@@ -814,6 +814,11 @@ static int __cpuinit do_boot_cpu(int api
8200 + .cpu = cpu,
8201 + .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
8202 + };
8203 ++
8204 ++#ifdef CONFIG_PAX_KERNEXEC
8205 ++ unsigned long cr0;
8206 ++#endif
8207 ++
8208 + INIT_WORK(&c_idle.work, do_fork_idle);
8209 +
8210 + #ifdef CONFIG_X86_64
8211 +@@ -864,7 +869,17 @@ do_rest:
8212 + cpu_pda(cpu)->pcurrent = c_idle.idle;
8213 + clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
8214 + #endif
8215 ++
8216 ++#ifdef CONFIG_PAX_KERNEXEC
8217 ++ pax_open_kernel(cr0);
8218 ++#endif
8219 ++
8220 + early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
8221 ++
8222 ++#ifdef CONFIG_PAX_KERNEXEC
8223 ++ pax_close_kernel(cr0);
8224 ++#endif
8225 ++
8226 + initial_code = (unsigned long)start_secondary;
8227 + stack_start.sp = (void *) c_idle.idle->thread.sp;
8228 +
8229 +diff -urNp linux-2.6.27.10/arch/x86/kernel/smpcommon.c linux-2.6.27.10/arch/x86/kernel/smpcommon.c
8230 +--- linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-07 12:55:34.000000000 -0500
8231 ++++ linux-2.6.27.10/arch/x86/kernel/smpcommon.c 2008-11-18 03:38:44.000000000 -0500
8232 +@@ -3,9 +3,10 @@
8233 + */
8234 + #include <linux/module.h>
8235 + #include <asm/smp.h>
8236 ++#include <asm/sections.h>
8237 +
8238 + #ifdef CONFIG_X86_32
8239 +-DEFINE_PER_CPU(unsigned long, this_cpu_off);
8240 ++DEFINE_PER_CPU(unsigned long, this_cpu_off) = (unsigned long)__per_cpu_start;
8241 + EXPORT_PER_CPU_SYMBOL(this_cpu_off);
8242 +
8243 + /*
8244 +@@ -15,16 +16,19 @@ EXPORT_PER_CPU_SYMBOL(this_cpu_off);
8245 + */
8246 + __cpuinit void init_gdt(int cpu)
8247 + {
8248 +- struct desc_struct gdt;
8249 ++ struct desc_struct d, *gdt = get_cpu_gdt_table(cpu);
8250 ++ unsigned long base, limit;
8251 +
8252 +- pack_descriptor(&gdt, __per_cpu_offset[cpu], 0xFFFFF,
8253 +- 0x2 | DESCTYPE_S, 0x8);
8254 +- gdt.s = 1;
8255 ++ base = per_cpu_offset(cpu);
8256 ++ limit = PERCPU_ENOUGH_ROOM - 1;
8257 ++ if (limit < 64*1024)
8258 ++ pack_descriptor(&d, base, limit, 0x80 | DESCTYPE_S | 0x3, 0x4);
8259 ++ else
8260 ++ pack_descriptor(&d, base, limit >> PAGE_SHIFT, 0x80 | DESCTYPE_S | 0x3, 0xC);
8261 +
8262 +- write_gdt_entry(get_cpu_gdt_table(cpu),
8263 +- GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
8264 ++ write_gdt_entry(gdt, GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
8265 +
8266 +- per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
8267 ++ per_cpu(this_cpu_off, cpu) = base;
8268 + per_cpu(cpu_number, cpu) = cpu;
8269 + }
8270 + #endif
8271 +diff -urNp linux-2.6.27.10/arch/x86/kernel/step.c linux-2.6.27.10/arch/x86/kernel/step.c
8272 +--- linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-07 12:55:34.000000000 -0500
8273 ++++ linux-2.6.27.10/arch/x86/kernel/step.c 2008-11-18 03:38:44.000000000 -0500
8274 +@@ -23,22 +23,20 @@ unsigned long convert_ip_to_linear(struc
8275 + * and APM bios ones we just ignore here.
8276 + */
8277 + if ((seg & SEGMENT_TI_MASK) == SEGMENT_LDT) {
8278 +- u32 *desc;
8279 ++ struct desc_struct *desc;
8280 + unsigned long base;
8281 +
8282 +- seg &= ~7UL;
8283 ++ seg >>= 3;
8284 +
8285 + mutex_lock(&child->mm->context.lock);
8286 +- if (unlikely((seg >> 3) >= child->mm->context.size))
8287 +- addr = -1L; /* bogus selector, access would fault */
8288 ++ if (unlikely(seg >= child->mm->context.size))
8289 ++ addr = -EINVAL;
8290 + else {
8291 +- desc = child->mm->context.ldt + seg;
8292 +- base = ((desc[0] >> 16) |
8293 +- ((desc[1] & 0xff) << 16) |
8294 +- (desc[1] & 0xff000000));
8295 ++ desc = &child->mm->context.ldt[seg];
8296 ++ base = (desc->a >> 16) | ((desc->b & 0xff) << 16) | (desc->b & 0xff000000);
8297 +
8298 + /* 16-bit code segment? */
8299 +- if (!((desc[1] >> 22) & 1))
8300 ++ if (!((desc->b >> 22) & 1))
8301 + addr &= 0xffff;
8302 + addr += base;
8303 + }
8304 +@@ -54,6 +52,9 @@ static int is_setting_trap_flag(struct t
8305 + unsigned char opcode[15];
8306 + unsigned long addr = convert_ip_to_linear(child, regs);
8307 +
8308 ++ if (addr == -EINVAL)
8309 ++ return 0;
8310 ++
8311 + copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
8312 + for (i = 0; i < copied; i++) {
8313 + switch (opcode[i]) {
8314 +@@ -75,7 +76,7 @@ static int is_setting_trap_flag(struct t
8315 +
8316 + #ifdef CONFIG_X86_64
8317 + case 0x40 ... 0x4f:
8318 +- if (regs->cs != __USER_CS)
8319 ++ if ((regs->cs & 0xffff) != __USER_CS)
8320 + /* 32-bit mode: register increment */
8321 + return 0;
8322 + /* 64-bit mode: REX prefix */
8323 +diff -urNp linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S
8324 +--- linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-07 12:55:34.000000000 -0500
8325 ++++ linux-2.6.27.10/arch/x86/kernel/syscall_table_32.S 2008-11-18 03:38:44.000000000 -0500
8326 +@@ -1,3 +1,4 @@
8327 ++.section .rodata,"a",@progbits
8328 + ENTRY(sys_call_table)
8329 + .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
8330 + .long sys_exit
8331 +diff -urNp linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c
8332 +--- linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-07 12:55:34.000000000 -0500
8333 ++++ linux-2.6.27.10/arch/x86/kernel/sys_i386_32.c 2008-11-18 03:38:44.000000000 -0500
8334 +@@ -22,6 +22,21 @@
8335 + #include <linux/uaccess.h>
8336 + #include <linux/unistd.h>
8337 +
8338 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
8339 ++{
8340 ++ unsigned long pax_task_size = TASK_SIZE;
8341 ++
8342 ++#ifdef CONFIG_PAX_SEGMEXEC
8343 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
8344 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
8345 ++#endif
8346 ++
8347 ++ if (len > pax_task_size || addr > pax_task_size - len)
8348 ++ return -EINVAL;
8349 ++
8350 ++ return 0;
8351 ++}
8352 ++
8353 + asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
8354 + unsigned long prot, unsigned long flags,
8355 + unsigned long fd, unsigned long pgoff)
8356 +@@ -81,6 +96,205 @@ out:
8357 + return err;
8358 + }
8359 +
8360 ++unsigned long
8361 ++arch_get_unmapped_area(struct file *filp, unsigned long addr,
8362 ++ unsigned long len, unsigned long pgoff, unsigned long flags)
8363 ++{
8364 ++ struct mm_struct *mm = current->mm;
8365 ++ struct vm_area_struct *vma;
8366 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
8367 ++
8368 ++#ifdef CONFIG_PAX_SEGMEXEC
8369 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
8370 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
8371 ++#endif
8372 ++
8373 ++ if (len > pax_task_size)
8374 ++ return -ENOMEM;
8375 ++
8376 ++ if (flags & MAP_FIXED)
8377 ++ return addr;
8378 ++
8379 ++#ifdef CONFIG_PAX_RANDMMAP
8380 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
8381 ++#endif
8382 ++
8383 ++ if (addr) {
8384 ++ addr = PAGE_ALIGN(addr);
8385 ++ vma = find_vma(mm, addr);
8386 ++ if (pax_task_size - len >= addr &&
8387 ++ (!vma || addr + len <= vma->vm_start))
8388 ++ return addr;
8389 ++ }
8390 ++ if (len > mm->cached_hole_size) {
8391 ++ start_addr = addr = mm->free_area_cache;
8392 ++ } else {
8393 ++ start_addr = addr = mm->mmap_base;
8394 ++ mm->cached_hole_size = 0;
8395 ++ }
8396 ++
8397 ++#ifdef CONFIG_PAX_PAGEEXEC
8398 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
8399 ++ start_addr = 0x00110000UL;
8400 ++
8401 ++#ifdef CONFIG_PAX_RANDMMAP
8402 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
8403 ++ start_addr += mm->delta_mmap & 0x03FFF000UL;
8404 ++#endif
8405 ++
8406 ++ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
8407 ++ start_addr = addr = mm->mmap_base;
8408 ++ else
8409 ++ addr = start_addr;
8410 ++ }
8411 ++#endif
8412 ++
8413 ++full_search:
8414 ++ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
8415 ++ /* At this point: (!vma || addr < vma->vm_end). */
8416 ++ if (pax_task_size - len < addr) {
8417 ++ /*
8418 ++ * Start a new search - just in case we missed
8419 ++ * some holes.
8420 ++ */
8421 ++ if (start_addr != mm->mmap_base) {
8422 ++ start_addr = addr = mm->mmap_base;
8423 ++ mm->cached_hole_size = 0;
8424 ++ goto full_search;
8425 ++ }
8426 ++ return -ENOMEM;
8427 ++ }
8428 ++ if (!vma || addr + len <= vma->vm_start) {
8429 ++ /*
8430 ++ * Remember the place where we stopped the search:
8431 ++ */
8432 ++ mm->free_area_cache = addr + len;
8433 ++ return addr;
8434 ++ }
8435 ++ if (addr + mm->cached_hole_size < vma->vm_start)
8436 ++ mm->cached_hole_size = vma->vm_start - addr;
8437 ++ addr = vma->vm_end;
8438 ++ if (mm->start_brk <= addr && addr < mm->mmap_base) {
8439 ++ start_addr = addr = mm->mmap_base;
8440 ++ mm->cached_hole_size = 0;
8441 ++ goto full_search;
8442 ++ }
8443 ++ }
8444 ++}
8445 ++
8446 ++unsigned long
8447 ++arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8448 ++ const unsigned long len, const unsigned long pgoff,
8449 ++ const unsigned long flags)
8450 ++{
8451 ++ struct vm_area_struct *vma;
8452 ++ struct mm_struct *mm = current->mm;
8453 ++ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
8454 ++
8455 ++#ifdef CONFIG_PAX_SEGMEXEC
8456 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
8457 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
8458 ++#endif
8459 ++
8460 ++ /* requested length too big for entire address space */
8461 ++ if (len > pax_task_size)
8462 ++ return -ENOMEM;
8463 ++
8464 ++ if (flags & MAP_FIXED)
8465 ++ return addr;
8466 ++
8467 ++#ifdef CONFIG_PAX_PAGEEXEC
8468 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
8469 ++ goto bottomup;
8470 ++#endif
8471 ++
8472 ++#ifdef CONFIG_PAX_RANDMMAP
8473 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
8474 ++#endif
8475 ++
8476 ++ /* requesting a specific address */
8477 ++ if (addr) {
8478 ++ addr = PAGE_ALIGN(addr);
8479 ++ vma = find_vma(mm, addr);
8480 ++ if (pax_task_size - len >= addr &&
8481 ++ (!vma || addr + len <= vma->vm_start))
8482 ++ return addr;
8483 ++ }
8484 ++
8485 ++ /* check if free_area_cache is useful for us */
8486 ++ if (len <= mm->cached_hole_size) {
8487 ++ mm->cached_hole_size = 0;
8488 ++ mm->free_area_cache = mm->mmap_base;
8489 ++ }
8490 ++
8491 ++ /* either no address requested or can't fit in requested address hole */
8492 ++ addr = mm->free_area_cache;
8493 ++
8494 ++ /* make sure it can fit in the remaining address space */
8495 ++ if (addr > len) {
8496 ++ vma = find_vma(mm, addr-len);
8497 ++ if (!vma || addr <= vma->vm_start)
8498 ++ /* remember the address as a hint for next time */
8499 ++ return (mm->free_area_cache = addr-len);
8500 ++ }
8501 ++
8502 ++ if (mm->mmap_base < len)
8503 ++ goto bottomup;
8504 ++
8505 ++ addr = mm->mmap_base-len;
8506 ++
8507 ++ do {
8508 ++ /*
8509 ++ * Lookup failure means no vma is above this address,
8510 ++ * else if new region fits below vma->vm_start,
8511 ++ * return with success:
8512 ++ */
8513 ++ vma = find_vma(mm, addr);
8514 ++ if (!vma || addr+len <= vma->vm_start)
8515 ++ /* remember the address as a hint for next time */
8516 ++ return (mm->free_area_cache = addr);
8517 ++
8518 ++ /* remember the largest hole we saw so far */
8519 ++ if (addr + mm->cached_hole_size < vma->vm_start)
8520 ++ mm->cached_hole_size = vma->vm_start - addr;
8521 ++
8522 ++ /* try just below the current vma->vm_start */
8523 ++ addr = vma->vm_start-len;
8524 ++ } while (len < vma->vm_start);
8525 ++
8526 ++bottomup:
8527 ++ /*
8528 ++ * A failed mmap() very likely causes application failure,
8529 ++ * so fall back to the bottom-up function here. This scenario
8530 ++ * can happen with large stack limits and large mmap()
8531 ++ * allocations.
8532 ++ */
8533 ++
8534 ++#ifdef CONFIG_PAX_SEGMEXEC
8535 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
8536 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
8537 ++ else
8538 ++#endif
8539 ++
8540 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
8541 ++
8542 ++#ifdef CONFIG_PAX_RANDMMAP
8543 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
8544 ++ mm->mmap_base += mm->delta_mmap;
8545 ++#endif
8546 ++
8547 ++ mm->free_area_cache = mm->mmap_base;
8548 ++ mm->cached_hole_size = ~0UL;
8549 ++ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
8550 ++ /*
8551 ++ * Restore the topdown base:
8552 ++ */
8553 ++ mm->mmap_base = base;
8554 ++ mm->free_area_cache = base;
8555 ++ mm->cached_hole_size = ~0UL;
8556 ++
8557 ++ return addr;
8558 ++}
8559 +
8560 + struct sel_arg_struct {
8561 + unsigned long n;
8562 +diff -urNp linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c
8563 +--- linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-07 12:55:34.000000000 -0500
8564 ++++ linux-2.6.27.10/arch/x86/kernel/sys_x86_64.c 2008-11-18 03:38:44.000000000 -0500
8565 +@@ -45,8 +45,8 @@ out:
8566 + return error;
8567 + }
8568 +
8569 +-static void find_start_end(unsigned long flags, unsigned long *begin,
8570 +- unsigned long *end)
8571 ++static void find_start_end(struct mm_struct *mm, unsigned long flags,
8572 ++ unsigned long *begin, unsigned long *end)
8573 + {
8574 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
8575 + unsigned long new_begin;
8576 +@@ -65,7 +65,7 @@ static void find_start_end(unsigned long
8577 + *begin = new_begin;
8578 + }
8579 + } else {
8580 +- *begin = TASK_UNMAPPED_BASE;
8581 ++ *begin = mm->mmap_base;
8582 + *end = TASK_SIZE;
8583 + }
8584 + }
8585 +@@ -82,11 +82,15 @@ arch_get_unmapped_area(struct file *filp
8586 + if (flags & MAP_FIXED)
8587 + return addr;
8588 +
8589 +- find_start_end(flags, &begin, &end);
8590 ++ find_start_end(mm, flags, &begin, &end);
8591 +
8592 + if (len > end)
8593 + return -ENOMEM;
8594 +
8595 ++#ifdef CONFIG_PAX_RANDMMAP
8596 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || !filp)
8597 ++#endif
8598 ++
8599 + if (addr) {
8600 + addr = PAGE_ALIGN(addr);
8601 + vma = find_vma(mm, addr);
8602 +@@ -141,7 +145,7 @@ arch_get_unmapped_area_topdown(struct fi
8603 + {
8604 + struct vm_area_struct *vma;
8605 + struct mm_struct *mm = current->mm;
8606 +- unsigned long addr = addr0;
8607 ++ unsigned long base = mm->mmap_base, addr = addr0;
8608 +
8609 + /* requested length too big for entire address space */
8610 + if (len > TASK_SIZE)
8611 +@@ -154,6 +158,10 @@ arch_get_unmapped_area_topdown(struct fi
8612 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
8613 + goto bottomup;
8614 +
8615 ++#ifdef CONFIG_PAX_RANDMMAP
8616 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8617 ++#endif
8618 ++
8619 + /* requesting a specific address */
8620 + if (addr) {
8621 + addr = PAGE_ALIGN(addr);
8622 +@@ -211,13 +219,21 @@ bottomup:
8623 + * can happen with large stack limits and large mmap()
8624 + * allocations.
8625 + */
8626 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
8627 ++
8628 ++#ifdef CONFIG_PAX_RANDMMAP
8629 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
8630 ++ mm->mmap_base += mm->delta_mmap;
8631 ++#endif
8632 ++
8633 ++ mm->free_area_cache = mm->mmap_base;
8634 + mm->cached_hole_size = ~0UL;
8635 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
8636 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
8637 + /*
8638 + * Restore the topdown base:
8639 + */
8640 +- mm->free_area_cache = mm->mmap_base;
8641 ++ mm->mmap_base = base;
8642 ++ mm->free_area_cache = base;
8643 + mm->cached_hole_size = ~0UL;
8644 +
8645 + return addr;
8646 +diff -urNp linux-2.6.27.10/arch/x86/kernel/time_32.c linux-2.6.27.10/arch/x86/kernel/time_32.c
8647 +--- linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-07 12:55:34.000000000 -0500
8648 ++++ linux-2.6.27.10/arch/x86/kernel/time_32.c 2008-11-18 03:38:44.000000000 -0500
8649 +@@ -49,20 +49,30 @@ unsigned long profile_pc(struct pt_regs
8650 + if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs) &&
8651 + in_lock_functions(pc)) {
8652 + #ifdef CONFIG_FRAME_POINTER
8653 +- return *(unsigned long *)(regs->bp + 4);
8654 ++ return ktla_ktva(*(unsigned long *)(regs->bp + 4));
8655 + #else
8656 + unsigned long *sp = (unsigned long *)&regs->sp;
8657 +
8658 + /* Return address is either directly at stack pointer
8659 + or above a saved flags. Eflags has bits 22-31 zero,
8660 + kernel addresses don't. */
8661 ++
8662 ++#ifdef CONFIG_PAX_KERNEXEC
8663 ++ return ktla_ktva(sp[0]);
8664 ++#else
8665 + if (sp[0] >> 22)
8666 + return sp[0];
8667 + if (sp[1] >> 22)
8668 + return sp[1];
8669 + #endif
8670 ++
8671 ++#endif
8672 + }
8673 + #endif
8674 ++
8675 ++ if (!v8086_mode(regs) && SEGMENT_IS_KERNEL_CODE(regs->cs))
8676 ++ pc = ktla_ktva(pc);
8677 ++
8678 + return pc;
8679 + }
8680 + EXPORT_SYMBOL(profile_pc);
8681 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tlb_32.c linux-2.6.27.10/arch/x86/kernel/tlb_32.c
8682 +--- linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-07 12:55:34.000000000 -0500
8683 ++++ linux-2.6.27.10/arch/x86/kernel/tlb_32.c 2008-11-18 03:38:44.000000000 -0500
8684 +@@ -5,7 +5,7 @@
8685 + #include <asm/tlbflush.h>
8686 +
8687 + DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate)
8688 +- ____cacheline_aligned = { &init_mm, 0, };
8689 ++ ____cacheline_aligned = { &init_mm, 0, {0} };
8690 +
8691 + /* must come after the send_IPI functions above for inlining */
8692 + #include <mach_ipi.h>
8693 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tls.c linux-2.6.27.10/arch/x86/kernel/tls.c
8694 +--- linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-07 12:55:34.000000000 -0500
8695 ++++ linux-2.6.27.10/arch/x86/kernel/tls.c 2008-11-18 03:38:44.000000000 -0500
8696 +@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struc
8697 + if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
8698 + return -EINVAL;
8699 +
8700 ++#ifdef CONFIG_PAX_SEGMEXEC
8701 ++ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
8702 ++ return -EINVAL;
8703 ++#endif
8704 ++
8705 + set_tls_desc(p, idx, &info, 1);
8706 +
8707 + return 0;
8708 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_32.c linux-2.6.27.10/arch/x86/kernel/traps_32.c
8709 +--- linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-11-07 12:55:34.000000000 -0500
8710 ++++ linux-2.6.27.10/arch/x86/kernel/traps_32.c 2008-12-10 22:28:27.000000000 -0500
8711 +@@ -70,14 +70,6 @@ asmlinkage int system_call(void);
8712 + /* Do we ignore FPU interrupts ? */
8713 + char ignore_fpu_irq;
8714 +
8715 +-/*
8716 +- * The IDT has to be page-aligned to simplify the Pentium
8717 +- * F0 0F bug workaround.. We have a special link segment
8718 +- * for this.
8719 +- */
8720 +-gate_desc idt_table[256]
8721 +- __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
8722 +-
8723 + int panic_on_unrecovered_nmi;
8724 + int kstack_depth_to_print = 24;
8725 + static unsigned int code_bytes = 64;
8726 +@@ -320,21 +312,22 @@ void show_registers(struct pt_regs *regs
8727 + * When in-kernel, we also print out the stack and code at the
8728 + * time of the fault..
8729 + */
8730 +- if (!user_mode_vm(regs)) {
8731 ++ if (!user_mode(regs)) {
8732 + unsigned int code_prologue = code_bytes * 43 / 64;
8733 + unsigned int code_len = code_bytes;
8734 + unsigned char c;
8735 + u8 *ip;
8736 ++ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
8737 +
8738 + printk("\n" KERN_EMERG "Stack: ");
8739 + show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
8740 +
8741 + printk(KERN_EMERG "Code: ");
8742 +
8743 +- ip = (u8 *)regs->ip - code_prologue;
8744 ++ ip = (u8 *)regs->ip - code_prologue + cs_base;
8745 + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
8746 + /* try starting at EIP */
8747 +- ip = (u8 *)regs->ip;
8748 ++ ip = (u8 *)regs->ip + cs_base;
8749 + code_len = code_len - code_prologue + 1;
8750 + }
8751 + for (i = 0; i < code_len; i++, ip++) {
8752 +@@ -343,7 +336,7 @@ void show_registers(struct pt_regs *regs
8753 + printk(" Bad EIP value.");
8754 + break;
8755 + }
8756 +- if (ip == (u8 *)regs->ip)
8757 ++ if (ip == (u8 *)regs->ip + cs_base)
8758 + printk("<%02x> ", c);
8759 + else
8760 + printk("%02x ", c);
8761 +@@ -356,6 +349,7 @@ int is_valid_bugaddr(unsigned long ip)
8762 + {
8763 + unsigned short ud2;
8764 +
8765 ++ ip = ktla_ktva(ip);
8766 + if (ip < PAGE_OFFSET)
8767 + return 0;
8768 + if (probe_kernel_address((unsigned short *)ip, ud2))
8769 +@@ -469,7 +463,7 @@ void die(const char *str, struct pt_regs
8770 + static inline void
8771 + die_if_kernel(const char *str, struct pt_regs *regs, long err)
8772 + {
8773 +- if (!user_mode_vm(regs))
8774 ++ if (!user_mode(regs))
8775 + die(str, regs, err);
8776 + }
8777 +
8778 +@@ -479,13 +473,13 @@ do_trap(int trapnr, int signr, char *str
8779 + {
8780 + struct task_struct *tsk = current;
8781 +
8782 +- if (regs->flags & X86_VM_MASK) {
8783 ++ if (v8086_mode(regs)) {
8784 + if (vm86)
8785 + goto vm86_trap;
8786 + goto trap_signal;
8787 + }
8788 +
8789 +- if (!user_mode(regs))
8790 ++ if (!user_mode_novm(regs))
8791 + goto kernel_trap;
8792 +
8793 + trap_signal:
8794 +@@ -513,6 +507,12 @@ kernel_trap:
8795 + tsk->thread.trap_no = trapnr;
8796 + die(str, regs, error_code);
8797 + }
8798 ++
8799 ++#ifdef CONFIG_PAX_REFCOUNT
8800 ++ if (trapnr == 4)
8801 ++ pax_report_refcount_overflow(regs);
8802 ++#endif
8803 ++
8804 + return;
8805 +
8806 + vm86_trap:
8807 +@@ -595,7 +595,7 @@ do_general_protection(struct pt_regs *re
8808 + int cpu;
8809 +
8810 + cpu = get_cpu();
8811 +- tss = &per_cpu(init_tss, cpu);
8812 ++ tss = init_tss + cpu;
8813 + thread = &current->thread;
8814 +
8815 + /*
8816 +@@ -627,13 +627,29 @@ do_general_protection(struct pt_regs *re
8817 + }
8818 + put_cpu();
8819 +
8820 +- if (regs->flags & X86_VM_MASK)
8821 ++ if (v8086_mode(regs))
8822 + goto gp_in_vm86;
8823 +
8824 + tsk = current;
8825 +- if (!user_mode(regs))
8826 ++ if (!user_mode_novm(regs))
8827 + goto gp_in_kernel;
8828 +
8829 ++#ifdef CONFIG_PAX_PAGEEXEC
8830 ++ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
8831 ++ struct mm_struct *mm = tsk->mm;
8832 ++ unsigned long limit;
8833 ++
8834 ++ down_write(&mm->mmap_sem);
8835 ++ limit = mm->context.user_cs_limit;
8836 ++ if (limit < TASK_SIZE) {
8837 ++ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
8838 ++ up_write(&mm->mmap_sem);
8839 ++ return;
8840 ++ }
8841 ++ up_write(&mm->mmap_sem);
8842 ++ }
8843 ++#endif
8844 ++
8845 + tsk->thread.error_code = error_code;
8846 + tsk->thread.trap_no = 13;
8847 +
8848 +@@ -664,6 +680,13 @@ gp_in_kernel:
8849 + if (notify_die(DIE_GPF, "general protection fault", regs,
8850 + error_code, 13, SIGSEGV) == NOTIFY_STOP)
8851 + return;
8852 ++
8853 ++#ifdef CONFIG_PAX_KERNEXEC
8854 ++ if ((regs->cs & 0xFFFF) == __KERNEL_CS)
8855 ++ die("PAX: suspicious general protection fault", regs, error_code);
8856 ++ else
8857 ++#endif
8858 ++
8859 + die("general protection fault", regs, error_code);
8860 + }
8861 +
8862 +@@ -766,7 +789,7 @@ void notrace __kprobes die_nmi(char *str
8863 + * If we are in kernel we are probably nested up pretty bad
8864 + * and might aswell get out now while we still can:
8865 + */
8866 +- if (!user_mode_vm(regs)) {
8867 ++ if (!user_mode(regs)) {
8868 + current->thread.trap_no = 2;
8869 + crash_kexec(regs);
8870 + }
8871 +@@ -915,7 +938,7 @@ void __kprobes do_debug(struct pt_regs *
8872 + goto clear_dr7;
8873 + }
8874 +
8875 +- if (regs->flags & X86_VM_MASK)
8876 ++ if (v8086_mode(regs))
8877 + goto debug_vm86;
8878 +
8879 + /* Save debug status register where ptrace can see it */
8880 +@@ -931,7 +954,7 @@ void __kprobes do_debug(struct pt_regs *
8881 + * check for kernel mode by just checking the CPL
8882 + * of CS.
8883 + */
8884 +- if (!user_mode(regs))
8885 ++ if (!user_mode_novm(regs))
8886 + goto clear_TF_reenable;
8887 + }
8888 +
8889 +@@ -1086,7 +1109,7 @@ void do_simd_coprocessor_error(struct pt
8890 + * Handle strange cache flush from user space exception
8891 + * in all other cases. This is undocumented behaviour.
8892 + */
8893 +- if (regs->flags & X86_VM_MASK) {
8894 ++ if (v8086_mode(regs)) {
8895 + handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
8896 + return;
8897 + }
8898 +@@ -1106,19 +1129,14 @@ void do_spurious_interrupt_bug(struct pt
8899 +
8900 + unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
8901 + {
8902 +- struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
8903 + unsigned long base = (kesp - uesp) & -THREAD_SIZE;
8904 + unsigned long new_kesp = kesp - base;
8905 + unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
8906 +- __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
8907 ++ struct desc_struct ss;
8908 +
8909 + /* Set up base for espfix segment */
8910 +- desc &= 0x00f0ff0000000000ULL;
8911 +- desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
8912 +- ((((__u64)base) << 32) & 0xff00000000000000ULL) |
8913 +- ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
8914 +- (lim_pages & 0xffff);
8915 +- *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
8916 ++ pack_descriptor(&ss, base, lim_pages, 0x93, 0xC);
8917 ++ write_gdt_entry(get_cpu_gdt_table(smp_processor_id()), GDT_ENTRY_ESPFIX_SS, &ss, DESCTYPE_S);
8918 +
8919 + return new_kesp;
8920 + }
8921 +diff -urNp linux-2.6.27.10/arch/x86/kernel/traps_64.c linux-2.6.27.10/arch/x86/kernel/traps_64.c
8922 +--- linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-07 12:55:34.000000000 -0500
8923 ++++ linux-2.6.27.10/arch/x86/kernel/traps_64.c 2008-11-18 03:38:44.000000000 -0500
8924 +@@ -634,6 +634,12 @@ kernel_trap:
8925 + tsk->thread.trap_no = trapnr;
8926 + die(str, regs, error_code);
8927 + }
8928 ++
8929 ++#ifdef CONFIG_PAX_REFCOUNT
8930 ++ if (trapnr == 4)
8931 ++ pax_report_refcount_overflow(regs);
8932 ++#endif
8933 ++
8934 + return;
8935 + }
8936 +
8937 +diff -urNp linux-2.6.27.10/arch/x86/kernel/tsc.c linux-2.6.27.10/arch/x86/kernel/tsc.c
8938 +--- linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-17 20:03:30.000000000 -0500
8939 ++++ linux-2.6.27.10/arch/x86/kernel/tsc.c 2008-11-18 03:38:44.000000000 -0500
8940 +@@ -554,7 +554,7 @@ static struct dmi_system_id __initdata b
8941 + DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
8942 + },
8943 + },
8944 +- {}
8945 ++ { NULL, NULL, {{0, NULL}}, NULL}
8946 + };
8947 +
8948 + /*
8949 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vm86_32.c linux-2.6.27.10/arch/x86/kernel/vm86_32.c
8950 +--- linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-07 12:55:34.000000000 -0500
8951 ++++ linux-2.6.27.10/arch/x86/kernel/vm86_32.c 2008-11-18 03:38:44.000000000 -0500
8952 +@@ -147,7 +147,7 @@ struct pt_regs *save_v86_state(struct ke
8953 + do_exit(SIGSEGV);
8954 + }
8955 +
8956 +- tss = &per_cpu(init_tss, get_cpu());
8957 ++ tss = init_tss + get_cpu();
8958 + current->thread.sp0 = current->thread.saved_sp0;
8959 + current->thread.sysenter_cs = __KERNEL_CS;
8960 + load_sp0(tss, &current->thread);
8961 +@@ -324,7 +324,7 @@ static void do_sys_vm86(struct kernel_vm
8962 + tsk->thread.saved_fs = info->regs32->fs;
8963 + savesegment(gs, tsk->thread.saved_gs);
8964 +
8965 +- tss = &per_cpu(init_tss, get_cpu());
8966 ++ tss = init_tss + get_cpu();
8967 + tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
8968 + if (cpu_has_sep)
8969 + tsk->thread.sysenter_cs = 0;
8970 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmi_32.c linux-2.6.27.10/arch/x86/kernel/vmi_32.c
8971 +--- linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:11.000000000 -0500
8972 ++++ linux-2.6.27.10/arch/x86/kernel/vmi_32.c 2008-12-21 01:18:21.000000000 -0500
8973 +@@ -102,18 +102,43 @@ static unsigned patch_internal(int call,
8974 + {
8975 + u64 reloc;
8976 + struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
8977 ++
8978 ++#ifdef CONFIG_PAX_KERNEXEC
8979 ++ unsigned long cr0;
8980 ++#endif
8981 ++
8982 + reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
8983 + switch(rel->type) {
8984 + case VMI_RELOCATION_CALL_REL:
8985 + BUG_ON(len < 5);
8986 ++
8987 ++#ifdef CONFIG_PAX_KERNEXEC
8988 ++ pax_open_kernel(cr0);
8989 ++#endif
8990 ++
8991 + *(char *)insnbuf = MNEM_CALL;
8992 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
8993 ++
8994 ++#ifdef CONFIG_PAX_KERNEXEC
8995 ++ pax_close_kernel(cr0);
8996 ++#endif
8997 ++
8998 + return 5;
8999 +
9000 + case VMI_RELOCATION_JUMP_REL:
9001 + BUG_ON(len < 5);
9002 ++
9003 ++#ifdef CONFIG_PAX_KERNEXEC
9004 ++ pax_open_kernel(cr0);
9005 ++#endif
9006 ++
9007 + *(char *)insnbuf = MNEM_JMP;
9008 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
9009 ++
9010 ++#ifdef CONFIG_PAX_KERNEXEC
9011 ++ pax_close_kernel(cr0);
9012 ++#endif
9013 ++
9014 + return 5;
9015 +
9016 + case VMI_RELOCATION_NOP:
9017 +@@ -516,14 +541,14 @@ static void vmi_set_pud(pud_t *pudp, pud
9018 +
9019 + static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
9020 + {
9021 +- const pte_t pte = { .pte = 0 };
9022 ++ const pte_t pte = __pte(0ULL);
9023 + vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE);
9024 + vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
9025 + }
9026 +
9027 + static void vmi_pmd_clear(pmd_t *pmd)
9028 + {
9029 +- const pte_t pte = { .pte = 0 };
9030 ++ const pte_t pte = __pte(0ULL);
9031 + vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD);
9032 + vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
9033 + }
9034 +@@ -552,8 +577,8 @@ vmi_startup_ipi_hook(int phys_apicid, un
9035 + ap.ss = __KERNEL_DS;
9036 + ap.esp = (unsigned long) start_esp;
9037 +
9038 +- ap.ds = __USER_DS;
9039 +- ap.es = __USER_DS;
9040 ++ ap.ds = __KERNEL_DS;
9041 ++ ap.es = __KERNEL_DS;
9042 + ap.fs = __KERNEL_PERCPU;
9043 + ap.gs = 0;
9044 +
9045 +@@ -748,12 +773,20 @@ static inline int __init activate_vmi(vo
9046 + u64 reloc;
9047 + const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc;
9048 +
9049 ++#ifdef CONFIG_PAX_KERNEXEC
9050 ++ unsigned long cr0;
9051 ++#endif
9052 ++
9053 + if (call_vrom_func(vmi_rom, vmi_init) != 0) {
9054 + printk(KERN_ERR "VMI ROM failed to initialize!");
9055 + return 0;
9056 + }
9057 + savesegment(cs, kernel_cs);
9058 +
9059 ++#ifdef CONFIG_PAX_KERNEXEC
9060 ++ pax_open_kernel(cr0);
9061 ++#endif
9062 ++
9063 + pv_info.paravirt_enabled = 1;
9064 + pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK;
9065 + pv_info.name = "vmi";
9066 +@@ -943,6 +976,10 @@ static inline int __init activate_vmi(vo
9067 +
9068 + para_fill(pv_irq_ops.safe_halt, Halt);
9069 +
9070 ++#ifdef CONFIG_PAX_KERNEXEC
9071 ++ pax_close_kernel(cr0);
9072 ++#endif
9073 ++
9074 + /*
9075 + * Alternative instruction rewriting doesn't happen soon enough
9076 + * to convert VMI_IRET to a call instead of a jump; so we have
9077 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S
9078 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-07 12:55:34.000000000 -0500
9079 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_32.lds.S 2008-11-18 03:38:44.000000000 -0500
9080 +@@ -15,6 +15,20 @@
9081 + #include <asm/page.h>
9082 + #include <asm/cache.h>
9083 + #include <asm/boot.h>
9084 ++#include <asm/segment.h>
9085 ++
9086 ++#ifdef CONFIG_X86_PAE
9087 ++#define PMD_SHIFT 21
9088 ++#else
9089 ++#define PMD_SHIFT 22
9090 ++#endif
9091 ++#define PMD_SIZE (1 << PMD_SHIFT)
9092 ++
9093 ++#ifdef CONFIG_PAX_KERNEXEC
9094 ++#define __KERNEL_TEXT_OFFSET (__PAGE_OFFSET + (((____LOAD_PHYSICAL_ADDR + 2*(PMD_SIZE - 1)) - 1) & ~(PMD_SIZE - 1)))
9095 ++#else
9096 ++#define __KERNEL_TEXT_OFFSET 0
9097 ++#endif
9098 +
9099 + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
9100 + OUTPUT_ARCH(i386)
9101 +@@ -22,81 +36,23 @@ ENTRY(phys_startup_32)
9102 + jiffies = jiffies_64;
9103 +
9104 + PHDRS {
9105 +- text PT_LOAD FLAGS(5); /* R_E */
9106 +- data PT_LOAD FLAGS(7); /* RWE */
9107 +- note PT_NOTE FLAGS(0); /* ___ */
9108 ++ initdata PT_LOAD FLAGS(6); /* RW_ */
9109 ++ percpu PT_LOAD FLAGS(6); /* RW_ */
9110 ++ inittext PT_LOAD FLAGS(5); /* R_E */
9111 ++ text PT_LOAD FLAGS(5); /* R_E */
9112 ++ rodata PT_LOAD FLAGS(4); /* R__ */
9113 ++ data PT_LOAD FLAGS(6); /* RW_ */
9114 ++ note PT_NOTE FLAGS(0); /* ___ */
9115 + }
9116 + SECTIONS
9117 + {
9118 +- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
9119 +- phys_startup_32 = startup_32 - LOAD_OFFSET;
9120 +-
9121 +- .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
9122 +- _text = .; /* Text and read-only data */
9123 +- *(.text.head)
9124 +- } :text = 0x9090
9125 +-
9126 +- /* read-only */
9127 +- .text : AT(ADDR(.text) - LOAD_OFFSET) {
9128 +- . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
9129 +- *(.text.page_aligned)
9130 +- TEXT_TEXT
9131 +- SCHED_TEXT
9132 +- LOCK_TEXT
9133 +- KPROBES_TEXT
9134 +- *(.fixup)
9135 +- *(.gnu.warning)
9136 +- _etext = .; /* End of text section */
9137 +- } :text = 0x9090
9138 +-
9139 +- NOTES :text :note
9140 ++ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
9141 +
9142 +- . = ALIGN(16); /* Exception table */
9143 +- __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
9144 +- __start___ex_table = .;
9145 +- *(__ex_table)
9146 +- __stop___ex_table = .;
9147 +- } :text = 0x9090
9148 +-
9149 +- RODATA
9150 +-
9151 +- /* writeable */
9152 +- . = ALIGN(PAGE_SIZE);
9153 +- .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
9154 +- DATA_DATA
9155 +- CONSTRUCTORS
9156 +- } :data
9157 +-
9158 +- . = ALIGN(PAGE_SIZE);
9159 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
9160 +- __nosave_begin = .;
9161 +- *(.data.nosave)
9162 +- . = ALIGN(PAGE_SIZE);
9163 +- __nosave_end = .;
9164 +- }
9165 +-
9166 +- . = ALIGN(PAGE_SIZE);
9167 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
9168 +- *(.data.page_aligned)
9169 +- *(.data.idt)
9170 +- }
9171 +-
9172 +- . = ALIGN(32);
9173 +- .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
9174 +- *(.data.cacheline_aligned)
9175 +- }
9176 +-
9177 +- /* rarely changed data like cpu maps */
9178 +- . = ALIGN(32);
9179 +- .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
9180 +- *(.data.read_mostly)
9181 +- _edata = .; /* End of data section */
9182 +- }
9183 +-
9184 +- . = ALIGN(THREAD_SIZE); /* init_task */
9185 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
9186 +- *(.data.init_task)
9187 +- }
9188 ++ .text.startup : AT(ADDR(.text.startup) - LOAD_OFFSET) {
9189 ++ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET;
9190 ++ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
9191 ++ *(.text.startup)
9192 ++ } :initdata
9193 +
9194 + /* might get freed after init */
9195 + . = ALIGN(PAGE_SIZE);
9196 +@@ -114,14 +70,8 @@ SECTIONS
9197 + . = ALIGN(PAGE_SIZE);
9198 +
9199 + /* will be freed after init */
9200 +- . = ALIGN(PAGE_SIZE); /* Init code and data */
9201 +- .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
9202 +- __init_begin = .;
9203 +- _sinittext = .;
9204 +- INIT_TEXT
9205 +- _einittext = .;
9206 +- }
9207 + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
9208 ++ __init_begin = .;
9209 + INIT_DATA
9210 + }
9211 + . = ALIGN(16);
9212 +@@ -161,11 +111,6 @@ SECTIONS
9213 + *(.parainstructions)
9214 + __parainstructions_end = .;
9215 + }
9216 +- /* .exit.text is discard at runtime, not link time, to deal with references
9217 +- from .altinstructions and .eh_frame */
9218 +- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
9219 +- EXIT_TEXT
9220 +- }
9221 + .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
9222 + EXIT_DATA
9223 + }
9224 +@@ -178,17 +123,136 @@ SECTIONS
9225 + }
9226 + #endif
9227 + . = ALIGN(PAGE_SIZE);
9228 +- .data.percpu : AT(ADDR(.data.percpu) - LOAD_OFFSET) {
9229 +- __per_cpu_start = .;
9230 ++ per_cpu_start = .;
9231 ++ .data.percpu (0) : AT(ADDR(.data.percpu) - LOAD_OFFSET + per_cpu_start) {
9232 ++ __per_cpu_start = . + per_cpu_start;
9233 ++ LONG(0)
9234 + *(.data.percpu)
9235 + *(.data.percpu.shared_aligned)
9236 +- __per_cpu_end = .;
9237 +- }
9238 ++ __per_cpu_end = . + per_cpu_start;
9239 ++ } :percpu
9240 ++ . += per_cpu_start;
9241 + . = ALIGN(PAGE_SIZE);
9242 + /* freed after init ends here */
9243 +
9244 ++ . = ALIGN(PAGE_SIZE); /* Init code and data */
9245 ++ .init.text (. - __KERNEL_TEXT_OFFSET) : AT(ADDR(.init.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
9246 ++ _sinittext = .;
9247 ++ INIT_TEXT
9248 ++ _einittext = .;
9249 ++ } :inittext
9250 ++
9251 ++ /* .exit.text is discard at runtime, not link time, to deal with references
9252 ++ from .altinstructions and .eh_frame */
9253 ++ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
9254 ++ EXIT_TEXT
9255 ++ }
9256 ++
9257 ++ .filler : AT(ADDR(.filler) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
9258 ++ BYTE(0)
9259 ++ . = ALIGN(2*PMD_SIZE) - 1;
9260 ++ }
9261 ++
9262 ++ /* freed after init ends here */
9263 ++
9264 ++ .text.head : AT(ADDR(.text.head) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
9265 ++ __init_end = . + __KERNEL_TEXT_OFFSET;
9266 ++ KERNEL_TEXT_OFFSET = . + __KERNEL_TEXT_OFFSET;
9267 ++ _text = .; /* Text and read-only data */
9268 ++ *(.text.head)
9269 ++ } :text = 0x9090
9270 ++
9271 ++ /* read-only */
9272 ++ .text : AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
9273 ++ . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
9274 ++ *(.text.page_aligned)
9275 ++ TEXT_TEXT
9276 ++ SCHED_TEXT
9277 ++ LOCK_TEXT
9278 ++ KPROBES_TEXT
9279 ++ *(.fixup)
9280 ++ *(.gnu.warning)
9281 ++ _etext = .; /* End of text section */
9282 ++ } :text = 0x9090
9283 ++
9284 ++ . += __KERNEL_TEXT_OFFSET;
9285 ++
9286 ++ . = ALIGN(4096); /* Exception table */
9287 ++ __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
9288 ++ __start___ex_table = .;
9289 ++ *(__ex_table)
9290 ++ __stop___ex_table = .;
9291 ++ } :rodata
9292 ++
9293 ++ NOTES :rodata :note
9294 ++
9295 ++ RO_DATA(PAGE_SIZE)
9296 ++
9297 ++ . = ALIGN(PAGE_SIZE);
9298 ++ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
9299 ++ *(.idt)
9300 ++ . = ALIGN(PAGE_SIZE);
9301 ++ *(.empty_zero_page)
9302 ++ *(.swapper_pg_pmd)
9303 ++ *(.swapper_pg_dir)
9304 ++ }
9305 ++
9306 ++#ifdef CONFIG_PAX_KERNEXEC
9307 ++
9308 ++#ifdef CONFIG_MODULES
9309 ++ . = ALIGN(PAGE_SIZE);
9310 ++ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
9311 ++ MODULES_VADDR = .;
9312 ++ BYTE(0)
9313 ++ . += (6 * 1024 * 1024);
9314 ++ . = ALIGN( PMD_SIZE) - 1;
9315 ++ MODULES_END = .;
9316 ++ }
9317 ++#else
9318 ++ . = ALIGN(PMD_SIZE) - 1;
9319 ++#endif
9320 ++
9321 ++#endif
9322 ++
9323 ++ /* writeable */
9324 ++ . = ALIGN(PAGE_SIZE);
9325 ++ .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
9326 ++ _data = .;
9327 ++ DATA_DATA
9328 ++ CONSTRUCTORS
9329 ++ } :data
9330 ++
9331 ++ . = ALIGN(PAGE_SIZE);
9332 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
9333 ++ __nosave_begin = .;
9334 ++ *(.data.nosave)
9335 ++ . = ALIGN(PAGE_SIZE);
9336 ++ __nosave_end = .;
9337 ++ }
9338 ++
9339 ++ . = ALIGN(PAGE_SIZE);
9340 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
9341 ++ *(.data.page_aligned)
9342 ++ }
9343 ++
9344 ++ . = ALIGN(32);
9345 ++ .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
9346 ++ *(.data.cacheline_aligned)
9347 ++ }
9348 ++
9349 ++ /* rarely changed data like cpu maps */
9350 ++ . = ALIGN(32);
9351 ++ .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
9352 ++ *(.data.read_mostly)
9353 ++ _edata = .; /* End of data section */
9354 ++ }
9355 ++
9356 ++ . = ALIGN(THREAD_SIZE); /* init_task */
9357 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
9358 ++ *(.data.init_task)
9359 ++ }
9360 ++
9361 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
9362 +- __init_end = .;
9363 + __bss_start = .; /* BSS */
9364 + *(.bss.page_aligned)
9365 + *(.bss)
9366 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S
9367 +--- linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-07 12:55:34.000000000 -0500
9368 ++++ linux-2.6.27.10/arch/x86/kernel/vmlinux_64.lds.S 2008-11-18 03:38:44.000000000 -0500
9369 +@@ -16,7 +16,7 @@ jiffies_64 = jiffies;
9370 + _proxy_pda = 1;
9371 + PHDRS {
9372 + text PT_LOAD FLAGS(5); /* R_E */
9373 +- data PT_LOAD FLAGS(7); /* RWE */
9374 ++ data PT_LOAD FLAGS(6); /* RW_ */
9375 + user PT_LOAD FLAGS(7); /* RWE */
9376 + data.init PT_LOAD FLAGS(7); /* RWE */
9377 + note PT_NOTE FLAGS(0); /* ___ */
9378 +@@ -49,17 +49,20 @@ SECTIONS
9379 + __stop___ex_table = .;
9380 + } :text = 0x9090
9381 +
9382 +- RODATA
9383 ++ RO_DATA(PAGE_SIZE)
9384 +
9385 ++#ifdef CONFIG_PAX_KERNEXEC
9386 ++ . = ALIGN(2*1024*1024); /* Align data segment to PMD size boundary */
9387 ++#else
9388 + . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
9389 ++#endif
9390 + /* Data */
9391 ++ _data = .;
9392 + .data : AT(ADDR(.data) - LOAD_OFFSET) {
9393 + DATA_DATA
9394 + CONSTRUCTORS
9395 + } :data
9396 +
9397 +- _edata = .; /* End of data section */
9398 +-
9399 + . = ALIGN(PAGE_SIZE);
9400 + . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
9401 + .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
9402 +@@ -70,9 +73,27 @@ SECTIONS
9403 + *(.data.read_mostly)
9404 + }
9405 +
9406 ++ . = ALIGN(THREAD_SIZE); /* init_task */
9407 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
9408 ++ *(.data.init_task)
9409 ++ }
9410 ++
9411 ++ . = ALIGN(PAGE_SIZE);
9412 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
9413 ++ *(.data.page_aligned)
9414 ++ }
9415 ++
9416 ++ . = ALIGN(PAGE_SIZE);
9417 ++ __nosave_begin = .;
9418 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
9419 ++ . = ALIGN(PAGE_SIZE);
9420 ++ __nosave_end = .;
9421 ++
9422 ++ _edata = .; /* End of data section */
9423 ++
9424 + #define VSYSCALL_ADDR (-10*1024*1024)
9425 +-#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
9426 +-#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
9427 ++#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
9428 ++#define VSYSCALL_VIRT_ADDR ((ADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
9429 +
9430 + #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
9431 + #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
9432 +@@ -120,23 +141,13 @@ SECTIONS
9433 + #undef VVIRT_OFFSET
9434 + #undef VVIRT
9435 +
9436 +- . = ALIGN(THREAD_SIZE); /* init_task */
9437 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
9438 +- *(.data.init_task)
9439 +- }:data.init
9440 +-
9441 +- . = ALIGN(PAGE_SIZE);
9442 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
9443 +- *(.data.page_aligned)
9444 +- }
9445 +-
9446 + /* might get freed after init */
9447 + . = ALIGN(PAGE_SIZE);
9448 + __smp_alt_begin = .;
9449 + __smp_locks = .;
9450 + .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
9451 + *(.smp_locks)
9452 +- }
9453 ++ } :data.init
9454 + __smp_locks_end = .;
9455 + . = ALIGN(PAGE_SIZE);
9456 + __smp_alt_end = .;
9457 +@@ -213,16 +224,11 @@ SECTIONS
9458 + . = ALIGN(PAGE_SIZE);
9459 + __init_end = .;
9460 +
9461 +- . = ALIGN(PAGE_SIZE);
9462 +- __nosave_begin = .;
9463 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
9464 +- . = ALIGN(PAGE_SIZE);
9465 +- __nosave_end = .;
9466 +-
9467 + __bss_start = .; /* BSS */
9468 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
9469 + *(.bss.page_aligned)
9470 + *(.bss)
9471 ++ . = ALIGN(2*1024*1024);
9472 + }
9473 + __bss_stop = .;
9474 +
9475 +diff -urNp linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c
9476 +--- linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-07 12:55:34.000000000 -0500
9477 ++++ linux-2.6.27.10/arch/x86/kernel/vsyscall_64.c 2008-11-18 03:38:44.000000000 -0500
9478 +@@ -236,13 +236,13 @@ static ctl_table kernel_table2[] = {
9479 + .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int),
9480 + .mode = 0644,
9481 + .proc_handler = vsyscall_sysctl_change },
9482 +- {}
9483 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
9484 + };
9485 +
9486 + static ctl_table kernel_root_table2[] = {
9487 + { .ctl_name = CTL_KERN, .procname = "kernel", .mode = 0555,
9488 + .child = kernel_table2 },
9489 +- {}
9490 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
9491 + };
9492 + #endif
9493 +
9494 +diff -urNp linux-2.6.27.10/arch/x86/kvm/svm.c linux-2.6.27.10/arch/x86/kvm/svm.c
9495 +--- linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-07 12:55:34.000000000 -0500
9496 ++++ linux-2.6.27.10/arch/x86/kvm/svm.c 2008-11-18 03:38:44.000000000 -0500
9497 +@@ -1515,7 +1515,19 @@ static void reload_tss(struct kvm_vcpu *
9498 + int cpu = raw_smp_processor_id();
9499 +
9500 + struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
9501 ++
9502 ++#ifdef CONFIG_PAX_KERNEXEC
9503 ++ unsigned long cr0;
9504 ++
9505 ++ pax_open_kernel(cr0);
9506 ++#endif
9507 ++
9508 + svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
9509 ++
9510 ++#ifdef CONFIG_PAX_KERNEXEC
9511 ++ pax_close_kernel(cr0);
9512 ++#endif
9513 ++
9514 + load_TR_desc();
9515 + }
9516 +
9517 +diff -urNp linux-2.6.27.10/arch/x86/kvm/vmx.c linux-2.6.27.10/arch/x86/kvm/vmx.c
9518 +--- linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-07 12:55:34.000000000 -0500
9519 ++++ linux-2.6.27.10/arch/x86/kvm/vmx.c 2008-11-18 03:38:44.000000000 -0500
9520 +@@ -115,7 +115,7 @@ static struct vmcs_config {
9521 + u32 vmentry_ctrl;
9522 + } vmcs_config;
9523 +
9524 +-struct vmx_capability {
9525 ++static struct vmx_capability {
9526 + u32 ept;
9527 + u32 vpid;
9528 + } vmx_capability;
9529 +@@ -484,9 +484,23 @@ static void reload_tss(void)
9530 + struct descriptor_table gdt;
9531 + struct desc_struct *descs;
9532 +
9533 ++#ifdef CONFIG_PAX_KERNEXEC
9534 ++ unsigned long cr0;
9535 ++#endif
9536 ++
9537 + kvm_get_gdt(&gdt);
9538 + descs = (void *)gdt.base;
9539 ++
9540 ++#ifdef CONFIG_PAX_KERNEXEC
9541 ++ pax_open_kernel(cr0);
9542 ++#endif
9543 ++
9544 + descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
9545 ++
9546 ++#ifdef CONFIG_PAX_KERNEXEC
9547 ++ pax_close_kernel(cr0);
9548 ++#endif
9549 ++
9550 + load_TR_desc();
9551 + }
9552 +
9553 +@@ -3069,7 +3083,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
9554 + (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
9555 + (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS)) == 0;
9556 +
9557 +- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
9558 ++ asm("mov %0, %%ds; mov %0, %%es" : : "r"(__KERNEL_DS));
9559 + vmx->launched = 1;
9560 +
9561 + intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
9562 +diff -urNp linux-2.6.27.10/arch/x86/kvm/x86.c linux-2.6.27.10/arch/x86/kvm/x86.c
9563 +--- linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-07 12:55:34.000000000 -0500
9564 ++++ linux-2.6.27.10/arch/x86/kvm/x86.c 2008-11-18 03:38:44.000000000 -0500
9565 +@@ -63,35 +63,35 @@ static int kvm_dev_ioctl_get_supported_c
9566 + struct kvm_x86_ops *kvm_x86_ops;
9567 +
9568 + struct kvm_stats_debugfs_item debugfs_entries[] = {
9569 +- { "pf_fixed", VCPU_STAT(pf_fixed) },
9570 +- { "pf_guest", VCPU_STAT(pf_guest) },
9571 +- { "tlb_flush", VCPU_STAT(tlb_flush) },
9572 +- { "invlpg", VCPU_STAT(invlpg) },
9573 +- { "exits", VCPU_STAT(exits) },
9574 +- { "io_exits", VCPU_STAT(io_exits) },
9575 +- { "mmio_exits", VCPU_STAT(mmio_exits) },
9576 +- { "signal_exits", VCPU_STAT(signal_exits) },
9577 +- { "irq_window", VCPU_STAT(irq_window_exits) },
9578 +- { "nmi_window", VCPU_STAT(nmi_window_exits) },
9579 +- { "halt_exits", VCPU_STAT(halt_exits) },
9580 +- { "halt_wakeup", VCPU_STAT(halt_wakeup) },
9581 +- { "hypercalls", VCPU_STAT(hypercalls) },
9582 +- { "request_irq", VCPU_STAT(request_irq_exits) },
9583 +- { "irq_exits", VCPU_STAT(irq_exits) },
9584 +- { "host_state_reload", VCPU_STAT(host_state_reload) },
9585 +- { "efer_reload", VCPU_STAT(efer_reload) },
9586 +- { "fpu_reload", VCPU_STAT(fpu_reload) },
9587 +- { "insn_emulation", VCPU_STAT(insn_emulation) },
9588 +- { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
9589 +- { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
9590 +- { "mmu_pte_write", VM_STAT(mmu_pte_write) },
9591 +- { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
9592 +- { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
9593 +- { "mmu_flooded", VM_STAT(mmu_flooded) },
9594 +- { "mmu_recycled", VM_STAT(mmu_recycled) },
9595 +- { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
9596 +- { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
9597 +- { "largepages", VM_STAT(lpages) },
9598 ++ { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
9599 ++ { "pf_guest", VCPU_STAT(pf_guest), NULL },
9600 ++ { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
9601 ++ { "invlpg", VCPU_STAT(invlpg), NULL },
9602 ++ { "exits", VCPU_STAT(exits), NULL },
9603 ++ { "io_exits", VCPU_STAT(io_exits), NULL },
9604 ++ { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
9605 ++ { "signal_exits", VCPU_STAT(signal_exits), NULL },
9606 ++ { "irq_window", VCPU_STAT(irq_window_exits), NULL },
9607 ++ { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
9608 ++ { "halt_exits", VCPU_STAT(halt_exits), NULL },
9609 ++ { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
9610 ++ { "hypercalls", VCPU_STAT(hypercalls), NULL },
9611 ++ { "request_irq", VCPU_STAT(request_irq_exits), NULL },
9612 ++ { "irq_exits", VCPU_STAT(irq_exits), NULL },
9613 ++ { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
9614 ++ { "efer_reload", VCPU_STAT(efer_reload), NULL },
9615 ++ { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
9616 ++ { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
9617 ++ { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
9618 ++ { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
9619 ++ { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
9620 ++ { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
9621 ++ { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
9622 ++ { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
9623 ++ { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
9624 ++ { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
9625 ++ { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
9626 ++ { "largepages", VM_STAT(lpages), NULL },
9627 + { NULL }
9628 + };
9629 +
9630 +@@ -1274,7 +1274,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
9631 + static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
9632 + struct kvm_interrupt *irq)
9633 + {
9634 +- if (irq->irq < 0 || irq->irq >= 256)
9635 ++ if (irq->irq >= 256)
9636 + return -EINVAL;
9637 + if (irqchip_in_kernel(vcpu->kvm))
9638 + return -ENXIO;
9639 +diff -urNp linux-2.6.27.10/arch/x86/lib/checksum_32.S linux-2.6.27.10/arch/x86/lib/checksum_32.S
9640 +--- linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-07 12:55:34.000000000 -0500
9641 ++++ linux-2.6.27.10/arch/x86/lib/checksum_32.S 2008-11-18 03:38:44.000000000 -0500
9642 +@@ -28,7 +28,8 @@
9643 + #include <linux/linkage.h>
9644 + #include <asm/dwarf2.h>
9645 + #include <asm/errno.h>
9646 +-
9647 ++#include <asm/segment.h>
9648 ++
9649 + /*
9650 + * computes a partial checksum, e.g. for TCP/UDP fragments
9651 + */
9652 +@@ -304,9 +305,22 @@ unsigned int csum_partial_copy_generic (
9653 +
9654 + #define ARGBASE 16
9655 + #define FP 12
9656 +-
9657 +-ENTRY(csum_partial_copy_generic)
9658 ++
9659 ++ENTRY(csum_partial_copy_generic_to_user)
9660 + CFI_STARTPROC
9661 ++ pushl $(__USER_DS)
9662 ++ CFI_ADJUST_CFA_OFFSET 4
9663 ++ popl %es
9664 ++ CFI_ADJUST_CFA_OFFSET -4
9665 ++ jmp csum_partial_copy_generic
9666 ++
9667 ++ENTRY(csum_partial_copy_generic_from_user)
9668 ++ pushl $(__USER_DS)
9669 ++ CFI_ADJUST_CFA_OFFSET 4
9670 ++ popl %ds
9671 ++ CFI_ADJUST_CFA_OFFSET -4
9672 ++
9673 ++ENTRY(csum_partial_copy_generic)
9674 + subl $4,%esp
9675 + CFI_ADJUST_CFA_OFFSET 4
9676 + pushl %edi
9677 +@@ -331,7 +345,7 @@ ENTRY(csum_partial_copy_generic)
9678 + jmp 4f
9679 + SRC(1: movw (%esi), %bx )
9680 + addl $2, %esi
9681 +-DST( movw %bx, (%edi) )
9682 ++DST( movw %bx, %es:(%edi) )
9683 + addl $2, %edi
9684 + addw %bx, %ax
9685 + adcl $0, %eax
9686 +@@ -343,30 +357,30 @@ DST( movw %bx, (%edi) )
9687 + SRC(1: movl (%esi), %ebx )
9688 + SRC( movl 4(%esi), %edx )
9689 + adcl %ebx, %eax
9690 +-DST( movl %ebx, (%edi) )
9691 ++DST( movl %ebx, %es:(%edi) )
9692 + adcl %edx, %eax
9693 +-DST( movl %edx, 4(%edi) )
9694 ++DST( movl %edx, %es:4(%edi) )
9695 +
9696 + SRC( movl 8(%esi), %ebx )
9697 + SRC( movl 12(%esi), %edx )
9698 + adcl %ebx, %eax
9699 +-DST( movl %ebx, 8(%edi) )
9700 ++DST( movl %ebx, %es:8(%edi) )
9701 + adcl %edx, %eax
9702 +-DST( movl %edx, 12(%edi) )
9703 ++DST( movl %edx, %es:12(%edi) )
9704 +
9705 + SRC( movl 16(%esi), %ebx )
9706 + SRC( movl 20(%esi), %edx )
9707 + adcl %ebx, %eax
9708 +-DST( movl %ebx, 16(%edi) )
9709 ++DST( movl %ebx, %es:16(%edi) )
9710 + adcl %edx, %eax
9711 +-DST( movl %edx, 20(%edi) )
9712 ++DST( movl %edx, %es:20(%edi) )
9713 +
9714 + SRC( movl 24(%esi), %ebx )
9715 + SRC( movl 28(%esi), %edx )
9716 + adcl %ebx, %eax
9717 +-DST( movl %ebx, 24(%edi) )
9718 ++DST( movl %ebx, %es:24(%edi) )
9719 + adcl %edx, %eax
9720 +-DST( movl %edx, 28(%edi) )
9721 ++DST( movl %edx, %es:28(%edi) )
9722 +
9723 + lea 32(%esi), %esi
9724 + lea 32(%edi), %edi
9725 +@@ -380,7 +394,7 @@ DST( movl %edx, 28(%edi) )
9726 + shrl $2, %edx # This clears CF
9727 + SRC(3: movl (%esi), %ebx )
9728 + adcl %ebx, %eax
9729 +-DST( movl %ebx, (%edi) )
9730 ++DST( movl %ebx, %es:(%edi) )
9731 + lea 4(%esi), %esi
9732 + lea 4(%edi), %edi
9733 + dec %edx
9734 +@@ -392,12 +406,12 @@ DST( movl %ebx, (%edi) )
9735 + jb 5f
9736 + SRC( movw (%esi), %cx )
9737 + leal 2(%esi), %esi
9738 +-DST( movw %cx, (%edi) )
9739 ++DST( movw %cx, %es:(%edi) )
9740 + leal 2(%edi), %edi
9741 + je 6f
9742 + shll $16,%ecx
9743 + SRC(5: movb (%esi), %cl )
9744 +-DST( movb %cl, (%edi) )
9745 ++DST( movb %cl, %es:(%edi) )
9746 + 6: addl %ecx, %eax
9747 + adcl $0, %eax
9748 + 7:
9749 +@@ -408,7 +422,7 @@ DST( movb %cl, (%edi) )
9750 +
9751 + 6001:
9752 + movl ARGBASE+20(%esp), %ebx # src_err_ptr
9753 +- movl $-EFAULT, (%ebx)
9754 ++ movl $-EFAULT, %ss:(%ebx)
9755 +
9756 + # zero the complete destination - computing the rest
9757 + # is too much work
9758 +@@ -421,11 +435,19 @@ DST( movb %cl, (%edi) )
9759 +
9760 + 6002:
9761 + movl ARGBASE+24(%esp), %ebx # dst_err_ptr
9762 +- movl $-EFAULT,(%ebx)
9763 ++ movl $-EFAULT,%ss:(%ebx)
9764 + jmp 5000b
9765 +
9766 + .previous
9767 +
9768 ++ pushl %ss
9769 ++ CFI_ADJUST_CFA_OFFSET 4
9770 ++ popl %ds
9771 ++ CFI_ADJUST_CFA_OFFSET -4
9772 ++ pushl %ss
9773 ++ CFI_ADJUST_CFA_OFFSET 4
9774 ++ popl %es
9775 ++ CFI_ADJUST_CFA_OFFSET -4
9776 + popl %ebx
9777 + CFI_ADJUST_CFA_OFFSET -4
9778 + CFI_RESTORE ebx
9779 +@@ -439,26 +461,41 @@ DST( movb %cl, (%edi) )
9780 + CFI_ADJUST_CFA_OFFSET -4
9781 + ret
9782 + CFI_ENDPROC
9783 +-ENDPROC(csum_partial_copy_generic)
9784 ++ENDPROC(csum_partial_copy_generic_to_user)
9785 +
9786 + #else
9787 +
9788 + /* Version for PentiumII/PPro */
9789 +
9790 + #define ROUND1(x) \
9791 ++ nop; nop; nop; \
9792 + SRC(movl x(%esi), %ebx ) ; \
9793 + addl %ebx, %eax ; \
9794 +- DST(movl %ebx, x(%edi) ) ;
9795 ++ DST(movl %ebx, %es:x(%edi)) ;
9796 +
9797 + #define ROUND(x) \
9798 ++ nop; nop; nop; \
9799 + SRC(movl x(%esi), %ebx ) ; \
9800 + adcl %ebx, %eax ; \
9801 +- DST(movl %ebx, x(%edi) ) ;
9802 ++ DST(movl %ebx, %es:x(%edi)) ;
9803 +
9804 + #define ARGBASE 12
9805 +-
9806 +-ENTRY(csum_partial_copy_generic)
9807 ++
9808 ++ENTRY(csum_partial_copy_generic_to_user)
9809 + CFI_STARTPROC
9810 ++ pushl $(__USER_DS)
9811 ++ CFI_ADJUST_CFA_OFFSET 4
9812 ++ popl %es
9813 ++ CFI_ADJUST_CFA_OFFSET -4
9814 ++ jmp csum_partial_copy_generic
9815 ++
9816 ++ENTRY(csum_partial_copy_generic_from_user)
9817 ++ pushl $(__USER_DS)
9818 ++ CFI_ADJUST_CFA_OFFSET 4
9819 ++ popl %ds
9820 ++ CFI_ADJUST_CFA_OFFSET -4
9821 ++
9822 ++ENTRY(csum_partial_copy_generic)
9823 + pushl %ebx
9824 + CFI_ADJUST_CFA_OFFSET 4
9825 + CFI_REL_OFFSET ebx, 0
9826 +@@ -482,7 +519,7 @@ ENTRY(csum_partial_copy_generic)
9827 + subl %ebx, %edi
9828 + lea -1(%esi),%edx
9829 + andl $-32,%edx
9830 +- lea 3f(%ebx,%ebx), %ebx
9831 ++ lea 3f(%ebx,%ebx,2), %ebx
9832 + testl %esi, %esi
9833 + jmp *%ebx
9834 + 1: addl $64,%esi
9835 +@@ -503,19 +540,19 @@ ENTRY(csum_partial_copy_generic)
9836 + jb 5f
9837 + SRC( movw (%esi), %dx )
9838 + leal 2(%esi), %esi
9839 +-DST( movw %dx, (%edi) )
9840 ++DST( movw %dx, %es:(%edi) )
9841 + leal 2(%edi), %edi
9842 + je 6f
9843 + shll $16,%edx
9844 + 5:
9845 + SRC( movb (%esi), %dl )
9846 +-DST( movb %dl, (%edi) )
9847 ++DST( movb %dl, %es:(%edi) )
9848 + 6: addl %edx, %eax
9849 + adcl $0, %eax
9850 + 7:
9851 + .section .fixup, "ax"
9852 + 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
9853 +- movl $-EFAULT, (%ebx)
9854 ++ movl $-EFAULT, %ss:(%ebx)
9855 + # zero the complete destination (computing the rest is too much work)
9856 + movl ARGBASE+8(%esp),%edi # dst
9857 + movl ARGBASE+12(%esp),%ecx # len
9858 +@@ -523,10 +560,18 @@ DST( movb %dl, (%edi) )
9859 + rep; stosb
9860 + jmp 7b
9861 + 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
9862 +- movl $-EFAULT, (%ebx)
9863 ++ movl $-EFAULT, %ss:(%ebx)
9864 + jmp 7b
9865 + .previous
9866 +
9867 ++ pushl %ss
9868 ++ CFI_ADJUST_CFA_OFFSET 4
9869 ++ popl %ds
9870 ++ CFI_ADJUST_CFA_OFFSET -4
9871 ++ pushl %ss
9872 ++ CFI_ADJUST_CFA_OFFSET 4
9873 ++ popl %es
9874 ++ CFI_ADJUST_CFA_OFFSET -4
9875 + popl %esi
9876 + CFI_ADJUST_CFA_OFFSET -4
9877 + CFI_RESTORE esi
9878 +@@ -538,7 +583,7 @@ DST( movb %dl, (%edi) )
9879 + CFI_RESTORE ebx
9880 + ret
9881 + CFI_ENDPROC
9882 +-ENDPROC(csum_partial_copy_generic)
9883 ++ENDPROC(csum_partial_copy_generic_to_user)
9884 +
9885 + #undef ROUND
9886 + #undef ROUND1
9887 +diff -urNp linux-2.6.27.10/arch/x86/lib/clear_page_64.S linux-2.6.27.10/arch/x86/lib/clear_page_64.S
9888 +--- linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-07 12:55:34.000000000 -0500
9889 ++++ linux-2.6.27.10/arch/x86/lib/clear_page_64.S 2008-11-18 03:38:44.000000000 -0500
9890 +@@ -44,7 +44,7 @@ ENDPROC(clear_page)
9891 +
9892 + #include <asm/cpufeature.h>
9893 +
9894 +- .section .altinstr_replacement,"ax"
9895 ++ .section .altinstr_replacement,"a"
9896 + 1: .byte 0xeb /* jmp <disp8> */
9897 + .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
9898 + 2:
9899 +diff -urNp linux-2.6.27.10/arch/x86/lib/copy_page_64.S linux-2.6.27.10/arch/x86/lib/copy_page_64.S
9900 +--- linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-07 12:55:34.000000000 -0500
9901 ++++ linux-2.6.27.10/arch/x86/lib/copy_page_64.S 2008-11-18 03:38:44.000000000 -0500
9902 +@@ -104,7 +104,7 @@ ENDPROC(copy_page)
9903 +
9904 + #include <asm/cpufeature.h>
9905 +
9906 +- .section .altinstr_replacement,"ax"
9907 ++ .section .altinstr_replacement,"a"
9908 + 1: .byte 0xeb /* jmp <disp8> */
9909 + .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
9910 + 2:
9911 +diff -urNp linux-2.6.27.10/arch/x86/lib/copy_user_64.S linux-2.6.27.10/arch/x86/lib/copy_user_64.S
9912 +--- linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-07 12:55:34.000000000 -0500
9913 ++++ linux-2.6.27.10/arch/x86/lib/copy_user_64.S 2008-11-18 03:38:44.000000000 -0500
9914 +@@ -21,7 +21,7 @@
9915 + .byte 0xe9 /* 32bit jump */
9916 + .long \orig-1f /* by default jump to orig */
9917 + 1:
9918 +- .section .altinstr_replacement,"ax"
9919 ++ .section .altinstr_replacement,"a"
9920 + 2: .byte 0xe9 /* near jump with 32bit immediate */
9921 + .long \alt-1b /* offset */ /* or alternatively to alt */
9922 + .previous
9923 +@@ -106,6 +106,8 @@ ENDPROC(__copy_from_user_inatomic)
9924 + ENTRY(bad_from_user)
9925 + bad_from_user:
9926 + CFI_STARTPROC
9927 ++ testl %edx,%edx
9928 ++ js bad_to_user
9929 + movl %edx,%ecx
9930 + xorl %eax,%eax
9931 + rep
9932 +diff -urNp linux-2.6.27.10/arch/x86/lib/getuser.S linux-2.6.27.10/arch/x86/lib/getuser.S
9933 +--- linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-07 12:55:34.000000000 -0500
9934 ++++ linux-2.6.27.10/arch/x86/lib/getuser.S 2008-11-18 03:38:44.000000000 -0500
9935 +@@ -33,6 +33,7 @@
9936 + #include <asm/asm-offsets.h>
9937 + #include <asm/thread_info.h>
9938 + #include <asm/asm.h>
9939 ++#include <asm/segment.h>
9940 +
9941 + .text
9942 + ENTRY(__get_user_1)
9943 +@@ -40,7 +41,19 @@ ENTRY(__get_user_1)
9944 + GET_THREAD_INFO(%_ASM_DX)
9945 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
9946 + jae bad_get_user
9947 ++
9948 ++#ifdef CONFIG_X86_32
9949 ++ pushl $(__USER_DS)
9950 ++ popl %ds
9951 ++#endif
9952 ++
9953 + 1: movzb (%_ASM_AX),%edx
9954 ++
9955 ++#ifdef CONFIG_X86_32
9956 ++ pushl %ss
9957 ++ pop %ds
9958 ++#endif
9959 ++
9960 + xor %eax,%eax
9961 + ret
9962 + CFI_ENDPROC
9963 +@@ -53,7 +66,19 @@ ENTRY(__get_user_2)
9964 + GET_THREAD_INFO(%_ASM_DX)
9965 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
9966 + jae bad_get_user
9967 ++
9968 ++#ifdef CONFIG_X86_32
9969 ++ pushl $(__USER_DS)
9970 ++ popl %ds
9971 ++#endif
9972 ++
9973 + 2: movzwl -1(%_ASM_AX),%edx
9974 ++
9975 ++#ifdef CONFIG_X86_32
9976 ++ pushl %ss
9977 ++ pop %ds
9978 ++#endif
9979 ++
9980 + xor %eax,%eax
9981 + ret
9982 + CFI_ENDPROC
9983 +@@ -66,7 +91,19 @@ ENTRY(__get_user_4)
9984 + GET_THREAD_INFO(%_ASM_DX)
9985 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
9986 + jae bad_get_user
9987 ++
9988 ++#ifdef CONFIG_X86_32
9989 ++ pushl $(__USER_DS)
9990 ++ popl %ds
9991 ++#endif
9992 ++
9993 + 3: mov -3(%_ASM_AX),%edx
9994 ++
9995 ++#ifdef CONFIG_X86_32
9996 ++ pushl %ss
9997 ++ pop %ds
9998 ++#endif
9999 ++
10000 + xor %eax,%eax
10001 + ret
10002 + CFI_ENDPROC
10003 +@@ -89,6 +126,12 @@ ENDPROC(__get_user_8)
10004 +
10005 + bad_get_user:
10006 + CFI_STARTPROC
10007 ++
10008 ++#ifdef CONFIG_X86_32
10009 ++ pushl %ss
10010 ++ pop %ds
10011 ++#endif
10012 ++
10013 + xor %edx,%edx
10014 + mov $(-EFAULT),%_ASM_AX
10015 + ret
10016 +diff -urNp linux-2.6.27.10/arch/x86/lib/memcpy_64.S linux-2.6.27.10/arch/x86/lib/memcpy_64.S
10017 +--- linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-07 12:55:34.000000000 -0500
10018 ++++ linux-2.6.27.10/arch/x86/lib/memcpy_64.S 2008-11-18 03:38:44.000000000 -0500
10019 +@@ -114,7 +114,7 @@ ENDPROC(__memcpy)
10020 + /* Some CPUs run faster using the string copy instructions.
10021 + It is also a lot simpler. Use this when possible */
10022 +
10023 +- .section .altinstr_replacement,"ax"
10024 ++ .section .altinstr_replacement,"a"
10025 + 1: .byte 0xeb /* jmp <disp8> */
10026 + .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
10027 + 2:
10028 +diff -urNp linux-2.6.27.10/arch/x86/lib/memset_64.S linux-2.6.27.10/arch/x86/lib/memset_64.S
10029 +--- linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-07 12:55:34.000000000 -0500
10030 ++++ linux-2.6.27.10/arch/x86/lib/memset_64.S 2008-11-18 03:38:44.000000000 -0500
10031 +@@ -118,7 +118,7 @@ ENDPROC(__memset)
10032 +
10033 + #include <asm/cpufeature.h>
10034 +
10035 +- .section .altinstr_replacement,"ax"
10036 ++ .section .altinstr_replacement,"a"
10037 + 1: .byte 0xeb /* jmp <disp8> */
10038 + .byte (memset_c - memset) - (2f - 1b) /* offset */
10039 + 2:
10040 +diff -urNp linux-2.6.27.10/arch/x86/lib/mmx_32.c linux-2.6.27.10/arch/x86/lib/mmx_32.c
10041 +--- linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-07 12:55:34.000000000 -0500
10042 ++++ linux-2.6.27.10/arch/x86/lib/mmx_32.c 2008-11-18 03:38:44.000000000 -0500
10043 +@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
10044 + {
10045 + void *p;
10046 + int i;
10047 ++ unsigned long cr0;
10048 +
10049 + if (unlikely(in_interrupt()))
10050 + return __memcpy(to, from, len);
10051 +@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
10052 + kernel_fpu_begin();
10053 +
10054 + __asm__ __volatile__ (
10055 +- "1: prefetch (%0)\n" /* This set is 28 bytes */
10056 +- " prefetch 64(%0)\n"
10057 +- " prefetch 128(%0)\n"
10058 +- " prefetch 192(%0)\n"
10059 +- " prefetch 256(%0)\n"
10060 ++ "1: prefetch (%1)\n" /* This set is 28 bytes */
10061 ++ " prefetch 64(%1)\n"
10062 ++ " prefetch 128(%1)\n"
10063 ++ " prefetch 192(%1)\n"
10064 ++ " prefetch 256(%1)\n"
10065 + "2: \n"
10066 + ".section .fixup, \"ax\"\n"
10067 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
10068 ++ "3: \n"
10069 ++
10070 ++#ifdef CONFIG_PAX_KERNEXEC
10071 ++ " movl %%cr0, %0\n"
10072 ++ " movl %0, %%eax\n"
10073 ++ " andl $0xFFFEFFFF, %%eax\n"
10074 ++ " movl %%eax, %%cr0\n"
10075 ++#endif
10076 ++
10077 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
10078 ++
10079 ++#ifdef CONFIG_PAX_KERNEXEC
10080 ++ " movl %0, %%cr0\n"
10081 ++#endif
10082 ++
10083 + " jmp 2b\n"
10084 + ".previous\n"
10085 + _ASM_EXTABLE(1b, 3b)
10086 +- : : "r" (from));
10087 ++ : "=&r" (cr0) : "r" (from) : "ax");
10088 +
10089 + for ( ; i > 5; i--) {
10090 + __asm__ __volatile__ (
10091 +- "1: prefetch 320(%0)\n"
10092 +- "2: movq (%0), %%mm0\n"
10093 +- " movq 8(%0), %%mm1\n"
10094 +- " movq 16(%0), %%mm2\n"
10095 +- " movq 24(%0), %%mm3\n"
10096 +- " movq %%mm0, (%1)\n"
10097 +- " movq %%mm1, 8(%1)\n"
10098 +- " movq %%mm2, 16(%1)\n"
10099 +- " movq %%mm3, 24(%1)\n"
10100 +- " movq 32(%0), %%mm0\n"
10101 +- " movq 40(%0), %%mm1\n"
10102 +- " movq 48(%0), %%mm2\n"
10103 +- " movq 56(%0), %%mm3\n"
10104 +- " movq %%mm0, 32(%1)\n"
10105 +- " movq %%mm1, 40(%1)\n"
10106 +- " movq %%mm2, 48(%1)\n"
10107 +- " movq %%mm3, 56(%1)\n"
10108 ++ "1: prefetch 320(%1)\n"
10109 ++ "2: movq (%1), %%mm0\n"
10110 ++ " movq 8(%1), %%mm1\n"
10111 ++ " movq 16(%1), %%mm2\n"
10112 ++ " movq 24(%1), %%mm3\n"
10113 ++ " movq %%mm0, (%2)\n"
10114 ++ " movq %%mm1, 8(%2)\n"
10115 ++ " movq %%mm2, 16(%2)\n"
10116 ++ " movq %%mm3, 24(%2)\n"
10117 ++ " movq 32(%1), %%mm0\n"
10118 ++ " movq 40(%1), %%mm1\n"
10119 ++ " movq 48(%1), %%mm2\n"
10120 ++ " movq 56(%1), %%mm3\n"
10121 ++ " movq %%mm0, 32(%2)\n"
10122 ++ " movq %%mm1, 40(%2)\n"
10123 ++ " movq %%mm2, 48(%2)\n"
10124 ++ " movq %%mm3, 56(%2)\n"
10125 + ".section .fixup, \"ax\"\n"
10126 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
10127 ++ "3:\n"
10128 ++
10129 ++#ifdef CONFIG_PAX_KERNEXEC
10130 ++ " movl %%cr0, %0\n"
10131 ++ " movl %0, %%eax\n"
10132 ++ " andl $0xFFFEFFFF, %%eax\n"
10133 ++ " movl %%eax, %%cr0\n"
10134 ++#endif
10135 ++
10136 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
10137 ++
10138 ++#ifdef CONFIG_PAX_KERNEXEC
10139 ++ " movl %0, %%cr0\n"
10140 ++#endif
10141 ++
10142 + " jmp 2b\n"
10143 + ".previous\n"
10144 + _ASM_EXTABLE(1b, 3b)
10145 +- : : "r" (from), "r" (to) : "memory");
10146 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
10147 +
10148 + from += 64;
10149 + to += 64;
10150 +@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
10151 + static void fast_copy_page(void *to, void *from)
10152 + {
10153 + int i;
10154 ++ unsigned long cr0;
10155 +
10156 + kernel_fpu_begin();
10157 +
10158 +@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
10159 + * but that is for later. -AV
10160 + */
10161 + __asm__ __volatile__(
10162 +- "1: prefetch (%0)\n"
10163 +- " prefetch 64(%0)\n"
10164 +- " prefetch 128(%0)\n"
10165 +- " prefetch 192(%0)\n"
10166 +- " prefetch 256(%0)\n"
10167 ++ "1: prefetch (%1)\n"
10168 ++ " prefetch 64(%1)\n"
10169 ++ " prefetch 128(%1)\n"
10170 ++ " prefetch 192(%1)\n"
10171 ++ " prefetch 256(%1)\n"
10172 + "2: \n"
10173 + ".section .fixup, \"ax\"\n"
10174 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
10175 ++ "3: \n"
10176 ++
10177 ++#ifdef CONFIG_PAX_KERNEXEC
10178 ++ " movl %%cr0, %0\n"
10179 ++ " movl %0, %%eax\n"
10180 ++ " andl $0xFFFEFFFF, %%eax\n"
10181 ++ " movl %%eax, %%cr0\n"
10182 ++#endif
10183 ++
10184 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
10185 ++
10186 ++#ifdef CONFIG_PAX_KERNEXEC
10187 ++ " movl %0, %%cr0\n"
10188 ++#endif
10189 ++
10190 + " jmp 2b\n"
10191 + ".previous\n"
10192 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
10193 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
10194 +
10195 + for (i = 0; i < (4096-320)/64; i++) {
10196 + __asm__ __volatile__ (
10197 +- "1: prefetch 320(%0)\n"
10198 +- "2: movq (%0), %%mm0\n"
10199 +- " movntq %%mm0, (%1)\n"
10200 +- " movq 8(%0), %%mm1\n"
10201 +- " movntq %%mm1, 8(%1)\n"
10202 +- " movq 16(%0), %%mm2\n"
10203 +- " movntq %%mm2, 16(%1)\n"
10204 +- " movq 24(%0), %%mm3\n"
10205 +- " movntq %%mm3, 24(%1)\n"
10206 +- " movq 32(%0), %%mm4\n"
10207 +- " movntq %%mm4, 32(%1)\n"
10208 +- " movq 40(%0), %%mm5\n"
10209 +- " movntq %%mm5, 40(%1)\n"
10210 +- " movq 48(%0), %%mm6\n"
10211 +- " movntq %%mm6, 48(%1)\n"
10212 +- " movq 56(%0), %%mm7\n"
10213 +- " movntq %%mm7, 56(%1)\n"
10214 ++ "1: prefetch 320(%1)\n"
10215 ++ "2: movq (%1), %%mm0\n"
10216 ++ " movntq %%mm0, (%2)\n"
10217 ++ " movq 8(%1), %%mm1\n"
10218 ++ " movntq %%mm1, 8(%2)\n"
10219 ++ " movq 16(%1), %%mm2\n"
10220 ++ " movntq %%mm2, 16(%2)\n"
10221 ++ " movq 24(%1), %%mm3\n"
10222 ++ " movntq %%mm3, 24(%2)\n"
10223 ++ " movq 32(%1), %%mm4\n"
10224 ++ " movntq %%mm4, 32(%2)\n"
10225 ++ " movq 40(%1), %%mm5\n"
10226 ++ " movntq %%mm5, 40(%2)\n"
10227 ++ " movq 48(%1), %%mm6\n"
10228 ++ " movntq %%mm6, 48(%2)\n"
10229 ++ " movq 56(%1), %%mm7\n"
10230 ++ " movntq %%mm7, 56(%2)\n"
10231 + ".section .fixup, \"ax\"\n"
10232 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
10233 ++ "3:\n"
10234 ++
10235 ++#ifdef CONFIG_PAX_KERNEXEC
10236 ++ " movl %%cr0, %0\n"
10237 ++ " movl %0, %%eax\n"
10238 ++ " andl $0xFFFEFFFF, %%eax\n"
10239 ++ " movl %%eax, %%cr0\n"
10240 ++#endif
10241 ++
10242 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
10243 ++
10244 ++#ifdef CONFIG_PAX_KERNEXEC
10245 ++ " movl %0, %%cr0\n"
10246 ++#endif
10247 ++
10248 + " jmp 2b\n"
10249 + ".previous\n"
10250 +- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
10251 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
10252 +
10253 + from += 64;
10254 + to += 64;
10255 +@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
10256 + static void fast_copy_page(void *to, void *from)
10257 + {
10258 + int i;
10259 ++ unsigned long cr0;
10260 +
10261 + kernel_fpu_begin();
10262 +
10263 + __asm__ __volatile__ (
10264 +- "1: prefetch (%0)\n"
10265 +- " prefetch 64(%0)\n"
10266 +- " prefetch 128(%0)\n"
10267 +- " prefetch 192(%0)\n"
10268 +- " prefetch 256(%0)\n"
10269 ++ "1: prefetch (%1)\n"
10270 ++ " prefetch 64(%1)\n"
10271 ++ " prefetch 128(%1)\n"
10272 ++ " prefetch 192(%1)\n"
10273 ++ " prefetch 256(%1)\n"
10274 + "2: \n"
10275 + ".section .fixup, \"ax\"\n"
10276 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
10277 ++ "3: \n"
10278 ++
10279 ++#ifdef CONFIG_PAX_KERNEXEC
10280 ++ " movl %%cr0, %0\n"
10281 ++ " movl %0, %%eax\n"
10282 ++ " andl $0xFFFEFFFF, %%eax\n"
10283 ++ " movl %%eax, %%cr0\n"
10284 ++#endif
10285 ++
10286 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
10287 ++
10288 ++#ifdef CONFIG_PAX_KERNEXEC
10289 ++ " movl %0, %%cr0\n"
10290 ++#endif
10291 ++
10292 + " jmp 2b\n"
10293 + ".previous\n"
10294 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
10295 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
10296 +
10297 + for (i = 0; i < 4096/64; i++) {
10298 + __asm__ __volatile__ (
10299 +- "1: prefetch 320(%0)\n"
10300 +- "2: movq (%0), %%mm0\n"
10301 +- " movq 8(%0), %%mm1\n"
10302 +- " movq 16(%0), %%mm2\n"
10303 +- " movq 24(%0), %%mm3\n"
10304 +- " movq %%mm0, (%1)\n"
10305 +- " movq %%mm1, 8(%1)\n"
10306 +- " movq %%mm2, 16(%1)\n"
10307 +- " movq %%mm3, 24(%1)\n"
10308 +- " movq 32(%0), %%mm0\n"
10309 +- " movq 40(%0), %%mm1\n"
10310 +- " movq 48(%0), %%mm2\n"
10311 +- " movq 56(%0), %%mm3\n"
10312 +- " movq %%mm0, 32(%1)\n"
10313 +- " movq %%mm1, 40(%1)\n"
10314 +- " movq %%mm2, 48(%1)\n"
10315 +- " movq %%mm3, 56(%1)\n"
10316 ++ "1: prefetch 320(%1)\n"
10317 ++ "2: movq (%1), %%mm0\n"
10318 ++ " movq 8(%1), %%mm1\n"
10319 ++ " movq 16(%1), %%mm2\n"
10320 ++ " movq 24(%1), %%mm3\n"
10321 ++ " movq %%mm0, (%2)\n"
10322 ++ " movq %%mm1, 8(%2)\n"
10323 ++ " movq %%mm2, 16(%2)\n"
10324 ++ " movq %%mm3, 24(%2)\n"
10325 ++ " movq 32(%1), %%mm0\n"
10326 ++ " movq 40(%1), %%mm1\n"
10327 ++ " movq 48(%1), %%mm2\n"
10328 ++ " movq 56(%1), %%mm3\n"
10329 ++ " movq %%mm0, 32(%2)\n"
10330 ++ " movq %%mm1, 40(%2)\n"
10331 ++ " movq %%mm2, 48(%2)\n"
10332 ++ " movq %%mm3, 56(%2)\n"
10333 + ".section .fixup, \"ax\"\n"
10334 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
10335 ++ "3:\n"
10336 ++
10337 ++#ifdef CONFIG_PAX_KERNEXEC
10338 ++ " movl %%cr0, %0\n"
10339 ++ " movl %0, %%eax\n"
10340 ++ " andl $0xFFFEFFFF, %%eax\n"
10341 ++ " movl %%eax, %%cr0\n"
10342 ++#endif
10343 ++
10344 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
10345 ++
10346 ++#ifdef CONFIG_PAX_KERNEXEC
10347 ++ " movl %0, %%cr0\n"
10348 ++#endif
10349 ++
10350 + " jmp 2b\n"
10351 + ".previous\n"
10352 + _ASM_EXTABLE(1b, 3b)
10353 +- : : "r" (from), "r" (to) : "memory");
10354 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
10355 +
10356 + from += 64;
10357 + to += 64;
10358 +diff -urNp linux-2.6.27.10/arch/x86/lib/putuser.S linux-2.6.27.10/arch/x86/lib/putuser.S
10359 +--- linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-07 12:55:34.000000000 -0500
10360 ++++ linux-2.6.27.10/arch/x86/lib/putuser.S 2008-11-18 03:38:44.000000000 -0500
10361 +@@ -15,6 +15,7 @@
10362 + #include <asm/thread_info.h>
10363 + #include <asm/errno.h>
10364 + #include <asm/asm.h>
10365 ++#include <asm/segment.h>
10366 +
10367 +
10368 + /*
10369 +@@ -39,7 +40,19 @@ ENTRY(__put_user_1)
10370 + ENTER
10371 + cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
10372 + jae bad_put_user
10373 ++
10374 ++#ifdef CONFIG_X86_32
10375 ++ pushl $(__USER_DS)
10376 ++ popl %ds
10377 ++#endif
10378 ++
10379 + 1: movb %al,(%_ASM_CX)
10380 ++
10381 ++#ifdef CONFIG_X86_32
10382 ++ pushl %ss
10383 ++ popl %ds
10384 ++#endif
10385 ++
10386 + xor %eax,%eax
10387 + EXIT
10388 + ENDPROC(__put_user_1)
10389 +@@ -50,7 +63,19 @@ ENTRY(__put_user_2)
10390 + sub $1,%_ASM_BX
10391 + cmp %_ASM_BX,%_ASM_CX
10392 + jae bad_put_user
10393 ++
10394 ++#ifdef CONFIG_X86_32
10395 ++ pushl $(__USER_DS)
10396 ++ popl %ds
10397 ++#endif
10398 ++
10399 + 2: movw %ax,(%_ASM_CX)
10400 ++
10401 ++#ifdef CONFIG_X86_32
10402 ++ pushl %ss
10403 ++ popl %ds
10404 ++#endif
10405 ++
10406 + xor %eax,%eax
10407 + EXIT
10408 + ENDPROC(__put_user_2)
10409 +@@ -61,7 +86,19 @@ ENTRY(__put_user_4)
10410 + sub $3,%_ASM_BX
10411 + cmp %_ASM_BX,%_ASM_CX
10412 + jae bad_put_user
10413 ++
10414 ++#ifdef CONFIG_X86_32
10415 ++ pushl $(__USER_DS)
10416 ++ popl %ds
10417 ++#endif
10418 ++
10419 + 3: movl %eax,(%_ASM_CX)
10420 ++
10421 ++#ifdef CONFIG_X86_32
10422 ++ pushl %ss
10423 ++ popl %ds
10424 ++#endif
10425 ++
10426 + xor %eax,%eax
10427 + EXIT
10428 + ENDPROC(__put_user_4)
10429 +@@ -72,16 +109,34 @@ ENTRY(__put_user_8)
10430 + sub $7,%_ASM_BX
10431 + cmp %_ASM_BX,%_ASM_CX
10432 + jae bad_put_user
10433 ++
10434 ++#ifdef CONFIG_X86_32
10435 ++ pushl $(__USER_DS)
10436 ++ popl %ds
10437 ++#endif
10438 ++
10439 + 4: mov %_ASM_AX,(%_ASM_CX)
10440 + #ifdef CONFIG_X86_32
10441 + 5: movl %edx,4(%_ASM_CX)
10442 + #endif
10443 ++
10444 ++#ifdef CONFIG_X86_32
10445 ++ pushl %ss
10446 ++ popl %ds
10447 ++#endif
10448 ++
10449 + xor %eax,%eax
10450 + EXIT
10451 + ENDPROC(__put_user_8)
10452 +
10453 + bad_put_user:
10454 + CFI_STARTPROC
10455 ++
10456 ++#ifdef CONFIG_X86_32
10457 ++ pushl %ss
10458 ++ popl %ds
10459 ++#endif
10460 ++
10461 + movl $-EFAULT,%eax
10462 + EXIT
10463 + END(bad_put_user)
10464 +diff -urNp linux-2.6.27.10/arch/x86/lib/usercopy_32.c linux-2.6.27.10/arch/x86/lib/usercopy_32.c
10465 +--- linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-07 12:55:34.000000000 -0500
10466 ++++ linux-2.6.27.10/arch/x86/lib/usercopy_32.c 2008-11-18 03:38:44.000000000 -0500
10467 +@@ -29,31 +29,38 @@ static inline int __movsl_is_ok(unsigned
10468 + * Copy a null terminated string from userspace.
10469 + */
10470 +
10471 +-#define __do_strncpy_from_user(dst, src, count, res) \
10472 +-do { \
10473 +- int __d0, __d1, __d2; \
10474 +- might_sleep(); \
10475 +- __asm__ __volatile__( \
10476 +- " testl %1,%1\n" \
10477 +- " jz 2f\n" \
10478 +- "0: lodsb\n" \
10479 +- " stosb\n" \
10480 +- " testb %%al,%%al\n" \
10481 +- " jz 1f\n" \
10482 +- " decl %1\n" \
10483 +- " jnz 0b\n" \
10484 +- "1: subl %1,%0\n" \
10485 +- "2:\n" \
10486 +- ".section .fixup,\"ax\"\n" \
10487 +- "3: movl %5,%0\n" \
10488 +- " jmp 2b\n" \
10489 +- ".previous\n" \
10490 +- _ASM_EXTABLE(0b,3b) \
10491 +- : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
10492 +- "=&D" (__d2) \
10493 +- : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
10494 +- : "memory"); \
10495 +-} while (0)
10496 ++static long __do_strncpy_from_user(char *dst, const char __user *src, long count)
10497 ++{
10498 ++ int __d0, __d1, __d2;
10499 ++ long res = -EFAULT;
10500 ++
10501 ++ might_sleep();
10502 ++ __asm__ __volatile__(
10503 ++ " movw %w10,%%ds\n"
10504 ++ " testl %1,%1\n"
10505 ++ " jz 2f\n"
10506 ++ "0: lodsb\n"
10507 ++ " stosb\n"
10508 ++ " testb %%al,%%al\n"
10509 ++ " jz 1f\n"
10510 ++ " decl %1\n"
10511 ++ " jnz 0b\n"
10512 ++ "1: subl %1,%0\n"
10513 ++ "2:\n"
10514 ++ " pushl %%ss\n"
10515 ++ " popl %%ds\n"
10516 ++ ".section .fixup,\"ax\"\n"
10517 ++ "3: movl %5,%0\n"
10518 ++ " jmp 2b\n"
10519 ++ ".previous\n"
10520 ++ _ASM_EXTABLE(0b,3b)
10521 ++ : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),
10522 ++ "=&D" (__d2)
10523 ++ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst),
10524 ++ "r"(__USER_DS)
10525 ++ : "memory");
10526 ++ return res;
10527 ++}
10528 +
10529 + /**
10530 + * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
10531 +@@ -78,9 +85,7 @@ do { \
10532 + long
10533 + __strncpy_from_user(char *dst, const char __user *src, long count)
10534 + {
10535 +- long res;
10536 +- __do_strncpy_from_user(dst, src, count, res);
10537 +- return res;
10538 ++ return __do_strncpy_from_user(dst, src, count);
10539 + }
10540 + EXPORT_SYMBOL(__strncpy_from_user);
10541 +
10542 +@@ -107,7 +112,7 @@ strncpy_from_user(char *dst, const char
10543 + {
10544 + long res = -EFAULT;
10545 + if (access_ok(VERIFY_READ, src, 1))
10546 +- __do_strncpy_from_user(dst, src, count, res);
10547 ++ res = __do_strncpy_from_user(dst, src, count);
10548 + return res;
10549 + }
10550 + EXPORT_SYMBOL(strncpy_from_user);
10551 +@@ -116,24 +121,30 @@ EXPORT_SYMBOL(strncpy_from_user);
10552 + * Zero Userspace
10553 + */
10554 +
10555 +-#define __do_clear_user(addr,size) \
10556 +-do { \
10557 +- int __d0; \
10558 +- might_sleep(); \
10559 +- __asm__ __volatile__( \
10560 +- "0: rep; stosl\n" \
10561 +- " movl %2,%0\n" \
10562 +- "1: rep; stosb\n" \
10563 +- "2:\n" \
10564 +- ".section .fixup,\"ax\"\n" \
10565 +- "3: lea 0(%2,%0,4),%0\n" \
10566 +- " jmp 2b\n" \
10567 +- ".previous\n" \
10568 +- _ASM_EXTABLE(0b,3b) \
10569 +- _ASM_EXTABLE(1b,2b) \
10570 +- : "=&c"(size), "=&D" (__d0) \
10571 +- : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \
10572 +-} while (0)
10573 ++static unsigned long __do_clear_user(void __user *addr, unsigned long size)
10574 ++{
10575 ++ int __d0;
10576 ++
10577 ++ might_sleep();
10578 ++ __asm__ __volatile__(
10579 ++ " movw %w6,%%es\n"
10580 ++ "0: rep; stosl\n"
10581 ++ " movl %2,%0\n"
10582 ++ "1: rep; stosb\n"
10583 ++ "2:\n"
10584 ++ " pushl %%ss\n"
10585 ++ " popl %%es\n"
10586 ++ ".section .fixup,\"ax\"\n"
10587 ++ "3: lea 0(%2,%0,4),%0\n"
10588 ++ " jmp 2b\n"
10589 ++ ".previous\n"
10590 ++ _ASM_EXTABLE(0b,3b)
10591 ++ _ASM_EXTABLE(1b,2b)
10592 ++ : "=&c"(size), "=&D" (__d0)
10593 ++ : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0),
10594 ++ "r"(__USER_DS));
10595 ++ return size;
10596 ++}
10597 +
10598 + /**
10599 + * clear_user: - Zero a block of memory in user space.
10600 +@@ -150,7 +161,7 @@ clear_user(void __user *to, unsigned lon
10601 + {
10602 + might_sleep();
10603 + if (access_ok(VERIFY_WRITE, to, n))
10604 +- __do_clear_user(to, n);
10605 ++ n = __do_clear_user(to, n);
10606 + return n;
10607 + }
10608 + EXPORT_SYMBOL(clear_user);
10609 +@@ -169,8 +180,7 @@ EXPORT_SYMBOL(clear_user);
10610 + unsigned long
10611 + __clear_user(void __user *to, unsigned long n)
10612 + {
10613 +- __do_clear_user(to, n);
10614 +- return n;
10615 ++ return __do_clear_user(to, n);
10616 + }
10617 + EXPORT_SYMBOL(__clear_user);
10618 +
10619 +@@ -193,14 +203,17 @@ long strnlen_user(const char __user *s,
10620 + might_sleep();
10621 +
10622 + __asm__ __volatile__(
10623 ++ " movw %w8,%%es\n"
10624 + " testl %0, %0\n"
10625 + " jz 3f\n"
10626 +- " andl %0,%%ecx\n"
10627 ++ " movl %0,%%ecx\n"
10628 + "0: repne; scasb\n"
10629 + " setne %%al\n"
10630 + " subl %%ecx,%0\n"
10631 + " addl %0,%%eax\n"
10632 + "1:\n"
10633 ++ " pushl %%ss\n"
10634 ++ " popl %%es\n"
10635 + ".section .fixup,\"ax\"\n"
10636 + "2: xorl %%eax,%%eax\n"
10637 + " jmp 1b\n"
10638 +@@ -212,7 +225,7 @@ long strnlen_user(const char __user *s,
10639 + " .long 0b,2b\n"
10640 + ".previous"
10641 + :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
10642 +- :"0" (n), "1" (s), "2" (0), "3" (mask)
10643 ++ :"0" (n), "1" (s), "2" (0), "3" (mask), "r" (__USER_DS)
10644 + :"cc");
10645 + return res & mask;
10646 + }
10647 +@@ -220,10 +233,11 @@ EXPORT_SYMBOL(strnlen_user);
10648 +
10649 + #ifdef CONFIG_X86_INTEL_USERCOPY
10650 + static unsigned long
10651 +-__copy_user_intel(void __user *to, const void *from, unsigned long size)
10652 ++__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
10653 + {
10654 + int d0, d1;
10655 + __asm__ __volatile__(
10656 ++ " movw %w6, %%es\n"
10657 + " .align 2,0x90\n"
10658 + "1: movl 32(%4), %%eax\n"
10659 + " cmpl $67, %0\n"
10660 +@@ -232,36 +246,36 @@ __copy_user_intel(void __user *to, const
10661 + " .align 2,0x90\n"
10662 + "3: movl 0(%4), %%eax\n"
10663 + "4: movl 4(%4), %%edx\n"
10664 +- "5: movl %%eax, 0(%3)\n"
10665 +- "6: movl %%edx, 4(%3)\n"
10666 ++ "5: movl %%eax, %%es:0(%3)\n"
10667 ++ "6: movl %%edx, %%es:4(%3)\n"
10668 + "7: movl 8(%4), %%eax\n"
10669 + "8: movl 12(%4),%%edx\n"
10670 +- "9: movl %%eax, 8(%3)\n"
10671 +- "10: movl %%edx, 12(%3)\n"
10672 ++ "9: movl %%eax, %%es:8(%3)\n"
10673 ++ "10: movl %%edx, %%es:12(%3)\n"
10674 + "11: movl 16(%4), %%eax\n"
10675 + "12: movl 20(%4), %%edx\n"
10676 +- "13: movl %%eax, 16(%3)\n"
10677 +- "14: movl %%edx, 20(%3)\n"
10678 ++ "13: movl %%eax, %%es:16(%3)\n"
10679 ++ "14: movl %%edx, %%es:20(%3)\n"
10680 + "15: movl 24(%4), %%eax\n"
10681 + "16: movl 28(%4), %%edx\n"
10682 +- "17: movl %%eax, 24(%3)\n"
10683 +- "18: movl %%edx, 28(%3)\n"
10684 ++ "17: movl %%eax, %%es:24(%3)\n"
10685 ++ "18: movl %%edx, %%es:28(%3)\n"
10686 + "19: movl 32(%4), %%eax\n"
10687 + "20: movl 36(%4), %%edx\n"
10688 +- "21: movl %%eax, 32(%3)\n"
10689 +- "22: movl %%edx, 36(%3)\n"
10690 ++ "21: movl %%eax, %%es:32(%3)\n"
10691 ++ "22: movl %%edx, %%es:36(%3)\n"
10692 + "23: movl 40(%4), %%eax\n"
10693 + "24: movl 44(%4), %%edx\n"
10694 +- "25: movl %%eax, 40(%3)\n"
10695 +- "26: movl %%edx, 44(%3)\n"
10696 ++ "25: movl %%eax, %%es:40(%3)\n"
10697 ++ "26: movl %%edx, %%es:44(%3)\n"
10698 + "27: movl 48(%4), %%eax\n"
10699 + "28: movl 52(%4), %%edx\n"
10700 +- "29: movl %%eax, 48(%3)\n"
10701 +- "30: movl %%edx, 52(%3)\n"
10702 ++ "29: movl %%eax, %%es:48(%3)\n"
10703 ++ "30: movl %%edx, %%es:52(%3)\n"
10704 + "31: movl 56(%4), %%eax\n"
10705 + "32: movl 60(%4), %%edx\n"
10706 +- "33: movl %%eax, 56(%3)\n"
10707 +- "34: movl %%edx, 60(%3)\n"
10708 ++ "33: movl %%eax, %%es:56(%3)\n"
10709 ++ "34: movl %%edx, %%es:60(%3)\n"
10710 + " addl $-64, %0\n"
10711 + " addl $64, %4\n"
10712 + " addl $64, %3\n"
10713 +@@ -275,6 +289,8 @@ __copy_user_intel(void __user *to, const
10714 + "36: movl %%eax, %0\n"
10715 + "37: rep; movsb\n"
10716 + "100:\n"
10717 ++ " pushl %%ss\n"
10718 ++ " popl %%es\n"
10719 + ".section .fixup,\"ax\"\n"
10720 + "101: lea 0(%%eax,%0,4),%0\n"
10721 + " jmp 100b\n"
10722 +@@ -321,7 +337,117 @@ __copy_user_intel(void __user *to, const
10723 + " .long 99b,101b\n"
10724 + ".previous"
10725 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
10726 +- : "1"(to), "2"(from), "0"(size)
10727 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
10728 ++ : "eax", "edx", "memory");
10729 ++ return size;
10730 ++}
10731 ++
10732 ++static unsigned long
10733 ++__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
10734 ++{
10735 ++ int d0, d1;
10736 ++ __asm__ __volatile__(
10737 ++ " movw %w6, %%ds\n"
10738 ++ " .align 2,0x90\n"
10739 ++ "1: movl 32(%4), %%eax\n"
10740 ++ " cmpl $67, %0\n"
10741 ++ " jbe 3f\n"
10742 ++ "2: movl 64(%4), %%eax\n"
10743 ++ " .align 2,0x90\n"
10744 ++ "3: movl 0(%4), %%eax\n"
10745 ++ "4: movl 4(%4), %%edx\n"
10746 ++ "5: movl %%eax, %%es:0(%3)\n"
10747 ++ "6: movl %%edx, %%es:4(%3)\n"
10748 ++ "7: movl 8(%4), %%eax\n"
10749 ++ "8: movl 12(%4),%%edx\n"
10750 ++ "9: movl %%eax, %%es:8(%3)\n"
10751 ++ "10: movl %%edx, %%es:12(%3)\n"
10752 ++ "11: movl 16(%4), %%eax\n"
10753 ++ "12: movl 20(%4), %%edx\n"
10754 ++ "13: movl %%eax, %%es:16(%3)\n"
10755 ++ "14: movl %%edx, %%es:20(%3)\n"
10756 ++ "15: movl 24(%4), %%eax\n"
10757 ++ "16: movl 28(%4), %%edx\n"
10758 ++ "17: movl %%eax, %%es:24(%3)\n"
10759 ++ "18: movl %%edx, %%es:28(%3)\n"
10760 ++ "19: movl 32(%4), %%eax\n"
10761 ++ "20: movl 36(%4), %%edx\n"
10762 ++ "21: movl %%eax, %%es:32(%3)\n"
10763 ++ "22: movl %%edx, %%es:36(%3)\n"
10764 ++ "23: movl 40(%4), %%eax\n"
10765 ++ "24: movl 44(%4), %%edx\n"
10766 ++ "25: movl %%eax, %%es:40(%3)\n"
10767 ++ "26: movl %%edx, %%es:44(%3)\n"
10768 ++ "27: movl 48(%4), %%eax\n"
10769 ++ "28: movl 52(%4), %%edx\n"
10770 ++ "29: movl %%eax, %%es:48(%3)\n"
10771 ++ "30: movl %%edx, %%es:52(%3)\n"
10772 ++ "31: movl 56(%4), %%eax\n"
10773 ++ "32: movl 60(%4), %%edx\n"
10774 ++ "33: movl %%eax, %%es:56(%3)\n"
10775 ++ "34: movl %%edx, %%es:60(%3)\n"
10776 ++ " addl $-64, %0\n"
10777 ++ " addl $64, %4\n"
10778 ++ " addl $64, %3\n"
10779 ++ " cmpl $63, %0\n"
10780 ++ " ja 1b\n"
10781 ++ "35: movl %0, %%eax\n"
10782 ++ " shrl $2, %0\n"
10783 ++ " andl $3, %%eax\n"
10784 ++ " cld\n"
10785 ++ "99: rep; movsl\n"
10786 ++ "36: movl %%eax, %0\n"
10787 ++ "37: rep; movsb\n"
10788 ++ "100:\n"
10789 ++ " pushl %%ss\n"
10790 ++ " popl %%ds\n"
10791 ++ ".section .fixup,\"ax\"\n"
10792 ++ "101: lea 0(%%eax,%0,4),%0\n"
10793 ++ " jmp 100b\n"
10794 ++ ".previous\n"
10795 ++ ".section __ex_table,\"a\"\n"
10796 ++ " .align 4\n"
10797 ++ " .long 1b,100b\n"
10798 ++ " .long 2b,100b\n"
10799 ++ " .long 3b,100b\n"
10800 ++ " .long 4b,100b\n"
10801 ++ " .long 5b,100b\n"
10802 ++ " .long 6b,100b\n"
10803 ++ " .long 7b,100b\n"
10804 ++ " .long 8b,100b\n"
10805 ++ " .long 9b,100b\n"
10806 ++ " .long 10b,100b\n"
10807 ++ " .long 11b,100b\n"
10808 ++ " .long 12b,100b\n"
10809 ++ " .long 13b,100b\n"
10810 ++ " .long 14b,100b\n"
10811 ++ " .long 15b,100b\n"
10812 ++ " .long 16b,100b\n"
10813 ++ " .long 17b,100b\n"
10814 ++ " .long 18b,100b\n"
10815 ++ " .long 19b,100b\n"
10816 ++ " .long 20b,100b\n"
10817 ++ " .long 21b,100b\n"
10818 ++ " .long 22b,100b\n"
10819 ++ " .long 23b,100b\n"
10820 ++ " .long 24b,100b\n"
10821 ++ " .long 25b,100b\n"
10822 ++ " .long 26b,100b\n"
10823 ++ " .long 27b,100b\n"
10824 ++ " .long 28b,100b\n"
10825 ++ " .long 29b,100b\n"
10826 ++ " .long 30b,100b\n"
10827 ++ " .long 31b,100b\n"
10828 ++ " .long 32b,100b\n"
10829 ++ " .long 33b,100b\n"
10830 ++ " .long 34b,100b\n"
10831 ++ " .long 35b,100b\n"
10832 ++ " .long 36b,100b\n"
10833 ++ " .long 37b,100b\n"
10834 ++ " .long 99b,101b\n"
10835 ++ ".previous"
10836 ++ : "=&c"(size), "=&D" (d0), "=&S" (d1)
10837 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
10838 + : "eax", "edx", "memory");
10839 + return size;
10840 + }
10841 +@@ -331,6 +457,7 @@ __copy_user_zeroing_intel(void *to, cons
10842 + {
10843 + int d0, d1;
10844 + __asm__ __volatile__(
10845 ++ " movw %w6, %%ds\n"
10846 + " .align 2,0x90\n"
10847 + "0: movl 32(%4), %%eax\n"
10848 + " cmpl $67, %0\n"
10849 +@@ -339,36 +466,36 @@ __copy_user_zeroing_intel(void *to, cons
10850 + " .align 2,0x90\n"
10851 + "2: movl 0(%4), %%eax\n"
10852 + "21: movl 4(%4), %%edx\n"
10853 +- " movl %%eax, 0(%3)\n"
10854 +- " movl %%edx, 4(%3)\n"
10855 ++ " movl %%eax, %%es:0(%3)\n"
10856 ++ " movl %%edx, %%es:4(%3)\n"
10857 + "3: movl 8(%4), %%eax\n"
10858 + "31: movl 12(%4),%%edx\n"
10859 +- " movl %%eax, 8(%3)\n"
10860 +- " movl %%edx, 12(%3)\n"
10861 ++ " movl %%eax, %%es:8(%3)\n"
10862 ++ " movl %%edx, %%es:12(%3)\n"
10863 + "4: movl 16(%4), %%eax\n"
10864 + "41: movl 20(%4), %%edx\n"
10865 +- " movl %%eax, 16(%3)\n"
10866 +- " movl %%edx, 20(%3)\n"
10867 ++ " movl %%eax, %%es:16(%3)\n"
10868 ++ " movl %%edx, %%es:20(%3)\n"
10869 + "10: movl 24(%4), %%eax\n"
10870 + "51: movl 28(%4), %%edx\n"
10871 +- " movl %%eax, 24(%3)\n"
10872 +- " movl %%edx, 28(%3)\n"
10873 ++ " movl %%eax, %%es:24(%3)\n"
10874 ++ " movl %%edx, %%es:28(%3)\n"
10875 + "11: movl 32(%4), %%eax\n"
10876 + "61: movl 36(%4), %%edx\n"
10877 +- " movl %%eax, 32(%3)\n"
10878 +- " movl %%edx, 36(%3)\n"
10879 ++ " movl %%eax, %%es:32(%3)\n"
10880 ++ " movl %%edx, %%es:36(%3)\n"
10881 + "12: movl 40(%4), %%eax\n"
10882 + "71: movl 44(%4), %%edx\n"
10883 +- " movl %%eax, 40(%3)\n"
10884 +- " movl %%edx, 44(%3)\n"
10885 ++ " movl %%eax, %%es:40(%3)\n"
10886 ++ " movl %%edx, %%es:44(%3)\n"
10887 + "13: movl 48(%4), %%eax\n"
10888 + "81: movl 52(%4), %%edx\n"
10889 +- " movl %%eax, 48(%3)\n"
10890 +- " movl %%edx, 52(%3)\n"
10891 ++ " movl %%eax, %%es:48(%3)\n"
10892 ++ " movl %%edx, %%es:52(%3)\n"
10893 + "14: movl 56(%4), %%eax\n"
10894 + "91: movl 60(%4), %%edx\n"
10895 +- " movl %%eax, 56(%3)\n"
10896 +- " movl %%edx, 60(%3)\n"
10897 ++ " movl %%eax, %%es:56(%3)\n"
10898 ++ " movl %%edx, %%es:60(%3)\n"
10899 + " addl $-64, %0\n"
10900 + " addl $64, %4\n"
10901 + " addl $64, %3\n"
10902 +@@ -382,6 +509,8 @@ __copy_user_zeroing_intel(void *to, cons
10903 + " movl %%eax,%0\n"
10904 + "7: rep; movsb\n"
10905 + "8:\n"
10906 ++ " pushl %%ss\n"
10907 ++ " popl %%ds\n"
10908 + ".section .fixup,\"ax\"\n"
10909 + "9: lea 0(%%eax,%0,4),%0\n"
10910 + "16: pushl %0\n"
10911 +@@ -416,7 +545,7 @@ __copy_user_zeroing_intel(void *to, cons
10912 + " .long 7b,16b\n"
10913 + ".previous"
10914 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
10915 +- : "1"(to), "2"(from), "0"(size)
10916 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
10917 + : "eax", "edx", "memory");
10918 + return size;
10919 + }
10920 +@@ -432,6 +561,7 @@ static unsigned long __copy_user_zeroing
10921 + int d0, d1;
10922 +
10923 + __asm__ __volatile__(
10924 ++ " movw %w6, %%ds\n"
10925 + " .align 2,0x90\n"
10926 + "0: movl 32(%4), %%eax\n"
10927 + " cmpl $67, %0\n"
10928 +@@ -440,36 +570,36 @@ static unsigned long __copy_user_zeroing
10929 + " .align 2,0x90\n"
10930 + "2: movl 0(%4), %%eax\n"
10931 + "21: movl 4(%4), %%edx\n"
10932 +- " movnti %%eax, 0(%3)\n"
10933 +- " movnti %%edx, 4(%3)\n"
10934 ++ " movnti %%eax, %%es:0(%3)\n"
10935 ++ " movnti %%edx, %%es:4(%3)\n"
10936 + "3: movl 8(%4), %%eax\n"
10937 + "31: movl 12(%4),%%edx\n"
10938 +- " movnti %%eax, 8(%3)\n"
10939 +- " movnti %%edx, 12(%3)\n"
10940 ++ " movnti %%eax, %%es:8(%3)\n"
10941 ++ " movnti %%edx, %%es:12(%3)\n"
10942 + "4: movl 16(%4), %%eax\n"
10943 + "41: movl 20(%4), %%edx\n"
10944 +- " movnti %%eax, 16(%3)\n"
10945 +- " movnti %%edx, 20(%3)\n"
10946 ++ " movnti %%eax, %%es:16(%3)\n"
10947 ++ " movnti %%edx, %%es:20(%3)\n"
10948 + "10: movl 24(%4), %%eax\n"
10949 + "51: movl 28(%4), %%edx\n"
10950 +- " movnti %%eax, 24(%3)\n"
10951 +- " movnti %%edx, 28(%3)\n"
10952 ++ " movnti %%eax, %%es:24(%3)\n"
10953 ++ " movnti %%edx, %%es:28(%3)\n"
10954 + "11: movl 32(%4), %%eax\n"
10955 + "61: movl 36(%4), %%edx\n"
10956 +- " movnti %%eax, 32(%3)\n"
10957 +- " movnti %%edx, 36(%3)\n"
10958 ++ " movnti %%eax, %%es:32(%3)\n"
10959 ++ " movnti %%edx, %%es:36(%3)\n"
10960 + "12: movl 40(%4), %%eax\n"
10961 + "71: movl 44(%4), %%edx\n"
10962 +- " movnti %%eax, 40(%3)\n"
10963 +- " movnti %%edx, 44(%3)\n"
10964 ++ " movnti %%eax, %%es:40(%3)\n"
10965 ++ " movnti %%edx, %%es:44(%3)\n"
10966 + "13: movl 48(%4), %%eax\n"
10967 + "81: movl 52(%4), %%edx\n"
10968 +- " movnti %%eax, 48(%3)\n"
10969 +- " movnti %%edx, 52(%3)\n"
10970 ++ " movnti %%eax, %%es:48(%3)\n"
10971 ++ " movnti %%edx, %%es:52(%3)\n"
10972 + "14: movl 56(%4), %%eax\n"
10973 + "91: movl 60(%4), %%edx\n"
10974 +- " movnti %%eax, 56(%3)\n"
10975 +- " movnti %%edx, 60(%3)\n"
10976 ++ " movnti %%eax, %%es:56(%3)\n"
10977 ++ " movnti %%edx, %%es:60(%3)\n"
10978 + " addl $-64, %0\n"
10979 + " addl $64, %4\n"
10980 + " addl $64, %3\n"
10981 +@@ -484,6 +614,8 @@ static unsigned long __copy_user_zeroing
10982 + " movl %%eax,%0\n"
10983 + "7: rep; movsb\n"
10984 + "8:\n"
10985 ++ " pushl %%ss\n"
10986 ++ " popl %%ds\n"
10987 + ".section .fixup,\"ax\"\n"
10988 + "9: lea 0(%%eax,%0,4),%0\n"
10989 + "16: pushl %0\n"
10990 +@@ -518,7 +650,7 @@ static unsigned long __copy_user_zeroing
10991 + " .long 7b,16b\n"
10992 + ".previous"
10993 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
10994 +- : "1"(to), "2"(from), "0"(size)
10995 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
10996 + : "eax", "edx", "memory");
10997 + return size;
10998 + }
10999 +@@ -529,6 +661,7 @@ static unsigned long __copy_user_intel_n
11000 + int d0, d1;
11001 +
11002 + __asm__ __volatile__(
11003 ++ " movw %w6, %%ds\n"
11004 + " .align 2,0x90\n"
11005 + "0: movl 32(%4), %%eax\n"
11006 + " cmpl $67, %0\n"
11007 +@@ -537,36 +670,36 @@ static unsigned long __copy_user_intel_n
11008 + " .align 2,0x90\n"
11009 + "2: movl 0(%4), %%eax\n"
11010 + "21: movl 4(%4), %%edx\n"
11011 +- " movnti %%eax, 0(%3)\n"
11012 +- " movnti %%edx, 4(%3)\n"
11013 ++ " movnti %%eax, %%es:0(%3)\n"
11014 ++ " movnti %%edx, %%es:4(%3)\n"
11015 + "3: movl 8(%4), %%eax\n"
11016 + "31: movl 12(%4),%%edx\n"
11017 +- " movnti %%eax, 8(%3)\n"
11018 +- " movnti %%edx, 12(%3)\n"
11019 ++ " movnti %%eax, %%es:8(%3)\n"
11020 ++ " movnti %%edx, %%es:12(%3)\n"
11021 + "4: movl 16(%4), %%eax\n"
11022 + "41: movl 20(%4), %%edx\n"
11023 +- " movnti %%eax, 16(%3)\n"
11024 +- " movnti %%edx, 20(%3)\n"
11025 ++ " movnti %%eax, %%es:16(%3)\n"
11026 ++ " movnti %%edx, %%es:20(%3)\n"
11027 + "10: movl 24(%4), %%eax\n"
11028 + "51: movl 28(%4), %%edx\n"
11029 +- " movnti %%eax, 24(%3)\n"
11030 +- " movnti %%edx, 28(%3)\n"
11031 ++ " movnti %%eax, %%es:24(%3)\n"
11032 ++ " movnti %%edx, %%es:28(%3)\n"
11033 + "11: movl 32(%4), %%eax\n"
11034 + "61: movl 36(%4), %%edx\n"
11035 +- " movnti %%eax, 32(%3)\n"
11036 +- " movnti %%edx, 36(%3)\n"
11037 ++ " movnti %%eax, %%es:32(%3)\n"
11038 ++ " movnti %%edx, %%es:36(%3)\n"
11039 + "12: movl 40(%4), %%eax\n"
11040 + "71: movl 44(%4), %%edx\n"
11041 +- " movnti %%eax, 40(%3)\n"
11042 +- " movnti %%edx, 44(%3)\n"
11043 ++ " movnti %%eax, %%es:40(%3)\n"
11044 ++ " movnti %%edx, %%es:44(%3)\n"
11045 + "13: movl 48(%4), %%eax\n"
11046 + "81: movl 52(%4), %%edx\n"
11047 +- " movnti %%eax, 48(%3)\n"
11048 +- " movnti %%edx, 52(%3)\n"
11049 ++ " movnti %%eax, %%es:48(%3)\n"
11050 ++ " movnti %%edx, %%es:52(%3)\n"
11051 + "14: movl 56(%4), %%eax\n"
11052 + "91: movl 60(%4), %%edx\n"
11053 +- " movnti %%eax, 56(%3)\n"
11054 +- " movnti %%edx, 60(%3)\n"
11055 ++ " movnti %%eax, %%es:56(%3)\n"
11056 ++ " movnti %%edx, %%es:60(%3)\n"
11057 + " addl $-64, %0\n"
11058 + " addl $64, %4\n"
11059 + " addl $64, %3\n"
11060 +@@ -581,6 +714,8 @@ static unsigned long __copy_user_intel_n
11061 + " movl %%eax,%0\n"
11062 + "7: rep; movsb\n"
11063 + "8:\n"
11064 ++ " pushl %%ss\n"
11065 ++ " popl %%ds\n"
11066 + ".section .fixup,\"ax\"\n"
11067 + "9: lea 0(%%eax,%0,4),%0\n"
11068 + "16: jmp 8b\n"
11069 +@@ -609,7 +744,7 @@ static unsigned long __copy_user_intel_n
11070 + " .long 7b,16b\n"
11071 + ".previous"
11072 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
11073 +- : "1"(to), "2"(from), "0"(size)
11074 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
11075 + : "eax", "edx", "memory");
11076 + return size;
11077 + }
11078 +@@ -622,90 +757,146 @@ static unsigned long __copy_user_intel_n
11079 + */
11080 + unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
11081 + unsigned long size);
11082 +-unsigned long __copy_user_intel(void __user *to, const void *from,
11083 ++unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
11084 ++ unsigned long size);
11085 ++unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
11086 + unsigned long size);
11087 + unsigned long __copy_user_zeroing_intel_nocache(void *to,
11088 + const void __user *from, unsigned long size);
11089 + #endif /* CONFIG_X86_INTEL_USERCOPY */
11090 +
11091 + /* Generic arbitrary sized copy. */
11092 +-#define __copy_user(to, from, size) \
11093 +-do { \
11094 +- int __d0, __d1, __d2; \
11095 +- __asm__ __volatile__( \
11096 +- " cmp $7,%0\n" \
11097 +- " jbe 1f\n" \
11098 +- " movl %1,%0\n" \
11099 +- " negl %0\n" \
11100 +- " andl $7,%0\n" \
11101 +- " subl %0,%3\n" \
11102 +- "4: rep; movsb\n" \
11103 +- " movl %3,%0\n" \
11104 +- " shrl $2,%0\n" \
11105 +- " andl $3,%3\n" \
11106 +- " .align 2,0x90\n" \
11107 +- "0: rep; movsl\n" \
11108 +- " movl %3,%0\n" \
11109 +- "1: rep; movsb\n" \
11110 +- "2:\n" \
11111 +- ".section .fixup,\"ax\"\n" \
11112 +- "5: addl %3,%0\n" \
11113 +- " jmp 2b\n" \
11114 +- "3: lea 0(%3,%0,4),%0\n" \
11115 +- " jmp 2b\n" \
11116 +- ".previous\n" \
11117 +- ".section __ex_table,\"a\"\n" \
11118 +- " .align 4\n" \
11119 +- " .long 4b,5b\n" \
11120 +- " .long 0b,3b\n" \
11121 +- " .long 1b,2b\n" \
11122 +- ".previous" \
11123 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
11124 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
11125 +- : "memory"); \
11126 +-} while (0)
11127 +-
11128 +-#define __copy_user_zeroing(to, from, size) \
11129 +-do { \
11130 +- int __d0, __d1, __d2; \
11131 +- __asm__ __volatile__( \
11132 +- " cmp $7,%0\n" \
11133 +- " jbe 1f\n" \
11134 +- " movl %1,%0\n" \
11135 +- " negl %0\n" \
11136 +- " andl $7,%0\n" \
11137 +- " subl %0,%3\n" \
11138 +- "4: rep; movsb\n" \
11139 +- " movl %3,%0\n" \
11140 +- " shrl $2,%0\n" \
11141 +- " andl $3,%3\n" \
11142 +- " .align 2,0x90\n" \
11143 +- "0: rep; movsl\n" \
11144 +- " movl %3,%0\n" \
11145 +- "1: rep; movsb\n" \
11146 +- "2:\n" \
11147 +- ".section .fixup,\"ax\"\n" \
11148 +- "5: addl %3,%0\n" \
11149 +- " jmp 6f\n" \
11150 +- "3: lea 0(%3,%0,4),%0\n" \
11151 +- "6: pushl %0\n" \
11152 +- " pushl %%eax\n" \
11153 +- " xorl %%eax,%%eax\n" \
11154 +- " rep; stosb\n" \
11155 +- " popl %%eax\n" \
11156 +- " popl %0\n" \
11157 +- " jmp 2b\n" \
11158 +- ".previous\n" \
11159 +- ".section __ex_table,\"a\"\n" \
11160 +- " .align 4\n" \
11161 +- " .long 4b,5b\n" \
11162 +- " .long 0b,3b\n" \
11163 +- " .long 1b,6b\n" \
11164 +- ".previous" \
11165 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
11166 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
11167 +- : "memory"); \
11168 +-} while (0)
11169 ++static unsigned long
11170 ++__generic_copy_to_user(void __user *to, const void *from, unsigned long size)
11171 ++{
11172 ++ int __d0, __d1, __d2;
11173 ++
11174 ++ __asm__ __volatile__(
11175 ++ " movw %w8,%%es\n"
11176 ++ " cmp $7,%0\n"
11177 ++ " jbe 1f\n"
11178 ++ " movl %1,%0\n"
11179 ++ " negl %0\n"
11180 ++ " andl $7,%0\n"
11181 ++ " subl %0,%3\n"
11182 ++ "4: rep; movsb\n"
11183 ++ " movl %3,%0\n"
11184 ++ " shrl $2,%0\n"
11185 ++ " andl $3,%3\n"
11186 ++ " .align 2,0x90\n"
11187 ++ "0: rep; movsl\n"
11188 ++ " movl %3,%0\n"
11189 ++ "1: rep; movsb\n"
11190 ++ "2:\n"
11191 ++ " pushl %%ss\n"
11192 ++ " popl %%es\n"
11193 ++ ".section .fixup,\"ax\"\n"
11194 ++ "5: addl %3,%0\n"
11195 ++ " jmp 2b\n"
11196 ++ "3: lea 0(%3,%0,4),%0\n"
11197 ++ " jmp 2b\n"
11198 ++ ".previous\n"
11199 ++ ".section __ex_table,\"a\"\n"
11200 ++ " .align 4\n"
11201 ++ " .long 4b,5b\n"
11202 ++ " .long 0b,3b\n"
11203 ++ " .long 1b,2b\n"
11204 ++ ".previous"
11205 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
11206 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
11207 ++ : "memory");
11208 ++ return size;
11209 ++}
11210 ++
11211 ++static unsigned long
11212 ++__generic_copy_from_user(void *to, const void __user *from, unsigned long size)
11213 ++{
11214 ++ int __d0, __d1, __d2;
11215 ++
11216 ++ __asm__ __volatile__(
11217 ++ " movw %w8,%%ds\n"
11218 ++ " cmp $7,%0\n"
11219 ++ " jbe 1f\n"
11220 ++ " movl %1,%0\n"
11221 ++ " negl %0\n"
11222 ++ " andl $7,%0\n"
11223 ++ " subl %0,%3\n"
11224 ++ "4: rep; movsb\n"
11225 ++ " movl %3,%0\n"
11226 ++ " shrl $2,%0\n"
11227 ++ " andl $3,%3\n"
11228 ++ " .align 2,0x90\n"
11229 ++ "0: rep; movsl\n"
11230 ++ " movl %3,%0\n"
11231 ++ "1: rep; movsb\n"
11232 ++ "2:\n"
11233 ++ " pushl %%ss\n"
11234 ++ " popl %%ds\n"
11235 ++ ".section .fixup,\"ax\"\n"
11236 ++ "5: addl %3,%0\n"
11237 ++ " jmp 2b\n"
11238 ++ "3: lea 0(%3,%0,4),%0\n"
11239 ++ " jmp 2b\n"
11240 ++ ".previous\n"
11241 ++ ".section __ex_table,\"a\"\n"
11242 ++ " .align 4\n"
11243 ++ " .long 4b,5b\n"
11244 ++ " .long 0b,3b\n"
11245 ++ " .long 1b,2b\n"
11246 ++ ".previous"
11247 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
11248 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
11249 ++ : "memory");
11250 ++ return size;
11251 ++}
11252 ++
11253 ++static unsigned long
11254 ++__copy_user_zeroing(void *to, const void __user *from, unsigned long size)
11255 ++{
11256 ++ int __d0, __d1, __d2;
11257 ++
11258 ++ __asm__ __volatile__(
11259 ++ " movw %w8,%%ds\n"
11260 ++ " cmp $7,%0\n"
11261 ++ " jbe 1f\n"
11262 ++ " movl %1,%0\n"
11263 ++ " negl %0\n"
11264 ++ " andl $7,%0\n"
11265 ++ " subl %0,%3\n"
11266 ++ "4: rep; movsb\n"
11267 ++ " movl %3,%0\n"
11268 ++ " shrl $2,%0\n"
11269 ++ " andl $3,%3\n"
11270 ++ " .align 2,0x90\n"
11271 ++ "0: rep; movsl\n"
11272 ++ " movl %3,%0\n"
11273 ++ "1: rep; movsb\n"
11274 ++ "2:\n"
11275 ++ " pushl %%ss\n"
11276 ++ " popl %%ds\n"
11277 ++ ".section .fixup,\"ax\"\n"
11278 ++ "5: addl %3,%0\n"
11279 ++ " jmp 6f\n"
11280 ++ "3: lea 0(%3,%0,4),%0\n"
11281 ++ "6: pushl %0\n"
11282 ++ " pushl %%eax\n"
11283 ++ " xorl %%eax,%%eax\n"
11284 ++ " rep; stosb\n"
11285 ++ " popl %%eax\n"
11286 ++ " popl %0\n"
11287 ++ " jmp 2b\n"
11288 ++ ".previous\n"
11289 ++ ".section __ex_table,\"a\"\n"
11290 ++ " .align 4\n"
11291 ++ " .long 4b,5b\n"
11292 ++ " .long 0b,3b\n"
11293 ++ " .long 1b,6b\n"
11294 ++ ".previous"
11295 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
11296 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
11297 ++ : "memory");
11298 ++ return size;
11299 ++}
11300 +
11301 + unsigned long __copy_to_user_ll(void __user *to, const void *from,
11302 + unsigned long n)
11303 +@@ -768,9 +959,9 @@ survive:
11304 + }
11305 + #endif
11306 + if (movsl_is_ok(to, from, n))
11307 +- __copy_user(to, from, n);
11308 ++ n = __generic_copy_to_user(to, from, n);
11309 + else
11310 +- n = __copy_user_intel(to, from, n);
11311 ++ n = __generic_copy_to_user_intel(to, from, n);
11312 + return n;
11313 + }
11314 + EXPORT_SYMBOL(__copy_to_user_ll);
11315 +@@ -779,7 +970,7 @@ unsigned long __copy_from_user_ll(void *
11316 + unsigned long n)
11317 + {
11318 + if (movsl_is_ok(to, from, n))
11319 +- __copy_user_zeroing(to, from, n);
11320 ++ n = __copy_user_zeroing(to, from, n);
11321 + else
11322 + n = __copy_user_zeroing_intel(to, from, n);
11323 + return n;
11324 +@@ -790,10 +981,9 @@ unsigned long __copy_from_user_ll_nozero
11325 + unsigned long n)
11326 + {
11327 + if (movsl_is_ok(to, from, n))
11328 +- __copy_user(to, from, n);
11329 ++ n = __generic_copy_from_user(to, from, n);
11330 + else
11331 +- n = __copy_user_intel((void __user *)to,
11332 +- (const void *)from, n);
11333 ++ n = __generic_copy_from_user_intel(to, from, n);
11334 + return n;
11335 + }
11336 + EXPORT_SYMBOL(__copy_from_user_ll_nozero);
11337 +@@ -802,12 +992,12 @@ unsigned long __copy_from_user_ll_nocach
11338 + unsigned long n)
11339 + {
11340 + #ifdef CONFIG_X86_INTEL_USERCOPY
11341 +- if (n > 64 && cpu_has_xmm2)
11342 ++ if ( n > 64 && cpu_has_xmm2)
11343 + n = __copy_user_zeroing_intel_nocache(to, from, n);
11344 + else
11345 +- __copy_user_zeroing(to, from, n);
11346 ++ n = __copy_user_zeroing(to, from, n);
11347 + #else
11348 +- __copy_user_zeroing(to, from, n);
11349 ++ n = __copy_user_zeroing(to, from, n);
11350 + #endif
11351 + return n;
11352 + }
11353 +@@ -817,12 +1007,12 @@ unsigned long __copy_from_user_ll_nocach
11354 + unsigned long n)
11355 + {
11356 + #ifdef CONFIG_X86_INTEL_USERCOPY
11357 +- if (n > 64 && cpu_has_xmm2)
11358 ++ if ( n > 64 && cpu_has_xmm2)
11359 + n = __copy_user_intel_nocache(to, from, n);
11360 + else
11361 +- __copy_user(to, from, n);
11362 ++ n = __generic_copy_from_user(to, from, n);
11363 + #else
11364 +- __copy_user(to, from, n);
11365 ++ n = __generic_copy_from_user(to, from, n);
11366 + #endif
11367 + return n;
11368 + }
11369 +@@ -871,8 +1061,35 @@ copy_from_user(void *to, const void __us
11370 + {
11371 + if (access_ok(VERIFY_READ, from, n))
11372 + n = __copy_from_user(to, from, n);
11373 +- else
11374 ++ else if ((long)n > 0)
11375 + memset(to, 0, n);
11376 + return n;
11377 + }
11378 + EXPORT_SYMBOL(copy_from_user);
11379 ++
11380 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
11381 ++void __set_fs(mm_segment_t x, int cpu)
11382 ++{
11383 ++ unsigned long limit = x.seg;
11384 ++ struct desc_struct d;
11385 ++
11386 ++ current_thread_info()->addr_limit = x;
11387 ++ if (likely(limit))
11388 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
11389 ++ pack_descriptor(&d, 0UL, limit, 0xF3, 0xC);
11390 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_DS, &d, DESCTYPE_S);
11391 ++}
11392 ++
11393 ++void set_fs(mm_segment_t x)
11394 ++{
11395 ++ __set_fs(x, get_cpu());
11396 ++ put_cpu_no_resched();
11397 ++}
11398 ++#else
11399 ++void set_fs(mm_segment_t x)
11400 ++{
11401 ++ current_thread_info()->addr_limit = x;
11402 ++}
11403 ++#endif
11404 ++
11405 ++EXPORT_SYMBOL(set_fs);
11406 +diff -urNp linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c
11407 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-07 12:55:34.000000000 -0500
11408 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_basic.c 2008-11-18 03:38:44.000000000 -0500
11409 +@@ -123,7 +123,7 @@ int __init voyager_memory_detect(int reg
11410 + __u8 cmos[4];
11411 + ClickMap_t *map;
11412 + unsigned long map_addr;
11413 +- unsigned long old;
11414 ++ pte_t old;
11415 +
11416 + if (region >= CLICK_ENTRIES) {
11417 + printk("Voyager: Illegal ClickMap region %d\n", region);
11418 +@@ -138,7 +138,7 @@ int __init voyager_memory_detect(int reg
11419 +
11420 + /* steal page 0 for this */
11421 + old = pg0[0];
11422 +- pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
11423 ++ pg0[0] = __pte((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
11424 + local_flush_tlb();
11425 + /* now clear everything out but page 0 */
11426 + map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
11427 +diff -urNp linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c
11428 +--- linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-07 12:55:34.000000000 -0500
11429 ++++ linux-2.6.27.10/arch/x86/mach-voyager/voyager_smp.c 2008-11-18 03:38:44.000000000 -0500
11430 +@@ -510,6 +510,10 @@ static void __init do_boot_cpu(__u8 cpu)
11431 + __u32 *hijack_vector;
11432 + __u32 start_phys_address = setup_trampoline();
11433 +
11434 ++#ifdef CONFIG_PAX_KERNEXEC
11435 ++ unsigned long cr0;
11436 ++#endif
11437 ++
11438 + /* There's a clever trick to this: The linux trampoline is
11439 + * compiled to begin at absolute location zero, so make the
11440 + * address zero but have the data segment selector compensate
11441 +@@ -529,7 +533,17 @@ static void __init do_boot_cpu(__u8 cpu)
11442 +
11443 + init_gdt(cpu);
11444 + per_cpu(current_task, cpu) = idle;
11445 +- early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
11446 ++
11447 ++#ifdef CONFIG_PAX_KERNEXEC
11448 ++ pax_open_kernel(cr0);
11449 ++#endif
11450 ++
11451 ++ early_gdt_descr.address = get_cpu_gdt_table(cpu);
11452 ++
11453 ++#ifdef CONFIG_PAX_KERNEXEC
11454 ++ pax_close_kernel(cr0);
11455 ++#endif
11456 ++
11457 + irq_ctx_init(cpu);
11458 +
11459 + /* Note: Don't modify initial ss override */
11460 +@@ -1141,7 +1155,7 @@ void smp_local_timer_interrupt(void)
11461 + per_cpu(prof_counter, cpu);
11462 + }
11463 +
11464 +- update_process_times(user_mode_vm(get_irq_regs()));
11465 ++ update_process_times(user_mode(get_irq_regs()));
11466 + }
11467 +
11468 + if (((1 << cpu) & voyager_extended_vic_processors) == 0)
11469 +diff -urNp linux-2.6.27.10/arch/x86/Makefile linux-2.6.27.10/arch/x86/Makefile
11470 +--- linux-2.6.27.10/arch/x86/Makefile 2008-11-07 12:55:34.000000000 -0500
11471 ++++ linux-2.6.27.10/arch/x86/Makefile 2008-11-18 03:38:44.000000000 -0500
11472 +@@ -232,3 +232,12 @@ endef
11473 + CLEAN_FILES += arch/x86/boot/fdimage \
11474 + arch/x86/boot/image.iso \
11475 + arch/x86/boot/mtools.conf
11476 ++
11477 ++define OLD_LD
11478 ++
11479 ++*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11480 ++*** Please upgrade your binutils to 2.18 or newer
11481 ++endef
11482 ++
11483 ++archprepare:
11484 ++ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11485 +diff -urNp linux-2.6.27.10/arch/x86/mm/discontig_32.c linux-2.6.27.10/arch/x86/mm/discontig_32.c
11486 +--- linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:36.000000000 -0500
11487 ++++ linux-2.6.27.10/arch/x86/mm/discontig_32.c 2008-12-10 22:35:46.000000000 -0500
11488 +@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
11489 + }
11490 + #endif
11491 +
11492 +-extern unsigned long find_max_low_pfn(void);
11493 + extern unsigned long highend_pfn, highstart_pfn;
11494 +
11495 + #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
11496 +diff -urNp linux-2.6.27.10/arch/x86/mm/extable.c linux-2.6.27.10/arch/x86/mm/extable.c
11497 +--- linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-07 12:55:34.000000000 -0500
11498 ++++ linux-2.6.27.10/arch/x86/mm/extable.c 2008-11-18 03:38:44.000000000 -0500
11499 +@@ -1,14 +1,62 @@
11500 + #include <linux/module.h>
11501 + #include <linux/spinlock.h>
11502 ++#include <linux/sort.h>
11503 + #include <asm/uaccess.h>
11504 +
11505 ++/*
11506 ++ * The exception table needs to be sorted so that the binary
11507 ++ * search that we use to find entries in it works properly.
11508 ++ * This is used both for the kernel exception table and for
11509 ++ * the exception tables of modules that get loaded.
11510 ++ */
11511 ++static int cmp_ex(const void *a, const void *b)
11512 ++{
11513 ++ const struct exception_table_entry *x = a, *y = b;
11514 ++
11515 ++ /* avoid overflow */
11516 ++ if (x->insn > y->insn)
11517 ++ return 1;
11518 ++ if (x->insn < y->insn)
11519 ++ return -1;
11520 ++ return 0;
11521 ++}
11522 ++
11523 ++static void swap_ex(void *a, void *b, int size)
11524 ++{
11525 ++ struct exception_table_entry t, *x = a, *y = b;
11526 ++
11527 ++#ifdef CONFIG_PAX_KERNEXEC
11528 ++ unsigned long cr0;
11529 ++#endif
11530 ++
11531 ++ t = *x;
11532 ++
11533 ++#ifdef CONFIG_PAX_KERNEXEC
11534 ++ pax_open_kernel(cr0);
11535 ++#endif
11536 ++
11537 ++ *x = *y;
11538 ++ *y = t;
11539 ++
11540 ++#ifdef CONFIG_PAX_KERNEXEC
11541 ++ pax_close_kernel(cr0);
11542 ++#endif
11543 ++
11544 ++}
11545 ++
11546 ++void sort_extable(struct exception_table_entry *start,
11547 ++ struct exception_table_entry *finish)
11548 ++{
11549 ++ sort(start, finish - start, sizeof(struct exception_table_entry),
11550 ++ cmp_ex, swap_ex);
11551 ++}
11552 +
11553 + int fixup_exception(struct pt_regs *regs)
11554 + {
11555 + const struct exception_table_entry *fixup;
11556 +
11557 + #ifdef CONFIG_PNPBIOS
11558 +- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
11559 ++ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
11560 + extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
11561 + extern u32 pnp_bios_is_utter_crap;
11562 + pnp_bios_is_utter_crap = 1;
11563 +diff -urNp linux-2.6.27.10/arch/x86/mm/fault.c linux-2.6.27.10/arch/x86/mm/fault.c
11564 +--- linux-2.6.27.10/arch/x86/mm/fault.c 2008-11-07 12:55:34.000000000 -0500
11565 ++++ linux-2.6.27.10/arch/x86/mm/fault.c 2008-12-10 22:28:27.000000000 -0500
11566 +@@ -26,6 +26,8 @@
11567 + #include <linux/kprobes.h>
11568 + #include <linux/uaccess.h>
11569 + #include <linux/kdebug.h>
11570 ++#include <linux/unistd.h>
11571 ++#include <linux/compiler.h>
11572 +
11573 + #include <asm/system.h>
11574 + #include <asm/desc.h>
11575 +@@ -66,7 +68,7 @@ static inline int notify_page_fault(stru
11576 + int ret = 0;
11577 +
11578 + /* kprobe_running() needs smp_processor_id() */
11579 +- if (!user_mode_vm(regs)) {
11580 ++ if (!user_mode(regs)) {
11581 + preempt_disable();
11582 + if (kprobe_running() && kprobe_fault_handler(regs, 14))
11583 + ret = 1;
11584 +@@ -264,6 +266,30 @@ bad:
11585 + #endif
11586 + }
11587 +
11588 ++#ifdef CONFIG_PAX_EMUTRAMP
11589 ++static int pax_handle_fetch_fault(struct pt_regs *regs);
11590 ++#endif
11591 ++
11592 ++#ifdef CONFIG_PAX_PAGEEXEC
11593 ++static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
11594 ++{
11595 ++ pgd_t *pgd;
11596 ++ pud_t *pud;
11597 ++ pmd_t *pmd;
11598 ++
11599 ++ pgd = pgd_offset(mm, address);
11600 ++ if (!pgd_present(*pgd))
11601 ++ return NULL;
11602 ++ pud = pud_offset(pgd, address);
11603 ++ if (!pud_present(*pud))
11604 ++ return NULL;
11605 ++ pmd = pmd_offset(pud, address);
11606 ++ if (!pmd_present(*pmd))
11607 ++ return NULL;
11608 ++ return pmd;
11609 ++}
11610 ++#endif
11611 ++
11612 + #ifdef CONFIG_X86_32
11613 + static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
11614 + {
11615 +@@ -350,7 +376,7 @@ static int is_errata93(struct pt_regs *r
11616 + static int is_errata100(struct pt_regs *regs, unsigned long address)
11617 + {
11618 + #ifdef CONFIG_X86_64
11619 +- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
11620 ++ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) &&
11621 + (address >> 32))
11622 + return 1;
11623 + #endif
11624 +@@ -387,14 +413,31 @@ static void show_fault_oops(struct pt_re
11625 + #endif
11626 +
11627 + #ifdef CONFIG_X86_PAE
11628 +- if (error_code & PF_INSTR) {
11629 ++ if (nx_enabled && (error_code & PF_INSTR)) {
11630 + unsigned int level;
11631 + pte_t *pte = lookup_address(address, &level);
11632 +
11633 + if (pte && pte_present(*pte) && !pte_exec(*pte))
11634 + printk(KERN_CRIT "kernel tried to execute "
11635 + "NX-protected page - exploit attempt? "
11636 +- "(uid: %d)\n", current->uid);
11637 ++ "(uid: %d, task: %s, pid: %d)\n",
11638 ++ current->uid, current->comm, task_pid_nr(current));
11639 ++ }
11640 ++#endif
11641 ++
11642 ++#ifdef CONFIG_PAX_KERNEXEC
11643 ++#ifdef CONFIG_MODULES
11644 ++ if (init_mm.start_code <= address && address < (unsigned long)MODULES_END)
11645 ++#else
11646 ++ if (init_mm.start_code <= address && address < init_mm.end_code)
11647 ++#endif
11648 ++ {
11649 ++ if (current->signal->curr_ip)
11650 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
11651 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
11652 ++ else
11653 ++ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
11654 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
11655 + }
11656 + #endif
11657 +
11658 +@@ -586,13 +629,22 @@ void __kprobes do_page_fault(struct pt_r
11659 + struct task_struct *tsk;
11660 + struct mm_struct *mm;
11661 + struct vm_area_struct *vma;
11662 +- unsigned long address;
11663 + int write, si_code;
11664 + int fault;
11665 + #ifdef CONFIG_X86_64
11666 + unsigned long flags;
11667 + #endif
11668 +
11669 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11670 ++ pte_t *pte;
11671 ++ pmd_t *pmd;
11672 ++ spinlock_t *ptl;
11673 ++ unsigned char pte_mask;
11674 ++#endif
11675 ++
11676 ++ /* get the address */
11677 ++ const unsigned long address = read_cr2();
11678 ++
11679 + /*
11680 + * We can fault from pretty much anywhere, with unknown IRQ state.
11681 + */
11682 +@@ -602,9 +654,6 @@ void __kprobes do_page_fault(struct pt_r
11683 + mm = tsk->mm;
11684 + prefetchw(&mm->mmap_sem);
11685 +
11686 +- /* get the address */
11687 +- address = read_cr2();
11688 +-
11689 + si_code = SEGV_MAPERR;
11690 +
11691 + if (notify_page_fault(regs))
11692 +@@ -657,7 +706,7 @@ void __kprobes do_page_fault(struct pt_r
11693 + * atomic region then we must not take the fault.
11694 + */
11695 + if (in_atomic() || !mm)
11696 +- goto bad_area_nosemaphore;
11697 ++ goto bad_area_nopax;
11698 + #else /* CONFIG_X86_64 */
11699 + if (likely(regs->flags & X86_EFLAGS_IF))
11700 + local_irq_enable();
11701 +@@ -670,13 +719,13 @@ void __kprobes do_page_fault(struct pt_r
11702 + * atomic region then we must not take the fault.
11703 + */
11704 + if (unlikely(in_atomic() || !mm))
11705 +- goto bad_area_nosemaphore;
11706 ++ goto bad_area_nopax;
11707 +
11708 + /*
11709 + * User-mode registers count as a user access even for any
11710 + * potential system fault or CPU buglet.
11711 + */
11712 +- if (user_mode_vm(regs))
11713 ++ if (user_mode(regs))
11714 + error_code |= PF_USER;
11715 + again:
11716 + #endif
11717 +@@ -698,10 +747,104 @@ again:
11718 + if (!down_read_trylock(&mm->mmap_sem)) {
11719 + if ((error_code & PF_USER) == 0 &&
11720 + !search_exception_tables(regs->ip))
11721 +- goto bad_area_nosemaphore;
11722 ++ goto bad_area_nopax;
11723 + down_read(&mm->mmap_sem);
11724 + }
11725 +
11726 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11727 ++ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
11728 ++ !(mm->pax_flags & MF_PAX_PAGEEXEC))
11729 ++ goto not_pax_fault;
11730 ++
11731 ++ /* PaX: it's our fault, let's handle it if we can */
11732 ++
11733 ++ /* PaX: take a look at read faults before acquiring any locks */
11734 ++ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
11735 ++ /* instruction fetch attempt from a protected page in user mode */
11736 ++ up_read(&mm->mmap_sem);
11737 ++
11738 ++#ifdef CONFIG_PAX_EMUTRAMP
11739 ++ switch (pax_handle_fetch_fault(regs)) {
11740 ++ case 2:
11741 ++ return;
11742 ++ }
11743 ++#endif
11744 ++
11745 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
11746 ++ do_group_exit(SIGKILL);
11747 ++ }
11748 ++
11749 ++ pmd = pax_get_pmd(mm, address);
11750 ++ if (unlikely(!pmd))
11751 ++ goto not_pax_fault;
11752 ++
11753 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
11754 ++ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
11755 ++ pte_unmap_unlock(pte, ptl);
11756 ++ goto not_pax_fault;
11757 ++ }
11758 ++
11759 ++ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
11760 ++ /* write attempt to a protected page in user mode */
11761 ++ pte_unmap_unlock(pte, ptl);
11762 ++ goto not_pax_fault;
11763 ++ }
11764 ++
11765 ++#ifdef CONFIG_SMP
11766 ++ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
11767 ++#else
11768 ++ if (likely(address > get_limit(regs->cs)))
11769 ++#endif
11770 ++ {
11771 ++ set_pte(pte, pte_mkread(*pte));
11772 ++ __flush_tlb_one(address);
11773 ++ pte_unmap_unlock(pte, ptl);
11774 ++ up_read(&mm->mmap_sem);
11775 ++ return;
11776 ++ }
11777 ++
11778 ++ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
11779 ++
11780 ++ /*
11781 ++ * PaX: fill DTLB with user rights and retry
11782 ++ */
11783 ++ __asm__ __volatile__ (
11784 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
11785 ++ "movw %w4,%%es\n"
11786 ++#endif
11787 ++ "orb %2,(%1)\n"
11788 ++#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
11789 ++/*
11790 ++ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
11791 ++ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
11792 ++ * page fault when examined during a TLB load attempt. this is true not only
11793 ++ * for PTEs holding a non-present entry but also present entries that will
11794 ++ * raise a page fault (such as those set up by PaX, or the copy-on-write
11795 ++ * mechanism). in effect it means that we do *not* need to flush the TLBs
11796 ++ * for our target pages since their PTEs are simply not in the TLBs at all.
11797 ++
11798 ++ * the best thing in omitting it is that we gain around 15-20% speed in the
11799 ++ * fast path of the page fault handler and can get rid of tracing since we
11800 ++ * can no longer flush unintended entries.
11801 ++ */
11802 ++ "invlpg (%0)\n"
11803 ++#endif
11804 ++ "testb $0,%%es:(%0)\n"
11805 ++ "xorb %3,(%1)\n"
11806 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
11807 ++ "pushl %%ss\n"
11808 ++ "popl %%es\n"
11809 ++#endif
11810 ++ :
11811 ++ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER), "r" (__USER_DS)
11812 ++ : "memory", "cc");
11813 ++ pte_unmap_unlock(pte, ptl);
11814 ++ up_read(&mm->mmap_sem);
11815 ++ return;
11816 ++
11817 ++not_pax_fault:
11818 ++#endif
11819 ++
11820 + vma = find_vma(mm, address);
11821 + if (!vma)
11822 + goto bad_area;
11823 +@@ -709,16 +852,20 @@ again:
11824 + goto good_area;
11825 + if (!(vma->vm_flags & VM_GROWSDOWN))
11826 + goto bad_area;
11827 +- if (error_code & PF_USER) {
11828 +- /*
11829 +- * Accessing the stack below %sp is always a bug.
11830 +- * The large cushion allows instructions like enter
11831 +- * and pusha to work. ("enter $65535,$31" pushes
11832 +- * 32 pointers and then decrements %sp by 65535.)
11833 +- */
11834 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
11835 +- goto bad_area;
11836 +- }
11837 ++ /*
11838 ++ * Accessing the stack below %sp is always a bug.
11839 ++ * The large cushion allows instructions like enter
11840 ++ * and pusha to work. ("enter $65535,$31" pushes
11841 ++ * 32 pointers and then decrements %sp by 65535.)
11842 ++ */
11843 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
11844 ++ goto bad_area;
11845 ++
11846 ++#ifdef CONFIG_PAX_SEGMEXEC
11847 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)
11848 ++ goto bad_area;
11849 ++#endif
11850 ++
11851 + if (expand_stack(vma, address))
11852 + goto bad_area;
11853 + /*
11854 +@@ -728,6 +875,8 @@ again:
11855 + good_area:
11856 + si_code = SEGV_ACCERR;
11857 + write = 0;
11858 ++ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
11859 ++ goto bad_area;
11860 + switch (error_code & (PF_PROT|PF_WRITE)) {
11861 + default: /* 3: write, present */
11862 + /* fall through */
11863 +@@ -785,6 +934,54 @@ bad_area:
11864 + up_read(&mm->mmap_sem);
11865 +
11866 + bad_area_nosemaphore:
11867 ++
11868 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
11869 ++ if (mm && (error_code & PF_USER)) {
11870 ++ unsigned long ip = regs->ip;
11871 ++
11872 ++ if (v8086_mode(regs))
11873 ++ ip = ((regs->cs & 0xffff) << 4) + (regs->ip & 0xffff);
11874 ++
11875 ++ /*
11876 ++ * It's possible to have interrupts off here.
11877 ++ */
11878 ++ local_irq_enable();
11879 ++
11880 ++#ifdef CONFIG_PAX_PAGEEXEC
11881 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
11882 ++ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && regs->ip == address))) {
11883 ++
11884 ++#ifdef CONFIG_PAX_EMUTRAMP
11885 ++ switch (pax_handle_fetch_fault(regs)) {
11886 ++ case 2:
11887 ++ return;
11888 ++ }
11889 ++#endif
11890 ++
11891 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
11892 ++ do_group_exit(SIGKILL);
11893 ++ }
11894 ++#endif
11895 ++
11896 ++#ifdef CONFIG_PAX_SEGMEXEC
11897 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (regs->ip + SEGMEXEC_TASK_SIZE == address)) {
11898 ++
11899 ++#ifdef CONFIG_PAX_EMUTRAMP
11900 ++ switch (pax_handle_fetch_fault(regs)) {
11901 ++ case 2:
11902 ++ return;
11903 ++ }
11904 ++#endif
11905 ++
11906 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
11907 ++ do_group_exit(SIGKILL);
11908 ++ }
11909 ++#endif
11910 ++
11911 ++ }
11912 ++#endif
11913 ++
11914 ++bad_area_nopax:
11915 + /* User mode accesses just cause a SIGSEGV */
11916 + if (error_code & PF_USER) {
11917 + /*
11918 +@@ -863,7 +1060,7 @@ no_context:
11919 + #ifdef CONFIG_X86_32
11920 + die("Oops", regs, error_code);
11921 + bust_spinlocks(0);
11922 +- do_exit(SIGKILL);
11923 ++ do_group_exit(SIGKILL);
11924 + #else
11925 + if (__die("Oops", regs, error_code))
11926 + regs = NULL;
11927 +@@ -877,17 +1074,17 @@ no_context:
11928 + * us unable to handle the page fault gracefully.
11929 + */
11930 + out_of_memory:
11931 +- up_read(&mm->mmap_sem);
11932 + if (is_global_init(tsk)) {
11933 + yield();
11934 + #ifdef CONFIG_X86_32
11935 +- down_read(&mm->mmap_sem);
11936 + goto survive;
11937 + #else
11938 ++ up_read(&mm->mmap_sem);
11939 + goto again;
11940 + #endif
11941 + }
11942 +
11943 ++ up_read(&mm->mmap_sem);
11944 + printk("VM: killing process %s\n", tsk->comm);
11945 + if (error_code & PF_USER)
11946 + do_group_exit(SIGKILL);
11947 +@@ -959,3 +1156,174 @@ void vmalloc_sync_all(void)
11948 + }
11949 + #endif
11950 + }
11951 ++
11952 ++#ifdef CONFIG_PAX_EMUTRAMP
11953 ++static int pax_handle_fetch_fault_32(struct pt_regs *regs)
11954 ++{
11955 ++ int err;
11956 ++
11957 ++ do { /* PaX: gcc trampoline emulation #1 */
11958 ++ unsigned char mov1, mov2;
11959 ++ unsigned short jmp;
11960 ++ unsigned int addr1, addr2;
11961 ++
11962 ++#ifdef CONFIG_X86_64
11963 ++ if ((regs->ip + 11) >> 32)
11964 ++ break;
11965 ++#endif
11966 ++
11967 ++ err = get_user(mov1, (unsigned char __user *)regs->ip);
11968 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
11969 ++ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
11970 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
11971 ++ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
11972 ++
11973 ++ if (err)
11974 ++ break;
11975 ++
11976 ++ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
11977 ++ regs->cx = addr1;
11978 ++ regs->ax = addr2;
11979 ++ regs->ip = addr2;
11980 ++ return 2;
11981 ++ }
11982 ++ } while (0);
11983 ++
11984 ++ do { /* PaX: gcc trampoline emulation #2 */
11985 ++ unsigned char mov, jmp;
11986 ++ unsigned int addr1, addr2;
11987 ++
11988 ++#ifdef CONFIG_X86_64
11989 ++ if ((regs->ip + 9) >> 32)
11990 ++ break;
11991 ++#endif
11992 ++
11993 ++ err = get_user(mov, (unsigned char __user *)regs->ip);
11994 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
11995 ++ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
11996 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
11997 ++
11998 ++ if (err)
11999 ++ break;
12000 ++
12001 ++ if (mov == 0xB9 && jmp == 0xE9) {
12002 ++ regs->cx = addr1;
12003 ++ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
12004 ++ return 2;
12005 ++ }
12006 ++ } while (0);
12007 ++
12008 ++ return 1; /* PaX in action */
12009 ++}
12010 ++
12011 ++#ifdef CONFIG_X86_64
12012 ++static int pax_handle_fetch_fault_64(struct pt_regs *regs)
12013 ++{
12014 ++ int err;
12015 ++
12016 ++ do { /* PaX: gcc trampoline emulation #1 */
12017 ++ unsigned short mov1, mov2, jmp1;
12018 ++ unsigned char jmp2;
12019 ++ unsigned int addr1;
12020 ++ unsigned long addr2;
12021 ++
12022 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
12023 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
12024 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
12025 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
12026 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
12027 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
12028 ++
12029 ++ if (err)
12030 ++ break;
12031 ++
12032 ++ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
12033 ++ regs->r11 = addr1;
12034 ++ regs->r10 = addr2;
12035 ++ regs->ip = addr1;
12036 ++ return 2;
12037 ++ }
12038 ++ } while (0);
12039 ++
12040 ++ do { /* PaX: gcc trampoline emulation #2 */
12041 ++ unsigned short mov1, mov2, jmp1;
12042 ++ unsigned char jmp2;
12043 ++ unsigned long addr1, addr2;
12044 ++
12045 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
12046 ++ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
12047 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
12048 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
12049 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
12050 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
12051 ++
12052 ++ if (err)
12053 ++ break;
12054 ++
12055 ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
12056 ++ regs->r11 = addr1;
12057 ++ regs->r10 = addr2;
12058 ++ regs->ip = addr1;
12059 ++ return 2;
12060 ++ }
12061 ++ } while (0);
12062 ++
12063 ++ return 1; /* PaX in action */
12064 ++}
12065 ++#endif
12066 ++
12067 ++/*
12068 ++ * PaX: decide what to do with offenders (regs->ip = fault address)
12069 ++ *
12070 ++ * returns 1 when task should be killed
12071 ++ * 2 when gcc trampoline was detected
12072 ++ */
12073 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
12074 ++{
12075 ++ if (v8086_mode(regs))
12076 ++ return 1;
12077 ++
12078 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
12079 ++ return 1;
12080 ++
12081 ++#ifdef CONFIG_X86_32
12082 ++ return pax_handle_fetch_fault_32(regs);
12083 ++#else
12084 ++ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
12085 ++ return pax_handle_fetch_fault_32(regs);
12086 ++ else
12087 ++ return pax_handle_fetch_fault_64(regs);
12088 ++#endif
12089 ++}
12090 ++#endif
12091 ++
12092 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12093 ++void pax_report_insns(void *pc, void *sp)
12094 ++{
12095 ++ long i;
12096 ++
12097 ++ printk(KERN_ERR "PAX: bytes at PC: ");
12098 ++ for (i = 0; i < 20; i++) {
12099 ++ unsigned char c;
12100 ++ if (get_user(c, (unsigned char __user *)pc+i))
12101 ++ printk(KERN_CONT "?? ");
12102 ++ else
12103 ++ printk(KERN_CONT "%02x ", c);
12104 ++ }
12105 ++ printk("\n");
12106 ++
12107 ++ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
12108 ++ for (i = -1; i < 80 / sizeof(long); i++) {
12109 ++ unsigned long c;
12110 ++ if (get_user(c, (unsigned long __user *)sp+i))
12111 ++#ifdef CONFIG_X86_32
12112 ++ printk(KERN_CONT "???????? ");
12113 ++#else
12114 ++ printk(KERN_CONT "???????????????? ");
12115 ++#endif
12116 ++ else
12117 ++ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
12118 ++ }
12119 ++ printk("\n");
12120 ++}
12121 ++#endif
12122 +diff -urNp linux-2.6.27.10/arch/x86/mm/highmem_32.c linux-2.6.27.10/arch/x86/mm/highmem_32.c
12123 +--- linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-07 12:55:34.000000000 -0500
12124 ++++ linux-2.6.27.10/arch/x86/mm/highmem_32.c 2008-11-18 03:38:44.000000000 -0500
12125 +@@ -74,6 +74,10 @@ void *kmap_atomic_prot(struct page *page
12126 + enum fixed_addresses idx;
12127 + unsigned long vaddr;
12128 +
12129 ++#ifdef CONFIG_PAX_KERNEXEC
12130 ++ unsigned long cr0;
12131 ++#endif
12132 ++
12133 + /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
12134 + pagefault_disable();
12135 +
12136 +@@ -85,7 +89,17 @@ void *kmap_atomic_prot(struct page *page
12137 + idx = type + KM_TYPE_NR*smp_processor_id();
12138 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
12139 + BUG_ON(!pte_none(*(kmap_pte-idx)));
12140 ++
12141 ++#ifdef CONFIG_PAX_KERNEXEC
12142 ++ pax_open_kernel(cr0);
12143 ++#endif
12144 ++
12145 + set_pte(kmap_pte-idx, mk_pte(page, prot));
12146 ++
12147 ++#ifdef CONFIG_PAX_KERNEXEC
12148 ++ pax_close_kernel(cr0);
12149 ++#endif
12150 ++
12151 + arch_flush_lazy_mmu_mode();
12152 +
12153 + return (void *)vaddr;
12154 +@@ -101,15 +115,29 @@ void kunmap_atomic(void *kvaddr, enum km
12155 + unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
12156 + enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
12157 +
12158 ++#ifdef CONFIG_PAX_KERNEXEC
12159 ++ unsigned long cr0;
12160 ++#endif
12161 ++
12162 + /*
12163 + * Force other mappings to Oops if they'll try to access this pte
12164 + * without first remap it. Keeping stale mappings around is a bad idea
12165 + * also, in case the page changes cacheability attributes or becomes
12166 + * a protected page in a hypervisor.
12167 + */
12168 +- if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx))
12169 ++ if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) {
12170 ++
12171 ++#ifdef CONFIG_PAX_KERNEXEC
12172 ++ pax_open_kernel(cr0);
12173 ++#endif
12174 ++
12175 + kpte_clear_flush(kmap_pte-idx, vaddr);
12176 +- else {
12177 ++
12178 ++#ifdef CONFIG_PAX_KERNEXEC
12179 ++ pax_close_kernel(cr0);
12180 ++#endif
12181 ++
12182 ++ } else {
12183 + #ifdef CONFIG_DEBUG_HIGHMEM
12184 + BUG_ON(vaddr < PAGE_OFFSET);
12185 + BUG_ON(vaddr >= (unsigned long)high_memory);
12186 +@@ -128,11 +156,25 @@ void *kmap_atomic_pfn(unsigned long pfn,
12187 + enum fixed_addresses idx;
12188 + unsigned long vaddr;
12189 +
12190 ++#ifdef CONFIG_PAX_KERNEXEC
12191 ++ unsigned long cr0;
12192 ++#endif
12193 ++
12194 + pagefault_disable();
12195 +
12196 + idx = type + KM_TYPE_NR*smp_processor_id();
12197 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
12198 ++
12199 ++#ifdef CONFIG_PAX_KERNEXEC
12200 ++ pax_open_kernel(cr0);
12201 ++#endif
12202 ++
12203 + set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
12204 ++
12205 ++#ifdef CONFIG_PAX_KERNEXEC
12206 ++ pax_close_kernel(cr0);
12207 ++#endif
12208 ++
12209 + arch_flush_lazy_mmu_mode();
12210 +
12211 + return (void*) vaddr;
12212 +diff -urNp linux-2.6.27.10/arch/x86/mm/hugetlbpage.c linux-2.6.27.10/arch/x86/mm/hugetlbpage.c
12213 +--- linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-07 12:55:34.000000000 -0500
12214 ++++ linux-2.6.27.10/arch/x86/mm/hugetlbpage.c 2008-11-18 03:38:44.000000000 -0500
12215 +@@ -263,13 +263,18 @@ static unsigned long hugetlb_get_unmappe
12216 + struct hstate *h = hstate_file(file);
12217 + struct mm_struct *mm = current->mm;
12218 + struct vm_area_struct *vma;
12219 +- unsigned long start_addr;
12220 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
12221 ++
12222 ++#ifdef CONFIG_PAX_SEGMEXEC
12223 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
12224 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
12225 ++#endif
12226 +
12227 + if (len > mm->cached_hole_size) {
12228 +- start_addr = mm->free_area_cache;
12229 ++ start_addr = mm->free_area_cache;
12230 + } else {
12231 +- start_addr = TASK_UNMAPPED_BASE;
12232 +- mm->cached_hole_size = 0;
12233 ++ start_addr = mm->mmap_base;
12234 ++ mm->cached_hole_size = 0;
12235 + }
12236 +
12237 + full_search:
12238 +@@ -277,13 +282,13 @@ full_search:
12239 +
12240 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
12241 + /* At this point: (!vma || addr < vma->vm_end). */
12242 +- if (TASK_SIZE - len < addr) {
12243 ++ if (pax_task_size - len < addr) {
12244 + /*
12245 + * Start a new search - just in case we missed
12246 + * some holes.
12247 + */
12248 +- if (start_addr != TASK_UNMAPPED_BASE) {
12249 +- start_addr = TASK_UNMAPPED_BASE;
12250 ++ if (start_addr != mm->mmap_base) {
12251 ++ start_addr = mm->mmap_base;
12252 + mm->cached_hole_size = 0;
12253 + goto full_search;
12254 + }
12255 +@@ -306,9 +311,8 @@ static unsigned long hugetlb_get_unmappe
12256 + struct hstate *h = hstate_file(file);
12257 + struct mm_struct *mm = current->mm;
12258 + struct vm_area_struct *vma, *prev_vma;
12259 +- unsigned long base = mm->mmap_base, addr = addr0;
12260 ++ unsigned long base = mm->mmap_base, addr;
12261 + unsigned long largest_hole = mm->cached_hole_size;
12262 +- int first_time = 1;
12263 +
12264 + /* don't allow allocations above current base */
12265 + if (mm->free_area_cache > base)
12266 +@@ -318,7 +322,7 @@ static unsigned long hugetlb_get_unmappe
12267 + largest_hole = 0;
12268 + mm->free_area_cache = base;
12269 + }
12270 +-try_again:
12271 ++
12272 + /* make sure it can fit in the remaining address space */
12273 + if (mm->free_area_cache < len)
12274 + goto fail;
12275 +@@ -360,22 +364,26 @@ try_again:
12276 +
12277 + fail:
12278 + /*
12279 +- * if hint left us with no space for the requested
12280 +- * mapping then try again:
12281 +- */
12282 +- if (first_time) {
12283 +- mm->free_area_cache = base;
12284 +- largest_hole = 0;
12285 +- first_time = 0;
12286 +- goto try_again;
12287 +- }
12288 +- /*
12289 + * A failed mmap() very likely causes application failure,
12290 + * so fall back to the bottom-up function here. This scenario
12291 + * can happen with large stack limits and large mmap()
12292 + * allocations.
12293 + */
12294 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
12295 ++
12296 ++#ifdef CONFIG_PAX_SEGMEXEC
12297 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
12298 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
12299 ++ else
12300 ++#endif
12301 ++
12302 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
12303 ++
12304 ++#ifdef CONFIG_PAX_RANDMMAP
12305 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
12306 ++ mm->mmap_base += mm->delta_mmap;
12307 ++#endif
12308 ++
12309 ++ mm->free_area_cache = mm->mmap_base;
12310 + mm->cached_hole_size = ~0UL;
12311 + addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
12312 + len, pgoff, flags);
12313 +@@ -383,6 +391,7 @@ fail:
12314 + /*
12315 + * Restore the topdown base:
12316 + */
12317 ++ mm->mmap_base = base;
12318 + mm->free_area_cache = base;
12319 + mm->cached_hole_size = ~0UL;
12320 +
12321 +@@ -396,10 +405,17 @@ hugetlb_get_unmapped_area(struct file *f
12322 + struct hstate *h = hstate_file(file);
12323 + struct mm_struct *mm = current->mm;
12324 + struct vm_area_struct *vma;
12325 ++ unsigned long pax_task_size = TASK_SIZE;
12326 +
12327 + if (len & ~huge_page_mask(h))
12328 + return -EINVAL;
12329 +- if (len > TASK_SIZE)
12330 ++
12331 ++#ifdef CONFIG_PAX_SEGMEXEC
12332 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
12333 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
12334 ++#endif
12335 ++
12336 ++ if (len > pax_task_size)
12337 + return -ENOMEM;
12338 +
12339 + if (flags & MAP_FIXED) {
12340 +@@ -411,7 +427,7 @@ hugetlb_get_unmapped_area(struct file *f
12341 + if (addr) {
12342 + addr = ALIGN(addr, huge_page_size(h));
12343 + vma = find_vma(mm, addr);
12344 +- if (TASK_SIZE - len >= addr &&
12345 ++ if (pax_task_size - len >= addr &&
12346 + (!vma || addr + len <= vma->vm_start))
12347 + return addr;
12348 + }
12349 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_32.c linux-2.6.27.10/arch/x86/mm/init_32.c
12350 +--- linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-07 12:55:34.000000000 -0500
12351 ++++ linux-2.6.27.10/arch/x86/mm/init_32.c 2008-11-18 03:38:44.000000000 -0500
12352 +@@ -47,6 +47,7 @@
12353 + #include <asm/paravirt.h>
12354 + #include <asm/setup.h>
12355 + #include <asm/cacheflush.h>
12356 ++#include <asm/desc.h>
12357 +
12358 + unsigned int __VMALLOC_RESERVE = 128 << 20;
12359 +
12360 +@@ -80,35 +81,6 @@ static __init void *alloc_low_page(unsig
12361 + }
12362 +
12363 + /*
12364 +- * Creates a middle page table and puts a pointer to it in the
12365 +- * given global directory entry. This only returns the gd entry
12366 +- * in non-PAE compilation mode, since the middle layer is folded.
12367 +- */
12368 +-static pmd_t * __init one_md_table_init(pgd_t *pgd)
12369 +-{
12370 +- pud_t *pud;
12371 +- pmd_t *pmd_table;
12372 +-
12373 +-#ifdef CONFIG_X86_PAE
12374 +- unsigned long phys;
12375 +- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
12376 +- if (after_init_bootmem)
12377 +- pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
12378 +- else
12379 +- pmd_table = (pmd_t *)alloc_low_page(&phys);
12380 +- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
12381 +- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
12382 +- pud = pud_offset(pgd, 0);
12383 +- BUG_ON(pmd_table != pmd_offset(pud, 0));
12384 +- }
12385 +-#endif
12386 +- pud = pud_offset(pgd, 0);
12387 +- pmd_table = pmd_offset(pud, 0);
12388 +-
12389 +- return pmd_table;
12390 +-}
12391 +-
12392 +-/*
12393 + * Create a page table and place a pointer to it in a middle page
12394 + * directory entry:
12395 + */
12396 +@@ -130,7 +102,11 @@ static pte_t * __init one_page_table_ini
12397 + }
12398 +
12399 + paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
12400 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
12401 ++ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
12402 ++#else
12403 + set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
12404 ++#endif
12405 + BUG_ON(page_table != pte_offset_kernel(pmd, 0));
12406 + }
12407 +
12408 +@@ -152,6 +128,7 @@ page_table_range_init(unsigned long star
12409 + int pgd_idx, pmd_idx;
12410 + unsigned long vaddr;
12411 + pgd_t *pgd;
12412 ++ pud_t *pud;
12413 + pmd_t *pmd;
12414 +
12415 + vaddr = start;
12416 +@@ -160,8 +137,13 @@ page_table_range_init(unsigned long star
12417 + pgd = pgd_base + pgd_idx;
12418 +
12419 + for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
12420 +- pmd = one_md_table_init(pgd);
12421 +- pmd = pmd + pmd_index(vaddr);
12422 ++ pud = pud_offset(pgd, vaddr);
12423 ++ pmd = pmd_offset(pud, vaddr);
12424 ++
12425 ++#ifdef CONFIG_X86_PAE
12426 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
12427 ++#endif
12428 ++
12429 + for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
12430 + pmd++, pmd_idx++) {
12431 + one_page_table_init(pmd);
12432 +@@ -172,11 +154,23 @@ page_table_range_init(unsigned long star
12433 + }
12434 + }
12435 +
12436 +-static inline int is_kernel_text(unsigned long addr)
12437 ++static inline int is_kernel_text(unsigned long start, unsigned long end)
12438 + {
12439 +- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
12440 +- return 1;
12441 +- return 0;
12442 ++ unsigned long etext;
12443 ++
12444 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
12445 ++ etext = ktva_ktla((unsigned long)&MODULES_END);
12446 ++#else
12447 ++ etext = (unsigned long)&_etext;
12448 ++#endif
12449 ++
12450 ++ if ((start > ktla_ktva(etext) ||
12451 ++ end <= ktla_ktva((unsigned long)_stext)) &&
12452 ++ (start > ktla_ktva((unsigned long)_einittext) ||
12453 ++ end <= ktla_ktva((unsigned long)_sinittext)) &&
12454 ++ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
12455 ++ return 0;
12456 ++ return 1;
12457 + }
12458 +
12459 + /*
12460 +@@ -189,9 +183,10 @@ static void __init kernel_physical_mappi
12461 + unsigned long end_pfn,
12462 + int use_pse)
12463 + {
12464 +- int pgd_idx, pmd_idx, pte_ofs;
12465 ++ unsigned int pgd_idx, pmd_idx, pte_ofs;
12466 + unsigned long pfn;
12467 + pgd_t *pgd;
12468 ++ pud_t *pud;
12469 + pmd_t *pmd;
12470 + pte_t *pte;
12471 + unsigned pages_2m = 0, pages_4k = 0;
12472 +@@ -202,8 +197,13 @@ static void __init kernel_physical_mappi
12473 + pfn = start_pfn;
12474 + pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
12475 + pgd = pgd_base + pgd_idx;
12476 +- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
12477 +- pmd = one_md_table_init(pgd);
12478 ++ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
12479 ++ pud = pud_offset(pgd, 0);
12480 ++ pmd = pmd_offset(pud, 0);
12481 ++
12482 ++#ifdef CONFIG_X86_PAE
12483 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
12484 ++#endif
12485 +
12486 + if (pfn >= end_pfn)
12487 + continue;
12488 +@@ -215,21 +215,16 @@ static void __init kernel_physical_mappi
12489 + #endif
12490 + for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
12491 + pmd++, pmd_idx++) {
12492 +- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
12493 ++ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
12494 +
12495 + /*
12496 + * Map with big pages if possible, otherwise
12497 + * create normal page tables:
12498 + */
12499 + if (use_pse) {
12500 +- unsigned int addr2;
12501 + pgprot_t prot = PAGE_KERNEL_LARGE;
12502 +
12503 +- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
12504 +- PAGE_OFFSET + PAGE_SIZE-1;
12505 +-
12506 +- if (is_kernel_text(addr) ||
12507 +- is_kernel_text(addr2))
12508 ++ if (is_kernel_text(address, address + PMD_SIZE))
12509 + prot = PAGE_KERNEL_LARGE_EXEC;
12510 +
12511 + pages_2m++;
12512 +@@ -243,10 +238,10 @@ static void __init kernel_physical_mappi
12513 + pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
12514 + pte += pte_ofs;
12515 + for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
12516 +- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
12517 ++ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
12518 + pgprot_t prot = PAGE_KERNEL;
12519 +
12520 +- if (is_kernel_text(addr))
12521 ++ if (is_kernel_text(address, address + PAGE_SIZE))
12522 + prot = PAGE_KERNEL_EXEC;
12523 +
12524 + pages_4k++;
12525 +@@ -270,7 +265,9 @@ static void __init kernel_physical_mappi
12526 + */
12527 + int devmem_is_allowed(unsigned long pagenr)
12528 + {
12529 +- if (pagenr <= 256)
12530 ++ if (!pagenr)
12531 ++ return 1;
12532 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
12533 + return 1;
12534 + if (!page_is_ram(pagenr))
12535 + return 1;
12536 +@@ -404,7 +401,7 @@ void __init native_pagetable_setup_start
12537 +
12538 + pud = pud_offset(pgd, va);
12539 + pmd = pmd_offset(pud, va);
12540 +- if (!pmd_present(*pmd))
12541 ++ if (!pmd_present(*pmd) || pmd_huge(*pmd))
12542 + break;
12543 +
12544 + pte = pte_offset_kernel(pmd, va);
12545 +@@ -456,9 +453,7 @@ static void __init early_ioremap_page_ta
12546 +
12547 + static void __init pagetable_init(void)
12548 + {
12549 +- pgd_t *pgd_base = swapper_pg_dir;
12550 +-
12551 +- permanent_kmaps_init(pgd_base);
12552 ++ permanent_kmaps_init(swapper_pg_dir);
12553 + }
12554 +
12555 + #ifdef CONFIG_ACPI_SLEEP
12556 +@@ -466,12 +461,12 @@ static void __init pagetable_init(void)
12557 + * ACPI suspend needs this for resume, because things like the intel-agp
12558 + * driver might have split up a kernel 4MB mapping.
12559 + */
12560 +-char swsusp_pg_dir[PAGE_SIZE]
12561 ++pgd_t swsusp_pg_dir[PTRS_PER_PGD]
12562 + __attribute__ ((aligned(PAGE_SIZE)));
12563 +
12564 + static inline void save_pg_dir(void)
12565 + {
12566 +- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
12567 ++ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
12568 + }
12569 + #else /* !CONFIG_ACPI_SLEEP */
12570 + static inline void save_pg_dir(void)
12571 +@@ -501,13 +496,11 @@ void zap_low_mappings(void)
12572 +
12573 + int nx_enabled;
12574 +
12575 +-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL);
12576 ++pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL);
12577 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
12578 +
12579 + #ifdef CONFIG_X86_PAE
12580 +
12581 +-static int disable_nx __initdata;
12582 +-
12583 + /*
12584 + * noexec = on|off
12585 + *
12586 +@@ -516,40 +509,33 @@ static int disable_nx __initdata;
12587 + * on Enable
12588 + * off Disable
12589 + */
12590 ++#if !defined(CONFIG_PAX_PAGEEXEC)
12591 + static int __init noexec_setup(char *str)
12592 + {
12593 + if (!str || !strcmp(str, "on")) {
12594 +- if (cpu_has_nx) {
12595 +- __supported_pte_mask |= _PAGE_NX;
12596 +- disable_nx = 0;
12597 +- }
12598 ++ if (cpu_has_nx)
12599 ++ nx_enabled = 1;
12600 + } else {
12601 +- if (!strcmp(str, "off")) {
12602 +- disable_nx = 1;
12603 +- __supported_pte_mask &= ~_PAGE_NX;
12604 +- } else {
12605 ++ if (!strcmp(str, "off"))
12606 ++ nx_enabled = 0;
12607 ++ else
12608 + return -EINVAL;
12609 +- }
12610 + }
12611 +
12612 + return 0;
12613 + }
12614 + early_param("noexec", noexec_setup);
12615 ++#endif
12616 +
12617 + static void __init set_nx(void)
12618 + {
12619 +- unsigned int v[4], l, h;
12620 +-
12621 +- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
12622 +- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
12623 ++ if (!nx_enabled && cpu_has_nx) {
12624 ++ unsigned l, h;
12625 +
12626 +- if ((v[3] & (1 << 20)) && !disable_nx) {
12627 +- rdmsr(MSR_EFER, l, h);
12628 +- l |= EFER_NX;
12629 +- wrmsr(MSR_EFER, l, h);
12630 +- nx_enabled = 1;
12631 +- __supported_pte_mask |= _PAGE_NX;
12632 +- }
12633 ++ __supported_pte_mask &= ~_PAGE_NX;
12634 ++ rdmsr(MSR_EFER, l, h);
12635 ++ l &= ~EFER_NX;
12636 ++ wrmsr(MSR_EFER, l, h);
12637 + }
12638 + }
12639 + #endif
12640 +@@ -920,7 +906,7 @@ void __init mem_init(void)
12641 + set_highmem_pages_init();
12642 +
12643 + codesize = (unsigned long) &_etext - (unsigned long) &_text;
12644 +- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
12645 ++ datasize = (unsigned long) &_edata - (unsigned long) &_data;
12646 + initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
12647 +
12648 + kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
12649 +@@ -966,10 +952,10 @@ void __init mem_init(void)
12650 + ((unsigned long)&__init_end -
12651 + (unsigned long)&__init_begin) >> 10,
12652 +
12653 +- (unsigned long)&_etext, (unsigned long)&_edata,
12654 +- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
12655 ++ (unsigned long)&_data, (unsigned long)&_edata,
12656 ++ ((unsigned long)&_edata - (unsigned long)&_data) >> 10,
12657 +
12658 +- (unsigned long)&_text, (unsigned long)&_etext,
12659 ++ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
12660 + ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
12661 +
12662 + #ifdef CONFIG_HIGHMEM
12663 +@@ -1099,6 +1085,46 @@ void free_init_pages(char *what, unsigne
12664 +
12665 + void free_initmem(void)
12666 + {
12667 ++
12668 ++#ifdef CONFIG_PAX_KERNEXEC
12669 ++ /* PaX: limit KERNEL_CS to actual size */
12670 ++ unsigned long addr, limit;
12671 ++ struct desc_struct d;
12672 ++ int cpu;
12673 ++ pgd_t *pgd;
12674 ++ pud_t *pud;
12675 ++ pmd_t *pmd;
12676 ++
12677 ++#ifdef CONFIG_MODULES
12678 ++ limit = ktva_ktla((unsigned long)&MODULES_END);
12679 ++#else
12680 ++ limit = (unsigned long)&_etext;
12681 ++#endif
12682 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
12683 ++
12684 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
12685 ++ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
12686 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
12687 ++ }
12688 ++
12689 ++ /* PaX: make KERNEL_CS read-only */
12690 ++ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_data; addr += PMD_SIZE) {
12691 ++ pgd = pgd_offset_k(addr);
12692 ++ pud = pud_offset(pgd, addr);
12693 ++ pmd = pmd_offset(pud, addr);
12694 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
12695 ++ }
12696 ++#ifdef CONFIG_X86_PAE
12697 ++ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
12698 ++ pgd = pgd_offset_k(addr);
12699 ++ pud = pud_offset(pgd, addr);
12700 ++ pmd = pmd_offset(pud, addr);
12701 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
12702 ++ }
12703 ++#endif
12704 ++ flush_tlb_all();
12705 ++#endif
12706 ++
12707 + free_init_pages("unused kernel memory",
12708 + (unsigned long)(&__init_begin),
12709 + (unsigned long)(&__init_end));
12710 +diff -urNp linux-2.6.27.10/arch/x86/mm/init_64.c linux-2.6.27.10/arch/x86/mm/init_64.c
12711 +--- linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:16:51.000000000 -0500
12712 ++++ linux-2.6.27.10/arch/x86/mm/init_64.c 2008-12-21 01:13:45.000000000 -0500
12713 +@@ -118,6 +118,10 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
12714 + pmd_t *pmd;
12715 + pte_t *pte;
12716 +
12717 ++#ifdef CONFIG_PAX_KERNEXEC
12718 ++ unsigned long cr0;
12719 ++#endif
12720 ++
12721 + pud = pud_page + pud_index(vaddr);
12722 + if (pud_none(*pud)) {
12723 + pmd = (pmd_t *) spp_getpage();
12724 +@@ -142,8 +146,17 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
12725 + if (!pte_none(*pte) && pte_val(new_pte) &&
12726 + pte_val(*pte) != (pte_val(new_pte) & __supported_pte_mask))
12727 + pte_ERROR(*pte);
12728 ++
12729 ++#ifdef CONFIG_PAX_KERNEXEC
12730 ++ pax_open_kernel(cr0);
12731 ++#endif
12732 ++
12733 + set_pte(pte, new_pte);
12734 +
12735 ++#ifdef CONFIG_PAX_KERNEXEC
12736 ++ pax_close_kernel(cr0);
12737 ++#endif
12738 ++
12739 + /*
12740 + * It's enough to flush this one mapping.
12741 + * (PGE mappings get flushed as well)
12742 +@@ -184,14 +197,12 @@ static void __init __init_extra_mapping(
12743 + pgd = pgd_offset_k((unsigned long)__va(phys));
12744 + if (pgd_none(*pgd)) {
12745 + pud = (pud_t *) spp_getpage();
12746 +- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
12747 +- _PAGE_USER));
12748 ++ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
12749 + }
12750 + pud = pud_offset(pgd, (unsigned long)__va(phys));
12751 + if (pud_none(*pud)) {
12752 + pmd = (pmd_t *) spp_getpage();
12753 +- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
12754 +- _PAGE_USER));
12755 ++ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
12756 + }
12757 + pmd = pmd_offset(pud, phys);
12758 + BUG_ON(!pmd_none(*pmd));
12759 +@@ -754,7 +765,9 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to
12760 + */
12761 + int devmem_is_allowed(unsigned long pagenr)
12762 + {
12763 +- if (pagenr <= 256)
12764 ++ if (!pagenr)
12765 ++ return 1;
12766 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
12767 + return 1;
12768 + if (!page_is_ram(pagenr))
12769 + return 1;
12770 +@@ -842,6 +855,39 @@ void free_init_pages(char *what, unsigne
12771 +
12772 + void free_initmem(void)
12773 + {
12774 ++
12775 ++#ifdef CONFIG_PAX_KERNEXEC
12776 ++ unsigned long addr, end;
12777 ++ pgd_t *pgd;
12778 ++ pud_t *pud;
12779 ++ pmd_t *pmd;
12780 ++
12781 ++ /* PaX: make kernel code/rodata read-only, rest non-executable */
12782 ++ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
12783 ++ pgd = pgd_offset_k(addr);
12784 ++ pud = pud_offset(pgd, addr);
12785 ++ pmd = pmd_offset(pud, addr);
12786 ++ if ((unsigned long)_text <= addr && addr < (unsigned long)_data)
12787 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
12788 ++ else
12789 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
12790 ++ }
12791 ++
12792 ++ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
12793 ++ end = addr + KERNEL_IMAGE_SIZE;
12794 ++ for (; addr < end; addr += PMD_SIZE) {
12795 ++ pgd = pgd_offset_k(addr);
12796 ++ pud = pud_offset(pgd, addr);
12797 ++ pmd = pmd_offset(pud, addr);
12798 ++ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_data)))
12799 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
12800 ++ else
12801 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
12802 ++ }
12803 ++
12804 ++ flush_tlb_all();
12805 ++#endif
12806 ++
12807 + free_init_pages("unused kernel memory",
12808 + (unsigned long)(&__init_begin),
12809 + (unsigned long)(&__init_end));
12810 +@@ -1014,7 +1060,7 @@ int in_gate_area_no_task(unsigned long a
12811 +
12812 + const char *arch_vma_name(struct vm_area_struct *vma)
12813 + {
12814 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
12815 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
12816 + return "[vdso]";
12817 + if (vma == &gate_vma)
12818 + return "[vsyscall]";
12819 +diff -urNp linux-2.6.27.10/arch/x86/mm/ioremap.c linux-2.6.27.10/arch/x86/mm/ioremap.c
12820 +--- linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-07 12:55:34.000000000 -0500
12821 ++++ linux-2.6.27.10/arch/x86/mm/ioremap.c 2008-11-18 03:38:44.000000000 -0500
12822 +@@ -63,8 +63,8 @@ int page_is_ram(unsigned long pagenr)
12823 + * Second special case: Some BIOSen report the PC BIOS
12824 + * area (640->1Mb) as ram even though it is not.
12825 + */
12826 +- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
12827 +- pagenr < (BIOS_END >> PAGE_SHIFT))
12828 ++ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
12829 ++ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
12830 + return 0;
12831 +
12832 + for (i = 0; i < e820.nr_map; i++) {
12833 +@@ -217,6 +217,8 @@ static void __iomem *__ioremap_caller(re
12834 + break;
12835 + }
12836 +
12837 ++ prot = canon_pgprot(prot);
12838 ++
12839 + /*
12840 + * Ok, go for it..
12841 + */
12842 +diff -urNp linux-2.6.27.10/arch/x86/mm/mmap.c linux-2.6.27.10/arch/x86/mm/mmap.c
12843 +--- linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
12844 ++++ linux-2.6.27.10/arch/x86/mm/mmap.c 2008-11-18 03:38:44.000000000 -0500
12845 +@@ -36,7 +36,7 @@
12846 + * Leave an at least ~128 MB hole.
12847 + */
12848 + #define MIN_GAP (128*1024*1024)
12849 +-#define MAX_GAP (TASK_SIZE/6*5)
12850 ++#define MAX_GAP (pax_task_size/6*5)
12851 +
12852 + /*
12853 + * True on X86_32 or when emulating IA32 on X86_64
12854 +@@ -81,27 +81,40 @@ static unsigned long mmap_rnd(void)
12855 + return rnd << PAGE_SHIFT;
12856 + }
12857 +
12858 +-static unsigned long mmap_base(void)
12859 ++static unsigned long mmap_base(struct mm_struct *mm)
12860 + {
12861 + unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
12862 ++ unsigned long pax_task_size = TASK_SIZE;
12863 ++
12864 ++#ifdef CONFIG_PAX_SEGMEXEC
12865 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
12866 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
12867 ++#endif
12868 +
12869 + if (gap < MIN_GAP)
12870 + gap = MIN_GAP;
12871 + else if (gap > MAX_GAP)
12872 + gap = MAX_GAP;
12873 +
12874 +- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
12875 ++ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
12876 + }
12877 +
12878 + /*
12879 + * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
12880 + * does, but not when emulating X86_32
12881 + */
12882 +-static unsigned long mmap_legacy_base(void)
12883 ++static unsigned long mmap_legacy_base(struct mm_struct *mm)
12884 + {
12885 +- if (mmap_is_ia32())
12886 ++ if (mmap_is_ia32()) {
12887 ++
12888 ++#ifdef CONFIG_PAX_SEGMEXEC
12889 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
12890 ++ return SEGMEXEC_TASK_UNMAPPED_BASE;
12891 ++ else
12892 ++#endif
12893 ++
12894 + return TASK_UNMAPPED_BASE;
12895 +- else
12896 ++ } else
12897 + return TASK_UNMAPPED_BASE + mmap_rnd();
12898 + }
12899 +
12900 +@@ -112,11 +125,23 @@ static unsigned long mmap_legacy_base(vo
12901 + void arch_pick_mmap_layout(struct mm_struct *mm)
12902 + {
12903 + if (mmap_is_legacy()) {
12904 +- mm->mmap_base = mmap_legacy_base();
12905 ++ mm->mmap_base = mmap_legacy_base(mm);
12906 ++
12907 ++#ifdef CONFIG_PAX_RANDMMAP
12908 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
12909 ++ mm->mmap_base += mm->delta_mmap;
12910 ++#endif
12911 ++
12912 + mm->get_unmapped_area = arch_get_unmapped_area;
12913 + mm->unmap_area = arch_unmap_area;
12914 + } else {
12915 +- mm->mmap_base = mmap_base();
12916 ++ mm->mmap_base = mmap_base(mm);
12917 ++
12918 ++#ifdef CONFIG_PAX_RANDMMAP
12919 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
12920 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
12921 ++#endif
12922 ++
12923 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
12924 + mm->unmap_area = arch_unmap_area_topdown;
12925 + }
12926 +diff -urNp linux-2.6.27.10/arch/x86/mm/pageattr.c linux-2.6.27.10/arch/x86/mm/pageattr.c
12927 +--- linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-07 12:55:34.000000000 -0500
12928 ++++ linux-2.6.27.10/arch/x86/mm/pageattr.c 2008-11-18 03:38:44.000000000 -0500
12929 +@@ -20,6 +20,7 @@
12930 + #include <asm/pgalloc.h>
12931 + #include <asm/proto.h>
12932 + #include <asm/pat.h>
12933 ++#include <asm/desc.h>
12934 +
12935 + /*
12936 + * The current flushing context - we pass it instead of 5 arguments:
12937 +@@ -213,7 +214,7 @@ static inline pgprot_t static_protection
12938 + * Does not cover __inittext since that is gone later on. On
12939 + * 64bit we do not enforce !NX on the low mapping
12940 + */
12941 +- if (within(address, (unsigned long)_text, (unsigned long)_etext))
12942 ++ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
12943 + pgprot_val(forbidden) |= _PAGE_NX;
12944 +
12945 + /*
12946 +@@ -275,8 +276,20 @@ EXPORT_SYMBOL_GPL(lookup_address);
12947 + */
12948 + static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
12949 + {
12950 ++
12951 ++#ifdef CONFIG_PAX_KERNEXEC
12952 ++ unsigned long cr0;
12953 ++
12954 ++ pax_open_kernel(cr0);
12955 ++#endif
12956 ++
12957 + /* change init_mm */
12958 + set_pte_atomic(kpte, pte);
12959 ++
12960 ++#ifdef CONFIG_PAX_KERNEXEC
12961 ++ pax_close_kernel(cr0);
12962 ++#endif
12963 ++
12964 + #ifdef CONFIG_X86_32
12965 + if (!SHARED_KERNEL_PMD) {
12966 + struct page *page;
12967 +diff -urNp linux-2.6.27.10/arch/x86/mm/pat.c linux-2.6.27.10/arch/x86/mm/pat.c
12968 +--- linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-07 12:55:34.000000000 -0500
12969 ++++ linux-2.6.27.10/arch/x86/mm/pat.c 2008-11-18 03:38:44.000000000 -0500
12970 +@@ -396,7 +396,7 @@ pgprot_t phys_mem_access_prot(struct fil
12971 + return vma_prot;
12972 + }
12973 +
12974 +-#ifdef CONFIG_STRICT_DEVMEM
12975 ++#ifndef CONFIG_STRICT_DEVMEM
12976 + /* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/
12977 + static inline int range_is_allowed(unsigned long pfn, unsigned long size)
12978 + {
12979 +diff -urNp linux-2.6.27.10/arch/x86/mm/pgtable_32.c linux-2.6.27.10/arch/x86/mm/pgtable_32.c
12980 +--- linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-07 12:55:34.000000000 -0500
12981 ++++ linux-2.6.27.10/arch/x86/mm/pgtable_32.c 2008-11-18 03:38:44.000000000 -0500
12982 +@@ -31,6 +31,10 @@ void set_pte_vaddr(unsigned long vaddr,
12983 + pmd_t *pmd;
12984 + pte_t *pte;
12985 +
12986 ++#ifdef CONFIG_PAX_KERNEXEC
12987 ++ unsigned long cr0;
12988 ++#endif
12989 ++
12990 + pgd = swapper_pg_dir + pgd_index(vaddr);
12991 + if (pgd_none(*pgd)) {
12992 + BUG();
12993 +@@ -47,11 +51,20 @@ void set_pte_vaddr(unsigned long vaddr,
12994 + return;
12995 + }
12996 + pte = pte_offset_kernel(pmd, vaddr);
12997 ++
12998 ++#ifdef CONFIG_PAX_KERNEXEC
12999 ++ pax_open_kernel(cr0);
13000 ++#endif
13001 ++
13002 + if (pte_val(pteval))
13003 + set_pte_present(&init_mm, vaddr, pte, pteval);
13004 + else
13005 + pte_clear(&init_mm, vaddr, pte);
13006 +
13007 ++#ifdef CONFIG_PAX_KERNEXEC
13008 ++ pax_close_kernel(cr0);
13009 ++#endif
13010 ++
13011 + /*
13012 + * It's enough to flush this one mapping.
13013 + * (PGE mappings get flushed as well)
13014 +diff -urNp linux-2.6.27.10/arch/x86/oprofile/backtrace.c linux-2.6.27.10/arch/x86/oprofile/backtrace.c
13015 +--- linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-07 12:55:34.000000000 -0500
13016 ++++ linux-2.6.27.10/arch/x86/oprofile/backtrace.c 2008-11-18 03:38:44.000000000 -0500
13017 +@@ -37,7 +37,7 @@ static void backtrace_address(void *data
13018 + unsigned int *depth = data;
13019 +
13020 + if ((*depth)--)
13021 +- oprofile_add_trace(addr);
13022 ++ oprofile_add_trace(ktla_ktva(addr));
13023 + }
13024 +
13025 + static struct stacktrace_ops backtrace_ops = {
13026 +@@ -79,7 +79,7 @@ x86_backtrace(struct pt_regs * const reg
13027 + struct frame_head *head = (struct frame_head *)frame_pointer(regs);
13028 + unsigned long stack = kernel_trap_sp(regs);
13029 +
13030 +- if (!user_mode_vm(regs)) {
13031 ++ if (!user_mode(regs)) {
13032 + if (depth)
13033 + dump_trace(NULL, regs, (unsigned long *)stack, 0,
13034 + &backtrace_ops, &depth);
13035 +diff -urNp linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c
13036 +--- linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-07 12:55:34.000000000 -0500
13037 ++++ linux-2.6.27.10/arch/x86/oprofile/op_model_p4.c 2008-11-18 03:38:44.000000000 -0500
13038 +@@ -47,7 +47,7 @@ static inline void setup_num_counters(vo
13039 + #endif
13040 + }
13041 +
13042 +-static int inline addr_increment(void)
13043 ++static inline int addr_increment(void)
13044 + {
13045 + #ifdef CONFIG_SMP
13046 + return smp_num_siblings == 2 ? 2 : 1;
13047 +diff -urNp linux-2.6.27.10/arch/x86/pci/common.c linux-2.6.27.10/arch/x86/pci/common.c
13048 +--- linux-2.6.27.10/arch/x86/pci/common.c 2008-11-07 12:55:34.000000000 -0500
13049 ++++ linux-2.6.27.10/arch/x86/pci/common.c 2008-11-18 03:38:44.000000000 -0500
13050 +@@ -362,7 +362,7 @@ static struct dmi_system_id __devinitdat
13051 + DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
13052 + },
13053 + },
13054 +- {}
13055 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
13056 + };
13057 +
13058 + void __init dmi_check_pciprobe(void)
13059 +diff -urNp linux-2.6.27.10/arch/x86/pci/fixup.c linux-2.6.27.10/arch/x86/pci/fixup.c
13060 +--- linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-07 12:55:34.000000000 -0500
13061 ++++ linux-2.6.27.10/arch/x86/pci/fixup.c 2008-11-18 03:38:44.000000000 -0500
13062 +@@ -365,7 +365,7 @@ static struct dmi_system_id __devinitdat
13063 + DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
13064 + },
13065 + },
13066 +- {}
13067 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
13068 + };
13069 +
13070 + /*
13071 +@@ -436,7 +436,7 @@ static struct dmi_system_id __devinitdat
13072 + DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
13073 + },
13074 + },
13075 +- { }
13076 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
13077 + };
13078 +
13079 + static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
13080 +diff -urNp linux-2.6.27.10/arch/x86/pci/irq.c linux-2.6.27.10/arch/x86/pci/irq.c
13081 +--- linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-07 12:55:34.000000000 -0500
13082 ++++ linux-2.6.27.10/arch/x86/pci/irq.c 2008-11-18 03:38:44.000000000 -0500
13083 +@@ -544,7 +544,7 @@ static __init int intel_router_probe(str
13084 + static struct pci_device_id __initdata pirq_440gx[] = {
13085 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
13086 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
13087 +- { },
13088 ++ { PCI_DEVICE(0, 0) }
13089 + };
13090 +
13091 + /* 440GX has a proprietary PIRQ router -- don't use it */
13092 +@@ -1131,7 +1131,7 @@ static struct dmi_system_id __initdata p
13093 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
13094 + },
13095 + },
13096 +- { }
13097 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
13098 + };
13099 +
13100 + int __init pcibios_irq_init(void)
13101 +diff -urNp linux-2.6.27.10/arch/x86/pci/pcbios.c linux-2.6.27.10/arch/x86/pci/pcbios.c
13102 +--- linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-07 12:55:34.000000000 -0500
13103 ++++ linux-2.6.27.10/arch/x86/pci/pcbios.c 2008-11-18 03:38:44.000000000 -0500
13104 +@@ -57,50 +57,120 @@ union bios32 {
13105 + static struct {
13106 + unsigned long address;
13107 + unsigned short segment;
13108 +-} bios32_indirect = { 0, __KERNEL_CS };
13109 ++} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
13110 +
13111 + /*
13112 + * Returns the entry point for the given service, NULL on error
13113 + */
13114 +
13115 +-static unsigned long bios32_service(unsigned long service)
13116 ++static unsigned long __devinit bios32_service(unsigned long service)
13117 + {
13118 + unsigned char return_code; /* %al */
13119 + unsigned long address; /* %ebx */
13120 + unsigned long length; /* %ecx */
13121 + unsigned long entry; /* %edx */
13122 + unsigned long flags;
13123 ++ struct desc_struct d, *gdt;
13124 ++
13125 ++#ifdef CONFIG_PAX_KERNEXEC
13126 ++ unsigned long cr0;
13127 ++#endif
13128 +
13129 + local_irq_save(flags);
13130 +- __asm__("lcall *(%%edi); cld"
13131 ++
13132 ++ gdt = get_cpu_gdt_table(smp_processor_id());
13133 ++
13134 ++#ifdef CONFIG_PAX_KERNEXEC
13135 ++ pax_open_kernel(cr0);
13136 ++#endif
13137 ++
13138 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
13139 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
13140 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
13141 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
13142 ++
13143 ++#ifdef CONFIG_PAX_KERNEXEC
13144 ++ pax_close_kernel(cr0);
13145 ++#endif
13146 ++
13147 ++ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
13148 + : "=a" (return_code),
13149 + "=b" (address),
13150 + "=c" (length),
13151 + "=d" (entry)
13152 + : "0" (service),
13153 + "1" (0),
13154 +- "D" (&bios32_indirect));
13155 ++ "D" (&bios32_indirect),
13156 ++ "r"(__PCIBIOS_DS)
13157 ++ : "memory");
13158 ++
13159 ++#ifdef CONFIG_PAX_KERNEXEC
13160 ++ pax_open_kernel(cr0);
13161 ++#endif
13162 ++
13163 ++ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
13164 ++ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
13165 ++ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
13166 ++ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
13167 ++
13168 ++#ifdef CONFIG_PAX_KERNEXEC
13169 ++ pax_close_kernel(cr0);
13170 ++#endif
13171 ++
13172 + local_irq_restore(flags);
13173 +
13174 + switch (return_code) {
13175 +- case 0:
13176 +- return address + entry;
13177 +- case 0x80: /* Not present */
13178 +- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
13179 +- return 0;
13180 +- default: /* Shouldn't happen */
13181 +- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
13182 +- service, return_code);
13183 ++ case 0: {
13184 ++ int cpu;
13185 ++ unsigned char flags;
13186 ++
13187 ++ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
13188 ++ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
13189 ++ printk(KERN_WARNING "bios32_service: not valid\n");
13190 + return 0;
13191 ++ }
13192 ++ address = address + PAGE_OFFSET;
13193 ++ length += 16UL; /* some BIOSs underreport this... */
13194 ++ flags = 4;
13195 ++ if (length >= 64*1024*1024) {
13196 ++ length >>= PAGE_SHIFT;
13197 ++ flags |= 8;
13198 ++ }
13199 ++
13200 ++#ifdef CONFIG_PAX_KERNEXEC
13201 ++ pax_open_kernel(cr0);
13202 ++#endif
13203 ++
13204 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
13205 ++ gdt = get_cpu_gdt_table(cpu);
13206 ++ pack_descriptor(&d, address, length, 0x9b, flags);
13207 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
13208 ++ pack_descriptor(&d, address, length, 0x93, flags);
13209 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
13210 ++ }
13211 ++
13212 ++#ifdef CONFIG_PAX_KERNEXEC
13213 ++ pax_close_kernel(cr0);
13214 ++#endif
13215 ++
13216 ++ return entry;
13217 ++ }
13218 ++ case 0x80: /* Not present */
13219 ++ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
13220 ++ return 0;
13221 ++ default: /* Shouldn't happen */
13222 ++ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
13223 ++ service, return_code);
13224 ++ return 0;
13225 + }
13226 + }
13227 +
13228 + static struct {
13229 + unsigned long address;
13230 + unsigned short segment;
13231 +-} pci_indirect = { 0, __KERNEL_CS };
13232 ++} pci_indirect __read_only = { 0, __PCIBIOS_CS };
13233 +
13234 +-static int pci_bios_present;
13235 ++static int pci_bios_present __read_only;
13236 +
13237 + static int __devinit check_pcibios(void)
13238 + {
13239 +@@ -109,11 +179,13 @@ static int __devinit check_pcibios(void)
13240 + unsigned long flags, pcibios_entry;
13241 +
13242 + if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
13243 +- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
13244 ++ pci_indirect.address = pcibios_entry;
13245 +
13246 + local_irq_save(flags);
13247 +- __asm__(
13248 +- "lcall *(%%edi); cld\n\t"
13249 ++ __asm__("movw %w6, %%ds\n\t"
13250 ++ "lcall *%%ss:(%%edi); cld\n\t"
13251 ++ "push %%ss\n\t"
13252 ++ "pop %%ds\n\t"
13253 + "jc 1f\n\t"
13254 + "xor %%ah, %%ah\n"
13255 + "1:"
13256 +@@ -122,7 +194,8 @@ static int __devinit check_pcibios(void)
13257 + "=b" (ebx),
13258 + "=c" (ecx)
13259 + : "1" (PCIBIOS_PCI_BIOS_PRESENT),
13260 +- "D" (&pci_indirect)
13261 ++ "D" (&pci_indirect),
13262 ++ "r" (__PCIBIOS_DS)
13263 + : "memory");
13264 + local_irq_restore(flags);
13265 +
13266 +@@ -166,7 +239,10 @@ static int pci_bios_read(unsigned int se
13267 +
13268 + switch (len) {
13269 + case 1:
13270 +- __asm__("lcall *(%%esi); cld\n\t"
13271 ++ __asm__("movw %w6, %%ds\n\t"
13272 ++ "lcall *%%ss:(%%esi); cld\n\t"
13273 ++ "push %%ss\n\t"
13274 ++ "pop %%ds\n\t"
13275 + "jc 1f\n\t"
13276 + "xor %%ah, %%ah\n"
13277 + "1:"
13278 +@@ -175,7 +251,8 @@ static int pci_bios_read(unsigned int se
13279 + : "1" (PCIBIOS_READ_CONFIG_BYTE),
13280 + "b" (bx),
13281 + "D" ((long)reg),
13282 +- "S" (&pci_indirect));
13283 ++ "S" (&pci_indirect),
13284 ++ "r" (__PCIBIOS_DS));
13285 + /*
13286 + * Zero-extend the result beyond 8 bits, do not trust the
13287 + * BIOS having done it:
13288 +@@ -183,7 +260,10 @@ static int pci_bios_read(unsigned int se
13289 + *value &= 0xff;
13290 + break;
13291 + case 2:
13292 +- __asm__("lcall *(%%esi); cld\n\t"
13293 ++ __asm__("movw %w6, %%ds\n\t"
13294 ++ "lcall *%%ss:(%%esi); cld\n\t"
13295 ++ "push %%ss\n\t"
13296 ++ "pop %%ds\n\t"
13297 + "jc 1f\n\t"
13298 + "xor %%ah, %%ah\n"
13299 + "1:"
13300 +@@ -192,7 +272,8 @@ static int pci_bios_read(unsigned int se
13301 + : "1" (PCIBIOS_READ_CONFIG_WORD),
13302 + "b" (bx),
13303 + "D" ((long)reg),
13304 +- "S" (&pci_indirect));
13305 ++ "S" (&pci_indirect),
13306 ++ "r" (__PCIBIOS_DS));
13307 + /*
13308 + * Zero-extend the result beyond 16 bits, do not trust the
13309 + * BIOS having done it:
13310 +@@ -200,7 +281,10 @@ static int pci_bios_read(unsigned int se
13311 + *value &= 0xffff;
13312 + break;
13313 + case 4:
13314 +- __asm__("lcall *(%%esi); cld\n\t"
13315 ++ __asm__("movw %w6, %%ds\n\t"
13316 ++ "lcall *%%ss:(%%esi); cld\n\t"
13317 ++ "push %%ss\n\t"
13318 ++ "pop %%ds\n\t"
13319 + "jc 1f\n\t"
13320 + "xor %%ah, %%ah\n"
13321 + "1:"
13322 +@@ -209,7 +293,8 @@ static int pci_bios_read(unsigned int se
13323 + : "1" (PCIBIOS_READ_CONFIG_DWORD),
13324 + "b" (bx),
13325 + "D" ((long)reg),
13326 +- "S" (&pci_indirect));
13327 ++ "S" (&pci_indirect),
13328 ++ "r" (__PCIBIOS_DS));
13329 + break;
13330 + }
13331 +
13332 +@@ -232,7 +317,10 @@ static int pci_bios_write(unsigned int s
13333 +
13334 + switch (len) {
13335 + case 1:
13336 +- __asm__("lcall *(%%esi); cld\n\t"
13337 ++ __asm__("movw %w6, %%ds\n\t"
13338 ++ "lcall *%%ss:(%%esi); cld\n\t"
13339 ++ "push %%ss\n\t"
13340 ++ "pop %%ds\n\t"
13341 + "jc 1f\n\t"
13342 + "xor %%ah, %%ah\n"
13343 + "1:"
13344 +@@ -241,10 +329,14 @@ static int pci_bios_write(unsigned int s
13345 + "c" (value),
13346 + "b" (bx),
13347 + "D" ((long)reg),
13348 +- "S" (&pci_indirect));
13349 ++ "S" (&pci_indirect),
13350 ++ "r" (__PCIBIOS_DS));
13351 + break;
13352 + case 2:
13353 +- __asm__("lcall *(%%esi); cld\n\t"
13354 ++ __asm__("movw %w6, %%ds\n\t"
13355 ++ "lcall *%%ss:(%%esi); cld\n\t"
13356 ++ "push %%ss\n\t"
13357 ++ "pop %%ds\n\t"
13358 + "jc 1f\n\t"
13359 + "xor %%ah, %%ah\n"
13360 + "1:"
13361 +@@ -253,10 +345,14 @@ static int pci_bios_write(unsigned int s
13362 + "c" (value),
13363 + "b" (bx),
13364 + "D" ((long)reg),
13365 +- "S" (&pci_indirect));
13366 ++ "S" (&pci_indirect),
13367 ++ "r" (__PCIBIOS_DS));
13368 + break;
13369 + case 4:
13370 +- __asm__("lcall *(%%esi); cld\n\t"
13371 ++ __asm__("movw %w6, %%ds\n\t"
13372 ++ "lcall *%%ss:(%%esi); cld\n\t"
13373 ++ "push %%ss\n\t"
13374 ++ "pop %%ds\n\t"
13375 + "jc 1f\n\t"
13376 + "xor %%ah, %%ah\n"
13377 + "1:"
13378 +@@ -265,7 +361,8 @@ static int pci_bios_write(unsigned int s
13379 + "c" (value),
13380 + "b" (bx),
13381 + "D" ((long)reg),
13382 +- "S" (&pci_indirect));
13383 ++ "S" (&pci_indirect),
13384 ++ "r" (__PCIBIOS_DS));
13385 + break;
13386 + }
13387 +
13388 +@@ -369,10 +466,13 @@ struct irq_routing_table * pcibios_get_i
13389 +
13390 + DBG("PCI: Fetching IRQ routing table... ");
13391 + __asm__("push %%es\n\t"
13392 ++ "movw %w8, %%ds\n\t"
13393 + "push %%ds\n\t"
13394 + "pop %%es\n\t"
13395 +- "lcall *(%%esi); cld\n\t"
13396 ++ "lcall *%%ss:(%%esi); cld\n\t"
13397 + "pop %%es\n\t"
13398 ++ "push %%ss\n\t"
13399 ++ "pop %%ds\n"
13400 + "jc 1f\n\t"
13401 + "xor %%ah, %%ah\n"
13402 + "1:"
13403 +@@ -383,7 +483,8 @@ struct irq_routing_table * pcibios_get_i
13404 + "1" (0),
13405 + "D" ((long) &opt),
13406 + "S" (&pci_indirect),
13407 +- "m" (opt)
13408 ++ "m" (opt),
13409 ++ "r" (__PCIBIOS_DS)
13410 + : "memory");
13411 + DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
13412 + if (ret & 0xff00)
13413 +@@ -407,7 +508,10 @@ int pcibios_set_irq_routing(struct pci_d
13414 + {
13415 + int ret;
13416 +
13417 +- __asm__("lcall *(%%esi); cld\n\t"
13418 ++ __asm__("movw %w5, %%ds\n\t"
13419 ++ "lcall *%%ss:(%%esi); cld\n\t"
13420 ++ "push %%ss\n\t"
13421 ++ "pop %%ds\n"
13422 + "jc 1f\n\t"
13423 + "xor %%ah, %%ah\n"
13424 + "1:"
13425 +@@ -415,7 +519,8 @@ int pcibios_set_irq_routing(struct pci_d
13426 + : "0" (PCIBIOS_SET_PCI_HW_INT),
13427 + "b" ((dev->bus->number << 8) | dev->devfn),
13428 + "c" ((irq << 8) | (pin + 10)),
13429 +- "S" (&pci_indirect));
13430 ++ "S" (&pci_indirect),
13431 ++ "r" (__PCIBIOS_DS));
13432 + return !(ret & 0xff00);
13433 + }
13434 + EXPORT_SYMBOL(pcibios_set_irq_routing);
13435 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_32.c linux-2.6.27.10/arch/x86/power/cpu_32.c
13436 +--- linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-07 12:55:34.000000000 -0500
13437 ++++ linux-2.6.27.10/arch/x86/power/cpu_32.c 2008-11-18 03:38:44.000000000 -0500
13438 +@@ -66,7 +66,7 @@ static void do_fpu_end(void)
13439 + static void fix_processor_context(void)
13440 + {
13441 + int cpu = smp_processor_id();
13442 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
13443 ++ struct tss_struct *t = init_tss + cpu;
13444 +
13445 + set_tss_desc(cpu, t); /*
13446 + * This just modifies memory; should not be
13447 +diff -urNp linux-2.6.27.10/arch/x86/power/cpu_64.c linux-2.6.27.10/arch/x86/power/cpu_64.c
13448 +--- linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-07 12:55:34.000000000 -0500
13449 ++++ linux-2.6.27.10/arch/x86/power/cpu_64.c 2008-11-18 03:38:44.000000000 -0500
13450 +@@ -136,7 +136,11 @@ void restore_processor_state(void)
13451 + static void fix_processor_context(void)
13452 + {
13453 + int cpu = smp_processor_id();
13454 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
13455 ++ struct tss_struct *t = init_tss + cpu;
13456 ++
13457 ++#ifdef CONFIG_PAX_KERNEXEC
13458 ++ unsigned long cr0;
13459 ++#endif
13460 +
13461 + /*
13462 + * This just modifies memory; should not be necessary. But... This
13463 +@@ -145,8 +149,16 @@ static void fix_processor_context(void)
13464 + */
13465 + set_tss_desc(cpu, t);
13466 +
13467 ++#ifdef CONFIG_PAX_KERNEXEC
13468 ++ pax_open_kernel(cr0);
13469 ++#endif
13470 ++
13471 + get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
13472 +
13473 ++#ifdef CONFIG_PAX_KERNEXEC
13474 ++ pax_close_kernel(cr0);
13475 ++#endif
13476 ++
13477 + syscall_init(); /* This sets MSR_*STAR and related */
13478 + load_TR_desc(); /* This does ltr */
13479 + load_LDT(&current->active_mm->context); /* This does lldt */
13480 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c
13481 +--- linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-07 12:55:34.000000000 -0500
13482 ++++ linux-2.6.27.10/arch/x86/vdso/vdso32-setup.c 2008-11-18 03:38:44.000000000 -0500
13483 +@@ -226,7 +226,7 @@ static inline void map_compat_vdso(int m
13484 + void enable_sep_cpu(void)
13485 + {
13486 + int cpu = get_cpu();
13487 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
13488 ++ struct tss_struct *tss = init_tss + cpu;
13489 +
13490 + if (!boot_cpu_has(X86_FEATURE_SEP)) {
13491 + put_cpu();
13492 +@@ -249,7 +249,7 @@ static int __init gate_vma_init(void)
13493 + gate_vma.vm_start = FIXADDR_USER_START;
13494 + gate_vma.vm_end = FIXADDR_USER_END;
13495 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
13496 +- gate_vma.vm_page_prot = __P101;
13497 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
13498 + /*
13499 + * Make sure the vDSO gets into every core dump.
13500 + * Dumping its contents makes post-mortem fully interpretable later
13501 +@@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct l
13502 + if (compat)
13503 + addr = VDSO_HIGH_BASE;
13504 + else {
13505 +- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
13506 ++ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
13507 + if (IS_ERR_VALUE(addr)) {
13508 + ret = addr;
13509 + goto up_fail;
13510 +@@ -358,7 +358,7 @@ int arch_setup_additional_pages(struct l
13511 + goto up_fail;
13512 + }
13513 +
13514 +- current->mm->context.vdso = (void *)addr;
13515 ++ current->mm->context.vdso = addr;
13516 + current_thread_info()->sysenter_return =
13517 + VDSO32_SYMBOL(addr, SYSENTER_RETURN);
13518 +
13519 +@@ -384,7 +384,7 @@ static ctl_table abi_table2[] = {
13520 + .mode = 0644,
13521 + .proc_handler = proc_dointvec
13522 + },
13523 +- {}
13524 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
13525 + };
13526 +
13527 + static ctl_table abi_root_table2[] = {
13528 +@@ -394,7 +394,7 @@ static ctl_table abi_root_table2[] = {
13529 + .mode = 0555,
13530 + .child = abi_table2
13531 + },
13532 +- {}
13533 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
13534 + };
13535 +
13536 + static __init int ia32_binfmt_init(void)
13537 +@@ -409,8 +409,14 @@ __initcall(ia32_binfmt_init);
13538 +
13539 + const char *arch_vma_name(struct vm_area_struct *vma)
13540 + {
13541 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
13542 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
13543 + return "[vdso]";
13544 ++
13545 ++#ifdef CONFIG_PAX_SEGMEXEC
13546 ++ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
13547 ++ return "[vdso]";
13548 ++#endif
13549 ++
13550 + return NULL;
13551 + }
13552 +
13553 +@@ -419,7 +425,7 @@ struct vm_area_struct *get_gate_vma(stru
13554 + struct mm_struct *mm = tsk->mm;
13555 +
13556 + /* Check to see if this task was created in compat vdso mode */
13557 +- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
13558 ++ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
13559 + return &gate_vma;
13560 + return NULL;
13561 + }
13562 +diff -urNp linux-2.6.27.10/arch/x86/vdso/vma.c linux-2.6.27.10/arch/x86/vdso/vma.c
13563 +--- linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-07 12:55:34.000000000 -0500
13564 ++++ linux-2.6.27.10/arch/x86/vdso/vma.c 2008-11-18 03:38:44.000000000 -0500
13565 +@@ -123,7 +123,7 @@ int arch_setup_additional_pages(struct l
13566 + if (ret)
13567 + goto up_fail;
13568 +
13569 +- current->mm->context.vdso = (void *)addr;
13570 ++ current->mm->context.vdso = addr;
13571 + up_fail:
13572 + up_write(&mm->mmap_sem);
13573 + return ret;
13574 +diff -urNp linux-2.6.27.10/arch/x86/xen/enlighten.c linux-2.6.27.10/arch/x86/xen/enlighten.c
13575 +--- linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:37.000000000 -0500
13576 ++++ linux-2.6.27.10/arch/x86/xen/enlighten.c 2008-12-10 22:35:46.000000000 -0500
13577 +@@ -343,7 +343,7 @@ static void xen_set_ldt(const void *addr
13578 + static void xen_load_gdt(const struct desc_ptr *dtr)
13579 + {
13580 + unsigned long *frames;
13581 +- unsigned long va = dtr->address;
13582 ++ unsigned long va = (unsigned long)dtr->address;
13583 + unsigned int size = dtr->size + 1;
13584 + unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
13585 + int f;
13586 +@@ -358,7 +358,7 @@ static void xen_load_gdt(const struct de
13587 + mcs = xen_mc_entry(sizeof(*frames) * pages);
13588 + frames = mcs.args;
13589 +
13590 +- for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
13591 ++ for (f = 0; va < (unsigned long)dtr->address + size; va += PAGE_SIZE, f++) {
13592 + frames[f] = virt_to_mfn(va);
13593 + make_lowmem_page_readonly((void *)va);
13594 + }
13595 +@@ -467,7 +467,7 @@ static void xen_write_idt_entry(gate_des
13596 +
13597 + preempt_disable();
13598 +
13599 +- start = __get_cpu_var(idt_desc).address;
13600 ++ start = (unsigned long)__get_cpu_var(idt_desc).address;
13601 + end = start + __get_cpu_var(idt_desc).size + 1;
13602 +
13603 + xen_mc_flush();
13604 +@@ -1574,6 +1574,8 @@ static __init pgd_t *xen_setup_kernel_pa
13605 + convert_pfn_mfn(init_level4_pgt);
13606 + convert_pfn_mfn(level3_ident_pgt);
13607 + convert_pfn_mfn(level3_kernel_pgt);
13608 ++ convert_pfn_mfn(level3_vmalloc_pgt);
13609 ++ convert_pfn_mfn(level3_vmemmap_pgt);
13610 +
13611 + l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
13612 + l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
13613 +@@ -1592,9 +1594,12 @@ static __init pgd_t *xen_setup_kernel_pa
13614 + set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
13615 + set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
13616 + set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
13617 ++ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
13618 ++ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
13619 + set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
13620 + set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
13621 + set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
13622 ++ set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
13623 +
13624 + /* Pin down new L4 */
13625 + pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
13626 +diff -urNp linux-2.6.27.10/arch/x86/xen/smp.c linux-2.6.27.10/arch/x86/xen/smp.c
13627 +--- linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-07 12:55:34.000000000 -0500
13628 ++++ linux-2.6.27.10/arch/x86/xen/smp.c 2008-11-18 03:38:44.000000000 -0500
13629 +@@ -170,11 +170,6 @@ static void __init xen_smp_prepare_boot_
13630 + {
13631 + BUG_ON(smp_processor_id() != 0);
13632 + native_smp_prepare_boot_cpu();
13633 +-
13634 +- /* We've switched to the "real" per-cpu gdt, so make sure the
13635 +- old memory can be recycled */
13636 +- make_lowmem_page_readwrite(&per_cpu_var(gdt_page));
13637 +-
13638 + xen_setup_vcpu_info_placement();
13639 + }
13640 +
13641 +@@ -232,8 +227,8 @@ cpu_initialize_context(unsigned int cpu,
13642 + gdt = get_cpu_gdt_table(cpu);
13643 +
13644 + ctxt->flags = VGCF_IN_KERNEL;
13645 +- ctxt->user_regs.ds = __USER_DS;
13646 +- ctxt->user_regs.es = __USER_DS;
13647 ++ ctxt->user_regs.ds = __KERNEL_DS;
13648 ++ ctxt->user_regs.es = __KERNEL_DS;
13649 + ctxt->user_regs.ss = __KERNEL_DS;
13650 + #ifdef CONFIG_X86_32
13651 + ctxt->user_regs.fs = __KERNEL_PERCPU;
13652 +diff -urNp linux-2.6.27.10/crypto/async_tx/async_tx.c linux-2.6.27.10/crypto/async_tx/async_tx.c
13653 +--- linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-07 12:55:34.000000000 -0500
13654 ++++ linux-2.6.27.10/crypto/async_tx/async_tx.c 2008-11-18 03:38:44.000000000 -0500
13655 +@@ -358,8 +358,8 @@ async_tx_init(void)
13656 + err:
13657 + printk(KERN_ERR "async_tx: initialization failure\n");
13658 +
13659 +- while (--cap >= 0)
13660 +- free_percpu(channel_table[cap]);
13661 ++ while (cap)
13662 ++ free_percpu(channel_table[--cap]);
13663 +
13664 + return 1;
13665 + }
13666 +diff -urNp linux-2.6.27.10/crypto/lrw.c linux-2.6.27.10/crypto/lrw.c
13667 +--- linux-2.6.27.10/crypto/lrw.c 2008-11-07 12:55:34.000000000 -0500
13668 ++++ linux-2.6.27.10/crypto/lrw.c 2008-11-18 03:38:44.000000000 -0500
13669 +@@ -54,7 +54,7 @@ static int setkey(struct crypto_tfm *par
13670 + struct priv *ctx = crypto_tfm_ctx(parent);
13671 + struct crypto_cipher *child = ctx->child;
13672 + int err, i;
13673 +- be128 tmp = { 0 };
13674 ++ be128 tmp = { 0, 0 };
13675 + int bsize = crypto_cipher_blocksize(child);
13676 +
13677 + crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
13678 +diff -urNp linux-2.6.27.10/Documentation/dontdiff linux-2.6.27.10/Documentation/dontdiff
13679 +--- linux-2.6.27.10/Documentation/dontdiff 2008-11-07 12:55:34.000000000 -0500
13680 ++++ linux-2.6.27.10/Documentation/dontdiff 2008-11-18 03:39:50.000000000 -0500
13681 +@@ -3,6 +3,7 @@
13682 + *.bin
13683 + *.cpio
13684 + *.css
13685 ++*.dbg
13686 + *.dvi
13687 + *.eps
13688 + *.fw.gen.S
13689 +@@ -53,9 +54,14 @@ COPYING
13690 + CREDITS
13691 + CVS
13692 + ChangeSet
13693 ++GPATH
13694 ++GRTAGS
13695 ++GSYMS
13696 ++GTAGS
13697 + Image
13698 + Kerntypes
13699 + MODS.txt
13700 ++Module.markers
13701 + Module.symvers
13702 + PENDING
13703 + SCCS
13704 +@@ -66,7 +72,6 @@ aic7*reg_print.c*
13705 + aic7*seq.h*
13706 + aicasm
13707 + aicdb.h*
13708 +-asm
13709 + asm-offsets.h
13710 + asm_offsets.h
13711 + autoconf.h*
13712 +@@ -74,6 +79,7 @@ bbootsect
13713 + bin2c
13714 + binkernel.spec
13715 + bootsect
13716 ++bounds.h
13717 + bsetup
13718 + btfixupprep
13719 + build
13720 +@@ -90,6 +96,7 @@ config_data.gz*
13721 + conmakehash
13722 + consolemap_deftbl.c*
13723 + crc32table.h*
13724 ++cpustr.h
13725 + cscope.*
13726 + defkeymap.c*
13727 + devlist.h*
13728 +@@ -138,6 +145,7 @@ miboot*
13729 + mk_elfconfig
13730 + mkboot
13731 + mkbugboot
13732 ++mkcpustr
13733 + mkdep
13734 + mkprep
13735 + mktables
13736 +@@ -179,16 +187,21 @@ times.h*
13737 + tkparse
13738 + trix_boot.h
13739 + utsrelease.h*
13740 +-vdso.lds
13741 ++vdso*.lds
13742 + version.h*
13743 + vmlinux
13744 + vmlinux-*
13745 + vmlinux.aout
13746 +-vmlinux*.lds*
13747 ++vmlinux.bin.all
13748 ++vmlinux*.lds
13749 ++vmlinux.relocs
13750 + vmlinux*.scr
13751 +-vsyscall.lds
13752 ++vsyscall*.lds
13753 ++wakeup.elf
13754 ++wakeup.lds
13755 + wanxlfw.inc
13756 + uImage
13757 + unifdef
13758 ++utsrelease.h
13759 + zImage*
13760 + zconf.hash.c
13761 +diff -urNp linux-2.6.27.10/drivers/acpi/blacklist.c linux-2.6.27.10/drivers/acpi/blacklist.c
13762 +--- linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-07 12:55:34.000000000 -0500
13763 ++++ linux-2.6.27.10/drivers/acpi/blacklist.c 2008-11-18 03:38:44.000000000 -0500
13764 +@@ -71,7 +71,7 @@ static struct acpi_blacklist_item acpi_b
13765 + {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
13766 + "Incorrect _ADR", 1},
13767 +
13768 +- {""}
13769 ++ {"", "", 0, 0, 0, all_versions, 0}
13770 + };
13771 +
13772 + #if CONFIG_ACPI_BLACKLIST_YEAR
13773 +diff -urNp linux-2.6.27.10/drivers/acpi/osl.c linux-2.6.27.10/drivers/acpi/osl.c
13774 +--- linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:16:51.000000000 -0500
13775 ++++ linux-2.6.27.10/drivers/acpi/osl.c 2008-12-21 01:13:45.000000000 -0500
13776 +@@ -494,6 +494,8 @@ acpi_os_read_memory(acpi_physical_addres
13777 + void __iomem *virt_addr;
13778 +
13779 + virt_addr = ioremap(phys_addr, width);
13780 ++ if (!virt_addr)
13781 ++ return AE_NO_MEMORY;
13782 + if (!value)
13783 + value = &dummy;
13784 +
13785 +@@ -522,6 +524,8 @@ acpi_os_write_memory(acpi_physical_addre
13786 + void __iomem *virt_addr;
13787 +
13788 + virt_addr = ioremap(phys_addr, width);
13789 ++ if (!virt_addr)
13790 ++ return AE_NO_MEMORY;
13791 +
13792 + switch (width) {
13793 + case 8:
13794 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_core.c linux-2.6.27.10/drivers/acpi/processor_core.c
13795 +--- linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-07 12:55:34.000000000 -0500
13796 ++++ linux-2.6.27.10/drivers/acpi/processor_core.c 2008-11-18 03:38:44.000000000 -0500
13797 +@@ -667,7 +667,7 @@ static int __cpuinit acpi_processor_star
13798 + return 0;
13799 + }
13800 +
13801 +- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
13802 ++ BUG_ON(pr->id >= nr_cpu_ids);
13803 +
13804 + /*
13805 + * Buggy BIOS check
13806 +diff -urNp linux-2.6.27.10/drivers/acpi/processor_idle.c linux-2.6.27.10/drivers/acpi/processor_idle.c
13807 +--- linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-07 12:55:34.000000000 -0500
13808 ++++ linux-2.6.27.10/drivers/acpi/processor_idle.c 2008-11-18 03:38:44.000000000 -0500
13809 +@@ -182,7 +182,7 @@ static struct dmi_system_id __cpuinitdat
13810 + DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
13811 + DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
13812 + (void *)2},
13813 +- {},
13814 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL},
13815 + };
13816 +
13817 + static inline u32 ticks_elapsed(u32 t1, u32 t2)
13818 +diff -urNp linux-2.6.27.10/drivers/acpi/tables/tbfadt.c linux-2.6.27.10/drivers/acpi/tables/tbfadt.c
13819 +--- linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-07 12:55:34.000000000 -0500
13820 ++++ linux-2.6.27.10/drivers/acpi/tables/tbfadt.c 2008-11-18 03:38:44.000000000 -0500
13821 +@@ -48,7 +48,7 @@
13822 + ACPI_MODULE_NAME("tbfadt")
13823 +
13824 + /* Local prototypes */
13825 +-static void inline
13826 ++static inline void
13827 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
13828 + u8 bit_width, u64 address);
13829 +
13830 +@@ -122,7 +122,7 @@ static struct acpi_fadt_info fadt_info_t
13831 + *
13832 + ******************************************************************************/
13833 +
13834 +-static void inline
13835 ++static inline void
13836 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
13837 + u8 bit_width, u64 address)
13838 + {
13839 +diff -urNp linux-2.6.27.10/drivers/ata/ahci.c linux-2.6.27.10/drivers/ata/ahci.c
13840 +--- linux-2.6.27.10/drivers/ata/ahci.c 2008-11-07 12:55:34.000000000 -0500
13841 ++++ linux-2.6.27.10/drivers/ata/ahci.c 2008-11-18 03:38:44.000000000 -0500
13842 +@@ -591,7 +591,7 @@ static const struct pci_device_id ahci_p
13843 + { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
13844 + PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
13845 +
13846 +- { } /* terminate list */
13847 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
13848 + };
13849 +
13850 +
13851 +diff -urNp linux-2.6.27.10/drivers/ata/ata_piix.c linux-2.6.27.10/drivers/ata/ata_piix.c
13852 +--- linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-07 12:55:34.000000000 -0500
13853 ++++ linux-2.6.27.10/drivers/ata/ata_piix.c 2008-11-18 03:38:44.000000000 -0500
13854 +@@ -284,7 +284,7 @@ static const struct pci_device_id piix_p
13855 + /* SATA Controller IDE (PCH) */
13856 + { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
13857 +
13858 +- { } /* terminate list */
13859 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
13860 + };
13861 +
13862 + static struct pci_driver piix_pci_driver = {
13863 +@@ -587,7 +587,7 @@ static const struct ich_laptop ich_lapto
13864 + { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
13865 + { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
13866 + /* end marker */
13867 +- { 0, }
13868 ++ { 0, 0, 0 }
13869 + };
13870 +
13871 + /**
13872 +@@ -1143,7 +1143,7 @@ static int piix_broken_suspend(void)
13873 + },
13874 + },
13875 +
13876 +- { } /* terminate list */
13877 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL } /* terminate list */
13878 + };
13879 + static const char *oemstrs[] = {
13880 + "Tecra M3,",
13881 +diff -urNp linux-2.6.27.10/drivers/ata/libata-core.c linux-2.6.27.10/drivers/ata/libata-core.c
13882 +--- linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:11.000000000 -0500
13883 ++++ linux-2.6.27.10/drivers/ata/libata-core.c 2008-12-21 01:18:21.000000000 -0500
13884 +@@ -746,7 +746,7 @@ static const struct ata_xfer_ent {
13885 + { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
13886 + { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
13887 + { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
13888 +- { -1, },
13889 ++ { -1, 0, 0 }
13890 + };
13891 +
13892 + /**
13893 +@@ -2917,7 +2917,7 @@ static const struct ata_timing ata_timin
13894 + { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
13895 + { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
13896 +
13897 +- { 0xFF }
13898 ++ { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
13899 + };
13900 +
13901 + #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
13902 +@@ -4073,7 +4073,7 @@ static const struct ata_blacklist_entry
13903 + { "TSSTcorp CDDVDW SH-S202N", "SB01", ATA_HORKAGE_IVB, },
13904 +
13905 + /* End Marker */
13906 +- { }
13907 ++ { NULL, NULL, 0 }
13908 + };
13909 +
13910 + static int strn_pattern_cmp(const char *patt, const char *name, int wildchar)
13911 +diff -urNp linux-2.6.27.10/drivers/char/agp/frontend.c linux-2.6.27.10/drivers/char/agp/frontend.c
13912 +--- linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-07 12:55:34.000000000 -0500
13913 ++++ linux-2.6.27.10/drivers/char/agp/frontend.c 2008-11-18 03:38:44.000000000 -0500
13914 +@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
13915 + if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
13916 + return -EFAULT;
13917 +
13918 +- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
13919 ++ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
13920 + return -EFAULT;
13921 +
13922 + client = agp_find_client_by_pid(reserve.pid);
13923 +diff -urNp linux-2.6.27.10/drivers/char/agp/intel-agp.c linux-2.6.27.10/drivers/char/agp/intel-agp.c
13924 +--- linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-07 12:55:34.000000000 -0500
13925 ++++ linux-2.6.27.10/drivers/char/agp/intel-agp.c 2008-11-18 03:38:44.000000000 -0500
13926 +@@ -2332,7 +2332,7 @@ static struct pci_device_id agp_intel_pc
13927 + ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
13928 + ID(PCI_DEVICE_ID_INTEL_Q45_HB),
13929 + ID(PCI_DEVICE_ID_INTEL_G45_HB),
13930 +- { }
13931 ++ { 0, 0, 0, 0, 0, 0, 0 }
13932 + };
13933 +
13934 + MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
13935 +diff -urNp linux-2.6.27.10/drivers/char/hpet.c linux-2.6.27.10/drivers/char/hpet.c
13936 +--- linux-2.6.27.10/drivers/char/hpet.c 2008-11-07 12:55:34.000000000 -0500
13937 ++++ linux-2.6.27.10/drivers/char/hpet.c 2008-11-18 03:38:44.000000000 -0500
13938 +@@ -959,7 +959,7 @@ static struct acpi_driver hpet_acpi_driv
13939 + },
13940 + };
13941 +
13942 +-static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
13943 ++static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
13944 +
13945 + static int __init hpet_init(void)
13946 + {
13947 +diff -urNp linux-2.6.27.10/drivers/char/keyboard.c linux-2.6.27.10/drivers/char/keyboard.c
13948 +--- linux-2.6.27.10/drivers/char/keyboard.c 2008-11-07 12:55:34.000000000 -0500
13949 ++++ linux-2.6.27.10/drivers/char/keyboard.c 2008-11-18 03:38:44.000000000 -0500
13950 +@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
13951 + kbd->kbdmode == VC_MEDIUMRAW) &&
13952 + value != KVAL(K_SAK))
13953 + return; /* SAK is allowed even in raw mode */
13954 ++
13955 ++#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
13956 ++ {
13957 ++ void *func = fn_handler[value];
13958 ++ if (func == fn_show_state || func == fn_show_ptregs ||
13959 ++ func == fn_show_mem)
13960 ++ return;
13961 ++ }
13962 ++#endif
13963 ++
13964 + fn_handler[value](vc);
13965 + }
13966 +
13967 +@@ -1388,7 +1398,7 @@ static const struct input_device_id kbd_
13968 + .evbit = { BIT_MASK(EV_SND) },
13969 + },
13970 +
13971 +- { }, /* Terminating entry */
13972 ++ { 0 }, /* Terminating entry */
13973 + };
13974 +
13975 + MODULE_DEVICE_TABLE(input, kbd_ids);
13976 +diff -urNp linux-2.6.27.10/drivers/char/mem.c linux-2.6.27.10/drivers/char/mem.c
13977 +--- linux-2.6.27.10/drivers/char/mem.c 2008-11-07 12:55:34.000000000 -0500
13978 ++++ linux-2.6.27.10/drivers/char/mem.c 2008-11-18 03:38:44.000000000 -0500
13979 +@@ -27,6 +27,7 @@
13980 + #include <linux/splice.h>
13981 + #include <linux/pfn.h>
13982 + #include <linux/smp_lock.h>
13983 ++#include <linux/grsecurity.h>
13984 +
13985 + #include <asm/uaccess.h>
13986 + #include <asm/io.h>
13987 +@@ -35,6 +36,10 @@
13988 + # include <linux/efi.h>
13989 + #endif
13990 +
13991 ++#ifdef CONFIG_GRKERNSEC
13992 ++extern struct file_operations grsec_fops;
13993 ++#endif
13994 ++
13995 + /*
13996 + * Architectures vary in how they handle caching for addresses
13997 + * outside of main memory.
13998 +@@ -192,6 +197,11 @@ static ssize_t write_mem(struct file * f
13999 + if (!valid_phys_addr_range(p, count))
14000 + return -EFAULT;
14001 +
14002 ++#ifdef CONFIG_GRKERNSEC_KMEM
14003 ++ gr_handle_mem_write();
14004 ++ return -EPERM;
14005 ++#endif
14006 ++
14007 + written = 0;
14008 +
14009 + #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
14010 +@@ -350,6 +360,11 @@ static int mmap_mem(struct file * file,
14011 + &vma->vm_page_prot))
14012 + return -EINVAL;
14013 +
14014 ++#ifdef CONFIG_GRKERNSEC_KMEM
14015 ++ if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
14016 ++ return -EPERM;
14017 ++#endif
14018 ++
14019 + vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
14020 + size,
14021 + vma->vm_page_prot);
14022 +@@ -588,6 +603,11 @@ static ssize_t write_kmem(struct file *
14023 + ssize_t written;
14024 + char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
14025 +
14026 ++#ifdef CONFIG_GRKERNSEC_KMEM
14027 ++ gr_handle_kmem_write();
14028 ++ return -EPERM;
14029 ++#endif
14030 ++
14031 + if (p < (unsigned long) high_memory) {
14032 +
14033 + wrote = count;
14034 +@@ -791,6 +811,16 @@ static loff_t memory_lseek(struct file *
14035 +
14036 + static int open_port(struct inode * inode, struct file * filp)
14037 + {
14038 ++#ifdef CONFIG_GRKERNSEC_KMEM
14039 ++ gr_handle_open_port();
14040 ++ return -EPERM;
14041 ++#endif
14042 ++
14043 ++ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
14044 ++}
14045 ++
14046 ++static int open_mem(struct inode * inode, struct file * filp)
14047 ++{
14048 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
14049 + }
14050 +
14051 +@@ -798,7 +828,6 @@ static int open_port(struct inode * inod
14052 + #define full_lseek null_lseek
14053 + #define write_zero write_null
14054 + #define read_full read_zero
14055 +-#define open_mem open_port
14056 + #define open_kmem open_mem
14057 + #define open_oldmem open_mem
14058 +
14059 +@@ -938,6 +967,11 @@ static int memory_open(struct inode * in
14060 + filp->f_op = &oldmem_fops;
14061 + break;
14062 + #endif
14063 ++#ifdef CONFIG_GRKERNSEC
14064 ++ case 13:
14065 ++ filp->f_op = &grsec_fops;
14066 ++ break;
14067 ++#endif
14068 + default:
14069 + unlock_kernel();
14070 + return -ENXIO;
14071 +@@ -974,6 +1008,9 @@ static const struct {
14072 + #ifdef CONFIG_CRASH_DUMP
14073 + {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
14074 + #endif
14075 ++#ifdef CONFIG_GRKERNSEC
14076 ++ {13,"grsec", S_IRUSR | S_IWUGO, &grsec_fops},
14077 ++#endif
14078 + };
14079 +
14080 + static struct class *mem_class;
14081 +diff -urNp linux-2.6.27.10/drivers/char/nvram.c linux-2.6.27.10/drivers/char/nvram.c
14082 +--- linux-2.6.27.10/drivers/char/nvram.c 2008-11-07 12:55:34.000000000 -0500
14083 ++++ linux-2.6.27.10/drivers/char/nvram.c 2008-11-18 03:38:44.000000000 -0500
14084 +@@ -433,7 +433,10 @@ static const struct file_operations nvra
14085 + static struct miscdevice nvram_dev = {
14086 + NVRAM_MINOR,
14087 + "nvram",
14088 +- &nvram_fops
14089 ++ &nvram_fops,
14090 ++ {NULL, NULL},
14091 ++ NULL,
14092 ++ NULL
14093 + };
14094 +
14095 + static int __init
14096 +diff -urNp linux-2.6.27.10/drivers/char/random.c linux-2.6.27.10/drivers/char/random.c
14097 +--- linux-2.6.27.10/drivers/char/random.c 2008-11-07 12:55:34.000000000 -0500
14098 ++++ linux-2.6.27.10/drivers/char/random.c 2008-11-18 03:38:44.000000000 -0500
14099 +@@ -249,8 +249,13 @@
14100 + /*
14101 + * Configuration information
14102 + */
14103 ++#ifdef CONFIG_GRKERNSEC_RANDNET
14104 ++#define INPUT_POOL_WORDS 512
14105 ++#define OUTPUT_POOL_WORDS 128
14106 ++#else
14107 + #define INPUT_POOL_WORDS 128
14108 + #define OUTPUT_POOL_WORDS 32
14109 ++#endif
14110 + #define SEC_XFER_SIZE 512
14111 +
14112 + /*
14113 +@@ -287,10 +292,17 @@ static struct poolinfo {
14114 + int poolwords;
14115 + int tap1, tap2, tap3, tap4, tap5;
14116 + } poolinfo_table[] = {
14117 ++#ifdef CONFIG_GRKERNSEC_RANDNET
14118 ++ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
14119 ++ { 512, 411, 308, 208, 104, 1 },
14120 ++ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
14121 ++ { 128, 103, 76, 51, 25, 1 },
14122 ++#else
14123 + /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
14124 + { 128, 103, 76, 51, 25, 1 },
14125 + /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
14126 + { 32, 26, 20, 14, 7, 1 },
14127 ++#endif
14128 + #if 0
14129 + /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
14130 + { 2048, 1638, 1231, 819, 411, 1 },
14131 +@@ -1166,7 +1178,7 @@ EXPORT_SYMBOL(generate_random_uuid);
14132 + #include <linux/sysctl.h>
14133 +
14134 + static int min_read_thresh = 8, min_write_thresh;
14135 +-static int max_read_thresh = INPUT_POOL_WORDS * 32;
14136 ++static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
14137 + static int max_write_thresh = INPUT_POOL_WORDS * 32;
14138 + static char sysctl_bootid[16];
14139 +
14140 +diff -urNp linux-2.6.27.10/drivers/char/tpm/tpm.c linux-2.6.27.10/drivers/char/tpm/tpm.c
14141 +--- linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-07 12:55:34.000000000 -0500
14142 ++++ linux-2.6.27.10/drivers/char/tpm/tpm.c 2008-11-18 03:38:44.000000000 -0500
14143 +@@ -1037,7 +1037,7 @@ ssize_t tpm_write(struct file *file, con
14144 +
14145 + mutex_lock(&chip->buffer_mutex);
14146 +
14147 +- if (in_size > TPM_BUFSIZE)
14148 ++ if (in_size > (unsigned int)TPM_BUFSIZE)
14149 + in_size = TPM_BUFSIZE;
14150 +
14151 + if (copy_from_user
14152 +diff -urNp linux-2.6.27.10/drivers/char/vt_ioctl.c linux-2.6.27.10/drivers/char/vt_ioctl.c
14153 +--- linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-07 12:55:34.000000000 -0500
14154 ++++ linux-2.6.27.10/drivers/char/vt_ioctl.c 2008-11-18 03:38:44.000000000 -0500
14155 +@@ -96,6 +96,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
14156 + case KDSKBENT:
14157 + if (!perm)
14158 + return -EPERM;
14159 ++
14160 ++#ifdef CONFIG_GRKERNSEC
14161 ++ if (!capable(CAP_SYS_TTY_CONFIG))
14162 ++ return -EPERM;
14163 ++#endif
14164 ++
14165 + if (!i && v == K_NOSUCHMAP) {
14166 + /* deallocate map */
14167 + key_map = key_maps[s];
14168 +@@ -236,6 +242,13 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
14169 + goto reterr;
14170 + }
14171 +
14172 ++#ifdef CONFIG_GRKERNSEC
14173 ++ if (!capable(CAP_SYS_TTY_CONFIG)) {
14174 ++ ret = -EPERM;
14175 ++ goto reterr;
14176 ++ }
14177 ++#endif
14178 ++
14179 + q = func_table[i];
14180 + first_free = funcbufptr + (funcbufsize - funcbufleft);
14181 + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
14182 +diff -urNp linux-2.6.27.10/drivers/edac/edac_core.h linux-2.6.27.10/drivers/edac/edac_core.h
14183 +--- linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-07 12:55:34.000000000 -0500
14184 ++++ linux-2.6.27.10/drivers/edac/edac_core.h 2008-11-18 03:38:44.000000000 -0500
14185 +@@ -85,11 +85,11 @@ extern int edac_debug_level;
14186 +
14187 + #else /* !CONFIG_EDAC_DEBUG */
14188 +
14189 +-#define debugf0( ... )
14190 +-#define debugf1( ... )
14191 +-#define debugf2( ... )
14192 +-#define debugf3( ... )
14193 +-#define debugf4( ... )
14194 ++#define debugf0( ... ) do {} while (0)
14195 ++#define debugf1( ... ) do {} while (0)
14196 ++#define debugf2( ... ) do {} while (0)
14197 ++#define debugf3( ... ) do {} while (0)
14198 ++#define debugf4( ... ) do {} while (0)
14199 +
14200 + #endif /* !CONFIG_EDAC_DEBUG */
14201 +
14202 +diff -urNp linux-2.6.27.10/drivers/firmware/dmi_scan.c linux-2.6.27.10/drivers/firmware/dmi_scan.c
14203 +--- linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-07 12:55:34.000000000 -0500
14204 ++++ linux-2.6.27.10/drivers/firmware/dmi_scan.c 2008-11-18 03:38:44.000000000 -0500
14205 +@@ -384,11 +384,6 @@ void __init dmi_scan_machine(void)
14206 + }
14207 + }
14208 + else {
14209 +- /*
14210 +- * no iounmap() for that ioremap(); it would be a no-op, but
14211 +- * it's so early in setup that sucker gets confused into doing
14212 +- * what it shouldn't if we actually call it.
14213 +- */
14214 + p = dmi_ioremap(0xF0000, 0x10000);
14215 + if (p == NULL)
14216 + goto out;
14217 +diff -urNp linux-2.6.27.10/drivers/hwmon/fscpos.c linux-2.6.27.10/drivers/hwmon/fscpos.c
14218 +--- linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-07 12:55:34.000000000 -0500
14219 ++++ linux-2.6.27.10/drivers/hwmon/fscpos.c 2008-11-18 03:38:44.000000000 -0500
14220 +@@ -240,7 +240,6 @@ static ssize_t set_pwm(struct i2c_client
14221 + unsigned long v = simple_strtoul(buf, NULL, 10);
14222 +
14223 + /* Range: 0..255 */
14224 +- if (v < 0) v = 0;
14225 + if (v > 255) v = 255;
14226 +
14227 + mutex_lock(&data->update_lock);
14228 +diff -urNp linux-2.6.27.10/drivers/hwmon/k8temp.c linux-2.6.27.10/drivers/hwmon/k8temp.c
14229 +--- linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-07 12:55:34.000000000 -0500
14230 ++++ linux-2.6.27.10/drivers/hwmon/k8temp.c 2008-11-18 03:38:44.000000000 -0500
14231 +@@ -130,7 +130,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
14232 +
14233 + static struct pci_device_id k8temp_ids[] = {
14234 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
14235 +- { 0 },
14236 ++ { 0, 0, 0, 0, 0, 0, 0 },
14237 + };
14238 +
14239 + MODULE_DEVICE_TABLE(pci, k8temp_ids);
14240 +diff -urNp linux-2.6.27.10/drivers/hwmon/sis5595.c linux-2.6.27.10/drivers/hwmon/sis5595.c
14241 +--- linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-07 12:55:34.000000000 -0500
14242 ++++ linux-2.6.27.10/drivers/hwmon/sis5595.c 2008-11-18 03:38:44.000000000 -0500
14243 +@@ -698,7 +698,7 @@ static struct sis5595_data *sis5595_upda
14244 +
14245 + static struct pci_device_id sis5595_pci_ids[] = {
14246 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
14247 +- { 0, }
14248 ++ { 0, 0, 0, 0, 0, 0, 0 }
14249 + };
14250 +
14251 + MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
14252 +diff -urNp linux-2.6.27.10/drivers/hwmon/via686a.c linux-2.6.27.10/drivers/hwmon/via686a.c
14253 +--- linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-07 12:55:34.000000000 -0500
14254 ++++ linux-2.6.27.10/drivers/hwmon/via686a.c 2008-11-18 03:38:44.000000000 -0500
14255 +@@ -768,7 +768,7 @@ static struct via686a_data *via686a_upda
14256 +
14257 + static struct pci_device_id via686a_pci_ids[] = {
14258 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
14259 +- { 0, }
14260 ++ { 0, 0, 0, 0, 0, 0, 0 }
14261 + };
14262 +
14263 + MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
14264 +diff -urNp linux-2.6.27.10/drivers/hwmon/vt8231.c linux-2.6.27.10/drivers/hwmon/vt8231.c
14265 +--- linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-07 12:55:34.000000000 -0500
14266 ++++ linux-2.6.27.10/drivers/hwmon/vt8231.c 2008-11-18 03:38:44.000000000 -0500
14267 +@@ -698,7 +698,7 @@ static struct platform_driver vt8231_dri
14268 +
14269 + static struct pci_device_id vt8231_pci_ids[] = {
14270 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
14271 +- { 0, }
14272 ++ { 0, 0, 0, 0, 0, 0, 0 }
14273 + };
14274 +
14275 + MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
14276 +diff -urNp linux-2.6.27.10/drivers/hwmon/w83791d.c linux-2.6.27.10/drivers/hwmon/w83791d.c
14277 +--- linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-07 12:55:34.000000000 -0500
14278 ++++ linux-2.6.27.10/drivers/hwmon/w83791d.c 2008-11-18 03:38:44.000000000 -0500
14279 +@@ -289,8 +289,8 @@ static int w83791d_detect(struct i2c_cli
14280 + struct i2c_board_info *info);
14281 + static int w83791d_remove(struct i2c_client *client);
14282 +
14283 +-static int w83791d_read(struct i2c_client *client, u8 register);
14284 +-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
14285 ++static int w83791d_read(struct i2c_client *client, u8 reg);
14286 ++static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
14287 + static struct w83791d_data *w83791d_update_device(struct device *dev);
14288 +
14289 + #ifdef DEBUG
14290 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c
14291 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-07 12:55:34.000000000 -0500
14292 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-i801.c 2008-11-18 03:38:44.000000000 -0500
14293 +@@ -576,7 +576,7 @@ static struct pci_device_id i801_ids[] =
14294 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TOLAPAI_1) },
14295 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
14296 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
14297 +- { 0, }
14298 ++ { 0, 0, 0, 0, 0, 0, 0 }
14299 + };
14300 +
14301 + MODULE_DEVICE_TABLE (pci, i801_ids);
14302 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c
14303 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-07 12:55:34.000000000 -0500
14304 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-piix4.c 2008-11-18 03:38:44.000000000 -0500
14305 +@@ -123,7 +123,7 @@ static struct dmi_system_id __devinitdat
14306 + .ident = "IBM",
14307 + .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
14308 + },
14309 +- { },
14310 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL },
14311 + };
14312 +
14313 + static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
14314 +@@ -424,7 +424,7 @@ static struct pci_device_id piix4_ids[]
14315 + PCI_DEVICE_ID_SERVERWORKS_CSB6) },
14316 + { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
14317 + PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
14318 +- { 0, }
14319 ++ { 0, 0, 0, 0, 0, 0, 0 }
14320 + };
14321 +
14322 + MODULE_DEVICE_TABLE (pci, piix4_ids);
14323 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c
14324 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-07 12:55:34.000000000 -0500
14325 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis630.c 2008-11-18 03:38:44.000000000 -0500
14326 +@@ -472,7 +472,7 @@ static struct i2c_adapter sis630_adapter
14327 + static struct pci_device_id sis630_ids[] __devinitdata = {
14328 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
14329 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
14330 +- { 0, }
14331 ++ { 0, 0, 0, 0, 0, 0, 0 }
14332 + };
14333 +
14334 + MODULE_DEVICE_TABLE (pci, sis630_ids);
14335 +diff -urNp linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c
14336 +--- linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-07 12:55:34.000000000 -0500
14337 ++++ linux-2.6.27.10/drivers/i2c/busses/i2c-sis96x.c 2008-11-18 03:38:44.000000000 -0500
14338 +@@ -248,7 +248,7 @@ static struct i2c_adapter sis96x_adapter
14339 +
14340 + static struct pci_device_id sis96x_ids[] = {
14341 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
14342 +- { 0, }
14343 ++ { 0, 0, 0, 0, 0, 0, 0 }
14344 + };
14345 +
14346 + MODULE_DEVICE_TABLE (pci, sis96x_ids);
14347 +diff -urNp linux-2.6.27.10/drivers/ieee1394/dv1394.c linux-2.6.27.10/drivers/ieee1394/dv1394.c
14348 +--- linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-07 12:55:34.000000000 -0500
14349 ++++ linux-2.6.27.10/drivers/ieee1394/dv1394.c 2008-11-18 03:38:44.000000000 -0500
14350 +@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
14351 + based upon DIF section and sequence
14352 + */
14353 +
14354 +-static void inline
14355 ++static inline void
14356 + frame_put_packet (struct frame *f, struct packet *p)
14357 + {
14358 + int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
14359 +@@ -918,7 +918,7 @@ static int do_dv1394_init(struct video_c
14360 + /* default SYT offset is 3 cycles */
14361 + init->syt_offset = 3;
14362 +
14363 +- if ( (init->channel > 63) || (init->channel < 0) )
14364 ++ if (init->channel > 63)
14365 + init->channel = 63;
14366 +
14367 + chan_mask = (u64)1 << init->channel;
14368 +@@ -2174,7 +2174,7 @@ static struct ieee1394_device_id dv1394_
14369 + .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
14370 + .version = AVC_SW_VERSION_ENTRY & 0xffffff
14371 + },
14372 +- { }
14373 ++ { 0, 0, 0, 0, 0, 0 }
14374 + };
14375 +
14376 + MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table);
14377 +diff -urNp linux-2.6.27.10/drivers/ieee1394/eth1394.c linux-2.6.27.10/drivers/ieee1394/eth1394.c
14378 +--- linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-07 12:55:34.000000000 -0500
14379 ++++ linux-2.6.27.10/drivers/ieee1394/eth1394.c 2008-11-18 03:38:44.000000000 -0500
14380 +@@ -451,7 +451,7 @@ static struct ieee1394_device_id eth1394
14381 + .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
14382 + .version = ETHER1394_GASP_VERSION,
14383 + },
14384 +- {}
14385 ++ { 0, 0, 0, 0, 0, 0 }
14386 + };
14387 +
14388 + MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
14389 +diff -urNp linux-2.6.27.10/drivers/ieee1394/hosts.c linux-2.6.27.10/drivers/ieee1394/hosts.c
14390 +--- linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-07 12:55:34.000000000 -0500
14391 ++++ linux-2.6.27.10/drivers/ieee1394/hosts.c 2008-11-18 03:38:44.000000000 -0500
14392 +@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
14393 + }
14394 +
14395 + static struct hpsb_host_driver dummy_driver = {
14396 ++ .name = "dummy",
14397 + .transmit_packet = dummy_transmit_packet,
14398 + .devctl = dummy_devctl,
14399 + .isoctl = dummy_isoctl
14400 +diff -urNp linux-2.6.27.10/drivers/ieee1394/ohci1394.c linux-2.6.27.10/drivers/ieee1394/ohci1394.c
14401 +--- linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-07 12:55:34.000000000 -0500
14402 ++++ linux-2.6.27.10/drivers/ieee1394/ohci1394.c 2008-11-18 03:38:44.000000000 -0500
14403 +@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
14404 + printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
14405 +
14406 + /* Module Parameters */
14407 +-static int phys_dma = 1;
14408 ++static int phys_dma;
14409 + module_param(phys_dma, int, 0444);
14410 +-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
14411 ++MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
14412 +
14413 + static void dma_trm_tasklet(unsigned long data);
14414 + static void dma_trm_reset(struct dma_trm_ctx *d);
14415 +@@ -3437,7 +3437,7 @@ static struct pci_device_id ohci1394_pci
14416 + .subvendor = PCI_ANY_ID,
14417 + .subdevice = PCI_ANY_ID,
14418 + },
14419 +- { 0, },
14420 ++ { 0, 0, 0, 0, 0, 0, 0 },
14421 + };
14422 +
14423 + MODULE_DEVICE_TABLE(pci, ohci1394_pci_tbl);
14424 +diff -urNp linux-2.6.27.10/drivers/ieee1394/raw1394.c linux-2.6.27.10/drivers/ieee1394/raw1394.c
14425 +--- linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-07 12:55:34.000000000 -0500
14426 ++++ linux-2.6.27.10/drivers/ieee1394/raw1394.c 2008-11-18 03:38:44.000000000 -0500
14427 +@@ -2968,7 +2968,7 @@ static struct ieee1394_device_id raw1394
14428 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
14429 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
14430 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
14431 +- {}
14432 ++ { 0, 0, 0, 0, 0, 0 }
14433 + };
14434 +
14435 + MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
14436 +diff -urNp linux-2.6.27.10/drivers/ieee1394/sbp2.c linux-2.6.27.10/drivers/ieee1394/sbp2.c
14437 +--- linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:37.000000000 -0500
14438 ++++ linux-2.6.27.10/drivers/ieee1394/sbp2.c 2008-12-10 22:35:46.000000000 -0500
14439 +@@ -290,7 +290,7 @@ static struct ieee1394_device_id sbp2_id
14440 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
14441 + .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
14442 + .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
14443 +- {}
14444 ++ { 0, 0, 0, 0, 0, 0 }
14445 + };
14446 + MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
14447 +
14448 +@@ -2135,7 +2135,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
14449 + MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
14450 + MODULE_LICENSE("GPL");
14451 +
14452 +-static int sbp2_module_init(void)
14453 ++static int __init sbp2_module_init(void)
14454 + {
14455 + int ret;
14456 +
14457 +diff -urNp linux-2.6.27.10/drivers/ieee1394/video1394.c linux-2.6.27.10/drivers/ieee1394/video1394.c
14458 +--- linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-07 12:55:34.000000000 -0500
14459 ++++ linux-2.6.27.10/drivers/ieee1394/video1394.c 2008-11-18 03:38:44.000000000 -0500
14460 +@@ -893,7 +893,7 @@ static long video1394_ioctl(struct file
14461 + if (unlikely(d == NULL))
14462 + return -EFAULT;
14463 +
14464 +- if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) {
14465 ++ if (unlikely(v.buffer>=d->num_desc - 1)) {
14466 + PRINT(KERN_ERR, ohci->host->id,
14467 + "Buffer %d out of range",v.buffer);
14468 + return -EINVAL;
14469 +@@ -959,7 +959,7 @@ static long video1394_ioctl(struct file
14470 + if (unlikely(d == NULL))
14471 + return -EFAULT;
14472 +
14473 +- if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) {
14474 ++ if (unlikely(v.buffer>d->num_desc - 1)) {
14475 + PRINT(KERN_ERR, ohci->host->id,
14476 + "Buffer %d out of range",v.buffer);
14477 + return -EINVAL;
14478 +@@ -1030,7 +1030,7 @@ static long video1394_ioctl(struct file
14479 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
14480 + if (d == NULL) return -EFAULT;
14481 +
14482 +- if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) {
14483 ++ if (v.buffer>=d->num_desc - 1) {
14484 + PRINT(KERN_ERR, ohci->host->id,
14485 + "Buffer %d out of range",v.buffer);
14486 + return -EINVAL;
14487 +@@ -1137,7 +1137,7 @@ static long video1394_ioctl(struct file
14488 + d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
14489 + if (d == NULL) return -EFAULT;
14490 +
14491 +- if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) {
14492 ++ if (v.buffer>=d->num_desc-1) {
14493 + PRINT(KERN_ERR, ohci->host->id,
14494 + "Buffer %d out of range",v.buffer);
14495 + return -EINVAL;
14496 +@@ -1310,7 +1310,7 @@ static struct ieee1394_device_id video13
14497 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
14498 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff
14499 + },
14500 +- { }
14501 ++ { 0, 0, 0, 0, 0, 0 }
14502 + };
14503 +
14504 + MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
14505 +diff -urNp linux-2.6.27.10/drivers/input/keyboard/atkbd.c linux-2.6.27.10/drivers/input/keyboard/atkbd.c
14506 +--- linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:37.000000000 -0500
14507 ++++ linux-2.6.27.10/drivers/input/keyboard/atkbd.c 2008-12-10 22:35:46.000000000 -0500
14508 +@@ -1148,7 +1148,7 @@ static struct serio_device_id atkbd_seri
14509 + .id = SERIO_ANY,
14510 + .extra = SERIO_ANY,
14511 + },
14512 +- { 0 }
14513 ++ { 0, 0, 0, 0 }
14514 + };
14515 +
14516 + MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
14517 +diff -urNp linux-2.6.27.10/drivers/input/mouse/lifebook.c linux-2.6.27.10/drivers/input/mouse/lifebook.c
14518 +--- linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-07 12:55:34.000000000 -0500
14519 ++++ linux-2.6.27.10/drivers/input/mouse/lifebook.c 2008-11-18 03:38:44.000000000 -0500
14520 +@@ -110,7 +110,7 @@ static const struct dmi_system_id lifebo
14521 + DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
14522 + },
14523 + },
14524 +- { }
14525 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL}
14526 + };
14527 +
14528 + static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
14529 +diff -urNp linux-2.6.27.10/drivers/input/mouse/psmouse-base.c linux-2.6.27.10/drivers/input/mouse/psmouse-base.c
14530 +--- linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-07 12:55:34.000000000 -0500
14531 ++++ linux-2.6.27.10/drivers/input/mouse/psmouse-base.c 2008-11-18 03:38:44.000000000 -0500
14532 +@@ -1328,7 +1328,7 @@ static struct serio_device_id psmouse_se
14533 + .id = SERIO_ANY,
14534 + .extra = SERIO_ANY,
14535 + },
14536 +- { 0 }
14537 ++ { 0, 0, 0, 0 }
14538 + };
14539 +
14540 + MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
14541 +diff -urNp linux-2.6.27.10/drivers/input/mouse/synaptics.c linux-2.6.27.10/drivers/input/mouse/synaptics.c
14542 +--- linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-07 12:55:34.000000000 -0500
14543 ++++ linux-2.6.27.10/drivers/input/mouse/synaptics.c 2008-11-18 03:38:45.000000000 -0500
14544 +@@ -417,7 +417,7 @@ static void synaptics_process_packet(str
14545 + break;
14546 + case 2:
14547 + if (SYN_MODEL_PEN(priv->model_id))
14548 +- ; /* Nothing, treat a pen as a single finger */
14549 ++ break; /* Nothing, treat a pen as a single finger */
14550 + break;
14551 + case 4 ... 15:
14552 + if (SYN_CAP_PALMDETECT(priv->capabilities))
14553 +@@ -624,7 +624,7 @@ static const struct dmi_system_id toshib
14554 + DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
14555 + },
14556 + },
14557 +- { }
14558 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
14559 + };
14560 + #endif
14561 +
14562 +diff -urNp linux-2.6.27.10/drivers/input/mousedev.c linux-2.6.27.10/drivers/input/mousedev.c
14563 +--- linux-2.6.27.10/drivers/input/mousedev.c 2008-11-07 12:55:34.000000000 -0500
14564 ++++ linux-2.6.27.10/drivers/input/mousedev.c 2008-11-18 03:38:45.000000000 -0500
14565 +@@ -1064,7 +1064,7 @@ static struct input_handler mousedev_han
14566 +
14567 + #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
14568 + static struct miscdevice psaux_mouse = {
14569 +- PSMOUSE_MINOR, "psaux", &mousedev_fops
14570 ++ PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
14571 + };
14572 + static int psaux_registered;
14573 + #endif
14574 +diff -urNp linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h
14575 +--- linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:51.000000000 -0500
14576 ++++ linux-2.6.27.10/drivers/input/serio/i8042-x86ia64io.h 2008-12-21 01:16:00.000000000 -0500
14577 +@@ -143,7 +143,7 @@ static struct dmi_system_id __initdata i
14578 + DMI_MATCH(DMI_PRODUCT_VERSION, "M606"),
14579 + },
14580 + },
14581 +- { }
14582 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
14583 + };
14584 +
14585 + /*
14586 +@@ -351,7 +351,7 @@ static struct dmi_system_id __initdata i
14587 + DMI_MATCH(DMI_PRODUCT_NAME, "HEL80I"),
14588 + },
14589 + },
14590 +- { }
14591 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
14592 + };
14593 +
14594 + #ifdef CONFIG_PNP
14595 +@@ -363,7 +363,7 @@ static struct dmi_system_id __initdata i
14596 + DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
14597 + },
14598 + },
14599 +- { }
14600 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
14601 + };
14602 + #endif
14603 +
14604 +@@ -430,7 +430,7 @@ static struct dmi_system_id __initdata i
14605 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
14606 + },
14607 + },
14608 +- { }
14609 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL }
14610 + };
14611 +
14612 + #endif /* CONFIG_X86 */
14613 +diff -urNp linux-2.6.27.10/drivers/input/serio/serio_raw.c linux-2.6.27.10/drivers/input/serio/serio_raw.c
14614 +--- linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-07 12:55:34.000000000 -0500
14615 ++++ linux-2.6.27.10/drivers/input/serio/serio_raw.c 2008-11-18 03:38:45.000000000 -0500
14616 +@@ -373,7 +373,7 @@ static struct serio_device_id serio_raw_
14617 + .id = SERIO_ANY,
14618 + .extra = SERIO_ANY,
14619 + },
14620 +- { 0 }
14621 ++ { 0, 0, 0, 0 }
14622 + };
14623 +
14624 + MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
14625 +diff -urNp linux-2.6.27.10/drivers/md/bitmap.c linux-2.6.27.10/drivers/md/bitmap.c
14626 +--- linux-2.6.27.10/drivers/md/bitmap.c 2008-11-07 12:55:34.000000000 -0500
14627 ++++ linux-2.6.27.10/drivers/md/bitmap.c 2008-11-18 03:38:45.000000000 -0500
14628 +@@ -57,7 +57,7 @@
14629 + # if DEBUG > 0
14630 + # define PRINTK(x...) printk(KERN_DEBUG x)
14631 + # else
14632 +-# define PRINTK(x...)
14633 ++# define PRINTK(x...) do {} while (0)
14634 + # endif
14635 + #endif
14636 +
14637 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2000.c linux-2.6.27.10/drivers/mtd/devices/doc2000.c
14638 +--- linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-07 12:55:34.000000000 -0500
14639 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2000.c 2008-11-18 03:38:45.000000000 -0500
14640 +@@ -777,7 +777,7 @@ static int doc_write(struct mtd_info *mt
14641 +
14642 + /* The ECC will not be calculated correctly if less than 512 is written */
14643 + /* DBB-
14644 +- if (len != 0x200 && eccbuf)
14645 ++ if (len != 0x200)
14646 + printk(KERN_WARNING
14647 + "ECC needs a full sector write (adr: %lx size %lx)\n",
14648 + (long) to, (long) len);
14649 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/doc2001.c linux-2.6.27.10/drivers/mtd/devices/doc2001.c
14650 +--- linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-07 12:55:34.000000000 -0500
14651 ++++ linux-2.6.27.10/drivers/mtd/devices/doc2001.c 2008-11-18 03:38:45.000000000 -0500
14652 +@@ -396,6 +396,8 @@ static int doc_read (struct mtd_info *mt
14653 + /* Don't allow read past end of device */
14654 + if (from >= this->totlen)
14655 + return -EINVAL;
14656 ++ if (!len)
14657 ++ return -EINVAL;
14658 +
14659 + /* Don't allow a single read to cross a 512-byte block boundary */
14660 + if (from + len > ((from | 0x1ff) + 1))
14661 +diff -urNp linux-2.6.27.10/drivers/mtd/devices/slram.c linux-2.6.27.10/drivers/mtd/devices/slram.c
14662 +--- linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-07 12:55:34.000000000 -0500
14663 ++++ linux-2.6.27.10/drivers/mtd/devices/slram.c 2008-11-18 03:38:45.000000000 -0500
14664 +@@ -273,7 +273,7 @@ static int parse_cmdline(char *devname,
14665 + }
14666 + T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
14667 + devname, devstart, devlength);
14668 +- if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
14669 ++ if (devlength % SLRAM_BLK_SZ != 0) {
14670 + E("slram: Illegal start / length parameter.\n");
14671 + return(-EINVAL);
14672 + }
14673 +diff -urNp linux-2.6.27.10/drivers/mtd/ubi/build.c linux-2.6.27.10/drivers/mtd/ubi/build.c
14674 +--- linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-07 12:55:34.000000000 -0500
14675 ++++ linux-2.6.27.10/drivers/mtd/ubi/build.c 2008-11-18 03:38:45.000000000 -0500
14676 +@@ -1104,7 +1104,7 @@ static int __init bytes_str_to_int(const
14677 + unsigned long result;
14678 +
14679 + result = simple_strtoul(str, &endp, 0);
14680 +- if (str == endp || result < 0) {
14681 ++ if (str == endp) {
14682 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
14683 + str);
14684 + return -EINVAL;
14685 +diff -urNp linux-2.6.27.10/drivers/net/eepro100.c linux-2.6.27.10/drivers/net/eepro100.c
14686 +--- linux-2.6.27.10/drivers/net/eepro100.c 2008-11-07 12:55:34.000000000 -0500
14687 ++++ linux-2.6.27.10/drivers/net/eepro100.c 2008-11-18 03:38:45.000000000 -0500
14688 +@@ -47,7 +47,7 @@ static int rxdmacount /* = 0 */;
14689 + # define rx_align(skb) skb_reserve((skb), 2)
14690 + # define RxFD_ALIGNMENT __attribute__ ((aligned (2), packed))
14691 + #else
14692 +-# define rx_align(skb)
14693 ++# define rx_align(skb) do {} while (0)
14694 + # define RxFD_ALIGNMENT
14695 + #endif
14696 +
14697 +@@ -2334,33 +2334,33 @@ static void __devexit eepro100_remove_on
14698 + }
14699 +
14700 + static struct pci_device_id eepro100_pci_tbl[] = {
14701 +- { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, },
14702 +- { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, },
14703 +- { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, },
14704 +- { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, },
14705 +- { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, },
14706 +- { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, },
14707 +- { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, },
14708 +- { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, },
14709 +- { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, },
14710 +- { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, },
14711 +- { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, },
14712 +- { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, },
14713 +- { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, },
14714 +- { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, },
14715 +- { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, },
14716 +- { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, },
14717 +- { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, },
14718 +- { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, },
14719 +- { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, },
14720 +- { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, },
14721 +- { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, },
14722 +- { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, },
14723 +- { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, },
14724 +- { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, },
14725 +- { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, },
14726 +- { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, },
14727 +- { 0,}
14728 ++ { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14729 ++ { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14730 ++ { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14731 ++ { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14732 ++ { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14733 ++ { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14734 ++ { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14735 ++ { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14736 ++ { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14737 ++ { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14738 ++ { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14739 ++ { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14740 ++ { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14741 ++ { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14742 ++ { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14743 ++ { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14744 ++ { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14745 ++ { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14746 ++ { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14747 ++ { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14748 ++ { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14749 ++ { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14750 ++ { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14751 ++ { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14752 ++ { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14753 ++ { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
14754 ++ { 0, 0, 0, 0, 0, 0, 0 }
14755 + };
14756 + MODULE_DEVICE_TABLE(pci, eepro100_pci_tbl);
14757 +
14758 +diff -urNp linux-2.6.27.10/drivers/net/irda/vlsi_ir.c linux-2.6.27.10/drivers/net/irda/vlsi_ir.c
14759 +--- linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-07 12:55:34.000000000 -0500
14760 ++++ linux-2.6.27.10/drivers/net/irda/vlsi_ir.c 2008-11-18 03:38:45.000000000 -0500
14761 +@@ -906,13 +906,12 @@ static int vlsi_hard_start_xmit(struct s
14762 + /* no race - tx-ring already empty */
14763 + vlsi_set_baud(idev, iobase);
14764 + netif_wake_queue(ndev);
14765 +- }
14766 +- else
14767 +- ;
14768 ++ } else {
14769 + /* keep the speed change pending like it would
14770 + * for any len>0 packet. tx completion interrupt
14771 + * will apply it when the tx ring becomes empty.
14772 + */
14773 ++ }
14774 + spin_unlock_irqrestore(&idev->lock, flags);
14775 + dev_kfree_skb_any(skb);
14776 + return 0;
14777 +diff -urNp linux-2.6.27.10/drivers/net/pcnet32.c linux-2.6.27.10/drivers/net/pcnet32.c
14778 +--- linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-07 12:55:34.000000000 -0500
14779 ++++ linux-2.6.27.10/drivers/net/pcnet32.c 2008-11-18 03:38:45.000000000 -0500
14780 +@@ -78,7 +78,7 @@ static int cards_found;
14781 + /*
14782 + * VLB I/O addresses
14783 + */
14784 +-static unsigned int pcnet32_portlist[] __initdata =
14785 ++static unsigned int pcnet32_portlist[] __devinitdata =
14786 + { 0x300, 0x320, 0x340, 0x360, 0 };
14787 +
14788 + static int pcnet32_debug = 0;
14789 +diff -urNp linux-2.6.27.10/drivers/net/tg3.h linux-2.6.27.10/drivers/net/tg3.h
14790 +--- linux-2.6.27.10/drivers/net/tg3.h 2008-11-07 12:55:34.000000000 -0500
14791 ++++ linux-2.6.27.10/drivers/net/tg3.h 2008-11-18 03:38:45.000000000 -0500
14792 +@@ -102,6 +102,7 @@
14793 + #define CHIPREV_ID_5750_A0 0x4000
14794 + #define CHIPREV_ID_5750_A1 0x4001
14795 + #define CHIPREV_ID_5750_A3 0x4003
14796 ++#define CHIPREV_ID_5750_C1 0x4201
14797 + #define CHIPREV_ID_5750_C2 0x4202
14798 + #define CHIPREV_ID_5752_A0_HW 0x5000
14799 + #define CHIPREV_ID_5752_A0 0x6000
14800 +diff -urNp linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c
14801 +--- linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-11-17 20:03:30.000000000 -0500
14802 ++++ linux-2.6.27.10/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-12-27 13:44:22.000000000 -0500
14803 +@@ -785,7 +785,7 @@ static int iwl3945_send_cmd_sync(struct
14804 + IWL_ERROR("Error: Response NULL in '%s'\n",
14805 + get_cmd_string(cmd->id));
14806 + ret = -EIO;
14807 +- goto out;
14808 ++ goto cancel;
14809 + }
14810 +
14811 + ret = 0;
14812 +diff -urNp linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c
14813 +--- linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-07 12:55:34.000000000 -0500
14814 ++++ linux-2.6.27.10/drivers/pci/hotplug/cpqphp_nvram.c 2008-11-18 03:38:45.000000000 -0500
14815 +@@ -425,9 +425,13 @@ static u32 store_HRT (void __iomem *rom_
14816 +
14817 + void compaq_nvram_init (void __iomem *rom_start)
14818 + {
14819 ++
14820 ++#ifndef CONFIG_PAX_KERNEXEC
14821 + if (rom_start) {
14822 + compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
14823 + }
14824 ++#endif
14825 ++
14826 + dbg("int15 entry = %p\n", compaq_int15_entry_point);
14827 +
14828 + /* initialize our int15 lock */
14829 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c
14830 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-07 12:55:34.000000000 -0500
14831 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv.c 2008-11-18 03:38:45.000000000 -0500
14832 +@@ -59,7 +59,7 @@ static struct pcie_port_service_id aer_i
14833 + .port_type = PCIE_RC_PORT,
14834 + .service_type = PCIE_PORT_SERVICE_AER,
14835 + },
14836 +- { /* end: all zeroes */ }
14837 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
14838 + };
14839 +
14840 + static struct pci_error_handlers aer_error_handlers = {
14841 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c
14842 +--- linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-07 12:55:34.000000000 -0500
14843 ++++ linux-2.6.27.10/drivers/pci/pcie/aer/aerdrv_core.c 2008-11-18 03:38:45.000000000 -0500
14844 +@@ -663,7 +663,7 @@ static void aer_isr_one_error(struct pci
14845 + struct aer_err_source *e_src)
14846 + {
14847 + struct device *s_device;
14848 +- struct aer_err_info e_info = {0, 0, 0,};
14849 ++ struct aer_err_info e_info = {0, 0, 0, {0, 0, 0, 0}};
14850 + int i;
14851 + u16 id;
14852 +
14853 +diff -urNp linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c
14854 +--- linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-07 12:55:34.000000000 -0500
14855 ++++ linux-2.6.27.10/drivers/pci/pcie/portdrv_pci.c 2008-11-18 03:38:45.000000000 -0500
14856 +@@ -264,7 +264,7 @@ static void pcie_portdrv_err_resume(stru
14857 + static const struct pci_device_id port_pci_ids[] = { {
14858 + /* handle any PCI-Express port */
14859 + PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
14860 +- }, { /* end: all zeroes */ }
14861 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
14862 + };
14863 + MODULE_DEVICE_TABLE(pci, port_pci_ids);
14864 +
14865 +diff -urNp linux-2.6.27.10/drivers/pci/proc.c linux-2.6.27.10/drivers/pci/proc.c
14866 +--- linux-2.6.27.10/drivers/pci/proc.c 2008-11-07 12:55:34.000000000 -0500
14867 ++++ linux-2.6.27.10/drivers/pci/proc.c 2008-11-18 03:38:45.000000000 -0500
14868 +@@ -470,7 +470,16 @@ static const struct file_operations proc
14869 + static int __init pci_proc_init(void)
14870 + {
14871 + struct pci_dev *dev = NULL;
14872 ++
14873 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
14874 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
14875 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
14876 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
14877 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
14878 ++#endif
14879 ++#else
14880 + proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
14881 ++#endif
14882 + proc_create("devices", 0, proc_bus_pci_dir,
14883 + &proc_bus_pci_dev_operations);
14884 + proc_initialized = 1;
14885 +diff -urNp linux-2.6.27.10/drivers/pcmcia/ti113x.h linux-2.6.27.10/drivers/pcmcia/ti113x.h
14886 +--- linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-07 12:55:34.000000000 -0500
14887 ++++ linux-2.6.27.10/drivers/pcmcia/ti113x.h 2008-11-18 03:38:45.000000000 -0500
14888 +@@ -897,7 +897,7 @@ static struct pci_device_id ene_tune_tbl
14889 + DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
14890 + ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
14891 +
14892 +- {}
14893 ++ { 0, 0, 0, 0, 0, 0, 0 }
14894 + };
14895 +
14896 + static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
14897 +diff -urNp linux-2.6.27.10/drivers/pcmcia/yenta_socket.c linux-2.6.27.10/drivers/pcmcia/yenta_socket.c
14898 +--- linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-07 12:55:34.000000000 -0500
14899 ++++ linux-2.6.27.10/drivers/pcmcia/yenta_socket.c 2008-11-18 03:38:45.000000000 -0500
14900 +@@ -1358,7 +1358,7 @@ static struct pci_device_id yenta_table
14901 +
14902 + /* match any cardbus bridge */
14903 + CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
14904 +- { /* all zeroes */ }
14905 ++ { 0, 0, 0, 0, 0, 0, 0 }
14906 + };
14907 + MODULE_DEVICE_TABLE(pci, yenta_table);
14908 +
14909 +diff -urNp linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c
14910 +--- linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-07 12:55:34.000000000 -0500
14911 ++++ linux-2.6.27.10/drivers/pnp/pnpbios/bioscalls.c 2008-11-18 03:38:45.000000000 -0500
14912 +@@ -60,7 +60,7 @@ set_base(gdt[(selname) >> 3], (u32)(addr
14913 + set_limit(gdt[(selname) >> 3], size); \
14914 + } while(0)
14915 +
14916 +-static struct desc_struct bad_bios_desc;
14917 ++static struct desc_struct bad_bios_desc __read_only;
14918 +
14919 + /*
14920 + * At some point we want to use this stack frame pointer to unwind
14921 +@@ -87,6 +87,10 @@ static inline u16 call_pnp_bios(u16 func
14922 + struct desc_struct save_desc_40;
14923 + int cpu;
14924 +
14925 ++#ifdef CONFIG_PAX_KERNEXEC
14926 ++ unsigned long cr0;
14927 ++#endif
14928 ++
14929 + /*
14930 + * PnP BIOSes are generally not terribly re-entrant.
14931 + * Also, don't rely on them to save everything correctly.
14932 +@@ -96,8 +100,17 @@ static inline u16 call_pnp_bios(u16 func
14933 +
14934 + cpu = get_cpu();
14935 + save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
14936 ++
14937 ++#ifdef CONFIG_PAX_KERNEXEC
14938 ++ pax_open_kernel(cr0);
14939 ++#endif
14940 ++
14941 + get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
14942 +
14943 ++#ifdef CONFIG_PAX_KERNEXEC
14944 ++ pax_close_kernel(cr0);
14945 ++#endif
14946 ++
14947 + /* On some boxes IRQ's during PnP BIOS calls are deadly. */
14948 + spin_lock_irqsave(&pnp_bios_lock, flags);
14949 +
14950 +@@ -134,7 +147,16 @@ static inline u16 call_pnp_bios(u16 func
14951 + :"memory");
14952 + spin_unlock_irqrestore(&pnp_bios_lock, flags);
14953 +
14954 ++#ifdef CONFIG_PAX_KERNEXEC
14955 ++ pax_open_kernel(cr0);
14956 ++#endif
14957 ++
14958 + get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
14959 ++
14960 ++#ifdef CONFIG_PAX_KERNEXEC
14961 ++ pax_close_kernel(cr0);
14962 ++#endif
14963 ++
14964 + put_cpu();
14965 +
14966 + /* If we get here and this is set then the PnP BIOS faulted on us. */
14967 +@@ -468,16 +490,24 @@ int pnp_bios_read_escd(char *data, u32 n
14968 + return status;
14969 + }
14970 +
14971 +-void pnpbios_calls_init(union pnp_bios_install_struct *header)
14972 ++void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
14973 + {
14974 + int i;
14975 +
14976 ++#ifdef CONFIG_PAX_KERNEXEC
14977 ++ unsigned long cr0;
14978 ++#endif
14979 ++
14980 + spin_lock_init(&pnp_bios_lock);
14981 + pnp_bios_callpoint.offset = header->fields.pm16offset;
14982 + pnp_bios_callpoint.segment = PNP_CS16;
14983 +
14984 ++#ifdef CONFIG_PAX_KERNEXEC
14985 ++ pax_open_kernel(cr0);
14986 ++#endif
14987 ++
14988 + bad_bios_desc.a = 0;
14989 +- bad_bios_desc.b = 0x00409200;
14990 ++ bad_bios_desc.b = 0x00409300;
14991 +
14992 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
14993 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
14994 +@@ -491,4 +521,9 @@ void pnpbios_calls_init(union pnp_bios_i
14995 + set_base(gdt[GDT_ENTRY_PNPBIOS_DS],
14996 + __va(header->fields.pm16dseg));
14997 + }
14998 ++
14999 ++#ifdef CONFIG_PAX_KERNEXEC
15000 ++ pax_close_kernel(cr0);
15001 ++#endif
15002 ++
15003 + }
15004 +diff -urNp linux-2.6.27.10/drivers/pnp/quirks.c linux-2.6.27.10/drivers/pnp/quirks.c
15005 +--- linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:16:51.000000000 -0500
15006 ++++ linux-2.6.27.10/drivers/pnp/quirks.c 2008-12-21 01:13:46.000000000 -0500
15007 +@@ -327,7 +327,7 @@ static struct pnp_fixup pnp_fixups[] = {
15008 + /* PnP resources that might overlap PCI BARs */
15009 + {"PNP0c01", quirk_system_pci_resources},
15010 + {"PNP0c02", quirk_system_pci_resources},
15011 +- {""}
15012 ++ {"", NULL}
15013 + };
15014 +
15015 + void pnp_fixup_device(struct pnp_dev *dev)
15016 +diff -urNp linux-2.6.27.10/drivers/pnp/resource.c linux-2.6.27.10/drivers/pnp/resource.c
15017 +--- linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:16:51.000000000 -0500
15018 ++++ linux-2.6.27.10/drivers/pnp/resource.c 2008-12-21 01:13:46.000000000 -0500
15019 +@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
15020 + return 1;
15021 +
15022 + /* check if the resource is valid */
15023 +- if (*irq < 0 || *irq > 15)
15024 ++ if (*irq > 15)
15025 + return 0;
15026 +
15027 + /* check if the resource is reserved */
15028 +@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
15029 + return 1;
15030 +
15031 + /* check if the resource is valid */
15032 +- if (*dma < 0 || *dma == 4 || *dma > 7)
15033 ++ if (*dma == 4 || *dma > 7)
15034 + return 0;
15035 +
15036 + /* check if the resource is reserved */
15037 +diff -urNp linux-2.6.27.10/drivers/scsi/scsi_logging.h linux-2.6.27.10/drivers/scsi/scsi_logging.h
15038 +--- linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-07 12:55:34.000000000 -0500
15039 ++++ linux-2.6.27.10/drivers/scsi/scsi_logging.h 2008-11-18 03:38:45.000000000 -0500
15040 +@@ -51,7 +51,7 @@ do { \
15041 + } while (0); \
15042 + } while (0)
15043 + #else
15044 +-#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
15045 ++#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
15046 + #endif /* CONFIG_SCSI_LOGGING */
15047 +
15048 + /*
15049 +diff -urNp linux-2.6.27.10/drivers/serial/8250_pci.c linux-2.6.27.10/drivers/serial/8250_pci.c
15050 +--- linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-07 12:55:34.000000000 -0500
15051 ++++ linux-2.6.27.10/drivers/serial/8250_pci.c 2008-11-18 03:38:45.000000000 -0500
15052 +@@ -2859,7 +2859,7 @@ static struct pci_device_id serial_pci_t
15053 + PCI_ANY_ID, PCI_ANY_ID,
15054 + PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
15055 + 0xffff00, pbn_default },
15056 +- { 0, }
15057 ++ { 0, 0, 0, 0, 0, 0, 0 }
15058 + };
15059 +
15060 + static struct pci_driver serial_pci_driver = {
15061 +diff -urNp linux-2.6.27.10/drivers/usb/class/cdc-acm.c linux-2.6.27.10/drivers/usb/class/cdc-acm.c
15062 +--- linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:38:40.000000000 -0500
15063 ++++ linux-2.6.27.10/drivers/usb/class/cdc-acm.c 2008-11-18 11:40:52.000000000 -0500
15064 +@@ -1381,7 +1381,7 @@ static struct usb_device_id acm_ids[] =
15065 + USB_CDC_ACM_PROTO_AT_CDMA) },
15066 +
15067 + /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
15068 +- { }
15069 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
15070 + };
15071 +
15072 + MODULE_DEVICE_TABLE (usb, acm_ids);
15073 +diff -urNp linux-2.6.27.10/drivers/usb/class/usblp.c linux-2.6.27.10/drivers/usb/class/usblp.c
15074 +--- linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-07 12:55:34.000000000 -0500
15075 ++++ linux-2.6.27.10/drivers/usb/class/usblp.c 2008-11-18 03:38:45.000000000 -0500
15076 +@@ -227,7 +227,7 @@ static const struct quirk_printer_struct
15077 + { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
15078 + { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@×××.de> */
15079 + { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
15080 +- { 0, 0 }
15081 ++ { 0, 0, 0 }
15082 + };
15083 +
15084 + static int usblp_wwait(struct usblp *usblp, int nonblock);
15085 +@@ -1401,7 +1401,7 @@ static struct usb_device_id usblp_ids []
15086 + { USB_INTERFACE_INFO(7, 1, 2) },
15087 + { USB_INTERFACE_INFO(7, 1, 3) },
15088 + { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
15089 +- { } /* Terminating entry */
15090 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
15091 + };
15092 +
15093 + MODULE_DEVICE_TABLE (usb, usblp_ids);
15094 +diff -urNp linux-2.6.27.10/drivers/usb/core/hub.c linux-2.6.27.10/drivers/usb/core/hub.c
15095 +--- linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-07 12:55:34.000000000 -0500
15096 ++++ linux-2.6.27.10/drivers/usb/core/hub.c 2008-11-18 03:38:45.000000000 -0500
15097 +@@ -3111,7 +3111,7 @@ static struct usb_device_id hub_id_table
15098 + .bDeviceClass = USB_CLASS_HUB},
15099 + { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
15100 + .bInterfaceClass = USB_CLASS_HUB},
15101 +- { } /* Terminating entry */
15102 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
15103 + };
15104 +
15105 + MODULE_DEVICE_TABLE (usb, hub_id_table);
15106 +diff -urNp linux-2.6.27.10/drivers/usb/host/ehci-pci.c linux-2.6.27.10/drivers/usb/host/ehci-pci.c
15107 +--- linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:37.000000000 -0500
15108 ++++ linux-2.6.27.10/drivers/usb/host/ehci-pci.c 2008-12-10 22:35:46.000000000 -0500
15109 +@@ -414,7 +414,7 @@ static const struct pci_device_id pci_id
15110 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
15111 + .driver_data = (unsigned long) &ehci_pci_hc_driver,
15112 + },
15113 +- { /* end: all zeroes */ }
15114 ++ { 0, 0, 0, 0, 0, 0, 0 }
15115 + };
15116 + MODULE_DEVICE_TABLE(pci, pci_ids);
15117 +
15118 +diff -urNp linux-2.6.27.10/drivers/usb/host/uhci-hcd.c linux-2.6.27.10/drivers/usb/host/uhci-hcd.c
15119 +--- linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-07 12:55:34.000000000 -0500
15120 ++++ linux-2.6.27.10/drivers/usb/host/uhci-hcd.c 2008-11-18 03:38:45.000000000 -0500
15121 +@@ -928,7 +928,7 @@ static const struct pci_device_id uhci_p
15122 + /* handle any USB UHCI controller */
15123 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
15124 + .driver_data = (unsigned long) &uhci_driver,
15125 +- }, { /* end: all zeroes */ }
15126 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
15127 + };
15128 +
15129 + MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
15130 +diff -urNp linux-2.6.27.10/drivers/usb/storage/debug.h linux-2.6.27.10/drivers/usb/storage/debug.h
15131 +--- linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-07 12:55:34.000000000 -0500
15132 ++++ linux-2.6.27.10/drivers/usb/storage/debug.h 2008-11-18 03:38:45.000000000 -0500
15133 +@@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
15134 + #define US_DEBUGPX(x...) printk( x )
15135 + #define US_DEBUG(x) x
15136 + #else
15137 +-#define US_DEBUGP(x...)
15138 +-#define US_DEBUGPX(x...)
15139 +-#define US_DEBUG(x)
15140 ++#define US_DEBUGP(x...) do {} while (0)
15141 ++#define US_DEBUGPX(x...) do {} while (0)
15142 ++#define US_DEBUG(x) do {} while (0)
15143 + #endif
15144 +
15145 + #endif
15146 +diff -urNp linux-2.6.27.10/drivers/usb/storage/usb.c linux-2.6.27.10/drivers/usb/storage/usb.c
15147 +--- linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-07 12:55:34.000000000 -0500
15148 ++++ linux-2.6.27.10/drivers/usb/storage/usb.c 2008-11-18 03:38:45.000000000 -0500
15149 +@@ -136,7 +136,7 @@ static struct usb_device_id storage_usb_
15150 + #undef UNUSUAL_DEV
15151 + #undef USUAL_DEV
15152 + /* Terminating entry */
15153 +- { }
15154 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
15155 + };
15156 +
15157 + MODULE_DEVICE_TABLE (usb, storage_usb_ids);
15158 +@@ -176,7 +176,7 @@ static struct us_unusual_dev us_unusual_
15159 + # undef USUAL_DEV
15160 +
15161 + /* Terminating entry */
15162 +- { NULL }
15163 ++ { NULL, NULL, 0, 0, NULL }
15164 + };
15165 +
15166 +
15167 +diff -urNp linux-2.6.27.10/drivers/video/fbcmap.c linux-2.6.27.10/drivers/video/fbcmap.c
15168 +--- linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-07 12:55:34.000000000 -0500
15169 ++++ linux-2.6.27.10/drivers/video/fbcmap.c 2008-11-18 03:38:45.000000000 -0500
15170 +@@ -250,8 +250,7 @@ int fb_set_user_cmap(struct fb_cmap_user
15171 + int rc, size = cmap->len * sizeof(u16);
15172 + struct fb_cmap umap;
15173 +
15174 +- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
15175 +- !info->fbops->fb_setcmap))
15176 ++ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap)
15177 + return -EINVAL;
15178 +
15179 + memset(&umap, 0, sizeof(struct fb_cmap));
15180 +diff -urNp linux-2.6.27.10/drivers/video/fbmem.c linux-2.6.27.10/drivers/video/fbmem.c
15181 +--- linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:37.000000000 -0500
15182 ++++ linux-2.6.27.10/drivers/video/fbmem.c 2008-12-10 22:35:46.000000000 -0500
15183 +@@ -395,7 +395,7 @@ static void fb_do_show_logo(struct fb_in
15184 + image->dx += image->width + 8;
15185 + }
15186 + } else if (rotate == FB_ROTATE_UD) {
15187 +- for (x = 0; x < num && image->dx >= 0; x++) {
15188 ++ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
15189 + info->fbops->fb_imageblit(info, image);
15190 + image->dx -= image->width + 8;
15191 + }
15192 +@@ -407,7 +407,7 @@ static void fb_do_show_logo(struct fb_in
15193 + image->dy += image->height + 8;
15194 + }
15195 + } else if (rotate == FB_ROTATE_CCW) {
15196 +- for (x = 0; x < num && image->dy >= 0; x++) {
15197 ++ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
15198 + info->fbops->fb_imageblit(info, image);
15199 + image->dy -= image->height + 8;
15200 + }
15201 +@@ -1083,7 +1083,7 @@ fb_ioctl(struct inode *inode, struct fil
15202 + return - EFAULT;
15203 + if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
15204 + return -EINVAL;
15205 +- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
15206 ++ if (con2fb.framebuffer >= FB_MAX)
15207 + return -EINVAL;
15208 + #ifdef CONFIG_KMOD
15209 + if (!registered_fb[con2fb.framebuffer])
15210 +diff -urNp linux-2.6.27.10/drivers/video/fbmon.c linux-2.6.27.10/drivers/video/fbmon.c
15211 +--- linux-2.6.27.10/drivers/video/fbmon.c 2008-11-07 12:55:34.000000000 -0500
15212 ++++ linux-2.6.27.10/drivers/video/fbmon.c 2008-11-18 03:38:45.000000000 -0500
15213 +@@ -45,7 +45,7 @@
15214 + #ifdef DEBUG
15215 + #define DPRINTK(fmt, args...) printk(fmt,## args)
15216 + #else
15217 +-#define DPRINTK(fmt, args...)
15218 ++#define DPRINTK(fmt, args...) do {} while (0)
15219 + #endif
15220 +
15221 + #define FBMON_FIX_HEADER 1
15222 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_accel.c linux-2.6.27.10/drivers/video/i810/i810_accel.c
15223 +--- linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-07 12:55:34.000000000 -0500
15224 ++++ linux-2.6.27.10/drivers/video/i810/i810_accel.c 2008-11-18 03:38:45.000000000 -0500
15225 +@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
15226 + }
15227 + }
15228 + printk("ringbuffer lockup!!!\n");
15229 ++ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
15230 + i810_report_error(mmio);
15231 + par->dev_flags |= LOCKUP;
15232 + info->pixmap.scan_align = 1;
15233 +diff -urNp linux-2.6.27.10/drivers/video/i810/i810_main.c linux-2.6.27.10/drivers/video/i810/i810_main.c
15234 +--- linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-07 12:55:34.000000000 -0500
15235 ++++ linux-2.6.27.10/drivers/video/i810/i810_main.c 2008-11-18 03:38:45.000000000 -0500
15236 +@@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
15237 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
15238 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
15239 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
15240 +- { 0 },
15241 ++ { 0, 0, 0, 0, 0, 0, 0 },
15242 + };
15243 +
15244 + static struct pci_driver i810fb_driver = {
15245 +@@ -1509,7 +1509,7 @@ static int i810fb_cursor(struct fb_info
15246 + int size = ((cursor->image.width + 7) >> 3) *
15247 + cursor->image.height;
15248 + int i;
15249 +- u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
15250 ++ u8 *data = kmalloc(64 * 8, GFP_KERNEL);
15251 +
15252 + if (data == NULL)
15253 + return -ENOMEM;
15254 +diff -urNp linux-2.6.27.10/drivers/video/modedb.c linux-2.6.27.10/drivers/video/modedb.c
15255 +--- linux-2.6.27.10/drivers/video/modedb.c 2008-11-07 12:55:34.000000000 -0500
15256 ++++ linux-2.6.27.10/drivers/video/modedb.c 2008-11-18 03:38:45.000000000 -0500
15257 +@@ -38,232 +38,232 @@ static const struct fb_videomode modedb[
15258 + {
15259 + /* 640x400 @ 70 Hz, 31.5 kHz hsync */
15260 + NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
15261 +- 0, FB_VMODE_NONINTERLACED
15262 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15263 + }, {
15264 + /* 640x480 @ 60 Hz, 31.5 kHz hsync */
15265 + NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
15266 +- 0, FB_VMODE_NONINTERLACED
15267 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15268 + }, {
15269 + /* 800x600 @ 56 Hz, 35.15 kHz hsync */
15270 + NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
15271 +- 0, FB_VMODE_NONINTERLACED
15272 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15273 + }, {
15274 + /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
15275 + NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
15276 +- 0, FB_VMODE_INTERLACED
15277 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
15278 + }, {
15279 + /* 640x400 @ 85 Hz, 37.86 kHz hsync */
15280 + NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
15281 +- FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15282 ++ FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15283 + }, {
15284 + /* 640x480 @ 72 Hz, 36.5 kHz hsync */
15285 + NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
15286 +- 0, FB_VMODE_NONINTERLACED
15287 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15288 + }, {
15289 + /* 640x480 @ 75 Hz, 37.50 kHz hsync */
15290 + NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
15291 +- 0, FB_VMODE_NONINTERLACED
15292 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15293 + }, {
15294 + /* 800x600 @ 60 Hz, 37.8 kHz hsync */
15295 + NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
15296 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15297 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15298 + }, {
15299 + /* 640x480 @ 85 Hz, 43.27 kHz hsync */
15300 + NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
15301 +- 0, FB_VMODE_NONINTERLACED
15302 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15303 + }, {
15304 + /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
15305 + NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
15306 +- 0, FB_VMODE_INTERLACED
15307 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
15308 + }, {
15309 + /* 800x600 @ 72 Hz, 48.0 kHz hsync */
15310 + NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
15311 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15312 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15313 + }, {
15314 + /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
15315 + NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
15316 +- 0, FB_VMODE_NONINTERLACED
15317 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15318 + }, {
15319 + /* 640x480 @ 100 Hz, 53.01 kHz hsync */
15320 + NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
15321 +- 0, FB_VMODE_NONINTERLACED
15322 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15323 + }, {
15324 + /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
15325 + NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
15326 +- 0, FB_VMODE_NONINTERLACED
15327 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15328 + }, {
15329 + /* 800x600 @ 85 Hz, 55.84 kHz hsync */
15330 + NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
15331 +- 0, FB_VMODE_NONINTERLACED
15332 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15333 + }, {
15334 + /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
15335 + NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
15336 +- 0, FB_VMODE_NONINTERLACED
15337 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15338 + }, {
15339 + /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
15340 + NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
15341 +- 0, FB_VMODE_INTERLACED
15342 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
15343 + }, {
15344 + /* 800x600 @ 100 Hz, 64.02 kHz hsync */
15345 + NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
15346 +- 0, FB_VMODE_NONINTERLACED
15347 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15348 + }, {
15349 + /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
15350 + NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
15351 +- 0, FB_VMODE_NONINTERLACED
15352 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15353 + }, {
15354 + /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
15355 + NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
15356 +- 0, FB_VMODE_NONINTERLACED
15357 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15358 + }, {
15359 + /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
15360 + NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
15361 +- 0, FB_VMODE_NONINTERLACED
15362 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15363 + }, {
15364 + /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
15365 + NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
15366 +- 0, FB_VMODE_NONINTERLACED
15367 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15368 + }, {
15369 + /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
15370 + NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
15371 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15372 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15373 + }, {
15374 + /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
15375 + NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
15376 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15377 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15378 + }, {
15379 + /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
15380 + NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
15381 +- 0, FB_VMODE_NONINTERLACED
15382 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15383 + }, {
15384 + /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
15385 + NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
15386 +- 0, FB_VMODE_NONINTERLACED
15387 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15388 + }, {
15389 + /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
15390 + NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
15391 +- 0, FB_VMODE_NONINTERLACED
15392 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15393 + }, {
15394 + /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
15395 + NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
15396 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15397 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15398 + }, {
15399 + /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
15400 + NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
15401 +- 0, FB_VMODE_NONINTERLACED
15402 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15403 + }, {
15404 + /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
15405 + NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
15406 +- 0, FB_VMODE_NONINTERLACED
15407 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15408 + }, {
15409 + /* 1024x768 @ 100Hz, 80.21 kHz hsync */
15410 + NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
15411 +- 0, FB_VMODE_NONINTERLACED
15412 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15413 + }, {
15414 + /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
15415 + NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
15416 +- 0, FB_VMODE_NONINTERLACED
15417 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15418 + }, {
15419 + /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
15420 + NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
15421 +- 0, FB_VMODE_NONINTERLACED
15422 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15423 + }, {
15424 + /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
15425 + NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
15426 +- 0, FB_VMODE_NONINTERLACED
15427 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15428 + }, {
15429 + /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
15430 + NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
15431 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15432 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15433 + }, {
15434 + /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
15435 + NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
15436 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15437 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15438 + }, {
15439 + /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
15440 + NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
15441 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15442 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15443 + }, {
15444 + /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
15445 + NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
15446 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15447 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15448 + }, {
15449 + /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
15450 + NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
15451 +- 0, FB_VMODE_NONINTERLACED
15452 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15453 + }, {
15454 + /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
15455 + NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
15456 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15457 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15458 + }, {
15459 + /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
15460 + NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
15461 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15462 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15463 + }, {
15464 + /* 512x384 @ 78 Hz, 31.50 kHz hsync */
15465 + NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
15466 +- 0, FB_VMODE_NONINTERLACED
15467 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15468 + }, {
15469 + /* 512x384 @ 85 Hz, 34.38 kHz hsync */
15470 + NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
15471 +- 0, FB_VMODE_NONINTERLACED
15472 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15473 + }, {
15474 + /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
15475 + NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
15476 +- 0, FB_VMODE_DOUBLE
15477 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15478 + }, {
15479 + /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
15480 + NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
15481 +- 0, FB_VMODE_DOUBLE
15482 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15483 + }, {
15484 + /* 320x240 @ 72 Hz, 36.5 kHz hsync */
15485 + NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
15486 +- 0, FB_VMODE_DOUBLE
15487 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15488 + }, {
15489 + /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
15490 + NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
15491 +- 0, FB_VMODE_DOUBLE
15492 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15493 + }, {
15494 + /* 400x300 @ 60 Hz, 37.8 kHz hsync */
15495 + NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
15496 +- 0, FB_VMODE_DOUBLE
15497 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15498 + }, {
15499 + /* 400x300 @ 72 Hz, 48.0 kHz hsync */
15500 + NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
15501 +- 0, FB_VMODE_DOUBLE
15502 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15503 + }, {
15504 + /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
15505 + NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
15506 +- 0, FB_VMODE_DOUBLE
15507 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15508 + }, {
15509 + /* 480x300 @ 60 Hz, 37.8 kHz hsync */
15510 + NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
15511 +- 0, FB_VMODE_DOUBLE
15512 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15513 + }, {
15514 + /* 480x300 @ 63 Hz, 39.6 kHz hsync */
15515 + NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
15516 +- 0, FB_VMODE_DOUBLE
15517 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15518 + }, {
15519 + /* 480x300 @ 72 Hz, 48.0 kHz hsync */
15520 + NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
15521 +- 0, FB_VMODE_DOUBLE
15522 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
15523 + }, {
15524 + /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
15525 + NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
15526 + FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
15527 +- FB_VMODE_NONINTERLACED
15528 ++ FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15529 + }, {
15530 + /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
15531 + NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
15532 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
15533 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15534 + }, {
15535 + /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
15536 + NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
15537 +- 0, FB_VMODE_NONINTERLACED
15538 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15539 + }, {
15540 + /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
15541 + NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
15542 +- 0, FB_VMODE_NONINTERLACED
15543 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
15544 + },
15545 + };
15546 +
15547 +diff -urNp linux-2.6.27.10/drivers/video/uvesafb.c linux-2.6.27.10/drivers/video/uvesafb.c
15548 +--- linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-07 12:55:34.000000000 -0500
15549 ++++ linux-2.6.27.10/drivers/video/uvesafb.c 2008-11-18 03:38:45.000000000 -0500
15550 +@@ -18,6 +18,7 @@
15551 + #include <linux/fb.h>
15552 + #include <linux/io.h>
15553 + #include <linux/mutex.h>
15554 ++#include <linux/moduleloader.h>
15555 + #include <video/edid.h>
15556 + #include <video/uvesafb.h>
15557 + #ifdef CONFIG_X86
15558 +@@ -117,7 +118,7 @@ static int uvesafb_helper_start(void)
15559 + NULL,
15560 + };
15561 +
15562 +- return call_usermodehelper(v86d_path, argv, envp, 1);
15563 ++ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
15564 + }
15565 +
15566 + /*
15567 +@@ -569,10 +570,34 @@ static int __devinit uvesafb_vbe_getpmi(
15568 + if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
15569 + par->pmi_setpal = par->ypan = 0;
15570 + } else {
15571 ++
15572 ++#ifdef CONFIG_PAX_KERNEXEC
15573 ++#ifdef CONFIG_MODULES
15574 ++ unsigned long cr0;
15575 ++
15576 ++ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
15577 ++#endif
15578 ++ if (!par->pmi_code) {
15579 ++ par->pmi_setpal = par->ypan = 0;
15580 ++ return 0;
15581 ++ }
15582 ++#endif
15583 ++
15584 + par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
15585 + + task->t.regs.edi);
15586 ++
15587 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15588 ++ pax_open_kernel(cr0);
15589 ++ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
15590 ++ pax_close_kernel(cr0);
15591 ++
15592 ++ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
15593 ++ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
15594 ++#else
15595 + par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
15596 + par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
15597 ++#endif
15598 ++
15599 + printk(KERN_INFO "uvesafb: protected mode interface info at "
15600 + "%04x:%04x\n",
15601 + (u16)task->t.regs.es, (u16)task->t.regs.edi);
15602 +@@ -1827,6 +1852,11 @@ out:
15603 + if (par->vbe_modes)
15604 + kfree(par->vbe_modes);
15605 +
15606 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15607 ++ if (par->pmi_code)
15608 ++ module_free_exec(NULL, par->pmi_code);
15609 ++#endif
15610 ++
15611 + framebuffer_release(info);
15612 + return err;
15613 + }
15614 +@@ -1853,6 +1883,12 @@ static int uvesafb_remove(struct platfor
15615 + kfree(par->vbe_state_orig);
15616 + if (par->vbe_state_saved)
15617 + kfree(par->vbe_state_saved);
15618 ++
15619 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15620 ++ if (par->pmi_code)
15621 ++ module_free_exec(NULL, par->pmi_code);
15622 ++#endif
15623 ++
15624 + }
15625 +
15626 + framebuffer_release(info);
15627 +diff -urNp linux-2.6.27.10/drivers/video/vesafb.c linux-2.6.27.10/drivers/video/vesafb.c
15628 +--- linux-2.6.27.10/drivers/video/vesafb.c 2008-11-07 12:55:34.000000000 -0500
15629 ++++ linux-2.6.27.10/drivers/video/vesafb.c 2008-11-18 03:38:45.000000000 -0500
15630 +@@ -9,6 +9,7 @@
15631 + */
15632 +
15633 + #include <linux/module.h>
15634 ++#include <linux/moduleloader.h>
15635 + #include <linux/kernel.h>
15636 + #include <linux/errno.h>
15637 + #include <linux/string.h>
15638 +@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
15639 + static int vram_total __initdata; /* Set total amount of memory */
15640 + static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
15641 + static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
15642 +-static void (*pmi_start)(void) __read_mostly;
15643 +-static void (*pmi_pal) (void) __read_mostly;
15644 ++static void (*pmi_start)(void) __read_only;
15645 ++static void (*pmi_pal) (void) __read_only;
15646 + static int depth __read_mostly;
15647 + static int vga_compat __read_mostly;
15648 + /* --------------------------------------------------------------------- */
15649 +@@ -224,6 +225,7 @@ static int __init vesafb_probe(struct pl
15650 + unsigned int size_vmode;
15651 + unsigned int size_remap;
15652 + unsigned int size_total;
15653 ++ void *pmi_code = NULL;
15654 +
15655 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
15656 + return -ENODEV;
15657 +@@ -266,10 +268,6 @@ static int __init vesafb_probe(struct pl
15658 + size_remap = size_total;
15659 + vesafb_fix.smem_len = size_remap;
15660 +
15661 +-#ifndef __i386__
15662 +- screen_info.vesapm_seg = 0;
15663 +-#endif
15664 +-
15665 + if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
15666 + printk(KERN_WARNING
15667 + "vesafb: cannot reserve video memory at 0x%lx\n",
15668 +@@ -302,9 +300,21 @@ static int __init vesafb_probe(struct pl
15669 + printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
15670 + vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
15671 +
15672 ++#ifdef __i386__
15673 ++
15674 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15675 ++ pmi_code = module_alloc_exec(screen_info.vesapm_size);
15676 ++ if (!pmi_code)
15677 ++#elif !defined(CONFIG_PAX_KERNEXEC)
15678 ++ if (0)
15679 ++#endif
15680 ++
15681 ++#endif
15682 ++ screen_info.vesapm_seg = 0;
15683 ++
15684 + if (screen_info.vesapm_seg) {
15685 +- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
15686 +- screen_info.vesapm_seg,screen_info.vesapm_off);
15687 ++ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
15688 ++ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
15689 + }
15690 +
15691 + if (screen_info.vesapm_seg < 0xc000)
15692 +@@ -312,9 +322,29 @@ static int __init vesafb_probe(struct pl
15693 +
15694 + if (ypan || pmi_setpal) {
15695 + unsigned short *pmi_base;
15696 +- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
15697 +- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
15698 +- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
15699 ++
15700 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15701 ++ unsigned long cr0;
15702 ++#endif
15703 ++
15704 ++ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
15705 ++
15706 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15707 ++ pax_open_kernel(cr0);
15708 ++ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
15709 ++#else
15710 ++ pmi_code = pmi_base;
15711 ++#endif
15712 ++
15713 ++ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
15714 ++ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
15715 ++
15716 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15717 ++ pmi_start = ktva_ktla(pmi_start);
15718 ++ pmi_pal = ktva_ktla(pmi_pal);
15719 ++ pax_close_kernel(cr0);
15720 ++#endif
15721 ++
15722 + printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
15723 + if (pmi_base[3]) {
15724 + printk(KERN_INFO "vesafb: pmi: ports = ");
15725 +@@ -456,6 +486,11 @@ static int __init vesafb_probe(struct pl
15726 + info->node, info->fix.id);
15727 + return 0;
15728 + err:
15729 ++
15730 ++#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15731 ++ module_free_exec(NULL, pmi_code);
15732 ++#endif
15733 ++
15734 + if (info->screen_base)
15735 + iounmap(info->screen_base);
15736 + framebuffer_release(info);
15737 +diff -urNp linux-2.6.27.10/fs/9p/vfs_inode.c linux-2.6.27.10/fs/9p/vfs_inode.c
15738 +--- linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-07 12:55:34.000000000 -0500
15739 ++++ linux-2.6.27.10/fs/9p/vfs_inode.c 2008-11-18 03:38:45.000000000 -0500
15740 +@@ -1021,7 +1021,7 @@ static void *v9fs_vfs_follow_link(struct
15741 + static void
15742 + v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
15743 + {
15744 +- char *s = nd_get_link(nd);
15745 ++ const char *s = nd_get_link(nd);
15746 +
15747 + P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name, s);
15748 + if (!IS_ERR(s))
15749 +diff -urNp linux-2.6.27.10/fs/aio.c linux-2.6.27.10/fs/aio.c
15750 +--- linux-2.6.27.10/fs/aio.c 2008-11-07 12:55:34.000000000 -0500
15751 ++++ linux-2.6.27.10/fs/aio.c 2008-11-18 03:38:45.000000000 -0500
15752 +@@ -114,7 +114,7 @@ static int aio_setup_ring(struct kioctx
15753 + size += sizeof(struct io_event) * nr_events;
15754 + nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
15755 +
15756 +- if (nr_pages < 0)
15757 ++ if (nr_pages <= 0)
15758 + return -EINVAL;
15759 +
15760 + nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
15761 +diff -urNp linux-2.6.27.10/fs/autofs4/symlink.c linux-2.6.27.10/fs/autofs4/symlink.c
15762 +--- linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-07 12:55:34.000000000 -0500
15763 ++++ linux-2.6.27.10/fs/autofs4/symlink.c 2008-11-18 03:38:45.000000000 -0500
15764 +@@ -15,7 +15,7 @@
15765 + static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
15766 + {
15767 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
15768 +- nd_set_link(nd, (char *)ino->u.symlink);
15769 ++ nd_set_link(nd, ino->u.symlink);
15770 + return NULL;
15771 + }
15772 +
15773 +diff -urNp linux-2.6.27.10/fs/befs/linuxvfs.c linux-2.6.27.10/fs/befs/linuxvfs.c
15774 +--- linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-07 12:55:34.000000000 -0500
15775 ++++ linux-2.6.27.10/fs/befs/linuxvfs.c 2008-11-18 03:38:45.000000000 -0500
15776 +@@ -490,7 +490,7 @@ static void befs_put_link(struct dentry
15777 + {
15778 + befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
15779 + if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
15780 +- char *link = nd_get_link(nd);
15781 ++ const char *link = nd_get_link(nd);
15782 + if (!IS_ERR(link))
15783 + kfree(link);
15784 + }
15785 +diff -urNp linux-2.6.27.10/fs/binfmt_aout.c linux-2.6.27.10/fs/binfmt_aout.c
15786 +--- linux-2.6.27.10/fs/binfmt_aout.c 2008-11-07 12:55:34.000000000 -0500
15787 ++++ linux-2.6.27.10/fs/binfmt_aout.c 2008-11-18 03:38:45.000000000 -0500
15788 +@@ -24,6 +24,7 @@
15789 + #include <linux/binfmts.h>
15790 + #include <linux/personality.h>
15791 + #include <linux/init.h>
15792 ++#include <linux/grsecurity.h>
15793 +
15794 + #include <asm/system.h>
15795 + #include <asm/uaccess.h>
15796 +@@ -124,18 +125,22 @@ static int aout_core_dump(long signr, st
15797 + /* If the size of the dump file exceeds the rlimit, then see what would happen
15798 + if we wrote the stack, but not the data area. */
15799 + #ifdef __sparc__
15800 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_dsize + dump.u_ssize, 1);
15801 + if ((dump.u_dsize + dump.u_ssize) > limit)
15802 + dump.u_dsize = 0;
15803 + #else
15804 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
15805 + if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
15806 + dump.u_dsize = 0;
15807 + #endif
15808 +
15809 + /* Make sure we have enough room to write the stack and data areas. */
15810 + #ifdef __sparc__
15811 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_ssize, 1);
15812 + if (dump.u_ssize > limit)
15813 + dump.u_ssize = 0;
15814 + #else
15815 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
15816 + if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
15817 + dump.u_ssize = 0;
15818 + #endif
15819 +@@ -291,6 +296,8 @@ static int load_aout_binary(struct linux
15820 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
15821 + if (rlim >= RLIM_INFINITY)
15822 + rlim = ~0;
15823 ++
15824 ++ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
15825 + if (ex.a_data + ex.a_bss > rlim)
15826 + return -ENOMEM;
15827 +
15828 +@@ -322,6 +329,28 @@ static int load_aout_binary(struct linux
15829 +
15830 + compute_creds(bprm);
15831 + current->flags &= ~PF_FORKNOEXEC;
15832 ++
15833 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
15834 ++ current->mm->pax_flags = 0UL;
15835 ++#endif
15836 ++
15837 ++#ifdef CONFIG_PAX_PAGEEXEC
15838 ++ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
15839 ++ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
15840 ++
15841 ++#ifdef CONFIG_PAX_EMUTRAMP
15842 ++ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
15843 ++ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
15844 ++#endif
15845 ++
15846 ++#ifdef CONFIG_PAX_MPROTECT
15847 ++ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
15848 ++ current->mm->pax_flags |= MF_PAX_MPROTECT;
15849 ++#endif
15850 ++
15851 ++ }
15852 ++#endif
15853 ++
15854 + #ifdef __sparc__
15855 + if (N_MAGIC(ex) == NMAGIC) {
15856 + loff_t pos = fd_offset;
15857 +@@ -413,7 +442,7 @@ static int load_aout_binary(struct linux
15858 +
15859 + down_write(&current->mm->mmap_sem);
15860 + error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
15861 +- PROT_READ | PROT_WRITE | PROT_EXEC,
15862 ++ PROT_READ | PROT_WRITE,
15863 + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
15864 + fd_offset + ex.a_text);
15865 + up_write(&current->mm->mmap_sem);
15866 +diff -urNp linux-2.6.27.10/fs/binfmt_elf.c linux-2.6.27.10/fs/binfmt_elf.c
15867 +--- linux-2.6.27.10/fs/binfmt_elf.c 2008-11-07 12:55:34.000000000 -0500
15868 ++++ linux-2.6.27.10/fs/binfmt_elf.c 2008-12-21 00:51:06.000000000 -0500
15869 +@@ -38,10 +38,16 @@
15870 + #include <linux/random.h>
15871 + #include <linux/elf.h>
15872 + #include <linux/utsname.h>
15873 ++#include <linux/grsecurity.h>
15874 ++
15875 + #include <asm/uaccess.h>
15876 + #include <asm/param.h>
15877 + #include <asm/page.h>
15878 +
15879 ++#ifdef CONFIG_PAX_SEGMEXEC
15880 ++#include <asm/desc.h>
15881 ++#endif
15882 ++
15883 + static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
15884 + static int load_elf_library(struct file *);
15885 + static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
15886 +@@ -57,6 +63,10 @@ static int elf_core_dump(long signr, str
15887 + #define elf_core_dump NULL
15888 + #endif
15889 +
15890 ++#ifdef CONFIG_PAX_MPROTECT
15891 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
15892 ++#endif
15893 ++
15894 + #if ELF_EXEC_PAGESIZE > PAGE_SIZE
15895 + #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
15896 + #else
15897 +@@ -76,6 +86,11 @@ static struct linux_binfmt elf_format =
15898 + .load_binary = load_elf_binary,
15899 + .load_shlib = load_elf_library,
15900 + .core_dump = elf_core_dump,
15901 ++
15902 ++#ifdef CONFIG_PAX_MPROTECT
15903 ++ .handle_mprotect= elf_handle_mprotect,
15904 ++#endif
15905 ++
15906 + .min_coredump = ELF_EXEC_PAGESIZE,
15907 + .hasvdso = 1
15908 + };
15909 +@@ -84,6 +99,8 @@ static struct linux_binfmt elf_format =
15910 +
15911 + static int set_brk(unsigned long start, unsigned long end)
15912 + {
15913 ++ unsigned long e = end;
15914 ++
15915 + start = ELF_PAGEALIGN(start);
15916 + end = ELF_PAGEALIGN(end);
15917 + if (end > start) {
15918 +@@ -94,7 +111,7 @@ static int set_brk(unsigned long start,
15919 + if (BAD_ADDR(addr))
15920 + return addr;
15921 + }
15922 +- current->mm->start_brk = current->mm->brk = end;
15923 ++ current->mm->start_brk = current->mm->brk = e;
15924 + return 0;
15925 + }
15926 +
15927 +@@ -380,10 +397,10 @@ static unsigned long load_elf_interp(str
15928 + {
15929 + struct elf_phdr *elf_phdata;
15930 + struct elf_phdr *eppnt;
15931 +- unsigned long load_addr = 0;
15932 ++ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
15933 + int load_addr_set = 0;
15934 + unsigned long last_bss = 0, elf_bss = 0;
15935 +- unsigned long error = ~0UL;
15936 ++ unsigned long error = -EINVAL;
15937 + unsigned long total_size;
15938 + int retval, i, size;
15939 +
15940 +@@ -429,6 +446,11 @@ static unsigned long load_elf_interp(str
15941 + goto out_close;
15942 + }
15943 +
15944 ++#ifdef CONFIG_PAX_SEGMEXEC
15945 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
15946 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
15947 ++#endif
15948 ++
15949 + eppnt = elf_phdata;
15950 + for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
15951 + if (eppnt->p_type == PT_LOAD) {
15952 +@@ -472,8 +494,8 @@ static unsigned long load_elf_interp(str
15953 + k = load_addr + eppnt->p_vaddr;
15954 + if (BAD_ADDR(k) ||
15955 + eppnt->p_filesz > eppnt->p_memsz ||
15956 +- eppnt->p_memsz > TASK_SIZE ||
15957 +- TASK_SIZE - eppnt->p_memsz < k) {
15958 ++ eppnt->p_memsz > pax_task_size ||
15959 ++ pax_task_size - eppnt->p_memsz < k) {
15960 + error = -ENOMEM;
15961 + goto out_close;
15962 + }
15963 +@@ -527,6 +549,177 @@ out:
15964 + return error;
15965 + }
15966 +
15967 ++#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
15968 ++static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
15969 ++{
15970 ++ unsigned long pax_flags = 0UL;
15971 ++
15972 ++#ifdef CONFIG_PAX_PAGEEXEC
15973 ++ if (elf_phdata->p_flags & PF_PAGEEXEC)
15974 ++ pax_flags |= MF_PAX_PAGEEXEC;
15975 ++#endif
15976 ++
15977 ++#ifdef CONFIG_PAX_SEGMEXEC
15978 ++ if (elf_phdata->p_flags & PF_SEGMEXEC)
15979 ++ pax_flags |= MF_PAX_SEGMEXEC;
15980 ++#endif
15981 ++
15982 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
15983 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
15984 ++ if (nx_enabled)
15985 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
15986 ++ else
15987 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
15988 ++ }
15989 ++#endif
15990 ++
15991 ++#ifdef CONFIG_PAX_EMUTRAMP
15992 ++ if (elf_phdata->p_flags & PF_EMUTRAMP)
15993 ++ pax_flags |= MF_PAX_EMUTRAMP;
15994 ++#endif
15995 ++
15996 ++#ifdef CONFIG_PAX_MPROTECT
15997 ++ if (elf_phdata->p_flags & PF_MPROTECT)
15998 ++ pax_flags |= MF_PAX_MPROTECT;
15999 ++#endif
16000 ++
16001 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
16002 ++ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
16003 ++ pax_flags |= MF_PAX_RANDMMAP;
16004 ++#endif
16005 ++
16006 ++ return pax_flags;
16007 ++}
16008 ++#endif
16009 ++
16010 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
16011 ++static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
16012 ++{
16013 ++ unsigned long pax_flags = 0UL;
16014 ++
16015 ++#ifdef CONFIG_PAX_PAGEEXEC
16016 ++ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
16017 ++ pax_flags |= MF_PAX_PAGEEXEC;
16018 ++#endif
16019 ++
16020 ++#ifdef CONFIG_PAX_SEGMEXEC
16021 ++ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
16022 ++ pax_flags |= MF_PAX_SEGMEXEC;
16023 ++#endif
16024 ++
16025 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
16026 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
16027 ++ if (nx_enabled)
16028 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
16029 ++ else
16030 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
16031 ++ }
16032 ++#endif
16033 ++
16034 ++#ifdef CONFIG_PAX_EMUTRAMP
16035 ++ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
16036 ++ pax_flags |= MF_PAX_EMUTRAMP;
16037 ++#endif
16038 ++
16039 ++#ifdef CONFIG_PAX_MPROTECT
16040 ++ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
16041 ++ pax_flags |= MF_PAX_MPROTECT;
16042 ++#endif
16043 ++
16044 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
16045 ++ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
16046 ++ pax_flags |= MF_PAX_RANDMMAP;
16047 ++#endif
16048 ++
16049 ++ return pax_flags;
16050 ++}
16051 ++#endif
16052 ++
16053 ++#ifdef CONFIG_PAX_EI_PAX
16054 ++static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
16055 ++{
16056 ++ unsigned long pax_flags = 0UL;
16057 ++
16058 ++#ifdef CONFIG_PAX_PAGEEXEC
16059 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
16060 ++ pax_flags |= MF_PAX_PAGEEXEC;
16061 ++#endif
16062 ++
16063 ++#ifdef CONFIG_PAX_SEGMEXEC
16064 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
16065 ++ pax_flags |= MF_PAX_SEGMEXEC;
16066 ++#endif
16067 ++
16068 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
16069 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
16070 ++ if (nx_enabled)
16071 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
16072 ++ else
16073 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
16074 ++ }
16075 ++#endif
16076 ++
16077 ++#ifdef CONFIG_PAX_EMUTRAMP
16078 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
16079 ++ pax_flags |= MF_PAX_EMUTRAMP;
16080 ++#endif
16081 ++
16082 ++#ifdef CONFIG_PAX_MPROTECT
16083 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
16084 ++ pax_flags |= MF_PAX_MPROTECT;
16085 ++#endif
16086 ++
16087 ++#ifdef CONFIG_PAX_ASLR
16088 ++ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
16089 ++ pax_flags |= MF_PAX_RANDMMAP;
16090 ++#endif
16091 ++
16092 ++ return pax_flags;
16093 ++}
16094 ++#endif
16095 ++
16096 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
16097 ++static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
16098 ++{
16099 ++ unsigned long pax_flags = 0UL;
16100 ++
16101 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
16102 ++ unsigned long i;
16103 ++#endif
16104 ++
16105 ++#ifdef CONFIG_PAX_EI_PAX
16106 ++ pax_flags = pax_parse_ei_pax(elf_ex);
16107 ++#endif
16108 ++
16109 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
16110 ++ for (i = 0UL; i < elf_ex->e_phnum; i++)
16111 ++ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
16112 ++ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
16113 ++ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
16114 ++ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
16115 ++ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
16116 ++ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
16117 ++ return -EINVAL;
16118 ++
16119 ++#ifdef CONFIG_PAX_SOFTMODE
16120 ++ if (pax_softmode)
16121 ++ pax_flags = pax_parse_softmode(&elf_phdata[i]);
16122 ++ else
16123 ++#endif
16124 ++
16125 ++ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
16126 ++ break;
16127 ++ }
16128 ++#endif
16129 ++
16130 ++ if (0 > pax_check_flags(&pax_flags))
16131 ++ return -EINVAL;
16132 ++
16133 ++ current->mm->pax_flags = pax_flags;
16134 ++ return 0;
16135 ++}
16136 ++#endif
16137 ++
16138 + /*
16139 + * These are the functions used to load ELF style executables and shared
16140 + * libraries. There is no binary dependent code anywhere else.
16141 +@@ -543,6 +736,11 @@ static unsigned long randomize_stack_top
16142 + {
16143 + unsigned int random_variable = 0;
16144 +
16145 ++#ifdef CONFIG_PAX_RANDUSTACK
16146 ++ if (randomize_va_space)
16147 ++ return stack_top - current->mm->delta_stack;
16148 ++#endif
16149 ++
16150 + if ((current->flags & PF_RANDOMIZE) &&
16151 + !(current->personality & ADDR_NO_RANDOMIZE)) {
16152 + random_variable = get_random_int() & STACK_RND_MASK;
16153 +@@ -561,7 +759,7 @@ static int load_elf_binary(struct linux_
16154 + unsigned long load_addr = 0, load_bias = 0;
16155 + int load_addr_set = 0;
16156 + char * elf_interpreter = NULL;
16157 +- unsigned long error;
16158 ++ unsigned long error = 0;
16159 + struct elf_phdr *elf_ppnt, *elf_phdata;
16160 + unsigned long elf_bss, elf_brk;
16161 + int elf_exec_fileno;
16162 +@@ -572,11 +770,11 @@ static int load_elf_binary(struct linux_
16163 + unsigned long start_code, end_code, start_data, end_data;
16164 + unsigned long reloc_func_desc = 0;
16165 + int executable_stack = EXSTACK_DEFAULT;
16166 +- unsigned long def_flags = 0;
16167 + struct {
16168 + struct elfhdr elf_ex;
16169 + struct elfhdr interp_elf_ex;
16170 + } *loc;
16171 ++ unsigned long pax_task_size = TASK_SIZE;
16172 +
16173 + loc = kmalloc(sizeof(*loc), GFP_KERNEL);
16174 + if (!loc) {
16175 +@@ -744,11 +942,80 @@ static int load_elf_binary(struct linux_
16176 +
16177 + /* OK, This is the point of no return */
16178 + current->flags &= ~PF_FORKNOEXEC;
16179 +- current->mm->def_flags = def_flags;
16180 ++
16181 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
16182 ++ current->mm->pax_flags = 0UL;
16183 ++#endif
16184 ++
16185 ++#ifdef CONFIG_PAX_DLRESOLVE
16186 ++ current->mm->call_dl_resolve = 0UL;
16187 ++#endif
16188 ++
16189 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
16190 ++ current->mm->call_syscall = 0UL;
16191 ++#endif
16192 ++
16193 ++#ifdef CONFIG_PAX_ASLR
16194 ++ current->mm->delta_mmap = 0UL;
16195 ++ current->mm->delta_stack = 0UL;
16196 ++#endif
16197 ++
16198 ++ current->mm->def_flags = 0;
16199 ++
16200 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
16201 ++ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
16202 ++ send_sig(SIGKILL, current, 0);
16203 ++ goto out_free_dentry;
16204 ++ }
16205 ++#endif
16206 ++
16207 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
16208 ++ pax_set_initial_flags(bprm);
16209 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
16210 ++ if (pax_set_initial_flags_func)
16211 ++ (pax_set_initial_flags_func)(bprm);
16212 ++#endif
16213 ++
16214 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
16215 ++ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
16216 ++ current->mm->context.user_cs_limit = PAGE_SIZE;
16217 ++ current->mm->def_flags |= VM_PAGEEXEC;
16218 ++ }
16219 ++#endif
16220 ++
16221 ++#ifdef CONFIG_PAX_SEGMEXEC
16222 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
16223 ++ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
16224 ++ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
16225 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
16226 ++ }
16227 ++#endif
16228 ++
16229 ++#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
16230 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
16231 ++ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
16232 ++ put_cpu_no_resched();
16233 ++ }
16234 ++#endif
16235 ++
16236 ++#ifdef CONFIG_PAX_ASLR
16237 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
16238 ++ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
16239 ++ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
16240 ++ }
16241 ++#endif
16242 +
16243 + /* Do this immediately, since STACK_TOP as used in setup_arg_pages
16244 + may depend on the personality. */
16245 + SET_PERSONALITY(loc->elf_ex, 0);
16246 ++
16247 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16248 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
16249 ++ executable_stack = EXSTACK_DISABLE_X;
16250 ++ current->personality &= ~READ_IMPLIES_EXEC;
16251 ++ } else
16252 ++#endif
16253 ++
16254 + if (elf_read_implies_exec(loc->elf_ex, executable_stack))
16255 + current->personality |= READ_IMPLIES_EXEC;
16256 +
16257 +@@ -829,6 +1096,20 @@ static int load_elf_binary(struct linux_
16258 + #else
16259 + load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
16260 + #endif
16261 ++
16262 ++#ifdef CONFIG_PAX_RANDMMAP
16263 ++ /* PaX: randomize base address at the default exe base if requested */
16264 ++ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
16265 ++#ifdef CONFIG_SPARC64
16266 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
16267 ++#else
16268 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
16269 ++#endif
16270 ++ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
16271 ++ elf_flags |= MAP_FIXED;
16272 ++ }
16273 ++#endif
16274 ++
16275 + }
16276 +
16277 + error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
16278 +@@ -861,9 +1142,9 @@ static int load_elf_binary(struct linux_
16279 + * allowed task size. Note that p_filesz must always be
16280 + * <= p_memsz so it is only necessary to check p_memsz.
16281 + */
16282 +- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
16283 +- elf_ppnt->p_memsz > TASK_SIZE ||
16284 +- TASK_SIZE - elf_ppnt->p_memsz < k) {
16285 ++ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
16286 ++ elf_ppnt->p_memsz > pax_task_size ||
16287 ++ pax_task_size - elf_ppnt->p_memsz < k) {
16288 + /* set_brk can never work. Avoid overflows. */
16289 + send_sig(SIGKILL, current, 0);
16290 + retval = -EINVAL;
16291 +@@ -891,6 +1172,11 @@ static int load_elf_binary(struct linux_
16292 + start_data += load_bias;
16293 + end_data += load_bias;
16294 +
16295 ++#ifdef CONFIG_PAX_RANDMMAP
16296 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
16297 ++ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
16298 ++#endif
16299 ++
16300 + /* Calling set_brk effectively mmaps the pages that we need
16301 + * for the bss and break sections. We must do this before
16302 + * mapping in the interpreter, to make sure it doesn't wind
16303 +@@ -902,9 +1188,11 @@ static int load_elf_binary(struct linux_
16304 + goto out_free_dentry;
16305 + }
16306 + if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
16307 +- send_sig(SIGSEGV, current, 0);
16308 +- retval = -EFAULT; /* Nobody gets to see this, but.. */
16309 +- goto out_free_dentry;
16310 ++ /*
16311 ++ * This bss-zeroing can fail if the ELF
16312 ++ * file specifies odd protections. So
16313 ++ * we don't check the return value
16314 ++ */
16315 + }
16316 +
16317 + if (elf_interpreter) {
16318 +@@ -1141,8 +1429,10 @@ static int dump_seek(struct file *file,
16319 + unsigned long n = off;
16320 + if (n > PAGE_SIZE)
16321 + n = PAGE_SIZE;
16322 +- if (!dump_write(file, buf, n))
16323 ++ if (!dump_write(file, buf, n)) {
16324 ++ free_page((unsigned long)buf);
16325 + return 0;
16326 ++ }
16327 + off -= n;
16328 + }
16329 + free_page((unsigned long)buf);
16330 +@@ -1154,7 +1444,7 @@ static int dump_seek(struct file *file,
16331 + * Decide what to dump of a segment, part, all or none.
16332 + */
16333 + static unsigned long vma_dump_size(struct vm_area_struct *vma,
16334 +- unsigned long mm_flags)
16335 ++ unsigned long mm_flags, long signr)
16336 + {
16337 + /* The vma can be set up to tell us the answer directly. */
16338 + if (vma->vm_flags & VM_ALWAYSDUMP)
16339 +@@ -1180,7 +1470,7 @@ static unsigned long vma_dump_size(struc
16340 + if (vma->vm_file == NULL)
16341 + return 0;
16342 +
16343 +- if (FILTER(MAPPED_PRIVATE))
16344 ++ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
16345 + goto whole;
16346 +
16347 + /*
16348 +@@ -1266,8 +1556,11 @@ static int writenote(struct memelfnote *
16349 + #undef DUMP_WRITE
16350 +
16351 + #define DUMP_WRITE(addr, nr) \
16352 ++ do { \
16353 ++ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
16354 + if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
16355 +- goto end_coredump;
16356 ++ goto end_coredump; \
16357 ++ } while (0);
16358 + #define DUMP_SEEK(off) \
16359 + if (!dump_seek(file, (off))) \
16360 + goto end_coredump;
16361 +@@ -1973,7 +2266,7 @@ static int elf_core_dump(long signr, str
16362 + phdr.p_offset = offset;
16363 + phdr.p_vaddr = vma->vm_start;
16364 + phdr.p_paddr = 0;
16365 +- phdr.p_filesz = vma_dump_size(vma, mm_flags);
16366 ++ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
16367 + phdr.p_memsz = vma->vm_end - vma->vm_start;
16368 + offset += phdr.p_filesz;
16369 + phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
16370 +@@ -2005,7 +2298,7 @@ static int elf_core_dump(long signr, str
16371 + unsigned long addr;
16372 + unsigned long end;
16373 +
16374 +- end = vma->vm_start + vma_dump_size(vma, mm_flags);
16375 ++ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
16376 +
16377 + for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
16378 + struct page *page;
16379 +@@ -2025,6 +2318,7 @@ static int elf_core_dump(long signr, str
16380 + flush_cache_page(tmp_vma, addr,
16381 + page_to_pfn(page));
16382 + kaddr = kmap(page);
16383 ++ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
16384 + if ((size += PAGE_SIZE) > limit ||
16385 + !dump_write(file, kaddr,
16386 + PAGE_SIZE)) {
16387 +@@ -2055,6 +2349,99 @@ out:
16388 +
16389 + #endif /* USE_ELF_CORE_DUMP */
16390 +
16391 ++#ifdef CONFIG_PAX_MPROTECT
16392 ++/* PaX: non-PIC ELF libraries need relocations on their executable segments
16393 ++ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
16394 ++ * we'll remove VM_MAYWRITE for good on RELRO segments.
16395 ++ *
16396 ++ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
16397 ++ * basis because we want to allow the common case and not the special ones.
16398 ++ */
16399 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
16400 ++{
16401 ++ struct elfhdr elf_h;
16402 ++ struct elf_phdr elf_p;
16403 ++ unsigned long i;
16404 ++ unsigned long oldflags;
16405 ++ bool is_textrel_rw, is_textrel_rx, is_relro;
16406 ++
16407 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
16408 ++ return;
16409 ++
16410 ++ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
16411 ++ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
16412 ++
16413 ++#ifdef CONFIG_PAX_NOELFRELOCS
16414 ++ is_textrel_rw = false;
16415 ++ is_textrel_rx = false;
16416 ++#else
16417 ++ /* possible TEXTREL */
16418 ++ is_textrel_rw = vma->vm_file && !vma->anon_vma && !vma->vm_pgoff && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
16419 ++ is_textrel_rx = vma->vm_file && vma->anon_vma && !vma->vm_pgoff && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
16420 ++#endif
16421 ++
16422 ++ /* possible RELRO */
16423 ++ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
16424 ++
16425 ++ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
16426 ++ return;
16427 ++
16428 ++ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
16429 ++ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
16430 ++
16431 ++#ifdef CONFIG_PAX_ETEXECRELOCS
16432 ++ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
16433 ++#else
16434 ++ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
16435 ++#endif
16436 ++
16437 ++ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
16438 ++ !elf_check_arch(&elf_h) ||
16439 ++ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
16440 ++ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
16441 ++ return;
16442 ++
16443 ++ for (i = 0UL; i < elf_h.e_phnum; i++) {
16444 ++ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
16445 ++ return;
16446 ++ switch (elf_p.p_type) {
16447 ++ case PT_DYNAMIC: {
16448 ++ elf_addr_t dyn_offset = 0UL;
16449 ++ elf_dyn dyn;
16450 ++
16451 ++ if (!is_textrel_rw && !is_textrel_rx)
16452 ++ continue;
16453 ++ dyn_offset = elf_p.p_offset;
16454 ++ i = 0UL;
16455 ++ do {
16456 ++ if (sizeof(dyn) != kernel_read(vma->vm_file, dyn_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
16457 ++ return;
16458 ++ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
16459 ++ gr_log_textrel(vma);
16460 ++ if (is_textrel_rw)
16461 ++ vma->vm_flags |= VM_MAYWRITE;
16462 ++ else
16463 ++ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
16464 ++ vma->vm_flags &= ~VM_MAYWRITE;
16465 ++ return;
16466 ++ }
16467 ++ i++;
16468 ++ } while (dyn.d_tag != DT_NULL);
16469 ++ return;
16470 ++ }
16471 ++
16472 ++ case PT_GNU_RELRO:
16473 ++ if (!is_relro)
16474 ++ continue;
16475 ++ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start) {
16476 ++ vma->vm_flags &= ~VM_MAYWRITE;
16477 ++ }
16478 ++ return;
16479 ++ }
16480 ++ }
16481 ++}
16482 ++#endif
16483 ++
16484 + static int __init init_elf_binfmt(void)
16485 + {
16486 + return register_binfmt(&elf_format);
16487 +diff -urNp linux-2.6.27.10/fs/binfmt_flat.c linux-2.6.27.10/fs/binfmt_flat.c
16488 +--- linux-2.6.27.10/fs/binfmt_flat.c 2008-11-07 12:55:34.000000000 -0500
16489 ++++ linux-2.6.27.10/fs/binfmt_flat.c 2008-11-18 03:38:45.000000000 -0500
16490 +@@ -561,7 +561,9 @@ static int load_flat_file(struct linux_b
16491 + realdatastart = (unsigned long) -ENOMEM;
16492 + printk("Unable to allocate RAM for process data, errno %d\n",
16493 + (int)-realdatastart);
16494 ++ down_write(&current->mm->mmap_sem);
16495 + do_munmap(current->mm, textpos, text_len);
16496 ++ up_write(&current->mm->mmap_sem);
16497 + ret = realdatastart;
16498 + goto err;
16499 + }
16500 +@@ -583,8 +585,10 @@ static int load_flat_file(struct linux_b
16501 + }
16502 + if (result >= (unsigned long)-4096) {
16503 + printk("Unable to read data+bss, errno %d\n", (int)-result);
16504 ++ down_write(&current->mm->mmap_sem);
16505 + do_munmap(current->mm, textpos, text_len);
16506 + do_munmap(current->mm, realdatastart, data_len + extra);
16507 ++ up_write(&current->mm->mmap_sem);
16508 + ret = result;
16509 + goto err;
16510 + }
16511 +@@ -657,8 +661,10 @@ static int load_flat_file(struct linux_b
16512 + }
16513 + if (result >= (unsigned long)-4096) {
16514 + printk("Unable to read code+data+bss, errno %d\n",(int)-result);
16515 ++ down_write(&current->mm->mmap_sem);
16516 + do_munmap(current->mm, textpos, text_len + data_len + extra +
16517 + MAX_SHARED_LIBS * sizeof(unsigned long));
16518 ++ up_write(&current->mm->mmap_sem);
16519 + ret = result;
16520 + goto err;
16521 + }
16522 +diff -urNp linux-2.6.27.10/fs/binfmt_misc.c linux-2.6.27.10/fs/binfmt_misc.c
16523 +--- linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:16:51.000000000 -0500
16524 ++++ linux-2.6.27.10/fs/binfmt_misc.c 2008-12-21 01:13:46.000000000 -0500
16525 +@@ -696,7 +696,7 @@ static int bm_fill_super(struct super_bl
16526 + static struct tree_descr bm_files[] = {
16527 + [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
16528 + [3] = {"register", &bm_register_operations, S_IWUSR},
16529 +- /* last one */ {""}
16530 ++ /* last one */ {"", NULL, 0}
16531 + };
16532 + int err = simple_fill_super(sb, 0x42494e4d, bm_files);
16533 + if (!err)
16534 +diff -urNp linux-2.6.27.10/fs/bio.c linux-2.6.27.10/fs/bio.c
16535 +--- linux-2.6.27.10/fs/bio.c 2008-11-07 12:55:34.000000000 -0500
16536 ++++ linux-2.6.27.10/fs/bio.c 2008-11-18 03:38:45.000000000 -0500
16537 +@@ -507,7 +507,7 @@ static int __bio_copy_iov(struct bio *bi
16538 +
16539 + while (bv_len && iov_idx < iov_count) {
16540 + unsigned int bytes;
16541 +- char *iov_addr;
16542 ++ char __user *iov_addr;
16543 +
16544 + bytes = min_t(unsigned int,
16545 + iov[iov_idx].iov_len - iov_off, bv_len);
16546 +diff -urNp linux-2.6.27.10/fs/buffer.c linux-2.6.27.10/fs/buffer.c
16547 +--- linux-2.6.27.10/fs/buffer.c 2008-11-07 12:55:34.000000000 -0500
16548 ++++ linux-2.6.27.10/fs/buffer.c 2008-11-18 03:38:45.000000000 -0500
16549 +@@ -41,6 +41,7 @@
16550 + #include <linux/bitops.h>
16551 + #include <linux/mpage.h>
16552 + #include <linux/bit_spinlock.h>
16553 ++#include <linux/grsecurity.h>
16554 +
16555 + static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
16556 +
16557 +@@ -2249,6 +2250,7 @@ int generic_cont_expand_simple(struct in
16558 +
16559 + err = -EFBIG;
16560 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
16561 ++ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size, 1);
16562 + if (limit != RLIM_INFINITY && size > (loff_t)limit) {
16563 + send_sig(SIGXFSZ, current, 0);
16564 + goto out;
16565 +diff -urNp linux-2.6.27.10/fs/cifs/cifs_uniupr.h linux-2.6.27.10/fs/cifs/cifs_uniupr.h
16566 +--- linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-07 12:55:34.000000000 -0500
16567 ++++ linux-2.6.27.10/fs/cifs/cifs_uniupr.h 2008-11-18 03:38:45.000000000 -0500
16568 +@@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
16569 + {0x0490, 0x04cc, UniCaseRangeU0490},
16570 + {0x1e00, 0x1ffc, UniCaseRangeU1e00},
16571 + {0xff40, 0xff5a, UniCaseRangeUff40},
16572 +- {0}
16573 ++ {0, 0, NULL}
16574 + };
16575 + #endif
16576 +
16577 +diff -urNp linux-2.6.27.10/fs/cifs/link.c linux-2.6.27.10/fs/cifs/link.c
16578 +--- linux-2.6.27.10/fs/cifs/link.c 2008-11-07 12:55:34.000000000 -0500
16579 ++++ linux-2.6.27.10/fs/cifs/link.c 2008-11-18 03:38:45.000000000 -0500
16580 +@@ -318,7 +318,7 @@ cifs_readlink(struct dentry *direntry, c
16581 +
16582 + void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
16583 + {
16584 +- char *p = nd_get_link(nd);
16585 ++ const char *p = nd_get_link(nd);
16586 + if (!IS_ERR(p))
16587 + kfree(p);
16588 + }
16589 +diff -urNp linux-2.6.27.10/fs/compat.c linux-2.6.27.10/fs/compat.c
16590 +--- linux-2.6.27.10/fs/compat.c 2008-11-07 12:55:34.000000000 -0500
16591 ++++ linux-2.6.27.10/fs/compat.c 2008-11-18 03:38:45.000000000 -0500
16592 +@@ -51,6 +51,7 @@
16593 + #include <linux/poll.h>
16594 + #include <linux/mm.h>
16595 + #include <linux/eventpoll.h>
16596 ++#include <linux/grsecurity.h>
16597 +
16598 + #include <asm/uaccess.h>
16599 + #include <asm/mmu_context.h>
16600 +@@ -1298,14 +1299,12 @@ static int compat_copy_strings(int argc,
16601 + if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
16602 + struct page *page;
16603 +
16604 +-#ifdef CONFIG_STACK_GROWSUP
16605 + ret = expand_stack_downwards(bprm->vma, pos);
16606 + if (ret < 0) {
16607 + /* We've exceed the stack rlimit. */
16608 + ret = -E2BIG;
16609 + goto out;
16610 + }
16611 +-#endif
16612 + ret = get_user_pages(current, bprm->mm, pos,
16613 + 1, 1, 1, &page, NULL);
16614 + if (ret <= 0) {
16615 +@@ -1351,6 +1350,11 @@ int compat_do_execve(char * filename,
16616 + compat_uptr_t __user *envp,
16617 + struct pt_regs * regs)
16618 + {
16619 ++#ifdef CONFIG_GRKERNSEC
16620 ++ struct file *old_exec_file;
16621 ++ struct acl_subject_label *old_acl;
16622 ++ struct rlimit old_rlim[RLIM_NLIMITS];
16623 ++#endif
16624 + struct linux_binprm *bprm;
16625 + struct file *file;
16626 + int retval;
16627 +@@ -1371,6 +1375,14 @@ int compat_do_execve(char * filename,
16628 + bprm->filename = filename;
16629 + bprm->interp = filename;
16630 +
16631 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
16632 ++ retval = -EAGAIN;
16633 ++ if (gr_handle_nproc())
16634 ++ goto out_file;
16635 ++ retval = -EACCES;
16636 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
16637 ++ goto out_file;
16638 ++
16639 + retval = bprm_mm_init(bprm);
16640 + if (retval)
16641 + goto out_file;
16642 +@@ -1404,8 +1416,36 @@ int compat_do_execve(char * filename,
16643 + if (retval < 0)
16644 + goto out;
16645 +
16646 ++ if (!gr_tpe_allow(file)) {
16647 ++ retval = -EACCES;
16648 ++ goto out;
16649 ++ }
16650 ++
16651 ++ if (gr_check_crash_exec(file)) {
16652 ++ retval = -EACCES;
16653 ++ goto out;
16654 ++ }
16655 ++
16656 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
16657 ++
16658 ++ gr_handle_exec_args(bprm, (char __user * __user *)argv);
16659 ++
16660 ++#ifdef CONFIG_GRKERNSEC
16661 ++ old_acl = current->acl;
16662 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
16663 ++ old_exec_file = current->exec_file;
16664 ++ get_file(file);
16665 ++ current->exec_file = file;
16666 ++#endif
16667 ++
16668 ++ gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
16669 ++
16670 + retval = search_binary_handler(bprm, regs);
16671 + if (retval >= 0) {
16672 ++#ifdef CONFIG_GRKERNSEC
16673 ++ if (old_exec_file)
16674 ++ fput(old_exec_file);
16675 ++#endif
16676 + /* execve success */
16677 + security_bprm_free(bprm);
16678 + acct_update_integrals(current);
16679 +@@ -1413,6 +1453,13 @@ int compat_do_execve(char * filename,
16680 + return retval;
16681 + }
16682 +
16683 ++#ifdef CONFIG_GRKERNSEC
16684 ++ current->acl = old_acl;
16685 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
16686 ++ fput(current->exec_file);
16687 ++ current->exec_file = old_exec_file;
16688 ++#endif
16689 ++
16690 + out:
16691 + if (bprm->security)
16692 + security_bprm_free(bprm);
16693 +diff -urNp linux-2.6.27.10/fs/compat_ioctl.c linux-2.6.27.10/fs/compat_ioctl.c
16694 +--- linux-2.6.27.10/fs/compat_ioctl.c 2008-11-07 12:55:34.000000000 -0500
16695 ++++ linux-2.6.27.10/fs/compat_ioctl.c 2008-11-18 03:38:45.000000000 -0500
16696 +@@ -1831,15 +1831,15 @@ struct ioctl_trans {
16697 + };
16698 +
16699 + #define HANDLE_IOCTL(cmd,handler) \
16700 +- { (cmd), (ioctl_trans_handler_t)(handler) },
16701 ++ { (cmd), (ioctl_trans_handler_t)(handler), NULL },
16702 +
16703 + /* pointer to compatible structure or no argument */
16704 + #define COMPATIBLE_IOCTL(cmd) \
16705 +- { (cmd), do_ioctl32_pointer },
16706 ++ { (cmd), do_ioctl32_pointer, NULL },
16707 +
16708 + /* argument is an unsigned long integer, not a pointer */
16709 + #define ULONG_IOCTL(cmd) \
16710 +- { (cmd), (ioctl_trans_handler_t)sys_ioctl },
16711 ++ { (cmd), (ioctl_trans_handler_t)sys_ioctl, NULL },
16712 +
16713 + /* ioctl should not be warned about even if it's not implemented.
16714 + Valid reasons to use this:
16715 +diff -urNp linux-2.6.27.10/fs/debugfs/inode.c linux-2.6.27.10/fs/debugfs/inode.c
16716 +--- linux-2.6.27.10/fs/debugfs/inode.c 2008-11-07 12:55:34.000000000 -0500
16717 ++++ linux-2.6.27.10/fs/debugfs/inode.c 2008-11-18 03:38:45.000000000 -0500
16718 +@@ -121,7 +121,7 @@ static inline int debugfs_positive(struc
16719 +
16720 + static int debug_fill_super(struct super_block *sb, void *data, int silent)
16721 + {
16722 +- static struct tree_descr debug_files[] = {{""}};
16723 ++ static struct tree_descr debug_files[] = {{"", NULL, 0}};
16724 +
16725 + return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
16726 + }
16727 +diff -urNp linux-2.6.27.10/fs/exec.c linux-2.6.27.10/fs/exec.c
16728 +--- linux-2.6.27.10/fs/exec.c 2008-12-21 01:16:51.000000000 -0500
16729 ++++ linux-2.6.27.10/fs/exec.c 2008-12-21 01:13:46.000000000 -0500
16730 +@@ -50,6 +50,13 @@
16731 + #include <linux/cn_proc.h>
16732 + #include <linux/audit.h>
16733 + #include <linux/tracehook.h>
16734 ++#include <linux/random.h>
16735 ++#include <linux/grsecurity.h>
16736 ++
16737 ++#ifdef CONFIG_PAX_REFCOUNT
16738 ++#include <linux/kallsyms.h>
16739 ++#include <linux/kdebug.h>
16740 ++#endif
16741 +
16742 + #include <asm/uaccess.h>
16743 + #include <asm/mmu_context.h>
16744 +@@ -64,6 +71,11 @@
16745 + #include <linux/a.out.h>
16746 + #endif
16747 +
16748 ++#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
16749 ++void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
16750 ++EXPORT_SYMBOL(pax_set_initial_flags_func);
16751 ++#endif
16752 ++
16753 + int core_uses_pid;
16754 + char core_pattern[CORENAME_MAX_SIZE] = "core";
16755 + int suid_dumpable = 0;
16756 +@@ -172,18 +184,10 @@ static struct page *get_arg_page(struct
16757 + int write)
16758 + {
16759 + struct page *page;
16760 +- int ret;
16761 +
16762 +-#ifdef CONFIG_STACK_GROWSUP
16763 +- if (write) {
16764 +- ret = expand_stack_downwards(bprm->vma, pos);
16765 +- if (ret < 0)
16766 +- return NULL;
16767 +- }
16768 +-#endif
16769 +- ret = get_user_pages(current, bprm->mm, pos,
16770 +- 1, write, 1, &page, NULL);
16771 +- if (ret <= 0)
16772 ++ if (0 > expand_stack_downwards(bprm->vma, pos))
16773 ++ return NULL;
16774 ++ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
16775 + return NULL;
16776 +
16777 + if (write) {
16778 +@@ -256,6 +260,11 @@ static int __bprm_mm_init(struct linux_b
16779 + vma->vm_start = vma->vm_end - PAGE_SIZE;
16780 +
16781 + vma->vm_flags = VM_STACK_FLAGS;
16782 ++
16783 ++#ifdef CONFIG_PAX_SEGMEXEC
16784 ++ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
16785 ++#endif
16786 ++
16787 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
16788 + err = insert_vm_struct(mm, vma);
16789 + if (err) {
16790 +@@ -268,6 +277,11 @@ static int __bprm_mm_init(struct linux_b
16791 +
16792 + bprm->p = vma->vm_end - sizeof(void *);
16793 +
16794 ++#ifdef CONFIG_PAX_RANDUSTACK
16795 ++ if (randomize_va_space)
16796 ++ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
16797 ++#endif
16798 ++
16799 + return 0;
16800 +
16801 + err:
16802 +@@ -391,7 +405,7 @@ static int count(char __user * __user *
16803 + if (!p)
16804 + break;
16805 + argv++;
16806 +- if(++i > max)
16807 ++ if (++i > max)
16808 + return -E2BIG;
16809 + cond_resched();
16810 + }
16811 +@@ -531,6 +545,10 @@ static int shift_arg_pages(struct vm_are
16812 + if (vma != find_vma(mm, new_start))
16813 + return -EFAULT;
16814 +
16815 ++#ifdef CONFIG_PAX_SEGMEXEC
16816 ++ BUG_ON(pax_find_mirror_vma(vma));
16817 ++#endif
16818 ++
16819 + /*
16820 + * cover the whole range: [new_start, old_end)
16821 + */
16822 +@@ -619,6 +637,14 @@ int setup_arg_pages(struct linux_binprm
16823 + bprm->exec -= stack_shift;
16824 +
16825 + down_write(&mm->mmap_sem);
16826 ++
16827 ++ /* Move stack pages down in memory. */
16828 ++ if (stack_shift) {
16829 ++ ret = shift_arg_pages(vma, stack_shift);
16830 ++ if (ret)
16831 ++ goto out_unlock;
16832 ++ }
16833 ++
16834 + vm_flags = VM_STACK_FLAGS;
16835 +
16836 + /*
16837 +@@ -632,21 +658,24 @@ int setup_arg_pages(struct linux_binprm
16838 + vm_flags &= ~VM_EXEC;
16839 + vm_flags |= mm->def_flags;
16840 +
16841 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16842 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
16843 ++ vm_flags &= ~VM_EXEC;
16844 ++
16845 ++#ifdef CONFIG_PAX_MPROTECT
16846 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
16847 ++ vm_flags &= ~VM_MAYEXEC;
16848 ++#endif
16849 ++
16850 ++ }
16851 ++#endif
16852 ++
16853 + ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
16854 + vm_flags);
16855 + if (ret)
16856 + goto out_unlock;
16857 + BUG_ON(prev != vma);
16858 +
16859 +- /* Move stack pages down in memory. */
16860 +- if (stack_shift) {
16861 +- ret = shift_arg_pages(vma, stack_shift);
16862 +- if (ret) {
16863 +- up_write(&mm->mmap_sem);
16864 +- return ret;
16865 +- }
16866 +- }
16867 +-
16868 + #ifdef CONFIG_STACK_GROWSUP
16869 + stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
16870 + #else
16871 +@@ -658,7 +687,7 @@ int setup_arg_pages(struct linux_binprm
16872 +
16873 + out_unlock:
16874 + up_write(&mm->mmap_sem);
16875 +- return 0;
16876 ++ return ret;
16877 + }
16878 + EXPORT_SYMBOL(setup_arg_pages);
16879 +
16880 +@@ -1286,6 +1315,11 @@ int do_execve(char * filename,
16881 + char __user *__user *envp,
16882 + struct pt_regs * regs)
16883 + {
16884 ++#ifdef CONFIG_GRKERNSEC
16885 ++ struct file *old_exec_file;
16886 ++ struct acl_subject_label *old_acl;
16887 ++ struct rlimit old_rlim[RLIM_NLIMITS];
16888 ++#endif
16889 + struct linux_binprm *bprm;
16890 + struct file *file;
16891 + struct files_struct *displaced;
16892 +@@ -1305,6 +1339,20 @@ int do_execve(char * filename,
16893 + if (IS_ERR(file))
16894 + goto out_kfree;
16895 +
16896 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
16897 ++
16898 ++ if (gr_handle_nproc()) {
16899 ++ allow_write_access(file);
16900 ++ fput(file);
16901 ++ return -EAGAIN;
16902 ++ }
16903 ++
16904 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
16905 ++ allow_write_access(file);
16906 ++ fput(file);
16907 ++ return -EACCES;
16908 ++ }
16909 ++
16910 + sched_exec();
16911 +
16912 + bprm->file = file;
16913 +@@ -1344,9 +1392,39 @@ int do_execve(char * filename,
16914 + if (retval < 0)
16915 + goto out;
16916 +
16917 ++ if (!gr_tpe_allow(file)) {
16918 ++ retval = -EACCES;
16919 ++ goto out;
16920 ++ }
16921 ++
16922 ++ if (gr_check_crash_exec(file)) {
16923 ++ retval = -EACCES;
16924 ++ goto out;
16925 ++ }
16926 ++
16927 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
16928 ++
16929 ++ gr_handle_exec_args(bprm, argv);
16930 ++
16931 ++#ifdef CONFIG_GRKERNSEC
16932 ++ old_acl = current->acl;
16933 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
16934 ++ old_exec_file = current->exec_file;
16935 ++ get_file(file);
16936 ++ current->exec_file = file;
16937 ++#endif
16938 ++
16939 ++ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
16940 ++ if (retval < 0)
16941 ++ goto out_fail;
16942 ++
16943 + current->flags &= ~PF_KTHREAD;
16944 + retval = search_binary_handler(bprm,regs);
16945 + if (retval >= 0) {
16946 ++#ifdef CONFIG_GRKERNSEC
16947 ++ if (old_exec_file)
16948 ++ fput(old_exec_file);
16949 ++#endif
16950 + /* execve success */
16951 + security_bprm_free(bprm);
16952 + acct_update_integrals(current);
16953 +@@ -1356,6 +1434,14 @@ int do_execve(char * filename,
16954 + return retval;
16955 + }
16956 +
16957 ++out_fail:
16958 ++#ifdef CONFIG_GRKERNSEC
16959 ++ current->acl = old_acl;
16960 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
16961 ++ fput(current->exec_file);
16962 ++ current->exec_file = old_exec_file;
16963 ++#endif
16964 ++
16965 + out:
16966 + if (bprm->security)
16967 + security_bprm_free(bprm);
16968 +@@ -1519,6 +1605,125 @@ out:
16969 + return ispipe;
16970 + }
16971 +
16972 ++int pax_check_flags(unsigned long *flags)
16973 ++{
16974 ++ int retval = 0;
16975 ++
16976 ++#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
16977 ++ if (*flags & MF_PAX_SEGMEXEC)
16978 ++ {
16979 ++ *flags &= ~MF_PAX_SEGMEXEC;
16980 ++ retval = -EINVAL;
16981 ++ }
16982 ++#endif
16983 ++
16984 ++ if ((*flags & MF_PAX_PAGEEXEC)
16985 ++
16986 ++#ifdef CONFIG_PAX_PAGEEXEC
16987 ++ && (*flags & MF_PAX_SEGMEXEC)
16988 ++#endif
16989 ++
16990 ++ )
16991 ++ {
16992 ++ *flags &= ~MF_PAX_PAGEEXEC;
16993 ++ retval = -EINVAL;
16994 ++ }
16995 ++
16996 ++ if ((*flags & MF_PAX_MPROTECT)
16997 ++
16998 ++#ifdef CONFIG_PAX_MPROTECT
16999 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
17000 ++#endif
17001 ++
17002 ++ )
17003 ++ {
17004 ++ *flags &= ~MF_PAX_MPROTECT;
17005 ++ retval = -EINVAL;
17006 ++ }
17007 ++
17008 ++ if ((*flags & MF_PAX_EMUTRAMP)
17009 ++
17010 ++#ifdef CONFIG_PAX_EMUTRAMP
17011 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
17012 ++#endif
17013 ++
17014 ++ )
17015 ++ {
17016 ++ *flags &= ~MF_PAX_EMUTRAMP;
17017 ++ retval = -EINVAL;
17018 ++ }
17019 ++
17020 ++ return retval;
17021 ++}
17022 ++
17023 ++EXPORT_SYMBOL(pax_check_flags);
17024 ++
17025 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17026 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
17027 ++{
17028 ++ struct task_struct *tsk = current;
17029 ++ struct mm_struct *mm = current->mm;
17030 ++ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
17031 ++ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
17032 ++ char *path_exec = NULL;
17033 ++ char *path_fault = NULL;
17034 ++ unsigned long start = 0UL, end = 0UL, offset = 0UL;
17035 ++
17036 ++ if (buffer_exec && buffer_fault) {
17037 ++ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
17038 ++
17039 ++ down_read(&mm->mmap_sem);
17040 ++ vma = mm->mmap;
17041 ++ while (vma && (!vma_exec || !vma_fault)) {
17042 ++ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
17043 ++ vma_exec = vma;
17044 ++ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
17045 ++ vma_fault = vma;
17046 ++ vma = vma->vm_next;
17047 ++ }
17048 ++ if (vma_exec) {
17049 ++ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
17050 ++ if (IS_ERR(path_exec))
17051 ++ path_exec = "<path too long>";
17052 ++ }
17053 ++ if (vma_fault) {
17054 ++ start = vma_fault->vm_start;
17055 ++ end = vma_fault->vm_end;
17056 ++ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
17057 ++ if (vma_fault->vm_file) {
17058 ++ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
17059 ++ if (IS_ERR(path_fault))
17060 ++ path_fault = "<path too long>";
17061 ++ } else
17062 ++ path_fault = "<anonymous mapping>";
17063 ++ }
17064 ++ up_read(&mm->mmap_sem);
17065 ++ }
17066 ++ if (tsk->signal->curr_ip)
17067 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: execution attempt in: %s, %08lx-%08lx %08lx\n", NIPQUAD(tsk->signal->curr_ip), path_fault, start, end, offset);
17068 ++ else
17069 ++ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
17070 ++ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
17071 ++ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
17072 ++ tsk->uid, tsk->euid, pc, sp);
17073 ++ free_page((unsigned long)buffer_exec);
17074 ++ free_page((unsigned long)buffer_fault);
17075 ++ pax_report_insns(pc, sp);
17076 ++ do_coredump(SIGKILL, SIGKILL, regs);
17077 ++}
17078 ++#endif
17079 ++
17080 ++#ifdef CONFIG_PAX_REFCOUNT
17081 ++void pax_report_refcount_overflow(struct pt_regs *regs)
17082 ++{
17083 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
17084 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
17085 ++ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
17086 ++ show_registers(regs);
17087 ++ force_sig_specific(SIGKILL, current);
17088 ++}
17089 ++#endif
17090 ++
17091 + static int zap_process(struct task_struct *start)
17092 + {
17093 + struct task_struct *t;
17094 +@@ -1765,6 +1970,10 @@ int do_coredump(long signr, int exit_cod
17095 + */
17096 + clear_thread_flag(TIF_SIGPENDING);
17097 +
17098 ++ if (signr == SIGKILL || signr == SIGILL)
17099 ++ gr_handle_brute_attach(current);
17100 ++ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
17101 ++
17102 + /*
17103 + * lock_kernel() because format_corename() is controlled by sysctl, which
17104 + * uses lock_kernel()
17105 +@@ -1785,6 +1994,8 @@ int do_coredump(long signr, int exit_cod
17106 +
17107 + if (ispipe) {
17108 + helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
17109 ++ if (!helper_argv)
17110 ++ goto fail_unlock;
17111 + /* Terminate the string before the first option */
17112 + delimit = strchr(corename, ' ');
17113 + if (delimit)
17114 +diff -urNp linux-2.6.27.10/fs/ext2/balloc.c linux-2.6.27.10/fs/ext2/balloc.c
17115 +--- linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:37.000000000 -0500
17116 ++++ linux-2.6.27.10/fs/ext2/balloc.c 2008-12-10 22:35:46.000000000 -0500
17117 +@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
17118 +
17119 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
17120 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
17121 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
17122 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
17123 + sbi->s_resuid != current->fsuid &&
17124 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
17125 + return 0;
17126 +diff -urNp linux-2.6.27.10/fs/ext3/balloc.c linux-2.6.27.10/fs/ext3/balloc.c
17127 +--- linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:37.000000000 -0500
17128 ++++ linux-2.6.27.10/fs/ext3/balloc.c 2008-12-10 22:35:46.000000000 -0500
17129 +@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
17130 +
17131 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
17132 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
17133 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
17134 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
17135 + sbi->s_resuid != current->fsuid &&
17136 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
17137 + return 0;
17138 +diff -urNp linux-2.6.27.10/fs/ext3/namei.c linux-2.6.27.10/fs/ext3/namei.c
17139 +--- linux-2.6.27.10/fs/ext3/namei.c 2008-11-07 12:55:34.000000000 -0500
17140 ++++ linux-2.6.27.10/fs/ext3/namei.c 2008-11-18 03:38:45.000000000 -0500
17141 +@@ -1173,9 +1173,9 @@ static struct ext3_dir_entry_2 *do_split
17142 + u32 hash2;
17143 + struct dx_map_entry *map;
17144 + char *data1 = (*bh)->b_data, *data2;
17145 +- unsigned split, move, size, i;
17146 ++ unsigned split, move, size;
17147 + struct ext3_dir_entry_2 *de = NULL, *de2;
17148 +- int err = 0;
17149 ++ int i, err = 0;
17150 +
17151 + bh2 = ext3_append (handle, dir, &newblock, &err);
17152 + if (!(bh2)) {
17153 +diff -urNp linux-2.6.27.10/fs/ext3/xattr.c linux-2.6.27.10/fs/ext3/xattr.c
17154 +--- linux-2.6.27.10/fs/ext3/xattr.c 2008-11-07 12:55:34.000000000 -0500
17155 ++++ linux-2.6.27.10/fs/ext3/xattr.c 2008-11-18 03:38:45.000000000 -0500
17156 +@@ -89,8 +89,8 @@
17157 + printk("\n"); \
17158 + } while (0)
17159 + #else
17160 +-# define ea_idebug(f...)
17161 +-# define ea_bdebug(f...)
17162 ++# define ea_idebug(f...) do {} while (0)
17163 ++# define ea_bdebug(f...) do {} while (0)
17164 + #endif
17165 +
17166 + static void ext3_xattr_cache_insert(struct buffer_head *);
17167 +diff -urNp linux-2.6.27.10/fs/ext4/balloc.c linux-2.6.27.10/fs/ext4/balloc.c
17168 +--- linux-2.6.27.10/fs/ext4/balloc.c 2008-11-07 12:55:34.000000000 -0500
17169 ++++ linux-2.6.27.10/fs/ext4/balloc.c 2008-11-18 03:38:45.000000000 -0500
17170 +@@ -1617,7 +1617,7 @@ ext4_fsblk_t ext4_has_free_blocks(struct
17171 +
17172 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
17173 +
17174 +- if (!capable(CAP_SYS_RESOURCE) &&
17175 ++ if (!capable_nolog(CAP_SYS_RESOURCE) &&
17176 + sbi->s_resuid != current->fsuid &&
17177 + (sbi->s_resgid == 0 || !in_group_p(sbi->s_resgid)))
17178 + root_blocks = ext4_r_blocks_count(sbi->s_es);
17179 +diff -urNp linux-2.6.27.10/fs/ext4/namei.c linux-2.6.27.10/fs/ext4/namei.c
17180 +--- linux-2.6.27.10/fs/ext4/namei.c 2008-11-07 12:55:34.000000000 -0500
17181 ++++ linux-2.6.27.10/fs/ext4/namei.c 2008-11-18 03:38:45.000000000 -0500
17182 +@@ -1176,9 +1176,9 @@ static struct ext4_dir_entry_2 *do_split
17183 + u32 hash2;
17184 + struct dx_map_entry *map;
17185 + char *data1 = (*bh)->b_data, *data2;
17186 +- unsigned split, move, size, i;
17187 ++ unsigned split, move, size;
17188 + struct ext4_dir_entry_2 *de = NULL, *de2;
17189 +- int err = 0;
17190 ++ int i, err = 0;
17191 +
17192 + bh2 = ext4_append (handle, dir, &newblock, &err);
17193 + if (!(bh2)) {
17194 +diff -urNp linux-2.6.27.10/fs/fcntl.c linux-2.6.27.10/fs/fcntl.c
17195 +--- linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:16:51.000000000 -0500
17196 ++++ linux-2.6.27.10/fs/fcntl.c 2008-12-21 01:14:31.000000000 -0500
17197 +@@ -19,6 +19,7 @@
17198 + #include <linux/signal.h>
17199 + #include <linux/rcupdate.h>
17200 + #include <linux/pid_namespace.h>
17201 ++#include <linux/grsecurity.h>
17202 + #include <linux/smp_lock.h>
17203 +
17204 + #include <asm/poll.h>
17205 +@@ -266,6 +267,7 @@ static long do_fcntl(int fd, unsigned in
17206 + switch (cmd) {
17207 + case F_DUPFD:
17208 + case F_DUPFD_CLOEXEC:
17209 ++ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
17210 + if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
17211 + break;
17212 + err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
17213 +@@ -410,7 +412,8 @@ static inline int sigio_perm(struct task
17214 + return (((fown->euid == 0) ||
17215 + (fown->euid == p->suid) || (fown->euid == p->uid) ||
17216 + (fown->uid == p->suid) || (fown->uid == p->uid)) &&
17217 +- !security_file_send_sigiotask(p, fown, sig));
17218 ++ !security_file_send_sigiotask(p, fown, sig) &&
17219 ++ !gr_check_protected_task(p) && !gr_pid_is_chrooted(p));
17220 + }
17221 +
17222 + static void send_sigio_to_task(struct task_struct *p,
17223 +diff -urNp linux-2.6.27.10/fs/file.c linux-2.6.27.10/fs/file.c
17224 +--- linux-2.6.27.10/fs/file.c 2008-11-07 12:55:34.000000000 -0500
17225 ++++ linux-2.6.27.10/fs/file.c 2008-11-18 03:38:45.000000000 -0500
17226 +@@ -19,6 +19,7 @@
17227 + #include <linux/spinlock.h>
17228 + #include <linux/rcupdate.h>
17229 + #include <linux/workqueue.h>
17230 ++#include <linux/grsecurity.h>
17231 +
17232 + struct fdtable_defer {
17233 + spinlock_t lock;
17234 +@@ -256,6 +257,8 @@ int expand_files(struct files_struct *fi
17235 + * N.B. For clone tasks sharing a files structure, this test
17236 + * will limit the total number of files that can be opened.
17237 + */
17238 ++
17239 ++ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
17240 + if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
17241 + return -EMFILE;
17242 +
17243 +diff -urNp linux-2.6.27.10/fs/fuse/control.c linux-2.6.27.10/fs/fuse/control.c
17244 +--- linux-2.6.27.10/fs/fuse/control.c 2008-11-07 12:55:34.000000000 -0500
17245 ++++ linux-2.6.27.10/fs/fuse/control.c 2008-11-18 03:38:45.000000000 -0500
17246 +@@ -159,7 +159,7 @@ void fuse_ctl_remove_conn(struct fuse_co
17247 +
17248 + static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
17249 + {
17250 +- struct tree_descr empty_descr = {""};
17251 ++ struct tree_descr empty_descr = {"", NULL, 0};
17252 + struct fuse_conn *fc;
17253 + int err;
17254 +
17255 +diff -urNp linux-2.6.27.10/fs/fuse/dir.c linux-2.6.27.10/fs/fuse/dir.c
17256 +--- linux-2.6.27.10/fs/fuse/dir.c 2008-11-07 12:55:34.000000000 -0500
17257 ++++ linux-2.6.27.10/fs/fuse/dir.c 2008-11-18 03:38:45.000000000 -0500
17258 +@@ -1072,7 +1072,7 @@ static char *read_link(struct dentry *de
17259 + return link;
17260 + }
17261 +
17262 +-static void free_link(char *link)
17263 ++static void free_link(const char *link)
17264 + {
17265 + if (!IS_ERR(link))
17266 + free_page((unsigned long) link);
17267 +diff -urNp linux-2.6.27.10/fs/hfs/inode.c linux-2.6.27.10/fs/hfs/inode.c
17268 +--- linux-2.6.27.10/fs/hfs/inode.c 2008-11-07 12:55:34.000000000 -0500
17269 ++++ linux-2.6.27.10/fs/hfs/inode.c 2008-11-18 03:38:45.000000000 -0500
17270 +@@ -419,7 +419,7 @@ int hfs_write_inode(struct inode *inode,
17271 +
17272 + if (S_ISDIR(main_inode->i_mode)) {
17273 + if (fd.entrylength < sizeof(struct hfs_cat_dir))
17274 +- /* panic? */;
17275 ++ {/* panic? */}
17276 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
17277 + sizeof(struct hfs_cat_dir));
17278 + if (rec.type != HFS_CDR_DIR ||
17279 +@@ -440,7 +440,7 @@ int hfs_write_inode(struct inode *inode,
17280 + sizeof(struct hfs_cat_file));
17281 + } else {
17282 + if (fd.entrylength < sizeof(struct hfs_cat_file))
17283 +- /* panic? */;
17284 ++ {/* panic? */}
17285 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
17286 + sizeof(struct hfs_cat_file));
17287 + if (rec.type != HFS_CDR_FIL ||
17288 +diff -urNp linux-2.6.27.10/fs/hfsplus/inode.c linux-2.6.27.10/fs/hfsplus/inode.c
17289 +--- linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-07 12:55:34.000000000 -0500
17290 ++++ linux-2.6.27.10/fs/hfsplus/inode.c 2008-11-18 03:38:45.000000000 -0500
17291 +@@ -417,7 +417,7 @@ int hfsplus_cat_read_inode(struct inode
17292 + struct hfsplus_cat_folder *folder = &entry.folder;
17293 +
17294 + if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
17295 +- /* panic? */;
17296 ++ {/* panic? */}
17297 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
17298 + sizeof(struct hfsplus_cat_folder));
17299 + hfsplus_get_perms(inode, &folder->permissions, 1);
17300 +@@ -434,7 +434,7 @@ int hfsplus_cat_read_inode(struct inode
17301 + struct hfsplus_cat_file *file = &entry.file;
17302 +
17303 + if (fd->entrylength < sizeof(struct hfsplus_cat_file))
17304 +- /* panic? */;
17305 ++ {/* panic? */}
17306 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
17307 + sizeof(struct hfsplus_cat_file));
17308 +
17309 +@@ -490,7 +490,7 @@ int hfsplus_cat_write_inode(struct inode
17310 + struct hfsplus_cat_folder *folder = &entry.folder;
17311 +
17312 + if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
17313 +- /* panic? */;
17314 ++ {/* panic? */}
17315 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
17316 + sizeof(struct hfsplus_cat_folder));
17317 + /* simple node checks? */
17318 +@@ -512,7 +512,7 @@ int hfsplus_cat_write_inode(struct inode
17319 + struct hfsplus_cat_file *file = &entry.file;
17320 +
17321 + if (fd.entrylength < sizeof(struct hfsplus_cat_file))
17322 +- /* panic? */;
17323 ++ {/* panic? */}
17324 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
17325 + sizeof(struct hfsplus_cat_file));
17326 + hfsplus_inode_write_fork(inode, &file->data_fork);
17327 +diff -urNp linux-2.6.27.10/fs/jffs2/debug.h linux-2.6.27.10/fs/jffs2/debug.h
17328 +--- linux-2.6.27.10/fs/jffs2/debug.h 2008-11-07 12:55:34.000000000 -0500
17329 ++++ linux-2.6.27.10/fs/jffs2/debug.h 2008-11-18 03:38:45.000000000 -0500
17330 +@@ -52,13 +52,13 @@
17331 + #if CONFIG_JFFS2_FS_DEBUG > 0
17332 + #define D1(x) x
17333 + #else
17334 +-#define D1(x)
17335 ++#define D1(x) do {} while (0);
17336 + #endif
17337 +
17338 + #if CONFIG_JFFS2_FS_DEBUG > 1
17339 + #define D2(x) x
17340 + #else
17341 +-#define D2(x)
17342 ++#define D2(x) do {} while (0);
17343 + #endif
17344 +
17345 + /* The prefixes of JFFS2 messages */
17346 +@@ -114,73 +114,73 @@
17347 + #ifdef JFFS2_DBG_READINODE_MESSAGES
17348 + #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17349 + #else
17350 +-#define dbg_readinode(fmt, ...)
17351 ++#define dbg_readinode(fmt, ...) do {} while (0)
17352 + #endif
17353 + #ifdef JFFS2_DBG_READINODE2_MESSAGES
17354 + #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17355 + #else
17356 +-#define dbg_readinode2(fmt, ...)
17357 ++#define dbg_readinode2(fmt, ...) do {} while (0)
17358 + #endif
17359 +
17360 + /* Fragtree build debugging messages */
17361 + #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
17362 + #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17363 + #else
17364 +-#define dbg_fragtree(fmt, ...)
17365 ++#define dbg_fragtree(fmt, ...) do {} while (0)
17366 + #endif
17367 + #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
17368 + #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17369 + #else
17370 +-#define dbg_fragtree2(fmt, ...)
17371 ++#define dbg_fragtree2(fmt, ...) do {} while (0)
17372 + #endif
17373 +
17374 + /* Directory entry list manilulation debugging messages */
17375 + #ifdef JFFS2_DBG_DENTLIST_MESSAGES
17376 + #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17377 + #else
17378 +-#define dbg_dentlist(fmt, ...)
17379 ++#define dbg_dentlist(fmt, ...) do {} while (0)
17380 + #endif
17381 +
17382 + /* Print the messages about manipulating node_refs */
17383 + #ifdef JFFS2_DBG_NODEREF_MESSAGES
17384 + #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17385 + #else
17386 +-#define dbg_noderef(fmt, ...)
17387 ++#define dbg_noderef(fmt, ...) do {} while (0)
17388 + #endif
17389 +
17390 + /* Manipulations with the list of inodes (JFFS2 inocache) */
17391 + #ifdef JFFS2_DBG_INOCACHE_MESSAGES
17392 + #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17393 + #else
17394 +-#define dbg_inocache(fmt, ...)
17395 ++#define dbg_inocache(fmt, ...) do {} while (0)
17396 + #endif
17397 +
17398 + /* Summary debugging messages */
17399 + #ifdef JFFS2_DBG_SUMMARY_MESSAGES
17400 + #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17401 + #else
17402 +-#define dbg_summary(fmt, ...)
17403 ++#define dbg_summary(fmt, ...) do {} while (0)
17404 + #endif
17405 +
17406 + /* File system build messages */
17407 + #ifdef JFFS2_DBG_FSBUILD_MESSAGES
17408 + #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17409 + #else
17410 +-#define dbg_fsbuild(fmt, ...)
17411 ++#define dbg_fsbuild(fmt, ...) do {} while (0)
17412 + #endif
17413 +
17414 + /* Watch the object allocations */
17415 + #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
17416 + #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17417 + #else
17418 +-#define dbg_memalloc(fmt, ...)
17419 ++#define dbg_memalloc(fmt, ...) do {} while (0)
17420 + #endif
17421 +
17422 + /* Watch the XATTR subsystem */
17423 + #ifdef JFFS2_DBG_XATTR_MESSAGES
17424 + #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
17425 + #else
17426 +-#define dbg_xattr(fmt, ...)
17427 ++#define dbg_xattr(fmt, ...) do {} while (0)
17428 + #endif
17429 +
17430 + /* "Sanity" checks */
17431 +diff -urNp linux-2.6.27.10/fs/jffs2/erase.c linux-2.6.27.10/fs/jffs2/erase.c
17432 +--- linux-2.6.27.10/fs/jffs2/erase.c 2008-11-07 12:55:34.000000000 -0500
17433 ++++ linux-2.6.27.10/fs/jffs2/erase.c 2008-11-18 03:38:45.000000000 -0500
17434 +@@ -431,7 +431,8 @@ static void jffs2_mark_erased_block(stru
17435 + struct jffs2_unknown_node marker = {
17436 + .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
17437 + .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
17438 +- .totlen = cpu_to_je32(c->cleanmarker_size)
17439 ++ .totlen = cpu_to_je32(c->cleanmarker_size),
17440 ++ .hdr_crc = cpu_to_je32(0)
17441 + };
17442 +
17443 + jffs2_prealloc_raw_node_refs(c, jeb, 1);
17444 +diff -urNp linux-2.6.27.10/fs/jffs2/summary.h linux-2.6.27.10/fs/jffs2/summary.h
17445 +--- linux-2.6.27.10/fs/jffs2/summary.h 2008-11-07 12:55:34.000000000 -0500
17446 ++++ linux-2.6.27.10/fs/jffs2/summary.h 2008-11-18 03:38:45.000000000 -0500
17447 +@@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
17448 +
17449 + #define jffs2_sum_active() (0)
17450 + #define jffs2_sum_init(a) (0)
17451 +-#define jffs2_sum_exit(a)
17452 +-#define jffs2_sum_disable_collecting(a)
17453 ++#define jffs2_sum_exit(a) do {} while (0)
17454 ++#define jffs2_sum_disable_collecting(a) do {} while (0)
17455 + #define jffs2_sum_is_disabled(a) (0)
17456 +-#define jffs2_sum_reset_collected(a)
17457 ++#define jffs2_sum_reset_collected(a) do {} while (0)
17458 + #define jffs2_sum_add_kvec(a,b,c,d) (0)
17459 +-#define jffs2_sum_move_collected(a,b)
17460 ++#define jffs2_sum_move_collected(a,b) do {} while (0)
17461 + #define jffs2_sum_write_sumnode(a) (0)
17462 +-#define jffs2_sum_add_padding_mem(a,b)
17463 +-#define jffs2_sum_add_inode_mem(a,b,c)
17464 +-#define jffs2_sum_add_dirent_mem(a,b,c)
17465 +-#define jffs2_sum_add_xattr_mem(a,b,c)
17466 +-#define jffs2_sum_add_xref_mem(a,b,c)
17467 ++#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
17468 ++#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
17469 ++#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
17470 ++#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
17471 ++#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
17472 + #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
17473 +
17474 + #endif /* CONFIG_JFFS2_SUMMARY */
17475 +diff -urNp linux-2.6.27.10/fs/jffs2/wbuf.c linux-2.6.27.10/fs/jffs2/wbuf.c
17476 +--- linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-07 12:55:34.000000000 -0500
17477 ++++ linux-2.6.27.10/fs/jffs2/wbuf.c 2008-11-18 03:38:45.000000000 -0500
17478 +@@ -1015,7 +1015,8 @@ static const struct jffs2_unknown_node o
17479 + {
17480 + .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
17481 + .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
17482 +- .totlen = constant_cpu_to_je32(8)
17483 ++ .totlen = constant_cpu_to_je32(8),
17484 ++ .hdr_crc = constant_cpu_to_je32(0)
17485 + };
17486 +
17487 + /*
17488 +diff -urNp linux-2.6.27.10/fs/locks.c linux-2.6.27.10/fs/locks.c
17489 +--- linux-2.6.27.10/fs/locks.c 2008-11-07 12:55:34.000000000 -0500
17490 ++++ linux-2.6.27.10/fs/locks.c 2008-11-18 03:38:45.000000000 -0500
17491 +@@ -2005,16 +2005,16 @@ void locks_remove_flock(struct file *fil
17492 + return;
17493 +
17494 + if (filp->f_op && filp->f_op->flock) {
17495 +- struct file_lock fl = {
17496 ++ struct file_lock flock = {
17497 + .fl_pid = current->tgid,
17498 + .fl_file = filp,
17499 + .fl_flags = FL_FLOCK,
17500 + .fl_type = F_UNLCK,
17501 + .fl_end = OFFSET_MAX,
17502 + };
17503 +- filp->f_op->flock(filp, F_SETLKW, &fl);
17504 +- if (fl.fl_ops && fl.fl_ops->fl_release_private)
17505 +- fl.fl_ops->fl_release_private(&fl);
17506 ++ filp->f_op->flock(filp, F_SETLKW, &flock);
17507 ++ if (flock.fl_ops && flock.fl_ops->fl_release_private)
17508 ++ flock.fl_ops->fl_release_private(&flock);
17509 + }
17510 +
17511 + lock_kernel();
17512 +diff -urNp linux-2.6.27.10/fs/namei.c linux-2.6.27.10/fs/namei.c
17513 +--- linux-2.6.27.10/fs/namei.c 2008-11-07 12:55:34.000000000 -0500
17514 ++++ linux-2.6.27.10/fs/namei.c 2008-11-18 04:47:57.000000000 -0500
17515 +@@ -31,6 +31,8 @@
17516 + #include <linux/file.h>
17517 + #include <linux/fcntl.h>
17518 + #include <linux/device_cgroup.h>
17519 ++#include <linux/grsecurity.h>
17520 ++
17521 + #include <asm/uaccess.h>
17522 +
17523 + #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
17524 +@@ -646,7 +648,7 @@ static __always_inline int __do_follow_l
17525 + cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
17526 + error = PTR_ERR(cookie);
17527 + if (!IS_ERR(cookie)) {
17528 +- char *s = nd_get_link(nd);
17529 ++ const char *s = nd_get_link(nd);
17530 + error = 0;
17531 + if (s)
17532 + error = __vfs_follow_link(nd, s);
17533 +@@ -677,6 +679,13 @@ static inline int do_follow_link(struct
17534 + err = security_inode_follow_link(path->dentry, nd);
17535 + if (err)
17536 + goto loop;
17537 ++
17538 ++ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
17539 ++ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
17540 ++ err = -EACCES;
17541 ++ goto loop;
17542 ++ }
17543 ++
17544 + current->link_count++;
17545 + current->total_link_count++;
17546 + nd->depth++;
17547 +@@ -1025,11 +1034,18 @@ return_reval:
17548 + break;
17549 + }
17550 + return_base:
17551 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
17552 ++ path_put(&nd->path);
17553 ++ return -ENOENT;
17554 ++ }
17555 + return 0;
17556 + out_dput:
17557 + path_put_conditional(&next, nd);
17558 + break;
17559 + }
17560 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
17561 ++ err = -ENOENT;
17562 ++
17563 + path_put(&nd->path);
17564 + return_err:
17565 + return err;
17566 +@@ -1613,9 +1629,17 @@ static int __open_namei_create(struct na
17567 + int error;
17568 + struct dentry *dir = nd->path.dentry;
17569 +
17570 ++ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
17571 ++ error = -EACCES;
17572 ++ goto out_unlock_dput;
17573 ++ }
17574 ++
17575 + if (!IS_POSIXACL(dir->d_inode))
17576 + mode &= ~current->fs->umask;
17577 + error = vfs_create(dir->d_inode, path->dentry, mode, nd);
17578 ++ if (!error)
17579 ++ gr_handle_create(path->dentry, nd->path.mnt);
17580 ++out_unlock_dput:
17581 + mutex_unlock(&dir->d_inode->i_mutex);
17582 + dput(nd->path.dentry);
17583 + nd->path.dentry = path->dentry;
17584 +@@ -1696,6 +1720,17 @@ struct file *do_filp_open(int dfd, const
17585 + &nd, flag);
17586 + if (error)
17587 + return ERR_PTR(error);
17588 ++
17589 ++ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
17590 ++ error = -EPERM;
17591 ++ goto exit;
17592 ++ }
17593 ++
17594 ++ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
17595 ++ error = -EACCES;
17596 ++ goto exit;
17597 ++ }
17598 ++
17599 + goto ok;
17600 + }
17601 +
17602 +@@ -1759,6 +1794,20 @@ do_last:
17603 + /*
17604 + * It already exists.
17605 + */
17606 ++
17607 ++ if (gr_handle_rawio(path.dentry->d_inode)) {
17608 ++ error = -EPERM;
17609 ++ goto exit_mutex_unlock;
17610 ++ }
17611 ++ if (!gr_acl_handle_open(path.dentry, nd.path.mnt, flag)) {
17612 ++ error = -EACCES;
17613 ++ goto exit_mutex_unlock;
17614 ++ }
17615 ++ if (gr_handle_fifo(path.dentry, nd.path.mnt, dir, flag, acc_mode)) {
17616 ++ error = -EACCES;
17617 ++ goto exit_mutex_unlock;
17618 ++ }
17619 ++
17620 + mutex_unlock(&dir->d_inode->i_mutex);
17621 + audit_inode(pathname, path.dentry);
17622 +
17623 +@@ -1843,6 +1892,13 @@ do_link:
17624 + error = security_inode_follow_link(path.dentry, &nd);
17625 + if (error)
17626 + goto exit_dput;
17627 ++
17628 ++ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
17629 ++ path.dentry, nd.path.mnt)) {
17630 ++ error = -EACCES;
17631 ++ goto exit_dput;
17632 ++ }
17633 ++
17634 + error = __do_follow_link(&path, &nd);
17635 + if (error) {
17636 + /* Does someone understand code flow here? Or it is only
17637 +@@ -2015,9 +2071,21 @@ asmlinkage long sys_mknodat(int dfd, con
17638 + error = may_mknod(mode);
17639 + if (error)
17640 + goto out_dput;
17641 ++
17642 ++ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
17643 ++ error = -EPERM;
17644 ++ goto out_dput;
17645 ++ }
17646 ++
17647 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
17648 ++ error = -EACCES;
17649 ++ goto out_dput;
17650 ++ }
17651 ++
17652 + error = mnt_want_write(nd.path.mnt);
17653 + if (error)
17654 + goto out_dput;
17655 ++
17656 + switch (mode & S_IFMT) {
17657 + case 0: case S_IFREG:
17658 + error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
17659 +@@ -2031,6 +2099,9 @@ asmlinkage long sys_mknodat(int dfd, con
17660 + break;
17661 + }
17662 + mnt_drop_write(nd.path.mnt);
17663 ++
17664 ++ if (!error)
17665 ++ gr_handle_create(dentry, nd.path.mnt);
17666 + out_dput:
17667 + dput(dentry);
17668 + out_unlock:
17669 +@@ -2084,6 +2155,11 @@ asmlinkage long sys_mkdirat(int dfd, con
17670 + if (IS_ERR(dentry))
17671 + goto out_unlock;
17672 +
17673 ++ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
17674 ++ error = -EACCES;
17675 ++ goto out_dput;
17676 ++ }
17677 ++
17678 + if (!IS_POSIXACL(nd.path.dentry->d_inode))
17679 + mode &= ~current->fs->umask;
17680 + error = mnt_want_write(nd.path.mnt);
17681 +@@ -2091,6 +2167,10 @@ asmlinkage long sys_mkdirat(int dfd, con
17682 + goto out_dput;
17683 + error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
17684 + mnt_drop_write(nd.path.mnt);
17685 ++
17686 ++ if (!error)
17687 ++ gr_handle_create(dentry, nd.path.mnt);
17688 ++
17689 + out_dput:
17690 + dput(dentry);
17691 + out_unlock:
17692 +@@ -2172,6 +2252,8 @@ static long do_rmdir(int dfd, const char
17693 + char * name;
17694 + struct dentry *dentry;
17695 + struct nameidata nd;
17696 ++ ino_t saved_ino = 0;
17697 ++ dev_t saved_dev = 0;
17698 +
17699 + error = user_path_parent(dfd, pathname, &nd, &name);
17700 + if (error)
17701 +@@ -2193,11 +2275,26 @@ static long do_rmdir(int dfd, const char
17702 + error = PTR_ERR(dentry);
17703 + if (IS_ERR(dentry))
17704 + goto exit2;
17705 ++
17706 ++ if (dentry->d_inode != NULL) {
17707 ++ if (dentry->d_inode->i_nlink <= 1) {
17708 ++ saved_ino = dentry->d_inode->i_ino;
17709 ++ saved_dev = dentry->d_inode->i_sb->s_dev;
17710 ++ }
17711 ++
17712 ++ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
17713 ++ error = -EACCES;
17714 ++ goto exit3;
17715 ++ }
17716 ++ }
17717 ++
17718 + error = mnt_want_write(nd.path.mnt);
17719 + if (error)
17720 + goto exit3;
17721 + error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
17722 + mnt_drop_write(nd.path.mnt);
17723 ++ if (!error && (saved_dev || saved_ino))
17724 ++ gr_handle_delete(saved_ino, saved_dev);
17725 + exit3:
17726 + dput(dentry);
17727 + exit2:
17728 +@@ -2257,6 +2354,8 @@ static long do_unlinkat(int dfd, const c
17729 + struct dentry *dentry;
17730 + struct nameidata nd;
17731 + struct inode *inode = NULL;
17732 ++ ino_t saved_ino = 0;
17733 ++ dev_t saved_dev = 0;
17734 +
17735 + error = user_path_parent(dfd, pathname, &nd, &name);
17736 + if (error)
17737 +@@ -2273,12 +2372,25 @@ static long do_unlinkat(int dfd, const c
17738 + if (nd.last.name[nd.last.len])
17739 + goto slashes;
17740 + inode = dentry->d_inode;
17741 +- if (inode)
17742 ++ if (inode) {
17743 ++ if (inode->i_nlink <= 1) {
17744 ++ saved_ino = inode->i_ino;
17745 ++ saved_dev = inode->i_sb->s_dev;
17746 ++ }
17747 ++
17748 + atomic_inc(&inode->i_count);
17749 ++
17750 ++ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
17751 ++ error = -EACCES;
17752 ++ goto exit2;
17753 ++ }
17754 ++ }
17755 + error = mnt_want_write(nd.path.mnt);
17756 + if (error)
17757 + goto exit2;
17758 + error = vfs_unlink(nd.path.dentry->d_inode, dentry);
17759 ++ if (!error && (saved_ino || saved_dev))
17760 ++ gr_handle_delete(saved_ino, saved_dev);
17761 + mnt_drop_write(nd.path.mnt);
17762 + exit2:
17763 + dput(dentry);
17764 +@@ -2356,10 +2468,17 @@ asmlinkage long sys_symlinkat(const char
17765 + if (IS_ERR(dentry))
17766 + goto out_unlock;
17767 +
17768 ++ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
17769 ++ error = -EACCES;
17770 ++ goto out_dput;
17771 ++ }
17772 ++
17773 + error = mnt_want_write(nd.path.mnt);
17774 + if (error)
17775 + goto out_dput;
17776 + error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
17777 ++ if (!error)
17778 ++ gr_handle_create(dentry, nd.path.mnt);
17779 + mnt_drop_write(nd.path.mnt);
17780 + out_dput:
17781 + dput(dentry);
17782 +@@ -2453,10 +2572,26 @@ asmlinkage long sys_linkat(int olddfd, c
17783 + error = PTR_ERR(new_dentry);
17784 + if (IS_ERR(new_dentry))
17785 + goto out_unlock;
17786 ++
17787 ++ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
17788 ++ old_path.dentry->d_inode,
17789 ++ old_path.dentry->d_inode->i_mode, to)) {
17790 ++ error = -EACCES;
17791 ++ goto out_dput;
17792 ++ }
17793 ++
17794 ++ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
17795 ++ old_path.dentry, old_path.mnt, to)) {
17796 ++ error = -EACCES;
17797 ++ goto out_dput;
17798 ++ }
17799 ++
17800 + error = mnt_want_write(nd.path.mnt);
17801 + if (error)
17802 + goto out_dput;
17803 + error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
17804 ++ if (!error)
17805 ++ gr_handle_create(new_dentry, nd.path.mnt);
17806 + mnt_drop_write(nd.path.mnt);
17807 + out_dput:
17808 + dput(new_dentry);
17809 +@@ -2612,8 +2747,10 @@ int vfs_rename(struct inode *old_dir, st
17810 + error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
17811 + else
17812 + error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
17813 ++
17814 + if (!error) {
17815 + const char *new_name = old_dentry->d_name.name;
17816 ++
17817 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
17818 + new_dentry->d_inode, old_dentry);
17819 + }
17820 +@@ -2685,11 +2822,21 @@ asmlinkage long sys_renameat(int olddfd,
17821 + if (new_dentry == trap)
17822 + goto exit5;
17823 +
17824 ++ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
17825 ++ old_dentry, old_dir->d_inode, oldnd.path.mnt,
17826 ++ to);
17827 ++ if (error)
17828 ++ goto exit5;
17829 ++
17830 + error = mnt_want_write(oldnd.path.mnt);
17831 + if (error)
17832 + goto exit5;
17833 + error = vfs_rename(old_dir->d_inode, old_dentry,
17834 + new_dir->d_inode, new_dentry);
17835 ++ if (!error)
17836 ++ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
17837 ++ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
17838 ++
17839 + mnt_drop_write(oldnd.path.mnt);
17840 + exit5:
17841 + dput(new_dentry);
17842 +diff -urNp linux-2.6.27.10/fs/namespace.c linux-2.6.27.10/fs/namespace.c
17843 +--- linux-2.6.27.10/fs/namespace.c 2008-11-18 11:38:40.000000000 -0500
17844 ++++ linux-2.6.27.10/fs/namespace.c 2008-11-18 11:40:53.000000000 -0500
17845 +@@ -27,6 +27,7 @@
17846 + #include <linux/ramfs.h>
17847 + #include <linux/log2.h>
17848 + #include <linux/idr.h>
17849 ++#include <linux/grsecurity.h>
17850 + #include <asm/uaccess.h>
17851 + #include <asm/unistd.h>
17852 + #include "pnode.h"
17853 +@@ -1094,6 +1095,8 @@ static int do_umount(struct vfsmount *mn
17854 + lock_kernel();
17855 + retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
17856 + unlock_kernel();
17857 ++
17858 ++ gr_log_remount(mnt->mnt_devname, retval);
17859 + }
17860 + up_write(&sb->s_umount);
17861 + return retval;
17862 +@@ -1117,6 +1120,9 @@ static int do_umount(struct vfsmount *mn
17863 + security_sb_umount_busy(mnt);
17864 + up_write(&namespace_sem);
17865 + release_mounts(&umount_list);
17866 ++
17867 ++ gr_log_unmount(mnt->mnt_devname, retval);
17868 ++
17869 + return retval;
17870 + }
17871 +
17872 +@@ -1954,6 +1960,11 @@ long do_mount(char *dev_name, char *dir_
17873 + if (retval)
17874 + goto dput_out;
17875 +
17876 ++ if (gr_handle_chroot_mount(nd.path.dentry, nd.path.mnt, dev_name)) {
17877 ++ retval = -EPERM;
17878 ++ goto dput_out;
17879 ++ }
17880 ++
17881 + if (flags & MS_REMOUNT)
17882 + retval = do_remount(&nd, flags & ~MS_REMOUNT, mnt_flags,
17883 + data_page);
17884 +@@ -1968,6 +1979,9 @@ long do_mount(char *dev_name, char *dir_
17885 + dev_name, data_page);
17886 + dput_out:
17887 + path_put(&nd.path);
17888 ++
17889 ++ gr_log_mount(dev_name, dir_name, retval);
17890 ++
17891 + return retval;
17892 + }
17893 +
17894 +@@ -2080,6 +2094,9 @@ asmlinkage long sys_mount(char __user *
17895 + if (retval < 0)
17896 + goto out3;
17897 +
17898 ++ if (gr_handle_chroot_pivot())
17899 ++ return -EPERM;
17900 ++
17901 + lock_kernel();
17902 + retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
17903 + flags, (void *)data_page);
17904 +diff -urNp linux-2.6.27.10/fs/nfs/nfs4proc.c linux-2.6.27.10/fs/nfs/nfs4proc.c
17905 +--- linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-07 12:55:34.000000000 -0500
17906 ++++ linux-2.6.27.10/fs/nfs/nfs4proc.c 2008-11-18 03:38:45.000000000 -0500
17907 +@@ -653,7 +653,7 @@ static int _nfs4_do_open_reclaim(struct
17908 + static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
17909 + {
17910 + struct nfs_server *server = NFS_SERVER(state->inode);
17911 +- struct nfs4_exception exception = { };
17912 ++ struct nfs4_exception exception = {0, 0};
17913 + int err;
17914 + do {
17915 + err = _nfs4_do_open_reclaim(ctx, state);
17916 +@@ -695,7 +695,7 @@ static int _nfs4_open_delegation_recall(
17917 +
17918 + int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
17919 + {
17920 +- struct nfs4_exception exception = { };
17921 ++ struct nfs4_exception exception = {0, 0};
17922 + struct nfs_server *server = NFS_SERVER(state->inode);
17923 + int err;
17924 + do {
17925 +@@ -988,7 +988,7 @@ static int _nfs4_open_expired(struct nfs
17926 + static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
17927 + {
17928 + struct nfs_server *server = NFS_SERVER(state->inode);
17929 +- struct nfs4_exception exception = { };
17930 ++ struct nfs4_exception exception = {0, 0};
17931 + int err;
17932 +
17933 + do {
17934 +@@ -1090,7 +1090,7 @@ out_err:
17935 +
17936 + static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, int flags, struct iattr *sattr, struct rpc_cred *cred)
17937 + {
17938 +- struct nfs4_exception exception = { };
17939 ++ struct nfs4_exception exception = {0, 0};
17940 + struct nfs4_state *res;
17941 + int status;
17942 +
17943 +@@ -1181,7 +1181,7 @@ static int nfs4_do_setattr(struct inode
17944 + struct nfs4_state *state)
17945 + {
17946 + struct nfs_server *server = NFS_SERVER(inode);
17947 +- struct nfs4_exception exception = { };
17948 ++ struct nfs4_exception exception = {0, 0};
17949 + int err;
17950 + do {
17951 + err = nfs4_handle_exception(server,
17952 +@@ -1494,7 +1494,7 @@ static int _nfs4_server_capabilities(str
17953 +
17954 + int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
17955 + {
17956 +- struct nfs4_exception exception = { };
17957 ++ struct nfs4_exception exception = {0, 0};
17958 + int err;
17959 + do {
17960 + err = nfs4_handle_exception(server,
17961 +@@ -1527,7 +1527,7 @@ static int _nfs4_lookup_root(struct nfs_
17962 + static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
17963 + struct nfs_fsinfo *info)
17964 + {
17965 +- struct nfs4_exception exception = { };
17966 ++ struct nfs4_exception exception = {0, 0};
17967 + int err;
17968 + do {
17969 + err = nfs4_handle_exception(server,
17970 +@@ -1616,7 +1616,7 @@ static int _nfs4_proc_getattr(struct nfs
17971 +
17972 + static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
17973 + {
17974 +- struct nfs4_exception exception = { };
17975 ++ struct nfs4_exception exception = {0, 0};
17976 + int err;
17977 + do {
17978 + err = nfs4_handle_exception(server,
17979 +@@ -1702,7 +1702,7 @@ static int nfs4_proc_lookupfh(struct nfs
17980 + struct qstr *name, struct nfs_fh *fhandle,
17981 + struct nfs_fattr *fattr)
17982 + {
17983 +- struct nfs4_exception exception = { };
17984 ++ struct nfs4_exception exception = {0, 0};
17985 + int err;
17986 + do {
17987 + err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
17988 +@@ -1731,7 +1731,7 @@ static int _nfs4_proc_lookup(struct inod
17989 +
17990 + static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
17991 + {
17992 +- struct nfs4_exception exception = { };
17993 ++ struct nfs4_exception exception = {0, 0};
17994 + int err;
17995 + do {
17996 + err = nfs4_handle_exception(NFS_SERVER(dir),
17997 +@@ -1795,7 +1795,7 @@ static int _nfs4_proc_access(struct inod
17998 +
17999 + static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
18000 + {
18001 +- struct nfs4_exception exception = { };
18002 ++ struct nfs4_exception exception = {0, 0};
18003 + int err;
18004 + do {
18005 + err = nfs4_handle_exception(NFS_SERVER(inode),
18006 +@@ -1850,7 +1850,7 @@ static int _nfs4_proc_readlink(struct in
18007 + static int nfs4_proc_readlink(struct inode *inode, struct page *page,
18008 + unsigned int pgbase, unsigned int pglen)
18009 + {
18010 +- struct nfs4_exception exception = { };
18011 ++ struct nfs4_exception exception = {0, 0};
18012 + int err;
18013 + do {
18014 + err = nfs4_handle_exception(NFS_SERVER(inode),
18015 +@@ -1947,7 +1947,7 @@ static int _nfs4_proc_remove(struct inod
18016 +
18017 + static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
18018 + {
18019 +- struct nfs4_exception exception = { };
18020 ++ struct nfs4_exception exception = {0, 0};
18021 + int err;
18022 + do {
18023 + err = nfs4_handle_exception(NFS_SERVER(dir),
18024 +@@ -2019,7 +2019,7 @@ static int _nfs4_proc_rename(struct inod
18025 + static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
18026 + struct inode *new_dir, struct qstr *new_name)
18027 + {
18028 +- struct nfs4_exception exception = { };
18029 ++ struct nfs4_exception exception = {0, 0};
18030 + int err;
18031 + do {
18032 + err = nfs4_handle_exception(NFS_SERVER(old_dir),
18033 +@@ -2066,7 +2066,7 @@ static int _nfs4_proc_link(struct inode
18034 +
18035 + static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
18036 + {
18037 +- struct nfs4_exception exception = { };
18038 ++ struct nfs4_exception exception = {0, 0};
18039 + int err;
18040 + do {
18041 + err = nfs4_handle_exception(NFS_SERVER(inode),
18042 +@@ -2157,7 +2157,7 @@ out:
18043 + static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
18044 + struct page *page, unsigned int len, struct iattr *sattr)
18045 + {
18046 +- struct nfs4_exception exception = { };
18047 ++ struct nfs4_exception exception = {0, 0};
18048 + int err;
18049 + do {
18050 + err = nfs4_handle_exception(NFS_SERVER(dir),
18051 +@@ -2188,7 +2188,7 @@ out:
18052 + static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
18053 + struct iattr *sattr)
18054 + {
18055 +- struct nfs4_exception exception = { };
18056 ++ struct nfs4_exception exception = {0, 0};
18057 + int err;
18058 + do {
18059 + err = nfs4_handle_exception(NFS_SERVER(dir),
18060 +@@ -2237,7 +2237,7 @@ static int _nfs4_proc_readdir(struct den
18061 + static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
18062 + u64 cookie, struct page *page, unsigned int count, int plus)
18063 + {
18064 +- struct nfs4_exception exception = { };
18065 ++ struct nfs4_exception exception = {0, 0};
18066 + int err;
18067 + do {
18068 + err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
18069 +@@ -2285,7 +2285,7 @@ out:
18070 + static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
18071 + struct iattr *sattr, dev_t rdev)
18072 + {
18073 +- struct nfs4_exception exception = { };
18074 ++ struct nfs4_exception exception = {0, 0};
18075 + int err;
18076 + do {
18077 + err = nfs4_handle_exception(NFS_SERVER(dir),
18078 +@@ -2314,7 +2314,7 @@ static int _nfs4_proc_statfs(struct nfs_
18079 +
18080 + static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
18081 + {
18082 +- struct nfs4_exception exception = { };
18083 ++ struct nfs4_exception exception = {0, 0};
18084 + int err;
18085 + do {
18086 + err = nfs4_handle_exception(server,
18087 +@@ -2342,7 +2342,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
18088 +
18089 + static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
18090 + {
18091 +- struct nfs4_exception exception = { };
18092 ++ struct nfs4_exception exception = {0, 0};
18093 + int err;
18094 +
18095 + do {
18096 +@@ -2385,7 +2385,7 @@ static int _nfs4_proc_pathconf(struct nf
18097 + static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
18098 + struct nfs_pathconf *pathconf)
18099 + {
18100 +- struct nfs4_exception exception = { };
18101 ++ struct nfs4_exception exception = {0, 0};
18102 + int err;
18103 +
18104 + do {
18105 +@@ -2672,7 +2672,7 @@ out_free:
18106 +
18107 + static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
18108 + {
18109 +- struct nfs4_exception exception = { };
18110 ++ struct nfs4_exception exception = {0, 0};
18111 + ssize_t ret;
18112 + do {
18113 + ret = __nfs4_get_acl_uncached(inode, buf, buflen);
18114 +@@ -2729,7 +2729,7 @@ static int __nfs4_proc_set_acl(struct in
18115 +
18116 + static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
18117 + {
18118 +- struct nfs4_exception exception = { };
18119 ++ struct nfs4_exception exception = {0, 0};
18120 + int err;
18121 + do {
18122 + err = nfs4_handle_exception(NFS_SERVER(inode),
18123 +@@ -3020,7 +3020,7 @@ out:
18124 + int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
18125 + {
18126 + struct nfs_server *server = NFS_SERVER(inode);
18127 +- struct nfs4_exception exception = { };
18128 ++ struct nfs4_exception exception = {0, 0};
18129 + int err;
18130 + do {
18131 + err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
18132 +@@ -3095,7 +3095,7 @@ out:
18133 +
18134 + static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
18135 + {
18136 +- struct nfs4_exception exception = { };
18137 ++ struct nfs4_exception exception = {0, 0};
18138 + int err;
18139 +
18140 + do {
18141 +@@ -3445,7 +3445,7 @@ static int _nfs4_do_setlk(struct nfs4_st
18142 + static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
18143 + {
18144 + struct nfs_server *server = NFS_SERVER(state->inode);
18145 +- struct nfs4_exception exception = { };
18146 ++ struct nfs4_exception exception = {0, 0};
18147 + int err;
18148 +
18149 + do {
18150 +@@ -3463,7 +3463,7 @@ static int nfs4_lock_reclaim(struct nfs4
18151 + static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
18152 + {
18153 + struct nfs_server *server = NFS_SERVER(state->inode);
18154 +- struct nfs4_exception exception = { };
18155 ++ struct nfs4_exception exception = {0, 0};
18156 + int err;
18157 +
18158 + err = nfs4_set_lock_state(state, request);
18159 +@@ -3524,7 +3524,7 @@ out:
18160 +
18161 + static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
18162 + {
18163 +- struct nfs4_exception exception = { };
18164 ++ struct nfs4_exception exception = {0, 0};
18165 + int err;
18166 +
18167 + do {
18168 +@@ -3574,7 +3574,7 @@ nfs4_proc_lock(struct file *filp, int cm
18169 + int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
18170 + {
18171 + struct nfs_server *server = NFS_SERVER(state->inode);
18172 +- struct nfs4_exception exception = { };
18173 ++ struct nfs4_exception exception = {0, 0};
18174 + int err;
18175 +
18176 + err = nfs4_set_lock_state(state, fl);
18177 +diff -urNp linux-2.6.27.10/fs/nfsd/export.c linux-2.6.27.10/fs/nfsd/export.c
18178 +--- linux-2.6.27.10/fs/nfsd/export.c 2008-11-07 12:55:34.000000000 -0500
18179 ++++ linux-2.6.27.10/fs/nfsd/export.c 2008-11-18 03:38:45.000000000 -0500
18180 +@@ -473,7 +473,7 @@ static int secinfo_parse(char **mesg, ch
18181 + * probably discover the problem when someone fails to
18182 + * authenticate.
18183 + */
18184 +- if (f->pseudoflavor < 0)
18185 ++ if ((s32)f->pseudoflavor < 0)
18186 + return -EINVAL;
18187 + err = get_int(mesg, &f->flags);
18188 + if (err)
18189 +diff -urNp linux-2.6.27.10/fs/nls/nls_base.c linux-2.6.27.10/fs/nls/nls_base.c
18190 +--- linux-2.6.27.10/fs/nls/nls_base.c 2008-11-07 12:55:34.000000000 -0500
18191 ++++ linux-2.6.27.10/fs/nls/nls_base.c 2008-11-18 03:38:45.000000000 -0500
18192 +@@ -42,7 +42,7 @@ static const struct utf8_table utf8_tabl
18193 + {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
18194 + {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
18195 + {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
18196 +- {0, /* end of table */}
18197 ++ {0, 0, 0, 0, 0, /* end of table */}
18198 + };
18199 +
18200 + int
18201 +diff -urNp linux-2.6.27.10/fs/ntfs/file.c linux-2.6.27.10/fs/ntfs/file.c
18202 +--- linux-2.6.27.10/fs/ntfs/file.c 2008-11-07 12:55:34.000000000 -0500
18203 ++++ linux-2.6.27.10/fs/ntfs/file.c 2008-11-18 03:38:45.000000000 -0500
18204 +@@ -2291,6 +2291,6 @@ const struct inode_operations ntfs_file_
18205 + #endif /* NTFS_RW */
18206 + };
18207 +
18208 +-const struct file_operations ntfs_empty_file_ops = {};
18209 ++const struct file_operations ntfs_empty_file_ops;
18210 +
18211 +-const struct inode_operations ntfs_empty_inode_ops = {};
18212 ++const struct inode_operations ntfs_empty_inode_ops;
18213 +diff -urNp linux-2.6.27.10/fs/open.c linux-2.6.27.10/fs/open.c
18214 +--- linux-2.6.27.10/fs/open.c 2008-11-07 12:55:34.000000000 -0500
18215 ++++ linux-2.6.27.10/fs/open.c 2008-11-18 03:38:45.000000000 -0500
18216 +@@ -29,6 +29,7 @@
18217 + #include <linux/rcupdate.h>
18218 + #include <linux/audit.h>
18219 + #include <linux/falloc.h>
18220 ++#include <linux/grsecurity.h>
18221 +
18222 + int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
18223 + {
18224 +@@ -207,6 +208,9 @@ int do_truncate(struct dentry *dentry, l
18225 + if (length < 0)
18226 + return -EINVAL;
18227 +
18228 ++ if (filp && !gr_acl_handle_truncate(dentry, filp->f_path.mnt))
18229 ++ return -EACCES;
18230 ++
18231 + newattrs.ia_size = length;
18232 + newattrs.ia_valid = ATTR_SIZE | time_attrs;
18233 + if (filp) {
18234 +@@ -491,6 +495,9 @@ asmlinkage long sys_faccessat(int dfd, c
18235 + if (__mnt_is_readonly(path.mnt))
18236 + res = -EROFS;
18237 +
18238 ++ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
18239 ++ res = -EACCES;
18240 ++
18241 + out_path_release:
18242 + path_put(&path);
18243 + out:
18244 +@@ -521,6 +528,8 @@ asmlinkage long sys_chdir(const char __u
18245 + if (error)
18246 + goto dput_and_out;
18247 +
18248 ++ gr_log_chdir(path.dentry, path.mnt);
18249 ++
18250 + set_fs_pwd(current->fs, &path);
18251 +
18252 + dput_and_out:
18253 +@@ -547,6 +556,13 @@ asmlinkage long sys_fchdir(unsigned int
18254 + goto out_putf;
18255 +
18256 + error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
18257 ++
18258 ++ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
18259 ++ error = -EPERM;
18260 ++
18261 ++ if (!error)
18262 ++ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
18263 ++
18264 + if (!error)
18265 + set_fs_pwd(current->fs, &file->f_path);
18266 + out_putf:
18267 +@@ -572,7 +588,14 @@ asmlinkage long sys_chroot(const char __
18268 + if (!capable(CAP_SYS_CHROOT))
18269 + goto dput_and_out;
18270 +
18271 ++ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
18272 ++ goto dput_and_out;
18273 ++
18274 + set_fs_root(current->fs, &path);
18275 ++
18276 ++ gr_handle_chroot_caps(current);
18277 ++ gr_handle_chroot_chdir(&path);
18278 ++
18279 + error = 0;
18280 + dput_and_out:
18281 + path_put(&path);
18282 +@@ -600,13 +623,28 @@ asmlinkage long sys_fchmod(unsigned int
18283 + err = mnt_want_write(file->f_path.mnt);
18284 + if (err)
18285 + goto out_putf;
18286 ++
18287 ++ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
18288 ++ err = -EACCES;
18289 ++ goto out_drop_write;
18290 ++ }
18291 ++
18292 + mutex_lock(&inode->i_mutex);
18293 + if (mode == (mode_t) -1)
18294 + mode = inode->i_mode;
18295 ++
18296 ++ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
18297 ++ err = -EPERM;
18298 ++ mutex_unlock(&inode->i_mutex);
18299 ++ goto out_drop_write;
18300 ++ }
18301 ++
18302 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
18303 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
18304 + err = notify_change(dentry, &newattrs);
18305 + mutex_unlock(&inode->i_mutex);
18306 ++
18307 ++out_drop_write:
18308 + mnt_drop_write(file->f_path.mnt);
18309 + out_putf:
18310 + fput(file);
18311 +@@ -630,13 +668,28 @@ asmlinkage long sys_fchmodat(int dfd, co
18312 + error = mnt_want_write(path.mnt);
18313 + if (error)
18314 + goto dput_and_out;
18315 ++
18316 ++ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
18317 ++ error = -EACCES;
18318 ++ goto out_drop_write;
18319 ++ }
18320 ++
18321 + mutex_lock(&inode->i_mutex);
18322 + if (mode == (mode_t) -1)
18323 + mode = inode->i_mode;
18324 ++
18325 ++ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
18326 ++ error = -EACCES;
18327 ++ mutex_unlock(&inode->i_mutex);
18328 ++ goto out_drop_write;
18329 ++ }
18330 ++
18331 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
18332 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
18333 + error = notify_change(path.dentry, &newattrs);
18334 + mutex_unlock(&inode->i_mutex);
18335 ++
18336 ++out_drop_write:
18337 + mnt_drop_write(path.mnt);
18338 + dput_and_out:
18339 + path_put(&path);
18340 +@@ -649,12 +702,15 @@ asmlinkage long sys_chmod(const char __u
18341 + return sys_fchmodat(AT_FDCWD, filename, mode);
18342 + }
18343 +
18344 +-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
18345 ++static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
18346 + {
18347 + struct inode *inode = dentry->d_inode;
18348 + int error;
18349 + struct iattr newattrs;
18350 +
18351 ++ if (!gr_acl_handle_chown(dentry, mnt))
18352 ++ return -EACCES;
18353 ++
18354 + newattrs.ia_valid = ATTR_CTIME;
18355 + if (user != (uid_t) -1) {
18356 + newattrs.ia_valid |= ATTR_UID;
18357 +@@ -685,7 +741,7 @@ asmlinkage long sys_chown(const char __u
18358 + error = mnt_want_write(path.mnt);
18359 + if (error)
18360 + goto out_release;
18361 +- error = chown_common(path.dentry, user, group);
18362 ++ error = chown_common(path.dentry, user, group, path.mnt);
18363 + mnt_drop_write(path.mnt);
18364 + out_release:
18365 + path_put(&path);
18366 +@@ -710,7 +766,7 @@ asmlinkage long sys_fchownat(int dfd, co
18367 + error = mnt_want_write(path.mnt);
18368 + if (error)
18369 + goto out_release;
18370 +- error = chown_common(path.dentry, user, group);
18371 ++ error = chown_common(path.dentry, user, group, path.mnt);
18372 + mnt_drop_write(path.mnt);
18373 + out_release:
18374 + path_put(&path);
18375 +@@ -729,7 +785,7 @@ asmlinkage long sys_lchown(const char __
18376 + error = mnt_want_write(path.mnt);
18377 + if (error)
18378 + goto out_release;
18379 +- error = chown_common(path.dentry, user, group);
18380 ++ error = chown_common(path.dentry, user, group, path.mnt);
18381 + mnt_drop_write(path.mnt);
18382 + out_release:
18383 + path_put(&path);
18384 +@@ -753,7 +809,7 @@ asmlinkage long sys_fchown(unsigned int
18385 + goto out_fput;
18386 + dentry = file->f_path.dentry;
18387 + audit_inode(NULL, dentry);
18388 +- error = chown_common(dentry, user, group);
18389 ++ error = chown_common(dentry, user, group, file->f_path.mnt);
18390 + mnt_drop_write(file->f_path.mnt);
18391 + out_fput:
18392 + fput(file);
18393 +diff -urNp linux-2.6.27.10/fs/pipe.c linux-2.6.27.10/fs/pipe.c
18394 +--- linux-2.6.27.10/fs/pipe.c 2008-11-07 12:55:34.000000000 -0500
18395 ++++ linux-2.6.27.10/fs/pipe.c 2008-11-18 03:38:45.000000000 -0500
18396 +@@ -851,7 +851,7 @@ void free_pipe_info(struct inode *inode)
18397 + inode->i_pipe = NULL;
18398 + }
18399 +
18400 +-static struct vfsmount *pipe_mnt __read_mostly;
18401 ++struct vfsmount *pipe_mnt __read_mostly;
18402 + static int pipefs_delete_dentry(struct dentry *dentry)
18403 + {
18404 + /*
18405 +diff -urNp linux-2.6.27.10/fs/proc/array.c linux-2.6.27.10/fs/proc/array.c
18406 +--- linux-2.6.27.10/fs/proc/array.c 2008-11-07 12:55:34.000000000 -0500
18407 ++++ linux-2.6.27.10/fs/proc/array.c 2008-11-18 03:38:45.000000000 -0500
18408 +@@ -315,6 +315,21 @@ static inline void task_context_switch_c
18409 + p->nivcsw);
18410 + }
18411 +
18412 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
18413 ++static inline void task_pax(struct seq_file *m, struct task_struct *p)
18414 ++{
18415 ++ if (p->mm)
18416 ++ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
18417 ++ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
18418 ++ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
18419 ++ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
18420 ++ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
18421 ++ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
18422 ++ else
18423 ++ seq_printf(m, "PaX:\t-----\n");
18424 ++}
18425 ++#endif
18426 ++
18427 + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
18428 + struct pid *pid, struct task_struct *task)
18429 + {
18430 +@@ -334,9 +349,20 @@ int proc_pid_status(struct seq_file *m,
18431 + task_show_regs(m, task);
18432 + #endif
18433 + task_context_switch_counts(m, task);
18434 ++
18435 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
18436 ++ task_pax(m, task);
18437 ++#endif
18438 ++
18439 + return 0;
18440 + }
18441 +
18442 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
18443 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
18444 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
18445 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
18446 ++#endif
18447 ++
18448 + static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
18449 + struct pid *pid, struct task_struct *task, int whole)
18450 + {
18451 +@@ -429,6 +455,19 @@ static int do_task_stat(struct seq_file
18452 + gtime = task_gtime(task);
18453 + }
18454 +
18455 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
18456 ++ if (PAX_RAND_FLAGS(mm)) {
18457 ++ eip = 0;
18458 ++ esp = 0;
18459 ++ wchan = 0;
18460 ++ }
18461 ++#endif
18462 ++#ifdef CONFIG_GRKERNSEC_HIDESYM
18463 ++ wchan = 0;
18464 ++ eip =0;
18465 ++ esp =0;
18466 ++#endif
18467 ++
18468 + /* scale priority and nice values from timeslices to -20..20 */
18469 + /* to make it look like a "normal" Unix priority/nice value */
18470 + priority = task_prio(task);
18471 +@@ -469,9 +508,15 @@ static int do_task_stat(struct seq_file
18472 + vsize,
18473 + mm ? get_mm_rss(mm) : 0,
18474 + rsslim,
18475 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
18476 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
18477 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
18478 ++ PAX_RAND_FLAGS(mm) ? 0 : (mm ? mm->start_stack : 0),
18479 ++#else
18480 + mm ? mm->start_code : 0,
18481 + mm ? mm->end_code : 0,
18482 + mm ? mm->start_stack : 0,
18483 ++#endif
18484 + esp,
18485 + eip,
18486 + /* The signal information here is obsolete.
18487 +@@ -524,3 +569,10 @@ int proc_pid_statm(struct seq_file *m, s
18488 +
18489 + return 0;
18490 + }
18491 ++
18492 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
18493 ++int proc_pid_ipaddr(struct task_struct *task, char *buffer)
18494 ++{
18495 ++ return sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip));
18496 ++}
18497 ++#endif
18498 +diff -urNp linux-2.6.27.10/fs/proc/base.c linux-2.6.27.10/fs/proc/base.c
18499 +--- linux-2.6.27.10/fs/proc/base.c 2008-11-07 12:55:34.000000000 -0500
18500 ++++ linux-2.6.27.10/fs/proc/base.c 2008-11-18 03:38:45.000000000 -0500
18501 +@@ -79,6 +79,8 @@
18502 + #include <linux/oom.h>
18503 + #include <linux/elf.h>
18504 + #include <linux/pid_namespace.h>
18505 ++#include <linux/grsecurity.h>
18506 ++
18507 + #include "internal.h"
18508 +
18509 + /* NOTE:
18510 +@@ -148,7 +150,7 @@ static unsigned int pid_entry_count_dirs
18511 + return count;
18512 + }
18513 +
18514 +-int maps_protect;
18515 ++int maps_protect = 1;
18516 + EXPORT_SYMBOL(maps_protect);
18517 +
18518 + static struct fs_struct *get_fs_struct(struct task_struct *task)
18519 +@@ -229,6 +231,9 @@ static int check_mem_permission(struct t
18520 + if (task == current)
18521 + return 0;
18522 +
18523 ++ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
18524 ++ return -EPERM;
18525 ++
18526 + /*
18527 + * If current is actively ptrace'ing, and would also be
18528 + * permitted to freshly attach with ptrace now, permit it.
18529 +@@ -312,9 +317,9 @@ static int proc_pid_auxv(struct task_str
18530 + struct mm_struct *mm = get_task_mm(task);
18531 + if (mm) {
18532 + unsigned int nwords = 0;
18533 +- do
18534 ++ do {
18535 + nwords += 2;
18536 +- while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
18537 ++ } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
18538 + res = nwords * sizeof(mm->saved_auxv[0]);
18539 + if (res > PAGE_SIZE)
18540 + res = PAGE_SIZE;
18541 +@@ -1437,7 +1442,11 @@ static struct inode *proc_pid_make_inode
18542 + inode->i_gid = 0;
18543 + if (task_dumpable(task)) {
18544 + inode->i_uid = task->euid;
18545 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
18546 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
18547 ++#else
18548 + inode->i_gid = task->egid;
18549 ++#endif
18550 + }
18551 + security_task_to_inode(task, inode);
18552 +
18553 +@@ -1453,17 +1462,45 @@ static int pid_getattr(struct vfsmount *
18554 + {
18555 + struct inode *inode = dentry->d_inode;
18556 + struct task_struct *task;
18557 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18558 ++ struct task_struct *tmp = current;
18559 ++#endif
18560 ++
18561 + generic_fillattr(inode, stat);
18562 +
18563 + rcu_read_lock();
18564 + stat->uid = 0;
18565 + stat->gid = 0;
18566 + task = pid_task(proc_pid(inode), PIDTYPE_PID);
18567 +- if (task) {
18568 ++
18569 ++ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
18570 ++ rcu_read_unlock();
18571 ++ return -ENOENT;
18572 ++ }
18573 ++
18574 ++
18575 ++ if (task
18576 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18577 ++ && (!tmp->uid || (tmp->uid == task->uid)
18578 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
18579 ++ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
18580 ++#endif
18581 ++ )
18582 ++#endif
18583 ++ ) {
18584 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
18585 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
18586 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
18587 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18588 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
18589 ++#endif
18590 + task_dumpable(task)) {
18591 + stat->uid = task->euid;
18592 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
18593 ++ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
18594 ++#else
18595 + stat->gid = task->egid;
18596 ++#endif
18597 + }
18598 + }
18599 + rcu_read_unlock();
18600 +@@ -1491,11 +1528,21 @@ static int pid_revalidate(struct dentry
18601 + {
18602 + struct inode *inode = dentry->d_inode;
18603 + struct task_struct *task = get_proc_task(inode);
18604 ++
18605 + if (task) {
18606 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
18607 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
18608 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
18609 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18610 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
18611 ++#endif
18612 + task_dumpable(task)) {
18613 + inode->i_uid = task->euid;
18614 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
18615 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
18616 ++#else
18617 + inode->i_gid = task->egid;
18618 ++#endif
18619 + } else {
18620 + inode->i_uid = 0;
18621 + inode->i_gid = 0;
18622 +@@ -1863,12 +1910,22 @@ static const struct file_operations proc
18623 + static int proc_fd_permission(struct inode *inode, int mask)
18624 + {
18625 + int rv;
18626 ++ struct task_struct *task;
18627 +
18628 + rv = generic_permission(inode, mask, NULL);
18629 +- if (rv == 0)
18630 +- return 0;
18631 ++
18632 + if (task_pid(current) == proc_pid(inode))
18633 + rv = 0;
18634 ++
18635 ++ task = get_proc_task(inode);
18636 ++ if (task == NULL)
18637 ++ return rv;
18638 ++
18639 ++ if (gr_acl_handle_procpidmem(task))
18640 ++ rv = -EACCES;
18641 ++
18642 ++ put_task_struct(task);
18643 ++
18644 + return rv;
18645 + }
18646 +
18647 +@@ -1979,6 +2036,9 @@ static struct dentry *proc_pident_lookup
18648 + if (!task)
18649 + goto out_no_task;
18650 +
18651 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
18652 ++ goto out;
18653 ++
18654 + /*
18655 + * Yes, it does not scale. And it should not. Don't add
18656 + * new entries into /proc/<tgid>/ without very good reasons.
18657 +@@ -2023,6 +2083,9 @@ static int proc_pident_readdir(struct fi
18658 + if (!task)
18659 + goto out_no_task;
18660 +
18661 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
18662 ++ goto out;
18663 ++
18664 + ret = 0;
18665 + i = filp->f_pos;
18666 + switch (i) {
18667 +@@ -2385,6 +2448,9 @@ static struct dentry *proc_base_lookup(s
18668 + if (p > last)
18669 + goto out;
18670 +
18671 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
18672 ++ goto out;
18673 ++
18674 + error = proc_base_instantiate(dir, dentry, task, p);
18675 +
18676 + out:
18677 +@@ -2518,6 +2584,9 @@ static const struct pid_entry tgid_base_
18678 + #ifdef CONFIG_TASK_IO_ACCOUNTING
18679 + INF("io", S_IRUGO, tgid_io_accounting),
18680 + #endif
18681 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
18682 ++ INF("ipaddr", S_IRUSR, pid_ipaddr),
18683 ++#endif
18684 + };
18685 +
18686 + static int proc_tgid_base_readdir(struct file * filp,
18687 +@@ -2647,7 +2716,14 @@ static struct dentry *proc_pid_instantia
18688 + if (!inode)
18689 + goto out;
18690 +
18691 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
18692 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
18693 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18694 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
18695 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
18696 ++#else
18697 + inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
18698 ++#endif
18699 + inode->i_op = &proc_tgid_base_inode_operations;
18700 + inode->i_fop = &proc_tgid_base_operations;
18701 + inode->i_flags|=S_IMMUTABLE;
18702 +@@ -2689,7 +2765,11 @@ struct dentry *proc_pid_lookup(struct in
18703 + if (!task)
18704 + goto out;
18705 +
18706 ++ if (gr_check_hidden_task(task))
18707 ++ goto out_put_task;
18708 ++
18709 + result = proc_pid_instantiate(dir, dentry, task, NULL);
18710 ++out_put_task:
18711 + put_task_struct(task);
18712 + out:
18713 + return result;
18714 +@@ -2754,6 +2834,9 @@ int proc_pid_readdir(struct file * filp,
18715 + {
18716 + unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
18717 + struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
18718 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18719 ++ struct task_struct *tmp = current;
18720 ++#endif
18721 + struct tgid_iter iter;
18722 + struct pid_namespace *ns;
18723 +
18724 +@@ -2772,6 +2855,17 @@ int proc_pid_readdir(struct file * filp,
18725 + for (iter = next_tgid(ns, iter);
18726 + iter.task;
18727 + iter.tgid += 1, iter = next_tgid(ns, iter)) {
18728 ++ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
18729 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18730 ++ || (tmp->uid && (iter.task->uid != tmp->uid)
18731 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
18732 ++ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
18733 ++#endif
18734 ++ )
18735 ++#endif
18736 ++ )
18737 ++ continue;
18738 ++
18739 + filp->f_pos = iter.tgid + TGID_OFFSET;
18740 + if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
18741 + put_task_struct(iter.task);
18742 +diff -urNp linux-2.6.27.10/fs/proc/inode.c linux-2.6.27.10/fs/proc/inode.c
18743 +--- linux-2.6.27.10/fs/proc/inode.c 2008-11-07 12:55:34.000000000 -0500
18744 ++++ linux-2.6.27.10/fs/proc/inode.c 2008-11-18 03:38:45.000000000 -0500
18745 +@@ -467,7 +467,11 @@ struct inode *proc_get_inode(struct supe
18746 + if (de->mode) {
18747 + inode->i_mode = de->mode;
18748 + inode->i_uid = de->uid;
18749 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
18750 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
18751 ++#else
18752 + inode->i_gid = de->gid;
18753 ++#endif
18754 + }
18755 + if (de->size)
18756 + inode->i_size = de->size;
18757 +diff -urNp linux-2.6.27.10/fs/proc/internal.h linux-2.6.27.10/fs/proc/internal.h
18758 +--- linux-2.6.27.10/fs/proc/internal.h 2008-11-07 12:55:34.000000000 -0500
18759 ++++ linux-2.6.27.10/fs/proc/internal.h 2008-11-18 03:38:45.000000000 -0500
18760 +@@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_fi
18761 + struct pid *pid, struct task_struct *task);
18762 + extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
18763 + struct pid *pid, struct task_struct *task);
18764 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
18765 ++extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
18766 ++#endif
18767 + extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
18768 +
18769 + extern const struct file_operations proc_maps_operations;
18770 +diff -urNp linux-2.6.27.10/fs/proc/Kconfig linux-2.6.27.10/fs/proc/Kconfig
18771 +--- linux-2.6.27.10/fs/proc/Kconfig 2008-11-07 12:55:34.000000000 -0500
18772 ++++ linux-2.6.27.10/fs/proc/Kconfig 2008-11-18 03:38:45.000000000 -0500
18773 +@@ -30,12 +30,12 @@ config PROC_FS
18774 +
18775 + config PROC_KCORE
18776 + bool "/proc/kcore support" if !ARM
18777 +- depends on PROC_FS && MMU
18778 ++ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
18779 +
18780 + config PROC_VMCORE
18781 + bool "/proc/vmcore support (EXPERIMENTAL)"
18782 +- depends on PROC_FS && CRASH_DUMP
18783 +- default y
18784 ++ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
18785 ++ default n
18786 + help
18787 + Exports the dump image of crashed kernel in ELF format.
18788 +
18789 +diff -urNp linux-2.6.27.10/fs/proc/proc_misc.c linux-2.6.27.10/fs/proc/proc_misc.c
18790 +--- linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-07 12:55:34.000000000 -0500
18791 ++++ linux-2.6.27.10/fs/proc/proc_misc.c 2008-11-18 03:38:45.000000000 -0500
18792 +@@ -860,6 +860,8 @@ struct proc_dir_entry *proc_root_kcore;
18793 +
18794 + void __init proc_misc_init(void)
18795 + {
18796 ++ int gr_mode = 0;
18797 ++
18798 + static struct {
18799 + char *name;
18800 + int (*read_proc)(char*,char**,off_t,int,int*,void*);
18801 +@@ -875,13 +877,24 @@ void __init proc_misc_init(void)
18802 + {"stram", stram_read_proc},
18803 + #endif
18804 + {"filesystems", filesystems_read_proc},
18805 ++#ifndef CONFIG_GRKERNSEC_PROC_ADD
18806 + {"cmdline", cmdline_read_proc},
18807 ++#endif
18808 + {"execdomains", execdomains_read_proc},
18809 + {NULL,}
18810 + };
18811 + for (p = simple_ones; p->name; p++)
18812 + create_proc_read_entry(p->name, 0, NULL, p->read_proc, NULL);
18813 +
18814 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
18815 ++ gr_mode = S_IRUSR;
18816 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18817 ++ gr_mode = S_IRUSR | S_IRGRP;
18818 ++#endif
18819 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
18820 ++ create_proc_read_entry("cmdline", gr_mode, NULL, &cmdline_read_proc, NULL);
18821 ++#endif
18822 ++
18823 + proc_symlink("mounts", NULL, "self/mounts");
18824 +
18825 + /* And now for trickier ones */
18826 +@@ -889,14 +902,18 @@ void __init proc_misc_init(void)
18827 + proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
18828 + #endif
18829 + proc_create("locks", 0, NULL, &proc_locks_operations);
18830 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
18831 ++ proc_create("devices", gr_mode, NULL, &proc_devinfo_operations);
18832 ++#else
18833 + proc_create("devices", 0, NULL, &proc_devinfo_operations);
18834 ++#endif
18835 + proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
18836 + #ifdef CONFIG_BLOCK
18837 + proc_create("partitions", 0, NULL, &proc_partitions_operations);
18838 + #endif
18839 + proc_create("stat", 0, NULL, &proc_stat_operations);
18840 + proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
18841 +-#ifdef CONFIG_SLABINFO
18842 ++#if defined(CONFIG_SLABINFO) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
18843 + proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
18844 + #ifdef CONFIG_DEBUG_SLAB_LEAK
18845 + proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
18846 +@@ -918,7 +935,7 @@ void __init proc_misc_init(void)
18847 + #ifdef CONFIG_SCHEDSTATS
18848 + proc_create("schedstat", 0, NULL, &proc_schedstat_operations);
18849 + #endif
18850 +-#ifdef CONFIG_PROC_KCORE
18851 ++#if defined(CONFIG_PROC_KCORE) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
18852 + proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
18853 + if (proc_root_kcore)
18854 + proc_root_kcore->size =
18855 +diff -urNp linux-2.6.27.10/fs/proc/proc_net.c linux-2.6.27.10/fs/proc/proc_net.c
18856 +--- linux-2.6.27.10/fs/proc/proc_net.c 2008-11-07 12:55:34.000000000 -0500
18857 ++++ linux-2.6.27.10/fs/proc/proc_net.c 2008-11-18 03:38:45.000000000 -0500
18858 +@@ -106,6 +106,14 @@ static struct net *get_proc_task_net(str
18859 + struct nsproxy *ns;
18860 + struct net *net = NULL;
18861 +
18862 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
18863 ++ if (current->fsuid)
18864 ++ return net;
18865 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18866 ++ if (current->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
18867 ++ return net;
18868 ++#endif
18869 ++
18870 + rcu_read_lock();
18871 + task = pid_task(proc_pid(dir), PIDTYPE_PID);
18872 + if (task != NULL) {
18873 +diff -urNp linux-2.6.27.10/fs/proc/proc_sysctl.c linux-2.6.27.10/fs/proc/proc_sysctl.c
18874 +--- linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:38:40.000000000 -0500
18875 ++++ linux-2.6.27.10/fs/proc/proc_sysctl.c 2008-11-18 11:40:53.000000000 -0500
18876 +@@ -7,6 +7,8 @@
18877 + #include <linux/security.h>
18878 + #include "internal.h"
18879 +
18880 ++extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
18881 ++
18882 + static struct dentry_operations proc_sys_dentry_operations;
18883 + static const struct file_operations proc_sys_file_operations;
18884 + static const struct inode_operations proc_sys_inode_operations;
18885 +@@ -110,6 +112,9 @@ static struct dentry *proc_sys_lookup(st
18886 + if (!p)
18887 + goto out;
18888 +
18889 ++ if (gr_handle_sysctl(p, MAY_EXEC))
18890 ++ goto out;
18891 ++
18892 + err = ERR_PTR(-ENOMEM);
18893 + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
18894 + if (h)
18895 +@@ -229,6 +234,9 @@ static int scan(struct ctl_table_header
18896 + if (*pos < file->f_pos)
18897 + continue;
18898 +
18899 ++ if (gr_handle_sysctl(table, 0))
18900 ++ continue;
18901 ++
18902 + res = proc_sys_fill_cache(file, dirent, filldir, head, table);
18903 + if (res)
18904 + return res;
18905 +@@ -339,6 +347,9 @@ static int proc_sys_getattr(struct vfsmo
18906 + if (IS_ERR(head))
18907 + return PTR_ERR(head);
18908 +
18909 ++ if (table && gr_handle_sysctl(table, MAY_EXEC))
18910 ++ return -ENOENT;
18911 ++
18912 + generic_fillattr(inode, stat);
18913 + if (table)
18914 + stat->mode = (stat->mode & S_IFMT) | table->mode;
18915 +diff -urNp linux-2.6.27.10/fs/proc/root.c linux-2.6.27.10/fs/proc/root.c
18916 +--- linux-2.6.27.10/fs/proc/root.c 2008-11-07 12:55:34.000000000 -0500
18917 ++++ linux-2.6.27.10/fs/proc/root.c 2008-11-18 03:38:45.000000000 -0500
18918 +@@ -135,7 +135,15 @@ void __init proc_root_init(void)
18919 + #ifdef CONFIG_PROC_DEVICETREE
18920 + proc_device_tree_init();
18921 + #endif
18922 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
18923 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
18924 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
18925 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
18926 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
18927 ++#endif
18928 ++#else
18929 + proc_mkdir("bus", NULL);
18930 ++#endif
18931 + proc_sys_init();
18932 + }
18933 +
18934 +diff -urNp linux-2.6.27.10/fs/proc/task_mmu.c linux-2.6.27.10/fs/proc/task_mmu.c
18935 +--- linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:16:51.000000000 -0500
18936 ++++ linux-2.6.27.10/fs/proc/task_mmu.c 2008-12-21 01:13:46.000000000 -0500
18937 +@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
18938 + "VmStk:\t%8lu kB\n"
18939 + "VmExe:\t%8lu kB\n"
18940 + "VmLib:\t%8lu kB\n"
18941 +- "VmPTE:\t%8lu kB\n",
18942 +- hiwater_vm << (PAGE_SHIFT-10),
18943 ++ "VmPTE:\t%8lu kB\n"
18944 ++
18945 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
18946 ++ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
18947 ++#endif
18948 ++
18949 ++ ,hiwater_vm << (PAGE_SHIFT-10),
18950 + (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
18951 + mm->locked_vm << (PAGE_SHIFT-10),
18952 + hiwater_rss << (PAGE_SHIFT-10),
18953 + total_rss << (PAGE_SHIFT-10),
18954 + data << (PAGE_SHIFT-10),
18955 + mm->stack_vm << (PAGE_SHIFT-10), text, lib,
18956 +- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
18957 ++ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
18958 ++
18959 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
18960 ++ , mm->context.user_cs_base, mm->context.user_cs_limit
18961 ++#endif
18962 ++
18963 ++ );
18964 + }
18965 +
18966 + unsigned long task_vsize(struct mm_struct *mm)
18967 +@@ -198,6 +209,12 @@ static int do_maps_open(struct inode *in
18968 + return ret;
18969 + }
18970 +
18971 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
18972 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
18973 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
18974 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
18975 ++#endif
18976 ++
18977 + static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
18978 + {
18979 + struct mm_struct *mm = vma->vm_mm;
18980 +@@ -214,13 +231,22 @@ static void show_map_vma(struct seq_file
18981 + }
18982 +
18983 + seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
18984 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
18985 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
18986 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
18987 ++#else
18988 + vma->vm_start,
18989 + vma->vm_end,
18990 ++#endif
18991 + flags & VM_READ ? 'r' : '-',
18992 + flags & VM_WRITE ? 'w' : '-',
18993 + flags & VM_EXEC ? 'x' : '-',
18994 + flags & VM_MAYSHARE ? 's' : 'p',
18995 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
18996 ++ PAX_RAND_FLAGS(mm) ? 0UL : ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
18997 ++#else
18998 + ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
18999 ++#endif
19000 + MAJOR(dev), MINOR(dev), ino, &len);
19001 +
19002 + /*
19003 +@@ -234,11 +260,11 @@ static void show_map_vma(struct seq_file
19004 + const char *name = arch_vma_name(vma);
19005 + if (!name) {
19006 + if (mm) {
19007 +- if (vma->vm_start <= mm->start_brk &&
19008 +- vma->vm_end >= mm->brk) {
19009 ++ if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
19010 + name = "[heap]";
19011 +- } else if (vma->vm_start <= mm->start_stack &&
19012 +- vma->vm_end >= mm->start_stack) {
19013 ++ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
19014 ++ (vma->vm_start <= mm->start_stack &&
19015 ++ vma->vm_end >= mm->start_stack)) {
19016 + name = "[stack]";
19017 + }
19018 + } else {
19019 +@@ -387,9 +413,16 @@ static int show_smap(struct seq_file *m,
19020 + return -EACCES;
19021 +
19022 + memset(&mss, 0, sizeof mss);
19023 +- mss.vma = vma;
19024 +- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
19025 +- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
19026 ++
19027 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
19028 ++ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
19029 ++#endif
19030 ++ mss.vma = vma;
19031 ++ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
19032 ++ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
19033 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
19034 ++ }
19035 ++#endif
19036 +
19037 + show_map_vma(m, vma);
19038 +
19039 +@@ -403,7 +436,11 @@ static int show_smap(struct seq_file *m,
19040 + "Private_Dirty: %8lu kB\n"
19041 + "Referenced: %8lu kB\n"
19042 + "Swap: %8lu kB\n",
19043 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
19044 ++ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
19045 ++#else
19046 + (vma->vm_end - vma->vm_start) >> 10,
19047 ++#endif
19048 + mss.resident >> 10,
19049 + (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
19050 + mss.shared_clean >> 10,
19051 +@@ -757,6 +794,11 @@ static int show_numa_map_checked(struct
19052 + struct proc_maps_private *priv = m->private;
19053 + struct task_struct *task = priv->task;
19054 +
19055 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
19056 ++ if (!ptrace_may_access(task, PTRACE_MODE_READ))
19057 ++ return -EACCES;
19058 ++#endif
19059 ++
19060 + if (maps_protect && !ptrace_may_access(task, PTRACE_MODE_READ))
19061 + return -EACCES;
19062 +
19063 +diff -urNp linux-2.6.27.10/fs/readdir.c linux-2.6.27.10/fs/readdir.c
19064 +--- linux-2.6.27.10/fs/readdir.c 2008-11-07 12:55:34.000000000 -0500
19065 ++++ linux-2.6.27.10/fs/readdir.c 2008-11-18 03:38:45.000000000 -0500
19066 +@@ -16,6 +16,8 @@
19067 + #include <linux/security.h>
19068 + #include <linux/syscalls.h>
19069 + #include <linux/unistd.h>
19070 ++#include <linux/namei.h>
19071 ++#include <linux/grsecurity.h>
19072 +
19073 + #include <asm/uaccess.h>
19074 +
19075 +@@ -67,6 +69,7 @@ struct old_linux_dirent {
19076 +
19077 + struct readdir_callback {
19078 + struct old_linux_dirent __user * dirent;
19079 ++ struct file * file;
19080 + int result;
19081 + };
19082 +
19083 +@@ -84,6 +87,10 @@ static int fillonedir(void * __buf, cons
19084 + buf->result = -EOVERFLOW;
19085 + return -EOVERFLOW;
19086 + }
19087 ++
19088 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
19089 ++ return 0;
19090 ++
19091 + buf->result++;
19092 + dirent = buf->dirent;
19093 + if (!access_ok(VERIFY_WRITE, dirent,
19094 +@@ -115,6 +122,7 @@ asmlinkage long old_readdir(unsigned int
19095 +
19096 + buf.result = 0;
19097 + buf.dirent = dirent;
19098 ++ buf.file = file;
19099 +
19100 + error = vfs_readdir(file, fillonedir, &buf);
19101 + if (error >= 0)
19102 +@@ -141,6 +149,7 @@ struct linux_dirent {
19103 + struct getdents_callback {
19104 + struct linux_dirent __user * current_dir;
19105 + struct linux_dirent __user * previous;
19106 ++ struct file * file;
19107 + int count;
19108 + int error;
19109 + };
19110 +@@ -161,6 +170,10 @@ static int filldir(void * __buf, const c
19111 + buf->error = -EOVERFLOW;
19112 + return -EOVERFLOW;
19113 + }
19114 ++
19115 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
19116 ++ return 0;
19117 ++
19118 + dirent = buf->previous;
19119 + if (dirent) {
19120 + if (__put_user(offset, &dirent->d_off))
19121 +@@ -207,6 +220,7 @@ asmlinkage long sys_getdents(unsigned in
19122 + buf.previous = NULL;
19123 + buf.count = count;
19124 + buf.error = 0;
19125 ++ buf.file = file;
19126 +
19127 + error = vfs_readdir(file, filldir, &buf);
19128 + if (error < 0)
19129 +@@ -229,6 +243,7 @@ out:
19130 + struct getdents_callback64 {
19131 + struct linux_dirent64 __user * current_dir;
19132 + struct linux_dirent64 __user * previous;
19133 ++ struct file *file;
19134 + int count;
19135 + int error;
19136 + };
19137 +@@ -243,6 +258,10 @@ static int filldir64(void * __buf, const
19138 + buf->error = -EINVAL; /* only used if we fail.. */
19139 + if (reclen > buf->count)
19140 + return -EINVAL;
19141 ++
19142 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
19143 ++ return 0;
19144 ++
19145 + dirent = buf->previous;
19146 + if (dirent) {
19147 + if (__put_user(offset, &dirent->d_off))
19148 +@@ -289,6 +308,7 @@ asmlinkage long sys_getdents64(unsigned
19149 +
19150 + buf.current_dir = dirent;
19151 + buf.previous = NULL;
19152 ++ buf.file = file;
19153 + buf.count = count;
19154 + buf.error = 0;
19155 +
19156 +diff -urNp linux-2.6.27.10/fs/select.c linux-2.6.27.10/fs/select.c
19157 +--- linux-2.6.27.10/fs/select.c 2008-11-07 12:55:34.000000000 -0500
19158 ++++ linux-2.6.27.10/fs/select.c 2008-11-18 03:38:45.000000000 -0500
19159 +@@ -24,6 +24,7 @@
19160 + #include <linux/fdtable.h>
19161 + #include <linux/fs.h>
19162 + #include <linux/rcupdate.h>
19163 ++#include <linux/grsecurity.h>
19164 +
19165 + #include <asm/uaccess.h>
19166 +
19167 +@@ -658,6 +659,7 @@ int do_sys_poll(struct pollfd __user *uf
19168 + struct poll_list *walk = head;
19169 + unsigned long todo = nfds;
19170 +
19171 ++ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
19172 + if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
19173 + return -EINVAL;
19174 +
19175 +diff -urNp linux-2.6.27.10/fs/smbfs/symlink.c linux-2.6.27.10/fs/smbfs/symlink.c
19176 +--- linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
19177 ++++ linux-2.6.27.10/fs/smbfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
19178 +@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
19179 +
19180 + static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
19181 + {
19182 +- char *s = nd_get_link(nd);
19183 ++ const char *s = nd_get_link(nd);
19184 + if (!IS_ERR(s))
19185 + __putname(s);
19186 + }
19187 +diff -urNp linux-2.6.27.10/fs/sysfs/symlink.c linux-2.6.27.10/fs/sysfs/symlink.c
19188 +--- linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-07 12:55:34.000000000 -0500
19189 ++++ linux-2.6.27.10/fs/sysfs/symlink.c 2008-11-18 03:38:45.000000000 -0500
19190 +@@ -200,7 +200,7 @@ static void *sysfs_follow_link(struct de
19191 +
19192 + static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
19193 + {
19194 +- char *page = nd_get_link(nd);
19195 ++ const char *page = nd_get_link(nd);
19196 + if (!IS_ERR(page))
19197 + free_page((unsigned long)page);
19198 + }
19199 +diff -urNp linux-2.6.27.10/fs/udf/balloc.c linux-2.6.27.10/fs/udf/balloc.c
19200 +--- linux-2.6.27.10/fs/udf/balloc.c 2008-11-07 12:55:34.000000000 -0500
19201 ++++ linux-2.6.27.10/fs/udf/balloc.c 2008-11-18 03:38:45.000000000 -0500
19202 +@@ -169,9 +169,7 @@ static void udf_bitmap_free_blocks(struc
19203 + unsigned long overflow;
19204 +
19205 + mutex_lock(&sbi->s_alloc_mutex);
19206 +- if (bloc.logicalBlockNum < 0 ||
19207 +- (bloc.logicalBlockNum + count) >
19208 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
19209 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
19210 + udf_debug("%d < %d || %d + %d > %d\n",
19211 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
19212 + sbi->s_partmaps[bloc.partitionReferenceNum].
19213 +@@ -239,7 +237,7 @@ static int udf_bitmap_prealloc_blocks(st
19214 +
19215 + mutex_lock(&sbi->s_alloc_mutex);
19216 + part_len = sbi->s_partmaps[partition].s_partition_len;
19217 +- if (first_block < 0 || first_block >= part_len)
19218 ++ if (first_block >= part_len)
19219 + goto out;
19220 +
19221 + if (first_block + block_count > part_len)
19222 +@@ -300,7 +298,7 @@ static int udf_bitmap_new_block(struct s
19223 + mutex_lock(&sbi->s_alloc_mutex);
19224 +
19225 + repeat:
19226 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
19227 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
19228 + goal = 0;
19229 +
19230 + nr_groups = bitmap->s_nr_groups;
19231 +@@ -438,9 +436,7 @@ static void udf_table_free_blocks(struct
19232 + struct udf_inode_info *iinfo;
19233 +
19234 + mutex_lock(&sbi->s_alloc_mutex);
19235 +- if (bloc.logicalBlockNum < 0 ||
19236 +- (bloc.logicalBlockNum + count) >
19237 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
19238 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
19239 + udf_debug("%d < %d || %d + %d > %d\n",
19240 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
19241 + sbi->s_partmaps[bloc.partitionReferenceNum].
19242 +@@ -671,8 +667,7 @@ static int udf_table_prealloc_blocks(str
19243 + int8_t etype = -1;
19244 + struct udf_inode_info *iinfo;
19245 +
19246 +- if (first_block < 0 ||
19247 +- first_block >= sbi->s_partmaps[partition].s_partition_len)
19248 ++ if (first_block >= sbi->s_partmaps[partition].s_partition_len)
19249 + return 0;
19250 +
19251 + iinfo = UDF_I(table);
19252 +@@ -750,7 +745,7 @@ static int udf_table_new_block(struct su
19253 + return newblock;
19254 +
19255 + mutex_lock(&sbi->s_alloc_mutex);
19256 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
19257 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
19258 + goal = 0;
19259 +
19260 + /* We search for the closest matching block to goal. If we find
19261 +diff -urNp linux-2.6.27.10/fs/ufs/inode.c linux-2.6.27.10/fs/ufs/inode.c
19262 +--- linux-2.6.27.10/fs/ufs/inode.c 2008-11-07 12:55:34.000000000 -0500
19263 ++++ linux-2.6.27.10/fs/ufs/inode.c 2008-11-18 03:38:45.000000000 -0500
19264 +@@ -56,9 +56,7 @@ static int ufs_block_to_path(struct inod
19265 +
19266 +
19267 + UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
19268 +- if (i_block < 0) {
19269 +- ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
19270 +- } else if (i_block < direct_blocks) {
19271 ++ if (i_block < direct_blocks) {
19272 + offsets[n++] = i_block;
19273 + } else if ((i_block -= direct_blocks) < indirect_blocks) {
19274 + offsets[n++] = UFS_IND_BLOCK;
19275 +@@ -440,8 +438,6 @@ int ufs_getfrag_block(struct inode *inod
19276 + lock_kernel();
19277 +
19278 + UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
19279 +- if (fragment < 0)
19280 +- goto abort_negative;
19281 + if (fragment >
19282 + ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
19283 + << uspi->s_fpbshift))
19284 +@@ -504,10 +500,6 @@ abort:
19285 + unlock_kernel();
19286 + return err;
19287 +
19288 +-abort_negative:
19289 +- ufs_warning(sb, "ufs_get_block", "block < 0");
19290 +- goto abort;
19291 +-
19292 + abort_too_big:
19293 + ufs_warning(sb, "ufs_get_block", "block > big");
19294 + goto abort;
19295 +diff -urNp linux-2.6.27.10/fs/utimes.c linux-2.6.27.10/fs/utimes.c
19296 +--- linux-2.6.27.10/fs/utimes.c 2008-11-07 12:55:34.000000000 -0500
19297 ++++ linux-2.6.27.10/fs/utimes.c 2008-11-18 03:38:45.000000000 -0500
19298 +@@ -8,6 +8,7 @@
19299 + #include <linux/stat.h>
19300 + #include <linux/utime.h>
19301 + #include <linux/syscalls.h>
19302 ++#include <linux/grsecurity.h>
19303 + #include <asm/uaccess.h>
19304 + #include <asm/unistd.h>
19305 +
19306 +@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
19307 + goto mnt_drop_write_and_out;
19308 + }
19309 + }
19310 ++
19311 ++ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
19312 ++ error = -EACCES;
19313 ++ goto mnt_drop_write_and_out;
19314 ++ }
19315 ++
19316 + mutex_lock(&inode->i_mutex);
19317 + error = notify_change(path->dentry, &newattrs);
19318 + mutex_unlock(&inode->i_mutex);
19319 +diff -urNp linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c
19320 +--- linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-07 12:55:34.000000000 -0500
19321 ++++ linux-2.6.27.10/fs/xfs/linux-2.6/xfs_iops.c 2008-11-18 03:38:45.000000000 -0500
19322 +@@ -500,7 +500,7 @@ xfs_vn_put_link(
19323 + struct nameidata *nd,
19324 + void *p)
19325 + {
19326 +- char *s = nd_get_link(nd);
19327 ++ const char *s = nd_get_link(nd);
19328 +
19329 + if (!IS_ERR(s))
19330 + kfree(s);
19331 +diff -urNp linux-2.6.27.10/fs/xfs/xfs_bmap.c linux-2.6.27.10/fs/xfs/xfs_bmap.c
19332 +--- linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-07 12:55:34.000000000 -0500
19333 ++++ linux-2.6.27.10/fs/xfs/xfs_bmap.c 2008-11-18 03:38:45.000000000 -0500
19334 +@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
19335 + int nmap,
19336 + int ret_nmap);
19337 + #else
19338 +-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
19339 ++#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
19340 + #endif /* DEBUG */
19341 +
19342 + #if defined(XFS_RW_TRACE)
19343 +diff -urNp linux-2.6.27.10/grsecurity/gracl_alloc.c linux-2.6.27.10/grsecurity/gracl_alloc.c
19344 +--- linux-2.6.27.10/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
19345 ++++ linux-2.6.27.10/grsecurity/gracl_alloc.c 2008-11-18 03:38:45.000000000 -0500
19346 +@@ -0,0 +1,91 @@
19347 ++#include <linux/kernel.h>
19348 ++#include <linux/mm.h>
19349 ++#include <linux/slab.h>
19350 ++#include <linux/vmalloc.h>
19351 ++#include <linux/gracl.h>
19352 ++#include <linux/grsecurity.h>
19353 ++
19354 ++static unsigned long alloc_stack_next = 1;
19355 ++static unsigned long alloc_stack_size = 1;
19356 ++static void **alloc_stack;
19357 ++
19358 ++static __inline__ int
19359 ++alloc_pop(void)
19360 ++{
19361 ++ if (alloc_stack_next == 1)
19362 ++ return 0;
19363 ++
19364 ++ kfree(alloc_stack[alloc_stack_next - 2]);
19365 ++
19366 ++ alloc_stack_next--;
19367 ++
19368 ++ return 1;
19369 ++}
19370 ++
19371 ++static __inline__ void
19372 ++alloc_push(void *buf)
19373 ++{
19374 ++ if (alloc_stack_next >= alloc_stack_size)
19375 ++ BUG();
19376 ++
19377 ++ alloc_stack[alloc_stack_next - 1] = buf;
19378 ++
19379 ++ alloc_stack_next++;
19380 ++
19381 ++ return;
19382 ++}
19383 ++
19384 ++void *
19385 ++acl_alloc(unsigned long len)
19386 ++{
19387 ++ void *ret;
19388 ++
19389 ++ if (len > PAGE_SIZE)
19390 ++ BUG();
19391 ++
19392 ++ ret = kmalloc(len, GFP_KERNEL);
19393 ++
19394 ++ if (ret)
19395 ++ alloc_push(ret);
19396 ++
19397 ++ return ret;
19398 ++}
19399 ++
19400 ++void
19401 ++acl_free_all(void)
19402 ++{
19403 ++ if (gr_acl_is_enabled() || !alloc_stack)
19404 ++ return;
19405 ++
19406 ++ while (alloc_pop()) ;
19407 ++
19408 ++ if (alloc_stack) {
19409 ++ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
19410 ++ kfree(alloc_stack);
19411 ++ else
19412 ++ vfree(alloc_stack);
19413 ++ }
19414 ++
19415 ++ alloc_stack = NULL;
19416 ++ alloc_stack_size = 1;
19417 ++ alloc_stack_next = 1;
19418 ++
19419 ++ return;
19420 ++}
19421 ++
19422 ++int
19423 ++acl_alloc_stack_init(unsigned long size)
19424 ++{
19425 ++ if ((size * sizeof (void *)) <= PAGE_SIZE)
19426 ++ alloc_stack =
19427 ++ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
19428 ++ else
19429 ++ alloc_stack = (void **) vmalloc(size * sizeof (void *));
19430 ++
19431 ++ alloc_stack_size = size;
19432 ++
19433 ++ if (!alloc_stack)
19434 ++ return 0;
19435 ++ else
19436 ++ return 1;
19437 ++}
19438 +diff -urNp linux-2.6.27.10/grsecurity/gracl.c linux-2.6.27.10/grsecurity/gracl.c
19439 +--- linux-2.6.27.10/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
19440 ++++ linux-2.6.27.10/grsecurity/gracl.c 2008-11-18 03:38:45.000000000 -0500
19441 +@@ -0,0 +1,3722 @@
19442 ++#include <linux/kernel.h>
19443 ++#include <linux/module.h>
19444 ++#include <linux/sched.h>
19445 ++#include <linux/mm.h>
19446 ++#include <linux/file.h>
19447 ++#include <linux/fs.h>
19448 ++#include <linux/namei.h>
19449 ++#include <linux/mount.h>
19450 ++#include <linux/tty.h>
19451 ++#include <linux/proc_fs.h>
19452 ++#include <linux/smp_lock.h>
19453 ++#include <linux/slab.h>
19454 ++#include <linux/vmalloc.h>
19455 ++#include <linux/types.h>
19456 ++#include <linux/sysctl.h>
19457 ++#include <linux/netdevice.h>
19458 ++#include <linux/ptrace.h>
19459 ++#include <linux/gracl.h>
19460 ++#include <linux/gralloc.h>
19461 ++#include <linux/grsecurity.h>
19462 ++#include <linux/grinternal.h>
19463 ++#include <linux/pid_namespace.h>
19464 ++#include <linux/fdtable.h>
19465 ++#include <linux/percpu.h>
19466 ++
19467 ++#include <asm/uaccess.h>
19468 ++#include <asm/errno.h>
19469 ++#include <asm/mman.h>
19470 ++
19471 ++static struct acl_role_db acl_role_set;
19472 ++static struct name_db name_set;
19473 ++static struct inodev_db inodev_set;
19474 ++
19475 ++/* for keeping track of userspace pointers used for subjects, so we
19476 ++ can share references in the kernel as well
19477 ++*/
19478 ++
19479 ++static struct dentry *real_root;
19480 ++static struct vfsmount *real_root_mnt;
19481 ++
19482 ++static struct acl_subj_map_db subj_map_set;
19483 ++
19484 ++static struct acl_role_label *default_role;
19485 ++
19486 ++static u16 acl_sp_role_value;
19487 ++
19488 ++extern char *gr_shared_page[4];
19489 ++static DECLARE_MUTEX(gr_dev_sem);
19490 ++DEFINE_RWLOCK(gr_inode_lock);
19491 ++
19492 ++struct gr_arg *gr_usermode;
19493 ++
19494 ++static unsigned int gr_status = GR_STATUS_INIT;
19495 ++
19496 ++extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
19497 ++extern void gr_clear_learn_entries(void);
19498 ++
19499 ++#ifdef CONFIG_GRKERNSEC_RESLOG
19500 ++extern void gr_log_resource(const struct task_struct *task,
19501 ++ const int res, const unsigned long wanted, const int gt);
19502 ++#endif
19503 ++
19504 ++unsigned char *gr_system_salt;
19505 ++unsigned char *gr_system_sum;
19506 ++
19507 ++static struct sprole_pw **acl_special_roles = NULL;
19508 ++static __u16 num_sprole_pws = 0;
19509 ++
19510 ++static struct acl_role_label *kernel_role = NULL;
19511 ++
19512 ++static unsigned int gr_auth_attempts = 0;
19513 ++static unsigned long gr_auth_expires = 0UL;
19514 ++
19515 ++extern struct vfsmount *sock_mnt;
19516 ++extern struct vfsmount *pipe_mnt;
19517 ++extern struct vfsmount *shm_mnt;
19518 ++static struct acl_object_label *fakefs_obj;
19519 ++
19520 ++extern int gr_init_uidset(void);
19521 ++extern void gr_free_uidset(void);
19522 ++extern void gr_remove_uid(uid_t uid);
19523 ++extern int gr_find_uid(uid_t uid);
19524 ++
19525 ++__inline__ int
19526 ++gr_acl_is_enabled(void)
19527 ++{
19528 ++ return (gr_status & GR_READY);
19529 ++}
19530 ++
19531 ++char gr_roletype_to_char(void)
19532 ++{
19533 ++ switch (current->role->roletype &
19534 ++ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
19535 ++ GR_ROLE_SPECIAL)) {
19536 ++ case GR_ROLE_DEFAULT:
19537 ++ return 'D';
19538 ++ case GR_ROLE_USER:
19539 ++ return 'U';
19540 ++ case GR_ROLE_GROUP:
19541 ++ return 'G';
19542 ++ case GR_ROLE_SPECIAL:
19543 ++ return 'S';
19544 ++ }
19545 ++
19546 ++ return 'X';
19547 ++}
19548 ++
19549 ++__inline__ int
19550 ++gr_acl_tpe_check(void)
19551 ++{
19552 ++ if (unlikely(!(gr_status & GR_READY)))
19553 ++ return 0;
19554 ++ if (current->role->roletype & GR_ROLE_TPE)
19555 ++ return 1;
19556 ++ else
19557 ++ return 0;
19558 ++}
19559 ++
19560 ++int
19561 ++gr_handle_rawio(const struct inode *inode)
19562 ++{
19563 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
19564 ++ if (inode && S_ISBLK(inode->i_mode) &&
19565 ++ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
19566 ++ !capable(CAP_SYS_RAWIO))
19567 ++ return 1;
19568 ++#endif
19569 ++ return 0;
19570 ++}
19571 ++
19572 ++static int
19573 ++gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
19574 ++{
19575 ++ int i;
19576 ++ unsigned long *l1;
19577 ++ unsigned long *l2;
19578 ++ unsigned char *c1;
19579 ++ unsigned char *c2;
19580 ++ int num_longs;
19581 ++
19582 ++ if (likely(lena != lenb))
19583 ++ return 0;
19584 ++
19585 ++ l1 = (unsigned long *)a;
19586 ++ l2 = (unsigned long *)b;
19587 ++
19588 ++ num_longs = lena / sizeof(unsigned long);
19589 ++
19590 ++ for (i = num_longs; i--; l1++, l2++) {
19591 ++ if (unlikely(*l1 != *l2))
19592 ++ return 0;
19593 ++ }
19594 ++
19595 ++ c1 = (unsigned char *) l1;
19596 ++ c2 = (unsigned char *) l2;
19597 ++
19598 ++ i = lena - (num_longs * sizeof(unsigned long));
19599 ++
19600 ++ for (; i--; c1++, c2++) {
19601 ++ if (unlikely(*c1 != *c2))
19602 ++ return 0;
19603 ++ }
19604 ++
19605 ++ return 1;
19606 ++}
19607 ++
19608 ++static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
19609 ++ struct dentry *root, struct vfsmount *rootmnt,
19610 ++ char *buffer, int buflen)
19611 ++{
19612 ++ char * end = buffer+buflen;
19613 ++ char * retval;
19614 ++ int namelen;
19615 ++
19616 ++ *--end = '\0';
19617 ++ buflen--;
19618 ++
19619 ++ if (buflen < 1)
19620 ++ goto Elong;
19621 ++ /* Get '/' right */
19622 ++ retval = end-1;
19623 ++ *retval = '/';
19624 ++
19625 ++ for (;;) {
19626 ++ struct dentry * parent;
19627 ++
19628 ++ if (dentry == root && vfsmnt == rootmnt)
19629 ++ break;
19630 ++ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
19631 ++ /* Global root? */
19632 ++ spin_lock(&vfsmount_lock);
19633 ++ if (vfsmnt->mnt_parent == vfsmnt) {
19634 ++ spin_unlock(&vfsmount_lock);
19635 ++ goto global_root;
19636 ++ }
19637 ++ dentry = vfsmnt->mnt_mountpoint;
19638 ++ vfsmnt = vfsmnt->mnt_parent;
19639 ++ spin_unlock(&vfsmount_lock);
19640 ++ continue;
19641 ++ }
19642 ++ parent = dentry->d_parent;
19643 ++ prefetch(parent);
19644 ++ namelen = dentry->d_name.len;
19645 ++ buflen -= namelen + 1;
19646 ++ if (buflen < 0)
19647 ++ goto Elong;
19648 ++ end -= namelen;
19649 ++ memcpy(end, dentry->d_name.name, namelen);
19650 ++ *--end = '/';
19651 ++ retval = end;
19652 ++ dentry = parent;
19653 ++ }
19654 ++
19655 ++ return retval;
19656 ++
19657 ++global_root:
19658 ++ namelen = dentry->d_name.len;
19659 ++ buflen -= namelen;
19660 ++ if (buflen < 0)
19661 ++ goto Elong;
19662 ++ retval -= namelen-1; /* hit the slash */
19663 ++ memcpy(retval, dentry->d_name.name, namelen);
19664 ++ return retval;
19665 ++Elong:
19666 ++ return ERR_PTR(-ENAMETOOLONG);
19667 ++}
19668 ++
19669 ++static char *
19670 ++gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
19671 ++ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
19672 ++{
19673 ++ char *retval;
19674 ++
19675 ++ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
19676 ++ if (unlikely(IS_ERR(retval)))
19677 ++ retval = strcpy(buf, "<path too long>");
19678 ++ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
19679 ++ retval[1] = '\0';
19680 ++
19681 ++ return retval;
19682 ++}
19683 ++
19684 ++static char *
19685 ++__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
19686 ++ char *buf, int buflen)
19687 ++{
19688 ++ char *res;
19689 ++
19690 ++ /* we can use real_root, real_root_mnt, because this is only called
19691 ++ by the RBAC system */
19692 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
19693 ++
19694 ++ return res;
19695 ++}
19696 ++
19697 ++static char *
19698 ++d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
19699 ++ char *buf, int buflen)
19700 ++{
19701 ++ char *res;
19702 ++ struct dentry *root;
19703 ++ struct vfsmount *rootmnt;
19704 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
19705 ++
19706 ++ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
19707 ++ read_lock(&reaper->fs->lock);
19708 ++ root = dget(reaper->fs->root.dentry);
19709 ++ rootmnt = mntget(reaper->fs->root.mnt);
19710 ++ read_unlock(&reaper->fs->lock);
19711 ++
19712 ++ spin_lock(&dcache_lock);
19713 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
19714 ++ spin_unlock(&dcache_lock);
19715 ++
19716 ++ dput(root);
19717 ++ mntput(rootmnt);
19718 ++ return res;
19719 ++}
19720 ++
19721 ++static char *
19722 ++gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
19723 ++{
19724 ++ char *ret;
19725 ++ spin_lock(&dcache_lock);
19726 ++ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
19727 ++ PAGE_SIZE);
19728 ++ spin_unlock(&dcache_lock);
19729 ++ return ret;
19730 ++}
19731 ++
19732 ++char *
19733 ++gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
19734 ++{
19735 ++ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
19736 ++ PAGE_SIZE);
19737 ++}
19738 ++
19739 ++char *
19740 ++gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
19741 ++{
19742 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
19743 ++ PAGE_SIZE);
19744 ++}
19745 ++
19746 ++char *
19747 ++gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
19748 ++{
19749 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
19750 ++ PAGE_SIZE);
19751 ++}
19752 ++
19753 ++char *
19754 ++gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
19755 ++{
19756 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
19757 ++ PAGE_SIZE);
19758 ++}
19759 ++
19760 ++char *
19761 ++gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
19762 ++{
19763 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
19764 ++ PAGE_SIZE);
19765 ++}
19766 ++
19767 ++__inline__ __u32
19768 ++to_gr_audit(const __u32 reqmode)
19769 ++{
19770 ++ /* masks off auditable permission flags, then shifts them to create
19771 ++ auditing flags, and adds the special case of append auditing if
19772 ++ we're requesting write */
19773 ++ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
19774 ++}
19775 ++
19776 ++struct acl_subject_label *
19777 ++lookup_subject_map(const struct acl_subject_label *userp)
19778 ++{
19779 ++ unsigned int index = shash(userp, subj_map_set.s_size);
19780 ++ struct subject_map *match;
19781 ++
19782 ++ match = subj_map_set.s_hash[index];
19783 ++
19784 ++ while (match && match->user != userp)
19785 ++ match = match->next;
19786 ++
19787 ++ if (match != NULL)
19788 ++ return match->kernel;
19789 ++ else
19790 ++ return NULL;
19791 ++}
19792 ++
19793 ++static void
19794 ++insert_subj_map_entry(struct subject_map *subjmap)
19795 ++{
19796 ++ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
19797 ++ struct subject_map **curr;
19798 ++
19799 ++ subjmap->prev = NULL;
19800 ++
19801 ++ curr = &subj_map_set.s_hash[index];
19802 ++ if (*curr != NULL)
19803 ++ (*curr)->prev = subjmap;
19804 ++
19805 ++ subjmap->next = *curr;
19806 ++ *curr = subjmap;
19807 ++
19808 ++ return;
19809 ++}
19810 ++
19811 ++static struct acl_role_label *
19812 ++lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
19813 ++ const gid_t gid)
19814 ++{
19815 ++ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
19816 ++ struct acl_role_label *match;
19817 ++ struct role_allowed_ip *ipp;
19818 ++ unsigned int x;
19819 ++
19820 ++ match = acl_role_set.r_hash[index];
19821 ++
19822 ++ while (match) {
19823 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
19824 ++ for (x = 0; x < match->domain_child_num; x++) {
19825 ++ if (match->domain_children[x] == uid)
19826 ++ goto found;
19827 ++ }
19828 ++ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
19829 ++ break;
19830 ++ match = match->next;
19831 ++ }
19832 ++found:
19833 ++ if (match == NULL) {
19834 ++ try_group:
19835 ++ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
19836 ++ match = acl_role_set.r_hash[index];
19837 ++
19838 ++ while (match) {
19839 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
19840 ++ for (x = 0; x < match->domain_child_num; x++) {
19841 ++ if (match->domain_children[x] == gid)
19842 ++ goto found2;
19843 ++ }
19844 ++ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
19845 ++ break;
19846 ++ match = match->next;
19847 ++ }
19848 ++found2:
19849 ++ if (match == NULL)
19850 ++ match = default_role;
19851 ++ if (match->allowed_ips == NULL)
19852 ++ return match;
19853 ++ else {
19854 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
19855 ++ if (likely
19856 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
19857 ++ (ntohl(ipp->addr) & ipp->netmask)))
19858 ++ return match;
19859 ++ }
19860 ++ match = default_role;
19861 ++ }
19862 ++ } else if (match->allowed_ips == NULL) {
19863 ++ return match;
19864 ++ } else {
19865 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
19866 ++ if (likely
19867 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
19868 ++ (ntohl(ipp->addr) & ipp->netmask)))
19869 ++ return match;
19870 ++ }
19871 ++ goto try_group;
19872 ++ }
19873 ++
19874 ++ return match;
19875 ++}
19876 ++
19877 ++struct acl_subject_label *
19878 ++lookup_acl_subj_label(const ino_t ino, const dev_t dev,
19879 ++ const struct acl_role_label *role)
19880 ++{
19881 ++ unsigned int index = fhash(ino, dev, role->subj_hash_size);
19882 ++ struct acl_subject_label *match;
19883 ++
19884 ++ match = role->subj_hash[index];
19885 ++
19886 ++ while (match && (match->inode != ino || match->device != dev ||
19887 ++ (match->mode & GR_DELETED))) {
19888 ++ match = match->next;
19889 ++ }
19890 ++
19891 ++ if (match && !(match->mode & GR_DELETED))
19892 ++ return match;
19893 ++ else
19894 ++ return NULL;
19895 ++}
19896 ++
19897 ++static struct acl_object_label *
19898 ++lookup_acl_obj_label(const ino_t ino, const dev_t dev,
19899 ++ const struct acl_subject_label *subj)
19900 ++{
19901 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
19902 ++ struct acl_object_label *match;
19903 ++
19904 ++ match = subj->obj_hash[index];
19905 ++
19906 ++ while (match && (match->inode != ino || match->device != dev ||
19907 ++ (match->mode & GR_DELETED))) {
19908 ++ match = match->next;
19909 ++ }
19910 ++
19911 ++ if (match && !(match->mode & GR_DELETED))
19912 ++ return match;
19913 ++ else
19914 ++ return NULL;
19915 ++}
19916 ++
19917 ++static struct acl_object_label *
19918 ++lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
19919 ++ const struct acl_subject_label *subj)
19920 ++{
19921 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
19922 ++ struct acl_object_label *match;
19923 ++
19924 ++ match = subj->obj_hash[index];
19925 ++
19926 ++ while (match && (match->inode != ino || match->device != dev ||
19927 ++ !(match->mode & GR_DELETED))) {
19928 ++ match = match->next;
19929 ++ }
19930 ++
19931 ++ if (match && (match->mode & GR_DELETED))
19932 ++ return match;
19933 ++
19934 ++ match = subj->obj_hash[index];
19935 ++
19936 ++ while (match && (match->inode != ino || match->device != dev ||
19937 ++ (match->mode & GR_DELETED))) {
19938 ++ match = match->next;
19939 ++ }
19940 ++
19941 ++ if (match && !(match->mode & GR_DELETED))
19942 ++ return match;
19943 ++ else
19944 ++ return NULL;
19945 ++}
19946 ++
19947 ++static struct name_entry *
19948 ++lookup_name_entry(const char *name)
19949 ++{
19950 ++ unsigned int len = strlen(name);
19951 ++ unsigned int key = full_name_hash(name, len);
19952 ++ unsigned int index = key % name_set.n_size;
19953 ++ struct name_entry *match;
19954 ++
19955 ++ match = name_set.n_hash[index];
19956 ++
19957 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
19958 ++ match = match->next;
19959 ++
19960 ++ return match;
19961 ++}
19962 ++
19963 ++static struct name_entry *
19964 ++lookup_name_entry_create(const char *name)
19965 ++{
19966 ++ unsigned int len = strlen(name);
19967 ++ unsigned int key = full_name_hash(name, len);
19968 ++ unsigned int index = key % name_set.n_size;
19969 ++ struct name_entry *match;
19970 ++
19971 ++ match = name_set.n_hash[index];
19972 ++
19973 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
19974 ++ !match->deleted))
19975 ++ match = match->next;
19976 ++
19977 ++ if (match && match->deleted)
19978 ++ return match;
19979 ++
19980 ++ match = name_set.n_hash[index];
19981 ++
19982 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
19983 ++ match->deleted))
19984 ++ match = match->next;
19985 ++
19986 ++ if (match && !match->deleted)
19987 ++ return match;
19988 ++ else
19989 ++ return NULL;
19990 ++}
19991 ++
19992 ++static struct inodev_entry *
19993 ++lookup_inodev_entry(const ino_t ino, const dev_t dev)
19994 ++{
19995 ++ unsigned int index = fhash(ino, dev, inodev_set.i_size);
19996 ++ struct inodev_entry *match;
19997 ++
19998 ++ match = inodev_set.i_hash[index];
19999 ++
20000 ++ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
20001 ++ match = match->next;
20002 ++
20003 ++ return match;
20004 ++}
20005 ++
20006 ++static void
20007 ++insert_inodev_entry(struct inodev_entry *entry)
20008 ++{
20009 ++ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
20010 ++ inodev_set.i_size);
20011 ++ struct inodev_entry **curr;
20012 ++
20013 ++ entry->prev = NULL;
20014 ++
20015 ++ curr = &inodev_set.i_hash[index];
20016 ++ if (*curr != NULL)
20017 ++ (*curr)->prev = entry;
20018 ++
20019 ++ entry->next = *curr;
20020 ++ *curr = entry;
20021 ++
20022 ++ return;
20023 ++}
20024 ++
20025 ++static void
20026 ++__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
20027 ++{
20028 ++ unsigned int index =
20029 ++ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
20030 ++ struct acl_role_label **curr;
20031 ++
20032 ++ role->prev = NULL;
20033 ++
20034 ++ curr = &acl_role_set.r_hash[index];
20035 ++ if (*curr != NULL)
20036 ++ (*curr)->prev = role;
20037 ++
20038 ++ role->next = *curr;
20039 ++ *curr = role;
20040 ++
20041 ++ return;
20042 ++}
20043 ++
20044 ++static void
20045 ++insert_acl_role_label(struct acl_role_label *role)
20046 ++{
20047 ++ int i;
20048 ++
20049 ++ if (role->roletype & GR_ROLE_DOMAIN) {
20050 ++ for (i = 0; i < role->domain_child_num; i++)
20051 ++ __insert_acl_role_label(role, role->domain_children[i]);
20052 ++ } else
20053 ++ __insert_acl_role_label(role, role->uidgid);
20054 ++}
20055 ++
20056 ++static int
20057 ++insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
20058 ++{
20059 ++ struct name_entry **curr, *nentry;
20060 ++ struct inodev_entry *ientry;
20061 ++ unsigned int len = strlen(name);
20062 ++ unsigned int key = full_name_hash(name, len);
20063 ++ unsigned int index = key % name_set.n_size;
20064 ++
20065 ++ curr = &name_set.n_hash[index];
20066 ++
20067 ++ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
20068 ++ curr = &((*curr)->next);
20069 ++
20070 ++ if (*curr != NULL)
20071 ++ return 1;
20072 ++
20073 ++ nentry = acl_alloc(sizeof (struct name_entry));
20074 ++ if (nentry == NULL)
20075 ++ return 0;
20076 ++ ientry = acl_alloc(sizeof (struct inodev_entry));
20077 ++ if (ientry == NULL)
20078 ++ return 0;
20079 ++ ientry->nentry = nentry;
20080 ++
20081 ++ nentry->key = key;
20082 ++ nentry->name = name;
20083 ++ nentry->inode = inode;
20084 ++ nentry->device = device;
20085 ++ nentry->len = len;
20086 ++ nentry->deleted = deleted;
20087 ++
20088 ++ nentry->prev = NULL;
20089 ++ curr = &name_set.n_hash[index];
20090 ++ if (*curr != NULL)
20091 ++ (*curr)->prev = nentry;
20092 ++ nentry->next = *curr;
20093 ++ *curr = nentry;
20094 ++
20095 ++ /* insert us into the table searchable by inode/dev */
20096 ++ insert_inodev_entry(ientry);
20097 ++
20098 ++ return 1;
20099 ++}
20100 ++
20101 ++static void
20102 ++insert_acl_obj_label(struct acl_object_label *obj,
20103 ++ struct acl_subject_label *subj)
20104 ++{
20105 ++ unsigned int index =
20106 ++ fhash(obj->inode, obj->device, subj->obj_hash_size);
20107 ++ struct acl_object_label **curr;
20108 ++
20109 ++
20110 ++ obj->prev = NULL;
20111 ++
20112 ++ curr = &subj->obj_hash[index];
20113 ++ if (*curr != NULL)
20114 ++ (*curr)->prev = obj;
20115 ++
20116 ++ obj->next = *curr;
20117 ++ *curr = obj;
20118 ++
20119 ++ return;
20120 ++}
20121 ++
20122 ++static void
20123 ++insert_acl_subj_label(struct acl_subject_label *obj,
20124 ++ struct acl_role_label *role)
20125 ++{
20126 ++ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
20127 ++ struct acl_subject_label **curr;
20128 ++
20129 ++ obj->prev = NULL;
20130 ++
20131 ++ curr = &role->subj_hash[index];
20132 ++ if (*curr != NULL)
20133 ++ (*curr)->prev = obj;
20134 ++
20135 ++ obj->next = *curr;
20136 ++ *curr = obj;
20137 ++
20138 ++ return;
20139 ++}
20140 ++
20141 ++/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
20142 ++
20143 ++static void *
20144 ++create_table(__u32 * len, int elementsize)
20145 ++{
20146 ++ unsigned int table_sizes[] = {
20147 ++ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
20148 ++ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
20149 ++ 4194301, 8388593, 16777213, 33554393, 67108859, 134217689,
20150 ++ 268435399, 536870909, 1073741789, 2147483647
20151 ++ };
20152 ++ void *newtable = NULL;
20153 ++ unsigned int pwr = 0;
20154 ++
20155 ++ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
20156 ++ table_sizes[pwr] <= *len)
20157 ++ pwr++;
20158 ++
20159 ++ if (table_sizes[pwr] <= *len)
20160 ++ return newtable;
20161 ++
20162 ++ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
20163 ++ newtable =
20164 ++ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
20165 ++ else
20166 ++ newtable = vmalloc(table_sizes[pwr] * elementsize);
20167 ++
20168 ++ *len = table_sizes[pwr];
20169 ++
20170 ++ return newtable;
20171 ++}
20172 ++
20173 ++static int
20174 ++init_variables(const struct gr_arg *arg)
20175 ++{
20176 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
20177 ++ unsigned int stacksize;
20178 ++
20179 ++ subj_map_set.s_size = arg->role_db.num_subjects;
20180 ++ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
20181 ++ name_set.n_size = arg->role_db.num_objects;
20182 ++ inodev_set.i_size = arg->role_db.num_objects;
20183 ++
20184 ++ if (!subj_map_set.s_size || !acl_role_set.r_size ||
20185 ++ !name_set.n_size || !inodev_set.i_size)
20186 ++ return 1;
20187 ++
20188 ++ if (!gr_init_uidset())
20189 ++ return 1;
20190 ++
20191 ++ /* set up the stack that holds allocation info */
20192 ++
20193 ++ stacksize = arg->role_db.num_pointers + 5;
20194 ++
20195 ++ if (!acl_alloc_stack_init(stacksize))
20196 ++ return 1;
20197 ++
20198 ++ /* grab reference for the real root dentry and vfsmount */
20199 ++ read_lock(&reaper->fs->lock);
20200 ++ real_root_mnt = mntget(reaper->fs->root.mnt);
20201 ++ real_root = dget(reaper->fs->root.dentry);
20202 ++ read_unlock(&reaper->fs->lock);
20203 ++
20204 ++ fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
20205 ++ if (fakefs_obj == NULL)
20206 ++ return 1;
20207 ++ fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
20208 ++
20209 ++ subj_map_set.s_hash =
20210 ++ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
20211 ++ acl_role_set.r_hash =
20212 ++ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
20213 ++ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
20214 ++ inodev_set.i_hash =
20215 ++ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
20216 ++
20217 ++ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
20218 ++ !name_set.n_hash || !inodev_set.i_hash)
20219 ++ return 1;
20220 ++
20221 ++ memset(subj_map_set.s_hash, 0,
20222 ++ sizeof(struct subject_map *) * subj_map_set.s_size);
20223 ++ memset(acl_role_set.r_hash, 0,
20224 ++ sizeof (struct acl_role_label *) * acl_role_set.r_size);
20225 ++ memset(name_set.n_hash, 0,
20226 ++ sizeof (struct name_entry *) * name_set.n_size);
20227 ++ memset(inodev_set.i_hash, 0,
20228 ++ sizeof (struct inodev_entry *) * inodev_set.i_size);
20229 ++
20230 ++ return 0;
20231 ++}
20232 ++
20233 ++/* free information not needed after startup
20234 ++ currently contains user->kernel pointer mappings for subjects
20235 ++*/
20236 ++
20237 ++static void
20238 ++free_init_variables(void)
20239 ++{
20240 ++ __u32 i;
20241 ++
20242 ++ if (subj_map_set.s_hash) {
20243 ++ for (i = 0; i < subj_map_set.s_size; i++) {
20244 ++ if (subj_map_set.s_hash[i]) {
20245 ++ kfree(subj_map_set.s_hash[i]);
20246 ++ subj_map_set.s_hash[i] = NULL;
20247 ++ }
20248 ++ }
20249 ++
20250 ++ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
20251 ++ PAGE_SIZE)
20252 ++ kfree(subj_map_set.s_hash);
20253 ++ else
20254 ++ vfree(subj_map_set.s_hash);
20255 ++ }
20256 ++
20257 ++ return;
20258 ++}
20259 ++
20260 ++static void
20261 ++free_variables(void)
20262 ++{
20263 ++ struct acl_subject_label *s;
20264 ++ struct acl_role_label *r;
20265 ++ struct task_struct *task, *task2;
20266 ++ unsigned int i, x;
20267 ++
20268 ++ gr_clear_learn_entries();
20269 ++
20270 ++ read_lock(&tasklist_lock);
20271 ++ do_each_thread(task2, task) {
20272 ++ task->acl_sp_role = 0;
20273 ++ task->acl_role_id = 0;
20274 ++ task->acl = NULL;
20275 ++ task->role = NULL;
20276 ++ } while_each_thread(task2, task);
20277 ++ read_unlock(&tasklist_lock);
20278 ++
20279 ++ /* release the reference to the real root dentry and vfsmount */
20280 ++ if (real_root)
20281 ++ dput(real_root);
20282 ++ real_root = NULL;
20283 ++ if (real_root_mnt)
20284 ++ mntput(real_root_mnt);
20285 ++ real_root_mnt = NULL;
20286 ++
20287 ++ /* free all object hash tables */
20288 ++
20289 ++ FOR_EACH_ROLE_START(r, i)
20290 ++ if (r->subj_hash == NULL)
20291 ++ break;
20292 ++ FOR_EACH_SUBJECT_START(r, s, x)
20293 ++ if (s->obj_hash == NULL)
20294 ++ break;
20295 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
20296 ++ kfree(s->obj_hash);
20297 ++ else
20298 ++ vfree(s->obj_hash);
20299 ++ FOR_EACH_SUBJECT_END(s, x)
20300 ++ FOR_EACH_NESTED_SUBJECT_START(r, s)
20301 ++ if (s->obj_hash == NULL)
20302 ++ break;
20303 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
20304 ++ kfree(s->obj_hash);
20305 ++ else
20306 ++ vfree(s->obj_hash);
20307 ++ FOR_EACH_NESTED_SUBJECT_END(s)
20308 ++ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
20309 ++ kfree(r->subj_hash);
20310 ++ else
20311 ++ vfree(r->subj_hash);
20312 ++ r->subj_hash = NULL;
20313 ++ FOR_EACH_ROLE_END(r,i)
20314 ++
20315 ++ acl_free_all();
20316 ++
20317 ++ if (acl_role_set.r_hash) {
20318 ++ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
20319 ++ PAGE_SIZE)
20320 ++ kfree(acl_role_set.r_hash);
20321 ++ else
20322 ++ vfree(acl_role_set.r_hash);
20323 ++ }
20324 ++ if (name_set.n_hash) {
20325 ++ if ((name_set.n_size * sizeof (struct name_entry *)) <=
20326 ++ PAGE_SIZE)
20327 ++ kfree(name_set.n_hash);
20328 ++ else
20329 ++ vfree(name_set.n_hash);
20330 ++ }
20331 ++
20332 ++ if (inodev_set.i_hash) {
20333 ++ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
20334 ++ PAGE_SIZE)
20335 ++ kfree(inodev_set.i_hash);
20336 ++ else
20337 ++ vfree(inodev_set.i_hash);
20338 ++ }
20339 ++
20340 ++ gr_free_uidset();
20341 ++
20342 ++ memset(&name_set, 0, sizeof (struct name_db));
20343 ++ memset(&inodev_set, 0, sizeof (struct inodev_db));
20344 ++ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
20345 ++ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
20346 ++
20347 ++ default_role = NULL;
20348 ++
20349 ++ return;
20350 ++}
20351 ++
20352 ++static __u32
20353 ++count_user_objs(struct acl_object_label *userp)
20354 ++{
20355 ++ struct acl_object_label o_tmp;
20356 ++ __u32 num = 0;
20357 ++
20358 ++ while (userp) {
20359 ++ if (copy_from_user(&o_tmp, userp,
20360 ++ sizeof (struct acl_object_label)))
20361 ++ break;
20362 ++
20363 ++ userp = o_tmp.prev;
20364 ++ num++;
20365 ++ }
20366 ++
20367 ++ return num;
20368 ++}
20369 ++
20370 ++static struct acl_subject_label *
20371 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
20372 ++
20373 ++static int
20374 ++copy_user_glob(struct acl_object_label *obj)
20375 ++{
20376 ++ struct acl_object_label *g_tmp, **guser;
20377 ++ unsigned int len;
20378 ++ char *tmp;
20379 ++
20380 ++ if (obj->globbed == NULL)
20381 ++ return 0;
20382 ++
20383 ++ guser = &obj->globbed;
20384 ++ while (*guser) {
20385 ++ g_tmp = (struct acl_object_label *)
20386 ++ acl_alloc(sizeof (struct acl_object_label));
20387 ++ if (g_tmp == NULL)
20388 ++ return -ENOMEM;
20389 ++
20390 ++ if (copy_from_user(g_tmp, *guser,
20391 ++ sizeof (struct acl_object_label)))
20392 ++ return -EFAULT;
20393 ++
20394 ++ len = strnlen_user(g_tmp->filename, PATH_MAX);
20395 ++
20396 ++ if (!len || len >= PATH_MAX)
20397 ++ return -EINVAL;
20398 ++
20399 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
20400 ++ return -ENOMEM;
20401 ++
20402 ++ if (copy_from_user(tmp, g_tmp->filename, len))
20403 ++ return -EFAULT;
20404 ++
20405 ++ g_tmp->filename = tmp;
20406 ++
20407 ++ *guser = g_tmp;
20408 ++ guser = &(g_tmp->next);
20409 ++ }
20410 ++
20411 ++ return 0;
20412 ++}
20413 ++
20414 ++static int
20415 ++copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
20416 ++ struct acl_role_label *role)
20417 ++{
20418 ++ struct acl_object_label *o_tmp;
20419 ++ unsigned int len;
20420 ++ int ret;
20421 ++ char *tmp;
20422 ++
20423 ++ while (userp) {
20424 ++ if ((o_tmp = (struct acl_object_label *)
20425 ++ acl_alloc(sizeof (struct acl_object_label))) == NULL)
20426 ++ return -ENOMEM;
20427 ++
20428 ++ if (copy_from_user(o_tmp, userp,
20429 ++ sizeof (struct acl_object_label)))
20430 ++ return -EFAULT;
20431 ++
20432 ++ userp = o_tmp->prev;
20433 ++
20434 ++ len = strnlen_user(o_tmp->filename, PATH_MAX);
20435 ++
20436 ++ if (!len || len >= PATH_MAX)
20437 ++ return -EINVAL;
20438 ++
20439 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
20440 ++ return -ENOMEM;
20441 ++
20442 ++ if (copy_from_user(tmp, o_tmp->filename, len))
20443 ++ return -EFAULT;
20444 ++
20445 ++ o_tmp->filename = tmp;
20446 ++
20447 ++ insert_acl_obj_label(o_tmp, subj);
20448 ++ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
20449 ++ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
20450 ++ return -ENOMEM;
20451 ++
20452 ++ ret = copy_user_glob(o_tmp);
20453 ++ if (ret)
20454 ++ return ret;
20455 ++
20456 ++ if (o_tmp->nested) {
20457 ++ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
20458 ++ if (IS_ERR(o_tmp->nested))
20459 ++ return PTR_ERR(o_tmp->nested);
20460 ++
20461 ++ /* insert into nested subject list */
20462 ++ o_tmp->nested->next = role->hash->first;
20463 ++ role->hash->first = o_tmp->nested;
20464 ++ }
20465 ++ }
20466 ++
20467 ++ return 0;
20468 ++}
20469 ++
20470 ++static __u32
20471 ++count_user_subjs(struct acl_subject_label *userp)
20472 ++{
20473 ++ struct acl_subject_label s_tmp;
20474 ++ __u32 num = 0;
20475 ++
20476 ++ while (userp) {
20477 ++ if (copy_from_user(&s_tmp, userp,
20478 ++ sizeof (struct acl_subject_label)))
20479 ++ break;
20480 ++
20481 ++ userp = s_tmp.prev;
20482 ++ /* do not count nested subjects against this count, since
20483 ++ they are not included in the hash table, but are
20484 ++ attached to objects. We have already counted
20485 ++ the subjects in userspace for the allocation
20486 ++ stack
20487 ++ */
20488 ++ if (!(s_tmp.mode & GR_NESTED))
20489 ++ num++;
20490 ++ }
20491 ++
20492 ++ return num;
20493 ++}
20494 ++
20495 ++static int
20496 ++copy_user_allowedips(struct acl_role_label *rolep)
20497 ++{
20498 ++ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
20499 ++
20500 ++ ruserip = rolep->allowed_ips;
20501 ++
20502 ++ while (ruserip) {
20503 ++ rlast = rtmp;
20504 ++
20505 ++ if ((rtmp = (struct role_allowed_ip *)
20506 ++ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
20507 ++ return -ENOMEM;
20508 ++
20509 ++ if (copy_from_user(rtmp, ruserip,
20510 ++ sizeof (struct role_allowed_ip)))
20511 ++ return -EFAULT;
20512 ++
20513 ++ ruserip = rtmp->prev;
20514 ++
20515 ++ if (!rlast) {
20516 ++ rtmp->prev = NULL;
20517 ++ rolep->allowed_ips = rtmp;
20518 ++ } else {
20519 ++ rlast->next = rtmp;
20520 ++ rtmp->prev = rlast;
20521 ++ }
20522 ++
20523 ++ if (!ruserip)
20524 ++ rtmp->next = NULL;
20525 ++ }
20526 ++
20527 ++ return 0;
20528 ++}
20529 ++
20530 ++static int
20531 ++copy_user_transitions(struct acl_role_label *rolep)
20532 ++{
20533 ++ struct role_transition *rusertp, *rtmp = NULL, *rlast;
20534 ++
20535 ++ unsigned int len;
20536 ++ char *tmp;
20537 ++
20538 ++ rusertp = rolep->transitions;
20539 ++
20540 ++ while (rusertp) {
20541 ++ rlast = rtmp;
20542 ++
20543 ++ if ((rtmp = (struct role_transition *)
20544 ++ acl_alloc(sizeof (struct role_transition))) == NULL)
20545 ++ return -ENOMEM;
20546 ++
20547 ++ if (copy_from_user(rtmp, rusertp,
20548 ++ sizeof (struct role_transition)))
20549 ++ return -EFAULT;
20550 ++
20551 ++ rusertp = rtmp->prev;
20552 ++
20553 ++ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
20554 ++
20555 ++ if (!len || len >= GR_SPROLE_LEN)
20556 ++ return -EINVAL;
20557 ++
20558 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
20559 ++ return -ENOMEM;
20560 ++
20561 ++ if (copy_from_user(tmp, rtmp->rolename, len))
20562 ++ return -EFAULT;
20563 ++
20564 ++ rtmp->rolename = tmp;
20565 ++
20566 ++ if (!rlast) {
20567 ++ rtmp->prev = NULL;
20568 ++ rolep->transitions = rtmp;
20569 ++ } else {
20570 ++ rlast->next = rtmp;
20571 ++ rtmp->prev = rlast;
20572 ++ }
20573 ++
20574 ++ if (!rusertp)
20575 ++ rtmp->next = NULL;
20576 ++ }
20577 ++
20578 ++ return 0;
20579 ++}
20580 ++
20581 ++static struct acl_subject_label *
20582 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
20583 ++{
20584 ++ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
20585 ++ unsigned int len;
20586 ++ char *tmp;
20587 ++ __u32 num_objs;
20588 ++ struct acl_ip_label **i_tmp, *i_utmp2;
20589 ++ struct gr_hash_struct ghash;
20590 ++ struct subject_map *subjmap;
20591 ++ unsigned int i_num;
20592 ++ int err;
20593 ++
20594 ++ s_tmp = lookup_subject_map(userp);
20595 ++
20596 ++ /* we've already copied this subject into the kernel, just return
20597 ++ the reference to it, and don't copy it over again
20598 ++ */
20599 ++ if (s_tmp)
20600 ++ return(s_tmp);
20601 ++
20602 ++ if ((s_tmp = (struct acl_subject_label *)
20603 ++ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
20604 ++ return ERR_PTR(-ENOMEM);
20605 ++
20606 ++ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
20607 ++ if (subjmap == NULL)
20608 ++ return ERR_PTR(-ENOMEM);
20609 ++
20610 ++ subjmap->user = userp;
20611 ++ subjmap->kernel = s_tmp;
20612 ++ insert_subj_map_entry(subjmap);
20613 ++
20614 ++ if (copy_from_user(s_tmp, userp,
20615 ++ sizeof (struct acl_subject_label)))
20616 ++ return ERR_PTR(-EFAULT);
20617 ++
20618 ++ len = strnlen_user(s_tmp->filename, PATH_MAX);
20619 ++
20620 ++ if (!len || len >= PATH_MAX)
20621 ++ return ERR_PTR(-EINVAL);
20622 ++
20623 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
20624 ++ return ERR_PTR(-ENOMEM);
20625 ++
20626 ++ if (copy_from_user(tmp, s_tmp->filename, len))
20627 ++ return ERR_PTR(-EFAULT);
20628 ++
20629 ++ s_tmp->filename = tmp;
20630 ++
20631 ++ if (!strcmp(s_tmp->filename, "/"))
20632 ++ role->root_label = s_tmp;
20633 ++
20634 ++ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
20635 ++ return ERR_PTR(-EFAULT);
20636 ++
20637 ++ /* copy user and group transition tables */
20638 ++
20639 ++ if (s_tmp->user_trans_num) {
20640 ++ uid_t *uidlist;
20641 ++
20642 ++ uidlist = (uid_t *)acl_alloc(s_tmp->user_trans_num * sizeof(uid_t));
20643 ++ if (uidlist == NULL)
20644 ++ return ERR_PTR(-ENOMEM);
20645 ++ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
20646 ++ return ERR_PTR(-EFAULT);
20647 ++
20648 ++ s_tmp->user_transitions = uidlist;
20649 ++ }
20650 ++
20651 ++ if (s_tmp->group_trans_num) {
20652 ++ gid_t *gidlist;
20653 ++
20654 ++ gidlist = (gid_t *)acl_alloc(s_tmp->group_trans_num * sizeof(gid_t));
20655 ++ if (gidlist == NULL)
20656 ++ return ERR_PTR(-ENOMEM);
20657 ++ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
20658 ++ return ERR_PTR(-EFAULT);
20659 ++
20660 ++ s_tmp->group_transitions = gidlist;
20661 ++ }
20662 ++
20663 ++ /* set up object hash table */
20664 ++ num_objs = count_user_objs(ghash.first);
20665 ++
20666 ++ s_tmp->obj_hash_size = num_objs;
20667 ++ s_tmp->obj_hash =
20668 ++ (struct acl_object_label **)
20669 ++ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
20670 ++
20671 ++ if (!s_tmp->obj_hash)
20672 ++ return ERR_PTR(-ENOMEM);
20673 ++
20674 ++ memset(s_tmp->obj_hash, 0,
20675 ++ s_tmp->obj_hash_size *
20676 ++ sizeof (struct acl_object_label *));
20677 ++
20678 ++ /* add in objects */
20679 ++ err = copy_user_objs(ghash.first, s_tmp, role);
20680 ++
20681 ++ if (err)
20682 ++ return ERR_PTR(err);
20683 ++
20684 ++ /* set pointer for parent subject */
20685 ++ if (s_tmp->parent_subject) {
20686 ++ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
20687 ++
20688 ++ if (IS_ERR(s_tmp2))
20689 ++ return s_tmp2;
20690 ++
20691 ++ s_tmp->parent_subject = s_tmp2;
20692 ++ }
20693 ++
20694 ++ /* add in ip acls */
20695 ++
20696 ++ if (!s_tmp->ip_num) {
20697 ++ s_tmp->ips = NULL;
20698 ++ goto insert;
20699 ++ }
20700 ++
20701 ++ i_tmp =
20702 ++ (struct acl_ip_label **) acl_alloc(s_tmp->ip_num *
20703 ++ sizeof (struct
20704 ++ acl_ip_label *));
20705 ++
20706 ++ if (!i_tmp)
20707 ++ return ERR_PTR(-ENOMEM);
20708 ++
20709 ++ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
20710 ++ *(i_tmp + i_num) =
20711 ++ (struct acl_ip_label *)
20712 ++ acl_alloc(sizeof (struct acl_ip_label));
20713 ++ if (!*(i_tmp + i_num))
20714 ++ return ERR_PTR(-ENOMEM);
20715 ++
20716 ++ if (copy_from_user
20717 ++ (&i_utmp2, s_tmp->ips + i_num,
20718 ++ sizeof (struct acl_ip_label *)))
20719 ++ return ERR_PTR(-EFAULT);
20720 ++
20721 ++ if (copy_from_user
20722 ++ (*(i_tmp + i_num), i_utmp2,
20723 ++ sizeof (struct acl_ip_label)))
20724 ++ return ERR_PTR(-EFAULT);
20725 ++
20726 ++ if ((*(i_tmp + i_num))->iface == NULL)
20727 ++ continue;
20728 ++
20729 ++ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
20730 ++ if (!len || len >= IFNAMSIZ)
20731 ++ return ERR_PTR(-EINVAL);
20732 ++ tmp = acl_alloc(len);
20733 ++ if (tmp == NULL)
20734 ++ return ERR_PTR(-ENOMEM);
20735 ++ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
20736 ++ return ERR_PTR(-EFAULT);
20737 ++ (*(i_tmp + i_num))->iface = tmp;
20738 ++ }
20739 ++
20740 ++ s_tmp->ips = i_tmp;
20741 ++
20742 ++insert:
20743 ++ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
20744 ++ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
20745 ++ return ERR_PTR(-ENOMEM);
20746 ++
20747 ++ return s_tmp;
20748 ++}
20749 ++
20750 ++static int
20751 ++copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
20752 ++{
20753 ++ struct acl_subject_label s_pre;
20754 ++ struct acl_subject_label * ret;
20755 ++ int err;
20756 ++
20757 ++ while (userp) {
20758 ++ if (copy_from_user(&s_pre, userp,
20759 ++ sizeof (struct acl_subject_label)))
20760 ++ return -EFAULT;
20761 ++
20762 ++ /* do not add nested subjects here, add
20763 ++ while parsing objects
20764 ++ */
20765 ++
20766 ++ if (s_pre.mode & GR_NESTED) {
20767 ++ userp = s_pre.prev;
20768 ++ continue;
20769 ++ }
20770 ++
20771 ++ ret = do_copy_user_subj(userp, role);
20772 ++
20773 ++ err = PTR_ERR(ret);
20774 ++ if (IS_ERR(ret))
20775 ++ return err;
20776 ++
20777 ++ insert_acl_subj_label(ret, role);
20778 ++
20779 ++ userp = s_pre.prev;
20780 ++ }
20781 ++
20782 ++ return 0;
20783 ++}
20784 ++
20785 ++static int
20786 ++copy_user_acl(struct gr_arg *arg)
20787 ++{
20788 ++ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
20789 ++ struct sprole_pw *sptmp;
20790 ++ struct gr_hash_struct *ghash;
20791 ++ uid_t *domainlist;
20792 ++ unsigned int r_num;
20793 ++ unsigned int len;
20794 ++ char *tmp;
20795 ++ int err = 0;
20796 ++ __u16 i;
20797 ++ __u32 num_subjs;
20798 ++
20799 ++ /* we need a default and kernel role */
20800 ++ if (arg->role_db.num_roles < 2)
20801 ++ return -EINVAL;
20802 ++
20803 ++ /* copy special role authentication info from userspace */
20804 ++
20805 ++ num_sprole_pws = arg->num_sprole_pws;
20806 ++ acl_special_roles = (struct sprole_pw **) acl_alloc(num_sprole_pws * sizeof(struct sprole_pw *));
20807 ++
20808 ++ if (!acl_special_roles) {
20809 ++ err = -ENOMEM;
20810 ++ goto cleanup;
20811 ++ }
20812 ++
20813 ++ for (i = 0; i < num_sprole_pws; i++) {
20814 ++ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
20815 ++ if (!sptmp) {
20816 ++ err = -ENOMEM;
20817 ++ goto cleanup;
20818 ++ }
20819 ++ if (copy_from_user(sptmp, arg->sprole_pws + i,
20820 ++ sizeof (struct sprole_pw))) {
20821 ++ err = -EFAULT;
20822 ++ goto cleanup;
20823 ++ }
20824 ++
20825 ++ len =
20826 ++ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
20827 ++
20828 ++ if (!len || len >= GR_SPROLE_LEN) {
20829 ++ err = -EINVAL;
20830 ++ goto cleanup;
20831 ++ }
20832 ++
20833 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
20834 ++ err = -ENOMEM;
20835 ++ goto cleanup;
20836 ++ }
20837 ++
20838 ++ if (copy_from_user(tmp, sptmp->rolename, len)) {
20839 ++ err = -EFAULT;
20840 ++ goto cleanup;
20841 ++ }
20842 ++
20843 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
20844 ++ printk(KERN_ALERT "Copying special role %s\n", tmp);
20845 ++#endif
20846 ++ sptmp->rolename = tmp;
20847 ++ acl_special_roles[i] = sptmp;
20848 ++ }
20849 ++
20850 ++ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
20851 ++
20852 ++ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
20853 ++ r_tmp = acl_alloc(sizeof (struct acl_role_label));
20854 ++
20855 ++ if (!r_tmp) {
20856 ++ err = -ENOMEM;
20857 ++ goto cleanup;
20858 ++ }
20859 ++
20860 ++ if (copy_from_user(&r_utmp2, r_utmp + r_num,
20861 ++ sizeof (struct acl_role_label *))) {
20862 ++ err = -EFAULT;
20863 ++ goto cleanup;
20864 ++ }
20865 ++
20866 ++ if (copy_from_user(r_tmp, r_utmp2,
20867 ++ sizeof (struct acl_role_label))) {
20868 ++ err = -EFAULT;
20869 ++ goto cleanup;
20870 ++ }
20871 ++
20872 ++ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
20873 ++
20874 ++ if (!len || len >= PATH_MAX) {
20875 ++ err = -EINVAL;
20876 ++ goto cleanup;
20877 ++ }
20878 ++
20879 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
20880 ++ err = -ENOMEM;
20881 ++ goto cleanup;
20882 ++ }
20883 ++ if (copy_from_user(tmp, r_tmp->rolename, len)) {
20884 ++ err = -EFAULT;
20885 ++ goto cleanup;
20886 ++ }
20887 ++ r_tmp->rolename = tmp;
20888 ++
20889 ++ if (!strcmp(r_tmp->rolename, "default")
20890 ++ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
20891 ++ default_role = r_tmp;
20892 ++ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
20893 ++ kernel_role = r_tmp;
20894 ++ }
20895 ++
20896 ++ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
20897 ++ err = -ENOMEM;
20898 ++ goto cleanup;
20899 ++ }
20900 ++ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
20901 ++ err = -EFAULT;
20902 ++ goto cleanup;
20903 ++ }
20904 ++
20905 ++ r_tmp->hash = ghash;
20906 ++
20907 ++ num_subjs = count_user_subjs(r_tmp->hash->first);
20908 ++
20909 ++ r_tmp->subj_hash_size = num_subjs;
20910 ++ r_tmp->subj_hash =
20911 ++ (struct acl_subject_label **)
20912 ++ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
20913 ++
20914 ++ if (!r_tmp->subj_hash) {
20915 ++ err = -ENOMEM;
20916 ++ goto cleanup;
20917 ++ }
20918 ++
20919 ++ err = copy_user_allowedips(r_tmp);
20920 ++ if (err)
20921 ++ goto cleanup;
20922 ++
20923 ++ /* copy domain info */
20924 ++ if (r_tmp->domain_children != NULL) {
20925 ++ domainlist = acl_alloc(r_tmp->domain_child_num * sizeof(uid_t));
20926 ++ if (domainlist == NULL) {
20927 ++ err = -ENOMEM;
20928 ++ goto cleanup;
20929 ++ }
20930 ++ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
20931 ++ err = -EFAULT;
20932 ++ goto cleanup;
20933 ++ }
20934 ++ r_tmp->domain_children = domainlist;
20935 ++ }
20936 ++
20937 ++ err = copy_user_transitions(r_tmp);
20938 ++ if (err)
20939 ++ goto cleanup;
20940 ++
20941 ++ memset(r_tmp->subj_hash, 0,
20942 ++ r_tmp->subj_hash_size *
20943 ++ sizeof (struct acl_subject_label *));
20944 ++
20945 ++ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
20946 ++
20947 ++ if (err)
20948 ++ goto cleanup;
20949 ++
20950 ++ /* set nested subject list to null */
20951 ++ r_tmp->hash->first = NULL;
20952 ++
20953 ++ insert_acl_role_label(r_tmp);
20954 ++ }
20955 ++
20956 ++ goto return_err;
20957 ++ cleanup:
20958 ++ free_variables();
20959 ++ return_err:
20960 ++ return err;
20961 ++
20962 ++}
20963 ++
20964 ++static int
20965 ++gracl_init(struct gr_arg *args)
20966 ++{
20967 ++ int error = 0;
20968 ++
20969 ++ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
20970 ++ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
20971 ++
20972 ++ if (init_variables(args)) {
20973 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
20974 ++ error = -ENOMEM;
20975 ++ free_variables();
20976 ++ goto out;
20977 ++ }
20978 ++
20979 ++ error = copy_user_acl(args);
20980 ++ free_init_variables();
20981 ++ if (error) {
20982 ++ free_variables();
20983 ++ goto out;
20984 ++ }
20985 ++
20986 ++ if ((error = gr_set_acls(0))) {
20987 ++ free_variables();
20988 ++ goto out;
20989 ++ }
20990 ++
20991 ++ gr_status |= GR_READY;
20992 ++ out:
20993 ++ return error;
20994 ++}
20995 ++
20996 ++/* derived from glibc fnmatch() 0: match, 1: no match*/
20997 ++
20998 ++static int
20999 ++glob_match(const char *p, const char *n)
21000 ++{
21001 ++ char c;
21002 ++
21003 ++ while ((c = *p++) != '\0') {
21004 ++ switch (c) {
21005 ++ case '?':
21006 ++ if (*n == '\0')
21007 ++ return 1;
21008 ++ else if (*n == '/')
21009 ++ return 1;
21010 ++ break;
21011 ++ case '\\':
21012 ++ if (*n != c)
21013 ++ return 1;
21014 ++ break;
21015 ++ case '*':
21016 ++ for (c = *p++; c == '?' || c == '*'; c = *p++) {
21017 ++ if (*n == '/')
21018 ++ return 1;
21019 ++ else if (c == '?') {
21020 ++ if (*n == '\0')
21021 ++ return 1;
21022 ++ else
21023 ++ ++n;
21024 ++ }
21025 ++ }
21026 ++ if (c == '\0') {
21027 ++ return 0;
21028 ++ } else {
21029 ++ const char *endp;
21030 ++
21031 ++ if ((endp = strchr(n, '/')) == NULL)
21032 ++ endp = n + strlen(n);
21033 ++
21034 ++ if (c == '[') {
21035 ++ for (--p; n < endp; ++n)
21036 ++ if (!glob_match(p, n))
21037 ++ return 0;
21038 ++ } else if (c == '/') {
21039 ++ while (*n != '\0' && *n != '/')
21040 ++ ++n;
21041 ++ if (*n == '/' && !glob_match(p, n + 1))
21042 ++ return 0;
21043 ++ } else {
21044 ++ for (--p; n < endp; ++n)
21045 ++ if (*n == c && !glob_match(p, n))
21046 ++ return 0;
21047 ++ }
21048 ++
21049 ++ return 1;
21050 ++ }
21051 ++ case '[':
21052 ++ {
21053 ++ int not;
21054 ++ char cold;
21055 ++
21056 ++ if (*n == '\0' || *n == '/')
21057 ++ return 1;
21058 ++
21059 ++ not = (*p == '!' || *p == '^');
21060 ++ if (not)
21061 ++ ++p;
21062 ++
21063 ++ c = *p++;
21064 ++ for (;;) {
21065 ++ unsigned char fn = (unsigned char)*n;
21066 ++
21067 ++ if (c == '\0')
21068 ++ return 1;
21069 ++ else {
21070 ++ if (c == fn)
21071 ++ goto matched;
21072 ++ cold = c;
21073 ++ c = *p++;
21074 ++
21075 ++ if (c == '-' && *p != ']') {
21076 ++ unsigned char cend = *p++;
21077 ++
21078 ++ if (cend == '\0')
21079 ++ return 1;
21080 ++
21081 ++ if (cold <= fn && fn <= cend)
21082 ++ goto matched;
21083 ++
21084 ++ c = *p++;
21085 ++ }
21086 ++ }
21087 ++
21088 ++ if (c == ']')
21089 ++ break;
21090 ++ }
21091 ++ if (!not)
21092 ++ return 1;
21093 ++ break;
21094 ++ matched:
21095 ++ while (c != ']') {
21096 ++ if (c == '\0')
21097 ++ return 1;
21098 ++
21099 ++ c = *p++;
21100 ++ }
21101 ++ if (not)
21102 ++ return 1;
21103 ++ }
21104 ++ break;
21105 ++ default:
21106 ++ if (c != *n)
21107 ++ return 1;
21108 ++ }
21109 ++
21110 ++ ++n;
21111 ++ }
21112 ++
21113 ++ if (*n == '\0')
21114 ++ return 0;
21115 ++
21116 ++ if (*n == '/')
21117 ++ return 0;
21118 ++
21119 ++ return 1;
21120 ++}
21121 ++
21122 ++static struct acl_object_label *
21123 ++chk_glob_label(struct acl_object_label *globbed,
21124 ++ struct dentry *dentry, struct vfsmount *mnt, char **path)
21125 ++{
21126 ++ struct acl_object_label *tmp;
21127 ++
21128 ++ if (*path == NULL)
21129 ++ *path = gr_to_filename_nolock(dentry, mnt);
21130 ++
21131 ++ tmp = globbed;
21132 ++
21133 ++ while (tmp) {
21134 ++ if (!glob_match(tmp->filename, *path))
21135 ++ return tmp;
21136 ++ tmp = tmp->next;
21137 ++ }
21138 ++
21139 ++ return NULL;
21140 ++}
21141 ++
21142 ++static struct acl_object_label *
21143 ++__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
21144 ++ const ino_t curr_ino, const dev_t curr_dev,
21145 ++ const struct acl_subject_label *subj, char **path)
21146 ++{
21147 ++ struct acl_subject_label *tmpsubj;
21148 ++ struct acl_object_label *retval;
21149 ++ struct acl_object_label *retval2;
21150 ++
21151 ++ tmpsubj = (struct acl_subject_label *) subj;
21152 ++ read_lock(&gr_inode_lock);
21153 ++ do {
21154 ++ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
21155 ++ if (retval) {
21156 ++ if (retval->globbed) {
21157 ++ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
21158 ++ (struct vfsmount *)orig_mnt, path);
21159 ++ if (retval2)
21160 ++ retval = retval2;
21161 ++ }
21162 ++ break;
21163 ++ }
21164 ++ } while ((tmpsubj = tmpsubj->parent_subject));
21165 ++ read_unlock(&gr_inode_lock);
21166 ++
21167 ++ return retval;
21168 ++}
21169 ++
21170 ++static __inline__ struct acl_object_label *
21171 ++full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
21172 ++ const struct dentry *curr_dentry,
21173 ++ const struct acl_subject_label *subj, char **path)
21174 ++{
21175 ++ return __full_lookup(orig_dentry, orig_mnt,
21176 ++ curr_dentry->d_inode->i_ino,
21177 ++ curr_dentry->d_inode->i_sb->s_dev, subj, path);
21178 ++}
21179 ++
21180 ++static struct acl_object_label *
21181 ++__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
21182 ++ const struct acl_subject_label *subj, char *path)
21183 ++{
21184 ++ struct dentry *dentry = (struct dentry *) l_dentry;
21185 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
21186 ++ struct acl_object_label *retval;
21187 ++
21188 ++ spin_lock(&dcache_lock);
21189 ++
21190 ++ if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
21191 ++ /* ignore Eric Biederman */
21192 ++ IS_PRIVATE(l_dentry->d_inode))) {
21193 ++ retval = fakefs_obj;
21194 ++ goto out;
21195 ++ }
21196 ++
21197 ++ for (;;) {
21198 ++ if (dentry == real_root && mnt == real_root_mnt)
21199 ++ break;
21200 ++
21201 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
21202 ++ if (mnt->mnt_parent == mnt)
21203 ++ break;
21204 ++
21205 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
21206 ++ if (retval != NULL)
21207 ++ goto out;
21208 ++
21209 ++ dentry = mnt->mnt_mountpoint;
21210 ++ mnt = mnt->mnt_parent;
21211 ++ continue;
21212 ++ }
21213 ++
21214 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
21215 ++ if (retval != NULL)
21216 ++ goto out;
21217 ++
21218 ++ dentry = dentry->d_parent;
21219 ++ }
21220 ++
21221 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
21222 ++
21223 ++ if (retval == NULL)
21224 ++ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path);
21225 ++out:
21226 ++ spin_unlock(&dcache_lock);
21227 ++ return retval;
21228 ++}
21229 ++
21230 ++static __inline__ struct acl_object_label *
21231 ++chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
21232 ++ const struct acl_subject_label *subj)
21233 ++{
21234 ++ char *path = NULL;
21235 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
21236 ++}
21237 ++
21238 ++static __inline__ struct acl_object_label *
21239 ++chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
21240 ++ const struct acl_subject_label *subj, char *path)
21241 ++{
21242 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
21243 ++}
21244 ++
21245 ++static struct acl_subject_label *
21246 ++chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
21247 ++ const struct acl_role_label *role)
21248 ++{
21249 ++ struct dentry *dentry = (struct dentry *) l_dentry;
21250 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
21251 ++ struct acl_subject_label *retval;
21252 ++
21253 ++ spin_lock(&dcache_lock);
21254 ++
21255 ++ for (;;) {
21256 ++ if (dentry == real_root && mnt == real_root_mnt)
21257 ++ break;
21258 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
21259 ++ if (mnt->mnt_parent == mnt)
21260 ++ break;
21261 ++
21262 ++ read_lock(&gr_inode_lock);
21263 ++ retval =
21264 ++ lookup_acl_subj_label(dentry->d_inode->i_ino,
21265 ++ dentry->d_inode->i_sb->s_dev, role);
21266 ++ read_unlock(&gr_inode_lock);
21267 ++ if (retval != NULL)
21268 ++ goto out;
21269 ++
21270 ++ dentry = mnt->mnt_mountpoint;
21271 ++ mnt = mnt->mnt_parent;
21272 ++ continue;
21273 ++ }
21274 ++
21275 ++ read_lock(&gr_inode_lock);
21276 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
21277 ++ dentry->d_inode->i_sb->s_dev, role);
21278 ++ read_unlock(&gr_inode_lock);
21279 ++ if (retval != NULL)
21280 ++ goto out;
21281 ++
21282 ++ dentry = dentry->d_parent;
21283 ++ }
21284 ++
21285 ++ read_lock(&gr_inode_lock);
21286 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
21287 ++ dentry->d_inode->i_sb->s_dev, role);
21288 ++ read_unlock(&gr_inode_lock);
21289 ++
21290 ++ if (unlikely(retval == NULL)) {
21291 ++ read_lock(&gr_inode_lock);
21292 ++ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
21293 ++ real_root->d_inode->i_sb->s_dev, role);
21294 ++ read_unlock(&gr_inode_lock);
21295 ++ }
21296 ++out:
21297 ++ spin_unlock(&dcache_lock);
21298 ++
21299 ++ return retval;
21300 ++}
21301 ++
21302 ++static void
21303 ++gr_log_learn(const struct task_struct *task, const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
21304 ++{
21305 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
21306 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
21307 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
21308 ++ 1, 1, gr_to_filename(dentry, mnt), (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
21309 ++
21310 ++ return;
21311 ++}
21312 ++
21313 ++static void
21314 ++gr_log_learn_sysctl(const struct task_struct *task, const char *path, const __u32 mode)
21315 ++{
21316 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
21317 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
21318 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
21319 ++ 1, 1, path, (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
21320 ++
21321 ++ return;
21322 ++}
21323 ++
21324 ++static void
21325 ++gr_log_learn_id_change(const struct task_struct *task, const char type, const unsigned int real,
21326 ++ const unsigned int effective, const unsigned int fs)
21327 ++{
21328 ++ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
21329 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
21330 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
21331 ++ type, real, effective, fs, NIPQUAD(task->signal->curr_ip));
21332 ++
21333 ++ return;
21334 ++}
21335 ++
21336 ++__u32
21337 ++gr_check_link(const struct dentry * new_dentry,
21338 ++ const struct dentry * parent_dentry,
21339 ++ const struct vfsmount * parent_mnt,
21340 ++ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
21341 ++{
21342 ++ struct acl_object_label *obj;
21343 ++ __u32 oldmode, newmode;
21344 ++ __u32 needmode;
21345 ++
21346 ++ if (unlikely(!(gr_status & GR_READY)))
21347 ++ return (GR_CREATE | GR_LINK);
21348 ++
21349 ++ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
21350 ++ oldmode = obj->mode;
21351 ++
21352 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
21353 ++ oldmode |= (GR_CREATE | GR_LINK);
21354 ++
21355 ++ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
21356 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
21357 ++ needmode |= GR_SETID | GR_AUDIT_SETID;
21358 ++
21359 ++ newmode =
21360 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
21361 ++ oldmode | needmode);
21362 ++
21363 ++ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
21364 ++ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
21365 ++ GR_INHERIT | GR_AUDIT_INHERIT);
21366 ++
21367 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
21368 ++ goto bad;
21369 ++
21370 ++ if ((oldmode & needmode) != needmode)
21371 ++ goto bad;
21372 ++
21373 ++ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
21374 ++ if ((newmode & needmode) != needmode)
21375 ++ goto bad;
21376 ++
21377 ++ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
21378 ++ return newmode;
21379 ++bad:
21380 ++ needmode = oldmode;
21381 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
21382 ++ needmode |= GR_SETID;
21383 ++
21384 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
21385 ++ gr_log_learn(current, old_dentry, old_mnt, needmode);
21386 ++ return (GR_CREATE | GR_LINK);
21387 ++ } else if (newmode & GR_SUPPRESS)
21388 ++ return GR_SUPPRESS;
21389 ++ else
21390 ++ return 0;
21391 ++}
21392 ++
21393 ++__u32
21394 ++gr_search_file(const struct dentry * dentry, const __u32 mode,
21395 ++ const struct vfsmount * mnt)
21396 ++{
21397 ++ __u32 retval = mode;
21398 ++ struct acl_subject_label *curracl;
21399 ++ struct acl_object_label *currobj;
21400 ++
21401 ++ if (unlikely(!(gr_status & GR_READY)))
21402 ++ return (mode & ~GR_AUDITS);
21403 ++
21404 ++ curracl = current->acl;
21405 ++
21406 ++ currobj = chk_obj_label(dentry, mnt, curracl);
21407 ++ retval = currobj->mode & mode;
21408 ++
21409 ++ if (unlikely
21410 ++ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
21411 ++ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
21412 ++ __u32 new_mode = mode;
21413 ++
21414 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
21415 ++
21416 ++ retval = new_mode;
21417 ++
21418 ++ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
21419 ++ new_mode |= GR_INHERIT;
21420 ++
21421 ++ if (!(mode & GR_NOLEARN))
21422 ++ gr_log_learn(current, dentry, mnt, new_mode);
21423 ++ }
21424 ++
21425 ++ return retval;
21426 ++}
21427 ++
21428 ++__u32
21429 ++gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
21430 ++ const struct vfsmount * mnt, const __u32 mode)
21431 ++{
21432 ++ struct name_entry *match;
21433 ++ struct acl_object_label *matchpo;
21434 ++ struct acl_subject_label *curracl;
21435 ++ char *path;
21436 ++ __u32 retval;
21437 ++
21438 ++ if (unlikely(!(gr_status & GR_READY)))
21439 ++ return (mode & ~GR_AUDITS);
21440 ++
21441 ++ preempt_disable();
21442 ++ path = gr_to_filename_rbac(new_dentry, mnt);
21443 ++ match = lookup_name_entry_create(path);
21444 ++
21445 ++ if (!match)
21446 ++ goto check_parent;
21447 ++
21448 ++ curracl = current->acl;
21449 ++
21450 ++ read_lock(&gr_inode_lock);
21451 ++ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
21452 ++ read_unlock(&gr_inode_lock);
21453 ++
21454 ++ if (matchpo) {
21455 ++ if ((matchpo->mode & mode) !=
21456 ++ (mode & ~(GR_AUDITS | GR_SUPPRESS))
21457 ++ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
21458 ++ __u32 new_mode = mode;
21459 ++
21460 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
21461 ++
21462 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
21463 ++
21464 ++ preempt_enable();
21465 ++ return new_mode;
21466 ++ }
21467 ++ preempt_enable();
21468 ++ return (matchpo->mode & mode);
21469 ++ }
21470 ++
21471 ++ check_parent:
21472 ++ curracl = current->acl;
21473 ++
21474 ++ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
21475 ++ retval = matchpo->mode & mode;
21476 ++
21477 ++ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
21478 ++ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
21479 ++ __u32 new_mode = mode;
21480 ++
21481 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
21482 ++
21483 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
21484 ++ preempt_enable();
21485 ++ return new_mode;
21486 ++ }
21487 ++
21488 ++ preempt_enable();
21489 ++ return retval;
21490 ++}
21491 ++
21492 ++int
21493 ++gr_check_hidden_task(const struct task_struct *task)
21494 ++{
21495 ++ if (unlikely(!(gr_status & GR_READY)))
21496 ++ return 0;
21497 ++
21498 ++ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
21499 ++ return 1;
21500 ++
21501 ++ return 0;
21502 ++}
21503 ++
21504 ++int
21505 ++gr_check_protected_task(const struct task_struct *task)
21506 ++{
21507 ++ if (unlikely(!(gr_status & GR_READY) || !task))
21508 ++ return 0;
21509 ++
21510 ++ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
21511 ++ task->acl != current->acl)
21512 ++ return 1;
21513 ++
21514 ++ return 0;
21515 ++}
21516 ++
21517 ++void
21518 ++gr_copy_label(struct task_struct *tsk)
21519 ++{
21520 ++ tsk->signal->used_accept = 0;
21521 ++ tsk->acl_sp_role = 0;
21522 ++ tsk->acl_role_id = current->acl_role_id;
21523 ++ tsk->acl = current->acl;
21524 ++ tsk->role = current->role;
21525 ++ tsk->signal->curr_ip = current->signal->curr_ip;
21526 ++ if (current->exec_file)
21527 ++ get_file(current->exec_file);
21528 ++ tsk->exec_file = current->exec_file;
21529 ++ tsk->is_writable = current->is_writable;
21530 ++ if (unlikely(current->signal->used_accept))
21531 ++ current->signal->curr_ip = 0;
21532 ++
21533 ++ return;
21534 ++}
21535 ++
21536 ++static void
21537 ++gr_set_proc_res(struct task_struct *task)
21538 ++{
21539 ++ struct acl_subject_label *proc;
21540 ++ unsigned short i;
21541 ++
21542 ++ proc = task->acl;
21543 ++
21544 ++ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
21545 ++ return;
21546 ++
21547 ++ for (i = 0; i < (GR_NLIMITS - 1); i++) {
21548 ++ if (!(proc->resmask & (1 << i)))
21549 ++ continue;
21550 ++
21551 ++ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
21552 ++ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
21553 ++ }
21554 ++
21555 ++ return;
21556 ++}
21557 ++
21558 ++int
21559 ++gr_check_user_change(int real, int effective, int fs)
21560 ++{
21561 ++ unsigned int i;
21562 ++ __u16 num;
21563 ++ uid_t *uidlist;
21564 ++ int curuid;
21565 ++ int realok = 0;
21566 ++ int effectiveok = 0;
21567 ++ int fsok = 0;
21568 ++
21569 ++ if (unlikely(!(gr_status & GR_READY)))
21570 ++ return 0;
21571 ++
21572 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
21573 ++ gr_log_learn_id_change(current, 'u', real, effective, fs);
21574 ++
21575 ++ num = current->acl->user_trans_num;
21576 ++ uidlist = current->acl->user_transitions;
21577 ++
21578 ++ if (uidlist == NULL)
21579 ++ return 0;
21580 ++
21581 ++ if (real == -1)
21582 ++ realok = 1;
21583 ++ if (effective == -1)
21584 ++ effectiveok = 1;
21585 ++ if (fs == -1)
21586 ++ fsok = 1;
21587 ++
21588 ++ if (current->acl->user_trans_type & GR_ID_ALLOW) {
21589 ++ for (i = 0; i < num; i++) {
21590 ++ curuid = (int)uidlist[i];
21591 ++ if (real == curuid)
21592 ++ realok = 1;
21593 ++ if (effective == curuid)
21594 ++ effectiveok = 1;
21595 ++ if (fs == curuid)
21596 ++ fsok = 1;
21597 ++ }
21598 ++ } else if (current->acl->user_trans_type & GR_ID_DENY) {
21599 ++ for (i = 0; i < num; i++) {
21600 ++ curuid = (int)uidlist[i];
21601 ++ if (real == curuid)
21602 ++ break;
21603 ++ if (effective == curuid)
21604 ++ break;
21605 ++ if (fs == curuid)
21606 ++ break;
21607 ++ }
21608 ++ /* not in deny list */
21609 ++ if (i == num) {
21610 ++ realok = 1;
21611 ++ effectiveok = 1;
21612 ++ fsok = 1;
21613 ++ }
21614 ++ }
21615 ++
21616 ++ if (realok && effectiveok && fsok)
21617 ++ return 0;
21618 ++ else {
21619 ++ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
21620 ++ return 1;
21621 ++ }
21622 ++}
21623 ++
21624 ++int
21625 ++gr_check_group_change(int real, int effective, int fs)
21626 ++{
21627 ++ unsigned int i;
21628 ++ __u16 num;
21629 ++ gid_t *gidlist;
21630 ++ int curgid;
21631 ++ int realok = 0;
21632 ++ int effectiveok = 0;
21633 ++ int fsok = 0;
21634 ++
21635 ++ if (unlikely(!(gr_status & GR_READY)))
21636 ++ return 0;
21637 ++
21638 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
21639 ++ gr_log_learn_id_change(current, 'g', real, effective, fs);
21640 ++
21641 ++ num = current->acl->group_trans_num;
21642 ++ gidlist = current->acl->group_transitions;
21643 ++
21644 ++ if (gidlist == NULL)
21645 ++ return 0;
21646 ++
21647 ++ if (real == -1)
21648 ++ realok = 1;
21649 ++ if (effective == -1)
21650 ++ effectiveok = 1;
21651 ++ if (fs == -1)
21652 ++ fsok = 1;
21653 ++
21654 ++ if (current->acl->group_trans_type & GR_ID_ALLOW) {
21655 ++ for (i = 0; i < num; i++) {
21656 ++ curgid = (int)gidlist[i];
21657 ++ if (real == curgid)
21658 ++ realok = 1;
21659 ++ if (effective == curgid)
21660 ++ effectiveok = 1;
21661 ++ if (fs == curgid)
21662 ++ fsok = 1;
21663 ++ }
21664 ++ } else if (current->acl->group_trans_type & GR_ID_DENY) {
21665 ++ for (i = 0; i < num; i++) {
21666 ++ curgid = (int)gidlist[i];
21667 ++ if (real == curgid)
21668 ++ break;
21669 ++ if (effective == curgid)
21670 ++ break;
21671 ++ if (fs == curgid)
21672 ++ break;
21673 ++ }
21674 ++ /* not in deny list */
21675 ++ if (i == num) {
21676 ++ realok = 1;
21677 ++ effectiveok = 1;
21678 ++ fsok = 1;
21679 ++ }
21680 ++ }
21681 ++
21682 ++ if (realok && effectiveok && fsok)
21683 ++ return 0;
21684 ++ else {
21685 ++ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
21686 ++ return 1;
21687 ++ }
21688 ++}
21689 ++
21690 ++void
21691 ++gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
21692 ++{
21693 ++ struct acl_role_label *role = task->role;
21694 ++ struct acl_subject_label *subj = NULL;
21695 ++ struct acl_object_label *obj;
21696 ++ struct file *filp;
21697 ++
21698 ++ if (unlikely(!(gr_status & GR_READY)))
21699 ++ return;
21700 ++
21701 ++ filp = task->exec_file;
21702 ++
21703 ++ /* kernel process, we'll give them the kernel role */
21704 ++ if (unlikely(!filp)) {
21705 ++ task->role = kernel_role;
21706 ++ task->acl = kernel_role->root_label;
21707 ++ return;
21708 ++ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
21709 ++ role = lookup_acl_role_label(task, uid, gid);
21710 ++
21711 ++ /* perform subject lookup in possibly new role
21712 ++ we can use this result below in the case where role == task->role
21713 ++ */
21714 ++ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
21715 ++
21716 ++ /* if we changed uid/gid, but result in the same role
21717 ++ and are using inheritance, don't lose the inherited subject
21718 ++ if current subject is other than what normal lookup
21719 ++ would result in, we arrived via inheritance, don't
21720 ++ lose subject
21721 ++ */
21722 ++ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
21723 ++ (subj == task->acl)))
21724 ++ task->acl = subj;
21725 ++
21726 ++ task->role = role;
21727 ++
21728 ++ task->is_writable = 0;
21729 ++
21730 ++ /* ignore additional mmap checks for processes that are writable
21731 ++ by the default ACL */
21732 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
21733 ++ if (unlikely(obj->mode & GR_WRITE))
21734 ++ task->is_writable = 1;
21735 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
21736 ++ if (unlikely(obj->mode & GR_WRITE))
21737 ++ task->is_writable = 1;
21738 ++
21739 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
21740 ++ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
21741 ++#endif
21742 ++
21743 ++ gr_set_proc_res(task);
21744 ++
21745 ++ return;
21746 ++}
21747 ++
21748 ++int
21749 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
21750 ++{
21751 ++ struct task_struct *task = current;
21752 ++ struct acl_subject_label *newacl;
21753 ++ struct acl_object_label *obj;
21754 ++ __u32 retmode;
21755 ++
21756 ++ if (unlikely(!(gr_status & GR_READY)))
21757 ++ return 0;
21758 ++
21759 ++ newacl = chk_subj_label(dentry, mnt, task->role);
21760 ++
21761 ++ task_lock(task);
21762 ++ if (((task->ptrace & PT_PTRACED) && !(task->acl->mode &
21763 ++ GR_POVERRIDE) && (task->acl != newacl) &&
21764 ++ !(task->role->roletype & GR_ROLE_GOD) &&
21765 ++ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
21766 ++ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) ||
21767 ++ (atomic_read(&task->fs->count) > 1 ||
21768 ++ atomic_read(&task->files->count) > 1 ||
21769 ++ atomic_read(&task->sighand->count) > 1)) {
21770 ++ task_unlock(task);
21771 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
21772 ++ return -EACCES;
21773 ++ }
21774 ++ task_unlock(task);
21775 ++
21776 ++ obj = chk_obj_label(dentry, mnt, task->acl);
21777 ++ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
21778 ++
21779 ++ if (!(task->acl->mode & GR_INHERITLEARN) &&
21780 ++ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
21781 ++ if (obj->nested)
21782 ++ task->acl = obj->nested;
21783 ++ else
21784 ++ task->acl = newacl;
21785 ++ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
21786 ++ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
21787 ++
21788 ++ task->is_writable = 0;
21789 ++
21790 ++ /* ignore additional mmap checks for processes that are writable
21791 ++ by the default ACL */
21792 ++ obj = chk_obj_label(dentry, mnt, default_role->root_label);
21793 ++ if (unlikely(obj->mode & GR_WRITE))
21794 ++ task->is_writable = 1;
21795 ++ obj = chk_obj_label(dentry, mnt, task->role->root_label);
21796 ++ if (unlikely(obj->mode & GR_WRITE))
21797 ++ task->is_writable = 1;
21798 ++
21799 ++ gr_set_proc_res(task);
21800 ++
21801 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
21802 ++ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
21803 ++#endif
21804 ++ return 0;
21805 ++}
21806 ++
21807 ++/* always called with valid inodev ptr */
21808 ++static void
21809 ++do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
21810 ++{
21811 ++ struct acl_object_label *matchpo;
21812 ++ struct acl_subject_label *matchps;
21813 ++ struct acl_subject_label *subj;
21814 ++ struct acl_role_label *role;
21815 ++ unsigned int i, x;
21816 ++
21817 ++ FOR_EACH_ROLE_START(role, i)
21818 ++ FOR_EACH_SUBJECT_START(role, subj, x)
21819 ++ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
21820 ++ matchpo->mode |= GR_DELETED;
21821 ++ FOR_EACH_SUBJECT_END(subj,x)
21822 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
21823 ++ if (subj->inode == ino && subj->device == dev)
21824 ++ subj->mode |= GR_DELETED;
21825 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
21826 ++ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
21827 ++ matchps->mode |= GR_DELETED;
21828 ++ FOR_EACH_ROLE_END(role,i)
21829 ++
21830 ++ inodev->nentry->deleted = 1;
21831 ++
21832 ++ return;
21833 ++}
21834 ++
21835 ++void
21836 ++gr_handle_delete(const ino_t ino, const dev_t dev)
21837 ++{
21838 ++ struct inodev_entry *inodev;
21839 ++
21840 ++ if (unlikely(!(gr_status & GR_READY)))
21841 ++ return;
21842 ++
21843 ++ write_lock(&gr_inode_lock);
21844 ++ inodev = lookup_inodev_entry(ino, dev);
21845 ++ if (inodev != NULL)
21846 ++ do_handle_delete(inodev, ino, dev);
21847 ++ write_unlock(&gr_inode_lock);
21848 ++
21849 ++ return;
21850 ++}
21851 ++
21852 ++static void
21853 ++update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
21854 ++ const ino_t newinode, const dev_t newdevice,
21855 ++ struct acl_subject_label *subj)
21856 ++{
21857 ++ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
21858 ++ struct acl_object_label *match;
21859 ++
21860 ++ match = subj->obj_hash[index];
21861 ++
21862 ++ while (match && (match->inode != oldinode ||
21863 ++ match->device != olddevice ||
21864 ++ !(match->mode & GR_DELETED)))
21865 ++ match = match->next;
21866 ++
21867 ++ if (match && (match->inode == oldinode)
21868 ++ && (match->device == olddevice)
21869 ++ && (match->mode & GR_DELETED)) {
21870 ++ if (match->prev == NULL) {
21871 ++ subj->obj_hash[index] = match->next;
21872 ++ if (match->next != NULL)
21873 ++ match->next->prev = NULL;
21874 ++ } else {
21875 ++ match->prev->next = match->next;
21876 ++ if (match->next != NULL)
21877 ++ match->next->prev = match->prev;
21878 ++ }
21879 ++ match->prev = NULL;
21880 ++ match->next = NULL;
21881 ++ match->inode = newinode;
21882 ++ match->device = newdevice;
21883 ++ match->mode &= ~GR_DELETED;
21884 ++
21885 ++ insert_acl_obj_label(match, subj);
21886 ++ }
21887 ++
21888 ++ return;
21889 ++}
21890 ++
21891 ++static void
21892 ++update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
21893 ++ const ino_t newinode, const dev_t newdevice,
21894 ++ struct acl_role_label *role)
21895 ++{
21896 ++ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
21897 ++ struct acl_subject_label *match;
21898 ++
21899 ++ match = role->subj_hash[index];
21900 ++
21901 ++ while (match && (match->inode != oldinode ||
21902 ++ match->device != olddevice ||
21903 ++ !(match->mode & GR_DELETED)))
21904 ++ match = match->next;
21905 ++
21906 ++ if (match && (match->inode == oldinode)
21907 ++ && (match->device == olddevice)
21908 ++ && (match->mode & GR_DELETED)) {
21909 ++ if (match->prev == NULL) {
21910 ++ role->subj_hash[index] = match->next;
21911 ++ if (match->next != NULL)
21912 ++ match->next->prev = NULL;
21913 ++ } else {
21914 ++ match->prev->next = match->next;
21915 ++ if (match->next != NULL)
21916 ++ match->next->prev = match->prev;
21917 ++ }
21918 ++ match->prev = NULL;
21919 ++ match->next = NULL;
21920 ++ match->inode = newinode;
21921 ++ match->device = newdevice;
21922 ++ match->mode &= ~GR_DELETED;
21923 ++
21924 ++ insert_acl_subj_label(match, role);
21925 ++ }
21926 ++
21927 ++ return;
21928 ++}
21929 ++
21930 ++static void
21931 ++update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
21932 ++ const ino_t newinode, const dev_t newdevice)
21933 ++{
21934 ++ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
21935 ++ struct inodev_entry *match;
21936 ++
21937 ++ match = inodev_set.i_hash[index];
21938 ++
21939 ++ while (match && (match->nentry->inode != oldinode ||
21940 ++ match->nentry->device != olddevice || !match->nentry->deleted))
21941 ++ match = match->next;
21942 ++
21943 ++ if (match && (match->nentry->inode == oldinode)
21944 ++ && (match->nentry->device == olddevice) &&
21945 ++ match->nentry->deleted) {
21946 ++ if (match->prev == NULL) {
21947 ++ inodev_set.i_hash[index] = match->next;
21948 ++ if (match->next != NULL)
21949 ++ match->next->prev = NULL;
21950 ++ } else {
21951 ++ match->prev->next = match->next;
21952 ++ if (match->next != NULL)
21953 ++ match->next->prev = match->prev;
21954 ++ }
21955 ++ match->prev = NULL;
21956 ++ match->next = NULL;
21957 ++ match->nentry->inode = newinode;
21958 ++ match->nentry->device = newdevice;
21959 ++ match->nentry->deleted = 0;
21960 ++
21961 ++ insert_inodev_entry(match);
21962 ++ }
21963 ++
21964 ++ return;
21965 ++}
21966 ++
21967 ++static void
21968 ++do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
21969 ++ const struct vfsmount *mnt)
21970 ++{
21971 ++ struct acl_subject_label *subj;
21972 ++ struct acl_role_label *role;
21973 ++ unsigned int i, x;
21974 ++
21975 ++ FOR_EACH_ROLE_START(role, i)
21976 ++ update_acl_subj_label(matchn->inode, matchn->device,
21977 ++ dentry->d_inode->i_ino,
21978 ++ dentry->d_inode->i_sb->s_dev, role);
21979 ++
21980 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
21981 ++ if ((subj->inode == dentry->d_inode->i_ino) &&
21982 ++ (subj->device == dentry->d_inode->i_sb->s_dev)) {
21983 ++ subj->inode = dentry->d_inode->i_ino;
21984 ++ subj->device = dentry->d_inode->i_sb->s_dev;
21985 ++ }
21986 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
21987 ++ FOR_EACH_SUBJECT_START(role, subj, x)
21988 ++ update_acl_obj_label(matchn->inode, matchn->device,
21989 ++ dentry->d_inode->i_ino,
21990 ++ dentry->d_inode->i_sb->s_dev, subj);
21991 ++ FOR_EACH_SUBJECT_END(subj,x)
21992 ++ FOR_EACH_ROLE_END(role,i)
21993 ++
21994 ++ update_inodev_entry(matchn->inode, matchn->device,
21995 ++ dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
21996 ++
21997 ++ return;
21998 ++}
21999 ++
22000 ++void
22001 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
22002 ++{
22003 ++ struct name_entry *matchn;
22004 ++
22005 ++ if (unlikely(!(gr_status & GR_READY)))
22006 ++ return;
22007 ++
22008 ++ preempt_disable();
22009 ++ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
22010 ++
22011 ++ if (unlikely((unsigned long)matchn)) {
22012 ++ write_lock(&gr_inode_lock);
22013 ++ do_handle_create(matchn, dentry, mnt);
22014 ++ write_unlock(&gr_inode_lock);
22015 ++ }
22016 ++ preempt_enable();
22017 ++
22018 ++ return;
22019 ++}
22020 ++
22021 ++void
22022 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
22023 ++ struct dentry *old_dentry,
22024 ++ struct dentry *new_dentry,
22025 ++ struct vfsmount *mnt, const __u8 replace)
22026 ++{
22027 ++ struct name_entry *matchn;
22028 ++ struct inodev_entry *inodev;
22029 ++
22030 ++ /* vfs_rename swaps the name and parent link for old_dentry and
22031 ++ new_dentry
22032 ++ at this point, old_dentry has the new name, parent link, and inode
22033 ++ for the renamed file
22034 ++ if a file is being replaced by a rename, new_dentry has the inode
22035 ++ and name for the replaced file
22036 ++ */
22037 ++
22038 ++ if (unlikely(!(gr_status & GR_READY)))
22039 ++ return;
22040 ++
22041 ++ preempt_disable();
22042 ++ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
22043 ++
22044 ++ /* we wouldn't have to check d_inode if it weren't for
22045 ++ NFS silly-renaming
22046 ++ */
22047 ++
22048 ++ write_lock(&gr_inode_lock);
22049 ++ if (unlikely(replace && new_dentry->d_inode)) {
22050 ++ inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
22051 ++ new_dentry->d_inode->i_sb->s_dev);
22052 ++ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
22053 ++ do_handle_delete(inodev, new_dentry->d_inode->i_ino,
22054 ++ new_dentry->d_inode->i_sb->s_dev);
22055 ++ }
22056 ++
22057 ++ inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
22058 ++ old_dentry->d_inode->i_sb->s_dev);
22059 ++ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
22060 ++ do_handle_delete(inodev, old_dentry->d_inode->i_ino,
22061 ++ old_dentry->d_inode->i_sb->s_dev);
22062 ++
22063 ++ if (unlikely((unsigned long)matchn))
22064 ++ do_handle_create(matchn, old_dentry, mnt);
22065 ++
22066 ++ write_unlock(&gr_inode_lock);
22067 ++ preempt_enable();
22068 ++
22069 ++ return;
22070 ++}
22071 ++
22072 ++static int
22073 ++lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
22074 ++ unsigned char **sum)
22075 ++{
22076 ++ struct acl_role_label *r;
22077 ++ struct role_allowed_ip *ipp;
22078 ++ struct role_transition *trans;
22079 ++ unsigned int i;
22080 ++ int found = 0;
22081 ++
22082 ++ /* check transition table */
22083 ++
22084 ++ for (trans = current->role->transitions; trans; trans = trans->next) {
22085 ++ if (!strcmp(rolename, trans->rolename)) {
22086 ++ found = 1;
22087 ++ break;
22088 ++ }
22089 ++ }
22090 ++
22091 ++ if (!found)
22092 ++ return 0;
22093 ++
22094 ++ /* handle special roles that do not require authentication
22095 ++ and check ip */
22096 ++
22097 ++ FOR_EACH_ROLE_START(r, i)
22098 ++ if (!strcmp(rolename, r->rolename) &&
22099 ++ (r->roletype & GR_ROLE_SPECIAL)) {
22100 ++ found = 0;
22101 ++ if (r->allowed_ips != NULL) {
22102 ++ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
22103 ++ if ((ntohl(current->signal->curr_ip) & ipp->netmask) ==
22104 ++ (ntohl(ipp->addr) & ipp->netmask))
22105 ++ found = 1;
22106 ++ }
22107 ++ } else
22108 ++ found = 2;
22109 ++ if (!found)
22110 ++ return 0;
22111 ++
22112 ++ if (((mode == SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
22113 ++ ((mode == SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
22114 ++ *salt = NULL;
22115 ++ *sum = NULL;
22116 ++ return 1;
22117 ++ }
22118 ++ }
22119 ++ FOR_EACH_ROLE_END(r,i)
22120 ++
22121 ++ for (i = 0; i < num_sprole_pws; i++) {
22122 ++ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
22123 ++ *salt = acl_special_roles[i]->salt;
22124 ++ *sum = acl_special_roles[i]->sum;
22125 ++ return 1;
22126 ++ }
22127 ++ }
22128 ++
22129 ++ return 0;
22130 ++}
22131 ++
22132 ++static void
22133 ++assign_special_role(char *rolename)
22134 ++{
22135 ++ struct acl_object_label *obj;
22136 ++ struct acl_role_label *r;
22137 ++ struct acl_role_label *assigned = NULL;
22138 ++ struct task_struct *tsk;
22139 ++ struct file *filp;
22140 ++ unsigned int i;
22141 ++
22142 ++ FOR_EACH_ROLE_START(r, i)
22143 ++ if (!strcmp(rolename, r->rolename) &&
22144 ++ (r->roletype & GR_ROLE_SPECIAL))
22145 ++ assigned = r;
22146 ++ FOR_EACH_ROLE_END(r,i)
22147 ++
22148 ++ if (!assigned)
22149 ++ return;
22150 ++
22151 ++ read_lock(&tasklist_lock);
22152 ++ read_lock(&grsec_exec_file_lock);
22153 ++
22154 ++ tsk = current->parent;
22155 ++ if (tsk == NULL)
22156 ++ goto out_unlock;
22157 ++
22158 ++ filp = tsk->exec_file;
22159 ++ if (filp == NULL)
22160 ++ goto out_unlock;
22161 ++
22162 ++ tsk->is_writable = 0;
22163 ++
22164 ++ tsk->acl_sp_role = 1;
22165 ++ tsk->acl_role_id = ++acl_sp_role_value;
22166 ++ tsk->role = assigned;
22167 ++ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
22168 ++
22169 ++ /* ignore additional mmap checks for processes that are writable
22170 ++ by the default ACL */
22171 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
22172 ++ if (unlikely(obj->mode & GR_WRITE))
22173 ++ tsk->is_writable = 1;
22174 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
22175 ++ if (unlikely(obj->mode & GR_WRITE))
22176 ++ tsk->is_writable = 1;
22177 ++
22178 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
22179 ++ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
22180 ++#endif
22181 ++
22182 ++out_unlock:
22183 ++ read_unlock(&grsec_exec_file_lock);
22184 ++ read_unlock(&tasklist_lock);
22185 ++ return;
22186 ++}
22187 ++
22188 ++int gr_check_secure_terminal(struct task_struct *task)
22189 ++{
22190 ++ struct task_struct *p, *p2, *p3;
22191 ++ struct files_struct *files;
22192 ++ struct fdtable *fdt;
22193 ++ struct file *our_file = NULL, *file;
22194 ++ int i;
22195 ++
22196 ++ if (task->signal->tty == NULL)
22197 ++ return 1;
22198 ++
22199 ++ files = get_files_struct(task);
22200 ++ if (files != NULL) {
22201 ++ rcu_read_lock();
22202 ++ fdt = files_fdtable(files);
22203 ++ for (i=0; i < fdt->max_fds; i++) {
22204 ++ file = fcheck_files(files, i);
22205 ++ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
22206 ++ get_file(file);
22207 ++ our_file = file;
22208 ++ }
22209 ++ }
22210 ++ rcu_read_unlock();
22211 ++ put_files_struct(files);
22212 ++ }
22213 ++
22214 ++ if (our_file == NULL)
22215 ++ return 1;
22216 ++
22217 ++ read_lock(&tasklist_lock);
22218 ++ do_each_thread(p2, p) {
22219 ++ files = get_files_struct(p);
22220 ++ if (files == NULL ||
22221 ++ (p->signal && p->signal->tty == task->signal->tty)) {
22222 ++ if (files != NULL)
22223 ++ put_files_struct(files);
22224 ++ continue;
22225 ++ }
22226 ++ rcu_read_lock();
22227 ++ fdt = files_fdtable(files);
22228 ++ for (i=0; i < fdt->max_fds; i++) {
22229 ++ file = fcheck_files(files, i);
22230 ++ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
22231 ++ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
22232 ++ p3 = task;
22233 ++ while (p3->pid > 0) {
22234 ++ if (p3 == p)
22235 ++ break;
22236 ++ p3 = p3->parent;
22237 ++ }
22238 ++ if (p3 == p)
22239 ++ break;
22240 ++ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
22241 ++ gr_handle_alertkill(p);
22242 ++ rcu_read_unlock();
22243 ++ put_files_struct(files);
22244 ++ read_unlock(&tasklist_lock);
22245 ++ fput(our_file);
22246 ++ return 0;
22247 ++ }
22248 ++ }
22249 ++ rcu_read_unlock();
22250 ++ put_files_struct(files);
22251 ++ } while_each_thread(p2, p);
22252 ++ read_unlock(&tasklist_lock);
22253 ++
22254 ++ fput(our_file);
22255 ++ return 1;
22256 ++}
22257 ++
22258 ++ssize_t
22259 ++write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
22260 ++{
22261 ++ struct gr_arg_wrapper uwrap;
22262 ++ unsigned char *sprole_salt;
22263 ++ unsigned char *sprole_sum;
22264 ++ int error = sizeof (struct gr_arg_wrapper);
22265 ++ int error2 = 0;
22266 ++
22267 ++ down(&gr_dev_sem);
22268 ++
22269 ++ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
22270 ++ error = -EPERM;
22271 ++ goto out;
22272 ++ }
22273 ++
22274 ++ if (count != sizeof (struct gr_arg_wrapper)) {
22275 ++ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
22276 ++ error = -EINVAL;
22277 ++ goto out;
22278 ++ }
22279 ++
22280 ++
22281 ++ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
22282 ++ gr_auth_expires = 0;
22283 ++ gr_auth_attempts = 0;
22284 ++ }
22285 ++
22286 ++ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
22287 ++ error = -EFAULT;
22288 ++ goto out;
22289 ++ }
22290 ++
22291 ++ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
22292 ++ error = -EINVAL;
22293 ++ goto out;
22294 ++ }
22295 ++
22296 ++ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
22297 ++ error = -EFAULT;
22298 ++ goto out;
22299 ++ }
22300 ++
22301 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != SPROLEPAM &&
22302 ++ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
22303 ++ time_after(gr_auth_expires, get_seconds())) {
22304 ++ error = -EBUSY;
22305 ++ goto out;
22306 ++ }
22307 ++
22308 ++ /* if non-root trying to do anything other than use a special role,
22309 ++ do not attempt authentication, do not count towards authentication
22310 ++ locking
22311 ++ */
22312 ++
22313 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != STATUS &&
22314 ++ gr_usermode->mode != UNSPROLE && gr_usermode->mode != SPROLEPAM &&
22315 ++ current->uid) {
22316 ++ error = -EPERM;
22317 ++ goto out;
22318 ++ }
22319 ++
22320 ++ /* ensure pw and special role name are null terminated */
22321 ++
22322 ++ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
22323 ++ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
22324 ++
22325 ++ /* Okay.
22326 ++ * We have our enough of the argument structure..(we have yet
22327 ++ * to copy_from_user the tables themselves) . Copy the tables
22328 ++ * only if we need them, i.e. for loading operations. */
22329 ++
22330 ++ switch (gr_usermode->mode) {
22331 ++ case STATUS:
22332 ++ if (gr_status & GR_READY) {
22333 ++ error = 1;
22334 ++ if (!gr_check_secure_terminal(current))
22335 ++ error = 3;
22336 ++ } else
22337 ++ error = 2;
22338 ++ goto out;
22339 ++ case SHUTDOWN:
22340 ++ if ((gr_status & GR_READY)
22341 ++ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
22342 ++ gr_status &= ~GR_READY;
22343 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
22344 ++ free_variables();
22345 ++ memset(gr_usermode, 0, sizeof (struct gr_arg));
22346 ++ memset(gr_system_salt, 0, GR_SALT_LEN);
22347 ++ memset(gr_system_sum, 0, GR_SHA_LEN);
22348 ++ } else if (gr_status & GR_READY) {
22349 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
22350 ++ error = -EPERM;
22351 ++ } else {
22352 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
22353 ++ error = -EAGAIN;
22354 ++ }
22355 ++ break;
22356 ++ case ENABLE:
22357 ++ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
22358 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
22359 ++ else {
22360 ++ if (gr_status & GR_READY)
22361 ++ error = -EAGAIN;
22362 ++ else
22363 ++ error = error2;
22364 ++ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
22365 ++ }
22366 ++ break;
22367 ++ case RELOAD:
22368 ++ if (!(gr_status & GR_READY)) {
22369 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
22370 ++ error = -EAGAIN;
22371 ++ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
22372 ++ lock_kernel();
22373 ++ gr_status &= ~GR_READY;
22374 ++ free_variables();
22375 ++ if (!(error2 = gracl_init(gr_usermode))) {
22376 ++ unlock_kernel();
22377 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
22378 ++ } else {
22379 ++ unlock_kernel();
22380 ++ error = error2;
22381 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
22382 ++ }
22383 ++ } else {
22384 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
22385 ++ error = -EPERM;
22386 ++ }
22387 ++ break;
22388 ++ case SEGVMOD:
22389 ++ if (unlikely(!(gr_status & GR_READY))) {
22390 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
22391 ++ error = -EAGAIN;
22392 ++ break;
22393 ++ }
22394 ++
22395 ++ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
22396 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
22397 ++ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
22398 ++ struct acl_subject_label *segvacl;
22399 ++ segvacl =
22400 ++ lookup_acl_subj_label(gr_usermode->segv_inode,
22401 ++ gr_usermode->segv_device,
22402 ++ current->role);
22403 ++ if (segvacl) {
22404 ++ segvacl->crashes = 0;
22405 ++ segvacl->expires = 0;
22406 ++ }
22407 ++ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
22408 ++ gr_remove_uid(gr_usermode->segv_uid);
22409 ++ }
22410 ++ } else {
22411 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
22412 ++ error = -EPERM;
22413 ++ }
22414 ++ break;
22415 ++ case SPROLE:
22416 ++ case SPROLEPAM:
22417 ++ if (unlikely(!(gr_status & GR_READY))) {
22418 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
22419 ++ error = -EAGAIN;
22420 ++ break;
22421 ++ }
22422 ++
22423 ++ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
22424 ++ current->role->expires = 0;
22425 ++ current->role->auth_attempts = 0;
22426 ++ }
22427 ++
22428 ++ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
22429 ++ time_after(current->role->expires, get_seconds())) {
22430 ++ error = -EBUSY;
22431 ++ goto out;
22432 ++ }
22433 ++
22434 ++ if (lookup_special_role_auth
22435 ++ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
22436 ++ && ((!sprole_salt && !sprole_sum)
22437 ++ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
22438 ++ char *p = "";
22439 ++ assign_special_role(gr_usermode->sp_role);
22440 ++ read_lock(&tasklist_lock);
22441 ++ if (current->parent)
22442 ++ p = current->parent->role->rolename;
22443 ++ read_unlock(&tasklist_lock);
22444 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
22445 ++ p, acl_sp_role_value);
22446 ++ } else {
22447 ++ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
22448 ++ error = -EPERM;
22449 ++ if(!(current->role->auth_attempts++))
22450 ++ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
22451 ++
22452 ++ goto out;
22453 ++ }
22454 ++ break;
22455 ++ case UNSPROLE:
22456 ++ if (unlikely(!(gr_status & GR_READY))) {
22457 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
22458 ++ error = -EAGAIN;
22459 ++ break;
22460 ++ }
22461 ++
22462 ++ if (current->role->roletype & GR_ROLE_SPECIAL) {
22463 ++ char *p = "";
22464 ++ int i = 0;
22465 ++
22466 ++ read_lock(&tasklist_lock);
22467 ++ if (current->parent) {
22468 ++ p = current->parent->role->rolename;
22469 ++ i = current->parent->acl_role_id;
22470 ++ }
22471 ++ read_unlock(&tasklist_lock);
22472 ++
22473 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
22474 ++ gr_set_acls(1);
22475 ++ } else {
22476 ++ gr_log_str(GR_DONT_AUDIT, GR_UNSPROLEF_ACL_MSG, current->role->rolename);
22477 ++ error = -EPERM;
22478 ++ goto out;
22479 ++ }
22480 ++ break;
22481 ++ default:
22482 ++ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
22483 ++ error = -EINVAL;
22484 ++ break;
22485 ++ }
22486 ++
22487 ++ if (error != -EPERM)
22488 ++ goto out;
22489 ++
22490 ++ if(!(gr_auth_attempts++))
22491 ++ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
22492 ++
22493 ++ out:
22494 ++ up(&gr_dev_sem);
22495 ++ return error;
22496 ++}
22497 ++
22498 ++int
22499 ++gr_set_acls(const int type)
22500 ++{
22501 ++ struct acl_object_label *obj;
22502 ++ struct task_struct *task, *task2;
22503 ++ struct file *filp;
22504 ++ struct acl_role_label *role = current->role;
22505 ++ __u16 acl_role_id = current->acl_role_id;
22506 ++
22507 ++ read_lock(&tasklist_lock);
22508 ++ read_lock(&grsec_exec_file_lock);
22509 ++ do_each_thread(task2, task) {
22510 ++ /* check to see if we're called from the exit handler,
22511 ++ if so, only replace ACLs that have inherited the admin
22512 ++ ACL */
22513 ++
22514 ++ if (type && (task->role != role ||
22515 ++ task->acl_role_id != acl_role_id))
22516 ++ continue;
22517 ++
22518 ++ task->acl_role_id = 0;
22519 ++ task->acl_sp_role = 0;
22520 ++
22521 ++ if ((filp = task->exec_file)) {
22522 ++ task->role = lookup_acl_role_label(task, task->uid, task->gid);
22523 ++
22524 ++ task->acl =
22525 ++ chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
22526 ++ task->role);
22527 ++ if (task->acl) {
22528 ++ struct acl_subject_label *curr;
22529 ++ curr = task->acl;
22530 ++
22531 ++ task->is_writable = 0;
22532 ++ /* ignore additional mmap checks for processes that are writable
22533 ++ by the default ACL */
22534 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
22535 ++ if (unlikely(obj->mode & GR_WRITE))
22536 ++ task->is_writable = 1;
22537 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
22538 ++ if (unlikely(obj->mode & GR_WRITE))
22539 ++ task->is_writable = 1;
22540 ++
22541 ++ gr_set_proc_res(task);
22542 ++
22543 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
22544 ++ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
22545 ++#endif
22546 ++ } else {
22547 ++ read_unlock(&grsec_exec_file_lock);
22548 ++ read_unlock(&tasklist_lock);
22549 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
22550 ++ return 1;
22551 ++ }
22552 ++ } else {
22553 ++ // it's a kernel process
22554 ++ task->role = kernel_role;
22555 ++ task->acl = kernel_role->root_label;
22556 ++#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
22557 ++ task->acl->mode &= ~GR_PROCFIND;
22558 ++#endif
22559 ++ }
22560 ++ } while_each_thread(task2, task);
22561 ++ read_unlock(&grsec_exec_file_lock);
22562 ++ read_unlock(&tasklist_lock);
22563 ++ return 0;
22564 ++}
22565 ++
22566 ++void
22567 ++gr_learn_resource(const struct task_struct *task,
22568 ++ const int res, const unsigned long wanted, const int gt)
22569 ++{
22570 ++ struct acl_subject_label *acl;
22571 ++
22572 ++ if (unlikely((gr_status & GR_READY) &&
22573 ++ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
22574 ++ goto skip_reslog;
22575 ++
22576 ++#ifdef CONFIG_GRKERNSEC_RESLOG
22577 ++ gr_log_resource(task, res, wanted, gt);
22578 ++#endif
22579 ++ skip_reslog:
22580 ++
22581 ++ if (unlikely(!(gr_status & GR_READY) || !wanted))
22582 ++ return;
22583 ++
22584 ++ acl = task->acl;
22585 ++
22586 ++ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
22587 ++ !(acl->resmask & (1 << (unsigned short) res))))
22588 ++ return;
22589 ++
22590 ++ if (wanted >= acl->res[res].rlim_cur) {
22591 ++ unsigned long res_add;
22592 ++
22593 ++ res_add = wanted;
22594 ++ switch (res) {
22595 ++ case RLIMIT_CPU:
22596 ++ res_add += GR_RLIM_CPU_BUMP;
22597 ++ break;
22598 ++ case RLIMIT_FSIZE:
22599 ++ res_add += GR_RLIM_FSIZE_BUMP;
22600 ++ break;
22601 ++ case RLIMIT_DATA:
22602 ++ res_add += GR_RLIM_DATA_BUMP;
22603 ++ break;
22604 ++ case RLIMIT_STACK:
22605 ++ res_add += GR_RLIM_STACK_BUMP;
22606 ++ break;
22607 ++ case RLIMIT_CORE:
22608 ++ res_add += GR_RLIM_CORE_BUMP;
22609 ++ break;
22610 ++ case RLIMIT_RSS:
22611 ++ res_add += GR_RLIM_RSS_BUMP;
22612 ++ break;
22613 ++ case RLIMIT_NPROC:
22614 ++ res_add += GR_RLIM_NPROC_BUMP;
22615 ++ break;
22616 ++ case RLIMIT_NOFILE:
22617 ++ res_add += GR_RLIM_NOFILE_BUMP;
22618 ++ break;
22619 ++ case RLIMIT_MEMLOCK:
22620 ++ res_add += GR_RLIM_MEMLOCK_BUMP;
22621 ++ break;
22622 ++ case RLIMIT_AS:
22623 ++ res_add += GR_RLIM_AS_BUMP;
22624 ++ break;
22625 ++ case RLIMIT_LOCKS:
22626 ++ res_add += GR_RLIM_LOCKS_BUMP;
22627 ++ break;
22628 ++ }
22629 ++
22630 ++ acl->res[res].rlim_cur = res_add;
22631 ++
22632 ++ if (wanted > acl->res[res].rlim_max)
22633 ++ acl->res[res].rlim_max = res_add;
22634 ++
22635 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
22636 ++ task->role->roletype, acl->filename,
22637 ++ acl->res[res].rlim_cur, acl->res[res].rlim_max,
22638 ++ "", (unsigned long) res);
22639 ++ }
22640 ++
22641 ++ return;
22642 ++}
22643 ++
22644 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
22645 ++void
22646 ++pax_set_initial_flags(struct linux_binprm *bprm)
22647 ++{
22648 ++ struct task_struct *task = current;
22649 ++ struct acl_subject_label *proc;
22650 ++ unsigned long flags;
22651 ++
22652 ++ if (unlikely(!(gr_status & GR_READY)))
22653 ++ return;
22654 ++
22655 ++ flags = pax_get_flags(task);
22656 ++
22657 ++ proc = task->acl;
22658 ++
22659 ++ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
22660 ++ flags &= ~MF_PAX_PAGEEXEC;
22661 ++ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
22662 ++ flags &= ~MF_PAX_SEGMEXEC;
22663 ++ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
22664 ++ flags &= ~MF_PAX_RANDMMAP;
22665 ++ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
22666 ++ flags &= ~MF_PAX_EMUTRAMP;
22667 ++ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
22668 ++ flags &= ~MF_PAX_MPROTECT;
22669 ++
22670 ++ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
22671 ++ flags |= MF_PAX_PAGEEXEC;
22672 ++ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
22673 ++ flags |= MF_PAX_SEGMEXEC;
22674 ++ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
22675 ++ flags |= MF_PAX_RANDMMAP;
22676 ++ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
22677 ++ flags |= MF_PAX_EMUTRAMP;
22678 ++ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
22679 ++ flags |= MF_PAX_MPROTECT;
22680 ++
22681 ++ pax_set_flags(task, flags);
22682 ++
22683 ++ return;
22684 ++}
22685 ++#endif
22686 ++
22687 ++#ifdef CONFIG_SYSCTL
22688 ++/* Eric Biederman likes breaking userland ABI and every inode-based security
22689 ++ system to save 35kb of memory */
22690 ++
22691 ++/* we modify the passed in filename, but adjust it back before returning */
22692 ++static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
22693 ++{
22694 ++ struct name_entry *nmatch;
22695 ++ char *p, *lastp = NULL;
22696 ++ struct acl_object_label *obj = NULL, *tmp;
22697 ++ struct acl_subject_label *tmpsubj;
22698 ++ char c = '\0';
22699 ++
22700 ++ read_lock(&gr_inode_lock);
22701 ++
22702 ++ p = name + len - 1;
22703 ++ do {
22704 ++ nmatch = lookup_name_entry(name);
22705 ++ if (lastp != NULL)
22706 ++ *lastp = c;
22707 ++
22708 ++ if (nmatch == NULL)
22709 ++ goto next_component;
22710 ++ tmpsubj = current->acl;
22711 ++ do {
22712 ++ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
22713 ++ if (obj != NULL) {
22714 ++ tmp = obj->globbed;
22715 ++ while (tmp) {
22716 ++ if (!glob_match(tmp->filename, name)) {
22717 ++ obj = tmp;
22718 ++ goto found_obj;
22719 ++ }
22720 ++ tmp = tmp->next;
22721 ++ }
22722 ++ goto found_obj;
22723 ++ }
22724 ++ } while ((tmpsubj = tmpsubj->parent_subject));
22725 ++next_component:
22726 ++ /* end case */
22727 ++ if (p == name)
22728 ++ break;
22729 ++
22730 ++ while (*p != '/')
22731 ++ p--;
22732 ++ if (p == name)
22733 ++ lastp = p + 1;
22734 ++ else {
22735 ++ lastp = p;
22736 ++ p--;
22737 ++ }
22738 ++ c = *lastp;
22739 ++ *lastp = '\0';
22740 ++ } while (1);
22741 ++found_obj:
22742 ++ read_unlock(&gr_inode_lock);
22743 ++ /* obj returned will always be non-null */
22744 ++ return obj;
22745 ++}
22746 ++
22747 ++/* returns 0 when allowing, non-zero on error
22748 ++ op of 0 is used for readdir, so we don't log the names of hidden files
22749 ++*/
22750 ++__u32
22751 ++gr_handle_sysctl(const struct ctl_table *table, const int op)
22752 ++{
22753 ++ ctl_table *tmp;
22754 ++ const char *proc_sys = "/proc/sys";
22755 ++ char *path;
22756 ++ struct acl_object_label *obj;
22757 ++ unsigned short len = 0, pos = 0, depth = 0, i;
22758 ++ __u32 err = 0;
22759 ++ __u32 mode = 0;
22760 ++
22761 ++ if (unlikely(!(gr_status & GR_READY)))
22762 ++ return 0;
22763 ++
22764 ++ /* for now, ignore operations on non-sysctl entries if it's not a
22765 ++ readdir*/
22766 ++ if (table->child != NULL && op != 0)
22767 ++ return 0;
22768 ++
22769 ++ mode |= GR_FIND;
22770 ++ /* it's only a read if it's an entry, read on dirs is for readdir */
22771 ++ if (op & MAY_READ)
22772 ++ mode |= GR_READ;
22773 ++ if (op & MAY_WRITE)
22774 ++ mode |= GR_WRITE;
22775 ++
22776 ++ preempt_disable();
22777 ++
22778 ++ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
22779 ++
22780 ++ /* it's only a read/write if it's an actual entry, not a dir
22781 ++ (which are opened for readdir)
22782 ++ */
22783 ++
22784 ++ /* convert the requested sysctl entry into a pathname */
22785 ++
22786 ++ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
22787 ++ len += strlen(tmp->procname);
22788 ++ len++;
22789 ++ depth++;
22790 ++ }
22791 ++
22792 ++ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
22793 ++ /* deny */
22794 ++ goto out;
22795 ++ }
22796 ++
22797 ++ memset(path, 0, PAGE_SIZE);
22798 ++
22799 ++ memcpy(path, proc_sys, strlen(proc_sys));
22800 ++
22801 ++ pos += strlen(proc_sys);
22802 ++
22803 ++ for (; depth > 0; depth--) {
22804 ++ path[pos] = '/';
22805 ++ pos++;
22806 ++ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
22807 ++ if (depth == i) {
22808 ++ memcpy(path + pos, tmp->procname,
22809 ++ strlen(tmp->procname));
22810 ++ pos += strlen(tmp->procname);
22811 ++ }
22812 ++ i++;
22813 ++ }
22814 ++ }
22815 ++
22816 ++ obj = gr_lookup_by_name(path, pos);
22817 ++ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
22818 ++
22819 ++ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
22820 ++ ((err & mode) != mode))) {
22821 ++ __u32 new_mode = mode;
22822 ++
22823 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
22824 ++
22825 ++ err = 0;
22826 ++ gr_log_learn_sysctl(current, path, new_mode);
22827 ++ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
22828 ++ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
22829 ++ err = -ENOENT;
22830 ++ } else if (!(err & GR_FIND)) {
22831 ++ err = -ENOENT;
22832 ++ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
22833 ++ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
22834 ++ path, (mode & GR_READ) ? " reading" : "",
22835 ++ (mode & GR_WRITE) ? " writing" : "");
22836 ++ err = -EACCES;
22837 ++ } else if ((err & mode) != mode) {
22838 ++ err = -EACCES;
22839 ++ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
22840 ++ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
22841 ++ path, (mode & GR_READ) ? " reading" : "",
22842 ++ (mode & GR_WRITE) ? " writing" : "");
22843 ++ err = 0;
22844 ++ } else
22845 ++ err = 0;
22846 ++
22847 ++ out:
22848 ++ preempt_enable();
22849 ++
22850 ++ return err;
22851 ++}
22852 ++#endif
22853 ++
22854 ++int
22855 ++gr_handle_proc_ptrace(struct task_struct *task)
22856 ++{
22857 ++ struct file *filp;
22858 ++ struct task_struct *tmp = task;
22859 ++ struct task_struct *curtemp = current;
22860 ++ __u32 retmode;
22861 ++
22862 ++ if (unlikely(!(gr_status & GR_READY)))
22863 ++ return 0;
22864 ++
22865 ++ read_lock(&tasklist_lock);
22866 ++ read_lock(&grsec_exec_file_lock);
22867 ++ filp = task->exec_file;
22868 ++
22869 ++ while (tmp->pid > 0) {
22870 ++ if (tmp == curtemp)
22871 ++ break;
22872 ++ tmp = tmp->parent;
22873 ++ }
22874 ++
22875 ++ if (!filp || (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE))) {
22876 ++ read_unlock(&grsec_exec_file_lock);
22877 ++ read_unlock(&tasklist_lock);
22878 ++ return 1;
22879 ++ }
22880 ++
22881 ++ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
22882 ++ read_unlock(&grsec_exec_file_lock);
22883 ++ read_unlock(&tasklist_lock);
22884 ++
22885 ++ if (retmode & GR_NOPTRACE)
22886 ++ return 1;
22887 ++
22888 ++ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
22889 ++ && (current->acl != task->acl || (current->acl != current->role->root_label
22890 ++ && current->pid != task->pid)))
22891 ++ return 1;
22892 ++
22893 ++ return 0;
22894 ++}
22895 ++
22896 ++int
22897 ++gr_handle_ptrace(struct task_struct *task, const long request)
22898 ++{
22899 ++ struct task_struct *tmp = task;
22900 ++ struct task_struct *curtemp = current;
22901 ++ __u32 retmode;
22902 ++
22903 ++ if (unlikely(!(gr_status & GR_READY)))
22904 ++ return 0;
22905 ++
22906 ++ read_lock(&tasklist_lock);
22907 ++ while (tmp->pid > 0) {
22908 ++ if (tmp == curtemp)
22909 ++ break;
22910 ++ tmp = tmp->parent;
22911 ++ }
22912 ++
22913 ++ if (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE)) {
22914 ++ read_unlock(&tasklist_lock);
22915 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
22916 ++ return 1;
22917 ++ }
22918 ++ read_unlock(&tasklist_lock);
22919 ++
22920 ++ read_lock(&grsec_exec_file_lock);
22921 ++ if (unlikely(!task->exec_file)) {
22922 ++ read_unlock(&grsec_exec_file_lock);
22923 ++ return 0;
22924 ++ }
22925 ++
22926 ++ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
22927 ++ read_unlock(&grsec_exec_file_lock);
22928 ++
22929 ++ if (retmode & GR_NOPTRACE) {
22930 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
22931 ++ return 1;
22932 ++ }
22933 ++
22934 ++ if (retmode & GR_PTRACERD) {
22935 ++ switch (request) {
22936 ++ case PTRACE_POKETEXT:
22937 ++ case PTRACE_POKEDATA:
22938 ++ case PTRACE_POKEUSR:
22939 ++#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
22940 ++ case PTRACE_SETREGS:
22941 ++ case PTRACE_SETFPREGS:
22942 ++#endif
22943 ++#ifdef CONFIG_X86
22944 ++ case PTRACE_SETFPXREGS:
22945 ++#endif
22946 ++#ifdef CONFIG_ALTIVEC
22947 ++ case PTRACE_SETVRREGS:
22948 ++#endif
22949 ++ return 1;
22950 ++ default:
22951 ++ return 0;
22952 ++ }
22953 ++ } else if (!(current->acl->mode & GR_POVERRIDE) &&
22954 ++ !(current->role->roletype & GR_ROLE_GOD) &&
22955 ++ (current->acl != task->acl)) {
22956 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
22957 ++ return 1;
22958 ++ }
22959 ++
22960 ++ return 0;
22961 ++}
22962 ++
22963 ++static int is_writable_mmap(const struct file *filp)
22964 ++{
22965 ++ struct task_struct *task = current;
22966 ++ struct acl_object_label *obj, *obj2;
22967 ++
22968 ++ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
22969 ++ !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode)) {
22970 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
22971 ++ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
22972 ++ task->role->root_label);
22973 ++ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
22974 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
22975 ++ return 1;
22976 ++ }
22977 ++ }
22978 ++ return 0;
22979 ++}
22980 ++
22981 ++int
22982 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
22983 ++{
22984 ++ __u32 mode;
22985 ++
22986 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
22987 ++ return 1;
22988 ++
22989 ++ if (is_writable_mmap(file))
22990 ++ return 0;
22991 ++
22992 ++ mode =
22993 ++ gr_search_file(file->f_path.dentry,
22994 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
22995 ++ file->f_path.mnt);
22996 ++
22997 ++ if (!gr_tpe_allow(file))
22998 ++ return 0;
22999 ++
23000 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
23001 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
23002 ++ return 0;
23003 ++ } else if (unlikely(!(mode & GR_EXEC))) {
23004 ++ return 0;
23005 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
23006 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
23007 ++ return 1;
23008 ++ }
23009 ++
23010 ++ return 1;
23011 ++}
23012 ++
23013 ++int
23014 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
23015 ++{
23016 ++ __u32 mode;
23017 ++
23018 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
23019 ++ return 1;
23020 ++
23021 ++ if (is_writable_mmap(file))
23022 ++ return 0;
23023 ++
23024 ++ mode =
23025 ++ gr_search_file(file->f_path.dentry,
23026 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
23027 ++ file->f_path.mnt);
23028 ++
23029 ++ if (!gr_tpe_allow(file))
23030 ++ return 0;
23031 ++
23032 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
23033 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
23034 ++ return 0;
23035 ++ } else if (unlikely(!(mode & GR_EXEC))) {
23036 ++ return 0;
23037 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
23038 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
23039 ++ return 1;
23040 ++ }
23041 ++
23042 ++ return 1;
23043 ++}
23044 ++
23045 ++void
23046 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
23047 ++{
23048 ++ unsigned long runtime;
23049 ++ unsigned long cputime;
23050 ++ unsigned int wday, cday;
23051 ++ __u8 whr, chr;
23052 ++ __u8 wmin, cmin;
23053 ++ __u8 wsec, csec;
23054 ++ struct timespec timeval;
23055 ++
23056 ++ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
23057 ++ !(task->acl->mode & GR_PROCACCT)))
23058 ++ return;
23059 ++
23060 ++ do_posix_clock_monotonic_gettime(&timeval);
23061 ++ runtime = timeval.tv_sec - task->start_time.tv_sec;
23062 ++ wday = runtime / (3600 * 24);
23063 ++ runtime -= wday * (3600 * 24);
23064 ++ whr = runtime / 3600;
23065 ++ runtime -= whr * 3600;
23066 ++ wmin = runtime / 60;
23067 ++ runtime -= wmin * 60;
23068 ++ wsec = runtime;
23069 ++
23070 ++ cputime = (task->utime + task->stime) / HZ;
23071 ++ cday = cputime / (3600 * 24);
23072 ++ cputime -= cday * (3600 * 24);
23073 ++ chr = cputime / 3600;
23074 ++ cputime -= chr * 3600;
23075 ++ cmin = cputime / 60;
23076 ++ cputime -= cmin * 60;
23077 ++ csec = cputime;
23078 ++
23079 ++ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
23080 ++
23081 ++ return;
23082 ++}
23083 ++
23084 ++void gr_set_kernel_label(struct task_struct *task)
23085 ++{
23086 ++ if (gr_status & GR_READY) {
23087 ++ task->role = kernel_role;
23088 ++ task->acl = kernel_role->root_label;
23089 ++ }
23090 ++ return;
23091 ++}
23092 ++
23093 ++int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
23094 ++{
23095 ++ struct task_struct *task = current;
23096 ++ struct dentry *dentry = file->f_path.dentry;
23097 ++ struct vfsmount *mnt = file->f_path.mnt;
23098 ++ struct acl_object_label *obj, *tmp;
23099 ++ struct acl_subject_label *subj;
23100 ++ unsigned int bufsize;
23101 ++ int is_not_root;
23102 ++ char *path;
23103 ++
23104 ++ if (unlikely(!(gr_status & GR_READY)))
23105 ++ return 1;
23106 ++
23107 ++ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
23108 ++ return 1;
23109 ++
23110 ++ /* ignore Eric Biederman */
23111 ++ if (IS_PRIVATE(dentry->d_inode))
23112 ++ return 1;
23113 ++
23114 ++ subj = task->acl;
23115 ++ do {
23116 ++ obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
23117 ++ if (obj != NULL)
23118 ++ return (obj->mode & GR_FIND) ? 1 : 0;
23119 ++ } while ((subj = subj->parent_subject));
23120 ++
23121 ++ obj = chk_obj_label(dentry, mnt, task->acl);
23122 ++ if (obj->globbed == NULL)
23123 ++ return (obj->mode & GR_FIND) ? 1 : 0;
23124 ++
23125 ++ is_not_root = ((obj->filename[0] == '/') &&
23126 ++ (obj->filename[1] == '\0')) ? 0 : 1;
23127 ++ bufsize = PAGE_SIZE - namelen - is_not_root;
23128 ++
23129 ++ /* check bufsize > PAGE_SIZE || bufsize == 0 */
23130 ++ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
23131 ++ return 1;
23132 ++
23133 ++ preempt_disable();
23134 ++ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
23135 ++ bufsize);
23136 ++
23137 ++ bufsize = strlen(path);
23138 ++
23139 ++ /* if base is "/", don't append an additional slash */
23140 ++ if (is_not_root)
23141 ++ *(path + bufsize) = '/';
23142 ++ memcpy(path + bufsize + is_not_root, name, namelen);
23143 ++ *(path + bufsize + namelen + is_not_root) = '\0';
23144 ++
23145 ++ tmp = obj->globbed;
23146 ++ while (tmp) {
23147 ++ if (!glob_match(tmp->filename, path)) {
23148 ++ preempt_enable();
23149 ++ return (tmp->mode & GR_FIND) ? 1 : 0;
23150 ++ }
23151 ++ tmp = tmp->next;
23152 ++ }
23153 ++ preempt_enable();
23154 ++ return (obj->mode & GR_FIND) ? 1 : 0;
23155 ++}
23156 ++
23157 ++EXPORT_SYMBOL(gr_learn_resource);
23158 ++EXPORT_SYMBOL(gr_set_kernel_label);
23159 ++#ifdef CONFIG_SECURITY
23160 ++EXPORT_SYMBOL(gr_check_user_change);
23161 ++EXPORT_SYMBOL(gr_check_group_change);
23162 ++#endif
23163 ++
23164 +diff -urNp linux-2.6.27.10/grsecurity/gracl_cap.c linux-2.6.27.10/grsecurity/gracl_cap.c
23165 +--- linux-2.6.27.10/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
23166 ++++ linux-2.6.27.10/grsecurity/gracl_cap.c 2008-11-18 03:38:45.000000000 -0500
23167 +@@ -0,0 +1,129 @@
23168 ++#include <linux/kernel.h>
23169 ++#include <linux/module.h>
23170 ++#include <linux/sched.h>
23171 ++#include <linux/gracl.h>
23172 ++#include <linux/grsecurity.h>
23173 ++#include <linux/grinternal.h>
23174 ++
23175 ++static const char *captab_log[] = {
23176 ++ "CAP_CHOWN",
23177 ++ "CAP_DAC_OVERRIDE",
23178 ++ "CAP_DAC_READ_SEARCH",
23179 ++ "CAP_FOWNER",
23180 ++ "CAP_FSETID",
23181 ++ "CAP_KILL",
23182 ++ "CAP_SETGID",
23183 ++ "CAP_SETUID",
23184 ++ "CAP_SETPCAP",
23185 ++ "CAP_LINUX_IMMUTABLE",
23186 ++ "CAP_NET_BIND_SERVICE",
23187 ++ "CAP_NET_BROADCAST",
23188 ++ "CAP_NET_ADMIN",
23189 ++ "CAP_NET_RAW",
23190 ++ "CAP_IPC_LOCK",
23191 ++ "CAP_IPC_OWNER",
23192 ++ "CAP_SYS_MODULE",
23193 ++ "CAP_SYS_RAWIO",
23194 ++ "CAP_SYS_CHROOT",
23195 ++ "CAP_SYS_PTRACE",
23196 ++ "CAP_SYS_PACCT",
23197 ++ "CAP_SYS_ADMIN",
23198 ++ "CAP_SYS_BOOT",
23199 ++ "CAP_SYS_NICE",
23200 ++ "CAP_SYS_RESOURCE",
23201 ++ "CAP_SYS_TIME",
23202 ++ "CAP_SYS_TTY_CONFIG",
23203 ++ "CAP_MKNOD",
23204 ++ "CAP_LEASE",
23205 ++ "CAP_AUDIT_WRITE",
23206 ++ "CAP_AUDIT_CONTROL",
23207 ++ "CAP_SETFCAP",
23208 ++ "CAP_MAC_OVERRIDE",
23209 ++ "CAP_MAC_ADMIN"
23210 ++};
23211 ++
23212 ++EXPORT_SYMBOL(gr_task_is_capable);
23213 ++EXPORT_SYMBOL(gr_is_capable_nolog);
23214 ++
23215 ++int
23216 ++gr_task_is_capable(struct task_struct *task, const int cap)
23217 ++{
23218 ++ struct acl_subject_label *curracl;
23219 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
23220 ++
23221 ++ if (!gr_acl_is_enabled())
23222 ++ return 1;
23223 ++
23224 ++ curracl = task->acl;
23225 ++
23226 ++ cap_drop = curracl->cap_lower;
23227 ++ cap_mask = curracl->cap_mask;
23228 ++
23229 ++ while ((curracl = curracl->parent_subject)) {
23230 ++ /* if the cap isn't specified in the current computed mask but is specified in the
23231 ++ current level subject, and is lowered in the current level subject, then add
23232 ++ it to the set of dropped capabilities
23233 ++ otherwise, add the current level subject's mask to the current computed mask
23234 ++ */
23235 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
23236 ++ cap_raise(cap_mask, cap);
23237 ++ if (cap_raised(curracl->cap_lower, cap))
23238 ++ cap_raise(cap_drop, cap);
23239 ++ }
23240 ++ }
23241 ++
23242 ++ if (!cap_raised(cap_drop, cap))
23243 ++ return 1;
23244 ++
23245 ++ curracl = task->acl;
23246 ++
23247 ++ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
23248 ++ && cap_raised(task->cap_effective, cap)) {
23249 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
23250 ++ task->role->roletype, task->uid,
23251 ++ task->gid, task->exec_file ?
23252 ++ gr_to_filename(task->exec_file->f_path.dentry,
23253 ++ task->exec_file->f_path.mnt) : curracl->filename,
23254 ++ curracl->filename, 0UL,
23255 ++ 0UL, "", (unsigned long) cap, NIPQUAD(task->signal->curr_ip));
23256 ++ return 1;
23257 ++ }
23258 ++
23259 ++ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(task->cap_effective, cap))
23260 ++ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
23261 ++ return 0;
23262 ++}
23263 ++
23264 ++int
23265 ++gr_is_capable_nolog(const int cap)
23266 ++{
23267 ++ struct acl_subject_label *curracl;
23268 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
23269 ++
23270 ++ if (!gr_acl_is_enabled())
23271 ++ return 1;
23272 ++
23273 ++ curracl = current->acl;
23274 ++
23275 ++ cap_drop = curracl->cap_lower;
23276 ++ cap_mask = curracl->cap_mask;
23277 ++
23278 ++ while ((curracl = curracl->parent_subject)) {
23279 ++ /* if the cap isn't specified in the current computed mask but is specified in the
23280 ++ current level subject, and is lowered in the current level subject, then add
23281 ++ it to the set of dropped capabilities
23282 ++ otherwise, add the current level subject's mask to the current computed mask
23283 ++ */
23284 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
23285 ++ cap_raise(cap_mask, cap);
23286 ++ if (cap_raised(curracl->cap_lower, cap))
23287 ++ cap_raise(cap_drop, cap);
23288 ++ }
23289 ++ }
23290 ++
23291 ++ if (!cap_raised(cap_drop, cap))
23292 ++ return 1;
23293 ++
23294 ++ return 0;
23295 ++}
23296 ++
23297 +diff -urNp linux-2.6.27.10/grsecurity/gracl_fs.c linux-2.6.27.10/grsecurity/gracl_fs.c
23298 +--- linux-2.6.27.10/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
23299 ++++ linux-2.6.27.10/grsecurity/gracl_fs.c 2008-11-18 03:38:45.000000000 -0500
23300 +@@ -0,0 +1,423 @@
23301 ++#include <linux/kernel.h>
23302 ++#include <linux/sched.h>
23303 ++#include <linux/types.h>
23304 ++#include <linux/fs.h>
23305 ++#include <linux/file.h>
23306 ++#include <linux/stat.h>
23307 ++#include <linux/grsecurity.h>
23308 ++#include <linux/grinternal.h>
23309 ++#include <linux/gracl.h>
23310 ++
23311 ++__u32
23312 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
23313 ++ const struct vfsmount * mnt)
23314 ++{
23315 ++ __u32 mode;
23316 ++
23317 ++ if (unlikely(!dentry->d_inode))
23318 ++ return GR_FIND;
23319 ++
23320 ++ mode =
23321 ++ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
23322 ++
23323 ++ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
23324 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
23325 ++ return mode;
23326 ++ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
23327 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
23328 ++ return 0;
23329 ++ } else if (unlikely(!(mode & GR_FIND)))
23330 ++ return 0;
23331 ++
23332 ++ return GR_FIND;
23333 ++}
23334 ++
23335 ++__u32
23336 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
23337 ++ const int fmode)
23338 ++{
23339 ++ __u32 reqmode = GR_FIND;
23340 ++ __u32 mode;
23341 ++
23342 ++ if (unlikely(!dentry->d_inode))
23343 ++ return reqmode;
23344 ++
23345 ++ if (unlikely(fmode & O_APPEND))
23346 ++ reqmode |= GR_APPEND;
23347 ++ else if (unlikely(fmode & FMODE_WRITE))
23348 ++ reqmode |= GR_WRITE;
23349 ++ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
23350 ++ reqmode |= GR_READ;
23351 ++
23352 ++ mode =
23353 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
23354 ++ mnt);
23355 ++
23356 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
23357 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
23358 ++ reqmode & GR_READ ? " reading" : "",
23359 ++ reqmode & GR_WRITE ? " writing" : reqmode &
23360 ++ GR_APPEND ? " appending" : "");
23361 ++ return reqmode;
23362 ++ } else
23363 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
23364 ++ {
23365 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
23366 ++ reqmode & GR_READ ? " reading" : "",
23367 ++ reqmode & GR_WRITE ? " writing" : reqmode &
23368 ++ GR_APPEND ? " appending" : "");
23369 ++ return 0;
23370 ++ } else if (unlikely((mode & reqmode) != reqmode))
23371 ++ return 0;
23372 ++
23373 ++ return reqmode;
23374 ++}
23375 ++
23376 ++__u32
23377 ++gr_acl_handle_creat(const struct dentry * dentry,
23378 ++ const struct dentry * p_dentry,
23379 ++ const struct vfsmount * p_mnt, const int fmode,
23380 ++ const int imode)
23381 ++{
23382 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
23383 ++ __u32 mode;
23384 ++
23385 ++ if (unlikely(fmode & O_APPEND))
23386 ++ reqmode |= GR_APPEND;
23387 ++ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
23388 ++ reqmode |= GR_READ;
23389 ++ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
23390 ++ reqmode |= GR_SETID;
23391 ++
23392 ++ mode =
23393 ++ gr_check_create(dentry, p_dentry, p_mnt,
23394 ++ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
23395 ++
23396 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
23397 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
23398 ++ reqmode & GR_READ ? " reading" : "",
23399 ++ reqmode & GR_WRITE ? " writing" : reqmode &
23400 ++ GR_APPEND ? " appending" : "");
23401 ++ return reqmode;
23402 ++ } else
23403 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
23404 ++ {
23405 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
23406 ++ reqmode & GR_READ ? " reading" : "",
23407 ++ reqmode & GR_WRITE ? " writing" : reqmode &
23408 ++ GR_APPEND ? " appending" : "");
23409 ++ return 0;
23410 ++ } else if (unlikely((mode & reqmode) != reqmode))
23411 ++ return 0;
23412 ++
23413 ++ return reqmode;
23414 ++}
23415 ++
23416 ++__u32
23417 ++gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
23418 ++ const int fmode)
23419 ++{
23420 ++ __u32 mode, reqmode = GR_FIND;
23421 ++
23422 ++ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
23423 ++ reqmode |= GR_EXEC;
23424 ++ if (fmode & S_IWOTH)
23425 ++ reqmode |= GR_WRITE;
23426 ++ if (fmode & S_IROTH)
23427 ++ reqmode |= GR_READ;
23428 ++
23429 ++ mode =
23430 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
23431 ++ mnt);
23432 ++
23433 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
23434 ++ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
23435 ++ reqmode & GR_READ ? " reading" : "",
23436 ++ reqmode & GR_WRITE ? " writing" : "",
23437 ++ reqmode & GR_EXEC ? " executing" : "");
23438 ++ return reqmode;
23439 ++ } else
23440 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
23441 ++ {
23442 ++ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
23443 ++ reqmode & GR_READ ? " reading" : "",
23444 ++ reqmode & GR_WRITE ? " writing" : "",
23445 ++ reqmode & GR_EXEC ? " executing" : "");
23446 ++ return 0;
23447 ++ } else if (unlikely((mode & reqmode) != reqmode))
23448 ++ return 0;
23449 ++
23450 ++ return reqmode;
23451 ++}
23452 ++
23453 ++static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
23454 ++{
23455 ++ __u32 mode;
23456 ++
23457 ++ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
23458 ++
23459 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
23460 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
23461 ++ return mode;
23462 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
23463 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
23464 ++ return 0;
23465 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
23466 ++ return 0;
23467 ++
23468 ++ return (reqmode);
23469 ++}
23470 ++
23471 ++__u32
23472 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
23473 ++{
23474 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
23475 ++}
23476 ++
23477 ++__u32
23478 ++gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
23479 ++{
23480 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
23481 ++}
23482 ++
23483 ++__u32
23484 ++gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
23485 ++{
23486 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
23487 ++}
23488 ++
23489 ++__u32
23490 ++gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
23491 ++{
23492 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
23493 ++}
23494 ++
23495 ++__u32
23496 ++gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
23497 ++ mode_t mode)
23498 ++{
23499 ++ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
23500 ++ return 1;
23501 ++
23502 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
23503 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
23504 ++ GR_FCHMOD_ACL_MSG);
23505 ++ } else {
23506 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
23507 ++ }
23508 ++}
23509 ++
23510 ++__u32
23511 ++gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
23512 ++ mode_t mode)
23513 ++{
23514 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
23515 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
23516 ++ GR_CHMOD_ACL_MSG);
23517 ++ } else {
23518 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
23519 ++ }
23520 ++}
23521 ++
23522 ++__u32
23523 ++gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
23524 ++{
23525 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
23526 ++}
23527 ++
23528 ++__u32
23529 ++gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
23530 ++{
23531 ++ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
23532 ++}
23533 ++
23534 ++__u32
23535 ++gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
23536 ++{
23537 ++ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
23538 ++ GR_UNIXCONNECT_ACL_MSG);
23539 ++}
23540 ++
23541 ++/* hardlinks require at minimum create permission,
23542 ++ any additional privilege required is based on the
23543 ++ privilege of the file being linked to
23544 ++*/
23545 ++__u32
23546 ++gr_acl_handle_link(const struct dentry * new_dentry,
23547 ++ const struct dentry * parent_dentry,
23548 ++ const struct vfsmount * parent_mnt,
23549 ++ const struct dentry * old_dentry,
23550 ++ const struct vfsmount * old_mnt, const char *to)
23551 ++{
23552 ++ __u32 mode;
23553 ++ __u32 needmode = GR_CREATE | GR_LINK;
23554 ++ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
23555 ++
23556 ++ mode =
23557 ++ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
23558 ++ old_mnt);
23559 ++
23560 ++ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
23561 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
23562 ++ return mode;
23563 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
23564 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
23565 ++ return 0;
23566 ++ } else if (unlikely((mode & needmode) != needmode))
23567 ++ return 0;
23568 ++
23569 ++ return 1;
23570 ++}
23571 ++
23572 ++__u32
23573 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
23574 ++ const struct dentry * parent_dentry,
23575 ++ const struct vfsmount * parent_mnt, const char *from)
23576 ++{
23577 ++ __u32 needmode = GR_WRITE | GR_CREATE;
23578 ++ __u32 mode;
23579 ++
23580 ++ mode =
23581 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
23582 ++ GR_CREATE | GR_AUDIT_CREATE |
23583 ++ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
23584 ++
23585 ++ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
23586 ++ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
23587 ++ return mode;
23588 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
23589 ++ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
23590 ++ return 0;
23591 ++ } else if (unlikely((mode & needmode) != needmode))
23592 ++ return 0;
23593 ++
23594 ++ return (GR_WRITE | GR_CREATE);
23595 ++}
23596 ++
23597 ++static __u32 generic_fs_create_handler(const struct dentry *new_dentry, const struct dentry *parent_dentry, const struct vfsmount *parent_mnt, __u32 reqmode, const char *fmt)
23598 ++{
23599 ++ __u32 mode;
23600 ++
23601 ++ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
23602 ++
23603 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
23604 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
23605 ++ return mode;
23606 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
23607 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
23608 ++ return 0;
23609 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
23610 ++ return 0;
23611 ++
23612 ++ return (reqmode);
23613 ++}
23614 ++
23615 ++__u32
23616 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
23617 ++ const struct dentry * parent_dentry,
23618 ++ const struct vfsmount * parent_mnt,
23619 ++ const int mode)
23620 ++{
23621 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
23622 ++ if (unlikely(mode & (S_ISUID | S_ISGID)))
23623 ++ reqmode |= GR_SETID;
23624 ++
23625 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
23626 ++ reqmode, GR_MKNOD_ACL_MSG);
23627 ++}
23628 ++
23629 ++__u32
23630 ++gr_acl_handle_mkdir(const struct dentry *new_dentry,
23631 ++ const struct dentry *parent_dentry,
23632 ++ const struct vfsmount *parent_mnt)
23633 ++{
23634 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
23635 ++ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
23636 ++}
23637 ++
23638 ++#define RENAME_CHECK_SUCCESS(old, new) \
23639 ++ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
23640 ++ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
23641 ++
23642 ++int
23643 ++gr_acl_handle_rename(struct dentry *new_dentry,
23644 ++ struct dentry *parent_dentry,
23645 ++ const struct vfsmount *parent_mnt,
23646 ++ struct dentry *old_dentry,
23647 ++ struct inode *old_parent_inode,
23648 ++ struct vfsmount *old_mnt, const char *newname)
23649 ++{
23650 ++ __u32 comp1, comp2;
23651 ++ int error = 0;
23652 ++
23653 ++ if (unlikely(!gr_acl_is_enabled()))
23654 ++ return 0;
23655 ++
23656 ++ if (!new_dentry->d_inode) {
23657 ++ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
23658 ++ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
23659 ++ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
23660 ++ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
23661 ++ GR_DELETE | GR_AUDIT_DELETE |
23662 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
23663 ++ GR_SUPPRESS, old_mnt);
23664 ++ } else {
23665 ++ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
23666 ++ GR_CREATE | GR_DELETE |
23667 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
23668 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
23669 ++ GR_SUPPRESS, parent_mnt);
23670 ++ comp2 =
23671 ++ gr_search_file(old_dentry,
23672 ++ GR_READ | GR_WRITE | GR_AUDIT_READ |
23673 ++ GR_DELETE | GR_AUDIT_DELETE |
23674 ++ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
23675 ++ }
23676 ++
23677 ++ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
23678 ++ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
23679 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
23680 ++ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
23681 ++ && !(comp2 & GR_SUPPRESS)) {
23682 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
23683 ++ error = -EACCES;
23684 ++ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
23685 ++ error = -EACCES;
23686 ++
23687 ++ return error;
23688 ++}
23689 ++
23690 ++void
23691 ++gr_acl_handle_exit(void)
23692 ++{
23693 ++ u16 id;
23694 ++ char *rolename;
23695 ++ struct file *exec_file;
23696 ++
23697 ++ if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
23698 ++ id = current->acl_role_id;
23699 ++ rolename = current->role->rolename;
23700 ++ gr_set_acls(1);
23701 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
23702 ++ }
23703 ++
23704 ++ write_lock(&grsec_exec_file_lock);
23705 ++ exec_file = current->exec_file;
23706 ++ current->exec_file = NULL;
23707 ++ write_unlock(&grsec_exec_file_lock);
23708 ++
23709 ++ if (exec_file)
23710 ++ fput(exec_file);
23711 ++}
23712 ++
23713 ++int
23714 ++gr_acl_handle_procpidmem(const struct task_struct *task)
23715 ++{
23716 ++ if (unlikely(!gr_acl_is_enabled()))
23717 ++ return 0;
23718 ++
23719 ++ if (task != current && task->acl->mode & GR_PROTPROCFD)
23720 ++ return -EACCES;
23721 ++
23722 ++ return 0;
23723 ++}
23724 +diff -urNp linux-2.6.27.10/grsecurity/gracl_ip.c linux-2.6.27.10/grsecurity/gracl_ip.c
23725 +--- linux-2.6.27.10/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
23726 ++++ linux-2.6.27.10/grsecurity/gracl_ip.c 2008-11-18 03:38:45.000000000 -0500
23727 +@@ -0,0 +1,313 @@
23728 ++#include <linux/kernel.h>
23729 ++#include <asm/uaccess.h>
23730 ++#include <asm/errno.h>
23731 ++#include <net/sock.h>
23732 ++#include <linux/file.h>
23733 ++#include <linux/fs.h>
23734 ++#include <linux/net.h>
23735 ++#include <linux/in.h>
23736 ++#include <linux/skbuff.h>
23737 ++#include <linux/ip.h>
23738 ++#include <linux/udp.h>
23739 ++#include <linux/smp_lock.h>
23740 ++#include <linux/types.h>
23741 ++#include <linux/sched.h>
23742 ++#include <linux/netdevice.h>
23743 ++#include <linux/inetdevice.h>
23744 ++#include <linux/gracl.h>
23745 ++#include <linux/grsecurity.h>
23746 ++#include <linux/grinternal.h>
23747 ++
23748 ++#define GR_BIND 0x01
23749 ++#define GR_CONNECT 0x02
23750 ++#define GR_INVERT 0x04
23751 ++
23752 ++static const char * gr_protocols[256] = {
23753 ++ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
23754 ++ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
23755 ++ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
23756 ++ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
23757 ++ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
23758 ++ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
23759 ++ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
23760 ++ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
23761 ++ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
23762 ++ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
23763 ++ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
23764 ++ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
23765 ++ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
23766 ++ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
23767 ++ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
23768 ++ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
23769 ++ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
23770 ++ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
23771 ++ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
23772 ++ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
23773 ++ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
23774 ++ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
23775 ++ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
23776 ++ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
23777 ++ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
23778 ++ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
23779 ++ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
23780 ++ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
23781 ++ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
23782 ++ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
23783 ++ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
23784 ++ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
23785 ++ };
23786 ++
23787 ++static const char * gr_socktypes[11] = {
23788 ++ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
23789 ++ "unknown:7", "unknown:8", "unknown:9", "packet"
23790 ++ };
23791 ++
23792 ++const char *
23793 ++gr_proto_to_name(unsigned char proto)
23794 ++{
23795 ++ return gr_protocols[proto];
23796 ++}
23797 ++
23798 ++const char *
23799 ++gr_socktype_to_name(unsigned char type)
23800 ++{
23801 ++ return gr_socktypes[type];
23802 ++}
23803 ++
23804 ++int
23805 ++gr_search_socket(const int domain, const int type, const int protocol)
23806 ++{
23807 ++ struct acl_subject_label *curr;
23808 ++
23809 ++ if (unlikely(!gr_acl_is_enabled()))
23810 ++ goto exit;
23811 ++
23812 ++ if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET)
23813 ++ || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255))
23814 ++ goto exit; // let the kernel handle it
23815 ++
23816 ++ curr = current->acl;
23817 ++
23818 ++ if (!curr->ips)
23819 ++ goto exit;
23820 ++
23821 ++ if ((curr->ip_type & (1 << type)) &&
23822 ++ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
23823 ++ goto exit;
23824 ++
23825 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
23826 ++ /* we don't place acls on raw sockets , and sometimes
23827 ++ dgram/ip sockets are opened for ioctl and not
23828 ++ bind/connect, so we'll fake a bind learn log */
23829 ++ if (type == SOCK_RAW || type == SOCK_PACKET) {
23830 ++ __u32 fakeip = 0;
23831 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
23832 ++ current->role->roletype, current->uid,
23833 ++ current->gid, current->exec_file ?
23834 ++ gr_to_filename(current->exec_file->f_path.dentry,
23835 ++ current->exec_file->f_path.mnt) :
23836 ++ curr->filename, curr->filename,
23837 ++ NIPQUAD(fakeip), 0, type,
23838 ++ protocol, GR_CONNECT,
23839 ++NIPQUAD(current->signal->curr_ip));
23840 ++ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
23841 ++ __u32 fakeip = 0;
23842 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
23843 ++ current->role->roletype, current->uid,
23844 ++ current->gid, current->exec_file ?
23845 ++ gr_to_filename(current->exec_file->f_path.dentry,
23846 ++ current->exec_file->f_path.mnt) :
23847 ++ curr->filename, curr->filename,
23848 ++ NIPQUAD(fakeip), 0, type,
23849 ++ protocol, GR_BIND, NIPQUAD(current->signal->curr_ip));
23850 ++ }
23851 ++ /* we'll log when they use connect or bind */
23852 ++ goto exit;
23853 ++ }
23854 ++
23855 ++ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, "inet",
23856 ++ gr_socktype_to_name(type), gr_proto_to_name(protocol));
23857 ++
23858 ++ return 0;
23859 ++ exit:
23860 ++ return 1;
23861 ++}
23862 ++
23863 ++int check_ip_policy(struct acl_ip_label *ip, __u32 ip_addr, __u16 ip_port, __u8 protocol, const int mode, const int type, __u32 our_addr, __u32 our_netmask)
23864 ++{
23865 ++ if ((ip->mode & mode) &&
23866 ++ (ip_port >= ip->low) &&
23867 ++ (ip_port <= ip->high) &&
23868 ++ ((ntohl(ip_addr) & our_netmask) ==
23869 ++ (ntohl(our_addr) & our_netmask))
23870 ++ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
23871 ++ && (ip->type & (1 << type))) {
23872 ++ if (ip->mode & GR_INVERT)
23873 ++ return 2; // specifically denied
23874 ++ else
23875 ++ return 1; // allowed
23876 ++ }
23877 ++
23878 ++ return 0; // not specifically allowed, may continue parsing
23879 ++}
23880 ++
23881 ++static int
23882 ++gr_search_connectbind(const int mode, const struct sock *sk,
23883 ++ const struct sockaddr_in *addr, const int type)
23884 ++{
23885 ++ char iface[IFNAMSIZ] = {0};
23886 ++ struct acl_subject_label *curr;
23887 ++ struct acl_ip_label *ip;
23888 ++ struct net_device *dev;
23889 ++ struct in_device *idev;
23890 ++ unsigned long i;
23891 ++ int ret;
23892 ++ __u32 ip_addr = 0;
23893 ++ __u32 our_addr;
23894 ++ __u32 our_netmask;
23895 ++ char *p;
23896 ++ __u16 ip_port = 0;
23897 ++
23898 ++ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
23899 ++ return 1;
23900 ++
23901 ++ curr = current->acl;
23902 ++
23903 ++ if (!curr->ips)
23904 ++ return 1;
23905 ++
23906 ++ ip_addr = addr->sin_addr.s_addr;
23907 ++ ip_port = ntohs(addr->sin_port);
23908 ++
23909 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
23910 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
23911 ++ current->role->roletype, current->uid,
23912 ++ current->gid, current->exec_file ?
23913 ++ gr_to_filename(current->exec_file->f_path.dentry,
23914 ++ current->exec_file->f_path.mnt) :
23915 ++ curr->filename, curr->filename,
23916 ++ NIPQUAD(ip_addr), ip_port, type,
23917 ++ sk->sk_protocol, mode, NIPQUAD(current->signal->curr_ip));
23918 ++ return 1;
23919 ++ }
23920 ++
23921 ++ for (i = 0; i < curr->ip_num; i++) {
23922 ++ ip = *(curr->ips + i);
23923 ++ if (ip->iface != NULL) {
23924 ++ strncpy(iface, ip->iface, IFNAMSIZ - 1);
23925 ++ p = strchr(iface, ':');
23926 ++ if (p != NULL)
23927 ++ *p = '\0';
23928 ++ dev = dev_get_by_name(sock_net(sk), iface);
23929 ++ if (dev == NULL)
23930 ++ continue;
23931 ++ idev = in_dev_get(dev);
23932 ++ if (idev == NULL) {
23933 ++ dev_put(dev);
23934 ++ continue;
23935 ++ }
23936 ++ rcu_read_lock();
23937 ++ for_ifa(idev) {
23938 ++ if (!strcmp(ip->iface, ifa->ifa_label)) {
23939 ++ our_addr = ifa->ifa_address;
23940 ++ our_netmask = 0xffffffff;
23941 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
23942 ++ if (ret == 1) {
23943 ++ rcu_read_unlock();
23944 ++ in_dev_put(idev);
23945 ++ dev_put(dev);
23946 ++ return 1;
23947 ++ } else if (ret == 2) {
23948 ++ rcu_read_unlock();
23949 ++ in_dev_put(idev);
23950 ++ dev_put(dev);
23951 ++ goto denied;
23952 ++ }
23953 ++ }
23954 ++ } endfor_ifa(idev);
23955 ++ rcu_read_unlock();
23956 ++ in_dev_put(idev);
23957 ++ dev_put(dev);
23958 ++ } else {
23959 ++ our_addr = ip->addr;
23960 ++ our_netmask = ip->netmask;
23961 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
23962 ++ if (ret == 1)
23963 ++ return 1;
23964 ++ else if (ret == 2)
23965 ++ goto denied;
23966 ++ }
23967 ++ }
23968 ++
23969 ++denied:
23970 ++ if (mode == GR_BIND)
23971 ++ gr_log_int5_str2(GR_DONT_AUDIT, GR_BIND_ACL_MSG, NIPQUAD(ip_addr), ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
23972 ++ else if (mode == GR_CONNECT)
23973 ++ gr_log_int5_str2(GR_DONT_AUDIT, GR_CONNECT_ACL_MSG, NIPQUAD(ip_addr), ip_port, gr_socktype_to_name(type), gr_proto_to_name(sk->sk_protocol));
23974 ++
23975 ++ return 0;
23976 ++}
23977 ++
23978 ++int
23979 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
23980 ++{
23981 ++ return gr_search_connectbind(GR_CONNECT, sock->sk, addr, sock->type);
23982 ++}
23983 ++
23984 ++int
23985 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
23986 ++{
23987 ++ return gr_search_connectbind(GR_BIND, sock->sk, addr, sock->type);
23988 ++}
23989 ++
23990 ++int gr_search_listen(const struct socket *sock)
23991 ++{
23992 ++ struct sock *sk = sock->sk;
23993 ++ struct sockaddr_in addr;
23994 ++
23995 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
23996 ++ addr.sin_port = inet_sk(sk)->sport;
23997 ++
23998 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
23999 ++}
24000 ++
24001 ++int gr_search_accept(const struct socket *sock)
24002 ++{
24003 ++ struct sock *sk = sock->sk;
24004 ++ struct sockaddr_in addr;
24005 ++
24006 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
24007 ++ addr.sin_port = inet_sk(sk)->sport;
24008 ++
24009 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
24010 ++}
24011 ++
24012 ++int
24013 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
24014 ++{
24015 ++ if (addr)
24016 ++ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
24017 ++ else {
24018 ++ struct sockaddr_in sin;
24019 ++ const struct inet_sock *inet = inet_sk(sk);
24020 ++
24021 ++ sin.sin_addr.s_addr = inet->daddr;
24022 ++ sin.sin_port = inet->dport;
24023 ++
24024 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
24025 ++ }
24026 ++}
24027 ++
24028 ++int
24029 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
24030 ++{
24031 ++ struct sockaddr_in sin;
24032 ++
24033 ++ if (unlikely(skb->len < sizeof (struct udphdr)))
24034 ++ return 1; // skip this packet
24035 ++
24036 ++ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
24037 ++ sin.sin_port = udp_hdr(skb)->source;
24038 ++
24039 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
24040 ++}
24041 +diff -urNp linux-2.6.27.10/grsecurity/gracl_learn.c linux-2.6.27.10/grsecurity/gracl_learn.c
24042 +--- linux-2.6.27.10/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
24043 ++++ linux-2.6.27.10/grsecurity/gracl_learn.c 2008-11-18 03:38:45.000000000 -0500
24044 +@@ -0,0 +1,211 @@
24045 ++#include <linux/kernel.h>
24046 ++#include <linux/mm.h>
24047 ++#include <linux/sched.h>
24048 ++#include <linux/poll.h>
24049 ++#include <linux/smp_lock.h>
24050 ++#include <linux/string.h>
24051 ++#include <linux/file.h>
24052 ++#include <linux/types.h>
24053 ++#include <linux/vmalloc.h>
24054 ++#include <linux/grinternal.h>
24055 ++
24056 ++extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
24057 ++ size_t count, loff_t *ppos);
24058 ++extern int gr_acl_is_enabled(void);
24059 ++
24060 ++static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
24061 ++static int gr_learn_attached;
24062 ++
24063 ++/* use a 512k buffer */
24064 ++#define LEARN_BUFFER_SIZE (512 * 1024)
24065 ++
24066 ++static DEFINE_SPINLOCK(gr_learn_lock);
24067 ++static DECLARE_MUTEX(gr_learn_user_sem);
24068 ++
24069 ++/* we need to maintain two buffers, so that the kernel context of grlearn
24070 ++ uses a semaphore around the userspace copying, and the other kernel contexts
24071 ++ use a spinlock when copying into the buffer, since they cannot sleep
24072 ++*/
24073 ++static char *learn_buffer;
24074 ++static char *learn_buffer_user;
24075 ++static int learn_buffer_len;
24076 ++static int learn_buffer_user_len;
24077 ++
24078 ++static ssize_t
24079 ++read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
24080 ++{
24081 ++ DECLARE_WAITQUEUE(wait, current);
24082 ++ ssize_t retval = 0;
24083 ++
24084 ++ add_wait_queue(&learn_wait, &wait);
24085 ++ set_current_state(TASK_INTERRUPTIBLE);
24086 ++ do {
24087 ++ down(&gr_learn_user_sem);
24088 ++ spin_lock(&gr_learn_lock);
24089 ++ if (learn_buffer_len)
24090 ++ break;
24091 ++ spin_unlock(&gr_learn_lock);
24092 ++ up(&gr_learn_user_sem);
24093 ++ if (file->f_flags & O_NONBLOCK) {
24094 ++ retval = -EAGAIN;
24095 ++ goto out;
24096 ++ }
24097 ++ if (signal_pending(current)) {
24098 ++ retval = -ERESTARTSYS;
24099 ++ goto out;
24100 ++ }
24101 ++
24102 ++ schedule();
24103 ++ } while (1);
24104 ++
24105 ++ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
24106 ++ learn_buffer_user_len = learn_buffer_len;
24107 ++ retval = learn_buffer_len;
24108 ++ learn_buffer_len = 0;
24109 ++
24110 ++ spin_unlock(&gr_learn_lock);
24111 ++
24112 ++ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
24113 ++ retval = -EFAULT;
24114 ++
24115 ++ up(&gr_learn_user_sem);
24116 ++out:
24117 ++ set_current_state(TASK_RUNNING);
24118 ++ remove_wait_queue(&learn_wait, &wait);
24119 ++ return retval;
24120 ++}
24121 ++
24122 ++static unsigned int
24123 ++poll_learn(struct file * file, poll_table * wait)
24124 ++{
24125 ++ poll_wait(file, &learn_wait, wait);
24126 ++
24127 ++ if (learn_buffer_len)
24128 ++ return (POLLIN | POLLRDNORM);
24129 ++
24130 ++ return 0;
24131 ++}
24132 ++
24133 ++void
24134 ++gr_clear_learn_entries(void)
24135 ++{
24136 ++ char *tmp;
24137 ++
24138 ++ down(&gr_learn_user_sem);
24139 ++ if (learn_buffer != NULL) {
24140 ++ spin_lock(&gr_learn_lock);
24141 ++ tmp = learn_buffer;
24142 ++ learn_buffer = NULL;
24143 ++ spin_unlock(&gr_learn_lock);
24144 ++ vfree(learn_buffer);
24145 ++ }
24146 ++ if (learn_buffer_user != NULL) {
24147 ++ vfree(learn_buffer_user);
24148 ++ learn_buffer_user = NULL;
24149 ++ }
24150 ++ learn_buffer_len = 0;
24151 ++ up(&gr_learn_user_sem);
24152 ++
24153 ++ return;
24154 ++}
24155 ++
24156 ++void
24157 ++gr_add_learn_entry(const char *fmt, ...)
24158 ++{
24159 ++ va_list args;
24160 ++ unsigned int len;
24161 ++
24162 ++ if (!gr_learn_attached)
24163 ++ return;
24164 ++
24165 ++ spin_lock(&gr_learn_lock);
24166 ++
24167 ++ /* leave a gap at the end so we know when it's "full" but don't have to
24168 ++ compute the exact length of the string we're trying to append
24169 ++ */
24170 ++ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
24171 ++ spin_unlock(&gr_learn_lock);
24172 ++ wake_up_interruptible(&learn_wait);
24173 ++ return;
24174 ++ }
24175 ++ if (learn_buffer == NULL) {
24176 ++ spin_unlock(&gr_learn_lock);
24177 ++ return;
24178 ++ }
24179 ++
24180 ++ va_start(args, fmt);
24181 ++ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
24182 ++ va_end(args);
24183 ++
24184 ++ learn_buffer_len += len + 1;
24185 ++
24186 ++ spin_unlock(&gr_learn_lock);
24187 ++ wake_up_interruptible(&learn_wait);
24188 ++
24189 ++ return;
24190 ++}
24191 ++
24192 ++static int
24193 ++open_learn(struct inode *inode, struct file *file)
24194 ++{
24195 ++ if (file->f_mode & FMODE_READ && gr_learn_attached)
24196 ++ return -EBUSY;
24197 ++ if (file->f_mode & FMODE_READ) {
24198 ++ int retval = 0;
24199 ++ down(&gr_learn_user_sem);
24200 ++ if (learn_buffer == NULL)
24201 ++ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
24202 ++ if (learn_buffer_user == NULL)
24203 ++ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
24204 ++ if (learn_buffer == NULL) {
24205 ++ retval = -ENOMEM;
24206 ++ goto out_error;
24207 ++ }
24208 ++ if (learn_buffer_user == NULL) {
24209 ++ retval = -ENOMEM;
24210 ++ goto out_error;
24211 ++ }
24212 ++ learn_buffer_len = 0;
24213 ++ learn_buffer_user_len = 0;
24214 ++ gr_learn_attached = 1;
24215 ++out_error:
24216 ++ up(&gr_learn_user_sem);
24217 ++ return retval;
24218 ++ }
24219 ++ return 0;
24220 ++}
24221 ++
24222 ++static int
24223 ++close_learn(struct inode *inode, struct file *file)
24224 ++{
24225 ++ char *tmp;
24226 ++
24227 ++ if (file->f_mode & FMODE_READ) {
24228 ++ down(&gr_learn_user_sem);
24229 ++ if (learn_buffer != NULL) {
24230 ++ spin_lock(&gr_learn_lock);
24231 ++ tmp = learn_buffer;
24232 ++ learn_buffer = NULL;
24233 ++ spin_unlock(&gr_learn_lock);
24234 ++ vfree(tmp);
24235 ++ }
24236 ++ if (learn_buffer_user != NULL) {
24237 ++ vfree(learn_buffer_user);
24238 ++ learn_buffer_user = NULL;
24239 ++ }
24240 ++ learn_buffer_len = 0;
24241 ++ learn_buffer_user_len = 0;
24242 ++ gr_learn_attached = 0;
24243 ++ up(&gr_learn_user_sem);
24244 ++ }
24245 ++
24246 ++ return 0;
24247 ++}
24248 ++
24249 ++struct file_operations grsec_fops = {
24250 ++ .read = read_learn,
24251 ++ .write = write_grsec_handler,
24252 ++ .open = open_learn,
24253 ++ .release = close_learn,
24254 ++ .poll = poll_learn,
24255 ++};
24256 +diff -urNp linux-2.6.27.10/grsecurity/gracl_res.c linux-2.6.27.10/grsecurity/gracl_res.c
24257 +--- linux-2.6.27.10/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
24258 ++++ linux-2.6.27.10/grsecurity/gracl_res.c 2008-11-18 03:38:45.000000000 -0500
24259 +@@ -0,0 +1,45 @@
24260 ++#include <linux/kernel.h>
24261 ++#include <linux/sched.h>
24262 ++#include <linux/gracl.h>
24263 ++#include <linux/grinternal.h>
24264 ++
24265 ++static const char *restab_log[] = {
24266 ++ [RLIMIT_CPU] = "RLIMIT_CPU",
24267 ++ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
24268 ++ [RLIMIT_DATA] = "RLIMIT_DATA",
24269 ++ [RLIMIT_STACK] = "RLIMIT_STACK",
24270 ++ [RLIMIT_CORE] = "RLIMIT_CORE",
24271 ++ [RLIMIT_RSS] = "RLIMIT_RSS",
24272 ++ [RLIMIT_NPROC] = "RLIMIT_NPROC",
24273 ++ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
24274 ++ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
24275 ++ [RLIMIT_AS] = "RLIMIT_AS",
24276 ++ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
24277 ++ [RLIMIT_LOCKS + 1] = "RLIMIT_CRASH"
24278 ++};
24279 ++
24280 ++void
24281 ++gr_log_resource(const struct task_struct *task,
24282 ++ const int res, const unsigned long wanted, const int gt)
24283 ++{
24284 ++ if (res == RLIMIT_NPROC &&
24285 ++ (cap_raised(task->cap_effective, CAP_SYS_ADMIN) ||
24286 ++ cap_raised(task->cap_effective, CAP_SYS_RESOURCE)))
24287 ++ return;
24288 ++ else if (res == RLIMIT_MEMLOCK &&
24289 ++ cap_raised(task->cap_effective, CAP_IPC_LOCK))
24290 ++ return;
24291 ++
24292 ++ if (!gr_acl_is_enabled() && !grsec_resource_logging)
24293 ++ return;
24294 ++
24295 ++ preempt_disable();
24296 ++
24297 ++ if (unlikely(((gt && wanted > task->signal->rlim[res].rlim_cur) ||
24298 ++ (!gt && wanted >= task->signal->rlim[res].rlim_cur)) &&
24299 ++ task->signal->rlim[res].rlim_cur != RLIM_INFINITY))
24300 ++ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], task->signal->rlim[res].rlim_cur);
24301 ++ preempt_enable_no_resched();
24302 ++
24303 ++ return;
24304 ++}
24305 +diff -urNp linux-2.6.27.10/grsecurity/gracl_segv.c linux-2.6.27.10/grsecurity/gracl_segv.c
24306 +--- linux-2.6.27.10/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
24307 ++++ linux-2.6.27.10/grsecurity/gracl_segv.c 2008-11-18 03:38:45.000000000 -0500
24308 +@@ -0,0 +1,304 @@
24309 ++#include <linux/kernel.h>
24310 ++#include <linux/mm.h>
24311 ++#include <asm/uaccess.h>
24312 ++#include <asm/errno.h>
24313 ++#include <asm/mman.h>
24314 ++#include <net/sock.h>
24315 ++#include <linux/file.h>
24316 ++#include <linux/fs.h>
24317 ++#include <linux/net.h>
24318 ++#include <linux/in.h>
24319 ++#include <linux/smp_lock.h>
24320 ++#include <linux/slab.h>
24321 ++#include <linux/types.h>
24322 ++#include <linux/sched.h>
24323 ++#include <linux/timer.h>
24324 ++#include <linux/gracl.h>
24325 ++#include <linux/grsecurity.h>
24326 ++#include <linux/grinternal.h>
24327 ++
24328 ++static struct crash_uid *uid_set;
24329 ++static unsigned short uid_used;
24330 ++static DEFINE_SPINLOCK(gr_uid_lock);
24331 ++extern rwlock_t gr_inode_lock;
24332 ++extern struct acl_subject_label *
24333 ++ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
24334 ++ struct acl_role_label *role);
24335 ++extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
24336 ++
24337 ++int
24338 ++gr_init_uidset(void)
24339 ++{
24340 ++ uid_set =
24341 ++ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
24342 ++ uid_used = 0;
24343 ++
24344 ++ return uid_set ? 1 : 0;
24345 ++}
24346 ++
24347 ++void
24348 ++gr_free_uidset(void)
24349 ++{
24350 ++ if (uid_set)
24351 ++ kfree(uid_set);
24352 ++
24353 ++ return;
24354 ++}
24355 ++
24356 ++int
24357 ++gr_find_uid(const uid_t uid)
24358 ++{
24359 ++ struct crash_uid *tmp = uid_set;
24360 ++ uid_t buid;
24361 ++ int low = 0, high = uid_used - 1, mid;
24362 ++
24363 ++ while (high >= low) {
24364 ++ mid = (low + high) >> 1;
24365 ++ buid = tmp[mid].uid;
24366 ++ if (buid == uid)
24367 ++ return mid;
24368 ++ if (buid > uid)
24369 ++ high = mid - 1;
24370 ++ if (buid < uid)
24371 ++ low = mid + 1;
24372 ++ }
24373 ++
24374 ++ return -1;
24375 ++}
24376 ++
24377 ++static __inline__ void
24378 ++gr_insertsort(void)
24379 ++{
24380 ++ unsigned short i, j;
24381 ++ struct crash_uid index;
24382 ++
24383 ++ for (i = 1; i < uid_used; i++) {
24384 ++ index = uid_set[i];
24385 ++ j = i;
24386 ++ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
24387 ++ uid_set[j] = uid_set[j - 1];
24388 ++ j--;
24389 ++ }
24390 ++ uid_set[j] = index;
24391 ++ }
24392 ++
24393 ++ return;
24394 ++}
24395 ++
24396 ++static __inline__ void
24397 ++gr_insert_uid(const uid_t uid, const unsigned long expires)
24398 ++{
24399 ++ int loc;
24400 ++
24401 ++ if (uid_used == GR_UIDTABLE_MAX)
24402 ++ return;
24403 ++
24404 ++ loc = gr_find_uid(uid);
24405 ++
24406 ++ if (loc >= 0) {
24407 ++ uid_set[loc].expires = expires;
24408 ++ return;
24409 ++ }
24410 ++
24411 ++ uid_set[uid_used].uid = uid;
24412 ++ uid_set[uid_used].expires = expires;
24413 ++ uid_used++;
24414 ++
24415 ++ gr_insertsort();
24416 ++
24417 ++ return;
24418 ++}
24419 ++
24420 ++void
24421 ++gr_remove_uid(const unsigned short loc)
24422 ++{
24423 ++ unsigned short i;
24424 ++
24425 ++ for (i = loc + 1; i < uid_used; i++)
24426 ++ uid_set[i - 1] = uid_set[i];
24427 ++
24428 ++ uid_used--;
24429 ++
24430 ++ return;
24431 ++}
24432 ++
24433 ++int
24434 ++gr_check_crash_uid(const uid_t uid)
24435 ++{
24436 ++ int loc;
24437 ++ int ret = 0;
24438 ++
24439 ++ if (unlikely(!gr_acl_is_enabled()))
24440 ++ return 0;
24441 ++
24442 ++ spin_lock(&gr_uid_lock);
24443 ++ loc = gr_find_uid(uid);
24444 ++
24445 ++ if (loc < 0)
24446 ++ goto out_unlock;
24447 ++
24448 ++ if (time_before_eq(uid_set[loc].expires, get_seconds()))
24449 ++ gr_remove_uid(loc);
24450 ++ else
24451 ++ ret = 1;
24452 ++
24453 ++out_unlock:
24454 ++ spin_unlock(&gr_uid_lock);
24455 ++ return ret;
24456 ++}
24457 ++
24458 ++static __inline__ int
24459 ++proc_is_setxid(const struct task_struct *task)
24460 ++{
24461 ++ if (task->uid != task->euid || task->uid != task->suid ||
24462 ++ task->uid != task->fsuid)
24463 ++ return 1;
24464 ++ if (task->gid != task->egid || task->gid != task->sgid ||
24465 ++ task->gid != task->fsgid)
24466 ++ return 1;
24467 ++
24468 ++ return 0;
24469 ++}
24470 ++static __inline__ int
24471 ++gr_fake_force_sig(int sig, struct task_struct *t)
24472 ++{
24473 ++ unsigned long int flags;
24474 ++ int ret, blocked, ignored;
24475 ++ struct k_sigaction *action;
24476 ++
24477 ++ spin_lock_irqsave(&t->sighand->siglock, flags);
24478 ++ action = &t->sighand->action[sig-1];
24479 ++ ignored = action->sa.sa_handler == SIG_IGN;
24480 ++ blocked = sigismember(&t->blocked, sig);
24481 ++ if (blocked || ignored) {
24482 ++ action->sa.sa_handler = SIG_DFL;
24483 ++ if (blocked) {
24484 ++ sigdelset(&t->blocked, sig);
24485 ++ recalc_sigpending_and_wake(t);
24486 ++ }
24487 ++ }
24488 ++ if (action->sa.sa_handler == SIG_DFL)
24489 ++ t->signal->flags &= ~SIGNAL_UNKILLABLE;
24490 ++ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
24491 ++
24492 ++ spin_unlock_irqrestore(&t->sighand->siglock, flags);
24493 ++
24494 ++ return ret;
24495 ++}
24496 ++
24497 ++void
24498 ++gr_handle_crash(struct task_struct *task, const int sig)
24499 ++{
24500 ++ struct acl_subject_label *curr;
24501 ++ struct acl_subject_label *curr2;
24502 ++ struct task_struct *tsk, *tsk2;
24503 ++
24504 ++ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
24505 ++ return;
24506 ++
24507 ++ if (unlikely(!gr_acl_is_enabled()))
24508 ++ return;
24509 ++
24510 ++ curr = task->acl;
24511 ++
24512 ++ if (!(curr->resmask & (1 << GR_CRASH_RES)))
24513 ++ return;
24514 ++
24515 ++ if (time_before_eq(curr->expires, get_seconds())) {
24516 ++ curr->expires = 0;
24517 ++ curr->crashes = 0;
24518 ++ }
24519 ++
24520 ++ curr->crashes++;
24521 ++
24522 ++ if (!curr->expires)
24523 ++ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
24524 ++
24525 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
24526 ++ time_after(curr->expires, get_seconds())) {
24527 ++ if (task->uid && proc_is_setxid(task)) {
24528 ++ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
24529 ++ spin_lock(&gr_uid_lock);
24530 ++ gr_insert_uid(task->uid, curr->expires);
24531 ++ spin_unlock(&gr_uid_lock);
24532 ++ curr->expires = 0;
24533 ++ curr->crashes = 0;
24534 ++ read_lock(&tasklist_lock);
24535 ++ do_each_thread(tsk2, tsk) {
24536 ++ if (tsk != task && tsk->uid == task->uid)
24537 ++ gr_fake_force_sig(SIGKILL, tsk);
24538 ++ } while_each_thread(tsk2, tsk);
24539 ++ read_unlock(&tasklist_lock);
24540 ++ } else {
24541 ++ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
24542 ++ read_lock(&tasklist_lock);
24543 ++ do_each_thread(tsk2, tsk) {
24544 ++ if (likely(tsk != task)) {
24545 ++ curr2 = tsk->acl;
24546 ++
24547 ++ if (curr2->device == curr->device &&
24548 ++ curr2->inode == curr->inode)
24549 ++ gr_fake_force_sig(SIGKILL, tsk);
24550 ++ }
24551 ++ } while_each_thread(tsk2, tsk);
24552 ++ read_unlock(&tasklist_lock);
24553 ++ }
24554 ++ }
24555 ++
24556 ++ return;
24557 ++}
24558 ++
24559 ++int
24560 ++gr_check_crash_exec(const struct file *filp)
24561 ++{
24562 ++ struct acl_subject_label *curr;
24563 ++
24564 ++ if (unlikely(!gr_acl_is_enabled()))
24565 ++ return 0;
24566 ++
24567 ++ read_lock(&gr_inode_lock);
24568 ++ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
24569 ++ filp->f_path.dentry->d_inode->i_sb->s_dev,
24570 ++ current->role);
24571 ++ read_unlock(&gr_inode_lock);
24572 ++
24573 ++ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
24574 ++ (!curr->crashes && !curr->expires))
24575 ++ return 0;
24576 ++
24577 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
24578 ++ time_after(curr->expires, get_seconds()))
24579 ++ return 1;
24580 ++ else if (time_before_eq(curr->expires, get_seconds())) {
24581 ++ curr->crashes = 0;
24582 ++ curr->expires = 0;
24583 ++ }
24584 ++
24585 ++ return 0;
24586 ++}
24587 ++
24588 ++void
24589 ++gr_handle_alertkill(struct task_struct *task)
24590 ++{
24591 ++ struct acl_subject_label *curracl;
24592 ++ __u32 curr_ip;
24593 ++ struct task_struct *p, *p2;
24594 ++
24595 ++ if (unlikely(!gr_acl_is_enabled()))
24596 ++ return;
24597 ++
24598 ++ curracl = task->acl;
24599 ++ curr_ip = task->signal->curr_ip;
24600 ++
24601 ++ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
24602 ++ read_lock(&tasklist_lock);
24603 ++ do_each_thread(p2, p) {
24604 ++ if (p->signal->curr_ip == curr_ip)
24605 ++ gr_fake_force_sig(SIGKILL, p);
24606 ++ } while_each_thread(p2, p);
24607 ++ read_unlock(&tasklist_lock);
24608 ++ } else if (curracl->mode & GR_KILLPROC)
24609 ++ gr_fake_force_sig(SIGKILL, task);
24610 ++
24611 ++ return;
24612 ++}
24613 +diff -urNp linux-2.6.27.10/grsecurity/gracl_shm.c linux-2.6.27.10/grsecurity/gracl_shm.c
24614 +--- linux-2.6.27.10/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
24615 ++++ linux-2.6.27.10/grsecurity/gracl_shm.c 2008-11-18 03:38:45.000000000 -0500
24616 +@@ -0,0 +1,33 @@
24617 ++#include <linux/kernel.h>
24618 ++#include <linux/mm.h>
24619 ++#include <linux/sched.h>
24620 ++#include <linux/file.h>
24621 ++#include <linux/ipc.h>
24622 ++#include <linux/gracl.h>
24623 ++#include <linux/grsecurity.h>
24624 ++#include <linux/grinternal.h>
24625 ++
24626 ++int
24627 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
24628 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
24629 ++{
24630 ++ struct task_struct *task;
24631 ++
24632 ++ if (!gr_acl_is_enabled())
24633 ++ return 1;
24634 ++
24635 ++ task = find_task_by_vpid(shm_cprid);
24636 ++
24637 ++ if (unlikely(!task))
24638 ++ task = find_task_by_vpid(shm_lapid);
24639 ++
24640 ++ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
24641 ++ (task->pid == shm_lapid)) &&
24642 ++ (task->acl->mode & GR_PROTSHM) &&
24643 ++ (task->acl != current->acl))) {
24644 ++ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
24645 ++ return 0;
24646 ++ }
24647 ++
24648 ++ return 1;
24649 ++}
24650 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chdir.c linux-2.6.27.10/grsecurity/grsec_chdir.c
24651 +--- linux-2.6.27.10/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
24652 ++++ linux-2.6.27.10/grsecurity/grsec_chdir.c 2008-11-18 03:38:45.000000000 -0500
24653 +@@ -0,0 +1,19 @@
24654 ++#include <linux/kernel.h>
24655 ++#include <linux/sched.h>
24656 ++#include <linux/fs.h>
24657 ++#include <linux/file.h>
24658 ++#include <linux/grsecurity.h>
24659 ++#include <linux/grinternal.h>
24660 ++
24661 ++void
24662 ++gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
24663 ++{
24664 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
24665 ++ if ((grsec_enable_chdir && grsec_enable_group &&
24666 ++ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
24667 ++ !grsec_enable_group)) {
24668 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
24669 ++ }
24670 ++#endif
24671 ++ return;
24672 ++}
24673 +diff -urNp linux-2.6.27.10/grsecurity/grsec_chroot.c linux-2.6.27.10/grsecurity/grsec_chroot.c
24674 +--- linux-2.6.27.10/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
24675 ++++ linux-2.6.27.10/grsecurity/grsec_chroot.c 2008-11-18 03:38:45.000000000 -0500
24676 +@@ -0,0 +1,336 @@
24677 ++#include <linux/kernel.h>
24678 ++#include <linux/module.h>
24679 ++#include <linux/sched.h>
24680 ++#include <linux/file.h>
24681 ++#include <linux/fs.h>
24682 ++#include <linux/mount.h>
24683 ++#include <linux/types.h>
24684 ++#include <linux/pid_namespace.h>
24685 ++#include <linux/grsecurity.h>
24686 ++#include <linux/grinternal.h>
24687 ++
24688 ++int
24689 ++gr_handle_chroot_unix(const pid_t pid)
24690 ++{
24691 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
24692 ++ struct pid *spid = NULL;
24693 ++
24694 ++ if (unlikely(!grsec_enable_chroot_unix))
24695 ++ return 1;
24696 ++
24697 ++ if (likely(!proc_is_chrooted(current)))
24698 ++ return 1;
24699 ++
24700 ++ read_lock(&tasklist_lock);
24701 ++
24702 ++ spid = find_vpid(pid);
24703 ++ if (spid) {
24704 ++ struct task_struct *p;
24705 ++ p = pid_task(spid, PIDTYPE_PID);
24706 ++ task_lock(p);
24707 ++ if (unlikely(!have_same_root(current, p))) {
24708 ++ task_unlock(p);
24709 ++ read_unlock(&tasklist_lock);
24710 ++ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
24711 ++ return 0;
24712 ++ }
24713 ++ task_unlock(p);
24714 ++ }
24715 ++ read_unlock(&tasklist_lock);
24716 ++#endif
24717 ++ return 1;
24718 ++}
24719 ++
24720 ++int
24721 ++gr_handle_chroot_nice(void)
24722 ++{
24723 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
24724 ++ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
24725 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
24726 ++ return -EPERM;
24727 ++ }
24728 ++#endif
24729 ++ return 0;
24730 ++}
24731 ++
24732 ++int
24733 ++gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
24734 ++{
24735 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
24736 ++ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
24737 ++ && proc_is_chrooted(current)) {
24738 ++ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
24739 ++ return -EACCES;
24740 ++ }
24741 ++#endif
24742 ++ return 0;
24743 ++}
24744 ++
24745 ++int
24746 ++gr_handle_chroot_rawio(const struct inode *inode)
24747 ++{
24748 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
24749 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
24750 ++ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
24751 ++ return 1;
24752 ++#endif
24753 ++ return 0;
24754 ++}
24755 ++
24756 ++int
24757 ++gr_pid_is_chrooted(struct task_struct *p)
24758 ++{
24759 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
24760 ++ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
24761 ++ return 0;
24762 ++
24763 ++ task_lock(p);
24764 ++ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
24765 ++ !have_same_root(current, p)) {
24766 ++ task_unlock(p);
24767 ++ return 1;
24768 ++ }
24769 ++ task_unlock(p);
24770 ++#endif
24771 ++ return 0;
24772 ++}
24773 ++
24774 ++EXPORT_SYMBOL(gr_pid_is_chrooted);
24775 ++
24776 ++#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
24777 ++int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
24778 ++{
24779 ++ struct dentry *dentry = (struct dentry *)u_dentry;
24780 ++ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
24781 ++ struct dentry *realroot;
24782 ++ struct vfsmount *realrootmnt;
24783 ++ struct dentry *currentroot;
24784 ++ struct vfsmount *currentmnt;
24785 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
24786 ++ int ret = 1;
24787 ++
24788 ++ read_lock(&reaper->fs->lock);
24789 ++ realrootmnt = mntget(reaper->fs->root.mnt);
24790 ++ realroot = dget(reaper->fs->root.dentry);
24791 ++ read_unlock(&reaper->fs->lock);
24792 ++
24793 ++ read_lock(&current->fs->lock);
24794 ++ currentmnt = mntget(current->fs->root.mnt);
24795 ++ currentroot = dget(current->fs->root.dentry);
24796 ++ read_unlock(&current->fs->lock);
24797 ++
24798 ++ spin_lock(&dcache_lock);
24799 ++ for (;;) {
24800 ++ if (unlikely((dentry == realroot && mnt == realrootmnt)
24801 ++ || (dentry == currentroot && mnt == currentmnt)))
24802 ++ break;
24803 ++ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
24804 ++ if (mnt->mnt_parent == mnt)
24805 ++ break;
24806 ++ dentry = mnt->mnt_mountpoint;
24807 ++ mnt = mnt->mnt_parent;
24808 ++ continue;
24809 ++ }
24810 ++ dentry = dentry->d_parent;
24811 ++ }
24812 ++ spin_unlock(&dcache_lock);
24813 ++
24814 ++ dput(currentroot);
24815 ++ mntput(currentmnt);
24816 ++
24817 ++ /* access is outside of chroot */
24818 ++ if (dentry == realroot && mnt == realrootmnt)
24819 ++ ret = 0;
24820 ++
24821 ++ dput(realroot);
24822 ++ mntput(realrootmnt);
24823 ++ return ret;
24824 ++}
24825 ++#endif
24826 ++
24827 ++int
24828 ++gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
24829 ++{
24830 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
24831 ++ if (!grsec_enable_chroot_fchdir)
24832 ++ return 1;
24833 ++
24834 ++ if (!proc_is_chrooted(current))
24835 ++ return 1;
24836 ++ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
24837 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
24838 ++ return 0;
24839 ++ }
24840 ++#endif
24841 ++ return 1;
24842 ++}
24843 ++
24844 ++int
24845 ++gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
24846 ++ const time_t shm_createtime)
24847 ++{
24848 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
24849 ++ struct pid *pid = NULL;
24850 ++ time_t starttime;
24851 ++
24852 ++ if (unlikely(!grsec_enable_chroot_shmat))
24853 ++ return 1;
24854 ++
24855 ++ if (likely(!proc_is_chrooted(current)))
24856 ++ return 1;
24857 ++
24858 ++ read_lock(&tasklist_lock);
24859 ++
24860 ++ pid = find_vpid(shm_cprid);
24861 ++ if (pid) {
24862 ++ struct task_struct *p;
24863 ++ p = pid_task(pid, PIDTYPE_PID);
24864 ++ task_lock(p);
24865 ++ starttime = p->start_time.tv_sec;
24866 ++ if (unlikely(!have_same_root(current, p) &&
24867 ++ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
24868 ++ task_unlock(p);
24869 ++ read_unlock(&tasklist_lock);
24870 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
24871 ++ return 0;
24872 ++ }
24873 ++ task_unlock(p);
24874 ++ } else {
24875 ++ pid = find_vpid(shm_lapid);
24876 ++ if (pid) {
24877 ++ struct task_struct *p;
24878 ++ p = pid_task(pid, PIDTYPE_PID);
24879 ++ task_lock(p);
24880 ++ if (unlikely(!have_same_root(current, p))) {
24881 ++ task_unlock(p);
24882 ++ read_unlock(&tasklist_lock);
24883 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
24884 ++ return 0;
24885 ++ }
24886 ++ task_unlock(p);
24887 ++ }
24888 ++ }
24889 ++
24890 ++ read_unlock(&tasklist_lock);
24891 ++#endif
24892 ++ return 1;
24893 ++}
24894 ++
24895 ++void
24896 ++gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
24897 ++{
24898 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
24899 ++ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
24900 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
24901 ++#endif
24902 ++ return;
24903 ++}
24904 ++
24905 ++int
24906 ++gr_handle_chroot_mknod(const struct dentry *dentry,
24907 ++ const struct vfsmount *mnt, const int mode)
24908 ++{
24909 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
24910 ++ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
24911 ++ proc_is_chrooted(current)) {
24912 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
24913 ++ return -EPERM;
24914 ++ }
24915 ++#endif
24916 ++ return 0;
24917 ++}
24918 ++
24919 ++int
24920 ++gr_handle_chroot_mount(const struct dentry *dentry,
24921 ++ const struct vfsmount *mnt, const char *dev_name)
24922 ++{
24923 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
24924 ++ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
24925 ++ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
24926 ++ return -EPERM;
24927 ++ }
24928 ++#endif
24929 ++ return 0;
24930 ++}
24931 ++
24932 ++int
24933 ++gr_handle_chroot_pivot(void)
24934 ++{
24935 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
24936 ++ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
24937 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
24938 ++ return -EPERM;
24939 ++ }
24940 ++#endif
24941 ++ return 0;
24942 ++}
24943 ++
24944 ++int
24945 ++gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
24946 ++{
24947 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
24948 ++ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
24949 ++ !gr_is_outside_chroot(dentry, mnt)) {
24950 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
24951 ++ return -EPERM;
24952 ++ }
24953 ++#endif
24954 ++ return 0;
24955 ++}
24956 ++
24957 ++void
24958 ++gr_handle_chroot_caps(struct task_struct *task)
24959 ++{
24960 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
24961 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
24962 ++ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
24963 ++ task->cap_permitted =
24964 ++ cap_drop(task->cap_permitted, chroot_caps);
24965 ++ task->cap_inheritable =
24966 ++ cap_drop(task->cap_inheritable, chroot_caps);
24967 ++ task->cap_effective =
24968 ++ cap_drop(task->cap_effective, chroot_caps);
24969 ++ }
24970 ++#endif
24971 ++ return;
24972 ++}
24973 ++
24974 ++int
24975 ++gr_handle_chroot_sysctl(const int op)
24976 ++{
24977 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
24978 ++ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
24979 ++ && (op & MAY_WRITE))
24980 ++ return -EACCES;
24981 ++#endif
24982 ++ return 0;
24983 ++}
24984 ++
24985 ++void
24986 ++gr_handle_chroot_chdir(struct path *path)
24987 ++{
24988 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
24989 ++ if (grsec_enable_chroot_chdir)
24990 ++ set_fs_pwd(current->fs, path);
24991 ++#endif
24992 ++ return;
24993 ++}
24994 ++
24995 ++int
24996 ++gr_handle_chroot_chmod(const struct dentry *dentry,
24997 ++ const struct vfsmount *mnt, const int mode)
24998 ++{
24999 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
25000 ++ if (grsec_enable_chroot_chmod &&
25001 ++ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
25002 ++ proc_is_chrooted(current)) {
25003 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
25004 ++ return -EPERM;
25005 ++ }
25006 ++#endif
25007 ++ return 0;
25008 ++}
25009 ++
25010 ++#ifdef CONFIG_SECURITY
25011 ++EXPORT_SYMBOL(gr_handle_chroot_caps);
25012 ++#endif
25013 +diff -urNp linux-2.6.27.10/grsecurity/grsec_disabled.c linux-2.6.27.10/grsecurity/grsec_disabled.c
25014 +--- linux-2.6.27.10/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
25015 ++++ linux-2.6.27.10/grsecurity/grsec_disabled.c 2008-11-18 03:38:45.000000000 -0500
25016 +@@ -0,0 +1,418 @@
25017 ++#include <linux/kernel.h>
25018 ++#include <linux/module.h>
25019 ++#include <linux/sched.h>
25020 ++#include <linux/file.h>
25021 ++#include <linux/fs.h>
25022 ++#include <linux/kdev_t.h>
25023 ++#include <linux/net.h>
25024 ++#include <linux/in.h>
25025 ++#include <linux/ip.h>
25026 ++#include <linux/skbuff.h>
25027 ++#include <linux/sysctl.h>
25028 ++
25029 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
25030 ++void
25031 ++pax_set_initial_flags(struct linux_binprm *bprm)
25032 ++{
25033 ++ return;
25034 ++}
25035 ++#endif
25036 ++
25037 ++#ifdef CONFIG_SYSCTL
25038 ++__u32
25039 ++gr_handle_sysctl(const struct ctl_table * table, const int op)
25040 ++{
25041 ++ return 0;
25042 ++}
25043 ++#endif
25044 ++
25045 ++int
25046 ++gr_acl_is_enabled(void)
25047 ++{
25048 ++ return 0;
25049 ++}
25050 ++
25051 ++int
25052 ++gr_handle_rawio(const struct inode *inode)
25053 ++{
25054 ++ return 0;
25055 ++}
25056 ++
25057 ++void
25058 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
25059 ++{
25060 ++ return;
25061 ++}
25062 ++
25063 ++int
25064 ++gr_handle_ptrace(struct task_struct *task, const long request)
25065 ++{
25066 ++ return 0;
25067 ++}
25068 ++
25069 ++int
25070 ++gr_handle_proc_ptrace(struct task_struct *task)
25071 ++{
25072 ++ return 0;
25073 ++}
25074 ++
25075 ++void
25076 ++gr_learn_resource(const struct task_struct *task,
25077 ++ const int res, const unsigned long wanted, const int gt)
25078 ++{
25079 ++ return;
25080 ++}
25081 ++
25082 ++int
25083 ++gr_set_acls(const int type)
25084 ++{
25085 ++ return 0;
25086 ++}
25087 ++
25088 ++int
25089 ++gr_check_hidden_task(const struct task_struct *tsk)
25090 ++{
25091 ++ return 0;
25092 ++}
25093 ++
25094 ++int
25095 ++gr_check_protected_task(const struct task_struct *task)
25096 ++{
25097 ++ return 0;
25098 ++}
25099 ++
25100 ++void
25101 ++gr_copy_label(struct task_struct *tsk)
25102 ++{
25103 ++ return;
25104 ++}
25105 ++
25106 ++void
25107 ++gr_set_pax_flags(struct task_struct *task)
25108 ++{
25109 ++ return;
25110 ++}
25111 ++
25112 ++int
25113 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
25114 ++{
25115 ++ return 0;
25116 ++}
25117 ++
25118 ++void
25119 ++gr_handle_delete(const ino_t ino, const dev_t dev)
25120 ++{
25121 ++ return;
25122 ++}
25123 ++
25124 ++void
25125 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
25126 ++{
25127 ++ return;
25128 ++}
25129 ++
25130 ++void
25131 ++gr_handle_crash(struct task_struct *task, const int sig)
25132 ++{
25133 ++ return;
25134 ++}
25135 ++
25136 ++int
25137 ++gr_check_crash_exec(const struct file *filp)
25138 ++{
25139 ++ return 0;
25140 ++}
25141 ++
25142 ++int
25143 ++gr_check_crash_uid(const uid_t uid)
25144 ++{
25145 ++ return 0;
25146 ++}
25147 ++
25148 ++void
25149 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
25150 ++ struct dentry *old_dentry,
25151 ++ struct dentry *new_dentry,
25152 ++ struct vfsmount *mnt, const __u8 replace)
25153 ++{
25154 ++ return;
25155 ++}
25156 ++
25157 ++int
25158 ++gr_search_socket(const int family, const int type, const int protocol)
25159 ++{
25160 ++ return 1;
25161 ++}
25162 ++
25163 ++int
25164 ++gr_search_connectbind(const int mode, const struct socket *sock,
25165 ++ const struct sockaddr_in *addr)
25166 ++{
25167 ++ return 1;
25168 ++}
25169 ++
25170 ++int
25171 ++gr_task_is_capable(struct task_struct *task, const int cap)
25172 ++{
25173 ++ return 1;
25174 ++}
25175 ++
25176 ++int
25177 ++gr_is_capable_nolog(const int cap)
25178 ++{
25179 ++ return 1;
25180 ++}
25181 ++
25182 ++void
25183 ++gr_handle_alertkill(struct task_struct *task)
25184 ++{
25185 ++ return;
25186 ++}
25187 ++
25188 ++__u32
25189 ++gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
25190 ++{
25191 ++ return 1;
25192 ++}
25193 ++
25194 ++__u32
25195 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
25196 ++ const struct vfsmount * mnt)
25197 ++{
25198 ++ return 1;
25199 ++}
25200 ++
25201 ++__u32
25202 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
25203 ++ const int fmode)
25204 ++{
25205 ++ return 1;
25206 ++}
25207 ++
25208 ++__u32
25209 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
25210 ++{
25211 ++ return 1;
25212 ++}
25213 ++
25214 ++__u32
25215 ++gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
25216 ++{
25217 ++ return 1;
25218 ++}
25219 ++
25220 ++int
25221 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
25222 ++ unsigned int *vm_flags)
25223 ++{
25224 ++ return 1;
25225 ++}
25226 ++
25227 ++__u32
25228 ++gr_acl_handle_truncate(const struct dentry * dentry,
25229 ++ const struct vfsmount * mnt)
25230 ++{
25231 ++ return 1;
25232 ++}
25233 ++
25234 ++__u32
25235 ++gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
25236 ++{
25237 ++ return 1;
25238 ++}
25239 ++
25240 ++__u32
25241 ++gr_acl_handle_access(const struct dentry * dentry,
25242 ++ const struct vfsmount * mnt, const int fmode)
25243 ++{
25244 ++ return 1;
25245 ++}
25246 ++
25247 ++__u32
25248 ++gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
25249 ++ mode_t mode)
25250 ++{
25251 ++ return 1;
25252 ++}
25253 ++
25254 ++__u32
25255 ++gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
25256 ++ mode_t mode)
25257 ++{
25258 ++ return 1;
25259 ++}
25260 ++
25261 ++__u32
25262 ++gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
25263 ++{
25264 ++ return 1;
25265 ++}
25266 ++
25267 ++void
25268 ++grsecurity_init(void)
25269 ++{
25270 ++ return;
25271 ++}
25272 ++
25273 ++__u32
25274 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
25275 ++ const struct dentry * parent_dentry,
25276 ++ const struct vfsmount * parent_mnt,
25277 ++ const int mode)
25278 ++{
25279 ++ return 1;
25280 ++}
25281 ++
25282 ++__u32
25283 ++gr_acl_handle_mkdir(const struct dentry * new_dentry,
25284 ++ const struct dentry * parent_dentry,
25285 ++ const struct vfsmount * parent_mnt)
25286 ++{
25287 ++ return 1;
25288 ++}
25289 ++
25290 ++__u32
25291 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
25292 ++ const struct dentry * parent_dentry,
25293 ++ const struct vfsmount * parent_mnt, const char *from)
25294 ++{
25295 ++ return 1;
25296 ++}
25297 ++
25298 ++__u32
25299 ++gr_acl_handle_link(const struct dentry * new_dentry,
25300 ++ const struct dentry * parent_dentry,
25301 ++ const struct vfsmount * parent_mnt,
25302 ++ const struct dentry * old_dentry,
25303 ++ const struct vfsmount * old_mnt, const char *to)
25304 ++{
25305 ++ return 1;
25306 ++}
25307 ++
25308 ++int
25309 ++gr_acl_handle_rename(const struct dentry *new_dentry,
25310 ++ const struct dentry *parent_dentry,
25311 ++ const struct vfsmount *parent_mnt,
25312 ++ const struct dentry *old_dentry,
25313 ++ const struct inode *old_parent_inode,
25314 ++ const struct vfsmount *old_mnt, const char *newname)
25315 ++{
25316 ++ return 0;
25317 ++}
25318 ++
25319 ++int
25320 ++gr_acl_handle_filldir(const struct file *file, const char *name,
25321 ++ const int namelen, const ino_t ino)
25322 ++{
25323 ++ return 1;
25324 ++}
25325 ++
25326 ++int
25327 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
25328 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
25329 ++{
25330 ++ return 1;
25331 ++}
25332 ++
25333 ++int
25334 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
25335 ++{
25336 ++ return 1;
25337 ++}
25338 ++
25339 ++int
25340 ++gr_search_accept(const struct socket *sock)
25341 ++{
25342 ++ return 1;
25343 ++}
25344 ++
25345 ++int
25346 ++gr_search_listen(const struct socket *sock)
25347 ++{
25348 ++ return 1;
25349 ++}
25350 ++
25351 ++int
25352 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
25353 ++{
25354 ++ return 1;
25355 ++}
25356 ++
25357 ++__u32
25358 ++gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
25359 ++{
25360 ++ return 1;
25361 ++}
25362 ++
25363 ++__u32
25364 ++gr_acl_handle_creat(const struct dentry * dentry,
25365 ++ const struct dentry * p_dentry,
25366 ++ const struct vfsmount * p_mnt, const int fmode,
25367 ++ const int imode)
25368 ++{
25369 ++ return 1;
25370 ++}
25371 ++
25372 ++void
25373 ++gr_acl_handle_exit(void)
25374 ++{
25375 ++ return;
25376 ++}
25377 ++
25378 ++int
25379 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
25380 ++{
25381 ++ return 1;
25382 ++}
25383 ++
25384 ++void
25385 ++gr_set_role_label(const uid_t uid, const gid_t gid)
25386 ++{
25387 ++ return;
25388 ++}
25389 ++
25390 ++int
25391 ++gr_acl_handle_procpidmem(const struct task_struct *task)
25392 ++{
25393 ++ return 0;
25394 ++}
25395 ++
25396 ++int
25397 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
25398 ++{
25399 ++ return 1;
25400 ++}
25401 ++
25402 ++int
25403 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
25404 ++{
25405 ++ return 1;
25406 ++}
25407 ++
25408 ++void
25409 ++gr_set_kernel_label(struct task_struct *task)
25410 ++{
25411 ++ return;
25412 ++}
25413 ++
25414 ++int
25415 ++gr_check_user_change(int real, int effective, int fs)
25416 ++{
25417 ++ return 0;
25418 ++}
25419 ++
25420 ++int
25421 ++gr_check_group_change(int real, int effective, int fs)
25422 ++{
25423 ++ return 0;
25424 ++}
25425 ++
25426 ++
25427 ++EXPORT_SYMBOL(gr_task_is_capable);
25428 ++EXPORT_SYMBOL(gr_is_capable_nolog);
25429 ++EXPORT_SYMBOL(gr_learn_resource);
25430 ++EXPORT_SYMBOL(gr_set_kernel_label);
25431 ++#ifdef CONFIG_SECURITY
25432 ++EXPORT_SYMBOL(gr_check_user_change);
25433 ++EXPORT_SYMBOL(gr_check_group_change);
25434 ++#endif
25435 +diff -urNp linux-2.6.27.10/grsecurity/grsec_exec.c linux-2.6.27.10/grsecurity/grsec_exec.c
25436 +--- linux-2.6.27.10/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
25437 ++++ linux-2.6.27.10/grsecurity/grsec_exec.c 2008-11-18 03:38:45.000000000 -0500
25438 +@@ -0,0 +1,88 @@
25439 ++#include <linux/kernel.h>
25440 ++#include <linux/sched.h>
25441 ++#include <linux/file.h>
25442 ++#include <linux/binfmts.h>
25443 ++#include <linux/smp_lock.h>
25444 ++#include <linux/fs.h>
25445 ++#include <linux/types.h>
25446 ++#include <linux/grdefs.h>
25447 ++#include <linux/grinternal.h>
25448 ++#include <linux/capability.h>
25449 ++
25450 ++#include <asm/uaccess.h>
25451 ++
25452 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
25453 ++static char gr_exec_arg_buf[132];
25454 ++static DECLARE_MUTEX(gr_exec_arg_sem);
25455 ++#endif
25456 ++
25457 ++int
25458 ++gr_handle_nproc(void)
25459 ++{
25460 ++#ifdef CONFIG_GRKERNSEC_EXECVE
25461 ++ if (grsec_enable_execve && current->user &&
25462 ++ (atomic_read(&current->user->processes) >
25463 ++ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
25464 ++ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
25465 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
25466 ++ return -EAGAIN;
25467 ++ }
25468 ++#endif
25469 ++ return 0;
25470 ++}
25471 ++
25472 ++void
25473 ++gr_handle_exec_args(struct linux_binprm *bprm, const char __user *__user *argv)
25474 ++{
25475 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
25476 ++ char *grarg = gr_exec_arg_buf;
25477 ++ unsigned int i, x, execlen = 0;
25478 ++ char c;
25479 ++
25480 ++ if (!((grsec_enable_execlog && grsec_enable_group &&
25481 ++ in_group_p(grsec_audit_gid))
25482 ++ || (grsec_enable_execlog && !grsec_enable_group)))
25483 ++ return;
25484 ++
25485 ++ down(&gr_exec_arg_sem);
25486 ++ memset(grarg, 0, sizeof(gr_exec_arg_buf));
25487 ++
25488 ++ if (unlikely(argv == NULL))
25489 ++ goto log;
25490 ++
25491 ++ for (i = 0; i < bprm->argc && execlen < 128; i++) {
25492 ++ const char __user *p;
25493 ++ unsigned int len;
25494 ++
25495 ++ if (copy_from_user(&p, argv + i, sizeof(p)))
25496 ++ goto log;
25497 ++ if (!p)
25498 ++ goto log;
25499 ++ len = strnlen_user(p, 128 - execlen);
25500 ++ if (len > 128 - execlen)
25501 ++ len = 128 - execlen;
25502 ++ else if (len > 0)
25503 ++ len--;
25504 ++ if (copy_from_user(grarg + execlen, p, len))
25505 ++ goto log;
25506 ++
25507 ++ /* rewrite unprintable characters */
25508 ++ for (x = 0; x < len; x++) {
25509 ++ c = *(grarg + execlen + x);
25510 ++ if (c < 32 || c > 126)
25511 ++ *(grarg + execlen + x) = ' ';
25512 ++ }
25513 ++
25514 ++ execlen += len;
25515 ++ *(grarg + execlen) = ' ';
25516 ++ *(grarg + execlen + 1) = '\0';
25517 ++ execlen++;
25518 ++ }
25519 ++
25520 ++ log:
25521 ++ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
25522 ++ bprm->file->f_path.mnt, grarg);
25523 ++ up(&gr_exec_arg_sem);
25524 ++#endif
25525 ++ return;
25526 ++}
25527 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fifo.c linux-2.6.27.10/grsecurity/grsec_fifo.c
25528 +--- linux-2.6.27.10/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
25529 ++++ linux-2.6.27.10/grsecurity/grsec_fifo.c 2008-11-18 03:38:45.000000000 -0500
25530 +@@ -0,0 +1,22 @@
25531 ++#include <linux/kernel.h>
25532 ++#include <linux/sched.h>
25533 ++#include <linux/fs.h>
25534 ++#include <linux/file.h>
25535 ++#include <linux/grinternal.h>
25536 ++
25537 ++int
25538 ++gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
25539 ++ const struct dentry *dir, const int flag, const int acc_mode)
25540 ++{
25541 ++#ifdef CONFIG_GRKERNSEC_FIFO
25542 ++ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
25543 ++ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
25544 ++ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
25545 ++ (current->fsuid != dentry->d_inode->i_uid)) {
25546 ++ if (!generic_permission(dentry->d_inode, acc_mode, NULL))
25547 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
25548 ++ return -EACCES;
25549 ++ }
25550 ++#endif
25551 ++ return 0;
25552 ++}
25553 +diff -urNp linux-2.6.27.10/grsecurity/grsec_fork.c linux-2.6.27.10/grsecurity/grsec_fork.c
25554 +--- linux-2.6.27.10/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
25555 ++++ linux-2.6.27.10/grsecurity/grsec_fork.c 2008-11-18 03:38:45.000000000 -0500
25556 +@@ -0,0 +1,15 @@
25557 ++#include <linux/kernel.h>
25558 ++#include <linux/sched.h>
25559 ++#include <linux/grsecurity.h>
25560 ++#include <linux/grinternal.h>
25561 ++#include <linux/errno.h>
25562 ++
25563 ++void
25564 ++gr_log_forkfail(const int retval)
25565 ++{
25566 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
25567 ++ if (grsec_enable_forkfail && retval != -ERESTARTNOINTR)
25568 ++ gr_log_int(GR_DONT_AUDIT, GR_FAILFORK_MSG, retval);
25569 ++#endif
25570 ++ return;
25571 ++}
25572 +diff -urNp linux-2.6.27.10/grsecurity/grsec_init.c linux-2.6.27.10/grsecurity/grsec_init.c
25573 +--- linux-2.6.27.10/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
25574 ++++ linux-2.6.27.10/grsecurity/grsec_init.c 2008-11-18 03:38:45.000000000 -0500
25575 +@@ -0,0 +1,230 @@
25576 ++#include <linux/kernel.h>
25577 ++#include <linux/sched.h>
25578 ++#include <linux/mm.h>
25579 ++#include <linux/smp_lock.h>
25580 ++#include <linux/gracl.h>
25581 ++#include <linux/slab.h>
25582 ++#include <linux/vmalloc.h>
25583 ++#include <linux/percpu.h>
25584 ++
25585 ++int grsec_enable_link;
25586 ++int grsec_enable_dmesg;
25587 ++int grsec_enable_fifo;
25588 ++int grsec_enable_execve;
25589 ++int grsec_enable_execlog;
25590 ++int grsec_enable_signal;
25591 ++int grsec_enable_forkfail;
25592 ++int grsec_enable_time;
25593 ++int grsec_enable_audit_textrel;
25594 ++int grsec_enable_group;
25595 ++int grsec_audit_gid;
25596 ++int grsec_enable_chdir;
25597 ++int grsec_enable_audit_ipc;
25598 ++int grsec_enable_mount;
25599 ++int grsec_enable_chroot_findtask;
25600 ++int grsec_enable_chroot_mount;
25601 ++int grsec_enable_chroot_shmat;
25602 ++int grsec_enable_chroot_fchdir;
25603 ++int grsec_enable_chroot_double;
25604 ++int grsec_enable_chroot_pivot;
25605 ++int grsec_enable_chroot_chdir;
25606 ++int grsec_enable_chroot_chmod;
25607 ++int grsec_enable_chroot_mknod;
25608 ++int grsec_enable_chroot_nice;
25609 ++int grsec_enable_chroot_execlog;
25610 ++int grsec_enable_chroot_caps;
25611 ++int grsec_enable_chroot_sysctl;
25612 ++int grsec_enable_chroot_unix;
25613 ++int grsec_enable_tpe;
25614 ++int grsec_tpe_gid;
25615 ++int grsec_enable_tpe_all;
25616 ++int grsec_enable_socket_all;
25617 ++int grsec_socket_all_gid;
25618 ++int grsec_enable_socket_client;
25619 ++int grsec_socket_client_gid;
25620 ++int grsec_enable_socket_server;
25621 ++int grsec_socket_server_gid;
25622 ++int grsec_resource_logging;
25623 ++int grsec_lock;
25624 ++
25625 ++DEFINE_SPINLOCK(grsec_alert_lock);
25626 ++unsigned long grsec_alert_wtime = 0;
25627 ++unsigned long grsec_alert_fyet = 0;
25628 ++
25629 ++DEFINE_SPINLOCK(grsec_audit_lock);
25630 ++
25631 ++DEFINE_RWLOCK(grsec_exec_file_lock);
25632 ++
25633 ++char *gr_shared_page[4];
25634 ++
25635 ++char *gr_alert_log_fmt;
25636 ++char *gr_audit_log_fmt;
25637 ++char *gr_alert_log_buf;
25638 ++char *gr_audit_log_buf;
25639 ++
25640 ++extern struct gr_arg *gr_usermode;
25641 ++extern unsigned char *gr_system_salt;
25642 ++extern unsigned char *gr_system_sum;
25643 ++
25644 ++void
25645 ++grsecurity_init(void)
25646 ++{
25647 ++ int j;
25648 ++ /* create the per-cpu shared pages */
25649 ++
25650 ++#ifdef CONFIG_X86
25651 ++ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
25652 ++#endif
25653 ++
25654 ++ for (j = 0; j < 4; j++) {
25655 ++ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE);
25656 ++ if (gr_shared_page[j] == NULL) {
25657 ++ panic("Unable to allocate grsecurity shared page");
25658 ++ return;
25659 ++ }
25660 ++ }
25661 ++
25662 ++ /* allocate log buffers */
25663 ++ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
25664 ++ if (!gr_alert_log_fmt) {
25665 ++ panic("Unable to allocate grsecurity alert log format buffer");
25666 ++ return;
25667 ++ }
25668 ++ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
25669 ++ if (!gr_audit_log_fmt) {
25670 ++ panic("Unable to allocate grsecurity audit log format buffer");
25671 ++ return;
25672 ++ }
25673 ++ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
25674 ++ if (!gr_alert_log_buf) {
25675 ++ panic("Unable to allocate grsecurity alert log buffer");
25676 ++ return;
25677 ++ }
25678 ++ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
25679 ++ if (!gr_audit_log_buf) {
25680 ++ panic("Unable to allocate grsecurity audit log buffer");
25681 ++ return;
25682 ++ }
25683 ++
25684 ++ /* allocate memory for authentication structure */
25685 ++ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
25686 ++ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
25687 ++ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
25688 ++
25689 ++ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
25690 ++ panic("Unable to allocate grsecurity authentication structure");
25691 ++ return;
25692 ++ }
25693 ++
25694 ++#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
25695 ++#ifndef CONFIG_GRKERNSEC_SYSCTL
25696 ++ grsec_lock = 1;
25697 ++#endif
25698 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
25699 ++ grsec_enable_audit_textrel = 1;
25700 ++#endif
25701 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
25702 ++ grsec_enable_group = 1;
25703 ++ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
25704 ++#endif
25705 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
25706 ++ grsec_enable_chdir = 1;
25707 ++#endif
25708 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25709 ++ grsec_enable_audit_ipc = 1;
25710 ++#endif
25711 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
25712 ++ grsec_enable_mount = 1;
25713 ++#endif
25714 ++#ifdef CONFIG_GRKERNSEC_LINK
25715 ++ grsec_enable_link = 1;
25716 ++#endif
25717 ++#ifdef CONFIG_GRKERNSEC_DMESG
25718 ++ grsec_enable_dmesg = 1;
25719 ++#endif
25720 ++#ifdef CONFIG_GRKERNSEC_FIFO
25721 ++ grsec_enable_fifo = 1;
25722 ++#endif
25723 ++#ifdef CONFIG_GRKERNSEC_EXECVE
25724 ++ grsec_enable_execve = 1;
25725 ++#endif
25726 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
25727 ++ grsec_enable_execlog = 1;
25728 ++#endif
25729 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
25730 ++ grsec_enable_signal = 1;
25731 ++#endif
25732 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
25733 ++ grsec_enable_forkfail = 1;
25734 ++#endif
25735 ++#ifdef CONFIG_GRKERNSEC_TIME
25736 ++ grsec_enable_time = 1;
25737 ++#endif
25738 ++#ifdef CONFIG_GRKERNSEC_RESLOG
25739 ++ grsec_resource_logging = 1;
25740 ++#endif
25741 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
25742 ++ grsec_enable_chroot_findtask = 1;
25743 ++#endif
25744 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
25745 ++ grsec_enable_chroot_unix = 1;
25746 ++#endif
25747 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
25748 ++ grsec_enable_chroot_mount = 1;
25749 ++#endif
25750 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
25751 ++ grsec_enable_chroot_fchdir = 1;
25752 ++#endif
25753 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
25754 ++ grsec_enable_chroot_shmat = 1;
25755 ++#endif
25756 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
25757 ++ grsec_enable_chroot_double = 1;
25758 ++#endif
25759 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
25760 ++ grsec_enable_chroot_pivot = 1;
25761 ++#endif
25762 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
25763 ++ grsec_enable_chroot_chdir = 1;
25764 ++#endif
25765 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
25766 ++ grsec_enable_chroot_chmod = 1;
25767 ++#endif
25768 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
25769 ++ grsec_enable_chroot_mknod = 1;
25770 ++#endif
25771 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
25772 ++ grsec_enable_chroot_nice = 1;
25773 ++#endif
25774 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
25775 ++ grsec_enable_chroot_execlog = 1;
25776 ++#endif
25777 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
25778 ++ grsec_enable_chroot_caps = 1;
25779 ++#endif
25780 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
25781 ++ grsec_enable_chroot_sysctl = 1;
25782 ++#endif
25783 ++#ifdef CONFIG_GRKERNSEC_TPE
25784 ++ grsec_enable_tpe = 1;
25785 ++ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
25786 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
25787 ++ grsec_enable_tpe_all = 1;
25788 ++#endif
25789 ++#endif
25790 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
25791 ++ grsec_enable_socket_all = 1;
25792 ++ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
25793 ++#endif
25794 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
25795 ++ grsec_enable_socket_client = 1;
25796 ++ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
25797 ++#endif
25798 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
25799 ++ grsec_enable_socket_server = 1;
25800 ++ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
25801 ++#endif
25802 ++#endif
25803 ++
25804 ++ return;
25805 ++}
25806 +diff -urNp linux-2.6.27.10/grsecurity/grsec_ipc.c linux-2.6.27.10/grsecurity/grsec_ipc.c
25807 +--- linux-2.6.27.10/grsecurity/grsec_ipc.c 1969-12-31 19:00:00.000000000 -0500
25808 ++++ linux-2.6.27.10/grsecurity/grsec_ipc.c 2008-11-18 03:38:45.000000000 -0500
25809 +@@ -0,0 +1,81 @@
25810 ++#include <linux/kernel.h>
25811 ++#include <linux/sched.h>
25812 ++#include <linux/types.h>
25813 ++#include <linux/ipc.h>
25814 ++#include <linux/grsecurity.h>
25815 ++#include <linux/grinternal.h>
25816 ++
25817 ++void
25818 ++gr_log_msgget(const int ret, const int msgflg)
25819 ++{
25820 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25821 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
25822 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
25823 ++ !grsec_enable_group)) && (ret >= 0)
25824 ++ && (msgflg & IPC_CREAT))
25825 ++ gr_log_noargs(GR_DO_AUDIT, GR_MSGQ_AUDIT_MSG);
25826 ++#endif
25827 ++ return;
25828 ++}
25829 ++
25830 ++void
25831 ++gr_log_msgrm(const uid_t uid, const uid_t cuid)
25832 ++{
25833 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25834 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
25835 ++ grsec_enable_audit_ipc) ||
25836 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
25837 ++ gr_log_int_int(GR_DO_AUDIT, GR_MSGQR_AUDIT_MSG, uid, cuid);
25838 ++#endif
25839 ++ return;
25840 ++}
25841 ++
25842 ++void
25843 ++gr_log_semget(const int err, const int semflg)
25844 ++{
25845 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25846 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
25847 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
25848 ++ !grsec_enable_group)) && (err >= 0)
25849 ++ && (semflg & IPC_CREAT))
25850 ++ gr_log_noargs(GR_DO_AUDIT, GR_SEM_AUDIT_MSG);
25851 ++#endif
25852 ++ return;
25853 ++}
25854 ++
25855 ++void
25856 ++gr_log_semrm(const uid_t uid, const uid_t cuid)
25857 ++{
25858 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25859 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
25860 ++ grsec_enable_audit_ipc) ||
25861 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
25862 ++ gr_log_int_int(GR_DO_AUDIT, GR_SEMR_AUDIT_MSG, uid, cuid);
25863 ++#endif
25864 ++ return;
25865 ++}
25866 ++
25867 ++void
25868 ++gr_log_shmget(const int err, const int shmflg, const size_t size)
25869 ++{
25870 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25871 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
25872 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
25873 ++ !grsec_enable_group)) && (err >= 0)
25874 ++ && (shmflg & IPC_CREAT))
25875 ++ gr_log_int(GR_DO_AUDIT, GR_SHM_AUDIT_MSG, size);
25876 ++#endif
25877 ++ return;
25878 ++}
25879 ++
25880 ++void
25881 ++gr_log_shmrm(const uid_t uid, const uid_t cuid)
25882 ++{
25883 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
25884 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
25885 ++ grsec_enable_audit_ipc) ||
25886 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
25887 ++ gr_log_int_int(GR_DO_AUDIT, GR_SHMR_AUDIT_MSG, uid, cuid);
25888 ++#endif
25889 ++ return;
25890 ++}
25891 +diff -urNp linux-2.6.27.10/grsecurity/grsec_link.c linux-2.6.27.10/grsecurity/grsec_link.c
25892 +--- linux-2.6.27.10/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
25893 ++++ linux-2.6.27.10/grsecurity/grsec_link.c 2008-11-18 03:38:45.000000000 -0500
25894 +@@ -0,0 +1,39 @@
25895 ++#include <linux/kernel.h>
25896 ++#include <linux/sched.h>
25897 ++#include <linux/fs.h>
25898 ++#include <linux/file.h>
25899 ++#include <linux/grinternal.h>
25900 ++
25901 ++int
25902 ++gr_handle_follow_link(const struct inode *parent,
25903 ++ const struct inode *inode,
25904 ++ const struct dentry *dentry, const struct vfsmount *mnt)
25905 ++{
25906 ++#ifdef CONFIG_GRKERNSEC_LINK
25907 ++ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
25908 ++ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
25909 ++ (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
25910 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
25911 ++ return -EACCES;
25912 ++ }
25913 ++#endif
25914 ++ return 0;
25915 ++}
25916 ++
25917 ++int
25918 ++gr_handle_hardlink(const struct dentry *dentry,
25919 ++ const struct vfsmount *mnt,
25920 ++ struct inode *inode, const int mode, const char *to)
25921 ++{
25922 ++#ifdef CONFIG_GRKERNSEC_LINK
25923 ++ if (grsec_enable_link && current->fsuid != inode->i_uid &&
25924 ++ (!S_ISREG(mode) || (mode & S_ISUID) ||
25925 ++ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
25926 ++ (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
25927 ++ !capable(CAP_FOWNER) && current->uid) {
25928 ++ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
25929 ++ return -EPERM;
25930 ++ }
25931 ++#endif
25932 ++ return 0;
25933 ++}
25934 +diff -urNp linux-2.6.27.10/grsecurity/grsec_log.c linux-2.6.27.10/grsecurity/grsec_log.c
25935 +--- linux-2.6.27.10/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
25936 ++++ linux-2.6.27.10/grsecurity/grsec_log.c 2008-11-18 03:38:45.000000000 -0500
25937 +@@ -0,0 +1,269 @@
25938 ++#include <linux/kernel.h>
25939 ++#include <linux/sched.h>
25940 ++#include <linux/file.h>
25941 ++#include <linux/tty.h>
25942 ++#include <linux/fs.h>
25943 ++#include <linux/grinternal.h>
25944 ++
25945 ++#define BEGIN_LOCKS(x) \
25946 ++ read_lock(&tasklist_lock); \
25947 ++ read_lock(&grsec_exec_file_lock); \
25948 ++ if (x != GR_DO_AUDIT) \
25949 ++ spin_lock(&grsec_alert_lock); \
25950 ++ else \
25951 ++ spin_lock(&grsec_audit_lock)
25952 ++
25953 ++#define END_LOCKS(x) \
25954 ++ if (x != GR_DO_AUDIT) \
25955 ++ spin_unlock(&grsec_alert_lock); \
25956 ++ else \
25957 ++ spin_unlock(&grsec_audit_lock); \
25958 ++ read_unlock(&grsec_exec_file_lock); \
25959 ++ read_unlock(&tasklist_lock); \
25960 ++ if (x == GR_DONT_AUDIT) \
25961 ++ gr_handle_alertkill(current)
25962 ++
25963 ++enum {
25964 ++ FLOODING,
25965 ++ NO_FLOODING
25966 ++};
25967 ++
25968 ++extern char *gr_alert_log_fmt;
25969 ++extern char *gr_audit_log_fmt;
25970 ++extern char *gr_alert_log_buf;
25971 ++extern char *gr_audit_log_buf;
25972 ++
25973 ++static int gr_log_start(int audit)
25974 ++{
25975 ++ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
25976 ++ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
25977 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
25978 ++
25979 ++ if (audit == GR_DO_AUDIT)
25980 ++ goto set_fmt;
25981 ++
25982 ++ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
25983 ++ grsec_alert_wtime = jiffies;
25984 ++ grsec_alert_fyet = 0;
25985 ++ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
25986 ++ grsec_alert_fyet++;
25987 ++ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
25988 ++ grsec_alert_wtime = jiffies;
25989 ++ grsec_alert_fyet++;
25990 ++ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
25991 ++ return FLOODING;
25992 ++ } else return FLOODING;
25993 ++
25994 ++set_fmt:
25995 ++ memset(buf, 0, PAGE_SIZE);
25996 ++ if (current->signal->curr_ip && gr_acl_is_enabled()) {
25997 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) ");
25998 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename);
25999 ++ } else if (current->signal->curr_ip) {
26000 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: ");
26001 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip));
26002 ++ } else if (gr_acl_is_enabled()) {
26003 ++ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
26004 ++ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
26005 ++ } else {
26006 ++ sprintf(fmt, "%s%s", loglevel, "grsec: ");
26007 ++ strcpy(buf, fmt);
26008 ++ }
26009 ++
26010 ++ return NO_FLOODING;
26011 ++}
26012 ++
26013 ++static void gr_log_middle(int audit, const char *msg, va_list ap)
26014 ++{
26015 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
26016 ++ unsigned int len = strlen(buf);
26017 ++
26018 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
26019 ++
26020 ++ return;
26021 ++}
26022 ++
26023 ++static void gr_log_middle_varargs(int audit, const char *msg, ...)
26024 ++{
26025 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
26026 ++ unsigned int len = strlen(buf);
26027 ++ va_list ap;
26028 ++
26029 ++ va_start(ap, msg);
26030 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
26031 ++ va_end(ap);
26032 ++
26033 ++ return;
26034 ++}
26035 ++
26036 ++static void gr_log_end(int audit)
26037 ++{
26038 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
26039 ++ unsigned int len = strlen(buf);
26040 ++
26041 ++ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current));
26042 ++ printk("%s\n", buf);
26043 ++
26044 ++ return;
26045 ++}
26046 ++
26047 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
26048 ++{
26049 ++ int logtype;
26050 ++ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
26051 ++ char *str1, *str2, *str3;
26052 ++ int num1, num2;
26053 ++ unsigned long ulong1, ulong2;
26054 ++ struct dentry *dentry;
26055 ++ struct vfsmount *mnt;
26056 ++ struct file *file;
26057 ++ struct task_struct *task;
26058 ++ va_list ap;
26059 ++
26060 ++ BEGIN_LOCKS(audit);
26061 ++ logtype = gr_log_start(audit);
26062 ++ if (logtype == FLOODING) {
26063 ++ END_LOCKS(audit);
26064 ++ return;
26065 ++ }
26066 ++ va_start(ap, argtypes);
26067 ++ switch (argtypes) {
26068 ++ case GR_TTYSNIFF:
26069 ++ task = va_arg(ap, struct task_struct *);
26070 ++ gr_log_middle_varargs(audit, msg, NIPQUAD(task->signal->curr_ip), gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->parent->comm, task->parent->pid);
26071 ++ break;
26072 ++ case GR_SYSCTL_HIDDEN:
26073 ++ str1 = va_arg(ap, char *);
26074 ++ gr_log_middle_varargs(audit, msg, result, str1);
26075 ++ break;
26076 ++ case GR_RBAC:
26077 ++ dentry = va_arg(ap, struct dentry *);
26078 ++ mnt = va_arg(ap, struct vfsmount *);
26079 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
26080 ++ break;
26081 ++ case GR_RBAC_STR:
26082 ++ dentry = va_arg(ap, struct dentry *);
26083 ++ mnt = va_arg(ap, struct vfsmount *);
26084 ++ str1 = va_arg(ap, char *);
26085 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
26086 ++ break;
26087 ++ case GR_STR_RBAC:
26088 ++ str1 = va_arg(ap, char *);
26089 ++ dentry = va_arg(ap, struct dentry *);
26090 ++ mnt = va_arg(ap, struct vfsmount *);
26091 ++ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
26092 ++ break;
26093 ++ case GR_RBAC_MODE2:
26094 ++ dentry = va_arg(ap, struct dentry *);
26095 ++ mnt = va_arg(ap, struct vfsmount *);
26096 ++ str1 = va_arg(ap, char *);
26097 ++ str2 = va_arg(ap, char *);
26098 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
26099 ++ break;
26100 ++ case GR_RBAC_MODE3:
26101 ++ dentry = va_arg(ap, struct dentry *);
26102 ++ mnt = va_arg(ap, struct vfsmount *);
26103 ++ str1 = va_arg(ap, char *);
26104 ++ str2 = va_arg(ap, char *);
26105 ++ str3 = va_arg(ap, char *);
26106 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
26107 ++ break;
26108 ++ case GR_FILENAME:
26109 ++ dentry = va_arg(ap, struct dentry *);
26110 ++ mnt = va_arg(ap, struct vfsmount *);
26111 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
26112 ++ break;
26113 ++ case GR_STR_FILENAME:
26114 ++ str1 = va_arg(ap, char *);
26115 ++ dentry = va_arg(ap, struct dentry *);
26116 ++ mnt = va_arg(ap, struct vfsmount *);
26117 ++ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
26118 ++ break;
26119 ++ case GR_FILENAME_STR:
26120 ++ dentry = va_arg(ap, struct dentry *);
26121 ++ mnt = va_arg(ap, struct vfsmount *);
26122 ++ str1 = va_arg(ap, char *);
26123 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
26124 ++ break;
26125 ++ case GR_FILENAME_TWO_INT:
26126 ++ dentry = va_arg(ap, struct dentry *);
26127 ++ mnt = va_arg(ap, struct vfsmount *);
26128 ++ num1 = va_arg(ap, int);
26129 ++ num2 = va_arg(ap, int);
26130 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
26131 ++ break;
26132 ++ case GR_FILENAME_TWO_INT_STR:
26133 ++ dentry = va_arg(ap, struct dentry *);
26134 ++ mnt = va_arg(ap, struct vfsmount *);
26135 ++ num1 = va_arg(ap, int);
26136 ++ num2 = va_arg(ap, int);
26137 ++ str1 = va_arg(ap, char *);
26138 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
26139 ++ break;
26140 ++ case GR_TEXTREL:
26141 ++ file = va_arg(ap, struct file *);
26142 ++ ulong1 = va_arg(ap, unsigned long);
26143 ++ ulong2 = va_arg(ap, unsigned long);
26144 ++ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
26145 ++ break;
26146 ++ case GR_PTRACE:
26147 ++ task = va_arg(ap, struct task_struct *);
26148 ++ gr_log_middle_varargs(audit, msg, task->exec_file ? gr_to_filename(task->exec_file->f_path.dentry, task->exec_file->f_path.mnt) : "(none)", task->comm, task->pid);
26149 ++ break;
26150 ++ case GR_RESOURCE:
26151 ++ task = va_arg(ap, struct task_struct *);
26152 ++ ulong1 = va_arg(ap, unsigned long);
26153 ++ str1 = va_arg(ap, char *);
26154 ++ ulong2 = va_arg(ap, unsigned long);
26155 ++ gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
26156 ++ break;
26157 ++ case GR_CAP:
26158 ++ task = va_arg(ap, struct task_struct *);
26159 ++ str1 = va_arg(ap, char *);
26160 ++ gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
26161 ++ break;
26162 ++ case GR_SIG:
26163 ++ task = va_arg(ap, struct task_struct *);
26164 ++ num1 = va_arg(ap, int);
26165 ++ gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath0(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
26166 ++ break;
26167 ++ case GR_CRASH1:
26168 ++ task = va_arg(ap, struct task_struct *);
26169 ++ ulong1 = va_arg(ap, unsigned long);
26170 ++ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid, task->uid, ulong1);
26171 ++ break;
26172 ++ case GR_CRASH2:
26173 ++ task = va_arg(ap, struct task_struct *);
26174 ++ ulong1 = va_arg(ap, unsigned long);
26175 ++ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, task->uid, task->euid, task->gid, task->egid, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid, ulong1);
26176 ++ break;
26177 ++ case GR_PSACCT:
26178 ++ {
26179 ++ unsigned int wday, cday;
26180 ++ __u8 whr, chr;
26181 ++ __u8 wmin, cmin;
26182 ++ __u8 wsec, csec;
26183 ++ char cur_tty[64] = { 0 };
26184 ++ char parent_tty[64] = { 0 };
26185 ++
26186 ++ task = va_arg(ap, struct task_struct *);
26187 ++ wday = va_arg(ap, unsigned int);
26188 ++ cday = va_arg(ap, unsigned int);
26189 ++ whr = va_arg(ap, int);
26190 ++ chr = va_arg(ap, int);
26191 ++ wmin = va_arg(ap, int);
26192 ++ cmin = va_arg(ap, int);
26193 ++ wsec = va_arg(ap, int);
26194 ++ csec = va_arg(ap, int);
26195 ++ ulong1 = va_arg(ap, unsigned long);
26196 ++
26197 ++ gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, NIPQUAD(task->signal->curr_ip), tty_name(task->signal->tty, cur_tty), task->uid, task->euid, task->gid, task->egid, wday, whr, wmin, wsec, cday, chr, cmin, csec, (task->flags & PF_SIGNALED) ? "killed by signal" : "exited", ulong1, gr_parent_task_fullpath(task), task->parent->comm, task->parent->pid, NIPQUAD(task->parent->signal->curr_ip), tty_name(task->parent->signal->tty, parent_tty), task->parent->uid, task->parent->euid, task->parent->gid, task->parent->egid);
26198 ++ }
26199 ++ break;
26200 ++ default:
26201 ++ gr_log_middle(audit, msg, ap);
26202 ++ }
26203 ++ va_end(ap);
26204 ++ gr_log_end(audit);
26205 ++ END_LOCKS(audit);
26206 ++}
26207 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mem.c linux-2.6.27.10/grsecurity/grsec_mem.c
26208 +--- linux-2.6.27.10/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
26209 ++++ linux-2.6.27.10/grsecurity/grsec_mem.c 2008-11-18 03:38:45.000000000 -0500
26210 +@@ -0,0 +1,71 @@
26211 ++#include <linux/kernel.h>
26212 ++#include <linux/sched.h>
26213 ++#include <linux/mm.h>
26214 ++#include <linux/mman.h>
26215 ++#include <linux/grinternal.h>
26216 ++
26217 ++void
26218 ++gr_handle_ioperm(void)
26219 ++{
26220 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
26221 ++ return;
26222 ++}
26223 ++
26224 ++void
26225 ++gr_handle_iopl(void)
26226 ++{
26227 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
26228 ++ return;
26229 ++}
26230 ++
26231 ++void
26232 ++gr_handle_mem_write(void)
26233 ++{
26234 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
26235 ++ return;
26236 ++}
26237 ++
26238 ++void
26239 ++gr_handle_kmem_write(void)
26240 ++{
26241 ++ gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
26242 ++ return;
26243 ++}
26244 ++
26245 ++void
26246 ++gr_handle_open_port(void)
26247 ++{
26248 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
26249 ++ return;
26250 ++}
26251 ++
26252 ++int
26253 ++gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
26254 ++{
26255 ++ unsigned long start, end;
26256 ++
26257 ++ start = offset;
26258 ++ end = start + vma->vm_end - vma->vm_start;
26259 ++
26260 ++ if (start > end) {
26261 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
26262 ++ return -EPERM;
26263 ++ }
26264 ++
26265 ++ /* allowed ranges : ISA I/O BIOS */
26266 ++ if ((start >= __pa(high_memory))
26267 ++#ifdef CONFIG_X86
26268 ++ || (start >= 0x000a0000 && end <= 0x00100000)
26269 ++ || (start >= 0x00000000 && end <= 0x00001000)
26270 ++#endif
26271 ++ )
26272 ++ return 0;
26273 ++
26274 ++ if (vma->vm_flags & VM_WRITE) {
26275 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
26276 ++ return -EPERM;
26277 ++ } else
26278 ++ vma->vm_flags &= ~VM_MAYWRITE;
26279 ++
26280 ++ return 0;
26281 ++}
26282 +diff -urNp linux-2.6.27.10/grsecurity/grsec_mount.c linux-2.6.27.10/grsecurity/grsec_mount.c
26283 +--- linux-2.6.27.10/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
26284 ++++ linux-2.6.27.10/grsecurity/grsec_mount.c 2008-11-18 03:38:45.000000000 -0500
26285 +@@ -0,0 +1,34 @@
26286 ++#include <linux/kernel.h>
26287 ++#include <linux/sched.h>
26288 ++#include <linux/grsecurity.h>
26289 ++#include <linux/grinternal.h>
26290 ++
26291 ++void
26292 ++gr_log_remount(const char *devname, const int retval)
26293 ++{
26294 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
26295 ++ if (grsec_enable_mount && (retval >= 0))
26296 ++ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
26297 ++#endif
26298 ++ return;
26299 ++}
26300 ++
26301 ++void
26302 ++gr_log_unmount(const char *devname, const int retval)
26303 ++{
26304 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
26305 ++ if (grsec_enable_mount && (retval >= 0))
26306 ++ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
26307 ++#endif
26308 ++ return;
26309 ++}
26310 ++
26311 ++void
26312 ++gr_log_mount(const char *from, const char *to, const int retval)
26313 ++{
26314 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
26315 ++ if (grsec_enable_mount && (retval >= 0))
26316 ++ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
26317 ++#endif
26318 ++ return;
26319 ++}
26320 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sig.c linux-2.6.27.10/grsecurity/grsec_sig.c
26321 +--- linux-2.6.27.10/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
26322 ++++ linux-2.6.27.10/grsecurity/grsec_sig.c 2008-11-18 03:38:45.000000000 -0500
26323 +@@ -0,0 +1,58 @@
26324 ++#include <linux/kernel.h>
26325 ++#include <linux/sched.h>
26326 ++#include <linux/delay.h>
26327 ++#include <linux/grsecurity.h>
26328 ++#include <linux/grinternal.h>
26329 ++
26330 ++void
26331 ++gr_log_signal(const int sig, const struct task_struct *t)
26332 ++{
26333 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
26334 ++ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
26335 ++ (sig == SIGABRT) || (sig == SIGBUS))) {
26336 ++ if (t->pid == current->pid) {
26337 ++ gr_log_int(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, sig);
26338 ++ } else {
26339 ++ gr_log_sig(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
26340 ++ }
26341 ++ }
26342 ++#endif
26343 ++ return;
26344 ++}
26345 ++
26346 ++int
26347 ++gr_handle_signal(const struct task_struct *p, const int sig)
26348 ++{
26349 ++#ifdef CONFIG_GRKERNSEC
26350 ++ if (current->pid > 1 && gr_check_protected_task(p)) {
26351 ++ gr_log_sig(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
26352 ++ return -EPERM;
26353 ++ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
26354 ++ return -EPERM;
26355 ++ }
26356 ++#endif
26357 ++ return 0;
26358 ++}
26359 ++
26360 ++void gr_handle_brute_attach(struct task_struct *p)
26361 ++{
26362 ++#ifdef CONFIG_GRKERNSEC_BRUTE
26363 ++ read_lock(&tasklist_lock);
26364 ++ read_lock(&grsec_exec_file_lock);
26365 ++ if (p->parent && p->parent->exec_file == p->exec_file)
26366 ++ p->parent->brute = 1;
26367 ++ read_unlock(&grsec_exec_file_lock);
26368 ++ read_unlock(&tasklist_lock);
26369 ++#endif
26370 ++ return;
26371 ++}
26372 ++
26373 ++void gr_handle_brute_check(void)
26374 ++{
26375 ++#ifdef CONFIG_GRKERNSEC_BRUTE
26376 ++ if (current->brute)
26377 ++ msleep(30 * 1000);
26378 ++#endif
26379 ++ return;
26380 ++}
26381 ++
26382 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sock.c linux-2.6.27.10/grsecurity/grsec_sock.c
26383 +--- linux-2.6.27.10/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
26384 ++++ linux-2.6.27.10/grsecurity/grsec_sock.c 2008-11-18 11:35:13.000000000 -0500
26385 +@@ -0,0 +1,274 @@
26386 ++#include <linux/kernel.h>
26387 ++#include <linux/module.h>
26388 ++#include <linux/sched.h>
26389 ++#include <linux/file.h>
26390 ++#include <linux/net.h>
26391 ++#include <linux/in.h>
26392 ++#include <linux/ip.h>
26393 ++#include <net/sock.h>
26394 ++#include <net/inet_sock.h>
26395 ++#include <linux/grsecurity.h>
26396 ++#include <linux/grinternal.h>
26397 ++#include <linux/gracl.h>
26398 ++
26399 ++#if defined(CONFIG_IP_NF_MATCH_STEALTH_MODULE)
26400 ++extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
26401 ++EXPORT_SYMBOL(udp_v4_lookup);
26402 ++#endif
26403 ++
26404 ++kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
26405 ++EXPORT_SYMBOL(gr_cap_rtnetlink);
26406 ++
26407 ++extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
26408 ++extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
26409 ++
26410 ++EXPORT_SYMBOL(gr_search_udp_recvmsg);
26411 ++EXPORT_SYMBOL(gr_search_udp_sendmsg);
26412 ++
26413 ++#ifdef CONFIG_UNIX_MODULE
26414 ++EXPORT_SYMBOL(gr_acl_handle_unix);
26415 ++EXPORT_SYMBOL(gr_acl_handle_mknod);
26416 ++EXPORT_SYMBOL(gr_handle_chroot_unix);
26417 ++EXPORT_SYMBOL(gr_handle_create);
26418 ++#endif
26419 ++
26420 ++#ifdef CONFIG_GRKERNSEC
26421 ++#define gr_conn_table_size 32749
26422 ++struct conn_table_entry {
26423 ++ struct conn_table_entry *next;
26424 ++ struct signal_struct *sig;
26425 ++};
26426 ++
26427 ++struct conn_table_entry *gr_conn_table[gr_conn_table_size];
26428 ++DEFINE_SPINLOCK(gr_conn_table_lock);
26429 ++
26430 ++extern const char * gr_socktype_to_name(unsigned char type);
26431 ++extern const char * gr_proto_to_name(unsigned char proto);
26432 ++
26433 ++static __inline__ int
26434 ++conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
26435 ++{
26436 ++ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
26437 ++}
26438 ++
26439 ++static __inline__ int
26440 ++conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
26441 ++ __u16 sport, __u16 dport)
26442 ++{
26443 ++ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
26444 ++ sig->gr_sport == sport && sig->gr_dport == dport))
26445 ++ return 1;
26446 ++ else
26447 ++ return 0;
26448 ++}
26449 ++
26450 ++static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
26451 ++{
26452 ++ struct conn_table_entry **match;
26453 ++ unsigned int index;
26454 ++
26455 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
26456 ++ sig->gr_sport, sig->gr_dport,
26457 ++ gr_conn_table_size);
26458 ++
26459 ++ newent->sig = sig;
26460 ++
26461 ++ match = &gr_conn_table[index];
26462 ++ newent->next = *match;
26463 ++ *match = newent;
26464 ++
26465 ++ return;
26466 ++}
26467 ++
26468 ++static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
26469 ++{
26470 ++ struct conn_table_entry *match, *last = NULL;
26471 ++ unsigned int index;
26472 ++
26473 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
26474 ++ sig->gr_sport, sig->gr_dport,
26475 ++ gr_conn_table_size);
26476 ++
26477 ++ match = gr_conn_table[index];
26478 ++ while (match && !conn_match(match->sig,
26479 ++ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
26480 ++ sig->gr_dport)) {
26481 ++ last = match;
26482 ++ match = match->next;
26483 ++ }
26484 ++
26485 ++ if (match) {
26486 ++ if (last)
26487 ++ last->next = match->next;
26488 ++ else
26489 ++ gr_conn_table[index] = NULL;
26490 ++ kfree(match);
26491 ++ }
26492 ++
26493 ++ return;
26494 ++}
26495 ++
26496 ++static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
26497 ++ __u16 sport, __u16 dport)
26498 ++{
26499 ++ struct conn_table_entry *match;
26500 ++ unsigned int index;
26501 ++
26502 ++ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
26503 ++
26504 ++ match = gr_conn_table[index];
26505 ++ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
26506 ++ match = match->next;
26507 ++
26508 ++ if (match)
26509 ++ return match->sig;
26510 ++ else
26511 ++ return NULL;
26512 ++}
26513 ++
26514 ++#endif
26515 ++
26516 ++void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
26517 ++{
26518 ++#ifdef CONFIG_GRKERNSEC
26519 ++ struct signal_struct *sig = task->signal;
26520 ++ struct conn_table_entry *newent;
26521 ++
26522 ++ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
26523 ++ if (newent == NULL)
26524 ++ return;
26525 ++ /* no bh lock needed since we are called with bh disabled */
26526 ++ spin_lock(&gr_conn_table_lock);
26527 ++ gr_del_task_from_ip_table_nolock(sig);
26528 ++ sig->gr_saddr = inet->rcv_saddr;
26529 ++ sig->gr_daddr = inet->daddr;
26530 ++ sig->gr_sport = inet->sport;
26531 ++ sig->gr_dport = inet->dport;
26532 ++ gr_add_to_task_ip_table_nolock(sig, newent);
26533 ++ spin_unlock(&gr_conn_table_lock);
26534 ++#endif
26535 ++ return;
26536 ++}
26537 ++
26538 ++void gr_del_task_from_ip_table(struct task_struct *task)
26539 ++{
26540 ++#ifdef CONFIG_GRKERNSEC
26541 ++ spin_lock_bh(&gr_conn_table_lock);
26542 ++ gr_del_task_from_ip_table_nolock(task->signal);
26543 ++ spin_unlock_bh(&gr_conn_table_lock);
26544 ++#endif
26545 ++ return;
26546 ++}
26547 ++
26548 ++void
26549 ++gr_attach_curr_ip(const struct sock *sk)
26550 ++{
26551 ++#ifdef CONFIG_GRKERNSEC
26552 ++ struct signal_struct *p, *set;
26553 ++ const struct inet_sock *inet = inet_sk(sk);
26554 ++
26555 ++ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
26556 ++ return;
26557 ++
26558 ++ set = current->signal;
26559 ++
26560 ++ spin_lock_bh(&gr_conn_table_lock);
26561 ++ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
26562 ++ inet->dport, inet->sport);
26563 ++ if (unlikely(p != NULL)) {
26564 ++ set->curr_ip = p->curr_ip;
26565 ++ set->used_accept = 1;
26566 ++ gr_del_task_from_ip_table_nolock(p);
26567 ++ spin_unlock_bh(&gr_conn_table_lock);
26568 ++ return;
26569 ++ }
26570 ++ spin_unlock_bh(&gr_conn_table_lock);
26571 ++
26572 ++ set->curr_ip = inet->daddr;
26573 ++ set->used_accept = 1;
26574 ++#endif
26575 ++ return;
26576 ++}
26577 ++
26578 ++int
26579 ++gr_handle_sock_all(const int family, const int type, const int protocol)
26580 ++{
26581 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
26582 ++ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
26583 ++ (family != AF_UNIX) && (family != AF_LOCAL)) {
26584 ++ gr_log_int_str2(GR_DONT_AUDIT, GR_SOCK2_MSG, family, gr_socktype_to_name(type), gr_proto_to_name(protocol));
26585 ++ return -EACCES;
26586 ++ }
26587 ++#endif
26588 ++ return 0;
26589 ++}
26590 ++
26591 ++int
26592 ++gr_handle_sock_server(const struct sockaddr *sck)
26593 ++{
26594 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
26595 ++ if (grsec_enable_socket_server &&
26596 ++ in_group_p(grsec_socket_server_gid) &&
26597 ++ sck && (sck->sa_family != AF_UNIX) &&
26598 ++ (sck->sa_family != AF_LOCAL)) {
26599 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
26600 ++ return -EACCES;
26601 ++ }
26602 ++#endif
26603 ++ return 0;
26604 ++}
26605 ++
26606 ++int
26607 ++gr_handle_sock_server_other(const struct sock *sck)
26608 ++{
26609 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
26610 ++ if (grsec_enable_socket_server &&
26611 ++ in_group_p(grsec_socket_server_gid) &&
26612 ++ sck && (sck->sk_family != AF_UNIX) &&
26613 ++ (sck->sk_family != AF_LOCAL)) {
26614 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
26615 ++ return -EACCES;
26616 ++ }
26617 ++#endif
26618 ++ return 0;
26619 ++}
26620 ++
26621 ++int
26622 ++gr_handle_sock_client(const struct sockaddr *sck)
26623 ++{
26624 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
26625 ++ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
26626 ++ sck && (sck->sa_family != AF_UNIX) &&
26627 ++ (sck->sa_family != AF_LOCAL)) {
26628 ++ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
26629 ++ return -EACCES;
26630 ++ }
26631 ++#endif
26632 ++ return 0;
26633 ++}
26634 ++
26635 ++kernel_cap_t
26636 ++gr_cap_rtnetlink(struct sock *sock)
26637 ++{
26638 ++#ifdef CONFIG_GRKERNSEC
26639 ++ if (!gr_acl_is_enabled())
26640 ++ return current->cap_effective;
26641 ++ else if (sock->sk_protocol == NETLINK_ISCSI &&
26642 ++ cap_raised(current->cap_effective, CAP_SYS_ADMIN) &&
26643 ++ gr_task_is_capable(current, CAP_SYS_ADMIN))
26644 ++ return current->cap_effective;
26645 ++ else if (sock->sk_protocol == NETLINK_AUDIT &&
26646 ++ cap_raised(current->cap_effective, CAP_AUDIT_WRITE) &&
26647 ++ gr_task_is_capable(current, CAP_AUDIT_WRITE) &&
26648 ++ cap_raised(current->cap_effective, CAP_AUDIT_CONTROL) &&
26649 ++ gr_task_is_capable(current, CAP_AUDIT_CONTROL))
26650 ++ return current->cap_effective;
26651 ++ else if (cap_raised(current->cap_effective, CAP_NET_ADMIN) &&
26652 ++ gr_task_is_capable(current, CAP_NET_ADMIN))
26653 ++ return current->cap_effective;
26654 ++ else
26655 ++ return __cap_empty_set;
26656 ++#else
26657 ++ return current->cap_effective;
26658 ++#endif
26659 ++}
26660 +diff -urNp linux-2.6.27.10/grsecurity/grsec_sysctl.c linux-2.6.27.10/grsecurity/grsec_sysctl.c
26661 +--- linux-2.6.27.10/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
26662 ++++ linux-2.6.27.10/grsecurity/grsec_sysctl.c 2008-11-18 03:38:45.000000000 -0500
26663 +@@ -0,0 +1,435 @@
26664 ++#include <linux/kernel.h>
26665 ++#include <linux/sched.h>
26666 ++#include <linux/sysctl.h>
26667 ++#include <linux/grsecurity.h>
26668 ++#include <linux/grinternal.h>
26669 ++
26670 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
26671 ++int grsec_modstop;
26672 ++#endif
26673 ++
26674 ++int
26675 ++gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
26676 ++{
26677 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
26678 ++ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
26679 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
26680 ++ return -EACCES;
26681 ++ }
26682 ++#endif
26683 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
26684 ++ if (!strcmp(dirname, "grsecurity") && !strcmp(name, "disable_modules") &&
26685 ++ grsec_modstop && (op & MAY_WRITE)) {
26686 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
26687 ++ return -EACCES;
26688 ++ }
26689 ++#endif
26690 ++ return 0;
26691 ++}
26692 ++
26693 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
26694 ++ctl_table grsecurity_table[] = {
26695 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
26696 ++#ifdef CONFIG_GRKERNSEC_LINK
26697 ++ {
26698 ++ .ctl_name = CTL_UNNUMBERED,
26699 ++ .procname = "linking_restrictions",
26700 ++ .data = &grsec_enable_link,
26701 ++ .maxlen = sizeof(int),
26702 ++ .mode = 0600,
26703 ++ .proc_handler = &proc_dointvec,
26704 ++ },
26705 ++#endif
26706 ++#ifdef CONFIG_GRKERNSEC_FIFO
26707 ++ {
26708 ++ .ctl_name = CTL_UNNUMBERED,
26709 ++ .procname = "fifo_restrictions",
26710 ++ .data = &grsec_enable_fifo,
26711 ++ .maxlen = sizeof(int),
26712 ++ .mode = 0600,
26713 ++ .proc_handler = &proc_dointvec,
26714 ++ },
26715 ++#endif
26716 ++#ifdef CONFIG_GRKERNSEC_EXECVE
26717 ++ {
26718 ++ .ctl_name = CTL_UNNUMBERED,
26719 ++ .procname = "execve_limiting",
26720 ++ .data = &grsec_enable_execve,
26721 ++ .maxlen = sizeof(int),
26722 ++ .mode = 0600,
26723 ++ .proc_handler = &proc_dointvec,
26724 ++ },
26725 ++#endif
26726 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
26727 ++ {
26728 ++ .ctl_name = CTL_UNNUMBERED,
26729 ++ .procname = "exec_logging",
26730 ++ .data = &grsec_enable_execlog,
26731 ++ .maxlen = sizeof(int),
26732 ++ .mode = 0600,
26733 ++ .proc_handler = &proc_dointvec,
26734 ++ },
26735 ++#endif
26736 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
26737 ++ {
26738 ++ .ctl_name = CTL_UNNUMBERED,
26739 ++ .procname = "signal_logging",
26740 ++ .data = &grsec_enable_signal,
26741 ++ .maxlen = sizeof(int),
26742 ++ .mode = 0600,
26743 ++ .proc_handler = &proc_dointvec,
26744 ++ },
26745 ++#endif
26746 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
26747 ++ {
26748 ++ .ctl_name = CTL_UNNUMBERED,
26749 ++ .procname = "forkfail_logging",
26750 ++ .data = &grsec_enable_forkfail,
26751 ++ .maxlen = sizeof(int),
26752 ++ .mode = 0600,
26753 ++ .proc_handler = &proc_dointvec,
26754 ++ },
26755 ++#endif
26756 ++#ifdef CONFIG_GRKERNSEC_TIME
26757 ++ {
26758 ++ .ctl_name = CTL_UNNUMBERED,
26759 ++ .procname = "timechange_logging",
26760 ++ .data = &grsec_enable_time,
26761 ++ .maxlen = sizeof(int),
26762 ++ .mode = 0600,
26763 ++ .proc_handler = &proc_dointvec,
26764 ++ },
26765 ++#endif
26766 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
26767 ++ {
26768 ++ .ctl_name = CTL_UNNUMBERED,
26769 ++ .procname = "chroot_deny_shmat",
26770 ++ .data = &grsec_enable_chroot_shmat,
26771 ++ .maxlen = sizeof(int),
26772 ++ .mode = 0600,
26773 ++ .proc_handler = &proc_dointvec,
26774 ++ },
26775 ++#endif
26776 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
26777 ++ {
26778 ++ .ctl_name = CTL_UNNUMBERED,
26779 ++ .procname = "chroot_deny_unix",
26780 ++ .data = &grsec_enable_chroot_unix,
26781 ++ .maxlen = sizeof(int),
26782 ++ .mode = 0600,
26783 ++ .proc_handler = &proc_dointvec,
26784 ++ },
26785 ++#endif
26786 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
26787 ++ {
26788 ++ .ctl_name = CTL_UNNUMBERED,
26789 ++ .procname = "chroot_deny_mount",
26790 ++ .data = &grsec_enable_chroot_mount,
26791 ++ .maxlen = sizeof(int),
26792 ++ .mode = 0600,
26793 ++ .proc_handler = &proc_dointvec,
26794 ++ },
26795 ++#endif
26796 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
26797 ++ {
26798 ++ .ctl_name = CTL_UNNUMBERED,
26799 ++ .procname = "chroot_deny_fchdir",
26800 ++ .data = &grsec_enable_chroot_fchdir,
26801 ++ .maxlen = sizeof(int),
26802 ++ .mode = 0600,
26803 ++ .proc_handler = &proc_dointvec,
26804 ++ },
26805 ++#endif
26806 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
26807 ++ {
26808 ++ .ctl_name = CTL_UNNUMBERED,
26809 ++ .procname = "chroot_deny_chroot",
26810 ++ .data = &grsec_enable_chroot_double,
26811 ++ .maxlen = sizeof(int),
26812 ++ .mode = 0600,
26813 ++ .proc_handler = &proc_dointvec,
26814 ++ },
26815 ++#endif
26816 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
26817 ++ {
26818 ++ .ctl_name = CTL_UNNUMBERED,
26819 ++ .procname = "chroot_deny_pivot",
26820 ++ .data = &grsec_enable_chroot_pivot,
26821 ++ .maxlen = sizeof(int),
26822 ++ .mode = 0600,
26823 ++ .proc_handler = &proc_dointvec,
26824 ++ },
26825 ++#endif
26826 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
26827 ++ {
26828 ++ .ctl_name = CTL_UNNUMBERED,
26829 ++ .procname = "chroot_enforce_chdir",
26830 ++ .data = &grsec_enable_chroot_chdir,
26831 ++ .maxlen = sizeof(int),
26832 ++ .mode = 0600,
26833 ++ .proc_handler = &proc_dointvec,
26834 ++ },
26835 ++#endif
26836 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
26837 ++ {
26838 ++ .ctl_name = CTL_UNNUMBERED,
26839 ++ .procname = "chroot_deny_chmod",
26840 ++ .data = &grsec_enable_chroot_chmod,
26841 ++ .maxlen = sizeof(int),
26842 ++ .mode = 0600,
26843 ++ .proc_handler = &proc_dointvec,
26844 ++ },
26845 ++#endif
26846 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
26847 ++ {
26848 ++ .ctl_name = CTL_UNNUMBERED,
26849 ++ .procname = "chroot_deny_mknod",
26850 ++ .data = &grsec_enable_chroot_mknod,
26851 ++ .maxlen = sizeof(int),
26852 ++ .mode = 0600,
26853 ++ .proc_handler = &proc_dointvec,
26854 ++ },
26855 ++#endif
26856 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
26857 ++ {
26858 ++ .ctl_name = CTL_UNNUMBERED,
26859 ++ .procname = "chroot_restrict_nice",
26860 ++ .data = &grsec_enable_chroot_nice,
26861 ++ .maxlen = sizeof(int),
26862 ++ .mode = 0600,
26863 ++ .proc_handler = &proc_dointvec,
26864 ++ },
26865 ++#endif
26866 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
26867 ++ {
26868 ++ .ctl_name = CTL_UNNUMBERED,
26869 ++ .procname = "chroot_execlog",
26870 ++ .data = &grsec_enable_chroot_execlog,
26871 ++ .maxlen = sizeof(int),
26872 ++ .mode = 0600,
26873 ++ .proc_handler = &proc_dointvec,
26874 ++ },
26875 ++#endif
26876 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
26877 ++ {
26878 ++ .ctl_name = CTL_UNNUMBERED,
26879 ++ .procname = "chroot_caps",
26880 ++ .data = &grsec_enable_chroot_caps,
26881 ++ .maxlen = sizeof(int),
26882 ++ .mode = 0600,
26883 ++ .proc_handler = &proc_dointvec,
26884 ++ },
26885 ++#endif
26886 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
26887 ++ {
26888 ++ .ctl_name = CTL_UNNUMBERED,
26889 ++ .procname = "chroot_deny_sysctl",
26890 ++ .data = &grsec_enable_chroot_sysctl,
26891 ++ .maxlen = sizeof(int),
26892 ++ .mode = 0600,
26893 ++ .proc_handler = &proc_dointvec,
26894 ++ },
26895 ++#endif
26896 ++#ifdef CONFIG_GRKERNSEC_TPE
26897 ++ {
26898 ++ .ctl_name = CTL_UNNUMBERED,
26899 ++ .procname = "tpe",
26900 ++ .data = &grsec_enable_tpe,
26901 ++ .maxlen = sizeof(int),
26902 ++ .mode = 0600,
26903 ++ .proc_handler = &proc_dointvec,
26904 ++ },
26905 ++ {
26906 ++ .ctl_name = CTL_UNNUMBERED,
26907 ++ .procname = "tpe_gid",
26908 ++ .data = &grsec_tpe_gid,
26909 ++ .maxlen = sizeof(int),
26910 ++ .mode = 0600,
26911 ++ .proc_handler = &proc_dointvec,
26912 ++ },
26913 ++#endif
26914 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
26915 ++ {
26916 ++ .ctl_name = CTL_UNNUMBERED,
26917 ++ .procname = "tpe_restrict_all",
26918 ++ .data = &grsec_enable_tpe_all,
26919 ++ .maxlen = sizeof(int),
26920 ++ .mode = 0600,
26921 ++ .proc_handler = &proc_dointvec,
26922 ++ },
26923 ++#endif
26924 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
26925 ++ {
26926 ++ .ctl_name = CTL_UNNUMBERED,
26927 ++ .procname = "socket_all",
26928 ++ .data = &grsec_enable_socket_all,
26929 ++ .maxlen = sizeof(int),
26930 ++ .mode = 0600,
26931 ++ .proc_handler = &proc_dointvec,
26932 ++ },
26933 ++ {
26934 ++ .ctl_name = CTL_UNNUMBERED,
26935 ++ .procname = "socket_all_gid",
26936 ++ .data = &grsec_socket_all_gid,
26937 ++ .maxlen = sizeof(int),
26938 ++ .mode = 0600,
26939 ++ .proc_handler = &proc_dointvec,
26940 ++ },
26941 ++#endif
26942 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
26943 ++ {
26944 ++ .ctl_name = CTL_UNNUMBERED,
26945 ++ .procname = "socket_client",
26946 ++ .data = &grsec_enable_socket_client,
26947 ++ .maxlen = sizeof(int),
26948 ++ .mode = 0600,
26949 ++ .proc_handler = &proc_dointvec,
26950 ++ },
26951 ++ {
26952 ++ .ctl_name = CTL_UNNUMBERED,
26953 ++ .procname = "socket_client_gid",
26954 ++ .data = &grsec_socket_client_gid,
26955 ++ .maxlen = sizeof(int),
26956 ++ .mode = 0600,
26957 ++ .proc_handler = &proc_dointvec,
26958 ++ },
26959 ++#endif
26960 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
26961 ++ {
26962 ++ .ctl_name = CTL_UNNUMBERED,
26963 ++ .procname = "socket_server",
26964 ++ .data = &grsec_enable_socket_server,
26965 ++ .maxlen = sizeof(int),
26966 ++ .mode = 0600,
26967 ++ .proc_handler = &proc_dointvec,
26968 ++ },
26969 ++ {
26970 ++ .ctl_name = CTL_UNNUMBERED,
26971 ++ .procname = "socket_server_gid",
26972 ++ .data = &grsec_socket_server_gid,
26973 ++ .maxlen = sizeof(int),
26974 ++ .mode = 0600,
26975 ++ .proc_handler = &proc_dointvec,
26976 ++ },
26977 ++#endif
26978 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
26979 ++ {
26980 ++ .ctl_name = CTL_UNNUMBERED,
26981 ++ .procname = "audit_group",
26982 ++ .data = &grsec_enable_group,
26983 ++ .maxlen = sizeof(int),
26984 ++ .mode = 0600,
26985 ++ .proc_handler = &proc_dointvec,
26986 ++ },
26987 ++ {
26988 ++ .ctl_name = CTL_UNNUMBERED,
26989 ++ .procname = "audit_gid",
26990 ++ .data = &grsec_audit_gid,
26991 ++ .maxlen = sizeof(int),
26992 ++ .mode = 0600,
26993 ++ .proc_handler = &proc_dointvec,
26994 ++ },
26995 ++#endif
26996 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
26997 ++ {
26998 ++ .ctl_name = CTL_UNNUMBERED,
26999 ++ .procname = "audit_chdir",
27000 ++ .data = &grsec_enable_chdir,
27001 ++ .maxlen = sizeof(int),
27002 ++ .mode = 0600,
27003 ++ .proc_handler = &proc_dointvec,
27004 ++ },
27005 ++#endif
27006 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
27007 ++ {
27008 ++ .ctl_name = CTL_UNNUMBERED,
27009 ++ .procname = "audit_mount",
27010 ++ .data = &grsec_enable_mount,
27011 ++ .maxlen = sizeof(int),
27012 ++ .mode = 0600,
27013 ++ .proc_handler = &proc_dointvec,
27014 ++ },
27015 ++#endif
27016 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
27017 ++ {
27018 ++ .ctl_name = CTL_UNNUMBERED,
27019 ++ .procname = "audit_ipc",
27020 ++ .data = &grsec_enable_audit_ipc,
27021 ++ .maxlen = sizeof(int),
27022 ++ .mode = 0600,
27023 ++ .proc_handler = &proc_dointvec,
27024 ++ },
27025 ++#endif
27026 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
27027 ++ {
27028 ++ .ctl_name = CTL_UNNUMBERED,
27029 ++ .procname = "audit_textrel",
27030 ++ .data = &grsec_enable_audit_textrel,
27031 ++ .maxlen = sizeof(int),
27032 ++ .mode = 0600,
27033 ++ .proc_handler = &proc_dointvec,
27034 ++ },
27035 ++#endif
27036 ++#ifdef CONFIG_GRKERNSEC_DMESG
27037 ++ {
27038 ++ .ctl_name = CTL_UNNUMBERED,
27039 ++ .procname = "dmesg",
27040 ++ .data = &grsec_enable_dmesg,
27041 ++ .maxlen = sizeof(int),
27042 ++ .mode = 0600,
27043 ++ .proc_handler = &proc_dointvec,
27044 ++ },
27045 ++#endif
27046 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
27047 ++ {
27048 ++ .ctl_name = CTL_UNNUMBERED,
27049 ++ .procname = "chroot_findtask",
27050 ++ .data = &grsec_enable_chroot_findtask,
27051 ++ .maxlen = sizeof(int),
27052 ++ .mode = 0600,
27053 ++ .proc_handler = &proc_dointvec,
27054 ++ },
27055 ++#endif
27056 ++#ifdef CONFIG_GRKERNSEC_RESLOG
27057 ++ {
27058 ++ .ctl_name = CTL_UNNUMBERED,
27059 ++ .procname = "resource_logging",
27060 ++ .data = &grsec_resource_logging,
27061 ++ .maxlen = sizeof(int),
27062 ++ .mode = 0600,
27063 ++ .proc_handler = &proc_dointvec,
27064 ++ },
27065 ++#endif
27066 ++ {
27067 ++ .ctl_name = CTL_UNNUMBERED,
27068 ++ .procname = "grsec_lock",
27069 ++ .data = &grsec_lock,
27070 ++ .maxlen = sizeof(int),
27071 ++ .mode = 0600,
27072 ++ .proc_handler = &proc_dointvec,
27073 ++ },
27074 ++#endif
27075 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
27076 ++ {
27077 ++ .ctl_name = CTL_UNNUMBERED,
27078 ++ .procname = "disable_modules",
27079 ++ .data = &grsec_modstop,
27080 ++ .maxlen = sizeof(int),
27081 ++ .mode = 0600,
27082 ++ .proc_handler = &proc_dointvec,
27083 ++ },
27084 ++#endif
27085 ++ { .ctl_name = 0 }
27086 ++};
27087 ++#endif
27088 ++
27089 ++int gr_check_modstop(void)
27090 ++{
27091 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
27092 ++ if (grsec_modstop == 1) {
27093 ++ gr_log_noargs(GR_DONT_AUDIT, GR_STOPMOD_MSG);
27094 ++ return 1;
27095 ++ }
27096 ++#endif
27097 ++ return 0;
27098 ++}
27099 +diff -urNp linux-2.6.27.10/grsecurity/grsec_textrel.c linux-2.6.27.10/grsecurity/grsec_textrel.c
27100 +--- linux-2.6.27.10/grsecurity/grsec_textrel.c 1969-12-31 19:00:00.000000000 -0500
27101 ++++ linux-2.6.27.10/grsecurity/grsec_textrel.c 2008-11-18 03:38:45.000000000 -0500
27102 +@@ -0,0 +1,16 @@
27103 ++#include <linux/kernel.h>
27104 ++#include <linux/sched.h>
27105 ++#include <linux/mm.h>
27106 ++#include <linux/file.h>
27107 ++#include <linux/grinternal.h>
27108 ++#include <linux/grsecurity.h>
27109 ++
27110 ++void
27111 ++gr_log_textrel(struct vm_area_struct * vma)
27112 ++{
27113 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
27114 ++ if (grsec_enable_audit_textrel)
27115 ++ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
27116 ++#endif
27117 ++ return;
27118 ++}
27119 +diff -urNp linux-2.6.27.10/grsecurity/grsec_time.c linux-2.6.27.10/grsecurity/grsec_time.c
27120 +--- linux-2.6.27.10/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
27121 ++++ linux-2.6.27.10/grsecurity/grsec_time.c 2008-11-18 03:38:45.000000000 -0500
27122 +@@ -0,0 +1,13 @@
27123 ++#include <linux/kernel.h>
27124 ++#include <linux/sched.h>
27125 ++#include <linux/grinternal.h>
27126 ++
27127 ++void
27128 ++gr_log_timechange(void)
27129 ++{
27130 ++#ifdef CONFIG_GRKERNSEC_TIME
27131 ++ if (grsec_enable_time)
27132 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
27133 ++#endif
27134 ++ return;
27135 ++}
27136 +diff -urNp linux-2.6.27.10/grsecurity/grsec_tpe.c linux-2.6.27.10/grsecurity/grsec_tpe.c
27137 +--- linux-2.6.27.10/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
27138 ++++ linux-2.6.27.10/grsecurity/grsec_tpe.c 2008-11-18 03:38:45.000000000 -0500
27139 +@@ -0,0 +1,37 @@
27140 ++#include <linux/kernel.h>
27141 ++#include <linux/sched.h>
27142 ++#include <linux/file.h>
27143 ++#include <linux/fs.h>
27144 ++#include <linux/grinternal.h>
27145 ++
27146 ++extern int gr_acl_tpe_check(void);
27147 ++
27148 ++int
27149 ++gr_tpe_allow(const struct file *file)
27150 ++{
27151 ++#ifdef CONFIG_GRKERNSEC
27152 ++ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
27153 ++
27154 ++ if (current->uid && ((grsec_enable_tpe &&
27155 ++#ifdef CONFIG_GRKERNSEC_TPE_INVERT
27156 ++ !in_group_p(grsec_tpe_gid)
27157 ++#else
27158 ++ in_group_p(grsec_tpe_gid)
27159 ++#endif
27160 ++ ) || gr_acl_tpe_check()) &&
27161 ++ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
27162 ++ (inode->i_mode & S_IWOTH))))) {
27163 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
27164 ++ return 0;
27165 ++ }
27166 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
27167 ++ if (current->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
27168 ++ ((inode->i_uid && (inode->i_uid != current->uid)) ||
27169 ++ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
27170 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
27171 ++ return 0;
27172 ++ }
27173 ++#endif
27174 ++#endif
27175 ++ return 1;
27176 ++}
27177 +diff -urNp linux-2.6.27.10/grsecurity/grsum.c linux-2.6.27.10/grsecurity/grsum.c
27178 +--- linux-2.6.27.10/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
27179 ++++ linux-2.6.27.10/grsecurity/grsum.c 2008-11-18 03:38:45.000000000 -0500
27180 +@@ -0,0 +1,59 @@
27181 ++#include <linux/err.h>
27182 ++#include <linux/kernel.h>
27183 ++#include <linux/sched.h>
27184 ++#include <linux/mm.h>
27185 ++#include <linux/scatterlist.h>
27186 ++#include <linux/crypto.h>
27187 ++#include <linux/gracl.h>
27188 ++
27189 ++
27190 ++#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
27191 ++#error "crypto and sha256 must be built into the kernel"
27192 ++#endif
27193 ++
27194 ++int
27195 ++chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
27196 ++{
27197 ++ char *p;
27198 ++ struct crypto_hash *tfm;
27199 ++ struct hash_desc desc;
27200 ++ struct scatterlist sg;
27201 ++ unsigned char temp_sum[GR_SHA_LEN];
27202 ++ volatile int retval = 0;
27203 ++ volatile int dummy = 0;
27204 ++ unsigned int i;
27205 ++
27206 ++ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
27207 ++ if (IS_ERR(tfm)) {
27208 ++ /* should never happen, since sha256 should be built in */
27209 ++ return 1;
27210 ++ }
27211 ++
27212 ++ desc.tfm = tfm;
27213 ++ desc.flags = 0;
27214 ++
27215 ++ crypto_hash_init(&desc);
27216 ++
27217 ++ p = salt;
27218 ++ sg_set_buf(&sg, p, GR_SALT_LEN);
27219 ++ crypto_hash_update(&desc, &sg, sg.length);
27220 ++
27221 ++ p = entry->pw;
27222 ++ sg_set_buf(&sg, p, strlen(p));
27223 ++
27224 ++ crypto_hash_update(&desc, &sg, sg.length);
27225 ++
27226 ++ crypto_hash_final(&desc, temp_sum);
27227 ++
27228 ++ memset(entry->pw, 0, GR_PW_LEN);
27229 ++
27230 ++ for (i = 0; i < GR_SHA_LEN; i++)
27231 ++ if (sum[i] != temp_sum[i])
27232 ++ retval = 1;
27233 ++ else
27234 ++ dummy = 1; // waste a cycle
27235 ++
27236 ++ crypto_free_hash(tfm);
27237 ++
27238 ++ return retval;
27239 ++}
27240 +diff -urNp linux-2.6.27.10/grsecurity/Kconfig linux-2.6.27.10/grsecurity/Kconfig
27241 +--- linux-2.6.27.10/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
27242 ++++ linux-2.6.27.10/grsecurity/Kconfig 2008-11-18 11:18:57.000000000 -0500
27243 +@@ -0,0 +1,863 @@
27244 ++#
27245 ++# grecurity configuration
27246 ++#
27247 ++
27248 ++menu "Grsecurity"
27249 ++
27250 ++config GRKERNSEC
27251 ++ bool "Grsecurity"
27252 ++ select CRYPTO
27253 ++ select CRYPTO_SHA256
27254 ++ select SECURITY
27255 ++ select SECURITY_CAPABILITIES
27256 ++ help
27257 ++ If you say Y here, you will be able to configure many features
27258 ++ that will enhance the security of your system. It is highly
27259 ++ recommended that you say Y here and read through the help
27260 ++ for each option so that you fully understand the features and
27261 ++ can evaluate their usefulness for your machine.
27262 ++
27263 ++choice
27264 ++ prompt "Security Level"
27265 ++ depends on GRKERNSEC
27266 ++ default GRKERNSEC_CUSTOM
27267 ++
27268 ++config GRKERNSEC_LOW
27269 ++ bool "Low"
27270 ++ select GRKERNSEC_LINK
27271 ++ select GRKERNSEC_FIFO
27272 ++ select GRKERNSEC_EXECVE
27273 ++ select GRKERNSEC_RANDNET
27274 ++ select GRKERNSEC_DMESG
27275 ++ select GRKERNSEC_CHROOT_CHDIR
27276 ++ select GRKERNSEC_MODSTOP if (MODULES)
27277 ++
27278 ++ help
27279 ++ If you choose this option, several of the grsecurity options will
27280 ++ be enabled that will give you greater protection against a number
27281 ++ of attacks, while assuring that none of your software will have any
27282 ++ conflicts with the additional security measures. If you run a lot
27283 ++ of unusual software, or you are having problems with the higher
27284 ++ security levels, you should say Y here. With this option, the
27285 ++ following features are enabled:
27286 ++
27287 ++ - Linking restrictions
27288 ++ - FIFO restrictions
27289 ++ - Enforcing RLIMIT_NPROC on execve
27290 ++ - Restricted dmesg
27291 ++ - Enforced chdir("/") on chroot
27292 ++ - Runtime module disabling
27293 ++
27294 ++config GRKERNSEC_MEDIUM
27295 ++ bool "Medium"
27296 ++ select PAX
27297 ++ select PAX_EI_PAX
27298 ++ select PAX_PT_PAX_FLAGS
27299 ++ select PAX_HAVE_ACL_FLAGS
27300 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
27301 ++ select GRKERNSEC_CHROOT_SYSCTL
27302 ++ select GRKERNSEC_LINK
27303 ++ select GRKERNSEC_FIFO
27304 ++ select GRKERNSEC_EXECVE
27305 ++ select GRKERNSEC_DMESG
27306 ++ select GRKERNSEC_RANDNET
27307 ++ select GRKERNSEC_FORKFAIL
27308 ++ select GRKERNSEC_TIME
27309 ++ select GRKERNSEC_SIGNAL
27310 ++ select GRKERNSEC_CHROOT
27311 ++ select GRKERNSEC_CHROOT_UNIX
27312 ++ select GRKERNSEC_CHROOT_MOUNT
27313 ++ select GRKERNSEC_CHROOT_PIVOT
27314 ++ select GRKERNSEC_CHROOT_DOUBLE
27315 ++ select GRKERNSEC_CHROOT_CHDIR
27316 ++ select GRKERNSEC_CHROOT_MKNOD
27317 ++ select GRKERNSEC_PROC
27318 ++ select GRKERNSEC_PROC_USERGROUP
27319 ++ select GRKERNSEC_MODSTOP if (MODULES)
27320 ++ select PAX_RANDUSTACK
27321 ++ select PAX_ASLR
27322 ++ select PAX_RANDMMAP
27323 ++ select PAX_REFCOUNT if (X86)
27324 ++
27325 ++ help
27326 ++ If you say Y here, several features in addition to those included
27327 ++ in the low additional security level will be enabled. These
27328 ++ features provide even more security to your system, though in rare
27329 ++ cases they may be incompatible with very old or poorly written
27330 ++ software. If you enable this option, make sure that your auth
27331 ++ service (identd) is running as gid 1001. With this option,
27332 ++ the following features (in addition to those provided in the
27333 ++ low additional security level) will be enabled:
27334 ++
27335 ++ - Failed fork logging
27336 ++ - Time change logging
27337 ++ - Signal logging
27338 ++ - Deny mounts in chroot
27339 ++ - Deny double chrooting
27340 ++ - Deny sysctl writes in chroot
27341 ++ - Deny mknod in chroot
27342 ++ - Deny access to abstract AF_UNIX sockets out of chroot
27343 ++ - Deny pivot_root in chroot
27344 ++ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
27345 ++ - /proc restrictions with special GID set to 10 (usually wheel)
27346 ++ - Address Space Layout Randomization (ASLR)
27347 ++
27348 ++config GRKERNSEC_HIGH
27349 ++ bool "High"
27350 ++ select GRKERNSEC_LINK
27351 ++ select GRKERNSEC_FIFO
27352 ++ select GRKERNSEC_EXECVE
27353 ++ select GRKERNSEC_DMESG
27354 ++ select GRKERNSEC_FORKFAIL
27355 ++ select GRKERNSEC_TIME
27356 ++ select GRKERNSEC_SIGNAL
27357 ++ select GRKERNSEC_CHROOT_SHMAT
27358 ++ select GRKERNSEC_CHROOT_UNIX
27359 ++ select GRKERNSEC_CHROOT_MOUNT
27360 ++ select GRKERNSEC_CHROOT_FCHDIR
27361 ++ select GRKERNSEC_CHROOT_PIVOT
27362 ++ select GRKERNSEC_CHROOT_DOUBLE
27363 ++ select GRKERNSEC_CHROOT_CHDIR
27364 ++ select GRKERNSEC_CHROOT_MKNOD
27365 ++ select GRKERNSEC_CHROOT_CAPS
27366 ++ select GRKERNSEC_CHROOT_SYSCTL
27367 ++ select GRKERNSEC_CHROOT_FINDTASK
27368 ++ select GRKERNSEC_PROC
27369 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
27370 ++ select GRKERNSEC_HIDESYM
27371 ++ select GRKERNSEC_BRUTE
27372 ++ select GRKERNSEC_PROC_USERGROUP
27373 ++ select GRKERNSEC_KMEM
27374 ++ select GRKERNSEC_RESLOG
27375 ++ select GRKERNSEC_RANDNET
27376 ++ select GRKERNSEC_PROC_ADD
27377 ++ select GRKERNSEC_CHROOT_CHMOD
27378 ++ select GRKERNSEC_CHROOT_NICE
27379 ++ select GRKERNSEC_AUDIT_MOUNT
27380 ++ select GRKERNSEC_MODSTOP if (MODULES)
27381 ++ select PAX
27382 ++ select PAX_RANDUSTACK
27383 ++ select PAX_ASLR
27384 ++ select PAX_RANDMMAP
27385 ++ select PAX_NOEXEC
27386 ++ select PAX_MPROTECT
27387 ++ select PAX_EI_PAX
27388 ++ select PAX_PT_PAX_FLAGS
27389 ++ select PAX_HAVE_ACL_FLAGS
27390 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
27391 ++ select PAX_MEMORY_UDEREF if (!X86_64 && !COMPAT_VDSO)
27392 ++ select PAX_RANDKSTACK if (X86_TSC && !X86_64)
27393 ++ select PAX_SEGMEXEC if (X86 && !X86_64)
27394 ++ select PAX_PAGEEXEC if (!X86)
27395 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
27396 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
27397 ++ select PAX_SYSCALL if (PPC32)
27398 ++ select PAX_EMUTRAMP if (PARISC)
27399 ++ select PAX_EMUSIGRT if (PARISC)
27400 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
27401 ++ select PAX_REFCOUNT if (X86)
27402 ++ help
27403 ++ If you say Y here, many of the features of grsecurity will be
27404 ++ enabled, which will protect you against many kinds of attacks
27405 ++ against your system. The heightened security comes at a cost
27406 ++ of an increased chance of incompatibilities with rare software
27407 ++ on your machine. Since this security level enables PaX, you should
27408 ++ view <http://pax.grsecurity.net> and read about the PaX
27409 ++ project. While you are there, download chpax and run it on
27410 ++ binaries that cause problems with PaX. Also remember that
27411 ++ since the /proc restrictions are enabled, you must run your
27412 ++ identd as gid 1001. This security level enables the following
27413 ++ features in addition to those listed in the low and medium
27414 ++ security levels:
27415 ++
27416 ++ - Additional /proc restrictions
27417 ++ - Chmod restrictions in chroot
27418 ++ - No signals, ptrace, or viewing of processes outside of chroot
27419 ++ - Capability restrictions in chroot
27420 ++ - Deny fchdir out of chroot
27421 ++ - Priority restrictions in chroot
27422 ++ - Segmentation-based implementation of PaX
27423 ++ - Mprotect restrictions
27424 ++ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
27425 ++ - Kernel stack randomization
27426 ++ - Mount/unmount/remount logging
27427 ++ - Kernel symbol hiding
27428 ++ - Prevention of memory exhaustion-based exploits
27429 ++config GRKERNSEC_CUSTOM
27430 ++ bool "Custom"
27431 ++ help
27432 ++ If you say Y here, you will be able to configure every grsecurity
27433 ++ option, which allows you to enable many more features that aren't
27434 ++ covered in the basic security levels. These additional features
27435 ++ include TPE, socket restrictions, and the sysctl system for
27436 ++ grsecurity. It is advised that you read through the help for
27437 ++ each option to determine its usefulness in your situation.
27438 ++
27439 ++endchoice
27440 ++
27441 ++menu "Address Space Protection"
27442 ++depends on GRKERNSEC
27443 ++
27444 ++config GRKERNSEC_KMEM
27445 ++ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
27446 ++ help
27447 ++ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
27448 ++ be written to via mmap or otherwise to modify the running kernel.
27449 ++ /dev/port will also not be allowed to be opened. If you have module
27450 ++ support disabled, enabling this will close up four ways that are
27451 ++ currently used to insert malicious code into the running kernel.
27452 ++ Even with all these features enabled, we still highly recommend that
27453 ++ you use the RBAC system, as it is still possible for an attacker to
27454 ++ modify the running kernel through privileged I/O granted by ioperm/iopl.
27455 ++ If you are not using XFree86, you may be able to stop this additional
27456 ++ case by enabling the 'Disable privileged I/O' option. Though nothing
27457 ++ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
27458 ++ but only to video memory, which is the only writing we allow in this
27459 ++ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
27460 ++ not be allowed to mprotect it with PROT_WRITE later.
27461 ++ It is highly recommended that you say Y here if you meet all the
27462 ++ conditions above.
27463 ++
27464 ++config GRKERNSEC_IO
27465 ++ bool "Disable privileged I/O"
27466 ++ depends on X86
27467 ++ select RTC
27468 ++ help
27469 ++ If you say Y here, all ioperm and iopl calls will return an error.
27470 ++ Ioperm and iopl can be used to modify the running kernel.
27471 ++ Unfortunately, some programs need this access to operate properly,
27472 ++ the most notable of which are XFree86 and hwclock. hwclock can be
27473 ++ remedied by having RTC support in the kernel, so CONFIG_RTC is
27474 ++ enabled if this option is enabled, to ensure that hwclock operates
27475 ++ correctly. XFree86 still will not operate correctly with this option
27476 ++ enabled, so DO NOT CHOOSE Y IF YOU USE XFree86. If you use XFree86
27477 ++ and you still want to protect your kernel against modification,
27478 ++ use the RBAC system.
27479 ++
27480 ++config GRKERNSEC_PROC_MEMMAP
27481 ++ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
27482 ++ depends on PAX_NOEXEC || PAX_ASLR
27483 ++ help
27484 ++ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
27485 ++ give no information about the addresses of its mappings if
27486 ++ PaX features that rely on random addresses are enabled on the task.
27487 ++ If you use PaX it is greatly recommended that you say Y here as it
27488 ++ closes up a hole that makes the full ASLR useless for suid
27489 ++ binaries.
27490 ++
27491 ++config GRKERNSEC_BRUTE
27492 ++ bool "Deter exploit bruteforcing"
27493 ++ help
27494 ++ If you say Y here, attempts to bruteforce exploits against forking
27495 ++ daemons such as apache or sshd will be deterred. When a child of a
27496 ++ forking daemon is killed by PaX or crashes due to an illegal
27497 ++ instruction, the parent process will be delayed 30 seconds upon every
27498 ++ subsequent fork until the administrator is able to assess the
27499 ++ situation and restart the daemon. It is recommended that you also
27500 ++ enable signal logging in the auditing section so that logs are
27501 ++ generated when a process performs an illegal instruction.
27502 ++
27503 ++config GRKERNSEC_MODSTOP
27504 ++ bool "Runtime module disabling"
27505 ++ depends on MODULES
27506 ++ help
27507 ++ If you say Y here, you will be able to disable the ability to (un)load
27508 ++ modules at runtime. This feature is useful if you need the ability
27509 ++ to load kernel modules at boot time, but do not want to allow an
27510 ++ attacker to load a rootkit kernel module into the system, or to remove
27511 ++ a loaded kernel module important to system functioning. You should
27512 ++ enable the /dev/mem protection feature as well, since rootkits can be
27513 ++ inserted into the kernel via other methods than kernel modules. Since
27514 ++ an untrusted module could still be loaded by modifying init scripts and
27515 ++ rebooting the system, it is also recommended that you enable the RBAC
27516 ++ system. If you enable this option, a sysctl option with name
27517 ++ "disable_modules" will be created. Setting this option to "1" disables
27518 ++ module loading. After this option is set, no further writes to it are
27519 ++ allowed until the system is rebooted.
27520 ++
27521 ++config GRKERNSEC_HIDESYM
27522 ++ bool "Hide kernel symbols"
27523 ++ help
27524 ++ If you say Y here, getting information on loaded modules, and
27525 ++ displaying all kernel symbols through a syscall will be restricted
27526 ++ to users with CAP_SYS_MODULE. This option is only effective
27527 ++ provided the following conditions are met:
27528 ++ 1) The kernel using grsecurity is not precompiled by some distribution
27529 ++ 2) You are using the RBAC system and hiding other files such as your
27530 ++ kernel image and System.map
27531 ++ 3) You have the additional /proc restrictions enabled, which removes
27532 ++ /proc/kcore
27533 ++ If the above conditions are met, this option will aid to provide a
27534 ++ useful protection against local and remote kernel exploitation of
27535 ++ overflows and arbitrary read/write vulnerabilities.
27536 ++
27537 ++endmenu
27538 ++menu "Role Based Access Control Options"
27539 ++depends on GRKERNSEC
27540 ++
27541 ++config GRKERNSEC_ACL_HIDEKERN
27542 ++ bool "Hide kernel processes"
27543 ++ help
27544 ++ If you say Y here, all kernel threads will be hidden to all
27545 ++ processes but those whose subject has the "view hidden processes"
27546 ++ flag.
27547 ++
27548 ++config GRKERNSEC_ACL_MAXTRIES
27549 ++ int "Maximum tries before password lockout"
27550 ++ default 3
27551 ++ help
27552 ++ This option enforces the maximum number of times a user can attempt
27553 ++ to authorize themselves with the grsecurity RBAC system before being
27554 ++ denied the ability to attempt authorization again for a specified time.
27555 ++ The lower the number, the harder it will be to brute-force a password.
27556 ++
27557 ++config GRKERNSEC_ACL_TIMEOUT
27558 ++ int "Time to wait after max password tries, in seconds"
27559 ++ default 30
27560 ++ help
27561 ++ This option specifies the time the user must wait after attempting to
27562 ++ authorize to the RBAC system with the maximum number of invalid
27563 ++ passwords. The higher the number, the harder it will be to brute-force
27564 ++ a password.
27565 ++
27566 ++endmenu
27567 ++menu "Filesystem Protections"
27568 ++depends on GRKERNSEC
27569 ++
27570 ++config GRKERNSEC_PROC
27571 ++ bool "Proc restrictions"
27572 ++ help
27573 ++ If you say Y here, the permissions of the /proc filesystem
27574 ++ will be altered to enhance system security and privacy. You MUST
27575 ++ choose either a user only restriction or a user and group restriction.
27576 ++ Depending upon the option you choose, you can either restrict users to
27577 ++ see only the processes they themselves run, or choose a group that can
27578 ++ view all processes and files normally restricted to root if you choose
27579 ++ the "restrict to user only" option. NOTE: If you're running identd as
27580 ++ a non-root user, you will have to run it as the group you specify here.
27581 ++
27582 ++config GRKERNSEC_PROC_USER
27583 ++ bool "Restrict /proc to user only"
27584 ++ depends on GRKERNSEC_PROC
27585 ++ help
27586 ++ If you say Y here, non-root users will only be able to view their own
27587 ++ processes, and restricts them from viewing network-related information,
27588 ++ and viewing kernel symbol and module information.
27589 ++
27590 ++config GRKERNSEC_PROC_USERGROUP
27591 ++ bool "Allow special group"
27592 ++ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
27593 ++ help
27594 ++ If you say Y here, you will be able to select a group that will be
27595 ++ able to view all processes, network-related information, and
27596 ++ kernel and symbol information. This option is useful if you want
27597 ++ to run identd as a non-root user.
27598 ++
27599 ++config GRKERNSEC_PROC_GID
27600 ++ int "GID for special group"
27601 ++ depends on GRKERNSEC_PROC_USERGROUP
27602 ++ default 1001
27603 ++
27604 ++config GRKERNSEC_PROC_ADD
27605 ++ bool "Additional restrictions"
27606 ++ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
27607 ++ help
27608 ++ If you say Y here, additional restrictions will be placed on
27609 ++ /proc that keep normal users from viewing device information and
27610 ++ slabinfo information that could be useful for exploits.
27611 ++
27612 ++config GRKERNSEC_LINK
27613 ++ bool "Linking restrictions"
27614 ++ help
27615 ++ If you say Y here, /tmp race exploits will be prevented, since users
27616 ++ will no longer be able to follow symlinks owned by other users in
27617 ++ world-writable +t directories (i.e. /tmp), unless the owner of the
27618 ++ symlink is the owner of the directory. users will also not be
27619 ++ able to hardlink to files they do not own. If the sysctl option is
27620 ++ enabled, a sysctl option with name "linking_restrictions" is created.
27621 ++
27622 ++config GRKERNSEC_FIFO
27623 ++ bool "FIFO restrictions"
27624 ++ help
27625 ++ If you say Y here, users will not be able to write to FIFOs they don't
27626 ++ own in world-writable +t directories (i.e. /tmp), unless the owner of
27627 ++ the FIFO is the same owner of the directory it's held in. If the sysctl
27628 ++ option is enabled, a sysctl option with name "fifo_restrictions" is
27629 ++ created.
27630 ++
27631 ++config GRKERNSEC_CHROOT
27632 ++ bool "Chroot jail restrictions"
27633 ++ help
27634 ++ If you say Y here, you will be able to choose several options that will
27635 ++ make breaking out of a chrooted jail much more difficult. If you
27636 ++ encounter no software incompatibilities with the following options, it
27637 ++ is recommended that you enable each one.
27638 ++
27639 ++config GRKERNSEC_CHROOT_MOUNT
27640 ++ bool "Deny mounts"
27641 ++ depends on GRKERNSEC_CHROOT
27642 ++ help
27643 ++ If you say Y here, processes inside a chroot will not be able to
27644 ++ mount or remount filesystems. If the sysctl option is enabled, a
27645 ++ sysctl option with name "chroot_deny_mount" is created.
27646 ++
27647 ++config GRKERNSEC_CHROOT_DOUBLE
27648 ++ bool "Deny double-chroots"
27649 ++ depends on GRKERNSEC_CHROOT
27650 ++ help
27651 ++ If you say Y here, processes inside a chroot will not be able to chroot
27652 ++ again outside the chroot. This is a widely used method of breaking
27653 ++ out of a chroot jail and should not be allowed. If the sysctl
27654 ++ option is enabled, a sysctl option with name
27655 ++ "chroot_deny_chroot" is created.
27656 ++
27657 ++config GRKERNSEC_CHROOT_PIVOT
27658 ++ bool "Deny pivot_root in chroot"
27659 ++ depends on GRKERNSEC_CHROOT
27660 ++ help
27661 ++ If you say Y here, processes inside a chroot will not be able to use
27662 ++ a function called pivot_root() that was introduced in Linux 2.3.41. It
27663 ++ works similar to chroot in that it changes the root filesystem. This
27664 ++ function could be misused in a chrooted process to attempt to break out
27665 ++ of the chroot, and therefore should not be allowed. If the sysctl
27666 ++ option is enabled, a sysctl option with name "chroot_deny_pivot" is
27667 ++ created.
27668 ++
27669 ++config GRKERNSEC_CHROOT_CHDIR
27670 ++ bool "Enforce chdir(\"/\") on all chroots"
27671 ++ depends on GRKERNSEC_CHROOT
27672 ++ help
27673 ++ If you say Y here, the current working directory of all newly-chrooted
27674 ++ applications will be set to the the root directory of the chroot.
27675 ++ The man page on chroot(2) states:
27676 ++ Note that this call does not change the current working
27677 ++ directory, so that `.' can be outside the tree rooted at
27678 ++ `/'. In particular, the super-user can escape from a
27679 ++ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
27680 ++
27681 ++ It is recommended that you say Y here, since it's not known to break
27682 ++ any software. If the sysctl option is enabled, a sysctl option with
27683 ++ name "chroot_enforce_chdir" is created.
27684 ++
27685 ++config GRKERNSEC_CHROOT_CHMOD
27686 ++ bool "Deny (f)chmod +s"
27687 ++ depends on GRKERNSEC_CHROOT
27688 ++ help
27689 ++ If you say Y here, processes inside a chroot will not be able to chmod
27690 ++ or fchmod files to make them have suid or sgid bits. This protects
27691 ++ against another published method of breaking a chroot. If the sysctl
27692 ++ option is enabled, a sysctl option with name "chroot_deny_chmod" is
27693 ++ created.
27694 ++
27695 ++config GRKERNSEC_CHROOT_FCHDIR
27696 ++ bool "Deny fchdir out of chroot"
27697 ++ depends on GRKERNSEC_CHROOT
27698 ++ help
27699 ++ If you say Y here, a well-known method of breaking chroots by fchdir'ing
27700 ++ to a file descriptor of the chrooting process that points to a directory
27701 ++ outside the filesystem will be stopped. If the sysctl option
27702 ++ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
27703 ++
27704 ++config GRKERNSEC_CHROOT_MKNOD
27705 ++ bool "Deny mknod"
27706 ++ depends on GRKERNSEC_CHROOT
27707 ++ help
27708 ++ If you say Y here, processes inside a chroot will not be allowed to
27709 ++ mknod. The problem with using mknod inside a chroot is that it
27710 ++ would allow an attacker to create a device entry that is the same
27711 ++ as one on the physical root of your system, which could range from
27712 ++ anything from the console device to a device for your harddrive (which
27713 ++ they could then use to wipe the drive or steal data). It is recommended
27714 ++ that you say Y here, unless you run into software incompatibilities.
27715 ++ If the sysctl option is enabled, a sysctl option with name
27716 ++ "chroot_deny_mknod" is created.
27717 ++
27718 ++config GRKERNSEC_CHROOT_SHMAT
27719 ++ bool "Deny shmat() out of chroot"
27720 ++ depends on GRKERNSEC_CHROOT
27721 ++ help
27722 ++ If you say Y here, processes inside a chroot will not be able to attach
27723 ++ to shared memory segments that were created outside of the chroot jail.
27724 ++ It is recommended that you say Y here. If the sysctl option is enabled,
27725 ++ a sysctl option with name "chroot_deny_shmat" is created.
27726 ++
27727 ++config GRKERNSEC_CHROOT_UNIX
27728 ++ bool "Deny access to abstract AF_UNIX sockets out of chroot"
27729 ++ depends on GRKERNSEC_CHROOT
27730 ++ help
27731 ++ If you say Y here, processes inside a chroot will not be able to
27732 ++ connect to abstract (meaning not belonging to a filesystem) Unix
27733 ++ domain sockets that were bound outside of a chroot. It is recommended
27734 ++ that you say Y here. If the sysctl option is enabled, a sysctl option
27735 ++ with name "chroot_deny_unix" is created.
27736 ++
27737 ++config GRKERNSEC_CHROOT_FINDTASK
27738 ++ bool "Protect outside processes"
27739 ++ depends on GRKERNSEC_CHROOT
27740 ++ help
27741 ++ If you say Y here, processes inside a chroot will not be able to
27742 ++ kill, send signals with fcntl, ptrace, capget, getpgid, getsid,
27743 ++ or view any process outside of the chroot. If the sysctl
27744 ++ option is enabled, a sysctl option with name "chroot_findtask" is
27745 ++ created.
27746 ++
27747 ++config GRKERNSEC_CHROOT_NICE
27748 ++ bool "Restrict priority changes"
27749 ++ depends on GRKERNSEC_CHROOT
27750 ++ help
27751 ++ If you say Y here, processes inside a chroot will not be able to raise
27752 ++ the priority of processes in the chroot, or alter the priority of
27753 ++ processes outside the chroot. This provides more security than simply
27754 ++ removing CAP_SYS_NICE from the process' capability set. If the
27755 ++ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
27756 ++ is created.
27757 ++
27758 ++config GRKERNSEC_CHROOT_SYSCTL
27759 ++ bool "Deny sysctl writes"
27760 ++ depends on GRKERNSEC_CHROOT
27761 ++ help
27762 ++ If you say Y here, an attacker in a chroot will not be able to
27763 ++ write to sysctl entries, either by sysctl(2) or through a /proc
27764 ++ interface. It is strongly recommended that you say Y here. If the
27765 ++ sysctl option is enabled, a sysctl option with name
27766 ++ "chroot_deny_sysctl" is created.
27767 ++
27768 ++config GRKERNSEC_CHROOT_CAPS
27769 ++ bool "Capability restrictions"
27770 ++ depends on GRKERNSEC_CHROOT
27771 ++ help
27772 ++ If you say Y here, the capabilities on all root processes within a
27773 ++ chroot jail will be lowered to stop module insertion, raw i/o,
27774 ++ system and net admin tasks, rebooting the system, modifying immutable
27775 ++ files, modifying IPC owned by another, and changing the system time.
27776 ++ This is left an option because it can break some apps. Disable this
27777 ++ if your chrooted apps are having problems performing those kinds of
27778 ++ tasks. If the sysctl option is enabled, a sysctl option with
27779 ++ name "chroot_caps" is created.
27780 ++
27781 ++endmenu
27782 ++menu "Kernel Auditing"
27783 ++depends on GRKERNSEC
27784 ++
27785 ++config GRKERNSEC_AUDIT_GROUP
27786 ++ bool "Single group for auditing"
27787 ++ help
27788 ++ If you say Y here, the exec, chdir, (un)mount, and ipc logging features
27789 ++ will only operate on a group you specify. This option is recommended
27790 ++ if you only want to watch certain users instead of having a large
27791 ++ amount of logs from the entire system. If the sysctl option is enabled,
27792 ++ a sysctl option with name "audit_group" is created.
27793 ++
27794 ++config GRKERNSEC_AUDIT_GID
27795 ++ int "GID for auditing"
27796 ++ depends on GRKERNSEC_AUDIT_GROUP
27797 ++ default 1007
27798 ++
27799 ++config GRKERNSEC_EXECLOG
27800 ++ bool "Exec logging"
27801 ++ help
27802 ++ If you say Y here, all execve() calls will be logged (since the
27803 ++ other exec*() calls are frontends to execve(), all execution
27804 ++ will be logged). Useful for shell-servers that like to keep track
27805 ++ of their users. If the sysctl option is enabled, a sysctl option with
27806 ++ name "exec_logging" is created.
27807 ++ WARNING: This option when enabled will produce a LOT of logs, especially
27808 ++ on an active system.
27809 ++
27810 ++config GRKERNSEC_RESLOG
27811 ++ bool "Resource logging"
27812 ++ help
27813 ++ If you say Y here, all attempts to overstep resource limits will
27814 ++ be logged with the resource name, the requested size, and the current
27815 ++ limit. It is highly recommended that you say Y here. If the sysctl
27816 ++ option is enabled, a sysctl option with name "resource_logging" is
27817 ++ created. If the RBAC system is enabled, the sysctl value is ignored.
27818 ++
27819 ++config GRKERNSEC_CHROOT_EXECLOG
27820 ++ bool "Log execs within chroot"
27821 ++ help
27822 ++ If you say Y here, all executions inside a chroot jail will be logged
27823 ++ to syslog. This can cause a large amount of logs if certain
27824 ++ applications (eg. djb's daemontools) are installed on the system, and
27825 ++ is therefore left as an option. If the sysctl option is enabled, a
27826 ++ sysctl option with name "chroot_execlog" is created.
27827 ++
27828 ++config GRKERNSEC_AUDIT_CHDIR
27829 ++ bool "Chdir logging"
27830 ++ help
27831 ++ If you say Y here, all chdir() calls will be logged. If the sysctl
27832 ++ option is enabled, a sysctl option with name "audit_chdir" is created.
27833 ++
27834 ++config GRKERNSEC_AUDIT_MOUNT
27835 ++ bool "(Un)Mount logging"
27836 ++ help
27837 ++ If you say Y here, all mounts and unmounts will be logged. If the
27838 ++ sysctl option is enabled, a sysctl option with name "audit_mount" is
27839 ++ created.
27840 ++
27841 ++config GRKERNSEC_AUDIT_IPC
27842 ++ bool "IPC logging"
27843 ++ help
27844 ++ If you say Y here, creation and removal of message queues, semaphores,
27845 ++ and shared memory will be logged. If the sysctl option is enabled, a
27846 ++ sysctl option with name "audit_ipc" is created.
27847 ++
27848 ++config GRKERNSEC_SIGNAL
27849 ++ bool "Signal logging"
27850 ++ help
27851 ++ If you say Y here, certain important signals will be logged, such as
27852 ++ SIGSEGV, which will as a result inform you of when a error in a program
27853 ++ occurred, which in some cases could mean a possible exploit attempt.
27854 ++ If the sysctl option is enabled, a sysctl option with name
27855 ++ "signal_logging" is created.
27856 ++
27857 ++config GRKERNSEC_FORKFAIL
27858 ++ bool "Fork failure logging"
27859 ++ help
27860 ++ If you say Y here, all failed fork() attempts will be logged.
27861 ++ This could suggest a fork bomb, or someone attempting to overstep
27862 ++ their process limit. If the sysctl option is enabled, a sysctl option
27863 ++ with name "forkfail_logging" is created.
27864 ++
27865 ++config GRKERNSEC_TIME
27866 ++ bool "Time change logging"
27867 ++ help
27868 ++ If you say Y here, any changes of the system clock will be logged.
27869 ++ If the sysctl option is enabled, a sysctl option with name
27870 ++ "timechange_logging" is created.
27871 ++
27872 ++config GRKERNSEC_PROC_IPADDR
27873 ++ bool "/proc/<pid>/ipaddr support"
27874 ++ help
27875 ++ If you say Y here, a new entry will be added to each /proc/<pid>
27876 ++ directory that contains the IP address of the person using the task.
27877 ++ The IP is carried across local TCP and AF_UNIX stream sockets.
27878 ++ This information can be useful for IDS/IPSes to perform remote response
27879 ++ to a local attack. The entry is readable by only the owner of the
27880 ++ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
27881 ++ the RBAC system), and thus does not create privacy concerns.
27882 ++
27883 ++config GRKERNSEC_AUDIT_TEXTREL
27884 ++ bool 'ELF text relocations logging (READ HELP)'
27885 ++ depends on PAX_MPROTECT
27886 ++ help
27887 ++ If you say Y here, text relocations will be logged with the filename
27888 ++ of the offending library or binary. The purpose of the feature is
27889 ++ to help Linux distribution developers get rid of libraries and
27890 ++ binaries that need text relocations which hinder the future progress
27891 ++ of PaX. Only Linux distribution developers should say Y here, and
27892 ++ never on a production machine, as this option creates an information
27893 ++ leak that could aid an attacker in defeating the randomization of
27894 ++ a single memory region. If the sysctl option is enabled, a sysctl
27895 ++ option with name "audit_textrel" is created.
27896 ++
27897 ++endmenu
27898 ++
27899 ++menu "Executable Protections"
27900 ++depends on GRKERNSEC
27901 ++
27902 ++config GRKERNSEC_EXECVE
27903 ++ bool "Enforce RLIMIT_NPROC on execs"
27904 ++ help
27905 ++ If you say Y here, users with a resource limit on processes will
27906 ++ have the value checked during execve() calls. The current system
27907 ++ only checks the system limit during fork() calls. If the sysctl option
27908 ++ is enabled, a sysctl option with name "execve_limiting" is created.
27909 ++
27910 ++config GRKERNSEC_DMESG
27911 ++ bool "Dmesg(8) restriction"
27912 ++ help
27913 ++ If you say Y here, non-root users will not be able to use dmesg(8)
27914 ++ to view up to the last 4kb of messages in the kernel's log buffer.
27915 ++ If the sysctl option is enabled, a sysctl option with name "dmesg" is
27916 ++ created.
27917 ++
27918 ++config GRKERNSEC_TPE
27919 ++ bool "Trusted Path Execution (TPE)"
27920 ++ help
27921 ++ If you say Y here, you will be able to choose a gid to add to the
27922 ++ supplementary groups of users you want to mark as "untrusted."
27923 ++ These users will not be able to execute any files that are not in
27924 ++ root-owned directories writable only by root. If the sysctl option
27925 ++ is enabled, a sysctl option with name "tpe" is created.
27926 ++
27927 ++config GRKERNSEC_TPE_ALL
27928 ++ bool "Partially restrict non-root users"
27929 ++ depends on GRKERNSEC_TPE
27930 ++ help
27931 ++ If you say Y here, All non-root users other than the ones in the
27932 ++ group specified in the main TPE option will only be allowed to
27933 ++ execute files in directories they own that are not group or
27934 ++ world-writable, or in directories owned by root and writable only by
27935 ++ root. If the sysctl option is enabled, a sysctl option with name
27936 ++ "tpe_restrict_all" is created.
27937 ++
27938 ++config GRKERNSEC_TPE_INVERT
27939 ++ bool "Invert GID option"
27940 ++ depends on GRKERNSEC_TPE
27941 ++ help
27942 ++ If you say Y here, the group you specify in the TPE configuration will
27943 ++ decide what group TPE restrictions will be *disabled* for. This
27944 ++ option is useful if you want TPE restrictions to be applied to most
27945 ++ users on the system.
27946 ++
27947 ++config GRKERNSEC_TPE_GID
27948 ++ int "GID for untrusted users"
27949 ++ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
27950 ++ default 1005
27951 ++ help
27952 ++ If you have selected the "Invert GID option" above, setting this
27953 ++ GID determines what group TPE restrictions will be *disabled* for.
27954 ++ If you have not selected the "Invert GID option" above, setting this
27955 ++ GID determines what group TPE restrictions will be *enabled* for.
27956 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
27957 ++ is created.
27958 ++
27959 ++config GRKERNSEC_TPE_GID
27960 ++ int "GID for trusted users"
27961 ++ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
27962 ++ default 1005
27963 ++ help
27964 ++ If you have selected the "Invert GID option" above, setting this
27965 ++ GID determines what group TPE restrictions will be *disabled* for.
27966 ++ If you have not selected the "Invert GID option" above, setting this
27967 ++ GID determines what group TPE restrictions will be *enabled* for.
27968 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
27969 ++ is created.
27970 ++
27971 ++endmenu
27972 ++menu "Network Protections"
27973 ++depends on GRKERNSEC
27974 ++
27975 ++config GRKERNSEC_RANDNET
27976 ++ bool "Larger entropy pools"
27977 ++ help
27978 ++ If you say Y here, the entropy pools used for many features of Linux
27979 ++ and grsecurity will be doubled in size. Since several grsecurity
27980 ++ features use additional randomness, it is recommended that you say Y
27981 ++ here. Saying Y here has a similar effect as modifying
27982 ++ /proc/sys/kernel/random/poolsize.
27983 ++
27984 ++config GRKERNSEC_SOCKET
27985 ++ bool "Socket restrictions"
27986 ++ help
27987 ++ If you say Y here, you will be able to choose from several options.
27988 ++ If you assign a GID on your system and add it to the supplementary
27989 ++ groups of users you want to restrict socket access to, this patch
27990 ++ will perform up to three things, based on the option(s) you choose.
27991 ++
27992 ++config GRKERNSEC_SOCKET_ALL
27993 ++ bool "Deny any sockets to group"
27994 ++ depends on GRKERNSEC_SOCKET
27995 ++ help
27996 ++ If you say Y here, you will be able to choose a GID of whose users will
27997 ++ be unable to connect to other hosts from your machine or run server
27998 ++ applications from your machine. If the sysctl option is enabled, a
27999 ++ sysctl option with name "socket_all" is created.
28000 ++
28001 ++config GRKERNSEC_SOCKET_ALL_GID
28002 ++ int "GID to deny all sockets for"
28003 ++ depends on GRKERNSEC_SOCKET_ALL
28004 ++ default 1004
28005 ++ help
28006 ++ Here you can choose the GID to disable socket access for. Remember to
28007 ++ add the users you want socket access disabled for to the GID
28008 ++ specified here. If the sysctl option is enabled, a sysctl option
28009 ++ with name "socket_all_gid" is created.
28010 ++
28011 ++config GRKERNSEC_SOCKET_CLIENT
28012 ++ bool "Deny client sockets to group"
28013 ++ depends on GRKERNSEC_SOCKET
28014 ++ help
28015 ++ If you say Y here, you will be able to choose a GID of whose users will
28016 ++ be unable to connect to other hosts from your machine, but will be
28017 ++ able to run servers. If this option is enabled, all users in the group
28018 ++ you specify will have to use passive mode when initiating ftp transfers
28019 ++ from the shell on your machine. If the sysctl option is enabled, a
28020 ++ sysctl option with name "socket_client" is created.
28021 ++
28022 ++config GRKERNSEC_SOCKET_CLIENT_GID
28023 ++ int "GID to deny client sockets for"
28024 ++ depends on GRKERNSEC_SOCKET_CLIENT
28025 ++ default 1003
28026 ++ help
28027 ++ Here you can choose the GID to disable client socket access for.
28028 ++ Remember to add the users you want client socket access disabled for to
28029 ++ the GID specified here. If the sysctl option is enabled, a sysctl
28030 ++ option with name "socket_client_gid" is created.
28031 ++
28032 ++config GRKERNSEC_SOCKET_SERVER
28033 ++ bool "Deny server sockets to group"
28034 ++ depends on GRKERNSEC_SOCKET
28035 ++ help
28036 ++ If you say Y here, you will be able to choose a GID of whose users will
28037 ++ be unable to run server applications from your machine. If the sysctl
28038 ++ option is enabled, a sysctl option with name "socket_server" is created.
28039 ++
28040 ++config GRKERNSEC_SOCKET_SERVER_GID
28041 ++ int "GID to deny server sockets for"
28042 ++ depends on GRKERNSEC_SOCKET_SERVER
28043 ++ default 1002
28044 ++ help
28045 ++ Here you can choose the GID to disable server socket access for.
28046 ++ Remember to add the users you want server socket access disabled for to
28047 ++ the GID specified here. If the sysctl option is enabled, a sysctl
28048 ++ option with name "socket_server_gid" is created.
28049 ++
28050 ++endmenu
28051 ++menu "Sysctl support"
28052 ++depends on GRKERNSEC && SYSCTL
28053 ++
28054 ++config GRKERNSEC_SYSCTL
28055 ++ bool "Sysctl support"
28056 ++ help
28057 ++ If you say Y here, you will be able to change the options that
28058 ++ grsecurity runs with at bootup, without having to recompile your
28059 ++ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
28060 ++ to enable (1) or disable (0) various features. All the sysctl entries
28061 ++ are mutable until the "grsec_lock" entry is set to a non-zero value.
28062 ++ All features enabled in the kernel configuration are disabled at boot
28063 ++ if you do not say Y to the "Turn on features by default" option.
28064 ++ All options should be set at startup, and the grsec_lock entry should
28065 ++ be set to a non-zero value after all the options are set.
28066 ++ *THIS IS EXTREMELY IMPORTANT*
28067 ++
28068 ++config GRKERNSEC_SYSCTL_ON
28069 ++ bool "Turn on features by default"
28070 ++ depends on GRKERNSEC_SYSCTL
28071 ++ help
28072 ++ If you say Y here, instead of having all features enabled in the
28073 ++ kernel configuration disabled at boot time, the features will be
28074 ++ enabled at boot time. It is recommended you say Y here unless
28075 ++ there is some reason you would want all sysctl-tunable features to
28076 ++ be disabled by default. As mentioned elsewhere, it is important
28077 ++ to enable the grsec_lock entry once you have finished modifying
28078 ++ the sysctl entries.
28079 ++
28080 ++endmenu
28081 ++menu "Logging Options"
28082 ++depends on GRKERNSEC
28083 ++
28084 ++config GRKERNSEC_FLOODTIME
28085 ++ int "Seconds in between log messages (minimum)"
28086 ++ default 10
28087 ++ help
28088 ++ This option allows you to enforce the number of seconds between
28089 ++ grsecurity log messages. The default should be suitable for most
28090 ++ people, however, if you choose to change it, choose a value small enough
28091 ++ to allow informative logs to be produced, but large enough to
28092 ++ prevent flooding.
28093 ++
28094 ++config GRKERNSEC_FLOODBURST
28095 ++ int "Number of messages in a burst (maximum)"
28096 ++ default 4
28097 ++ help
28098 ++ This option allows you to choose the maximum number of messages allowed
28099 ++ within the flood time interval you chose in a separate option. The
28100 ++ default should be suitable for most people, however if you find that
28101 ++ many of your logs are being interpreted as flooding, you may want to
28102 ++ raise this value.
28103 ++
28104 ++endmenu
28105 ++
28106 ++endmenu
28107 +diff -urNp linux-2.6.27.10/grsecurity/Makefile linux-2.6.27.10/grsecurity/Makefile
28108 +--- linux-2.6.27.10/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
28109 ++++ linux-2.6.27.10/grsecurity/Makefile 2008-11-18 03:38:45.000000000 -0500
28110 +@@ -0,0 +1,20 @@
28111 ++# grsecurity's ACL system was originally written in 2001 by Michael Dalton
28112 ++# during 2001-2005 it has been completely redesigned by Brad Spengler
28113 ++# into an RBAC system
28114 ++#
28115 ++# All code in this directory and various hooks inserted throughout the kernel
28116 ++# are copyright Brad Spengler, and released under the GPL v2 or higher
28117 ++
28118 ++obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
28119 ++ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
28120 ++ grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o grsec_textrel.o
28121 ++
28122 ++obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
28123 ++ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
28124 ++ gracl_learn.o grsec_log.o
28125 ++obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
28126 ++
28127 ++ifndef CONFIG_GRKERNSEC
28128 ++obj-y += grsec_disabled.o
28129 ++endif
28130 ++
28131 +diff -urNp linux-2.6.27.10/include/asm-cris/kmap_types.h linux-2.6.27.10/include/asm-cris/kmap_types.h
28132 +--- linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28133 ++++ linux-2.6.27.10/include/asm-cris/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28134 +@@ -19,6 +19,7 @@ enum km_type {
28135 + KM_IRQ1,
28136 + KM_SOFTIRQ0,
28137 + KM_SOFTIRQ1,
28138 ++ KM_CLEARPAGE,
28139 + KM_TYPE_NR
28140 + };
28141 +
28142 +diff -urNp linux-2.6.27.10/include/asm-frv/kmap_types.h linux-2.6.27.10/include/asm-frv/kmap_types.h
28143 +--- linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28144 ++++ linux-2.6.27.10/include/asm-frv/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28145 +@@ -23,6 +23,7 @@ enum km_type {
28146 + KM_IRQ1,
28147 + KM_SOFTIRQ0,
28148 + KM_SOFTIRQ1,
28149 ++ KM_CLEARPAGE,
28150 + KM_TYPE_NR
28151 + };
28152 +
28153 +diff -urNp linux-2.6.27.10/include/asm-generic/futex.h linux-2.6.27.10/include/asm-generic/futex.h
28154 +--- linux-2.6.27.10/include/asm-generic/futex.h 2008-11-07 12:55:34.000000000 -0500
28155 ++++ linux-2.6.27.10/include/asm-generic/futex.h 2008-11-18 03:38:45.000000000 -0500
28156 +@@ -6,7 +6,7 @@
28157 + #include <asm/errno.h>
28158 +
28159 + static inline int
28160 +-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
28161 ++futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
28162 + {
28163 + int op = (encoded_op >> 28) & 7;
28164 + int cmp = (encoded_op >> 24) & 15;
28165 +@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
28166 + }
28167 +
28168 + static inline int
28169 +-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
28170 ++futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
28171 + {
28172 + return -ENOSYS;
28173 + }
28174 +diff -urNp linux-2.6.27.10/include/asm-generic/vmlinux.lds.h linux-2.6.27.10/include/asm-generic/vmlinux.lds.h
28175 +--- linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-07 12:55:34.000000000 -0500
28176 ++++ linux-2.6.27.10/include/asm-generic/vmlinux.lds.h 2008-11-18 03:38:45.000000000 -0500
28177 +@@ -59,6 +59,7 @@
28178 + .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
28179 + VMLINUX_SYMBOL(__start_rodata) = .; \
28180 + *(.rodata) *(.rodata.*) \
28181 ++ *(.data.read_only) \
28182 + *(__vermagic) /* Kernel version magic */ \
28183 + *(__markers_strings) /* Markers: strings */ \
28184 + } \
28185 +diff -urNp linux-2.6.27.10/include/asm-m32r/kmap_types.h linux-2.6.27.10/include/asm-m32r/kmap_types.h
28186 +--- linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28187 ++++ linux-2.6.27.10/include/asm-m32r/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28188 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
28189 + D(10) KM_IRQ1,
28190 + D(11) KM_SOFTIRQ0,
28191 + D(12) KM_SOFTIRQ1,
28192 +-D(13) KM_TYPE_NR
28193 ++D(13) KM_CLEARPAGE,
28194 ++D(14) KM_TYPE_NR
28195 + };
28196 +
28197 + #undef D
28198 +diff -urNp linux-2.6.27.10/include/asm-m68k/kmap_types.h linux-2.6.27.10/include/asm-m68k/kmap_types.h
28199 +--- linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28200 ++++ linux-2.6.27.10/include/asm-m68k/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28201 +@@ -15,6 +15,7 @@ enum km_type {
28202 + KM_IRQ1,
28203 + KM_SOFTIRQ0,
28204 + KM_SOFTIRQ1,
28205 ++ KM_CLEARPAGE,
28206 + KM_TYPE_NR
28207 + };
28208 +
28209 +diff -urNp linux-2.6.27.10/include/asm-mips/elf.h linux-2.6.27.10/include/asm-mips/elf.h
28210 +--- linux-2.6.27.10/include/asm-mips/elf.h 2008-11-07 12:55:34.000000000 -0500
28211 ++++ linux-2.6.27.10/include/asm-mips/elf.h 2008-11-18 03:38:45.000000000 -0500
28212 +@@ -368,4 +368,11 @@ extern int dump_task_fpu(struct task_str
28213 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
28214 + #endif
28215 +
28216 ++#ifdef CONFIG_PAX_ASLR
28217 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
28218 ++
28219 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
28220 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
28221 ++#endif
28222 ++
28223 + #endif /* _ASM_ELF_H */
28224 +diff -urNp linux-2.6.27.10/include/asm-mips/kmap_types.h linux-2.6.27.10/include/asm-mips/kmap_types.h
28225 +--- linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28226 ++++ linux-2.6.27.10/include/asm-mips/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28227 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
28228 + D(10) KM_IRQ1,
28229 + D(11) KM_SOFTIRQ0,
28230 + D(12) KM_SOFTIRQ1,
28231 +-D(13) KM_TYPE_NR
28232 ++D(13) KM_CLEARPAGE,
28233 ++D(14) KM_TYPE_NR
28234 + };
28235 +
28236 + #undef D
28237 +diff -urNp linux-2.6.27.10/include/asm-mips/page.h linux-2.6.27.10/include/asm-mips/page.h
28238 +--- linux-2.6.27.10/include/asm-mips/page.h 2008-11-07 12:55:34.000000000 -0500
28239 ++++ linux-2.6.27.10/include/asm-mips/page.h 2008-11-18 03:38:45.000000000 -0500
28240 +@@ -82,7 +82,7 @@ extern void copy_user_highpage(struct pa
28241 + #ifdef CONFIG_CPU_MIPS32
28242 + typedef struct { unsigned long pte_low, pte_high; } pte_t;
28243 + #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
28244 +- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
28245 ++ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
28246 + #else
28247 + typedef struct { unsigned long long pte; } pte_t;
28248 + #define pte_val(x) ((x).pte)
28249 +diff -urNp linux-2.6.27.10/include/asm-mips/system.h linux-2.6.27.10/include/asm-mips/system.h
28250 +--- linux-2.6.27.10/include/asm-mips/system.h 2008-11-07 12:55:34.000000000 -0500
28251 ++++ linux-2.6.27.10/include/asm-mips/system.h 2008-11-18 03:38:45.000000000 -0500
28252 +@@ -215,6 +215,6 @@ extern void per_cpu_trap_init(void);
28253 + */
28254 + #define __ARCH_WANT_UNLOCKED_CTXSW
28255 +
28256 +-extern unsigned long arch_align_stack(unsigned long sp);
28257 ++#define arch_align_stack(x) ((x) & ALMASK)
28258 +
28259 + #endif /* _ASM_SYSTEM_H */
28260 +diff -urNp linux-2.6.27.10/include/asm-mn10300/kmap_types.h linux-2.6.27.10/include/asm-mn10300/kmap_types.h
28261 +--- linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28262 ++++ linux-2.6.27.10/include/asm-mn10300/kmap_types.h 2008-11-18 03:39:50.000000000 -0500
28263 +@@ -25,6 +25,7 @@ enum km_type {
28264 + KM_IRQ1,
28265 + KM_SOFTIRQ0,
28266 + KM_SOFTIRQ1,
28267 ++ KM_CLEARPAGE,
28268 + KM_TYPE_NR
28269 + };
28270 +
28271 +diff -urNp linux-2.6.27.10/include/asm-parisc/elf.h linux-2.6.27.10/include/asm-parisc/elf.h
28272 +--- linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-07 12:55:34.000000000 -0500
28273 ++++ linux-2.6.27.10/include/asm-parisc/elf.h 2008-11-18 03:38:45.000000000 -0500
28274 +@@ -333,6 +333,13 @@ struct pt_regs; /* forward declaration..
28275 +
28276 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
28277 +
28278 ++#ifdef CONFIG_PAX_ASLR
28279 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
28280 ++
28281 ++#define PAX_DELTA_MMAP_LEN 16
28282 ++#define PAX_DELTA_STACK_LEN 16
28283 ++#endif
28284 ++
28285 + /* This yields a mask that user programs can use to figure out what
28286 + instruction set this CPU supports. This could be done in user space,
28287 + but it's not easy, and we've already done it here. */
28288 +diff -urNp linux-2.6.27.10/include/asm-parisc/kmap_types.h linux-2.6.27.10/include/asm-parisc/kmap_types.h
28289 +--- linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28290 ++++ linux-2.6.27.10/include/asm-parisc/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28291 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
28292 + D(10) KM_IRQ1,
28293 + D(11) KM_SOFTIRQ0,
28294 + D(12) KM_SOFTIRQ1,
28295 +-D(13) KM_TYPE_NR
28296 ++D(13) KM_CLEARPAGE,
28297 ++D(14) KM_TYPE_NR
28298 + };
28299 +
28300 + #undef D
28301 +diff -urNp linux-2.6.27.10/include/asm-parisc/pgtable.h linux-2.6.27.10/include/asm-parisc/pgtable.h
28302 +--- linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-07 12:55:34.000000000 -0500
28303 ++++ linux-2.6.27.10/include/asm-parisc/pgtable.h 2008-11-18 03:38:45.000000000 -0500
28304 +@@ -202,6 +202,17 @@
28305 + #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
28306 + #define PAGE_COPY PAGE_EXECREAD
28307 + #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
28308 ++
28309 ++#ifdef CONFIG_PAX_PAGEEXEC
28310 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
28311 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
28312 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
28313 ++#else
28314 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
28315 ++# define PAGE_COPY_NOEXEC PAGE_COPY
28316 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
28317 ++#endif
28318 ++
28319 + #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
28320 + #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
28321 + #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
28322 +diff -urNp linux-2.6.27.10/include/asm-um/kmap_types.h linux-2.6.27.10/include/asm-um/kmap_types.h
28323 +--- linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
28324 ++++ linux-2.6.27.10/include/asm-um/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
28325 +@@ -23,6 +23,7 @@ enum km_type {
28326 + KM_IRQ1,
28327 + KM_SOFTIRQ0,
28328 + KM_SOFTIRQ1,
28329 ++ KM_CLEARPAGE,
28330 + KM_TYPE_NR
28331 + };
28332 +
28333 +diff -urNp linux-2.6.27.10/include/asm-um/page.h linux-2.6.27.10/include/asm-um/page.h
28334 +--- linux-2.6.27.10/include/asm-um/page.h 2008-11-07 12:55:34.000000000 -0500
28335 ++++ linux-2.6.27.10/include/asm-um/page.h 2008-11-18 03:38:45.000000000 -0500
28336 +@@ -14,6 +14,9 @@
28337 + #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
28338 + #define PAGE_MASK (~(PAGE_SIZE-1))
28339 +
28340 ++#define ktla_ktva(addr) (addr)
28341 ++#define ktva_ktla(addr) (addr)
28342 ++
28343 + #ifndef __ASSEMBLY__
28344 +
28345 + struct page;
28346 +diff -urNp linux-2.6.27.10/include/asm-x86/alternative.h linux-2.6.27.10/include/asm-x86/alternative.h
28347 +--- linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-07 12:55:34.000000000 -0500
28348 ++++ linux-2.6.27.10/include/asm-x86/alternative.h 2008-11-18 03:38:45.000000000 -0500
28349 +@@ -96,7 +96,7 @@ const unsigned char *const *find_nop_tab
28350 + " .byte 662b-661b\n" /* sourcelen */ \
28351 + " .byte 664f-663f\n" /* replacementlen */ \
28352 + ".previous\n" \
28353 +- ".section .altinstr_replacement,\"ax\"\n" \
28354 ++ ".section .altinstr_replacement,\"a\"\n" \
28355 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
28356 + ".previous" :: "i" (feature) : "memory")
28357 +
28358 +@@ -120,7 +120,7 @@ const unsigned char *const *find_nop_tab
28359 + " .byte 662b-661b\n" /* sourcelen */ \
28360 + " .byte 664f-663f\n" /* replacementlen */ \
28361 + ".previous\n" \
28362 +- ".section .altinstr_replacement,\"ax\"\n" \
28363 ++ ".section .altinstr_replacement,\"a\"\n" \
28364 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
28365 + ".previous" :: "i" (feature), ##input)
28366 +
28367 +@@ -135,7 +135,7 @@ const unsigned char *const *find_nop_tab
28368 + " .byte 662b-661b\n" /* sourcelen */ \
28369 + " .byte 664f-663f\n" /* replacementlen */ \
28370 + ".previous\n" \
28371 +- ".section .altinstr_replacement,\"ax\"\n" \
28372 ++ ".section .altinstr_replacement,\"a\"\n" \
28373 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
28374 + ".previous" : output : [feat] "i" (feature), ##input)
28375 +
28376 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_32.h linux-2.6.27.10/include/asm-x86/atomic_32.h
28377 +--- linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-07 12:55:34.000000000 -0500
28378 ++++ linux-2.6.27.10/include/asm-x86/atomic_32.h 2008-11-18 03:38:45.000000000 -0500
28379 +@@ -47,7 +47,15 @@ typedef struct {
28380 + */
28381 + static inline void atomic_add(int i, atomic_t *v)
28382 + {
28383 +- asm volatile(LOCK_PREFIX "addl %1,%0"
28384 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
28385 ++
28386 ++#ifdef CONFIG_PAX_REFCOUNT
28387 ++ "jno 0f\n"
28388 ++ LOCK_PREFIX "subl %1,%0\n"
28389 ++ "into\n0:\n"
28390 ++ _ASM_EXTABLE(0b, 0b)
28391 ++#endif
28392 ++
28393 + : "+m" (v->counter)
28394 + : "ir" (i));
28395 + }
28396 +@@ -61,7 +69,15 @@ static inline void atomic_add(int i, ato
28397 + */
28398 + static inline void atomic_sub(int i, atomic_t *v)
28399 + {
28400 +- asm volatile(LOCK_PREFIX "subl %1,%0"
28401 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
28402 ++
28403 ++#ifdef CONFIG_PAX_REFCOUNT
28404 ++ "jno 0f\n"
28405 ++ LOCK_PREFIX "addl %1,%0\n"
28406 ++ "into\n0:\n"
28407 ++ _ASM_EXTABLE(0b, 0b)
28408 ++#endif
28409 ++
28410 + : "+m" (v->counter)
28411 + : "ir" (i));
28412 + }
28413 +@@ -79,7 +95,16 @@ static inline int atomic_sub_and_test(in
28414 + {
28415 + unsigned char c;
28416 +
28417 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
28418 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
28419 ++
28420 ++#ifdef CONFIG_PAX_REFCOUNT
28421 ++ "jno 0f\n"
28422 ++ LOCK_PREFIX "addl %2,%0\n"
28423 ++ "into\n0:\n"
28424 ++ _ASM_EXTABLE(0b, 0b)
28425 ++#endif
28426 ++
28427 ++ "sete %1\n"
28428 + : "+m" (v->counter), "=qm" (c)
28429 + : "ir" (i) : "memory");
28430 + return c;
28431 +@@ -93,7 +118,18 @@ static inline int atomic_sub_and_test(in
28432 + */
28433 + static inline void atomic_inc(atomic_t *v)
28434 + {
28435 +- asm volatile(LOCK_PREFIX "incl %0"
28436 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28437 ++
28438 ++#ifdef CONFIG_PAX_REFCOUNT
28439 ++ "into\n0:\n"
28440 ++ ".pushsection .fixup,\"ax\"\n"
28441 ++ "1:\n"
28442 ++ LOCK_PREFIX "decl %0\n"
28443 ++ "jmp 0b\n"
28444 ++ ".popsection\n"
28445 ++ _ASM_EXTABLE(0b, 1b)
28446 ++#endif
28447 ++
28448 + : "+m" (v->counter));
28449 + }
28450 +
28451 +@@ -105,7 +141,18 @@ static inline void atomic_inc(atomic_t *
28452 + */
28453 + static inline void atomic_dec(atomic_t *v)
28454 + {
28455 +- asm volatile(LOCK_PREFIX "decl %0"
28456 ++ asm volatile(LOCK_PREFIX "decl %0\n"
28457 ++
28458 ++#ifdef CONFIG_PAX_REFCOUNT
28459 ++ "into\n0:\n"
28460 ++ ".pushsection .fixup,\"ax\"\n"
28461 ++ "1: \n"
28462 ++ LOCK_PREFIX "incl %0\n"
28463 ++ "jmp 0b\n"
28464 ++ ".popsection\n"
28465 ++ _ASM_EXTABLE(0b, 1b)
28466 ++#endif
28467 ++
28468 + : "+m" (v->counter));
28469 + }
28470 +
28471 +@@ -121,7 +168,19 @@ static inline int atomic_dec_and_test(at
28472 + {
28473 + unsigned char c;
28474 +
28475 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
28476 ++ asm volatile(LOCK_PREFIX "decl %0\n"
28477 ++
28478 ++#ifdef CONFIG_PAX_REFCOUNT
28479 ++ "into\n0:\n"
28480 ++ ".pushsection .fixup,\"ax\"\n"
28481 ++ "1: \n"
28482 ++ LOCK_PREFIX "incl %0\n"
28483 ++ "jmp 0b\n"
28484 ++ ".popsection\n"
28485 ++ _ASM_EXTABLE(0b, 1b)
28486 ++#endif
28487 ++
28488 ++ "sete %1\n"
28489 + : "+m" (v->counter), "=qm" (c)
28490 + : : "memory");
28491 + return c != 0;
28492 +@@ -139,7 +198,19 @@ static inline int atomic_inc_and_test(at
28493 + {
28494 + unsigned char c;
28495 +
28496 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
28497 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28498 ++
28499 ++#ifdef CONFIG_PAX_REFCOUNT
28500 ++ "into\n0:\n"
28501 ++ ".pushsection .fixup,\"ax\"\n"
28502 ++ "1: \n"
28503 ++ LOCK_PREFIX "decl %0\n"
28504 ++ "jmp 0b\n"
28505 ++ ".popsection\n"
28506 ++ _ASM_EXTABLE(0b, 1b)
28507 ++#endif
28508 ++
28509 ++ "sete %1\n"
28510 + : "+m" (v->counter), "=qm" (c)
28511 + : : "memory");
28512 + return c != 0;
28513 +@@ -158,7 +229,16 @@ static inline int atomic_add_negative(in
28514 + {
28515 + unsigned char c;
28516 +
28517 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
28518 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
28519 ++
28520 ++#ifdef CONFIG_PAX_REFCOUNT
28521 ++ "jno 0f\n"
28522 ++ LOCK_PREFIX "subl %2,%0\n"
28523 ++ "into\n0:\n"
28524 ++ _ASM_EXTABLE(0b, 0b)
28525 ++#endif
28526 ++
28527 ++ "sets %1\n"
28528 + : "+m" (v->counter), "=qm" (c)
28529 + : "ir" (i) : "memory");
28530 + return c;
28531 +@@ -181,7 +261,15 @@ static inline int atomic_add_return(int
28532 + #endif
28533 + /* Modern 486+ processor */
28534 + __i = i;
28535 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
28536 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
28537 ++
28538 ++#ifdef CONFIG_PAX_REFCOUNT
28539 ++ "jno 0f\n"
28540 ++ "movl %0, %1\n"
28541 ++ "into\n0:\n"
28542 ++ _ASM_EXTABLE(0b, 0b)
28543 ++#endif
28544 ++
28545 + : "+r" (i), "+m" (v->counter)
28546 + : : "memory");
28547 + return i + __i;
28548 +diff -urNp linux-2.6.27.10/include/asm-x86/atomic_64.h linux-2.6.27.10/include/asm-x86/atomic_64.h
28549 +--- linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-07 12:55:34.000000000 -0500
28550 ++++ linux-2.6.27.10/include/asm-x86/atomic_64.h 2008-11-18 03:38:45.000000000 -0500
28551 +@@ -48,7 +48,15 @@ typedef struct {
28552 + */
28553 + static inline void atomic_add(int i, atomic_t *v)
28554 + {
28555 +- asm volatile(LOCK_PREFIX "addl %1,%0"
28556 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
28557 ++
28558 ++#ifdef CONFIG_PAX_REFCOUNT
28559 ++ "jno 0f\n"
28560 ++ LOCK_PREFIX "subl %1,%0\n"
28561 ++ "int $4\n0:\n"
28562 ++ _ASM_EXTABLE(0b, 0b)
28563 ++#endif
28564 ++
28565 + : "=m" (v->counter)
28566 + : "ir" (i), "m" (v->counter));
28567 + }
28568 +@@ -62,7 +70,15 @@ static inline void atomic_add(int i, ato
28569 + */
28570 + static inline void atomic_sub(int i, atomic_t *v)
28571 + {
28572 +- asm volatile(LOCK_PREFIX "subl %1,%0"
28573 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
28574 ++
28575 ++#ifdef CONFIG_PAX_REFCOUNT
28576 ++ "jno 0f\n"
28577 ++ LOCK_PREFIX "addl %1,%0\n"
28578 ++ "int $4\n0:\n"
28579 ++ _ASM_EXTABLE(0b, 0b)
28580 ++#endif
28581 ++
28582 + : "=m" (v->counter)
28583 + : "ir" (i), "m" (v->counter));
28584 + }
28585 +@@ -80,7 +96,16 @@ static inline int atomic_sub_and_test(in
28586 + {
28587 + unsigned char c;
28588 +
28589 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
28590 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
28591 ++
28592 ++#ifdef CONFIG_PAX_REFCOUNT
28593 ++ "jno 0f\n"
28594 ++ LOCK_PREFIX "addl %2,%0\n"
28595 ++ "int $4\n0:\n"
28596 ++ _ASM_EXTABLE(0b, 0b)
28597 ++#endif
28598 ++
28599 ++ "sete %1\n"
28600 + : "=m" (v->counter), "=qm" (c)
28601 + : "ir" (i), "m" (v->counter) : "memory");
28602 + return c;
28603 +@@ -94,7 +119,19 @@ static inline int atomic_sub_and_test(in
28604 + */
28605 + static inline void atomic_inc(atomic_t *v)
28606 + {
28607 +- asm volatile(LOCK_PREFIX "incl %0"
28608 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28609 ++
28610 ++#ifdef CONFIG_PAX_REFCOUNT
28611 ++ "jno 0f\n"
28612 ++ "int $4\n0:\n"
28613 ++ ".pushsection .fixup,\"ax\"\n"
28614 ++ "1:\n"
28615 ++ LOCK_PREFIX "decl %0\n"
28616 ++ "jmp 0b\n"
28617 ++ ".popsection\n"
28618 ++ _ASM_EXTABLE(0b, 1b)
28619 ++#endif
28620 ++
28621 + : "=m" (v->counter)
28622 + : "m" (v->counter));
28623 + }
28624 +@@ -107,7 +144,19 @@ static inline void atomic_inc(atomic_t *
28625 + */
28626 + static inline void atomic_dec(atomic_t *v)
28627 + {
28628 +- asm volatile(LOCK_PREFIX "decl %0"
28629 ++ asm volatile(LOCK_PREFIX "decl %0\n"
28630 ++
28631 ++#ifdef CONFIG_PAX_REFCOUNT
28632 ++ "jno 0f\n"
28633 ++ "int $4\n0:\n"
28634 ++ ".pushsection .fixup,\"ax\"\n"
28635 ++ "1: \n"
28636 ++ LOCK_PREFIX "incl %0\n"
28637 ++ "jmp 0b\n"
28638 ++ ".popsection\n"
28639 ++ _ASM_EXTABLE(0b, 1b)
28640 ++#endif
28641 ++
28642 + : "=m" (v->counter)
28643 + : "m" (v->counter));
28644 + }
28645 +@@ -124,7 +173,20 @@ static inline int atomic_dec_and_test(at
28646 + {
28647 + unsigned char c;
28648 +
28649 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
28650 ++ asm volatile(LOCK_PREFIX "decl %0\n"
28651 ++
28652 ++#ifdef CONFIG_PAX_REFCOUNT
28653 ++ "jno 0f\n"
28654 ++ "int $4\n0:\n"
28655 ++ ".pushsection .fixup,\"ax\"\n"
28656 ++ "1: \n"
28657 ++ LOCK_PREFIX "incl %0\n"
28658 ++ "jmp 0b\n"
28659 ++ ".popsection\n"
28660 ++ _ASM_EXTABLE(0b, 1b)
28661 ++#endif
28662 ++
28663 ++ "sete %1\n"
28664 + : "=m" (v->counter), "=qm" (c)
28665 + : "m" (v->counter) : "memory");
28666 + return c != 0;
28667 +@@ -142,7 +204,20 @@ static inline int atomic_inc_and_test(at
28668 + {
28669 + unsigned char c;
28670 +
28671 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
28672 ++ asm volatile(LOCK_PREFIX "incl %0\n"
28673 ++
28674 ++#ifdef CONFIG_PAX_REFCOUNT
28675 ++ "jno 0f\n"
28676 ++ "int $4\n0:\n"
28677 ++ ".pushsection .fixup,\"ax\"\n"
28678 ++ "1: \n"
28679 ++ LOCK_PREFIX "decl %0\n"
28680 ++ "jmp 0b\n"
28681 ++ ".popsection\n"
28682 ++ _ASM_EXTABLE(0b, 1b)
28683 ++#endif
28684 ++
28685 ++ "sete %1\n"
28686 + : "=m" (v->counter), "=qm" (c)
28687 + : "m" (v->counter) : "memory");
28688 + return c != 0;
28689 +@@ -161,7 +236,16 @@ static inline int atomic_add_negative(in
28690 + {
28691 + unsigned char c;
28692 +
28693 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
28694 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
28695 ++
28696 ++#ifdef CONFIG_PAX_REFCOUNT
28697 ++ "jno 0f\n"
28698 ++ LOCK_PREFIX "subl %2,%0\n"
28699 ++ "int $4\n0:\n"
28700 ++ _ASM_EXTABLE(0b, 0b)
28701 ++#endif
28702 ++
28703 ++ "sets %1\n"
28704 + : "=m" (v->counter), "=qm" (c)
28705 + : "ir" (i), "m" (v->counter) : "memory");
28706 + return c;
28707 +@@ -177,7 +261,15 @@ static inline int atomic_add_negative(in
28708 + static inline int atomic_add_return(int i, atomic_t *v)
28709 + {
28710 + int __i = i;
28711 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
28712 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
28713 ++
28714 ++#ifdef CONFIG_PAX_REFCOUNT
28715 ++ "jno 0f\n"
28716 ++ "movl %0, %1\n"
28717 ++ "int $4\n0:\n"
28718 ++ _ASM_EXTABLE(0b, 0b)
28719 ++#endif
28720 ++
28721 + : "+r" (i), "+m" (v->counter)
28722 + : : "memory");
28723 + return i + __i;
28724 +@@ -226,7 +318,15 @@ typedef struct {
28725 + */
28726 + static inline void atomic64_add(long i, atomic64_t *v)
28727 + {
28728 +- asm volatile(LOCK_PREFIX "addq %1,%0"
28729 ++ asm volatile(LOCK_PREFIX "addq %1,%0\n"
28730 ++
28731 ++#ifdef CONFIG_PAX_REFCOUNT
28732 ++ "jno 0f\n"
28733 ++ LOCK_PREFIX "subq %1,%0\n"
28734 ++ "int $4\n0:\n"
28735 ++ _ASM_EXTABLE(0b, 0b)
28736 ++#endif
28737 ++
28738 + : "=m" (v->counter)
28739 + : "er" (i), "m" (v->counter));
28740 + }
28741 +@@ -240,7 +340,15 @@ static inline void atomic64_add(long i,
28742 + */
28743 + static inline void atomic64_sub(long i, atomic64_t *v)
28744 + {
28745 +- asm volatile(LOCK_PREFIX "subq %1,%0"
28746 ++ asm volatile(LOCK_PREFIX "subq %1,%0\n"
28747 ++
28748 ++#ifdef CONFIG_PAX_REFCOUNT
28749 ++ "jno 0f\n"
28750 ++ LOCK_PREFIX "addq %1,%0\n"
28751 ++ "int $4\n0:\n"
28752 ++ _ASM_EXTABLE(0b, 0b)
28753 ++#endif
28754 ++
28755 + : "=m" (v->counter)
28756 + : "er" (i), "m" (v->counter));
28757 + }
28758 +@@ -258,7 +366,16 @@ static inline int atomic64_sub_and_test(
28759 + {
28760 + unsigned char c;
28761 +
28762 +- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
28763 ++ asm volatile(LOCK_PREFIX "subq %2,%0\n"
28764 ++
28765 ++#ifdef CONFIG_PAX_REFCOUNT
28766 ++ "jno 0f\n"
28767 ++ LOCK_PREFIX "addq %2,%0\n"
28768 ++ "int $4\n0:\n"
28769 ++ _ASM_EXTABLE(0b, 0b)
28770 ++#endif
28771 ++
28772 ++ "sete %1\n"
28773 + : "=m" (v->counter), "=qm" (c)
28774 + : "er" (i), "m" (v->counter) : "memory");
28775 + return c;
28776 +@@ -272,7 +389,19 @@ static inline int atomic64_sub_and_test(
28777 + */
28778 + static inline void atomic64_inc(atomic64_t *v)
28779 + {
28780 +- asm volatile(LOCK_PREFIX "incq %0"
28781 ++ asm volatile(LOCK_PREFIX "incq %0\n"
28782 ++
28783 ++#ifdef CONFIG_PAX_REFCOUNT
28784 ++ "jno 0f\n"
28785 ++ "int $4\n0:\n"
28786 ++ ".pushsection .fixup,\"ax\"\n"
28787 ++ "1:\n"
28788 ++ LOCK_PREFIX "decq %0\n"
28789 ++ "jmp 0b\n"
28790 ++ ".popsection\n"
28791 ++ _ASM_EXTABLE(0b, 1b)
28792 ++#endif
28793 ++
28794 + : "=m" (v->counter)
28795 + : "m" (v->counter));
28796 + }
28797 +@@ -285,7 +414,19 @@ static inline void atomic64_inc(atomic64
28798 + */
28799 + static inline void atomic64_dec(atomic64_t *v)
28800 + {
28801 +- asm volatile(LOCK_PREFIX "decq %0"
28802 ++ asm volatile(LOCK_PREFIX "decq %0\n"
28803 ++
28804 ++#ifdef CONFIG_PAX_REFCOUNT
28805 ++ "jno 0f\n"
28806 ++ "int $4\n0:\n"
28807 ++ ".pushsection .fixup,\"ax\"\n"
28808 ++ "1: \n"
28809 ++ LOCK_PREFIX "incq %0\n"
28810 ++ "jmp 0b\n"
28811 ++ ".popsection\n"
28812 ++ _ASM_EXTABLE(0b, 1b)
28813 ++#endif
28814 ++
28815 + : "=m" (v->counter)
28816 + : "m" (v->counter));
28817 + }
28818 +@@ -302,7 +443,20 @@ static inline int atomic64_dec_and_test(
28819 + {
28820 + unsigned char c;
28821 +
28822 +- asm volatile(LOCK_PREFIX "decq %0; sete %1"
28823 ++ asm volatile(LOCK_PREFIX "decq %0\n"
28824 ++
28825 ++#ifdef CONFIG_PAX_REFCOUNT
28826 ++ "jno 0f\n"
28827 ++ "int $4\n0:\n"
28828 ++ ".pushsection .fixup,\"ax\"\n"
28829 ++ "1: \n"
28830 ++ LOCK_PREFIX "incq %0\n"
28831 ++ "jmp 0b\n"
28832 ++ ".popsection\n"
28833 ++ _ASM_EXTABLE(0b, 1b)
28834 ++#endif
28835 ++
28836 ++ "sete %1\n"
28837 + : "=m" (v->counter), "=qm" (c)
28838 + : "m" (v->counter) : "memory");
28839 + return c != 0;
28840 +@@ -320,7 +474,20 @@ static inline int atomic64_inc_and_test(
28841 + {
28842 + unsigned char c;
28843 +
28844 +- asm volatile(LOCK_PREFIX "incq %0; sete %1"
28845 ++ asm volatile(LOCK_PREFIX "incq %0\n"
28846 ++
28847 ++#ifdef CONFIG_PAX_REFCOUNT
28848 ++ "jno 0f\n"
28849 ++ "int $4\n0:\n"
28850 ++ ".pushsection .fixup,\"ax\"\n"
28851 ++ "1: \n"
28852 ++ LOCK_PREFIX "decq %0\n"
28853 ++ "jmp 0b\n"
28854 ++ ".popsection\n"
28855 ++ _ASM_EXTABLE(0b, 1b)
28856 ++#endif
28857 ++
28858 ++ "sete %1\n"
28859 + : "=m" (v->counter), "=qm" (c)
28860 + : "m" (v->counter) : "memory");
28861 + return c != 0;
28862 +@@ -339,7 +506,16 @@ static inline int atomic64_add_negative(
28863 + {
28864 + unsigned char c;
28865 +
28866 +- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
28867 ++ asm volatile(LOCK_PREFIX "addq %2,%0\n"
28868 ++
28869 ++#ifdef CONFIG_PAX_REFCOUNT
28870 ++ "jno 0f\n"
28871 ++ LOCK_PREFIX "subq %2,%0\n"
28872 ++ "int $4\n0:\n"
28873 ++ _ASM_EXTABLE(0b, 0b)
28874 ++#endif
28875 ++
28876 ++ "sets %1\n"
28877 + : "=m" (v->counter), "=qm" (c)
28878 + : "er" (i), "m" (v->counter) : "memory");
28879 + return c;
28880 +@@ -355,7 +531,15 @@ static inline int atomic64_add_negative(
28881 + static inline long atomic64_add_return(long i, atomic64_t *v)
28882 + {
28883 + long __i = i;
28884 +- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
28885 ++ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
28886 ++
28887 ++#ifdef CONFIG_PAX_REFCOUNT
28888 ++ "jno 0f\n"
28889 ++ "movq %0, %1\n"
28890 ++ "int $4\n0:\n"
28891 ++ _ASM_EXTABLE(0b, 0b)
28892 ++#endif
28893 ++
28894 + : "+r" (i), "+m" (v->counter)
28895 + : : "memory");
28896 + return i + __i;
28897 +diff -urNp linux-2.6.27.10/include/asm-x86/boot.h linux-2.6.27.10/include/asm-x86/boot.h
28898 +--- linux-2.6.27.10/include/asm-x86/boot.h 2008-11-07 12:55:34.000000000 -0500
28899 ++++ linux-2.6.27.10/include/asm-x86/boot.h 2008-11-18 03:38:45.000000000 -0500
28900 +@@ -13,10 +13,15 @@
28901 + #define ASK_VGA 0xfffd /* ask for it at bootup */
28902 +
28903 + /* Physical address where kernel should be loaded. */
28904 +-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
28905 ++#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
28906 + + (CONFIG_PHYSICAL_ALIGN - 1)) \
28907 + & ~(CONFIG_PHYSICAL_ALIGN - 1))
28908 +
28909 ++#ifndef __ASSEMBLY__
28910 ++extern unsigned char __LOAD_PHYSICAL_ADDR[];
28911 ++#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
28912 ++#endif
28913 ++
28914 + #ifdef CONFIG_X86_64
28915 + #define BOOT_HEAP_SIZE 0x7000
28916 + #define BOOT_STACK_SIZE 0x4000
28917 +diff -urNp linux-2.6.27.10/include/asm-x86/cache.h linux-2.6.27.10/include/asm-x86/cache.h
28918 +--- linux-2.6.27.10/include/asm-x86/cache.h 2008-11-07 12:55:34.000000000 -0500
28919 ++++ linux-2.6.27.10/include/asm-x86/cache.h 2008-11-18 03:38:45.000000000 -0500
28920 +@@ -6,6 +6,7 @@
28921 + #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
28922 +
28923 + #define __read_mostly __attribute__((__section__(".data.read_mostly")))
28924 ++#define __read_only __attribute__((__section__(".data.read_only")))
28925 +
28926 + #ifdef CONFIG_X86_VSMP
28927 + /* vSMP Internode cacheline shift */
28928 +diff -urNp linux-2.6.27.10/include/asm-x86/checksum_32.h linux-2.6.27.10/include/asm-x86/checksum_32.h
28929 +--- linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-07 12:55:34.000000000 -0500
28930 ++++ linux-2.6.27.10/include/asm-x86/checksum_32.h 2008-11-18 03:38:45.000000000 -0500
28931 +@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
28932 + int len, __wsum sum,
28933 + int *src_err_ptr, int *dst_err_ptr);
28934 +
28935 ++asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
28936 ++ int len, __wsum sum,
28937 ++ int *src_err_ptr, int *dst_err_ptr);
28938 ++
28939 ++asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
28940 ++ int len, __wsum sum,
28941 ++ int *src_err_ptr, int *dst_err_ptr);
28942 ++
28943 + /*
28944 + * Note: when you get a NULL pointer exception here this means someone
28945 + * passed in an incorrect kernel address to one of these functions.
28946 +@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
28947 + int *err_ptr)
28948 + {
28949 + might_sleep();
28950 +- return csum_partial_copy_generic((__force void *)src, dst,
28951 ++ return csum_partial_copy_generic_from_user((__force void *)src, dst,
28952 + len, sum, err_ptr, NULL);
28953 + }
28954 +
28955 +@@ -177,7 +185,7 @@ static inline __wsum csum_and_copy_to_us
28956 + {
28957 + might_sleep();
28958 + if (access_ok(VERIFY_WRITE, dst, len))
28959 +- return csum_partial_copy_generic(src, (__force void *)dst,
28960 ++ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
28961 + len, sum, NULL, err_ptr);
28962 +
28963 + if (len)
28964 +diff -urNp linux-2.6.27.10/include/asm-x86/desc.h linux-2.6.27.10/include/asm-x86/desc.h
28965 +--- linux-2.6.27.10/include/asm-x86/desc.h 2008-11-07 12:55:34.000000000 -0500
28966 ++++ linux-2.6.27.10/include/asm-x86/desc.h 2008-11-18 03:38:45.000000000 -0500
28967 +@@ -16,6 +16,7 @@ static inline void fill_ldt(struct desc_
28968 + desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
28969 + desc->type = (info->read_exec_only ^ 1) << 1;
28970 + desc->type |= info->contents << 2;
28971 ++ desc->type |= info->seg_not_present ^ 1;
28972 + desc->s = 1;
28973 + desc->dpl = 0x3;
28974 + desc->p = info->seg_not_present ^ 1;
28975 +@@ -27,16 +28,12 @@ static inline void fill_ldt(struct desc_
28976 + }
28977 +
28978 + extern struct desc_ptr idt_descr;
28979 +-extern gate_desc idt_table[];
28980 +-
28981 +-struct gdt_page {
28982 +- struct desc_struct gdt[GDT_ENTRIES];
28983 +-} __attribute__((aligned(PAGE_SIZE)));
28984 +-DECLARE_PER_CPU(struct gdt_page, gdt_page);
28985 ++extern gate_desc idt_table[256];
28986 +
28987 ++extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
28988 + static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
28989 + {
28990 +- return per_cpu(gdt_page, cpu).gdt;
28991 ++ return cpu_gdt_table[cpu];
28992 + }
28993 +
28994 + #ifdef CONFIG_X86_64
28995 +@@ -65,7 +62,6 @@ static inline void pack_gate(gate_desc *
28996 + gate->b = (base & 0xffff0000) |
28997 + (((0x80 | type | (dpl << 5)) & 0xff) << 8);
28998 + }
28999 +-
29000 + #endif
29001 +
29002 + static inline int desc_empty(const void *ptr)
29003 +@@ -102,19 +98,48 @@ static inline int desc_empty(const void
29004 + static inline void native_write_idt_entry(gate_desc *idt, int entry,
29005 + const gate_desc *gate)
29006 + {
29007 ++
29008 ++#ifdef CONFIG_PAX_KERNEXEC
29009 ++ unsigned long cr0;
29010 ++
29011 ++ pax_open_kernel(cr0);
29012 ++#endif
29013 ++
29014 + memcpy(&idt[entry], gate, sizeof(*gate));
29015 ++
29016 ++#ifdef CONFIG_PAX_KERNEXEC
29017 ++ pax_close_kernel(cr0);
29018 ++#endif
29019 ++
29020 + }
29021 +
29022 + static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
29023 + const void *desc)
29024 + {
29025 ++
29026 ++#ifdef CONFIG_PAX_KERNEXEC
29027 ++ unsigned long cr0;
29028 ++
29029 ++ pax_open_kernel(cr0);
29030 ++#endif
29031 ++
29032 + memcpy(&ldt[entry], desc, 8);
29033 ++
29034 ++#ifdef CONFIG_PAX_KERNEXEC
29035 ++ pax_close_kernel(cr0);
29036 ++#endif
29037 ++
29038 + }
29039 +
29040 + static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
29041 + const void *desc, int type)
29042 + {
29043 + unsigned int size;
29044 ++
29045 ++#ifdef CONFIG_PAX_KERNEXEC
29046 ++ unsigned long cr0;
29047 ++#endif
29048 ++
29049 + switch (type) {
29050 + case DESC_TSS:
29051 + size = sizeof(tss_desc);
29052 +@@ -126,7 +151,17 @@ static inline void native_write_gdt_entr
29053 + size = sizeof(struct desc_struct);
29054 + break;
29055 + }
29056 ++
29057 ++#ifdef CONFIG_PAX_KERNEXEC
29058 ++ pax_open_kernel(cr0);
29059 ++#endif
29060 ++
29061 + memcpy(&gdt[entry], desc, size);
29062 ++
29063 ++#ifdef CONFIG_PAX_KERNEXEC
29064 ++ pax_close_kernel(cr0);
29065 ++#endif
29066 ++
29067 + }
29068 +
29069 + static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
29070 +@@ -198,7 +233,19 @@ static inline void native_set_ldt(const
29071 +
29072 + static inline void native_load_tr_desc(void)
29073 + {
29074 ++
29075 ++#ifdef CONFIG_PAX_KERNEXEC
29076 ++ unsigned long cr0;
29077 ++
29078 ++ pax_open_kernel(cr0);
29079 ++#endif
29080 ++
29081 + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
29082 ++
29083 ++#ifdef CONFIG_PAX_KERNEXEC
29084 ++ pax_close_kernel(cr0);
29085 ++#endif
29086 ++
29087 + }
29088 +
29089 + static inline void native_load_gdt(const struct desc_ptr *dtr)
29090 +@@ -233,8 +280,19 @@ static inline void native_load_tls(struc
29091 + unsigned int i;
29092 + struct desc_struct *gdt = get_cpu_gdt_table(cpu);
29093 +
29094 ++#ifdef CONFIG_PAX_KERNEXEC
29095 ++ unsigned long cr0;
29096 ++
29097 ++ pax_open_kernel(cr0);
29098 ++#endif
29099 ++
29100 + for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
29101 + gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
29102 ++
29103 ++#ifdef CONFIG_PAX_KERNEXEC
29104 ++ pax_close_kernel(cr0);
29105 ++#endif
29106 ++
29107 + }
29108 +
29109 + #define _LDT_empty(info) \
29110 +@@ -372,6 +430,18 @@ static inline void set_system_gate_ist(i
29111 + _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
29112 + }
29113 +
29114 ++#ifdef CONFIG_X86_32
29115 ++static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
29116 ++{
29117 ++ struct desc_struct d;
29118 ++
29119 ++ if (likely(limit))
29120 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
29121 ++ pack_descriptor(&d, base, limit, 0xFB, 0xC);
29122 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
29123 ++}
29124 ++#endif
29125 ++
29126 + #else
29127 + /*
29128 + * GET_DESC_BASE reads the descriptor base of the specified segment.
29129 +diff -urNp linux-2.6.27.10/include/asm-x86/e820.h linux-2.6.27.10/include/asm-x86/e820.h
29130 +--- linux-2.6.27.10/include/asm-x86/e820.h 2008-11-07 12:55:34.000000000 -0500
29131 ++++ linux-2.6.27.10/include/asm-x86/e820.h 2008-11-18 03:38:45.000000000 -0500
29132 +@@ -131,7 +131,7 @@ extern char *memory_setup(void);
29133 + #define ISA_END_ADDRESS 0x100000
29134 + #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
29135 +
29136 +-#define BIOS_BEGIN 0x000a0000
29137 ++#define BIOS_BEGIN 0x000c0000
29138 + #define BIOS_END 0x00100000
29139 +
29140 + #ifdef __KERNEL__
29141 +diff -urNp linux-2.6.27.10/include/asm-x86/elf.h linux-2.6.27.10/include/asm-x86/elf.h
29142 +--- linux-2.6.27.10/include/asm-x86/elf.h 2008-11-07 12:55:34.000000000 -0500
29143 ++++ linux-2.6.27.10/include/asm-x86/elf.h 2008-11-18 03:38:45.000000000 -0500
29144 +@@ -251,7 +251,25 @@ extern int force_personality32;
29145 + the loader. We need to make sure that it is out of the way of the program
29146 + that it will "exec", and that there is sufficient room for the brk. */
29147 +
29148 ++#ifdef CONFIG_PAX_SEGMEXEC
29149 ++#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
29150 ++#else
29151 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
29152 ++#endif
29153 ++
29154 ++#ifdef CONFIG_PAX_ASLR
29155 ++#ifdef CONFIG_X86_32
29156 ++#define PAX_ELF_ET_DYN_BASE 0x10000000UL
29157 ++
29158 ++#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
29159 ++#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
29160 ++#else
29161 ++#define PAX_ELF_ET_DYN_BASE 0x400000UL
29162 ++
29163 ++#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
29164 ++#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
29165 ++#endif
29166 ++#endif
29167 +
29168 + /* This yields a mask that user programs can use to figure out what
29169 + instruction set this CPU supports. This could be done in user space,
29170 +@@ -303,8 +321,7 @@ do { \
29171 + #define ARCH_DLINFO \
29172 + do { \
29173 + if (vdso_enabled) \
29174 +- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
29175 +- (unsigned long)current->mm->context.vdso); \
29176 ++ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
29177 + } while (0)
29178 +
29179 + #define AT_SYSINFO 32
29180 +@@ -315,7 +332,7 @@ do { \
29181 +
29182 + #endif /* !CONFIG_X86_32 */
29183 +
29184 +-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
29185 ++#define VDSO_CURRENT_BASE (current->mm->context.vdso)
29186 +
29187 + #define VDSO_ENTRY \
29188 + ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
29189 +@@ -329,7 +346,4 @@ extern int arch_setup_additional_pages(s
29190 + extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
29191 + #define compat_arch_setup_additional_pages syscall32_setup_pages
29192 +
29193 +-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
29194 +-#define arch_randomize_brk arch_randomize_brk
29195 +-
29196 + #endif
29197 +diff -urNp linux-2.6.27.10/include/asm-x86/futex.h linux-2.6.27.10/include/asm-x86/futex.h
29198 +--- linux-2.6.27.10/include/asm-x86/futex.h 2008-11-07 12:55:34.000000000 -0500
29199 ++++ linux-2.6.27.10/include/asm-x86/futex.h 2008-11-18 03:38:45.000000000 -0500
29200 +@@ -11,6 +11,40 @@
29201 + #include <asm/processor.h>
29202 + #include <asm/system.h>
29203 +
29204 ++#ifdef CONFIG_X86_32
29205 ++#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
29206 ++ asm volatile( \
29207 ++ "movw\t%w6, %%ds\n" \
29208 ++ "1:\t" insn "\n" \
29209 ++ "2:\tpushl\t%%ss\n" \
29210 ++ "\tpopl\t%%ds\n" \
29211 ++ "\t.section .fixup,\"ax\"\n" \
29212 ++ "3:\tmov\t%3, %1\n" \
29213 ++ "\tjmp\t2b\n" \
29214 ++ "\t.previous\n" \
29215 ++ _ASM_EXTABLE(1b, 3b) \
29216 ++ : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
29217 ++ : "i" (-EFAULT), "0" (oparg), "1" (0), "r" (__USER_DS))
29218 ++
29219 ++#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
29220 ++ asm volatile("movw\t%w7, %%es\n" \
29221 ++ "1:\tmovl\t%%es:%2, %0\n" \
29222 ++ "\tmovl\t%0, %3\n" \
29223 ++ "\t" insn "\n" \
29224 ++ "2:\tlock; cmpxchgl %3, %%es:%2\n" \
29225 ++ "\tjnz\t1b\n" \
29226 ++ "3:\tpushl\t%%ss\n" \
29227 ++ "\tpopl\t%%es\n" \
29228 ++ "\t.section .fixup,\"ax\"\n" \
29229 ++ "4:\tmov\t%5, %1\n" \
29230 ++ "\tjmp\t3b\n" \
29231 ++ "\t.previous\n" \
29232 ++ _ASM_EXTABLE(1b, 4b) \
29233 ++ _ASM_EXTABLE(2b, 4b) \
29234 ++ : "=&a" (oldval), "=&r" (ret), \
29235 ++ "+m" (*uaddr), "=&r" (tem) \
29236 ++ : "r" (oparg), "i" (-EFAULT), "1" (0), "r" (__USER_DS))
29237 ++#else
29238 + #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
29239 + asm volatile("1:\t" insn "\n" \
29240 + "2:\t.section .fixup,\"ax\"\n" \
29241 +@@ -36,8 +70,9 @@
29242 + : "=&a" (oldval), "=&r" (ret), \
29243 + "+m" (*uaddr), "=&r" (tem) \
29244 + : "r" (oparg), "i" (-EFAULT), "1" (0))
29245 ++#endif
29246 +
29247 +-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
29248 ++static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
29249 + {
29250 + int op = (encoded_op >> 28) & 7;
29251 + int cmp = (encoded_op >> 24) & 15;
29252 +@@ -61,11 +96,20 @@ static inline int futex_atomic_op_inuser
29253 +
29254 + switch (op) {
29255 + case FUTEX_OP_SET:
29256 ++#ifdef CONFIG_X86_32
29257 ++ __futex_atomic_op1("xchgl %0, %%ds:%2", ret, oldval, uaddr, oparg);
29258 ++#else
29259 + __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
29260 ++#endif
29261 + break;
29262 + case FUTEX_OP_ADD:
29263 ++#ifdef CONFIG_X86_32
29264 ++ __futex_atomic_op1("lock ; xaddl %0, %%ds:%2", ret, oldval,
29265 ++ uaddr, oparg);
29266 ++#else
29267 + __futex_atomic_op1("lock; xaddl %0, %2", ret, oldval,
29268 + uaddr, oparg);
29269 ++#endif
29270 + break;
29271 + case FUTEX_OP_OR:
29272 + __futex_atomic_op2("orl %4, %3", ret, oldval, uaddr, oparg);
29273 +@@ -109,7 +153,7 @@ static inline int futex_atomic_op_inuser
29274 + return ret;
29275 + }
29276 +
29277 +-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
29278 ++static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
29279 + int newval)
29280 + {
29281 +
29282 +@@ -122,14 +166,27 @@ static inline int futex_atomic_cmpxchg_i
29283 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
29284 + return -EFAULT;
29285 +
29286 +- asm volatile("1:\tlock; cmpxchgl %3, %1\n"
29287 ++ asm volatile(
29288 ++#ifdef CONFIG_X86_32
29289 ++ "\tmovw %w5, %%ds\n"
29290 ++ "1:\tlock; cmpxchgl %3, %1\n"
29291 ++ "2:\tpushl %%ss\n"
29292 ++ "\tpopl %%ds\n"
29293 ++ "\t.section .fixup, \"ax\"\n"
29294 ++#else
29295 ++ "1:\tlock; cmpxchgl %3, %1\n"
29296 + "2:\t.section .fixup, \"ax\"\n"
29297 ++#endif
29298 + "3:\tmov %2, %0\n"
29299 + "\tjmp 2b\n"
29300 + "\t.previous\n"
29301 + _ASM_EXTABLE(1b, 3b)
29302 + : "=a" (oldval), "+m" (*uaddr)
29303 ++#ifdef CONFIG_X86_32
29304 ++ : "i" (-EFAULT), "r" (newval), "0" (oldval), "r" (__USER_DS)
29305 ++#else
29306 + : "i" (-EFAULT), "r" (newval), "0" (oldval)
29307 ++#endif
29308 + : "memory"
29309 + );
29310 +
29311 +diff -urNp linux-2.6.27.10/include/asm-x86/i387.h linux-2.6.27.10/include/asm-x86/i387.h
29312 +--- linux-2.6.27.10/include/asm-x86/i387.h 2008-11-07 12:55:34.000000000 -0500
29313 ++++ linux-2.6.27.10/include/asm-x86/i387.h 2008-11-18 03:38:45.000000000 -0500
29314 +@@ -159,13 +159,8 @@ static inline void restore_fpu(struct ta
29315 + }
29316 +
29317 + /* We need a safe address that is cheap to find and that is already
29318 +- in L1 during context switch. The best choices are unfortunately
29319 +- different for UP and SMP */
29320 +-#ifdef CONFIG_SMP
29321 +-#define safe_address (__per_cpu_offset[0])
29322 +-#else
29323 +-#define safe_address (kstat_cpu(0).cpustat.user)
29324 +-#endif
29325 ++ in L1 during context switch. */
29326 ++#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
29327 +
29328 + /*
29329 + * These must be called with preempt disabled
29330 +diff -urNp linux-2.6.27.10/include/asm-x86/io_64.h linux-2.6.27.10/include/asm-x86/io_64.h
29331 +--- linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-07 12:55:34.000000000 -0500
29332 ++++ linux-2.6.27.10/include/asm-x86/io_64.h 2008-11-18 03:38:45.000000000 -0500
29333 +@@ -158,6 +158,17 @@ static inline void *phys_to_virt(unsigne
29334 + }
29335 + #endif
29336 +
29337 ++#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
29338 ++static inline int valid_phys_addr_range (unsigned long addr, size_t count)
29339 ++{
29340 ++ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
29341 ++}
29342 ++
29343 ++static inline int valid_mmap_phys_addr_range (unsigned long pfn, size_t count)
29344 ++{
29345 ++ return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
29346 ++}
29347 ++
29348 + /*
29349 + * Change "struct page" to physical address.
29350 + */
29351 +diff -urNp linux-2.6.27.10/include/asm-x86/irqflags.h linux-2.6.27.10/include/asm-x86/irqflags.h
29352 +--- linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-07 12:55:34.000000000 -0500
29353 ++++ linux-2.6.27.10/include/asm-x86/irqflags.h 2008-11-18 03:38:45.000000000 -0500
29354 +@@ -141,6 +141,8 @@ static inline unsigned long __raw_local_
29355 + #define INTERRUPT_RETURN iret
29356 + #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
29357 + #define GET_CR0_INTO_EAX movl %cr0, %eax
29358 ++#define GET_CR0_INTO_EDX movl %cr0, %edx
29359 ++#define SET_CR0_FROM_EDX movl %edx, %cr0
29360 + #endif
29361 +
29362 +
29363 +diff -urNp linux-2.6.27.10/include/asm-x86/kmap_types.h linux-2.6.27.10/include/asm-x86/kmap_types.h
29364 +--- linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
29365 ++++ linux-2.6.27.10/include/asm-x86/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
29366 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
29367 + D(10) KM_IRQ1,
29368 + D(11) KM_SOFTIRQ0,
29369 + D(12) KM_SOFTIRQ1,
29370 +-D(13) KM_TYPE_NR
29371 ++D(13) KM_CLEARPAGE,
29372 ++D(14) KM_TYPE_NR
29373 + };
29374 +
29375 + #undef D
29376 +diff -urNp linux-2.6.27.10/include/asm-x86/linkage.h linux-2.6.27.10/include/asm-x86/linkage.h
29377 +--- linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-07 12:55:34.000000000 -0500
29378 ++++ linux-2.6.27.10/include/asm-x86/linkage.h 2008-11-18 03:38:45.000000000 -0500
29379 +@@ -7,6 +7,11 @@
29380 + #ifdef CONFIG_X86_64
29381 + #define __ALIGN .p2align 4,,15
29382 + #define __ALIGN_STR ".p2align 4,,15"
29383 ++#else
29384 ++#ifdef CONFIG_X86_ALIGNMENT_16
29385 ++#define __ALIGN .align 16,0x90
29386 ++#define __ALIGN_STR ".align 16,0x90"
29387 ++#endif
29388 + #endif
29389 +
29390 + #ifdef CONFIG_X86_32
29391 +@@ -52,10 +57,5 @@
29392 +
29393 + #endif
29394 +
29395 +-#ifdef CONFIG_X86_ALIGNMENT_16
29396 +-#define __ALIGN .align 16,0x90
29397 +-#define __ALIGN_STR ".align 16,0x90"
29398 +-#endif
29399 +-
29400 + #endif
29401 +
29402 +diff -urNp linux-2.6.27.10/include/asm-x86/local.h linux-2.6.27.10/include/asm-x86/local.h
29403 +--- linux-2.6.27.10/include/asm-x86/local.h 2008-11-07 12:55:34.000000000 -0500
29404 ++++ linux-2.6.27.10/include/asm-x86/local.h 2008-11-18 03:38:45.000000000 -0500
29405 +@@ -18,26 +18,90 @@ typedef struct {
29406 +
29407 + static inline void local_inc(local_t *l)
29408 + {
29409 +- asm volatile(_ASM_INC "%0"
29410 ++ asm volatile(_ASM_INC "%0\n"
29411 ++
29412 ++#ifdef CONFIG_PAX_REFCOUNT
29413 ++#ifdef CONFIG_X86_32
29414 ++ "into\n0:\n"
29415 ++#else
29416 ++ "jno 0f\n"
29417 ++ "int $4\n0:\n"
29418 ++#endif
29419 ++ ".pushsection .fixup,\"ax\"\n"
29420 ++ "1:\n"
29421 ++ _ASM_DEC "%0\n"
29422 ++ "jmp 0b\n"
29423 ++ ".popsection\n"
29424 ++ _ASM_EXTABLE(0b, 1b)
29425 ++#endif
29426 ++
29427 + : "+m" (l->a.counter));
29428 + }
29429 +
29430 + static inline void local_dec(local_t *l)
29431 + {
29432 +- asm volatile(_ASM_DEC "%0"
29433 ++ asm volatile(_ASM_DEC "%0\n"
29434 ++
29435 ++#ifdef CONFIG_PAX_REFCOUNT
29436 ++#ifdef CONFIG_X86_32
29437 ++ "into\n0:\n"
29438 ++#else
29439 ++ "jno 0f\n"
29440 ++ "int $4\n0:\n"
29441 ++#endif
29442 ++ ".pushsection .fixup,\"ax\"\n"
29443 ++ "1:\n"
29444 ++ _ASM_INC "%0\n"
29445 ++ "jmp 0b\n"
29446 ++ ".popsection\n"
29447 ++ _ASM_EXTABLE(0b, 1b)
29448 ++#endif
29449 ++
29450 + : "+m" (l->a.counter));
29451 + }
29452 +
29453 + static inline void local_add(long i, local_t *l)
29454 + {
29455 +- asm volatile(_ASM_ADD "%1,%0"
29456 ++ asm volatile(_ASM_ADD "%1,%0\n"
29457 ++
29458 ++#ifdef CONFIG_PAX_REFCOUNT
29459 ++#ifdef CONFIG_X86_32
29460 ++ "into\n0:\n"
29461 ++#else
29462 ++ "jno 0f\n"
29463 ++ "int $4\n0:\n"
29464 ++#endif
29465 ++ ".pushsection .fixup,\"ax\"\n"
29466 ++ "1:\n"
29467 ++ _ASM_SUB "%1,%0\n"
29468 ++ "jmp 0b\n"
29469 ++ ".popsection\n"
29470 ++ _ASM_EXTABLE(0b, 1b)
29471 ++#endif
29472 ++
29473 + : "+m" (l->a.counter)
29474 + : "ir" (i));
29475 + }
29476 +
29477 + static inline void local_sub(long i, local_t *l)
29478 + {
29479 +- asm volatile(_ASM_SUB "%1,%0"
29480 ++ asm volatile(_ASM_SUB "%1,%0\n"
29481 ++
29482 ++#ifdef CONFIG_PAX_REFCOUNT
29483 ++#ifdef CONFIG_X86_32
29484 ++ "into\n0:\n"
29485 ++#else
29486 ++ "jno 0f\n"
29487 ++ "int $4\n0:\n"
29488 ++#endif
29489 ++ ".pushsection .fixup,\"ax\"\n"
29490 ++ "1:\n"
29491 ++ _ASM_ADD "%1,%0\n"
29492 ++ "jmp 0b\n"
29493 ++ ".popsection\n"
29494 ++ _ASM_EXTABLE(0b, 1b)
29495 ++#endif
29496 ++
29497 + : "+m" (l->a.counter)
29498 + : "ir" (i));
29499 + }
29500 +@@ -55,7 +119,24 @@ static inline int local_sub_and_test(lon
29501 + {
29502 + unsigned char c;
29503 +
29504 +- asm volatile(_ASM_SUB "%2,%0; sete %1"
29505 ++ asm volatile(_ASM_SUB "%2,%0\n"
29506 ++
29507 ++#ifdef CONFIG_PAX_REFCOUNT
29508 ++#ifdef CONFIG_X86_32
29509 ++ "into\n0:\n"
29510 ++#else
29511 ++ "jno 0f\n"
29512 ++ "int $4\n0:\n"
29513 ++#endif
29514 ++ ".pushsection .fixup,\"ax\"\n"
29515 ++ "1:\n"
29516 ++ _ASM_ADD "%2,%0\n"
29517 ++ "jmp 0b\n"
29518 ++ ".popsection\n"
29519 ++ _ASM_EXTABLE(0b, 1b)
29520 ++#endif
29521 ++
29522 ++ "sete %1\n"
29523 + : "+m" (l->a.counter), "=qm" (c)
29524 + : "ir" (i) : "memory");
29525 + return c;
29526 +@@ -73,7 +154,24 @@ static inline int local_dec_and_test(loc
29527 + {
29528 + unsigned char c;
29529 +
29530 +- asm volatile(_ASM_DEC "%0; sete %1"
29531 ++ asm volatile(_ASM_DEC "%0\n"
29532 ++
29533 ++#ifdef CONFIG_PAX_REFCOUNT
29534 ++#ifdef CONFIG_X86_32
29535 ++ "into\n0:\n"
29536 ++#else
29537 ++ "jno 0f\n"
29538 ++ "int $4\n0:\n"
29539 ++#endif
29540 ++ ".pushsection .fixup,\"ax\"\n"
29541 ++ "1:\n"
29542 ++ _ASM_INC "%0\n"
29543 ++ "jmp 0b\n"
29544 ++ ".popsection\n"
29545 ++ _ASM_EXTABLE(0b, 1b)
29546 ++#endif
29547 ++
29548 ++ "sete %1\n"
29549 + : "+m" (l->a.counter), "=qm" (c)
29550 + : : "memory");
29551 + return c != 0;
29552 +@@ -91,7 +189,24 @@ static inline int local_inc_and_test(loc
29553 + {
29554 + unsigned char c;
29555 +
29556 +- asm volatile(_ASM_INC "%0; sete %1"
29557 ++ asm volatile(_ASM_INC "%0\n"
29558 ++
29559 ++#ifdef CONFIG_PAX_REFCOUNT
29560 ++#ifdef CONFIG_X86_32
29561 ++ "into\n0:\n"
29562 ++#else
29563 ++ "jno 0f\n"
29564 ++ "int $4\n0:\n"
29565 ++#endif
29566 ++ ".pushsection .fixup,\"ax\"\n"
29567 ++ "1:\n"
29568 ++ _ASM_DEC "%0\n"
29569 ++ "jmp 0b\n"
29570 ++ ".popsection\n"
29571 ++ _ASM_EXTABLE(0b, 1b)
29572 ++#endif
29573 ++
29574 ++ "sete %1\n"
29575 + : "+m" (l->a.counter), "=qm" (c)
29576 + : : "memory");
29577 + return c != 0;
29578 +@@ -110,7 +225,24 @@ static inline int local_add_negative(lon
29579 + {
29580 + unsigned char c;
29581 +
29582 +- asm volatile(_ASM_ADD "%2,%0; sets %1"
29583 ++ asm volatile(_ASM_ADD "%2,%0\n"
29584 ++
29585 ++#ifdef CONFIG_PAX_REFCOUNT
29586 ++#ifdef CONFIG_X86_32
29587 ++ "into\n0:\n"
29588 ++#else
29589 ++ "jno 0f\n"
29590 ++ "int $4\n0:\n"
29591 ++#endif
29592 ++ ".pushsection .fixup,\"ax\"\n"
29593 ++ "1:\n"
29594 ++ _ASM_SUB "%2,%0\n"
29595 ++ "jmp 0b\n"
29596 ++ ".popsection\n"
29597 ++ _ASM_EXTABLE(0b, 1b)
29598 ++#endif
29599 ++
29600 ++ "sets %1\n"
29601 + : "+m" (l->a.counter), "=qm" (c)
29602 + : "ir" (i) : "memory");
29603 + return c;
29604 +@@ -133,7 +265,23 @@ static inline long local_add_return(long
29605 + #endif
29606 + /* Modern 486+ processor */
29607 + __i = i;
29608 +- asm volatile(_ASM_XADD "%0, %1;"
29609 ++ asm volatile(_ASM_XADD "%0, %1\n"
29610 ++
29611 ++#ifdef CONFIG_PAX_REFCOUNT
29612 ++#ifdef CONFIG_X86_32
29613 ++ "into\n0:\n"
29614 ++#else
29615 ++ "jno 0f\n"
29616 ++ "int $4\n0:\n"
29617 ++#endif
29618 ++ ".pushsection .fixup,\"ax\"\n"
29619 ++ "1:\n"
29620 ++ _ASM_MOV_UL "%0,%1\n"
29621 ++ "jmp 0b\n"
29622 ++ ".popsection\n"
29623 ++ _ASM_EXTABLE(0b, 1b)
29624 ++#endif
29625 ++
29626 + : "+r" (i), "+m" (l->a.counter)
29627 + : : "memory");
29628 + return i + __i;
29629 +diff -urNp linux-2.6.27.10/include/asm-x86/mach-default/apm.h linux-2.6.27.10/include/asm-x86/mach-default/apm.h
29630 +--- linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-07 12:55:34.000000000 -0500
29631 ++++ linux-2.6.27.10/include/asm-x86/mach-default/apm.h 2008-11-18 03:38:45.000000000 -0500
29632 +@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
29633 + __asm__ __volatile__(APM_DO_ZERO_SEGS
29634 + "pushl %%edi\n\t"
29635 + "pushl %%ebp\n\t"
29636 +- "lcall *%%cs:apm_bios_entry\n\t"
29637 ++ "lcall *%%ss:apm_bios_entry\n\t"
29638 + "setc %%al\n\t"
29639 + "popl %%ebp\n\t"
29640 + "popl %%edi\n\t"
29641 +@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
29642 + __asm__ __volatile__(APM_DO_ZERO_SEGS
29643 + "pushl %%edi\n\t"
29644 + "pushl %%ebp\n\t"
29645 +- "lcall *%%cs:apm_bios_entry\n\t"
29646 ++ "lcall *%%ss:apm_bios_entry\n\t"
29647 + "setc %%bl\n\t"
29648 + "popl %%ebp\n\t"
29649 + "popl %%edi\n\t"
29650 +diff -urNp linux-2.6.27.10/include/asm-x86/mman.h linux-2.6.27.10/include/asm-x86/mman.h
29651 +--- linux-2.6.27.10/include/asm-x86/mman.h 2008-11-07 12:55:34.000000000 -0500
29652 ++++ linux-2.6.27.10/include/asm-x86/mman.h 2008-11-18 03:38:45.000000000 -0500
29653 +@@ -17,4 +17,14 @@
29654 + #define MCL_CURRENT 1 /* lock all current mappings */
29655 + #define MCL_FUTURE 2 /* lock all future mappings */
29656 +
29657 ++#ifdef __KERNEL__
29658 ++#ifndef __ASSEMBLY__
29659 ++#ifdef CONFIG_X86_32
29660 ++#define arch_mmap_check i386_mmap_check
29661 ++int i386_mmap_check(unsigned long addr, unsigned long len,
29662 ++ unsigned long flags);
29663 ++#endif
29664 ++#endif
29665 ++#endif
29666 ++
29667 + #endif /* _ASM_X86_MMAN_H */
29668 +diff -urNp linux-2.6.27.10/include/asm-x86/mmu_context_32.h linux-2.6.27.10/include/asm-x86/mmu_context_32.h
29669 +--- linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-07 12:55:34.000000000 -0500
29670 ++++ linux-2.6.27.10/include/asm-x86/mmu_context_32.h 2008-11-18 03:38:45.000000000 -0500
29671 +@@ -33,6 +33,22 @@ static inline void switch_mm(struct mm_s
29672 + */
29673 + if (unlikely(prev->context.ldt != next->context.ldt))
29674 + load_LDT_nolock(&next->context);
29675 ++
29676 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
29677 ++ if (!nx_enabled) {
29678 ++ smp_mb__before_clear_bit();
29679 ++ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
29680 ++ smp_mb__after_clear_bit();
29681 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
29682 ++ }
29683 ++#endif
29684 ++
29685 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29686 ++ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
29687 ++ prev->context.user_cs_limit != next->context.user_cs_limit))
29688 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
29689 ++#endif
29690 ++
29691 + }
29692 + #ifdef CONFIG_SMP
29693 + else {
29694 +@@ -45,6 +61,19 @@ static inline void switch_mm(struct mm_s
29695 + */
29696 + load_cr3(next->pgd);
29697 + load_LDT_nolock(&next->context);
29698 ++
29699 ++#ifdef CONFIG_PAX_PAGEEXEC
29700 ++ if (!nx_enabled)
29701 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
29702 ++#endif
29703 ++
29704 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29705 ++#ifdef CONFIG_PAX_PAGEEXEC
29706 ++ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
29707 ++#endif
29708 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
29709 ++#endif
29710 ++
29711 + }
29712 + }
29713 + #endif
29714 +diff -urNp linux-2.6.27.10/include/asm-x86/mmu.h linux-2.6.27.10/include/asm-x86/mmu.h
29715 +--- linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-07 12:55:34.000000000 -0500
29716 ++++ linux-2.6.27.10/include/asm-x86/mmu.h 2008-11-18 03:38:45.000000000 -0500
29717 +@@ -11,13 +11,26 @@
29718 + * cpu_vm_mask is used to optimize ldt flushing.
29719 + */
29720 + typedef struct {
29721 +- void *ldt;
29722 ++ struct desc_struct *ldt;
29723 + #ifdef CONFIG_X86_64
29724 + rwlock_t ldtlock;
29725 + #endif
29726 + int size;
29727 + struct mutex lock;
29728 +- void *vdso;
29729 ++ unsigned long vdso;
29730 ++
29731 ++#ifdef CONFIG_X86_32
29732 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
29733 ++ unsigned long user_cs_base;
29734 ++ unsigned long user_cs_limit;
29735 ++
29736 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
29737 ++ cpumask_t cpu_user_cs_mask;
29738 ++#endif
29739 ++
29740 ++#endif
29741 ++#endif
29742 ++
29743 + } mm_context_t;
29744 +
29745 + #ifdef CONFIG_SMP
29746 +diff -urNp linux-2.6.27.10/include/asm-x86/module.h linux-2.6.27.10/include/asm-x86/module.h
29747 +--- linux-2.6.27.10/include/asm-x86/module.h 2008-11-07 12:55:34.000000000 -0500
29748 ++++ linux-2.6.27.10/include/asm-x86/module.h 2008-11-18 03:38:45.000000000 -0500
29749 +@@ -76,7 +76,12 @@ struct mod_arch_specific {};
29750 + # else
29751 + # define MODULE_STACKSIZE ""
29752 + # endif
29753 +-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
29754 ++# ifdef CONFIG_GRKERNSEC
29755 ++# define MODULE_GRSEC "GRSECURITY "
29756 ++# else
29757 ++# define MODULE_GRSEC ""
29758 ++# endif
29759 ++# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC
29760 + #endif
29761 +
29762 + #endif /* _ASM_MODULE_H */
29763 +diff -urNp linux-2.6.27.10/include/asm-x86/page_32.h linux-2.6.27.10/include/asm-x86/page_32.h
29764 +--- linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-07 12:55:34.000000000 -0500
29765 ++++ linux-2.6.27.10/include/asm-x86/page_32.h 2008-11-18 03:38:45.000000000 -0500
29766 +@@ -13,6 +13,23 @@
29767 + */
29768 + #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
29769 +
29770 ++#ifdef CONFIG_PAX_KERNEXEC
29771 ++#ifndef __ASSEMBLY__
29772 ++extern unsigned char MODULES_VADDR[];
29773 ++extern unsigned char MODULES_END[];
29774 ++extern unsigned char KERNEL_TEXT_OFFSET[];
29775 ++#define ktla_ktva(addr) (addr + (unsigned long)KERNEL_TEXT_OFFSET)
29776 ++#define ktva_ktla(addr) (addr - (unsigned long)KERNEL_TEXT_OFFSET)
29777 ++#endif
29778 ++#else
29779 ++#define ktla_ktva(addr) (addr)
29780 ++#define ktva_ktla(addr) (addr)
29781 ++#endif
29782 ++
29783 ++#ifdef CONFIG_PAX_PAGEEXEC
29784 ++#define CONFIG_ARCH_TRACK_EXEC_LIMIT 1
29785 ++#endif
29786 ++
29787 + #ifdef CONFIG_4KSTACKS
29788 + #define THREAD_ORDER 0
29789 + #else
29790 +diff -urNp linux-2.6.27.10/include/asm-x86/page_64.h linux-2.6.27.10/include/asm-x86/page_64.h
29791 +--- linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-07 12:55:34.000000000 -0500
29792 ++++ linux-2.6.27.10/include/asm-x86/page_64.h 2008-11-18 03:38:45.000000000 -0500
29793 +@@ -49,6 +49,9 @@
29794 + #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START)
29795 + #define __START_KERNEL_map _AC(0xffffffff80000000, UL)
29796 +
29797 ++#define ktla_ktva(addr) (addr)
29798 ++#define ktva_ktla(addr) (addr)
29799 ++
29800 + /* See Documentation/x86_64/mm.txt for a description of the memory map. */
29801 + #define __PHYSICAL_MASK_SHIFT 46
29802 + #define __VIRTUAL_MASK_SHIFT 48
29803 +@@ -101,5 +104,6 @@ extern void init_extra_mapping_wb(unsign
29804 + #define pfn_valid(pfn) ((pfn) < max_pfn)
29805 + #endif
29806 +
29807 ++#define nx_enabled (1)
29808 +
29809 + #endif /* _X86_64_PAGE_H */
29810 +diff -urNp linux-2.6.27.10/include/asm-x86/paravirt.h linux-2.6.27.10/include/asm-x86/paravirt.h
29811 +--- linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-07 12:55:34.000000000 -0500
29812 ++++ linux-2.6.27.10/include/asm-x86/paravirt.h 2008-11-18 03:38:45.000000000 -0500
29813 +@@ -1557,7 +1557,7 @@ static inline unsigned long __raw_local_
29814 + #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
29815 + #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
29816 + #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
29817 +-#define PARA_INDIRECT(addr) *%cs:addr
29818 ++#define PARA_INDIRECT(addr) *%ss:addr
29819 + #endif
29820 +
29821 + #define INTERRUPT_RETURN \
29822 +diff -urNp linux-2.6.27.10/include/asm-x86/pda.h linux-2.6.27.10/include/asm-x86/pda.h
29823 +--- linux-2.6.27.10/include/asm-x86/pda.h 2008-11-07 12:55:34.000000000 -0500
29824 ++++ linux-2.6.27.10/include/asm-x86/pda.h 2008-11-18 03:38:45.000000000 -0500
29825 +@@ -16,11 +16,9 @@ struct x8664_pda {
29826 + unsigned long oldrsp; /* 24 user rsp for system call */
29827 + int irqcount; /* 32 Irq nesting counter. Starts -1 */
29828 + unsigned int cpunumber; /* 36 Logical CPU number */
29829 +-#ifdef CONFIG_CC_STACKPROTECTOR
29830 + unsigned long stack_canary; /* 40 stack canary value */
29831 + /* gcc-ABI: this canary MUST be at
29832 + offset 40!!! */
29833 +-#endif
29834 + char *irqstackptr;
29835 + short nodenumber; /* number of current node (32k max) */
29836 + short in_bootmem; /* pda lives in bootmem */
29837 +diff -urNp linux-2.6.27.10/include/asm-x86/percpu.h linux-2.6.27.10/include/asm-x86/percpu.h
29838 +--- linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-07 12:55:34.000000000 -0500
29839 ++++ linux-2.6.27.10/include/asm-x86/percpu.h 2008-11-18 03:38:45.000000000 -0500
29840 +@@ -93,6 +93,12 @@ DECLARE_PER_CPU(struct x8664_pda, pda);
29841 +
29842 + #define __my_cpu_offset x86_read_percpu(this_cpu_off)
29843 +
29844 ++#include <asm-generic/sections.h>
29845 ++#include <linux/threads.h>
29846 ++#define __per_cpu_offset __per_cpu_offset
29847 ++extern unsigned long __per_cpu_offset[NR_CPUS];
29848 ++#define per_cpu_offset(x) (__per_cpu_offset[x] + (unsigned long)__per_cpu_start)
29849 ++
29850 + /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
29851 + #define __percpu_seg "%%fs:"
29852 +
29853 +diff -urNp linux-2.6.27.10/include/asm-x86/pgalloc.h linux-2.6.27.10/include/asm-x86/pgalloc.h
29854 +--- linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-07 12:55:34.000000000 -0500
29855 ++++ linux-2.6.27.10/include/asm-x86/pgalloc.h 2008-11-18 03:38:45.000000000 -0500
29856 +@@ -51,7 +51,7 @@ static inline void pmd_populate_kernel(s
29857 + pmd_t *pmd, pte_t *pte)
29858 + {
29859 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
29860 +- set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
29861 ++ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
29862 + }
29863 +
29864 + static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
29865 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-2level.h linux-2.6.27.10/include/asm-x86/pgtable-2level.h
29866 +--- linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-07 12:55:34.000000000 -0500
29867 ++++ linux-2.6.27.10/include/asm-x86/pgtable-2level.h 2008-11-18 03:38:45.000000000 -0500
29868 +@@ -18,7 +18,19 @@ static inline void native_set_pte(pte_t
29869 +
29870 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
29871 + {
29872 ++
29873 ++#ifdef CONFIG_PAX_KERNEXEC
29874 ++ unsigned long cr0;
29875 ++
29876 ++ pax_open_kernel(cr0);
29877 ++#endif
29878 ++
29879 + *pmdp = pmd;
29880 ++
29881 ++#ifdef CONFIG_PAX_KERNEXEC
29882 ++ pax_close_kernel(cr0);
29883 ++#endif
29884 ++
29885 + }
29886 +
29887 + static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
29888 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_32.h linux-2.6.27.10/include/asm-x86/pgtable_32.h
29889 +--- linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-07 12:55:34.000000000 -0500
29890 ++++ linux-2.6.27.10/include/asm-x86/pgtable_32.h 2008-11-18 03:38:45.000000000 -0500
29891 +@@ -25,8 +25,6 @@
29892 + struct mm_struct;
29893 + struct vm_area_struct;
29894 +
29895 +-extern pgd_t swapper_pg_dir[1024];
29896 +-
29897 + static inline void pgtable_cache_init(void) { }
29898 + static inline void check_pgt_cache(void) { }
29899 + void paging_init(void);
29900 +@@ -45,6 +43,11 @@ void paging_init(void);
29901 + # include <asm/pgtable-2level-defs.h>
29902 + #endif
29903 +
29904 ++extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
29905 ++#ifdef CONFIG_X86_PAE
29906 ++extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
29907 ++#endif
29908 ++
29909 + #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
29910 + #define PGDIR_MASK (~(PGDIR_SIZE - 1))
29911 +
29912 +@@ -81,7 +84,7 @@ void paging_init(void);
29913 + #undef TEST_ACCESS_OK
29914 +
29915 + /* The boot page tables (all created as a single array) */
29916 +-extern unsigned long pg0[];
29917 ++extern pte_t pg0[];
29918 +
29919 + #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
29920 +
29921 +@@ -173,6 +176,9 @@ do { \
29922 +
29923 + #endif /* !__ASSEMBLY__ */
29924 +
29925 ++#define HAVE_ARCH_UNMAPPED_AREA
29926 ++#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
29927 ++
29928 + /*
29929 + * kern_addr_valid() is (1) for FLATMEM and (0) for
29930 + * SPARSEMEM and DISCONTIGMEM
29931 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable-3level.h linux-2.6.27.10/include/asm-x86/pgtable-3level.h
29932 +--- linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-07 12:55:34.000000000 -0500
29933 ++++ linux-2.6.27.10/include/asm-x86/pgtable-3level.h 2008-11-18 03:38:45.000000000 -0500
29934 +@@ -70,12 +70,36 @@ static inline void native_set_pte_atomic
29935 +
29936 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
29937 + {
29938 ++
29939 ++#ifdef CONFIG_PAX_KERNEXEC
29940 ++ unsigned long cr0;
29941 ++
29942 ++ pax_open_kernel(cr0);
29943 ++#endif
29944 ++
29945 + set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
29946 ++
29947 ++#ifdef CONFIG_PAX_KERNEXEC
29948 ++ pax_close_kernel(cr0);
29949 ++#endif
29950 ++
29951 + }
29952 +
29953 + static inline void native_set_pud(pud_t *pudp, pud_t pud)
29954 + {
29955 ++
29956 ++#ifdef CONFIG_PAX_KERNEXEC
29957 ++ unsigned long cr0;
29958 ++
29959 ++ pax_open_kernel(cr0);
29960 ++#endif
29961 ++
29962 + set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
29963 ++
29964 ++#ifdef CONFIG_PAX_KERNEXEC
29965 ++ pax_close_kernel(cr0);
29966 ++#endif
29967 ++
29968 + }
29969 +
29970 + /*
29971 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable_64.h linux-2.6.27.10/include/asm-x86/pgtable_64.h
29972 +--- linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-07 12:55:34.000000000 -0500
29973 ++++ linux-2.6.27.10/include/asm-x86/pgtable_64.h 2008-11-18 03:38:45.000000000 -0500
29974 +@@ -15,9 +15,12 @@
29975 +
29976 + extern pud_t level3_kernel_pgt[512];
29977 + extern pud_t level3_ident_pgt[512];
29978 ++extern pud_t level3_vmalloc_pgt[512];
29979 ++extern pud_t level3_vmemmap_pgt[512];
29980 + extern pmd_t level2_kernel_pgt[512];
29981 + extern pmd_t level2_fixmap_pgt[512];
29982 + extern pmd_t level2_ident_pgt[512];
29983 ++extern pte_t level1_fixmap_pgt[512];
29984 + extern pgd_t init_level4_pgt[];
29985 +
29986 + #define swapper_pg_dir init_level4_pgt
29987 +@@ -106,7 +109,19 @@ static inline pte_t native_ptep_get_and_
29988 +
29989 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
29990 + {
29991 ++
29992 ++#ifdef CONFIG_PAX_KERNEXEC
29993 ++ unsigned long cr0;
29994 ++
29995 ++ pax_open_kernel(cr0);
29996 ++#endif
29997 ++
29998 + *pmdp = pmd;
29999 ++
30000 ++#ifdef CONFIG_PAX_KERNEXEC
30001 ++ pax_close_kernel(cr0);
30002 ++#endif
30003 ++
30004 + }
30005 +
30006 + static inline void native_pmd_clear(pmd_t *pmd)
30007 +@@ -158,17 +173,17 @@ static inline void native_pgd_clear(pgd_
30008 +
30009 + static inline int pgd_bad(pgd_t pgd)
30010 + {
30011 +- return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
30012 ++ return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
30013 + }
30014 +
30015 + static inline int pud_bad(pud_t pud)
30016 + {
30017 +- return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
30018 ++ return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
30019 + }
30020 +
30021 + static inline int pmd_bad(pmd_t pmd)
30022 + {
30023 +- return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
30024 ++ return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
30025 + }
30026 +
30027 + #define pte_none(x) (!pte_val((x)))
30028 +diff -urNp linux-2.6.27.10/include/asm-x86/pgtable.h linux-2.6.27.10/include/asm-x86/pgtable.h
30029 +--- linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-07 12:55:34.000000000 -0500
30030 ++++ linux-2.6.27.10/include/asm-x86/pgtable.h 2008-11-18 03:38:45.000000000 -0500
30031 +@@ -41,7 +41,7 @@
30032 + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
30033 + #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
30034 + #else
30035 +-#define _PAGE_NX (_AT(pteval_t, 0))
30036 ++#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
30037 + #endif
30038 +
30039 + /* If _PAGE_PRESENT is clear, we use these: */
30040 +@@ -81,6 +81,9 @@
30041 + #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
30042 + _PAGE_ACCESSED)
30043 +
30044 ++#define PAGE_READONLY_NOEXEC PAGE_READONLY
30045 ++#define PAGE_SHARED_NOEXEC PAGE_SHARED
30046 ++
30047 + #define __PAGE_KERNEL_EXEC \
30048 + (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
30049 + #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
30050 +@@ -92,7 +95,7 @@
30051 + #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
30052 + #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
30053 + #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
30054 +-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
30055 ++#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
30056 + #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
30057 + #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
30058 + #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
30059 +@@ -142,10 +145,17 @@ extern unsigned long empty_zero_page[PAG
30060 + extern spinlock_t pgd_lock;
30061 + extern struct list_head pgd_list;
30062 +
30063 ++extern pteval_t __supported_pte_mask;
30064 ++
30065 + /*
30066 + * The following only work if pte_present() is true.
30067 + * Undefined behaviour if not..
30068 + */
30069 ++static inline int pte_user(pte_t pte)
30070 ++{
30071 ++ return pte_val(pte) & _PAGE_USER;
30072 ++}
30073 ++
30074 + static inline int pte_dirty(pte_t pte)
30075 + {
30076 + return pte_flags(pte) & _PAGE_DIRTY;
30077 +@@ -207,9 +217,29 @@ static inline pte_t pte_wrprotect(pte_t
30078 + return __pte(pte_val(pte) & ~_PAGE_RW);
30079 + }
30080 +
30081 ++static inline pte_t pte_mkread(pte_t pte)
30082 ++{
30083 ++ return __pte(pte_val(pte) | _PAGE_USER);
30084 ++}
30085 ++
30086 + static inline pte_t pte_mkexec(pte_t pte)
30087 + {
30088 +- return __pte(pte_val(pte) & ~_PAGE_NX);
30089 ++#ifdef CONFIG_X86_PAE
30090 ++ if (__supported_pte_mask & _PAGE_NX)
30091 ++ return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX);
30092 ++ else
30093 ++#endif
30094 ++ return __pte(pte_val(pte) | _PAGE_USER);
30095 ++}
30096 ++
30097 ++static inline pte_t pte_exprotect(pte_t pte)
30098 ++{
30099 ++#ifdef CONFIG_X86_PAE
30100 ++ if (__supported_pte_mask & _PAGE_NX)
30101 ++ return __pte(pte_val(pte) | _PAGE_NX);
30102 ++ else
30103 ++#endif
30104 ++ return __pte(pte_val(pte) & ~_PAGE_USER);
30105 + }
30106 +
30107 + static inline pte_t pte_mkdirty(pte_t pte)
30108 +@@ -252,8 +282,6 @@ static inline pte_t pte_mkspecial(pte_t
30109 + return __pte(pte_val(pte) | _PAGE_SPECIAL);
30110 + }
30111 +
30112 +-extern pteval_t __supported_pte_mask;
30113 +-
30114 + static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
30115 + {
30116 + return __pte((((phys_addr_t)page_nr << PAGE_SHIFT) |
30117 +@@ -514,7 +542,19 @@ static inline void ptep_set_wrprotect(st
30118 + */
30119 + static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
30120 + {
30121 +- memcpy(dst, src, count * sizeof(pgd_t));
30122 ++
30123 ++#ifdef CONFIG_PAX_KERNEXEC
30124 ++ unsigned long cr0;
30125 ++
30126 ++ pax_open_kernel(cr0);
30127 ++#endif
30128 ++
30129 ++ memcpy(dst, src, count * sizeof(pgd_t));
30130 ++
30131 ++#ifdef CONFIG_PAX_KERNEXEC
30132 ++ pax_close_kernel(cr0);
30133 ++#endif
30134 ++
30135 + }
30136 +
30137 +
30138 +diff -urNp linux-2.6.27.10/include/asm-x86/processor.h linux-2.6.27.10/include/asm-x86/processor.h
30139 +--- linux-2.6.27.10/include/asm-x86/processor.h 2008-11-07 12:55:34.000000000 -0500
30140 ++++ linux-2.6.27.10/include/asm-x86/processor.h 2008-11-18 03:38:45.000000000 -0500
30141 +@@ -269,7 +269,7 @@ struct tss_struct {
30142 +
30143 + } ____cacheline_aligned;
30144 +
30145 +-DECLARE_PER_CPU(struct tss_struct, init_tss);
30146 ++extern struct tss_struct init_tss[NR_CPUS];
30147 +
30148 + /*
30149 + * Save the original ist values for checking stack pointers during debugging
30150 +@@ -832,11 +832,20 @@ static inline void spin_lock_prefetch(co
30151 + * User space process size: 3GB (default).
30152 + */
30153 + #define TASK_SIZE PAGE_OFFSET
30154 ++
30155 ++#ifdef CONFIG_PAX_SEGMEXEC
30156 ++#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
30157 ++#endif
30158 ++
30159 ++#ifdef CONFIG_PAX_SEGMEXEC
30160 ++#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
30161 ++#else
30162 + #define STACK_TOP TASK_SIZE
30163 +-#define STACK_TOP_MAX STACK_TOP
30164 ++#endif
30165 ++#define STACK_TOP_MAX TASK_SIZE
30166 +
30167 + #define INIT_THREAD { \
30168 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
30169 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
30170 + .vm86_info = NULL, \
30171 + .sysenter_cs = __KERNEL_CS, \
30172 + .io_bitmap_ptr = NULL, \
30173 +@@ -851,7 +860,7 @@ static inline void spin_lock_prefetch(co
30174 + */
30175 + #define INIT_TSS { \
30176 + .x86_tss = { \
30177 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
30178 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
30179 + .ss0 = __KERNEL_DS, \
30180 + .ss1 = __KERNEL_CS, \
30181 + .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
30182 +@@ -862,11 +871,7 @@ static inline void spin_lock_prefetch(co
30183 + extern unsigned long thread_saved_pc(struct task_struct *tsk);
30184 +
30185 + #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
30186 +-#define KSTK_TOP(info) \
30187 +-({ \
30188 +- unsigned long *__ptr = (unsigned long *)(info); \
30189 +- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
30190 +-})
30191 ++#define KSTK_TOP(info) ((info)->task.thread.sp0)
30192 +
30193 + /*
30194 + * The below -8 is to reserve 8 bytes on top of the ring0 stack.
30195 +@@ -881,7 +886,7 @@ extern unsigned long thread_saved_pc(str
30196 + #define task_pt_regs(task) \
30197 + ({ \
30198 + struct pt_regs *__regs__; \
30199 +- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
30200 ++ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
30201 + __regs__ - 1; \
30202 + })
30203 +
30204 +@@ -897,7 +902,7 @@ extern unsigned long thread_saved_pc(str
30205 + * space during mmap's.
30206 + */
30207 + #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
30208 +- 0xc0000000 : 0xFFFFe000)
30209 ++ 0xc0000000 : 0xFFFFf000)
30210 +
30211 + #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
30212 + IA32_PAGE_OFFSET : TASK_SIZE64)
30213 +@@ -934,6 +939,10 @@ extern void start_thread(struct pt_regs
30214 + */
30215 + #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
30216 +
30217 ++#ifdef CONFIG_PAX_SEGMEXEC
30218 ++#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
30219 ++#endif
30220 ++
30221 + #define KSTK_EIP(task) (task_pt_regs(task)->ip)
30222 +
30223 + /* Get/set a process' ability to use the timestamp counter instruction */
30224 +diff -urNp linux-2.6.27.10/include/asm-x86/ptrace.h linux-2.6.27.10/include/asm-x86/ptrace.h
30225 +--- linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-07 12:55:34.000000000 -0500
30226 ++++ linux-2.6.27.10/include/asm-x86/ptrace.h 2008-11-18 03:38:45.000000000 -0500
30227 +@@ -131,6 +131,7 @@ struct pt_regs {
30228 +
30229 + /* the DS BTS struct is used for ptrace as well */
30230 + #include <asm/ds.h>
30231 ++#include <asm/segment.h>
30232 +
30233 + struct task_struct;
30234 +
30235 +@@ -154,28 +155,29 @@ static inline unsigned long regs_return_
30236 + }
30237 +
30238 + /*
30239 +- * user_mode_vm(regs) determines whether a register set came from user mode.
30240 ++ * user_mode(regs) determines whether a register set came from user mode.
30241 + * This is true if V8086 mode was enabled OR if the register set was from
30242 + * protected mode with RPL-3 CS value. This tricky test checks that with
30243 + * one comparison. Many places in the kernel can bypass this full check
30244 +- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
30245 ++ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
30246 ++ * be used.
30247 + */
30248 +-static inline int user_mode(struct pt_regs *regs)
30249 ++static inline int user_mode_novm(struct pt_regs *regs)
30250 + {
30251 + #ifdef CONFIG_X86_32
30252 + return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
30253 + #else
30254 +- return !!(regs->cs & 3);
30255 ++ return !!(regs->cs & SEGMENT_RPL_MASK);
30256 + #endif
30257 + }
30258 +
30259 +-static inline int user_mode_vm(struct pt_regs *regs)
30260 ++static inline int user_mode(struct pt_regs *regs)
30261 + {
30262 + #ifdef CONFIG_X86_32
30263 + return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
30264 + USER_RPL;
30265 + #else
30266 +- return user_mode(regs);
30267 ++ return user_mode_novm(regs);
30268 + #endif
30269 + }
30270 +
30271 +diff -urNp linux-2.6.27.10/include/asm-x86/reboot.h linux-2.6.27.10/include/asm-x86/reboot.h
30272 +--- linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-07 12:55:34.000000000 -0500
30273 ++++ linux-2.6.27.10/include/asm-x86/reboot.h 2008-11-18 03:38:45.000000000 -0500
30274 +@@ -16,6 +16,6 @@ extern struct machine_ops machine_ops;
30275 +
30276 + void native_machine_crash_shutdown(struct pt_regs *regs);
30277 + void native_machine_shutdown(void);
30278 +-void machine_real_restart(const unsigned char *code, int length);
30279 ++void machine_real_restart(const unsigned char *code, unsigned int length);
30280 +
30281 + #endif /* _ASM_REBOOT_H */
30282 +diff -urNp linux-2.6.27.10/include/asm-x86/rwsem.h linux-2.6.27.10/include/asm-x86/rwsem.h
30283 +--- linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-07 12:55:34.000000000 -0500
30284 ++++ linux-2.6.27.10/include/asm-x86/rwsem.h 2008-11-18 03:38:45.000000000 -0500
30285 +@@ -106,10 +106,26 @@ static inline void __down_read(struct rw
30286 + {
30287 + asm volatile("# beginning down_read\n\t"
30288 + LOCK_PREFIX " incl (%%eax)\n\t"
30289 ++
30290 ++#ifdef CONFIG_PAX_REFCOUNT
30291 ++#ifdef CONFIG_X86_32
30292 ++ "into\n0:\n"
30293 ++#else
30294 ++ "jno 0f\n"
30295 ++ "int $4\n0:\n"
30296 ++#endif
30297 ++ ".pushsection .fixup,\"ax\"\n"
30298 ++ "1:\n"
30299 ++ LOCK_PREFIX "decl (%%eax)\n"
30300 ++ "jmp 0b\n"
30301 ++ ".popsection\n"
30302 ++ _ASM_EXTABLE(0b, 1b)
30303 ++#endif
30304 ++
30305 + /* adds 0x00000001, returns the old value */
30306 +- " jns 1f\n"
30307 ++ " jns 2f\n"
30308 + " call call_rwsem_down_read_failed\n"
30309 +- "1:\n\t"
30310 ++ "2:\n\t"
30311 + "# ending down_read\n\t"
30312 + : "+m" (sem->count)
30313 + : "a" (sem)
30314 +@@ -124,13 +140,29 @@ static inline int __down_read_trylock(st
30315 + __s32 result, tmp;
30316 + asm volatile("# beginning __down_read_trylock\n\t"
30317 + " movl %0,%1\n\t"
30318 +- "1:\n\t"
30319 ++ "2:\n\t"
30320 + " movl %1,%2\n\t"
30321 + " addl %3,%2\n\t"
30322 +- " jle 2f\n\t"
30323 ++
30324 ++#ifdef CONFIG_PAX_REFCOUNT
30325 ++#ifdef CONFIG_X86_32
30326 ++ "into\n0:\n"
30327 ++#else
30328 ++ "jno 0f\n"
30329 ++ "int $4\n0:\n"
30330 ++#endif
30331 ++ ".pushsection .fixup,\"ax\"\n"
30332 ++ "1:\n"
30333 ++ "subl %3,%2\n"
30334 ++ "jmp 0b\n"
30335 ++ ".popsection\n"
30336 ++ _ASM_EXTABLE(0b, 1b)
30337 ++#endif
30338 ++
30339 ++ " jle 3f\n\t"
30340 + LOCK_PREFIX " cmpxchgl %2,%0\n\t"
30341 +- " jnz 1b\n\t"
30342 +- "2:\n\t"
30343 ++ " jnz 2b\n\t"
30344 ++ "3:\n\t"
30345 + "# ending __down_read_trylock\n\t"
30346 + : "+m" (sem->count), "=&a" (result), "=&r" (tmp)
30347 + : "i" (RWSEM_ACTIVE_READ_BIAS)
30348 +@@ -148,12 +180,28 @@ static inline void __down_write_nested(s
30349 + tmp = RWSEM_ACTIVE_WRITE_BIAS;
30350 + asm volatile("# beginning down_write\n\t"
30351 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
30352 ++
30353 ++#ifdef CONFIG_PAX_REFCOUNT
30354 ++#ifdef CONFIG_X86_32
30355 ++ "into\n0:\n"
30356 ++#else
30357 ++ "jno 0f\n"
30358 ++ "int $4\n0:\n"
30359 ++#endif
30360 ++ ".pushsection .fixup,\"ax\"\n"
30361 ++ "1:\n"
30362 ++ "movl %%edx,(%%eax)\n"
30363 ++ "jmp 0b\n"
30364 ++ ".popsection\n"
30365 ++ _ASM_EXTABLE(0b, 1b)
30366 ++#endif
30367 ++
30368 + /* subtract 0x0000ffff, returns the old value */
30369 + " testl %%edx,%%edx\n\t"
30370 + /* was the count 0 before? */
30371 +- " jz 1f\n"
30372 ++ " jz 2f\n"
30373 + " call call_rwsem_down_write_failed\n"
30374 +- "1:\n"
30375 ++ "2:\n"
30376 + "# ending down_write"
30377 + : "+m" (sem->count), "=d" (tmp)
30378 + : "a" (sem), "1" (tmp)
30379 +@@ -186,10 +234,26 @@ static inline void __up_read(struct rw_s
30380 + __s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
30381 + asm volatile("# beginning __up_read\n\t"
30382 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
30383 ++
30384 ++#ifdef CONFIG_PAX_REFCOUNT
30385 ++#ifdef CONFIG_X86_32
30386 ++ "into\n0:\n"
30387 ++#else
30388 ++ "jno 0f\n"
30389 ++ "int $4\n0:\n"
30390 ++#endif
30391 ++ ".pushsection .fixup,\"ax\"\n"
30392 ++ "1:\n"
30393 ++ "movl %%edx,(%%eax)\n"
30394 ++ "jmp 0b\n"
30395 ++ ".popsection\n"
30396 ++ _ASM_EXTABLE(0b, 1b)
30397 ++#endif
30398 ++
30399 + /* subtracts 1, returns the old value */
30400 +- " jns 1f\n\t"
30401 ++ " jns 2f\n\t"
30402 + " call call_rwsem_wake\n"
30403 +- "1:\n"
30404 ++ "2:\n"
30405 + "# ending __up_read\n"
30406 + : "+m" (sem->count), "=d" (tmp)
30407 + : "a" (sem), "1" (tmp)
30408 +@@ -204,11 +268,27 @@ static inline void __up_write(struct rw_
30409 + asm volatile("# beginning __up_write\n\t"
30410 + " movl %2,%%edx\n\t"
30411 + LOCK_PREFIX " xaddl %%edx,(%%eax)\n\t"
30412 ++
30413 ++#ifdef CONFIG_PAX_REFCOUNT
30414 ++#ifdef CONFIG_X86_32
30415 ++ "into\n0:\n"
30416 ++#else
30417 ++ "jno 0f\n"
30418 ++ "int $4\n0:\n"
30419 ++#endif
30420 ++ ".pushsection .fixup,\"ax\"\n"
30421 ++ "1:\n"
30422 ++ "movl %%edx,(%%eax)\n"
30423 ++ "jmp 0b\n"
30424 ++ ".popsection\n"
30425 ++ _ASM_EXTABLE(0b, 1b)
30426 ++#endif
30427 ++
30428 + /* tries to transition
30429 + 0xffff0001 -> 0x00000000 */
30430 +- " jz 1f\n"
30431 ++ " jz 2f\n"
30432 + " call call_rwsem_wake\n"
30433 +- "1:\n\t"
30434 ++ "2:\n\t"
30435 + "# ending __up_write\n"
30436 + : "+m" (sem->count)
30437 + : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS)
30438 +@@ -222,10 +302,26 @@ static inline void __downgrade_write(str
30439 + {
30440 + asm volatile("# beginning __downgrade_write\n\t"
30441 + LOCK_PREFIX " addl %2,(%%eax)\n\t"
30442 ++
30443 ++#ifdef CONFIG_PAX_REFCOUNT
30444 ++#ifdef CONFIG_X86_32
30445 ++ "into\n0:\n"
30446 ++#else
30447 ++ "jno 0f\n"
30448 ++ "int $4\n0:\n"
30449 ++#endif
30450 ++ ".pushsection .fixup,\"ax\"\n"
30451 ++ "1:\n"
30452 ++ LOCK_PREFIX "subl %2,(%%eax)\n"
30453 ++ "jmp 0b\n"
30454 ++ ".popsection\n"
30455 ++ _ASM_EXTABLE(0b, 1b)
30456 ++#endif
30457 ++
30458 + /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
30459 +- " jns 1f\n\t"
30460 ++ " jns 2f\n\t"
30461 + " call call_rwsem_downgrade_wake\n"
30462 +- "1:\n\t"
30463 ++ "2:\n\t"
30464 + "# ending __downgrade_write\n"
30465 + : "+m" (sem->count)
30466 + : "a" (sem), "i" (-RWSEM_WAITING_BIAS)
30467 +@@ -237,7 +333,23 @@ static inline void __downgrade_write(str
30468 + */
30469 + static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
30470 + {
30471 +- asm volatile(LOCK_PREFIX "addl %1,%0"
30472 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
30473 ++
30474 ++#ifdef CONFIG_PAX_REFCOUNT
30475 ++#ifdef CONFIG_X86_32
30476 ++ "into\n0:\n"
30477 ++#else
30478 ++ "jno 0f\n"
30479 ++ "int $4\n0:\n"
30480 ++#endif
30481 ++ ".pushsection .fixup,\"ax\"\n"
30482 ++ "1:\n"
30483 ++ LOCK_PREFIX "subl %1,%0\n"
30484 ++ "jmp 0b\n"
30485 ++ ".popsection\n"
30486 ++ _ASM_EXTABLE(0b, 1b)
30487 ++#endif
30488 ++
30489 + : "+m" (sem->count)
30490 + : "ir" (delta));
30491 + }
30492 +@@ -249,7 +361,23 @@ static inline int rwsem_atomic_update(in
30493 + {
30494 + int tmp = delta;
30495 +
30496 +- asm volatile(LOCK_PREFIX "xadd %0,%1"
30497 ++ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
30498 ++
30499 ++#ifdef CONFIG_PAX_REFCOUNT
30500 ++#ifdef CONFIG_X86_32
30501 ++ "into\n0:\n"
30502 ++#else
30503 ++ "jno 0f\n"
30504 ++ "int $4\n0:\n"
30505 ++#endif
30506 ++ ".pushsection .fixup,\"ax\"\n"
30507 ++ "1:\n"
30508 ++ "movl %0,%1\n"
30509 ++ "jmp 0b\n"
30510 ++ ".popsection\n"
30511 ++ _ASM_EXTABLE(0b, 1b)
30512 ++#endif
30513 ++
30514 + : "+r" (tmp), "+m" (sem->count)
30515 + : : "memory");
30516 +
30517 +diff -urNp linux-2.6.27.10/include/asm-x86/segment.h linux-2.6.27.10/include/asm-x86/segment.h
30518 +--- linux-2.6.27.10/include/asm-x86/segment.h 2008-11-07 12:55:34.000000000 -0500
30519 ++++ linux-2.6.27.10/include/asm-x86/segment.h 2008-11-18 03:38:45.000000000 -0500
30520 +@@ -88,13 +88,19 @@
30521 + #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
30522 + #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
30523 +
30524 +-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
30525 ++#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
30526 + #ifdef CONFIG_SMP
30527 + #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
30528 + #else
30529 + #define __KERNEL_PERCPU 0
30530 + #endif
30531 +
30532 ++#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 16)
30533 ++#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
30534 ++
30535 ++#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 17)
30536 ++#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
30537 ++
30538 + #define GDT_ENTRY_DOUBLEFAULT_TSS 31
30539 +
30540 + /*
30541 +@@ -135,10 +141,10 @@
30542 + #define SEGMENT_IS_KERNEL_CODE(x) (((x) & 0xfc) == GDT_ENTRY_KERNEL_CS * 8)
30543 +
30544 + /* Matches __KERNEL_CS and __USER_CS (they must be 2 entries apart) */
30545 +-#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xec) == GDT_ENTRY_KERNEL_CS * 8)
30546 ++#define SEGMENT_IS_FLAT_CODE(x) (((x) & 0xFFFCU) == __KERNEL_CS || ((x) & 0xFFFCU) == __USER_CS)
30547 +
30548 + /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
30549 +-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
30550 ++#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
30551 +
30552 +
30553 + #else
30554 +diff -urNp linux-2.6.27.10/include/asm-x86/spinlock.h linux-2.6.27.10/include/asm-x86/spinlock.h
30555 +--- linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-07 12:55:34.000000000 -0500
30556 ++++ linux-2.6.27.10/include/asm-x86/spinlock.h 2008-11-18 03:38:45.000000000 -0500
30557 +@@ -315,18 +315,50 @@ static inline int __raw_write_can_lock(r
30558 + static inline void __raw_read_lock(raw_rwlock_t *rw)
30559 + {
30560 + asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
30561 +- "jns 1f\n"
30562 +- "call __read_lock_failed\n\t"
30563 ++
30564 ++#ifdef CONFIG_PAX_REFCOUNT
30565 ++#ifdef CONFIG_X86_32
30566 ++ "into\n0:\n"
30567 ++#else
30568 ++ "jno 0f\n"
30569 ++ "int $4\n0:\n"
30570 ++#endif
30571 ++ ".pushsection .fixup,\"ax\"\n"
30572 + "1:\n"
30573 ++ LOCK_PREFIX " addl $1,(%0)\n"
30574 ++ "jmp 0b\n"
30575 ++ ".popsection\n"
30576 ++ _ASM_EXTABLE(0b, 1b)
30577 ++#endif
30578 ++
30579 ++ "jns 2f\n"
30580 ++ "call __read_lock_failed\n\t"
30581 ++ "2:\n"
30582 + ::LOCK_PTR_REG (rw) : "memory");
30583 + }
30584 +
30585 + static inline void __raw_write_lock(raw_rwlock_t *rw)
30586 + {
30587 + asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
30588 +- "jz 1f\n"
30589 +- "call __write_lock_failed\n\t"
30590 ++
30591 ++#ifdef CONFIG_PAX_REFCOUNT
30592 ++#ifdef CONFIG_X86_32
30593 ++ "into\n0:\n"
30594 ++#else
30595 ++ "jno 0f\n"
30596 ++ "int $4\n0:\n"
30597 ++#endif
30598 ++ ".pushsection .fixup,\"ax\"\n"
30599 + "1:\n"
30600 ++ LOCK_PREFIX " addl %1,(%0)\n"
30601 ++ "jmp 0b\n"
30602 ++ ".popsection\n"
30603 ++ _ASM_EXTABLE(0b, 1b)
30604 ++#endif
30605 ++
30606 ++ "jz 2f\n"
30607 ++ "call __write_lock_failed\n\t"
30608 ++ "2:\n"
30609 + ::LOCK_PTR_REG (rw), "i" (RW_LOCK_BIAS) : "memory");
30610 + }
30611 +
30612 +@@ -353,12 +385,45 @@ static inline int __raw_write_trylock(ra
30613 +
30614 + static inline void __raw_read_unlock(raw_rwlock_t *rw)
30615 + {
30616 +- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
30617 ++ asm volatile(LOCK_PREFIX "incl %0\n"
30618 ++
30619 ++#ifdef CONFIG_PAX_REFCOUNT
30620 ++#ifdef CONFIG_X86_32
30621 ++ "into\n0:\n"
30622 ++#else
30623 ++ "jno 0f\n"
30624 ++ "int $4\n0:\n"
30625 ++#endif
30626 ++ ".pushsection .fixup,\"ax\"\n"
30627 ++ "1:\n"
30628 ++ LOCK_PREFIX "decl %0\n"
30629 ++ "jmp 0b\n"
30630 ++ ".popsection\n"
30631 ++ _ASM_EXTABLE(0b, 1b)
30632 ++#endif
30633 ++
30634 ++ :"+m" (rw->lock) : : "memory");
30635 + }
30636 +
30637 + static inline void __raw_write_unlock(raw_rwlock_t *rw)
30638 + {
30639 +- asm volatile(LOCK_PREFIX "addl %1, %0"
30640 ++ asm volatile(LOCK_PREFIX "addl %1, %0\n"
30641 ++
30642 ++#ifdef CONFIG_PAX_REFCOUNT
30643 ++#ifdef CONFIG_X86_32
30644 ++ "into\n0:\n"
30645 ++#else
30646 ++ "jno 0f\n"
30647 ++ "int $4\n0:\n"
30648 ++#endif
30649 ++ ".pushsection .fixup,\"ax\"\n"
30650 ++ "1:\n"
30651 ++ LOCK_PREFIX "subl %1,%0\n"
30652 ++ "jmp 0b\n"
30653 ++ ".popsection\n"
30654 ++ _ASM_EXTABLE(0b, 1b)
30655 ++#endif
30656 ++
30657 + : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
30658 + }
30659 +
30660 +diff -urNp linux-2.6.27.10/include/asm-x86/system.h linux-2.6.27.10/include/asm-x86/system.h
30661 +--- linux-2.6.27.10/include/asm-x86/system.h 2008-11-07 12:55:34.000000000 -0500
30662 ++++ linux-2.6.27.10/include/asm-x86/system.h 2008-11-18 03:38:45.000000000 -0500
30663 +@@ -92,6 +92,8 @@ do { \
30664 + ".globl thread_return\n" \
30665 + "thread_return:\n\t" \
30666 + "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
30667 ++ "movq %P[task_canary](%%rsi),%%r8\n\t" \
30668 ++ "movq %%r8,%%gs:%P[pda_canary]\n\t" \
30669 + "movq %P[thread_info](%%rsi),%%r8\n\t" \
30670 + LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
30671 + "movq %%rax,%%rdi\n\t" \
30672 +@@ -103,7 +105,9 @@ do { \
30673 + [ti_flags] "i" (offsetof(struct thread_info, flags)), \
30674 + [tif_fork] "i" (TIF_FORK), \
30675 + [thread_info] "i" (offsetof(struct task_struct, stack)), \
30676 +- [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
30677 ++ [task_canary] "i" (offsetof(struct task_struct, stack_canary)), \
30678 ++ [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \
30679 ++ [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\
30680 + : "memory", "cc" __EXTRA_CLOBBER)
30681 + #endif
30682 +
30683 +@@ -166,7 +170,7 @@ static inline unsigned long get_limit(un
30684 + {
30685 + unsigned long __limit;
30686 + asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
30687 +- return __limit + 1;
30688 ++ return __limit;
30689 + }
30690 +
30691 + static inline void native_clts(void)
30692 +@@ -292,6 +296,21 @@ static inline void native_wbinvd(void)
30693 +
30694 + #define stts() write_cr0(read_cr0() | X86_CR0_TS)
30695 +
30696 ++#define pax_open_kernel(cr0) \
30697 ++do { \
30698 ++ typecheck(unsigned long, cr0); \
30699 ++ preempt_disable(); \
30700 ++ cr0 = read_cr0(); \
30701 ++ write_cr0(cr0 & ~X86_CR0_WP); \
30702 ++} while (0)
30703 ++
30704 ++#define pax_close_kernel(cr0) \
30705 ++do { \
30706 ++ typecheck(unsigned long, cr0); \
30707 ++ write_cr0(cr0); \
30708 ++ preempt_enable_no_resched(); \
30709 ++} while (0)
30710 ++
30711 + #endif /* __KERNEL__ */
30712 +
30713 + static inline void clflush(volatile void *__p)
30714 +@@ -306,7 +325,7 @@ void enable_hlt(void);
30715 +
30716 + void cpu_idle_wait(void);
30717 +
30718 +-extern unsigned long arch_align_stack(unsigned long sp);
30719 ++#define arch_align_stack(x) ((x) & ~0xfUL)
30720 + extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
30721 +
30722 + void default_idle(void);
30723 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess_64.h linux-2.6.27.10/include/asm-x86/uaccess_64.h
30724 +--- linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-07 12:55:34.000000000 -0500
30725 ++++ linux-2.6.27.10/include/asm-x86/uaccess_64.h 2008-11-18 03:38:45.000000000 -0500
30726 +@@ -10,6 +10,8 @@
30727 + #include <linux/lockdep.h>
30728 + #include <asm/page.h>
30729 +
30730 ++#define set_fs(x) (current_thread_info()->addr_limit = (x))
30731 ++
30732 + /*
30733 + * Copy To/From Userspace
30734 + */
30735 +diff -urNp linux-2.6.27.10/include/asm-x86/uaccess.h linux-2.6.27.10/include/asm-x86/uaccess.h
30736 +--- linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-07 12:55:34.000000000 -0500
30737 ++++ linux-2.6.27.10/include/asm-x86/uaccess.h 2008-11-18 03:38:45.000000000 -0500
30738 +@@ -10,6 +10,7 @@
30739 + #include <linux/string.h>
30740 + #include <asm/asm.h>
30741 + #include <asm/page.h>
30742 ++#include <asm/segment.h>
30743 +
30744 + #define VERIFY_READ 0
30745 + #define VERIFY_WRITE 1
30746 +@@ -29,7 +30,12 @@
30747 +
30748 + #define get_ds() (KERNEL_DS)
30749 + #define get_fs() (current_thread_info()->addr_limit)
30750 ++#ifdef CONFIG_X86_32
30751 ++void __set_fs(mm_segment_t x, int cpu);
30752 ++void set_fs(mm_segment_t x);
30753 ++#else
30754 + #define set_fs(x) (current_thread_info()->addr_limit = (x))
30755 ++#endif
30756 +
30757 + #define segment_eq(a, b) ((a).seg == (b).seg)
30758 +
30759 +@@ -97,6 +103,7 @@ struct exception_table_entry {
30760 + };
30761 +
30762 + extern int fixup_exception(struct pt_regs *regs);
30763 ++#define ARCH_HAS_SORT_EXTABLE
30764 +
30765 + /*
30766 + * These are the main single-value transfer routines. They automatically
30767 +@@ -186,9 +193,12 @@ extern int __get_user_bad(void);
30768 +
30769 + #ifdef CONFIG_X86_32
30770 + #define __put_user_u64(x, addr, err) \
30771 +- asm volatile("1: movl %%eax,0(%2)\n" \
30772 +- "2: movl %%edx,4(%2)\n" \
30773 ++ asm volatile(" movw %w5,%%ds\n" \
30774 ++ "1: movl %%eax,%%ds:0(%2)\n" \
30775 ++ "2: movl %%edx,%%ds:4(%2)\n" \
30776 + "3:\n" \
30777 ++ " pushl %%ss\n" \
30778 ++ " popl %%ds\n" \
30779 + ".section .fixup,\"ax\"\n" \
30780 + "4: movl %3,%0\n" \
30781 + " jmp 3b\n" \
30782 +@@ -196,7 +206,8 @@ extern int __get_user_bad(void);
30783 + _ASM_EXTABLE(1b, 4b) \
30784 + _ASM_EXTABLE(2b, 4b) \
30785 + : "=r" (err) \
30786 +- : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
30787 ++ : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err), \
30788 ++ "r"(__USER_DS))
30789 +
30790 + #define __put_user_x8(x, ptr, __ret_pu) \
30791 + asm volatile("call __put_user_8" : "=a" (__ret_pu) \
30792 +@@ -336,6 +347,22 @@ do { \
30793 + } \
30794 + } while (0)
30795 +
30796 ++#ifdef CONFIG_X86_32
30797 ++#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
30798 ++ asm volatile(" movw %w5,%%ds\n" \
30799 ++ "1: mov"itype" %%ds:%2,%"rtype"1\n" \
30800 ++ "2:\n" \
30801 ++ " pushl %%ss\n" \
30802 ++ " popl %%ds\n" \
30803 ++ ".section .fixup,\"ax\"\n" \
30804 ++ "3: movl %3,%0\n" \
30805 ++ " xor"itype" %"rtype"1,%"rtype"1\n" \
30806 ++ " jmp 2b\n" \
30807 ++ ".previous\n" \
30808 ++ _ASM_EXTABLE(1b, 3b) \
30809 ++ : "=r" (err), ltype (x) \
30810 ++ : "m" (__m(addr)), "i" (errret), "0" (err), "r"(__USER_DS))
30811 ++#else
30812 + #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
30813 + asm volatile("1: mov"itype" %2,%"rtype"1\n" \
30814 + "2:\n" \
30815 +@@ -347,6 +374,7 @@ do { \
30816 + _ASM_EXTABLE(1b, 3b) \
30817 + : "=r" (err), ltype(x) \
30818 + : "m" (__m(addr)), "i" (errret), "0" (err))
30819 ++#endif
30820 +
30821 + #define __put_user_nocheck(x, ptr, size) \
30822 + ({ \
30823 +@@ -373,6 +401,22 @@ struct __large_struct { unsigned long bu
30824 + * we do not write to any memory gcc knows about, so there are no
30825 + * aliasing issues.
30826 + */
30827 ++#ifdef CONFIG_X86_32
30828 ++#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
30829 ++ asm volatile(" movw %w5,%%ds\n" \
30830 ++ "1: mov"itype" %"rtype"1,%%ds:%2\n" \
30831 ++ "2:\n" \
30832 ++ " pushl %%ss\n" \
30833 ++ " popl %%ds\n" \
30834 ++ ".section .fixup,\"ax\"\n" \
30835 ++ "3: movl %3,%0\n" \
30836 ++ " jmp 2b\n" \
30837 ++ ".previous\n" \
30838 ++ _ASM_EXTABLE(1b, 3b) \
30839 ++ : "=r"(err) \
30840 ++ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err),\
30841 ++ "r"(__USER_DS))
30842 ++#else
30843 + #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
30844 + asm volatile("1: mov"itype" %"rtype"1,%2\n" \
30845 + "2:\n" \
30846 +@@ -383,6 +427,7 @@ struct __large_struct { unsigned long bu
30847 + _ASM_EXTABLE(1b, 3b) \
30848 + : "=r"(err) \
30849 + : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
30850 ++#endif
30851 + /**
30852 + * __get_user: - Get a simple variable from user space, with less checking.
30853 + * @x: Variable to store result.
30854 +@@ -447,6 +492,7 @@ extern struct movsl_mask {
30855 + # include "uaccess_32.h"
30856 + #else
30857 + # define ARCH_HAS_SEARCH_EXTABLE
30858 ++# define ARCH_HAS_SORT_EXTABLE
30859 + # include "uaccess_64.h"
30860 + #endif
30861 +
30862 +diff -urNp linux-2.6.27.10/include/asm-xtensa/kmap_types.h linux-2.6.27.10/include/asm-xtensa/kmap_types.h
30863 +--- linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-07 12:55:34.000000000 -0500
30864 ++++ linux-2.6.27.10/include/asm-xtensa/kmap_types.h 2008-11-18 03:38:45.000000000 -0500
30865 +@@ -25,6 +25,7 @@ enum km_type {
30866 + KM_IRQ1,
30867 + KM_SOFTIRQ0,
30868 + KM_SOFTIRQ1,
30869 ++ KM_CLEARPAGE,
30870 + KM_TYPE_NR
30871 + };
30872 +
30873 +diff -urNp linux-2.6.27.10/include/drm/drm_pciids.h linux-2.6.27.10/include/drm/drm_pciids.h
30874 +--- linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-07 12:55:34.000000000 -0500
30875 ++++ linux-2.6.27.10/include/drm/drm_pciids.h 2008-11-18 03:38:45.000000000 -0500
30876 +@@ -237,7 +237,7 @@
30877 + {0x1002, 0x7835, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS300|RADEON_IS_IGP|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \
30878 + {0x1002, 0x791e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
30879 + {0x1002, 0x791f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS690|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
30880 +- {0, 0, 0}
30881 ++ {0, 0, 0, 0, 0, 0}
30882 +
30883 + #define r128_PCI_IDS \
30884 + {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30885 +@@ -277,14 +277,14 @@
30886 + {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30887 + {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30888 + {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30889 +- {0, 0, 0}
30890 ++ {0, 0, 0, 0, 0, 0}
30891 +
30892 + #define mga_PCI_IDS \
30893 + {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
30894 + {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
30895 + {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
30896 + {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
30897 +- {0, 0, 0}
30898 ++ {0, 0, 0, 0, 0, 0}
30899 +
30900 + #define mach64_PCI_IDS \
30901 + {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30902 +@@ -307,7 +307,7 @@
30903 + {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30904 + {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30905 + {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30906 +- {0, 0, 0}
30907 ++ {0, 0, 0, 0, 0, 0}
30908 +
30909 + #define sisdrv_PCI_IDS \
30910 + {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30911 +@@ -318,7 +318,7 @@
30912 + {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30913 + {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
30914 + {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
30915 +- {0, 0, 0}
30916 ++ {0, 0, 0, 0, 0, 0}
30917 +
30918 + #define tdfx_PCI_IDS \
30919 + {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30920 +@@ -327,7 +327,7 @@
30921 + {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30922 + {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30923 + {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30924 +- {0, 0, 0}
30925 ++ {0, 0, 0, 0, 0, 0}
30926 +
30927 + #define viadrv_PCI_IDS \
30928 + {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30929 +@@ -339,25 +339,25 @@
30930 + {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30931 + {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
30932 + {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
30933 +- {0, 0, 0}
30934 ++ {0, 0, 0, 0, 0, 0}
30935 +
30936 + #define i810_PCI_IDS \
30937 + {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30938 + {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30939 + {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30940 + {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30941 +- {0, 0, 0}
30942 ++ {0, 0, 0, 0, 0, 0}
30943 +
30944 + #define i830_PCI_IDS \
30945 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30946 + {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30947 + {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30948 + {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30949 +- {0, 0, 0}
30950 ++ {0, 0, 0, 0, 0, 0}
30951 +
30952 + #define gamma_PCI_IDS \
30953 + {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30954 +- {0, 0, 0}
30955 ++ {0, 0, 0, 0, 0, 0}
30956 +
30957 + #define savage_PCI_IDS \
30958 + {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
30959 +@@ -383,10 +383,10 @@
30960 + {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
30961 + {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
30962 + {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
30963 +- {0, 0, 0}
30964 ++ {0, 0, 0, 0, 0, 0}
30965 +
30966 + #define ffb_PCI_IDS \
30967 +- {0, 0, 0}
30968 ++ {0, 0, 0, 0, 0, 0}
30969 +
30970 + #define i915_PCI_IDS \
30971 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30972 +@@ -412,4 +412,4 @@
30973 + {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30974 + {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30975 + {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
30976 +- {0, 0, 0}
30977 ++ {0, 0, 0, 0, 0, 0}
30978 +diff -urNp linux-2.6.27.10/include/linux/a.out.h linux-2.6.27.10/include/linux/a.out.h
30979 +--- linux-2.6.27.10/include/linux/a.out.h 2008-11-07 12:55:34.000000000 -0500
30980 ++++ linux-2.6.27.10/include/linux/a.out.h 2008-11-18 03:38:45.000000000 -0500
30981 +@@ -39,6 +39,14 @@ enum machine_type {
30982 + M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
30983 + };
30984 +
30985 ++/* Constants for the N_FLAGS field */
30986 ++#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
30987 ++#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
30988 ++#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
30989 ++#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
30990 ++/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
30991 ++#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
30992 ++
30993 + #if !defined (N_MAGIC)
30994 + #define N_MAGIC(exec) ((exec).a_info & 0xffff)
30995 + #endif
30996 +diff -urNp linux-2.6.27.10/include/linux/binfmts.h linux-2.6.27.10/include/linux/binfmts.h
30997 +--- linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:16:52.000000000 -0500
30998 ++++ linux-2.6.27.10/include/linux/binfmts.h 2008-12-21 01:13:46.000000000 -0500
30999 +@@ -71,6 +71,7 @@ struct linux_binfmt {
31000 + int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
31001 + int (*load_shlib)(struct file *);
31002 + int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
31003 ++ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
31004 + unsigned long min_coredump; /* minimal dump size */
31005 + int hasvdso;
31006 + };
31007 +diff -urNp linux-2.6.27.10/include/linux/cache.h linux-2.6.27.10/include/linux/cache.h
31008 +--- linux-2.6.27.10/include/linux/cache.h 2008-11-07 12:55:34.000000000 -0500
31009 ++++ linux-2.6.27.10/include/linux/cache.h 2008-11-18 03:38:45.000000000 -0500
31010 +@@ -16,6 +16,10 @@
31011 + #define __read_mostly
31012 + #endif
31013 +
31014 ++#ifndef __read_only
31015 ++#define __read_only __read_mostly
31016 ++#endif
31017 ++
31018 + #ifndef ____cacheline_aligned
31019 + #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
31020 + #endif
31021 +diff -urNp linux-2.6.27.10/include/linux/capability.h linux-2.6.27.10/include/linux/capability.h
31022 +--- linux-2.6.27.10/include/linux/capability.h 2008-11-07 12:55:34.000000000 -0500
31023 ++++ linux-2.6.27.10/include/linux/capability.h 2008-11-18 03:38:45.000000000 -0500
31024 +@@ -516,6 +516,7 @@ kernel_cap_t cap_set_effective(const ker
31025 + #define has_capability(t, cap) (security_capable((t), (cap)) == 0)
31026 +
31027 + extern int capable(int cap);
31028 ++int capable_nolog(int cap);
31029 +
31030 + #endif /* __KERNEL__ */
31031 +
31032 +diff -urNp linux-2.6.27.10/include/linux/cpumask.h linux-2.6.27.10/include/linux/cpumask.h
31033 +--- linux-2.6.27.10/include/linux/cpumask.h 2008-11-07 12:55:34.000000000 -0500
31034 ++++ linux-2.6.27.10/include/linux/cpumask.h 2008-11-18 03:38:45.000000000 -0500
31035 +@@ -139,7 +139,6 @@
31036 + #include <linux/bitmap.h>
31037 +
31038 + typedef struct { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
31039 +-extern cpumask_t _unused_cpumask_arg_;
31040 +
31041 + #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
31042 + static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
31043 +diff -urNp linux-2.6.27.10/include/linux/elf.h linux-2.6.27.10/include/linux/elf.h
31044 +--- linux-2.6.27.10/include/linux/elf.h 2008-11-07 12:55:34.000000000 -0500
31045 ++++ linux-2.6.27.10/include/linux/elf.h 2008-12-21 00:44:29.000000000 -0500
31046 +@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
31047 + #define PT_GNU_EH_FRAME 0x6474e550
31048 +
31049 + #define PT_GNU_STACK (PT_LOOS + 0x474e551)
31050 ++#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
31051 ++
31052 ++#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
31053 ++
31054 ++/* Constants for the e_flags field */
31055 ++#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
31056 ++#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
31057 ++#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
31058 ++#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
31059 ++/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
31060 ++#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
31061 +
31062 + /* These constants define the different elf file types */
31063 + #define ET_NONE 0
31064 +@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
31065 + #define DT_DEBUG 21
31066 + #define DT_TEXTREL 22
31067 + #define DT_JMPREL 23
31068 ++#define DT_FLAGS 30
31069 ++ #define DF_TEXTREL 0x00000004
31070 + #define DT_ENCODING 32
31071 + #define OLD_DT_LOOS 0x60000000
31072 + #define DT_LOOS 0x6000000d
31073 +@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
31074 + #define PF_W 0x2
31075 + #define PF_X 0x1
31076 +
31077 ++#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
31078 ++#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
31079 ++#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
31080 ++#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
31081 ++#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
31082 ++#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
31083 ++/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
31084 ++/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
31085 ++#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
31086 ++#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
31087 ++#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
31088 ++#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
31089 ++
31090 + typedef struct elf32_phdr{
31091 + Elf32_Word p_type;
31092 + Elf32_Off p_offset;
31093 +@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
31094 + #define EI_OSABI 7
31095 + #define EI_PAD 8
31096 +
31097 ++#define EI_PAX 14
31098 ++
31099 + #define ELFMAG0 0x7f /* EI_MAG */
31100 + #define ELFMAG1 'E'
31101 + #define ELFMAG2 'L'
31102 +@@ -383,6 +411,7 @@ extern Elf32_Dyn _DYNAMIC [];
31103 + #define elf_phdr elf32_phdr
31104 + #define elf_note elf32_note
31105 + #define elf_addr_t Elf32_Off
31106 ++#define elf_dyn Elf32_Dyn
31107 +
31108 + #else
31109 +
31110 +@@ -391,6 +420,7 @@ extern Elf64_Dyn _DYNAMIC [];
31111 + #define elf_phdr elf64_phdr
31112 + #define elf_note elf64_note
31113 + #define elf_addr_t Elf64_Off
31114 ++#define elf_dyn Elf64_Dyn
31115 +
31116 + #endif
31117 +
31118 +diff -urNp linux-2.6.27.10/include/linux/gracl.h linux-2.6.27.10/include/linux/gracl.h
31119 +--- linux-2.6.27.10/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
31120 ++++ linux-2.6.27.10/include/linux/gracl.h 2008-11-18 03:38:45.000000000 -0500
31121 +@@ -0,0 +1,318 @@
31122 ++#ifndef GR_ACL_H
31123 ++#define GR_ACL_H
31124 ++
31125 ++#include <linux/grdefs.h>
31126 ++#include <linux/resource.h>
31127 ++#include <linux/capability.h>
31128 ++#include <linux/dcache.h>
31129 ++#include <asm/resource.h>
31130 ++
31131 ++/* Major status information */
31132 ++
31133 ++#define GR_VERSION "grsecurity 2.1.12"
31134 ++#define GRSECURITY_VERSION 0x2112
31135 ++
31136 ++enum {
31137 ++
31138 ++ SHUTDOWN = 0,
31139 ++ ENABLE = 1,
31140 ++ SPROLE = 2,
31141 ++ RELOAD = 3,
31142 ++ SEGVMOD = 4,
31143 ++ STATUS = 5,
31144 ++ UNSPROLE = 6,
31145 ++ PASSSET = 7,
31146 ++ SPROLEPAM = 8
31147 ++};
31148 ++
31149 ++/* Password setup definitions
31150 ++ * kernel/grhash.c */
31151 ++enum {
31152 ++ GR_PW_LEN = 128,
31153 ++ GR_SALT_LEN = 16,
31154 ++ GR_SHA_LEN = 32,
31155 ++};
31156 ++
31157 ++enum {
31158 ++ GR_SPROLE_LEN = 64,
31159 ++};
31160 ++
31161 ++#define GR_NLIMITS (RLIMIT_LOCKS + 2)
31162 ++
31163 ++/* Begin Data Structures */
31164 ++
31165 ++struct sprole_pw {
31166 ++ unsigned char *rolename;
31167 ++ unsigned char salt[GR_SALT_LEN];
31168 ++ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
31169 ++};
31170 ++
31171 ++struct name_entry {
31172 ++ __u32 key;
31173 ++ ino_t inode;
31174 ++ dev_t device;
31175 ++ char *name;
31176 ++ __u16 len;
31177 ++ __u8 deleted;
31178 ++ struct name_entry *prev;
31179 ++ struct name_entry *next;
31180 ++};
31181 ++
31182 ++struct inodev_entry {
31183 ++ struct name_entry *nentry;
31184 ++ struct inodev_entry *prev;
31185 ++ struct inodev_entry *next;
31186 ++};
31187 ++
31188 ++struct acl_role_db {
31189 ++ struct acl_role_label **r_hash;
31190 ++ __u32 r_size;
31191 ++};
31192 ++
31193 ++struct inodev_db {
31194 ++ struct inodev_entry **i_hash;
31195 ++ __u32 i_size;
31196 ++};
31197 ++
31198 ++struct name_db {
31199 ++ struct name_entry **n_hash;
31200 ++ __u32 n_size;
31201 ++};
31202 ++
31203 ++struct crash_uid {
31204 ++ uid_t uid;
31205 ++ unsigned long expires;
31206 ++};
31207 ++
31208 ++struct gr_hash_struct {
31209 ++ void **table;
31210 ++ void **nametable;
31211 ++ void *first;
31212 ++ __u32 table_size;
31213 ++ __u32 used_size;
31214 ++ int type;
31215 ++};
31216 ++
31217 ++/* Userspace Grsecurity ACL data structures */
31218 ++
31219 ++struct acl_subject_label {
31220 ++ char *filename;
31221 ++ ino_t inode;
31222 ++ dev_t device;
31223 ++ __u32 mode;
31224 ++ kernel_cap_t cap_mask;
31225 ++ kernel_cap_t cap_lower;
31226 ++
31227 ++ struct rlimit res[GR_NLIMITS];
31228 ++ __u16 resmask;
31229 ++
31230 ++ __u8 user_trans_type;
31231 ++ __u8 group_trans_type;
31232 ++ uid_t *user_transitions;
31233 ++ gid_t *group_transitions;
31234 ++ __u16 user_trans_num;
31235 ++ __u16 group_trans_num;
31236 ++
31237 ++ __u32 ip_proto[8];
31238 ++ __u32 ip_type;
31239 ++ struct acl_ip_label **ips;
31240 ++ __u32 ip_num;
31241 ++
31242 ++ __u32 crashes;
31243 ++ unsigned long expires;
31244 ++
31245 ++ struct acl_subject_label *parent_subject;
31246 ++ struct gr_hash_struct *hash;
31247 ++ struct acl_subject_label *prev;
31248 ++ struct acl_subject_label *next;
31249 ++
31250 ++ struct acl_object_label **obj_hash;
31251 ++ __u32 obj_hash_size;
31252 ++ __u16 pax_flags;
31253 ++};
31254 ++
31255 ++struct role_allowed_ip {
31256 ++ __u32 addr;
31257 ++ __u32 netmask;
31258 ++
31259 ++ struct role_allowed_ip *prev;
31260 ++ struct role_allowed_ip *next;
31261 ++};
31262 ++
31263 ++struct role_transition {
31264 ++ char *rolename;
31265 ++
31266 ++ struct role_transition *prev;
31267 ++ struct role_transition *next;
31268 ++};
31269 ++
31270 ++struct acl_role_label {
31271 ++ char *rolename;
31272 ++ uid_t uidgid;
31273 ++ __u16 roletype;
31274 ++
31275 ++ __u16 auth_attempts;
31276 ++ unsigned long expires;
31277 ++
31278 ++ struct acl_subject_label *root_label;
31279 ++ struct gr_hash_struct *hash;
31280 ++
31281 ++ struct acl_role_label *prev;
31282 ++ struct acl_role_label *next;
31283 ++
31284 ++ struct role_transition *transitions;
31285 ++ struct role_allowed_ip *allowed_ips;
31286 ++ uid_t *domain_children;
31287 ++ __u16 domain_child_num;
31288 ++
31289 ++ struct acl_subject_label **subj_hash;
31290 ++ __u32 subj_hash_size;
31291 ++};
31292 ++
31293 ++struct user_acl_role_db {
31294 ++ struct acl_role_label **r_table;
31295 ++ __u32 num_pointers; /* Number of allocations to track */
31296 ++ __u32 num_roles; /* Number of roles */
31297 ++ __u32 num_domain_children; /* Number of domain children */
31298 ++ __u32 num_subjects; /* Number of subjects */
31299 ++ __u32 num_objects; /* Number of objects */
31300 ++};
31301 ++
31302 ++struct acl_object_label {
31303 ++ char *filename;
31304 ++ ino_t inode;
31305 ++ dev_t device;
31306 ++ __u32 mode;
31307 ++
31308 ++ struct acl_subject_label *nested;
31309 ++ struct acl_object_label *globbed;
31310 ++
31311 ++ /* next two structures not used */
31312 ++
31313 ++ struct acl_object_label *prev;
31314 ++ struct acl_object_label *next;
31315 ++};
31316 ++
31317 ++struct acl_ip_label {
31318 ++ char *iface;
31319 ++ __u32 addr;
31320 ++ __u32 netmask;
31321 ++ __u16 low, high;
31322 ++ __u8 mode;
31323 ++ __u32 type;
31324 ++ __u32 proto[8];
31325 ++
31326 ++ /* next two structures not used */
31327 ++
31328 ++ struct acl_ip_label *prev;
31329 ++ struct acl_ip_label *next;
31330 ++};
31331 ++
31332 ++struct gr_arg {
31333 ++ struct user_acl_role_db role_db;
31334 ++ unsigned char pw[GR_PW_LEN];
31335 ++ unsigned char salt[GR_SALT_LEN];
31336 ++ unsigned char sum[GR_SHA_LEN];
31337 ++ unsigned char sp_role[GR_SPROLE_LEN];
31338 ++ struct sprole_pw *sprole_pws;
31339 ++ dev_t segv_device;
31340 ++ ino_t segv_inode;
31341 ++ uid_t segv_uid;
31342 ++ __u16 num_sprole_pws;
31343 ++ __u16 mode;
31344 ++};
31345 ++
31346 ++struct gr_arg_wrapper {
31347 ++ struct gr_arg *arg;
31348 ++ __u32 version;
31349 ++ __u32 size;
31350 ++};
31351 ++
31352 ++struct subject_map {
31353 ++ struct acl_subject_label *user;
31354 ++ struct acl_subject_label *kernel;
31355 ++ struct subject_map *prev;
31356 ++ struct subject_map *next;
31357 ++};
31358 ++
31359 ++struct acl_subj_map_db {
31360 ++ struct subject_map **s_hash;
31361 ++ __u32 s_size;
31362 ++};
31363 ++
31364 ++/* End Data Structures Section */
31365 ++
31366 ++/* Hash functions generated by empirical testing by Brad Spengler
31367 ++ Makes good use of the low bits of the inode. Generally 0-1 times
31368 ++ in loop for successful match. 0-3 for unsuccessful match.
31369 ++ Shift/add algorithm with modulus of table size and an XOR*/
31370 ++
31371 ++static __inline__ unsigned int
31372 ++rhash(const uid_t uid, const __u16 type, const unsigned int sz)
31373 ++{
31374 ++ return (((uid << type) + (uid ^ type)) % sz);
31375 ++}
31376 ++
31377 ++ static __inline__ unsigned int
31378 ++shash(const struct acl_subject_label *userp, const unsigned int sz)
31379 ++{
31380 ++ return ((const unsigned long)userp % sz);
31381 ++}
31382 ++
31383 ++static __inline__ unsigned int
31384 ++fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
31385 ++{
31386 ++ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
31387 ++}
31388 ++
31389 ++static __inline__ unsigned int
31390 ++nhash(const char *name, const __u16 len, const unsigned int sz)
31391 ++{
31392 ++ return full_name_hash(name, len) % sz;
31393 ++}
31394 ++
31395 ++#define FOR_EACH_ROLE_START(role,iter) \
31396 ++ role = NULL; \
31397 ++ iter = 0; \
31398 ++ while (iter < acl_role_set.r_size) { \
31399 ++ if (role == NULL) \
31400 ++ role = acl_role_set.r_hash[iter]; \
31401 ++ if (role == NULL) { \
31402 ++ iter++; \
31403 ++ continue; \
31404 ++ }
31405 ++
31406 ++#define FOR_EACH_ROLE_END(role,iter) \
31407 ++ role = role->next; \
31408 ++ if (role == NULL) \
31409 ++ iter++; \
31410 ++ }
31411 ++
31412 ++#define FOR_EACH_SUBJECT_START(role,subj,iter) \
31413 ++ subj = NULL; \
31414 ++ iter = 0; \
31415 ++ while (iter < role->subj_hash_size) { \
31416 ++ if (subj == NULL) \
31417 ++ subj = role->subj_hash[iter]; \
31418 ++ if (subj == NULL) { \
31419 ++ iter++; \
31420 ++ continue; \
31421 ++ }
31422 ++
31423 ++#define FOR_EACH_SUBJECT_END(subj,iter) \
31424 ++ subj = subj->next; \
31425 ++ if (subj == NULL) \
31426 ++ iter++; \
31427 ++ }
31428 ++
31429 ++
31430 ++#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
31431 ++ subj = role->hash->first; \
31432 ++ while (subj != NULL) {
31433 ++
31434 ++#define FOR_EACH_NESTED_SUBJECT_END(subj) \
31435 ++ subj = subj->next; \
31436 ++ }
31437 ++
31438 ++#endif
31439 ++
31440 +diff -urNp linux-2.6.27.10/include/linux/gralloc.h linux-2.6.27.10/include/linux/gralloc.h
31441 +--- linux-2.6.27.10/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
31442 ++++ linux-2.6.27.10/include/linux/gralloc.h 2008-11-18 03:38:45.000000000 -0500
31443 +@@ -0,0 +1,8 @@
31444 ++#ifndef __GRALLOC_H
31445 ++#define __GRALLOC_H
31446 ++
31447 ++void acl_free_all(void);
31448 ++int acl_alloc_stack_init(unsigned long size);
31449 ++void *acl_alloc(unsigned long len);
31450 ++
31451 ++#endif
31452 +diff -urNp linux-2.6.27.10/include/linux/grdefs.h linux-2.6.27.10/include/linux/grdefs.h
31453 +--- linux-2.6.27.10/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
31454 ++++ linux-2.6.27.10/include/linux/grdefs.h 2008-11-18 03:38:45.000000000 -0500
31455 +@@ -0,0 +1,131 @@
31456 ++#ifndef GRDEFS_H
31457 ++#define GRDEFS_H
31458 ++
31459 ++/* Begin grsecurity status declarations */
31460 ++
31461 ++enum {
31462 ++ GR_READY = 0x01,
31463 ++ GR_STATUS_INIT = 0x00 // disabled state
31464 ++};
31465 ++
31466 ++/* Begin ACL declarations */
31467 ++
31468 ++/* Role flags */
31469 ++
31470 ++enum {
31471 ++ GR_ROLE_USER = 0x0001,
31472 ++ GR_ROLE_GROUP = 0x0002,
31473 ++ GR_ROLE_DEFAULT = 0x0004,
31474 ++ GR_ROLE_SPECIAL = 0x0008,
31475 ++ GR_ROLE_AUTH = 0x0010,
31476 ++ GR_ROLE_NOPW = 0x0020,
31477 ++ GR_ROLE_GOD = 0x0040,
31478 ++ GR_ROLE_LEARN = 0x0080,
31479 ++ GR_ROLE_TPE = 0x0100,
31480 ++ GR_ROLE_DOMAIN = 0x0200,
31481 ++ GR_ROLE_PAM = 0x0400
31482 ++};
31483 ++
31484 ++/* ACL Subject and Object mode flags */
31485 ++enum {
31486 ++ GR_DELETED = 0x80000000
31487 ++};
31488 ++
31489 ++/* ACL Object-only mode flags */
31490 ++enum {
31491 ++ GR_READ = 0x00000001,
31492 ++ GR_APPEND = 0x00000002,
31493 ++ GR_WRITE = 0x00000004,
31494 ++ GR_EXEC = 0x00000008,
31495 ++ GR_FIND = 0x00000010,
31496 ++ GR_INHERIT = 0x00000020,
31497 ++ GR_SETID = 0x00000040,
31498 ++ GR_CREATE = 0x00000080,
31499 ++ GR_DELETE = 0x00000100,
31500 ++ GR_LINK = 0x00000200,
31501 ++ GR_AUDIT_READ = 0x00000400,
31502 ++ GR_AUDIT_APPEND = 0x00000800,
31503 ++ GR_AUDIT_WRITE = 0x00001000,
31504 ++ GR_AUDIT_EXEC = 0x00002000,
31505 ++ GR_AUDIT_FIND = 0x00004000,
31506 ++ GR_AUDIT_INHERIT= 0x00008000,
31507 ++ GR_AUDIT_SETID = 0x00010000,
31508 ++ GR_AUDIT_CREATE = 0x00020000,
31509 ++ GR_AUDIT_DELETE = 0x00040000,
31510 ++ GR_AUDIT_LINK = 0x00080000,
31511 ++ GR_PTRACERD = 0x00100000,
31512 ++ GR_NOPTRACE = 0x00200000,
31513 ++ GR_SUPPRESS = 0x00400000,
31514 ++ GR_NOLEARN = 0x00800000
31515 ++};
31516 ++
31517 ++#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
31518 ++ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
31519 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
31520 ++
31521 ++/* ACL subject-only mode flags */
31522 ++enum {
31523 ++ GR_KILL = 0x00000001,
31524 ++ GR_VIEW = 0x00000002,
31525 ++ GR_PROTECTED = 0x00000004,
31526 ++ GR_LEARN = 0x00000008,
31527 ++ GR_OVERRIDE = 0x00000010,
31528 ++ /* just a placeholder, this mode is only used in userspace */
31529 ++ GR_DUMMY = 0x00000020,
31530 ++ GR_PROTSHM = 0x00000040,
31531 ++ GR_KILLPROC = 0x00000080,
31532 ++ GR_KILLIPPROC = 0x00000100,
31533 ++ /* just a placeholder, this mode is only used in userspace */
31534 ++ GR_NOTROJAN = 0x00000200,
31535 ++ GR_PROTPROCFD = 0x00000400,
31536 ++ GR_PROCACCT = 0x00000800,
31537 ++ GR_RELAXPTRACE = 0x00001000,
31538 ++ GR_NESTED = 0x00002000,
31539 ++ GR_INHERITLEARN = 0x00004000,
31540 ++ GR_PROCFIND = 0x00008000,
31541 ++ GR_POVERRIDE = 0x00010000,
31542 ++ GR_KERNELAUTH = 0x00020000,
31543 ++};
31544 ++
31545 ++enum {
31546 ++ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
31547 ++ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
31548 ++ GR_PAX_ENABLE_MPROTECT = 0x0004,
31549 ++ GR_PAX_ENABLE_RANDMMAP = 0x0008,
31550 ++ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
31551 ++ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
31552 ++ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
31553 ++ GR_PAX_DISABLE_MPROTECT = 0x0400,
31554 ++ GR_PAX_DISABLE_RANDMMAP = 0x0800,
31555 ++ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
31556 ++};
31557 ++
31558 ++enum {
31559 ++ GR_ID_USER = 0x01,
31560 ++ GR_ID_GROUP = 0x02,
31561 ++};
31562 ++
31563 ++enum {
31564 ++ GR_ID_ALLOW = 0x01,
31565 ++ GR_ID_DENY = 0x02,
31566 ++};
31567 ++
31568 ++#define GR_CRASH_RES 11
31569 ++#define GR_UIDTABLE_MAX 500
31570 ++
31571 ++/* begin resource learning section */
31572 ++enum {
31573 ++ GR_RLIM_CPU_BUMP = 60,
31574 ++ GR_RLIM_FSIZE_BUMP = 50000,
31575 ++ GR_RLIM_DATA_BUMP = 10000,
31576 ++ GR_RLIM_STACK_BUMP = 1000,
31577 ++ GR_RLIM_CORE_BUMP = 10000,
31578 ++ GR_RLIM_RSS_BUMP = 500000,
31579 ++ GR_RLIM_NPROC_BUMP = 1,
31580 ++ GR_RLIM_NOFILE_BUMP = 5,
31581 ++ GR_RLIM_MEMLOCK_BUMP = 50000,
31582 ++ GR_RLIM_AS_BUMP = 500000,
31583 ++ GR_RLIM_LOCKS_BUMP = 2
31584 ++};
31585 ++
31586 ++#endif
31587 +diff -urNp linux-2.6.27.10/include/linux/grinternal.h linux-2.6.27.10/include/linux/grinternal.h
31588 +--- linux-2.6.27.10/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
31589 ++++ linux-2.6.27.10/include/linux/grinternal.h 2008-11-18 03:38:45.000000000 -0500
31590 +@@ -0,0 +1,210 @@
31591 ++#ifndef __GRINTERNAL_H
31592 ++#define __GRINTERNAL_H
31593 ++
31594 ++#ifdef CONFIG_GRKERNSEC
31595 ++
31596 ++#include <linux/fs.h>
31597 ++#include <linux/gracl.h>
31598 ++#include <linux/grdefs.h>
31599 ++#include <linux/grmsg.h>
31600 ++
31601 ++void gr_add_learn_entry(const char *fmt, ...);
31602 ++__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
31603 ++ const struct vfsmount *mnt);
31604 ++__u32 gr_check_create(const struct dentry *new_dentry,
31605 ++ const struct dentry *parent,
31606 ++ const struct vfsmount *mnt, const __u32 mode);
31607 ++int gr_check_protected_task(const struct task_struct *task);
31608 ++__u32 to_gr_audit(const __u32 reqmode);
31609 ++int gr_set_acls(const int type);
31610 ++
31611 ++int gr_acl_is_enabled(void);
31612 ++char gr_roletype_to_char(void);
31613 ++
31614 ++void gr_handle_alertkill(struct task_struct *task);
31615 ++char *gr_to_filename(const struct dentry *dentry,
31616 ++ const struct vfsmount *mnt);
31617 ++char *gr_to_filename1(const struct dentry *dentry,
31618 ++ const struct vfsmount *mnt);
31619 ++char *gr_to_filename2(const struct dentry *dentry,
31620 ++ const struct vfsmount *mnt);
31621 ++char *gr_to_filename3(const struct dentry *dentry,
31622 ++ const struct vfsmount *mnt);
31623 ++
31624 ++extern int grsec_enable_link;
31625 ++extern int grsec_enable_fifo;
31626 ++extern int grsec_enable_execve;
31627 ++extern int grsec_enable_shm;
31628 ++extern int grsec_enable_execlog;
31629 ++extern int grsec_enable_signal;
31630 ++extern int grsec_enable_forkfail;
31631 ++extern int grsec_enable_time;
31632 ++extern int grsec_enable_chroot_shmat;
31633 ++extern int grsec_enable_chroot_findtask;
31634 ++extern int grsec_enable_chroot_mount;
31635 ++extern int grsec_enable_chroot_double;
31636 ++extern int grsec_enable_chroot_pivot;
31637 ++extern int grsec_enable_chroot_chdir;
31638 ++extern int grsec_enable_chroot_chmod;
31639 ++extern int grsec_enable_chroot_mknod;
31640 ++extern int grsec_enable_chroot_fchdir;
31641 ++extern int grsec_enable_chroot_nice;
31642 ++extern int grsec_enable_chroot_execlog;
31643 ++extern int grsec_enable_chroot_caps;
31644 ++extern int grsec_enable_chroot_sysctl;
31645 ++extern int grsec_enable_chroot_unix;
31646 ++extern int grsec_enable_tpe;
31647 ++extern int grsec_tpe_gid;
31648 ++extern int grsec_enable_tpe_all;
31649 ++extern int grsec_enable_sidcaps;
31650 ++extern int grsec_enable_socket_all;
31651 ++extern int grsec_socket_all_gid;
31652 ++extern int grsec_enable_socket_client;
31653 ++extern int grsec_socket_client_gid;
31654 ++extern int grsec_enable_socket_server;
31655 ++extern int grsec_socket_server_gid;
31656 ++extern int grsec_audit_gid;
31657 ++extern int grsec_enable_group;
31658 ++extern int grsec_enable_audit_ipc;
31659 ++extern int grsec_enable_audit_textrel;
31660 ++extern int grsec_enable_mount;
31661 ++extern int grsec_enable_chdir;
31662 ++extern int grsec_resource_logging;
31663 ++extern int grsec_lock;
31664 ++
31665 ++extern spinlock_t grsec_alert_lock;
31666 ++extern unsigned long grsec_alert_wtime;
31667 ++extern unsigned long grsec_alert_fyet;
31668 ++
31669 ++extern spinlock_t grsec_audit_lock;
31670 ++
31671 ++extern rwlock_t grsec_exec_file_lock;
31672 ++
31673 ++#define gr_task_fullpath(tsk) (tsk->exec_file ? \
31674 ++ gr_to_filename2(tsk->exec_file->f_path.dentry, \
31675 ++ tsk->exec_file->f_vfsmnt) : "/")
31676 ++
31677 ++#define gr_parent_task_fullpath(tsk) (tsk->parent->exec_file ? \
31678 ++ gr_to_filename3(tsk->parent->exec_file->f_path.dentry, \
31679 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
31680 ++
31681 ++#define gr_task_fullpath0(tsk) (tsk->exec_file ? \
31682 ++ gr_to_filename(tsk->exec_file->f_path.dentry, \
31683 ++ tsk->exec_file->f_vfsmnt) : "/")
31684 ++
31685 ++#define gr_parent_task_fullpath0(tsk) (tsk->parent->exec_file ? \
31686 ++ gr_to_filename1(tsk->parent->exec_file->f_path.dentry, \
31687 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
31688 ++
31689 ++#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && (tsk_a->fs != NULL) && \
31690 ++ ((tsk_a->fs->root.dentry->d_inode->i_sb->s_dev != \
31691 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb->s_dev) || \
31692 ++ (tsk_a->fs->root.dentry->d_inode->i_ino != \
31693 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino)))
31694 ++
31695 ++#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs != NULL) && (tsk_b->fs != NULL) && \
31696 ++ (tsk_a->fs->root.dentry->d_inode->i_sb->s_dev == \
31697 ++ tsk_b->fs->root.dentry->d_inode->i_sb->s_dev) && \
31698 ++ (tsk_a->fs->root.dentry->d_inode->i_ino == \
31699 ++ tsk_b->fs->root.dentry->d_inode->i_ino))
31700 ++
31701 ++#define DEFAULTSECARGS(task) gr_task_fullpath(task), task->comm, \
31702 ++ task->pid, task->uid, \
31703 ++ task->euid, task->gid, task->egid, \
31704 ++ gr_parent_task_fullpath(task), \
31705 ++ task->parent->comm, task->parent->pid, \
31706 ++ task->parent->uid, task->parent->euid, \
31707 ++ task->parent->gid, task->parent->egid
31708 ++
31709 ++#define GR_CHROOT_CAPS {{ \
31710 ++ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
31711 ++ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
31712 ++ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
31713 ++ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
31714 ++ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
31715 ++ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
31716 ++
31717 ++#define security_learn(normal_msg,args...) \
31718 ++({ \
31719 ++ read_lock(&grsec_exec_file_lock); \
31720 ++ gr_add_learn_entry(normal_msg "\n", ## args); \
31721 ++ read_unlock(&grsec_exec_file_lock); \
31722 ++})
31723 ++
31724 ++enum {
31725 ++ GR_DO_AUDIT,
31726 ++ GR_DONT_AUDIT,
31727 ++ GR_DONT_AUDIT_GOOD
31728 ++};
31729 ++
31730 ++enum {
31731 ++ GR_TTYSNIFF,
31732 ++ GR_RBAC,
31733 ++ GR_RBAC_STR,
31734 ++ GR_STR_RBAC,
31735 ++ GR_RBAC_MODE2,
31736 ++ GR_RBAC_MODE3,
31737 ++ GR_FILENAME,
31738 ++ GR_SYSCTL_HIDDEN,
31739 ++ GR_NOARGS,
31740 ++ GR_ONE_INT,
31741 ++ GR_ONE_INT_TWO_STR,
31742 ++ GR_ONE_STR,
31743 ++ GR_STR_INT,
31744 ++ GR_TWO_INT,
31745 ++ GR_THREE_INT,
31746 ++ GR_FIVE_INT_TWO_STR,
31747 ++ GR_TWO_STR,
31748 ++ GR_THREE_STR,
31749 ++ GR_FOUR_STR,
31750 ++ GR_STR_FILENAME,
31751 ++ GR_FILENAME_STR,
31752 ++ GR_FILENAME_TWO_INT,
31753 ++ GR_FILENAME_TWO_INT_STR,
31754 ++ GR_TEXTREL,
31755 ++ GR_PTRACE,
31756 ++ GR_RESOURCE,
31757 ++ GR_CAP,
31758 ++ GR_SIG,
31759 ++ GR_CRASH1,
31760 ++ GR_CRASH2,
31761 ++ GR_PSACCT
31762 ++};
31763 ++
31764 ++#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
31765 ++#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
31766 ++#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
31767 ++#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
31768 ++#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
31769 ++#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
31770 ++#define gr_log_fs_rbac_mode3(audit, msg, dentry, mnt, str1, str2, str3) gr_log_varargs(audit, msg, GR_RBAC_MODE3, dentry, mnt, str1, str2, str3)
31771 ++#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
31772 ++#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
31773 ++#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
31774 ++#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
31775 ++#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
31776 ++#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
31777 ++#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
31778 ++#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
31779 ++#define gr_log_int5_str2(audit, msg, num1, num2, str1, str2) gr_log_varargs(audit, msg, GR_FIVE_INT_TWO_STR, num1, num2, str1, str2)
31780 ++#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
31781 ++#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
31782 ++#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
31783 ++#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
31784 ++#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
31785 ++#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
31786 ++#define gr_log_fs_int2_str(audit, msg, dentry, mnt, num1, num2, str) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT_STR, dentry, mnt, num1, num2, str)
31787 ++#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
31788 ++#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
31789 ++#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
31790 ++#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
31791 ++#define gr_log_sig(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG, task, num)
31792 ++#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
31793 ++#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
31794 ++#define gr_log_procacct(audit, msg, task, num1, num2, num3, num4, num5, num6, num7, num8, num9) gr_log_varargs(audit, msg, GR_PSACCT, task, num1, num2, num3, num4, num5, num6, num7, num8, num9)
31795 ++
31796 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
31797 ++
31798 ++#endif
31799 ++
31800 ++#endif
31801 +diff -urNp linux-2.6.27.10/include/linux/grmsg.h linux-2.6.27.10/include/linux/grmsg.h
31802 +--- linux-2.6.27.10/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
31803 ++++ linux-2.6.27.10/include/linux/grmsg.h 2008-11-18 03:38:45.000000000 -0500
31804 +@@ -0,0 +1,108 @@
31805 ++#define DEFAULTSECMSG "%.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u, parent %.256s[%.16s:%d] uid/euid:%u/%u gid/egid:%u/%u"
31806 ++#define GR_ACL_PROCACCT_MSG "%.256s[%.16s:%d] IP:%u.%u.%u.%u TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u run time:[%ud %uh %um %us] cpu time:[%ud %uh %um %us] %s with exit code %ld, parent %.256s[%.16s:%d] IP:%u.%u.%u.%u TTY:%.64s uid/euid:%u/%u gid/egid:%u/%u"
31807 ++#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
31808 ++#define GR_STOPMOD_MSG "denied modification of module state by "
31809 ++#define GR_IOPERM_MSG "denied use of ioperm() by "
31810 ++#define GR_IOPL_MSG "denied use of iopl() by "
31811 ++#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
31812 ++#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
31813 ++#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
31814 ++#define GR_KMEM_MSG "denied write of /dev/kmem by "
31815 ++#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
31816 ++#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
31817 ++#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
31818 ++#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
31819 ++#define GR_LEARN_AUDIT_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%lu\t%lu\t%.4095s\t%lu\t%u.%u.%u.%u"
31820 ++#define GR_ID_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%c\t%d\t%d\t%d\t%u.%u.%u.%u"
31821 ++#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
31822 ++#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
31823 ++#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
31824 ++#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
31825 ++#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
31826 ++#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
31827 ++#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
31828 ++#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%u.%u.%u.%u %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
31829 ++#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
31830 ++#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
31831 ++#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
31832 ++#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
31833 ++#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
31834 ++#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
31835 ++#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
31836 ++#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
31837 ++#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
31838 ++#define GR_NPROC_MSG "denied overstep of process limit by "
31839 ++#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
31840 ++#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
31841 ++#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
31842 ++#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
31843 ++#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
31844 ++#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
31845 ++#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
31846 ++#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
31847 ++#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
31848 ++#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
31849 ++#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
31850 ++#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
31851 ++#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
31852 ++#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
31853 ++#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
31854 ++#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
31855 ++#define GR_INITF_ACL_MSG "init_variables() failed %s by "
31856 ++#define GR_DISABLED_ACL_MSG "Error loading %s, trying to run kernel with acls disabled. To disable acls at startup use <kernel image name> gracl=off from your boot loader"
31857 ++#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
31858 ++#define GR_SHUTS_ACL_MSG "shutdown auth success for "
31859 ++#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
31860 ++#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
31861 ++#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
31862 ++#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
31863 ++#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
31864 ++#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
31865 ++#define GR_ENABLEF_ACL_MSG "unable to load %s for "
31866 ++#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
31867 ++#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
31868 ++#define GR_RELOADF_ACL_MSG "failed reload of %s for "
31869 ++#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
31870 ++#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
31871 ++#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
31872 ++#define GR_SPROLEF_ACL_MSG "special role %s failure for "
31873 ++#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
31874 ++#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
31875 ++#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for "
31876 ++#define GR_INVMODE_ACL_MSG "invalid mode %d by "
31877 ++#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
31878 ++#define GR_FAILFORK_MSG "failed fork with errno %d by "
31879 ++#define GR_NICE_CHROOT_MSG "denied priority change by "
31880 ++#define GR_UNISIGLOG_MSG "signal %d sent to "
31881 ++#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
31882 ++#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
31883 ++#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
31884 ++#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
31885 ++#define GR_TIME_MSG "time set by "
31886 ++#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
31887 ++#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
31888 ++#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
31889 ++#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
31890 ++#define GR_SOCK2_MSG "denied socket(%d,%.16s,%.16s) by "
31891 ++#define GR_BIND_MSG "denied bind() by "
31892 ++#define GR_CONNECT_MSG "denied connect() by "
31893 ++#define GR_BIND_ACL_MSG "denied bind() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
31894 ++#define GR_CONNECT_ACL_MSG "denied connect() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
31895 ++#define GR_IP_LEARN_MSG "%s\t%u\t%u\t%u\t%.4095s\t%.4095s\t%u.%u.%u.%u\t%u\t%u\t%u\t%u\t%u.%u.%u.%u"
31896 ++#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
31897 ++#define GR_CAP_ACL_MSG "use of %s denied for "
31898 ++#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
31899 ++#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
31900 ++#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
31901 ++#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
31902 ++#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
31903 ++#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
31904 ++#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
31905 ++#define GR_MSGQ_AUDIT_MSG "message queue created by "
31906 ++#define GR_MSGQR_AUDIT_MSG "message queue of uid:%u euid:%u removed by "
31907 ++#define GR_SEM_AUDIT_MSG "semaphore created by "
31908 ++#define GR_SEMR_AUDIT_MSG "semaphore of uid:%u euid:%u removed by "
31909 ++#define GR_SHM_AUDIT_MSG "shared memory of size %d created by "
31910 ++#define GR_SHMR_AUDIT_MSG "shared memory of uid:%u euid:%u removed by "
31911 ++#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
31912 ++#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
31913 +diff -urNp linux-2.6.27.10/include/linux/grsecurity.h linux-2.6.27.10/include/linux/grsecurity.h
31914 +--- linux-2.6.27.10/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
31915 ++++ linux-2.6.27.10/include/linux/grsecurity.h 2008-11-18 03:38:45.000000000 -0500
31916 +@@ -0,0 +1,200 @@
31917 ++#ifndef GR_SECURITY_H
31918 ++#define GR_SECURITY_H
31919 ++#include <linux/fs.h>
31920 ++#include <linux/binfmts.h>
31921 ++#include <linux/gracl.h>
31922 ++
31923 ++/* notify of brain-dead configs */
31924 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
31925 ++#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
31926 ++#endif
31927 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
31928 ++#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
31929 ++#endif
31930 ++#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
31931 ++#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
31932 ++#endif
31933 ++#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
31934 ++#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
31935 ++#endif
31936 ++#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
31937 ++#error "CONFIG_PAX enabled, but no PaX options are enabled."
31938 ++#endif
31939 ++
31940 ++void gr_handle_brute_attach(struct task_struct *p);
31941 ++void gr_handle_brute_check(void);
31942 ++
31943 ++char gr_roletype_to_char(void);
31944 ++
31945 ++int gr_check_user_change(int real, int effective, int fs);
31946 ++int gr_check_group_change(int real, int effective, int fs);
31947 ++
31948 ++void gr_del_task_from_ip_table(struct task_struct *p);
31949 ++
31950 ++int gr_pid_is_chrooted(struct task_struct *p);
31951 ++int gr_handle_chroot_nice(void);
31952 ++int gr_handle_chroot_sysctl(const int op);
31953 ++int gr_handle_chroot_setpriority(struct task_struct *p,
31954 ++ const int niceval);
31955 ++int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
31956 ++int gr_handle_chroot_chroot(const struct dentry *dentry,
31957 ++ const struct vfsmount *mnt);
31958 ++void gr_handle_chroot_caps(struct task_struct *task);
31959 ++void gr_handle_chroot_chdir(struct path *path);
31960 ++int gr_handle_chroot_chmod(const struct dentry *dentry,
31961 ++ const struct vfsmount *mnt, const int mode);
31962 ++int gr_handle_chroot_mknod(const struct dentry *dentry,
31963 ++ const struct vfsmount *mnt, const int mode);
31964 ++int gr_handle_chroot_mount(const struct dentry *dentry,
31965 ++ const struct vfsmount *mnt,
31966 ++ const char *dev_name);
31967 ++int gr_handle_chroot_pivot(void);
31968 ++int gr_handle_chroot_unix(const pid_t pid);
31969 ++
31970 ++int gr_handle_rawio(const struct inode *inode);
31971 ++int gr_handle_nproc(void);
31972 ++
31973 ++void gr_handle_ioperm(void);
31974 ++void gr_handle_iopl(void);
31975 ++
31976 ++int gr_tpe_allow(const struct file *file);
31977 ++
31978 ++int gr_random_pid(void);
31979 ++
31980 ++void gr_log_forkfail(const int retval);
31981 ++void gr_log_timechange(void);
31982 ++void gr_log_signal(const int sig, const struct task_struct *t);
31983 ++void gr_log_chdir(const struct dentry *dentry,
31984 ++ const struct vfsmount *mnt);
31985 ++void gr_log_chroot_exec(const struct dentry *dentry,
31986 ++ const struct vfsmount *mnt);
31987 ++void gr_handle_exec_args(struct linux_binprm *bprm, char **argv);
31988 ++void gr_log_remount(const char *devname, const int retval);
31989 ++void gr_log_unmount(const char *devname, const int retval);
31990 ++void gr_log_mount(const char *from, const char *to, const int retval);
31991 ++void gr_log_msgget(const int ret, const int msgflg);
31992 ++void gr_log_msgrm(const uid_t uid, const uid_t cuid);
31993 ++void gr_log_semget(const int err, const int semflg);
31994 ++void gr_log_semrm(const uid_t uid, const uid_t cuid);
31995 ++void gr_log_shmget(const int err, const int shmflg, const size_t size);
31996 ++void gr_log_shmrm(const uid_t uid, const uid_t cuid);
31997 ++void gr_log_textrel(struct vm_area_struct *vma);
31998 ++
31999 ++int gr_handle_follow_link(const struct inode *parent,
32000 ++ const struct inode *inode,
32001 ++ const struct dentry *dentry,
32002 ++ const struct vfsmount *mnt);
32003 ++int gr_handle_fifo(const struct dentry *dentry,
32004 ++ const struct vfsmount *mnt,
32005 ++ const struct dentry *dir, const int flag,
32006 ++ const int acc_mode);
32007 ++int gr_handle_hardlink(const struct dentry *dentry,
32008 ++ const struct vfsmount *mnt,
32009 ++ struct inode *inode,
32010 ++ const int mode, const char *to);
32011 ++
32012 ++int gr_task_is_capable(struct task_struct *task, const int cap);
32013 ++int gr_is_capable_nolog(const int cap);
32014 ++void gr_learn_resource(const struct task_struct *task, const int limit,
32015 ++ const unsigned long wanted, const int gt);
32016 ++void gr_copy_label(struct task_struct *tsk);
32017 ++void gr_handle_crash(struct task_struct *task, const int sig);
32018 ++int gr_handle_signal(const struct task_struct *p, const int sig);
32019 ++int gr_check_crash_uid(const uid_t uid);
32020 ++int gr_check_protected_task(const struct task_struct *task);
32021 ++int gr_acl_handle_mmap(const struct file *file,
32022 ++ const unsigned long prot);
32023 ++int gr_acl_handle_mprotect(const struct file *file,
32024 ++ const unsigned long prot);
32025 ++int gr_check_hidden_task(const struct task_struct *tsk);
32026 ++__u32 gr_acl_handle_truncate(const struct dentry *dentry,
32027 ++ const struct vfsmount *mnt);
32028 ++__u32 gr_acl_handle_utime(const struct dentry *dentry,
32029 ++ const struct vfsmount *mnt);
32030 ++__u32 gr_acl_handle_access(const struct dentry *dentry,
32031 ++ const struct vfsmount *mnt, const int fmode);
32032 ++__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
32033 ++ const struct vfsmount *mnt, mode_t mode);
32034 ++__u32 gr_acl_handle_chmod(const struct dentry *dentry,
32035 ++ const struct vfsmount *mnt, mode_t mode);
32036 ++__u32 gr_acl_handle_chown(const struct dentry *dentry,
32037 ++ const struct vfsmount *mnt);
32038 ++int gr_handle_ptrace(struct task_struct *task, const long request);
32039 ++int gr_handle_proc_ptrace(struct task_struct *task);
32040 ++__u32 gr_acl_handle_execve(const struct dentry *dentry,
32041 ++ const struct vfsmount *mnt);
32042 ++int gr_check_crash_exec(const struct file *filp);
32043 ++int gr_acl_is_enabled(void);
32044 ++void gr_set_kernel_label(struct task_struct *task);
32045 ++void gr_set_role_label(struct task_struct *task, const uid_t uid,
32046 ++ const gid_t gid);
32047 ++int gr_set_proc_label(const struct dentry *dentry,
32048 ++ const struct vfsmount *mnt);
32049 ++__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
32050 ++ const struct vfsmount *mnt);
32051 ++__u32 gr_acl_handle_open(const struct dentry *dentry,
32052 ++ const struct vfsmount *mnt, const int fmode);
32053 ++__u32 gr_acl_handle_creat(const struct dentry *dentry,
32054 ++ const struct dentry *p_dentry,
32055 ++ const struct vfsmount *p_mnt, const int fmode,
32056 ++ const int imode);
32057 ++void gr_handle_create(const struct dentry *dentry,
32058 ++ const struct vfsmount *mnt);
32059 ++__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
32060 ++ const struct dentry *parent_dentry,
32061 ++ const struct vfsmount *parent_mnt,
32062 ++ const int mode);
32063 ++__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
32064 ++ const struct dentry *parent_dentry,
32065 ++ const struct vfsmount *parent_mnt);
32066 ++__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
32067 ++ const struct vfsmount *mnt);
32068 ++void gr_handle_delete(const ino_t ino, const dev_t dev);
32069 ++__u32 gr_acl_handle_unlink(const struct dentry *dentry,
32070 ++ const struct vfsmount *mnt);
32071 ++__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
32072 ++ const struct dentry *parent_dentry,
32073 ++ const struct vfsmount *parent_mnt,
32074 ++ const char *from);
32075 ++__u32 gr_acl_handle_link(const struct dentry *new_dentry,
32076 ++ const struct dentry *parent_dentry,
32077 ++ const struct vfsmount *parent_mnt,
32078 ++ const struct dentry *old_dentry,
32079 ++ const struct vfsmount *old_mnt, const char *to);
32080 ++int gr_acl_handle_rename(struct dentry *new_dentry,
32081 ++ struct dentry *parent_dentry,
32082 ++ const struct vfsmount *parent_mnt,
32083 ++ struct dentry *old_dentry,
32084 ++ struct inode *old_parent_inode,
32085 ++ struct vfsmount *old_mnt, const char *newname);
32086 ++void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
32087 ++ struct dentry *old_dentry,
32088 ++ struct dentry *new_dentry,
32089 ++ struct vfsmount *mnt, const __u8 replace);
32090 ++__u32 gr_check_link(const struct dentry *new_dentry,
32091 ++ const struct dentry *parent_dentry,
32092 ++ const struct vfsmount *parent_mnt,
32093 ++ const struct dentry *old_dentry,
32094 ++ const struct vfsmount *old_mnt);
32095 ++int gr_acl_handle_filldir(const struct file *file, const char *name,
32096 ++ const unsigned int namelen, const ino_t ino);
32097 ++
32098 ++__u32 gr_acl_handle_unix(const struct dentry *dentry,
32099 ++ const struct vfsmount *mnt);
32100 ++void gr_acl_handle_exit(void);
32101 ++void gr_acl_handle_psacct(struct task_struct *task, const long code);
32102 ++int gr_acl_handle_procpidmem(const struct task_struct *task);
32103 ++
32104 ++#ifdef CONFIG_GRKERNSEC
32105 ++void gr_handle_mem_write(void);
32106 ++void gr_handle_kmem_write(void);
32107 ++void gr_handle_open_port(void);
32108 ++int gr_handle_mem_mmap(const unsigned long offset,
32109 ++ struct vm_area_struct *vma);
32110 ++
32111 ++extern int grsec_enable_dmesg;
32112 ++extern int grsec_enable_randsrc;
32113 ++extern int grsec_enable_shm;
32114 ++#endif
32115 ++
32116 ++#endif
32117 +diff -urNp linux-2.6.27.10/include/linux/highmem.h linux-2.6.27.10/include/linux/highmem.h
32118 +--- linux-2.6.27.10/include/linux/highmem.h 2008-11-07 12:55:34.000000000 -0500
32119 ++++ linux-2.6.27.10/include/linux/highmem.h 2008-11-18 03:38:45.000000000 -0500
32120 +@@ -122,6 +122,13 @@ static inline void clear_highpage(struct
32121 + kunmap_atomic(kaddr, KM_USER0);
32122 + }
32123 +
32124 ++static inline void sanitize_highpage(struct page *page)
32125 ++{
32126 ++ void *kaddr = kmap_atomic(page, KM_CLEARPAGE);
32127 ++ clear_page(kaddr);
32128 ++ kunmap_atomic(kaddr, KM_CLEARPAGE);
32129 ++}
32130 ++
32131 + static inline void zero_user_segments(struct page *page,
32132 + unsigned start1, unsigned end1,
32133 + unsigned start2, unsigned end2)
32134 +diff -urNp linux-2.6.27.10/include/linux/jbd2.h linux-2.6.27.10/include/linux/jbd2.h
32135 +--- linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:38.000000000 -0500
32136 ++++ linux-2.6.27.10/include/linux/jbd2.h 2008-12-10 22:35:46.000000000 -0500
32137 +@@ -66,7 +66,7 @@ extern u8 jbd2_journal_enable_debug;
32138 + } \
32139 + } while (0)
32140 + #else
32141 +-#define jbd_debug(f, a...) /**/
32142 ++#define jbd_debug(f, a...) do {} while (0)
32143 + #endif
32144 +
32145 + static inline void *jbd2_alloc(size_t size, gfp_t flags)
32146 +diff -urNp linux-2.6.27.10/include/linux/jbd.h linux-2.6.27.10/include/linux/jbd.h
32147 +--- linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:16:52.000000000 -0500
32148 ++++ linux-2.6.27.10/include/linux/jbd.h 2008-12-21 01:13:46.000000000 -0500
32149 +@@ -66,7 +66,7 @@ extern u8 journal_enable_debug;
32150 + } \
32151 + } while (0)
32152 + #else
32153 +-#define jbd_debug(f, a...) /**/
32154 ++#define jbd_debug(f, a...) do {} while (0)
32155 + #endif
32156 +
32157 + static inline void *jbd_alloc(size_t size, gfp_t flags)
32158 +diff -urNp linux-2.6.27.10/include/linux/libata.h linux-2.6.27.10/include/linux/libata.h
32159 +--- linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:38.000000000 -0500
32160 ++++ linux-2.6.27.10/include/linux/libata.h 2008-12-10 22:35:46.000000000 -0500
32161 +@@ -64,11 +64,11 @@
32162 + #ifdef ATA_VERBOSE_DEBUG
32163 + #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
32164 + #else
32165 +-#define VPRINTK(fmt, args...)
32166 ++#define VPRINTK(fmt, args...) do {} while (0)
32167 + #endif /* ATA_VERBOSE_DEBUG */
32168 + #else
32169 +-#define DPRINTK(fmt, args...)
32170 +-#define VPRINTK(fmt, args...)
32171 ++#define DPRINTK(fmt, args...) do {} while (0)
32172 ++#define VPRINTK(fmt, args...) do {} while (0)
32173 + #endif /* ATA_DEBUG */
32174 +
32175 + #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
32176 +diff -urNp linux-2.6.27.10/include/linux/mm.h linux-2.6.27.10/include/linux/mm.h
32177 +--- linux-2.6.27.10/include/linux/mm.h 2008-11-07 12:55:34.000000000 -0500
32178 ++++ linux-2.6.27.10/include/linux/mm.h 2008-12-21 00:44:29.000000000 -0500
32179 +@@ -38,6 +38,7 @@ extern unsigned long mmap_min_addr;
32180 + #include <asm/page.h>
32181 + #include <asm/pgtable.h>
32182 + #include <asm/processor.h>
32183 ++#include <asm/mman.h>
32184 +
32185 + #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
32186 +
32187 +@@ -114,6 +115,10 @@ extern unsigned int kobjsize(const void
32188 + #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
32189 + #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
32190 +
32191 ++#ifdef CONFIG_PAX_PAGEEXEC
32192 ++#define VM_PAGEEXEC 0x40000000 /* vma->vm_page_prot needs special handling */
32193 ++#endif
32194 ++
32195 + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
32196 + #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
32197 + #endif
32198 +@@ -874,6 +879,8 @@ struct shrinker {
32199 + extern void register_shrinker(struct shrinker *);
32200 + extern void unregister_shrinker(struct shrinker *);
32201 +
32202 ++pgprot_t vm_get_page_prot(unsigned long vm_flags);
32203 ++
32204 + int vma_wants_writenotify(struct vm_area_struct *vma);
32205 +
32206 + extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
32207 +@@ -1129,6 +1136,7 @@ out:
32208 + }
32209 +
32210 + extern int do_munmap(struct mm_struct *, unsigned long, size_t);
32211 ++extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
32212 +
32213 + extern unsigned long do_brk(unsigned long, unsigned long);
32214 +
32215 +@@ -1181,6 +1189,10 @@ extern struct vm_area_struct * find_vma(
32216 + extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
32217 + struct vm_area_struct **pprev);
32218 +
32219 ++extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
32220 ++extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
32221 ++extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
32222 ++
32223 + /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
32224 + NULL if none. Assume start_addr < end_addr. */
32225 + static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
32226 +@@ -1197,7 +1209,6 @@ static inline unsigned long vma_pages(st
32227 + return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
32228 + }
32229 +
32230 +-pgprot_t vm_get_page_prot(unsigned long vm_flags);
32231 + struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
32232 + int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
32233 + unsigned long pfn, unsigned long size, pgprot_t);
32234 +@@ -1286,5 +1297,11 @@ int vmemmap_populate_basepages(struct pa
32235 + int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
32236 + void vmemmap_populate_print_last(void);
32237 +
32238 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
32239 ++extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
32240 ++#else
32241 ++static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
32242 ++#endif
32243 ++
32244 + #endif /* __KERNEL__ */
32245 + #endif /* _LINUX_MM_H */
32246 +diff -urNp linux-2.6.27.10/include/linux/mm_types.h linux-2.6.27.10/include/linux/mm_types.h
32247 +--- linux-2.6.27.10/include/linux/mm_types.h 2008-11-07 12:55:34.000000000 -0500
32248 ++++ linux-2.6.27.10/include/linux/mm_types.h 2008-11-18 03:38:45.000000000 -0500
32249 +@@ -158,6 +158,8 @@ struct vm_area_struct {
32250 + #ifdef CONFIG_NUMA
32251 + struct mempolicy *vm_policy; /* NUMA policy for the VMA */
32252 + #endif
32253 ++
32254 ++ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
32255 + };
32256 +
32257 + struct core_thread {
32258 +@@ -257,6 +259,24 @@ struct mm_struct {
32259 + #ifdef CONFIG_MMU_NOTIFIER
32260 + struct mmu_notifier_mm *mmu_notifier_mm;
32261 + #endif
32262 ++
32263 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
32264 ++ unsigned long pax_flags;
32265 ++#endif
32266 ++
32267 ++#ifdef CONFIG_PAX_DLRESOLVE
32268 ++ unsigned long call_dl_resolve;
32269 ++#endif
32270 ++
32271 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
32272 ++ unsigned long call_syscall;
32273 ++#endif
32274 ++
32275 ++#ifdef CONFIG_PAX_ASLR
32276 ++ unsigned long delta_mmap; /* randomized offset */
32277 ++ unsigned long delta_stack; /* randomized offset */
32278 ++#endif
32279 ++
32280 + };
32281 +
32282 + #endif /* _LINUX_MM_TYPES_H */
32283 +diff -urNp linux-2.6.27.10/include/linux/module.h linux-2.6.27.10/include/linux/module.h
32284 +--- linux-2.6.27.10/include/linux/module.h 2008-11-07 12:55:34.000000000 -0500
32285 ++++ linux-2.6.27.10/include/linux/module.h 2008-11-18 03:38:45.000000000 -0500
32286 +@@ -282,16 +282,16 @@ struct module
32287 + int (*init)(void);
32288 +
32289 + /* If this is non-NULL, vfree after init() returns */
32290 +- void *module_init;
32291 ++ void *module_init_rx, *module_init_rw;
32292 +
32293 + /* Here is the actual code + data, vfree'd on unload. */
32294 +- void *module_core;
32295 ++ void *module_core_rx, *module_core_rw;
32296 +
32297 + /* Here are the sizes of the init and core sections */
32298 +- unsigned int init_size, core_size;
32299 ++ unsigned int init_size_rw, core_size_rw;
32300 +
32301 + /* The size of the executable code in each section. */
32302 +- unsigned int init_text_size, core_text_size;
32303 ++ unsigned int init_size_rx, core_size_rx;
32304 +
32305 + /* The handle returned from unwind_add_table. */
32306 + void *unwind_info;
32307 +diff -urNp linux-2.6.27.10/include/linux/moduleloader.h linux-2.6.27.10/include/linux/moduleloader.h
32308 +--- linux-2.6.27.10/include/linux/moduleloader.h 2008-11-07 12:55:34.000000000 -0500
32309 ++++ linux-2.6.27.10/include/linux/moduleloader.h 2008-11-18 03:38:45.000000000 -0500
32310 +@@ -17,9 +17,21 @@ int module_frob_arch_sections(Elf_Ehdr *
32311 + sections. Returns NULL on failure. */
32312 + void *module_alloc(unsigned long size);
32313 +
32314 ++#ifdef CONFIG_PAX_KERNEXEC
32315 ++void *module_alloc_exec(unsigned long size);
32316 ++#else
32317 ++#define module_alloc_exec(x) module_alloc(x)
32318 ++#endif
32319 ++
32320 + /* Free memory returned from module_alloc. */
32321 + void module_free(struct module *mod, void *module_region);
32322 +
32323 ++#ifdef CONFIG_PAX_KERNEXEC
32324 ++void module_free_exec(struct module *mod, void *module_region);
32325 ++#else
32326 ++#define module_free_exec(x, y) module_free(x, y)
32327 ++#endif
32328 ++
32329 + /* Apply the given relocation to the (simplified) ELF. Return -error
32330 + or 0. */
32331 + int apply_relocate(Elf_Shdr *sechdrs,
32332 +diff -urNp linux-2.6.27.10/include/linux/namei.h linux-2.6.27.10/include/linux/namei.h
32333 +--- linux-2.6.27.10/include/linux/namei.h 2008-11-07 12:55:34.000000000 -0500
32334 ++++ linux-2.6.27.10/include/linux/namei.h 2008-11-18 03:38:45.000000000 -0500
32335 +@@ -21,7 +21,7 @@ struct nameidata {
32336 + unsigned int flags;
32337 + int last_type;
32338 + unsigned depth;
32339 +- char *saved_names[MAX_NESTED_LINKS + 1];
32340 ++ const char *saved_names[MAX_NESTED_LINKS + 1];
32341 +
32342 + /* Intent data */
32343 + union {
32344 +@@ -80,12 +80,12 @@ extern int follow_up(struct vfsmount **,
32345 + extern struct dentry *lock_rename(struct dentry *, struct dentry *);
32346 + extern void unlock_rename(struct dentry *, struct dentry *);
32347 +
32348 +-static inline void nd_set_link(struct nameidata *nd, char *path)
32349 ++static inline void nd_set_link(struct nameidata *nd, const char *path)
32350 + {
32351 + nd->saved_names[nd->depth] = path;
32352 + }
32353 +
32354 +-static inline char *nd_get_link(struct nameidata *nd)
32355 ++static inline const char *nd_get_link(struct nameidata *nd)
32356 + {
32357 + return nd->saved_names[nd->depth];
32358 + }
32359 +diff -urNp linux-2.6.27.10/include/linux/nodemask.h linux-2.6.27.10/include/linux/nodemask.h
32360 +--- linux-2.6.27.10/include/linux/nodemask.h 2008-11-07 12:55:34.000000000 -0500
32361 ++++ linux-2.6.27.10/include/linux/nodemask.h 2008-11-18 03:38:45.000000000 -0500
32362 +@@ -442,11 +442,11 @@ static inline int num_node_state(enum no
32363 +
32364 + #define any_online_node(mask) \
32365 + ({ \
32366 +- int node; \
32367 +- for_each_node_mask(node, (mask)) \
32368 +- if (node_online(node)) \
32369 ++ int __node; \
32370 ++ for_each_node_mask(__node, (mask)) \
32371 ++ if (node_online(__node)) \
32372 + break; \
32373 +- node; \
32374 ++ __node; \
32375 + })
32376 +
32377 + #define num_online_nodes() num_node_state(N_ONLINE)
32378 +diff -urNp linux-2.6.27.10/include/linux/percpu.h linux-2.6.27.10/include/linux/percpu.h
32379 +--- linux-2.6.27.10/include/linux/percpu.h 2008-11-07 12:55:34.000000000 -0500
32380 ++++ linux-2.6.27.10/include/linux/percpu.h 2008-11-18 03:38:45.000000000 -0500
32381 +@@ -43,7 +43,7 @@
32382 + #endif
32383 +
32384 + #define PERCPU_ENOUGH_ROOM \
32385 +- (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)
32386 ++ ((unsigned long)(__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE))
32387 + #endif /* PERCPU_ENOUGH_ROOM */
32388 +
32389 + /*
32390 +diff -urNp linux-2.6.27.10/include/linux/poison.h linux-2.6.27.10/include/linux/poison.h
32391 +--- linux-2.6.27.10/include/linux/poison.h 2008-11-07 12:55:34.000000000 -0500
32392 ++++ linux-2.6.27.10/include/linux/poison.h 2008-11-18 03:38:45.000000000 -0500
32393 +@@ -7,8 +7,8 @@
32394 + * under normal circumstances, used to verify that nobody uses
32395 + * non-initialized list entries.
32396 + */
32397 +-#define LIST_POISON1 ((void *) 0x00100100)
32398 +-#define LIST_POISON2 ((void *) 0x00200200)
32399 ++#define LIST_POISON1 ((void *) 0xFF1001FFFF1001FFULL)
32400 ++#define LIST_POISON2 ((void *) 0xFF2002FFFF2002FFULL)
32401 +
32402 + /********** include/linux/timer.h **********/
32403 + /*
32404 +diff -urNp linux-2.6.27.10/include/linux/random.h linux-2.6.27.10/include/linux/random.h
32405 +--- linux-2.6.27.10/include/linux/random.h 2008-11-07 12:55:34.000000000 -0500
32406 ++++ linux-2.6.27.10/include/linux/random.h 2008-11-18 03:38:45.000000000 -0500
32407 +@@ -72,6 +72,11 @@ unsigned long randomize_range(unsigned l
32408 + u32 random32(void);
32409 + void srandom32(u32 seed);
32410 +
32411 ++static inline unsigned long pax_get_random_long(void)
32412 ++{
32413 ++ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
32414 ++}
32415 ++
32416 + #endif /* __KERNEL___ */
32417 +
32418 + #endif /* _LINUX_RANDOM_H */
32419 +diff -urNp linux-2.6.27.10/include/linux/sched.h linux-2.6.27.10/include/linux/sched.h
32420 +--- linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:38.000000000 -0500
32421 ++++ linux-2.6.27.10/include/linux/sched.h 2008-12-10 22:35:46.000000000 -0500
32422 +@@ -96,6 +96,7 @@ struct exec_domain;
32423 + struct futex_pi_state;
32424 + struct robust_list_head;
32425 + struct bio;
32426 ++struct linux_binprm;
32427 +
32428 + /*
32429 + * List of flags we want to share for kernel threads,
32430 +@@ -545,6 +546,15 @@ struct signal_struct {
32431 + unsigned audit_tty;
32432 + struct tty_audit_buf *tty_audit_buf;
32433 + #endif
32434 ++
32435 ++#ifdef CONFIG_GRKERNSEC
32436 ++ u32 curr_ip;
32437 ++ u32 gr_saddr;
32438 ++ u32 gr_daddr;
32439 ++ u16 gr_sport;
32440 ++ u16 gr_dport;
32441 ++ u8 used_accept:1;
32442 ++#endif
32443 + };
32444 +
32445 + /* Context switch must be unlocked if interrupts are to be enabled */
32446 +@@ -1030,7 +1040,7 @@ struct sched_rt_entity {
32447 +
32448 + struct task_struct {
32449 + volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
32450 +- void *stack;
32451 ++ struct thread_info *stack;
32452 + atomic_t usage;
32453 + unsigned int flags; /* per process flags, defined below */
32454 + unsigned int ptrace;
32455 +@@ -1095,10 +1105,9 @@ struct task_struct {
32456 + pid_t pid;
32457 + pid_t tgid;
32458 +
32459 +-#ifdef CONFIG_CC_STACKPROTECTOR
32460 + /* Canary value for the -fstack-protector gcc feature */
32461 + unsigned long stack_canary;
32462 +-#endif
32463 ++
32464 + /*
32465 + * pointers to (original) parent process, youngest child, younger sibling,
32466 + * older sibling, respectively. (p->father can be replaced with
32467 +@@ -1126,8 +1135,8 @@ struct task_struct {
32468 + struct list_head thread_group;
32469 +
32470 + struct completion *vfork_done; /* for vfork() */
32471 +- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
32472 +- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
32473 ++ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
32474 ++ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
32475 +
32476 + cputime_t utime, stime, utimescaled, stimescaled;
32477 + cputime_t gtime;
32478 +@@ -1307,8 +1316,64 @@ struct task_struct {
32479 + int latency_record_count;
32480 + struct latency_record latency_record[LT_SAVECOUNT];
32481 + #endif
32482 ++
32483 ++#ifdef CONFIG_GRKERNSEC
32484 ++ /* grsecurity */
32485 ++ struct acl_subject_label *acl;
32486 ++ struct acl_role_label *role;
32487 ++ struct file *exec_file;
32488 ++ u16 acl_role_id;
32489 ++ u8 acl_sp_role;
32490 ++ u8 is_writable;
32491 ++ u8 brute;
32492 ++#endif
32493 ++
32494 + };
32495 +
32496 ++#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
32497 ++#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
32498 ++#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
32499 ++#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
32500 ++/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
32501 ++#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
32502 ++
32503 ++#ifdef CONFIG_PAX_SOFTMODE
32504 ++extern unsigned int pax_softmode;
32505 ++#endif
32506 ++
32507 ++extern int pax_check_flags(unsigned long *);
32508 ++
32509 ++/* if tsk != current then task_lock must be held on it */
32510 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
32511 ++static inline unsigned long pax_get_flags(struct task_struct *tsk)
32512 ++{
32513 ++ if (likely(tsk->mm))
32514 ++ return tsk->mm->pax_flags;
32515 ++ else
32516 ++ return 0UL;
32517 ++}
32518 ++
32519 ++/* if tsk != current then task_lock must be held on it */
32520 ++static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
32521 ++{
32522 ++ if (likely(tsk->mm)) {
32523 ++ tsk->mm->pax_flags = flags;
32524 ++ return 0;
32525 ++ }
32526 ++ return -EINVAL;
32527 ++}
32528 ++#endif
32529 ++
32530 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
32531 ++extern void pax_set_initial_flags(struct linux_binprm *bprm);
32532 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
32533 ++extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
32534 ++#endif
32535 ++
32536 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
32537 ++void pax_report_insns(void *pc, void *sp);
32538 ++void pax_report_refcount_overflow(struct pt_regs *regs);
32539 ++
32540 + /*
32541 + * Priority of a process goes from 0..MAX_PRIO-1, valid RT
32542 + * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
32543 +@@ -1849,7 +1914,7 @@ extern void __cleanup_sighand(struct sig
32544 + extern void exit_itimers(struct signal_struct *);
32545 + extern void flush_itimer_signals(void);
32546 +
32547 +-extern NORET_TYPE void do_group_exit(int);
32548 ++extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
32549 +
32550 + extern void daemonize(const char *, ...);
32551 + extern int allow_signal(int);
32552 +@@ -1952,8 +2017,8 @@ static inline void unlock_task_sighand(s
32553 +
32554 + #ifndef __HAVE_THREAD_FUNCTIONS
32555 +
32556 +-#define task_thread_info(task) ((struct thread_info *)(task)->stack)
32557 +-#define task_stack_page(task) ((task)->stack)
32558 ++#define task_thread_info(task) ((task)->stack)
32559 ++#define task_stack_page(task) ((void *)(task)->stack)
32560 +
32561 + static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
32562 + {
32563 +diff -urNp linux-2.6.27.10/include/linux/screen_info.h linux-2.6.27.10/include/linux/screen_info.h
32564 +--- linux-2.6.27.10/include/linux/screen_info.h 2008-11-07 12:55:34.000000000 -0500
32565 ++++ linux-2.6.27.10/include/linux/screen_info.h 2008-11-18 03:38:45.000000000 -0500
32566 +@@ -42,7 +42,8 @@ struct screen_info {
32567 + __u16 pages; /* 0x32 */
32568 + __u16 vesa_attributes; /* 0x34 */
32569 + __u32 capabilities; /* 0x36 */
32570 +- __u8 _reserved[6]; /* 0x3a */
32571 ++ __u16 vesapm_size; /* 0x3a */
32572 ++ __u8 _reserved[4]; /* 0x3c */
32573 + } __attribute__((packed));
32574 +
32575 + #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
32576 +diff -urNp linux-2.6.27.10/include/linux/shm.h linux-2.6.27.10/include/linux/shm.h
32577 +--- linux-2.6.27.10/include/linux/shm.h 2008-11-07 12:55:34.000000000 -0500
32578 ++++ linux-2.6.27.10/include/linux/shm.h 2008-11-18 03:38:45.000000000 -0500
32579 +@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
32580 + pid_t shm_cprid;
32581 + pid_t shm_lprid;
32582 + struct user_struct *mlock_user;
32583 ++#ifdef CONFIG_GRKERNSEC
32584 ++ time_t shm_createtime;
32585 ++ pid_t shm_lapid;
32586 ++#endif
32587 + };
32588 +
32589 + /* shm_mode upper byte flags */
32590 +diff -urNp linux-2.6.27.10/include/linux/slab.h linux-2.6.27.10/include/linux/slab.h
32591 +--- linux-2.6.27.10/include/linux/slab.h 2008-11-07 12:55:34.000000000 -0500
32592 ++++ linux-2.6.27.10/include/linux/slab.h 2008-11-18 03:38:45.000000000 -0500
32593 +@@ -45,10 +45,9 @@
32594 + * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
32595 + * Both make kfree a no-op.
32596 + */
32597 +-#define ZERO_SIZE_PTR ((void *)16)
32598 ++#define ZERO_SIZE_PTR ((void *)-1024L)
32599 +
32600 +-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
32601 +- (unsigned long)ZERO_SIZE_PTR)
32602 ++#define ZERO_OR_NULL_PTR(x) (!(x) || (x) == ZERO_SIZE_PTR)
32603 +
32604 + /*
32605 + * struct kmem_cache related prototypes
32606 +diff -urNp linux-2.6.27.10/include/linux/sysctl.h linux-2.6.27.10/include/linux/sysctl.h
32607 +--- linux-2.6.27.10/include/linux/sysctl.h 2008-11-07 12:55:34.000000000 -0500
32608 ++++ linux-2.6.27.10/include/linux/sysctl.h 2008-11-18 03:38:45.000000000 -0500
32609 +@@ -165,7 +165,11 @@ enum
32610 + KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
32611 + };
32612 +
32613 +-
32614 ++#ifdef CONFIG_PAX_SOFTMODE
32615 ++enum {
32616 ++ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
32617 ++};
32618 ++#endif
32619 +
32620 + /* CTL_VM names: */
32621 + enum
32622 +diff -urNp linux-2.6.27.10/include/linux/thread_info.h linux-2.6.27.10/include/linux/thread_info.h
32623 +--- linux-2.6.27.10/include/linux/thread_info.h 2008-11-07 12:55:34.000000000 -0500
32624 ++++ linux-2.6.27.10/include/linux/thread_info.h 2008-11-18 03:38:45.000000000 -0500
32625 +@@ -23,7 +23,7 @@ struct restart_block {
32626 + };
32627 + /* For futex_wait */
32628 + struct {
32629 +- u32 *uaddr;
32630 ++ u32 __user *uaddr;
32631 + u32 val;
32632 + u32 flags;
32633 + u32 bitset;
32634 +diff -urNp linux-2.6.27.10/include/linux/uaccess.h linux-2.6.27.10/include/linux/uaccess.h
32635 +--- linux-2.6.27.10/include/linux/uaccess.h 2008-11-07 12:55:34.000000000 -0500
32636 ++++ linux-2.6.27.10/include/linux/uaccess.h 2008-11-18 03:38:45.000000000 -0500
32637 +@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
32638 + long ret; \
32639 + mm_segment_t old_fs = get_fs(); \
32640 + \
32641 +- set_fs(KERNEL_DS); \
32642 + pagefault_disable(); \
32643 ++ set_fs(KERNEL_DS); \
32644 + ret = __get_user(retval, (__force typeof(retval) __user *)(addr)); \
32645 +- pagefault_enable(); \
32646 + set_fs(old_fs); \
32647 ++ pagefault_enable(); \
32648 + ret; \
32649 + })
32650 +
32651 +diff -urNp linux-2.6.27.10/include/linux/vmalloc.h linux-2.6.27.10/include/linux/vmalloc.h
32652 +--- linux-2.6.27.10/include/linux/vmalloc.h 2008-11-07 12:55:34.000000000 -0500
32653 ++++ linux-2.6.27.10/include/linux/vmalloc.h 2008-11-18 03:38:45.000000000 -0500
32654 +@@ -12,6 +12,11 @@ struct vm_area_struct; /* vma defining
32655 + #define VM_MAP 0x00000004 /* vmap()ed pages */
32656 + #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
32657 + #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
32658 ++
32659 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32660 ++#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
32661 ++#endif
32662 ++
32663 + /* bits [20..32] reserved for arch specific ioremap internals */
32664 +
32665 + /*
32666 +diff -urNp linux-2.6.27.10/include/net/sctp/sctp.h linux-2.6.27.10/include/net/sctp/sctp.h
32667 +--- linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-07 12:55:34.000000000 -0500
32668 ++++ linux-2.6.27.10/include/net/sctp/sctp.h 2008-11-18 03:38:45.000000000 -0500
32669 +@@ -309,8 +309,8 @@ extern int sctp_debug_flag;
32670 +
32671 + #else /* SCTP_DEBUG */
32672 +
32673 +-#define SCTP_DEBUG_PRINTK(whatever...)
32674 +-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
32675 ++#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
32676 ++#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
32677 + #define SCTP_ENABLE_DEBUG
32678 + #define SCTP_DISABLE_DEBUG
32679 + #define SCTP_ASSERT(expr, str, func)
32680 +diff -urNp linux-2.6.27.10/include/sound/core.h linux-2.6.27.10/include/sound/core.h
32681 +--- linux-2.6.27.10/include/sound/core.h 2008-11-07 12:55:34.000000000 -0500
32682 ++++ linux-2.6.27.10/include/sound/core.h 2008-11-18 03:38:45.000000000 -0500
32683 +@@ -406,9 +406,9 @@ void snd_verbose_printd(const char *file
32684 +
32685 + #else /* !CONFIG_SND_DEBUG */
32686 +
32687 +-#define snd_printd(fmt, args...) /* nothing */
32688 ++#define snd_printd(fmt, args...) do {} while (0)
32689 + #define snd_assert(expr, args...) (void)(expr)
32690 +-#define snd_BUG() /* nothing */
32691 ++#define snd_BUG() do {} while (0)
32692 +
32693 + #endif /* CONFIG_SND_DEBUG */
32694 +
32695 +@@ -422,7 +422,7 @@ void snd_verbose_printd(const char *file
32696 + */
32697 + #define snd_printdd(format, args...) snd_printk(format, ##args)
32698 + #else
32699 +-#define snd_printdd(format, args...) /* nothing */
32700 ++#define snd_printdd(format, args...) do {} while (0)
32701 + #endif
32702 +
32703 +
32704 +diff -urNp linux-2.6.27.10/include/video/uvesafb.h linux-2.6.27.10/include/video/uvesafb.h
32705 +--- linux-2.6.27.10/include/video/uvesafb.h 2008-11-07 12:55:34.000000000 -0500
32706 ++++ linux-2.6.27.10/include/video/uvesafb.h 2008-11-18 03:38:45.000000000 -0500
32707 +@@ -175,6 +175,7 @@ struct uvesafb_par {
32708 + u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
32709 + u8 pmi_setpal; /* PMI for palette changes */
32710 + u16 *pmi_base; /* protected mode interface location */
32711 ++ u8 *pmi_code; /* protected mode code location */
32712 + void *pmi_start;
32713 + void *pmi_pal;
32714 + u8 *vbe_state_orig; /*
32715 +diff -urNp linux-2.6.27.10/init/do_mounts.c linux-2.6.27.10/init/do_mounts.c
32716 +--- linux-2.6.27.10/init/do_mounts.c 2008-11-07 12:55:34.000000000 -0500
32717 ++++ linux-2.6.27.10/init/do_mounts.c 2008-11-18 03:38:45.000000000 -0500
32718 +@@ -214,11 +214,11 @@ static void __init get_fs_names(char *pa
32719 +
32720 + static int __init do_mount_root(char *name, char *fs, int flags, void *data)
32721 + {
32722 +- int err = sys_mount(name, "/root", fs, flags, data);
32723 ++ int err = sys_mount((char __user *)name, (char __user *)"/root", (char __user *)fs, flags, (void __user *)data);
32724 + if (err)
32725 + return err;
32726 +
32727 +- sys_chdir("/root");
32728 ++ sys_chdir((char __user *)"/root");
32729 + ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
32730 + printk("VFS: Mounted root (%s filesystem)%s.\n",
32731 + current->fs->pwd.mnt->mnt_sb->s_type->name,
32732 +@@ -304,18 +304,18 @@ void __init change_floppy(char *fmt, ...
32733 + va_start(args, fmt);
32734 + vsprintf(buf, fmt, args);
32735 + va_end(args);
32736 +- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
32737 ++ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
32738 + if (fd >= 0) {
32739 + sys_ioctl(fd, FDEJECT, 0);
32740 + sys_close(fd);
32741 + }
32742 + printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
32743 +- fd = sys_open("/dev/console", O_RDWR, 0);
32744 ++ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
32745 + if (fd >= 0) {
32746 + sys_ioctl(fd, TCGETS, (long)&termios);
32747 + termios.c_lflag &= ~ICANON;
32748 + sys_ioctl(fd, TCSETSF, (long)&termios);
32749 +- sys_read(fd, &c, 1);
32750 ++ sys_read(fd, (char __user *)&c, 1);
32751 + termios.c_lflag |= ICANON;
32752 + sys_ioctl(fd, TCSETSF, (long)&termios);
32753 + sys_close(fd);
32754 +@@ -402,7 +402,7 @@ void __init prepare_namespace(void)
32755 +
32756 + mount_root();
32757 + out:
32758 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
32759 +- sys_chroot(".");
32760 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
32761 ++ sys_chroot((char __user *)".");
32762 + }
32763 +
32764 +diff -urNp linux-2.6.27.10/init/do_mounts.h linux-2.6.27.10/init/do_mounts.h
32765 +--- linux-2.6.27.10/init/do_mounts.h 2008-11-07 12:55:34.000000000 -0500
32766 ++++ linux-2.6.27.10/init/do_mounts.h 2008-11-18 03:38:45.000000000 -0500
32767 +@@ -14,15 +14,15 @@ extern int root_mountflags;
32768 +
32769 + static inline int create_dev(char *name, dev_t dev)
32770 + {
32771 +- sys_unlink(name);
32772 +- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
32773 ++ sys_unlink((char __user *)name);
32774 ++ return sys_mknod((char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
32775 + }
32776 +
32777 + #if BITS_PER_LONG == 32
32778 + static inline u32 bstat(char *name)
32779 + {
32780 + struct stat64 stat;
32781 +- if (sys_stat64(name, &stat) != 0)
32782 ++ if (sys_stat64((char __user *)name, (struct stat64 __user *)&stat) != 0)
32783 + return 0;
32784 + if (!S_ISBLK(stat.st_mode))
32785 + return 0;
32786 +diff -urNp linux-2.6.27.10/init/do_mounts_initrd.c linux-2.6.27.10/init/do_mounts_initrd.c
32787 +--- linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-07 12:55:34.000000000 -0500
32788 ++++ linux-2.6.27.10/init/do_mounts_initrd.c 2008-11-18 03:38:45.000000000 -0500
32789 +@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
32790 + sys_close(old_fd);sys_close(root_fd);
32791 + sys_close(0);sys_close(1);sys_close(2);
32792 + sys_setsid();
32793 +- (void) sys_open("/dev/console",O_RDWR,0);
32794 ++ (void) sys_open((const char __user *)"/dev/console",O_RDWR,0);
32795 + (void) sys_dup(0);
32796 + (void) sys_dup(0);
32797 + return kernel_execve(shell, argv, envp_init);
32798 +@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
32799 + create_dev("/dev/root.old", Root_RAM0);
32800 + /* mount initrd on rootfs' /root */
32801 + mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
32802 +- sys_mkdir("/old", 0700);
32803 +- root_fd = sys_open("/", 0, 0);
32804 +- old_fd = sys_open("/old", 0, 0);
32805 ++ sys_mkdir((const char __user *)"/old", 0700);
32806 ++ root_fd = sys_open((const char __user *)"/", 0, 0);
32807 ++ old_fd = sys_open((const char __user *)"/old", 0, 0);
32808 + /* move initrd over / and chdir/chroot in initrd root */
32809 +- sys_chdir("/root");
32810 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
32811 +- sys_chroot(".");
32812 ++ sys_chdir((const char __user *)"/root");
32813 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
32814 ++ sys_chroot((const char __user *)".");
32815 +
32816 + /*
32817 + * In case that a resume from disk is carried out by linuxrc or one of
32818 +@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
32819 +
32820 + /* move initrd to rootfs' /old */
32821 + sys_fchdir(old_fd);
32822 +- sys_mount("/", ".", NULL, MS_MOVE, NULL);
32823 ++ sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL);
32824 + /* switch root and cwd back to / of rootfs */
32825 + sys_fchdir(root_fd);
32826 +- sys_chroot(".");
32827 ++ sys_chroot((const char __user *)".");
32828 + sys_close(old_fd);
32829 + sys_close(root_fd);
32830 +
32831 + if (new_decode_dev(real_root_dev) == Root_RAM0) {
32832 +- sys_chdir("/old");
32833 ++ sys_chdir((const char __user *)"/old");
32834 + return;
32835 + }
32836 +
32837 +@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
32838 + mount_root();
32839 +
32840 + printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
32841 +- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
32842 ++ error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
32843 + if (!error)
32844 + printk("okay\n");
32845 + else {
32846 +- int fd = sys_open("/dev/root.old", O_RDWR, 0);
32847 ++ int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0);
32848 + if (error == -ENOENT)
32849 + printk("/initrd does not exist. Ignored.\n");
32850 + else
32851 + printk("failed\n");
32852 + printk(KERN_NOTICE "Unmounting old root\n");
32853 +- sys_umount("/old", MNT_DETACH);
32854 ++ sys_umount((char __user *)"/old", MNT_DETACH);
32855 + printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
32856 + if (fd < 0) {
32857 + error = fd;
32858 +@@ -119,11 +119,11 @@ int __init initrd_load(void)
32859 + * mounted in the normal path.
32860 + */
32861 + if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
32862 +- sys_unlink("/initrd.image");
32863 ++ sys_unlink((const char __user *)"/initrd.image");
32864 + handle_initrd();
32865 + return 1;
32866 + }
32867 + }
32868 +- sys_unlink("/initrd.image");
32869 ++ sys_unlink((const char __user *)"/initrd.image");
32870 + return 0;
32871 + }
32872 +diff -urNp linux-2.6.27.10/init/do_mounts_md.c linux-2.6.27.10/init/do_mounts_md.c
32873 +--- linux-2.6.27.10/init/do_mounts_md.c 2008-11-07 12:55:34.000000000 -0500
32874 ++++ linux-2.6.27.10/init/do_mounts_md.c 2008-11-18 03:38:45.000000000 -0500
32875 +@@ -166,7 +166,7 @@ static void __init md_setup_drive(void)
32876 + partitioned ? "_d" : "", minor,
32877 + md_setup_args[ent].device_names);
32878 +
32879 +- fd = sys_open(name, 0, 0);
32880 ++ fd = sys_open((char __user *)name, 0, 0);
32881 + if (fd < 0) {
32882 + printk(KERN_ERR "md: open failed - cannot start "
32883 + "array %s\n", name);
32884 +@@ -229,7 +229,7 @@ static void __init md_setup_drive(void)
32885 + * array without it
32886 + */
32887 + sys_close(fd);
32888 +- fd = sys_open(name, 0, 0);
32889 ++ fd = sys_open((char __user *)name, 0, 0);
32890 + sys_ioctl(fd, BLKRRPART, 0);
32891 + }
32892 + sys_close(fd);
32893 +@@ -270,7 +270,7 @@ void __init md_run_setup(void)
32894 + if (raid_noautodetect)
32895 + printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
32896 + else {
32897 +- int fd = sys_open("/dev/md0", 0, 0);
32898 ++ int fd = sys_open((char __user *)"/dev/md0", 0, 0);
32899 + if (fd >= 0) {
32900 + sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
32901 + sys_close(fd);
32902 +diff -urNp linux-2.6.27.10/init/initramfs.c linux-2.6.27.10/init/initramfs.c
32903 +--- linux-2.6.27.10/init/initramfs.c 2008-11-07 12:55:34.000000000 -0500
32904 ++++ linux-2.6.27.10/init/initramfs.c 2008-11-18 03:38:45.000000000 -0500
32905 +@@ -230,7 +230,7 @@ static int __init maybe_link(void)
32906 + if (nlink >= 2) {
32907 + char *old = find_link(major, minor, ino, mode, collected);
32908 + if (old)
32909 +- return (sys_link(old, collected) < 0) ? -1 : 1;
32910 ++ return (sys_link((char __user *)old, (char __user *)collected) < 0) ? -1 : 1;
32911 + }
32912 + return 0;
32913 + }
32914 +@@ -239,11 +239,11 @@ static void __init clean_path(char *path
32915 + {
32916 + struct stat st;
32917 +
32918 +- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
32919 ++ if (!sys_newlstat((char __user *)path, (struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
32920 + if (S_ISDIR(st.st_mode))
32921 +- sys_rmdir(path);
32922 ++ sys_rmdir((char __user *)path);
32923 + else
32924 +- sys_unlink(path);
32925 ++ sys_unlink((char __user *)path);
32926 + }
32927 + }
32928 +
32929 +@@ -266,7 +266,7 @@ static int __init do_name(void)
32930 + int openflags = O_WRONLY|O_CREAT;
32931 + if (ml != 1)
32932 + openflags |= O_TRUNC;
32933 +- wfd = sys_open(collected, openflags, mode);
32934 ++ wfd = sys_open((char __user *)collected, openflags, mode);
32935 +
32936 + if (wfd >= 0) {
32937 + sys_fchown(wfd, uid, gid);
32938 +@@ -275,15 +275,15 @@ static int __init do_name(void)
32939 + }
32940 + }
32941 + } else if (S_ISDIR(mode)) {
32942 +- sys_mkdir(collected, mode);
32943 +- sys_chown(collected, uid, gid);
32944 +- sys_chmod(collected, mode);
32945 ++ sys_mkdir((char __user *)collected, mode);
32946 ++ sys_chown((char __user *)collected, uid, gid);
32947 ++ sys_chmod((char __user *)collected, mode);
32948 + } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
32949 + S_ISFIFO(mode) || S_ISSOCK(mode)) {
32950 + if (maybe_link() == 0) {
32951 +- sys_mknod(collected, mode, rdev);
32952 +- sys_chown(collected, uid, gid);
32953 +- sys_chmod(collected, mode);
32954 ++ sys_mknod((char __user *)collected, mode, rdev);
32955 ++ sys_chown((char __user *)collected, uid, gid);
32956 ++ sys_chmod((char __user *)collected, mode);
32957 + }
32958 + }
32959 + return 0;
32960 +@@ -292,13 +292,13 @@ static int __init do_name(void)
32961 + static int __init do_copy(void)
32962 + {
32963 + if (count >= body_len) {
32964 +- sys_write(wfd, victim, body_len);
32965 ++ sys_write(wfd, (char __user *)victim, body_len);
32966 + sys_close(wfd);
32967 + eat(body_len);
32968 + state = SkipIt;
32969 + return 0;
32970 + } else {
32971 +- sys_write(wfd, victim, count);
32972 ++ sys_write(wfd, (char __user *)victim, count);
32973 + body_len -= count;
32974 + eat(count);
32975 + return 1;
32976 +@@ -309,8 +309,8 @@ static int __init do_symlink(void)
32977 + {
32978 + collected[N_ALIGN(name_len) + body_len] = '\0';
32979 + clean_path(collected, 0);
32980 +- sys_symlink(collected + N_ALIGN(name_len), collected);
32981 +- sys_lchown(collected, uid, gid);
32982 ++ sys_symlink((char __user *)collected + N_ALIGN(name_len), (char __user *)collected);
32983 ++ sys_lchown((char __user *)collected, uid, gid);
32984 + state = SkipIt;
32985 + next_state = Reset;
32986 + return 0;
32987 +diff -urNp linux-2.6.27.10/init/Kconfig linux-2.6.27.10/init/Kconfig
32988 +--- linux-2.6.27.10/init/Kconfig 2008-11-07 12:55:34.000000000 -0500
32989 ++++ linux-2.6.27.10/init/Kconfig 2008-11-18 03:38:45.000000000 -0500
32990 +@@ -561,6 +561,7 @@ config SYSCTL_SYSCALL
32991 + config KALLSYMS
32992 + bool "Load all symbols for debugging/ksymoops" if EMBEDDED
32993 + default y
32994 ++ depends on !GRKERNSEC_HIDESYM
32995 + help
32996 + Say Y here to let the kernel print out symbolic crash information and
32997 + symbolic stack backtraces. This increases the size of the kernel
32998 +@@ -780,8 +781,8 @@ config MARKERS
32999 + source "arch/Kconfig"
33000 +
33001 + config PROC_PAGE_MONITOR
33002 +- default y
33003 +- depends on PROC_FS && MMU
33004 ++ default n
33005 ++ depends on PROC_FS && MMU && !GRKERNSEC
33006 + bool "Enable /proc page monitoring" if EMBEDDED
33007 + help
33008 + Various /proc files exist to monitor process memory utilization:
33009 +@@ -797,9 +798,9 @@ config HAVE_GENERIC_DMA_COHERENT
33010 +
33011 + config SLABINFO
33012 + bool
33013 +- depends on PROC_FS
33014 ++ depends on PROC_FS && !GRKERNSEC_PROC_ADD
33015 + depends on SLAB || SLUB_DEBUG
33016 +- default y
33017 ++ default n
33018 +
33019 + config RT_MUTEXES
33020 + boolean
33021 +diff -urNp linux-2.6.27.10/init/main.c linux-2.6.27.10/init/main.c
33022 +--- linux-2.6.27.10/init/main.c 2008-11-07 12:55:34.000000000 -0500
33023 ++++ linux-2.6.27.10/init/main.c 2008-11-18 03:38:45.000000000 -0500
33024 +@@ -101,6 +101,7 @@ static inline void mark_rodata_ro(void)
33025 + #ifdef CONFIG_TC
33026 + extern void tc_init(void);
33027 + #endif
33028 ++extern void grsecurity_init(void);
33029 +
33030 + enum system_states system_state;
33031 + EXPORT_SYMBOL(system_state);
33032 +@@ -187,6 +188,40 @@ static int __init set_reset_devices(char
33033 +
33034 + __setup("reset_devices", set_reset_devices);
33035 +
33036 ++#if defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32)
33037 ++static int __init setup_pax_nouderef(char *str)
33038 ++{
33039 ++ unsigned int cpu;
33040 ++
33041 ++#ifdef CONFIG_PAX_KERNEXEC
33042 ++ unsigned long cr0;
33043 ++
33044 ++ pax_open_kernel(cr0);
33045 ++#endif
33046 ++
33047 ++ for (cpu = 0; cpu < NR_CPUS; cpu++)
33048 ++ get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].b = 0x00cf9300;
33049 ++
33050 ++#ifdef CONFIG_PAX_KERNEXEC
33051 ++ pax_close_kernel(cr0);
33052 ++#endif
33053 ++
33054 ++ return 1;
33055 ++}
33056 ++__setup("pax_nouderef", setup_pax_nouderef);
33057 ++#endif
33058 ++
33059 ++#ifdef CONFIG_PAX_SOFTMODE
33060 ++unsigned int pax_softmode;
33061 ++
33062 ++static int __init setup_pax_softmode(char *str)
33063 ++{
33064 ++ get_option(&str, &pax_softmode);
33065 ++ return 1;
33066 ++}
33067 ++__setup("pax_softmode=", setup_pax_softmode);
33068 ++#endif
33069 ++
33070 + static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
33071 + char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
33072 + static const char *panic_later, *panic_param;
33073 +@@ -385,7 +420,7 @@ static void __init setup_nr_cpu_ids(void
33074 + }
33075 +
33076 + #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
33077 +-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
33078 ++unsigned long __per_cpu_offset[NR_CPUS] __read_only;
33079 +
33080 + EXPORT_SYMBOL(__per_cpu_offset);
33081 +
33082 +@@ -704,6 +739,7 @@ int do_one_initcall(initcall_t fn)
33083 + {
33084 + int count = preempt_count();
33085 + ktime_t t0, t1, delta;
33086 ++ const char *msg1 = "", *msg2 = "";
33087 + char msgbuf[64];
33088 + int result;
33089 +
33090 +@@ -729,15 +765,15 @@ int do_one_initcall(initcall_t fn)
33091 + sprintf(msgbuf, "error code %d ", result);
33092 +
33093 + if (preempt_count() != count) {
33094 +- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
33095 ++ msg1 = " preemption imbalance";
33096 + preempt_count() = count;
33097 + }
33098 + if (irqs_disabled()) {
33099 +- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
33100 ++ msg2 = " disabled interrupts";
33101 + local_irq_enable();
33102 + }
33103 +- if (msgbuf[0]) {
33104 +- printk("initcall %pF returned with %s\n", fn, msgbuf);
33105 ++ if (msgbuf[0] || *msg1 || *msg2) {
33106 ++ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
33107 + }
33108 +
33109 + return result;
33110 +@@ -876,6 +912,8 @@ static int __init kernel_init(void * unu
33111 + prepare_namespace();
33112 + }
33113 +
33114 ++ grsecurity_init();
33115 ++
33116 + /*
33117 + * Ok, we have completed the initial bootup, and
33118 + * we're essentially up and running. Get rid of the
33119 +diff -urNp linux-2.6.27.10/init/noinitramfs.c linux-2.6.27.10/init/noinitramfs.c
33120 +--- linux-2.6.27.10/init/noinitramfs.c 2008-11-07 12:55:34.000000000 -0500
33121 ++++ linux-2.6.27.10/init/noinitramfs.c 2008-11-18 03:38:45.000000000 -0500
33122 +@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
33123 + {
33124 + int err;
33125 +
33126 +- err = sys_mkdir("/dev", 0755);
33127 ++ err = sys_mkdir((const char __user *)"/dev", 0755);
33128 + if (err < 0)
33129 + goto out;
33130 +
33131 +@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
33132 + if (err < 0)
33133 + goto out;
33134 +
33135 +- err = sys_mkdir("/root", 0700);
33136 ++ err = sys_mkdir((const char __user *)"/root", 0700);
33137 + if (err < 0)
33138 + goto out;
33139 +
33140 +diff -urNp linux-2.6.27.10/ipc/ipc_sysctl.c linux-2.6.27.10/ipc/ipc_sysctl.c
33141 +--- linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-07 12:55:34.000000000 -0500
33142 ++++ linux-2.6.27.10/ipc/ipc_sysctl.c 2008-11-18 03:38:45.000000000 -0500
33143 +@@ -268,7 +268,7 @@ static struct ctl_table ipc_kern_table[]
33144 + .extra1 = &zero,
33145 + .extra2 = &one,
33146 + },
33147 +- {}
33148 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33149 + };
33150 +
33151 + static struct ctl_table ipc_root_table[] = {
33152 +@@ -278,7 +278,7 @@ static struct ctl_table ipc_root_table[]
33153 + .mode = 0555,
33154 + .child = ipc_kern_table,
33155 + },
33156 +- {}
33157 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33158 + };
33159 +
33160 + static int __init ipc_sysctl_init(void)
33161 +diff -urNp linux-2.6.27.10/ipc/msg.c linux-2.6.27.10/ipc/msg.c
33162 +--- linux-2.6.27.10/ipc/msg.c 2008-11-07 12:55:34.000000000 -0500
33163 ++++ linux-2.6.27.10/ipc/msg.c 2008-11-18 03:38:45.000000000 -0500
33164 +@@ -38,6 +38,7 @@
33165 + #include <linux/rwsem.h>
33166 + #include <linux/nsproxy.h>
33167 + #include <linux/ipc_namespace.h>
33168 ++#include <linux/grsecurity.h>
33169 +
33170 + #include <asm/current.h>
33171 + #include <asm/uaccess.h>
33172 +@@ -314,6 +315,7 @@ asmlinkage long sys_msgget(key_t key, in
33173 + struct ipc_namespace *ns;
33174 + struct ipc_ops msg_ops;
33175 + struct ipc_params msg_params;
33176 ++ long err;
33177 +
33178 + ns = current->nsproxy->ipc_ns;
33179 +
33180 +@@ -324,7 +326,11 @@ asmlinkage long sys_msgget(key_t key, in
33181 + msg_params.key = key;
33182 + msg_params.flg = msgflg;
33183 +
33184 +- return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
33185 ++ err = ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
33186 ++
33187 ++ gr_log_msgget(err, msgflg);
33188 ++
33189 ++ return err;
33190 + }
33191 +
33192 + static inline unsigned long
33193 +@@ -434,6 +440,7 @@ static int msgctl_down(struct ipc_namesp
33194 +
33195 + switch (cmd) {
33196 + case IPC_RMID:
33197 ++ gr_log_msgrm(ipcp->uid, ipcp->cuid);
33198 + freeque(ns, ipcp);
33199 + goto out_up;
33200 + case IPC_SET:
33201 +diff -urNp linux-2.6.27.10/ipc/sem.c linux-2.6.27.10/ipc/sem.c
33202 +--- linux-2.6.27.10/ipc/sem.c 2008-11-07 12:55:34.000000000 -0500
33203 ++++ linux-2.6.27.10/ipc/sem.c 2008-11-18 03:38:45.000000000 -0500
33204 +@@ -83,6 +83,7 @@
33205 + #include <linux/rwsem.h>
33206 + #include <linux/nsproxy.h>
33207 + #include <linux/ipc_namespace.h>
33208 ++#include <linux/grsecurity.h>
33209 +
33210 + #include <asm/uaccess.h>
33211 + #include "util.h"
33212 +@@ -313,6 +314,7 @@ asmlinkage long sys_semget(key_t key, in
33213 + struct ipc_namespace *ns;
33214 + struct ipc_ops sem_ops;
33215 + struct ipc_params sem_params;
33216 ++ long err;
33217 +
33218 + ns = current->nsproxy->ipc_ns;
33219 +
33220 +@@ -327,7 +329,11 @@ asmlinkage long sys_semget(key_t key, in
33221 + sem_params.flg = semflg;
33222 + sem_params.u.nsems = nsems;
33223 +
33224 +- return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
33225 ++ err = ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
33226 ++
33227 ++ gr_log_semget(err, semflg);
33228 ++
33229 ++ return err;
33230 + }
33231 +
33232 + /*
33233 +@@ -870,6 +876,7 @@ static int semctl_down(struct ipc_namesp
33234 +
33235 + switch(cmd){
33236 + case IPC_RMID:
33237 ++ gr_log_semrm(ipcp->uid, ipcp->cuid);
33238 + freeary(ns, ipcp);
33239 + goto out_up;
33240 + case IPC_SET:
33241 +diff -urNp linux-2.6.27.10/ipc/shm.c linux-2.6.27.10/ipc/shm.c
33242 +--- linux-2.6.27.10/ipc/shm.c 2008-11-07 12:55:34.000000000 -0500
33243 ++++ linux-2.6.27.10/ipc/shm.c 2008-11-18 03:38:45.000000000 -0500
33244 +@@ -39,6 +39,7 @@
33245 + #include <linux/nsproxy.h>
33246 + #include <linux/mount.h>
33247 + #include <linux/ipc_namespace.h>
33248 ++#include <linux/grsecurity.h>
33249 +
33250 + #include <asm/uaccess.h>
33251 +
33252 +@@ -69,6 +70,14 @@ static void shm_destroy (struct ipc_name
33253 + static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
33254 + #endif
33255 +
33256 ++#ifdef CONFIG_GRKERNSEC
33257 ++extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
33258 ++ const time_t shm_createtime, const uid_t cuid,
33259 ++ const int shmid);
33260 ++extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
33261 ++ const time_t shm_createtime);
33262 ++#endif
33263 ++
33264 + void shm_init_ns(struct ipc_namespace *ns)
33265 + {
33266 + ns->shm_ctlmax = SHMMAX;
33267 +@@ -87,6 +96,8 @@ static void do_shm_rmid(struct ipc_names
33268 + struct shmid_kernel *shp;
33269 + shp = container_of(ipcp, struct shmid_kernel, shm_perm);
33270 +
33271 ++ gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid);
33272 ++
33273 + if (shp->shm_nattch){
33274 + shp->shm_perm.mode |= SHM_DEST;
33275 + /* Do not find it any more */
33276 +@@ -392,6 +403,14 @@ static int newseg(struct ipc_namespace *
33277 + shp->shm_lprid = 0;
33278 + shp->shm_atim = shp->shm_dtim = 0;
33279 + shp->shm_ctim = get_seconds();
33280 ++#ifdef CONFIG_GRKERNSEC
33281 ++ {
33282 ++ struct timespec timeval;
33283 ++ do_posix_clock_monotonic_gettime(&timeval);
33284 ++
33285 ++ shp->shm_createtime = timeval.tv_sec;
33286 ++ }
33287 ++#endif
33288 + shp->shm_segsz = size;
33289 + shp->shm_nattch = 0;
33290 + shp->shm_file = file;
33291 +@@ -445,6 +464,7 @@ asmlinkage long sys_shmget (key_t key, s
33292 + struct ipc_namespace *ns;
33293 + struct ipc_ops shm_ops;
33294 + struct ipc_params shm_params;
33295 ++ long err;
33296 +
33297 + ns = current->nsproxy->ipc_ns;
33298 +
33299 +@@ -456,7 +476,11 @@ asmlinkage long sys_shmget (key_t key, s
33300 + shm_params.flg = shmflg;
33301 + shm_params.u.size = size;
33302 +
33303 +- return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
33304 ++ err = ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
33305 ++
33306 ++ gr_log_shmget(err, shmflg, size);
33307 ++
33308 ++ return err;
33309 + }
33310 +
33311 + static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
33312 +@@ -869,9 +893,21 @@ long do_shmat(int shmid, char __user *sh
33313 + if (err)
33314 + goto out_unlock;
33315 +
33316 ++#ifdef CONFIG_GRKERNSEC
33317 ++ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
33318 ++ shp->shm_perm.cuid, shmid) ||
33319 ++ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
33320 ++ err = -EACCES;
33321 ++ goto out_unlock;
33322 ++ }
33323 ++#endif
33324 ++
33325 + path.dentry = dget(shp->shm_file->f_path.dentry);
33326 + path.mnt = shp->shm_file->f_path.mnt;
33327 + shp->shm_nattch++;
33328 ++#ifdef CONFIG_GRKERNSEC
33329 ++ shp->shm_lapid = current->pid;
33330 ++#endif
33331 + size = i_size_read(path.dentry->d_inode);
33332 + shm_unlock(shp);
33333 +
33334 +diff -urNp linux-2.6.27.10/kernel/acct.c linux-2.6.27.10/kernel/acct.c
33335 +--- linux-2.6.27.10/kernel/acct.c 2008-11-07 12:55:34.000000000 -0500
33336 ++++ linux-2.6.27.10/kernel/acct.c 2008-11-18 03:38:45.000000000 -0500
33337 +@@ -573,7 +573,7 @@ static void do_acct_process(struct bsd_a
33338 + */
33339 + flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
33340 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
33341 +- file->f_op->write(file, (char *)&ac,
33342 ++ file->f_op->write(file, (char __user *)&ac,
33343 + sizeof(acct_t), &file->f_pos);
33344 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
33345 + set_fs(fs);
33346 +diff -urNp linux-2.6.27.10/kernel/capability.c linux-2.6.27.10/kernel/capability.c
33347 +--- linux-2.6.27.10/kernel/capability.c 2008-11-07 12:55:34.000000000 -0500
33348 ++++ linux-2.6.27.10/kernel/capability.c 2008-11-18 03:38:45.000000000 -0500
33349 +@@ -13,6 +13,7 @@
33350 + #include <linux/security.h>
33351 + #include <linux/syscalls.h>
33352 + #include <linux/pid_namespace.h>
33353 ++#include <linux/grsecurity.h>
33354 + #include <asm/uaccess.h>
33355 +
33356 + /*
33357 +@@ -498,10 +499,21 @@ asmlinkage long sys_capset(cap_user_head
33358 + */
33359 + int capable(int cap)
33360 + {
33361 +- if (has_capability(current, cap)) {
33362 ++ if (has_capability(current, cap) && gr_task_is_capable(current, cap)) {
33363 + current->flags |= PF_SUPERPRIV;
33364 + return 1;
33365 + }
33366 + return 0;
33367 + }
33368 ++
33369 ++int capable_nolog(int cap)
33370 ++{
33371 ++ if (has_capability(current, cap) && gr_is_capable_nolog(cap)) {
33372 ++ current->flags |= PF_SUPERPRIV;
33373 ++ return 1;
33374 ++ }
33375 ++ return 0;
33376 ++}
33377 ++
33378 + EXPORT_SYMBOL(capable);
33379 ++EXPORT_SYMBOL(capable_nolog);
33380 +diff -urNp linux-2.6.27.10/kernel/configs.c linux-2.6.27.10/kernel/configs.c
33381 +--- linux-2.6.27.10/kernel/configs.c 2008-11-07 12:55:34.000000000 -0500
33382 ++++ linux-2.6.27.10/kernel/configs.c 2008-11-18 03:38:45.000000000 -0500
33383 +@@ -79,8 +79,19 @@ static int __init ikconfig_init(void)
33384 + struct proc_dir_entry *entry;
33385 +
33386 + /* create the current config file */
33387 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
33388 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
33389 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
33390 ++ &ikconfig_file_ops);
33391 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33392 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
33393 ++ &ikconfig_file_ops);
33394 ++#endif
33395 ++#else
33396 + entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
33397 + &ikconfig_file_ops);
33398 ++#endif
33399 ++
33400 + if (!entry)
33401 + return -ENOMEM;
33402 +
33403 +diff -urNp linux-2.6.27.10/kernel/cpu.c linux-2.6.27.10/kernel/cpu.c
33404 +--- linux-2.6.27.10/kernel/cpu.c 2008-11-07 12:55:34.000000000 -0500
33405 ++++ linux-2.6.27.10/kernel/cpu.c 2008-11-18 03:38:45.000000000 -0500
33406 +@@ -40,7 +40,7 @@ EXPORT_SYMBOL(cpu_possible_map);
33407 + /* Serializes the updates to cpu_online_map, cpu_present_map */
33408 + static DEFINE_MUTEX(cpu_add_remove_lock);
33409 +
33410 +-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
33411 ++static RAW_NOTIFIER_HEAD(cpu_chain);
33412 +
33413 + /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
33414 + * Should always be manipulated under cpu_add_remove_lock
33415 +diff -urNp linux-2.6.27.10/kernel/exit.c linux-2.6.27.10/kernel/exit.c
33416 +--- linux-2.6.27.10/kernel/exit.c 2008-11-07 12:55:34.000000000 -0500
33417 ++++ linux-2.6.27.10/kernel/exit.c 2008-11-29 19:01:27.000000000 -0500
33418 +@@ -40,13 +40,17 @@
33419 + #include <linux/cn_proc.h>
33420 + #include <linux/mutex.h>
33421 + #include <linux/futex.h>
33422 +-#include <linux/compat.h>
33423 + #include <linux/pipe_fs_i.h>
33424 + #include <linux/audit.h> /* for audit_free() */
33425 + #include <linux/resource.h>
33426 + #include <linux/blkdev.h>
33427 + #include <linux/task_io_accounting_ops.h>
33428 + #include <linux/tracehook.h>
33429 ++#include <linux/grsecurity.h>
33430 ++
33431 ++#ifdef CONFIG_GRKERNSEC
33432 ++extern rwlock_t grsec_exec_file_lock;
33433 ++#endif
33434 +
33435 + #include <asm/uaccess.h>
33436 + #include <asm/unistd.h>
33437 +@@ -133,7 +137,6 @@ static void __exit_signal(struct task_st
33438 + * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
33439 + */
33440 + flush_sigqueue(&tsk->pending);
33441 +-
33442 + tsk->signal = NULL;
33443 + tsk->sighand = NULL;
33444 + spin_unlock(&sighand->siglock);
33445 +@@ -158,6 +161,8 @@ void release_task(struct task_struct * p
33446 + struct task_struct *leader;
33447 + int zap_leader;
33448 + repeat:
33449 ++ gr_del_task_from_ip_table(p);
33450 ++
33451 + tracehook_prepare_release_task(p);
33452 + atomic_dec(&p->user->processes);
33453 + proc_flush_task(p);
33454 +@@ -321,11 +326,22 @@ static void reparent_to_kthreadd(void)
33455 + {
33456 + write_lock_irq(&tasklist_lock);
33457 +
33458 ++#ifdef CONFIG_GRKERNSEC
33459 ++ write_lock(&grsec_exec_file_lock);
33460 ++ if (current->exec_file) {
33461 ++ fput(current->exec_file);
33462 ++ current->exec_file = NULL;
33463 ++ }
33464 ++ write_unlock(&grsec_exec_file_lock);
33465 ++#endif
33466 ++
33467 + ptrace_unlink(current);
33468 + /* Reparent to init */
33469 + current->real_parent = current->parent = kthreadd_task;
33470 + list_move_tail(&current->sibling, &current->real_parent->children);
33471 +
33472 ++ gr_set_kernel_label(current);
33473 ++
33474 + /* Set the exit signal to SIGCHLD so we signal init on exit */
33475 + current->exit_signal = SIGCHLD;
33476 +
33477 +@@ -419,6 +435,17 @@ void daemonize(const char *name, ...)
33478 + vsnprintf(current->comm, sizeof(current->comm), name, args);
33479 + va_end(args);
33480 +
33481 ++#ifdef CONFIG_GRKERNSEC
33482 ++ write_lock(&grsec_exec_file_lock);
33483 ++ if (current->exec_file) {
33484 ++ fput(current->exec_file);
33485 ++ current->exec_file = NULL;
33486 ++ }
33487 ++ write_unlock(&grsec_exec_file_lock);
33488 ++#endif
33489 ++
33490 ++ gr_set_kernel_label(current);
33491 ++
33492 + /*
33493 + * If we were started as result of loading a module, close all of the
33494 + * user space pages. We don't need them, and if we didn't close them
33495 +@@ -1054,14 +1081,6 @@ NORET_TYPE void do_exit(long code)
33496 + exit_itimers(tsk->signal);
33497 + }
33498 + acct_collect(code, group_dead);
33499 +-#ifdef CONFIG_FUTEX
33500 +- if (unlikely(tsk->robust_list))
33501 +- exit_robust_list(tsk);
33502 +-#ifdef CONFIG_COMPAT
33503 +- if (unlikely(tsk->compat_robust_list))
33504 +- compat_exit_robust_list(tsk);
33505 +-#endif
33506 +-#endif
33507 + if (group_dead)
33508 + tty_audit_exit();
33509 + if (unlikely(tsk->audit_context))
33510 +@@ -1070,6 +1089,9 @@ NORET_TYPE void do_exit(long code)
33511 + tsk->exit_code = code;
33512 + taskstats_exit(tsk, group_dead);
33513 +
33514 ++ gr_acl_handle_psacct(tsk, code);
33515 ++ gr_acl_handle_exit();
33516 ++
33517 + exit_mm(tsk);
33518 +
33519 + if (group_dead)
33520 +@@ -1272,7 +1294,7 @@ static int wait_task_zombie(struct task_
33521 + if (unlikely(options & WNOWAIT)) {
33522 + uid_t uid = p->uid;
33523 + int exit_code = p->exit_code;
33524 +- int why, status;
33525 ++ int why;
33526 +
33527 + get_task_struct(p);
33528 + read_unlock(&tasklist_lock);
33529 +diff -urNp linux-2.6.27.10/kernel/fork.c linux-2.6.27.10/kernel/fork.c
33530 +--- linux-2.6.27.10/kernel/fork.c 2008-12-21 01:16:52.000000000 -0500
33531 ++++ linux-2.6.27.10/kernel/fork.c 2008-12-21 01:13:46.000000000 -0500
33532 +@@ -40,6 +40,7 @@
33533 + #include <linux/jiffies.h>
33534 + #include <linux/tracehook.h>
33535 + #include <linux/futex.h>
33536 ++#include <linux/compat.h>
33537 + #include <linux/task_io_accounting_ops.h>
33538 + #include <linux/rcupdate.h>
33539 + #include <linux/ptrace.h>
33540 +@@ -58,6 +59,7 @@
33541 + #include <linux/tty.h>
33542 + #include <linux/proc_fs.h>
33543 + #include <linux/blkdev.h>
33544 ++#include <linux/grsecurity.h>
33545 +
33546 + #include <asm/pgtable.h>
33547 + #include <asm/pgalloc.h>
33548 +@@ -234,7 +236,7 @@ static struct task_struct *dup_task_stru
33549 + setup_thread_stack(tsk, orig);
33550 +
33551 + #ifdef CONFIG_CC_STACKPROTECTOR
33552 +- tsk->stack_canary = get_random_int();
33553 ++ tsk->stack_canary = pax_get_random_long();
33554 + #endif
33555 +
33556 + /* One for us, one for whoever does the "release_task()" (usually parent) */
33557 +@@ -271,8 +273,8 @@ static int dup_mmap(struct mm_struct *mm
33558 + mm->locked_vm = 0;
33559 + mm->mmap = NULL;
33560 + mm->mmap_cache = NULL;
33561 +- mm->free_area_cache = oldmm->mmap_base;
33562 +- mm->cached_hole_size = ~0UL;
33563 ++ mm->free_area_cache = oldmm->free_area_cache;
33564 ++ mm->cached_hole_size = oldmm->cached_hole_size;
33565 + mm->map_count = 0;
33566 + cpus_clear(mm->cpu_vm_mask);
33567 + mm->mm_rb = RB_ROOT;
33568 +@@ -309,6 +311,7 @@ static int dup_mmap(struct mm_struct *mm
33569 + tmp->vm_flags &= ~VM_LOCKED;
33570 + tmp->vm_mm = mm;
33571 + tmp->vm_next = NULL;
33572 ++ tmp->vm_mirror = NULL;
33573 + anon_vma_link(tmp);
33574 + file = tmp->vm_file;
33575 + if (file) {
33576 +@@ -356,6 +359,31 @@ static int dup_mmap(struct mm_struct *mm
33577 + if (retval)
33578 + goto out;
33579 + }
33580 ++
33581 ++#ifdef CONFIG_PAX_SEGMEXEC
33582 ++ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
33583 ++ struct vm_area_struct *mpnt_m;
33584 ++
33585 ++ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
33586 ++ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
33587 ++
33588 ++ if (!mpnt->vm_mirror)
33589 ++ continue;
33590 ++
33591 ++ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
33592 ++ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
33593 ++ mpnt->vm_mirror = mpnt_m;
33594 ++ } else {
33595 ++ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
33596 ++ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
33597 ++ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
33598 ++ mpnt->vm_mirror->vm_mirror = mpnt;
33599 ++ }
33600 ++ }
33601 ++ BUG_ON(mpnt_m);
33602 ++ }
33603 ++#endif
33604 ++
33605 + /* a new mm has just been created */
33606 + arch_dup_mmap(oldmm, mm);
33607 + retval = 0;
33608 +@@ -521,6 +549,18 @@ void mm_release(struct task_struct *tsk,
33609 + {
33610 + struct completion *vfork_done = tsk->vfork_done;
33611 +
33612 ++ /* Get rid of any futexes when releasing the mm */
33613 ++#ifdef CONFIG_FUTEX
33614 ++ if (unlikely(tsk->robust_list))
33615 ++ exit_robust_list(tsk);
33616 ++ tsk->robust_list = NULL;
33617 ++#ifdef CONFIG_COMPAT
33618 ++ if (unlikely(tsk->compat_robust_list))
33619 ++ compat_exit_robust_list(tsk);
33620 ++ tsk->compat_robust_list = NULL;
33621 ++#endif
33622 ++#endif
33623 ++
33624 + /* Get rid of any cached register state */
33625 + deactivate_mm(tsk, mm);
33626 +
33627 +@@ -539,7 +579,7 @@ void mm_release(struct task_struct *tsk,
33628 + if (tsk->clear_child_tid
33629 + && !(tsk->flags & PF_SIGNALED)
33630 + && atomic_read(&mm->mm_users) > 1) {
33631 +- u32 __user * tidptr = tsk->clear_child_tid;
33632 ++ pid_t __user * tidptr = tsk->clear_child_tid;
33633 + tsk->clear_child_tid = NULL;
33634 +
33635 + /*
33636 +@@ -547,7 +587,7 @@ void mm_release(struct task_struct *tsk,
33637 + * not set up a proper pointer then tough luck.
33638 + */
33639 + put_user(0, tidptr);
33640 +- sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
33641 ++ sys_futex((u32 __user *)tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
33642 + }
33643 + }
33644 +
33645 +@@ -942,6 +982,9 @@ static struct task_struct *copy_process(
33646 + DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
33647 + #endif
33648 + retval = -EAGAIN;
33649 ++
33650 ++ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->user->processes), 0);
33651 ++
33652 + if (atomic_read(&p->user->processes) >=
33653 + p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
33654 + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
33655 +@@ -1108,6 +1151,8 @@ static struct task_struct *copy_process(
33656 + goto bad_fork_free_pid;
33657 + }
33658 +
33659 ++ gr_copy_label(p);
33660 ++
33661 + p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
33662 + /*
33663 + * Clear TID on mm_release()?
33664 +@@ -1293,6 +1338,8 @@ bad_fork_cleanup_count:
33665 + bad_fork_free:
33666 + free_task(p);
33667 + fork_out:
33668 ++ gr_log_forkfail(retval);
33669 ++
33670 + return ERR_PTR(retval);
33671 + }
33672 +
33673 +@@ -1369,6 +1416,8 @@ long do_fork(unsigned long clone_flags,
33674 + if (clone_flags & CLONE_PARENT_SETTID)
33675 + put_user(nr, parent_tidptr);
33676 +
33677 ++ gr_handle_brute_check();
33678 ++
33679 + if (clone_flags & CLONE_VFORK) {
33680 + p->vfork_done = &vfork;
33681 + init_completion(&vfork);
33682 +diff -urNp linux-2.6.27.10/kernel/futex.c linux-2.6.27.10/kernel/futex.c
33683 +--- linux-2.6.27.10/kernel/futex.c 2008-11-07 12:55:34.000000000 -0500
33684 ++++ linux-2.6.27.10/kernel/futex.c 2008-11-18 03:38:45.000000000 -0500
33685 +@@ -188,6 +188,11 @@ static int get_futex_key(u32 __user *uad
33686 + struct page *page;
33687 + int err;
33688 +
33689 ++#ifdef CONFIG_PAX_SEGMEXEC
33690 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
33691 ++ return -EFAULT;
33692 ++#endif
33693 ++
33694 + /*
33695 + * The futex address must be "naturally" aligned.
33696 + */
33697 +@@ -214,8 +219,8 @@ static int get_futex_key(u32 __user *uad
33698 + * The futex is hashed differently depending on whether
33699 + * it's in a shared or private mapping. So check vma first.
33700 + */
33701 +- vma = find_extend_vma(mm, address);
33702 +- if (unlikely(!vma))
33703 ++ vma = find_vma(mm, address);
33704 ++ if (unlikely(!vma || address < vma->vm_start))
33705 + return -EFAULT;
33706 +
33707 + /*
33708 +@@ -1345,7 +1350,7 @@ static int futex_wait(u32 __user *uaddr,
33709 + struct restart_block *restart;
33710 + restart = &current_thread_info()->restart_block;
33711 + restart->fn = futex_wait_restart;
33712 +- restart->futex.uaddr = (u32 *)uaddr;
33713 ++ restart->futex.uaddr = uaddr;
33714 + restart->futex.val = val;
33715 + restart->futex.time = abs_time->tv64;
33716 + restart->futex.bitset = bitset;
33717 +@@ -1906,7 +1911,7 @@ retry:
33718 + */
33719 + static inline int fetch_robust_entry(struct robust_list __user **entry,
33720 + struct robust_list __user * __user *head,
33721 +- int *pi)
33722 ++ unsigned int *pi)
33723 + {
33724 + unsigned long uentry;
33725 +
33726 +diff -urNp linux-2.6.27.10/kernel/irq/handle.c linux-2.6.27.10/kernel/irq/handle.c
33727 +--- linux-2.6.27.10/kernel/irq/handle.c 2008-11-07 12:55:34.000000000 -0500
33728 ++++ linux-2.6.27.10/kernel/irq/handle.c 2008-11-18 03:38:45.000000000 -0500
33729 +@@ -55,7 +55,8 @@ struct irq_desc irq_desc[NR_IRQS] __cach
33730 + .depth = 1,
33731 + .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
33732 + #ifdef CONFIG_SMP
33733 +- .affinity = CPU_MASK_ALL
33734 ++ .affinity = CPU_MASK_ALL,
33735 ++ .cpu = 0,
33736 + #endif
33737 + }
33738 + };
33739 +diff -urNp linux-2.6.27.10/kernel/kallsyms.c linux-2.6.27.10/kernel/kallsyms.c
33740 +--- linux-2.6.27.10/kernel/kallsyms.c 2008-11-07 12:55:34.000000000 -0500
33741 ++++ linux-2.6.27.10/kernel/kallsyms.c 2008-11-18 03:38:45.000000000 -0500
33742 +@@ -62,6 +62,19 @@ static inline int is_kernel_text(unsigne
33743 +
33744 + static inline int is_kernel(unsigned long addr)
33745 + {
33746 ++
33747 ++#ifdef CONFIG_PAX_KERNEXEC
33748 ++
33749 ++#ifdef CONFIG_MODULES
33750 ++ if ((unsigned long)MODULES_VADDR <= ktla_ktva(addr) &&
33751 ++ ktla_ktva(addr) < (unsigned long)MODULES_END)
33752 ++ return 0;
33753 ++#endif
33754 ++
33755 ++ if (is_kernel_inittext(addr))
33756 ++ return 1;
33757 ++#endif
33758 ++
33759 + if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
33760 + return 1;
33761 + return in_gate_area_no_task(addr);
33762 +@@ -366,7 +379,6 @@ static unsigned long get_ksymbol_core(st
33763 +
33764 + static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
33765 + {
33766 +- iter->name[0] = '\0';
33767 + iter->nameoff = get_symbol_offset(new_pos);
33768 + iter->pos = new_pos;
33769 + }
33770 +@@ -450,7 +462,7 @@ static int kallsyms_open(struct inode *i
33771 + struct kallsym_iter *iter;
33772 + int ret;
33773 +
33774 +- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
33775 ++ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
33776 + if (!iter)
33777 + return -ENOMEM;
33778 + reset_iter(iter, 0);
33779 +@@ -472,7 +484,15 @@ static const struct file_operations kall
33780 +
33781 + static int __init kallsyms_init(void)
33782 + {
33783 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
33784 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
33785 ++ proc_create("kallsyms", S_IFREG | S_IRUSR, NULL, &kallsyms_operations);
33786 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33787 ++ proc_create("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL, &kallsyms_operations);
33788 ++#endif
33789 ++#else
33790 + proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
33791 ++#endif
33792 + return 0;
33793 + }
33794 + __initcall(kallsyms_init);
33795 +diff -urNp linux-2.6.27.10/kernel/kmod.c linux-2.6.27.10/kernel/kmod.c
33796 +--- linux-2.6.27.10/kernel/kmod.c 2008-11-07 12:55:34.000000000 -0500
33797 ++++ linux-2.6.27.10/kernel/kmod.c 2008-11-18 03:38:45.000000000 -0500
33798 +@@ -108,7 +108,7 @@ int request_module(const char *fmt, ...)
33799 + return -ENOMEM;
33800 + }
33801 +
33802 +- ret = call_usermodehelper(modprobe_path, argv, envp, 1);
33803 ++ ret = call_usermodehelper(modprobe_path, argv, envp, UMH_WAIT_PROC);
33804 + atomic_dec(&kmod_concurrent);
33805 + return ret;
33806 + }
33807 +diff -urNp linux-2.6.27.10/kernel/kprobes.c linux-2.6.27.10/kernel/kprobes.c
33808 +--- linux-2.6.27.10/kernel/kprobes.c 2008-11-07 12:55:34.000000000 -0500
33809 ++++ linux-2.6.27.10/kernel/kprobes.c 2008-11-18 03:38:45.000000000 -0500
33810 +@@ -182,7 +182,7 @@ kprobe_opcode_t __kprobes *get_insn_slot
33811 + * kernel image and loaded module images reside. This is required
33812 + * so x86_64 can correctly handle the %rip-relative fixups.
33813 + */
33814 +- kip->insns = module_alloc(PAGE_SIZE);
33815 ++ kip->insns = module_alloc_exec(PAGE_SIZE);
33816 + if (!kip->insns) {
33817 + kfree(kip);
33818 + return NULL;
33819 +@@ -214,7 +214,7 @@ static int __kprobes collect_one_slot(st
33820 + hlist_add_head(&kip->hlist,
33821 + &kprobe_insn_pages);
33822 + } else {
33823 +- module_free(NULL, kip->insns);
33824 ++ module_free_exec(NULL, kip->insns);
33825 + kfree(kip);
33826 + }
33827 + return 1;
33828 +diff -urNp linux-2.6.27.10/kernel/lockdep.c linux-2.6.27.10/kernel/lockdep.c
33829 +--- linux-2.6.27.10/kernel/lockdep.c 2008-11-07 12:55:34.000000000 -0500
33830 ++++ linux-2.6.27.10/kernel/lockdep.c 2008-11-18 03:38:45.000000000 -0500
33831 +@@ -627,6 +627,10 @@ static int static_obj(void *obj)
33832 + int i;
33833 + #endif
33834 +
33835 ++#ifdef CONFIG_PAX_KERNEXEC
33836 ++ start = (unsigned long )&_data;
33837 ++#endif
33838 ++
33839 + /*
33840 + * static variable?
33841 + */
33842 +@@ -638,9 +642,12 @@ static int static_obj(void *obj)
33843 + * percpu var?
33844 + */
33845 + for_each_possible_cpu(i) {
33846 ++#ifdef CONFIG_X86_32
33847 ++ start = per_cpu_offset(i);
33848 ++#else
33849 + start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
33850 +- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
33851 +- + per_cpu_offset(i);
33852 ++#endif
33853 ++ end = start + PERCPU_ENOUGH_ROOM;
33854 +
33855 + if ((addr >= start) && (addr < end))
33856 + return 1;
33857 +diff -urNp linux-2.6.27.10/kernel/module.c linux-2.6.27.10/kernel/module.c
33858 +--- linux-2.6.27.10/kernel/module.c 2008-11-07 12:55:34.000000000 -0500
33859 ++++ linux-2.6.27.10/kernel/module.c 2008-12-21 01:17:47.000000000 -0500
33860 +@@ -44,6 +44,11 @@
33861 + #include <linux/unwind.h>
33862 + #include <asm/uaccess.h>
33863 + #include <asm/cacheflush.h>
33864 ++
33865 ++#ifdef CONFIG_PAX_KERNEXEC
33866 ++#include <asm/desc.h>
33867 ++#endif
33868 ++
33869 + #include <linux/license.h>
33870 + #include <asm/sections.h>
33871 +
33872 +@@ -71,7 +76,10 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
33873 + static BLOCKING_NOTIFIER_HEAD(module_notify_list);
33874 +
33875 + /* Bounds of module allocation, for speeding __module_text_address */
33876 +-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
33877 ++static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
33878 ++static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
33879 ++
33880 ++extern int gr_check_modstop(void);
33881 +
33882 + int register_module_notifier(struct notifier_block * nb)
33883 + {
33884 +@@ -217,7 +225,7 @@ static bool each_symbol(bool (*fn)(const
33885 + return true;
33886 +
33887 + list_for_each_entry(mod, &modules, list) {
33888 +- struct symsearch arr[] = {
33889 ++ struct symsearch modarr[] = {
33890 + { mod->syms, mod->syms + mod->num_syms, mod->crcs,
33891 + NOT_GPL_ONLY, false },
33892 + { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
33893 +@@ -239,7 +247,7 @@ static bool each_symbol(bool (*fn)(const
33894 + #endif
33895 + };
33896 +
33897 +- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
33898 ++ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
33899 + return true;
33900 + }
33901 + return false;
33902 +@@ -375,6 +383,8 @@ static inline unsigned int block_size(in
33903 + return val;
33904 + }
33905 +
33906 ++EXPORT_SYMBOL(__per_cpu_start);
33907 ++
33908 + static void *percpu_modalloc(unsigned long size, unsigned long align,
33909 + const char *name)
33910 + {
33911 +@@ -382,7 +392,7 @@ static void *percpu_modalloc(unsigned lo
33912 + unsigned int i;
33913 + void *ptr;
33914 +
33915 +- if (align > PAGE_SIZE) {
33916 ++ if (align-1 >= PAGE_SIZE) {
33917 + printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
33918 + name, align, PAGE_SIZE);
33919 + align = PAGE_SIZE;
33920 +@@ -464,7 +474,11 @@ static void percpu_modcopy(void *pcpudes
33921 + int cpu;
33922 +
33923 + for_each_possible_cpu(cpu)
33924 ++#ifdef CONFIG_X86_32
33925 ++ memcpy(pcpudest + __per_cpu_offset[cpu], from, size);
33926 ++#else
33927 + memcpy(pcpudest + per_cpu_offset(cpu), from, size);
33928 ++#endif
33929 + }
33930 +
33931 + static int percpu_modinit(void)
33932 +@@ -722,6 +736,9 @@ sys_delete_module(const char __user *nam
33933 + char name[MODULE_NAME_LEN];
33934 + int ret, forced = 0;
33935 +
33936 ++ if (gr_check_modstop())
33937 ++ return -EPERM;
33938 ++
33939 + if (!capable(CAP_SYS_MODULE))
33940 + return -EPERM;
33941 +
33942 +@@ -1430,16 +1447,19 @@ static void free_module(struct module *m
33943 + module_unload_free(mod);
33944 +
33945 + /* This may be NULL, but that's OK */
33946 +- module_free(mod, mod->module_init);
33947 ++ module_free(mod, mod->module_init_rw);
33948 ++ module_free_exec(mod, mod->module_init_rx);
33949 + kfree(mod->args);
33950 + if (mod->percpu)
33951 + percpu_modfree(mod->percpu);
33952 +
33953 + /* Free lock-classes: */
33954 +- lockdep_free_key_range(mod->module_core, mod->core_size);
33955 ++ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
33956 ++ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
33957 +
33958 + /* Finally, free the core (containing the module structure) */
33959 +- module_free(mod, mod->module_core);
33960 ++ module_free_exec(mod, mod->module_core_rx);
33961 ++ module_free(mod, mod->module_core_rw);
33962 + }
33963 +
33964 + void *__symbol_get(const char *symbol)
33965 +@@ -1505,10 +1525,14 @@ static int simplify_symbols(Elf_Shdr *se
33966 + struct module *mod)
33967 + {
33968 + Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
33969 +- unsigned long secbase;
33970 ++ unsigned long secbase, symbol;
33971 + unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
33972 + int ret = 0;
33973 +
33974 ++#ifdef CONFIG_PAX_KERNEXEC
33975 ++ unsigned long cr0;
33976 ++#endif
33977 ++
33978 + for (i = 1; i < n; i++) {
33979 + switch (sym[i].st_shndx) {
33980 + case SHN_COMMON:
33981 +@@ -1527,10 +1551,19 @@ static int simplify_symbols(Elf_Shdr *se
33982 + break;
33983 +
33984 + case SHN_UNDEF:
33985 +- sym[i].st_value
33986 +- = resolve_symbol(sechdrs, versindex,
33987 ++ symbol = resolve_symbol(sechdrs, versindex,
33988 + strtab + sym[i].st_name, mod);
33989 +
33990 ++#ifdef CONFIG_PAX_KERNEXEC
33991 ++ pax_open_kernel(cr0);
33992 ++#endif
33993 ++
33994 ++ sym[i].st_value = symbol;
33995 ++
33996 ++#ifdef CONFIG_PAX_KERNEXEC
33997 ++ pax_close_kernel(cr0);
33998 ++#endif
33999 ++
34000 + /* Ok if resolved. */
34001 + if (!IS_ERR_VALUE(sym[i].st_value))
34002 + break;
34003 +@@ -1545,11 +1578,27 @@ static int simplify_symbols(Elf_Shdr *se
34004 +
34005 + default:
34006 + /* Divert to percpu allocation if a percpu var. */
34007 +- if (sym[i].st_shndx == pcpuindex)
34008 ++ if (sym[i].st_shndx == pcpuindex) {
34009 ++
34010 ++#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
34011 ++ secbase = (unsigned long)mod->percpu - (unsigned long)__per_cpu_start;
34012 ++#else
34013 + secbase = (unsigned long)mod->percpu;
34014 +- else
34015 ++#endif
34016 ++
34017 ++ } else
34018 + secbase = sechdrs[sym[i].st_shndx].sh_addr;
34019 ++
34020 ++#ifdef CONFIG_PAX_KERNEXEC
34021 ++ pax_open_kernel(cr0);
34022 ++#endif
34023 ++
34024 + sym[i].st_value += secbase;
34025 ++
34026 ++#ifdef CONFIG_PAX_KERNEXEC
34027 ++ pax_close_kernel(cr0);
34028 ++#endif
34029 ++
34030 + break;
34031 + }
34032 + }
34033 +@@ -1601,11 +1650,12 @@ static void layout_sections(struct modul
34034 + || strncmp(secstrings + s->sh_name,
34035 + ".init", 5) == 0)
34036 + continue;
34037 +- s->sh_entsize = get_offset(&mod->core_size, s);
34038 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
34039 ++ s->sh_entsize = get_offset(&mod->core_size_rw, s);
34040 ++ else
34041 ++ s->sh_entsize = get_offset(&mod->core_size_rx, s);
34042 + DEBUGP("\t%s\n", secstrings + s->sh_name);
34043 + }
34044 +- if (m == 0)
34045 +- mod->core_text_size = mod->core_size;
34046 + }
34047 +
34048 + DEBUGP("Init section allocation order:\n");
34049 +@@ -1619,12 +1669,13 @@ static void layout_sections(struct modul
34050 + || strncmp(secstrings + s->sh_name,
34051 + ".init", 5) != 0)
34052 + continue;
34053 +- s->sh_entsize = (get_offset(&mod->init_size, s)
34054 +- | INIT_OFFSET_MASK);
34055 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
34056 ++ s->sh_entsize = get_offset(&mod->init_size_rw, s);
34057 ++ else
34058 ++ s->sh_entsize = get_offset(&mod->init_size_rx, s);
34059 ++ s->sh_entsize |= INIT_OFFSET_MASK;
34060 + DEBUGP("\t%s\n", secstrings + s->sh_name);
34061 + }
34062 +- if (m == 0)
34063 +- mod->init_text_size = mod->init_size;
34064 + }
34065 + }
34066 +
34067 +@@ -1764,14 +1815,31 @@ static void add_kallsyms(struct module *
34068 + {
34069 + unsigned int i;
34070 +
34071 ++#ifdef CONFIG_PAX_KERNEXEC
34072 ++ unsigned long cr0;
34073 ++#endif
34074 ++
34075 + mod->symtab = (void *)sechdrs[symindex].sh_addr;
34076 + mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
34077 + mod->strtab = (void *)sechdrs[strindex].sh_addr;
34078 +
34079 + /* Set types up while we still have access to sections. */
34080 +- for (i = 0; i < mod->num_symtab; i++)
34081 +- mod->symtab[i].st_info
34082 +- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
34083 ++
34084 ++ for (i = 0; i < mod->num_symtab; i++) {
34085 ++ char type = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
34086 ++
34087 ++#ifdef CONFIG_PAX_KERNEXEC
34088 ++ pax_open_kernel(cr0);
34089 ++#endif
34090 ++
34091 ++ mod->symtab[i].st_info = type;
34092 ++
34093 ++#ifdef CONFIG_PAX_KERNEXEC
34094 ++ pax_close_kernel(cr0);
34095 ++#endif
34096 ++
34097 ++ }
34098 ++
34099 + }
34100 + #else
34101 + static inline void add_kallsyms(struct module *mod,
34102 +@@ -1783,16 +1851,30 @@ static inline void add_kallsyms(struct m
34103 + }
34104 + #endif /* CONFIG_KALLSYMS */
34105 +
34106 +-static void *module_alloc_update_bounds(unsigned long size)
34107 ++static void *module_alloc_update_bounds_rw(unsigned long size)
34108 + {
34109 + void *ret = module_alloc(size);
34110 +
34111 + if (ret) {
34112 + /* Update module bounds. */
34113 +- if ((unsigned long)ret < module_addr_min)
34114 +- module_addr_min = (unsigned long)ret;
34115 +- if ((unsigned long)ret + size > module_addr_max)
34116 +- module_addr_max = (unsigned long)ret + size;
34117 ++ if ((unsigned long)ret < module_addr_min_rw)
34118 ++ module_addr_min_rw = (unsigned long)ret;
34119 ++ if ((unsigned long)ret + size > module_addr_max_rw)
34120 ++ module_addr_max_rw = (unsigned long)ret + size;
34121 ++ }
34122 ++ return ret;
34123 ++}
34124 ++
34125 ++static void *module_alloc_update_bounds_rx(unsigned long size)
34126 ++{
34127 ++ void *ret = module_alloc_exec(size);
34128 ++
34129 ++ if (ret) {
34130 ++ /* Update module bounds. */
34131 ++ if ((unsigned long)ret < module_addr_min_rx)
34132 ++ module_addr_min_rx = (unsigned long)ret;
34133 ++ if ((unsigned long)ret + size > module_addr_max_rx)
34134 ++ module_addr_max_rx = (unsigned long)ret + size;
34135 + }
34136 + return ret;
34137 + }
34138 +@@ -1837,6 +1919,10 @@ static noinline struct module *load_modu
34139 + struct exception_table_entry *extable;
34140 + mm_segment_t old_fs;
34141 +
34142 ++#ifdef CONFIG_PAX_KERNEXEC
34143 ++ unsigned long cr0;
34144 ++#endif
34145 ++
34146 + DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
34147 + umod, len, uargs);
34148 + if (len < sizeof(*hdr))
34149 +@@ -1998,22 +2084,57 @@ static noinline struct module *load_modu
34150 + layout_sections(mod, hdr, sechdrs, secstrings);
34151 +
34152 + /* Do the allocs. */
34153 +- ptr = module_alloc_update_bounds(mod->core_size);
34154 ++ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
34155 + if (!ptr) {
34156 + err = -ENOMEM;
34157 + goto free_percpu;
34158 + }
34159 +- memset(ptr, 0, mod->core_size);
34160 +- mod->module_core = ptr;
34161 ++ memset(ptr, 0, mod->core_size_rw);
34162 ++ mod->module_core_rw = ptr;
34163 ++
34164 ++ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
34165 ++ if (!ptr && mod->init_size_rw) {
34166 ++ err = -ENOMEM;
34167 ++ goto free_core_rw;
34168 ++ }
34169 ++ memset(ptr, 0, mod->init_size_rw);
34170 ++ mod->module_init_rw = ptr;
34171 ++
34172 ++ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
34173 ++ if (!ptr) {
34174 ++ err = -ENOMEM;
34175 ++ goto free_init_rw;
34176 ++ }
34177 ++
34178 ++#ifdef CONFIG_PAX_KERNEXEC
34179 ++ pax_open_kernel(cr0);
34180 ++#endif
34181 ++
34182 ++ memset(ptr, 0, mod->core_size_rx);
34183 +
34184 +- ptr = module_alloc_update_bounds(mod->init_size);
34185 +- if (!ptr && mod->init_size) {
34186 ++#ifdef CONFIG_PAX_KERNEXEC
34187 ++ pax_close_kernel(cr0);
34188 ++#endif
34189 ++
34190 ++ mod->module_core_rx = ptr;
34191 ++
34192 ++ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
34193 ++ if (!ptr && mod->init_size_rx) {
34194 + err = -ENOMEM;
34195 +- goto free_core;
34196 ++ goto free_core_rx;
34197 + }
34198 +- memset(ptr, 0, mod->init_size);
34199 +- mod->module_init = ptr;
34200 +
34201 ++#ifdef CONFIG_PAX_KERNEXEC
34202 ++ pax_open_kernel(cr0);
34203 ++#endif
34204 ++
34205 ++ memset(ptr, 0, mod->init_size_rx);
34206 ++
34207 ++#ifdef CONFIG_PAX_KERNEXEC
34208 ++ pax_close_kernel(cr0);
34209 ++#endif
34210 ++
34211 ++ mod->module_init_rx = ptr;
34212 + /* Transfer each section which specifies SHF_ALLOC */
34213 + DEBUGP("final section addresses:\n");
34214 + for (i = 0; i < hdr->e_shnum; i++) {
34215 +@@ -2022,17 +2143,41 @@ static noinline struct module *load_modu
34216 + if (!(sechdrs[i].sh_flags & SHF_ALLOC))
34217 + continue;
34218 +
34219 +- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
34220 +- dest = mod->module_init
34221 +- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
34222 +- else
34223 +- dest = mod->module_core + sechdrs[i].sh_entsize;
34224 ++ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
34225 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
34226 ++ dest = mod->module_init_rw
34227 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
34228 ++ else
34229 ++ dest = mod->module_init_rx
34230 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
34231 ++ } else {
34232 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
34233 ++ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
34234 ++ else
34235 ++ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
34236 ++ }
34237 +
34238 +- if (sechdrs[i].sh_type != SHT_NOBITS)
34239 +- memcpy(dest, (void *)sechdrs[i].sh_addr,
34240 +- sechdrs[i].sh_size);
34241 ++ if (sechdrs[i].sh_type != SHT_NOBITS) {
34242 ++
34243 ++#ifdef CONFIG_PAX_KERNEXEC
34244 ++ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
34245 ++ pax_open_kernel(cr0);
34246 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
34247 ++ pax_close_kernel(cr0);
34248 ++ } else
34249 ++#endif
34250 ++
34251 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
34252 ++ }
34253 + /* Update sh_addr to point to copy in image. */
34254 +- sechdrs[i].sh_addr = (unsigned long)dest;
34255 ++
34256 ++#ifdef CONFIG_PAX_KERNEXEC
34257 ++ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
34258 ++ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
34259 ++ else
34260 ++#endif
34261 ++
34262 ++ sechdrs[i].sh_addr = (unsigned long)dest;
34263 + DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
34264 + }
34265 + /* Module has been moved. */
34266 +@@ -2120,8 +2265,8 @@ static noinline struct module *load_modu
34267 +
34268 + /* Now do relocations. */
34269 + for (i = 1; i < hdr->e_shnum; i++) {
34270 +- const char *strtab = (char *)sechdrs[strindex].sh_addr;
34271 + unsigned int info = sechdrs[i].sh_info;
34272 ++ strtab = (char *)sechdrs[strindex].sh_addr;
34273 +
34274 + /* Not a valid relocation section? */
34275 + if (info >= hdr->e_shnum)
34276 +@@ -2180,12 +2325,12 @@ static noinline struct module *load_modu
34277 + * Do it before processing of module parameters, so the module
34278 + * can provide parameter accessor functions of its own.
34279 + */
34280 +- if (mod->module_init)
34281 +- flush_icache_range((unsigned long)mod->module_init,
34282 +- (unsigned long)mod->module_init
34283 +- + mod->init_size);
34284 +- flush_icache_range((unsigned long)mod->module_core,
34285 +- (unsigned long)mod->module_core + mod->core_size);
34286 ++ if (mod->module_init_rx)
34287 ++ flush_icache_range((unsigned long)mod->module_init_rx,
34288 ++ (unsigned long)mod->module_init_rx
34289 ++ + mod->init_size_rx);
34290 ++ flush_icache_range((unsigned long)mod->module_core_rx,
34291 ++ (unsigned long)mod->module_core_rx + mod->core_size_rx);
34292 +
34293 + set_fs(old_fs);
34294 +
34295 +@@ -2238,9 +2383,13 @@ static noinline struct module *load_modu
34296 + kobject_put(&mod->mkobj.kobj);
34297 + free_unload:
34298 + module_unload_free(mod);
34299 +- module_free(mod, mod->module_init);
34300 +- free_core:
34301 +- module_free(mod, mod->module_core);
34302 ++ module_free_exec(mod, mod->module_init_rx);
34303 ++ free_core_rx:
34304 ++ module_free_exec(mod, mod->module_core_rx);
34305 ++ free_init_rw:
34306 ++ module_free(mod, mod->module_init_rw);
34307 ++ free_core_rw:
34308 ++ module_free(mod, mod->module_core_rw);
34309 + free_percpu:
34310 + if (percpu)
34311 + percpu_modfree(percpu);
34312 +@@ -2265,6 +2414,9 @@ sys_init_module(void __user *umod,
34313 + struct module *mod;
34314 + int ret = 0;
34315 +
34316 ++ if (gr_check_modstop())
34317 ++ return -EPERM;
34318 ++
34319 + /* Must have permission */
34320 + if (!capable(CAP_SYS_MODULE))
34321 + return -EPERM;
34322 +@@ -2320,10 +2472,12 @@ sys_init_module(void __user *umod,
34323 + /* Drop initial reference. */
34324 + module_put(mod);
34325 + unwind_remove_table(mod->unwind_info, 1);
34326 +- module_free(mod, mod->module_init);
34327 +- mod->module_init = NULL;
34328 +- mod->init_size = 0;
34329 +- mod->init_text_size = 0;
34330 ++ module_free(mod, mod->module_init_rw);
34331 ++ module_free_exec(mod, mod->module_init_rx);
34332 ++ mod->module_init_rw = NULL;
34333 ++ mod->module_init_rx = NULL;
34334 ++ mod->init_size_rw = 0;
34335 ++ mod->init_size_rx = 0;
34336 + mutex_unlock(&module_mutex);
34337 +
34338 + return 0;
34339 +@@ -2331,6 +2485,13 @@ sys_init_module(void __user *umod,
34340 +
34341 + static inline int within(unsigned long addr, void *start, unsigned long size)
34342 + {
34343 ++
34344 ++#ifdef CONFIG_PAX_KERNEXEC
34345 ++ if (ktla_ktva(addr) >= (unsigned long)start &&
34346 ++ ktla_ktva(addr) < (unsigned long)start + size)
34347 ++ return 1;
34348 ++#endif
34349 ++
34350 + return ((void *)addr >= start && (void *)addr < start + size);
34351 + }
34352 +
34353 +@@ -2354,10 +2515,14 @@ static const char *get_ksymbol(struct mo
34354 + unsigned long nextval;
34355 +
34356 + /* At worse, next value is at end of module */
34357 +- if (within(addr, mod->module_init, mod->init_size))
34358 +- nextval = (unsigned long)mod->module_init+mod->init_text_size;
34359 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx))
34360 ++ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
34361 ++ else if (within(addr, mod->module_init_rw, mod->init_size_rw))
34362 ++ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
34363 ++ else if (within(addr, mod->module_core_rx, mod->core_size_rx))
34364 ++ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
34365 + else
34366 +- nextval = (unsigned long)mod->module_core+mod->core_text_size;
34367 ++ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
34368 +
34369 + /* Scan for closest preceeding symbol, and next symbol. (ELF
34370 + starts real symbols at 1). */
34371 +@@ -2402,8 +2567,10 @@ const char *module_address_lookup(unsign
34372 +
34373 + preempt_disable();
34374 + list_for_each_entry(mod, &modules, list) {
34375 +- if (within(addr, mod->module_init, mod->init_size)
34376 +- || within(addr, mod->module_core, mod->core_size)) {
34377 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
34378 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
34379 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
34380 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34381 + if (modname)
34382 + *modname = mod->name;
34383 + ret = get_ksymbol(mod, addr, size, offset);
34384 +@@ -2425,8 +2592,10 @@ int lookup_module_symbol_name(unsigned l
34385 +
34386 + preempt_disable();
34387 + list_for_each_entry(mod, &modules, list) {
34388 +- if (within(addr, mod->module_init, mod->init_size) ||
34389 +- within(addr, mod->module_core, mod->core_size)) {
34390 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
34391 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
34392 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
34393 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34394 + const char *sym;
34395 +
34396 + sym = get_ksymbol(mod, addr, NULL, NULL);
34397 +@@ -2449,8 +2618,10 @@ int lookup_module_symbol_attrs(unsigned
34398 +
34399 + preempt_disable();
34400 + list_for_each_entry(mod, &modules, list) {
34401 +- if (within(addr, mod->module_init, mod->init_size) ||
34402 +- within(addr, mod->module_core, mod->core_size)) {
34403 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
34404 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
34405 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
34406 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34407 + const char *sym;
34408 +
34409 + sym = get_ksymbol(mod, addr, size, offset);
34410 +@@ -2581,7 +2752,7 @@ static int m_show(struct seq_file *m, vo
34411 + char buf[8];
34412 +
34413 + seq_printf(m, "%s %u",
34414 +- mod->name, mod->init_size + mod->core_size);
34415 ++ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
34416 + print_unload_info(m, mod);
34417 +
34418 + /* Informative for users. */
34419 +@@ -2590,7 +2761,7 @@ static int m_show(struct seq_file *m, vo
34420 + mod->state == MODULE_STATE_COMING ? "Loading":
34421 + "Live");
34422 + /* Used by oprofile and other similar tools. */
34423 +- seq_printf(m, " 0x%p", mod->module_core);
34424 ++ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
34425 +
34426 + /* Taints info */
34427 + if (mod->taints)
34428 +@@ -2646,7 +2817,8 @@ int is_module_address(unsigned long addr
34429 + preempt_disable();
34430 +
34431 + list_for_each_entry(mod, &modules, list) {
34432 +- if (within(addr, mod->module_core, mod->core_size)) {
34433 ++ if (within(addr, mod->module_core_rx, mod->core_size_rx) ||
34434 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34435 + preempt_enable();
34436 + return 1;
34437 + }
34438 +@@ -2663,12 +2835,16 @@ struct module *__module_text_address(uns
34439 + {
34440 + struct module *mod;
34441 +
34442 +- if (addr < module_addr_min || addr > module_addr_max)
34443 ++#ifdef CONFIG_X86_32
34444 ++ addr = ktla_ktva(addr);
34445 ++#endif
34446 ++
34447 ++ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
34448 + return NULL;
34449 +
34450 + list_for_each_entry(mod, &modules, list)
34451 +- if (within(addr, mod->module_init, mod->init_text_size)
34452 +- || within(addr, mod->module_core, mod->core_text_size))
34453 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx)
34454 ++ || within(addr, mod->module_core_rx, mod->core_size_rx))
34455 + return mod;
34456 + return NULL;
34457 + }
34458 +diff -urNp linux-2.6.27.10/kernel/mutex.c linux-2.6.27.10/kernel/mutex.c
34459 +--- linux-2.6.27.10/kernel/mutex.c 2008-11-07 12:55:34.000000000 -0500
34460 ++++ linux-2.6.27.10/kernel/mutex.c 2008-11-18 03:38:45.000000000 -0500
34461 +@@ -83,7 +83,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
34462 + *
34463 + * This function is similar to (but not equivalent to) down().
34464 + */
34465 +-void inline __sched mutex_lock(struct mutex *lock)
34466 ++inline void __sched mutex_lock(struct mutex *lock)
34467 + {
34468 + might_sleep();
34469 + /*
34470 +diff -urNp linux-2.6.27.10/kernel/panic.c linux-2.6.27.10/kernel/panic.c
34471 +--- linux-2.6.27.10/kernel/panic.c 2008-11-07 12:55:34.000000000 -0500
34472 ++++ linux-2.6.27.10/kernel/panic.c 2008-11-18 03:38:45.000000000 -0500
34473 +@@ -349,6 +349,8 @@ EXPORT_SYMBOL(warn_slowpath);
34474 + */
34475 + void __stack_chk_fail(void)
34476 + {
34477 ++ print_symbol("stack corrupted in: %s\n", (unsigned long)__builtin_return_address(0));
34478 ++ dump_stack();
34479 + panic("stack-protector: Kernel stack is corrupted");
34480 + }
34481 + EXPORT_SYMBOL(__stack_chk_fail);
34482 +diff -urNp linux-2.6.27.10/kernel/pid.c linux-2.6.27.10/kernel/pid.c
34483 +--- linux-2.6.27.10/kernel/pid.c 2008-11-07 12:55:34.000000000 -0500
34484 ++++ linux-2.6.27.10/kernel/pid.c 2008-11-18 03:38:45.000000000 -0500
34485 +@@ -36,6 +36,7 @@
34486 + #include <linux/pid_namespace.h>
34487 + #include <linux/init_task.h>
34488 + #include <linux/syscalls.h>
34489 ++#include <linux/grsecurity.h>
34490 +
34491 + #define pid_hashfn(nr, ns) \
34492 + hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
34493 +@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
34494 +
34495 + int pid_max = PID_MAX_DEFAULT;
34496 +
34497 +-#define RESERVED_PIDS 300
34498 ++#define RESERVED_PIDS 500
34499 +
34500 + int pid_max_min = RESERVED_PIDS + 1;
34501 + int pid_max_max = PID_MAX_LIMIT;
34502 +@@ -381,7 +382,14 @@ EXPORT_SYMBOL(pid_task);
34503 + struct task_struct *find_task_by_pid_type_ns(int type, int nr,
34504 + struct pid_namespace *ns)
34505 + {
34506 +- return pid_task(find_pid_ns(nr, ns), type);
34507 ++ struct task_struct *task;
34508 ++
34509 ++ task = pid_task(find_pid_ns(nr, ns), type);
34510 ++
34511 ++ if (gr_pid_is_chrooted(task))
34512 ++ return NULL;
34513 ++
34514 ++ return task;
34515 + }
34516 +
34517 + EXPORT_SYMBOL(find_task_by_pid_type_ns);
34518 +diff -urNp linux-2.6.27.10/kernel/posix-cpu-timers.c linux-2.6.27.10/kernel/posix-cpu-timers.c
34519 +--- linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-07 12:55:34.000000000 -0500
34520 ++++ linux-2.6.27.10/kernel/posix-cpu-timers.c 2008-11-18 03:38:45.000000000 -0500
34521 +@@ -6,6 +6,7 @@
34522 + #include <linux/posix-timers.h>
34523 + #include <linux/errno.h>
34524 + #include <linux/math64.h>
34525 ++#include <linux/grsecurity.h>
34526 + #include <asm/uaccess.h>
34527 +
34528 + static int check_clock(const clockid_t which_clock)
34529 +@@ -1176,6 +1177,7 @@ static void check_process_timers(struct
34530 + __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
34531 + return;
34532 + }
34533 ++ gr_learn_resource(tsk, RLIMIT_CPU, psecs, 1);
34534 + if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) {
34535 + /*
34536 + * At the soft limit, send a SIGXCPU every second.
34537 +@@ -1370,17 +1372,17 @@ void run_posix_cpu_timers(struct task_st
34538 + * timer call will interfere.
34539 + */
34540 + list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) {
34541 +- int firing;
34542 ++ int __firing;
34543 + spin_lock(&timer->it_lock);
34544 + list_del_init(&timer->it.cpu.entry);
34545 +- firing = timer->it.cpu.firing;
34546 ++ __firing = timer->it.cpu.firing;
34547 + timer->it.cpu.firing = 0;
34548 + /*
34549 + * The firing flag is -1 if we collided with a reset
34550 + * of the timer, which already reported this
34551 + * almost-firing as an overrun. So don't generate an event.
34552 + */
34553 +- if (likely(firing >= 0)) {
34554 ++ if (likely(__firing >= 0)) {
34555 + cpu_timer_fire(timer);
34556 + }
34557 + spin_unlock(&timer->it_lock);
34558 +diff -urNp linux-2.6.27.10/kernel/power/poweroff.c linux-2.6.27.10/kernel/power/poweroff.c
34559 +--- linux-2.6.27.10/kernel/power/poweroff.c 2008-11-07 12:55:34.000000000 -0500
34560 ++++ linux-2.6.27.10/kernel/power/poweroff.c 2008-11-18 03:38:45.000000000 -0500
34561 +@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
34562 + .enable_mask = SYSRQ_ENABLE_BOOT,
34563 + };
34564 +
34565 +-static int pm_sysrq_init(void)
34566 ++static int __init pm_sysrq_init(void)
34567 + {
34568 + register_sysrq_key('o', &sysrq_poweroff_op);
34569 + return 0;
34570 +diff -urNp linux-2.6.27.10/kernel/printk.c linux-2.6.27.10/kernel/printk.c
34571 +--- linux-2.6.27.10/kernel/printk.c 2008-11-07 12:55:34.000000000 -0500
34572 ++++ linux-2.6.27.10/kernel/printk.c 2008-11-18 03:38:45.000000000 -0500
34573 +@@ -32,6 +32,7 @@
34574 + #include <linux/security.h>
34575 + #include <linux/bootmem.h>
34576 + #include <linux/syscalls.h>
34577 ++#include <linux/grsecurity.h>
34578 +
34579 + #include <asm/uaccess.h>
34580 +
34581 +@@ -293,6 +294,11 @@ int do_syslog(int type, char __user *buf
34582 + char c;
34583 + int error = 0;
34584 +
34585 ++#ifdef CONFIG_GRKERNSEC_DMESG
34586 ++ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
34587 ++ return -EPERM;
34588 ++#endif
34589 ++
34590 + error = security_syslog(type);
34591 + if (error)
34592 + return error;
34593 +diff -urNp linux-2.6.27.10/kernel/ptrace.c linux-2.6.27.10/kernel/ptrace.c
34594 +--- linux-2.6.27.10/kernel/ptrace.c 2008-11-07 12:55:34.000000000 -0500
34595 ++++ linux-2.6.27.10/kernel/ptrace.c 2008-11-18 03:38:45.000000000 -0500
34596 +@@ -21,6 +21,7 @@
34597 + #include <linux/audit.h>
34598 + #include <linux/pid_namespace.h>
34599 + #include <linux/syscalls.h>
34600 ++#include <linux/grsecurity.h>
34601 +
34602 + #include <asm/pgtable.h>
34603 + #include <asm/uaccess.h>
34604 +@@ -132,12 +133,12 @@ int __ptrace_may_access(struct task_stru
34605 + (current->uid != task->uid) ||
34606 + (current->gid != task->egid) ||
34607 + (current->gid != task->sgid) ||
34608 +- (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
34609 ++ (current->gid != task->gid)) && !capable_nolog(CAP_SYS_PTRACE))
34610 + return -EPERM;
34611 + smp_rmb();
34612 + if (task->mm)
34613 + dumpable = get_dumpable(task->mm);
34614 +- if (!dumpable && !capable(CAP_SYS_PTRACE))
34615 ++ if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
34616 + return -EPERM;
34617 +
34618 + return security_ptrace_may_access(task, mode);
34619 +@@ -193,7 +194,7 @@ repeat:
34620 +
34621 + /* Go */
34622 + task->ptrace |= PT_PTRACED;
34623 +- if (capable(CAP_SYS_PTRACE))
34624 ++ if (capable_nolog(CAP_SYS_PTRACE))
34625 + task->ptrace |= PT_PTRACE_CAP;
34626 +
34627 + __ptrace_link(task, current);
34628 +@@ -582,6 +583,11 @@ asmlinkage long sys_ptrace(long request,
34629 + if (ret < 0)
34630 + goto out_put_task_struct;
34631 +
34632 ++ if (gr_handle_ptrace(child, request)) {
34633 ++ ret = -EPERM;
34634 ++ goto out_put_task_struct;
34635 ++ }
34636 ++
34637 + ret = arch_ptrace(child, request, addr, data);
34638 + if (ret < 0)
34639 + goto out_put_task_struct;
34640 +diff -urNp linux-2.6.27.10/kernel/relay.c linux-2.6.27.10/kernel/relay.c
34641 +--- linux-2.6.27.10/kernel/relay.c 2008-11-07 12:55:34.000000000 -0500
34642 ++++ linux-2.6.27.10/kernel/relay.c 2008-11-18 03:38:45.000000000 -0500
34643 +@@ -1291,7 +1291,7 @@ static int subbuf_splice_actor(struct fi
34644 + return 0;
34645 +
34646 + ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
34647 +- if (ret < 0 || ret < total_len)
34648 ++ if ((int)ret < 0 || ret < total_len)
34649 + return ret;
34650 +
34651 + if (read_start + ret == nonpad_end)
34652 +diff -urNp linux-2.6.27.10/kernel/resource.c linux-2.6.27.10/kernel/resource.c
34653 +--- linux-2.6.27.10/kernel/resource.c 2008-11-07 12:55:34.000000000 -0500
34654 ++++ linux-2.6.27.10/kernel/resource.c 2008-11-18 03:38:45.000000000 -0500
34655 +@@ -131,8 +131,18 @@ static const struct file_operations proc
34656 +
34657 + static int __init ioresources_init(void)
34658 + {
34659 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
34660 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
34661 ++ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
34662 ++ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
34663 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
34664 ++ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
34665 ++ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
34666 ++#endif
34667 ++#else
34668 + proc_create("ioports", 0, NULL, &proc_ioports_operations);
34669 + proc_create("iomem", 0, NULL, &proc_iomem_operations);
34670 ++#endif
34671 + return 0;
34672 + }
34673 + __initcall(ioresources_init);
34674 +diff -urNp linux-2.6.27.10/kernel/sched.c linux-2.6.27.10/kernel/sched.c
34675 +--- linux-2.6.27.10/kernel/sched.c 2008-12-21 01:16:52.000000000 -0500
34676 ++++ linux-2.6.27.10/kernel/sched.c 2008-12-21 01:13:46.000000000 -0500
34677 +@@ -71,6 +71,7 @@
34678 + #include <linux/debugfs.h>
34679 + #include <linux/ctype.h>
34680 + #include <linux/ftrace.h>
34681 ++#include <linux/grsecurity.h>
34682 +
34683 + #include <asm/tlb.h>
34684 + #include <asm/irq_regs.h>
34685 +@@ -4962,7 +4963,8 @@ asmlinkage long sys_nice(int increment)
34686 + if (nice > 19)
34687 + nice = 19;
34688 +
34689 +- if (increment < 0 && !can_nice(current, nice))
34690 ++ if (increment < 0 && (!can_nice(current, nice) ||
34691 ++ gr_handle_chroot_nice()))
34692 + return -EPERM;
34693 +
34694 + retval = security_task_setnice(current, nice);
34695 +@@ -6225,7 +6227,7 @@ static struct ctl_table sd_ctl_dir[] = {
34696 + .procname = "sched_domain",
34697 + .mode = 0555,
34698 + },
34699 +- {0, },
34700 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
34701 + };
34702 +
34703 + static struct ctl_table sd_ctl_root[] = {
34704 +@@ -6235,7 +6237,7 @@ static struct ctl_table sd_ctl_root[] =
34705 + .mode = 0555,
34706 + .child = sd_ctl_dir,
34707 + },
34708 +- {0, },
34709 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
34710 + };
34711 +
34712 + static struct ctl_table *sd_alloc_ctl_entry(int n)
34713 +diff -urNp linux-2.6.27.10/kernel/signal.c linux-2.6.27.10/kernel/signal.c
34714 +--- linux-2.6.27.10/kernel/signal.c 2008-11-07 12:55:34.000000000 -0500
34715 ++++ linux-2.6.27.10/kernel/signal.c 2008-11-18 03:38:45.000000000 -0500
34716 +@@ -26,6 +26,7 @@
34717 + #include <linux/capability.h>
34718 + #include <linux/freezer.h>
34719 + #include <linux/pid_namespace.h>
34720 ++#include <linux/grsecurity.h>
34721 + #include <linux/nsproxy.h>
34722 +
34723 + #include <asm/param.h>
34724 +@@ -595,6 +596,9 @@ static int check_kill_permission(int sig
34725 + }
34726 + }
34727 +
34728 ++ if (gr_handle_signal(t, sig))
34729 ++ return -EPERM;
34730 ++
34731 + return security_task_kill(t, info, sig, 0);
34732 + }
34733 +
34734 +@@ -884,8 +888,8 @@ static void print_fatal_signal(struct pt
34735 + for (i = 0; i < 16; i++) {
34736 + unsigned char insn;
34737 +
34738 +- __get_user(insn, (unsigned char *)(regs->ip + i));
34739 +- printk("%02x ", insn);
34740 ++ if (!get_user(insn, (unsigned char __user *)(regs->ip + i)))
34741 ++ printk("%02x ", insn);
34742 + }
34743 + }
34744 + #endif
34745 +@@ -908,7 +912,7 @@ __group_send_sig_info(int sig, struct si
34746 + return send_signal(sig, info, p, 1);
34747 + }
34748 +
34749 +-static int
34750 ++int
34751 + specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
34752 + {
34753 + return send_signal(sig, info, t, 0);
34754 +@@ -946,8 +950,12 @@ force_sig_info(int sig, struct siginfo *
34755 + if (action->sa.sa_handler == SIG_DFL)
34756 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
34757 + ret = specific_send_sig_info(sig, info, t);
34758 ++
34759 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
34760 +
34761 ++ gr_log_signal(sig, t);
34762 ++ gr_handle_crash(t, sig);
34763 ++
34764 + return ret;
34765 + }
34766 +
34767 +@@ -1018,6 +1026,8 @@ int group_send_sig_info(int sig, struct
34768 + ret = __group_send_sig_info(sig, info, p);
34769 + unlock_task_sighand(p, &flags);
34770 + }
34771 ++ if (!ret)
34772 ++ gr_log_signal(sig, p);
34773 + }
34774 +
34775 + return ret;
34776 +diff -urNp linux-2.6.27.10/kernel/softirq.c linux-2.6.27.10/kernel/softirq.c
34777 +--- linux-2.6.27.10/kernel/softirq.c 2008-11-07 12:55:34.000000000 -0500
34778 ++++ linux-2.6.27.10/kernel/softirq.c 2008-11-18 03:38:45.000000000 -0500
34779 +@@ -453,9 +453,9 @@ void tasklet_kill(struct tasklet_struct
34780 + printk("Attempt to kill tasklet from interrupt\n");
34781 +
34782 + while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
34783 +- do
34784 ++ do {
34785 + yield();
34786 +- while (test_bit(TASKLET_STATE_SCHED, &t->state));
34787 ++ } while (test_bit(TASKLET_STATE_SCHED, &t->state));
34788 + }
34789 + tasklet_unlock_wait(t);
34790 + clear_bit(TASKLET_STATE_SCHED, &t->state);
34791 +diff -urNp linux-2.6.27.10/kernel/sys.c linux-2.6.27.10/kernel/sys.c
34792 +--- linux-2.6.27.10/kernel/sys.c 2008-11-07 12:55:34.000000000 -0500
34793 ++++ linux-2.6.27.10/kernel/sys.c 2008-11-18 03:38:45.000000000 -0500
34794 +@@ -33,6 +33,7 @@
34795 + #include <linux/task_io_accounting_ops.h>
34796 + #include <linux/seccomp.h>
34797 + #include <linux/cpu.h>
34798 ++#include <linux/grsecurity.h>
34799 +
34800 + #include <linux/compat.h>
34801 + #include <linux/syscalls.h>
34802 +@@ -125,6 +126,12 @@ static int set_one_prio(struct task_stru
34803 + error = -EACCES;
34804 + goto out;
34805 + }
34806 ++
34807 ++ if (gr_handle_chroot_setpriority(p, niceval)) {
34808 ++ error = -EACCES;
34809 ++ goto out;
34810 ++ }
34811 ++
34812 + no_nice = security_task_setnice(p, niceval);
34813 + if (no_nice) {
34814 + error = no_nice;
34815 +@@ -181,10 +188,10 @@ asmlinkage long sys_setpriority(int whic
34816 + if ((who != current->uid) && !(user = find_user(who)))
34817 + goto out_unlock; /* No processes for this user */
34818 +
34819 +- do_each_thread(g, p)
34820 ++ do_each_thread(g, p) {
34821 + if (p->uid == who)
34822 + error = set_one_prio(p, niceval, error);
34823 +- while_each_thread(g, p);
34824 ++ } while_each_thread(g, p);
34825 + if (who != current->uid)
34826 + free_uid(user); /* For find_user() */
34827 + break;
34828 +@@ -243,13 +250,13 @@ asmlinkage long sys_getpriority(int whic
34829 + if ((who != current->uid) && !(user = find_user(who)))
34830 + goto out_unlock; /* No processes for this user */
34831 +
34832 +- do_each_thread(g, p)
34833 ++ do_each_thread(g, p) {
34834 + if (p->uid == who) {
34835 + niceval = 20 - task_nice(p);
34836 + if (niceval > retval)
34837 + retval = niceval;
34838 + }
34839 +- while_each_thread(g, p);
34840 ++ } while_each_thread(g, p);
34841 + if (who != current->uid)
34842 + free_uid(user); /* for find_user() */
34843 + break;
34844 +@@ -499,6 +506,10 @@ asmlinkage long sys_setregid(gid_t rgid,
34845 + else
34846 + return -EPERM;
34847 + }
34848 ++
34849 ++ if (gr_check_group_change(new_rgid, new_egid, -1))
34850 ++ return -EPERM;
34851 ++
34852 + if (new_egid != old_egid) {
34853 + set_dumpable(current->mm, suid_dumpable);
34854 + smp_wmb();
34855 +@@ -506,6 +517,9 @@ asmlinkage long sys_setregid(gid_t rgid,
34856 + if (rgid != (gid_t) -1 ||
34857 + (egid != (gid_t) -1 && egid != old_rgid))
34858 + current->sgid = new_egid;
34859 ++
34860 ++ gr_set_role_label(current, current->uid, new_rgid);
34861 ++
34862 + current->fsgid = new_egid;
34863 + current->egid = new_egid;
34864 + current->gid = new_rgid;
34865 +@@ -528,11 +542,17 @@ asmlinkage long sys_setgid(gid_t gid)
34866 + if (retval)
34867 + return retval;
34868 +
34869 ++ if (gr_check_group_change(gid, gid, gid))
34870 ++ return -EPERM;
34871 ++
34872 + if (capable(CAP_SETGID)) {
34873 + if (old_egid != gid) {
34874 + set_dumpable(current->mm, suid_dumpable);
34875 + smp_wmb();
34876 + }
34877 ++
34878 ++ gr_set_role_label(current, current->uid, gid);
34879 ++
34880 + current->gid = current->egid = current->sgid = current->fsgid = gid;
34881 + } else if ((gid == current->gid) || (gid == current->sgid)) {
34882 + if (old_egid != gid) {
34883 +@@ -570,6 +590,9 @@ static int set_user(uid_t new_ruid, int
34884 + set_dumpable(current->mm, suid_dumpable);
34885 + smp_wmb();
34886 + }
34887 ++
34888 ++ gr_set_role_label(current, new_ruid, current->gid);
34889 ++
34890 + current->uid = new_ruid;
34891 + return 0;
34892 + }
34893 +@@ -619,6 +642,9 @@ asmlinkage long sys_setreuid(uid_t ruid,
34894 + return -EPERM;
34895 + }
34896 +
34897 ++ if (gr_check_user_change(new_ruid, new_euid, -1))
34898 ++ return -EPERM;
34899 ++
34900 + if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
34901 + return -EAGAIN;
34902 +
34903 +@@ -665,6 +691,12 @@ asmlinkage long sys_setuid(uid_t uid)
34904 + old_suid = current->suid;
34905 + new_suid = old_suid;
34906 +
34907 ++ if (gr_check_crash_uid(uid))
34908 ++ return -EPERM;
34909 ++
34910 ++ if (gr_check_user_change(uid, uid, uid))
34911 ++ return -EPERM;
34912 ++
34913 + if (capable(CAP_SETUID)) {
34914 + if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
34915 + return -EAGAIN;
34916 +@@ -712,6 +744,10 @@ asmlinkage long sys_setresuid(uid_t ruid
34917 + (suid != current->euid) && (suid != current->suid))
34918 + return -EPERM;
34919 + }
34920 ++
34921 ++ if (gr_check_user_change(ruid, euid, -1))
34922 ++ return -EPERM;
34923 ++
34924 + if (ruid != (uid_t) -1) {
34925 + if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
34926 + return -EAGAIN;
34927 +@@ -766,6 +802,10 @@ asmlinkage long sys_setresgid(gid_t rgid
34928 + (sgid != current->egid) && (sgid != current->sgid))
34929 + return -EPERM;
34930 + }
34931 ++
34932 ++ if (gr_check_group_change(rgid, egid, -1))
34933 ++ return -EPERM;
34934 ++
34935 + if (egid != (gid_t) -1) {
34936 + if (egid != current->egid) {
34937 + set_dumpable(current->mm, suid_dumpable);
34938 +@@ -774,8 +814,10 @@ asmlinkage long sys_setresgid(gid_t rgid
34939 + current->egid = egid;
34940 + }
34941 + current->fsgid = current->egid;
34942 +- if (rgid != (gid_t) -1)
34943 ++ if (rgid != (gid_t) -1) {
34944 ++ gr_set_role_label(current, current->uid, rgid);
34945 + current->gid = rgid;
34946 ++ }
34947 + if (sgid != (gid_t) -1)
34948 + current->sgid = sgid;
34949 +
34950 +@@ -810,6 +852,9 @@ asmlinkage long sys_setfsuid(uid_t uid)
34951 + if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
34952 + return old_fsuid;
34953 +
34954 ++ if (gr_check_user_change(-1, -1, uid))
34955 ++ return old_fsuid;
34956 ++
34957 + if (uid == current->uid || uid == current->euid ||
34958 + uid == current->suid || uid == current->fsuid ||
34959 + capable(CAP_SETUID)) {
34960 +@@ -842,6 +887,9 @@ asmlinkage long sys_setfsgid(gid_t gid)
34961 + if (gid == current->gid || gid == current->egid ||
34962 + gid == current->sgid || gid == current->fsgid ||
34963 + capable(CAP_SETGID)) {
34964 ++ if (gr_check_group_change(-1, -1, gid))
34965 ++ return old_fsgid;
34966 ++
34967 + if (gid != old_fsgid) {
34968 + set_dumpable(current->mm, suid_dumpable);
34969 + smp_wmb();
34970 +@@ -923,7 +971,10 @@ asmlinkage long sys_setpgid(pid_t pid, p
34971 + write_lock_irq(&tasklist_lock);
34972 +
34973 + err = -ESRCH;
34974 +- p = find_task_by_vpid(pid);
34975 ++ /* grsec: replaced find_task_by_vpid with equivalent call which
34976 ++ lacks the chroot restriction
34977 ++ */
34978 ++ p = pid_task(find_pid_ns(pid, current->nsproxy->pid_ns), PIDTYPE_PID);
34979 + if (!p)
34980 + goto out;
34981 +
34982 +@@ -1655,7 +1706,7 @@ asmlinkage long sys_prctl(int option, un
34983 + error = get_dumpable(current->mm);
34984 + break;
34985 + case PR_SET_DUMPABLE:
34986 +- if (arg2 < 0 || arg2 > 1) {
34987 ++ if (arg2 > 1) {
34988 + error = -EINVAL;
34989 + break;
34990 + }
34991 +diff -urNp linux-2.6.27.10/kernel/sysctl.c linux-2.6.27.10/kernel/sysctl.c
34992 +--- linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:38.000000000 -0500
34993 ++++ linux-2.6.27.10/kernel/sysctl.c 2008-12-10 22:35:46.000000000 -0500
34994 +@@ -61,6 +61,13 @@
34995 + static int deprecated_sysctl_warning(struct __sysctl_args *args);
34996 +
34997 + #if defined(CONFIG_SYSCTL)
34998 ++#include <linux/grsecurity.h>
34999 ++#include <linux/grinternal.h>
35000 ++
35001 ++extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
35002 ++extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
35003 ++ const int op);
35004 ++extern int gr_handle_chroot_sysctl(const int op);
35005 +
35006 + /* External variables not in a header file. */
35007 + extern int C_A_D;
35008 +@@ -155,6 +162,7 @@ static int proc_do_cad_pid(struct ctl_ta
35009 + static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
35010 + void __user *buffer, size_t *lenp, loff_t *ppos);
35011 + #endif
35012 ++extern ctl_table grsecurity_table[];
35013 +
35014 + static struct ctl_table root_table[];
35015 + static struct ctl_table_root sysctl_table_root;
35016 +@@ -187,6 +195,21 @@ extern struct ctl_table epoll_table[];
35017 + int sysctl_legacy_va_layout;
35018 + #endif
35019 +
35020 ++#ifdef CONFIG_PAX_SOFTMODE
35021 ++static ctl_table pax_table[] = {
35022 ++ {
35023 ++ .ctl_name = CTL_UNNUMBERED,
35024 ++ .procname = "softmode",
35025 ++ .data = &pax_softmode,
35026 ++ .maxlen = sizeof(unsigned int),
35027 ++ .mode = 0600,
35028 ++ .proc_handler = &proc_dointvec,
35029 ++ },
35030 ++
35031 ++ { .ctl_name = 0 }
35032 ++};
35033 ++#endif
35034 ++
35035 + extern int prove_locking;
35036 + extern int lock_stat;
35037 +
35038 +@@ -223,6 +246,7 @@ static struct ctl_table root_table[] = {
35039 + .mode = 0555,
35040 + .child = dev_table,
35041 + },
35042 ++
35043 + /*
35044 + * NOTE: do not add new entries to this table unless you have read
35045 + * Documentation/sysctl/ctl_unnumbered.txt
35046 +@@ -850,6 +874,25 @@ static struct ctl_table kern_table[] = {
35047 + .proc_handler = &proc_dointvec,
35048 + },
35049 + #endif
35050 ++
35051 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
35052 ++ {
35053 ++ .ctl_name = CTL_UNNUMBERED,
35054 ++ .procname = "grsecurity",
35055 ++ .mode = 0500,
35056 ++ .child = grsecurity_table,
35057 ++ },
35058 ++#endif
35059 ++
35060 ++#ifdef CONFIG_PAX_SOFTMODE
35061 ++ {
35062 ++ .ctl_name = CTL_UNNUMBERED,
35063 ++ .procname = "pax",
35064 ++ .mode = 0500,
35065 ++ .child = pax_table,
35066 ++ },
35067 ++#endif
35068 ++
35069 + /*
35070 + * NOTE: do not add new entries to this table unless you have read
35071 + * Documentation/sysctl/ctl_unnumbered.txt
35072 +@@ -1179,6 +1222,7 @@ static struct ctl_table vm_table[] = {
35073 + .extra2 = &one,
35074 + },
35075 + #endif
35076 ++
35077 + /*
35078 + * NOTE: do not add new entries to this table unless you have read
35079 + * Documentation/sysctl/ctl_unnumbered.txt
35080 +@@ -1553,6 +1597,8 @@ static int do_sysctl_strategy(struct ctl
35081 + return 0;
35082 + }
35083 +
35084 ++static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
35085 ++
35086 + static int parse_table(int __user *name, int nlen,
35087 + void __user *oldval, size_t __user *oldlenp,
35088 + void __user *newval, size_t newlen,
35089 +@@ -1571,7 +1617,7 @@ repeat:
35090 + if (n == table->ctl_name) {
35091 + int error;
35092 + if (table->child) {
35093 +- if (sysctl_perm(root, table, MAY_EXEC))
35094 ++ if (sysctl_perm_nochk(root, table, MAY_EXEC))
35095 + return -EPERM;
35096 + name++;
35097 + nlen--;
35098 +@@ -1656,6 +1702,33 @@ int sysctl_perm(struct ctl_table_root *r
35099 + int error;
35100 + int mode;
35101 +
35102 ++ if (table->parent != NULL && table->parent->procname != NULL &&
35103 ++ table->procname != NULL &&
35104 ++ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
35105 ++ return -EACCES;
35106 ++ if (gr_handle_chroot_sysctl(op))
35107 ++ return -EACCES;
35108 ++ error = gr_handle_sysctl(table, op);
35109 ++ if (error)
35110 ++ return error;
35111 ++
35112 ++ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
35113 ++ if (error)
35114 ++ return error;
35115 ++
35116 ++ if (root->permissions)
35117 ++ mode = root->permissions(root, current->nsproxy, table);
35118 ++ else
35119 ++ mode = table->mode;
35120 ++
35121 ++ return test_perm(mode, op);
35122 ++}
35123 ++
35124 ++int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
35125 ++{
35126 ++ int error;
35127 ++ int mode;
35128 ++
35129 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
35130 + if (error)
35131 + return error;
35132 +diff -urNp linux-2.6.27.10/kernel/time/tick-broadcast.c linux-2.6.27.10/kernel/time/tick-broadcast.c
35133 +--- linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-07 12:55:34.000000000 -0500
35134 ++++ linux-2.6.27.10/kernel/time/tick-broadcast.c 2008-11-18 03:38:45.000000000 -0500
35135 +@@ -114,7 +114,7 @@ int tick_device_uses_broadcast(struct cl
35136 + * then clear the broadcast bit.
35137 + */
35138 + if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
35139 +- int cpu = smp_processor_id();
35140 ++ cpu = smp_processor_id();
35141 +
35142 + cpu_clear(cpu, tick_broadcast_mask);
35143 + tick_broadcast_clear_oneshot(cpu);
35144 +diff -urNp linux-2.6.27.10/kernel/time.c linux-2.6.27.10/kernel/time.c
35145 +--- linux-2.6.27.10/kernel/time.c 2008-11-07 12:55:34.000000000 -0500
35146 ++++ linux-2.6.27.10/kernel/time.c 2008-11-18 03:38:45.000000000 -0500
35147 +@@ -37,6 +37,7 @@
35148 + #include <linux/fs.h>
35149 + #include <linux/slab.h>
35150 + #include <linux/math64.h>
35151 ++#include <linux/grsecurity.h>
35152 +
35153 + #include <asm/uaccess.h>
35154 + #include <asm/unistd.h>
35155 +@@ -92,6 +93,9 @@ asmlinkage long sys_stime(time_t __user
35156 + return err;
35157 +
35158 + do_settimeofday(&tv);
35159 ++
35160 ++ gr_log_timechange();
35161 ++
35162 + return 0;
35163 + }
35164 +
35165 +@@ -200,6 +204,8 @@ asmlinkage long sys_settimeofday(struct
35166 + return -EFAULT;
35167 + }
35168 +
35169 ++ gr_log_timechange();
35170 ++
35171 + return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
35172 + }
35173 +
35174 +@@ -238,7 +244,7 @@ EXPORT_SYMBOL(current_fs_time);
35175 + * Avoid unnecessary multiplications/divisions in the
35176 + * two most common HZ cases:
35177 + */
35178 +-unsigned int inline jiffies_to_msecs(const unsigned long j)
35179 ++inline unsigned int jiffies_to_msecs(const unsigned long j)
35180 + {
35181 + #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
35182 + return (MSEC_PER_SEC / HZ) * j;
35183 +@@ -254,7 +260,7 @@ unsigned int inline jiffies_to_msecs(con
35184 + }
35185 + EXPORT_SYMBOL(jiffies_to_msecs);
35186 +
35187 +-unsigned int inline jiffies_to_usecs(const unsigned long j)
35188 ++inline unsigned int jiffies_to_usecs(const unsigned long j)
35189 + {
35190 + #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
35191 + return (USEC_PER_SEC / HZ) * j;
35192 +diff -urNp linux-2.6.27.10/kernel/utsname_sysctl.c linux-2.6.27.10/kernel/utsname_sysctl.c
35193 +--- linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-07 12:55:34.000000000 -0500
35194 ++++ linux-2.6.27.10/kernel/utsname_sysctl.c 2008-11-18 03:38:45.000000000 -0500
35195 +@@ -124,7 +124,7 @@ static struct ctl_table uts_kern_table[]
35196 + .proc_handler = proc_do_uts_string,
35197 + .strategy = sysctl_uts_string,
35198 + },
35199 +- {}
35200 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
35201 + };
35202 +
35203 + static struct ctl_table uts_root_table[] = {
35204 +@@ -134,7 +134,7 @@ static struct ctl_table uts_root_table[]
35205 + .mode = 0555,
35206 + .child = uts_kern_table,
35207 + },
35208 +- {}
35209 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
35210 + };
35211 +
35212 + static int __init utsname_sysctl_init(void)
35213 +diff -urNp linux-2.6.27.10/lib/radix-tree.c linux-2.6.27.10/lib/radix-tree.c
35214 +--- linux-2.6.27.10/lib/radix-tree.c 2008-11-07 12:55:34.000000000 -0500
35215 ++++ linux-2.6.27.10/lib/radix-tree.c 2008-11-18 03:38:45.000000000 -0500
35216 +@@ -81,7 +81,7 @@ struct radix_tree_preload {
35217 + int nr;
35218 + struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
35219 + };
35220 +-DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
35221 ++DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
35222 +
35223 + static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
35224 + {
35225 +diff -urNp linux-2.6.27.10/localversion-grsec linux-2.6.27.10/localversion-grsec
35226 +--- linux-2.6.27.10/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
35227 ++++ linux-2.6.27.10/localversion-grsec 2008-11-18 03:38:45.000000000 -0500
35228 +@@ -0,0 +1 @@
35229 ++-grsec
35230 +diff -urNp linux-2.6.27.10/Makefile linux-2.6.27.10/Makefile
35231 +--- linux-2.6.27.10/Makefile 2008-12-21 01:18:11.000000000 -0500
35232 ++++ linux-2.6.27.10/Makefile 2008-12-21 01:18:21.000000000 -0500
35233 +@@ -221,7 +221,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
35234 +
35235 + HOSTCC = gcc
35236 + HOSTCXX = g++
35237 +-HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
35238 ++HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
35239 + HOSTCXXFLAGS = -O2
35240 +
35241 + # Decide whether to build built-in, modular, or both.
35242 +@@ -619,7 +619,7 @@ export mod_strip_cmd
35243 +
35244 +
35245 + ifeq ($(KBUILD_EXTMOD),)
35246 +-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
35247 ++core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
35248 +
35249 + vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
35250 + $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
35251 +diff -urNp linux-2.6.27.10/mm/filemap.c linux-2.6.27.10/mm/filemap.c
35252 +--- linux-2.6.27.10/mm/filemap.c 2008-11-07 12:55:34.000000000 -0500
35253 ++++ linux-2.6.27.10/mm/filemap.c 2008-11-18 03:38:45.000000000 -0500
35254 +@@ -33,6 +33,7 @@
35255 + #include <linux/cpuset.h>
35256 + #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
35257 + #include <linux/memcontrol.h>
35258 ++#include <linux/grsecurity.h>
35259 + #include "internal.h"
35260 +
35261 + /*
35262 +@@ -1588,7 +1589,7 @@ int generic_file_mmap(struct file * file
35263 + struct address_space *mapping = file->f_mapping;
35264 +
35265 + if (!mapping->a_ops->readpage)
35266 +- return -ENOEXEC;
35267 ++ return -ENODEV;
35268 + file_accessed(file);
35269 + vma->vm_ops = &generic_file_vm_ops;
35270 + vma->vm_flags |= VM_CAN_NONLINEAR;
35271 +@@ -1949,6 +1950,7 @@ inline int generic_write_checks(struct f
35272 + *pos = i_size_read(inode);
35273 +
35274 + if (limit != RLIM_INFINITY) {
35275 ++ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
35276 + if (*pos >= limit) {
35277 + send_sig(SIGXFSZ, current, 0);
35278 + return -EFBIG;
35279 +diff -urNp linux-2.6.27.10/mm/fremap.c linux-2.6.27.10/mm/fremap.c
35280 +--- linux-2.6.27.10/mm/fremap.c 2008-11-07 12:55:34.000000000 -0500
35281 ++++ linux-2.6.27.10/mm/fremap.c 2008-11-18 03:38:45.000000000 -0500
35282 +@@ -151,6 +151,13 @@ asmlinkage long sys_remap_file_pages(uns
35283 + retry:
35284 + vma = find_vma(mm, start);
35285 +
35286 ++#ifdef CONFIG_PAX_SEGMEXEC
35287 ++ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC)) {
35288 ++ up_read(&mm->mmap_sem);
35289 ++ return err;
35290 ++ }
35291 ++#endif
35292 ++
35293 + /*
35294 + * Make sure the vma is shared, that it supports prefaulting,
35295 + * and that the remapped range is valid and fully within
35296 +diff -urNp linux-2.6.27.10/mm/hugetlb.c linux-2.6.27.10/mm/hugetlb.c
35297 +--- linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:38:40.000000000 -0500
35298 ++++ linux-2.6.27.10/mm/hugetlb.c 2008-11-18 11:40:53.000000000 -0500
35299 +@@ -1833,6 +1833,26 @@ int unmap_ref_private(struct mm_struct *
35300 + return 1;
35301 + }
35302 +
35303 ++#ifdef CONFIG_PAX_SEGMEXEC
35304 ++static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
35305 ++{
35306 ++ struct mm_struct *mm = vma->vm_mm;
35307 ++ struct vm_area_struct *vma_m;
35308 ++ unsigned long address_m;
35309 ++ pte_t *ptep_m;
35310 ++
35311 ++ vma_m = pax_find_mirror_vma(vma);
35312 ++ if (!vma_m)
35313 ++ return;
35314 ++
35315 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35316 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35317 ++ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
35318 ++ get_page(page_m);
35319 ++ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
35320 ++}
35321 ++#endif
35322 ++
35323 + static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
35324 + unsigned long address, pte_t *ptep, pte_t pte,
35325 + struct page *pagecache_page)
35326 +@@ -1904,6 +1924,11 @@ retry_avoidcopy:
35327 + huge_ptep_clear_flush(vma, address, ptep);
35328 + set_huge_pte_at(mm, address, ptep,
35329 + make_huge_pte(vma, new_page, 1));
35330 ++
35331 ++#ifdef CONFIG_PAX_SEGMEXEC
35332 ++ pax_mirror_huge_pte(vma, address, new_page);
35333 ++#endif
35334 ++
35335 + /* Make the old page be freed below */
35336 + new_page = old_page;
35337 + }
35338 +@@ -2013,6 +2038,10 @@ retry:
35339 + && (vma->vm_flags & VM_SHARED)));
35340 + set_huge_pte_at(mm, address, ptep, new_pte);
35341 +
35342 ++#ifdef CONFIG_PAX_SEGMEXEC
35343 ++ pax_mirror_huge_pte(vma, address, page);
35344 ++#endif
35345 ++
35346 + if (write_access && !(vma->vm_flags & VM_SHARED)) {
35347 + /* Optimization, do the COW without a second fault */
35348 + ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
35349 +@@ -2041,6 +2070,28 @@ int hugetlb_fault(struct mm_struct *mm,
35350 + static DEFINE_MUTEX(hugetlb_instantiation_mutex);
35351 + struct hstate *h = hstate_vma(vma);
35352 +
35353 ++#ifdef CONFIG_PAX_SEGMEXEC
35354 ++ struct vm_area_struct *vma_m;
35355 ++
35356 ++ vma_m = pax_find_mirror_vma(vma);
35357 ++ if (vma_m) {
35358 ++ unsigned long address_m;
35359 ++
35360 ++ if (vma->vm_start > vma_m->vm_start) {
35361 ++ address_m = address;
35362 ++ address -= SEGMEXEC_TASK_SIZE;
35363 ++ vma = vma_m;
35364 ++ h = hstate_vma(vma);
35365 ++ } else
35366 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35367 ++
35368 ++ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
35369 ++ return VM_FAULT_OOM;
35370 ++ address_m &= HPAGE_MASK;
35371 ++ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
35372 ++ }
35373 ++#endif
35374 ++
35375 + ptep = huge_pte_alloc(mm, address, huge_page_size(h));
35376 + if (!ptep)
35377 + return VM_FAULT_OOM;
35378 +diff -urNp linux-2.6.27.10/mm/madvise.c linux-2.6.27.10/mm/madvise.c
35379 +--- linux-2.6.27.10/mm/madvise.c 2008-11-07 12:55:34.000000000 -0500
35380 ++++ linux-2.6.27.10/mm/madvise.c 2008-11-18 03:38:45.000000000 -0500
35381 +@@ -43,6 +43,10 @@ static long madvise_behavior(struct vm_a
35382 + pgoff_t pgoff;
35383 + int new_flags = vma->vm_flags;
35384 +
35385 ++#ifdef CONFIG_PAX_SEGMEXEC
35386 ++ struct vm_area_struct *vma_m;
35387 ++#endif
35388 ++
35389 + switch (behavior) {
35390 + case MADV_NORMAL:
35391 + new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
35392 +@@ -92,6 +96,13 @@ success:
35393 + /*
35394 + * vm_flags is protected by the mmap_sem held in write mode.
35395 + */
35396 ++
35397 ++#ifdef CONFIG_PAX_SEGMEXEC
35398 ++ vma_m = pax_find_mirror_vma(vma);
35399 ++ if (vma_m)
35400 ++ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
35401 ++#endif
35402 ++
35403 + vma->vm_flags = new_flags;
35404 +
35405 + out:
35406 +@@ -236,6 +247,17 @@ madvise_vma(struct vm_area_struct *vma,
35407 +
35408 + case MADV_DONTNEED:
35409 + error = madvise_dontneed(vma, prev, start, end);
35410 ++
35411 ++#ifdef CONFIG_PAX_SEGMEXEC
35412 ++ if (!error) {
35413 ++ struct vm_area_struct *vma_m, *prev_m;
35414 ++
35415 ++ vma_m = pax_find_mirror_vma(vma);
35416 ++ if (vma_m)
35417 ++ error = madvise_dontneed(vma_m, &prev_m, start + SEGMEXEC_TASK_SIZE, end + SEGMEXEC_TASK_SIZE);
35418 ++ }
35419 ++#endif
35420 ++
35421 + break;
35422 +
35423 + default:
35424 +@@ -308,6 +330,16 @@ asmlinkage long sys_madvise(unsigned lon
35425 + if (end < start)
35426 + goto out;
35427 +
35428 ++#ifdef CONFIG_PAX_SEGMEXEC
35429 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
35430 ++ if (end > SEGMEXEC_TASK_SIZE)
35431 ++ goto out;
35432 ++ } else
35433 ++#endif
35434 ++
35435 ++ if (end > TASK_SIZE)
35436 ++ goto out;
35437 ++
35438 + error = 0;
35439 + if (end == start)
35440 + goto out;
35441 +diff -urNp linux-2.6.27.10/mm/memory.c linux-2.6.27.10/mm/memory.c
35442 +--- linux-2.6.27.10/mm/memory.c 2008-11-07 12:55:34.000000000 -0500
35443 ++++ linux-2.6.27.10/mm/memory.c 2008-11-18 03:38:45.000000000 -0500
35444 +@@ -52,6 +52,7 @@
35445 + #include <linux/writeback.h>
35446 + #include <linux/memcontrol.h>
35447 + #include <linux/mmu_notifier.h>
35448 ++#include <linux/grsecurity.h>
35449 +
35450 + #include <asm/pgalloc.h>
35451 + #include <asm/uaccess.h>
35452 +@@ -1146,11 +1147,11 @@ int get_user_pages(struct task_struct *t
35453 + vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
35454 + i = 0;
35455 +
35456 +- do {
35457 ++ while (len) {
35458 + struct vm_area_struct *vma;
35459 + unsigned int foll_flags;
35460 +
35461 +- vma = find_extend_vma(mm, start);
35462 ++ vma = find_vma(mm, start);
35463 + if (!vma && in_gate_area(tsk, start)) {
35464 + unsigned long pg = start & PAGE_MASK;
35465 + struct vm_area_struct *gate_vma = get_gate_vma(tsk);
35466 +@@ -1190,7 +1191,7 @@ int get_user_pages(struct task_struct *t
35467 + continue;
35468 + }
35469 +
35470 +- if (!vma || (vma->vm_flags & (VM_IO | VM_PFNMAP))
35471 ++ if (!vma || start < vma->vm_start || (vma->vm_flags & (VM_IO | VM_PFNMAP))
35472 + || !(vm_flags & vma->vm_flags))
35473 + return i ? : -EFAULT;
35474 +
35475 +@@ -1263,7 +1264,7 @@ int get_user_pages(struct task_struct *t
35476 + start += PAGE_SIZE;
35477 + len--;
35478 + } while (len && start < vma->vm_end);
35479 +- } while (len);
35480 ++ }
35481 + return i;
35482 + }
35483 + EXPORT_SYMBOL(get_user_pages);
35484 +@@ -1741,6 +1742,186 @@ static inline void cow_user_page(struct
35485 + copy_user_highpage(dst, src, va, vma);
35486 + }
35487 +
35488 ++#ifdef CONFIG_PAX_SEGMEXEC
35489 ++static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
35490 ++{
35491 ++ struct mm_struct *mm = vma->vm_mm;
35492 ++ spinlock_t *ptl;
35493 ++ pte_t *pte, entry;
35494 ++
35495 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
35496 ++ entry = *pte;
35497 ++ if (!pte_present(entry)) {
35498 ++ if (!pte_none(entry)) {
35499 ++ BUG_ON(pte_file(entry));
35500 ++ free_swap_and_cache(pte_to_swp_entry(entry));
35501 ++ pte_clear_not_present_full(mm, address, pte, 0);
35502 ++ }
35503 ++ } else {
35504 ++ struct page *page;
35505 ++
35506 ++ flush_cache_page(vma, address, pte_pfn(entry));
35507 ++ entry = ptep_clear_flush(vma, address, pte);
35508 ++ BUG_ON(pte_dirty(entry));
35509 ++ page = vm_normal_page(vma, address, entry);
35510 ++ if (page) {
35511 ++ update_hiwater_rss(mm);
35512 ++ if (PageAnon(page))
35513 ++ dec_mm_counter(mm, anon_rss);
35514 ++ else
35515 ++ dec_mm_counter(mm, file_rss);
35516 ++ page_remove_rmap(page, vma);
35517 ++ page_cache_release(page);
35518 ++ }
35519 ++ }
35520 ++ pte_unmap_unlock(pte, ptl);
35521 ++}
35522 ++
35523 ++/* PaX: if vma is mirrored, synchronize the mirror's PTE
35524 ++ *
35525 ++ * the ptl of the lower mapped page is held on entry and is not released on exit
35526 ++ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
35527 ++ */
35528 ++static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
35529 ++{
35530 ++ struct mm_struct *mm = vma->vm_mm;
35531 ++ unsigned long address_m;
35532 ++ spinlock_t *ptl_m;
35533 ++ struct vm_area_struct *vma_m;
35534 ++ pmd_t *pmd_m;
35535 ++ pte_t *pte_m, entry_m;
35536 ++
35537 ++ BUG_ON(!page_m || !PageAnon(page_m));
35538 ++
35539 ++ vma_m = pax_find_mirror_vma(vma);
35540 ++ if (!vma_m)
35541 ++ return;
35542 ++
35543 ++ BUG_ON(!PageLocked(page_m));
35544 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35545 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35546 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
35547 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
35548 ++ ptl_m = pte_lockptr(mm, pmd_m);
35549 ++ if (ptl != ptl_m) {
35550 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
35551 ++ if (!pte_none(*pte_m))
35552 ++ goto out;
35553 ++ }
35554 ++
35555 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
35556 ++ page_cache_get(page_m);
35557 ++ page_add_anon_rmap(page_m, vma_m, address_m);
35558 ++ inc_mm_counter(mm, anon_rss);
35559 ++ set_pte_at(mm, address_m, pte_m, entry_m);
35560 ++ update_mmu_cache(vma_m, address_m, entry_m);
35561 ++out:
35562 ++ if (ptl != ptl_m)
35563 ++ spin_unlock(ptl_m);
35564 ++ pte_unmap_nested(pte_m);
35565 ++ unlock_page(page_m);
35566 ++}
35567 ++
35568 ++void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
35569 ++{
35570 ++ struct mm_struct *mm = vma->vm_mm;
35571 ++ unsigned long address_m;
35572 ++ spinlock_t *ptl_m;
35573 ++ struct vm_area_struct *vma_m;
35574 ++ pmd_t *pmd_m;
35575 ++ pte_t *pte_m, entry_m;
35576 ++
35577 ++ BUG_ON(!page_m || PageAnon(page_m));
35578 ++
35579 ++ vma_m = pax_find_mirror_vma(vma);
35580 ++ if (!vma_m)
35581 ++ return;
35582 ++
35583 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35584 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35585 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
35586 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
35587 ++ ptl_m = pte_lockptr(mm, pmd_m);
35588 ++ if (ptl != ptl_m) {
35589 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
35590 ++ if (!pte_none(*pte_m))
35591 ++ goto out;
35592 ++ }
35593 ++
35594 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
35595 ++ page_cache_get(page_m);
35596 ++ page_add_file_rmap(page_m);
35597 ++ inc_mm_counter(mm, file_rss);
35598 ++ set_pte_at(mm, address_m, pte_m, entry_m);
35599 ++ update_mmu_cache(vma_m, address_m, entry_m);
35600 ++out:
35601 ++ if (ptl != ptl_m)
35602 ++ spin_unlock(ptl_m);
35603 ++ pte_unmap_nested(pte_m);
35604 ++}
35605 ++
35606 ++static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
35607 ++{
35608 ++ struct mm_struct *mm = vma->vm_mm;
35609 ++ unsigned long address_m;
35610 ++ spinlock_t *ptl_m;
35611 ++ struct vm_area_struct *vma_m;
35612 ++ pmd_t *pmd_m;
35613 ++ pte_t *pte_m, entry_m;
35614 ++
35615 ++ vma_m = pax_find_mirror_vma(vma);
35616 ++ if (!vma_m)
35617 ++ return;
35618 ++
35619 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35620 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35621 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
35622 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
35623 ++ ptl_m = pte_lockptr(mm, pmd_m);
35624 ++ if (ptl != ptl_m) {
35625 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
35626 ++ if (!pte_none(*pte_m))
35627 ++ goto out;
35628 ++ }
35629 ++
35630 ++ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
35631 ++ set_pte_at(mm, address_m, pte_m, entry_m);
35632 ++out:
35633 ++ if (ptl != ptl_m)
35634 ++ spin_unlock(ptl_m);
35635 ++ pte_unmap_nested(pte_m);
35636 ++}
35637 ++
35638 ++static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
35639 ++{
35640 ++ struct page *page_m;
35641 ++ pte_t entry;
35642 ++
35643 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
35644 ++ goto out;
35645 ++
35646 ++ entry = *pte;
35647 ++ page_m = vm_normal_page(vma, address, entry);
35648 ++ if (!page_m)
35649 ++ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
35650 ++ else if (PageAnon(page_m)) {
35651 ++ if (pax_find_mirror_vma(vma)) {
35652 ++ pte_unmap_unlock(pte, ptl);
35653 ++ lock_page(page_m);
35654 ++ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
35655 ++ if (pte_same(entry, *pte))
35656 ++ pax_mirror_anon_pte(vma, address, page_m, ptl);
35657 ++ else
35658 ++ unlock_page(page_m);
35659 ++ }
35660 ++ } else
35661 ++ pax_mirror_file_pte(vma, address, page_m, ptl);
35662 ++
35663 ++out:
35664 ++ pte_unmap_unlock(pte, ptl);
35665 ++}
35666 ++#endif
35667 ++
35668 + /*
35669 + * This routine handles present pages, when users try to write
35670 + * to a shared page. It is done by copying the page to a new address
35671 +@@ -1869,6 +2050,12 @@ gotten:
35672 + */
35673 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
35674 + if (likely(pte_same(*page_table, orig_pte))) {
35675 ++
35676 ++#ifdef CONFIG_PAX_SEGMEXEC
35677 ++ if (pax_find_mirror_vma(vma))
35678 ++ BUG_ON(!trylock_page(new_page));
35679 ++#endif
35680 ++
35681 + if (old_page) {
35682 + if (!PageAnon(old_page)) {
35683 + dec_mm_counter(mm, file_rss);
35684 +@@ -1917,6 +2104,10 @@ gotten:
35685 + page_remove_rmap(old_page, vma);
35686 + }
35687 +
35688 ++#ifdef CONFIG_PAX_SEGMEXEC
35689 ++ pax_mirror_anon_pte(vma, address, new_page, ptl);
35690 ++#endif
35691 ++
35692 + /* Free the old page.. */
35693 + new_page = old_page;
35694 + ret |= VM_FAULT_WRITE;
35695 +@@ -2176,6 +2367,7 @@ int vmtruncate(struct inode * inode, lof
35696 + unsigned long limit;
35697 +
35698 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
35699 ++ gr_learn_resource(current, RLIMIT_FSIZE, offset, 1);
35700 + if (limit != RLIM_INFINITY && offset > limit)
35701 + goto out_sig;
35702 + if (offset > inode->i_sb->s_maxbytes)
35703 +@@ -2326,6 +2518,11 @@ static int do_swap_page(struct mm_struct
35704 + swap_free(entry);
35705 + if (vm_swap_full())
35706 + remove_exclusive_swap_page(page);
35707 ++
35708 ++#ifdef CONFIG_PAX_SEGMEXEC
35709 ++ if (write_access || !pax_find_mirror_vma(vma))
35710 ++#endif
35711 ++
35712 + unlock_page(page);
35713 +
35714 + if (write_access) {
35715 +@@ -2337,6 +2534,11 @@ static int do_swap_page(struct mm_struct
35716 +
35717 + /* No need to invalidate - it was non-present before */
35718 + update_mmu_cache(vma, address, pte);
35719 ++
35720 ++#ifdef CONFIG_PAX_SEGMEXEC
35721 ++ pax_mirror_anon_pte(vma, address, page, ptl);
35722 ++#endif
35723 ++
35724 + unlock:
35725 + pte_unmap_unlock(page_table, ptl);
35726 + out:
35727 +@@ -2381,6 +2583,12 @@ static int do_anonymous_page(struct mm_s
35728 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
35729 + if (!pte_none(*page_table))
35730 + goto release;
35731 ++
35732 ++#ifdef CONFIG_PAX_SEGMEXEC
35733 ++ if (pax_find_mirror_vma(vma))
35734 ++ BUG_ON(!trylock_page(page));
35735 ++#endif
35736 ++
35737 + inc_mm_counter(mm, anon_rss);
35738 + lru_cache_add_active(page);
35739 + page_add_new_anon_rmap(page, vma, address);
35740 +@@ -2388,6 +2596,11 @@ static int do_anonymous_page(struct mm_s
35741 +
35742 + /* No need to invalidate - it was non-present before */
35743 + update_mmu_cache(vma, address, entry);
35744 ++
35745 ++#ifdef CONFIG_PAX_SEGMEXEC
35746 ++ pax_mirror_anon_pte(vma, address, page, ptl);
35747 ++#endif
35748 ++
35749 + unlock:
35750 + pte_unmap_unlock(page_table, ptl);
35751 + return 0;
35752 +@@ -2516,6 +2729,12 @@ static int __do_fault(struct mm_struct *
35753 + */
35754 + /* Only go through if we didn't race with anybody else... */
35755 + if (likely(pte_same(*page_table, orig_pte))) {
35756 ++
35757 ++#ifdef CONFIG_PAX_SEGMEXEC
35758 ++ if (anon && pax_find_mirror_vma(vma))
35759 ++ BUG_ON(!trylock_page(page));
35760 ++#endif
35761 ++
35762 + flush_icache_page(vma, page);
35763 + entry = mk_pte(page, vma->vm_page_prot);
35764 + if (flags & FAULT_FLAG_WRITE)
35765 +@@ -2536,6 +2755,14 @@ static int __do_fault(struct mm_struct *
35766 +
35767 + /* no need to invalidate: a not-present page won't be cached */
35768 + update_mmu_cache(vma, address, entry);
35769 ++
35770 ++#ifdef CONFIG_PAX_SEGMEXEC
35771 ++ if (anon)
35772 ++ pax_mirror_anon_pte(vma, address, page, ptl);
35773 ++ else
35774 ++ pax_mirror_file_pte(vma, address, page, ptl);
35775 ++#endif
35776 ++
35777 + } else {
35778 + mem_cgroup_uncharge_page(page);
35779 + if (anon)
35780 +@@ -2668,6 +2895,12 @@ static inline int handle_pte_fault(struc
35781 + if (write_access)
35782 + flush_tlb_page(vma, address);
35783 + }
35784 ++
35785 ++#ifdef CONFIG_PAX_SEGMEXEC
35786 ++ pax_mirror_pte(vma, address, pte, pmd, ptl);
35787 ++ return 0;
35788 ++#endif
35789 ++
35790 + unlock:
35791 + pte_unmap_unlock(pte, ptl);
35792 + return 0;
35793 +@@ -2684,6 +2917,10 @@ int handle_mm_fault(struct mm_struct *mm
35794 + pmd_t *pmd;
35795 + pte_t *pte;
35796 +
35797 ++#ifdef CONFIG_PAX_SEGMEXEC
35798 ++ struct vm_area_struct *vma_m;
35799 ++#endif
35800 ++
35801 + __set_current_state(TASK_RUNNING);
35802 +
35803 + count_vm_event(PGFAULT);
35804 +@@ -2691,6 +2928,34 @@ int handle_mm_fault(struct mm_struct *mm
35805 + if (unlikely(is_vm_hugetlb_page(vma)))
35806 + return hugetlb_fault(mm, vma, address, write_access);
35807 +
35808 ++#ifdef CONFIG_PAX_SEGMEXEC
35809 ++ vma_m = pax_find_mirror_vma(vma);
35810 ++ if (vma_m) {
35811 ++ unsigned long address_m;
35812 ++ pgd_t *pgd_m;
35813 ++ pud_t *pud_m;
35814 ++ pmd_t *pmd_m;
35815 ++
35816 ++ if (vma->vm_start > vma_m->vm_start) {
35817 ++ address_m = address;
35818 ++ address -= SEGMEXEC_TASK_SIZE;
35819 ++ vma = vma_m;
35820 ++ } else
35821 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35822 ++
35823 ++ pgd_m = pgd_offset(mm, address_m);
35824 ++ pud_m = pud_alloc(mm, pgd_m, address_m);
35825 ++ if (!pud_m)
35826 ++ return VM_FAULT_OOM;
35827 ++ pmd_m = pmd_alloc(mm, pud_m, address_m);
35828 ++ if (!pmd_m)
35829 ++ return VM_FAULT_OOM;
35830 ++ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
35831 ++ return VM_FAULT_OOM;
35832 ++ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
35833 ++ }
35834 ++#endif
35835 ++
35836 + pgd = pgd_offset(mm, address);
35837 + pud = pud_alloc(mm, pgd, address);
35838 + if (!pud)
35839 +@@ -2798,7 +3063,7 @@ static int __init gate_vma_init(void)
35840 + gate_vma.vm_start = FIXADDR_USER_START;
35841 + gate_vma.vm_end = FIXADDR_USER_END;
35842 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35843 +- gate_vma.vm_page_prot = __P101;
35844 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35845 + /*
35846 + * Make sure the vDSO gets into every core dump.
35847 + * Dumping its contents makes post-mortem fully interpretable later
35848 +diff -urNp linux-2.6.27.10/mm/mempolicy.c linux-2.6.27.10/mm/mempolicy.c
35849 +--- linux-2.6.27.10/mm/mempolicy.c 2008-11-07 12:55:34.000000000 -0500
35850 ++++ linux-2.6.27.10/mm/mempolicy.c 2008-11-18 03:38:45.000000000 -0500
35851 +@@ -555,6 +555,10 @@ static int mbind_range(struct vm_area_st
35852 + struct vm_area_struct *next;
35853 + int err;
35854 +
35855 ++#ifdef CONFIG_PAX_SEGMEXEC
35856 ++ struct vm_area_struct *vma_m;
35857 ++#endif
35858 ++
35859 + err = 0;
35860 + for (; vma && vma->vm_start < end; vma = next) {
35861 + next = vma->vm_next;
35862 +@@ -566,6 +570,16 @@ static int mbind_range(struct vm_area_st
35863 + err = policy_vma(vma, new);
35864 + if (err)
35865 + break;
35866 ++
35867 ++#ifdef CONFIG_PAX_SEGMEXEC
35868 ++ vma_m = pax_find_mirror_vma(vma);
35869 ++ if (vma_m) {
35870 ++ err = policy_vma(vma_m, new);
35871 ++ if (err)
35872 ++ break;
35873 ++ }
35874 ++#endif
35875 ++
35876 + }
35877 + return err;
35878 + }
35879 +@@ -951,6 +965,17 @@ static long do_mbind(unsigned long start
35880 +
35881 + if (end < start)
35882 + return -EINVAL;
35883 ++
35884 ++#ifdef CONFIG_PAX_SEGMEXEC
35885 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
35886 ++ if (end > SEGMEXEC_TASK_SIZE)
35887 ++ return -EINVAL;
35888 ++ } else
35889 ++#endif
35890 ++
35891 ++ if (end > TASK_SIZE)
35892 ++ return -EINVAL;
35893 ++
35894 + if (end == start)
35895 + return 0;
35896 +
35897 +diff -urNp linux-2.6.27.10/mm/mlock.c linux-2.6.27.10/mm/mlock.c
35898 +--- linux-2.6.27.10/mm/mlock.c 2008-11-07 12:55:34.000000000 -0500
35899 ++++ linux-2.6.27.10/mm/mlock.c 2008-11-18 03:38:45.000000000 -0500
35900 +@@ -12,6 +12,7 @@
35901 + #include <linux/syscalls.h>
35902 + #include <linux/sched.h>
35903 + #include <linux/module.h>
35904 ++#include <linux/grsecurity.h>
35905 +
35906 + int can_do_mlock(void)
35907 + {
35908 +@@ -93,6 +94,17 @@ static int do_mlock(unsigned long start,
35909 + return -EINVAL;
35910 + if (end == start)
35911 + return 0;
35912 ++
35913 ++#ifdef CONFIG_PAX_SEGMEXEC
35914 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
35915 ++ if (end > SEGMEXEC_TASK_SIZE)
35916 ++ return -EINVAL;
35917 ++ } else
35918 ++#endif
35919 ++
35920 ++ if (end > TASK_SIZE)
35921 ++ return -EINVAL;
35922 ++
35923 + vma = find_vma_prev(current->mm, start, &prev);
35924 + if (!vma || vma->vm_start > start)
35925 + return -ENOMEM;
35926 +@@ -150,6 +162,7 @@ asmlinkage long sys_mlock(unsigned long
35927 + lock_limit >>= PAGE_SHIFT;
35928 +
35929 + /* check against resource limits */
35930 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
35931 + if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
35932 + error = do_mlock(start, len, 1);
35933 + up_write(&current->mm->mmap_sem);
35934 +@@ -171,10 +184,10 @@ asmlinkage long sys_munlock(unsigned lon
35935 + static int do_mlockall(int flags)
35936 + {
35937 + struct vm_area_struct * vma, * prev = NULL;
35938 +- unsigned int def_flags = 0;
35939 ++ unsigned int def_flags = current->mm->def_flags & ~VM_LOCKED;
35940 +
35941 + if (flags & MCL_FUTURE)
35942 +- def_flags = VM_LOCKED;
35943 ++ def_flags |= VM_LOCKED;
35944 + current->mm->def_flags = def_flags;
35945 + if (flags == MCL_FUTURE)
35946 + goto out;
35947 +@@ -182,6 +195,12 @@ static int do_mlockall(int flags)
35948 + for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
35949 + unsigned int newflags;
35950 +
35951 ++#ifdef CONFIG_PAX_SEGMEXEC
35952 ++ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
35953 ++ break;
35954 ++#endif
35955 ++
35956 ++ BUG_ON(vma->vm_end > TASK_SIZE);
35957 + newflags = vma->vm_flags | VM_LOCKED;
35958 + if (!(flags & MCL_CURRENT))
35959 + newflags &= ~VM_LOCKED;
35960 +@@ -211,6 +230,7 @@ asmlinkage long sys_mlockall(int flags)
35961 + lock_limit >>= PAGE_SHIFT;
35962 +
35963 + ret = -ENOMEM;
35964 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm, 1);
35965 + if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
35966 + capable(CAP_IPC_LOCK))
35967 + ret = do_mlockall(flags);
35968 +diff -urNp linux-2.6.27.10/mm/mmap.c linux-2.6.27.10/mm/mmap.c
35969 +--- linux-2.6.27.10/mm/mmap.c 2008-11-07 12:55:34.000000000 -0500
35970 ++++ linux-2.6.27.10/mm/mmap.c 2008-12-21 00:44:29.000000000 -0500
35971 +@@ -27,6 +27,7 @@
35972 + #include <linux/mempolicy.h>
35973 + #include <linux/rmap.h>
35974 + #include <linux/mmu_notifier.h>
35975 ++#include <linux/grsecurity.h>
35976 +
35977 + #include <asm/uaccess.h>
35978 + #include <asm/cacheflush.h>
35979 +@@ -43,6 +44,16 @@
35980 + #define arch_rebalance_pgtables(addr, len) (addr)
35981 + #endif
35982 +
35983 ++static inline void verify_mm_writelocked(struct mm_struct *mm)
35984 ++{
35985 ++#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
35986 ++ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
35987 ++ up_read(&mm->mmap_sem);
35988 ++ BUG();
35989 ++ }
35990 ++#endif
35991 ++}
35992 ++
35993 + static void unmap_region(struct mm_struct *mm,
35994 + struct vm_area_struct *vma, struct vm_area_struct *prev,
35995 + unsigned long start, unsigned long end);
35996 +@@ -68,16 +79,25 @@ static void unmap_region(struct mm_struc
35997 + * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
35998 + *
35999 + */
36000 +-pgprot_t protection_map[16] = {
36001 ++pgprot_t protection_map[16] __read_only = {
36002 + __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
36003 + __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
36004 + };
36005 +
36006 + pgprot_t vm_get_page_prot(unsigned long vm_flags)
36007 + {
36008 +- return __pgprot(pgprot_val(protection_map[vm_flags &
36009 ++ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
36010 + (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
36011 + pgprot_val(arch_vm_get_page_prot(vm_flags)));
36012 ++
36013 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
36014 ++ if (!nx_enabled &&
36015 ++ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
36016 ++ (vm_flags & (VM_READ | VM_WRITE)))
36017 ++ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
36018 ++#endif
36019 ++
36020 ++ return prot;
36021 + }
36022 + EXPORT_SYMBOL(vm_get_page_prot);
36023 +
36024 +@@ -232,6 +252,7 @@ static struct vm_area_struct *remove_vma
36025 + struct vm_area_struct *next = vma->vm_next;
36026 +
36027 + might_sleep();
36028 ++ BUG_ON(vma->vm_mirror);
36029 + if (vma->vm_ops && vma->vm_ops->close)
36030 + vma->vm_ops->close(vma);
36031 + if (vma->vm_file) {
36032 +@@ -268,6 +289,7 @@ asmlinkage unsigned long sys_brk(unsigne
36033 + * not page aligned -Ram Gupta
36034 + */
36035 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
36036 ++ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
36037 + if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
36038 + (mm->end_data - mm->start_data) > rlim)
36039 + goto out;
36040 +@@ -697,6 +719,12 @@ static int
36041 + can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
36042 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
36043 + {
36044 ++
36045 ++#ifdef CONFIG_PAX_SEGMEXEC
36046 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
36047 ++ return 0;
36048 ++#endif
36049 ++
36050 + if (is_mergeable_vma(vma, file, vm_flags) &&
36051 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
36052 + if (vma->vm_pgoff == vm_pgoff)
36053 +@@ -716,6 +744,12 @@ static int
36054 + can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
36055 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
36056 + {
36057 ++
36058 ++#ifdef CONFIG_PAX_SEGMEXEC
36059 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
36060 ++ return 0;
36061 ++#endif
36062 ++
36063 + if (is_mergeable_vma(vma, file, vm_flags) &&
36064 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
36065 + pgoff_t vm_pglen;
36066 +@@ -758,12 +792,19 @@ can_vma_merge_after(struct vm_area_struc
36067 + struct vm_area_struct *vma_merge(struct mm_struct *mm,
36068 + struct vm_area_struct *prev, unsigned long addr,
36069 + unsigned long end, unsigned long vm_flags,
36070 +- struct anon_vma *anon_vma, struct file *file,
36071 ++ struct anon_vma *anon_vma, struct file *file,
36072 + pgoff_t pgoff, struct mempolicy *policy)
36073 + {
36074 + pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
36075 + struct vm_area_struct *area, *next;
36076 +
36077 ++#ifdef CONFIG_PAX_SEGMEXEC
36078 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
36079 ++ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
36080 ++
36081 ++ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
36082 ++#endif
36083 ++
36084 + /*
36085 + * We later require that vma->vm_flags == vm_flags,
36086 + * so this tests vma->vm_flags & VM_SPECIAL, too.
36087 +@@ -779,6 +820,15 @@ struct vm_area_struct *vma_merge(struct
36088 + if (next && next->vm_end == end) /* cases 6, 7, 8 */
36089 + next = next->vm_next;
36090 +
36091 ++#ifdef CONFIG_PAX_SEGMEXEC
36092 ++ if (prev)
36093 ++ prev_m = pax_find_mirror_vma(prev);
36094 ++ if (area)
36095 ++ area_m = pax_find_mirror_vma(area);
36096 ++ if (next)
36097 ++ next_m = pax_find_mirror_vma(next);
36098 ++#endif
36099 ++
36100 + /*
36101 + * Can it merge with the predecessor?
36102 + */
36103 +@@ -798,9 +848,24 @@ struct vm_area_struct *vma_merge(struct
36104 + /* cases 1, 6 */
36105 + vma_adjust(prev, prev->vm_start,
36106 + next->vm_end, prev->vm_pgoff, NULL);
36107 +- } else /* cases 2, 5, 7 */
36108 ++
36109 ++#ifdef CONFIG_PAX_SEGMEXEC
36110 ++ if (prev_m)
36111 ++ vma_adjust(prev_m, prev_m->vm_start,
36112 ++ next_m->vm_end, prev_m->vm_pgoff, NULL);
36113 ++#endif
36114 ++
36115 ++ } else { /* cases 2, 5, 7 */
36116 + vma_adjust(prev, prev->vm_start,
36117 + end, prev->vm_pgoff, NULL);
36118 ++
36119 ++#ifdef CONFIG_PAX_SEGMEXEC
36120 ++ if (prev_m)
36121 ++ vma_adjust(prev_m, prev_m->vm_start,
36122 ++ end_m, prev_m->vm_pgoff, NULL);
36123 ++#endif
36124 ++
36125 ++ }
36126 + return prev;
36127 + }
36128 +
36129 +@@ -811,12 +876,27 @@ struct vm_area_struct *vma_merge(struct
36130 + mpol_equal(policy, vma_policy(next)) &&
36131 + can_vma_merge_before(next, vm_flags,
36132 + anon_vma, file, pgoff+pglen)) {
36133 +- if (prev && addr < prev->vm_end) /* case 4 */
36134 ++ if (prev && addr < prev->vm_end) { /* case 4 */
36135 + vma_adjust(prev, prev->vm_start,
36136 + addr, prev->vm_pgoff, NULL);
36137 +- else /* cases 3, 8 */
36138 ++
36139 ++#ifdef CONFIG_PAX_SEGMEXEC
36140 ++ if (prev_m)
36141 ++ vma_adjust(prev_m, prev_m->vm_start,
36142 ++ addr_m, prev_m->vm_pgoff, NULL);
36143 ++#endif
36144 ++
36145 ++ } else { /* cases 3, 8 */
36146 + vma_adjust(area, addr, next->vm_end,
36147 + next->vm_pgoff - pglen, NULL);
36148 ++
36149 ++#ifdef CONFIG_PAX_SEGMEXEC
36150 ++ if (area_m)
36151 ++ vma_adjust(area_m, addr_m, next_m->vm_end,
36152 ++ next_m->vm_pgoff - pglen, NULL);
36153 ++#endif
36154 ++
36155 ++ }
36156 + return area;
36157 + }
36158 +
36159 +@@ -891,14 +971,11 @@ none:
36160 + void vm_stat_account(struct mm_struct *mm, unsigned long flags,
36161 + struct file *file, long pages)
36162 + {
36163 +- const unsigned long stack_flags
36164 +- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
36165 +-
36166 + if (file) {
36167 + mm->shared_vm += pages;
36168 + if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
36169 + mm->exec_vm += pages;
36170 +- } else if (flags & stack_flags)
36171 ++ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
36172 + mm->stack_vm += pages;
36173 + if (flags & (VM_RESERVED|VM_IO))
36174 + mm->reserved_vm += pages;
36175 +@@ -926,7 +1003,7 @@ unsigned long do_mmap_pgoff(struct file
36176 + * (the exception is when the underlying filesystem is noexec
36177 + * mounted, in which case we dont add PROT_EXEC.)
36178 + */
36179 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
36180 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
36181 + if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
36182 + prot |= PROT_EXEC;
36183 +
36184 +@@ -936,15 +1013,15 @@ unsigned long do_mmap_pgoff(struct file
36185 + if (!(flags & MAP_FIXED))
36186 + addr = round_hint_to_min(addr);
36187 +
36188 +- error = arch_mmap_check(addr, len, flags);
36189 +- if (error)
36190 +- return error;
36191 +-
36192 + /* Careful about overflows.. */
36193 + len = PAGE_ALIGN(len);
36194 + if (!len || len > TASK_SIZE)
36195 + return -ENOMEM;
36196 +
36197 ++ error = arch_mmap_check(addr, len, flags);
36198 ++ if (error)
36199 ++ return error;
36200 ++
36201 + /* offset overflow? */
36202 + if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
36203 + return -EOVERFLOW;
36204 +@@ -956,7 +1033,7 @@ unsigned long do_mmap_pgoff(struct file
36205 + /* Obtain the address to map to. we verify (or select) it and ensure
36206 + * that it represents a valid section of the address space.
36207 + */
36208 +- addr = get_unmapped_area(file, addr, len, pgoff, flags);
36209 ++ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
36210 + if (addr & ~PAGE_MASK)
36211 + return addr;
36212 +
36213 +@@ -967,6 +1044,26 @@ unsigned long do_mmap_pgoff(struct file
36214 + vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
36215 + mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
36216 +
36217 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
36218 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36219 ++
36220 ++#ifdef CONFIG_PAX_MPROTECT
36221 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
36222 ++ if ((prot & (PROT_WRITE | PROT_EXEC)) != PROT_EXEC)
36223 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
36224 ++ else
36225 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
36226 ++ }
36227 ++#endif
36228 ++
36229 ++ }
36230 ++#endif
36231 ++
36232 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
36233 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
36234 ++ vm_flags &= ~VM_PAGEEXEC;
36235 ++#endif
36236 ++
36237 + if (flags & MAP_LOCKED) {
36238 + if (!can_do_mlock())
36239 + return -EPERM;
36240 +@@ -979,6 +1076,7 @@ unsigned long do_mmap_pgoff(struct file
36241 + locked += mm->locked_vm;
36242 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
36243 + lock_limit >>= PAGE_SHIFT;
36244 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
36245 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
36246 + return -EAGAIN;
36247 + }
36248 +@@ -1051,6 +1149,9 @@ unsigned long do_mmap_pgoff(struct file
36249 + if (error)
36250 + return error;
36251 +
36252 ++ if (!gr_acl_handle_mmap(file, prot))
36253 ++ return -EACCES;
36254 ++
36255 + return mmap_region(file, addr, len, flags, vm_flags, pgoff,
36256 + accountable);
36257 + }
36258 +@@ -1064,10 +1165,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
36259 + */
36260 + int vma_wants_writenotify(struct vm_area_struct *vma)
36261 + {
36262 +- unsigned int vm_flags = vma->vm_flags;
36263 ++ unsigned long vm_flags = vma->vm_flags;
36264 +
36265 + /* If it was private or non-writable, the write bit is already clear */
36266 +- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
36267 ++ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
36268 + return 0;
36269 +
36270 + /* The backer wishes to know when pages are first written to? */
36271 +@@ -1101,14 +1202,24 @@ unsigned long mmap_region(struct file *f
36272 + unsigned long charged = 0;
36273 + struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
36274 +
36275 ++#ifdef CONFIG_PAX_SEGMEXEC
36276 ++ struct vm_area_struct *vma_m = NULL;
36277 ++#endif
36278 ++
36279 ++ /*
36280 ++ * mm->mmap_sem is required to protect against another thread
36281 ++ * changing the mappings in case we sleep.
36282 ++ */
36283 ++ verify_mm_writelocked(mm);
36284 ++
36285 + /* Clear old maps */
36286 + error = -ENOMEM;
36287 +-munmap_back:
36288 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
36289 + if (vma && vma->vm_start < addr + len) {
36290 + if (do_munmap(mm, addr, len))
36291 + return -ENOMEM;
36292 +- goto munmap_back;
36293 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
36294 ++ BUG_ON(vma && vma->vm_start < addr + len);
36295 + }
36296 +
36297 + /* Check against address space limit. */
36298 +@@ -1155,6 +1266,16 @@ munmap_back:
36299 + goto unacct_error;
36300 + }
36301 +
36302 ++#ifdef CONFIG_PAX_SEGMEXEC
36303 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
36304 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
36305 ++ if (!vma_m) {
36306 ++ error = -ENOMEM;
36307 ++ goto free_vma;
36308 ++ }
36309 ++ }
36310 ++#endif
36311 ++
36312 + vma->vm_mm = mm;
36313 + vma->vm_start = addr;
36314 + vma->vm_end = addr + len;
36315 +@@ -1177,6 +1298,19 @@ munmap_back:
36316 + error = file->f_op->mmap(file, vma);
36317 + if (error)
36318 + goto unmap_and_free_vma;
36319 ++
36320 ++#ifdef CONFIG_PAX_SEGMEXEC
36321 ++ if (vma_m && (vm_flags & VM_EXECUTABLE))
36322 ++ added_exe_file_vma(mm);
36323 ++#endif
36324 ++
36325 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
36326 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
36327 ++ vma->vm_flags |= VM_PAGEEXEC;
36328 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
36329 ++ }
36330 ++#endif
36331 ++
36332 + if (vm_flags & VM_EXECUTABLE)
36333 + added_exe_file_vma(mm);
36334 + } else if (vm_flags & VM_SHARED) {
36335 +@@ -1209,12 +1343,29 @@ munmap_back:
36336 + vma->vm_flags, NULL, file, pgoff, vma_policy(vma))) {
36337 + mpol_put(vma_policy(vma));
36338 + kmem_cache_free(vm_area_cachep, vma);
36339 ++ vma = NULL;
36340 + fput(file);
36341 ++
36342 ++#ifdef CONFIG_PAX_SEGMEXEC
36343 ++ if (vma_m) {
36344 ++ kmem_cache_free(vm_area_cachep, vma_m);
36345 ++
36346 ++ if (vm_flags & VM_EXECUTABLE)
36347 ++ removed_exe_file_vma(mm);
36348 ++ }
36349 ++#endif
36350 ++
36351 + if (vm_flags & VM_EXECUTABLE)
36352 + removed_exe_file_vma(mm);
36353 + } else {
36354 + vma_link(mm, vma, prev, rb_link, rb_parent);
36355 + file = vma->vm_file;
36356 ++
36357 ++#ifdef CONFIG_PAX_SEGMEXEC
36358 ++ if (vma_m)
36359 ++ pax_mirror_vma(vma_m, vma);
36360 ++#endif
36361 ++
36362 + }
36363 +
36364 + /* Once vma denies write, undo our temporary denial count */
36365 +@@ -1223,6 +1374,7 @@ munmap_back:
36366 + out:
36367 + mm->total_vm += len >> PAGE_SHIFT;
36368 + vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
36369 ++ track_exec_limit(mm, addr, addr + len, vm_flags);
36370 + if (vm_flags & VM_LOCKED) {
36371 + mm->locked_vm += len >> PAGE_SHIFT;
36372 + make_pages_present(addr, addr + len);
36373 +@@ -1241,6 +1393,12 @@ unmap_and_free_vma:
36374 + unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
36375 + charged = 0;
36376 + free_vma:
36377 ++
36378 ++#ifdef CONFIG_PAX_SEGMEXEC
36379 ++ if (vma_m)
36380 ++ kmem_cache_free(vm_area_cachep, vma_m);
36381 ++#endif
36382 ++
36383 + kmem_cache_free(vm_area_cachep, vma);
36384 + unacct_error:
36385 + if (charged)
36386 +@@ -1274,6 +1432,10 @@ arch_get_unmapped_area(struct file *filp
36387 + if (flags & MAP_FIXED)
36388 + return addr;
36389 +
36390 ++#ifdef CONFIG_PAX_RANDMMAP
36391 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
36392 ++#endif
36393 ++
36394 + if (addr) {
36395 + addr = PAGE_ALIGN(addr);
36396 + vma = find_vma(mm, addr);
36397 +@@ -1282,10 +1444,10 @@ arch_get_unmapped_area(struct file *filp
36398 + return addr;
36399 + }
36400 + if (len > mm->cached_hole_size) {
36401 +- start_addr = addr = mm->free_area_cache;
36402 ++ start_addr = addr = mm->free_area_cache;
36403 + } else {
36404 +- start_addr = addr = TASK_UNMAPPED_BASE;
36405 +- mm->cached_hole_size = 0;
36406 ++ start_addr = addr = mm->mmap_base;
36407 ++ mm->cached_hole_size = 0;
36408 + }
36409 +
36410 + full_search:
36411 +@@ -1296,9 +1458,8 @@ full_search:
36412 + * Start a new search - just in case we missed
36413 + * some holes.
36414 + */
36415 +- if (start_addr != TASK_UNMAPPED_BASE) {
36416 +- addr = TASK_UNMAPPED_BASE;
36417 +- start_addr = addr;
36418 ++ if (start_addr != mm->mmap_base) {
36419 ++ start_addr = addr = mm->mmap_base;
36420 + mm->cached_hole_size = 0;
36421 + goto full_search;
36422 + }
36423 +@@ -1320,10 +1481,16 @@ full_search:
36424 +
36425 + void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
36426 + {
36427 ++
36428 ++#ifdef CONFIG_PAX_SEGMEXEC
36429 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
36430 ++ return;
36431 ++#endif
36432 ++
36433 + /*
36434 + * Is this a new hole at the lowest possible address?
36435 + */
36436 +- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
36437 ++ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
36438 + mm->free_area_cache = addr;
36439 + mm->cached_hole_size = ~0UL;
36440 + }
36441 +@@ -1341,7 +1508,7 @@ arch_get_unmapped_area_topdown(struct fi
36442 + {
36443 + struct vm_area_struct *vma;
36444 + struct mm_struct *mm = current->mm;
36445 +- unsigned long addr = addr0;
36446 ++ unsigned long base = mm->mmap_base, addr = addr0;
36447 +
36448 + /* requested length too big for entire address space */
36449 + if (len > TASK_SIZE)
36450 +@@ -1350,6 +1517,10 @@ arch_get_unmapped_area_topdown(struct fi
36451 + if (flags & MAP_FIXED)
36452 + return addr;
36453 +
36454 ++#ifdef CONFIG_PAX_RANDMMAP
36455 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
36456 ++#endif
36457 ++
36458 + /* requesting a specific address */
36459 + if (addr) {
36460 + addr = PAGE_ALIGN(addr);
36461 +@@ -1407,13 +1578,21 @@ bottomup:
36462 + * can happen with large stack limits and large mmap()
36463 + * allocations.
36464 + */
36465 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
36466 ++
36467 ++#ifdef CONFIG_PAX_RANDMMAP
36468 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
36469 ++ mm->mmap_base += mm->delta_mmap;
36470 ++#endif
36471 ++
36472 ++ mm->free_area_cache = mm->mmap_base;
36473 + mm->cached_hole_size = ~0UL;
36474 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
36475 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
36476 + /*
36477 + * Restore the topdown base:
36478 + */
36479 +- mm->free_area_cache = mm->mmap_base;
36480 ++ mm->mmap_base = base;
36481 ++ mm->free_area_cache = base;
36482 + mm->cached_hole_size = ~0UL;
36483 +
36484 + return addr;
36485 +@@ -1422,6 +1601,12 @@ bottomup:
36486 +
36487 + void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
36488 + {
36489 ++
36490 ++#ifdef CONFIG_PAX_SEGMEXEC
36491 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
36492 ++ return;
36493 ++#endif
36494 ++
36495 + /*
36496 + * Is this a new hole at the highest possible address?
36497 + */
36498 +@@ -1429,8 +1614,10 @@ void arch_unmap_area_topdown(struct mm_s
36499 + mm->free_area_cache = addr;
36500 +
36501 + /* dont allow allocations above current base */
36502 +- if (mm->free_area_cache > mm->mmap_base)
36503 ++ if (mm->free_area_cache > mm->mmap_base) {
36504 + mm->free_area_cache = mm->mmap_base;
36505 ++ mm->cached_hole_size = ~0UL;
36506 ++ }
36507 + }
36508 +
36509 + unsigned long
36510 +@@ -1530,6 +1717,27 @@ out:
36511 + return prev ? prev->vm_next : vma;
36512 + }
36513 +
36514 ++#ifdef CONFIG_PAX_SEGMEXEC
36515 ++struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
36516 ++{
36517 ++ struct vm_area_struct *vma_m;
36518 ++
36519 ++ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
36520 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
36521 ++ BUG_ON(vma->vm_mirror);
36522 ++ return NULL;
36523 ++ }
36524 ++ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
36525 ++ vma_m = vma->vm_mirror;
36526 ++ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
36527 ++ BUG_ON(vma->vm_file != vma_m->vm_file);
36528 ++ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
36529 ++ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
36530 ++ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
36531 ++ return vma_m;
36532 ++}
36533 ++#endif
36534 ++
36535 + /*
36536 + * Verify that the stack growth is acceptable and
36537 + * update accounting. This is shared with both the
36538 +@@ -1546,6 +1754,7 @@ static int acct_stack_growth(struct vm_a
36539 + return -ENOMEM;
36540 +
36541 + /* Stack limit test */
36542 ++ gr_learn_resource(current, RLIMIT_STACK, size, 1);
36543 + if (size > rlim[RLIMIT_STACK].rlim_cur)
36544 + return -ENOMEM;
36545 +
36546 +@@ -1555,6 +1764,7 @@ static int acct_stack_growth(struct vm_a
36547 + unsigned long limit;
36548 + locked = mm->locked_vm + grow;
36549 + limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
36550 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
36551 + if (locked > limit && !capable(CAP_IPC_LOCK))
36552 + return -ENOMEM;
36553 + }
36554 +@@ -1569,7 +1779,7 @@ static int acct_stack_growth(struct vm_a
36555 + * Overcommit.. This must be the final test, as it will
36556 + * update security statistics.
36557 + */
36558 +- if (security_vm_enough_memory(grow))
36559 ++ if (security_vm_enough_memory_mm(mm, grow))
36560 + return -ENOMEM;
36561 +
36562 + /* Ok, everything looks good - let it rip */
36563 +@@ -1590,35 +1800,40 @@ static inline
36564 + #endif
36565 + int expand_upwards(struct vm_area_struct *vma, unsigned long address)
36566 + {
36567 +- int error;
36568 ++ int error, locknext;
36569 +
36570 + if (!(vma->vm_flags & VM_GROWSUP))
36571 + return -EFAULT;
36572 +
36573 ++ /* Also guard against wrapping around to address 0. */
36574 ++ if (address < PAGE_ALIGN(address+1))
36575 ++ address = PAGE_ALIGN(address+1);
36576 ++ else
36577 ++ return -ENOMEM;
36578 ++
36579 + /*
36580 + * We must make sure the anon_vma is allocated
36581 + * so that the anon_vma locking is not a noop.
36582 + */
36583 + if (unlikely(anon_vma_prepare(vma)))
36584 + return -ENOMEM;
36585 ++ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
36586 ++ if (locknext && unlikely(anon_vma_prepare(vma->vm_next)))
36587 ++ return -ENOMEM;
36588 + anon_vma_lock(vma);
36589 ++ if (locknext)
36590 ++ anon_vma_lock(vma->vm_next);
36591 +
36592 + /*
36593 + * vma->vm_start/vm_end cannot change under us because the caller
36594 + * is required to hold the mmap_sem in read mode. We need the
36595 +- * anon_vma lock to serialize against concurrent expand_stacks.
36596 +- * Also guard against wrapping around to address 0.
36597 ++ * anon_vma locks to serialize against concurrent expand_stacks
36598 ++ * and expand_upwards.
36599 + */
36600 +- if (address < PAGE_ALIGN(address+4))
36601 +- address = PAGE_ALIGN(address+4);
36602 +- else {
36603 +- anon_vma_unlock(vma);
36604 +- return -ENOMEM;
36605 +- }
36606 + error = 0;
36607 +
36608 + /* Somebody else might have raced and expanded it already */
36609 +- if (address > vma->vm_end) {
36610 ++ if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
36611 + unsigned long size, grow;
36612 +
36613 + size = address - vma->vm_start;
36614 +@@ -1628,6 +1843,8 @@ int expand_upwards(struct vm_area_struct
36615 + if (!error)
36616 + vma->vm_end = address;
36617 + }
36618 ++ if (locknext)
36619 ++ anon_vma_unlock(vma->vm_next);
36620 + anon_vma_unlock(vma);
36621 + return error;
36622 + }
36623 +@@ -1639,7 +1856,8 @@ int expand_upwards(struct vm_area_struct
36624 + static inline int expand_downwards(struct vm_area_struct *vma,
36625 + unsigned long address)
36626 + {
36627 +- int error;
36628 ++ int error, lockprev = 0;
36629 ++ struct vm_area_struct *prev = NULL;
36630 +
36631 + /*
36632 + * We must make sure the anon_vma is allocated
36633 +@@ -1653,6 +1871,15 @@ static inline int expand_downwards(struc
36634 + if (error)
36635 + return error;
36636 +
36637 ++#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
36638 ++ find_vma_prev(vma->vm_mm, address, &prev);
36639 ++ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
36640 ++#endif
36641 ++ if (lockprev && unlikely(anon_vma_prepare(prev)))
36642 ++ return -ENOMEM;
36643 ++ if (lockprev)
36644 ++ anon_vma_lock(prev);
36645 ++
36646 + anon_vma_lock(vma);
36647 +
36648 + /*
36649 +@@ -1662,9 +1889,15 @@ static inline int expand_downwards(struc
36650 + */
36651 +
36652 + /* Somebody else might have raced and expanded it already */
36653 +- if (address < vma->vm_start) {
36654 ++ if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
36655 + unsigned long size, grow;
36656 +
36657 ++#ifdef CONFIG_PAX_SEGMEXEC
36658 ++ struct vm_area_struct *vma_m;
36659 ++
36660 ++ vma_m = pax_find_mirror_vma(vma);
36661 ++#endif
36662 ++
36663 + size = vma->vm_end - address;
36664 + grow = (vma->vm_start - address) >> PAGE_SHIFT;
36665 +
36666 +@@ -1672,9 +1905,20 @@ static inline int expand_downwards(struc
36667 + if (!error) {
36668 + vma->vm_start = address;
36669 + vma->vm_pgoff -= grow;
36670 ++ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
36671 ++
36672 ++#ifdef CONFIG_PAX_SEGMEXEC
36673 ++ if (vma_m) {
36674 ++ vma_m->vm_start -= grow << PAGE_SHIFT;
36675 ++ vma_m->vm_pgoff -= grow;
36676 ++ }
36677 ++#endif
36678 ++
36679 + }
36680 + }
36681 + anon_vma_unlock(vma);
36682 ++ if (lockprev)
36683 ++ anon_vma_unlock(prev);
36684 + return error;
36685 + }
36686 +
36687 +@@ -1746,6 +1990,13 @@ static void remove_vma_list(struct mm_st
36688 + do {
36689 + long nrpages = vma_pages(vma);
36690 +
36691 ++#ifdef CONFIG_PAX_SEGMEXEC
36692 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
36693 ++ vma = remove_vma(vma);
36694 ++ continue;
36695 ++ }
36696 ++#endif
36697 ++
36698 + mm->total_vm -= nrpages;
36699 + if (vma->vm_flags & VM_LOCKED)
36700 + mm->locked_vm -= nrpages;
36701 +@@ -1792,6 +2043,16 @@ detach_vmas_to_be_unmapped(struct mm_str
36702 +
36703 + insertion_point = (prev ? &prev->vm_next : &mm->mmap);
36704 + do {
36705 ++
36706 ++#ifdef CONFIG_PAX_SEGMEXEC
36707 ++ if (vma->vm_mirror) {
36708 ++ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
36709 ++ vma->vm_mirror->vm_mirror = NULL;
36710 ++ vma->vm_mirror->vm_flags &= ~VM_EXEC;
36711 ++ vma->vm_mirror = NULL;
36712 ++ }
36713 ++#endif
36714 ++
36715 + rb_erase(&vma->vm_rb, &mm->mm_rb);
36716 + mm->map_count--;
36717 + tail_vma = vma;
36718 +@@ -1811,6 +2072,108 @@ detach_vmas_to_be_unmapped(struct mm_str
36719 + * Split a vma into two pieces at address 'addr', a new vma is allocated
36720 + * either for the first part or the tail.
36721 + */
36722 ++
36723 ++#ifdef CONFIG_PAX_SEGMEXEC
36724 ++int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
36725 ++ unsigned long addr, int new_below)
36726 ++{
36727 ++ struct mempolicy *pol;
36728 ++ struct vm_area_struct *new, *vma_m, *new_m = NULL;
36729 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
36730 ++
36731 ++ if (is_vm_hugetlb_page(vma) && (addr & ~HPAGE_MASK))
36732 ++ return -EINVAL;
36733 ++
36734 ++ vma_m = pax_find_mirror_vma(vma);
36735 ++ if (vma_m) {
36736 ++ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
36737 ++ if (mm->map_count >= sysctl_max_map_count-1)
36738 ++ return -ENOMEM;
36739 ++ } else if (mm->map_count >= sysctl_max_map_count)
36740 ++ return -ENOMEM;
36741 ++
36742 ++ new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
36743 ++ if (!new)
36744 ++ return -ENOMEM;
36745 ++
36746 ++ if (vma_m) {
36747 ++ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
36748 ++ if (!new_m) {
36749 ++ kmem_cache_free(vm_area_cachep, new);
36750 ++ return -ENOMEM;
36751 ++ }
36752 ++ }
36753 ++
36754 ++ /* most fields are the same, copy all, and then fixup */
36755 ++ *new = *vma;
36756 ++
36757 ++ if (new_below)
36758 ++ new->vm_end = addr;
36759 ++ else {
36760 ++ new->vm_start = addr;
36761 ++ new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
36762 ++ }
36763 ++
36764 ++ if (vma_m) {
36765 ++ *new_m = *vma_m;
36766 ++ new_m->vm_mirror = new;
36767 ++ new->vm_mirror = new_m;
36768 ++
36769 ++ if (new_below)
36770 ++ new_m->vm_end = addr_m;
36771 ++ else {
36772 ++ new_m->vm_start = addr_m;
36773 ++ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
36774 ++ }
36775 ++ }
36776 ++
36777 ++ pol = mpol_dup(vma_policy(vma));
36778 ++ if (IS_ERR(pol)) {
36779 ++ if (new_m)
36780 ++ kmem_cache_free(vm_area_cachep, new_m);
36781 ++ kmem_cache_free(vm_area_cachep, new);
36782 ++ return PTR_ERR(pol);
36783 ++ }
36784 ++ vma_set_policy(new, pol);
36785 ++
36786 ++ if (new->vm_file) {
36787 ++ get_file(new->vm_file);
36788 ++ if (vma->vm_flags & VM_EXECUTABLE)
36789 ++ added_exe_file_vma(mm);
36790 ++ }
36791 ++
36792 ++ if (new->vm_ops && new->vm_ops->open)
36793 ++ new->vm_ops->open(new);
36794 ++
36795 ++ if (new_below)
36796 ++ vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff +
36797 ++ ((addr - new->vm_start) >> PAGE_SHIFT), new);
36798 ++ else
36799 ++ vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
36800 ++
36801 ++ if (vma_m) {
36802 ++ mpol_get(pol);
36803 ++ vma_set_policy(new_m, pol);
36804 ++
36805 ++ if (new_m->vm_file) {
36806 ++ get_file(new_m->vm_file);
36807 ++ if (vma_m->vm_flags & VM_EXECUTABLE)
36808 ++ added_exe_file_vma(mm);
36809 ++ }
36810 ++
36811 ++ if (new_m->vm_ops && new_m->vm_ops->open)
36812 ++ new_m->vm_ops->open(new_m);
36813 ++
36814 ++ if (new_below)
36815 ++ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
36816 ++ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
36817 ++ else
36818 ++ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
36819 ++ }
36820 ++
36821 ++ return 0;
36822 ++}
36823 ++#else
36824 + int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
36825 + unsigned long addr, int new_below)
36826 + {
36827 +@@ -1862,17 +2225,37 @@ int split_vma(struct mm_struct * mm, str
36828 +
36829 + return 0;
36830 + }
36831 ++#endif
36832 +
36833 + /* Munmap is split into 2 main parts -- this part which finds
36834 + * what needs doing, and the areas themselves, which do the
36835 + * work. This now handles partial unmappings.
36836 + * Jeremy Fitzhardinge <jeremy@××××.org>
36837 + */
36838 ++#ifdef CONFIG_PAX_SEGMEXEC
36839 + int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
36840 + {
36841 ++ int ret = __do_munmap(mm, start, len);
36842 ++ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
36843 ++ return ret;
36844 ++
36845 ++ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
36846 ++}
36847 ++
36848 ++int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
36849 ++#else
36850 ++int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
36851 ++#endif
36852 ++{
36853 + unsigned long end;
36854 + struct vm_area_struct *vma, *prev, *last;
36855 +
36856 ++ /*
36857 ++ * mm->mmap_sem is required to protect against another thread
36858 ++ * changing the mappings in case we sleep.
36859 ++ */
36860 ++ verify_mm_writelocked(mm);
36861 ++
36862 + if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
36863 + return -EINVAL;
36864 +
36865 +@@ -1922,6 +2305,8 @@ int do_munmap(struct mm_struct *mm, unsi
36866 + /* Fix up all other VM information */
36867 + remove_vma_list(mm, vma);
36868 +
36869 ++ track_exec_limit(mm, start, end, 0UL);
36870 ++
36871 + return 0;
36872 + }
36873 +
36874 +@@ -1934,22 +2319,18 @@ asmlinkage long sys_munmap(unsigned long
36875 +
36876 + profile_munmap(addr);
36877 +
36878 ++#ifdef CONFIG_PAX_SEGMEXEC
36879 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
36880 ++ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
36881 ++ return -EINVAL;
36882 ++#endif
36883 ++
36884 + down_write(&mm->mmap_sem);
36885 + ret = do_munmap(mm, addr, len);
36886 + up_write(&mm->mmap_sem);
36887 + return ret;
36888 + }
36889 +
36890 +-static inline void verify_mm_writelocked(struct mm_struct *mm)
36891 +-{
36892 +-#ifdef CONFIG_DEBUG_VM
36893 +- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
36894 +- WARN_ON(1);
36895 +- up_read(&mm->mmap_sem);
36896 +- }
36897 +-#endif
36898 +-}
36899 +-
36900 + /*
36901 + * this is really a simplified "do_mmap". it only handles
36902 + * anonymous maps. eventually we may be able to do some
36903 +@@ -1963,6 +2344,11 @@ unsigned long do_brk(unsigned long addr,
36904 + struct rb_node ** rb_link, * rb_parent;
36905 + pgoff_t pgoff = addr >> PAGE_SHIFT;
36906 + int error;
36907 ++ unsigned long charged;
36908 ++
36909 ++#ifdef CONFIG_PAX_SEGMEXEC
36910 ++ struct vm_area_struct *vma_m = NULL;
36911 ++#endif
36912 +
36913 + len = PAGE_ALIGN(len);
36914 + if (!len)
36915 +@@ -1980,19 +2366,34 @@ unsigned long do_brk(unsigned long addr,
36916 +
36917 + flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
36918 +
36919 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
36920 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36921 ++ flags &= ~VM_EXEC;
36922 ++
36923 ++#ifdef CONFIG_PAX_MPROTECT
36924 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
36925 ++ flags &= ~VM_MAYEXEC;
36926 ++#endif
36927 ++
36928 ++ }
36929 ++#endif
36930 ++
36931 + error = arch_mmap_check(addr, len, flags);
36932 + if (error)
36933 + return error;
36934 +
36935 ++ charged = len >> PAGE_SHIFT;
36936 ++
36937 + /*
36938 + * mlock MCL_FUTURE?
36939 + */
36940 + if (mm->def_flags & VM_LOCKED) {
36941 + unsigned long locked, lock_limit;
36942 +- locked = len >> PAGE_SHIFT;
36943 ++ locked = charged;
36944 + locked += mm->locked_vm;
36945 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
36946 + lock_limit >>= PAGE_SHIFT;
36947 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
36948 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
36949 + return -EAGAIN;
36950 + }
36951 +@@ -2006,22 +2407,22 @@ unsigned long do_brk(unsigned long addr,
36952 + /*
36953 + * Clear old maps. this also does some error checking for us
36954 + */
36955 +- munmap_back:
36956 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
36957 + if (vma && vma->vm_start < addr + len) {
36958 + if (do_munmap(mm, addr, len))
36959 + return -ENOMEM;
36960 +- goto munmap_back;
36961 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
36962 ++ BUG_ON(vma && vma->vm_start < addr + len);
36963 + }
36964 +
36965 + /* Check against address space limits *after* clearing old maps... */
36966 +- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
36967 ++ if (!may_expand_vm(mm, charged))
36968 + return -ENOMEM;
36969 +
36970 + if (mm->map_count > sysctl_max_map_count)
36971 + return -ENOMEM;
36972 +
36973 +- if (security_vm_enough_memory(len >> PAGE_SHIFT))
36974 ++ if (security_vm_enough_memory(charged))
36975 + return -ENOMEM;
36976 +
36977 + /* Can we just expand an old private anonymous mapping? */
36978 +@@ -2034,10 +2435,21 @@ unsigned long do_brk(unsigned long addr,
36979 + */
36980 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
36981 + if (!vma) {
36982 +- vm_unacct_memory(len >> PAGE_SHIFT);
36983 ++ vm_unacct_memory(charged);
36984 + return -ENOMEM;
36985 + }
36986 +
36987 ++#ifdef CONFIG_PAX_SEGMEXEC
36988 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (flags & VM_EXEC)) {
36989 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
36990 ++ if (!vma_m) {
36991 ++ kmem_cache_free(vm_area_cachep, vma);
36992 ++ vm_unacct_memory(charged);
36993 ++ return -ENOMEM;
36994 ++ }
36995 ++ }
36996 ++#endif
36997 ++
36998 + vma->vm_mm = mm;
36999 + vma->vm_start = addr;
37000 + vma->vm_end = addr + len;
37001 +@@ -2045,12 +2457,19 @@ unsigned long do_brk(unsigned long addr,
37002 + vma->vm_flags = flags;
37003 + vma->vm_page_prot = vm_get_page_prot(flags);
37004 + vma_link(mm, vma, prev, rb_link, rb_parent);
37005 ++
37006 ++#ifdef CONFIG_PAX_SEGMEXEC
37007 ++ if (vma_m)
37008 ++ pax_mirror_vma(vma_m, vma);
37009 ++#endif
37010 ++
37011 + out:
37012 +- mm->total_vm += len >> PAGE_SHIFT;
37013 ++ mm->total_vm += charged;
37014 + if (flags & VM_LOCKED) {
37015 +- mm->locked_vm += len >> PAGE_SHIFT;
37016 ++ mm->locked_vm += charged;
37017 + make_pages_present(addr, addr + len);
37018 + }
37019 ++ track_exec_limit(mm, addr, addr + len, flags);
37020 + return addr;
37021 + }
37022 +
37023 +@@ -2082,8 +2501,10 @@ void exit_mmap(struct mm_struct *mm)
37024 + * Walk the list again, actually closing and freeing it,
37025 + * with preemption enabled, without holding any MM locks.
37026 + */
37027 +- while (vma)
37028 ++ while (vma) {
37029 ++ vma->vm_mirror = NULL;
37030 + vma = remove_vma(vma);
37031 ++ }
37032 +
37033 + BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
37034 + }
37035 +@@ -2097,6 +2518,10 @@ int insert_vm_struct(struct mm_struct *
37036 + struct vm_area_struct * __vma, * prev;
37037 + struct rb_node ** rb_link, * rb_parent;
37038 +
37039 ++#ifdef CONFIG_PAX_SEGMEXEC
37040 ++ struct vm_area_struct *vma_m = NULL;
37041 ++#endif
37042 ++
37043 + /*
37044 + * The vm_pgoff of a purely anonymous vma should be irrelevant
37045 + * until its first write fault, when page's anon_vma and index
37046 +@@ -2119,7 +2544,22 @@ int insert_vm_struct(struct mm_struct *
37047 + if ((vma->vm_flags & VM_ACCOUNT) &&
37048 + security_vm_enough_memory_mm(mm, vma_pages(vma)))
37049 + return -ENOMEM;
37050 ++
37051 ++#ifdef CONFIG_PAX_SEGMEXEC
37052 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
37053 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
37054 ++ if (!vma_m)
37055 ++ return -ENOMEM;
37056 ++ }
37057 ++#endif
37058 ++
37059 + vma_link(mm, vma, prev, rb_link, rb_parent);
37060 ++
37061 ++#ifdef CONFIG_PAX_SEGMEXEC
37062 ++ if (vma_m)
37063 ++ pax_mirror_vma(vma_m, vma);
37064 ++#endif
37065 ++
37066 + return 0;
37067 + }
37068 +
37069 +@@ -2137,6 +2577,8 @@ struct vm_area_struct *copy_vma(struct v
37070 + struct rb_node **rb_link, *rb_parent;
37071 + struct mempolicy *pol;
37072 +
37073 ++ BUG_ON(vma->vm_mirror);
37074 ++
37075 + /*
37076 + * If anonymous vma has not yet been faulted, update new pgoff
37077 + * to match new location, to increase its chance of merging.
37078 +@@ -2180,6 +2622,35 @@ struct vm_area_struct *copy_vma(struct v
37079 + return new_vma;
37080 + }
37081 +
37082 ++#ifdef CONFIG_PAX_SEGMEXEC
37083 ++void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
37084 ++{
37085 ++ struct vm_area_struct *prev_m;
37086 ++ struct rb_node **rb_link_m, *rb_parent_m;
37087 ++ struct mempolicy *pol_m;
37088 ++
37089 ++ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
37090 ++ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
37091 ++ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
37092 ++ *vma_m = *vma;
37093 ++ pol_m = vma_policy(vma_m);
37094 ++ mpol_get(pol_m);
37095 ++ vma_set_policy(vma_m, pol_m);
37096 ++ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
37097 ++ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
37098 ++ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
37099 ++ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
37100 ++ if (vma_m->vm_file)
37101 ++ get_file(vma_m->vm_file);
37102 ++ if (vma_m->vm_ops && vma_m->vm_ops->open)
37103 ++ vma_m->vm_ops->open(vma_m);
37104 ++ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
37105 ++ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
37106 ++ vma_m->vm_mirror = vma;
37107 ++ vma->vm_mirror = vma_m;
37108 ++}
37109 ++#endif
37110 ++
37111 + /*
37112 + * Return true if the calling process may expand its vm space by the passed
37113 + * number of pages
37114 +@@ -2190,7 +2661,7 @@ int may_expand_vm(struct mm_struct *mm,
37115 + unsigned long lim;
37116 +
37117 + lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
37118 +-
37119 ++ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
37120 + if (cur + npages > lim)
37121 + return 0;
37122 + return 1;
37123 +@@ -2259,6 +2730,15 @@ int install_special_mapping(struct mm_st
37124 + vma->vm_start = addr;
37125 + vma->vm_end = addr + len;
37126 +
37127 ++#ifdef CONFIG_PAX_MPROTECT
37128 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
37129 ++ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
37130 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
37131 ++ else
37132 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
37133 ++ }
37134 ++#endif
37135 ++
37136 + vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
37137 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
37138 +
37139 +diff -urNp linux-2.6.27.10/mm/mprotect.c linux-2.6.27.10/mm/mprotect.c
37140 +--- linux-2.6.27.10/mm/mprotect.c 2008-11-07 12:55:34.000000000 -0500
37141 ++++ linux-2.6.27.10/mm/mprotect.c 2008-12-21 00:45:45.000000000 -0500
37142 +@@ -22,10 +22,17 @@
37143 + #include <linux/swap.h>
37144 + #include <linux/swapops.h>
37145 + #include <linux/mmu_notifier.h>
37146 ++#include <linux/grsecurity.h>
37147 ++
37148 ++#ifdef CONFIG_PAX_MPROTECT
37149 ++#include <linux/elf.h>
37150 ++#endif
37151 ++
37152 + #include <asm/uaccess.h>
37153 + #include <asm/pgtable.h>
37154 + #include <asm/cacheflush.h>
37155 + #include <asm/tlbflush.h>
37156 ++#include <asm/mmu_context.h>
37157 +
37158 + #ifndef pgprot_modify
37159 + static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
37160 +@@ -133,6 +140,48 @@ static void change_protection(struct vm_
37161 + flush_tlb_range(vma, start, end);
37162 + }
37163 +
37164 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
37165 ++/* called while holding the mmap semaphor for writing except stack expansion */
37166 ++void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
37167 ++{
37168 ++ unsigned long oldlimit, newlimit = 0UL;
37169 ++
37170 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
37171 ++ return;
37172 ++
37173 ++ spin_lock(&mm->page_table_lock);
37174 ++ oldlimit = mm->context.user_cs_limit;
37175 ++ if ((prot & VM_EXEC) && oldlimit < end)
37176 ++ /* USER_CS limit moved up */
37177 ++ newlimit = end;
37178 ++ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
37179 ++ /* USER_CS limit moved down */
37180 ++ newlimit = start;
37181 ++
37182 ++ if (newlimit) {
37183 ++ mm->context.user_cs_limit = newlimit;
37184 ++
37185 ++#ifdef CONFIG_SMP
37186 ++ wmb();
37187 ++ cpus_clear(mm->context.cpu_user_cs_mask);
37188 ++ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
37189 ++#endif
37190 ++
37191 ++ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
37192 ++ }
37193 ++ spin_unlock(&mm->page_table_lock);
37194 ++ if (newlimit == end) {
37195 ++ struct vm_area_struct *vma = find_vma(mm, oldlimit);
37196 ++
37197 ++ for (; vma && vma->vm_start < end; vma = vma->vm_next)
37198 ++ if (is_vm_hugetlb_page(vma))
37199 ++ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
37200 ++ else
37201 ++ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
37202 ++ }
37203 ++}
37204 ++#endif
37205 ++
37206 + int
37207 + mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
37208 + unsigned long start, unsigned long end, unsigned long newflags)
37209 +@@ -145,6 +194,14 @@ mprotect_fixup(struct vm_area_struct *vm
37210 + int error;
37211 + int dirty_accountable = 0;
37212 +
37213 ++#ifdef CONFIG_PAX_SEGMEXEC
37214 ++ struct vm_area_struct *vma_m = NULL;
37215 ++ unsigned long start_m, end_m;
37216 ++
37217 ++ start_m = start + SEGMEXEC_TASK_SIZE;
37218 ++ end_m = end + SEGMEXEC_TASK_SIZE;
37219 ++#endif
37220 ++
37221 + if (newflags == oldflags) {
37222 + *pprev = vma;
37223 + return 0;
37224 +@@ -165,6 +222,38 @@ mprotect_fixup(struct vm_area_struct *vm
37225 + }
37226 + }
37227 +
37228 ++#ifdef CONFIG_PAX_SEGMEXEC
37229 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
37230 ++ if (start != vma->vm_start) {
37231 ++ error = split_vma(mm, vma, start, 1);
37232 ++ if (error)
37233 ++ goto fail;
37234 ++ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
37235 ++ *pprev = (*pprev)->vm_next;
37236 ++ }
37237 ++
37238 ++ if (end != vma->vm_end) {
37239 ++ error = split_vma(mm, vma, end, 0);
37240 ++ if (error)
37241 ++ goto fail;
37242 ++ }
37243 ++
37244 ++ if (pax_find_mirror_vma(vma)) {
37245 ++ error = __do_munmap(mm, start_m, end_m - start_m);
37246 ++ if (error)
37247 ++ goto fail;
37248 ++ } else {
37249 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
37250 ++ if (!vma_m) {
37251 ++ error = -ENOMEM;
37252 ++ goto fail;
37253 ++ }
37254 ++ vma->vm_flags = newflags;
37255 ++ pax_mirror_vma(vma_m, vma);
37256 ++ }
37257 ++ }
37258 ++#endif
37259 ++
37260 + /*
37261 + * First try to merge with previous and/or next vma.
37262 + */
37263 +@@ -196,8 +285,14 @@ success:
37264 + * held in write mode.
37265 + */
37266 + vma->vm_flags = newflags;
37267 ++
37268 ++#ifdef CONFIG_PAX_MPROTECT
37269 ++ if (current->binfmt && current->binfmt->handle_mprotect)
37270 ++ current->binfmt->handle_mprotect(vma, newflags);
37271 ++#endif
37272 ++
37273 + vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
37274 +- vm_get_page_prot(newflags));
37275 ++ vm_get_page_prot(vma->vm_flags));
37276 +
37277 + if (vma_wants_writenotify(vma)) {
37278 + vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
37279 +@@ -238,6 +333,17 @@ sys_mprotect(unsigned long start, size_t
37280 + end = start + len;
37281 + if (end <= start)
37282 + return -ENOMEM;
37283 ++
37284 ++#ifdef CONFIG_PAX_SEGMEXEC
37285 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
37286 ++ if (end > SEGMEXEC_TASK_SIZE)
37287 ++ return -EINVAL;
37288 ++ } else
37289 ++#endif
37290 ++
37291 ++ if (end > TASK_SIZE)
37292 ++ return -EINVAL;
37293 ++
37294 + if (!arch_validate_prot(prot))
37295 + return -EINVAL;
37296 +
37297 +@@ -245,7 +351,7 @@ sys_mprotect(unsigned long start, size_t
37298 + /*
37299 + * Does the application expect PROT_READ to imply PROT_EXEC:
37300 + */
37301 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
37302 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
37303 + prot |= PROT_EXEC;
37304 +
37305 + vm_flags = calc_vm_prot_bits(prot);
37306 +@@ -277,6 +383,16 @@ sys_mprotect(unsigned long start, size_t
37307 + if (start > vma->vm_start)
37308 + prev = vma;
37309 +
37310 ++ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
37311 ++ error = -EACCES;
37312 ++ goto out;
37313 ++ }
37314 ++
37315 ++#ifdef CONFIG_PAX_MPROTECT
37316 ++ if (current->binfmt && current->binfmt->handle_mprotect)
37317 ++ current->binfmt->handle_mprotect(vma, vm_flags);
37318 ++#endif
37319 ++
37320 + for (nstart = start ; ; ) {
37321 + unsigned long newflags;
37322 +
37323 +@@ -300,6 +416,9 @@ sys_mprotect(unsigned long start, size_t
37324 + error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
37325 + if (error)
37326 + goto out;
37327 ++
37328 ++ track_exec_limit(current->mm, nstart, tmp, vm_flags);
37329 ++
37330 + nstart = tmp;
37331 +
37332 + if (nstart < prev->vm_end)
37333 +diff -urNp linux-2.6.27.10/mm/mremap.c linux-2.6.27.10/mm/mremap.c
37334 +--- linux-2.6.27.10/mm/mremap.c 2008-11-07 12:55:34.000000000 -0500
37335 ++++ linux-2.6.27.10/mm/mremap.c 2008-11-18 03:38:45.000000000 -0500
37336 +@@ -111,6 +111,12 @@ static void move_ptes(struct vm_area_str
37337 + continue;
37338 + pte = ptep_clear_flush(vma, old_addr, old_pte);
37339 + pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
37340 ++
37341 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
37342 ++ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
37343 ++ pte = pte_exprotect(pte);
37344 ++#endif
37345 ++
37346 + set_pte_at(mm, new_addr, new_pte, pte);
37347 + }
37348 +
37349 +@@ -260,6 +266,7 @@ unsigned long do_mremap(unsigned long ad
37350 + struct vm_area_struct *vma;
37351 + unsigned long ret = -EINVAL;
37352 + unsigned long charged = 0;
37353 ++ unsigned long pax_task_size = TASK_SIZE;
37354 +
37355 + if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
37356 + goto out;
37357 +@@ -278,6 +285,15 @@ unsigned long do_mremap(unsigned long ad
37358 + if (!new_len)
37359 + goto out;
37360 +
37361 ++#ifdef CONFIG_PAX_SEGMEXEC
37362 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
37363 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
37364 ++#endif
37365 ++
37366 ++ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
37367 ++ old_len > pax_task_size || addr > pax_task_size-old_len)
37368 ++ goto out;
37369 ++
37370 + /* new_addr is only valid if MREMAP_FIXED is specified */
37371 + if (flags & MREMAP_FIXED) {
37372 + if (new_addr & ~PAGE_MASK)
37373 +@@ -285,16 +301,13 @@ unsigned long do_mremap(unsigned long ad
37374 + if (!(flags & MREMAP_MAYMOVE))
37375 + goto out;
37376 +
37377 +- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
37378 ++ if (new_addr > pax_task_size - new_len)
37379 + goto out;
37380 +
37381 + /* Check if the location we're moving into overlaps the
37382 + * old location at all, and fail if it does.
37383 + */
37384 +- if ((new_addr <= addr) && (new_addr+new_len) > addr)
37385 +- goto out;
37386 +-
37387 +- if ((addr <= new_addr) && (addr+old_len) > new_addr)
37388 ++ if (addr + old_len > new_addr && new_addr + new_len > addr)
37389 + goto out;
37390 +
37391 + ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
37392 +@@ -332,6 +345,14 @@ unsigned long do_mremap(unsigned long ad
37393 + ret = -EINVAL;
37394 + goto out;
37395 + }
37396 ++
37397 ++#ifdef CONFIG_PAX_SEGMEXEC
37398 ++ if (pax_find_mirror_vma(vma)) {
37399 ++ ret = -EINVAL;
37400 ++ goto out;
37401 ++ }
37402 ++#endif
37403 ++
37404 + /* We can't remap across vm area boundaries */
37405 + if (old_len > vma->vm_end - addr)
37406 + goto out;
37407 +@@ -365,7 +386,7 @@ unsigned long do_mremap(unsigned long ad
37408 + if (old_len == vma->vm_end - addr &&
37409 + !((flags & MREMAP_FIXED) && (addr != new_addr)) &&
37410 + (old_len != new_len || !(flags & MREMAP_MAYMOVE))) {
37411 +- unsigned long max_addr = TASK_SIZE;
37412 ++ unsigned long max_addr = pax_task_size;
37413 + if (vma->vm_next)
37414 + max_addr = vma->vm_next->vm_start;
37415 + /* can we just expand the current mapping? */
37416 +@@ -383,6 +404,7 @@ unsigned long do_mremap(unsigned long ad
37417 + addr + new_len);
37418 + }
37419 + ret = addr;
37420 ++ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
37421 + goto out;
37422 + }
37423 + }
37424 +@@ -393,8 +415,8 @@ unsigned long do_mremap(unsigned long ad
37425 + */
37426 + ret = -ENOMEM;
37427 + if (flags & MREMAP_MAYMOVE) {
37428 ++ unsigned long map_flags = 0;
37429 + if (!(flags & MREMAP_FIXED)) {
37430 +- unsigned long map_flags = 0;
37431 + if (vma->vm_flags & VM_MAYSHARE)
37432 + map_flags |= MAP_SHARED;
37433 +
37434 +@@ -409,7 +431,12 @@ unsigned long do_mremap(unsigned long ad
37435 + if (ret)
37436 + goto out;
37437 + }
37438 ++ map_flags = vma->vm_flags;
37439 + ret = move_vma(vma, addr, old_len, new_len, new_addr);
37440 ++ if (!(ret & ~PAGE_MASK)) {
37441 ++ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
37442 ++ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
37443 ++ }
37444 + }
37445 + out:
37446 + if (ret & ~PAGE_MASK)
37447 +diff -urNp linux-2.6.27.10/mm/nommu.c linux-2.6.27.10/mm/nommu.c
37448 +--- linux-2.6.27.10/mm/nommu.c 2008-11-07 12:55:34.000000000 -0500
37449 ++++ linux-2.6.27.10/mm/nommu.c 2008-11-18 03:38:45.000000000 -0500
37450 +@@ -437,15 +437,6 @@ struct vm_area_struct *find_vma(struct m
37451 + }
37452 + EXPORT_SYMBOL(find_vma);
37453 +
37454 +-/*
37455 +- * find a VMA
37456 +- * - we don't extend stack VMAs under NOMMU conditions
37457 +- */
37458 +-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
37459 +-{
37460 +- return find_vma(mm, addr);
37461 +-}
37462 +-
37463 + int expand_stack(struct vm_area_struct *vma, unsigned long address)
37464 + {
37465 + return -ENOMEM;
37466 +diff -urNp linux-2.6.27.10/mm/page_alloc.c linux-2.6.27.10/mm/page_alloc.c
37467 +--- linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:12.000000000 -0500
37468 ++++ linux-2.6.27.10/mm/page_alloc.c 2008-12-21 01:18:22.000000000 -0500
37469 +@@ -515,9 +515,20 @@ static void free_pages_bulk(struct zone
37470 +
37471 + static void free_one_page(struct zone *zone, struct page *page, int order)
37472 + {
37473 ++
37474 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
37475 ++ unsigned long index = 1UL << order;
37476 ++#endif
37477 ++
37478 + spin_lock(&zone->lock);
37479 + zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
37480 + zone->pages_scanned = 0;
37481 ++
37482 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
37483 ++ for (; index; --index)
37484 ++ sanitize_highpage(page + index - 1);
37485 ++#endif
37486 ++
37487 + __free_one_page(page, zone, order);
37488 + spin_unlock(&zone->lock);
37489 + }
37490 +@@ -635,8 +646,10 @@ static int prep_new_page(struct page *pa
37491 + arch_alloc_page(page, order);
37492 + kernel_map_pages(page, 1 << order, 1);
37493 +
37494 ++#ifndef CONFIG_PAX_MEMORY_SANITIZE
37495 + if (gfp_flags & __GFP_ZERO)
37496 + prep_zero_page(page, order, gfp_flags);
37497 ++#endif
37498 +
37499 + if (order && (gfp_flags & __GFP_COMP))
37500 + prep_compound_page(page, order);
37501 +@@ -1009,6 +1022,11 @@ static void free_hot_cold_page(struct pa
37502 + list_add(&page->lru, &pcp->list);
37503 + set_page_private(page, get_pageblock_migratetype(page));
37504 + pcp->count++;
37505 ++
37506 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
37507 ++ sanitize_highpage(page);
37508 ++#endif
37509 ++
37510 + if (pcp->count >= pcp->high) {
37511 + free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
37512 + pcp->count -= pcp->batch;
37513 +diff -urNp linux-2.6.27.10/mm/rmap.c linux-2.6.27.10/mm/rmap.c
37514 +--- linux-2.6.27.10/mm/rmap.c 2008-11-07 12:55:34.000000000 -0500
37515 ++++ linux-2.6.27.10/mm/rmap.c 2008-11-18 03:38:45.000000000 -0500
37516 +@@ -91,6 +91,10 @@ int anon_vma_prepare(struct vm_area_stru
37517 + struct mm_struct *mm = vma->vm_mm;
37518 + struct anon_vma *allocated;
37519 +
37520 ++#ifdef CONFIG_PAX_SEGMEXEC
37521 ++ struct vm_area_struct *vma_m;
37522 ++#endif
37523 ++
37524 + anon_vma = find_mergeable_anon_vma(vma);
37525 + allocated = NULL;
37526 + if (!anon_vma) {
37527 +@@ -104,6 +108,15 @@ int anon_vma_prepare(struct vm_area_stru
37528 + /* page_table_lock to protect against threads */
37529 + spin_lock(&mm->page_table_lock);
37530 + if (likely(!vma->anon_vma)) {
37531 ++
37532 ++#ifdef CONFIG_PAX_SEGMEXEC
37533 ++ vma_m = pax_find_mirror_vma(vma);
37534 ++ if (vma_m) {
37535 ++ vma_m->anon_vma = anon_vma;
37536 ++ __anon_vma_link(vma_m);
37537 ++ }
37538 ++#endif
37539 ++
37540 + vma->anon_vma = anon_vma;
37541 + list_add_tail(&vma->anon_vma_node, &anon_vma->head);
37542 + allocated = NULL;
37543 +diff -urNp linux-2.6.27.10/mm/shmem.c linux-2.6.27.10/mm/shmem.c
37544 +--- linux-2.6.27.10/mm/shmem.c 2008-11-07 12:55:34.000000000 -0500
37545 ++++ linux-2.6.27.10/mm/shmem.c 2008-11-18 03:38:45.000000000 -0500
37546 +@@ -2483,7 +2483,7 @@ static struct file_system_type tmpfs_fs_
37547 + .get_sb = shmem_get_sb,
37548 + .kill_sb = kill_litter_super,
37549 + };
37550 +-static struct vfsmount *shm_mnt;
37551 ++struct vfsmount *shm_mnt;
37552 +
37553 + static int __init init_tmpfs(void)
37554 + {
37555 +diff -urNp linux-2.6.27.10/mm/slab.c linux-2.6.27.10/mm/slab.c
37556 +--- linux-2.6.27.10/mm/slab.c 2008-11-07 12:55:34.000000000 -0500
37557 ++++ linux-2.6.27.10/mm/slab.c 2008-11-18 03:38:45.000000000 -0500
37558 +@@ -304,7 +304,7 @@ struct kmem_list3 {
37559 + * Need this for bootstrapping a per node allocator.
37560 + */
37561 + #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
37562 +-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
37563 ++struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
37564 + #define CACHE_CACHE 0
37565 + #define SIZE_AC MAX_NUMNODES
37566 + #define SIZE_L3 (2 * MAX_NUMNODES)
37567 +@@ -653,14 +653,14 @@ struct cache_names {
37568 + static struct cache_names __initdata cache_names[] = {
37569 + #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
37570 + #include <linux/kmalloc_sizes.h>
37571 +- {NULL,}
37572 ++ {NULL, NULL}
37573 + #undef CACHE
37574 + };
37575 +
37576 + static struct arraycache_init initarray_cache __initdata =
37577 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
37578 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
37579 + static struct arraycache_init initarray_generic =
37580 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
37581 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
37582 +
37583 + /* internal cache of cache description objs */
37584 + static struct kmem_cache cache_cache = {
37585 +@@ -2996,7 +2996,7 @@ retry:
37586 + * there must be at least one object available for
37587 + * allocation.
37588 + */
37589 +- BUG_ON(slabp->inuse < 0 || slabp->inuse >= cachep->num);
37590 ++ BUG_ON(slabp->inuse >= cachep->num);
37591 +
37592 + while (slabp->inuse < cachep->num && batchcount--) {
37593 + STATS_INC_ALLOCED(cachep);
37594 +diff -urNp linux-2.6.27.10/mm/tiny-shmem.c linux-2.6.27.10/mm/tiny-shmem.c
37595 +--- linux-2.6.27.10/mm/tiny-shmem.c 2008-11-07 12:55:34.000000000 -0500
37596 ++++ linux-2.6.27.10/mm/tiny-shmem.c 2008-11-18 03:38:45.000000000 -0500
37597 +@@ -26,7 +26,7 @@ static struct file_system_type tmpfs_fs_
37598 + .kill_sb = kill_litter_super,
37599 + };
37600 +
37601 +-static struct vfsmount *shm_mnt;
37602 ++struct vfsmount *shm_mnt;
37603 +
37604 + static int __init init_tmpfs(void)
37605 + {
37606 +diff -urNp linux-2.6.27.10/mm/util.c linux-2.6.27.10/mm/util.c
37607 +--- linux-2.6.27.10/mm/util.c 2008-11-07 12:55:34.000000000 -0500
37608 ++++ linux-2.6.27.10/mm/util.c 2008-11-18 03:38:45.000000000 -0500
37609 +@@ -167,6 +167,12 @@ EXPORT_SYMBOL(strndup_user);
37610 + void arch_pick_mmap_layout(struct mm_struct *mm)
37611 + {
37612 + mm->mmap_base = TASK_UNMAPPED_BASE;
37613 ++
37614 ++#ifdef CONFIG_PAX_RANDMMAP
37615 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
37616 ++ mm->mmap_base += mm->delta_mmap;
37617 ++#endif
37618 ++
37619 + mm->get_unmapped_area = arch_get_unmapped_area;
37620 + mm->unmap_area = arch_unmap_area;
37621 + }
37622 +diff -urNp linux-2.6.27.10/mm/vmalloc.c linux-2.6.27.10/mm/vmalloc.c
37623 +--- linux-2.6.27.10/mm/vmalloc.c 2008-11-07 12:55:34.000000000 -0500
37624 ++++ linux-2.6.27.10/mm/vmalloc.c 2008-11-18 03:38:45.000000000 -0500
37625 +@@ -98,19 +98,36 @@ static int vmap_pte_range(pmd_t *pmd, un
37626 + unsigned long end, pgprot_t prot, struct page ***pages)
37627 + {
37628 + pte_t *pte;
37629 ++ int ret = -ENOMEM;
37630 ++
37631 ++#ifdef CONFIG_PAX_KERNEXEC
37632 ++ unsigned long cr0;
37633 ++#endif
37634 +
37635 + pte = pte_alloc_kernel(pmd, addr);
37636 + if (!pte)
37637 + return -ENOMEM;
37638 ++
37639 ++#ifdef CONFIG_PAX_KERNEXEC
37640 ++ pax_open_kernel(cr0);
37641 ++#endif
37642 ++
37643 + do {
37644 + struct page *page = **pages;
37645 + WARN_ON(!pte_none(*pte));
37646 + if (!page)
37647 +- return -ENOMEM;
37648 ++ goto out;
37649 + set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
37650 + (*pages)++;
37651 + } while (pte++, addr += PAGE_SIZE, addr != end);
37652 +- return 0;
37653 ++ ret = 0;
37654 ++out:
37655 ++
37656 ++#ifdef CONFIG_PAX_KERNEXEC
37657 ++ pax_close_kernel(cr0);
37658 ++#endif
37659 ++
37660 ++ return ret;
37661 + }
37662 +
37663 + static inline int vmap_pmd_range(pud_t *pud, unsigned long addr,
37664 +@@ -215,6 +232,16 @@ __get_vm_area_node(unsigned long size, u
37665 + unsigned long addr;
37666 +
37667 + BUG_ON(in_interrupt());
37668 ++
37669 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37670 ++ if (flags & VM_KERNEXEC) {
37671 ++ if (start != VMALLOC_START || end != VMALLOC_END)
37672 ++ return NULL;
37673 ++ start = (unsigned long)MODULES_VADDR;
37674 ++ end = (unsigned long)MODULES_END;
37675 ++ }
37676 ++#endif
37677 ++
37678 + if (flags & VM_IOREMAP) {
37679 + int bit = fls(size);
37680 +
37681 +@@ -248,20 +275,15 @@ __get_vm_area_node(unsigned long size, u
37682 + (unsigned long)tmp->addr, align);
37683 + continue;
37684 + }
37685 +- if ((size + addr) < addr)
37686 +- goto out;
37687 + if (size + addr <= (unsigned long)tmp->addr)
37688 +- goto found;
37689 ++ break;
37690 + addr = ALIGN(tmp->size + (unsigned long)tmp->addr, align);
37691 +- if (addr > end - size)
37692 +- goto out;
37693 + }
37694 + if ((size + addr) < addr)
37695 + goto out;
37696 + if (addr > end - size)
37697 + goto out;
37698 +
37699 +-found:
37700 + area->next = *p;
37701 + *p = area;
37702 +
37703 +@@ -466,6 +488,11 @@ void *vmap(struct page **pages, unsigned
37704 + if (count > num_physpages)
37705 + return NULL;
37706 +
37707 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37708 ++ if (!(pgprot_val(prot) & _PAGE_NX))
37709 ++ flags |= VM_KERNEXEC;
37710 ++#endif
37711 ++
37712 + area = get_vm_area_caller((count << PAGE_SHIFT), flags,
37713 + __builtin_return_address(0));
37714 + if (!area)
37715 +@@ -560,6 +587,13 @@ static void *__vmalloc_node(unsigned lon
37716 + if (!size || (size >> PAGE_SHIFT) > num_physpages)
37717 + return NULL;
37718 +
37719 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37720 ++ if (!(pgprot_val(prot) & _PAGE_NX))
37721 ++ area = __get_vm_area_node(size, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
37722 ++ node, gfp_mask, caller);
37723 ++ else
37724 ++#endif
37725 ++
37726 + area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
37727 + node, gfp_mask, caller);
37728 +
37729 +@@ -651,7 +685,7 @@ EXPORT_SYMBOL(vmalloc_node);
37730 +
37731 + void *vmalloc_exec(unsigned long size)
37732 + {
37733 +- return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC);
37734 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC);
37735 + }
37736 +
37737 + #if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
37738 +diff -urNp linux-2.6.27.10/net/bridge/br_stp_if.c linux-2.6.27.10/net/bridge/br_stp_if.c
37739 +--- linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-07 12:55:34.000000000 -0500
37740 ++++ linux-2.6.27.10/net/bridge/br_stp_if.c 2008-11-18 03:38:45.000000000 -0500
37741 +@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
37742 + char *envp[] = { NULL };
37743 +
37744 + if (br->stp_enabled == BR_USER_STP) {
37745 +- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
37746 ++ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
37747 + printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
37748 + br->dev->name, r);
37749 +
37750 +diff -urNp linux-2.6.27.10/net/core/flow.c linux-2.6.27.10/net/core/flow.c
37751 +--- linux-2.6.27.10/net/core/flow.c 2008-11-07 12:55:34.000000000 -0500
37752 ++++ linux-2.6.27.10/net/core/flow.c 2008-11-18 03:38:45.000000000 -0500
37753 +@@ -39,7 +39,7 @@ atomic_t flow_cache_genid = ATOMIC_INIT(
37754 +
37755 + static u32 flow_hash_shift;
37756 + #define flow_hash_size (1 << flow_hash_shift)
37757 +-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
37758 ++static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
37759 +
37760 + #define flow_table(cpu) (per_cpu(flow_tables, cpu))
37761 +
37762 +@@ -52,7 +52,7 @@ struct flow_percpu_info {
37763 + u32 hash_rnd;
37764 + int count;
37765 + };
37766 +-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
37767 ++static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
37768 +
37769 + #define flow_hash_rnd_recalc(cpu) \
37770 + (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
37771 +@@ -69,7 +69,7 @@ struct flow_flush_info {
37772 + atomic_t cpuleft;
37773 + struct completion completion;
37774 + };
37775 +-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
37776 ++static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
37777 +
37778 + #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
37779 +
37780 +diff -urNp linux-2.6.27.10/net/dccp/ccids/ccid3.c linux-2.6.27.10/net/dccp/ccids/ccid3.c
37781 +--- linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-07 12:55:34.000000000 -0500
37782 ++++ linux-2.6.27.10/net/dccp/ccids/ccid3.c 2008-11-18 03:38:45.000000000 -0500
37783 +@@ -43,7 +43,7 @@
37784 + static int ccid3_debug;
37785 + #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
37786 + #else
37787 +-#define ccid3_pr_debug(format, a...)
37788 ++#define ccid3_pr_debug(format, a...) do {} while (0)
37789 + #endif
37790 +
37791 + /*
37792 +diff -urNp linux-2.6.27.10/net/dccp/dccp.h linux-2.6.27.10/net/dccp/dccp.h
37793 +--- linux-2.6.27.10/net/dccp/dccp.h 2008-11-07 12:55:34.000000000 -0500
37794 ++++ linux-2.6.27.10/net/dccp/dccp.h 2008-11-18 03:38:45.000000000 -0500
37795 +@@ -43,8 +43,8 @@ extern int dccp_debug;
37796 + #define dccp_pr_debug(format, a...) DCCP_PR_DEBUG(dccp_debug, format, ##a)
37797 + #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
37798 + #else
37799 +-#define dccp_pr_debug(format, a...)
37800 +-#define dccp_pr_debug_cat(format, a...)
37801 ++#define dccp_pr_debug(format, a...) do {} while (0)
37802 ++#define dccp_pr_debug_cat(format, a...) do {} while (0)
37803 + #endif
37804 +
37805 + extern struct inet_hashinfo dccp_hashinfo;
37806 +diff -urNp linux-2.6.27.10/net/ipv4/inet_connection_sock.c linux-2.6.27.10/net/ipv4/inet_connection_sock.c
37807 +--- linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-07 12:55:34.000000000 -0500
37808 ++++ linux-2.6.27.10/net/ipv4/inet_connection_sock.c 2008-11-18 03:38:45.000000000 -0500
37809 +@@ -15,6 +15,7 @@
37810 +
37811 + #include <linux/module.h>
37812 + #include <linux/jhash.h>
37813 ++#include <linux/grsecurity.h>
37814 +
37815 + #include <net/inet_connection_sock.h>
37816 + #include <net/inet_hashtables.h>
37817 +diff -urNp linux-2.6.27.10/net/ipv4/inet_hashtables.c linux-2.6.27.10/net/ipv4/inet_hashtables.c
37818 +--- linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-07 12:55:34.000000000 -0500
37819 ++++ linux-2.6.27.10/net/ipv4/inet_hashtables.c 2008-11-18 03:38:45.000000000 -0500
37820 +@@ -18,11 +18,14 @@
37821 + #include <linux/sched.h>
37822 + #include <linux/slab.h>
37823 + #include <linux/wait.h>
37824 ++#include <linux/grsecurity.h>
37825 +
37826 + #include <net/inet_connection_sock.h>
37827 + #include <net/inet_hashtables.h>
37828 + #include <net/ip.h>
37829 +
37830 ++extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
37831 ++
37832 + /*
37833 + * Allocate and initialize a new local port bind bucket.
37834 + * The bindhash mutex for snum's hash chain must be held here.
37835 +@@ -487,6 +490,8 @@ ok:
37836 + }
37837 + spin_unlock(&head->lock);
37838 +
37839 ++ gr_update_task_in_ip_table(current, inet_sk(sk));
37840 ++
37841 + if (tw) {
37842 + inet_twsk_deschedule(tw, death_row);
37843 + inet_twsk_put(tw);
37844 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c
37845 +--- linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 1969-12-31 19:00:00.000000000 -0500
37846 ++++ linux-2.6.27.10/net/ipv4/netfilter/ipt_stealth.c 2008-11-18 03:38:45.000000000 -0500
37847 +@@ -0,0 +1,114 @@
37848 ++/* Kernel module to add stealth support.
37849 ++ *
37850 ++ * Copyright (C) 2002-2006 Brad Spengler <spender@××××××××××.net>
37851 ++ *
37852 ++ */
37853 ++
37854 ++#include <linux/kernel.h>
37855 ++#include <linux/module.h>
37856 ++#include <linux/skbuff.h>
37857 ++#include <linux/net.h>
37858 ++#include <linux/sched.h>
37859 ++#include <linux/inet.h>
37860 ++#include <linux/stddef.h>
37861 ++
37862 ++#include <net/ip.h>
37863 ++#include <net/sock.h>
37864 ++#include <net/tcp.h>
37865 ++#include <net/udp.h>
37866 ++#include <net/route.h>
37867 ++#include <net/inet_common.h>
37868 ++
37869 ++#include <linux/netfilter_ipv4/ip_tables.h>
37870 ++
37871 ++MODULE_LICENSE("GPL");
37872 ++
37873 ++extern struct sock *udp_v4_lookup(struct net *net, u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
37874 ++
37875 ++static bool
37876 ++match(const struct sk_buff *skb,
37877 ++ const struct net_device *in,
37878 ++ const struct net_device *out,
37879 ++ const struct xt_match *match,
37880 ++ const void *matchinfo,
37881 ++ int offset,
37882 ++ unsigned int protoff,
37883 ++ bool *hotdrop)
37884 ++{
37885 ++ struct iphdr *ip = ip_hdr(skb);
37886 ++ struct tcphdr th;
37887 ++ struct udphdr uh;
37888 ++ struct sock *sk = NULL;
37889 ++
37890 ++ if (!ip || offset) return false;
37891 ++
37892 ++ switch(ip->protocol) {
37893 ++ case IPPROTO_TCP:
37894 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &th, sizeof(th)) < 0) {
37895 ++ *hotdrop = true;
37896 ++ return false;
37897 ++ }
37898 ++ if (!(th.syn && !th.ack)) return false;
37899 ++ sk = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, ip->daddr, th.dest, inet_iif(skb));
37900 ++ break;
37901 ++ case IPPROTO_UDP:
37902 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &uh, sizeof(uh)) < 0) {
37903 ++ *hotdrop = true;
37904 ++ return false;
37905 ++ }
37906 ++ sk = udp_v4_lookup(dev_net(skb->dev), ip->saddr, uh.source, ip->daddr, uh.dest, skb->dev->ifindex);
37907 ++ break;
37908 ++ default:
37909 ++ return false;
37910 ++ }
37911 ++
37912 ++ if(!sk) // port is being listened on, match this
37913 ++ return true;
37914 ++ else {
37915 ++ sock_put(sk);
37916 ++ return false;
37917 ++ }
37918 ++}
37919 ++
37920 ++/* Called when user tries to insert an entry of this type. */
37921 ++static bool
37922 ++checkentry(const char *tablename,
37923 ++ const void *nip,
37924 ++ const struct xt_match *match,
37925 ++ void *matchinfo,
37926 ++ unsigned int hook_mask)
37927 ++{
37928 ++ const struct ipt_ip *ip = (const struct ipt_ip *)nip;
37929 ++
37930 ++ if(((ip->proto == IPPROTO_TCP && !(ip->invflags & IPT_INV_PROTO)) ||
37931 ++ ((ip->proto == IPPROTO_UDP) && !(ip->invflags & IPT_INV_PROTO)))
37932 ++ && (hook_mask & (1 << NF_INET_LOCAL_IN)))
37933 ++ return true;
37934 ++
37935 ++ printk("stealth: Only works on TCP and UDP for the INPUT chain.\n");
37936 ++
37937 ++ return false;
37938 ++}
37939 ++
37940 ++
37941 ++static struct xt_match stealth_match __read_mostly = {
37942 ++ .name = "stealth",
37943 ++ .family = AF_INET,
37944 ++ .match = match,
37945 ++ .checkentry = checkentry,
37946 ++ .destroy = NULL,
37947 ++ .me = THIS_MODULE
37948 ++};
37949 ++
37950 ++static int __init init(void)
37951 ++{
37952 ++ return xt_register_match(&stealth_match);
37953 ++}
37954 ++
37955 ++static void __exit fini(void)
37956 ++{
37957 ++ xt_unregister_match(&stealth_match);
37958 ++}
37959 ++
37960 ++module_init(init);
37961 ++module_exit(fini);
37962 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Kconfig linux-2.6.27.10/net/ipv4/netfilter/Kconfig
37963 +--- linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-07 12:55:34.000000000 -0500
37964 ++++ linux-2.6.27.10/net/ipv4/netfilter/Kconfig 2008-11-18 03:38:45.000000000 -0500
37965 +@@ -111,6 +111,21 @@ config IP_NF_MATCH_ADDRTYPE
37966 + If you want to compile it as a module, say M here and read
37967 + <file:Documentation/kbuild/modules.txt>. If unsure, say `N'.
37968 +
37969 ++config IP_NF_MATCH_STEALTH
37970 ++ tristate "stealth match support"
37971 ++ depends on IP_NF_IPTABLES
37972 ++ help
37973 ++ Enabling this option will drop all syn packets coming to unserved tcp
37974 ++ ports as well as all packets coming to unserved udp ports. If you
37975 ++ are using your system to route any type of packets (ie. via NAT)
37976 ++ you should put this module at the end of your ruleset, since it will
37977 ++ drop packets that aren't going to ports that are listening on your
37978 ++ machine itself, it doesn't take into account that the packet might be
37979 ++ destined for someone on your internal network if you're using NAT for
37980 ++ instance.
37981 ++
37982 ++ To compile it as a module, choose M here. If unsure, say N.
37983 ++
37984 + # `filter', generic and specific targets
37985 + config IP_NF_FILTER
37986 + tristate "Packet filtering"
37987 +@@ -407,4 +422,3 @@ config IP_NF_ARP_MANGLE
37988 + hardware and network addresses.
37989 +
37990 + endmenu
37991 +-
37992 +diff -urNp linux-2.6.27.10/net/ipv4/netfilter/Makefile linux-2.6.27.10/net/ipv4/netfilter/Makefile
37993 +--- linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-07 12:55:34.000000000 -0500
37994 ++++ linux-2.6.27.10/net/ipv4/netfilter/Makefile 2008-11-18 03:38:45.000000000 -0500
37995 +@@ -59,6 +59,7 @@ obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) +=
37996 + obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
37997 + obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
37998 + obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
37999 ++obj-$(CONFIG_IP_NF_MATCH_STEALTH) += ipt_stealth.o
38000 + obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
38001 + obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
38002 +
38003 +diff -urNp linux-2.6.27.10/net/ipv4/tcp_ipv4.c linux-2.6.27.10/net/ipv4/tcp_ipv4.c
38004 +--- linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-07 12:55:34.000000000 -0500
38005 ++++ linux-2.6.27.10/net/ipv4/tcp_ipv4.c 2008-11-18 03:38:45.000000000 -0500
38006 +@@ -59,6 +59,7 @@
38007 + #include <linux/jhash.h>
38008 + #include <linux/init.h>
38009 + #include <linux/times.h>
38010 ++#include <linux/grsecurity.h>
38011 +
38012 + #include <net/net_namespace.h>
38013 + #include <net/icmp.h>
38014 +diff -urNp linux-2.6.27.10/net/ipv4/udp.c linux-2.6.27.10/net/ipv4/udp.c
38015 +--- linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:16:52.000000000 -0500
38016 ++++ linux-2.6.27.10/net/ipv4/udp.c 2008-12-21 01:13:47.000000000 -0500
38017 +@@ -97,6 +97,7 @@
38018 + #include <linux/skbuff.h>
38019 + #include <linux/proc_fs.h>
38020 + #include <linux/seq_file.h>
38021 ++#include <linux/grsecurity.h>
38022 + #include <net/net_namespace.h>
38023 + #include <net/icmp.h>
38024 + #include <net/route.h>
38025 +@@ -104,6 +105,11 @@
38026 + #include <net/xfrm.h>
38027 + #include "udp_impl.h"
38028 +
38029 ++extern int gr_search_udp_recvmsg(const struct sock *sk,
38030 ++ const struct sk_buff *skb);
38031 ++extern int gr_search_udp_sendmsg(const struct sock *sk,
38032 ++ const struct sockaddr_in *addr);
38033 ++
38034 + /*
38035 + * Snmp MIB for the UDP layer
38036 + */
38037 +@@ -302,6 +308,13 @@ static struct sock *__udp4_lib_lookup(st
38038 + return result;
38039 + }
38040 +
38041 ++struct sock *udp_v4_lookup(struct net *net, __be32 saddr, __be16 sport,
38042 ++ __be32 daddr, __be16 dport, int dif)
38043 ++{
38044 ++ return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, udp_hash);
38045 ++}
38046 ++
38047 ++
38048 + static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
38049 + __be16 loc_port, __be32 loc_addr,
38050 + __be16 rmt_port, __be32 rmt_addr,
38051 +@@ -592,9 +605,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
38052 + dport = usin->sin_port;
38053 + if (dport == 0)
38054 + return -EINVAL;
38055 ++
38056 ++ if (!gr_search_udp_sendmsg(sk, usin))
38057 ++ return -EPERM;
38058 + } else {
38059 + if (sk->sk_state != TCP_ESTABLISHED)
38060 + return -EDESTADDRREQ;
38061 ++
38062 ++ if (!gr_search_udp_sendmsg(sk, NULL))
38063 ++ return -EPERM;
38064 ++
38065 + daddr = inet->daddr;
38066 + dport = inet->dport;
38067 + /* Open fast path for connected socket.
38068 +@@ -859,6 +879,11 @@ try_again:
38069 + if (!skb)
38070 + goto out;
38071 +
38072 ++ if (!gr_search_udp_recvmsg(sk, skb)) {
38073 ++ err = -EPERM;
38074 ++ goto out_free;
38075 ++ }
38076 ++
38077 + ulen = skb->len - sizeof(struct udphdr);
38078 + copied = len;
38079 + if (copied > ulen)
38080 +diff -urNp linux-2.6.27.10/net/ipv6/exthdrs.c linux-2.6.27.10/net/ipv6/exthdrs.c
38081 +--- linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-07 12:55:34.000000000 -0500
38082 ++++ linux-2.6.27.10/net/ipv6/exthdrs.c 2008-11-18 03:38:45.000000000 -0500
38083 +@@ -624,7 +624,7 @@ static struct tlvtype_proc tlvprochopopt
38084 + .type = IPV6_TLV_JUMBO,
38085 + .func = ipv6_hop_jumbo,
38086 + },
38087 +- { -1, }
38088 ++ { -1, NULL }
38089 + };
38090 +
38091 + int ipv6_parse_hopopts(struct sk_buff *skb)
38092 +diff -urNp linux-2.6.27.10/net/ipv6/raw.c linux-2.6.27.10/net/ipv6/raw.c
38093 +--- linux-2.6.27.10/net/ipv6/raw.c 2008-11-07 12:55:34.000000000 -0500
38094 ++++ linux-2.6.27.10/net/ipv6/raw.c 2008-11-18 03:38:45.000000000 -0500
38095 +@@ -600,7 +600,7 @@ out:
38096 + return err;
38097 + }
38098 +
38099 +-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
38100 ++static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
38101 + struct flowi *fl, struct rt6_info *rt,
38102 + unsigned int flags)
38103 + {
38104 +diff -urNp linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c
38105 +--- linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-07 12:55:34.000000000 -0500
38106 ++++ linux-2.6.27.10/net/irda/ircomm/ircomm_tty.c 2008-11-18 03:38:45.000000000 -0500
38107 +@@ -371,7 +371,7 @@ static int ircomm_tty_open(struct tty_st
38108 + IRDA_DEBUG(2, "%s()\n", __func__ );
38109 +
38110 + line = tty->index;
38111 +- if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
38112 ++ if (line >= IRCOMM_TTY_PORTS) {
38113 + return -ENODEV;
38114 + }
38115 +
38116 +diff -urNp linux-2.6.27.10/net/sctp/socket.c linux-2.6.27.10/net/sctp/socket.c
38117 +--- linux-2.6.27.10/net/sctp/socket.c 2008-11-07 12:55:34.000000000 -0500
38118 ++++ linux-2.6.27.10/net/sctp/socket.c 2008-11-18 03:38:45.000000000 -0500
38119 +@@ -1434,7 +1434,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
38120 + struct sctp_sndrcvinfo *sinfo;
38121 + struct sctp_initmsg *sinit;
38122 + sctp_assoc_t associd = 0;
38123 +- sctp_cmsgs_t cmsgs = { NULL };
38124 ++ sctp_cmsgs_t cmsgs = { NULL, NULL };
38125 + int err;
38126 + sctp_scope_t scope;
38127 + long timeo;
38128 +@@ -5616,7 +5616,6 @@ pp_found:
38129 + */
38130 + int reuse = sk->sk_reuse;
38131 + struct sock *sk2;
38132 +- struct hlist_node *node;
38133 +
38134 + SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
38135 + if (pp->fastreuse && sk->sk_reuse &&
38136 +diff -urNp linux-2.6.27.10/net/socket.c linux-2.6.27.10/net/socket.c
38137 +--- linux-2.6.27.10/net/socket.c 2008-11-07 12:55:34.000000000 -0500
38138 ++++ linux-2.6.27.10/net/socket.c 2008-11-18 03:38:45.000000000 -0500
38139 +@@ -87,6 +87,7 @@
38140 + #include <linux/audit.h>
38141 + #include <linux/wireless.h>
38142 + #include <linux/nsproxy.h>
38143 ++#include <linux/in.h>
38144 +
38145 + #include <asm/uaccess.h>
38146 + #include <asm/unistd.h>
38147 +@@ -97,6 +98,21 @@
38148 + #include <net/sock.h>
38149 + #include <linux/netfilter.h>
38150 +
38151 ++extern void gr_attach_curr_ip(const struct sock *sk);
38152 ++extern int gr_handle_sock_all(const int family, const int type,
38153 ++ const int protocol);
38154 ++extern int gr_handle_sock_server(const struct sockaddr *sck);
38155 ++extern int gr_handle_sock_server_other(const struct socket *sck);
38156 ++extern int gr_handle_sock_client(const struct sockaddr *sck);
38157 ++extern int gr_search_connect(const struct socket * sock,
38158 ++ const struct sockaddr_in * addr);
38159 ++extern int gr_search_bind(const struct socket * sock,
38160 ++ const struct sockaddr_in * addr);
38161 ++extern int gr_search_listen(const struct socket * sock);
38162 ++extern int gr_search_accept(const struct socket * sock);
38163 ++extern int gr_search_socket(const int domain, const int type,
38164 ++ const int protocol);
38165 ++
38166 + static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
38167 + static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
38168 + unsigned long nr_segs, loff_t pos);
38169 +@@ -300,7 +316,7 @@ static int sockfs_get_sb(struct file_sys
38170 + mnt);
38171 + }
38172 +
38173 +-static struct vfsmount *sock_mnt __read_mostly;
38174 ++struct vfsmount *sock_mnt __read_mostly;
38175 +
38176 + static struct file_system_type sock_fs_type = {
38177 + .name = "sockfs",
38178 +@@ -1236,6 +1252,16 @@ asmlinkage long sys_socket(int family, i
38179 + if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
38180 + flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
38181 +
38182 ++ if(!gr_search_socket(family, type, protocol)) {
38183 ++ retval = -EACCES;
38184 ++ goto out;
38185 ++ }
38186 ++
38187 ++ if (gr_handle_sock_all(family, type, protocol)) {
38188 ++ retval = -EACCES;
38189 ++ goto out;
38190 ++ }
38191 ++
38192 + retval = sock_create(family, type, protocol, &sock);
38193 + if (retval < 0)
38194 + goto out;
38195 +@@ -1375,6 +1401,12 @@ asmlinkage long sys_bind(int fd, struct
38196 + if (sock) {
38197 + err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
38198 + if (err >= 0) {
38199 ++ if (!gr_search_bind(sock, (struct sockaddr_in *)&address) ||
38200 ++ gr_handle_sock_server((struct sockaddr *)&address)) {
38201 ++ err = -EACCES;
38202 ++ goto error;
38203 ++ }
38204 ++
38205 + err = security_socket_bind(sock,
38206 + (struct sockaddr *)&address,
38207 + addrlen);
38208 +@@ -1383,6 +1415,7 @@ asmlinkage long sys_bind(int fd, struct
38209 + (struct sockaddr *)
38210 + &address, addrlen);
38211 + }
38212 ++error:
38213 + fput_light(sock->file, fput_needed);
38214 + }
38215 + return err;
38216 +@@ -1406,10 +1439,17 @@ asmlinkage long sys_listen(int fd, int b
38217 + if ((unsigned)backlog > somaxconn)
38218 + backlog = somaxconn;
38219 +
38220 ++ if (gr_handle_sock_server_other(sock) ||
38221 ++ !gr_search_listen(sock)) {
38222 ++ err = -EPERM;
38223 ++ goto error;
38224 ++ }
38225 ++
38226 + err = security_socket_listen(sock, backlog);
38227 + if (!err)
38228 + err = sock->ops->listen(sock, backlog);
38229 +
38230 ++error:
38231 + fput_light(sock->file, fput_needed);
38232 + }
38233 + return err;
38234 +@@ -1452,6 +1492,13 @@ long do_accept(int fd, struct sockaddr _
38235 + newsock->type = sock->type;
38236 + newsock->ops = sock->ops;
38237 +
38238 ++ if (gr_handle_sock_server_other(sock) ||
38239 ++ !gr_search_accept(sock)) {
38240 ++ err = -EPERM;
38241 ++ sock_release(newsock);
38242 ++ goto out_put;
38243 ++ }
38244 ++
38245 + /*
38246 + * We don't need try_module_get here, as the listening socket (sock)
38247 + * has the protocol module (sock->ops->owner) held.
38248 +@@ -1495,6 +1542,7 @@ long do_accept(int fd, struct sockaddr _
38249 + err = newfd;
38250 +
38251 + security_socket_post_accept(sock, newsock);
38252 ++ gr_attach_curr_ip(newsock->sk);
38253 +
38254 + out_put:
38255 + fput_light(sock->file, fput_needed);
38256 +@@ -1589,6 +1637,7 @@ asmlinkage long sys_connect(int fd, stru
38257 + int addrlen)
38258 + {
38259 + struct socket *sock;
38260 ++ struct sockaddr *sck;
38261 + struct sockaddr_storage address;
38262 + int err, fput_needed;
38263 +
38264 +@@ -1599,6 +1648,13 @@ asmlinkage long sys_connect(int fd, stru
38265 + if (err < 0)
38266 + goto out_put;
38267 +
38268 ++ sck = (struct sockaddr *)&address;
38269 ++ if (!gr_search_connect(sock, (struct sockaddr_in *)sck) ||
38270 ++ gr_handle_sock_client(sck)) {
38271 ++ err = -EACCES;
38272 ++ goto out_put;
38273 ++ }
38274 ++
38275 + err =
38276 + security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
38277 + if (err)
38278 +@@ -1866,6 +1922,7 @@ asmlinkage long sys_shutdown(int fd, int
38279 + err = sock->ops->shutdown(sock, how);
38280 + fput_light(sock->file, fput_needed);
38281 + }
38282 ++
38283 + return err;
38284 + }
38285 +
38286 +diff -urNp linux-2.6.27.10/net/unix/af_unix.c linux-2.6.27.10/net/unix/af_unix.c
38287 +--- linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:16:52.000000000 -0500
38288 ++++ linux-2.6.27.10/net/unix/af_unix.c 2008-12-21 01:13:47.000000000 -0500
38289 +@@ -114,6 +114,7 @@
38290 + #include <linux/mount.h>
38291 + #include <net/checksum.h>
38292 + #include <linux/security.h>
38293 ++#include <linux/grsecurity.h>
38294 +
38295 + static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
38296 + static DEFINE_SPINLOCK(unix_table_lock);
38297 +@@ -725,6 +726,12 @@ static struct sock *unix_find_other(stru
38298 + err = -ECONNREFUSED;
38299 + if (!S_ISSOCK(nd.path.dentry->d_inode->i_mode))
38300 + goto put_fail;
38301 ++
38302 ++ if (!gr_acl_handle_unix(nd.path.dentry, nd.path.mnt)) {
38303 ++ err = -EACCES;
38304 ++ goto put_fail;
38305 ++ }
38306 ++
38307 + u = unix_find_socket_byinode(net, nd.path.dentry->d_inode);
38308 + if (!u)
38309 + goto put_fail;
38310 +@@ -745,6 +752,13 @@ static struct sock *unix_find_other(stru
38311 + if (u) {
38312 + struct dentry *dentry;
38313 + dentry = unix_sk(u)->dentry;
38314 ++
38315 ++ if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
38316 ++ err = -EPERM;
38317 ++ sock_put(u);
38318 ++ goto fail;
38319 ++ }
38320 ++
38321 + if (dentry)
38322 + touch_atime(unix_sk(u)->mnt, dentry);
38323 + } else
38324 +@@ -827,10 +841,20 @@ static int unix_bind(struct socket *sock
38325 + err = mnt_want_write(nd.path.mnt);
38326 + if (err)
38327 + goto out_mknod_dput;
38328 ++
38329 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
38330 ++ err = -EACCES;
38331 ++ mnt_drop_write(nd.path.mnt);
38332 ++ goto out_mknod_dput;
38333 ++ }
38334 ++
38335 + err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
38336 + mnt_drop_write(nd.path.mnt);
38337 + if (err)
38338 + goto out_mknod_dput;
38339 ++
38340 ++ gr_handle_create(dentry, nd.path.mnt);
38341 ++
38342 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
38343 + dput(nd.path.dentry);
38344 + nd.path.dentry = dentry;
38345 +@@ -848,6 +872,10 @@ static int unix_bind(struct socket *sock
38346 + goto out_unlock;
38347 + }
38348 +
38349 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
38350 ++ sk->sk_peercred.pid = current->pid;
38351 ++#endif
38352 ++
38353 + list = &unix_socket_table[addr->hash];
38354 + } else {
38355 + list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
38356 +diff -urNp linux-2.6.27.10/scripts/pnmtologo.c linux-2.6.27.10/scripts/pnmtologo.c
38357 +--- linux-2.6.27.10/scripts/pnmtologo.c 2008-11-07 12:55:34.000000000 -0500
38358 ++++ linux-2.6.27.10/scripts/pnmtologo.c 2008-11-18 03:38:45.000000000 -0500
38359 +@@ -237,14 +237,14 @@ static void write_header(void)
38360 + fprintf(out, " * Linux logo %s\n", logoname);
38361 + fputs(" */\n\n", out);
38362 + fputs("#include <linux/linux_logo.h>\n\n", out);
38363 +- fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
38364 ++ fprintf(out, "static unsigned char %s_data[] = {\n",
38365 + logoname);
38366 + }
38367 +
38368 + static void write_footer(void)
38369 + {
38370 + fputs("\n};\n\n", out);
38371 +- fprintf(out, "struct linux_logo %s __initdata = {\n", logoname);
38372 ++ fprintf(out, "struct linux_logo %s = {\n", logoname);
38373 + fprintf(out, " .type\t= %s,\n", logo_types[logo_type]);
38374 + fprintf(out, " .width\t= %d,\n", logo_width);
38375 + fprintf(out, " .height\t= %d,\n", logo_height);
38376 +@@ -374,7 +374,7 @@ static void write_logo_clut224(void)
38377 + fputs("\n};\n\n", out);
38378 +
38379 + /* write logo clut */
38380 +- fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
38381 ++ fprintf(out, "static unsigned char %s_clut[] = {\n",
38382 + logoname);
38383 + write_hex_cnt = 0;
38384 + for (i = 0; i < logo_clutsize; i++) {
38385 +diff -urNp linux-2.6.27.10/security/commoncap.c linux-2.6.27.10/security/commoncap.c
38386 +--- linux-2.6.27.10/security/commoncap.c 2008-11-07 12:55:34.000000000 -0500
38387 ++++ linux-2.6.27.10/security/commoncap.c 2008-11-18 03:38:45.000000000 -0500
38388 +@@ -26,10 +26,13 @@
38389 + #include <linux/sched.h>
38390 + #include <linux/prctl.h>
38391 + #include <linux/securebits.h>
38392 ++#include <linux/grsecurity.h>
38393 ++
38394 ++extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
38395 +
38396 + int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
38397 + {
38398 +- NETLINK_CB(skb).eff_cap = current->cap_effective;
38399 ++ NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
38400 + return 0;
38401 + }
38402 +
38403 +@@ -51,7 +54,15 @@ EXPORT_SYMBOL(cap_netlink_recv);
38404 + int cap_capable (struct task_struct *tsk, int cap)
38405 + {
38406 + /* Derived from include/linux/sched.h:capable. */
38407 +- if (cap_raised(tsk->cap_effective, cap))
38408 ++ if (cap_raised (tsk->cap_effective, cap))
38409 ++ return 0;
38410 ++ return -EPERM;
38411 ++}
38412 ++
38413 ++int cap_capable_nolog (struct task_struct *tsk, int cap)
38414 ++{
38415 ++ /* tsk = current for all callers */
38416 ++ if (cap_raised(tsk->cap_effective, cap) && gr_is_capable_nolog(cap))
38417 + return 0;
38418 + return -EPERM;
38419 + }
38420 +@@ -379,8 +390,11 @@ void cap_bprm_apply_creds (struct linux_
38421 + }
38422 + }
38423 +
38424 +- current->suid = current->euid = current->fsuid = bprm->e_uid;
38425 +- current->sgid = current->egid = current->fsgid = bprm->e_gid;
38426 ++ if (!gr_check_user_change(-1, bprm->e_uid, bprm->e_uid))
38427 ++ current->suid = current->euid = current->fsuid = bprm->e_uid;
38428 ++
38429 ++ if (!gr_check_group_change(-1, bprm->e_gid, bprm->e_gid))
38430 ++ current->sgid = current->egid = current->fsgid = bprm->e_gid;
38431 +
38432 + /* For init, we want to retain the capabilities set
38433 + * in the init_task struct. Thus we skip the usual
38434 +@@ -393,6 +407,8 @@ void cap_bprm_apply_creds (struct linux_
38435 + cap_clear(current->cap_effective);
38436 + }
38437 +
38438 ++ gr_handle_chroot_caps(current);
38439 ++
38440 + /* AUD: Audit candidate if current->cap_effective is set */
38441 +
38442 + current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
38443 +@@ -705,7 +721,7 @@ int cap_vm_enough_memory(struct mm_struc
38444 + {
38445 + int cap_sys_admin = 0;
38446 +
38447 +- if (cap_capable(current, CAP_SYS_ADMIN) == 0)
38448 ++ if (cap_capable_nolog(current, CAP_SYS_ADMIN) == 0)
38449 + cap_sys_admin = 1;
38450 + return __vm_enough_memory(mm, pages, cap_sys_admin);
38451 + }
38452 +diff -urNp linux-2.6.27.10/security/Kconfig linux-2.6.27.10/security/Kconfig
38453 +--- linux-2.6.27.10/security/Kconfig 2008-11-07 12:55:34.000000000 -0500
38454 ++++ linux-2.6.27.10/security/Kconfig 2008-11-18 03:38:45.000000000 -0500
38455 +@@ -4,6 +4,447 @@
38456 +
38457 + menu "Security options"
38458 +
38459 ++source grsecurity/Kconfig
38460 ++
38461 ++menu "PaX"
38462 ++
38463 ++config PAX
38464 ++ bool "Enable various PaX features"
38465 ++ depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
38466 ++ help
38467 ++ This allows you to enable various PaX features. PaX adds
38468 ++ intrusion prevention mechanisms to the kernel that reduce
38469 ++ the risks posed by exploitable memory corruption bugs.
38470 ++
38471 ++menu "PaX Control"
38472 ++ depends on PAX
38473 ++
38474 ++config PAX_SOFTMODE
38475 ++ bool 'Support soft mode'
38476 ++ help
38477 ++ Enabling this option will allow you to run PaX in soft mode, that
38478 ++ is, PaX features will not be enforced by default, only on executables
38479 ++ marked explicitly. You must also enable PT_PAX_FLAGS support as it
38480 ++ is the only way to mark executables for soft mode use.
38481 ++
38482 ++ Soft mode can be activated by using the "pax_softmode=1" kernel command
38483 ++ line option on boot. Furthermore you can control various PaX features
38484 ++ at runtime via the entries in /proc/sys/kernel/pax.
38485 ++
38486 ++config PAX_EI_PAX
38487 ++ bool 'Use legacy ELF header marking'
38488 ++ help
38489 ++ Enabling this option will allow you to control PaX features on
38490 ++ a per executable basis via the 'chpax' utility available at
38491 ++ http://pax.grsecurity.net/. The control flags will be read from
38492 ++ an otherwise reserved part of the ELF header. This marking has
38493 ++ numerous drawbacks (no support for soft-mode, toolchain does not
38494 ++ know about the non-standard use of the ELF header) therefore it
38495 ++ has been deprecated in favour of PT_PAX_FLAGS support.
38496 ++
38497 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
38498 ++ program header then you MUST enable this option otherwise they
38499 ++ will not get any protection.
38500 ++
38501 ++ Note that if you enable PT_PAX_FLAGS marking support as well,
38502 ++ the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
38503 ++
38504 ++config PAX_PT_PAX_FLAGS
38505 ++ bool 'Use ELF program header marking'
38506 ++ help
38507 ++ Enabling this option will allow you to control PaX features on
38508 ++ a per executable basis via the 'paxctl' utility available at
38509 ++ http://pax.grsecurity.net/. The control flags will be read from
38510 ++ a PaX specific ELF program header (PT_PAX_FLAGS). This marking
38511 ++ has the benefits of supporting both soft mode and being fully
38512 ++ integrated into the toolchain (the binutils patch is available
38513 ++ from http://pax.grsecurity.net).
38514 ++
38515 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
38516 ++ program header then you MUST enable the EI_PAX marking support
38517 ++ otherwise they will not get any protection.
38518 ++
38519 ++ Note that if you enable the legacy EI_PAX marking support as well,
38520 ++ the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
38521 ++
38522 ++choice
38523 ++ prompt 'MAC system integration'
38524 ++ default PAX_HAVE_ACL_FLAGS
38525 ++ help
38526 ++ Mandatory Access Control systems have the option of controlling
38527 ++ PaX flags on a per executable basis, choose the method supported
38528 ++ by your particular system.
38529 ++
38530 ++ - "none": if your MAC system does not interact with PaX,
38531 ++ - "direct": if your MAC system defines pax_set_initial_flags() itself,
38532 ++ - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
38533 ++
38534 ++ NOTE: this option is for developers/integrators only.
38535 ++
38536 ++ config PAX_NO_ACL_FLAGS
38537 ++ bool 'none'
38538 ++
38539 ++ config PAX_HAVE_ACL_FLAGS
38540 ++ bool 'direct'
38541 ++
38542 ++ config PAX_HOOK_ACL_FLAGS
38543 ++ bool 'hook'
38544 ++endchoice
38545 ++
38546 ++endmenu
38547 ++
38548 ++menu "Non-executable pages"
38549 ++ depends on PAX
38550 ++
38551 ++config PAX_NOEXEC
38552 ++ bool "Enforce non-executable pages"
38553 ++ depends on (PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS) && (ALPHA || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
38554 ++ help
38555 ++ By design some architectures do not allow for protecting memory
38556 ++ pages against execution or even if they do, Linux does not make
38557 ++ use of this feature. In practice this means that if a page is
38558 ++ readable (such as the stack or heap) it is also executable.
38559 ++
38560 ++ There is a well known exploit technique that makes use of this
38561 ++ fact and a common programming mistake where an attacker can
38562 ++ introduce code of his choice somewhere in the attacked program's
38563 ++ memory (typically the stack or the heap) and then execute it.
38564 ++
38565 ++ If the attacked program was running with different (typically
38566 ++ higher) privileges than that of the attacker, then he can elevate
38567 ++ his own privilege level (e.g. get a root shell, write to files for
38568 ++ which he does not have write access to, etc).
38569 ++
38570 ++ Enabling this option will let you choose from various features
38571 ++ that prevent the injection and execution of 'foreign' code in
38572 ++ a program.
38573 ++
38574 ++ This will also break programs that rely on the old behaviour and
38575 ++ expect that dynamically allocated memory via the malloc() family
38576 ++ of functions is executable (which it is not). Notable examples
38577 ++ are the XFree86 4.x server, the java runtime and wine.
38578 ++
38579 ++config PAX_PAGEEXEC
38580 ++ bool "Paging based non-executable pages"
38581 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && (!X86_32 || M586 || M586TSC || M586MMX || M686 || MPENTIUMII || MPENTIUMIII || MPENTIUMM || MCORE2 || MPENTIUM4 || MPSC || MK7 || MK8 || MWINCHIPC6 || MWINCHIP2 || MWINCHIP3D || MVIAC3_2 || MVIAC7)
38582 ++ help
38583 ++ This implementation is based on the paging feature of the CPU.
38584 ++ On i386 without hardware non-executable bit support there is a
38585 ++ variable but usually low performance impact, however on Intel's
38586 ++ P4 core based CPUs it is very high so you should not enable this
38587 ++ for kernels meant to be used on such CPUs.
38588 ++
38589 ++ On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
38590 ++ with hardware non-executable bit support there is no performance
38591 ++ impact, on ppc the impact is negligible.
38592 ++
38593 ++ Note that several architectures require various emulations due to
38594 ++ badly designed userland ABIs, this will cause a performance impact
38595 ++ but will disappear as soon as userland is fixed (e.g., ppc users
38596 ++ can make use of the secure-plt feature found in binutils).
38597 ++
38598 ++config PAX_SEGMEXEC
38599 ++ bool "Segmentation based non-executable pages"
38600 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && X86_32
38601 ++ help
38602 ++ This implementation is based on the segmentation feature of the
38603 ++ CPU and has a very small performance impact, however applications
38604 ++ will be limited to a 1.5 GB address space instead of the normal
38605 ++ 3 GB.
38606 ++
38607 ++config PAX_EMUTRAMP
38608 ++ bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || PPC32 || X86)
38609 ++ default y if PARISC || PPC32
38610 ++ help
38611 ++ There are some programs and libraries that for one reason or
38612 ++ another attempt to execute special small code snippets from
38613 ++ non-executable memory pages. Most notable examples are the
38614 ++ signal handler return code generated by the kernel itself and
38615 ++ the GCC trampolines.
38616 ++
38617 ++ If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
38618 ++ such programs will no longer work under your kernel.
38619 ++
38620 ++ As a remedy you can say Y here and use the 'chpax' or 'paxctl'
38621 ++ utilities to enable trampoline emulation for the affected programs
38622 ++ yet still have the protection provided by the non-executable pages.
38623 ++
38624 ++ On parisc and ppc you MUST enable this option and EMUSIGRT as
38625 ++ well, otherwise your system will not even boot.
38626 ++
38627 ++ Alternatively you can say N here and use the 'chpax' or 'paxctl'
38628 ++ utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
38629 ++ for the affected files.
38630 ++
38631 ++ NOTE: enabling this feature *may* open up a loophole in the
38632 ++ protection provided by non-executable pages that an attacker
38633 ++ could abuse. Therefore the best solution is to not have any
38634 ++ files on your system that would require this option. This can
38635 ++ be achieved by not using libc5 (which relies on the kernel
38636 ++ signal handler return code) and not using or rewriting programs
38637 ++ that make use of the nested function implementation of GCC.
38638 ++ Skilled users can just fix GCC itself so that it implements
38639 ++ nested function calls in a way that does not interfere with PaX.
38640 ++
38641 ++config PAX_EMUSIGRT
38642 ++ bool "Automatically emulate sigreturn trampolines"
38643 ++ depends on PAX_EMUTRAMP && (PARISC || PPC32)
38644 ++ default y
38645 ++ help
38646 ++ Enabling this option will have the kernel automatically detect
38647 ++ and emulate signal return trampolines executing on the stack
38648 ++ that would otherwise lead to task termination.
38649 ++
38650 ++ This solution is intended as a temporary one for users with
38651 ++ legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
38652 ++ Modula-3 runtime, etc) or executables linked to such, basically
38653 ++ everything that does not specify its own SA_RESTORER function in
38654 ++ normal executable memory like glibc 2.1+ does.
38655 ++
38656 ++ On parisc and ppc you MUST enable this option, otherwise your
38657 ++ system will not even boot.
38658 ++
38659 ++ NOTE: this feature cannot be disabled on a per executable basis
38660 ++ and since it *does* open up a loophole in the protection provided
38661 ++ by non-executable pages, the best solution is to not have any
38662 ++ files on your system that would require this option.
38663 ++
38664 ++config PAX_MPROTECT
38665 ++ bool "Restrict mprotect()"
38666 ++ depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && !PPC64
38667 ++ help
38668 ++ Enabling this option will prevent programs from
38669 ++ - changing the executable status of memory pages that were
38670 ++ not originally created as executable,
38671 ++ - making read-only executable pages writable again,
38672 ++ - creating executable pages from anonymous memory.
38673 ++
38674 ++ You should say Y here to complete the protection provided by
38675 ++ the enforcement of non-executable pages.
38676 ++
38677 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
38678 ++ this feature on a per file basis.
38679 ++
38680 ++config PAX_NOELFRELOCS
38681 ++ bool "Disallow ELF text relocations"
38682 ++ depends on PAX_MPROTECT && !PAX_ETEXECRELOCS && (IA64 || X86)
38683 ++ help
38684 ++ Non-executable pages and mprotect() restrictions are effective
38685 ++ in preventing the introduction of new executable code into an
38686 ++ attacked task's address space. There remain only two venues
38687 ++ for this kind of attack: if the attacker can execute already
38688 ++ existing code in the attacked task then he can either have it
38689 ++ create and mmap() a file containing his code or have it mmap()
38690 ++ an already existing ELF library that does not have position
38691 ++ independent code in it and use mprotect() on it to make it
38692 ++ writable and copy his code there. While protecting against
38693 ++ the former approach is beyond PaX, the latter can be prevented
38694 ++ by having only PIC ELF libraries on one's system (which do not
38695 ++ need to relocate their code). If you are sure this is your case,
38696 ++ then enable this option otherwise be careful as you may not even
38697 ++ be able to boot or log on your system (for example, some PAM
38698 ++ modules are erroneously compiled as non-PIC by default).
38699 ++
38700 ++ NOTE: if you are using dynamic ELF executables (as suggested
38701 ++ when using ASLR) then you must have made sure that you linked
38702 ++ your files using the PIC version of crt1 (the et_dyn.tar.gz package
38703 ++ referenced there has already been updated to support this).
38704 ++
38705 ++config PAX_ETEXECRELOCS
38706 ++ bool "Allow ELF ET_EXEC text relocations"
38707 ++ depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
38708 ++ default y
38709 ++ help
38710 ++ On some architectures there are incorrectly created applications
38711 ++ that require text relocations and would not work without enabling
38712 ++ this option. If you are an alpha, ia64 or parisc user, you should
38713 ++ enable this option and disable it once you have made sure that
38714 ++ none of your applications need it.
38715 ++
38716 ++config PAX_EMUPLT
38717 ++ bool "Automatically emulate ELF PLT"
38718 ++ depends on PAX_MPROTECT && (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
38719 ++ default y
38720 ++ help
38721 ++ Enabling this option will have the kernel automatically detect
38722 ++ and emulate the Procedure Linkage Table entries in ELF files.
38723 ++ On some architectures such entries are in writable memory, and
38724 ++ become non-executable leading to task termination. Therefore
38725 ++ it is mandatory that you enable this option on alpha, parisc,
38726 ++ ppc (if secure-plt is not used throughout in userland), sparc
38727 ++ and sparc64, otherwise your system would not even boot.
38728 ++
38729 ++ NOTE: this feature *does* open up a loophole in the protection
38730 ++ provided by the non-executable pages, therefore the proper
38731 ++ solution is to modify the toolchain to produce a PLT that does
38732 ++ not need to be writable.
38733 ++
38734 ++config PAX_DLRESOLVE
38735 ++ bool
38736 ++ depends on PAX_EMUPLT && (SPARC32 || SPARC64)
38737 ++ default y
38738 ++
38739 ++config PAX_SYSCALL
38740 ++ bool
38741 ++ depends on PAX_PAGEEXEC && PPC32
38742 ++ default y
38743 ++
38744 ++config PAX_KERNEXEC
38745 ++ bool "Enforce non-executable kernel pages"
38746 ++ depends on PAX_NOEXEC && X86 && !EFI && !COMPAT_VDSO && (!X86_32 || X86_WP_WORKS_OK) && !PARAVIRT
38747 ++ help
38748 ++ This is the kernel land equivalent of PAGEEXEC and MPROTECT,
38749 ++ that is, enabling this option will make it harder to inject
38750 ++ and execute 'foreign' code in kernel memory itself.
38751 ++
38752 ++endmenu
38753 ++
38754 ++menu "Address Space Layout Randomization"
38755 ++ depends on PAX
38756 ++
38757 ++config PAX_ASLR
38758 ++ bool "Address Space Layout Randomization"
38759 ++ depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
38760 ++ help
38761 ++ Many if not most exploit techniques rely on the knowledge of
38762 ++ certain addresses in the attacked program. The following options
38763 ++ will allow the kernel to apply a certain amount of randomization
38764 ++ to specific parts of the program thereby forcing an attacker to
38765 ++ guess them in most cases. Any failed guess will most likely crash
38766 ++ the attacked program which allows the kernel to detect such attempts
38767 ++ and react on them. PaX itself provides no reaction mechanisms,
38768 ++ instead it is strongly encouraged that you make use of Nergal's
38769 ++ segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
38770 ++ (http://www.grsecurity.net/) built-in crash detection features or
38771 ++ develop one yourself.
38772 ++
38773 ++ By saying Y here you can choose to randomize the following areas:
38774 ++ - top of the task's kernel stack
38775 ++ - top of the task's userland stack
38776 ++ - base address for mmap() requests that do not specify one
38777 ++ (this includes all libraries)
38778 ++ - base address of the main executable
38779 ++
38780 ++ It is strongly recommended to say Y here as address space layout
38781 ++ randomization has negligible impact on performance yet it provides
38782 ++ a very effective protection.
38783 ++
38784 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
38785 ++ this feature on a per file basis.
38786 ++
38787 ++config PAX_RANDKSTACK
38788 ++ bool "Randomize kernel stack base"
38789 ++ depends on PAX_ASLR && X86_TSC && X86_32
38790 ++ help
38791 ++ By saying Y here the kernel will randomize every task's kernel
38792 ++ stack on every system call. This will not only force an attacker
38793 ++ to guess it but also prevent him from making use of possible
38794 ++ leaked information about it.
38795 ++
38796 ++ Since the kernel stack is a rather scarce resource, randomization
38797 ++ may cause unexpected stack overflows, therefore you should very
38798 ++ carefully test your system. Note that once enabled in the kernel
38799 ++ configuration, this feature cannot be disabled on a per file basis.
38800 ++
38801 ++config PAX_RANDUSTACK
38802 ++ bool "Randomize user stack base"
38803 ++ depends on PAX_ASLR
38804 ++ help
38805 ++ By saying Y here the kernel will randomize every task's userland
38806 ++ stack. The randomization is done in two steps where the second
38807 ++ one may apply a big amount of shift to the top of the stack and
38808 ++ cause problems for programs that want to use lots of memory (more
38809 ++ than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
38810 ++ For this reason the second step can be controlled by 'chpax' or
38811 ++ 'paxctl' on a per file basis.
38812 ++
38813 ++config PAX_RANDMMAP
38814 ++ bool "Randomize mmap() base"
38815 ++ depends on PAX_ASLR
38816 ++ help
38817 ++ By saying Y here the kernel will use a randomized base address for
38818 ++ mmap() requests that do not specify one themselves. As a result
38819 ++ all dynamically loaded libraries will appear at random addresses
38820 ++ and therefore be harder to exploit by a technique where an attacker
38821 ++ attempts to execute library code for his purposes (e.g. spawn a
38822 ++ shell from an exploited program that is running at an elevated
38823 ++ privilege level).
38824 ++
38825 ++ Furthermore, if a program is relinked as a dynamic ELF file, its
38826 ++ base address will be randomized as well, completing the full
38827 ++ randomization of the address space layout. Attacking such programs
38828 ++ becomes a guess game. You can find an example of doing this at
38829 ++ http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
38830 ++ http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
38831 ++
38832 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
38833 ++ feature on a per file basis.
38834 ++
38835 ++endmenu
38836 ++
38837 ++menu "Miscellaneous hardening features"
38838 ++
38839 ++config PAX_MEMORY_SANITIZE
38840 ++ bool "Sanitize all freed memory"
38841 ++ help
38842 ++ By saying Y here the kernel will erase memory pages as soon as they
38843 ++ are freed. This in turn reduces the lifetime of data stored in the
38844 ++ pages, making it less likely that sensitive information such as
38845 ++ passwords, cryptographic secrets, etc stay in memory for too long.
38846 ++
38847 ++ This is especially useful for programs whose runtime is short, long
38848 ++ lived processes and the kernel itself benefit from this as long as
38849 ++ they operate on whole memory pages and ensure timely freeing of pages
38850 ++ that may hold sensitive information.
38851 ++
38852 ++ The tradeoff is performance impact, on a single CPU system kernel
38853 ++ compilation sees a 3% slowdown, other systems and workloads may vary
38854 ++ and you are advised to test this feature on your expected workload
38855 ++ before deploying it.
38856 ++
38857 ++ Note that this feature does not protect data stored in live pages,
38858 ++ e.g., process memory swapped to disk may stay there for a long time.
38859 ++
38860 ++config PAX_MEMORY_UDEREF
38861 ++ bool "Prevent invalid userland pointer dereference"
38862 ++ depends on X86_32 && !COMPAT_VDSO && !UML_X86
38863 ++ help
38864 ++ By saying Y here the kernel will be prevented from dereferencing
38865 ++ userland pointers in contexts where the kernel expects only kernel
38866 ++ pointers. This is both a useful runtime debugging feature and a
38867 ++ security measure that prevents exploiting a class of kernel bugs.
38868 ++
38869 ++ The tradeoff is that some virtualization solutions may experience
38870 ++ a huge slowdown and therefore you should not enable this feature
38871 ++ for kernels meant to run in such environments. Whether a given VM
38872 ++ solution is affected or not is best determined by simply trying it
38873 ++ out, the performance impact will be obvious right on boot as this
38874 ++ mechanism engages from very early on. A good rule of thumb is that
38875 ++ VMs running on CPUs without hardware virtualization support (i.e.,
38876 ++ the majority of IA-32 CPUs) will likely experience the slowdown.
38877 ++
38878 ++config PAX_REFCOUNT
38879 ++ bool "Prevent various kernel object reference counter overflows"
38880 ++ depends on X86
38881 ++ help
38882 ++ By saying Y here the kernel will detect and prevent overflowing
38883 ++ various (but not all) kinds of object reference counters. Such
38884 ++ overflows can normally occur due to bugs only and are often, if
38885 ++ not always, exploitable.
38886 ++
38887 ++ The tradeoff is that data structures protected by an oveflowed
38888 ++ refcount will never be freed and therefore will leak memory. Note
38889 ++ that this leak also happens even without this protection but in
38890 ++ that case the overflow can eventually trigger the freeing of the
38891 ++ data structure while it is still being used elsewhere, resulting
38892 ++ in the exploitable situation that this feature prevents.
38893 ++
38894 ++ Since this has a negligible performance impact, you should enable
38895 ++ this feature.
38896 ++endmenu
38897 ++
38898 ++endmenu
38899 ++
38900 + config KEYS
38901 + bool "Enable access key retention support"
38902 + help
38903 +diff -urNp linux-2.6.27.10/sound/core/oss/pcm_oss.c linux-2.6.27.10/sound/core/oss/pcm_oss.c
38904 +--- linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-07 12:55:34.000000000 -0500
38905 ++++ linux-2.6.27.10/sound/core/oss/pcm_oss.c 2008-11-18 03:38:45.000000000 -0500
38906 +@@ -2911,8 +2911,8 @@ static void snd_pcm_oss_proc_done(struct
38907 + }
38908 + }
38909 + #else /* !CONFIG_SND_VERBOSE_PROCFS */
38910 +-#define snd_pcm_oss_proc_init(pcm)
38911 +-#define snd_pcm_oss_proc_done(pcm)
38912 ++#define snd_pcm_oss_proc_init(pcm) do {} while (0)
38913 ++#define snd_pcm_oss_proc_done(pcm) do {} while (0)
38914 + #endif /* CONFIG_SND_VERBOSE_PROCFS */
38915 +
38916 + /*
38917 +diff -urNp linux-2.6.27.10/sound/core/seq/seq_lock.h linux-2.6.27.10/sound/core/seq/seq_lock.h
38918 +--- linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-07 12:55:34.000000000 -0500
38919 ++++ linux-2.6.27.10/sound/core/seq/seq_lock.h 2008-11-18 03:38:45.000000000 -0500
38920 +@@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
38921 + #else /* SMP || CONFIG_SND_DEBUG */
38922 +
38923 + typedef spinlock_t snd_use_lock_t; /* dummy */
38924 +-#define snd_use_lock_init(lockp) /**/
38925 +-#define snd_use_lock_use(lockp) /**/
38926 +-#define snd_use_lock_free(lockp) /**/
38927 +-#define snd_use_lock_sync(lockp) /**/
38928 ++#define snd_use_lock_init(lockp) do {} while (0)
38929 ++#define snd_use_lock_use(lockp) do {} while (0)
38930 ++#define snd_use_lock_free(lockp) do {} while (0)
38931 ++#define snd_use_lock_sync(lockp) do {} while (0)
38932 +
38933 + #endif /* SMP || CONFIG_SND_DEBUG */
38934 +
38935 +diff -urNp linux-2.6.27.10/sound/pci/ac97/ac97_patch.c linux-2.6.27.10/sound/pci/ac97/ac97_patch.c
38936 +--- linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-07 12:55:34.000000000 -0500
38937 ++++ linux-2.6.27.10/sound/pci/ac97/ac97_patch.c 2008-11-18 03:38:45.000000000 -0500
38938 +@@ -1498,7 +1498,7 @@ static const struct snd_ac97_res_table a
38939 + { AC97_VIDEO, 0x9f1f },
38940 + { AC97_AUX, 0x9f1f },
38941 + { AC97_PCM, 0x9f1f },
38942 +- { } /* terminator */
38943 ++ { 0, 0 } /* terminator */
38944 + };
38945 +
38946 + static int patch_ad1819(struct snd_ac97 * ac97)
38947 +@@ -3668,7 +3668,7 @@ static struct snd_ac97_res_table lm4550_
38948 + { AC97_AUX, 0x1f1f },
38949 + { AC97_PCM, 0x1f1f },
38950 + { AC97_REC_GAIN, 0x0f0f },
38951 +- { } /* terminator */
38952 ++ { 0, 0 } /* terminator */
38953 + };
38954 +
38955 + static int patch_lm4550(struct snd_ac97 *ac97)
38956 +diff -urNp linux-2.6.27.10/sound/pci/ens1370.c linux-2.6.27.10/sound/pci/ens1370.c
38957 +--- linux-2.6.27.10/sound/pci/ens1370.c 2008-11-07 12:55:34.000000000 -0500
38958 ++++ linux-2.6.27.10/sound/pci/ens1370.c 2008-11-18 03:38:45.000000000 -0500
38959 +@@ -452,7 +452,7 @@ static struct pci_device_id snd_audiopci
38960 + { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */
38961 + { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */
38962 + #endif
38963 +- { 0, }
38964 ++ { 0, 0, 0, 0, 0, 0, 0 }
38965 + };
38966 +
38967 + MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
38968 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0.c linux-2.6.27.10/sound/pci/intel8x0.c
38969 +--- linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-07 12:55:34.000000000 -0500
38970 ++++ linux-2.6.27.10/sound/pci/intel8x0.c 2008-11-18 03:38:45.000000000 -0500
38971 +@@ -437,7 +437,7 @@ static struct pci_device_id snd_intel8x0
38972 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
38973 + { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
38974 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
38975 +- { 0, }
38976 ++ { 0, 0, 0, 0, 0, 0, 0 }
38977 + };
38978 +
38979 + MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
38980 +@@ -2076,7 +2076,7 @@ static struct ac97_quirk ac97_quirks[] _
38981 + .type = AC97_TUNE_HP_ONLY
38982 + },
38983 + #endif
38984 +- { } /* terminator */
38985 ++ { 0, 0, 0, 0, NULL, 0 } /* terminator */
38986 + };
38987 +
38988 + static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
38989 +diff -urNp linux-2.6.27.10/sound/pci/intel8x0m.c linux-2.6.27.10/sound/pci/intel8x0m.c
38990 +--- linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-07 12:55:34.000000000 -0500
38991 ++++ linux-2.6.27.10/sound/pci/intel8x0m.c 2008-11-18 03:38:45.000000000 -0500
38992 +@@ -239,7 +239,7 @@ static struct pci_device_id snd_intel8x0
38993 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
38994 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
38995 + #endif
38996 +- { 0, }
38997 ++ { 0, 0, 0, 0, 0, 0, 0 }
38998 + };
38999 +
39000 + MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
39001 +@@ -1257,7 +1257,7 @@ static struct shortname_table {
39002 + { 0x5455, "ALi M5455" },
39003 + { 0x746d, "AMD AMD8111" },
39004 + #endif
39005 +- { 0 },
39006 ++ { 0, NULL },
39007 + };
39008 +
39009 + static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
39010 +diff -urNp linux-2.6.27.10/virt/kvm/kvm_main.c linux-2.6.27.10/virt/kvm/kvm_main.c
39011 +--- linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-07 12:55:34.000000000 -0500
39012 ++++ linux-2.6.27.10/virt/kvm/kvm_main.c 2008-11-18 03:38:45.000000000 -0500
39013 +@@ -1469,6 +1469,9 @@ static struct miscdevice kvm_dev = {
39014 + KVM_MINOR,
39015 + "kvm",
39016 + &kvm_chardev_ops,
39017 ++ {NULL, NULL},
39018 ++ NULL,
39019 ++ NULL
39020 + };
39021 +
39022 + static void hardware_enable(void *junk)
39023
39024 Added: hardened/2.6/tags/2.6.27-8/4421_grsec-remove-localversion-grsec.patch
39025 ===================================================================
39026 --- hardened/2.6/tags/2.6.27-8/4421_grsec-remove-localversion-grsec.patch (rev 0)
39027 +++ hardened/2.6/tags/2.6.27-8/4421_grsec-remove-localversion-grsec.patch 2009-01-25 09:01:31 UTC (rev 1485)
39028 @@ -0,0 +1,9 @@
39029 +From: Kerin Millar <kerframil@×××××.com>
39030 +
39031 +Remove grsecurity's localversion-grsec file as it is inconsistent with
39032 +Gentoo's kernel practices and naming scheme.
39033 +
39034 +--- a/localversion-grsec 2008-02-24 14:26:59.000000000 +0000
39035 ++++ b/localversion-grsec 1970-01-01 01:00:00.000000000 +0100
39036 +@@ -1 +0,0 @@
39037 +--grsec
39038
39039 Added: hardened/2.6/tags/2.6.27-8/4422_grsec-mute-warnings.patch
39040 ===================================================================
39041 --- hardened/2.6/tags/2.6.27-8/4422_grsec-mute-warnings.patch (rev 0)
39042 +++ hardened/2.6/tags/2.6.27-8/4422_grsec-mute-warnings.patch 2009-01-25 09:01:31 UTC (rev 1485)
39043 @@ -0,0 +1,28 @@
39044 +From: Gordon Malm <gengor@g.o>
39045 +
39046 +Updated patch for kernel series 2.6.24.
39047 +
39048 +The credits/description from the original version of this patch remain accurate
39049 +and are included below.
39050 +
39051 +---
39052 +From: Alexander Gabert <gaberta@××××××××.de>
39053 +
39054 +This patch removes the warnings introduced by grsec patch 2.1.9 and later.
39055 +It removes the -W options added by the patch and restores the original
39056 +warning flags of vanilla kernel versions.
39057 +
39058 +Acked-by: Christian Heim <phreak@g.o>
39059 +---
39060 +
39061 +--- a/Makefile
39062 ++++ b/Makefile
39063 +@@ -214,7 +214,7 @@
39064 +
39065 + HOSTCC = gcc
39066 + HOSTCXX = g++
39067 +-HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
39068 ++HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
39069 + HOSTCXXFLAGS = -O2
39070 +
39071 + # Decide whether to build built-in, modular, or both.
39072
39073 Added: hardened/2.6/tags/2.6.27-8/4425_grsec-pax-without-grsec.patch
39074 ===================================================================
39075 --- hardened/2.6/tags/2.6.27-8/4425_grsec-pax-without-grsec.patch (rev 0)
39076 +++ hardened/2.6/tags/2.6.27-8/4425_grsec-pax-without-grsec.patch 2009-01-25 09:01:31 UTC (rev 1485)
39077 @@ -0,0 +1,47 @@
39078 +From: Gordon Malm <gengor@g.o>
39079 +
39080 +Allow PaX options to be selected without first selecting CONFIG_GRKERNSEC.
39081 +
39082 +This patch has been updated to keep current with newer kernel versions.
39083 +The original version of this patch contained no credits/description.
39084 +
39085 +--- a/arch/x86/mm/fault.c
39086 ++++ b/arch/x86/mm/fault.c
39087 +@@ -433,10 +433,12 @@ static void show_fault_oops(struct pt_re
39088 + if (init_mm.start_code <= address && address < init_mm.end_code)
39089 + #endif
39090 + {
39091 ++#ifdef CONFIG_GRKERNSEC
39092 + if (current->signal->curr_ip)
39093 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
39094 + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
39095 + else
39096 ++#endif
39097 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
39098 + current->comm, task_pid_nr(current), current->uid, current->euid);
39099 + }
39100 +--- a/fs/exec.c
39101 ++++ b/fs/exec.c
39102 +@@ -1691,9 +1691,11 @@ void pax_report_fault(struct pt_regs *re
39103 + }
39104 + up_read(&mm->mmap_sem);
39105 + }
39106 ++#ifdef CONFIG_GRKERNSEC
39107 + if (tsk->signal->curr_ip)
39108 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: execution attempt in: %s, %08lx-%08lx %08lx\n", NIPQUAD(tsk->signal->curr_ip), path_fault, start, end, offset);
39109 + else
39110 ++#endif
39111 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
39112 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
39113 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
39114 +--- a/security/Kconfig
39115 ++++ b/security/Kconfig
39116 +@@ -10,7 +10,7 @@ menu "PaX"
39117 +
39118 + config PAX
39119 + bool "Enable various PaX features"
39120 +- depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
39121 ++ depends on (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
39122 + help
39123 + This allows you to enable various PaX features. PaX adds
39124 + intrusion prevention mechanisms to the kernel that reduce
39125
39126 Added: hardened/2.6/tags/2.6.27-8/4430_grsec-kconfig-default-gids.patch
39127 ===================================================================
39128 --- hardened/2.6/tags/2.6.27-8/4430_grsec-kconfig-default-gids.patch (rev 0)
39129 +++ hardened/2.6/tags/2.6.27-8/4430_grsec-kconfig-default-gids.patch 2009-01-25 09:01:31 UTC (rev 1485)
39130 @@ -0,0 +1,76 @@
39131 +From: Kerin Millar <kerframil@×××××.com>
39132 +
39133 +grsecurity contains a number of options which allow certain protections
39134 +to be applied to or exempted from members of a given group. However, the
39135 +default GIDs specified in the upstream patch are entirely arbitrary and
39136 +there is no telling which (if any) groups the GIDs will correlate with
39137 +on an end-user's system. Because some users don't pay a great deal of
39138 +attention to the finer points of kernel configuration, it is probably
39139 +wise to specify some reasonable defaults so as to stop careless users
39140 +from shooting themselves in the foot.
39141 +
39142 +--- a/grsecurity/Kconfig
39143 ++++ b/grsecurity/Kconfig
39144 +@@ -352,7 +564,7 @@
39145 + config GRKERNSEC_PROC_GID
39146 + int "GID for special group"
39147 + depends on GRKERNSEC_PROC_USERGROUP
39148 +- default 1001
39149 ++ default 10
39150 +
39151 + config GRKERNSEC_PROC_ADD
39152 + bool "Additional restrictions"
39153 +@@ -547,7 +759,7 @@
39154 + config GRKERNSEC_AUDIT_GID
39155 + int "GID for auditing"
39156 + depends on GRKERNSEC_AUDIT_GROUP
39157 +- default 1007
39158 ++ default 100
39159 +
39160 + config GRKERNSEC_EXECLOG
39161 + bool "Exec logging"
39162 +@@ -700,7 +912,7 @@
39163 + config GRKERNSEC_TPE_GID
39164 + int "GID for untrusted users"
39165 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
39166 +- default 1005
39167 ++ default 100
39168 + help
39169 + If you have selected the "Invert GID option" above, setting this
39170 + GID determines what group TPE restrictions will be *disabled* for.
39171 +@@ -712,7 +924,7 @@
39172 + config GRKERNSEC_TPE_GID
39173 + int "GID for trusted users"
39174 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
39175 +- default 1005
39176 ++ default 10
39177 + help
39178 + If you have selected the "Invert GID option" above, setting this
39179 + GID determines what group TPE restrictions will be *disabled* for.
39180 +@@ -754,7 +966,7 @@
39181 + config GRKERNSEC_SOCKET_ALL_GID
39182 + int "GID to deny all sockets for"
39183 + depends on GRKERNSEC_SOCKET_ALL
39184 +- default 1004
39185 ++ default 65534
39186 + help
39187 + Here you can choose the GID to disable socket access for. Remember to
39188 + add the users you want socket access disabled for to the GID
39189 +@@ -775,7 +987,7 @@
39190 + config GRKERNSEC_SOCKET_CLIENT_GID
39191 + int "GID to deny client sockets for"
39192 + depends on GRKERNSEC_SOCKET_CLIENT
39193 +- default 1003
39194 ++ default 65534
39195 + help
39196 + Here you can choose the GID to disable client socket access for.
39197 + Remember to add the users you want client socket access disabled for to
39198 +@@ -793,7 +1005,7 @@
39199 + config GRKERNSEC_SOCKET_SERVER_GID
39200 + int "GID to deny server sockets for"
39201 + depends on GRKERNSEC_SOCKET_SERVER
39202 +- default 1002
39203 ++ default 65534
39204 + help
39205 + Here you can choose the GID to disable server socket access for.
39206 + Remember to add the users you want server socket access disabled for to
39207
39208 Added: hardened/2.6/tags/2.6.27-8/4435_grsec-kconfig-gentoo.patch
39209 ===================================================================
39210 --- hardened/2.6/tags/2.6.27-8/4435_grsec-kconfig-gentoo.patch (rev 0)
39211 +++ hardened/2.6/tags/2.6.27-8/4435_grsec-kconfig-gentoo.patch 2009-01-25 09:01:31 UTC (rev 1485)
39212 @@ -0,0 +1,243 @@
39213 +From: Gordon Malm <gengor@g.o>
39214 +From: Kerin Millar <kerframil@×××××.com>
39215 +
39216 +Add Hardened Gentoo [server/workstation] predefined grsecurity
39217 +levels. They're designed to provide a comparitively high level of
39218 +security while remaining generally suitable for as great a majority
39219 +of the userbase as possible (particularly new users).
39220 +
39221 +Make Hardened Gentoo [workstation] predefined grsecurity level the
39222 +default. The Hardened Gentoo [server] level is more restrictive
39223 +and conflicts with some software and thus would be less suitable.
39224 +
39225 +The original version of this patch was conceived and created by:
39226 +Ned Ludd <solar@g.o>
39227 +
39228 +--- a/grsecurity/Kconfig
39229 ++++ b/grsecurity/Kconfig
39230 +@@ -20,7 +20,7 @@ config GRKERNSEC
39231 + choice
39232 + prompt "Security Level"
39233 + depends on GRKERNSEC
39234 +- default GRKERNSEC_CUSTOM
39235 ++ default GRKERNSEC_HARDENED_WORKSTATION
39236 +
39237 + config GRKERNSEC_LOW
39238 + bool "Low"
39239 +@@ -183,6 +183,216 @@ config GRKERNSEC_HIGH
39240 + - Mount/unmount/remount logging
39241 + - Kernel symbol hiding
39242 + - Prevention of memory exhaustion-based exploits
39243 ++
39244 ++config GRKERNSEC_HARDENED_SERVER
39245 ++ bool "Hardened Gentoo [server]"
39246 ++ select GRKERNSEC_AUDIT_MOUNT
39247 ++ select GRKERNSEC_BRUTE
39248 ++ select GRKERNSEC_CHROOT
39249 ++ select GRKERNSEC_CHROOT_CAPS
39250 ++ select GRKERNSEC_CHROOT_CHDIR
39251 ++ select GRKERNSEC_CHROOT_CHMOD
39252 ++ select GRKERNSEC_CHROOT_DOUBLE
39253 ++ select GRKERNSEC_CHROOT_FCHDIR
39254 ++ select GRKERNSEC_CHROOT_FINDTASK
39255 ++ select GRKERNSEC_CHROOT_MKNOD
39256 ++ select GRKERNSEC_CHROOT_MOUNT
39257 ++ select GRKERNSEC_CHROOT_NICE
39258 ++ select GRKERNSEC_CHROOT_PIVOT
39259 ++ select GRKERNSEC_CHROOT_SHMAT
39260 ++ select GRKERNSEC_CHROOT_SYSCTL
39261 ++ select GRKERNSEC_CHROOT_UNIX
39262 ++ select GRKERNSEC_DMESG
39263 ++ select GRKERNSEC_EXECVE
39264 ++ select GRKERNSEC_FIFO
39265 ++ select GRKERNSEC_FORKFAIL
39266 ++ select GRKERNSEC_HIDESYM
39267 ++ select GRKERNSEC_IO if (X86)
39268 ++ select GRKERNSEC_KMEM
39269 ++ select GRKERNSEC_LINK
39270 ++ select GRKERNSEC_MODSTOP if (MODULES)
39271 ++ select GRKERNSEC_PROC
39272 ++ select GRKERNSEC_PROC_ADD
39273 ++ select GRKERNSEC_PROC_IPADDR
39274 ++ select GRKERNSEC_PROC_MEMMAP
39275 ++ select GRKERNSEC_PROC_USERGROUP
39276 ++ select GRKERNSEC_RANDNET
39277 ++ select GRKERNSEC_RESLOG
39278 ++ select GRKERNSEC_SIGNAL
39279 ++# select GRKERNSEC_SOCKET
39280 ++# select GRKERNSEC_SOCKET_SERVER
39281 ++ select GRKERNSEC_SYSCTL
39282 ++ select GRKERNSEC_SYSCTL_ON
39283 ++ select GRKERNSEC_TIME
39284 ++ select PAX
39285 ++ select PAX_ASLR
39286 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
39287 ++ select PAX_EI_PAX
39288 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
39289 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
39290 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
39291 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
39292 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
39293 ++ select PAX_MEMORY_SANITIZE
39294 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
39295 ++ select PAX_MPROTECT if (!PPC64)
39296 ++ select PAX_HAVE_ACL_FLAGS
39297 ++ select PAX_NOELFRELOCS if (X86)
39298 ++ select PAX_NOEXEC
39299 ++ select PAX_PAGEEXEC
39300 ++ select PAX_PT_PAX_FLAGS
39301 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
39302 ++ select PAX_RANDMMAP
39303 ++ select PAX_RANDUSTACK
39304 ++ select PAX_REFCOUNT if (X86)
39305 ++ select PAX_SEGMEXEC if (X86_32)
39306 ++ select PAX_SYSCALL if (PPC32)
39307 ++ help
39308 ++ If you say Y here, a configuration will be used that is endorsed by
39309 ++ the Hardened Gentoo project. Therefore, many of the protections
39310 ++ made available by grsecurity and PaX will be enabled.
39311 ++
39312 ++ Hardened Gentoo's pre-defined security levels are designed to provide
39313 ++ a high level of security while minimizing incompatibilities with the
39314 ++ majority of available software. For further information, please
39315 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
39316 ++ well as the Hardened Gentoo Primer at
39317 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
39318 ++
39319 ++ This Hardened Gentoo [server] level is identical to the
39320 ++ Hardened Gentoo [workstation] level, but with the GRKERNSEC_IO,
39321 ++ PAX_KERNEXEC and PAX_NOELFRELOCS security features enabled.
39322 ++ Accordingly, this is the preferred security level if the system will
39323 ++ not be utilizing software incompatible with the aforementioned
39324 ++ grsecurity/PaX features.
39325 ++
39326 ++ You may wish to emerge paxctl, a utility which allows you to toggle
39327 ++ PaX features on problematic binaries on an individual basis. Note that
39328 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
39329 ++ Translated, this means that if you wish to toggle PaX features on
39330 ++ binaries provided by applications that are distributed only in binary
39331 ++ format (rather than being built locally from sources), you will need to
39332 ++ run paxctl -C on the binaries beforehand so as to inject the missing
39333 ++ headers.
39334 ++
39335 ++ When this level is selected, some options cannot be changed. However,
39336 ++ you may opt to fully customize the options that are selected by
39337 ++ choosing "Custom" in the Security Level menu. You may find it helpful
39338 ++ to inherit the options selected by the "Hardened Gentoo [server]"
39339 ++ security level as a starting point for further configuration. To
39340 ++ accomplish this, select this security level then exit the menuconfig
39341 ++ interface, saving changes when prompted. Then, run make menuconfig
39342 ++ again and select the "Custom" level.
39343 ++
39344 ++ Note that this security level probably should not be used if the
39345 ++ target system is a 32bit x86 virtualized guest. If you intend to run
39346 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
39347 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
39348 ++ impact on performance.
39349 ++
39350 ++config GRKERNSEC_HARDENED_WORKSTATION
39351 ++ bool "Hardened Gentoo [workstation]"
39352 ++ select GRKERNSEC_AUDIT_MOUNT
39353 ++ select GRKERNSEC_BRUTE
39354 ++ select GRKERNSEC_CHROOT
39355 ++ select GRKERNSEC_CHROOT_CAPS
39356 ++ select GRKERNSEC_CHROOT_CHDIR
39357 ++ select GRKERNSEC_CHROOT_CHMOD
39358 ++ select GRKERNSEC_CHROOT_DOUBLE
39359 ++ select GRKERNSEC_CHROOT_FCHDIR
39360 ++ select GRKERNSEC_CHROOT_FINDTASK
39361 ++ select GRKERNSEC_CHROOT_MKNOD
39362 ++ select GRKERNSEC_CHROOT_MOUNT
39363 ++ select GRKERNSEC_CHROOT_NICE
39364 ++ select GRKERNSEC_CHROOT_PIVOT
39365 ++ select GRKERNSEC_CHROOT_SHMAT
39366 ++ select GRKERNSEC_CHROOT_SYSCTL
39367 ++ select GRKERNSEC_CHROOT_UNIX
39368 ++ select GRKERNSEC_DMESG
39369 ++ select GRKERNSEC_EXECVE
39370 ++ select GRKERNSEC_FIFO
39371 ++ select GRKERNSEC_FORKFAIL
39372 ++ select GRKERNSEC_HIDESYM
39373 ++ select GRKERNSEC_KMEM
39374 ++ select GRKERNSEC_LINK
39375 ++ select GRKERNSEC_MODSTOP if (MODULES)
39376 ++ select GRKERNSEC_PROC
39377 ++ select GRKERNSEC_PROC_ADD
39378 ++ select GRKERNSEC_PROC_IPADDR
39379 ++ select GRKERNSEC_PROC_MEMMAP
39380 ++ select GRKERNSEC_PROC_USERGROUP
39381 ++ select GRKERNSEC_RANDNET
39382 ++ select GRKERNSEC_RESLOG
39383 ++ select GRKERNSEC_SIGNAL
39384 ++# select GRKERNSEC_SOCKET
39385 ++# select GRKERNSEC_SOCKET_SERVER
39386 ++ select GRKERNSEC_SYSCTL
39387 ++ select GRKERNSEC_SYSCTL_ON
39388 ++ select GRKERNSEC_TIME
39389 ++ select PAX
39390 ++ select PAX_ASLR
39391 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
39392 ++ select PAX_EI_PAX
39393 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
39394 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
39395 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
39396 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
39397 ++ select PAX_MEMORY_SANITIZE
39398 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
39399 ++ select PAX_MPROTECT if (!PPC64)
39400 ++ select PAX_HAVE_ACL_FLAGS
39401 ++ select PAX_NOEXEC
39402 ++ select PAX_PAGEEXEC
39403 ++ select PAX_PT_PAX_FLAGS
39404 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
39405 ++ select PAX_RANDMMAP
39406 ++ select PAX_RANDUSTACK
39407 ++ select PAX_REFCOUNT if (X86)
39408 ++ select PAX_SEGMEXEC if (X86_32)
39409 ++ select PAX_SYSCALL if (PPC32)
39410 ++ help
39411 ++ If you say Y here, a configuration will be used that is endorsed by
39412 ++ the Hardened Gentoo project. Therefore, many of the protections
39413 ++ made available by grsecurity and PaX will be enabled.
39414 ++
39415 ++ Hardened Gentoo's pre-defined security levels are designed to provide
39416 ++ a high level of security while minimizing incompatibilities with the
39417 ++ majority of available software. For further information, please
39418 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
39419 ++ well as the Hardened Gentoo Primer at
39420 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
39421 ++
39422 ++ This Hardened Gentoo [workstation] level is designed for machines
39423 ++ which are intended to run software not compatible with the
39424 ++ GRKERNSEC_IO, PAX_KERNEXEC and PAX_NOELFRELOCS features of grsecurity.
39425 ++ Accordingly, this security level is suitable for use with the X server
39426 ++ "Xorg" and/or any system that will act as host OS to the virtualization
39427 ++ softwares vmware-server or virtualbox.
39428 ++
39429 ++ You may wish to emerge paxctl, a utility which allows you to toggle
39430 ++ PaX features on problematic binaries on an individual basis. Note that
39431 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
39432 ++ Translated, this means that if you wish to toggle PaX features on
39433 ++ binaries provided by applications that are distributed only in binary
39434 ++ format (rather than being built locally from sources), you will need to
39435 ++ run paxctl -C on the binaries beforehand so as to inject the missing
39436 ++ headers.
39437 ++
39438 ++ When this level is selected, some options cannot be changed. However,
39439 ++ you may opt to fully customize the options that are selected by
39440 ++ choosing "Custom" in the Security Level menu. You may find it helpful
39441 ++ to inherit the options selected by the "Hardened Gentoo [workstation]"
39442 ++ security level as a starting point for further configuration. To
39443 ++ accomplish this, select this security level then exit the menuconfig
39444 ++ interface, saving changes when prompted. Then, run make menuconfig
39445 ++ again and select the "Custom" level.
39446 ++
39447 ++ Note that this security level probably should not be used if the
39448 ++ target system is a 32bit x86 virtualized guest. If you intend to run
39449 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
39450 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
39451 ++ impact on performance.
39452 ++
39453 + config GRKERNSEC_CUSTOM
39454 + bool "Custom"
39455 + help
39456
39457 Added: hardened/2.6/tags/2.6.27-8/4440_selinux-avc_audit-log-curr_ip.patch
39458 ===================================================================
39459 --- hardened/2.6/tags/2.6.27-8/4440_selinux-avc_audit-log-curr_ip.patch (rev 0)
39460 +++ hardened/2.6/tags/2.6.27-8/4440_selinux-avc_audit-log-curr_ip.patch 2009-01-25 09:01:31 UTC (rev 1485)
39461 @@ -0,0 +1,65 @@
39462 +From: Gordon Malm <gengor@g.o>
39463 +
39464 +This is a reworked version of the original
39465 +*_selinux-avc_audit-log-curr_ip.patch carried in earlier releases of
39466 +hardened-sources.
39467 +
39468 +Dropping the patch, or simply fixing the #ifdef of the original patch
39469 +could break automated logging setups so this route was necessary.
39470 +
39471 +Suggestions for improving the help text are welcome.
39472 +
39473 +The original patch's description is still accurate and included below.
39474 +
39475 +---
39476 +Provides support for a new field ipaddr within the SELinux
39477 +AVC audit log, relying in task_struct->curr_ip (ipv4 only)
39478 +provided by grSecurity patch to be applied before.
39479 +
39480 +Signed-off-by: Lorenzo Hernandez Garcia-Hierro <lorenzo@×××.org>
39481 +---
39482 +
39483 +--- a/grsecurity/Kconfig
39484 ++++ b/grsecurity/Kconfig
39485 +@@ -1044,6 +1044,27 @@ endmenu
39486 + menu "Logging Options"
39487 + depends on GRKERNSEC
39488 +
39489 ++config GRKERNSEC_SELINUX_AVC_LOG_IPADDR
39490 ++ def_bool n
39491 ++ prompt "Add source IP address to SELinux AVC log messages"
39492 ++ depends on GRKERNSEC && SECURITY_SELINUX
39493 ++ help
39494 ++ If you say Y here, a new field "ipaddr=" will be added to many SELinux
39495 ++ AVC log messages. The value of this field in any given message
39496 ++ represents the source IP address of the remote machine/user that created
39497 ++ the offending process.
39498 ++
39499 ++ This information is sourced from task_struct->curr_ip provided by
39500 ++ grsecurity's GRKERNSEC top-level configuration option. One limitation
39501 ++ is that only IPv4 is supported.
39502 ++
39503 ++ In many instances SELinux AVC log messages already log a superior level
39504 ++ of information that also includes source port and destination ip/port.
39505 ++ Additionally, SELinux's AVC log code supports IPv6.
39506 ++
39507 ++ However, grsecurity's task_struct->curr_ip will sometimes (often?)
39508 ++ provide the offender's IP address where stock SELinux logging fails to.
39509 ++
39510 + config GRKERNSEC_FLOODTIME
39511 + int "Seconds in between log messages (minimum)"
39512 + default 10
39513 +--- a/security/selinux/avc.c
39514 ++++ b/security/selinux/avc.c
39515 +@@ -202,6 +202,11 @@ static void avc_dump_query(struct audit_
39516 + char *scontext;
39517 + u32 scontext_len;
39518 +
39519 ++#ifdef CONFIG_GRKERNSEC_SELINUX_AVC_LOG_IPADDR
39520 ++ if (current->signal->curr_ip)
39521 ++ audit_log_format(ab, "ipaddr=%u.%u.%u.%u ", NIPQUAD(current->signal->curr_ip));
39522 ++#endif
39523 ++
39524 + rc = security_sid_to_context(ssid, &scontext, &scontext_len);
39525 + if (rc)
39526 + audit_log_format(ab, "ssid=%d", ssid);
39527
39528 Added: hardened/2.6/tags/2.6.27-8/4445_disable-compat_vdso.patch
39529 ===================================================================
39530 --- hardened/2.6/tags/2.6.27-8/4445_disable-compat_vdso.patch (rev 0)
39531 +++ hardened/2.6/tags/2.6.27-8/4445_disable-compat_vdso.patch 2009-01-25 09:01:31 UTC (rev 1485)
39532 @@ -0,0 +1,74 @@
39533 +From: Gordon Malm <gengor@g.o>
39534 +From: Kerin Millar <kerframil@×××××.com>
39535 +
39536 +COMPAT_VDSO is inappropriate for any modern Hardened Gentoo system. It
39537 +conflicts with various parts of PaX, crashing the system if enabled
39538 +while PaX's NOEXEC or UDEREF features are active. Moreover, it prevents
39539 +a number of important PaX options from appearing in the configuration
39540 +menu, including all PaX NOEXEC implementations. Unfortunately, the
39541 +reason for the disappearance of these PaX configuration options is
39542 +often far from obvious to inexperienced users.
39543 +
39544 +Therefore, we disable the COMPAT_VDSO menu entry entirely. However,
39545 +COMPAT_VDSO operation can still be enabled via bootparam and sysctl
39546 +interfaces. Consequently, we must also disable the ability to select
39547 +COMPAT_VDSO operation at boot or runtime. Here we patch the kernel so
39548 +that selecting COMPAT_VDSO operation at boot/runtime has no effect if
39549 +conflicting PaX options are enabled, leaving VDSO_ENABLED operation
39550 +intact.
39551 +
39552 +Closes bug: http://bugs.gentoo.org/show_bug.cgi?id=210138
39553 +
39554 +--- a/arch/x86/Kconfig
39555 ++++ b/arch/x86/Kconfig
39556 +@@ -1215,16 +1215,7 @@ config HOTPLUG_CPU
39557 +
39558 + config COMPAT_VDSO
39559 + def_bool n
39560 +- prompt "Compat VDSO support"
39561 + depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
39562 +- help
39563 +- Map the 32-bit VDSO to the predictable old-style address too.
39564 +- ---help---
39565 +- Say N here if you are running a sufficiently recent glibc
39566 +- version (2.3.3 or later), to remove the high-mapped
39567 +- VDSO mapping and to exclusively use the randomized VDSO.
39568 +-
39569 +- If unsure, say Y.
39570 +
39571 + endmenu
39572 +
39573 +--- a/arch/x86/vdso/vdso32-setup.c
39574 ++++ b/arch/x86/vdso/vdso32-setup.c
39575 +@@ -333,17 +333,21 @@ int arch_setup_additional_pages(struct l
39576 +
39577 + map_compat_vdso(compat);
39578 +
39579 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
39580 + if (compat)
39581 + addr = VDSO_HIGH_BASE;
39582 + else {
39583 ++#endif
39584 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
39585 + if (IS_ERR_VALUE(addr)) {
39586 + ret = addr;
39587 + goto up_fail;
39588 + }
39589 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
39590 + }
39591 +
39592 + if (compat_uses_vma || !compat) {
39593 ++#endif
39594 + /*
39595 + * MAYWRITE to allow gdb to COW and set breakpoints
39596 + *
39597 +@@ -361,7 +365,9 @@ int arch_setup_additional_pages(struct l
39598 +
39599 + if (ret)
39600 + goto up_fail;
39601 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
39602 + }
39603 ++#endif
39604 +
39605 + current->mm->context.vdso = addr;
39606 + current_thread_info()->sysenter_return =
39607
39608 Added: hardened/2.6/tags/2.6.27-8/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch
39609 ===================================================================
39610 --- hardened/2.6/tags/2.6.27-8/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch (rev 0)
39611 +++ hardened/2.6/tags/2.6.27-8/4450_grsec-add-offender-IP-to-pax_refcount-logging.patch 2009-01-25 09:01:31 UTC (rev 1485)
39612 @@ -0,0 +1,21 @@
39613 +From: Gordon Malm <gengor@g.o>
39614 +
39615 +Add offender's IP to PAX_REFCOUNT log messages if it is available.
39616 +
39617 +--- a/fs/exec.c
39618 ++++ b/fs/exec.c
39619 +@@ -1710,7 +1710,13 @@ void pax_report_fault(struct pt_regs *re
39620 + #ifdef CONFIG_PAX_REFCOUNT
39621 + void pax_report_refcount_overflow(struct pt_regs *regs)
39622 + {
39623 +- printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
39624 ++#ifdef CONFIG_GRKERNSEC
39625 ++ if (current->signal->curr_ip)
39626 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
39627 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
39628 ++ else
39629 ++#endif
39630 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
39631 + current->comm, task_pid_nr(current), current->uid, current->euid);
39632 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
39633 + show_registers(regs);
39634
39635 Added: hardened/2.6/tags/2.6.27-8/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch
39636 ===================================================================
39637 --- hardened/2.6/tags/2.6.27-8/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch (rev 0)
39638 +++ hardened/2.6/tags/2.6.27-8/4455_pax-revert-fix-false-RLIMIT_STACK-warnings.patch 2009-01-25 09:01:31 UTC (rev 1485)
39639 @@ -0,0 +1,33 @@
39640 +From: Gordon Malm <gengor@g.o>
39641 +
39642 +Revert RLIMIT_STACK false-positives-avoidance change in PaX for now.
39643 +
39644 +Fixes random segmentation faults, bugs 253773 and 254843.
39645 +
39646 +--- a/arch/x86/mm/fault.c
39647 ++++ b/arch/x86/mm/fault.c
39648 +@@ -852,14 +852,16 @@ not_pax_fault:
39649 + goto good_area;
39650 + if (!(vma->vm_flags & VM_GROWSDOWN))
39651 + goto bad_area;
39652 +- /*
39653 +- * Accessing the stack below %sp is always a bug.
39654 +- * The large cushion allows instructions like enter
39655 +- * and pusha to work. ("enter $65535,$31" pushes
39656 +- * 32 pointers and then decrements %sp by 65535.)
39657 +- */
39658 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
39659 +- goto bad_area;
39660 ++ if (error_code & PF_USER) {
39661 ++ /*
39662 ++ * Accessing the stack below %sp is always a bug.
39663 ++ * The large cushion allows instructions like enter
39664 ++ * and pusha to work. ("enter $65535,$31" pushes
39665 ++ * 32 pointers and then decrements %sp by 65535.)
39666 ++ */
39667 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
39668 ++ goto bad_area;
39669 ++ }
39670 +
39671 + #ifdef CONFIG_PAX_SEGMEXEC
39672 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)