Gentoo Archives: gentoo-commits

From: "Gordon Malm (gengor)" <gengor@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] linux-patches r1486 - in hardened/2.6/tags: . 2.6.28-1
Date: Sun, 25 Jan 2009 09:04:45
Message-Id: E1LR0tV-0007bs-Gl@stork.gentoo.org
1 Author: gengor
2 Date: 2009-01-25 09:03:04 +0000 (Sun, 25 Jan 2009)
3 New Revision: 1486
4
5 Added:
6 hardened/2.6/tags/2.6.28-1/
7 hardened/2.6/tags/2.6.28-1/0000_README
8 hardened/2.6/tags/2.6.28-1/1001_linux-2.6.28.2.patch
9 hardened/2.6/tags/2.6.28-1/4420_grsec-2.1.12-2.6.28-200901161810.patch
10 hardened/2.6/tags/2.6.28-1/4421_grsec-remove-localversion-grsec.patch
11 hardened/2.6/tags/2.6.28-1/4422_grsec-mute-warnings.patch
12 hardened/2.6/tags/2.6.28-1/4425_grsec-pax-without-grsec.patch
13 hardened/2.6/tags/2.6.28-1/4430_grsec-kconfig-default-gids.patch
14 hardened/2.6/tags/2.6.28-1/4435_grsec-kconfig-gentoo.patch
15 hardened/2.6/tags/2.6.28-1/4440_selinux-avc_audit-log-curr_ip.patch
16 hardened/2.6/tags/2.6.28-1/4445_disable-compat_vdso.patch
17 hardened/2.6/tags/2.6.28-1/4450_pax-2.6.28.1-test8-to-test10.patch
18 Log:
19 Tag 2.6.28-1 hardened-extras patchset
20
21 Added: hardened/2.6/tags/2.6.28-1/0000_README
22 ===================================================================
23 --- hardened/2.6/tags/2.6.28-1/0000_README (rev 0)
24 +++ hardened/2.6/tags/2.6.28-1/0000_README 2009-01-25 09:03:04 UTC (rev 1486)
25 @@ -0,0 +1,50 @@
26 +README
27 +-----------------------------------------------------------------------------
28 +
29 +Individual Patch Descriptions:
30 +-----------------------------------------------------------------------------
31 +Patch: 1001_linux-2.6.28.2.patch
32 +From: http://www.kernel.org
33 +Desc: Linux 2.6.28.2
34 +
35 +Patch: 4420_grsec-2.1.12-2.6.28-200901161810.patch
36 +From: http://www.grsecurity.net
37 +Desc: hardened-sources base patch from upstream grsecurity
38 +
39 +Patch: 4421_grsec-remove-localversion-grsec.patch
40 +From: Kerin Millar <kerframil@×××××.com>
41 +Desc: Removes grsecurity's localversion-grsec file
42 +
43 +Patch: 4422_grsec-mute-warnings.patch
44 +From: Alexander Gabert <gaberta@××××××××.de>
45 + Gordon Malm <gengor@g.o>
46 +Desc: Removes verbose compile warning settings from grsecurity, restores
47 + mainline Linux kernel behavior
48 +
49 +Patch: 4425_grsec-pax-without-grsec.patch
50 +From: Gordon Malm <gengor@g.o>
51 +Desc: Allows PaX features to be selected without enabling GRKERNSEC
52 +
53 +Patch: 4430_grsec-kconfig-default-gids.patch
54 +From: Kerin Millar <kerframil@×××××.com>
55 +Desc: Sets sane(r) default GIDs on various grsecurity group-dependent
56 + features
57 +
58 +Patch: 4435_grsec-kconfig-gentoo.patch
59 +From: Gordon Malm <gengor@g.o>
60 + Kerin Millar <kerframil@×××××.com>
61 +Desc: Adds Hardened Gentoo [server/workstation] security levels, sets
62 + Hardened Gentoo [workstation] as default
63 +
64 +Patch: 4440_selinux-avc_audit-log-curr_ip.patch
65 +From: Gordon Malm <gengor@g.o>
66 +Desc: Configurable option to add src IP address to SELinux log messages
67 +
68 +Patch: 4445_disable-compat_vdso.patch
69 +From: Gordon Malm <gengor@g.o>
70 + Kerin Millar <kerframil@×××××.com>
71 +Desc: Disables VDSO_COMPAT operation completely
72 +
73 +Patch: 4450_pax-2.6.28.1-test8-to-test10.patch
74 +From: Gordon Malm <gengor@g.o>
75 +Desc: Adds PaX changes from pax-2.6.28.1-test9 and pax-2.6.28.1-test10
76
77 Added: hardened/2.6/tags/2.6.28-1/1001_linux-2.6.28.2.patch
78 ===================================================================
79 --- hardened/2.6/tags/2.6.28-1/1001_linux-2.6.28.2.patch (rev 0)
80 +++ hardened/2.6/tags/2.6.28-1/1001_linux-2.6.28.2.patch 2009-01-25 09:03:04 UTC (rev 1486)
81 @@ -0,0 +1,1998 @@
82 +diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
83 +index 394d7d3..bef6550 100644
84 +--- a/Documentation/sound/alsa/ALSA-Configuration.txt
85 ++++ b/Documentation/sound/alsa/ALSA-Configuration.txt
86 +@@ -979,9 +979,10 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
87 + 6stack 6-jack, separate surrounds (default)
88 + 3stack 3-stack, shared surrounds
89 + laptop 2-channel only (FSC V2060, Samsung M50)
90 +- laptop-eapd 2-channel with EAPD (Samsung R65, ASUS A6J)
91 ++ laptop-eapd 2-channel with EAPD (ASUS A6J)
92 + laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100)
93 + ultra 2-channel with EAPD (Samsung Ultra tablet PC)
94 ++ samsung 2-channel with EAPD (Samsung R65)
95 +
96 + AD1988/AD1988B/AD1989A/AD1989B
97 + 6stack 6-jack
98 +diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
99 +index 6bd91ed..0429d3e 100644
100 +--- a/arch/ia64/Kconfig
101 ++++ b/arch/ia64/Kconfig
102 +@@ -17,6 +17,7 @@ config IA64
103 + select ACPI if (!IA64_HP_SIM)
104 + select PM if (!IA64_HP_SIM)
105 + select ARCH_SUPPORTS_MSI
106 ++ select HAVE_UNSTABLE_SCHED_CLOCK
107 + select HAVE_IDE
108 + select HAVE_OPROFILE
109 + select HAVE_KPROBES
110 +diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
111 +index db44e02..ba51948 100644
112 +--- a/arch/powerpc/mm/slice.c
113 ++++ b/arch/powerpc/mm/slice.c
114 +@@ -710,9 +710,18 @@ int is_hugepage_only_range(struct mm_struct *mm, unsigned long addr,
115 + unsigned long len)
116 + {
117 + struct slice_mask mask, available;
118 ++ unsigned int psize = mm->context.user_psize;
119 +
120 + mask = slice_range_to_mask(addr, len);
121 +- available = slice_mask_for_size(mm, mm->context.user_psize);
122 ++ available = slice_mask_for_size(mm, psize);
123 ++#ifdef CONFIG_PPC_64K_PAGES
124 ++ /* We need to account for 4k slices too */
125 ++ if (psize == MMU_PAGE_64K) {
126 ++ struct slice_mask compat_mask;
127 ++ compat_mask = slice_mask_for_size(mm, MMU_PAGE_4K);
128 ++ or_mask(available, compat_mask);
129 ++ }
130 ++#endif
131 +
132 + #if 0 /* too verbose */
133 + slice_dbg("is_hugepage_only_range(mm=%p, addr=%lx, len=%lx)\n",
134 +diff --git a/drivers/firmware/dell_rbu.c b/drivers/firmware/dell_rbu.c
135 +index 13946eb..b4704e1 100644
136 +--- a/drivers/firmware/dell_rbu.c
137 ++++ b/drivers/firmware/dell_rbu.c
138 +@@ -576,7 +576,7 @@ static ssize_t read_rbu_image_type(struct kobject *kobj,
139 + {
140 + int size = 0;
141 + if (!pos)
142 +- size = sprintf(buffer, "%s\n", image_type);
143 ++ size = scnprintf(buffer, count, "%s\n", image_type);
144 + return size;
145 + }
146 +
147 +@@ -648,7 +648,7 @@ static ssize_t read_rbu_packet_size(struct kobject *kobj,
148 + int size = 0;
149 + if (!pos) {
150 + spin_lock(&rbu_data.lock);
151 +- size = sprintf(buffer, "%lu\n", rbu_data.packetsize);
152 ++ size = scnprintf(buffer, count, "%lu\n", rbu_data.packetsize);
153 + spin_unlock(&rbu_data.lock);
154 + }
155 + return size;
156 +diff --git a/drivers/hwmon/abituguru3.c b/drivers/hwmon/abituguru3.c
157 +index 70bb854..fcf74eb 100644
158 +--- a/drivers/hwmon/abituguru3.c
159 ++++ b/drivers/hwmon/abituguru3.c
160 +@@ -1153,7 +1153,7 @@ static int __init abituguru3_dmi_detect(void)
161 +
162 + static inline int abituguru3_dmi_detect(void)
163 + {
164 +- return -ENODEV;
165 ++ return 1;
166 + }
167 +
168 + #endif /* CONFIG_DMI */
169 +diff --git a/drivers/misc/sgi-xp/xpc_sn2.c b/drivers/misc/sgi-xp/xpc_sn2.c
170 +index b4882cc..d32c1ee 100644
171 +--- a/drivers/misc/sgi-xp/xpc_sn2.c
172 ++++ b/drivers/misc/sgi-xp/xpc_sn2.c
173 +@@ -904,7 +904,7 @@ xpc_update_partition_info_sn2(struct xpc_partition *part, u8 remote_rp_version,
174 + dev_dbg(xpc_part, " remote_vars_pa = 0x%016lx\n",
175 + part_sn2->remote_vars_pa);
176 +
177 +- part->last_heartbeat = remote_vars->heartbeat;
178 ++ part->last_heartbeat = remote_vars->heartbeat - 1;
179 + dev_dbg(xpc_part, " last_heartbeat = 0x%016lx\n",
180 + part->last_heartbeat);
181 +
182 +diff --git a/drivers/net/irda/irda-usb.c b/drivers/net/irda/irda-usb.c
183 +index b5d6b9a..b427978 100644
184 +--- a/drivers/net/irda/irda-usb.c
185 ++++ b/drivers/net/irda/irda-usb.c
186 +@@ -1075,7 +1075,7 @@ static int stir421x_patch_device(struct irda_usb_cb *self)
187 + {
188 + unsigned int i;
189 + int ret;
190 +- char stir421x_fw_name[11];
191 ++ char stir421x_fw_name[12];
192 + const struct firmware *fw;
193 + const unsigned char *fw_version_ptr; /* pointer to version string */
194 + unsigned long fw_version = 0;
195 +diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c
196 +index 34fe7ef..9934dbc 100644
197 +--- a/drivers/net/r6040.c
198 ++++ b/drivers/net/r6040.c
199 +@@ -49,8 +49,8 @@
200 + #include <asm/processor.h>
201 +
202 + #define DRV_NAME "r6040"
203 +-#define DRV_VERSION "0.18"
204 +-#define DRV_RELDATE "13Jul2008"
205 ++#define DRV_VERSION "0.19"
206 ++#define DRV_RELDATE "18Dec2008"
207 +
208 + /* PHY CHIP Address */
209 + #define PHY1_ADDR 1 /* For MAC1 */
210 +@@ -214,7 +214,7 @@ static int r6040_phy_read(void __iomem *ioaddr, int phy_addr, int reg)
211 + /* Wait for the read bit to be cleared */
212 + while (limit--) {
213 + cmd = ioread16(ioaddr + MMDIO);
214 +- if (cmd & MDIO_READ)
215 ++ if (!(cmd & MDIO_READ))
216 + break;
217 + }
218 +
219 +@@ -233,7 +233,7 @@ static void r6040_phy_write(void __iomem *ioaddr, int phy_addr, int reg, u16 val
220 + /* Wait for the write bit to be cleared */
221 + while (limit--) {
222 + cmd = ioread16(ioaddr + MMDIO);
223 +- if (cmd & MDIO_WRITE)
224 ++ if (!(cmd & MDIO_WRITE))
225 + break;
226 + }
227 + }
228 +@@ -681,8 +681,10 @@ static irqreturn_t r6040_interrupt(int irq, void *dev_id)
229 + struct net_device *dev = dev_id;
230 + struct r6040_private *lp = netdev_priv(dev);
231 + void __iomem *ioaddr = lp->base;
232 +- u16 status;
233 ++ u16 misr, status;
234 +
235 ++ /* Save MIER */
236 ++ misr = ioread16(ioaddr + MIER);
237 + /* Mask off RDC MAC interrupt */
238 + iowrite16(MSK_INT, ioaddr + MIER);
239 + /* Read MISR status and clear */
240 +@@ -702,7 +704,7 @@ static irqreturn_t r6040_interrupt(int irq, void *dev_id)
241 + dev->stats.rx_fifo_errors++;
242 +
243 + /* Mask off RX interrupt */
244 +- iowrite16(ioread16(ioaddr + MIER) & ~RX_INTS, ioaddr + MIER);
245 ++ misr &= ~RX_INTS;
246 + netif_rx_schedule(dev, &lp->napi);
247 + }
248 +
249 +@@ -710,6 +712,9 @@ static irqreturn_t r6040_interrupt(int irq, void *dev_id)
250 + if (status & TX_INTS)
251 + r6040_tx(dev);
252 +
253 ++ /* Restore RDC MAC interrupt */
254 ++ iowrite16(misr, ioaddr + MIER);
255 ++
256 + return IRQ_HANDLED;
257 + }
258 +
259 +diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
260 +index 75d749b..8a2e32d 100644
261 +--- a/drivers/net/wireless/p54/p54usb.c
262 ++++ b/drivers/net/wireless/p54/p54usb.c
263 +@@ -54,6 +54,7 @@ static struct usb_device_id p54u_table[] __devinitdata = {
264 + {USB_DEVICE(0x050d, 0x7050)}, /* Belkin F5D7050 ver 1000 */
265 + {USB_DEVICE(0x0572, 0x2000)}, /* Cohiba Proto board */
266 + {USB_DEVICE(0x0572, 0x2002)}, /* Cohiba Proto board */
267 ++ {USB_DEVICE(0x06b9, 0x0121)}, /* Thomson SpeedTouch 121g */
268 + {USB_DEVICE(0x0707, 0xee13)}, /* SMC 2862W-G version 2 */
269 + {USB_DEVICE(0x083a, 0x4521)}, /* Siemens Gigaset USB Adapter 54 version 2 */
270 + {USB_DEVICE(0x0846, 0x4240)}, /* Netgear WG111 (v2) */
271 +@@ -214,6 +215,8 @@ static void p54u_tx_3887(struct ieee80211_hw *dev, struct p54_control_hdr *data,
272 + usb_fill_bulk_urb(data_urb, priv->udev,
273 + usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), data, len,
274 + free_on_tx ? p54u_tx_free_cb : p54u_tx_cb, dev);
275 ++ addr_urb->transfer_flags |= URB_ZERO_PACKET;
276 ++ data_urb->transfer_flags |= URB_ZERO_PACKET;
277 +
278 + usb_submit_urb(addr_urb, GFP_ATOMIC);
279 + usb_submit_urb(data_urb, GFP_ATOMIC);
280 +@@ -251,6 +254,7 @@ static void p54u_tx_lm87(struct ieee80211_hw *dev,
281 + usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), hdr,
282 + len + sizeof(*hdr), free_on_tx ? p54u_tx_free_cb : p54u_tx_cb,
283 + dev);
284 ++ data_urb->transfer_flags |= URB_ZERO_PACKET;
285 +
286 + usb_submit_urb(data_urb, GFP_ATOMIC);
287 + }
288 +@@ -293,11 +297,13 @@ static void p54u_tx_net2280(struct ieee80211_hw *dev, struct p54_control_hdr *da
289 + usb_fill_bulk_urb(int_urb, priv->udev,
290 + usb_sndbulkpipe(priv->udev, P54U_PIPE_DEV), reg, sizeof(*reg),
291 + p54u_tx_free_cb, dev);
292 ++ int_urb->transfer_flags |= URB_ZERO_PACKET;
293 + usb_submit_urb(int_urb, GFP_ATOMIC);
294 +
295 + usb_fill_bulk_urb(data_urb, priv->udev,
296 + usb_sndbulkpipe(priv->udev, P54U_PIPE_DATA), hdr, len + sizeof(*hdr),
297 + free_on_tx ? p54u_tx_free_cb : p54u_tx_cb, dev);
298 ++ data_urb->transfer_flags |= URB_ZERO_PACKET;
299 + usb_submit_urb(data_urb, GFP_ATOMIC);
300 + }
301 +
302 +diff --git a/drivers/net/wireless/rt2x00/rt73usb.c b/drivers/net/wireless/rt2x00/rt73usb.c
303 +index 934f8e0..42cfa05 100644
304 +--- a/drivers/net/wireless/rt2x00/rt73usb.c
305 ++++ b/drivers/net/wireless/rt2x00/rt73usb.c
306 +@@ -2434,6 +2434,7 @@ static struct usb_device_id rt73usb_device_table[] = {
307 + /* Linksys */
308 + { USB_DEVICE(0x13b1, 0x0020), USB_DEVICE_DATA(&rt73usb_ops) },
309 + { USB_DEVICE(0x13b1, 0x0023), USB_DEVICE_DATA(&rt73usb_ops) },
310 ++ { USB_DEVICE(0x13b1, 0x0028), USB_DEVICE_DATA(&rt73usb_ops) },
311 + /* MSI */
312 + { USB_DEVICE(0x0db0, 0x6877), USB_DEVICE_DATA(&rt73usb_ops) },
313 + { USB_DEVICE(0x0db0, 0x6874), USB_DEVICE_DATA(&rt73usb_ops) },
314 +diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
315 +index 9aad608..503f082 100644
316 +--- a/drivers/pci/pcie/aspm.c
317 ++++ b/drivers/pci/pcie/aspm.c
318 +@@ -33,6 +33,11 @@ struct endpoint_state {
319 + struct pcie_link_state {
320 + struct list_head sibiling;
321 + struct pci_dev *pdev;
322 ++ bool downstream_has_switch;
323 ++
324 ++ struct pcie_link_state *parent;
325 ++ struct list_head children;
326 ++ struct list_head link;
327 +
328 + /* ASPM state */
329 + unsigned int support_state;
330 +@@ -125,7 +130,7 @@ static void pcie_set_clock_pm(struct pci_dev *pdev, int enable)
331 + link_state->clk_pm_enabled = !!enable;
332 + }
333 +
334 +-static void pcie_check_clock_pm(struct pci_dev *pdev)
335 ++static void pcie_check_clock_pm(struct pci_dev *pdev, int blacklist)
336 + {
337 + int pos;
338 + u32 reg32;
339 +@@ -149,10 +154,26 @@ static void pcie_check_clock_pm(struct pci_dev *pdev)
340 + if (!(reg16 & PCI_EXP_LNKCTL_CLKREQ_EN))
341 + enabled = 0;
342 + }
343 +- link_state->clk_pm_capable = capable;
344 + link_state->clk_pm_enabled = enabled;
345 + link_state->bios_clk_state = enabled;
346 +- pcie_set_clock_pm(pdev, policy_to_clkpm_state(pdev));
347 ++ if (!blacklist) {
348 ++ link_state->clk_pm_capable = capable;
349 ++ pcie_set_clock_pm(pdev, policy_to_clkpm_state(pdev));
350 ++ } else {
351 ++ link_state->clk_pm_capable = 0;
352 ++ pcie_set_clock_pm(pdev, 0);
353 ++ }
354 ++}
355 ++
356 ++static bool pcie_aspm_downstream_has_switch(struct pci_dev *pdev)
357 ++{
358 ++ struct pci_dev *child_dev;
359 ++
360 ++ list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
361 ++ if (child_dev->pcie_type == PCI_EXP_TYPE_UPSTREAM)
362 ++ return true;
363 ++ }
364 ++ return false;
365 + }
366 +
367 + /*
368 +@@ -419,9 +440,9 @@ static unsigned int pcie_aspm_check_state(struct pci_dev *pdev,
369 + {
370 + struct pci_dev *child_dev;
371 +
372 +- /* If no child, disable the link */
373 ++ /* If no child, ignore the link */
374 + if (list_empty(&pdev->subordinate->devices))
375 +- return 0;
376 ++ return state;
377 + list_for_each_entry(child_dev, &pdev->subordinate->devices, bus_list) {
378 + if (child_dev->pcie_type == PCI_EXP_TYPE_PCI_BRIDGE) {
379 + /*
380 +@@ -462,6 +483,9 @@ static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state)
381 + int valid = 1;
382 + struct pcie_link_state *link_state = pdev->link_state;
383 +
384 ++ /* If no child, disable the link */
385 ++ if (list_empty(&pdev->subordinate->devices))
386 ++ state = 0;
387 + /*
388 + * if the downstream component has pci bridge function, don't do ASPM
389 + * now
390 +@@ -493,20 +517,52 @@ static void __pcie_aspm_config_link(struct pci_dev *pdev, unsigned int state)
391 + link_state->enabled_state = state;
392 + }
393 +
394 ++static struct pcie_link_state *get_root_port_link(struct pcie_link_state *link)
395 ++{
396 ++ struct pcie_link_state *root_port_link = link;
397 ++ while (root_port_link->parent)
398 ++ root_port_link = root_port_link->parent;
399 ++ return root_port_link;
400 ++}
401 ++
402 ++/* check the whole hierarchy, and configure each link in the hierarchy */
403 + static void __pcie_aspm_configure_link_state(struct pci_dev *pdev,
404 + unsigned int state)
405 + {
406 + struct pcie_link_state *link_state = pdev->link_state;
407 ++ struct pcie_link_state *root_port_link = get_root_port_link(link_state);
408 ++ struct pcie_link_state *leaf;
409 +
410 +- if (link_state->support_state == 0)
411 +- return;
412 + state &= PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1;
413 +
414 +- /* state 0 means disabling aspm */
415 +- state = pcie_aspm_check_state(pdev, state);
416 ++ /* check all links who have specific root port link */
417 ++ list_for_each_entry(leaf, &link_list, sibiling) {
418 ++ if (!list_empty(&leaf->children) ||
419 ++ get_root_port_link(leaf) != root_port_link)
420 ++ continue;
421 ++ state = pcie_aspm_check_state(leaf->pdev, state);
422 ++ }
423 ++ /* check root port link too in case it hasn't children */
424 ++ state = pcie_aspm_check_state(root_port_link->pdev, state);
425 ++
426 + if (link_state->enabled_state == state)
427 + return;
428 +- __pcie_aspm_config_link(pdev, state);
429 ++
430 ++ /*
431 ++ * we must change the hierarchy. See comments in
432 ++ * __pcie_aspm_config_link for the order
433 ++ **/
434 ++ if (state & PCIE_LINK_STATE_L1) {
435 ++ list_for_each_entry(leaf, &link_list, sibiling) {
436 ++ if (get_root_port_link(leaf) == root_port_link)
437 ++ __pcie_aspm_config_link(leaf->pdev, state);
438 ++ }
439 ++ } else {
440 ++ list_for_each_entry_reverse(leaf, &link_list, sibiling) {
441 ++ if (get_root_port_link(leaf) == root_port_link)
442 ++ __pcie_aspm_config_link(leaf->pdev, state);
443 ++ }
444 ++ }
445 + }
446 +
447 + /*
448 +@@ -570,6 +626,7 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
449 + unsigned int state;
450 + struct pcie_link_state *link_state;
451 + int error = 0;
452 ++ int blacklist;
453 +
454 + if (aspm_disabled || !pdev->is_pcie || pdev->link_state)
455 + return;
456 +@@ -580,29 +637,58 @@ void pcie_aspm_init_link_state(struct pci_dev *pdev)
457 + if (list_empty(&pdev->subordinate->devices))
458 + goto out;
459 +
460 +- if (pcie_aspm_sanity_check(pdev))
461 +- goto out;
462 ++ blacklist = !!pcie_aspm_sanity_check(pdev);
463 +
464 + mutex_lock(&aspm_lock);
465 +
466 + link_state = kzalloc(sizeof(*link_state), GFP_KERNEL);
467 + if (!link_state)
468 + goto unlock_out;
469 +- pdev->link_state = link_state;
470 +
471 +- pcie_aspm_configure_common_clock(pdev);
472 ++ link_state->downstream_has_switch = pcie_aspm_downstream_has_switch(pdev);
473 ++ INIT_LIST_HEAD(&link_state->children);
474 ++ INIT_LIST_HEAD(&link_state->link);
475 ++ if (pdev->bus->self) {/* this is a switch */
476 ++ struct pcie_link_state *parent_link_state;
477 +
478 +- pcie_aspm_cap_init(pdev);
479 ++ parent_link_state = pdev->bus->parent->self->link_state;
480 ++ if (!parent_link_state) {
481 ++ kfree(link_state);
482 ++ goto unlock_out;
483 ++ }
484 ++ list_add(&link_state->link, &parent_link_state->children);
485 ++ link_state->parent = parent_link_state;
486 ++ }
487 +
488 +- /* config link state to avoid BIOS error */
489 +- state = pcie_aspm_check_state(pdev, policy_to_aspm_state(pdev));
490 +- __pcie_aspm_config_link(pdev, state);
491 ++ pdev->link_state = link_state;
492 +
493 +- pcie_check_clock_pm(pdev);
494 ++ if (!blacklist) {
495 ++ pcie_aspm_configure_common_clock(pdev);
496 ++ pcie_aspm_cap_init(pdev);
497 ++ } else {
498 ++ link_state->enabled_state = PCIE_LINK_STATE_L0S|PCIE_LINK_STATE_L1;
499 ++ link_state->bios_aspm_state = 0;
500 ++ /* Set support state to 0, so we will disable ASPM later */
501 ++ link_state->support_state = 0;
502 ++ }
503 +
504 + link_state->pdev = pdev;
505 + list_add(&link_state->sibiling, &link_list);
506 +
507 ++ if (link_state->downstream_has_switch) {
508 ++ /*
509 ++ * If link has switch, delay the link config. The leaf link
510 ++ * initialization will config the whole hierarchy. but we must
511 ++ * make sure BIOS doesn't set unsupported link state
512 ++ **/
513 ++ state = pcie_aspm_check_state(pdev, link_state->bios_aspm_state);
514 ++ __pcie_aspm_config_link(pdev, state);
515 ++ } else
516 ++ __pcie_aspm_configure_link_state(pdev,
517 ++ policy_to_aspm_state(pdev));
518 ++
519 ++ pcie_check_clock_pm(pdev, blacklist);
520 ++
521 + unlock_out:
522 + if (error)
523 + free_link_state(pdev);
524 +@@ -635,6 +721,7 @@ void pcie_aspm_exit_link_state(struct pci_dev *pdev)
525 + /* All functions are removed, so just disable ASPM for the link */
526 + __pcie_aspm_config_one_dev(parent, 0);
527 + list_del(&link_state->sibiling);
528 ++ list_del(&link_state->link);
529 + /* Clock PM is for endpoint device */
530 +
531 + free_link_state(parent);
532 +diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
533 +index 8c08130..7c3710e 100644
534 +--- a/drivers/usb/core/driver.c
535 ++++ b/drivers/usb/core/driver.c
536 +@@ -279,9 +279,12 @@ static int usb_unbind_interface(struct device *dev)
537 + * altsetting means creating new endpoint device entries).
538 + * When either of these happens, defer the Set-Interface.
539 + */
540 +- if (intf->cur_altsetting->desc.bAlternateSetting == 0)
541 +- ; /* Already in altsetting 0 so skip Set-Interface */
542 +- else if (!error && intf->dev.power.status == DPM_ON)
543 ++ if (intf->cur_altsetting->desc.bAlternateSetting == 0) {
544 ++ /* Already in altsetting 0 so skip Set-Interface.
545 ++ * Just re-enable it without affecting the endpoint toggles.
546 ++ */
547 ++ usb_enable_interface(udev, intf, false);
548 ++ } else if (!error && intf->dev.power.status == DPM_ON)
549 + usb_set_interface(udev, intf->altsetting[0].
550 + desc.bInterfaceNumber, 0);
551 + else
552 +diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
553 +index b19cbfc..81eea42 100644
554 +--- a/drivers/usb/core/hub.c
555 ++++ b/drivers/usb/core/hub.c
556 +@@ -2385,7 +2385,7 @@ void usb_ep0_reinit(struct usb_device *udev)
557 + {
558 + usb_disable_endpoint(udev, 0 + USB_DIR_IN);
559 + usb_disable_endpoint(udev, 0 + USB_DIR_OUT);
560 +- usb_enable_endpoint(udev, &udev->ep0);
561 ++ usb_enable_endpoint(udev, &udev->ep0, true);
562 + }
563 + EXPORT_SYMBOL_GPL(usb_ep0_reinit);
564 +
565 +diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
566 +index 6d1048f..bdcfe92 100644
567 +--- a/drivers/usb/core/message.c
568 ++++ b/drivers/usb/core/message.c
569 +@@ -1113,22 +1113,26 @@ void usb_disable_device(struct usb_device *dev, int skip_ep0)
570 + * usb_enable_endpoint - Enable an endpoint for USB communications
571 + * @dev: the device whose interface is being enabled
572 + * @ep: the endpoint
573 ++ * @reset_toggle: flag to set the endpoint's toggle back to 0
574 + *
575 +- * Resets the endpoint toggle, and sets dev->ep_{in,out} pointers.
576 ++ * Resets the endpoint toggle if asked, and sets dev->ep_{in,out} pointers.
577 + * For control endpoints, both the input and output sides are handled.
578 + */
579 +-void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep)
580 ++void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep,
581 ++ bool reset_toggle)
582 + {
583 + int epnum = usb_endpoint_num(&ep->desc);
584 + int is_out = usb_endpoint_dir_out(&ep->desc);
585 + int is_control = usb_endpoint_xfer_control(&ep->desc);
586 +
587 + if (is_out || is_control) {
588 +- usb_settoggle(dev, epnum, 1, 0);
589 ++ if (reset_toggle)
590 ++ usb_settoggle(dev, epnum, 1, 0);
591 + dev->ep_out[epnum] = ep;
592 + }
593 + if (!is_out || is_control) {
594 +- usb_settoggle(dev, epnum, 0, 0);
595 ++ if (reset_toggle)
596 ++ usb_settoggle(dev, epnum, 0, 0);
597 + dev->ep_in[epnum] = ep;
598 + }
599 + ep->enabled = 1;
600 +@@ -1138,17 +1142,18 @@ void usb_enable_endpoint(struct usb_device *dev, struct usb_host_endpoint *ep)
601 + * usb_enable_interface - Enable all the endpoints for an interface
602 + * @dev: the device whose interface is being enabled
603 + * @intf: pointer to the interface descriptor
604 ++ * @reset_toggles: flag to set the endpoints' toggles back to 0
605 + *
606 + * Enables all the endpoints for the interface's current altsetting.
607 + */
608 +-static void usb_enable_interface(struct usb_device *dev,
609 +- struct usb_interface *intf)
610 ++void usb_enable_interface(struct usb_device *dev,
611 ++ struct usb_interface *intf, bool reset_toggles)
612 + {
613 + struct usb_host_interface *alt = intf->cur_altsetting;
614 + int i;
615 +
616 + for (i = 0; i < alt->desc.bNumEndpoints; ++i)
617 +- usb_enable_endpoint(dev, &alt->endpoint[i]);
618 ++ usb_enable_endpoint(dev, &alt->endpoint[i], reset_toggles);
619 + }
620 +
621 + /**
622 +@@ -1271,7 +1276,7 @@ int usb_set_interface(struct usb_device *dev, int interface, int alternate)
623 + * during the SETUP stage - hence EP0 toggles are "don't care" here.
624 + * (Likewise, EP0 never "halts" on well designed devices.)
625 + */
626 +- usb_enable_interface(dev, iface);
627 ++ usb_enable_interface(dev, iface, true);
628 + if (device_is_registered(&iface->dev))
629 + usb_create_sysfs_intf_files(iface);
630 +
631 +@@ -1346,7 +1351,7 @@ int usb_reset_configuration(struct usb_device *dev)
632 + alt = &intf->altsetting[0];
633 +
634 + intf->cur_altsetting = alt;
635 +- usb_enable_interface(dev, intf);
636 ++ usb_enable_interface(dev, intf, true);
637 + if (device_is_registered(&intf->dev))
638 + usb_create_sysfs_intf_files(intf);
639 + }
640 +@@ -1604,7 +1609,7 @@ free_interfaces:
641 + alt = &intf->altsetting[0];
642 +
643 + intf->cur_altsetting = alt;
644 +- usb_enable_interface(dev, intf);
645 ++ usb_enable_interface(dev, intf, true);
646 + intf->dev.parent = &dev->dev;
647 + intf->dev.driver = NULL;
648 + intf->dev.bus = &usb_bus_type;
649 +diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
650 +index be1fa07..956bf1e 100644
651 +--- a/drivers/usb/core/usb.c
652 ++++ b/drivers/usb/core/usb.c
653 +@@ -362,7 +362,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
654 + dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
655 + dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT;
656 + /* ep0 maxpacket comes later, from device descriptor */
657 +- usb_enable_endpoint(dev, &dev->ep0);
658 ++ usb_enable_endpoint(dev, &dev->ep0, true);
659 + dev->can_submit = 1;
660 +
661 + /* Save readable and stable topology id, distinguishing devices
662 +diff --git a/drivers/usb/core/usb.h b/drivers/usb/core/usb.h
663 +index 9a1a45a..1d450e9 100644
664 +--- a/drivers/usb/core/usb.h
665 ++++ b/drivers/usb/core/usb.h
666 +@@ -10,7 +10,9 @@ extern int usb_create_ep_files(struct device *parent,
667 + extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
668 +
669 + extern void usb_enable_endpoint(struct usb_device *dev,
670 +- struct usb_host_endpoint *ep);
671 ++ struct usb_host_endpoint *ep, bool reset_toggle);
672 ++extern void usb_enable_interface(struct usb_device *dev,
673 ++ struct usb_interface *intf, bool reset_toggles);
674 + extern void usb_disable_endpoint(struct usb_device *dev, unsigned int epaddr);
675 + extern void usb_disable_interface(struct usb_device *dev,
676 + struct usb_interface *intf);
677 +diff --git a/drivers/usb/storage/libusual.c b/drivers/usb/storage/libusual.c
678 +index d617e8a..f970b27 100644
679 +--- a/drivers/usb/storage/libusual.c
680 ++++ b/drivers/usb/storage/libusual.c
681 +@@ -46,6 +46,12 @@ static int usu_probe_thread(void *arg);
682 + { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
683 + .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
684 +
685 ++#define COMPLIANT_DEV(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax, \
686 ++ vendorName, productName, useProtocol, useTransport, \
687 ++ initFunction, flags) \
688 ++{ USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin, bcdDeviceMax), \
689 ++ .driver_info = (flags) }
690 ++
691 + #define USUAL_DEV(useProto, useTrans, useType) \
692 + { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
693 + .driver_info = ((useType)<<24) }
694 +@@ -57,6 +63,7 @@ struct usb_device_id storage_usb_ids [] = {
695 +
696 + #undef USUAL_DEV
697 + #undef UNUSUAL_DEV
698 ++#undef COMPLIANT_DEV
699 +
700 + MODULE_DEVICE_TABLE(usb, storage_usb_ids);
701 + EXPORT_SYMBOL_GPL(storage_usb_ids);
702 +diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
703 +index 09779f6..620c2b5 100644
704 +--- a/drivers/usb/storage/scsiglue.c
705 ++++ b/drivers/usb/storage/scsiglue.c
706 +@@ -59,6 +59,13 @@
707 + #include "transport.h"
708 + #include "protocol.h"
709 +
710 ++/* Vendor IDs for companies that seem to include the READ CAPACITY bug
711 ++ * in all their devices
712 ++ */
713 ++#define VENDOR_ID_NOKIA 0x0421
714 ++#define VENDOR_ID_NIKON 0x04b0
715 ++#define VENDOR_ID_MOTOROLA 0x22b8
716 ++
717 + /***********************************************************************
718 + * Host functions
719 + ***********************************************************************/
720 +@@ -134,6 +141,22 @@ static int slave_configure(struct scsi_device *sdev)
721 + * settings can't be overridden via the scsi devinfo mechanism. */
722 + if (sdev->type == TYPE_DISK) {
723 +
724 ++ /* Some vendors seem to put the READ CAPACITY bug into
725 ++ * all their devices -- primarily makers of cell phones
726 ++ * and digital cameras. Since these devices always use
727 ++ * flash media and can be expected to have an even number
728 ++ * of sectors, we will always enable the CAPACITY_HEURISTICS
729 ++ * flag unless told otherwise. */
730 ++ switch (le16_to_cpu(us->pusb_dev->descriptor.idVendor)) {
731 ++ case VENDOR_ID_NOKIA:
732 ++ case VENDOR_ID_NIKON:
733 ++ case VENDOR_ID_MOTOROLA:
734 ++ if (!(us->fflags & (US_FL_FIX_CAPACITY |
735 ++ US_FL_CAPACITY_OK)))
736 ++ us->fflags |= US_FL_CAPACITY_HEURISTICS;
737 ++ break;
738 ++ }
739 ++
740 + /* Disk-type devices use MODE SENSE(6) if the protocol
741 + * (SubClass) is Transparent SCSI, otherwise they use
742 + * MODE SENSE(10). */
743 +@@ -196,6 +219,14 @@ static int slave_configure(struct scsi_device *sdev)
744 + * sector in a larger then 1 sector read, since the performance
745 + * impact is negible we set this flag for all USB disks */
746 + sdev->last_sector_bug = 1;
747 ++
748 ++ /* Enable last-sector hacks for single-target devices using
749 ++ * the Bulk-only transport, unless we already know the
750 ++ * capacity will be decremented or is correct. */
751 ++ if (!(us->fflags & (US_FL_FIX_CAPACITY | US_FL_CAPACITY_OK |
752 ++ US_FL_SCM_MULT_TARG)) &&
753 ++ us->protocol == US_PR_BULK)
754 ++ us->use_last_sector_hacks = 1;
755 + } else {
756 +
757 + /* Non-disk-type devices don't need to blacklist any pages
758 +diff --git a/drivers/usb/storage/transport.c b/drivers/usb/storage/transport.c
759 +index 79108d5..95de764 100644
760 +--- a/drivers/usb/storage/transport.c
761 ++++ b/drivers/usb/storage/transport.c
762 +@@ -57,6 +57,9 @@
763 + #include "scsiglue.h"
764 + #include "debug.h"
765 +
766 ++#include <linux/blkdev.h>
767 ++#include "../../scsi/sd.h"
768 ++
769 +
770 + /***********************************************************************
771 + * Data transfer routines
772 +@@ -511,6 +514,80 @@ int usb_stor_bulk_transfer_sg(struct us_data* us, unsigned int pipe,
773 + * Transport routines
774 + ***********************************************************************/
775 +
776 ++/* There are so many devices that report the capacity incorrectly,
777 ++ * this routine was written to counteract some of the resulting
778 ++ * problems.
779 ++ */
780 ++static void last_sector_hacks(struct us_data *us, struct scsi_cmnd *srb)
781 ++{
782 ++ struct gendisk *disk;
783 ++ struct scsi_disk *sdkp;
784 ++ u32 sector;
785 ++
786 ++ /* To Report "Medium Error: Record Not Found */
787 ++ static unsigned char record_not_found[18] = {
788 ++ [0] = 0x70, /* current error */
789 ++ [2] = MEDIUM_ERROR, /* = 0x03 */
790 ++ [7] = 0x0a, /* additional length */
791 ++ [12] = 0x14 /* Record Not Found */
792 ++ };
793 ++
794 ++ /* If last-sector problems can't occur, whether because the
795 ++ * capacity was already decremented or because the device is
796 ++ * known to report the correct capacity, then we don't need
797 ++ * to do anything.
798 ++ */
799 ++ if (!us->use_last_sector_hacks)
800 ++ return;
801 ++
802 ++ /* Was this command a READ(10) or a WRITE(10)? */
803 ++ if (srb->cmnd[0] != READ_10 && srb->cmnd[0] != WRITE_10)
804 ++ goto done;
805 ++
806 ++ /* Did this command access the last sector? */
807 ++ sector = (srb->cmnd[2] << 24) | (srb->cmnd[3] << 16) |
808 ++ (srb->cmnd[4] << 8) | (srb->cmnd[5]);
809 ++ disk = srb->request->rq_disk;
810 ++ if (!disk)
811 ++ goto done;
812 ++ sdkp = scsi_disk(disk);
813 ++ if (!sdkp)
814 ++ goto done;
815 ++ if (sector + 1 != sdkp->capacity)
816 ++ goto done;
817 ++
818 ++ if (srb->result == SAM_STAT_GOOD && scsi_get_resid(srb) == 0) {
819 ++
820 ++ /* The command succeeded. We know this device doesn't
821 ++ * have the last-sector bug, so stop checking it.
822 ++ */
823 ++ us->use_last_sector_hacks = 0;
824 ++
825 ++ } else {
826 ++ /* The command failed. Allow up to 3 retries in case this
827 ++ * is some normal sort of failure. After that, assume the
828 ++ * capacity is wrong and we're trying to access the sector
829 ++ * beyond the end. Replace the result code and sense data
830 ++ * with values that will cause the SCSI core to fail the
831 ++ * command immediately, instead of going into an infinite
832 ++ * (or even just a very long) retry loop.
833 ++ */
834 ++ if (++us->last_sector_retries < 3)
835 ++ return;
836 ++ srb->result = SAM_STAT_CHECK_CONDITION;
837 ++ memcpy(srb->sense_buffer, record_not_found,
838 ++ sizeof(record_not_found));
839 ++ }
840 ++
841 ++ done:
842 ++ /* Don't reset the retry counter for TEST UNIT READY commands,
843 ++ * because they get issued after device resets which might be
844 ++ * caused by a failed last-sector access.
845 ++ */
846 ++ if (srb->cmnd[0] != TEST_UNIT_READY)
847 ++ us->last_sector_retries = 0;
848 ++}
849 ++
850 + /* Invoke the transport and basic error-handling/recovery methods
851 + *
852 + * This is used by the protocol layers to actually send the message to
853 +@@ -544,6 +621,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
854 + /* if the transport provided its own sense data, don't auto-sense */
855 + if (result == USB_STOR_TRANSPORT_NO_SENSE) {
856 + srb->result = SAM_STAT_CHECK_CONDITION;
857 ++ last_sector_hacks(us, srb);
858 + return;
859 + }
860 +
861 +@@ -667,6 +745,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
862 + scsi_bufflen(srb) - scsi_get_resid(srb) < srb->underflow)
863 + srb->result = (DID_ERROR << 16) | (SUGGEST_RETRY << 24);
864 +
865 ++ last_sector_hacks(us, srb);
866 + return;
867 +
868 + /* Error and abort processing: try to resynchronize with the device
869 +@@ -694,6 +773,7 @@ void usb_stor_invoke_transport(struct scsi_cmnd *srb, struct us_data *us)
870 + us->transport_reset(us);
871 + }
872 + clear_bit(US_FLIDX_RESETTING, &us->dflags);
873 ++ last_sector_hacks(us, srb);
874 + }
875 +
876 + /* Stop the current URB transfer */
877 +diff --git a/drivers/usb/storage/unusual_devs.h b/drivers/usb/storage/unusual_devs.h
878 +index a078540..ce7f746 100644
879 +--- a/drivers/usb/storage/unusual_devs.h
880 ++++ b/drivers/usb/storage/unusual_devs.h
881 +@@ -27,7 +27,8 @@
882 +
883 + /* IMPORTANT NOTE: This file must be included in another file which does
884 + * the following thing for it to work:
885 +- * The macro UNUSUAL_DEV() must be defined before this file is included
886 ++ * The UNUSUAL_DEV, COMPLIANT_DEV, and USUAL_DEV macros must be defined
887 ++ * before this file is included.
888 + */
889 +
890 + /* If you edit this file, please try to keep it sorted first by VendorID,
891 +@@ -46,6 +47,12 @@
892 + * <usb-storage@××××××××××××××××××××.net>
893 + */
894 +
895 ++/* Note: If you add an entry only in order to set the CAPACITY_OK flag,
896 ++ * use the COMPLIANT_DEV macro instead of UNUSUAL_DEV. This is
897 ++ * because such entries mark devices which actually work correctly,
898 ++ * as opposed to devices that do something strangely or wrongly.
899 ++ */
900 ++
901 + /* patch submitted by Vivian Bregier <Vivian.Bregier@××××.fr>
902 + */
903 + UNUSUAL_DEV( 0x03eb, 0x2002, 0x0100, 0x0100,
904 +@@ -160,34 +167,6 @@ UNUSUAL_DEV( 0x0421, 0x0019, 0x0592, 0x0592,
905 + US_SC_DEVICE, US_PR_DEVICE, NULL,
906 + US_FL_MAX_SECTORS_64 ),
907 +
908 +-/* Reported by Filip Joelsson <filip@××××××××××.nu> */
909 +-UNUSUAL_DEV( 0x0421, 0x005d, 0x0001, 0x0600,
910 +- "Nokia",
911 +- "Nokia 3110c",
912 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
913 +- US_FL_FIX_CAPACITY ),
914 +-
915 +-/* Reported by Ozan Sener <themgzzy@×××××.com> */
916 +-UNUSUAL_DEV( 0x0421, 0x0060, 0x0551, 0x0551,
917 +- "Nokia",
918 +- "3500c",
919 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
920 +- US_FL_FIX_CAPACITY ),
921 +-
922 +-/* Reported by CSECSY Laszlo <boobaa@××××××××××.org> */
923 +-UNUSUAL_DEV( 0x0421, 0x0063, 0x0001, 0x0601,
924 +- "Nokia",
925 +- "Nokia 3109c",
926 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
927 +- US_FL_FIX_CAPACITY ),
928 +-
929 +-/* Patch for Nokia 5310 capacity */
930 +-UNUSUAL_DEV( 0x0421, 0x006a, 0x0000, 0x0701,
931 +- "Nokia",
932 +- "5310",
933 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
934 +- US_FL_FIX_CAPACITY ),
935 +-
936 + /* Reported by Mario Rettig <mariorettig@×××.de> */
937 + UNUSUAL_DEV( 0x0421, 0x042e, 0x0100, 0x0100,
938 + "Nokia",
939 +@@ -253,42 +232,6 @@ UNUSUAL_DEV( 0x0421, 0x0495, 0x0370, 0x0370,
940 + US_SC_DEVICE, US_PR_DEVICE, NULL,
941 + US_FL_MAX_SECTORS_64 ),
942 +
943 +-/* Reported by Cedric Godin <cedric@×××××××.be> */
944 +-UNUSUAL_DEV( 0x0421, 0x04b9, 0x0500, 0x0551,
945 +- "Nokia",
946 +- "5300",
947 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
948 +- US_FL_FIX_CAPACITY ),
949 +-
950 +-/* Reported by Paulo Fessel <pfessel@×××××.com> */
951 +-UNUSUAL_DEV( 0x0421, 0x04bd, 0x0000, 0x9999,
952 +- "Nokia",
953 +- "5200",
954 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
955 +- US_FL_FIX_CAPACITY ),
956 +-
957 +-/* Reported by Richard Nauber <RichardNauber@×××.de> */
958 +-UNUSUAL_DEV( 0x0421, 0x04fa, 0x0550, 0x0660,
959 +- "Nokia",
960 +- "6300",
961 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
962 +- US_FL_FIX_CAPACITY ),
963 +-
964 +-/* Patch for Nokia 5310 capacity */
965 +-UNUSUAL_DEV( 0x0421, 0x006a, 0x0000, 0x0591,
966 +- "Nokia",
967 +- "5310",
968 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
969 +- US_FL_FIX_CAPACITY ),
970 +-
971 +-/* Submitted by Ricky Wong Yung Fei <evilbladewarrior@×××××.com> */
972 +-/* Nokia 7610 Supernova - Too many sectors reported in usb storage mode */
973 +-UNUSUAL_DEV( 0x0421, 0x00f5, 0x0000, 0x0470,
974 +- "Nokia",
975 +- "7610 Supernova",
976 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
977 +- US_FL_FIX_CAPACITY ),
978 +-
979 + /* Reported by Olaf Hering <olh@××××.de> from novell bug #105878 */
980 + UNUSUAL_DEV( 0x0424, 0x0fdc, 0x0210, 0x0210,
981 + "SMSC",
982 +@@ -403,83 +346,6 @@ UNUSUAL_DEV( 0x04b0, 0x0301, 0x0010, 0x0010,
983 + US_SC_DEVICE, US_PR_DEVICE,NULL,
984 + US_FL_NOT_LOCKABLE ),
985 +
986 +-/* Reported by Stefan de Konink <skinkie@××××××.nl> */
987 +-UNUSUAL_DEV( 0x04b0, 0x0401, 0x0200, 0x0200,
988 +- "NIKON",
989 +- "NIKON DSC D100",
990 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
991 +- US_FL_FIX_CAPACITY),
992 +-
993 +-/* Reported by Tobias Kunze Briseno <t-linux@×××××××.com> */
994 +-UNUSUAL_DEV( 0x04b0, 0x0403, 0x0200, 0x0200,
995 +- "NIKON",
996 +- "NIKON DSC D2H",
997 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
998 +- US_FL_FIX_CAPACITY),
999 +-
1000 +-/* Reported by Milinevsky Dmitry <niam.niam@×××××.com> */
1001 +-UNUSUAL_DEV( 0x04b0, 0x0409, 0x0100, 0x0100,
1002 +- "NIKON",
1003 +- "NIKON DSC D50",
1004 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1005 +- US_FL_FIX_CAPACITY),
1006 +-
1007 +-/* Reported by Andreas Bockhold <andreas@×××××××××××.de> */
1008 +-UNUSUAL_DEV( 0x04b0, 0x0405, 0x0100, 0x0100,
1009 +- "NIKON",
1010 +- "NIKON DSC D70",
1011 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1012 +- US_FL_FIX_CAPACITY),
1013 +-
1014 +-/* Reported by Jamie Kitson <jamie@×××××××××××××××××××.uk> */
1015 +-UNUSUAL_DEV( 0x04b0, 0x040d, 0x0100, 0x0100,
1016 +- "NIKON",
1017 +- "NIKON DSC D70s",
1018 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1019 +- US_FL_FIX_CAPACITY),
1020 +-
1021 +-/* Reported by Graber and Mike Pagano <mpagano-kernel@×××××××.com> */
1022 +-UNUSUAL_DEV( 0x04b0, 0x040f, 0x0100, 0x0200,
1023 +- "NIKON",
1024 +- "NIKON DSC D200",
1025 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1026 +- US_FL_FIX_CAPACITY),
1027 +-
1028 +-/* Reported by Emil Larsson <emil@××××.net> */
1029 +-UNUSUAL_DEV( 0x04b0, 0x0411, 0x0100, 0x0111,
1030 +- "NIKON",
1031 +- "NIKON DSC D80",
1032 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1033 +- US_FL_FIX_CAPACITY),
1034 +-
1035 +-/* Reported by Ortwin Glueck <odi@×××.ch> */
1036 +-UNUSUAL_DEV( 0x04b0, 0x0413, 0x0110, 0x0111,
1037 +- "NIKON",
1038 +- "NIKON DSC D40",
1039 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1040 +- US_FL_FIX_CAPACITY),
1041 +-
1042 +-/* Reported by Paul Check <paul@××××××××××.com> */
1043 +-UNUSUAL_DEV( 0x04b0, 0x0415, 0x0100, 0x0100,
1044 +- "NIKON",
1045 +- "NIKON DSC D2Xs",
1046 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1047 +- US_FL_FIX_CAPACITY),
1048 +-
1049 +-/* Reported by Shan Destromp (shansan@×××××.com) */
1050 +-UNUSUAL_DEV( 0x04b0, 0x0417, 0x0100, 0x0100,
1051 +- "NIKON",
1052 +- "NIKON DSC D40X",
1053 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1054 +- US_FL_FIX_CAPACITY),
1055 +-
1056 +-/* Reported by paul ready <lxtwin@×××××××××××.uk> */
1057 +-UNUSUAL_DEV( 0x04b0, 0x0419, 0x0100, 0x0200,
1058 +- "NIKON",
1059 +- "NIKON DSC D300",
1060 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1061 +- US_FL_FIX_CAPACITY),
1062 +-
1063 + /* Reported by Doug Maxey (dwm@××××××××××.com) */
1064 + UNUSUAL_DEV( 0x04b3, 0x4001, 0x0110, 0x0110,
1065 + "IBM",
1066 +@@ -692,6 +558,13 @@ UNUSUAL_DEV( 0x0525, 0xa140, 0x0100, 0x0100,
1067 + US_SC_8070, US_PR_DEVICE, NULL,
1068 + US_FL_FIX_INQUIRY ),
1069 +
1070 ++/* Added by Alan Stern <stern@×××××××××××××××.edu> */
1071 ++COMPLIANT_DEV(0x0525, 0xa4a5, 0x0000, 0x9999,
1072 ++ "Linux",
1073 ++ "File-backed Storage Gadget",
1074 ++ US_SC_DEVICE, US_PR_DEVICE, NULL,
1075 ++ US_FL_CAPACITY_OK ),
1076 ++
1077 + /* Yakumo Mega Image 37
1078 + * Submitted by Stephan Fuhrmann <atomenergie@××××××××.de> */
1079 + UNUSUAL_DEV( 0x052b, 0x1801, 0x0100, 0x0100,
1080 +@@ -2107,27 +1980,6 @@ UNUSUAL_DEV( 0x22b8, 0x3010, 0x0001, 0x0001,
1081 + US_FL_FIX_CAPACITY | US_FL_IGNORE_RESIDUE ),
1082 +
1083 + /*
1084 +- * Patch by Pete Zaitcev <zaitcev@××××××.com>
1085 +- * Report by Mark Patton. Red Hat bz#208928.
1086 +- * Added support for rev 0x0002 (Motorola ROKR W5)
1087 +- * by Javier Smaldone <javier@××××××××××××.ar>
1088 +- */
1089 +-UNUSUAL_DEV( 0x22b8, 0x4810, 0x0001, 0x0002,
1090 +- "Motorola",
1091 +- "RAZR V3i/ROKR W5",
1092 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1093 +- US_FL_FIX_CAPACITY),
1094 +-
1095 +-/*
1096 +- * Patch by Jost Diederichs <jost@×××××.com>
1097 +- */
1098 +-UNUSUAL_DEV(0x22b8, 0x6410, 0x0001, 0x9999,
1099 +- "Motorola Inc.",
1100 +- "Motorola Phone (RAZRV3xx)",
1101 +- US_SC_DEVICE, US_PR_DEVICE, NULL,
1102 +- US_FL_FIX_CAPACITY),
1103 +-
1104 +-/*
1105 + * Patch by Constantin Baranov <const@×××××.ru>
1106 + * Report by Andreas Koenecke.
1107 + * Motorola ROKR Z6.
1108 +diff --git a/drivers/usb/storage/usb.c b/drivers/usb/storage/usb.c
1109 +index 27016fd..ceb8ac3 100644
1110 +--- a/drivers/usb/storage/usb.c
1111 ++++ b/drivers/usb/storage/usb.c
1112 +@@ -126,6 +126,8 @@ MODULE_PARM_DESC(delay_use, "seconds to delay before using a new device");
1113 + { USB_DEVICE_VER(id_vendor, id_product, bcdDeviceMin,bcdDeviceMax), \
1114 + .driver_info = (flags)|(USB_US_TYPE_STOR<<24) }
1115 +
1116 ++#define COMPLIANT_DEV UNUSUAL_DEV
1117 ++
1118 + #define USUAL_DEV(useProto, useTrans, useType) \
1119 + { USB_INTERFACE_INFO(USB_CLASS_MASS_STORAGE, useProto, useTrans), \
1120 + .driver_info = (USB_US_TYPE_STOR<<24) }
1121 +@@ -134,6 +136,7 @@ static struct usb_device_id storage_usb_ids [] = {
1122 +
1123 + # include "unusual_devs.h"
1124 + #undef UNUSUAL_DEV
1125 ++#undef COMPLIANT_DEV
1126 + #undef USUAL_DEV
1127 + /* Terminating entry */
1128 + { }
1129 +@@ -164,6 +167,8 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids);
1130 + .initFunction = init_function, \
1131 + }
1132 +
1133 ++#define COMPLIANT_DEV UNUSUAL_DEV
1134 ++
1135 + #define USUAL_DEV(use_protocol, use_transport, use_type) \
1136 + { \
1137 + .useProtocol = use_protocol, \
1138 +@@ -173,6 +178,7 @@ MODULE_DEVICE_TABLE (usb, storage_usb_ids);
1139 + static struct us_unusual_dev us_unusual_dev_list[] = {
1140 + # include "unusual_devs.h"
1141 + # undef UNUSUAL_DEV
1142 ++# undef COMPLIANT_DEV
1143 + # undef USUAL_DEV
1144 +
1145 + /* Terminating entry */
1146 +diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
1147 +index a4ad73b..2e995c9 100644
1148 +--- a/drivers/usb/storage/usb.h
1149 ++++ b/drivers/usb/storage/usb.h
1150 +@@ -155,6 +155,10 @@ struct us_data {
1151 + #ifdef CONFIG_PM
1152 + pm_hook suspend_resume_hook;
1153 + #endif
1154 ++
1155 ++ /* hacks for READ CAPACITY bug handling */
1156 ++ int use_last_sector_hacks;
1157 ++ int last_sector_retries;
1158 + };
1159 +
1160 + /* Convert between us_data and the corresponding Scsi_Host */
1161 +diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c
1162 +index d0ff0b8..e5eaa62 100644
1163 +--- a/fs/fs-writeback.c
1164 ++++ b/fs/fs-writeback.c
1165 +@@ -421,9 +421,6 @@ __writeback_single_inode(struct inode *inode, struct writeback_control *wbc)
1166 + * If we're a pdlfush thread, then implement pdflush collision avoidance
1167 + * against the entire list.
1168 + *
1169 +- * WB_SYNC_HOLD is a hack for sys_sync(): reattach the inode to sb->s_dirty so
1170 +- * that it can be located for waiting on in __writeback_single_inode().
1171 +- *
1172 + * If `bdi' is non-zero then we're being asked to writeback a specific queue.
1173 + * This function assumes that the blockdev superblock's inodes are backed by
1174 + * a variety of queues, so all inodes are searched. For other superblocks,
1175 +@@ -443,6 +440,7 @@ void generic_sync_sb_inodes(struct super_block *sb,
1176 + struct writeback_control *wbc)
1177 + {
1178 + const unsigned long start = jiffies; /* livelock avoidance */
1179 ++ int sync = wbc->sync_mode == WB_SYNC_ALL;
1180 +
1181 + spin_lock(&inode_lock);
1182 + if (!wbc->for_kupdate || list_empty(&sb->s_io))
1183 +@@ -499,10 +497,6 @@ void generic_sync_sb_inodes(struct super_block *sb,
1184 + __iget(inode);
1185 + pages_skipped = wbc->pages_skipped;
1186 + __writeback_single_inode(inode, wbc);
1187 +- if (wbc->sync_mode == WB_SYNC_HOLD) {
1188 +- inode->dirtied_when = jiffies;
1189 +- list_move(&inode->i_list, &sb->s_dirty);
1190 +- }
1191 + if (current_is_pdflush())
1192 + writeback_release(bdi);
1193 + if (wbc->pages_skipped != pages_skipped) {
1194 +@@ -523,7 +517,49 @@ void generic_sync_sb_inodes(struct super_block *sb,
1195 + if (!list_empty(&sb->s_more_io))
1196 + wbc->more_io = 1;
1197 + }
1198 +- spin_unlock(&inode_lock);
1199 ++
1200 ++ if (sync) {
1201 ++ struct inode *inode, *old_inode = NULL;
1202 ++
1203 ++ /*
1204 ++ * Data integrity sync. Must wait for all pages under writeback,
1205 ++ * because there may have been pages dirtied before our sync
1206 ++ * call, but which had writeout started before we write it out.
1207 ++ * In which case, the inode may not be on the dirty list, but
1208 ++ * we still have to wait for that writeout.
1209 ++ */
1210 ++ list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
1211 ++ struct address_space *mapping;
1212 ++
1213 ++ if (inode->i_state & (I_FREEING|I_WILL_FREE))
1214 ++ continue;
1215 ++ mapping = inode->i_mapping;
1216 ++ if (mapping->nrpages == 0)
1217 ++ continue;
1218 ++ __iget(inode);
1219 ++ spin_unlock(&inode_lock);
1220 ++ /*
1221 ++ * We hold a reference to 'inode' so it couldn't have
1222 ++ * been removed from s_inodes list while we dropped the
1223 ++ * inode_lock. We cannot iput the inode now as we can
1224 ++ * be holding the last reference and we cannot iput it
1225 ++ * under inode_lock. So we keep the reference and iput
1226 ++ * it later.
1227 ++ */
1228 ++ iput(old_inode);
1229 ++ old_inode = inode;
1230 ++
1231 ++ filemap_fdatawait(mapping);
1232 ++
1233 ++ cond_resched();
1234 ++
1235 ++ spin_lock(&inode_lock);
1236 ++ }
1237 ++ spin_unlock(&inode_lock);
1238 ++ iput(old_inode);
1239 ++ } else
1240 ++ spin_unlock(&inode_lock);
1241 ++
1242 + return; /* Leave any unwritten inodes on s_io */
1243 + }
1244 + EXPORT_SYMBOL_GPL(generic_sync_sb_inodes);
1245 +@@ -588,8 +624,7 @@ restart:
1246 +
1247 + /*
1248 + * writeback and wait upon the filesystem's dirty inodes. The caller will
1249 +- * do this in two passes - one to write, and one to wait. WB_SYNC_HOLD is
1250 +- * used to park the written inodes on sb->s_dirty for the wait pass.
1251 ++ * do this in two passes - one to write, and one to wait.
1252 + *
1253 + * A finite limit is set on the number of pages which will be written.
1254 + * To prevent infinite livelock of sys_sync().
1255 +@@ -600,30 +635,21 @@ restart:
1256 + void sync_inodes_sb(struct super_block *sb, int wait)
1257 + {
1258 + struct writeback_control wbc = {
1259 +- .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_HOLD,
1260 ++ .sync_mode = wait ? WB_SYNC_ALL : WB_SYNC_NONE,
1261 + .range_start = 0,
1262 + .range_end = LLONG_MAX,
1263 + };
1264 +- unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY);
1265 +- unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS);
1266 +
1267 +- wbc.nr_to_write = nr_dirty + nr_unstable +
1268 +- (inodes_stat.nr_inodes - inodes_stat.nr_unused) +
1269 +- nr_dirty + nr_unstable;
1270 +- wbc.nr_to_write += wbc.nr_to_write / 2; /* Bit more for luck */
1271 +- sync_sb_inodes(sb, &wbc);
1272 +-}
1273 ++ if (!wait) {
1274 ++ unsigned long nr_dirty = global_page_state(NR_FILE_DIRTY);
1275 ++ unsigned long nr_unstable = global_page_state(NR_UNSTABLE_NFS);
1276 +
1277 +-/*
1278 +- * Rather lame livelock avoidance.
1279 +- */
1280 +-static void set_sb_syncing(int val)
1281 +-{
1282 +- struct super_block *sb;
1283 +- spin_lock(&sb_lock);
1284 +- list_for_each_entry_reverse(sb, &super_blocks, s_list)
1285 +- sb->s_syncing = val;
1286 +- spin_unlock(&sb_lock);
1287 ++ wbc.nr_to_write = nr_dirty + nr_unstable +
1288 ++ (inodes_stat.nr_inodes - inodes_stat.nr_unused);
1289 ++ } else
1290 ++ wbc.nr_to_write = LONG_MAX; /* doesn't actually matter */
1291 ++
1292 ++ sync_sb_inodes(sb, &wbc);
1293 + }
1294 +
1295 + /**
1296 +@@ -652,9 +678,6 @@ static void __sync_inodes(int wait)
1297 + spin_lock(&sb_lock);
1298 + restart:
1299 + list_for_each_entry(sb, &super_blocks, s_list) {
1300 +- if (sb->s_syncing)
1301 +- continue;
1302 +- sb->s_syncing = 1;
1303 + sb->s_count++;
1304 + spin_unlock(&sb_lock);
1305 + down_read(&sb->s_umount);
1306 +@@ -672,13 +695,10 @@ restart:
1307 +
1308 + void sync_inodes(int wait)
1309 + {
1310 +- set_sb_syncing(0);
1311 + __sync_inodes(0);
1312 +
1313 +- if (wait) {
1314 +- set_sb_syncing(0);
1315 ++ if (wait)
1316 + __sync_inodes(1);
1317 +- }
1318 + }
1319 +
1320 + /**
1321 +diff --git a/fs/sync.c b/fs/sync.c
1322 +index 6cc8cb4..9e5f60d 100644
1323 +--- a/fs/sync.c
1324 ++++ b/fs/sync.c
1325 +@@ -287,7 +287,7 @@ int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
1326 +
1327 + if (flags & SYNC_FILE_RANGE_WRITE) {
1328 + ret = __filemap_fdatawrite_range(mapping, offset, endbyte,
1329 +- WB_SYNC_NONE);
1330 ++ WB_SYNC_ALL);
1331 + if (ret < 0)
1332 + goto out;
1333 + }
1334 +diff --git a/include/linux/fs.h b/include/linux/fs.h
1335 +index efeff3d..4b91924 100644
1336 +--- a/include/linux/fs.h
1337 ++++ b/include/linux/fs.h
1338 +@@ -1124,7 +1124,6 @@ struct super_block {
1339 + struct rw_semaphore s_umount;
1340 + struct mutex s_lock;
1341 + int s_count;
1342 +- int s_syncing;
1343 + int s_need_sync_fs;
1344 + atomic_t s_active;
1345 + #ifdef CONFIG_SECURITY
1346 +diff --git a/include/linux/usb_usual.h b/include/linux/usb_usual.h
1347 +index d9a3bbe..bd414ec 100644
1348 +--- a/include/linux/usb_usual.h
1349 ++++ b/include/linux/usb_usual.h
1350 +@@ -52,8 +52,9 @@
1351 + US_FLAG(MAX_SECTORS_MIN,0x00002000) \
1352 + /* Sets max_sectors to arch min */ \
1353 + US_FLAG(BULK_IGNORE_TAG,0x00004000) \
1354 +- /* Ignore tag mismatch in bulk operations */
1355 +-
1356 ++ /* Ignore tag mismatch in bulk operations */ \
1357 ++ US_FLAG(CAPACITY_OK, 0x00010000) \
1358 ++ /* READ CAPACITY response is correct */
1359 +
1360 + #define US_FLAG(name, value) US_FL_##name = value ,
1361 + enum { US_DO_ALL_FLAGS };
1362 +diff --git a/include/linux/writeback.h b/include/linux/writeback.h
1363 +index e585657..b93ab38 100644
1364 +--- a/include/linux/writeback.h
1365 ++++ b/include/linux/writeback.h
1366 +@@ -30,7 +30,6 @@ static inline int task_is_pdflush(struct task_struct *task)
1367 + enum writeback_sync_modes {
1368 + WB_SYNC_NONE, /* Don't wait on anything */
1369 + WB_SYNC_ALL, /* Wait on every mapping */
1370 +- WB_SYNC_HOLD, /* Hold the inode on sb_dirty for sys_sync() */
1371 + };
1372 +
1373 + /*
1374 +diff --git a/kernel/sched_fair.c b/kernel/sched_fair.c
1375 +index 98345e4..06a68c4 100644
1376 +--- a/kernel/sched_fair.c
1377 ++++ b/kernel/sched_fair.c
1378 +@@ -283,7 +283,7 @@ static void update_min_vruntime(struct cfs_rq *cfs_rq)
1379 + struct sched_entity,
1380 + run_node);
1381 +
1382 +- if (vruntime == cfs_rq->min_vruntime)
1383 ++ if (!cfs_rq->curr)
1384 + vruntime = se->vruntime;
1385 + else
1386 + vruntime = min_vruntime(vruntime, se->vruntime);
1387 +diff --git a/lib/idr.c b/lib/idr.c
1388 +index 1c4f928..21154ae 100644
1389 +--- a/lib/idr.c
1390 ++++ b/lib/idr.c
1391 +@@ -121,7 +121,7 @@ int idr_pre_get(struct idr *idp, gfp_t gfp_mask)
1392 + {
1393 + while (idp->id_free_cnt < IDR_FREE_MAX) {
1394 + struct idr_layer *new;
1395 +- new = kmem_cache_alloc(idr_layer_cache, gfp_mask);
1396 ++ new = kmem_cache_zalloc(idr_layer_cache, gfp_mask);
1397 + if (new == NULL)
1398 + return (0);
1399 + move_to_free_list(idp, new);
1400 +@@ -623,16 +623,10 @@ void *idr_replace(struct idr *idp, void *ptr, int id)
1401 + }
1402 + EXPORT_SYMBOL(idr_replace);
1403 +
1404 +-static void idr_cache_ctor(void *idr_layer)
1405 +-{
1406 +- memset(idr_layer, 0, sizeof(struct idr_layer));
1407 +-}
1408 +-
1409 + void __init idr_init_cache(void)
1410 + {
1411 + idr_layer_cache = kmem_cache_create("idr_layer_cache",
1412 +- sizeof(struct idr_layer), 0, SLAB_PANIC,
1413 +- idr_cache_ctor);
1414 ++ sizeof(struct idr_layer), 0, SLAB_PANIC, NULL);
1415 + }
1416 +
1417 + /**
1418 +diff --git a/mm/filemap.c b/mm/filemap.c
1419 +index f65417c..6f62ef9 100644
1420 +--- a/mm/filemap.c
1421 ++++ b/mm/filemap.c
1422 +@@ -210,7 +210,7 @@ int __filemap_fdatawrite_range(struct address_space *mapping, loff_t start,
1423 + int ret;
1424 + struct writeback_control wbc = {
1425 + .sync_mode = sync_mode,
1426 +- .nr_to_write = mapping->nrpages * 2,
1427 ++ .nr_to_write = LONG_MAX,
1428 + .range_start = start,
1429 + .range_end = end,
1430 + };
1431 +@@ -1317,7 +1317,8 @@ generic_file_aio_read(struct kiocb *iocb, const struct iovec *iov,
1432 + goto out; /* skip atime */
1433 + size = i_size_read(inode);
1434 + if (pos < size) {
1435 +- retval = filemap_write_and_wait(mapping);
1436 ++ retval = filemap_write_and_wait_range(mapping, pos,
1437 ++ pos + iov_length(iov, nr_segs) - 1);
1438 + if (!retval) {
1439 + retval = mapping->a_ops->direct_IO(READ, iocb,
1440 + iov, pos, nr_segs);
1441 +@@ -2067,18 +2068,10 @@ generic_file_direct_write(struct kiocb *iocb, const struct iovec *iov,
1442 + if (count != ocount)
1443 + *nr_segs = iov_shorten((struct iovec *)iov, *nr_segs, count);
1444 +
1445 +- /*
1446 +- * Unmap all mmappings of the file up-front.
1447 +- *
1448 +- * This will cause any pte dirty bits to be propagated into the
1449 +- * pageframes for the subsequent filemap_write_and_wait().
1450 +- */
1451 + write_len = iov_length(iov, *nr_segs);
1452 + end = (pos + write_len - 1) >> PAGE_CACHE_SHIFT;
1453 +- if (mapping_mapped(mapping))
1454 +- unmap_mapping_range(mapping, pos, write_len, 0);
1455 +
1456 +- written = filemap_write_and_wait(mapping);
1457 ++ written = filemap_write_and_wait_range(mapping, pos, pos + write_len - 1);
1458 + if (written)
1459 + goto out;
1460 +
1461 +@@ -2298,7 +2291,8 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov,
1462 + * the file data here, to try to honour O_DIRECT expectations.
1463 + */
1464 + if (unlikely(file->f_flags & O_DIRECT) && written)
1465 +- status = filemap_write_and_wait(mapping);
1466 ++ status = filemap_write_and_wait_range(mapping,
1467 ++ pos, pos + written - 1);
1468 +
1469 + return written ? written : status;
1470 + }
1471 +diff --git a/mm/page-writeback.c b/mm/page-writeback.c
1472 +index 2970e35..08d2b96 100644
1473 +--- a/mm/page-writeback.c
1474 ++++ b/mm/page-writeback.c
1475 +@@ -868,9 +868,11 @@ int write_cache_pages(struct address_space *mapping,
1476 + int done = 0;
1477 + struct pagevec pvec;
1478 + int nr_pages;
1479 ++ pgoff_t uninitialized_var(writeback_index);
1480 + pgoff_t index;
1481 + pgoff_t end; /* Inclusive */
1482 +- int scanned = 0;
1483 ++ pgoff_t done_index;
1484 ++ int cycled;
1485 + int range_whole = 0;
1486 + long nr_to_write = wbc->nr_to_write;
1487 +
1488 +@@ -881,83 +883,134 @@ int write_cache_pages(struct address_space *mapping,
1489 +
1490 + pagevec_init(&pvec, 0);
1491 + if (wbc->range_cyclic) {
1492 +- index = mapping->writeback_index; /* Start from prev offset */
1493 ++ writeback_index = mapping->writeback_index; /* prev offset */
1494 ++ index = writeback_index;
1495 ++ if (index == 0)
1496 ++ cycled = 1;
1497 ++ else
1498 ++ cycled = 0;
1499 + end = -1;
1500 + } else {
1501 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
1502 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
1503 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
1504 + range_whole = 1;
1505 +- scanned = 1;
1506 ++ cycled = 1; /* ignore range_cyclic tests */
1507 + }
1508 + retry:
1509 +- while (!done && (index <= end) &&
1510 +- (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
1511 +- PAGECACHE_TAG_DIRTY,
1512 +- min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) {
1513 +- unsigned i;
1514 ++ done_index = index;
1515 ++ while (!done && (index <= end)) {
1516 ++ int i;
1517 ++
1518 ++ nr_pages = pagevec_lookup_tag(&pvec, mapping, &index,
1519 ++ PAGECACHE_TAG_DIRTY,
1520 ++ min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1);
1521 ++ if (nr_pages == 0)
1522 ++ break;
1523 +
1524 +- scanned = 1;
1525 + for (i = 0; i < nr_pages; i++) {
1526 + struct page *page = pvec.pages[i];
1527 +
1528 + /*
1529 +- * At this point we hold neither mapping->tree_lock nor
1530 +- * lock on the page itself: the page may be truncated or
1531 +- * invalidated (changing page->mapping to NULL), or even
1532 +- * swizzled back from swapper_space to tmpfs file
1533 +- * mapping
1534 ++ * At this point, the page may be truncated or
1535 ++ * invalidated (changing page->mapping to NULL), or
1536 ++ * even swizzled back from swapper_space to tmpfs file
1537 ++ * mapping. However, page->index will not change
1538 ++ * because we have a reference on the page.
1539 + */
1540 ++ if (page->index > end) {
1541 ++ /*
1542 ++ * can't be range_cyclic (1st pass) because
1543 ++ * end == -1 in that case.
1544 ++ */
1545 ++ done = 1;
1546 ++ break;
1547 ++ }
1548 ++
1549 ++ done_index = page->index + 1;
1550 ++
1551 + lock_page(page);
1552 +
1553 ++ /*
1554 ++ * Page truncated or invalidated. We can freely skip it
1555 ++ * then, even for data integrity operations: the page
1556 ++ * has disappeared concurrently, so there could be no
1557 ++ * real expectation of this data interity operation
1558 ++ * even if there is now a new, dirty page at the same
1559 ++ * pagecache address.
1560 ++ */
1561 + if (unlikely(page->mapping != mapping)) {
1562 ++continue_unlock:
1563 + unlock_page(page);
1564 + continue;
1565 + }
1566 +
1567 +- if (!wbc->range_cyclic && page->index > end) {
1568 +- done = 1;
1569 +- unlock_page(page);
1570 +- continue;
1571 ++ if (!PageDirty(page)) {
1572 ++ /* someone wrote it for us */
1573 ++ goto continue_unlock;
1574 + }
1575 +
1576 +- if (wbc->sync_mode != WB_SYNC_NONE)
1577 +- wait_on_page_writeback(page);
1578 +-
1579 +- if (PageWriteback(page) ||
1580 +- !clear_page_dirty_for_io(page)) {
1581 +- unlock_page(page);
1582 +- continue;
1583 ++ if (PageWriteback(page)) {
1584 ++ if (wbc->sync_mode != WB_SYNC_NONE)
1585 ++ wait_on_page_writeback(page);
1586 ++ else
1587 ++ goto continue_unlock;
1588 + }
1589 +
1590 +- ret = (*writepage)(page, wbc, data);
1591 ++ BUG_ON(PageWriteback(page));
1592 ++ if (!clear_page_dirty_for_io(page))
1593 ++ goto continue_unlock;
1594 +
1595 +- if (unlikely(ret == AOP_WRITEPAGE_ACTIVATE)) {
1596 +- unlock_page(page);
1597 +- ret = 0;
1598 ++ ret = (*writepage)(page, wbc, data);
1599 ++ if (unlikely(ret)) {
1600 ++ if (ret == AOP_WRITEPAGE_ACTIVATE) {
1601 ++ unlock_page(page);
1602 ++ ret = 0;
1603 ++ } else {
1604 ++ /*
1605 ++ * done_index is set past this page,
1606 ++ * so media errors will not choke
1607 ++ * background writeout for the entire
1608 ++ * file. This has consequences for
1609 ++ * range_cyclic semantics (ie. it may
1610 ++ * not be suitable for data integrity
1611 ++ * writeout).
1612 ++ */
1613 ++ done = 1;
1614 ++ break;
1615 ++ }
1616 ++ }
1617 ++
1618 ++ if (wbc->sync_mode == WB_SYNC_NONE) {
1619 ++ wbc->nr_to_write--;
1620 ++ if (wbc->nr_to_write <= 0) {
1621 ++ done = 1;
1622 ++ break;
1623 ++ }
1624 + }
1625 +- if (ret || (--nr_to_write <= 0))
1626 +- done = 1;
1627 + if (wbc->nonblocking && bdi_write_congested(bdi)) {
1628 + wbc->encountered_congestion = 1;
1629 + done = 1;
1630 ++ break;
1631 + }
1632 + }
1633 + pagevec_release(&pvec);
1634 + cond_resched();
1635 + }
1636 +- if (!scanned && !done) {
1637 ++ if (!cycled) {
1638 + /*
1639 ++ * range_cyclic:
1640 + * We hit the last page and there is more work to be done: wrap
1641 + * back to the start of the file
1642 + */
1643 +- scanned = 1;
1644 ++ cycled = 1;
1645 + index = 0;
1646 ++ end = writeback_index - 1;
1647 + goto retry;
1648 + }
1649 + if (!wbc->no_nrwrite_index_update) {
1650 + if (wbc->range_cyclic || (range_whole && nr_to_write > 0))
1651 +- mapping->writeback_index = index;
1652 ++ mapping->writeback_index = done_index;
1653 + wbc->nr_to_write = nr_to_write;
1654 + }
1655 +
1656 +diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
1657 +index 0fa208e..05f198d 100644
1658 +--- a/net/bridge/netfilter/ebtables.c
1659 ++++ b/net/bridge/netfilter/ebtables.c
1660 +@@ -80,7 +80,7 @@ static inline int ebt_do_match (struct ebt_entry_match *m,
1661 + {
1662 + par->match = m->u.match;
1663 + par->matchinfo = m->data;
1664 +- return m->u.match->match(skb, par);
1665 ++ return m->u.match->match(skb, par) ? EBT_MATCH : EBT_NOMATCH;
1666 + }
1667 +
1668 + static inline int ebt_dev_check(char *entry, const struct net_device *device)
1669 +diff --git a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
1670 +index 4e88792..625707a 100644
1671 +--- a/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
1672 ++++ b/net/ipv4/netfilter/nf_conntrack_proto_icmp.c
1673 +@@ -20,7 +20,7 @@
1674 + #include <net/netfilter/nf_conntrack_core.h>
1675 + #include <net/netfilter/nf_log.h>
1676 +
1677 +-static unsigned long nf_ct_icmp_timeout __read_mostly = 30*HZ;
1678 ++static unsigned int nf_ct_icmp_timeout __read_mostly = 30*HZ;
1679 +
1680 + static bool icmp_pkt_to_tuple(const struct sk_buff *skb, unsigned int dataoff,
1681 + struct nf_conntrack_tuple *tuple)
1682 +diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
1683 +index c5aca0b..9e31f91 100644
1684 +--- a/net/ipv4/tcp.c
1685 ++++ b/net/ipv4/tcp.c
1686 +@@ -578,10 +578,6 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
1687 + else if (!ret) {
1688 + if (spliced)
1689 + break;
1690 +- if (flags & SPLICE_F_NONBLOCK) {
1691 +- ret = -EAGAIN;
1692 +- break;
1693 +- }
1694 + if (sock_flag(sk, SOCK_DONE))
1695 + break;
1696 + if (sk->sk_err) {
1697 +@@ -599,6 +595,10 @@ ssize_t tcp_splice_read(struct socket *sock, loff_t *ppos,
1698 + ret = -ENOTCONN;
1699 + break;
1700 + }
1701 ++ if (flags & SPLICE_F_NONBLOCK) {
1702 ++ ret = -EAGAIN;
1703 ++ break;
1704 ++ }
1705 + if (!timeo) {
1706 + ret = -EAGAIN;
1707 + break;
1708 +diff --git a/net/ipv6/ip6_fib.c b/net/ipv6/ip6_fib.c
1709 +index 29c7c99..52ee1dc 100644
1710 +--- a/net/ipv6/ip6_fib.c
1711 ++++ b/net/ipv6/ip6_fib.c
1712 +@@ -298,6 +298,10 @@ static void fib6_dump_end(struct netlink_callback *cb)
1713 + struct fib6_walker_t *w = (void*)cb->args[2];
1714 +
1715 + if (w) {
1716 ++ if (cb->args[4]) {
1717 ++ cb->args[4] = 0;
1718 ++ fib6_walker_unlink(w);
1719 ++ }
1720 + cb->args[2] = 0;
1721 + kfree(w);
1722 + }
1723 +@@ -330,15 +334,12 @@ static int fib6_dump_table(struct fib6_table *table, struct sk_buff *skb,
1724 + read_lock_bh(&table->tb6_lock);
1725 + res = fib6_walk_continue(w);
1726 + read_unlock_bh(&table->tb6_lock);
1727 +- if (res != 0) {
1728 +- if (res < 0)
1729 +- fib6_walker_unlink(w);
1730 +- goto end;
1731 ++ if (res <= 0) {
1732 ++ fib6_walker_unlink(w);
1733 ++ cb->args[4] = 0;
1734 + }
1735 +- fib6_walker_unlink(w);
1736 +- cb->args[4] = 0;
1737 + }
1738 +-end:
1739 ++
1740 + return res;
1741 + }
1742 +
1743 +diff --git a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
1744 +index 0572617..7cd13e5 100644
1745 +--- a/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
1746 ++++ b/net/ipv6/netfilter/nf_conntrack_proto_icmpv6.c
1747 +@@ -26,7 +26,7 @@
1748 + #include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
1749 + #include <net/netfilter/nf_log.h>
1750 +
1751 +-static unsigned long nf_ct_icmpv6_timeout __read_mostly = 30*HZ;
1752 ++static unsigned int nf_ct_icmpv6_timeout __read_mostly = 30*HZ;
1753 +
1754 + static bool icmpv6_pkt_to_tuple(const struct sk_buff *skb,
1755 + unsigned int dataoff,
1756 +diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
1757 +index 89837a4..bfbf521 100644
1758 +--- a/net/netfilter/x_tables.c
1759 ++++ b/net/netfilter/x_tables.c
1760 +@@ -273,6 +273,10 @@ static int match_revfn(u8 af, const char *name, u8 revision, int *bestp)
1761 + have_rev = 1;
1762 + }
1763 + }
1764 ++
1765 ++ if (af != NFPROTO_UNSPEC && !have_rev)
1766 ++ return match_revfn(NFPROTO_UNSPEC, name, revision, bestp);
1767 ++
1768 + return have_rev;
1769 + }
1770 +
1771 +@@ -289,6 +293,10 @@ static int target_revfn(u8 af, const char *name, u8 revision, int *bestp)
1772 + have_rev = 1;
1773 + }
1774 + }
1775 ++
1776 ++ if (af != NFPROTO_UNSPEC && !have_rev)
1777 ++ return target_revfn(NFPROTO_UNSPEC, name, revision, bestp);
1778 ++
1779 + return have_rev;
1780 + }
1781 +
1782 +diff --git a/net/sched/cls_u32.c b/net/sched/cls_u32.c
1783 +index 246f906..ea51fcd 100644
1784 +--- a/net/sched/cls_u32.c
1785 ++++ b/net/sched/cls_u32.c
1786 +@@ -637,8 +637,9 @@ static int u32_change(struct tcf_proto *tp, unsigned long base, u32 handle,
1787 + break;
1788 +
1789 + n->next = *ins;
1790 +- wmb();
1791 ++ tcf_tree_lock(tp);
1792 + *ins = n;
1793 ++ tcf_tree_unlock(tp);
1794 +
1795 + *arg = (unsigned long)n;
1796 + return 0;
1797 +diff --git a/net/sched/sch_htb.c b/net/sched/sch_htb.c
1798 +index d14f020..d2943a4 100644
1799 +--- a/net/sched/sch_htb.c
1800 ++++ b/net/sched/sch_htb.c
1801 +@@ -924,6 +924,7 @@ static struct sk_buff *htb_dequeue(struct Qdisc *sch)
1802 + }
1803 + }
1804 + sch->qstats.overlimits++;
1805 ++ qdisc_watchdog_cancel(&q->watchdog);
1806 + qdisc_watchdog_schedule(&q->watchdog, next_event);
1807 + fin:
1808 + return skb;
1809 +diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c
1810 +index a6a0ea7..679fcde 100644
1811 +--- a/net/sctp/sm_statefuns.c
1812 ++++ b/net/sctp/sm_statefuns.c
1813 +@@ -3691,6 +3691,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
1814 + {
1815 + struct sctp_chunk *chunk = arg;
1816 + struct sctp_fwdtsn_hdr *fwdtsn_hdr;
1817 ++ struct sctp_fwdtsn_skip *skip;
1818 + __u16 len;
1819 + __u32 tsn;
1820 +
1821 +@@ -3720,6 +3721,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn(const struct sctp_endpoint *ep,
1822 + if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
1823 + goto discard_noforce;
1824 +
1825 ++ /* Silently discard the chunk if stream-id is not valid */
1826 ++ sctp_walk_fwdtsn(skip, chunk) {
1827 ++ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
1828 ++ goto discard_noforce;
1829 ++ }
1830 ++
1831 + sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
1832 + if (len > sizeof(struct sctp_fwdtsn_hdr))
1833 + sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
1834 +@@ -3751,6 +3758,7 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
1835 + {
1836 + struct sctp_chunk *chunk = arg;
1837 + struct sctp_fwdtsn_hdr *fwdtsn_hdr;
1838 ++ struct sctp_fwdtsn_skip *skip;
1839 + __u16 len;
1840 + __u32 tsn;
1841 +
1842 +@@ -3780,6 +3788,12 @@ sctp_disposition_t sctp_sf_eat_fwd_tsn_fast(
1843 + if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
1844 + goto gen_shutdown;
1845 +
1846 ++ /* Silently discard the chunk if stream-id is not valid */
1847 ++ sctp_walk_fwdtsn(skip, chunk) {
1848 ++ if (ntohs(skip->stream) >= asoc->c.sinit_max_instreams)
1849 ++ goto gen_shutdown;
1850 ++ }
1851 ++
1852 + sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
1853 + if (len > sizeof(struct sctp_fwdtsn_hdr))
1854 + sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
1855 +diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
1856 +index 9b4e0e9..3c0f421 100644
1857 +--- a/security/keys/keyctl.c
1858 ++++ b/security/keys/keyctl.c
1859 +@@ -270,6 +270,7 @@ long keyctl_join_session_keyring(const char __user *_name)
1860 +
1861 + /* join the session */
1862 + ret = join_session_keyring(name);
1863 ++ kfree(name);
1864 +
1865 + error:
1866 + return ret;
1867 +diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
1868 +index 2dc976d..87bade3 100644
1869 +--- a/sound/pci/hda/patch_analog.c
1870 ++++ b/sound/pci/hda/patch_analog.c
1871 +@@ -629,6 +629,36 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
1872 + HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
1873 + HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
1874 + HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
1875 ++ HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
1876 ++ HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
1877 ++ HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1878 ++ HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1879 ++ HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
1880 ++ HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
1881 ++ HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
1882 ++ {
1883 ++ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1884 ++ .name = "Capture Source",
1885 ++ .info = ad198x_mux_enum_info,
1886 ++ .get = ad198x_mux_enum_get,
1887 ++ .put = ad198x_mux_enum_put,
1888 ++ },
1889 ++ {
1890 ++ .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1891 ++ .name = "External Amplifier",
1892 ++ .info = ad198x_eapd_info,
1893 ++ .get = ad198x_eapd_get,
1894 ++ .put = ad198x_eapd_put,
1895 ++ .private_value = 0x1b | (1 << 8), /* port-D, inversed */
1896 ++ },
1897 ++ { } /* end */
1898 ++};
1899 ++
1900 ++static struct snd_kcontrol_new ad1986a_samsung_mixers[] = {
1901 ++ HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
1902 ++ HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
1903 ++ HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
1904 ++ HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
1905 + HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
1906 + HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
1907 + HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
1908 +@@ -917,6 +947,7 @@ enum {
1909 + AD1986A_LAPTOP_EAPD,
1910 + AD1986A_LAPTOP_AUTOMUTE,
1911 + AD1986A_ULTRA,
1912 ++ AD1986A_SAMSUNG,
1913 + AD1986A_MODELS
1914 + };
1915 +
1916 +@@ -927,6 +958,7 @@ static const char *ad1986a_models[AD1986A_MODELS] = {
1917 + [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
1918 + [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
1919 + [AD1986A_ULTRA] = "ultra",
1920 ++ [AD1986A_SAMSUNG] = "samsung",
1921 + };
1922 +
1923 + static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1924 +@@ -949,9 +981,9 @@ static struct snd_pci_quirk ad1986a_cfg_tbl[] = {
1925 + SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba", AD1986A_LAPTOP_EAPD),
1926 + SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
1927 + SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
1928 +- SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_LAPTOP_EAPD),
1929 +- SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_LAPTOP_EAPD),
1930 +- SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_LAPTOP_EAPD),
1931 ++ SND_PCI_QUIRK(0x144d, 0xc023, "Samsung X60", AD1986A_SAMSUNG),
1932 ++ SND_PCI_QUIRK(0x144d, 0xc024, "Samsung R65", AD1986A_SAMSUNG),
1933 ++ SND_PCI_QUIRK(0x144d, 0xc026, "Samsung X11", AD1986A_SAMSUNG),
1934 + SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
1935 + SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
1936 + SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
1937 +@@ -1033,6 +1065,17 @@ static int patch_ad1986a(struct hda_codec *codec)
1938 + break;
1939 + case AD1986A_LAPTOP_EAPD:
1940 + spec->mixers[0] = ad1986a_laptop_eapd_mixers;
1941 ++ spec->num_init_verbs = 2;
1942 ++ spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1943 ++ spec->multiout.max_channels = 2;
1944 ++ spec->multiout.num_dacs = 1;
1945 ++ spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
1946 ++ if (!is_jack_available(codec, 0x25))
1947 ++ spec->multiout.dig_out_nid = 0;
1948 ++ spec->input_mux = &ad1986a_laptop_eapd_capture_source;
1949 ++ break;
1950 ++ case AD1986A_SAMSUNG:
1951 ++ spec->mixers[0] = ad1986a_samsung_mixers;
1952 + spec->num_init_verbs = 3;
1953 + spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1954 + spec->init_verbs[2] = ad1986a_automic_verbs;
1955 +diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
1956 +index a378c01..befb699 100644
1957 +--- a/sound/pci/hda/patch_realtek.c
1958 ++++ b/sound/pci/hda/patch_realtek.c
1959 +@@ -10473,6 +10473,7 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
1960 + SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
1961 + SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
1962 + SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
1963 ++ SND_PCI_QUIRK(0x144d, 0xc510, "Samsung Q45", ALC262_HIPPO),
1964 + SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
1965 + SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
1966 + SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
1967 +diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
1968 +index 24ff2b8..8b204b8 100644
1969 +--- a/sound/pci/hda/patch_sigmatel.c
1970 ++++ b/sound/pci/hda/patch_sigmatel.c
1971 +@@ -89,6 +89,7 @@ enum {
1972 + STAC_DELL_M4_2,
1973 + STAC_DELL_M4_3,
1974 + STAC_HP_M4,
1975 ++ STAC_HP_DV5,
1976 + STAC_92HD71BXX_MODELS
1977 + };
1978 +
1979 +@@ -1702,6 +1703,7 @@ static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1980 + [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1981 + [STAC_DELL_M4_3] = dell_m4_3_pin_configs,
1982 + [STAC_HP_M4] = NULL,
1983 ++ [STAC_HP_DV5] = NULL,
1984 + };
1985 +
1986 + static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1987 +@@ -1710,6 +1712,7 @@ static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1988 + [STAC_DELL_M4_2] = "dell-m4-2",
1989 + [STAC_DELL_M4_3] = "dell-m4-3",
1990 + [STAC_HP_M4] = "hp-m4",
1991 ++ [STAC_HP_DV5] = "hp-dv5",
1992 + };
1993 +
1994 + static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1995 +@@ -1722,6 +1725,8 @@ static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1996 + "HP dv7", STAC_HP_M4),
1997 + SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x30fc,
1998 + "HP dv7", STAC_HP_M4),
1999 ++ SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3603,
2000 ++ "HP dv5", STAC_HP_DV5),
2001 + SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x361a,
2002 + "unknown HP", STAC_HP_M4),
2003 + SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
2004 +@@ -3980,8 +3985,19 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
2005 + continue;
2006 + if (presence)
2007 + stac92xx_set_pinctl(codec, cfg->hp_pins[i], val);
2008 ++#if 0 /* FIXME */
2009 ++/* Resetting the pinctl like below may lead to (a sort of) regressions
2010 ++ * on some devices since they use the HP pin actually for line/speaker
2011 ++ * outs although the default pin config shows a different pin (that is
2012 ++ * wrong and useless).
2013 ++ *
2014 ++ * So, it's basically a problem of default pin configs, likely a BIOS issue.
2015 ++ * But, disabling the code below just works around it, and I'm too tired of
2016 ++ * bug reports with such devices...
2017 ++ */
2018 + else
2019 + stac92xx_reset_pinctl(codec, cfg->hp_pins[i], val);
2020 ++#endif /* FIXME */
2021 + }
2022 + }
2023 +
2024 +diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
2025 +index 98c6a8c..e9e829e 100644
2026 +--- a/sound/pci/oxygen/virtuoso.c
2027 ++++ b/sound/pci/oxygen/virtuoso.c
2028 +@@ -26,7 +26,7 @@
2029 + * SPI 0 -> 1st PCM1796 (front)
2030 + * SPI 1 -> 2nd PCM1796 (surround)
2031 + * SPI 2 -> 3rd PCM1796 (center/LFE)
2032 +- * SPI 4 -> 4th PCM1796 (back)
2033 ++ * SPI 4 -> 4th PCM1796 (back) and EEPROM self-destruct (do not use!)
2034 + *
2035 + * GPIO 2 -> M0 of CS5381
2036 + * GPIO 3 -> M1 of CS5381
2037 +@@ -207,6 +207,12 @@ static void xonar_gpio_changed(struct oxygen *chip);
2038 + static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
2039 + u8 reg, u8 value)
2040 + {
2041 ++ /*
2042 ++ * We don't want to do writes on SPI 4 because the EEPROM, which shares
2043 ++ * the same pin, might get confused and broken. We'd better take care
2044 ++ * that the driver works with the default register values ...
2045 ++ */
2046 ++#if 0
2047 + /* maps ALSA channel pair number to SPI output */
2048 + static const u8 codec_map[4] = {
2049 + 0, 1, 2, 4
2050 +@@ -217,6 +223,7 @@ static inline void pcm1796_write_spi(struct oxygen *chip, unsigned int codec,
2051 + (codec_map[codec] << OXYGEN_SPI_CODEC_SHIFT) |
2052 + OXYGEN_SPI_CEN_LATCH_CLOCK_HI,
2053 + (reg << 8) | value);
2054 ++#endif
2055 + }
2056 +
2057 + static inline void pcm1796_write_i2c(struct oxygen *chip, unsigned int codec,
2058 +@@ -750,6 +757,9 @@ static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -12700, 100, 0);
2059 +
2060 + static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
2061 + {
2062 ++ if (!strncmp(template->name, "Master Playback ", 16))
2063 ++ /* disable volume/mute because they would require SPI writes */
2064 ++ return 1;
2065 + if (!strncmp(template->name, "CD Capture ", 11))
2066 + /* CD in is actually connected to the video in pin */
2067 + template->private_value ^= AC97_CD ^ AC97_VIDEO;
2068 +@@ -840,9 +850,8 @@ static const struct oxygen_model model_xonar_d2 = {
2069 + .dac_volume_min = 0x0f,
2070 + .dac_volume_max = 0xff,
2071 + .misc_flags = OXYGEN_MISC_MIDI,
2072 +- .function_flags = OXYGEN_FUNCTION_SPI |
2073 +- OXYGEN_FUNCTION_ENABLE_SPI_4_5,
2074 +- .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
2075 ++ .function_flags = OXYGEN_FUNCTION_SPI,
2076 ++ .dac_i2s_format = OXYGEN_I2S_FORMAT_I2S,
2077 + .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
2078 + };
2079 +
2080
2081 Added: hardened/2.6/tags/2.6.28-1/4420_grsec-2.1.12-2.6.28-200901161810.patch
2082 ===================================================================
2083 --- hardened/2.6/tags/2.6.28-1/4420_grsec-2.1.12-2.6.28-200901161810.patch (rev 0)
2084 +++ hardened/2.6/tags/2.6.28-1/4420_grsec-2.1.12-2.6.28-200901161810.patch 2009-01-25 09:03:04 UTC (rev 1486)
2085 @@ -0,0 +1,37139 @@
2086 +diff -urNp linux-2.6.28/arch/alpha/include/asm/elf.h linux-2.6.28/arch/alpha/include/asm/elf.h
2087 +--- linux-2.6.28/arch/alpha/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
2088 ++++ linux-2.6.28/arch/alpha/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
2089 +@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2090 +
2091 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
2092 +
2093 ++#ifdef CONFIG_PAX_ASLR
2094 ++#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
2095 ++
2096 ++#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
2097 ++#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
2098 ++#endif
2099 ++
2100 + /* $0 is set by ld.so to a pointer to a function which might be
2101 + registered using atexit. This provides a mean for the dynamic
2102 + linker to call DT_FINI functions for shared libraries that have
2103 +diff -urNp linux-2.6.28/arch/alpha/include/asm/kmap_types.h linux-2.6.28/arch/alpha/include/asm/kmap_types.h
2104 +--- linux-2.6.28/arch/alpha/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2105 ++++ linux-2.6.28/arch/alpha/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2106 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
2107 + D(10) KM_IRQ1,
2108 + D(11) KM_SOFTIRQ0,
2109 + D(12) KM_SOFTIRQ1,
2110 +-D(13) KM_TYPE_NR
2111 ++D(13) KM_CLEARPAGE,
2112 ++D(14) KM_TYPE_NR
2113 + };
2114 +
2115 + #undef D
2116 +diff -urNp linux-2.6.28/arch/alpha/include/asm/pgtable.h linux-2.6.28/arch/alpha/include/asm/pgtable.h
2117 +--- linux-2.6.28/arch/alpha/include/asm/pgtable.h 2008-12-24 18:26:37.000000000 -0500
2118 ++++ linux-2.6.28/arch/alpha/include/asm/pgtable.h 2009-01-11 07:20:06.000000000 -0500
2119 +@@ -101,6 +101,17 @@ struct vm_area_struct;
2120 + #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
2121 + #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
2122 + #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
2123 ++
2124 ++#ifdef CONFIG_PAX_PAGEEXEC
2125 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
2126 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
2127 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
2128 ++#else
2129 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
2130 ++# define PAGE_COPY_NOEXEC PAGE_COPY
2131 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
2132 ++#endif
2133 ++
2134 + #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
2135 +
2136 + #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
2137 +diff -urNp linux-2.6.28/arch/alpha/kernel/module.c linux-2.6.28/arch/alpha/kernel/module.c
2138 +--- linux-2.6.28/arch/alpha/kernel/module.c 2008-12-24 18:26:37.000000000 -0500
2139 ++++ linux-2.6.28/arch/alpha/kernel/module.c 2009-01-11 07:20:06.000000000 -0500
2140 +@@ -182,7 +182,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs,
2141 +
2142 + /* The small sections were sorted to the end of the segment.
2143 + The following should definitely cover them. */
2144 +- gp = (u64)me->module_core + me->core_size - 0x8000;
2145 ++ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
2146 + got = sechdrs[me->arch.gotsecindex].sh_addr;
2147 +
2148 + for (i = 0; i < n; i++) {
2149 +diff -urNp linux-2.6.28/arch/alpha/kernel/osf_sys.c linux-2.6.28/arch/alpha/kernel/osf_sys.c
2150 +--- linux-2.6.28/arch/alpha/kernel/osf_sys.c 2008-12-24 18:26:37.000000000 -0500
2151 ++++ linux-2.6.28/arch/alpha/kernel/osf_sys.c 2009-01-11 07:20:06.000000000 -0500
2152 +@@ -1230,6 +1230,10 @@ arch_get_unmapped_area(struct file *filp
2153 + merely specific addresses, but regions of memory -- perhaps
2154 + this feature should be incorporated into all ports? */
2155 +
2156 ++#ifdef CONFIG_PAX_RANDMMAP
2157 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2158 ++#endif
2159 ++
2160 + if (addr) {
2161 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
2162 + if (addr != (unsigned long) -ENOMEM)
2163 +@@ -1237,8 +1241,8 @@ arch_get_unmapped_area(struct file *filp
2164 + }
2165 +
2166 + /* Next, try allocating at TASK_UNMAPPED_BASE. */
2167 +- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
2168 +- len, limit);
2169 ++ addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
2170 ++
2171 + if (addr != (unsigned long) -ENOMEM)
2172 + return addr;
2173 +
2174 +diff -urNp linux-2.6.28/arch/alpha/kernel/ptrace.c linux-2.6.28/arch/alpha/kernel/ptrace.c
2175 +--- linux-2.6.28/arch/alpha/kernel/ptrace.c 2008-12-24 18:26:37.000000000 -0500
2176 ++++ linux-2.6.28/arch/alpha/kernel/ptrace.c 2009-01-11 05:46:58.000000000 -0500
2177 +@@ -15,6 +15,7 @@
2178 + #include <linux/slab.h>
2179 + #include <linux/security.h>
2180 + #include <linux/signal.h>
2181 ++#include <linux/grsecurity.h>
2182 +
2183 + #include <asm/uaccess.h>
2184 + #include <asm/pgtable.h>
2185 +@@ -266,6 +267,9 @@ long arch_ptrace(struct task_struct *chi
2186 + size_t copied;
2187 + long ret;
2188 +
2189 ++ if (gr_handle_ptrace(child, request))
2190 ++ return -EPERM;
2191 ++
2192 + switch (request) {
2193 + /* When I and D space are separate, these will need to be fixed. */
2194 + case PTRACE_PEEKTEXT: /* read word at location addr. */
2195 +diff -urNp linux-2.6.28/arch/alpha/mm/fault.c linux-2.6.28/arch/alpha/mm/fault.c
2196 +--- linux-2.6.28/arch/alpha/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
2197 ++++ linux-2.6.28/arch/alpha/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
2198 +@@ -54,6 +54,124 @@ __load_new_mm_context(struct mm_struct *
2199 + __reload_thread(pcb);
2200 + }
2201 +
2202 ++#ifdef CONFIG_PAX_PAGEEXEC
2203 ++/*
2204 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
2205 ++ *
2206 ++ * returns 1 when task should be killed
2207 ++ * 2 when patched PLT trampoline was detected
2208 ++ * 3 when unpatched PLT trampoline was detected
2209 ++ */
2210 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
2211 ++{
2212 ++
2213 ++#ifdef CONFIG_PAX_EMUPLT
2214 ++ int err;
2215 ++
2216 ++ do { /* PaX: patched PLT emulation #1 */
2217 ++ unsigned int ldah, ldq, jmp;
2218 ++
2219 ++ err = get_user(ldah, (unsigned int *)regs->pc);
2220 ++ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
2221 ++ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
2222 ++
2223 ++ if (err)
2224 ++ break;
2225 ++
2226 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
2227 ++ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
2228 ++ jmp == 0x6BFB0000U)
2229 ++ {
2230 ++ unsigned long r27, addr;
2231 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
2232 ++ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
2233 ++
2234 ++ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
2235 ++ err = get_user(r27, (unsigned long *)addr);
2236 ++ if (err)
2237 ++ break;
2238 ++
2239 ++ regs->r27 = r27;
2240 ++ regs->pc = r27;
2241 ++ return 2;
2242 ++ }
2243 ++ } while (0);
2244 ++
2245 ++ do { /* PaX: patched PLT emulation #2 */
2246 ++ unsigned int ldah, lda, br;
2247 ++
2248 ++ err = get_user(ldah, (unsigned int *)regs->pc);
2249 ++ err |= get_user(lda, (unsigned int *)(regs->pc+4));
2250 ++ err |= get_user(br, (unsigned int *)(regs->pc+8));
2251 ++
2252 ++ if (err)
2253 ++ break;
2254 ++
2255 ++ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
2256 ++ (lda & 0xFFFF0000U) == 0xA77B0000U &&
2257 ++ (br & 0xFFE00000U) == 0xC3E00000U)
2258 ++ {
2259 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
2260 ++ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
2261 ++ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
2262 ++
2263 ++ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
2264 ++ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
2265 ++ return 2;
2266 ++ }
2267 ++ } while (0);
2268 ++
2269 ++ do { /* PaX: unpatched PLT emulation */
2270 ++ unsigned int br;
2271 ++
2272 ++ err = get_user(br, (unsigned int *)regs->pc);
2273 ++
2274 ++ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
2275 ++ unsigned int br2, ldq, nop, jmp;
2276 ++ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
2277 ++
2278 ++ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
2279 ++ err = get_user(br2, (unsigned int *)addr);
2280 ++ err |= get_user(ldq, (unsigned int *)(addr+4));
2281 ++ err |= get_user(nop, (unsigned int *)(addr+8));
2282 ++ err |= get_user(jmp, (unsigned int *)(addr+12));
2283 ++ err |= get_user(resolver, (unsigned long *)(addr+16));
2284 ++
2285 ++ if (err)
2286 ++ break;
2287 ++
2288 ++ if (br2 == 0xC3600000U &&
2289 ++ ldq == 0xA77B000CU &&
2290 ++ nop == 0x47FF041FU &&
2291 ++ jmp == 0x6B7B0000U)
2292 ++ {
2293 ++ regs->r28 = regs->pc+4;
2294 ++ regs->r27 = addr+16;
2295 ++ regs->pc = resolver;
2296 ++ return 3;
2297 ++ }
2298 ++ }
2299 ++ } while (0);
2300 ++#endif
2301 ++
2302 ++ return 1;
2303 ++}
2304 ++
2305 ++void pax_report_insns(void *pc, void *sp)
2306 ++{
2307 ++ unsigned long i;
2308 ++
2309 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2310 ++ for (i = 0; i < 5; i++) {
2311 ++ unsigned int c;
2312 ++ if (get_user(c, (unsigned int *)pc+i))
2313 ++ printk(KERN_CONT "???????? ");
2314 ++ else
2315 ++ printk(KERN_CONT "%08x ", c);
2316 ++ }
2317 ++ printk("\n");
2318 ++}
2319 ++#endif
2320 +
2321 + /*
2322 + * This routine handles page faults. It determines the address,
2323 +@@ -131,8 +249,29 @@ do_page_fault(unsigned long address, uns
2324 + good_area:
2325 + si_code = SEGV_ACCERR;
2326 + if (cause < 0) {
2327 +- if (!(vma->vm_flags & VM_EXEC))
2328 ++ if (!(vma->vm_flags & VM_EXEC)) {
2329 ++
2330 ++#ifdef CONFIG_PAX_PAGEEXEC
2331 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
2332 ++ goto bad_area;
2333 ++
2334 ++ up_read(&mm->mmap_sem);
2335 ++ switch (pax_handle_fetch_fault(regs)) {
2336 ++
2337 ++#ifdef CONFIG_PAX_EMUPLT
2338 ++ case 2:
2339 ++ case 3:
2340 ++ return;
2341 ++#endif
2342 ++
2343 ++ }
2344 ++ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
2345 ++ do_group_exit(SIGKILL);
2346 ++#else
2347 + goto bad_area;
2348 ++#endif
2349 ++
2350 ++ }
2351 + } else if (!cause) {
2352 + /* Allow reads even for write-only mappings */
2353 + if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
2354 +diff -urNp linux-2.6.28/arch/arm/include/asm/elf.h linux-2.6.28/arch/arm/include/asm/elf.h
2355 +--- linux-2.6.28/arch/arm/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
2356 ++++ linux-2.6.28/arch/arm/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
2357 +@@ -99,7 +99,14 @@ extern int arm_elf_read_implies_exec(con
2358 + the loader. We need to make sure that it is out of the way of the program
2359 + that it will "exec", and that there is sufficient room for the brk. */
2360 +
2361 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2362 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2363 ++
2364 ++#ifdef CONFIG_PAX_ASLR
2365 ++#define PAX_ELF_ET_DYN_BASE 0x00008000UL
2366 ++
2367 ++#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2368 ++#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
2369 ++#endif
2370 +
2371 + /* When the program starts, a1 contains a pointer to a function to be
2372 + registered with atexit, as per the SVR4 ABI. A value of 0 means we
2373 +diff -urNp linux-2.6.28/arch/arm/include/asm/kmap_types.h linux-2.6.28/arch/arm/include/asm/kmap_types.h
2374 +--- linux-2.6.28/arch/arm/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2375 ++++ linux-2.6.28/arch/arm/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2376 +@@ -18,6 +18,7 @@ enum km_type {
2377 + KM_IRQ1,
2378 + KM_SOFTIRQ0,
2379 + KM_SOFTIRQ1,
2380 ++ KM_CLEARPAGE,
2381 + KM_TYPE_NR
2382 + };
2383 +
2384 +diff -urNp linux-2.6.28/arch/arm/mm/mmap.c linux-2.6.28/arch/arm/mm/mmap.c
2385 +--- linux-2.6.28/arch/arm/mm/mmap.c 2008-12-24 18:26:37.000000000 -0500
2386 ++++ linux-2.6.28/arch/arm/mm/mmap.c 2009-01-11 07:20:06.000000000 -0500
2387 +@@ -62,6 +62,10 @@ arch_get_unmapped_area(struct file *filp
2388 + if (len > TASK_SIZE)
2389 + return -ENOMEM;
2390 +
2391 ++#ifdef CONFIG_PAX_RANDMMAP
2392 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
2393 ++#endif
2394 ++
2395 + if (addr) {
2396 + if (do_align)
2397 + addr = COLOUR_ALIGN(addr, pgoff);
2398 +@@ -74,10 +78,10 @@ arch_get_unmapped_area(struct file *filp
2399 + return addr;
2400 + }
2401 + if (len > mm->cached_hole_size) {
2402 +- start_addr = addr = mm->free_area_cache;
2403 ++ start_addr = addr = mm->free_area_cache;
2404 + } else {
2405 +- start_addr = addr = TASK_UNMAPPED_BASE;
2406 +- mm->cached_hole_size = 0;
2407 ++ start_addr = addr = mm->mmap_base;
2408 ++ mm->cached_hole_size = 0;
2409 + }
2410 +
2411 + full_search:
2412 +@@ -93,8 +97,8 @@ full_search:
2413 + * Start a new search - just in case we missed
2414 + * some holes.
2415 + */
2416 +- if (start_addr != TASK_UNMAPPED_BASE) {
2417 +- start_addr = addr = TASK_UNMAPPED_BASE;
2418 ++ if (start_addr != mm->mmap_base) {
2419 ++ start_addr = addr = mm->mmap_base;
2420 + mm->cached_hole_size = 0;
2421 + goto full_search;
2422 + }
2423 +diff -urNp linux-2.6.28/arch/avr32/include/asm/elf.h linux-2.6.28/arch/avr32/include/asm/elf.h
2424 +--- linux-2.6.28/arch/avr32/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
2425 ++++ linux-2.6.28/arch/avr32/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
2426 +@@ -85,8 +85,14 @@ typedef struct user_fpu_struct elf_fpreg
2427 + the loader. We need to make sure that it is out of the way of the program
2428 + that it will "exec", and that there is sufficient room for the brk. */
2429 +
2430 +-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2431 ++#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2432 +
2433 ++#ifdef CONFIG_PAX_ASLR
2434 ++#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2435 ++
2436 ++#define PAX_DELTA_MMAP_LEN 15
2437 ++#define PAX_DELTA_STACK_LEN 15
2438 ++#endif
2439 +
2440 + /* This yields a mask that user programs can use to figure out what
2441 + instruction set this CPU supports. This could be done in user space,
2442 +diff -urNp linux-2.6.28/arch/avr32/include/asm/kmap_types.h linux-2.6.28/arch/avr32/include/asm/kmap_types.h
2443 +--- linux-2.6.28/arch/avr32/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2444 ++++ linux-2.6.28/arch/avr32/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2445 +@@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2446 + D(11) KM_IRQ1,
2447 + D(12) KM_SOFTIRQ0,
2448 + D(13) KM_SOFTIRQ1,
2449 +-D(14) KM_TYPE_NR
2450 ++D(14) KM_CLEARPAGE,
2451 ++D(15) KM_TYPE_NR
2452 + };
2453 +
2454 + #undef D
2455 +diff -urNp linux-2.6.28/arch/avr32/mm/fault.c linux-2.6.28/arch/avr32/mm/fault.c
2456 +--- linux-2.6.28/arch/avr32/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
2457 ++++ linux-2.6.28/arch/avr32/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
2458 +@@ -41,6 +41,23 @@ static inline int notify_page_fault(stru
2459 +
2460 + int exception_trace = 1;
2461 +
2462 ++#ifdef CONFIG_PAX_PAGEEXEC
2463 ++void pax_report_insns(void *pc, void *sp)
2464 ++{
2465 ++ unsigned long i;
2466 ++
2467 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2468 ++ for (i = 0; i < 20; i++) {
2469 ++ unsigned char c;
2470 ++ if (get_user(c, (unsigned char *)pc+i))
2471 ++ printk(KERN_CONT "???????? ");
2472 ++ else
2473 ++ printk(KERN_CONT "%02x ", c);
2474 ++ }
2475 ++ printk("\n");
2476 ++}
2477 ++#endif
2478 ++
2479 + /*
2480 + * This routine handles page faults. It determines the address and the
2481 + * problem, and then passes it off to one of the appropriate routines.
2482 +@@ -157,6 +174,16 @@ bad_area:
2483 + up_read(&mm->mmap_sem);
2484 +
2485 + if (user_mode(regs)) {
2486 ++
2487 ++#ifdef CONFIG_PAX_PAGEEXEC
2488 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2489 ++ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2490 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2491 ++ do_group_exit(SIGKILL);
2492 ++ }
2493 ++ }
2494 ++#endif
2495 ++
2496 + if (exception_trace && printk_ratelimit())
2497 + printk("%s%s[%d]: segfault at %08lx pc %08lx "
2498 + "sp %08lx ecr %lu\n",
2499 +diff -urNp linux-2.6.28/arch/blackfin/include/asm/kmap_types.h linux-2.6.28/arch/blackfin/include/asm/kmap_types.h
2500 +--- linux-2.6.28/arch/blackfin/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2501 ++++ linux-2.6.28/arch/blackfin/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2502 +@@ -15,6 +15,7 @@ enum km_type {
2503 + KM_IRQ1,
2504 + KM_SOFTIRQ0,
2505 + KM_SOFTIRQ1,
2506 ++ KM_CLEARPAGE,
2507 + KM_TYPE_NR
2508 + };
2509 +
2510 +diff -urNp linux-2.6.28/arch/cris/include/asm/kmap_types.h linux-2.6.28/arch/cris/include/asm/kmap_types.h
2511 +--- linux-2.6.28/arch/cris/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2512 ++++ linux-2.6.28/arch/cris/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2513 +@@ -19,6 +19,7 @@ enum km_type {
2514 + KM_IRQ1,
2515 + KM_SOFTIRQ0,
2516 + KM_SOFTIRQ1,
2517 ++ KM_CLEARPAGE,
2518 + KM_TYPE_NR
2519 + };
2520 +
2521 +diff -urNp linux-2.6.28/arch/h8300/include/asm/kmap_types.h linux-2.6.28/arch/h8300/include/asm/kmap_types.h
2522 +--- linux-2.6.28/arch/h8300/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2523 ++++ linux-2.6.28/arch/h8300/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2524 +@@ -15,6 +15,7 @@ enum km_type {
2525 + KM_IRQ1,
2526 + KM_SOFTIRQ0,
2527 + KM_SOFTIRQ1,
2528 ++ KM_CLEARPAGE,
2529 + KM_TYPE_NR
2530 + };
2531 +
2532 +diff -urNp linux-2.6.28/arch/ia64/ia32/binfmt_elf32.c linux-2.6.28/arch/ia64/ia32/binfmt_elf32.c
2533 +--- linux-2.6.28/arch/ia64/ia32/binfmt_elf32.c 2008-12-24 18:26:37.000000000 -0500
2534 ++++ linux-2.6.28/arch/ia64/ia32/binfmt_elf32.c 2009-01-11 07:20:06.000000000 -0500
2535 +@@ -45,6 +45,13 @@ randomize_stack_top(unsigned long stack_
2536 +
2537 + #define elf_read_implies_exec(ex, have_pt_gnu_stack) (!(have_pt_gnu_stack))
2538 +
2539 ++#ifdef CONFIG_PAX_ASLR
2540 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2541 ++
2542 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2543 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2544 ++#endif
2545 ++
2546 + /* Ugly but avoids duplication */
2547 + #include "../../../fs/binfmt_elf.c"
2548 +
2549 +diff -urNp linux-2.6.28/arch/ia64/ia32/ia32priv.h linux-2.6.28/arch/ia64/ia32/ia32priv.h
2550 +--- linux-2.6.28/arch/ia64/ia32/ia32priv.h 2008-12-24 18:26:37.000000000 -0500
2551 ++++ linux-2.6.28/arch/ia64/ia32/ia32priv.h 2009-01-11 07:20:06.000000000 -0500
2552 +@@ -296,7 +296,14 @@ typedef struct compat_siginfo {
2553 + #define ELF_DATA ELFDATA2LSB
2554 + #define ELF_ARCH EM_386
2555 +
2556 +-#define IA32_STACK_TOP IA32_PAGE_OFFSET
2557 ++#ifdef CONFIG_PAX_RANDUSTACK
2558 ++#define __IA32_DELTA_STACK (current->mm->delta_stack)
2559 ++#else
2560 ++#define __IA32_DELTA_STACK 0UL
2561 ++#endif
2562 ++
2563 ++#define IA32_STACK_TOP (IA32_PAGE_OFFSET - __IA32_DELTA_STACK)
2564 ++
2565 + #define IA32_GATE_OFFSET IA32_PAGE_OFFSET
2566 + #define IA32_GATE_END IA32_PAGE_OFFSET + PAGE_SIZE
2567 +
2568 +diff -urNp linux-2.6.28/arch/ia64/include/asm/elf.h linux-2.6.28/arch/ia64/include/asm/elf.h
2569 +--- linux-2.6.28/arch/ia64/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
2570 ++++ linux-2.6.28/arch/ia64/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
2571 +@@ -43,6 +43,13 @@
2572 + */
2573 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2574 +
2575 ++#ifdef CONFIG_PAX_ASLR
2576 ++#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2577 ++
2578 ++#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2579 ++#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2580 ++#endif
2581 ++
2582 + #define PT_IA_64_UNWIND 0x70000001
2583 +
2584 + /* IA-64 relocations: */
2585 +diff -urNp linux-2.6.28/arch/ia64/include/asm/kmap_types.h linux-2.6.28/arch/ia64/include/asm/kmap_types.h
2586 +--- linux-2.6.28/arch/ia64/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2587 ++++ linux-2.6.28/arch/ia64/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2588 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
2589 + D(10) KM_IRQ1,
2590 + D(11) KM_SOFTIRQ0,
2591 + D(12) KM_SOFTIRQ1,
2592 +-D(13) KM_TYPE_NR
2593 ++D(13) KM_CLEARPAGE,
2594 ++D(14) KM_TYPE_NR
2595 + };
2596 +
2597 + #undef D
2598 +diff -urNp linux-2.6.28/arch/ia64/include/asm/pgtable.h linux-2.6.28/arch/ia64/include/asm/pgtable.h
2599 +--- linux-2.6.28/arch/ia64/include/asm/pgtable.h 2008-12-24 18:26:37.000000000 -0500
2600 ++++ linux-2.6.28/arch/ia64/include/asm/pgtable.h 2009-01-11 07:20:06.000000000 -0500
2601 +@@ -143,6 +143,17 @@
2602 + #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2603 + #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2604 + #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2605 ++
2606 ++#ifdef CONFIG_PAX_PAGEEXEC
2607 ++# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2608 ++# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2609 ++# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2610 ++#else
2611 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
2612 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
2613 ++# define PAGE_COPY_NOEXEC PAGE_COPY
2614 ++#endif
2615 ++
2616 + #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2617 + #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2618 + #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2619 +diff -urNp linux-2.6.28/arch/ia64/kernel/module.c linux-2.6.28/arch/ia64/kernel/module.c
2620 +--- linux-2.6.28/arch/ia64/kernel/module.c 2008-12-24 18:26:37.000000000 -0500
2621 ++++ linux-2.6.28/arch/ia64/kernel/module.c 2009-01-11 07:20:06.000000000 -0500
2622 +@@ -312,8 +312,7 @@ module_alloc (unsigned long size)
2623 + void
2624 + module_free (struct module *mod, void *module_region)
2625 + {
2626 +- if (mod && mod->arch.init_unw_table &&
2627 +- module_region == mod->module_init) {
2628 ++ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2629 + unw_remove_unwind_table(mod->arch.init_unw_table);
2630 + mod->arch.init_unw_table = NULL;
2631 + }
2632 +@@ -491,15 +490,39 @@ module_frob_arch_sections (Elf_Ehdr *ehd
2633 + }
2634 +
2635 + static inline int
2636 ++in_init_rx (const struct module *mod, uint64_t addr)
2637 ++{
2638 ++ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2639 ++}
2640 ++
2641 ++static inline int
2642 ++in_init_rw (const struct module *mod, uint64_t addr)
2643 ++{
2644 ++ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2645 ++}
2646 ++
2647 ++static inline int
2648 + in_init (const struct module *mod, uint64_t addr)
2649 + {
2650 +- return addr - (uint64_t) mod->module_init < mod->init_size;
2651 ++ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2652 ++}
2653 ++
2654 ++static inline int
2655 ++in_core_rx (const struct module *mod, uint64_t addr)
2656 ++{
2657 ++ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2658 ++}
2659 ++
2660 ++static inline int
2661 ++in_core_rw (const struct module *mod, uint64_t addr)
2662 ++{
2663 ++ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2664 + }
2665 +
2666 + static inline int
2667 + in_core (const struct module *mod, uint64_t addr)
2668 + {
2669 +- return addr - (uint64_t) mod->module_core < mod->core_size;
2670 ++ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2671 + }
2672 +
2673 + static inline int
2674 +@@ -683,7 +706,14 @@ do_reloc (struct module *mod, uint8_t r_
2675 + break;
2676 +
2677 + case RV_BDREL:
2678 +- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2679 ++ if (in_init_rx(mod, val))
2680 ++ val -= (uint64_t) mod->module_init_rx;
2681 ++ else if (in_init_rw(mod, val))
2682 ++ val -= (uint64_t) mod->module_init_rw;
2683 ++ else if (in_core_rx(mod, val))
2684 ++ val -= (uint64_t) mod->module_core_rx;
2685 ++ else if (in_core_rw(mod, val))
2686 ++ val -= (uint64_t) mod->module_core_rw;
2687 + break;
2688 +
2689 + case RV_LTV:
2690 +@@ -817,15 +847,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs,
2691 + * addresses have been selected...
2692 + */
2693 + uint64_t gp;
2694 +- if (mod->core_size > MAX_LTOFF)
2695 ++ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2696 + /*
2697 + * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2698 + * at the end of the module.
2699 + */
2700 +- gp = mod->core_size - MAX_LTOFF / 2;
2701 ++ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2702 + else
2703 +- gp = mod->core_size / 2;
2704 +- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2705 ++ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2706 ++ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2707 + mod->arch.gp = gp;
2708 + DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2709 + }
2710 +diff -urNp linux-2.6.28/arch/ia64/kernel/sys_ia64.c linux-2.6.28/arch/ia64/kernel/sys_ia64.c
2711 +--- linux-2.6.28/arch/ia64/kernel/sys_ia64.c 2008-12-24 18:26:37.000000000 -0500
2712 ++++ linux-2.6.28/arch/ia64/kernel/sys_ia64.c 2009-01-11 07:20:06.000000000 -0500
2713 +@@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *fil
2714 + if (REGION_NUMBER(addr) == RGN_HPAGE)
2715 + addr = 0;
2716 + #endif
2717 ++
2718 ++#ifdef CONFIG_PAX_RANDMMAP
2719 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
2720 ++ addr = mm->free_area_cache;
2721 ++ else
2722 ++#endif
2723 ++
2724 + if (!addr)
2725 + addr = mm->free_area_cache;
2726 +
2727 +@@ -61,9 +68,9 @@ arch_get_unmapped_area (struct file *fil
2728 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2729 + /* At this point: (!vma || addr < vma->vm_end). */
2730 + if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2731 +- if (start_addr != TASK_UNMAPPED_BASE) {
2732 ++ if (start_addr != mm->mmap_base) {
2733 + /* Start a new search --- just in case we missed some holes. */
2734 +- addr = TASK_UNMAPPED_BASE;
2735 ++ addr = mm->mmap_base;
2736 + goto full_search;
2737 + }
2738 + return -ENOMEM;
2739 +diff -urNp linux-2.6.28/arch/ia64/mm/fault.c linux-2.6.28/arch/ia64/mm/fault.c
2740 +--- linux-2.6.28/arch/ia64/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
2741 ++++ linux-2.6.28/arch/ia64/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
2742 +@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned
2743 + return pte_present(pte);
2744 + }
2745 +
2746 ++#ifdef CONFIG_PAX_PAGEEXEC
2747 ++void pax_report_insns(void *pc, void *sp)
2748 ++{
2749 ++ unsigned long i;
2750 ++
2751 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2752 ++ for (i = 0; i < 8; i++) {
2753 ++ unsigned int c;
2754 ++ if (get_user(c, (unsigned int *)pc+i))
2755 ++ printk(KERN_CONT "???????? ");
2756 ++ else
2757 ++ printk(KERN_CONT "%08x ", c);
2758 ++ }
2759 ++ printk("\n");
2760 ++}
2761 ++#endif
2762 ++
2763 + void __kprobes
2764 + ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2765 + {
2766 +@@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long addres
2767 + mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2768 + | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2769 +
2770 +- if ((vma->vm_flags & mask) != mask)
2771 ++ if ((vma->vm_flags & mask) != mask) {
2772 ++
2773 ++#ifdef CONFIG_PAX_PAGEEXEC
2774 ++ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2775 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2776 ++ goto bad_area;
2777 ++
2778 ++ up_read(&mm->mmap_sem);
2779 ++ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2780 ++ do_group_exit(SIGKILL);
2781 ++ }
2782 ++#endif
2783 ++
2784 + goto bad_area;
2785 +
2786 ++ }
2787 ++
2788 + survive:
2789 + /*
2790 + * If for any reason at all we couldn't handle the fault, make
2791 +diff -urNp linux-2.6.28/arch/ia64/mm/init.c linux-2.6.28/arch/ia64/mm/init.c
2792 +--- linux-2.6.28/arch/ia64/mm/init.c 2008-12-24 18:26:37.000000000 -0500
2793 ++++ linux-2.6.28/arch/ia64/mm/init.c 2009-01-11 07:20:06.000000000 -0500
2794 +@@ -121,6 +121,19 @@ ia64_init_addr_space (void)
2795 + vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2796 + vma->vm_end = vma->vm_start + PAGE_SIZE;
2797 + vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2798 ++
2799 ++#ifdef CONFIG_PAX_PAGEEXEC
2800 ++ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2801 ++ vma->vm_flags &= ~VM_EXEC;
2802 ++
2803 ++#ifdef CONFIG_PAX_MPROTECT
2804 ++ if (current->mm->pax_flags & MF_PAX_MPROTECT)
2805 ++ vma->vm_flags &= ~VM_MAYEXEC;
2806 ++#endif
2807 ++
2808 ++ }
2809 ++#endif
2810 ++
2811 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2812 + down_write(&current->mm->mmap_sem);
2813 + if (insert_vm_struct(current->mm, vma)) {
2814 +diff -urNp linux-2.6.28/arch/m68knommu/include/asm/kmap_types.h linux-2.6.28/arch/m68knommu/include/asm/kmap_types.h
2815 +--- linux-2.6.28/arch/m68knommu/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2816 ++++ linux-2.6.28/arch/m68knommu/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2817 +@@ -15,6 +15,7 @@ enum km_type {
2818 + KM_IRQ1,
2819 + KM_SOFTIRQ0,
2820 + KM_SOFTIRQ1,
2821 ++ KM_CLEARPAGE,
2822 + KM_TYPE_NR
2823 + };
2824 +
2825 +diff -urNp linux-2.6.28/arch/mips/include/asm/elf.h linux-2.6.28/arch/mips/include/asm/elf.h
2826 +--- linux-2.6.28/arch/mips/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
2827 ++++ linux-2.6.28/arch/mips/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
2828 +@@ -364,4 +364,11 @@ extern int dump_task_fpu(struct task_str
2829 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2830 + #endif
2831 +
2832 ++#ifdef CONFIG_PAX_ASLR
2833 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2834 ++
2835 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2836 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2837 ++#endif
2838 ++
2839 + #endif /* _ASM_ELF_H */
2840 +diff -urNp linux-2.6.28/arch/mips/include/asm/kmap_types.h linux-2.6.28/arch/mips/include/asm/kmap_types.h
2841 +--- linux-2.6.28/arch/mips/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2842 ++++ linux-2.6.28/arch/mips/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
2843 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
2844 + D(10) KM_IRQ1,
2845 + D(11) KM_SOFTIRQ0,
2846 + D(12) KM_SOFTIRQ1,
2847 +-D(13) KM_TYPE_NR
2848 ++D(13) KM_CLEARPAGE,
2849 ++D(14) KM_TYPE_NR
2850 + };
2851 +
2852 + #undef D
2853 +diff -urNp linux-2.6.28/arch/mips/include/asm/page.h linux-2.6.28/arch/mips/include/asm/page.h
2854 +--- linux-2.6.28/arch/mips/include/asm/page.h 2008-12-24 18:26:37.000000000 -0500
2855 ++++ linux-2.6.28/arch/mips/include/asm/page.h 2009-01-11 07:20:06.000000000 -0500
2856 +@@ -82,7 +82,7 @@ extern void copy_user_highpage(struct pa
2857 + #ifdef CONFIG_CPU_MIPS32
2858 + typedef struct { unsigned long pte_low, pte_high; } pte_t;
2859 + #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2860 +- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2861 ++ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2862 + #else
2863 + typedef struct { unsigned long long pte; } pte_t;
2864 + #define pte_val(x) ((x).pte)
2865 +diff -urNp linux-2.6.28/arch/mips/include/asm/system.h linux-2.6.28/arch/mips/include/asm/system.h
2866 +--- linux-2.6.28/arch/mips/include/asm/system.h 2008-12-24 18:26:37.000000000 -0500
2867 ++++ linux-2.6.28/arch/mips/include/asm/system.h 2009-01-11 07:20:06.000000000 -0500
2868 +@@ -217,6 +217,6 @@ extern void per_cpu_trap_init(void);
2869 + */
2870 + #define __ARCH_WANT_UNLOCKED_CTXSW
2871 +
2872 +-extern unsigned long arch_align_stack(unsigned long sp);
2873 ++#define arch_align_stack(x) ((x) & ALMASK)
2874 +
2875 + #endif /* _ASM_SYSTEM_H */
2876 +diff -urNp linux-2.6.28/arch/mips/kernel/binfmt_elfn32.c linux-2.6.28/arch/mips/kernel/binfmt_elfn32.c
2877 +--- linux-2.6.28/arch/mips/kernel/binfmt_elfn32.c 2008-12-24 18:26:37.000000000 -0500
2878 ++++ linux-2.6.28/arch/mips/kernel/binfmt_elfn32.c 2009-01-11 07:20:06.000000000 -0500
2879 +@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2880 + #undef ELF_ET_DYN_BASE
2881 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2882 +
2883 ++#ifdef CONFIG_PAX_ASLR
2884 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2885 ++
2886 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2887 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2888 ++#endif
2889 ++
2890 + #include <asm/processor.h>
2891 + #include <linux/module.h>
2892 + #include <linux/elfcore.h>
2893 +diff -urNp linux-2.6.28/arch/mips/kernel/binfmt_elfo32.c linux-2.6.28/arch/mips/kernel/binfmt_elfo32.c
2894 +--- linux-2.6.28/arch/mips/kernel/binfmt_elfo32.c 2008-12-24 18:26:37.000000000 -0500
2895 ++++ linux-2.6.28/arch/mips/kernel/binfmt_elfo32.c 2009-01-11 07:20:06.000000000 -0500
2896 +@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_N
2897 + #undef ELF_ET_DYN_BASE
2898 + #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2899 +
2900 ++#ifdef CONFIG_PAX_ASLR
2901 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT_ADDR) ? 0x00400000UL : 0x00400000UL)
2902 ++
2903 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2904 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT_ADDR) ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2905 ++#endif
2906 ++
2907 + #include <asm/processor.h>
2908 + #include <linux/module.h>
2909 + #include <linux/elfcore.h>
2910 +diff -urNp linux-2.6.28/arch/mips/kernel/process.c linux-2.6.28/arch/mips/kernel/process.c
2911 +--- linux-2.6.28/arch/mips/kernel/process.c 2008-12-24 18:26:37.000000000 -0500
2912 ++++ linux-2.6.28/arch/mips/kernel/process.c 2009-01-11 07:20:06.000000000 -0500
2913 +@@ -457,15 +457,3 @@ unsigned long get_wchan(struct task_stru
2914 + out:
2915 + return pc;
2916 + }
2917 +-
2918 +-/*
2919 +- * Don't forget that the stack pointer must be aligned on a 8 bytes
2920 +- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2921 +- */
2922 +-unsigned long arch_align_stack(unsigned long sp)
2923 +-{
2924 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
2925 +- sp -= get_random_int() & ~PAGE_MASK;
2926 +-
2927 +- return sp & ALMASK;
2928 +-}
2929 +diff -urNp linux-2.6.28/arch/mips/kernel/syscall.c linux-2.6.28/arch/mips/kernel/syscall.c
2930 +--- linux-2.6.28/arch/mips/kernel/syscall.c 2008-12-24 18:26:37.000000000 -0500
2931 ++++ linux-2.6.28/arch/mips/kernel/syscall.c 2009-01-11 07:20:06.000000000 -0500
2932 +@@ -99,6 +99,11 @@ unsigned long arch_get_unmapped_area(str
2933 + do_color_align = 0;
2934 + if (filp || (flags & MAP_SHARED))
2935 + do_color_align = 1;
2936 ++
2937 ++#ifdef CONFIG_PAX_RANDMMAP
2938 ++ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
2939 ++#endif
2940 ++
2941 + if (addr) {
2942 + if (do_color_align)
2943 + addr = COLOUR_ALIGN(addr, pgoff);
2944 +@@ -109,7 +114,7 @@ unsigned long arch_get_unmapped_area(str
2945 + (!vmm || addr + len <= vmm->vm_start))
2946 + return addr;
2947 + }
2948 +- addr = TASK_UNMAPPED_BASE;
2949 ++ addr = current->mm->mmap_base;
2950 + if (do_color_align)
2951 + addr = COLOUR_ALIGN(addr, pgoff);
2952 + else
2953 +diff -urNp linux-2.6.28/arch/mips/mm/fault.c linux-2.6.28/arch/mips/mm/fault.c
2954 +--- linux-2.6.28/arch/mips/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
2955 ++++ linux-2.6.28/arch/mips/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
2956 +@@ -26,6 +26,23 @@
2957 + #include <asm/ptrace.h>
2958 + #include <asm/highmem.h> /* For VMALLOC_END */
2959 +
2960 ++#ifdef CONFIG_PAX_PAGEEXEC
2961 ++void pax_report_insns(void *pc)
2962 ++{
2963 ++ unsigned long i;
2964 ++
2965 ++ printk(KERN_ERR "PAX: bytes at PC: ");
2966 ++ for (i = 0; i < 5; i++) {
2967 ++ unsigned int c;
2968 ++ if (get_user(c, (unsigned int *)pc+i))
2969 ++ printk(KERN_CONT "???????? ");
2970 ++ else
2971 ++ printk(KERN_CONT "%08x ", c);
2972 ++ }
2973 ++ printk("\n");
2974 ++}
2975 ++#endif
2976 ++
2977 + /*
2978 + * This routine handles page faults. It determines the address,
2979 + * and the problem, and then passes it off to one of the appropriate
2980 +diff -urNp linux-2.6.28/arch/parisc/include/asm/elf.h linux-2.6.28/arch/parisc/include/asm/elf.h
2981 +--- linux-2.6.28/arch/parisc/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
2982 ++++ linux-2.6.28/arch/parisc/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
2983 +@@ -333,6 +333,13 @@ struct pt_regs; /* forward declaration..
2984 +
2985 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
2986 +
2987 ++#ifdef CONFIG_PAX_ASLR
2988 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
2989 ++
2990 ++#define PAX_DELTA_MMAP_LEN 16
2991 ++#define PAX_DELTA_STACK_LEN 16
2992 ++#endif
2993 ++
2994 + /* This yields a mask that user programs can use to figure out what
2995 + instruction set this CPU supports. This could be done in user space,
2996 + but it's not easy, and we've already done it here. */
2997 +diff -urNp linux-2.6.28/arch/parisc/include/asm/kmap_types.h linux-2.6.28/arch/parisc/include/asm/kmap_types.h
2998 +--- linux-2.6.28/arch/parisc/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
2999 ++++ linux-2.6.28/arch/parisc/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
3000 +@@ -22,7 +22,8 @@ D(9) KM_IRQ0,
3001 + D(10) KM_IRQ1,
3002 + D(11) KM_SOFTIRQ0,
3003 + D(12) KM_SOFTIRQ1,
3004 +-D(13) KM_TYPE_NR
3005 ++D(13) KM_CLEARPAGE,
3006 ++D(14) KM_TYPE_NR
3007 + };
3008 +
3009 + #undef D
3010 +diff -urNp linux-2.6.28/arch/parisc/include/asm/pgtable.h linux-2.6.28/arch/parisc/include/asm/pgtable.h
3011 +--- linux-2.6.28/arch/parisc/include/asm/pgtable.h 2008-12-24 18:26:37.000000000 -0500
3012 ++++ linux-2.6.28/arch/parisc/include/asm/pgtable.h 2009-01-11 07:20:06.000000000 -0500
3013 +@@ -202,6 +202,17 @@
3014 + #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3015 + #define PAGE_COPY PAGE_EXECREAD
3016 + #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3017 ++
3018 ++#ifdef CONFIG_PAX_PAGEEXEC
3019 ++# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3020 ++# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3021 ++# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3022 ++#else
3023 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
3024 ++# define PAGE_COPY_NOEXEC PAGE_COPY
3025 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
3026 ++#endif
3027 ++
3028 + #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3029 + #define PAGE_KERNEL_RO __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
3030 + #define PAGE_KERNEL_UNC __pgprot(_PAGE_KERNEL | _PAGE_NO_CACHE)
3031 +diff -urNp linux-2.6.28/arch/parisc/kernel/module.c linux-2.6.28/arch/parisc/kernel/module.c
3032 +--- linux-2.6.28/arch/parisc/kernel/module.c 2008-12-24 18:26:37.000000000 -0500
3033 ++++ linux-2.6.28/arch/parisc/kernel/module.c 2009-01-11 07:20:06.000000000 -0500
3034 +@@ -75,16 +75,38 @@
3035 +
3036 + /* three functions to determine where in the module core
3037 + * or init pieces the location is */
3038 ++static inline int in_init_rx(struct module *me, void *loc)
3039 ++{
3040 ++ return (loc >= me->module_init_rx &&
3041 ++ loc < (me->module_init_rx + me->init_size_rx));
3042 ++}
3043 ++
3044 ++static inline int in_init_rw(struct module *me, void *loc)
3045 ++{
3046 ++ return (loc >= me->module_init_rw &&
3047 ++ loc < (me->module_init_rw + me->init_size_rw));
3048 ++}
3049 ++
3050 + static inline int in_init(struct module *me, void *loc)
3051 + {
3052 +- return (loc >= me->module_init &&
3053 +- loc <= (me->module_init + me->init_size));
3054 ++ return in_init_rx(me, loc) || in_init_rw(me, loc);
3055 ++}
3056 ++
3057 ++static inline int in_core_rx(struct module *me, void *loc)
3058 ++{
3059 ++ return (loc >= me->module_core_rx &&
3060 ++ loc < (me->module_core_rx + me->core_size_rx));
3061 ++}
3062 ++
3063 ++static inline int in_core_rw(struct module *me, void *loc)
3064 ++{
3065 ++ return (loc >= me->module_core_rw &&
3066 ++ loc < (me->module_core_rw + me->core_size_rw));
3067 + }
3068 +
3069 + static inline int in_core(struct module *me, void *loc)
3070 + {
3071 +- return (loc >= me->module_core &&
3072 +- loc <= (me->module_core + me->core_size));
3073 ++ return in_core_rx(me, loc) || in_core_rw(me, loc);
3074 + }
3075 +
3076 + static inline int in_local(struct module *me, void *loc)
3077 +@@ -298,21 +320,21 @@ int module_frob_arch_sections(CONST Elf_
3078 + }
3079 +
3080 + /* align things a bit */
3081 +- me->core_size = ALIGN(me->core_size, 16);
3082 +- me->arch.got_offset = me->core_size;
3083 +- me->core_size += gots * sizeof(struct got_entry);
3084 +-
3085 +- me->core_size = ALIGN(me->core_size, 16);
3086 +- me->arch.fdesc_offset = me->core_size;
3087 +- me->core_size += fdescs * sizeof(Elf_Fdesc);
3088 +-
3089 +- me->core_size = ALIGN(me->core_size, 16);
3090 +- me->arch.stub_offset = me->core_size;
3091 +- me->core_size += stubs * sizeof(struct stub_entry);
3092 +-
3093 +- me->init_size = ALIGN(me->init_size, 16);
3094 +- me->arch.init_stub_offset = me->init_size;
3095 +- me->init_size += init_stubs * sizeof(struct stub_entry);
3096 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3097 ++ me->arch.got_offset = me->core_size_rw;
3098 ++ me->core_size_rw += gots * sizeof(struct got_entry);
3099 ++
3100 ++ me->core_size_rw = ALIGN(me->core_size_rw, 16);
3101 ++ me->arch.fdesc_offset = me->core_size_rw;
3102 ++ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3103 ++
3104 ++ me->core_size_rx = ALIGN(me->core_size_rx, 16);
3105 ++ me->arch.stub_offset = me->core_size_rx;
3106 ++ me->core_size_rx += stubs * sizeof(struct stub_entry);
3107 ++
3108 ++ me->init_size_rx = ALIGN(me->init_size_rx, 16);
3109 ++ me->arch.init_stub_offset = me->init_size_rx;
3110 ++ me->init_size_rx += init_stubs * sizeof(struct stub_entry);
3111 +
3112 + me->arch.got_max = gots;
3113 + me->arch.fdesc_max = fdescs;
3114 +@@ -332,7 +354,7 @@ static Elf64_Word get_got(struct module
3115 +
3116 + BUG_ON(value == 0);
3117 +
3118 +- got = me->module_core + me->arch.got_offset;
3119 ++ got = me->module_core_rw + me->arch.got_offset;
3120 + for (i = 0; got[i].addr; i++)
3121 + if (got[i].addr == value)
3122 + goto out;
3123 +@@ -350,7 +372,7 @@ static Elf64_Word get_got(struct module
3124 + #ifdef CONFIG_64BIT
3125 + static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3126 + {
3127 +- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3128 ++ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3129 +
3130 + if (!value) {
3131 + printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3132 +@@ -368,7 +390,7 @@ static Elf_Addr get_fdesc(struct module
3133 +
3134 + /* Create new one */
3135 + fdesc->addr = value;
3136 +- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3137 ++ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3138 + return (Elf_Addr)fdesc;
3139 + }
3140 + #endif /* CONFIG_64BIT */
3141 +@@ -388,12 +410,12 @@ static Elf_Addr get_stub(struct module *
3142 + if(init_section) {
3143 + i = me->arch.init_stub_count++;
3144 + BUG_ON(me->arch.init_stub_count > me->arch.init_stub_max);
3145 +- stub = me->module_init + me->arch.init_stub_offset +
3146 ++ stub = me->module_init_rx + me->arch.init_stub_offset +
3147 + i * sizeof(struct stub_entry);
3148 + } else {
3149 + i = me->arch.stub_count++;
3150 + BUG_ON(me->arch.stub_count > me->arch.stub_max);
3151 +- stub = me->module_core + me->arch.stub_offset +
3152 ++ stub = me->module_core_rx + me->arch.stub_offset +
3153 + i * sizeof(struct stub_entry);
3154 + }
3155 +
3156 +@@ -761,7 +783,7 @@ register_unwind_table(struct module *me,
3157 +
3158 + table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3159 + end = table + sechdrs[me->arch.unwind_section].sh_size;
3160 +- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3161 ++ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3162 +
3163 + DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3164 + me->arch.unwind_section, table, end, gp);
3165 +diff -urNp linux-2.6.28/arch/parisc/kernel/sys_parisc.c linux-2.6.28/arch/parisc/kernel/sys_parisc.c
3166 +--- linux-2.6.28/arch/parisc/kernel/sys_parisc.c 2008-12-24 18:26:37.000000000 -0500
3167 ++++ linux-2.6.28/arch/parisc/kernel/sys_parisc.c 2009-01-11 07:20:06.000000000 -0500
3168 +@@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(str
3169 + if (flags & MAP_FIXED)
3170 + return addr;
3171 + if (!addr)
3172 +- addr = TASK_UNMAPPED_BASE;
3173 ++ addr = current->mm->mmap_base;
3174 +
3175 + if (filp) {
3176 + addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3177 +diff -urNp linux-2.6.28/arch/parisc/kernel/traps.c linux-2.6.28/arch/parisc/kernel/traps.c
3178 +--- linux-2.6.28/arch/parisc/kernel/traps.c 2008-12-24 18:26:37.000000000 -0500
3179 ++++ linux-2.6.28/arch/parisc/kernel/traps.c 2009-01-11 07:20:06.000000000 -0500
3180 +@@ -731,9 +731,7 @@ void handle_interruption(int code, struc
3181 +
3182 + down_read(&current->mm->mmap_sem);
3183 + vma = find_vma(current->mm,regs->iaoq[0]);
3184 +- if (vma && (regs->iaoq[0] >= vma->vm_start)
3185 +- && (vma->vm_flags & VM_EXEC)) {
3186 +-
3187 ++ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3188 + fault_address = regs->iaoq[0];
3189 + fault_space = regs->iasq[0];
3190 +
3191 +diff -urNp linux-2.6.28/arch/parisc/mm/fault.c linux-2.6.28/arch/parisc/mm/fault.c
3192 +--- linux-2.6.28/arch/parisc/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
3193 ++++ linux-2.6.28/arch/parisc/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
3194 +@@ -16,6 +16,7 @@
3195 + #include <linux/sched.h>
3196 + #include <linux/interrupt.h>
3197 + #include <linux/module.h>
3198 ++#include <linux/unistd.h>
3199 +
3200 + #include <asm/uaccess.h>
3201 + #include <asm/traps.h>
3202 +@@ -53,7 +54,7 @@ DEFINE_PER_CPU(struct exception_data, ex
3203 + static unsigned long
3204 + parisc_acctyp(unsigned long code, unsigned int inst)
3205 + {
3206 +- if (code == 6 || code == 16)
3207 ++ if (code == 6 || code == 7 || code == 16)
3208 + return VM_EXEC;
3209 +
3210 + switch (inst & 0xf0000000) {
3211 +@@ -139,6 +140,116 @@ parisc_acctyp(unsigned long code, unsign
3212 + }
3213 + #endif
3214 +
3215 ++#ifdef CONFIG_PAX_PAGEEXEC
3216 ++/*
3217 ++ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3218 ++ *
3219 ++ * returns 1 when task should be killed
3220 ++ * 2 when rt_sigreturn trampoline was detected
3221 ++ * 3 when unpatched PLT trampoline was detected
3222 ++ */
3223 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
3224 ++{
3225 ++
3226 ++#ifdef CONFIG_PAX_EMUPLT
3227 ++ int err;
3228 ++
3229 ++ do { /* PaX: unpatched PLT emulation */
3230 ++ unsigned int bl, depwi;
3231 ++
3232 ++ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3233 ++ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3234 ++
3235 ++ if (err)
3236 ++ break;
3237 ++
3238 ++ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3239 ++ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3240 ++
3241 ++ err = get_user(ldw, (unsigned int *)addr);
3242 ++ err |= get_user(bv, (unsigned int *)(addr+4));
3243 ++ err |= get_user(ldw2, (unsigned int *)(addr+8));
3244 ++
3245 ++ if (err)
3246 ++ break;
3247 ++
3248 ++ if (ldw == 0x0E801096U &&
3249 ++ bv == 0xEAC0C000U &&
3250 ++ ldw2 == 0x0E881095U)
3251 ++ {
3252 ++ unsigned int resolver, map;
3253 ++
3254 ++ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3255 ++ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3256 ++ if (err)
3257 ++ break;
3258 ++
3259 ++ regs->gr[20] = instruction_pointer(regs)+8;
3260 ++ regs->gr[21] = map;
3261 ++ regs->gr[22] = resolver;
3262 ++ regs->iaoq[0] = resolver | 3UL;
3263 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
3264 ++ return 3;
3265 ++ }
3266 ++ }
3267 ++ } while (0);
3268 ++#endif
3269 ++
3270 ++#ifdef CONFIG_PAX_EMUTRAMP
3271 ++
3272 ++#ifndef CONFIG_PAX_EMUSIGRT
3273 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3274 ++ return 1;
3275 ++#endif
3276 ++
3277 ++ do { /* PaX: rt_sigreturn emulation */
3278 ++ unsigned int ldi1, ldi2, bel, nop;
3279 ++
3280 ++ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3281 ++ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3282 ++ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3283 ++ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3284 ++
3285 ++ if (err)
3286 ++ break;
3287 ++
3288 ++ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3289 ++ ldi2 == 0x3414015AU &&
3290 ++ bel == 0xE4008200U &&
3291 ++ nop == 0x08000240U)
3292 ++ {
3293 ++ regs->gr[25] = (ldi1 & 2) >> 1;
3294 ++ regs->gr[20] = __NR_rt_sigreturn;
3295 ++ regs->gr[31] = regs->iaoq[1] + 16;
3296 ++ regs->sr[0] = regs->iasq[1];
3297 ++ regs->iaoq[0] = 0x100UL;
3298 ++ regs->iaoq[1] = regs->iaoq[0] + 4;
3299 ++ regs->iasq[0] = regs->sr[2];
3300 ++ regs->iasq[1] = regs->sr[2];
3301 ++ return 2;
3302 ++ }
3303 ++ } while (0);
3304 ++#endif
3305 ++
3306 ++ return 1;
3307 ++}
3308 ++
3309 ++void pax_report_insns(void *pc, void *sp)
3310 ++{
3311 ++ unsigned long i;
3312 ++
3313 ++ printk(KERN_ERR "PAX: bytes at PC: ");
3314 ++ for (i = 0; i < 5; i++) {
3315 ++ unsigned int c;
3316 ++ if (get_user(c, (unsigned int *)pc+i))
3317 ++ printk(KERN_CONT "???????? ");
3318 ++ else
3319 ++ printk(KERN_CONT "%08x ", c);
3320 ++ }
3321 ++ printk("\n");
3322 ++}
3323 ++#endif
3324 ++
3325 + void do_page_fault(struct pt_regs *regs, unsigned long code,
3326 + unsigned long address)
3327 + {
3328 +@@ -165,8 +276,33 @@ good_area:
3329 +
3330 + acc_type = parisc_acctyp(code,regs->iir);
3331 +
3332 +- if ((vma->vm_flags & acc_type) != acc_type)
3333 ++ if ((vma->vm_flags & acc_type) != acc_type) {
3334 ++
3335 ++#ifdef CONFIG_PAX_PAGEEXEC
3336 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3337 ++ (address & ~3UL) == instruction_pointer(regs))
3338 ++ {
3339 ++ up_read(&mm->mmap_sem);
3340 ++ switch (pax_handle_fetch_fault(regs)) {
3341 ++
3342 ++#ifdef CONFIG_PAX_EMUPLT
3343 ++ case 3:
3344 ++ return;
3345 ++#endif
3346 ++
3347 ++#ifdef CONFIG_PAX_EMUTRAMP
3348 ++ case 2:
3349 ++ return;
3350 ++#endif
3351 ++
3352 ++ }
3353 ++ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3354 ++ do_group_exit(SIGKILL);
3355 ++ }
3356 ++#endif
3357 ++
3358 + goto bad_area;
3359 ++ }
3360 +
3361 + /*
3362 + * If for any reason at all we couldn't handle the fault, make
3363 +diff -urNp linux-2.6.28/arch/powerpc/include/asm/elf.h linux-2.6.28/arch/powerpc/include/asm/elf.h
3364 +--- linux-2.6.28/arch/powerpc/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
3365 ++++ linux-2.6.28/arch/powerpc/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
3366 +@@ -180,6 +180,18 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[E
3367 +
3368 + #define ELF_ET_DYN_BASE (0x20000000)
3369 +
3370 ++#ifdef CONFIG_PAX_ASLR
3371 ++#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3372 ++
3373 ++#ifdef __powerpc64__
3374 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
3375 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 16 : 28)
3376 ++#else
3377 ++#define PAX_DELTA_MMAP_LEN 15
3378 ++#define PAX_DELTA_STACK_LEN 15
3379 ++#endif
3380 ++#endif
3381 ++
3382 + /*
3383 + * Our registers are always unsigned longs, whether we're a 32 bit
3384 + * process or 64 bit, on either a 64 bit or 32 bit kernel.
3385 +diff -urNp linux-2.6.28/arch/powerpc/include/asm/kmap_types.h linux-2.6.28/arch/powerpc/include/asm/kmap_types.h
3386 +--- linux-2.6.28/arch/powerpc/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
3387 ++++ linux-2.6.28/arch/powerpc/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
3388 +@@ -26,6 +26,7 @@ enum km_type {
3389 + KM_SOFTIRQ1,
3390 + KM_PPC_SYNC_PAGE,
3391 + KM_PPC_SYNC_ICACHE,
3392 ++ KM_CLEARPAGE,
3393 + KM_TYPE_NR
3394 + };
3395 +
3396 +diff -urNp linux-2.6.28/arch/powerpc/include/asm/page_64.h linux-2.6.28/arch/powerpc/include/asm/page_64.h
3397 +--- linux-2.6.28/arch/powerpc/include/asm/page_64.h 2008-12-24 18:26:37.000000000 -0500
3398 ++++ linux-2.6.28/arch/powerpc/include/asm/page_64.h 2009-01-11 07:20:06.000000000 -0500
3399 +@@ -170,15 +170,18 @@ do { \
3400 + * stack by default, so in the absense of a PT_GNU_STACK program header
3401 + * we turn execute permission off.
3402 + */
3403 +-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3404 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3405 ++#define VM_STACK_DEFAULT_FLAGS32 \
3406 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3407 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3408 +
3409 + #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3410 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3411 +
3412 ++#ifndef CONFIG_PAX_PAGEEXEC
3413 + #define VM_STACK_DEFAULT_FLAGS \
3414 + (test_thread_flag(TIF_32BIT) ? \
3415 + VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3416 ++#endif
3417 +
3418 + #include <asm-generic/page.h>
3419 +
3420 +diff -urNp linux-2.6.28/arch/powerpc/include/asm/page.h linux-2.6.28/arch/powerpc/include/asm/page.h
3421 +--- linux-2.6.28/arch/powerpc/include/asm/page.h 2008-12-24 18:26:37.000000000 -0500
3422 ++++ linux-2.6.28/arch/powerpc/include/asm/page.h 2009-01-11 07:20:06.000000000 -0500
3423 +@@ -111,8 +111,9 @@ extern phys_addr_t kernstart_addr;
3424 + * and needs to be executable. This means the whole heap ends
3425 + * up being executable.
3426 + */
3427 +-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3428 +- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3429 ++#define VM_DATA_DEFAULT_FLAGS32 \
3430 ++ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3431 ++ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3432 +
3433 + #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3434 + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3435 +diff -urNp linux-2.6.28/arch/powerpc/kernel/module_32.c linux-2.6.28/arch/powerpc/kernel/module_32.c
3436 +--- linux-2.6.28/arch/powerpc/kernel/module_32.c 2008-12-24 18:26:37.000000000 -0500
3437 ++++ linux-2.6.28/arch/powerpc/kernel/module_32.c 2009-01-11 07:20:06.000000000 -0500
3438 +@@ -158,7 +158,7 @@ int module_frob_arch_sections(Elf32_Ehdr
3439 + me->arch.core_plt_section = i;
3440 + }
3441 + if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
3442 +- printk("Module doesn't contain .plt or .init.plt sections.\n");
3443 ++ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
3444 + return -ENOEXEC;
3445 + }
3446 +
3447 +@@ -199,11 +199,16 @@ static uint32_t do_plt_call(void *locati
3448 +
3449 + DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
3450 + /* Init, or core PLT? */
3451 +- if (location >= mod->module_core
3452 +- && location < mod->module_core + mod->core_size)
3453 ++ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
3454 ++ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
3455 + entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
3456 +- else
3457 ++ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
3458 ++ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
3459 + entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
3460 ++ else {
3461 ++ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
3462 ++ return ~0UL;
3463 ++ }
3464 +
3465 + /* Find this entry, or if that fails, the next avail. entry */
3466 + while (entry->jump[0]) {
3467 +diff -urNp linux-2.6.28/arch/powerpc/kernel/signal_32.c linux-2.6.28/arch/powerpc/kernel/signal_32.c
3468 +--- linux-2.6.28/arch/powerpc/kernel/signal_32.c 2008-12-24 18:26:37.000000000 -0500
3469 ++++ linux-2.6.28/arch/powerpc/kernel/signal_32.c 2009-01-11 07:20:06.000000000 -0500
3470 +@@ -857,7 +857,7 @@ int handle_rt_signal32(unsigned long sig
3471 + /* Save user registers on the stack */
3472 + frame = &rt_sf->uc.uc_mcontext;
3473 + addr = frame;
3474 +- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
3475 ++ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3476 + if (save_user_regs(regs, frame, 0, 1))
3477 + goto badframe;
3478 + regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
3479 +diff -urNp linux-2.6.28/arch/powerpc/kernel/signal_64.c linux-2.6.28/arch/powerpc/kernel/signal_64.c
3480 +--- linux-2.6.28/arch/powerpc/kernel/signal_64.c 2008-12-24 18:26:37.000000000 -0500
3481 ++++ linux-2.6.28/arch/powerpc/kernel/signal_64.c 2009-01-11 07:20:06.000000000 -0500
3482 +@@ -429,7 +429,7 @@ int handle_rt_signal64(int signr, struct
3483 + current->thread.fpscr.val = 0;
3484 +
3485 + /* Set up to return from userspace. */
3486 +- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
3487 ++ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
3488 + regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
3489 + } else {
3490 + err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
3491 +diff -urNp linux-2.6.28/arch/powerpc/kernel/vdso.c linux-2.6.28/arch/powerpc/kernel/vdso.c
3492 +--- linux-2.6.28/arch/powerpc/kernel/vdso.c 2008-12-24 18:26:37.000000000 -0500
3493 ++++ linux-2.6.28/arch/powerpc/kernel/vdso.c 2009-01-11 07:20:06.000000000 -0500
3494 +@@ -212,7 +212,7 @@ int arch_setup_additional_pages(struct l
3495 + vdso_base = VDSO32_MBASE;
3496 + #endif
3497 +
3498 +- current->mm->context.vdso_base = 0;
3499 ++ current->mm->context.vdso_base = ~0UL;
3500 +
3501 + /* vDSO has a problem and was disabled, just don't "enable" it for the
3502 + * process
3503 +@@ -229,7 +229,7 @@ int arch_setup_additional_pages(struct l
3504 + */
3505 + down_write(&mm->mmap_sem);
3506 + vdso_base = get_unmapped_area(NULL, vdso_base,
3507 +- vdso_pages << PAGE_SHIFT, 0, 0);
3508 ++ vdso_pages << PAGE_SHIFT, 0, MAP_PRIVATE | MAP_EXECUTABLE);
3509 + if (IS_ERR_VALUE(vdso_base)) {
3510 + rc = vdso_base;
3511 + goto fail_mmapsem;
3512 +diff -urNp linux-2.6.28/arch/powerpc/mm/fault.c linux-2.6.28/arch/powerpc/mm/fault.c
3513 +--- linux-2.6.28/arch/powerpc/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
3514 ++++ linux-2.6.28/arch/powerpc/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
3515 +@@ -29,6 +29,10 @@
3516 + #include <linux/module.h>
3517 + #include <linux/kprobes.h>
3518 + #include <linux/kdebug.h>
3519 ++#include <linux/slab.h>
3520 ++#include <linux/pagemap.h>
3521 ++#include <linux/compiler.h>
3522 ++#include <linux/unistd.h>
3523 +
3524 + #include <asm/page.h>
3525 + #include <asm/pgtable.h>
3526 +@@ -62,6 +66,363 @@ static inline int notify_page_fault(stru
3527 + }
3528 + #endif
3529 +
3530 ++#ifdef CONFIG_PAX_EMUSIGRT
3531 ++void pax_syscall_close(struct vm_area_struct *vma)
3532 ++{
3533 ++ vma->vm_mm->call_syscall = 0UL;
3534 ++}
3535 ++
3536 ++static int pax_syscall_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
3537 ++{
3538 ++ unsigned int *kaddr;
3539 ++
3540 ++ vmf->page = alloc_page(GFP_HIGHUSER);
3541 ++ if (!vmf->page)
3542 ++ return VM_FAULT_OOM;
3543 ++
3544 ++ kaddr = kmap(vmf->page);
3545 ++ memset(kaddr, 0, PAGE_SIZE);
3546 ++ kaddr[0] = 0x44000002U; /* sc */
3547 ++ __flush_dcache_icache(kaddr);
3548 ++ kunmap(vmf->page);
3549 ++ return VM_FAULT_MAJOR;
3550 ++}
3551 ++
3552 ++static struct vm_operations_struct pax_vm_ops = {
3553 ++ .close = pax_syscall_close,
3554 ++ .fault = pax_syscall_fault
3555 ++};
3556 ++
3557 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
3558 ++{
3559 ++ int ret;
3560 ++
3561 ++ vma->vm_mm = current->mm;
3562 ++ vma->vm_start = addr;
3563 ++ vma->vm_end = addr + PAGE_SIZE;
3564 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
3565 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
3566 ++ vma->vm_ops = &pax_vm_ops;
3567 ++
3568 ++ ret = insert_vm_struct(current->mm, vma);
3569 ++ if (ret)
3570 ++ return ret;
3571 ++
3572 ++ ++current->mm->total_vm;
3573 ++ return 0;
3574 ++}
3575 ++#endif
3576 ++
3577 ++#ifdef CONFIG_PAX_PAGEEXEC
3578 ++/*
3579 ++ * PaX: decide what to do with offenders (regs->nip = fault address)
3580 ++ *
3581 ++ * returns 1 when task should be killed
3582 ++ * 2 when patched GOT trampoline was detected
3583 ++ * 3 when patched PLT trampoline was detected
3584 ++ * 4 when unpatched PLT trampoline was detected
3585 ++ * 5 when sigreturn trampoline was detected
3586 ++ * 6 when rt_sigreturn trampoline was detected
3587 ++ */
3588 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
3589 ++{
3590 ++
3591 ++#if defined(CONFIG_PAX_EMUPLT) || defined(CONFIG_PAX_EMUSIGRT)
3592 ++ int err;
3593 ++#endif
3594 ++
3595 ++#ifdef CONFIG_PAX_EMUPLT
3596 ++ do { /* PaX: patched GOT emulation */
3597 ++ unsigned int blrl;
3598 ++
3599 ++ err = get_user(blrl, (unsigned int *)regs->nip);
3600 ++
3601 ++ if (!err && blrl == 0x4E800021U) {
3602 ++ unsigned long temp = regs->nip;
3603 ++
3604 ++ regs->nip = regs->link & 0xFFFFFFFCUL;
3605 ++ regs->link = temp + 4UL;
3606 ++ return 2;
3607 ++ }
3608 ++ } while (0);
3609 ++
3610 ++ do { /* PaX: patched PLT emulation #1 */
3611 ++ unsigned int b;
3612 ++
3613 ++ err = get_user(b, (unsigned int *)regs->nip);
3614 ++
3615 ++ if (!err && (b & 0xFC000003U) == 0x48000000U) {
3616 ++ regs->nip += (((b | 0xFC000000UL) ^ 0x02000000UL) + 0x02000000UL);
3617 ++ return 3;
3618 ++ }
3619 ++ } while (0);
3620 ++
3621 ++ do { /* PaX: unpatched PLT emulation #1 */
3622 ++ unsigned int li, b;
3623 ++
3624 ++ err = get_user(li, (unsigned int *)regs->nip);
3625 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
3626 ++
3627 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
3628 ++ unsigned int rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
3629 ++ unsigned long addr = b | 0xFC000000UL;
3630 ++
3631 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
3632 ++ err = get_user(rlwinm, (unsigned int *)addr);
3633 ++ err |= get_user(add, (unsigned int *)(addr+4));
3634 ++ err |= get_user(li2, (unsigned int *)(addr+8));
3635 ++ err |= get_user(addis2, (unsigned int *)(addr+12));
3636 ++ err |= get_user(mtctr, (unsigned int *)(addr+16));
3637 ++ err |= get_user(li3, (unsigned int *)(addr+20));
3638 ++ err |= get_user(addis3, (unsigned int *)(addr+24));
3639 ++ err |= get_user(bctr, (unsigned int *)(addr+28));
3640 ++
3641 ++ if (err)
3642 ++ break;
3643 ++
3644 ++ if (rlwinm == 0x556C083CU &&
3645 ++ add == 0x7D6C5A14U &&
3646 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
3647 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
3648 ++ mtctr == 0x7D8903A6U &&
3649 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
3650 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
3651 ++ bctr == 0x4E800420U)
3652 ++ {
3653 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3654 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3655 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
3656 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3657 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
3658 ++ regs->nip = regs->ctr;
3659 ++ return 4;
3660 ++ }
3661 ++ }
3662 ++ } while (0);
3663 ++
3664 ++#if 0
3665 ++ do { /* PaX: unpatched PLT emulation #2 */
3666 ++ unsigned int lis, lwzu, b, bctr;
3667 ++
3668 ++ err = get_user(lis, (unsigned int *)regs->nip);
3669 ++ err |= get_user(lwzu, (unsigned int *)(regs->nip+4));
3670 ++ err |= get_user(b, (unsigned int *)(regs->nip+8));
3671 ++ err |= get_user(bctr, (unsigned int *)(regs->nip+12));
3672 ++
3673 ++ if (err)
3674 ++ break;
3675 ++
3676 ++ if ((lis & 0xFFFF0000U) == 0x39600000U &&
3677 ++ (lwzu & 0xU) == 0xU &&
3678 ++ (b & 0xFC000003U) == 0x48000000U &&
3679 ++ bctr == 0x4E800420U)
3680 ++ {
3681 ++ unsigned int addis, addi, rlwinm, add, li2, addis2, mtctr, li3, addis3, bctr;
3682 ++ unsigned long addr = b | 0xFC000000UL;
3683 ++
3684 ++ addr = regs->nip + 12 + ((addr ^ 0x02000000UL) + 0x02000000UL);
3685 ++ err = get_user(addis, (unsigned int *)addr);
3686 ++ err |= get_user(addi, (unsigned int *)(addr+4));
3687 ++ err |= get_user(rlwinm, (unsigned int *)(addr+8));
3688 ++ err |= get_user(add, (unsigned int *)(addr+12));
3689 ++ err |= get_user(li2, (unsigned int *)(addr+16));
3690 ++ err |= get_user(addis2, (unsigned int *)(addr+20));
3691 ++ err |= get_user(mtctr, (unsigned int *)(addr+24));
3692 ++ err |= get_user(li3, (unsigned int *)(addr+28));
3693 ++ err |= get_user(addis3, (unsigned int *)(addr+32));
3694 ++ err |= get_user(bctr, (unsigned int *)(addr+36));
3695 ++
3696 ++ if (err)
3697 ++ break;
3698 ++
3699 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
3700 ++ (addi & 0xFFFF0000U) == 0x396B0000U &&
3701 ++ rlwinm == 0x556C083CU &&
3702 ++ add == 0x7D6C5A14U &&
3703 ++ (li2 & 0xFFFF0000U) == 0x39800000U &&
3704 ++ (addis2 & 0xFFFF0000U) == 0x3D8C0000U &&
3705 ++ mtctr == 0x7D8903A6U &&
3706 ++ (li3 & 0xFFFF0000U) == 0x39800000U &&
3707 ++ (addis3 & 0xFFFF0000U) == 0x3D8C0000U &&
3708 ++ bctr == 0x4E800420U)
3709 ++ {
3710 ++ regs->gpr[PT_R11] = 3 * (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3711 ++ regs->gpr[PT_R12] = (((li3 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3712 ++ regs->gpr[PT_R12] += (addis3 & 0xFFFFU) << 16;
3713 ++ regs->ctr = (((li2 | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3714 ++ regs->ctr += (addis2 & 0xFFFFU) << 16;
3715 ++ regs->nip = regs->ctr;
3716 ++ return 4;
3717 ++ }
3718 ++ }
3719 ++ } while (0);
3720 ++#endif
3721 ++
3722 ++ do { /* PaX: unpatched PLT emulation #3 */
3723 ++ unsigned int li, b;
3724 ++
3725 ++ err = get_user(li, (unsigned int *)regs->nip);
3726 ++ err |= get_user(b, (unsigned int *)(regs->nip+4));
3727 ++
3728 ++ if (!err && (li & 0xFFFF0000U) == 0x39600000U && (b & 0xFC000003U) == 0x48000000U) {
3729 ++ unsigned int addis, lwz, mtctr, bctr;
3730 ++ unsigned long addr = b | 0xFC000000UL;
3731 ++
3732 ++ addr = regs->nip + 4 + ((addr ^ 0x02000000UL) + 0x02000000UL);
3733 ++ err = get_user(addis, (unsigned int *)addr);
3734 ++ err |= get_user(lwz, (unsigned int *)(addr+4));
3735 ++ err |= get_user(mtctr, (unsigned int *)(addr+8));
3736 ++ err |= get_user(bctr, (unsigned int *)(addr+12));
3737 ++
3738 ++ if (err)
3739 ++ break;
3740 ++
3741 ++ if ((addis & 0xFFFF0000U) == 0x3D6B0000U &&
3742 ++ (lwz & 0xFFFF0000U) == 0x816B0000U &&
3743 ++ mtctr == 0x7D6903A6U &&
3744 ++ bctr == 0x4E800420U)
3745 ++ {
3746 ++ unsigned int r11;
3747 ++
3748 ++ addr = (addis << 16) + (((li | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3749 ++ addr += (((lwz | 0xFFFF0000UL) ^ 0x00008000UL) + 0x00008000UL);
3750 ++
3751 ++ err = get_user(r11, (unsigned int *)addr);
3752 ++ if (err)
3753 ++ break;
3754 ++
3755 ++ regs->gpr[PT_R11] = r11;
3756 ++ regs->ctr = r11;
3757 ++ regs->nip = r11;
3758 ++ return 4;
3759 ++ }
3760 ++ }
3761 ++ } while (0);
3762 ++#endif
3763 ++
3764 ++#ifdef CONFIG_PAX_EMUSIGRT
3765 ++ do { /* PaX: sigreturn emulation */
3766 ++ unsigned int li, sc;
3767 ++
3768 ++ err = get_user(li, (unsigned int *)regs->nip);
3769 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
3770 ++
3771 ++ if (!err && li == 0x38000000U + __NR_sigreturn && sc == 0x44000002U) {
3772 ++ struct vm_area_struct *vma;
3773 ++ unsigned long call_syscall;
3774 ++
3775 ++ down_read(&current->mm->mmap_sem);
3776 ++ call_syscall = current->mm->call_syscall;
3777 ++ up_read(&current->mm->mmap_sem);
3778 ++ if (likely(call_syscall))
3779 ++ goto emulate;
3780 ++
3781 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
3782 ++
3783 ++ down_write(&current->mm->mmap_sem);
3784 ++ if (current->mm->call_syscall) {
3785 ++ call_syscall = current->mm->call_syscall;
3786 ++ up_write(&current->mm->mmap_sem);
3787 ++ if (vma)
3788 ++ kmem_cache_free(vm_area_cachep, vma);
3789 ++ goto emulate;
3790 ++ }
3791 ++
3792 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
3793 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
3794 ++ up_write(&current->mm->mmap_sem);
3795 ++ if (vma)
3796 ++ kmem_cache_free(vm_area_cachep, vma);
3797 ++ return 1;
3798 ++ }
3799 ++
3800 ++ if (pax_insert_vma(vma, call_syscall)) {
3801 ++ up_write(&current->mm->mmap_sem);
3802 ++ kmem_cache_free(vm_area_cachep, vma);
3803 ++ return 1;
3804 ++ }
3805 ++
3806 ++ current->mm->call_syscall = call_syscall;
3807 ++ up_write(&current->mm->mmap_sem);
3808 ++
3809 ++emulate:
3810 ++ regs->gpr[PT_R0] = __NR_sigreturn;
3811 ++ regs->nip = call_syscall;
3812 ++ return 5;
3813 ++ }
3814 ++ } while (0);
3815 ++
3816 ++ do { /* PaX: rt_sigreturn emulation */
3817 ++ unsigned int li, sc;
3818 ++
3819 ++ err = get_user(li, (unsigned int *)regs->nip);
3820 ++ err |= get_user(sc, (unsigned int *)(regs->nip+4));
3821 ++
3822 ++ if (!err && li == 0x38000000U + __NR_rt_sigreturn && sc == 0x44000002U) {
3823 ++ struct vm_area_struct *vma;
3824 ++ unsigned int call_syscall;
3825 ++
3826 ++ down_read(&current->mm->mmap_sem);
3827 ++ call_syscall = current->mm->call_syscall;
3828 ++ up_read(&current->mm->mmap_sem);
3829 ++ if (likely(call_syscall))
3830 ++ goto rt_emulate;
3831 ++
3832 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
3833 ++
3834 ++ down_write(&current->mm->mmap_sem);
3835 ++ if (current->mm->call_syscall) {
3836 ++ call_syscall = current->mm->call_syscall;
3837 ++ up_write(&current->mm->mmap_sem);
3838 ++ if (vma)
3839 ++ kmem_cache_free(vm_area_cachep, vma);
3840 ++ goto rt_emulate;
3841 ++ }
3842 ++
3843 ++ call_syscall = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
3844 ++ if (!vma || (call_syscall & ~PAGE_MASK)) {
3845 ++ up_write(&current->mm->mmap_sem);
3846 ++ if (vma)
3847 ++ kmem_cache_free(vm_area_cachep, vma);
3848 ++ return 1;
3849 ++ }
3850 ++
3851 ++ if (pax_insert_vma(vma, call_syscall)) {
3852 ++ up_write(&current->mm->mmap_sem);
3853 ++ kmem_cache_free(vm_area_cachep, vma);
3854 ++ return 1;
3855 ++ }
3856 ++
3857 ++ current->mm->call_syscall = call_syscall;
3858 ++ up_write(&current->mm->mmap_sem);
3859 ++
3860 ++rt_emulate:
3861 ++ regs->gpr[PT_R0] = __NR_rt_sigreturn;
3862 ++ regs->nip = call_syscall;
3863 ++ return 6;
3864 ++ }
3865 ++ } while (0);
3866 ++#endif
3867 ++
3868 ++ return 1;
3869 ++}
3870 ++
3871 ++void pax_report_insns(void *pc, void *sp)
3872 ++{
3873 ++ unsigned long i;
3874 ++
3875 ++ printk(KERN_ERR "PAX: bytes at PC: ");
3876 ++ for (i = 0; i < 5; i++) {
3877 ++ unsigned int c;
3878 ++ if (get_user(c, (unsigned int *)pc+i))
3879 ++ printk(KERN_CONT "???????? ");
3880 ++ else
3881 ++ printk(KERN_CONT "%08x ", c);
3882 ++ }
3883 ++ printk("\n");
3884 ++}
3885 ++#endif
3886 ++
3887 + /*
3888 + * Check whether the instruction at regs->nip is a store using
3889 + * an update addressing form which will update r1.
3890 +@@ -132,7 +493,7 @@ int __kprobes do_page_fault(struct pt_re
3891 + * indicate errors in DSISR but can validly be set in SRR1.
3892 + */
3893 + if (trap == 0x400)
3894 +- error_code &= 0x48200000;
3895 ++ error_code &= 0x58200000;
3896 + else
3897 + is_write = error_code & DSISR_ISSTORE;
3898 + #else
3899 +@@ -331,6 +692,37 @@ bad_area:
3900 + bad_area_nosemaphore:
3901 + /* User mode accesses cause a SIGSEGV */
3902 + if (user_mode(regs)) {
3903 ++
3904 ++#ifdef CONFIG_PAX_PAGEEXEC
3905 ++ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
3906 ++#ifdef CONFIG_PPC64
3907 ++ if (is_exec && (error_code & DSISR_PROTFAULT)) {
3908 ++#else
3909 ++ if (is_exec && regs->nip == address) {
3910 ++#endif
3911 ++ switch (pax_handle_fetch_fault(regs)) {
3912 ++
3913 ++#ifdef CONFIG_PAX_EMUPLT
3914 ++ case 2:
3915 ++ case 3:
3916 ++ case 4:
3917 ++ return 0;
3918 ++#endif
3919 ++
3920 ++#ifdef CONFIG_PAX_EMUSIGRT
3921 ++ case 5:
3922 ++ case 6:
3923 ++ return 0;
3924 ++#endif
3925 ++
3926 ++ }
3927 ++
3928 ++ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
3929 ++ do_group_exit(SIGKILL);
3930 ++ }
3931 ++ }
3932 ++#endif
3933 ++
3934 + _exception(SIGSEGV, regs, code, address);
3935 + return 0;
3936 + }
3937 +diff -urNp linux-2.6.28/arch/powerpc/mm/mmap.c linux-2.6.28/arch/powerpc/mm/mmap.c
3938 +--- linux-2.6.28/arch/powerpc/mm/mmap.c 2008-12-24 18:26:37.000000000 -0500
3939 ++++ linux-2.6.28/arch/powerpc/mm/mmap.c 2009-01-11 07:20:06.000000000 -0500
3940 +@@ -75,10 +75,22 @@ void arch_pick_mmap_layout(struct mm_str
3941 + */
3942 + if (mmap_is_legacy()) {
3943 + mm->mmap_base = TASK_UNMAPPED_BASE;
3944 ++
3945 ++#ifdef CONFIG_PAX_RANDMMAP
3946 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
3947 ++ mm->mmap_base += mm->delta_mmap;
3948 ++#endif
3949 ++
3950 + mm->get_unmapped_area = arch_get_unmapped_area;
3951 + mm->unmap_area = arch_unmap_area;
3952 + } else {
3953 + mm->mmap_base = mmap_base();
3954 ++
3955 ++#ifdef CONFIG_PAX_RANDMMAP
3956 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
3957 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3958 ++#endif
3959 ++
3960 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3961 + mm->unmap_area = arch_unmap_area_topdown;
3962 + }
3963 +diff -urNp linux-2.6.28/arch/s390/include/asm/kmap_types.h linux-2.6.28/arch/s390/include/asm/kmap_types.h
3964 +--- linux-2.6.28/arch/s390/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
3965 ++++ linux-2.6.28/arch/s390/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
3966 +@@ -16,6 +16,7 @@ enum km_type {
3967 + KM_IRQ1,
3968 + KM_SOFTIRQ0,
3969 + KM_SOFTIRQ1,
3970 ++ KM_CLEARPAGE,
3971 + KM_TYPE_NR
3972 + };
3973 +
3974 +diff -urNp linux-2.6.28/arch/s390/kernel/module.c linux-2.6.28/arch/s390/kernel/module.c
3975 +--- linux-2.6.28/arch/s390/kernel/module.c 2008-12-24 18:26:37.000000000 -0500
3976 ++++ linux-2.6.28/arch/s390/kernel/module.c 2009-01-11 07:20:06.000000000 -0500
3977 +@@ -166,11 +166,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr,
3978 +
3979 + /* Increase core size by size of got & plt and set start
3980 + offsets for got and plt. */
3981 +- me->core_size = ALIGN(me->core_size, 4);
3982 +- me->arch.got_offset = me->core_size;
3983 +- me->core_size += me->arch.got_size;
3984 +- me->arch.plt_offset = me->core_size;
3985 +- me->core_size += me->arch.plt_size;
3986 ++ me->core_size_rw = ALIGN(me->core_size_rw, 4);
3987 ++ me->arch.got_offset = me->core_size_rw;
3988 ++ me->core_size_rw += me->arch.got_size;
3989 ++ me->arch.plt_offset = me->core_size_rx;
3990 ++ me->core_size_rx += me->arch.plt_size;
3991 + return 0;
3992 + }
3993 +
3994 +@@ -256,7 +256,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
3995 + if (info->got_initialized == 0) {
3996 + Elf_Addr *gotent;
3997 +
3998 +- gotent = me->module_core + me->arch.got_offset +
3999 ++ gotent = me->module_core_rw + me->arch.got_offset +
4000 + info->got_offset;
4001 + *gotent = val;
4002 + info->got_initialized = 1;
4003 +@@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4004 + else if (r_type == R_390_GOTENT ||
4005 + r_type == R_390_GOTPLTENT)
4006 + *(unsigned int *) loc =
4007 +- (val + (Elf_Addr) me->module_core - loc) >> 1;
4008 ++ (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4009 + else if (r_type == R_390_GOT64 ||
4010 + r_type == R_390_GOTPLT64)
4011 + *(unsigned long *) loc = val;
4012 +@@ -294,7 +294,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4013 + case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4014 + if (info->plt_initialized == 0) {
4015 + unsigned int *ip;
4016 +- ip = me->module_core + me->arch.plt_offset +
4017 ++ ip = me->module_core_rx + me->arch.plt_offset +
4018 + info->plt_offset;
4019 + #ifndef CONFIG_64BIT
4020 + ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4021 +@@ -316,7 +316,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4022 + val = me->arch.plt_offset - me->arch.got_offset +
4023 + info->plt_offset + rela->r_addend;
4024 + else
4025 +- val = (Elf_Addr) me->module_core +
4026 ++ val = (Elf_Addr) me->module_core_rx +
4027 + me->arch.plt_offset + info->plt_offset +
4028 + rela->r_addend - loc;
4029 + if (r_type == R_390_PLT16DBL)
4030 +@@ -336,7 +336,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4031 + case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4032 + case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4033 + val = val + rela->r_addend -
4034 +- ((Elf_Addr) me->module_core + me->arch.got_offset);
4035 ++ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4036 + if (r_type == R_390_GOTOFF16)
4037 + *(unsigned short *) loc = val;
4038 + else if (r_type == R_390_GOTOFF32)
4039 +@@ -346,7 +346,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base
4040 + break;
4041 + case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4042 + case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4043 +- val = (Elf_Addr) me->module_core + me->arch.got_offset +
4044 ++ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4045 + rela->r_addend - loc;
4046 + if (r_type == R_390_GOTPC)
4047 + *(unsigned int *) loc = val;
4048 +diff -urNp linux-2.6.28/arch/sh/include/asm/kmap_types.h linux-2.6.28/arch/sh/include/asm/kmap_types.h
4049 +--- linux-2.6.28/arch/sh/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
4050 ++++ linux-2.6.28/arch/sh/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
4051 +@@ -24,7 +24,8 @@ D(9) KM_IRQ0,
4052 + D(10) KM_IRQ1,
4053 + D(11) KM_SOFTIRQ0,
4054 + D(12) KM_SOFTIRQ1,
4055 +-D(13) KM_TYPE_NR
4056 ++D(13) KM_CLEARPAGE,
4057 ++D(14) KM_TYPE_NR
4058 + };
4059 +
4060 + #undef D
4061 +diff -urNp linux-2.6.28/arch/sparc/include/asm/elf_32.h linux-2.6.28/arch/sparc/include/asm/elf_32.h
4062 +--- linux-2.6.28/arch/sparc/include/asm/elf_32.h 2008-12-24 18:26:37.000000000 -0500
4063 ++++ linux-2.6.28/arch/sparc/include/asm/elf_32.h 2009-01-11 07:20:06.000000000 -0500
4064 +@@ -116,6 +116,13 @@ typedef struct {
4065 +
4066 + #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
4067 +
4068 ++#ifdef CONFIG_PAX_ASLR
4069 ++#define PAX_ELF_ET_DYN_BASE 0x10000UL
4070 ++
4071 ++#define PAX_DELTA_MMAP_LEN 16
4072 ++#define PAX_DELTA_STACK_LEN 16
4073 ++#endif
4074 ++
4075 + /* This yields a mask that user programs can use to figure out what
4076 + instruction set this cpu supports. This can NOT be done in userspace
4077 + on Sparc. */
4078 +diff -urNp linux-2.6.28/arch/sparc/include/asm/elf_64.h linux-2.6.28/arch/sparc/include/asm/elf_64.h
4079 +--- linux-2.6.28/arch/sparc/include/asm/elf_64.h 2008-12-24 18:26:37.000000000 -0500
4080 ++++ linux-2.6.28/arch/sparc/include/asm/elf_64.h 2009-01-11 07:20:06.000000000 -0500
4081 +@@ -163,6 +163,12 @@ typedef struct {
4082 + #define ELF_ET_DYN_BASE 0x0000010000000000UL
4083 + #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
4084 +
4085 ++#ifdef CONFIG_PAX_ASLR
4086 ++#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
4087 ++
4088 ++#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28 )
4089 ++#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29 )
4090 ++#endif
4091 +
4092 + /* This yields a mask that user programs can use to figure out what
4093 + instruction set this cpu supports. */
4094 +diff -urNp linux-2.6.28/arch/sparc/include/asm/kmap_types.h linux-2.6.28/arch/sparc/include/asm/kmap_types.h
4095 +--- linux-2.6.28/arch/sparc/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
4096 ++++ linux-2.6.28/arch/sparc/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
4097 +@@ -19,6 +19,7 @@ enum km_type {
4098 + KM_IRQ1,
4099 + KM_SOFTIRQ0,
4100 + KM_SOFTIRQ1,
4101 ++ KM_CLEARPAGE,
4102 + KM_TYPE_NR
4103 + };
4104 +
4105 +diff -urNp linux-2.6.28/arch/sparc/include/asm/pgtable_32.h linux-2.6.28/arch/sparc/include/asm/pgtable_32.h
4106 +--- linux-2.6.28/arch/sparc/include/asm/pgtable_32.h 2008-12-24 18:26:37.000000000 -0500
4107 ++++ linux-2.6.28/arch/sparc/include/asm/pgtable_32.h 2009-01-11 07:20:06.000000000 -0500
4108 +@@ -43,6 +43,13 @@ BTFIXUPDEF_SIMM13(user_ptrs_per_pgd)
4109 + BTFIXUPDEF_INT(page_none)
4110 + BTFIXUPDEF_INT(page_copy)
4111 + BTFIXUPDEF_INT(page_readonly)
4112 ++
4113 ++#ifdef CONFIG_PAX_PAGEEXEC
4114 ++BTFIXUPDEF_INT(page_shared_noexec)
4115 ++BTFIXUPDEF_INT(page_copy_noexec)
4116 ++BTFIXUPDEF_INT(page_readonly_noexec)
4117 ++#endif
4118 ++
4119 + BTFIXUPDEF_INT(page_kernel)
4120 +
4121 + #define PMD_SHIFT SUN4C_PMD_SHIFT
4122 +@@ -64,6 +71,16 @@ extern pgprot_t PAGE_SHARED;
4123 + #define PAGE_COPY __pgprot(BTFIXUP_INT(page_copy))
4124 + #define PAGE_READONLY __pgprot(BTFIXUP_INT(page_readonly))
4125 +
4126 ++#ifdef CONFIG_PAX_PAGEEXEC
4127 ++extern pgprot_t PAGE_SHARED_NOEXEC;
4128 ++# define PAGE_COPY_NOEXEC __pgprot(BTFIXUP_INT(page_copy_noexec))
4129 ++# define PAGE_READONLY_NOEXEC __pgprot(BTFIXUP_INT(page_readonly_noexec))
4130 ++#else
4131 ++# define PAGE_SHARED_NOEXEC PAGE_SHARED
4132 ++# define PAGE_COPY_NOEXEC PAGE_COPY
4133 ++# define PAGE_READONLY_NOEXEC PAGE_READONLY
4134 ++#endif
4135 ++
4136 + extern unsigned long page_kernel;
4137 +
4138 + #ifdef MODULE
4139 +diff -urNp linux-2.6.28/arch/sparc/include/asm/pgtsrmmu.h linux-2.6.28/arch/sparc/include/asm/pgtsrmmu.h
4140 +--- linux-2.6.28/arch/sparc/include/asm/pgtsrmmu.h 2008-12-24 18:26:37.000000000 -0500
4141 ++++ linux-2.6.28/arch/sparc/include/asm/pgtsrmmu.h 2009-01-11 07:20:06.000000000 -0500
4142 +@@ -115,6 +115,13 @@
4143 + SRMMU_EXEC | SRMMU_REF)
4144 + #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
4145 + SRMMU_EXEC | SRMMU_REF)
4146 ++
4147 ++#ifdef CONFIG_PAX_PAGEEXEC
4148 ++#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
4149 ++#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4150 ++#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
4151 ++#endif
4152 ++
4153 + #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
4154 + SRMMU_DIRTY | SRMMU_REF)
4155 +
4156 +diff -urNp linux-2.6.28/arch/sparc/kernel/sys_sparc.c linux-2.6.28/arch/sparc/kernel/sys_sparc.c
4157 +--- linux-2.6.28/arch/sparc/kernel/sys_sparc.c 2008-12-24 18:26:37.000000000 -0500
4158 ++++ linux-2.6.28/arch/sparc/kernel/sys_sparc.c 2009-01-11 07:20:06.000000000 -0500
4159 +@@ -56,7 +56,7 @@ unsigned long arch_get_unmapped_area(str
4160 + if (ARCH_SUN4C && len > 0x20000000)
4161 + return -ENOMEM;
4162 + if (!addr)
4163 +- addr = TASK_UNMAPPED_BASE;
4164 ++ addr = current->mm->mmap_base;
4165 +
4166 + if (flags & MAP_SHARED)
4167 + addr = COLOUR_ALIGN(addr);
4168 +diff -urNp linux-2.6.28/arch/sparc/Makefile linux-2.6.28/arch/sparc/Makefile
4169 +--- linux-2.6.28/arch/sparc/Makefile 2008-12-24 18:26:37.000000000 -0500
4170 ++++ linux-2.6.28/arch/sparc/Makefile 2009-01-11 05:46:58.000000000 -0500
4171 +@@ -37,7 +37,7 @@ drivers-$(CONFIG_OPROFILE) += arch/sparc
4172 + # Renaming is done to avoid confusing pattern matching rules in 2.5.45 (multy-)
4173 + INIT_Y := $(patsubst %/, %/built-in.o, $(init-y))
4174 + CORE_Y := $(core-y)
4175 +-CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
4176 ++CORE_Y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
4177 + CORE_Y := $(patsubst %/, %/built-in.o, $(CORE_Y))
4178 + DRIVERS_Y := $(patsubst %/, %/built-in.o, $(drivers-y))
4179 + NET_Y := $(patsubst %/, %/built-in.o, $(net-y))
4180 +diff -urNp linux-2.6.28/arch/sparc/mm/fault.c linux-2.6.28/arch/sparc/mm/fault.c
4181 +--- linux-2.6.28/arch/sparc/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
4182 ++++ linux-2.6.28/arch/sparc/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
4183 +@@ -21,6 +21,9 @@
4184 + #include <linux/interrupt.h>
4185 + #include <linux/module.h>
4186 + #include <linux/kdebug.h>
4187 ++#include <linux/slab.h>
4188 ++#include <linux/pagemap.h>
4189 ++#include <linux/compiler.h>
4190 +
4191 + #include <asm/system.h>
4192 + #include <asm/page.h>
4193 +@@ -167,6 +170,249 @@ static unsigned long compute_si_addr(str
4194 + return safe_compute_effective_address(regs, insn);
4195 + }
4196 +
4197 ++#ifdef CONFIG_PAX_PAGEEXEC
4198 ++void pax_emuplt_close(struct vm_area_struct *vma)
4199 ++{
4200 ++ vma->vm_mm->call_dl_resolve = 0UL;
4201 ++}
4202 ++
4203 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4204 ++{
4205 ++ unsigned int *kaddr;
4206 ++
4207 ++ vmf->page = alloc_page(GFP_HIGHUSER);
4208 ++ if (!vmf->page)
4209 ++ return VM_FAULT_OOM;
4210 ++
4211 ++ kaddr = kmap(vmf->page);
4212 ++ memset(kaddr, 0, PAGE_SIZE);
4213 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
4214 ++ flush_dcache_page(vmf->page);
4215 ++ kunmap(vmf->page);
4216 ++ return VM_FAULT_MAJOR;
4217 ++}
4218 ++
4219 ++static struct vm_operations_struct pax_vm_ops = {
4220 ++ .close = pax_emuplt_close,
4221 ++ .fault = pax_emuplt_fault
4222 ++};
4223 ++
4224 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4225 ++{
4226 ++ int ret;
4227 ++
4228 ++ vma->vm_mm = current->mm;
4229 ++ vma->vm_start = addr;
4230 ++ vma->vm_end = addr + PAGE_SIZE;
4231 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4232 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4233 ++ vma->vm_ops = &pax_vm_ops;
4234 ++
4235 ++ ret = insert_vm_struct(current->mm, vma);
4236 ++ if (ret)
4237 ++ return ret;
4238 ++
4239 ++ ++current->mm->total_vm;
4240 ++ return 0;
4241 ++}
4242 ++
4243 ++/*
4244 ++ * PaX: decide what to do with offenders (regs->pc = fault address)
4245 ++ *
4246 ++ * returns 1 when task should be killed
4247 ++ * 2 when patched PLT trampoline was detected
4248 ++ * 3 when unpatched PLT trampoline was detected
4249 ++ */
4250 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
4251 ++{
4252 ++
4253 ++#ifdef CONFIG_PAX_EMUPLT
4254 ++ int err;
4255 ++
4256 ++ do { /* PaX: patched PLT emulation #1 */
4257 ++ unsigned int sethi1, sethi2, jmpl;
4258 ++
4259 ++ err = get_user(sethi1, (unsigned int *)regs->pc);
4260 ++ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
4261 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
4262 ++
4263 ++ if (err)
4264 ++ break;
4265 ++
4266 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4267 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
4268 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
4269 ++ {
4270 ++ unsigned int addr;
4271 ++
4272 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4273 ++ addr = regs->u_regs[UREG_G1];
4274 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4275 ++ regs->pc = addr;
4276 ++ regs->npc = addr+4;
4277 ++ return 2;
4278 ++ }
4279 ++ } while (0);
4280 ++
4281 ++ { /* PaX: patched PLT emulation #2 */
4282 ++ unsigned int ba;
4283 ++
4284 ++ err = get_user(ba, (unsigned int *)regs->pc);
4285 ++
4286 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4287 ++ unsigned int addr;
4288 ++
4289 ++ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4290 ++ regs->pc = addr;
4291 ++ regs->npc = addr+4;
4292 ++ return 2;
4293 ++ }
4294 ++ }
4295 ++
4296 ++ do { /* PaX: patched PLT emulation #3 */
4297 ++ unsigned int sethi, jmpl, nop;
4298 ++
4299 ++ err = get_user(sethi, (unsigned int *)regs->pc);
4300 ++ err |= get_user(jmpl, (unsigned int *)(regs->pc+4));
4301 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
4302 ++
4303 ++ if (err)
4304 ++ break;
4305 ++
4306 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4307 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4308 ++ nop == 0x01000000U)
4309 ++ {
4310 ++ unsigned int addr;
4311 ++
4312 ++ addr = (sethi & 0x003FFFFFU) << 10;
4313 ++ regs->u_regs[UREG_G1] = addr;
4314 ++ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
4315 ++ regs->pc = addr;
4316 ++ regs->npc = addr+4;
4317 ++ return 2;
4318 ++ }
4319 ++ } while (0);
4320 ++
4321 ++ do { /* PaX: unpatched PLT emulation step 1 */
4322 ++ unsigned int sethi, ba, nop;
4323 ++
4324 ++ err = get_user(sethi, (unsigned int *)regs->pc);
4325 ++ err |= get_user(ba, (unsigned int *)(regs->pc+4));
4326 ++ err |= get_user(nop, (unsigned int *)(regs->pc+8));
4327 ++
4328 ++ if (err)
4329 ++ break;
4330 ++
4331 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4332 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4333 ++ nop == 0x01000000U)
4334 ++ {
4335 ++ unsigned int addr, save, call;
4336 ++
4337 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
4338 ++ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
4339 ++ else
4340 ++ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
4341 ++
4342 ++ err = get_user(save, (unsigned int *)addr);
4343 ++ err |= get_user(call, (unsigned int *)(addr+4));
4344 ++ err |= get_user(nop, (unsigned int *)(addr+8));
4345 ++ if (err)
4346 ++ break;
4347 ++
4348 ++ if (save == 0x9DE3BFA8U &&
4349 ++ (call & 0xC0000000U) == 0x40000000U &&
4350 ++ nop == 0x01000000U)
4351 ++ {
4352 ++ struct vm_area_struct *vma;
4353 ++ unsigned long call_dl_resolve;
4354 ++
4355 ++ down_read(&current->mm->mmap_sem);
4356 ++ call_dl_resolve = current->mm->call_dl_resolve;
4357 ++ up_read(&current->mm->mmap_sem);
4358 ++ if (likely(call_dl_resolve))
4359 ++ goto emulate;
4360 ++
4361 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4362 ++
4363 ++ down_write(&current->mm->mmap_sem);
4364 ++ if (current->mm->call_dl_resolve) {
4365 ++ call_dl_resolve = current->mm->call_dl_resolve;
4366 ++ up_write(&current->mm->mmap_sem);
4367 ++ if (vma)
4368 ++ kmem_cache_free(vm_area_cachep, vma);
4369 ++ goto emulate;
4370 ++ }
4371 ++
4372 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4373 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4374 ++ up_write(&current->mm->mmap_sem);
4375 ++ if (vma)
4376 ++ kmem_cache_free(vm_area_cachep, vma);
4377 ++ return 1;
4378 ++ }
4379 ++
4380 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
4381 ++ up_write(&current->mm->mmap_sem);
4382 ++ kmem_cache_free(vm_area_cachep, vma);
4383 ++ return 1;
4384 ++ }
4385 ++
4386 ++ current->mm->call_dl_resolve = call_dl_resolve;
4387 ++ up_write(&current->mm->mmap_sem);
4388 ++
4389 ++emulate:
4390 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4391 ++ regs->pc = call_dl_resolve;
4392 ++ regs->npc = addr+4;
4393 ++ return 3;
4394 ++ }
4395 ++ }
4396 ++ } while (0);
4397 ++
4398 ++ do { /* PaX: unpatched PLT emulation step 2 */
4399 ++ unsigned int save, call, nop;
4400 ++
4401 ++ err = get_user(save, (unsigned int *)(regs->pc-4));
4402 ++ err |= get_user(call, (unsigned int *)regs->pc);
4403 ++ err |= get_user(nop, (unsigned int *)(regs->pc+4));
4404 ++ if (err)
4405 ++ break;
4406 ++
4407 ++ if (save == 0x9DE3BFA8U &&
4408 ++ (call & 0xC0000000U) == 0x40000000U &&
4409 ++ nop == 0x01000000U)
4410 ++ {
4411 ++ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
4412 ++
4413 ++ regs->u_regs[UREG_RETPC] = regs->pc;
4414 ++ regs->pc = dl_resolve;
4415 ++ regs->npc = dl_resolve+4;
4416 ++ return 3;
4417 ++ }
4418 ++ } while (0);
4419 ++#endif
4420 ++
4421 ++ return 1;
4422 ++}
4423 ++
4424 ++void pax_report_insns(void *pc, void *sp)
4425 ++{
4426 ++ unsigned long i;
4427 ++
4428 ++ printk(KERN_ERR "PAX: bytes at PC: ");
4429 ++ for (i = 0; i < 5; i++) {
4430 ++ unsigned int c;
4431 ++ if (get_user(c, (unsigned int *)pc+i))
4432 ++ printk(KERN_CONT "???????? ");
4433 ++ else
4434 ++ printk(KERN_CONT "%08x ", c);
4435 ++ }
4436 ++ printk("\n");
4437 ++}
4438 ++#endif
4439 ++
4440 + asmlinkage void do_sparc_fault(struct pt_regs *regs, int text_fault, int write,
4441 + unsigned long address)
4442 + {
4443 +@@ -231,6 +477,24 @@ good_area:
4444 + if(!(vma->vm_flags & VM_WRITE))
4445 + goto bad_area;
4446 + } else {
4447 ++
4448 ++#ifdef CONFIG_PAX_PAGEEXEC
4449 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
4450 ++ up_read(&mm->mmap_sem);
4451 ++ switch (pax_handle_fetch_fault(regs)) {
4452 ++
4453 ++#ifdef CONFIG_PAX_EMUPLT
4454 ++ case 2:
4455 ++ case 3:
4456 ++ return;
4457 ++#endif
4458 ++
4459 ++ }
4460 ++ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
4461 ++ do_group_exit(SIGKILL);
4462 ++ }
4463 ++#endif
4464 ++
4465 + /* Allow reads even for write-only mappings */
4466 + if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
4467 + goto bad_area;
4468 +diff -urNp linux-2.6.28/arch/sparc/mm/init.c linux-2.6.28/arch/sparc/mm/init.c
4469 +--- linux-2.6.28/arch/sparc/mm/init.c 2008-12-24 18:26:37.000000000 -0500
4470 ++++ linux-2.6.28/arch/sparc/mm/init.c 2009-01-11 07:20:06.000000000 -0500
4471 +@@ -313,6 +313,9 @@ extern void device_scan(void);
4472 + pgprot_t PAGE_SHARED __read_mostly;
4473 + EXPORT_SYMBOL(PAGE_SHARED);
4474 +
4475 ++pgprot_t PAGE_SHARED_NOEXEC __read_mostly;
4476 ++EXPORT_SYMBOL(PAGE_SHARED_NOEXEC);
4477 ++
4478 + void __init paging_init(void)
4479 + {
4480 + switch(sparc_cpu_model) {
4481 +@@ -338,17 +341,17 @@ void __init paging_init(void)
4482 +
4483 + /* Initialize the protection map with non-constant, MMU dependent values. */
4484 + protection_map[0] = PAGE_NONE;
4485 +- protection_map[1] = PAGE_READONLY;
4486 +- protection_map[2] = PAGE_COPY;
4487 +- protection_map[3] = PAGE_COPY;
4488 ++ protection_map[1] = PAGE_READONLY_NOEXEC;
4489 ++ protection_map[2] = PAGE_COPY_NOEXEC;
4490 ++ protection_map[3] = PAGE_COPY_NOEXEC;
4491 + protection_map[4] = PAGE_READONLY;
4492 + protection_map[5] = PAGE_READONLY;
4493 + protection_map[6] = PAGE_COPY;
4494 + protection_map[7] = PAGE_COPY;
4495 + protection_map[8] = PAGE_NONE;
4496 +- protection_map[9] = PAGE_READONLY;
4497 +- protection_map[10] = PAGE_SHARED;
4498 +- protection_map[11] = PAGE_SHARED;
4499 ++ protection_map[9] = PAGE_READONLY_NOEXEC;
4500 ++ protection_map[10] = PAGE_SHARED_NOEXEC;
4501 ++ protection_map[11] = PAGE_SHARED_NOEXEC;
4502 + protection_map[12] = PAGE_READONLY;
4503 + protection_map[13] = PAGE_READONLY;
4504 + protection_map[14] = PAGE_SHARED;
4505 +diff -urNp linux-2.6.28/arch/sparc/mm/srmmu.c linux-2.6.28/arch/sparc/mm/srmmu.c
4506 +--- linux-2.6.28/arch/sparc/mm/srmmu.c 2008-12-24 18:26:37.000000000 -0500
4507 ++++ linux-2.6.28/arch/sparc/mm/srmmu.c 2009-01-11 07:20:06.000000000 -0500
4508 +@@ -2162,6 +2162,13 @@ void __init ld_mmu_srmmu(void)
4509 + PAGE_SHARED = pgprot_val(SRMMU_PAGE_SHARED);
4510 + BTFIXUPSET_INT(page_copy, pgprot_val(SRMMU_PAGE_COPY));
4511 + BTFIXUPSET_INT(page_readonly, pgprot_val(SRMMU_PAGE_RDONLY));
4512 ++
4513 ++#ifdef CONFIG_PAX_PAGEEXEC
4514 ++ PAGE_SHARED_NOEXEC = pgprot_val(SRMMU_PAGE_SHARED_NOEXEC);
4515 ++ BTFIXUPSET_INT(page_copy_noexec, pgprot_val(SRMMU_PAGE_COPY_NOEXEC));
4516 ++ BTFIXUPSET_INT(page_readonly_noexec, pgprot_val(SRMMU_PAGE_RDONLY_NOEXEC));
4517 ++#endif
4518 ++
4519 + BTFIXUPSET_INT(page_kernel, pgprot_val(SRMMU_PAGE_KERNEL));
4520 + page_kernel = pgprot_val(SRMMU_PAGE_KERNEL);
4521 +
4522 +diff -urNp linux-2.6.28/arch/sparc64/kernel/Makefile linux-2.6.28/arch/sparc64/kernel/Makefile
4523 +--- linux-2.6.28/arch/sparc64/kernel/Makefile 2008-12-24 18:26:37.000000000 -0500
4524 ++++ linux-2.6.28/arch/sparc64/kernel/Makefile 2009-01-11 07:20:06.000000000 -0500
4525 +@@ -3,7 +3,7 @@
4526 + #
4527 +
4528 + EXTRA_AFLAGS := -ansi
4529 +-EXTRA_CFLAGS := -Werror
4530 ++#EXTRA_CFLAGS := -Werror
4531 +
4532 + CFLAGS_REMOVE_ftrace.o = -pg
4533 +
4534 +diff -urNp linux-2.6.28/arch/sparc64/kernel/sys_sparc.c linux-2.6.28/arch/sparc64/kernel/sys_sparc.c
4535 +--- linux-2.6.28/arch/sparc64/kernel/sys_sparc.c 2008-12-24 18:26:37.000000000 -0500
4536 ++++ linux-2.6.28/arch/sparc64/kernel/sys_sparc.c 2009-01-11 07:20:06.000000000 -0500
4537 +@@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(str
4538 + /* We do not accept a shared mapping if it would violate
4539 + * cache aliasing constraints.
4540 + */
4541 +- if ((flags & MAP_SHARED) &&
4542 ++ if ((filp || (flags & MAP_SHARED)) &&
4543 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4544 + return -EINVAL;
4545 + return addr;
4546 +@@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(str
4547 + if (filp || (flags & MAP_SHARED))
4548 + do_color_align = 1;
4549 +
4550 ++#ifdef CONFIG_PAX_RANDMMAP
4551 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4552 ++#endif
4553 ++
4554 + if (addr) {
4555 + if (do_color_align)
4556 + addr = COLOUR_ALIGN(addr, pgoff);
4557 +@@ -152,9 +156,9 @@ unsigned long arch_get_unmapped_area(str
4558 + }
4559 +
4560 + if (len > mm->cached_hole_size) {
4561 +- start_addr = addr = mm->free_area_cache;
4562 ++ start_addr = addr = mm->free_area_cache;
4563 + } else {
4564 +- start_addr = addr = TASK_UNMAPPED_BASE;
4565 ++ start_addr = addr = mm->mmap_base;
4566 + mm->cached_hole_size = 0;
4567 + }
4568 +
4569 +@@ -174,8 +178,8 @@ full_search:
4570 + vma = find_vma(mm, VA_EXCLUDE_END);
4571 + }
4572 + if (unlikely(task_size < addr)) {
4573 +- if (start_addr != TASK_UNMAPPED_BASE) {
4574 +- start_addr = addr = TASK_UNMAPPED_BASE;
4575 ++ if (start_addr != mm->mmap_base) {
4576 ++ start_addr = addr = mm->mmap_base;
4577 + mm->cached_hole_size = 0;
4578 + goto full_search;
4579 + }
4580 +@@ -215,7 +219,7 @@ arch_get_unmapped_area_topdown(struct fi
4581 + /* We do not accept a shared mapping if it would violate
4582 + * cache aliasing constraints.
4583 + */
4584 +- if ((flags & MAP_SHARED) &&
4585 ++ if ((filp || (flags & MAP_SHARED)) &&
4586 + ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
4587 + return -EINVAL;
4588 + return addr;
4589 +@@ -378,6 +382,12 @@ void arch_pick_mmap_layout(struct mm_str
4590 + current->signal->rlim[RLIMIT_STACK].rlim_cur == RLIM_INFINITY ||
4591 + sysctl_legacy_va_layout) {
4592 + mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4593 ++
4594 ++#ifdef CONFIG_PAX_RANDMMAP
4595 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
4596 ++ mm->mmap_base += mm->delta_mmap;
4597 ++#endif
4598 ++
4599 + mm->get_unmapped_area = arch_get_unmapped_area;
4600 + mm->unmap_area = arch_unmap_area;
4601 + } else {
4602 +@@ -392,6 +402,12 @@ void arch_pick_mmap_layout(struct mm_str
4603 + gap = (task_size / 6 * 5);
4604 +
4605 + mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
4606 ++
4607 ++#ifdef CONFIG_PAX_RANDMMAP
4608 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
4609 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4610 ++#endif
4611 ++
4612 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4613 + mm->unmap_area = arch_unmap_area_topdown;
4614 + }
4615 +diff -urNp linux-2.6.28/arch/sparc64/mm/fault.c linux-2.6.28/arch/sparc64/mm/fault.c
4616 +--- linux-2.6.28/arch/sparc64/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
4617 ++++ linux-2.6.28/arch/sparc64/mm/fault.c 2009-01-11 07:20:06.000000000 -0500
4618 +@@ -19,6 +19,9 @@
4619 + #include <linux/interrupt.h>
4620 + #include <linux/kprobes.h>
4621 + #include <linux/kdebug.h>
4622 ++#include <linux/slab.h>
4623 ++#include <linux/pagemap.h>
4624 ++#include <linux/compiler.h>
4625 +
4626 + #include <asm/page.h>
4627 + #include <asm/pgtable.h>
4628 +@@ -224,6 +227,367 @@ cannot_handle:
4629 + unhandled_fault (address, current, regs);
4630 + }
4631 +
4632 ++#ifdef CONFIG_PAX_PAGEEXEC
4633 ++#ifdef CONFIG_PAX_EMUPLT
4634 ++static void pax_emuplt_close(struct vm_area_struct *vma)
4635 ++{
4636 ++ vma->vm_mm->call_dl_resolve = 0UL;
4637 ++}
4638 ++
4639 ++static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
4640 ++{
4641 ++ unsigned int *kaddr;
4642 ++
4643 ++ vmf->page = alloc_page(GFP_HIGHUSER);
4644 ++ if (!vmf->page)
4645 ++ return VM_FAULT_OOM;
4646 ++
4647 ++ kaddr = kmap(vmf->page);
4648 ++ memset(kaddr, 0, PAGE_SIZE);
4649 ++ kaddr[0] = 0x9DE3BFA8U; /* save */
4650 ++ flush_dcache_page(vmf->page);
4651 ++ kunmap(vmf->page);
4652 ++ return VM_FAULT_MAJOR;
4653 ++}
4654 ++
4655 ++static struct vm_operations_struct pax_vm_ops = {
4656 ++ .close = pax_emuplt_close,
4657 ++ .fault = pax_emuplt_fault
4658 ++};
4659 ++
4660 ++static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
4661 ++{
4662 ++ int ret;
4663 ++
4664 ++ vma->vm_mm = current->mm;
4665 ++ vma->vm_start = addr;
4666 ++ vma->vm_end = addr + PAGE_SIZE;
4667 ++ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
4668 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
4669 ++ vma->vm_ops = &pax_vm_ops;
4670 ++
4671 ++ ret = insert_vm_struct(current->mm, vma);
4672 ++ if (ret)
4673 ++ return ret;
4674 ++
4675 ++ ++current->mm->total_vm;
4676 ++ return 0;
4677 ++}
4678 ++#endif
4679 ++
4680 ++/*
4681 ++ * PaX: decide what to do with offenders (regs->tpc = fault address)
4682 ++ *
4683 ++ * returns 1 when task should be killed
4684 ++ * 2 when patched PLT trampoline was detected
4685 ++ * 3 when unpatched PLT trampoline was detected
4686 ++ */
4687 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
4688 ++{
4689 ++
4690 ++#ifdef CONFIG_PAX_EMUPLT
4691 ++ int err;
4692 ++
4693 ++ do { /* PaX: patched PLT emulation #1 */
4694 ++ unsigned int sethi1, sethi2, jmpl;
4695 ++
4696 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
4697 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4698 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
4699 ++
4700 ++ if (err)
4701 ++ break;
4702 ++
4703 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4704 ++ (sethi2 & 0xFFC00000U) == 0x03000000U &&
4705 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U)
4706 ++ {
4707 ++ unsigned long addr;
4708 ++
4709 ++ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
4710 ++ addr = regs->u_regs[UREG_G1];
4711 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4712 ++ regs->tpc = addr;
4713 ++ regs->tnpc = addr+4;
4714 ++ return 2;
4715 ++ }
4716 ++ } while (0);
4717 ++
4718 ++ { /* PaX: patched PLT emulation #2 */
4719 ++ unsigned int ba;
4720 ++
4721 ++ err = get_user(ba, (unsigned int *)regs->tpc);
4722 ++
4723 ++ if (!err && (ba & 0xFFC00000U) == 0x30800000U) {
4724 ++ unsigned long addr;
4725 ++
4726 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4727 ++ regs->tpc = addr;
4728 ++ regs->tnpc = addr+4;
4729 ++ return 2;
4730 ++ }
4731 ++ }
4732 ++
4733 ++ do { /* PaX: patched PLT emulation #3 */
4734 ++ unsigned int sethi, jmpl, nop;
4735 ++
4736 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
4737 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+4));
4738 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4739 ++
4740 ++ if (err)
4741 ++ break;
4742 ++
4743 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4744 ++ (jmpl & 0xFFFFE000U) == 0x81C06000U &&
4745 ++ nop == 0x01000000U)
4746 ++ {
4747 ++ unsigned long addr;
4748 ++
4749 ++ addr = (sethi & 0x003FFFFFU) << 10;
4750 ++ regs->u_regs[UREG_G1] = addr;
4751 ++ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
4752 ++ regs->tpc = addr;
4753 ++ regs->tnpc = addr+4;
4754 ++ return 2;
4755 ++ }
4756 ++ } while (0);
4757 ++
4758 ++ do { /* PaX: patched PLT emulation #4 */
4759 ++ unsigned int mov1, call, mov2;
4760 ++
4761 ++ err = get_user(mov1, (unsigned int *)regs->tpc);
4762 ++ err |= get_user(call, (unsigned int *)(regs->tpc+4));
4763 ++ err |= get_user(mov2, (unsigned int *)(regs->tpc+8));
4764 ++
4765 ++ if (err)
4766 ++ break;
4767 ++
4768 ++ if (mov1 == 0x8210000FU &&
4769 ++ (call & 0xC0000000U) == 0x40000000U &&
4770 ++ mov2 == 0x9E100001U)
4771 ++ {
4772 ++ unsigned long addr;
4773 ++
4774 ++ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
4775 ++ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
4776 ++ regs->tpc = addr;
4777 ++ regs->tnpc = addr+4;
4778 ++ return 2;
4779 ++ }
4780 ++ } while (0);
4781 ++
4782 ++ do { /* PaX: patched PLT emulation #5 */
4783 ++ unsigned int sethi1, sethi2, or1, or2, sllx, jmpl, nop;
4784 ++
4785 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
4786 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4787 ++ err |= get_user(or1, (unsigned int *)(regs->tpc+8));
4788 ++ err |= get_user(or2, (unsigned int *)(regs->tpc+12));
4789 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+16));
4790 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
4791 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
4792 ++
4793 ++ if (err)
4794 ++ break;
4795 ++
4796 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4797 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4798 ++ (or1 & 0xFFFFE000U) == 0x82106000U &&
4799 ++ (or2 & 0xFFFFE000U) == 0x8A116000U &&
4800 ++ sllx == 0x83287020 &&
4801 ++ jmpl == 0x81C04005U &&
4802 ++ nop == 0x01000000U)
4803 ++ {
4804 ++ unsigned long addr;
4805 ++
4806 ++ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
4807 ++ regs->u_regs[UREG_G1] <<= 32;
4808 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
4809 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
4810 ++ regs->tpc = addr;
4811 ++ regs->tnpc = addr+4;
4812 ++ return 2;
4813 ++ }
4814 ++ } while (0);
4815 ++
4816 ++ do { /* PaX: patched PLT emulation #6 */
4817 ++ unsigned int sethi1, sethi2, sllx, or, jmpl, nop;
4818 ++
4819 ++ err = get_user(sethi1, (unsigned int *)regs->tpc);
4820 ++ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
4821 ++ err |= get_user(sllx, (unsigned int *)(regs->tpc+8));
4822 ++ err |= get_user(or, (unsigned int *)(regs->tpc+12));
4823 ++ err |= get_user(jmpl, (unsigned int *)(regs->tpc+16));
4824 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+20));
4825 ++
4826 ++ if (err)
4827 ++ break;
4828 ++
4829 ++ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
4830 ++ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
4831 ++ sllx == 0x83287020 &&
4832 ++ (or & 0xFFFFE000U) == 0x8A116000U &&
4833 ++ jmpl == 0x81C04005U &&
4834 ++ nop == 0x01000000U)
4835 ++ {
4836 ++ unsigned long addr;
4837 ++
4838 ++ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
4839 ++ regs->u_regs[UREG_G1] <<= 32;
4840 ++ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
4841 ++ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
4842 ++ regs->tpc = addr;
4843 ++ regs->tnpc = addr+4;
4844 ++ return 2;
4845 ++ }
4846 ++ } while (0);
4847 ++
4848 ++ do { /* PaX: patched PLT emulation #7 */
4849 ++ unsigned int sethi, ba, nop;
4850 ++
4851 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
4852 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
4853 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4854 ++
4855 ++ if (err)
4856 ++ break;
4857 ++
4858 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4859 ++ (ba & 0xFFF00000U) == 0x30600000U &&
4860 ++ nop == 0x01000000U)
4861 ++ {
4862 ++ unsigned long addr;
4863 ++
4864 ++ addr = (sethi & 0x003FFFFFU) << 10;
4865 ++ regs->u_regs[UREG_G1] = addr;
4866 ++ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
4867 ++ regs->tpc = addr;
4868 ++ regs->tnpc = addr+4;
4869 ++ return 2;
4870 ++ }
4871 ++ } while (0);
4872 ++
4873 ++ do { /* PaX: unpatched PLT emulation step 1 */
4874 ++ unsigned int sethi, ba, nop;
4875 ++
4876 ++ err = get_user(sethi, (unsigned int *)regs->tpc);
4877 ++ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
4878 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
4879 ++
4880 ++ if (err)
4881 ++ break;
4882 ++
4883 ++ if ((sethi & 0xFFC00000U) == 0x03000000U &&
4884 ++ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
4885 ++ nop == 0x01000000U)
4886 ++ {
4887 ++ unsigned long addr;
4888 ++ unsigned int save, call;
4889 ++
4890 ++ if ((ba & 0xFFC00000U) == 0x30800000U)
4891 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
4892 ++ else
4893 ++ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
4894 ++
4895 ++ err = get_user(save, (unsigned int *)addr);
4896 ++ err |= get_user(call, (unsigned int *)(addr+4));
4897 ++ err |= get_user(nop, (unsigned int *)(addr+8));
4898 ++ if (err)
4899 ++ break;
4900 ++
4901 ++ if (save == 0x9DE3BFA8U &&
4902 ++ (call & 0xC0000000U) == 0x40000000U &&
4903 ++ nop == 0x01000000U)
4904 ++ {
4905 ++ struct vm_area_struct *vma;
4906 ++ unsigned long call_dl_resolve;
4907 ++
4908 ++ down_read(&current->mm->mmap_sem);
4909 ++ call_dl_resolve = current->mm->call_dl_resolve;
4910 ++ up_read(&current->mm->mmap_sem);
4911 ++ if (likely(call_dl_resolve))
4912 ++ goto emulate;
4913 ++
4914 ++ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
4915 ++
4916 ++ down_write(&current->mm->mmap_sem);
4917 ++ if (current->mm->call_dl_resolve) {
4918 ++ call_dl_resolve = current->mm->call_dl_resolve;
4919 ++ up_write(&current->mm->mmap_sem);
4920 ++ if (vma)
4921 ++ kmem_cache_free(vm_area_cachep, vma);
4922 ++ goto emulate;
4923 ++ }
4924 ++
4925 ++ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
4926 ++ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
4927 ++ up_write(&current->mm->mmap_sem);
4928 ++ if (vma)
4929 ++ kmem_cache_free(vm_area_cachep, vma);
4930 ++ return 1;
4931 ++ }
4932 ++
4933 ++ if (pax_insert_vma(vma, call_dl_resolve)) {
4934 ++ up_write(&current->mm->mmap_sem);
4935 ++ kmem_cache_free(vm_area_cachep, vma);
4936 ++ return 1;
4937 ++ }
4938 ++
4939 ++ current->mm->call_dl_resolve = call_dl_resolve;
4940 ++ up_write(&current->mm->mmap_sem);
4941 ++
4942 ++emulate:
4943 ++ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
4944 ++ regs->tpc = call_dl_resolve;
4945 ++ regs->tnpc = addr+4;
4946 ++ return 3;
4947 ++ }
4948 ++ }
4949 ++ } while (0);
4950 ++
4951 ++ do { /* PaX: unpatched PLT emulation step 2 */
4952 ++ unsigned int save, call, nop;
4953 ++
4954 ++ err = get_user(save, (unsigned int *)(regs->tpc-4));
4955 ++ err |= get_user(call, (unsigned int *)regs->tpc);
4956 ++ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
4957 ++ if (err)
4958 ++ break;
4959 ++
4960 ++ if (save == 0x9DE3BFA8U &&
4961 ++ (call & 0xC0000000U) == 0x40000000U &&
4962 ++ nop == 0x01000000U)
4963 ++ {
4964 ++ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
4965 ++
4966 ++ regs->u_regs[UREG_RETPC] = regs->tpc;
4967 ++ regs->tpc = dl_resolve;
4968 ++ regs->tnpc = dl_resolve+4;
4969 ++ return 3;
4970 ++ }
4971 ++ } while (0);
4972 ++#endif
4973 ++
4974 ++ return 1;
4975 ++}
4976 ++
4977 ++void pax_report_insns(void *pc, void *sp)
4978 ++{
4979 ++ unsigned long i;
4980 ++
4981 ++ printk(KERN_ERR "PAX: bytes at PC: ");
4982 ++ for (i = 0; i < 5; i++) {
4983 ++ unsigned int c;
4984 ++ if (get_user(c, (unsigned int *)pc+i))
4985 ++ printk(KERN_CONT "???????? ");
4986 ++ else
4987 ++ printk(KERN_CONT "%08x ", c);
4988 ++ }
4989 ++ printk("\n");
4990 ++}
4991 ++#endif
4992 ++
4993 + asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
4994 + {
4995 + struct mm_struct *mm = current->mm;
4996 +@@ -265,8 +629,10 @@ asmlinkage void __kprobes do_sparc64_fau
4997 + goto intr_or_no_mm;
4998 +
4999 + if (test_thread_flag(TIF_32BIT)) {
5000 +- if (!(regs->tstate & TSTATE_PRIV))
5001 ++ if (!(regs->tstate & TSTATE_PRIV)) {
5002 + regs->tpc &= 0xffffffff;
5003 ++ regs->tnpc &= 0xffffffff;
5004 ++ }
5005 + address &= 0xffffffff;
5006 + }
5007 +
5008 +@@ -283,6 +649,29 @@ asmlinkage void __kprobes do_sparc64_fau
5009 + if (!vma)
5010 + goto bad_area;
5011 +
5012 ++#ifdef CONFIG_PAX_PAGEEXEC
5013 ++ /* PaX: detect ITLB misses on non-exec pages */
5014 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
5015 ++ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
5016 ++ {
5017 ++ if (address != regs->tpc)
5018 ++ goto good_area;
5019 ++
5020 ++ up_read(&mm->mmap_sem);
5021 ++ switch (pax_handle_fetch_fault(regs)) {
5022 ++
5023 ++#ifdef CONFIG_PAX_EMUPLT
5024 ++ case 2:
5025 ++ case 3:
5026 ++ return;
5027 ++#endif
5028 ++
5029 ++ }
5030 ++ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
5031 ++ do_group_exit(SIGKILL);
5032 ++ }
5033 ++#endif
5034 ++
5035 + /* Pure DTLB misses do not tell us whether the fault causing
5036 + * load/store/atomic was a write or not, it only says that there
5037 + * was no match. So in such a case we (carefully) read the
5038 +diff -urNp linux-2.6.28/arch/sparc64/mm/Makefile linux-2.6.28/arch/sparc64/mm/Makefile
5039 +--- linux-2.6.28/arch/sparc64/mm/Makefile 2008-12-24 18:26:37.000000000 -0500
5040 ++++ linux-2.6.28/arch/sparc64/mm/Makefile 2009-01-11 07:20:06.000000000 -0500
5041 +@@ -2,7 +2,7 @@
5042 + #
5043 +
5044 + EXTRA_AFLAGS := -ansi
5045 +-EXTRA_CFLAGS := -Werror
5046 ++#EXTRA_CFLAGS := -Werror
5047 +
5048 + obj-y := ultra.o tlb.o tsb.o fault.o init.o generic.o
5049 +
5050 +diff -urNp linux-2.6.28/arch/um/include/asm/kmap_types.h linux-2.6.28/arch/um/include/asm/kmap_types.h
5051 +--- linux-2.6.28/arch/um/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
5052 ++++ linux-2.6.28/arch/um/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
5053 +@@ -23,6 +23,7 @@ enum km_type {
5054 + KM_IRQ1,
5055 + KM_SOFTIRQ0,
5056 + KM_SOFTIRQ1,
5057 ++ KM_CLEARPAGE,
5058 + KM_TYPE_NR
5059 + };
5060 +
5061 +diff -urNp linux-2.6.28/arch/um/include/asm/page.h linux-2.6.28/arch/um/include/asm/page.h
5062 +--- linux-2.6.28/arch/um/include/asm/page.h 2008-12-24 18:26:37.000000000 -0500
5063 ++++ linux-2.6.28/arch/um/include/asm/page.h 2009-01-11 07:20:06.000000000 -0500
5064 +@@ -14,6 +14,9 @@
5065 + #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
5066 + #define PAGE_MASK (~(PAGE_SIZE-1))
5067 +
5068 ++#define ktla_ktva(addr) (addr)
5069 ++#define ktva_ktla(addr) (addr)
5070 ++
5071 + #ifndef __ASSEMBLY__
5072 +
5073 + struct page;
5074 +diff -urNp linux-2.6.28/arch/um/sys-i386/syscalls.c linux-2.6.28/arch/um/sys-i386/syscalls.c
5075 +--- linux-2.6.28/arch/um/sys-i386/syscalls.c 2008-12-24 18:26:37.000000000 -0500
5076 ++++ linux-2.6.28/arch/um/sys-i386/syscalls.c 2009-01-11 07:20:06.000000000 -0500
5077 +@@ -11,6 +11,21 @@
5078 + #include "asm/uaccess.h"
5079 + #include "asm/unistd.h"
5080 +
5081 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
5082 ++{
5083 ++ unsigned long pax_task_size = TASK_SIZE;
5084 ++
5085 ++#ifdef CONFIG_PAX_SEGMEXEC
5086 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
5087 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
5088 ++#endif
5089 ++
5090 ++ if (len > pax_task_size || addr > pax_task_size - len)
5091 ++ return -EINVAL;
5092 ++
5093 ++ return 0;
5094 ++}
5095 ++
5096 + /*
5097 + * Perform the select(nd, in, out, ex, tv) and mmap() system
5098 + * calls. Linux/i386 didn't use to be able to handle more than
5099 +diff -urNp linux-2.6.28/arch/x86/boot/bitops.h linux-2.6.28/arch/x86/boot/bitops.h
5100 +--- linux-2.6.28/arch/x86/boot/bitops.h 2008-12-24 18:26:37.000000000 -0500
5101 ++++ linux-2.6.28/arch/x86/boot/bitops.h 2009-01-11 07:20:06.000000000 -0500
5102 +@@ -26,7 +26,7 @@ static inline int variable_test_bit(int
5103 + u8 v;
5104 + const u32 *p = (const u32 *)addr;
5105 +
5106 +- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5107 ++ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
5108 + return v;
5109 + }
5110 +
5111 +@@ -37,7 +37,7 @@ static inline int variable_test_bit(int
5112 +
5113 + static inline void set_bit(int nr, void *addr)
5114 + {
5115 +- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5116 ++ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
5117 + }
5118 +
5119 + #endif /* BOOT_BITOPS_H */
5120 +diff -urNp linux-2.6.28/arch/x86/boot/boot.h linux-2.6.28/arch/x86/boot/boot.h
5121 +--- linux-2.6.28/arch/x86/boot/boot.h 2008-12-24 18:26:37.000000000 -0500
5122 ++++ linux-2.6.28/arch/x86/boot/boot.h 2009-01-11 07:20:06.000000000 -0500
5123 +@@ -80,7 +80,7 @@ static inline void io_delay(void)
5124 + static inline u16 ds(void)
5125 + {
5126 + u16 seg;
5127 +- asm("movw %%ds,%0" : "=rm" (seg));
5128 ++ asm volatile("movw %%ds,%0" : "=rm" (seg));
5129 + return seg;
5130 + }
5131 +
5132 +@@ -176,7 +176,7 @@ static inline void wrgs32(u32 v, addr_t
5133 + static inline int memcmp(const void *s1, const void *s2, size_t len)
5134 + {
5135 + u8 diff;
5136 +- asm("repe; cmpsb; setnz %0"
5137 ++ asm volatile("repe; cmpsb; setnz %0"
5138 + : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
5139 + return diff;
5140 + }
5141 +diff -urNp linux-2.6.28/arch/x86/boot/compressed/head_32.S linux-2.6.28/arch/x86/boot/compressed/head_32.S
5142 +--- linux-2.6.28/arch/x86/boot/compressed/head_32.S 2008-12-24 18:26:37.000000000 -0500
5143 ++++ linux-2.6.28/arch/x86/boot/compressed/head_32.S 2009-01-11 07:20:06.000000000 -0500
5144 +@@ -70,7 +70,7 @@ startup_32:
5145 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebx
5146 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebx
5147 + #else
5148 +- movl $LOAD_PHYSICAL_ADDR, %ebx
5149 ++ movl $____LOAD_PHYSICAL_ADDR, %ebx
5150 + #endif
5151 +
5152 + /* Replace the compressed data size with the uncompressed size */
5153 +@@ -105,7 +105,7 @@ startup_32:
5154 + addl $(CONFIG_PHYSICAL_ALIGN - 1), %ebp
5155 + andl $(~(CONFIG_PHYSICAL_ALIGN - 1)), %ebp
5156 + #else
5157 +- movl $LOAD_PHYSICAL_ADDR, %ebp
5158 ++ movl $____LOAD_PHYSICAL_ADDR, %ebp
5159 + #endif
5160 +
5161 + /*
5162 +@@ -160,16 +160,15 @@ relocated:
5163 + * and where it was actually loaded.
5164 + */
5165 + movl %ebp, %ebx
5166 +- subl $LOAD_PHYSICAL_ADDR, %ebx
5167 ++ subl $____LOAD_PHYSICAL_ADDR, %ebx
5168 + jz 2f /* Nothing to be done if loaded at compiled addr. */
5169 + /*
5170 + * Process relocations.
5171 + */
5172 +
5173 + 1: subl $4, %edi
5174 +- movl 0(%edi), %ecx
5175 +- testl %ecx, %ecx
5176 +- jz 2f
5177 ++ movl (%edi), %ecx
5178 ++ jecxz 2f
5179 + addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
5180 + jmp 1b
5181 + 2:
5182 +diff -urNp linux-2.6.28/arch/x86/boot/compressed/misc.c linux-2.6.28/arch/x86/boot/compressed/misc.c
5183 +--- linux-2.6.28/arch/x86/boot/compressed/misc.c 2008-12-24 18:26:37.000000000 -0500
5184 ++++ linux-2.6.28/arch/x86/boot/compressed/misc.c 2009-01-11 07:20:06.000000000 -0500
5185 +@@ -373,7 +373,7 @@ static void parse_elf(void *output)
5186 + case PT_LOAD:
5187 + #ifdef CONFIG_RELOCATABLE
5188 + dest = output;
5189 +- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
5190 ++ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
5191 + #else
5192 + dest = (void *)(phdr->p_paddr);
5193 + #endif
5194 +@@ -425,7 +425,7 @@ asmlinkage void decompress_kernel(void *
5195 + if (heap > ((-__PAGE_OFFSET-(512<<20)-1) & 0x7fffffff))
5196 + error("Destination address too large");
5197 + #ifndef CONFIG_RELOCATABLE
5198 +- if ((u32)output != LOAD_PHYSICAL_ADDR)
5199 ++ if ((u32)output != ____LOAD_PHYSICAL_ADDR)
5200 + error("Wrong destination address");
5201 + #endif
5202 + #endif
5203 +diff -urNp linux-2.6.28/arch/x86/boot/compressed/relocs.c linux-2.6.28/arch/x86/boot/compressed/relocs.c
5204 +--- linux-2.6.28/arch/x86/boot/compressed/relocs.c 2008-12-24 18:26:37.000000000 -0500
5205 ++++ linux-2.6.28/arch/x86/boot/compressed/relocs.c 2009-01-11 07:20:06.000000000 -0500
5206 +@@ -10,8 +10,11 @@
5207 + #define USE_BSD
5208 + #include <endian.h>
5209 +
5210 ++#include "../../../../include/linux/autoconf.h"
5211 ++
5212 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
5213 + static Elf32_Ehdr ehdr;
5214 ++static Elf32_Phdr *phdr;
5215 + static unsigned long reloc_count, reloc_idx;
5216 + static unsigned long *relocs;
5217 +
5218 +@@ -245,6 +248,36 @@ static void read_ehdr(FILE *fp)
5219 + }
5220 + }
5221 +
5222 ++static void read_phdrs(FILE *fp)
5223 ++{
5224 ++ int i;
5225 ++
5226 ++ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
5227 ++ if (!phdr) {
5228 ++ die("Unable to allocate %d program headers\n",
5229 ++ ehdr.e_phnum);
5230 ++ }
5231 ++ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
5232 ++ die("Seek to %d failed: %s\n",
5233 ++ ehdr.e_phoff, strerror(errno));
5234 ++ }
5235 ++ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
5236 ++ die("Cannot read ELF program headers: %s\n",
5237 ++ strerror(errno));
5238 ++ }
5239 ++ for(i = 0; i < ehdr.e_phnum; i++) {
5240 ++ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
5241 ++ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
5242 ++ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
5243 ++ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
5244 ++ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
5245 ++ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
5246 ++ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
5247 ++ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
5248 ++ }
5249 ++
5250 ++}
5251 ++
5252 + static void read_shdrs(FILE *fp)
5253 + {
5254 + int i;
5255 +@@ -341,6 +374,8 @@ static void read_symtabs(FILE *fp)
5256 + static void read_relocs(FILE *fp)
5257 + {
5258 + int i,j;
5259 ++ uint32_t base;
5260 ++
5261 + for (i = 0; i < ehdr.e_shnum; i++) {
5262 + struct section *sec = &secs[i];
5263 + if (sec->shdr.sh_type != SHT_REL) {
5264 +@@ -360,9 +395,18 @@ static void read_relocs(FILE *fp)
5265 + die("Cannot read symbol table: %s\n",
5266 + strerror(errno));
5267 + }
5268 ++ base = 0;
5269 ++ for (j = 0; j < ehdr.e_phnum; j++) {
5270 ++ if (phdr[j].p_type != PT_LOAD )
5271 ++ continue;
5272 ++ 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)
5273 ++ continue;
5274 ++ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
5275 ++ break;
5276 ++ }
5277 + for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
5278 + Elf32_Rel *rel = &sec->reltab[j];
5279 +- rel->r_offset = elf32_to_cpu(rel->r_offset);
5280 ++ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
5281 + rel->r_info = elf32_to_cpu(rel->r_info);
5282 + }
5283 + }
5284 +@@ -504,6 +548,23 @@ static void walk_relocs(void (*visit)(El
5285 + if (sym->st_shndx == SHN_ABS) {
5286 + continue;
5287 + }
5288 ++ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
5289 ++ if (!strcmp(sec_name(sym->st_shndx), ".data.percpu") && strncmp(sym_name(sym_strtab, sym), "__per_cpu_", 10))
5290 ++ continue;
5291 ++#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
5292 ++ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
5293 ++ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
5294 ++ continue;
5295 ++ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
5296 ++ continue;
5297 ++ if (!strcmp(sec_name(sym->st_shndx), ".text.head")) {
5298 ++ if (strcmp(sym_name(sym_strtab, sym), "__init_end") &&
5299 ++ strcmp(sym_name(sym_strtab, sym), "KERNEL_TEXT_OFFSET"))
5300 ++ continue;
5301 ++ }
5302 ++ if (!strcmp(sec_name(sym->st_shndx), ".text"))
5303 ++ continue;
5304 ++#endif
5305 + if (r_type == R_386_PC32) {
5306 + /* PC relative relocations don't need to be adjusted */
5307 + }
5308 +@@ -631,6 +692,7 @@ int main(int argc, char **argv)
5309 + fname, strerror(errno));
5310 + }
5311 + read_ehdr(fp);
5312 ++ read_phdrs(fp);
5313 + read_shdrs(fp);
5314 + read_strtabs(fp);
5315 + read_symtabs(fp);
5316 +diff -urNp linux-2.6.28/arch/x86/boot/cpucheck.c linux-2.6.28/arch/x86/boot/cpucheck.c
5317 +--- linux-2.6.28/arch/x86/boot/cpucheck.c 2008-12-24 18:26:37.000000000 -0500
5318 ++++ linux-2.6.28/arch/x86/boot/cpucheck.c 2009-01-11 07:20:06.000000000 -0500
5319 +@@ -74,7 +74,7 @@ static int has_fpu(void)
5320 + u16 fcw = -1, fsw = -1;
5321 + u32 cr0;
5322 +
5323 +- asm("movl %%cr0,%0" : "=r" (cr0));
5324 ++ asm volatile("movl %%cr0,%0" : "=r" (cr0));
5325 + if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
5326 + cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
5327 + asm volatile("movl %0,%%cr0" : : "r" (cr0));
5328 +@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
5329 + {
5330 + u32 f0, f1;
5331 +
5332 +- asm("pushfl ; "
5333 ++ asm volatile("pushfl ; "
5334 + "pushfl ; "
5335 + "popl %0 ; "
5336 + "movl %0,%1 ; "
5337 +@@ -115,7 +115,7 @@ static void get_flags(void)
5338 + set_bit(X86_FEATURE_FPU, cpu.flags);
5339 +
5340 + if (has_eflag(X86_EFLAGS_ID)) {
5341 +- asm("cpuid"
5342 ++ asm volatile("cpuid"
5343 + : "=a" (max_intel_level),
5344 + "=b" (cpu_vendor[0]),
5345 + "=d" (cpu_vendor[1]),
5346 +@@ -124,7 +124,7 @@ static void get_flags(void)
5347 +
5348 + if (max_intel_level >= 0x00000001 &&
5349 + max_intel_level <= 0x0000ffff) {
5350 +- asm("cpuid"
5351 ++ asm volatile("cpuid"
5352 + : "=a" (tfms),
5353 + "=c" (cpu.flags[4]),
5354 + "=d" (cpu.flags[0])
5355 +@@ -136,7 +136,7 @@ static void get_flags(void)
5356 + cpu.model += ((tfms >> 16) & 0xf) << 4;
5357 + }
5358 +
5359 +- asm("cpuid"
5360 ++ asm volatile("cpuid"
5361 + : "=a" (max_amd_level)
5362 + : "a" (0x80000000)
5363 + : "ebx", "ecx", "edx");
5364 +@@ -144,7 +144,7 @@ static void get_flags(void)
5365 + if (max_amd_level >= 0x80000001 &&
5366 + max_amd_level <= 0x8000ffff) {
5367 + u32 eax = 0x80000001;
5368 +- asm("cpuid"
5369 ++ asm volatile("cpuid"
5370 + : "+a" (eax),
5371 + "=c" (cpu.flags[6]),
5372 + "=d" (cpu.flags[1])
5373 +@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *r
5374 + u32 ecx = MSR_K7_HWCR;
5375 + u32 eax, edx;
5376 +
5377 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5378 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5379 + eax &= ~(1 << 15);
5380 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5381 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5382 +
5383 + get_flags(); /* Make sure it really did something */
5384 + err = check_flags();
5385 +@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *r
5386 + u32 ecx = MSR_VIA_FCR;
5387 + u32 eax, edx;
5388 +
5389 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5390 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5391 + eax |= (1<<1)|(1<<7);
5392 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5393 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5394 +
5395 + set_bit(X86_FEATURE_CX8, cpu.flags);
5396 + err = check_flags();
5397 +@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *r
5398 + u32 eax, edx;
5399 + u32 level = 1;
5400 +
5401 +- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5402 +- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
5403 +- asm("cpuid"
5404 ++ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
5405 ++ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
5406 ++ asm volatile("cpuid"
5407 + : "+a" (level), "=d" (cpu.flags[0])
5408 + : : "ecx", "ebx");
5409 +- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5410 ++ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
5411 +
5412 + err = check_flags();
5413 + }
5414 +diff -urNp linux-2.6.28/arch/x86/boot/edd.c linux-2.6.28/arch/x86/boot/edd.c
5415 +--- linux-2.6.28/arch/x86/boot/edd.c 2008-12-24 18:26:37.000000000 -0500
5416 ++++ linux-2.6.28/arch/x86/boot/edd.c 2009-01-11 07:20:06.000000000 -0500
5417 +@@ -81,7 +81,7 @@ static int get_edd_info(u8 devno, struct
5418 + ax = 0x4100;
5419 + bx = EDDMAGIC1;
5420 + dx = devno;
5421 +- asm("pushfl; stc; int $0x13; setc %%al; popfl"
5422 ++ asm volatile("pushfl; stc; int $0x13; setc %%al; popfl"
5423 + : "+a" (ax), "+b" (bx), "=c" (cx), "+d" (dx)
5424 + : : "esi", "edi");
5425 +
5426 +@@ -100,7 +100,7 @@ static int get_edd_info(u8 devno, struct
5427 + ei->params.length = sizeof(ei->params);
5428 + ax = 0x4800;
5429 + dx = devno;
5430 +- asm("pushfl; int $0x13; popfl"
5431 ++ asm volatile("pushfl; int $0x13; popfl"
5432 + : "+a" (ax), "+d" (dx), "=m" (ei->params)
5433 + : "S" (&ei->params)
5434 + : "ebx", "ecx", "edi");
5435 +@@ -111,7 +111,7 @@ static int get_edd_info(u8 devno, struct
5436 + ax = 0x0800;
5437 + dx = devno;
5438 + di = 0;
5439 +- asm("pushw %%es; "
5440 ++ asm volatile("pushw %%es; "
5441 + "movw %%di,%%es; "
5442 + "pushfl; stc; int $0x13; setc %%al; popfl; "
5443 + "popw %%es"
5444 +diff -urNp linux-2.6.28/arch/x86/boot/main.c linux-2.6.28/arch/x86/boot/main.c
5445 +--- linux-2.6.28/arch/x86/boot/main.c 2008-12-24 18:26:37.000000000 -0500
5446 ++++ linux-2.6.28/arch/x86/boot/main.c 2009-01-11 07:20:06.000000000 -0500
5447 +@@ -78,7 +78,7 @@ static void query_ist(void)
5448 + if (cpu.level < 6)
5449 + return;
5450 +
5451 +- asm("int $0x15"
5452 ++ asm volatile("int $0x15"
5453 + : "=a" (boot_params.ist_info.signature),
5454 + "=b" (boot_params.ist_info.command),
5455 + "=c" (boot_params.ist_info.event),
5456 +diff -urNp linux-2.6.28/arch/x86/boot/mca.c linux-2.6.28/arch/x86/boot/mca.c
5457 +--- linux-2.6.28/arch/x86/boot/mca.c 2008-12-24 18:26:37.000000000 -0500
5458 ++++ linux-2.6.28/arch/x86/boot/mca.c 2009-01-11 07:20:06.000000000 -0500
5459 +@@ -19,7 +19,7 @@ int query_mca(void)
5460 + u8 err;
5461 + u16 es, bx, len;
5462 +
5463 +- asm("pushw %%es ; "
5464 ++ asm volatile("pushw %%es ; "
5465 + "int $0x15 ; "
5466 + "setc %0 ; "
5467 + "movw %%es, %1 ; "
5468 +diff -urNp linux-2.6.28/arch/x86/boot/memory.c linux-2.6.28/arch/x86/boot/memory.c
5469 +--- linux-2.6.28/arch/x86/boot/memory.c 2008-12-24 18:26:37.000000000 -0500
5470 ++++ linux-2.6.28/arch/x86/boot/memory.c 2009-01-11 07:20:06.000000000 -0500
5471 +@@ -30,7 +30,7 @@ static int detect_memory_e820(void)
5472 + /* Important: %edx is clobbered by some BIOSes,
5473 + so it must be either used for the error output
5474 + or explicitly marked clobbered. */
5475 +- asm("int $0x15; setc %0"
5476 ++ asm volatile("int $0x15; setc %0"
5477 + : "=d" (err), "+b" (next), "=a" (id), "+c" (size),
5478 + "=m" (*desc)
5479 + : "D" (desc), "d" (SMAP), "a" (0xe820));
5480 +@@ -65,7 +65,7 @@ static int detect_memory_e801(void)
5481 +
5482 + bx = cx = dx = 0;
5483 + ax = 0xe801;
5484 +- asm("stc; int $0x15; setc %0"
5485 ++ asm volatile("stc; int $0x15; setc %0"
5486 + : "=m" (err), "+a" (ax), "+b" (bx), "+c" (cx), "+d" (dx));
5487 +
5488 + if (err)
5489 +@@ -95,7 +95,7 @@ static int detect_memory_88(void)
5490 + u8 err;
5491 +
5492 + ax = 0x8800;
5493 +- asm("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
5494 ++ asm volatile("stc; int $0x15; setc %0" : "=bcdm" (err), "+a" (ax));
5495 +
5496 + boot_params.screen_info.ext_mem_k = ax;
5497 +
5498 +diff -urNp linux-2.6.28/arch/x86/boot/video.c linux-2.6.28/arch/x86/boot/video.c
5499 +--- linux-2.6.28/arch/x86/boot/video.c 2008-12-24 18:26:37.000000000 -0500
5500 ++++ linux-2.6.28/arch/x86/boot/video.c 2009-01-11 07:20:06.000000000 -0500
5501 +@@ -23,7 +23,7 @@ static void store_cursor_position(void)
5502 +
5503 + ax = 0x0300;
5504 + bx = 0;
5505 +- asm(INT10
5506 ++ asm volatile(INT10
5507 + : "=d" (curpos), "+a" (ax), "+b" (bx)
5508 + : : "ecx", "esi", "edi");
5509 +
5510 +@@ -38,7 +38,7 @@ static void store_video_mode(void)
5511 + /* N.B.: the saving of the video page here is a bit silly,
5512 + since we pretty much assume page 0 everywhere. */
5513 + ax = 0x0f00;
5514 +- asm(INT10
5515 ++ asm volatile(INT10
5516 + : "+a" (ax), "=b" (page)
5517 + : : "ecx", "edx", "esi", "edi");
5518 +
5519 +diff -urNp linux-2.6.28/arch/x86/boot/video-vesa.c linux-2.6.28/arch/x86/boot/video-vesa.c
5520 +--- linux-2.6.28/arch/x86/boot/video-vesa.c 2008-12-24 18:26:37.000000000 -0500
5521 ++++ linux-2.6.28/arch/x86/boot/video-vesa.c 2009-01-11 07:20:06.000000000 -0500
5522 +@@ -41,7 +41,7 @@ static int vesa_probe(void)
5523 +
5524 + ax = 0x4f00;
5525 + di = (size_t)&vginfo;
5526 +- asm(INT10
5527 ++ asm volatile(INT10
5528 + : "+a" (ax), "+D" (di), "=m" (vginfo)
5529 + : : "ebx", "ecx", "edx", "esi");
5530 +
5531 +@@ -68,7 +68,7 @@ static int vesa_probe(void)
5532 + ax = 0x4f01;
5533 + cx = mode;
5534 + di = (size_t)&vminfo;
5535 +- asm(INT10
5536 ++ asm volatile(INT10
5537 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
5538 + : : "ebx", "edx", "esi");
5539 +
5540 +@@ -120,7 +120,7 @@ static int vesa_set_mode(struct mode_inf
5541 + ax = 0x4f01;
5542 + cx = vesa_mode;
5543 + di = (size_t)&vminfo;
5544 +- asm(INT10
5545 ++ asm volatile(INT10
5546 + : "+a" (ax), "+c" (cx), "+D" (di), "=m" (vminfo)
5547 + : : "ebx", "edx", "esi");
5548 +
5549 +@@ -202,19 +202,20 @@ static void vesa_dac_set_8bits(void)
5550 + /* Save the VESA protected mode info */
5551 + static void vesa_store_pm_info(void)
5552 + {
5553 +- u16 ax, bx, di, es;
5554 ++ u16 ax, bx, cx, di, es;
5555 +
5556 + ax = 0x4f0a;
5557 +- bx = di = 0;
5558 +- asm("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
5559 +- : "=d" (es), "+a" (ax), "+b" (bx), "+D" (di)
5560 +- : : "ecx", "esi");
5561 ++ bx = cx = di = 0;
5562 ++ asm volatile("pushw %%es; "INT10"; movw %%es,%0; popw %%es"
5563 ++ : "=d" (es), "+a" (ax), "+b" (bx), "+c" (cx), "+D" (di)
5564 ++ : : "esi");
5565 +
5566 + if (ax != 0x004f)
5567 + return;
5568 +
5569 + boot_params.screen_info.vesapm_seg = es;
5570 + boot_params.screen_info.vesapm_off = di;
5571 ++ boot_params.screen_info.vesapm_size = cx;
5572 + }
5573 +
5574 + /*
5575 +@@ -268,7 +269,7 @@ void vesa_store_edid(void)
5576 + /* Note: The VBE DDC spec is different from the main VESA spec;
5577 + we genuinely have to assume all registers are destroyed here. */
5578 +
5579 +- asm("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
5580 ++ asm volatile("pushw %%es; movw %2,%%es; "INT10"; popw %%es"
5581 + : "+a" (ax), "+b" (bx)
5582 + : "c" (cx), "D" (di)
5583 + : "esi");
5584 +@@ -284,7 +285,7 @@ void vesa_store_edid(void)
5585 + cx = 0; /* Controller 0 */
5586 + dx = 0; /* EDID block number */
5587 + di =(size_t) &boot_params.edid_info; /* (ES:)Pointer to block */
5588 +- asm(INT10
5589 ++ asm volatile(INT10
5590 + : "+a" (ax), "+b" (bx), "+d" (dx), "=m" (boot_params.edid_info)
5591 + : "c" (cx), "D" (di)
5592 + : "esi");
5593 +diff -urNp linux-2.6.28/arch/x86/boot/video-vga.c linux-2.6.28/arch/x86/boot/video-vga.c
5594 +--- linux-2.6.28/arch/x86/boot/video-vga.c 2008-12-24 18:26:37.000000000 -0500
5595 ++++ linux-2.6.28/arch/x86/boot/video-vga.c 2009-01-11 07:20:06.000000000 -0500
5596 +@@ -225,7 +225,7 @@ static int vga_probe(void)
5597 + };
5598 + u8 vga_flag;
5599 +
5600 +- asm(INT10
5601 ++ asm volatile(INT10
5602 + : "=b" (ega_bx)
5603 + : "a" (0x1200), "b" (0x10) /* Check EGA/VGA */
5604 + : "ecx", "edx", "esi", "edi");
5605 +@@ -237,7 +237,7 @@ static int vga_probe(void)
5606 + /* If we have MDA/CGA/HGC then BL will be unchanged at 0x10 */
5607 + if ((u8)ega_bx != 0x10) {
5608 + /* EGA/VGA */
5609 +- asm(INT10
5610 ++ asm volatile(INT10
5611 + : "=a" (vga_flag)
5612 + : "a" (0x1a00)
5613 + : "ebx", "ecx", "edx", "esi", "edi");
5614 +diff -urNp linux-2.6.28/arch/x86/boot/voyager.c linux-2.6.28/arch/x86/boot/voyager.c
5615 +--- linux-2.6.28/arch/x86/boot/voyager.c 2008-12-24 18:26:37.000000000 -0500
5616 ++++ linux-2.6.28/arch/x86/boot/voyager.c 2009-01-11 07:20:06.000000000 -0500
5617 +@@ -23,7 +23,7 @@ int query_voyager(void)
5618 +
5619 + data_ptr[0] = 0xff; /* Flag on config not found(?) */
5620 +
5621 +- asm("pushw %%es ; "
5622 ++ asm volatile("pushw %%es ; "
5623 + "int $0x15 ; "
5624 + "setc %0 ; "
5625 + "movw %%es, %1 ; "
5626 +diff -urNp linux-2.6.28/arch/x86/ia32/ia32_signal.c linux-2.6.28/arch/x86/ia32/ia32_signal.c
5627 +--- linux-2.6.28/arch/x86/ia32/ia32_signal.c 2008-12-24 18:26:37.000000000 -0500
5628 ++++ linux-2.6.28/arch/x86/ia32/ia32_signal.c 2009-01-11 07:20:06.000000000 -0500
5629 +@@ -518,6 +518,7 @@ int ia32_setup_rt_frame(int sig, struct
5630 + __NR_ia32_rt_sigreturn,
5631 + 0x80cd,
5632 + 0,
5633 ++ 0
5634 + };
5635 +
5636 + frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
5637 +diff -urNp linux-2.6.28/arch/x86/include/asm/alternative.h linux-2.6.28/arch/x86/include/asm/alternative.h
5638 +--- linux-2.6.28/arch/x86/include/asm/alternative.h 2008-12-24 18:26:37.000000000 -0500
5639 ++++ linux-2.6.28/arch/x86/include/asm/alternative.h 2009-01-11 07:20:06.000000000 -0500
5640 +@@ -96,7 +96,7 @@ const unsigned char *const *find_nop_tab
5641 + " .byte 662b-661b\n" /* sourcelen */ \
5642 + " .byte 664f-663f\n" /* replacementlen */ \
5643 + ".previous\n" \
5644 +- ".section .altinstr_replacement,\"ax\"\n" \
5645 ++ ".section .altinstr_replacement,\"a\"\n" \
5646 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
5647 + ".previous" :: "i" (feature) : "memory")
5648 +
5649 +@@ -120,7 +120,7 @@ const unsigned char *const *find_nop_tab
5650 + " .byte 662b-661b\n" /* sourcelen */ \
5651 + " .byte 664f-663f\n" /* replacementlen */ \
5652 + ".previous\n" \
5653 +- ".section .altinstr_replacement,\"ax\"\n" \
5654 ++ ".section .altinstr_replacement,\"a\"\n" \
5655 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
5656 + ".previous" :: "i" (feature), ##input)
5657 +
5658 +@@ -135,7 +135,7 @@ const unsigned char *const *find_nop_tab
5659 + " .byte 662b-661b\n" /* sourcelen */ \
5660 + " .byte 664f-663f\n" /* replacementlen */ \
5661 + ".previous\n" \
5662 +- ".section .altinstr_replacement,\"ax\"\n" \
5663 ++ ".section .altinstr_replacement,\"a\"\n" \
5664 + "663:\n\t" newinstr "\n664:\n" /* replacement */ \
5665 + ".previous" : output : [feat] "i" (feature), ##input)
5666 +
5667 +diff -urNp linux-2.6.28/arch/x86/include/asm/atomic_32.h linux-2.6.28/arch/x86/include/asm/atomic_32.h
5668 +--- linux-2.6.28/arch/x86/include/asm/atomic_32.h 2008-12-24 18:26:37.000000000 -0500
5669 ++++ linux-2.6.28/arch/x86/include/asm/atomic_32.h 2009-01-11 07:20:06.000000000 -0500
5670 +@@ -47,7 +47,15 @@ typedef struct {
5671 + */
5672 + static inline void atomic_add(int i, atomic_t *v)
5673 + {
5674 +- asm volatile(LOCK_PREFIX "addl %1,%0"
5675 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
5676 ++
5677 ++#ifdef CONFIG_PAX_REFCOUNT
5678 ++ "jno 0f\n"
5679 ++ LOCK_PREFIX "subl %1,%0\n"
5680 ++ "into\n0:\n"
5681 ++ _ASM_EXTABLE(0b, 0b)
5682 ++#endif
5683 ++
5684 + : "+m" (v->counter)
5685 + : "ir" (i));
5686 + }
5687 +@@ -61,7 +69,15 @@ static inline void atomic_add(int i, ato
5688 + */
5689 + static inline void atomic_sub(int i, atomic_t *v)
5690 + {
5691 +- asm volatile(LOCK_PREFIX "subl %1,%0"
5692 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
5693 ++
5694 ++#ifdef CONFIG_PAX_REFCOUNT
5695 ++ "jno 0f\n"
5696 ++ LOCK_PREFIX "addl %1,%0\n"
5697 ++ "into\n0:\n"
5698 ++ _ASM_EXTABLE(0b, 0b)
5699 ++#endif
5700 ++
5701 + : "+m" (v->counter)
5702 + : "ir" (i));
5703 + }
5704 +@@ -79,7 +95,16 @@ static inline int atomic_sub_and_test(in
5705 + {
5706 + unsigned char c;
5707 +
5708 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
5709 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
5710 ++
5711 ++#ifdef CONFIG_PAX_REFCOUNT
5712 ++ "jno 0f\n"
5713 ++ LOCK_PREFIX "addl %2,%0\n"
5714 ++ "into\n0:\n"
5715 ++ _ASM_EXTABLE(0b, 0b)
5716 ++#endif
5717 ++
5718 ++ "sete %1\n"
5719 + : "+m" (v->counter), "=qm" (c)
5720 + : "ir" (i) : "memory");
5721 + return c;
5722 +@@ -93,7 +118,18 @@ static inline int atomic_sub_and_test(in
5723 + */
5724 + static inline void atomic_inc(atomic_t *v)
5725 + {
5726 +- asm volatile(LOCK_PREFIX "incl %0"
5727 ++ asm volatile(LOCK_PREFIX "incl %0\n"
5728 ++
5729 ++#ifdef CONFIG_PAX_REFCOUNT
5730 ++ "into\n0:\n"
5731 ++ ".pushsection .fixup,\"ax\"\n"
5732 ++ "1:\n"
5733 ++ LOCK_PREFIX "decl %0\n"
5734 ++ "jmp 0b\n"
5735 ++ ".popsection\n"
5736 ++ _ASM_EXTABLE(0b, 1b)
5737 ++#endif
5738 ++
5739 + : "+m" (v->counter));
5740 + }
5741 +
5742 +@@ -105,7 +141,18 @@ static inline void atomic_inc(atomic_t *
5743 + */
5744 + static inline void atomic_dec(atomic_t *v)
5745 + {
5746 +- asm volatile(LOCK_PREFIX "decl %0"
5747 ++ asm volatile(LOCK_PREFIX "decl %0\n"
5748 ++
5749 ++#ifdef CONFIG_PAX_REFCOUNT
5750 ++ "into\n0:\n"
5751 ++ ".pushsection .fixup,\"ax\"\n"
5752 ++ "1: \n"
5753 ++ LOCK_PREFIX "incl %0\n"
5754 ++ "jmp 0b\n"
5755 ++ ".popsection\n"
5756 ++ _ASM_EXTABLE(0b, 1b)
5757 ++#endif
5758 ++
5759 + : "+m" (v->counter));
5760 + }
5761 +
5762 +@@ -121,7 +168,19 @@ static inline int atomic_dec_and_test(at
5763 + {
5764 + unsigned char c;
5765 +
5766 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
5767 ++ asm volatile(LOCK_PREFIX "decl %0\n"
5768 ++
5769 ++#ifdef CONFIG_PAX_REFCOUNT
5770 ++ "into\n0:\n"
5771 ++ ".pushsection .fixup,\"ax\"\n"
5772 ++ "1: \n"
5773 ++ LOCK_PREFIX "incl %0\n"
5774 ++ "jmp 0b\n"
5775 ++ ".popsection\n"
5776 ++ _ASM_EXTABLE(0b, 1b)
5777 ++#endif
5778 ++
5779 ++ "sete %1\n"
5780 + : "+m" (v->counter), "=qm" (c)
5781 + : : "memory");
5782 + return c != 0;
5783 +@@ -139,7 +198,19 @@ static inline int atomic_inc_and_test(at
5784 + {
5785 + unsigned char c;
5786 +
5787 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
5788 ++ asm volatile(LOCK_PREFIX "incl %0\n"
5789 ++
5790 ++#ifdef CONFIG_PAX_REFCOUNT
5791 ++ "into\n0:\n"
5792 ++ ".pushsection .fixup,\"ax\"\n"
5793 ++ "1: \n"
5794 ++ LOCK_PREFIX "decl %0\n"
5795 ++ "jmp 0b\n"
5796 ++ ".popsection\n"
5797 ++ _ASM_EXTABLE(0b, 1b)
5798 ++#endif
5799 ++
5800 ++ "sete %1\n"
5801 + : "+m" (v->counter), "=qm" (c)
5802 + : : "memory");
5803 + return c != 0;
5804 +@@ -158,7 +229,16 @@ static inline int atomic_add_negative(in
5805 + {
5806 + unsigned char c;
5807 +
5808 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
5809 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
5810 ++
5811 ++#ifdef CONFIG_PAX_REFCOUNT
5812 ++ "jno 0f\n"
5813 ++ LOCK_PREFIX "subl %2,%0\n"
5814 ++ "into\n0:\n"
5815 ++ _ASM_EXTABLE(0b, 0b)
5816 ++#endif
5817 ++
5818 ++ "sets %1\n"
5819 + : "+m" (v->counter), "=qm" (c)
5820 + : "ir" (i) : "memory");
5821 + return c;
5822 +@@ -181,7 +261,15 @@ static inline int atomic_add_return(int
5823 + #endif
5824 + /* Modern 486+ processor */
5825 + __i = i;
5826 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
5827 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
5828 ++
5829 ++#ifdef CONFIG_PAX_REFCOUNT
5830 ++ "jno 0f\n"
5831 ++ "movl %0, %1\n"
5832 ++ "into\n0:\n"
5833 ++ _ASM_EXTABLE(0b, 0b)
5834 ++#endif
5835 ++
5836 + : "+r" (i), "+m" (v->counter)
5837 + : : "memory");
5838 + return i + __i;
5839 +diff -urNp linux-2.6.28/arch/x86/include/asm/atomic_64.h linux-2.6.28/arch/x86/include/asm/atomic_64.h
5840 +--- linux-2.6.28/arch/x86/include/asm/atomic_64.h 2008-12-24 18:26:37.000000000 -0500
5841 ++++ linux-2.6.28/arch/x86/include/asm/atomic_64.h 2009-01-11 07:20:06.000000000 -0500
5842 +@@ -48,7 +48,15 @@ typedef struct {
5843 + */
5844 + static inline void atomic_add(int i, atomic_t *v)
5845 + {
5846 +- asm volatile(LOCK_PREFIX "addl %1,%0"
5847 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
5848 ++
5849 ++#ifdef CONFIG_PAX_REFCOUNT
5850 ++ "jno 0f\n"
5851 ++ LOCK_PREFIX "subl %1,%0\n"
5852 ++ "int $4\n0:\n"
5853 ++ _ASM_EXTABLE(0b, 0b)
5854 ++#endif
5855 ++
5856 + : "=m" (v->counter)
5857 + : "ir" (i), "m" (v->counter));
5858 + }
5859 +@@ -62,7 +70,15 @@ static inline void atomic_add(int i, ato
5860 + */
5861 + static inline void atomic_sub(int i, atomic_t *v)
5862 + {
5863 +- asm volatile(LOCK_PREFIX "subl %1,%0"
5864 ++ asm volatile(LOCK_PREFIX "subl %1,%0\n"
5865 ++
5866 ++#ifdef CONFIG_PAX_REFCOUNT
5867 ++ "jno 0f\n"
5868 ++ LOCK_PREFIX "addl %1,%0\n"
5869 ++ "int $4\n0:\n"
5870 ++ _ASM_EXTABLE(0b, 0b)
5871 ++#endif
5872 ++
5873 + : "=m" (v->counter)
5874 + : "ir" (i), "m" (v->counter));
5875 + }
5876 +@@ -80,7 +96,16 @@ static inline int atomic_sub_and_test(in
5877 + {
5878 + unsigned char c;
5879 +
5880 +- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
5881 ++ asm volatile(LOCK_PREFIX "subl %2,%0\n"
5882 ++
5883 ++#ifdef CONFIG_PAX_REFCOUNT
5884 ++ "jno 0f\n"
5885 ++ LOCK_PREFIX "addl %2,%0\n"
5886 ++ "int $4\n0:\n"
5887 ++ _ASM_EXTABLE(0b, 0b)
5888 ++#endif
5889 ++
5890 ++ "sete %1\n"
5891 + : "=m" (v->counter), "=qm" (c)
5892 + : "ir" (i), "m" (v->counter) : "memory");
5893 + return c;
5894 +@@ -94,7 +119,19 @@ static inline int atomic_sub_and_test(in
5895 + */
5896 + static inline void atomic_inc(atomic_t *v)
5897 + {
5898 +- asm volatile(LOCK_PREFIX "incl %0"
5899 ++ asm volatile(LOCK_PREFIX "incl %0\n"
5900 ++
5901 ++#ifdef CONFIG_PAX_REFCOUNT
5902 ++ "jno 0f\n"
5903 ++ "int $4\n0:\n"
5904 ++ ".pushsection .fixup,\"ax\"\n"
5905 ++ "1:\n"
5906 ++ LOCK_PREFIX "decl %0\n"
5907 ++ "jmp 0b\n"
5908 ++ ".popsection\n"
5909 ++ _ASM_EXTABLE(0b, 1b)
5910 ++#endif
5911 ++
5912 + : "=m" (v->counter)
5913 + : "m" (v->counter));
5914 + }
5915 +@@ -107,7 +144,19 @@ static inline void atomic_inc(atomic_t *
5916 + */
5917 + static inline void atomic_dec(atomic_t *v)
5918 + {
5919 +- asm volatile(LOCK_PREFIX "decl %0"
5920 ++ asm volatile(LOCK_PREFIX "decl %0\n"
5921 ++
5922 ++#ifdef CONFIG_PAX_REFCOUNT
5923 ++ "jno 0f\n"
5924 ++ "int $4\n0:\n"
5925 ++ ".pushsection .fixup,\"ax\"\n"
5926 ++ "1: \n"
5927 ++ LOCK_PREFIX "incl %0\n"
5928 ++ "jmp 0b\n"
5929 ++ ".popsection\n"
5930 ++ _ASM_EXTABLE(0b, 1b)
5931 ++#endif
5932 ++
5933 + : "=m" (v->counter)
5934 + : "m" (v->counter));
5935 + }
5936 +@@ -124,7 +173,20 @@ static inline int atomic_dec_and_test(at
5937 + {
5938 + unsigned char c;
5939 +
5940 +- asm volatile(LOCK_PREFIX "decl %0; sete %1"
5941 ++ asm volatile(LOCK_PREFIX "decl %0\n"
5942 ++
5943 ++#ifdef CONFIG_PAX_REFCOUNT
5944 ++ "jno 0f\n"
5945 ++ "int $4\n0:\n"
5946 ++ ".pushsection .fixup,\"ax\"\n"
5947 ++ "1: \n"
5948 ++ LOCK_PREFIX "incl %0\n"
5949 ++ "jmp 0b\n"
5950 ++ ".popsection\n"
5951 ++ _ASM_EXTABLE(0b, 1b)
5952 ++#endif
5953 ++
5954 ++ "sete %1\n"
5955 + : "=m" (v->counter), "=qm" (c)
5956 + : "m" (v->counter) : "memory");
5957 + return c != 0;
5958 +@@ -142,7 +204,20 @@ static inline int atomic_inc_and_test(at
5959 + {
5960 + unsigned char c;
5961 +
5962 +- asm volatile(LOCK_PREFIX "incl %0; sete %1"
5963 ++ asm volatile(LOCK_PREFIX "incl %0\n"
5964 ++
5965 ++#ifdef CONFIG_PAX_REFCOUNT
5966 ++ "jno 0f\n"
5967 ++ "int $4\n0:\n"
5968 ++ ".pushsection .fixup,\"ax\"\n"
5969 ++ "1: \n"
5970 ++ LOCK_PREFIX "decl %0\n"
5971 ++ "jmp 0b\n"
5972 ++ ".popsection\n"
5973 ++ _ASM_EXTABLE(0b, 1b)
5974 ++#endif
5975 ++
5976 ++ "sete %1\n"
5977 + : "=m" (v->counter), "=qm" (c)
5978 + : "m" (v->counter) : "memory");
5979 + return c != 0;
5980 +@@ -161,7 +236,16 @@ static inline int atomic_add_negative(in
5981 + {
5982 + unsigned char c;
5983 +
5984 +- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
5985 ++ asm volatile(LOCK_PREFIX "addl %2,%0\n"
5986 ++
5987 ++#ifdef CONFIG_PAX_REFCOUNT
5988 ++ "jno 0f\n"
5989 ++ LOCK_PREFIX "subl %2,%0\n"
5990 ++ "int $4\n0:\n"
5991 ++ _ASM_EXTABLE(0b, 0b)
5992 ++#endif
5993 ++
5994 ++ "sets %1\n"
5995 + : "=m" (v->counter), "=qm" (c)
5996 + : "ir" (i), "m" (v->counter) : "memory");
5997 + return c;
5998 +@@ -177,7 +261,15 @@ static inline int atomic_add_negative(in
5999 + static inline int atomic_add_return(int i, atomic_t *v)
6000 + {
6001 + int __i = i;
6002 +- asm volatile(LOCK_PREFIX "xaddl %0, %1"
6003 ++ asm volatile(LOCK_PREFIX "xaddl %0, %1\n"
6004 ++
6005 ++#ifdef CONFIG_PAX_REFCOUNT
6006 ++ "jno 0f\n"
6007 ++ "movl %0, %1\n"
6008 ++ "int $4\n0:\n"
6009 ++ _ASM_EXTABLE(0b, 0b)
6010 ++#endif
6011 ++
6012 + : "+r" (i), "+m" (v->counter)
6013 + : : "memory");
6014 + return i + __i;
6015 +@@ -226,7 +318,15 @@ typedef struct {
6016 + */
6017 + static inline void atomic64_add(long i, atomic64_t *v)
6018 + {
6019 +- asm volatile(LOCK_PREFIX "addq %1,%0"
6020 ++ asm volatile(LOCK_PREFIX "addq %1,%0\n"
6021 ++
6022 ++#ifdef CONFIG_PAX_REFCOUNT
6023 ++ "jno 0f\n"
6024 ++ LOCK_PREFIX "subq %1,%0\n"
6025 ++ "int $4\n0:\n"
6026 ++ _ASM_EXTABLE(0b, 0b)
6027 ++#endif
6028 ++
6029 + : "=m" (v->counter)
6030 + : "er" (i), "m" (v->counter));
6031 + }
6032 +@@ -240,7 +340,15 @@ static inline void atomic64_add(long i,
6033 + */
6034 + static inline void atomic64_sub(long i, atomic64_t *v)
6035 + {
6036 +- asm volatile(LOCK_PREFIX "subq %1,%0"
6037 ++ asm volatile(LOCK_PREFIX "subq %1,%0\n"
6038 ++
6039 ++#ifdef CONFIG_PAX_REFCOUNT
6040 ++ "jno 0f\n"
6041 ++ LOCK_PREFIX "addq %1,%0\n"
6042 ++ "int $4\n0:\n"
6043 ++ _ASM_EXTABLE(0b, 0b)
6044 ++#endif
6045 ++
6046 + : "=m" (v->counter)
6047 + : "er" (i), "m" (v->counter));
6048 + }
6049 +@@ -258,7 +366,16 @@ static inline int atomic64_sub_and_test(
6050 + {
6051 + unsigned char c;
6052 +
6053 +- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
6054 ++ asm volatile(LOCK_PREFIX "subq %2,%0\n"
6055 ++
6056 ++#ifdef CONFIG_PAX_REFCOUNT
6057 ++ "jno 0f\n"
6058 ++ LOCK_PREFIX "addq %2,%0\n"
6059 ++ "int $4\n0:\n"
6060 ++ _ASM_EXTABLE(0b, 0b)
6061 ++#endif
6062 ++
6063 ++ "sete %1\n"
6064 + : "=m" (v->counter), "=qm" (c)
6065 + : "er" (i), "m" (v->counter) : "memory");
6066 + return c;
6067 +@@ -272,7 +389,19 @@ static inline int atomic64_sub_and_test(
6068 + */
6069 + static inline void atomic64_inc(atomic64_t *v)
6070 + {
6071 +- asm volatile(LOCK_PREFIX "incq %0"
6072 ++ asm volatile(LOCK_PREFIX "incq %0\n"
6073 ++
6074 ++#ifdef CONFIG_PAX_REFCOUNT
6075 ++ "jno 0f\n"
6076 ++ "int $4\n0:\n"
6077 ++ ".pushsection .fixup,\"ax\"\n"
6078 ++ "1:\n"
6079 ++ LOCK_PREFIX "decq %0\n"
6080 ++ "jmp 0b\n"
6081 ++ ".popsection\n"
6082 ++ _ASM_EXTABLE(0b, 1b)
6083 ++#endif
6084 ++
6085 + : "=m" (v->counter)
6086 + : "m" (v->counter));
6087 + }
6088 +@@ -285,7 +414,19 @@ static inline void atomic64_inc(atomic64
6089 + */
6090 + static inline void atomic64_dec(atomic64_t *v)
6091 + {
6092 +- asm volatile(LOCK_PREFIX "decq %0"
6093 ++ asm volatile(LOCK_PREFIX "decq %0\n"
6094 ++
6095 ++#ifdef CONFIG_PAX_REFCOUNT
6096 ++ "jno 0f\n"
6097 ++ "int $4\n0:\n"
6098 ++ ".pushsection .fixup,\"ax\"\n"
6099 ++ "1: \n"
6100 ++ LOCK_PREFIX "incq %0\n"
6101 ++ "jmp 0b\n"
6102 ++ ".popsection\n"
6103 ++ _ASM_EXTABLE(0b, 1b)
6104 ++#endif
6105 ++
6106 + : "=m" (v->counter)
6107 + : "m" (v->counter));
6108 + }
6109 +@@ -302,7 +443,20 @@ static inline int atomic64_dec_and_test(
6110 + {
6111 + unsigned char c;
6112 +
6113 +- asm volatile(LOCK_PREFIX "decq %0; sete %1"
6114 ++ asm volatile(LOCK_PREFIX "decq %0\n"
6115 ++
6116 ++#ifdef CONFIG_PAX_REFCOUNT
6117 ++ "jno 0f\n"
6118 ++ "int $4\n0:\n"
6119 ++ ".pushsection .fixup,\"ax\"\n"
6120 ++ "1: \n"
6121 ++ LOCK_PREFIX "incq %0\n"
6122 ++ "jmp 0b\n"
6123 ++ ".popsection\n"
6124 ++ _ASM_EXTABLE(0b, 1b)
6125 ++#endif
6126 ++
6127 ++ "sete %1\n"
6128 + : "=m" (v->counter), "=qm" (c)
6129 + : "m" (v->counter) : "memory");
6130 + return c != 0;
6131 +@@ -320,7 +474,20 @@ static inline int atomic64_inc_and_test(
6132 + {
6133 + unsigned char c;
6134 +
6135 +- asm volatile(LOCK_PREFIX "incq %0; sete %1"
6136 ++ asm volatile(LOCK_PREFIX "incq %0\n"
6137 ++
6138 ++#ifdef CONFIG_PAX_REFCOUNT
6139 ++ "jno 0f\n"
6140 ++ "int $4\n0:\n"
6141 ++ ".pushsection .fixup,\"ax\"\n"
6142 ++ "1: \n"
6143 ++ LOCK_PREFIX "decq %0\n"
6144 ++ "jmp 0b\n"
6145 ++ ".popsection\n"
6146 ++ _ASM_EXTABLE(0b, 1b)
6147 ++#endif
6148 ++
6149 ++ "sete %1\n"
6150 + : "=m" (v->counter), "=qm" (c)
6151 + : "m" (v->counter) : "memory");
6152 + return c != 0;
6153 +@@ -339,7 +506,16 @@ static inline int atomic64_add_negative(
6154 + {
6155 + unsigned char c;
6156 +
6157 +- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
6158 ++ asm volatile(LOCK_PREFIX "addq %2,%0\n"
6159 ++
6160 ++#ifdef CONFIG_PAX_REFCOUNT
6161 ++ "jno 0f\n"
6162 ++ LOCK_PREFIX "subq %2,%0\n"
6163 ++ "int $4\n0:\n"
6164 ++ _ASM_EXTABLE(0b, 0b)
6165 ++#endif
6166 ++
6167 ++ "sets %1\n"
6168 + : "=m" (v->counter), "=qm" (c)
6169 + : "er" (i), "m" (v->counter) : "memory");
6170 + return c;
6171 +@@ -355,7 +531,15 @@ static inline int atomic64_add_negative(
6172 + static inline long atomic64_add_return(long i, atomic64_t *v)
6173 + {
6174 + long __i = i;
6175 +- asm volatile(LOCK_PREFIX "xaddq %0, %1;"
6176 ++ asm volatile(LOCK_PREFIX "xaddq %0, %1\n"
6177 ++
6178 ++#ifdef CONFIG_PAX_REFCOUNT
6179 ++ "jno 0f\n"
6180 ++ "movq %0, %1\n"
6181 ++ "int $4\n0:\n"
6182 ++ _ASM_EXTABLE(0b, 0b)
6183 ++#endif
6184 ++
6185 + : "+r" (i), "+m" (v->counter)
6186 + : : "memory");
6187 + return i + __i;
6188 +diff -urNp linux-2.6.28/arch/x86/include/asm/boot.h linux-2.6.28/arch/x86/include/asm/boot.h
6189 +--- linux-2.6.28/arch/x86/include/asm/boot.h 2008-12-24 18:26:37.000000000 -0500
6190 ++++ linux-2.6.28/arch/x86/include/asm/boot.h 2009-01-11 07:20:06.000000000 -0500
6191 +@@ -11,10 +11,15 @@
6192 + #define ASK_VGA 0xfffd /* ask for it at bootup */
6193 +
6194 + /* Physical address where kernel should be loaded. */
6195 +-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
6196 ++#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
6197 + + (CONFIG_PHYSICAL_ALIGN - 1)) \
6198 + & ~(CONFIG_PHYSICAL_ALIGN - 1))
6199 +
6200 ++#ifndef __ASSEMBLY__
6201 ++extern unsigned char __LOAD_PHYSICAL_ADDR[];
6202 ++#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
6203 ++#endif
6204 ++
6205 + #ifdef CONFIG_X86_64
6206 + #define BOOT_HEAP_SIZE 0x7000
6207 + #define BOOT_STACK_SIZE 0x4000
6208 +diff -urNp linux-2.6.28/arch/x86/include/asm/cache.h linux-2.6.28/arch/x86/include/asm/cache.h
6209 +--- linux-2.6.28/arch/x86/include/asm/cache.h 2008-12-24 18:26:37.000000000 -0500
6210 ++++ linux-2.6.28/arch/x86/include/asm/cache.h 2009-01-11 07:20:06.000000000 -0500
6211 +@@ -6,6 +6,7 @@
6212 + #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6213 +
6214 + #define __read_mostly __attribute__((__section__(".data.read_mostly")))
6215 ++#define __read_only __attribute__((__section__(".data.read_only")))
6216 +
6217 + #ifdef CONFIG_X86_VSMP
6218 + /* vSMP Internode cacheline shift */
6219 +diff -urNp linux-2.6.28/arch/x86/include/asm/checksum_32.h linux-2.6.28/arch/x86/include/asm/checksum_32.h
6220 +--- linux-2.6.28/arch/x86/include/asm/checksum_32.h 2008-12-24 18:26:37.000000000 -0500
6221 ++++ linux-2.6.28/arch/x86/include/asm/checksum_32.h 2009-01-11 07:20:06.000000000 -0500
6222 +@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_gene
6223 + int len, __wsum sum,
6224 + int *src_err_ptr, int *dst_err_ptr);
6225 +
6226 ++asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
6227 ++ int len, __wsum sum,
6228 ++ int *src_err_ptr, int *dst_err_ptr);
6229 ++
6230 ++asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
6231 ++ int len, __wsum sum,
6232 ++ int *src_err_ptr, int *dst_err_ptr);
6233 ++
6234 + /*
6235 + * Note: when you get a NULL pointer exception here this means someone
6236 + * passed in an incorrect kernel address to one of these functions.
6237 +@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_f
6238 + int *err_ptr)
6239 + {
6240 + might_sleep();
6241 +- return csum_partial_copy_generic((__force void *)src, dst,
6242 ++ return csum_partial_copy_generic_from_user((__force void *)src, dst,
6243 + len, sum, err_ptr, NULL);
6244 + }
6245 +
6246 +@@ -177,7 +185,7 @@ static inline __wsum csum_and_copy_to_us
6247 + {
6248 + might_sleep();
6249 + if (access_ok(VERIFY_WRITE, dst, len))
6250 +- return csum_partial_copy_generic(src, (__force void *)dst,
6251 ++ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
6252 + len, sum, NULL, err_ptr);
6253 +
6254 + if (len)
6255 +diff -urNp linux-2.6.28/arch/x86/include/asm/cpufeature.h linux-2.6.28/arch/x86/include/asm/cpufeature.h
6256 +--- linux-2.6.28/arch/x86/include/asm/cpufeature.h 2008-12-24 18:26:37.000000000 -0500
6257 ++++ linux-2.6.28/arch/x86/include/asm/cpufeature.h 2009-01-11 07:20:06.000000000 -0500
6258 +@@ -80,7 +80,6 @@
6259 + #define X86_FEATURE_UP (3*32+ 9) /* smp kernel running on up */
6260 + #define X86_FEATURE_FXSAVE_LEAK (3*32+10) /* "" FXSAVE leaks FOP/FIP/FOP */
6261 + #define X86_FEATURE_ARCH_PERFMON (3*32+11) /* Intel Architectural PerfMon */
6262 +-#define X86_FEATURE_NOPL (3*32+20) /* The NOPL (0F 1F) instructions */
6263 + #define X86_FEATURE_PEBS (3*32+12) /* Precise-Event Based Sampling */
6264 + #define X86_FEATURE_BTS (3*32+13) /* Branch Trace Store */
6265 + #define X86_FEATURE_SYSCALL32 (3*32+14) /* "" syscall in ia32 userspace */
6266 +diff -urNp linux-2.6.28/arch/x86/include/asm/desc.h linux-2.6.28/arch/x86/include/asm/desc.h
6267 +--- linux-2.6.28/arch/x86/include/asm/desc.h 2008-12-24 18:26:37.000000000 -0500
6268 ++++ linux-2.6.28/arch/x86/include/asm/desc.h 2009-01-11 07:20:06.000000000 -0500
6269 +@@ -16,6 +16,7 @@ static inline void fill_ldt(struct desc_
6270 + desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
6271 + desc->type = (info->read_exec_only ^ 1) << 1;
6272 + desc->type |= info->contents << 2;
6273 ++ desc->type |= info->seg_not_present ^ 1;
6274 + desc->s = 1;
6275 + desc->dpl = 0x3;
6276 + desc->p = info->seg_not_present ^ 1;
6277 +@@ -32,16 +33,12 @@ static inline void fill_ldt(struct desc_
6278 + }
6279 +
6280 + extern struct desc_ptr idt_descr;
6281 +-extern gate_desc idt_table[];
6282 +-
6283 +-struct gdt_page {
6284 +- struct desc_struct gdt[GDT_ENTRIES];
6285 +-} __attribute__((aligned(PAGE_SIZE)));
6286 +-DECLARE_PER_CPU(struct gdt_page, gdt_page);
6287 ++extern gate_desc idt_table[256];
6288 +
6289 ++extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
6290 + static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
6291 + {
6292 +- return per_cpu(gdt_page, cpu).gdt;
6293 ++ return cpu_gdt_table[cpu];
6294 + }
6295 +
6296 + #ifdef CONFIG_X86_64
6297 +@@ -115,19 +112,48 @@ static inline void paravirt_free_ldt(str
6298 + static inline void native_write_idt_entry(gate_desc *idt, int entry,
6299 + const gate_desc *gate)
6300 + {
6301 ++
6302 ++#ifdef CONFIG_PAX_KERNEXEC
6303 ++ unsigned long cr0;
6304 ++
6305 ++ pax_open_kernel(cr0);
6306 ++#endif
6307 ++
6308 + memcpy(&idt[entry], gate, sizeof(*gate));
6309 ++
6310 ++#ifdef CONFIG_PAX_KERNEXEC
6311 ++ pax_close_kernel(cr0);
6312 ++#endif
6313 ++
6314 + }
6315 +
6316 + static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry,
6317 + const void *desc)
6318 + {
6319 ++
6320 ++#ifdef CONFIG_PAX_KERNEXEC
6321 ++ unsigned long cr0;
6322 ++
6323 ++ pax_open_kernel(cr0);
6324 ++#endif
6325 ++
6326 + memcpy(&ldt[entry], desc, 8);
6327 ++
6328 ++#ifdef CONFIG_PAX_KERNEXEC
6329 ++ pax_close_kernel(cr0);
6330 ++#endif
6331 ++
6332 + }
6333 +
6334 + static inline void native_write_gdt_entry(struct desc_struct *gdt, int entry,
6335 + const void *desc, int type)
6336 + {
6337 + unsigned int size;
6338 ++
6339 ++#ifdef CONFIG_PAX_KERNEXEC
6340 ++ unsigned long cr0;
6341 ++#endif
6342 ++
6343 + switch (type) {
6344 + case DESC_TSS:
6345 + size = sizeof(tss_desc);
6346 +@@ -139,7 +165,17 @@ static inline void native_write_gdt_entr
6347 + size = sizeof(struct desc_struct);
6348 + break;
6349 + }
6350 ++
6351 ++#ifdef CONFIG_PAX_KERNEXEC
6352 ++ pax_open_kernel(cr0);
6353 ++#endif
6354 ++
6355 + memcpy(&gdt[entry], desc, size);
6356 ++
6357 ++#ifdef CONFIG_PAX_KERNEXEC
6358 ++ pax_close_kernel(cr0);
6359 ++#endif
6360 ++
6361 + }
6362 +
6363 + static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
6364 +@@ -211,7 +247,19 @@ static inline void native_set_ldt(const
6365 +
6366 + static inline void native_load_tr_desc(void)
6367 + {
6368 ++
6369 ++#ifdef CONFIG_PAX_KERNEXEC
6370 ++ unsigned long cr0;
6371 ++
6372 ++ pax_open_kernel(cr0);
6373 ++#endif
6374 ++
6375 + asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
6376 ++
6377 ++#ifdef CONFIG_PAX_KERNEXEC
6378 ++ pax_close_kernel(cr0);
6379 ++#endif
6380 ++
6381 + }
6382 +
6383 + static inline void native_load_gdt(const struct desc_ptr *dtr)
6384 +@@ -246,8 +294,19 @@ static inline void native_load_tls(struc
6385 + unsigned int i;
6386 + struct desc_struct *gdt = get_cpu_gdt_table(cpu);
6387 +
6388 ++#ifdef CONFIG_PAX_KERNEXEC
6389 ++ unsigned long cr0;
6390 ++
6391 ++ pax_open_kernel(cr0);
6392 ++#endif
6393 ++
6394 + for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
6395 + gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
6396 ++
6397 ++#ifdef CONFIG_PAX_KERNEXEC
6398 ++ pax_close_kernel(cr0);
6399 ++#endif
6400 ++
6401 + }
6402 +
6403 + #define _LDT_empty(info) \
6404 +@@ -381,6 +440,18 @@ static inline void set_system_intr_gate_
6405 + _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
6406 + }
6407 +
6408 ++#ifdef CONFIG_X86_32
6409 ++static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
6410 ++{
6411 ++ struct desc_struct d;
6412 ++
6413 ++ if (likely(limit))
6414 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
6415 ++ pack_descriptor(&d, base, limit, 0xFB, 0xC);
6416 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
6417 ++}
6418 ++#endif
6419 ++
6420 + #else
6421 + /*
6422 + * GET_DESC_BASE reads the descriptor base of the specified segment.
6423 +diff -urNp linux-2.6.28/arch/x86/include/asm/e820.h linux-2.6.28/arch/x86/include/asm/e820.h
6424 +--- linux-2.6.28/arch/x86/include/asm/e820.h 2008-12-24 18:26:37.000000000 -0500
6425 ++++ linux-2.6.28/arch/x86/include/asm/e820.h 2009-01-11 07:20:06.000000000 -0500
6426 +@@ -134,7 +134,7 @@ extern char *memory_setup(void);
6427 + #define ISA_END_ADDRESS 0x100000
6428 + #define is_ISA_range(s, e) ((s) >= ISA_START_ADDRESS && (e) < ISA_END_ADDRESS)
6429 +
6430 +-#define BIOS_BEGIN 0x000a0000
6431 ++#define BIOS_BEGIN 0x000c0000
6432 + #define BIOS_END 0x00100000
6433 +
6434 + #ifdef __KERNEL__
6435 +diff -urNp linux-2.6.28/arch/x86/include/asm/elf.h linux-2.6.28/arch/x86/include/asm/elf.h
6436 +--- linux-2.6.28/arch/x86/include/asm/elf.h 2008-12-24 18:26:37.000000000 -0500
6437 ++++ linux-2.6.28/arch/x86/include/asm/elf.h 2009-01-11 07:20:06.000000000 -0500
6438 +@@ -252,7 +252,25 @@ extern int force_personality32;
6439 + the loader. We need to make sure that it is out of the way of the program
6440 + that it will "exec", and that there is sufficient room for the brk. */
6441 +
6442 ++#ifdef CONFIG_PAX_SEGMEXEC
6443 ++#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
6444 ++#else
6445 + #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6446 ++#endif
6447 ++
6448 ++#ifdef CONFIG_PAX_ASLR
6449 ++#ifdef CONFIG_X86_32
6450 ++#define PAX_ELF_ET_DYN_BASE 0x10000000UL
6451 ++
6452 ++#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
6453 ++#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
6454 ++#else
6455 ++#define PAX_ELF_ET_DYN_BASE 0x400000UL
6456 ++
6457 ++#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
6458 ++#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_IA32)) ? 16 : 32)
6459 ++#endif
6460 ++#endif
6461 +
6462 + /* This yields a mask that user programs can use to figure out what
6463 + instruction set this CPU supports. This could be done in user space,
6464 +@@ -304,8 +322,7 @@ do { \
6465 + #define ARCH_DLINFO \
6466 + do { \
6467 + if (vdso_enabled) \
6468 +- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
6469 +- (unsigned long)current->mm->context.vdso); \
6470 ++ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso);\
6471 + } while (0)
6472 +
6473 + #define AT_SYSINFO 32
6474 +@@ -316,7 +333,7 @@ do { \
6475 +
6476 + #endif /* !CONFIG_X86_32 */
6477 +
6478 +-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
6479 ++#define VDSO_CURRENT_BASE (current->mm->context.vdso)
6480 +
6481 + #define VDSO_ENTRY \
6482 + ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
6483 +@@ -330,7 +347,4 @@ extern int arch_setup_additional_pages(s
6484 + extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
6485 + #define compat_arch_setup_additional_pages syscall32_setup_pages
6486 +
6487 +-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6488 +-#define arch_randomize_brk arch_randomize_brk
6489 +-
6490 + #endif /* _ASM_X86_ELF_H */
6491 +diff -urNp linux-2.6.28/arch/x86/include/asm/futex.h linux-2.6.28/arch/x86/include/asm/futex.h
6492 +--- linux-2.6.28/arch/x86/include/asm/futex.h 2008-12-24 18:26:37.000000000 -0500
6493 ++++ linux-2.6.28/arch/x86/include/asm/futex.h 2009-01-11 07:20:06.000000000 -0500
6494 +@@ -11,6 +11,40 @@
6495 + #include <asm/processor.h>
6496 + #include <asm/system.h>
6497 +
6498 ++#ifdef CONFIG_X86_32
6499 ++#define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
6500 ++ asm volatile( \
6501 ++ "movw\t%w6, %%ds\n" \
6502 ++ "1:\t" insn "\n" \
6503 ++ "2:\tpushl\t%%ss\n" \
6504 ++ "\tpopl\t%%ds\n" \
6505 ++ "\t.section .fixup,\"ax\"\n" \
6506 ++ "3:\tmov\t%3, %1\n" \
6507 ++ "\tjmp\t2b\n" \
6508 ++ "\t.previous\n" \
6509 ++ _ASM_EXTABLE(1b, 3b) \
6510 ++ : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
6511 ++ : "i" (-EFAULT), "0" (oparg), "1" (0), "r" (__USER_DS))
6512 ++
6513 ++#define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
6514 ++ asm volatile("movw\t%w7, %%es\n" \
6515 ++ "1:\tmovl\t%%es:%2, %0\n" \
6516 ++ "\tmovl\t%0, %3\n" \
6517 ++ "\t" insn "\n" \
6518 ++ "2:\tlock; cmpxchgl %3, %%es:%2\n" \
6519 ++ "\tjnz\t1b\n" \
6520 ++ "3:\tpushl\t%%ss\n" \
6521 ++ "\tpopl\t%%es\n" \
6522 ++ "\t.section .fixup,\"ax\"\n" \
6523 ++ "4:\tmov\t%5, %1\n" \
6524 ++ "\tjmp\t3b\n" \
6525 ++ "\t.previous\n" \
6526 ++ _ASM_EXTABLE(1b, 4b) \
6527 ++ _ASM_EXTABLE(2b, 4b) \
6528 ++ : "=&a" (oldval), "=&r" (ret), \
6529 ++ "+m" (*uaddr), "=&r" (tem) \
6530 ++ : "r" (oparg), "i" (-EFAULT), "1" (0), "r" (__USER_DS))
6531 ++#else
6532 + #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
6533 + asm volatile("1:\t" insn "\n" \
6534 + "2:\t.section .fixup,\"ax\"\n" \
6535 +@@ -36,8 +70,9 @@
6536 + : "=&a" (oldval), "=&r" (ret), \
6537 + "+m" (*uaddr), "=&r" (tem) \
6538 + : "r" (oparg), "i" (-EFAULT), "1" (0))
6539 ++#endif
6540 +
6541 +-static inline int futex_atomic_op_inuser(int encoded_op, int __user *uaddr)
6542 ++static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
6543 + {
6544 + int op = (encoded_op >> 28) & 7;
6545 + int cmp = (encoded_op >> 24) & 15;
6546 +@@ -61,11 +96,20 @@ static inline int futex_atomic_op_inuser
6547 +
6548 + switch (op) {
6549 + case FUTEX_OP_SET:
6550 ++#ifdef CONFIG_X86_32
6551 ++ __futex_atomic_op1("xchgl %0, %%ds:%2", ret, oldval, uaddr, oparg);
6552 ++#else
6553 + __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
6554 ++#endif
6555 + break;
6556 + case FUTEX_OP_ADD:
6557 ++#ifdef CONFIG_X86_32
6558 ++ __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %%ds:%2", ret, oldval,
6559 ++ uaddr, oparg);
6560 ++#else
6561 + __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
6562 + uaddr, oparg);
6563 ++#endif
6564 + break;
6565 + case FUTEX_OP_OR:
6566 + __futex_atomic_op2("orl %4, %3", ret, oldval, uaddr, oparg);
6567 +@@ -109,7 +153,7 @@ static inline int futex_atomic_op_inuser
6568 + return ret;
6569 + }
6570 +
6571 +-static inline int futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval,
6572 ++static inline int futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval,
6573 + int newval)
6574 + {
6575 +
6576 +@@ -122,14 +166,27 @@ static inline int futex_atomic_cmpxchg_i
6577 + if (!access_ok(VERIFY_WRITE, uaddr, sizeof(int)))
6578 + return -EFAULT;
6579 +
6580 +- asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %3, %1\n"
6581 ++ asm volatile(
6582 ++#ifdef CONFIG_X86_32
6583 ++ "\tmovw %w5, %%ds\n"
6584 ++ "1:\tlock; cmpxchgl %3, %1\n"
6585 ++ "2:\tpushl %%ss\n"
6586 ++ "\tpopl %%ds\n"
6587 ++ "\t.section .fixup, \"ax\"\n"
6588 ++#else
6589 ++ "1:\tlock; cmpxchgl %3, %1\n"
6590 + "2:\t.section .fixup, \"ax\"\n"
6591 ++#endif
6592 + "3:\tmov %2, %0\n"
6593 + "\tjmp 2b\n"
6594 + "\t.previous\n"
6595 + _ASM_EXTABLE(1b, 3b)
6596 + : "=a" (oldval), "+m" (*uaddr)
6597 ++#ifdef CONFIG_X86_32
6598 ++ : "i" (-EFAULT), "r" (newval), "0" (oldval), "r" (__USER_DS)
6599 ++#else
6600 + : "i" (-EFAULT), "r" (newval), "0" (oldval)
6601 ++#endif
6602 + : "memory"
6603 + );
6604 +
6605 +diff -urNp linux-2.6.28/arch/x86/include/asm/i387.h linux-2.6.28/arch/x86/include/asm/i387.h
6606 +--- linux-2.6.28/arch/x86/include/asm/i387.h 2008-12-24 18:26:37.000000000 -0500
6607 ++++ linux-2.6.28/arch/x86/include/asm/i387.h 2009-01-11 07:20:06.000000000 -0500
6608 +@@ -197,13 +197,8 @@ static inline void restore_fpu(struct ta
6609 + }
6610 +
6611 + /* We need a safe address that is cheap to find and that is already
6612 +- in L1 during context switch. The best choices are unfortunately
6613 +- different for UP and SMP */
6614 +-#ifdef CONFIG_SMP
6615 +-#define safe_address (__per_cpu_offset[0])
6616 +-#else
6617 +-#define safe_address (kstat_cpu(0).cpustat.user)
6618 +-#endif
6619 ++ in L1 during context switch. */
6620 ++#define safe_address (init_tss[smp_processor_id()].x86_tss.sp0)
6621 +
6622 + /*
6623 + * These must be called with preempt disabled
6624 +diff -urNp linux-2.6.28/arch/x86/include/asm/io_64.h linux-2.6.28/arch/x86/include/asm/io_64.h
6625 +--- linux-2.6.28/arch/x86/include/asm/io_64.h 2008-12-24 18:26:37.000000000 -0500
6626 ++++ linux-2.6.28/arch/x86/include/asm/io_64.h 2009-01-11 07:20:06.000000000 -0500
6627 +@@ -158,6 +158,17 @@ static inline void *phys_to_virt(unsigne
6628 + }
6629 + #endif
6630 +
6631 ++#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
6632 ++static inline int valid_phys_addr_range (unsigned long addr, size_t count)
6633 ++{
6634 ++ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
6635 ++}
6636 ++
6637 ++static inline int valid_mmap_phys_addr_range (unsigned long pfn, size_t count)
6638 ++{
6639 ++ return (pfn + (count >> PAGE_SHIFT)) < (1 << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
6640 ++}
6641 ++
6642 + /*
6643 + * Change "struct page" to physical address.
6644 + */
6645 +diff -urNp linux-2.6.28/arch/x86/include/asm/irqflags.h linux-2.6.28/arch/x86/include/asm/irqflags.h
6646 +--- linux-2.6.28/arch/x86/include/asm/irqflags.h 2008-12-24 18:26:37.000000000 -0500
6647 ++++ linux-2.6.28/arch/x86/include/asm/irqflags.h 2009-01-11 07:20:06.000000000 -0500
6648 +@@ -141,6 +141,8 @@ static inline unsigned long __raw_local_
6649 + #define INTERRUPT_RETURN iret
6650 + #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
6651 + #define GET_CR0_INTO_EAX movl %cr0, %eax
6652 ++#define GET_CR0_INTO_EDX movl %cr0, %edx
6653 ++#define SET_CR0_FROM_EDX movl %edx, %cr0
6654 + #endif
6655 +
6656 +
6657 +diff -urNp linux-2.6.28/arch/x86/include/asm/kmap_types.h linux-2.6.28/arch/x86/include/asm/kmap_types.h
6658 +--- linux-2.6.28/arch/x86/include/asm/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
6659 ++++ linux-2.6.28/arch/x86/include/asm/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
6660 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
6661 + D(10) KM_IRQ1,
6662 + D(11) KM_SOFTIRQ0,
6663 + D(12) KM_SOFTIRQ1,
6664 +-D(13) KM_TYPE_NR
6665 ++D(13) KM_CLEARPAGE,
6666 ++D(14) KM_TYPE_NR
6667 + };
6668 +
6669 + #undef D
6670 +diff -urNp linux-2.6.28/arch/x86/include/asm/linkage.h linux-2.6.28/arch/x86/include/asm/linkage.h
6671 +--- linux-2.6.28/arch/x86/include/asm/linkage.h 2008-12-24 18:26:37.000000000 -0500
6672 ++++ linux-2.6.28/arch/x86/include/asm/linkage.h 2009-01-11 07:20:06.000000000 -0500
6673 +@@ -7,6 +7,11 @@
6674 + #ifdef CONFIG_X86_64
6675 + #define __ALIGN .p2align 4,,15
6676 + #define __ALIGN_STR ".p2align 4,,15"
6677 ++#else
6678 ++#ifdef CONFIG_X86_ALIGNMENT_16
6679 ++#define __ALIGN .align 16,0x90
6680 ++#define __ALIGN_STR ".align 16,0x90"
6681 ++#endif
6682 + #endif
6683 +
6684 + #ifdef CONFIG_X86_32
6685 +@@ -52,10 +57,5 @@
6686 +
6687 + #endif
6688 +
6689 +-#ifdef CONFIG_X86_ALIGNMENT_16
6690 +-#define __ALIGN .align 16,0x90
6691 +-#define __ALIGN_STR ".align 16,0x90"
6692 +-#endif
6693 +-
6694 + #endif /* _ASM_X86_LINKAGE_H */
6695 +
6696 +diff -urNp linux-2.6.28/arch/x86/include/asm/local.h linux-2.6.28/arch/x86/include/asm/local.h
6697 +--- linux-2.6.28/arch/x86/include/asm/local.h 2008-12-24 18:26:37.000000000 -0500
6698 ++++ linux-2.6.28/arch/x86/include/asm/local.h 2009-01-11 07:20:06.000000000 -0500
6699 +@@ -18,26 +18,90 @@ typedef struct {
6700 +
6701 + static inline void local_inc(local_t *l)
6702 + {
6703 +- asm volatile(_ASM_INC "%0"
6704 ++ asm volatile(_ASM_INC "%0\n"
6705 ++
6706 ++#ifdef CONFIG_PAX_REFCOUNT
6707 ++#ifdef CONFIG_X86_32
6708 ++ "into\n0:\n"
6709 ++#else
6710 ++ "jno 0f\n"
6711 ++ "int $4\n0:\n"
6712 ++#endif
6713 ++ ".pushsection .fixup,\"ax\"\n"
6714 ++ "1:\n"
6715 ++ _ASM_DEC "%0\n"
6716 ++ "jmp 0b\n"
6717 ++ ".popsection\n"
6718 ++ _ASM_EXTABLE(0b, 1b)
6719 ++#endif
6720 ++
6721 + : "+m" (l->a.counter));
6722 + }
6723 +
6724 + static inline void local_dec(local_t *l)
6725 + {
6726 +- asm volatile(_ASM_DEC "%0"
6727 ++ asm volatile(_ASM_DEC "%0\n"
6728 ++
6729 ++#ifdef CONFIG_PAX_REFCOUNT
6730 ++#ifdef CONFIG_X86_32
6731 ++ "into\n0:\n"
6732 ++#else
6733 ++ "jno 0f\n"
6734 ++ "int $4\n0:\n"
6735 ++#endif
6736 ++ ".pushsection .fixup,\"ax\"\n"
6737 ++ "1:\n"
6738 ++ _ASM_INC "%0\n"
6739 ++ "jmp 0b\n"
6740 ++ ".popsection\n"
6741 ++ _ASM_EXTABLE(0b, 1b)
6742 ++#endif
6743 ++
6744 + : "+m" (l->a.counter));
6745 + }
6746 +
6747 + static inline void local_add(long i, local_t *l)
6748 + {
6749 +- asm volatile(_ASM_ADD "%1,%0"
6750 ++ asm volatile(_ASM_ADD "%1,%0\n"
6751 ++
6752 ++#ifdef CONFIG_PAX_REFCOUNT
6753 ++#ifdef CONFIG_X86_32
6754 ++ "into\n0:\n"
6755 ++#else
6756 ++ "jno 0f\n"
6757 ++ "int $4\n0:\n"
6758 ++#endif
6759 ++ ".pushsection .fixup,\"ax\"\n"
6760 ++ "1:\n"
6761 ++ _ASM_SUB "%1,%0\n"
6762 ++ "jmp 0b\n"
6763 ++ ".popsection\n"
6764 ++ _ASM_EXTABLE(0b, 1b)
6765 ++#endif
6766 ++
6767 + : "+m" (l->a.counter)
6768 + : "ir" (i));
6769 + }
6770 +
6771 + static inline void local_sub(long i, local_t *l)
6772 + {
6773 +- asm volatile(_ASM_SUB "%1,%0"
6774 ++ asm volatile(_ASM_SUB "%1,%0\n"
6775 ++
6776 ++#ifdef CONFIG_PAX_REFCOUNT
6777 ++#ifdef CONFIG_X86_32
6778 ++ "into\n0:\n"
6779 ++#else
6780 ++ "jno 0f\n"
6781 ++ "int $4\n0:\n"
6782 ++#endif
6783 ++ ".pushsection .fixup,\"ax\"\n"
6784 ++ "1:\n"
6785 ++ _ASM_ADD "%1,%0\n"
6786 ++ "jmp 0b\n"
6787 ++ ".popsection\n"
6788 ++ _ASM_EXTABLE(0b, 1b)
6789 ++#endif
6790 ++
6791 + : "+m" (l->a.counter)
6792 + : "ir" (i));
6793 + }
6794 +@@ -55,7 +119,24 @@ static inline int local_sub_and_test(lon
6795 + {
6796 + unsigned char c;
6797 +
6798 +- asm volatile(_ASM_SUB "%2,%0; sete %1"
6799 ++ asm volatile(_ASM_SUB "%2,%0\n"
6800 ++
6801 ++#ifdef CONFIG_PAX_REFCOUNT
6802 ++#ifdef CONFIG_X86_32
6803 ++ "into\n0:\n"
6804 ++#else
6805 ++ "jno 0f\n"
6806 ++ "int $4\n0:\n"
6807 ++#endif
6808 ++ ".pushsection .fixup,\"ax\"\n"
6809 ++ "1:\n"
6810 ++ _ASM_ADD "%2,%0\n"
6811 ++ "jmp 0b\n"
6812 ++ ".popsection\n"
6813 ++ _ASM_EXTABLE(0b, 1b)
6814 ++#endif
6815 ++
6816 ++ "sete %1\n"
6817 + : "+m" (l->a.counter), "=qm" (c)
6818 + : "ir" (i) : "memory");
6819 + return c;
6820 +@@ -73,7 +154,24 @@ static inline int local_dec_and_test(loc
6821 + {
6822 + unsigned char c;
6823 +
6824 +- asm volatile(_ASM_DEC "%0; sete %1"
6825 ++ asm volatile(_ASM_DEC "%0\n"
6826 ++
6827 ++#ifdef CONFIG_PAX_REFCOUNT
6828 ++#ifdef CONFIG_X86_32
6829 ++ "into\n0:\n"
6830 ++#else
6831 ++ "jno 0f\n"
6832 ++ "int $4\n0:\n"
6833 ++#endif
6834 ++ ".pushsection .fixup,\"ax\"\n"
6835 ++ "1:\n"
6836 ++ _ASM_INC "%0\n"
6837 ++ "jmp 0b\n"
6838 ++ ".popsection\n"
6839 ++ _ASM_EXTABLE(0b, 1b)
6840 ++#endif
6841 ++
6842 ++ "sete %1\n"
6843 + : "+m" (l->a.counter), "=qm" (c)
6844 + : : "memory");
6845 + return c != 0;
6846 +@@ -91,7 +189,24 @@ static inline int local_inc_and_test(loc
6847 + {
6848 + unsigned char c;
6849 +
6850 +- asm volatile(_ASM_INC "%0; sete %1"
6851 ++ asm volatile(_ASM_INC "%0\n"
6852 ++
6853 ++#ifdef CONFIG_PAX_REFCOUNT
6854 ++#ifdef CONFIG_X86_32
6855 ++ "into\n0:\n"
6856 ++#else
6857 ++ "jno 0f\n"
6858 ++ "int $4\n0:\n"
6859 ++#endif
6860 ++ ".pushsection .fixup,\"ax\"\n"
6861 ++ "1:\n"
6862 ++ _ASM_DEC "%0\n"
6863 ++ "jmp 0b\n"
6864 ++ ".popsection\n"
6865 ++ _ASM_EXTABLE(0b, 1b)
6866 ++#endif
6867 ++
6868 ++ "sete %1\n"
6869 + : "+m" (l->a.counter), "=qm" (c)
6870 + : : "memory");
6871 + return c != 0;
6872 +@@ -110,7 +225,24 @@ static inline int local_add_negative(lon
6873 + {
6874 + unsigned char c;
6875 +
6876 +- asm volatile(_ASM_ADD "%2,%0; sets %1"
6877 ++ asm volatile(_ASM_ADD "%2,%0\n"
6878 ++
6879 ++#ifdef CONFIG_PAX_REFCOUNT
6880 ++#ifdef CONFIG_X86_32
6881 ++ "into\n0:\n"
6882 ++#else
6883 ++ "jno 0f\n"
6884 ++ "int $4\n0:\n"
6885 ++#endif
6886 ++ ".pushsection .fixup,\"ax\"\n"
6887 ++ "1:\n"
6888 ++ _ASM_SUB "%2,%0\n"
6889 ++ "jmp 0b\n"
6890 ++ ".popsection\n"
6891 ++ _ASM_EXTABLE(0b, 1b)
6892 ++#endif
6893 ++
6894 ++ "sets %1\n"
6895 + : "+m" (l->a.counter), "=qm" (c)
6896 + : "ir" (i) : "memory");
6897 + return c;
6898 +@@ -133,7 +265,23 @@ static inline long local_add_return(long
6899 + #endif
6900 + /* Modern 486+ processor */
6901 + __i = i;
6902 +- asm volatile(_ASM_XADD "%0, %1;"
6903 ++ asm volatile(_ASM_XADD "%0, %1\n"
6904 ++
6905 ++#ifdef CONFIG_PAX_REFCOUNT
6906 ++#ifdef CONFIG_X86_32
6907 ++ "into\n0:\n"
6908 ++#else
6909 ++ "jno 0f\n"
6910 ++ "int $4\n0:\n"
6911 ++#endif
6912 ++ ".pushsection .fixup,\"ax\"\n"
6913 ++ "1:\n"
6914 ++ _ASM_MOV "%0,%1\n"
6915 ++ "jmp 0b\n"
6916 ++ ".popsection\n"
6917 ++ _ASM_EXTABLE(0b, 1b)
6918 ++#endif
6919 ++
6920 + : "+r" (i), "+m" (l->a.counter)
6921 + : : "memory");
6922 + return i + __i;
6923 +diff -urNp linux-2.6.28/arch/x86/include/asm/mach-default/apm.h linux-2.6.28/arch/x86/include/asm/mach-default/apm.h
6924 +--- linux-2.6.28/arch/x86/include/asm/mach-default/apm.h 2008-12-24 18:26:37.000000000 -0500
6925 ++++ linux-2.6.28/arch/x86/include/asm/mach-default/apm.h 2009-01-11 07:20:06.000000000 -0500
6926 +@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32
6927 + __asm__ __volatile__(APM_DO_ZERO_SEGS
6928 + "pushl %%edi\n\t"
6929 + "pushl %%ebp\n\t"
6930 +- "lcall *%%cs:apm_bios_entry\n\t"
6931 ++ "lcall *%%ss:apm_bios_entry\n\t"
6932 + "setc %%al\n\t"
6933 + "popl %%ebp\n\t"
6934 + "popl %%edi\n\t"
6935 +@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_as
6936 + __asm__ __volatile__(APM_DO_ZERO_SEGS
6937 + "pushl %%edi\n\t"
6938 + "pushl %%ebp\n\t"
6939 +- "lcall *%%cs:apm_bios_entry\n\t"
6940 ++ "lcall *%%ss:apm_bios_entry\n\t"
6941 + "setc %%bl\n\t"
6942 + "popl %%ebp\n\t"
6943 + "popl %%edi\n\t"
6944 +diff -urNp linux-2.6.28/arch/x86/include/asm/mman.h linux-2.6.28/arch/x86/include/asm/mman.h
6945 +--- linux-2.6.28/arch/x86/include/asm/mman.h 2008-12-24 18:26:37.000000000 -0500
6946 ++++ linux-2.6.28/arch/x86/include/asm/mman.h 2009-01-11 07:20:06.000000000 -0500
6947 +@@ -17,4 +17,14 @@
6948 + #define MCL_CURRENT 1 /* lock all current mappings */
6949 + #define MCL_FUTURE 2 /* lock all future mappings */
6950 +
6951 ++#ifdef __KERNEL__
6952 ++#ifndef __ASSEMBLY__
6953 ++#ifdef CONFIG_X86_32
6954 ++#define arch_mmap_check i386_mmap_check
6955 ++int i386_mmap_check(unsigned long addr, unsigned long len,
6956 ++ unsigned long flags);
6957 ++#endif
6958 ++#endif
6959 ++#endif
6960 ++
6961 + #endif /* _ASM_X86_MMAN_H */
6962 +diff -urNp linux-2.6.28/arch/x86/include/asm/mmu_context_32.h linux-2.6.28/arch/x86/include/asm/mmu_context_32.h
6963 +--- linux-2.6.28/arch/x86/include/asm/mmu_context_32.h 2008-12-24 18:26:37.000000000 -0500
6964 ++++ linux-2.6.28/arch/x86/include/asm/mmu_context_32.h 2009-01-11 07:20:06.000000000 -0500
6965 +@@ -33,6 +33,22 @@ static inline void switch_mm(struct mm_s
6966 + */
6967 + if (unlikely(prev->context.ldt != next->context.ldt))
6968 + load_LDT_nolock(&next->context);
6969 ++
6970 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
6971 ++ if (!nx_enabled) {
6972 ++ smp_mb__before_clear_bit();
6973 ++ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
6974 ++ smp_mb__after_clear_bit();
6975 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
6976 ++ }
6977 ++#endif
6978 ++
6979 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
6980 ++ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
6981 ++ prev->context.user_cs_limit != next->context.user_cs_limit))
6982 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
6983 ++#endif
6984 ++
6985 + }
6986 + #ifdef CONFIG_SMP
6987 + else {
6988 +@@ -45,6 +61,19 @@ static inline void switch_mm(struct mm_s
6989 + */
6990 + load_cr3(next->pgd);
6991 + load_LDT_nolock(&next->context);
6992 ++
6993 ++#ifdef CONFIG_PAX_PAGEEXEC
6994 ++ if (!nx_enabled)
6995 ++ cpu_set(cpu, next->context.cpu_user_cs_mask);
6996 ++#endif
6997 ++
6998 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
6999 ++#ifdef CONFIG_PAX_PAGEEXEC
7000 ++ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && nx_enabled))
7001 ++#endif
7002 ++ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
7003 ++#endif
7004 ++
7005 + }
7006 + }
7007 + #endif
7008 +diff -urNp linux-2.6.28/arch/x86/include/asm/mmu.h linux-2.6.28/arch/x86/include/asm/mmu.h
7009 +--- linux-2.6.28/arch/x86/include/asm/mmu.h 2008-12-24 18:26:37.000000000 -0500
7010 ++++ linux-2.6.28/arch/x86/include/asm/mmu.h 2009-01-11 07:20:06.000000000 -0500
7011 +@@ -9,10 +9,23 @@
7012 + * we put the segment information here.
7013 + */
7014 + typedef struct {
7015 +- void *ldt;
7016 ++ struct desc_struct *ldt;
7017 + int size;
7018 + struct mutex lock;
7019 +- void *vdso;
7020 ++ unsigned long vdso;
7021 ++
7022 ++#ifdef CONFIG_X86_32
7023 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
7024 ++ unsigned long user_cs_base;
7025 ++ unsigned long user_cs_limit;
7026 ++
7027 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
7028 ++ cpumask_t cpu_user_cs_mask;
7029 ++#endif
7030 ++
7031 ++#endif
7032 ++#endif
7033 ++
7034 + } mm_context_t;
7035 +
7036 + #ifdef CONFIG_SMP
7037 +diff -urNp linux-2.6.28/arch/x86/include/asm/module.h linux-2.6.28/arch/x86/include/asm/module.h
7038 +--- linux-2.6.28/arch/x86/include/asm/module.h 2008-12-24 18:26:37.000000000 -0500
7039 ++++ linux-2.6.28/arch/x86/include/asm/module.h 2009-01-11 06:08:50.000000000 -0500
7040 +@@ -74,7 +74,12 @@ struct mod_arch_specific {};
7041 + # else
7042 + # define MODULE_STACKSIZE ""
7043 + # endif
7044 +-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE
7045 ++# ifdef CONFIG_GRKERNSEC
7046 ++# define MODULE_GRSEC "GRSECURITY "
7047 ++# else
7048 ++# define MODULE_GRSEC ""
7049 ++# endif
7050 ++# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_STACKSIZE MODULE_GRSEC
7051 + #endif
7052 +
7053 + #endif /* _ASM_X86_MODULE_H */
7054 +diff -urNp linux-2.6.28/arch/x86/include/asm/page_32.h linux-2.6.28/arch/x86/include/asm/page_32.h
7055 +--- linux-2.6.28/arch/x86/include/asm/page_32.h 2008-12-24 18:26:37.000000000 -0500
7056 ++++ linux-2.6.28/arch/x86/include/asm/page_32.h 2009-01-11 07:20:06.000000000 -0500
7057 +@@ -13,6 +13,23 @@
7058 + */
7059 + #define __PAGE_OFFSET _AC(CONFIG_PAGE_OFFSET, UL)
7060 +
7061 ++#ifdef CONFIG_PAX_KERNEXEC
7062 ++#ifndef __ASSEMBLY__
7063 ++extern unsigned char MODULES_VADDR[];
7064 ++extern unsigned char MODULES_END[];
7065 ++extern unsigned char KERNEL_TEXT_OFFSET[];
7066 ++#define ktla_ktva(addr) (addr + (unsigned long)KERNEL_TEXT_OFFSET)
7067 ++#define ktva_ktla(addr) (addr - (unsigned long)KERNEL_TEXT_OFFSET)
7068 ++#endif
7069 ++#else
7070 ++#define ktla_ktva(addr) (addr)
7071 ++#define ktva_ktla(addr) (addr)
7072 ++#endif
7073 ++
7074 ++#ifdef CONFIG_PAX_PAGEEXEC
7075 ++#define CONFIG_ARCH_TRACK_EXEC_LIMIT 1
7076 ++#endif
7077 ++
7078 + #ifdef CONFIG_4KSTACKS
7079 + #define THREAD_ORDER 0
7080 + #else
7081 +diff -urNp linux-2.6.28/arch/x86/include/asm/page_64.h linux-2.6.28/arch/x86/include/asm/page_64.h
7082 +--- linux-2.6.28/arch/x86/include/asm/page_64.h 2008-12-24 18:26:37.000000000 -0500
7083 ++++ linux-2.6.28/arch/x86/include/asm/page_64.h 2009-01-11 07:20:06.000000000 -0500
7084 +@@ -49,6 +49,9 @@
7085 + #define __START_KERNEL (__START_KERNEL_map + __PHYSICAL_START)
7086 + #define __START_KERNEL_map _AC(0xffffffff80000000, UL)
7087 +
7088 ++#define ktla_ktva(addr) (addr)
7089 ++#define ktva_ktla(addr) (addr)
7090 ++
7091 + /* See Documentation/x86_64/mm.txt for a description of the memory map. */
7092 + #define __PHYSICAL_MASK_SHIFT 46
7093 + #define __VIRTUAL_MASK_SHIFT 48
7094 +@@ -101,5 +104,6 @@ extern void init_extra_mapping_wb(unsign
7095 + #define pfn_valid(pfn) ((pfn) < max_pfn)
7096 + #endif
7097 +
7098 ++#define nx_enabled (1)
7099 +
7100 + #endif /* _ASM_X86_PAGE_64_H */
7101 +diff -urNp linux-2.6.28/arch/x86/include/asm/paravirt.h linux-2.6.28/arch/x86/include/asm/paravirt.h
7102 +--- linux-2.6.28/arch/x86/include/asm/paravirt.h 2008-12-24 18:26:37.000000000 -0500
7103 ++++ linux-2.6.28/arch/x86/include/asm/paravirt.h 2009-01-11 07:20:06.000000000 -0500
7104 +@@ -1570,7 +1570,7 @@ static inline unsigned long __raw_local_
7105 + #define PV_RESTORE_REGS popl %edx; popl %ecx; popl %edi; popl %eax
7106 + #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
7107 + #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
7108 +-#define PARA_INDIRECT(addr) *%cs:addr
7109 ++#define PARA_INDIRECT(addr) *%ss:addr
7110 + #endif
7111 +
7112 + #define INTERRUPT_RETURN \
7113 +diff -urNp linux-2.6.28/arch/x86/include/asm/pda.h linux-2.6.28/arch/x86/include/asm/pda.h
7114 +--- linux-2.6.28/arch/x86/include/asm/pda.h 2008-12-24 18:26:37.000000000 -0500
7115 ++++ linux-2.6.28/arch/x86/include/asm/pda.h 2009-01-11 07:20:06.000000000 -0500
7116 +@@ -16,11 +16,9 @@ struct x8664_pda {
7117 + unsigned long oldrsp; /* 24 user rsp for system call */
7118 + int irqcount; /* 32 Irq nesting counter. Starts -1 */
7119 + unsigned int cpunumber; /* 36 Logical CPU number */
7120 +-#ifdef CONFIG_CC_STACKPROTECTOR
7121 + unsigned long stack_canary; /* 40 stack canary value */
7122 + /* gcc-ABI: this canary MUST be at
7123 + offset 40!!! */
7124 +-#endif
7125 + char *irqstackptr;
7126 + short nodenumber; /* number of current node (32k max) */
7127 + short in_bootmem; /* pda lives in bootmem */
7128 +diff -urNp linux-2.6.28/arch/x86/include/asm/percpu.h linux-2.6.28/arch/x86/include/asm/percpu.h
7129 +--- linux-2.6.28/arch/x86/include/asm/percpu.h 2008-12-24 18:26:37.000000000 -0500
7130 ++++ linux-2.6.28/arch/x86/include/asm/percpu.h 2009-01-11 07:20:06.000000000 -0500
7131 +@@ -93,6 +93,12 @@ DECLARE_PER_CPU(struct x8664_pda, pda);
7132 +
7133 + #define __my_cpu_offset x86_read_percpu(this_cpu_off)
7134 +
7135 ++#include <asm-generic/sections.h>
7136 ++#include <linux/threads.h>
7137 ++#define __per_cpu_offset __per_cpu_offset
7138 ++extern unsigned long __per_cpu_offset[NR_CPUS];
7139 ++#define per_cpu_offset(x) (__per_cpu_offset[x] + (unsigned long)__per_cpu_start)
7140 ++
7141 + /* fs segment starts at (positive) offset == __per_cpu_offset[cpu] */
7142 + #define __percpu_seg "%%fs:"
7143 +
7144 +diff -urNp linux-2.6.28/arch/x86/include/asm/pgalloc.h linux-2.6.28/arch/x86/include/asm/pgalloc.h
7145 +--- linux-2.6.28/arch/x86/include/asm/pgalloc.h 2008-12-24 18:26:37.000000000 -0500
7146 ++++ linux-2.6.28/arch/x86/include/asm/pgalloc.h 2009-01-11 07:20:06.000000000 -0500
7147 +@@ -51,7 +51,7 @@ static inline void pmd_populate_kernel(s
7148 + pmd_t *pmd, pte_t *pte)
7149 + {
7150 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
7151 +- set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
7152 ++ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
7153 + }
7154 +
7155 + static inline void pmd_populate(struct mm_struct *mm, pmd_t *pmd,
7156 +diff -urNp linux-2.6.28/arch/x86/include/asm/pgtable-2level.h linux-2.6.28/arch/x86/include/asm/pgtable-2level.h
7157 +--- linux-2.6.28/arch/x86/include/asm/pgtable-2level.h 2008-12-24 18:26:37.000000000 -0500
7158 ++++ linux-2.6.28/arch/x86/include/asm/pgtable-2level.h 2009-01-11 07:20:06.000000000 -0500
7159 +@@ -18,7 +18,19 @@ static inline void native_set_pte(pte_t
7160 +
7161 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
7162 + {
7163 ++
7164 ++#ifdef CONFIG_PAX_KERNEXEC
7165 ++ unsigned long cr0;
7166 ++
7167 ++ pax_open_kernel(cr0);
7168 ++#endif
7169 ++
7170 + *pmdp = pmd;
7171 ++
7172 ++#ifdef CONFIG_PAX_KERNEXEC
7173 ++ pax_close_kernel(cr0);
7174 ++#endif
7175 ++
7176 + }
7177 +
7178 + static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
7179 +diff -urNp linux-2.6.28/arch/x86/include/asm/pgtable_32.h linux-2.6.28/arch/x86/include/asm/pgtable_32.h
7180 +--- linux-2.6.28/arch/x86/include/asm/pgtable_32.h 2008-12-24 18:26:37.000000000 -0500
7181 ++++ linux-2.6.28/arch/x86/include/asm/pgtable_32.h 2009-01-11 07:20:06.000000000 -0500
7182 +@@ -25,8 +25,6 @@
7183 + struct mm_struct;
7184 + struct vm_area_struct;
7185 +
7186 +-extern pgd_t swapper_pg_dir[1024];
7187 +-
7188 + static inline void pgtable_cache_init(void) { }
7189 + static inline void check_pgt_cache(void) { }
7190 + void paging_init(void);
7191 +@@ -46,6 +44,11 @@ extern void set_pmd_pfn(unsigned long, u
7192 + # include <asm/pgtable-2level-defs.h>
7193 + #endif
7194 +
7195 ++extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
7196 ++#ifdef CONFIG_X86_PAE
7197 ++extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
7198 ++#endif
7199 ++
7200 + #define PGDIR_SIZE (1UL << PGDIR_SHIFT)
7201 + #define PGDIR_MASK (~(PGDIR_SIZE - 1))
7202 +
7203 +@@ -83,7 +86,7 @@ extern void set_pmd_pfn(unsigned long, u
7204 + #undef TEST_ACCESS_OK
7205 +
7206 + /* The boot page tables (all created as a single array) */
7207 +-extern unsigned long pg0[];
7208 ++extern pte_t pg0[];
7209 +
7210 + #define pte_present(x) ((x).pte_low & (_PAGE_PRESENT | _PAGE_PROTNONE))
7211 +
7212 +@@ -175,6 +178,9 @@ do { \
7213 +
7214 + #endif /* !__ASSEMBLY__ */
7215 +
7216 ++#define HAVE_ARCH_UNMAPPED_AREA
7217 ++#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
7218 ++
7219 + /*
7220 + * kern_addr_valid() is (1) for FLATMEM and (0) for
7221 + * SPARSEMEM and DISCONTIGMEM
7222 +diff -urNp linux-2.6.28/arch/x86/include/asm/pgtable-3level.h linux-2.6.28/arch/x86/include/asm/pgtable-3level.h
7223 +--- linux-2.6.28/arch/x86/include/asm/pgtable-3level.h 2008-12-24 18:26:37.000000000 -0500
7224 ++++ linux-2.6.28/arch/x86/include/asm/pgtable-3level.h 2009-01-11 07:20:06.000000000 -0500
7225 +@@ -70,12 +70,36 @@ static inline void native_set_pte_atomic
7226 +
7227 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
7228 + {
7229 ++
7230 ++#ifdef CONFIG_PAX_KERNEXEC
7231 ++ unsigned long cr0;
7232 ++
7233 ++ pax_open_kernel(cr0);
7234 ++#endif
7235 ++
7236 + set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
7237 ++
7238 ++#ifdef CONFIG_PAX_KERNEXEC
7239 ++ pax_close_kernel(cr0);
7240 ++#endif
7241 ++
7242 + }
7243 +
7244 + static inline void native_set_pud(pud_t *pudp, pud_t pud)
7245 + {
7246 ++
7247 ++#ifdef CONFIG_PAX_KERNEXEC
7248 ++ unsigned long cr0;
7249 ++
7250 ++ pax_open_kernel(cr0);
7251 ++#endif
7252 ++
7253 + set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
7254 ++
7255 ++#ifdef CONFIG_PAX_KERNEXEC
7256 ++ pax_close_kernel(cr0);
7257 ++#endif
7258 ++
7259 + }
7260 +
7261 + /*
7262 +diff -urNp linux-2.6.28/arch/x86/include/asm/pgtable_64.h linux-2.6.28/arch/x86/include/asm/pgtable_64.h
7263 +--- linux-2.6.28/arch/x86/include/asm/pgtable_64.h 2008-12-24 18:26:37.000000000 -0500
7264 ++++ linux-2.6.28/arch/x86/include/asm/pgtable_64.h 2009-01-11 07:20:06.000000000 -0500
7265 +@@ -15,9 +15,12 @@
7266 +
7267 + extern pud_t level3_kernel_pgt[512];
7268 + extern pud_t level3_ident_pgt[512];
7269 ++extern pud_t level3_vmalloc_pgt[512];
7270 ++extern pud_t level3_vmemmap_pgt[512];
7271 + extern pmd_t level2_kernel_pgt[512];
7272 + extern pmd_t level2_fixmap_pgt[512];
7273 +-extern pmd_t level2_ident_pgt[512];
7274 ++extern pmd_t level2_ident_pgt[512*4];
7275 ++extern pte_t level1_fixmap_pgt[512];
7276 + extern pgd_t init_level4_pgt[];
7277 +
7278 + #define swapper_pg_dir init_level4_pgt
7279 +@@ -106,7 +109,19 @@ static inline pte_t native_ptep_get_and_
7280 +
7281 + static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
7282 + {
7283 ++
7284 ++#ifdef CONFIG_PAX_KERNEXEC
7285 ++ unsigned long cr0;
7286 ++
7287 ++ pax_open_kernel(cr0);
7288 ++#endif
7289 ++
7290 + *pmdp = pmd;
7291 ++
7292 ++#ifdef CONFIG_PAX_KERNEXEC
7293 ++ pax_close_kernel(cr0);
7294 ++#endif
7295 ++
7296 + }
7297 +
7298 + static inline void native_pmd_clear(pmd_t *pmd)
7299 +@@ -158,17 +173,17 @@ static inline void native_pgd_clear(pgd_
7300 +
7301 + static inline int pgd_bad(pgd_t pgd)
7302 + {
7303 +- return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
7304 ++ return (pgd_val(pgd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
7305 + }
7306 +
7307 + static inline int pud_bad(pud_t pud)
7308 + {
7309 +- return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
7310 ++ return (pud_val(pud) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
7311 + }
7312 +
7313 + static inline int pmd_bad(pmd_t pmd)
7314 + {
7315 +- return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER)) != _KERNPG_TABLE;
7316 ++ return (pmd_val(pmd) & ~(PTE_PFN_MASK | _PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
7317 + }
7318 +
7319 + #define pte_none(x) (!pte_val((x)))
7320 +diff -urNp linux-2.6.28/arch/x86/include/asm/pgtable.h linux-2.6.28/arch/x86/include/asm/pgtable.h
7321 +--- linux-2.6.28/arch/x86/include/asm/pgtable.h 2008-12-24 18:26:37.000000000 -0500
7322 ++++ linux-2.6.28/arch/x86/include/asm/pgtable.h 2009-01-11 07:20:06.000000000 -0500
7323 +@@ -14,12 +14,11 @@
7324 + #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
7325 + #define _PAGE_BIT_PAT 7 /* on 4KB pages */
7326 + #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
7327 +-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
7328 ++#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
7329 + #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
7330 + #define _PAGE_BIT_UNUSED3 11
7331 + #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
7332 +-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
7333 +-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
7334 ++#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
7335 + #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
7336 +
7337 + #define _PAGE_PRESENT (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT)
7338 +@@ -31,7 +30,6 @@
7339 + #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
7340 + #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
7341 + #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
7342 +-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
7343 + #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
7344 + #define _PAGE_UNUSED3 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
7345 + #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
7346 +@@ -43,7 +41,7 @@
7347 + #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
7348 + #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
7349 + #else
7350 +-#define _PAGE_NX (_AT(pteval_t, 0))
7351 ++#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED3)
7352 + #endif
7353 +
7354 + /* If _PAGE_PRESENT is clear, we use these: */
7355 +@@ -83,6 +81,9 @@
7356 + #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
7357 + _PAGE_ACCESSED)
7358 +
7359 ++#define PAGE_READONLY_NOEXEC PAGE_READONLY
7360 ++#define PAGE_SHARED_NOEXEC PAGE_SHARED
7361 ++
7362 + #define __PAGE_KERNEL_EXEC \
7363 + (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
7364 + #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
7365 +@@ -94,7 +95,7 @@
7366 + #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
7367 + #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
7368 + #define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
7369 +-#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_VSYSCALL | _PAGE_PCD | _PAGE_PWT)
7370 ++#define __PAGE_KERNEL_VSYSCALL_NOCACHE (__PAGE_KERNEL_RO | _PAGE_PCD | _PAGE_PWT | _PAGE_USER)
7371 + #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
7372 + #define __PAGE_KERNEL_LARGE_NOCACHE (__PAGE_KERNEL | _PAGE_CACHE_UC | _PAGE_PSE)
7373 + #define __PAGE_KERNEL_LARGE_EXEC (__PAGE_KERNEL_EXEC | _PAGE_PSE)
7374 +@@ -153,7 +154,7 @@
7375 + * bits are combined, this will alow user to access the high address mapped
7376 + * VDSO in the presence of CONFIG_COMPAT_VDSO
7377 + */
7378 +-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
7379 ++#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
7380 + #define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
7381 + #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
7382 + #endif
7383 +@@ -170,10 +171,17 @@ extern unsigned long empty_zero_page[PAG
7384 + extern spinlock_t pgd_lock;
7385 + extern struct list_head pgd_list;
7386 +
7387 ++extern pteval_t __supported_pte_mask;
7388 ++
7389 + /*
7390 + * The following only work if pte_present() is true.
7391 + * Undefined behaviour if not..
7392 + */
7393 ++static inline int pte_user(pte_t pte)
7394 ++{
7395 ++ return pte_val(pte) & _PAGE_USER;
7396 ++}
7397 ++
7398 + static inline int pte_dirty(pte_t pte)
7399 + {
7400 + return pte_flags(pte) & _PAGE_DIRTY;
7401 +@@ -242,9 +250,29 @@ static inline pte_t pte_wrprotect(pte_t
7402 + return __pte(pte_val(pte) & ~_PAGE_RW);
7403 + }
7404 +
7405 ++static inline pte_t pte_mkread(pte_t pte)
7406 ++{
7407 ++ return __pte(pte_val(pte) | _PAGE_USER);
7408 ++}
7409 ++
7410 + static inline pte_t pte_mkexec(pte_t pte)
7411 + {
7412 +- return __pte(pte_val(pte) & ~_PAGE_NX);
7413 ++#ifdef CONFIG_X86_PAE
7414 ++ if (__supported_pte_mask & _PAGE_NX)
7415 ++ return __pte(pte_val(pte) & ~(pteval_t)_PAGE_NX);
7416 ++ else
7417 ++#endif
7418 ++ return __pte(pte_val(pte) | _PAGE_USER);
7419 ++}
7420 ++
7421 ++static inline pte_t pte_exprotect(pte_t pte)
7422 ++{
7423 ++#ifdef CONFIG_X86_PAE
7424 ++ if (__supported_pte_mask & _PAGE_NX)
7425 ++ return __pte(pte_val(pte) | _PAGE_NX);
7426 ++ else
7427 ++#endif
7428 ++ return __pte(pte_val(pte) & ~_PAGE_USER);
7429 + }
7430 +
7431 + static inline pte_t pte_mkdirty(pte_t pte)
7432 +@@ -287,8 +315,6 @@ static inline pte_t pte_mkspecial(pte_t
7433 + return __pte(pte_val(pte) | _PAGE_SPECIAL);
7434 + }
7435 +
7436 +-extern pteval_t __supported_pte_mask;
7437 +-
7438 + static inline pte_t pfn_pte(unsigned long page_nr, pgprot_t pgprot)
7439 + {
7440 + return __pte((((phys_addr_t)page_nr << PAGE_SHIFT) |
7441 +@@ -552,7 +578,19 @@ static inline void ptep_set_wrprotect(st
7442 + */
7443 + static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
7444 + {
7445 +- memcpy(dst, src, count * sizeof(pgd_t));
7446 ++
7447 ++#ifdef CONFIG_PAX_KERNEXEC
7448 ++ unsigned long cr0;
7449 ++
7450 ++ pax_open_kernel(cr0);
7451 ++#endif
7452 ++
7453 ++ memcpy(dst, src, count * sizeof(pgd_t));
7454 ++
7455 ++#ifdef CONFIG_PAX_KERNEXEC
7456 ++ pax_close_kernel(cr0);
7457 ++#endif
7458 ++
7459 + }
7460 +
7461 +
7462 +diff -urNp linux-2.6.28/arch/x86/include/asm/processor.h linux-2.6.28/arch/x86/include/asm/processor.h
7463 +--- linux-2.6.28/arch/x86/include/asm/processor.h 2008-12-24 18:26:37.000000000 -0500
7464 ++++ linux-2.6.28/arch/x86/include/asm/processor.h 2009-01-11 07:20:06.000000000 -0500
7465 +@@ -271,7 +271,7 @@ struct tss_struct {
7466 +
7467 + } ____cacheline_aligned;
7468 +
7469 +-DECLARE_PER_CPU(struct tss_struct, init_tss);
7470 ++extern struct tss_struct init_tss[NR_CPUS];
7471 +
7472 + /*
7473 + * Save the original ist values for checking stack pointers during debugging
7474 +@@ -822,11 +822,20 @@ static inline void spin_lock_prefetch(co
7475 + * User space process size: 3GB (default).
7476 + */
7477 + #define TASK_SIZE PAGE_OFFSET
7478 ++
7479 ++#ifdef CONFIG_PAX_SEGMEXEC
7480 ++#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
7481 ++#endif
7482 ++
7483 ++#ifdef CONFIG_PAX_SEGMEXEC
7484 ++#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
7485 ++#else
7486 + #define STACK_TOP TASK_SIZE
7487 +-#define STACK_TOP_MAX STACK_TOP
7488 ++#endif
7489 ++#define STACK_TOP_MAX TASK_SIZE
7490 +
7491 + #define INIT_THREAD { \
7492 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
7493 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
7494 + .vm86_info = NULL, \
7495 + .sysenter_cs = __KERNEL_CS, \
7496 + .io_bitmap_ptr = NULL, \
7497 +@@ -841,7 +850,7 @@ static inline void spin_lock_prefetch(co
7498 + */
7499 + #define INIT_TSS { \
7500 + .x86_tss = { \
7501 +- .sp0 = sizeof(init_stack) + (long)&init_stack, \
7502 ++ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
7503 + .ss0 = __KERNEL_DS, \
7504 + .ss1 = __KERNEL_CS, \
7505 + .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
7506 +@@ -852,11 +861,7 @@ static inline void spin_lock_prefetch(co
7507 + extern unsigned long thread_saved_pc(struct task_struct *tsk);
7508 +
7509 + #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
7510 +-#define KSTK_TOP(info) \
7511 +-({ \
7512 +- unsigned long *__ptr = (unsigned long *)(info); \
7513 +- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
7514 +-})
7515 ++#define KSTK_TOP(info) ((info)->task.thread.sp0)
7516 +
7517 + /*
7518 + * The below -8 is to reserve 8 bytes on top of the ring0 stack.
7519 +@@ -871,7 +876,7 @@ extern unsigned long thread_saved_pc(str
7520 + #define task_pt_regs(task) \
7521 + ({ \
7522 + struct pt_regs *__regs__; \
7523 +- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
7524 ++ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
7525 + __regs__ - 1; \
7526 + })
7527 +
7528 +@@ -887,7 +892,7 @@ extern unsigned long thread_saved_pc(str
7529 + * space during mmap's.
7530 + */
7531 + #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
7532 +- 0xc0000000 : 0xFFFFe000)
7533 ++ 0xc0000000 : 0xFFFFf000)
7534 +
7535 + #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \
7536 + IA32_PAGE_OFFSET : TASK_SIZE64)
7537 +@@ -924,6 +929,10 @@ extern void start_thread(struct pt_regs
7538 + */
7539 + #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
7540 +
7541 ++#ifdef CONFIG_PAX_SEGMEXEC
7542 ++#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
7543 ++#endif
7544 ++
7545 + #define KSTK_EIP(task) (task_pt_regs(task)->ip)
7546 +
7547 + /* Get/set a process' ability to use the timestamp counter instruction */
7548 +diff -urNp linux-2.6.28/arch/x86/include/asm/ptrace.h linux-2.6.28/arch/x86/include/asm/ptrace.h
7549 +--- linux-2.6.28/arch/x86/include/asm/ptrace.h 2008-12-24 18:26:37.000000000 -0500
7550 ++++ linux-2.6.28/arch/x86/include/asm/ptrace.h 2009-01-11 07:20:06.000000000 -0500
7551 +@@ -187,28 +187,29 @@ static inline unsigned long regs_return_
7552 + }
7553 +
7554 + /*
7555 +- * user_mode_vm(regs) determines whether a register set came from user mode.
7556 ++ * user_mode(regs) determines whether a register set came from user mode.
7557 + * This is true if V8086 mode was enabled OR if the register set was from
7558 + * protected mode with RPL-3 CS value. This tricky test checks that with
7559 + * one comparison. Many places in the kernel can bypass this full check
7560 +- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
7561 ++ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
7562 ++ * be used.
7563 + */
7564 +-static inline int user_mode(struct pt_regs *regs)
7565 ++static inline int user_mode_novm(struct pt_regs *regs)
7566 + {
7567 + #ifdef CONFIG_X86_32
7568 + return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
7569 + #else
7570 +- return !!(regs->cs & 3);
7571 ++ return !!(regs->cs & SEGMENT_RPL_MASK);
7572 + #endif
7573 + }
7574 +
7575 +-static inline int user_mode_vm(struct pt_regs *regs)
7576 ++static inline int user_mode(struct pt_regs *regs)
7577 + {
7578 + #ifdef CONFIG_X86_32
7579 + return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
7580 + USER_RPL;
7581 + #else
7582 +- return user_mode(regs);
7583 ++ return user_mode_novm(regs);
7584 + #endif
7585 + }
7586 +
7587 +diff -urNp linux-2.6.28/arch/x86/include/asm/reboot.h linux-2.6.28/arch/x86/include/asm/reboot.h
7588 +--- linux-2.6.28/arch/x86/include/asm/reboot.h 2008-12-24 18:26:37.000000000 -0500
7589 ++++ linux-2.6.28/arch/x86/include/asm/reboot.h 2009-01-11 07:20:06.000000000 -0500
7590 +@@ -16,6 +16,6 @@ extern struct machine_ops machine_ops;
7591 +
7592 + void native_machine_crash_shutdown(struct pt_regs *regs);
7593 + void native_machine_shutdown(void);
7594 +-void machine_real_restart(const unsigned char *code, int length);
7595 ++void machine_real_restart(const unsigned char *code, unsigned int length);
7596 +
7597 + #endif /* _ASM_X86_REBOOT_H */
7598 +diff -urNp linux-2.6.28/arch/x86/include/asm/rwsem.h linux-2.6.28/arch/x86/include/asm/rwsem.h
7599 +--- linux-2.6.28/arch/x86/include/asm/rwsem.h 2008-12-24 18:26:37.000000000 -0500
7600 ++++ linux-2.6.28/arch/x86/include/asm/rwsem.h 2009-01-11 07:20:06.000000000 -0500
7601 +@@ -106,10 +106,26 @@ static inline void __down_read(struct rw
7602 + {
7603 + asm volatile("# beginning down_read\n\t"
7604 + LOCK_PREFIX " incl (%%eax)\n\t"
7605 ++
7606 ++#ifdef CONFIG_PAX_REFCOUNT
7607 ++#ifdef CONFIG_X86_32
7608 ++ "into\n0:\n"
7609 ++#else
7610 ++ "jno 0f\n"
7611 ++ "int $4\n0:\n"
7612 ++#endif
7613 ++ ".pushsection .fixup,\"ax\"\n"
7614 ++ "1:\n"
7615 ++ LOCK_PREFIX "decl (%%eax)\n"
7616 ++ "jmp 0b\n"
7617 ++ ".popsection\n"
7618 ++ _ASM_EXTABLE(0b, 1b)
7619 ++#endif
7620 ++
7621 + /* adds 0x00000001, returns the old value */
7622 +- " jns 1f\n"
7623 ++ " jns 2f\n"
7624 + " call call_rwsem_down_read_failed\n"
7625 +- "1:\n\t"
7626 ++ "2:\n\t"
7627 + "# ending down_read\n\t"
7628 + : "+m" (sem->count)
7629 + : "a" (sem)
7630 +@@ -124,13 +140,29 @@ static inline int __down_read_trylock(st
7631 + __s32 result, tmp;
7632 + asm volatile("# beginning __down_read_trylock\n\t"
7633 + " movl %0,%1\n\t"
7634 +- "1:\n\t"
7635 ++ "2:\n\t"
7636 + " movl %1,%2\n\t"
7637 + " addl %3,%2\n\t"
7638 +- " jle 2f\n\t"
7639 ++
7640 ++#ifdef CONFIG_PAX_REFCOUNT
7641 ++#ifdef CONFIG_X86_32
7642 ++ "into\n0:\n"
7643 ++#else
7644 ++ "jno 0f\n"
7645 ++ "int $4\n0:\n"
7646 ++#endif
7647 ++ ".pushsection .fixup,\"ax\"\n"
7648 ++ "1:\n"
7649 ++ "subl %3,%2\n"
7650 ++ "jmp 0b\n"
7651 ++ ".popsection\n"
7652 ++ _ASM_EXTABLE(0b, 1b)
7653 ++#endif
7654 ++
7655 ++ " jle 3f\n\t"
7656 + LOCK_PREFIX " cmpxchgl %2,%0\n\t"
7657 +- " jnz 1b\n\t"
7658 +- "2:\n\t"
7659 ++ " jnz 2b\n\t"
7660 ++ "3:\n\t"
7661 + "# ending __down_read_trylock\n\t"
7662 + : "+m" (sem->count), "=&a" (result), "=&r" (tmp)
7663 + : "i" (RWSEM_ACTIVE_READ_BIAS)
7664 +@@ -148,12 +180,28 @@ static inline void __down_write_nested(s
7665 + tmp = RWSEM_ACTIVE_WRITE_BIAS;
7666 + asm volatile("# beginning down_write\n\t"
7667 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
7668 ++
7669 ++#ifdef CONFIG_PAX_REFCOUNT
7670 ++#ifdef CONFIG_X86_32
7671 ++ "into\n0:\n"
7672 ++#else
7673 ++ "jno 0f\n"
7674 ++ "int $4\n0:\n"
7675 ++#endif
7676 ++ ".pushsection .fixup,\"ax\"\n"
7677 ++ "1:\n"
7678 ++ "movl %%edx,(%%eax)\n"
7679 ++ "jmp 0b\n"
7680 ++ ".popsection\n"
7681 ++ _ASM_EXTABLE(0b, 1b)
7682 ++#endif
7683 ++
7684 + /* subtract 0x0000ffff, returns the old value */
7685 + " testl %%edx,%%edx\n\t"
7686 + /* was the count 0 before? */
7687 +- " jz 1f\n"
7688 ++ " jz 2f\n"
7689 + " call call_rwsem_down_write_failed\n"
7690 +- "1:\n"
7691 ++ "2:\n"
7692 + "# ending down_write"
7693 + : "+m" (sem->count), "=d" (tmp)
7694 + : "a" (sem), "1" (tmp)
7695 +@@ -186,10 +234,26 @@ static inline void __up_read(struct rw_s
7696 + __s32 tmp = -RWSEM_ACTIVE_READ_BIAS;
7697 + asm volatile("# beginning __up_read\n\t"
7698 + LOCK_PREFIX " xadd %%edx,(%%eax)\n\t"
7699 ++
7700 ++#ifdef CONFIG_PAX_REFCOUNT
7701 ++#ifdef CONFIG_X86_32
7702 ++ "into\n0:\n"
7703 ++#else
7704 ++ "jno 0f\n"
7705 ++ "int $4\n0:\n"
7706 ++#endif
7707 ++ ".pushsection .fixup,\"ax\"\n"
7708 ++ "1:\n"
7709 ++ "movl %%edx,(%%eax)\n"
7710 ++ "jmp 0b\n"
7711 ++ ".popsection\n"
7712 ++ _ASM_EXTABLE(0b, 1b)
7713 ++#endif
7714 ++
7715 + /* subtracts 1, returns the old value */
7716 +- " jns 1f\n\t"
7717 ++ " jns 2f\n\t"
7718 + " call call_rwsem_wake\n"
7719 +- "1:\n"
7720 ++ "2:\n"
7721 + "# ending __up_read\n"
7722 + : "+m" (sem->count), "=d" (tmp)
7723 + : "a" (sem), "1" (tmp)
7724 +@@ -204,11 +268,27 @@ static inline void __up_write(struct rw_
7725 + asm volatile("# beginning __up_write\n\t"
7726 + " movl %2,%%edx\n\t"
7727 + LOCK_PREFIX " xaddl %%edx,(%%eax)\n\t"
7728 ++
7729 ++#ifdef CONFIG_PAX_REFCOUNT
7730 ++#ifdef CONFIG_X86_32
7731 ++ "into\n0:\n"
7732 ++#else
7733 ++ "jno 0f\n"
7734 ++ "int $4\n0:\n"
7735 ++#endif
7736 ++ ".pushsection .fixup,\"ax\"\n"
7737 ++ "1:\n"
7738 ++ "movl %%edx,(%%eax)\n"
7739 ++ "jmp 0b\n"
7740 ++ ".popsection\n"
7741 ++ _ASM_EXTABLE(0b, 1b)
7742 ++#endif
7743 ++
7744 + /* tries to transition
7745 + 0xffff0001 -> 0x00000000 */
7746 +- " jz 1f\n"
7747 ++ " jz 2f\n"
7748 + " call call_rwsem_wake\n"
7749 +- "1:\n\t"
7750 ++ "2:\n\t"
7751 + "# ending __up_write\n"
7752 + : "+m" (sem->count)
7753 + : "a" (sem), "i" (-RWSEM_ACTIVE_WRITE_BIAS)
7754 +@@ -222,10 +302,26 @@ static inline void __downgrade_write(str
7755 + {
7756 + asm volatile("# beginning __downgrade_write\n\t"
7757 + LOCK_PREFIX " addl %2,(%%eax)\n\t"
7758 ++
7759 ++#ifdef CONFIG_PAX_REFCOUNT
7760 ++#ifdef CONFIG_X86_32
7761 ++ "into\n0:\n"
7762 ++#else
7763 ++ "jno 0f\n"
7764 ++ "int $4\n0:\n"
7765 ++#endif
7766 ++ ".pushsection .fixup,\"ax\"\n"
7767 ++ "1:\n"
7768 ++ LOCK_PREFIX "subl %2,(%%eax)\n"
7769 ++ "jmp 0b\n"
7770 ++ ".popsection\n"
7771 ++ _ASM_EXTABLE(0b, 1b)
7772 ++#endif
7773 ++
7774 + /* transitions 0xZZZZ0001 -> 0xYYYY0001 */
7775 +- " jns 1f\n\t"
7776 ++ " jns 2f\n\t"
7777 + " call call_rwsem_downgrade_wake\n"
7778 +- "1:\n\t"
7779 ++ "2:\n\t"
7780 + "# ending __downgrade_write\n"
7781 + : "+m" (sem->count)
7782 + : "a" (sem), "i" (-RWSEM_WAITING_BIAS)
7783 +@@ -237,7 +333,23 @@ static inline void __downgrade_write(str
7784 + */
7785 + static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
7786 + {
7787 +- asm volatile(LOCK_PREFIX "addl %1,%0"
7788 ++ asm volatile(LOCK_PREFIX "addl %1,%0\n"
7789 ++
7790 ++#ifdef CONFIG_PAX_REFCOUNT
7791 ++#ifdef CONFIG_X86_32
7792 ++ "into\n0:\n"
7793 ++#else
7794 ++ "jno 0f\n"
7795 ++ "int $4\n0:\n"
7796 ++#endif
7797 ++ ".pushsection .fixup,\"ax\"\n"
7798 ++ "1:\n"
7799 ++ LOCK_PREFIX "subl %1,%0\n"
7800 ++ "jmp 0b\n"
7801 ++ ".popsection\n"
7802 ++ _ASM_EXTABLE(0b, 1b)
7803 ++#endif
7804 ++
7805 + : "+m" (sem->count)
7806 + : "ir" (delta));
7807 + }
7808 +@@ -249,7 +361,23 @@ static inline int rwsem_atomic_update(in
7809 + {
7810 + int tmp = delta;
7811 +
7812 +- asm volatile(LOCK_PREFIX "xadd %0,%1"
7813 ++ asm volatile(LOCK_PREFIX "xadd %0,%1\n"
7814 ++
7815 ++#ifdef CONFIG_PAX_REFCOUNT
7816 ++#ifdef CONFIG_X86_32
7817 ++ "into\n0:\n"
7818 ++#else
7819 ++ "jno 0f\n"
7820 ++ "int $4\n0:\n"
7821 ++#endif
7822 ++ ".pushsection .fixup,\"ax\"\n"
7823 ++ "1:\n"
7824 ++ "movl %0,%1\n"
7825 ++ "jmp 0b\n"
7826 ++ ".popsection\n"
7827 ++ _ASM_EXTABLE(0b, 1b)
7828 ++#endif
7829 ++
7830 + : "+r" (tmp), "+m" (sem->count)
7831 + : : "memory");
7832 +
7833 +diff -urNp linux-2.6.28/arch/x86/include/asm/segment.h linux-2.6.28/arch/x86/include/asm/segment.h
7834 +--- linux-2.6.28/arch/x86/include/asm/segment.h 2008-12-24 18:26:37.000000000 -0500
7835 ++++ linux-2.6.28/arch/x86/include/asm/segment.h 2009-01-11 07:20:06.000000000 -0500
7836 +@@ -88,13 +88,19 @@
7837 + #define GDT_ENTRY_ESPFIX_SS (GDT_ENTRY_KERNEL_BASE + 14)
7838 + #define __ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)
7839 +
7840 +-#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
7841 ++#define GDT_ENTRY_PERCPU (GDT_ENTRY_KERNEL_BASE + 15)
7842 + #ifdef CONFIG_SMP
7843 + #define __KERNEL_PERCPU (GDT_ENTRY_PERCPU * 8)
7844 + #else
7845 + #define __KERNEL_PERCPU 0
7846 + #endif
7847 +
7848 ++#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE + 16)
7849 ++#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
7850 ++
7851 ++#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE + 17)
7852 ++#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
7853 ++
7854 + #define GDT_ENTRY_DOUBLEFAULT_TSS 31
7855 +
7856 + /*
7857 +@@ -132,7 +138,7 @@
7858 + */
7859 +
7860 + /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
7861 +-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
7862 ++#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
7863 +
7864 +
7865 + #else
7866 +diff -urNp linux-2.6.28/arch/x86/include/asm/spinlock.h linux-2.6.28/arch/x86/include/asm/spinlock.h
7867 +--- linux-2.6.28/arch/x86/include/asm/spinlock.h 2008-12-24 18:26:37.000000000 -0500
7868 ++++ linux-2.6.28/arch/x86/include/asm/spinlock.h 2009-01-11 07:20:06.000000000 -0500
7869 +@@ -310,18 +310,50 @@ static inline int __raw_write_can_lock(r
7870 + static inline void __raw_read_lock(raw_rwlock_t *rw)
7871 + {
7872 + asm volatile(LOCK_PREFIX " subl $1,(%0)\n\t"
7873 +- "jns 1f\n"
7874 +- "call __read_lock_failed\n\t"
7875 ++
7876 ++#ifdef CONFIG_PAX_REFCOUNT
7877 ++#ifdef CONFIG_X86_32
7878 ++ "into\n0:\n"
7879 ++#else
7880 ++ "jno 0f\n"
7881 ++ "int $4\n0:\n"
7882 ++#endif
7883 ++ ".pushsection .fixup,\"ax\"\n"
7884 + "1:\n"
7885 ++ LOCK_PREFIX " addl $1,(%0)\n"
7886 ++ "jmp 0b\n"
7887 ++ ".popsection\n"
7888 ++ _ASM_EXTABLE(0b, 1b)
7889 ++#endif
7890 ++
7891 ++ "jns 2f\n"
7892 ++ "call __read_lock_failed\n\t"
7893 ++ "2:\n"
7894 + ::LOCK_PTR_REG (rw) : "memory");
7895 + }
7896 +
7897 + static inline void __raw_write_lock(raw_rwlock_t *rw)
7898 + {
7899 + asm volatile(LOCK_PREFIX " subl %1,(%0)\n\t"
7900 +- "jz 1f\n"
7901 +- "call __write_lock_failed\n\t"
7902 ++
7903 ++#ifdef CONFIG_PAX_REFCOUNT
7904 ++#ifdef CONFIG_X86_32
7905 ++ "into\n0:\n"
7906 ++#else
7907 ++ "jno 0f\n"
7908 ++ "int $4\n0:\n"
7909 ++#endif
7910 ++ ".pushsection .fixup,\"ax\"\n"
7911 + "1:\n"
7912 ++ LOCK_PREFIX " addl %1,(%0)\n"
7913 ++ "jmp 0b\n"
7914 ++ ".popsection\n"
7915 ++ _ASM_EXTABLE(0b, 1b)
7916 ++#endif
7917 ++
7918 ++ "jz 2f\n"
7919 ++ "call __write_lock_failed\n\t"
7920 ++ "2:\n"
7921 + ::LOCK_PTR_REG (rw), "i" (RW_LOCK_BIAS) : "memory");
7922 + }
7923 +
7924 +@@ -348,12 +380,45 @@ static inline int __raw_write_trylock(ra
7925 +
7926 + static inline void __raw_read_unlock(raw_rwlock_t *rw)
7927 + {
7928 +- asm volatile(LOCK_PREFIX "incl %0" :"+m" (rw->lock) : : "memory");
7929 ++ asm volatile(LOCK_PREFIX "incl %0\n"
7930 ++
7931 ++#ifdef CONFIG_PAX_REFCOUNT
7932 ++#ifdef CONFIG_X86_32
7933 ++ "into\n0:\n"
7934 ++#else
7935 ++ "jno 0f\n"
7936 ++ "int $4\n0:\n"
7937 ++#endif
7938 ++ ".pushsection .fixup,\"ax\"\n"
7939 ++ "1:\n"
7940 ++ LOCK_PREFIX "decl %0\n"
7941 ++ "jmp 0b\n"
7942 ++ ".popsection\n"
7943 ++ _ASM_EXTABLE(0b, 1b)
7944 ++#endif
7945 ++
7946 ++ :"+m" (rw->lock) : : "memory");
7947 + }
7948 +
7949 + static inline void __raw_write_unlock(raw_rwlock_t *rw)
7950 + {
7951 +- asm volatile(LOCK_PREFIX "addl %1, %0"
7952 ++ asm volatile(LOCK_PREFIX "addl %1, %0\n"
7953 ++
7954 ++#ifdef CONFIG_PAX_REFCOUNT
7955 ++#ifdef CONFIG_X86_32
7956 ++ "into\n0:\n"
7957 ++#else
7958 ++ "jno 0f\n"
7959 ++ "int $4\n0:\n"
7960 ++#endif
7961 ++ ".pushsection .fixup,\"ax\"\n"
7962 ++ "1:\n"
7963 ++ LOCK_PREFIX "subl %1,%0\n"
7964 ++ "jmp 0b\n"
7965 ++ ".popsection\n"
7966 ++ _ASM_EXTABLE(0b, 1b)
7967 ++#endif
7968 ++
7969 + : "+m" (rw->lock) : "i" (RW_LOCK_BIAS) : "memory");
7970 + }
7971 +
7972 +diff -urNp linux-2.6.28/arch/x86/include/asm/system.h linux-2.6.28/arch/x86/include/asm/system.h
7973 +--- linux-2.6.28/arch/x86/include/asm/system.h 2008-12-24 18:26:37.000000000 -0500
7974 ++++ linux-2.6.28/arch/x86/include/asm/system.h 2009-01-11 07:20:06.000000000 -0500
7975 +@@ -95,6 +95,8 @@ do { \
7976 + ".globl thread_return\n" \
7977 + "thread_return:\n\t" \
7978 + "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
7979 ++ "movq %P[task_canary](%%rsi),%%r8\n\t" \
7980 ++ "movq %%r8,%%gs:%P[pda_canary]\n\t" \
7981 + "movq %P[thread_info](%%rsi),%%r8\n\t" \
7982 + LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
7983 + "movq %%rax,%%rdi\n\t" \
7984 +@@ -106,7 +108,9 @@ do { \
7985 + [ti_flags] "i" (offsetof(struct thread_info, flags)), \
7986 + [tif_fork] "i" (TIF_FORK), \
7987 + [thread_info] "i" (offsetof(struct task_struct, stack)), \
7988 +- [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
7989 ++ [task_canary] "i" (offsetof(struct task_struct, stack_canary)), \
7990 ++ [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)), \
7991 ++ [pda_canary] "i" (offsetof(struct x8664_pda, stack_canary))\
7992 + : "memory", "cc" __EXTRA_CLOBBER)
7993 + #endif
7994 +
7995 +@@ -169,7 +173,7 @@ static inline unsigned long get_limit(un
7996 + {
7997 + unsigned long __limit;
7998 + asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
7999 +- return __limit + 1;
8000 ++ return __limit;
8001 + }
8002 +
8003 + static inline void native_clts(void)
8004 +@@ -295,6 +299,21 @@ static inline void native_wbinvd(void)
8005 +
8006 + #define stts() write_cr0(read_cr0() | X86_CR0_TS)
8007 +
8008 ++#define pax_open_kernel(cr0) \
8009 ++do { \
8010 ++ typecheck(unsigned long, cr0); \
8011 ++ preempt_disable(); \
8012 ++ cr0 = read_cr0(); \
8013 ++ write_cr0(cr0 & ~X86_CR0_WP); \
8014 ++} while (0)
8015 ++
8016 ++#define pax_close_kernel(cr0) \
8017 ++do { \
8018 ++ typecheck(unsigned long, cr0); \
8019 ++ write_cr0(cr0); \
8020 ++ preempt_enable_no_resched(); \
8021 ++} while (0)
8022 ++
8023 + #endif /* __KERNEL__ */
8024 +
8025 + static inline void clflush(volatile void *__p)
8026 +@@ -309,7 +328,7 @@ void enable_hlt(void);
8027 +
8028 + void cpu_idle_wait(void);
8029 +
8030 +-extern unsigned long arch_align_stack(unsigned long sp);
8031 ++#define arch_align_stack(x) ((x) & ~0xfUL)
8032 + extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
8033 +
8034 + void default_idle(void);
8035 +diff -urNp linux-2.6.28/arch/x86/include/asm/uaccess_64.h linux-2.6.28/arch/x86/include/asm/uaccess_64.h
8036 +--- linux-2.6.28/arch/x86/include/asm/uaccess_64.h 2008-12-24 18:26:37.000000000 -0500
8037 ++++ linux-2.6.28/arch/x86/include/asm/uaccess_64.h 2009-01-11 07:20:06.000000000 -0500
8038 +@@ -10,6 +10,8 @@
8039 + #include <linux/lockdep.h>
8040 + #include <asm/page.h>
8041 +
8042 ++#define set_fs(x) (current_thread_info()->addr_limit = (x))
8043 ++
8044 + /*
8045 + * Copy To/From Userspace
8046 + */
8047 +diff -urNp linux-2.6.28/arch/x86/include/asm/uaccess.h linux-2.6.28/arch/x86/include/asm/uaccess.h
8048 +--- linux-2.6.28/arch/x86/include/asm/uaccess.h 2008-12-24 18:26:37.000000000 -0500
8049 ++++ linux-2.6.28/arch/x86/include/asm/uaccess.h 2009-01-11 07:20:06.000000000 -0500
8050 +@@ -10,6 +10,7 @@
8051 + #include <linux/string.h>
8052 + #include <asm/asm.h>
8053 + #include <asm/page.h>
8054 ++#include <asm/segment.h>
8055 +
8056 + #define VERIFY_READ 0
8057 + #define VERIFY_WRITE 1
8058 +@@ -29,7 +30,12 @@
8059 +
8060 + #define get_ds() (KERNEL_DS)
8061 + #define get_fs() (current_thread_info()->addr_limit)
8062 ++#ifdef CONFIG_X86_32
8063 ++void __set_fs(mm_segment_t x, int cpu);
8064 ++void set_fs(mm_segment_t x);
8065 ++#else
8066 + #define set_fs(x) (current_thread_info()->addr_limit = (x))
8067 ++#endif
8068 +
8069 + #define segment_eq(a, b) ((a).seg == (b).seg)
8070 +
8071 +@@ -186,9 +192,12 @@ extern int __get_user_bad(void);
8072 +
8073 + #ifdef CONFIG_X86_32
8074 + #define __put_user_u64(x, addr, err) \
8075 +- asm volatile("1: movl %%eax,0(%2)\n" \
8076 +- "2: movl %%edx,4(%2)\n" \
8077 ++ asm volatile(" movw %w5,%%ds\n" \
8078 ++ "1: movl %%eax,%%ds:0(%2)\n" \
8079 ++ "2: movl %%edx,%%ds:4(%2)\n" \
8080 + "3:\n" \
8081 ++ " pushl %%ss\n" \
8082 ++ " popl %%ds\n" \
8083 + ".section .fixup,\"ax\"\n" \
8084 + "4: movl %3,%0\n" \
8085 + " jmp 3b\n" \
8086 +@@ -196,7 +205,8 @@ extern int __get_user_bad(void);
8087 + _ASM_EXTABLE(1b, 4b) \
8088 + _ASM_EXTABLE(2b, 4b) \
8089 + : "=r" (err) \
8090 +- : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err))
8091 ++ : "A" (x), "r" (addr), "i" (-EFAULT), "0" (err), \
8092 ++ "r"(__USER_DS))
8093 +
8094 + #define __put_user_x8(x, ptr, __ret_pu) \
8095 + asm volatile("call __put_user_8" : "=a" (__ret_pu) \
8096 +@@ -336,6 +346,22 @@ do { \
8097 + } \
8098 + } while (0)
8099 +
8100 ++#ifdef CONFIG_X86_32
8101 ++#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
8102 ++ asm volatile(" movw %w5,%%ds\n" \
8103 ++ "1: mov"itype" %%ds:%2,%"rtype"1\n" \
8104 ++ "2:\n" \
8105 ++ " pushl %%ss\n" \
8106 ++ " popl %%ds\n" \
8107 ++ ".section .fixup,\"ax\"\n" \
8108 ++ "3: movl %3,%0\n" \
8109 ++ " xor"itype" %"rtype"1,%"rtype"1\n" \
8110 ++ " jmp 2b\n" \
8111 ++ ".previous\n" \
8112 ++ _ASM_EXTABLE(1b, 3b) \
8113 ++ : "=r" (err), ltype (x) \
8114 ++ : "m" (__m(addr)), "i" (errret), "0" (err), "r"(__USER_DS))
8115 ++#else
8116 + #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
8117 + asm volatile("1: mov"itype" %2,%"rtype"1\n" \
8118 + "2:\n" \
8119 +@@ -347,6 +373,7 @@ do { \
8120 + _ASM_EXTABLE(1b, 3b) \
8121 + : "=r" (err), ltype(x) \
8122 + : "m" (__m(addr)), "i" (errret), "0" (err))
8123 ++#endif
8124 +
8125 + #define __put_user_nocheck(x, ptr, size) \
8126 + ({ \
8127 +@@ -373,6 +400,22 @@ struct __large_struct { unsigned long bu
8128 + * we do not write to any memory gcc knows about, so there are no
8129 + * aliasing issues.
8130 + */
8131 ++#ifdef CONFIG_X86_32
8132 ++#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
8133 ++ asm volatile(" movw %w5,%%ds\n" \
8134 ++ "1: mov"itype" %"rtype"1,%%ds:%2\n" \
8135 ++ "2:\n" \
8136 ++ " pushl %%ss\n" \
8137 ++ " popl %%ds\n" \
8138 ++ ".section .fixup,\"ax\"\n" \
8139 ++ "3: movl %3,%0\n" \
8140 ++ " jmp 2b\n" \
8141 ++ ".previous\n" \
8142 ++ _ASM_EXTABLE(1b, 3b) \
8143 ++ : "=r"(err) \
8144 ++ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err),\
8145 ++ "r"(__USER_DS))
8146 ++#else
8147 + #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
8148 + asm volatile("1: mov"itype" %"rtype"1,%2\n" \
8149 + "2:\n" \
8150 +@@ -383,6 +426,7 @@ struct __large_struct { unsigned long bu
8151 + _ASM_EXTABLE(1b, 3b) \
8152 + : "=r"(err) \
8153 + : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
8154 ++#endif
8155 + /**
8156 + * __get_user: - Get a simple variable from user space, with less checking.
8157 + * @x: Variable to store result.
8158 +@@ -443,6 +487,7 @@ extern struct movsl_mask {
8159 +
8160 + #define ARCH_HAS_NOCACHE_UACCESS 1
8161 +
8162 ++#define ARCH_HAS_SORT_EXTABLE
8163 + #ifdef CONFIG_X86_32
8164 + # include "uaccess_32.h"
8165 + #else
8166 +diff -urNp linux-2.6.28/arch/x86/Kconfig linux-2.6.28/arch/x86/Kconfig
8167 +--- linux-2.6.28/arch/x86/Kconfig 2008-12-24 18:26:37.000000000 -0500
8168 ++++ linux-2.6.28/arch/x86/Kconfig 2009-01-11 07:20:06.000000000 -0500
8169 +@@ -935,7 +935,7 @@ config PAGE_OFFSET
8170 + hex
8171 + default 0xB0000000 if VMSPLIT_3G_OPT
8172 + default 0x80000000 if VMSPLIT_2G
8173 +- default 0x78000000 if VMSPLIT_2G_OPT
8174 ++ default 0x70000000 if VMSPLIT_2G_OPT
8175 + default 0x40000000 if VMSPLIT_1G
8176 + default 0xC0000000
8177 + depends on X86_32
8178 +@@ -1337,8 +1337,7 @@ config KEXEC_JUMP
8179 + config PHYSICAL_START
8180 + hex "Physical address where the kernel is loaded" if (EMBEDDED || CRASH_DUMP)
8181 + default "0x1000000" if X86_NUMAQ
8182 +- default "0x200000" if X86_64
8183 +- default "0x100000"
8184 ++ default "0x200000"
8185 + help
8186 + This gives the physical address where the kernel is loaded.
8187 +
8188 +@@ -1430,9 +1429,9 @@ config HOTPLUG_CPU
8189 + Say N if you want to disable CPU hotplug.
8190 +
8191 + config COMPAT_VDSO
8192 +- def_bool y
8193 ++ def_bool n
8194 + prompt "Compat VDSO support"
8195 +- depends on X86_32 || IA32_EMULATION
8196 ++ depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
8197 + help
8198 + Map the 32-bit VDSO to the predictable old-style address too.
8199 + ---help---
8200 +diff -urNp linux-2.6.28/arch/x86/Kconfig.cpu linux-2.6.28/arch/x86/Kconfig.cpu
8201 +--- linux-2.6.28/arch/x86/Kconfig.cpu 2008-12-24 18:26:37.000000000 -0500
8202 ++++ linux-2.6.28/arch/x86/Kconfig.cpu 2009-01-11 07:20:06.000000000 -0500
8203 +@@ -331,7 +331,7 @@ config X86_PPRO_FENCE
8204 +
8205 + config X86_F00F_BUG
8206 + def_bool y
8207 +- depends on M586MMX || M586TSC || M586 || M486 || M386
8208 ++ depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
8209 +
8210 + config X86_WP_WORKS_OK
8211 + def_bool y
8212 +@@ -351,7 +351,7 @@ config X86_POPAD_OK
8213 +
8214 + config X86_ALIGNMENT_16
8215 + def_bool y
8216 +- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8217 ++ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
8218 +
8219 + config X86_INTEL_USERCOPY
8220 + def_bool y
8221 +@@ -397,7 +397,7 @@ config X86_CMPXCHG64
8222 + # generates cmov.
8223 + config X86_CMOV
8224 + def_bool y
8225 +- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64)
8226 ++ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64)
8227 +
8228 + config X86_MINIMUM_CPU_FAMILY
8229 + int
8230 +diff -urNp linux-2.6.28/arch/x86/Kconfig.debug linux-2.6.28/arch/x86/Kconfig.debug
8231 +--- linux-2.6.28/arch/x86/Kconfig.debug 2008-12-24 18:26:37.000000000 -0500
8232 ++++ linux-2.6.28/arch/x86/Kconfig.debug 2009-01-11 07:20:06.000000000 -0500
8233 +@@ -107,7 +107,7 @@ config X86_PTDUMP
8234 + config DEBUG_RODATA
8235 + bool "Write protect kernel read-only data structures"
8236 + default y
8237 +- depends on DEBUG_KERNEL
8238 ++ depends on DEBUG_KERNEL && BROKEN
8239 + help
8240 + Mark the kernel read-only data as write-protected in the pagetables,
8241 + in order to catch accidental (and incorrect) writes to such const
8242 +diff -urNp linux-2.6.28/arch/x86/kernel/acpi/boot.c linux-2.6.28/arch/x86/kernel/acpi/boot.c
8243 +--- linux-2.6.28/arch/x86/kernel/acpi/boot.c 2008-12-24 18:26:37.000000000 -0500
8244 ++++ linux-2.6.28/arch/x86/kernel/acpi/boot.c 2009-01-11 07:20:06.000000000 -0500
8245 +@@ -1645,7 +1645,7 @@ static struct dmi_system_id __initdata a
8246 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq 6715b"),
8247 + },
8248 + },
8249 +- {}
8250 ++ { NULL, NULL, {{0, {0}}}, NULL}
8251 + };
8252 +
8253 + /*
8254 +diff -urNp linux-2.6.28/arch/x86/kernel/acpi/realmode/wakeup.S linux-2.6.28/arch/x86/kernel/acpi/realmode/wakeup.S
8255 +--- linux-2.6.28/arch/x86/kernel/acpi/realmode/wakeup.S 2008-12-24 18:26:37.000000000 -0500
8256 ++++ linux-2.6.28/arch/x86/kernel/acpi/realmode/wakeup.S 2009-01-11 07:20:06.000000000 -0500
8257 +@@ -104,7 +104,7 @@ _start:
8258 + movl %eax, %ecx
8259 + orl %edx, %ecx
8260 + jz 1f
8261 +- movl $0xc0000080, %ecx
8262 ++ mov $MSR_EFER, %ecx
8263 + wrmsr
8264 + 1:
8265 +
8266 +diff -urNp linux-2.6.28/arch/x86/kernel/acpi/sleep.c linux-2.6.28/arch/x86/kernel/acpi/sleep.c
8267 +--- linux-2.6.28/arch/x86/kernel/acpi/sleep.c 2008-12-24 18:26:37.000000000 -0500
8268 ++++ linux-2.6.28/arch/x86/kernel/acpi/sleep.c 2009-01-11 07:20:06.000000000 -0500
8269 +@@ -37,6 +37,10 @@ int acpi_save_state_mem(void)
8270 + {
8271 + struct wakeup_header *header;
8272 +
8273 ++#if defined(CONFIG_64BIT) && defined(CONFIG_SMP) && defined(CONFIG_PAX_KERNEXEC)
8274 ++ unsigned long cr0;
8275 ++#endif
8276 ++
8277 + if (!acpi_realmode) {
8278 + printk(KERN_ERR "Could not allocate memory during boot, "
8279 + "S3 disabled\n");
8280 +@@ -99,8 +103,18 @@ int acpi_save_state_mem(void)
8281 + header->trampoline_segment = setup_trampoline() >> 4;
8282 + #ifdef CONFIG_SMP
8283 + stack_start.sp = temp_stack + sizeof(temp_stack);
8284 ++
8285 ++#ifdef CONFIG_PAX_KERNEXEC
8286 ++ pax_open_kernel(cr0);
8287 ++#endif
8288 ++
8289 + early_gdt_descr.address =
8290 + (unsigned long)get_cpu_gdt_table(smp_processor_id());
8291 ++
8292 ++#ifdef CONFIG_PAX_KERNEXEC
8293 ++ pax_close_kernel(cr0);
8294 ++#endif
8295 ++
8296 + #endif
8297 + initial_code = (unsigned long)wakeup_long64;
8298 + saved_magic = 0x123456789abcdef0;
8299 +diff -urNp linux-2.6.28/arch/x86/kernel/acpi/wakeup_32.S linux-2.6.28/arch/x86/kernel/acpi/wakeup_32.S
8300 +--- linux-2.6.28/arch/x86/kernel/acpi/wakeup_32.S 2008-12-24 18:26:37.000000000 -0500
8301 ++++ linux-2.6.28/arch/x86/kernel/acpi/wakeup_32.S 2009-01-11 07:20:06.000000000 -0500
8302 +@@ -30,13 +30,11 @@ wakeup_pmode_return:
8303 + # and restore the stack ... but you need gdt for this to work
8304 + movl saved_context_esp, %esp
8305 +
8306 +- movl %cs:saved_magic, %eax
8307 +- cmpl $0x12345678, %eax
8308 ++ cmpl $0x12345678, saved_magic
8309 + jne bogus_magic
8310 +
8311 + # jump to place where we left off
8312 +- movl saved_eip, %eax
8313 +- jmp *%eax
8314 ++ jmp *(saved_eip)
8315 +
8316 + bogus_magic:
8317 + jmp bogus_magic
8318 +diff -urNp linux-2.6.28/arch/x86/kernel/alternative.c linux-2.6.28/arch/x86/kernel/alternative.c
8319 +--- linux-2.6.28/arch/x86/kernel/alternative.c 2008-12-24 18:26:37.000000000 -0500
8320 ++++ linux-2.6.28/arch/x86/kernel/alternative.c 2009-01-11 07:20:06.000000000 -0500
8321 +@@ -393,7 +393,7 @@ void apply_paravirt(struct paravirt_patc
8322 +
8323 + BUG_ON(p->len > MAX_PATCH_LEN);
8324 + /* prep the buffer with the original instructions */
8325 +- memcpy(insnbuf, p->instr, p->len);
8326 ++ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
8327 + used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
8328 + (unsigned long)p->instr, p->len);
8329 +
8330 +@@ -473,11 +473,26 @@ void __init alternative_instructions(voi
8331 + * instructions. And on the local CPU you need to be protected again NMI or MCE
8332 + * handlers seeing an inconsistent instruction while you patch.
8333 + */
8334 +-void *text_poke_early(void *addr, const void *opcode, size_t len)
8335 ++void *__kprobes text_poke_early(void *addr, const void *opcode, size_t len)
8336 + {
8337 + unsigned long flags;
8338 ++
8339 ++#ifdef CONFIG_PAX_KERNEXEC
8340 ++ unsigned long cr0;
8341 ++#endif
8342 ++
8343 + local_irq_save(flags);
8344 +- memcpy(addr, opcode, len);
8345 ++
8346 ++#ifdef CONFIG_PAX_KERNEXEC
8347 ++ pax_open_kernel(cr0);
8348 ++#endif
8349 ++
8350 ++ memcpy(ktla_ktva(addr), opcode, len);
8351 ++
8352 ++#ifdef CONFIG_PAX_KERNEXEC
8353 ++ pax_close_kernel(cr0);
8354 ++#endif
8355 ++
8356 + local_irq_restore(flags);
8357 + sync_core();
8358 + /* Could also do a CLFLUSH here to speed up CPU recovery; but
8359 +@@ -498,33 +513,27 @@ void *text_poke_early(void *addr, const
8360 + */
8361 + void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
8362 + {
8363 +- unsigned long flags;
8364 +- char *vaddr;
8365 +- int nr_pages = 2;
8366 ++ unsigned char *vaddr = ktla_ktva(addr);
8367 + struct page *pages[2];
8368 +- int i;
8369 ++ size_t i;
8370 ++
8371 ++ if (!core_kernel_text((unsigned long)addr)
8372 +
8373 +- if (!core_kernel_text((unsigned long)addr)) {
8374 +- pages[0] = vmalloc_to_page(addr);
8375 +- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
8376 ++#if defined(CONFIG_X86_32) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
8377 ++ && (vaddr < MODULES_VADDR || MODULES_END < vaddr)
8378 ++#endif
8379 ++
8380 ++ ) {
8381 ++ pages[0] = vmalloc_to_page(vaddr);
8382 ++ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
8383 + } else {
8384 +- pages[0] = virt_to_page(addr);
8385 ++ pages[0] = virt_to_page(vaddr);
8386 + WARN_ON(!PageReserved(pages[0]));
8387 +- pages[1] = virt_to_page(addr + PAGE_SIZE);
8388 ++ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
8389 + }
8390 + BUG_ON(!pages[0]);
8391 +- if (!pages[1])
8392 +- nr_pages = 1;
8393 +- vaddr = vmap(pages, nr_pages, VM_MAP, PAGE_KERNEL);
8394 +- BUG_ON(!vaddr);
8395 +- local_irq_save(flags);
8396 +- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
8397 +- local_irq_restore(flags);
8398 +- vunmap(vaddr);
8399 +- sync_core();
8400 +- /* Could also do a CLFLUSH here to speed up CPU recovery; but
8401 +- that causes hangs on some VIA CPUs. */
8402 ++ text_poke_early(addr, opcode, len);
8403 + for (i = 0; i < len; i++)
8404 +- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
8405 ++ BUG_ON((vaddr)[i] != ((unsigned char *)opcode)[i]);
8406 + return addr;
8407 + }
8408 +diff -urNp linux-2.6.28/arch/x86/kernel/apm_32.c linux-2.6.28/arch/x86/kernel/apm_32.c
8409 +--- linux-2.6.28/arch/x86/kernel/apm_32.c 2008-12-24 18:26:37.000000000 -0500
8410 ++++ linux-2.6.28/arch/x86/kernel/apm_32.c 2009-01-11 07:20:06.000000000 -0500
8411 +@@ -407,7 +407,7 @@ static DECLARE_WAIT_QUEUE_HEAD(apm_waitq
8412 + static DECLARE_WAIT_QUEUE_HEAD(apm_suspend_waitqueue);
8413 + static struct apm_user *user_list;
8414 + static DEFINE_SPINLOCK(user_list_lock);
8415 +-static const struct desc_struct bad_bios_desc = { { { 0, 0x00409200 } } };
8416 ++static const struct desc_struct bad_bios_desc = { { { 0, 0x00409300 } } };
8417 +
8418 + static const char driver_version[] = "1.16ac"; /* no spaces */
8419 +
8420 +@@ -602,19 +602,42 @@ static u8 apm_bios_call(u32 func, u32 eb
8421 + struct desc_struct save_desc_40;
8422 + struct desc_struct *gdt;
8423 +
8424 ++#ifdef CONFIG_PAX_KERNEXEC
8425 ++ unsigned long cr0;
8426 ++#endif
8427 ++
8428 + cpus = apm_save_cpus();
8429 +
8430 + cpu = get_cpu();
8431 + gdt = get_cpu_gdt_table(cpu);
8432 + save_desc_40 = gdt[0x40 / 8];
8433 ++
8434 ++#ifdef CONFIG_PAX_KERNEXEC
8435 ++ pax_open_kernel(cr0);
8436 ++#endif
8437 ++
8438 + gdt[0x40 / 8] = bad_bios_desc;
8439 +
8440 ++#ifdef CONFIG_PAX_KERNEXEC
8441 ++ pax_close_kernel(cr0);
8442 ++#endif
8443 ++
8444 + apm_irq_save(flags);
8445 + APM_DO_SAVE_SEGS;
8446 + apm_bios_call_asm(func, ebx_in, ecx_in, eax, ebx, ecx, edx, esi);
8447 + APM_DO_RESTORE_SEGS;
8448 + apm_irq_restore(flags);
8449 ++
8450 ++#ifdef CONFIG_PAX_KERNEXEC
8451 ++ pax_open_kernel(cr0);
8452 ++#endif
8453 ++
8454 + gdt[0x40 / 8] = save_desc_40;
8455 ++
8456 ++#ifdef CONFIG_PAX_KERNEXEC
8457 ++ pax_close_kernel(cr0);
8458 ++#endif
8459 ++
8460 + put_cpu();
8461 + apm_restore_cpus(cpus);
8462 +
8463 +@@ -645,19 +668,42 @@ static u8 apm_bios_call_simple(u32 func,
8464 + struct desc_struct save_desc_40;
8465 + struct desc_struct *gdt;
8466 +
8467 ++#ifdef CONFIG_PAX_KERNEXEC
8468 ++ unsigned long cr0;
8469 ++#endif
8470 ++
8471 + cpus = apm_save_cpus();
8472 +
8473 + cpu = get_cpu();
8474 + gdt = get_cpu_gdt_table(cpu);
8475 + save_desc_40 = gdt[0x40 / 8];
8476 ++
8477 ++#ifdef CONFIG_PAX_KERNEXEC
8478 ++ pax_open_kernel(cr0);
8479 ++#endif
8480 ++
8481 + gdt[0x40 / 8] = bad_bios_desc;
8482 +
8483 ++#ifdef CONFIG_PAX_KERNEXEC
8484 ++ pax_close_kernel(cr0);
8485 ++#endif
8486 ++
8487 + apm_irq_save(flags);
8488 + APM_DO_SAVE_SEGS;
8489 + error = apm_bios_call_simple_asm(func, ebx_in, ecx_in, eax);
8490 + APM_DO_RESTORE_SEGS;
8491 + apm_irq_restore(flags);
8492 ++
8493 ++#ifdef CONFIG_PAX_KERNEXEC
8494 ++ pax_open_kernel(cr0);
8495 ++#endif
8496 ++
8497 + gdt[0x40 / 8] = save_desc_40;
8498 ++
8499 ++#ifdef CONFIG_PAX_KERNEXEC
8500 ++ pax_close_kernel(cr0);
8501 ++#endif
8502 ++
8503 + put_cpu();
8504 + apm_restore_cpus(cpus);
8505 + return error;
8506 +@@ -929,7 +975,7 @@ recalc:
8507 +
8508 + static void apm_power_off(void)
8509 + {
8510 +- unsigned char po_bios_call[] = {
8511 ++ const unsigned char po_bios_call[] = {
8512 + 0xb8, 0x00, 0x10, /* movw $0x1000,ax */
8513 + 0x8e, 0xd0, /* movw ax,ss */
8514 + 0xbc, 0x00, 0xf0, /* movw $0xf000,sp */
8515 +@@ -1876,7 +1922,10 @@ static const struct file_operations apm_
8516 + static struct miscdevice apm_device = {
8517 + APM_MINOR_DEV,
8518 + "apm_bios",
8519 +- &apm_bios_fops
8520 ++ &apm_bios_fops,
8521 ++ {NULL, NULL},
8522 ++ NULL,
8523 ++ NULL
8524 + };
8525 +
8526 +
8527 +@@ -2197,7 +2246,7 @@ static struct dmi_system_id __initdata a
8528 + { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
8529 + },
8530 +
8531 +- { }
8532 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
8533 + };
8534 +
8535 + /*
8536 +@@ -2215,6 +2264,10 @@ static int __init apm_init(void)
8537 + struct desc_struct *gdt;
8538 + int err;
8539 +
8540 ++#ifdef CONFIG_PAX_KERNEXEC
8541 ++ unsigned long cr0;
8542 ++#endif
8543 ++
8544 + dmi_check_system(apm_dmi_table);
8545 +
8546 + if (apm_info.bios.version == 0 || paravirt_enabled() || machine_is_olpc()) {
8547 +@@ -2288,9 +2341,18 @@ static int __init apm_init(void)
8548 + * This is for buggy BIOS's that refer to (real mode) segment 0x40
8549 + * even though they are called in protected mode.
8550 + */
8551 ++
8552 ++#ifdef CONFIG_PAX_KERNEXEC
8553 ++ pax_open_kernel(cr0);
8554 ++#endif
8555 ++
8556 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
8557 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
8558 +
8559 ++#ifdef CONFIG_PAX_KERNEXEC
8560 ++ pax_close_kernel(cr0);
8561 ++#endif
8562 ++
8563 + /*
8564 + * Set up the long jump entry point to the APM BIOS, which is called
8565 + * from inline assembly.
8566 +@@ -2309,6 +2371,11 @@ static int __init apm_init(void)
8567 + * code to that CPU.
8568 + */
8569 + gdt = get_cpu_gdt_table(0);
8570 ++
8571 ++#ifdef CONFIG_PAX_KERNEXEC
8572 ++ pax_open_kernel(cr0);
8573 ++#endif
8574 ++
8575 + set_base(gdt[APM_CS >> 3],
8576 + __va((unsigned long)apm_info.bios.cseg << 4));
8577 + set_base(gdt[APM_CS_16 >> 3],
8578 +@@ -2316,6 +2383,10 @@ static int __init apm_init(void)
8579 + set_base(gdt[APM_DS >> 3],
8580 + __va((unsigned long)apm_info.bios.dseg << 4));
8581 +
8582 ++#ifdef CONFIG_PAX_KERNEXEC
8583 ++ pax_close_kernel(cr0);
8584 ++#endif
8585 ++
8586 + proc_create("apm", 0, NULL, &apm_file_ops);
8587 +
8588 + kapmd_task = kthread_create(apm, NULL, "kapmd");
8589 +diff -urNp linux-2.6.28/arch/x86/kernel/asm-offsets_32.c linux-2.6.28/arch/x86/kernel/asm-offsets_32.c
8590 +--- linux-2.6.28/arch/x86/kernel/asm-offsets_32.c 2008-12-24 18:26:37.000000000 -0500
8591 ++++ linux-2.6.28/arch/x86/kernel/asm-offsets_32.c 2009-01-11 07:20:06.000000000 -0500
8592 +@@ -100,6 +100,7 @@ void foo(void)
8593 + DEFINE(PTRS_PER_PTE, PTRS_PER_PTE);
8594 + DEFINE(PTRS_PER_PMD, PTRS_PER_PMD);
8595 + DEFINE(PTRS_PER_PGD, PTRS_PER_PGD);
8596 ++ DEFINE(PERCPU_MODULE_RESERVE, PERCPU_MODULE_RESERVE);
8597 +
8598 + OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
8599 +
8600 +@@ -113,6 +114,7 @@ void foo(void)
8601 + OFFSET(PV_CPU_iret, pv_cpu_ops, iret);
8602 + OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
8603 + OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
8604 ++ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
8605 + #endif
8606 +
8607 + #ifdef CONFIG_XEN
8608 +diff -urNp linux-2.6.28/arch/x86/kernel/asm-offsets_64.c linux-2.6.28/arch/x86/kernel/asm-offsets_64.c
8609 +--- linux-2.6.28/arch/x86/kernel/asm-offsets_64.c 2008-12-24 18:26:37.000000000 -0500
8610 ++++ linux-2.6.28/arch/x86/kernel/asm-offsets_64.c 2009-01-11 07:20:06.000000000 -0500
8611 +@@ -122,6 +122,7 @@ int main(void)
8612 + ENTRY(cr8);
8613 + BLANK();
8614 + #undef ENTRY
8615 ++ DEFINE(TSS_size, sizeof(struct tss_struct));
8616 + DEFINE(TSS_ist, offsetof(struct tss_struct, x86_tss.ist));
8617 + BLANK();
8618 + DEFINE(crypto_tfm_ctx_offset, offsetof(struct crypto_tfm, __crt_ctx));
8619 +diff -urNp linux-2.6.28/arch/x86/kernel/cpu/common.c linux-2.6.28/arch/x86/kernel/cpu/common.c
8620 +--- linux-2.6.28/arch/x86/kernel/cpu/common.c 2008-12-24 18:26:37.000000000 -0500
8621 ++++ linux-2.6.28/arch/x86/kernel/cpu/common.c 2009-01-11 07:20:06.000000000 -0500
8622 +@@ -2,7 +2,6 @@
8623 + #include <linux/kernel.h>
8624 + #include <linux/sched.h>
8625 + #include <linux/string.h>
8626 +-#include <linux/bootmem.h>
8627 + #include <linux/bitops.h>
8628 + #include <linux/module.h>
8629 + #include <linux/kgdb.h>
8630 +@@ -41,59 +40,6 @@
8631 +
8632 + static struct cpu_dev *this_cpu __cpuinitdata;
8633 +
8634 +-#ifdef CONFIG_X86_64
8635 +-/* We need valid kernel segments for data and code in long mode too
8636 +- * IRET will check the segment types kkeil 2000/10/28
8637 +- * Also sysret mandates a special GDT layout
8638 +- */
8639 +-/* The TLS descriptors are currently at a different place compared to i386.
8640 +- Hopefully nobody expects them at a fixed place (Wine?) */
8641 +-DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = {
8642 +- [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
8643 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
8644 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
8645 +- [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
8646 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
8647 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
8648 +-} };
8649 +-#else
8650 +-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
8651 +- [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
8652 +- [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
8653 +- [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
8654 +- [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
8655 +- /*
8656 +- * Segments used for calling PnP BIOS have byte granularity.
8657 +- * They code segments and data segments have fixed 64k limits,
8658 +- * the transfer segment sizes are set at run time.
8659 +- */
8660 +- /* 32-bit code */
8661 +- [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
8662 +- /* 16-bit code */
8663 +- [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
8664 +- /* 16-bit data */
8665 +- [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
8666 +- /* 16-bit data */
8667 +- [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
8668 +- /* 16-bit data */
8669 +- [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
8670 +- /*
8671 +- * The APM segments have byte granularity and their bases
8672 +- * are set at run time. All have 64k limits.
8673 +- */
8674 +- /* 32-bit code */
8675 +- [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
8676 +- /* 16-bit code */
8677 +- [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
8678 +- /* data */
8679 +- [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
8680 +-
8681 +- [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
8682 +- [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
8683 +-} };
8684 +-#endif
8685 +-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
8686 +-
8687 + #ifdef CONFIG_X86_32
8688 + static int cachesize_override __cpuinitdata = -1;
8689 + static int disable_x86_serial_nr __cpuinitdata = 1;
8690 +@@ -227,7 +173,7 @@ void switch_to_new_gdt(void)
8691 + {
8692 + struct desc_ptr gdt_descr;
8693 +
8694 +- gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
8695 ++ gdt_descr.address = (unsigned long)get_cpu_gdt_table(smp_processor_id());
8696 + gdt_descr.size = GDT_SIZE - 1;
8697 + load_gdt(&gdt_descr);
8698 + #ifdef CONFIG_X86_32
8699 +@@ -687,6 +633,10 @@ static void __cpuinit identify_cpu(struc
8700 + * we do "generic changes."
8701 + */
8702 +
8703 ++#if defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
8704 ++ setup_clear_cpu_cap(X86_FEATURE_SEP);
8705 ++#endif
8706 ++
8707 + /* If the model name is still unset, do table lookup. */
8708 + if (!c->x86_model_id[0]) {
8709 + char *p;
8710 +@@ -854,13 +804,13 @@ static __init int setup_disablecpuid(cha
8711 + }
8712 + __setup("clearcpuid=", setup_disablecpuid);
8713 +
8714 +-cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
8715 ++cpumask_t cpu_initialized = CPU_MASK_NONE;
8716 +
8717 + #ifdef CONFIG_X86_64
8718 + struct x8664_pda **_cpu_pda __read_mostly;
8719 + EXPORT_SYMBOL(_cpu_pda);
8720 +
8721 +-struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
8722 ++struct desc_ptr idt_descr __read_only = { 256 * 16 - 1, (unsigned long) idt_table };
8723 +
8724 + char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss;
8725 +
8726 +@@ -959,7 +909,7 @@ struct pt_regs * __cpuinit idle_regs(str
8727 + void __cpuinit cpu_init(void)
8728 + {
8729 + int cpu = stack_smp_processor_id();
8730 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
8731 ++ struct tss_struct *t = init_tss + cpu;
8732 + struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu);
8733 + unsigned long v;
8734 + char *estacks = NULL;
8735 +@@ -1080,7 +1030,7 @@ void __cpuinit cpu_init(void)
8736 + {
8737 + int cpu = smp_processor_id();
8738 + struct task_struct *curr = current;
8739 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
8740 ++ struct tss_struct *t = init_tss + cpu;
8741 + struct thread_struct *thread = &curr->thread;
8742 +
8743 + if (cpu_test_and_set(cpu, cpu_initialized)) {
8744 +diff -urNp linux-2.6.28/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c linux-2.6.28/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c
8745 +--- linux-2.6.28/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2008-12-24 18:26:37.000000000 -0500
8746 ++++ linux-2.6.28/arch/x86/kernel/cpu/cpufreq/acpi-cpufreq.c 2009-01-11 07:20:06.000000000 -0500
8747 +@@ -561,7 +561,7 @@ static const struct dmi_system_id sw_any
8748 + DMI_MATCH(DMI_PRODUCT_NAME, "X6DLP"),
8749 + },
8750 + },
8751 +- { }
8752 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
8753 + };
8754 + #endif
8755 +
8756 +diff -urNp linux-2.6.28/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c linux-2.6.28/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c
8757 +--- linux-2.6.28/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2008-12-24 18:26:37.000000000 -0500
8758 ++++ linux-2.6.28/arch/x86/kernel/cpu/cpufreq/speedstep-centrino.c 2009-01-11 07:20:06.000000000 -0500
8759 +@@ -225,7 +225,7 @@ static struct cpu_model models[] =
8760 + { &cpu_ids[CPU_MP4HT_D0], NULL, 0, NULL },
8761 + { &cpu_ids[CPU_MP4HT_E0], NULL, 0, NULL },
8762 +
8763 +- { NULL, }
8764 ++ { NULL, NULL, 0, NULL}
8765 + };
8766 + #undef _BANIAS
8767 + #undef BANIAS
8768 +diff -urNp linux-2.6.28/arch/x86/kernel/cpu/intel.c linux-2.6.28/arch/x86/kernel/cpu/intel.c
8769 +--- linux-2.6.28/arch/x86/kernel/cpu/intel.c 2008-12-24 18:26:37.000000000 -0500
8770 ++++ linux-2.6.28/arch/x86/kernel/cpu/intel.c 2009-01-11 07:20:06.000000000 -0500
8771 +@@ -72,7 +72,7 @@ static void __cpuinit trap_init_f00f_bug
8772 + * Update the IDT descriptor and reload the IDT so that
8773 + * it uses the read-only mapped virtual address.
8774 + */
8775 +- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
8776 ++ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
8777 + load_idt(&idt_descr);
8778 + }
8779 + #endif
8780 +diff -urNp linux-2.6.28/arch/x86/kernel/cpu/mcheck/mce_64.c linux-2.6.28/arch/x86/kernel/cpu/mcheck/mce_64.c
8781 +--- linux-2.6.28/arch/x86/kernel/cpu/mcheck/mce_64.c 2008-12-24 18:26:37.000000000 -0500
8782 ++++ linux-2.6.28/arch/x86/kernel/cpu/mcheck/mce_64.c 2009-01-11 07:20:06.000000000 -0500
8783 +@@ -678,6 +678,7 @@ static struct miscdevice mce_log_device
8784 + MISC_MCELOG_MINOR,
8785 + "mcelog",
8786 + &mce_chrdev_ops,
8787 ++ {NULL, NULL}, NULL, NULL
8788 + };
8789 +
8790 + static unsigned long old_cr4 __initdata;
8791 +diff -urNp linux-2.6.28/arch/x86/kernel/cpu/mtrr/generic.c linux-2.6.28/arch/x86/kernel/cpu/mtrr/generic.c
8792 +--- linux-2.6.28/arch/x86/kernel/cpu/mtrr/generic.c 2008-12-24 18:26:37.000000000 -0500
8793 ++++ linux-2.6.28/arch/x86/kernel/cpu/mtrr/generic.c 2009-01-11 07:20:06.000000000 -0500
8794 +@@ -31,11 +31,11 @@ static struct fixed_range_block fixed_ra
8795 + { MTRRfix64K_00000_MSR, 1 }, /* one 64k MTRR */
8796 + { MTRRfix16K_80000_MSR, 2 }, /* two 16k MTRRs */
8797 + { MTRRfix4K_C0000_MSR, 8 }, /* eight 4k MTRRs */
8798 +- {}
8799 ++ { 0, 0 }
8800 + };
8801 +
8802 + static unsigned long smp_changes_mask;
8803 +-static struct mtrr_state mtrr_state = {};
8804 ++static struct mtrr_state mtrr_state;
8805 + static int mtrr_state_set;
8806 + u64 mtrr_tom2;
8807 +
8808 +diff -urNp linux-2.6.28/arch/x86/kernel/crash.c linux-2.6.28/arch/x86/kernel/crash.c
8809 +--- linux-2.6.28/arch/x86/kernel/crash.c 2008-12-24 18:26:37.000000000 -0500
8810 ++++ linux-2.6.28/arch/x86/kernel/crash.c 2009-01-11 07:20:06.000000000 -0500
8811 +@@ -59,7 +59,7 @@ static int crash_nmi_callback(struct not
8812 + local_irq_disable();
8813 +
8814 + #ifdef CONFIG_X86_32
8815 +- if (!user_mode_vm(regs)) {
8816 ++ if (!user_mode(regs)) {
8817 + crash_fixup_ss_esp(&fixed_regs, regs);
8818 + regs = &fixed_regs;
8819 + }
8820 +diff -urNp linux-2.6.28/arch/x86/kernel/doublefault_32.c linux-2.6.28/arch/x86/kernel/doublefault_32.c
8821 +--- linux-2.6.28/arch/x86/kernel/doublefault_32.c 2008-12-24 18:26:37.000000000 -0500
8822 ++++ linux-2.6.28/arch/x86/kernel/doublefault_32.c 2009-01-11 07:20:06.000000000 -0500
8823 +@@ -11,7 +11,7 @@
8824 +
8825 + #define DOUBLEFAULT_STACKSIZE (1024)
8826 + static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
8827 +-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
8828 ++#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
8829 +
8830 + #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
8831 +
8832 +@@ -21,7 +21,7 @@ static void doublefault_fn(void)
8833 + unsigned long gdt, tss;
8834 +
8835 + store_gdt(&gdt_desc);
8836 +- gdt = gdt_desc.address;
8837 ++ gdt = (unsigned long)gdt_desc.address;
8838 +
8839 + printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
8840 +
8841 +@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cach
8842 + /* 0x2 bit is always set */
8843 + .flags = X86_EFLAGS_SF | 0x2,
8844 + .sp = STACK_START,
8845 +- .es = __USER_DS,
8846 ++ .es = __KERNEL_DS,
8847 + .cs = __KERNEL_CS,
8848 + .ss = __KERNEL_DS,
8849 +- .ds = __USER_DS,
8850 ++ .ds = __KERNEL_DS,
8851 + .fs = __KERNEL_PERCPU,
8852 +
8853 + .__cr3 = __pa_nodebug(swapper_pg_dir),
8854 +diff -urNp linux-2.6.28/arch/x86/kernel/dumpstack_32.c linux-2.6.28/arch/x86/kernel/dumpstack_32.c
8855 +--- linux-2.6.28/arch/x86/kernel/dumpstack_32.c 2008-12-24 18:26:37.000000000 -0500
8856 ++++ linux-2.6.28/arch/x86/kernel/dumpstack_32.c 2009-01-11 07:20:06.000000000 -0500
8857 +@@ -238,11 +238,12 @@ void show_registers(struct pt_regs *regs
8858 + * When in-kernel, we also print out the stack and code at the
8859 + * time of the fault..
8860 + */
8861 +- if (!user_mode_vm(regs)) {
8862 ++ if (!user_mode(regs)) {
8863 + unsigned int code_prologue = code_bytes * 43 / 64;
8864 + unsigned int code_len = code_bytes;
8865 + unsigned char c;
8866 + u8 *ip;
8867 ++ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
8868 +
8869 + printk(KERN_EMERG "Stack:\n");
8870 + show_stack_log_lvl(NULL, regs, &regs->sp,
8871 +@@ -250,10 +251,10 @@ void show_registers(struct pt_regs *regs
8872 +
8873 + printk(KERN_EMERG "Code: ");
8874 +
8875 +- ip = (u8 *)regs->ip - code_prologue;
8876 ++ ip = (u8 *)regs->ip - code_prologue + cs_base;
8877 + if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
8878 + /* try starting at IP */
8879 +- ip = (u8 *)regs->ip;
8880 ++ ip = (u8 *)regs->ip + cs_base;
8881 + code_len = code_len - code_prologue + 1;
8882 + }
8883 + for (i = 0; i < code_len; i++, ip++) {
8884 +@@ -262,7 +263,7 @@ void show_registers(struct pt_regs *regs
8885 + printk(" Bad EIP value.");
8886 + break;
8887 + }
8888 +- if (ip == (u8 *)regs->ip)
8889 ++ if (ip == (u8 *)regs->ip + cs_base)
8890 + printk("<%02x> ", c);
8891 + else
8892 + printk("%02x ", c);
8893 +@@ -275,6 +276,7 @@ int is_valid_bugaddr(unsigned long ip)
8894 + {
8895 + unsigned short ud2;
8896 +
8897 ++ ip = ktla_ktva(ip);
8898 + if (ip < PAGE_OFFSET)
8899 + return 0;
8900 + if (probe_kernel_address((unsigned short *)ip, ud2))
8901 +@@ -410,7 +412,7 @@ die_nmi(char *str, struct pt_regs *regs,
8902 + * If we are in kernel we are probably nested up pretty bad
8903 + * and might aswell get out now while we still can:
8904 + */
8905 +- if (!user_mode_vm(regs)) {
8906 ++ if (!user_mode(regs)) {
8907 + current->thread.trap_no = 2;
8908 + crash_kexec(regs);
8909 + }
8910 +diff -urNp linux-2.6.28/arch/x86/kernel/efi_32.c linux-2.6.28/arch/x86/kernel/efi_32.c
8911 +--- linux-2.6.28/arch/x86/kernel/efi_32.c 2008-12-24 18:26:37.000000000 -0500
8912 ++++ linux-2.6.28/arch/x86/kernel/efi_32.c 2009-01-11 07:20:06.000000000 -0500
8913 +@@ -38,70 +38,38 @@
8914 + */
8915 +
8916 + static unsigned long efi_rt_eflags;
8917 +-static pgd_t efi_bak_pg_dir_pointer[2];
8918 ++static pgd_t __initdata efi_bak_pg_dir_pointer[KERNEL_PGD_PTRS];
8919 +
8920 +-void efi_call_phys_prelog(void)
8921 ++void __init efi_call_phys_prelog(void)
8922 + {
8923 +- unsigned long cr4;
8924 +- unsigned long temp;
8925 + struct desc_ptr gdt_descr;
8926 +
8927 + local_irq_save(efi_rt_eflags);
8928 +
8929 +- /*
8930 +- * If I don't have PAE, I should just duplicate two entries in page
8931 +- * directory. If I have PAE, I just need to duplicate one entry in
8932 +- * page directory.
8933 +- */
8934 +- cr4 = read_cr4_safe();
8935 +
8936 +- if (cr4 & X86_CR4_PAE) {
8937 +- efi_bak_pg_dir_pointer[0].pgd =
8938 +- swapper_pg_dir[pgd_index(0)].pgd;
8939 +- swapper_pg_dir[0].pgd =
8940 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
8941 +- } else {
8942 +- efi_bak_pg_dir_pointer[0].pgd =
8943 +- swapper_pg_dir[pgd_index(0)].pgd;
8944 +- efi_bak_pg_dir_pointer[1].pgd =
8945 +- swapper_pg_dir[pgd_index(0x400000)].pgd;
8946 +- swapper_pg_dir[pgd_index(0)].pgd =
8947 +- swapper_pg_dir[pgd_index(PAGE_OFFSET)].pgd;
8948 +- temp = PAGE_OFFSET + 0x400000;
8949 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
8950 +- swapper_pg_dir[pgd_index(temp)].pgd;
8951 +- }
8952 ++ clone_pgd_range(efi_bak_pg_dir_pointer, swapper_pg_dir, KERNEL_PGD_PTRS);
8953 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
8954 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
8955 +
8956 + /*
8957 + * After the lock is released, the original page table is restored.
8958 + */
8959 + __flush_tlb_all();
8960 +
8961 +- gdt_descr.address = __pa(get_cpu_gdt_table(0));
8962 ++ gdt_descr.address = (struct desc_struct *)__pa(get_cpu_gdt_table(0));
8963 + gdt_descr.size = GDT_SIZE - 1;
8964 + load_gdt(&gdt_descr);
8965 + }
8966 +
8967 +-void efi_call_phys_epilog(void)
8968 ++void __init efi_call_phys_epilog(void)
8969 + {
8970 +- unsigned long cr4;
8971 + struct desc_ptr gdt_descr;
8972 +
8973 +- gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
8974 ++ gdt_descr.address = get_cpu_gdt_table(0);
8975 + gdt_descr.size = GDT_SIZE - 1;
8976 + load_gdt(&gdt_descr);
8977 +
8978 +- cr4 = read_cr4_safe();
8979 +-
8980 +- if (cr4 & X86_CR4_PAE) {
8981 +- swapper_pg_dir[pgd_index(0)].pgd =
8982 +- efi_bak_pg_dir_pointer[0].pgd;
8983 +- } else {
8984 +- swapper_pg_dir[pgd_index(0)].pgd =
8985 +- efi_bak_pg_dir_pointer[0].pgd;
8986 +- swapper_pg_dir[pgd_index(0x400000)].pgd =
8987 +- efi_bak_pg_dir_pointer[1].pgd;
8988 +- }
8989 ++ clone_pgd_range(swapper_pg_dir, efi_bak_pg_dir_pointer, KERNEL_PGD_PTRS);
8990 +
8991 + /*
8992 + * After the lock is released, the original page table is restored.
8993 +diff -urNp linux-2.6.28/arch/x86/kernel/efi_stub_32.S linux-2.6.28/arch/x86/kernel/efi_stub_32.S
8994 +--- linux-2.6.28/arch/x86/kernel/efi_stub_32.S 2008-12-24 18:26:37.000000000 -0500
8995 ++++ linux-2.6.28/arch/x86/kernel/efi_stub_32.S 2009-01-11 07:20:06.000000000 -0500
8996 +@@ -6,6 +6,7 @@
8997 + */
8998 +
8999 + #include <linux/linkage.h>
9000 ++#include <linux/init.h>
9001 + #include <asm/page.h>
9002 +
9003 + /*
9004 +@@ -20,7 +21,7 @@
9005 + * service functions will comply with gcc calling convention, too.
9006 + */
9007 +
9008 +-.text
9009 ++__INIT
9010 + ENTRY(efi_call_phys)
9011 + /*
9012 + * 0. The function can only be called in Linux kernel. So CS has been
9013 +@@ -36,9 +37,7 @@ ENTRY(efi_call_phys)
9014 + * The mapping of lower virtual memory has been created in prelog and
9015 + * epilog.
9016 + */
9017 +- movl $1f, %edx
9018 +- subl $__PAGE_OFFSET, %edx
9019 +- jmp *%edx
9020 ++ jmp 1f-__PAGE_OFFSET
9021 + 1:
9022 +
9023 + /*
9024 +@@ -47,14 +46,8 @@ ENTRY(efi_call_phys)
9025 + * parameter 2, ..., param n. To make things easy, we save the return
9026 + * address of efi_call_phys in a global variable.
9027 + */
9028 +- popl %edx
9029 +- movl %edx, saved_return_addr
9030 +- /* get the function pointer into ECX*/
9031 +- popl %ecx
9032 +- movl %ecx, efi_rt_function_ptr
9033 +- movl $2f, %edx
9034 +- subl $__PAGE_OFFSET, %edx
9035 +- pushl %edx
9036 ++ popl (saved_return_addr)
9037 ++ popl (efi_rt_function_ptr)
9038 +
9039 + /*
9040 + * 3. Clear PG bit in %CR0.
9041 +@@ -73,9 +66,8 @@ ENTRY(efi_call_phys)
9042 + /*
9043 + * 5. Call the physical function.
9044 + */
9045 +- jmp *%ecx
9046 ++ call *(efi_rt_function_ptr-__PAGE_OFFSET)
9047 +
9048 +-2:
9049 + /*
9050 + * 6. After EFI runtime service returns, control will return to
9051 + * following instruction. We'd better readjust stack pointer first.
9052 +@@ -88,34 +80,27 @@ ENTRY(efi_call_phys)
9053 + movl %cr0, %edx
9054 + orl $0x80000000, %edx
9055 + movl %edx, %cr0
9056 +- jmp 1f
9057 +-1:
9058 ++
9059 + /*
9060 + * 8. Now restore the virtual mode from flat mode by
9061 + * adding EIP with PAGE_OFFSET.
9062 + */
9063 +- movl $1f, %edx
9064 +- jmp *%edx
9065 ++ jmp 1f+__PAGE_OFFSET
9066 + 1:
9067 +
9068 + /*
9069 + * 9. Balance the stack. And because EAX contain the return value,
9070 + * we'd better not clobber it.
9071 + */
9072 +- leal efi_rt_function_ptr, %edx
9073 +- movl (%edx), %ecx
9074 +- pushl %ecx
9075 ++ pushl (efi_rt_function_ptr)
9076 +
9077 + /*
9078 +- * 10. Push the saved return address onto the stack and return.
9079 ++ * 10. Return to the saved return address.
9080 + */
9081 +- leal saved_return_addr, %edx
9082 +- movl (%edx), %ecx
9083 +- pushl %ecx
9084 +- ret
9085 ++ jmpl *(saved_return_addr)
9086 + .previous
9087 +
9088 +-.data
9089 ++__INITDATA
9090 + saved_return_addr:
9091 + .long 0
9092 + efi_rt_function_ptr:
9093 +diff -urNp linux-2.6.28/arch/x86/kernel/entry_32.S linux-2.6.28/arch/x86/kernel/entry_32.S
9094 +--- linux-2.6.28/arch/x86/kernel/entry_32.S 2008-12-24 18:26:37.000000000 -0500
9095 ++++ linux-2.6.28/arch/x86/kernel/entry_32.S 2009-01-11 07:20:06.000000000 -0500
9096 +@@ -101,7 +101,7 @@
9097 + #define resume_userspace_sig resume_userspace
9098 + #endif
9099 +
9100 +-#define SAVE_ALL \
9101 ++#define __SAVE_ALL(_DS) \
9102 + cld; \
9103 + pushl %fs; \
9104 + CFI_ADJUST_CFA_OFFSET 4;\
9105 +@@ -133,12 +133,26 @@
9106 + pushl %ebx; \
9107 + CFI_ADJUST_CFA_OFFSET 4;\
9108 + CFI_REL_OFFSET ebx, 0;\
9109 +- movl $(__USER_DS), %edx; \
9110 ++ movl $(_DS), %edx; \
9111 + movl %edx, %ds; \
9112 + movl %edx, %es; \
9113 + movl $(__KERNEL_PERCPU), %edx; \
9114 + movl %edx, %fs
9115 +
9116 ++#ifdef CONFIG_PAX_KERNEXEC
9117 ++#define SAVE_ALL \
9118 ++ __SAVE_ALL(__KERNEL_DS); \
9119 ++ GET_CR0_INTO_EDX; \
9120 ++ movl %edx, %esi; \
9121 ++ orl $X86_CR0_WP, %edx; \
9122 ++ xorl %edx, %esi; \
9123 ++ SET_CR0_FROM_EDX
9124 ++#elif defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
9125 ++#define SAVE_ALL __SAVE_ALL(__KERNEL_DS)
9126 ++#else
9127 ++#define SAVE_ALL __SAVE_ALL(__USER_DS)
9128 ++#endif
9129 ++
9130 + #define RESTORE_INT_REGS \
9131 + popl %ebx; \
9132 + CFI_ADJUST_CFA_OFFSET -4;\
9133 +@@ -229,6 +243,11 @@ ENTRY(ret_from_fork)
9134 + CFI_ADJUST_CFA_OFFSET 4
9135 + popfl
9136 + CFI_ADJUST_CFA_OFFSET -4
9137 ++
9138 ++#ifdef CONFIG_PAX_KERNEXEC
9139 ++ xorl %esi, %esi
9140 ++#endif
9141 ++
9142 + jmp syscall_exit
9143 + CFI_ENDPROC
9144 + END(ret_from_fork)
9145 +@@ -252,7 +271,17 @@ check_userspace:
9146 + movb PT_CS(%esp), %al
9147 + andl $(X86_EFLAGS_VM | SEGMENT_RPL_MASK), %eax
9148 + cmpl $USER_RPL, %eax
9149 ++
9150 ++#ifdef CONFIG_PAX_KERNEXEC
9151 ++ jae resume_userspace
9152 ++
9153 ++ GET_CR0_INTO_EDX
9154 ++ xorl %esi, %edx
9155 ++ SET_CR0_FROM_EDX
9156 ++ jmp resume_kernel
9157 ++#else
9158 + jb resume_kernel # not returning to v8086 or userspace
9159 ++#endif
9160 +
9161 + ENTRY(resume_userspace)
9162 + LOCKDEP_SYS_EXIT
9163 +@@ -314,10 +343,9 @@ sysenter_past_esp:
9164 + /*CFI_REL_OFFSET cs, 0*/
9165 + /*
9166 + * Push current_thread_info()->sysenter_return to the stack.
9167 +- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
9168 +- * pushed above; +8 corresponds to copy_thread's esp0 setting.
9169 + */
9170 +- pushl (TI_sysenter_return-THREAD_SIZE+8+4*4)(%esp)
9171 ++ GET_THREAD_INFO(%ebp)
9172 ++ pushl TI_sysenter_return(%ebp)
9173 + CFI_ADJUST_CFA_OFFSET 4
9174 + CFI_REL_OFFSET eip, 0
9175 +
9176 +@@ -330,9 +358,17 @@ sysenter_past_esp:
9177 + * Load the potential sixth argument from user stack.
9178 + * Careful about security.
9179 + */
9180 ++ movl PT_OLDESP(%esp),%ebp
9181 ++
9182 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
9183 ++ mov PT_OLDSS(%esp),%ds
9184 ++1: movl %ds:(%ebp),%ebp
9185 ++#else
9186 + cmpl $__PAGE_OFFSET-3,%ebp
9187 + jae syscall_fault
9188 + 1: movl (%ebp),%ebp
9189 ++#endif
9190 ++
9191 + movl %ebp,PT_EBP(%esp)
9192 + .section __ex_table,"a"
9193 + .align 4
9194 +@@ -356,12 +392,23 @@ sysenter_do_call:
9195 + testw $_TIF_ALLWORK_MASK, %cx
9196 + jne sysexit_audit
9197 + sysenter_exit:
9198 ++
9199 ++#ifdef CONFIG_PAX_RANDKSTACK
9200 ++ pushl %eax
9201 ++ CFI_ADJUST_CFA_OFFSET 4
9202 ++ call pax_randomize_kstack
9203 ++ popl %eax
9204 ++ CFI_ADJUST_CFA_OFFSET -4
9205 ++#endif
9206 ++
9207 + /* if something modifies registers it must also disable sysexit */
9208 + movl PT_EIP(%esp), %edx
9209 + movl PT_OLDESP(%esp), %ecx
9210 + xorl %ebp,%ebp
9211 + TRACE_IRQS_ON
9212 + 1: mov PT_FS(%esp), %fs
9213 ++2: mov PT_DS(%esp), %ds
9214 ++3: mov PT_ES(%esp), %es
9215 + ENABLE_INTERRUPTS_SYSEXIT
9216 +
9217 + #ifdef CONFIG_AUDITSYSCALL
9218 +@@ -404,11 +451,17 @@ sysexit_audit:
9219 +
9220 + CFI_ENDPROC
9221 + .pushsection .fixup,"ax"
9222 +-2: movl $0,PT_FS(%esp)
9223 ++4: movl $0,PT_FS(%esp)
9224 ++ jmp 1b
9225 ++5: movl $0,PT_DS(%esp)
9226 ++ jmp 1b
9227 ++6: movl $0,PT_ES(%esp)
9228 + jmp 1b
9229 + .section __ex_table,"a"
9230 + .align 4
9231 +- .long 1b,2b
9232 ++ .long 1b,4b
9233 ++ .long 2b,5b
9234 ++ .long 3b,6b
9235 + .popsection
9236 + ENDPROC(ia32_sysenter_target)
9237 +
9238 +@@ -438,6 +491,10 @@ syscall_exit:
9239 + testw $_TIF_ALLWORK_MASK, %cx # current->work
9240 + jne syscall_exit_work
9241 +
9242 ++#ifdef CONFIG_PAX_RANDKSTACK
9243 ++ call pax_randomize_kstack
9244 ++#endif
9245 ++
9246 + restore_all:
9247 + movl PT_EFLAGS(%esp), %eax # mix EFLAGS, SS and CS
9248 + # Warning: PT_OLDSS(%esp) contains the wrong/random values if we
9249 +@@ -531,25 +588,19 @@ work_resched:
9250 +
9251 + work_notifysig: # deal with pending signals and
9252 + # notify-resume requests
9253 ++ movl %esp, %eax
9254 + #ifdef CONFIG_VM86
9255 + testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
9256 +- movl %esp, %eax
9257 +- jne work_notifysig_v86 # returning to kernel-space or
9258 ++ jz 1f # returning to kernel-space or
9259 + # vm86-space
9260 +- xorl %edx, %edx
9261 +- call do_notify_resume
9262 +- jmp resume_userspace_sig
9263 +
9264 +- ALIGN
9265 +-work_notifysig_v86:
9266 + pushl %ecx # save ti_flags for do_notify_resume
9267 + CFI_ADJUST_CFA_OFFSET 4
9268 + call save_v86_state # %eax contains pt_regs pointer
9269 + popl %ecx
9270 + CFI_ADJUST_CFA_OFFSET -4
9271 + movl %eax, %esp
9272 +-#else
9273 +- movl %esp, %eax
9274 ++1:
9275 + #endif
9276 + xorl %edx, %edx
9277 + call do_notify_resume
9278 +@@ -595,17 +646,24 @@ syscall_badsys:
9279 + END(syscall_badsys)
9280 + CFI_ENDPROC
9281 +
9282 +-#define FIXUP_ESPFIX_STACK \
9283 +- /* since we are on a wrong stack, we cant make it a C code :( */ \
9284 +- PER_CPU(gdt_page, %ebx); \
9285 +- GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah); \
9286 +- addl %esp, %eax; \
9287 +- pushl $__KERNEL_DS; \
9288 +- CFI_ADJUST_CFA_OFFSET 4; \
9289 +- pushl %eax; \
9290 +- CFI_ADJUST_CFA_OFFSET 4; \
9291 +- lss (%esp), %esp; \
9292 ++.macro FIXUP_ESPFIX_STACK
9293 ++ /* since we are on a wrong stack, we cant make it a C code :( */
9294 ++#ifdef CONFIG_SMP
9295 ++ movl PER_CPU_VAR(cpu_number), %ebx;
9296 ++ shll $PAGE_SHIFT_asm, %ebx;
9297 ++ addl $cpu_gdt_table, %ebx;
9298 ++#else
9299 ++ movl $cpu_gdt_table, %ebx;
9300 ++#endif
9301 ++ GET_DESC_BASE(GDT_ENTRY_ESPFIX_SS, %ebx, %eax, %ax, %al, %ah);
9302 ++ addl %esp, %eax;
9303 ++ pushl $__KERNEL_DS;
9304 ++ CFI_ADJUST_CFA_OFFSET 4;
9305 ++ pushl %eax;
9306 ++ CFI_ADJUST_CFA_OFFSET 4;
9307 ++ lss (%esp), %esp;
9308 + CFI_ADJUST_CFA_OFFSET -8;
9309 ++.endm
9310 + #define UNWIND_ESPFIX_STACK \
9311 + movl %ss, %eax; \
9312 + /* see if on espfix stack */ \
9313 +@@ -622,7 +680,7 @@ END(syscall_badsys)
9314 + * Build the entry stubs and pointer table with
9315 + * some assembler magic.
9316 + */
9317 +-.section .rodata,"a"
9318 ++.section .rodata,"a",@progbits
9319 + ENTRY(interrupt)
9320 + .text
9321 +
9322 +@@ -722,12 +780,21 @@ error_code:
9323 + popl %ecx
9324 + CFI_ADJUST_CFA_OFFSET -4
9325 + /*CFI_REGISTER es, ecx*/
9326 ++
9327 ++#ifdef CONFIG_PAX_KERNEXEC
9328 ++ GET_CR0_INTO_EDX
9329 ++ movl %edx, %esi
9330 ++ orl $X86_CR0_WP, %edx
9331 ++ xorl %edx, %esi
9332 ++ SET_CR0_FROM_EDX
9333 ++#endif
9334 ++
9335 + movl PT_FS(%esp), %edi # get the function address
9336 + movl PT_ORIG_EAX(%esp), %edx # get the error code
9337 + movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
9338 + mov %ecx, PT_FS(%esp)
9339 + /*CFI_REL_OFFSET fs, ES*/
9340 +- movl $(__USER_DS), %ecx
9341 ++ movl $(__KERNEL_DS), %ecx
9342 + movl %ecx, %ds
9343 + movl %ecx, %es
9344 + TRACE_IRQS_OFF
9345 +@@ -853,6 +920,13 @@ nmi_stack_correct:
9346 + xorl %edx,%edx # zero error code
9347 + movl %esp,%eax # pt_regs pointer
9348 + call do_nmi
9349 ++
9350 ++#ifdef CONFIG_PAX_KERNEXEC
9351 ++ GET_CR0_INTO_EDX
9352 ++ xorl %esi, %edx
9353 ++ SET_CR0_FROM_EDX
9354 ++#endif
9355 ++
9356 + jmp restore_nocheck_notrace
9357 + CFI_ENDPROC
9358 +
9359 +@@ -894,6 +968,13 @@ nmi_espfix_stack:
9360 + FIXUP_ESPFIX_STACK # %eax == %esp
9361 + xorl %edx,%edx # zero error code
9362 + call do_nmi
9363 ++
9364 ++#ifdef CONFIG_PAX_KERNEXEC
9365 ++ GET_CR0_INTO_EDX
9366 ++ xorl %esi, %edx
9367 ++ SET_CR0_FROM_EDX
9368 ++#endif
9369 ++
9370 + RESTORE_REGS
9371 + lss 12+4(%esp), %esp # back to espfix stack
9372 + CFI_ADJUST_CFA_OFFSET -24
9373 +@@ -1206,7 +1287,6 @@ END(mcount)
9374 + #endif /* CONFIG_DYNAMIC_FTRACE */
9375 + #endif /* CONFIG_FUNCTION_TRACER */
9376 +
9377 +-.section .rodata,"a"
9378 + #include "syscall_table_32.S"
9379 +
9380 + syscall_table_size=(.-sys_call_table)
9381 +diff -urNp linux-2.6.28/arch/x86/kernel/entry_64.S linux-2.6.28/arch/x86/kernel/entry_64.S
9382 +--- linux-2.6.28/arch/x86/kernel/entry_64.S 2008-12-24 18:26:37.000000000 -0500
9383 ++++ linux-2.6.28/arch/x86/kernel/entry_64.S 2009-01-11 07:20:06.000000000 -0500
9384 +@@ -911,7 +911,8 @@ END(spurious_interrupt)
9385 + xorl %ebx,%ebx
9386 + 1:
9387 + .if \ist
9388 +- movq %gs:pda_data_offset, %rbp
9389 ++ imul $TSS_size, %gs:pda_cpunumber, %ebp
9390 ++ lea init_tss(%rbp), %rbp
9391 + .endif
9392 + .if \irqtrace
9393 + TRACE_IRQS_OFF
9394 +@@ -920,11 +921,11 @@ END(spurious_interrupt)
9395 + movq ORIG_RAX(%rsp),%rsi
9396 + movq $-1,ORIG_RAX(%rsp)
9397 + .if \ist
9398 +- subq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
9399 ++ subq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
9400 + .endif
9401 + call \sym
9402 + .if \ist
9403 +- addq $EXCEPTION_STKSZ, per_cpu__init_tss + TSS_ist + (\ist - 1) * 8(%rbp)
9404 ++ addq $EXCEPTION_STKSZ, TSS_ist + (\ist - 1) * 8(%rbp)
9405 + .endif
9406 + DISABLE_INTERRUPTS(CLBR_NONE)
9407 + .if \irqtrace
9408 +diff -urNp linux-2.6.28/arch/x86/kernel/ftrace.c linux-2.6.28/arch/x86/kernel/ftrace.c
9409 +--- linux-2.6.28/arch/x86/kernel/ftrace.c 2008-12-24 18:26:37.000000000 -0500
9410 ++++ linux-2.6.28/arch/x86/kernel/ftrace.c 2009-01-11 07:20:06.000000000 -0500
9411 +@@ -95,9 +95,9 @@ int ftrace_update_ftrace_func(ftrace_fun
9412 + unsigned char old[MCOUNT_INSN_SIZE], *new;
9413 + int ret;
9414 +
9415 +- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
9416 ++ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
9417 + new = ftrace_call_replace(ip, (unsigned long)func);
9418 +- ret = ftrace_modify_code(ip, old, new);
9419 ++ ret = ftrace_modify_code(ktla_ktva(ip), old, new);
9420 +
9421 + return ret;
9422 + }
9423 +diff -urNp linux-2.6.28/arch/x86/kernel/head32.c linux-2.6.28/arch/x86/kernel/head32.c
9424 +--- linux-2.6.28/arch/x86/kernel/head32.c 2008-12-24 18:26:37.000000000 -0500
9425 ++++ linux-2.6.28/arch/x86/kernel/head32.c 2009-01-11 07:20:06.000000000 -0500
9426 +@@ -12,10 +12,11 @@
9427 + #include <asm/sections.h>
9428 + #include <asm/e820.h>
9429 + #include <asm/bios_ebda.h>
9430 ++#include <asm/boot.h>
9431 +
9432 + void __init i386_start_kernel(void)
9433 + {
9434 +- reserve_early(__pa_symbol(&_text), __pa_symbol(&_end), "TEXT DATA BSS");
9435 ++ reserve_early(LOAD_PHYSICAL_ADDR, __pa_symbol(&_end), "TEXT DATA BSS");
9436 +
9437 + #ifdef CONFIG_BLK_DEV_INITRD
9438 + /* Reserve INITRD */
9439 +diff -urNp linux-2.6.28/arch/x86/kernel/head_32.S linux-2.6.28/arch/x86/kernel/head_32.S
9440 +--- linux-2.6.28/arch/x86/kernel/head_32.S 2008-12-24 18:26:37.000000000 -0500
9441 ++++ linux-2.6.28/arch/x86/kernel/head_32.S 2009-01-11 07:20:06.000000000 -0500
9442 +@@ -19,6 +19,7 @@
9443 + #include <asm/asm-offsets.h>
9444 + #include <asm/setup.h>
9445 + #include <asm/processor-flags.h>
9446 ++#include <asm/msr-index.h>
9447 +
9448 + /* Physical address */
9449 + #define pa(X) ((X) - __PAGE_OFFSET)
9450 +@@ -64,17 +65,22 @@ LOW_PAGES = 1<<(32-PAGE_SHIFT_asm)
9451 + LOW_PAGES = LOW_PAGES + 0x1000000
9452 + #endif
9453 +
9454 +-#if PTRS_PER_PMD > 1
9455 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PMD) + PTRS_PER_PGD
9456 +-#else
9457 +-PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PGD)
9458 +-#endif
9459 ++PAGE_TABLE_SIZE = (LOW_PAGES / PTRS_PER_PTE)
9460 + BOOTBITMAP_SIZE = LOW_PAGES / 8
9461 + ALLOCATOR_SLOP = 4
9462 +
9463 + INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE + (PAGE_TABLE_SIZE + ALLOCATOR_SLOP)*PAGE_SIZE_asm
9464 +
9465 + /*
9466 ++ * Real beginning of normal "text" segment
9467 ++ */
9468 ++ENTRY(stext)
9469 ++ENTRY(_stext)
9470 ++
9471 ++.section .text.startup,"ax",@progbits
9472 ++ ljmp $(__BOOT_CS),$phys_startup_32
9473 ++
9474 ++/*
9475 + * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
9476 + * %esi points to the real-mode code as a 32-bit pointer.
9477 + * CS and DS must be 4 GB flat segments, but we don't depend on
9478 +@@ -82,6 +88,12 @@ INIT_MAP_BEYOND_END = BOOTBITMAP_SIZE +
9479 + * can.
9480 + */
9481 + .section .text.head,"ax",@progbits
9482 ++
9483 ++#ifdef CONFIG_PAX_KERNEXEC
9484 ++/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
9485 ++.fill 4096,1,0xcc
9486 ++#endif
9487 ++
9488 + ENTRY(startup_32)
9489 + /* test KEEP_SEGMENTS flag to see if the bootloader is asking
9490 + us to not reload segments */
9491 +@@ -99,6 +111,56 @@ ENTRY(startup_32)
9492 + movl %eax,%gs
9493 + 2:
9494 +
9495 ++ movl $pa(cpu_gdt_table),%edi
9496 ++ movl $__per_cpu_start,%eax
9497 ++ movw %ax,__KERNEL_PERCPU + 2(%edi)
9498 ++ rorl $16,%eax
9499 ++ movb %al,__KERNEL_PERCPU + 4(%edi)
9500 ++ movb %ah,__KERNEL_PERCPU + 7(%edi)
9501 ++ movl $__per_cpu_end + PERCPU_MODULE_RESERVE - 1,%eax
9502 ++ subl $__per_cpu_start,%eax
9503 ++ movw %ax,__KERNEL_PERCPU + 0(%edi)
9504 ++
9505 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
9506 ++ /* check for VMware */
9507 ++ movl $0x564d5868,%eax
9508 ++ xorl %ebx,%ebx
9509 ++ movl $0xa,%ecx
9510 ++ movl $0x5658,%edx
9511 ++ in (%dx),%eax
9512 ++ cmpl $0x564d5868,%ebx
9513 ++ jz 2f
9514 ++
9515 ++ movl $NR_CPUS,%ecx
9516 ++ movl $pa(cpu_gdt_table),%edi
9517 ++1:
9518 ++ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
9519 ++ addl $PAGE_SIZE_asm,%edi
9520 ++ loop 1b
9521 ++2:
9522 ++#endif
9523 ++
9524 ++#ifdef CONFIG_PAX_KERNEXEC
9525 ++ movl $pa(boot_gdt),%edi
9526 ++ movl $KERNEL_TEXT_OFFSET,%eax
9527 ++ movw %ax,__BOOT_CS + 2(%edi)
9528 ++ rorl $16,%eax
9529 ++ movb %al,__BOOT_CS + 4(%edi)
9530 ++ movb %ah,__BOOT_CS + 7(%edi)
9531 ++ rorl $16,%eax
9532 ++
9533 ++ movl $NR_CPUS,%ecx
9534 ++ movl $pa(cpu_gdt_table),%edi
9535 ++1:
9536 ++ movw %ax,__KERNEL_CS + 2(%edi)
9537 ++ rorl $16,%eax
9538 ++ movb %al,__KERNEL_CS + 4(%edi)
9539 ++ movb %ah,__KERNEL_CS + 7(%edi)
9540 ++ rorl $16,%eax
9541 ++ addl $PAGE_SIZE_asm,%edi
9542 ++ loop 1b
9543 ++#endif
9544 ++
9545 + /*
9546 + * Clear BSS first so that there are no surprises...
9547 + */
9548 +@@ -142,9 +204,7 @@ ENTRY(startup_32)
9549 + cmpl $num_subarch_entries, %eax
9550 + jae bad_subarch
9551 +
9552 +- movl pa(subarch_entries)(,%eax,4), %eax
9553 +- subl $__PAGE_OFFSET, %eax
9554 +- jmp *%eax
9555 ++ jmp *pa(subarch_entries)(,%eax,4)
9556 +
9557 + bad_subarch:
9558 + WEAK(lguest_entry)
9559 +@@ -156,9 +216,9 @@ WEAK(xen_entry)
9560 + __INITDATA
9561 +
9562 + subarch_entries:
9563 +- .long default_entry /* normal x86/PC */
9564 +- .long lguest_entry /* lguest hypervisor */
9565 +- .long xen_entry /* Xen hypervisor */
9566 ++ .long pa(default_entry) /* normal x86/PC */
9567 ++ .long pa(lguest_entry) /* lguest hypervisor */
9568 ++ .long pa(xen_entry) /* Xen hypervisor */
9569 + num_subarch_entries = (. - subarch_entries) / 4
9570 + .previous
9571 + #endif /* CONFIG_PARAVIRT */
9572 +@@ -220,8 +280,7 @@ default_entry:
9573 + movl %eax, pa(max_pfn_mapped)
9574 +
9575 + /* Do early initialization of the fixmap area */
9576 +- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
9577 +- movl %eax,pa(swapper_pg_pmd+0x1000*KPMDS-8)
9578 ++ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_pmd+0x1000*KPMDS-8)
9579 + #else /* Not PAE */
9580 +
9581 + page_pde_offset = (__PAGE_OFFSET >> 20);
9582 +@@ -253,8 +312,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
9583 + movl %eax, pa(max_pfn_mapped)
9584 +
9585 + /* Do early initialization of the fixmap area */
9586 +- movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,%eax
9587 +- movl %eax,pa(swapper_pg_dir+0xffc)
9588 ++ movl $pa(swapper_pg_fixmap)+PDE_IDENT_ATTR,pa(swapper_pg_dir+0xffc)
9589 + #endif
9590 + jmp 3f
9591 + /*
9592 +@@ -318,13 +376,16 @@ ENTRY(startup_32_smp)
9593 + jnc 6f
9594 +
9595 + /* Setup EFER (Extended Feature Enable Register) */
9596 +- movl $0xc0000080, %ecx
9597 ++ movl $MSR_EFER, %ecx
9598 + rdmsr
9599 +
9600 + btsl $11, %eax
9601 + /* Make changes effective */
9602 + wrmsr
9603 +
9604 ++ btsl $63-32,pa(__supported_pte_mask+4)
9605 ++ movl $1,pa(nx_enabled)
9606 ++
9607 + 6:
9608 +
9609 + /*
9610 +@@ -350,9 +411,7 @@ ENTRY(startup_32_smp)
9611 +
9612 + #ifdef CONFIG_SMP
9613 + cmpb $0, ready
9614 +- jz 1f /* Initial CPU cleans BSS */
9615 +- jmp checkCPUtype
9616 +-1:
9617 ++ jnz checkCPUtype /* Initial CPU cleans BSS */
9618 + #endif /* CONFIG_SMP */
9619 +
9620 + /*
9621 +@@ -429,12 +488,12 @@ is386: movl $2,%ecx # set MP
9622 + ljmp $(__KERNEL_CS),$1f
9623 + 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
9624 + movl %eax,%ss # after changing gdt.
9625 +- movl %eax,%fs # gets reset once there's real percpu
9626 +-
9627 +- movl $(__USER_DS),%eax # DS/ES contains default USER segment
9628 + movl %eax,%ds
9629 + movl %eax,%es
9630 +
9631 ++ movl $(__KERNEL_PERCPU), %eax
9632 ++ movl %eax,%fs # set this cpu's percpu
9633 ++
9634 + xorl %eax,%eax # Clear GS and LDT
9635 + movl %eax,%gs
9636 + lldt %ax
9637 +@@ -444,12 +503,6 @@ is386: movl $2,%ecx # set MP
9638 + #ifdef CONFIG_SMP
9639 + movb ready, %cl
9640 + movb $1, ready
9641 +- cmpb $0,%cl # the first CPU calls start_kernel
9642 +- je 1f
9643 +- movl $(__KERNEL_PERCPU), %eax
9644 +- movl %eax,%fs # set this cpu's percpu
9645 +- movl (stack_start), %esp
9646 +-1:
9647 + #endif /* CONFIG_SMP */
9648 + jmp *(initial_code)
9649 +
9650 +@@ -535,15 +588,15 @@ early_page_fault:
9651 + jmp early_fault
9652 +
9653 + early_fault:
9654 +- cld
9655 + #ifdef CONFIG_PRINTK
9656 ++ cmpl $2,%ss:early_recursion_flag
9657 ++ je hlt_loop
9658 ++ incl %ss:early_recursion_flag
9659 ++ cld
9660 + pusha
9661 + movl $(__KERNEL_DS),%eax
9662 + movl %eax,%ds
9663 + movl %eax,%es
9664 +- cmpl $2,early_recursion_flag
9665 +- je hlt_loop
9666 +- incl early_recursion_flag
9667 + movl %cr2,%eax
9668 + pushl %eax
9669 + pushl %edx /* trapno */
9670 +@@ -553,8 +606,8 @@ early_fault:
9671 + #else
9672 + call printk
9673 + #endif
9674 +-#endif
9675 + call dump_stack
9676 ++#endif
9677 + hlt_loop:
9678 + hlt
9679 + jmp hlt_loop
9680 +@@ -562,8 +615,11 @@ hlt_loop:
9681 + /* This is the default interrupt "handler" :-) */
9682 + ALIGN
9683 + ignore_int:
9684 +- cld
9685 + #ifdef CONFIG_PRINTK
9686 ++ cmpl $2,%ss:early_recursion_flag
9687 ++ je hlt_loop
9688 ++ incl %ss:early_recursion_flag
9689 ++ cld
9690 + pushl %eax
9691 + pushl %ecx
9692 + pushl %edx
9693 +@@ -572,9 +628,6 @@ ignore_int:
9694 + movl $(__KERNEL_DS),%eax
9695 + movl %eax,%ds
9696 + movl %eax,%es
9697 +- cmpl $2,early_recursion_flag
9698 +- je hlt_loop
9699 +- incl early_recursion_flag
9700 + pushl 16(%esp)
9701 + pushl 24(%esp)
9702 + pushl 32(%esp)
9703 +@@ -599,36 +652,41 @@ ignore_int:
9704 + ENTRY(initial_code)
9705 + .long i386_start_kernel
9706 +
9707 +-.section .text
9708 +-/*
9709 +- * Real beginning of normal "text" segment
9710 +- */
9711 +-ENTRY(stext)
9712 +-ENTRY(_stext)
9713 +-
9714 + /*
9715 + * BSS section
9716 + */
9717 +-.section ".bss.page_aligned","wa"
9718 +- .align PAGE_SIZE_asm
9719 + #ifdef CONFIG_X86_PAE
9720 ++.section .swapper_pg_pmd,"a",@progbits
9721 + swapper_pg_pmd:
9722 + .fill 1024*KPMDS,4,0
9723 + #else
9724 ++.section .swapper_pg_dir,"a",@progbits
9725 + ENTRY(swapper_pg_dir)
9726 + .fill 1024,4,0
9727 + #endif
9728 + swapper_pg_fixmap:
9729 + .fill 1024,4,0
9730 ++
9731 ++.section .empty_zero_page,"a",@progbits
9732 + ENTRY(empty_zero_page)
9733 + .fill 4096,1,0
9734 ++
9735 ++/*
9736 ++ * The IDT has to be page-aligned to simplify the Pentium
9737 ++ * F0 0F bug workaround.. We have a special link segment
9738 ++ * for this.
9739 ++ */
9740 ++.section .idt,"a",@progbits
9741 ++ENTRY(idt_table)
9742 ++ .fill 256,8,0
9743 ++
9744 + /*
9745 + * This starts the data section.
9746 + */
9747 ++.data
9748 ++
9749 + #ifdef CONFIG_X86_PAE
9750 +-.section ".data.page_aligned","wa"
9751 +- /* Page-aligned for the benefit of paravirt? */
9752 +- .align PAGE_SIZE_asm
9753 ++.section .swapper_pg_dir,"a",@progbits
9754 + ENTRY(swapper_pg_dir)
9755 + .long pa(swapper_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
9756 + # if KPMDS == 3
9757 +@@ -651,11 +709,12 @@ ENTRY(swapper_pg_dir)
9758 +
9759 + .data
9760 + ENTRY(stack_start)
9761 +- .long init_thread_union+THREAD_SIZE
9762 ++ .long init_thread_union+THREAD_SIZE-8
9763 + .long __BOOT_DS
9764 +
9765 + ready: .byte 0
9766 +
9767 ++.section .rodata,"a",@progbits
9768 + early_recursion_flag:
9769 + .long 0
9770 +
9771 +@@ -691,7 +750,7 @@ fault_msg:
9772 + .word 0 # 32 bit align gdt_desc.address
9773 + boot_gdt_descr:
9774 + .word __BOOT_DS+7
9775 +- .long boot_gdt - __PAGE_OFFSET
9776 ++ .long pa(boot_gdt)
9777 +
9778 + .word 0 # 32-bit align idt_desc.address
9779 + idt_descr:
9780 +@@ -702,7 +761,7 @@ idt_descr:
9781 + .word 0 # 32 bit align gdt_desc.address
9782 + ENTRY(early_gdt_descr)
9783 + .word GDT_ENTRIES*8-1
9784 +- .long per_cpu__gdt_page /* Overwritten for secondary CPUs */
9785 ++ .long cpu_gdt_table /* Overwritten for secondary CPUs */
9786 +
9787 + /*
9788 + * The boot_gdt must mirror the equivalent in setup.S and is
9789 +@@ -711,5 +770,59 @@ ENTRY(early_gdt_descr)
9790 + .align L1_CACHE_BYTES
9791 + ENTRY(boot_gdt)
9792 + .fill GDT_ENTRY_BOOT_CS,8,0
9793 +- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
9794 +- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
9795 ++ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
9796 ++ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
9797 ++
9798 ++ .align PAGE_SIZE_asm
9799 ++ENTRY(cpu_gdt_table)
9800 ++ .rept NR_CPUS
9801 ++ .quad 0x0000000000000000 /* NULL descriptor */
9802 ++ .quad 0x0000000000000000 /* 0x0b reserved */
9803 ++ .quad 0x0000000000000000 /* 0x13 reserved */
9804 ++ .quad 0x0000000000000000 /* 0x1b reserved */
9805 ++ .quad 0x0000000000000000 /* 0x20 unused */
9806 ++ .quad 0x0000000000000000 /* 0x28 unused */
9807 ++ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
9808 ++ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
9809 ++ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
9810 ++ .quad 0x0000000000000000 /* 0x4b reserved */
9811 ++ .quad 0x0000000000000000 /* 0x53 reserved */
9812 ++ .quad 0x0000000000000000 /* 0x5b reserved */
9813 ++
9814 ++ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
9815 ++ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
9816 ++ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
9817 ++ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
9818 ++
9819 ++ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
9820 ++ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
9821 ++
9822 ++ /*
9823 ++ * Segments used for calling PnP BIOS have byte granularity.
9824 ++ * The code segments and data segments have fixed 64k limits,
9825 ++ * the transfer segment sizes are set at run time.
9826 ++ */
9827 ++ .quad 0x00409b000000ffff /* 0x90 32-bit code */
9828 ++ .quad 0x00009b000000ffff /* 0x98 16-bit code */
9829 ++ .quad 0x000093000000ffff /* 0xa0 16-bit data */
9830 ++ .quad 0x0000930000000000 /* 0xa8 16-bit data */
9831 ++ .quad 0x0000930000000000 /* 0xb0 16-bit data */
9832 ++
9833 ++ /*
9834 ++ * The APM segments have byte granularity and their bases
9835 ++ * are set at run time. All have 64k limits.
9836 ++ */
9837 ++ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
9838 ++ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
9839 ++ .quad 0x004093000000ffff /* 0xc8 APM DS data */
9840 ++
9841 ++ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
9842 ++ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
9843 ++ .quad 0x0000000000000000 /* 0xe0 - PCIBIOS_CS */
9844 ++ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_DS */
9845 ++ .quad 0x0000000000000000 /* 0xf0 - unused */
9846 ++ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
9847 ++
9848 ++ /* Be sure this is zeroed to avoid false validations in Xen */
9849 ++ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
9850 ++ .endr
9851 +diff -urNp linux-2.6.28/arch/x86/kernel/head64.c linux-2.6.28/arch/x86/kernel/head64.c
9852 +--- linux-2.6.28/arch/x86/kernel/head64.c 2008-12-24 18:26:37.000000000 -0500
9853 ++++ linux-2.6.28/arch/x86/kernel/head64.c 2009-01-11 07:20:06.000000000 -0500
9854 +@@ -93,6 +93,8 @@ void __init x86_64_start_kernel(char * r
9855 + /* clear bss before set_intr_gate with early_idt_handler */
9856 + clear_bss();
9857 +
9858 ++ x86_64_init_pda();
9859 ++
9860 + /* Make NULL pointers segfault */
9861 + zap_identity_mappings();
9862 +
9863 +@@ -111,8 +113,6 @@ void __init x86_64_start_kernel(char * r
9864 + if (console_loglevel == 10)
9865 + early_printk("Kernel alive\n");
9866 +
9867 +- x86_64_init_pda();
9868 +-
9869 + x86_64_start_reservations(real_mode_data);
9870 + }
9871 +
9872 +diff -urNp linux-2.6.28/arch/x86/kernel/head_64.S linux-2.6.28/arch/x86/kernel/head_64.S
9873 +--- linux-2.6.28/arch/x86/kernel/head_64.S 2008-12-24 18:26:37.000000000 -0500
9874 ++++ linux-2.6.28/arch/x86/kernel/head_64.S 2009-01-11 07:20:06.000000000 -0500
9875 +@@ -38,6 +38,10 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET
9876 + L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
9877 + L4_START_KERNEL = pgd_index(__START_KERNEL_map)
9878 + L3_START_KERNEL = pud_index(__START_KERNEL_map)
9879 ++L4_VMALLOC_START = pgd_index(VMALLOC_START)
9880 ++L3_VMALLOC_START = pud_index(VMALLOC_START)
9881 ++L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
9882 ++L3_VMEMMAP_START = pud_index(VMEMMAP_START)
9883 +
9884 + .text
9885 + .section .text.head
9886 +@@ -85,35 +89,22 @@ startup_64:
9887 + */
9888 + addq %rbp, init_level4_pgt + 0(%rip)
9889 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
9890 ++ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
9891 ++ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
9892 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
9893 +
9894 + addq %rbp, level3_ident_pgt + 0(%rip)
9895 ++ addq %rbp, level3_ident_pgt + 8(%rip)
9896 ++ addq %rbp, level3_ident_pgt + 16(%rip)
9897 ++ addq %rbp, level3_ident_pgt + 24(%rip)
9898 +
9899 +- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
9900 +- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
9901 ++ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
9902 +
9903 +- addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
9904 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
9905 ++ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
9906 +
9907 +- /* Add an Identity mapping if I am above 1G */
9908 +- leaq _text(%rip), %rdi
9909 +- andq $PMD_PAGE_MASK, %rdi
9910 +-
9911 +- movq %rdi, %rax
9912 +- shrq $PUD_SHIFT, %rax
9913 +- andq $(PTRS_PER_PUD - 1), %rax
9914 +- jz ident_complete
9915 +-
9916 +- leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
9917 +- leaq level3_ident_pgt(%rip), %rbx
9918 +- movq %rdx, 0(%rbx, %rax, 8)
9919 +-
9920 +- movq %rdi, %rax
9921 +- shrq $PMD_SHIFT, %rax
9922 +- andq $(PTRS_PER_PMD - 1), %rax
9923 +- leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
9924 +- leaq level2_spare_pgt(%rip), %rbx
9925 +- movq %rdx, 0(%rbx, %rax, 8)
9926 +-ident_complete:
9927 ++ addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
9928 ++ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
9929 +
9930 + /*
9931 + * Fixup the kernel text+data virtual addresses. Note that
9932 +@@ -187,6 +178,10 @@ ENTRY(secondary_startup_64)
9933 + btl $20,%edi /* No Execute supported? */
9934 + jnc 1f
9935 + btsl $_EFER_NX, %eax
9936 ++ leaq init_level4_pgt(%rip), %rdi
9937 ++ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
9938 ++ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
9939 ++ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
9940 + 1: wrmsr /* Make changes effective */
9941 +
9942 + /* Setup cr0 */
9943 +@@ -257,16 +252,16 @@ ENTRY(secondary_startup_64)
9944 + .align 8
9945 + ENTRY(initial_code)
9946 + .quad x86_64_start_kernel
9947 +- __FINITDATA
9948 +
9949 + ENTRY(stack_start)
9950 + .quad init_thread_union+THREAD_SIZE-8
9951 + .word 0
9952 ++ __FINITDATA
9953 +
9954 + bad_address:
9955 + jmp bad_address
9956 +
9957 +- .section ".init.text","ax"
9958 ++ __INIT
9959 + #ifdef CONFIG_EARLY_PRINTK
9960 + .globl early_idt_handlers
9961 + early_idt_handlers:
9962 +@@ -311,18 +306,23 @@ ENTRY(early_idt_handler)
9963 + #endif /* EARLY_PRINTK */
9964 + 1: hlt
9965 + jmp 1b
9966 ++ .previous
9967 +
9968 + #ifdef CONFIG_EARLY_PRINTK
9969 ++ __INITDATA
9970 + early_recursion_flag:
9971 + .long 0
9972 ++ .previous
9973 +
9974 ++ .section .rodata,"a",@progbits
9975 + early_idt_msg:
9976 + .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
9977 + early_idt_ripmsg:
9978 + .asciz "RIP %s\n"
9979 +-#endif /* CONFIG_EARLY_PRINTK */
9980 + .previous
9981 ++#endif /* CONFIG_EARLY_PRINTK */
9982 +
9983 ++ .section .rodata,"a",@progbits
9984 + .balign PAGE_SIZE
9985 +
9986 + #define NEXT_PAGE(name) \
9987 +@@ -347,13 +347,27 @@ NEXT_PAGE(init_level4_pgt)
9988 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
9989 + .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
9990 + .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
9991 ++ .org init_level4_pgt + L4_VMALLOC_START*8, 0
9992 ++ .quad level3_vmalloc_pgt - __START_KERNEL_map + _KERNPG_TABLE
9993 ++ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
9994 ++ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
9995 + .org init_level4_pgt + L4_START_KERNEL*8, 0
9996 + /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
9997 + .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
9998 +
9999 + NEXT_PAGE(level3_ident_pgt)
10000 + .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
10001 +- .fill 511,8,0
10002 ++ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
10003 ++ .quad level2_ident_pgt + 2*PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
10004 ++ .quad level2_ident_pgt + 3*PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
10005 ++ .fill 508,8,0
10006 ++
10007 ++NEXT_PAGE(level3_vmalloc_pgt)
10008 ++ .fill 512,8,0
10009 ++
10010 ++NEXT_PAGE(level3_vmemmap_pgt)
10011 ++ .fill L3_VMEMMAP_START,8,0
10012 ++ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
10013 +
10014 + NEXT_PAGE(level3_kernel_pgt)
10015 + .fill L3_START_KERNEL,8,0
10016 +@@ -361,20 +375,27 @@ NEXT_PAGE(level3_kernel_pgt)
10017 + .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
10018 + .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
10019 +
10020 ++NEXT_PAGE(level2_vmemmap_pgt)
10021 ++ .fill 512,8,0
10022 ++
10023 + NEXT_PAGE(level2_fixmap_pgt)
10024 + .fill 506,8,0
10025 + .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
10026 +- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
10027 +- .fill 5,8,0
10028 ++ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
10029 ++ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
10030 ++ .fill 4,8,0
10031 +
10032 + NEXT_PAGE(level1_fixmap_pgt)
10033 + .fill 512,8,0
10034 +
10035 +-NEXT_PAGE(level2_ident_pgt)
10036 +- /* Since I easily can, map the first 1G.
10037 ++NEXT_PAGE(level1_vsyscall_pgt)
10038 ++ .fill 512,8,0
10039 ++
10040 ++ /* Since I easily can, map the first 4G.
10041 + * Don't set NX because code runs from these pages.
10042 + */
10043 +- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
10044 ++NEXT_PAGE(level2_ident_pgt)
10045 ++ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 4*PTRS_PER_PMD)
10046 +
10047 + NEXT_PAGE(level2_kernel_pgt)
10048 + /*
10049 +@@ -387,32 +408,48 @@ NEXT_PAGE(level2_kernel_pgt)
10050 + * If you want to increase this then increase MODULES_VADDR
10051 + * too.)
10052 + */
10053 +- PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
10054 +- KERNEL_IMAGE_SIZE/PMD_SIZE)
10055 +-
10056 +-NEXT_PAGE(level2_spare_pgt)
10057 +- .fill 512, 8, 0
10058 ++ PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
10059 +
10060 + #undef PMDS
10061 + #undef NEXT_PAGE
10062 +
10063 +- .data
10064 ++ .align PAGE_SIZE
10065 ++ENTRY(cpu_gdt_table)
10066 ++ .rept NR_CPUS
10067 ++ .quad 0x0000000000000000 /* NULL descriptor */
10068 ++ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
10069 ++ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10070 ++ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10071 ++ .quad 0x00cffb000000ffff /* __USER32_CS */
10072 ++ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
10073 ++ .quad 0x00affb000000ffff /* __USER_CS */
10074 ++ .quad 0x0 /* unused */
10075 ++ .quad 0,0 /* TSS */
10076 ++ .quad 0,0 /* LDT */
10077 ++ .quad 0,0,0 /* three TLS descriptors */
10078 ++ .quad 0x0000f40000000000 /* node/CPU stored in limit */
10079 ++ /* asm/segment.h:GDT_ENTRIES must match this */
10080 ++
10081 ++ /* zero the remaining page */
10082 ++ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
10083 ++ .endr
10084 ++
10085 + .align 16
10086 + .globl early_gdt_descr
10087 + early_gdt_descr:
10088 + .word GDT_ENTRIES*8-1
10089 +- .quad per_cpu__gdt_page
10090 ++ .quad cpu_gdt_table
10091 +
10092 + ENTRY(phys_base)
10093 + /* This must match the first entry in level2_kernel_pgt */
10094 + .quad 0x0000000000000000
10095 +
10096 + #include "../../x86/xen/xen-head.S"
10097 +-
10098 +- .section .bss, "aw", @nobits
10099 ++
10100 ++ .section .rodata,"a",@progbits
10101 + .align L1_CACHE_BYTES
10102 + ENTRY(idt_table)
10103 +- .skip 256 * 16
10104 ++ .fill 512,8,0
10105 +
10106 + .section .bss.page_aligned, "aw", @nobits
10107 + .align PAGE_SIZE
10108 +diff -urNp linux-2.6.28/arch/x86/kernel/i386_ksyms_32.c linux-2.6.28/arch/x86/kernel/i386_ksyms_32.c
10109 +--- linux-2.6.28/arch/x86/kernel/i386_ksyms_32.c 2008-12-24 18:26:37.000000000 -0500
10110 ++++ linux-2.6.28/arch/x86/kernel/i386_ksyms_32.c 2009-01-11 07:20:06.000000000 -0500
10111 +@@ -10,8 +10,12 @@
10112 + EXPORT_SYMBOL(mcount);
10113 + #endif
10114 +
10115 ++EXPORT_SYMBOL_GPL(cpu_gdt_table);
10116 ++
10117 + /* Networking helper routines. */
10118 + EXPORT_SYMBOL(csum_partial_copy_generic);
10119 ++EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
10120 ++EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
10121 +
10122 + EXPORT_SYMBOL(__get_user_1);
10123 + EXPORT_SYMBOL(__get_user_2);
10124 +@@ -26,3 +30,7 @@ EXPORT_SYMBOL(strstr);
10125 +
10126 + EXPORT_SYMBOL(csum_partial);
10127 + EXPORT_SYMBOL(empty_zero_page);
10128 ++
10129 ++#ifdef CONFIG_PAX_KERNEXEC
10130 ++EXPORT_SYMBOL(KERNEL_TEXT_OFFSET);
10131 ++#endif
10132 +diff -urNp linux-2.6.28/arch/x86/kernel/init_task.c linux-2.6.28/arch/x86/kernel/init_task.c
10133 +--- linux-2.6.28/arch/x86/kernel/init_task.c 2008-12-24 18:26:37.000000000 -0500
10134 ++++ linux-2.6.28/arch/x86/kernel/init_task.c 2009-01-11 07:20:06.000000000 -0500
10135 +@@ -42,5 +42,5 @@ EXPORT_SYMBOL(init_task);
10136 + * section. Since TSS's are completely CPU-local, we want them
10137 + * on exact cacheline boundaries, to eliminate cacheline ping-pong.
10138 + */
10139 +-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
10140 +-
10141 ++struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
10142 ++EXPORT_SYMBOL(init_tss);
10143 +diff -urNp linux-2.6.28/arch/x86/kernel/ioport.c linux-2.6.28/arch/x86/kernel/ioport.c
10144 +--- linux-2.6.28/arch/x86/kernel/ioport.c 2008-12-24 18:26:37.000000000 -0500
10145 ++++ linux-2.6.28/arch/x86/kernel/ioport.c 2009-01-11 07:20:06.000000000 -0500
10146 +@@ -14,6 +14,7 @@
10147 + #include <linux/slab.h>
10148 + #include <linux/thread_info.h>
10149 + #include <linux/syscalls.h>
10150 ++#include <linux/grsecurity.h>
10151 + #include <asm/syscalls.h>
10152 +
10153 + /* Set EXTENT bits starting at BASE in BITMAP to value TURN_ON. */
10154 +@@ -41,6 +42,12 @@ asmlinkage long sys_ioperm(unsigned long
10155 +
10156 + if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
10157 + return -EINVAL;
10158 ++#ifdef CONFIG_GRKERNSEC_IO
10159 ++ if (turn_on) {
10160 ++ gr_handle_ioperm();
10161 ++ return -EPERM;
10162 ++ }
10163 ++#endif
10164 + if (turn_on && !capable(CAP_SYS_RAWIO))
10165 + return -EPERM;
10166 +
10167 +@@ -67,7 +74,7 @@ asmlinkage long sys_ioperm(unsigned long
10168 + * because the ->io_bitmap_max value must match the bitmap
10169 + * contents:
10170 + */
10171 +- tss = &per_cpu(init_tss, get_cpu());
10172 ++ tss = init_tss + get_cpu();
10173 +
10174 + set_bitmap(t->io_bitmap_ptr, from, num, !turn_on);
10175 +
10176 +@@ -122,8 +129,13 @@ static int do_iopl(unsigned int level, s
10177 + return -EINVAL;
10178 + /* Trying to gain more privileges? */
10179 + if (level > old) {
10180 ++#ifdef CONFIG_GRKERNSEC_IO
10181 ++ gr_handle_iopl();
10182 ++ return -EPERM;
10183 ++#else
10184 + if (!capable(CAP_SYS_RAWIO))
10185 + return -EPERM;
10186 ++#endif
10187 + }
10188 + regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
10189 +
10190 +diff -urNp linux-2.6.28/arch/x86/kernel/irq_32.c linux-2.6.28/arch/x86/kernel/irq_32.c
10191 +--- linux-2.6.28/arch/x86/kernel/irq_32.c 2008-12-24 18:26:37.000000000 -0500
10192 ++++ linux-2.6.28/arch/x86/kernel/irq_32.c 2009-01-11 07:20:06.000000000 -0500
10193 +@@ -93,7 +93,7 @@ execute_on_irq_stack(int overflow, struc
10194 + return 0;
10195 +
10196 + /* build the stack frame on the IRQ stack */
10197 +- isp = (u32 *) ((char*)irqctx + sizeof(*irqctx));
10198 ++ isp = (u32 *) ((char*)irqctx + sizeof(*irqctx) - 8);
10199 + irqctx->tinfo.task = curctx->tinfo.task;
10200 + irqctx->tinfo.previous_esp = current_stack_pointer;
10201 +
10202 +@@ -174,7 +174,7 @@ asmlinkage void do_softirq(void)
10203 + irqctx->tinfo.previous_esp = current_stack_pointer;
10204 +
10205 + /* build the stack frame on the softirq stack */
10206 +- isp = (u32*) ((char*)irqctx + sizeof(*irqctx));
10207 ++ isp = (u32*) ((char*)irqctx + sizeof(*irqctx) - 8);
10208 +
10209 + call_on_stack(__do_softirq, isp);
10210 + /*
10211 +diff -urNp linux-2.6.28/arch/x86/kernel/kprobes.c linux-2.6.28/arch/x86/kernel/kprobes.c
10212 +--- linux-2.6.28/arch/x86/kernel/kprobes.c 2008-12-24 18:26:37.000000000 -0500
10213 ++++ linux-2.6.28/arch/x86/kernel/kprobes.c 2009-01-11 07:20:06.000000000 -0500
10214 +@@ -166,9 +166,24 @@ static void __kprobes set_jmp_op(void *f
10215 + char op;
10216 + s32 raddr;
10217 + } __attribute__((packed)) * jop;
10218 +- jop = (struct __arch_jmp_op *)from;
10219 ++
10220 ++#ifdef CONFIG_PAX_KERNEXEC
10221 ++ unsigned long cr0;
10222 ++#endif
10223 ++
10224 ++ jop = (struct __arch_jmp_op *)(ktla_ktva(from));
10225 ++
10226 ++#ifdef CONFIG_PAX_KERNEXEC
10227 ++ pax_open_kernel(cr0);
10228 ++#endif
10229 ++
10230 + jop->raddr = (s32)((long)(to) - ((long)(from) + 5));
10231 + jop->op = RELATIVEJUMP_INSTRUCTION;
10232 ++
10233 ++#ifdef CONFIG_PAX_KERNEXEC
10234 ++ pax_close_kernel(cr0);
10235 ++#endif
10236 ++
10237 + }
10238 +
10239 + /*
10240 +@@ -342,16 +357,29 @@ static void __kprobes fix_riprel(struct
10241 +
10242 + static void __kprobes arch_copy_kprobe(struct kprobe *p)
10243 + {
10244 +- memcpy(p->ainsn.insn, p->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
10245 ++
10246 ++#ifdef CONFIG_PAX_KERNEXEC
10247 ++ unsigned long cr0;
10248 ++#endif
10249 ++
10250 ++#ifdef CONFIG_PAX_KERNEXEC
10251 ++ pax_open_kernel(cr0);
10252 ++#endif
10253 ++
10254 ++ memcpy(p->ainsn.insn, ktla_ktva(p->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
10255 ++
10256 ++#ifdef CONFIG_PAX_KERNEXEC
10257 ++ pax_close_kernel(cr0);
10258 ++#endif
10259 +
10260 + fix_riprel(p);
10261 +
10262 +- if (can_boost(p->addr))
10263 ++ if (can_boost(ktla_ktva(p->addr)))
10264 + p->ainsn.boostable = 0;
10265 + else
10266 + p->ainsn.boostable = -1;
10267 +
10268 +- p->opcode = *p->addr;
10269 ++ p->opcode = *(ktla_ktva(p->addr));
10270 + }
10271 +
10272 + int __kprobes arch_prepare_kprobe(struct kprobe *p)
10273 +@@ -428,7 +456,7 @@ static void __kprobes prepare_singlestep
10274 + if (p->opcode == BREAKPOINT_INSTRUCTION)
10275 + regs->ip = (unsigned long)p->addr;
10276 + else
10277 +- regs->ip = (unsigned long)p->ainsn.insn;
10278 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
10279 + }
10280 +
10281 + void __kprobes arch_prepare_kretprobe(struct kretprobe_instance *ri,
10282 +@@ -449,7 +477,7 @@ static void __kprobes setup_singlestep(s
10283 + if (p->ainsn.boostable == 1 && !p->post_handler) {
10284 + /* Boost up -- we can execute copied instructions directly */
10285 + reset_current_kprobe();
10286 +- regs->ip = (unsigned long)p->ainsn.insn;
10287 ++ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
10288 + preempt_enable_no_resched();
10289 + return;
10290 + }
10291 +@@ -519,7 +547,7 @@ static int __kprobes kprobe_handler(stru
10292 + struct kprobe_ctlblk *kcb;
10293 +
10294 + addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
10295 +- if (*addr != BREAKPOINT_INSTRUCTION) {
10296 ++ if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
10297 + /*
10298 + * The breakpoint instruction was removed right
10299 + * after we hit it. Another cpu has removed
10300 +@@ -770,7 +798,7 @@ static void __kprobes resume_execution(s
10301 + struct pt_regs *regs, struct kprobe_ctlblk *kcb)
10302 + {
10303 + unsigned long *tos = stack_addr(regs);
10304 +- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
10305 ++ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
10306 + unsigned long orig_ip = (unsigned long)p->addr;
10307 + kprobe_opcode_t *insn = p->ainsn.insn;
10308 +
10309 +@@ -953,7 +981,7 @@ int __kprobes kprobe_exceptions_notify(s
10310 + struct die_args *args = data;
10311 + int ret = NOTIFY_DONE;
10312 +
10313 +- if (args->regs && user_mode_vm(args->regs))
10314 ++ if (args->regs && user_mode(args->regs))
10315 + return ret;
10316 +
10317 + switch (val) {
10318 +diff -urNp linux-2.6.28/arch/x86/kernel/ldt.c linux-2.6.28/arch/x86/kernel/ldt.c
10319 +--- linux-2.6.28/arch/x86/kernel/ldt.c 2008-12-24 18:26:37.000000000 -0500
10320 ++++ linux-2.6.28/arch/x86/kernel/ldt.c 2009-01-11 07:20:06.000000000 -0500
10321 +@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, i
10322 + if (reload) {
10323 + #ifdef CONFIG_SMP
10324 + preempt_disable();
10325 +- load_LDT(pc);
10326 ++ load_LDT_nolock(pc);
10327 + if (!cpus_equal(current->mm->cpu_vm_mask,
10328 + cpumask_of_cpu(smp_processor_id())))
10329 + smp_call_function(flush_ldt, current->mm, 1);
10330 + preempt_enable();
10331 + #else
10332 +- load_LDT(pc);
10333 ++ load_LDT_nolock(pc);
10334 + #endif
10335 + }
10336 + if (oldsize) {
10337 +@@ -115,6 +115,24 @@ int init_new_context(struct task_struct
10338 + retval = copy_ldt(&mm->context, &old_mm->context);
10339 + mutex_unlock(&old_mm->context.lock);
10340 + }
10341 ++
10342 ++ if (tsk == current) {
10343 ++ mm->context.vdso = ~0UL;
10344 ++
10345 ++#ifdef CONFIG_X86_32
10346 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10347 ++ mm->context.user_cs_base = 0UL;
10348 ++ mm->context.user_cs_limit = ~0UL;
10349 ++
10350 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10351 ++ cpus_clear(mm->context.cpu_user_cs_mask);
10352 ++#endif
10353 ++
10354 ++#endif
10355 ++#endif
10356 ++
10357 ++ }
10358 ++
10359 + return retval;
10360 + }
10361 +
10362 +@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, u
10363 + }
10364 + }
10365 +
10366 ++#ifdef CONFIG_PAX_SEGMEXEC
10367 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
10368 ++ error = -EINVAL;
10369 ++ goto out_unlock;
10370 ++ }
10371 ++#endif
10372 ++
10373 + fill_ldt(&ldt, &ldt_info);
10374 + if (oldmode)
10375 + ldt.avl = 0;
10376 +diff -urNp linux-2.6.28/arch/x86/kernel/machine_kexec_32.c linux-2.6.28/arch/x86/kernel/machine_kexec_32.c
10377 +--- linux-2.6.28/arch/x86/kernel/machine_kexec_32.c 2008-12-24 18:26:37.000000000 -0500
10378 ++++ linux-2.6.28/arch/x86/kernel/machine_kexec_32.c 2009-01-11 07:20:06.000000000 -0500
10379 +@@ -34,7 +34,7 @@ static u32 kexec_pmd1[1024] PAGE_ALIGNED
10380 + static u32 kexec_pte0[1024] PAGE_ALIGNED;
10381 + static u32 kexec_pte1[1024] PAGE_ALIGNED;
10382 +
10383 +-static void set_idt(void *newidt, __u16 limit)
10384 ++static void set_idt(struct desc_struct *newidt, __u16 limit)
10385 + {
10386 + struct desc_ptr curidt;
10387 +
10388 +@@ -46,7 +46,7 @@ static void set_idt(void *newidt, __u16
10389 + }
10390 +
10391 +
10392 +-static void set_gdt(void *newgdt, __u16 limit)
10393 ++static void set_gdt(struct desc_struct *newgdt, __u16 limit)
10394 + {
10395 + struct desc_ptr curgdt;
10396 +
10397 +@@ -145,7 +145,7 @@ void machine_kexec(struct kimage *image)
10398 + }
10399 +
10400 + control_page = page_address(image->control_code_page);
10401 +- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
10402 ++ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
10403 +
10404 + relocate_kernel_ptr = control_page;
10405 + page_list[PA_CONTROL_PAGE] = __pa(control_page);
10406 +diff -urNp linux-2.6.28/arch/x86/kernel/module_32.c linux-2.6.28/arch/x86/kernel/module_32.c
10407 +--- linux-2.6.28/arch/x86/kernel/module_32.c 2008-12-24 18:26:37.000000000 -0500
10408 ++++ linux-2.6.28/arch/x86/kernel/module_32.c 2009-01-11 07:20:06.000000000 -0500
10409 +@@ -23,6 +23,9 @@
10410 + #include <linux/kernel.h>
10411 + #include <linux/bug.h>
10412 +
10413 ++#include <asm/desc.h>
10414 ++#include <asm/pgtable.h>
10415 ++
10416 + #if 0
10417 + #define DEBUGP printk
10418 + #else
10419 +@@ -33,9 +36,31 @@ void *module_alloc(unsigned long size)
10420 + {
10421 + if (size == 0)
10422 + return NULL;
10423 ++
10424 ++#ifdef CONFIG_PAX_KERNEXEC
10425 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL);
10426 ++#else
10427 + return vmalloc_exec(size);
10428 ++#endif
10429 ++
10430 + }
10431 +
10432 ++#ifdef CONFIG_PAX_KERNEXEC
10433 ++void *module_alloc_exec(unsigned long size)
10434 ++{
10435 ++ struct vm_struct *area;
10436 ++
10437 ++ if (size == 0)
10438 ++ return NULL;
10439 ++
10440 ++ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_VADDR, (unsigned long)&MODULES_END);
10441 ++ if (area)
10442 ++ return area->addr;
10443 ++
10444 ++ return NULL;
10445 ++}
10446 ++EXPORT_SYMBOL(module_alloc_exec);
10447 ++#endif
10448 +
10449 + /* Free memory returned from module_alloc */
10450 + void module_free(struct module *mod, void *module_region)
10451 +@@ -45,6 +70,45 @@ void module_free(struct module *mod, voi
10452 + table entries. */
10453 + }
10454 +
10455 ++#ifdef CONFIG_PAX_KERNEXEC
10456 ++void module_free_exec(struct module *mod, void *module_region)
10457 ++{
10458 ++ struct vm_struct **p, *tmp;
10459 ++
10460 ++ if (!module_region)
10461 ++ return;
10462 ++
10463 ++ if ((PAGE_SIZE-1) & (unsigned long)module_region) {
10464 ++ printk(KERN_ERR "Trying to module_free_exec() bad address (%p)\n", module_region);
10465 ++ WARN_ON(1);
10466 ++ return;
10467 ++ }
10468 ++
10469 ++ write_lock(&vmlist_lock);
10470 ++ for (p = &vmlist; (tmp = *p) != NULL; p = &tmp->next)
10471 ++ if (tmp->addr == module_region)
10472 ++ break;
10473 ++
10474 ++ if (tmp) {
10475 ++ unsigned long cr0;
10476 ++
10477 ++ pax_open_kernel(cr0);
10478 ++ memset(tmp->addr, 0xCC, tmp->size);
10479 ++ pax_close_kernel(cr0);
10480 ++
10481 ++ *p = tmp->next;
10482 ++ kfree(tmp);
10483 ++ }
10484 ++ write_unlock(&vmlist_lock);
10485 ++
10486 ++ if (!tmp) {
10487 ++ printk(KERN_ERR "Trying to module_free_exec() nonexistent vm area (%p)\n",
10488 ++ module_region);
10489 ++ WARN_ON(1);
10490 ++ }
10491 ++}
10492 ++#endif
10493 ++
10494 + /* We don't need anything special. */
10495 + int module_frob_arch_sections(Elf_Ehdr *hdr,
10496 + Elf_Shdr *sechdrs,
10497 +@@ -63,14 +127,20 @@ int apply_relocate(Elf32_Shdr *sechdrs,
10498 + unsigned int i;
10499 + Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
10500 + Elf32_Sym *sym;
10501 +- uint32_t *location;
10502 ++ uint32_t *plocation, location;
10503 ++
10504 ++#ifdef CONFIG_PAX_KERNEXEC
10505 ++ unsigned long cr0;
10506 ++#endif
10507 +
10508 + DEBUGP("Applying relocate section %u to %u\n", relsec,
10509 + sechdrs[relsec].sh_info);
10510 + for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
10511 + /* This is where to make the change */
10512 +- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
10513 +- + rel[i].r_offset;
10514 ++ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
10515 ++ location = (uint32_t)plocation;
10516 ++ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
10517 ++ plocation = ktla_ktva((void *)plocation);
10518 + /* This is the symbol it is referring to. Note that all
10519 + undefined symbols have been resolved. */
10520 + sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
10521 +@@ -78,12 +148,32 @@ int apply_relocate(Elf32_Shdr *sechdrs,
10522 +
10523 + switch (ELF32_R_TYPE(rel[i].r_info)) {
10524 + case R_386_32:
10525 ++
10526 ++#ifdef CONFIG_PAX_KERNEXEC
10527 ++ pax_open_kernel(cr0);
10528 ++#endif
10529 ++
10530 + /* We add the value into the location given */
10531 +- *location += sym->st_value;
10532 ++ *plocation += sym->st_value;
10533 ++
10534 ++#ifdef CONFIG_PAX_KERNEXEC
10535 ++ pax_close_kernel(cr0);
10536 ++#endif
10537 ++
10538 + break;
10539 + case R_386_PC32:
10540 ++
10541 ++#ifdef CONFIG_PAX_KERNEXEC
10542 ++ pax_open_kernel(cr0);
10543 ++#endif
10544 ++
10545 + /* Add the value, subtract its postition */
10546 +- *location += sym->st_value - (uint32_t)location;
10547 ++ *plocation += sym->st_value - location;
10548 ++
10549 ++#ifdef CONFIG_PAX_KERNEXEC
10550 ++ pax_close_kernel(cr0);
10551 ++#endif
10552 ++
10553 + break;
10554 + default:
10555 + printk(KERN_ERR "module %s: Unknown relocation: %u\n",
10556 +diff -urNp linux-2.6.28/arch/x86/kernel/module_64.c linux-2.6.28/arch/x86/kernel/module_64.c
10557 +--- linux-2.6.28/arch/x86/kernel/module_64.c 2008-12-24 18:26:37.000000000 -0500
10558 ++++ linux-2.6.28/arch/x86/kernel/module_64.c 2009-01-11 07:20:06.000000000 -0500
10559 +@@ -40,7 +40,7 @@ void module_free(struct module *mod, voi
10560 + table entries. */
10561 + }
10562 +
10563 +-void *module_alloc(unsigned long size)
10564 ++static void *__module_alloc(unsigned long size, pgprot_t prot)
10565 + {
10566 + struct vm_struct *area;
10567 +
10568 +@@ -54,8 +54,31 @@ void *module_alloc(unsigned long size)
10569 + if (!area)
10570 + return NULL;
10571 +
10572 +- return __vmalloc_area(area, GFP_KERNEL, PAGE_KERNEL_EXEC);
10573 ++ return __vmalloc_area(area, GFP_KERNEL | __GFP_ZERO, prot);
10574 ++}
10575 ++
10576 ++#ifdef CONFIG_PAX_KERNEXEC
10577 ++void *module_alloc(unsigned long size)
10578 ++{
10579 ++ return __module_alloc(size, PAGE_KERNEL);
10580 ++}
10581 ++
10582 ++void module_free_exec(struct module *mod, void *module_region)
10583 ++{
10584 ++ module_free(mod, module_region);
10585 ++}
10586 ++
10587 ++void *module_alloc_exec(unsigned long size)
10588 ++{
10589 ++ return __module_alloc(size, PAGE_KERNEL_RX);
10590 + }
10591 ++#else
10592 ++void *module_alloc(unsigned long size)
10593 ++{
10594 ++ return __module_alloc(size, PAGE_KERNEL_EXEC);
10595 ++}
10596 ++#endif
10597 ++
10598 + #endif
10599 +
10600 + /* We don't need anything special. */
10601 +@@ -77,7 +100,11 @@ int apply_relocate_add(Elf64_Shdr *sechd
10602 + Elf64_Rela *rel = (void *)sechdrs[relsec].sh_addr;
10603 + Elf64_Sym *sym;
10604 + void *loc;
10605 +- u64 val;
10606 ++ u64 val;
10607 ++
10608 ++#ifdef CONFIG_PAX_KERNEXEC
10609 ++ unsigned long cr0;
10610 ++#endif
10611 +
10612 + DEBUGP("Applying relocate section %u to %u\n", relsec,
10613 + sechdrs[relsec].sh_info);
10614 +@@ -101,21 +128,61 @@ int apply_relocate_add(Elf64_Shdr *sechd
10615 + case R_X86_64_NONE:
10616 + break;
10617 + case R_X86_64_64:
10618 ++
10619 ++#ifdef CONFIG_PAX_KERNEXEC
10620 ++ pax_open_kernel(cr0);
10621 ++#endif
10622 ++
10623 + *(u64 *)loc = val;
10624 ++
10625 ++#ifdef CONFIG_PAX_KERNEXEC
10626 ++ pax_close_kernel(cr0);
10627 ++#endif
10628 ++
10629 + break;
10630 + case R_X86_64_32:
10631 ++
10632 ++#ifdef CONFIG_PAX_KERNEXEC
10633 ++ pax_open_kernel(cr0);
10634 ++#endif
10635 ++
10636 + *(u32 *)loc = val;
10637 ++
10638 ++#ifdef CONFIG_PAX_KERNEXEC
10639 ++ pax_close_kernel(cr0);
10640 ++#endif
10641 ++
10642 + if (val != *(u32 *)loc)
10643 + goto overflow;
10644 + break;
10645 + case R_X86_64_32S:
10646 ++
10647 ++#ifdef CONFIG_PAX_KERNEXEC
10648 ++ pax_open_kernel(cr0);
10649 ++#endif
10650 ++
10651 + *(s32 *)loc = val;
10652 ++
10653 ++#ifdef CONFIG_PAX_KERNEXEC
10654 ++ pax_close_kernel(cr0);
10655 ++#endif
10656 ++
10657 + if ((s64)val != *(s32 *)loc)
10658 + goto overflow;
10659 + break;
10660 + case R_X86_64_PC32:
10661 + val -= (u64)loc;
10662 ++
10663 ++#ifdef CONFIG_PAX_KERNEXEC
10664 ++ pax_open_kernel(cr0);
10665 ++#endif
10666 ++
10667 + *(u32 *)loc = val;
10668 ++
10669 ++#ifdef CONFIG_PAX_KERNEXEC
10670 ++ pax_close_kernel(cr0);
10671 ++#endif
10672 ++
10673 + #if 0
10674 + if ((s64)val != *(s32 *)loc)
10675 + goto overflow;
10676 +diff -urNp linux-2.6.28/arch/x86/kernel/paravirt.c linux-2.6.28/arch/x86/kernel/paravirt.c
10677 +--- linux-2.6.28/arch/x86/kernel/paravirt.c 2008-12-24 18:26:37.000000000 -0500
10678 ++++ linux-2.6.28/arch/x86/kernel/paravirt.c 2009-01-11 07:20:06.000000000 -0500
10679 +@@ -44,7 +44,7 @@ void _paravirt_nop(void)
10680 + {
10681 + }
10682 +
10683 +-static void __init default_banner(void)
10684 ++static void default_banner(void)
10685 + {
10686 + printk(KERN_INFO "Booting paravirtualized kernel on %s\n",
10687 + pv_info.name);
10688 +@@ -164,7 +164,7 @@ unsigned paravirt_patch_insns(void *insn
10689 + if (insn_len > len || start == NULL)
10690 + insn_len = len;
10691 + else
10692 +- memcpy(insnbuf, start, insn_len);
10693 ++ memcpy(insnbuf, ktla_ktva(start), insn_len);
10694 +
10695 + return insn_len;
10696 + }
10697 +@@ -268,21 +268,21 @@ enum paravirt_lazy_mode paravirt_get_laz
10698 + return __get_cpu_var(paravirt_lazy_mode);
10699 + }
10700 +
10701 +-struct pv_info pv_info = {
10702 ++struct pv_info pv_info __read_only = {
10703 + .name = "bare hardware",
10704 + .paravirt_enabled = 0,
10705 + .kernel_rpl = 0,
10706 + .shared_kernel_pmd = 1, /* Only used when CONFIG_X86_PAE is set */
10707 + };
10708 +
10709 +-struct pv_init_ops pv_init_ops = {
10710 ++struct pv_init_ops pv_init_ops __read_only = {
10711 + .patch = native_patch,
10712 + .banner = default_banner,
10713 + .arch_setup = paravirt_nop,
10714 + .memory_setup = machine_specific_memory_setup,
10715 + };
10716 +
10717 +-struct pv_time_ops pv_time_ops = {
10718 ++struct pv_time_ops pv_time_ops __read_only = {
10719 + .time_init = hpet_time_init,
10720 + .get_wallclock = native_get_wallclock,
10721 + .set_wallclock = native_set_wallclock,
10722 +@@ -290,7 +290,7 @@ struct pv_time_ops pv_time_ops = {
10723 + .get_tsc_khz = native_calibrate_tsc,
10724 + };
10725 +
10726 +-struct pv_irq_ops pv_irq_ops = {
10727 ++struct pv_irq_ops pv_irq_ops __read_only = {
10728 + .init_IRQ = native_init_IRQ,
10729 + .save_fl = native_save_fl,
10730 + .restore_fl = native_restore_fl,
10731 +@@ -303,7 +303,7 @@ struct pv_irq_ops pv_irq_ops = {
10732 + #endif
10733 + };
10734 +
10735 +-struct pv_cpu_ops pv_cpu_ops = {
10736 ++struct pv_cpu_ops pv_cpu_ops __read_only = {
10737 + .cpuid = native_cpuid,
10738 + .get_debugreg = native_get_debugreg,
10739 + .set_debugreg = native_set_debugreg,
10740 +@@ -365,7 +365,7 @@ struct pv_cpu_ops pv_cpu_ops = {
10741 + },
10742 + };
10743 +
10744 +-struct pv_apic_ops pv_apic_ops = {
10745 ++struct pv_apic_ops pv_apic_ops __read_only = {
10746 + #ifdef CONFIG_X86_LOCAL_APIC
10747 + .setup_boot_clock = setup_boot_APIC_clock,
10748 + .setup_secondary_clock = setup_secondary_APIC_clock,
10749 +@@ -373,7 +373,7 @@ struct pv_apic_ops pv_apic_ops = {
10750 + #endif
10751 + };
10752 +
10753 +-struct pv_mmu_ops pv_mmu_ops = {
10754 ++struct pv_mmu_ops pv_mmu_ops __read_only = {
10755 + #ifndef CONFIG_X86_64
10756 + .pagetable_setup_start = native_pagetable_setup_start,
10757 + .pagetable_setup_done = native_pagetable_setup_done,
10758 +diff -urNp linux-2.6.28/arch/x86/kernel/paravirt-spinlocks.c linux-2.6.28/arch/x86/kernel/paravirt-spinlocks.c
10759 +--- linux-2.6.28/arch/x86/kernel/paravirt-spinlocks.c 2008-12-24 18:26:37.000000000 -0500
10760 ++++ linux-2.6.28/arch/x86/kernel/paravirt-spinlocks.c 2009-01-11 07:20:06.000000000 -0500
10761 +@@ -13,7 +13,7 @@ default_spin_lock_flags(raw_spinlock_t *
10762 + __raw_spin_lock(lock);
10763 + }
10764 +
10765 +-struct pv_lock_ops pv_lock_ops = {
10766 ++struct pv_lock_ops pv_lock_ops __read_only = {
10767 + #ifdef CONFIG_SMP
10768 + .spin_is_locked = __ticket_spin_is_locked,
10769 + .spin_is_contended = __ticket_spin_is_contended,
10770 +diff -urNp linux-2.6.28/arch/x86/kernel/process_32.c linux-2.6.28/arch/x86/kernel/process_32.c
10771 +--- linux-2.6.28/arch/x86/kernel/process_32.c 2008-12-24 18:26:37.000000000 -0500
10772 ++++ linux-2.6.28/arch/x86/kernel/process_32.c 2009-01-11 07:20:06.000000000 -0500
10773 +@@ -65,8 +65,10 @@ asmlinkage void ret_from_fork(void) __as
10774 + DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
10775 + EXPORT_PER_CPU_SYMBOL(current_task);
10776 +
10777 ++#ifdef CONFIG_SMP
10778 + DEFINE_PER_CPU(int, cpu_number);
10779 + EXPORT_PER_CPU_SYMBOL(cpu_number);
10780 ++#endif
10781 +
10782 + /*
10783 + * Return saved PC of a blocked thread.
10784 +@@ -74,6 +76,7 @@ EXPORT_PER_CPU_SYMBOL(cpu_number);
10785 + unsigned long thread_saved_pc(struct task_struct *tsk)
10786 + {
10787 + return ((unsigned long *)tsk->thread.sp)[3];
10788 ++//XXX return tsk->thread.eip;
10789 + }
10790 +
10791 + #ifndef CONFIG_SMP
10792 +@@ -131,7 +134,7 @@ void __show_regs(struct pt_regs *regs, i
10793 + unsigned short ss, gs;
10794 + const char *board;
10795 +
10796 +- if (user_mode_vm(regs)) {
10797 ++ if (user_mode(regs)) {
10798 + sp = regs->sp;
10799 + ss = regs->ss & 0xffff;
10800 + savesegment(gs, gs);
10801 +@@ -212,8 +215,8 @@ int kernel_thread(int (*fn)(void *), voi
10802 + regs.bx = (unsigned long) fn;
10803 + regs.dx = (unsigned long) arg;
10804 +
10805 +- regs.ds = __USER_DS;
10806 +- regs.es = __USER_DS;
10807 ++ regs.ds = __KERNEL_DS;
10808 ++ regs.es = __KERNEL_DS;
10809 + regs.fs = __KERNEL_PERCPU;
10810 + regs.orig_ax = -1;
10811 + regs.ip = (unsigned long) kernel_thread_helper;
10812 +@@ -235,7 +238,7 @@ void exit_thread(void)
10813 + struct task_struct *tsk = current;
10814 + struct thread_struct *t = &tsk->thread;
10815 + int cpu = get_cpu();
10816 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
10817 ++ struct tss_struct *tss = init_tss + cpu;
10818 +
10819 + kfree(t->io_bitmap_ptr);
10820 + t->io_bitmap_ptr = NULL;
10821 +@@ -264,6 +267,7 @@ void flush_thread(void)
10822 + {
10823 + struct task_struct *tsk = current;
10824 +
10825 ++ loadsegment(gs, 0);
10826 + tsk->thread.debugreg0 = 0;
10827 + tsk->thread.debugreg1 = 0;
10828 + tsk->thread.debugreg2 = 0;
10829 +@@ -303,7 +307,7 @@ int copy_thread(int nr, unsigned long cl
10830 + struct task_struct *tsk;
10831 + int err;
10832 +
10833 +- childregs = task_pt_regs(p);
10834 ++ childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
10835 + *childregs = *regs;
10836 + childregs->ax = 0;
10837 + childregs->sp = sp;
10838 +@@ -332,6 +336,7 @@ int copy_thread(int nr, unsigned long cl
10839 + * Set a new TLS for the child thread?
10840 + */
10841 + if (clone_flags & CLONE_SETTLS)
10842 ++//XXX needs set_fs()?
10843 + err = do_set_thread_area(p, -1,
10844 + (struct user_desc __user *)childregs->si, 0);
10845 +
10846 +@@ -553,7 +558,7 @@ struct task_struct * __switch_to(struct
10847 + struct thread_struct *prev = &prev_p->thread,
10848 + *next = &next_p->thread;
10849 + int cpu = smp_processor_id();
10850 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
10851 ++ struct tss_struct *tss = init_tss + cpu;
10852 +
10853 + /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
10854 +
10855 +@@ -581,6 +586,11 @@ struct task_struct * __switch_to(struct
10856 + */
10857 + savesegment(gs, prev->gs);
10858 +
10859 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
10860 ++ if (!segment_eq(task_thread_info(prev_p)->addr_limit, task_thread_info(next_p)->addr_limit))
10861 ++ __set_fs(task_thread_info(next_p)->addr_limit, cpu);
10862 ++#endif
10863 ++
10864 + /*
10865 + * Load the per-thread Thread-Local Storage descriptor.
10866 + */
10867 +@@ -719,15 +729,27 @@ unsigned long get_wchan(struct task_stru
10868 + return 0;
10869 + }
10870 +
10871 +-unsigned long arch_align_stack(unsigned long sp)
10872 ++#ifdef CONFIG_PAX_RANDKSTACK
10873 ++asmlinkage void pax_randomize_kstack(void)
10874 + {
10875 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10876 +- sp -= get_random_int() % 8192;
10877 +- return sp & ~0xf;
10878 +-}
10879 ++ struct thread_struct *thread = &current->thread;
10880 ++ unsigned long time;
10881 +
10882 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
10883 +-{
10884 +- unsigned long range_end = mm->brk + 0x02000000;
10885 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
10886 ++ if (!randomize_va_space)
10887 ++ return;
10888 ++
10889 ++ rdtscl(time);
10890 ++
10891 ++ /* P4 seems to return a 0 LSB, ignore it */
10892 ++#ifdef CONFIG_MPENTIUM4
10893 ++ time &= 0x1EUL;
10894 ++ time <<= 2;
10895 ++#else
10896 ++ time &= 0xFUL;
10897 ++ time <<= 3;
10898 ++#endif
10899 ++
10900 ++ thread->sp0 ^= time;
10901 ++ load_sp0(init_tss + smp_processor_id(), thread);
10902 + }
10903 ++#endif
10904 +diff -urNp linux-2.6.28/arch/x86/kernel/process_64.c linux-2.6.28/arch/x86/kernel/process_64.c
10905 +--- linux-2.6.28/arch/x86/kernel/process_64.c 2008-12-24 18:26:37.000000000 -0500
10906 ++++ linux-2.6.28/arch/x86/kernel/process_64.c 2009-01-11 07:20:06.000000000 -0500
10907 +@@ -109,6 +109,8 @@ static inline void play_dead(void)
10908 + void cpu_idle(void)
10909 + {
10910 + current_thread_info()->status |= TS_POLLING;
10911 ++ current->stack_canary = pax_get_random_long();
10912 ++ write_pda(stack_canary, current->stack_canary);
10913 + /* endless idle loop with no priority at all */
10914 + while (1) {
10915 + tick_nohz_stop_sched_tick(1);
10916 +@@ -223,7 +225,7 @@ void exit_thread(void)
10917 + struct thread_struct *t = &me->thread;
10918 +
10919 + if (me->thread.io_bitmap_ptr) {
10920 +- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
10921 ++ struct tss_struct *tss = init_tss + get_cpu();
10922 +
10923 + kfree(t->io_bitmap_ptr);
10924 + t->io_bitmap_ptr = NULL;
10925 +@@ -558,7 +560,7 @@ __switch_to(struct task_struct *prev_p,
10926 + struct thread_struct *prev = &prev_p->thread;
10927 + struct thread_struct *next = &next_p->thread;
10928 + int cpu = smp_processor_id();
10929 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
10930 ++ struct tss_struct *tss = init_tss + cpu;
10931 + unsigned fsindex, gsindex;
10932 +
10933 + /* we're going to use this soon, after a few expensive things */
10934 +@@ -647,7 +649,6 @@ __switch_to(struct task_struct *prev_p,
10935 + (unsigned long)task_stack_page(next_p) +
10936 + THREAD_SIZE - PDA_STACKOFFSET);
10937 + #ifdef CONFIG_CC_STACKPROTECTOR
10938 +- write_pda(stack_canary, next_p->stack_canary);
10939 + /*
10940 + * Build time only check to make sure the stack_canary is at
10941 + * offset 40 in the pda; this is a gcc ABI requirement
10942 +@@ -746,12 +747,11 @@ unsigned long get_wchan(struct task_stru
10943 + if (!p || p == current || p->state == TASK_RUNNING)
10944 + return 0;
10945 + stack = (unsigned long)task_stack_page(p);
10946 +- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
10947 ++ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-8-sizeof(u64))
10948 + return 0;
10949 + fp = *(u64 *)(p->thread.sp);
10950 + do {
10951 +- if (fp < (unsigned long)stack ||
10952 +- fp >= (unsigned long)stack+THREAD_SIZE)
10953 ++ if (fp < stack || fp > stack+THREAD_SIZE-8-sizeof(u64))
10954 + return 0;
10955 + ip = *(u64 *)(fp+8);
10956 + if (!in_sched_functions(ip))
10957 +@@ -860,16 +860,3 @@ long sys_arch_prctl(int code, unsigned l
10958 + {
10959 + return do_arch_prctl(current, code, addr);
10960 + }
10961 +-
10962 +-unsigned long arch_align_stack(unsigned long sp)
10963 +-{
10964 +- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10965 +- sp -= get_random_int() % 8192;
10966 +- return sp & ~0xf;
10967 +-}
10968 +-
10969 +-unsigned long arch_randomize_brk(struct mm_struct *mm)
10970 +-{
10971 +- unsigned long range_end = mm->brk + 0x02000000;
10972 +- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
10973 +-}
10974 +diff -urNp linux-2.6.28/arch/x86/kernel/ptrace.c linux-2.6.28/arch/x86/kernel/ptrace.c
10975 +--- linux-2.6.28/arch/x86/kernel/ptrace.c 2008-12-24 18:26:37.000000000 -0500
10976 ++++ linux-2.6.28/arch/x86/kernel/ptrace.c 2009-01-11 07:20:06.000000000 -0500
10977 +@@ -1502,7 +1502,7 @@ void send_sigtrap(struct task_struct *ts
10978 + info.si_code = si_code;
10979 +
10980 + /* User-mode ip? */
10981 +- info.si_addr = user_mode_vm(regs) ? (void __user *) regs->ip : NULL;
10982 ++ info.si_addr = user_mode(regs) ? (void __user *) regs->ip : NULL;
10983 +
10984 + /* Send us the fake SIGTRAP */
10985 + force_sig_info(SIGTRAP, &info, tsk);
10986 +diff -urNp linux-2.6.28/arch/x86/kernel/reboot.c linux-2.6.28/arch/x86/kernel/reboot.c
10987 +--- linux-2.6.28/arch/x86/kernel/reboot.c 2008-12-24 18:26:37.000000000 -0500
10988 ++++ linux-2.6.28/arch/x86/kernel/reboot.c 2009-01-11 07:20:06.000000000 -0500
10989 +@@ -28,7 +28,7 @@ void (*pm_power_off)(void);
10990 + EXPORT_SYMBOL(pm_power_off);
10991 +
10992 + static const struct desc_ptr no_idt = {};
10993 +-static int reboot_mode;
10994 ++static unsigned short reboot_mode;
10995 + enum reboot_type reboot_type = BOOT_KBD;
10996 + int reboot_force;
10997 +
10998 +@@ -202,7 +202,7 @@ static struct dmi_system_id __initdata r
10999 + DMI_MATCH(DMI_PRODUCT_NAME, "HP Compaq"),
11000 + },
11001 + },
11002 +- { }
11003 ++ { NULL, NULL, {{0, {0}}}, NULL}
11004 + };
11005 +
11006 + static int __init reboot_init(void)
11007 +@@ -218,12 +218,12 @@ core_initcall(reboot_init);
11008 + controller to pulse the CPU reset line, which is more thorough, but
11009 + doesn't work with at least one type of 486 motherboard. It is easy
11010 + to stop this code working; hence the copious comments. */
11011 +-static const unsigned long long
11012 +-real_mode_gdt_entries [3] =
11013 ++static struct desc_struct
11014 ++real_mode_gdt_entries [3] __read_only =
11015 + {
11016 +- 0x0000000000000000ULL, /* Null descriptor */
11017 +- 0x00009b000000ffffULL, /* 16-bit real-mode 64k code at 0x00000000 */
11018 +- 0x000093000100ffffULL /* 16-bit real-mode 64k data at 0x00000100 */
11019 ++ {{{0x00000000, 0x00000000}}}, /* Null descriptor */
11020 ++ {{{0x0000ffff, 0x00009b00}}}, /* 16-bit real-mode 64k code at 0x00000000 */
11021 ++ {{{0x0100ffff, 0x00009300}}} /* 16-bit real-mode 64k data at 0x00000100 */
11022 + };
11023 +
11024 + static const struct desc_ptr
11025 +@@ -272,7 +272,7 @@ static const unsigned char jump_to_bios
11026 + * specified by the code and length parameters.
11027 + * We assume that length will aways be less that 100!
11028 + */
11029 +-void machine_real_restart(const unsigned char *code, int length)
11030 ++void machine_real_restart(const unsigned char *code, unsigned int length)
11031 + {
11032 + local_irq_disable();
11033 +
11034 +@@ -292,8 +292,8 @@ void machine_real_restart(const unsigned
11035 + /* Remap the kernel at virtual address zero, as well as offset zero
11036 + from the kernel segment. This assumes the kernel segment starts at
11037 + virtual address PAGE_OFFSET. */
11038 +- memcpy(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
11039 +- sizeof(swapper_pg_dir [0]) * KERNEL_PGD_PTRS);
11040 ++ clone_pgd_range(swapper_pg_dir, swapper_pg_dir + KERNEL_PGD_BOUNDARY,
11041 ++ min_t(unsigned long, KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
11042 +
11043 + /*
11044 + * Use `swapper_pg_dir' as our page directory.
11045 +@@ -305,16 +305,15 @@ void machine_real_restart(const unsigned
11046 + boot)". This seems like a fairly standard thing that gets set by
11047 + REBOOT.COM programs, and the previous reset routine did this
11048 + too. */
11049 +- *((unsigned short *)0x472) = reboot_mode;
11050 ++ *(unsigned short *)(__va(0x472)) = reboot_mode;
11051 +
11052 + /* For the switch to real mode, copy some code to low memory. It has
11053 + to be in the first 64k because it is running in 16-bit mode, and it
11054 + has to have the same physical and virtual address, because it turns
11055 + off paging. Copy it near the end of the first page, out of the way
11056 + of BIOS variables. */
11057 +- memcpy((void *)(0x1000 - sizeof(real_mode_switch) - 100),
11058 +- real_mode_switch, sizeof (real_mode_switch));
11059 +- memcpy((void *)(0x1000 - 100), code, length);
11060 ++ memcpy(__va(0x1000 - sizeof (real_mode_switch) - 100), real_mode_switch, sizeof (real_mode_switch));
11061 ++ memcpy(__va(0x1000 - 100), code, length);
11062 +
11063 + /* Set up the IDT for real mode. */
11064 + load_idt(&real_mode_idt);
11065 +diff -urNp linux-2.6.28/arch/x86/kernel/setup.c linux-2.6.28/arch/x86/kernel/setup.c
11066 +--- linux-2.6.28/arch/x86/kernel/setup.c 2008-12-24 18:26:37.000000000 -0500
11067 ++++ linux-2.6.28/arch/x86/kernel/setup.c 2009-01-11 07:20:06.000000000 -0500
11068 +@@ -738,6 +738,7 @@ void start_periodic_check_for_corruption
11069 + }
11070 + #endif
11071 +
11072 ++#ifdef CONFIG_X86_RESERVE_LOW_64K
11073 + static int __init dmi_low_memory_corruption(const struct dmi_system_id *d)
11074 + {
11075 + printk(KERN_NOTICE
11076 +@@ -749,6 +750,7 @@ static int __init dmi_low_memory_corrupt
11077 +
11078 + return 0;
11079 + }
11080 ++#endif
11081 +
11082 + /* List of systems that have known low memory corruption BIOS problems */
11083 + static struct dmi_system_id __initdata bad_bios_dmi_table[] = {
11084 +@@ -845,8 +847,8 @@ void __init setup_arch(char **cmdline_p)
11085 +
11086 + if (!boot_params.hdr.root_flags)
11087 + root_mountflags &= ~MS_RDONLY;
11088 +- init_mm.start_code = (unsigned long) _text;
11089 +- init_mm.end_code = (unsigned long) _etext;
11090 ++ init_mm.start_code = ktla_ktva((unsigned long) _text);
11091 ++ init_mm.end_code = ktla_ktva((unsigned long) _etext);
11092 + init_mm.end_data = (unsigned long) _edata;
11093 + #ifdef CONFIG_X86_32
11094 + init_mm.brk = init_pg_tables_end + PAGE_OFFSET;
11095 +@@ -854,9 +856,9 @@ void __init setup_arch(char **cmdline_p)
11096 + init_mm.brk = (unsigned long) &_end;
11097 + #endif
11098 +
11099 +- code_resource.start = virt_to_phys(_text);
11100 +- code_resource.end = virt_to_phys(_etext)-1;
11101 +- data_resource.start = virt_to_phys(_etext);
11102 ++ code_resource.start = virt_to_phys(ktla_ktva(_text));
11103 ++ code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
11104 ++ data_resource.start = virt_to_phys(_data);
11105 + data_resource.end = virt_to_phys(_edata)-1;
11106 + bss_resource.start = virt_to_phys(&__bss_start);
11107 + bss_resource.end = virt_to_phys(&__bss_stop)-1;
11108 +diff -urNp linux-2.6.28/arch/x86/kernel/setup_percpu.c linux-2.6.28/arch/x86/kernel/setup_percpu.c
11109 +--- linux-2.6.28/arch/x86/kernel/setup_percpu.c 2008-12-24 18:26:37.000000000 -0500
11110 ++++ linux-2.6.28/arch/x86/kernel/setup_percpu.c 2009-01-11 07:20:06.000000000 -0500
11111 +@@ -179,7 +179,11 @@ void __init setup_per_cpu_areas(void)
11112 + cpu, node, __pa(ptr));
11113 + }
11114 + #endif
11115 ++#ifdef CONFIG_X86_32
11116 ++ __per_cpu_offset[cpu] = ptr - __per_cpu_start;
11117 ++#else
11118 + per_cpu_offset(cpu) = ptr - __per_cpu_start;
11119 ++#endif
11120 + memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
11121 + }
11122 +
11123 +diff -urNp linux-2.6.28/arch/x86/kernel/signal_32.c linux-2.6.28/arch/x86/kernel/signal_32.c
11124 +--- linux-2.6.28/arch/x86/kernel/signal_32.c 2008-12-24 18:26:37.000000000 -0500
11125 ++++ linux-2.6.28/arch/x86/kernel/signal_32.c 2009-01-11 07:20:06.000000000 -0500
11126 +@@ -367,9 +367,9 @@ __setup_frame(int sig, struct k_sigactio
11127 + }
11128 +
11129 + if (current->mm->context.vdso)
11130 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
11131 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
11132 + else
11133 +- restorer = &frame->retcode;
11134 ++ restorer = (void __user *)&frame->retcode;
11135 + if (ka->sa.sa_flags & SA_RESTORER)
11136 + restorer = ka->sa.sa_restorer;
11137 +
11138 +@@ -442,7 +442,7 @@ static int __setup_rt_frame(int sig, str
11139 + return -EFAULT;
11140 +
11141 + /* Set up to return from userspace. */
11142 +- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11143 ++ restorer = (void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11144 + if (ka->sa.sa_flags & SA_RESTORER)
11145 + restorer = ka->sa.sa_restorer;
11146 + err |= __put_user(restorer, &frame->pretcode);
11147 +@@ -612,7 +612,7 @@ static void do_signal(struct pt_regs *re
11148 + * X86_32: vm86 regs switched out by assembly code before reaching
11149 + * here, so testing against kernel CS suffices.
11150 + */
11151 +- if (!user_mode(regs))
11152 ++ if (!user_mode_novm(regs))
11153 + return;
11154 +
11155 + if (current_thread_info()->status & TS_RESTORE_SIGMASK)
11156 +diff -urNp linux-2.6.28/arch/x86/kernel/signal_64.c linux-2.6.28/arch/x86/kernel/signal_64.c
11157 +--- linux-2.6.28/arch/x86/kernel/signal_64.c 2008-12-24 18:26:37.000000000 -0500
11158 ++++ linux-2.6.28/arch/x86/kernel/signal_64.c 2009-01-11 07:20:06.000000000 -0500
11159 +@@ -239,8 +239,8 @@ static int __setup_rt_frame(int sig, str
11160 + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs, set->sig[0], me);
11161 + err |= __put_user(fp, &frame->uc.uc_mcontext.fpstate);
11162 + if (sizeof(*set) == 16) {
11163 +- __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
11164 +- __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
11165 ++ err |= __put_user(set->sig[0], &frame->uc.uc_sigmask.sig[0]);
11166 ++ err |= __put_user(set->sig[1], &frame->uc.uc_sigmask.sig[1]);
11167 + } else
11168 + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
11169 +
11170 +diff -urNp linux-2.6.28/arch/x86/kernel/smpboot.c linux-2.6.28/arch/x86/kernel/smpboot.c
11171 +--- linux-2.6.28/arch/x86/kernel/smpboot.c 2008-12-24 18:26:37.000000000 -0500
11172 ++++ linux-2.6.28/arch/x86/kernel/smpboot.c 2009-01-11 07:20:06.000000000 -0500
11173 +@@ -814,6 +814,11 @@ static int __cpuinit do_boot_cpu(int api
11174 + .cpu = cpu,
11175 + .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
11176 + };
11177 ++
11178 ++#ifdef CONFIG_PAX_KERNEXEC
11179 ++ unsigned long cr0;
11180 ++#endif
11181 ++
11182 + INIT_WORK(&c_idle.work, do_fork_idle);
11183 +
11184 + #ifdef CONFIG_X86_64
11185 +@@ -864,7 +869,17 @@ do_rest:
11186 + cpu_pda(cpu)->pcurrent = c_idle.idle;
11187 + clear_tsk_thread_flag(c_idle.idle, TIF_FORK);
11188 + #endif
11189 ++
11190 ++#ifdef CONFIG_PAX_KERNEXEC
11191 ++ pax_open_kernel(cr0);
11192 ++#endif
11193 ++
11194 + early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
11195 ++
11196 ++#ifdef CONFIG_PAX_KERNEXEC
11197 ++ pax_close_kernel(cr0);
11198 ++#endif
11199 ++
11200 + initial_code = (unsigned long)start_secondary;
11201 + stack_start.sp = (void *) c_idle.idle->thread.sp;
11202 +
11203 +diff -urNp linux-2.6.28/arch/x86/kernel/smpcommon.c linux-2.6.28/arch/x86/kernel/smpcommon.c
11204 +--- linux-2.6.28/arch/x86/kernel/smpcommon.c 2008-12-24 18:26:37.000000000 -0500
11205 ++++ linux-2.6.28/arch/x86/kernel/smpcommon.c 2009-01-11 07:20:06.000000000 -0500
11206 +@@ -3,9 +3,10 @@
11207 + */
11208 + #include <linux/module.h>
11209 + #include <asm/smp.h>
11210 ++#include <asm/sections.h>
11211 +
11212 + #ifdef CONFIG_X86_32
11213 +-DEFINE_PER_CPU(unsigned long, this_cpu_off);
11214 ++DEFINE_PER_CPU(unsigned long, this_cpu_off) = (unsigned long)__per_cpu_start;
11215 + EXPORT_PER_CPU_SYMBOL(this_cpu_off);
11216 +
11217 + /*
11218 +@@ -15,16 +16,19 @@ EXPORT_PER_CPU_SYMBOL(this_cpu_off);
11219 + */
11220 + __cpuinit void init_gdt(int cpu)
11221 + {
11222 +- struct desc_struct gdt;
11223 ++ struct desc_struct d, *gdt = get_cpu_gdt_table(cpu);
11224 ++ unsigned long base, limit;
11225 +
11226 +- pack_descriptor(&gdt, __per_cpu_offset[cpu], 0xFFFFF,
11227 +- 0x2 | DESCTYPE_S, 0x8);
11228 +- gdt.s = 1;
11229 ++ base = per_cpu_offset(cpu);
11230 ++ limit = PERCPU_ENOUGH_ROOM - 1;
11231 ++ if (limit < 64*1024)
11232 ++ pack_descriptor(&d, base, limit, 0x80 | DESCTYPE_S | 0x3, 0x4);
11233 ++ else
11234 ++ pack_descriptor(&d, base, limit >> PAGE_SHIFT, 0x80 | DESCTYPE_S | 0x3, 0xC);
11235 +
11236 +- write_gdt_entry(get_cpu_gdt_table(cpu),
11237 +- GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
11238 ++ write_gdt_entry(gdt, GDT_ENTRY_PERCPU, &d, DESCTYPE_S);
11239 +
11240 +- per_cpu(this_cpu_off, cpu) = __per_cpu_offset[cpu];
11241 ++ per_cpu(this_cpu_off, cpu) = base;
11242 + per_cpu(cpu_number, cpu) = cpu;
11243 + }
11244 + #endif
11245 +diff -urNp linux-2.6.28/arch/x86/kernel/step.c linux-2.6.28/arch/x86/kernel/step.c
11246 +--- linux-2.6.28/arch/x86/kernel/step.c 2008-12-24 18:26:37.000000000 -0500
11247 ++++ linux-2.6.28/arch/x86/kernel/step.c 2009-01-11 07:20:06.000000000 -0500
11248 +@@ -23,22 +23,20 @@ unsigned long convert_ip_to_linear(struc
11249 + * and APM bios ones we just ignore here.
11250 + */
11251 + if ((seg & SEGMENT_TI_MASK) == SEGMENT_LDT) {
11252 +- u32 *desc;
11253 ++ struct desc_struct *desc;
11254 + unsigned long base;
11255 +
11256 +- seg &= ~7UL;
11257 ++ seg >>= 3;
11258 +
11259 + mutex_lock(&child->mm->context.lock);
11260 +- if (unlikely((seg >> 3) >= child->mm->context.size))
11261 +- addr = -1L; /* bogus selector, access would fault */
11262 ++ if (unlikely(seg >= child->mm->context.size))
11263 ++ addr = -EINVAL;
11264 + else {
11265 +- desc = child->mm->context.ldt + seg;
11266 +- base = ((desc[0] >> 16) |
11267 +- ((desc[1] & 0xff) << 16) |
11268 +- (desc[1] & 0xff000000));
11269 ++ desc = &child->mm->context.ldt[seg];
11270 ++ base = (desc->a >> 16) | ((desc->b & 0xff) << 16) | (desc->b & 0xff000000);
11271 +
11272 + /* 16-bit code segment? */
11273 +- if (!((desc[1] >> 22) & 1))
11274 ++ if (!((desc->b >> 22) & 1))
11275 + addr &= 0xffff;
11276 + addr += base;
11277 + }
11278 +@@ -54,6 +52,9 @@ static int is_setting_trap_flag(struct t
11279 + unsigned char opcode[15];
11280 + unsigned long addr = convert_ip_to_linear(child, regs);
11281 +
11282 ++ if (addr == -EINVAL)
11283 ++ return 0;
11284 ++
11285 + copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
11286 + for (i = 0; i < copied; i++) {
11287 + switch (opcode[i]) {
11288 +@@ -75,7 +76,7 @@ static int is_setting_trap_flag(struct t
11289 +
11290 + #ifdef CONFIG_X86_64
11291 + case 0x40 ... 0x4f:
11292 +- if (regs->cs != __USER_CS)
11293 ++ if ((regs->cs & 0xffff) != __USER_CS)
11294 + /* 32-bit mode: register increment */
11295 + return 0;
11296 + /* 64-bit mode: REX prefix */
11297 +diff -urNp linux-2.6.28/arch/x86/kernel/syscall_table_32.S linux-2.6.28/arch/x86/kernel/syscall_table_32.S
11298 +--- linux-2.6.28/arch/x86/kernel/syscall_table_32.S 2008-12-24 18:26:37.000000000 -0500
11299 ++++ linux-2.6.28/arch/x86/kernel/syscall_table_32.S 2009-01-11 07:20:06.000000000 -0500
11300 +@@ -1,3 +1,4 @@
11301 ++.section .rodata,"a",@progbits
11302 + ENTRY(sys_call_table)
11303 + .long sys_restart_syscall /* 0 - old "setup()" system call, used for restarting */
11304 + .long sys_exit
11305 +diff -urNp linux-2.6.28/arch/x86/kernel/sys_i386_32.c linux-2.6.28/arch/x86/kernel/sys_i386_32.c
11306 +--- linux-2.6.28/arch/x86/kernel/sys_i386_32.c 2008-12-24 18:26:37.000000000 -0500
11307 ++++ linux-2.6.28/arch/x86/kernel/sys_i386_32.c 2009-01-11 07:20:06.000000000 -0500
11308 +@@ -24,6 +24,21 @@
11309 +
11310 + #include <asm/syscalls.h>
11311 +
11312 ++int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
11313 ++{
11314 ++ unsigned long pax_task_size = TASK_SIZE;
11315 ++
11316 ++#ifdef CONFIG_PAX_SEGMEXEC
11317 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
11318 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
11319 ++#endif
11320 ++
11321 ++ if (len > pax_task_size || addr > pax_task_size - len)
11322 ++ return -EINVAL;
11323 ++
11324 ++ return 0;
11325 ++}
11326 ++
11327 + asmlinkage long sys_mmap2(unsigned long addr, unsigned long len,
11328 + unsigned long prot, unsigned long flags,
11329 + unsigned long fd, unsigned long pgoff)
11330 +@@ -83,6 +98,205 @@ out:
11331 + return err;
11332 + }
11333 +
11334 ++unsigned long
11335 ++arch_get_unmapped_area(struct file *filp, unsigned long addr,
11336 ++ unsigned long len, unsigned long pgoff, unsigned long flags)
11337 ++{
11338 ++ struct mm_struct *mm = current->mm;
11339 ++ struct vm_area_struct *vma;
11340 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
11341 ++
11342 ++#ifdef CONFIG_PAX_SEGMEXEC
11343 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11344 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
11345 ++#endif
11346 ++
11347 ++ if (len > pax_task_size)
11348 ++ return -ENOMEM;
11349 ++
11350 ++ if (flags & MAP_FIXED)
11351 ++ return addr;
11352 ++
11353 ++#ifdef CONFIG_PAX_RANDMMAP
11354 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11355 ++#endif
11356 ++
11357 ++ if (addr) {
11358 ++ addr = PAGE_ALIGN(addr);
11359 ++ vma = find_vma(mm, addr);
11360 ++ if (pax_task_size - len >= addr &&
11361 ++ (!vma || addr + len <= vma->vm_start))
11362 ++ return addr;
11363 ++ }
11364 ++ if (len > mm->cached_hole_size) {
11365 ++ start_addr = addr = mm->free_area_cache;
11366 ++ } else {
11367 ++ start_addr = addr = mm->mmap_base;
11368 ++ mm->cached_hole_size = 0;
11369 ++ }
11370 ++
11371 ++#ifdef CONFIG_PAX_PAGEEXEC
11372 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
11373 ++ start_addr = 0x00110000UL;
11374 ++
11375 ++#ifdef CONFIG_PAX_RANDMMAP
11376 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11377 ++ start_addr += mm->delta_mmap & 0x03FFF000UL;
11378 ++#endif
11379 ++
11380 ++ if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
11381 ++ start_addr = addr = mm->mmap_base;
11382 ++ else
11383 ++ addr = start_addr;
11384 ++ }
11385 ++#endif
11386 ++
11387 ++full_search:
11388 ++ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
11389 ++ /* At this point: (!vma || addr < vma->vm_end). */
11390 ++ if (pax_task_size - len < addr) {
11391 ++ /*
11392 ++ * Start a new search - just in case we missed
11393 ++ * some holes.
11394 ++ */
11395 ++ if (start_addr != mm->mmap_base) {
11396 ++ start_addr = addr = mm->mmap_base;
11397 ++ mm->cached_hole_size = 0;
11398 ++ goto full_search;
11399 ++ }
11400 ++ return -ENOMEM;
11401 ++ }
11402 ++ if (!vma || addr + len <= vma->vm_start) {
11403 ++ /*
11404 ++ * Remember the place where we stopped the search:
11405 ++ */
11406 ++ mm->free_area_cache = addr + len;
11407 ++ return addr;
11408 ++ }
11409 ++ if (addr + mm->cached_hole_size < vma->vm_start)
11410 ++ mm->cached_hole_size = vma->vm_start - addr;
11411 ++ addr = vma->vm_end;
11412 ++ if (mm->start_brk <= addr && addr < mm->mmap_base) {
11413 ++ start_addr = addr = mm->mmap_base;
11414 ++ mm->cached_hole_size = 0;
11415 ++ goto full_search;
11416 ++ }
11417 ++ }
11418 ++}
11419 ++
11420 ++unsigned long
11421 ++arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11422 ++ const unsigned long len, const unsigned long pgoff,
11423 ++ const unsigned long flags)
11424 ++{
11425 ++ struct vm_area_struct *vma;
11426 ++ struct mm_struct *mm = current->mm;
11427 ++ unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
11428 ++
11429 ++#ifdef CONFIG_PAX_SEGMEXEC
11430 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11431 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
11432 ++#endif
11433 ++
11434 ++ /* requested length too big for entire address space */
11435 ++ if (len > pax_task_size)
11436 ++ return -ENOMEM;
11437 ++
11438 ++ if (flags & MAP_FIXED)
11439 ++ return addr;
11440 ++
11441 ++#ifdef CONFIG_PAX_PAGEEXEC
11442 ++ if (!nx_enabled && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
11443 ++ goto bottomup;
11444 ++#endif
11445 ++
11446 ++#ifdef CONFIG_PAX_RANDMMAP
11447 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11448 ++#endif
11449 ++
11450 ++ /* requesting a specific address */
11451 ++ if (addr) {
11452 ++ addr = PAGE_ALIGN(addr);
11453 ++ vma = find_vma(mm, addr);
11454 ++ if (pax_task_size - len >= addr &&
11455 ++ (!vma || addr + len <= vma->vm_start))
11456 ++ return addr;
11457 ++ }
11458 ++
11459 ++ /* check if free_area_cache is useful for us */
11460 ++ if (len <= mm->cached_hole_size) {
11461 ++ mm->cached_hole_size = 0;
11462 ++ mm->free_area_cache = mm->mmap_base;
11463 ++ }
11464 ++
11465 ++ /* either no address requested or can't fit in requested address hole */
11466 ++ addr = mm->free_area_cache;
11467 ++
11468 ++ /* make sure it can fit in the remaining address space */
11469 ++ if (addr > len) {
11470 ++ vma = find_vma(mm, addr-len);
11471 ++ if (!vma || addr <= vma->vm_start)
11472 ++ /* remember the address as a hint for next time */
11473 ++ return (mm->free_area_cache = addr-len);
11474 ++ }
11475 ++
11476 ++ if (mm->mmap_base < len)
11477 ++ goto bottomup;
11478 ++
11479 ++ addr = mm->mmap_base-len;
11480 ++
11481 ++ do {
11482 ++ /*
11483 ++ * Lookup failure means no vma is above this address,
11484 ++ * else if new region fits below vma->vm_start,
11485 ++ * return with success:
11486 ++ */
11487 ++ vma = find_vma(mm, addr);
11488 ++ if (!vma || addr+len <= vma->vm_start)
11489 ++ /* remember the address as a hint for next time */
11490 ++ return (mm->free_area_cache = addr);
11491 ++
11492 ++ /* remember the largest hole we saw so far */
11493 ++ if (addr + mm->cached_hole_size < vma->vm_start)
11494 ++ mm->cached_hole_size = vma->vm_start - addr;
11495 ++
11496 ++ /* try just below the current vma->vm_start */
11497 ++ addr = vma->vm_start-len;
11498 ++ } while (len < vma->vm_start);
11499 ++
11500 ++bottomup:
11501 ++ /*
11502 ++ * A failed mmap() very likely causes application failure,
11503 ++ * so fall back to the bottom-up function here. This scenario
11504 ++ * can happen with large stack limits and large mmap()
11505 ++ * allocations.
11506 ++ */
11507 ++
11508 ++#ifdef CONFIG_PAX_SEGMEXEC
11509 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
11510 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
11511 ++ else
11512 ++#endif
11513 ++
11514 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
11515 ++
11516 ++#ifdef CONFIG_PAX_RANDMMAP
11517 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11518 ++ mm->mmap_base += mm->delta_mmap;
11519 ++#endif
11520 ++
11521 ++ mm->free_area_cache = mm->mmap_base;
11522 ++ mm->cached_hole_size = ~0UL;
11523 ++ addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
11524 ++ /*
11525 ++ * Restore the topdown base:
11526 ++ */
11527 ++ mm->mmap_base = base;
11528 ++ mm->free_area_cache = base;
11529 ++ mm->cached_hole_size = ~0UL;
11530 ++
11531 ++ return addr;
11532 ++}
11533 +
11534 + struct sel_arg_struct {
11535 + unsigned long n;
11536 +diff -urNp linux-2.6.28/arch/x86/kernel/sys_x86_64.c linux-2.6.28/arch/x86/kernel/sys_x86_64.c
11537 +--- linux-2.6.28/arch/x86/kernel/sys_x86_64.c 2008-12-24 18:26:37.000000000 -0500
11538 ++++ linux-2.6.28/arch/x86/kernel/sys_x86_64.c 2009-01-11 07:20:06.000000000 -0500
11539 +@@ -47,8 +47,8 @@ out:
11540 + return error;
11541 + }
11542 +
11543 +-static void find_start_end(unsigned long flags, unsigned long *begin,
11544 +- unsigned long *end)
11545 ++static void find_start_end(struct mm_struct *mm, unsigned long flags,
11546 ++ unsigned long *begin, unsigned long *end)
11547 + {
11548 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT)) {
11549 + unsigned long new_begin;
11550 +@@ -67,7 +67,7 @@ static void find_start_end(unsigned long
11551 + *begin = new_begin;
11552 + }
11553 + } else {
11554 +- *begin = TASK_UNMAPPED_BASE;
11555 ++ *begin = mm->mmap_base;
11556 + *end = TASK_SIZE;
11557 + }
11558 + }
11559 +@@ -84,11 +84,15 @@ arch_get_unmapped_area(struct file *filp
11560 + if (flags & MAP_FIXED)
11561 + return addr;
11562 +
11563 +- find_start_end(flags, &begin, &end);
11564 ++ find_start_end(mm, flags, &begin, &end);
11565 +
11566 + if (len > end)
11567 + return -ENOMEM;
11568 +
11569 ++#ifdef CONFIG_PAX_RANDMMAP
11570 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11571 ++#endif
11572 ++
11573 + if (addr) {
11574 + addr = PAGE_ALIGN(addr);
11575 + vma = find_vma(mm, addr);
11576 +@@ -143,7 +147,7 @@ arch_get_unmapped_area_topdown(struct fi
11577 + {
11578 + struct vm_area_struct *vma;
11579 + struct mm_struct *mm = current->mm;
11580 +- unsigned long addr = addr0;
11581 ++ unsigned long base = mm->mmap_base, addr = addr0;
11582 +
11583 + /* requested length too big for entire address space */
11584 + if (len > TASK_SIZE)
11585 +@@ -156,6 +160,10 @@ arch_get_unmapped_area_topdown(struct fi
11586 + if (!test_thread_flag(TIF_IA32) && (flags & MAP_32BIT))
11587 + goto bottomup;
11588 +
11589 ++#ifdef CONFIG_PAX_RANDMMAP
11590 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11591 ++#endif
11592 ++
11593 + /* requesting a specific address */
11594 + if (addr) {
11595 + addr = PAGE_ALIGN(addr);
11596 +@@ -213,13 +221,21 @@ bottomup:
11597 + * can happen with large stack limits and large mmap()
11598 + * allocations.
11599 + */
11600 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
11601 ++
11602 ++#ifdef CONFIG_PAX_RANDMMAP
11603 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
11604 ++ mm->mmap_base += mm->delta_mmap;
11605 ++#endif
11606 ++
11607 ++ mm->free_area_cache = mm->mmap_base;
11608 + mm->cached_hole_size = ~0UL;
11609 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
11610 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
11611 + /*
11612 + * Restore the topdown base:
11613 + */
11614 +- mm->free_area_cache = mm->mmap_base;
11615 ++ mm->mmap_base = base;
11616 ++ mm->free_area_cache = base;
11617 + mm->cached_hole_size = ~0UL;
11618 +
11619 + return addr;
11620 +diff -urNp linux-2.6.28/arch/x86/kernel/time_32.c linux-2.6.28/arch/x86/kernel/time_32.c
11621 +--- linux-2.6.28/arch/x86/kernel/time_32.c 2008-12-24 18:26:37.000000000 -0500
11622 ++++ linux-2.6.28/arch/x86/kernel/time_32.c 2009-01-11 07:20:06.000000000 -0500
11623 +@@ -47,22 +47,32 @@ unsigned long profile_pc(struct pt_regs
11624 + unsigned long pc = instruction_pointer(regs);
11625 +
11626 + #ifdef CONFIG_SMP
11627 +- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
11628 ++ if (!user_mode(regs) && in_lock_functions(pc)) {
11629 + #ifdef CONFIG_FRAME_POINTER
11630 +- return *(unsigned long *)(regs->bp + sizeof(long));
11631 ++ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
11632 + #else
11633 + unsigned long *sp = (unsigned long *)&regs->sp;
11634 +
11635 + /* Return address is either directly at stack pointer
11636 + or above a saved flags. Eflags has bits 22-31 zero,
11637 + kernel addresses don't. */
11638 ++
11639 ++#ifdef CONFIG_PAX_KERNEXEC
11640 ++ return ktla_ktva(sp[0]);
11641 ++#else
11642 + if (sp[0] >> 22)
11643 + return sp[0];
11644 + if (sp[1] >> 22)
11645 + return sp[1];
11646 + #endif
11647 ++
11648 ++#endif
11649 + }
11650 + #endif
11651 ++
11652 ++ if (!user_mode(regs))
11653 ++ pc = ktla_ktva(pc);
11654 ++
11655 + return pc;
11656 + }
11657 + EXPORT_SYMBOL(profile_pc);
11658 +diff -urNp linux-2.6.28/arch/x86/kernel/time_64.c linux-2.6.28/arch/x86/kernel/time_64.c
11659 +--- linux-2.6.28/arch/x86/kernel/time_64.c 2008-12-24 18:26:37.000000000 -0500
11660 ++++ linux-2.6.28/arch/x86/kernel/time_64.c 2009-01-11 07:20:06.000000000 -0500
11661 +@@ -34,7 +34,7 @@ unsigned long profile_pc(struct pt_regs
11662 + /* Assume the lock function has either no stack frame or a copy
11663 + of flags from PUSHF
11664 + Eflags always has bits 22 and up cleared unlike kernel addresses. */
11665 +- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
11666 ++ if (!user_mode(regs) && in_lock_functions(pc)) {
11667 + #ifdef CONFIG_FRAME_POINTER
11668 + return *(unsigned long *)(regs->bp + sizeof(long));
11669 + #else
11670 +diff -urNp linux-2.6.28/arch/x86/kernel/tlb_32.c linux-2.6.28/arch/x86/kernel/tlb_32.c
11671 +--- linux-2.6.28/arch/x86/kernel/tlb_32.c 2008-12-24 18:26:37.000000000 -0500
11672 ++++ linux-2.6.28/arch/x86/kernel/tlb_32.c 2009-01-11 07:20:06.000000000 -0500
11673 +@@ -5,7 +5,7 @@
11674 + #include <asm/tlbflush.h>
11675 +
11676 + DEFINE_PER_CPU(struct tlb_state, cpu_tlbstate)
11677 +- ____cacheline_aligned = { &init_mm, 0, };
11678 ++ ____cacheline_aligned = { &init_mm, 0, {0} };
11679 +
11680 + /* must come after the send_IPI functions above for inlining */
11681 + #include <mach_ipi.h>
11682 +diff -urNp linux-2.6.28/arch/x86/kernel/tls.c linux-2.6.28/arch/x86/kernel/tls.c
11683 +--- linux-2.6.28/arch/x86/kernel/tls.c 2008-12-24 18:26:37.000000000 -0500
11684 ++++ linux-2.6.28/arch/x86/kernel/tls.c 2009-01-11 07:20:06.000000000 -0500
11685 +@@ -85,6 +85,11 @@ int do_set_thread_area(struct task_struc
11686 + if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
11687 + return -EINVAL;
11688 +
11689 ++#ifdef CONFIG_PAX_SEGMEXEC
11690 ++ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
11691 ++ return -EINVAL;
11692 ++#endif
11693 ++
11694 + set_tls_desc(p, idx, &info, 1);
11695 +
11696 + return 0;
11697 +diff -urNp linux-2.6.28/arch/x86/kernel/traps.c linux-2.6.28/arch/x86/kernel/traps.c
11698 +--- linux-2.6.28/arch/x86/kernel/traps.c 2008-12-24 18:26:37.000000000 -0500
11699 ++++ linux-2.6.28/arch/x86/kernel/traps.c 2009-01-11 07:20:06.000000000 -0500
11700 +@@ -79,14 +79,6 @@ asmlinkage int system_call(void);
11701 +
11702 + /* Do we ignore FPU interrupts ? */
11703 + char ignore_fpu_irq;
11704 +-
11705 +-/*
11706 +- * The IDT has to be page-aligned to simplify the Pentium
11707 +- * F0 0F bug workaround.. We have a special link segment
11708 +- * for this.
11709 +- */
11710 +-gate_desc idt_table[256]
11711 +- __attribute__((__section__(".data.idt"))) = { { { { 0, 0 } } }, };
11712 + #endif
11713 +
11714 + static int ignore_nmis;
11715 +@@ -115,7 +107,7 @@ static inline void preempt_conditional_c
11716 + static inline void
11717 + die_if_kernel(const char *str, struct pt_regs *regs, long err)
11718 + {
11719 +- if (!user_mode_vm(regs))
11720 ++ if (!user_mode(regs))
11721 + die(str, regs, err);
11722 + }
11723 +
11724 +@@ -132,7 +124,7 @@ static int lazy_iobitmap_copy(void)
11725 + int cpu;
11726 +
11727 + cpu = get_cpu();
11728 +- tss = &per_cpu(init_tss, cpu);
11729 ++ tss = init_tss + cpu;
11730 + thread = &current->thread;
11731 +
11732 + if (tss->x86_tss.io_bitmap_base == INVALID_IO_BITMAP_OFFSET_LAZY &&
11733 +@@ -168,7 +160,7 @@ do_trap(int trapnr, int signr, char *str
11734 + struct task_struct *tsk = current;
11735 +
11736 + #ifdef CONFIG_X86_32
11737 +- if (regs->flags & X86_VM_MASK) {
11738 ++ if (v8086_mode(regs)) {
11739 + /*
11740 + * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
11741 + * On nmi (interrupt 2), do_trap should not be called.
11742 +@@ -179,7 +171,7 @@ do_trap(int trapnr, int signr, char *str
11743 + }
11744 + #endif
11745 +
11746 +- if (!user_mode(regs))
11747 ++ if (!user_mode_novm(regs))
11748 + goto kernel_trap;
11749 +
11750 + #ifdef CONFIG_X86_32
11751 +@@ -221,6 +213,12 @@ kernel_trap:
11752 + tsk->thread.trap_no = trapnr;
11753 + die(str, regs, error_code);
11754 + }
11755 ++
11756 ++#ifdef CONFIG_PAX_REFCOUNT
11757 ++ if (trapnr == 4)
11758 ++ pax_report_refcount_overflow(regs);
11759 ++#endif
11760 ++
11761 + return;
11762 +
11763 + #ifdef CONFIG_X86_32
11764 +@@ -312,14 +310,30 @@ do_general_protection(struct pt_regs *re
11765 + return;
11766 + }
11767 +
11768 +- if (regs->flags & X86_VM_MASK)
11769 ++ if (v8086_mode(regs))
11770 + goto gp_in_vm86;
11771 + #endif
11772 +
11773 + tsk = current;
11774 +- if (!user_mode(regs))
11775 ++ if (!user_mode_novm(regs))
11776 + goto gp_in_kernel;
11777 +
11778 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11779 ++ if (!nx_enabled && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
11780 ++ struct mm_struct *mm = tsk->mm;
11781 ++ unsigned long limit;
11782 ++
11783 ++ down_write(&mm->mmap_sem);
11784 ++ limit = mm->context.user_cs_limit;
11785 ++ if (limit < TASK_SIZE) {
11786 ++ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
11787 ++ up_write(&mm->mmap_sem);
11788 ++ return;
11789 ++ }
11790 ++ up_write(&mm->mmap_sem);
11791 ++ }
11792 ++#endif
11793 ++
11794 + tsk->thread.error_code = error_code;
11795 + tsk->thread.trap_no = 13;
11796 +
11797 +@@ -352,6 +366,13 @@ gp_in_kernel:
11798 + if (notify_die(DIE_GPF, "general protection fault", regs,
11799 + error_code, 13, SIGSEGV) == NOTIFY_STOP)
11800 + return;
11801 ++
11802 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
11803 ++ if ((regs->cs & 0xFFFF) == __KERNEL_CS)
11804 ++ die("PAX: suspicious general protection fault", regs, error_code);
11805 ++ else
11806 ++#endif
11807 ++
11808 + die("general protection fault", regs, error_code);
11809 + }
11810 +
11811 +@@ -598,7 +619,7 @@ dotraplinkage void __kprobes do_debug(st
11812 + }
11813 +
11814 + #ifdef CONFIG_X86_32
11815 +- if (regs->flags & X86_VM_MASK)
11816 ++ if (v8086_mode(regs))
11817 + goto debug_vm86;
11818 + #endif
11819 +
11820 +@@ -610,7 +631,7 @@ dotraplinkage void __kprobes do_debug(st
11821 + * kernel space (but re-enable TF when returning to user mode).
11822 + */
11823 + if (condition & DR_STEP) {
11824 +- if (!user_mode(regs))
11825 ++ if (!user_mode_novm(regs))
11826 + goto clear_TF_reenable;
11827 + }
11828 +
11829 +@@ -800,7 +821,7 @@ do_simd_coprocessor_error(struct pt_regs
11830 + * Handle strange cache flush from user space exception
11831 + * in all other cases. This is undocumented behaviour.
11832 + */
11833 +- if (regs->flags & X86_VM_MASK) {
11834 ++ if (v8086_mode(regs)) {
11835 + handle_vm86_fault((struct kernel_vm86_regs *)regs, error_code);
11836 + return;
11837 + }
11838 +@@ -829,19 +850,14 @@ do_spurious_interrupt_bug(struct pt_regs
11839 + #ifdef CONFIG_X86_32
11840 + unsigned long patch_espfix_desc(unsigned long uesp, unsigned long kesp)
11841 + {
11842 +- struct desc_struct *gdt = get_cpu_gdt_table(smp_processor_id());
11843 + unsigned long base = (kesp - uesp) & -THREAD_SIZE;
11844 + unsigned long new_kesp = kesp - base;
11845 + unsigned long lim_pages = (new_kesp | (THREAD_SIZE - 1)) >> PAGE_SHIFT;
11846 +- __u64 desc = *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS];
11847 ++ struct desc_struct ss;
11848 +
11849 + /* Set up base for espfix segment */
11850 +- desc &= 0x00f0ff0000000000ULL;
11851 +- desc |= ((((__u64)base) << 16) & 0x000000ffffff0000ULL) |
11852 +- ((((__u64)base) << 32) & 0xff00000000000000ULL) |
11853 +- ((((__u64)lim_pages) << 32) & 0x000f000000000000ULL) |
11854 +- (lim_pages & 0xffff);
11855 +- *(__u64 *)&gdt[GDT_ENTRY_ESPFIX_SS] = desc;
11856 ++ pack_descriptor(&ss, base, lim_pages, 0x93, 0xC);
11857 ++ write_gdt_entry(get_cpu_gdt_table(smp_processor_id()), GDT_ENTRY_ESPFIX_SS, &ss, DESCTYPE_S);
11858 +
11859 + return new_kesp;
11860 + }
11861 +diff -urNp linux-2.6.28/arch/x86/kernel/tsc.c linux-2.6.28/arch/x86/kernel/tsc.c
11862 +--- linux-2.6.28/arch/x86/kernel/tsc.c 2008-12-24 18:26:37.000000000 -0500
11863 ++++ linux-2.6.28/arch/x86/kernel/tsc.c 2009-01-11 07:20:06.000000000 -0500
11864 +@@ -728,7 +728,7 @@ static struct dmi_system_id __initdata b
11865 + DMI_MATCH(DMI_BOARD_NAME, "2635FA0"),
11866 + },
11867 + },
11868 +- {}
11869 ++ { NULL, NULL, {{0, {0}}}, NULL}
11870 + };
11871 +
11872 + /*
11873 +diff -urNp linux-2.6.28/arch/x86/kernel/vm86_32.c linux-2.6.28/arch/x86/kernel/vm86_32.c
11874 +--- linux-2.6.28/arch/x86/kernel/vm86_32.c 2008-12-24 18:26:37.000000000 -0500
11875 ++++ linux-2.6.28/arch/x86/kernel/vm86_32.c 2009-01-11 07:20:06.000000000 -0500
11876 +@@ -148,7 +148,7 @@ struct pt_regs *save_v86_state(struct ke
11877 + do_exit(SIGSEGV);
11878 + }
11879 +
11880 +- tss = &per_cpu(init_tss, get_cpu());
11881 ++ tss = init_tss + get_cpu();
11882 + current->thread.sp0 = current->thread.saved_sp0;
11883 + current->thread.sysenter_cs = __KERNEL_CS;
11884 + load_sp0(tss, &current->thread);
11885 +@@ -325,7 +325,7 @@ static void do_sys_vm86(struct kernel_vm
11886 + tsk->thread.saved_fs = info->regs32->fs;
11887 + savesegment(gs, tsk->thread.saved_gs);
11888 +
11889 +- tss = &per_cpu(init_tss, get_cpu());
11890 ++ tss = init_tss + get_cpu();
11891 + tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
11892 + if (cpu_has_sep)
11893 + tsk->thread.sysenter_cs = 0;
11894 +diff -urNp linux-2.6.28/arch/x86/kernel/vmi_32.c linux-2.6.28/arch/x86/kernel/vmi_32.c
11895 +--- linux-2.6.28/arch/x86/kernel/vmi_32.c 2008-12-24 18:26:37.000000000 -0500
11896 ++++ linux-2.6.28/arch/x86/kernel/vmi_32.c 2009-01-11 07:20:06.000000000 -0500
11897 +@@ -102,18 +102,43 @@ static unsigned patch_internal(int call,
11898 + {
11899 + u64 reloc;
11900 + struct vmi_relocation_info *const rel = (struct vmi_relocation_info *)&reloc;
11901 ++
11902 ++#ifdef CONFIG_PAX_KERNEXEC
11903 ++ unsigned long cr0;
11904 ++#endif
11905 ++
11906 + reloc = call_vrom_long_func(vmi_rom, get_reloc, call);
11907 + switch(rel->type) {
11908 + case VMI_RELOCATION_CALL_REL:
11909 + BUG_ON(len < 5);
11910 ++
11911 ++#ifdef CONFIG_PAX_KERNEXEC
11912 ++ pax_open_kernel(cr0);
11913 ++#endif
11914 ++
11915 + *(char *)insnbuf = MNEM_CALL;
11916 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
11917 ++
11918 ++#ifdef CONFIG_PAX_KERNEXEC
11919 ++ pax_close_kernel(cr0);
11920 ++#endif
11921 ++
11922 + return 5;
11923 +
11924 + case VMI_RELOCATION_JUMP_REL:
11925 + BUG_ON(len < 5);
11926 ++
11927 ++#ifdef CONFIG_PAX_KERNEXEC
11928 ++ pax_open_kernel(cr0);
11929 ++#endif
11930 ++
11931 + *(char *)insnbuf = MNEM_JMP;
11932 + patch_offset(insnbuf, ip, (unsigned long)rel->eip);
11933 ++
11934 ++#ifdef CONFIG_PAX_KERNEXEC
11935 ++ pax_close_kernel(cr0);
11936 ++#endif
11937 ++
11938 + return 5;
11939 +
11940 + case VMI_RELOCATION_NOP:
11941 +@@ -516,14 +541,14 @@ static void vmi_set_pud(pud_t *pudp, pud
11942 +
11943 + static void vmi_pte_clear(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
11944 + {
11945 +- const pte_t pte = { .pte = 0 };
11946 ++ const pte_t pte = __pte(0ULL);
11947 + vmi_check_page_type(__pa(ptep) >> PAGE_SHIFT, VMI_PAGE_PTE);
11948 + vmi_ops.set_pte(pte, ptep, vmi_flags_addr(mm, addr, VMI_PAGE_PT, 0));
11949 + }
11950 +
11951 + static void vmi_pmd_clear(pmd_t *pmd)
11952 + {
11953 +- const pte_t pte = { .pte = 0 };
11954 ++ const pte_t pte = __pte(0ULL);
11955 + vmi_check_page_type(__pa(pmd) >> PAGE_SHIFT, VMI_PAGE_PMD);
11956 + vmi_ops.set_pte(pte, (pte_t *)pmd, VMI_PAGE_PD);
11957 + }
11958 +@@ -552,8 +577,8 @@ vmi_startup_ipi_hook(int phys_apicid, un
11959 + ap.ss = __KERNEL_DS;
11960 + ap.esp = (unsigned long) start_esp;
11961 +
11962 +- ap.ds = __USER_DS;
11963 +- ap.es = __USER_DS;
11964 ++ ap.ds = __KERNEL_DS;
11965 ++ ap.es = __KERNEL_DS;
11966 + ap.fs = __KERNEL_PERCPU;
11967 + ap.gs = 0;
11968 +
11969 +@@ -748,12 +773,20 @@ static inline int __init activate_vmi(vo
11970 + u64 reloc;
11971 + const struct vmi_relocation_info *rel = (struct vmi_relocation_info *)&reloc;
11972 +
11973 ++#ifdef CONFIG_PAX_KERNEXEC
11974 ++ unsigned long cr0;
11975 ++#endif
11976 ++
11977 + if (call_vrom_func(vmi_rom, vmi_init) != 0) {
11978 + printk(KERN_ERR "VMI ROM failed to initialize!");
11979 + return 0;
11980 + }
11981 + savesegment(cs, kernel_cs);
11982 +
11983 ++#ifdef CONFIG_PAX_KERNEXEC
11984 ++ pax_open_kernel(cr0);
11985 ++#endif
11986 ++
11987 + pv_info.paravirt_enabled = 1;
11988 + pv_info.kernel_rpl = kernel_cs & SEGMENT_RPL_MASK;
11989 + pv_info.name = "vmi";
11990 +@@ -943,6 +976,10 @@ static inline int __init activate_vmi(vo
11991 +
11992 + para_fill(pv_irq_ops.safe_halt, Halt);
11993 +
11994 ++#ifdef CONFIG_PAX_KERNEXEC
11995 ++ pax_close_kernel(cr0);
11996 ++#endif
11997 ++
11998 + /*
11999 + * Alternative instruction rewriting doesn't happen soon enough
12000 + * to convert VMI_IRET to a call instead of a jump; so we have
12001 +diff -urNp linux-2.6.28/arch/x86/kernel/vmlinux_32.lds.S linux-2.6.28/arch/x86/kernel/vmlinux_32.lds.S
12002 +--- linux-2.6.28/arch/x86/kernel/vmlinux_32.lds.S 2008-12-24 18:26:37.000000000 -0500
12003 ++++ linux-2.6.28/arch/x86/kernel/vmlinux_32.lds.S 2009-01-11 07:20:06.000000000 -0500
12004 +@@ -15,6 +15,20 @@
12005 + #include <asm/page.h>
12006 + #include <asm/cache.h>
12007 + #include <asm/boot.h>
12008 ++#include <asm/segment.h>
12009 ++
12010 ++#ifdef CONFIG_X86_PAE
12011 ++#define PMD_SHIFT 21
12012 ++#else
12013 ++#define PMD_SHIFT 22
12014 ++#endif
12015 ++#define PMD_SIZE (1 << PMD_SHIFT)
12016 ++
12017 ++#ifdef CONFIG_PAX_KERNEXEC
12018 ++#define __KERNEL_TEXT_OFFSET (__PAGE_OFFSET + (((____LOAD_PHYSICAL_ADDR + 2*(PMD_SIZE - 1)) - 1) & ~(PMD_SIZE - 1)))
12019 ++#else
12020 ++#define __KERNEL_TEXT_OFFSET 0
12021 ++#endif
12022 +
12023 + OUTPUT_FORMAT("elf32-i386", "elf32-i386", "elf32-i386")
12024 + OUTPUT_ARCH(i386)
12025 +@@ -22,81 +36,23 @@ ENTRY(phys_startup_32)
12026 + jiffies = jiffies_64;
12027 +
12028 + PHDRS {
12029 +- text PT_LOAD FLAGS(5); /* R_E */
12030 +- data PT_LOAD FLAGS(7); /* RWE */
12031 +- note PT_NOTE FLAGS(0); /* ___ */
12032 ++ initdata PT_LOAD FLAGS(6); /* RW_ */
12033 ++ percpu PT_LOAD FLAGS(6); /* RW_ */
12034 ++ inittext PT_LOAD FLAGS(5); /* R_E */
12035 ++ text PT_LOAD FLAGS(5); /* R_E */
12036 ++ rodata PT_LOAD FLAGS(4); /* R__ */
12037 ++ data PT_LOAD FLAGS(6); /* RW_ */
12038 ++ note PT_NOTE FLAGS(0); /* ___ */
12039 + }
12040 + SECTIONS
12041 + {
12042 +- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
12043 +- phys_startup_32 = startup_32 - LOAD_OFFSET;
12044 ++ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
12045 +
12046 +- .text.head : AT(ADDR(.text.head) - LOAD_OFFSET) {
12047 +- _text = .; /* Text and read-only data */
12048 +- *(.text.head)
12049 +- } :text = 0x9090
12050 +-
12051 +- /* read-only */
12052 +- .text : AT(ADDR(.text) - LOAD_OFFSET) {
12053 +- . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
12054 +- *(.text.page_aligned)
12055 +- TEXT_TEXT
12056 +- SCHED_TEXT
12057 +- LOCK_TEXT
12058 +- KPROBES_TEXT
12059 +- *(.fixup)
12060 +- *(.gnu.warning)
12061 +- _etext = .; /* End of text section */
12062 +- } :text = 0x9090
12063 +-
12064 +- NOTES :text :note
12065 +-
12066 +- . = ALIGN(16); /* Exception table */
12067 +- __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
12068 +- __start___ex_table = .;
12069 +- *(__ex_table)
12070 +- __stop___ex_table = .;
12071 +- } :text = 0x9090
12072 +-
12073 +- RODATA
12074 +-
12075 +- /* writeable */
12076 +- . = ALIGN(PAGE_SIZE);
12077 +- .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
12078 +- DATA_DATA
12079 +- CONSTRUCTORS
12080 +- } :data
12081 +-
12082 +- . = ALIGN(PAGE_SIZE);
12083 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
12084 +- __nosave_begin = .;
12085 +- *(.data.nosave)
12086 +- . = ALIGN(PAGE_SIZE);
12087 +- __nosave_end = .;
12088 +- }
12089 +-
12090 +- . = ALIGN(PAGE_SIZE);
12091 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
12092 +- *(.data.page_aligned)
12093 +- *(.data.idt)
12094 +- }
12095 +-
12096 +- . = ALIGN(32);
12097 +- .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
12098 +- *(.data.cacheline_aligned)
12099 +- }
12100 +-
12101 +- /* rarely changed data like cpu maps */
12102 +- . = ALIGN(32);
12103 +- .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
12104 +- *(.data.read_mostly)
12105 +- _edata = .; /* End of data section */
12106 +- }
12107 +-
12108 +- . = ALIGN(THREAD_SIZE); /* init_task */
12109 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
12110 +- *(.data.init_task)
12111 +- }
12112 ++ .text.startup : AT(ADDR(.text.startup) - LOAD_OFFSET) {
12113 ++ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET;
12114 ++ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
12115 ++ *(.text.startup)
12116 ++ } :initdata
12117 +
12118 + /* might get freed after init */
12119 + . = ALIGN(PAGE_SIZE);
12120 +@@ -114,14 +70,8 @@ SECTIONS
12121 + . = ALIGN(PAGE_SIZE);
12122 +
12123 + /* will be freed after init */
12124 +- . = ALIGN(PAGE_SIZE); /* Init code and data */
12125 +- .init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
12126 +- __init_begin = .;
12127 +- _sinittext = .;
12128 +- INIT_TEXT
12129 +- _einittext = .;
12130 +- }
12131 + .init.data : AT(ADDR(.init.data) - LOAD_OFFSET) {
12132 ++ __init_begin = .;
12133 + INIT_DATA
12134 + }
12135 + . = ALIGN(16);
12136 +@@ -161,11 +111,6 @@ SECTIONS
12137 + *(.parainstructions)
12138 + __parainstructions_end = .;
12139 + }
12140 +- /* .exit.text is discard at runtime, not link time, to deal with references
12141 +- from .altinstructions and .eh_frame */
12142 +- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
12143 +- EXIT_TEXT
12144 +- }
12145 + .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
12146 + EXIT_DATA
12147 + }
12148 +@@ -178,18 +123,138 @@ SECTIONS
12149 + }
12150 + #endif
12151 + . = ALIGN(PAGE_SIZE);
12152 +- .data.percpu : AT(ADDR(.data.percpu) - LOAD_OFFSET) {
12153 +- __per_cpu_start = .;
12154 +- *(.data.percpu.page_aligned)
12155 ++ per_cpu_start = .;
12156 ++ .data.percpu (0) : AT(ADDR(.data.percpu) - LOAD_OFFSET + per_cpu_start) {
12157 ++ __per_cpu_start = . + per_cpu_start;
12158 ++ LONG(0)
12159 + *(.data.percpu)
12160 + *(.data.percpu.shared_aligned)
12161 +- __per_cpu_end = .;
12162 +- }
12163 ++ . = ALIGN(PAGE_SIZE);
12164 ++ *(.data.percpu.page_aligned)
12165 ++ __per_cpu_end = . + per_cpu_start;
12166 ++ } :percpu
12167 ++ . += per_cpu_start;
12168 + . = ALIGN(PAGE_SIZE);
12169 + /* freed after init ends here */
12170 +
12171 ++ . = ALIGN(PAGE_SIZE); /* Init code and data */
12172 ++ .init.text (. - __KERNEL_TEXT_OFFSET) : AT(ADDR(.init.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
12173 ++ _sinittext = .;
12174 ++ INIT_TEXT
12175 ++ _einittext = .;
12176 ++ } :inittext
12177 ++
12178 ++ /* .exit.text is discard at runtime, not link time, to deal with references
12179 ++ from .altinstructions and .eh_frame */
12180 ++ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
12181 ++ EXIT_TEXT
12182 ++ }
12183 ++
12184 ++ .filler : AT(ADDR(.filler) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
12185 ++ BYTE(0)
12186 ++ . = ALIGN(2*PMD_SIZE) - 1;
12187 ++ }
12188 ++
12189 ++ /* freed after init ends here */
12190 ++
12191 ++ .text.head : AT(ADDR(.text.head) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
12192 ++ __init_end = . + __KERNEL_TEXT_OFFSET;
12193 ++ KERNEL_TEXT_OFFSET = . + __KERNEL_TEXT_OFFSET;
12194 ++ _text = .; /* Text and read-only data */
12195 ++ *(.text.head)
12196 ++ } :text = 0x9090
12197 ++
12198 ++ /* read-only */
12199 ++ .text : AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
12200 ++ . = ALIGN(PAGE_SIZE); /* not really needed, already page aligned */
12201 ++ *(.text.page_aligned)
12202 ++ TEXT_TEXT
12203 ++ SCHED_TEXT
12204 ++ LOCK_TEXT
12205 ++ KPROBES_TEXT
12206 ++ *(.fixup)
12207 ++ *(.gnu.warning)
12208 ++ _etext = .; /* End of text section */
12209 ++ } :text = 0x9090
12210 ++
12211 ++ . += __KERNEL_TEXT_OFFSET;
12212 ++
12213 ++ . = ALIGN(4096); /* Exception table */
12214 ++ __ex_table : AT(ADDR(__ex_table) - LOAD_OFFSET) {
12215 ++ __start___ex_table = .;
12216 ++ *(__ex_table)
12217 ++ __stop___ex_table = .;
12218 ++ } :rodata
12219 ++
12220 ++ NOTES :rodata :note
12221 ++
12222 ++ RO_DATA(PAGE_SIZE)
12223 ++
12224 ++ . = ALIGN(PAGE_SIZE);
12225 ++ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
12226 ++ *(.idt)
12227 ++ . = ALIGN(PAGE_SIZE);
12228 ++ *(.empty_zero_page)
12229 ++ *(.swapper_pg_pmd)
12230 ++ *(.swapper_pg_dir)
12231 ++ }
12232 ++
12233 ++#ifdef CONFIG_PAX_KERNEXEC
12234 ++
12235 ++#ifdef CONFIG_MODULES
12236 ++ . = ALIGN(PAGE_SIZE);
12237 ++ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
12238 ++ MODULES_VADDR = .;
12239 ++ BYTE(0)
12240 ++ . += (6 * 1024 * 1024);
12241 ++ . = ALIGN( PMD_SIZE) - 1;
12242 ++ MODULES_END = .;
12243 ++ }
12244 ++#else
12245 ++ . = ALIGN(PMD_SIZE) - 1;
12246 ++#endif
12247 ++
12248 ++#endif
12249 ++
12250 ++ /* writeable */
12251 ++ . = ALIGN(PAGE_SIZE);
12252 ++ .data : AT(ADDR(.data) - LOAD_OFFSET) { /* Data */
12253 ++ _data = .;
12254 ++ DATA_DATA
12255 ++ CONSTRUCTORS
12256 ++ } :data
12257 ++
12258 ++ . = ALIGN(PAGE_SIZE);
12259 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
12260 ++ __nosave_begin = .;
12261 ++ *(.data.nosave)
12262 ++ . = ALIGN(PAGE_SIZE);
12263 ++ __nosave_end = .;
12264 ++ }
12265 ++
12266 ++ . = ALIGN(PAGE_SIZE);
12267 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
12268 ++ *(.data.page_aligned)
12269 ++ }
12270 ++
12271 ++ . = ALIGN(32);
12272 ++ .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
12273 ++ *(.data.cacheline_aligned)
12274 ++ }
12275 ++
12276 ++ /* rarely changed data like cpu maps */
12277 ++ . = ALIGN(32);
12278 ++ .data.read_mostly : AT(ADDR(.data.read_mostly) - LOAD_OFFSET) {
12279 ++ *(.data.read_mostly)
12280 ++ _edata = .; /* End of data section */
12281 ++ }
12282 ++
12283 ++ . = ALIGN(THREAD_SIZE); /* init_task */
12284 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
12285 ++ *(.data.init_task)
12286 ++ }
12287 ++
12288 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
12289 +- __init_end = .;
12290 + __bss_start = .; /* BSS */
12291 + *(.bss.page_aligned)
12292 + *(.bss)
12293 +diff -urNp linux-2.6.28/arch/x86/kernel/vmlinux_64.lds.S linux-2.6.28/arch/x86/kernel/vmlinux_64.lds.S
12294 +--- linux-2.6.28/arch/x86/kernel/vmlinux_64.lds.S 2008-12-24 18:26:37.000000000 -0500
12295 ++++ linux-2.6.28/arch/x86/kernel/vmlinux_64.lds.S 2009-01-11 07:20:06.000000000 -0500
12296 +@@ -16,7 +16,7 @@ jiffies_64 = jiffies;
12297 + _proxy_pda = 1;
12298 + PHDRS {
12299 + text PT_LOAD FLAGS(5); /* R_E */
12300 +- data PT_LOAD FLAGS(7); /* RWE */
12301 ++ data PT_LOAD FLAGS(6); /* RW_ */
12302 + user PT_LOAD FLAGS(7); /* RWE */
12303 + data.init PT_LOAD FLAGS(7); /* RWE */
12304 + note PT_NOTE FLAGS(0); /* ___ */
12305 +@@ -49,17 +49,20 @@ SECTIONS
12306 + __stop___ex_table = .;
12307 + } :text = 0x9090
12308 +
12309 +- RODATA
12310 ++ RO_DATA(PAGE_SIZE)
12311 +
12312 ++#ifdef CONFIG_PAX_KERNEXEC
12313 ++ . = ALIGN(2*1024*1024); /* Align data segment to PMD size boundary */
12314 ++#else
12315 + . = ALIGN(PAGE_SIZE); /* Align data segment to page size boundary */
12316 ++#endif
12317 + /* Data */
12318 ++ _data = .;
12319 + .data : AT(ADDR(.data) - LOAD_OFFSET) {
12320 + DATA_DATA
12321 + CONSTRUCTORS
12322 + } :data
12323 +
12324 +- _edata = .; /* End of data section */
12325 +-
12326 + . = ALIGN(PAGE_SIZE);
12327 + . = ALIGN(CONFIG_X86_L1_CACHE_BYTES);
12328 + .data.cacheline_aligned : AT(ADDR(.data.cacheline_aligned) - LOAD_OFFSET) {
12329 +@@ -70,9 +73,27 @@ SECTIONS
12330 + *(.data.read_mostly)
12331 + }
12332 +
12333 ++ . = ALIGN(THREAD_SIZE); /* init_task */
12334 ++ .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
12335 ++ *(.data.init_task)
12336 ++ }
12337 ++
12338 ++ . = ALIGN(PAGE_SIZE);
12339 ++ .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
12340 ++ *(.data.page_aligned)
12341 ++ }
12342 ++
12343 ++ . = ALIGN(PAGE_SIZE);
12344 ++ __nosave_begin = .;
12345 ++ .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
12346 ++ . = ALIGN(PAGE_SIZE);
12347 ++ __nosave_end = .;
12348 ++
12349 ++ _edata = .; /* End of data section */
12350 ++
12351 + #define VSYSCALL_ADDR (-10*1024*1024)
12352 +-#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
12353 +-#define VSYSCALL_VIRT_ADDR ((ADDR(.data.read_mostly) + SIZEOF(.data.read_mostly) + 4095) & ~(4095))
12354 ++#define VSYSCALL_PHYS_ADDR ((LOADADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
12355 ++#define VSYSCALL_VIRT_ADDR ((ADDR(.data_nosave) + SIZEOF(.data_nosave) + 4095) & ~(4095))
12356 +
12357 + #define VLOAD_OFFSET (VSYSCALL_ADDR - VSYSCALL_PHYS_ADDR)
12358 + #define VLOAD(x) (ADDR(x) - VLOAD_OFFSET)
12359 +@@ -120,23 +141,13 @@ SECTIONS
12360 + #undef VVIRT_OFFSET
12361 + #undef VVIRT
12362 +
12363 +- . = ALIGN(THREAD_SIZE); /* init_task */
12364 +- .data.init_task : AT(ADDR(.data.init_task) - LOAD_OFFSET) {
12365 +- *(.data.init_task)
12366 +- }:data.init
12367 +-
12368 +- . = ALIGN(PAGE_SIZE);
12369 +- .data.page_aligned : AT(ADDR(.data.page_aligned) - LOAD_OFFSET) {
12370 +- *(.data.page_aligned)
12371 +- }
12372 +-
12373 + /* might get freed after init */
12374 + . = ALIGN(PAGE_SIZE);
12375 + __smp_alt_begin = .;
12376 + __smp_locks = .;
12377 + .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
12378 + *(.smp_locks)
12379 +- }
12380 ++ } :data.init
12381 + __smp_locks_end = .;
12382 + . = ALIGN(PAGE_SIZE);
12383 + __smp_alt_end = .;
12384 +@@ -212,16 +223,11 @@ SECTIONS
12385 + . = ALIGN(PAGE_SIZE);
12386 + __init_end = .;
12387 +
12388 +- . = ALIGN(PAGE_SIZE);
12389 +- __nosave_begin = .;
12390 +- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) { *(.data.nosave) }
12391 +- . = ALIGN(PAGE_SIZE);
12392 +- __nosave_end = .;
12393 +-
12394 + __bss_start = .; /* BSS */
12395 + .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
12396 + *(.bss.page_aligned)
12397 + *(.bss)
12398 ++ . = ALIGN(2*1024*1024);
12399 + }
12400 + __bss_stop = .;
12401 +
12402 +diff -urNp linux-2.6.28/arch/x86/kernel/vsyscall_64.c linux-2.6.28/arch/x86/kernel/vsyscall_64.c
12403 +--- linux-2.6.28/arch/x86/kernel/vsyscall_64.c 2008-12-24 18:26:37.000000000 -0500
12404 ++++ linux-2.6.28/arch/x86/kernel/vsyscall_64.c 2009-01-11 07:20:06.000000000 -0500
12405 +@@ -236,13 +236,13 @@ static ctl_table kernel_table2[] = {
12406 + .data = &vsyscall_gtod_data.sysctl_enabled, .maxlen = sizeof(int),
12407 + .mode = 0644,
12408 + .proc_handler = vsyscall_sysctl_change },
12409 +- {}
12410 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
12411 + };
12412 +
12413 + static ctl_table kernel_root_table2[] = {
12414 + { .ctl_name = CTL_KERN, .procname = "kernel", .mode = 0555,
12415 + .child = kernel_table2 },
12416 +- {}
12417 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
12418 + };
12419 + #endif
12420 +
12421 +diff -urNp linux-2.6.28/arch/x86/kvm/svm.c linux-2.6.28/arch/x86/kvm/svm.c
12422 +--- linux-2.6.28/arch/x86/kvm/svm.c 2008-12-24 18:26:37.000000000 -0500
12423 ++++ linux-2.6.28/arch/x86/kvm/svm.c 2009-01-11 07:20:06.000000000 -0500
12424 +@@ -1505,7 +1505,19 @@ static void reload_tss(struct kvm_vcpu *
12425 + int cpu = raw_smp_processor_id();
12426 +
12427 + struct svm_cpu_data *svm_data = per_cpu(svm_data, cpu);
12428 ++
12429 ++#ifdef CONFIG_PAX_KERNEXEC
12430 ++ unsigned long cr0;
12431 ++
12432 ++ pax_open_kernel(cr0);
12433 ++#endif
12434 ++
12435 + svm_data->tss_desc->type = 9; /* available 32/64-bit TSS */
12436 ++
12437 ++#ifdef CONFIG_PAX_KERNEXEC
12438 ++ pax_close_kernel(cr0);
12439 ++#endif
12440 ++
12441 + load_TR_desc();
12442 + }
12443 +
12444 +diff -urNp linux-2.6.28/arch/x86/kvm/vmx.c linux-2.6.28/arch/x86/kvm/vmx.c
12445 +--- linux-2.6.28/arch/x86/kvm/vmx.c 2008-12-24 18:26:37.000000000 -0500
12446 ++++ linux-2.6.28/arch/x86/kvm/vmx.c 2009-01-11 07:20:06.000000000 -0500
12447 +@@ -122,7 +122,7 @@ static struct vmcs_config {
12448 + u32 vmentry_ctrl;
12449 + } vmcs_config;
12450 +
12451 +-struct vmx_capability {
12452 ++static struct vmx_capability {
12453 + u32 ept;
12454 + u32 vpid;
12455 + } vmx_capability;
12456 +@@ -491,9 +491,23 @@ static void reload_tss(void)
12457 + struct descriptor_table gdt;
12458 + struct desc_struct *descs;
12459 +
12460 ++#ifdef CONFIG_PAX_KERNEXEC
12461 ++ unsigned long cr0;
12462 ++#endif
12463 ++
12464 + kvm_get_gdt(&gdt);
12465 + descs = (void *)gdt.base;
12466 ++
12467 ++#ifdef CONFIG_PAX_KERNEXEC
12468 ++ pax_open_kernel(cr0);
12469 ++#endif
12470 ++
12471 + descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
12472 ++
12473 ++#ifdef CONFIG_PAX_KERNEXEC
12474 ++ pax_close_kernel(cr0);
12475 ++#endif
12476 ++
12477 + load_TR_desc();
12478 + }
12479 +
12480 +@@ -3331,7 +3345,7 @@ static void vmx_vcpu_run(struct kvm_vcpu
12481 + (vmcs_read32(GUEST_INTERRUPTIBILITY_INFO) &
12482 + (GUEST_INTR_STATE_STI | GUEST_INTR_STATE_MOV_SS)) == 0;
12483 +
12484 +- asm("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
12485 ++ asm("mov %0, %%ds; mov %0, %%es" : : "r"(__KERNEL_DS));
12486 + vmx->launched = 1;
12487 +
12488 + intr_info = vmcs_read32(VM_EXIT_INTR_INFO);
12489 +diff -urNp linux-2.6.28/arch/x86/kvm/x86.c linux-2.6.28/arch/x86/kvm/x86.c
12490 +--- linux-2.6.28/arch/x86/kvm/x86.c 2008-12-24 18:26:37.000000000 -0500
12491 ++++ linux-2.6.28/arch/x86/kvm/x86.c 2009-01-11 07:20:06.000000000 -0500
12492 +@@ -72,37 +72,37 @@ struct kvm_x86_ops *kvm_x86_ops;
12493 + EXPORT_SYMBOL_GPL(kvm_x86_ops);
12494 +
12495 + struct kvm_stats_debugfs_item debugfs_entries[] = {
12496 +- { "pf_fixed", VCPU_STAT(pf_fixed) },
12497 +- { "pf_guest", VCPU_STAT(pf_guest) },
12498 +- { "tlb_flush", VCPU_STAT(tlb_flush) },
12499 +- { "invlpg", VCPU_STAT(invlpg) },
12500 +- { "exits", VCPU_STAT(exits) },
12501 +- { "io_exits", VCPU_STAT(io_exits) },
12502 +- { "mmio_exits", VCPU_STAT(mmio_exits) },
12503 +- { "signal_exits", VCPU_STAT(signal_exits) },
12504 +- { "irq_window", VCPU_STAT(irq_window_exits) },
12505 +- { "nmi_window", VCPU_STAT(nmi_window_exits) },
12506 +- { "halt_exits", VCPU_STAT(halt_exits) },
12507 +- { "halt_wakeup", VCPU_STAT(halt_wakeup) },
12508 +- { "hypercalls", VCPU_STAT(hypercalls) },
12509 +- { "request_irq", VCPU_STAT(request_irq_exits) },
12510 +- { "irq_exits", VCPU_STAT(irq_exits) },
12511 +- { "host_state_reload", VCPU_STAT(host_state_reload) },
12512 +- { "efer_reload", VCPU_STAT(efer_reload) },
12513 +- { "fpu_reload", VCPU_STAT(fpu_reload) },
12514 +- { "insn_emulation", VCPU_STAT(insn_emulation) },
12515 +- { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail) },
12516 +- { "irq_injections", VCPU_STAT(irq_injections) },
12517 +- { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped) },
12518 +- { "mmu_pte_write", VM_STAT(mmu_pte_write) },
12519 +- { "mmu_pte_updated", VM_STAT(mmu_pte_updated) },
12520 +- { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped) },
12521 +- { "mmu_flooded", VM_STAT(mmu_flooded) },
12522 +- { "mmu_recycled", VM_STAT(mmu_recycled) },
12523 +- { "mmu_cache_miss", VM_STAT(mmu_cache_miss) },
12524 +- { "mmu_unsync", VM_STAT(mmu_unsync) },
12525 +- { "remote_tlb_flush", VM_STAT(remote_tlb_flush) },
12526 +- { "largepages", VM_STAT(lpages) },
12527 ++ { "pf_fixed", VCPU_STAT(pf_fixed), NULL },
12528 ++ { "pf_guest", VCPU_STAT(pf_guest), NULL },
12529 ++ { "tlb_flush", VCPU_STAT(tlb_flush), NULL },
12530 ++ { "invlpg", VCPU_STAT(invlpg), NULL },
12531 ++ { "exits", VCPU_STAT(exits), NULL },
12532 ++ { "io_exits", VCPU_STAT(io_exits), NULL },
12533 ++ { "mmio_exits", VCPU_STAT(mmio_exits), NULL },
12534 ++ { "signal_exits", VCPU_STAT(signal_exits), NULL },
12535 ++ { "irq_window", VCPU_STAT(irq_window_exits), NULL },
12536 ++ { "nmi_window", VCPU_STAT(nmi_window_exits), NULL },
12537 ++ { "halt_exits", VCPU_STAT(halt_exits), NULL },
12538 ++ { "halt_wakeup", VCPU_STAT(halt_wakeup), NULL },
12539 ++ { "hypercalls", VCPU_STAT(hypercalls), NULL },
12540 ++ { "request_irq", VCPU_STAT(request_irq_exits), NULL },
12541 ++ { "irq_exits", VCPU_STAT(irq_exits), NULL },
12542 ++ { "host_state_reload", VCPU_STAT(host_state_reload), NULL },
12543 ++ { "efer_reload", VCPU_STAT(efer_reload), NULL },
12544 ++ { "fpu_reload", VCPU_STAT(fpu_reload), NULL },
12545 ++ { "insn_emulation", VCPU_STAT(insn_emulation), NULL },
12546 ++ { "insn_emulation_fail", VCPU_STAT(insn_emulation_fail), NULL },
12547 ++ { "irq_injections", VCPU_STAT(irq_injections), NULL },
12548 ++ { "mmu_shadow_zapped", VM_STAT(mmu_shadow_zapped), NULL },
12549 ++ { "mmu_pte_write", VM_STAT(mmu_pte_write), NULL },
12550 ++ { "mmu_pte_updated", VM_STAT(mmu_pte_updated), NULL },
12551 ++ { "mmu_pde_zapped", VM_STAT(mmu_pde_zapped), NULL },
12552 ++ { "mmu_flooded", VM_STAT(mmu_flooded), NULL },
12553 ++ { "mmu_recycled", VM_STAT(mmu_recycled), NULL },
12554 ++ { "mmu_cache_miss", VM_STAT(mmu_cache_miss), NULL },
12555 ++ { "mmu_unsync", VM_STAT(mmu_unsync), NULL },
12556 ++ { "remote_tlb_flush", VM_STAT(remote_tlb_flush), NULL },
12557 ++ { "largepages", VM_STAT(lpages), NULL },
12558 + { NULL }
12559 + };
12560 +
12561 +@@ -1304,7 +1304,7 @@ static int kvm_vcpu_ioctl_set_lapic(stru
12562 + static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
12563 + struct kvm_interrupt *irq)
12564 + {
12565 +- if (irq->irq < 0 || irq->irq >= 256)
12566 ++ if (irq->irq >= 256)
12567 + return -EINVAL;
12568 + if (irqchip_in_kernel(vcpu->kvm))
12569 + return -ENXIO;
12570 +diff -urNp linux-2.6.28/arch/x86/lib/checksum_32.S linux-2.6.28/arch/x86/lib/checksum_32.S
12571 +--- linux-2.6.28/arch/x86/lib/checksum_32.S 2008-12-24 18:26:37.000000000 -0500
12572 ++++ linux-2.6.28/arch/x86/lib/checksum_32.S 2009-01-11 07:20:06.000000000 -0500
12573 +@@ -28,7 +28,8 @@
12574 + #include <linux/linkage.h>
12575 + #include <asm/dwarf2.h>
12576 + #include <asm/errno.h>
12577 +-
12578 ++#include <asm/segment.h>
12579 ++
12580 + /*
12581 + * computes a partial checksum, e.g. for TCP/UDP fragments
12582 + */
12583 +@@ -304,9 +305,22 @@ unsigned int csum_partial_copy_generic (
12584 +
12585 + #define ARGBASE 16
12586 + #define FP 12
12587 +-
12588 +-ENTRY(csum_partial_copy_generic)
12589 ++
12590 ++ENTRY(csum_partial_copy_generic_to_user)
12591 + CFI_STARTPROC
12592 ++ pushl $(__USER_DS)
12593 ++ CFI_ADJUST_CFA_OFFSET 4
12594 ++ popl %es
12595 ++ CFI_ADJUST_CFA_OFFSET -4
12596 ++ jmp csum_partial_copy_generic
12597 ++
12598 ++ENTRY(csum_partial_copy_generic_from_user)
12599 ++ pushl $(__USER_DS)
12600 ++ CFI_ADJUST_CFA_OFFSET 4
12601 ++ popl %ds
12602 ++ CFI_ADJUST_CFA_OFFSET -4
12603 ++
12604 ++ENTRY(csum_partial_copy_generic)
12605 + subl $4,%esp
12606 + CFI_ADJUST_CFA_OFFSET 4
12607 + pushl %edi
12608 +@@ -331,7 +345,7 @@ ENTRY(csum_partial_copy_generic)
12609 + jmp 4f
12610 + SRC(1: movw (%esi), %bx )
12611 + addl $2, %esi
12612 +-DST( movw %bx, (%edi) )
12613 ++DST( movw %bx, %es:(%edi) )
12614 + addl $2, %edi
12615 + addw %bx, %ax
12616 + adcl $0, %eax
12617 +@@ -343,30 +357,30 @@ DST( movw %bx, (%edi) )
12618 + SRC(1: movl (%esi), %ebx )
12619 + SRC( movl 4(%esi), %edx )
12620 + adcl %ebx, %eax
12621 +-DST( movl %ebx, (%edi) )
12622 ++DST( movl %ebx, %es:(%edi) )
12623 + adcl %edx, %eax
12624 +-DST( movl %edx, 4(%edi) )
12625 ++DST( movl %edx, %es:4(%edi) )
12626 +
12627 + SRC( movl 8(%esi), %ebx )
12628 + SRC( movl 12(%esi), %edx )
12629 + adcl %ebx, %eax
12630 +-DST( movl %ebx, 8(%edi) )
12631 ++DST( movl %ebx, %es:8(%edi) )
12632 + adcl %edx, %eax
12633 +-DST( movl %edx, 12(%edi) )
12634 ++DST( movl %edx, %es:12(%edi) )
12635 +
12636 + SRC( movl 16(%esi), %ebx )
12637 + SRC( movl 20(%esi), %edx )
12638 + adcl %ebx, %eax
12639 +-DST( movl %ebx, 16(%edi) )
12640 ++DST( movl %ebx, %es:16(%edi) )
12641 + adcl %edx, %eax
12642 +-DST( movl %edx, 20(%edi) )
12643 ++DST( movl %edx, %es:20(%edi) )
12644 +
12645 + SRC( movl 24(%esi), %ebx )
12646 + SRC( movl 28(%esi), %edx )
12647 + adcl %ebx, %eax
12648 +-DST( movl %ebx, 24(%edi) )
12649 ++DST( movl %ebx, %es:24(%edi) )
12650 + adcl %edx, %eax
12651 +-DST( movl %edx, 28(%edi) )
12652 ++DST( movl %edx, %es:28(%edi) )
12653 +
12654 + lea 32(%esi), %esi
12655 + lea 32(%edi), %edi
12656 +@@ -380,7 +394,7 @@ DST( movl %edx, 28(%edi) )
12657 + shrl $2, %edx # This clears CF
12658 + SRC(3: movl (%esi), %ebx )
12659 + adcl %ebx, %eax
12660 +-DST( movl %ebx, (%edi) )
12661 ++DST( movl %ebx, %es:(%edi) )
12662 + lea 4(%esi), %esi
12663 + lea 4(%edi), %edi
12664 + dec %edx
12665 +@@ -392,12 +406,12 @@ DST( movl %ebx, (%edi) )
12666 + jb 5f
12667 + SRC( movw (%esi), %cx )
12668 + leal 2(%esi), %esi
12669 +-DST( movw %cx, (%edi) )
12670 ++DST( movw %cx, %es:(%edi) )
12671 + leal 2(%edi), %edi
12672 + je 6f
12673 + shll $16,%ecx
12674 + SRC(5: movb (%esi), %cl )
12675 +-DST( movb %cl, (%edi) )
12676 ++DST( movb %cl, %es:(%edi) )
12677 + 6: addl %ecx, %eax
12678 + adcl $0, %eax
12679 + 7:
12680 +@@ -408,7 +422,7 @@ DST( movb %cl, (%edi) )
12681 +
12682 + 6001:
12683 + movl ARGBASE+20(%esp), %ebx # src_err_ptr
12684 +- movl $-EFAULT, (%ebx)
12685 ++ movl $-EFAULT, %ss:(%ebx)
12686 +
12687 + # zero the complete destination - computing the rest
12688 + # is too much work
12689 +@@ -421,11 +435,19 @@ DST( movb %cl, (%edi) )
12690 +
12691 + 6002:
12692 + movl ARGBASE+24(%esp), %ebx # dst_err_ptr
12693 +- movl $-EFAULT,(%ebx)
12694 ++ movl $-EFAULT,%ss:(%ebx)
12695 + jmp 5000b
12696 +
12697 + .previous
12698 +
12699 ++ pushl %ss
12700 ++ CFI_ADJUST_CFA_OFFSET 4
12701 ++ popl %ds
12702 ++ CFI_ADJUST_CFA_OFFSET -4
12703 ++ pushl %ss
12704 ++ CFI_ADJUST_CFA_OFFSET 4
12705 ++ popl %es
12706 ++ CFI_ADJUST_CFA_OFFSET -4
12707 + popl %ebx
12708 + CFI_ADJUST_CFA_OFFSET -4
12709 + CFI_RESTORE ebx
12710 +@@ -439,26 +461,41 @@ DST( movb %cl, (%edi) )
12711 + CFI_ADJUST_CFA_OFFSET -4
12712 + ret
12713 + CFI_ENDPROC
12714 +-ENDPROC(csum_partial_copy_generic)
12715 ++ENDPROC(csum_partial_copy_generic_to_user)
12716 +
12717 + #else
12718 +
12719 + /* Version for PentiumII/PPro */
12720 +
12721 + #define ROUND1(x) \
12722 ++ nop; nop; nop; \
12723 + SRC(movl x(%esi), %ebx ) ; \
12724 + addl %ebx, %eax ; \
12725 +- DST(movl %ebx, x(%edi) ) ;
12726 ++ DST(movl %ebx, %es:x(%edi)) ;
12727 +
12728 + #define ROUND(x) \
12729 ++ nop; nop; nop; \
12730 + SRC(movl x(%esi), %ebx ) ; \
12731 + adcl %ebx, %eax ; \
12732 +- DST(movl %ebx, x(%edi) ) ;
12733 ++ DST(movl %ebx, %es:x(%edi)) ;
12734 +
12735 + #define ARGBASE 12
12736 +-
12737 +-ENTRY(csum_partial_copy_generic)
12738 ++
12739 ++ENTRY(csum_partial_copy_generic_to_user)
12740 + CFI_STARTPROC
12741 ++ pushl $(__USER_DS)
12742 ++ CFI_ADJUST_CFA_OFFSET 4
12743 ++ popl %es
12744 ++ CFI_ADJUST_CFA_OFFSET -4
12745 ++ jmp csum_partial_copy_generic
12746 ++
12747 ++ENTRY(csum_partial_copy_generic_from_user)
12748 ++ pushl $(__USER_DS)
12749 ++ CFI_ADJUST_CFA_OFFSET 4
12750 ++ popl %ds
12751 ++ CFI_ADJUST_CFA_OFFSET -4
12752 ++
12753 ++ENTRY(csum_partial_copy_generic)
12754 + pushl %ebx
12755 + CFI_ADJUST_CFA_OFFSET 4
12756 + CFI_REL_OFFSET ebx, 0
12757 +@@ -482,7 +519,7 @@ ENTRY(csum_partial_copy_generic)
12758 + subl %ebx, %edi
12759 + lea -1(%esi),%edx
12760 + andl $-32,%edx
12761 +- lea 3f(%ebx,%ebx), %ebx
12762 ++ lea 3f(%ebx,%ebx,2), %ebx
12763 + testl %esi, %esi
12764 + jmp *%ebx
12765 + 1: addl $64,%esi
12766 +@@ -503,19 +540,19 @@ ENTRY(csum_partial_copy_generic)
12767 + jb 5f
12768 + SRC( movw (%esi), %dx )
12769 + leal 2(%esi), %esi
12770 +-DST( movw %dx, (%edi) )
12771 ++DST( movw %dx, %es:(%edi) )
12772 + leal 2(%edi), %edi
12773 + je 6f
12774 + shll $16,%edx
12775 + 5:
12776 + SRC( movb (%esi), %dl )
12777 +-DST( movb %dl, (%edi) )
12778 ++DST( movb %dl, %es:(%edi) )
12779 + 6: addl %edx, %eax
12780 + adcl $0, %eax
12781 + 7:
12782 + .section .fixup, "ax"
12783 + 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
12784 +- movl $-EFAULT, (%ebx)
12785 ++ movl $-EFAULT, %ss:(%ebx)
12786 + # zero the complete destination (computing the rest is too much work)
12787 + movl ARGBASE+8(%esp),%edi # dst
12788 + movl ARGBASE+12(%esp),%ecx # len
12789 +@@ -523,10 +560,18 @@ DST( movb %dl, (%edi) )
12790 + rep; stosb
12791 + jmp 7b
12792 + 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
12793 +- movl $-EFAULT, (%ebx)
12794 ++ movl $-EFAULT, %ss:(%ebx)
12795 + jmp 7b
12796 + .previous
12797 +
12798 ++ pushl %ss
12799 ++ CFI_ADJUST_CFA_OFFSET 4
12800 ++ popl %ds
12801 ++ CFI_ADJUST_CFA_OFFSET -4
12802 ++ pushl %ss
12803 ++ CFI_ADJUST_CFA_OFFSET 4
12804 ++ popl %es
12805 ++ CFI_ADJUST_CFA_OFFSET -4
12806 + popl %esi
12807 + CFI_ADJUST_CFA_OFFSET -4
12808 + CFI_RESTORE esi
12809 +@@ -538,7 +583,7 @@ DST( movb %dl, (%edi) )
12810 + CFI_RESTORE ebx
12811 + ret
12812 + CFI_ENDPROC
12813 +-ENDPROC(csum_partial_copy_generic)
12814 ++ENDPROC(csum_partial_copy_generic_to_user)
12815 +
12816 + #undef ROUND
12817 + #undef ROUND1
12818 +diff -urNp linux-2.6.28/arch/x86/lib/clear_page_64.S linux-2.6.28/arch/x86/lib/clear_page_64.S
12819 +--- linux-2.6.28/arch/x86/lib/clear_page_64.S 2008-12-24 18:26:37.000000000 -0500
12820 ++++ linux-2.6.28/arch/x86/lib/clear_page_64.S 2009-01-11 07:20:06.000000000 -0500
12821 +@@ -44,7 +44,7 @@ ENDPROC(clear_page)
12822 +
12823 + #include <asm/cpufeature.h>
12824 +
12825 +- .section .altinstr_replacement,"ax"
12826 ++ .section .altinstr_replacement,"a"
12827 + 1: .byte 0xeb /* jmp <disp8> */
12828 + .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
12829 + 2:
12830 +diff -urNp linux-2.6.28/arch/x86/lib/copy_page_64.S linux-2.6.28/arch/x86/lib/copy_page_64.S
12831 +--- linux-2.6.28/arch/x86/lib/copy_page_64.S 2008-12-24 18:26:37.000000000 -0500
12832 ++++ linux-2.6.28/arch/x86/lib/copy_page_64.S 2009-01-11 07:20:06.000000000 -0500
12833 +@@ -104,7 +104,7 @@ ENDPROC(copy_page)
12834 +
12835 + #include <asm/cpufeature.h>
12836 +
12837 +- .section .altinstr_replacement,"ax"
12838 ++ .section .altinstr_replacement,"a"
12839 + 1: .byte 0xeb /* jmp <disp8> */
12840 + .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
12841 + 2:
12842 +diff -urNp linux-2.6.28/arch/x86/lib/copy_user_64.S linux-2.6.28/arch/x86/lib/copy_user_64.S
12843 +--- linux-2.6.28/arch/x86/lib/copy_user_64.S 2008-12-24 18:26:37.000000000 -0500
12844 ++++ linux-2.6.28/arch/x86/lib/copy_user_64.S 2009-01-11 07:20:06.000000000 -0500
12845 +@@ -21,7 +21,7 @@
12846 + .byte 0xe9 /* 32bit jump */
12847 + .long \orig-1f /* by default jump to orig */
12848 + 1:
12849 +- .section .altinstr_replacement,"ax"
12850 ++ .section .altinstr_replacement,"a"
12851 + 2: .byte 0xe9 /* near jump with 32bit immediate */
12852 + .long \alt-1b /* offset */ /* or alternatively to alt */
12853 + .previous
12854 +@@ -106,6 +106,8 @@ ENDPROC(__copy_from_user_inatomic)
12855 + ENTRY(bad_from_user)
12856 + bad_from_user:
12857 + CFI_STARTPROC
12858 ++ testl %edx,%edx
12859 ++ js bad_to_user
12860 + movl %edx,%ecx
12861 + xorl %eax,%eax
12862 + rep
12863 +diff -urNp linux-2.6.28/arch/x86/lib/getuser.S linux-2.6.28/arch/x86/lib/getuser.S
12864 +--- linux-2.6.28/arch/x86/lib/getuser.S 2008-12-24 18:26:37.000000000 -0500
12865 ++++ linux-2.6.28/arch/x86/lib/getuser.S 2009-01-11 07:20:06.000000000 -0500
12866 +@@ -33,6 +33,7 @@
12867 + #include <asm/asm-offsets.h>
12868 + #include <asm/thread_info.h>
12869 + #include <asm/asm.h>
12870 ++#include <asm/segment.h>
12871 +
12872 + .text
12873 + ENTRY(__get_user_1)
12874 +@@ -40,7 +41,19 @@ ENTRY(__get_user_1)
12875 + GET_THREAD_INFO(%_ASM_DX)
12876 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
12877 + jae bad_get_user
12878 ++
12879 ++#ifdef CONFIG_X86_32
12880 ++ pushl $(__USER_DS)
12881 ++ popl %ds
12882 ++#endif
12883 ++
12884 + 1: movzb (%_ASM_AX),%edx
12885 ++
12886 ++#ifdef CONFIG_X86_32
12887 ++ pushl %ss
12888 ++ pop %ds
12889 ++#endif
12890 ++
12891 + xor %eax,%eax
12892 + ret
12893 + CFI_ENDPROC
12894 +@@ -53,7 +66,19 @@ ENTRY(__get_user_2)
12895 + GET_THREAD_INFO(%_ASM_DX)
12896 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
12897 + jae bad_get_user
12898 ++
12899 ++#ifdef CONFIG_X86_32
12900 ++ pushl $(__USER_DS)
12901 ++ popl %ds
12902 ++#endif
12903 ++
12904 + 2: movzwl -1(%_ASM_AX),%edx
12905 ++
12906 ++#ifdef CONFIG_X86_32
12907 ++ pushl %ss
12908 ++ pop %ds
12909 ++#endif
12910 ++
12911 + xor %eax,%eax
12912 + ret
12913 + CFI_ENDPROC
12914 +@@ -66,7 +91,19 @@ ENTRY(__get_user_4)
12915 + GET_THREAD_INFO(%_ASM_DX)
12916 + cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
12917 + jae bad_get_user
12918 ++
12919 ++#ifdef CONFIG_X86_32
12920 ++ pushl $(__USER_DS)
12921 ++ popl %ds
12922 ++#endif
12923 ++
12924 + 3: mov -3(%_ASM_AX),%edx
12925 ++
12926 ++#ifdef CONFIG_X86_32
12927 ++ pushl %ss
12928 ++ pop %ds
12929 ++#endif
12930 ++
12931 + xor %eax,%eax
12932 + ret
12933 + CFI_ENDPROC
12934 +@@ -89,6 +126,12 @@ ENDPROC(__get_user_8)
12935 +
12936 + bad_get_user:
12937 + CFI_STARTPROC
12938 ++
12939 ++#ifdef CONFIG_X86_32
12940 ++ pushl %ss
12941 ++ pop %ds
12942 ++#endif
12943 ++
12944 + xor %edx,%edx
12945 + mov $(-EFAULT),%_ASM_AX
12946 + ret
12947 +diff -urNp linux-2.6.28/arch/x86/lib/memcpy_64.S linux-2.6.28/arch/x86/lib/memcpy_64.S
12948 +--- linux-2.6.28/arch/x86/lib/memcpy_64.S 2008-12-24 18:26:37.000000000 -0500
12949 ++++ linux-2.6.28/arch/x86/lib/memcpy_64.S 2009-01-11 07:20:06.000000000 -0500
12950 +@@ -114,7 +114,7 @@ ENDPROC(__memcpy)
12951 + /* Some CPUs run faster using the string copy instructions.
12952 + It is also a lot simpler. Use this when possible */
12953 +
12954 +- .section .altinstr_replacement,"ax"
12955 ++ .section .altinstr_replacement,"a"
12956 + 1: .byte 0xeb /* jmp <disp8> */
12957 + .byte (memcpy_c - memcpy) - (2f - 1b) /* offset */
12958 + 2:
12959 +diff -urNp linux-2.6.28/arch/x86/lib/memset_64.S linux-2.6.28/arch/x86/lib/memset_64.S
12960 +--- linux-2.6.28/arch/x86/lib/memset_64.S 2008-12-24 18:26:37.000000000 -0500
12961 ++++ linux-2.6.28/arch/x86/lib/memset_64.S 2009-01-11 07:20:06.000000000 -0500
12962 +@@ -118,7 +118,7 @@ ENDPROC(__memset)
12963 +
12964 + #include <asm/cpufeature.h>
12965 +
12966 +- .section .altinstr_replacement,"ax"
12967 ++ .section .altinstr_replacement,"a"
12968 + 1: .byte 0xeb /* jmp <disp8> */
12969 + .byte (memset_c - memset) - (2f - 1b) /* offset */
12970 + 2:
12971 +diff -urNp linux-2.6.28/arch/x86/lib/mmx_32.c linux-2.6.28/arch/x86/lib/mmx_32.c
12972 +--- linux-2.6.28/arch/x86/lib/mmx_32.c 2008-12-24 18:26:37.000000000 -0500
12973 ++++ linux-2.6.28/arch/x86/lib/mmx_32.c 2009-01-11 07:20:06.000000000 -0500
12974 +@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *
12975 + {
12976 + void *p;
12977 + int i;
12978 ++ unsigned long cr0;
12979 +
12980 + if (unlikely(in_interrupt()))
12981 + return __memcpy(to, from, len);
12982 +@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *
12983 + kernel_fpu_begin();
12984 +
12985 + __asm__ __volatile__ (
12986 +- "1: prefetch (%0)\n" /* This set is 28 bytes */
12987 +- " prefetch 64(%0)\n"
12988 +- " prefetch 128(%0)\n"
12989 +- " prefetch 192(%0)\n"
12990 +- " prefetch 256(%0)\n"
12991 ++ "1: prefetch (%1)\n" /* This set is 28 bytes */
12992 ++ " prefetch 64(%1)\n"
12993 ++ " prefetch 128(%1)\n"
12994 ++ " prefetch 192(%1)\n"
12995 ++ " prefetch 256(%1)\n"
12996 + "2: \n"
12997 + ".section .fixup, \"ax\"\n"
12998 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
12999 ++ "3: \n"
13000 ++
13001 ++#ifdef CONFIG_PAX_KERNEXEC
13002 ++ " movl %%cr0, %0\n"
13003 ++ " movl %0, %%eax\n"
13004 ++ " andl $0xFFFEFFFF, %%eax\n"
13005 ++ " movl %%eax, %%cr0\n"
13006 ++#endif
13007 ++
13008 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
13009 ++
13010 ++#ifdef CONFIG_PAX_KERNEXEC
13011 ++ " movl %0, %%cr0\n"
13012 ++#endif
13013 ++
13014 + " jmp 2b\n"
13015 + ".previous\n"
13016 + _ASM_EXTABLE(1b, 3b)
13017 +- : : "r" (from));
13018 ++ : "=&r" (cr0) : "r" (from) : "ax");
13019 +
13020 + for ( ; i > 5; i--) {
13021 + __asm__ __volatile__ (
13022 +- "1: prefetch 320(%0)\n"
13023 +- "2: movq (%0), %%mm0\n"
13024 +- " movq 8(%0), %%mm1\n"
13025 +- " movq 16(%0), %%mm2\n"
13026 +- " movq 24(%0), %%mm3\n"
13027 +- " movq %%mm0, (%1)\n"
13028 +- " movq %%mm1, 8(%1)\n"
13029 +- " movq %%mm2, 16(%1)\n"
13030 +- " movq %%mm3, 24(%1)\n"
13031 +- " movq 32(%0), %%mm0\n"
13032 +- " movq 40(%0), %%mm1\n"
13033 +- " movq 48(%0), %%mm2\n"
13034 +- " movq 56(%0), %%mm3\n"
13035 +- " movq %%mm0, 32(%1)\n"
13036 +- " movq %%mm1, 40(%1)\n"
13037 +- " movq %%mm2, 48(%1)\n"
13038 +- " movq %%mm3, 56(%1)\n"
13039 ++ "1: prefetch 320(%1)\n"
13040 ++ "2: movq (%1), %%mm0\n"
13041 ++ " movq 8(%1), %%mm1\n"
13042 ++ " movq 16(%1), %%mm2\n"
13043 ++ " movq 24(%1), %%mm3\n"
13044 ++ " movq %%mm0, (%2)\n"
13045 ++ " movq %%mm1, 8(%2)\n"
13046 ++ " movq %%mm2, 16(%2)\n"
13047 ++ " movq %%mm3, 24(%2)\n"
13048 ++ " movq 32(%1), %%mm0\n"
13049 ++ " movq 40(%1), %%mm1\n"
13050 ++ " movq 48(%1), %%mm2\n"
13051 ++ " movq 56(%1), %%mm3\n"
13052 ++ " movq %%mm0, 32(%2)\n"
13053 ++ " movq %%mm1, 40(%2)\n"
13054 ++ " movq %%mm2, 48(%2)\n"
13055 ++ " movq %%mm3, 56(%2)\n"
13056 + ".section .fixup, \"ax\"\n"
13057 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
13058 ++ "3:\n"
13059 ++
13060 ++#ifdef CONFIG_PAX_KERNEXEC
13061 ++ " movl %%cr0, %0\n"
13062 ++ " movl %0, %%eax\n"
13063 ++ " andl $0xFFFEFFFF, %%eax\n"
13064 ++ " movl %%eax, %%cr0\n"
13065 ++#endif
13066 ++
13067 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
13068 ++
13069 ++#ifdef CONFIG_PAX_KERNEXEC
13070 ++ " movl %0, %%cr0\n"
13071 ++#endif
13072 ++
13073 + " jmp 2b\n"
13074 + ".previous\n"
13075 + _ASM_EXTABLE(1b, 3b)
13076 +- : : "r" (from), "r" (to) : "memory");
13077 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
13078 +
13079 + from += 64;
13080 + to += 64;
13081 +@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
13082 + static void fast_copy_page(void *to, void *from)
13083 + {
13084 + int i;
13085 ++ unsigned long cr0;
13086 +
13087 + kernel_fpu_begin();
13088 +
13089 +@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, voi
13090 + * but that is for later. -AV
13091 + */
13092 + __asm__ __volatile__(
13093 +- "1: prefetch (%0)\n"
13094 +- " prefetch 64(%0)\n"
13095 +- " prefetch 128(%0)\n"
13096 +- " prefetch 192(%0)\n"
13097 +- " prefetch 256(%0)\n"
13098 ++ "1: prefetch (%1)\n"
13099 ++ " prefetch 64(%1)\n"
13100 ++ " prefetch 128(%1)\n"
13101 ++ " prefetch 192(%1)\n"
13102 ++ " prefetch 256(%1)\n"
13103 + "2: \n"
13104 + ".section .fixup, \"ax\"\n"
13105 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
13106 ++ "3: \n"
13107 ++
13108 ++#ifdef CONFIG_PAX_KERNEXEC
13109 ++ " movl %%cr0, %0\n"
13110 ++ " movl %0, %%eax\n"
13111 ++ " andl $0xFFFEFFFF, %%eax\n"
13112 ++ " movl %%eax, %%cr0\n"
13113 ++#endif
13114 ++
13115 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
13116 ++
13117 ++#ifdef CONFIG_PAX_KERNEXEC
13118 ++ " movl %0, %%cr0\n"
13119 ++#endif
13120 ++
13121 + " jmp 2b\n"
13122 + ".previous\n"
13123 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
13124 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
13125 +
13126 + for (i = 0; i < (4096-320)/64; i++) {
13127 + __asm__ __volatile__ (
13128 +- "1: prefetch 320(%0)\n"
13129 +- "2: movq (%0), %%mm0\n"
13130 +- " movntq %%mm0, (%1)\n"
13131 +- " movq 8(%0), %%mm1\n"
13132 +- " movntq %%mm1, 8(%1)\n"
13133 +- " movq 16(%0), %%mm2\n"
13134 +- " movntq %%mm2, 16(%1)\n"
13135 +- " movq 24(%0), %%mm3\n"
13136 +- " movntq %%mm3, 24(%1)\n"
13137 +- " movq 32(%0), %%mm4\n"
13138 +- " movntq %%mm4, 32(%1)\n"
13139 +- " movq 40(%0), %%mm5\n"
13140 +- " movntq %%mm5, 40(%1)\n"
13141 +- " movq 48(%0), %%mm6\n"
13142 +- " movntq %%mm6, 48(%1)\n"
13143 +- " movq 56(%0), %%mm7\n"
13144 +- " movntq %%mm7, 56(%1)\n"
13145 ++ "1: prefetch 320(%1)\n"
13146 ++ "2: movq (%1), %%mm0\n"
13147 ++ " movntq %%mm0, (%2)\n"
13148 ++ " movq 8(%1), %%mm1\n"
13149 ++ " movntq %%mm1, 8(%2)\n"
13150 ++ " movq 16(%1), %%mm2\n"
13151 ++ " movntq %%mm2, 16(%2)\n"
13152 ++ " movq 24(%1), %%mm3\n"
13153 ++ " movntq %%mm3, 24(%2)\n"
13154 ++ " movq 32(%1), %%mm4\n"
13155 ++ " movntq %%mm4, 32(%2)\n"
13156 ++ " movq 40(%1), %%mm5\n"
13157 ++ " movntq %%mm5, 40(%2)\n"
13158 ++ " movq 48(%1), %%mm6\n"
13159 ++ " movntq %%mm6, 48(%2)\n"
13160 ++ " movq 56(%1), %%mm7\n"
13161 ++ " movntq %%mm7, 56(%2)\n"
13162 + ".section .fixup, \"ax\"\n"
13163 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
13164 ++ "3:\n"
13165 ++
13166 ++#ifdef CONFIG_PAX_KERNEXEC
13167 ++ " movl %%cr0, %0\n"
13168 ++ " movl %0, %%eax\n"
13169 ++ " andl $0xFFFEFFFF, %%eax\n"
13170 ++ " movl %%eax, %%cr0\n"
13171 ++#endif
13172 ++
13173 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
13174 ++
13175 ++#ifdef CONFIG_PAX_KERNEXEC
13176 ++ " movl %0, %%cr0\n"
13177 ++#endif
13178 ++
13179 + " jmp 2b\n"
13180 + ".previous\n"
13181 +- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
13182 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
13183 +
13184 + from += 64;
13185 + to += 64;
13186 +@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
13187 + static void fast_copy_page(void *to, void *from)
13188 + {
13189 + int i;
13190 ++ unsigned long cr0;
13191 +
13192 + kernel_fpu_begin();
13193 +
13194 + __asm__ __volatile__ (
13195 +- "1: prefetch (%0)\n"
13196 +- " prefetch 64(%0)\n"
13197 +- " prefetch 128(%0)\n"
13198 +- " prefetch 192(%0)\n"
13199 +- " prefetch 256(%0)\n"
13200 ++ "1: prefetch (%1)\n"
13201 ++ " prefetch 64(%1)\n"
13202 ++ " prefetch 128(%1)\n"
13203 ++ " prefetch 192(%1)\n"
13204 ++ " prefetch 256(%1)\n"
13205 + "2: \n"
13206 + ".section .fixup, \"ax\"\n"
13207 +- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
13208 ++ "3: \n"
13209 ++
13210 ++#ifdef CONFIG_PAX_KERNEXEC
13211 ++ " movl %%cr0, %0\n"
13212 ++ " movl %0, %%eax\n"
13213 ++ " andl $0xFFFEFFFF, %%eax\n"
13214 ++ " movl %%eax, %%cr0\n"
13215 ++#endif
13216 ++
13217 ++ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
13218 ++
13219 ++#ifdef CONFIG_PAX_KERNEXEC
13220 ++ " movl %0, %%cr0\n"
13221 ++#endif
13222 ++
13223 + " jmp 2b\n"
13224 + ".previous\n"
13225 +- _ASM_EXTABLE(1b, 3b) : : "r" (from));
13226 ++ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
13227 +
13228 + for (i = 0; i < 4096/64; i++) {
13229 + __asm__ __volatile__ (
13230 +- "1: prefetch 320(%0)\n"
13231 +- "2: movq (%0), %%mm0\n"
13232 +- " movq 8(%0), %%mm1\n"
13233 +- " movq 16(%0), %%mm2\n"
13234 +- " movq 24(%0), %%mm3\n"
13235 +- " movq %%mm0, (%1)\n"
13236 +- " movq %%mm1, 8(%1)\n"
13237 +- " movq %%mm2, 16(%1)\n"
13238 +- " movq %%mm3, 24(%1)\n"
13239 +- " movq 32(%0), %%mm0\n"
13240 +- " movq 40(%0), %%mm1\n"
13241 +- " movq 48(%0), %%mm2\n"
13242 +- " movq 56(%0), %%mm3\n"
13243 +- " movq %%mm0, 32(%1)\n"
13244 +- " movq %%mm1, 40(%1)\n"
13245 +- " movq %%mm2, 48(%1)\n"
13246 +- " movq %%mm3, 56(%1)\n"
13247 ++ "1: prefetch 320(%1)\n"
13248 ++ "2: movq (%1), %%mm0\n"
13249 ++ " movq 8(%1), %%mm1\n"
13250 ++ " movq 16(%1), %%mm2\n"
13251 ++ " movq 24(%1), %%mm3\n"
13252 ++ " movq %%mm0, (%2)\n"
13253 ++ " movq %%mm1, 8(%2)\n"
13254 ++ " movq %%mm2, 16(%2)\n"
13255 ++ " movq %%mm3, 24(%2)\n"
13256 ++ " movq 32(%1), %%mm0\n"
13257 ++ " movq 40(%1), %%mm1\n"
13258 ++ " movq 48(%1), %%mm2\n"
13259 ++ " movq 56(%1), %%mm3\n"
13260 ++ " movq %%mm0, 32(%2)\n"
13261 ++ " movq %%mm1, 40(%2)\n"
13262 ++ " movq %%mm2, 48(%2)\n"
13263 ++ " movq %%mm3, 56(%2)\n"
13264 + ".section .fixup, \"ax\"\n"
13265 +- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
13266 ++ "3:\n"
13267 ++
13268 ++#ifdef CONFIG_PAX_KERNEXEC
13269 ++ " movl %%cr0, %0\n"
13270 ++ " movl %0, %%eax\n"
13271 ++ " andl $0xFFFEFFFF, %%eax\n"
13272 ++ " movl %%eax, %%cr0\n"
13273 ++#endif
13274 ++
13275 ++ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
13276 ++
13277 ++#ifdef CONFIG_PAX_KERNEXEC
13278 ++ " movl %0, %%cr0\n"
13279 ++#endif
13280 ++
13281 + " jmp 2b\n"
13282 + ".previous\n"
13283 + _ASM_EXTABLE(1b, 3b)
13284 +- : : "r" (from), "r" (to) : "memory");
13285 ++ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
13286 +
13287 + from += 64;
13288 + to += 64;
13289 +diff -urNp linux-2.6.28/arch/x86/lib/putuser.S linux-2.6.28/arch/x86/lib/putuser.S
13290 +--- linux-2.6.28/arch/x86/lib/putuser.S 2008-12-24 18:26:37.000000000 -0500
13291 ++++ linux-2.6.28/arch/x86/lib/putuser.S 2009-01-11 07:20:06.000000000 -0500
13292 +@@ -15,6 +15,7 @@
13293 + #include <asm/thread_info.h>
13294 + #include <asm/errno.h>
13295 + #include <asm/asm.h>
13296 ++#include <asm/segment.h>
13297 +
13298 +
13299 + /*
13300 +@@ -39,7 +40,19 @@ ENTRY(__put_user_1)
13301 + ENTER
13302 + cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
13303 + jae bad_put_user
13304 ++
13305 ++#ifdef CONFIG_X86_32
13306 ++ pushl $(__USER_DS)
13307 ++ popl %ds
13308 ++#endif
13309 ++
13310 + 1: movb %al,(%_ASM_CX)
13311 ++
13312 ++#ifdef CONFIG_X86_32
13313 ++ pushl %ss
13314 ++ popl %ds
13315 ++#endif
13316 ++
13317 + xor %eax,%eax
13318 + EXIT
13319 + ENDPROC(__put_user_1)
13320 +@@ -50,7 +63,19 @@ ENTRY(__put_user_2)
13321 + sub $1,%_ASM_BX
13322 + cmp %_ASM_BX,%_ASM_CX
13323 + jae bad_put_user
13324 ++
13325 ++#ifdef CONFIG_X86_32
13326 ++ pushl $(__USER_DS)
13327 ++ popl %ds
13328 ++#endif
13329 ++
13330 + 2: movw %ax,(%_ASM_CX)
13331 ++
13332 ++#ifdef CONFIG_X86_32
13333 ++ pushl %ss
13334 ++ popl %ds
13335 ++#endif
13336 ++
13337 + xor %eax,%eax
13338 + EXIT
13339 + ENDPROC(__put_user_2)
13340 +@@ -61,7 +86,19 @@ ENTRY(__put_user_4)
13341 + sub $3,%_ASM_BX
13342 + cmp %_ASM_BX,%_ASM_CX
13343 + jae bad_put_user
13344 ++
13345 ++#ifdef CONFIG_X86_32
13346 ++ pushl $(__USER_DS)
13347 ++ popl %ds
13348 ++#endif
13349 ++
13350 + 3: movl %eax,(%_ASM_CX)
13351 ++
13352 ++#ifdef CONFIG_X86_32
13353 ++ pushl %ss
13354 ++ popl %ds
13355 ++#endif
13356 ++
13357 + xor %eax,%eax
13358 + EXIT
13359 + ENDPROC(__put_user_4)
13360 +@@ -72,16 +109,34 @@ ENTRY(__put_user_8)
13361 + sub $7,%_ASM_BX
13362 + cmp %_ASM_BX,%_ASM_CX
13363 + jae bad_put_user
13364 ++
13365 ++#ifdef CONFIG_X86_32
13366 ++ pushl $(__USER_DS)
13367 ++ popl %ds
13368 ++#endif
13369 ++
13370 + 4: mov %_ASM_AX,(%_ASM_CX)
13371 + #ifdef CONFIG_X86_32
13372 + 5: movl %edx,4(%_ASM_CX)
13373 + #endif
13374 ++
13375 ++#ifdef CONFIG_X86_32
13376 ++ pushl %ss
13377 ++ popl %ds
13378 ++#endif
13379 ++
13380 + xor %eax,%eax
13381 + EXIT
13382 + ENDPROC(__put_user_8)
13383 +
13384 + bad_put_user:
13385 + CFI_STARTPROC
13386 ++
13387 ++#ifdef CONFIG_X86_32
13388 ++ pushl %ss
13389 ++ popl %ds
13390 ++#endif
13391 ++
13392 + movl $-EFAULT,%eax
13393 + EXIT
13394 + END(bad_put_user)
13395 +diff -urNp linux-2.6.28/arch/x86/lib/usercopy_32.c linux-2.6.28/arch/x86/lib/usercopy_32.c
13396 +--- linux-2.6.28/arch/x86/lib/usercopy_32.c 2008-12-24 18:26:37.000000000 -0500
13397 ++++ linux-2.6.28/arch/x86/lib/usercopy_32.c 2009-01-11 07:20:06.000000000 -0500
13398 +@@ -36,31 +36,38 @@ static inline int __movsl_is_ok(unsigned
13399 + * Copy a null terminated string from userspace.
13400 + */
13401 +
13402 +-#define __do_strncpy_from_user(dst, src, count, res) \
13403 +-do { \
13404 +- int __d0, __d1, __d2; \
13405 +- might_sleep(); \
13406 +- __asm__ __volatile__( \
13407 +- " testl %1,%1\n" \
13408 +- " jz 2f\n" \
13409 +- "0: lodsb\n" \
13410 +- " stosb\n" \
13411 +- " testb %%al,%%al\n" \
13412 +- " jz 1f\n" \
13413 +- " decl %1\n" \
13414 +- " jnz 0b\n" \
13415 +- "1: subl %1,%0\n" \
13416 +- "2:\n" \
13417 +- ".section .fixup,\"ax\"\n" \
13418 +- "3: movl %5,%0\n" \
13419 +- " jmp 2b\n" \
13420 +- ".previous\n" \
13421 +- _ASM_EXTABLE(0b,3b) \
13422 +- : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1), \
13423 +- "=&D" (__d2) \
13424 +- : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst) \
13425 +- : "memory"); \
13426 +-} while (0)
13427 ++static long __do_strncpy_from_user(char *dst, const char __user *src, long count)
13428 ++{
13429 ++ int __d0, __d1, __d2;
13430 ++ long res = -EFAULT;
13431 ++
13432 ++ might_sleep();
13433 ++ __asm__ __volatile__(
13434 ++ " movw %w10,%%ds\n"
13435 ++ " testl %1,%1\n"
13436 ++ " jz 2f\n"
13437 ++ "0: lodsb\n"
13438 ++ " stosb\n"
13439 ++ " testb %%al,%%al\n"
13440 ++ " jz 1f\n"
13441 ++ " decl %1\n"
13442 ++ " jnz 0b\n"
13443 ++ "1: subl %1,%0\n"
13444 ++ "2:\n"
13445 ++ " pushl %%ss\n"
13446 ++ " popl %%ds\n"
13447 ++ ".section .fixup,\"ax\"\n"
13448 ++ "3: movl %5,%0\n"
13449 ++ " jmp 2b\n"
13450 ++ ".previous\n"
13451 ++ _ASM_EXTABLE(0b,3b)
13452 ++ : "=d"(res), "=c"(count), "=&a" (__d0), "=&S" (__d1),
13453 ++ "=&D" (__d2)
13454 ++ : "i"(-EFAULT), "0"(count), "1"(count), "3"(src), "4"(dst),
13455 ++ "r"(__USER_DS)
13456 ++ : "memory");
13457 ++ return res;
13458 ++}
13459 +
13460 + /**
13461 + * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking.
13462 +@@ -85,9 +92,7 @@ do { \
13463 + long
13464 + __strncpy_from_user(char *dst, const char __user *src, long count)
13465 + {
13466 +- long res;
13467 +- __do_strncpy_from_user(dst, src, count, res);
13468 +- return res;
13469 ++ return __do_strncpy_from_user(dst, src, count);
13470 + }
13471 + EXPORT_SYMBOL(__strncpy_from_user);
13472 +
13473 +@@ -114,7 +119,7 @@ strncpy_from_user(char *dst, const char
13474 + {
13475 + long res = -EFAULT;
13476 + if (access_ok(VERIFY_READ, src, 1))
13477 +- __do_strncpy_from_user(dst, src, count, res);
13478 ++ res = __do_strncpy_from_user(dst, src, count);
13479 + return res;
13480 + }
13481 + EXPORT_SYMBOL(strncpy_from_user);
13482 +@@ -123,24 +128,30 @@ EXPORT_SYMBOL(strncpy_from_user);
13483 + * Zero Userspace
13484 + */
13485 +
13486 +-#define __do_clear_user(addr,size) \
13487 +-do { \
13488 +- int __d0; \
13489 +- might_sleep(); \
13490 +- __asm__ __volatile__( \
13491 +- "0: rep; stosl\n" \
13492 +- " movl %2,%0\n" \
13493 +- "1: rep; stosb\n" \
13494 +- "2:\n" \
13495 +- ".section .fixup,\"ax\"\n" \
13496 +- "3: lea 0(%2,%0,4),%0\n" \
13497 +- " jmp 2b\n" \
13498 +- ".previous\n" \
13499 +- _ASM_EXTABLE(0b,3b) \
13500 +- _ASM_EXTABLE(1b,2b) \
13501 +- : "=&c"(size), "=&D" (__d0) \
13502 +- : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0)); \
13503 +-} while (0)
13504 ++static unsigned long __do_clear_user(void __user *addr, unsigned long size)
13505 ++{
13506 ++ int __d0;
13507 ++
13508 ++ might_sleep();
13509 ++ __asm__ __volatile__(
13510 ++ " movw %w6,%%es\n"
13511 ++ "0: rep; stosl\n"
13512 ++ " movl %2,%0\n"
13513 ++ "1: rep; stosb\n"
13514 ++ "2:\n"
13515 ++ " pushl %%ss\n"
13516 ++ " popl %%es\n"
13517 ++ ".section .fixup,\"ax\"\n"
13518 ++ "3: lea 0(%2,%0,4),%0\n"
13519 ++ " jmp 2b\n"
13520 ++ ".previous\n"
13521 ++ _ASM_EXTABLE(0b,3b)
13522 ++ _ASM_EXTABLE(1b,2b)
13523 ++ : "=&c"(size), "=&D" (__d0)
13524 ++ : "r"(size & 3), "0"(size / 4), "1"(addr), "a"(0),
13525 ++ "r"(__USER_DS));
13526 ++ return size;
13527 ++}
13528 +
13529 + /**
13530 + * clear_user: - Zero a block of memory in user space.
13531 +@@ -157,7 +168,7 @@ clear_user(void __user *to, unsigned lon
13532 + {
13533 + might_sleep();
13534 + if (access_ok(VERIFY_WRITE, to, n))
13535 +- __do_clear_user(to, n);
13536 ++ n = __do_clear_user(to, n);
13537 + return n;
13538 + }
13539 + EXPORT_SYMBOL(clear_user);
13540 +@@ -176,8 +187,7 @@ EXPORT_SYMBOL(clear_user);
13541 + unsigned long
13542 + __clear_user(void __user *to, unsigned long n)
13543 + {
13544 +- __do_clear_user(to, n);
13545 +- return n;
13546 ++ return __do_clear_user(to, n);
13547 + }
13548 + EXPORT_SYMBOL(__clear_user);
13549 +
13550 +@@ -200,14 +210,17 @@ long strnlen_user(const char __user *s,
13551 + might_sleep();
13552 +
13553 + __asm__ __volatile__(
13554 ++ " movw %w8,%%es\n"
13555 + " testl %0, %0\n"
13556 + " jz 3f\n"
13557 +- " andl %0,%%ecx\n"
13558 ++ " movl %0,%%ecx\n"
13559 + "0: repne; scasb\n"
13560 + " setne %%al\n"
13561 + " subl %%ecx,%0\n"
13562 + " addl %0,%%eax\n"
13563 + "1:\n"
13564 ++ " pushl %%ss\n"
13565 ++ " popl %%es\n"
13566 + ".section .fixup,\"ax\"\n"
13567 + "2: xorl %%eax,%%eax\n"
13568 + " jmp 1b\n"
13569 +@@ -219,7 +232,7 @@ long strnlen_user(const char __user *s,
13570 + " .long 0b,2b\n"
13571 + ".previous"
13572 + :"=r" (n), "=D" (s), "=a" (res), "=c" (tmp)
13573 +- :"0" (n), "1" (s), "2" (0), "3" (mask)
13574 ++ :"0" (n), "1" (s), "2" (0), "3" (mask), "r" (__USER_DS)
13575 + :"cc");
13576 + return res & mask;
13577 + }
13578 +@@ -227,10 +240,11 @@ EXPORT_SYMBOL(strnlen_user);
13579 +
13580 + #ifdef CONFIG_X86_INTEL_USERCOPY
13581 + static unsigned long
13582 +-__copy_user_intel(void __user *to, const void *from, unsigned long size)
13583 ++__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
13584 + {
13585 + int d0, d1;
13586 + __asm__ __volatile__(
13587 ++ " movw %w6, %%es\n"
13588 + " .align 2,0x90\n"
13589 + "1: movl 32(%4), %%eax\n"
13590 + " cmpl $67, %0\n"
13591 +@@ -239,36 +253,36 @@ __copy_user_intel(void __user *to, const
13592 + " .align 2,0x90\n"
13593 + "3: movl 0(%4), %%eax\n"
13594 + "4: movl 4(%4), %%edx\n"
13595 +- "5: movl %%eax, 0(%3)\n"
13596 +- "6: movl %%edx, 4(%3)\n"
13597 ++ "5: movl %%eax, %%es:0(%3)\n"
13598 ++ "6: movl %%edx, %%es:4(%3)\n"
13599 + "7: movl 8(%4), %%eax\n"
13600 + "8: movl 12(%4),%%edx\n"
13601 +- "9: movl %%eax, 8(%3)\n"
13602 +- "10: movl %%edx, 12(%3)\n"
13603 ++ "9: movl %%eax, %%es:8(%3)\n"
13604 ++ "10: movl %%edx, %%es:12(%3)\n"
13605 + "11: movl 16(%4), %%eax\n"
13606 + "12: movl 20(%4), %%edx\n"
13607 +- "13: movl %%eax, 16(%3)\n"
13608 +- "14: movl %%edx, 20(%3)\n"
13609 ++ "13: movl %%eax, %%es:16(%3)\n"
13610 ++ "14: movl %%edx, %%es:20(%3)\n"
13611 + "15: movl 24(%4), %%eax\n"
13612 + "16: movl 28(%4), %%edx\n"
13613 +- "17: movl %%eax, 24(%3)\n"
13614 +- "18: movl %%edx, 28(%3)\n"
13615 ++ "17: movl %%eax, %%es:24(%3)\n"
13616 ++ "18: movl %%edx, %%es:28(%3)\n"
13617 + "19: movl 32(%4), %%eax\n"
13618 + "20: movl 36(%4), %%edx\n"
13619 +- "21: movl %%eax, 32(%3)\n"
13620 +- "22: movl %%edx, 36(%3)\n"
13621 ++ "21: movl %%eax, %%es:32(%3)\n"
13622 ++ "22: movl %%edx, %%es:36(%3)\n"
13623 + "23: movl 40(%4), %%eax\n"
13624 + "24: movl 44(%4), %%edx\n"
13625 +- "25: movl %%eax, 40(%3)\n"
13626 +- "26: movl %%edx, 44(%3)\n"
13627 ++ "25: movl %%eax, %%es:40(%3)\n"
13628 ++ "26: movl %%edx, %%es:44(%3)\n"
13629 + "27: movl 48(%4), %%eax\n"
13630 + "28: movl 52(%4), %%edx\n"
13631 +- "29: movl %%eax, 48(%3)\n"
13632 +- "30: movl %%edx, 52(%3)\n"
13633 ++ "29: movl %%eax, %%es:48(%3)\n"
13634 ++ "30: movl %%edx, %%es:52(%3)\n"
13635 + "31: movl 56(%4), %%eax\n"
13636 + "32: movl 60(%4), %%edx\n"
13637 +- "33: movl %%eax, 56(%3)\n"
13638 +- "34: movl %%edx, 60(%3)\n"
13639 ++ "33: movl %%eax, %%es:56(%3)\n"
13640 ++ "34: movl %%edx, %%es:60(%3)\n"
13641 + " addl $-64, %0\n"
13642 + " addl $64, %4\n"
13643 + " addl $64, %3\n"
13644 +@@ -282,6 +296,8 @@ __copy_user_intel(void __user *to, const
13645 + "36: movl %%eax, %0\n"
13646 + "37: rep; movsb\n"
13647 + "100:\n"
13648 ++ " pushl %%ss\n"
13649 ++ " popl %%es\n"
13650 + ".section .fixup,\"ax\"\n"
13651 + "101: lea 0(%%eax,%0,4),%0\n"
13652 + " jmp 100b\n"
13653 +@@ -328,7 +344,117 @@ __copy_user_intel(void __user *to, const
13654 + " .long 99b,101b\n"
13655 + ".previous"
13656 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
13657 +- : "1"(to), "2"(from), "0"(size)
13658 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
13659 ++ : "eax", "edx", "memory");
13660 ++ return size;
13661 ++}
13662 ++
13663 ++static unsigned long
13664 ++__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
13665 ++{
13666 ++ int d0, d1;
13667 ++ __asm__ __volatile__(
13668 ++ " movw %w6, %%ds\n"
13669 ++ " .align 2,0x90\n"
13670 ++ "1: movl 32(%4), %%eax\n"
13671 ++ " cmpl $67, %0\n"
13672 ++ " jbe 3f\n"
13673 ++ "2: movl 64(%4), %%eax\n"
13674 ++ " .align 2,0x90\n"
13675 ++ "3: movl 0(%4), %%eax\n"
13676 ++ "4: movl 4(%4), %%edx\n"
13677 ++ "5: movl %%eax, %%es:0(%3)\n"
13678 ++ "6: movl %%edx, %%es:4(%3)\n"
13679 ++ "7: movl 8(%4), %%eax\n"
13680 ++ "8: movl 12(%4),%%edx\n"
13681 ++ "9: movl %%eax, %%es:8(%3)\n"
13682 ++ "10: movl %%edx, %%es:12(%3)\n"
13683 ++ "11: movl 16(%4), %%eax\n"
13684 ++ "12: movl 20(%4), %%edx\n"
13685 ++ "13: movl %%eax, %%es:16(%3)\n"
13686 ++ "14: movl %%edx, %%es:20(%3)\n"
13687 ++ "15: movl 24(%4), %%eax\n"
13688 ++ "16: movl 28(%4), %%edx\n"
13689 ++ "17: movl %%eax, %%es:24(%3)\n"
13690 ++ "18: movl %%edx, %%es:28(%3)\n"
13691 ++ "19: movl 32(%4), %%eax\n"
13692 ++ "20: movl 36(%4), %%edx\n"
13693 ++ "21: movl %%eax, %%es:32(%3)\n"
13694 ++ "22: movl %%edx, %%es:36(%3)\n"
13695 ++ "23: movl 40(%4), %%eax\n"
13696 ++ "24: movl 44(%4), %%edx\n"
13697 ++ "25: movl %%eax, %%es:40(%3)\n"
13698 ++ "26: movl %%edx, %%es:44(%3)\n"
13699 ++ "27: movl 48(%4), %%eax\n"
13700 ++ "28: movl 52(%4), %%edx\n"
13701 ++ "29: movl %%eax, %%es:48(%3)\n"
13702 ++ "30: movl %%edx, %%es:52(%3)\n"
13703 ++ "31: movl 56(%4), %%eax\n"
13704 ++ "32: movl 60(%4), %%edx\n"
13705 ++ "33: movl %%eax, %%es:56(%3)\n"
13706 ++ "34: movl %%edx, %%es:60(%3)\n"
13707 ++ " addl $-64, %0\n"
13708 ++ " addl $64, %4\n"
13709 ++ " addl $64, %3\n"
13710 ++ " cmpl $63, %0\n"
13711 ++ " ja 1b\n"
13712 ++ "35: movl %0, %%eax\n"
13713 ++ " shrl $2, %0\n"
13714 ++ " andl $3, %%eax\n"
13715 ++ " cld\n"
13716 ++ "99: rep; movsl\n"
13717 ++ "36: movl %%eax, %0\n"
13718 ++ "37: rep; movsb\n"
13719 ++ "100:\n"
13720 ++ " pushl %%ss\n"
13721 ++ " popl %%ds\n"
13722 ++ ".section .fixup,\"ax\"\n"
13723 ++ "101: lea 0(%%eax,%0,4),%0\n"
13724 ++ " jmp 100b\n"
13725 ++ ".previous\n"
13726 ++ ".section __ex_table,\"a\"\n"
13727 ++ " .align 4\n"
13728 ++ " .long 1b,100b\n"
13729 ++ " .long 2b,100b\n"
13730 ++ " .long 3b,100b\n"
13731 ++ " .long 4b,100b\n"
13732 ++ " .long 5b,100b\n"
13733 ++ " .long 6b,100b\n"
13734 ++ " .long 7b,100b\n"
13735 ++ " .long 8b,100b\n"
13736 ++ " .long 9b,100b\n"
13737 ++ " .long 10b,100b\n"
13738 ++ " .long 11b,100b\n"
13739 ++ " .long 12b,100b\n"
13740 ++ " .long 13b,100b\n"
13741 ++ " .long 14b,100b\n"
13742 ++ " .long 15b,100b\n"
13743 ++ " .long 16b,100b\n"
13744 ++ " .long 17b,100b\n"
13745 ++ " .long 18b,100b\n"
13746 ++ " .long 19b,100b\n"
13747 ++ " .long 20b,100b\n"
13748 ++ " .long 21b,100b\n"
13749 ++ " .long 22b,100b\n"
13750 ++ " .long 23b,100b\n"
13751 ++ " .long 24b,100b\n"
13752 ++ " .long 25b,100b\n"
13753 ++ " .long 26b,100b\n"
13754 ++ " .long 27b,100b\n"
13755 ++ " .long 28b,100b\n"
13756 ++ " .long 29b,100b\n"
13757 ++ " .long 30b,100b\n"
13758 ++ " .long 31b,100b\n"
13759 ++ " .long 32b,100b\n"
13760 ++ " .long 33b,100b\n"
13761 ++ " .long 34b,100b\n"
13762 ++ " .long 35b,100b\n"
13763 ++ " .long 36b,100b\n"
13764 ++ " .long 37b,100b\n"
13765 ++ " .long 99b,101b\n"
13766 ++ ".previous"
13767 ++ : "=&c"(size), "=&D" (d0), "=&S" (d1)
13768 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
13769 + : "eax", "edx", "memory");
13770 + return size;
13771 + }
13772 +@@ -338,6 +464,7 @@ __copy_user_zeroing_intel(void *to, cons
13773 + {
13774 + int d0, d1;
13775 + __asm__ __volatile__(
13776 ++ " movw %w6, %%ds\n"
13777 + " .align 2,0x90\n"
13778 + "0: movl 32(%4), %%eax\n"
13779 + " cmpl $67, %0\n"
13780 +@@ -346,36 +473,36 @@ __copy_user_zeroing_intel(void *to, cons
13781 + " .align 2,0x90\n"
13782 + "2: movl 0(%4), %%eax\n"
13783 + "21: movl 4(%4), %%edx\n"
13784 +- " movl %%eax, 0(%3)\n"
13785 +- " movl %%edx, 4(%3)\n"
13786 ++ " movl %%eax, %%es:0(%3)\n"
13787 ++ " movl %%edx, %%es:4(%3)\n"
13788 + "3: movl 8(%4), %%eax\n"
13789 + "31: movl 12(%4),%%edx\n"
13790 +- " movl %%eax, 8(%3)\n"
13791 +- " movl %%edx, 12(%3)\n"
13792 ++ " movl %%eax, %%es:8(%3)\n"
13793 ++ " movl %%edx, %%es:12(%3)\n"
13794 + "4: movl 16(%4), %%eax\n"
13795 + "41: movl 20(%4), %%edx\n"
13796 +- " movl %%eax, 16(%3)\n"
13797 +- " movl %%edx, 20(%3)\n"
13798 ++ " movl %%eax, %%es:16(%3)\n"
13799 ++ " movl %%edx, %%es:20(%3)\n"
13800 + "10: movl 24(%4), %%eax\n"
13801 + "51: movl 28(%4), %%edx\n"
13802 +- " movl %%eax, 24(%3)\n"
13803 +- " movl %%edx, 28(%3)\n"
13804 ++ " movl %%eax, %%es:24(%3)\n"
13805 ++ " movl %%edx, %%es:28(%3)\n"
13806 + "11: movl 32(%4), %%eax\n"
13807 + "61: movl 36(%4), %%edx\n"
13808 +- " movl %%eax, 32(%3)\n"
13809 +- " movl %%edx, 36(%3)\n"
13810 ++ " movl %%eax, %%es:32(%3)\n"
13811 ++ " movl %%edx, %%es:36(%3)\n"
13812 + "12: movl 40(%4), %%eax\n"
13813 + "71: movl 44(%4), %%edx\n"
13814 +- " movl %%eax, 40(%3)\n"
13815 +- " movl %%edx, 44(%3)\n"
13816 ++ " movl %%eax, %%es:40(%3)\n"
13817 ++ " movl %%edx, %%es:44(%3)\n"
13818 + "13: movl 48(%4), %%eax\n"
13819 + "81: movl 52(%4), %%edx\n"
13820 +- " movl %%eax, 48(%3)\n"
13821 +- " movl %%edx, 52(%3)\n"
13822 ++ " movl %%eax, %%es:48(%3)\n"
13823 ++ " movl %%edx, %%es:52(%3)\n"
13824 + "14: movl 56(%4), %%eax\n"
13825 + "91: movl 60(%4), %%edx\n"
13826 +- " movl %%eax, 56(%3)\n"
13827 +- " movl %%edx, 60(%3)\n"
13828 ++ " movl %%eax, %%es:56(%3)\n"
13829 ++ " movl %%edx, %%es:60(%3)\n"
13830 + " addl $-64, %0\n"
13831 + " addl $64, %4\n"
13832 + " addl $64, %3\n"
13833 +@@ -389,6 +516,8 @@ __copy_user_zeroing_intel(void *to, cons
13834 + " movl %%eax,%0\n"
13835 + "7: rep; movsb\n"
13836 + "8:\n"
13837 ++ " pushl %%ss\n"
13838 ++ " popl %%ds\n"
13839 + ".section .fixup,\"ax\"\n"
13840 + "9: lea 0(%%eax,%0,4),%0\n"
13841 + "16: pushl %0\n"
13842 +@@ -423,7 +552,7 @@ __copy_user_zeroing_intel(void *to, cons
13843 + " .long 7b,16b\n"
13844 + ".previous"
13845 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
13846 +- : "1"(to), "2"(from), "0"(size)
13847 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
13848 + : "eax", "edx", "memory");
13849 + return size;
13850 + }
13851 +@@ -439,6 +568,7 @@ static unsigned long __copy_user_zeroing
13852 + int d0, d1;
13853 +
13854 + __asm__ __volatile__(
13855 ++ " movw %w6, %%ds\n"
13856 + " .align 2,0x90\n"
13857 + "0: movl 32(%4), %%eax\n"
13858 + " cmpl $67, %0\n"
13859 +@@ -447,36 +577,36 @@ static unsigned long __copy_user_zeroing
13860 + " .align 2,0x90\n"
13861 + "2: movl 0(%4), %%eax\n"
13862 + "21: movl 4(%4), %%edx\n"
13863 +- " movnti %%eax, 0(%3)\n"
13864 +- " movnti %%edx, 4(%3)\n"
13865 ++ " movnti %%eax, %%es:0(%3)\n"
13866 ++ " movnti %%edx, %%es:4(%3)\n"
13867 + "3: movl 8(%4), %%eax\n"
13868 + "31: movl 12(%4),%%edx\n"
13869 +- " movnti %%eax, 8(%3)\n"
13870 +- " movnti %%edx, 12(%3)\n"
13871 ++ " movnti %%eax, %%es:8(%3)\n"
13872 ++ " movnti %%edx, %%es:12(%3)\n"
13873 + "4: movl 16(%4), %%eax\n"
13874 + "41: movl 20(%4), %%edx\n"
13875 +- " movnti %%eax, 16(%3)\n"
13876 +- " movnti %%edx, 20(%3)\n"
13877 ++ " movnti %%eax, %%es:16(%3)\n"
13878 ++ " movnti %%edx, %%es:20(%3)\n"
13879 + "10: movl 24(%4), %%eax\n"
13880 + "51: movl 28(%4), %%edx\n"
13881 +- " movnti %%eax, 24(%3)\n"
13882 +- " movnti %%edx, 28(%3)\n"
13883 ++ " movnti %%eax, %%es:24(%3)\n"
13884 ++ " movnti %%edx, %%es:28(%3)\n"
13885 + "11: movl 32(%4), %%eax\n"
13886 + "61: movl 36(%4), %%edx\n"
13887 +- " movnti %%eax, 32(%3)\n"
13888 +- " movnti %%edx, 36(%3)\n"
13889 ++ " movnti %%eax, %%es:32(%3)\n"
13890 ++ " movnti %%edx, %%es:36(%3)\n"
13891 + "12: movl 40(%4), %%eax\n"
13892 + "71: movl 44(%4), %%edx\n"
13893 +- " movnti %%eax, 40(%3)\n"
13894 +- " movnti %%edx, 44(%3)\n"
13895 ++ " movnti %%eax, %%es:40(%3)\n"
13896 ++ " movnti %%edx, %%es:44(%3)\n"
13897 + "13: movl 48(%4), %%eax\n"
13898 + "81: movl 52(%4), %%edx\n"
13899 +- " movnti %%eax, 48(%3)\n"
13900 +- " movnti %%edx, 52(%3)\n"
13901 ++ " movnti %%eax, %%es:48(%3)\n"
13902 ++ " movnti %%edx, %%es:52(%3)\n"
13903 + "14: movl 56(%4), %%eax\n"
13904 + "91: movl 60(%4), %%edx\n"
13905 +- " movnti %%eax, 56(%3)\n"
13906 +- " movnti %%edx, 60(%3)\n"
13907 ++ " movnti %%eax, %%es:56(%3)\n"
13908 ++ " movnti %%edx, %%es:60(%3)\n"
13909 + " addl $-64, %0\n"
13910 + " addl $64, %4\n"
13911 + " addl $64, %3\n"
13912 +@@ -491,6 +621,8 @@ static unsigned long __copy_user_zeroing
13913 + " movl %%eax,%0\n"
13914 + "7: rep; movsb\n"
13915 + "8:\n"
13916 ++ " pushl %%ss\n"
13917 ++ " popl %%ds\n"
13918 + ".section .fixup,\"ax\"\n"
13919 + "9: lea 0(%%eax,%0,4),%0\n"
13920 + "16: pushl %0\n"
13921 +@@ -525,7 +657,7 @@ static unsigned long __copy_user_zeroing
13922 + " .long 7b,16b\n"
13923 + ".previous"
13924 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
13925 +- : "1"(to), "2"(from), "0"(size)
13926 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
13927 + : "eax", "edx", "memory");
13928 + return size;
13929 + }
13930 +@@ -536,6 +668,7 @@ static unsigned long __copy_user_intel_n
13931 + int d0, d1;
13932 +
13933 + __asm__ __volatile__(
13934 ++ " movw %w6, %%ds\n"
13935 + " .align 2,0x90\n"
13936 + "0: movl 32(%4), %%eax\n"
13937 + " cmpl $67, %0\n"
13938 +@@ -544,36 +677,36 @@ static unsigned long __copy_user_intel_n
13939 + " .align 2,0x90\n"
13940 + "2: movl 0(%4), %%eax\n"
13941 + "21: movl 4(%4), %%edx\n"
13942 +- " movnti %%eax, 0(%3)\n"
13943 +- " movnti %%edx, 4(%3)\n"
13944 ++ " movnti %%eax, %%es:0(%3)\n"
13945 ++ " movnti %%edx, %%es:4(%3)\n"
13946 + "3: movl 8(%4), %%eax\n"
13947 + "31: movl 12(%4),%%edx\n"
13948 +- " movnti %%eax, 8(%3)\n"
13949 +- " movnti %%edx, 12(%3)\n"
13950 ++ " movnti %%eax, %%es:8(%3)\n"
13951 ++ " movnti %%edx, %%es:12(%3)\n"
13952 + "4: movl 16(%4), %%eax\n"
13953 + "41: movl 20(%4), %%edx\n"
13954 +- " movnti %%eax, 16(%3)\n"
13955 +- " movnti %%edx, 20(%3)\n"
13956 ++ " movnti %%eax, %%es:16(%3)\n"
13957 ++ " movnti %%edx, %%es:20(%3)\n"
13958 + "10: movl 24(%4), %%eax\n"
13959 + "51: movl 28(%4), %%edx\n"
13960 +- " movnti %%eax, 24(%3)\n"
13961 +- " movnti %%edx, 28(%3)\n"
13962 ++ " movnti %%eax, %%es:24(%3)\n"
13963 ++ " movnti %%edx, %%es:28(%3)\n"
13964 + "11: movl 32(%4), %%eax\n"
13965 + "61: movl 36(%4), %%edx\n"
13966 +- " movnti %%eax, 32(%3)\n"
13967 +- " movnti %%edx, 36(%3)\n"
13968 ++ " movnti %%eax, %%es:32(%3)\n"
13969 ++ " movnti %%edx, %%es:36(%3)\n"
13970 + "12: movl 40(%4), %%eax\n"
13971 + "71: movl 44(%4), %%edx\n"
13972 +- " movnti %%eax, 40(%3)\n"
13973 +- " movnti %%edx, 44(%3)\n"
13974 ++ " movnti %%eax, %%es:40(%3)\n"
13975 ++ " movnti %%edx, %%es:44(%3)\n"
13976 + "13: movl 48(%4), %%eax\n"
13977 + "81: movl 52(%4), %%edx\n"
13978 +- " movnti %%eax, 48(%3)\n"
13979 +- " movnti %%edx, 52(%3)\n"
13980 ++ " movnti %%eax, %%es:48(%3)\n"
13981 ++ " movnti %%edx, %%es:52(%3)\n"
13982 + "14: movl 56(%4), %%eax\n"
13983 + "91: movl 60(%4), %%edx\n"
13984 +- " movnti %%eax, 56(%3)\n"
13985 +- " movnti %%edx, 60(%3)\n"
13986 ++ " movnti %%eax, %%es:56(%3)\n"
13987 ++ " movnti %%edx, %%es:60(%3)\n"
13988 + " addl $-64, %0\n"
13989 + " addl $64, %4\n"
13990 + " addl $64, %3\n"
13991 +@@ -588,6 +721,8 @@ static unsigned long __copy_user_intel_n
13992 + " movl %%eax,%0\n"
13993 + "7: rep; movsb\n"
13994 + "8:\n"
13995 ++ " pushl %%ss\n"
13996 ++ " popl %%ds\n"
13997 + ".section .fixup,\"ax\"\n"
13998 + "9: lea 0(%%eax,%0,4),%0\n"
13999 + "16: jmp 8b\n"
14000 +@@ -616,7 +751,7 @@ static unsigned long __copy_user_intel_n
14001 + " .long 7b,16b\n"
14002 + ".previous"
14003 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
14004 +- : "1"(to), "2"(from), "0"(size)
14005 ++ : "1"(to), "2"(from), "0"(size), "r"(__USER_DS)
14006 + : "eax", "edx", "memory");
14007 + return size;
14008 + }
14009 +@@ -629,90 +764,146 @@ static unsigned long __copy_user_intel_n
14010 + */
14011 + unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
14012 + unsigned long size);
14013 +-unsigned long __copy_user_intel(void __user *to, const void *from,
14014 ++unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
14015 ++ unsigned long size);
14016 ++unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
14017 + unsigned long size);
14018 + unsigned long __copy_user_zeroing_intel_nocache(void *to,
14019 + const void __user *from, unsigned long size);
14020 + #endif /* CONFIG_X86_INTEL_USERCOPY */
14021 +
14022 + /* Generic arbitrary sized copy. */
14023 +-#define __copy_user(to, from, size) \
14024 +-do { \
14025 +- int __d0, __d1, __d2; \
14026 +- __asm__ __volatile__( \
14027 +- " cmp $7,%0\n" \
14028 +- " jbe 1f\n" \
14029 +- " movl %1,%0\n" \
14030 +- " negl %0\n" \
14031 +- " andl $7,%0\n" \
14032 +- " subl %0,%3\n" \
14033 +- "4: rep; movsb\n" \
14034 +- " movl %3,%0\n" \
14035 +- " shrl $2,%0\n" \
14036 +- " andl $3,%3\n" \
14037 +- " .align 2,0x90\n" \
14038 +- "0: rep; movsl\n" \
14039 +- " movl %3,%0\n" \
14040 +- "1: rep; movsb\n" \
14041 +- "2:\n" \
14042 +- ".section .fixup,\"ax\"\n" \
14043 +- "5: addl %3,%0\n" \
14044 +- " jmp 2b\n" \
14045 +- "3: lea 0(%3,%0,4),%0\n" \
14046 +- " jmp 2b\n" \
14047 +- ".previous\n" \
14048 +- ".section __ex_table,\"a\"\n" \
14049 +- " .align 4\n" \
14050 +- " .long 4b,5b\n" \
14051 +- " .long 0b,3b\n" \
14052 +- " .long 1b,2b\n" \
14053 +- ".previous" \
14054 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
14055 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
14056 +- : "memory"); \
14057 +-} while (0)
14058 +-
14059 +-#define __copy_user_zeroing(to, from, size) \
14060 +-do { \
14061 +- int __d0, __d1, __d2; \
14062 +- __asm__ __volatile__( \
14063 +- " cmp $7,%0\n" \
14064 +- " jbe 1f\n" \
14065 +- " movl %1,%0\n" \
14066 +- " negl %0\n" \
14067 +- " andl $7,%0\n" \
14068 +- " subl %0,%3\n" \
14069 +- "4: rep; movsb\n" \
14070 +- " movl %3,%0\n" \
14071 +- " shrl $2,%0\n" \
14072 +- " andl $3,%3\n" \
14073 +- " .align 2,0x90\n" \
14074 +- "0: rep; movsl\n" \
14075 +- " movl %3,%0\n" \
14076 +- "1: rep; movsb\n" \
14077 +- "2:\n" \
14078 +- ".section .fixup,\"ax\"\n" \
14079 +- "5: addl %3,%0\n" \
14080 +- " jmp 6f\n" \
14081 +- "3: lea 0(%3,%0,4),%0\n" \
14082 +- "6: pushl %0\n" \
14083 +- " pushl %%eax\n" \
14084 +- " xorl %%eax,%%eax\n" \
14085 +- " rep; stosb\n" \
14086 +- " popl %%eax\n" \
14087 +- " popl %0\n" \
14088 +- " jmp 2b\n" \
14089 +- ".previous\n" \
14090 +- ".section __ex_table,\"a\"\n" \
14091 +- " .align 4\n" \
14092 +- " .long 4b,5b\n" \
14093 +- " .long 0b,3b\n" \
14094 +- " .long 1b,6b\n" \
14095 +- ".previous" \
14096 +- : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2) \
14097 +- : "3"(size), "0"(size), "1"(to), "2"(from) \
14098 +- : "memory"); \
14099 +-} while (0)
14100 ++static unsigned long
14101 ++__generic_copy_to_user(void __user *to, const void *from, unsigned long size)
14102 ++{
14103 ++ int __d0, __d1, __d2;
14104 ++
14105 ++ __asm__ __volatile__(
14106 ++ " movw %w8,%%es\n"
14107 ++ " cmp $7,%0\n"
14108 ++ " jbe 1f\n"
14109 ++ " movl %1,%0\n"
14110 ++ " negl %0\n"
14111 ++ " andl $7,%0\n"
14112 ++ " subl %0,%3\n"
14113 ++ "4: rep; movsb\n"
14114 ++ " movl %3,%0\n"
14115 ++ " shrl $2,%0\n"
14116 ++ " andl $3,%3\n"
14117 ++ " .align 2,0x90\n"
14118 ++ "0: rep; movsl\n"
14119 ++ " movl %3,%0\n"
14120 ++ "1: rep; movsb\n"
14121 ++ "2:\n"
14122 ++ " pushl %%ss\n"
14123 ++ " popl %%es\n"
14124 ++ ".section .fixup,\"ax\"\n"
14125 ++ "5: addl %3,%0\n"
14126 ++ " jmp 2b\n"
14127 ++ "3: lea 0(%3,%0,4),%0\n"
14128 ++ " jmp 2b\n"
14129 ++ ".previous\n"
14130 ++ ".section __ex_table,\"a\"\n"
14131 ++ " .align 4\n"
14132 ++ " .long 4b,5b\n"
14133 ++ " .long 0b,3b\n"
14134 ++ " .long 1b,2b\n"
14135 ++ ".previous"
14136 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
14137 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
14138 ++ : "memory");
14139 ++ return size;
14140 ++}
14141 ++
14142 ++static unsigned long
14143 ++__generic_copy_from_user(void *to, const void __user *from, unsigned long size)
14144 ++{
14145 ++ int __d0, __d1, __d2;
14146 ++
14147 ++ __asm__ __volatile__(
14148 ++ " movw %w8,%%ds\n"
14149 ++ " cmp $7,%0\n"
14150 ++ " jbe 1f\n"
14151 ++ " movl %1,%0\n"
14152 ++ " negl %0\n"
14153 ++ " andl $7,%0\n"
14154 ++ " subl %0,%3\n"
14155 ++ "4: rep; movsb\n"
14156 ++ " movl %3,%0\n"
14157 ++ " shrl $2,%0\n"
14158 ++ " andl $3,%3\n"
14159 ++ " .align 2,0x90\n"
14160 ++ "0: rep; movsl\n"
14161 ++ " movl %3,%0\n"
14162 ++ "1: rep; movsb\n"
14163 ++ "2:\n"
14164 ++ " pushl %%ss\n"
14165 ++ " popl %%ds\n"
14166 ++ ".section .fixup,\"ax\"\n"
14167 ++ "5: addl %3,%0\n"
14168 ++ " jmp 2b\n"
14169 ++ "3: lea 0(%3,%0,4),%0\n"
14170 ++ " jmp 2b\n"
14171 ++ ".previous\n"
14172 ++ ".section __ex_table,\"a\"\n"
14173 ++ " .align 4\n"
14174 ++ " .long 4b,5b\n"
14175 ++ " .long 0b,3b\n"
14176 ++ " .long 1b,2b\n"
14177 ++ ".previous"
14178 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
14179 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
14180 ++ : "memory");
14181 ++ return size;
14182 ++}
14183 ++
14184 ++static unsigned long
14185 ++__copy_user_zeroing(void *to, const void __user *from, unsigned long size)
14186 ++{
14187 ++ int __d0, __d1, __d2;
14188 ++
14189 ++ __asm__ __volatile__(
14190 ++ " movw %w8,%%ds\n"
14191 ++ " cmp $7,%0\n"
14192 ++ " jbe 1f\n"
14193 ++ " movl %1,%0\n"
14194 ++ " negl %0\n"
14195 ++ " andl $7,%0\n"
14196 ++ " subl %0,%3\n"
14197 ++ "4: rep; movsb\n"
14198 ++ " movl %3,%0\n"
14199 ++ " shrl $2,%0\n"
14200 ++ " andl $3,%3\n"
14201 ++ " .align 2,0x90\n"
14202 ++ "0: rep; movsl\n"
14203 ++ " movl %3,%0\n"
14204 ++ "1: rep; movsb\n"
14205 ++ "2:\n"
14206 ++ " pushl %%ss\n"
14207 ++ " popl %%ds\n"
14208 ++ ".section .fixup,\"ax\"\n"
14209 ++ "5: addl %3,%0\n"
14210 ++ " jmp 6f\n"
14211 ++ "3: lea 0(%3,%0,4),%0\n"
14212 ++ "6: pushl %0\n"
14213 ++ " pushl %%eax\n"
14214 ++ " xorl %%eax,%%eax\n"
14215 ++ " rep; stosb\n"
14216 ++ " popl %%eax\n"
14217 ++ " popl %0\n"
14218 ++ " jmp 2b\n"
14219 ++ ".previous\n"
14220 ++ ".section __ex_table,\"a\"\n"
14221 ++ " .align 4\n"
14222 ++ " .long 4b,5b\n"
14223 ++ " .long 0b,3b\n"
14224 ++ " .long 1b,6b\n"
14225 ++ ".previous"
14226 ++ : "=&c"(size), "=&D" (__d0), "=&S" (__d1), "=r"(__d2)
14227 ++ : "3"(size), "0"(size), "1"(to), "2"(from), "r"(__USER_DS)
14228 ++ : "memory");
14229 ++ return size;
14230 ++}
14231 +
14232 + unsigned long __copy_to_user_ll(void __user *to, const void *from,
14233 + unsigned long n)
14234 +@@ -775,9 +966,9 @@ survive:
14235 + }
14236 + #endif
14237 + if (movsl_is_ok(to, from, n))
14238 +- __copy_user(to, from, n);
14239 ++ n = __generic_copy_to_user(to, from, n);
14240 + else
14241 +- n = __copy_user_intel(to, from, n);
14242 ++ n = __generic_copy_to_user_intel(to, from, n);
14243 + return n;
14244 + }
14245 + EXPORT_SYMBOL(__copy_to_user_ll);
14246 +@@ -786,7 +977,7 @@ unsigned long __copy_from_user_ll(void *
14247 + unsigned long n)
14248 + {
14249 + if (movsl_is_ok(to, from, n))
14250 +- __copy_user_zeroing(to, from, n);
14251 ++ n = __copy_user_zeroing(to, from, n);
14252 + else
14253 + n = __copy_user_zeroing_intel(to, from, n);
14254 + return n;
14255 +@@ -797,10 +988,9 @@ unsigned long __copy_from_user_ll_nozero
14256 + unsigned long n)
14257 + {
14258 + if (movsl_is_ok(to, from, n))
14259 +- __copy_user(to, from, n);
14260 ++ n = __generic_copy_from_user(to, from, n);
14261 + else
14262 +- n = __copy_user_intel((void __user *)to,
14263 +- (const void *)from, n);
14264 ++ n = __generic_copy_from_user_intel(to, from, n);
14265 + return n;
14266 + }
14267 + EXPORT_SYMBOL(__copy_from_user_ll_nozero);
14268 +@@ -809,12 +999,12 @@ unsigned long __copy_from_user_ll_nocach
14269 + unsigned long n)
14270 + {
14271 + #ifdef CONFIG_X86_INTEL_USERCOPY
14272 +- if (n > 64 && cpu_has_xmm2)
14273 ++ if ( n > 64 && cpu_has_xmm2)
14274 + n = __copy_user_zeroing_intel_nocache(to, from, n);
14275 + else
14276 +- __copy_user_zeroing(to, from, n);
14277 ++ n = __copy_user_zeroing(to, from, n);
14278 + #else
14279 +- __copy_user_zeroing(to, from, n);
14280 ++ n = __copy_user_zeroing(to, from, n);
14281 + #endif
14282 + return n;
14283 + }
14284 +@@ -824,12 +1014,12 @@ unsigned long __copy_from_user_ll_nocach
14285 + unsigned long n)
14286 + {
14287 + #ifdef CONFIG_X86_INTEL_USERCOPY
14288 +- if (n > 64 && cpu_has_xmm2)
14289 ++ if ( n > 64 && cpu_has_xmm2)
14290 + n = __copy_user_intel_nocache(to, from, n);
14291 + else
14292 +- __copy_user(to, from, n);
14293 ++ n = __generic_copy_from_user(to, from, n);
14294 + #else
14295 +- __copy_user(to, from, n);
14296 ++ n = __generic_copy_from_user(to, from, n);
14297 + #endif
14298 + return n;
14299 + }
14300 +@@ -878,8 +1068,35 @@ copy_from_user(void *to, const void __us
14301 + {
14302 + if (access_ok(VERIFY_READ, from, n))
14303 + n = __copy_from_user(to, from, n);
14304 +- else
14305 ++ else if ((long)n > 0)
14306 + memset(to, 0, n);
14307 + return n;
14308 + }
14309 + EXPORT_SYMBOL(copy_from_user);
14310 ++
14311 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
14312 ++void __set_fs(mm_segment_t x, int cpu)
14313 ++{
14314 ++ unsigned long limit = x.seg;
14315 ++ struct desc_struct d;
14316 ++
14317 ++ current_thread_info()->addr_limit = x;
14318 ++ if (likely(limit))
14319 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
14320 ++ pack_descriptor(&d, 0UL, limit, 0xF3, 0xC);
14321 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_DS, &d, DESCTYPE_S);
14322 ++}
14323 ++
14324 ++void set_fs(mm_segment_t x)
14325 ++{
14326 ++ __set_fs(x, get_cpu());
14327 ++ put_cpu_no_resched();
14328 ++}
14329 ++#else
14330 ++void set_fs(mm_segment_t x)
14331 ++{
14332 ++ current_thread_info()->addr_limit = x;
14333 ++}
14334 ++#endif
14335 ++
14336 ++EXPORT_SYMBOL(set_fs);
14337 +diff -urNp linux-2.6.28/arch/x86/mach-voyager/voyager_basic.c linux-2.6.28/arch/x86/mach-voyager/voyager_basic.c
14338 +--- linux-2.6.28/arch/x86/mach-voyager/voyager_basic.c 2008-12-24 18:26:37.000000000 -0500
14339 ++++ linux-2.6.28/arch/x86/mach-voyager/voyager_basic.c 2009-01-11 07:20:06.000000000 -0500
14340 +@@ -123,7 +123,7 @@ int __init voyager_memory_detect(int reg
14341 + __u8 cmos[4];
14342 + ClickMap_t *map;
14343 + unsigned long map_addr;
14344 +- unsigned long old;
14345 ++ pte_t old;
14346 +
14347 + if (region >= CLICK_ENTRIES) {
14348 + printk("Voyager: Illegal ClickMap region %d\n", region);
14349 +@@ -138,7 +138,7 @@ int __init voyager_memory_detect(int reg
14350 +
14351 + /* steal page 0 for this */
14352 + old = pg0[0];
14353 +- pg0[0] = ((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
14354 ++ pg0[0] = __pte((map_addr & PAGE_MASK) | _PAGE_RW | _PAGE_PRESENT);
14355 + local_flush_tlb();
14356 + /* now clear everything out but page 0 */
14357 + map = (ClickMap_t *) (map_addr & (~PAGE_MASK));
14358 +diff -urNp linux-2.6.28/arch/x86/mach-voyager/voyager_smp.c linux-2.6.28/arch/x86/mach-voyager/voyager_smp.c
14359 +--- linux-2.6.28/arch/x86/mach-voyager/voyager_smp.c 2008-12-24 18:26:37.000000000 -0500
14360 ++++ linux-2.6.28/arch/x86/mach-voyager/voyager_smp.c 2009-01-11 07:20:06.000000000 -0500
14361 +@@ -521,6 +521,10 @@ static void __init do_boot_cpu(__u8 cpu)
14362 + __u32 *hijack_vector;
14363 + __u32 start_phys_address = setup_trampoline();
14364 +
14365 ++#ifdef CONFIG_PAX_KERNEXEC
14366 ++ unsigned long cr0;
14367 ++#endif
14368 ++
14369 + /* There's a clever trick to this: The linux trampoline is
14370 + * compiled to begin at absolute location zero, so make the
14371 + * address zero but have the data segment selector compensate
14372 +@@ -540,7 +544,17 @@ static void __init do_boot_cpu(__u8 cpu)
14373 +
14374 + init_gdt(cpu);
14375 + per_cpu(current_task, cpu) = idle;
14376 +- early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14377 ++
14378 ++#ifdef CONFIG_PAX_KERNEXEC
14379 ++ pax_open_kernel(cr0);
14380 ++#endif
14381 ++
14382 ++ early_gdt_descr.address = get_cpu_gdt_table(cpu);
14383 ++
14384 ++#ifdef CONFIG_PAX_KERNEXEC
14385 ++ pax_close_kernel(cr0);
14386 ++#endif
14387 ++
14388 + irq_ctx_init(cpu);
14389 +
14390 + /* Note: Don't modify initial ss override */
14391 +@@ -1154,7 +1168,7 @@ void smp_local_timer_interrupt(void)
14392 + per_cpu(prof_counter, cpu);
14393 + }
14394 +
14395 +- update_process_times(user_mode_vm(get_irq_regs()));
14396 ++ update_process_times(user_mode(get_irq_regs()));
14397 + }
14398 +
14399 + if (((1 << cpu) & voyager_extended_vic_processors) == 0)
14400 +diff -urNp linux-2.6.28/arch/x86/Makefile linux-2.6.28/arch/x86/Makefile
14401 +--- linux-2.6.28/arch/x86/Makefile 2008-12-24 18:26:37.000000000 -0500
14402 ++++ linux-2.6.28/arch/x86/Makefile 2009-01-11 07:20:06.000000000 -0500
14403 +@@ -232,3 +232,12 @@ endef
14404 + CLEAN_FILES += arch/x86/boot/fdimage \
14405 + arch/x86/boot/image.iso \
14406 + arch/x86/boot/mtools.conf
14407 ++
14408 ++define OLD_LD
14409 ++
14410 ++*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
14411 ++*** Please upgrade your binutils to 2.18 or newer
14412 ++endef
14413 ++
14414 ++archprepare:
14415 ++ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
14416 +diff -urNp linux-2.6.28/arch/x86/mm/extable.c linux-2.6.28/arch/x86/mm/extable.c
14417 +--- linux-2.6.28/arch/x86/mm/extable.c 2008-12-24 18:26:37.000000000 -0500
14418 ++++ linux-2.6.28/arch/x86/mm/extable.c 2009-01-11 07:20:06.000000000 -0500
14419 +@@ -1,14 +1,62 @@
14420 + #include <linux/module.h>
14421 + #include <linux/spinlock.h>
14422 ++#include <linux/sort.h>
14423 + #include <asm/uaccess.h>
14424 +
14425 ++/*
14426 ++ * The exception table needs to be sorted so that the binary
14427 ++ * search that we use to find entries in it works properly.
14428 ++ * This is used both for the kernel exception table and for
14429 ++ * the exception tables of modules that get loaded.
14430 ++ */
14431 ++static int cmp_ex(const void *a, const void *b)
14432 ++{
14433 ++ const struct exception_table_entry *x = a, *y = b;
14434 ++
14435 ++ /* avoid overflow */
14436 ++ if (x->insn > y->insn)
14437 ++ return 1;
14438 ++ if (x->insn < y->insn)
14439 ++ return -1;
14440 ++ return 0;
14441 ++}
14442 ++
14443 ++static void swap_ex(void *a, void *b, int size)
14444 ++{
14445 ++ struct exception_table_entry t, *x = a, *y = b;
14446 ++
14447 ++#ifdef CONFIG_PAX_KERNEXEC
14448 ++ unsigned long cr0;
14449 ++#endif
14450 ++
14451 ++ t = *x;
14452 ++
14453 ++#ifdef CONFIG_PAX_KERNEXEC
14454 ++ pax_open_kernel(cr0);
14455 ++#endif
14456 ++
14457 ++ *x = *y;
14458 ++ *y = t;
14459 ++
14460 ++#ifdef CONFIG_PAX_KERNEXEC
14461 ++ pax_close_kernel(cr0);
14462 ++#endif
14463 ++
14464 ++}
14465 ++
14466 ++void sort_extable(struct exception_table_entry *start,
14467 ++ struct exception_table_entry *finish)
14468 ++{
14469 ++ sort(start, finish - start, sizeof(struct exception_table_entry),
14470 ++ cmp_ex, swap_ex);
14471 ++}
14472 +
14473 + int fixup_exception(struct pt_regs *regs)
14474 + {
14475 + const struct exception_table_entry *fixup;
14476 +
14477 + #ifdef CONFIG_PNPBIOS
14478 +- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
14479 ++ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
14480 + extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
14481 + extern u32 pnp_bios_is_utter_crap;
14482 + pnp_bios_is_utter_crap = 1;
14483 +diff -urNp linux-2.6.28/arch/x86/mm/fault.c linux-2.6.28/arch/x86/mm/fault.c
14484 +--- linux-2.6.28/arch/x86/mm/fault.c 2008-12-24 18:26:37.000000000 -0500
14485 ++++ linux-2.6.28/arch/x86/mm/fault.c 2009-01-11 07:28:08.000000000 -0500
14486 +@@ -26,6 +26,8 @@
14487 + #include <linux/kprobes.h>
14488 + #include <linux/uaccess.h>
14489 + #include <linux/kdebug.h>
14490 ++#include <linux/unistd.h>
14491 ++#include <linux/compiler.h>
14492 +
14493 + #include <asm/system.h>
14494 + #include <asm/desc.h>
14495 +@@ -67,7 +69,7 @@ static inline int notify_page_fault(stru
14496 + int ret = 0;
14497 +
14498 + /* kprobe_running() needs smp_processor_id() */
14499 +- if (!user_mode_vm(regs)) {
14500 ++ if (!user_mode(regs)) {
14501 + preempt_disable();
14502 + if (kprobe_running() && kprobe_fault_handler(regs, 14))
14503 + ret = 1;
14504 +@@ -265,6 +267,30 @@ bad:
14505 + #endif
14506 + }
14507 +
14508 ++#ifdef CONFIG_PAX_EMUTRAMP
14509 ++static int pax_handle_fetch_fault(struct pt_regs *regs);
14510 ++#endif
14511 ++
14512 ++#ifdef CONFIG_PAX_PAGEEXEC
14513 ++static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
14514 ++{
14515 ++ pgd_t *pgd;
14516 ++ pud_t *pud;
14517 ++ pmd_t *pmd;
14518 ++
14519 ++ pgd = pgd_offset(mm, address);
14520 ++ if (!pgd_present(*pgd))
14521 ++ return NULL;
14522 ++ pud = pud_offset(pgd, address);
14523 ++ if (!pud_present(*pud))
14524 ++ return NULL;
14525 ++ pmd = pmd_offset(pud, address);
14526 ++ if (!pmd_present(*pmd))
14527 ++ return NULL;
14528 ++ return pmd;
14529 ++}
14530 ++#endif
14531 ++
14532 + #ifdef CONFIG_X86_32
14533 + static inline pmd_t *vmalloc_sync_one(pgd_t *pgd, unsigned long address)
14534 + {
14535 +@@ -351,7 +377,7 @@ static int is_errata93(struct pt_regs *r
14536 + static int is_errata100(struct pt_regs *regs, unsigned long address)
14537 + {
14538 + #ifdef CONFIG_X86_64
14539 +- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) &&
14540 ++ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) &&
14541 + (address >> 32))
14542 + return 1;
14543 + #endif
14544 +@@ -386,14 +412,31 @@ static void show_fault_oops(struct pt_re
14545 + #endif
14546 +
14547 + #ifdef CONFIG_X86_PAE
14548 +- if (error_code & PF_INSTR) {
14549 ++ if (nx_enabled && (error_code & PF_INSTR)) {
14550 + unsigned int level;
14551 + pte_t *pte = lookup_address(address, &level);
14552 +
14553 + if (pte && pte_present(*pte) && !pte_exec(*pte))
14554 + printk(KERN_CRIT "kernel tried to execute "
14555 + "NX-protected page - exploit attempt? "
14556 +- "(uid: %d)\n", current->uid);
14557 ++ "(uid: %d, task: %s, pid: %d)\n",
14558 ++ current->uid, current->comm, task_pid_nr(current));
14559 ++ }
14560 ++#endif
14561 ++
14562 ++#ifdef CONFIG_PAX_KERNEXEC
14563 ++#ifdef CONFIG_MODULES
14564 ++ if (init_mm.start_code <= address && address < (unsigned long)MODULES_END)
14565 ++#else
14566 ++ if (init_mm.start_code <= address && address < init_mm.end_code)
14567 ++#endif
14568 ++ {
14569 ++ if (current->signal->curr_ip)
14570 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
14571 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
14572 ++ else
14573 ++ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
14574 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
14575 + }
14576 + #endif
14577 +
14578 +@@ -585,20 +628,26 @@ void __kprobes do_page_fault(struct pt_r
14579 + struct task_struct *tsk;
14580 + struct mm_struct *mm;
14581 + struct vm_area_struct *vma;
14582 +- unsigned long address;
14583 + int write, si_code;
14584 + int fault;
14585 + #ifdef CONFIG_X86_64
14586 + unsigned long flags;
14587 + #endif
14588 +
14589 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14590 ++ pte_t *pte;
14591 ++ pmd_t *pmd;
14592 ++ spinlock_t *ptl;
14593 ++ unsigned char pte_mask;
14594 ++#endif
14595 ++
14596 ++ /* get the address */
14597 ++ const unsigned long address = read_cr2();
14598 ++
14599 + tsk = current;
14600 + mm = tsk->mm;
14601 + prefetchw(&mm->mmap_sem);
14602 +
14603 +- /* get the address */
14604 +- address = read_cr2();
14605 +-
14606 + si_code = SEGV_MAPERR;
14607 +
14608 + if (notify_page_fault(regs))
14609 +@@ -647,7 +696,7 @@ void __kprobes do_page_fault(struct pt_r
14610 + * User-mode registers count as a user access even for any
14611 + * potential system fault or CPU buglet.
14612 + */
14613 +- if (user_mode_vm(regs)) {
14614 ++ if (user_mode(regs)) {
14615 + local_irq_enable();
14616 + error_code |= PF_USER;
14617 + } else if (regs->flags & X86_EFLAGS_IF)
14618 +@@ -663,7 +712,7 @@ void __kprobes do_page_fault(struct pt_r
14619 + * atomic region then we must not take the fault.
14620 + */
14621 + if (unlikely(in_atomic() || !mm))
14622 +- goto bad_area_nosemaphore;
14623 ++ goto bad_area_nopax;
14624 +
14625 + again:
14626 + /*
14627 +@@ -685,10 +734,104 @@ again:
14628 + if (!down_read_trylock(&mm->mmap_sem)) {
14629 + if ((error_code & PF_USER) == 0 &&
14630 + !search_exception_tables(regs->ip))
14631 +- goto bad_area_nosemaphore;
14632 ++ goto bad_area_nopax;
14633 + down_read(&mm->mmap_sem);
14634 + }
14635 +
14636 ++#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14637 ++ if (nx_enabled || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
14638 ++ !(mm->pax_flags & MF_PAX_PAGEEXEC))
14639 ++ goto not_pax_fault;
14640 ++
14641 ++ /* PaX: it's our fault, let's handle it if we can */
14642 ++
14643 ++ /* PaX: take a look at read faults before acquiring any locks */
14644 ++ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
14645 ++ /* instruction fetch attempt from a protected page in user mode */
14646 ++ up_read(&mm->mmap_sem);
14647 ++
14648 ++#ifdef CONFIG_PAX_EMUTRAMP
14649 ++ switch (pax_handle_fetch_fault(regs)) {
14650 ++ case 2:
14651 ++ return;
14652 ++ }
14653 ++#endif
14654 ++
14655 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
14656 ++ do_group_exit(SIGKILL);
14657 ++ }
14658 ++
14659 ++ pmd = pax_get_pmd(mm, address);
14660 ++ if (unlikely(!pmd))
14661 ++ goto not_pax_fault;
14662 ++
14663 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
14664 ++ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
14665 ++ pte_unmap_unlock(pte, ptl);
14666 ++ goto not_pax_fault;
14667 ++ }
14668 ++
14669 ++ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
14670 ++ /* write attempt to a protected page in user mode */
14671 ++ pte_unmap_unlock(pte, ptl);
14672 ++ goto not_pax_fault;
14673 ++ }
14674 ++
14675 ++#ifdef CONFIG_SMP
14676 ++ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
14677 ++#else
14678 ++ if (likely(address > get_limit(regs->cs)))
14679 ++#endif
14680 ++ {
14681 ++ set_pte(pte, pte_mkread(*pte));
14682 ++ __flush_tlb_one(address);
14683 ++ pte_unmap_unlock(pte, ptl);
14684 ++ up_read(&mm->mmap_sem);
14685 ++ return;
14686 ++ }
14687 ++
14688 ++ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
14689 ++
14690 ++ /*
14691 ++ * PaX: fill DTLB with user rights and retry
14692 ++ */
14693 ++ __asm__ __volatile__ (
14694 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
14695 ++ "movw %w4,%%es\n"
14696 ++#endif
14697 ++ "orb %2,(%1)\n"
14698 ++#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
14699 ++/*
14700 ++ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
14701 ++ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
14702 ++ * page fault when examined during a TLB load attempt. this is true not only
14703 ++ * for PTEs holding a non-present entry but also present entries that will
14704 ++ * raise a page fault (such as those set up by PaX, or the copy-on-write
14705 ++ * mechanism). in effect it means that we do *not* need to flush the TLBs
14706 ++ * for our target pages since their PTEs are simply not in the TLBs at all.
14707 ++
14708 ++ * the best thing in omitting it is that we gain around 15-20% speed in the
14709 ++ * fast path of the page fault handler and can get rid of tracing since we
14710 ++ * can no longer flush unintended entries.
14711 ++ */
14712 ++ "invlpg (%0)\n"
14713 ++#endif
14714 ++ "testb $0,%%es:(%0)\n"
14715 ++ "xorb %3,(%1)\n"
14716 ++#ifdef CONFIG_PAX_MEMORY_UDEREF
14717 ++ "pushl %%ss\n"
14718 ++ "popl %%es\n"
14719 ++#endif
14720 ++ :
14721 ++ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER), "r" (__USER_DS)
14722 ++ : "memory", "cc");
14723 ++ pte_unmap_unlock(pte, ptl);
14724 ++ up_read(&mm->mmap_sem);
14725 ++ return;
14726 ++
14727 ++not_pax_fault:
14728 ++#endif
14729 ++
14730 + vma = find_vma(mm, address);
14731 + if (!vma)
14732 + goto bad_area;
14733 +@@ -696,16 +839,20 @@ again:
14734 + goto good_area;
14735 + if (!(vma->vm_flags & VM_GROWSDOWN))
14736 + goto bad_area;
14737 +- if (error_code & PF_USER) {
14738 +- /*
14739 +- * Accessing the stack below %sp is always a bug.
14740 +- * The large cushion allows instructions like enter
14741 +- * and pusha to work. ("enter $65535,$31" pushes
14742 +- * 32 pointers and then decrements %sp by 65535.)
14743 +- */
14744 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
14745 +- goto bad_area;
14746 +- }
14747 ++ /*
14748 ++ * Accessing the stack below %sp is always a bug.
14749 ++ * The large cushion allows instructions like enter
14750 ++ * and pusha to work. ("enter $65535,$31" pushes
14751 ++ * 32 pointers and then decrements %sp by 65535.)
14752 ++ */
14753 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
14754 ++ goto bad_area;
14755 ++
14756 ++#ifdef CONFIG_PAX_SEGMEXEC
14757 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)
14758 ++ goto bad_area;
14759 ++#endif
14760 ++
14761 + if (expand_stack(vma, address))
14762 + goto bad_area;
14763 + /*
14764 +@@ -715,6 +862,8 @@ again:
14765 + good_area:
14766 + si_code = SEGV_ACCERR;
14767 + write = 0;
14768 ++ if (nx_enabled && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
14769 ++ goto bad_area;
14770 + switch (error_code & (PF_PROT|PF_WRITE)) {
14771 + default: /* 3: write, present */
14772 + /* fall through */
14773 +@@ -769,6 +918,54 @@ bad_area:
14774 + up_read(&mm->mmap_sem);
14775 +
14776 + bad_area_nosemaphore:
14777 ++
14778 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14779 ++ if (mm && (error_code & PF_USER)) {
14780 ++ unsigned long ip = regs->ip;
14781 ++
14782 ++ if (v8086_mode(regs))
14783 ++ ip = ((regs->cs & 0xffff) << 4) + (regs->ip & 0xffff);
14784 ++
14785 ++ /*
14786 ++ * It's possible to have interrupts off here.
14787 ++ */
14788 ++ local_irq_enable();
14789 ++
14790 ++#ifdef CONFIG_PAX_PAGEEXEC
14791 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) &&
14792 ++ ((nx_enabled && (error_code & PF_INSTR)) || (!(error_code & (PF_PROT | PF_WRITE)) && regs->ip == address))) {
14793 ++
14794 ++#ifdef CONFIG_PAX_EMUTRAMP
14795 ++ switch (pax_handle_fetch_fault(regs)) {
14796 ++ case 2:
14797 ++ return;
14798 ++ }
14799 ++#endif
14800 ++
14801 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
14802 ++ do_group_exit(SIGKILL);
14803 ++ }
14804 ++#endif
14805 ++
14806 ++#ifdef CONFIG_PAX_SEGMEXEC
14807 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && !(error_code & (PF_PROT | PF_WRITE)) && (regs->ip + SEGMEXEC_TASK_SIZE == address)) {
14808 ++
14809 ++#ifdef CONFIG_PAX_EMUTRAMP
14810 ++ switch (pax_handle_fetch_fault(regs)) {
14811 ++ case 2:
14812 ++ return;
14813 ++ }
14814 ++#endif
14815 ++
14816 ++ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
14817 ++ do_group_exit(SIGKILL);
14818 ++ }
14819 ++#endif
14820 ++
14821 ++ }
14822 ++#endif
14823 ++
14824 ++bad_area_nopax:
14825 + /* User mode accesses just cause a SIGSEGV */
14826 + if (error_code & PF_USER) {
14827 + /*
14828 +@@ -847,7 +1044,7 @@ no_context:
14829 + #ifdef CONFIG_X86_32
14830 + die("Oops", regs, error_code);
14831 + bust_spinlocks(0);
14832 +- do_exit(SIGKILL);
14833 ++ do_group_exit(SIGKILL);
14834 + #else
14835 + if (__die("Oops", regs, error_code))
14836 + regs = NULL;
14837 +@@ -940,3 +1137,174 @@ void vmalloc_sync_all(void)
14838 + }
14839 + #endif
14840 + }
14841 ++
14842 ++#ifdef CONFIG_PAX_EMUTRAMP
14843 ++static int pax_handle_fetch_fault_32(struct pt_regs *regs)
14844 ++{
14845 ++ int err;
14846 ++
14847 ++ do { /* PaX: gcc trampoline emulation #1 */
14848 ++ unsigned char mov1, mov2;
14849 ++ unsigned short jmp;
14850 ++ unsigned int addr1, addr2;
14851 ++
14852 ++#ifdef CONFIG_X86_64
14853 ++ if ((regs->ip + 11) >> 32)
14854 ++ break;
14855 ++#endif
14856 ++
14857 ++ err = get_user(mov1, (unsigned char __user *)regs->ip);
14858 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
14859 ++ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
14860 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
14861 ++ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
14862 ++
14863 ++ if (err)
14864 ++ break;
14865 ++
14866 ++ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
14867 ++ regs->cx = addr1;
14868 ++ regs->ax = addr2;
14869 ++ regs->ip = addr2;
14870 ++ return 2;
14871 ++ }
14872 ++ } while (0);
14873 ++
14874 ++ do { /* PaX: gcc trampoline emulation #2 */
14875 ++ unsigned char mov, jmp;
14876 ++ unsigned int addr1, addr2;
14877 ++
14878 ++#ifdef CONFIG_X86_64
14879 ++ if ((regs->ip + 9) >> 32)
14880 ++ break;
14881 ++#endif
14882 ++
14883 ++ err = get_user(mov, (unsigned char __user *)regs->ip);
14884 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
14885 ++ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
14886 ++ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
14887 ++
14888 ++ if (err)
14889 ++ break;
14890 ++
14891 ++ if (mov == 0xB9 && jmp == 0xE9) {
14892 ++ regs->cx = addr1;
14893 ++ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
14894 ++ return 2;
14895 ++ }
14896 ++ } while (0);
14897 ++
14898 ++ return 1; /* PaX in action */
14899 ++}
14900 ++
14901 ++#ifdef CONFIG_X86_64
14902 ++static int pax_handle_fetch_fault_64(struct pt_regs *regs)
14903 ++{
14904 ++ int err;
14905 ++
14906 ++ do { /* PaX: gcc trampoline emulation #1 */
14907 ++ unsigned short mov1, mov2, jmp1;
14908 ++ unsigned char jmp2;
14909 ++ unsigned int addr1;
14910 ++ unsigned long addr2;
14911 ++
14912 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
14913 ++ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
14914 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
14915 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
14916 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
14917 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
14918 ++
14919 ++ if (err)
14920 ++ break;
14921 ++
14922 ++ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
14923 ++ regs->r11 = addr1;
14924 ++ regs->r10 = addr2;
14925 ++ regs->ip = addr1;
14926 ++ return 2;
14927 ++ }
14928 ++ } while (0);
14929 ++
14930 ++ do { /* PaX: gcc trampoline emulation #2 */
14931 ++ unsigned short mov1, mov2, jmp1;
14932 ++ unsigned char jmp2;
14933 ++ unsigned long addr1, addr2;
14934 ++
14935 ++ err = get_user(mov1, (unsigned short __user *)regs->ip);
14936 ++ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
14937 ++ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
14938 ++ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
14939 ++ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
14940 ++ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
14941 ++
14942 ++ if (err)
14943 ++ break;
14944 ++
14945 ++ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
14946 ++ regs->r11 = addr1;
14947 ++ regs->r10 = addr2;
14948 ++ regs->ip = addr1;
14949 ++ return 2;
14950 ++ }
14951 ++ } while (0);
14952 ++
14953 ++ return 1; /* PaX in action */
14954 ++}
14955 ++#endif
14956 ++
14957 ++/*
14958 ++ * PaX: decide what to do with offenders (regs->ip = fault address)
14959 ++ *
14960 ++ * returns 1 when task should be killed
14961 ++ * 2 when gcc trampoline was detected
14962 ++ */
14963 ++static int pax_handle_fetch_fault(struct pt_regs *regs)
14964 ++{
14965 ++ if (v8086_mode(regs))
14966 ++ return 1;
14967 ++
14968 ++ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
14969 ++ return 1;
14970 ++
14971 ++#ifdef CONFIG_X86_32
14972 ++ return pax_handle_fetch_fault_32(regs);
14973 ++#else
14974 ++ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
14975 ++ return pax_handle_fetch_fault_32(regs);
14976 ++ else
14977 ++ return pax_handle_fetch_fault_64(regs);
14978 ++#endif
14979 ++}
14980 ++#endif
14981 ++
14982 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
14983 ++void pax_report_insns(void *pc, void *sp)
14984 ++{
14985 ++ long i;
14986 ++
14987 ++ printk(KERN_ERR "PAX: bytes at PC: ");
14988 ++ for (i = 0; i < 20; i++) {
14989 ++ unsigned char c;
14990 ++ if (get_user(c, (unsigned char __user *)pc+i))
14991 ++ printk(KERN_CONT "?? ");
14992 ++ else
14993 ++ printk(KERN_CONT "%02x ", c);
14994 ++ }
14995 ++ printk("\n");
14996 ++
14997 ++ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
14998 ++ for (i = -1; i < 80 / sizeof(long); i++) {
14999 ++ unsigned long c;
15000 ++ if (get_user(c, (unsigned long __user *)sp+i))
15001 ++#ifdef CONFIG_X86_32
15002 ++ printk(KERN_CONT "???????? ");
15003 ++#else
15004 ++ printk(KERN_CONT "???????????????? ");
15005 ++#endif
15006 ++ else
15007 ++ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
15008 ++ }
15009 ++ printk("\n");
15010 ++}
15011 ++#endif
15012 +diff -urNp linux-2.6.28/arch/x86/mm/highmem_32.c linux-2.6.28/arch/x86/mm/highmem_32.c
15013 +--- linux-2.6.28/arch/x86/mm/highmem_32.c 2008-12-24 18:26:37.000000000 -0500
15014 ++++ linux-2.6.28/arch/x86/mm/highmem_32.c 2009-01-11 07:20:06.000000000 -0500
15015 +@@ -74,6 +74,10 @@ void *kmap_atomic_prot(struct page *page
15016 + enum fixed_addresses idx;
15017 + unsigned long vaddr;
15018 +
15019 ++#ifdef CONFIG_PAX_KERNEXEC
15020 ++ unsigned long cr0;
15021 ++#endif
15022 ++
15023 + /* even !CONFIG_PREEMPT needs this, for in_atomic in do_page_fault */
15024 + pagefault_disable();
15025 +
15026 +@@ -85,7 +89,17 @@ void *kmap_atomic_prot(struct page *page
15027 + idx = type + KM_TYPE_NR*smp_processor_id();
15028 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
15029 + BUG_ON(!pte_none(*(kmap_pte-idx)));
15030 ++
15031 ++#ifdef CONFIG_PAX_KERNEXEC
15032 ++ pax_open_kernel(cr0);
15033 ++#endif
15034 ++
15035 + set_pte(kmap_pte-idx, mk_pte(page, prot));
15036 ++
15037 ++#ifdef CONFIG_PAX_KERNEXEC
15038 ++ pax_close_kernel(cr0);
15039 ++#endif
15040 ++
15041 + arch_flush_lazy_mmu_mode();
15042 +
15043 + return (void *)vaddr;
15044 +@@ -101,15 +115,29 @@ void kunmap_atomic(void *kvaddr, enum km
15045 + unsigned long vaddr = (unsigned long) kvaddr & PAGE_MASK;
15046 + enum fixed_addresses idx = type + KM_TYPE_NR*smp_processor_id();
15047 +
15048 ++#ifdef CONFIG_PAX_KERNEXEC
15049 ++ unsigned long cr0;
15050 ++#endif
15051 ++
15052 + /*
15053 + * Force other mappings to Oops if they'll try to access this pte
15054 + * without first remap it. Keeping stale mappings around is a bad idea
15055 + * also, in case the page changes cacheability attributes or becomes
15056 + * a protected page in a hypervisor.
15057 + */
15058 +- if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx))
15059 ++ if (vaddr == __fix_to_virt(FIX_KMAP_BEGIN+idx)) {
15060 ++
15061 ++#ifdef CONFIG_PAX_KERNEXEC
15062 ++ pax_open_kernel(cr0);
15063 ++#endif
15064 ++
15065 + kpte_clear_flush(kmap_pte-idx, vaddr);
15066 +- else {
15067 ++
15068 ++#ifdef CONFIG_PAX_KERNEXEC
15069 ++ pax_close_kernel(cr0);
15070 ++#endif
15071 ++
15072 ++ } else {
15073 + #ifdef CONFIG_DEBUG_HIGHMEM
15074 + BUG_ON(vaddr < PAGE_OFFSET);
15075 + BUG_ON(vaddr >= (unsigned long)high_memory);
15076 +@@ -128,11 +156,25 @@ void *kmap_atomic_pfn(unsigned long pfn,
15077 + enum fixed_addresses idx;
15078 + unsigned long vaddr;
15079 +
15080 ++#ifdef CONFIG_PAX_KERNEXEC
15081 ++ unsigned long cr0;
15082 ++#endif
15083 ++
15084 + pagefault_disable();
15085 +
15086 + idx = type + KM_TYPE_NR*smp_processor_id();
15087 + vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
15088 ++
15089 ++#ifdef CONFIG_PAX_KERNEXEC
15090 ++ pax_open_kernel(cr0);
15091 ++#endif
15092 ++
15093 + set_pte(kmap_pte-idx, pfn_pte(pfn, kmap_prot));
15094 ++
15095 ++#ifdef CONFIG_PAX_KERNEXEC
15096 ++ pax_close_kernel(cr0);
15097 ++#endif
15098 ++
15099 + arch_flush_lazy_mmu_mode();
15100 +
15101 + return (void*) vaddr;
15102 +diff -urNp linux-2.6.28/arch/x86/mm/hugetlbpage.c linux-2.6.28/arch/x86/mm/hugetlbpage.c
15103 +--- linux-2.6.28/arch/x86/mm/hugetlbpage.c 2008-12-24 18:26:37.000000000 -0500
15104 ++++ linux-2.6.28/arch/x86/mm/hugetlbpage.c 2009-01-11 07:20:06.000000000 -0500
15105 +@@ -263,13 +263,18 @@ static unsigned long hugetlb_get_unmappe
15106 + struct hstate *h = hstate_file(file);
15107 + struct mm_struct *mm = current->mm;
15108 + struct vm_area_struct *vma;
15109 +- unsigned long start_addr;
15110 ++ unsigned long start_addr, pax_task_size = TASK_SIZE;
15111 ++
15112 ++#ifdef CONFIG_PAX_SEGMEXEC
15113 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
15114 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
15115 ++#endif
15116 +
15117 + if (len > mm->cached_hole_size) {
15118 +- start_addr = mm->free_area_cache;
15119 ++ start_addr = mm->free_area_cache;
15120 + } else {
15121 +- start_addr = TASK_UNMAPPED_BASE;
15122 +- mm->cached_hole_size = 0;
15123 ++ start_addr = mm->mmap_base;
15124 ++ mm->cached_hole_size = 0;
15125 + }
15126 +
15127 + full_search:
15128 +@@ -277,13 +282,13 @@ full_search:
15129 +
15130 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
15131 + /* At this point: (!vma || addr < vma->vm_end). */
15132 +- if (TASK_SIZE - len < addr) {
15133 ++ if (pax_task_size - len < addr) {
15134 + /*
15135 + * Start a new search - just in case we missed
15136 + * some holes.
15137 + */
15138 +- if (start_addr != TASK_UNMAPPED_BASE) {
15139 +- start_addr = TASK_UNMAPPED_BASE;
15140 ++ if (start_addr != mm->mmap_base) {
15141 ++ start_addr = mm->mmap_base;
15142 + mm->cached_hole_size = 0;
15143 + goto full_search;
15144 + }
15145 +@@ -306,9 +311,8 @@ static unsigned long hugetlb_get_unmappe
15146 + struct hstate *h = hstate_file(file);
15147 + struct mm_struct *mm = current->mm;
15148 + struct vm_area_struct *vma, *prev_vma;
15149 +- unsigned long base = mm->mmap_base, addr = addr0;
15150 ++ unsigned long base = mm->mmap_base, addr;
15151 + unsigned long largest_hole = mm->cached_hole_size;
15152 +- int first_time = 1;
15153 +
15154 + /* don't allow allocations above current base */
15155 + if (mm->free_area_cache > base)
15156 +@@ -318,7 +322,7 @@ static unsigned long hugetlb_get_unmappe
15157 + largest_hole = 0;
15158 + mm->free_area_cache = base;
15159 + }
15160 +-try_again:
15161 ++
15162 + /* make sure it can fit in the remaining address space */
15163 + if (mm->free_area_cache < len)
15164 + goto fail;
15165 +@@ -360,22 +364,26 @@ try_again:
15166 +
15167 + fail:
15168 + /*
15169 +- * if hint left us with no space for the requested
15170 +- * mapping then try again:
15171 +- */
15172 +- if (first_time) {
15173 +- mm->free_area_cache = base;
15174 +- largest_hole = 0;
15175 +- first_time = 0;
15176 +- goto try_again;
15177 +- }
15178 +- /*
15179 + * A failed mmap() very likely causes application failure,
15180 + * so fall back to the bottom-up function here. This scenario
15181 + * can happen with large stack limits and large mmap()
15182 + * allocations.
15183 + */
15184 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
15185 ++
15186 ++#ifdef CONFIG_PAX_SEGMEXEC
15187 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
15188 ++ mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
15189 ++ else
15190 ++#endif
15191 ++
15192 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
15193 ++
15194 ++#ifdef CONFIG_PAX_RANDMMAP
15195 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
15196 ++ mm->mmap_base += mm->delta_mmap;
15197 ++#endif
15198 ++
15199 ++ mm->free_area_cache = mm->mmap_base;
15200 + mm->cached_hole_size = ~0UL;
15201 + addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
15202 + len, pgoff, flags);
15203 +@@ -383,6 +391,7 @@ fail:
15204 + /*
15205 + * Restore the topdown base:
15206 + */
15207 ++ mm->mmap_base = base;
15208 + mm->free_area_cache = base;
15209 + mm->cached_hole_size = ~0UL;
15210 +
15211 +@@ -396,10 +405,17 @@ hugetlb_get_unmapped_area(struct file *f
15212 + struct hstate *h = hstate_file(file);
15213 + struct mm_struct *mm = current->mm;
15214 + struct vm_area_struct *vma;
15215 ++ unsigned long pax_task_size = TASK_SIZE;
15216 +
15217 + if (len & ~huge_page_mask(h))
15218 + return -EINVAL;
15219 +- if (len > TASK_SIZE)
15220 ++
15221 ++#ifdef CONFIG_PAX_SEGMEXEC
15222 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
15223 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
15224 ++#endif
15225 ++
15226 ++ if (len > pax_task_size)
15227 + return -ENOMEM;
15228 +
15229 + if (flags & MAP_FIXED) {
15230 +@@ -411,7 +427,7 @@ hugetlb_get_unmapped_area(struct file *f
15231 + if (addr) {
15232 + addr = ALIGN(addr, huge_page_size(h));
15233 + vma = find_vma(mm, addr);
15234 +- if (TASK_SIZE - len >= addr &&
15235 ++ if (pax_task_size - len >= addr &&
15236 + (!vma || addr + len <= vma->vm_start))
15237 + return addr;
15238 + }
15239 +diff -urNp linux-2.6.28/arch/x86/mm/init_32.c linux-2.6.28/arch/x86/mm/init_32.c
15240 +--- linux-2.6.28/arch/x86/mm/init_32.c 2008-12-24 18:26:37.000000000 -0500
15241 ++++ linux-2.6.28/arch/x86/mm/init_32.c 2009-01-11 07:20:06.000000000 -0500
15242 +@@ -49,6 +49,7 @@
15243 + #include <asm/setup.h>
15244 + #include <asm/cacheflush.h>
15245 + #include <asm/smp.h>
15246 ++#include <asm/desc.h>
15247 +
15248 + unsigned int __VMALLOC_RESERVE = 128 << 20;
15249 +
15250 +@@ -82,35 +83,6 @@ static __init void *alloc_low_page(unsig
15251 + }
15252 +
15253 + /*
15254 +- * Creates a middle page table and puts a pointer to it in the
15255 +- * given global directory entry. This only returns the gd entry
15256 +- * in non-PAE compilation mode, since the middle layer is folded.
15257 +- */
15258 +-static pmd_t * __init one_md_table_init(pgd_t *pgd)
15259 +-{
15260 +- pud_t *pud;
15261 +- pmd_t *pmd_table;
15262 +-
15263 +-#ifdef CONFIG_X86_PAE
15264 +- unsigned long phys;
15265 +- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
15266 +- if (after_init_bootmem)
15267 +- pmd_table = (pmd_t *)alloc_bootmem_low_pages(PAGE_SIZE);
15268 +- else
15269 +- pmd_table = (pmd_t *)alloc_low_page(&phys);
15270 +- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
15271 +- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
15272 +- pud = pud_offset(pgd, 0);
15273 +- BUG_ON(pmd_table != pmd_offset(pud, 0));
15274 +- }
15275 +-#endif
15276 +- pud = pud_offset(pgd, 0);
15277 +- pmd_table = pmd_offset(pud, 0);
15278 +-
15279 +- return pmd_table;
15280 +-}
15281 +-
15282 +-/*
15283 + * Create a page table and place a pointer to it in a middle page
15284 + * directory entry:
15285 + */
15286 +@@ -132,7 +104,11 @@ static pte_t * __init one_page_table_ini
15287 + }
15288 +
15289 + paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
15290 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
15291 ++ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
15292 ++#else
15293 + set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
15294 ++#endif
15295 + BUG_ON(page_table != pte_offset_kernel(pmd, 0));
15296 + }
15297 +
15298 +@@ -154,6 +130,7 @@ page_table_range_init(unsigned long star
15299 + int pgd_idx, pmd_idx;
15300 + unsigned long vaddr;
15301 + pgd_t *pgd;
15302 ++ pud_t *pud;
15303 + pmd_t *pmd;
15304 +
15305 + vaddr = start;
15306 +@@ -162,8 +139,13 @@ page_table_range_init(unsigned long star
15307 + pgd = pgd_base + pgd_idx;
15308 +
15309 + for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
15310 +- pmd = one_md_table_init(pgd);
15311 +- pmd = pmd + pmd_index(vaddr);
15312 ++ pud = pud_offset(pgd, vaddr);
15313 ++ pmd = pmd_offset(pud, vaddr);
15314 ++
15315 ++#ifdef CONFIG_X86_PAE
15316 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
15317 ++#endif
15318 ++
15319 + for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
15320 + pmd++, pmd_idx++) {
15321 + one_page_table_init(pmd);
15322 +@@ -174,11 +156,23 @@ page_table_range_init(unsigned long star
15323 + }
15324 + }
15325 +
15326 +-static inline int is_kernel_text(unsigned long addr)
15327 ++static inline int is_kernel_text(unsigned long start, unsigned long end)
15328 + {
15329 +- if (addr >= PAGE_OFFSET && addr <= (unsigned long)__init_end)
15330 +- return 1;
15331 +- return 0;
15332 ++ unsigned long etext;
15333 ++
15334 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
15335 ++ etext = ktva_ktla((unsigned long)&MODULES_END);
15336 ++#else
15337 ++ etext = (unsigned long)&_etext;
15338 ++#endif
15339 ++
15340 ++ if ((start > ktla_ktva(etext) ||
15341 ++ end <= ktla_ktva((unsigned long)_stext)) &&
15342 ++ (start > ktla_ktva((unsigned long)_einittext) ||
15343 ++ end <= ktla_ktva((unsigned long)_sinittext)) &&
15344 ++ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
15345 ++ return 0;
15346 ++ return 1;
15347 + }
15348 +
15349 + /*
15350 +@@ -191,9 +185,10 @@ static void __init kernel_physical_mappi
15351 + unsigned long end_pfn,
15352 + int use_pse)
15353 + {
15354 +- int pgd_idx, pmd_idx, pte_ofs;
15355 ++ unsigned int pgd_idx, pmd_idx, pte_ofs;
15356 + unsigned long pfn;
15357 + pgd_t *pgd;
15358 ++ pud_t *pud;
15359 + pmd_t *pmd;
15360 + pte_t *pte;
15361 + unsigned pages_2m, pages_4k;
15362 +@@ -223,8 +218,13 @@ repeat:
15363 + pfn = start_pfn;
15364 + pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
15365 + pgd = pgd_base + pgd_idx;
15366 +- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
15367 +- pmd = one_md_table_init(pgd);
15368 ++ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
15369 ++ pud = pud_offset(pgd, 0);
15370 ++ pmd = pmd_offset(pud, 0);
15371 ++
15372 ++#ifdef CONFIG_X86_PAE
15373 ++ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
15374 ++#endif
15375 +
15376 + if (pfn >= end_pfn)
15377 + continue;
15378 +@@ -236,14 +236,13 @@ repeat:
15379 + #endif
15380 + for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
15381 + pmd++, pmd_idx++) {
15382 +- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
15383 ++ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
15384 +
15385 + /*
15386 + * Map with big pages if possible, otherwise
15387 + * create normal page tables:
15388 + */
15389 + if (use_pse) {
15390 +- unsigned int addr2;
15391 + pgprot_t prot = PAGE_KERNEL_LARGE;
15392 + /*
15393 + * first pass will use the same initial
15394 +@@ -253,11 +252,7 @@ repeat:
15395 + __pgprot(PTE_IDENT_ATTR |
15396 + _PAGE_PSE);
15397 +
15398 +- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
15399 +- PAGE_OFFSET + PAGE_SIZE-1;
15400 +-
15401 +- if (is_kernel_text(addr) ||
15402 +- is_kernel_text(addr2))
15403 ++ if (is_kernel_text(address, address + PMD_SIZE))
15404 + prot = PAGE_KERNEL_LARGE_EXEC;
15405 +
15406 + pages_2m++;
15407 +@@ -274,7 +269,7 @@ repeat:
15408 + pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
15409 + pte += pte_ofs;
15410 + for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
15411 +- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
15412 ++ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
15413 + pgprot_t prot = PAGE_KERNEL;
15414 + /*
15415 + * first pass will use the same initial
15416 +@@ -282,7 +277,7 @@ repeat:
15417 + */
15418 + pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
15419 +
15420 +- if (is_kernel_text(addr))
15421 ++ if (is_kernel_text(address, address + PAGE_SIZE))
15422 + prot = PAGE_KERNEL_EXEC;
15423 +
15424 + pages_4k++;
15425 +@@ -327,7 +322,9 @@ repeat:
15426 + */
15427 + int devmem_is_allowed(unsigned long pagenr)
15428 + {
15429 +- if (pagenr <= 256)
15430 ++ if (!pagenr)
15431 ++ return 1;
15432 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
15433 + return 1;
15434 + if (!page_is_ram(pagenr))
15435 + return 1;
15436 +@@ -460,7 +457,7 @@ void __init native_pagetable_setup_start
15437 +
15438 + pud = pud_offset(pgd, va);
15439 + pmd = pmd_offset(pud, va);
15440 +- if (!pmd_present(*pmd))
15441 ++ if (!pmd_present(*pmd) || pmd_huge(*pmd))
15442 + break;
15443 +
15444 + pte = pte_offset_kernel(pmd, va);
15445 +@@ -512,9 +509,7 @@ static void __init early_ioremap_page_ta
15446 +
15447 + static void __init pagetable_init(void)
15448 + {
15449 +- pgd_t *pgd_base = swapper_pg_dir;
15450 +-
15451 +- permanent_kmaps_init(pgd_base);
15452 ++ permanent_kmaps_init(swapper_pg_dir);
15453 + }
15454 +
15455 + #ifdef CONFIG_ACPI_SLEEP
15456 +@@ -522,12 +517,12 @@ static void __init pagetable_init(void)
15457 + * ACPI suspend needs this for resume, because things like the intel-agp
15458 + * driver might have split up a kernel 4MB mapping.
15459 + */
15460 +-char swsusp_pg_dir[PAGE_SIZE]
15461 ++pgd_t swsusp_pg_dir[PTRS_PER_PGD]
15462 + __attribute__ ((aligned(PAGE_SIZE)));
15463 +
15464 + static inline void save_pg_dir(void)
15465 + {
15466 +- memcpy(swsusp_pg_dir, swapper_pg_dir, PAGE_SIZE);
15467 ++ clone_pgd_range(swsusp_pg_dir, swapper_pg_dir, PTRS_PER_PGD);
15468 + }
15469 + #else /* !CONFIG_ACPI_SLEEP */
15470 + static inline void save_pg_dir(void)
15471 +@@ -557,13 +552,11 @@ void zap_low_mappings(void)
15472 +
15473 + int nx_enabled;
15474 +
15475 +-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
15476 ++pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
15477 + EXPORT_SYMBOL_GPL(__supported_pte_mask);
15478 +
15479 + #ifdef CONFIG_X86_PAE
15480 +
15481 +-static int disable_nx __initdata;
15482 +-
15483 + /*
15484 + * noexec = on|off
15485 + *
15486 +@@ -572,40 +565,33 @@ static int disable_nx __initdata;
15487 + * on Enable
15488 + * off Disable
15489 + */
15490 ++#if !defined(CONFIG_PAX_PAGEEXEC)
15491 + static int __init noexec_setup(char *str)
15492 + {
15493 + if (!str || !strcmp(str, "on")) {
15494 +- if (cpu_has_nx) {
15495 +- __supported_pte_mask |= _PAGE_NX;
15496 +- disable_nx = 0;
15497 +- }
15498 ++ if (cpu_has_nx)
15499 ++ nx_enabled = 1;
15500 + } else {
15501 +- if (!strcmp(str, "off")) {
15502 +- disable_nx = 1;
15503 +- __supported_pte_mask &= ~_PAGE_NX;
15504 +- } else {
15505 ++ if (!strcmp(str, "off"))
15506 ++ nx_enabled = 0;
15507 ++ else
15508 + return -EINVAL;
15509 +- }
15510 + }
15511 +
15512 + return 0;
15513 + }
15514 + early_param("noexec", noexec_setup);
15515 ++#endif
15516 +
15517 + static void __init set_nx(void)
15518 + {
15519 +- unsigned int v[4], l, h;
15520 +-
15521 +- if (cpu_has_pae && (cpuid_eax(0x80000000) > 0x80000001)) {
15522 +- cpuid(0x80000001, &v[0], &v[1], &v[2], &v[3]);
15523 ++ if (!nx_enabled && cpu_has_nx) {
15524 ++ unsigned l, h;
15525 +
15526 +- if ((v[3] & (1 << 20)) && !disable_nx) {
15527 +- rdmsr(MSR_EFER, l, h);
15528 +- l |= EFER_NX;
15529 +- wrmsr(MSR_EFER, l, h);
15530 +- nx_enabled = 1;
15531 +- __supported_pte_mask |= _PAGE_NX;
15532 +- }
15533 ++ __supported_pte_mask &= ~_PAGE_NX;
15534 ++ rdmsr(MSR_EFER, l, h);
15535 ++ l &= ~EFER_NX;
15536 ++ wrmsr(MSR_EFER, l, h);
15537 + }
15538 + }
15539 + #endif
15540 +@@ -988,7 +974,7 @@ void __init mem_init(void)
15541 + set_highmem_pages_init();
15542 +
15543 + codesize = (unsigned long) &_etext - (unsigned long) &_text;
15544 +- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
15545 ++ datasize = (unsigned long) &_edata - (unsigned long) &_data;
15546 + initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
15547 +
15548 + kclist_add(&kcore_mem, __va(0), max_low_pfn << PAGE_SHIFT);
15549 +@@ -1034,10 +1020,10 @@ void __init mem_init(void)
15550 + ((unsigned long)&__init_end -
15551 + (unsigned long)&__init_begin) >> 10,
15552 +
15553 +- (unsigned long)&_etext, (unsigned long)&_edata,
15554 +- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
15555 ++ (unsigned long)&_data, (unsigned long)&_edata,
15556 ++ ((unsigned long)&_edata - (unsigned long)&_data) >> 10,
15557 +
15558 +- (unsigned long)&_text, (unsigned long)&_etext,
15559 ++ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
15560 + ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
15561 +
15562 + #ifdef CONFIG_HIGHMEM
15563 +@@ -1166,6 +1152,46 @@ void free_init_pages(char *what, unsigne
15564 +
15565 + void free_initmem(void)
15566 + {
15567 ++
15568 ++#ifdef CONFIG_PAX_KERNEXEC
15569 ++ /* PaX: limit KERNEL_CS to actual size */
15570 ++ unsigned long addr, limit;
15571 ++ struct desc_struct d;
15572 ++ int cpu;
15573 ++ pgd_t *pgd;
15574 ++ pud_t *pud;
15575 ++ pmd_t *pmd;
15576 ++
15577 ++#ifdef CONFIG_MODULES
15578 ++ limit = ktva_ktla((unsigned long)&MODULES_END);
15579 ++#else
15580 ++ limit = (unsigned long)&_etext;
15581 ++#endif
15582 ++ limit = (limit - 1UL) >> PAGE_SHIFT;
15583 ++
15584 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
15585 ++ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
15586 ++ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
15587 ++ }
15588 ++
15589 ++ /* PaX: make KERNEL_CS read-only */
15590 ++ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_data; addr += PMD_SIZE) {
15591 ++ pgd = pgd_offset_k(addr);
15592 ++ pud = pud_offset(pgd, addr);
15593 ++ pmd = pmd_offset(pud, addr);
15594 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
15595 ++ }
15596 ++#ifdef CONFIG_X86_PAE
15597 ++ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
15598 ++ pgd = pgd_offset_k(addr);
15599 ++ pud = pud_offset(pgd, addr);
15600 ++ pmd = pmd_offset(pud, addr);
15601 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
15602 ++ }
15603 ++#endif
15604 ++ flush_tlb_all();
15605 ++#endif
15606 ++
15607 + free_init_pages("unused kernel memory",
15608 + (unsigned long)(&__init_begin),
15609 + (unsigned long)(&__init_end));
15610 +diff -urNp linux-2.6.28/arch/x86/mm/init_64.c linux-2.6.28/arch/x86/mm/init_64.c
15611 +--- linux-2.6.28/arch/x86/mm/init_64.c 2008-12-24 18:26:37.000000000 -0500
15612 ++++ linux-2.6.28/arch/x86/mm/init_64.c 2009-01-11 07:20:06.000000000 -0500
15613 +@@ -175,6 +175,10 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
15614 + pmd_t *pmd;
15615 + pte_t *pte;
15616 +
15617 ++#ifdef CONFIG_PAX_KERNEXEC
15618 ++ unsigned long cr0;
15619 ++#endif
15620 ++
15621 + pud = pud_page + pud_index(vaddr);
15622 + if (pud_none(*pud)) {
15623 + pmd = (pmd_t *) spp_getpage();
15624 +@@ -196,8 +200,17 @@ set_pte_vaddr_pud(pud_t *pud_page, unsig
15625 + }
15626 +
15627 + pte = pte_offset_kernel(pmd, vaddr);
15628 ++
15629 ++#ifdef CONFIG_PAX_KERNEXEC
15630 ++ pax_open_kernel(cr0);
15631 ++#endif
15632 ++
15633 + set_pte(pte, new_pte);
15634 +
15635 ++#ifdef CONFIG_PAX_KERNEXEC
15636 ++ pax_close_kernel(cr0);
15637 ++#endif
15638 ++
15639 + /*
15640 + * It's enough to flush this one mapping.
15641 + * (PGE mappings get flushed as well)
15642 +@@ -238,14 +251,12 @@ static void __init __init_extra_mapping(
15643 + pgd = pgd_offset_k((unsigned long)__va(phys));
15644 + if (pgd_none(*pgd)) {
15645 + pud = (pud_t *) spp_getpage();
15646 +- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
15647 +- _PAGE_USER));
15648 ++ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
15649 + }
15650 + pud = pud_offset(pgd, (unsigned long)__va(phys));
15651 + if (pud_none(*pud)) {
15652 + pmd = (pmd_t *) spp_getpage();
15653 +- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
15654 +- _PAGE_USER));
15655 ++ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
15656 + }
15657 + pmd = pmd_offset(pud, phys);
15658 + BUG_ON(!pmd_none(*pmd));
15659 +@@ -886,7 +897,9 @@ EXPORT_SYMBOL_GPL(memory_add_physaddr_to
15660 + */
15661 + int devmem_is_allowed(unsigned long pagenr)
15662 + {
15663 +- if (pagenr <= 256)
15664 ++ if (!pagenr)
15665 ++ return 1;
15666 ++ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
15667 + return 1;
15668 + if (!page_is_ram(pagenr))
15669 + return 1;
15670 +@@ -977,6 +990,39 @@ void free_init_pages(char *what, unsigne
15671 +
15672 + void free_initmem(void)
15673 + {
15674 ++
15675 ++#ifdef CONFIG_PAX_KERNEXEC
15676 ++ unsigned long addr, end;
15677 ++ pgd_t *pgd;
15678 ++ pud_t *pud;
15679 ++ pmd_t *pmd;
15680 ++
15681 ++ /* PaX: make kernel code/rodata read-only, rest non-executable */
15682 ++ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
15683 ++ pgd = pgd_offset_k(addr);
15684 ++ pud = pud_offset(pgd, addr);
15685 ++ pmd = pmd_offset(pud, addr);
15686 ++ if ((unsigned long)_text <= addr && addr < (unsigned long)_data)
15687 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
15688 ++ else
15689 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
15690 ++ }
15691 ++
15692 ++ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
15693 ++ end = addr + KERNEL_IMAGE_SIZE;
15694 ++ for (; addr < end; addr += PMD_SIZE) {
15695 ++ pgd = pgd_offset_k(addr);
15696 ++ pud = pud_offset(pgd, addr);
15697 ++ pmd = pmd_offset(pud, addr);
15698 ++ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_data)))
15699 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
15700 ++ else
15701 ++ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
15702 ++ }
15703 ++
15704 ++ flush_tlb_all();
15705 ++#endif
15706 ++
15707 + free_init_pages("unused kernel memory",
15708 + (unsigned long)(&__init_begin),
15709 + (unsigned long)(&__init_end));
15710 +@@ -1149,7 +1195,7 @@ int in_gate_area_no_task(unsigned long a
15711 +
15712 + const char *arch_vma_name(struct vm_area_struct *vma)
15713 + {
15714 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
15715 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
15716 + return "[vdso]";
15717 + if (vma == &gate_vma)
15718 + return "[vsyscall]";
15719 +diff -urNp linux-2.6.28/arch/x86/mm/ioremap.c linux-2.6.28/arch/x86/mm/ioremap.c
15720 +--- linux-2.6.28/arch/x86/mm/ioremap.c 2008-12-24 18:26:37.000000000 -0500
15721 ++++ linux-2.6.28/arch/x86/mm/ioremap.c 2009-01-11 07:20:06.000000000 -0500
15722 +@@ -114,8 +114,8 @@ int page_is_ram(unsigned long pagenr)
15723 + * Second special case: Some BIOSen report the PC BIOS
15724 + * area (640->1Mb) as ram even though it is not.
15725 + */
15726 +- if (pagenr >= (BIOS_BEGIN >> PAGE_SHIFT) &&
15727 +- pagenr < (BIOS_END >> PAGE_SHIFT))
15728 ++ if (pagenr >= (ISA_START_ADDRESS >> PAGE_SHIFT) &&
15729 ++ pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
15730 + return 0;
15731 +
15732 + for (i = 0; i < e820.nr_map; i++) {
15733 +@@ -293,6 +293,8 @@ static void __iomem *__ioremap_caller(re
15734 + break;
15735 + }
15736 +
15737 ++ prot = canon_pgprot(prot);
15738 ++
15739 + /*
15740 + * Ok, go for it..
15741 + */
15742 +@@ -508,7 +510,7 @@ static int __init early_ioremap_debug_se
15743 + early_param("early_ioremap_debug", early_ioremap_debug_setup);
15744 +
15745 + static __initdata int after_paging_init;
15746 +-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
15747 ++static __initdata pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __aligned(PAGE_SIZE);
15748 +
15749 + static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
15750 + {
15751 +@@ -523,7 +525,11 @@ static inline pmd_t * __init early_iorem
15752 +
15753 + static inline pte_t * __init early_ioremap_pte(unsigned long addr)
15754 + {
15755 ++#ifdef CONFIG_X86_32
15756 + return &bm_pte[pte_index(addr)];
15757 ++#else
15758 ++ return &level1_fixmap_pgt[pte_index(addr)];
15759 ++#endif
15760 + }
15761 +
15762 + void __init early_ioremap_init(void)
15763 +@@ -534,8 +540,10 @@ void __init early_ioremap_init(void)
15764 + printk(KERN_INFO "early_ioremap_init()\n");
15765 +
15766 + pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
15767 ++#ifdef CONFIG_X86_32
15768 + memset(bm_pte, 0, sizeof(bm_pte));
15769 + pmd_populate_kernel(&init_mm, pmd, bm_pte);
15770 ++#endif
15771 +
15772 + /*
15773 + * The boot-ioremap range spans multiple pmds, for which
15774 +diff -urNp linux-2.6.28/arch/x86/mm/mmap.c linux-2.6.28/arch/x86/mm/mmap.c
15775 +--- linux-2.6.28/arch/x86/mm/mmap.c 2008-12-24 18:26:37.000000000 -0500
15776 ++++ linux-2.6.28/arch/x86/mm/mmap.c 2009-01-11 07:20:06.000000000 -0500
15777 +@@ -36,7 +36,7 @@
15778 + * Leave an at least ~128 MB hole.
15779 + */
15780 + #define MIN_GAP (128*1024*1024)
15781 +-#define MAX_GAP (TASK_SIZE/6*5)
15782 ++#define MAX_GAP (pax_task_size/6*5)
15783 +
15784 + /*
15785 + * True on X86_32 or when emulating IA32 on X86_64
15786 +@@ -81,27 +81,40 @@ static unsigned long mmap_rnd(void)
15787 + return rnd << PAGE_SHIFT;
15788 + }
15789 +
15790 +-static unsigned long mmap_base(void)
15791 ++static unsigned long mmap_base(struct mm_struct *mm)
15792 + {
15793 + unsigned long gap = current->signal->rlim[RLIMIT_STACK].rlim_cur;
15794 ++ unsigned long pax_task_size = TASK_SIZE;
15795 ++
15796 ++#ifdef CONFIG_PAX_SEGMEXEC
15797 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
15798 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
15799 ++#endif
15800 +
15801 + if (gap < MIN_GAP)
15802 + gap = MIN_GAP;
15803 + else if (gap > MAX_GAP)
15804 + gap = MAX_GAP;
15805 +
15806 +- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
15807 ++ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
15808 + }
15809 +
15810 + /*
15811 + * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
15812 + * does, but not when emulating X86_32
15813 + */
15814 +-static unsigned long mmap_legacy_base(void)
15815 ++static unsigned long mmap_legacy_base(struct mm_struct *mm)
15816 + {
15817 +- if (mmap_is_ia32())
15818 ++ if (mmap_is_ia32()) {
15819 ++
15820 ++#ifdef CONFIG_PAX_SEGMEXEC
15821 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC)
15822 ++ return SEGMEXEC_TASK_UNMAPPED_BASE;
15823 ++ else
15824 ++#endif
15825 ++
15826 + return TASK_UNMAPPED_BASE;
15827 +- else
15828 ++ } else
15829 + return TASK_UNMAPPED_BASE + mmap_rnd();
15830 + }
15831 +
15832 +@@ -112,11 +125,23 @@ static unsigned long mmap_legacy_base(vo
15833 + void arch_pick_mmap_layout(struct mm_struct *mm)
15834 + {
15835 + if (mmap_is_legacy()) {
15836 +- mm->mmap_base = mmap_legacy_base();
15837 ++ mm->mmap_base = mmap_legacy_base(mm);
15838 ++
15839 ++#ifdef CONFIG_PAX_RANDMMAP
15840 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
15841 ++ mm->mmap_base += mm->delta_mmap;
15842 ++#endif
15843 ++
15844 + mm->get_unmapped_area = arch_get_unmapped_area;
15845 + mm->unmap_area = arch_unmap_area;
15846 + } else {
15847 +- mm->mmap_base = mmap_base();
15848 ++ mm->mmap_base = mmap_base(mm);
15849 ++
15850 ++#ifdef CONFIG_PAX_RANDMMAP
15851 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
15852 ++ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
15853 ++#endif
15854 ++
15855 + mm->get_unmapped_area = arch_get_unmapped_area_topdown;
15856 + mm->unmap_area = arch_unmap_area_topdown;
15857 + }
15858 +diff -urNp linux-2.6.28/arch/x86/mm/numa_32.c linux-2.6.28/arch/x86/mm/numa_32.c
15859 +--- linux-2.6.28/arch/x86/mm/numa_32.c 2008-12-24 18:26:37.000000000 -0500
15860 ++++ linux-2.6.28/arch/x86/mm/numa_32.c 2009-01-11 07:20:06.000000000 -0500
15861 +@@ -98,7 +98,6 @@ unsigned long node_memmap_size_bytes(int
15862 + }
15863 + #endif
15864 +
15865 +-extern unsigned long find_max_low_pfn(void);
15866 + extern unsigned long highend_pfn, highstart_pfn;
15867 +
15868 + #define LARGE_PAGE_BYTES (PTRS_PER_PTE * PAGE_SIZE)
15869 +diff -urNp linux-2.6.28/arch/x86/mm/pageattr.c linux-2.6.28/arch/x86/mm/pageattr.c
15870 +--- linux-2.6.28/arch/x86/mm/pageattr.c 2008-12-24 18:26:37.000000000 -0500
15871 ++++ linux-2.6.28/arch/x86/mm/pageattr.c 2009-01-11 07:20:06.000000000 -0500
15872 +@@ -20,6 +20,7 @@
15873 + #include <asm/pgalloc.h>
15874 + #include <asm/proto.h>
15875 + #include <asm/pat.h>
15876 ++#include <asm/desc.h>
15877 +
15878 + /*
15879 + * The current flushing context - we pass it instead of 5 arguments:
15880 +@@ -259,7 +260,7 @@ static inline pgprot_t static_protection
15881 + * Does not cover __inittext since that is gone later on. On
15882 + * 64bit we do not enforce !NX on the low mapping
15883 + */
15884 +- if (within(address, (unsigned long)_text, (unsigned long)_etext))
15885 ++ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
15886 + pgprot_val(forbidden) |= _PAGE_NX;
15887 +
15888 + /*
15889 +@@ -321,8 +322,20 @@ EXPORT_SYMBOL_GPL(lookup_address);
15890 + */
15891 + static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
15892 + {
15893 ++
15894 ++#ifdef CONFIG_PAX_KERNEXEC
15895 ++ unsigned long cr0;
15896 ++
15897 ++ pax_open_kernel(cr0);
15898 ++#endif
15899 ++
15900 + /* change init_mm */
15901 + set_pte_atomic(kpte, pte);
15902 ++
15903 ++#ifdef CONFIG_PAX_KERNEXEC
15904 ++ pax_close_kernel(cr0);
15905 ++#endif
15906 ++
15907 + #ifdef CONFIG_X86_32
15908 + if (!SHARED_KERNEL_PMD) {
15909 + struct page *page;
15910 +diff -urNp linux-2.6.28/arch/x86/mm/pat.c linux-2.6.28/arch/x86/mm/pat.c
15911 +--- linux-2.6.28/arch/x86/mm/pat.c 2008-12-24 18:26:37.000000000 -0500
15912 ++++ linux-2.6.28/arch/x86/mm/pat.c 2009-01-11 07:20:06.000000000 -0500
15913 +@@ -333,6 +333,9 @@ int reserve_memtype(u64 start, u64 end,
15914 + req_type & _PAGE_CACHE_MASK);
15915 + }
15916 +
15917 ++ if (new_type)
15918 ++ *new_type = actual_type;
15919 ++
15920 + is_range_ram = pagerange_is_ram(start, end);
15921 + if (is_range_ram == 1)
15922 + return reserve_ram_pages_type(start, end, req_type, new_type);
15923 +@@ -347,9 +350,6 @@ int reserve_memtype(u64 start, u64 end,
15924 + new->end = end;
15925 + new->type = actual_type;
15926 +
15927 +- if (new_type)
15928 +- *new_type = actual_type;
15929 +-
15930 + spin_lock(&memtype_lock);
15931 +
15932 + if (cached_entry && start >= cached_start)
15933 +@@ -474,7 +474,7 @@ pgprot_t phys_mem_access_prot(struct fil
15934 + return vma_prot;
15935 + }
15936 +
15937 +-#ifdef CONFIG_STRICT_DEVMEM
15938 ++#ifndef CONFIG_STRICT_DEVMEM
15939 + /* This check is done in drivers/char/mem.c in case of STRICT_DEVMEM*/
15940 + static inline int range_is_allowed(unsigned long pfn, unsigned long size)
15941 + {
15942 +diff -urNp linux-2.6.28/arch/x86/mm/pgtable_32.c linux-2.6.28/arch/x86/mm/pgtable_32.c
15943 +--- linux-2.6.28/arch/x86/mm/pgtable_32.c 2008-12-24 18:26:37.000000000 -0500
15944 ++++ linux-2.6.28/arch/x86/mm/pgtable_32.c 2009-01-11 07:20:06.000000000 -0500
15945 +@@ -31,6 +31,10 @@ void set_pte_vaddr(unsigned long vaddr,
15946 + pmd_t *pmd;
15947 + pte_t *pte;
15948 +
15949 ++#ifdef CONFIG_PAX_KERNEXEC
15950 ++ unsigned long cr0;
15951 ++#endif
15952 ++
15953 + pgd = swapper_pg_dir + pgd_index(vaddr);
15954 + if (pgd_none(*pgd)) {
15955 + BUG();
15956 +@@ -47,11 +51,20 @@ void set_pte_vaddr(unsigned long vaddr,
15957 + return;
15958 + }
15959 + pte = pte_offset_kernel(pmd, vaddr);
15960 ++
15961 ++#ifdef CONFIG_PAX_KERNEXEC
15962 ++ pax_open_kernel(cr0);
15963 ++#endif
15964 ++
15965 + if (pte_val(pteval))
15966 + set_pte_present(&init_mm, vaddr, pte, pteval);
15967 + else
15968 + pte_clear(&init_mm, vaddr, pte);
15969 +
15970 ++#ifdef CONFIG_PAX_KERNEXEC
15971 ++ pax_close_kernel(cr0);
15972 ++#endif
15973 ++
15974 + /*
15975 + * It's enough to flush this one mapping.
15976 + * (PGE mappings get flushed as well)
15977 +diff -urNp linux-2.6.28/arch/x86/oprofile/backtrace.c linux-2.6.28/arch/x86/oprofile/backtrace.c
15978 +--- linux-2.6.28/arch/x86/oprofile/backtrace.c 2008-12-24 18:26:37.000000000 -0500
15979 ++++ linux-2.6.28/arch/x86/oprofile/backtrace.c 2009-01-11 07:20:06.000000000 -0500
15980 +@@ -37,7 +37,7 @@ static void backtrace_address(void *data
15981 + unsigned int *depth = data;
15982 +
15983 + if ((*depth)--)
15984 +- oprofile_add_trace(addr);
15985 ++ oprofile_add_trace(ktla_ktva(addr));
15986 + }
15987 +
15988 + static struct stacktrace_ops backtrace_ops = {
15989 +@@ -78,7 +78,7 @@ x86_backtrace(struct pt_regs * const reg
15990 + struct frame_head *head = (struct frame_head *)frame_pointer(regs);
15991 + unsigned long stack = kernel_trap_sp(regs);
15992 +
15993 +- if (!user_mode_vm(regs)) {
15994 ++ if (!user_mode(regs)) {
15995 + if (depth)
15996 + dump_trace(NULL, regs, (unsigned long *)stack, 0,
15997 + &backtrace_ops, &depth);
15998 +diff -urNp linux-2.6.28/arch/x86/oprofile/op_model_p4.c linux-2.6.28/arch/x86/oprofile/op_model_p4.c
15999 +--- linux-2.6.28/arch/x86/oprofile/op_model_p4.c 2008-12-24 18:26:37.000000000 -0500
16000 ++++ linux-2.6.28/arch/x86/oprofile/op_model_p4.c 2009-01-11 07:20:06.000000000 -0500
16001 +@@ -48,7 +48,7 @@ static inline void setup_num_counters(vo
16002 + #endif
16003 + }
16004 +
16005 +-static int inline addr_increment(void)
16006 ++static inline int addr_increment(void)
16007 + {
16008 + #ifdef CONFIG_SMP
16009 + return smp_num_siblings == 2 ? 2 : 1;
16010 +diff -urNp linux-2.6.28/arch/x86/pci/common.c linux-2.6.28/arch/x86/pci/common.c
16011 +--- linux-2.6.28/arch/x86/pci/common.c 2008-12-24 18:26:37.000000000 -0500
16012 ++++ linux-2.6.28/arch/x86/pci/common.c 2009-01-11 07:20:06.000000000 -0500
16013 +@@ -362,7 +362,7 @@ static struct dmi_system_id __devinitdat
16014 + DMI_MATCH(DMI_PRODUCT_NAME, "ProLiant DL585 G2"),
16015 + },
16016 + },
16017 +- {}
16018 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
16019 + };
16020 +
16021 + void __init dmi_check_pciprobe(void)
16022 +diff -urNp linux-2.6.28/arch/x86/pci/fixup.c linux-2.6.28/arch/x86/pci/fixup.c
16023 +--- linux-2.6.28/arch/x86/pci/fixup.c 2008-12-24 18:26:37.000000000 -0500
16024 ++++ linux-2.6.28/arch/x86/pci/fixup.c 2009-01-11 07:20:06.000000000 -0500
16025 +@@ -365,7 +365,7 @@ static struct dmi_system_id __devinitdat
16026 + DMI_MATCH(DMI_PRODUCT_NAME, "MS-6702E"),
16027 + },
16028 + },
16029 +- {}
16030 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
16031 + };
16032 +
16033 + /*
16034 +@@ -436,7 +436,7 @@ static struct dmi_system_id __devinitdat
16035 + DMI_MATCH(DMI_PRODUCT_VERSION, "PSA40U"),
16036 + },
16037 + },
16038 +- { }
16039 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
16040 + };
16041 +
16042 + static void __devinit pci_pre_fixup_toshiba_ohci1394(struct pci_dev *dev)
16043 +diff -urNp linux-2.6.28/arch/x86/pci/irq.c linux-2.6.28/arch/x86/pci/irq.c
16044 +--- linux-2.6.28/arch/x86/pci/irq.c 2008-12-24 18:26:37.000000000 -0500
16045 ++++ linux-2.6.28/arch/x86/pci/irq.c 2009-01-11 07:20:06.000000000 -0500
16046 +@@ -544,7 +544,7 @@ static __init int intel_router_probe(str
16047 + static struct pci_device_id __initdata pirq_440gx[] = {
16048 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_0) },
16049 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443GX_2) },
16050 +- { },
16051 ++ { PCI_DEVICE(0, 0) }
16052 + };
16053 +
16054 + /* 440GX has a proprietary PIRQ router -- don't use it */
16055 +@@ -1147,7 +1147,7 @@ static struct dmi_system_id __initdata p
16056 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 360"),
16057 + },
16058 + },
16059 +- { }
16060 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
16061 + };
16062 +
16063 + int __init pcibios_irq_init(void)
16064 +diff -urNp linux-2.6.28/arch/x86/pci/pcbios.c linux-2.6.28/arch/x86/pci/pcbios.c
16065 +--- linux-2.6.28/arch/x86/pci/pcbios.c 2008-12-24 18:26:37.000000000 -0500
16066 ++++ linux-2.6.28/arch/x86/pci/pcbios.c 2009-01-11 07:20:06.000000000 -0500
16067 +@@ -57,50 +57,120 @@ union bios32 {
16068 + static struct {
16069 + unsigned long address;
16070 + unsigned short segment;
16071 +-} bios32_indirect = { 0, __KERNEL_CS };
16072 ++} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
16073 +
16074 + /*
16075 + * Returns the entry point for the given service, NULL on error
16076 + */
16077 +
16078 +-static unsigned long bios32_service(unsigned long service)
16079 ++static unsigned long __devinit bios32_service(unsigned long service)
16080 + {
16081 + unsigned char return_code; /* %al */
16082 + unsigned long address; /* %ebx */
16083 + unsigned long length; /* %ecx */
16084 + unsigned long entry; /* %edx */
16085 + unsigned long flags;
16086 ++ struct desc_struct d, *gdt;
16087 ++
16088 ++#ifdef CONFIG_PAX_KERNEXEC
16089 ++ unsigned long cr0;
16090 ++#endif
16091 +
16092 + local_irq_save(flags);
16093 +- __asm__("lcall *(%%edi); cld"
16094 ++
16095 ++ gdt = get_cpu_gdt_table(smp_processor_id());
16096 ++
16097 ++#ifdef CONFIG_PAX_KERNEXEC
16098 ++ pax_open_kernel(cr0);
16099 ++#endif
16100 ++
16101 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
16102 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
16103 ++ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
16104 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
16105 ++
16106 ++#ifdef CONFIG_PAX_KERNEXEC
16107 ++ pax_close_kernel(cr0);
16108 ++#endif
16109 ++
16110 ++ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
16111 + : "=a" (return_code),
16112 + "=b" (address),
16113 + "=c" (length),
16114 + "=d" (entry)
16115 + : "0" (service),
16116 + "1" (0),
16117 +- "D" (&bios32_indirect));
16118 ++ "D" (&bios32_indirect),
16119 ++ "r"(__PCIBIOS_DS)
16120 ++ : "memory");
16121 ++
16122 ++#ifdef CONFIG_PAX_KERNEXEC
16123 ++ pax_open_kernel(cr0);
16124 ++#endif
16125 ++
16126 ++ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
16127 ++ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
16128 ++ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
16129 ++ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
16130 ++
16131 ++#ifdef CONFIG_PAX_KERNEXEC
16132 ++ pax_close_kernel(cr0);
16133 ++#endif
16134 ++
16135 + local_irq_restore(flags);
16136 +
16137 + switch (return_code) {
16138 +- case 0:
16139 +- return address + entry;
16140 +- case 0x80: /* Not present */
16141 +- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
16142 +- return 0;
16143 +- default: /* Shouldn't happen */
16144 +- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
16145 +- service, return_code);
16146 ++ case 0: {
16147 ++ int cpu;
16148 ++ unsigned char flags;
16149 ++
16150 ++ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
16151 ++ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
16152 ++ printk(KERN_WARNING "bios32_service: not valid\n");
16153 + return 0;
16154 ++ }
16155 ++ address = address + PAGE_OFFSET;
16156 ++ length += 16UL; /* some BIOSs underreport this... */
16157 ++ flags = 4;
16158 ++ if (length >= 64*1024*1024) {
16159 ++ length >>= PAGE_SHIFT;
16160 ++ flags |= 8;
16161 ++ }
16162 ++
16163 ++#ifdef CONFIG_PAX_KERNEXEC
16164 ++ pax_open_kernel(cr0);
16165 ++#endif
16166 ++
16167 ++ for (cpu = 0; cpu < NR_CPUS; cpu++) {
16168 ++ gdt = get_cpu_gdt_table(cpu);
16169 ++ pack_descriptor(&d, address, length, 0x9b, flags);
16170 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
16171 ++ pack_descriptor(&d, address, length, 0x93, flags);
16172 ++ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
16173 ++ }
16174 ++
16175 ++#ifdef CONFIG_PAX_KERNEXEC
16176 ++ pax_close_kernel(cr0);
16177 ++#endif
16178 ++
16179 ++ return entry;
16180 ++ }
16181 ++ case 0x80: /* Not present */
16182 ++ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
16183 ++ return 0;
16184 ++ default: /* Shouldn't happen */
16185 ++ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
16186 ++ service, return_code);
16187 ++ return 0;
16188 + }
16189 + }
16190 +
16191 + static struct {
16192 + unsigned long address;
16193 + unsigned short segment;
16194 +-} pci_indirect = { 0, __KERNEL_CS };
16195 ++} pci_indirect __read_only = { 0, __PCIBIOS_CS };
16196 +
16197 +-static int pci_bios_present;
16198 ++static int pci_bios_present __read_only;
16199 +
16200 + static int __devinit check_pcibios(void)
16201 + {
16202 +@@ -109,11 +179,13 @@ static int __devinit check_pcibios(void)
16203 + unsigned long flags, pcibios_entry;
16204 +
16205 + if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
16206 +- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
16207 ++ pci_indirect.address = pcibios_entry;
16208 +
16209 + local_irq_save(flags);
16210 +- __asm__(
16211 +- "lcall *(%%edi); cld\n\t"
16212 ++ __asm__("movw %w6, %%ds\n\t"
16213 ++ "lcall *%%ss:(%%edi); cld\n\t"
16214 ++ "push %%ss\n\t"
16215 ++ "pop %%ds\n\t"
16216 + "jc 1f\n\t"
16217 + "xor %%ah, %%ah\n"
16218 + "1:"
16219 +@@ -122,7 +194,8 @@ static int __devinit check_pcibios(void)
16220 + "=b" (ebx),
16221 + "=c" (ecx)
16222 + : "1" (PCIBIOS_PCI_BIOS_PRESENT),
16223 +- "D" (&pci_indirect)
16224 ++ "D" (&pci_indirect),
16225 ++ "r" (__PCIBIOS_DS)
16226 + : "memory");
16227 + local_irq_restore(flags);
16228 +
16229 +@@ -166,7 +239,10 @@ static int pci_bios_read(unsigned int se
16230 +
16231 + switch (len) {
16232 + case 1:
16233 +- __asm__("lcall *(%%esi); cld\n\t"
16234 ++ __asm__("movw %w6, %%ds\n\t"
16235 ++ "lcall *%%ss:(%%esi); cld\n\t"
16236 ++ "push %%ss\n\t"
16237 ++ "pop %%ds\n\t"
16238 + "jc 1f\n\t"
16239 + "xor %%ah, %%ah\n"
16240 + "1:"
16241 +@@ -175,7 +251,8 @@ static int pci_bios_read(unsigned int se
16242 + : "1" (PCIBIOS_READ_CONFIG_BYTE),
16243 + "b" (bx),
16244 + "D" ((long)reg),
16245 +- "S" (&pci_indirect));
16246 ++ "S" (&pci_indirect),
16247 ++ "r" (__PCIBIOS_DS));
16248 + /*
16249 + * Zero-extend the result beyond 8 bits, do not trust the
16250 + * BIOS having done it:
16251 +@@ -183,7 +260,10 @@ static int pci_bios_read(unsigned int se
16252 + *value &= 0xff;
16253 + break;
16254 + case 2:
16255 +- __asm__("lcall *(%%esi); cld\n\t"
16256 ++ __asm__("movw %w6, %%ds\n\t"
16257 ++ "lcall *%%ss:(%%esi); cld\n\t"
16258 ++ "push %%ss\n\t"
16259 ++ "pop %%ds\n\t"
16260 + "jc 1f\n\t"
16261 + "xor %%ah, %%ah\n"
16262 + "1:"
16263 +@@ -192,7 +272,8 @@ static int pci_bios_read(unsigned int se
16264 + : "1" (PCIBIOS_READ_CONFIG_WORD),
16265 + "b" (bx),
16266 + "D" ((long)reg),
16267 +- "S" (&pci_indirect));
16268 ++ "S" (&pci_indirect),
16269 ++ "r" (__PCIBIOS_DS));
16270 + /*
16271 + * Zero-extend the result beyond 16 bits, do not trust the
16272 + * BIOS having done it:
16273 +@@ -200,7 +281,10 @@ static int pci_bios_read(unsigned int se
16274 + *value &= 0xffff;
16275 + break;
16276 + case 4:
16277 +- __asm__("lcall *(%%esi); cld\n\t"
16278 ++ __asm__("movw %w6, %%ds\n\t"
16279 ++ "lcall *%%ss:(%%esi); cld\n\t"
16280 ++ "push %%ss\n\t"
16281 ++ "pop %%ds\n\t"
16282 + "jc 1f\n\t"
16283 + "xor %%ah, %%ah\n"
16284 + "1:"
16285 +@@ -209,7 +293,8 @@ static int pci_bios_read(unsigned int se
16286 + : "1" (PCIBIOS_READ_CONFIG_DWORD),
16287 + "b" (bx),
16288 + "D" ((long)reg),
16289 +- "S" (&pci_indirect));
16290 ++ "S" (&pci_indirect),
16291 ++ "r" (__PCIBIOS_DS));
16292 + break;
16293 + }
16294 +
16295 +@@ -232,7 +317,10 @@ static int pci_bios_write(unsigned int s
16296 +
16297 + switch (len) {
16298 + case 1:
16299 +- __asm__("lcall *(%%esi); cld\n\t"
16300 ++ __asm__("movw %w6, %%ds\n\t"
16301 ++ "lcall *%%ss:(%%esi); cld\n\t"
16302 ++ "push %%ss\n\t"
16303 ++ "pop %%ds\n\t"
16304 + "jc 1f\n\t"
16305 + "xor %%ah, %%ah\n"
16306 + "1:"
16307 +@@ -241,10 +329,14 @@ static int pci_bios_write(unsigned int s
16308 + "c" (value),
16309 + "b" (bx),
16310 + "D" ((long)reg),
16311 +- "S" (&pci_indirect));
16312 ++ "S" (&pci_indirect),
16313 ++ "r" (__PCIBIOS_DS));
16314 + break;
16315 + case 2:
16316 +- __asm__("lcall *(%%esi); cld\n\t"
16317 ++ __asm__("movw %w6, %%ds\n\t"
16318 ++ "lcall *%%ss:(%%esi); cld\n\t"
16319 ++ "push %%ss\n\t"
16320 ++ "pop %%ds\n\t"
16321 + "jc 1f\n\t"
16322 + "xor %%ah, %%ah\n"
16323 + "1:"
16324 +@@ -253,10 +345,14 @@ static int pci_bios_write(unsigned int s
16325 + "c" (value),
16326 + "b" (bx),
16327 + "D" ((long)reg),
16328 +- "S" (&pci_indirect));
16329 ++ "S" (&pci_indirect),
16330 ++ "r" (__PCIBIOS_DS));
16331 + break;
16332 + case 4:
16333 +- __asm__("lcall *(%%esi); cld\n\t"
16334 ++ __asm__("movw %w6, %%ds\n\t"
16335 ++ "lcall *%%ss:(%%esi); cld\n\t"
16336 ++ "push %%ss\n\t"
16337 ++ "pop %%ds\n\t"
16338 + "jc 1f\n\t"
16339 + "xor %%ah, %%ah\n"
16340 + "1:"
16341 +@@ -265,7 +361,8 @@ static int pci_bios_write(unsigned int s
16342 + "c" (value),
16343 + "b" (bx),
16344 + "D" ((long)reg),
16345 +- "S" (&pci_indirect));
16346 ++ "S" (&pci_indirect),
16347 ++ "r" (__PCIBIOS_DS));
16348 + break;
16349 + }
16350 +
16351 +@@ -369,10 +466,13 @@ struct irq_routing_table * pcibios_get_i
16352 +
16353 + DBG("PCI: Fetching IRQ routing table... ");
16354 + __asm__("push %%es\n\t"
16355 ++ "movw %w8, %%ds\n\t"
16356 + "push %%ds\n\t"
16357 + "pop %%es\n\t"
16358 +- "lcall *(%%esi); cld\n\t"
16359 ++ "lcall *%%ss:(%%esi); cld\n\t"
16360 + "pop %%es\n\t"
16361 ++ "push %%ss\n\t"
16362 ++ "pop %%ds\n"
16363 + "jc 1f\n\t"
16364 + "xor %%ah, %%ah\n"
16365 + "1:"
16366 +@@ -383,7 +483,8 @@ struct irq_routing_table * pcibios_get_i
16367 + "1" (0),
16368 + "D" ((long) &opt),
16369 + "S" (&pci_indirect),
16370 +- "m" (opt)
16371 ++ "m" (opt),
16372 ++ "r" (__PCIBIOS_DS)
16373 + : "memory");
16374 + DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
16375 + if (ret & 0xff00)
16376 +@@ -407,7 +508,10 @@ int pcibios_set_irq_routing(struct pci_d
16377 + {
16378 + int ret;
16379 +
16380 +- __asm__("lcall *(%%esi); cld\n\t"
16381 ++ __asm__("movw %w5, %%ds\n\t"
16382 ++ "lcall *%%ss:(%%esi); cld\n\t"
16383 ++ "push %%ss\n\t"
16384 ++ "pop %%ds\n"
16385 + "jc 1f\n\t"
16386 + "xor %%ah, %%ah\n"
16387 + "1:"
16388 +@@ -415,7 +519,8 @@ int pcibios_set_irq_routing(struct pci_d
16389 + : "0" (PCIBIOS_SET_PCI_HW_INT),
16390 + "b" ((dev->bus->number << 8) | dev->devfn),
16391 + "c" ((irq << 8) | (pin + 10)),
16392 +- "S" (&pci_indirect));
16393 ++ "S" (&pci_indirect),
16394 ++ "r" (__PCIBIOS_DS));
16395 + return !(ret & 0xff00);
16396 + }
16397 + EXPORT_SYMBOL(pcibios_set_irq_routing);
16398 +diff -urNp linux-2.6.28/arch/x86/power/cpu_32.c linux-2.6.28/arch/x86/power/cpu_32.c
16399 +--- linux-2.6.28/arch/x86/power/cpu_32.c 2008-12-24 18:26:37.000000000 -0500
16400 ++++ linux-2.6.28/arch/x86/power/cpu_32.c 2009-01-11 07:20:06.000000000 -0500
16401 +@@ -67,7 +67,7 @@ static void do_fpu_end(void)
16402 + static void fix_processor_context(void)
16403 + {
16404 + int cpu = smp_processor_id();
16405 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
16406 ++ struct tss_struct *t = init_tss + cpu;
16407 +
16408 + set_tss_desc(cpu, t); /*
16409 + * This just modifies memory; should not be
16410 +diff -urNp linux-2.6.28/arch/x86/power/cpu_64.c linux-2.6.28/arch/x86/power/cpu_64.c
16411 +--- linux-2.6.28/arch/x86/power/cpu_64.c 2008-12-24 18:26:37.000000000 -0500
16412 ++++ linux-2.6.28/arch/x86/power/cpu_64.c 2009-01-11 07:20:06.000000000 -0500
16413 +@@ -143,7 +143,11 @@ void restore_processor_state(void)
16414 + static void fix_processor_context(void)
16415 + {
16416 + int cpu = smp_processor_id();
16417 +- struct tss_struct *t = &per_cpu(init_tss, cpu);
16418 ++ struct tss_struct *t = init_tss + cpu;
16419 ++
16420 ++#ifdef CONFIG_PAX_KERNEXEC
16421 ++ unsigned long cr0;
16422 ++#endif
16423 +
16424 + /*
16425 + * This just modifies memory; should not be necessary. But... This
16426 +@@ -152,8 +156,16 @@ static void fix_processor_context(void)
16427 + */
16428 + set_tss_desc(cpu, t);
16429 +
16430 ++#ifdef CONFIG_PAX_KERNEXEC
16431 ++ pax_open_kernel(cr0);
16432 ++#endif
16433 ++
16434 + get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
16435 +
16436 ++#ifdef CONFIG_PAX_KERNEXEC
16437 ++ pax_close_kernel(cr0);
16438 ++#endif
16439 ++
16440 + syscall_init(); /* This sets MSR_*STAR and related */
16441 + load_TR_desc(); /* This does ltr */
16442 + load_LDT(&current->active_mm->context); /* This does lldt */
16443 +diff -urNp linux-2.6.28/arch/x86/vdso/vdso32-setup.c linux-2.6.28/arch/x86/vdso/vdso32-setup.c
16444 +--- linux-2.6.28/arch/x86/vdso/vdso32-setup.c 2008-12-24 18:26:37.000000000 -0500
16445 ++++ linux-2.6.28/arch/x86/vdso/vdso32-setup.c 2009-01-11 07:20:06.000000000 -0500
16446 +@@ -226,7 +226,7 @@ static inline void map_compat_vdso(int m
16447 + void enable_sep_cpu(void)
16448 + {
16449 + int cpu = get_cpu();
16450 +- struct tss_struct *tss = &per_cpu(init_tss, cpu);
16451 ++ struct tss_struct *tss = init_tss + cpu;
16452 +
16453 + if (!boot_cpu_has(X86_FEATURE_SEP)) {
16454 + put_cpu();
16455 +@@ -249,7 +249,7 @@ static int __init gate_vma_init(void)
16456 + gate_vma.vm_start = FIXADDR_USER_START;
16457 + gate_vma.vm_end = FIXADDR_USER_END;
16458 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
16459 +- gate_vma.vm_page_prot = __P101;
16460 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
16461 + /*
16462 + * Make sure the vDSO gets into every core dump.
16463 + * Dumping its contents makes post-mortem fully interpretable later
16464 +@@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct l
16465 + if (compat)
16466 + addr = VDSO_HIGH_BASE;
16467 + else {
16468 +- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
16469 ++ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
16470 + if (IS_ERR_VALUE(addr)) {
16471 + ret = addr;
16472 + goto up_fail;
16473 +@@ -358,7 +358,7 @@ int arch_setup_additional_pages(struct l
16474 + goto up_fail;
16475 + }
16476 +
16477 +- current->mm->context.vdso = (void *)addr;
16478 ++ current->mm->context.vdso = addr;
16479 + current_thread_info()->sysenter_return =
16480 + VDSO32_SYMBOL(addr, SYSENTER_RETURN);
16481 +
16482 +@@ -384,7 +384,7 @@ static ctl_table abi_table2[] = {
16483 + .mode = 0644,
16484 + .proc_handler = proc_dointvec
16485 + },
16486 +- {}
16487 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
16488 + };
16489 +
16490 + static ctl_table abi_root_table2[] = {
16491 +@@ -394,7 +394,7 @@ static ctl_table abi_root_table2[] = {
16492 + .mode = 0555,
16493 + .child = abi_table2
16494 + },
16495 +- {}
16496 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
16497 + };
16498 +
16499 + static __init int ia32_binfmt_init(void)
16500 +@@ -409,8 +409,14 @@ __initcall(ia32_binfmt_init);
16501 +
16502 + const char *arch_vma_name(struct vm_area_struct *vma)
16503 + {
16504 +- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
16505 ++ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
16506 + return "[vdso]";
16507 ++
16508 ++#ifdef CONFIG_PAX_SEGMEXEC
16509 ++ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
16510 ++ return "[vdso]";
16511 ++#endif
16512 ++
16513 + return NULL;
16514 + }
16515 +
16516 +@@ -419,7 +425,7 @@ struct vm_area_struct *get_gate_vma(stru
16517 + struct mm_struct *mm = tsk->mm;
16518 +
16519 + /* Check to see if this task was created in compat vdso mode */
16520 +- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
16521 ++ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
16522 + return &gate_vma;
16523 + return NULL;
16524 + }
16525 +diff -urNp linux-2.6.28/arch/x86/vdso/vma.c linux-2.6.28/arch/x86/vdso/vma.c
16526 +--- linux-2.6.28/arch/x86/vdso/vma.c 2008-12-24 18:26:37.000000000 -0500
16527 ++++ linux-2.6.28/arch/x86/vdso/vma.c 2009-01-11 07:20:06.000000000 -0500
16528 +@@ -123,7 +123,7 @@ int arch_setup_additional_pages(struct l
16529 + if (ret)
16530 + goto up_fail;
16531 +
16532 +- current->mm->context.vdso = (void *)addr;
16533 ++ current->mm->context.vdso = addr;
16534 + up_fail:
16535 + up_write(&mm->mmap_sem);
16536 + return ret;
16537 +diff -urNp linux-2.6.28/arch/x86/xen/enlighten.c linux-2.6.28/arch/x86/xen/enlighten.c
16538 +--- linux-2.6.28/arch/x86/xen/enlighten.c 2008-12-24 18:26:37.000000000 -0500
16539 ++++ linux-2.6.28/arch/x86/xen/enlighten.c 2009-01-11 07:20:06.000000000 -0500
16540 +@@ -318,7 +318,7 @@ static void xen_set_ldt(const void *addr
16541 + static void xen_load_gdt(const struct desc_ptr *dtr)
16542 + {
16543 + unsigned long *frames;
16544 +- unsigned long va = dtr->address;
16545 ++ unsigned long va = (unsigned long)dtr->address;
16546 + unsigned int size = dtr->size + 1;
16547 + unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
16548 + int f;
16549 +@@ -333,7 +333,7 @@ static void xen_load_gdt(const struct de
16550 + mcs = xen_mc_entry(sizeof(*frames) * pages);
16551 + frames = mcs.args;
16552 +
16553 +- for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
16554 ++ for (f = 0; va < (unsigned long)dtr->address + size; va += PAGE_SIZE, f++) {
16555 + frames[f] = virt_to_mfn(va);
16556 + make_lowmem_page_readonly((void *)va);
16557 + }
16558 +@@ -441,7 +441,7 @@ static void xen_write_idt_entry(gate_des
16559 +
16560 + preempt_disable();
16561 +
16562 +- start = __get_cpu_var(idt_desc).address;
16563 ++ start = (unsigned long)__get_cpu_var(idt_desc).address;
16564 + end = start + __get_cpu_var(idt_desc).size + 1;
16565 +
16566 + xen_mc_flush();
16567 +@@ -1526,6 +1526,8 @@ static __init pgd_t *xen_setup_kernel_pa
16568 + convert_pfn_mfn(init_level4_pgt);
16569 + convert_pfn_mfn(level3_ident_pgt);
16570 + convert_pfn_mfn(level3_kernel_pgt);
16571 ++ convert_pfn_mfn(level3_vmalloc_pgt);
16572 ++ convert_pfn_mfn(level3_vmemmap_pgt);
16573 +
16574 + l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
16575 + l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
16576 +@@ -1544,9 +1546,12 @@ static __init pgd_t *xen_setup_kernel_pa
16577 + set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
16578 + set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
16579 + set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
16580 ++ set_page_prot(level3_vmalloc_pgt, PAGE_KERNEL_RO);
16581 ++ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
16582 + set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
16583 + set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
16584 + set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
16585 ++ set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
16586 +
16587 + /* Pin down new L4 */
16588 + pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
16589 +diff -urNp linux-2.6.28/arch/x86/xen/smp.c linux-2.6.28/arch/x86/xen/smp.c
16590 +--- linux-2.6.28/arch/x86/xen/smp.c 2008-12-24 18:26:37.000000000 -0500
16591 ++++ linux-2.6.28/arch/x86/xen/smp.c 2009-01-11 07:20:06.000000000 -0500
16592 +@@ -171,11 +171,6 @@ static void __init xen_smp_prepare_boot_
16593 + {
16594 + BUG_ON(smp_processor_id() != 0);
16595 + native_smp_prepare_boot_cpu();
16596 +-
16597 +- /* We've switched to the "real" per-cpu gdt, so make sure the
16598 +- old memory can be recycled */
16599 +- make_lowmem_page_readwrite(&per_cpu_var(gdt_page));
16600 +-
16601 + xen_setup_vcpu_info_placement();
16602 + }
16603 +
16604 +@@ -231,8 +226,8 @@ cpu_initialize_context(unsigned int cpu,
16605 + gdt = get_cpu_gdt_table(cpu);
16606 +
16607 + ctxt->flags = VGCF_IN_KERNEL;
16608 +- ctxt->user_regs.ds = __USER_DS;
16609 +- ctxt->user_regs.es = __USER_DS;
16610 ++ ctxt->user_regs.ds = __KERNEL_DS;
16611 ++ ctxt->user_regs.es = __KERNEL_DS;
16612 + ctxt->user_regs.ss = __KERNEL_DS;
16613 + #ifdef CONFIG_X86_32
16614 + ctxt->user_regs.fs = __KERNEL_PERCPU;
16615 +diff -urNp linux-2.6.28/crypto/async_tx/async_tx.c linux-2.6.28/crypto/async_tx/async_tx.c
16616 +--- linux-2.6.28/crypto/async_tx/async_tx.c 2008-12-24 18:26:37.000000000 -0500
16617 ++++ linux-2.6.28/crypto/async_tx/async_tx.c 2009-01-11 07:20:06.000000000 -0500
16618 +@@ -356,8 +356,8 @@ async_tx_init(void)
16619 + err:
16620 + printk(KERN_ERR "async_tx: initialization failure\n");
16621 +
16622 +- while (--cap >= 0)
16623 +- free_percpu(channel_table[cap]);
16624 ++ while (cap)
16625 ++ free_percpu(channel_table[--cap]);
16626 +
16627 + return 1;
16628 + }
16629 +diff -urNp linux-2.6.28/crypto/lrw.c linux-2.6.28/crypto/lrw.c
16630 +--- linux-2.6.28/crypto/lrw.c 2008-12-24 18:26:37.000000000 -0500
16631 ++++ linux-2.6.28/crypto/lrw.c 2009-01-11 07:20:06.000000000 -0500
16632 +@@ -54,7 +54,7 @@ static int setkey(struct crypto_tfm *par
16633 + struct priv *ctx = crypto_tfm_ctx(parent);
16634 + struct crypto_cipher *child = ctx->child;
16635 + int err, i;
16636 +- be128 tmp = { 0 };
16637 ++ be128 tmp = { 0, 0 };
16638 + int bsize = crypto_cipher_blocksize(child);
16639 +
16640 + crypto_cipher_clear_flags(child, CRYPTO_TFM_REQ_MASK);
16641 +diff -urNp linux-2.6.28/Documentation/dontdiff linux-2.6.28/Documentation/dontdiff
16642 +--- linux-2.6.28/Documentation/dontdiff 2008-12-24 18:26:37.000000000 -0500
16643 ++++ linux-2.6.28/Documentation/dontdiff 2009-01-11 07:20:06.000000000 -0500
16644 +@@ -3,6 +3,7 @@
16645 + *.bin
16646 + *.cpio
16647 + *.csp
16648 ++*.dbg
16649 + *.dsp
16650 + *.dvi
16651 + *.elf
16652 +@@ -49,6 +50,10 @@
16653 + 53c700_d.h
16654 + CVS
16655 + ChangeSet
16656 ++GPATH
16657 ++GRTAGS
16658 ++GSYMS
16659 ++GTAGS
16660 + Image
16661 + Kerntypes
16662 + Module.markers
16663 +@@ -62,7 +67,6 @@ aic7*reg_print.c*
16664 + aic7*seq.h*
16665 + aicasm
16666 + aicdb.h*
16667 +-asm
16668 + asm-offsets.h
16669 + asm_offsets.h
16670 + autoconf.h*
16671 +@@ -77,6 +81,7 @@ btfixupprep
16672 + build
16673 + bvmlinux
16674 + bzImage*
16675 ++capflags.c
16676 + classlist.h*
16677 + comp*.log
16678 + compile.h*
16679 +@@ -188,12 +193,15 @@ version.h*
16680 + vmlinux
16681 + vmlinux-*
16682 + vmlinux.aout
16683 ++vmlinux.bin.all
16684 + vmlinux.lds
16685 ++vmlinux.relocs
16686 + vsyscall.lds
16687 + vsyscall_32.lds
16688 + wanxlfw.inc
16689 + uImage
16690 + unifdef
16691 ++utsrelease.h
16692 + wakeup.bin
16693 + wakeup.elf
16694 + wakeup.lds
16695 +diff -urNp linux-2.6.28/drivers/acpi/blacklist.c linux-2.6.28/drivers/acpi/blacklist.c
16696 +--- linux-2.6.28/drivers/acpi/blacklist.c 2008-12-24 18:26:37.000000000 -0500
16697 ++++ linux-2.6.28/drivers/acpi/blacklist.c 2009-01-11 07:20:06.000000000 -0500
16698 +@@ -71,7 +71,7 @@ static struct acpi_blacklist_item acpi_b
16699 + {"IBM ", "TP600E ", 0x00000105, ACPI_SIG_DSDT, less_than_or_equal,
16700 + "Incorrect _ADR", 1},
16701 +
16702 +- {""}
16703 ++ {"", "", 0, 0, 0, all_versions, 0}
16704 + };
16705 +
16706 + #if CONFIG_ACPI_BLACKLIST_YEAR
16707 +diff -urNp linux-2.6.28/drivers/acpi/osl.c linux-2.6.28/drivers/acpi/osl.c
16708 +--- linux-2.6.28/drivers/acpi/osl.c 2008-12-24 18:26:37.000000000 -0500
16709 ++++ linux-2.6.28/drivers/acpi/osl.c 2009-01-11 07:20:06.000000000 -0500
16710 +@@ -483,6 +483,8 @@ acpi_os_read_memory(acpi_physical_addres
16711 + void __iomem *virt_addr;
16712 +
16713 + virt_addr = ioremap(phys_addr, width);
16714 ++ if (!virt_addr)
16715 ++ return AE_NO_MEMORY;
16716 + if (!value)
16717 + value = &dummy;
16718 +
16719 +@@ -511,6 +513,8 @@ acpi_os_write_memory(acpi_physical_addre
16720 + void __iomem *virt_addr;
16721 +
16722 + virt_addr = ioremap(phys_addr, width);
16723 ++ if (!virt_addr)
16724 ++ return AE_NO_MEMORY;
16725 +
16726 + switch (width) {
16727 + case 8:
16728 +diff -urNp linux-2.6.28/drivers/acpi/processor_core.c linux-2.6.28/drivers/acpi/processor_core.c
16729 +--- linux-2.6.28/drivers/acpi/processor_core.c 2008-12-24 18:26:37.000000000 -0500
16730 ++++ linux-2.6.28/drivers/acpi/processor_core.c 2009-01-11 07:20:06.000000000 -0500
16731 +@@ -678,7 +678,7 @@ static int __cpuinit acpi_processor_star
16732 + return 0;
16733 + }
16734 +
16735 +- BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
16736 ++ BUG_ON(pr->id >= nr_cpu_ids);
16737 +
16738 + /*
16739 + * Buggy BIOS check
16740 +diff -urNp linux-2.6.28/drivers/acpi/processor_idle.c linux-2.6.28/drivers/acpi/processor_idle.c
16741 +--- linux-2.6.28/drivers/acpi/processor_idle.c 2008-12-24 18:26:37.000000000 -0500
16742 ++++ linux-2.6.28/drivers/acpi/processor_idle.c 2009-01-11 07:20:06.000000000 -0500
16743 +@@ -181,7 +181,7 @@ static struct dmi_system_id __cpuinitdat
16744 + DMI_MATCH(DMI_BIOS_VENDOR,"Phoenix Technologies LTD"),
16745 + DMI_MATCH(DMI_BIOS_VERSION,"SHE845M0.86C.0013.D.0302131307")},
16746 + (void *)2},
16747 +- {},
16748 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL},
16749 + };
16750 +
16751 + static inline u32 ticks_elapsed(u32 t1, u32 t2)
16752 +diff -urNp linux-2.6.28/drivers/acpi/tables/tbfadt.c linux-2.6.28/drivers/acpi/tables/tbfadt.c
16753 +--- linux-2.6.28/drivers/acpi/tables/tbfadt.c 2008-12-24 18:26:37.000000000 -0500
16754 ++++ linux-2.6.28/drivers/acpi/tables/tbfadt.c 2009-01-11 07:20:06.000000000 -0500
16755 +@@ -48,7 +48,7 @@
16756 + ACPI_MODULE_NAME("tbfadt")
16757 +
16758 + /* Local prototypes */
16759 +-static void inline
16760 ++static inline void
16761 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
16762 + u8 byte_width, u64 address);
16763 +
16764 +@@ -122,7 +122,7 @@ static struct acpi_fadt_info fadt_info_t
16765 + *
16766 + ******************************************************************************/
16767 +
16768 +-static void inline
16769 ++static inline void
16770 + acpi_tb_init_generic_address(struct acpi_generic_address *generic_address,
16771 + u8 byte_width, u64 address)
16772 + {
16773 +diff -urNp linux-2.6.28/drivers/ata/ahci.c linux-2.6.28/drivers/ata/ahci.c
16774 +--- linux-2.6.28/drivers/ata/ahci.c 2008-12-24 18:26:37.000000000 -0500
16775 ++++ linux-2.6.28/drivers/ata/ahci.c 2009-01-11 07:20:06.000000000 -0500
16776 +@@ -606,7 +606,7 @@ static const struct pci_device_id ahci_p
16777 + { PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID, PCI_ANY_ID,
16778 + PCI_CLASS_STORAGE_SATA_AHCI, 0xffffff, board_ahci },
16779 +
16780 +- { } /* terminate list */
16781 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
16782 + };
16783 +
16784 +
16785 +diff -urNp linux-2.6.28/drivers/ata/ata_piix.c linux-2.6.28/drivers/ata/ata_piix.c
16786 +--- linux-2.6.28/drivers/ata/ata_piix.c 2008-12-24 18:26:37.000000000 -0500
16787 ++++ linux-2.6.28/drivers/ata/ata_piix.c 2009-01-11 07:20:06.000000000 -0500
16788 +@@ -289,7 +289,7 @@ static const struct pci_device_id piix_p
16789 + { 0x8086, 0x3b2d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_2port_sata },
16790 + /* SATA Controller IDE (PCH) */
16791 + { 0x8086, 0x3b2e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ich8_sata },
16792 +- { } /* terminate list */
16793 ++ { 0, 0, 0, 0, 0, 0, 0 } /* terminate list */
16794 + };
16795 +
16796 + static struct pci_driver piix_pci_driver = {
16797 +@@ -593,7 +593,7 @@ static const struct ich_laptop ich_lapto
16798 + { 0x266F, 0x1025, 0x0066 }, /* ICH6 on ACER Aspire 1694WLMi */
16799 + { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
16800 + /* end marker */
16801 +- { 0, }
16802 ++ { 0, 0, 0 }
16803 + };
16804 +
16805 + /**
16806 +@@ -1052,7 +1052,7 @@ static int piix_broken_suspend(void)
16807 + },
16808 + },
16809 +
16810 +- { } /* terminate list */
16811 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL } /* terminate list */
16812 + };
16813 + static const char *oemstrs[] = {
16814 + "Tecra M3,",
16815 +diff -urNp linux-2.6.28/drivers/ata/libata-core.c linux-2.6.28/drivers/ata/libata-core.c
16816 +--- linux-2.6.28/drivers/ata/libata-core.c 2008-12-24 18:26:37.000000000 -0500
16817 ++++ linux-2.6.28/drivers/ata/libata-core.c 2009-01-11 07:20:06.000000000 -0500
16818 +@@ -807,7 +807,7 @@ static const struct ata_xfer_ent {
16819 + { ATA_SHIFT_PIO, ATA_NR_PIO_MODES, XFER_PIO_0 },
16820 + { ATA_SHIFT_MWDMA, ATA_NR_MWDMA_MODES, XFER_MW_DMA_0 },
16821 + { ATA_SHIFT_UDMA, ATA_NR_UDMA_MODES, XFER_UDMA_0 },
16822 +- { -1, },
16823 ++ { -1, 0, 0 }
16824 + };
16825 +
16826 + /**
16827 +@@ -2981,7 +2981,7 @@ static const struct ata_timing ata_timin
16828 + { XFER_UDMA_5, 0, 0, 0, 0, 0, 0, 0, 20 },
16829 + { XFER_UDMA_6, 0, 0, 0, 0, 0, 0, 0, 15 },
16830 +
16831 +- { 0xFF }
16832 ++ { 0xFF, 0, 0, 0, 0, 0, 0, 0, 0 }
16833 + };
16834 +
16835 + #define ENOUGH(v, unit) (((v)-1)/(unit)+1)
16836 +@@ -4147,7 +4147,7 @@ static const struct ata_blacklist_entry
16837 + { "MTRON MSP-SATA*", NULL, ATA_HORKAGE_BRIDGE_OK, },
16838 +
16839 + /* End Marker */
16840 +- { }
16841 ++ { NULL, NULL, 0 }
16842 + };
16843 +
16844 + static int strn_pattern_cmp(const char *patt, const char *name, int wildchar)
16845 +diff -urNp linux-2.6.28/drivers/char/agp/frontend.c linux-2.6.28/drivers/char/agp/frontend.c
16846 +--- linux-2.6.28/drivers/char/agp/frontend.c 2008-12-24 18:26:37.000000000 -0500
16847 ++++ linux-2.6.28/drivers/char/agp/frontend.c 2009-01-11 07:20:06.000000000 -0500
16848 +@@ -824,7 +824,7 @@ static int agpioc_reserve_wrap(struct ag
16849 + if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
16850 + return -EFAULT;
16851 +
16852 +- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
16853 ++ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
16854 + return -EFAULT;
16855 +
16856 + client = agp_find_client_by_pid(reserve.pid);
16857 +diff -urNp linux-2.6.28/drivers/char/agp/intel-agp.c linux-2.6.28/drivers/char/agp/intel-agp.c
16858 +--- linux-2.6.28/drivers/char/agp/intel-agp.c 2008-12-24 18:26:37.000000000 -0500
16859 ++++ linux-2.6.28/drivers/char/agp/intel-agp.c 2009-01-11 07:20:06.000000000 -0500
16860 +@@ -2360,7 +2360,7 @@ static struct pci_device_id agp_intel_pc
16861 + ID(PCI_DEVICE_ID_INTEL_IGD_E_HB),
16862 + ID(PCI_DEVICE_ID_INTEL_Q45_HB),
16863 + ID(PCI_DEVICE_ID_INTEL_G45_HB),
16864 +- { }
16865 ++ { 0, 0, 0, 0, 0, 0, 0 }
16866 + };
16867 +
16868 + MODULE_DEVICE_TABLE(pci, agp_intel_pci_table);
16869 +diff -urNp linux-2.6.28/drivers/char/hpet.c linux-2.6.28/drivers/char/hpet.c
16870 +--- linux-2.6.28/drivers/char/hpet.c 2008-12-24 18:26:37.000000000 -0500
16871 ++++ linux-2.6.28/drivers/char/hpet.c 2009-01-11 07:20:06.000000000 -0500
16872 +@@ -975,7 +975,7 @@ static struct acpi_driver hpet_acpi_driv
16873 + },
16874 + };
16875 +
16876 +-static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops };
16877 ++static struct miscdevice hpet_misc = { HPET_MINOR, "hpet", &hpet_fops, {NULL, NULL}, NULL, NULL };
16878 +
16879 + static int __init hpet_init(void)
16880 + {
16881 +diff -urNp linux-2.6.28/drivers/char/keyboard.c linux-2.6.28/drivers/char/keyboard.c
16882 +--- linux-2.6.28/drivers/char/keyboard.c 2008-12-24 18:26:37.000000000 -0500
16883 ++++ linux-2.6.28/drivers/char/keyboard.c 2009-01-11 07:20:06.000000000 -0500
16884 +@@ -635,6 +635,16 @@ static void k_spec(struct vc_data *vc, u
16885 + kbd->kbdmode == VC_MEDIUMRAW) &&
16886 + value != KVAL(K_SAK))
16887 + return; /* SAK is allowed even in raw mode */
16888 ++
16889 ++#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
16890 ++ {
16891 ++ void *func = fn_handler[value];
16892 ++ if (func == fn_show_state || func == fn_show_ptregs ||
16893 ++ func == fn_show_mem)
16894 ++ return;
16895 ++ }
16896 ++#endif
16897 ++
16898 + fn_handler[value](vc);
16899 + }
16900 +
16901 +@@ -1388,7 +1398,7 @@ static const struct input_device_id kbd_
16902 + .evbit = { BIT_MASK(EV_SND) },
16903 + },
16904 +
16905 +- { }, /* Terminating entry */
16906 ++ { 0 }, /* Terminating entry */
16907 + };
16908 +
16909 + MODULE_DEVICE_TABLE(input, kbd_ids);
16910 +diff -urNp linux-2.6.28/drivers/char/mem.c linux-2.6.28/drivers/char/mem.c
16911 +--- linux-2.6.28/drivers/char/mem.c 2008-12-24 18:26:37.000000000 -0500
16912 ++++ linux-2.6.28/drivers/char/mem.c 2009-01-11 05:46:58.000000000 -0500
16913 +@@ -27,6 +27,7 @@
16914 + #include <linux/splice.h>
16915 + #include <linux/pfn.h>
16916 + #include <linux/smp_lock.h>
16917 ++#include <linux/grsecurity.h>
16918 +
16919 + #include <asm/uaccess.h>
16920 + #include <asm/io.h>
16921 +@@ -35,6 +36,10 @@
16922 + # include <linux/efi.h>
16923 + #endif
16924 +
16925 ++#ifdef CONFIG_GRKERNSEC
16926 ++extern struct file_operations grsec_fops;
16927 ++#endif
16928 ++
16929 + /*
16930 + * Architectures vary in how they handle caching for addresses
16931 + * outside of main memory.
16932 +@@ -192,6 +197,11 @@ static ssize_t write_mem(struct file * f
16933 + if (!valid_phys_addr_range(p, count))
16934 + return -EFAULT;
16935 +
16936 ++#ifdef CONFIG_GRKERNSEC_KMEM
16937 ++ gr_handle_mem_write();
16938 ++ return -EPERM;
16939 ++#endif
16940 ++
16941 + written = 0;
16942 +
16943 + #ifdef __ARCH_HAS_NO_PAGE_ZERO_MAPPED
16944 +@@ -350,6 +360,11 @@ static int mmap_mem(struct file * file,
16945 + &vma->vm_page_prot))
16946 + return -EINVAL;
16947 +
16948 ++#ifdef CONFIG_GRKERNSEC_KMEM
16949 ++ if (gr_handle_mem_mmap(vma->vm_pgoff << PAGE_SHIFT, vma))
16950 ++ return -EPERM;
16951 ++#endif
16952 ++
16953 + vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
16954 + size,
16955 + vma->vm_page_prot);
16956 +@@ -588,6 +603,11 @@ static ssize_t write_kmem(struct file *
16957 + ssize_t written;
16958 + char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
16959 +
16960 ++#ifdef CONFIG_GRKERNSEC_KMEM
16961 ++ gr_handle_kmem_write();
16962 ++ return -EPERM;
16963 ++#endif
16964 ++
16965 + if (p < (unsigned long) high_memory) {
16966 +
16967 + wrote = count;
16968 +@@ -791,6 +811,16 @@ static loff_t memory_lseek(struct file *
16969 +
16970 + static int open_port(struct inode * inode, struct file * filp)
16971 + {
16972 ++#ifdef CONFIG_GRKERNSEC_KMEM
16973 ++ gr_handle_open_port();
16974 ++ return -EPERM;
16975 ++#endif
16976 ++
16977 ++ return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
16978 ++}
16979 ++
16980 ++static int open_mem(struct inode * inode, struct file * filp)
16981 ++{
16982 + return capable(CAP_SYS_RAWIO) ? 0 : -EPERM;
16983 + }
16984 +
16985 +@@ -798,7 +828,6 @@ static int open_port(struct inode * inod
16986 + #define full_lseek null_lseek
16987 + #define write_zero write_null
16988 + #define read_full read_zero
16989 +-#define open_mem open_port
16990 + #define open_kmem open_mem
16991 + #define open_oldmem open_mem
16992 +
16993 +@@ -938,6 +967,11 @@ static int memory_open(struct inode * in
16994 + filp->f_op = &oldmem_fops;
16995 + break;
16996 + #endif
16997 ++#ifdef CONFIG_GRKERNSEC
16998 ++ case 13:
16999 ++ filp->f_op = &grsec_fops;
17000 ++ break;
17001 ++#endif
17002 + default:
17003 + unlock_kernel();
17004 + return -ENXIO;
17005 +@@ -974,6 +1008,9 @@ static const struct {
17006 + #ifdef CONFIG_CRASH_DUMP
17007 + {12,"oldmem", S_IRUSR | S_IWUSR | S_IRGRP, &oldmem_fops},
17008 + #endif
17009 ++#ifdef CONFIG_GRKERNSEC
17010 ++ {13,"grsec", S_IRUSR | S_IWUGO, &grsec_fops},
17011 ++#endif
17012 + };
17013 +
17014 + static struct class *mem_class;
17015 +diff -urNp linux-2.6.28/drivers/char/nvram.c linux-2.6.28/drivers/char/nvram.c
17016 +--- linux-2.6.28/drivers/char/nvram.c 2008-12-24 18:26:37.000000000 -0500
17017 ++++ linux-2.6.28/drivers/char/nvram.c 2009-01-11 07:20:06.000000000 -0500
17018 +@@ -433,7 +433,10 @@ static const struct file_operations nvra
17019 + static struct miscdevice nvram_dev = {
17020 + NVRAM_MINOR,
17021 + "nvram",
17022 +- &nvram_fops
17023 ++ &nvram_fops,
17024 ++ {NULL, NULL},
17025 ++ NULL,
17026 ++ NULL
17027 + };
17028 +
17029 + static int __init
17030 +diff -urNp linux-2.6.28/drivers/char/random.c linux-2.6.28/drivers/char/random.c
17031 +--- linux-2.6.28/drivers/char/random.c 2008-12-24 18:26:37.000000000 -0500
17032 ++++ linux-2.6.28/drivers/char/random.c 2009-01-11 07:20:06.000000000 -0500
17033 +@@ -249,8 +249,13 @@
17034 + /*
17035 + * Configuration information
17036 + */
17037 ++#ifdef CONFIG_GRKERNSEC_RANDNET
17038 ++#define INPUT_POOL_WORDS 512
17039 ++#define OUTPUT_POOL_WORDS 128
17040 ++#else
17041 + #define INPUT_POOL_WORDS 128
17042 + #define OUTPUT_POOL_WORDS 32
17043 ++#endif
17044 + #define SEC_XFER_SIZE 512
17045 +
17046 + /*
17047 +@@ -287,10 +292,17 @@ static struct poolinfo {
17048 + int poolwords;
17049 + int tap1, tap2, tap3, tap4, tap5;
17050 + } poolinfo_table[] = {
17051 ++#ifdef CONFIG_GRKERNSEC_RANDNET
17052 ++ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
17053 ++ { 512, 411, 308, 208, 104, 1 },
17054 ++ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
17055 ++ { 128, 103, 76, 51, 25, 1 },
17056 ++#else
17057 + /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
17058 + { 128, 103, 76, 51, 25, 1 },
17059 + /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
17060 + { 32, 26, 20, 14, 7, 1 },
17061 ++#endif
17062 + #if 0
17063 + /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
17064 + { 2048, 1638, 1231, 819, 411, 1 },
17065 +@@ -1185,7 +1197,7 @@ EXPORT_SYMBOL(generate_random_uuid);
17066 + #include <linux/sysctl.h>
17067 +
17068 + static int min_read_thresh = 8, min_write_thresh;
17069 +-static int max_read_thresh = INPUT_POOL_WORDS * 32;
17070 ++static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
17071 + static int max_write_thresh = INPUT_POOL_WORDS * 32;
17072 + static char sysctl_bootid[16];
17073 +
17074 +diff -urNp linux-2.6.28/drivers/char/tpm/tpm.c linux-2.6.28/drivers/char/tpm/tpm.c
17075 +--- linux-2.6.28/drivers/char/tpm/tpm.c 2008-12-24 18:26:37.000000000 -0500
17076 ++++ linux-2.6.28/drivers/char/tpm/tpm.c 2009-01-11 05:46:58.000000000 -0500
17077 +@@ -1035,7 +1035,7 @@ ssize_t tpm_write(struct file *file, con
17078 +
17079 + mutex_lock(&chip->buffer_mutex);
17080 +
17081 +- if (in_size > TPM_BUFSIZE)
17082 ++ if (in_size > (unsigned int)TPM_BUFSIZE)
17083 + in_size = TPM_BUFSIZE;
17084 +
17085 + if (copy_from_user
17086 +diff -urNp linux-2.6.28/drivers/char/vt_ioctl.c linux-2.6.28/drivers/char/vt_ioctl.c
17087 +--- linux-2.6.28/drivers/char/vt_ioctl.c 2008-12-24 18:26:37.000000000 -0500
17088 ++++ linux-2.6.28/drivers/char/vt_ioctl.c 2009-01-11 05:46:58.000000000 -0500
17089 +@@ -96,6 +96,12 @@ do_kdsk_ioctl(int cmd, struct kbentry __
17090 + case KDSKBENT:
17091 + if (!perm)
17092 + return -EPERM;
17093 ++
17094 ++#ifdef CONFIG_GRKERNSEC
17095 ++ if (!capable(CAP_SYS_TTY_CONFIG))
17096 ++ return -EPERM;
17097 ++#endif
17098 ++
17099 + if (!i && v == K_NOSUCHMAP) {
17100 + /* deallocate map */
17101 + key_map = key_maps[s];
17102 +@@ -236,6 +242,13 @@ do_kdgkb_ioctl(int cmd, struct kbsentry
17103 + goto reterr;
17104 + }
17105 +
17106 ++#ifdef CONFIG_GRKERNSEC
17107 ++ if (!capable(CAP_SYS_TTY_CONFIG)) {
17108 ++ ret = -EPERM;
17109 ++ goto reterr;
17110 ++ }
17111 ++#endif
17112 ++
17113 + q = func_table[i];
17114 + first_free = funcbufptr + (funcbufsize - funcbufleft);
17115 + for (j = i+1; j < MAX_NR_FUNC && !func_table[j]; j++)
17116 +diff -urNp linux-2.6.28/drivers/edac/edac_core.h linux-2.6.28/drivers/edac/edac_core.h
17117 +--- linux-2.6.28/drivers/edac/edac_core.h 2008-12-24 18:26:37.000000000 -0500
17118 ++++ linux-2.6.28/drivers/edac/edac_core.h 2009-01-11 07:20:06.000000000 -0500
17119 +@@ -85,11 +85,11 @@ extern int edac_debug_level;
17120 +
17121 + #else /* !CONFIG_EDAC_DEBUG */
17122 +
17123 +-#define debugf0( ... )
17124 +-#define debugf1( ... )
17125 +-#define debugf2( ... )
17126 +-#define debugf3( ... )
17127 +-#define debugf4( ... )
17128 ++#define debugf0( ... ) do {} while (0)
17129 ++#define debugf1( ... ) do {} while (0)
17130 ++#define debugf2( ... ) do {} while (0)
17131 ++#define debugf3( ... ) do {} while (0)
17132 ++#define debugf4( ... ) do {} while (0)
17133 +
17134 + #endif /* !CONFIG_EDAC_DEBUG */
17135 +
17136 +diff -urNp linux-2.6.28/drivers/firmware/dmi_scan.c linux-2.6.28/drivers/firmware/dmi_scan.c
17137 +--- linux-2.6.28/drivers/firmware/dmi_scan.c 2008-12-24 18:26:37.000000000 -0500
17138 ++++ linux-2.6.28/drivers/firmware/dmi_scan.c 2009-01-11 07:20:06.000000000 -0500
17139 +@@ -389,11 +389,6 @@ void __init dmi_scan_machine(void)
17140 + }
17141 + }
17142 + else {
17143 +- /*
17144 +- * no iounmap() for that ioremap(); it would be a no-op, but
17145 +- * it's so early in setup that sucker gets confused into doing
17146 +- * what it shouldn't if we actually call it.
17147 +- */
17148 + p = dmi_ioremap(0xF0000, 0x10000);
17149 + if (p == NULL)
17150 + goto error;
17151 +diff -urNp linux-2.6.28/drivers/hwmon/fscpos.c linux-2.6.28/drivers/hwmon/fscpos.c
17152 +--- linux-2.6.28/drivers/hwmon/fscpos.c 2008-12-24 18:26:37.000000000 -0500
17153 ++++ linux-2.6.28/drivers/hwmon/fscpos.c 2009-01-11 07:20:06.000000000 -0500
17154 +@@ -240,7 +240,6 @@ static ssize_t set_pwm(struct i2c_client
17155 + unsigned long v = simple_strtoul(buf, NULL, 10);
17156 +
17157 + /* Range: 0..255 */
17158 +- if (v < 0) v = 0;
17159 + if (v > 255) v = 255;
17160 +
17161 + mutex_lock(&data->update_lock);
17162 +diff -urNp linux-2.6.28/drivers/hwmon/k8temp.c linux-2.6.28/drivers/hwmon/k8temp.c
17163 +--- linux-2.6.28/drivers/hwmon/k8temp.c 2008-12-24 18:26:37.000000000 -0500
17164 ++++ linux-2.6.28/drivers/hwmon/k8temp.c 2009-01-11 07:20:06.000000000 -0500
17165 +@@ -130,7 +130,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_n
17166 +
17167 + static struct pci_device_id k8temp_ids[] = {
17168 + { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) },
17169 +- { 0 },
17170 ++ { 0, 0, 0, 0, 0, 0, 0 },
17171 + };
17172 +
17173 + MODULE_DEVICE_TABLE(pci, k8temp_ids);
17174 +diff -urNp linux-2.6.28/drivers/hwmon/sis5595.c linux-2.6.28/drivers/hwmon/sis5595.c
17175 +--- linux-2.6.28/drivers/hwmon/sis5595.c 2008-12-24 18:26:37.000000000 -0500
17176 ++++ linux-2.6.28/drivers/hwmon/sis5595.c 2009-01-11 07:20:06.000000000 -0500
17177 +@@ -698,7 +698,7 @@ static struct sis5595_data *sis5595_upda
17178 +
17179 + static struct pci_device_id sis5595_pci_ids[] = {
17180 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
17181 +- { 0, }
17182 ++ { 0, 0, 0, 0, 0, 0, 0 }
17183 + };
17184 +
17185 + MODULE_DEVICE_TABLE(pci, sis5595_pci_ids);
17186 +diff -urNp linux-2.6.28/drivers/hwmon/via686a.c linux-2.6.28/drivers/hwmon/via686a.c
17187 +--- linux-2.6.28/drivers/hwmon/via686a.c 2008-12-24 18:26:37.000000000 -0500
17188 ++++ linux-2.6.28/drivers/hwmon/via686a.c 2009-01-11 07:20:06.000000000 -0500
17189 +@@ -768,7 +768,7 @@ static struct via686a_data *via686a_upda
17190 +
17191 + static struct pci_device_id via686a_pci_ids[] = {
17192 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4) },
17193 +- { 0, }
17194 ++ { 0, 0, 0, 0, 0, 0, 0 }
17195 + };
17196 +
17197 + MODULE_DEVICE_TABLE(pci, via686a_pci_ids);
17198 +diff -urNp linux-2.6.28/drivers/hwmon/vt8231.c linux-2.6.28/drivers/hwmon/vt8231.c
17199 +--- linux-2.6.28/drivers/hwmon/vt8231.c 2008-12-24 18:26:37.000000000 -0500
17200 ++++ linux-2.6.28/drivers/hwmon/vt8231.c 2009-01-11 07:20:06.000000000 -0500
17201 +@@ -698,7 +698,7 @@ static struct platform_driver vt8231_dri
17202 +
17203 + static struct pci_device_id vt8231_pci_ids[] = {
17204 + { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
17205 +- { 0, }
17206 ++ { 0, 0, 0, 0, 0, 0, 0 }
17207 + };
17208 +
17209 + MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
17210 +diff -urNp linux-2.6.28/drivers/hwmon/w83791d.c linux-2.6.28/drivers/hwmon/w83791d.c
17211 +--- linux-2.6.28/drivers/hwmon/w83791d.c 2008-12-24 18:26:37.000000000 -0500
17212 ++++ linux-2.6.28/drivers/hwmon/w83791d.c 2009-01-11 07:20:06.000000000 -0500
17213 +@@ -327,8 +327,8 @@ static int w83791d_detect(struct i2c_cli
17214 + struct i2c_board_info *info);
17215 + static int w83791d_remove(struct i2c_client *client);
17216 +
17217 +-static int w83791d_read(struct i2c_client *client, u8 register);
17218 +-static int w83791d_write(struct i2c_client *client, u8 register, u8 value);
17219 ++static int w83791d_read(struct i2c_client *client, u8 reg);
17220 ++static int w83791d_write(struct i2c_client *client, u8 reg, u8 value);
17221 + static struct w83791d_data *w83791d_update_device(struct device *dev);
17222 +
17223 + #ifdef DEBUG
17224 +diff -urNp linux-2.6.28/drivers/i2c/busses/i2c-i801.c linux-2.6.28/drivers/i2c/busses/i2c-i801.c
17225 +--- linux-2.6.28/drivers/i2c/busses/i2c-i801.c 2008-12-24 18:26:37.000000000 -0500
17226 ++++ linux-2.6.28/drivers/i2c/busses/i2c-i801.c 2009-01-11 07:20:06.000000000 -0500
17227 +@@ -578,7 +578,7 @@ static struct pci_device_id i801_ids[] =
17228 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_4) },
17229 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_5) },
17230 + { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PCH_SMBUS) },
17231 +- { 0, }
17232 ++ { 0, 0, 0, 0, 0, 0, 0 }
17233 + };
17234 +
17235 + MODULE_DEVICE_TABLE (pci, i801_ids);
17236 +diff -urNp linux-2.6.28/drivers/i2c/busses/i2c-piix4.c linux-2.6.28/drivers/i2c/busses/i2c-piix4.c
17237 +--- linux-2.6.28/drivers/i2c/busses/i2c-piix4.c 2008-12-24 18:26:37.000000000 -0500
17238 ++++ linux-2.6.28/drivers/i2c/busses/i2c-piix4.c 2009-01-11 07:20:06.000000000 -0500
17239 +@@ -123,7 +123,7 @@ static struct dmi_system_id __devinitdat
17240 + .ident = "IBM",
17241 + .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
17242 + },
17243 +- { },
17244 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, NULL)}, NULL },
17245 + };
17246 +
17247 + static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
17248 +@@ -424,7 +424,7 @@ static struct pci_device_id piix4_ids[]
17249 + PCI_DEVICE_ID_SERVERWORKS_CSB6) },
17250 + { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
17251 + PCI_DEVICE_ID_SERVERWORKS_HT1000SB) },
17252 +- { 0, }
17253 ++ { 0, 0, 0, 0, 0, 0, 0 }
17254 + };
17255 +
17256 + MODULE_DEVICE_TABLE (pci, piix4_ids);
17257 +diff -urNp linux-2.6.28/drivers/i2c/busses/i2c-sis630.c linux-2.6.28/drivers/i2c/busses/i2c-sis630.c
17258 +--- linux-2.6.28/drivers/i2c/busses/i2c-sis630.c 2008-12-24 18:26:37.000000000 -0500
17259 ++++ linux-2.6.28/drivers/i2c/busses/i2c-sis630.c 2009-01-11 07:20:06.000000000 -0500
17260 +@@ -472,7 +472,7 @@ static struct i2c_adapter sis630_adapter
17261 + static struct pci_device_id sis630_ids[] __devinitdata = {
17262 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503) },
17263 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC) },
17264 +- { 0, }
17265 ++ { 0, 0, 0, 0, 0, 0, 0 }
17266 + };
17267 +
17268 + MODULE_DEVICE_TABLE (pci, sis630_ids);
17269 +diff -urNp linux-2.6.28/drivers/i2c/busses/i2c-sis96x.c linux-2.6.28/drivers/i2c/busses/i2c-sis96x.c
17270 +--- linux-2.6.28/drivers/i2c/busses/i2c-sis96x.c 2008-12-24 18:26:37.000000000 -0500
17271 ++++ linux-2.6.28/drivers/i2c/busses/i2c-sis96x.c 2009-01-11 07:20:06.000000000 -0500
17272 +@@ -248,7 +248,7 @@ static struct i2c_adapter sis96x_adapter
17273 +
17274 + static struct pci_device_id sis96x_ids[] = {
17275 + { PCI_DEVICE(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_SMBUS) },
17276 +- { 0, }
17277 ++ { 0, 0, 0, 0, 0, 0, 0 }
17278 + };
17279 +
17280 + MODULE_DEVICE_TABLE (pci, sis96x_ids);
17281 +diff -urNp linux-2.6.28/drivers/ieee1394/dv1394.c linux-2.6.28/drivers/ieee1394/dv1394.c
17282 +--- linux-2.6.28/drivers/ieee1394/dv1394.c 2008-12-24 18:26:37.000000000 -0500
17283 ++++ linux-2.6.28/drivers/ieee1394/dv1394.c 2009-01-11 07:20:06.000000000 -0500
17284 +@@ -739,7 +739,7 @@ static void frame_prepare(struct video_c
17285 + based upon DIF section and sequence
17286 + */
17287 +
17288 +-static void inline
17289 ++static inline void
17290 + frame_put_packet (struct frame *f, struct packet *p)
17291 + {
17292 + int section_type = p->data[0] >> 5; /* section type is in bits 5 - 7 */
17293 +@@ -2177,7 +2177,7 @@ static struct ieee1394_device_id dv1394_
17294 + .specifier_id = AVC_UNIT_SPEC_ID_ENTRY & 0xffffff,
17295 + .version = AVC_SW_VERSION_ENTRY & 0xffffff
17296 + },
17297 +- { }
17298 ++ { 0, 0, 0, 0, 0, 0 }
17299 + };
17300 +
17301 + MODULE_DEVICE_TABLE(ieee1394, dv1394_id_table);
17302 +diff -urNp linux-2.6.28/drivers/ieee1394/eth1394.c linux-2.6.28/drivers/ieee1394/eth1394.c
17303 +--- linux-2.6.28/drivers/ieee1394/eth1394.c 2008-12-24 18:26:37.000000000 -0500
17304 ++++ linux-2.6.28/drivers/ieee1394/eth1394.c 2009-01-11 07:20:06.000000000 -0500
17305 +@@ -451,7 +451,7 @@ static struct ieee1394_device_id eth1394
17306 + .specifier_id = ETHER1394_GASP_SPECIFIER_ID,
17307 + .version = ETHER1394_GASP_VERSION,
17308 + },
17309 +- {}
17310 ++ { 0, 0, 0, 0, 0, 0 }
17311 + };
17312 +
17313 + MODULE_DEVICE_TABLE(ieee1394, eth1394_id_table);
17314 +diff -urNp linux-2.6.28/drivers/ieee1394/hosts.c linux-2.6.28/drivers/ieee1394/hosts.c
17315 +--- linux-2.6.28/drivers/ieee1394/hosts.c 2008-12-24 18:26:37.000000000 -0500
17316 ++++ linux-2.6.28/drivers/ieee1394/hosts.c 2009-01-11 07:20:06.000000000 -0500
17317 +@@ -78,6 +78,7 @@ static int dummy_isoctl(struct hpsb_iso
17318 + }
17319 +
17320 + static struct hpsb_host_driver dummy_driver = {
17321 ++ .name = "dummy",
17322 + .transmit_packet = dummy_transmit_packet,
17323 + .devctl = dummy_devctl,
17324 + .isoctl = dummy_isoctl
17325 +diff -urNp linux-2.6.28/drivers/ieee1394/ohci1394.c linux-2.6.28/drivers/ieee1394/ohci1394.c
17326 +--- linux-2.6.28/drivers/ieee1394/ohci1394.c 2008-12-24 18:26:37.000000000 -0500
17327 ++++ linux-2.6.28/drivers/ieee1394/ohci1394.c 2009-01-11 07:20:06.000000000 -0500
17328 +@@ -147,9 +147,9 @@ printk(level "%s: " fmt "\n" , OHCI1394_
17329 + printk(level "%s: fw-host%d: " fmt "\n" , OHCI1394_DRIVER_NAME, ohci->host->id , ## args)
17330 +
17331 + /* Module Parameters */
17332 +-static int phys_dma = 1;
17333 ++static int phys_dma;
17334 + module_param(phys_dma, int, 0444);
17335 +-MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 1).");
17336 ++MODULE_PARM_DESC(phys_dma, "Enable physical DMA (default = 0).");
17337 +
17338 + static void dma_trm_tasklet(unsigned long data);
17339 + static void dma_trm_reset(struct dma_trm_ctx *d);
17340 +@@ -3437,7 +3437,7 @@ static struct pci_device_id ohci1394_pci
17341 + .subvendor = PCI_ANY_ID,
17342 + .subdevice = PCI_ANY_ID,
17343 + },
17344 +- { 0, },
17345 ++ { 0, 0, 0, 0, 0, 0, 0 },
17346 + };
17347 +
17348 + MODULE_DEVICE_TABLE(pci, ohci1394_pci_tbl);
17349 +diff -urNp linux-2.6.28/drivers/ieee1394/raw1394.c linux-2.6.28/drivers/ieee1394/raw1394.c
17350 +--- linux-2.6.28/drivers/ieee1394/raw1394.c 2008-12-24 18:26:37.000000000 -0500
17351 ++++ linux-2.6.28/drivers/ieee1394/raw1394.c 2009-01-11 07:20:06.000000000 -0500
17352 +@@ -2995,7 +2995,7 @@ static struct ieee1394_device_id raw1394
17353 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
17354 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
17355 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff},
17356 +- {}
17357 ++ { 0, 0, 0, 0, 0, 0 }
17358 + };
17359 +
17360 + MODULE_DEVICE_TABLE(ieee1394, raw1394_id_table);
17361 +diff -urNp linux-2.6.28/drivers/ieee1394/sbp2.c linux-2.6.28/drivers/ieee1394/sbp2.c
17362 +--- linux-2.6.28/drivers/ieee1394/sbp2.c 2008-12-24 18:26:37.000000000 -0500
17363 ++++ linux-2.6.28/drivers/ieee1394/sbp2.c 2009-01-11 07:20:06.000000000 -0500
17364 +@@ -290,7 +290,7 @@ static struct ieee1394_device_id sbp2_id
17365 + .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION,
17366 + .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff,
17367 + .version = SBP2_SW_VERSION_ENTRY & 0xffffff},
17368 +- {}
17369 ++ { 0, 0, 0, 0, 0, 0 }
17370 + };
17371 + MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);
17372 +
17373 +@@ -2100,7 +2100,7 @@ MODULE_DESCRIPTION("IEEE-1394 SBP-2 prot
17374 + MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME);
17375 + MODULE_LICENSE("GPL");
17376 +
17377 +-static int sbp2_module_init(void)
17378 ++static int __init sbp2_module_init(void)
17379 + {
17380 + int ret;
17381 +
17382 +diff -urNp linux-2.6.28/drivers/ieee1394/video1394.c linux-2.6.28/drivers/ieee1394/video1394.c
17383 +--- linux-2.6.28/drivers/ieee1394/video1394.c 2008-12-24 18:26:37.000000000 -0500
17384 ++++ linux-2.6.28/drivers/ieee1394/video1394.c 2009-01-11 07:20:06.000000000 -0500
17385 +@@ -1310,7 +1310,7 @@ static struct ieee1394_device_id video13
17386 + .specifier_id = CAMERA_UNIT_SPEC_ID_ENTRY & 0xffffff,
17387 + .version = (CAMERA_SW_VERSION_ENTRY + 2) & 0xffffff
17388 + },
17389 +- { }
17390 ++ { 0, 0, 0, 0, 0, 0 }
17391 + };
17392 +
17393 + MODULE_DEVICE_TABLE(ieee1394, video1394_id_table);
17394 +diff -urNp linux-2.6.28/drivers/input/keyboard/atkbd.c linux-2.6.28/drivers/input/keyboard/atkbd.c
17395 +--- linux-2.6.28/drivers/input/keyboard/atkbd.c 2008-12-24 18:26:37.000000000 -0500
17396 ++++ linux-2.6.28/drivers/input/keyboard/atkbd.c 2009-01-11 07:20:06.000000000 -0500
17397 +@@ -1148,7 +1148,7 @@ static struct serio_device_id atkbd_seri
17398 + .id = SERIO_ANY,
17399 + .extra = SERIO_ANY,
17400 + },
17401 +- { 0 }
17402 ++ { 0, 0, 0, 0 }
17403 + };
17404 +
17405 + MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
17406 +diff -urNp linux-2.6.28/drivers/input/mouse/lifebook.c linux-2.6.28/drivers/input/mouse/lifebook.c
17407 +--- linux-2.6.28/drivers/input/mouse/lifebook.c 2008-12-24 18:26:37.000000000 -0500
17408 ++++ linux-2.6.28/drivers/input/mouse/lifebook.c 2009-01-11 07:20:06.000000000 -0500
17409 +@@ -110,7 +110,7 @@ static const struct dmi_system_id lifebo
17410 + DMI_MATCH(DMI_PRODUCT_NAME, "LifeBook B142"),
17411 + },
17412 + },
17413 +- { }
17414 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL}
17415 + };
17416 +
17417 + static psmouse_ret_t lifebook_process_byte(struct psmouse *psmouse)
17418 +diff -urNp linux-2.6.28/drivers/input/mouse/psmouse-base.c linux-2.6.28/drivers/input/mouse/psmouse-base.c
17419 +--- linux-2.6.28/drivers/input/mouse/psmouse-base.c 2008-12-24 18:26:37.000000000 -0500
17420 ++++ linux-2.6.28/drivers/input/mouse/psmouse-base.c 2009-01-11 07:20:06.000000000 -0500
17421 +@@ -1378,7 +1378,7 @@ static struct serio_device_id psmouse_se
17422 + .id = SERIO_ANY,
17423 + .extra = SERIO_ANY,
17424 + },
17425 +- { 0 }
17426 ++ { 0, 0, 0, 0 }
17427 + };
17428 +
17429 + MODULE_DEVICE_TABLE(serio, psmouse_serio_ids);
17430 +diff -urNp linux-2.6.28/drivers/input/mouse/synaptics.c linux-2.6.28/drivers/input/mouse/synaptics.c
17431 +--- linux-2.6.28/drivers/input/mouse/synaptics.c 2008-12-24 18:26:37.000000000 -0500
17432 ++++ linux-2.6.28/drivers/input/mouse/synaptics.c 2009-01-11 07:20:06.000000000 -0500
17433 +@@ -417,7 +417,7 @@ static void synaptics_process_packet(str
17434 + break;
17435 + case 2:
17436 + if (SYN_MODEL_PEN(priv->model_id))
17437 +- ; /* Nothing, treat a pen as a single finger */
17438 ++ break; /* Nothing, treat a pen as a single finger */
17439 + break;
17440 + case 4 ... 15:
17441 + if (SYN_CAP_PALMDETECT(priv->capabilities))
17442 +@@ -624,7 +624,7 @@ static const struct dmi_system_id toshib
17443 + DMI_MATCH(DMI_PRODUCT_NAME, "PORTEGE M300"),
17444 + },
17445 + },
17446 +- { }
17447 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
17448 + };
17449 + #endif
17450 +
17451 +diff -urNp linux-2.6.28/drivers/input/mousedev.c linux-2.6.28/drivers/input/mousedev.c
17452 +--- linux-2.6.28/drivers/input/mousedev.c 2008-12-24 18:26:37.000000000 -0500
17453 ++++ linux-2.6.28/drivers/input/mousedev.c 2009-01-11 07:20:06.000000000 -0500
17454 +@@ -1063,7 +1063,7 @@ static struct input_handler mousedev_han
17455 +
17456 + #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX
17457 + static struct miscdevice psaux_mouse = {
17458 +- PSMOUSE_MINOR, "psaux", &mousedev_fops
17459 ++ PSMOUSE_MINOR, "psaux", &mousedev_fops, {NULL, NULL}, NULL, NULL
17460 + };
17461 + static int psaux_registered;
17462 + #endif
17463 +diff -urNp linux-2.6.28/drivers/input/serio/i8042-x86ia64io.h linux-2.6.28/drivers/input/serio/i8042-x86ia64io.h
17464 +--- linux-2.6.28/drivers/input/serio/i8042-x86ia64io.h 2008-12-24 18:26:37.000000000 -0500
17465 ++++ linux-2.6.28/drivers/input/serio/i8042-x86ia64io.h 2009-01-11 07:20:06.000000000 -0500
17466 +@@ -143,7 +143,7 @@ static struct dmi_system_id __initdata i
17467 + DMI_MATCH(DMI_PRODUCT_VERSION, "M606"),
17468 + },
17469 + },
17470 +- { }
17471 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
17472 + };
17473 +
17474 + /*
17475 +@@ -351,7 +351,7 @@ static struct dmi_system_id __initdata i
17476 + DMI_MATCH(DMI_PRODUCT_NAME, "HEL80I"),
17477 + },
17478 + },
17479 +- { }
17480 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
17481 + };
17482 +
17483 + #ifdef CONFIG_PNP
17484 +@@ -363,7 +363,7 @@ static struct dmi_system_id __initdata i
17485 + DMI_MATCH(DMI_BOARD_VENDOR, "Intel Corporation"),
17486 + },
17487 + },
17488 +- { }
17489 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
17490 + };
17491 + #endif
17492 +
17493 +@@ -430,7 +430,7 @@ static struct dmi_system_id __initdata i
17494 + DMI_MATCH(DMI_PRODUCT_NAME, "TravelMate 4280"),
17495 + },
17496 + },
17497 +- { }
17498 ++ { NULL, NULL, {DMI_MATCH(DMI_NONE, {0})}, NULL }
17499 + };
17500 +
17501 + #endif /* CONFIG_X86 */
17502 +diff -urNp linux-2.6.28/drivers/input/serio/serio_raw.c linux-2.6.28/drivers/input/serio/serio_raw.c
17503 +--- linux-2.6.28/drivers/input/serio/serio_raw.c 2008-12-24 18:26:37.000000000 -0500
17504 ++++ linux-2.6.28/drivers/input/serio/serio_raw.c 2009-01-11 07:20:06.000000000 -0500
17505 +@@ -378,7 +378,7 @@ static struct serio_device_id serio_raw_
17506 + .id = SERIO_ANY,
17507 + .extra = SERIO_ANY,
17508 + },
17509 +- { 0 }
17510 ++ { 0, 0, 0, 0 }
17511 + };
17512 +
17513 + MODULE_DEVICE_TABLE(serio, serio_raw_serio_ids);
17514 +diff -urNp linux-2.6.28/drivers/md/bitmap.c linux-2.6.28/drivers/md/bitmap.c
17515 +--- linux-2.6.28/drivers/md/bitmap.c 2008-12-24 18:26:37.000000000 -0500
17516 ++++ linux-2.6.28/drivers/md/bitmap.c 2009-01-11 07:20:06.000000000 -0500
17517 +@@ -57,7 +57,7 @@
17518 + # if DEBUG > 0
17519 + # define PRINTK(x...) printk(KERN_DEBUG x)
17520 + # else
17521 +-# define PRINTK(x...)
17522 ++# define PRINTK(x...) do {} while (0)
17523 + # endif
17524 + #endif
17525 +
17526 +diff -urNp linux-2.6.28/drivers/mtd/devices/doc2000.c linux-2.6.28/drivers/mtd/devices/doc2000.c
17527 +--- linux-2.6.28/drivers/mtd/devices/doc2000.c 2008-12-24 18:26:37.000000000 -0500
17528 ++++ linux-2.6.28/drivers/mtd/devices/doc2000.c 2009-01-11 07:20:06.000000000 -0500
17529 +@@ -777,7 +777,7 @@ static int doc_write(struct mtd_info *mt
17530 +
17531 + /* The ECC will not be calculated correctly if less than 512 is written */
17532 + /* DBB-
17533 +- if (len != 0x200 && eccbuf)
17534 ++ if (len != 0x200)
17535 + printk(KERN_WARNING
17536 + "ECC needs a full sector write (adr: %lx size %lx)\n",
17537 + (long) to, (long) len);
17538 +diff -urNp linux-2.6.28/drivers/mtd/devices/doc2001.c linux-2.6.28/drivers/mtd/devices/doc2001.c
17539 +--- linux-2.6.28/drivers/mtd/devices/doc2001.c 2008-12-24 18:26:37.000000000 -0500
17540 ++++ linux-2.6.28/drivers/mtd/devices/doc2001.c 2009-01-11 05:46:58.000000000 -0500
17541 +@@ -396,6 +396,8 @@ static int doc_read (struct mtd_info *mt
17542 + /* Don't allow read past end of device */
17543 + if (from >= this->totlen)
17544 + return -EINVAL;
17545 ++ if (!len)
17546 ++ return -EINVAL;
17547 +
17548 + /* Don't allow a single read to cross a 512-byte block boundary */
17549 + if (from + len > ((from | 0x1ff) + 1))
17550 +diff -urNp linux-2.6.28/drivers/mtd/devices/slram.c linux-2.6.28/drivers/mtd/devices/slram.c
17551 +--- linux-2.6.28/drivers/mtd/devices/slram.c 2008-12-24 18:26:37.000000000 -0500
17552 ++++ linux-2.6.28/drivers/mtd/devices/slram.c 2009-01-11 07:20:06.000000000 -0500
17553 +@@ -273,7 +273,7 @@ static int parse_cmdline(char *devname,
17554 + }
17555 + T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n",
17556 + devname, devstart, devlength);
17557 +- if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) {
17558 ++ if (devlength % SLRAM_BLK_SZ != 0) {
17559 + E("slram: Illegal start / length parameter.\n");
17560 + return(-EINVAL);
17561 + }
17562 +diff -urNp linux-2.6.28/drivers/mtd/ubi/build.c linux-2.6.28/drivers/mtd/ubi/build.c
17563 +--- linux-2.6.28/drivers/mtd/ubi/build.c 2008-12-24 18:26:37.000000000 -0500
17564 ++++ linux-2.6.28/drivers/mtd/ubi/build.c 2009-01-11 07:20:06.000000000 -0500
17565 +@@ -1104,7 +1104,7 @@ static int __init bytes_str_to_int(const
17566 + unsigned long result;
17567 +
17568 + result = simple_strtoul(str, &endp, 0);
17569 +- if (str == endp || result < 0) {
17570 ++ if (str == endp) {
17571 + printk(KERN_ERR "UBI error: incorrect bytes count: \"%s\"\n",
17572 + str);
17573 + return -EINVAL;
17574 +diff -urNp linux-2.6.28/drivers/net/eepro100.c linux-2.6.28/drivers/net/eepro100.c
17575 +--- linux-2.6.28/drivers/net/eepro100.c 2008-12-24 18:26:37.000000000 -0500
17576 ++++ linux-2.6.28/drivers/net/eepro100.c 2009-01-11 07:20:06.000000000 -0500
17577 +@@ -47,7 +47,7 @@ static int rxdmacount /* = 0 */;
17578 + # define rx_align(skb) skb_reserve((skb), 2)
17579 + # define RxFD_ALIGNMENT __attribute__ ((aligned (2), packed))
17580 + #else
17581 +-# define rx_align(skb)
17582 ++# define rx_align(skb) do {} while (0)
17583 + # define RxFD_ALIGNMENT
17584 + #endif
17585 +
17586 +@@ -2334,33 +2334,33 @@ static void __devexit eepro100_remove_on
17587 + }
17588 +
17589 + static struct pci_device_id eepro100_pci_tbl[] = {
17590 +- { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, },
17591 +- { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, },
17592 +- { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, },
17593 +- { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, },
17594 +- { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, },
17595 +- { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, },
17596 +- { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, },
17597 +- { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, },
17598 +- { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, },
17599 +- { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, },
17600 +- { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, },
17601 +- { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, },
17602 +- { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, },
17603 +- { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, },
17604 +- { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, },
17605 +- { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, },
17606 +- { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, },
17607 +- { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, },
17608 +- { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, },
17609 +- { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, },
17610 +- { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, },
17611 +- { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, },
17612 +- { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, },
17613 +- { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, },
17614 +- { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, },
17615 +- { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, },
17616 +- { 0,}
17617 ++ { PCI_VENDOR_ID_INTEL, 0x1229, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17618 ++ { PCI_VENDOR_ID_INTEL, 0x1209, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17619 ++ { PCI_VENDOR_ID_INTEL, 0x1029, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17620 ++ { PCI_VENDOR_ID_INTEL, 0x1030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17621 ++ { PCI_VENDOR_ID_INTEL, 0x1031, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17622 ++ { PCI_VENDOR_ID_INTEL, 0x1032, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17623 ++ { PCI_VENDOR_ID_INTEL, 0x1033, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17624 ++ { PCI_VENDOR_ID_INTEL, 0x1034, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17625 ++ { PCI_VENDOR_ID_INTEL, 0x1035, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17626 ++ { PCI_VENDOR_ID_INTEL, 0x1036, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17627 ++ { PCI_VENDOR_ID_INTEL, 0x1037, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17628 ++ { PCI_VENDOR_ID_INTEL, 0x1038, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17629 ++ { PCI_VENDOR_ID_INTEL, 0x1039, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17630 ++ { PCI_VENDOR_ID_INTEL, 0x103A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17631 ++ { PCI_VENDOR_ID_INTEL, 0x103B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17632 ++ { PCI_VENDOR_ID_INTEL, 0x103C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17633 ++ { PCI_VENDOR_ID_INTEL, 0x103D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17634 ++ { PCI_VENDOR_ID_INTEL, 0x103E, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17635 ++ { PCI_VENDOR_ID_INTEL, 0x1050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17636 ++ { PCI_VENDOR_ID_INTEL, 0x1059, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17637 ++ { PCI_VENDOR_ID_INTEL, 0x1227, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17638 ++ { PCI_VENDOR_ID_INTEL, 0x2449, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17639 ++ { PCI_VENDOR_ID_INTEL, 0x2459, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17640 ++ { PCI_VENDOR_ID_INTEL, 0x245D, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17641 ++ { PCI_VENDOR_ID_INTEL, 0x5200, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17642 ++ { PCI_VENDOR_ID_INTEL, 0x5201, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
17643 ++ { 0, 0, 0, 0, 0, 0, 0 }
17644 + };
17645 + MODULE_DEVICE_TABLE(pci, eepro100_pci_tbl);
17646 +
17647 +diff -urNp linux-2.6.28/drivers/net/irda/vlsi_ir.c linux-2.6.28/drivers/net/irda/vlsi_ir.c
17648 +--- linux-2.6.28/drivers/net/irda/vlsi_ir.c 2008-12-24 18:26:37.000000000 -0500
17649 ++++ linux-2.6.28/drivers/net/irda/vlsi_ir.c 2009-01-11 07:20:06.000000000 -0500
17650 +@@ -906,13 +906,12 @@ static int vlsi_hard_start_xmit(struct s
17651 + /* no race - tx-ring already empty */
17652 + vlsi_set_baud(idev, iobase);
17653 + netif_wake_queue(ndev);
17654 +- }
17655 +- else
17656 +- ;
17657 ++ } else {
17658 + /* keep the speed change pending like it would
17659 + * for any len>0 packet. tx completion interrupt
17660 + * will apply it when the tx ring becomes empty.
17661 + */
17662 ++ }
17663 + spin_unlock_irqrestore(&idev->lock, flags);
17664 + dev_kfree_skb_any(skb);
17665 + return 0;
17666 +diff -urNp linux-2.6.28/drivers/net/pcnet32.c linux-2.6.28/drivers/net/pcnet32.c
17667 +--- linux-2.6.28/drivers/net/pcnet32.c 2008-12-24 18:26:37.000000000 -0500
17668 ++++ linux-2.6.28/drivers/net/pcnet32.c 2009-01-11 07:20:06.000000000 -0500
17669 +@@ -78,7 +78,7 @@ static int cards_found;
17670 + /*
17671 + * VLB I/O addresses
17672 + */
17673 +-static unsigned int pcnet32_portlist[] __initdata =
17674 ++static unsigned int pcnet32_portlist[] __devinitdata =
17675 + { 0x300, 0x320, 0x340, 0x360, 0 };
17676 +
17677 + static int pcnet32_debug = 0;
17678 +diff -urNp linux-2.6.28/drivers/net/tg3.h linux-2.6.28/drivers/net/tg3.h
17679 +--- linux-2.6.28/drivers/net/tg3.h 2008-12-24 18:26:37.000000000 -0500
17680 ++++ linux-2.6.28/drivers/net/tg3.h 2009-01-11 07:20:06.000000000 -0500
17681 +@@ -102,6 +102,7 @@
17682 + #define CHIPREV_ID_5750_A0 0x4000
17683 + #define CHIPREV_ID_5750_A1 0x4001
17684 + #define CHIPREV_ID_5750_A3 0x4003
17685 ++#define CHIPREV_ID_5750_C1 0x4201
17686 + #define CHIPREV_ID_5750_C2 0x4202
17687 + #define CHIPREV_ID_5752_A0_HW 0x5000
17688 + #define CHIPREV_ID_5752_A0 0x6000
17689 +diff -urNp linux-2.6.28/drivers/net/wireless/iwlwifi/iwl3945-base.c linux-2.6.28/drivers/net/wireless/iwlwifi/iwl3945-base.c
17690 +--- linux-2.6.28/drivers/net/wireless/iwlwifi/iwl3945-base.c 2008-12-24 18:26:37.000000000 -0500
17691 ++++ linux-2.6.28/drivers/net/wireless/iwlwifi/iwl3945-base.c 2009-01-11 07:20:06.000000000 -0500
17692 +@@ -785,7 +785,7 @@ static int iwl3945_send_cmd_sync(struct
17693 + IWL_ERROR("Error: Response NULL in '%s'\n",
17694 + get_cmd_string(cmd->id));
17695 + ret = -EIO;
17696 +- goto out;
17697 ++ goto cancel;
17698 + }
17699 +
17700 + ret = 0;
17701 +diff -urNp linux-2.6.28/drivers/pci/hotplug/cpqphp_nvram.c linux-2.6.28/drivers/pci/hotplug/cpqphp_nvram.c
17702 +--- linux-2.6.28/drivers/pci/hotplug/cpqphp_nvram.c 2008-12-24 18:26:37.000000000 -0500
17703 ++++ linux-2.6.28/drivers/pci/hotplug/cpqphp_nvram.c 2009-01-11 07:20:06.000000000 -0500
17704 +@@ -425,9 +425,13 @@ static u32 store_HRT (void __iomem *rom_
17705 +
17706 + void compaq_nvram_init (void __iomem *rom_start)
17707 + {
17708 ++
17709 ++#ifndef CONFIG_PAX_KERNEXEC
17710 + if (rom_start) {
17711 + compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
17712 + }
17713 ++#endif
17714 ++
17715 + dbg("int15 entry = %p\n", compaq_int15_entry_point);
17716 +
17717 + /* initialize our int15 lock */
17718 +diff -urNp linux-2.6.28/drivers/pci/pcie/aer/aerdrv.c linux-2.6.28/drivers/pci/pcie/aer/aerdrv.c
17719 +--- linux-2.6.28/drivers/pci/pcie/aer/aerdrv.c 2008-12-24 18:26:37.000000000 -0500
17720 ++++ linux-2.6.28/drivers/pci/pcie/aer/aerdrv.c 2009-01-11 07:20:06.000000000 -0500
17721 +@@ -59,7 +59,7 @@ static struct pcie_port_service_id aer_i
17722 + .port_type = PCIE_RC_PORT,
17723 + .service_type = PCIE_PORT_SERVICE_AER,
17724 + },
17725 +- { /* end: all zeroes */ }
17726 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0 }
17727 + };
17728 +
17729 + static struct pci_error_handlers aer_error_handlers = {
17730 +diff -urNp linux-2.6.28/drivers/pci/pcie/aer/aerdrv_core.c linux-2.6.28/drivers/pci/pcie/aer/aerdrv_core.c
17731 +--- linux-2.6.28/drivers/pci/pcie/aer/aerdrv_core.c 2008-12-24 18:26:37.000000000 -0500
17732 ++++ linux-2.6.28/drivers/pci/pcie/aer/aerdrv_core.c 2009-01-11 07:20:06.000000000 -0500
17733 +@@ -637,7 +637,7 @@ static void aer_isr_one_error(struct pci
17734 + struct aer_err_source *e_src)
17735 + {
17736 + struct device *s_device;
17737 +- struct aer_err_info e_info = {0, 0, 0,};
17738 ++ struct aer_err_info e_info = {0, 0, 0, {0, 0, 0, 0}};
17739 + int i;
17740 + u16 id;
17741 +
17742 +diff -urNp linux-2.6.28/drivers/pci/pcie/portdrv_pci.c linux-2.6.28/drivers/pci/pcie/portdrv_pci.c
17743 +--- linux-2.6.28/drivers/pci/pcie/portdrv_pci.c 2008-12-24 18:26:37.000000000 -0500
17744 ++++ linux-2.6.28/drivers/pci/pcie/portdrv_pci.c 2009-01-11 07:20:06.000000000 -0500
17745 +@@ -264,7 +264,7 @@ static void pcie_portdrv_err_resume(stru
17746 + static const struct pci_device_id port_pci_ids[] = { {
17747 + /* handle any PCI-Express port */
17748 + PCI_DEVICE_CLASS(((PCI_CLASS_BRIDGE_PCI << 8) | 0x00), ~0),
17749 +- }, { /* end: all zeroes */ }
17750 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
17751 + };
17752 + MODULE_DEVICE_TABLE(pci, port_pci_ids);
17753 +
17754 +diff -urNp linux-2.6.28/drivers/pci/proc.c linux-2.6.28/drivers/pci/proc.c
17755 +--- linux-2.6.28/drivers/pci/proc.c 2008-12-24 18:26:37.000000000 -0500
17756 ++++ linux-2.6.28/drivers/pci/proc.c 2009-01-11 05:46:58.000000000 -0500
17757 +@@ -470,7 +470,16 @@ static const struct file_operations proc
17758 + static int __init pci_proc_init(void)
17759 + {
17760 + struct pci_dev *dev = NULL;
17761 ++
17762 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
17763 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
17764 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
17765 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
17766 ++ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
17767 ++#endif
17768 ++#else
17769 + proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
17770 ++#endif
17771 + proc_create("devices", 0, proc_bus_pci_dir,
17772 + &proc_bus_pci_dev_operations);
17773 + proc_initialized = 1;
17774 +diff -urNp linux-2.6.28/drivers/pcmcia/ti113x.h linux-2.6.28/drivers/pcmcia/ti113x.h
17775 +--- linux-2.6.28/drivers/pcmcia/ti113x.h 2008-12-24 18:26:37.000000000 -0500
17776 ++++ linux-2.6.28/drivers/pcmcia/ti113x.h 2009-01-11 07:20:06.000000000 -0500
17777 +@@ -903,7 +903,7 @@ static struct pci_device_id ene_tune_tbl
17778 + DEVID(PCI_VENDOR_ID_MOTOROLA, 0x3410, 0xECC0, PCI_ANY_ID,
17779 + ENE_TEST_C9_TLTENABLE | ENE_TEST_C9_PFENABLE, ENE_TEST_C9_TLTENABLE),
17780 +
17781 +- {}
17782 ++ { 0, 0, 0, 0, 0, 0, 0 }
17783 + };
17784 +
17785 + static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
17786 +diff -urNp linux-2.6.28/drivers/pcmcia/yenta_socket.c linux-2.6.28/drivers/pcmcia/yenta_socket.c
17787 +--- linux-2.6.28/drivers/pcmcia/yenta_socket.c 2008-12-24 18:26:37.000000000 -0500
17788 ++++ linux-2.6.28/drivers/pcmcia/yenta_socket.c 2009-01-11 07:20:06.000000000 -0500
17789 +@@ -1366,7 +1366,7 @@ static struct pci_device_id yenta_table
17790 +
17791 + /* match any cardbus bridge */
17792 + CB_ID(PCI_ANY_ID, PCI_ANY_ID, DEFAULT),
17793 +- { /* all zeroes */ }
17794 ++ { 0, 0, 0, 0, 0, 0, 0 }
17795 + };
17796 + MODULE_DEVICE_TABLE(pci, yenta_table);
17797 +
17798 +diff -urNp linux-2.6.28/drivers/pnp/pnpbios/bioscalls.c linux-2.6.28/drivers/pnp/pnpbios/bioscalls.c
17799 +--- linux-2.6.28/drivers/pnp/pnpbios/bioscalls.c 2008-12-24 18:26:37.000000000 -0500
17800 ++++ linux-2.6.28/drivers/pnp/pnpbios/bioscalls.c 2009-01-11 07:20:06.000000000 -0500
17801 +@@ -60,7 +60,7 @@ set_base(gdt[(selname) >> 3], (u32)(addr
17802 + set_limit(gdt[(selname) >> 3], size); \
17803 + } while(0)
17804 +
17805 +-static struct desc_struct bad_bios_desc;
17806 ++static struct desc_struct bad_bios_desc __read_only;
17807 +
17808 + /*
17809 + * At some point we want to use this stack frame pointer to unwind
17810 +@@ -87,6 +87,10 @@ static inline u16 call_pnp_bios(u16 func
17811 + struct desc_struct save_desc_40;
17812 + int cpu;
17813 +
17814 ++#ifdef CONFIG_PAX_KERNEXEC
17815 ++ unsigned long cr0;
17816 ++#endif
17817 ++
17818 + /*
17819 + * PnP BIOSes are generally not terribly re-entrant.
17820 + * Also, don't rely on them to save everything correctly.
17821 +@@ -96,8 +100,17 @@ static inline u16 call_pnp_bios(u16 func
17822 +
17823 + cpu = get_cpu();
17824 + save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
17825 ++
17826 ++#ifdef CONFIG_PAX_KERNEXEC
17827 ++ pax_open_kernel(cr0);
17828 ++#endif
17829 ++
17830 + get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
17831 +
17832 ++#ifdef CONFIG_PAX_KERNEXEC
17833 ++ pax_close_kernel(cr0);
17834 ++#endif
17835 ++
17836 + /* On some boxes IRQ's during PnP BIOS calls are deadly. */
17837 + spin_lock_irqsave(&pnp_bios_lock, flags);
17838 +
17839 +@@ -134,7 +147,16 @@ static inline u16 call_pnp_bios(u16 func
17840 + :"memory");
17841 + spin_unlock_irqrestore(&pnp_bios_lock, flags);
17842 +
17843 ++#ifdef CONFIG_PAX_KERNEXEC
17844 ++ pax_open_kernel(cr0);
17845 ++#endif
17846 ++
17847 + get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
17848 ++
17849 ++#ifdef CONFIG_PAX_KERNEXEC
17850 ++ pax_close_kernel(cr0);
17851 ++#endif
17852 ++
17853 + put_cpu();
17854 +
17855 + /* If we get here and this is set then the PnP BIOS faulted on us. */
17856 +@@ -468,16 +490,24 @@ int pnp_bios_read_escd(char *data, u32 n
17857 + return status;
17858 + }
17859 +
17860 +-void pnpbios_calls_init(union pnp_bios_install_struct *header)
17861 ++void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
17862 + {
17863 + int i;
17864 +
17865 ++#ifdef CONFIG_PAX_KERNEXEC
17866 ++ unsigned long cr0;
17867 ++#endif
17868 ++
17869 + spin_lock_init(&pnp_bios_lock);
17870 + pnp_bios_callpoint.offset = header->fields.pm16offset;
17871 + pnp_bios_callpoint.segment = PNP_CS16;
17872 +
17873 ++#ifdef CONFIG_PAX_KERNEXEC
17874 ++ pax_open_kernel(cr0);
17875 ++#endif
17876 ++
17877 + bad_bios_desc.a = 0;
17878 +- bad_bios_desc.b = 0x00409200;
17879 ++ bad_bios_desc.b = 0x00409300;
17880 +
17881 + set_base(bad_bios_desc, __va((unsigned long)0x40 << 4));
17882 + _set_limit((char *)&bad_bios_desc, 4095 - (0x40 << 4));
17883 +@@ -491,4 +521,9 @@ void pnpbios_calls_init(union pnp_bios_i
17884 + set_base(gdt[GDT_ENTRY_PNPBIOS_DS],
17885 + __va(header->fields.pm16dseg));
17886 + }
17887 ++
17888 ++#ifdef CONFIG_PAX_KERNEXEC
17889 ++ pax_close_kernel(cr0);
17890 ++#endif
17891 ++
17892 + }
17893 +diff -urNp linux-2.6.28/drivers/pnp/quirks.c linux-2.6.28/drivers/pnp/quirks.c
17894 +--- linux-2.6.28/drivers/pnp/quirks.c 2008-12-24 18:26:37.000000000 -0500
17895 ++++ linux-2.6.28/drivers/pnp/quirks.c 2009-01-11 07:20:06.000000000 -0500
17896 +@@ -327,7 +327,7 @@ static struct pnp_fixup pnp_fixups[] = {
17897 + /* PnP resources that might overlap PCI BARs */
17898 + {"PNP0c01", quirk_system_pci_resources},
17899 + {"PNP0c02", quirk_system_pci_resources},
17900 +- {""}
17901 ++ {"", NULL}
17902 + };
17903 +
17904 + void pnp_fixup_device(struct pnp_dev *dev)
17905 +diff -urNp linux-2.6.28/drivers/pnp/resource.c linux-2.6.28/drivers/pnp/resource.c
17906 +--- linux-2.6.28/drivers/pnp/resource.c 2008-12-24 18:26:37.000000000 -0500
17907 ++++ linux-2.6.28/drivers/pnp/resource.c 2009-01-11 07:20:06.000000000 -0500
17908 +@@ -355,7 +355,7 @@ int pnp_check_irq(struct pnp_dev *dev, s
17909 + return 1;
17910 +
17911 + /* check if the resource is valid */
17912 +- if (*irq < 0 || *irq > 15)
17913 ++ if (*irq > 15)
17914 + return 0;
17915 +
17916 + /* check if the resource is reserved */
17917 +@@ -419,7 +419,7 @@ int pnp_check_dma(struct pnp_dev *dev, s
17918 + return 1;
17919 +
17920 + /* check if the resource is valid */
17921 +- if (*dma < 0 || *dma == 4 || *dma > 7)
17922 ++ if (*dma == 4 || *dma > 7)
17923 + return 0;
17924 +
17925 + /* check if the resource is reserved */
17926 +diff -urNp linux-2.6.28/drivers/scsi/scsi_logging.h linux-2.6.28/drivers/scsi/scsi_logging.h
17927 +--- linux-2.6.28/drivers/scsi/scsi_logging.h 2008-12-24 18:26:37.000000000 -0500
17928 ++++ linux-2.6.28/drivers/scsi/scsi_logging.h 2009-01-11 07:20:06.000000000 -0500
17929 +@@ -51,7 +51,7 @@ do { \
17930 + } while (0); \
17931 + } while (0)
17932 + #else
17933 +-#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD)
17934 ++#define SCSI_CHECK_LOGGING(SHIFT, BITS, LEVEL, CMD) do {} while (0)
17935 + #endif /* CONFIG_SCSI_LOGGING */
17936 +
17937 + /*
17938 +diff -urNp linux-2.6.28/drivers/serial/8250_pci.c linux-2.6.28/drivers/serial/8250_pci.c
17939 +--- linux-2.6.28/drivers/serial/8250_pci.c 2008-12-24 18:26:37.000000000 -0500
17940 ++++ linux-2.6.28/drivers/serial/8250_pci.c 2009-01-11 07:20:06.000000000 -0500
17941 +@@ -3090,7 +3090,7 @@ static struct pci_device_id serial_pci_t
17942 + PCI_ANY_ID, PCI_ANY_ID,
17943 + PCI_CLASS_COMMUNICATION_MULTISERIAL << 8,
17944 + 0xffff00, pbn_default },
17945 +- { 0, }
17946 ++ { 0, 0, 0, 0, 0, 0, 0 }
17947 + };
17948 +
17949 + static struct pci_driver serial_pci_driver = {
17950 +diff -urNp linux-2.6.28/drivers/usb/class/cdc-acm.c linux-2.6.28/drivers/usb/class/cdc-acm.c
17951 +--- linux-2.6.28/drivers/usb/class/cdc-acm.c 2008-12-24 18:26:37.000000000 -0500
17952 ++++ linux-2.6.28/drivers/usb/class/cdc-acm.c 2009-01-11 07:20:06.000000000 -0500
17953 +@@ -1386,7 +1386,7 @@ static struct usb_device_id acm_ids[] =
17954 + USB_CDC_ACM_PROTO_AT_CDMA) },
17955 +
17956 + /* NOTE: COMM/ACM/0xff is likely MSFT RNDIS ... NOT a modem!! */
17957 +- { }
17958 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
17959 + };
17960 +
17961 + MODULE_DEVICE_TABLE (usb, acm_ids);
17962 +diff -urNp linux-2.6.28/drivers/usb/class/usblp.c linux-2.6.28/drivers/usb/class/usblp.c
17963 +--- linux-2.6.28/drivers/usb/class/usblp.c 2008-12-24 18:26:37.000000000 -0500
17964 ++++ linux-2.6.28/drivers/usb/class/usblp.c 2009-01-11 07:20:06.000000000 -0500
17965 +@@ -227,7 +227,7 @@ static const struct quirk_printer_struct
17966 + { 0x0409, 0xf1be, USBLP_QUIRK_BIDIR }, /* NEC Picty800 (HP OEM) */
17967 + { 0x0482, 0x0010, USBLP_QUIRK_BIDIR }, /* Kyocera Mita FS 820, by zut <kernel@×××.de> */
17968 + { 0x04b8, 0x0202, USBLP_QUIRK_BAD_CLASS }, /* Seiko Epson Receipt Printer M129C */
17969 +- { 0, 0 }
17970 ++ { 0, 0, 0 }
17971 + };
17972 +
17973 + static int usblp_wwait(struct usblp *usblp, int nonblock);
17974 +@@ -1402,7 +1402,7 @@ static struct usb_device_id usblp_ids []
17975 + { USB_INTERFACE_INFO(7, 1, 2) },
17976 + { USB_INTERFACE_INFO(7, 1, 3) },
17977 + { USB_DEVICE(0x04b8, 0x0202) }, /* Seiko Epson Receipt Printer M129C */
17978 +- { } /* Terminating entry */
17979 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
17980 + };
17981 +
17982 + MODULE_DEVICE_TABLE (usb, usblp_ids);
17983 +diff -urNp linux-2.6.28/drivers/usb/core/hub.c linux-2.6.28/drivers/usb/core/hub.c
17984 +--- linux-2.6.28/drivers/usb/core/hub.c 2008-12-24 18:26:37.000000000 -0500
17985 ++++ linux-2.6.28/drivers/usb/core/hub.c 2009-01-11 07:20:06.000000000 -0500
17986 +@@ -3194,7 +3194,7 @@ static struct usb_device_id hub_id_table
17987 + .bDeviceClass = USB_CLASS_HUB},
17988 + { .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS,
17989 + .bInterfaceClass = USB_CLASS_HUB},
17990 +- { } /* Terminating entry */
17991 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } /* Terminating entry */
17992 + };
17993 +
17994 + MODULE_DEVICE_TABLE (usb, hub_id_table);
17995 +diff -urNp linux-2.6.28/drivers/usb/host/ehci-pci.c linux-2.6.28/drivers/usb/host/ehci-pci.c
17996 +--- linux-2.6.28/drivers/usb/host/ehci-pci.c 2008-12-24 18:26:37.000000000 -0500
17997 ++++ linux-2.6.28/drivers/usb/host/ehci-pci.c 2009-01-11 07:20:06.000000000 -0500
17998 +@@ -414,7 +414,7 @@ static const struct pci_device_id pci_id
17999 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_EHCI, ~0),
18000 + .driver_data = (unsigned long) &ehci_pci_hc_driver,
18001 + },
18002 +- { /* end: all zeroes */ }
18003 ++ { 0, 0, 0, 0, 0, 0, 0 }
18004 + };
18005 + MODULE_DEVICE_TABLE(pci, pci_ids);
18006 +
18007 +diff -urNp linux-2.6.28/drivers/usb/host/uhci-hcd.c linux-2.6.28/drivers/usb/host/uhci-hcd.c
18008 +--- linux-2.6.28/drivers/usb/host/uhci-hcd.c 2008-12-24 18:26:37.000000000 -0500
18009 ++++ linux-2.6.28/drivers/usb/host/uhci-hcd.c 2009-01-11 07:20:06.000000000 -0500
18010 +@@ -927,7 +927,7 @@ static const struct pci_device_id uhci_p
18011 + /* handle any USB UHCI controller */
18012 + PCI_DEVICE_CLASS(PCI_CLASS_SERIAL_USB_UHCI, ~0),
18013 + .driver_data = (unsigned long) &uhci_driver,
18014 +- }, { /* end: all zeroes */ }
18015 ++ }, { 0, 0, 0, 0, 0, 0, 0 }
18016 + };
18017 +
18018 + MODULE_DEVICE_TABLE(pci, uhci_pci_ids);
18019 +diff -urNp linux-2.6.28/drivers/usb/storage/debug.h linux-2.6.28/drivers/usb/storage/debug.h
18020 +--- linux-2.6.28/drivers/usb/storage/debug.h 2008-12-24 18:26:37.000000000 -0500
18021 ++++ linux-2.6.28/drivers/usb/storage/debug.h 2009-01-11 07:20:06.000000000 -0500
18022 +@@ -54,9 +54,9 @@ void usb_stor_show_sense( unsigned char
18023 + #define US_DEBUGPX(x...) printk( x )
18024 + #define US_DEBUG(x) x
18025 + #else
18026 +-#define US_DEBUGP(x...)
18027 +-#define US_DEBUGPX(x...)
18028 +-#define US_DEBUG(x)
18029 ++#define US_DEBUGP(x...) do {} while (0)
18030 ++#define US_DEBUGPX(x...) do {} while (0)
18031 ++#define US_DEBUG(x) do {} while (0)
18032 + #endif
18033 +
18034 + #endif
18035 +diff -urNp linux-2.6.28/drivers/usb/storage/usb.c linux-2.6.28/drivers/usb/storage/usb.c
18036 +--- linux-2.6.28/drivers/usb/storage/usb.c 2008-12-24 18:26:37.000000000 -0500
18037 ++++ linux-2.6.28/drivers/usb/storage/usb.c 2009-01-11 07:20:06.000000000 -0500
18038 +@@ -136,7 +136,7 @@ static struct usb_device_id storage_usb_
18039 + #undef UNUSUAL_DEV
18040 + #undef USUAL_DEV
18041 + /* Terminating entry */
18042 +- { }
18043 ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
18044 + };
18045 +
18046 + MODULE_DEVICE_TABLE (usb, storage_usb_ids);
18047 +@@ -176,7 +176,7 @@ static struct us_unusual_dev us_unusual_
18048 + # undef USUAL_DEV
18049 +
18050 + /* Terminating entry */
18051 +- { NULL }
18052 ++ { NULL, NULL, 0, 0, NULL }
18053 + };
18054 +
18055 +
18056 +diff -urNp linux-2.6.28/drivers/uwb/wlp/messages.c linux-2.6.28/drivers/uwb/wlp/messages.c
18057 +--- linux-2.6.28/drivers/uwb/wlp/messages.c 2008-12-24 18:26:37.000000000 -0500
18058 ++++ linux-2.6.28/drivers/uwb/wlp/messages.c 2009-01-11 07:20:06.000000000 -0500
18059 +@@ -988,7 +988,7 @@ int wlp_parse_f0(struct wlp *wlp, struct
18060 + size_t len = skb->len;
18061 + size_t used;
18062 + ssize_t result;
18063 +- struct wlp_nonce enonce, rnonce;
18064 ++ struct wlp_nonce enonce = {{0}}, rnonce = {{0}};
18065 + enum wlp_assc_error assc_err;
18066 + char enonce_buf[WLP_WSS_NONCE_STRSIZE];
18067 + char rnonce_buf[WLP_WSS_NONCE_STRSIZE];
18068 +diff -urNp linux-2.6.28/drivers/video/fbcmap.c linux-2.6.28/drivers/video/fbcmap.c
18069 +--- linux-2.6.28/drivers/video/fbcmap.c 2008-12-24 18:26:37.000000000 -0500
18070 ++++ linux-2.6.28/drivers/video/fbcmap.c 2009-01-11 07:20:06.000000000 -0500
18071 +@@ -250,8 +250,7 @@ int fb_set_user_cmap(struct fb_cmap_user
18072 + int rc, size = cmap->len * sizeof(u16);
18073 + struct fb_cmap umap;
18074 +
18075 +- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
18076 +- !info->fbops->fb_setcmap))
18077 ++ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap)
18078 + return -EINVAL;
18079 +
18080 + memset(&umap, 0, sizeof(struct fb_cmap));
18081 +diff -urNp linux-2.6.28/drivers/video/fbmem.c linux-2.6.28/drivers/video/fbmem.c
18082 +--- linux-2.6.28/drivers/video/fbmem.c 2008-12-24 18:26:37.000000000 -0500
18083 ++++ linux-2.6.28/drivers/video/fbmem.c 2009-01-11 07:20:06.000000000 -0500
18084 +@@ -393,7 +393,7 @@ static void fb_do_show_logo(struct fb_in
18085 + image->dx += image->width + 8;
18086 + }
18087 + } else if (rotate == FB_ROTATE_UD) {
18088 +- for (x = 0; x < num && image->dx >= 0; x++) {
18089 ++ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
18090 + info->fbops->fb_imageblit(info, image);
18091 + image->dx -= image->width + 8;
18092 + }
18093 +@@ -405,7 +405,7 @@ static void fb_do_show_logo(struct fb_in
18094 + image->dy += image->height + 8;
18095 + }
18096 + } else if (rotate == FB_ROTATE_CCW) {
18097 +- for (x = 0; x < num && image->dy >= 0; x++) {
18098 ++ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
18099 + info->fbops->fb_imageblit(info, image);
18100 + image->dy -= image->height + 8;
18101 + }
18102 +@@ -1090,7 +1090,7 @@ static long do_fb_ioctl(struct fb_info *
18103 + ret = -EINVAL;
18104 + break;
18105 + }
18106 +- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) {
18107 ++ if (con2fb.framebuffer >= FB_MAX) {
18108 + ret = -EINVAL;
18109 + break;
18110 + }
18111 +diff -urNp linux-2.6.28/drivers/video/fbmon.c linux-2.6.28/drivers/video/fbmon.c
18112 +--- linux-2.6.28/drivers/video/fbmon.c 2008-12-24 18:26:37.000000000 -0500
18113 ++++ linux-2.6.28/drivers/video/fbmon.c 2009-01-11 07:20:06.000000000 -0500
18114 +@@ -45,7 +45,7 @@
18115 + #ifdef DEBUG
18116 + #define DPRINTK(fmt, args...) printk(fmt,## args)
18117 + #else
18118 +-#define DPRINTK(fmt, args...)
18119 ++#define DPRINTK(fmt, args...) do {} while (0)
18120 + #endif
18121 +
18122 + #define FBMON_FIX_HEADER 1
18123 +diff -urNp linux-2.6.28/drivers/video/i810/i810_accel.c linux-2.6.28/drivers/video/i810/i810_accel.c
18124 +--- linux-2.6.28/drivers/video/i810/i810_accel.c 2008-12-24 18:26:37.000000000 -0500
18125 ++++ linux-2.6.28/drivers/video/i810/i810_accel.c 2009-01-11 07:20:06.000000000 -0500
18126 +@@ -73,6 +73,7 @@ static inline int wait_for_space(struct
18127 + }
18128 + }
18129 + printk("ringbuffer lockup!!!\n");
18130 ++ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
18131 + i810_report_error(mmio);
18132 + par->dev_flags |= LOCKUP;
18133 + info->pixmap.scan_align = 1;
18134 +diff -urNp linux-2.6.28/drivers/video/i810/i810_main.c linux-2.6.28/drivers/video/i810/i810_main.c
18135 +--- linux-2.6.28/drivers/video/i810/i810_main.c 2008-12-24 18:26:37.000000000 -0500
18136 ++++ linux-2.6.28/drivers/video/i810/i810_main.c 2009-01-11 07:20:06.000000000 -0500
18137 +@@ -120,7 +120,7 @@ static struct pci_device_id i810fb_pci_t
18138 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4 },
18139 + { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC,
18140 + PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5 },
18141 +- { 0 },
18142 ++ { 0, 0, 0, 0, 0, 0, 0 },
18143 + };
18144 +
18145 + static struct pci_driver i810fb_driver = {
18146 +@@ -1509,7 +1509,7 @@ static int i810fb_cursor(struct fb_info
18147 + int size = ((cursor->image.width + 7) >> 3) *
18148 + cursor->image.height;
18149 + int i;
18150 +- u8 *data = kmalloc(64 * 8, GFP_ATOMIC);
18151 ++ u8 *data = kmalloc(64 * 8, GFP_KERNEL);
18152 +
18153 + if (data == NULL)
18154 + return -ENOMEM;
18155 +diff -urNp linux-2.6.28/drivers/video/modedb.c linux-2.6.28/drivers/video/modedb.c
18156 +--- linux-2.6.28/drivers/video/modedb.c 2008-12-24 18:26:37.000000000 -0500
18157 ++++ linux-2.6.28/drivers/video/modedb.c 2009-01-11 07:20:06.000000000 -0500
18158 +@@ -38,232 +38,232 @@ static const struct fb_videomode modedb[
18159 + {
18160 + /* 640x400 @ 70 Hz, 31.5 kHz hsync */
18161 + NULL, 70, 640, 400, 39721, 40, 24, 39, 9, 96, 2,
18162 +- 0, FB_VMODE_NONINTERLACED
18163 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18164 + }, {
18165 + /* 640x480 @ 60 Hz, 31.5 kHz hsync */
18166 + NULL, 60, 640, 480, 39721, 40, 24, 32, 11, 96, 2,
18167 +- 0, FB_VMODE_NONINTERLACED
18168 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18169 + }, {
18170 + /* 800x600 @ 56 Hz, 35.15 kHz hsync */
18171 + NULL, 56, 800, 600, 27777, 128, 24, 22, 1, 72, 2,
18172 +- 0, FB_VMODE_NONINTERLACED
18173 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18174 + }, {
18175 + /* 1024x768 @ 87 Hz interlaced, 35.5 kHz hsync */
18176 + NULL, 87, 1024, 768, 22271, 56, 24, 33, 8, 160, 8,
18177 +- 0, FB_VMODE_INTERLACED
18178 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
18179 + }, {
18180 + /* 640x400 @ 85 Hz, 37.86 kHz hsync */
18181 + NULL, 85, 640, 400, 31746, 96, 32, 41, 1, 64, 3,
18182 +- FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18183 ++ FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18184 + }, {
18185 + /* 640x480 @ 72 Hz, 36.5 kHz hsync */
18186 + NULL, 72, 640, 480, 31746, 144, 40, 30, 8, 40, 3,
18187 +- 0, FB_VMODE_NONINTERLACED
18188 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18189 + }, {
18190 + /* 640x480 @ 75 Hz, 37.50 kHz hsync */
18191 + NULL, 75, 640, 480, 31746, 120, 16, 16, 1, 64, 3,
18192 +- 0, FB_VMODE_NONINTERLACED
18193 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18194 + }, {
18195 + /* 800x600 @ 60 Hz, 37.8 kHz hsync */
18196 + NULL, 60, 800, 600, 25000, 88, 40, 23, 1, 128, 4,
18197 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18198 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18199 + }, {
18200 + /* 640x480 @ 85 Hz, 43.27 kHz hsync */
18201 + NULL, 85, 640, 480, 27777, 80, 56, 25, 1, 56, 3,
18202 +- 0, FB_VMODE_NONINTERLACED
18203 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18204 + }, {
18205 + /* 1152x864 @ 89 Hz interlaced, 44 kHz hsync */
18206 + NULL, 89, 1152, 864, 15384, 96, 16, 110, 1, 216, 10,
18207 +- 0, FB_VMODE_INTERLACED
18208 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
18209 + }, {
18210 + /* 800x600 @ 72 Hz, 48.0 kHz hsync */
18211 + NULL, 72, 800, 600, 20000, 64, 56, 23, 37, 120, 6,
18212 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18213 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18214 + }, {
18215 + /* 1024x768 @ 60 Hz, 48.4 kHz hsync */
18216 + NULL, 60, 1024, 768, 15384, 168, 8, 29, 3, 144, 6,
18217 +- 0, FB_VMODE_NONINTERLACED
18218 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18219 + }, {
18220 + /* 640x480 @ 100 Hz, 53.01 kHz hsync */
18221 + NULL, 100, 640, 480, 21834, 96, 32, 36, 8, 96, 6,
18222 +- 0, FB_VMODE_NONINTERLACED
18223 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18224 + }, {
18225 + /* 1152x864 @ 60 Hz, 53.5 kHz hsync */
18226 + NULL, 60, 1152, 864, 11123, 208, 64, 16, 4, 256, 8,
18227 +- 0, FB_VMODE_NONINTERLACED
18228 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18229 + }, {
18230 + /* 800x600 @ 85 Hz, 55.84 kHz hsync */
18231 + NULL, 85, 800, 600, 16460, 160, 64, 36, 16, 64, 5,
18232 +- 0, FB_VMODE_NONINTERLACED
18233 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18234 + }, {
18235 + /* 1024x768 @ 70 Hz, 56.5 kHz hsync */
18236 + NULL, 70, 1024, 768, 13333, 144, 24, 29, 3, 136, 6,
18237 +- 0, FB_VMODE_NONINTERLACED
18238 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18239 + }, {
18240 + /* 1280x1024 @ 87 Hz interlaced, 51 kHz hsync */
18241 + NULL, 87, 1280, 1024, 12500, 56, 16, 128, 1, 216, 12,
18242 +- 0, FB_VMODE_INTERLACED
18243 ++ 0, FB_VMODE_INTERLACED, FB_MODE_IS_UNKNOWN
18244 + }, {
18245 + /* 800x600 @ 100 Hz, 64.02 kHz hsync */
18246 + NULL, 100, 800, 600, 14357, 160, 64, 30, 4, 64, 6,
18247 +- 0, FB_VMODE_NONINTERLACED
18248 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18249 + }, {
18250 + /* 1024x768 @ 76 Hz, 62.5 kHz hsync */
18251 + NULL, 76, 1024, 768, 11764, 208, 8, 36, 16, 120, 3,
18252 +- 0, FB_VMODE_NONINTERLACED
18253 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18254 + }, {
18255 + /* 1152x864 @ 70 Hz, 62.4 kHz hsync */
18256 + NULL, 70, 1152, 864, 10869, 106, 56, 20, 1, 160, 10,
18257 +- 0, FB_VMODE_NONINTERLACED
18258 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18259 + }, {
18260 + /* 1280x1024 @ 61 Hz, 64.2 kHz hsync */
18261 + NULL, 61, 1280, 1024, 9090, 200, 48, 26, 1, 184, 3,
18262 +- 0, FB_VMODE_NONINTERLACED
18263 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18264 + }, {
18265 + /* 1400x1050 @ 60Hz, 63.9 kHz hsync */
18266 + NULL, 60, 1400, 1050, 9259, 136, 40, 13, 1, 112, 3,
18267 +- 0, FB_VMODE_NONINTERLACED
18268 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18269 + }, {
18270 + /* 1400x1050 @ 75,107 Hz, 82,392 kHz +hsync +vsync*/
18271 + NULL, 75, 1400, 1050, 7190, 120, 56, 23, 10, 112, 13,
18272 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18273 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18274 + }, {
18275 + /* 1400x1050 @ 60 Hz, ? kHz +hsync +vsync*/
18276 + NULL, 60, 1400, 1050, 9259, 128, 40, 12, 0, 112, 3,
18277 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18278 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18279 + }, {
18280 + /* 1024x768 @ 85 Hz, 70.24 kHz hsync */
18281 + NULL, 85, 1024, 768, 10111, 192, 32, 34, 14, 160, 6,
18282 +- 0, FB_VMODE_NONINTERLACED
18283 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18284 + }, {
18285 + /* 1152x864 @ 78 Hz, 70.8 kHz hsync */
18286 + NULL, 78, 1152, 864, 9090, 228, 88, 32, 0, 84, 12,
18287 +- 0, FB_VMODE_NONINTERLACED
18288 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18289 + }, {
18290 + /* 1280x1024 @ 70 Hz, 74.59 kHz hsync */
18291 + NULL, 70, 1280, 1024, 7905, 224, 32, 28, 8, 160, 8,
18292 +- 0, FB_VMODE_NONINTERLACED
18293 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18294 + }, {
18295 + /* 1600x1200 @ 60Hz, 75.00 kHz hsync */
18296 + NULL, 60, 1600, 1200, 6172, 304, 64, 46, 1, 192, 3,
18297 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18298 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18299 + }, {
18300 + /* 1152x864 @ 84 Hz, 76.0 kHz hsync */
18301 + NULL, 84, 1152, 864, 7407, 184, 312, 32, 0, 128, 12,
18302 +- 0, FB_VMODE_NONINTERLACED
18303 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18304 + }, {
18305 + /* 1280x1024 @ 74 Hz, 78.85 kHz hsync */
18306 + NULL, 74, 1280, 1024, 7407, 256, 32, 34, 3, 144, 3,
18307 +- 0, FB_VMODE_NONINTERLACED
18308 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18309 + }, {
18310 + /* 1024x768 @ 100Hz, 80.21 kHz hsync */
18311 + NULL, 100, 1024, 768, 8658, 192, 32, 21, 3, 192, 10,
18312 +- 0, FB_VMODE_NONINTERLACED
18313 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18314 + }, {
18315 + /* 1280x1024 @ 76 Hz, 81.13 kHz hsync */
18316 + NULL, 76, 1280, 1024, 7407, 248, 32, 34, 3, 104, 3,
18317 +- 0, FB_VMODE_NONINTERLACED
18318 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18319 + }, {
18320 + /* 1600x1200 @ 70 Hz, 87.50 kHz hsync */
18321 + NULL, 70, 1600, 1200, 5291, 304, 64, 46, 1, 192, 3,
18322 +- 0, FB_VMODE_NONINTERLACED
18323 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18324 + }, {
18325 + /* 1152x864 @ 100 Hz, 89.62 kHz hsync */
18326 + NULL, 100, 1152, 864, 7264, 224, 32, 17, 2, 128, 19,
18327 +- 0, FB_VMODE_NONINTERLACED
18328 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18329 + }, {
18330 + /* 1280x1024 @ 85 Hz, 91.15 kHz hsync */
18331 + NULL, 85, 1280, 1024, 6349, 224, 64, 44, 1, 160, 3,
18332 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18333 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18334 + }, {
18335 + /* 1600x1200 @ 75 Hz, 93.75 kHz hsync */
18336 + NULL, 75, 1600, 1200, 4938, 304, 64, 46, 1, 192, 3,
18337 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18338 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18339 + }, {
18340 + /* 1680x1050 @ 60 Hz, 65.191 kHz hsync */
18341 + NULL, 60, 1680, 1050, 6848, 280, 104, 30, 3, 176, 6,
18342 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18343 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18344 + }, {
18345 + /* 1600x1200 @ 85 Hz, 105.77 kHz hsync */
18346 + NULL, 85, 1600, 1200, 4545, 272, 16, 37, 4, 192, 3,
18347 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18348 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18349 + }, {
18350 + /* 1280x1024 @ 100 Hz, 107.16 kHz hsync */
18351 + NULL, 100, 1280, 1024, 5502, 256, 32, 26, 7, 128, 15,
18352 +- 0, FB_VMODE_NONINTERLACED
18353 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18354 + }, {
18355 + /* 1800x1440 @ 64Hz, 96.15 kHz hsync */
18356 + NULL, 64, 1800, 1440, 4347, 304, 96, 46, 1, 192, 3,
18357 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18358 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18359 + }, {
18360 + /* 1800x1440 @ 70Hz, 104.52 kHz hsync */
18361 + NULL, 70, 1800, 1440, 4000, 304, 96, 46, 1, 192, 3,
18362 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18363 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18364 + }, {
18365 + /* 512x384 @ 78 Hz, 31.50 kHz hsync */
18366 + NULL, 78, 512, 384, 49603, 48, 16, 16, 1, 64, 3,
18367 +- 0, FB_VMODE_NONINTERLACED
18368 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18369 + }, {
18370 + /* 512x384 @ 85 Hz, 34.38 kHz hsync */
18371 + NULL, 85, 512, 384, 45454, 48, 16, 16, 1, 64, 3,
18372 +- 0, FB_VMODE_NONINTERLACED
18373 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18374 + }, {
18375 + /* 320x200 @ 70 Hz, 31.5 kHz hsync, 8:5 aspect ratio */
18376 + NULL, 70, 320, 200, 79440, 16, 16, 20, 4, 48, 1,
18377 +- 0, FB_VMODE_DOUBLE
18378 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18379 + }, {
18380 + /* 320x240 @ 60 Hz, 31.5 kHz hsync, 4:3 aspect ratio */
18381 + NULL, 60, 320, 240, 79440, 16, 16, 16, 5, 48, 1,
18382 +- 0, FB_VMODE_DOUBLE
18383 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18384 + }, {
18385 + /* 320x240 @ 72 Hz, 36.5 kHz hsync */
18386 + NULL, 72, 320, 240, 63492, 16, 16, 16, 4, 48, 2,
18387 +- 0, FB_VMODE_DOUBLE
18388 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18389 + }, {
18390 + /* 400x300 @ 56 Hz, 35.2 kHz hsync, 4:3 aspect ratio */
18391 + NULL, 56, 400, 300, 55555, 64, 16, 10, 1, 32, 1,
18392 +- 0, FB_VMODE_DOUBLE
18393 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18394 + }, {
18395 + /* 400x300 @ 60 Hz, 37.8 kHz hsync */
18396 + NULL, 60, 400, 300, 50000, 48, 16, 11, 1, 64, 2,
18397 +- 0, FB_VMODE_DOUBLE
18398 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18399 + }, {
18400 + /* 400x300 @ 72 Hz, 48.0 kHz hsync */
18401 + NULL, 72, 400, 300, 40000, 32, 24, 11, 19, 64, 3,
18402 +- 0, FB_VMODE_DOUBLE
18403 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18404 + }, {
18405 + /* 480x300 @ 56 Hz, 35.2 kHz hsync, 8:5 aspect ratio */
18406 + NULL, 56, 480, 300, 46176, 80, 16, 10, 1, 40, 1,
18407 +- 0, FB_VMODE_DOUBLE
18408 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18409 + }, {
18410 + /* 480x300 @ 60 Hz, 37.8 kHz hsync */
18411 + NULL, 60, 480, 300, 41858, 56, 16, 11, 1, 80, 2,
18412 +- 0, FB_VMODE_DOUBLE
18413 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18414 + }, {
18415 + /* 480x300 @ 63 Hz, 39.6 kHz hsync */
18416 + NULL, 63, 480, 300, 40000, 56, 16, 11, 1, 80, 2,
18417 +- 0, FB_VMODE_DOUBLE
18418 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18419 + }, {
18420 + /* 480x300 @ 72 Hz, 48.0 kHz hsync */
18421 + NULL, 72, 480, 300, 33386, 40, 24, 11, 19, 80, 3,
18422 +- 0, FB_VMODE_DOUBLE
18423 ++ 0, FB_VMODE_DOUBLE, FB_MODE_IS_UNKNOWN
18424 + }, {
18425 + /* 1920x1200 @ 60 Hz, 74.5 Khz hsync */
18426 + NULL, 60, 1920, 1200, 5177, 128, 336, 1, 38, 208, 3,
18427 + FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
18428 +- FB_VMODE_NONINTERLACED
18429 ++ FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18430 + }, {
18431 + /* 1152x768, 60 Hz, PowerBook G4 Titanium I and II */
18432 + NULL, 60, 1152, 768, 14047, 158, 26, 29, 3, 136, 6,
18433 +- FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED
18434 ++ FB_SYNC_HOR_HIGH_ACT|FB_SYNC_VERT_HIGH_ACT, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18435 + }, {
18436 + /* 1366x768, 60 Hz, 47.403 kHz hsync, WXGA 16:9 aspect ratio */
18437 + NULL, 60, 1366, 768, 13806, 120, 10, 14, 3, 32, 5,
18438 +- 0, FB_VMODE_NONINTERLACED
18439 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18440 + }, {
18441 + /* 1280x800, 60 Hz, 47.403 kHz hsync, WXGA 16:10 aspect ratio */
18442 + NULL, 60, 1280, 800, 12048, 200, 64, 24, 1, 136, 3,
18443 +- 0, FB_VMODE_NONINTERLACED
18444 ++ 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_UNKNOWN
18445 + },
18446 + };
18447 +
18448 +diff -urNp linux-2.6.28/drivers/video/uvesafb.c linux-2.6.28/drivers/video/uvesafb.c
18449 +--- linux-2.6.28/drivers/video/uvesafb.c 2008-12-24 18:26:37.000000000 -0500
18450 ++++ linux-2.6.28/drivers/video/uvesafb.c 2009-01-11 07:20:06.000000000 -0500
18451 +@@ -18,6 +18,7 @@
18452 + #include <linux/fb.h>
18453 + #include <linux/io.h>
18454 + #include <linux/mutex.h>
18455 ++#include <linux/moduleloader.h>
18456 + #include <video/edid.h>
18457 + #include <video/uvesafb.h>
18458 + #ifdef CONFIG_X86
18459 +@@ -117,7 +118,7 @@ static int uvesafb_helper_start(void)
18460 + NULL,
18461 + };
18462 +
18463 +- return call_usermodehelper(v86d_path, argv, envp, 1);
18464 ++ return call_usermodehelper(v86d_path, argv, envp, UMH_WAIT_PROC);
18465 + }
18466 +
18467 + /*
18468 +@@ -574,10 +575,34 @@ static int __devinit uvesafb_vbe_getpmi(
18469 + if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
18470 + par->pmi_setpal = par->ypan = 0;
18471 + } else {
18472 ++
18473 ++#ifdef CONFIG_PAX_KERNEXEC
18474 ++#ifdef CONFIG_MODULES
18475 ++ unsigned long cr0;
18476 ++
18477 ++ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
18478 ++#endif
18479 ++ if (!par->pmi_code) {
18480 ++ par->pmi_setpal = par->ypan = 0;
18481 ++ return 0;
18482 ++ }
18483 ++#endif
18484 ++
18485 + par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
18486 + + task->t.regs.edi);
18487 ++
18488 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18489 ++ pax_open_kernel(cr0);
18490 ++ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
18491 ++ pax_close_kernel(cr0);
18492 ++
18493 ++ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
18494 ++ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
18495 ++#else
18496 + par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
18497 + par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
18498 ++#endif
18499 ++
18500 + printk(KERN_INFO "uvesafb: protected mode interface info at "
18501 + "%04x:%04x\n",
18502 + (u16)task->t.regs.es, (u16)task->t.regs.edi);
18503 +@@ -1832,6 +1857,11 @@ out:
18504 + if (par->vbe_modes)
18505 + kfree(par->vbe_modes);
18506 +
18507 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18508 ++ if (par->pmi_code)
18509 ++ module_free_exec(NULL, par->pmi_code);
18510 ++#endif
18511 ++
18512 + framebuffer_release(info);
18513 + return err;
18514 + }
18515 +@@ -1858,6 +1888,12 @@ static int uvesafb_remove(struct platfor
18516 + kfree(par->vbe_state_orig);
18517 + if (par->vbe_state_saved)
18518 + kfree(par->vbe_state_saved);
18519 ++
18520 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18521 ++ if (par->pmi_code)
18522 ++ module_free_exec(NULL, par->pmi_code);
18523 ++#endif
18524 ++
18525 + }
18526 +
18527 + framebuffer_release(info);
18528 +diff -urNp linux-2.6.28/drivers/video/vesafb.c linux-2.6.28/drivers/video/vesafb.c
18529 +--- linux-2.6.28/drivers/video/vesafb.c 2008-12-24 18:26:37.000000000 -0500
18530 ++++ linux-2.6.28/drivers/video/vesafb.c 2009-01-11 07:20:06.000000000 -0500
18531 +@@ -9,6 +9,7 @@
18532 + */
18533 +
18534 + #include <linux/module.h>
18535 ++#include <linux/moduleloader.h>
18536 + #include <linux/kernel.h>
18537 + #include <linux/errno.h>
18538 + #include <linux/string.h>
18539 +@@ -53,8 +54,8 @@ static int vram_remap __initdata; /*
18540 + static int vram_total __initdata; /* Set total amount of memory */
18541 + static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
18542 + static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
18543 +-static void (*pmi_start)(void) __read_mostly;
18544 +-static void (*pmi_pal) (void) __read_mostly;
18545 ++static void (*pmi_start)(void) __read_only;
18546 ++static void (*pmi_pal) (void) __read_only;
18547 + static int depth __read_mostly;
18548 + static int vga_compat __read_mostly;
18549 + /* --------------------------------------------------------------------- */
18550 +@@ -224,6 +225,7 @@ static int __init vesafb_probe(struct pl
18551 + unsigned int size_vmode;
18552 + unsigned int size_remap;
18553 + unsigned int size_total;
18554 ++ void *pmi_code = NULL;
18555 +
18556 + if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
18557 + return -ENODEV;
18558 +@@ -266,10 +268,6 @@ static int __init vesafb_probe(struct pl
18559 + size_remap = size_total;
18560 + vesafb_fix.smem_len = size_remap;
18561 +
18562 +-#ifndef __i386__
18563 +- screen_info.vesapm_seg = 0;
18564 +-#endif
18565 +-
18566 + if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
18567 + printk(KERN_WARNING
18568 + "vesafb: cannot reserve video memory at 0x%lx\n",
18569 +@@ -302,9 +300,21 @@ static int __init vesafb_probe(struct pl
18570 + printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
18571 + vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
18572 +
18573 ++#ifdef __i386__
18574 ++
18575 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18576 ++ pmi_code = module_alloc_exec(screen_info.vesapm_size);
18577 ++ if (!pmi_code)
18578 ++#elif !defined(CONFIG_PAX_KERNEXEC)
18579 ++ if (0)
18580 ++#endif
18581 ++
18582 ++#endif
18583 ++ screen_info.vesapm_seg = 0;
18584 ++
18585 + if (screen_info.vesapm_seg) {
18586 +- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
18587 +- screen_info.vesapm_seg,screen_info.vesapm_off);
18588 ++ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
18589 ++ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
18590 + }
18591 +
18592 + if (screen_info.vesapm_seg < 0xc000)
18593 +@@ -312,9 +322,29 @@ static int __init vesafb_probe(struct pl
18594 +
18595 + if (ypan || pmi_setpal) {
18596 + unsigned short *pmi_base;
18597 +- pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
18598 +- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
18599 +- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
18600 ++
18601 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18602 ++ unsigned long cr0;
18603 ++#endif
18604 ++
18605 ++ pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
18606 ++
18607 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18608 ++ pax_open_kernel(cr0);
18609 ++ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
18610 ++#else
18611 ++ pmi_code = pmi_base;
18612 ++#endif
18613 ++
18614 ++ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
18615 ++ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
18616 ++
18617 ++#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18618 ++ pmi_start = ktva_ktla(pmi_start);
18619 ++ pmi_pal = ktva_ktla(pmi_pal);
18620 ++ pax_close_kernel(cr0);
18621 ++#endif
18622 ++
18623 + printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
18624 + if (pmi_base[3]) {
18625 + printk(KERN_INFO "vesafb: pmi: ports = ");
18626 +@@ -456,6 +486,11 @@ static int __init vesafb_probe(struct pl
18627 + info->node, info->fix.id);
18628 + return 0;
18629 + err:
18630 ++
18631 ++#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
18632 ++ module_free_exec(NULL, pmi_code);
18633 ++#endif
18634 ++
18635 + if (info->screen_base)
18636 + iounmap(info->screen_base);
18637 + framebuffer_release(info);
18638 +diff -urNp linux-2.6.28/fs/9p/vfs_inode.c linux-2.6.28/fs/9p/vfs_inode.c
18639 +--- linux-2.6.28/fs/9p/vfs_inode.c 2008-12-24 18:26:37.000000000 -0500
18640 ++++ linux-2.6.28/fs/9p/vfs_inode.c 2009-01-11 07:20:06.000000000 -0500
18641 +@@ -1021,7 +1021,7 @@ static void *v9fs_vfs_follow_link(struct
18642 + static void
18643 + v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
18644 + {
18645 +- char *s = nd_get_link(nd);
18646 ++ const char *s = nd_get_link(nd);
18647 +
18648 + P9_DPRINTK(P9_DEBUG_VFS, " %s %s\n", dentry->d_name.name,
18649 + IS_ERR(s) ? "<error>" : s);
18650 +diff -urNp linux-2.6.28/fs/aio.c linux-2.6.28/fs/aio.c
18651 +--- linux-2.6.28/fs/aio.c 2008-12-24 18:26:37.000000000 -0500
18652 ++++ linux-2.6.28/fs/aio.c 2009-01-11 07:20:06.000000000 -0500
18653 +@@ -114,7 +114,7 @@ static int aio_setup_ring(struct kioctx
18654 + size += sizeof(struct io_event) * nr_events;
18655 + nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
18656 +
18657 +- if (nr_pages < 0)
18658 ++ if (nr_pages <= 0)
18659 + return -EINVAL;
18660 +
18661 + nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
18662 +diff -urNp linux-2.6.28/fs/autofs4/symlink.c linux-2.6.28/fs/autofs4/symlink.c
18663 +--- linux-2.6.28/fs/autofs4/symlink.c 2008-12-24 18:26:37.000000000 -0500
18664 ++++ linux-2.6.28/fs/autofs4/symlink.c 2009-01-11 07:20:06.000000000 -0500
18665 +@@ -15,7 +15,7 @@
18666 + static void *autofs4_follow_link(struct dentry *dentry, struct nameidata *nd)
18667 + {
18668 + struct autofs_info *ino = autofs4_dentry_ino(dentry);
18669 +- nd_set_link(nd, (char *)ino->u.symlink);
18670 ++ nd_set_link(nd, ino->u.symlink);
18671 + return NULL;
18672 + }
18673 +
18674 +diff -urNp linux-2.6.28/fs/befs/linuxvfs.c linux-2.6.28/fs/befs/linuxvfs.c
18675 +--- linux-2.6.28/fs/befs/linuxvfs.c 2008-12-24 18:26:37.000000000 -0500
18676 ++++ linux-2.6.28/fs/befs/linuxvfs.c 2009-01-11 07:20:06.000000000 -0500
18677 +@@ -490,7 +490,7 @@ static void befs_put_link(struct dentry
18678 + {
18679 + befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
18680 + if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
18681 +- char *link = nd_get_link(nd);
18682 ++ const char *link = nd_get_link(nd);
18683 + if (!IS_ERR(link))
18684 + kfree(link);
18685 + }
18686 +diff -urNp linux-2.6.28/fs/binfmt_aout.c linux-2.6.28/fs/binfmt_aout.c
18687 +--- linux-2.6.28/fs/binfmt_aout.c 2008-12-24 18:26:37.000000000 -0500
18688 ++++ linux-2.6.28/fs/binfmt_aout.c 2009-01-11 07:20:06.000000000 -0500
18689 +@@ -24,6 +24,7 @@
18690 + #include <linux/binfmts.h>
18691 + #include <linux/personality.h>
18692 + #include <linux/init.h>
18693 ++#include <linux/grsecurity.h>
18694 +
18695 + #include <asm/system.h>
18696 + #include <asm/uaccess.h>
18697 +@@ -124,18 +125,22 @@ static int aout_core_dump(long signr, st
18698 + /* If the size of the dump file exceeds the rlimit, then see what would happen
18699 + if we wrote the stack, but not the data area. */
18700 + #ifdef __sparc__
18701 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_dsize + dump.u_ssize, 1);
18702 + if ((dump.u_dsize + dump.u_ssize) > limit)
18703 + dump.u_dsize = 0;
18704 + #else
18705 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
18706 + if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > limit)
18707 + dump.u_dsize = 0;
18708 + #endif
18709 +
18710 + /* Make sure we have enough room to write the stack and data areas. */
18711 + #ifdef __sparc__
18712 ++ gr_learn_resource(current, RLIMIT_CORE, dump.u_ssize, 1);
18713 + if (dump.u_ssize > limit)
18714 + dump.u_ssize = 0;
18715 + #else
18716 ++ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
18717 + if ((dump.u_ssize + 1) * PAGE_SIZE > limit)
18718 + dump.u_ssize = 0;
18719 + #endif
18720 +@@ -291,6 +296,8 @@ static int load_aout_binary(struct linux
18721 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
18722 + if (rlim >= RLIM_INFINITY)
18723 + rlim = ~0;
18724 ++
18725 ++ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
18726 + if (ex.a_data + ex.a_bss > rlim)
18727 + return -ENOMEM;
18728 +
18729 +@@ -322,6 +329,28 @@ static int load_aout_binary(struct linux
18730 +
18731 + compute_creds(bprm);
18732 + current->flags &= ~PF_FORKNOEXEC;
18733 ++
18734 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
18735 ++ current->mm->pax_flags = 0UL;
18736 ++#endif
18737 ++
18738 ++#ifdef CONFIG_PAX_PAGEEXEC
18739 ++ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
18740 ++ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
18741 ++
18742 ++#ifdef CONFIG_PAX_EMUTRAMP
18743 ++ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
18744 ++ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
18745 ++#endif
18746 ++
18747 ++#ifdef CONFIG_PAX_MPROTECT
18748 ++ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
18749 ++ current->mm->pax_flags |= MF_PAX_MPROTECT;
18750 ++#endif
18751 ++
18752 ++ }
18753 ++#endif
18754 ++
18755 + #ifdef __sparc__
18756 + if (N_MAGIC(ex) == NMAGIC) {
18757 + loff_t pos = fd_offset;
18758 +@@ -413,7 +442,7 @@ static int load_aout_binary(struct linux
18759 +
18760 + down_write(&current->mm->mmap_sem);
18761 + error = do_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
18762 +- PROT_READ | PROT_WRITE | PROT_EXEC,
18763 ++ PROT_READ | PROT_WRITE,
18764 + MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
18765 + fd_offset + ex.a_text);
18766 + up_write(&current->mm->mmap_sem);
18767 +diff -urNp linux-2.6.28/fs/binfmt_elf.c linux-2.6.28/fs/binfmt_elf.c
18768 +--- linux-2.6.28/fs/binfmt_elf.c 2008-12-24 18:26:37.000000000 -0500
18769 ++++ linux-2.6.28/fs/binfmt_elf.c 2009-01-11 07:21:39.000000000 -0500
18770 +@@ -38,10 +38,16 @@
18771 + #include <linux/random.h>
18772 + #include <linux/elf.h>
18773 + #include <linux/utsname.h>
18774 ++#include <linux/grsecurity.h>
18775 ++
18776 + #include <asm/uaccess.h>
18777 + #include <asm/param.h>
18778 + #include <asm/page.h>
18779 +
18780 ++#ifdef CONFIG_PAX_SEGMEXEC
18781 ++#include <asm/desc.h>
18782 ++#endif
18783 ++
18784 + static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs);
18785 + static int load_elf_library(struct file *);
18786 + static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
18787 +@@ -57,6 +63,10 @@ static int elf_core_dump(long signr, str
18788 + #define elf_core_dump NULL
18789 + #endif
18790 +
18791 ++#ifdef CONFIG_PAX_MPROTECT
18792 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
18793 ++#endif
18794 ++
18795 + #if ELF_EXEC_PAGESIZE > PAGE_SIZE
18796 + #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
18797 + #else
18798 +@@ -76,6 +86,11 @@ static struct linux_binfmt elf_format =
18799 + .load_binary = load_elf_binary,
18800 + .load_shlib = load_elf_library,
18801 + .core_dump = elf_core_dump,
18802 ++
18803 ++#ifdef CONFIG_PAX_MPROTECT
18804 ++ .handle_mprotect= elf_handle_mprotect,
18805 ++#endif
18806 ++
18807 + .min_coredump = ELF_EXEC_PAGESIZE,
18808 + .hasvdso = 1
18809 + };
18810 +@@ -84,6 +99,8 @@ static struct linux_binfmt elf_format =
18811 +
18812 + static int set_brk(unsigned long start, unsigned long end)
18813 + {
18814 ++ unsigned long e = end;
18815 ++
18816 + start = ELF_PAGEALIGN(start);
18817 + end = ELF_PAGEALIGN(end);
18818 + if (end > start) {
18819 +@@ -94,7 +111,7 @@ static int set_brk(unsigned long start,
18820 + if (BAD_ADDR(addr))
18821 + return addr;
18822 + }
18823 +- current->mm->start_brk = current->mm->brk = end;
18824 ++ current->mm->start_brk = current->mm->brk = e;
18825 + return 0;
18826 + }
18827 +
18828 +@@ -380,10 +397,10 @@ static unsigned long load_elf_interp(str
18829 + {
18830 + struct elf_phdr *elf_phdata;
18831 + struct elf_phdr *eppnt;
18832 +- unsigned long load_addr = 0;
18833 ++ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
18834 + int load_addr_set = 0;
18835 + unsigned long last_bss = 0, elf_bss = 0;
18836 +- unsigned long error = ~0UL;
18837 ++ unsigned long error = -EINVAL;
18838 + unsigned long total_size;
18839 + int retval, i, size;
18840 +
18841 +@@ -429,6 +446,11 @@ static unsigned long load_elf_interp(str
18842 + goto out_close;
18843 + }
18844 +
18845 ++#ifdef CONFIG_PAX_SEGMEXEC
18846 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
18847 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
18848 ++#endif
18849 ++
18850 + eppnt = elf_phdata;
18851 + for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
18852 + if (eppnt->p_type == PT_LOAD) {
18853 +@@ -472,8 +494,8 @@ static unsigned long load_elf_interp(str
18854 + k = load_addr + eppnt->p_vaddr;
18855 + if (BAD_ADDR(k) ||
18856 + eppnt->p_filesz > eppnt->p_memsz ||
18857 +- eppnt->p_memsz > TASK_SIZE ||
18858 +- TASK_SIZE - eppnt->p_memsz < k) {
18859 ++ eppnt->p_memsz > pax_task_size ||
18860 ++ pax_task_size - eppnt->p_memsz < k) {
18861 + error = -ENOMEM;
18862 + goto out_close;
18863 + }
18864 +@@ -527,6 +549,177 @@ out:
18865 + return error;
18866 + }
18867 +
18868 ++#if (defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)) && defined(CONFIG_PAX_SOFTMODE)
18869 ++static unsigned long pax_parse_softmode(const struct elf_phdr * const elf_phdata)
18870 ++{
18871 ++ unsigned long pax_flags = 0UL;
18872 ++
18873 ++#ifdef CONFIG_PAX_PAGEEXEC
18874 ++ if (elf_phdata->p_flags & PF_PAGEEXEC)
18875 ++ pax_flags |= MF_PAX_PAGEEXEC;
18876 ++#endif
18877 ++
18878 ++#ifdef CONFIG_PAX_SEGMEXEC
18879 ++ if (elf_phdata->p_flags & PF_SEGMEXEC)
18880 ++ pax_flags |= MF_PAX_SEGMEXEC;
18881 ++#endif
18882 ++
18883 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
18884 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
18885 ++ if (nx_enabled)
18886 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
18887 ++ else
18888 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
18889 ++ }
18890 ++#endif
18891 ++
18892 ++#ifdef CONFIG_PAX_EMUTRAMP
18893 ++ if (elf_phdata->p_flags & PF_EMUTRAMP)
18894 ++ pax_flags |= MF_PAX_EMUTRAMP;
18895 ++#endif
18896 ++
18897 ++#ifdef CONFIG_PAX_MPROTECT
18898 ++ if (elf_phdata->p_flags & PF_MPROTECT)
18899 ++ pax_flags |= MF_PAX_MPROTECT;
18900 ++#endif
18901 ++
18902 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
18903 ++ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
18904 ++ pax_flags |= MF_PAX_RANDMMAP;
18905 ++#endif
18906 ++
18907 ++ return pax_flags;
18908 ++}
18909 ++#endif
18910 ++
18911 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
18912 ++static unsigned long pax_parse_hardmode(const struct elf_phdr * const elf_phdata)
18913 ++{
18914 ++ unsigned long pax_flags = 0UL;
18915 ++
18916 ++#ifdef CONFIG_PAX_PAGEEXEC
18917 ++ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
18918 ++ pax_flags |= MF_PAX_PAGEEXEC;
18919 ++#endif
18920 ++
18921 ++#ifdef CONFIG_PAX_SEGMEXEC
18922 ++ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
18923 ++ pax_flags |= MF_PAX_SEGMEXEC;
18924 ++#endif
18925 ++
18926 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
18927 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
18928 ++ if (nx_enabled)
18929 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
18930 ++ else
18931 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
18932 ++ }
18933 ++#endif
18934 ++
18935 ++#ifdef CONFIG_PAX_EMUTRAMP
18936 ++ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
18937 ++ pax_flags |= MF_PAX_EMUTRAMP;
18938 ++#endif
18939 ++
18940 ++#ifdef CONFIG_PAX_MPROTECT
18941 ++ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
18942 ++ pax_flags |= MF_PAX_MPROTECT;
18943 ++#endif
18944 ++
18945 ++#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
18946 ++ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
18947 ++ pax_flags |= MF_PAX_RANDMMAP;
18948 ++#endif
18949 ++
18950 ++ return pax_flags;
18951 ++}
18952 ++#endif
18953 ++
18954 ++#ifdef CONFIG_PAX_EI_PAX
18955 ++static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
18956 ++{
18957 ++ unsigned long pax_flags = 0UL;
18958 ++
18959 ++#ifdef CONFIG_PAX_PAGEEXEC
18960 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
18961 ++ pax_flags |= MF_PAX_PAGEEXEC;
18962 ++#endif
18963 ++
18964 ++#ifdef CONFIG_PAX_SEGMEXEC
18965 ++ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
18966 ++ pax_flags |= MF_PAX_SEGMEXEC;
18967 ++#endif
18968 ++
18969 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
18970 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
18971 ++ if (nx_enabled)
18972 ++ pax_flags &= ~MF_PAX_SEGMEXEC;
18973 ++ else
18974 ++ pax_flags &= ~MF_PAX_PAGEEXEC;
18975 ++ }
18976 ++#endif
18977 ++
18978 ++#ifdef CONFIG_PAX_EMUTRAMP
18979 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
18980 ++ pax_flags |= MF_PAX_EMUTRAMP;
18981 ++#endif
18982 ++
18983 ++#ifdef CONFIG_PAX_MPROTECT
18984 ++ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
18985 ++ pax_flags |= MF_PAX_MPROTECT;
18986 ++#endif
18987 ++
18988 ++#ifdef CONFIG_PAX_ASLR
18989 ++ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
18990 ++ pax_flags |= MF_PAX_RANDMMAP;
18991 ++#endif
18992 ++
18993 ++ return pax_flags;
18994 ++}
18995 ++#endif
18996 ++
18997 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
18998 ++static long pax_parse_elf_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
18999 ++{
19000 ++ unsigned long pax_flags = 0UL;
19001 ++
19002 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
19003 ++ unsigned long i;
19004 ++#endif
19005 ++
19006 ++#ifdef CONFIG_PAX_EI_PAX
19007 ++ pax_flags = pax_parse_ei_pax(elf_ex);
19008 ++#endif
19009 ++
19010 ++#ifdef CONFIG_PAX_PT_PAX_FLAGS
19011 ++ for (i = 0UL; i < elf_ex->e_phnum; i++)
19012 ++ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
19013 ++ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
19014 ++ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
19015 ++ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
19016 ++ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
19017 ++ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
19018 ++ return -EINVAL;
19019 ++
19020 ++#ifdef CONFIG_PAX_SOFTMODE
19021 ++ if (pax_softmode)
19022 ++ pax_flags = pax_parse_softmode(&elf_phdata[i]);
19023 ++ else
19024 ++#endif
19025 ++
19026 ++ pax_flags = pax_parse_hardmode(&elf_phdata[i]);
19027 ++ break;
19028 ++ }
19029 ++#endif
19030 ++
19031 ++ if (0 > pax_check_flags(&pax_flags))
19032 ++ return -EINVAL;
19033 ++
19034 ++ current->mm->pax_flags = pax_flags;
19035 ++ return 0;
19036 ++}
19037 ++#endif
19038 ++
19039 + /*
19040 + * These are the functions used to load ELF style executables and shared
19041 + * libraries. There is no binary dependent code anywhere else.
19042 +@@ -543,6 +736,11 @@ static unsigned long randomize_stack_top
19043 + {
19044 + unsigned int random_variable = 0;
19045 +
19046 ++#ifdef CONFIG_PAX_RANDUSTACK
19047 ++ if (randomize_va_space)
19048 ++ return stack_top - current->mm->delta_stack;
19049 ++#endif
19050 ++
19051 + if ((current->flags & PF_RANDOMIZE) &&
19052 + !(current->personality & ADDR_NO_RANDOMIZE)) {
19053 + random_variable = get_random_int() & STACK_RND_MASK;
19054 +@@ -561,7 +759,7 @@ static int load_elf_binary(struct linux_
19055 + unsigned long load_addr = 0, load_bias = 0;
19056 + int load_addr_set = 0;
19057 + char * elf_interpreter = NULL;
19058 +- unsigned long error;
19059 ++ unsigned long error = 0;
19060 + struct elf_phdr *elf_ppnt, *elf_phdata;
19061 + unsigned long elf_bss, elf_brk;
19062 + int elf_exec_fileno;
19063 +@@ -572,11 +770,11 @@ static int load_elf_binary(struct linux_
19064 + unsigned long start_code, end_code, start_data, end_data;
19065 + unsigned long reloc_func_desc = 0;
19066 + int executable_stack = EXSTACK_DEFAULT;
19067 +- unsigned long def_flags = 0;
19068 + struct {
19069 + struct elfhdr elf_ex;
19070 + struct elfhdr interp_elf_ex;
19071 + } *loc;
19072 ++ unsigned long pax_task_size = TASK_SIZE;
19073 +
19074 + loc = kmalloc(sizeof(*loc), GFP_KERNEL);
19075 + if (!loc) {
19076 +@@ -744,11 +942,80 @@ static int load_elf_binary(struct linux_
19077 +
19078 + /* OK, This is the point of no return */
19079 + current->flags &= ~PF_FORKNOEXEC;
19080 +- current->mm->def_flags = def_flags;
19081 ++
19082 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
19083 ++ current->mm->pax_flags = 0UL;
19084 ++#endif
19085 ++
19086 ++#ifdef CONFIG_PAX_DLRESOLVE
19087 ++ current->mm->call_dl_resolve = 0UL;
19088 ++#endif
19089 ++
19090 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
19091 ++ current->mm->call_syscall = 0UL;
19092 ++#endif
19093 ++
19094 ++#ifdef CONFIG_PAX_ASLR
19095 ++ current->mm->delta_mmap = 0UL;
19096 ++ current->mm->delta_stack = 0UL;
19097 ++#endif
19098 ++
19099 ++ current->mm->def_flags = 0;
19100 ++
19101 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS)
19102 ++ if (0 > pax_parse_elf_flags(&loc->elf_ex, elf_phdata)) {
19103 ++ send_sig(SIGKILL, current, 0);
19104 ++ goto out_free_dentry;
19105 ++ }
19106 ++#endif
19107 ++
19108 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
19109 ++ pax_set_initial_flags(bprm);
19110 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
19111 ++ if (pax_set_initial_flags_func)
19112 ++ (pax_set_initial_flags_func)(bprm);
19113 ++#endif
19114 ++
19115 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
19116 ++ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !nx_enabled) {
19117 ++ current->mm->context.user_cs_limit = PAGE_SIZE;
19118 ++ current->mm->def_flags |= VM_PAGEEXEC;
19119 ++ }
19120 ++#endif
19121 ++
19122 ++#ifdef CONFIG_PAX_SEGMEXEC
19123 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
19124 ++ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
19125 ++ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
19126 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
19127 ++ }
19128 ++#endif
19129 ++
19130 ++#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
19131 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
19132 ++ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
19133 ++ put_cpu_no_resched();
19134 ++ }
19135 ++#endif
19136 ++
19137 ++#ifdef CONFIG_PAX_ASLR
19138 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
19139 ++ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
19140 ++ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
19141 ++ }
19142 ++#endif
19143 +
19144 + /* Do this immediately, since STACK_TOP as used in setup_arg_pages
19145 + may depend on the personality. */
19146 + SET_PERSONALITY(loc->elf_ex);
19147 ++
19148 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19149 ++ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
19150 ++ executable_stack = EXSTACK_DISABLE_X;
19151 ++ current->personality &= ~READ_IMPLIES_EXEC;
19152 ++ } else
19153 ++#endif
19154 ++
19155 + if (elf_read_implies_exec(loc->elf_ex, executable_stack))
19156 + current->personality |= READ_IMPLIES_EXEC;
19157 +
19158 +@@ -829,6 +1096,20 @@ static int load_elf_binary(struct linux_
19159 + #else
19160 + load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
19161 + #endif
19162 ++
19163 ++#ifdef CONFIG_PAX_RANDMMAP
19164 ++ /* PaX: randomize base address at the default exe base if requested */
19165 ++ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
19166 ++#ifdef CONFIG_SPARC64
19167 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
19168 ++#else
19169 ++ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
19170 ++#endif
19171 ++ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
19172 ++ elf_flags |= MAP_FIXED;
19173 ++ }
19174 ++#endif
19175 ++
19176 + }
19177 +
19178 + error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
19179 +@@ -861,9 +1142,9 @@ static int load_elf_binary(struct linux_
19180 + * allowed task size. Note that p_filesz must always be
19181 + * <= p_memsz so it is only necessary to check p_memsz.
19182 + */
19183 +- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
19184 +- elf_ppnt->p_memsz > TASK_SIZE ||
19185 +- TASK_SIZE - elf_ppnt->p_memsz < k) {
19186 ++ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
19187 ++ elf_ppnt->p_memsz > pax_task_size ||
19188 ++ pax_task_size - elf_ppnt->p_memsz < k) {
19189 + /* set_brk can never work. Avoid overflows. */
19190 + send_sig(SIGKILL, current, 0);
19191 + retval = -EINVAL;
19192 +@@ -891,6 +1172,11 @@ static int load_elf_binary(struct linux_
19193 + start_data += load_bias;
19194 + end_data += load_bias;
19195 +
19196 ++#ifdef CONFIG_PAX_RANDMMAP
19197 ++ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
19198 ++ elf_brk += PAGE_SIZE + ((pax_get_random_long() & ~PAGE_MASK) << 4);
19199 ++#endif
19200 ++
19201 + /* Calling set_brk effectively mmaps the pages that we need
19202 + * for the bss and break sections. We must do this before
19203 + * mapping in the interpreter, to make sure it doesn't wind
19204 +@@ -902,9 +1188,11 @@ static int load_elf_binary(struct linux_
19205 + goto out_free_dentry;
19206 + }
19207 + if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
19208 +- send_sig(SIGSEGV, current, 0);
19209 +- retval = -EFAULT; /* Nobody gets to see this, but.. */
19210 +- goto out_free_dentry;
19211 ++ /*
19212 ++ * This bss-zeroing can fail if the ELF
19213 ++ * file specifies odd protections. So
19214 ++ * we don't check the return value
19215 ++ */
19216 + }
19217 +
19218 + if (elf_interpreter) {
19219 +@@ -1141,8 +1429,10 @@ static int dump_seek(struct file *file,
19220 + unsigned long n = off;
19221 + if (n > PAGE_SIZE)
19222 + n = PAGE_SIZE;
19223 +- if (!dump_write(file, buf, n))
19224 ++ if (!dump_write(file, buf, n)) {
19225 ++ free_page((unsigned long)buf);
19226 + return 0;
19227 ++ }
19228 + off -= n;
19229 + }
19230 + free_page((unsigned long)buf);
19231 +@@ -1154,7 +1444,7 @@ static int dump_seek(struct file *file,
19232 + * Decide what to dump of a segment, part, all or none.
19233 + */
19234 + static unsigned long vma_dump_size(struct vm_area_struct *vma,
19235 +- unsigned long mm_flags)
19236 ++ unsigned long mm_flags, long signr)
19237 + {
19238 + #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
19239 +
19240 +@@ -1188,7 +1478,7 @@ static unsigned long vma_dump_size(struc
19241 + if (vma->vm_file == NULL)
19242 + return 0;
19243 +
19244 +- if (FILTER(MAPPED_PRIVATE))
19245 ++ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
19246 + goto whole;
19247 +
19248 + /*
19249 +@@ -1274,8 +1564,11 @@ static int writenote(struct memelfnote *
19250 + #undef DUMP_WRITE
19251 +
19252 + #define DUMP_WRITE(addr, nr) \
19253 ++ do { \
19254 ++ gr_learn_resource(current, RLIMIT_CORE, size + (nr), 1); \
19255 + if ((size += (nr)) > limit || !dump_write(file, (addr), (nr))) \
19256 +- goto end_coredump;
19257 ++ goto end_coredump; \
19258 ++ } while (0);
19259 + #define DUMP_SEEK(off) \
19260 + if (!dump_seek(file, (off))) \
19261 + goto end_coredump;
19262 +@@ -1976,7 +2269,7 @@ static int elf_core_dump(long signr, str
19263 + phdr.p_offset = offset;
19264 + phdr.p_vaddr = vma->vm_start;
19265 + phdr.p_paddr = 0;
19266 +- phdr.p_filesz = vma_dump_size(vma, mm_flags);
19267 ++ phdr.p_filesz = vma_dump_size(vma, mm_flags, signr);
19268 + phdr.p_memsz = vma->vm_end - vma->vm_start;
19269 + offset += phdr.p_filesz;
19270 + phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
19271 +@@ -2008,7 +2301,7 @@ static int elf_core_dump(long signr, str
19272 + unsigned long addr;
19273 + unsigned long end;
19274 +
19275 +- end = vma->vm_start + vma_dump_size(vma, mm_flags);
19276 ++ end = vma->vm_start + vma_dump_size(vma, mm_flags, signr);
19277 +
19278 + for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
19279 + struct page *page;
19280 +@@ -2028,6 +2321,7 @@ static int elf_core_dump(long signr, str
19281 + flush_cache_page(tmp_vma, addr,
19282 + page_to_pfn(page));
19283 + kaddr = kmap(page);
19284 ++ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
19285 + if ((size += PAGE_SIZE) > limit ||
19286 + !dump_write(file, kaddr,
19287 + PAGE_SIZE)) {
19288 +@@ -2058,6 +2352,99 @@ out:
19289 +
19290 + #endif /* USE_ELF_CORE_DUMP */
19291 +
19292 ++#ifdef CONFIG_PAX_MPROTECT
19293 ++/* PaX: non-PIC ELF libraries need relocations on their executable segments
19294 ++ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
19295 ++ * we'll remove VM_MAYWRITE for good on RELRO segments.
19296 ++ *
19297 ++ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
19298 ++ * basis because we want to allow the common case and not the special ones.
19299 ++ */
19300 ++static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
19301 ++{
19302 ++ struct elfhdr elf_h;
19303 ++ struct elf_phdr elf_p;
19304 ++ unsigned long i;
19305 ++ unsigned long oldflags;
19306 ++ bool is_textrel_rw, is_textrel_rx, is_relro;
19307 ++
19308 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
19309 ++ return;
19310 ++
19311 ++ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
19312 ++ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
19313 ++
19314 ++#ifdef CONFIG_PAX_NOELFRELOCS
19315 ++ is_textrel_rw = false;
19316 ++ is_textrel_rx = false;
19317 ++#else
19318 ++ /* possible TEXTREL */
19319 ++ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
19320 ++ is_textrel_rx = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
19321 ++#endif
19322 ++
19323 ++ /* possible RELRO */
19324 ++ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
19325 ++
19326 ++ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
19327 ++ return;
19328 ++
19329 ++ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
19330 ++ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
19331 ++
19332 ++#ifdef CONFIG_PAX_ETEXECRELOCS
19333 ++ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
19334 ++#else
19335 ++ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
19336 ++#endif
19337 ++
19338 ++ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
19339 ++ !elf_check_arch(&elf_h) ||
19340 ++ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
19341 ++ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
19342 ++ return;
19343 ++
19344 ++ for (i = 0UL; i < elf_h.e_phnum; i++) {
19345 ++ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
19346 ++ return;
19347 ++ switch (elf_p.p_type) {
19348 ++ case PT_DYNAMIC: {
19349 ++ elf_addr_t dyn_offset = 0UL;
19350 ++ elf_dyn dyn;
19351 ++
19352 ++ if (!is_textrel_rw && !is_textrel_rx)
19353 ++ continue;
19354 ++ dyn_offset = elf_p.p_offset;
19355 ++ i = 0UL;
19356 ++ do {
19357 ++ if (sizeof(dyn) != kernel_read(vma->vm_file, dyn_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
19358 ++ return;
19359 ++ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
19360 ++ gr_log_textrel(vma);
19361 ++ if (is_textrel_rw)
19362 ++ vma->vm_flags |= VM_MAYWRITE;
19363 ++ else
19364 ++ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
19365 ++ vma->vm_flags &= ~VM_MAYWRITE;
19366 ++ return;
19367 ++ }
19368 ++ i++;
19369 ++ } while (dyn.d_tag != DT_NULL);
19370 ++ return;
19371 ++ }
19372 ++
19373 ++ case PT_GNU_RELRO:
19374 ++ if (!is_relro)
19375 ++ continue;
19376 ++ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start) {
19377 ++ vma->vm_flags &= ~VM_MAYWRITE;
19378 ++ }
19379 ++ return;
19380 ++ }
19381 ++ }
19382 ++}
19383 ++#endif
19384 ++
19385 + static int __init init_elf_binfmt(void)
19386 + {
19387 + return register_binfmt(&elf_format);
19388 +diff -urNp linux-2.6.28/fs/binfmt_flat.c linux-2.6.28/fs/binfmt_flat.c
19389 +--- linux-2.6.28/fs/binfmt_flat.c 2008-12-24 18:26:37.000000000 -0500
19390 ++++ linux-2.6.28/fs/binfmt_flat.c 2009-01-11 07:20:06.000000000 -0500
19391 +@@ -561,7 +561,9 @@ static int load_flat_file(struct linux_b
19392 + realdatastart = (unsigned long) -ENOMEM;
19393 + printk("Unable to allocate RAM for process data, errno %d\n",
19394 + (int)-realdatastart);
19395 ++ down_write(&current->mm->mmap_sem);
19396 + do_munmap(current->mm, textpos, text_len);
19397 ++ up_write(&current->mm->mmap_sem);
19398 + ret = realdatastart;
19399 + goto err;
19400 + }
19401 +@@ -583,8 +585,10 @@ static int load_flat_file(struct linux_b
19402 + }
19403 + if (result >= (unsigned long)-4096) {
19404 + printk("Unable to read data+bss, errno %d\n", (int)-result);
19405 ++ down_write(&current->mm->mmap_sem);
19406 + do_munmap(current->mm, textpos, text_len);
19407 + do_munmap(current->mm, realdatastart, data_len + extra);
19408 ++ up_write(&current->mm->mmap_sem);
19409 + ret = result;
19410 + goto err;
19411 + }
19412 +@@ -657,8 +661,10 @@ static int load_flat_file(struct linux_b
19413 + }
19414 + if (result >= (unsigned long)-4096) {
19415 + printk("Unable to read code+data+bss, errno %d\n",(int)-result);
19416 ++ down_write(&current->mm->mmap_sem);
19417 + do_munmap(current->mm, textpos, text_len + data_len + extra +
19418 + MAX_SHARED_LIBS * sizeof(unsigned long));
19419 ++ up_write(&current->mm->mmap_sem);
19420 + ret = result;
19421 + goto err;
19422 + }
19423 +diff -urNp linux-2.6.28/fs/binfmt_misc.c linux-2.6.28/fs/binfmt_misc.c
19424 +--- linux-2.6.28/fs/binfmt_misc.c 2008-12-24 18:26:37.000000000 -0500
19425 ++++ linux-2.6.28/fs/binfmt_misc.c 2009-01-11 07:20:06.000000000 -0500
19426 +@@ -696,7 +696,7 @@ static int bm_fill_super(struct super_bl
19427 + static struct tree_descr bm_files[] = {
19428 + [2] = {"status", &bm_status_operations, S_IWUSR|S_IRUGO},
19429 + [3] = {"register", &bm_register_operations, S_IWUSR},
19430 +- /* last one */ {""}
19431 ++ /* last one */ {"", NULL, 0}
19432 + };
19433 + int err = simple_fill_super(sb, 0x42494e4d, bm_files);
19434 + if (!err)
19435 +diff -urNp linux-2.6.28/fs/bio.c linux-2.6.28/fs/bio.c
19436 +--- linux-2.6.28/fs/bio.c 2008-12-24 18:26:37.000000000 -0500
19437 ++++ linux-2.6.28/fs/bio.c 2009-01-11 07:20:06.000000000 -0500
19438 +@@ -554,7 +554,7 @@ static int __bio_copy_iov(struct bio *bi
19439 +
19440 + while (bv_len && iov_idx < iov_count) {
19441 + unsigned int bytes;
19442 +- char *iov_addr;
19443 ++ char __user *iov_addr;
19444 +
19445 + bytes = min_t(unsigned int,
19446 + iov[iov_idx].iov_len - iov_off, bv_len);
19447 +diff -urNp linux-2.6.28/fs/buffer.c linux-2.6.28/fs/buffer.c
19448 +--- linux-2.6.28/fs/buffer.c 2008-12-24 18:26:37.000000000 -0500
19449 ++++ linux-2.6.28/fs/buffer.c 2009-01-11 05:46:58.000000000 -0500
19450 +@@ -41,6 +41,7 @@
19451 + #include <linux/bitops.h>
19452 + #include <linux/mpage.h>
19453 + #include <linux/bit_spinlock.h>
19454 ++#include <linux/grsecurity.h>
19455 +
19456 + static int fsync_buffers_list(spinlock_t *lock, struct list_head *list);
19457 +
19458 +@@ -2249,6 +2250,7 @@ int generic_cont_expand_simple(struct in
19459 +
19460 + err = -EFBIG;
19461 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
19462 ++ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long) size, 1);
19463 + if (limit != RLIM_INFINITY && size > (loff_t)limit) {
19464 + send_sig(SIGXFSZ, current, 0);
19465 + goto out;
19466 +diff -urNp linux-2.6.28/fs/cifs/cifs_uniupr.h linux-2.6.28/fs/cifs/cifs_uniupr.h
19467 +--- linux-2.6.28/fs/cifs/cifs_uniupr.h 2008-12-24 18:26:37.000000000 -0500
19468 ++++ linux-2.6.28/fs/cifs/cifs_uniupr.h 2009-01-11 07:20:06.000000000 -0500
19469 +@@ -132,7 +132,7 @@ const struct UniCaseRange CifsUniUpperRa
19470 + {0x0490, 0x04cc, UniCaseRangeU0490},
19471 + {0x1e00, 0x1ffc, UniCaseRangeU1e00},
19472 + {0xff40, 0xff5a, UniCaseRangeUff40},
19473 +- {0}
19474 ++ {0, 0, NULL}
19475 + };
19476 + #endif
19477 +
19478 +diff -urNp linux-2.6.28/fs/cifs/link.c linux-2.6.28/fs/cifs/link.c
19479 +--- linux-2.6.28/fs/cifs/link.c 2008-12-24 18:26:37.000000000 -0500
19480 ++++ linux-2.6.28/fs/cifs/link.c 2009-01-11 07:20:06.000000000 -0500
19481 +@@ -318,7 +318,7 @@ cifs_readlink(struct dentry *direntry, c
19482 +
19483 + void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
19484 + {
19485 +- char *p = nd_get_link(nd);
19486 ++ const char *p = nd_get_link(nd);
19487 + if (!IS_ERR(p))
19488 + kfree(p);
19489 + }
19490 +diff -urNp linux-2.6.28/fs/compat.c linux-2.6.28/fs/compat.c
19491 +--- linux-2.6.28/fs/compat.c 2008-12-24 18:26:37.000000000 -0500
19492 ++++ linux-2.6.28/fs/compat.c 2009-01-11 07:20:06.000000000 -0500
19493 +@@ -51,6 +51,7 @@
19494 + #include <linux/poll.h>
19495 + #include <linux/mm.h>
19496 + #include <linux/eventpoll.h>
19497 ++#include <linux/grsecurity.h>
19498 +
19499 + #include <asm/uaccess.h>
19500 + #include <asm/mmu_context.h>
19501 +@@ -1331,14 +1332,12 @@ static int compat_copy_strings(int argc,
19502 + if (!kmapped_page || kpos != (pos & PAGE_MASK)) {
19503 + struct page *page;
19504 +
19505 +-#ifdef CONFIG_STACK_GROWSUP
19506 + ret = expand_stack_downwards(bprm->vma, pos);
19507 + if (ret < 0) {
19508 + /* We've exceed the stack rlimit. */
19509 + ret = -E2BIG;
19510 + goto out;
19511 + }
19512 +-#endif
19513 + ret = get_user_pages(current, bprm->mm, pos,
19514 + 1, 1, 1, &page, NULL);
19515 + if (ret <= 0) {
19516 +@@ -1384,6 +1383,11 @@ int compat_do_execve(char * filename,
19517 + compat_uptr_t __user *envp,
19518 + struct pt_regs * regs)
19519 + {
19520 ++#ifdef CONFIG_GRKERNSEC
19521 ++ struct file *old_exec_file;
19522 ++ struct acl_subject_label *old_acl;
19523 ++ struct rlimit old_rlim[RLIM_NLIMITS];
19524 ++#endif
19525 + struct linux_binprm *bprm;
19526 + struct file *file;
19527 + int retval;
19528 +@@ -1404,6 +1408,14 @@ int compat_do_execve(char * filename,
19529 + bprm->filename = filename;
19530 + bprm->interp = filename;
19531 +
19532 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
19533 ++ retval = -EAGAIN;
19534 ++ if (gr_handle_nproc())
19535 ++ goto out_file;
19536 ++ retval = -EACCES;
19537 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt))
19538 ++ goto out_file;
19539 ++
19540 + retval = bprm_mm_init(bprm);
19541 + if (retval)
19542 + goto out_file;
19543 +@@ -1437,8 +1449,36 @@ int compat_do_execve(char * filename,
19544 + if (retval < 0)
19545 + goto out;
19546 +
19547 ++ if (!gr_tpe_allow(file)) {
19548 ++ retval = -EACCES;
19549 ++ goto out;
19550 ++ }
19551 ++
19552 ++ if (gr_check_crash_exec(file)) {
19553 ++ retval = -EACCES;
19554 ++ goto out;
19555 ++ }
19556 ++
19557 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
19558 ++
19559 ++ gr_handle_exec_args(bprm, (char __user * __user *)argv);
19560 ++
19561 ++#ifdef CONFIG_GRKERNSEC
19562 ++ old_acl = current->acl;
19563 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
19564 ++ old_exec_file = current->exec_file;
19565 ++ get_file(file);
19566 ++ current->exec_file = file;
19567 ++#endif
19568 ++
19569 ++ gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
19570 ++
19571 + retval = search_binary_handler(bprm, regs);
19572 + if (retval >= 0) {
19573 ++#ifdef CONFIG_GRKERNSEC
19574 ++ if (old_exec_file)
19575 ++ fput(old_exec_file);
19576 ++#endif
19577 + /* execve success */
19578 + security_bprm_free(bprm);
19579 + acct_update_integrals(current);
19580 +@@ -1446,6 +1486,13 @@ int compat_do_execve(char * filename,
19581 + return retval;
19582 + }
19583 +
19584 ++#ifdef CONFIG_GRKERNSEC
19585 ++ current->acl = old_acl;
19586 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
19587 ++ fput(current->exec_file);
19588 ++ current->exec_file = old_exec_file;
19589 ++#endif
19590 ++
19591 + out:
19592 + if (bprm->security)
19593 + security_bprm_free(bprm);
19594 +diff -urNp linux-2.6.28/fs/compat_ioctl.c linux-2.6.28/fs/compat_ioctl.c
19595 +--- linux-2.6.28/fs/compat_ioctl.c 2008-12-24 18:26:37.000000000 -0500
19596 ++++ linux-2.6.28/fs/compat_ioctl.c 2009-01-11 07:20:06.000000000 -0500
19597 +@@ -1831,15 +1831,15 @@ struct ioctl_trans {
19598 + };
19599 +
19600 + #define HANDLE_IOCTL(cmd,handler) \
19601 +- { (cmd), (ioctl_trans_handler_t)(handler) },
19602 ++ { (cmd), (ioctl_trans_handler_t)(handler), NULL },
19603 +
19604 + /* pointer to compatible structure or no argument */
19605 + #define COMPATIBLE_IOCTL(cmd) \
19606 +- { (cmd), do_ioctl32_pointer },
19607 ++ { (cmd), do_ioctl32_pointer, NULL },
19608 +
19609 + /* argument is an unsigned long integer, not a pointer */
19610 + #define ULONG_IOCTL(cmd) \
19611 +- { (cmd), (ioctl_trans_handler_t)sys_ioctl },
19612 ++ { (cmd), (ioctl_trans_handler_t)sys_ioctl, NULL },
19613 +
19614 + /* ioctl should not be warned about even if it's not implemented.
19615 + Valid reasons to use this:
19616 +diff -urNp linux-2.6.28/fs/debugfs/inode.c linux-2.6.28/fs/debugfs/inode.c
19617 +--- linux-2.6.28/fs/debugfs/inode.c 2008-12-24 18:26:37.000000000 -0500
19618 ++++ linux-2.6.28/fs/debugfs/inode.c 2009-01-11 07:20:06.000000000 -0500
19619 +@@ -120,7 +120,7 @@ static inline int debugfs_positive(struc
19620 +
19621 + static int debug_fill_super(struct super_block *sb, void *data, int silent)
19622 + {
19623 +- static struct tree_descr debug_files[] = {{""}};
19624 ++ static struct tree_descr debug_files[] = {{"", NULL, 0}};
19625 +
19626 + return simple_fill_super(sb, DEBUGFS_MAGIC, debug_files);
19627 + }
19628 +diff -urNp linux-2.6.28/fs/exec.c linux-2.6.28/fs/exec.c
19629 +--- linux-2.6.28/fs/exec.c 2008-12-24 18:26:37.000000000 -0500
19630 ++++ linux-2.6.28/fs/exec.c 2009-01-11 07:25:34.000000000 -0500
19631 +@@ -51,6 +51,13 @@
19632 + #include <linux/audit.h>
19633 + #include <linux/tracehook.h>
19634 + #include <linux/kmod.h>
19635 ++#include <linux/random.h>
19636 ++#include <linux/grsecurity.h>
19637 ++
19638 ++#ifdef CONFIG_PAX_REFCOUNT
19639 ++#include <linux/kallsyms.h>
19640 ++#include <linux/kdebug.h>
19641 ++#endif
19642 +
19643 + #include <asm/uaccess.h>
19644 + #include <asm/mmu_context.h>
19645 +@@ -61,6 +68,11 @@
19646 + #include <linux/a.out.h>
19647 + #endif
19648 +
19649 ++#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
19650 ++void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
19651 ++EXPORT_SYMBOL(pax_set_initial_flags_func);
19652 ++#endif
19653 ++
19654 + int core_uses_pid;
19655 + char core_pattern[CORENAME_MAX_SIZE] = "core";
19656 + int suid_dumpable = 0;
19657 +@@ -169,18 +181,10 @@ static struct page *get_arg_page(struct
19658 + int write)
19659 + {
19660 + struct page *page;
19661 +- int ret;
19662 +
19663 +-#ifdef CONFIG_STACK_GROWSUP
19664 +- if (write) {
19665 +- ret = expand_stack_downwards(bprm->vma, pos);
19666 +- if (ret < 0)
19667 +- return NULL;
19668 +- }
19669 +-#endif
19670 +- ret = get_user_pages(current, bprm->mm, pos,
19671 +- 1, write, 1, &page, NULL);
19672 +- if (ret <= 0)
19673 ++ if (0 > expand_stack_downwards(bprm->vma, pos))
19674 ++ return NULL;
19675 ++ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
19676 + return NULL;
19677 +
19678 + if (write) {
19679 +@@ -253,6 +257,11 @@ static int __bprm_mm_init(struct linux_b
19680 + vma->vm_start = vma->vm_end - PAGE_SIZE;
19681 +
19682 + vma->vm_flags = VM_STACK_FLAGS;
19683 ++
19684 ++#ifdef CONFIG_PAX_SEGMEXEC
19685 ++ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
19686 ++#endif
19687 ++
19688 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
19689 + err = insert_vm_struct(mm, vma);
19690 + if (err) {
19691 +@@ -265,6 +274,11 @@ static int __bprm_mm_init(struct linux_b
19692 +
19693 + bprm->p = vma->vm_end - sizeof(void *);
19694 +
19695 ++#ifdef CONFIG_PAX_RANDUSTACK
19696 ++ if (randomize_va_space)
19697 ++ bprm->p ^= (pax_get_random_long() & ~15) & ~PAGE_MASK;
19698 ++#endif
19699 ++
19700 + return 0;
19701 +
19702 + err:
19703 +@@ -528,6 +542,10 @@ static int shift_arg_pages(struct vm_are
19704 + if (vma != find_vma(mm, new_start))
19705 + return -EFAULT;
19706 +
19707 ++#ifdef CONFIG_PAX_SEGMEXEC
19708 ++ BUG_ON(pax_find_mirror_vma(vma));
19709 ++#endif
19710 ++
19711 + /*
19712 + * cover the whole range: [new_start, old_end)
19713 + */
19714 +@@ -616,6 +634,14 @@ int setup_arg_pages(struct linux_binprm
19715 + bprm->exec -= stack_shift;
19716 +
19717 + down_write(&mm->mmap_sem);
19718 ++
19719 ++ /* Move stack pages down in memory. */
19720 ++ if (stack_shift) {
19721 ++ ret = shift_arg_pages(vma, stack_shift);
19722 ++ if (ret)
19723 ++ goto out_unlock;
19724 ++ }
19725 ++
19726 + vm_flags = VM_STACK_FLAGS;
19727 +
19728 + /*
19729 +@@ -629,21 +655,24 @@ int setup_arg_pages(struct linux_binprm
19730 + vm_flags &= ~VM_EXEC;
19731 + vm_flags |= mm->def_flags;
19732 +
19733 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19734 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
19735 ++ vm_flags &= ~VM_EXEC;
19736 ++
19737 ++#ifdef CONFIG_PAX_MPROTECT
19738 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
19739 ++ vm_flags &= ~VM_MAYEXEC;
19740 ++#endif
19741 ++
19742 ++ }
19743 ++#endif
19744 ++
19745 + ret = mprotect_fixup(vma, &prev, vma->vm_start, vma->vm_end,
19746 + vm_flags);
19747 + if (ret)
19748 + goto out_unlock;
19749 + BUG_ON(prev != vma);
19750 +
19751 +- /* Move stack pages down in memory. */
19752 +- if (stack_shift) {
19753 +- ret = shift_arg_pages(vma, stack_shift);
19754 +- if (ret) {
19755 +- up_write(&mm->mmap_sem);
19756 +- return ret;
19757 +- }
19758 +- }
19759 +-
19760 + #ifdef CONFIG_STACK_GROWSUP
19761 + stack_base = vma->vm_end + EXTRA_STACK_VM_PAGES * PAGE_SIZE;
19762 + #else
19763 +@@ -655,7 +684,7 @@ int setup_arg_pages(struct linux_binprm
19764 +
19765 + out_unlock:
19766 + up_write(&mm->mmap_sem);
19767 +- return 0;
19768 ++ return ret;
19769 + }
19770 + EXPORT_SYMBOL(setup_arg_pages);
19771 +
19772 +@@ -1281,6 +1310,11 @@ int do_execve(char * filename,
19773 + char __user *__user *envp,
19774 + struct pt_regs * regs)
19775 + {
19776 ++#ifdef CONFIG_GRKERNSEC
19777 ++ struct file *old_exec_file;
19778 ++ struct acl_subject_label *old_acl;
19779 ++ struct rlimit old_rlim[RLIM_NLIMITS];
19780 ++#endif
19781 + struct linux_binprm *bprm;
19782 + struct file *file;
19783 + struct files_struct *displaced;
19784 +@@ -1300,6 +1334,20 @@ int do_execve(char * filename,
19785 + if (IS_ERR(file))
19786 + goto out_kfree;
19787 +
19788 ++ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->user->processes), 1);
19789 ++
19790 ++ if (gr_handle_nproc()) {
19791 ++ allow_write_access(file);
19792 ++ fput(file);
19793 ++ return -EAGAIN;
19794 ++ }
19795 ++
19796 ++ if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
19797 ++ allow_write_access(file);
19798 ++ fput(file);
19799 ++ return -EACCES;
19800 ++ }
19801 ++
19802 + sched_exec();
19803 +
19804 + bprm->file = file;
19805 +@@ -1339,9 +1387,39 @@ int do_execve(char * filename,
19806 + if (retval < 0)
19807 + goto out;
19808 +
19809 ++ if (!gr_tpe_allow(file)) {
19810 ++ retval = -EACCES;
19811 ++ goto out;
19812 ++ }
19813 ++
19814 ++ if (gr_check_crash_exec(file)) {
19815 ++ retval = -EACCES;
19816 ++ goto out;
19817 ++ }
19818 ++
19819 ++ gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
19820 ++
19821 ++ gr_handle_exec_args(bprm, argv);
19822 ++
19823 ++#ifdef CONFIG_GRKERNSEC
19824 ++ old_acl = current->acl;
19825 ++ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
19826 ++ old_exec_file = current->exec_file;
19827 ++ get_file(file);
19828 ++ current->exec_file = file;
19829 ++#endif
19830 ++
19831 ++ retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt);
19832 ++ if (retval < 0)
19833 ++ goto out_fail;
19834 ++
19835 + current->flags &= ~PF_KTHREAD;
19836 + retval = search_binary_handler(bprm,regs);
19837 + if (retval >= 0) {
19838 ++#ifdef CONFIG_GRKERNSEC
19839 ++ if (old_exec_file)
19840 ++ fput(old_exec_file);
19841 ++#endif
19842 + /* execve success */
19843 + security_bprm_free(bprm);
19844 + acct_update_integrals(current);
19845 +@@ -1351,6 +1429,14 @@ int do_execve(char * filename,
19846 + return retval;
19847 + }
19848 +
19849 ++out_fail:
19850 ++#ifdef CONFIG_GRKERNSEC
19851 ++ current->acl = old_acl;
19852 ++ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
19853 ++ fput(current->exec_file);
19854 ++ current->exec_file = old_exec_file;
19855 ++#endif
19856 ++
19857 + out:
19858 + if (bprm->security)
19859 + security_bprm_free(bprm);
19860 +@@ -1513,6 +1599,129 @@ out:
19861 + return ispipe;
19862 + }
19863 +
19864 ++int pax_check_flags(unsigned long *flags)
19865 ++{
19866 ++ int retval = 0;
19867 ++
19868 ++#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
19869 ++ if (*flags & MF_PAX_SEGMEXEC)
19870 ++ {
19871 ++ *flags &= ~MF_PAX_SEGMEXEC;
19872 ++ retval = -EINVAL;
19873 ++ }
19874 ++#endif
19875 ++
19876 ++ if ((*flags & MF_PAX_PAGEEXEC)
19877 ++
19878 ++#ifdef CONFIG_PAX_PAGEEXEC
19879 ++ && (*flags & MF_PAX_SEGMEXEC)
19880 ++#endif
19881 ++
19882 ++ )
19883 ++ {
19884 ++ *flags &= ~MF_PAX_PAGEEXEC;
19885 ++ retval = -EINVAL;
19886 ++ }
19887 ++
19888 ++ if ((*flags & MF_PAX_MPROTECT)
19889 ++
19890 ++#ifdef CONFIG_PAX_MPROTECT
19891 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
19892 ++#endif
19893 ++
19894 ++ )
19895 ++ {
19896 ++ *flags &= ~MF_PAX_MPROTECT;
19897 ++ retval = -EINVAL;
19898 ++ }
19899 ++
19900 ++ if ((*flags & MF_PAX_EMUTRAMP)
19901 ++
19902 ++#ifdef CONFIG_PAX_EMUTRAMP
19903 ++ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
19904 ++#endif
19905 ++
19906 ++ )
19907 ++ {
19908 ++ *flags &= ~MF_PAX_EMUTRAMP;
19909 ++ retval = -EINVAL;
19910 ++ }
19911 ++
19912 ++ return retval;
19913 ++}
19914 ++
19915 ++EXPORT_SYMBOL(pax_check_flags);
19916 ++
19917 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
19918 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
19919 ++{
19920 ++ struct task_struct *tsk = current;
19921 ++ struct mm_struct *mm = current->mm;
19922 ++ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
19923 ++ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
19924 ++ char *path_exec = NULL;
19925 ++ char *path_fault = NULL;
19926 ++ unsigned long start = 0UL, end = 0UL, offset = 0UL;
19927 ++
19928 ++ if (buffer_exec && buffer_fault) {
19929 ++ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
19930 ++
19931 ++ down_read(&mm->mmap_sem);
19932 ++ vma = mm->mmap;
19933 ++ while (vma && (!vma_exec || !vma_fault)) {
19934 ++ if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
19935 ++ vma_exec = vma;
19936 ++ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
19937 ++ vma_fault = vma;
19938 ++ vma = vma->vm_next;
19939 ++ }
19940 ++ if (vma_exec) {
19941 ++ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
19942 ++ if (IS_ERR(path_exec))
19943 ++ path_exec = "<path too long>";
19944 ++ }
19945 ++ if (vma_fault) {
19946 ++ start = vma_fault->vm_start;
19947 ++ end = vma_fault->vm_end;
19948 ++ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
19949 ++ if (vma_fault->vm_file) {
19950 ++ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
19951 ++ if (IS_ERR(path_fault))
19952 ++ path_fault = "<path too long>";
19953 ++ } else
19954 ++ path_fault = "<anonymous mapping>";
19955 ++ }
19956 ++ up_read(&mm->mmap_sem);
19957 ++ }
19958 ++ if (tsk->signal->curr_ip)
19959 ++ 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);
19960 ++ else
19961 ++ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
19962 ++ printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
19963 ++ "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
19964 ++ tsk->uid, tsk->euid, pc, sp);
19965 ++ free_page((unsigned long)buffer_exec);
19966 ++ free_page((unsigned long)buffer_fault);
19967 ++ pax_report_insns(pc, sp);
19968 ++ do_coredump(SIGKILL, SIGKILL, regs);
19969 ++}
19970 ++#endif
19971 ++
19972 ++#ifdef CONFIG_PAX_REFCOUNT
19973 ++void pax_report_refcount_overflow(struct pt_regs *regs)
19974 ++{
19975 ++ if (current->signal->curr_ip)
19976 ++ printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
19977 ++ NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
19978 ++ else
19979 ++ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
19980 ++ current->comm, task_pid_nr(current), current->uid, current->euid);
19981 ++ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
19982 ++ show_registers(regs);
19983 ++ force_sig_specific(SIGKILL, current);
19984 ++}
19985 ++#endif
19986 ++
19987 + static int zap_process(struct task_struct *start)
19988 + {
19989 + struct task_struct *t;
19990 +@@ -1759,6 +1968,10 @@ int do_coredump(long signr, int exit_cod
19991 + */
19992 + clear_thread_flag(TIF_SIGPENDING);
19993 +
19994 ++ if (signr == SIGKILL || signr == SIGILL)
19995 ++ gr_handle_brute_attach(current);
19996 ++ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
19997 ++
19998 + /*
19999 + * lock_kernel() because format_corename() is controlled by sysctl, which
20000 + * uses lock_kernel()
20001 +@@ -1779,6 +1992,8 @@ int do_coredump(long signr, int exit_cod
20002 +
20003 + if (ispipe) {
20004 + helper_argv = argv_split(GFP_KERNEL, corename+1, &helper_argc);
20005 ++ if (!helper_argv)
20006 ++ goto fail_unlock;
20007 + /* Terminate the string before the first option */
20008 + delimit = strchr(corename, ' ');
20009 + if (delimit)
20010 +diff -urNp linux-2.6.28/fs/ext2/balloc.c linux-2.6.28/fs/ext2/balloc.c
20011 +--- linux-2.6.28/fs/ext2/balloc.c 2008-12-24 18:26:37.000000000 -0500
20012 ++++ linux-2.6.28/fs/ext2/balloc.c 2009-01-11 05:46:58.000000000 -0500
20013 +@@ -1192,7 +1192,7 @@ static int ext2_has_free_blocks(struct e
20014 +
20015 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
20016 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
20017 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
20018 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
20019 + sbi->s_resuid != current->fsuid &&
20020 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
20021 + return 0;
20022 +diff -urNp linux-2.6.28/fs/ext3/balloc.c linux-2.6.28/fs/ext3/balloc.c
20023 +--- linux-2.6.28/fs/ext3/balloc.c 2008-12-24 18:26:37.000000000 -0500
20024 ++++ linux-2.6.28/fs/ext3/balloc.c 2009-01-11 05:46:58.000000000 -0500
20025 +@@ -1421,7 +1421,7 @@ static int ext3_has_free_blocks(struct e
20026 +
20027 + free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
20028 + root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
20029 +- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
20030 ++ if (free_blocks < root_blocks + 1 && !capable_nolog(CAP_SYS_RESOURCE) &&
20031 + sbi->s_resuid != current->fsuid &&
20032 + (sbi->s_resgid == 0 || !in_group_p (sbi->s_resgid))) {
20033 + return 0;
20034 +diff -urNp linux-2.6.28/fs/ext3/namei.c linux-2.6.28/fs/ext3/namei.c
20035 +--- linux-2.6.28/fs/ext3/namei.c 2008-12-24 18:26:37.000000000 -0500
20036 ++++ linux-2.6.28/fs/ext3/namei.c 2009-01-11 07:20:06.000000000 -0500
20037 +@@ -1156,9 +1156,9 @@ static struct ext3_dir_entry_2 *do_split
20038 + u32 hash2;
20039 + struct dx_map_entry *map;
20040 + char *data1 = (*bh)->b_data, *data2;
20041 +- unsigned split, move, size, i;
20042 ++ unsigned split, move, size;
20043 + struct ext3_dir_entry_2 *de = NULL, *de2;
20044 +- int err = 0;
20045 ++ int i, err = 0;
20046 +
20047 + bh2 = ext3_append (handle, dir, &newblock, &err);
20048 + if (!(bh2)) {
20049 +diff -urNp linux-2.6.28/fs/ext3/xattr.c linux-2.6.28/fs/ext3/xattr.c
20050 +--- linux-2.6.28/fs/ext3/xattr.c 2008-12-24 18:26:37.000000000 -0500
20051 ++++ linux-2.6.28/fs/ext3/xattr.c 2009-01-11 07:20:06.000000000 -0500
20052 +@@ -89,8 +89,8 @@
20053 + printk("\n"); \
20054 + } while (0)
20055 + #else
20056 +-# define ea_idebug(f...)
20057 +-# define ea_bdebug(f...)
20058 ++# define ea_idebug(f...) do {} while (0)
20059 ++# define ea_bdebug(f...) do {} while (0)
20060 + #endif
20061 +
20062 + static void ext3_xattr_cache_insert(struct buffer_head *);
20063 +diff -urNp linux-2.6.28/fs/ext4/balloc.c linux-2.6.28/fs/ext4/balloc.c
20064 +--- linux-2.6.28/fs/ext4/balloc.c 2008-12-24 18:26:37.000000000 -0500
20065 ++++ linux-2.6.28/fs/ext4/balloc.c 2009-01-11 05:53:04.000000000 -0500
20066 +@@ -626,7 +626,7 @@ int ext4_has_free_blocks(struct ext4_sb_
20067 + /* Hm, nope. Are (enough) root reserved blocks available? */
20068 + if (sbi->s_resuid == current->fsuid ||
20069 + ((sbi->s_resgid != 0) && in_group_p(sbi->s_resgid)) ||
20070 +- capable(CAP_SYS_RESOURCE)) {
20071 ++ capable_nolog(CAP_SYS_RESOURCE)) {
20072 + if (free_blocks >= (nblocks + dirty_blocks))
20073 + return 1;
20074 + }
20075 +diff -urNp linux-2.6.28/fs/ext4/namei.c linux-2.6.28/fs/ext4/namei.c
20076 +--- linux-2.6.28/fs/ext4/namei.c 2008-12-24 18:26:37.000000000 -0500
20077 ++++ linux-2.6.28/fs/ext4/namei.c 2009-01-11 07:20:06.000000000 -0500
20078 +@@ -1166,9 +1166,9 @@ static struct ext4_dir_entry_2 *do_split
20079 + u32 hash2;
20080 + struct dx_map_entry *map;
20081 + char *data1 = (*bh)->b_data, *data2;
20082 +- unsigned split, move, size, i;
20083 ++ unsigned split, move, size;
20084 + struct ext4_dir_entry_2 *de = NULL, *de2;
20085 +- int err = 0;
20086 ++ int i, err = 0;
20087 +
20088 + bh2 = ext4_append (handle, dir, &newblock, &err);
20089 + if (!(bh2)) {
20090 +diff -urNp linux-2.6.28/fs/fcntl.c linux-2.6.28/fs/fcntl.c
20091 +--- linux-2.6.28/fs/fcntl.c 2008-12-24 18:26:37.000000000 -0500
20092 ++++ linux-2.6.28/fs/fcntl.c 2009-01-11 05:46:58.000000000 -0500
20093 +@@ -19,6 +19,7 @@
20094 + #include <linux/signal.h>
20095 + #include <linux/rcupdate.h>
20096 + #include <linux/pid_namespace.h>
20097 ++#include <linux/grsecurity.h>
20098 + #include <linux/smp_lock.h>
20099 +
20100 + #include <asm/poll.h>
20101 +@@ -266,6 +267,7 @@ static long do_fcntl(int fd, unsigned in
20102 + switch (cmd) {
20103 + case F_DUPFD:
20104 + case F_DUPFD_CLOEXEC:
20105 ++ gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
20106 + if (arg >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
20107 + break;
20108 + err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
20109 +@@ -410,7 +412,8 @@ static inline int sigio_perm(struct task
20110 + return (((fown->euid == 0) ||
20111 + (fown->euid == p->suid) || (fown->euid == p->uid) ||
20112 + (fown->uid == p->suid) || (fown->uid == p->uid)) &&
20113 +- !security_file_send_sigiotask(p, fown, sig));
20114 ++ !security_file_send_sigiotask(p, fown, sig) &&
20115 ++ !gr_check_protected_task(p) && !gr_pid_is_chrooted(p));
20116 + }
20117 +
20118 + static void send_sigio_to_task(struct task_struct *p,
20119 +diff -urNp linux-2.6.28/fs/file.c linux-2.6.28/fs/file.c
20120 +--- linux-2.6.28/fs/file.c 2008-12-24 18:26:37.000000000 -0500
20121 ++++ linux-2.6.28/fs/file.c 2009-01-11 05:46:58.000000000 -0500
20122 +@@ -19,6 +19,7 @@
20123 + #include <linux/spinlock.h>
20124 + #include <linux/rcupdate.h>
20125 + #include <linux/workqueue.h>
20126 ++#include <linux/grsecurity.h>
20127 +
20128 + struct fdtable_defer {
20129 + spinlock_t lock;
20130 +@@ -256,6 +257,8 @@ int expand_files(struct files_struct *fi
20131 + * N.B. For clone tasks sharing a files structure, this test
20132 + * will limit the total number of files that can be opened.
20133 + */
20134 ++
20135 ++ gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
20136 + if (nr >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
20137 + return -EMFILE;
20138 +
20139 +diff -urNp linux-2.6.28/fs/fuse/control.c linux-2.6.28/fs/fuse/control.c
20140 +--- linux-2.6.28/fs/fuse/control.c 2008-12-24 18:26:37.000000000 -0500
20141 ++++ linux-2.6.28/fs/fuse/control.c 2009-01-11 07:20:06.000000000 -0500
20142 +@@ -159,7 +159,7 @@ void fuse_ctl_remove_conn(struct fuse_co
20143 +
20144 + static int fuse_ctl_fill_super(struct super_block *sb, void *data, int silent)
20145 + {
20146 +- struct tree_descr empty_descr = {""};
20147 ++ struct tree_descr empty_descr = {"", NULL, 0};
20148 + struct fuse_conn *fc;
20149 + int err;
20150 +
20151 +diff -urNp linux-2.6.28/fs/fuse/dir.c linux-2.6.28/fs/fuse/dir.c
20152 +--- linux-2.6.28/fs/fuse/dir.c 2008-12-24 18:26:37.000000000 -0500
20153 ++++ linux-2.6.28/fs/fuse/dir.c 2009-01-11 07:20:06.000000000 -0500
20154 +@@ -1072,7 +1072,7 @@ static char *read_link(struct dentry *de
20155 + return link;
20156 + }
20157 +
20158 +-static void free_link(char *link)
20159 ++static void free_link(const char *link)
20160 + {
20161 + if (!IS_ERR(link))
20162 + free_page((unsigned long) link);
20163 +diff -urNp linux-2.6.28/fs/hfs/inode.c linux-2.6.28/fs/hfs/inode.c
20164 +--- linux-2.6.28/fs/hfs/inode.c 2008-12-24 18:26:37.000000000 -0500
20165 ++++ linux-2.6.28/fs/hfs/inode.c 2009-01-11 07:20:06.000000000 -0500
20166 +@@ -419,7 +419,7 @@ int hfs_write_inode(struct inode *inode,
20167 +
20168 + if (S_ISDIR(main_inode->i_mode)) {
20169 + if (fd.entrylength < sizeof(struct hfs_cat_dir))
20170 +- /* panic? */;
20171 ++ {/* panic? */}
20172 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
20173 + sizeof(struct hfs_cat_dir));
20174 + if (rec.type != HFS_CDR_DIR ||
20175 +@@ -440,7 +440,7 @@ int hfs_write_inode(struct inode *inode,
20176 + sizeof(struct hfs_cat_file));
20177 + } else {
20178 + if (fd.entrylength < sizeof(struct hfs_cat_file))
20179 +- /* panic? */;
20180 ++ {/* panic? */}
20181 + hfs_bnode_read(fd.bnode, &rec, fd.entryoffset,
20182 + sizeof(struct hfs_cat_file));
20183 + if (rec.type != HFS_CDR_FIL ||
20184 +diff -urNp linux-2.6.28/fs/hfsplus/inode.c linux-2.6.28/fs/hfsplus/inode.c
20185 +--- linux-2.6.28/fs/hfsplus/inode.c 2008-12-24 18:26:37.000000000 -0500
20186 ++++ linux-2.6.28/fs/hfsplus/inode.c 2009-01-11 07:20:06.000000000 -0500
20187 +@@ -406,7 +406,7 @@ int hfsplus_cat_read_inode(struct inode
20188 + struct hfsplus_cat_folder *folder = &entry.folder;
20189 +
20190 + if (fd->entrylength < sizeof(struct hfsplus_cat_folder))
20191 +- /* panic? */;
20192 ++ {/* panic? */}
20193 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
20194 + sizeof(struct hfsplus_cat_folder));
20195 + hfsplus_get_perms(inode, &folder->permissions, 1);
20196 +@@ -423,7 +423,7 @@ int hfsplus_cat_read_inode(struct inode
20197 + struct hfsplus_cat_file *file = &entry.file;
20198 +
20199 + if (fd->entrylength < sizeof(struct hfsplus_cat_file))
20200 +- /* panic? */;
20201 ++ {/* panic? */}
20202 + hfs_bnode_read(fd->bnode, &entry, fd->entryoffset,
20203 + sizeof(struct hfsplus_cat_file));
20204 +
20205 +@@ -479,7 +479,7 @@ int hfsplus_cat_write_inode(struct inode
20206 + struct hfsplus_cat_folder *folder = &entry.folder;
20207 +
20208 + if (fd.entrylength < sizeof(struct hfsplus_cat_folder))
20209 +- /* panic? */;
20210 ++ {/* panic? */}
20211 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
20212 + sizeof(struct hfsplus_cat_folder));
20213 + /* simple node checks? */
20214 +@@ -501,7 +501,7 @@ int hfsplus_cat_write_inode(struct inode
20215 + struct hfsplus_cat_file *file = &entry.file;
20216 +
20217 + if (fd.entrylength < sizeof(struct hfsplus_cat_file))
20218 +- /* panic? */;
20219 ++ {/* panic? */}
20220 + hfs_bnode_read(fd.bnode, &entry, fd.entryoffset,
20221 + sizeof(struct hfsplus_cat_file));
20222 + hfsplus_inode_write_fork(inode, &file->data_fork);
20223 +diff -urNp linux-2.6.28/fs/jffs2/debug.h linux-2.6.28/fs/jffs2/debug.h
20224 +--- linux-2.6.28/fs/jffs2/debug.h 2008-12-24 18:26:37.000000000 -0500
20225 ++++ linux-2.6.28/fs/jffs2/debug.h 2009-01-11 07:20:06.000000000 -0500
20226 +@@ -52,13 +52,13 @@
20227 + #if CONFIG_JFFS2_FS_DEBUG > 0
20228 + #define D1(x) x
20229 + #else
20230 +-#define D1(x)
20231 ++#define D1(x) do {} while (0);
20232 + #endif
20233 +
20234 + #if CONFIG_JFFS2_FS_DEBUG > 1
20235 + #define D2(x) x
20236 + #else
20237 +-#define D2(x)
20238 ++#define D2(x) do {} while (0);
20239 + #endif
20240 +
20241 + /* The prefixes of JFFS2 messages */
20242 +@@ -114,73 +114,73 @@
20243 + #ifdef JFFS2_DBG_READINODE_MESSAGES
20244 + #define dbg_readinode(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20245 + #else
20246 +-#define dbg_readinode(fmt, ...)
20247 ++#define dbg_readinode(fmt, ...) do {} while (0)
20248 + #endif
20249 + #ifdef JFFS2_DBG_READINODE2_MESSAGES
20250 + #define dbg_readinode2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20251 + #else
20252 +-#define dbg_readinode2(fmt, ...)
20253 ++#define dbg_readinode2(fmt, ...) do {} while (0)
20254 + #endif
20255 +
20256 + /* Fragtree build debugging messages */
20257 + #ifdef JFFS2_DBG_FRAGTREE_MESSAGES
20258 + #define dbg_fragtree(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20259 + #else
20260 +-#define dbg_fragtree(fmt, ...)
20261 ++#define dbg_fragtree(fmt, ...) do {} while (0)
20262 + #endif
20263 + #ifdef JFFS2_DBG_FRAGTREE2_MESSAGES
20264 + #define dbg_fragtree2(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20265 + #else
20266 +-#define dbg_fragtree2(fmt, ...)
20267 ++#define dbg_fragtree2(fmt, ...) do {} while (0)
20268 + #endif
20269 +
20270 + /* Directory entry list manilulation debugging messages */
20271 + #ifdef JFFS2_DBG_DENTLIST_MESSAGES
20272 + #define dbg_dentlist(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20273 + #else
20274 +-#define dbg_dentlist(fmt, ...)
20275 ++#define dbg_dentlist(fmt, ...) do {} while (0)
20276 + #endif
20277 +
20278 + /* Print the messages about manipulating node_refs */
20279 + #ifdef JFFS2_DBG_NODEREF_MESSAGES
20280 + #define dbg_noderef(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20281 + #else
20282 +-#define dbg_noderef(fmt, ...)
20283 ++#define dbg_noderef(fmt, ...) do {} while (0)
20284 + #endif
20285 +
20286 + /* Manipulations with the list of inodes (JFFS2 inocache) */
20287 + #ifdef JFFS2_DBG_INOCACHE_MESSAGES
20288 + #define dbg_inocache(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20289 + #else
20290 +-#define dbg_inocache(fmt, ...)
20291 ++#define dbg_inocache(fmt, ...) do {} while (0)
20292 + #endif
20293 +
20294 + /* Summary debugging messages */
20295 + #ifdef JFFS2_DBG_SUMMARY_MESSAGES
20296 + #define dbg_summary(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20297 + #else
20298 +-#define dbg_summary(fmt, ...)
20299 ++#define dbg_summary(fmt, ...) do {} while (0)
20300 + #endif
20301 +
20302 + /* File system build messages */
20303 + #ifdef JFFS2_DBG_FSBUILD_MESSAGES
20304 + #define dbg_fsbuild(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20305 + #else
20306 +-#define dbg_fsbuild(fmt, ...)
20307 ++#define dbg_fsbuild(fmt, ...) do {} while (0)
20308 + #endif
20309 +
20310 + /* Watch the object allocations */
20311 + #ifdef JFFS2_DBG_MEMALLOC_MESSAGES
20312 + #define dbg_memalloc(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20313 + #else
20314 +-#define dbg_memalloc(fmt, ...)
20315 ++#define dbg_memalloc(fmt, ...) do {} while (0)
20316 + #endif
20317 +
20318 + /* Watch the XATTR subsystem */
20319 + #ifdef JFFS2_DBG_XATTR_MESSAGES
20320 + #define dbg_xattr(fmt, ...) JFFS2_DEBUG(fmt, ##__VA_ARGS__)
20321 + #else
20322 +-#define dbg_xattr(fmt, ...)
20323 ++#define dbg_xattr(fmt, ...) do {} while (0)
20324 + #endif
20325 +
20326 + /* "Sanity" checks */
20327 +diff -urNp linux-2.6.28/fs/jffs2/erase.c linux-2.6.28/fs/jffs2/erase.c
20328 +--- linux-2.6.28/fs/jffs2/erase.c 2008-12-24 18:26:37.000000000 -0500
20329 ++++ linux-2.6.28/fs/jffs2/erase.c 2009-01-11 07:20:06.000000000 -0500
20330 +@@ -431,7 +431,8 @@ static void jffs2_mark_erased_block(stru
20331 + struct jffs2_unknown_node marker = {
20332 + .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
20333 + .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
20334 +- .totlen = cpu_to_je32(c->cleanmarker_size)
20335 ++ .totlen = cpu_to_je32(c->cleanmarker_size),
20336 ++ .hdr_crc = cpu_to_je32(0)
20337 + };
20338 +
20339 + jffs2_prealloc_raw_node_refs(c, jeb, 1);
20340 +diff -urNp linux-2.6.28/fs/jffs2/summary.h linux-2.6.28/fs/jffs2/summary.h
20341 +--- linux-2.6.28/fs/jffs2/summary.h 2008-12-24 18:26:37.000000000 -0500
20342 ++++ linux-2.6.28/fs/jffs2/summary.h 2009-01-11 07:20:06.000000000 -0500
20343 +@@ -194,18 +194,18 @@ int jffs2_sum_scan_sumnode(struct jffs2_
20344 +
20345 + #define jffs2_sum_active() (0)
20346 + #define jffs2_sum_init(a) (0)
20347 +-#define jffs2_sum_exit(a)
20348 +-#define jffs2_sum_disable_collecting(a)
20349 ++#define jffs2_sum_exit(a) do {} while (0)
20350 ++#define jffs2_sum_disable_collecting(a) do {} while (0)
20351 + #define jffs2_sum_is_disabled(a) (0)
20352 +-#define jffs2_sum_reset_collected(a)
20353 ++#define jffs2_sum_reset_collected(a) do {} while (0)
20354 + #define jffs2_sum_add_kvec(a,b,c,d) (0)
20355 +-#define jffs2_sum_move_collected(a,b)
20356 ++#define jffs2_sum_move_collected(a,b) do {} while (0)
20357 + #define jffs2_sum_write_sumnode(a) (0)
20358 +-#define jffs2_sum_add_padding_mem(a,b)
20359 +-#define jffs2_sum_add_inode_mem(a,b,c)
20360 +-#define jffs2_sum_add_dirent_mem(a,b,c)
20361 +-#define jffs2_sum_add_xattr_mem(a,b,c)
20362 +-#define jffs2_sum_add_xref_mem(a,b,c)
20363 ++#define jffs2_sum_add_padding_mem(a,b) do {} while (0)
20364 ++#define jffs2_sum_add_inode_mem(a,b,c) do {} while (0)
20365 ++#define jffs2_sum_add_dirent_mem(a,b,c) do {} while (0)
20366 ++#define jffs2_sum_add_xattr_mem(a,b,c) do {} while (0)
20367 ++#define jffs2_sum_add_xref_mem(a,b,c) do {} while (0)
20368 + #define jffs2_sum_scan_sumnode(a,b,c,d,e) (0)
20369 +
20370 + #endif /* CONFIG_JFFS2_SUMMARY */
20371 +diff -urNp linux-2.6.28/fs/jffs2/wbuf.c linux-2.6.28/fs/jffs2/wbuf.c
20372 +--- linux-2.6.28/fs/jffs2/wbuf.c 2008-12-24 18:26:37.000000000 -0500
20373 ++++ linux-2.6.28/fs/jffs2/wbuf.c 2009-01-11 07:20:06.000000000 -0500
20374 +@@ -1012,7 +1012,8 @@ static const struct jffs2_unknown_node o
20375 + {
20376 + .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
20377 + .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
20378 +- .totlen = constant_cpu_to_je32(8)
20379 ++ .totlen = constant_cpu_to_je32(8),
20380 ++ .hdr_crc = constant_cpu_to_je32(0)
20381 + };
20382 +
20383 + /*
20384 +diff -urNp linux-2.6.28/fs/locks.c linux-2.6.28/fs/locks.c
20385 +--- linux-2.6.28/fs/locks.c 2008-12-24 18:26:37.000000000 -0500
20386 ++++ linux-2.6.28/fs/locks.c 2009-01-11 07:20:06.000000000 -0500
20387 +@@ -2006,16 +2006,16 @@ void locks_remove_flock(struct file *fil
20388 + return;
20389 +
20390 + if (filp->f_op && filp->f_op->flock) {
20391 +- struct file_lock fl = {
20392 ++ struct file_lock flock = {
20393 + .fl_pid = current->tgid,
20394 + .fl_file = filp,
20395 + .fl_flags = FL_FLOCK,
20396 + .fl_type = F_UNLCK,
20397 + .fl_end = OFFSET_MAX,
20398 + };
20399 +- filp->f_op->flock(filp, F_SETLKW, &fl);
20400 +- if (fl.fl_ops && fl.fl_ops->fl_release_private)
20401 +- fl.fl_ops->fl_release_private(&fl);
20402 ++ filp->f_op->flock(filp, F_SETLKW, &flock);
20403 ++ if (flock.fl_ops && flock.fl_ops->fl_release_private)
20404 ++ flock.fl_ops->fl_release_private(&flock);
20405 + }
20406 +
20407 + lock_kernel();
20408 +diff -urNp linux-2.6.28/fs/namei.c linux-2.6.28/fs/namei.c
20409 +--- linux-2.6.28/fs/namei.c 2008-12-24 18:26:37.000000000 -0500
20410 ++++ linux-2.6.28/fs/namei.c 2009-01-11 07:20:06.000000000 -0500
20411 +@@ -31,6 +31,8 @@
20412 + #include <linux/file.h>
20413 + #include <linux/fcntl.h>
20414 + #include <linux/device_cgroup.h>
20415 ++#include <linux/grsecurity.h>
20416 ++
20417 + #include <asm/uaccess.h>
20418 +
20419 + #define ACC_MODE(x) ("\000\004\002\006"[(x)&O_ACCMODE])
20420 +@@ -633,7 +635,7 @@ static __always_inline int __do_follow_l
20421 + cookie = dentry->d_inode->i_op->follow_link(dentry, nd);
20422 + error = PTR_ERR(cookie);
20423 + if (!IS_ERR(cookie)) {
20424 +- char *s = nd_get_link(nd);
20425 ++ const char *s = nd_get_link(nd);
20426 + error = 0;
20427 + if (s)
20428 + error = __vfs_follow_link(nd, s);
20429 +@@ -664,6 +666,13 @@ static inline int do_follow_link(struct
20430 + err = security_inode_follow_link(path->dentry, nd);
20431 + if (err)
20432 + goto loop;
20433 ++
20434 ++ if (gr_handle_follow_link(path->dentry->d_parent->d_inode,
20435 ++ path->dentry->d_inode, path->dentry, nd->path.mnt)) {
20436 ++ err = -EACCES;
20437 ++ goto loop;
20438 ++ }
20439 ++
20440 + current->link_count++;
20441 + current->total_link_count++;
20442 + nd->depth++;
20443 +@@ -1012,11 +1021,18 @@ return_reval:
20444 + break;
20445 + }
20446 + return_base:
20447 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
20448 ++ path_put(&nd->path);
20449 ++ return -ENOENT;
20450 ++ }
20451 + return 0;
20452 + out_dput:
20453 + path_put_conditional(&next, nd);
20454 + break;
20455 + }
20456 ++ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt))
20457 ++ err = -ENOENT;
20458 ++
20459 + path_put(&nd->path);
20460 + return_err:
20461 + return err;
20462 +@@ -1582,9 +1598,17 @@ static int __open_namei_create(struct na
20463 + int error;
20464 + struct dentry *dir = nd->path.dentry;
20465 +
20466 ++ if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, nd->path.mnt, flag, mode)) {
20467 ++ error = -EACCES;
20468 ++ goto out_unlock_dput;
20469 ++ }
20470 ++
20471 + if (!IS_POSIXACL(dir->d_inode))
20472 + mode &= ~current->fs->umask;
20473 + error = vfs_create(dir->d_inode, path->dentry, mode, nd);
20474 ++ if (!error)
20475 ++ gr_handle_create(path->dentry, nd->path.mnt);
20476 ++out_unlock_dput:
20477 + mutex_unlock(&dir->d_inode->i_mutex);
20478 + dput(nd->path.dentry);
20479 + nd->path.dentry = path->dentry;
20480 +@@ -1665,6 +1689,17 @@ struct file *do_filp_open(int dfd, const
20481 + &nd, flag);
20482 + if (error)
20483 + return ERR_PTR(error);
20484 ++
20485 ++ if (gr_handle_rawio(nd.path.dentry->d_inode)) {
20486 ++ error = -EPERM;
20487 ++ goto exit;
20488 ++ }
20489 ++
20490 ++ if (!gr_acl_handle_open(nd.path.dentry, nd.path.mnt, flag)) {
20491 ++ error = -EACCES;
20492 ++ goto exit;
20493 ++ }
20494 ++
20495 + goto ok;
20496 + }
20497 +
20498 +@@ -1737,6 +1772,20 @@ do_last:
20499 + /*
20500 + * It already exists.
20501 + */
20502 ++
20503 ++ if (gr_handle_rawio(path.dentry->d_inode)) {
20504 ++ error = -EPERM;
20505 ++ goto exit_mutex_unlock;
20506 ++ }
20507 ++ if (!gr_acl_handle_open(path.dentry, nd.path.mnt, flag)) {
20508 ++ error = -EACCES;
20509 ++ goto exit_mutex_unlock;
20510 ++ }
20511 ++ if (gr_handle_fifo(path.dentry, nd.path.mnt, dir, flag, acc_mode)) {
20512 ++ error = -EACCES;
20513 ++ goto exit_mutex_unlock;
20514 ++ }
20515 ++
20516 + mutex_unlock(&dir->d_inode->i_mutex);
20517 + audit_inode(pathname, path.dentry);
20518 +
20519 +@@ -1822,6 +1871,13 @@ do_link:
20520 + error = security_inode_follow_link(path.dentry, &nd);
20521 + if (error)
20522 + goto exit_dput;
20523 ++
20524 ++ if (gr_handle_follow_link(path.dentry->d_parent->d_inode, path.dentry->d_inode,
20525 ++ path.dentry, nd.path.mnt)) {
20526 ++ error = -EACCES;
20527 ++ goto exit_dput;
20528 ++ }
20529 ++
20530 + error = __do_follow_link(&path, &nd);
20531 + if (error) {
20532 + /* Does someone understand code flow here? Or it is only
20533 +@@ -1994,9 +2050,21 @@ asmlinkage long sys_mknodat(int dfd, con
20534 + error = may_mknod(mode);
20535 + if (error)
20536 + goto out_dput;
20537 ++
20538 ++ if (gr_handle_chroot_mknod(dentry, nd.path.mnt, mode)) {
20539 ++ error = -EPERM;
20540 ++ goto out_dput;
20541 ++ }
20542 ++
20543 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
20544 ++ error = -EACCES;
20545 ++ goto out_dput;
20546 ++ }
20547 ++
20548 + error = mnt_want_write(nd.path.mnt);
20549 + if (error)
20550 + goto out_dput;
20551 ++
20552 + switch (mode & S_IFMT) {
20553 + case 0: case S_IFREG:
20554 + error = vfs_create(nd.path.dentry->d_inode,dentry,mode,&nd);
20555 +@@ -2010,6 +2078,9 @@ asmlinkage long sys_mknodat(int dfd, con
20556 + break;
20557 + }
20558 + mnt_drop_write(nd.path.mnt);
20559 ++
20560 ++ if (!error)
20561 ++ gr_handle_create(dentry, nd.path.mnt);
20562 + out_dput:
20563 + dput(dentry);
20564 + out_unlock:
20565 +@@ -2063,6 +2134,11 @@ asmlinkage long sys_mkdirat(int dfd, con
20566 + if (IS_ERR(dentry))
20567 + goto out_unlock;
20568 +
20569 ++ if (!gr_acl_handle_mkdir(dentry, nd.path.dentry, nd.path.mnt)) {
20570 ++ error = -EACCES;
20571 ++ goto out_dput;
20572 ++ }
20573 ++
20574 + if (!IS_POSIXACL(nd.path.dentry->d_inode))
20575 + mode &= ~current->fs->umask;
20576 + error = mnt_want_write(nd.path.mnt);
20577 +@@ -2070,6 +2146,10 @@ asmlinkage long sys_mkdirat(int dfd, con
20578 + goto out_dput;
20579 + error = vfs_mkdir(nd.path.dentry->d_inode, dentry, mode);
20580 + mnt_drop_write(nd.path.mnt);
20581 ++
20582 ++ if (!error)
20583 ++ gr_handle_create(dentry, nd.path.mnt);
20584 ++
20585 + out_dput:
20586 + dput(dentry);
20587 + out_unlock:
20588 +@@ -2151,6 +2231,8 @@ static long do_rmdir(int dfd, const char
20589 + char * name;
20590 + struct dentry *dentry;
20591 + struct nameidata nd;
20592 ++ ino_t saved_ino = 0;
20593 ++ dev_t saved_dev = 0;
20594 +
20595 + error = user_path_parent(dfd, pathname, &nd, &name);
20596 + if (error)
20597 +@@ -2175,11 +2257,26 @@ static long do_rmdir(int dfd, const char
20598 + error = PTR_ERR(dentry);
20599 + if (IS_ERR(dentry))
20600 + goto exit2;
20601 ++
20602 ++ if (dentry->d_inode != NULL) {
20603 ++ if (dentry->d_inode->i_nlink <= 1) {
20604 ++ saved_ino = dentry->d_inode->i_ino;
20605 ++ saved_dev = dentry->d_inode->i_sb->s_dev;
20606 ++ }
20607 ++
20608 ++ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
20609 ++ error = -EACCES;
20610 ++ goto exit3;
20611 ++ }
20612 ++ }
20613 ++
20614 + error = mnt_want_write(nd.path.mnt);
20615 + if (error)
20616 + goto exit3;
20617 + error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
20618 + mnt_drop_write(nd.path.mnt);
20619 ++ if (!error && (saved_dev || saved_ino))
20620 ++ gr_handle_delete(saved_ino, saved_dev);
20621 + exit3:
20622 + dput(dentry);
20623 + exit2:
20624 +@@ -2239,6 +2336,8 @@ static long do_unlinkat(int dfd, const c
20625 + struct dentry *dentry;
20626 + struct nameidata nd;
20627 + struct inode *inode = NULL;
20628 ++ ino_t saved_ino = 0;
20629 ++ dev_t saved_dev = 0;
20630 +
20631 + error = user_path_parent(dfd, pathname, &nd, &name);
20632 + if (error)
20633 +@@ -2258,12 +2357,25 @@ static long do_unlinkat(int dfd, const c
20634 + if (nd.last.name[nd.last.len])
20635 + goto slashes;
20636 + inode = dentry->d_inode;
20637 +- if (inode)
20638 ++ if (inode) {
20639 ++ if (inode->i_nlink <= 1) {
20640 ++ saved_ino = inode->i_ino;
20641 ++ saved_dev = inode->i_sb->s_dev;
20642 ++ }
20643 ++
20644 + atomic_inc(&inode->i_count);
20645 ++
20646 ++ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
20647 ++ error = -EACCES;
20648 ++ goto exit2;
20649 ++ }
20650 ++ }
20651 + error = mnt_want_write(nd.path.mnt);
20652 + if (error)
20653 + goto exit2;
20654 + error = vfs_unlink(nd.path.dentry->d_inode, dentry);
20655 ++ if (!error && (saved_ino || saved_dev))
20656 ++ gr_handle_delete(saved_ino, saved_dev);
20657 + mnt_drop_write(nd.path.mnt);
20658 + exit2:
20659 + dput(dentry);
20660 +@@ -2341,10 +2453,17 @@ asmlinkage long sys_symlinkat(const char
20661 + if (IS_ERR(dentry))
20662 + goto out_unlock;
20663 +
20664 ++ if (!gr_acl_handle_symlink(dentry, nd.path.dentry, nd.path.mnt, from)) {
20665 ++ error = -EACCES;
20666 ++ goto out_dput;
20667 ++ }
20668 ++
20669 + error = mnt_want_write(nd.path.mnt);
20670 + if (error)
20671 + goto out_dput;
20672 + error = vfs_symlink(nd.path.dentry->d_inode, dentry, from);
20673 ++ if (!error)
20674 ++ gr_handle_create(dentry, nd.path.mnt);
20675 + mnt_drop_write(nd.path.mnt);
20676 + out_dput:
20677 + dput(dentry);
20678 +@@ -2438,10 +2557,26 @@ asmlinkage long sys_linkat(int olddfd, c
20679 + error = PTR_ERR(new_dentry);
20680 + if (IS_ERR(new_dentry))
20681 + goto out_unlock;
20682 ++
20683 ++ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
20684 ++ old_path.dentry->d_inode,
20685 ++ old_path.dentry->d_inode->i_mode, to)) {
20686 ++ error = -EACCES;
20687 ++ goto out_dput;
20688 ++ }
20689 ++
20690 ++ if (!gr_acl_handle_link(new_dentry, nd.path.dentry, nd.path.mnt,
20691 ++ old_path.dentry, old_path.mnt, to)) {
20692 ++ error = -EACCES;
20693 ++ goto out_dput;
20694 ++ }
20695 ++
20696 + error = mnt_want_write(nd.path.mnt);
20697 + if (error)
20698 + goto out_dput;
20699 + error = vfs_link(old_path.dentry, nd.path.dentry->d_inode, new_dentry);
20700 ++ if (!error)
20701 ++ gr_handle_create(new_dentry, nd.path.mnt);
20702 + mnt_drop_write(nd.path.mnt);
20703 + out_dput:
20704 + dput(new_dentry);
20705 +@@ -2597,8 +2732,10 @@ int vfs_rename(struct inode *old_dir, st
20706 + error = vfs_rename_dir(old_dir,old_dentry,new_dir,new_dentry);
20707 + else
20708 + error = vfs_rename_other(old_dir,old_dentry,new_dir,new_dentry);
20709 ++
20710 + if (!error) {
20711 + const char *new_name = old_dentry->d_name.name;
20712 ++
20713 + fsnotify_move(old_dir, new_dir, old_name, new_name, is_dir,
20714 + new_dentry->d_inode, old_dentry);
20715 + }
20716 +@@ -2674,11 +2811,21 @@ asmlinkage long sys_renameat(int olddfd,
20717 + if (new_dentry == trap)
20718 + goto exit5;
20719 +
20720 ++ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
20721 ++ old_dentry, old_dir->d_inode, oldnd.path.mnt,
20722 ++ to);
20723 ++ if (error)
20724 ++ goto exit5;
20725 ++
20726 + error = mnt_want_write(oldnd.path.mnt);
20727 + if (error)
20728 + goto exit5;
20729 + error = vfs_rename(old_dir->d_inode, old_dentry,
20730 + new_dir->d_inode, new_dentry);
20731 ++ if (!error)
20732 ++ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
20733 ++ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
20734 ++
20735 + mnt_drop_write(oldnd.path.mnt);
20736 + exit5:
20737 + dput(new_dentry);
20738 +diff -urNp linux-2.6.28/fs/namespace.c linux-2.6.28/fs/namespace.c
20739 +--- linux-2.6.28/fs/namespace.c 2008-12-24 18:26:37.000000000 -0500
20740 ++++ linux-2.6.28/fs/namespace.c 2009-01-11 07:52:31.000000000 -0500
20741 +@@ -27,6 +27,7 @@
20742 + #include <linux/ramfs.h>
20743 + #include <linux/log2.h>
20744 + #include <linux/idr.h>
20745 ++#include <linux/grsecurity.h>
20746 + #include <asm/uaccess.h>
20747 + #include <asm/unistd.h>
20748 + #include "pnode.h"
20749 +@@ -1094,6 +1095,8 @@ static int do_umount(struct vfsmount *mn
20750 + lock_kernel();
20751 + retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
20752 + unlock_kernel();
20753 ++
20754 ++ gr_log_remount(mnt->mnt_devname, retval);
20755 + }
20756 + up_write(&sb->s_umount);
20757 + return retval;
20758 +@@ -1117,6 +1120,9 @@ static int do_umount(struct vfsmount *mn
20759 + security_sb_umount_busy(mnt);
20760 + up_write(&namespace_sem);
20761 + release_mounts(&umount_list);
20762 ++
20763 ++ gr_log_unmount(mnt->mnt_devname, retval);
20764 ++
20765 + return retval;
20766 + }
20767 +
20768 +@@ -1946,6 +1952,11 @@ long do_mount(char *dev_name, char *dir_
20769 + if (retval)
20770 + goto dput_out;
20771 +
20772 ++ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
20773 ++ retval = -EPERM;
20774 ++ goto dput_out;
20775 ++ }
20776 ++
20777 + if (flags & MS_REMOUNT)
20778 + retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
20779 + data_page);
20780 +@@ -1960,6 +1971,9 @@ long do_mount(char *dev_name, char *dir_
20781 + dev_name, data_page);
20782 + dput_out:
20783 + path_put(&path);
20784 ++
20785 ++ gr_log_mount(dev_name, dir_name, retval);
20786 ++
20787 + return retval;
20788 + }
20789 +
20790 +@@ -2072,6 +2086,9 @@ asmlinkage long sys_mount(char __user *
20791 + if (retval < 0)
20792 + goto out3;
20793 +
20794 ++ if (gr_handle_chroot_pivot())
20795 ++ return -EPERM;
20796 ++
20797 + lock_kernel();
20798 + retval = do_mount((char *)dev_page, dir_page, (char *)type_page,
20799 + flags, (void *)data_page);
20800 +diff -urNp linux-2.6.28/fs/nfs/nfs4proc.c linux-2.6.28/fs/nfs/nfs4proc.c
20801 +--- linux-2.6.28/fs/nfs/nfs4proc.c 2008-12-24 18:26:37.000000000 -0500
20802 ++++ linux-2.6.28/fs/nfs/nfs4proc.c 2009-01-11 07:20:06.000000000 -0500
20803 +@@ -653,7 +653,7 @@ static int _nfs4_do_open_reclaim(struct
20804 + static int nfs4_do_open_reclaim(struct nfs_open_context *ctx, struct nfs4_state *state)
20805 + {
20806 + struct nfs_server *server = NFS_SERVER(state->inode);
20807 +- struct nfs4_exception exception = { };
20808 ++ struct nfs4_exception exception = {0, 0};
20809 + int err;
20810 + do {
20811 + err = _nfs4_do_open_reclaim(ctx, state);
20812 +@@ -695,7 +695,7 @@ static int _nfs4_open_delegation_recall(
20813 +
20814 + int nfs4_open_delegation_recall(struct nfs_open_context *ctx, struct nfs4_state *state, const nfs4_stateid *stateid)
20815 + {
20816 +- struct nfs4_exception exception = { };
20817 ++ struct nfs4_exception exception = {0, 0};
20818 + struct nfs_server *server = NFS_SERVER(state->inode);
20819 + int err;
20820 + do {
20821 +@@ -988,7 +988,7 @@ static int _nfs4_open_expired(struct nfs
20822 + static inline int nfs4_do_open_expired(struct nfs_open_context *ctx, struct nfs4_state *state)
20823 + {
20824 + struct nfs_server *server = NFS_SERVER(state->inode);
20825 +- struct nfs4_exception exception = { };
20826 ++ struct nfs4_exception exception = {0, 0};
20827 + int err;
20828 +
20829 + do {
20830 +@@ -1090,7 +1090,7 @@ out_err:
20831 +
20832 + static struct nfs4_state *nfs4_do_open(struct inode *dir, struct path *path, int flags, struct iattr *sattr, struct rpc_cred *cred)
20833 + {
20834 +- struct nfs4_exception exception = { };
20835 ++ struct nfs4_exception exception = {0, 0};
20836 + struct nfs4_state *res;
20837 + int status;
20838 +
20839 +@@ -1181,7 +1181,7 @@ static int nfs4_do_setattr(struct inode
20840 + struct nfs4_state *state)
20841 + {
20842 + struct nfs_server *server = NFS_SERVER(inode);
20843 +- struct nfs4_exception exception = { };
20844 ++ struct nfs4_exception exception = {0, 0};
20845 + int err;
20846 + do {
20847 + err = nfs4_handle_exception(server,
20848 +@@ -1494,7 +1494,7 @@ static int _nfs4_server_capabilities(str
20849 +
20850 + int nfs4_server_capabilities(struct nfs_server *server, struct nfs_fh *fhandle)
20851 + {
20852 +- struct nfs4_exception exception = { };
20853 ++ struct nfs4_exception exception = {0, 0};
20854 + int err;
20855 + do {
20856 + err = nfs4_handle_exception(server,
20857 +@@ -1527,7 +1527,7 @@ static int _nfs4_lookup_root(struct nfs_
20858 + static int nfs4_lookup_root(struct nfs_server *server, struct nfs_fh *fhandle,
20859 + struct nfs_fsinfo *info)
20860 + {
20861 +- struct nfs4_exception exception = { };
20862 ++ struct nfs4_exception exception = {0, 0};
20863 + int err;
20864 + do {
20865 + err = nfs4_handle_exception(server,
20866 +@@ -1616,7 +1616,7 @@ static int _nfs4_proc_getattr(struct nfs
20867 +
20868 + static int nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
20869 + {
20870 +- struct nfs4_exception exception = { };
20871 ++ struct nfs4_exception exception = {0, 0};
20872 + int err;
20873 + do {
20874 + err = nfs4_handle_exception(server,
20875 +@@ -1704,7 +1704,7 @@ static int nfs4_proc_lookupfh(struct nfs
20876 + struct qstr *name, struct nfs_fh *fhandle,
20877 + struct nfs_fattr *fattr)
20878 + {
20879 +- struct nfs4_exception exception = { };
20880 ++ struct nfs4_exception exception = {0, 0};
20881 + int err;
20882 + do {
20883 + err = _nfs4_proc_lookupfh(server, dirfh, name, fhandle, fattr);
20884 +@@ -1733,7 +1733,7 @@ static int _nfs4_proc_lookup(struct inod
20885 +
20886 + static int nfs4_proc_lookup(struct inode *dir, struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr)
20887 + {
20888 +- struct nfs4_exception exception = { };
20889 ++ struct nfs4_exception exception = {0, 0};
20890 + int err;
20891 + do {
20892 + err = nfs4_handle_exception(NFS_SERVER(dir),
20893 +@@ -1797,7 +1797,7 @@ static int _nfs4_proc_access(struct inod
20894 +
20895 + static int nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry)
20896 + {
20897 +- struct nfs4_exception exception = { };
20898 ++ struct nfs4_exception exception = {0, 0};
20899 + int err;
20900 + do {
20901 + err = nfs4_handle_exception(NFS_SERVER(inode),
20902 +@@ -1852,7 +1852,7 @@ static int _nfs4_proc_readlink(struct in
20903 + static int nfs4_proc_readlink(struct inode *inode, struct page *page,
20904 + unsigned int pgbase, unsigned int pglen)
20905 + {
20906 +- struct nfs4_exception exception = { };
20907 ++ struct nfs4_exception exception = {0, 0};
20908 + int err;
20909 + do {
20910 + err = nfs4_handle_exception(NFS_SERVER(inode),
20911 +@@ -1949,7 +1949,7 @@ static int _nfs4_proc_remove(struct inod
20912 +
20913 + static int nfs4_proc_remove(struct inode *dir, struct qstr *name)
20914 + {
20915 +- struct nfs4_exception exception = { };
20916 ++ struct nfs4_exception exception = {0, 0};
20917 + int err;
20918 + do {
20919 + err = nfs4_handle_exception(NFS_SERVER(dir),
20920 +@@ -2021,7 +2021,7 @@ static int _nfs4_proc_rename(struct inod
20921 + static int nfs4_proc_rename(struct inode *old_dir, struct qstr *old_name,
20922 + struct inode *new_dir, struct qstr *new_name)
20923 + {
20924 +- struct nfs4_exception exception = { };
20925 ++ struct nfs4_exception exception = {0, 0};
20926 + int err;
20927 + do {
20928 + err = nfs4_handle_exception(NFS_SERVER(old_dir),
20929 +@@ -2068,7 +2068,7 @@ static int _nfs4_proc_link(struct inode
20930 +
20931 + static int nfs4_proc_link(struct inode *inode, struct inode *dir, struct qstr *name)
20932 + {
20933 +- struct nfs4_exception exception = { };
20934 ++ struct nfs4_exception exception = {0, 0};
20935 + int err;
20936 + do {
20937 + err = nfs4_handle_exception(NFS_SERVER(inode),
20938 +@@ -2159,7 +2159,7 @@ out:
20939 + static int nfs4_proc_symlink(struct inode *dir, struct dentry *dentry,
20940 + struct page *page, unsigned int len, struct iattr *sattr)
20941 + {
20942 +- struct nfs4_exception exception = { };
20943 ++ struct nfs4_exception exception = {0, 0};
20944 + int err;
20945 + do {
20946 + err = nfs4_handle_exception(NFS_SERVER(dir),
20947 +@@ -2190,7 +2190,7 @@ out:
20948 + static int nfs4_proc_mkdir(struct inode *dir, struct dentry *dentry,
20949 + struct iattr *sattr)
20950 + {
20951 +- struct nfs4_exception exception = { };
20952 ++ struct nfs4_exception exception = {0, 0};
20953 + int err;
20954 + do {
20955 + err = nfs4_handle_exception(NFS_SERVER(dir),
20956 +@@ -2239,7 +2239,7 @@ static int _nfs4_proc_readdir(struct den
20957 + static int nfs4_proc_readdir(struct dentry *dentry, struct rpc_cred *cred,
20958 + u64 cookie, struct page *page, unsigned int count, int plus)
20959 + {
20960 +- struct nfs4_exception exception = { };
20961 ++ struct nfs4_exception exception = {0, 0};
20962 + int err;
20963 + do {
20964 + err = nfs4_handle_exception(NFS_SERVER(dentry->d_inode),
20965 +@@ -2287,7 +2287,7 @@ out:
20966 + static int nfs4_proc_mknod(struct inode *dir, struct dentry *dentry,
20967 + struct iattr *sattr, dev_t rdev)
20968 + {
20969 +- struct nfs4_exception exception = { };
20970 ++ struct nfs4_exception exception = {0, 0};
20971 + int err;
20972 + do {
20973 + err = nfs4_handle_exception(NFS_SERVER(dir),
20974 +@@ -2316,7 +2316,7 @@ static int _nfs4_proc_statfs(struct nfs_
20975 +
20976 + static int nfs4_proc_statfs(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsstat *fsstat)
20977 + {
20978 +- struct nfs4_exception exception = { };
20979 ++ struct nfs4_exception exception = {0, 0};
20980 + int err;
20981 + do {
20982 + err = nfs4_handle_exception(server,
20983 +@@ -2344,7 +2344,7 @@ static int _nfs4_do_fsinfo(struct nfs_se
20984 +
20985 + static int nfs4_do_fsinfo(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fsinfo *fsinfo)
20986 + {
20987 +- struct nfs4_exception exception = { };
20988 ++ struct nfs4_exception exception = {0, 0};
20989 + int err;
20990 +
20991 + do {
20992 +@@ -2387,7 +2387,7 @@ static int _nfs4_proc_pathconf(struct nf
20993 + static int nfs4_proc_pathconf(struct nfs_server *server, struct nfs_fh *fhandle,
20994 + struct nfs_pathconf *pathconf)
20995 + {
20996 +- struct nfs4_exception exception = { };
20997 ++ struct nfs4_exception exception = {0, 0};
20998 + int err;
20999 +
21000 + do {
21001 +@@ -2674,7 +2674,7 @@ out_free:
21002 +
21003 + static ssize_t nfs4_get_acl_uncached(struct inode *inode, void *buf, size_t buflen)
21004 + {
21005 +- struct nfs4_exception exception = { };
21006 ++ struct nfs4_exception exception = {0, 0};
21007 + ssize_t ret;
21008 + do {
21009 + ret = __nfs4_get_acl_uncached(inode, buf, buflen);
21010 +@@ -2731,7 +2731,7 @@ static int __nfs4_proc_set_acl(struct in
21011 +
21012 + static int nfs4_proc_set_acl(struct inode *inode, const void *buf, size_t buflen)
21013 + {
21014 +- struct nfs4_exception exception = { };
21015 ++ struct nfs4_exception exception = {0, 0};
21016 + int err;
21017 + do {
21018 + err = nfs4_handle_exception(NFS_SERVER(inode),
21019 +@@ -3022,7 +3022,7 @@ out:
21020 + int nfs4_proc_delegreturn(struct inode *inode, struct rpc_cred *cred, const nfs4_stateid *stateid, int issync)
21021 + {
21022 + struct nfs_server *server = NFS_SERVER(inode);
21023 +- struct nfs4_exception exception = { };
21024 ++ struct nfs4_exception exception = {0, 0};
21025 + int err;
21026 + do {
21027 + err = _nfs4_proc_delegreturn(inode, cred, stateid, issync);
21028 +@@ -3097,7 +3097,7 @@ out:
21029 +
21030 + static int nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock *request)
21031 + {
21032 +- struct nfs4_exception exception = { };
21033 ++ struct nfs4_exception exception = {0, 0};
21034 + int err;
21035 +
21036 + do {
21037 +@@ -3447,7 +3447,7 @@ static int _nfs4_do_setlk(struct nfs4_st
21038 + static int nfs4_lock_reclaim(struct nfs4_state *state, struct file_lock *request)
21039 + {
21040 + struct nfs_server *server = NFS_SERVER(state->inode);
21041 +- struct nfs4_exception exception = { };
21042 ++ struct nfs4_exception exception = {0, 0};
21043 + int err;
21044 +
21045 + do {
21046 +@@ -3465,7 +3465,7 @@ static int nfs4_lock_reclaim(struct nfs4
21047 + static int nfs4_lock_expired(struct nfs4_state *state, struct file_lock *request)
21048 + {
21049 + struct nfs_server *server = NFS_SERVER(state->inode);
21050 +- struct nfs4_exception exception = { };
21051 ++ struct nfs4_exception exception = {0, 0};
21052 + int err;
21053 +
21054 + err = nfs4_set_lock_state(state, request);
21055 +@@ -3526,7 +3526,7 @@ out:
21056 +
21057 + static int nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock *request)
21058 + {
21059 +- struct nfs4_exception exception = { };
21060 ++ struct nfs4_exception exception = {0, 0};
21061 + int err;
21062 +
21063 + do {
21064 +@@ -3576,7 +3576,7 @@ nfs4_proc_lock(struct file *filp, int cm
21065 + int nfs4_lock_delegation_recall(struct nfs4_state *state, struct file_lock *fl)
21066 + {
21067 + struct nfs_server *server = NFS_SERVER(state->inode);
21068 +- struct nfs4_exception exception = { };
21069 ++ struct nfs4_exception exception = {0, 0};
21070 + int err;
21071 +
21072 + err = nfs4_set_lock_state(state, fl);
21073 +diff -urNp linux-2.6.28/fs/nfsd/export.c linux-2.6.28/fs/nfsd/export.c
21074 +--- linux-2.6.28/fs/nfsd/export.c 2008-12-24 18:26:37.000000000 -0500
21075 ++++ linux-2.6.28/fs/nfsd/export.c 2009-01-11 07:20:06.000000000 -0500
21076 +@@ -472,7 +472,7 @@ static int secinfo_parse(char **mesg, ch
21077 + * probably discover the problem when someone fails to
21078 + * authenticate.
21079 + */
21080 +- if (f->pseudoflavor < 0)
21081 ++ if ((s32)f->pseudoflavor < 0)
21082 + return -EINVAL;
21083 + err = get_int(mesg, &f->flags);
21084 + if (err)
21085 +diff -urNp linux-2.6.28/fs/nls/nls_base.c linux-2.6.28/fs/nls/nls_base.c
21086 +--- linux-2.6.28/fs/nls/nls_base.c 2008-12-24 18:26:37.000000000 -0500
21087 ++++ linux-2.6.28/fs/nls/nls_base.c 2009-01-11 07:20:06.000000000 -0500
21088 +@@ -40,7 +40,7 @@ static const struct utf8_table utf8_tabl
21089 + {0xF8, 0xF0, 3*6, 0x1FFFFF, 0x10000, /* 4 byte sequence */},
21090 + {0xFC, 0xF8, 4*6, 0x3FFFFFF, 0x200000, /* 5 byte sequence */},
21091 + {0xFE, 0xFC, 5*6, 0x7FFFFFFF, 0x4000000, /* 6 byte sequence */},
21092 +- {0, /* end of table */}
21093 ++ {0, 0, 0, 0, 0, /* end of table */}
21094 + };
21095 +
21096 + int
21097 +diff -urNp linux-2.6.28/fs/ntfs/file.c linux-2.6.28/fs/ntfs/file.c
21098 +--- linux-2.6.28/fs/ntfs/file.c 2008-12-24 18:26:37.000000000 -0500
21099 ++++ linux-2.6.28/fs/ntfs/file.c 2009-01-11 07:20:06.000000000 -0500
21100 +@@ -2291,6 +2291,6 @@ const struct inode_operations ntfs_file_
21101 + #endif /* NTFS_RW */
21102 + };
21103 +
21104 +-const struct file_operations ntfs_empty_file_ops = {};
21105 ++const struct file_operations ntfs_empty_file_ops;
21106 +
21107 +-const struct inode_operations ntfs_empty_inode_ops = {};
21108 ++const struct inode_operations ntfs_empty_inode_ops;
21109 +diff -urNp linux-2.6.28/fs/open.c linux-2.6.28/fs/open.c
21110 +--- linux-2.6.28/fs/open.c 2008-12-24 18:26:37.000000000 -0500
21111 ++++ linux-2.6.28/fs/open.c 2009-01-11 05:46:58.000000000 -0500
21112 +@@ -29,6 +29,7 @@
21113 + #include <linux/rcupdate.h>
21114 + #include <linux/audit.h>
21115 + #include <linux/falloc.h>
21116 ++#include <linux/grsecurity.h>
21117 +
21118 + int vfs_statfs(struct dentry *dentry, struct kstatfs *buf)
21119 + {
21120 +@@ -207,6 +208,9 @@ int do_truncate(struct dentry *dentry, l
21121 + if (length < 0)
21122 + return -EINVAL;
21123 +
21124 ++ if (filp && !gr_acl_handle_truncate(dentry, filp->f_path.mnt))
21125 ++ return -EACCES;
21126 ++
21127 + newattrs.ia_size = length;
21128 + newattrs.ia_valid = ATTR_SIZE | time_attrs;
21129 + if (filp) {
21130 +@@ -491,6 +495,9 @@ asmlinkage long sys_faccessat(int dfd, c
21131 + if (__mnt_is_readonly(path.mnt))
21132 + res = -EROFS;
21133 +
21134 ++ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
21135 ++ res = -EACCES;
21136 ++
21137 + out_path_release:
21138 + path_put(&path);
21139 + out:
21140 +@@ -521,6 +528,8 @@ asmlinkage long sys_chdir(const char __u
21141 + if (error)
21142 + goto dput_and_out;
21143 +
21144 ++ gr_log_chdir(path.dentry, path.mnt);
21145 ++
21146 + set_fs_pwd(current->fs, &path);
21147 +
21148 + dput_and_out:
21149 +@@ -547,6 +556,13 @@ asmlinkage long sys_fchdir(unsigned int
21150 + goto out_putf;
21151 +
21152 + error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
21153 ++
21154 ++ if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
21155 ++ error = -EPERM;
21156 ++
21157 ++ if (!error)
21158 ++ gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
21159 ++
21160 + if (!error)
21161 + set_fs_pwd(current->fs, &file->f_path);
21162 + out_putf:
21163 +@@ -572,7 +588,14 @@ asmlinkage long sys_chroot(const char __
21164 + if (!capable(CAP_SYS_CHROOT))
21165 + goto dput_and_out;
21166 +
21167 ++ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
21168 ++ goto dput_and_out;
21169 ++
21170 + set_fs_root(current->fs, &path);
21171 ++
21172 ++ gr_handle_chroot_caps(current);
21173 ++ gr_handle_chroot_chdir(&path);
21174 ++
21175 + error = 0;
21176 + dput_and_out:
21177 + path_put(&path);
21178 +@@ -600,13 +623,28 @@ asmlinkage long sys_fchmod(unsigned int
21179 + err = mnt_want_write(file->f_path.mnt);
21180 + if (err)
21181 + goto out_putf;
21182 ++
21183 ++ if (!gr_acl_handle_fchmod(dentry, file->f_path.mnt, mode)) {
21184 ++ err = -EACCES;
21185 ++ goto out_drop_write;
21186 ++ }
21187 ++
21188 + mutex_lock(&inode->i_mutex);
21189 + if (mode == (mode_t) -1)
21190 + mode = inode->i_mode;
21191 ++
21192 ++ if (gr_handle_chroot_chmod(dentry, file->f_path.mnt, mode)) {
21193 ++ err = -EPERM;
21194 ++ mutex_unlock(&inode->i_mutex);
21195 ++ goto out_drop_write;
21196 ++ }
21197 ++
21198 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
21199 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
21200 + err = notify_change(dentry, &newattrs);
21201 + mutex_unlock(&inode->i_mutex);
21202 ++
21203 ++out_drop_write:
21204 + mnt_drop_write(file->f_path.mnt);
21205 + out_putf:
21206 + fput(file);
21207 +@@ -630,13 +668,28 @@ asmlinkage long sys_fchmodat(int dfd, co
21208 + error = mnt_want_write(path.mnt);
21209 + if (error)
21210 + goto dput_and_out;
21211 ++
21212 ++ if (!gr_acl_handle_chmod(path.dentry, path.mnt, mode)) {
21213 ++ error = -EACCES;
21214 ++ goto out_drop_write;
21215 ++ }
21216 ++
21217 + mutex_lock(&inode->i_mutex);
21218 + if (mode == (mode_t) -1)
21219 + mode = inode->i_mode;
21220 ++
21221 ++ if (gr_handle_chroot_chmod(path.dentry, path.mnt, mode)) {
21222 ++ error = -EACCES;
21223 ++ mutex_unlock(&inode->i_mutex);
21224 ++ goto out_drop_write;
21225 ++ }
21226 ++
21227 + newattrs.ia_mode = (mode & S_IALLUGO) | (inode->i_mode & ~S_IALLUGO);
21228 + newattrs.ia_valid = ATTR_MODE | ATTR_CTIME;
21229 + error = notify_change(path.dentry, &newattrs);
21230 + mutex_unlock(&inode->i_mutex);
21231 ++
21232 ++out_drop_write:
21233 + mnt_drop_write(path.mnt);
21234 + dput_and_out:
21235 + path_put(&path);
21236 +@@ -649,12 +702,15 @@ asmlinkage long sys_chmod(const char __u
21237 + return sys_fchmodat(AT_FDCWD, filename, mode);
21238 + }
21239 +
21240 +-static int chown_common(struct dentry * dentry, uid_t user, gid_t group)
21241 ++static int chown_common(struct dentry * dentry, uid_t user, gid_t group, struct vfsmount *mnt)
21242 + {
21243 + struct inode *inode = dentry->d_inode;
21244 + int error;
21245 + struct iattr newattrs;
21246 +
21247 ++ if (!gr_acl_handle_chown(dentry, mnt))
21248 ++ return -EACCES;
21249 ++
21250 + newattrs.ia_valid = ATTR_CTIME;
21251 + if (user != (uid_t) -1) {
21252 + newattrs.ia_valid |= ATTR_UID;
21253 +@@ -685,7 +741,7 @@ asmlinkage long sys_chown(const char __u
21254 + error = mnt_want_write(path.mnt);
21255 + if (error)
21256 + goto out_release;
21257 +- error = chown_common(path.dentry, user, group);
21258 ++ error = chown_common(path.dentry, user, group, path.mnt);
21259 + mnt_drop_write(path.mnt);
21260 + out_release:
21261 + path_put(&path);
21262 +@@ -710,7 +766,7 @@ asmlinkage long sys_fchownat(int dfd, co
21263 + error = mnt_want_write(path.mnt);
21264 + if (error)
21265 + goto out_release;
21266 +- error = chown_common(path.dentry, user, group);
21267 ++ error = chown_common(path.dentry, user, group, path.mnt);
21268 + mnt_drop_write(path.mnt);
21269 + out_release:
21270 + path_put(&path);
21271 +@@ -729,7 +785,7 @@ asmlinkage long sys_lchown(const char __
21272 + error = mnt_want_write(path.mnt);
21273 + if (error)
21274 + goto out_release;
21275 +- error = chown_common(path.dentry, user, group);
21276 ++ error = chown_common(path.dentry, user, group, path.mnt);
21277 + mnt_drop_write(path.mnt);
21278 + out_release:
21279 + path_put(&path);
21280 +@@ -753,7 +809,7 @@ asmlinkage long sys_fchown(unsigned int
21281 + goto out_fput;
21282 + dentry = file->f_path.dentry;
21283 + audit_inode(NULL, dentry);
21284 +- error = chown_common(dentry, user, group);
21285 ++ error = chown_common(dentry, user, group, file->f_path.mnt);
21286 + mnt_drop_write(file->f_path.mnt);
21287 + out_fput:
21288 + fput(file);
21289 +diff -urNp linux-2.6.28/fs/pipe.c linux-2.6.28/fs/pipe.c
21290 +--- linux-2.6.28/fs/pipe.c 2008-12-24 18:26:37.000000000 -0500
21291 ++++ linux-2.6.28/fs/pipe.c 2009-01-11 05:46:58.000000000 -0500
21292 +@@ -848,7 +848,7 @@ void free_pipe_info(struct inode *inode)
21293 + inode->i_pipe = NULL;
21294 + }
21295 +
21296 +-static struct vfsmount *pipe_mnt __read_mostly;
21297 ++struct vfsmount *pipe_mnt __read_mostly;
21298 + static int pipefs_delete_dentry(struct dentry *dentry)
21299 + {
21300 + /*
21301 +diff -urNp linux-2.6.28/fs/proc/array.c linux-2.6.28/fs/proc/array.c
21302 +--- linux-2.6.28/fs/proc/array.c 2008-12-24 18:26:37.000000000 -0500
21303 ++++ linux-2.6.28/fs/proc/array.c 2009-01-11 07:20:06.000000000 -0500
21304 +@@ -308,6 +308,21 @@ static inline void task_context_switch_c
21305 + p->nivcsw);
21306 + }
21307 +
21308 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
21309 ++static inline void task_pax(struct seq_file *m, struct task_struct *p)
21310 ++{
21311 ++ if (p->mm)
21312 ++ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
21313 ++ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
21314 ++ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
21315 ++ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
21316 ++ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
21317 ++ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
21318 ++ else
21319 ++ seq_printf(m, "PaX:\t-----\n");
21320 ++}
21321 ++#endif
21322 ++
21323 + int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
21324 + struct pid *pid, struct task_struct *task)
21325 + {
21326 +@@ -327,9 +342,20 @@ int proc_pid_status(struct seq_file *m,
21327 + task_show_regs(m, task);
21328 + #endif
21329 + task_context_switch_counts(m, task);
21330 ++
21331 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
21332 ++ task_pax(m, task);
21333 ++#endif
21334 ++
21335 + return 0;
21336 + }
21337 +
21338 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21339 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
21340 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
21341 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
21342 ++#endif
21343 ++
21344 + static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
21345 + struct pid *pid, struct task_struct *task, int whole)
21346 + {
21347 +@@ -422,6 +448,19 @@ static int do_task_stat(struct seq_file
21348 + gtime = task_gtime(task);
21349 + }
21350 +
21351 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21352 ++ if (PAX_RAND_FLAGS(mm)) {
21353 ++ eip = 0;
21354 ++ esp = 0;
21355 ++ wchan = 0;
21356 ++ }
21357 ++#endif
21358 ++#ifdef CONFIG_GRKERNSEC_HIDESYM
21359 ++ wchan = 0;
21360 ++ eip =0;
21361 ++ esp =0;
21362 ++#endif
21363 ++
21364 + /* scale priority and nice values from timeslices to -20..20 */
21365 + /* to make it look like a "normal" Unix priority/nice value */
21366 + priority = task_prio(task);
21367 +@@ -462,9 +501,15 @@ static int do_task_stat(struct seq_file
21368 + vsize,
21369 + mm ? get_mm_rss(mm) : 0,
21370 + rsslim,
21371 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21372 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->start_code : 0),
21373 ++ PAX_RAND_FLAGS(mm) ? 1 : (mm ? mm->end_code : 0),
21374 ++ PAX_RAND_FLAGS(mm) ? 0 : (mm ? mm->start_stack : 0),
21375 ++#else
21376 + mm ? mm->start_code : 0,
21377 + mm ? mm->end_code : 0,
21378 + mm ? mm->start_stack : 0,
21379 ++#endif
21380 + esp,
21381 + eip,
21382 + /* The signal information here is obsolete.
21383 +@@ -517,3 +562,10 @@ int proc_pid_statm(struct seq_file *m, s
21384 +
21385 + return 0;
21386 + }
21387 ++
21388 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
21389 ++int proc_pid_ipaddr(struct task_struct *task, char *buffer)
21390 ++{
21391 ++ return sprintf(buffer, "%u.%u.%u.%u\n", NIPQUAD(task->signal->curr_ip));
21392 ++}
21393 ++#endif
21394 +diff -urNp linux-2.6.28/fs/proc/base.c linux-2.6.28/fs/proc/base.c
21395 +--- linux-2.6.28/fs/proc/base.c 2008-12-24 18:26:37.000000000 -0500
21396 ++++ linux-2.6.28/fs/proc/base.c 2009-01-11 07:20:06.000000000 -0500
21397 +@@ -79,6 +79,8 @@
21398 + #include <linux/oom.h>
21399 + #include <linux/elf.h>
21400 + #include <linux/pid_namespace.h>
21401 ++#include <linux/grsecurity.h>
21402 ++
21403 + #include "internal.h"
21404 +
21405 + /* NOTE:
21406 +@@ -225,6 +227,9 @@ static int check_mem_permission(struct t
21407 + if (task == current)
21408 + return 0;
21409 +
21410 ++ if (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))
21411 ++ return -EPERM;
21412 ++
21413 + /*
21414 + * If current is actively ptrace'ing, and would also be
21415 + * permitted to freshly attach with ptrace now, permit it.
21416 +@@ -308,9 +313,9 @@ static int proc_pid_auxv(struct task_str
21417 + struct mm_struct *mm = get_task_mm(task);
21418 + if (mm) {
21419 + unsigned int nwords = 0;
21420 +- do
21421 ++ do {
21422 + nwords += 2;
21423 +- while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
21424 ++ } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
21425 + res = nwords * sizeof(mm->saved_auxv[0]);
21426 + if (res > PAGE_SIZE)
21427 + res = PAGE_SIZE;
21428 +@@ -1429,7 +1434,11 @@ static struct inode *proc_pid_make_inode
21429 + inode->i_gid = 0;
21430 + if (task_dumpable(task)) {
21431 + inode->i_uid = task->euid;
21432 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
21433 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
21434 ++#else
21435 + inode->i_gid = task->egid;
21436 ++#endif
21437 + }
21438 + security_task_to_inode(task, inode);
21439 +
21440 +@@ -1445,17 +1454,45 @@ static int pid_getattr(struct vfsmount *
21441 + {
21442 + struct inode *inode = dentry->d_inode;
21443 + struct task_struct *task;
21444 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21445 ++ struct task_struct *tmp = current;
21446 ++#endif
21447 ++
21448 + generic_fillattr(inode, stat);
21449 +
21450 + rcu_read_lock();
21451 + stat->uid = 0;
21452 + stat->gid = 0;
21453 + task = pid_task(proc_pid(inode), PIDTYPE_PID);
21454 +- if (task) {
21455 ++
21456 ++ if (task && (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))) {
21457 ++ rcu_read_unlock();
21458 ++ return -ENOENT;
21459 ++ }
21460 ++
21461 ++
21462 ++ if (task
21463 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21464 ++ && (!tmp->uid || (tmp->uid == task->uid)
21465 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
21466 ++ || in_group_p(CONFIG_GRKERNSEC_PROC_GID)
21467 ++#endif
21468 ++ )
21469 ++#endif
21470 ++ ) {
21471 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
21472 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
21473 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
21474 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21475 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
21476 ++#endif
21477 + task_dumpable(task)) {
21478 + stat->uid = task->euid;
21479 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
21480 ++ stat->gid = CONFIG_GRKERNSEC_PROC_GID;
21481 ++#else
21482 + stat->gid = task->egid;
21483 ++#endif
21484 + }
21485 + }
21486 + rcu_read_unlock();
21487 +@@ -1483,11 +1520,21 @@ static int pid_revalidate(struct dentry
21488 + {
21489 + struct inode *inode = dentry->d_inode;
21490 + struct task_struct *task = get_proc_task(inode);
21491 ++
21492 + if (task) {
21493 + if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
21494 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
21495 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
21496 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21497 ++ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
21498 ++#endif
21499 + task_dumpable(task)) {
21500 + inode->i_uid = task->euid;
21501 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
21502 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
21503 ++#else
21504 + inode->i_gid = task->egid;
21505 ++#endif
21506 + } else {
21507 + inode->i_uid = 0;
21508 + inode->i_gid = 0;
21509 +@@ -1855,12 +1902,22 @@ static const struct file_operations proc
21510 + static int proc_fd_permission(struct inode *inode, int mask)
21511 + {
21512 + int rv;
21513 ++ struct task_struct *task;
21514 +
21515 + rv = generic_permission(inode, mask, NULL);
21516 +- if (rv == 0)
21517 +- return 0;
21518 ++
21519 + if (task_pid(current) == proc_pid(inode))
21520 + rv = 0;
21521 ++
21522 ++ task = get_proc_task(inode);
21523 ++ if (task == NULL)
21524 ++ return rv;
21525 ++
21526 ++ if (gr_acl_handle_procpidmem(task))
21527 ++ rv = -EACCES;
21528 ++
21529 ++ put_task_struct(task);
21530 ++
21531 + return rv;
21532 + }
21533 +
21534 +@@ -1971,6 +2028,9 @@ static struct dentry *proc_pident_lookup
21535 + if (!task)
21536 + goto out_no_task;
21537 +
21538 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
21539 ++ goto out;
21540 ++
21541 + /*
21542 + * Yes, it does not scale. And it should not. Don't add
21543 + * new entries into /proc/<tgid>/ without very good reasons.
21544 +@@ -2015,6 +2075,9 @@ static int proc_pident_readdir(struct fi
21545 + if (!task)
21546 + goto out_no_task;
21547 +
21548 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
21549 ++ goto out;
21550 ++
21551 + ret = 0;
21552 + i = filp->f_pos;
21553 + switch (i) {
21554 +@@ -2377,6 +2440,9 @@ static struct dentry *proc_base_lookup(s
21555 + if (p > last)
21556 + goto out;
21557 +
21558 ++ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
21559 ++ goto out;
21560 ++
21561 + error = proc_base_instantiate(dir, dentry, task, p);
21562 +
21563 + out:
21564 +@@ -2518,6 +2584,9 @@ static const struct pid_entry tgid_base_
21565 + #ifdef CONFIG_TASK_IO_ACCOUNTING
21566 + INF("io", S_IRUGO, tgid_io_accounting),
21567 + #endif
21568 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
21569 ++ INF("ipaddr", S_IRUSR, pid_ipaddr),
21570 ++#endif
21571 + };
21572 +
21573 + static int proc_tgid_base_readdir(struct file * filp,
21574 +@@ -2647,7 +2716,14 @@ static struct dentry *proc_pid_instantia
21575 + if (!inode)
21576 + goto out;
21577 +
21578 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
21579 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
21580 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21581 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
21582 ++ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
21583 ++#else
21584 + inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
21585 ++#endif
21586 + inode->i_op = &proc_tgid_base_inode_operations;
21587 + inode->i_fop = &proc_tgid_base_operations;
21588 + inode->i_flags|=S_IMMUTABLE;
21589 +@@ -2689,7 +2765,11 @@ struct dentry *proc_pid_lookup(struct in
21590 + if (!task)
21591 + goto out;
21592 +
21593 ++ if (gr_check_hidden_task(task))
21594 ++ goto out_put_task;
21595 ++
21596 + result = proc_pid_instantiate(dir, dentry, task, NULL);
21597 ++out_put_task:
21598 + put_task_struct(task);
21599 + out:
21600 + return result;
21601 +@@ -2754,6 +2834,9 @@ int proc_pid_readdir(struct file * filp,
21602 + {
21603 + unsigned int nr = filp->f_pos - FIRST_PROCESS_ENTRY;
21604 + struct task_struct *reaper = get_proc_task(filp->f_path.dentry->d_inode);
21605 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21606 ++ struct task_struct *tmp = current;
21607 ++#endif
21608 + struct tgid_iter iter;
21609 + struct pid_namespace *ns;
21610 +
21611 +@@ -2772,6 +2855,17 @@ int proc_pid_readdir(struct file * filp,
21612 + for (iter = next_tgid(ns, iter);
21613 + iter.task;
21614 + iter.tgid += 1, iter = next_tgid(ns, iter)) {
21615 ++ if (gr_pid_is_chrooted(iter.task) || gr_check_hidden_task(iter.task)
21616 ++#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21617 ++ || (tmp->uid && (iter.task->uid != tmp->uid)
21618 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
21619 ++ && !in_group_p(CONFIG_GRKERNSEC_PROC_GID)
21620 ++#endif
21621 ++ )
21622 ++#endif
21623 ++ )
21624 ++ continue;
21625 ++
21626 + filp->f_pos = iter.tgid + TGID_OFFSET;
21627 + if (proc_pid_fill_cache(filp, dirent, filldir, iter) < 0) {
21628 + put_task_struct(iter.task);
21629 +diff -urNp linux-2.6.28/fs/proc/cmdline.c linux-2.6.28/fs/proc/cmdline.c
21630 +--- linux-2.6.28/fs/proc/cmdline.c 2008-12-24 18:26:37.000000000 -0500
21631 ++++ linux-2.6.28/fs/proc/cmdline.c 2009-01-11 07:11:34.000000000 -0500
21632 +@@ -23,7 +23,11 @@ static const struct file_operations cmdl
21633 +
21634 + static int __init proc_cmdline_init(void)
21635 + {
21636 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
21637 ++ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
21638 ++#else
21639 + proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
21640 ++#endif
21641 + return 0;
21642 + }
21643 + module_init(proc_cmdline_init);
21644 +diff -urNp linux-2.6.28/fs/proc/devices.c linux-2.6.28/fs/proc/devices.c
21645 +--- linux-2.6.28/fs/proc/devices.c 2008-12-24 18:26:37.000000000 -0500
21646 ++++ linux-2.6.28/fs/proc/devices.c 2009-01-11 07:12:12.000000000 -0500
21647 +@@ -64,7 +64,11 @@ static const struct file_operations proc
21648 +
21649 + static int __init proc_devices_init(void)
21650 + {
21651 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
21652 ++ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
21653 ++#else
21654 + proc_create("devices", 0, NULL, &proc_devinfo_operations);
21655 ++#endif
21656 + return 0;
21657 + }
21658 + module_init(proc_devices_init);
21659 +diff -urNp linux-2.6.28/fs/proc/inode.c linux-2.6.28/fs/proc/inode.c
21660 +--- linux-2.6.28/fs/proc/inode.c 2008-12-24 18:26:37.000000000 -0500
21661 ++++ linux-2.6.28/fs/proc/inode.c 2009-01-11 05:46:58.000000000 -0500
21662 +@@ -466,7 +466,11 @@ struct inode *proc_get_inode(struct supe
21663 + if (de->mode) {
21664 + inode->i_mode = de->mode;
21665 + inode->i_uid = de->uid;
21666 ++#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
21667 ++ inode->i_gid = CONFIG_GRKERNSEC_PROC_GID;
21668 ++#else
21669 + inode->i_gid = de->gid;
21670 ++#endif
21671 + }
21672 + if (de->size)
21673 + inode->i_size = de->size;
21674 +diff -urNp linux-2.6.28/fs/proc/internal.h linux-2.6.28/fs/proc/internal.h
21675 +--- linux-2.6.28/fs/proc/internal.h 2008-12-24 18:26:37.000000000 -0500
21676 ++++ linux-2.6.28/fs/proc/internal.h 2009-01-11 05:46:58.000000000 -0500
21677 +@@ -53,6 +53,9 @@ extern int proc_pid_status(struct seq_fi
21678 + struct pid *pid, struct task_struct *task);
21679 + extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
21680 + struct pid *pid, struct task_struct *task);
21681 ++#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
21682 ++extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
21683 ++#endif
21684 + extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
21685 +
21686 + extern const struct file_operations proc_maps_operations;
21687 +diff -urNp linux-2.6.28/fs/proc/Kconfig linux-2.6.28/fs/proc/Kconfig
21688 +--- linux-2.6.28/fs/proc/Kconfig 2008-12-24 18:26:37.000000000 -0500
21689 ++++ linux-2.6.28/fs/proc/Kconfig 2009-01-11 06:01:07.000000000 -0500
21690 +@@ -30,12 +30,12 @@ config PROC_FS
21691 +
21692 + config PROC_KCORE
21693 + bool "/proc/kcore support" if !ARM
21694 +- depends on PROC_FS && MMU
21695 ++ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
21696 +
21697 + config PROC_VMCORE
21698 + bool "/proc/vmcore support (EXPERIMENTAL)"
21699 +- depends on PROC_FS && CRASH_DUMP
21700 +- default y
21701 ++ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
21702 ++ default n
21703 + help
21704 + Exports the dump image of crashed kernel in ELF format.
21705 +
21706 +@@ -59,8 +59,8 @@ config PROC_SYSCTL
21707 + limited in memory.
21708 +
21709 + config PROC_PAGE_MONITOR
21710 +- default y
21711 +- depends on PROC_FS && MMU
21712 ++ default n
21713 ++ depends on PROC_FS && MMU && !GRKERNSEC
21714 + bool "Enable /proc page monitoring" if EMBEDDED
21715 + help
21716 + Various /proc files exist to monitor process memory utilization:
21717 +diff -urNp linux-2.6.28/fs/proc/kcore.c linux-2.6.28/fs/proc/kcore.c
21718 +--- linux-2.6.28/fs/proc/kcore.c 2008-12-24 18:26:37.000000000 -0500
21719 ++++ linux-2.6.28/fs/proc/kcore.c 2009-01-11 07:16:00.000000000 -0500
21720 +@@ -404,10 +404,12 @@ read_kcore(struct file *file, char __use
21721 +
21722 + static int __init proc_kcore_init(void)
21723 + {
21724 ++#if !defined(CONFIG_GRKERNSEC_PROC_ADD)
21725 + proc_root_kcore = proc_create("kcore", S_IRUSR, NULL, &proc_kcore_operations);
21726 + if (proc_root_kcore)
21727 + proc_root_kcore->size =
21728 + (size_t)high_memory - PAGE_OFFSET + PAGE_SIZE;
21729 ++#endif
21730 + return 0;
21731 + }
21732 + module_init(proc_kcore_init);
21733 +diff -urNp linux-2.6.28/fs/proc/proc_net.c linux-2.6.28/fs/proc/proc_net.c
21734 +--- linux-2.6.28/fs/proc/proc_net.c 2008-12-24 18:26:37.000000000 -0500
21735 ++++ linux-2.6.28/fs/proc/proc_net.c 2009-01-11 05:47:03.000000000 -0500
21736 +@@ -106,6 +106,14 @@ static struct net *get_proc_task_net(str
21737 + struct nsproxy *ns;
21738 + struct net *net = NULL;
21739 +
21740 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
21741 ++ if (current->fsuid)
21742 ++ return net;
21743 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21744 ++ if (current->fsuid && !in_group_p(CONFIG_GRKERNSEC_PROC_GID))
21745 ++ return net;
21746 ++#endif
21747 ++
21748 + rcu_read_lock();
21749 + task = pid_task(proc_pid(dir), PIDTYPE_PID);
21750 + if (task != NULL) {
21751 +diff -urNp linux-2.6.28/fs/proc/proc_sysctl.c linux-2.6.28/fs/proc/proc_sysctl.c
21752 +--- linux-2.6.28/fs/proc/proc_sysctl.c 2008-12-24 18:26:37.000000000 -0500
21753 ++++ linux-2.6.28/fs/proc/proc_sysctl.c 2009-01-11 05:47:03.000000000 -0500
21754 +@@ -7,6 +7,8 @@
21755 + #include <linux/security.h>
21756 + #include "internal.h"
21757 +
21758 ++extern __u32 gr_handle_sysctl(const struct ctl_table *table, const int op);
21759 ++
21760 + static struct dentry_operations proc_sys_dentry_operations;
21761 + static const struct file_operations proc_sys_file_operations;
21762 + static const struct inode_operations proc_sys_inode_operations;
21763 +@@ -110,6 +112,9 @@ static struct dentry *proc_sys_lookup(st
21764 + if (!p)
21765 + goto out;
21766 +
21767 ++ if (gr_handle_sysctl(p, MAY_EXEC))
21768 ++ goto out;
21769 ++
21770 + err = ERR_PTR(-ENOMEM);
21771 + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p);
21772 + if (h)
21773 +@@ -229,6 +234,9 @@ static int scan(struct ctl_table_header
21774 + if (*pos < file->f_pos)
21775 + continue;
21776 +
21777 ++ if (gr_handle_sysctl(table, 0))
21778 ++ continue;
21779 ++
21780 + res = proc_sys_fill_cache(file, dirent, filldir, head, table);
21781 + if (res)
21782 + return res;
21783 +@@ -345,6 +353,9 @@ static int proc_sys_getattr(struct vfsmo
21784 + if (IS_ERR(head))
21785 + return PTR_ERR(head);
21786 +
21787 ++ if (table && gr_handle_sysctl(table, MAY_EXEC))
21788 ++ return -ENOENT;
21789 ++
21790 + generic_fillattr(inode, stat);
21791 + if (table)
21792 + stat->mode = (stat->mode & S_IFMT) | table->mode;
21793 +diff -urNp linux-2.6.28/fs/proc/root.c linux-2.6.28/fs/proc/root.c
21794 +--- linux-2.6.28/fs/proc/root.c 2008-12-24 18:26:37.000000000 -0500
21795 ++++ linux-2.6.28/fs/proc/root.c 2009-01-11 05:47:03.000000000 -0500
21796 +@@ -135,7 +135,15 @@ void __init proc_root_init(void)
21797 + #ifdef CONFIG_PROC_DEVICETREE
21798 + proc_device_tree_init();
21799 + #endif
21800 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
21801 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
21802 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
21803 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
21804 ++ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
21805 ++#endif
21806 ++#else
21807 + proc_mkdir("bus", NULL);
21808 ++#endif
21809 + proc_sys_init();
21810 + }
21811 +
21812 +diff -urNp linux-2.6.28/fs/proc/task_mmu.c linux-2.6.28/fs/proc/task_mmu.c
21813 +--- linux-2.6.28/fs/proc/task_mmu.c 2008-12-24 18:26:37.000000000 -0500
21814 ++++ linux-2.6.28/fs/proc/task_mmu.c 2009-01-11 07:20:06.000000000 -0500
21815 +@@ -46,15 +46,26 @@ void task_mem(struct seq_file *m, struct
21816 + "VmStk:\t%8lu kB\n"
21817 + "VmExe:\t%8lu kB\n"
21818 + "VmLib:\t%8lu kB\n"
21819 +- "VmPTE:\t%8lu kB\n",
21820 +- hiwater_vm << (PAGE_SHIFT-10),
21821 ++ "VmPTE:\t%8lu kB\n"
21822 ++
21823 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
21824 ++ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
21825 ++#endif
21826 ++
21827 ++ ,hiwater_vm << (PAGE_SHIFT-10),
21828 + (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
21829 + mm->locked_vm << (PAGE_SHIFT-10),
21830 + hiwater_rss << (PAGE_SHIFT-10),
21831 + total_rss << (PAGE_SHIFT-10),
21832 + data << (PAGE_SHIFT-10),
21833 + mm->stack_vm << (PAGE_SHIFT-10), text, lib,
21834 +- (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
21835 ++ (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10
21836 ++
21837 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
21838 ++ , mm->context.user_cs_base, mm->context.user_cs_limit
21839 ++#endif
21840 ++
21841 ++ );
21842 + }
21843 +
21844 + unsigned long task_vsize(struct mm_struct *mm)
21845 +@@ -198,6 +209,12 @@ static int do_maps_open(struct inode *in
21846 + return ret;
21847 + }
21848 +
21849 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21850 ++#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
21851 ++ (_mm->pax_flags & MF_PAX_RANDMMAP || \
21852 ++ _mm->pax_flags & MF_PAX_SEGMEXEC))
21853 ++#endif
21854 ++
21855 + static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma)
21856 + {
21857 + struct mm_struct *mm = vma->vm_mm;
21858 +@@ -214,13 +231,22 @@ static void show_map_vma(struct seq_file
21859 + }
21860 +
21861 + seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
21862 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21863 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start,
21864 ++ PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end,
21865 ++#else
21866 + vma->vm_start,
21867 + vma->vm_end,
21868 ++#endif
21869 + flags & VM_READ ? 'r' : '-',
21870 + flags & VM_WRITE ? 'w' : '-',
21871 + flags & VM_EXEC ? 'x' : '-',
21872 + flags & VM_MAYSHARE ? 's' : 'p',
21873 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21874 ++ PAX_RAND_FLAGS(mm) ? 0UL : ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
21875 ++#else
21876 + ((loff_t)vma->vm_pgoff) << PAGE_SHIFT,
21877 ++#endif
21878 + MAJOR(dev), MINOR(dev), ino, &len);
21879 +
21880 + /*
21881 +@@ -234,11 +260,11 @@ static void show_map_vma(struct seq_file
21882 + const char *name = arch_vma_name(vma);
21883 + if (!name) {
21884 + if (mm) {
21885 +- if (vma->vm_start <= mm->start_brk &&
21886 +- vma->vm_end >= mm->brk) {
21887 ++ if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
21888 + name = "[heap]";
21889 +- } else if (vma->vm_start <= mm->start_stack &&
21890 +- vma->vm_end >= mm->start_stack) {
21891 ++ } else if ((vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
21892 ++ (vma->vm_start <= mm->start_stack &&
21893 ++ vma->vm_end >= mm->start_stack)) {
21894 + name = "[stack]";
21895 + }
21896 + } else {
21897 +@@ -381,9 +407,16 @@ static int show_smap(struct seq_file *m,
21898 + };
21899 +
21900 + memset(&mss, 0, sizeof mss);
21901 +- mss.vma = vma;
21902 +- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
21903 +- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
21904 ++
21905 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21906 ++ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
21907 ++#endif
21908 ++ mss.vma = vma;
21909 ++ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
21910 ++ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
21911 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21912 ++ }
21913 ++#endif
21914 +
21915 + show_map_vma(m, vma);
21916 +
21917 +@@ -397,7 +430,11 @@ static int show_smap(struct seq_file *m,
21918 + "Private_Dirty: %8lu kB\n"
21919 + "Referenced: %8lu kB\n"
21920 + "Swap: %8lu kB\n",
21921 ++#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
21922 ++ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
21923 ++#else
21924 + (vma->vm_end - vma->vm_start) >> 10,
21925 ++#endif
21926 + mss.resident >> 10,
21927 + (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
21928 + mss.shared_clean >> 10,
21929 +diff -urNp linux-2.6.28/fs/readdir.c linux-2.6.28/fs/readdir.c
21930 +--- linux-2.6.28/fs/readdir.c 2008-12-24 18:26:37.000000000 -0500
21931 ++++ linux-2.6.28/fs/readdir.c 2009-01-11 05:47:03.000000000 -0500
21932 +@@ -16,6 +16,8 @@
21933 + #include <linux/security.h>
21934 + #include <linux/syscalls.h>
21935 + #include <linux/unistd.h>
21936 ++#include <linux/namei.h>
21937 ++#include <linux/grsecurity.h>
21938 +
21939 + #include <asm/uaccess.h>
21940 +
21941 +@@ -67,6 +69,7 @@ struct old_linux_dirent {
21942 +
21943 + struct readdir_callback {
21944 + struct old_linux_dirent __user * dirent;
21945 ++ struct file * file;
21946 + int result;
21947 + };
21948 +
21949 +@@ -84,6 +87,10 @@ static int fillonedir(void * __buf, cons
21950 + buf->result = -EOVERFLOW;
21951 + return -EOVERFLOW;
21952 + }
21953 ++
21954 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
21955 ++ return 0;
21956 ++
21957 + buf->result++;
21958 + dirent = buf->dirent;
21959 + if (!access_ok(VERIFY_WRITE, dirent,
21960 +@@ -115,6 +122,7 @@ asmlinkage long old_readdir(unsigned int
21961 +
21962 + buf.result = 0;
21963 + buf.dirent = dirent;
21964 ++ buf.file = file;
21965 +
21966 + error = vfs_readdir(file, fillonedir, &buf);
21967 + if (buf.result)
21968 +@@ -141,6 +149,7 @@ struct linux_dirent {
21969 + struct getdents_callback {
21970 + struct linux_dirent __user * current_dir;
21971 + struct linux_dirent __user * previous;
21972 ++ struct file * file;
21973 + int count;
21974 + int error;
21975 + };
21976 +@@ -161,6 +170,10 @@ static int filldir(void * __buf, const c
21977 + buf->error = -EOVERFLOW;
21978 + return -EOVERFLOW;
21979 + }
21980 ++
21981 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
21982 ++ return 0;
21983 ++
21984 + dirent = buf->previous;
21985 + if (dirent) {
21986 + if (__put_user(offset, &dirent->d_off))
21987 +@@ -207,6 +220,7 @@ asmlinkage long sys_getdents(unsigned in
21988 + buf.previous = NULL;
21989 + buf.count = count;
21990 + buf.error = 0;
21991 ++ buf.file = file;
21992 +
21993 + error = vfs_readdir(file, filldir, &buf);
21994 + if (error >= 0)
21995 +@@ -226,6 +240,7 @@ out:
21996 + struct getdents_callback64 {
21997 + struct linux_dirent64 __user * current_dir;
21998 + struct linux_dirent64 __user * previous;
21999 ++ struct file *file;
22000 + int count;
22001 + int error;
22002 + };
22003 +@@ -240,6 +255,10 @@ static int filldir64(void * __buf, const
22004 + buf->error = -EINVAL; /* only used if we fail.. */
22005 + if (reclen > buf->count)
22006 + return -EINVAL;
22007 ++
22008 ++ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
22009 ++ return 0;
22010 ++
22011 + dirent = buf->previous;
22012 + if (dirent) {
22013 + if (__put_user(offset, &dirent->d_off))
22014 +@@ -286,6 +305,7 @@ asmlinkage long sys_getdents64(unsigned
22015 +
22016 + buf.current_dir = dirent;
22017 + buf.previous = NULL;
22018 ++ buf.file = file;
22019 + buf.count = count;
22020 + buf.error = 0;
22021 +
22022 +diff -urNp linux-2.6.28/fs/select.c linux-2.6.28/fs/select.c
22023 +--- linux-2.6.28/fs/select.c 2008-12-24 18:26:37.000000000 -0500
22024 ++++ linux-2.6.28/fs/select.c 2009-01-11 05:53:29.000000000 -0500
22025 +@@ -25,6 +25,7 @@
22026 + #include <linux/fs.h>
22027 + #include <linux/rcupdate.h>
22028 + #include <linux/hrtimer.h>
22029 ++#include <linux/grsecurity.h>
22030 +
22031 + #include <asm/uaccess.h>
22032 +
22033 +@@ -732,6 +733,7 @@ int do_sys_poll(struct pollfd __user *uf
22034 + struct poll_list *walk = head;
22035 + unsigned long todo = nfds;
22036 +
22037 ++ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
22038 + if (nfds > current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
22039 + return -EINVAL;
22040 +
22041 +diff -urNp linux-2.6.28/fs/smbfs/symlink.c linux-2.6.28/fs/smbfs/symlink.c
22042 +--- linux-2.6.28/fs/smbfs/symlink.c 2008-12-24 18:26:37.000000000 -0500
22043 ++++ linux-2.6.28/fs/smbfs/symlink.c 2009-01-11 07:20:06.000000000 -0500
22044 +@@ -55,7 +55,7 @@ static void *smb_follow_link(struct dent
22045 +
22046 + static void smb_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
22047 + {
22048 +- char *s = nd_get_link(nd);
22049 ++ const char *s = nd_get_link(nd);
22050 + if (!IS_ERR(s))
22051 + __putname(s);
22052 + }
22053 +diff -urNp linux-2.6.28/fs/sysfs/symlink.c linux-2.6.28/fs/sysfs/symlink.c
22054 +--- linux-2.6.28/fs/sysfs/symlink.c 2008-12-24 18:26:37.000000000 -0500
22055 ++++ linux-2.6.28/fs/sysfs/symlink.c 2009-01-11 07:20:06.000000000 -0500
22056 +@@ -200,7 +200,7 @@ static void *sysfs_follow_link(struct de
22057 +
22058 + static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
22059 + {
22060 +- char *page = nd_get_link(nd);
22061 ++ const char *page = nd_get_link(nd);
22062 + if (!IS_ERR(page))
22063 + free_page((unsigned long)page);
22064 + }
22065 +diff -urNp linux-2.6.28/fs/udf/balloc.c linux-2.6.28/fs/udf/balloc.c
22066 +--- linux-2.6.28/fs/udf/balloc.c 2008-12-24 18:26:37.000000000 -0500
22067 ++++ linux-2.6.28/fs/udf/balloc.c 2009-01-11 07:20:06.000000000 -0500
22068 +@@ -169,9 +169,7 @@ static void udf_bitmap_free_blocks(struc
22069 + unsigned long overflow;
22070 +
22071 + mutex_lock(&sbi->s_alloc_mutex);
22072 +- if (bloc.logicalBlockNum < 0 ||
22073 +- (bloc.logicalBlockNum + count) >
22074 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
22075 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
22076 + udf_debug("%d < %d || %d + %d > %d\n",
22077 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
22078 + sbi->s_partmaps[bloc.partitionReferenceNum].
22079 +@@ -239,7 +237,7 @@ static int udf_bitmap_prealloc_blocks(st
22080 +
22081 + mutex_lock(&sbi->s_alloc_mutex);
22082 + part_len = sbi->s_partmaps[partition].s_partition_len;
22083 +- if (first_block < 0 || first_block >= part_len)
22084 ++ if (first_block >= part_len)
22085 + goto out;
22086 +
22087 + if (first_block + block_count > part_len)
22088 +@@ -300,7 +298,7 @@ static int udf_bitmap_new_block(struct s
22089 + mutex_lock(&sbi->s_alloc_mutex);
22090 +
22091 + repeat:
22092 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
22093 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
22094 + goal = 0;
22095 +
22096 + nr_groups = bitmap->s_nr_groups;
22097 +@@ -438,9 +436,7 @@ static void udf_table_free_blocks(struct
22098 + struct udf_inode_info *iinfo;
22099 +
22100 + mutex_lock(&sbi->s_alloc_mutex);
22101 +- if (bloc.logicalBlockNum < 0 ||
22102 +- (bloc.logicalBlockNum + count) >
22103 +- sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
22104 ++ if (bloc.logicalBlockNum + count > sbi->s_partmaps[bloc.partitionReferenceNum].s_partition_len) {
22105 + udf_debug("%d < %d || %d + %d > %d\n",
22106 + bloc.logicalBlockNum, 0, bloc.logicalBlockNum, count,
22107 + sbi->s_partmaps[bloc.partitionReferenceNum].
22108 +@@ -671,8 +667,7 @@ static int udf_table_prealloc_blocks(str
22109 + int8_t etype = -1;
22110 + struct udf_inode_info *iinfo;
22111 +
22112 +- if (first_block < 0 ||
22113 +- first_block >= sbi->s_partmaps[partition].s_partition_len)
22114 ++ if (first_block >= sbi->s_partmaps[partition].s_partition_len)
22115 + return 0;
22116 +
22117 + iinfo = UDF_I(table);
22118 +@@ -750,7 +745,7 @@ static int udf_table_new_block(struct su
22119 + return newblock;
22120 +
22121 + mutex_lock(&sbi->s_alloc_mutex);
22122 +- if (goal < 0 || goal >= sbi->s_partmaps[partition].s_partition_len)
22123 ++ if (goal >= sbi->s_partmaps[partition].s_partition_len)
22124 + goal = 0;
22125 +
22126 + /* We search for the closest matching block to goal. If we find
22127 +diff -urNp linux-2.6.28/fs/ufs/inode.c linux-2.6.28/fs/ufs/inode.c
22128 +--- linux-2.6.28/fs/ufs/inode.c 2008-12-24 18:26:37.000000000 -0500
22129 ++++ linux-2.6.28/fs/ufs/inode.c 2009-01-11 07:20:06.000000000 -0500
22130 +@@ -56,9 +56,7 @@ static int ufs_block_to_path(struct inod
22131 +
22132 +
22133 + UFSD("ptrs=uspi->s_apb = %d,double_blocks=%ld \n",ptrs,double_blocks);
22134 +- if (i_block < 0) {
22135 +- ufs_warning(inode->i_sb, "ufs_block_to_path", "block < 0");
22136 +- } else if (i_block < direct_blocks) {
22137 ++ if (i_block < direct_blocks) {
22138 + offsets[n++] = i_block;
22139 + } else if ((i_block -= direct_blocks) < indirect_blocks) {
22140 + offsets[n++] = UFS_IND_BLOCK;
22141 +@@ -440,8 +438,6 @@ int ufs_getfrag_block(struct inode *inod
22142 + lock_kernel();
22143 +
22144 + UFSD("ENTER, ino %lu, fragment %llu\n", inode->i_ino, (unsigned long long)fragment);
22145 +- if (fragment < 0)
22146 +- goto abort_negative;
22147 + if (fragment >
22148 + ((UFS_NDADDR + uspi->s_apb + uspi->s_2apb + uspi->s_3apb)
22149 + << uspi->s_fpbshift))
22150 +@@ -504,10 +500,6 @@ abort:
22151 + unlock_kernel();
22152 + return err;
22153 +
22154 +-abort_negative:
22155 +- ufs_warning(sb, "ufs_get_block", "block < 0");
22156 +- goto abort;
22157 +-
22158 + abort_too_big:
22159 + ufs_warning(sb, "ufs_get_block", "block > big");
22160 + goto abort;
22161 +diff -urNp linux-2.6.28/fs/utimes.c linux-2.6.28/fs/utimes.c
22162 +--- linux-2.6.28/fs/utimes.c 2008-12-24 18:26:37.000000000 -0500
22163 ++++ linux-2.6.28/fs/utimes.c 2009-01-11 05:47:03.000000000 -0500
22164 +@@ -8,6 +8,7 @@
22165 + #include <linux/stat.h>
22166 + #include <linux/utime.h>
22167 + #include <linux/syscalls.h>
22168 ++#include <linux/grsecurity.h>
22169 + #include <asm/uaccess.h>
22170 + #include <asm/unistd.h>
22171 +
22172 +@@ -101,6 +102,12 @@ static int utimes_common(struct path *pa
22173 + goto mnt_drop_write_and_out;
22174 + }
22175 + }
22176 ++
22177 ++ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
22178 ++ error = -EACCES;
22179 ++ goto mnt_drop_write_and_out;
22180 ++ }
22181 ++
22182 + mutex_lock(&inode->i_mutex);
22183 + error = notify_change(path->dentry, &newattrs);
22184 + mutex_unlock(&inode->i_mutex);
22185 +diff -urNp linux-2.6.28/fs/xfs/linux-2.6/xfs_iops.c linux-2.6.28/fs/xfs/linux-2.6/xfs_iops.c
22186 +--- linux-2.6.28/fs/xfs/linux-2.6/xfs_iops.c 2008-12-24 18:26:37.000000000 -0500
22187 ++++ linux-2.6.28/fs/xfs/linux-2.6/xfs_iops.c 2009-01-11 07:20:06.000000000 -0500
22188 +@@ -500,7 +500,7 @@ xfs_vn_put_link(
22189 + struct nameidata *nd,
22190 + void *p)
22191 + {
22192 +- char *s = nd_get_link(nd);
22193 ++ const char *s = nd_get_link(nd);
22194 +
22195 + if (!IS_ERR(s))
22196 + kfree(s);
22197 +diff -urNp linux-2.6.28/fs/xfs/xfs_bmap.c linux-2.6.28/fs/xfs/xfs_bmap.c
22198 +--- linux-2.6.28/fs/xfs/xfs_bmap.c 2008-12-24 18:26:37.000000000 -0500
22199 ++++ linux-2.6.28/fs/xfs/xfs_bmap.c 2009-01-11 07:20:06.000000000 -0500
22200 +@@ -360,7 +360,7 @@ xfs_bmap_validate_ret(
22201 + int nmap,
22202 + int ret_nmap);
22203 + #else
22204 +-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
22205 ++#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
22206 + #endif /* DEBUG */
22207 +
22208 + #if defined(XFS_RW_TRACE)
22209 +diff -urNp linux-2.6.28/grsecurity/gracl_alloc.c linux-2.6.28/grsecurity/gracl_alloc.c
22210 +--- linux-2.6.28/grsecurity/gracl_alloc.c 1969-12-31 19:00:00.000000000 -0500
22211 ++++ linux-2.6.28/grsecurity/gracl_alloc.c 2009-01-11 05:47:03.000000000 -0500
22212 +@@ -0,0 +1,91 @@
22213 ++#include <linux/kernel.h>
22214 ++#include <linux/mm.h>
22215 ++#include <linux/slab.h>
22216 ++#include <linux/vmalloc.h>
22217 ++#include <linux/gracl.h>
22218 ++#include <linux/grsecurity.h>
22219 ++
22220 ++static unsigned long alloc_stack_next = 1;
22221 ++static unsigned long alloc_stack_size = 1;
22222 ++static void **alloc_stack;
22223 ++
22224 ++static __inline__ int
22225 ++alloc_pop(void)
22226 ++{
22227 ++ if (alloc_stack_next == 1)
22228 ++ return 0;
22229 ++
22230 ++ kfree(alloc_stack[alloc_stack_next - 2]);
22231 ++
22232 ++ alloc_stack_next--;
22233 ++
22234 ++ return 1;
22235 ++}
22236 ++
22237 ++static __inline__ void
22238 ++alloc_push(void *buf)
22239 ++{
22240 ++ if (alloc_stack_next >= alloc_stack_size)
22241 ++ BUG();
22242 ++
22243 ++ alloc_stack[alloc_stack_next - 1] = buf;
22244 ++
22245 ++ alloc_stack_next++;
22246 ++
22247 ++ return;
22248 ++}
22249 ++
22250 ++void *
22251 ++acl_alloc(unsigned long len)
22252 ++{
22253 ++ void *ret;
22254 ++
22255 ++ if (len > PAGE_SIZE)
22256 ++ BUG();
22257 ++
22258 ++ ret = kmalloc(len, GFP_KERNEL);
22259 ++
22260 ++ if (ret)
22261 ++ alloc_push(ret);
22262 ++
22263 ++ return ret;
22264 ++}
22265 ++
22266 ++void
22267 ++acl_free_all(void)
22268 ++{
22269 ++ if (gr_acl_is_enabled() || !alloc_stack)
22270 ++ return;
22271 ++
22272 ++ while (alloc_pop()) ;
22273 ++
22274 ++ if (alloc_stack) {
22275 ++ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
22276 ++ kfree(alloc_stack);
22277 ++ else
22278 ++ vfree(alloc_stack);
22279 ++ }
22280 ++
22281 ++ alloc_stack = NULL;
22282 ++ alloc_stack_size = 1;
22283 ++ alloc_stack_next = 1;
22284 ++
22285 ++ return;
22286 ++}
22287 ++
22288 ++int
22289 ++acl_alloc_stack_init(unsigned long size)
22290 ++{
22291 ++ if ((size * sizeof (void *)) <= PAGE_SIZE)
22292 ++ alloc_stack =
22293 ++ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
22294 ++ else
22295 ++ alloc_stack = (void **) vmalloc(size * sizeof (void *));
22296 ++
22297 ++ alloc_stack_size = size;
22298 ++
22299 ++ if (!alloc_stack)
22300 ++ return 0;
22301 ++ else
22302 ++ return 1;
22303 ++}
22304 +diff -urNp linux-2.6.28/grsecurity/gracl.c linux-2.6.28/grsecurity/gracl.c
22305 +--- linux-2.6.28/grsecurity/gracl.c 1969-12-31 19:00:00.000000000 -0500
22306 ++++ linux-2.6.28/grsecurity/gracl.c 2009-01-11 05:47:03.000000000 -0500
22307 +@@ -0,0 +1,3722 @@
22308 ++#include <linux/kernel.h>
22309 ++#include <linux/module.h>
22310 ++#include <linux/sched.h>
22311 ++#include <linux/mm.h>
22312 ++#include <linux/file.h>
22313 ++#include <linux/fs.h>
22314 ++#include <linux/namei.h>
22315 ++#include <linux/mount.h>
22316 ++#include <linux/tty.h>
22317 ++#include <linux/proc_fs.h>
22318 ++#include <linux/smp_lock.h>
22319 ++#include <linux/slab.h>
22320 ++#include <linux/vmalloc.h>
22321 ++#include <linux/types.h>
22322 ++#include <linux/sysctl.h>
22323 ++#include <linux/netdevice.h>
22324 ++#include <linux/ptrace.h>
22325 ++#include <linux/gracl.h>
22326 ++#include <linux/gralloc.h>
22327 ++#include <linux/grsecurity.h>
22328 ++#include <linux/grinternal.h>
22329 ++#include <linux/pid_namespace.h>
22330 ++#include <linux/fdtable.h>
22331 ++#include <linux/percpu.h>
22332 ++
22333 ++#include <asm/uaccess.h>
22334 ++#include <asm/errno.h>
22335 ++#include <asm/mman.h>
22336 ++
22337 ++static struct acl_role_db acl_role_set;
22338 ++static struct name_db name_set;
22339 ++static struct inodev_db inodev_set;
22340 ++
22341 ++/* for keeping track of userspace pointers used for subjects, so we
22342 ++ can share references in the kernel as well
22343 ++*/
22344 ++
22345 ++static struct dentry *real_root;
22346 ++static struct vfsmount *real_root_mnt;
22347 ++
22348 ++static struct acl_subj_map_db subj_map_set;
22349 ++
22350 ++static struct acl_role_label *default_role;
22351 ++
22352 ++static u16 acl_sp_role_value;
22353 ++
22354 ++extern char *gr_shared_page[4];
22355 ++static DECLARE_MUTEX(gr_dev_sem);
22356 ++DEFINE_RWLOCK(gr_inode_lock);
22357 ++
22358 ++struct gr_arg *gr_usermode;
22359 ++
22360 ++static unsigned int gr_status = GR_STATUS_INIT;
22361 ++
22362 ++extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
22363 ++extern void gr_clear_learn_entries(void);
22364 ++
22365 ++#ifdef CONFIG_GRKERNSEC_RESLOG
22366 ++extern void gr_log_resource(const struct task_struct *task,
22367 ++ const int res, const unsigned long wanted, const int gt);
22368 ++#endif
22369 ++
22370 ++unsigned char *gr_system_salt;
22371 ++unsigned char *gr_system_sum;
22372 ++
22373 ++static struct sprole_pw **acl_special_roles = NULL;
22374 ++static __u16 num_sprole_pws = 0;
22375 ++
22376 ++static struct acl_role_label *kernel_role = NULL;
22377 ++
22378 ++static unsigned int gr_auth_attempts = 0;
22379 ++static unsigned long gr_auth_expires = 0UL;
22380 ++
22381 ++extern struct vfsmount *sock_mnt;
22382 ++extern struct vfsmount *pipe_mnt;
22383 ++extern struct vfsmount *shm_mnt;
22384 ++static struct acl_object_label *fakefs_obj;
22385 ++
22386 ++extern int gr_init_uidset(void);
22387 ++extern void gr_free_uidset(void);
22388 ++extern void gr_remove_uid(uid_t uid);
22389 ++extern int gr_find_uid(uid_t uid);
22390 ++
22391 ++__inline__ int
22392 ++gr_acl_is_enabled(void)
22393 ++{
22394 ++ return (gr_status & GR_READY);
22395 ++}
22396 ++
22397 ++char gr_roletype_to_char(void)
22398 ++{
22399 ++ switch (current->role->roletype &
22400 ++ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
22401 ++ GR_ROLE_SPECIAL)) {
22402 ++ case GR_ROLE_DEFAULT:
22403 ++ return 'D';
22404 ++ case GR_ROLE_USER:
22405 ++ return 'U';
22406 ++ case GR_ROLE_GROUP:
22407 ++ return 'G';
22408 ++ case GR_ROLE_SPECIAL:
22409 ++ return 'S';
22410 ++ }
22411 ++
22412 ++ return 'X';
22413 ++}
22414 ++
22415 ++__inline__ int
22416 ++gr_acl_tpe_check(void)
22417 ++{
22418 ++ if (unlikely(!(gr_status & GR_READY)))
22419 ++ return 0;
22420 ++ if (current->role->roletype & GR_ROLE_TPE)
22421 ++ return 1;
22422 ++ else
22423 ++ return 0;
22424 ++}
22425 ++
22426 ++int
22427 ++gr_handle_rawio(const struct inode *inode)
22428 ++{
22429 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
22430 ++ if (inode && S_ISBLK(inode->i_mode) &&
22431 ++ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
22432 ++ !capable(CAP_SYS_RAWIO))
22433 ++ return 1;
22434 ++#endif
22435 ++ return 0;
22436 ++}
22437 ++
22438 ++static int
22439 ++gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
22440 ++{
22441 ++ int i;
22442 ++ unsigned long *l1;
22443 ++ unsigned long *l2;
22444 ++ unsigned char *c1;
22445 ++ unsigned char *c2;
22446 ++ int num_longs;
22447 ++
22448 ++ if (likely(lena != lenb))
22449 ++ return 0;
22450 ++
22451 ++ l1 = (unsigned long *)a;
22452 ++ l2 = (unsigned long *)b;
22453 ++
22454 ++ num_longs = lena / sizeof(unsigned long);
22455 ++
22456 ++ for (i = num_longs; i--; l1++, l2++) {
22457 ++ if (unlikely(*l1 != *l2))
22458 ++ return 0;
22459 ++ }
22460 ++
22461 ++ c1 = (unsigned char *) l1;
22462 ++ c2 = (unsigned char *) l2;
22463 ++
22464 ++ i = lena - (num_longs * sizeof(unsigned long));
22465 ++
22466 ++ for (; i--; c1++, c2++) {
22467 ++ if (unlikely(*c1 != *c2))
22468 ++ return 0;
22469 ++ }
22470 ++
22471 ++ return 1;
22472 ++}
22473 ++
22474 ++static char * __our_d_path(struct dentry *dentry, struct vfsmount *vfsmnt,
22475 ++ struct dentry *root, struct vfsmount *rootmnt,
22476 ++ char *buffer, int buflen)
22477 ++{
22478 ++ char * end = buffer+buflen;
22479 ++ char * retval;
22480 ++ int namelen;
22481 ++
22482 ++ *--end = '\0';
22483 ++ buflen--;
22484 ++
22485 ++ if (buflen < 1)
22486 ++ goto Elong;
22487 ++ /* Get '/' right */
22488 ++ retval = end-1;
22489 ++ *retval = '/';
22490 ++
22491 ++ for (;;) {
22492 ++ struct dentry * parent;
22493 ++
22494 ++ if (dentry == root && vfsmnt == rootmnt)
22495 ++ break;
22496 ++ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
22497 ++ /* Global root? */
22498 ++ spin_lock(&vfsmount_lock);
22499 ++ if (vfsmnt->mnt_parent == vfsmnt) {
22500 ++ spin_unlock(&vfsmount_lock);
22501 ++ goto global_root;
22502 ++ }
22503 ++ dentry = vfsmnt->mnt_mountpoint;
22504 ++ vfsmnt = vfsmnt->mnt_parent;
22505 ++ spin_unlock(&vfsmount_lock);
22506 ++ continue;
22507 ++ }
22508 ++ parent = dentry->d_parent;
22509 ++ prefetch(parent);
22510 ++ namelen = dentry->d_name.len;
22511 ++ buflen -= namelen + 1;
22512 ++ if (buflen < 0)
22513 ++ goto Elong;
22514 ++ end -= namelen;
22515 ++ memcpy(end, dentry->d_name.name, namelen);
22516 ++ *--end = '/';
22517 ++ retval = end;
22518 ++ dentry = parent;
22519 ++ }
22520 ++
22521 ++ return retval;
22522 ++
22523 ++global_root:
22524 ++ namelen = dentry->d_name.len;
22525 ++ buflen -= namelen;
22526 ++ if (buflen < 0)
22527 ++ goto Elong;
22528 ++ retval -= namelen-1; /* hit the slash */
22529 ++ memcpy(retval, dentry->d_name.name, namelen);
22530 ++ return retval;
22531 ++Elong:
22532 ++ return ERR_PTR(-ENAMETOOLONG);
22533 ++}
22534 ++
22535 ++static char *
22536 ++gen_full_path(struct dentry *dentry, struct vfsmount *vfsmnt,
22537 ++ struct dentry *root, struct vfsmount *rootmnt, char *buf, int buflen)
22538 ++{
22539 ++ char *retval;
22540 ++
22541 ++ retval = __our_d_path(dentry, vfsmnt, root, rootmnt, buf, buflen);
22542 ++ if (unlikely(IS_ERR(retval)))
22543 ++ retval = strcpy(buf, "<path too long>");
22544 ++ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
22545 ++ retval[1] = '\0';
22546 ++
22547 ++ return retval;
22548 ++}
22549 ++
22550 ++static char *
22551 ++__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
22552 ++ char *buf, int buflen)
22553 ++{
22554 ++ char *res;
22555 ++
22556 ++ /* we can use real_root, real_root_mnt, because this is only called
22557 ++ by the RBAC system */
22558 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, real_root, real_root_mnt, buf, buflen);
22559 ++
22560 ++ return res;
22561 ++}
22562 ++
22563 ++static char *
22564 ++d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
22565 ++ char *buf, int buflen)
22566 ++{
22567 ++ char *res;
22568 ++ struct dentry *root;
22569 ++ struct vfsmount *rootmnt;
22570 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
22571 ++
22572 ++ /* we can't use real_root, real_root_mnt, because they belong only to the RBAC system */
22573 ++ read_lock(&reaper->fs->lock);
22574 ++ root = dget(reaper->fs->root.dentry);
22575 ++ rootmnt = mntget(reaper->fs->root.mnt);
22576 ++ read_unlock(&reaper->fs->lock);
22577 ++
22578 ++ spin_lock(&dcache_lock);
22579 ++ res = gen_full_path((struct dentry *)dentry, (struct vfsmount *)vfsmnt, root, rootmnt, buf, buflen);
22580 ++ spin_unlock(&dcache_lock);
22581 ++
22582 ++ dput(root);
22583 ++ mntput(rootmnt);
22584 ++ return res;
22585 ++}
22586 ++
22587 ++static char *
22588 ++gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
22589 ++{
22590 ++ char *ret;
22591 ++ spin_lock(&dcache_lock);
22592 ++ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
22593 ++ PAGE_SIZE);
22594 ++ spin_unlock(&dcache_lock);
22595 ++ return ret;
22596 ++}
22597 ++
22598 ++char *
22599 ++gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
22600 ++{
22601 ++ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
22602 ++ PAGE_SIZE);
22603 ++}
22604 ++
22605 ++char *
22606 ++gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
22607 ++{
22608 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
22609 ++ PAGE_SIZE);
22610 ++}
22611 ++
22612 ++char *
22613 ++gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
22614 ++{
22615 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
22616 ++ PAGE_SIZE);
22617 ++}
22618 ++
22619 ++char *
22620 ++gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
22621 ++{
22622 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
22623 ++ PAGE_SIZE);
22624 ++}
22625 ++
22626 ++char *
22627 ++gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
22628 ++{
22629 ++ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
22630 ++ PAGE_SIZE);
22631 ++}
22632 ++
22633 ++__inline__ __u32
22634 ++to_gr_audit(const __u32 reqmode)
22635 ++{
22636 ++ /* masks off auditable permission flags, then shifts them to create
22637 ++ auditing flags, and adds the special case of append auditing if
22638 ++ we're requesting write */
22639 ++ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
22640 ++}
22641 ++
22642 ++struct acl_subject_label *
22643 ++lookup_subject_map(const struct acl_subject_label *userp)
22644 ++{
22645 ++ unsigned int index = shash(userp, subj_map_set.s_size);
22646 ++ struct subject_map *match;
22647 ++
22648 ++ match = subj_map_set.s_hash[index];
22649 ++
22650 ++ while (match && match->user != userp)
22651 ++ match = match->next;
22652 ++
22653 ++ if (match != NULL)
22654 ++ return match->kernel;
22655 ++ else
22656 ++ return NULL;
22657 ++}
22658 ++
22659 ++static void
22660 ++insert_subj_map_entry(struct subject_map *subjmap)
22661 ++{
22662 ++ unsigned int index = shash(subjmap->user, subj_map_set.s_size);
22663 ++ struct subject_map **curr;
22664 ++
22665 ++ subjmap->prev = NULL;
22666 ++
22667 ++ curr = &subj_map_set.s_hash[index];
22668 ++ if (*curr != NULL)
22669 ++ (*curr)->prev = subjmap;
22670 ++
22671 ++ subjmap->next = *curr;
22672 ++ *curr = subjmap;
22673 ++
22674 ++ return;
22675 ++}
22676 ++
22677 ++static struct acl_role_label *
22678 ++lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
22679 ++ const gid_t gid)
22680 ++{
22681 ++ unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
22682 ++ struct acl_role_label *match;
22683 ++ struct role_allowed_ip *ipp;
22684 ++ unsigned int x;
22685 ++
22686 ++ match = acl_role_set.r_hash[index];
22687 ++
22688 ++ while (match) {
22689 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
22690 ++ for (x = 0; x < match->domain_child_num; x++) {
22691 ++ if (match->domain_children[x] == uid)
22692 ++ goto found;
22693 ++ }
22694 ++ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
22695 ++ break;
22696 ++ match = match->next;
22697 ++ }
22698 ++found:
22699 ++ if (match == NULL) {
22700 ++ try_group:
22701 ++ index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
22702 ++ match = acl_role_set.r_hash[index];
22703 ++
22704 ++ while (match) {
22705 ++ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
22706 ++ for (x = 0; x < match->domain_child_num; x++) {
22707 ++ if (match->domain_children[x] == gid)
22708 ++ goto found2;
22709 ++ }
22710 ++ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
22711 ++ break;
22712 ++ match = match->next;
22713 ++ }
22714 ++found2:
22715 ++ if (match == NULL)
22716 ++ match = default_role;
22717 ++ if (match->allowed_ips == NULL)
22718 ++ return match;
22719 ++ else {
22720 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
22721 ++ if (likely
22722 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
22723 ++ (ntohl(ipp->addr) & ipp->netmask)))
22724 ++ return match;
22725 ++ }
22726 ++ match = default_role;
22727 ++ }
22728 ++ } else if (match->allowed_ips == NULL) {
22729 ++ return match;
22730 ++ } else {
22731 ++ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
22732 ++ if (likely
22733 ++ ((ntohl(task->signal->curr_ip) & ipp->netmask) ==
22734 ++ (ntohl(ipp->addr) & ipp->netmask)))
22735 ++ return match;
22736 ++ }
22737 ++ goto try_group;
22738 ++ }
22739 ++
22740 ++ return match;
22741 ++}
22742 ++
22743 ++struct acl_subject_label *
22744 ++lookup_acl_subj_label(const ino_t ino, const dev_t dev,
22745 ++ const struct acl_role_label *role)
22746 ++{
22747 ++ unsigned int index = fhash(ino, dev, role->subj_hash_size);
22748 ++ struct acl_subject_label *match;
22749 ++
22750 ++ match = role->subj_hash[index];
22751 ++
22752 ++ while (match && (match->inode != ino || match->device != dev ||
22753 ++ (match->mode & GR_DELETED))) {
22754 ++ match = match->next;
22755 ++ }
22756 ++
22757 ++ if (match && !(match->mode & GR_DELETED))
22758 ++ return match;
22759 ++ else
22760 ++ return NULL;
22761 ++}
22762 ++
22763 ++static struct acl_object_label *
22764 ++lookup_acl_obj_label(const ino_t ino, const dev_t dev,
22765 ++ const struct acl_subject_label *subj)
22766 ++{
22767 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
22768 ++ struct acl_object_label *match;
22769 ++
22770 ++ match = subj->obj_hash[index];
22771 ++
22772 ++ while (match && (match->inode != ino || match->device != dev ||
22773 ++ (match->mode & GR_DELETED))) {
22774 ++ match = match->next;
22775 ++ }
22776 ++
22777 ++ if (match && !(match->mode & GR_DELETED))
22778 ++ return match;
22779 ++ else
22780 ++ return NULL;
22781 ++}
22782 ++
22783 ++static struct acl_object_label *
22784 ++lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
22785 ++ const struct acl_subject_label *subj)
22786 ++{
22787 ++ unsigned int index = fhash(ino, dev, subj->obj_hash_size);
22788 ++ struct acl_object_label *match;
22789 ++
22790 ++ match = subj->obj_hash[index];
22791 ++
22792 ++ while (match && (match->inode != ino || match->device != dev ||
22793 ++ !(match->mode & GR_DELETED))) {
22794 ++ match = match->next;
22795 ++ }
22796 ++
22797 ++ if (match && (match->mode & GR_DELETED))
22798 ++ return match;
22799 ++
22800 ++ match = subj->obj_hash[index];
22801 ++
22802 ++ while (match && (match->inode != ino || match->device != dev ||
22803 ++ (match->mode & GR_DELETED))) {
22804 ++ match = match->next;
22805 ++ }
22806 ++
22807 ++ if (match && !(match->mode & GR_DELETED))
22808 ++ return match;
22809 ++ else
22810 ++ return NULL;
22811 ++}
22812 ++
22813 ++static struct name_entry *
22814 ++lookup_name_entry(const char *name)
22815 ++{
22816 ++ unsigned int len = strlen(name);
22817 ++ unsigned int key = full_name_hash(name, len);
22818 ++ unsigned int index = key % name_set.n_size;
22819 ++ struct name_entry *match;
22820 ++
22821 ++ match = name_set.n_hash[index];
22822 ++
22823 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
22824 ++ match = match->next;
22825 ++
22826 ++ return match;
22827 ++}
22828 ++
22829 ++static struct name_entry *
22830 ++lookup_name_entry_create(const char *name)
22831 ++{
22832 ++ unsigned int len = strlen(name);
22833 ++ unsigned int key = full_name_hash(name, len);
22834 ++ unsigned int index = key % name_set.n_size;
22835 ++ struct name_entry *match;
22836 ++
22837 ++ match = name_set.n_hash[index];
22838 ++
22839 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
22840 ++ !match->deleted))
22841 ++ match = match->next;
22842 ++
22843 ++ if (match && match->deleted)
22844 ++ return match;
22845 ++
22846 ++ match = name_set.n_hash[index];
22847 ++
22848 ++ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
22849 ++ match->deleted))
22850 ++ match = match->next;
22851 ++
22852 ++ if (match && !match->deleted)
22853 ++ return match;
22854 ++ else
22855 ++ return NULL;
22856 ++}
22857 ++
22858 ++static struct inodev_entry *
22859 ++lookup_inodev_entry(const ino_t ino, const dev_t dev)
22860 ++{
22861 ++ unsigned int index = fhash(ino, dev, inodev_set.i_size);
22862 ++ struct inodev_entry *match;
22863 ++
22864 ++ match = inodev_set.i_hash[index];
22865 ++
22866 ++ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
22867 ++ match = match->next;
22868 ++
22869 ++ return match;
22870 ++}
22871 ++
22872 ++static void
22873 ++insert_inodev_entry(struct inodev_entry *entry)
22874 ++{
22875 ++ unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
22876 ++ inodev_set.i_size);
22877 ++ struct inodev_entry **curr;
22878 ++
22879 ++ entry->prev = NULL;
22880 ++
22881 ++ curr = &inodev_set.i_hash[index];
22882 ++ if (*curr != NULL)
22883 ++ (*curr)->prev = entry;
22884 ++
22885 ++ entry->next = *curr;
22886 ++ *curr = entry;
22887 ++
22888 ++ return;
22889 ++}
22890 ++
22891 ++static void
22892 ++__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
22893 ++{
22894 ++ unsigned int index =
22895 ++ rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
22896 ++ struct acl_role_label **curr;
22897 ++
22898 ++ role->prev = NULL;
22899 ++
22900 ++ curr = &acl_role_set.r_hash[index];
22901 ++ if (*curr != NULL)
22902 ++ (*curr)->prev = role;
22903 ++
22904 ++ role->next = *curr;
22905 ++ *curr = role;
22906 ++
22907 ++ return;
22908 ++}
22909 ++
22910 ++static void
22911 ++insert_acl_role_label(struct acl_role_label *role)
22912 ++{
22913 ++ int i;
22914 ++
22915 ++ if (role->roletype & GR_ROLE_DOMAIN) {
22916 ++ for (i = 0; i < role->domain_child_num; i++)
22917 ++ __insert_acl_role_label(role, role->domain_children[i]);
22918 ++ } else
22919 ++ __insert_acl_role_label(role, role->uidgid);
22920 ++}
22921 ++
22922 ++static int
22923 ++insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
22924 ++{
22925 ++ struct name_entry **curr, *nentry;
22926 ++ struct inodev_entry *ientry;
22927 ++ unsigned int len = strlen(name);
22928 ++ unsigned int key = full_name_hash(name, len);
22929 ++ unsigned int index = key % name_set.n_size;
22930 ++
22931 ++ curr = &name_set.n_hash[index];
22932 ++
22933 ++ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
22934 ++ curr = &((*curr)->next);
22935 ++
22936 ++ if (*curr != NULL)
22937 ++ return 1;
22938 ++
22939 ++ nentry = acl_alloc(sizeof (struct name_entry));
22940 ++ if (nentry == NULL)
22941 ++ return 0;
22942 ++ ientry = acl_alloc(sizeof (struct inodev_entry));
22943 ++ if (ientry == NULL)
22944 ++ return 0;
22945 ++ ientry->nentry = nentry;
22946 ++
22947 ++ nentry->key = key;
22948 ++ nentry->name = name;
22949 ++ nentry->inode = inode;
22950 ++ nentry->device = device;
22951 ++ nentry->len = len;
22952 ++ nentry->deleted = deleted;
22953 ++
22954 ++ nentry->prev = NULL;
22955 ++ curr = &name_set.n_hash[index];
22956 ++ if (*curr != NULL)
22957 ++ (*curr)->prev = nentry;
22958 ++ nentry->next = *curr;
22959 ++ *curr = nentry;
22960 ++
22961 ++ /* insert us into the table searchable by inode/dev */
22962 ++ insert_inodev_entry(ientry);
22963 ++
22964 ++ return 1;
22965 ++}
22966 ++
22967 ++static void
22968 ++insert_acl_obj_label(struct acl_object_label *obj,
22969 ++ struct acl_subject_label *subj)
22970 ++{
22971 ++ unsigned int index =
22972 ++ fhash(obj->inode, obj->device, subj->obj_hash_size);
22973 ++ struct acl_object_label **curr;
22974 ++
22975 ++
22976 ++ obj->prev = NULL;
22977 ++
22978 ++ curr = &subj->obj_hash[index];
22979 ++ if (*curr != NULL)
22980 ++ (*curr)->prev = obj;
22981 ++
22982 ++ obj->next = *curr;
22983 ++ *curr = obj;
22984 ++
22985 ++ return;
22986 ++}
22987 ++
22988 ++static void
22989 ++insert_acl_subj_label(struct acl_subject_label *obj,
22990 ++ struct acl_role_label *role)
22991 ++{
22992 ++ unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
22993 ++ struct acl_subject_label **curr;
22994 ++
22995 ++ obj->prev = NULL;
22996 ++
22997 ++ curr = &role->subj_hash[index];
22998 ++ if (*curr != NULL)
22999 ++ (*curr)->prev = obj;
23000 ++
23001 ++ obj->next = *curr;
23002 ++ *curr = obj;
23003 ++
23004 ++ return;
23005 ++}
23006 ++
23007 ++/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
23008 ++
23009 ++static void *
23010 ++create_table(__u32 * len, int elementsize)
23011 ++{
23012 ++ unsigned int table_sizes[] = {
23013 ++ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
23014 ++ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
23015 ++ 4194301, 8388593, 16777213, 33554393, 67108859, 134217689,
23016 ++ 268435399, 536870909, 1073741789, 2147483647
23017 ++ };
23018 ++ void *newtable = NULL;
23019 ++ unsigned int pwr = 0;
23020 ++
23021 ++ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
23022 ++ table_sizes[pwr] <= *len)
23023 ++ pwr++;
23024 ++
23025 ++ if (table_sizes[pwr] <= *len)
23026 ++ return newtable;
23027 ++
23028 ++ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
23029 ++ newtable =
23030 ++ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
23031 ++ else
23032 ++ newtable = vmalloc(table_sizes[pwr] * elementsize);
23033 ++
23034 ++ *len = table_sizes[pwr];
23035 ++
23036 ++ return newtable;
23037 ++}
23038 ++
23039 ++static int
23040 ++init_variables(const struct gr_arg *arg)
23041 ++{
23042 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
23043 ++ unsigned int stacksize;
23044 ++
23045 ++ subj_map_set.s_size = arg->role_db.num_subjects;
23046 ++ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
23047 ++ name_set.n_size = arg->role_db.num_objects;
23048 ++ inodev_set.i_size = arg->role_db.num_objects;
23049 ++
23050 ++ if (!subj_map_set.s_size || !acl_role_set.r_size ||
23051 ++ !name_set.n_size || !inodev_set.i_size)
23052 ++ return 1;
23053 ++
23054 ++ if (!gr_init_uidset())
23055 ++ return 1;
23056 ++
23057 ++ /* set up the stack that holds allocation info */
23058 ++
23059 ++ stacksize = arg->role_db.num_pointers + 5;
23060 ++
23061 ++ if (!acl_alloc_stack_init(stacksize))
23062 ++ return 1;
23063 ++
23064 ++ /* grab reference for the real root dentry and vfsmount */
23065 ++ read_lock(&reaper->fs->lock);
23066 ++ real_root_mnt = mntget(reaper->fs->root.mnt);
23067 ++ real_root = dget(reaper->fs->root.dentry);
23068 ++ read_unlock(&reaper->fs->lock);
23069 ++
23070 ++ fakefs_obj = acl_alloc(sizeof(struct acl_object_label));
23071 ++ if (fakefs_obj == NULL)
23072 ++ return 1;
23073 ++ fakefs_obj->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
23074 ++
23075 ++ subj_map_set.s_hash =
23076 ++ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
23077 ++ acl_role_set.r_hash =
23078 ++ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
23079 ++ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
23080 ++ inodev_set.i_hash =
23081 ++ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
23082 ++
23083 ++ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
23084 ++ !name_set.n_hash || !inodev_set.i_hash)
23085 ++ return 1;
23086 ++
23087 ++ memset(subj_map_set.s_hash, 0,
23088 ++ sizeof(struct subject_map *) * subj_map_set.s_size);
23089 ++ memset(acl_role_set.r_hash, 0,
23090 ++ sizeof (struct acl_role_label *) * acl_role_set.r_size);
23091 ++ memset(name_set.n_hash, 0,
23092 ++ sizeof (struct name_entry *) * name_set.n_size);
23093 ++ memset(inodev_set.i_hash, 0,
23094 ++ sizeof (struct inodev_entry *) * inodev_set.i_size);
23095 ++
23096 ++ return 0;
23097 ++}
23098 ++
23099 ++/* free information not needed after startup
23100 ++ currently contains user->kernel pointer mappings for subjects
23101 ++*/
23102 ++
23103 ++static void
23104 ++free_init_variables(void)
23105 ++{
23106 ++ __u32 i;
23107 ++
23108 ++ if (subj_map_set.s_hash) {
23109 ++ for (i = 0; i < subj_map_set.s_size; i++) {
23110 ++ if (subj_map_set.s_hash[i]) {
23111 ++ kfree(subj_map_set.s_hash[i]);
23112 ++ subj_map_set.s_hash[i] = NULL;
23113 ++ }
23114 ++ }
23115 ++
23116 ++ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
23117 ++ PAGE_SIZE)
23118 ++ kfree(subj_map_set.s_hash);
23119 ++ else
23120 ++ vfree(subj_map_set.s_hash);
23121 ++ }
23122 ++
23123 ++ return;
23124 ++}
23125 ++
23126 ++static void
23127 ++free_variables(void)
23128 ++{
23129 ++ struct acl_subject_label *s;
23130 ++ struct acl_role_label *r;
23131 ++ struct task_struct *task, *task2;
23132 ++ unsigned int i, x;
23133 ++
23134 ++ gr_clear_learn_entries();
23135 ++
23136 ++ read_lock(&tasklist_lock);
23137 ++ do_each_thread(task2, task) {
23138 ++ task->acl_sp_role = 0;
23139 ++ task->acl_role_id = 0;
23140 ++ task->acl = NULL;
23141 ++ task->role = NULL;
23142 ++ } while_each_thread(task2, task);
23143 ++ read_unlock(&tasklist_lock);
23144 ++
23145 ++ /* release the reference to the real root dentry and vfsmount */
23146 ++ if (real_root)
23147 ++ dput(real_root);
23148 ++ real_root = NULL;
23149 ++ if (real_root_mnt)
23150 ++ mntput(real_root_mnt);
23151 ++ real_root_mnt = NULL;
23152 ++
23153 ++ /* free all object hash tables */
23154 ++
23155 ++ FOR_EACH_ROLE_START(r, i)
23156 ++ if (r->subj_hash == NULL)
23157 ++ break;
23158 ++ FOR_EACH_SUBJECT_START(r, s, x)
23159 ++ if (s->obj_hash == NULL)
23160 ++ break;
23161 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
23162 ++ kfree(s->obj_hash);
23163 ++ else
23164 ++ vfree(s->obj_hash);
23165 ++ FOR_EACH_SUBJECT_END(s, x)
23166 ++ FOR_EACH_NESTED_SUBJECT_START(r, s)
23167 ++ if (s->obj_hash == NULL)
23168 ++ break;
23169 ++ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
23170 ++ kfree(s->obj_hash);
23171 ++ else
23172 ++ vfree(s->obj_hash);
23173 ++ FOR_EACH_NESTED_SUBJECT_END(s)
23174 ++ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
23175 ++ kfree(r->subj_hash);
23176 ++ else
23177 ++ vfree(r->subj_hash);
23178 ++ r->subj_hash = NULL;
23179 ++ FOR_EACH_ROLE_END(r,i)
23180 ++
23181 ++ acl_free_all();
23182 ++
23183 ++ if (acl_role_set.r_hash) {
23184 ++ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
23185 ++ PAGE_SIZE)
23186 ++ kfree(acl_role_set.r_hash);
23187 ++ else
23188 ++ vfree(acl_role_set.r_hash);
23189 ++ }
23190 ++ if (name_set.n_hash) {
23191 ++ if ((name_set.n_size * sizeof (struct name_entry *)) <=
23192 ++ PAGE_SIZE)
23193 ++ kfree(name_set.n_hash);
23194 ++ else
23195 ++ vfree(name_set.n_hash);
23196 ++ }
23197 ++
23198 ++ if (inodev_set.i_hash) {
23199 ++ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
23200 ++ PAGE_SIZE)
23201 ++ kfree(inodev_set.i_hash);
23202 ++ else
23203 ++ vfree(inodev_set.i_hash);
23204 ++ }
23205 ++
23206 ++ gr_free_uidset();
23207 ++
23208 ++ memset(&name_set, 0, sizeof (struct name_db));
23209 ++ memset(&inodev_set, 0, sizeof (struct inodev_db));
23210 ++ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
23211 ++ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
23212 ++
23213 ++ default_role = NULL;
23214 ++
23215 ++ return;
23216 ++}
23217 ++
23218 ++static __u32
23219 ++count_user_objs(struct acl_object_label *userp)
23220 ++{
23221 ++ struct acl_object_label o_tmp;
23222 ++ __u32 num = 0;
23223 ++
23224 ++ while (userp) {
23225 ++ if (copy_from_user(&o_tmp, userp,
23226 ++ sizeof (struct acl_object_label)))
23227 ++ break;
23228 ++
23229 ++ userp = o_tmp.prev;
23230 ++ num++;
23231 ++ }
23232 ++
23233 ++ return num;
23234 ++}
23235 ++
23236 ++static struct acl_subject_label *
23237 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
23238 ++
23239 ++static int
23240 ++copy_user_glob(struct acl_object_label *obj)
23241 ++{
23242 ++ struct acl_object_label *g_tmp, **guser;
23243 ++ unsigned int len;
23244 ++ char *tmp;
23245 ++
23246 ++ if (obj->globbed == NULL)
23247 ++ return 0;
23248 ++
23249 ++ guser = &obj->globbed;
23250 ++ while (*guser) {
23251 ++ g_tmp = (struct acl_object_label *)
23252 ++ acl_alloc(sizeof (struct acl_object_label));
23253 ++ if (g_tmp == NULL)
23254 ++ return -ENOMEM;
23255 ++
23256 ++ if (copy_from_user(g_tmp, *guser,
23257 ++ sizeof (struct acl_object_label)))
23258 ++ return -EFAULT;
23259 ++
23260 ++ len = strnlen_user(g_tmp->filename, PATH_MAX);
23261 ++
23262 ++ if (!len || len >= PATH_MAX)
23263 ++ return -EINVAL;
23264 ++
23265 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
23266 ++ return -ENOMEM;
23267 ++
23268 ++ if (copy_from_user(tmp, g_tmp->filename, len))
23269 ++ return -EFAULT;
23270 ++
23271 ++ g_tmp->filename = tmp;
23272 ++
23273 ++ *guser = g_tmp;
23274 ++ guser = &(g_tmp->next);
23275 ++ }
23276 ++
23277 ++ return 0;
23278 ++}
23279 ++
23280 ++static int
23281 ++copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
23282 ++ struct acl_role_label *role)
23283 ++{
23284 ++ struct acl_object_label *o_tmp;
23285 ++ unsigned int len;
23286 ++ int ret;
23287 ++ char *tmp;
23288 ++
23289 ++ while (userp) {
23290 ++ if ((o_tmp = (struct acl_object_label *)
23291 ++ acl_alloc(sizeof (struct acl_object_label))) == NULL)
23292 ++ return -ENOMEM;
23293 ++
23294 ++ if (copy_from_user(o_tmp, userp,
23295 ++ sizeof (struct acl_object_label)))
23296 ++ return -EFAULT;
23297 ++
23298 ++ userp = o_tmp->prev;
23299 ++
23300 ++ len = strnlen_user(o_tmp->filename, PATH_MAX);
23301 ++
23302 ++ if (!len || len >= PATH_MAX)
23303 ++ return -EINVAL;
23304 ++
23305 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
23306 ++ return -ENOMEM;
23307 ++
23308 ++ if (copy_from_user(tmp, o_tmp->filename, len))
23309 ++ return -EFAULT;
23310 ++
23311 ++ o_tmp->filename = tmp;
23312 ++
23313 ++ insert_acl_obj_label(o_tmp, subj);
23314 ++ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
23315 ++ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
23316 ++ return -ENOMEM;
23317 ++
23318 ++ ret = copy_user_glob(o_tmp);
23319 ++ if (ret)
23320 ++ return ret;
23321 ++
23322 ++ if (o_tmp->nested) {
23323 ++ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
23324 ++ if (IS_ERR(o_tmp->nested))
23325 ++ return PTR_ERR(o_tmp->nested);
23326 ++
23327 ++ /* insert into nested subject list */
23328 ++ o_tmp->nested->next = role->hash->first;
23329 ++ role->hash->first = o_tmp->nested;
23330 ++ }
23331 ++ }
23332 ++
23333 ++ return 0;
23334 ++}
23335 ++
23336 ++static __u32
23337 ++count_user_subjs(struct acl_subject_label *userp)
23338 ++{
23339 ++ struct acl_subject_label s_tmp;
23340 ++ __u32 num = 0;
23341 ++
23342 ++ while (userp) {
23343 ++ if (copy_from_user(&s_tmp, userp,
23344 ++ sizeof (struct acl_subject_label)))
23345 ++ break;
23346 ++
23347 ++ userp = s_tmp.prev;
23348 ++ /* do not count nested subjects against this count, since
23349 ++ they are not included in the hash table, but are
23350 ++ attached to objects. We have already counted
23351 ++ the subjects in userspace for the allocation
23352 ++ stack
23353 ++ */
23354 ++ if (!(s_tmp.mode & GR_NESTED))
23355 ++ num++;
23356 ++ }
23357 ++
23358 ++ return num;
23359 ++}
23360 ++
23361 ++static int
23362 ++copy_user_allowedips(struct acl_role_label *rolep)
23363 ++{
23364 ++ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
23365 ++
23366 ++ ruserip = rolep->allowed_ips;
23367 ++
23368 ++ while (ruserip) {
23369 ++ rlast = rtmp;
23370 ++
23371 ++ if ((rtmp = (struct role_allowed_ip *)
23372 ++ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
23373 ++ return -ENOMEM;
23374 ++
23375 ++ if (copy_from_user(rtmp, ruserip,
23376 ++ sizeof (struct role_allowed_ip)))
23377 ++ return -EFAULT;
23378 ++
23379 ++ ruserip = rtmp->prev;
23380 ++
23381 ++ if (!rlast) {
23382 ++ rtmp->prev = NULL;
23383 ++ rolep->allowed_ips = rtmp;
23384 ++ } else {
23385 ++ rlast->next = rtmp;
23386 ++ rtmp->prev = rlast;
23387 ++ }
23388 ++
23389 ++ if (!ruserip)
23390 ++ rtmp->next = NULL;
23391 ++ }
23392 ++
23393 ++ return 0;
23394 ++}
23395 ++
23396 ++static int
23397 ++copy_user_transitions(struct acl_role_label *rolep)
23398 ++{
23399 ++ struct role_transition *rusertp, *rtmp = NULL, *rlast;
23400 ++
23401 ++ unsigned int len;
23402 ++ char *tmp;
23403 ++
23404 ++ rusertp = rolep->transitions;
23405 ++
23406 ++ while (rusertp) {
23407 ++ rlast = rtmp;
23408 ++
23409 ++ if ((rtmp = (struct role_transition *)
23410 ++ acl_alloc(sizeof (struct role_transition))) == NULL)
23411 ++ return -ENOMEM;
23412 ++
23413 ++ if (copy_from_user(rtmp, rusertp,
23414 ++ sizeof (struct role_transition)))
23415 ++ return -EFAULT;
23416 ++
23417 ++ rusertp = rtmp->prev;
23418 ++
23419 ++ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
23420 ++
23421 ++ if (!len || len >= GR_SPROLE_LEN)
23422 ++ return -EINVAL;
23423 ++
23424 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
23425 ++ return -ENOMEM;
23426 ++
23427 ++ if (copy_from_user(tmp, rtmp->rolename, len))
23428 ++ return -EFAULT;
23429 ++
23430 ++ rtmp->rolename = tmp;
23431 ++
23432 ++ if (!rlast) {
23433 ++ rtmp->prev = NULL;
23434 ++ rolep->transitions = rtmp;
23435 ++ } else {
23436 ++ rlast->next = rtmp;
23437 ++ rtmp->prev = rlast;
23438 ++ }
23439 ++
23440 ++ if (!rusertp)
23441 ++ rtmp->next = NULL;
23442 ++ }
23443 ++
23444 ++ return 0;
23445 ++}
23446 ++
23447 ++static struct acl_subject_label *
23448 ++do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
23449 ++{
23450 ++ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
23451 ++ unsigned int len;
23452 ++ char *tmp;
23453 ++ __u32 num_objs;
23454 ++ struct acl_ip_label **i_tmp, *i_utmp2;
23455 ++ struct gr_hash_struct ghash;
23456 ++ struct subject_map *subjmap;
23457 ++ unsigned int i_num;
23458 ++ int err;
23459 ++
23460 ++ s_tmp = lookup_subject_map(userp);
23461 ++
23462 ++ /* we've already copied this subject into the kernel, just return
23463 ++ the reference to it, and don't copy it over again
23464 ++ */
23465 ++ if (s_tmp)
23466 ++ return(s_tmp);
23467 ++
23468 ++ if ((s_tmp = (struct acl_subject_label *)
23469 ++ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
23470 ++ return ERR_PTR(-ENOMEM);
23471 ++
23472 ++ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
23473 ++ if (subjmap == NULL)
23474 ++ return ERR_PTR(-ENOMEM);
23475 ++
23476 ++ subjmap->user = userp;
23477 ++ subjmap->kernel = s_tmp;
23478 ++ insert_subj_map_entry(subjmap);
23479 ++
23480 ++ if (copy_from_user(s_tmp, userp,
23481 ++ sizeof (struct acl_subject_label)))
23482 ++ return ERR_PTR(-EFAULT);
23483 ++
23484 ++ len = strnlen_user(s_tmp->filename, PATH_MAX);
23485 ++
23486 ++ if (!len || len >= PATH_MAX)
23487 ++ return ERR_PTR(-EINVAL);
23488 ++
23489 ++ if ((tmp = (char *) acl_alloc(len)) == NULL)
23490 ++ return ERR_PTR(-ENOMEM);
23491 ++
23492 ++ if (copy_from_user(tmp, s_tmp->filename, len))
23493 ++ return ERR_PTR(-EFAULT);
23494 ++
23495 ++ s_tmp->filename = tmp;
23496 ++
23497 ++ if (!strcmp(s_tmp->filename, "/"))
23498 ++ role->root_label = s_tmp;
23499 ++
23500 ++ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
23501 ++ return ERR_PTR(-EFAULT);
23502 ++
23503 ++ /* copy user and group transition tables */
23504 ++
23505 ++ if (s_tmp->user_trans_num) {
23506 ++ uid_t *uidlist;
23507 ++
23508 ++ uidlist = (uid_t *)acl_alloc(s_tmp->user_trans_num * sizeof(uid_t));
23509 ++ if (uidlist == NULL)
23510 ++ return ERR_PTR(-ENOMEM);
23511 ++ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
23512 ++ return ERR_PTR(-EFAULT);
23513 ++
23514 ++ s_tmp->user_transitions = uidlist;
23515 ++ }
23516 ++
23517 ++ if (s_tmp->group_trans_num) {
23518 ++ gid_t *gidlist;
23519 ++
23520 ++ gidlist = (gid_t *)acl_alloc(s_tmp->group_trans_num * sizeof(gid_t));
23521 ++ if (gidlist == NULL)
23522 ++ return ERR_PTR(-ENOMEM);
23523 ++ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
23524 ++ return ERR_PTR(-EFAULT);
23525 ++
23526 ++ s_tmp->group_transitions = gidlist;
23527 ++ }
23528 ++
23529 ++ /* set up object hash table */
23530 ++ num_objs = count_user_objs(ghash.first);
23531 ++
23532 ++ s_tmp->obj_hash_size = num_objs;
23533 ++ s_tmp->obj_hash =
23534 ++ (struct acl_object_label **)
23535 ++ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
23536 ++
23537 ++ if (!s_tmp->obj_hash)
23538 ++ return ERR_PTR(-ENOMEM);
23539 ++
23540 ++ memset(s_tmp->obj_hash, 0,
23541 ++ s_tmp->obj_hash_size *
23542 ++ sizeof (struct acl_object_label *));
23543 ++
23544 ++ /* add in objects */
23545 ++ err = copy_user_objs(ghash.first, s_tmp, role);
23546 ++
23547 ++ if (err)
23548 ++ return ERR_PTR(err);
23549 ++
23550 ++ /* set pointer for parent subject */
23551 ++ if (s_tmp->parent_subject) {
23552 ++ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
23553 ++
23554 ++ if (IS_ERR(s_tmp2))
23555 ++ return s_tmp2;
23556 ++
23557 ++ s_tmp->parent_subject = s_tmp2;
23558 ++ }
23559 ++
23560 ++ /* add in ip acls */
23561 ++
23562 ++ if (!s_tmp->ip_num) {
23563 ++ s_tmp->ips = NULL;
23564 ++ goto insert;
23565 ++ }
23566 ++
23567 ++ i_tmp =
23568 ++ (struct acl_ip_label **) acl_alloc(s_tmp->ip_num *
23569 ++ sizeof (struct
23570 ++ acl_ip_label *));
23571 ++
23572 ++ if (!i_tmp)
23573 ++ return ERR_PTR(-ENOMEM);
23574 ++
23575 ++ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
23576 ++ *(i_tmp + i_num) =
23577 ++ (struct acl_ip_label *)
23578 ++ acl_alloc(sizeof (struct acl_ip_label));
23579 ++ if (!*(i_tmp + i_num))
23580 ++ return ERR_PTR(-ENOMEM);
23581 ++
23582 ++ if (copy_from_user
23583 ++ (&i_utmp2, s_tmp->ips + i_num,
23584 ++ sizeof (struct acl_ip_label *)))
23585 ++ return ERR_PTR(-EFAULT);
23586 ++
23587 ++ if (copy_from_user
23588 ++ (*(i_tmp + i_num), i_utmp2,
23589 ++ sizeof (struct acl_ip_label)))
23590 ++ return ERR_PTR(-EFAULT);
23591 ++
23592 ++ if ((*(i_tmp + i_num))->iface == NULL)
23593 ++ continue;
23594 ++
23595 ++ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
23596 ++ if (!len || len >= IFNAMSIZ)
23597 ++ return ERR_PTR(-EINVAL);
23598 ++ tmp = acl_alloc(len);
23599 ++ if (tmp == NULL)
23600 ++ return ERR_PTR(-ENOMEM);
23601 ++ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
23602 ++ return ERR_PTR(-EFAULT);
23603 ++ (*(i_tmp + i_num))->iface = tmp;
23604 ++ }
23605 ++
23606 ++ s_tmp->ips = i_tmp;
23607 ++
23608 ++insert:
23609 ++ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
23610 ++ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
23611 ++ return ERR_PTR(-ENOMEM);
23612 ++
23613 ++ return s_tmp;
23614 ++}
23615 ++
23616 ++static int
23617 ++copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
23618 ++{
23619 ++ struct acl_subject_label s_pre;
23620 ++ struct acl_subject_label * ret;
23621 ++ int err;
23622 ++
23623 ++ while (userp) {
23624 ++ if (copy_from_user(&s_pre, userp,
23625 ++ sizeof (struct acl_subject_label)))
23626 ++ return -EFAULT;
23627 ++
23628 ++ /* do not add nested subjects here, add
23629 ++ while parsing objects
23630 ++ */
23631 ++
23632 ++ if (s_pre.mode & GR_NESTED) {
23633 ++ userp = s_pre.prev;
23634 ++ continue;
23635 ++ }
23636 ++
23637 ++ ret = do_copy_user_subj(userp, role);
23638 ++
23639 ++ err = PTR_ERR(ret);
23640 ++ if (IS_ERR(ret))
23641 ++ return err;
23642 ++
23643 ++ insert_acl_subj_label(ret, role);
23644 ++
23645 ++ userp = s_pre.prev;
23646 ++ }
23647 ++
23648 ++ return 0;
23649 ++}
23650 ++
23651 ++static int
23652 ++copy_user_acl(struct gr_arg *arg)
23653 ++{
23654 ++ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
23655 ++ struct sprole_pw *sptmp;
23656 ++ struct gr_hash_struct *ghash;
23657 ++ uid_t *domainlist;
23658 ++ unsigned int r_num;
23659 ++ unsigned int len;
23660 ++ char *tmp;
23661 ++ int err = 0;
23662 ++ __u16 i;
23663 ++ __u32 num_subjs;
23664 ++
23665 ++ /* we need a default and kernel role */
23666 ++ if (arg->role_db.num_roles < 2)
23667 ++ return -EINVAL;
23668 ++
23669 ++ /* copy special role authentication info from userspace */
23670 ++
23671 ++ num_sprole_pws = arg->num_sprole_pws;
23672 ++ acl_special_roles = (struct sprole_pw **) acl_alloc(num_sprole_pws * sizeof(struct sprole_pw *));
23673 ++
23674 ++ if (!acl_special_roles) {
23675 ++ err = -ENOMEM;
23676 ++ goto cleanup;
23677 ++ }
23678 ++
23679 ++ for (i = 0; i < num_sprole_pws; i++) {
23680 ++ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
23681 ++ if (!sptmp) {
23682 ++ err = -ENOMEM;
23683 ++ goto cleanup;
23684 ++ }
23685 ++ if (copy_from_user(sptmp, arg->sprole_pws + i,
23686 ++ sizeof (struct sprole_pw))) {
23687 ++ err = -EFAULT;
23688 ++ goto cleanup;
23689 ++ }
23690 ++
23691 ++ len =
23692 ++ strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
23693 ++
23694 ++ if (!len || len >= GR_SPROLE_LEN) {
23695 ++ err = -EINVAL;
23696 ++ goto cleanup;
23697 ++ }
23698 ++
23699 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
23700 ++ err = -ENOMEM;
23701 ++ goto cleanup;
23702 ++ }
23703 ++
23704 ++ if (copy_from_user(tmp, sptmp->rolename, len)) {
23705 ++ err = -EFAULT;
23706 ++ goto cleanup;
23707 ++ }
23708 ++
23709 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
23710 ++ printk(KERN_ALERT "Copying special role %s\n", tmp);
23711 ++#endif
23712 ++ sptmp->rolename = tmp;
23713 ++ acl_special_roles[i] = sptmp;
23714 ++ }
23715 ++
23716 ++ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
23717 ++
23718 ++ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
23719 ++ r_tmp = acl_alloc(sizeof (struct acl_role_label));
23720 ++
23721 ++ if (!r_tmp) {
23722 ++ err = -ENOMEM;
23723 ++ goto cleanup;
23724 ++ }
23725 ++
23726 ++ if (copy_from_user(&r_utmp2, r_utmp + r_num,
23727 ++ sizeof (struct acl_role_label *))) {
23728 ++ err = -EFAULT;
23729 ++ goto cleanup;
23730 ++ }
23731 ++
23732 ++ if (copy_from_user(r_tmp, r_utmp2,
23733 ++ sizeof (struct acl_role_label))) {
23734 ++ err = -EFAULT;
23735 ++ goto cleanup;
23736 ++ }
23737 ++
23738 ++ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
23739 ++
23740 ++ if (!len || len >= PATH_MAX) {
23741 ++ err = -EINVAL;
23742 ++ goto cleanup;
23743 ++ }
23744 ++
23745 ++ if ((tmp = (char *) acl_alloc(len)) == NULL) {
23746 ++ err = -ENOMEM;
23747 ++ goto cleanup;
23748 ++ }
23749 ++ if (copy_from_user(tmp, r_tmp->rolename, len)) {
23750 ++ err = -EFAULT;
23751 ++ goto cleanup;
23752 ++ }
23753 ++ r_tmp->rolename = tmp;
23754 ++
23755 ++ if (!strcmp(r_tmp->rolename, "default")
23756 ++ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
23757 ++ default_role = r_tmp;
23758 ++ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
23759 ++ kernel_role = r_tmp;
23760 ++ }
23761 ++
23762 ++ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL) {
23763 ++ err = -ENOMEM;
23764 ++ goto cleanup;
23765 ++ }
23766 ++ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct))) {
23767 ++ err = -EFAULT;
23768 ++ goto cleanup;
23769 ++ }
23770 ++
23771 ++ r_tmp->hash = ghash;
23772 ++
23773 ++ num_subjs = count_user_subjs(r_tmp->hash->first);
23774 ++
23775 ++ r_tmp->subj_hash_size = num_subjs;
23776 ++ r_tmp->subj_hash =
23777 ++ (struct acl_subject_label **)
23778 ++ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
23779 ++
23780 ++ if (!r_tmp->subj_hash) {
23781 ++ err = -ENOMEM;
23782 ++ goto cleanup;
23783 ++ }
23784 ++
23785 ++ err = copy_user_allowedips(r_tmp);
23786 ++ if (err)
23787 ++ goto cleanup;
23788 ++
23789 ++ /* copy domain info */
23790 ++ if (r_tmp->domain_children != NULL) {
23791 ++ domainlist = acl_alloc(r_tmp->domain_child_num * sizeof(uid_t));
23792 ++ if (domainlist == NULL) {
23793 ++ err = -ENOMEM;
23794 ++ goto cleanup;
23795 ++ }
23796 ++ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t))) {
23797 ++ err = -EFAULT;
23798 ++ goto cleanup;
23799 ++ }
23800 ++ r_tmp->domain_children = domainlist;
23801 ++ }
23802 ++
23803 ++ err = copy_user_transitions(r_tmp);
23804 ++ if (err)
23805 ++ goto cleanup;
23806 ++
23807 ++ memset(r_tmp->subj_hash, 0,
23808 ++ r_tmp->subj_hash_size *
23809 ++ sizeof (struct acl_subject_label *));
23810 ++
23811 ++ err = copy_user_subjs(r_tmp->hash->first, r_tmp);
23812 ++
23813 ++ if (err)
23814 ++ goto cleanup;
23815 ++
23816 ++ /* set nested subject list to null */
23817 ++ r_tmp->hash->first = NULL;
23818 ++
23819 ++ insert_acl_role_label(r_tmp);
23820 ++ }
23821 ++
23822 ++ goto return_err;
23823 ++ cleanup:
23824 ++ free_variables();
23825 ++ return_err:
23826 ++ return err;
23827 ++
23828 ++}
23829 ++
23830 ++static int
23831 ++gracl_init(struct gr_arg *args)
23832 ++{
23833 ++ int error = 0;
23834 ++
23835 ++ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
23836 ++ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
23837 ++
23838 ++ if (init_variables(args)) {
23839 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
23840 ++ error = -ENOMEM;
23841 ++ free_variables();
23842 ++ goto out;
23843 ++ }
23844 ++
23845 ++ error = copy_user_acl(args);
23846 ++ free_init_variables();
23847 ++ if (error) {
23848 ++ free_variables();
23849 ++ goto out;
23850 ++ }
23851 ++
23852 ++ if ((error = gr_set_acls(0))) {
23853 ++ free_variables();
23854 ++ goto out;
23855 ++ }
23856 ++
23857 ++ gr_status |= GR_READY;
23858 ++ out:
23859 ++ return error;
23860 ++}
23861 ++
23862 ++/* derived from glibc fnmatch() 0: match, 1: no match*/
23863 ++
23864 ++static int
23865 ++glob_match(const char *p, const char *n)
23866 ++{
23867 ++ char c;
23868 ++
23869 ++ while ((c = *p++) != '\0') {
23870 ++ switch (c) {
23871 ++ case '?':
23872 ++ if (*n == '\0')
23873 ++ return 1;
23874 ++ else if (*n == '/')
23875 ++ return 1;
23876 ++ break;
23877 ++ case '\\':
23878 ++ if (*n != c)
23879 ++ return 1;
23880 ++ break;
23881 ++ case '*':
23882 ++ for (c = *p++; c == '?' || c == '*'; c = *p++) {
23883 ++ if (*n == '/')
23884 ++ return 1;
23885 ++ else if (c == '?') {
23886 ++ if (*n == '\0')
23887 ++ return 1;
23888 ++ else
23889 ++ ++n;
23890 ++ }
23891 ++ }
23892 ++ if (c == '\0') {
23893 ++ return 0;
23894 ++ } else {
23895 ++ const char *endp;
23896 ++
23897 ++ if ((endp = strchr(n, '/')) == NULL)
23898 ++ endp = n + strlen(n);
23899 ++
23900 ++ if (c == '[') {
23901 ++ for (--p; n < endp; ++n)
23902 ++ if (!glob_match(p, n))
23903 ++ return 0;
23904 ++ } else if (c == '/') {
23905 ++ while (*n != '\0' && *n != '/')
23906 ++ ++n;
23907 ++ if (*n == '/' && !glob_match(p, n + 1))
23908 ++ return 0;
23909 ++ } else {
23910 ++ for (--p; n < endp; ++n)
23911 ++ if (*n == c && !glob_match(p, n))
23912 ++ return 0;
23913 ++ }
23914 ++
23915 ++ return 1;
23916 ++ }
23917 ++ case '[':
23918 ++ {
23919 ++ int not;
23920 ++ char cold;
23921 ++
23922 ++ if (*n == '\0' || *n == '/')
23923 ++ return 1;
23924 ++
23925 ++ not = (*p == '!' || *p == '^');
23926 ++ if (not)
23927 ++ ++p;
23928 ++
23929 ++ c = *p++;
23930 ++ for (;;) {
23931 ++ unsigned char fn = (unsigned char)*n;
23932 ++
23933 ++ if (c == '\0')
23934 ++ return 1;
23935 ++ else {
23936 ++ if (c == fn)
23937 ++ goto matched;
23938 ++ cold = c;
23939 ++ c = *p++;
23940 ++
23941 ++ if (c == '-' && *p != ']') {
23942 ++ unsigned char cend = *p++;
23943 ++
23944 ++ if (cend == '\0')
23945 ++ return 1;
23946 ++
23947 ++ if (cold <= fn && fn <= cend)
23948 ++ goto matched;
23949 ++
23950 ++ c = *p++;
23951 ++ }
23952 ++ }
23953 ++
23954 ++ if (c == ']')
23955 ++ break;
23956 ++ }
23957 ++ if (!not)
23958 ++ return 1;
23959 ++ break;
23960 ++ matched:
23961 ++ while (c != ']') {
23962 ++ if (c == '\0')
23963 ++ return 1;
23964 ++
23965 ++ c = *p++;
23966 ++ }
23967 ++ if (not)
23968 ++ return 1;
23969 ++ }
23970 ++ break;
23971 ++ default:
23972 ++ if (c != *n)
23973 ++ return 1;
23974 ++ }
23975 ++
23976 ++ ++n;
23977 ++ }
23978 ++
23979 ++ if (*n == '\0')
23980 ++ return 0;
23981 ++
23982 ++ if (*n == '/')
23983 ++ return 0;
23984 ++
23985 ++ return 1;
23986 ++}
23987 ++
23988 ++static struct acl_object_label *
23989 ++chk_glob_label(struct acl_object_label *globbed,
23990 ++ struct dentry *dentry, struct vfsmount *mnt, char **path)
23991 ++{
23992 ++ struct acl_object_label *tmp;
23993 ++
23994 ++ if (*path == NULL)
23995 ++ *path = gr_to_filename_nolock(dentry, mnt);
23996 ++
23997 ++ tmp = globbed;
23998 ++
23999 ++ while (tmp) {
24000 ++ if (!glob_match(tmp->filename, *path))
24001 ++ return tmp;
24002 ++ tmp = tmp->next;
24003 ++ }
24004 ++
24005 ++ return NULL;
24006 ++}
24007 ++
24008 ++static struct acl_object_label *
24009 ++__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
24010 ++ const ino_t curr_ino, const dev_t curr_dev,
24011 ++ const struct acl_subject_label *subj, char **path)
24012 ++{
24013 ++ struct acl_subject_label *tmpsubj;
24014 ++ struct acl_object_label *retval;
24015 ++ struct acl_object_label *retval2;
24016 ++
24017 ++ tmpsubj = (struct acl_subject_label *) subj;
24018 ++ read_lock(&gr_inode_lock);
24019 ++ do {
24020 ++ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
24021 ++ if (retval) {
24022 ++ if (retval->globbed) {
24023 ++ retval2 = chk_glob_label(retval->globbed, (struct dentry *)orig_dentry,
24024 ++ (struct vfsmount *)orig_mnt, path);
24025 ++ if (retval2)
24026 ++ retval = retval2;
24027 ++ }
24028 ++ break;
24029 ++ }
24030 ++ } while ((tmpsubj = tmpsubj->parent_subject));
24031 ++ read_unlock(&gr_inode_lock);
24032 ++
24033 ++ return retval;
24034 ++}
24035 ++
24036 ++static __inline__ struct acl_object_label *
24037 ++full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
24038 ++ const struct dentry *curr_dentry,
24039 ++ const struct acl_subject_label *subj, char **path)
24040 ++{
24041 ++ return __full_lookup(orig_dentry, orig_mnt,
24042 ++ curr_dentry->d_inode->i_ino,
24043 ++ curr_dentry->d_inode->i_sb->s_dev, subj, path);
24044 ++}
24045 ++
24046 ++static struct acl_object_label *
24047 ++__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
24048 ++ const struct acl_subject_label *subj, char *path)
24049 ++{
24050 ++ struct dentry *dentry = (struct dentry *) l_dentry;
24051 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
24052 ++ struct acl_object_label *retval;
24053 ++
24054 ++ spin_lock(&dcache_lock);
24055 ++
24056 ++ if (unlikely(mnt == shm_mnt || mnt == pipe_mnt || mnt == sock_mnt ||
24057 ++ /* ignore Eric Biederman */
24058 ++ IS_PRIVATE(l_dentry->d_inode))) {
24059 ++ retval = fakefs_obj;
24060 ++ goto out;
24061 ++ }
24062 ++
24063 ++ for (;;) {
24064 ++ if (dentry == real_root && mnt == real_root_mnt)
24065 ++ break;
24066 ++
24067 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
24068 ++ if (mnt->mnt_parent == mnt)
24069 ++ break;
24070 ++
24071 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
24072 ++ if (retval != NULL)
24073 ++ goto out;
24074 ++
24075 ++ dentry = mnt->mnt_mountpoint;
24076 ++ mnt = mnt->mnt_parent;
24077 ++ continue;
24078 ++ }
24079 ++
24080 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
24081 ++ if (retval != NULL)
24082 ++ goto out;
24083 ++
24084 ++ dentry = dentry->d_parent;
24085 ++ }
24086 ++
24087 ++ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path);
24088 ++
24089 ++ if (retval == NULL)
24090 ++ retval = full_lookup(l_dentry, l_mnt, real_root, subj, &path);
24091 ++out:
24092 ++ spin_unlock(&dcache_lock);
24093 ++ return retval;
24094 ++}
24095 ++
24096 ++static __inline__ struct acl_object_label *
24097 ++chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
24098 ++ const struct acl_subject_label *subj)
24099 ++{
24100 ++ char *path = NULL;
24101 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
24102 ++}
24103 ++
24104 ++static __inline__ struct acl_object_label *
24105 ++chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
24106 ++ const struct acl_subject_label *subj, char *path)
24107 ++{
24108 ++ return __chk_obj_label(l_dentry, l_mnt, subj, path);
24109 ++}
24110 ++
24111 ++static struct acl_subject_label *
24112 ++chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
24113 ++ const struct acl_role_label *role)
24114 ++{
24115 ++ struct dentry *dentry = (struct dentry *) l_dentry;
24116 ++ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
24117 ++ struct acl_subject_label *retval;
24118 ++
24119 ++ spin_lock(&dcache_lock);
24120 ++
24121 ++ for (;;) {
24122 ++ if (dentry == real_root && mnt == real_root_mnt)
24123 ++ break;
24124 ++ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
24125 ++ if (mnt->mnt_parent == mnt)
24126 ++ break;
24127 ++
24128 ++ read_lock(&gr_inode_lock);
24129 ++ retval =
24130 ++ lookup_acl_subj_label(dentry->d_inode->i_ino,
24131 ++ dentry->d_inode->i_sb->s_dev, role);
24132 ++ read_unlock(&gr_inode_lock);
24133 ++ if (retval != NULL)
24134 ++ goto out;
24135 ++
24136 ++ dentry = mnt->mnt_mountpoint;
24137 ++ mnt = mnt->mnt_parent;
24138 ++ continue;
24139 ++ }
24140 ++
24141 ++ read_lock(&gr_inode_lock);
24142 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
24143 ++ dentry->d_inode->i_sb->s_dev, role);
24144 ++ read_unlock(&gr_inode_lock);
24145 ++ if (retval != NULL)
24146 ++ goto out;
24147 ++
24148 ++ dentry = dentry->d_parent;
24149 ++ }
24150 ++
24151 ++ read_lock(&gr_inode_lock);
24152 ++ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
24153 ++ dentry->d_inode->i_sb->s_dev, role);
24154 ++ read_unlock(&gr_inode_lock);
24155 ++
24156 ++ if (unlikely(retval == NULL)) {
24157 ++ read_lock(&gr_inode_lock);
24158 ++ retval = lookup_acl_subj_label(real_root->d_inode->i_ino,
24159 ++ real_root->d_inode->i_sb->s_dev, role);
24160 ++ read_unlock(&gr_inode_lock);
24161 ++ }
24162 ++out:
24163 ++ spin_unlock(&dcache_lock);
24164 ++
24165 ++ return retval;
24166 ++}
24167 ++
24168 ++static void
24169 ++gr_log_learn(const struct task_struct *task, const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
24170 ++{
24171 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
24172 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
24173 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
24174 ++ 1, 1, gr_to_filename(dentry, mnt), (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
24175 ++
24176 ++ return;
24177 ++}
24178 ++
24179 ++static void
24180 ++gr_log_learn_sysctl(const struct task_struct *task, const char *path, const __u32 mode)
24181 ++{
24182 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
24183 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
24184 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
24185 ++ 1, 1, path, (unsigned long) mode, NIPQUAD(task->signal->curr_ip));
24186 ++
24187 ++ return;
24188 ++}
24189 ++
24190 ++static void
24191 ++gr_log_learn_id_change(const struct task_struct *task, const char type, const unsigned int real,
24192 ++ const unsigned int effective, const unsigned int fs)
24193 ++{
24194 ++ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
24195 ++ task->uid, task->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
24196 ++ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
24197 ++ type, real, effective, fs, NIPQUAD(task->signal->curr_ip));
24198 ++
24199 ++ return;
24200 ++}
24201 ++
24202 ++__u32
24203 ++gr_check_link(const struct dentry * new_dentry,
24204 ++ const struct dentry * parent_dentry,
24205 ++ const struct vfsmount * parent_mnt,
24206 ++ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
24207 ++{
24208 ++ struct acl_object_label *obj;
24209 ++ __u32 oldmode, newmode;
24210 ++ __u32 needmode;
24211 ++
24212 ++ if (unlikely(!(gr_status & GR_READY)))
24213 ++ return (GR_CREATE | GR_LINK);
24214 ++
24215 ++ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
24216 ++ oldmode = obj->mode;
24217 ++
24218 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
24219 ++ oldmode |= (GR_CREATE | GR_LINK);
24220 ++
24221 ++ needmode = GR_CREATE | GR_AUDIT_CREATE | GR_SUPPRESS;
24222 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
24223 ++ needmode |= GR_SETID | GR_AUDIT_SETID;
24224 ++
24225 ++ newmode =
24226 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
24227 ++ oldmode | needmode);
24228 ++
24229 ++ needmode = newmode & (GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC |
24230 ++ GR_SETID | GR_READ | GR_FIND | GR_DELETE |
24231 ++ GR_INHERIT | GR_AUDIT_INHERIT);
24232 ++
24233 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID) && !(newmode & GR_SETID))
24234 ++ goto bad;
24235 ++
24236 ++ if ((oldmode & needmode) != needmode)
24237 ++ goto bad;
24238 ++
24239 ++ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
24240 ++ if ((newmode & needmode) != needmode)
24241 ++ goto bad;
24242 ++
24243 ++ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
24244 ++ return newmode;
24245 ++bad:
24246 ++ needmode = oldmode;
24247 ++ if (old_dentry->d_inode->i_mode & (S_ISUID | S_ISGID))
24248 ++ needmode |= GR_SETID;
24249 ++
24250 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
24251 ++ gr_log_learn(current, old_dentry, old_mnt, needmode);
24252 ++ return (GR_CREATE | GR_LINK);
24253 ++ } else if (newmode & GR_SUPPRESS)
24254 ++ return GR_SUPPRESS;
24255 ++ else
24256 ++ return 0;
24257 ++}
24258 ++
24259 ++__u32
24260 ++gr_search_file(const struct dentry * dentry, const __u32 mode,
24261 ++ const struct vfsmount * mnt)
24262 ++{
24263 ++ __u32 retval = mode;
24264 ++ struct acl_subject_label *curracl;
24265 ++ struct acl_object_label *currobj;
24266 ++
24267 ++ if (unlikely(!(gr_status & GR_READY)))
24268 ++ return (mode & ~GR_AUDITS);
24269 ++
24270 ++ curracl = current->acl;
24271 ++
24272 ++ currobj = chk_obj_label(dentry, mnt, curracl);
24273 ++ retval = currobj->mode & mode;
24274 ++
24275 ++ if (unlikely
24276 ++ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
24277 ++ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
24278 ++ __u32 new_mode = mode;
24279 ++
24280 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
24281 ++
24282 ++ retval = new_mode;
24283 ++
24284 ++ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
24285 ++ new_mode |= GR_INHERIT;
24286 ++
24287 ++ if (!(mode & GR_NOLEARN))
24288 ++ gr_log_learn(current, dentry, mnt, new_mode);
24289 ++ }
24290 ++
24291 ++ return retval;
24292 ++}
24293 ++
24294 ++__u32
24295 ++gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
24296 ++ const struct vfsmount * mnt, const __u32 mode)
24297 ++{
24298 ++ struct name_entry *match;
24299 ++ struct acl_object_label *matchpo;
24300 ++ struct acl_subject_label *curracl;
24301 ++ char *path;
24302 ++ __u32 retval;
24303 ++
24304 ++ if (unlikely(!(gr_status & GR_READY)))
24305 ++ return (mode & ~GR_AUDITS);
24306 ++
24307 ++ preempt_disable();
24308 ++ path = gr_to_filename_rbac(new_dentry, mnt);
24309 ++ match = lookup_name_entry_create(path);
24310 ++
24311 ++ if (!match)
24312 ++ goto check_parent;
24313 ++
24314 ++ curracl = current->acl;
24315 ++
24316 ++ read_lock(&gr_inode_lock);
24317 ++ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
24318 ++ read_unlock(&gr_inode_lock);
24319 ++
24320 ++ if (matchpo) {
24321 ++ if ((matchpo->mode & mode) !=
24322 ++ (mode & ~(GR_AUDITS | GR_SUPPRESS))
24323 ++ && curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
24324 ++ __u32 new_mode = mode;
24325 ++
24326 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
24327 ++
24328 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
24329 ++
24330 ++ preempt_enable();
24331 ++ return new_mode;
24332 ++ }
24333 ++ preempt_enable();
24334 ++ return (matchpo->mode & mode);
24335 ++ }
24336 ++
24337 ++ check_parent:
24338 ++ curracl = current->acl;
24339 ++
24340 ++ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
24341 ++ retval = matchpo->mode & mode;
24342 ++
24343 ++ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
24344 ++ && (curracl->mode & (GR_LEARN | GR_INHERITLEARN))) {
24345 ++ __u32 new_mode = mode;
24346 ++
24347 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
24348 ++
24349 ++ gr_log_learn(current, new_dentry, mnt, new_mode);
24350 ++ preempt_enable();
24351 ++ return new_mode;
24352 ++ }
24353 ++
24354 ++ preempt_enable();
24355 ++ return retval;
24356 ++}
24357 ++
24358 ++int
24359 ++gr_check_hidden_task(const struct task_struct *task)
24360 ++{
24361 ++ if (unlikely(!(gr_status & GR_READY)))
24362 ++ return 0;
24363 ++
24364 ++ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
24365 ++ return 1;
24366 ++
24367 ++ return 0;
24368 ++}
24369 ++
24370 ++int
24371 ++gr_check_protected_task(const struct task_struct *task)
24372 ++{
24373 ++ if (unlikely(!(gr_status & GR_READY) || !task))
24374 ++ return 0;
24375 ++
24376 ++ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
24377 ++ task->acl != current->acl)
24378 ++ return 1;
24379 ++
24380 ++ return 0;
24381 ++}
24382 ++
24383 ++void
24384 ++gr_copy_label(struct task_struct *tsk)
24385 ++{
24386 ++ tsk->signal->used_accept = 0;
24387 ++ tsk->acl_sp_role = 0;
24388 ++ tsk->acl_role_id = current->acl_role_id;
24389 ++ tsk->acl = current->acl;
24390 ++ tsk->role = current->role;
24391 ++ tsk->signal->curr_ip = current->signal->curr_ip;
24392 ++ if (current->exec_file)
24393 ++ get_file(current->exec_file);
24394 ++ tsk->exec_file = current->exec_file;
24395 ++ tsk->is_writable = current->is_writable;
24396 ++ if (unlikely(current->signal->used_accept))
24397 ++ current->signal->curr_ip = 0;
24398 ++
24399 ++ return;
24400 ++}
24401 ++
24402 ++static void
24403 ++gr_set_proc_res(struct task_struct *task)
24404 ++{
24405 ++ struct acl_subject_label *proc;
24406 ++ unsigned short i;
24407 ++
24408 ++ proc = task->acl;
24409 ++
24410 ++ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
24411 ++ return;
24412 ++
24413 ++ for (i = 0; i < (GR_NLIMITS - 1); i++) {
24414 ++ if (!(proc->resmask & (1 << i)))
24415 ++ continue;
24416 ++
24417 ++ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
24418 ++ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
24419 ++ }
24420 ++
24421 ++ return;
24422 ++}
24423 ++
24424 ++int
24425 ++gr_check_user_change(int real, int effective, int fs)
24426 ++{
24427 ++ unsigned int i;
24428 ++ __u16 num;
24429 ++ uid_t *uidlist;
24430 ++ int curuid;
24431 ++ int realok = 0;
24432 ++ int effectiveok = 0;
24433 ++ int fsok = 0;
24434 ++
24435 ++ if (unlikely(!(gr_status & GR_READY)))
24436 ++ return 0;
24437 ++
24438 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
24439 ++ gr_log_learn_id_change(current, 'u', real, effective, fs);
24440 ++
24441 ++ num = current->acl->user_trans_num;
24442 ++ uidlist = current->acl->user_transitions;
24443 ++
24444 ++ if (uidlist == NULL)
24445 ++ return 0;
24446 ++
24447 ++ if (real == -1)
24448 ++ realok = 1;
24449 ++ if (effective == -1)
24450 ++ effectiveok = 1;
24451 ++ if (fs == -1)
24452 ++ fsok = 1;
24453 ++
24454 ++ if (current->acl->user_trans_type & GR_ID_ALLOW) {
24455 ++ for (i = 0; i < num; i++) {
24456 ++ curuid = (int)uidlist[i];
24457 ++ if (real == curuid)
24458 ++ realok = 1;
24459 ++ if (effective == curuid)
24460 ++ effectiveok = 1;
24461 ++ if (fs == curuid)
24462 ++ fsok = 1;
24463 ++ }
24464 ++ } else if (current->acl->user_trans_type & GR_ID_DENY) {
24465 ++ for (i = 0; i < num; i++) {
24466 ++ curuid = (int)uidlist[i];
24467 ++ if (real == curuid)
24468 ++ break;
24469 ++ if (effective == curuid)
24470 ++ break;
24471 ++ if (fs == curuid)
24472 ++ break;
24473 ++ }
24474 ++ /* not in deny list */
24475 ++ if (i == num) {
24476 ++ realok = 1;
24477 ++ effectiveok = 1;
24478 ++ fsok = 1;
24479 ++ }
24480 ++ }
24481 ++
24482 ++ if (realok && effectiveok && fsok)
24483 ++ return 0;
24484 ++ else {
24485 ++ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
24486 ++ return 1;
24487 ++ }
24488 ++}
24489 ++
24490 ++int
24491 ++gr_check_group_change(int real, int effective, int fs)
24492 ++{
24493 ++ unsigned int i;
24494 ++ __u16 num;
24495 ++ gid_t *gidlist;
24496 ++ int curgid;
24497 ++ int realok = 0;
24498 ++ int effectiveok = 0;
24499 ++ int fsok = 0;
24500 ++
24501 ++ if (unlikely(!(gr_status & GR_READY)))
24502 ++ return 0;
24503 ++
24504 ++ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
24505 ++ gr_log_learn_id_change(current, 'g', real, effective, fs);
24506 ++
24507 ++ num = current->acl->group_trans_num;
24508 ++ gidlist = current->acl->group_transitions;
24509 ++
24510 ++ if (gidlist == NULL)
24511 ++ return 0;
24512 ++
24513 ++ if (real == -1)
24514 ++ realok = 1;
24515 ++ if (effective == -1)
24516 ++ effectiveok = 1;
24517 ++ if (fs == -1)
24518 ++ fsok = 1;
24519 ++
24520 ++ if (current->acl->group_trans_type & GR_ID_ALLOW) {
24521 ++ for (i = 0; i < num; i++) {
24522 ++ curgid = (int)gidlist[i];
24523 ++ if (real == curgid)
24524 ++ realok = 1;
24525 ++ if (effective == curgid)
24526 ++ effectiveok = 1;
24527 ++ if (fs == curgid)
24528 ++ fsok = 1;
24529 ++ }
24530 ++ } else if (current->acl->group_trans_type & GR_ID_DENY) {
24531 ++ for (i = 0; i < num; i++) {
24532 ++ curgid = (int)gidlist[i];
24533 ++ if (real == curgid)
24534 ++ break;
24535 ++ if (effective == curgid)
24536 ++ break;
24537 ++ if (fs == curgid)
24538 ++ break;
24539 ++ }
24540 ++ /* not in deny list */
24541 ++ if (i == num) {
24542 ++ realok = 1;
24543 ++ effectiveok = 1;
24544 ++ fsok = 1;
24545 ++ }
24546 ++ }
24547 ++
24548 ++ if (realok && effectiveok && fsok)
24549 ++ return 0;
24550 ++ else {
24551 ++ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
24552 ++ return 1;
24553 ++ }
24554 ++}
24555 ++
24556 ++void
24557 ++gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
24558 ++{
24559 ++ struct acl_role_label *role = task->role;
24560 ++ struct acl_subject_label *subj = NULL;
24561 ++ struct acl_object_label *obj;
24562 ++ struct file *filp;
24563 ++
24564 ++ if (unlikely(!(gr_status & GR_READY)))
24565 ++ return;
24566 ++
24567 ++ filp = task->exec_file;
24568 ++
24569 ++ /* kernel process, we'll give them the kernel role */
24570 ++ if (unlikely(!filp)) {
24571 ++ task->role = kernel_role;
24572 ++ task->acl = kernel_role->root_label;
24573 ++ return;
24574 ++ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
24575 ++ role = lookup_acl_role_label(task, uid, gid);
24576 ++
24577 ++ /* perform subject lookup in possibly new role
24578 ++ we can use this result below in the case where role == task->role
24579 ++ */
24580 ++ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
24581 ++
24582 ++ /* if we changed uid/gid, but result in the same role
24583 ++ and are using inheritance, don't lose the inherited subject
24584 ++ if current subject is other than what normal lookup
24585 ++ would result in, we arrived via inheritance, don't
24586 ++ lose subject
24587 ++ */
24588 ++ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
24589 ++ (subj == task->acl)))
24590 ++ task->acl = subj;
24591 ++
24592 ++ task->role = role;
24593 ++
24594 ++ task->is_writable = 0;
24595 ++
24596 ++ /* ignore additional mmap checks for processes that are writable
24597 ++ by the default ACL */
24598 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
24599 ++ if (unlikely(obj->mode & GR_WRITE))
24600 ++ task->is_writable = 1;
24601 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
24602 ++ if (unlikely(obj->mode & GR_WRITE))
24603 ++ task->is_writable = 1;
24604 ++
24605 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
24606 ++ printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
24607 ++#endif
24608 ++
24609 ++ gr_set_proc_res(task);
24610 ++
24611 ++ return;
24612 ++}
24613 ++
24614 ++int
24615 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
24616 ++{
24617 ++ struct task_struct *task = current;
24618 ++ struct acl_subject_label *newacl;
24619 ++ struct acl_object_label *obj;
24620 ++ __u32 retmode;
24621 ++
24622 ++ if (unlikely(!(gr_status & GR_READY)))
24623 ++ return 0;
24624 ++
24625 ++ newacl = chk_subj_label(dentry, mnt, task->role);
24626 ++
24627 ++ task_lock(task);
24628 ++ if (((task->ptrace & PT_PTRACED) && !(task->acl->mode &
24629 ++ GR_POVERRIDE) && (task->acl != newacl) &&
24630 ++ !(task->role->roletype & GR_ROLE_GOD) &&
24631 ++ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
24632 ++ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) ||
24633 ++ (atomic_read(&task->fs->count) > 1 ||
24634 ++ atomic_read(&task->files->count) > 1 ||
24635 ++ atomic_read(&task->sighand->count) > 1)) {
24636 ++ task_unlock(task);
24637 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
24638 ++ return -EACCES;
24639 ++ }
24640 ++ task_unlock(task);
24641 ++
24642 ++ obj = chk_obj_label(dentry, mnt, task->acl);
24643 ++ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
24644 ++
24645 ++ if (!(task->acl->mode & GR_INHERITLEARN) &&
24646 ++ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
24647 ++ if (obj->nested)
24648 ++ task->acl = obj->nested;
24649 ++ else
24650 ++ task->acl = newacl;
24651 ++ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
24652 ++ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
24653 ++
24654 ++ task->is_writable = 0;
24655 ++
24656 ++ /* ignore additional mmap checks for processes that are writable
24657 ++ by the default ACL */
24658 ++ obj = chk_obj_label(dentry, mnt, default_role->root_label);
24659 ++ if (unlikely(obj->mode & GR_WRITE))
24660 ++ task->is_writable = 1;
24661 ++ obj = chk_obj_label(dentry, mnt, task->role->root_label);
24662 ++ if (unlikely(obj->mode & GR_WRITE))
24663 ++ task->is_writable = 1;
24664 ++
24665 ++ gr_set_proc_res(task);
24666 ++
24667 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
24668 ++ printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
24669 ++#endif
24670 ++ return 0;
24671 ++}
24672 ++
24673 ++/* always called with valid inodev ptr */
24674 ++static void
24675 ++do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
24676 ++{
24677 ++ struct acl_object_label *matchpo;
24678 ++ struct acl_subject_label *matchps;
24679 ++ struct acl_subject_label *subj;
24680 ++ struct acl_role_label *role;
24681 ++ unsigned int i, x;
24682 ++
24683 ++ FOR_EACH_ROLE_START(role, i)
24684 ++ FOR_EACH_SUBJECT_START(role, subj, x)
24685 ++ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
24686 ++ matchpo->mode |= GR_DELETED;
24687 ++ FOR_EACH_SUBJECT_END(subj,x)
24688 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
24689 ++ if (subj->inode == ino && subj->device == dev)
24690 ++ subj->mode |= GR_DELETED;
24691 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
24692 ++ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
24693 ++ matchps->mode |= GR_DELETED;
24694 ++ FOR_EACH_ROLE_END(role,i)
24695 ++
24696 ++ inodev->nentry->deleted = 1;
24697 ++
24698 ++ return;
24699 ++}
24700 ++
24701 ++void
24702 ++gr_handle_delete(const ino_t ino, const dev_t dev)
24703 ++{
24704 ++ struct inodev_entry *inodev;
24705 ++
24706 ++ if (unlikely(!(gr_status & GR_READY)))
24707 ++ return;
24708 ++
24709 ++ write_lock(&gr_inode_lock);
24710 ++ inodev = lookup_inodev_entry(ino, dev);
24711 ++ if (inodev != NULL)
24712 ++ do_handle_delete(inodev, ino, dev);
24713 ++ write_unlock(&gr_inode_lock);
24714 ++
24715 ++ return;
24716 ++}
24717 ++
24718 ++static void
24719 ++update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
24720 ++ const ino_t newinode, const dev_t newdevice,
24721 ++ struct acl_subject_label *subj)
24722 ++{
24723 ++ unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
24724 ++ struct acl_object_label *match;
24725 ++
24726 ++ match = subj->obj_hash[index];
24727 ++
24728 ++ while (match && (match->inode != oldinode ||
24729 ++ match->device != olddevice ||
24730 ++ !(match->mode & GR_DELETED)))
24731 ++ match = match->next;
24732 ++
24733 ++ if (match && (match->inode == oldinode)
24734 ++ && (match->device == olddevice)
24735 ++ && (match->mode & GR_DELETED)) {
24736 ++ if (match->prev == NULL) {
24737 ++ subj->obj_hash[index] = match->next;
24738 ++ if (match->next != NULL)
24739 ++ match->next->prev = NULL;
24740 ++ } else {
24741 ++ match->prev->next = match->next;
24742 ++ if (match->next != NULL)
24743 ++ match->next->prev = match->prev;
24744 ++ }
24745 ++ match->prev = NULL;
24746 ++ match->next = NULL;
24747 ++ match->inode = newinode;
24748 ++ match->device = newdevice;
24749 ++ match->mode &= ~GR_DELETED;
24750 ++
24751 ++ insert_acl_obj_label(match, subj);
24752 ++ }
24753 ++
24754 ++ return;
24755 ++}
24756 ++
24757 ++static void
24758 ++update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
24759 ++ const ino_t newinode, const dev_t newdevice,
24760 ++ struct acl_role_label *role)
24761 ++{
24762 ++ unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
24763 ++ struct acl_subject_label *match;
24764 ++
24765 ++ match = role->subj_hash[index];
24766 ++
24767 ++ while (match && (match->inode != oldinode ||
24768 ++ match->device != olddevice ||
24769 ++ !(match->mode & GR_DELETED)))
24770 ++ match = match->next;
24771 ++
24772 ++ if (match && (match->inode == oldinode)
24773 ++ && (match->device == olddevice)
24774 ++ && (match->mode & GR_DELETED)) {
24775 ++ if (match->prev == NULL) {
24776 ++ role->subj_hash[index] = match->next;
24777 ++ if (match->next != NULL)
24778 ++ match->next->prev = NULL;
24779 ++ } else {
24780 ++ match->prev->next = match->next;
24781 ++ if (match->next != NULL)
24782 ++ match->next->prev = match->prev;
24783 ++ }
24784 ++ match->prev = NULL;
24785 ++ match->next = NULL;
24786 ++ match->inode = newinode;
24787 ++ match->device = newdevice;
24788 ++ match->mode &= ~GR_DELETED;
24789 ++
24790 ++ insert_acl_subj_label(match, role);
24791 ++ }
24792 ++
24793 ++ return;
24794 ++}
24795 ++
24796 ++static void
24797 ++update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
24798 ++ const ino_t newinode, const dev_t newdevice)
24799 ++{
24800 ++ unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
24801 ++ struct inodev_entry *match;
24802 ++
24803 ++ match = inodev_set.i_hash[index];
24804 ++
24805 ++ while (match && (match->nentry->inode != oldinode ||
24806 ++ match->nentry->device != olddevice || !match->nentry->deleted))
24807 ++ match = match->next;
24808 ++
24809 ++ if (match && (match->nentry->inode == oldinode)
24810 ++ && (match->nentry->device == olddevice) &&
24811 ++ match->nentry->deleted) {
24812 ++ if (match->prev == NULL) {
24813 ++ inodev_set.i_hash[index] = match->next;
24814 ++ if (match->next != NULL)
24815 ++ match->next->prev = NULL;
24816 ++ } else {
24817 ++ match->prev->next = match->next;
24818 ++ if (match->next != NULL)
24819 ++ match->next->prev = match->prev;
24820 ++ }
24821 ++ match->prev = NULL;
24822 ++ match->next = NULL;
24823 ++ match->nentry->inode = newinode;
24824 ++ match->nentry->device = newdevice;
24825 ++ match->nentry->deleted = 0;
24826 ++
24827 ++ insert_inodev_entry(match);
24828 ++ }
24829 ++
24830 ++ return;
24831 ++}
24832 ++
24833 ++static void
24834 ++do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
24835 ++ const struct vfsmount *mnt)
24836 ++{
24837 ++ struct acl_subject_label *subj;
24838 ++ struct acl_role_label *role;
24839 ++ unsigned int i, x;
24840 ++
24841 ++ FOR_EACH_ROLE_START(role, i)
24842 ++ update_acl_subj_label(matchn->inode, matchn->device,
24843 ++ dentry->d_inode->i_ino,
24844 ++ dentry->d_inode->i_sb->s_dev, role);
24845 ++
24846 ++ FOR_EACH_NESTED_SUBJECT_START(role, subj)
24847 ++ if ((subj->inode == dentry->d_inode->i_ino) &&
24848 ++ (subj->device == dentry->d_inode->i_sb->s_dev)) {
24849 ++ subj->inode = dentry->d_inode->i_ino;
24850 ++ subj->device = dentry->d_inode->i_sb->s_dev;
24851 ++ }
24852 ++ FOR_EACH_NESTED_SUBJECT_END(subj)
24853 ++ FOR_EACH_SUBJECT_START(role, subj, x)
24854 ++ update_acl_obj_label(matchn->inode, matchn->device,
24855 ++ dentry->d_inode->i_ino,
24856 ++ dentry->d_inode->i_sb->s_dev, subj);
24857 ++ FOR_EACH_SUBJECT_END(subj,x)
24858 ++ FOR_EACH_ROLE_END(role,i)
24859 ++
24860 ++ update_inodev_entry(matchn->inode, matchn->device,
24861 ++ dentry->d_inode->i_ino, dentry->d_inode->i_sb->s_dev);
24862 ++
24863 ++ return;
24864 ++}
24865 ++
24866 ++void
24867 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
24868 ++{
24869 ++ struct name_entry *matchn;
24870 ++
24871 ++ if (unlikely(!(gr_status & GR_READY)))
24872 ++ return;
24873 ++
24874 ++ preempt_disable();
24875 ++ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
24876 ++
24877 ++ if (unlikely((unsigned long)matchn)) {
24878 ++ write_lock(&gr_inode_lock);
24879 ++ do_handle_create(matchn, dentry, mnt);
24880 ++ write_unlock(&gr_inode_lock);
24881 ++ }
24882 ++ preempt_enable();
24883 ++
24884 ++ return;
24885 ++}
24886 ++
24887 ++void
24888 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
24889 ++ struct dentry *old_dentry,
24890 ++ struct dentry *new_dentry,
24891 ++ struct vfsmount *mnt, const __u8 replace)
24892 ++{
24893 ++ struct name_entry *matchn;
24894 ++ struct inodev_entry *inodev;
24895 ++
24896 ++ /* vfs_rename swaps the name and parent link for old_dentry and
24897 ++ new_dentry
24898 ++ at this point, old_dentry has the new name, parent link, and inode
24899 ++ for the renamed file
24900 ++ if a file is being replaced by a rename, new_dentry has the inode
24901 ++ and name for the replaced file
24902 ++ */
24903 ++
24904 ++ if (unlikely(!(gr_status & GR_READY)))
24905 ++ return;
24906 ++
24907 ++ preempt_disable();
24908 ++ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
24909 ++
24910 ++ /* we wouldn't have to check d_inode if it weren't for
24911 ++ NFS silly-renaming
24912 ++ */
24913 ++
24914 ++ write_lock(&gr_inode_lock);
24915 ++ if (unlikely(replace && new_dentry->d_inode)) {
24916 ++ inodev = lookup_inodev_entry(new_dentry->d_inode->i_ino,
24917 ++ new_dentry->d_inode->i_sb->s_dev);
24918 ++ if (inodev != NULL && (new_dentry->d_inode->i_nlink <= 1))
24919 ++ do_handle_delete(inodev, new_dentry->d_inode->i_ino,
24920 ++ new_dentry->d_inode->i_sb->s_dev);
24921 ++ }
24922 ++
24923 ++ inodev = lookup_inodev_entry(old_dentry->d_inode->i_ino,
24924 ++ old_dentry->d_inode->i_sb->s_dev);
24925 ++ if (inodev != NULL && (old_dentry->d_inode->i_nlink <= 1))
24926 ++ do_handle_delete(inodev, old_dentry->d_inode->i_ino,
24927 ++ old_dentry->d_inode->i_sb->s_dev);
24928 ++
24929 ++ if (unlikely((unsigned long)matchn))
24930 ++ do_handle_create(matchn, old_dentry, mnt);
24931 ++
24932 ++ write_unlock(&gr_inode_lock);
24933 ++ preempt_enable();
24934 ++
24935 ++ return;
24936 ++}
24937 ++
24938 ++static int
24939 ++lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
24940 ++ unsigned char **sum)
24941 ++{
24942 ++ struct acl_role_label *r;
24943 ++ struct role_allowed_ip *ipp;
24944 ++ struct role_transition *trans;
24945 ++ unsigned int i;
24946 ++ int found = 0;
24947 ++
24948 ++ /* check transition table */
24949 ++
24950 ++ for (trans = current->role->transitions; trans; trans = trans->next) {
24951 ++ if (!strcmp(rolename, trans->rolename)) {
24952 ++ found = 1;
24953 ++ break;
24954 ++ }
24955 ++ }
24956 ++
24957 ++ if (!found)
24958 ++ return 0;
24959 ++
24960 ++ /* handle special roles that do not require authentication
24961 ++ and check ip */
24962 ++
24963 ++ FOR_EACH_ROLE_START(r, i)
24964 ++ if (!strcmp(rolename, r->rolename) &&
24965 ++ (r->roletype & GR_ROLE_SPECIAL)) {
24966 ++ found = 0;
24967 ++ if (r->allowed_ips != NULL) {
24968 ++ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
24969 ++ if ((ntohl(current->signal->curr_ip) & ipp->netmask) ==
24970 ++ (ntohl(ipp->addr) & ipp->netmask))
24971 ++ found = 1;
24972 ++ }
24973 ++ } else
24974 ++ found = 2;
24975 ++ if (!found)
24976 ++ return 0;
24977 ++
24978 ++ if (((mode == SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
24979 ++ ((mode == SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
24980 ++ *salt = NULL;
24981 ++ *sum = NULL;
24982 ++ return 1;
24983 ++ }
24984 ++ }
24985 ++ FOR_EACH_ROLE_END(r,i)
24986 ++
24987 ++ for (i = 0; i < num_sprole_pws; i++) {
24988 ++ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
24989 ++ *salt = acl_special_roles[i]->salt;
24990 ++ *sum = acl_special_roles[i]->sum;
24991 ++ return 1;
24992 ++ }
24993 ++ }
24994 ++
24995 ++ return 0;
24996 ++}
24997 ++
24998 ++static void
24999 ++assign_special_role(char *rolename)
25000 ++{
25001 ++ struct acl_object_label *obj;
25002 ++ struct acl_role_label *r;
25003 ++ struct acl_role_label *assigned = NULL;
25004 ++ struct task_struct *tsk;
25005 ++ struct file *filp;
25006 ++ unsigned int i;
25007 ++
25008 ++ FOR_EACH_ROLE_START(r, i)
25009 ++ if (!strcmp(rolename, r->rolename) &&
25010 ++ (r->roletype & GR_ROLE_SPECIAL))
25011 ++ assigned = r;
25012 ++ FOR_EACH_ROLE_END(r,i)
25013 ++
25014 ++ if (!assigned)
25015 ++ return;
25016 ++
25017 ++ read_lock(&tasklist_lock);
25018 ++ read_lock(&grsec_exec_file_lock);
25019 ++
25020 ++ tsk = current->parent;
25021 ++ if (tsk == NULL)
25022 ++ goto out_unlock;
25023 ++
25024 ++ filp = tsk->exec_file;
25025 ++ if (filp == NULL)
25026 ++ goto out_unlock;
25027 ++
25028 ++ tsk->is_writable = 0;
25029 ++
25030 ++ tsk->acl_sp_role = 1;
25031 ++ tsk->acl_role_id = ++acl_sp_role_value;
25032 ++ tsk->role = assigned;
25033 ++ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
25034 ++
25035 ++ /* ignore additional mmap checks for processes that are writable
25036 ++ by the default ACL */
25037 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
25038 ++ if (unlikely(obj->mode & GR_WRITE))
25039 ++ tsk->is_writable = 1;
25040 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
25041 ++ if (unlikely(obj->mode & GR_WRITE))
25042 ++ tsk->is_writable = 1;
25043 ++
25044 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
25045 ++ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
25046 ++#endif
25047 ++
25048 ++out_unlock:
25049 ++ read_unlock(&grsec_exec_file_lock);
25050 ++ read_unlock(&tasklist_lock);
25051 ++ return;
25052 ++}
25053 ++
25054 ++int gr_check_secure_terminal(struct task_struct *task)
25055 ++{
25056 ++ struct task_struct *p, *p2, *p3;
25057 ++ struct files_struct *files;
25058 ++ struct fdtable *fdt;
25059 ++ struct file *our_file = NULL, *file;
25060 ++ int i;
25061 ++
25062 ++ if (task->signal->tty == NULL)
25063 ++ return 1;
25064 ++
25065 ++ files = get_files_struct(task);
25066 ++ if (files != NULL) {
25067 ++ rcu_read_lock();
25068 ++ fdt = files_fdtable(files);
25069 ++ for (i=0; i < fdt->max_fds; i++) {
25070 ++ file = fcheck_files(files, i);
25071 ++ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
25072 ++ get_file(file);
25073 ++ our_file = file;
25074 ++ }
25075 ++ }
25076 ++ rcu_read_unlock();
25077 ++ put_files_struct(files);
25078 ++ }
25079 ++
25080 ++ if (our_file == NULL)
25081 ++ return 1;
25082 ++
25083 ++ read_lock(&tasklist_lock);
25084 ++ do_each_thread(p2, p) {
25085 ++ files = get_files_struct(p);
25086 ++ if (files == NULL ||
25087 ++ (p->signal && p->signal->tty == task->signal->tty)) {
25088 ++ if (files != NULL)
25089 ++ put_files_struct(files);
25090 ++ continue;
25091 ++ }
25092 ++ rcu_read_lock();
25093 ++ fdt = files_fdtable(files);
25094 ++ for (i=0; i < fdt->max_fds; i++) {
25095 ++ file = fcheck_files(files, i);
25096 ++ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
25097 ++ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
25098 ++ p3 = task;
25099 ++ while (p3->pid > 0) {
25100 ++ if (p3 == p)
25101 ++ break;
25102 ++ p3 = p3->parent;
25103 ++ }
25104 ++ if (p3 == p)
25105 ++ break;
25106 ++ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
25107 ++ gr_handle_alertkill(p);
25108 ++ rcu_read_unlock();
25109 ++ put_files_struct(files);
25110 ++ read_unlock(&tasklist_lock);
25111 ++ fput(our_file);
25112 ++ return 0;
25113 ++ }
25114 ++ }
25115 ++ rcu_read_unlock();
25116 ++ put_files_struct(files);
25117 ++ } while_each_thread(p2, p);
25118 ++ read_unlock(&tasklist_lock);
25119 ++
25120 ++ fput(our_file);
25121 ++ return 1;
25122 ++}
25123 ++
25124 ++ssize_t
25125 ++write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
25126 ++{
25127 ++ struct gr_arg_wrapper uwrap;
25128 ++ unsigned char *sprole_salt;
25129 ++ unsigned char *sprole_sum;
25130 ++ int error = sizeof (struct gr_arg_wrapper);
25131 ++ int error2 = 0;
25132 ++
25133 ++ down(&gr_dev_sem);
25134 ++
25135 ++ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
25136 ++ error = -EPERM;
25137 ++ goto out;
25138 ++ }
25139 ++
25140 ++ if (count != sizeof (struct gr_arg_wrapper)) {
25141 ++ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
25142 ++ error = -EINVAL;
25143 ++ goto out;
25144 ++ }
25145 ++
25146 ++
25147 ++ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
25148 ++ gr_auth_expires = 0;
25149 ++ gr_auth_attempts = 0;
25150 ++ }
25151 ++
25152 ++ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
25153 ++ error = -EFAULT;
25154 ++ goto out;
25155 ++ }
25156 ++
25157 ++ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
25158 ++ error = -EINVAL;
25159 ++ goto out;
25160 ++ }
25161 ++
25162 ++ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
25163 ++ error = -EFAULT;
25164 ++ goto out;
25165 ++ }
25166 ++
25167 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != SPROLEPAM &&
25168 ++ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
25169 ++ time_after(gr_auth_expires, get_seconds())) {
25170 ++ error = -EBUSY;
25171 ++ goto out;
25172 ++ }
25173 ++
25174 ++ /* if non-root trying to do anything other than use a special role,
25175 ++ do not attempt authentication, do not count towards authentication
25176 ++ locking
25177 ++ */
25178 ++
25179 ++ if (gr_usermode->mode != SPROLE && gr_usermode->mode != STATUS &&
25180 ++ gr_usermode->mode != UNSPROLE && gr_usermode->mode != SPROLEPAM &&
25181 ++ current->uid) {
25182 ++ error = -EPERM;
25183 ++ goto out;
25184 ++ }
25185 ++
25186 ++ /* ensure pw and special role name are null terminated */
25187 ++
25188 ++ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
25189 ++ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
25190 ++
25191 ++ /* Okay.
25192 ++ * We have our enough of the argument structure..(we have yet
25193 ++ * to copy_from_user the tables themselves) . Copy the tables
25194 ++ * only if we need them, i.e. for loading operations. */
25195 ++
25196 ++ switch (gr_usermode->mode) {
25197 ++ case STATUS:
25198 ++ if (gr_status & GR_READY) {
25199 ++ error = 1;
25200 ++ if (!gr_check_secure_terminal(current))
25201 ++ error = 3;
25202 ++ } else
25203 ++ error = 2;
25204 ++ goto out;
25205 ++ case SHUTDOWN:
25206 ++ if ((gr_status & GR_READY)
25207 ++ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
25208 ++ gr_status &= ~GR_READY;
25209 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
25210 ++ free_variables();
25211 ++ memset(gr_usermode, 0, sizeof (struct gr_arg));
25212 ++ memset(gr_system_salt, 0, GR_SALT_LEN);
25213 ++ memset(gr_system_sum, 0, GR_SHA_LEN);
25214 ++ } else if (gr_status & GR_READY) {
25215 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
25216 ++ error = -EPERM;
25217 ++ } else {
25218 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
25219 ++ error = -EAGAIN;
25220 ++ }
25221 ++ break;
25222 ++ case ENABLE:
25223 ++ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
25224 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
25225 ++ else {
25226 ++ if (gr_status & GR_READY)
25227 ++ error = -EAGAIN;
25228 ++ else
25229 ++ error = error2;
25230 ++ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
25231 ++ }
25232 ++ break;
25233 ++ case RELOAD:
25234 ++ if (!(gr_status & GR_READY)) {
25235 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
25236 ++ error = -EAGAIN;
25237 ++ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
25238 ++ lock_kernel();
25239 ++ gr_status &= ~GR_READY;
25240 ++ free_variables();
25241 ++ if (!(error2 = gracl_init(gr_usermode))) {
25242 ++ unlock_kernel();
25243 ++ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
25244 ++ } else {
25245 ++ unlock_kernel();
25246 ++ error = error2;
25247 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
25248 ++ }
25249 ++ } else {
25250 ++ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
25251 ++ error = -EPERM;
25252 ++ }
25253 ++ break;
25254 ++ case SEGVMOD:
25255 ++ if (unlikely(!(gr_status & GR_READY))) {
25256 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
25257 ++ error = -EAGAIN;
25258 ++ break;
25259 ++ }
25260 ++
25261 ++ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
25262 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
25263 ++ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
25264 ++ struct acl_subject_label *segvacl;
25265 ++ segvacl =
25266 ++ lookup_acl_subj_label(gr_usermode->segv_inode,
25267 ++ gr_usermode->segv_device,
25268 ++ current->role);
25269 ++ if (segvacl) {
25270 ++ segvacl->crashes = 0;
25271 ++ segvacl->expires = 0;
25272 ++ }
25273 ++ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
25274 ++ gr_remove_uid(gr_usermode->segv_uid);
25275 ++ }
25276 ++ } else {
25277 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
25278 ++ error = -EPERM;
25279 ++ }
25280 ++ break;
25281 ++ case SPROLE:
25282 ++ case SPROLEPAM:
25283 ++ if (unlikely(!(gr_status & GR_READY))) {
25284 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
25285 ++ error = -EAGAIN;
25286 ++ break;
25287 ++ }
25288 ++
25289 ++ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
25290 ++ current->role->expires = 0;
25291 ++ current->role->auth_attempts = 0;
25292 ++ }
25293 ++
25294 ++ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
25295 ++ time_after(current->role->expires, get_seconds())) {
25296 ++ error = -EBUSY;
25297 ++ goto out;
25298 ++ }
25299 ++
25300 ++ if (lookup_special_role_auth
25301 ++ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
25302 ++ && ((!sprole_salt && !sprole_sum)
25303 ++ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
25304 ++ char *p = "";
25305 ++ assign_special_role(gr_usermode->sp_role);
25306 ++ read_lock(&tasklist_lock);
25307 ++ if (current->parent)
25308 ++ p = current->parent->role->rolename;
25309 ++ read_unlock(&tasklist_lock);
25310 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
25311 ++ p, acl_sp_role_value);
25312 ++ } else {
25313 ++ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
25314 ++ error = -EPERM;
25315 ++ if(!(current->role->auth_attempts++))
25316 ++ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
25317 ++
25318 ++ goto out;
25319 ++ }
25320 ++ break;
25321 ++ case UNSPROLE:
25322 ++ if (unlikely(!(gr_status & GR_READY))) {
25323 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
25324 ++ error = -EAGAIN;
25325 ++ break;
25326 ++ }
25327 ++
25328 ++ if (current->role->roletype & GR_ROLE_SPECIAL) {
25329 ++ char *p = "";
25330 ++ int i = 0;
25331 ++
25332 ++ read_lock(&tasklist_lock);
25333 ++ if (current->parent) {
25334 ++ p = current->parent->role->rolename;
25335 ++ i = current->parent->acl_role_id;
25336 ++ }
25337 ++ read_unlock(&tasklist_lock);
25338 ++
25339 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
25340 ++ gr_set_acls(1);
25341 ++ } else {
25342 ++ gr_log_str(GR_DONT_AUDIT, GR_UNSPROLEF_ACL_MSG, current->role->rolename);
25343 ++ error = -EPERM;
25344 ++ goto out;
25345 ++ }
25346 ++ break;
25347 ++ default:
25348 ++ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
25349 ++ error = -EINVAL;
25350 ++ break;
25351 ++ }
25352 ++
25353 ++ if (error != -EPERM)
25354 ++ goto out;
25355 ++
25356 ++ if(!(gr_auth_attempts++))
25357 ++ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
25358 ++
25359 ++ out:
25360 ++ up(&gr_dev_sem);
25361 ++ return error;
25362 ++}
25363 ++
25364 ++int
25365 ++gr_set_acls(const int type)
25366 ++{
25367 ++ struct acl_object_label *obj;
25368 ++ struct task_struct *task, *task2;
25369 ++ struct file *filp;
25370 ++ struct acl_role_label *role = current->role;
25371 ++ __u16 acl_role_id = current->acl_role_id;
25372 ++
25373 ++ read_lock(&tasklist_lock);
25374 ++ read_lock(&grsec_exec_file_lock);
25375 ++ do_each_thread(task2, task) {
25376 ++ /* check to see if we're called from the exit handler,
25377 ++ if so, only replace ACLs that have inherited the admin
25378 ++ ACL */
25379 ++
25380 ++ if (type && (task->role != role ||
25381 ++ task->acl_role_id != acl_role_id))
25382 ++ continue;
25383 ++
25384 ++ task->acl_role_id = 0;
25385 ++ task->acl_sp_role = 0;
25386 ++
25387 ++ if ((filp = task->exec_file)) {
25388 ++ task->role = lookup_acl_role_label(task, task->uid, task->gid);
25389 ++
25390 ++ task->acl =
25391 ++ chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
25392 ++ task->role);
25393 ++ if (task->acl) {
25394 ++ struct acl_subject_label *curr;
25395 ++ curr = task->acl;
25396 ++
25397 ++ task->is_writable = 0;
25398 ++ /* ignore additional mmap checks for processes that are writable
25399 ++ by the default ACL */
25400 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
25401 ++ if (unlikely(obj->mode & GR_WRITE))
25402 ++ task->is_writable = 1;
25403 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
25404 ++ if (unlikely(obj->mode & GR_WRITE))
25405 ++ task->is_writable = 1;
25406 ++
25407 ++ gr_set_proc_res(task);
25408 ++
25409 ++#ifdef CONFIG_GRKERNSEC_ACL_DEBUG
25410 ++ printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
25411 ++#endif
25412 ++ } else {
25413 ++ read_unlock(&grsec_exec_file_lock);
25414 ++ read_unlock(&tasklist_lock);
25415 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
25416 ++ return 1;
25417 ++ }
25418 ++ } else {
25419 ++ // it's a kernel process
25420 ++ task->role = kernel_role;
25421 ++ task->acl = kernel_role->root_label;
25422 ++#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
25423 ++ task->acl->mode &= ~GR_PROCFIND;
25424 ++#endif
25425 ++ }
25426 ++ } while_each_thread(task2, task);
25427 ++ read_unlock(&grsec_exec_file_lock);
25428 ++ read_unlock(&tasklist_lock);
25429 ++ return 0;
25430 ++}
25431 ++
25432 ++void
25433 ++gr_learn_resource(const struct task_struct *task,
25434 ++ const int res, const unsigned long wanted, const int gt)
25435 ++{
25436 ++ struct acl_subject_label *acl;
25437 ++
25438 ++ if (unlikely((gr_status & GR_READY) &&
25439 ++ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
25440 ++ goto skip_reslog;
25441 ++
25442 ++#ifdef CONFIG_GRKERNSEC_RESLOG
25443 ++ gr_log_resource(task, res, wanted, gt);
25444 ++#endif
25445 ++ skip_reslog:
25446 ++
25447 ++ if (unlikely(!(gr_status & GR_READY) || !wanted))
25448 ++ return;
25449 ++
25450 ++ acl = task->acl;
25451 ++
25452 ++ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
25453 ++ !(acl->resmask & (1 << (unsigned short) res))))
25454 ++ return;
25455 ++
25456 ++ if (wanted >= acl->res[res].rlim_cur) {
25457 ++ unsigned long res_add;
25458 ++
25459 ++ res_add = wanted;
25460 ++ switch (res) {
25461 ++ case RLIMIT_CPU:
25462 ++ res_add += GR_RLIM_CPU_BUMP;
25463 ++ break;
25464 ++ case RLIMIT_FSIZE:
25465 ++ res_add += GR_RLIM_FSIZE_BUMP;
25466 ++ break;
25467 ++ case RLIMIT_DATA:
25468 ++ res_add += GR_RLIM_DATA_BUMP;
25469 ++ break;
25470 ++ case RLIMIT_STACK:
25471 ++ res_add += GR_RLIM_STACK_BUMP;
25472 ++ break;
25473 ++ case RLIMIT_CORE:
25474 ++ res_add += GR_RLIM_CORE_BUMP;
25475 ++ break;
25476 ++ case RLIMIT_RSS:
25477 ++ res_add += GR_RLIM_RSS_BUMP;
25478 ++ break;
25479 ++ case RLIMIT_NPROC:
25480 ++ res_add += GR_RLIM_NPROC_BUMP;
25481 ++ break;
25482 ++ case RLIMIT_NOFILE:
25483 ++ res_add += GR_RLIM_NOFILE_BUMP;
25484 ++ break;
25485 ++ case RLIMIT_MEMLOCK:
25486 ++ res_add += GR_RLIM_MEMLOCK_BUMP;
25487 ++ break;
25488 ++ case RLIMIT_AS:
25489 ++ res_add += GR_RLIM_AS_BUMP;
25490 ++ break;
25491 ++ case RLIMIT_LOCKS:
25492 ++ res_add += GR_RLIM_LOCKS_BUMP;
25493 ++ break;
25494 ++ }
25495 ++
25496 ++ acl->res[res].rlim_cur = res_add;
25497 ++
25498 ++ if (wanted > acl->res[res].rlim_max)
25499 ++ acl->res[res].rlim_max = res_add;
25500 ++
25501 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
25502 ++ task->role->roletype, acl->filename,
25503 ++ acl->res[res].rlim_cur, acl->res[res].rlim_max,
25504 ++ "", (unsigned long) res);
25505 ++ }
25506 ++
25507 ++ return;
25508 ++}
25509 ++
25510 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
25511 ++void
25512 ++pax_set_initial_flags(struct linux_binprm *bprm)
25513 ++{
25514 ++ struct task_struct *task = current;
25515 ++ struct acl_subject_label *proc;
25516 ++ unsigned long flags;
25517 ++
25518 ++ if (unlikely(!(gr_status & GR_READY)))
25519 ++ return;
25520 ++
25521 ++ flags = pax_get_flags(task);
25522 ++
25523 ++ proc = task->acl;
25524 ++
25525 ++ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
25526 ++ flags &= ~MF_PAX_PAGEEXEC;
25527 ++ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
25528 ++ flags &= ~MF_PAX_SEGMEXEC;
25529 ++ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
25530 ++ flags &= ~MF_PAX_RANDMMAP;
25531 ++ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
25532 ++ flags &= ~MF_PAX_EMUTRAMP;
25533 ++ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
25534 ++ flags &= ~MF_PAX_MPROTECT;
25535 ++
25536 ++ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
25537 ++ flags |= MF_PAX_PAGEEXEC;
25538 ++ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
25539 ++ flags |= MF_PAX_SEGMEXEC;
25540 ++ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
25541 ++ flags |= MF_PAX_RANDMMAP;
25542 ++ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
25543 ++ flags |= MF_PAX_EMUTRAMP;
25544 ++ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
25545 ++ flags |= MF_PAX_MPROTECT;
25546 ++
25547 ++ pax_set_flags(task, flags);
25548 ++
25549 ++ return;
25550 ++}
25551 ++#endif
25552 ++
25553 ++#ifdef CONFIG_SYSCTL
25554 ++/* Eric Biederman likes breaking userland ABI and every inode-based security
25555 ++ system to save 35kb of memory */
25556 ++
25557 ++/* we modify the passed in filename, but adjust it back before returning */
25558 ++static struct acl_object_label *gr_lookup_by_name(char *name, unsigned int len)
25559 ++{
25560 ++ struct name_entry *nmatch;
25561 ++ char *p, *lastp = NULL;
25562 ++ struct acl_object_label *obj = NULL, *tmp;
25563 ++ struct acl_subject_label *tmpsubj;
25564 ++ char c = '\0';
25565 ++
25566 ++ read_lock(&gr_inode_lock);
25567 ++
25568 ++ p = name + len - 1;
25569 ++ do {
25570 ++ nmatch = lookup_name_entry(name);
25571 ++ if (lastp != NULL)
25572 ++ *lastp = c;
25573 ++
25574 ++ if (nmatch == NULL)
25575 ++ goto next_component;
25576 ++ tmpsubj = current->acl;
25577 ++ do {
25578 ++ obj = lookup_acl_obj_label(nmatch->inode, nmatch->device, tmpsubj);
25579 ++ if (obj != NULL) {
25580 ++ tmp = obj->globbed;
25581 ++ while (tmp) {
25582 ++ if (!glob_match(tmp->filename, name)) {
25583 ++ obj = tmp;
25584 ++ goto found_obj;
25585 ++ }
25586 ++ tmp = tmp->next;
25587 ++ }
25588 ++ goto found_obj;
25589 ++ }
25590 ++ } while ((tmpsubj = tmpsubj->parent_subject));
25591 ++next_component:
25592 ++ /* end case */
25593 ++ if (p == name)
25594 ++ break;
25595 ++
25596 ++ while (*p != '/')
25597 ++ p--;
25598 ++ if (p == name)
25599 ++ lastp = p + 1;
25600 ++ else {
25601 ++ lastp = p;
25602 ++ p--;
25603 ++ }
25604 ++ c = *lastp;
25605 ++ *lastp = '\0';
25606 ++ } while (1);
25607 ++found_obj:
25608 ++ read_unlock(&gr_inode_lock);
25609 ++ /* obj returned will always be non-null */
25610 ++ return obj;
25611 ++}
25612 ++
25613 ++/* returns 0 when allowing, non-zero on error
25614 ++ op of 0 is used for readdir, so we don't log the names of hidden files
25615 ++*/
25616 ++__u32
25617 ++gr_handle_sysctl(const struct ctl_table *table, const int op)
25618 ++{
25619 ++ ctl_table *tmp;
25620 ++ const char *proc_sys = "/proc/sys";
25621 ++ char *path;
25622 ++ struct acl_object_label *obj;
25623 ++ unsigned short len = 0, pos = 0, depth = 0, i;
25624 ++ __u32 err = 0;
25625 ++ __u32 mode = 0;
25626 ++
25627 ++ if (unlikely(!(gr_status & GR_READY)))
25628 ++ return 0;
25629 ++
25630 ++ /* for now, ignore operations on non-sysctl entries if it's not a
25631 ++ readdir*/
25632 ++ if (table->child != NULL && op != 0)
25633 ++ return 0;
25634 ++
25635 ++ mode |= GR_FIND;
25636 ++ /* it's only a read if it's an entry, read on dirs is for readdir */
25637 ++ if (op & MAY_READ)
25638 ++ mode |= GR_READ;
25639 ++ if (op & MAY_WRITE)
25640 ++ mode |= GR_WRITE;
25641 ++
25642 ++ preempt_disable();
25643 ++
25644 ++ path = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
25645 ++
25646 ++ /* it's only a read/write if it's an actual entry, not a dir
25647 ++ (which are opened for readdir)
25648 ++ */
25649 ++
25650 ++ /* convert the requested sysctl entry into a pathname */
25651 ++
25652 ++ for (tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
25653 ++ len += strlen(tmp->procname);
25654 ++ len++;
25655 ++ depth++;
25656 ++ }
25657 ++
25658 ++ if ((len + depth + strlen(proc_sys) + 1) > PAGE_SIZE) {
25659 ++ /* deny */
25660 ++ goto out;
25661 ++ }
25662 ++
25663 ++ memset(path, 0, PAGE_SIZE);
25664 ++
25665 ++ memcpy(path, proc_sys, strlen(proc_sys));
25666 ++
25667 ++ pos += strlen(proc_sys);
25668 ++
25669 ++ for (; depth > 0; depth--) {
25670 ++ path[pos] = '/';
25671 ++ pos++;
25672 ++ for (i = 1, tmp = (ctl_table *)table; tmp != NULL; tmp = tmp->parent) {
25673 ++ if (depth == i) {
25674 ++ memcpy(path + pos, tmp->procname,
25675 ++ strlen(tmp->procname));
25676 ++ pos += strlen(tmp->procname);
25677 ++ }
25678 ++ i++;
25679 ++ }
25680 ++ }
25681 ++
25682 ++ obj = gr_lookup_by_name(path, pos);
25683 ++ err = obj->mode & (mode | to_gr_audit(mode) | GR_SUPPRESS);
25684 ++
25685 ++ if (unlikely((current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) &&
25686 ++ ((err & mode) != mode))) {
25687 ++ __u32 new_mode = mode;
25688 ++
25689 ++ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
25690 ++
25691 ++ err = 0;
25692 ++ gr_log_learn_sysctl(current, path, new_mode);
25693 ++ } else if (!(err & GR_FIND) && !(err & GR_SUPPRESS) && op != 0) {
25694 ++ gr_log_hidden_sysctl(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, path);
25695 ++ err = -ENOENT;
25696 ++ } else if (!(err & GR_FIND)) {
25697 ++ err = -ENOENT;
25698 ++ } else if (((err & mode) & ~GR_FIND) != (mode & ~GR_FIND) && !(err & GR_SUPPRESS)) {
25699 ++ gr_log_str4(GR_DONT_AUDIT, GR_SYSCTL_ACL_MSG, "denied",
25700 ++ path, (mode & GR_READ) ? " reading" : "",
25701 ++ (mode & GR_WRITE) ? " writing" : "");
25702 ++ err = -EACCES;
25703 ++ } else if ((err & mode) != mode) {
25704 ++ err = -EACCES;
25705 ++ } else if ((((err & mode) & ~GR_FIND) == (mode & ~GR_FIND)) && (err & GR_AUDITS)) {
25706 ++ gr_log_str4(GR_DO_AUDIT, GR_SYSCTL_ACL_MSG, "successful",
25707 ++ path, (mode & GR_READ) ? " reading" : "",
25708 ++ (mode & GR_WRITE) ? " writing" : "");
25709 ++ err = 0;
25710 ++ } else
25711 ++ err = 0;
25712 ++
25713 ++ out:
25714 ++ preempt_enable();
25715 ++
25716 ++ return err;
25717 ++}
25718 ++#endif
25719 ++
25720 ++int
25721 ++gr_handle_proc_ptrace(struct task_struct *task)
25722 ++{
25723 ++ struct file *filp;
25724 ++ struct task_struct *tmp = task;
25725 ++ struct task_struct *curtemp = current;
25726 ++ __u32 retmode;
25727 ++
25728 ++ if (unlikely(!(gr_status & GR_READY)))
25729 ++ return 0;
25730 ++
25731 ++ read_lock(&tasklist_lock);
25732 ++ read_lock(&grsec_exec_file_lock);
25733 ++ filp = task->exec_file;
25734 ++
25735 ++ while (tmp->pid > 0) {
25736 ++ if (tmp == curtemp)
25737 ++ break;
25738 ++ tmp = tmp->parent;
25739 ++ }
25740 ++
25741 ++ if (!filp || (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE))) {
25742 ++ read_unlock(&grsec_exec_file_lock);
25743 ++ read_unlock(&tasklist_lock);
25744 ++ return 1;
25745 ++ }
25746 ++
25747 ++ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
25748 ++ read_unlock(&grsec_exec_file_lock);
25749 ++ read_unlock(&tasklist_lock);
25750 ++
25751 ++ if (retmode & GR_NOPTRACE)
25752 ++ return 1;
25753 ++
25754 ++ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
25755 ++ && (current->acl != task->acl || (current->acl != current->role->root_label
25756 ++ && current->pid != task->pid)))
25757 ++ return 1;
25758 ++
25759 ++ return 0;
25760 ++}
25761 ++
25762 ++int
25763 ++gr_handle_ptrace(struct task_struct *task, const long request)
25764 ++{
25765 ++ struct task_struct *tmp = task;
25766 ++ struct task_struct *curtemp = current;
25767 ++ __u32 retmode;
25768 ++
25769 ++ if (unlikely(!(gr_status & GR_READY)))
25770 ++ return 0;
25771 ++
25772 ++ read_lock(&tasklist_lock);
25773 ++ while (tmp->pid > 0) {
25774 ++ if (tmp == curtemp)
25775 ++ break;
25776 ++ tmp = tmp->parent;
25777 ++ }
25778 ++
25779 ++ if (tmp->pid == 0 && !(current->acl->mode & GR_RELAXPTRACE)) {
25780 ++ read_unlock(&tasklist_lock);
25781 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
25782 ++ return 1;
25783 ++ }
25784 ++ read_unlock(&tasklist_lock);
25785 ++
25786 ++ read_lock(&grsec_exec_file_lock);
25787 ++ if (unlikely(!task->exec_file)) {
25788 ++ read_unlock(&grsec_exec_file_lock);
25789 ++ return 0;
25790 ++ }
25791 ++
25792 ++ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
25793 ++ read_unlock(&grsec_exec_file_lock);
25794 ++
25795 ++ if (retmode & GR_NOPTRACE) {
25796 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
25797 ++ return 1;
25798 ++ }
25799 ++
25800 ++ if (retmode & GR_PTRACERD) {
25801 ++ switch (request) {
25802 ++ case PTRACE_POKETEXT:
25803 ++ case PTRACE_POKEDATA:
25804 ++ case PTRACE_POKEUSR:
25805 ++#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
25806 ++ case PTRACE_SETREGS:
25807 ++ case PTRACE_SETFPREGS:
25808 ++#endif
25809 ++#ifdef CONFIG_X86
25810 ++ case PTRACE_SETFPXREGS:
25811 ++#endif
25812 ++#ifdef CONFIG_ALTIVEC
25813 ++ case PTRACE_SETVRREGS:
25814 ++#endif
25815 ++ return 1;
25816 ++ default:
25817 ++ return 0;
25818 ++ }
25819 ++ } else if (!(current->acl->mode & GR_POVERRIDE) &&
25820 ++ !(current->role->roletype & GR_ROLE_GOD) &&
25821 ++ (current->acl != task->acl)) {
25822 ++ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
25823 ++ return 1;
25824 ++ }
25825 ++
25826 ++ return 0;
25827 ++}
25828 ++
25829 ++static int is_writable_mmap(const struct file *filp)
25830 ++{
25831 ++ struct task_struct *task = current;
25832 ++ struct acl_object_label *obj, *obj2;
25833 ++
25834 ++ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
25835 ++ !task->is_writable && S_ISREG(filp->f_path.dentry->d_inode->i_mode)) {
25836 ++ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
25837 ++ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
25838 ++ task->role->root_label);
25839 ++ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
25840 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
25841 ++ return 1;
25842 ++ }
25843 ++ }
25844 ++ return 0;
25845 ++}
25846 ++
25847 ++int
25848 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
25849 ++{
25850 ++ __u32 mode;
25851 ++
25852 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
25853 ++ return 1;
25854 ++
25855 ++ if (is_writable_mmap(file))
25856 ++ return 0;
25857 ++
25858 ++ mode =
25859 ++ gr_search_file(file->f_path.dentry,
25860 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
25861 ++ file->f_path.mnt);
25862 ++
25863 ++ if (!gr_tpe_allow(file))
25864 ++ return 0;
25865 ++
25866 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
25867 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
25868 ++ return 0;
25869 ++ } else if (unlikely(!(mode & GR_EXEC))) {
25870 ++ return 0;
25871 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
25872 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
25873 ++ return 1;
25874 ++ }
25875 ++
25876 ++ return 1;
25877 ++}
25878 ++
25879 ++int
25880 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
25881 ++{
25882 ++ __u32 mode;
25883 ++
25884 ++ if (unlikely(!file || !(prot & PROT_EXEC)))
25885 ++ return 1;
25886 ++
25887 ++ if (is_writable_mmap(file))
25888 ++ return 0;
25889 ++
25890 ++ mode =
25891 ++ gr_search_file(file->f_path.dentry,
25892 ++ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
25893 ++ file->f_path.mnt);
25894 ++
25895 ++ if (!gr_tpe_allow(file))
25896 ++ return 0;
25897 ++
25898 ++ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
25899 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
25900 ++ return 0;
25901 ++ } else if (unlikely(!(mode & GR_EXEC))) {
25902 ++ return 0;
25903 ++ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
25904 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
25905 ++ return 1;
25906 ++ }
25907 ++
25908 ++ return 1;
25909 ++}
25910 ++
25911 ++void
25912 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
25913 ++{
25914 ++ unsigned long runtime;
25915 ++ unsigned long cputime;
25916 ++ unsigned int wday, cday;
25917 ++ __u8 whr, chr;
25918 ++ __u8 wmin, cmin;
25919 ++ __u8 wsec, csec;
25920 ++ struct timespec timeval;
25921 ++
25922 ++ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
25923 ++ !(task->acl->mode & GR_PROCACCT)))
25924 ++ return;
25925 ++
25926 ++ do_posix_clock_monotonic_gettime(&timeval);
25927 ++ runtime = timeval.tv_sec - task->start_time.tv_sec;
25928 ++ wday = runtime / (3600 * 24);
25929 ++ runtime -= wday * (3600 * 24);
25930 ++ whr = runtime / 3600;
25931 ++ runtime -= whr * 3600;
25932 ++ wmin = runtime / 60;
25933 ++ runtime -= wmin * 60;
25934 ++ wsec = runtime;
25935 ++
25936 ++ cputime = (task->utime + task->stime) / HZ;
25937 ++ cday = cputime / (3600 * 24);
25938 ++ cputime -= cday * (3600 * 24);
25939 ++ chr = cputime / 3600;
25940 ++ cputime -= chr * 3600;
25941 ++ cmin = cputime / 60;
25942 ++ cputime -= cmin * 60;
25943 ++ csec = cputime;
25944 ++
25945 ++ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
25946 ++
25947 ++ return;
25948 ++}
25949 ++
25950 ++void gr_set_kernel_label(struct task_struct *task)
25951 ++{
25952 ++ if (gr_status & GR_READY) {
25953 ++ task->role = kernel_role;
25954 ++ task->acl = kernel_role->root_label;
25955 ++ }
25956 ++ return;
25957 ++}
25958 ++
25959 ++int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
25960 ++{
25961 ++ struct task_struct *task = current;
25962 ++ struct dentry *dentry = file->f_path.dentry;
25963 ++ struct vfsmount *mnt = file->f_path.mnt;
25964 ++ struct acl_object_label *obj, *tmp;
25965 ++ struct acl_subject_label *subj;
25966 ++ unsigned int bufsize;
25967 ++ int is_not_root;
25968 ++ char *path;
25969 ++
25970 ++ if (unlikely(!(gr_status & GR_READY)))
25971 ++ return 1;
25972 ++
25973 ++ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
25974 ++ return 1;
25975 ++
25976 ++ /* ignore Eric Biederman */
25977 ++ if (IS_PRIVATE(dentry->d_inode))
25978 ++ return 1;
25979 ++
25980 ++ subj = task->acl;
25981 ++ do {
25982 ++ obj = lookup_acl_obj_label(ino, dentry->d_inode->i_sb->s_dev, subj);
25983 ++ if (obj != NULL)
25984 ++ return (obj->mode & GR_FIND) ? 1 : 0;
25985 ++ } while ((subj = subj->parent_subject));
25986 ++
25987 ++ obj = chk_obj_label(dentry, mnt, task->acl);
25988 ++ if (obj->globbed == NULL)
25989 ++ return (obj->mode & GR_FIND) ? 1 : 0;
25990 ++
25991 ++ is_not_root = ((obj->filename[0] == '/') &&
25992 ++ (obj->filename[1] == '\0')) ? 0 : 1;
25993 ++ bufsize = PAGE_SIZE - namelen - is_not_root;
25994 ++
25995 ++ /* check bufsize > PAGE_SIZE || bufsize == 0 */
25996 ++ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
25997 ++ return 1;
25998 ++
25999 ++ preempt_disable();
26000 ++ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
26001 ++ bufsize);
26002 ++
26003 ++ bufsize = strlen(path);
26004 ++
26005 ++ /* if base is "/", don't append an additional slash */
26006 ++ if (is_not_root)
26007 ++ *(path + bufsize) = '/';
26008 ++ memcpy(path + bufsize + is_not_root, name, namelen);
26009 ++ *(path + bufsize + namelen + is_not_root) = '\0';
26010 ++
26011 ++ tmp = obj->globbed;
26012 ++ while (tmp) {
26013 ++ if (!glob_match(tmp->filename, path)) {
26014 ++ preempt_enable();
26015 ++ return (tmp->mode & GR_FIND) ? 1 : 0;
26016 ++ }
26017 ++ tmp = tmp->next;
26018 ++ }
26019 ++ preempt_enable();
26020 ++ return (obj->mode & GR_FIND) ? 1 : 0;
26021 ++}
26022 ++
26023 ++EXPORT_SYMBOL(gr_learn_resource);
26024 ++EXPORT_SYMBOL(gr_set_kernel_label);
26025 ++#ifdef CONFIG_SECURITY
26026 ++EXPORT_SYMBOL(gr_check_user_change);
26027 ++EXPORT_SYMBOL(gr_check_group_change);
26028 ++#endif
26029 ++
26030 +diff -urNp linux-2.6.28/grsecurity/gracl_cap.c linux-2.6.28/grsecurity/gracl_cap.c
26031 +--- linux-2.6.28/grsecurity/gracl_cap.c 1969-12-31 19:00:00.000000000 -0500
26032 ++++ linux-2.6.28/grsecurity/gracl_cap.c 2009-01-11 05:47:03.000000000 -0500
26033 +@@ -0,0 +1,129 @@
26034 ++#include <linux/kernel.h>
26035 ++#include <linux/module.h>
26036 ++#include <linux/sched.h>
26037 ++#include <linux/gracl.h>
26038 ++#include <linux/grsecurity.h>
26039 ++#include <linux/grinternal.h>
26040 ++
26041 ++static const char *captab_log[] = {
26042 ++ "CAP_CHOWN",
26043 ++ "CAP_DAC_OVERRIDE",
26044 ++ "CAP_DAC_READ_SEARCH",
26045 ++ "CAP_FOWNER",
26046 ++ "CAP_FSETID",
26047 ++ "CAP_KILL",
26048 ++ "CAP_SETGID",
26049 ++ "CAP_SETUID",
26050 ++ "CAP_SETPCAP",
26051 ++ "CAP_LINUX_IMMUTABLE",
26052 ++ "CAP_NET_BIND_SERVICE",
26053 ++ "CAP_NET_BROADCAST",
26054 ++ "CAP_NET_ADMIN",
26055 ++ "CAP_NET_RAW",
26056 ++ "CAP_IPC_LOCK",
26057 ++ "CAP_IPC_OWNER",
26058 ++ "CAP_SYS_MODULE",
26059 ++ "CAP_SYS_RAWIO",
26060 ++ "CAP_SYS_CHROOT",
26061 ++ "CAP_SYS_PTRACE",
26062 ++ "CAP_SYS_PACCT",
26063 ++ "CAP_SYS_ADMIN",
26064 ++ "CAP_SYS_BOOT",
26065 ++ "CAP_SYS_NICE",
26066 ++ "CAP_SYS_RESOURCE",
26067 ++ "CAP_SYS_TIME",
26068 ++ "CAP_SYS_TTY_CONFIG",
26069 ++ "CAP_MKNOD",
26070 ++ "CAP_LEASE",
26071 ++ "CAP_AUDIT_WRITE",
26072 ++ "CAP_AUDIT_CONTROL",
26073 ++ "CAP_SETFCAP",
26074 ++ "CAP_MAC_OVERRIDE",
26075 ++ "CAP_MAC_ADMIN"
26076 ++};
26077 ++
26078 ++EXPORT_SYMBOL(gr_task_is_capable);
26079 ++EXPORT_SYMBOL(gr_is_capable_nolog);
26080 ++
26081 ++int
26082 ++gr_task_is_capable(struct task_struct *task, const int cap)
26083 ++{
26084 ++ struct acl_subject_label *curracl;
26085 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
26086 ++
26087 ++ if (!gr_acl_is_enabled())
26088 ++ return 1;
26089 ++
26090 ++ curracl = task->acl;
26091 ++
26092 ++ cap_drop = curracl->cap_lower;
26093 ++ cap_mask = curracl->cap_mask;
26094 ++
26095 ++ while ((curracl = curracl->parent_subject)) {
26096 ++ /* if the cap isn't specified in the current computed mask but is specified in the
26097 ++ current level subject, and is lowered in the current level subject, then add
26098 ++ it to the set of dropped capabilities
26099 ++ otherwise, add the current level subject's mask to the current computed mask
26100 ++ */
26101 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
26102 ++ cap_raise(cap_mask, cap);
26103 ++ if (cap_raised(curracl->cap_lower, cap))
26104 ++ cap_raise(cap_drop, cap);
26105 ++ }
26106 ++ }
26107 ++
26108 ++ if (!cap_raised(cap_drop, cap))
26109 ++ return 1;
26110 ++
26111 ++ curracl = task->acl;
26112 ++
26113 ++ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
26114 ++ && cap_raised(task->cap_effective, cap)) {
26115 ++ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
26116 ++ task->role->roletype, task->uid,
26117 ++ task->gid, task->exec_file ?
26118 ++ gr_to_filename(task->exec_file->f_path.dentry,
26119 ++ task->exec_file->f_path.mnt) : curracl->filename,
26120 ++ curracl->filename, 0UL,
26121 ++ 0UL, "", (unsigned long) cap, NIPQUAD(task->signal->curr_ip));
26122 ++ return 1;
26123 ++ }
26124 ++
26125 ++ if ((cap >= 0) && (cap < (sizeof(captab_log)/sizeof(captab_log[0]))) && cap_raised(task->cap_effective, cap))
26126 ++ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
26127 ++ return 0;
26128 ++}
26129 ++
26130 ++int
26131 ++gr_is_capable_nolog(const int cap)
26132 ++{
26133 ++ struct acl_subject_label *curracl;
26134 ++ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
26135 ++
26136 ++ if (!gr_acl_is_enabled())
26137 ++ return 1;
26138 ++
26139 ++ curracl = current->acl;
26140 ++
26141 ++ cap_drop = curracl->cap_lower;
26142 ++ cap_mask = curracl->cap_mask;
26143 ++
26144 ++ while ((curracl = curracl->parent_subject)) {
26145 ++ /* if the cap isn't specified in the current computed mask but is specified in the
26146 ++ current level subject, and is lowered in the current level subject, then add
26147 ++ it to the set of dropped capabilities
26148 ++ otherwise, add the current level subject's mask to the current computed mask
26149 ++ */
26150 ++ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
26151 ++ cap_raise(cap_mask, cap);
26152 ++ if (cap_raised(curracl->cap_lower, cap))
26153 ++ cap_raise(cap_drop, cap);
26154 ++ }
26155 ++ }
26156 ++
26157 ++ if (!cap_raised(cap_drop, cap))
26158 ++ return 1;
26159 ++
26160 ++ return 0;
26161 ++}
26162 ++
26163 +diff -urNp linux-2.6.28/grsecurity/gracl_fs.c linux-2.6.28/grsecurity/gracl_fs.c
26164 +--- linux-2.6.28/grsecurity/gracl_fs.c 1969-12-31 19:00:00.000000000 -0500
26165 ++++ linux-2.6.28/grsecurity/gracl_fs.c 2009-01-11 05:47:03.000000000 -0500
26166 +@@ -0,0 +1,423 @@
26167 ++#include <linux/kernel.h>
26168 ++#include <linux/sched.h>
26169 ++#include <linux/types.h>
26170 ++#include <linux/fs.h>
26171 ++#include <linux/file.h>
26172 ++#include <linux/stat.h>
26173 ++#include <linux/grsecurity.h>
26174 ++#include <linux/grinternal.h>
26175 ++#include <linux/gracl.h>
26176 ++
26177 ++__u32
26178 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
26179 ++ const struct vfsmount * mnt)
26180 ++{
26181 ++ __u32 mode;
26182 ++
26183 ++ if (unlikely(!dentry->d_inode))
26184 ++ return GR_FIND;
26185 ++
26186 ++ mode =
26187 ++ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
26188 ++
26189 ++ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
26190 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
26191 ++ return mode;
26192 ++ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
26193 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
26194 ++ return 0;
26195 ++ } else if (unlikely(!(mode & GR_FIND)))
26196 ++ return 0;
26197 ++
26198 ++ return GR_FIND;
26199 ++}
26200 ++
26201 ++__u32
26202 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
26203 ++ const int fmode)
26204 ++{
26205 ++ __u32 reqmode = GR_FIND;
26206 ++ __u32 mode;
26207 ++
26208 ++ if (unlikely(!dentry->d_inode))
26209 ++ return reqmode;
26210 ++
26211 ++ if (unlikely(fmode & O_APPEND))
26212 ++ reqmode |= GR_APPEND;
26213 ++ else if (unlikely(fmode & FMODE_WRITE))
26214 ++ reqmode |= GR_WRITE;
26215 ++ if (likely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
26216 ++ reqmode |= GR_READ;
26217 ++
26218 ++ mode =
26219 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
26220 ++ mnt);
26221 ++
26222 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
26223 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
26224 ++ reqmode & GR_READ ? " reading" : "",
26225 ++ reqmode & GR_WRITE ? " writing" : reqmode &
26226 ++ GR_APPEND ? " appending" : "");
26227 ++ return reqmode;
26228 ++ } else
26229 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
26230 ++ {
26231 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
26232 ++ reqmode & GR_READ ? " reading" : "",
26233 ++ reqmode & GR_WRITE ? " writing" : reqmode &
26234 ++ GR_APPEND ? " appending" : "");
26235 ++ return 0;
26236 ++ } else if (unlikely((mode & reqmode) != reqmode))
26237 ++ return 0;
26238 ++
26239 ++ return reqmode;
26240 ++}
26241 ++
26242 ++__u32
26243 ++gr_acl_handle_creat(const struct dentry * dentry,
26244 ++ const struct dentry * p_dentry,
26245 ++ const struct vfsmount * p_mnt, const int fmode,
26246 ++ const int imode)
26247 ++{
26248 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
26249 ++ __u32 mode;
26250 ++
26251 ++ if (unlikely(fmode & O_APPEND))
26252 ++ reqmode |= GR_APPEND;
26253 ++ if (unlikely((fmode & FMODE_READ) && !(fmode & O_DIRECTORY)))
26254 ++ reqmode |= GR_READ;
26255 ++ if (unlikely((fmode & O_CREAT) && (imode & (S_ISUID | S_ISGID))))
26256 ++ reqmode |= GR_SETID;
26257 ++
26258 ++ mode =
26259 ++ gr_check_create(dentry, p_dentry, p_mnt,
26260 ++ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
26261 ++
26262 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
26263 ++ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
26264 ++ reqmode & GR_READ ? " reading" : "",
26265 ++ reqmode & GR_WRITE ? " writing" : reqmode &
26266 ++ GR_APPEND ? " appending" : "");
26267 ++ return reqmode;
26268 ++ } else
26269 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
26270 ++ {
26271 ++ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
26272 ++ reqmode & GR_READ ? " reading" : "",
26273 ++ reqmode & GR_WRITE ? " writing" : reqmode &
26274 ++ GR_APPEND ? " appending" : "");
26275 ++ return 0;
26276 ++ } else if (unlikely((mode & reqmode) != reqmode))
26277 ++ return 0;
26278 ++
26279 ++ return reqmode;
26280 ++}
26281 ++
26282 ++__u32
26283 ++gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
26284 ++ const int fmode)
26285 ++{
26286 ++ __u32 mode, reqmode = GR_FIND;
26287 ++
26288 ++ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
26289 ++ reqmode |= GR_EXEC;
26290 ++ if (fmode & S_IWOTH)
26291 ++ reqmode |= GR_WRITE;
26292 ++ if (fmode & S_IROTH)
26293 ++ reqmode |= GR_READ;
26294 ++
26295 ++ mode =
26296 ++ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
26297 ++ mnt);
26298 ++
26299 ++ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
26300 ++ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
26301 ++ reqmode & GR_READ ? " reading" : "",
26302 ++ reqmode & GR_WRITE ? " writing" : "",
26303 ++ reqmode & GR_EXEC ? " executing" : "");
26304 ++ return reqmode;
26305 ++ } else
26306 ++ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
26307 ++ {
26308 ++ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
26309 ++ reqmode & GR_READ ? " reading" : "",
26310 ++ reqmode & GR_WRITE ? " writing" : "",
26311 ++ reqmode & GR_EXEC ? " executing" : "");
26312 ++ return 0;
26313 ++ } else if (unlikely((mode & reqmode) != reqmode))
26314 ++ return 0;
26315 ++
26316 ++ return reqmode;
26317 ++}
26318 ++
26319 ++static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
26320 ++{
26321 ++ __u32 mode;
26322 ++
26323 ++ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
26324 ++
26325 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
26326 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
26327 ++ return mode;
26328 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
26329 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
26330 ++ return 0;
26331 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
26332 ++ return 0;
26333 ++
26334 ++ return (reqmode);
26335 ++}
26336 ++
26337 ++__u32
26338 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
26339 ++{
26340 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
26341 ++}
26342 ++
26343 ++__u32
26344 ++gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
26345 ++{
26346 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
26347 ++}
26348 ++
26349 ++__u32
26350 ++gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
26351 ++{
26352 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
26353 ++}
26354 ++
26355 ++__u32
26356 ++gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
26357 ++{
26358 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
26359 ++}
26360 ++
26361 ++__u32
26362 ++gr_acl_handle_fchmod(const struct dentry *dentry, const struct vfsmount *mnt,
26363 ++ mode_t mode)
26364 ++{
26365 ++ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
26366 ++ return 1;
26367 ++
26368 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
26369 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
26370 ++ GR_FCHMOD_ACL_MSG);
26371 ++ } else {
26372 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_FCHMOD_ACL_MSG);
26373 ++ }
26374 ++}
26375 ++
26376 ++__u32
26377 ++gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
26378 ++ mode_t mode)
26379 ++{
26380 ++ if (unlikely((mode != (mode_t)-1) && (mode & (S_ISUID | S_ISGID)))) {
26381 ++ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
26382 ++ GR_CHMOD_ACL_MSG);
26383 ++ } else {
26384 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
26385 ++ }
26386 ++}
26387 ++
26388 ++__u32
26389 ++gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
26390 ++{
26391 ++ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
26392 ++}
26393 ++
26394 ++__u32
26395 ++gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
26396 ++{
26397 ++ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
26398 ++}
26399 ++
26400 ++__u32
26401 ++gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
26402 ++{
26403 ++ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
26404 ++ GR_UNIXCONNECT_ACL_MSG);
26405 ++}
26406 ++
26407 ++/* hardlinks require at minimum create permission,
26408 ++ any additional privilege required is based on the
26409 ++ privilege of the file being linked to
26410 ++*/
26411 ++__u32
26412 ++gr_acl_handle_link(const struct dentry * new_dentry,
26413 ++ const struct dentry * parent_dentry,
26414 ++ const struct vfsmount * parent_mnt,
26415 ++ const struct dentry * old_dentry,
26416 ++ const struct vfsmount * old_mnt, const char *to)
26417 ++{
26418 ++ __u32 mode;
26419 ++ __u32 needmode = GR_CREATE | GR_LINK;
26420 ++ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
26421 ++
26422 ++ mode =
26423 ++ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
26424 ++ old_mnt);
26425 ++
26426 ++ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
26427 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
26428 ++ return mode;
26429 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
26430 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
26431 ++ return 0;
26432 ++ } else if (unlikely((mode & needmode) != needmode))
26433 ++ return 0;
26434 ++
26435 ++ return 1;
26436 ++}
26437 ++
26438 ++__u32
26439 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
26440 ++ const struct dentry * parent_dentry,
26441 ++ const struct vfsmount * parent_mnt, const char *from)
26442 ++{
26443 ++ __u32 needmode = GR_WRITE | GR_CREATE;
26444 ++ __u32 mode;
26445 ++
26446 ++ mode =
26447 ++ gr_check_create(new_dentry, parent_dentry, parent_mnt,
26448 ++ GR_CREATE | GR_AUDIT_CREATE |
26449 ++ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
26450 ++
26451 ++ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
26452 ++ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
26453 ++ return mode;
26454 ++ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
26455 ++ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
26456 ++ return 0;
26457 ++ } else if (unlikely((mode & needmode) != needmode))
26458 ++ return 0;
26459 ++
26460 ++ return (GR_WRITE | GR_CREATE);
26461 ++}
26462 ++
26463 ++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)
26464 ++{
26465 ++ __u32 mode;
26466 ++
26467 ++ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
26468 ++
26469 ++ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
26470 ++ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
26471 ++ return mode;
26472 ++ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
26473 ++ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
26474 ++ return 0;
26475 ++ } else if (unlikely((mode & (reqmode)) != (reqmode)))
26476 ++ return 0;
26477 ++
26478 ++ return (reqmode);
26479 ++}
26480 ++
26481 ++__u32
26482 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
26483 ++ const struct dentry * parent_dentry,
26484 ++ const struct vfsmount * parent_mnt,
26485 ++ const int mode)
26486 ++{
26487 ++ __u32 reqmode = GR_WRITE | GR_CREATE;
26488 ++ if (unlikely(mode & (S_ISUID | S_ISGID)))
26489 ++ reqmode |= GR_SETID;
26490 ++
26491 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
26492 ++ reqmode, GR_MKNOD_ACL_MSG);
26493 ++}
26494 ++
26495 ++__u32
26496 ++gr_acl_handle_mkdir(const struct dentry *new_dentry,
26497 ++ const struct dentry *parent_dentry,
26498 ++ const struct vfsmount *parent_mnt)
26499 ++{
26500 ++ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
26501 ++ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
26502 ++}
26503 ++
26504 ++#define RENAME_CHECK_SUCCESS(old, new) \
26505 ++ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
26506 ++ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
26507 ++
26508 ++int
26509 ++gr_acl_handle_rename(struct dentry *new_dentry,
26510 ++ struct dentry *parent_dentry,
26511 ++ const struct vfsmount *parent_mnt,
26512 ++ struct dentry *old_dentry,
26513 ++ struct inode *old_parent_inode,
26514 ++ struct vfsmount *old_mnt, const char *newname)
26515 ++{
26516 ++ __u32 comp1, comp2;
26517 ++ int error = 0;
26518 ++
26519 ++ if (unlikely(!gr_acl_is_enabled()))
26520 ++ return 0;
26521 ++
26522 ++ if (!new_dentry->d_inode) {
26523 ++ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
26524 ++ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
26525 ++ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
26526 ++ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
26527 ++ GR_DELETE | GR_AUDIT_DELETE |
26528 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
26529 ++ GR_SUPPRESS, old_mnt);
26530 ++ } else {
26531 ++ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
26532 ++ GR_CREATE | GR_DELETE |
26533 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
26534 ++ GR_AUDIT_READ | GR_AUDIT_WRITE |
26535 ++ GR_SUPPRESS, parent_mnt);
26536 ++ comp2 =
26537 ++ gr_search_file(old_dentry,
26538 ++ GR_READ | GR_WRITE | GR_AUDIT_READ |
26539 ++ GR_DELETE | GR_AUDIT_DELETE |
26540 ++ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
26541 ++ }
26542 ++
26543 ++ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
26544 ++ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
26545 ++ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
26546 ++ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
26547 ++ && !(comp2 & GR_SUPPRESS)) {
26548 ++ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
26549 ++ error = -EACCES;
26550 ++ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
26551 ++ error = -EACCES;
26552 ++
26553 ++ return error;
26554 ++}
26555 ++
26556 ++void
26557 ++gr_acl_handle_exit(void)
26558 ++{
26559 ++ u16 id;
26560 ++ char *rolename;
26561 ++ struct file *exec_file;
26562 ++
26563 ++ if (unlikely(current->acl_sp_role && gr_acl_is_enabled())) {
26564 ++ id = current->acl_role_id;
26565 ++ rolename = current->role->rolename;
26566 ++ gr_set_acls(1);
26567 ++ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
26568 ++ }
26569 ++
26570 ++ write_lock(&grsec_exec_file_lock);
26571 ++ exec_file = current->exec_file;
26572 ++ current->exec_file = NULL;
26573 ++ write_unlock(&grsec_exec_file_lock);
26574 ++
26575 ++ if (exec_file)
26576 ++ fput(exec_file);
26577 ++}
26578 ++
26579 ++int
26580 ++gr_acl_handle_procpidmem(const struct task_struct *task)
26581 ++{
26582 ++ if (unlikely(!gr_acl_is_enabled()))
26583 ++ return 0;
26584 ++
26585 ++ if (task != current && task->acl->mode & GR_PROTPROCFD)
26586 ++ return -EACCES;
26587 ++
26588 ++ return 0;
26589 ++}
26590 +diff -urNp linux-2.6.28/grsecurity/gracl_ip.c linux-2.6.28/grsecurity/gracl_ip.c
26591 +--- linux-2.6.28/grsecurity/gracl_ip.c 1969-12-31 19:00:00.000000000 -0500
26592 ++++ linux-2.6.28/grsecurity/gracl_ip.c 2009-01-11 05:47:03.000000000 -0500
26593 +@@ -0,0 +1,313 @@
26594 ++#include <linux/kernel.h>
26595 ++#include <asm/uaccess.h>
26596 ++#include <asm/errno.h>
26597 ++#include <net/sock.h>
26598 ++#include <linux/file.h>
26599 ++#include <linux/fs.h>
26600 ++#include <linux/net.h>
26601 ++#include <linux/in.h>
26602 ++#include <linux/skbuff.h>
26603 ++#include <linux/ip.h>
26604 ++#include <linux/udp.h>
26605 ++#include <linux/smp_lock.h>
26606 ++#include <linux/types.h>
26607 ++#include <linux/sched.h>
26608 ++#include <linux/netdevice.h>
26609 ++#include <linux/inetdevice.h>
26610 ++#include <linux/gracl.h>
26611 ++#include <linux/grsecurity.h>
26612 ++#include <linux/grinternal.h>
26613 ++
26614 ++#define GR_BIND 0x01
26615 ++#define GR_CONNECT 0x02
26616 ++#define GR_INVERT 0x04
26617 ++
26618 ++static const char * gr_protocols[256] = {
26619 ++ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
26620 ++ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
26621 ++ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
26622 ++ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
26623 ++ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
26624 ++ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
26625 ++ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
26626 ++ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
26627 ++ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
26628 ++ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
26629 ++ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
26630 ++ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
26631 ++ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
26632 ++ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
26633 ++ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
26634 ++ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
26635 ++ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
26636 ++ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
26637 ++ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
26638 ++ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
26639 ++ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
26640 ++ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
26641 ++ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
26642 ++ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
26643 ++ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
26644 ++ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
26645 ++ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
26646 ++ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
26647 ++ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
26648 ++ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
26649 ++ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
26650 ++ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
26651 ++ };
26652 ++
26653 ++static const char * gr_socktypes[11] = {
26654 ++ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
26655 ++ "unknown:7", "unknown:8", "unknown:9", "packet"
26656 ++ };
26657 ++
26658 ++const char *
26659 ++gr_proto_to_name(unsigned char proto)
26660 ++{
26661 ++ return gr_protocols[proto];
26662 ++}
26663 ++
26664 ++const char *
26665 ++gr_socktype_to_name(unsigned char type)
26666 ++{
26667 ++ return gr_socktypes[type];
26668 ++}
26669 ++
26670 ++int
26671 ++gr_search_socket(const int domain, const int type, const int protocol)
26672 ++{
26673 ++ struct acl_subject_label *curr;
26674 ++
26675 ++ if (unlikely(!gr_acl_is_enabled()))
26676 ++ goto exit;
26677 ++
26678 ++ if ((domain < 0) || (type < 0) || (protocol < 0) || (domain != PF_INET)
26679 ++ || (domain >= NPROTO) || (type >= SOCK_MAX) || (protocol > 255))
26680 ++ goto exit; // let the kernel handle it
26681 ++
26682 ++ curr = current->acl;
26683 ++
26684 ++ if (!curr->ips)
26685 ++ goto exit;
26686 ++
26687 ++ if ((curr->ip_type & (1 << type)) &&
26688 ++ (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
26689 ++ goto exit;
26690 ++
26691 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
26692 ++ /* we don't place acls on raw sockets , and sometimes
26693 ++ dgram/ip sockets are opened for ioctl and not
26694 ++ bind/connect, so we'll fake a bind learn log */
26695 ++ if (type == SOCK_RAW || type == SOCK_PACKET) {
26696 ++ __u32 fakeip = 0;
26697 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
26698 ++ current->role->roletype, current->uid,
26699 ++ current->gid, current->exec_file ?
26700 ++ gr_to_filename(current->exec_file->f_path.dentry,
26701 ++ current->exec_file->f_path.mnt) :
26702 ++ curr->filename, curr->filename,
26703 ++ NIPQUAD(fakeip), 0, type,
26704 ++ protocol, GR_CONNECT,
26705 ++NIPQUAD(current->signal->curr_ip));
26706 ++ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
26707 ++ __u32 fakeip = 0;
26708 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
26709 ++ current->role->roletype, current->uid,
26710 ++ current->gid, current->exec_file ?
26711 ++ gr_to_filename(current->exec_file->f_path.dentry,
26712 ++ current->exec_file->f_path.mnt) :
26713 ++ curr->filename, curr->filename,
26714 ++ NIPQUAD(fakeip), 0, type,
26715 ++ protocol, GR_BIND, NIPQUAD(current->signal->curr_ip));
26716 ++ }
26717 ++ /* we'll log when they use connect or bind */
26718 ++ goto exit;
26719 ++ }
26720 ++
26721 ++ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, "inet",
26722 ++ gr_socktype_to_name(type), gr_proto_to_name(protocol));
26723 ++
26724 ++ return 0;
26725 ++ exit:
26726 ++ return 1;
26727 ++}
26728 ++
26729 ++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)
26730 ++{
26731 ++ if ((ip->mode & mode) &&
26732 ++ (ip_port >= ip->low) &&
26733 ++ (ip_port <= ip->high) &&
26734 ++ ((ntohl(ip_addr) & our_netmask) ==
26735 ++ (ntohl(our_addr) & our_netmask))
26736 ++ && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
26737 ++ && (ip->type & (1 << type))) {
26738 ++ if (ip->mode & GR_INVERT)
26739 ++ return 2; // specifically denied
26740 ++ else
26741 ++ return 1; // allowed
26742 ++ }
26743 ++
26744 ++ return 0; // not specifically allowed, may continue parsing
26745 ++}
26746 ++
26747 ++static int
26748 ++gr_search_connectbind(const int mode, const struct sock *sk,
26749 ++ const struct sockaddr_in *addr, const int type)
26750 ++{
26751 ++ char iface[IFNAMSIZ] = {0};
26752 ++ struct acl_subject_label *curr;
26753 ++ struct acl_ip_label *ip;
26754 ++ struct net_device *dev;
26755 ++ struct in_device *idev;
26756 ++ unsigned long i;
26757 ++ int ret;
26758 ++ __u32 ip_addr = 0;
26759 ++ __u32 our_addr;
26760 ++ __u32 our_netmask;
26761 ++ char *p;
26762 ++ __u16 ip_port = 0;
26763 ++
26764 ++ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
26765 ++ return 1;
26766 ++
26767 ++ curr = current->acl;
26768 ++
26769 ++ if (!curr->ips)
26770 ++ return 1;
26771 ++
26772 ++ ip_addr = addr->sin_addr.s_addr;
26773 ++ ip_port = ntohs(addr->sin_port);
26774 ++
26775 ++ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
26776 ++ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
26777 ++ current->role->roletype, current->uid,
26778 ++ current->gid, current->exec_file ?
26779 ++ gr_to_filename(current->exec_file->f_path.dentry,
26780 ++ current->exec_file->f_path.mnt) :
26781 ++ curr->filename, curr->filename,
26782 ++ NIPQUAD(ip_addr), ip_port, type,
26783 ++ sk->sk_protocol, mode, NIPQUAD(current->signal->curr_ip));
26784 ++ return 1;
26785 ++ }
26786 ++
26787 ++ for (i = 0; i < curr->ip_num; i++) {
26788 ++ ip = *(curr->ips + i);
26789 ++ if (ip->iface != NULL) {
26790 ++ strncpy(iface, ip->iface, IFNAMSIZ - 1);
26791 ++ p = strchr(iface, ':');
26792 ++ if (p != NULL)
26793 ++ *p = '\0';
26794 ++ dev = dev_get_by_name(sock_net(sk), iface);
26795 ++ if (dev == NULL)
26796 ++ continue;
26797 ++ idev = in_dev_get(dev);
26798 ++ if (idev == NULL) {
26799 ++ dev_put(dev);
26800 ++ continue;
26801 ++ }
26802 ++ rcu_read_lock();
26803 ++ for_ifa(idev) {
26804 ++ if (!strcmp(ip->iface, ifa->ifa_label)) {
26805 ++ our_addr = ifa->ifa_address;
26806 ++ our_netmask = 0xffffffff;
26807 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
26808 ++ if (ret == 1) {
26809 ++ rcu_read_unlock();
26810 ++ in_dev_put(idev);
26811 ++ dev_put(dev);
26812 ++ return 1;
26813 ++ } else if (ret == 2) {
26814 ++ rcu_read_unlock();
26815 ++ in_dev_put(idev);
26816 ++ dev_put(dev);
26817 ++ goto denied;
26818 ++ }
26819 ++ }
26820 ++ } endfor_ifa(idev);
26821 ++ rcu_read_unlock();
26822 ++ in_dev_put(idev);
26823 ++ dev_put(dev);
26824 ++ } else {
26825 ++ our_addr = ip->addr;
26826 ++ our_netmask = ip->netmask;
26827 ++ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
26828 ++ if (ret == 1)
26829 ++ return 1;
26830 ++ else if (ret == 2)
26831 ++ goto denied;
26832 ++ }
26833 ++ }
26834 ++
26835 ++denied:
26836 ++ if (mode == GR_BIND)
26837 ++ 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));
26838 ++ else if (mode == GR_CONNECT)
26839 ++ 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));
26840 ++
26841 ++ return 0;
26842 ++}
26843 ++
26844 ++int
26845 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
26846 ++{
26847 ++ return gr_search_connectbind(GR_CONNECT, sock->sk, addr, sock->type);
26848 ++}
26849 ++
26850 ++int
26851 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
26852 ++{
26853 ++ return gr_search_connectbind(GR_BIND, sock->sk, addr, sock->type);
26854 ++}
26855 ++
26856 ++int gr_search_listen(const struct socket *sock)
26857 ++{
26858 ++ struct sock *sk = sock->sk;
26859 ++ struct sockaddr_in addr;
26860 ++
26861 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
26862 ++ addr.sin_port = inet_sk(sk)->sport;
26863 ++
26864 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
26865 ++}
26866 ++
26867 ++int gr_search_accept(const struct socket *sock)
26868 ++{
26869 ++ struct sock *sk = sock->sk;
26870 ++ struct sockaddr_in addr;
26871 ++
26872 ++ addr.sin_addr.s_addr = inet_sk(sk)->saddr;
26873 ++ addr.sin_port = inet_sk(sk)->sport;
26874 ++
26875 ++ return gr_search_connectbind(GR_BIND, sock->sk, &addr, sock->type);
26876 ++}
26877 ++
26878 ++int
26879 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
26880 ++{
26881 ++ if (addr)
26882 ++ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
26883 ++ else {
26884 ++ struct sockaddr_in sin;
26885 ++ const struct inet_sock *inet = inet_sk(sk);
26886 ++
26887 ++ sin.sin_addr.s_addr = inet->daddr;
26888 ++ sin.sin_port = inet->dport;
26889 ++
26890 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
26891 ++ }
26892 ++}
26893 ++
26894 ++int
26895 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
26896 ++{
26897 ++ struct sockaddr_in sin;
26898 ++
26899 ++ if (unlikely(skb->len < sizeof (struct udphdr)))
26900 ++ return 1; // skip this packet
26901 ++
26902 ++ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
26903 ++ sin.sin_port = udp_hdr(skb)->source;
26904 ++
26905 ++ return gr_search_connectbind(GR_CONNECT, sk, &sin, SOCK_DGRAM);
26906 ++}
26907 +diff -urNp linux-2.6.28/grsecurity/gracl_learn.c linux-2.6.28/grsecurity/gracl_learn.c
26908 +--- linux-2.6.28/grsecurity/gracl_learn.c 1969-12-31 19:00:00.000000000 -0500
26909 ++++ linux-2.6.28/grsecurity/gracl_learn.c 2009-01-11 05:47:03.000000000 -0500
26910 +@@ -0,0 +1,211 @@
26911 ++#include <linux/kernel.h>
26912 ++#include <linux/mm.h>
26913 ++#include <linux/sched.h>
26914 ++#include <linux/poll.h>
26915 ++#include <linux/smp_lock.h>
26916 ++#include <linux/string.h>
26917 ++#include <linux/file.h>
26918 ++#include <linux/types.h>
26919 ++#include <linux/vmalloc.h>
26920 ++#include <linux/grinternal.h>
26921 ++
26922 ++extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
26923 ++ size_t count, loff_t *ppos);
26924 ++extern int gr_acl_is_enabled(void);
26925 ++
26926 ++static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
26927 ++static int gr_learn_attached;
26928 ++
26929 ++/* use a 512k buffer */
26930 ++#define LEARN_BUFFER_SIZE (512 * 1024)
26931 ++
26932 ++static DEFINE_SPINLOCK(gr_learn_lock);
26933 ++static DECLARE_MUTEX(gr_learn_user_sem);
26934 ++
26935 ++/* we need to maintain two buffers, so that the kernel context of grlearn
26936 ++ uses a semaphore around the userspace copying, and the other kernel contexts
26937 ++ use a spinlock when copying into the buffer, since they cannot sleep
26938 ++*/
26939 ++static char *learn_buffer;
26940 ++static char *learn_buffer_user;
26941 ++static int learn_buffer_len;
26942 ++static int learn_buffer_user_len;
26943 ++
26944 ++static ssize_t
26945 ++read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
26946 ++{
26947 ++ DECLARE_WAITQUEUE(wait, current);
26948 ++ ssize_t retval = 0;
26949 ++
26950 ++ add_wait_queue(&learn_wait, &wait);
26951 ++ set_current_state(TASK_INTERRUPTIBLE);
26952 ++ do {
26953 ++ down(&gr_learn_user_sem);
26954 ++ spin_lock(&gr_learn_lock);
26955 ++ if (learn_buffer_len)
26956 ++ break;
26957 ++ spin_unlock(&gr_learn_lock);
26958 ++ up(&gr_learn_user_sem);
26959 ++ if (file->f_flags & O_NONBLOCK) {
26960 ++ retval = -EAGAIN;
26961 ++ goto out;
26962 ++ }
26963 ++ if (signal_pending(current)) {
26964 ++ retval = -ERESTARTSYS;
26965 ++ goto out;
26966 ++ }
26967 ++
26968 ++ schedule();
26969 ++ } while (1);
26970 ++
26971 ++ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
26972 ++ learn_buffer_user_len = learn_buffer_len;
26973 ++ retval = learn_buffer_len;
26974 ++ learn_buffer_len = 0;
26975 ++
26976 ++ spin_unlock(&gr_learn_lock);
26977 ++
26978 ++ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
26979 ++ retval = -EFAULT;
26980 ++
26981 ++ up(&gr_learn_user_sem);
26982 ++out:
26983 ++ set_current_state(TASK_RUNNING);
26984 ++ remove_wait_queue(&learn_wait, &wait);
26985 ++ return retval;
26986 ++}
26987 ++
26988 ++static unsigned int
26989 ++poll_learn(struct file * file, poll_table * wait)
26990 ++{
26991 ++ poll_wait(file, &learn_wait, wait);
26992 ++
26993 ++ if (learn_buffer_len)
26994 ++ return (POLLIN | POLLRDNORM);
26995 ++
26996 ++ return 0;
26997 ++}
26998 ++
26999 ++void
27000 ++gr_clear_learn_entries(void)
27001 ++{
27002 ++ char *tmp;
27003 ++
27004 ++ down(&gr_learn_user_sem);
27005 ++ if (learn_buffer != NULL) {
27006 ++ spin_lock(&gr_learn_lock);
27007 ++ tmp = learn_buffer;
27008 ++ learn_buffer = NULL;
27009 ++ spin_unlock(&gr_learn_lock);
27010 ++ vfree(learn_buffer);
27011 ++ }
27012 ++ if (learn_buffer_user != NULL) {
27013 ++ vfree(learn_buffer_user);
27014 ++ learn_buffer_user = NULL;
27015 ++ }
27016 ++ learn_buffer_len = 0;
27017 ++ up(&gr_learn_user_sem);
27018 ++
27019 ++ return;
27020 ++}
27021 ++
27022 ++void
27023 ++gr_add_learn_entry(const char *fmt, ...)
27024 ++{
27025 ++ va_list args;
27026 ++ unsigned int len;
27027 ++
27028 ++ if (!gr_learn_attached)
27029 ++ return;
27030 ++
27031 ++ spin_lock(&gr_learn_lock);
27032 ++
27033 ++ /* leave a gap at the end so we know when it's "full" but don't have to
27034 ++ compute the exact length of the string we're trying to append
27035 ++ */
27036 ++ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
27037 ++ spin_unlock(&gr_learn_lock);
27038 ++ wake_up_interruptible(&learn_wait);
27039 ++ return;
27040 ++ }
27041 ++ if (learn_buffer == NULL) {
27042 ++ spin_unlock(&gr_learn_lock);
27043 ++ return;
27044 ++ }
27045 ++
27046 ++ va_start(args, fmt);
27047 ++ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
27048 ++ va_end(args);
27049 ++
27050 ++ learn_buffer_len += len + 1;
27051 ++
27052 ++ spin_unlock(&gr_learn_lock);
27053 ++ wake_up_interruptible(&learn_wait);
27054 ++
27055 ++ return;
27056 ++}
27057 ++
27058 ++static int
27059 ++open_learn(struct inode *inode, struct file *file)
27060 ++{
27061 ++ if (file->f_mode & FMODE_READ && gr_learn_attached)
27062 ++ return -EBUSY;
27063 ++ if (file->f_mode & FMODE_READ) {
27064 ++ int retval = 0;
27065 ++ down(&gr_learn_user_sem);
27066 ++ if (learn_buffer == NULL)
27067 ++ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
27068 ++ if (learn_buffer_user == NULL)
27069 ++ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
27070 ++ if (learn_buffer == NULL) {
27071 ++ retval = -ENOMEM;
27072 ++ goto out_error;
27073 ++ }
27074 ++ if (learn_buffer_user == NULL) {
27075 ++ retval = -ENOMEM;
27076 ++ goto out_error;
27077 ++ }
27078 ++ learn_buffer_len = 0;
27079 ++ learn_buffer_user_len = 0;
27080 ++ gr_learn_attached = 1;
27081 ++out_error:
27082 ++ up(&gr_learn_user_sem);
27083 ++ return retval;
27084 ++ }
27085 ++ return 0;
27086 ++}
27087 ++
27088 ++static int
27089 ++close_learn(struct inode *inode, struct file *file)
27090 ++{
27091 ++ char *tmp;
27092 ++
27093 ++ if (file->f_mode & FMODE_READ) {
27094 ++ down(&gr_learn_user_sem);
27095 ++ if (learn_buffer != NULL) {
27096 ++ spin_lock(&gr_learn_lock);
27097 ++ tmp = learn_buffer;
27098 ++ learn_buffer = NULL;
27099 ++ spin_unlock(&gr_learn_lock);
27100 ++ vfree(tmp);
27101 ++ }
27102 ++ if (learn_buffer_user != NULL) {
27103 ++ vfree(learn_buffer_user);
27104 ++ learn_buffer_user = NULL;
27105 ++ }
27106 ++ learn_buffer_len = 0;
27107 ++ learn_buffer_user_len = 0;
27108 ++ gr_learn_attached = 0;
27109 ++ up(&gr_learn_user_sem);
27110 ++ }
27111 ++
27112 ++ return 0;
27113 ++}
27114 ++
27115 ++struct file_operations grsec_fops = {
27116 ++ .read = read_learn,
27117 ++ .write = write_grsec_handler,
27118 ++ .open = open_learn,
27119 ++ .release = close_learn,
27120 ++ .poll = poll_learn,
27121 ++};
27122 +diff -urNp linux-2.6.28/grsecurity/gracl_res.c linux-2.6.28/grsecurity/gracl_res.c
27123 +--- linux-2.6.28/grsecurity/gracl_res.c 1969-12-31 19:00:00.000000000 -0500
27124 ++++ linux-2.6.28/grsecurity/gracl_res.c 2009-01-11 05:47:03.000000000 -0500
27125 +@@ -0,0 +1,45 @@
27126 ++#include <linux/kernel.h>
27127 ++#include <linux/sched.h>
27128 ++#include <linux/gracl.h>
27129 ++#include <linux/grinternal.h>
27130 ++
27131 ++static const char *restab_log[] = {
27132 ++ [RLIMIT_CPU] = "RLIMIT_CPU",
27133 ++ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
27134 ++ [RLIMIT_DATA] = "RLIMIT_DATA",
27135 ++ [RLIMIT_STACK] = "RLIMIT_STACK",
27136 ++ [RLIMIT_CORE] = "RLIMIT_CORE",
27137 ++ [RLIMIT_RSS] = "RLIMIT_RSS",
27138 ++ [RLIMIT_NPROC] = "RLIMIT_NPROC",
27139 ++ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
27140 ++ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
27141 ++ [RLIMIT_AS] = "RLIMIT_AS",
27142 ++ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
27143 ++ [RLIMIT_LOCKS + 1] = "RLIMIT_CRASH"
27144 ++};
27145 ++
27146 ++void
27147 ++gr_log_resource(const struct task_struct *task,
27148 ++ const int res, const unsigned long wanted, const int gt)
27149 ++{
27150 ++ if (res == RLIMIT_NPROC &&
27151 ++ (cap_raised(task->cap_effective, CAP_SYS_ADMIN) ||
27152 ++ cap_raised(task->cap_effective, CAP_SYS_RESOURCE)))
27153 ++ return;
27154 ++ else if (res == RLIMIT_MEMLOCK &&
27155 ++ cap_raised(task->cap_effective, CAP_IPC_LOCK))
27156 ++ return;
27157 ++
27158 ++ if (!gr_acl_is_enabled() && !grsec_resource_logging)
27159 ++ return;
27160 ++
27161 ++ preempt_disable();
27162 ++
27163 ++ if (unlikely(((gt && wanted > task->signal->rlim[res].rlim_cur) ||
27164 ++ (!gt && wanted >= task->signal->rlim[res].rlim_cur)) &&
27165 ++ task->signal->rlim[res].rlim_cur != RLIM_INFINITY))
27166 ++ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], task->signal->rlim[res].rlim_cur);
27167 ++ preempt_enable_no_resched();
27168 ++
27169 ++ return;
27170 ++}
27171 +diff -urNp linux-2.6.28/grsecurity/gracl_segv.c linux-2.6.28/grsecurity/gracl_segv.c
27172 +--- linux-2.6.28/grsecurity/gracl_segv.c 1969-12-31 19:00:00.000000000 -0500
27173 ++++ linux-2.6.28/grsecurity/gracl_segv.c 2009-01-11 05:47:03.000000000 -0500
27174 +@@ -0,0 +1,304 @@
27175 ++#include <linux/kernel.h>
27176 ++#include <linux/mm.h>
27177 ++#include <asm/uaccess.h>
27178 ++#include <asm/errno.h>
27179 ++#include <asm/mman.h>
27180 ++#include <net/sock.h>
27181 ++#include <linux/file.h>
27182 ++#include <linux/fs.h>
27183 ++#include <linux/net.h>
27184 ++#include <linux/in.h>
27185 ++#include <linux/smp_lock.h>
27186 ++#include <linux/slab.h>
27187 ++#include <linux/types.h>
27188 ++#include <linux/sched.h>
27189 ++#include <linux/timer.h>
27190 ++#include <linux/gracl.h>
27191 ++#include <linux/grsecurity.h>
27192 ++#include <linux/grinternal.h>
27193 ++
27194 ++static struct crash_uid *uid_set;
27195 ++static unsigned short uid_used;
27196 ++static DEFINE_SPINLOCK(gr_uid_lock);
27197 ++extern rwlock_t gr_inode_lock;
27198 ++extern struct acl_subject_label *
27199 ++ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
27200 ++ struct acl_role_label *role);
27201 ++extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
27202 ++
27203 ++int
27204 ++gr_init_uidset(void)
27205 ++{
27206 ++ uid_set =
27207 ++ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
27208 ++ uid_used = 0;
27209 ++
27210 ++ return uid_set ? 1 : 0;
27211 ++}
27212 ++
27213 ++void
27214 ++gr_free_uidset(void)
27215 ++{
27216 ++ if (uid_set)
27217 ++ kfree(uid_set);
27218 ++
27219 ++ return;
27220 ++}
27221 ++
27222 ++int
27223 ++gr_find_uid(const uid_t uid)
27224 ++{
27225 ++ struct crash_uid *tmp = uid_set;
27226 ++ uid_t buid;
27227 ++ int low = 0, high = uid_used - 1, mid;
27228 ++
27229 ++ while (high >= low) {
27230 ++ mid = (low + high) >> 1;
27231 ++ buid = tmp[mid].uid;
27232 ++ if (buid == uid)
27233 ++ return mid;
27234 ++ if (buid > uid)
27235 ++ high = mid - 1;
27236 ++ if (buid < uid)
27237 ++ low = mid + 1;
27238 ++ }
27239 ++
27240 ++ return -1;
27241 ++}
27242 ++
27243 ++static __inline__ void
27244 ++gr_insertsort(void)
27245 ++{
27246 ++ unsigned short i, j;
27247 ++ struct crash_uid index;
27248 ++
27249 ++ for (i = 1; i < uid_used; i++) {
27250 ++ index = uid_set[i];
27251 ++ j = i;
27252 ++ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
27253 ++ uid_set[j] = uid_set[j - 1];
27254 ++ j--;
27255 ++ }
27256 ++ uid_set[j] = index;
27257 ++ }
27258 ++
27259 ++ return;
27260 ++}
27261 ++
27262 ++static __inline__ void
27263 ++gr_insert_uid(const uid_t uid, const unsigned long expires)
27264 ++{
27265 ++ int loc;
27266 ++
27267 ++ if (uid_used == GR_UIDTABLE_MAX)
27268 ++ return;
27269 ++
27270 ++ loc = gr_find_uid(uid);
27271 ++
27272 ++ if (loc >= 0) {
27273 ++ uid_set[loc].expires = expires;
27274 ++ return;
27275 ++ }
27276 ++
27277 ++ uid_set[uid_used].uid = uid;
27278 ++ uid_set[uid_used].expires = expires;
27279 ++ uid_used++;
27280 ++
27281 ++ gr_insertsort();
27282 ++
27283 ++ return;
27284 ++}
27285 ++
27286 ++void
27287 ++gr_remove_uid(const unsigned short loc)
27288 ++{
27289 ++ unsigned short i;
27290 ++
27291 ++ for (i = loc + 1; i < uid_used; i++)
27292 ++ uid_set[i - 1] = uid_set[i];
27293 ++
27294 ++ uid_used--;
27295 ++
27296 ++ return;
27297 ++}
27298 ++
27299 ++int
27300 ++gr_check_crash_uid(const uid_t uid)
27301 ++{
27302 ++ int loc;
27303 ++ int ret = 0;
27304 ++
27305 ++ if (unlikely(!gr_acl_is_enabled()))
27306 ++ return 0;
27307 ++
27308 ++ spin_lock(&gr_uid_lock);
27309 ++ loc = gr_find_uid(uid);
27310 ++
27311 ++ if (loc < 0)
27312 ++ goto out_unlock;
27313 ++
27314 ++ if (time_before_eq(uid_set[loc].expires, get_seconds()))
27315 ++ gr_remove_uid(loc);
27316 ++ else
27317 ++ ret = 1;
27318 ++
27319 ++out_unlock:
27320 ++ spin_unlock(&gr_uid_lock);
27321 ++ return ret;
27322 ++}
27323 ++
27324 ++static __inline__ int
27325 ++proc_is_setxid(const struct task_struct *task)
27326 ++{
27327 ++ if (task->uid != task->euid || task->uid != task->suid ||
27328 ++ task->uid != task->fsuid)
27329 ++ return 1;
27330 ++ if (task->gid != task->egid || task->gid != task->sgid ||
27331 ++ task->gid != task->fsgid)
27332 ++ return 1;
27333 ++
27334 ++ return 0;
27335 ++}
27336 ++static __inline__ int
27337 ++gr_fake_force_sig(int sig, struct task_struct *t)
27338 ++{
27339 ++ unsigned long int flags;
27340 ++ int ret, blocked, ignored;
27341 ++ struct k_sigaction *action;
27342 ++
27343 ++ spin_lock_irqsave(&t->sighand->siglock, flags);
27344 ++ action = &t->sighand->action[sig-1];
27345 ++ ignored = action->sa.sa_handler == SIG_IGN;
27346 ++ blocked = sigismember(&t->blocked, sig);
27347 ++ if (blocked || ignored) {
27348 ++ action->sa.sa_handler = SIG_DFL;
27349 ++ if (blocked) {
27350 ++ sigdelset(&t->blocked, sig);
27351 ++ recalc_sigpending_and_wake(t);
27352 ++ }
27353 ++ }
27354 ++ if (action->sa.sa_handler == SIG_DFL)
27355 ++ t->signal->flags &= ~SIGNAL_UNKILLABLE;
27356 ++ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
27357 ++
27358 ++ spin_unlock_irqrestore(&t->sighand->siglock, flags);
27359 ++
27360 ++ return ret;
27361 ++}
27362 ++
27363 ++void
27364 ++gr_handle_crash(struct task_struct *task, const int sig)
27365 ++{
27366 ++ struct acl_subject_label *curr;
27367 ++ struct acl_subject_label *curr2;
27368 ++ struct task_struct *tsk, *tsk2;
27369 ++
27370 ++ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
27371 ++ return;
27372 ++
27373 ++ if (unlikely(!gr_acl_is_enabled()))
27374 ++ return;
27375 ++
27376 ++ curr = task->acl;
27377 ++
27378 ++ if (!(curr->resmask & (1 << GR_CRASH_RES)))
27379 ++ return;
27380 ++
27381 ++ if (time_before_eq(curr->expires, get_seconds())) {
27382 ++ curr->expires = 0;
27383 ++ curr->crashes = 0;
27384 ++ }
27385 ++
27386 ++ curr->crashes++;
27387 ++
27388 ++ if (!curr->expires)
27389 ++ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
27390 ++
27391 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
27392 ++ time_after(curr->expires, get_seconds())) {
27393 ++ if (task->uid && proc_is_setxid(task)) {
27394 ++ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
27395 ++ spin_lock(&gr_uid_lock);
27396 ++ gr_insert_uid(task->uid, curr->expires);
27397 ++ spin_unlock(&gr_uid_lock);
27398 ++ curr->expires = 0;
27399 ++ curr->crashes = 0;
27400 ++ read_lock(&tasklist_lock);
27401 ++ do_each_thread(tsk2, tsk) {
27402 ++ if (tsk != task && tsk->uid == task->uid)
27403 ++ gr_fake_force_sig(SIGKILL, tsk);
27404 ++ } while_each_thread(tsk2, tsk);
27405 ++ read_unlock(&tasklist_lock);
27406 ++ } else {
27407 ++ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
27408 ++ read_lock(&tasklist_lock);
27409 ++ do_each_thread(tsk2, tsk) {
27410 ++ if (likely(tsk != task)) {
27411 ++ curr2 = tsk->acl;
27412 ++
27413 ++ if (curr2->device == curr->device &&
27414 ++ curr2->inode == curr->inode)
27415 ++ gr_fake_force_sig(SIGKILL, tsk);
27416 ++ }
27417 ++ } while_each_thread(tsk2, tsk);
27418 ++ read_unlock(&tasklist_lock);
27419 ++ }
27420 ++ }
27421 ++
27422 ++ return;
27423 ++}
27424 ++
27425 ++int
27426 ++gr_check_crash_exec(const struct file *filp)
27427 ++{
27428 ++ struct acl_subject_label *curr;
27429 ++
27430 ++ if (unlikely(!gr_acl_is_enabled()))
27431 ++ return 0;
27432 ++
27433 ++ read_lock(&gr_inode_lock);
27434 ++ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
27435 ++ filp->f_path.dentry->d_inode->i_sb->s_dev,
27436 ++ current->role);
27437 ++ read_unlock(&gr_inode_lock);
27438 ++
27439 ++ if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
27440 ++ (!curr->crashes && !curr->expires))
27441 ++ return 0;
27442 ++
27443 ++ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
27444 ++ time_after(curr->expires, get_seconds()))
27445 ++ return 1;
27446 ++ else if (time_before_eq(curr->expires, get_seconds())) {
27447 ++ curr->crashes = 0;
27448 ++ curr->expires = 0;
27449 ++ }
27450 ++
27451 ++ return 0;
27452 ++}
27453 ++
27454 ++void
27455 ++gr_handle_alertkill(struct task_struct *task)
27456 ++{
27457 ++ struct acl_subject_label *curracl;
27458 ++ __u32 curr_ip;
27459 ++ struct task_struct *p, *p2;
27460 ++
27461 ++ if (unlikely(!gr_acl_is_enabled()))
27462 ++ return;
27463 ++
27464 ++ curracl = task->acl;
27465 ++ curr_ip = task->signal->curr_ip;
27466 ++
27467 ++ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
27468 ++ read_lock(&tasklist_lock);
27469 ++ do_each_thread(p2, p) {
27470 ++ if (p->signal->curr_ip == curr_ip)
27471 ++ gr_fake_force_sig(SIGKILL, p);
27472 ++ } while_each_thread(p2, p);
27473 ++ read_unlock(&tasklist_lock);
27474 ++ } else if (curracl->mode & GR_KILLPROC)
27475 ++ gr_fake_force_sig(SIGKILL, task);
27476 ++
27477 ++ return;
27478 ++}
27479 +diff -urNp linux-2.6.28/grsecurity/gracl_shm.c linux-2.6.28/grsecurity/gracl_shm.c
27480 +--- linux-2.6.28/grsecurity/gracl_shm.c 1969-12-31 19:00:00.000000000 -0500
27481 ++++ linux-2.6.28/grsecurity/gracl_shm.c 2009-01-11 05:47:03.000000000 -0500
27482 +@@ -0,0 +1,33 @@
27483 ++#include <linux/kernel.h>
27484 ++#include <linux/mm.h>
27485 ++#include <linux/sched.h>
27486 ++#include <linux/file.h>
27487 ++#include <linux/ipc.h>
27488 ++#include <linux/gracl.h>
27489 ++#include <linux/grsecurity.h>
27490 ++#include <linux/grinternal.h>
27491 ++
27492 ++int
27493 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
27494 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
27495 ++{
27496 ++ struct task_struct *task;
27497 ++
27498 ++ if (!gr_acl_is_enabled())
27499 ++ return 1;
27500 ++
27501 ++ task = find_task_by_vpid(shm_cprid);
27502 ++
27503 ++ if (unlikely(!task))
27504 ++ task = find_task_by_vpid(shm_lapid);
27505 ++
27506 ++ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
27507 ++ (task->pid == shm_lapid)) &&
27508 ++ (task->acl->mode & GR_PROTSHM) &&
27509 ++ (task->acl != current->acl))) {
27510 ++ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
27511 ++ return 0;
27512 ++ }
27513 ++
27514 ++ return 1;
27515 ++}
27516 +diff -urNp linux-2.6.28/grsecurity/grsec_chdir.c linux-2.6.28/grsecurity/grsec_chdir.c
27517 +--- linux-2.6.28/grsecurity/grsec_chdir.c 1969-12-31 19:00:00.000000000 -0500
27518 ++++ linux-2.6.28/grsecurity/grsec_chdir.c 2009-01-11 05:47:03.000000000 -0500
27519 +@@ -0,0 +1,19 @@
27520 ++#include <linux/kernel.h>
27521 ++#include <linux/sched.h>
27522 ++#include <linux/fs.h>
27523 ++#include <linux/file.h>
27524 ++#include <linux/grsecurity.h>
27525 ++#include <linux/grinternal.h>
27526 ++
27527 ++void
27528 ++gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
27529 ++{
27530 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
27531 ++ if ((grsec_enable_chdir && grsec_enable_group &&
27532 ++ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
27533 ++ !grsec_enable_group)) {
27534 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
27535 ++ }
27536 ++#endif
27537 ++ return;
27538 ++}
27539 +diff -urNp linux-2.6.28/grsecurity/grsec_chroot.c linux-2.6.28/grsecurity/grsec_chroot.c
27540 +--- linux-2.6.28/grsecurity/grsec_chroot.c 1969-12-31 19:00:00.000000000 -0500
27541 ++++ linux-2.6.28/grsecurity/grsec_chroot.c 2009-01-11 05:47:03.000000000 -0500
27542 +@@ -0,0 +1,336 @@
27543 ++#include <linux/kernel.h>
27544 ++#include <linux/module.h>
27545 ++#include <linux/sched.h>
27546 ++#include <linux/file.h>
27547 ++#include <linux/fs.h>
27548 ++#include <linux/mount.h>
27549 ++#include <linux/types.h>
27550 ++#include <linux/pid_namespace.h>
27551 ++#include <linux/grsecurity.h>
27552 ++#include <linux/grinternal.h>
27553 ++
27554 ++int
27555 ++gr_handle_chroot_unix(const pid_t pid)
27556 ++{
27557 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
27558 ++ struct pid *spid = NULL;
27559 ++
27560 ++ if (unlikely(!grsec_enable_chroot_unix))
27561 ++ return 1;
27562 ++
27563 ++ if (likely(!proc_is_chrooted(current)))
27564 ++ return 1;
27565 ++
27566 ++ read_lock(&tasklist_lock);
27567 ++
27568 ++ spid = find_vpid(pid);
27569 ++ if (spid) {
27570 ++ struct task_struct *p;
27571 ++ p = pid_task(spid, PIDTYPE_PID);
27572 ++ task_lock(p);
27573 ++ if (unlikely(!have_same_root(current, p))) {
27574 ++ task_unlock(p);
27575 ++ read_unlock(&tasklist_lock);
27576 ++ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
27577 ++ return 0;
27578 ++ }
27579 ++ task_unlock(p);
27580 ++ }
27581 ++ read_unlock(&tasklist_lock);
27582 ++#endif
27583 ++ return 1;
27584 ++}
27585 ++
27586 ++int
27587 ++gr_handle_chroot_nice(void)
27588 ++{
27589 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
27590 ++ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
27591 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
27592 ++ return -EPERM;
27593 ++ }
27594 ++#endif
27595 ++ return 0;
27596 ++}
27597 ++
27598 ++int
27599 ++gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
27600 ++{
27601 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
27602 ++ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
27603 ++ && proc_is_chrooted(current)) {
27604 ++ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
27605 ++ return -EACCES;
27606 ++ }
27607 ++#endif
27608 ++ return 0;
27609 ++}
27610 ++
27611 ++int
27612 ++gr_handle_chroot_rawio(const struct inode *inode)
27613 ++{
27614 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
27615 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
27616 ++ inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
27617 ++ return 1;
27618 ++#endif
27619 ++ return 0;
27620 ++}
27621 ++
27622 ++int
27623 ++gr_pid_is_chrooted(struct task_struct *p)
27624 ++{
27625 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
27626 ++ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
27627 ++ return 0;
27628 ++
27629 ++ task_lock(p);
27630 ++ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
27631 ++ !have_same_root(current, p)) {
27632 ++ task_unlock(p);
27633 ++ return 1;
27634 ++ }
27635 ++ task_unlock(p);
27636 ++#endif
27637 ++ return 0;
27638 ++}
27639 ++
27640 ++EXPORT_SYMBOL(gr_pid_is_chrooted);
27641 ++
27642 ++#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
27643 ++int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
27644 ++{
27645 ++ struct dentry *dentry = (struct dentry *)u_dentry;
27646 ++ struct vfsmount *mnt = (struct vfsmount *)u_mnt;
27647 ++ struct dentry *realroot;
27648 ++ struct vfsmount *realrootmnt;
27649 ++ struct dentry *currentroot;
27650 ++ struct vfsmount *currentmnt;
27651 ++ struct task_struct *reaper = current->nsproxy->pid_ns->child_reaper;
27652 ++ int ret = 1;
27653 ++
27654 ++ read_lock(&reaper->fs->lock);
27655 ++ realrootmnt = mntget(reaper->fs->root.mnt);
27656 ++ realroot = dget(reaper->fs->root.dentry);
27657 ++ read_unlock(&reaper->fs->lock);
27658 ++
27659 ++ read_lock(&current->fs->lock);
27660 ++ currentmnt = mntget(current->fs->root.mnt);
27661 ++ currentroot = dget(current->fs->root.dentry);
27662 ++ read_unlock(&current->fs->lock);
27663 ++
27664 ++ spin_lock(&dcache_lock);
27665 ++ for (;;) {
27666 ++ if (unlikely((dentry == realroot && mnt == realrootmnt)
27667 ++ || (dentry == currentroot && mnt == currentmnt)))
27668 ++ break;
27669 ++ if (unlikely(dentry == mnt->mnt_root || IS_ROOT(dentry))) {
27670 ++ if (mnt->mnt_parent == mnt)
27671 ++ break;
27672 ++ dentry = mnt->mnt_mountpoint;
27673 ++ mnt = mnt->mnt_parent;
27674 ++ continue;
27675 ++ }
27676 ++ dentry = dentry->d_parent;
27677 ++ }
27678 ++ spin_unlock(&dcache_lock);
27679 ++
27680 ++ dput(currentroot);
27681 ++ mntput(currentmnt);
27682 ++
27683 ++ /* access is outside of chroot */
27684 ++ if (dentry == realroot && mnt == realrootmnt)
27685 ++ ret = 0;
27686 ++
27687 ++ dput(realroot);
27688 ++ mntput(realrootmnt);
27689 ++ return ret;
27690 ++}
27691 ++#endif
27692 ++
27693 ++int
27694 ++gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
27695 ++{
27696 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
27697 ++ if (!grsec_enable_chroot_fchdir)
27698 ++ return 1;
27699 ++
27700 ++ if (!proc_is_chrooted(current))
27701 ++ return 1;
27702 ++ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
27703 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
27704 ++ return 0;
27705 ++ }
27706 ++#endif
27707 ++ return 1;
27708 ++}
27709 ++
27710 ++int
27711 ++gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
27712 ++ const time_t shm_createtime)
27713 ++{
27714 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
27715 ++ struct pid *pid = NULL;
27716 ++ time_t starttime;
27717 ++
27718 ++ if (unlikely(!grsec_enable_chroot_shmat))
27719 ++ return 1;
27720 ++
27721 ++ if (likely(!proc_is_chrooted(current)))
27722 ++ return 1;
27723 ++
27724 ++ read_lock(&tasklist_lock);
27725 ++
27726 ++ pid = find_vpid(shm_cprid);
27727 ++ if (pid) {
27728 ++ struct task_struct *p;
27729 ++ p = pid_task(pid, PIDTYPE_PID);
27730 ++ task_lock(p);
27731 ++ starttime = p->start_time.tv_sec;
27732 ++ if (unlikely(!have_same_root(current, p) &&
27733 ++ time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime))) {
27734 ++ task_unlock(p);
27735 ++ read_unlock(&tasklist_lock);
27736 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
27737 ++ return 0;
27738 ++ }
27739 ++ task_unlock(p);
27740 ++ } else {
27741 ++ pid = find_vpid(shm_lapid);
27742 ++ if (pid) {
27743 ++ struct task_struct *p;
27744 ++ p = pid_task(pid, PIDTYPE_PID);
27745 ++ task_lock(p);
27746 ++ if (unlikely(!have_same_root(current, p))) {
27747 ++ task_unlock(p);
27748 ++ read_unlock(&tasklist_lock);
27749 ++ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
27750 ++ return 0;
27751 ++ }
27752 ++ task_unlock(p);
27753 ++ }
27754 ++ }
27755 ++
27756 ++ read_unlock(&tasklist_lock);
27757 ++#endif
27758 ++ return 1;
27759 ++}
27760 ++
27761 ++void
27762 ++gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
27763 ++{
27764 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
27765 ++ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
27766 ++ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
27767 ++#endif
27768 ++ return;
27769 ++}
27770 ++
27771 ++int
27772 ++gr_handle_chroot_mknod(const struct dentry *dentry,
27773 ++ const struct vfsmount *mnt, const int mode)
27774 ++{
27775 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
27776 ++ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
27777 ++ proc_is_chrooted(current)) {
27778 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
27779 ++ return -EPERM;
27780 ++ }
27781 ++#endif
27782 ++ return 0;
27783 ++}
27784 ++
27785 ++int
27786 ++gr_handle_chroot_mount(const struct dentry *dentry,
27787 ++ const struct vfsmount *mnt, const char *dev_name)
27788 ++{
27789 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
27790 ++ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
27791 ++ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name, dentry, mnt);
27792 ++ return -EPERM;
27793 ++ }
27794 ++#endif
27795 ++ return 0;
27796 ++}
27797 ++
27798 ++int
27799 ++gr_handle_chroot_pivot(void)
27800 ++{
27801 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
27802 ++ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
27803 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
27804 ++ return -EPERM;
27805 ++ }
27806 ++#endif
27807 ++ return 0;
27808 ++}
27809 ++
27810 ++int
27811 ++gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
27812 ++{
27813 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
27814 ++ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
27815 ++ !gr_is_outside_chroot(dentry, mnt)) {
27816 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
27817 ++ return -EPERM;
27818 ++ }
27819 ++#endif
27820 ++ return 0;
27821 ++}
27822 ++
27823 ++void
27824 ++gr_handle_chroot_caps(struct task_struct *task)
27825 ++{
27826 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
27827 ++ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
27828 ++ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
27829 ++ task->cap_permitted =
27830 ++ cap_drop(task->cap_permitted, chroot_caps);
27831 ++ task->cap_inheritable =
27832 ++ cap_drop(task->cap_inheritable, chroot_caps);
27833 ++ task->cap_effective =
27834 ++ cap_drop(task->cap_effective, chroot_caps);
27835 ++ }
27836 ++#endif
27837 ++ return;
27838 ++}
27839 ++
27840 ++int
27841 ++gr_handle_chroot_sysctl(const int op)
27842 ++{
27843 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
27844 ++ if (grsec_enable_chroot_sysctl && proc_is_chrooted(current)
27845 ++ && (op & MAY_WRITE))
27846 ++ return -EACCES;
27847 ++#endif
27848 ++ return 0;
27849 ++}
27850 ++
27851 ++void
27852 ++gr_handle_chroot_chdir(struct path *path)
27853 ++{
27854 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
27855 ++ if (grsec_enable_chroot_chdir)
27856 ++ set_fs_pwd(current->fs, path);
27857 ++#endif
27858 ++ return;
27859 ++}
27860 ++
27861 ++int
27862 ++gr_handle_chroot_chmod(const struct dentry *dentry,
27863 ++ const struct vfsmount *mnt, const int mode)
27864 ++{
27865 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
27866 ++ if (grsec_enable_chroot_chmod &&
27867 ++ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
27868 ++ proc_is_chrooted(current)) {
27869 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
27870 ++ return -EPERM;
27871 ++ }
27872 ++#endif
27873 ++ return 0;
27874 ++}
27875 ++
27876 ++#ifdef CONFIG_SECURITY
27877 ++EXPORT_SYMBOL(gr_handle_chroot_caps);
27878 ++#endif
27879 +diff -urNp linux-2.6.28/grsecurity/grsec_disabled.c linux-2.6.28/grsecurity/grsec_disabled.c
27880 +--- linux-2.6.28/grsecurity/grsec_disabled.c 1969-12-31 19:00:00.000000000 -0500
27881 ++++ linux-2.6.28/grsecurity/grsec_disabled.c 2009-01-11 05:47:03.000000000 -0500
27882 +@@ -0,0 +1,418 @@
27883 ++#include <linux/kernel.h>
27884 ++#include <linux/module.h>
27885 ++#include <linux/sched.h>
27886 ++#include <linux/file.h>
27887 ++#include <linux/fs.h>
27888 ++#include <linux/kdev_t.h>
27889 ++#include <linux/net.h>
27890 ++#include <linux/in.h>
27891 ++#include <linux/ip.h>
27892 ++#include <linux/skbuff.h>
27893 ++#include <linux/sysctl.h>
27894 ++
27895 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
27896 ++void
27897 ++pax_set_initial_flags(struct linux_binprm *bprm)
27898 ++{
27899 ++ return;
27900 ++}
27901 ++#endif
27902 ++
27903 ++#ifdef CONFIG_SYSCTL
27904 ++__u32
27905 ++gr_handle_sysctl(const struct ctl_table * table, const int op)
27906 ++{
27907 ++ return 0;
27908 ++}
27909 ++#endif
27910 ++
27911 ++int
27912 ++gr_acl_is_enabled(void)
27913 ++{
27914 ++ return 0;
27915 ++}
27916 ++
27917 ++int
27918 ++gr_handle_rawio(const struct inode *inode)
27919 ++{
27920 ++ return 0;
27921 ++}
27922 ++
27923 ++void
27924 ++gr_acl_handle_psacct(struct task_struct *task, const long code)
27925 ++{
27926 ++ return;
27927 ++}
27928 ++
27929 ++int
27930 ++gr_handle_ptrace(struct task_struct *task, const long request)
27931 ++{
27932 ++ return 0;
27933 ++}
27934 ++
27935 ++int
27936 ++gr_handle_proc_ptrace(struct task_struct *task)
27937 ++{
27938 ++ return 0;
27939 ++}
27940 ++
27941 ++void
27942 ++gr_learn_resource(const struct task_struct *task,
27943 ++ const int res, const unsigned long wanted, const int gt)
27944 ++{
27945 ++ return;
27946 ++}
27947 ++
27948 ++int
27949 ++gr_set_acls(const int type)
27950 ++{
27951 ++ return 0;
27952 ++}
27953 ++
27954 ++int
27955 ++gr_check_hidden_task(const struct task_struct *tsk)
27956 ++{
27957 ++ return 0;
27958 ++}
27959 ++
27960 ++int
27961 ++gr_check_protected_task(const struct task_struct *task)
27962 ++{
27963 ++ return 0;
27964 ++}
27965 ++
27966 ++void
27967 ++gr_copy_label(struct task_struct *tsk)
27968 ++{
27969 ++ return;
27970 ++}
27971 ++
27972 ++void
27973 ++gr_set_pax_flags(struct task_struct *task)
27974 ++{
27975 ++ return;
27976 ++}
27977 ++
27978 ++int
27979 ++gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt)
27980 ++{
27981 ++ return 0;
27982 ++}
27983 ++
27984 ++void
27985 ++gr_handle_delete(const ino_t ino, const dev_t dev)
27986 ++{
27987 ++ return;
27988 ++}
27989 ++
27990 ++void
27991 ++gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
27992 ++{
27993 ++ return;
27994 ++}
27995 ++
27996 ++void
27997 ++gr_handle_crash(struct task_struct *task, const int sig)
27998 ++{
27999 ++ return;
28000 ++}
28001 ++
28002 ++int
28003 ++gr_check_crash_exec(const struct file *filp)
28004 ++{
28005 ++ return 0;
28006 ++}
28007 ++
28008 ++int
28009 ++gr_check_crash_uid(const uid_t uid)
28010 ++{
28011 ++ return 0;
28012 ++}
28013 ++
28014 ++void
28015 ++gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
28016 ++ struct dentry *old_dentry,
28017 ++ struct dentry *new_dentry,
28018 ++ struct vfsmount *mnt, const __u8 replace)
28019 ++{
28020 ++ return;
28021 ++}
28022 ++
28023 ++int
28024 ++gr_search_socket(const int family, const int type, const int protocol)
28025 ++{
28026 ++ return 1;
28027 ++}
28028 ++
28029 ++int
28030 ++gr_search_connectbind(const int mode, const struct socket *sock,
28031 ++ const struct sockaddr_in *addr)
28032 ++{
28033 ++ return 1;
28034 ++}
28035 ++
28036 ++int
28037 ++gr_task_is_capable(struct task_struct *task, const int cap)
28038 ++{
28039 ++ return 1;
28040 ++}
28041 ++
28042 ++int
28043 ++gr_is_capable_nolog(const int cap)
28044 ++{
28045 ++ return 1;
28046 ++}
28047 ++
28048 ++void
28049 ++gr_handle_alertkill(struct task_struct *task)
28050 ++{
28051 ++ return;
28052 ++}
28053 ++
28054 ++__u32
28055 ++gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
28056 ++{
28057 ++ return 1;
28058 ++}
28059 ++
28060 ++__u32
28061 ++gr_acl_handle_hidden_file(const struct dentry * dentry,
28062 ++ const struct vfsmount * mnt)
28063 ++{
28064 ++ return 1;
28065 ++}
28066 ++
28067 ++__u32
28068 ++gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
28069 ++ const int fmode)
28070 ++{
28071 ++ return 1;
28072 ++}
28073 ++
28074 ++__u32
28075 ++gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
28076 ++{
28077 ++ return 1;
28078 ++}
28079 ++
28080 ++__u32
28081 ++gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
28082 ++{
28083 ++ return 1;
28084 ++}
28085 ++
28086 ++int
28087 ++gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
28088 ++ unsigned int *vm_flags)
28089 ++{
28090 ++ return 1;
28091 ++}
28092 ++
28093 ++__u32
28094 ++gr_acl_handle_truncate(const struct dentry * dentry,
28095 ++ const struct vfsmount * mnt)
28096 ++{
28097 ++ return 1;
28098 ++}
28099 ++
28100 ++__u32
28101 ++gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
28102 ++{
28103 ++ return 1;
28104 ++}
28105 ++
28106 ++__u32
28107 ++gr_acl_handle_access(const struct dentry * dentry,
28108 ++ const struct vfsmount * mnt, const int fmode)
28109 ++{
28110 ++ return 1;
28111 ++}
28112 ++
28113 ++__u32
28114 ++gr_acl_handle_fchmod(const struct dentry * dentry, const struct vfsmount * mnt,
28115 ++ mode_t mode)
28116 ++{
28117 ++ return 1;
28118 ++}
28119 ++
28120 ++__u32
28121 ++gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
28122 ++ mode_t mode)
28123 ++{
28124 ++ return 1;
28125 ++}
28126 ++
28127 ++__u32
28128 ++gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
28129 ++{
28130 ++ return 1;
28131 ++}
28132 ++
28133 ++void
28134 ++grsecurity_init(void)
28135 ++{
28136 ++ return;
28137 ++}
28138 ++
28139 ++__u32
28140 ++gr_acl_handle_mknod(const struct dentry * new_dentry,
28141 ++ const struct dentry * parent_dentry,
28142 ++ const struct vfsmount * parent_mnt,
28143 ++ const int mode)
28144 ++{
28145 ++ return 1;
28146 ++}
28147 ++
28148 ++__u32
28149 ++gr_acl_handle_mkdir(const struct dentry * new_dentry,
28150 ++ const struct dentry * parent_dentry,
28151 ++ const struct vfsmount * parent_mnt)
28152 ++{
28153 ++ return 1;
28154 ++}
28155 ++
28156 ++__u32
28157 ++gr_acl_handle_symlink(const struct dentry * new_dentry,
28158 ++ const struct dentry * parent_dentry,
28159 ++ const struct vfsmount * parent_mnt, const char *from)
28160 ++{
28161 ++ return 1;
28162 ++}
28163 ++
28164 ++__u32
28165 ++gr_acl_handle_link(const struct dentry * new_dentry,
28166 ++ const struct dentry * parent_dentry,
28167 ++ const struct vfsmount * parent_mnt,
28168 ++ const struct dentry * old_dentry,
28169 ++ const struct vfsmount * old_mnt, const char *to)
28170 ++{
28171 ++ return 1;
28172 ++}
28173 ++
28174 ++int
28175 ++gr_acl_handle_rename(const struct dentry *new_dentry,
28176 ++ const struct dentry *parent_dentry,
28177 ++ const struct vfsmount *parent_mnt,
28178 ++ const struct dentry *old_dentry,
28179 ++ const struct inode *old_parent_inode,
28180 ++ const struct vfsmount *old_mnt, const char *newname)
28181 ++{
28182 ++ return 0;
28183 ++}
28184 ++
28185 ++int
28186 ++gr_acl_handle_filldir(const struct file *file, const char *name,
28187 ++ const int namelen, const ino_t ino)
28188 ++{
28189 ++ return 1;
28190 ++}
28191 ++
28192 ++int
28193 ++gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
28194 ++ const time_t shm_createtime, const uid_t cuid, const int shmid)
28195 ++{
28196 ++ return 1;
28197 ++}
28198 ++
28199 ++int
28200 ++gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
28201 ++{
28202 ++ return 1;
28203 ++}
28204 ++
28205 ++int
28206 ++gr_search_accept(const struct socket *sock)
28207 ++{
28208 ++ return 1;
28209 ++}
28210 ++
28211 ++int
28212 ++gr_search_listen(const struct socket *sock)
28213 ++{
28214 ++ return 1;
28215 ++}
28216 ++
28217 ++int
28218 ++gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
28219 ++{
28220 ++ return 1;
28221 ++}
28222 ++
28223 ++__u32
28224 ++gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
28225 ++{
28226 ++ return 1;
28227 ++}
28228 ++
28229 ++__u32
28230 ++gr_acl_handle_creat(const struct dentry * dentry,
28231 ++ const struct dentry * p_dentry,
28232 ++ const struct vfsmount * p_mnt, const int fmode,
28233 ++ const int imode)
28234 ++{
28235 ++ return 1;
28236 ++}
28237 ++
28238 ++void
28239 ++gr_acl_handle_exit(void)
28240 ++{
28241 ++ return;
28242 ++}
28243 ++
28244 ++int
28245 ++gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
28246 ++{
28247 ++ return 1;
28248 ++}
28249 ++
28250 ++void
28251 ++gr_set_role_label(const uid_t uid, const gid_t gid)
28252 ++{
28253 ++ return;
28254 ++}
28255 ++
28256 ++int
28257 ++gr_acl_handle_procpidmem(const struct task_struct *task)
28258 ++{
28259 ++ return 0;
28260 ++}
28261 ++
28262 ++int
28263 ++gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
28264 ++{
28265 ++ return 1;
28266 ++}
28267 ++
28268 ++int
28269 ++gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
28270 ++{
28271 ++ return 1;
28272 ++}
28273 ++
28274 ++void
28275 ++gr_set_kernel_label(struct task_struct *task)
28276 ++{
28277 ++ return;
28278 ++}
28279 ++
28280 ++int
28281 ++gr_check_user_change(int real, int effective, int fs)
28282 ++{
28283 ++ return 0;
28284 ++}
28285 ++
28286 ++int
28287 ++gr_check_group_change(int real, int effective, int fs)
28288 ++{
28289 ++ return 0;
28290 ++}
28291 ++
28292 ++
28293 ++EXPORT_SYMBOL(gr_task_is_capable);
28294 ++EXPORT_SYMBOL(gr_is_capable_nolog);
28295 ++EXPORT_SYMBOL(gr_learn_resource);
28296 ++EXPORT_SYMBOL(gr_set_kernel_label);
28297 ++#ifdef CONFIG_SECURITY
28298 ++EXPORT_SYMBOL(gr_check_user_change);
28299 ++EXPORT_SYMBOL(gr_check_group_change);
28300 ++#endif
28301 +diff -urNp linux-2.6.28/grsecurity/grsec_exec.c linux-2.6.28/grsecurity/grsec_exec.c
28302 +--- linux-2.6.28/grsecurity/grsec_exec.c 1969-12-31 19:00:00.000000000 -0500
28303 ++++ linux-2.6.28/grsecurity/grsec_exec.c 2009-01-11 05:47:03.000000000 -0500
28304 +@@ -0,0 +1,88 @@
28305 ++#include <linux/kernel.h>
28306 ++#include <linux/sched.h>
28307 ++#include <linux/file.h>
28308 ++#include <linux/binfmts.h>
28309 ++#include <linux/smp_lock.h>
28310 ++#include <linux/fs.h>
28311 ++#include <linux/types.h>
28312 ++#include <linux/grdefs.h>
28313 ++#include <linux/grinternal.h>
28314 ++#include <linux/capability.h>
28315 ++
28316 ++#include <asm/uaccess.h>
28317 ++
28318 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
28319 ++static char gr_exec_arg_buf[132];
28320 ++static DECLARE_MUTEX(gr_exec_arg_sem);
28321 ++#endif
28322 ++
28323 ++int
28324 ++gr_handle_nproc(void)
28325 ++{
28326 ++#ifdef CONFIG_GRKERNSEC_EXECVE
28327 ++ if (grsec_enable_execve && current->user &&
28328 ++ (atomic_read(&current->user->processes) >
28329 ++ current->signal->rlim[RLIMIT_NPROC].rlim_cur) &&
28330 ++ !capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE)) {
28331 ++ gr_log_noargs(GR_DONT_AUDIT, GR_NPROC_MSG);
28332 ++ return -EAGAIN;
28333 ++ }
28334 ++#endif
28335 ++ return 0;
28336 ++}
28337 ++
28338 ++void
28339 ++gr_handle_exec_args(struct linux_binprm *bprm, const char __user *__user *argv)
28340 ++{
28341 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
28342 ++ char *grarg = gr_exec_arg_buf;
28343 ++ unsigned int i, x, execlen = 0;
28344 ++ char c;
28345 ++
28346 ++ if (!((grsec_enable_execlog && grsec_enable_group &&
28347 ++ in_group_p(grsec_audit_gid))
28348 ++ || (grsec_enable_execlog && !grsec_enable_group)))
28349 ++ return;
28350 ++
28351 ++ down(&gr_exec_arg_sem);
28352 ++ memset(grarg, 0, sizeof(gr_exec_arg_buf));
28353 ++
28354 ++ if (unlikely(argv == NULL))
28355 ++ goto log;
28356 ++
28357 ++ for (i = 0; i < bprm->argc && execlen < 128; i++) {
28358 ++ const char __user *p;
28359 ++ unsigned int len;
28360 ++
28361 ++ if (copy_from_user(&p, argv + i, sizeof(p)))
28362 ++ goto log;
28363 ++ if (!p)
28364 ++ goto log;
28365 ++ len = strnlen_user(p, 128 - execlen);
28366 ++ if (len > 128 - execlen)
28367 ++ len = 128 - execlen;
28368 ++ else if (len > 0)
28369 ++ len--;
28370 ++ if (copy_from_user(grarg + execlen, p, len))
28371 ++ goto log;
28372 ++
28373 ++ /* rewrite unprintable characters */
28374 ++ for (x = 0; x < len; x++) {
28375 ++ c = *(grarg + execlen + x);
28376 ++ if (c < 32 || c > 126)
28377 ++ *(grarg + execlen + x) = ' ';
28378 ++ }
28379 ++
28380 ++ execlen += len;
28381 ++ *(grarg + execlen) = ' ';
28382 ++ *(grarg + execlen + 1) = '\0';
28383 ++ execlen++;
28384 ++ }
28385 ++
28386 ++ log:
28387 ++ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
28388 ++ bprm->file->f_path.mnt, grarg);
28389 ++ up(&gr_exec_arg_sem);
28390 ++#endif
28391 ++ return;
28392 ++}
28393 +diff -urNp linux-2.6.28/grsecurity/grsec_fifo.c linux-2.6.28/grsecurity/grsec_fifo.c
28394 +--- linux-2.6.28/grsecurity/grsec_fifo.c 1969-12-31 19:00:00.000000000 -0500
28395 ++++ linux-2.6.28/grsecurity/grsec_fifo.c 2009-01-11 05:47:03.000000000 -0500
28396 +@@ -0,0 +1,22 @@
28397 ++#include <linux/kernel.h>
28398 ++#include <linux/sched.h>
28399 ++#include <linux/fs.h>
28400 ++#include <linux/file.h>
28401 ++#include <linux/grinternal.h>
28402 ++
28403 ++int
28404 ++gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
28405 ++ const struct dentry *dir, const int flag, const int acc_mode)
28406 ++{
28407 ++#ifdef CONFIG_GRKERNSEC_FIFO
28408 ++ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
28409 ++ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
28410 ++ (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
28411 ++ (current->fsuid != dentry->d_inode->i_uid)) {
28412 ++ if (!generic_permission(dentry->d_inode, acc_mode, NULL))
28413 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
28414 ++ return -EACCES;
28415 ++ }
28416 ++#endif
28417 ++ return 0;
28418 ++}
28419 +diff -urNp linux-2.6.28/grsecurity/grsec_fork.c linux-2.6.28/grsecurity/grsec_fork.c
28420 +--- linux-2.6.28/grsecurity/grsec_fork.c 1969-12-31 19:00:00.000000000 -0500
28421 ++++ linux-2.6.28/grsecurity/grsec_fork.c 2009-01-11 05:47:03.000000000 -0500
28422 +@@ -0,0 +1,15 @@
28423 ++#include <linux/kernel.h>
28424 ++#include <linux/sched.h>
28425 ++#include <linux/grsecurity.h>
28426 ++#include <linux/grinternal.h>
28427 ++#include <linux/errno.h>
28428 ++
28429 ++void
28430 ++gr_log_forkfail(const int retval)
28431 ++{
28432 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
28433 ++ if (grsec_enable_forkfail && retval != -ERESTARTNOINTR)
28434 ++ gr_log_int(GR_DONT_AUDIT, GR_FAILFORK_MSG, retval);
28435 ++#endif
28436 ++ return;
28437 ++}
28438 +diff -urNp linux-2.6.28/grsecurity/grsec_init.c linux-2.6.28/grsecurity/grsec_init.c
28439 +--- linux-2.6.28/grsecurity/grsec_init.c 1969-12-31 19:00:00.000000000 -0500
28440 ++++ linux-2.6.28/grsecurity/grsec_init.c 2009-01-11 05:47:03.000000000 -0500
28441 +@@ -0,0 +1,230 @@
28442 ++#include <linux/kernel.h>
28443 ++#include <linux/sched.h>
28444 ++#include <linux/mm.h>
28445 ++#include <linux/smp_lock.h>
28446 ++#include <linux/gracl.h>
28447 ++#include <linux/slab.h>
28448 ++#include <linux/vmalloc.h>
28449 ++#include <linux/percpu.h>
28450 ++
28451 ++int grsec_enable_link;
28452 ++int grsec_enable_dmesg;
28453 ++int grsec_enable_fifo;
28454 ++int grsec_enable_execve;
28455 ++int grsec_enable_execlog;
28456 ++int grsec_enable_signal;
28457 ++int grsec_enable_forkfail;
28458 ++int grsec_enable_time;
28459 ++int grsec_enable_audit_textrel;
28460 ++int grsec_enable_group;
28461 ++int grsec_audit_gid;
28462 ++int grsec_enable_chdir;
28463 ++int grsec_enable_audit_ipc;
28464 ++int grsec_enable_mount;
28465 ++int grsec_enable_chroot_findtask;
28466 ++int grsec_enable_chroot_mount;
28467 ++int grsec_enable_chroot_shmat;
28468 ++int grsec_enable_chroot_fchdir;
28469 ++int grsec_enable_chroot_double;
28470 ++int grsec_enable_chroot_pivot;
28471 ++int grsec_enable_chroot_chdir;
28472 ++int grsec_enable_chroot_chmod;
28473 ++int grsec_enable_chroot_mknod;
28474 ++int grsec_enable_chroot_nice;
28475 ++int grsec_enable_chroot_execlog;
28476 ++int grsec_enable_chroot_caps;
28477 ++int grsec_enable_chroot_sysctl;
28478 ++int grsec_enable_chroot_unix;
28479 ++int grsec_enable_tpe;
28480 ++int grsec_tpe_gid;
28481 ++int grsec_enable_tpe_all;
28482 ++int grsec_enable_socket_all;
28483 ++int grsec_socket_all_gid;
28484 ++int grsec_enable_socket_client;
28485 ++int grsec_socket_client_gid;
28486 ++int grsec_enable_socket_server;
28487 ++int grsec_socket_server_gid;
28488 ++int grsec_resource_logging;
28489 ++int grsec_lock;
28490 ++
28491 ++DEFINE_SPINLOCK(grsec_alert_lock);
28492 ++unsigned long grsec_alert_wtime = 0;
28493 ++unsigned long grsec_alert_fyet = 0;
28494 ++
28495 ++DEFINE_SPINLOCK(grsec_audit_lock);
28496 ++
28497 ++DEFINE_RWLOCK(grsec_exec_file_lock);
28498 ++
28499 ++char *gr_shared_page[4];
28500 ++
28501 ++char *gr_alert_log_fmt;
28502 ++char *gr_audit_log_fmt;
28503 ++char *gr_alert_log_buf;
28504 ++char *gr_audit_log_buf;
28505 ++
28506 ++extern struct gr_arg *gr_usermode;
28507 ++extern unsigned char *gr_system_salt;
28508 ++extern unsigned char *gr_system_sum;
28509 ++
28510 ++void
28511 ++grsecurity_init(void)
28512 ++{
28513 ++ int j;
28514 ++ /* create the per-cpu shared pages */
28515 ++
28516 ++#ifdef CONFIG_X86
28517 ++ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
28518 ++#endif
28519 ++
28520 ++ for (j = 0; j < 4; j++) {
28521 ++ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE);
28522 ++ if (gr_shared_page[j] == NULL) {
28523 ++ panic("Unable to allocate grsecurity shared page");
28524 ++ return;
28525 ++ }
28526 ++ }
28527 ++
28528 ++ /* allocate log buffers */
28529 ++ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
28530 ++ if (!gr_alert_log_fmt) {
28531 ++ panic("Unable to allocate grsecurity alert log format buffer");
28532 ++ return;
28533 ++ }
28534 ++ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
28535 ++ if (!gr_audit_log_fmt) {
28536 ++ panic("Unable to allocate grsecurity audit log format buffer");
28537 ++ return;
28538 ++ }
28539 ++ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
28540 ++ if (!gr_alert_log_buf) {
28541 ++ panic("Unable to allocate grsecurity alert log buffer");
28542 ++ return;
28543 ++ }
28544 ++ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
28545 ++ if (!gr_audit_log_buf) {
28546 ++ panic("Unable to allocate grsecurity audit log buffer");
28547 ++ return;
28548 ++ }
28549 ++
28550 ++ /* allocate memory for authentication structure */
28551 ++ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
28552 ++ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
28553 ++ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
28554 ++
28555 ++ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
28556 ++ panic("Unable to allocate grsecurity authentication structure");
28557 ++ return;
28558 ++ }
28559 ++
28560 ++#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
28561 ++#ifndef CONFIG_GRKERNSEC_SYSCTL
28562 ++ grsec_lock = 1;
28563 ++#endif
28564 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
28565 ++ grsec_enable_audit_textrel = 1;
28566 ++#endif
28567 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
28568 ++ grsec_enable_group = 1;
28569 ++ grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
28570 ++#endif
28571 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
28572 ++ grsec_enable_chdir = 1;
28573 ++#endif
28574 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28575 ++ grsec_enable_audit_ipc = 1;
28576 ++#endif
28577 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
28578 ++ grsec_enable_mount = 1;
28579 ++#endif
28580 ++#ifdef CONFIG_GRKERNSEC_LINK
28581 ++ grsec_enable_link = 1;
28582 ++#endif
28583 ++#ifdef CONFIG_GRKERNSEC_DMESG
28584 ++ grsec_enable_dmesg = 1;
28585 ++#endif
28586 ++#ifdef CONFIG_GRKERNSEC_FIFO
28587 ++ grsec_enable_fifo = 1;
28588 ++#endif
28589 ++#ifdef CONFIG_GRKERNSEC_EXECVE
28590 ++ grsec_enable_execve = 1;
28591 ++#endif
28592 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
28593 ++ grsec_enable_execlog = 1;
28594 ++#endif
28595 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
28596 ++ grsec_enable_signal = 1;
28597 ++#endif
28598 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
28599 ++ grsec_enable_forkfail = 1;
28600 ++#endif
28601 ++#ifdef CONFIG_GRKERNSEC_TIME
28602 ++ grsec_enable_time = 1;
28603 ++#endif
28604 ++#ifdef CONFIG_GRKERNSEC_RESLOG
28605 ++ grsec_resource_logging = 1;
28606 ++#endif
28607 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
28608 ++ grsec_enable_chroot_findtask = 1;
28609 ++#endif
28610 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
28611 ++ grsec_enable_chroot_unix = 1;
28612 ++#endif
28613 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
28614 ++ grsec_enable_chroot_mount = 1;
28615 ++#endif
28616 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
28617 ++ grsec_enable_chroot_fchdir = 1;
28618 ++#endif
28619 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
28620 ++ grsec_enable_chroot_shmat = 1;
28621 ++#endif
28622 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
28623 ++ grsec_enable_chroot_double = 1;
28624 ++#endif
28625 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
28626 ++ grsec_enable_chroot_pivot = 1;
28627 ++#endif
28628 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
28629 ++ grsec_enable_chroot_chdir = 1;
28630 ++#endif
28631 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
28632 ++ grsec_enable_chroot_chmod = 1;
28633 ++#endif
28634 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
28635 ++ grsec_enable_chroot_mknod = 1;
28636 ++#endif
28637 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
28638 ++ grsec_enable_chroot_nice = 1;
28639 ++#endif
28640 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
28641 ++ grsec_enable_chroot_execlog = 1;
28642 ++#endif
28643 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
28644 ++ grsec_enable_chroot_caps = 1;
28645 ++#endif
28646 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
28647 ++ grsec_enable_chroot_sysctl = 1;
28648 ++#endif
28649 ++#ifdef CONFIG_GRKERNSEC_TPE
28650 ++ grsec_enable_tpe = 1;
28651 ++ grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
28652 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
28653 ++ grsec_enable_tpe_all = 1;
28654 ++#endif
28655 ++#endif
28656 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
28657 ++ grsec_enable_socket_all = 1;
28658 ++ grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
28659 ++#endif
28660 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
28661 ++ grsec_enable_socket_client = 1;
28662 ++ grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
28663 ++#endif
28664 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
28665 ++ grsec_enable_socket_server = 1;
28666 ++ grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
28667 ++#endif
28668 ++#endif
28669 ++
28670 ++ return;
28671 ++}
28672 +diff -urNp linux-2.6.28/grsecurity/grsec_ipc.c linux-2.6.28/grsecurity/grsec_ipc.c
28673 +--- linux-2.6.28/grsecurity/grsec_ipc.c 1969-12-31 19:00:00.000000000 -0500
28674 ++++ linux-2.6.28/grsecurity/grsec_ipc.c 2009-01-11 05:47:03.000000000 -0500
28675 +@@ -0,0 +1,81 @@
28676 ++#include <linux/kernel.h>
28677 ++#include <linux/sched.h>
28678 ++#include <linux/types.h>
28679 ++#include <linux/ipc.h>
28680 ++#include <linux/grsecurity.h>
28681 ++#include <linux/grinternal.h>
28682 ++
28683 ++void
28684 ++gr_log_msgget(const int ret, const int msgflg)
28685 ++{
28686 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28687 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
28688 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
28689 ++ !grsec_enable_group)) && (ret >= 0)
28690 ++ && (msgflg & IPC_CREAT))
28691 ++ gr_log_noargs(GR_DO_AUDIT, GR_MSGQ_AUDIT_MSG);
28692 ++#endif
28693 ++ return;
28694 ++}
28695 ++
28696 ++void
28697 ++gr_log_msgrm(const uid_t uid, const uid_t cuid)
28698 ++{
28699 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28700 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
28701 ++ grsec_enable_audit_ipc) ||
28702 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
28703 ++ gr_log_int_int(GR_DO_AUDIT, GR_MSGQR_AUDIT_MSG, uid, cuid);
28704 ++#endif
28705 ++ return;
28706 ++}
28707 ++
28708 ++void
28709 ++gr_log_semget(const int err, const int semflg)
28710 ++{
28711 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28712 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
28713 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
28714 ++ !grsec_enable_group)) && (err >= 0)
28715 ++ && (semflg & IPC_CREAT))
28716 ++ gr_log_noargs(GR_DO_AUDIT, GR_SEM_AUDIT_MSG);
28717 ++#endif
28718 ++ return;
28719 ++}
28720 ++
28721 ++void
28722 ++gr_log_semrm(const uid_t uid, const uid_t cuid)
28723 ++{
28724 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28725 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
28726 ++ grsec_enable_audit_ipc) ||
28727 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
28728 ++ gr_log_int_int(GR_DO_AUDIT, GR_SEMR_AUDIT_MSG, uid, cuid);
28729 ++#endif
28730 ++ return;
28731 ++}
28732 ++
28733 ++void
28734 ++gr_log_shmget(const int err, const int shmflg, const size_t size)
28735 ++{
28736 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28737 ++ if (((grsec_enable_group && in_group_p(grsec_audit_gid) &&
28738 ++ grsec_enable_audit_ipc) || (grsec_enable_audit_ipc &&
28739 ++ !grsec_enable_group)) && (err >= 0)
28740 ++ && (shmflg & IPC_CREAT))
28741 ++ gr_log_int(GR_DO_AUDIT, GR_SHM_AUDIT_MSG, size);
28742 ++#endif
28743 ++ return;
28744 ++}
28745 ++
28746 ++void
28747 ++gr_log_shmrm(const uid_t uid, const uid_t cuid)
28748 ++{
28749 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
28750 ++ if ((grsec_enable_group && in_group_p(grsec_audit_gid) &&
28751 ++ grsec_enable_audit_ipc) ||
28752 ++ (grsec_enable_audit_ipc && !grsec_enable_group))
28753 ++ gr_log_int_int(GR_DO_AUDIT, GR_SHMR_AUDIT_MSG, uid, cuid);
28754 ++#endif
28755 ++ return;
28756 ++}
28757 +diff -urNp linux-2.6.28/grsecurity/grsec_link.c linux-2.6.28/grsecurity/grsec_link.c
28758 +--- linux-2.6.28/grsecurity/grsec_link.c 1969-12-31 19:00:00.000000000 -0500
28759 ++++ linux-2.6.28/grsecurity/grsec_link.c 2009-01-11 05:47:03.000000000 -0500
28760 +@@ -0,0 +1,39 @@
28761 ++#include <linux/kernel.h>
28762 ++#include <linux/sched.h>
28763 ++#include <linux/fs.h>
28764 ++#include <linux/file.h>
28765 ++#include <linux/grinternal.h>
28766 ++
28767 ++int
28768 ++gr_handle_follow_link(const struct inode *parent,
28769 ++ const struct inode *inode,
28770 ++ const struct dentry *dentry, const struct vfsmount *mnt)
28771 ++{
28772 ++#ifdef CONFIG_GRKERNSEC_LINK
28773 ++ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
28774 ++ (parent->i_mode & S_ISVTX) && (parent->i_uid != inode->i_uid) &&
28775 ++ (parent->i_mode & S_IWOTH) && (current->fsuid != inode->i_uid)) {
28776 ++ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
28777 ++ return -EACCES;
28778 ++ }
28779 ++#endif
28780 ++ return 0;
28781 ++}
28782 ++
28783 ++int
28784 ++gr_handle_hardlink(const struct dentry *dentry,
28785 ++ const struct vfsmount *mnt,
28786 ++ struct inode *inode, const int mode, const char *to)
28787 ++{
28788 ++#ifdef CONFIG_GRKERNSEC_LINK
28789 ++ if (grsec_enable_link && current->fsuid != inode->i_uid &&
28790 ++ (!S_ISREG(mode) || (mode & S_ISUID) ||
28791 ++ ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP)) ||
28792 ++ (generic_permission(inode, MAY_READ | MAY_WRITE, NULL))) &&
28793 ++ !capable(CAP_FOWNER) && current->uid) {
28794 ++ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
28795 ++ return -EPERM;
28796 ++ }
28797 ++#endif
28798 ++ return 0;
28799 ++}
28800 +diff -urNp linux-2.6.28/grsecurity/grsec_log.c linux-2.6.28/grsecurity/grsec_log.c
28801 +--- linux-2.6.28/grsecurity/grsec_log.c 1969-12-31 19:00:00.000000000 -0500
28802 ++++ linux-2.6.28/grsecurity/grsec_log.c 2009-01-11 05:47:03.000000000 -0500
28803 +@@ -0,0 +1,269 @@
28804 ++#include <linux/kernel.h>
28805 ++#include <linux/sched.h>
28806 ++#include <linux/file.h>
28807 ++#include <linux/tty.h>
28808 ++#include <linux/fs.h>
28809 ++#include <linux/grinternal.h>
28810 ++
28811 ++#define BEGIN_LOCKS(x) \
28812 ++ read_lock(&tasklist_lock); \
28813 ++ read_lock(&grsec_exec_file_lock); \
28814 ++ if (x != GR_DO_AUDIT) \
28815 ++ spin_lock(&grsec_alert_lock); \
28816 ++ else \
28817 ++ spin_lock(&grsec_audit_lock)
28818 ++
28819 ++#define END_LOCKS(x) \
28820 ++ if (x != GR_DO_AUDIT) \
28821 ++ spin_unlock(&grsec_alert_lock); \
28822 ++ else \
28823 ++ spin_unlock(&grsec_audit_lock); \
28824 ++ read_unlock(&grsec_exec_file_lock); \
28825 ++ read_unlock(&tasklist_lock); \
28826 ++ if (x == GR_DONT_AUDIT) \
28827 ++ gr_handle_alertkill(current)
28828 ++
28829 ++enum {
28830 ++ FLOODING,
28831 ++ NO_FLOODING
28832 ++};
28833 ++
28834 ++extern char *gr_alert_log_fmt;
28835 ++extern char *gr_audit_log_fmt;
28836 ++extern char *gr_alert_log_buf;
28837 ++extern char *gr_audit_log_buf;
28838 ++
28839 ++static int gr_log_start(int audit)
28840 ++{
28841 ++ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
28842 ++ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
28843 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
28844 ++
28845 ++ if (audit == GR_DO_AUDIT)
28846 ++ goto set_fmt;
28847 ++
28848 ++ if (!grsec_alert_wtime || jiffies - grsec_alert_wtime > CONFIG_GRKERNSEC_FLOODTIME * HZ) {
28849 ++ grsec_alert_wtime = jiffies;
28850 ++ grsec_alert_fyet = 0;
28851 ++ } else if ((jiffies - grsec_alert_wtime < CONFIG_GRKERNSEC_FLOODTIME * HZ) && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
28852 ++ grsec_alert_fyet++;
28853 ++ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
28854 ++ grsec_alert_wtime = jiffies;
28855 ++ grsec_alert_fyet++;
28856 ++ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
28857 ++ return FLOODING;
28858 ++ } else return FLOODING;
28859 ++
28860 ++set_fmt:
28861 ++ memset(buf, 0, PAGE_SIZE);
28862 ++ if (current->signal->curr_ip && gr_acl_is_enabled()) {
28863 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: (%.64s:%c:%.950s) ");
28864 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip), current->role->rolename, gr_roletype_to_char(), current->acl->filename);
28865 ++ } else if (current->signal->curr_ip) {
28866 ++ sprintf(fmt, "%s%s", loglevel, "grsec: From %u.%u.%u.%u: ");
28867 ++ snprintf(buf, PAGE_SIZE - 1, fmt, NIPQUAD(current->signal->curr_ip));
28868 ++ } else if (gr_acl_is_enabled()) {
28869 ++ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
28870 ++ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
28871 ++ } else {
28872 ++ sprintf(fmt, "%s%s", loglevel, "grsec: ");
28873 ++ strcpy(buf, fmt);
28874 ++ }
28875 ++
28876 ++ return NO_FLOODING;
28877 ++}
28878 ++
28879 ++static void gr_log_middle(int audit, const char *msg, va_list ap)
28880 ++{
28881 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
28882 ++ unsigned int len = strlen(buf);
28883 ++
28884 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
28885 ++
28886 ++ return;
28887 ++}
28888 ++
28889 ++static void gr_log_middle_varargs(int audit, const char *msg, ...)
28890 ++{
28891 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
28892 ++ unsigned int len = strlen(buf);
28893 ++ va_list ap;
28894 ++
28895 ++ va_start(ap, msg);
28896 ++ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
28897 ++ va_end(ap);
28898 ++
28899 ++ return;
28900 ++}
28901 ++
28902 ++static void gr_log_end(int audit)
28903 ++{
28904 ++ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
28905 ++ unsigned int len = strlen(buf);
28906 ++
28907 ++ snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current));
28908 ++ printk("%s\n", buf);
28909 ++
28910 ++ return;
28911 ++}
28912 ++
28913 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
28914 ++{
28915 ++ int logtype;
28916 ++ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
28917 ++ char *str1, *str2, *str3;
28918 ++ int num1, num2;
28919 ++ unsigned long ulong1, ulong2;
28920 ++ struct dentry *dentry;
28921 ++ struct vfsmount *mnt;
28922 ++ struct file *file;
28923 ++ struct task_struct *task;
28924 ++ va_list ap;
28925 ++
28926 ++ BEGIN_LOCKS(audit);
28927 ++ logtype = gr_log_start(audit);
28928 ++ if (logtype == FLOODING) {
28929 ++ END_LOCKS(audit);
28930 ++ return;
28931 ++ }
28932 ++ va_start(ap, argtypes);
28933 ++ switch (argtypes) {
28934 ++ case GR_TTYSNIFF:
28935 ++ task = va_arg(ap, struct task_struct *);
28936 ++ 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);
28937 ++ break;
28938 ++ case GR_SYSCTL_HIDDEN:
28939 ++ str1 = va_arg(ap, char *);
28940 ++ gr_log_middle_varargs(audit, msg, result, str1);
28941 ++ break;
28942 ++ case GR_RBAC:
28943 ++ dentry = va_arg(ap, struct dentry *);
28944 ++ mnt = va_arg(ap, struct vfsmount *);
28945 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
28946 ++ break;
28947 ++ case GR_RBAC_STR:
28948 ++ dentry = va_arg(ap, struct dentry *);
28949 ++ mnt = va_arg(ap, struct vfsmount *);
28950 ++ str1 = va_arg(ap, char *);
28951 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
28952 ++ break;
28953 ++ case GR_STR_RBAC:
28954 ++ str1 = va_arg(ap, char *);
28955 ++ dentry = va_arg(ap, struct dentry *);
28956 ++ mnt = va_arg(ap, struct vfsmount *);
28957 ++ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
28958 ++ break;
28959 ++ case GR_RBAC_MODE2:
28960 ++ dentry = va_arg(ap, struct dentry *);
28961 ++ mnt = va_arg(ap, struct vfsmount *);
28962 ++ str1 = va_arg(ap, char *);
28963 ++ str2 = va_arg(ap, char *);
28964 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
28965 ++ break;
28966 ++ case GR_RBAC_MODE3:
28967 ++ dentry = va_arg(ap, struct dentry *);
28968 ++ mnt = va_arg(ap, struct vfsmount *);
28969 ++ str1 = va_arg(ap, char *);
28970 ++ str2 = va_arg(ap, char *);
28971 ++ str3 = va_arg(ap, char *);
28972 ++ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
28973 ++ break;
28974 ++ case GR_FILENAME:
28975 ++ dentry = va_arg(ap, struct dentry *);
28976 ++ mnt = va_arg(ap, struct vfsmount *);
28977 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
28978 ++ break;
28979 ++ case GR_STR_FILENAME:
28980 ++ str1 = va_arg(ap, char *);
28981 ++ dentry = va_arg(ap, struct dentry *);
28982 ++ mnt = va_arg(ap, struct vfsmount *);
28983 ++ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
28984 ++ break;
28985 ++ case GR_FILENAME_STR:
28986 ++ dentry = va_arg(ap, struct dentry *);
28987 ++ mnt = va_arg(ap, struct vfsmount *);
28988 ++ str1 = va_arg(ap, char *);
28989 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
28990 ++ break;
28991 ++ case GR_FILENAME_TWO_INT:
28992 ++ dentry = va_arg(ap, struct dentry *);
28993 ++ mnt = va_arg(ap, struct vfsmount *);
28994 ++ num1 = va_arg(ap, int);
28995 ++ num2 = va_arg(ap, int);
28996 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
28997 ++ break;
28998 ++ case GR_FILENAME_TWO_INT_STR:
28999 ++ dentry = va_arg(ap, struct dentry *);
29000 ++ mnt = va_arg(ap, struct vfsmount *);
29001 ++ num1 = va_arg(ap, int);
29002 ++ num2 = va_arg(ap, int);
29003 ++ str1 = va_arg(ap, char *);
29004 ++ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
29005 ++ break;
29006 ++ case GR_TEXTREL:
29007 ++ file = va_arg(ap, struct file *);
29008 ++ ulong1 = va_arg(ap, unsigned long);
29009 ++ ulong2 = va_arg(ap, unsigned long);
29010 ++ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
29011 ++ break;
29012 ++ case GR_PTRACE:
29013 ++ task = va_arg(ap, struct task_struct *);
29014 ++ 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);
29015 ++ break;
29016 ++ case GR_RESOURCE:
29017 ++ task = va_arg(ap, struct task_struct *);
29018 ++ ulong1 = va_arg(ap, unsigned long);
29019 ++ str1 = va_arg(ap, char *);
29020 ++ ulong2 = va_arg(ap, unsigned long);
29021 ++ 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);
29022 ++ break;
29023 ++ case GR_CAP:
29024 ++ task = va_arg(ap, struct task_struct *);
29025 ++ str1 = va_arg(ap, char *);
29026 ++ 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);
29027 ++ break;
29028 ++ case GR_SIG:
29029 ++ task = va_arg(ap, struct task_struct *);
29030 ++ num1 = va_arg(ap, int);
29031 ++ 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);
29032 ++ break;
29033 ++ case GR_CRASH1:
29034 ++ task = va_arg(ap, struct task_struct *);
29035 ++ ulong1 = va_arg(ap, unsigned long);
29036 ++ 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);
29037 ++ break;
29038 ++ case GR_CRASH2:
29039 ++ task = va_arg(ap, struct task_struct *);
29040 ++ ulong1 = va_arg(ap, unsigned long);
29041 ++ 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);
29042 ++ break;
29043 ++ case GR_PSACCT:
29044 ++ {
29045 ++ unsigned int wday, cday;
29046 ++ __u8 whr, chr;
29047 ++ __u8 wmin, cmin;
29048 ++ __u8 wsec, csec;
29049 ++ char cur_tty[64] = { 0 };
29050 ++ char parent_tty[64] = { 0 };
29051 ++
29052 ++ task = va_arg(ap, struct task_struct *);
29053 ++ wday = va_arg(ap, unsigned int);
29054 ++ cday = va_arg(ap, unsigned int);
29055 ++ whr = va_arg(ap, int);
29056 ++ chr = va_arg(ap, int);
29057 ++ wmin = va_arg(ap, int);
29058 ++ cmin = va_arg(ap, int);
29059 ++ wsec = va_arg(ap, int);
29060 ++ csec = va_arg(ap, int);
29061 ++ ulong1 = va_arg(ap, unsigned long);
29062 ++
29063 ++ 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);
29064 ++ }
29065 ++ break;
29066 ++ default:
29067 ++ gr_log_middle(audit, msg, ap);
29068 ++ }
29069 ++ va_end(ap);
29070 ++ gr_log_end(audit);
29071 ++ END_LOCKS(audit);
29072 ++}
29073 +diff -urNp linux-2.6.28/grsecurity/grsec_mem.c linux-2.6.28/grsecurity/grsec_mem.c
29074 +--- linux-2.6.28/grsecurity/grsec_mem.c 1969-12-31 19:00:00.000000000 -0500
29075 ++++ linux-2.6.28/grsecurity/grsec_mem.c 2009-01-11 05:47:03.000000000 -0500
29076 +@@ -0,0 +1,71 @@
29077 ++#include <linux/kernel.h>
29078 ++#include <linux/sched.h>
29079 ++#include <linux/mm.h>
29080 ++#include <linux/mman.h>
29081 ++#include <linux/grinternal.h>
29082 ++
29083 ++void
29084 ++gr_handle_ioperm(void)
29085 ++{
29086 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
29087 ++ return;
29088 ++}
29089 ++
29090 ++void
29091 ++gr_handle_iopl(void)
29092 ++{
29093 ++ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
29094 ++ return;
29095 ++}
29096 ++
29097 ++void
29098 ++gr_handle_mem_write(void)
29099 ++{
29100 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_WRITE_MSG);
29101 ++ return;
29102 ++}
29103 ++
29104 ++void
29105 ++gr_handle_kmem_write(void)
29106 ++{
29107 ++ gr_log_noargs(GR_DONT_AUDIT, GR_KMEM_MSG);
29108 ++ return;
29109 ++}
29110 ++
29111 ++void
29112 ++gr_handle_open_port(void)
29113 ++{
29114 ++ gr_log_noargs(GR_DONT_AUDIT, GR_PORT_OPEN_MSG);
29115 ++ return;
29116 ++}
29117 ++
29118 ++int
29119 ++gr_handle_mem_mmap(const unsigned long offset, struct vm_area_struct *vma)
29120 ++{
29121 ++ unsigned long start, end;
29122 ++
29123 ++ start = offset;
29124 ++ end = start + vma->vm_end - vma->vm_start;
29125 ++
29126 ++ if (start > end) {
29127 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
29128 ++ return -EPERM;
29129 ++ }
29130 ++
29131 ++ /* allowed ranges : ISA I/O BIOS */
29132 ++ if ((start >= __pa(high_memory))
29133 ++#ifdef CONFIG_X86
29134 ++ || (start >= 0x000a0000 && end <= 0x00100000)
29135 ++ || (start >= 0x00000000 && end <= 0x00001000)
29136 ++#endif
29137 ++ )
29138 ++ return 0;
29139 ++
29140 ++ if (vma->vm_flags & VM_WRITE) {
29141 ++ gr_log_noargs(GR_DONT_AUDIT, GR_MEM_MMAP_MSG);
29142 ++ return -EPERM;
29143 ++ } else
29144 ++ vma->vm_flags &= ~VM_MAYWRITE;
29145 ++
29146 ++ return 0;
29147 ++}
29148 +diff -urNp linux-2.6.28/grsecurity/grsec_mount.c linux-2.6.28/grsecurity/grsec_mount.c
29149 +--- linux-2.6.28/grsecurity/grsec_mount.c 1969-12-31 19:00:00.000000000 -0500
29150 ++++ linux-2.6.28/grsecurity/grsec_mount.c 2009-01-11 05:47:03.000000000 -0500
29151 +@@ -0,0 +1,34 @@
29152 ++#include <linux/kernel.h>
29153 ++#include <linux/sched.h>
29154 ++#include <linux/grsecurity.h>
29155 ++#include <linux/grinternal.h>
29156 ++
29157 ++void
29158 ++gr_log_remount(const char *devname, const int retval)
29159 ++{
29160 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
29161 ++ if (grsec_enable_mount && (retval >= 0))
29162 ++ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
29163 ++#endif
29164 ++ return;
29165 ++}
29166 ++
29167 ++void
29168 ++gr_log_unmount(const char *devname, const int retval)
29169 ++{
29170 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
29171 ++ if (grsec_enable_mount && (retval >= 0))
29172 ++ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
29173 ++#endif
29174 ++ return;
29175 ++}
29176 ++
29177 ++void
29178 ++gr_log_mount(const char *from, const char *to, const int retval)
29179 ++{
29180 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
29181 ++ if (grsec_enable_mount && (retval >= 0))
29182 ++ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from, to);
29183 ++#endif
29184 ++ return;
29185 ++}
29186 +diff -urNp linux-2.6.28/grsecurity/grsec_sig.c linux-2.6.28/grsecurity/grsec_sig.c
29187 +--- linux-2.6.28/grsecurity/grsec_sig.c 1969-12-31 19:00:00.000000000 -0500
29188 ++++ linux-2.6.28/grsecurity/grsec_sig.c 2009-01-11 05:47:03.000000000 -0500
29189 +@@ -0,0 +1,58 @@
29190 ++#include <linux/kernel.h>
29191 ++#include <linux/sched.h>
29192 ++#include <linux/delay.h>
29193 ++#include <linux/grsecurity.h>
29194 ++#include <linux/grinternal.h>
29195 ++
29196 ++void
29197 ++gr_log_signal(const int sig, const struct task_struct *t)
29198 ++{
29199 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
29200 ++ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
29201 ++ (sig == SIGABRT) || (sig == SIGBUS))) {
29202 ++ if (t->pid == current->pid) {
29203 ++ gr_log_int(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, sig);
29204 ++ } else {
29205 ++ gr_log_sig(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
29206 ++ }
29207 ++ }
29208 ++#endif
29209 ++ return;
29210 ++}
29211 ++
29212 ++int
29213 ++gr_handle_signal(const struct task_struct *p, const int sig)
29214 ++{
29215 ++#ifdef CONFIG_GRKERNSEC
29216 ++ if (current->pid > 1 && gr_check_protected_task(p)) {
29217 ++ gr_log_sig(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
29218 ++ return -EPERM;
29219 ++ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
29220 ++ return -EPERM;
29221 ++ }
29222 ++#endif
29223 ++ return 0;
29224 ++}
29225 ++
29226 ++void gr_handle_brute_attach(struct task_struct *p)
29227 ++{
29228 ++#ifdef CONFIG_GRKERNSEC_BRUTE
29229 ++ read_lock(&tasklist_lock);
29230 ++ read_lock(&grsec_exec_file_lock);
29231 ++ if (p->parent && p->parent->exec_file == p->exec_file)
29232 ++ p->parent->brute = 1;
29233 ++ read_unlock(&grsec_exec_file_lock);
29234 ++ read_unlock(&tasklist_lock);
29235 ++#endif
29236 ++ return;
29237 ++}
29238 ++
29239 ++void gr_handle_brute_check(void)
29240 ++{
29241 ++#ifdef CONFIG_GRKERNSEC_BRUTE
29242 ++ if (current->brute)
29243 ++ msleep(30 * 1000);
29244 ++#endif
29245 ++ return;
29246 ++}
29247 ++
29248 +diff -urNp linux-2.6.28/grsecurity/grsec_sock.c linux-2.6.28/grsecurity/grsec_sock.c
29249 +--- linux-2.6.28/grsecurity/grsec_sock.c 1969-12-31 19:00:00.000000000 -0500
29250 ++++ linux-2.6.28/grsecurity/grsec_sock.c 2009-01-11 05:47:03.000000000 -0500
29251 +@@ -0,0 +1,274 @@
29252 ++#include <linux/kernel.h>
29253 ++#include <linux/module.h>
29254 ++#include <linux/sched.h>
29255 ++#include <linux/file.h>
29256 ++#include <linux/net.h>
29257 ++#include <linux/in.h>
29258 ++#include <linux/ip.h>
29259 ++#include <net/sock.h>
29260 ++#include <net/inet_sock.h>
29261 ++#include <linux/grsecurity.h>
29262 ++#include <linux/grinternal.h>
29263 ++#include <linux/gracl.h>
29264 ++
29265 ++#if defined(CONFIG_IP_NF_MATCH_STEALTH_MODULE)
29266 ++extern struct sock *udp_v4_lookup(u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
29267 ++EXPORT_SYMBOL(udp_v4_lookup);
29268 ++#endif
29269 ++
29270 ++kernel_cap_t gr_cap_rtnetlink(struct sock *sock);
29271 ++EXPORT_SYMBOL(gr_cap_rtnetlink);
29272 ++
29273 ++extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
29274 ++extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
29275 ++
29276 ++EXPORT_SYMBOL(gr_search_udp_recvmsg);
29277 ++EXPORT_SYMBOL(gr_search_udp_sendmsg);
29278 ++
29279 ++#ifdef CONFIG_UNIX_MODULE
29280 ++EXPORT_SYMBOL(gr_acl_handle_unix);
29281 ++EXPORT_SYMBOL(gr_acl_handle_mknod);
29282 ++EXPORT_SYMBOL(gr_handle_chroot_unix);
29283 ++EXPORT_SYMBOL(gr_handle_create);
29284 ++#endif
29285 ++
29286 ++#ifdef CONFIG_GRKERNSEC
29287 ++#define gr_conn_table_size 32749
29288 ++struct conn_table_entry {
29289 ++ struct conn_table_entry *next;
29290 ++ struct signal_struct *sig;
29291 ++};
29292 ++
29293 ++struct conn_table_entry *gr_conn_table[gr_conn_table_size];
29294 ++DEFINE_SPINLOCK(gr_conn_table_lock);
29295 ++
29296 ++extern const char * gr_socktype_to_name(unsigned char type);
29297 ++extern const char * gr_proto_to_name(unsigned char proto);
29298 ++
29299 ++static __inline__ int
29300 ++conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
29301 ++{
29302 ++ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
29303 ++}
29304 ++
29305 ++static __inline__ int
29306 ++conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
29307 ++ __u16 sport, __u16 dport)
29308 ++{
29309 ++ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
29310 ++ sig->gr_sport == sport && sig->gr_dport == dport))
29311 ++ return 1;
29312 ++ else
29313 ++ return 0;
29314 ++}
29315 ++
29316 ++static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
29317 ++{
29318 ++ struct conn_table_entry **match;
29319 ++ unsigned int index;
29320 ++
29321 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
29322 ++ sig->gr_sport, sig->gr_dport,
29323 ++ gr_conn_table_size);
29324 ++
29325 ++ newent->sig = sig;
29326 ++
29327 ++ match = &gr_conn_table[index];
29328 ++ newent->next = *match;
29329 ++ *match = newent;
29330 ++
29331 ++ return;
29332 ++}
29333 ++
29334 ++static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
29335 ++{
29336 ++ struct conn_table_entry *match, *last = NULL;
29337 ++ unsigned int index;
29338 ++
29339 ++ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
29340 ++ sig->gr_sport, sig->gr_dport,
29341 ++ gr_conn_table_size);
29342 ++
29343 ++ match = gr_conn_table[index];
29344 ++ while (match && !conn_match(match->sig,
29345 ++ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
29346 ++ sig->gr_dport)) {
29347 ++ last = match;
29348 ++ match = match->next;
29349 ++ }
29350 ++
29351 ++ if (match) {
29352 ++ if (last)
29353 ++ last->next = match->next;
29354 ++ else
29355 ++ gr_conn_table[index] = NULL;
29356 ++ kfree(match);
29357 ++ }
29358 ++
29359 ++ return;
29360 ++}
29361 ++
29362 ++static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
29363 ++ __u16 sport, __u16 dport)
29364 ++{
29365 ++ struct conn_table_entry *match;
29366 ++ unsigned int index;
29367 ++
29368 ++ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
29369 ++
29370 ++ match = gr_conn_table[index];
29371 ++ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
29372 ++ match = match->next;
29373 ++
29374 ++ if (match)
29375 ++ return match->sig;
29376 ++ else
29377 ++ return NULL;
29378 ++}
29379 ++
29380 ++#endif
29381 ++
29382 ++void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
29383 ++{
29384 ++#ifdef CONFIG_GRKERNSEC
29385 ++ struct signal_struct *sig = task->signal;
29386 ++ struct conn_table_entry *newent;
29387 ++
29388 ++ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
29389 ++ if (newent == NULL)
29390 ++ return;
29391 ++ /* no bh lock needed since we are called with bh disabled */
29392 ++ spin_lock(&gr_conn_table_lock);
29393 ++ gr_del_task_from_ip_table_nolock(sig);
29394 ++ sig->gr_saddr = inet->rcv_saddr;
29395 ++ sig->gr_daddr = inet->daddr;
29396 ++ sig->gr_sport = inet->sport;
29397 ++ sig->gr_dport = inet->dport;
29398 ++ gr_add_to_task_ip_table_nolock(sig, newent);
29399 ++ spin_unlock(&gr_conn_table_lock);
29400 ++#endif
29401 ++ return;
29402 ++}
29403 ++
29404 ++void gr_del_task_from_ip_table(struct task_struct *task)
29405 ++{
29406 ++#ifdef CONFIG_GRKERNSEC
29407 ++ spin_lock_bh(&gr_conn_table_lock);
29408 ++ gr_del_task_from_ip_table_nolock(task->signal);
29409 ++ spin_unlock_bh(&gr_conn_table_lock);
29410 ++#endif
29411 ++ return;
29412 ++}
29413 ++
29414 ++void
29415 ++gr_attach_curr_ip(const struct sock *sk)
29416 ++{
29417 ++#ifdef CONFIG_GRKERNSEC
29418 ++ struct signal_struct *p, *set;
29419 ++ const struct inet_sock *inet = inet_sk(sk);
29420 ++
29421 ++ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
29422 ++ return;
29423 ++
29424 ++ set = current->signal;
29425 ++
29426 ++ spin_lock_bh(&gr_conn_table_lock);
29427 ++ p = gr_lookup_task_ip_table(inet->daddr, inet->rcv_saddr,
29428 ++ inet->dport, inet->sport);
29429 ++ if (unlikely(p != NULL)) {
29430 ++ set->curr_ip = p->curr_ip;
29431 ++ set->used_accept = 1;
29432 ++ gr_del_task_from_ip_table_nolock(p);
29433 ++ spin_unlock_bh(&gr_conn_table_lock);
29434 ++ return;
29435 ++ }
29436 ++ spin_unlock_bh(&gr_conn_table_lock);
29437 ++
29438 ++ set->curr_ip = inet->daddr;
29439 ++ set->used_accept = 1;
29440 ++#endif
29441 ++ return;
29442 ++}
29443 ++
29444 ++int
29445 ++gr_handle_sock_all(const int family, const int type, const int protocol)
29446 ++{
29447 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
29448 ++ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
29449 ++ (family != AF_UNIX) && (family != AF_LOCAL)) {
29450 ++ gr_log_int_str2(GR_DONT_AUDIT, GR_SOCK2_MSG, family, gr_socktype_to_name(type), gr_proto_to_name(protocol));
29451 ++ return -EACCES;
29452 ++ }
29453 ++#endif
29454 ++ return 0;
29455 ++}
29456 ++
29457 ++int
29458 ++gr_handle_sock_server(const struct sockaddr *sck)
29459 ++{
29460 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
29461 ++ if (grsec_enable_socket_server &&
29462 ++ in_group_p(grsec_socket_server_gid) &&
29463 ++ sck && (sck->sa_family != AF_UNIX) &&
29464 ++ (sck->sa_family != AF_LOCAL)) {
29465 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
29466 ++ return -EACCES;
29467 ++ }
29468 ++#endif
29469 ++ return 0;
29470 ++}
29471 ++
29472 ++int
29473 ++gr_handle_sock_server_other(const struct sock *sck)
29474 ++{
29475 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
29476 ++ if (grsec_enable_socket_server &&
29477 ++ in_group_p(grsec_socket_server_gid) &&
29478 ++ sck && (sck->sk_family != AF_UNIX) &&
29479 ++ (sck->sk_family != AF_LOCAL)) {
29480 ++ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
29481 ++ return -EACCES;
29482 ++ }
29483 ++#endif
29484 ++ return 0;
29485 ++}
29486 ++
29487 ++int
29488 ++gr_handle_sock_client(const struct sockaddr *sck)
29489 ++{
29490 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
29491 ++ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
29492 ++ sck && (sck->sa_family != AF_UNIX) &&
29493 ++ (sck->sa_family != AF_LOCAL)) {
29494 ++ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
29495 ++ return -EACCES;
29496 ++ }
29497 ++#endif
29498 ++ return 0;
29499 ++}
29500 ++
29501 ++kernel_cap_t
29502 ++gr_cap_rtnetlink(struct sock *sock)
29503 ++{
29504 ++#ifdef CONFIG_GRKERNSEC
29505 ++ if (!gr_acl_is_enabled())
29506 ++ return current->cap_effective;
29507 ++ else if (sock->sk_protocol == NETLINK_ISCSI &&
29508 ++ cap_raised(current->cap_effective, CAP_SYS_ADMIN) &&
29509 ++ gr_task_is_capable(current, CAP_SYS_ADMIN))
29510 ++ return current->cap_effective;
29511 ++ else if (sock->sk_protocol == NETLINK_AUDIT &&
29512 ++ cap_raised(current->cap_effective, CAP_AUDIT_WRITE) &&
29513 ++ gr_task_is_capable(current, CAP_AUDIT_WRITE) &&
29514 ++ cap_raised(current->cap_effective, CAP_AUDIT_CONTROL) &&
29515 ++ gr_task_is_capable(current, CAP_AUDIT_CONTROL))
29516 ++ return current->cap_effective;
29517 ++ else if (cap_raised(current->cap_effective, CAP_NET_ADMIN) &&
29518 ++ gr_task_is_capable(current, CAP_NET_ADMIN))
29519 ++ return current->cap_effective;
29520 ++ else
29521 ++ return __cap_empty_set;
29522 ++#else
29523 ++ return current->cap_effective;
29524 ++#endif
29525 ++}
29526 +diff -urNp linux-2.6.28/grsecurity/grsec_sysctl.c linux-2.6.28/grsecurity/grsec_sysctl.c
29527 +--- linux-2.6.28/grsecurity/grsec_sysctl.c 1969-12-31 19:00:00.000000000 -0500
29528 ++++ linux-2.6.28/grsecurity/grsec_sysctl.c 2009-01-11 05:47:03.000000000 -0500
29529 +@@ -0,0 +1,435 @@
29530 ++#include <linux/kernel.h>
29531 ++#include <linux/sched.h>
29532 ++#include <linux/sysctl.h>
29533 ++#include <linux/grsecurity.h>
29534 ++#include <linux/grinternal.h>
29535 ++
29536 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
29537 ++int grsec_modstop;
29538 ++#endif
29539 ++
29540 ++int
29541 ++gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
29542 ++{
29543 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
29544 ++ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
29545 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
29546 ++ return -EACCES;
29547 ++ }
29548 ++#endif
29549 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
29550 ++ if (!strcmp(dirname, "grsecurity") && !strcmp(name, "disable_modules") &&
29551 ++ grsec_modstop && (op & MAY_WRITE)) {
29552 ++ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
29553 ++ return -EACCES;
29554 ++ }
29555 ++#endif
29556 ++ return 0;
29557 ++}
29558 ++
29559 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
29560 ++ctl_table grsecurity_table[] = {
29561 ++#ifdef CONFIG_GRKERNSEC_SYSCTL
29562 ++#ifdef CONFIG_GRKERNSEC_LINK
29563 ++ {
29564 ++ .ctl_name = CTL_UNNUMBERED,
29565 ++ .procname = "linking_restrictions",
29566 ++ .data = &grsec_enable_link,
29567 ++ .maxlen = sizeof(int),
29568 ++ .mode = 0600,
29569 ++ .proc_handler = &proc_dointvec,
29570 ++ },
29571 ++#endif
29572 ++#ifdef CONFIG_GRKERNSEC_FIFO
29573 ++ {
29574 ++ .ctl_name = CTL_UNNUMBERED,
29575 ++ .procname = "fifo_restrictions",
29576 ++ .data = &grsec_enable_fifo,
29577 ++ .maxlen = sizeof(int),
29578 ++ .mode = 0600,
29579 ++ .proc_handler = &proc_dointvec,
29580 ++ },
29581 ++#endif
29582 ++#ifdef CONFIG_GRKERNSEC_EXECVE
29583 ++ {
29584 ++ .ctl_name = CTL_UNNUMBERED,
29585 ++ .procname = "execve_limiting",
29586 ++ .data = &grsec_enable_execve,
29587 ++ .maxlen = sizeof(int),
29588 ++ .mode = 0600,
29589 ++ .proc_handler = &proc_dointvec,
29590 ++ },
29591 ++#endif
29592 ++#ifdef CONFIG_GRKERNSEC_EXECLOG
29593 ++ {
29594 ++ .ctl_name = CTL_UNNUMBERED,
29595 ++ .procname = "exec_logging",
29596 ++ .data = &grsec_enable_execlog,
29597 ++ .maxlen = sizeof(int),
29598 ++ .mode = 0600,
29599 ++ .proc_handler = &proc_dointvec,
29600 ++ },
29601 ++#endif
29602 ++#ifdef CONFIG_GRKERNSEC_SIGNAL
29603 ++ {
29604 ++ .ctl_name = CTL_UNNUMBERED,
29605 ++ .procname = "signal_logging",
29606 ++ .data = &grsec_enable_signal,
29607 ++ .maxlen = sizeof(int),
29608 ++ .mode = 0600,
29609 ++ .proc_handler = &proc_dointvec,
29610 ++ },
29611 ++#endif
29612 ++#ifdef CONFIG_GRKERNSEC_FORKFAIL
29613 ++ {
29614 ++ .ctl_name = CTL_UNNUMBERED,
29615 ++ .procname = "forkfail_logging",
29616 ++ .data = &grsec_enable_forkfail,
29617 ++ .maxlen = sizeof(int),
29618 ++ .mode = 0600,
29619 ++ .proc_handler = &proc_dointvec,
29620 ++ },
29621 ++#endif
29622 ++#ifdef CONFIG_GRKERNSEC_TIME
29623 ++ {
29624 ++ .ctl_name = CTL_UNNUMBERED,
29625 ++ .procname = "timechange_logging",
29626 ++ .data = &grsec_enable_time,
29627 ++ .maxlen = sizeof(int),
29628 ++ .mode = 0600,
29629 ++ .proc_handler = &proc_dointvec,
29630 ++ },
29631 ++#endif
29632 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
29633 ++ {
29634 ++ .ctl_name = CTL_UNNUMBERED,
29635 ++ .procname = "chroot_deny_shmat",
29636 ++ .data = &grsec_enable_chroot_shmat,
29637 ++ .maxlen = sizeof(int),
29638 ++ .mode = 0600,
29639 ++ .proc_handler = &proc_dointvec,
29640 ++ },
29641 ++#endif
29642 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
29643 ++ {
29644 ++ .ctl_name = CTL_UNNUMBERED,
29645 ++ .procname = "chroot_deny_unix",
29646 ++ .data = &grsec_enable_chroot_unix,
29647 ++ .maxlen = sizeof(int),
29648 ++ .mode = 0600,
29649 ++ .proc_handler = &proc_dointvec,
29650 ++ },
29651 ++#endif
29652 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
29653 ++ {
29654 ++ .ctl_name = CTL_UNNUMBERED,
29655 ++ .procname = "chroot_deny_mount",
29656 ++ .data = &grsec_enable_chroot_mount,
29657 ++ .maxlen = sizeof(int),
29658 ++ .mode = 0600,
29659 ++ .proc_handler = &proc_dointvec,
29660 ++ },
29661 ++#endif
29662 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
29663 ++ {
29664 ++ .ctl_name = CTL_UNNUMBERED,
29665 ++ .procname = "chroot_deny_fchdir",
29666 ++ .data = &grsec_enable_chroot_fchdir,
29667 ++ .maxlen = sizeof(int),
29668 ++ .mode = 0600,
29669 ++ .proc_handler = &proc_dointvec,
29670 ++ },
29671 ++#endif
29672 ++#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
29673 ++ {
29674 ++ .ctl_name = CTL_UNNUMBERED,
29675 ++ .procname = "chroot_deny_chroot",
29676 ++ .data = &grsec_enable_chroot_double,
29677 ++ .maxlen = sizeof(int),
29678 ++ .mode = 0600,
29679 ++ .proc_handler = &proc_dointvec,
29680 ++ },
29681 ++#endif
29682 ++#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
29683 ++ {
29684 ++ .ctl_name = CTL_UNNUMBERED,
29685 ++ .procname = "chroot_deny_pivot",
29686 ++ .data = &grsec_enable_chroot_pivot,
29687 ++ .maxlen = sizeof(int),
29688 ++ .mode = 0600,
29689 ++ .proc_handler = &proc_dointvec,
29690 ++ },
29691 ++#endif
29692 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
29693 ++ {
29694 ++ .ctl_name = CTL_UNNUMBERED,
29695 ++ .procname = "chroot_enforce_chdir",
29696 ++ .data = &grsec_enable_chroot_chdir,
29697 ++ .maxlen = sizeof(int),
29698 ++ .mode = 0600,
29699 ++ .proc_handler = &proc_dointvec,
29700 ++ },
29701 ++#endif
29702 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
29703 ++ {
29704 ++ .ctl_name = CTL_UNNUMBERED,
29705 ++ .procname = "chroot_deny_chmod",
29706 ++ .data = &grsec_enable_chroot_chmod,
29707 ++ .maxlen = sizeof(int),
29708 ++ .mode = 0600,
29709 ++ .proc_handler = &proc_dointvec,
29710 ++ },
29711 ++#endif
29712 ++#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
29713 ++ {
29714 ++ .ctl_name = CTL_UNNUMBERED,
29715 ++ .procname = "chroot_deny_mknod",
29716 ++ .data = &grsec_enable_chroot_mknod,
29717 ++ .maxlen = sizeof(int),
29718 ++ .mode = 0600,
29719 ++ .proc_handler = &proc_dointvec,
29720 ++ },
29721 ++#endif
29722 ++#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
29723 ++ {
29724 ++ .ctl_name = CTL_UNNUMBERED,
29725 ++ .procname = "chroot_restrict_nice",
29726 ++ .data = &grsec_enable_chroot_nice,
29727 ++ .maxlen = sizeof(int),
29728 ++ .mode = 0600,
29729 ++ .proc_handler = &proc_dointvec,
29730 ++ },
29731 ++#endif
29732 ++#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
29733 ++ {
29734 ++ .ctl_name = CTL_UNNUMBERED,
29735 ++ .procname = "chroot_execlog",
29736 ++ .data = &grsec_enable_chroot_execlog,
29737 ++ .maxlen = sizeof(int),
29738 ++ .mode = 0600,
29739 ++ .proc_handler = &proc_dointvec,
29740 ++ },
29741 ++#endif
29742 ++#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
29743 ++ {
29744 ++ .ctl_name = CTL_UNNUMBERED,
29745 ++ .procname = "chroot_caps",
29746 ++ .data = &grsec_enable_chroot_caps,
29747 ++ .maxlen = sizeof(int),
29748 ++ .mode = 0600,
29749 ++ .proc_handler = &proc_dointvec,
29750 ++ },
29751 ++#endif
29752 ++#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
29753 ++ {
29754 ++ .ctl_name = CTL_UNNUMBERED,
29755 ++ .procname = "chroot_deny_sysctl",
29756 ++ .data = &grsec_enable_chroot_sysctl,
29757 ++ .maxlen = sizeof(int),
29758 ++ .mode = 0600,
29759 ++ .proc_handler = &proc_dointvec,
29760 ++ },
29761 ++#endif
29762 ++#ifdef CONFIG_GRKERNSEC_TPE
29763 ++ {
29764 ++ .ctl_name = CTL_UNNUMBERED,
29765 ++ .procname = "tpe",
29766 ++ .data = &grsec_enable_tpe,
29767 ++ .maxlen = sizeof(int),
29768 ++ .mode = 0600,
29769 ++ .proc_handler = &proc_dointvec,
29770 ++ },
29771 ++ {
29772 ++ .ctl_name = CTL_UNNUMBERED,
29773 ++ .procname = "tpe_gid",
29774 ++ .data = &grsec_tpe_gid,
29775 ++ .maxlen = sizeof(int),
29776 ++ .mode = 0600,
29777 ++ .proc_handler = &proc_dointvec,
29778 ++ },
29779 ++#endif
29780 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
29781 ++ {
29782 ++ .ctl_name = CTL_UNNUMBERED,
29783 ++ .procname = "tpe_restrict_all",
29784 ++ .data = &grsec_enable_tpe_all,
29785 ++ .maxlen = sizeof(int),
29786 ++ .mode = 0600,
29787 ++ .proc_handler = &proc_dointvec,
29788 ++ },
29789 ++#endif
29790 ++#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
29791 ++ {
29792 ++ .ctl_name = CTL_UNNUMBERED,
29793 ++ .procname = "socket_all",
29794 ++ .data = &grsec_enable_socket_all,
29795 ++ .maxlen = sizeof(int),
29796 ++ .mode = 0600,
29797 ++ .proc_handler = &proc_dointvec,
29798 ++ },
29799 ++ {
29800 ++ .ctl_name = CTL_UNNUMBERED,
29801 ++ .procname = "socket_all_gid",
29802 ++ .data = &grsec_socket_all_gid,
29803 ++ .maxlen = sizeof(int),
29804 ++ .mode = 0600,
29805 ++ .proc_handler = &proc_dointvec,
29806 ++ },
29807 ++#endif
29808 ++#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
29809 ++ {
29810 ++ .ctl_name = CTL_UNNUMBERED,
29811 ++ .procname = "socket_client",
29812 ++ .data = &grsec_enable_socket_client,
29813 ++ .maxlen = sizeof(int),
29814 ++ .mode = 0600,
29815 ++ .proc_handler = &proc_dointvec,
29816 ++ },
29817 ++ {
29818 ++ .ctl_name = CTL_UNNUMBERED,
29819 ++ .procname = "socket_client_gid",
29820 ++ .data = &grsec_socket_client_gid,
29821 ++ .maxlen = sizeof(int),
29822 ++ .mode = 0600,
29823 ++ .proc_handler = &proc_dointvec,
29824 ++ },
29825 ++#endif
29826 ++#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
29827 ++ {
29828 ++ .ctl_name = CTL_UNNUMBERED,
29829 ++ .procname = "socket_server",
29830 ++ .data = &grsec_enable_socket_server,
29831 ++ .maxlen = sizeof(int),
29832 ++ .mode = 0600,
29833 ++ .proc_handler = &proc_dointvec,
29834 ++ },
29835 ++ {
29836 ++ .ctl_name = CTL_UNNUMBERED,
29837 ++ .procname = "socket_server_gid",
29838 ++ .data = &grsec_socket_server_gid,
29839 ++ .maxlen = sizeof(int),
29840 ++ .mode = 0600,
29841 ++ .proc_handler = &proc_dointvec,
29842 ++ },
29843 ++#endif
29844 ++#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
29845 ++ {
29846 ++ .ctl_name = CTL_UNNUMBERED,
29847 ++ .procname = "audit_group",
29848 ++ .data = &grsec_enable_group,
29849 ++ .maxlen = sizeof(int),
29850 ++ .mode = 0600,
29851 ++ .proc_handler = &proc_dointvec,
29852 ++ },
29853 ++ {
29854 ++ .ctl_name = CTL_UNNUMBERED,
29855 ++ .procname = "audit_gid",
29856 ++ .data = &grsec_audit_gid,
29857 ++ .maxlen = sizeof(int),
29858 ++ .mode = 0600,
29859 ++ .proc_handler = &proc_dointvec,
29860 ++ },
29861 ++#endif
29862 ++#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
29863 ++ {
29864 ++ .ctl_name = CTL_UNNUMBERED,
29865 ++ .procname = "audit_chdir",
29866 ++ .data = &grsec_enable_chdir,
29867 ++ .maxlen = sizeof(int),
29868 ++ .mode = 0600,
29869 ++ .proc_handler = &proc_dointvec,
29870 ++ },
29871 ++#endif
29872 ++#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
29873 ++ {
29874 ++ .ctl_name = CTL_UNNUMBERED,
29875 ++ .procname = "audit_mount",
29876 ++ .data = &grsec_enable_mount,
29877 ++ .maxlen = sizeof(int),
29878 ++ .mode = 0600,
29879 ++ .proc_handler = &proc_dointvec,
29880 ++ },
29881 ++#endif
29882 ++#ifdef CONFIG_GRKERNSEC_AUDIT_IPC
29883 ++ {
29884 ++ .ctl_name = CTL_UNNUMBERED,
29885 ++ .procname = "audit_ipc",
29886 ++ .data = &grsec_enable_audit_ipc,
29887 ++ .maxlen = sizeof(int),
29888 ++ .mode = 0600,
29889 ++ .proc_handler = &proc_dointvec,
29890 ++ },
29891 ++#endif
29892 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
29893 ++ {
29894 ++ .ctl_name = CTL_UNNUMBERED,
29895 ++ .procname = "audit_textrel",
29896 ++ .data = &grsec_enable_audit_textrel,
29897 ++ .maxlen = sizeof(int),
29898 ++ .mode = 0600,
29899 ++ .proc_handler = &proc_dointvec,
29900 ++ },
29901 ++#endif
29902 ++#ifdef CONFIG_GRKERNSEC_DMESG
29903 ++ {
29904 ++ .ctl_name = CTL_UNNUMBERED,
29905 ++ .procname = "dmesg",
29906 ++ .data = &grsec_enable_dmesg,
29907 ++ .maxlen = sizeof(int),
29908 ++ .mode = 0600,
29909 ++ .proc_handler = &proc_dointvec,
29910 ++ },
29911 ++#endif
29912 ++#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
29913 ++ {
29914 ++ .ctl_name = CTL_UNNUMBERED,
29915 ++ .procname = "chroot_findtask",
29916 ++ .data = &grsec_enable_chroot_findtask,
29917 ++ .maxlen = sizeof(int),
29918 ++ .mode = 0600,
29919 ++ .proc_handler = &proc_dointvec,
29920 ++ },
29921 ++#endif
29922 ++#ifdef CONFIG_GRKERNSEC_RESLOG
29923 ++ {
29924 ++ .ctl_name = CTL_UNNUMBERED,
29925 ++ .procname = "resource_logging",
29926 ++ .data = &grsec_resource_logging,
29927 ++ .maxlen = sizeof(int),
29928 ++ .mode = 0600,
29929 ++ .proc_handler = &proc_dointvec,
29930 ++ },
29931 ++#endif
29932 ++ {
29933 ++ .ctl_name = CTL_UNNUMBERED,
29934 ++ .procname = "grsec_lock",
29935 ++ .data = &grsec_lock,
29936 ++ .maxlen = sizeof(int),
29937 ++ .mode = 0600,
29938 ++ .proc_handler = &proc_dointvec,
29939 ++ },
29940 ++#endif
29941 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
29942 ++ {
29943 ++ .ctl_name = CTL_UNNUMBERED,
29944 ++ .procname = "disable_modules",
29945 ++ .data = &grsec_modstop,
29946 ++ .maxlen = sizeof(int),
29947 ++ .mode = 0600,
29948 ++ .proc_handler = &proc_dointvec,
29949 ++ },
29950 ++#endif
29951 ++ { .ctl_name = 0 }
29952 ++};
29953 ++#endif
29954 ++
29955 ++int gr_check_modstop(void)
29956 ++{
29957 ++#ifdef CONFIG_GRKERNSEC_MODSTOP
29958 ++ if (grsec_modstop == 1) {
29959 ++ gr_log_noargs(GR_DONT_AUDIT, GR_STOPMOD_MSG);
29960 ++ return 1;
29961 ++ }
29962 ++#endif
29963 ++ return 0;
29964 ++}
29965 +diff -urNp linux-2.6.28/grsecurity/grsec_textrel.c linux-2.6.28/grsecurity/grsec_textrel.c
29966 +--- linux-2.6.28/grsecurity/grsec_textrel.c 1969-12-31 19:00:00.000000000 -0500
29967 ++++ linux-2.6.28/grsecurity/grsec_textrel.c 2009-01-11 05:47:03.000000000 -0500
29968 +@@ -0,0 +1,16 @@
29969 ++#include <linux/kernel.h>
29970 ++#include <linux/sched.h>
29971 ++#include <linux/mm.h>
29972 ++#include <linux/file.h>
29973 ++#include <linux/grinternal.h>
29974 ++#include <linux/grsecurity.h>
29975 ++
29976 ++void
29977 ++gr_log_textrel(struct vm_area_struct * vma)
29978 ++{
29979 ++#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
29980 ++ if (grsec_enable_audit_textrel)
29981 ++ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
29982 ++#endif
29983 ++ return;
29984 ++}
29985 +diff -urNp linux-2.6.28/grsecurity/grsec_time.c linux-2.6.28/grsecurity/grsec_time.c
29986 +--- linux-2.6.28/grsecurity/grsec_time.c 1969-12-31 19:00:00.000000000 -0500
29987 ++++ linux-2.6.28/grsecurity/grsec_time.c 2009-01-11 05:47:03.000000000 -0500
29988 +@@ -0,0 +1,13 @@
29989 ++#include <linux/kernel.h>
29990 ++#include <linux/sched.h>
29991 ++#include <linux/grinternal.h>
29992 ++
29993 ++void
29994 ++gr_log_timechange(void)
29995 ++{
29996 ++#ifdef CONFIG_GRKERNSEC_TIME
29997 ++ if (grsec_enable_time)
29998 ++ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
29999 ++#endif
30000 ++ return;
30001 ++}
30002 +diff -urNp linux-2.6.28/grsecurity/grsec_tpe.c linux-2.6.28/grsecurity/grsec_tpe.c
30003 +--- linux-2.6.28/grsecurity/grsec_tpe.c 1969-12-31 19:00:00.000000000 -0500
30004 ++++ linux-2.6.28/grsecurity/grsec_tpe.c 2009-01-11 05:47:03.000000000 -0500
30005 +@@ -0,0 +1,37 @@
30006 ++#include <linux/kernel.h>
30007 ++#include <linux/sched.h>
30008 ++#include <linux/file.h>
30009 ++#include <linux/fs.h>
30010 ++#include <linux/grinternal.h>
30011 ++
30012 ++extern int gr_acl_tpe_check(void);
30013 ++
30014 ++int
30015 ++gr_tpe_allow(const struct file *file)
30016 ++{
30017 ++#ifdef CONFIG_GRKERNSEC
30018 ++ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
30019 ++
30020 ++ if (current->uid && ((grsec_enable_tpe &&
30021 ++#ifdef CONFIG_GRKERNSEC_TPE_INVERT
30022 ++ !in_group_p(grsec_tpe_gid)
30023 ++#else
30024 ++ in_group_p(grsec_tpe_gid)
30025 ++#endif
30026 ++ ) || gr_acl_tpe_check()) &&
30027 ++ (inode->i_uid || (!inode->i_uid && ((inode->i_mode & S_IWGRP) ||
30028 ++ (inode->i_mode & S_IWOTH))))) {
30029 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
30030 ++ return 0;
30031 ++ }
30032 ++#ifdef CONFIG_GRKERNSEC_TPE_ALL
30033 ++ if (current->uid && grsec_enable_tpe && grsec_enable_tpe_all &&
30034 ++ ((inode->i_uid && (inode->i_uid != current->uid)) ||
30035 ++ (inode->i_mode & S_IWGRP) || (inode->i_mode & S_IWOTH))) {
30036 ++ gr_log_fs_generic(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, file->f_path.dentry, file->f_path.mnt);
30037 ++ return 0;
30038 ++ }
30039 ++#endif
30040 ++#endif
30041 ++ return 1;
30042 ++}
30043 +diff -urNp linux-2.6.28/grsecurity/grsum.c linux-2.6.28/grsecurity/grsum.c
30044 +--- linux-2.6.28/grsecurity/grsum.c 1969-12-31 19:00:00.000000000 -0500
30045 ++++ linux-2.6.28/grsecurity/grsum.c 2009-01-11 05:47:03.000000000 -0500
30046 +@@ -0,0 +1,59 @@
30047 ++#include <linux/err.h>
30048 ++#include <linux/kernel.h>
30049 ++#include <linux/sched.h>
30050 ++#include <linux/mm.h>
30051 ++#include <linux/scatterlist.h>
30052 ++#include <linux/crypto.h>
30053 ++#include <linux/gracl.h>
30054 ++
30055 ++
30056 ++#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
30057 ++#error "crypto and sha256 must be built into the kernel"
30058 ++#endif
30059 ++
30060 ++int
30061 ++chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
30062 ++{
30063 ++ char *p;
30064 ++ struct crypto_hash *tfm;
30065 ++ struct hash_desc desc;
30066 ++ struct scatterlist sg;
30067 ++ unsigned char temp_sum[GR_SHA_LEN];
30068 ++ volatile int retval = 0;
30069 ++ volatile int dummy = 0;
30070 ++ unsigned int i;
30071 ++
30072 ++ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
30073 ++ if (IS_ERR(tfm)) {
30074 ++ /* should never happen, since sha256 should be built in */
30075 ++ return 1;
30076 ++ }
30077 ++
30078 ++ desc.tfm = tfm;
30079 ++ desc.flags = 0;
30080 ++
30081 ++ crypto_hash_init(&desc);
30082 ++
30083 ++ p = salt;
30084 ++ sg_set_buf(&sg, p, GR_SALT_LEN);
30085 ++ crypto_hash_update(&desc, &sg, sg.length);
30086 ++
30087 ++ p = entry->pw;
30088 ++ sg_set_buf(&sg, p, strlen(p));
30089 ++
30090 ++ crypto_hash_update(&desc, &sg, sg.length);
30091 ++
30092 ++ crypto_hash_final(&desc, temp_sum);
30093 ++
30094 ++ memset(entry->pw, 0, GR_PW_LEN);
30095 ++
30096 ++ for (i = 0; i < GR_SHA_LEN; i++)
30097 ++ if (sum[i] != temp_sum[i])
30098 ++ retval = 1;
30099 ++ else
30100 ++ dummy = 1; // waste a cycle
30101 ++
30102 ++ crypto_free_hash(tfm);
30103 ++
30104 ++ return retval;
30105 ++}
30106 +diff -urNp linux-2.6.28/grsecurity/Kconfig linux-2.6.28/grsecurity/Kconfig
30107 +--- linux-2.6.28/grsecurity/Kconfig 1969-12-31 19:00:00.000000000 -0500
30108 ++++ linux-2.6.28/grsecurity/Kconfig 2009-01-11 07:47:02.000000000 -0500
30109 +@@ -0,0 +1,867 @@
30110 ++#
30111 ++# grecurity configuration
30112 ++#
30113 ++
30114 ++menu "Grsecurity"
30115 ++
30116 ++config GRKERNSEC
30117 ++ bool "Grsecurity"
30118 ++ select CRYPTO
30119 ++ select CRYPTO_SHA256
30120 ++ select SECURITY
30121 ++ select SECURITY_CAPABILITIES
30122 ++ help
30123 ++ If you say Y here, you will be able to configure many features
30124 ++ that will enhance the security of your system. It is highly
30125 ++ recommended that you say Y here and read through the help
30126 ++ for each option so that you fully understand the features and
30127 ++ can evaluate their usefulness for your machine.
30128 ++
30129 ++choice
30130 ++ prompt "Security Level"
30131 ++ depends on GRKERNSEC
30132 ++ default GRKERNSEC_CUSTOM
30133 ++
30134 ++config GRKERNSEC_LOW
30135 ++ bool "Low"
30136 ++ select GRKERNSEC_LINK
30137 ++ select GRKERNSEC_FIFO
30138 ++ select GRKERNSEC_EXECVE
30139 ++ select GRKERNSEC_RANDNET
30140 ++ select GRKERNSEC_DMESG
30141 ++ select GRKERNSEC_CHROOT
30142 ++ select GRKERNSEC_CHROOT_CHDIR
30143 ++ select GRKERNSEC_MODSTOP if (MODULES)
30144 ++
30145 ++ help
30146 ++ If you choose this option, several of the grsecurity options will
30147 ++ be enabled that will give you greater protection against a number
30148 ++ of attacks, while assuring that none of your software will have any
30149 ++ conflicts with the additional security measures. If you run a lot
30150 ++ of unusual software, or you are having problems with the higher
30151 ++ security levels, you should say Y here. With this option, the
30152 ++ following features are enabled:
30153 ++
30154 ++ - Linking restrictions
30155 ++ - FIFO restrictions
30156 ++ - Enforcing RLIMIT_NPROC on execve
30157 ++ - Restricted dmesg
30158 ++ - Enforced chdir("/") on chroot
30159 ++ - Runtime module disabling
30160 ++
30161 ++config GRKERNSEC_MEDIUM
30162 ++ bool "Medium"
30163 ++ select PAX
30164 ++ select PAX_EI_PAX
30165 ++ select PAX_PT_PAX_FLAGS
30166 ++ select PAX_HAVE_ACL_FLAGS
30167 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
30168 ++ select GRKERNSEC_CHROOT
30169 ++ select GRKERNSEC_CHROOT_SYSCTL
30170 ++ select GRKERNSEC_LINK
30171 ++ select GRKERNSEC_FIFO
30172 ++ select GRKERNSEC_EXECVE
30173 ++ select GRKERNSEC_DMESG
30174 ++ select GRKERNSEC_RANDNET
30175 ++ select GRKERNSEC_FORKFAIL
30176 ++ select GRKERNSEC_TIME
30177 ++ select GRKERNSEC_SIGNAL
30178 ++ select GRKERNSEC_CHROOT
30179 ++ select GRKERNSEC_CHROOT_UNIX
30180 ++ select GRKERNSEC_CHROOT_MOUNT
30181 ++ select GRKERNSEC_CHROOT_PIVOT
30182 ++ select GRKERNSEC_CHROOT_DOUBLE
30183 ++ select GRKERNSEC_CHROOT_CHDIR
30184 ++ select GRKERNSEC_CHROOT_MKNOD
30185 ++ select GRKERNSEC_PROC
30186 ++ select GRKERNSEC_PROC_USERGROUP
30187 ++ select GRKERNSEC_MODSTOP if (MODULES)
30188 ++ select PAX_RANDUSTACK
30189 ++ select PAX_ASLR
30190 ++ select PAX_RANDMMAP
30191 ++ select PAX_REFCOUNT if (X86)
30192 ++
30193 ++ help
30194 ++ If you say Y here, several features in addition to those included
30195 ++ in the low additional security level will be enabled. These
30196 ++ features provide even more security to your system, though in rare
30197 ++ cases they may be incompatible with very old or poorly written
30198 ++ software. If you enable this option, make sure that your auth
30199 ++ service (identd) is running as gid 1001. With this option,
30200 ++ the following features (in addition to those provided in the
30201 ++ low additional security level) will be enabled:
30202 ++
30203 ++ - Failed fork logging
30204 ++ - Time change logging
30205 ++ - Signal logging
30206 ++ - Deny mounts in chroot
30207 ++ - Deny double chrooting
30208 ++ - Deny sysctl writes in chroot
30209 ++ - Deny mknod in chroot
30210 ++ - Deny access to abstract AF_UNIX sockets out of chroot
30211 ++ - Deny pivot_root in chroot
30212 ++ - Denied writes of /dev/kmem, /dev/mem, and /dev/port
30213 ++ - /proc restrictions with special GID set to 10 (usually wheel)
30214 ++ - Address Space Layout Randomization (ASLR)
30215 ++ - Prevent exploitation of most refcount overflows
30216 ++
30217 ++config GRKERNSEC_HIGH
30218 ++ bool "High"
30219 ++ select GRKERNSEC_LINK
30220 ++ select GRKERNSEC_FIFO
30221 ++ select GRKERNSEC_EXECVE
30222 ++ select GRKERNSEC_DMESG
30223 ++ select GRKERNSEC_FORKFAIL
30224 ++ select GRKERNSEC_TIME
30225 ++ select GRKERNSEC_SIGNAL
30226 ++ select GRKERNSEC_CHROOT
30227 ++ select GRKERNSEC_CHROOT_SHMAT
30228 ++ select GRKERNSEC_CHROOT_UNIX
30229 ++ select GRKERNSEC_CHROOT_MOUNT
30230 ++ select GRKERNSEC_CHROOT_FCHDIR
30231 ++ select GRKERNSEC_CHROOT_PIVOT
30232 ++ select GRKERNSEC_CHROOT_DOUBLE
30233 ++ select GRKERNSEC_CHROOT_CHDIR
30234 ++ select GRKERNSEC_CHROOT_MKNOD
30235 ++ select GRKERNSEC_CHROOT_CAPS
30236 ++ select GRKERNSEC_CHROOT_SYSCTL
30237 ++ select GRKERNSEC_CHROOT_FINDTASK
30238 ++ select GRKERNSEC_PROC
30239 ++ select GRKERNSEC_PROC_MEMMAP if (PAX_NOEXEC || PAX_ASLR)
30240 ++ select GRKERNSEC_HIDESYM
30241 ++ select GRKERNSEC_BRUTE
30242 ++ select GRKERNSEC_PROC_USERGROUP
30243 ++ select GRKERNSEC_KMEM
30244 ++ select GRKERNSEC_RESLOG
30245 ++ select GRKERNSEC_RANDNET
30246 ++ select GRKERNSEC_PROC_ADD
30247 ++ select GRKERNSEC_CHROOT_CHMOD
30248 ++ select GRKERNSEC_CHROOT_NICE
30249 ++ select GRKERNSEC_AUDIT_MOUNT
30250 ++ select GRKERNSEC_MODSTOP if (MODULES)
30251 ++ select PAX
30252 ++ select PAX_RANDUSTACK
30253 ++ select PAX_ASLR
30254 ++ select PAX_RANDMMAP
30255 ++ select PAX_NOEXEC
30256 ++ select PAX_MPROTECT
30257 ++ select PAX_EI_PAX
30258 ++ select PAX_PT_PAX_FLAGS
30259 ++ select PAX_HAVE_ACL_FLAGS
30260 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
30261 ++ select PAX_MEMORY_UDEREF if (!X86_64 && !COMPAT_VDSO)
30262 ++ select PAX_RANDKSTACK if (X86_TSC && !X86_64)
30263 ++ select PAX_SEGMEXEC if (X86 && !X86_64)
30264 ++ select PAX_PAGEEXEC if (!X86)
30265 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
30266 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
30267 ++ select PAX_SYSCALL if (PPC32)
30268 ++ select PAX_EMUTRAMP if (PARISC)
30269 ++ select PAX_EMUSIGRT if (PARISC)
30270 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
30271 ++ select PAX_REFCOUNT if (X86)
30272 ++ help
30273 ++ If you say Y here, many of the features of grsecurity will be
30274 ++ enabled, which will protect you against many kinds of attacks
30275 ++ against your system. The heightened security comes at a cost
30276 ++ of an increased chance of incompatibilities with rare software
30277 ++ on your machine. Since this security level enables PaX, you should
30278 ++ view <http://pax.grsecurity.net> and read about the PaX
30279 ++ project. While you are there, download chpax and run it on
30280 ++ binaries that cause problems with PaX. Also remember that
30281 ++ since the /proc restrictions are enabled, you must run your
30282 ++ identd as gid 1001. This security level enables the following
30283 ++ features in addition to those listed in the low and medium
30284 ++ security levels:
30285 ++
30286 ++ - Additional /proc restrictions
30287 ++ - Chmod restrictions in chroot
30288 ++ - No signals, ptrace, or viewing of processes outside of chroot
30289 ++ - Capability restrictions in chroot
30290 ++ - Deny fchdir out of chroot
30291 ++ - Priority restrictions in chroot
30292 ++ - Segmentation-based implementation of PaX
30293 ++ - Mprotect restrictions
30294 ++ - Removal of addresses from /proc/<pid>/[smaps|maps|stat]
30295 ++ - Kernel stack randomization
30296 ++ - Mount/unmount/remount logging
30297 ++ - Kernel symbol hiding
30298 ++ - Prevention of memory exhaustion-based exploits
30299 ++config GRKERNSEC_CUSTOM
30300 ++ bool "Custom"
30301 ++ help
30302 ++ If you say Y here, you will be able to configure every grsecurity
30303 ++ option, which allows you to enable many more features that aren't
30304 ++ covered in the basic security levels. These additional features
30305 ++ include TPE, socket restrictions, and the sysctl system for
30306 ++ grsecurity. It is advised that you read through the help for
30307 ++ each option to determine its usefulness in your situation.
30308 ++
30309 ++endchoice
30310 ++
30311 ++menu "Address Space Protection"
30312 ++depends on GRKERNSEC
30313 ++
30314 ++config GRKERNSEC_KMEM
30315 ++ bool "Deny writing to /dev/kmem, /dev/mem, and /dev/port"
30316 ++ help
30317 ++ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
30318 ++ be written to via mmap or otherwise to modify the running kernel.
30319 ++ /dev/port will also not be allowed to be opened. If you have module
30320 ++ support disabled, enabling this will close up four ways that are
30321 ++ currently used to insert malicious code into the running kernel.
30322 ++ Even with all these features enabled, we still highly recommend that
30323 ++ you use the RBAC system, as it is still possible for an attacker to
30324 ++ modify the running kernel through privileged I/O granted by ioperm/iopl.
30325 ++ If you are not using XFree86, you may be able to stop this additional
30326 ++ case by enabling the 'Disable privileged I/O' option. Though nothing
30327 ++ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
30328 ++ but only to video memory, which is the only writing we allow in this
30329 ++ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
30330 ++ not be allowed to mprotect it with PROT_WRITE later.
30331 ++ It is highly recommended that you say Y here if you meet all the
30332 ++ conditions above.
30333 ++
30334 ++config GRKERNSEC_IO
30335 ++ bool "Disable privileged I/O"
30336 ++ depends on X86
30337 ++ select RTC
30338 ++ help
30339 ++ If you say Y here, all ioperm and iopl calls will return an error.
30340 ++ Ioperm and iopl can be used to modify the running kernel.
30341 ++ Unfortunately, some programs need this access to operate properly,
30342 ++ the most notable of which are XFree86 and hwclock. hwclock can be
30343 ++ remedied by having RTC support in the kernel, so CONFIG_RTC is
30344 ++ enabled if this option is enabled, to ensure that hwclock operates
30345 ++ correctly. XFree86 still will not operate correctly with this option
30346 ++ enabled, so DO NOT CHOOSE Y IF YOU USE XFree86. If you use XFree86
30347 ++ and you still want to protect your kernel against modification,
30348 ++ use the RBAC system.
30349 ++
30350 ++config GRKERNSEC_PROC_MEMMAP
30351 ++ bool "Remove addresses from /proc/<pid>/[smaps|maps|stat]"
30352 ++ depends on PAX_NOEXEC || PAX_ASLR
30353 ++ help
30354 ++ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
30355 ++ give no information about the addresses of its mappings if
30356 ++ PaX features that rely on random addresses are enabled on the task.
30357 ++ If you use PaX it is greatly recommended that you say Y here as it
30358 ++ closes up a hole that makes the full ASLR useless for suid
30359 ++ binaries.
30360 ++
30361 ++config GRKERNSEC_BRUTE
30362 ++ bool "Deter exploit bruteforcing"
30363 ++ help
30364 ++ If you say Y here, attempts to bruteforce exploits against forking
30365 ++ daemons such as apache or sshd will be deterred. When a child of a
30366 ++ forking daemon is killed by PaX or crashes due to an illegal
30367 ++ instruction, the parent process will be delayed 30 seconds upon every
30368 ++ subsequent fork until the administrator is able to assess the
30369 ++ situation and restart the daemon. It is recommended that you also
30370 ++ enable signal logging in the auditing section so that logs are
30371 ++ generated when a process performs an illegal instruction.
30372 ++
30373 ++config GRKERNSEC_MODSTOP
30374 ++ bool "Runtime module disabling"
30375 ++ depends on MODULES
30376 ++ help
30377 ++ If you say Y here, you will be able to disable the ability to (un)load
30378 ++ modules at runtime. This feature is useful if you need the ability
30379 ++ to load kernel modules at boot time, but do not want to allow an
30380 ++ attacker to load a rootkit kernel module into the system, or to remove
30381 ++ a loaded kernel module important to system functioning. You should
30382 ++ enable the /dev/mem protection feature as well, since rootkits can be
30383 ++ inserted into the kernel via other methods than kernel modules. Since
30384 ++ an untrusted module could still be loaded by modifying init scripts and
30385 ++ rebooting the system, it is also recommended that you enable the RBAC
30386 ++ system. If you enable this option, a sysctl option with name
30387 ++ "disable_modules" will be created. Setting this option to "1" disables
30388 ++ module loading. After this option is set, no further writes to it are
30389 ++ allowed until the system is rebooted.
30390 ++
30391 ++config GRKERNSEC_HIDESYM
30392 ++ bool "Hide kernel symbols"
30393 ++ help
30394 ++ If you say Y here, getting information on loaded modules, and
30395 ++ displaying all kernel symbols through a syscall will be restricted
30396 ++ to users with CAP_SYS_MODULE. This option is only effective
30397 ++ provided the following conditions are met:
30398 ++ 1) The kernel using grsecurity is not precompiled by some distribution
30399 ++ 2) You are using the RBAC system and hiding other files such as your
30400 ++ kernel image and System.map
30401 ++ 3) You have the additional /proc restrictions enabled, which removes
30402 ++ /proc/kcore
30403 ++ If the above conditions are met, this option will aid to provide a
30404 ++ useful protection against local and remote kernel exploitation of
30405 ++ overflows and arbitrary read/write vulnerabilities.
30406 ++
30407 ++endmenu
30408 ++menu "Role Based Access Control Options"
30409 ++depends on GRKERNSEC
30410 ++
30411 ++config GRKERNSEC_ACL_HIDEKERN
30412 ++ bool "Hide kernel processes"
30413 ++ help
30414 ++ If you say Y here, all kernel threads will be hidden to all
30415 ++ processes but those whose subject has the "view hidden processes"
30416 ++ flag.
30417 ++
30418 ++config GRKERNSEC_ACL_MAXTRIES
30419 ++ int "Maximum tries before password lockout"
30420 ++ default 3
30421 ++ help
30422 ++ This option enforces the maximum number of times a user can attempt
30423 ++ to authorize themselves with the grsecurity RBAC system before being
30424 ++ denied the ability to attempt authorization again for a specified time.
30425 ++ The lower the number, the harder it will be to brute-force a password.
30426 ++
30427 ++config GRKERNSEC_ACL_TIMEOUT
30428 ++ int "Time to wait after max password tries, in seconds"
30429 ++ default 30
30430 ++ help
30431 ++ This option specifies the time the user must wait after attempting to
30432 ++ authorize to the RBAC system with the maximum number of invalid
30433 ++ passwords. The higher the number, the harder it will be to brute-force
30434 ++ a password.
30435 ++
30436 ++endmenu
30437 ++menu "Filesystem Protections"
30438 ++depends on GRKERNSEC
30439 ++
30440 ++config GRKERNSEC_PROC
30441 ++ bool "Proc restrictions"
30442 ++ help
30443 ++ If you say Y here, the permissions of the /proc filesystem
30444 ++ will be altered to enhance system security and privacy. You MUST
30445 ++ choose either a user only restriction or a user and group restriction.
30446 ++ Depending upon the option you choose, you can either restrict users to
30447 ++ see only the processes they themselves run, or choose a group that can
30448 ++ view all processes and files normally restricted to root if you choose
30449 ++ the "restrict to user only" option. NOTE: If you're running identd as
30450 ++ a non-root user, you will have to run it as the group you specify here.
30451 ++
30452 ++config GRKERNSEC_PROC_USER
30453 ++ bool "Restrict /proc to user only"
30454 ++ depends on GRKERNSEC_PROC
30455 ++ help
30456 ++ If you say Y here, non-root users will only be able to view their own
30457 ++ processes, and restricts them from viewing network-related information,
30458 ++ and viewing kernel symbol and module information.
30459 ++
30460 ++config GRKERNSEC_PROC_USERGROUP
30461 ++ bool "Allow special group"
30462 ++ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
30463 ++ help
30464 ++ If you say Y here, you will be able to select a group that will be
30465 ++ able to view all processes, network-related information, and
30466 ++ kernel and symbol information. This option is useful if you want
30467 ++ to run identd as a non-root user.
30468 ++
30469 ++config GRKERNSEC_PROC_GID
30470 ++ int "GID for special group"
30471 ++ depends on GRKERNSEC_PROC_USERGROUP
30472 ++ default 1001
30473 ++
30474 ++config GRKERNSEC_PROC_ADD
30475 ++ bool "Additional restrictions"
30476 ++ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
30477 ++ help
30478 ++ If you say Y here, additional restrictions will be placed on
30479 ++ /proc that keep normal users from viewing device information and
30480 ++ slabinfo information that could be useful for exploits.
30481 ++
30482 ++config GRKERNSEC_LINK
30483 ++ bool "Linking restrictions"
30484 ++ help
30485 ++ If you say Y here, /tmp race exploits will be prevented, since users
30486 ++ will no longer be able to follow symlinks owned by other users in
30487 ++ world-writable +t directories (i.e. /tmp), unless the owner of the
30488 ++ symlink is the owner of the directory. users will also not be
30489 ++ able to hardlink to files they do not own. If the sysctl option is
30490 ++ enabled, a sysctl option with name "linking_restrictions" is created.
30491 ++
30492 ++config GRKERNSEC_FIFO
30493 ++ bool "FIFO restrictions"
30494 ++ help
30495 ++ If you say Y here, users will not be able to write to FIFOs they don't
30496 ++ own in world-writable +t directories (i.e. /tmp), unless the owner of
30497 ++ the FIFO is the same owner of the directory it's held in. If the sysctl
30498 ++ option is enabled, a sysctl option with name "fifo_restrictions" is
30499 ++ created.
30500 ++
30501 ++config GRKERNSEC_CHROOT
30502 ++ bool "Chroot jail restrictions"
30503 ++ help
30504 ++ If you say Y here, you will be able to choose several options that will
30505 ++ make breaking out of a chrooted jail much more difficult. If you
30506 ++ encounter no software incompatibilities with the following options, it
30507 ++ is recommended that you enable each one.
30508 ++
30509 ++config GRKERNSEC_CHROOT_MOUNT
30510 ++ bool "Deny mounts"
30511 ++ depends on GRKERNSEC_CHROOT
30512 ++ help
30513 ++ If you say Y here, processes inside a chroot will not be able to
30514 ++ mount or remount filesystems. If the sysctl option is enabled, a
30515 ++ sysctl option with name "chroot_deny_mount" is created.
30516 ++
30517 ++config GRKERNSEC_CHROOT_DOUBLE
30518 ++ bool "Deny double-chroots"
30519 ++ depends on GRKERNSEC_CHROOT
30520 ++ help
30521 ++ If you say Y here, processes inside a chroot will not be able to chroot
30522 ++ again outside the chroot. This is a widely used method of breaking
30523 ++ out of a chroot jail and should not be allowed. If the sysctl
30524 ++ option is enabled, a sysctl option with name
30525 ++ "chroot_deny_chroot" is created.
30526 ++
30527 ++config GRKERNSEC_CHROOT_PIVOT
30528 ++ bool "Deny pivot_root in chroot"
30529 ++ depends on GRKERNSEC_CHROOT
30530 ++ help
30531 ++ If you say Y here, processes inside a chroot will not be able to use
30532 ++ a function called pivot_root() that was introduced in Linux 2.3.41. It
30533 ++ works similar to chroot in that it changes the root filesystem. This
30534 ++ function could be misused in a chrooted process to attempt to break out
30535 ++ of the chroot, and therefore should not be allowed. If the sysctl
30536 ++ option is enabled, a sysctl option with name "chroot_deny_pivot" is
30537 ++ created.
30538 ++
30539 ++config GRKERNSEC_CHROOT_CHDIR
30540 ++ bool "Enforce chdir(\"/\") on all chroots"
30541 ++ depends on GRKERNSEC_CHROOT
30542 ++ help
30543 ++ If you say Y here, the current working directory of all newly-chrooted
30544 ++ applications will be set to the the root directory of the chroot.
30545 ++ The man page on chroot(2) states:
30546 ++ Note that this call does not change the current working
30547 ++ directory, so that `.' can be outside the tree rooted at
30548 ++ `/'. In particular, the super-user can escape from a
30549 ++ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
30550 ++
30551 ++ It is recommended that you say Y here, since it's not known to break
30552 ++ any software. If the sysctl option is enabled, a sysctl option with
30553 ++ name "chroot_enforce_chdir" is created.
30554 ++
30555 ++config GRKERNSEC_CHROOT_CHMOD
30556 ++ bool "Deny (f)chmod +s"
30557 ++ depends on GRKERNSEC_CHROOT
30558 ++ help
30559 ++ If you say Y here, processes inside a chroot will not be able to chmod
30560 ++ or fchmod files to make them have suid or sgid bits. This protects
30561 ++ against another published method of breaking a chroot. If the sysctl
30562 ++ option is enabled, a sysctl option with name "chroot_deny_chmod" is
30563 ++ created.
30564 ++
30565 ++config GRKERNSEC_CHROOT_FCHDIR
30566 ++ bool "Deny fchdir out of chroot"
30567 ++ depends on GRKERNSEC_CHROOT
30568 ++ help
30569 ++ If you say Y here, a well-known method of breaking chroots by fchdir'ing
30570 ++ to a file descriptor of the chrooting process that points to a directory
30571 ++ outside the filesystem will be stopped. If the sysctl option
30572 ++ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
30573 ++
30574 ++config GRKERNSEC_CHROOT_MKNOD
30575 ++ bool "Deny mknod"
30576 ++ depends on GRKERNSEC_CHROOT
30577 ++ help
30578 ++ If you say Y here, processes inside a chroot will not be allowed to
30579 ++ mknod. The problem with using mknod inside a chroot is that it
30580 ++ would allow an attacker to create a device entry that is the same
30581 ++ as one on the physical root of your system, which could range from
30582 ++ anything from the console device to a device for your harddrive (which
30583 ++ they could then use to wipe the drive or steal data). It is recommended
30584 ++ that you say Y here, unless you run into software incompatibilities.
30585 ++ If the sysctl option is enabled, a sysctl option with name
30586 ++ "chroot_deny_mknod" is created.
30587 ++
30588 ++config GRKERNSEC_CHROOT_SHMAT
30589 ++ bool "Deny shmat() out of chroot"
30590 ++ depends on GRKERNSEC_CHROOT
30591 ++ help
30592 ++ If you say Y here, processes inside a chroot will not be able to attach
30593 ++ to shared memory segments that were created outside of the chroot jail.
30594 ++ It is recommended that you say Y here. If the sysctl option is enabled,
30595 ++ a sysctl option with name "chroot_deny_shmat" is created.
30596 ++
30597 ++config GRKERNSEC_CHROOT_UNIX
30598 ++ bool "Deny access to abstract AF_UNIX sockets out of chroot"
30599 ++ depends on GRKERNSEC_CHROOT
30600 ++ help
30601 ++ If you say Y here, processes inside a chroot will not be able to
30602 ++ connect to abstract (meaning not belonging to a filesystem) Unix
30603 ++ domain sockets that were bound outside of a chroot. It is recommended
30604 ++ that you say Y here. If the sysctl option is enabled, a sysctl option
30605 ++ with name "chroot_deny_unix" is created.
30606 ++
30607 ++config GRKERNSEC_CHROOT_FINDTASK
30608 ++ bool "Protect outside processes"
30609 ++ depends on GRKERNSEC_CHROOT
30610 ++ help
30611 ++ If you say Y here, processes inside a chroot will not be able to
30612 ++ kill, send signals with fcntl, ptrace, capget, getpgid, getsid,
30613 ++ or view any process outside of the chroot. If the sysctl
30614 ++ option is enabled, a sysctl option with name "chroot_findtask" is
30615 ++ created.
30616 ++
30617 ++config GRKERNSEC_CHROOT_NICE
30618 ++ bool "Restrict priority changes"
30619 ++ depends on GRKERNSEC_CHROOT
30620 ++ help
30621 ++ If you say Y here, processes inside a chroot will not be able to raise
30622 ++ the priority of processes in the chroot, or alter the priority of
30623 ++ processes outside the chroot. This provides more security than simply
30624 ++ removing CAP_SYS_NICE from the process' capability set. If the
30625 ++ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
30626 ++ is created.
30627 ++
30628 ++config GRKERNSEC_CHROOT_SYSCTL
30629 ++ bool "Deny sysctl writes"
30630 ++ depends on GRKERNSEC_CHROOT
30631 ++ help
30632 ++ If you say Y here, an attacker in a chroot will not be able to
30633 ++ write to sysctl entries, either by sysctl(2) or through a /proc
30634 ++ interface. It is strongly recommended that you say Y here. If the
30635 ++ sysctl option is enabled, a sysctl option with name
30636 ++ "chroot_deny_sysctl" is created.
30637 ++
30638 ++config GRKERNSEC_CHROOT_CAPS
30639 ++ bool "Capability restrictions"
30640 ++ depends on GRKERNSEC_CHROOT
30641 ++ help
30642 ++ If you say Y here, the capabilities on all root processes within a
30643 ++ chroot jail will be lowered to stop module insertion, raw i/o,
30644 ++ system and net admin tasks, rebooting the system, modifying immutable
30645 ++ files, modifying IPC owned by another, and changing the system time.
30646 ++ This is left an option because it can break some apps. Disable this
30647 ++ if your chrooted apps are having problems performing those kinds of
30648 ++ tasks. If the sysctl option is enabled, a sysctl option with
30649 ++ name "chroot_caps" is created.
30650 ++
30651 ++endmenu
30652 ++menu "Kernel Auditing"
30653 ++depends on GRKERNSEC
30654 ++
30655 ++config GRKERNSEC_AUDIT_GROUP
30656 ++ bool "Single group for auditing"
30657 ++ help
30658 ++ If you say Y here, the exec, chdir, (un)mount, and ipc logging features
30659 ++ will only operate on a group you specify. This option is recommended
30660 ++ if you only want to watch certain users instead of having a large
30661 ++ amount of logs from the entire system. If the sysctl option is enabled,
30662 ++ a sysctl option with name "audit_group" is created.
30663 ++
30664 ++config GRKERNSEC_AUDIT_GID
30665 ++ int "GID for auditing"
30666 ++ depends on GRKERNSEC_AUDIT_GROUP
30667 ++ default 1007
30668 ++
30669 ++config GRKERNSEC_EXECLOG
30670 ++ bool "Exec logging"
30671 ++ help
30672 ++ If you say Y here, all execve() calls will be logged (since the
30673 ++ other exec*() calls are frontends to execve(), all execution
30674 ++ will be logged). Useful for shell-servers that like to keep track
30675 ++ of their users. If the sysctl option is enabled, a sysctl option with
30676 ++ name "exec_logging" is created.
30677 ++ WARNING: This option when enabled will produce a LOT of logs, especially
30678 ++ on an active system.
30679 ++
30680 ++config GRKERNSEC_RESLOG
30681 ++ bool "Resource logging"
30682 ++ help
30683 ++ If you say Y here, all attempts to overstep resource limits will
30684 ++ be logged with the resource name, the requested size, and the current
30685 ++ limit. It is highly recommended that you say Y here. If the sysctl
30686 ++ option is enabled, a sysctl option with name "resource_logging" is
30687 ++ created. If the RBAC system is enabled, the sysctl value is ignored.
30688 ++
30689 ++config GRKERNSEC_CHROOT_EXECLOG
30690 ++ bool "Log execs within chroot"
30691 ++ help
30692 ++ If you say Y here, all executions inside a chroot jail will be logged
30693 ++ to syslog. This can cause a large amount of logs if certain
30694 ++ applications (eg. djb's daemontools) are installed on the system, and
30695 ++ is therefore left as an option. If the sysctl option is enabled, a
30696 ++ sysctl option with name "chroot_execlog" is created.
30697 ++
30698 ++config GRKERNSEC_AUDIT_CHDIR
30699 ++ bool "Chdir logging"
30700 ++ help
30701 ++ If you say Y here, all chdir() calls will be logged. If the sysctl
30702 ++ option is enabled, a sysctl option with name "audit_chdir" is created.
30703 ++
30704 ++config GRKERNSEC_AUDIT_MOUNT
30705 ++ bool "(Un)Mount logging"
30706 ++ help
30707 ++ If you say Y here, all mounts and unmounts will be logged. If the
30708 ++ sysctl option is enabled, a sysctl option with name "audit_mount" is
30709 ++ created.
30710 ++
30711 ++config GRKERNSEC_AUDIT_IPC
30712 ++ bool "IPC logging"
30713 ++ help
30714 ++ If you say Y here, creation and removal of message queues, semaphores,
30715 ++ and shared memory will be logged. If the sysctl option is enabled, a
30716 ++ sysctl option with name "audit_ipc" is created.
30717 ++
30718 ++config GRKERNSEC_SIGNAL
30719 ++ bool "Signal logging"
30720 ++ help
30721 ++ If you say Y here, certain important signals will be logged, such as
30722 ++ SIGSEGV, which will as a result inform you of when a error in a program
30723 ++ occurred, which in some cases could mean a possible exploit attempt.
30724 ++ If the sysctl option is enabled, a sysctl option with name
30725 ++ "signal_logging" is created.
30726 ++
30727 ++config GRKERNSEC_FORKFAIL
30728 ++ bool "Fork failure logging"
30729 ++ help
30730 ++ If you say Y here, all failed fork() attempts will be logged.
30731 ++ This could suggest a fork bomb, or someone attempting to overstep
30732 ++ their process limit. If the sysctl option is enabled, a sysctl option
30733 ++ with name "forkfail_logging" is created.
30734 ++
30735 ++config GRKERNSEC_TIME
30736 ++ bool "Time change logging"
30737 ++ help
30738 ++ If you say Y here, any changes of the system clock will be logged.
30739 ++ If the sysctl option is enabled, a sysctl option with name
30740 ++ "timechange_logging" is created.
30741 ++
30742 ++config GRKERNSEC_PROC_IPADDR
30743 ++ bool "/proc/<pid>/ipaddr support"
30744 ++ help
30745 ++ If you say Y here, a new entry will be added to each /proc/<pid>
30746 ++ directory that contains the IP address of the person using the task.
30747 ++ The IP is carried across local TCP and AF_UNIX stream sockets.
30748 ++ This information can be useful for IDS/IPSes to perform remote response
30749 ++ to a local attack. The entry is readable by only the owner of the
30750 ++ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
30751 ++ the RBAC system), and thus does not create privacy concerns.
30752 ++
30753 ++config GRKERNSEC_AUDIT_TEXTREL
30754 ++ bool 'ELF text relocations logging (READ HELP)'
30755 ++ depends on PAX_MPROTECT
30756 ++ help
30757 ++ If you say Y here, text relocations will be logged with the filename
30758 ++ of the offending library or binary. The purpose of the feature is
30759 ++ to help Linux distribution developers get rid of libraries and
30760 ++ binaries that need text relocations which hinder the future progress
30761 ++ of PaX. Only Linux distribution developers should say Y here, and
30762 ++ never on a production machine, as this option creates an information
30763 ++ leak that could aid an attacker in defeating the randomization of
30764 ++ a single memory region. If the sysctl option is enabled, a sysctl
30765 ++ option with name "audit_textrel" is created.
30766 ++
30767 ++endmenu
30768 ++
30769 ++menu "Executable Protections"
30770 ++depends on GRKERNSEC
30771 ++
30772 ++config GRKERNSEC_EXECVE
30773 ++ bool "Enforce RLIMIT_NPROC on execs"
30774 ++ help
30775 ++ If you say Y here, users with a resource limit on processes will
30776 ++ have the value checked during execve() calls. The current system
30777 ++ only checks the system limit during fork() calls. If the sysctl option
30778 ++ is enabled, a sysctl option with name "execve_limiting" is created.
30779 ++
30780 ++config GRKERNSEC_DMESG
30781 ++ bool "Dmesg(8) restriction"
30782 ++ help
30783 ++ If you say Y here, non-root users will not be able to use dmesg(8)
30784 ++ to view up to the last 4kb of messages in the kernel's log buffer.
30785 ++ If the sysctl option is enabled, a sysctl option with name "dmesg" is
30786 ++ created.
30787 ++
30788 ++config GRKERNSEC_TPE
30789 ++ bool "Trusted Path Execution (TPE)"
30790 ++ help
30791 ++ If you say Y here, you will be able to choose a gid to add to the
30792 ++ supplementary groups of users you want to mark as "untrusted."
30793 ++ These users will not be able to execute any files that are not in
30794 ++ root-owned directories writable only by root. If the sysctl option
30795 ++ is enabled, a sysctl option with name "tpe" is created.
30796 ++
30797 ++config GRKERNSEC_TPE_ALL
30798 ++ bool "Partially restrict non-root users"
30799 ++ depends on GRKERNSEC_TPE
30800 ++ help
30801 ++ If you say Y here, All non-root users other than the ones in the
30802 ++ group specified in the main TPE option will only be allowed to
30803 ++ execute files in directories they own that are not group or
30804 ++ world-writable, or in directories owned by root and writable only by
30805 ++ root. If the sysctl option is enabled, a sysctl option with name
30806 ++ "tpe_restrict_all" is created.
30807 ++
30808 ++config GRKERNSEC_TPE_INVERT
30809 ++ bool "Invert GID option"
30810 ++ depends on GRKERNSEC_TPE
30811 ++ help
30812 ++ If you say Y here, the group you specify in the TPE configuration will
30813 ++ decide what group TPE restrictions will be *disabled* for. This
30814 ++ option is useful if you want TPE restrictions to be applied to most
30815 ++ users on the system.
30816 ++
30817 ++config GRKERNSEC_TPE_GID
30818 ++ int "GID for untrusted users"
30819 ++ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
30820 ++ default 1005
30821 ++ help
30822 ++ If you have selected the "Invert GID option" above, setting this
30823 ++ GID determines what group TPE restrictions will be *disabled* for.
30824 ++ If you have not selected the "Invert GID option" above, setting this
30825 ++ GID determines what group TPE restrictions will be *enabled* for.
30826 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
30827 ++ is created.
30828 ++
30829 ++config GRKERNSEC_TPE_GID
30830 ++ int "GID for trusted users"
30831 ++ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
30832 ++ default 1005
30833 ++ help
30834 ++ If you have selected the "Invert GID option" above, setting this
30835 ++ GID determines what group TPE restrictions will be *disabled* for.
30836 ++ If you have not selected the "Invert GID option" above, setting this
30837 ++ GID determines what group TPE restrictions will be *enabled* for.
30838 ++ If the sysctl option is enabled, a sysctl option with name "tpe_gid"
30839 ++ is created.
30840 ++
30841 ++endmenu
30842 ++menu "Network Protections"
30843 ++depends on GRKERNSEC
30844 ++
30845 ++config GRKERNSEC_RANDNET
30846 ++ bool "Larger entropy pools"
30847 ++ help
30848 ++ If you say Y here, the entropy pools used for many features of Linux
30849 ++ and grsecurity will be doubled in size. Since several grsecurity
30850 ++ features use additional randomness, it is recommended that you say Y
30851 ++ here. Saying Y here has a similar effect as modifying
30852 ++ /proc/sys/kernel/random/poolsize.
30853 ++
30854 ++config GRKERNSEC_SOCKET
30855 ++ bool "Socket restrictions"
30856 ++ help
30857 ++ If you say Y here, you will be able to choose from several options.
30858 ++ If you assign a GID on your system and add it to the supplementary
30859 ++ groups of users you want to restrict socket access to, this patch
30860 ++ will perform up to three things, based on the option(s) you choose.
30861 ++
30862 ++config GRKERNSEC_SOCKET_ALL
30863 ++ bool "Deny any sockets to group"
30864 ++ depends on GRKERNSEC_SOCKET
30865 ++ help
30866 ++ If you say Y here, you will be able to choose a GID of whose users will
30867 ++ be unable to connect to other hosts from your machine or run server
30868 ++ applications from your machine. If the sysctl option is enabled, a
30869 ++ sysctl option with name "socket_all" is created.
30870 ++
30871 ++config GRKERNSEC_SOCKET_ALL_GID
30872 ++ int "GID to deny all sockets for"
30873 ++ depends on GRKERNSEC_SOCKET_ALL
30874 ++ default 1004
30875 ++ help
30876 ++ Here you can choose the GID to disable socket access for. Remember to
30877 ++ add the users you want socket access disabled for to the GID
30878 ++ specified here. If the sysctl option is enabled, a sysctl option
30879 ++ with name "socket_all_gid" is created.
30880 ++
30881 ++config GRKERNSEC_SOCKET_CLIENT
30882 ++ bool "Deny client sockets to group"
30883 ++ depends on GRKERNSEC_SOCKET
30884 ++ help
30885 ++ If you say Y here, you will be able to choose a GID of whose users will
30886 ++ be unable to connect to other hosts from your machine, but will be
30887 ++ able to run servers. If this option is enabled, all users in the group
30888 ++ you specify will have to use passive mode when initiating ftp transfers
30889 ++ from the shell on your machine. If the sysctl option is enabled, a
30890 ++ sysctl option with name "socket_client" is created.
30891 ++
30892 ++config GRKERNSEC_SOCKET_CLIENT_GID
30893 ++ int "GID to deny client sockets for"
30894 ++ depends on GRKERNSEC_SOCKET_CLIENT
30895 ++ default 1003
30896 ++ help
30897 ++ Here you can choose the GID to disable client socket access for.
30898 ++ Remember to add the users you want client socket access disabled for to
30899 ++ the GID specified here. If the sysctl option is enabled, a sysctl
30900 ++ option with name "socket_client_gid" is created.
30901 ++
30902 ++config GRKERNSEC_SOCKET_SERVER
30903 ++ bool "Deny server sockets to group"
30904 ++ depends on GRKERNSEC_SOCKET
30905 ++ help
30906 ++ If you say Y here, you will be able to choose a GID of whose users will
30907 ++ be unable to run server applications from your machine. If the sysctl
30908 ++ option is enabled, a sysctl option with name "socket_server" is created.
30909 ++
30910 ++config GRKERNSEC_SOCKET_SERVER_GID
30911 ++ int "GID to deny server sockets for"
30912 ++ depends on GRKERNSEC_SOCKET_SERVER
30913 ++ default 1002
30914 ++ help
30915 ++ Here you can choose the GID to disable server socket access for.
30916 ++ Remember to add the users you want server socket access disabled for to
30917 ++ the GID specified here. If the sysctl option is enabled, a sysctl
30918 ++ option with name "socket_server_gid" is created.
30919 ++
30920 ++endmenu
30921 ++menu "Sysctl support"
30922 ++depends on GRKERNSEC && SYSCTL
30923 ++
30924 ++config GRKERNSEC_SYSCTL
30925 ++ bool "Sysctl support"
30926 ++ help
30927 ++ If you say Y here, you will be able to change the options that
30928 ++ grsecurity runs with at bootup, without having to recompile your
30929 ++ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
30930 ++ to enable (1) or disable (0) various features. All the sysctl entries
30931 ++ are mutable until the "grsec_lock" entry is set to a non-zero value.
30932 ++ All features enabled in the kernel configuration are disabled at boot
30933 ++ if you do not say Y to the "Turn on features by default" option.
30934 ++ All options should be set at startup, and the grsec_lock entry should
30935 ++ be set to a non-zero value after all the options are set.
30936 ++ *THIS IS EXTREMELY IMPORTANT*
30937 ++
30938 ++config GRKERNSEC_SYSCTL_ON
30939 ++ bool "Turn on features by default"
30940 ++ depends on GRKERNSEC_SYSCTL
30941 ++ help
30942 ++ If you say Y here, instead of having all features enabled in the
30943 ++ kernel configuration disabled at boot time, the features will be
30944 ++ enabled at boot time. It is recommended you say Y here unless
30945 ++ there is some reason you would want all sysctl-tunable features to
30946 ++ be disabled by default. As mentioned elsewhere, it is important
30947 ++ to enable the grsec_lock entry once you have finished modifying
30948 ++ the sysctl entries.
30949 ++
30950 ++endmenu
30951 ++menu "Logging Options"
30952 ++depends on GRKERNSEC
30953 ++
30954 ++config GRKERNSEC_FLOODTIME
30955 ++ int "Seconds in between log messages (minimum)"
30956 ++ default 10
30957 ++ help
30958 ++ This option allows you to enforce the number of seconds between
30959 ++ grsecurity log messages. The default should be suitable for most
30960 ++ people, however, if you choose to change it, choose a value small enough
30961 ++ to allow informative logs to be produced, but large enough to
30962 ++ prevent flooding.
30963 ++
30964 ++config GRKERNSEC_FLOODBURST
30965 ++ int "Number of messages in a burst (maximum)"
30966 ++ default 4
30967 ++ help
30968 ++ This option allows you to choose the maximum number of messages allowed
30969 ++ within the flood time interval you chose in a separate option. The
30970 ++ default should be suitable for most people, however if you find that
30971 ++ many of your logs are being interpreted as flooding, you may want to
30972 ++ raise this value.
30973 ++
30974 ++endmenu
30975 ++
30976 ++endmenu
30977 +diff -urNp linux-2.6.28/grsecurity/Makefile linux-2.6.28/grsecurity/Makefile
30978 +--- linux-2.6.28/grsecurity/Makefile 1969-12-31 19:00:00.000000000 -0500
30979 ++++ linux-2.6.28/grsecurity/Makefile 2009-01-11 05:47:03.000000000 -0500
30980 +@@ -0,0 +1,20 @@
30981 ++# grsecurity's ACL system was originally written in 2001 by Michael Dalton
30982 ++# during 2001-2005 it has been completely redesigned by Brad Spengler
30983 ++# into an RBAC system
30984 ++#
30985 ++# All code in this directory and various hooks inserted throughout the kernel
30986 ++# are copyright Brad Spengler, and released under the GPL v2 or higher
30987 ++
30988 ++obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
30989 ++ grsec_mount.o grsec_sig.o grsec_sock.o grsec_sysctl.o \
30990 ++ grsec_time.o grsec_tpe.o grsec_ipc.o grsec_link.o grsec_textrel.o
30991 ++
30992 ++obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_ip.o gracl_segv.o \
30993 ++ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
30994 ++ gracl_learn.o grsec_log.o
30995 ++obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
30996 ++
30997 ++ifndef CONFIG_GRKERNSEC
30998 ++obj-y += grsec_disabled.o
30999 ++endif
31000 ++
31001 +diff -urNp linux-2.6.28/include/asm-frv/kmap_types.h linux-2.6.28/include/asm-frv/kmap_types.h
31002 +--- linux-2.6.28/include/asm-frv/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
31003 ++++ linux-2.6.28/include/asm-frv/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
31004 +@@ -23,6 +23,7 @@ enum km_type {
31005 + KM_IRQ1,
31006 + KM_SOFTIRQ0,
31007 + KM_SOFTIRQ1,
31008 ++ KM_CLEARPAGE,
31009 + KM_TYPE_NR
31010 + };
31011 +
31012 +diff -urNp linux-2.6.28/include/asm-generic/futex.h linux-2.6.28/include/asm-generic/futex.h
31013 +--- linux-2.6.28/include/asm-generic/futex.h 2008-12-24 18:26:37.000000000 -0500
31014 ++++ linux-2.6.28/include/asm-generic/futex.h 2009-01-11 07:20:06.000000000 -0500
31015 +@@ -6,7 +6,7 @@
31016 + #include <asm/errno.h>
31017 +
31018 + static inline int
31019 +-futex_atomic_op_inuser (int encoded_op, int __user *uaddr)
31020 ++futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
31021 + {
31022 + int op = (encoded_op >> 28) & 7;
31023 + int cmp = (encoded_op >> 24) & 15;
31024 +@@ -48,7 +48,7 @@ futex_atomic_op_inuser (int encoded_op,
31025 + }
31026 +
31027 + static inline int
31028 +-futex_atomic_cmpxchg_inatomic(int __user *uaddr, int oldval, int newval)
31029 ++futex_atomic_cmpxchg_inatomic(u32 __user *uaddr, int oldval, int newval)
31030 + {
31031 + return -ENOSYS;
31032 + }
31033 +diff -urNp linux-2.6.28/include/asm-generic/vmlinux.lds.h linux-2.6.28/include/asm-generic/vmlinux.lds.h
31034 +--- linux-2.6.28/include/asm-generic/vmlinux.lds.h 2008-12-24 18:26:37.000000000 -0500
31035 ++++ linux-2.6.28/include/asm-generic/vmlinux.lds.h 2009-01-11 07:20:06.000000000 -0500
31036 +@@ -69,6 +69,7 @@
31037 + .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
31038 + VMLINUX_SYMBOL(__start_rodata) = .; \
31039 + *(.rodata) *(.rodata.*) \
31040 ++ *(.data.read_only) \
31041 + *(__vermagic) /* Kernel version magic */ \
31042 + *(__markers_strings) /* Markers: strings */ \
31043 + *(__tracepoints_strings)/* Tracepoints: strings */ \
31044 +diff -urNp linux-2.6.28/include/asm-m32r/kmap_types.h linux-2.6.28/include/asm-m32r/kmap_types.h
31045 +--- linux-2.6.28/include/asm-m32r/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
31046 ++++ linux-2.6.28/include/asm-m32r/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
31047 +@@ -21,7 +21,8 @@ D(9) KM_IRQ0,
31048 + D(10) KM_IRQ1,
31049 + D(11) KM_SOFTIRQ0,
31050 + D(12) KM_SOFTIRQ1,
31051 +-D(13) KM_TYPE_NR
31052 ++D(13) KM_CLEARPAGE,
31053 ++D(14) KM_TYPE_NR
31054 + };
31055 +
31056 + #undef D
31057 +diff -urNp linux-2.6.28/include/asm-m68k/kmap_types.h linux-2.6.28/include/asm-m68k/kmap_types.h
31058 +--- linux-2.6.28/include/asm-m68k/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
31059 ++++ linux-2.6.28/include/asm-m68k/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
31060 +@@ -15,6 +15,7 @@ enum km_type {
31061 + KM_IRQ1,
31062 + KM_SOFTIRQ0,
31063 + KM_SOFTIRQ1,
31064 ++ KM_CLEARPAGE,
31065 + KM_TYPE_NR
31066 + };
31067 +
31068 +diff -urNp linux-2.6.28/include/asm-mn10300/kmap_types.h linux-2.6.28/include/asm-mn10300/kmap_types.h
31069 +--- linux-2.6.28/include/asm-mn10300/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
31070 ++++ linux-2.6.28/include/asm-mn10300/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
31071 +@@ -25,6 +25,7 @@ enum km_type {
31072 + KM_IRQ1,
31073 + KM_SOFTIRQ0,
31074 + KM_SOFTIRQ1,
31075 ++ KM_CLEARPAGE,
31076 + KM_TYPE_NR
31077 + };
31078 +
31079 +diff -urNp linux-2.6.28/include/asm-xtensa/kmap_types.h linux-2.6.28/include/asm-xtensa/kmap_types.h
31080 +--- linux-2.6.28/include/asm-xtensa/kmap_types.h 2008-12-24 18:26:37.000000000 -0500
31081 ++++ linux-2.6.28/include/asm-xtensa/kmap_types.h 2009-01-11 07:20:06.000000000 -0500
31082 +@@ -25,6 +25,7 @@ enum km_type {
31083 + KM_IRQ1,
31084 + KM_SOFTIRQ0,
31085 + KM_SOFTIRQ1,
31086 ++ KM_CLEARPAGE,
31087 + KM_TYPE_NR
31088 + };
31089 +
31090 +diff -urNp linux-2.6.28/include/drm/drm_pciids.h linux-2.6.28/include/drm/drm_pciids.h
31091 +--- linux-2.6.28/include/drm/drm_pciids.h 2008-12-24 18:26:37.000000000 -0500
31092 ++++ linux-2.6.28/include/drm/drm_pciids.h 2009-01-11 07:20:06.000000000 -0500
31093 +@@ -243,7 +243,7 @@
31094 + {0x1002, 0x796d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
31095 + {0x1002, 0x796e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
31096 + {0x1002, 0x796f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS740|RADEON_IS_IGP|RADEON_NEW_MEMMAP|RADEON_IS_IGPGART}, \
31097 +- {0, 0, 0}
31098 ++ {0, 0, 0, 0, 0, 0}
31099 +
31100 + #define r128_PCI_IDS \
31101 + {0x1002, 0x4c45, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31102 +@@ -283,14 +283,14 @@
31103 + {0x1002, 0x5446, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31104 + {0x1002, 0x544C, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31105 + {0x1002, 0x5452, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31106 +- {0, 0, 0}
31107 ++ {0, 0, 0, 0, 0, 0}
31108 +
31109 + #define mga_PCI_IDS \
31110 + {0x102b, 0x0520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
31111 + {0x102b, 0x0521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G200}, \
31112 + {0x102b, 0x0525, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G400}, \
31113 + {0x102b, 0x2527, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MGA_CARD_TYPE_G550}, \
31114 +- {0, 0, 0}
31115 ++ {0, 0, 0, 0, 0, 0}
31116 +
31117 + #define mach64_PCI_IDS \
31118 + {0x1002, 0x4749, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31119 +@@ -313,7 +313,7 @@
31120 + {0x1002, 0x4c53, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31121 + {0x1002, 0x4c4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31122 + {0x1002, 0x4c4e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31123 +- {0, 0, 0}
31124 ++ {0, 0, 0, 0, 0, 0}
31125 +
31126 + #define sisdrv_PCI_IDS \
31127 + {0x1039, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31128 +@@ -324,7 +324,7 @@
31129 + {0x1039, 0x7300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31130 + {0x18CA, 0x0040, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
31131 + {0x18CA, 0x0042, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SIS_CHIP_315}, \
31132 +- {0, 0, 0}
31133 ++ {0, 0, 0, 0, 0, 0}
31134 +
31135 + #define tdfx_PCI_IDS \
31136 + {0x121a, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31137 +@@ -333,7 +333,7 @@
31138 + {0x121a, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31139 + {0x121a, 0x0009, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31140 + {0x121a, 0x000b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31141 +- {0, 0, 0}
31142 ++ {0, 0, 0, 0, 0, 0}
31143 +
31144 + #define viadrv_PCI_IDS \
31145 + {0x1106, 0x3022, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31146 +@@ -345,25 +345,25 @@
31147 + {0x1106, 0x3343, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31148 + {0x1106, 0x3230, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_DX9_0}, \
31149 + {0x1106, 0x3157, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VIA_PRO_GROUP_A}, \
31150 +- {0, 0, 0}
31151 ++ {0, 0, 0, 0, 0, 0}
31152 +
31153 + #define i810_PCI_IDS \
31154 + {0x8086, 0x7121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31155 + {0x8086, 0x7123, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31156 + {0x8086, 0x7125, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31157 + {0x8086, 0x1132, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31158 +- {0, 0, 0}
31159 ++ {0, 0, 0, 0, 0, 0}
31160 +
31161 + #define i830_PCI_IDS \
31162 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31163 + {0x8086, 0x2562, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31164 + {0x8086, 0x3582, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31165 + {0x8086, 0x2572, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31166 +- {0, 0, 0}
31167 ++ {0, 0, 0, 0, 0, 0}
31168 +
31169 + #define gamma_PCI_IDS \
31170 + {0x3d3d, 0x0008, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, \
31171 +- {0, 0, 0}
31172 ++ {0, 0, 0, 0, 0, 0}
31173 +
31174 + #define savage_PCI_IDS \
31175 + {0x5333, 0x8a20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_SAVAGE3D}, \
31176 +@@ -389,10 +389,10 @@
31177 + {0x5333, 0x8d02, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_TWISTER}, \
31178 + {0x5333, 0x8d03, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
31179 + {0x5333, 0x8d04, PCI_ANY_ID, PCI_ANY_ID, 0, 0, S3_PROSAVAGEDDR}, \
31180 +- {0, 0, 0}
31181 ++ {0, 0, 0, 0, 0, 0}
31182 +
31183 + #define ffb_PCI_IDS \
31184 +- {0, 0, 0}
31185 ++ {0, 0, 0, 0, 0, 0}
31186 +
31187 + #define i915_PCI_IDS \
31188 + {0x8086, 0x3577, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
31189 +@@ -418,4 +418,4 @@
31190 + {0x8086, 0x2e02, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
31191 + {0x8086, 0x2e12, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
31192 + {0x8086, 0x2e22, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \
31193 +- {0, 0, 0}
31194 ++ {0, 0, 0, 0, 0, 0}
31195 +diff -urNp linux-2.6.28/include/linux/a.out.h linux-2.6.28/include/linux/a.out.h
31196 +--- linux-2.6.28/include/linux/a.out.h 2008-12-24 18:26:37.000000000 -0500
31197 ++++ linux-2.6.28/include/linux/a.out.h 2009-01-11 07:20:06.000000000 -0500
31198 +@@ -39,6 +39,14 @@ enum machine_type {
31199 + M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
31200 + };
31201 +
31202 ++/* Constants for the N_FLAGS field */
31203 ++#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
31204 ++#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
31205 ++#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
31206 ++#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
31207 ++/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
31208 ++#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
31209 ++
31210 + #if !defined (N_MAGIC)
31211 + #define N_MAGIC(exec) ((exec).a_info & 0xffff)
31212 + #endif
31213 +diff -urNp linux-2.6.28/include/linux/binfmts.h linux-2.6.28/include/linux/binfmts.h
31214 +--- linux-2.6.28/include/linux/binfmts.h 2008-12-24 18:26:37.000000000 -0500
31215 ++++ linux-2.6.28/include/linux/binfmts.h 2009-01-11 07:20:06.000000000 -0500
31216 +@@ -74,6 +74,7 @@ struct linux_binfmt {
31217 + int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
31218 + int (*load_shlib)(struct file *);
31219 + int (*core_dump)(long signr, struct pt_regs *regs, struct file *file, unsigned long limit);
31220 ++ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
31221 + unsigned long min_coredump; /* minimal dump size */
31222 + int hasvdso;
31223 + };
31224 +diff -urNp linux-2.6.28/include/linux/cache.h linux-2.6.28/include/linux/cache.h
31225 +--- linux-2.6.28/include/linux/cache.h 2008-12-24 18:26:37.000000000 -0500
31226 ++++ linux-2.6.28/include/linux/cache.h 2009-01-11 07:20:06.000000000 -0500
31227 +@@ -16,6 +16,10 @@
31228 + #define __read_mostly
31229 + #endif
31230 +
31231 ++#ifndef __read_only
31232 ++#define __read_only __read_mostly
31233 ++#endif
31234 ++
31235 + #ifndef ____cacheline_aligned
31236 + #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
31237 + #endif
31238 +diff -urNp linux-2.6.28/include/linux/capability.h linux-2.6.28/include/linux/capability.h
31239 +--- linux-2.6.28/include/linux/capability.h 2008-12-24 18:26:37.000000000 -0500
31240 ++++ linux-2.6.28/include/linux/capability.h 2009-01-11 05:47:05.000000000 -0500
31241 +@@ -516,6 +516,7 @@ kernel_cap_t cap_set_effective(const ker
31242 + #define has_capability(t, cap) (security_capable((t), (cap)) == 0)
31243 +
31244 + extern int capable(int cap);
31245 ++int capable_nolog(int cap);
31246 +
31247 + #endif /* __KERNEL__ */
31248 +
31249 +diff -urNp linux-2.6.28/include/linux/cpumask.h linux-2.6.28/include/linux/cpumask.h
31250 +--- linux-2.6.28/include/linux/cpumask.h 2008-12-24 18:26:37.000000000 -0500
31251 ++++ linux-2.6.28/include/linux/cpumask.h 2009-01-11 07:20:06.000000000 -0500
31252 +@@ -142,7 +142,6 @@
31253 + #include <linux/bitmap.h>
31254 +
31255 + typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } cpumask_t;
31256 +-extern cpumask_t _unused_cpumask_arg_;
31257 +
31258 + #define cpu_set(cpu, dst) __cpu_set((cpu), &(dst))
31259 + static inline void __cpu_set(int cpu, volatile cpumask_t *dstp)
31260 +diff -urNp linux-2.6.28/include/linux/elf.h linux-2.6.28/include/linux/elf.h
31261 +--- linux-2.6.28/include/linux/elf.h 2008-12-24 18:26:37.000000000 -0500
31262 ++++ linux-2.6.28/include/linux/elf.h 2009-01-11 07:20:06.000000000 -0500
31263 +@@ -49,6 +49,17 @@ typedef __s64 Elf64_Sxword;
31264 + #define PT_GNU_EH_FRAME 0x6474e550
31265 +
31266 + #define PT_GNU_STACK (PT_LOOS + 0x474e551)
31267 ++#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
31268 ++
31269 ++#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
31270 ++
31271 ++/* Constants for the e_flags field */
31272 ++#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
31273 ++#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
31274 ++#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
31275 ++#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
31276 ++/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
31277 ++#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
31278 +
31279 + /* These constants define the different elf file types */
31280 + #define ET_NONE 0
31281 +@@ -84,6 +95,8 @@ typedef __s64 Elf64_Sxword;
31282 + #define DT_DEBUG 21
31283 + #define DT_TEXTREL 22
31284 + #define DT_JMPREL 23
31285 ++#define DT_FLAGS 30
31286 ++ #define DF_TEXTREL 0x00000004
31287 + #define DT_ENCODING 32
31288 + #define OLD_DT_LOOS 0x60000000
31289 + #define DT_LOOS 0x6000000d
31290 +@@ -230,6 +243,19 @@ typedef struct elf64_hdr {
31291 + #define PF_W 0x2
31292 + #define PF_X 0x1
31293 +
31294 ++#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
31295 ++#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
31296 ++#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
31297 ++#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
31298 ++#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
31299 ++#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
31300 ++/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
31301 ++/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
31302 ++#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
31303 ++#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
31304 ++#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
31305 ++#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
31306 ++
31307 + typedef struct elf32_phdr{
31308 + Elf32_Word p_type;
31309 + Elf32_Off p_offset;
31310 +@@ -322,6 +348,8 @@ typedef struct elf64_shdr {
31311 + #define EI_OSABI 7
31312 + #define EI_PAD 8
31313 +
31314 ++#define EI_PAX 14
31315 ++
31316 + #define ELFMAG0 0x7f /* EI_MAG */
31317 + #define ELFMAG1 'E'
31318 + #define ELFMAG2 'L'
31319 +@@ -384,6 +412,7 @@ extern Elf32_Dyn _DYNAMIC [];
31320 + #define elf_phdr elf32_phdr
31321 + #define elf_note elf32_note
31322 + #define elf_addr_t Elf32_Off
31323 ++#define elf_dyn Elf32_Dyn
31324 +
31325 + #else
31326 +
31327 +@@ -392,6 +421,7 @@ extern Elf64_Dyn _DYNAMIC [];
31328 + #define elf_phdr elf64_phdr
31329 + #define elf_note elf64_note
31330 + #define elf_addr_t Elf64_Off
31331 ++#define elf_dyn Elf64_Dyn
31332 +
31333 + #endif
31334 +
31335 +diff -urNp linux-2.6.28/include/linux/gracl.h linux-2.6.28/include/linux/gracl.h
31336 +--- linux-2.6.28/include/linux/gracl.h 1969-12-31 19:00:00.000000000 -0500
31337 ++++ linux-2.6.28/include/linux/gracl.h 2009-01-11 05:47:05.000000000 -0500
31338 +@@ -0,0 +1,318 @@
31339 ++#ifndef GR_ACL_H
31340 ++#define GR_ACL_H
31341 ++
31342 ++#include <linux/grdefs.h>
31343 ++#include <linux/resource.h>
31344 ++#include <linux/capability.h>
31345 ++#include <linux/dcache.h>
31346 ++#include <asm/resource.h>
31347 ++
31348 ++/* Major status information */
31349 ++
31350 ++#define GR_VERSION "grsecurity 2.1.12"
31351 ++#define GRSECURITY_VERSION 0x2112
31352 ++
31353 ++enum {
31354 ++
31355 ++ SHUTDOWN = 0,
31356 ++ ENABLE = 1,
31357 ++ SPROLE = 2,
31358 ++ RELOAD = 3,
31359 ++ SEGVMOD = 4,
31360 ++ STATUS = 5,
31361 ++ UNSPROLE = 6,
31362 ++ PASSSET = 7,
31363 ++ SPROLEPAM = 8
31364 ++};
31365 ++
31366 ++/* Password setup definitions
31367 ++ * kernel/grhash.c */
31368 ++enum {
31369 ++ GR_PW_LEN = 128,
31370 ++ GR_SALT_LEN = 16,
31371 ++ GR_SHA_LEN = 32,
31372 ++};
31373 ++
31374 ++enum {
31375 ++ GR_SPROLE_LEN = 64,
31376 ++};
31377 ++
31378 ++#define GR_NLIMITS (RLIMIT_LOCKS + 2)
31379 ++
31380 ++/* Begin Data Structures */
31381 ++
31382 ++struct sprole_pw {
31383 ++ unsigned char *rolename;
31384 ++ unsigned char salt[GR_SALT_LEN];
31385 ++ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
31386 ++};
31387 ++
31388 ++struct name_entry {
31389 ++ __u32 key;
31390 ++ ino_t inode;
31391 ++ dev_t device;
31392 ++ char *name;
31393 ++ __u16 len;
31394 ++ __u8 deleted;
31395 ++ struct name_entry *prev;
31396 ++ struct name_entry *next;
31397 ++};
31398 ++
31399 ++struct inodev_entry {
31400 ++ struct name_entry *nentry;
31401 ++ struct inodev_entry *prev;
31402 ++ struct inodev_entry *next;
31403 ++};
31404 ++
31405 ++struct acl_role_db {
31406 ++ struct acl_role_label **r_hash;
31407 ++ __u32 r_size;
31408 ++};
31409 ++
31410 ++struct inodev_db {
31411 ++ struct inodev_entry **i_hash;
31412 ++ __u32 i_size;
31413 ++};
31414 ++
31415 ++struct name_db {
31416 ++ struct name_entry **n_hash;
31417 ++ __u32 n_size;
31418 ++};
31419 ++
31420 ++struct crash_uid {
31421 ++ uid_t uid;
31422 ++ unsigned long expires;
31423 ++};
31424 ++
31425 ++struct gr_hash_struct {
31426 ++ void **table;
31427 ++ void **nametable;
31428 ++ void *first;
31429 ++ __u32 table_size;
31430 ++ __u32 used_size;
31431 ++ int type;
31432 ++};
31433 ++
31434 ++/* Userspace Grsecurity ACL data structures */
31435 ++
31436 ++struct acl_subject_label {
31437 ++ char *filename;
31438 ++ ino_t inode;
31439 ++ dev_t device;
31440 ++ __u32 mode;
31441 ++ kernel_cap_t cap_mask;
31442 ++ kernel_cap_t cap_lower;
31443 ++
31444 ++ struct rlimit res[GR_NLIMITS];
31445 ++ __u16 resmask;
31446 ++
31447 ++ __u8 user_trans_type;
31448 ++ __u8 group_trans_type;
31449 ++ uid_t *user_transitions;
31450 ++ gid_t *group_transitions;
31451 ++ __u16 user_trans_num;
31452 ++ __u16 group_trans_num;
31453 ++
31454 ++ __u32 ip_proto[8];
31455 ++ __u32 ip_type;
31456 ++ struct acl_ip_label **ips;
31457 ++ __u32 ip_num;
31458 ++
31459 ++ __u32 crashes;
31460 ++ unsigned long expires;
31461 ++
31462 ++ struct acl_subject_label *parent_subject;
31463 ++ struct gr_hash_struct *hash;
31464 ++ struct acl_subject_label *prev;
31465 ++ struct acl_subject_label *next;
31466 ++
31467 ++ struct acl_object_label **obj_hash;
31468 ++ __u32 obj_hash_size;
31469 ++ __u16 pax_flags;
31470 ++};
31471 ++
31472 ++struct role_allowed_ip {
31473 ++ __u32 addr;
31474 ++ __u32 netmask;
31475 ++
31476 ++ struct role_allowed_ip *prev;
31477 ++ struct role_allowed_ip *next;
31478 ++};
31479 ++
31480 ++struct role_transition {
31481 ++ char *rolename;
31482 ++
31483 ++ struct role_transition *prev;
31484 ++ struct role_transition *next;
31485 ++};
31486 ++
31487 ++struct acl_role_label {
31488 ++ char *rolename;
31489 ++ uid_t uidgid;
31490 ++ __u16 roletype;
31491 ++
31492 ++ __u16 auth_attempts;
31493 ++ unsigned long expires;
31494 ++
31495 ++ struct acl_subject_label *root_label;
31496 ++ struct gr_hash_struct *hash;
31497 ++
31498 ++ struct acl_role_label *prev;
31499 ++ struct acl_role_label *next;
31500 ++
31501 ++ struct role_transition *transitions;
31502 ++ struct role_allowed_ip *allowed_ips;
31503 ++ uid_t *domain_children;
31504 ++ __u16 domain_child_num;
31505 ++
31506 ++ struct acl_subject_label **subj_hash;
31507 ++ __u32 subj_hash_size;
31508 ++};
31509 ++
31510 ++struct user_acl_role_db {
31511 ++ struct acl_role_label **r_table;
31512 ++ __u32 num_pointers; /* Number of allocations to track */
31513 ++ __u32 num_roles; /* Number of roles */
31514 ++ __u32 num_domain_children; /* Number of domain children */
31515 ++ __u32 num_subjects; /* Number of subjects */
31516 ++ __u32 num_objects; /* Number of objects */
31517 ++};
31518 ++
31519 ++struct acl_object_label {
31520 ++ char *filename;
31521 ++ ino_t inode;
31522 ++ dev_t device;
31523 ++ __u32 mode;
31524 ++
31525 ++ struct acl_subject_label *nested;
31526 ++ struct acl_object_label *globbed;
31527 ++
31528 ++ /* next two structures not used */
31529 ++
31530 ++ struct acl_object_label *prev;
31531 ++ struct acl_object_label *next;
31532 ++};
31533 ++
31534 ++struct acl_ip_label {
31535 ++ char *iface;
31536 ++ __u32 addr;
31537 ++ __u32 netmask;
31538 ++ __u16 low, high;
31539 ++ __u8 mode;
31540 ++ __u32 type;
31541 ++ __u32 proto[8];
31542 ++
31543 ++ /* next two structures not used */
31544 ++
31545 ++ struct acl_ip_label *prev;
31546 ++ struct acl_ip_label *next;
31547 ++};
31548 ++
31549 ++struct gr_arg {
31550 ++ struct user_acl_role_db role_db;
31551 ++ unsigned char pw[GR_PW_LEN];
31552 ++ unsigned char salt[GR_SALT_LEN];
31553 ++ unsigned char sum[GR_SHA_LEN];
31554 ++ unsigned char sp_role[GR_SPROLE_LEN];
31555 ++ struct sprole_pw *sprole_pws;
31556 ++ dev_t segv_device;
31557 ++ ino_t segv_inode;
31558 ++ uid_t segv_uid;
31559 ++ __u16 num_sprole_pws;
31560 ++ __u16 mode;
31561 ++};
31562 ++
31563 ++struct gr_arg_wrapper {
31564 ++ struct gr_arg *arg;
31565 ++ __u32 version;
31566 ++ __u32 size;
31567 ++};
31568 ++
31569 ++struct subject_map {
31570 ++ struct acl_subject_label *user;
31571 ++ struct acl_subject_label *kernel;
31572 ++ struct subject_map *prev;
31573 ++ struct subject_map *next;
31574 ++};
31575 ++
31576 ++struct acl_subj_map_db {
31577 ++ struct subject_map **s_hash;
31578 ++ __u32 s_size;
31579 ++};
31580 ++
31581 ++/* End Data Structures Section */
31582 ++
31583 ++/* Hash functions generated by empirical testing by Brad Spengler
31584 ++ Makes good use of the low bits of the inode. Generally 0-1 times
31585 ++ in loop for successful match. 0-3 for unsuccessful match.
31586 ++ Shift/add algorithm with modulus of table size and an XOR*/
31587 ++
31588 ++static __inline__ unsigned int
31589 ++rhash(const uid_t uid, const __u16 type, const unsigned int sz)
31590 ++{
31591 ++ return (((uid << type) + (uid ^ type)) % sz);
31592 ++}
31593 ++
31594 ++ static __inline__ unsigned int
31595 ++shash(const struct acl_subject_label *userp, const unsigned int sz)
31596 ++{
31597 ++ return ((const unsigned long)userp % sz);
31598 ++}
31599 ++
31600 ++static __inline__ unsigned int
31601 ++fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
31602 ++{
31603 ++ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
31604 ++}
31605 ++
31606 ++static __inline__ unsigned int
31607 ++nhash(const char *name, const __u16 len, const unsigned int sz)
31608 ++{
31609 ++ return full_name_hash(name, len) % sz;
31610 ++}
31611 ++
31612 ++#define FOR_EACH_ROLE_START(role,iter) \
31613 ++ role = NULL; \
31614 ++ iter = 0; \
31615 ++ while (iter < acl_role_set.r_size) { \
31616 ++ if (role == NULL) \
31617 ++ role = acl_role_set.r_hash[iter]; \
31618 ++ if (role == NULL) { \
31619 ++ iter++; \
31620 ++ continue; \
31621 ++ }
31622 ++
31623 ++#define FOR_EACH_ROLE_END(role,iter) \
31624 ++ role = role->next; \
31625 ++ if (role == NULL) \
31626 ++ iter++; \
31627 ++ }
31628 ++
31629 ++#define FOR_EACH_SUBJECT_START(role,subj,iter) \
31630 ++ subj = NULL; \
31631 ++ iter = 0; \
31632 ++ while (iter < role->subj_hash_size) { \
31633 ++ if (subj == NULL) \
31634 ++ subj = role->subj_hash[iter]; \
31635 ++ if (subj == NULL) { \
31636 ++ iter++; \
31637 ++ continue; \
31638 ++ }
31639 ++
31640 ++#define FOR_EACH_SUBJECT_END(subj,iter) \
31641 ++ subj = subj->next; \
31642 ++ if (subj == NULL) \
31643 ++ iter++; \
31644 ++ }
31645 ++
31646 ++
31647 ++#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
31648 ++ subj = role->hash->first; \
31649 ++ while (subj != NULL) {
31650 ++
31651 ++#define FOR_EACH_NESTED_SUBJECT_END(subj) \
31652 ++ subj = subj->next; \
31653 ++ }
31654 ++
31655 ++#endif
31656 ++
31657 +diff -urNp linux-2.6.28/include/linux/gralloc.h linux-2.6.28/include/linux/gralloc.h
31658 +--- linux-2.6.28/include/linux/gralloc.h 1969-12-31 19:00:00.000000000 -0500
31659 ++++ linux-2.6.28/include/linux/gralloc.h 2009-01-11 05:47:05.000000000 -0500
31660 +@@ -0,0 +1,8 @@
31661 ++#ifndef __GRALLOC_H
31662 ++#define __GRALLOC_H
31663 ++
31664 ++void acl_free_all(void);
31665 ++int acl_alloc_stack_init(unsigned long size);
31666 ++void *acl_alloc(unsigned long len);
31667 ++
31668 ++#endif
31669 +diff -urNp linux-2.6.28/include/linux/grdefs.h linux-2.6.28/include/linux/grdefs.h
31670 +--- linux-2.6.28/include/linux/grdefs.h 1969-12-31 19:00:00.000000000 -0500
31671 ++++ linux-2.6.28/include/linux/grdefs.h 2009-01-11 05:47:05.000000000 -0500
31672 +@@ -0,0 +1,131 @@
31673 ++#ifndef GRDEFS_H
31674 ++#define GRDEFS_H
31675 ++
31676 ++/* Begin grsecurity status declarations */
31677 ++
31678 ++enum {
31679 ++ GR_READY = 0x01,
31680 ++ GR_STATUS_INIT = 0x00 // disabled state
31681 ++};
31682 ++
31683 ++/* Begin ACL declarations */
31684 ++
31685 ++/* Role flags */
31686 ++
31687 ++enum {
31688 ++ GR_ROLE_USER = 0x0001,
31689 ++ GR_ROLE_GROUP = 0x0002,
31690 ++ GR_ROLE_DEFAULT = 0x0004,
31691 ++ GR_ROLE_SPECIAL = 0x0008,
31692 ++ GR_ROLE_AUTH = 0x0010,
31693 ++ GR_ROLE_NOPW = 0x0020,
31694 ++ GR_ROLE_GOD = 0x0040,
31695 ++ GR_ROLE_LEARN = 0x0080,
31696 ++ GR_ROLE_TPE = 0x0100,
31697 ++ GR_ROLE_DOMAIN = 0x0200,
31698 ++ GR_ROLE_PAM = 0x0400
31699 ++};
31700 ++
31701 ++/* ACL Subject and Object mode flags */
31702 ++enum {
31703 ++ GR_DELETED = 0x80000000
31704 ++};
31705 ++
31706 ++/* ACL Object-only mode flags */
31707 ++enum {
31708 ++ GR_READ = 0x00000001,
31709 ++ GR_APPEND = 0x00000002,
31710 ++ GR_WRITE = 0x00000004,
31711 ++ GR_EXEC = 0x00000008,
31712 ++ GR_FIND = 0x00000010,
31713 ++ GR_INHERIT = 0x00000020,
31714 ++ GR_SETID = 0x00000040,
31715 ++ GR_CREATE = 0x00000080,
31716 ++ GR_DELETE = 0x00000100,
31717 ++ GR_LINK = 0x00000200,
31718 ++ GR_AUDIT_READ = 0x00000400,
31719 ++ GR_AUDIT_APPEND = 0x00000800,
31720 ++ GR_AUDIT_WRITE = 0x00001000,
31721 ++ GR_AUDIT_EXEC = 0x00002000,
31722 ++ GR_AUDIT_FIND = 0x00004000,
31723 ++ GR_AUDIT_INHERIT= 0x00008000,
31724 ++ GR_AUDIT_SETID = 0x00010000,
31725 ++ GR_AUDIT_CREATE = 0x00020000,
31726 ++ GR_AUDIT_DELETE = 0x00040000,
31727 ++ GR_AUDIT_LINK = 0x00080000,
31728 ++ GR_PTRACERD = 0x00100000,
31729 ++ GR_NOPTRACE = 0x00200000,
31730 ++ GR_SUPPRESS = 0x00400000,
31731 ++ GR_NOLEARN = 0x00800000
31732 ++};
31733 ++
31734 ++#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
31735 ++ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
31736 ++ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
31737 ++
31738 ++/* ACL subject-only mode flags */
31739 ++enum {
31740 ++ GR_KILL = 0x00000001,
31741 ++ GR_VIEW = 0x00000002,
31742 ++ GR_PROTECTED = 0x00000004,
31743 ++ GR_LEARN = 0x00000008,
31744 ++ GR_OVERRIDE = 0x00000010,
31745 ++ /* just a placeholder, this mode is only used in userspace */
31746 ++ GR_DUMMY = 0x00000020,
31747 ++ GR_PROTSHM = 0x00000040,
31748 ++ GR_KILLPROC = 0x00000080,
31749 ++ GR_KILLIPPROC = 0x00000100,
31750 ++ /* just a placeholder, this mode is only used in userspace */
31751 ++ GR_NOTROJAN = 0x00000200,
31752 ++ GR_PROTPROCFD = 0x00000400,
31753 ++ GR_PROCACCT = 0x00000800,
31754 ++ GR_RELAXPTRACE = 0x00001000,
31755 ++ GR_NESTED = 0x00002000,
31756 ++ GR_INHERITLEARN = 0x00004000,
31757 ++ GR_PROCFIND = 0x00008000,
31758 ++ GR_POVERRIDE = 0x00010000,
31759 ++ GR_KERNELAUTH = 0x00020000,
31760 ++};
31761 ++
31762 ++enum {
31763 ++ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
31764 ++ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
31765 ++ GR_PAX_ENABLE_MPROTECT = 0x0004,
31766 ++ GR_PAX_ENABLE_RANDMMAP = 0x0008,
31767 ++ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
31768 ++ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
31769 ++ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
31770 ++ GR_PAX_DISABLE_MPROTECT = 0x0400,
31771 ++ GR_PAX_DISABLE_RANDMMAP = 0x0800,
31772 ++ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
31773 ++};
31774 ++
31775 ++enum {
31776 ++ GR_ID_USER = 0x01,
31777 ++ GR_ID_GROUP = 0x02,
31778 ++};
31779 ++
31780 ++enum {
31781 ++ GR_ID_ALLOW = 0x01,
31782 ++ GR_ID_DENY = 0x02,
31783 ++};
31784 ++
31785 ++#define GR_CRASH_RES 11
31786 ++#define GR_UIDTABLE_MAX 500
31787 ++
31788 ++/* begin resource learning section */
31789 ++enum {
31790 ++ GR_RLIM_CPU_BUMP = 60,
31791 ++ GR_RLIM_FSIZE_BUMP = 50000,
31792 ++ GR_RLIM_DATA_BUMP = 10000,
31793 ++ GR_RLIM_STACK_BUMP = 1000,
31794 ++ GR_RLIM_CORE_BUMP = 10000,
31795 ++ GR_RLIM_RSS_BUMP = 500000,
31796 ++ GR_RLIM_NPROC_BUMP = 1,
31797 ++ GR_RLIM_NOFILE_BUMP = 5,
31798 ++ GR_RLIM_MEMLOCK_BUMP = 50000,
31799 ++ GR_RLIM_AS_BUMP = 500000,
31800 ++ GR_RLIM_LOCKS_BUMP = 2
31801 ++};
31802 ++
31803 ++#endif
31804 +diff -urNp linux-2.6.28/include/linux/grinternal.h linux-2.6.28/include/linux/grinternal.h
31805 +--- linux-2.6.28/include/linux/grinternal.h 1969-12-31 19:00:00.000000000 -0500
31806 ++++ linux-2.6.28/include/linux/grinternal.h 2009-01-11 05:47:05.000000000 -0500
31807 +@@ -0,0 +1,210 @@
31808 ++#ifndef __GRINTERNAL_H
31809 ++#define __GRINTERNAL_H
31810 ++
31811 ++#ifdef CONFIG_GRKERNSEC
31812 ++
31813 ++#include <linux/fs.h>
31814 ++#include <linux/gracl.h>
31815 ++#include <linux/grdefs.h>
31816 ++#include <linux/grmsg.h>
31817 ++
31818 ++void gr_add_learn_entry(const char *fmt, ...);
31819 ++__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
31820 ++ const struct vfsmount *mnt);
31821 ++__u32 gr_check_create(const struct dentry *new_dentry,
31822 ++ const struct dentry *parent,
31823 ++ const struct vfsmount *mnt, const __u32 mode);
31824 ++int gr_check_protected_task(const struct task_struct *task);
31825 ++__u32 to_gr_audit(const __u32 reqmode);
31826 ++int gr_set_acls(const int type);
31827 ++
31828 ++int gr_acl_is_enabled(void);
31829 ++char gr_roletype_to_char(void);
31830 ++
31831 ++void gr_handle_alertkill(struct task_struct *task);
31832 ++char *gr_to_filename(const struct dentry *dentry,
31833 ++ const struct vfsmount *mnt);
31834 ++char *gr_to_filename1(const struct dentry *dentry,
31835 ++ const struct vfsmount *mnt);
31836 ++char *gr_to_filename2(const struct dentry *dentry,
31837 ++ const struct vfsmount *mnt);
31838 ++char *gr_to_filename3(const struct dentry *dentry,
31839 ++ const struct vfsmount *mnt);
31840 ++
31841 ++extern int grsec_enable_link;
31842 ++extern int grsec_enable_fifo;
31843 ++extern int grsec_enable_execve;
31844 ++extern int grsec_enable_shm;
31845 ++extern int grsec_enable_execlog;
31846 ++extern int grsec_enable_signal;
31847 ++extern int grsec_enable_forkfail;
31848 ++extern int grsec_enable_time;
31849 ++extern int grsec_enable_chroot_shmat;
31850 ++extern int grsec_enable_chroot_findtask;
31851 ++extern int grsec_enable_chroot_mount;
31852 ++extern int grsec_enable_chroot_double;
31853 ++extern int grsec_enable_chroot_pivot;
31854 ++extern int grsec_enable_chroot_chdir;
31855 ++extern int grsec_enable_chroot_chmod;
31856 ++extern int grsec_enable_chroot_mknod;
31857 ++extern int grsec_enable_chroot_fchdir;
31858 ++extern int grsec_enable_chroot_nice;
31859 ++extern int grsec_enable_chroot_execlog;
31860 ++extern int grsec_enable_chroot_caps;
31861 ++extern int grsec_enable_chroot_sysctl;
31862 ++extern int grsec_enable_chroot_unix;
31863 ++extern int grsec_enable_tpe;
31864 ++extern int grsec_tpe_gid;
31865 ++extern int grsec_enable_tpe_all;
31866 ++extern int grsec_enable_sidcaps;
31867 ++extern int grsec_enable_socket_all;
31868 ++extern int grsec_socket_all_gid;
31869 ++extern int grsec_enable_socket_client;
31870 ++extern int grsec_socket_client_gid;
31871 ++extern int grsec_enable_socket_server;
31872 ++extern int grsec_socket_server_gid;
31873 ++extern int grsec_audit_gid;
31874 ++extern int grsec_enable_group;
31875 ++extern int grsec_enable_audit_ipc;
31876 ++extern int grsec_enable_audit_textrel;
31877 ++extern int grsec_enable_mount;
31878 ++extern int grsec_enable_chdir;
31879 ++extern int grsec_resource_logging;
31880 ++extern int grsec_lock;
31881 ++
31882 ++extern spinlock_t grsec_alert_lock;
31883 ++extern unsigned long grsec_alert_wtime;
31884 ++extern unsigned long grsec_alert_fyet;
31885 ++
31886 ++extern spinlock_t grsec_audit_lock;
31887 ++
31888 ++extern rwlock_t grsec_exec_file_lock;
31889 ++
31890 ++#define gr_task_fullpath(tsk) (tsk->exec_file ? \
31891 ++ gr_to_filename2(tsk->exec_file->f_path.dentry, \
31892 ++ tsk->exec_file->f_vfsmnt) : "/")
31893 ++
31894 ++#define gr_parent_task_fullpath(tsk) (tsk->parent->exec_file ? \
31895 ++ gr_to_filename3(tsk->parent->exec_file->f_path.dentry, \
31896 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
31897 ++
31898 ++#define gr_task_fullpath0(tsk) (tsk->exec_file ? \
31899 ++ gr_to_filename(tsk->exec_file->f_path.dentry, \
31900 ++ tsk->exec_file->f_vfsmnt) : "/")
31901 ++
31902 ++#define gr_parent_task_fullpath0(tsk) (tsk->parent->exec_file ? \
31903 ++ gr_to_filename1(tsk->parent->exec_file->f_path.dentry, \
31904 ++ tsk->parent->exec_file->f_vfsmnt) : "/")
31905 ++
31906 ++#define proc_is_chrooted(tsk_a) ((tsk_a->pid > 1) && (tsk_a->fs != NULL) && \
31907 ++ ((tsk_a->fs->root.dentry->d_inode->i_sb->s_dev != \
31908 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_sb->s_dev) || \
31909 ++ (tsk_a->fs->root.dentry->d_inode->i_ino != \
31910 ++ tsk_a->nsproxy->pid_ns->child_reaper->fs->root.dentry->d_inode->i_ino)))
31911 ++
31912 ++#define have_same_root(tsk_a,tsk_b) ((tsk_a->fs != NULL) && (tsk_b->fs != NULL) && \
31913 ++ (tsk_a->fs->root.dentry->d_inode->i_sb->s_dev == \
31914 ++ tsk_b->fs->root.dentry->d_inode->i_sb->s_dev) && \
31915 ++ (tsk_a->fs->root.dentry->d_inode->i_ino == \
31916 ++ tsk_b->fs->root.dentry->d_inode->i_ino))
31917 ++
31918 ++#define DEFAULTSECARGS(task) gr_task_fullpath(task), task->comm, \
31919 ++ task->pid, task->uid, \
31920 ++ task->euid, task->gid, task->egid, \
31921 ++ gr_parent_task_fullpath(task), \
31922 ++ task->parent->comm, task->parent->pid, \
31923 ++ task->parent->uid, task->parent->euid, \
31924 ++ task->parent->gid, task->parent->egid
31925 ++
31926 ++#define GR_CHROOT_CAPS {{ \
31927 ++ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
31928 ++ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
31929 ++ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
31930 ++ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
31931 ++ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
31932 ++ CAP_TO_MASK(CAP_IPC_OWNER) , 0 }}
31933 ++
31934 ++#define security_learn(normal_msg,args...) \
31935 ++({ \
31936 ++ read_lock(&grsec_exec_file_lock); \
31937 ++ gr_add_learn_entry(normal_msg "\n", ## args); \
31938 ++ read_unlock(&grsec_exec_file_lock); \
31939 ++})
31940 ++
31941 ++enum {
31942 ++ GR_DO_AUDIT,
31943 ++ GR_DONT_AUDIT,
31944 ++ GR_DONT_AUDIT_GOOD
31945 ++};
31946 ++
31947 ++enum {
31948 ++ GR_TTYSNIFF,
31949 ++ GR_RBAC,
31950 ++ GR_RBAC_STR,
31951 ++ GR_STR_RBAC,
31952 ++ GR_RBAC_MODE2,
31953 ++ GR_RBAC_MODE3,
31954 ++ GR_FILENAME,
31955 ++ GR_SYSCTL_HIDDEN,
31956 ++ GR_NOARGS,
31957 ++ GR_ONE_INT,
31958 ++ GR_ONE_INT_TWO_STR,
31959 ++ GR_ONE_STR,
31960 ++ GR_STR_INT,
31961 ++ GR_TWO_INT,
31962 ++ GR_THREE_INT,
31963 ++ GR_FIVE_INT_TWO_STR,
31964 ++ GR_TWO_STR,
31965 ++ GR_THREE_STR,
31966 ++ GR_FOUR_STR,
31967 ++ GR_STR_FILENAME,
31968 ++ GR_FILENAME_STR,
31969 ++ GR_FILENAME_TWO_INT,
31970 ++ GR_FILENAME_TWO_INT_STR,
31971 ++ GR_TEXTREL,
31972 ++ GR_PTRACE,
31973 ++ GR_RESOURCE,
31974 ++ GR_CAP,
31975 ++ GR_SIG,
31976 ++ GR_CRASH1,
31977 ++ GR_CRASH2,
31978 ++ GR_PSACCT
31979 ++};
31980 ++
31981 ++#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
31982 ++#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
31983 ++#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
31984 ++#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
31985 ++#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
31986 ++#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
31987 ++#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)
31988 ++#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
31989 ++#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
31990 ++#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
31991 ++#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
31992 ++#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
31993 ++#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
31994 ++#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
31995 ++#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
31996 ++#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)
31997 ++#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
31998 ++#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
31999 ++#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
32000 ++#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
32001 ++#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
32002 ++#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
32003 ++#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)
32004 ++#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
32005 ++#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
32006 ++#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
32007 ++#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
32008 ++#define gr_log_sig(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG, task, num)
32009 ++#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
32010 ++#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
32011 ++#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)
32012 ++
32013 ++void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
32014 ++
32015 ++#endif
32016 ++
32017 ++#endif
32018 +diff -urNp linux-2.6.28/include/linux/grmsg.h linux-2.6.28/include/linux/grmsg.h
32019 +--- linux-2.6.28/include/linux/grmsg.h 1969-12-31 19:00:00.000000000 -0500
32020 ++++ linux-2.6.28/include/linux/grmsg.h 2009-01-11 05:47:05.000000000 -0500
32021 +@@ -0,0 +1,108 @@
32022 ++#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"
32023 ++#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"
32024 ++#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
32025 ++#define GR_STOPMOD_MSG "denied modification of module state by "
32026 ++#define GR_IOPERM_MSG "denied use of ioperm() by "
32027 ++#define GR_IOPL_MSG "denied use of iopl() by "
32028 ++#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
32029 ++#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
32030 ++#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
32031 ++#define GR_KMEM_MSG "denied write of /dev/kmem by "
32032 ++#define GR_PORT_OPEN_MSG "denied open of /dev/port by "
32033 ++#define GR_MEM_WRITE_MSG "denied write of /dev/mem by "
32034 ++#define GR_MEM_MMAP_MSG "denied mmap write of /dev/[k]mem by "
32035 ++#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
32036 ++#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"
32037 ++#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"
32038 ++#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
32039 ++#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
32040 ++#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
32041 ++#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
32042 ++#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
32043 ++#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
32044 ++#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
32045 ++#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%u.%u.%u.%u %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
32046 ++#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
32047 ++#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
32048 ++#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
32049 ++#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
32050 ++#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
32051 ++#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
32052 ++#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
32053 ++#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
32054 ++#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
32055 ++#define GR_NPROC_MSG "denied overstep of process limit by "
32056 ++#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
32057 ++#define GR_EXEC_TPE_MSG "denied untrusted exec of %.950s by "
32058 ++#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
32059 ++#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
32060 ++#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
32061 ++#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
32062 ++#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
32063 ++#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
32064 ++#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
32065 ++#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
32066 ++#define GR_FCHMOD_ACL_MSG "%s fchmod of %.950s by "
32067 ++#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
32068 ++#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
32069 ++#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
32070 ++#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
32071 ++#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
32072 ++#define GR_INITF_ACL_MSG "init_variables() failed %s by "
32073 ++#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"
32074 ++#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbaged by "
32075 ++#define GR_SHUTS_ACL_MSG "shutdown auth success for "
32076 ++#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
32077 ++#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
32078 ++#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
32079 ++#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
32080 ++#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
32081 ++#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
32082 ++#define GR_ENABLEF_ACL_MSG "unable to load %s for "
32083 ++#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
32084 ++#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
32085 ++#define GR_RELOADF_ACL_MSG "failed reload of %s for "
32086 ++#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
32087 ++#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
32088 ++#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
32089 ++#define GR_SPROLEF_ACL_MSG "special role %s failure for "
32090 ++#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
32091 ++#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
32092 ++#define GR_UNSPROLEF_ACL_MSG "special role unauth of %s failure for "
32093 ++#define GR_INVMODE_ACL_MSG "invalid mode %d by "
32094 ++#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
32095 ++#define GR_FAILFORK_MSG "failed fork with errno %d by "
32096 ++#define GR_NICE_CHROOT_MSG "denied priority change by "
32097 ++#define GR_UNISIGLOG_MSG "signal %d sent to "
32098 ++#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
32099 ++#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
32100 ++#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
32101 ++#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
32102 ++#define GR_TIME_MSG "time set by "
32103 ++#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
32104 ++#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
32105 ++#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
32106 ++#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
32107 ++#define GR_SOCK2_MSG "denied socket(%d,%.16s,%.16s) by "
32108 ++#define GR_BIND_MSG "denied bind() by "
32109 ++#define GR_CONNECT_MSG "denied connect() by "
32110 ++#define GR_BIND_ACL_MSG "denied bind() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
32111 ++#define GR_CONNECT_ACL_MSG "denied connect() to %u.%u.%u.%u port %u sock type %.16s protocol %.16s by "
32112 ++#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"
32113 ++#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
32114 ++#define GR_CAP_ACL_MSG "use of %s denied for "
32115 ++#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
32116 ++#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
32117 ++#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
32118 ++#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
32119 ++#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
32120 ++#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
32121 ++#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
32122 ++#define GR_MSGQ_AUDIT_MSG "message queue created by "
32123 ++#define GR_MSGQR_AUDIT_MSG "message queue of uid:%u euid:%u removed by "
32124 ++#define GR_SEM_AUDIT_MSG "semaphore created by "
32125 ++#define GR_SEMR_AUDIT_MSG "semaphore of uid:%u euid:%u removed by "
32126 ++#define GR_SHM_AUDIT_MSG "shared memory of size %d created by "
32127 ++#define GR_SHMR_AUDIT_MSG "shared memory of uid:%u euid:%u removed by "
32128 ++#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
32129 ++#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
32130 +diff -urNp linux-2.6.28/include/linux/grsecurity.h linux-2.6.28/include/linux/grsecurity.h
32131 +--- linux-2.6.28/include/linux/grsecurity.h 1969-12-31 19:00:00.000000000 -0500
32132 ++++ linux-2.6.28/include/linux/grsecurity.h 2009-01-11 05:47:05.000000000 -0500
32133 +@@ -0,0 +1,200 @@
32134 ++#ifndef GR_SECURITY_H
32135 ++#define GR_SECURITY_H
32136 ++#include <linux/fs.h>
32137 ++#include <linux/binfmts.h>
32138 ++#include <linux/gracl.h>
32139 ++
32140 ++/* notify of brain-dead configs */
32141 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
32142 ++#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
32143 ++#endif
32144 ++#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
32145 ++#error "CONFIG_PAX_NOEXEC enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
32146 ++#endif
32147 ++#if defined(CONFIG_PAX_ASLR) && (defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)) && !defined(CONFIG_PAX_EI_PAX) && !defined(CONFIG_PAX_PT_PAX_FLAGS)
32148 ++#error "CONFIG_PAX_ASLR enabled, but neither CONFIG_PAX_EI_PAX nor CONFIG_PAX_PT_PAX_FLAGS are enabled."
32149 ++#endif
32150 ++#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
32151 ++#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
32152 ++#endif
32153 ++#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
32154 ++#error "CONFIG_PAX enabled, but no PaX options are enabled."
32155 ++#endif
32156 ++
32157 ++void gr_handle_brute_attach(struct task_struct *p);
32158 ++void gr_handle_brute_check(void);
32159 ++
32160 ++char gr_roletype_to_char(void);
32161 ++
32162 ++int gr_check_user_change(int real, int effective, int fs);
32163 ++int gr_check_group_change(int real, int effective, int fs);
32164 ++
32165 ++void gr_del_task_from_ip_table(struct task_struct *p);
32166 ++
32167 ++int gr_pid_is_chrooted(struct task_struct *p);
32168 ++int gr_handle_chroot_nice(void);
32169 ++int gr_handle_chroot_sysctl(const int op);
32170 ++int gr_handle_chroot_setpriority(struct task_struct *p,
32171 ++ const int niceval);
32172 ++int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
32173 ++int gr_handle_chroot_chroot(const struct dentry *dentry,
32174 ++ const struct vfsmount *mnt);
32175 ++void gr_handle_chroot_caps(struct task_struct *task);
32176 ++void gr_handle_chroot_chdir(struct path *path);
32177 ++int gr_handle_chroot_chmod(const struct dentry *dentry,
32178 ++ const struct vfsmount *mnt, const int mode);
32179 ++int gr_handle_chroot_mknod(const struct dentry *dentry,
32180 ++ const struct vfsmount *mnt, const int mode);
32181 ++int gr_handle_chroot_mount(const struct dentry *dentry,
32182 ++ const struct vfsmount *mnt,
32183 ++ const char *dev_name);
32184 ++int gr_handle_chroot_pivot(void);
32185 ++int gr_handle_chroot_unix(const pid_t pid);
32186 ++
32187 ++int gr_handle_rawio(const struct inode *inode);
32188 ++int gr_handle_nproc(void);
32189 ++
32190 ++void gr_handle_ioperm(void);
32191 ++void gr_handle_iopl(void);
32192 ++
32193 ++int gr_tpe_allow(const struct file *file);
32194 ++
32195 ++int gr_random_pid(void);
32196 ++
32197 ++void gr_log_forkfail(const int retval);
32198 ++void gr_log_timechange(void);
32199 ++void gr_log_signal(const int sig, const struct task_struct *t);
32200 ++void gr_log_chdir(const struct dentry *dentry,
32201 ++ const struct vfsmount *mnt);
32202 ++void gr_log_chroot_exec(const struct dentry *dentry,
32203 ++ const struct vfsmount *mnt);
32204 ++void gr_handle_exec_args(struct linux_binprm *bprm, char **argv);
32205 ++void gr_log_remount(const char *devname, const int retval);
32206 ++void gr_log_unmount(const char *devname, const int retval);
32207 ++void gr_log_mount(const char *from, const char *to, const int retval);
32208 ++void gr_log_msgget(const int ret, const int msgflg);
32209 ++void gr_log_msgrm(const uid_t uid, const uid_t cuid);
32210 ++void gr_log_semget(const int err, const int semflg);
32211 ++void gr_log_semrm(const uid_t uid, const uid_t cuid);
32212 ++void gr_log_shmget(const int err, const int shmflg, const size_t size);
32213 ++void gr_log_shmrm(const uid_t uid, const uid_t cuid);
32214 ++void gr_log_textrel(struct vm_area_struct *vma);
32215 ++
32216 ++int gr_handle_follow_link(const struct inode *parent,
32217 ++ const struct inode *inode,
32218 ++ const struct dentry *dentry,
32219 ++ const struct vfsmount *mnt);
32220 ++int gr_handle_fifo(const struct dentry *dentry,
32221 ++ const struct vfsmount *mnt,
32222 ++ const struct dentry *dir, const int flag,
32223 ++ const int acc_mode);
32224 ++int gr_handle_hardlink(const struct dentry *dentry,
32225 ++ const struct vfsmount *mnt,
32226 ++ struct inode *inode,
32227 ++ const int mode, const char *to);
32228 ++
32229 ++int gr_task_is_capable(struct task_struct *task, const int cap);
32230 ++int gr_is_capable_nolog(const int cap);
32231 ++void gr_learn_resource(const struct task_struct *task, const int limit,
32232 ++ const unsigned long wanted, const int gt);
32233 ++void gr_copy_label(struct task_struct *tsk);
32234 ++void gr_handle_crash(struct task_struct *task, const int sig);
32235 ++int gr_handle_signal(const struct task_struct *p, const int sig);
32236 ++int gr_check_crash_uid(const uid_t uid);
32237 ++int gr_check_protected_task(const struct task_struct *task);
32238 ++int gr_acl_handle_mmap(const struct file *file,
32239 ++ const unsigned long prot);
32240 ++int gr_acl_handle_mprotect(const struct file *file,
32241 ++ const unsigned long prot);
32242 ++int gr_check_hidden_task(const struct task_struct *tsk);
32243 ++__u32 gr_acl_handle_truncate(const struct dentry *dentry,
32244 ++ const struct vfsmount *mnt);
32245 ++__u32 gr_acl_handle_utime(const struct dentry *dentry,
32246 ++ const struct vfsmount *mnt);
32247 ++__u32 gr_acl_handle_access(const struct dentry *dentry,
32248 ++ const struct vfsmount *mnt, const int fmode);
32249 ++__u32 gr_acl_handle_fchmod(const struct dentry *dentry,
32250 ++ const struct vfsmount *mnt, mode_t mode);
32251 ++__u32 gr_acl_handle_chmod(const struct dentry *dentry,
32252 ++ const struct vfsmount *mnt, mode_t mode);
32253 ++__u32 gr_acl_handle_chown(const struct dentry *dentry,
32254 ++ const struct vfsmount *mnt);
32255 ++int gr_handle_ptrace(struct task_struct *task, const long request);
32256 ++int gr_handle_proc_ptrace(struct task_struct *task);
32257 ++__u32 gr_acl_handle_execve(const struct dentry *dentry,
32258 ++ const struct vfsmount *mnt);
32259 ++int gr_check_crash_exec(const struct file *filp);
32260 ++int gr_acl_is_enabled(void);
32261 ++void gr_set_kernel_label(struct task_struct *task);
32262 ++void gr_set_role_label(struct task_struct *task, const uid_t uid,
32263 ++ const gid_t gid);
32264 ++int gr_set_proc_label(const struct dentry *dentry,
32265 ++ const struct vfsmount *mnt);
32266 ++__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
32267 ++ const struct vfsmount *mnt);
32268 ++__u32 gr_acl_handle_open(const struct dentry *dentry,
32269 ++ const struct vfsmount *mnt, const int fmode);
32270 ++__u32 gr_acl_handle_creat(const struct dentry *dentry,
32271 ++ const struct dentry *p_dentry,
32272 ++ const struct vfsmount *p_mnt, const int fmode,
32273 ++ const int imode);
32274 ++void gr_handle_create(const struct dentry *dentry,
32275 ++ const struct vfsmount *mnt);
32276 ++__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
32277 ++ const struct dentry *parent_dentry,
32278 ++ const struct vfsmount *parent_mnt,
32279 ++ const int mode);
32280 ++__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
32281 ++ const struct dentry *parent_dentry,
32282 ++ const struct vfsmount *parent_mnt);
32283 ++__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
32284 ++ const struct vfsmount *mnt);
32285 ++void gr_handle_delete(const ino_t ino, const dev_t dev);
32286 ++__u32 gr_acl_handle_unlink(const struct dentry *dentry,
32287 ++ const struct vfsmount *mnt);
32288 ++__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
32289 ++ const struct dentry *parent_dentry,
32290 ++ const struct vfsmount *parent_mnt,
32291 ++ const char *from);
32292 ++__u32 gr_acl_handle_link(const struct dentry *new_dentry,
32293 ++ const struct dentry *parent_dentry,
32294 ++ const struct vfsmount *parent_mnt,
32295 ++ const struct dentry *old_dentry,
32296 ++ const struct vfsmount *old_mnt, const char *to);
32297 ++int gr_acl_handle_rename(struct dentry *new_dentry,
32298 ++ struct dentry *parent_dentry,
32299 ++ const struct vfsmount *parent_mnt,
32300 ++ struct dentry *old_dentry,
32301 ++ struct inode *old_parent_inode,
32302 ++ struct vfsmount *old_mnt, const char *newname);
32303 ++void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
32304 ++ struct dentry *old_dentry,
32305 ++ struct dentry *new_dentry,
32306 ++ struct vfsmount *mnt, const __u8 replace);
32307 ++__u32 gr_check_link(const struct dentry *new_dentry,
32308 ++ const struct dentry *parent_dentry,
32309 ++ const struct vfsmount *parent_mnt,
32310 ++ const struct dentry *old_dentry,
32311 ++ const struct vfsmount *old_mnt);
32312 ++int gr_acl_handle_filldir(const struct file *file, const char *name,
32313 ++ const unsigned int namelen, const ino_t ino);
32314 ++
32315 ++__u32 gr_acl_handle_unix(const struct dentry *dentry,
32316 ++ const struct vfsmount *mnt);
32317 ++void gr_acl_handle_exit(void);
32318 ++void gr_acl_handle_psacct(struct task_struct *task, const long code);
32319 ++int gr_acl_handle_procpidmem(const struct task_struct *task);
32320 ++
32321 ++#ifdef CONFIG_GRKERNSEC
32322 ++void gr_handle_mem_write(void);
32323 ++void gr_handle_kmem_write(void);
32324 ++void gr_handle_open_port(void);
32325 ++int gr_handle_mem_mmap(const unsigned long offset,
32326 ++ struct vm_area_struct *vma);
32327 ++
32328 ++extern int grsec_enable_dmesg;
32329 ++extern int grsec_enable_randsrc;
32330 ++extern int grsec_enable_shm;
32331 ++#endif
32332 ++
32333 ++#endif
32334 +diff -urNp linux-2.6.28/include/linux/highmem.h linux-2.6.28/include/linux/highmem.h
32335 +--- linux-2.6.28/include/linux/highmem.h 2008-12-24 18:26:37.000000000 -0500
32336 ++++ linux-2.6.28/include/linux/highmem.h 2009-01-11 07:20:06.000000000 -0500
32337 +@@ -124,6 +124,13 @@ static inline void clear_highpage(struct
32338 + kunmap_atomic(kaddr, KM_USER0);
32339 + }
32340 +
32341 ++static inline void sanitize_highpage(struct page *page)
32342 ++{
32343 ++ void *kaddr = kmap_atomic(page, KM_CLEARPAGE);
32344 ++ clear_page(kaddr);
32345 ++ kunmap_atomic(kaddr, KM_CLEARPAGE);
32346 ++}
32347 ++
32348 + static inline void zero_user_segments(struct page *page,
32349 + unsigned start1, unsigned end1,
32350 + unsigned start2, unsigned end2)
32351 +diff -urNp linux-2.6.28/include/linux/jbd2.h linux-2.6.28/include/linux/jbd2.h
32352 +--- linux-2.6.28/include/linux/jbd2.h 2008-12-24 18:26:37.000000000 -0500
32353 ++++ linux-2.6.28/include/linux/jbd2.h 2009-01-11 07:20:06.000000000 -0500
32354 +@@ -66,7 +66,7 @@ extern u8 jbd2_journal_enable_debug;
32355 + } \
32356 + } while (0)
32357 + #else
32358 +-#define jbd_debug(f, a...) /**/
32359 ++#define jbd_debug(f, a...) do {} while (0)
32360 + #endif
32361 +
32362 + static inline void *jbd2_alloc(size_t size, gfp_t flags)
32363 +diff -urNp linux-2.6.28/include/linux/jbd.h linux-2.6.28/include/linux/jbd.h
32364 +--- linux-2.6.28/include/linux/jbd.h 2008-12-24 18:26:37.000000000 -0500
32365 ++++ linux-2.6.28/include/linux/jbd.h 2009-01-11 07:20:06.000000000 -0500
32366 +@@ -66,7 +66,7 @@ extern u8 journal_enable_debug;
32367 + } \
32368 + } while (0)
32369 + #else
32370 +-#define jbd_debug(f, a...) /**/
32371 ++#define jbd_debug(f, a...) do {} while (0)
32372 + #endif
32373 +
32374 + static inline void *jbd_alloc(size_t size, gfp_t flags)
32375 +diff -urNp linux-2.6.28/include/linux/libata.h linux-2.6.28/include/linux/libata.h
32376 +--- linux-2.6.28/include/linux/libata.h 2008-12-24 18:26:37.000000000 -0500
32377 ++++ linux-2.6.28/include/linux/libata.h 2009-01-11 07:20:06.000000000 -0500
32378 +@@ -64,11 +64,11 @@
32379 + #ifdef ATA_VERBOSE_DEBUG
32380 + #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
32381 + #else
32382 +-#define VPRINTK(fmt, args...)
32383 ++#define VPRINTK(fmt, args...) do {} while (0)
32384 + #endif /* ATA_VERBOSE_DEBUG */
32385 + #else
32386 +-#define DPRINTK(fmt, args...)
32387 +-#define VPRINTK(fmt, args...)
32388 ++#define DPRINTK(fmt, args...) do {} while (0)
32389 ++#define VPRINTK(fmt, args...) do {} while (0)
32390 + #endif /* ATA_DEBUG */
32391 +
32392 + #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
32393 +diff -urNp linux-2.6.28/include/linux/mm.h linux-2.6.28/include/linux/mm.h
32394 +--- linux-2.6.28/include/linux/mm.h 2008-12-24 18:26:37.000000000 -0500
32395 ++++ linux-2.6.28/include/linux/mm.h 2009-01-11 07:20:06.000000000 -0500
32396 +@@ -39,6 +39,7 @@ extern unsigned long mmap_min_addr;
32397 + #include <asm/page.h>
32398 + #include <asm/pgtable.h>
32399 + #include <asm/processor.h>
32400 ++#include <asm/mman.h>
32401 +
32402 + #define nth_page(page,n) pfn_to_page(page_to_pfn((page)) + (n))
32403 +
32404 +@@ -115,6 +116,10 @@ extern unsigned int kobjsize(const void
32405 + #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
32406 + #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
32407 +
32408 ++#ifdef CONFIG_PAX_PAGEEXEC
32409 ++#define VM_PAGEEXEC 0x40000000 /* vma->vm_page_prot needs special handling */
32410 ++#endif
32411 ++
32412 + #ifndef VM_STACK_DEFAULT_FLAGS /* arch can override this */
32413 + #define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS
32414 + #endif
32415 +@@ -874,6 +879,8 @@ struct shrinker {
32416 + extern void register_shrinker(struct shrinker *);
32417 + extern void unregister_shrinker(struct shrinker *);
32418 +
32419 ++pgprot_t vm_get_page_prot(unsigned long vm_flags);
32420 ++
32421 + int vma_wants_writenotify(struct vm_area_struct *vma);
32422 +
32423 + extern pte_t *get_locked_pte(struct mm_struct *mm, unsigned long addr, spinlock_t **ptl);
32424 +@@ -1129,6 +1136,7 @@ out:
32425 + }
32426 +
32427 + extern int do_munmap(struct mm_struct *, unsigned long, size_t);
32428 ++extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
32429 +
32430 + extern unsigned long do_brk(unsigned long, unsigned long);
32431 +
32432 +@@ -1181,6 +1189,10 @@ extern struct vm_area_struct * find_vma(
32433 + extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
32434 + struct vm_area_struct **pprev);
32435 +
32436 ++extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
32437 ++extern void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
32438 ++extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
32439 ++
32440 + /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
32441 + NULL if none. Assume start_addr < end_addr. */
32442 + static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
32443 +@@ -1197,7 +1209,6 @@ static inline unsigned long vma_pages(st
32444 + return (vma->vm_end - vma->vm_start) >> PAGE_SHIFT;
32445 + }
32446 +
32447 +-pgprot_t vm_get_page_prot(unsigned long vm_flags);
32448 + struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
32449 + int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
32450 + unsigned long pfn, unsigned long size, pgprot_t);
32451 +@@ -1286,5 +1297,11 @@ int vmemmap_populate_basepages(struct pa
32452 + int vmemmap_populate(struct page *start_page, unsigned long pages, int node);
32453 + void vmemmap_populate_print_last(void);
32454 +
32455 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
32456 ++extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
32457 ++#else
32458 ++static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
32459 ++#endif
32460 ++
32461 + #endif /* __KERNEL__ */
32462 + #endif /* _LINUX_MM_H */
32463 +diff -urNp linux-2.6.28/include/linux/mm_types.h linux-2.6.28/include/linux/mm_types.h
32464 +--- linux-2.6.28/include/linux/mm_types.h 2008-12-24 18:26:37.000000000 -0500
32465 ++++ linux-2.6.28/include/linux/mm_types.h 2009-01-11 07:20:06.000000000 -0500
32466 +@@ -157,6 +157,8 @@ struct vm_area_struct {
32467 + #ifdef CONFIG_NUMA
32468 + struct mempolicy *vm_policy; /* NUMA policy for the VMA */
32469 + #endif
32470 ++
32471 ++ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
32472 + };
32473 +
32474 + struct core_thread {
32475 +@@ -256,6 +258,24 @@ struct mm_struct {
32476 + #ifdef CONFIG_MMU_NOTIFIER
32477 + struct mmu_notifier_mm *mmu_notifier_mm;
32478 + #endif
32479 ++
32480 ++#if defined(CONFIG_PAX_EI_PAX) || defined(CONFIG_PAX_PT_PAX_FLAGS) || defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
32481 ++ unsigned long pax_flags;
32482 ++#endif
32483 ++
32484 ++#ifdef CONFIG_PAX_DLRESOLVE
32485 ++ unsigned long call_dl_resolve;
32486 ++#endif
32487 ++
32488 ++#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
32489 ++ unsigned long call_syscall;
32490 ++#endif
32491 ++
32492 ++#ifdef CONFIG_PAX_ASLR
32493 ++ unsigned long delta_mmap; /* randomized offset */
32494 ++ unsigned long delta_stack; /* randomized offset */
32495 ++#endif
32496 ++
32497 + };
32498 +
32499 + #endif /* _LINUX_MM_TYPES_H */
32500 +diff -urNp linux-2.6.28/include/linux/module.h linux-2.6.28/include/linux/module.h
32501 +--- linux-2.6.28/include/linux/module.h 2008-12-24 18:26:37.000000000 -0500
32502 ++++ linux-2.6.28/include/linux/module.h 2009-01-11 07:20:06.000000000 -0500
32503 +@@ -283,16 +283,16 @@ struct module
32504 + int (*init)(void);
32505 +
32506 + /* If this is non-NULL, vfree after init() returns */
32507 +- void *module_init;
32508 ++ void *module_init_rx, *module_init_rw;
32509 +
32510 + /* Here is the actual code + data, vfree'd on unload. */
32511 +- void *module_core;
32512 ++ void *module_core_rx, *module_core_rw;
32513 +
32514 + /* Here are the sizes of the init and core sections */
32515 +- unsigned int init_size, core_size;
32516 ++ unsigned int init_size_rw, core_size_rw;
32517 +
32518 + /* The size of the executable code in each section. */
32519 +- unsigned int init_text_size, core_text_size;
32520 ++ unsigned int init_size_rx, core_size_rx;
32521 +
32522 + /* The handle returned from unwind_add_table. */
32523 + void *unwind_info;
32524 +diff -urNp linux-2.6.28/include/linux/moduleloader.h linux-2.6.28/include/linux/moduleloader.h
32525 +--- linux-2.6.28/include/linux/moduleloader.h 2008-12-24 18:26:37.000000000 -0500
32526 ++++ linux-2.6.28/include/linux/moduleloader.h 2009-01-11 07:20:06.000000000 -0500
32527 +@@ -17,9 +17,21 @@ int module_frob_arch_sections(Elf_Ehdr *
32528 + sections. Returns NULL on failure. */
32529 + void *module_alloc(unsigned long size);
32530 +
32531 ++#ifdef CONFIG_PAX_KERNEXEC
32532 ++void *module_alloc_exec(unsigned long size);
32533 ++#else
32534 ++#define module_alloc_exec(x) module_alloc(x)
32535 ++#endif
32536 ++
32537 + /* Free memory returned from module_alloc. */
32538 + void module_free(struct module *mod, void *module_region);
32539 +
32540 ++#ifdef CONFIG_PAX_KERNEXEC
32541 ++void module_free_exec(struct module *mod, void *module_region);
32542 ++#else
32543 ++#define module_free_exec(x, y) module_free(x, y)
32544 ++#endif
32545 ++
32546 + /* Apply the given relocation to the (simplified) ELF. Return -error
32547 + or 0. */
32548 + int apply_relocate(Elf_Shdr *sechdrs,
32549 +diff -urNp linux-2.6.28/include/linux/namei.h linux-2.6.28/include/linux/namei.h
32550 +--- linux-2.6.28/include/linux/namei.h 2008-12-24 18:26:37.000000000 -0500
32551 ++++ linux-2.6.28/include/linux/namei.h 2009-01-11 07:20:06.000000000 -0500
32552 +@@ -21,7 +21,7 @@ struct nameidata {
32553 + unsigned int flags;
32554 + int last_type;
32555 + unsigned depth;
32556 +- char *saved_names[MAX_NESTED_LINKS + 1];
32557 ++ const char *saved_names[MAX_NESTED_LINKS + 1];
32558 +
32559 + /* Intent data */
32560 + union {
32561 +@@ -84,12 +84,12 @@ extern int follow_up(struct vfsmount **,
32562 + extern struct dentry *lock_rename(struct dentry *, struct dentry *);
32563 + extern void unlock_rename(struct dentry *, struct dentry *);
32564 +
32565 +-static inline void nd_set_link(struct nameidata *nd, char *path)
32566 ++static inline void nd_set_link(struct nameidata *nd, const char *path)
32567 + {
32568 + nd->saved_names[nd->depth] = path;
32569 + }
32570 +
32571 +-static inline char *nd_get_link(struct nameidata *nd)
32572 ++static inline const char *nd_get_link(struct nameidata *nd)
32573 + {
32574 + return nd->saved_names[nd->depth];
32575 + }
32576 +diff -urNp linux-2.6.28/include/linux/nodemask.h linux-2.6.28/include/linux/nodemask.h
32577 +--- linux-2.6.28/include/linux/nodemask.h 2008-12-24 18:26:37.000000000 -0500
32578 ++++ linux-2.6.28/include/linux/nodemask.h 2009-01-11 07:20:06.000000000 -0500
32579 +@@ -442,11 +442,11 @@ static inline int num_node_state(enum no
32580 +
32581 + #define any_online_node(mask) \
32582 + ({ \
32583 +- int node; \
32584 +- for_each_node_mask(node, (mask)) \
32585 +- if (node_online(node)) \
32586 ++ int __node; \
32587 ++ for_each_node_mask(__node, (mask)) \
32588 ++ if (node_online(__node)) \
32589 + break; \
32590 +- node; \
32591 ++ __node; \
32592 + })
32593 +
32594 + #define num_online_nodes() num_node_state(N_ONLINE)
32595 +diff -urNp linux-2.6.28/include/linux/percpu.h linux-2.6.28/include/linux/percpu.h
32596 +--- linux-2.6.28/include/linux/percpu.h 2008-12-24 18:26:37.000000000 -0500
32597 ++++ linux-2.6.28/include/linux/percpu.h 2009-01-11 07:20:06.000000000 -0500
32598 +@@ -50,7 +50,7 @@
32599 + #endif
32600 +
32601 + #define PERCPU_ENOUGH_ROOM \
32602 +- (__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE)
32603 ++ ((unsigned long)(__per_cpu_end - __per_cpu_start + PERCPU_MODULE_RESERVE))
32604 + #endif /* PERCPU_ENOUGH_ROOM */
32605 +
32606 + /*
32607 +diff -urNp linux-2.6.28/include/linux/poison.h linux-2.6.28/include/linux/poison.h
32608 +--- linux-2.6.28/include/linux/poison.h 2008-12-24 18:26:37.000000000 -0500
32609 ++++ linux-2.6.28/include/linux/poison.h 2009-01-11 07:20:06.000000000 -0500
32610 +@@ -7,8 +7,8 @@
32611 + * under normal circumstances, used to verify that nobody uses
32612 + * non-initialized list entries.
32613 + */
32614 +-#define LIST_POISON1 ((void *) 0x00100100)
32615 +-#define LIST_POISON2 ((void *) 0x00200200)
32616 ++#define LIST_POISON1 ((void *) 0xFF1001FFFF1001FFULL)
32617 ++#define LIST_POISON2 ((void *) 0xFF2002FFFF2002FFULL)
32618 +
32619 + /********** include/linux/timer.h **********/
32620 + /*
32621 +diff -urNp linux-2.6.28/include/linux/proc_fs.h linux-2.6.28/include/linux/proc_fs.h
32622 +--- linux-2.6.28/include/linux/proc_fs.h 2008-12-24 18:26:37.000000000 -0500
32623 ++++ linux-2.6.28/include/linux/proc_fs.h 2009-01-11 07:10:44.000000000 -0500
32624 +@@ -174,6 +174,19 @@ static inline struct proc_dir_entry *pro
32625 + return proc_create_data(name, mode, parent, proc_fops, NULL);
32626 + }
32627 +
32628 ++static inline struct proc_dir_entry *proc_create_grsec(const char *name, mode_t mode,
32629 ++ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
32630 ++{
32631 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
32632 ++ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
32633 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
32634 ++ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
32635 ++#else
32636 ++ return proc_create_data(name, mode, parent, proc_fops, NULL);
32637 ++#endif
32638 ++}
32639 ++
32640 ++
32641 + static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
32642 + mode_t mode, struct proc_dir_entry *base,
32643 + read_proc_t *read_proc, void * data)
32644 +diff -urNp linux-2.6.28/include/linux/random.h linux-2.6.28/include/linux/random.h
32645 +--- linux-2.6.28/include/linux/random.h 2008-12-24 18:26:37.000000000 -0500
32646 ++++ linux-2.6.28/include/linux/random.h 2009-01-11 07:20:06.000000000 -0500
32647 +@@ -72,6 +72,11 @@ unsigned long randomize_range(unsigned l
32648 + u32 random32(void);
32649 + void srandom32(u32 seed);
32650 +
32651 ++static inline unsigned long pax_get_random_long(void)
32652 ++{
32653 ++ return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
32654 ++}
32655 ++
32656 + #endif /* __KERNEL___ */
32657 +
32658 + #endif /* _LINUX_RANDOM_H */
32659 +diff -urNp linux-2.6.28/include/linux/sched.h linux-2.6.28/include/linux/sched.h
32660 +--- linux-2.6.28/include/linux/sched.h 2008-12-24 18:26:37.000000000 -0500
32661 ++++ linux-2.6.28/include/linux/sched.h 2009-01-11 07:50:31.000000000 -0500
32662 +@@ -96,6 +96,7 @@ struct exec_domain;
32663 + struct futex_pi_state;
32664 + struct robust_list_head;
32665 + struct bio;
32666 ++struct linux_binprm;
32667 +
32668 + /*
32669 + * List of flags we want to share for kernel threads,
32670 +@@ -588,6 +589,15 @@ struct signal_struct {
32671 + unsigned audit_tty;
32672 + struct tty_audit_buf *tty_audit_buf;
32673 + #endif
32674 ++
32675 ++#ifdef CONFIG_GRKERNSEC
32676 ++ u32 curr_ip;
32677 ++ u32 gr_saddr;
32678 ++ u32 gr_daddr;
32679 ++ u16 gr_sport;
32680 ++ u16 gr_dport;
32681 ++ u8 used_accept:1;
32682 ++#endif
32683 + };
32684 +
32685 + /* Context switch must be unlocked if interrupts are to be enabled */
32686 +@@ -1074,7 +1084,7 @@ struct sched_rt_entity {
32687 +
32688 + struct task_struct {
32689 + volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
32690 +- void *stack;
32691 ++ struct thread_info *stack;
32692 + atomic_t usage;
32693 + unsigned int flags; /* per process flags, defined below */
32694 + unsigned int ptrace;
32695 +@@ -1139,10 +1149,9 @@ struct task_struct {
32696 + pid_t pid;
32697 + pid_t tgid;
32698 +
32699 +-#ifdef CONFIG_CC_STACKPROTECTOR
32700 + /* Canary value for the -fstack-protector gcc feature */
32701 + unsigned long stack_canary;
32702 +-#endif
32703 ++
32704 + /*
32705 + * pointers to (original) parent process, youngest child, younger sibling,
32706 + * older sibling, respectively. (p->father can be replaced with
32707 +@@ -1170,8 +1179,8 @@ struct task_struct {
32708 + struct list_head thread_group;
32709 +
32710 + struct completion *vfork_done; /* for vfork() */
32711 +- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
32712 +- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
32713 ++ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
32714 ++ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
32715 +
32716 + cputime_t utime, stime, utimescaled, stimescaled;
32717 + cputime_t gtime;
32718 +@@ -1356,8 +1365,64 @@ struct task_struct {
32719 + unsigned long default_timer_slack_ns;
32720 +
32721 + struct list_head *scm_work_list;
32722 ++
32723 ++#ifdef CONFIG_GRKERNSEC
32724 ++ /* grsecurity */
32725 ++ struct acl_subject_label *acl;
32726 ++ struct acl_role_label *role;
32727 ++ struct file *exec_file;
32728 ++ u16 acl_role_id;
32729 ++ u8 acl_sp_role;
32730 ++ u8 is_writable;
32731 ++ u8 brute;
32732 ++#endif
32733 ++
32734 + };
32735 +
32736 ++#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
32737 ++#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
32738 ++#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
32739 ++#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
32740 ++/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
32741 ++#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
32742 ++
32743 ++#ifdef CONFIG_PAX_SOFTMODE
32744 ++extern unsigned int pax_softmode;
32745 ++#endif
32746 ++
32747 ++extern int pax_check_flags(unsigned long *);
32748 ++
32749 ++/* if tsk != current then task_lock must be held on it */
32750 ++#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
32751 ++static inline unsigned long pax_get_flags(struct task_struct *tsk)
32752 ++{
32753 ++ if (likely(tsk->mm))
32754 ++ return tsk->mm->pax_flags;
32755 ++ else
32756 ++ return 0UL;
32757 ++}
32758 ++
32759 ++/* if tsk != current then task_lock must be held on it */
32760 ++static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
32761 ++{
32762 ++ if (likely(tsk->mm)) {
32763 ++ tsk->mm->pax_flags = flags;
32764 ++ return 0;
32765 ++ }
32766 ++ return -EINVAL;
32767 ++}
32768 ++#endif
32769 ++
32770 ++#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
32771 ++extern void pax_set_initial_flags(struct linux_binprm *bprm);
32772 ++#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
32773 ++extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
32774 ++#endif
32775 ++
32776 ++void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
32777 ++void pax_report_insns(void *pc, void *sp);
32778 ++void pax_report_refcount_overflow(struct pt_regs *regs);
32779 ++
32780 + /*
32781 + * Priority of a process goes from 0..MAX_PRIO-1, valid RT
32782 + * priority is 0..MAX_RT_PRIO-1, and SCHED_NORMAL/SCHED_BATCH
32783 +@@ -1900,7 +1965,7 @@ extern void __cleanup_sighand(struct sig
32784 + extern void exit_itimers(struct signal_struct *);
32785 + extern void flush_itimer_signals(void);
32786 +
32787 +-extern NORET_TYPE void do_group_exit(int);
32788 ++extern NORET_TYPE void do_group_exit(int) ATTRIB_NORET;
32789 +
32790 + extern void daemonize(const char *, ...);
32791 + extern int allow_signal(int);
32792 +@@ -2003,8 +2068,8 @@ static inline void unlock_task_sighand(s
32793 +
32794 + #ifndef __HAVE_THREAD_FUNCTIONS
32795 +
32796 +-#define task_thread_info(task) ((struct thread_info *)(task)->stack)
32797 +-#define task_stack_page(task) ((task)->stack)
32798 ++#define task_thread_info(task) ((task)->stack)
32799 ++#define task_stack_page(task) ((void *)(task)->stack)
32800 +
32801 + static inline void setup_thread_stack(struct task_struct *p, struct task_struct *org)
32802 + {
32803 +diff -urNp linux-2.6.28/include/linux/screen_info.h linux-2.6.28/include/linux/screen_info.h
32804 +--- linux-2.6.28/include/linux/screen_info.h 2008-12-24 18:26:37.000000000 -0500
32805 ++++ linux-2.6.28/include/linux/screen_info.h 2009-01-11 07:20:06.000000000 -0500
32806 +@@ -42,7 +42,8 @@ struct screen_info {
32807 + __u16 pages; /* 0x32 */
32808 + __u16 vesa_attributes; /* 0x34 */
32809 + __u32 capabilities; /* 0x36 */
32810 +- __u8 _reserved[6]; /* 0x3a */
32811 ++ __u16 vesapm_size; /* 0x3a */
32812 ++ __u8 _reserved[4]; /* 0x3c */
32813 + } __attribute__((packed));
32814 +
32815 + #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
32816 +diff -urNp linux-2.6.28/include/linux/shm.h linux-2.6.28/include/linux/shm.h
32817 +--- linux-2.6.28/include/linux/shm.h 2008-12-24 18:26:37.000000000 -0500
32818 ++++ linux-2.6.28/include/linux/shm.h 2009-01-11 05:47:05.000000000 -0500
32819 +@@ -95,6 +95,10 @@ struct shmid_kernel /* private to the ke
32820 + pid_t shm_cprid;
32821 + pid_t shm_lprid;
32822 + struct user_struct *mlock_user;
32823 ++#ifdef CONFIG_GRKERNSEC
32824 ++ time_t shm_createtime;
32825 ++ pid_t shm_lapid;
32826 ++#endif
32827 + };
32828 +
32829 + /* shm_mode upper byte flags */
32830 +diff -urNp linux-2.6.28/include/linux/slab.h linux-2.6.28/include/linux/slab.h
32831 +--- linux-2.6.28/include/linux/slab.h 2008-12-24 18:26:37.000000000 -0500
32832 ++++ linux-2.6.28/include/linux/slab.h 2009-01-11 07:20:06.000000000 -0500
32833 +@@ -73,10 +73,9 @@
32834 + * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
32835 + * Both make kfree a no-op.
32836 + */
32837 +-#define ZERO_SIZE_PTR ((void *)16)
32838 ++#define ZERO_SIZE_PTR ((void *)-1024L)
32839 +
32840 +-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
32841 +- (unsigned long)ZERO_SIZE_PTR)
32842 ++#define ZERO_OR_NULL_PTR(x) (!(x) || (x) == ZERO_SIZE_PTR)
32843 +
32844 + /*
32845 + * struct kmem_cache related prototypes
32846 +diff -urNp linux-2.6.28/include/linux/sysctl.h linux-2.6.28/include/linux/sysctl.h
32847 +--- linux-2.6.28/include/linux/sysctl.h 2008-12-24 18:26:37.000000000 -0500
32848 ++++ linux-2.6.28/include/linux/sysctl.h 2009-01-11 07:20:06.000000000 -0500
32849 +@@ -165,7 +165,11 @@ enum
32850 + KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
32851 + };
32852 +
32853 +-
32854 ++#ifdef CONFIG_PAX_SOFTMODE
32855 ++enum {
32856 ++ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
32857 ++};
32858 ++#endif
32859 +
32860 + /* CTL_VM names: */
32861 + enum
32862 +diff -urNp linux-2.6.28/include/linux/thread_info.h linux-2.6.28/include/linux/thread_info.h
32863 +--- linux-2.6.28/include/linux/thread_info.h 2008-12-24 18:26:37.000000000 -0500
32864 ++++ linux-2.6.28/include/linux/thread_info.h 2009-01-11 07:20:06.000000000 -0500
32865 +@@ -23,7 +23,7 @@ struct restart_block {
32866 + };
32867 + /* For futex_wait */
32868 + struct {
32869 +- u32 *uaddr;
32870 ++ u32 __user *uaddr;
32871 + u32 val;
32872 + u32 flags;
32873 + u32 bitset;
32874 +diff -urNp linux-2.6.28/include/linux/uaccess.h linux-2.6.28/include/linux/uaccess.h
32875 +--- linux-2.6.28/include/linux/uaccess.h 2008-12-24 18:26:37.000000000 -0500
32876 ++++ linux-2.6.28/include/linux/uaccess.h 2009-01-11 07:20:06.000000000 -0500
32877 +@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_
32878 + long ret; \
32879 + mm_segment_t old_fs = get_fs(); \
32880 + \
32881 +- set_fs(KERNEL_DS); \
32882 + pagefault_disable(); \
32883 ++ set_fs(KERNEL_DS); \
32884 + ret = __get_user(retval, (__force typeof(retval) __user *)(addr)); \
32885 +- pagefault_enable(); \
32886 + set_fs(old_fs); \
32887 ++ pagefault_enable(); \
32888 + ret; \
32889 + })
32890 +
32891 +diff -urNp linux-2.6.28/include/linux/vmalloc.h linux-2.6.28/include/linux/vmalloc.h
32892 +--- linux-2.6.28/include/linux/vmalloc.h 2008-12-24 18:26:37.000000000 -0500
32893 ++++ linux-2.6.28/include/linux/vmalloc.h 2009-01-11 07:20:06.000000000 -0500
32894 +@@ -13,6 +13,11 @@ struct vm_area_struct; /* vma defining
32895 + #define VM_MAP 0x00000004 /* vmap()ed pages */
32896 + #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
32897 + #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
32898 ++
32899 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32900 ++#define VM_KERNEXEC 0x00000020 /* allocate from executable kernel memory range */
32901 ++#endif
32902 ++
32903 + /* bits [20..32] reserved for arch specific ioremap internals */
32904 +
32905 + /*
32906 +diff -urNp linux-2.6.28/include/net/sctp/sctp.h linux-2.6.28/include/net/sctp/sctp.h
32907 +--- linux-2.6.28/include/net/sctp/sctp.h 2008-12-24 18:26:37.000000000 -0500
32908 ++++ linux-2.6.28/include/net/sctp/sctp.h 2009-01-11 07:20:06.000000000 -0500
32909 +@@ -309,8 +309,8 @@ extern int sctp_debug_flag;
32910 +
32911 + #else /* SCTP_DEBUG */
32912 +
32913 +-#define SCTP_DEBUG_PRINTK(whatever...)
32914 +-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
32915 ++#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
32916 ++#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
32917 + #define SCTP_ENABLE_DEBUG
32918 + #define SCTP_DISABLE_DEBUG
32919 + #define SCTP_ASSERT(expr, str, func)
32920 +diff -urNp linux-2.6.28/include/sound/core.h linux-2.6.28/include/sound/core.h
32921 +--- linux-2.6.28/include/sound/core.h 2008-12-24 18:26:37.000000000 -0500
32922 ++++ linux-2.6.28/include/sound/core.h 2009-01-11 07:20:06.000000000 -0500
32923 +@@ -405,7 +405,7 @@ static inline int __snd_bug_on(void)
32924 + */
32925 + #define snd_printdd(format, args...) snd_printk(format, ##args)
32926 + #else
32927 +-#define snd_printdd(format, args...) /* nothing */
32928 ++#define snd_printdd(format, args...) do {} while (0)
32929 + #endif
32930 +
32931 +
32932 +diff -urNp linux-2.6.28/include/video/uvesafb.h linux-2.6.28/include/video/uvesafb.h
32933 +--- linux-2.6.28/include/video/uvesafb.h 2008-12-24 18:26:37.000000000 -0500
32934 ++++ linux-2.6.28/include/video/uvesafb.h 2009-01-11 07:20:06.000000000 -0500
32935 +@@ -175,6 +175,7 @@ struct uvesafb_par {
32936 + u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
32937 + u8 pmi_setpal; /* PMI for palette changes */
32938 + u16 *pmi_base; /* protected mode interface location */
32939 ++ u8 *pmi_code; /* protected mode code location */
32940 + void *pmi_start;
32941 + void *pmi_pal;
32942 + u8 *vbe_state_orig; /*
32943 +diff -urNp linux-2.6.28/init/do_mounts.c linux-2.6.28/init/do_mounts.c
32944 +--- linux-2.6.28/init/do_mounts.c 2008-12-24 18:26:37.000000000 -0500
32945 ++++ linux-2.6.28/init/do_mounts.c 2009-01-11 07:20:06.000000000 -0500
32946 +@@ -214,11 +214,11 @@ static void __init get_fs_names(char *pa
32947 +
32948 + static int __init do_mount_root(char *name, char *fs, int flags, void *data)
32949 + {
32950 +- int err = sys_mount(name, "/root", fs, flags, data);
32951 ++ int err = sys_mount((char __user *)name, (char __user *)"/root", (char __user *)fs, flags, (void __user *)data);
32952 + if (err)
32953 + return err;
32954 +
32955 +- sys_chdir("/root");
32956 ++ sys_chdir((char __user *)"/root");
32957 + ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
32958 + printk("VFS: Mounted root (%s filesystem)%s.\n",
32959 + current->fs->pwd.mnt->mnt_sb->s_type->name,
32960 +@@ -308,18 +308,18 @@ void __init change_floppy(char *fmt, ...
32961 + va_start(args, fmt);
32962 + vsprintf(buf, fmt, args);
32963 + va_end(args);
32964 +- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
32965 ++ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
32966 + if (fd >= 0) {
32967 + sys_ioctl(fd, FDEJECT, 0);
32968 + sys_close(fd);
32969 + }
32970 + printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
32971 +- fd = sys_open("/dev/console", O_RDWR, 0);
32972 ++ fd = sys_open((char __user *)"/dev/console", O_RDWR, 0);
32973 + if (fd >= 0) {
32974 + sys_ioctl(fd, TCGETS, (long)&termios);
32975 + termios.c_lflag &= ~ICANON;
32976 + sys_ioctl(fd, TCSETSF, (long)&termios);
32977 +- sys_read(fd, &c, 1);
32978 ++ sys_read(fd, (char __user *)&c, 1);
32979 + termios.c_lflag |= ICANON;
32980 + sys_ioctl(fd, TCSETSF, (long)&termios);
32981 + sys_close(fd);
32982 +@@ -406,7 +406,7 @@ void __init prepare_namespace(void)
32983 +
32984 + mount_root();
32985 + out:
32986 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
32987 +- sys_chroot(".");
32988 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
32989 ++ sys_chroot((char __user *)".");
32990 + }
32991 +
32992 +diff -urNp linux-2.6.28/init/do_mounts.h linux-2.6.28/init/do_mounts.h
32993 +--- linux-2.6.28/init/do_mounts.h 2008-12-24 18:26:37.000000000 -0500
32994 ++++ linux-2.6.28/init/do_mounts.h 2009-01-11 07:20:06.000000000 -0500
32995 +@@ -14,15 +14,15 @@ extern int root_mountflags;
32996 +
32997 + static inline int create_dev(char *name, dev_t dev)
32998 + {
32999 +- sys_unlink(name);
33000 +- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
33001 ++ sys_unlink((char __user *)name);
33002 ++ return sys_mknod((char __user *)name, S_IFBLK|0600, new_encode_dev(dev));
33003 + }
33004 +
33005 + #if BITS_PER_LONG == 32
33006 + static inline u32 bstat(char *name)
33007 + {
33008 + struct stat64 stat;
33009 +- if (sys_stat64(name, &stat) != 0)
33010 ++ if (sys_stat64((char __user *)name, (struct stat64 __user *)&stat) != 0)
33011 + return 0;
33012 + if (!S_ISBLK(stat.st_mode))
33013 + return 0;
33014 +diff -urNp linux-2.6.28/init/do_mounts_initrd.c linux-2.6.28/init/do_mounts_initrd.c
33015 +--- linux-2.6.28/init/do_mounts_initrd.c 2008-12-24 18:26:37.000000000 -0500
33016 ++++ linux-2.6.28/init/do_mounts_initrd.c 2009-01-11 07:20:06.000000000 -0500
33017 +@@ -32,7 +32,7 @@ static int __init do_linuxrc(void * shel
33018 + sys_close(old_fd);sys_close(root_fd);
33019 + sys_close(0);sys_close(1);sys_close(2);
33020 + sys_setsid();
33021 +- (void) sys_open("/dev/console",O_RDWR,0);
33022 ++ (void) sys_open((const char __user *)"/dev/console",O_RDWR,0);
33023 + (void) sys_dup(0);
33024 + (void) sys_dup(0);
33025 + return kernel_execve(shell, argv, envp_init);
33026 +@@ -47,13 +47,13 @@ static void __init handle_initrd(void)
33027 + create_dev("/dev/root.old", Root_RAM0);
33028 + /* mount initrd on rootfs' /root */
33029 + mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
33030 +- sys_mkdir("/old", 0700);
33031 +- root_fd = sys_open("/", 0, 0);
33032 +- old_fd = sys_open("/old", 0, 0);
33033 ++ sys_mkdir((const char __user *)"/old", 0700);
33034 ++ root_fd = sys_open((const char __user *)"/", 0, 0);
33035 ++ old_fd = sys_open((const char __user *)"/old", 0, 0);
33036 + /* move initrd over / and chdir/chroot in initrd root */
33037 +- sys_chdir("/root");
33038 +- sys_mount(".", "/", NULL, MS_MOVE, NULL);
33039 +- sys_chroot(".");
33040 ++ sys_chdir((const char __user *)"/root");
33041 ++ sys_mount((char __user *)".", (char __user *)"/", NULL, MS_MOVE, NULL);
33042 ++ sys_chroot((const char __user *)".");
33043 +
33044 + /*
33045 + * In case that a resume from disk is carried out by linuxrc or one of
33046 +@@ -70,15 +70,15 @@ static void __init handle_initrd(void)
33047 +
33048 + /* move initrd to rootfs' /old */
33049 + sys_fchdir(old_fd);
33050 +- sys_mount("/", ".", NULL, MS_MOVE, NULL);
33051 ++ sys_mount((char __user *)"/", (char __user *)".", NULL, MS_MOVE, NULL);
33052 + /* switch root and cwd back to / of rootfs */
33053 + sys_fchdir(root_fd);
33054 +- sys_chroot(".");
33055 ++ sys_chroot((const char __user *)".");
33056 + sys_close(old_fd);
33057 + sys_close(root_fd);
33058 +
33059 + if (new_decode_dev(real_root_dev) == Root_RAM0) {
33060 +- sys_chdir("/old");
33061 ++ sys_chdir((const char __user *)"/old");
33062 + return;
33063 + }
33064 +
33065 +@@ -86,17 +86,17 @@ static void __init handle_initrd(void)
33066 + mount_root();
33067 +
33068 + printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
33069 +- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
33070 ++ error = sys_mount((char __user *)"/old", (char __user *)"/root/initrd", NULL, MS_MOVE, NULL);
33071 + if (!error)
33072 + printk("okay\n");
33073 + else {
33074 +- int fd = sys_open("/dev/root.old", O_RDWR, 0);
33075 ++ int fd = sys_open((const char __user *)"/dev/root.old", O_RDWR, 0);
33076 + if (error == -ENOENT)
33077 + printk("/initrd does not exist. Ignored.\n");
33078 + else
33079 + printk("failed\n");
33080 + printk(KERN_NOTICE "Unmounting old root\n");
33081 +- sys_umount("/old", MNT_DETACH);
33082 ++ sys_umount((char __user *)"/old", MNT_DETACH);
33083 + printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
33084 + if (fd < 0) {
33085 + error = fd;
33086 +@@ -119,11 +119,11 @@ int __init initrd_load(void)
33087 + * mounted in the normal path.
33088 + */
33089 + if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
33090 +- sys_unlink("/initrd.image");
33091 ++ sys_unlink((const char __user *)"/initrd.image");
33092 + handle_initrd();
33093 + return 1;
33094 + }
33095 + }
33096 +- sys_unlink("/initrd.image");
33097 ++ sys_unlink((const char __user *)"/initrd.image");
33098 + return 0;
33099 + }
33100 +diff -urNp linux-2.6.28/init/do_mounts_md.c linux-2.6.28/init/do_mounts_md.c
33101 +--- linux-2.6.28/init/do_mounts_md.c 2008-12-24 18:26:37.000000000 -0500
33102 ++++ linux-2.6.28/init/do_mounts_md.c 2009-01-11 07:20:06.000000000 -0500
33103 +@@ -171,7 +171,7 @@ static void __init md_setup_drive(void)
33104 + partitioned ? "_d" : "", minor,
33105 + md_setup_args[ent].device_names);
33106 +
33107 +- fd = sys_open(name, 0, 0);
33108 ++ fd = sys_open((char __user *)name, 0, 0);
33109 + if (fd < 0) {
33110 + printk(KERN_ERR "md: open failed - cannot start "
33111 + "array %s\n", name);
33112 +@@ -234,7 +234,7 @@ static void __init md_setup_drive(void)
33113 + * array without it
33114 + */
33115 + sys_close(fd);
33116 +- fd = sys_open(name, 0, 0);
33117 ++ fd = sys_open((char __user *)name, 0, 0);
33118 + sys_ioctl(fd, BLKRRPART, 0);
33119 + }
33120 + sys_close(fd);
33121 +@@ -283,7 +283,7 @@ static void autodetect_raid(void)
33122 + printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
33123 + while (driver_probe_done() < 0)
33124 + msleep(100);
33125 +- fd = sys_open("/dev/md0", 0, 0);
33126 ++ fd = sys_open((char __user *)"/dev/md0", 0, 0);
33127 + if (fd >= 0) {
33128 + sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
33129 + sys_close(fd);
33130 +diff -urNp linux-2.6.28/init/initramfs.c linux-2.6.28/init/initramfs.c
33131 +--- linux-2.6.28/init/initramfs.c 2008-12-24 18:26:37.000000000 -0500
33132 ++++ linux-2.6.28/init/initramfs.c 2009-01-11 07:20:06.000000000 -0500
33133 +@@ -276,7 +276,7 @@ static int __init maybe_link(void)
33134 + if (nlink >= 2) {
33135 + char *old = find_link(major, minor, ino, mode, collected);
33136 + if (old)
33137 +- return (sys_link(old, collected) < 0) ? -1 : 1;
33138 ++ return (sys_link((char __user *)old, (char __user *)collected) < 0) ? -1 : 1;
33139 + }
33140 + return 0;
33141 + }
33142 +@@ -285,11 +285,11 @@ static void __init clean_path(char *path
33143 + {
33144 + struct stat st;
33145 +
33146 +- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
33147 ++ if (!sys_newlstat((char __user *)path, (struct stat __user *)&st) && (st.st_mode^mode) & S_IFMT) {
33148 + if (S_ISDIR(st.st_mode))
33149 +- sys_rmdir(path);
33150 ++ sys_rmdir((char __user *)path);
33151 + else
33152 +- sys_unlink(path);
33153 ++ sys_unlink((char __user *)path);
33154 + }
33155 + }
33156 +
33157 +@@ -312,7 +312,7 @@ static int __init do_name(void)
33158 + int openflags = O_WRONLY|O_CREAT;
33159 + if (ml != 1)
33160 + openflags |= O_TRUNC;
33161 +- wfd = sys_open(collected, openflags, mode);
33162 ++ wfd = sys_open((char __user *)collected, openflags, mode);
33163 +
33164 + if (wfd >= 0) {
33165 + sys_fchown(wfd, uid, gid);
33166 +@@ -322,16 +322,16 @@ static int __init do_name(void)
33167 + }
33168 + }
33169 + } else if (S_ISDIR(mode)) {
33170 +- sys_mkdir(collected, mode);
33171 +- sys_chown(collected, uid, gid);
33172 +- sys_chmod(collected, mode);
33173 ++ sys_mkdir((char __user *)collected, mode);
33174 ++ sys_chown((char __user *)collected, uid, gid);
33175 ++ sys_chmod((char __user *)collected, mode);
33176 + dir_add(collected, mtime);
33177 + } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
33178 + S_ISFIFO(mode) || S_ISSOCK(mode)) {
33179 + if (maybe_link() == 0) {
33180 +- sys_mknod(collected, mode, rdev);
33181 +- sys_chown(collected, uid, gid);
33182 +- sys_chmod(collected, mode);
33183 ++ sys_mknod((char __user *)collected, mode, rdev);
33184 ++ sys_chown((char __user *)collected, uid, gid);
33185 ++ sys_chmod((char __user *)collected, mode);
33186 + do_utime(collected, mtime);
33187 + }
33188 + }
33189 +@@ -341,7 +341,7 @@ static int __init do_name(void)
33190 + static int __init do_copy(void)
33191 + {
33192 + if (count >= body_len) {
33193 +- sys_write(wfd, victim, body_len);
33194 ++ sys_write(wfd, (char __user *)victim, body_len);
33195 + sys_close(wfd);
33196 + do_utime(vcollected, mtime);
33197 + kfree(vcollected);
33198 +@@ -349,7 +349,7 @@ static int __init do_copy(void)
33199 + state = SkipIt;
33200 + return 0;
33201 + } else {
33202 +- sys_write(wfd, victim, count);
33203 ++ sys_write(wfd, (char __user *)victim, count);
33204 + body_len -= count;
33205 + eat(count);
33206 + return 1;
33207 +@@ -360,8 +360,8 @@ static int __init do_symlink(void)
33208 + {
33209 + collected[N_ALIGN(name_len) + body_len] = '\0';
33210 + clean_path(collected, 0);
33211 +- sys_symlink(collected + N_ALIGN(name_len), collected);
33212 +- sys_lchown(collected, uid, gid);
33213 ++ sys_symlink((char __user *)collected + N_ALIGN(name_len), (char __user *)collected);
33214 ++ sys_lchown((char __user *)collected, uid, gid);
33215 + do_utime(collected, mtime);
33216 + state = SkipIt;
33217 + next_state = Reset;
33218 +diff -urNp linux-2.6.28/init/Kconfig linux-2.6.28/init/Kconfig
33219 +--- linux-2.6.28/init/Kconfig 2008-12-24 18:26:37.000000000 -0500
33220 ++++ linux-2.6.28/init/Kconfig 2009-01-11 05:47:05.000000000 -0500
33221 +@@ -572,6 +572,7 @@ config SYSCTL_SYSCALL
33222 + config KALLSYMS
33223 + bool "Load all symbols for debugging/ksymoops" if EMBEDDED
33224 + default y
33225 ++ depends on !GRKERNSEC_HIDESYM
33226 + help
33227 + Say Y here to let the kernel print out symbolic crash information and
33228 + symbolic stack backtraces. This increases the size of the kernel
33229 +@@ -822,9 +823,9 @@ config HAVE_GENERIC_DMA_COHERENT
33230 +
33231 + config SLABINFO
33232 + bool
33233 +- depends on PROC_FS
33234 ++ depends on PROC_FS && !GRKERNSEC_PROC_ADD
33235 + depends on SLAB || SLUB_DEBUG
33236 +- default y
33237 ++ default n
33238 +
33239 + config RT_MUTEXES
33240 + boolean
33241 +diff -urNp linux-2.6.28/init/main.c linux-2.6.28/init/main.c
33242 +--- linux-2.6.28/init/main.c 2008-12-24 18:26:37.000000000 -0500
33243 ++++ linux-2.6.28/init/main.c 2009-01-11 07:20:06.000000000 -0500
33244 +@@ -104,6 +104,7 @@ static inline void mark_rodata_ro(void)
33245 + #ifdef CONFIG_TC
33246 + extern void tc_init(void);
33247 + #endif
33248 ++extern void grsecurity_init(void);
33249 +
33250 + enum system_states system_state;
33251 + EXPORT_SYMBOL(system_state);
33252 +@@ -190,6 +191,40 @@ static int __init set_reset_devices(char
33253 +
33254 + __setup("reset_devices", set_reset_devices);
33255 +
33256 ++#if defined(CONFIG_PAX_MEMORY_UDEREF) && defined(CONFIG_X86_32)
33257 ++static int __init setup_pax_nouderef(char *str)
33258 ++{
33259 ++ unsigned int cpu;
33260 ++
33261 ++#ifdef CONFIG_PAX_KERNEXEC
33262 ++ unsigned long cr0;
33263 ++
33264 ++ pax_open_kernel(cr0);
33265 ++#endif
33266 ++
33267 ++ for (cpu = 0; cpu < NR_CPUS; cpu++)
33268 ++ get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_DS].b = 0x00cf9300;
33269 ++
33270 ++#ifdef CONFIG_PAX_KERNEXEC
33271 ++ pax_close_kernel(cr0);
33272 ++#endif
33273 ++
33274 ++ return 1;
33275 ++}
33276 ++__setup("pax_nouderef", setup_pax_nouderef);
33277 ++#endif
33278 ++
33279 ++#ifdef CONFIG_PAX_SOFTMODE
33280 ++unsigned int pax_softmode;
33281 ++
33282 ++static int __init setup_pax_softmode(char *str)
33283 ++{
33284 ++ get_option(&str, &pax_softmode);
33285 ++ return 1;
33286 ++}
33287 ++__setup("pax_softmode=", setup_pax_softmode);
33288 ++#endif
33289 ++
33290 + static char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
33291 + char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
33292 + static const char *panic_later, *panic_param;
33293 +@@ -388,7 +423,7 @@ static void __init setup_nr_cpu_ids(void
33294 + }
33295 +
33296 + #ifndef CONFIG_HAVE_SETUP_PER_CPU_AREA
33297 +-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
33298 ++unsigned long __per_cpu_offset[NR_CPUS] __read_only;
33299 +
33300 + EXPORT_SYMBOL(__per_cpu_offset);
33301 +
33302 +@@ -704,6 +739,7 @@ int do_one_initcall(initcall_t fn)
33303 + {
33304 + int count = preempt_count();
33305 + ktime_t delta;
33306 ++ const char *msg1 = "", *msg2 = "";
33307 + char msgbuf[64];
33308 + struct boot_trace it;
33309 +
33310 +@@ -730,15 +766,15 @@ int do_one_initcall(initcall_t fn)
33311 + sprintf(msgbuf, "error code %d ", it.result);
33312 +
33313 + if (preempt_count() != count) {
33314 +- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
33315 ++ msg1 = " preemption imbalance";
33316 + preempt_count() = count;
33317 + }
33318 + if (irqs_disabled()) {
33319 +- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
33320 ++ msg2 = " disabled interrupts";
33321 + local_irq_enable();
33322 + }
33323 +- if (msgbuf[0]) {
33324 +- printk("initcall %pF returned with %s\n", fn, msgbuf);
33325 ++ if (msgbuf[0] || *msg1 || *msg2) {
33326 ++ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
33327 + }
33328 +
33329 + return it.result;
33330 +@@ -877,6 +913,8 @@ static int __init kernel_init(void * unu
33331 + prepare_namespace();
33332 + }
33333 +
33334 ++ grsecurity_init();
33335 ++
33336 + /*
33337 + * Ok, we have completed the initial bootup, and
33338 + * we're essentially up and running. Get rid of the
33339 +diff -urNp linux-2.6.28/init/noinitramfs.c linux-2.6.28/init/noinitramfs.c
33340 +--- linux-2.6.28/init/noinitramfs.c 2008-12-24 18:26:37.000000000 -0500
33341 ++++ linux-2.6.28/init/noinitramfs.c 2009-01-11 07:20:06.000000000 -0500
33342 +@@ -29,7 +29,7 @@ static int __init default_rootfs(void)
33343 + {
33344 + int err;
33345 +
33346 +- err = sys_mkdir("/dev", 0755);
33347 ++ err = sys_mkdir((const char __user *)"/dev", 0755);
33348 + if (err < 0)
33349 + goto out;
33350 +
33351 +@@ -39,7 +39,7 @@ static int __init default_rootfs(void)
33352 + if (err < 0)
33353 + goto out;
33354 +
33355 +- err = sys_mkdir("/root", 0700);
33356 ++ err = sys_mkdir((const char __user *)"/root", 0700);
33357 + if (err < 0)
33358 + goto out;
33359 +
33360 +diff -urNp linux-2.6.28/ipc/ipc_sysctl.c linux-2.6.28/ipc/ipc_sysctl.c
33361 +--- linux-2.6.28/ipc/ipc_sysctl.c 2008-12-24 18:26:37.000000000 -0500
33362 ++++ linux-2.6.28/ipc/ipc_sysctl.c 2009-01-11 07:20:06.000000000 -0500
33363 +@@ -267,7 +267,7 @@ static struct ctl_table ipc_kern_table[]
33364 + .extra1 = &zero,
33365 + .extra2 = &one,
33366 + },
33367 +- {}
33368 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33369 + };
33370 +
33371 + static struct ctl_table ipc_root_table[] = {
33372 +@@ -277,7 +277,7 @@ static struct ctl_table ipc_root_table[]
33373 + .mode = 0555,
33374 + .child = ipc_kern_table,
33375 + },
33376 +- {}
33377 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
33378 + };
33379 +
33380 + static int __init ipc_sysctl_init(void)
33381 +diff -urNp linux-2.6.28/ipc/msg.c linux-2.6.28/ipc/msg.c
33382 +--- linux-2.6.28/ipc/msg.c 2008-12-24 18:26:37.000000000 -0500
33383 ++++ linux-2.6.28/ipc/msg.c 2009-01-11 05:47:05.000000000 -0500
33384 +@@ -38,6 +38,7 @@
33385 + #include <linux/rwsem.h>
33386 + #include <linux/nsproxy.h>
33387 + #include <linux/ipc_namespace.h>
33388 ++#include <linux/grsecurity.h>
33389 +
33390 + #include <asm/current.h>
33391 + #include <asm/uaccess.h>
33392 +@@ -314,6 +315,7 @@ asmlinkage long sys_msgget(key_t key, in
33393 + struct ipc_namespace *ns;
33394 + struct ipc_ops msg_ops;
33395 + struct ipc_params msg_params;
33396 ++ long err;
33397 +
33398 + ns = current->nsproxy->ipc_ns;
33399 +
33400 +@@ -324,7 +326,11 @@ asmlinkage long sys_msgget(key_t key, in
33401 + msg_params.key = key;
33402 + msg_params.flg = msgflg;
33403 +
33404 +- return ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
33405 ++ err = ipcget(ns, &msg_ids(ns), &msg_ops, &msg_params);
33406 ++
33407 ++ gr_log_msgget(err, msgflg);
33408 ++
33409 ++ return err;
33410 + }
33411 +
33412 + static inline unsigned long
33413 +@@ -434,6 +440,7 @@ static int msgctl_down(struct ipc_namesp
33414 +
33415 + switch (cmd) {
33416 + case IPC_RMID:
33417 ++ gr_log_msgrm(ipcp->uid, ipcp->cuid);
33418 + freeque(ns, ipcp);
33419 + goto out_up;
33420 + case IPC_SET:
33421 +diff -urNp linux-2.6.28/ipc/sem.c linux-2.6.28/ipc/sem.c
33422 +--- linux-2.6.28/ipc/sem.c 2008-12-24 18:26:37.000000000 -0500
33423 ++++ linux-2.6.28/ipc/sem.c 2009-01-11 05:47:05.000000000 -0500
33424 +@@ -83,6 +83,7 @@
33425 + #include <linux/rwsem.h>
33426 + #include <linux/nsproxy.h>
33427 + #include <linux/ipc_namespace.h>
33428 ++#include <linux/grsecurity.h>
33429 +
33430 + #include <asm/uaccess.h>
33431 + #include "util.h"
33432 +@@ -313,6 +314,7 @@ asmlinkage long sys_semget(key_t key, in
33433 + struct ipc_namespace *ns;
33434 + struct ipc_ops sem_ops;
33435 + struct ipc_params sem_params;
33436 ++ long err;
33437 +
33438 + ns = current->nsproxy->ipc_ns;
33439 +
33440 +@@ -327,7 +329,11 @@ asmlinkage long sys_semget(key_t key, in
33441 + sem_params.flg = semflg;
33442 + sem_params.u.nsems = nsems;
33443 +
33444 +- return ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
33445 ++ err = ipcget(ns, &sem_ids(ns), &sem_ops, &sem_params);
33446 ++
33447 ++ gr_log_semget(err, semflg);
33448 ++
33449 ++ return err;
33450 + }
33451 +
33452 + /*
33453 +@@ -870,6 +876,7 @@ static int semctl_down(struct ipc_namesp
33454 +
33455 + switch(cmd){
33456 + case IPC_RMID:
33457 ++ gr_log_semrm(ipcp->uid, ipcp->cuid);
33458 + freeary(ns, ipcp);
33459 + goto out_up;
33460 + case IPC_SET:
33461 +diff -urNp linux-2.6.28/ipc/shm.c linux-2.6.28/ipc/shm.c
33462 +--- linux-2.6.28/ipc/shm.c 2008-12-24 18:26:37.000000000 -0500
33463 ++++ linux-2.6.28/ipc/shm.c 2009-01-11 05:47:05.000000000 -0500
33464 +@@ -39,6 +39,7 @@
33465 + #include <linux/nsproxy.h>
33466 + #include <linux/mount.h>
33467 + #include <linux/ipc_namespace.h>
33468 ++#include <linux/grsecurity.h>
33469 +
33470 + #include <asm/uaccess.h>
33471 +
33472 +@@ -69,6 +70,14 @@ static void shm_destroy (struct ipc_name
33473 + static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
33474 + #endif
33475 +
33476 ++#ifdef CONFIG_GRKERNSEC
33477 ++extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
33478 ++ const time_t shm_createtime, const uid_t cuid,
33479 ++ const int shmid);
33480 ++extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
33481 ++ const time_t shm_createtime);
33482 ++#endif
33483 ++
33484 + void shm_init_ns(struct ipc_namespace *ns)
33485 + {
33486 + ns->shm_ctlmax = SHMMAX;
33487 +@@ -87,6 +96,8 @@ static void do_shm_rmid(struct ipc_names
33488 + struct shmid_kernel *shp;
33489 + shp = container_of(ipcp, struct shmid_kernel, shm_perm);
33490 +
33491 ++ gr_log_shmrm(shp->shm_perm.uid, shp->shm_perm.cuid);
33492 ++
33493 + if (shp->shm_nattch){
33494 + shp->shm_perm.mode |= SHM_DEST;
33495 + /* Do not find it any more */
33496 +@@ -392,6 +403,14 @@ static int newseg(struct ipc_namespace *
33497 + shp->shm_lprid = 0;
33498 + shp->shm_atim = shp->shm_dtim = 0;
33499 + shp->shm_ctim = get_seconds();
33500 ++#ifdef CONFIG_GRKERNSEC
33501 ++ {
33502 ++ struct timespec timeval;
33503 ++ do_posix_clock_monotonic_gettime(&timeval);
33504 ++
33505 ++ shp->shm_createtime = timeval.tv_sec;
33506 ++ }
33507 ++#endif
33508 + shp->shm_segsz = size;
33509 + shp->shm_nattch = 0;
33510 + shp->shm_file = file;
33511 +@@ -445,6 +464,7 @@ asmlinkage long sys_shmget (key_t key, s
33512 + struct ipc_namespace *ns;
33513 + struct ipc_ops shm_ops;
33514 + struct ipc_params shm_params;
33515 ++ long err;
33516 +
33517 + ns = current->nsproxy->ipc_ns;
33518 +
33519 +@@ -456,7 +476,11 @@ asmlinkage long sys_shmget (key_t key, s
33520 + shm_params.flg = shmflg;
33521 + shm_params.u.size = size;
33522 +
33523 +- return ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
33524 ++ err = ipcget(ns, &shm_ids(ns), &shm_ops, &shm_params);
33525 ++
33526 ++ gr_log_shmget(err, shmflg, size);
33527 ++
33528 ++ return err;
33529 + }
33530 +
33531 + static inline unsigned long copy_shmid_to_user(void __user *buf, struct shmid64_ds *in, int version)
33532 +@@ -873,9 +897,21 @@ long do_shmat(int shmid, char __user *sh
33533 + if (err)
33534 + goto out_unlock;
33535 +
33536 ++#ifdef CONFIG_GRKERNSEC
33537 ++ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
33538 ++ shp->shm_perm.cuid, shmid) ||
33539 ++ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
33540 ++ err = -EACCES;
33541 ++ goto out_unlock;
33542 ++ }
33543 ++#endif
33544 ++
33545 + path.dentry = dget(shp->shm_file->f_path.dentry);
33546 + path.mnt = shp->shm_file->f_path.mnt;
33547 + shp->shm_nattch++;
33548 ++#ifdef CONFIG_GRKERNSEC
33549 ++ shp->shm_lapid = current->pid;
33550 ++#endif
33551 + size = i_size_read(path.dentry->d_inode);
33552 + shm_unlock(shp);
33553 +
33554 +diff -urNp linux-2.6.28/kernel/acct.c linux-2.6.28/kernel/acct.c
33555 +--- linux-2.6.28/kernel/acct.c 2008-12-24 18:26:37.000000000 -0500
33556 ++++ linux-2.6.28/kernel/acct.c 2009-01-11 07:20:06.000000000 -0500
33557 +@@ -573,7 +573,7 @@ static void do_acct_process(struct bsd_a
33558 + */
33559 + flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
33560 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
33561 +- file->f_op->write(file, (char *)&ac,
33562 ++ file->f_op->write(file, (char __user *)&ac,
33563 + sizeof(acct_t), &file->f_pos);
33564 + current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
33565 + set_fs(fs);
33566 +diff -urNp linux-2.6.28/kernel/capability.c linux-2.6.28/kernel/capability.c
33567 +--- linux-2.6.28/kernel/capability.c 2008-12-24 18:26:37.000000000 -0500
33568 ++++ linux-2.6.28/kernel/capability.c 2009-01-11 05:47:05.000000000 -0500
33569 +@@ -13,6 +13,7 @@
33570 + #include <linux/security.h>
33571 + #include <linux/syscalls.h>
33572 + #include <linux/pid_namespace.h>
33573 ++#include <linux/grsecurity.h>
33574 + #include <asm/uaccess.h>
33575 +
33576 + /*
33577 +@@ -498,10 +499,21 @@ asmlinkage long sys_capset(cap_user_head
33578 + */
33579 + int capable(int cap)
33580 + {
33581 +- if (has_capability(current, cap)) {
33582 ++ if (has_capability(current, cap) && gr_task_is_capable(current, cap)) {
33583 + current->flags |= PF_SUPERPRIV;
33584 + return 1;
33585 + }
33586 + return 0;
33587 + }
33588 ++
33589 ++int capable_nolog(int cap)
33590 ++{
33591 ++ if (has_capability(current, cap) && gr_is_capable_nolog(cap)) {
33592 ++ current->flags |= PF_SUPERPRIV;
33593 ++ return 1;
33594 ++ }
33595 ++ return 0;
33596 ++}
33597 ++
33598 + EXPORT_SYMBOL(capable);
33599 ++EXPORT_SYMBOL(capable_nolog);
33600 +diff -urNp linux-2.6.28/kernel/configs.c linux-2.6.28/kernel/configs.c
33601 +--- linux-2.6.28/kernel/configs.c 2008-12-24 18:26:37.000000000 -0500
33602 ++++ linux-2.6.28/kernel/configs.c 2009-01-11 05:47:05.000000000 -0500
33603 +@@ -73,8 +73,19 @@ static int __init ikconfig_init(void)
33604 + struct proc_dir_entry *entry;
33605 +
33606 + /* create the current config file */
33607 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
33608 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
33609 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
33610 ++ &ikconfig_file_ops);
33611 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33612 ++ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
33613 ++ &ikconfig_file_ops);
33614 ++#endif
33615 ++#else
33616 + entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
33617 + &ikconfig_file_ops);
33618 ++#endif
33619 ++
33620 + if (!entry)
33621 + return -ENOMEM;
33622 +
33623 +diff -urNp linux-2.6.28/kernel/cpu.c linux-2.6.28/kernel/cpu.c
33624 +--- linux-2.6.28/kernel/cpu.c 2008-12-24 18:26:37.000000000 -0500
33625 ++++ linux-2.6.28/kernel/cpu.c 2009-01-11 07:20:06.000000000 -0500
33626 +@@ -40,7 +40,7 @@ EXPORT_SYMBOL(cpu_possible_map);
33627 + /* Serializes the updates to cpu_online_map, cpu_present_map */
33628 + static DEFINE_MUTEX(cpu_add_remove_lock);
33629 +
33630 +-static __cpuinitdata RAW_NOTIFIER_HEAD(cpu_chain);
33631 ++static RAW_NOTIFIER_HEAD(cpu_chain);
33632 +
33633 + /* If set, cpu_up and cpu_down will return -EBUSY and do nothing.
33634 + * Should always be manipulated under cpu_add_remove_lock
33635 +diff -urNp linux-2.6.28/kernel/exit.c linux-2.6.28/kernel/exit.c
33636 +--- linux-2.6.28/kernel/exit.c 2008-12-24 18:26:37.000000000 -0500
33637 ++++ linux-2.6.28/kernel/exit.c 2009-01-11 07:20:06.000000000 -0500
33638 +@@ -46,6 +46,12 @@
33639 + #include <linux/blkdev.h>
33640 + #include <linux/task_io_accounting_ops.h>
33641 + #include <linux/tracehook.h>
33642 ++#include <linux/grsecurity.h>
33643 ++
33644 ++#ifdef CONFIG_GRKERNSEC
33645 ++extern rwlock_t grsec_exec_file_lock;
33646 ++#endif
33647 ++
33648 + #include <trace/sched.h>
33649 +
33650 + #include <asm/uaccess.h>
33651 +@@ -130,7 +136,6 @@ static void __exit_signal(struct task_st
33652 + * doing sigqueue_free() if we have SIGQUEUE_PREALLOC signals.
33653 + */
33654 + flush_sigqueue(&tsk->pending);
33655 +-
33656 + tsk->signal = NULL;
33657 + tsk->sighand = NULL;
33658 + spin_unlock(&sighand->siglock);
33659 +@@ -163,6 +168,8 @@ void release_task(struct task_struct * p
33660 + struct task_struct *leader;
33661 + int zap_leader;
33662 + repeat:
33663 ++ gr_del_task_from_ip_table(p);
33664 ++
33665 + tracehook_prepare_release_task(p);
33666 + atomic_dec(&p->user->processes);
33667 + proc_flush_task(p);
33668 +@@ -326,11 +333,22 @@ static void reparent_to_kthreadd(void)
33669 + {
33670 + write_lock_irq(&tasklist_lock);
33671 +
33672 ++#ifdef CONFIG_GRKERNSEC
33673 ++ write_lock(&grsec_exec_file_lock);
33674 ++ if (current->exec_file) {
33675 ++ fput(current->exec_file);
33676 ++ current->exec_file = NULL;
33677 ++ }
33678 ++ write_unlock(&grsec_exec_file_lock);
33679 ++#endif
33680 ++
33681 + ptrace_unlink(current);
33682 + /* Reparent to init */
33683 + current->real_parent = current->parent = kthreadd_task;
33684 + list_move_tail(&current->sibling, &current->real_parent->children);
33685 +
33686 ++ gr_set_kernel_label(current);
33687 ++
33688 + /* Set the exit signal to SIGCHLD so we signal init on exit */
33689 + current->exit_signal = SIGCHLD;
33690 +
33691 +@@ -424,6 +442,17 @@ void daemonize(const char *name, ...)
33692 + vsnprintf(current->comm, sizeof(current->comm), name, args);
33693 + va_end(args);
33694 +
33695 ++#ifdef CONFIG_GRKERNSEC
33696 ++ write_lock(&grsec_exec_file_lock);
33697 ++ if (current->exec_file) {
33698 ++ fput(current->exec_file);
33699 ++ current->exec_file = NULL;
33700 ++ }
33701 ++ write_unlock(&grsec_exec_file_lock);
33702 ++#endif
33703 ++
33704 ++ gr_set_kernel_label(current);
33705 ++
33706 + /*
33707 + * If we were started as result of loading a module, close all of the
33708 + * user space pages. We don't need them, and if we didn't close them
33709 +@@ -1066,6 +1095,9 @@ NORET_TYPE void do_exit(long code)
33710 + tsk->exit_code = code;
33711 + taskstats_exit(tsk, group_dead);
33712 +
33713 ++ gr_acl_handle_psacct(tsk, code);
33714 ++ gr_acl_handle_exit();
33715 ++
33716 + exit_mm(tsk);
33717 +
33718 + if (group_dead)
33719 +@@ -1270,7 +1302,7 @@ static int wait_task_zombie(struct task_
33720 + if (unlikely(options & WNOWAIT)) {
33721 + uid_t uid = p->uid;
33722 + int exit_code = p->exit_code;
33723 +- int why, status;
33724 ++ int why;
33725 +
33726 + get_task_struct(p);
33727 + read_unlock(&tasklist_lock);
33728 +diff -urNp linux-2.6.28/kernel/fork.c linux-2.6.28/kernel/fork.c
33729 +--- linux-2.6.28/kernel/fork.c 2008-12-24 18:26:37.000000000 -0500
33730 ++++ linux-2.6.28/kernel/fork.c 2009-01-11 07:20:06.000000000 -0500
33731 +@@ -59,6 +59,7 @@
33732 + #include <linux/tty.h>
33733 + #include <linux/proc_fs.h>
33734 + #include <linux/blkdev.h>
33735 ++#include <linux/grsecurity.h>
33736 + #include <trace/sched.h>
33737 +
33738 + #include <asm/pgtable.h>
33739 +@@ -236,7 +237,7 @@ static struct task_struct *dup_task_stru
33740 + setup_thread_stack(tsk, orig);
33741 +
33742 + #ifdef CONFIG_CC_STACKPROTECTOR
33743 +- tsk->stack_canary = get_random_int();
33744 ++ tsk->stack_canary = pax_get_random_long();
33745 + #endif
33746 +
33747 + /* One for us, one for whoever does the "release_task()" (usually parent) */
33748 +@@ -273,8 +274,8 @@ static int dup_mmap(struct mm_struct *mm
33749 + mm->locked_vm = 0;
33750 + mm->mmap = NULL;
33751 + mm->mmap_cache = NULL;
33752 +- mm->free_area_cache = oldmm->mmap_base;
33753 +- mm->cached_hole_size = ~0UL;
33754 ++ mm->free_area_cache = oldmm->free_area_cache;
33755 ++ mm->cached_hole_size = oldmm->cached_hole_size;
33756 + mm->map_count = 0;
33757 + cpus_clear(mm->cpu_vm_mask);
33758 + mm->mm_rb = RB_ROOT;
33759 +@@ -311,6 +312,7 @@ static int dup_mmap(struct mm_struct *mm
33760 + tmp->vm_flags &= ~VM_LOCKED;
33761 + tmp->vm_mm = mm;
33762 + tmp->vm_next = NULL;
33763 ++ tmp->vm_mirror = NULL;
33764 + anon_vma_link(tmp);
33765 + file = tmp->vm_file;
33766 + if (file) {
33767 +@@ -358,6 +360,31 @@ static int dup_mmap(struct mm_struct *mm
33768 + if (retval)
33769 + goto out;
33770 + }
33771 ++
33772 ++#ifdef CONFIG_PAX_SEGMEXEC
33773 ++ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
33774 ++ struct vm_area_struct *mpnt_m;
33775 ++
33776 ++ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
33777 ++ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
33778 ++
33779 ++ if (!mpnt->vm_mirror)
33780 ++ continue;
33781 ++
33782 ++ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
33783 ++ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
33784 ++ mpnt->vm_mirror = mpnt_m;
33785 ++ } else {
33786 ++ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
33787 ++ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
33788 ++ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
33789 ++ mpnt->vm_mirror->vm_mirror = mpnt;
33790 ++ }
33791 ++ }
33792 ++ BUG_ON(mpnt_m);
33793 ++ }
33794 ++#endif
33795 ++
33796 + /* a new mm has just been created */
33797 + arch_dup_mmap(oldmm, mm);
33798 + retval = 0;
33799 +@@ -527,9 +554,11 @@ void mm_release(struct task_struct *tsk,
33800 + #ifdef CONFIG_FUTEX
33801 + if (unlikely(tsk->robust_list))
33802 + exit_robust_list(tsk);
33803 ++ tsk->robust_list = NULL;
33804 + #ifdef CONFIG_COMPAT
33805 + if (unlikely(tsk->compat_robust_list))
33806 + compat_exit_robust_list(tsk);
33807 ++ tsk->compat_robust_list = NULL;
33808 + #endif
33809 + #endif
33810 +
33811 +@@ -551,7 +580,7 @@ void mm_release(struct task_struct *tsk,
33812 + if (tsk->clear_child_tid
33813 + && !(tsk->flags & PF_SIGNALED)
33814 + && atomic_read(&mm->mm_users) > 1) {
33815 +- u32 __user * tidptr = tsk->clear_child_tid;
33816 ++ pid_t __user * tidptr = tsk->clear_child_tid;
33817 + tsk->clear_child_tid = NULL;
33818 +
33819 + /*
33820 +@@ -559,7 +588,7 @@ void mm_release(struct task_struct *tsk,
33821 + * not set up a proper pointer then tough luck.
33822 + */
33823 + put_user(0, tidptr);
33824 +- sys_futex(tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
33825 ++ sys_futex((u32 __user *)tidptr, FUTEX_WAKE, 1, NULL, NULL, 0);
33826 + }
33827 + }
33828 +
33829 +@@ -984,6 +1013,9 @@ static struct task_struct *copy_process(
33830 + DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
33831 + #endif
33832 + retval = -EAGAIN;
33833 ++
33834 ++ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->user->processes), 0);
33835 ++
33836 + if (atomic_read(&p->user->processes) >=
33837 + p->signal->rlim[RLIMIT_NPROC].rlim_cur) {
33838 + if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
33839 +@@ -1147,6 +1179,8 @@ static struct task_struct *copy_process(
33840 + goto bad_fork_free_pid;
33841 + }
33842 +
33843 ++ gr_copy_label(p);
33844 ++
33845 + p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
33846 + /*
33847 + * Clear TID on mm_release()?
33848 +@@ -1318,6 +1352,8 @@ bad_fork_cleanup_count:
33849 + bad_fork_free:
33850 + free_task(p);
33851 + fork_out:
33852 ++ gr_log_forkfail(retval);
33853 ++
33854 + return ERR_PTR(retval);
33855 + }
33856 +
33857 +@@ -1396,6 +1432,8 @@ long do_fork(unsigned long clone_flags,
33858 + if (clone_flags & CLONE_PARENT_SETTID)
33859 + put_user(nr, parent_tidptr);
33860 +
33861 ++ gr_handle_brute_check();
33862 ++
33863 + if (clone_flags & CLONE_VFORK) {
33864 + p->vfork_done = &vfork;
33865 + init_completion(&vfork);
33866 +diff -urNp linux-2.6.28/kernel/futex.c linux-2.6.28/kernel/futex.c
33867 +--- linux-2.6.28/kernel/futex.c 2008-12-24 18:26:37.000000000 -0500
33868 ++++ linux-2.6.28/kernel/futex.c 2009-01-11 07:20:06.000000000 -0500
33869 +@@ -188,6 +188,11 @@ static int get_futex_key(u32 __user *uad
33870 + struct page *page;
33871 + int err;
33872 +
33873 ++#ifdef CONFIG_PAX_SEGMEXEC
33874 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
33875 ++ return -EFAULT;
33876 ++#endif
33877 ++
33878 + /*
33879 + * The futex address must be "naturally" aligned.
33880 + */
33881 +@@ -214,8 +219,8 @@ static int get_futex_key(u32 __user *uad
33882 + * The futex is hashed differently depending on whether
33883 + * it's in a shared or private mapping. So check vma first.
33884 + */
33885 +- vma = find_extend_vma(mm, address);
33886 +- if (unlikely(!vma))
33887 ++ vma = find_vma(mm, address);
33888 ++ if (unlikely(!vma || address < vma->vm_start))
33889 + return -EFAULT;
33890 +
33891 + /*
33892 +@@ -1348,7 +1353,7 @@ static int futex_wait(u32 __user *uaddr,
33893 + struct restart_block *restart;
33894 + restart = &current_thread_info()->restart_block;
33895 + restart->fn = futex_wait_restart;
33896 +- restart->futex.uaddr = (u32 *)uaddr;
33897 ++ restart->futex.uaddr = uaddr;
33898 + restart->futex.val = val;
33899 + restart->futex.time = abs_time->tv64;
33900 + restart->futex.bitset = bitset;
33901 +@@ -1909,7 +1914,7 @@ retry:
33902 + */
33903 + static inline int fetch_robust_entry(struct robust_list __user **entry,
33904 + struct robust_list __user * __user *head,
33905 +- int *pi)
33906 ++ unsigned int *pi)
33907 + {
33908 + unsigned long uentry;
33909 +
33910 +diff -urNp linux-2.6.28/kernel/irq/handle.c linux-2.6.28/kernel/irq/handle.c
33911 +--- linux-2.6.28/kernel/irq/handle.c 2008-12-24 18:26:37.000000000 -0500
33912 ++++ linux-2.6.28/kernel/irq/handle.c 2009-01-11 07:20:06.000000000 -0500
33913 +@@ -57,7 +57,8 @@ struct irq_desc irq_desc[NR_IRQS] __cach
33914 + .depth = 1,
33915 + .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
33916 + #ifdef CONFIG_SMP
33917 +- .affinity = CPU_MASK_ALL
33918 ++ .affinity = CPU_MASK_ALL,
33919 ++ .cpu = 0,
33920 + #endif
33921 + }
33922 + };
33923 +diff -urNp linux-2.6.28/kernel/kallsyms.c linux-2.6.28/kernel/kallsyms.c
33924 +--- linux-2.6.28/kernel/kallsyms.c 2008-12-24 18:26:37.000000000 -0500
33925 ++++ linux-2.6.28/kernel/kallsyms.c 2009-01-11 07:20:06.000000000 -0500
33926 +@@ -62,6 +62,19 @@ static inline int is_kernel_text(unsigne
33927 +
33928 + static inline int is_kernel(unsigned long addr)
33929 + {
33930 ++
33931 ++#ifdef CONFIG_PAX_KERNEXEC
33932 ++
33933 ++#ifdef CONFIG_MODULES
33934 ++ if ((unsigned long)MODULES_VADDR <= ktla_ktva(addr) &&
33935 ++ ktla_ktva(addr) < (unsigned long)MODULES_END)
33936 ++ return 0;
33937 ++#endif
33938 ++
33939 ++ if (is_kernel_inittext(addr))
33940 ++ return 1;
33941 ++#endif
33942 ++
33943 + if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
33944 + return 1;
33945 + return in_gate_area_no_task(addr);
33946 +@@ -372,7 +385,6 @@ static unsigned long get_ksymbol_core(st
33947 +
33948 + static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
33949 + {
33950 +- iter->name[0] = '\0';
33951 + iter->nameoff = get_symbol_offset(new_pos);
33952 + iter->pos = new_pos;
33953 + }
33954 +@@ -456,7 +468,7 @@ static int kallsyms_open(struct inode *i
33955 + struct kallsym_iter *iter;
33956 + int ret;
33957 +
33958 +- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
33959 ++ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
33960 + if (!iter)
33961 + return -ENOMEM;
33962 + reset_iter(iter, 0);
33963 +@@ -478,7 +490,15 @@ static const struct file_operations kall
33964 +
33965 + static int __init kallsyms_init(void)
33966 + {
33967 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
33968 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
33969 ++ proc_create("kallsyms", S_IFREG | S_IRUSR, NULL, &kallsyms_operations);
33970 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
33971 ++ proc_create("kallsyms", S_IFREG | S_IRUSR | S_IRGRP, NULL, &kallsyms_operations);
33972 ++#endif
33973 ++#else
33974 + proc_create("kallsyms", 0444, NULL, &kallsyms_operations);
33975 ++#endif
33976 + return 0;
33977 + }
33978 + __initcall(kallsyms_init);
33979 +diff -urNp linux-2.6.28/kernel/kmod.c linux-2.6.28/kernel/kmod.c
33980 +--- linux-2.6.28/kernel/kmod.c 2008-12-24 18:26:37.000000000 -0500
33981 ++++ linux-2.6.28/kernel/kmod.c 2009-01-11 07:20:06.000000000 -0500
33982 +@@ -108,7 +108,7 @@ int request_module(const char *fmt, ...)
33983 + return -ENOMEM;
33984 + }
33985 +
33986 +- ret = call_usermodehelper(modprobe_path, argv, envp, 1);
33987 ++ ret = call_usermodehelper(modprobe_path, argv, envp, UMH_WAIT_PROC);
33988 + atomic_dec(&kmod_concurrent);
33989 + return ret;
33990 + }
33991 +diff -urNp linux-2.6.28/kernel/kprobes.c linux-2.6.28/kernel/kprobes.c
33992 +--- linux-2.6.28/kernel/kprobes.c 2008-12-24 18:26:37.000000000 -0500
33993 ++++ linux-2.6.28/kernel/kprobes.c 2009-01-11 07:20:06.000000000 -0500
33994 +@@ -182,7 +182,7 @@ kprobe_opcode_t __kprobes *get_insn_slot
33995 + * kernel image and loaded module images reside. This is required
33996 + * so x86_64 can correctly handle the %rip-relative fixups.
33997 + */
33998 +- kip->insns = module_alloc(PAGE_SIZE);
33999 ++ kip->insns = module_alloc_exec(PAGE_SIZE);
34000 + if (!kip->insns) {
34001 + kfree(kip);
34002 + return NULL;
34003 +@@ -214,7 +214,7 @@ static int __kprobes collect_one_slot(st
34004 + hlist_add_head(&kip->hlist,
34005 + &kprobe_insn_pages);
34006 + } else {
34007 +- module_free(NULL, kip->insns);
34008 ++ module_free_exec(NULL, kip->insns);
34009 + kfree(kip);
34010 + }
34011 + return 1;
34012 +diff -urNp linux-2.6.28/kernel/lockdep.c linux-2.6.28/kernel/lockdep.c
34013 +--- linux-2.6.28/kernel/lockdep.c 2008-12-24 18:26:37.000000000 -0500
34014 ++++ linux-2.6.28/kernel/lockdep.c 2009-01-11 07:20:06.000000000 -0500
34015 +@@ -627,6 +627,10 @@ static int static_obj(void *obj)
34016 + int i;
34017 + #endif
34018 +
34019 ++#ifdef CONFIG_PAX_KERNEXEC
34020 ++ start = (unsigned long )&_data;
34021 ++#endif
34022 ++
34023 + /*
34024 + * static variable?
34025 + */
34026 +@@ -638,9 +642,12 @@ static int static_obj(void *obj)
34027 + * percpu var?
34028 + */
34029 + for_each_possible_cpu(i) {
34030 ++#ifdef CONFIG_X86_32
34031 ++ start = per_cpu_offset(i);
34032 ++#else
34033 + start = (unsigned long) &__per_cpu_start + per_cpu_offset(i);
34034 +- end = (unsigned long) &__per_cpu_start + PERCPU_ENOUGH_ROOM
34035 +- + per_cpu_offset(i);
34036 ++#endif
34037 ++ end = start + PERCPU_ENOUGH_ROOM;
34038 +
34039 + if ((addr >= start) && (addr < end))
34040 + return 1;
34041 +diff -urNp linux-2.6.28/kernel/module.c linux-2.6.28/kernel/module.c
34042 +--- linux-2.6.28/kernel/module.c 2008-12-24 18:26:37.000000000 -0500
34043 ++++ linux-2.6.28/kernel/module.c 2009-01-11 07:20:06.000000000 -0500
34044 +@@ -47,6 +47,11 @@
34045 + #include <linux/rculist.h>
34046 + #include <asm/uaccess.h>
34047 + #include <asm/cacheflush.h>
34048 ++
34049 ++#ifdef CONFIG_PAX_KERNEXEC
34050 ++#include <asm/desc.h>
34051 ++#endif
34052 ++
34053 + #include <linux/license.h>
34054 + #include <asm/sections.h>
34055 + #include <linux/tracepoint.h>
34056 +@@ -76,7 +81,10 @@ static DECLARE_WAIT_QUEUE_HEAD(module_wq
34057 + static BLOCKING_NOTIFIER_HEAD(module_notify_list);
34058 +
34059 + /* Bounds of module allocation, for speeding __module_text_address */
34060 +-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
34061 ++static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
34062 ++static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
34063 ++
34064 ++extern int gr_check_modstop(void);
34065 +
34066 + int register_module_notifier(struct notifier_block * nb)
34067 + {
34068 +@@ -245,7 +253,7 @@ static bool each_symbol(bool (*fn)(const
34069 + return true;
34070 +
34071 + list_for_each_entry_rcu(mod, &modules, list) {
34072 +- struct symsearch arr[] = {
34073 ++ struct symsearch modarr[] = {
34074 + { mod->syms, mod->syms + mod->num_syms, mod->crcs,
34075 + NOT_GPL_ONLY, false },
34076 + { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
34077 +@@ -267,7 +275,7 @@ static bool each_symbol(bool (*fn)(const
34078 + #endif
34079 + };
34080 +
34081 +- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
34082 ++ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
34083 + return true;
34084 + }
34085 + return false;
34086 +@@ -403,6 +411,8 @@ static inline unsigned int block_size(in
34087 + return val;
34088 + }
34089 +
34090 ++EXPORT_SYMBOL(__per_cpu_start);
34091 ++
34092 + static void *percpu_modalloc(unsigned long size, unsigned long align,
34093 + const char *name)
34094 + {
34095 +@@ -410,7 +420,7 @@ static void *percpu_modalloc(unsigned lo
34096 + unsigned int i;
34097 + void *ptr;
34098 +
34099 +- if (align > PAGE_SIZE) {
34100 ++ if (align-1 >= PAGE_SIZE) {
34101 + printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
34102 + name, align, PAGE_SIZE);
34103 + align = PAGE_SIZE;
34104 +@@ -492,7 +502,11 @@ static void percpu_modcopy(void *pcpudes
34105 + int cpu;
34106 +
34107 + for_each_possible_cpu(cpu)
34108 ++#ifdef CONFIG_X86_32
34109 ++ memcpy(pcpudest + __per_cpu_offset[cpu], from, size);
34110 ++#else
34111 + memcpy(pcpudest + per_cpu_offset(cpu), from, size);
34112 ++#endif
34113 + }
34114 +
34115 + static int percpu_modinit(void)
34116 +@@ -750,6 +764,9 @@ sys_delete_module(const char __user *nam
34117 + char name[MODULE_NAME_LEN];
34118 + int ret, forced = 0;
34119 +
34120 ++ if (gr_check_modstop())
34121 ++ return -EPERM;
34122 ++
34123 + if (!capable(CAP_SYS_MODULE))
34124 + return -EPERM;
34125 +
34126 +@@ -1448,19 +1465,22 @@ static void free_module(struct module *m
34127 + module_unload_free(mod);
34128 +
34129 + /* release any pointers to mcount in this module */
34130 +- ftrace_release(mod->module_core, mod->core_size);
34131 ++ ftrace_release(mod->module_core_rx, mod->core_size_rx);
34132 +
34133 + /* This may be NULL, but that's OK */
34134 +- module_free(mod, mod->module_init);
34135 ++ module_free(mod, mod->module_init_rw);
34136 ++ module_free_exec(mod, mod->module_init_rx);
34137 + kfree(mod->args);
34138 + if (mod->percpu)
34139 + percpu_modfree(mod->percpu);
34140 +
34141 + /* Free lock-classes: */
34142 +- lockdep_free_key_range(mod->module_core, mod->core_size);
34143 ++ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
34144 ++ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
34145 +
34146 + /* Finally, free the core (containing the module structure) */
34147 +- module_free(mod, mod->module_core);
34148 ++ module_free_exec(mod, mod->module_core_rx);
34149 ++ module_free(mod, mod->module_core_rw);
34150 + }
34151 +
34152 + void *__symbol_get(const char *symbol)
34153 +@@ -1526,10 +1546,14 @@ static int simplify_symbols(Elf_Shdr *se
34154 + struct module *mod)
34155 + {
34156 + Elf_Sym *sym = (void *)sechdrs[symindex].sh_addr;
34157 +- unsigned long secbase;
34158 ++ unsigned long secbase, symbol;
34159 + unsigned int i, n = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
34160 + int ret = 0;
34161 +
34162 ++#ifdef CONFIG_PAX_KERNEXEC
34163 ++ unsigned long cr0;
34164 ++#endif
34165 ++
34166 + for (i = 1; i < n; i++) {
34167 + switch (sym[i].st_shndx) {
34168 + case SHN_COMMON:
34169 +@@ -1548,10 +1572,19 @@ static int simplify_symbols(Elf_Shdr *se
34170 + break;
34171 +
34172 + case SHN_UNDEF:
34173 +- sym[i].st_value
34174 +- = resolve_symbol(sechdrs, versindex,
34175 ++ symbol = resolve_symbol(sechdrs, versindex,
34176 + strtab + sym[i].st_name, mod);
34177 +
34178 ++#ifdef CONFIG_PAX_KERNEXEC
34179 ++ pax_open_kernel(cr0);
34180 ++#endif
34181 ++
34182 ++ sym[i].st_value = symbol;
34183 ++
34184 ++#ifdef CONFIG_PAX_KERNEXEC
34185 ++ pax_close_kernel(cr0);
34186 ++#endif
34187 ++
34188 + /* Ok if resolved. */
34189 + if (!IS_ERR_VALUE(sym[i].st_value))
34190 + break;
34191 +@@ -1566,11 +1599,27 @@ static int simplify_symbols(Elf_Shdr *se
34192 +
34193 + default:
34194 + /* Divert to percpu allocation if a percpu var. */
34195 +- if (sym[i].st_shndx == pcpuindex)
34196 ++ if (sym[i].st_shndx == pcpuindex) {
34197 ++
34198 ++#if defined(CONFIG_X86_32) && defined(CONFIG_SMP)
34199 ++ secbase = (unsigned long)mod->percpu - (unsigned long)__per_cpu_start;
34200 ++#else
34201 + secbase = (unsigned long)mod->percpu;
34202 +- else
34203 ++#endif
34204 ++
34205 ++ } else
34206 + secbase = sechdrs[sym[i].st_shndx].sh_addr;
34207 ++
34208 ++#ifdef CONFIG_PAX_KERNEXEC
34209 ++ pax_open_kernel(cr0);
34210 ++#endif
34211 ++
34212 + sym[i].st_value += secbase;
34213 ++
34214 ++#ifdef CONFIG_PAX_KERNEXEC
34215 ++ pax_close_kernel(cr0);
34216 ++#endif
34217 ++
34218 + break;
34219 + }
34220 + }
34221 +@@ -1622,11 +1671,12 @@ static void layout_sections(struct modul
34222 + || strncmp(secstrings + s->sh_name,
34223 + ".init", 5) == 0)
34224 + continue;
34225 +- s->sh_entsize = get_offset(&mod->core_size, s);
34226 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
34227 ++ s->sh_entsize = get_offset(&mod->core_size_rw, s);
34228 ++ else
34229 ++ s->sh_entsize = get_offset(&mod->core_size_rx, s);
34230 + DEBUGP("\t%s\n", secstrings + s->sh_name);
34231 + }
34232 +- if (m == 0)
34233 +- mod->core_text_size = mod->core_size;
34234 + }
34235 +
34236 + DEBUGP("Init section allocation order:\n");
34237 +@@ -1640,12 +1690,13 @@ static void layout_sections(struct modul
34238 + || strncmp(secstrings + s->sh_name,
34239 + ".init", 5) != 0)
34240 + continue;
34241 +- s->sh_entsize = (get_offset(&mod->init_size, s)
34242 +- | INIT_OFFSET_MASK);
34243 ++ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
34244 ++ s->sh_entsize = get_offset(&mod->init_size_rw, s);
34245 ++ else
34246 ++ s->sh_entsize = get_offset(&mod->init_size_rx, s);
34247 ++ s->sh_entsize |= INIT_OFFSET_MASK;
34248 + DEBUGP("\t%s\n", secstrings + s->sh_name);
34249 + }
34250 +- if (m == 0)
34251 +- mod->init_text_size = mod->init_size;
34252 + }
34253 + }
34254 +
34255 +@@ -1785,14 +1836,31 @@ static void add_kallsyms(struct module *
34256 + {
34257 + unsigned int i;
34258 +
34259 ++#ifdef CONFIG_PAX_KERNEXEC
34260 ++ unsigned long cr0;
34261 ++#endif
34262 ++
34263 + mod->symtab = (void *)sechdrs[symindex].sh_addr;
34264 + mod->num_symtab = sechdrs[symindex].sh_size / sizeof(Elf_Sym);
34265 + mod->strtab = (void *)sechdrs[strindex].sh_addr;
34266 +
34267 + /* Set types up while we still have access to sections. */
34268 +- for (i = 0; i < mod->num_symtab; i++)
34269 +- mod->symtab[i].st_info
34270 +- = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
34271 ++
34272 ++ for (i = 0; i < mod->num_symtab; i++) {
34273 ++ char type = elf_type(&mod->symtab[i], sechdrs, secstrings, mod);
34274 ++
34275 ++#ifdef CONFIG_PAX_KERNEXEC
34276 ++ pax_open_kernel(cr0);
34277 ++#endif
34278 ++
34279 ++ mod->symtab[i].st_info = type;
34280 ++
34281 ++#ifdef CONFIG_PAX_KERNEXEC
34282 ++ pax_close_kernel(cr0);
34283 ++#endif
34284 ++
34285 ++ }
34286 ++
34287 + }
34288 + #else
34289 + static inline void add_kallsyms(struct module *mod,
34290 +@@ -1819,16 +1887,30 @@ static void dynamic_printk_setup(struct
34291 + #endif /* CONFIG_DYNAMIC_PRINTK_DEBUG */
34292 + }
34293 +
34294 +-static void *module_alloc_update_bounds(unsigned long size)
34295 ++static void *module_alloc_update_bounds_rw(unsigned long size)
34296 + {
34297 + void *ret = module_alloc(size);
34298 +
34299 + if (ret) {
34300 + /* Update module bounds. */
34301 +- if ((unsigned long)ret < module_addr_min)
34302 +- module_addr_min = (unsigned long)ret;
34303 +- if ((unsigned long)ret + size > module_addr_max)
34304 +- module_addr_max = (unsigned long)ret + size;
34305 ++ if ((unsigned long)ret < module_addr_min_rw)
34306 ++ module_addr_min_rw = (unsigned long)ret;
34307 ++ if ((unsigned long)ret + size > module_addr_max_rw)
34308 ++ module_addr_max_rw = (unsigned long)ret + size;
34309 ++ }
34310 ++ return ret;
34311 ++}
34312 ++
34313 ++static void *module_alloc_update_bounds_rx(unsigned long size)
34314 ++{
34315 ++ void *ret = module_alloc_exec(size);
34316 ++
34317 ++ if (ret) {
34318 ++ /* Update module bounds. */
34319 ++ if ((unsigned long)ret < module_addr_min_rx)
34320 ++ module_addr_min_rx = (unsigned long)ret;
34321 ++ if ((unsigned long)ret + size > module_addr_max_rx)
34322 ++ module_addr_max_rx = (unsigned long)ret + size;
34323 + }
34324 + return ret;
34325 + }
34326 +@@ -1856,6 +1938,10 @@ static noinline struct module *load_modu
34327 + unsigned long *mseg;
34328 + mm_segment_t old_fs;
34329 +
34330 ++#ifdef CONFIG_PAX_KERNEXEC
34331 ++ unsigned long cr0;
34332 ++#endif
34333 ++
34334 + DEBUGP("load_module: umod=%p, len=%lu, uargs=%p\n",
34335 + umod, len, uargs);
34336 + if (len < sizeof(*hdr))
34337 +@@ -2010,22 +2096,57 @@ static noinline struct module *load_modu
34338 + layout_sections(mod, hdr, sechdrs, secstrings);
34339 +
34340 + /* Do the allocs. */
34341 +- ptr = module_alloc_update_bounds(mod->core_size);
34342 ++ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
34343 + if (!ptr) {
34344 + err = -ENOMEM;
34345 + goto free_percpu;
34346 + }
34347 +- memset(ptr, 0, mod->core_size);
34348 +- mod->module_core = ptr;
34349 ++ memset(ptr, 0, mod->core_size_rw);
34350 ++ mod->module_core_rw = ptr;
34351 +
34352 +- ptr = module_alloc_update_bounds(mod->init_size);
34353 +- if (!ptr && mod->init_size) {
34354 ++ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
34355 ++ if (!ptr && mod->init_size_rw) {
34356 + err = -ENOMEM;
34357 +- goto free_core;
34358 ++ goto free_core_rw;
34359 + }
34360 +- memset(ptr, 0, mod->init_size);
34361 +- mod->module_init = ptr;
34362 ++ memset(ptr, 0, mod->init_size_rw);
34363 ++ mod->module_init_rw = ptr;
34364 ++
34365 ++ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
34366 ++ if (!ptr) {
34367 ++ err = -ENOMEM;
34368 ++ goto free_init_rw;
34369 ++ }
34370 ++
34371 ++#ifdef CONFIG_PAX_KERNEXEC
34372 ++ pax_open_kernel(cr0);
34373 ++#endif
34374 +
34375 ++ memset(ptr, 0, mod->core_size_rx);
34376 ++
34377 ++#ifdef CONFIG_PAX_KERNEXEC
34378 ++ pax_close_kernel(cr0);
34379 ++#endif
34380 ++
34381 ++ mod->module_core_rx = ptr;
34382 ++
34383 ++ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
34384 ++ if (!ptr && mod->init_size_rx) {
34385 ++ err = -ENOMEM;
34386 ++ goto free_core_rx;
34387 ++ }
34388 ++
34389 ++#ifdef CONFIG_PAX_KERNEXEC
34390 ++ pax_open_kernel(cr0);
34391 ++#endif
34392 ++
34393 ++ memset(ptr, 0, mod->init_size_rx);
34394 ++
34395 ++#ifdef CONFIG_PAX_KERNEXEC
34396 ++ pax_close_kernel(cr0);
34397 ++#endif
34398 ++
34399 ++ mod->module_init_rx = ptr;
34400 + /* Transfer each section which specifies SHF_ALLOC */
34401 + DEBUGP("final section addresses:\n");
34402 + for (i = 0; i < hdr->e_shnum; i++) {
34403 +@@ -2034,17 +2155,41 @@ static noinline struct module *load_modu
34404 + if (!(sechdrs[i].sh_flags & SHF_ALLOC))
34405 + continue;
34406 +
34407 +- if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK)
34408 +- dest = mod->module_init
34409 +- + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
34410 +- else
34411 +- dest = mod->module_core + sechdrs[i].sh_entsize;
34412 ++ if (sechdrs[i].sh_entsize & INIT_OFFSET_MASK) {
34413 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
34414 ++ dest = mod->module_init_rw
34415 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
34416 ++ else
34417 ++ dest = mod->module_init_rx
34418 ++ + (sechdrs[i].sh_entsize & ~INIT_OFFSET_MASK);
34419 ++ } else {
34420 ++ if ((sechdrs[i].sh_flags & SHF_WRITE) || !(sechdrs[i].sh_flags & SHF_ALLOC))
34421 ++ dest = mod->module_core_rw + sechdrs[i].sh_entsize;
34422 ++ else
34423 ++ dest = mod->module_core_rx + sechdrs[i].sh_entsize;
34424 ++ }
34425 ++
34426 ++ if (sechdrs[i].sh_type != SHT_NOBITS) {
34427 +
34428 +- if (sechdrs[i].sh_type != SHT_NOBITS)
34429 +- memcpy(dest, (void *)sechdrs[i].sh_addr,
34430 +- sechdrs[i].sh_size);
34431 ++#ifdef CONFIG_PAX_KERNEXEC
34432 ++ if (!(sechdrs[i].sh_flags & SHF_WRITE) && (sechdrs[i].sh_flags & SHF_ALLOC)) {
34433 ++ pax_open_kernel(cr0);
34434 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
34435 ++ pax_close_kernel(cr0);
34436 ++ } else
34437 ++#endif
34438 ++
34439 ++ memcpy(dest, (void *)sechdrs[i].sh_addr, sechdrs[i].sh_size);
34440 ++ }
34441 + /* Update sh_addr to point to copy in image. */
34442 +- sechdrs[i].sh_addr = (unsigned long)dest;
34443 ++
34444 ++#ifdef CONFIG_PAX_KERNEXEC
34445 ++ if (sechdrs[i].sh_flags & SHF_EXECINSTR)
34446 ++ sechdrs[i].sh_addr = ktva_ktla((unsigned long)dest);
34447 ++ else
34448 ++#endif
34449 ++
34450 ++ sechdrs[i].sh_addr = (unsigned long)dest;
34451 + DEBUGP("\t0x%lx %s\n", sechdrs[i].sh_addr, secstrings + sechdrs[i].sh_name);
34452 + }
34453 + /* Module has been moved. */
34454 +@@ -2144,8 +2289,8 @@ static noinline struct module *load_modu
34455 +
34456 + /* Now do relocations. */
34457 + for (i = 1; i < hdr->e_shnum; i++) {
34458 +- const char *strtab = (char *)sechdrs[strindex].sh_addr;
34459 + unsigned int info = sechdrs[i].sh_info;
34460 ++ strtab = (char *)sechdrs[strindex].sh_addr;
34461 +
34462 + /* Not a valid relocation section? */
34463 + if (info >= hdr->e_shnum)
34464 +@@ -2216,12 +2361,12 @@ static noinline struct module *load_modu
34465 + * Do it before processing of module parameters, so the module
34466 + * can provide parameter accessor functions of its own.
34467 + */
34468 +- if (mod->module_init)
34469 +- flush_icache_range((unsigned long)mod->module_init,
34470 +- (unsigned long)mod->module_init
34471 +- + mod->init_size);
34472 +- flush_icache_range((unsigned long)mod->module_core,
34473 +- (unsigned long)mod->module_core + mod->core_size);
34474 ++ if (mod->module_init_rx)
34475 ++ flush_icache_range((unsigned long)mod->module_init_rx,
34476 ++ (unsigned long)mod->module_init_rx
34477 ++ + mod->init_size_rx);
34478 ++ flush_icache_range((unsigned long)mod->module_core_rx,
34479 ++ (unsigned long)mod->module_core_rx + mod->core_size_rx);
34480 +
34481 + set_fs(old_fs);
34482 +
34483 +@@ -2266,12 +2411,16 @@ static noinline struct module *load_modu
34484 + cleanup:
34485 + kobject_del(&mod->mkobj.kobj);
34486 + kobject_put(&mod->mkobj.kobj);
34487 +- ftrace_release(mod->module_core, mod->core_size);
34488 ++ ftrace_release(mod->module_core_rx, mod->core_size_rx);
34489 + free_unload:
34490 + module_unload_free(mod);
34491 +- module_free(mod, mod->module_init);
34492 +- free_core:
34493 +- module_free(mod, mod->module_core);
34494 ++ module_free_exec(mod, mod->module_init_rx);
34495 ++ free_core_rx:
34496 ++ module_free_exec(mod, mod->module_core_rx);
34497 ++ free_init_rw:
34498 ++ module_free(mod, mod->module_init_rw);
34499 ++ free_core_rw:
34500 ++ module_free(mod, mod->module_core_rw);
34501 + free_percpu:
34502 + if (percpu)
34503 + percpu_modfree(percpu);
34504 +@@ -2296,6 +2445,9 @@ sys_init_module(void __user *umod,
34505 + struct module *mod;
34506 + int ret = 0;
34507 +
34508 ++ if (gr_check_modstop())
34509 ++ return -EPERM;
34510 ++
34511 + /* Must have permission */
34512 + if (!capable(CAP_SYS_MODULE))
34513 + return -EPERM;
34514 +@@ -2351,10 +2503,12 @@ sys_init_module(void __user *umod,
34515 + /* Drop initial reference. */
34516 + module_put(mod);
34517 + unwind_remove_table(mod->unwind_info, 1);
34518 +- module_free(mod, mod->module_init);
34519 +- mod->module_init = NULL;
34520 +- mod->init_size = 0;
34521 +- mod->init_text_size = 0;
34522 ++ module_free(mod, mod->module_init_rw);
34523 ++ module_free_exec(mod, mod->module_init_rx);
34524 ++ mod->module_init_rw = NULL;
34525 ++ mod->module_init_rx = NULL;
34526 ++ mod->init_size_rw = 0;
34527 ++ mod->init_size_rx = 0;
34528 + mutex_unlock(&module_mutex);
34529 +
34530 + return 0;
34531 +@@ -2362,6 +2516,13 @@ sys_init_module(void __user *umod,
34532 +
34533 + static inline int within(unsigned long addr, void *start, unsigned long size)
34534 + {
34535 ++
34536 ++#ifdef CONFIG_PAX_KERNEXEC
34537 ++ if (ktla_ktva(addr) >= (unsigned long)start &&
34538 ++ ktla_ktva(addr) < (unsigned long)start + size)
34539 ++ return 1;
34540 ++#endif
34541 ++
34542 + return ((void *)addr >= start && (void *)addr < start + size);
34543 + }
34544 +
34545 +@@ -2385,10 +2546,14 @@ static const char *get_ksymbol(struct mo
34546 + unsigned long nextval;
34547 +
34548 + /* At worse, next value is at end of module */
34549 +- if (within(addr, mod->module_init, mod->init_size))
34550 +- nextval = (unsigned long)mod->module_init+mod->init_text_size;
34551 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx))
34552 ++ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
34553 ++ else if (within(addr, mod->module_init_rw, mod->init_size_rw))
34554 ++ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
34555 ++ else if (within(addr, mod->module_core_rx, mod->core_size_rx))
34556 ++ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
34557 + else
34558 +- nextval = (unsigned long)mod->module_core+mod->core_text_size;
34559 ++ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
34560 +
34561 + /* Scan for closest preceeding symbol, and next symbol. (ELF
34562 + starts real symbols at 1). */
34563 +@@ -2433,8 +2598,10 @@ const char *module_address_lookup(unsign
34564 +
34565 + preempt_disable();
34566 + list_for_each_entry_rcu(mod, &modules, list) {
34567 +- if (within(addr, mod->module_init, mod->init_size)
34568 +- || within(addr, mod->module_core, mod->core_size)) {
34569 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
34570 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
34571 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
34572 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34573 + if (modname)
34574 + *modname = mod->name;
34575 + ret = get_ksymbol(mod, addr, size, offset);
34576 +@@ -2456,8 +2623,10 @@ int lookup_module_symbol_name(unsigned l
34577 +
34578 + preempt_disable();
34579 + list_for_each_entry_rcu(mod, &modules, list) {
34580 +- if (within(addr, mod->module_init, mod->init_size) ||
34581 +- within(addr, mod->module_core, mod->core_size)) {
34582 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
34583 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
34584 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
34585 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34586 + const char *sym;
34587 +
34588 + sym = get_ksymbol(mod, addr, NULL, NULL);
34589 +@@ -2480,8 +2649,10 @@ int lookup_module_symbol_attrs(unsigned
34590 +
34591 + preempt_disable();
34592 + list_for_each_entry_rcu(mod, &modules, list) {
34593 +- if (within(addr, mod->module_init, mod->init_size) ||
34594 +- within(addr, mod->module_core, mod->core_size)) {
34595 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx) ||
34596 ++ within(addr, mod->module_init_rw, mod->init_size_rw) ||
34597 ++ within(addr, mod->module_core_rx, mod->core_size_rx) ||
34598 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34599 + const char *sym;
34600 +
34601 + sym = get_ksymbol(mod, addr, size, offset);
34602 +@@ -2615,7 +2786,7 @@ static int m_show(struct seq_file *m, vo
34603 + char buf[8];
34604 +
34605 + seq_printf(m, "%s %u",
34606 +- mod->name, mod->init_size + mod->core_size);
34607 ++ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
34608 + print_unload_info(m, mod);
34609 +
34610 + /* Informative for users. */
34611 +@@ -2624,7 +2795,7 @@ static int m_show(struct seq_file *m, vo
34612 + mod->state == MODULE_STATE_COMING ? "Loading":
34613 + "Live");
34614 + /* Used by oprofile and other similar tools. */
34615 +- seq_printf(m, " 0x%p", mod->module_core);
34616 ++ seq_printf(m, " 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
34617 +
34618 + /* Taints info */
34619 + if (mod->taints)
34620 +@@ -2700,8 +2871,8 @@ int is_module_address(unsigned long addr
34621 + preempt_disable();
34622 +
34623 + list_for_each_entry_rcu(mod, &modules, list) {
34624 +- if (within(addr, mod->module_core, mod->core_size)) {
34625 +- preempt_enable();
34626 ++ if (within(addr, mod->module_core_rx, mod->core_size_rx) ||
34627 ++ within(addr, mod->module_core_rw, mod->core_size_rw)) {
34628 + return 1;
34629 + }
34630 + }
34631 +@@ -2717,12 +2888,16 @@ struct module *__module_text_address(uns
34632 + {
34633 + struct module *mod;
34634 +
34635 +- if (addr < module_addr_min || addr > module_addr_max)
34636 ++#ifdef CONFIG_X86_32
34637 ++ addr = ktla_ktva(addr);
34638 ++#endif
34639 ++
34640 ++ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
34641 + return NULL;
34642 +
34643 + list_for_each_entry_rcu(mod, &modules, list)
34644 +- if (within(addr, mod->module_init, mod->init_text_size)
34645 +- || within(addr, mod->module_core, mod->core_text_size))
34646 ++ if (within(addr, mod->module_init_rx, mod->init_size_rx)
34647 ++ || within(addr, mod->module_core_rx, mod->core_size_rx))
34648 + return mod;
34649 + return NULL;
34650 + }
34651 +diff -urNp linux-2.6.28/kernel/mutex.c linux-2.6.28/kernel/mutex.c
34652 +--- linux-2.6.28/kernel/mutex.c 2008-12-24 18:26:37.000000000 -0500
34653 ++++ linux-2.6.28/kernel/mutex.c 2009-01-11 07:20:06.000000000 -0500
34654 +@@ -83,7 +83,7 @@ __mutex_lock_slowpath(atomic_t *lock_cou
34655 + *
34656 + * This function is similar to (but not equivalent to) down().
34657 + */
34658 +-void inline __sched mutex_lock(struct mutex *lock)
34659 ++inline void __sched mutex_lock(struct mutex *lock)
34660 + {
34661 + might_sleep();
34662 + /*
34663 +diff -urNp linux-2.6.28/kernel/panic.c linux-2.6.28/kernel/panic.c
34664 +--- linux-2.6.28/kernel/panic.c 2008-12-24 18:26:37.000000000 -0500
34665 ++++ linux-2.6.28/kernel/panic.c 2009-01-11 07:20:06.000000000 -0500
34666 +@@ -367,6 +367,8 @@ EXPORT_SYMBOL(warn_slowpath);
34667 + */
34668 + void __stack_chk_fail(void)
34669 + {
34670 ++ print_symbol("stack corrupted in: %s\n", (unsigned long)__builtin_return_address(0));
34671 ++ dump_stack();
34672 + panic("stack-protector: Kernel stack is corrupted");
34673 + }
34674 + EXPORT_SYMBOL(__stack_chk_fail);
34675 +diff -urNp linux-2.6.28/kernel/pid.c linux-2.6.28/kernel/pid.c
34676 +--- linux-2.6.28/kernel/pid.c 2008-12-24 18:26:37.000000000 -0500
34677 ++++ linux-2.6.28/kernel/pid.c 2009-01-11 07:20:06.000000000 -0500
34678 +@@ -36,6 +36,7 @@
34679 + #include <linux/pid_namespace.h>
34680 + #include <linux/init_task.h>
34681 + #include <linux/syscalls.h>
34682 ++#include <linux/grsecurity.h>
34683 +
34684 + #define pid_hashfn(nr, ns) \
34685 + hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
34686 +@@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT
34687 +
34688 + int pid_max = PID_MAX_DEFAULT;
34689 +
34690 +-#define RESERVED_PIDS 300
34691 ++#define RESERVED_PIDS 500
34692 +
34693 + int pid_max_min = RESERVED_PIDS + 1;
34694 + int pid_max_max = PID_MAX_LIMIT;
34695 +@@ -381,7 +382,14 @@ EXPORT_SYMBOL(pid_task);
34696 + struct task_struct *find_task_by_pid_type_ns(int type, int nr,
34697 + struct pid_namespace *ns)
34698 + {
34699 +- return pid_task(find_pid_ns(nr, ns), type);
34700 ++ struct task_struct *task;
34701 ++
34702 ++ task = pid_task(find_pid_ns(nr, ns), type);
34703 ++
34704 ++ if (gr_pid_is_chrooted(task))
34705 ++ return NULL;
34706 ++
34707 ++ return task;
34708 + }
34709 +
34710 + EXPORT_SYMBOL(find_task_by_pid_type_ns);
34711 +diff -urNp linux-2.6.28/kernel/posix-cpu-timers.c linux-2.6.28/kernel/posix-cpu-timers.c
34712 +--- linux-2.6.28/kernel/posix-cpu-timers.c 2008-12-24 18:26:37.000000000 -0500
34713 ++++ linux-2.6.28/kernel/posix-cpu-timers.c 2009-01-11 07:20:06.000000000 -0500
34714 +@@ -6,6 +6,7 @@
34715 + #include <linux/posix-timers.h>
34716 + #include <linux/errno.h>
34717 + #include <linux/math64.h>
34718 ++#include <linux/grsecurity.h>
34719 + #include <asm/uaccess.h>
34720 + #include <linux/kernel_stat.h>
34721 +
34722 +@@ -1157,6 +1158,7 @@ static void check_process_timers(struct
34723 + __group_send_sig_info(SIGKILL, SEND_SIG_PRIV, tsk);
34724 + return;
34725 + }
34726 ++ gr_learn_resource(tsk, RLIMIT_CPU, psecs, 1);
34727 + if (psecs >= sig->rlim[RLIMIT_CPU].rlim_cur) {
34728 + /*
34729 + * At the soft limit, send a SIGXCPU every second.
34730 +@@ -1381,17 +1383,17 @@ void run_posix_cpu_timers(struct task_st
34731 + * timer call will interfere.
34732 + */
34733 + list_for_each_entry_safe(timer, next, &firing, it.cpu.entry) {
34734 +- int firing;
34735 ++ int __firing;
34736 + spin_lock(&timer->it_lock);
34737 + list_del_init(&timer->it.cpu.entry);
34738 +- firing = timer->it.cpu.firing;
34739 ++ __firing = timer->it.cpu.firing;
34740 + timer->it.cpu.firing = 0;
34741 + /*
34742 + * The firing flag is -1 if we collided with a reset
34743 + * of the timer, which already reported this
34744 + * almost-firing as an overrun. So don't generate an event.
34745 + */
34746 +- if (likely(firing >= 0)) {
34747 ++ if (likely(__firing >= 0)) {
34748 + cpu_timer_fire(timer);
34749 + }
34750 + spin_unlock(&timer->it_lock);
34751 +diff -urNp linux-2.6.28/kernel/power/poweroff.c linux-2.6.28/kernel/power/poweroff.c
34752 +--- linux-2.6.28/kernel/power/poweroff.c 2008-12-24 18:26:37.000000000 -0500
34753 ++++ linux-2.6.28/kernel/power/poweroff.c 2009-01-11 07:20:06.000000000 -0500
34754 +@@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_powerof
34755 + .enable_mask = SYSRQ_ENABLE_BOOT,
34756 + };
34757 +
34758 +-static int pm_sysrq_init(void)
34759 ++static int __init pm_sysrq_init(void)
34760 + {
34761 + register_sysrq_key('o', &sysrq_poweroff_op);
34762 + return 0;
34763 +diff -urNp linux-2.6.28/kernel/printk.c linux-2.6.28/kernel/printk.c
34764 +--- linux-2.6.28/kernel/printk.c 2008-12-24 18:26:37.000000000 -0500
34765 ++++ linux-2.6.28/kernel/printk.c 2009-01-11 05:47:05.000000000 -0500
34766 +@@ -32,6 +32,7 @@
34767 + #include <linux/security.h>
34768 + #include <linux/bootmem.h>
34769 + #include <linux/syscalls.h>
34770 ++#include <linux/grsecurity.h>
34771 +
34772 + #include <asm/uaccess.h>
34773 +
34774 +@@ -254,6 +255,11 @@ int do_syslog(int type, char __user *buf
34775 + char c;
34776 + int error = 0;
34777 +
34778 ++#ifdef CONFIG_GRKERNSEC_DMESG
34779 ++ if (grsec_enable_dmesg && !capable(CAP_SYS_ADMIN))
34780 ++ return -EPERM;
34781 ++#endif
34782 ++
34783 + error = security_syslog(type);
34784 + if (error)
34785 + return error;
34786 +diff -urNp linux-2.6.28/kernel/ptrace.c linux-2.6.28/kernel/ptrace.c
34787 +--- linux-2.6.28/kernel/ptrace.c 2008-12-24 18:26:37.000000000 -0500
34788 ++++ linux-2.6.28/kernel/ptrace.c 2009-01-11 05:47:05.000000000 -0500
34789 +@@ -21,6 +21,7 @@
34790 + #include <linux/audit.h>
34791 + #include <linux/pid_namespace.h>
34792 + #include <linux/syscalls.h>
34793 ++#include <linux/grsecurity.h>
34794 +
34795 + #include <asm/pgtable.h>
34796 + #include <asm/uaccess.h>
34797 +@@ -132,12 +133,12 @@ int __ptrace_may_access(struct task_stru
34798 + (current->uid != task->uid) ||
34799 + (current->gid != task->egid) ||
34800 + (current->gid != task->sgid) ||
34801 +- (current->gid != task->gid)) && !capable(CAP_SYS_PTRACE))
34802 ++ (current->gid != task->gid)) && !capable_nolog(CAP_SYS_PTRACE))
34803 + return -EPERM;
34804 + smp_rmb();
34805 + if (task->mm)
34806 + dumpable = get_dumpable(task->mm);
34807 +- if (!dumpable && !capable(CAP_SYS_PTRACE))
34808 ++ if (!dumpable && !capable_nolog(CAP_SYS_PTRACE))
34809 + return -EPERM;
34810 +
34811 + return security_ptrace_may_access(task, mode);
34812 +@@ -193,7 +194,7 @@ repeat:
34813 +
34814 + /* Go */
34815 + task->ptrace |= PT_PTRACED;
34816 +- if (capable(CAP_SYS_PTRACE))
34817 ++ if (capable_nolog(CAP_SYS_PTRACE))
34818 + task->ptrace |= PT_PTRACE_CAP;
34819 +
34820 + __ptrace_link(task, current);
34821 +@@ -582,6 +583,11 @@ asmlinkage long sys_ptrace(long request,
34822 + if (ret < 0)
34823 + goto out_put_task_struct;
34824 +
34825 ++ if (gr_handle_ptrace(child, request)) {
34826 ++ ret = -EPERM;
34827 ++ goto out_put_task_struct;
34828 ++ }
34829 ++
34830 + ret = arch_ptrace(child, request, addr, data);
34831 + if (ret < 0)
34832 + goto out_put_task_struct;
34833 +diff -urNp linux-2.6.28/kernel/relay.c linux-2.6.28/kernel/relay.c
34834 +--- linux-2.6.28/kernel/relay.c 2008-12-24 18:26:37.000000000 -0500
34835 ++++ linux-2.6.28/kernel/relay.c 2009-01-11 07:20:06.000000000 -0500
34836 +@@ -1290,7 +1290,7 @@ static int subbuf_splice_actor(struct fi
34837 + return 0;
34838 +
34839 + ret = *nonpad_ret = splice_to_pipe(pipe, &spd);
34840 +- if (ret < 0 || ret < total_len)
34841 ++ if ((int)ret < 0 || ret < total_len)
34842 + return ret;
34843 +
34844 + if (read_start + ret == nonpad_end)
34845 +diff -urNp linux-2.6.28/kernel/resource.c linux-2.6.28/kernel/resource.c
34846 +--- linux-2.6.28/kernel/resource.c 2008-12-24 18:26:37.000000000 -0500
34847 ++++ linux-2.6.28/kernel/resource.c 2009-01-11 05:47:05.000000000 -0500
34848 +@@ -132,8 +132,18 @@ static const struct file_operations proc
34849 +
34850 + static int __init ioresources_init(void)
34851 + {
34852 ++#ifdef CONFIG_GRKERNSEC_PROC_ADD
34853 ++#ifdef CONFIG_GRKERNSEC_PROC_USER
34854 ++ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
34855 ++ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
34856 ++#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
34857 ++ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
34858 ++ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
34859 ++#endif
34860 ++#else
34861 + proc_create("ioports", 0, NULL, &proc_ioports_operations);
34862 + proc_create("iomem", 0, NULL, &proc_iomem_operations);
34863 ++#endif
34864 + return 0;
34865 + }
34866 + __initcall(ioresources_init);
34867 +diff -urNp linux-2.6.28/kernel/sched.c linux-2.6.28/kernel/sched.c
34868 +--- linux-2.6.28/kernel/sched.c 2008-12-24 18:26:37.000000000 -0500
34869 ++++ linux-2.6.28/kernel/sched.c 2009-01-11 07:20:06.000000000 -0500
34870 +@@ -72,6 +72,7 @@
34871 + #include <linux/debugfs.h>
34872 + #include <linux/ctype.h>
34873 + #include <linux/ftrace.h>
34874 ++#include <linux/grsecurity.h>
34875 + #include <trace/sched.h>
34876 +
34877 + #include <asm/tlb.h>
34878 +@@ -5045,7 +5046,8 @@ asmlinkage long sys_nice(int increment)
34879 + if (nice > 19)
34880 + nice = 19;
34881 +
34882 +- if (increment < 0 && !can_nice(current, nice))
34883 ++ if (increment < 0 && (!can_nice(current, nice) ||
34884 ++ gr_handle_chroot_nice()))
34885 + return -EPERM;
34886 +
34887 + retval = security_task_setnice(current, nice);
34888 +@@ -6310,7 +6312,7 @@ static struct ctl_table sd_ctl_dir[] = {
34889 + .procname = "sched_domain",
34890 + .mode = 0555,
34891 + },
34892 +- {0, },
34893 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
34894 + };
34895 +
34896 + static struct ctl_table sd_ctl_root[] = {
34897 +@@ -6320,7 +6322,7 @@ static struct ctl_table sd_ctl_root[] =
34898 + .mode = 0555,
34899 + .child = sd_ctl_dir,
34900 + },
34901 +- {0, },
34902 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
34903 + };
34904 +
34905 + static struct ctl_table *sd_alloc_ctl_entry(int n)
34906 +diff -urNp linux-2.6.28/kernel/signal.c linux-2.6.28/kernel/signal.c
34907 +--- linux-2.6.28/kernel/signal.c 2008-12-24 18:26:37.000000000 -0500
34908 ++++ linux-2.6.28/kernel/signal.c 2009-01-11 07:20:06.000000000 -0500
34909 +@@ -26,6 +26,7 @@
34910 + #include <linux/capability.h>
34911 + #include <linux/freezer.h>
34912 + #include <linux/pid_namespace.h>
34913 ++#include <linux/grsecurity.h>
34914 + #include <linux/nsproxy.h>
34915 + #include <trace/sched.h>
34916 +
34917 +@@ -596,6 +597,9 @@ static int check_kill_permission(int sig
34918 + }
34919 + }
34920 +
34921 ++ if (gr_handle_signal(t, sig))
34922 ++ return -EPERM;
34923 ++
34924 + return security_task_kill(t, info, sig, 0);
34925 + }
34926 +
34927 +@@ -887,8 +891,8 @@ static void print_fatal_signal(struct pt
34928 + for (i = 0; i < 16; i++) {
34929 + unsigned char insn;
34930 +
34931 +- __get_user(insn, (unsigned char *)(regs->ip + i));
34932 +- printk("%02x ", insn);
34933 ++ if (!get_user(insn, (unsigned char __user *)(regs->ip + i)))
34934 ++ printk("%02x ", insn);
34935 + }
34936 + }
34937 + #endif
34938 +@@ -911,7 +915,7 @@ __group_send_sig_info(int sig, struct si
34939 + return send_signal(sig, info, p, 1);
34940 + }
34941 +
34942 +-static int
34943 ++int
34944 + specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
34945 + {
34946 + return send_signal(sig, info, t, 0);
34947 +@@ -949,8 +953,12 @@ force_sig_info(int sig, struct siginfo *
34948 + if (action->sa.sa_handler == SIG_DFL)
34949 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
34950 + ret = specific_send_sig_info(sig, info, t);
34951 ++
34952 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
34953 +
34954 ++ gr_log_signal(sig, t);
34955 ++ gr_handle_crash(t, sig);
34956 ++
34957 + return ret;
34958 + }
34959 +
34960 +@@ -1021,6 +1029,8 @@ int group_send_sig_info(int sig, struct
34961 + ret = __group_send_sig_info(sig, info, p);
34962 + unlock_task_sighand(p, &flags);
34963 + }
34964 ++ if (!ret)
34965 ++ gr_log_signal(sig, p);
34966 + }
34967 +
34968 + return ret;
34969 +diff -urNp linux-2.6.28/kernel/softirq.c linux-2.6.28/kernel/softirq.c
34970 +--- linux-2.6.28/kernel/softirq.c 2008-12-24 18:26:37.000000000 -0500
34971 ++++ linux-2.6.28/kernel/softirq.c 2009-01-11 07:20:06.000000000 -0500
34972 +@@ -463,9 +463,9 @@ void tasklet_kill(struct tasklet_struct
34973 + printk("Attempt to kill tasklet from interrupt\n");
34974 +
34975 + while (test_and_set_bit(TASKLET_STATE_SCHED, &t->state)) {
34976 +- do
34977 ++ do {
34978 + yield();
34979 +- while (test_bit(TASKLET_STATE_SCHED, &t->state));
34980 ++ } while (test_bit(TASKLET_STATE_SCHED, &t->state));
34981 + }
34982 + tasklet_unlock_wait(t);
34983 + clear_bit(TASKLET_STATE_SCHED, &t->state);
34984 +diff -urNp linux-2.6.28/kernel/sys.c linux-2.6.28/kernel/sys.c
34985 +--- linux-2.6.28/kernel/sys.c 2008-12-24 18:26:37.000000000 -0500
34986 ++++ linux-2.6.28/kernel/sys.c 2009-01-11 07:20:06.000000000 -0500
34987 +@@ -33,6 +33,7 @@
34988 + #include <linux/task_io_accounting_ops.h>
34989 + #include <linux/seccomp.h>
34990 + #include <linux/cpu.h>
34991 ++#include <linux/grsecurity.h>
34992 +
34993 + #include <linux/compat.h>
34994 + #include <linux/syscalls.h>
34995 +@@ -125,6 +126,12 @@ static int set_one_prio(struct task_stru
34996 + error = -EACCES;
34997 + goto out;
34998 + }
34999 ++
35000 ++ if (gr_handle_chroot_setpriority(p, niceval)) {
35001 ++ error = -EACCES;
35002 ++ goto out;
35003 ++ }
35004 ++
35005 + no_nice = security_task_setnice(p, niceval);
35006 + if (no_nice) {
35007 + error = no_nice;
35008 +@@ -181,10 +188,10 @@ asmlinkage long sys_setpriority(int whic
35009 + if ((who != current->uid) && !(user = find_user(who)))
35010 + goto out_unlock; /* No processes for this user */
35011 +
35012 +- do_each_thread(g, p)
35013 ++ do_each_thread(g, p) {
35014 + if (p->uid == who)
35015 + error = set_one_prio(p, niceval, error);
35016 +- while_each_thread(g, p);
35017 ++ } while_each_thread(g, p);
35018 + if (who != current->uid)
35019 + free_uid(user); /* For find_user() */
35020 + break;
35021 +@@ -243,13 +250,13 @@ asmlinkage long sys_getpriority(int whic
35022 + if ((who != current->uid) && !(user = find_user(who)))
35023 + goto out_unlock; /* No processes for this user */
35024 +
35025 +- do_each_thread(g, p)
35026 ++ do_each_thread(g, p) {
35027 + if (p->uid == who) {
35028 + niceval = 20 - task_nice(p);
35029 + if (niceval > retval)
35030 + retval = niceval;
35031 + }
35032 +- while_each_thread(g, p);
35033 ++ } while_each_thread(g, p);
35034 + if (who != current->uid)
35035 + free_uid(user); /* for find_user() */
35036 + break;
35037 +@@ -499,6 +506,10 @@ asmlinkage long sys_setregid(gid_t rgid,
35038 + else
35039 + return -EPERM;
35040 + }
35041 ++
35042 ++ if (gr_check_group_change(new_rgid, new_egid, -1))
35043 ++ return -EPERM;
35044 ++
35045 + if (new_egid != old_egid) {
35046 + set_dumpable(current->mm, suid_dumpable);
35047 + smp_wmb();
35048 +@@ -506,6 +517,9 @@ asmlinkage long sys_setregid(gid_t rgid,
35049 + if (rgid != (gid_t) -1 ||
35050 + (egid != (gid_t) -1 && egid != old_rgid))
35051 + current->sgid = new_egid;
35052 ++
35053 ++ gr_set_role_label(current, current->uid, new_rgid);
35054 ++
35055 + current->fsgid = new_egid;
35056 + current->egid = new_egid;
35057 + current->gid = new_rgid;
35058 +@@ -528,11 +542,17 @@ asmlinkage long sys_setgid(gid_t gid)
35059 + if (retval)
35060 + return retval;
35061 +
35062 ++ if (gr_check_group_change(gid, gid, gid))
35063 ++ return -EPERM;
35064 ++
35065 + if (capable(CAP_SETGID)) {
35066 + if (old_egid != gid) {
35067 + set_dumpable(current->mm, suid_dumpable);
35068 + smp_wmb();
35069 + }
35070 ++
35071 ++ gr_set_role_label(current, current->uid, gid);
35072 ++
35073 + current->gid = current->egid = current->sgid = current->fsgid = gid;
35074 + } else if ((gid == current->gid) || (gid == current->sgid)) {
35075 + if (old_egid != gid) {
35076 +@@ -570,6 +590,9 @@ static int set_user(uid_t new_ruid, int
35077 + set_dumpable(current->mm, suid_dumpable);
35078 + smp_wmb();
35079 + }
35080 ++
35081 ++ gr_set_role_label(current, new_ruid, current->gid);
35082 ++
35083 + current->uid = new_ruid;
35084 + return 0;
35085 + }
35086 +@@ -619,6 +642,9 @@ asmlinkage long sys_setreuid(uid_t ruid,
35087 + return -EPERM;
35088 + }
35089 +
35090 ++ if (gr_check_user_change(new_ruid, new_euid, -1))
35091 ++ return -EPERM;
35092 ++
35093 + if (new_ruid != old_ruid && set_user(new_ruid, new_euid != old_euid) < 0)
35094 + return -EAGAIN;
35095 +
35096 +@@ -665,6 +691,12 @@ asmlinkage long sys_setuid(uid_t uid)
35097 + old_suid = current->suid;
35098 + new_suid = old_suid;
35099 +
35100 ++ if (gr_check_crash_uid(uid))
35101 ++ return -EPERM;
35102 ++
35103 ++ if (gr_check_user_change(uid, uid, uid))
35104 ++ return -EPERM;
35105 ++
35106 + if (capable(CAP_SETUID)) {
35107 + if (uid != old_ruid && set_user(uid, old_euid != uid) < 0)
35108 + return -EAGAIN;
35109 +@@ -712,6 +744,10 @@ asmlinkage long sys_setresuid(uid_t ruid
35110 + (suid != current->euid) && (suid != current->suid))
35111 + return -EPERM;
35112 + }
35113 ++
35114 ++ if (gr_check_user_change(ruid, euid, -1))
35115 ++ return -EPERM;
35116 ++
35117 + if (ruid != (uid_t) -1) {
35118 + if (ruid != current->uid && set_user(ruid, euid != current->euid) < 0)
35119 + return -EAGAIN;
35120 +@@ -766,6 +802,10 @@ asmlinkage long sys_setresgid(gid_t rgid
35121 + (sgid != current->egid) && (sgid != current->sgid))
35122 + return -EPERM;
35123 + }
35124 ++
35125 ++ if (gr_check_group_change(rgid, egid, -1))
35126 ++ return -EPERM;
35127 ++
35128 + if (egid != (gid_t) -1) {
35129 + if (egid != current->egid) {
35130 + set_dumpable(current->mm, suid_dumpable);
35131 +@@ -774,8 +814,10 @@ asmlinkage long sys_setresgid(gid_t rgid
35132 + current->egid = egid;
35133 + }
35134 + current->fsgid = current->egid;
35135 +- if (rgid != (gid_t) -1)
35136 ++ if (rgid != (gid_t) -1) {
35137 ++ gr_set_role_label(current, current->uid, rgid);
35138 + current->gid = rgid;
35139 ++ }
35140 + if (sgid != (gid_t) -1)
35141 + current->sgid = sgid;
35142 +
35143 +@@ -810,6 +852,9 @@ asmlinkage long sys_setfsuid(uid_t uid)
35144 + if (security_task_setuid(uid, (uid_t)-1, (uid_t)-1, LSM_SETID_FS))
35145 + return old_fsuid;
35146 +
35147 ++ if (gr_check_user_change(-1, -1, uid))
35148 ++ return old_fsuid;
35149 ++
35150 + if (uid == current->uid || uid == current->euid ||
35151 + uid == current->suid || uid == current->fsuid ||
35152 + capable(CAP_SETUID)) {
35153 +@@ -842,6 +887,9 @@ asmlinkage long sys_setfsgid(gid_t gid)
35154 + if (gid == current->gid || gid == current->egid ||
35155 + gid == current->sgid || gid == current->fsgid ||
35156 + capable(CAP_SETGID)) {
35157 ++ if (gr_check_group_change(-1, -1, gid))
35158 ++ return old_fsgid;
35159 ++
35160 + if (gid != old_fsgid) {
35161 + set_dumpable(current->mm, suid_dumpable);
35162 + smp_wmb();
35163 +@@ -913,7 +961,10 @@ asmlinkage long sys_setpgid(pid_t pid, p
35164 + write_lock_irq(&tasklist_lock);
35165 +
35166 + err = -ESRCH;
35167 +- p = find_task_by_vpid(pid);
35168 ++ /* grsec: replaced find_task_by_vpid with equivalent call which
35169 ++ lacks the chroot restriction
35170 ++ */
35171 ++ p = pid_task(find_pid_ns(pid, current->nsproxy->pid_ns), PIDTYPE_PID);
35172 + if (!p)
35173 + goto out;
35174 +
35175 +@@ -1644,7 +1695,7 @@ asmlinkage long sys_prctl(int option, un
35176 + error = get_dumpable(current->mm);
35177 + break;
35178 + case PR_SET_DUMPABLE:
35179 +- if (arg2 < 0 || arg2 > 1) {
35180 ++ if (arg2 > 1) {
35181 + error = -EINVAL;
35182 + break;
35183 + }
35184 +diff -urNp linux-2.6.28/kernel/sysctl.c linux-2.6.28/kernel/sysctl.c
35185 +--- linux-2.6.28/kernel/sysctl.c 2008-12-24 18:26:37.000000000 -0500
35186 ++++ linux-2.6.28/kernel/sysctl.c 2009-01-11 07:20:06.000000000 -0500
35187 +@@ -61,6 +61,13 @@
35188 + static int deprecated_sysctl_warning(struct __sysctl_args *args);
35189 +
35190 + #if defined(CONFIG_SYSCTL)
35191 ++#include <linux/grsecurity.h>
35192 ++#include <linux/grinternal.h>
35193 ++
35194 ++extern __u32 gr_handle_sysctl(const ctl_table *table, const int op);
35195 ++extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
35196 ++ const int op);
35197 ++extern int gr_handle_chroot_sysctl(const int op);
35198 +
35199 + /* External variables not in a header file. */
35200 + extern int C_A_D;
35201 +@@ -152,6 +159,7 @@ static int proc_do_cad_pid(struct ctl_ta
35202 + static int proc_taint(struct ctl_table *table, int write, struct file *filp,
35203 + void __user *buffer, size_t *lenp, loff_t *ppos);
35204 + #endif
35205 ++extern ctl_table grsecurity_table[];
35206 +
35207 + static struct ctl_table root_table[];
35208 + static struct ctl_table_root sysctl_table_root;
35209 +@@ -184,6 +192,21 @@ extern struct ctl_table epoll_table[];
35210 + int sysctl_legacy_va_layout;
35211 + #endif
35212 +
35213 ++#ifdef CONFIG_PAX_SOFTMODE
35214 ++static ctl_table pax_table[] = {
35215 ++ {
35216 ++ .ctl_name = CTL_UNNUMBERED,
35217 ++ .procname = "softmode",
35218 ++ .data = &pax_softmode,
35219 ++ .maxlen = sizeof(unsigned int),
35220 ++ .mode = 0600,
35221 ++ .proc_handler = &proc_dointvec,
35222 ++ },
35223 ++
35224 ++ { .ctl_name = 0 }
35225 ++};
35226 ++#endif
35227 ++
35228 + extern int prove_locking;
35229 + extern int lock_stat;
35230 +
35231 +@@ -220,6 +243,7 @@ static struct ctl_table root_table[] = {
35232 + .mode = 0555,
35233 + .child = dev_table,
35234 + },
35235 ++
35236 + /*
35237 + * NOTE: do not add new entries to this table unless you have read
35238 + * Documentation/sysctl/ctl_unnumbered.txt
35239 +@@ -856,6 +880,25 @@ static struct ctl_table kern_table[] = {
35240 + .proc_handler = &scan_unevictable_handler,
35241 + },
35242 + #endif
35243 ++
35244 ++#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_MODSTOP)
35245 ++ {
35246 ++ .ctl_name = CTL_UNNUMBERED,
35247 ++ .procname = "grsecurity",
35248 ++ .mode = 0500,
35249 ++ .child = grsecurity_table,
35250 ++ },
35251 ++#endif
35252 ++
35253 ++#ifdef CONFIG_PAX_SOFTMODE
35254 ++ {
35255 ++ .ctl_name = CTL_UNNUMBERED,
35256 ++ .procname = "pax",
35257 ++ .mode = 0500,
35258 ++ .child = pax_table,
35259 ++ },
35260 ++#endif
35261 ++
35262 + /*
35263 + * NOTE: do not add new entries to this table unless you have read
35264 + * Documentation/sysctl/ctl_unnumbered.txt
35265 +@@ -1185,6 +1228,7 @@ static struct ctl_table vm_table[] = {
35266 + .extra2 = &one,
35267 + },
35268 + #endif
35269 ++
35270 + /*
35271 + * NOTE: do not add new entries to this table unless you have read
35272 + * Documentation/sysctl/ctl_unnumbered.txt
35273 +@@ -1562,6 +1606,8 @@ static int do_sysctl_strategy(struct ctl
35274 + return 0;
35275 + }
35276 +
35277 ++static int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op);
35278 ++
35279 + static int parse_table(int __user *name, int nlen,
35280 + void __user *oldval, size_t __user *oldlenp,
35281 + void __user *newval, size_t newlen,
35282 +@@ -1580,7 +1626,7 @@ repeat:
35283 + if (n == table->ctl_name) {
35284 + int error;
35285 + if (table->child) {
35286 +- if (sysctl_perm(root, table, MAY_EXEC))
35287 ++ if (sysctl_perm_nochk(root, table, MAY_EXEC))
35288 + return -EPERM;
35289 + name++;
35290 + nlen--;
35291 +@@ -1665,6 +1711,33 @@ int sysctl_perm(struct ctl_table_root *r
35292 + int error;
35293 + int mode;
35294 +
35295 ++ if (table->parent != NULL && table->parent->procname != NULL &&
35296 ++ table->procname != NULL &&
35297 ++ gr_handle_sysctl_mod(table->parent->procname, table->procname, op))
35298 ++ return -EACCES;
35299 ++ if (gr_handle_chroot_sysctl(op))
35300 ++ return -EACCES;
35301 ++ error = gr_handle_sysctl(table, op);
35302 ++ if (error)
35303 ++ return error;
35304 ++
35305 ++ error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
35306 ++ if (error)
35307 ++ return error;
35308 ++
35309 ++ if (root->permissions)
35310 ++ mode = root->permissions(root, current->nsproxy, table);
35311 ++ else
35312 ++ mode = table->mode;
35313 ++
35314 ++ return test_perm(mode, op);
35315 ++}
35316 ++
35317 ++int sysctl_perm_nochk(struct ctl_table_root *root, struct ctl_table *table, int op)
35318 ++{
35319 ++ int error;
35320 ++ int mode;
35321 ++
35322 + error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
35323 + if (error)
35324 + return error;
35325 +diff -urNp linux-2.6.28/kernel/time/tick-broadcast.c linux-2.6.28/kernel/time/tick-broadcast.c
35326 +--- linux-2.6.28/kernel/time/tick-broadcast.c 2008-12-24 18:26:37.000000000 -0500
35327 ++++ linux-2.6.28/kernel/time/tick-broadcast.c 2009-01-11 07:20:06.000000000 -0500
35328 +@@ -114,7 +114,7 @@ int tick_device_uses_broadcast(struct cl
35329 + * then clear the broadcast bit.
35330 + */
35331 + if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
35332 +- int cpu = smp_processor_id();
35333 ++ cpu = smp_processor_id();
35334 +
35335 + cpu_clear(cpu, tick_broadcast_mask);
35336 + tick_broadcast_clear_oneshot(cpu);
35337 +diff -urNp linux-2.6.28/kernel/time.c linux-2.6.28/kernel/time.c
35338 +--- linux-2.6.28/kernel/time.c 2008-12-24 18:26:37.000000000 -0500
35339 ++++ linux-2.6.28/kernel/time.c 2009-01-11 07:20:06.000000000 -0500
35340 +@@ -37,6 +37,7 @@
35341 + #include <linux/fs.h>
35342 + #include <linux/slab.h>
35343 + #include <linux/math64.h>
35344 ++#include <linux/grsecurity.h>
35345 +
35346 + #include <asm/uaccess.h>
35347 + #include <asm/unistd.h>
35348 +@@ -92,6 +93,9 @@ asmlinkage long sys_stime(time_t __user
35349 + return err;
35350 +
35351 + do_settimeofday(&tv);
35352 ++
35353 ++ gr_log_timechange();
35354 ++
35355 + return 0;
35356 + }
35357 +
35358 +@@ -200,6 +204,8 @@ asmlinkage long sys_settimeofday(struct
35359 + return -EFAULT;
35360 + }
35361 +
35362 ++ gr_log_timechange();
35363 ++
35364 + return do_sys_settimeofday(tv ? &new_ts : NULL, tz ? &new_tz : NULL);
35365 + }
35366 +
35367 +@@ -238,7 +244,7 @@ EXPORT_SYMBOL(current_fs_time);
35368 + * Avoid unnecessary multiplications/divisions in the
35369 + * two most common HZ cases:
35370 + */
35371 +-unsigned int inline jiffies_to_msecs(const unsigned long j)
35372 ++inline unsigned int jiffies_to_msecs(const unsigned long j)
35373 + {
35374 + #if HZ <= MSEC_PER_SEC && !(MSEC_PER_SEC % HZ)
35375 + return (MSEC_PER_SEC / HZ) * j;
35376 +@@ -254,7 +260,7 @@ unsigned int inline jiffies_to_msecs(con
35377 + }
35378 + EXPORT_SYMBOL(jiffies_to_msecs);
35379 +
35380 +-unsigned int inline jiffies_to_usecs(const unsigned long j)
35381 ++inline unsigned int jiffies_to_usecs(const unsigned long j)
35382 + {
35383 + #if HZ <= USEC_PER_SEC && !(USEC_PER_SEC % HZ)
35384 + return (USEC_PER_SEC / HZ) * j;
35385 +diff -urNp linux-2.6.28/kernel/utsname_sysctl.c linux-2.6.28/kernel/utsname_sysctl.c
35386 +--- linux-2.6.28/kernel/utsname_sysctl.c 2008-12-24 18:26:37.000000000 -0500
35387 ++++ linux-2.6.28/kernel/utsname_sysctl.c 2009-01-11 07:20:06.000000000 -0500
35388 +@@ -123,7 +123,7 @@ static struct ctl_table uts_kern_table[]
35389 + .proc_handler = proc_do_uts_string,
35390 + .strategy = sysctl_uts_string,
35391 + },
35392 +- {}
35393 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
35394 + };
35395 +
35396 + static struct ctl_table uts_root_table[] = {
35397 +@@ -133,7 +133,7 @@ static struct ctl_table uts_root_table[]
35398 + .mode = 0555,
35399 + .child = uts_kern_table,
35400 + },
35401 +- {}
35402 ++ { 0, NULL, NULL, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL }
35403 + };
35404 +
35405 + static int __init utsname_sysctl_init(void)
35406 +diff -urNp linux-2.6.28/lib/radix-tree.c linux-2.6.28/lib/radix-tree.c
35407 +--- linux-2.6.28/lib/radix-tree.c 2008-12-24 18:26:37.000000000 -0500
35408 ++++ linux-2.6.28/lib/radix-tree.c 2009-01-11 07:20:06.000000000 -0500
35409 +@@ -81,7 +81,7 @@ struct radix_tree_preload {
35410 + int nr;
35411 + struct radix_tree_node *nodes[RADIX_TREE_MAX_PATH];
35412 + };
35413 +-DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
35414 ++DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
35415 +
35416 + static inline gfp_t root_gfp_mask(struct radix_tree_root *root)
35417 + {
35418 +diff -urNp linux-2.6.28/localversion-grsec linux-2.6.28/localversion-grsec
35419 +--- linux-2.6.28/localversion-grsec 1969-12-31 19:00:00.000000000 -0500
35420 ++++ linux-2.6.28/localversion-grsec 2009-01-11 05:47:05.000000000 -0500
35421 +@@ -0,0 +1 @@
35422 ++-grsec
35423 +diff -urNp linux-2.6.28/Makefile linux-2.6.28/Makefile
35424 +--- linux-2.6.28/Makefile 2008-12-24 18:26:37.000000000 -0500
35425 ++++ linux-2.6.28/Makefile 2009-01-11 07:20:06.000000000 -0500
35426 +@@ -221,7 +221,7 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH"
35427 +
35428 + HOSTCC = gcc
35429 + HOSTCXX = g++
35430 +-HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
35431 ++HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
35432 + HOSTCXXFLAGS = -O2
35433 +
35434 + # Decide whether to build built-in, modular, or both.
35435 +@@ -619,7 +619,7 @@ export mod_strip_cmd
35436 +
35437 +
35438 + ifeq ($(KBUILD_EXTMOD),)
35439 +-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
35440 ++core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
35441 +
35442 + vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
35443 + $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
35444 +diff -urNp linux-2.6.28/mm/filemap.c linux-2.6.28/mm/filemap.c
35445 +--- linux-2.6.28/mm/filemap.c 2008-12-24 18:26:37.000000000 -0500
35446 ++++ linux-2.6.28/mm/filemap.c 2009-01-11 07:20:06.000000000 -0500
35447 +@@ -34,6 +34,7 @@
35448 + #include <linux/hardirq.h> /* for BUG_ON(!in_atomic()) only */
35449 + #include <linux/memcontrol.h>
35450 + #include <linux/mm_inline.h> /* for page_is_file_cache() */
35451 ++#include <linux/grsecurity.h>
35452 + #include "internal.h"
35453 +
35454 + /*
35455 +@@ -1601,7 +1602,7 @@ int generic_file_mmap(struct file * file
35456 + struct address_space *mapping = file->f_mapping;
35457 +
35458 + if (!mapping->a_ops->readpage)
35459 +- return -ENOEXEC;
35460 ++ return -ENODEV;
35461 + file_accessed(file);
35462 + vma->vm_ops = &generic_file_vm_ops;
35463 + vma->vm_flags |= VM_CAN_NONLINEAR;
35464 +@@ -1962,6 +1963,7 @@ inline int generic_write_checks(struct f
35465 + *pos = i_size_read(inode);
35466 +
35467 + if (limit != RLIM_INFINITY) {
35468 ++ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
35469 + if (*pos >= limit) {
35470 + send_sig(SIGXFSZ, current, 0);
35471 + return -EFBIG;
35472 +diff -urNp linux-2.6.28/mm/fremap.c linux-2.6.28/mm/fremap.c
35473 +--- linux-2.6.28/mm/fremap.c 2008-12-24 18:26:37.000000000 -0500
35474 ++++ linux-2.6.28/mm/fremap.c 2009-01-11 07:20:06.000000000 -0500
35475 +@@ -153,6 +153,13 @@ asmlinkage long sys_remap_file_pages(uns
35476 + retry:
35477 + vma = find_vma(mm, start);
35478 +
35479 ++#ifdef CONFIG_PAX_SEGMEXEC
35480 ++ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC)) {
35481 ++ up_read(&mm->mmap_sem);
35482 ++ return err;
35483 ++ }
35484 ++#endif
35485 ++
35486 + /*
35487 + * Make sure the vma is shared, that it supports prefaulting,
35488 + * and that the remapped range is valid and fully within
35489 +diff -urNp linux-2.6.28/mm/hugetlb.c linux-2.6.28/mm/hugetlb.c
35490 +--- linux-2.6.28/mm/hugetlb.c 2008-12-24 18:26:37.000000000 -0500
35491 ++++ linux-2.6.28/mm/hugetlb.c 2009-01-11 07:20:06.000000000 -0500
35492 +@@ -1832,6 +1832,26 @@ static int unmap_ref_private(struct mm_s
35493 + return 1;
35494 + }
35495 +
35496 ++#ifdef CONFIG_PAX_SEGMEXEC
35497 ++static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
35498 ++{
35499 ++ struct mm_struct *mm = vma->vm_mm;
35500 ++ struct vm_area_struct *vma_m;
35501 ++ unsigned long address_m;
35502 ++ pte_t *ptep_m;
35503 ++
35504 ++ vma_m = pax_find_mirror_vma(vma);
35505 ++ if (!vma_m)
35506 ++ return;
35507 ++
35508 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35509 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35510 ++ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
35511 ++ get_page(page_m);
35512 ++ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
35513 ++}
35514 ++#endif
35515 ++
35516 + static int hugetlb_cow(struct mm_struct *mm, struct vm_area_struct *vma,
35517 + unsigned long address, pte_t *ptep, pte_t pte,
35518 + struct page *pagecache_page)
35519 +@@ -1903,6 +1923,11 @@ retry_avoidcopy:
35520 + huge_ptep_clear_flush(vma, address, ptep);
35521 + set_huge_pte_at(mm, address, ptep,
35522 + make_huge_pte(vma, new_page, 1));
35523 ++
35524 ++#ifdef CONFIG_PAX_SEGMEXEC
35525 ++ pax_mirror_huge_pte(vma, address, new_page);
35526 ++#endif
35527 ++
35528 + /* Make the old page be freed below */
35529 + new_page = old_page;
35530 + }
35531 +@@ -2012,6 +2037,10 @@ retry:
35532 + && (vma->vm_flags & VM_SHARED)));
35533 + set_huge_pte_at(mm, address, ptep, new_pte);
35534 +
35535 ++#ifdef CONFIG_PAX_SEGMEXEC
35536 ++ pax_mirror_huge_pte(vma, address, page);
35537 ++#endif
35538 ++
35539 + if (write_access && !(vma->vm_flags & VM_SHARED)) {
35540 + /* Optimization, do the COW without a second fault */
35541 + ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
35542 +@@ -2040,6 +2069,28 @@ int hugetlb_fault(struct mm_struct *mm,
35543 + static DEFINE_MUTEX(hugetlb_instantiation_mutex);
35544 + struct hstate *h = hstate_vma(vma);
35545 +
35546 ++#ifdef CONFIG_PAX_SEGMEXEC
35547 ++ struct vm_area_struct *vma_m;
35548 ++
35549 ++ vma_m = pax_find_mirror_vma(vma);
35550 ++ if (vma_m) {
35551 ++ unsigned long address_m;
35552 ++
35553 ++ if (vma->vm_start > vma_m->vm_start) {
35554 ++ address_m = address;
35555 ++ address -= SEGMEXEC_TASK_SIZE;
35556 ++ vma = vma_m;
35557 ++ h = hstate_vma(vma);
35558 ++ } else
35559 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35560 ++
35561 ++ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
35562 ++ return VM_FAULT_OOM;
35563 ++ address_m &= HPAGE_MASK;
35564 ++ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
35565 ++ }
35566 ++#endif
35567 ++
35568 + ptep = huge_pte_alloc(mm, address, huge_page_size(h));
35569 + if (!ptep)
35570 + return VM_FAULT_OOM;
35571 +diff -urNp linux-2.6.28/mm/madvise.c linux-2.6.28/mm/madvise.c
35572 +--- linux-2.6.28/mm/madvise.c 2008-12-24 18:26:37.000000000 -0500
35573 ++++ linux-2.6.28/mm/madvise.c 2009-01-11 07:20:06.000000000 -0500
35574 +@@ -43,6 +43,10 @@ static long madvise_behavior(struct vm_a
35575 + pgoff_t pgoff;
35576 + int new_flags = vma->vm_flags;
35577 +
35578 ++#ifdef CONFIG_PAX_SEGMEXEC
35579 ++ struct vm_area_struct *vma_m;
35580 ++#endif
35581 ++
35582 + switch (behavior) {
35583 + case MADV_NORMAL:
35584 + new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
35585 +@@ -92,6 +96,13 @@ success:
35586 + /*
35587 + * vm_flags is protected by the mmap_sem held in write mode.
35588 + */
35589 ++
35590 ++#ifdef CONFIG_PAX_SEGMEXEC
35591 ++ vma_m = pax_find_mirror_vma(vma);
35592 ++ if (vma_m)
35593 ++ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
35594 ++#endif
35595 ++
35596 + vma->vm_flags = new_flags;
35597 +
35598 + out:
35599 +@@ -236,6 +247,17 @@ madvise_vma(struct vm_area_struct *vma,
35600 +
35601 + case MADV_DONTNEED:
35602 + error = madvise_dontneed(vma, prev, start, end);
35603 ++
35604 ++#ifdef CONFIG_PAX_SEGMEXEC
35605 ++ if (!error) {
35606 ++ struct vm_area_struct *vma_m, *prev_m;
35607 ++
35608 ++ vma_m = pax_find_mirror_vma(vma);
35609 ++ if (vma_m)
35610 ++ error = madvise_dontneed(vma_m, &prev_m, start + SEGMEXEC_TASK_SIZE, end + SEGMEXEC_TASK_SIZE);
35611 ++ }
35612 ++#endif
35613 ++
35614 + break;
35615 +
35616 + default:
35617 +@@ -308,6 +330,16 @@ asmlinkage long sys_madvise(unsigned lon
35618 + if (end < start)
35619 + goto out;
35620 +
35621 ++#ifdef CONFIG_PAX_SEGMEXEC
35622 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
35623 ++ if (end > SEGMEXEC_TASK_SIZE)
35624 ++ goto out;
35625 ++ } else
35626 ++#endif
35627 ++
35628 ++ if (end > TASK_SIZE)
35629 ++ goto out;
35630 ++
35631 + error = 0;
35632 + if (end == start)
35633 + goto out;
35634 +diff -urNp linux-2.6.28/mm/memory.c linux-2.6.28/mm/memory.c
35635 +--- linux-2.6.28/mm/memory.c 2008-12-24 18:26:37.000000000 -0500
35636 ++++ linux-2.6.28/mm/memory.c 2009-01-11 07:20:06.000000000 -0500
35637 +@@ -52,6 +52,7 @@
35638 + #include <linux/writeback.h>
35639 + #include <linux/memcontrol.h>
35640 + #include <linux/mmu_notifier.h>
35641 ++#include <linux/grsecurity.h>
35642 +
35643 + #include <asm/pgalloc.h>
35644 + #include <asm/uaccess.h>
35645 +@@ -1151,11 +1152,11 @@ int __get_user_pages(struct task_struct
35646 + vm_flags &= force ? (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
35647 + i = 0;
35648 +
35649 +- do {
35650 ++ while (len) {
35651 + struct vm_area_struct *vma;
35652 + unsigned int foll_flags;
35653 +
35654 +- vma = find_extend_vma(mm, start);
35655 ++ vma = find_vma(mm, start);
35656 + if (!vma && in_gate_area(tsk, start)) {
35657 + unsigned long pg = start & PAGE_MASK;
35658 + struct vm_area_struct *gate_vma = get_gate_vma(tsk);
35659 +@@ -1197,7 +1198,7 @@ int __get_user_pages(struct task_struct
35660 + continue;
35661 + }
35662 +
35663 +- if (!vma ||
35664 ++ if (!vma || start < vma->vm_start ||
35665 + (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
35666 + (!ignore && !(vm_flags & vma->vm_flags)))
35667 + return i ? : -EFAULT;
35668 +@@ -1271,7 +1272,7 @@ int __get_user_pages(struct task_struct
35669 + start += PAGE_SIZE;
35670 + len--;
35671 + } while (len && start < vma->vm_end);
35672 +- } while (len);
35673 ++ }
35674 + return i;
35675 + }
35676 +
35677 +@@ -1760,6 +1761,186 @@ static inline void cow_user_page(struct
35678 + copy_user_highpage(dst, src, va, vma);
35679 + }
35680 +
35681 ++#ifdef CONFIG_PAX_SEGMEXEC
35682 ++static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
35683 ++{
35684 ++ struct mm_struct *mm = vma->vm_mm;
35685 ++ spinlock_t *ptl;
35686 ++ pte_t *pte, entry;
35687 ++
35688 ++ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
35689 ++ entry = *pte;
35690 ++ if (!pte_present(entry)) {
35691 ++ if (!pte_none(entry)) {
35692 ++ BUG_ON(pte_file(entry));
35693 ++ free_swap_and_cache(pte_to_swp_entry(entry));
35694 ++ pte_clear_not_present_full(mm, address, pte, 0);
35695 ++ }
35696 ++ } else {
35697 ++ struct page *page;
35698 ++
35699 ++ flush_cache_page(vma, address, pte_pfn(entry));
35700 ++ entry = ptep_clear_flush(vma, address, pte);
35701 ++ BUG_ON(pte_dirty(entry));
35702 ++ page = vm_normal_page(vma, address, entry);
35703 ++ if (page) {
35704 ++ update_hiwater_rss(mm);
35705 ++ if (PageAnon(page))
35706 ++ dec_mm_counter(mm, anon_rss);
35707 ++ else
35708 ++ dec_mm_counter(mm, file_rss);
35709 ++ page_remove_rmap(page, vma);
35710 ++ page_cache_release(page);
35711 ++ }
35712 ++ }
35713 ++ pte_unmap_unlock(pte, ptl);
35714 ++}
35715 ++
35716 ++/* PaX: if vma is mirrored, synchronize the mirror's PTE
35717 ++ *
35718 ++ * the ptl of the lower mapped page is held on entry and is not released on exit
35719 ++ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
35720 ++ */
35721 ++static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
35722 ++{
35723 ++ struct mm_struct *mm = vma->vm_mm;
35724 ++ unsigned long address_m;
35725 ++ spinlock_t *ptl_m;
35726 ++ struct vm_area_struct *vma_m;
35727 ++ pmd_t *pmd_m;
35728 ++ pte_t *pte_m, entry_m;
35729 ++
35730 ++ BUG_ON(!page_m || !PageAnon(page_m));
35731 ++
35732 ++ vma_m = pax_find_mirror_vma(vma);
35733 ++ if (!vma_m)
35734 ++ return;
35735 ++
35736 ++ BUG_ON(!PageLocked(page_m));
35737 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35738 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35739 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
35740 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
35741 ++ ptl_m = pte_lockptr(mm, pmd_m);
35742 ++ if (ptl != ptl_m) {
35743 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
35744 ++ if (!pte_none(*pte_m))
35745 ++ goto out;
35746 ++ }
35747 ++
35748 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
35749 ++ page_cache_get(page_m);
35750 ++ page_add_anon_rmap(page_m, vma_m, address_m);
35751 ++ inc_mm_counter(mm, anon_rss);
35752 ++ set_pte_at(mm, address_m, pte_m, entry_m);
35753 ++ update_mmu_cache(vma_m, address_m, entry_m);
35754 ++out:
35755 ++ if (ptl != ptl_m)
35756 ++ spin_unlock(ptl_m);
35757 ++ pte_unmap_nested(pte_m);
35758 ++ unlock_page(page_m);
35759 ++}
35760 ++
35761 ++void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
35762 ++{
35763 ++ struct mm_struct *mm = vma->vm_mm;
35764 ++ unsigned long address_m;
35765 ++ spinlock_t *ptl_m;
35766 ++ struct vm_area_struct *vma_m;
35767 ++ pmd_t *pmd_m;
35768 ++ pte_t *pte_m, entry_m;
35769 ++
35770 ++ BUG_ON(!page_m || PageAnon(page_m));
35771 ++
35772 ++ vma_m = pax_find_mirror_vma(vma);
35773 ++ if (!vma_m)
35774 ++ return;
35775 ++
35776 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35777 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35778 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
35779 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
35780 ++ ptl_m = pte_lockptr(mm, pmd_m);
35781 ++ if (ptl != ptl_m) {
35782 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
35783 ++ if (!pte_none(*pte_m))
35784 ++ goto out;
35785 ++ }
35786 ++
35787 ++ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
35788 ++ page_cache_get(page_m);
35789 ++ page_add_file_rmap(page_m);
35790 ++ inc_mm_counter(mm, file_rss);
35791 ++ set_pte_at(mm, address_m, pte_m, entry_m);
35792 ++ update_mmu_cache(vma_m, address_m, entry_m);
35793 ++out:
35794 ++ if (ptl != ptl_m)
35795 ++ spin_unlock(ptl_m);
35796 ++ pte_unmap_nested(pte_m);
35797 ++}
35798 ++
35799 ++static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
35800 ++{
35801 ++ struct mm_struct *mm = vma->vm_mm;
35802 ++ unsigned long address_m;
35803 ++ spinlock_t *ptl_m;
35804 ++ struct vm_area_struct *vma_m;
35805 ++ pmd_t *pmd_m;
35806 ++ pte_t *pte_m, entry_m;
35807 ++
35808 ++ vma_m = pax_find_mirror_vma(vma);
35809 ++ if (!vma_m)
35810 ++ return;
35811 ++
35812 ++ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
35813 ++ address_m = address + SEGMEXEC_TASK_SIZE;
35814 ++ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
35815 ++ pte_m = pte_offset_map_nested(pmd_m, address_m);
35816 ++ ptl_m = pte_lockptr(mm, pmd_m);
35817 ++ if (ptl != ptl_m) {
35818 ++ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
35819 ++ if (!pte_none(*pte_m))
35820 ++ goto out;
35821 ++ }
35822 ++
35823 ++ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
35824 ++ set_pte_at(mm, address_m, pte_m, entry_m);
35825 ++out:
35826 ++ if (ptl != ptl_m)
35827 ++ spin_unlock(ptl_m);
35828 ++ pte_unmap_nested(pte_m);
35829 ++}
35830 ++
35831 ++static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
35832 ++{
35833 ++ struct page *page_m;
35834 ++ pte_t entry;
35835 ++
35836 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
35837 ++ goto out;
35838 ++
35839 ++ entry = *pte;
35840 ++ page_m = vm_normal_page(vma, address, entry);
35841 ++ if (!page_m)
35842 ++ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
35843 ++ else if (PageAnon(page_m)) {
35844 ++ if (pax_find_mirror_vma(vma)) {
35845 ++ pte_unmap_unlock(pte, ptl);
35846 ++ lock_page(page_m);
35847 ++ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
35848 ++ if (pte_same(entry, *pte))
35849 ++ pax_mirror_anon_pte(vma, address, page_m, ptl);
35850 ++ else
35851 ++ unlock_page(page_m);
35852 ++ }
35853 ++ } else
35854 ++ pax_mirror_file_pte(vma, address, page_m, ptl);
35855 ++
35856 ++out:
35857 ++ pte_unmap_unlock(pte, ptl);
35858 ++}
35859 ++#endif
35860 ++
35861 + /*
35862 + * This routine handles present pages, when users try to write
35863 + * to a shared page. It is done by copying the page to a new address
35864 +@@ -1897,6 +2078,12 @@ gotten:
35865 + */
35866 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
35867 + if (likely(pte_same(*page_table, orig_pte))) {
35868 ++
35869 ++#ifdef CONFIG_PAX_SEGMEXEC
35870 ++ if (pax_find_mirror_vma(vma))
35871 ++ BUG_ON(!trylock_page(new_page));
35872 ++#endif
35873 ++
35874 + if (old_page) {
35875 + if (!PageAnon(old_page)) {
35876 + dec_mm_counter(mm, file_rss);
35877 +@@ -1947,6 +2134,10 @@ gotten:
35878 + page_remove_rmap(old_page, vma);
35879 + }
35880 +
35881 ++#ifdef CONFIG_PAX_SEGMEXEC
35882 ++ pax_mirror_anon_pte(vma, address, new_page, ptl);
35883 ++#endif
35884 ++
35885 + /* Free the old page.. */
35886 + new_page = old_page;
35887 + ret |= VM_FAULT_WRITE;
35888 +@@ -2206,6 +2397,7 @@ int vmtruncate(struct inode * inode, lof
35889 + unsigned long limit;
35890 +
35891 + limit = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
35892 ++ gr_learn_resource(current, RLIMIT_FSIZE, offset, 1);
35893 + if (limit != RLIM_INFINITY && offset > limit)
35894 + goto out_sig;
35895 + if (offset > inode->i_sb->s_maxbytes)
35896 +@@ -2357,6 +2549,11 @@ static int do_swap_page(struct mm_struct
35897 + swap_free(entry);
35898 + if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
35899 + remove_exclusive_swap_page(page);
35900 ++
35901 ++#ifdef CONFIG_PAX_SEGMEXEC
35902 ++ if (write_access || !pax_find_mirror_vma(vma))
35903 ++#endif
35904 ++
35905 + unlock_page(page);
35906 +
35907 + if (write_access) {
35908 +@@ -2368,6 +2565,11 @@ static int do_swap_page(struct mm_struct
35909 +
35910 + /* No need to invalidate - it was non-present before */
35911 + update_mmu_cache(vma, address, pte);
35912 ++
35913 ++#ifdef CONFIG_PAX_SEGMEXEC
35914 ++ pax_mirror_anon_pte(vma, address, page, ptl);
35915 ++#endif
35916 ++
35917 + unlock:
35918 + pte_unmap_unlock(page_table, ptl);
35919 + out:
35920 +@@ -2412,6 +2614,12 @@ static int do_anonymous_page(struct mm_s
35921 + page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
35922 + if (!pte_none(*page_table))
35923 + goto release;
35924 ++
35925 ++#ifdef CONFIG_PAX_SEGMEXEC
35926 ++ if (pax_find_mirror_vma(vma))
35927 ++ BUG_ON(!trylock_page(page));
35928 ++#endif
35929 ++
35930 + inc_mm_counter(mm, anon_rss);
35931 + SetPageSwapBacked(page);
35932 + lru_cache_add_active_or_unevictable(page, vma);
35933 +@@ -2420,6 +2628,11 @@ static int do_anonymous_page(struct mm_s
35934 +
35935 + /* No need to invalidate - it was non-present before */
35936 + update_mmu_cache(vma, address, entry);
35937 ++
35938 ++#ifdef CONFIG_PAX_SEGMEXEC
35939 ++ pax_mirror_anon_pte(vma, address, page, ptl);
35940 ++#endif
35941 ++
35942 + unlock:
35943 + pte_unmap_unlock(page_table, ptl);
35944 + return 0;
35945 +@@ -2556,6 +2769,12 @@ static int __do_fault(struct mm_struct *
35946 + */
35947 + /* Only go through if we didn't race with anybody else... */
35948 + if (likely(pte_same(*page_table, orig_pte))) {
35949 ++
35950 ++#ifdef CONFIG_PAX_SEGMEXEC
35951 ++ if (anon && pax_find_mirror_vma(vma))
35952 ++ BUG_ON(!trylock_page(page));
35953 ++#endif
35954 ++
35955 + flush_icache_page(vma, page);
35956 + entry = mk_pte(page, vma->vm_page_prot);
35957 + if (flags & FAULT_FLAG_WRITE)
35958 +@@ -2578,6 +2797,14 @@ static int __do_fault(struct mm_struct *
35959 +
35960 + /* no need to invalidate: a not-present page won't be cached */
35961 + update_mmu_cache(vma, address, entry);
35962 ++
35963 ++#ifdef CONFIG_PAX_SEGMEXEC
35964 ++ if (anon)
35965 ++ pax_mirror_anon_pte(vma, address, page, ptl);
35966 ++ else
35967 ++ pax_mirror_file_pte(vma, address, page, ptl);
35968 ++#endif
35969 ++
35970 + } else {
35971 + if (charged)
35972 + mem_cgroup_uncharge_page(page);
35973 +@@ -2711,6 +2938,12 @@ static inline int handle_pte_fault(struc
35974 + if (write_access)
35975 + flush_tlb_page(vma, address);
35976 + }
35977 ++
35978 ++#ifdef CONFIG_PAX_SEGMEXEC
35979 ++ pax_mirror_pte(vma, address, pte, pmd, ptl);
35980 ++ return 0;
35981 ++#endif
35982 ++
35983 + unlock:
35984 + pte_unmap_unlock(pte, ptl);
35985 + return 0;
35986 +@@ -2727,6 +2960,10 @@ int handle_mm_fault(struct mm_struct *mm
35987 + pmd_t *pmd;
35988 + pte_t *pte;
35989 +
35990 ++#ifdef CONFIG_PAX_SEGMEXEC
35991 ++ struct vm_area_struct *vma_m;
35992 ++#endif
35993 ++
35994 + __set_current_state(TASK_RUNNING);
35995 +
35996 + count_vm_event(PGFAULT);
35997 +@@ -2734,6 +2971,34 @@ int handle_mm_fault(struct mm_struct *mm
35998 + if (unlikely(is_vm_hugetlb_page(vma)))
35999 + return hugetlb_fault(mm, vma, address, write_access);
36000 +
36001 ++#ifdef CONFIG_PAX_SEGMEXEC
36002 ++ vma_m = pax_find_mirror_vma(vma);
36003 ++ if (vma_m) {
36004 ++ unsigned long address_m;
36005 ++ pgd_t *pgd_m;
36006 ++ pud_t *pud_m;
36007 ++ pmd_t *pmd_m;
36008 ++
36009 ++ if (vma->vm_start > vma_m->vm_start) {
36010 ++ address_m = address;
36011 ++ address -= SEGMEXEC_TASK_SIZE;
36012 ++ vma = vma_m;
36013 ++ } else
36014 ++ address_m = address + SEGMEXEC_TASK_SIZE;
36015 ++
36016 ++ pgd_m = pgd_offset(mm, address_m);
36017 ++ pud_m = pud_alloc(mm, pgd_m, address_m);
36018 ++ if (!pud_m)
36019 ++ return VM_FAULT_OOM;
36020 ++ pmd_m = pmd_alloc(mm, pud_m, address_m);
36021 ++ if (!pmd_m)
36022 ++ return VM_FAULT_OOM;
36023 ++ if (!pmd_present(*pmd_m) && __pte_alloc(mm, pmd_m, address_m))
36024 ++ return VM_FAULT_OOM;
36025 ++ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
36026 ++ }
36027 ++#endif
36028 ++
36029 + pgd = pgd_offset(mm, address);
36030 + pud = pud_alloc(mm, pgd, address);
36031 + if (!pud)
36032 +@@ -2831,7 +3096,7 @@ static int __init gate_vma_init(void)
36033 + gate_vma.vm_start = FIXADDR_USER_START;
36034 + gate_vma.vm_end = FIXADDR_USER_END;
36035 + gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36036 +- gate_vma.vm_page_prot = __P101;
36037 ++ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36038 + /*
36039 + * Make sure the vDSO gets into every core dump.
36040 + * Dumping its contents makes post-mortem fully interpretable later
36041 +diff -urNp linux-2.6.28/mm/mempolicy.c linux-2.6.28/mm/mempolicy.c
36042 +--- linux-2.6.28/mm/mempolicy.c 2008-12-24 18:26:37.000000000 -0500
36043 ++++ linux-2.6.28/mm/mempolicy.c 2009-01-11 07:20:06.000000000 -0500
36044 +@@ -551,6 +551,10 @@ static int mbind_range(struct vm_area_st
36045 + struct vm_area_struct *next;
36046 + int err;
36047 +
36048 ++#ifdef CONFIG_PAX_SEGMEXEC
36049 ++ struct vm_area_struct *vma_m;
36050 ++#endif
36051 ++
36052 + err = 0;
36053 + for (; vma && vma->vm_start < end; vma = next) {
36054 + next = vma->vm_next;
36055 +@@ -562,6 +566,16 @@ static int mbind_range(struct vm_area_st
36056 + err = policy_vma(vma, new);
36057 + if (err)
36058 + break;
36059 ++
36060 ++#ifdef CONFIG_PAX_SEGMEXEC
36061 ++ vma_m = pax_find_mirror_vma(vma);
36062 ++ if (vma_m) {
36063 ++ err = policy_vma(vma_m, new);
36064 ++ if (err)
36065 ++ break;
36066 ++ }
36067 ++#endif
36068 ++
36069 + }
36070 + return err;
36071 + }
36072 +@@ -954,6 +968,17 @@ static long do_mbind(unsigned long start
36073 +
36074 + if (end < start)
36075 + return -EINVAL;
36076 ++
36077 ++#ifdef CONFIG_PAX_SEGMEXEC
36078 ++ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
36079 ++ if (end > SEGMEXEC_TASK_SIZE)
36080 ++ return -EINVAL;
36081 ++ } else
36082 ++#endif
36083 ++
36084 ++ if (end > TASK_SIZE)
36085 ++ return -EINVAL;
36086 ++
36087 + if (end == start)
36088 + return 0;
36089 +
36090 +diff -urNp linux-2.6.28/mm/mlock.c linux-2.6.28/mm/mlock.c
36091 +--- linux-2.6.28/mm/mlock.c 2008-12-24 18:26:37.000000000 -0500
36092 ++++ linux-2.6.28/mm/mlock.c 2009-01-11 07:20:06.000000000 -0500
36093 +@@ -18,6 +18,7 @@
36094 + #include <linux/rmap.h>
36095 + #include <linux/mmzone.h>
36096 + #include <linux/hugetlb.h>
36097 ++#include <linux/grsecurity.h>
36098 +
36099 + #include "internal.h"
36100 +
36101 +@@ -492,6 +493,17 @@ static int do_mlock(unsigned long start,
36102 + return -EINVAL;
36103 + if (end == start)
36104 + return 0;
36105 ++
36106 ++#ifdef CONFIG_PAX_SEGMEXEC
36107 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
36108 ++ if (end > SEGMEXEC_TASK_SIZE)
36109 ++ return -EINVAL;
36110 ++ } else
36111 ++#endif
36112 ++
36113 ++ if (end > TASK_SIZE)
36114 ++ return -EINVAL;
36115 ++
36116 + vma = find_vma_prev(current->mm, start, &prev);
36117 + if (!vma || vma->vm_start > start)
36118 + return -ENOMEM;
36119 +@@ -551,6 +563,7 @@ asmlinkage long sys_mlock(unsigned long
36120 + lock_limit >>= PAGE_SHIFT;
36121 +
36122 + /* check against resource limits */
36123 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
36124 + if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
36125 + error = do_mlock(start, len, 1);
36126 + up_write(&current->mm->mmap_sem);
36127 +@@ -572,10 +585,10 @@ asmlinkage long sys_munlock(unsigned lon
36128 + static int do_mlockall(int flags)
36129 + {
36130 + struct vm_area_struct * vma, * prev = NULL;
36131 +- unsigned int def_flags = 0;
36132 ++ unsigned int def_flags = current->mm->def_flags & ~VM_LOCKED;
36133 +
36134 + if (flags & MCL_FUTURE)
36135 +- def_flags = VM_LOCKED;
36136 ++ def_flags |= VM_LOCKED;
36137 + current->mm->def_flags = def_flags;
36138 + if (flags == MCL_FUTURE)
36139 + goto out;
36140 +@@ -583,6 +596,12 @@ static int do_mlockall(int flags)
36141 + for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
36142 + unsigned int newflags;
36143 +
36144 ++#ifdef CONFIG_PAX_SEGMEXEC
36145 ++ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
36146 ++ break;
36147 ++#endif
36148 ++
36149 ++ BUG_ON(vma->vm_end > TASK_SIZE);
36150 + newflags = vma->vm_flags | VM_LOCKED;
36151 + if (!(flags & MCL_CURRENT))
36152 + newflags &= ~VM_LOCKED;
36153 +@@ -614,6 +633,7 @@ asmlinkage long sys_mlockall(int flags)
36154 + lock_limit >>= PAGE_SHIFT;
36155 +
36156 + ret = -ENOMEM;
36157 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm, 1);
36158 + if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
36159 + capable(CAP_IPC_LOCK))
36160 + ret = do_mlockall(flags);
36161 +diff -urNp linux-2.6.28/mm/mmap.c linux-2.6.28/mm/mmap.c
36162 +--- linux-2.6.28/mm/mmap.c 2008-12-24 18:26:37.000000000 -0500
36163 ++++ linux-2.6.28/mm/mmap.c 2009-01-11 07:20:06.000000000 -0500
36164 +@@ -27,6 +27,7 @@
36165 + #include <linux/mempolicy.h>
36166 + #include <linux/rmap.h>
36167 + #include <linux/mmu_notifier.h>
36168 ++#include <linux/grsecurity.h>
36169 +
36170 + #include <asm/uaccess.h>
36171 + #include <asm/cacheflush.h>
36172 +@@ -43,6 +44,16 @@
36173 + #define arch_rebalance_pgtables(addr, len) (addr)
36174 + #endif
36175 +
36176 ++static inline void verify_mm_writelocked(struct mm_struct *mm)
36177 ++{
36178 ++#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
36179 ++ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
36180 ++ up_read(&mm->mmap_sem);
36181 ++ BUG();
36182 ++ }
36183 ++#endif
36184 ++}
36185 ++
36186 + static void unmap_region(struct mm_struct *mm,
36187 + struct vm_area_struct *vma, struct vm_area_struct *prev,
36188 + unsigned long start, unsigned long end);
36189 +@@ -68,16 +79,25 @@ static void unmap_region(struct mm_struc
36190 + * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
36191 + *
36192 + */
36193 +-pgprot_t protection_map[16] = {
36194 ++pgprot_t protection_map[16] __read_only = {
36195 + __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
36196 + __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
36197 + };
36198 +
36199 + pgprot_t vm_get_page_prot(unsigned long vm_flags)
36200 + {
36201 +- return __pgprot(pgprot_val(protection_map[vm_flags &
36202 ++ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
36203 + (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
36204 + pgprot_val(arch_vm_get_page_prot(vm_flags)));
36205 ++
36206 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
36207 ++ if (!nx_enabled &&
36208 ++ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
36209 ++ (vm_flags & (VM_READ | VM_WRITE)))
36210 ++ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
36211 ++#endif
36212 ++
36213 ++ return prot;
36214 + }
36215 + EXPORT_SYMBOL(vm_get_page_prot);
36216 +
36217 +@@ -233,6 +253,7 @@ static struct vm_area_struct *remove_vma
36218 + struct vm_area_struct *next = vma->vm_next;
36219 +
36220 + might_sleep();
36221 ++ BUG_ON(vma->vm_mirror);
36222 + if (vma->vm_ops && vma->vm_ops->close)
36223 + vma->vm_ops->close(vma);
36224 + if (vma->vm_file) {
36225 +@@ -269,6 +290,7 @@ asmlinkage unsigned long sys_brk(unsigne
36226 + * not page aligned -Ram Gupta
36227 + */
36228 + rlim = current->signal->rlim[RLIMIT_DATA].rlim_cur;
36229 ++ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
36230 + if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
36231 + (mm->end_data - mm->start_data) > rlim)
36232 + goto out;
36233 +@@ -696,6 +718,12 @@ static int
36234 + can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
36235 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
36236 + {
36237 ++
36238 ++#ifdef CONFIG_PAX_SEGMEXEC
36239 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
36240 ++ return 0;
36241 ++#endif
36242 ++
36243 + if (is_mergeable_vma(vma, file, vm_flags) &&
36244 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
36245 + if (vma->vm_pgoff == vm_pgoff)
36246 +@@ -715,6 +743,12 @@ static int
36247 + can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
36248 + struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
36249 + {
36250 ++
36251 ++#ifdef CONFIG_PAX_SEGMEXEC
36252 ++ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
36253 ++ return 0;
36254 ++#endif
36255 ++
36256 + if (is_mergeable_vma(vma, file, vm_flags) &&
36257 + is_mergeable_anon_vma(anon_vma, vma->anon_vma)) {
36258 + pgoff_t vm_pglen;
36259 +@@ -757,12 +791,19 @@ can_vma_merge_after(struct vm_area_struc
36260 + struct vm_area_struct *vma_merge(struct mm_struct *mm,
36261 + struct vm_area_struct *prev, unsigned long addr,
36262 + unsigned long end, unsigned long vm_flags,
36263 +- struct anon_vma *anon_vma, struct file *file,
36264 ++ struct anon_vma *anon_vma, struct file *file,
36265 + pgoff_t pgoff, struct mempolicy *policy)
36266 + {
36267 + pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
36268 + struct vm_area_struct *area, *next;
36269 +
36270 ++#ifdef CONFIG_PAX_SEGMEXEC
36271 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
36272 ++ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
36273 ++
36274 ++ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
36275 ++#endif
36276 ++
36277 + /*
36278 + * We later require that vma->vm_flags == vm_flags,
36279 + * so this tests vma->vm_flags & VM_SPECIAL, too.
36280 +@@ -778,6 +819,15 @@ struct vm_area_struct *vma_merge(struct
36281 + if (next && next->vm_end == end) /* cases 6, 7, 8 */
36282 + next = next->vm_next;
36283 +
36284 ++#ifdef CONFIG_PAX_SEGMEXEC
36285 ++ if (prev)
36286 ++ prev_m = pax_find_mirror_vma(prev);
36287 ++ if (area)
36288 ++ area_m = pax_find_mirror_vma(area);
36289 ++ if (next)
36290 ++ next_m = pax_find_mirror_vma(next);
36291 ++#endif
36292 ++
36293 + /*
36294 + * Can it merge with the predecessor?
36295 + */
36296 +@@ -797,9 +847,24 @@ struct vm_area_struct *vma_merge(struct
36297 + /* cases 1, 6 */
36298 + vma_adjust(prev, prev->vm_start,
36299 + next->vm_end, prev->vm_pgoff, NULL);
36300 +- } else /* cases 2, 5, 7 */
36301 ++
36302 ++#ifdef CONFIG_PAX_SEGMEXEC
36303 ++ if (prev_m)
36304 ++ vma_adjust(prev_m, prev_m->vm_start,
36305 ++ next_m->vm_end, prev_m->vm_pgoff, NULL);
36306 ++#endif
36307 ++
36308 ++ } else { /* cases 2, 5, 7 */
36309 + vma_adjust(prev, prev->vm_start,
36310 + end, prev->vm_pgoff, NULL);
36311 ++
36312 ++#ifdef CONFIG_PAX_SEGMEXEC
36313 ++ if (prev_m)
36314 ++ vma_adjust(prev_m, prev_m->vm_start,
36315 ++ end_m, prev_m->vm_pgoff, NULL);
36316 ++#endif
36317 ++
36318 ++ }
36319 + return prev;
36320 + }
36321 +
36322 +@@ -810,12 +875,27 @@ struct vm_area_struct *vma_merge(struct
36323 + mpol_equal(policy, vma_policy(next)) &&
36324 + can_vma_merge_before(next, vm_flags,
36325 + anon_vma, file, pgoff+pglen)) {
36326 +- if (prev && addr < prev->vm_end) /* case 4 */
36327 ++ if (prev && addr < prev->vm_end) { /* case 4 */
36328 + vma_adjust(prev, prev->vm_start,
36329 + addr, prev->vm_pgoff, NULL);
36330 +- else /* cases 3, 8 */
36331 ++
36332 ++#ifdef CONFIG_PAX_SEGMEXEC
36333 ++ if (prev_m)
36334 ++ vma_adjust(prev_m, prev_m->vm_start,
36335 ++ addr_m, prev_m->vm_pgoff, NULL);
36336 ++#endif
36337 ++
36338 ++ } else { /* cases 3, 8 */
36339 + vma_adjust(area, addr, next->vm_end,
36340 + next->vm_pgoff - pglen, NULL);
36341 ++
36342 ++#ifdef CONFIG_PAX_SEGMEXEC
36343 ++ if (area_m)
36344 ++ vma_adjust(area_m, addr_m, next_m->vm_end,
36345 ++ next_m->vm_pgoff - pglen, NULL);
36346 ++#endif
36347 ++
36348 ++ }
36349 + return area;
36350 + }
36351 +
36352 +@@ -890,14 +970,11 @@ none:
36353 + void vm_stat_account(struct mm_struct *mm, unsigned long flags,
36354 + struct file *file, long pages)
36355 + {
36356 +- const unsigned long stack_flags
36357 +- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
36358 +-
36359 + if (file) {
36360 + mm->shared_vm += pages;
36361 + if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
36362 + mm->exec_vm += pages;
36363 +- } else if (flags & stack_flags)
36364 ++ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
36365 + mm->stack_vm += pages;
36366 + if (flags & (VM_RESERVED|VM_IO))
36367 + mm->reserved_vm += pages;
36368 +@@ -925,7 +1002,7 @@ unsigned long do_mmap_pgoff(struct file
36369 + * (the exception is when the underlying filesystem is noexec
36370 + * mounted, in which case we dont add PROT_EXEC.)
36371 + */
36372 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
36373 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
36374 + if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
36375 + prot |= PROT_EXEC;
36376 +
36377 +@@ -935,15 +1012,15 @@ unsigned long do_mmap_pgoff(struct file
36378 + if (!(flags & MAP_FIXED))
36379 + addr = round_hint_to_min(addr);
36380 +
36381 +- error = arch_mmap_check(addr, len, flags);
36382 +- if (error)
36383 +- return error;
36384 +-
36385 + /* Careful about overflows.. */
36386 + len = PAGE_ALIGN(len);
36387 + if (!len || len > TASK_SIZE)
36388 + return -ENOMEM;
36389 +
36390 ++ error = arch_mmap_check(addr, len, flags);
36391 ++ if (error)
36392 ++ return error;
36393 ++
36394 + /* offset overflow? */
36395 + if ((pgoff + (len >> PAGE_SHIFT)) < pgoff)
36396 + return -EOVERFLOW;
36397 +@@ -955,7 +1032,7 @@ unsigned long do_mmap_pgoff(struct file
36398 + /* Obtain the address to map to. we verify (or select) it and ensure
36399 + * that it represents a valid section of the address space.
36400 + */
36401 +- addr = get_unmapped_area(file, addr, len, pgoff, flags);
36402 ++ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
36403 + if (addr & ~PAGE_MASK)
36404 + return addr;
36405 +
36406 +@@ -966,6 +1043,26 @@ unsigned long do_mmap_pgoff(struct file
36407 + vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
36408 + mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
36409 +
36410 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
36411 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
36412 ++
36413 ++#ifdef CONFIG_PAX_MPROTECT
36414 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
36415 ++ if ((prot & (PROT_WRITE | PROT_EXEC)) != PROT_EXEC)
36416 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
36417 ++ else
36418 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
36419 ++ }
36420 ++#endif
36421 ++
36422 ++ }
36423 ++#endif
36424 ++
36425 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
36426 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
36427 ++ vm_flags &= ~VM_PAGEEXEC;
36428 ++#endif
36429 ++
36430 + if (flags & MAP_LOCKED) {
36431 + if (!can_do_mlock())
36432 + return -EPERM;
36433 +@@ -979,6 +1076,7 @@ unsigned long do_mmap_pgoff(struct file
36434 + locked += mm->locked_vm;
36435 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
36436 + lock_limit >>= PAGE_SHIFT;
36437 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
36438 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
36439 + return -EAGAIN;
36440 + }
36441 +@@ -1051,6 +1149,9 @@ unsigned long do_mmap_pgoff(struct file
36442 + if (error)
36443 + return error;
36444 +
36445 ++ if (!gr_acl_handle_mmap(file, prot))
36446 ++ return -EACCES;
36447 ++
36448 + return mmap_region(file, addr, len, flags, vm_flags, pgoff,
36449 + accountable);
36450 + }
36451 +@@ -1064,10 +1165,10 @@ EXPORT_SYMBOL(do_mmap_pgoff);
36452 + */
36453 + int vma_wants_writenotify(struct vm_area_struct *vma)
36454 + {
36455 +- unsigned int vm_flags = vma->vm_flags;
36456 ++ unsigned long vm_flags = vma->vm_flags;
36457 +
36458 + /* If it was private or non-writable, the write bit is already clear */
36459 +- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
36460 ++ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
36461 + return 0;
36462 +
36463 + /* The backer wishes to know when pages are first written to? */
36464 +@@ -1101,14 +1202,24 @@ unsigned long mmap_region(struct file *f
36465 + unsigned long charged = 0;
36466 + struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
36467 +
36468 ++#ifdef CONFIG_PAX_SEGMEXEC
36469 ++ struct vm_area_struct *vma_m = NULL;
36470 ++#endif
36471 ++
36472 ++ /*
36473 ++ * mm->mmap_sem is required to protect against another thread
36474 ++ * changing the mappings in case we sleep.
36475 ++ */
36476 ++ verify_mm_writelocked(mm);
36477 ++
36478 + /* Clear old maps */
36479 + error = -ENOMEM;
36480 +-munmap_back:
36481 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
36482 + if (vma && vma->vm_start < addr + len) {
36483 + if (do_munmap(mm, addr, len))
36484 + return -ENOMEM;
36485 +- goto munmap_back;
36486 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
36487 ++ BUG_ON(vma && vma->vm_start < addr + len);
36488 + }
36489 +
36490 + /* Check against address space limit. */
36491 +@@ -1157,6 +1268,16 @@ munmap_back:
36492 + goto unacct_error;
36493 + }
36494 +
36495 ++#ifdef CONFIG_PAX_SEGMEXEC
36496 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
36497 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
36498 ++ if (!vma_m) {
36499 ++ error = -ENOMEM;
36500 ++ goto free_vma;
36501 ++ }
36502 ++ }
36503 ++#endif
36504 ++
36505 + vma->vm_mm = mm;
36506 + vma->vm_start = addr;
36507 + vma->vm_end = addr + len;
36508 +@@ -1179,6 +1300,19 @@ munmap_back:
36509 + error = file->f_op->mmap(file, vma);
36510 + if (error)
36511 + goto unmap_and_free_vma;
36512 ++
36513 ++#ifdef CONFIG_PAX_SEGMEXEC
36514 ++ if (vma_m && (vm_flags & VM_EXECUTABLE))
36515 ++ added_exe_file_vma(mm);
36516 ++#endif
36517 ++
36518 ++#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
36519 ++ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
36520 ++ vma->vm_flags |= VM_PAGEEXEC;
36521 ++ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
36522 ++ }
36523 ++#endif
36524 ++
36525 + if (vm_flags & VM_EXECUTABLE)
36526 + added_exe_file_vma(mm);
36527 + } else if (vm_flags & VM_SHARED) {
36528 +@@ -1211,12 +1345,29 @@ munmap_back:
36529 + vma->vm_flags, NULL, file, pgoff, vma_policy(vma))) {
36530 + mpol_put(vma_policy(vma));
36531 + kmem_cache_free(vm_area_cachep, vma);
36532 ++ vma = NULL;
36533 + fput(file);
36534 ++
36535 ++#ifdef CONFIG_PAX_SEGMEXEC
36536 ++ if (vma_m) {
36537 ++ kmem_cache_free(vm_area_cachep, vma_m);
36538 ++
36539 ++ if (vm_flags & VM_EXECUTABLE)
36540 ++ removed_exe_file_vma(mm);
36541 ++ }
36542 ++#endif
36543 ++
36544 + if (vm_flags & VM_EXECUTABLE)
36545 + removed_exe_file_vma(mm);
36546 + } else {
36547 + vma_link(mm, vma, prev, rb_link, rb_parent);
36548 + file = vma->vm_file;
36549 ++
36550 ++#ifdef CONFIG_PAX_SEGMEXEC
36551 ++ if (vma_m)
36552 ++ pax_mirror_vma(vma_m, vma);
36553 ++#endif
36554 ++
36555 + }
36556 +
36557 + /* Once vma denies write, undo our temporary denial count */
36558 +@@ -1225,6 +1376,7 @@ munmap_back:
36559 + out:
36560 + mm->total_vm += len >> PAGE_SHIFT;
36561 + vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
36562 ++ track_exec_limit(mm, addr, addr + len, vm_flags);
36563 + if (vm_flags & VM_LOCKED) {
36564 + /*
36565 + * makes pages present; downgrades, drops, reacquires mmap_sem
36566 +@@ -1247,6 +1399,12 @@ unmap_and_free_vma:
36567 + unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
36568 + charged = 0;
36569 + free_vma:
36570 ++
36571 ++#ifdef CONFIG_PAX_SEGMEXEC
36572 ++ if (vma_m)
36573 ++ kmem_cache_free(vm_area_cachep, vma_m);
36574 ++#endif
36575 ++
36576 + kmem_cache_free(vm_area_cachep, vma);
36577 + unacct_error:
36578 + if (charged)
36579 +@@ -1280,6 +1438,10 @@ arch_get_unmapped_area(struct file *filp
36580 + if (flags & MAP_FIXED)
36581 + return addr;
36582 +
36583 ++#ifdef CONFIG_PAX_RANDMMAP
36584 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
36585 ++#endif
36586 ++
36587 + if (addr) {
36588 + addr = PAGE_ALIGN(addr);
36589 + vma = find_vma(mm, addr);
36590 +@@ -1288,10 +1450,10 @@ arch_get_unmapped_area(struct file *filp
36591 + return addr;
36592 + }
36593 + if (len > mm->cached_hole_size) {
36594 +- start_addr = addr = mm->free_area_cache;
36595 ++ start_addr = addr = mm->free_area_cache;
36596 + } else {
36597 +- start_addr = addr = TASK_UNMAPPED_BASE;
36598 +- mm->cached_hole_size = 0;
36599 ++ start_addr = addr = mm->mmap_base;
36600 ++ mm->cached_hole_size = 0;
36601 + }
36602 +
36603 + full_search:
36604 +@@ -1302,9 +1464,8 @@ full_search:
36605 + * Start a new search - just in case we missed
36606 + * some holes.
36607 + */
36608 +- if (start_addr != TASK_UNMAPPED_BASE) {
36609 +- addr = TASK_UNMAPPED_BASE;
36610 +- start_addr = addr;
36611 ++ if (start_addr != mm->mmap_base) {
36612 ++ start_addr = addr = mm->mmap_base;
36613 + mm->cached_hole_size = 0;
36614 + goto full_search;
36615 + }
36616 +@@ -1326,10 +1487,16 @@ full_search:
36617 +
36618 + void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
36619 + {
36620 ++
36621 ++#ifdef CONFIG_PAX_SEGMEXEC
36622 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
36623 ++ return;
36624 ++#endif
36625 ++
36626 + /*
36627 + * Is this a new hole at the lowest possible address?
36628 + */
36629 +- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache) {
36630 ++ if (addr >= mm->mmap_base && addr < mm->free_area_cache) {
36631 + mm->free_area_cache = addr;
36632 + mm->cached_hole_size = ~0UL;
36633 + }
36634 +@@ -1347,7 +1514,7 @@ arch_get_unmapped_area_topdown(struct fi
36635 + {
36636 + struct vm_area_struct *vma;
36637 + struct mm_struct *mm = current->mm;
36638 +- unsigned long addr = addr0;
36639 ++ unsigned long base = mm->mmap_base, addr = addr0;
36640 +
36641 + /* requested length too big for entire address space */
36642 + if (len > TASK_SIZE)
36643 +@@ -1356,6 +1523,10 @@ arch_get_unmapped_area_topdown(struct fi
36644 + if (flags & MAP_FIXED)
36645 + return addr;
36646 +
36647 ++#ifdef CONFIG_PAX_RANDMMAP
36648 ++ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
36649 ++#endif
36650 ++
36651 + /* requesting a specific address */
36652 + if (addr) {
36653 + addr = PAGE_ALIGN(addr);
36654 +@@ -1413,13 +1584,21 @@ bottomup:
36655 + * can happen with large stack limits and large mmap()
36656 + * allocations.
36657 + */
36658 ++ mm->mmap_base = TASK_UNMAPPED_BASE;
36659 ++
36660 ++#ifdef CONFIG_PAX_RANDMMAP
36661 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
36662 ++ mm->mmap_base += mm->delta_mmap;
36663 ++#endif
36664 ++
36665 ++ mm->free_area_cache = mm->mmap_base;
36666 + mm->cached_hole_size = ~0UL;
36667 +- mm->free_area_cache = TASK_UNMAPPED_BASE;
36668 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
36669 + /*
36670 + * Restore the topdown base:
36671 + */
36672 +- mm->free_area_cache = mm->mmap_base;
36673 ++ mm->mmap_base = base;
36674 ++ mm->free_area_cache = base;
36675 + mm->cached_hole_size = ~0UL;
36676 +
36677 + return addr;
36678 +@@ -1428,6 +1607,12 @@ bottomup:
36679 +
36680 + void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
36681 + {
36682 ++
36683 ++#ifdef CONFIG_PAX_SEGMEXEC
36684 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
36685 ++ return;
36686 ++#endif
36687 ++
36688 + /*
36689 + * Is this a new hole at the highest possible address?
36690 + */
36691 +@@ -1435,8 +1620,10 @@ void arch_unmap_area_topdown(struct mm_s
36692 + mm->free_area_cache = addr;
36693 +
36694 + /* dont allow allocations above current base */
36695 +- if (mm->free_area_cache > mm->mmap_base)
36696 ++ if (mm->free_area_cache > mm->mmap_base) {
36697 + mm->free_area_cache = mm->mmap_base;
36698 ++ mm->cached_hole_size = ~0UL;
36699 ++ }
36700 + }
36701 +
36702 + unsigned long
36703 +@@ -1536,6 +1723,27 @@ out:
36704 + return prev ? prev->vm_next : vma;
36705 + }
36706 +
36707 ++#ifdef CONFIG_PAX_SEGMEXEC
36708 ++struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
36709 ++{
36710 ++ struct vm_area_struct *vma_m;
36711 ++
36712 ++ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
36713 ++ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
36714 ++ BUG_ON(vma->vm_mirror);
36715 ++ return NULL;
36716 ++ }
36717 ++ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
36718 ++ vma_m = vma->vm_mirror;
36719 ++ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
36720 ++ BUG_ON(vma->vm_file != vma_m->vm_file);
36721 ++ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
36722 ++ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff || vma->anon_vma != vma_m->anon_vma);
36723 ++ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
36724 ++ return vma_m;
36725 ++}
36726 ++#endif
36727 ++
36728 + /*
36729 + * Verify that the stack growth is acceptable and
36730 + * update accounting. This is shared with both the
36731 +@@ -1552,6 +1760,7 @@ static int acct_stack_growth(struct vm_a
36732 + return -ENOMEM;
36733 +
36734 + /* Stack limit test */
36735 ++ gr_learn_resource(current, RLIMIT_STACK, size, 1);
36736 + if (size > rlim[RLIMIT_STACK].rlim_cur)
36737 + return -ENOMEM;
36738 +
36739 +@@ -1561,6 +1770,7 @@ static int acct_stack_growth(struct vm_a
36740 + unsigned long limit;
36741 + locked = mm->locked_vm + grow;
36742 + limit = rlim[RLIMIT_MEMLOCK].rlim_cur >> PAGE_SHIFT;
36743 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
36744 + if (locked > limit && !capable(CAP_IPC_LOCK))
36745 + return -ENOMEM;
36746 + }
36747 +@@ -1575,7 +1785,7 @@ static int acct_stack_growth(struct vm_a
36748 + * Overcommit.. This must be the final test, as it will
36749 + * update security statistics.
36750 + */
36751 +- if (security_vm_enough_memory(grow))
36752 ++ if (security_vm_enough_memory_mm(mm, grow))
36753 + return -ENOMEM;
36754 +
36755 + /* Ok, everything looks good - let it rip */
36756 +@@ -1596,35 +1806,40 @@ static
36757 + #endif
36758 + int expand_upwards(struct vm_area_struct *vma, unsigned long address)
36759 + {
36760 +- int error;
36761 ++ int error, locknext;
36762 +
36763 + if (!(vma->vm_flags & VM_GROWSUP))
36764 + return -EFAULT;
36765 +
36766 ++ /* Also guard against wrapping around to address 0. */
36767 ++ if (address < PAGE_ALIGN(address+1))
36768 ++ address = PAGE_ALIGN(address+1);
36769 ++ else
36770 ++ return -ENOMEM;
36771 ++
36772 + /*
36773 + * We must make sure the anon_vma is allocated
36774 + * so that the anon_vma locking is not a noop.
36775 + */
36776 + if (unlikely(anon_vma_prepare(vma)))
36777 + return -ENOMEM;
36778 ++ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
36779 ++ if (locknext && unlikely(anon_vma_prepare(vma->vm_next)))
36780 ++ return -ENOMEM;
36781 + anon_vma_lock(vma);
36782 ++ if (locknext)
36783 ++ anon_vma_lock(vma->vm_next);
36784 +
36785 + /*
36786 + * vma->vm_start/vm_end cannot change under us because the caller
36787 + * is required to hold the mmap_sem in read mode. We need the
36788 +- * anon_vma lock to serialize against concurrent expand_stacks.
36789 +- * Also guard against wrapping around to address 0.
36790 ++ * anon_vma locks to serialize against concurrent expand_stacks
36791 ++ * and expand_upwards.
36792 + */
36793 +- if (address < PAGE_ALIGN(address+4))
36794 +- address = PAGE_ALIGN(address+4);
36795 +- else {
36796 +- anon_vma_unlock(vma);
36797 +- return -ENOMEM;
36798 +- }
36799 + error = 0;
36800 +
36801 + /* Somebody else might have raced and expanded it already */
36802 +- if (address > vma->vm_end) {
36803 ++ if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
36804 + unsigned long size, grow;
36805 +
36806 + size = address - vma->vm_start;
36807 +@@ -1634,6 +1849,8 @@ int expand_upwards(struct vm_area_struct
36808 + if (!error)
36809 + vma->vm_end = address;
36810 + }
36811 ++ if (locknext)
36812 ++ anon_vma_unlock(vma->vm_next);
36813 + anon_vma_unlock(vma);
36814 + return error;
36815 + }
36816 +@@ -1645,7 +1862,8 @@ int expand_upwards(struct vm_area_struct
36817 + static int expand_downwards(struct vm_area_struct *vma,
36818 + unsigned long address)
36819 + {
36820 +- int error;
36821 ++ int error, lockprev = 0;
36822 ++ struct vm_area_struct *prev = NULL;
36823 +
36824 + /*
36825 + * We must make sure the anon_vma is allocated
36826 +@@ -1659,6 +1877,15 @@ static int expand_downwards(struct vm_ar
36827 + if (error)
36828 + return error;
36829 +
36830 ++#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
36831 ++ find_vma_prev(vma->vm_mm, address, &prev);
36832 ++ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
36833 ++#endif
36834 ++ if (lockprev && unlikely(anon_vma_prepare(prev)))
36835 ++ return -ENOMEM;
36836 ++ if (lockprev)
36837 ++ anon_vma_lock(prev);
36838 ++
36839 + anon_vma_lock(vma);
36840 +
36841 + /*
36842 +@@ -1668,9 +1895,15 @@ static int expand_downwards(struct vm_ar
36843 + */
36844 +
36845 + /* Somebody else might have raced and expanded it already */
36846 +- if (address < vma->vm_start) {
36847 ++ if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
36848 + unsigned long size, grow;
36849 +
36850 ++#ifdef CONFIG_PAX_SEGMEXEC
36851 ++ struct vm_area_struct *vma_m;
36852 ++
36853 ++ vma_m = pax_find_mirror_vma(vma);
36854 ++#endif
36855 ++
36856 + size = vma->vm_end - address;
36857 + grow = (vma->vm_start - address) >> PAGE_SHIFT;
36858 +
36859 +@@ -1678,9 +1911,20 @@ static int expand_downwards(struct vm_ar
36860 + if (!error) {
36861 + vma->vm_start = address;
36862 + vma->vm_pgoff -= grow;
36863 ++ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
36864 ++
36865 ++#ifdef CONFIG_PAX_SEGMEXEC
36866 ++ if (vma_m) {
36867 ++ vma_m->vm_start -= grow << PAGE_SHIFT;
36868 ++ vma_m->vm_pgoff -= grow;
36869 ++ }
36870 ++#endif
36871 ++
36872 + }
36873 + }
36874 + anon_vma_unlock(vma);
36875 ++ if (lockprev)
36876 ++ anon_vma_unlock(prev);
36877 + return error;
36878 + }
36879 +
36880 +@@ -1756,6 +2000,13 @@ static void remove_vma_list(struct mm_st
36881 + do {
36882 + long nrpages = vma_pages(vma);
36883 +
36884 ++#ifdef CONFIG_PAX_SEGMEXEC
36885 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
36886 ++ vma = remove_vma(vma);
36887 ++ continue;
36888 ++ }
36889 ++#endif
36890 ++
36891 + mm->total_vm -= nrpages;
36892 + vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
36893 + vma = remove_vma(vma);
36894 +@@ -1800,6 +2051,16 @@ detach_vmas_to_be_unmapped(struct mm_str
36895 +
36896 + insertion_point = (prev ? &prev->vm_next : &mm->mmap);
36897 + do {
36898 ++
36899 ++#ifdef CONFIG_PAX_SEGMEXEC
36900 ++ if (vma->vm_mirror) {
36901 ++ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
36902 ++ vma->vm_mirror->vm_mirror = NULL;
36903 ++ vma->vm_mirror->vm_flags &= ~VM_EXEC;
36904 ++ vma->vm_mirror = NULL;
36905 ++ }
36906 ++#endif
36907 ++
36908 + rb_erase(&vma->vm_rb, &mm->mm_rb);
36909 + mm->map_count--;
36910 + tail_vma = vma;
36911 +@@ -1819,6 +2080,108 @@ detach_vmas_to_be_unmapped(struct mm_str
36912 + * Split a vma into two pieces at address 'addr', a new vma is allocated
36913 + * either for the first part or the tail.
36914 + */
36915 ++
36916 ++#ifdef CONFIG_PAX_SEGMEXEC
36917 ++int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
36918 ++ unsigned long addr, int new_below)
36919 ++{
36920 ++ struct mempolicy *pol;
36921 ++ struct vm_area_struct *new, *vma_m, *new_m = NULL;
36922 ++ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
36923 ++
36924 ++ if (is_vm_hugetlb_page(vma) && (addr & ~HPAGE_MASK))
36925 ++ return -EINVAL;
36926 ++
36927 ++ vma_m = pax_find_mirror_vma(vma);
36928 ++ if (vma_m) {
36929 ++ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
36930 ++ if (mm->map_count >= sysctl_max_map_count-1)
36931 ++ return -ENOMEM;
36932 ++ } else if (mm->map_count >= sysctl_max_map_count)
36933 ++ return -ENOMEM;
36934 ++
36935 ++ new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
36936 ++ if (!new)
36937 ++ return -ENOMEM;
36938 ++
36939 ++ if (vma_m) {
36940 ++ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
36941 ++ if (!new_m) {
36942 ++ kmem_cache_free(vm_area_cachep, new);
36943 ++ return -ENOMEM;
36944 ++ }
36945 ++ }
36946 ++
36947 ++ /* most fields are the same, copy all, and then fixup */
36948 ++ *new = *vma;
36949 ++
36950 ++ if (new_below)
36951 ++ new->vm_end = addr;
36952 ++ else {
36953 ++ new->vm_start = addr;
36954 ++ new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
36955 ++ }
36956 ++
36957 ++ if (vma_m) {
36958 ++ *new_m = *vma_m;
36959 ++ new_m->vm_mirror = new;
36960 ++ new->vm_mirror = new_m;
36961 ++
36962 ++ if (new_below)
36963 ++ new_m->vm_end = addr_m;
36964 ++ else {
36965 ++ new_m->vm_start = addr_m;
36966 ++ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
36967 ++ }
36968 ++ }
36969 ++
36970 ++ pol = mpol_dup(vma_policy(vma));
36971 ++ if (IS_ERR(pol)) {
36972 ++ if (new_m)
36973 ++ kmem_cache_free(vm_area_cachep, new_m);
36974 ++ kmem_cache_free(vm_area_cachep, new);
36975 ++ return PTR_ERR(pol);
36976 ++ }
36977 ++ vma_set_policy(new, pol);
36978 ++
36979 ++ if (new->vm_file) {
36980 ++ get_file(new->vm_file);
36981 ++ if (vma->vm_flags & VM_EXECUTABLE)
36982 ++ added_exe_file_vma(mm);
36983 ++ }
36984 ++
36985 ++ if (new->vm_ops && new->vm_ops->open)
36986 ++ new->vm_ops->open(new);
36987 ++
36988 ++ if (new_below)
36989 ++ vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff +
36990 ++ ((addr - new->vm_start) >> PAGE_SHIFT), new);
36991 ++ else
36992 ++ vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
36993 ++
36994 ++ if (vma_m) {
36995 ++ mpol_get(pol);
36996 ++ vma_set_policy(new_m, pol);
36997 ++
36998 ++ if (new_m->vm_file) {
36999 ++ get_file(new_m->vm_file);
37000 ++ if (vma_m->vm_flags & VM_EXECUTABLE)
37001 ++ added_exe_file_vma(mm);
37002 ++ }
37003 ++
37004 ++ if (new_m->vm_ops && new_m->vm_ops->open)
37005 ++ new_m->vm_ops->open(new_m);
37006 ++
37007 ++ if (new_below)
37008 ++ vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
37009 ++ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
37010 ++ else
37011 ++ vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
37012 ++ }
37013 ++
37014 ++ return 0;
37015 ++}
37016 ++#else
37017 + int split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
37018 + unsigned long addr, int new_below)
37019 + {
37020 +@@ -1870,17 +2233,37 @@ int split_vma(struct mm_struct * mm, str
37021 +
37022 + return 0;
37023 + }
37024 ++#endif
37025 +
37026 + /* Munmap is split into 2 main parts -- this part which finds
37027 + * what needs doing, and the areas themselves, which do the
37028 + * work. This now handles partial unmappings.
37029 + * Jeremy Fitzhardinge <jeremy@××××.org>
37030 + */
37031 ++#ifdef CONFIG_PAX_SEGMEXEC
37032 + int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
37033 + {
37034 ++ int ret = __do_munmap(mm, start, len);
37035 ++ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
37036 ++ return ret;
37037 ++
37038 ++ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
37039 ++}
37040 ++
37041 ++int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
37042 ++#else
37043 ++int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
37044 ++#endif
37045 ++{
37046 + unsigned long end;
37047 + struct vm_area_struct *vma, *prev, *last;
37048 +
37049 ++ /*
37050 ++ * mm->mmap_sem is required to protect against another thread
37051 ++ * changing the mappings in case we sleep.
37052 ++ */
37053 ++ verify_mm_writelocked(mm);
37054 ++
37055 + if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
37056 + return -EINVAL;
37057 +
37058 +@@ -1944,6 +2327,8 @@ int do_munmap(struct mm_struct *mm, unsi
37059 + /* Fix up all other VM information */
37060 + remove_vma_list(mm, vma);
37061 +
37062 ++ track_exec_limit(mm, start, end, 0UL);
37063 ++
37064 + return 0;
37065 + }
37066 +
37067 +@@ -1956,22 +2341,18 @@ asmlinkage long sys_munmap(unsigned long
37068 +
37069 + profile_munmap(addr);
37070 +
37071 ++#ifdef CONFIG_PAX_SEGMEXEC
37072 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
37073 ++ (len > SEGMEXEC_TASK_SIZE || addr > SEGMEXEC_TASK_SIZE-len))
37074 ++ return -EINVAL;
37075 ++#endif
37076 ++
37077 + down_write(&mm->mmap_sem);
37078 + ret = do_munmap(mm, addr, len);
37079 + up_write(&mm->mmap_sem);
37080 + return ret;
37081 + }
37082 +
37083 +-static inline void verify_mm_writelocked(struct mm_struct *mm)
37084 +-{
37085 +-#ifdef CONFIG_DEBUG_VM
37086 +- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
37087 +- WARN_ON(1);
37088 +- up_read(&mm->mmap_sem);
37089 +- }
37090 +-#endif
37091 +-}
37092 +-
37093 + /*
37094 + * this is really a simplified "do_mmap". it only handles
37095 + * anonymous maps. eventually we may be able to do some
37096 +@@ -1985,6 +2366,11 @@ unsigned long do_brk(unsigned long addr,
37097 + struct rb_node ** rb_link, * rb_parent;
37098 + pgoff_t pgoff = addr >> PAGE_SHIFT;
37099 + int error;
37100 ++ unsigned long charged;
37101 ++
37102 ++#ifdef CONFIG_PAX_SEGMEXEC
37103 ++ struct vm_area_struct *vma_m = NULL;
37104 ++#endif
37105 +
37106 + len = PAGE_ALIGN(len);
37107 + if (!len)
37108 +@@ -2002,19 +2388,34 @@ unsigned long do_brk(unsigned long addr,
37109 +
37110 + flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
37111 +
37112 ++#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
37113 ++ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
37114 ++ flags &= ~VM_EXEC;
37115 ++
37116 ++#ifdef CONFIG_PAX_MPROTECT
37117 ++ if (mm->pax_flags & MF_PAX_MPROTECT)
37118 ++ flags &= ~VM_MAYEXEC;
37119 ++#endif
37120 ++
37121 ++ }
37122 ++#endif
37123 ++
37124 + error = arch_mmap_check(addr, len, flags);
37125 + if (error)
37126 + return error;
37127 +
37128 ++ charged = len >> PAGE_SHIFT;
37129 ++
37130 + /*
37131 + * mlock MCL_FUTURE?
37132 + */
37133 + if (mm->def_flags & VM_LOCKED) {
37134 + unsigned long locked, lock_limit;
37135 +- locked = len >> PAGE_SHIFT;
37136 ++ locked = charged;
37137 + locked += mm->locked_vm;
37138 + lock_limit = current->signal->rlim[RLIMIT_MEMLOCK].rlim_cur;
37139 + lock_limit >>= PAGE_SHIFT;
37140 ++ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
37141 + if (locked > lock_limit && !capable(CAP_IPC_LOCK))
37142 + return -EAGAIN;
37143 + }
37144 +@@ -2028,22 +2429,22 @@ unsigned long do_brk(unsigned long addr,
37145 + /*
37146 + * Clear old maps. this also does some error checking for us
37147 + */
37148 +- munmap_back:
37149 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
37150 + if (vma && vma->vm_start < addr + len) {
37151 + if (do_munmap(mm, addr, len))
37152 + return -ENOMEM;
37153 +- goto munmap_back;
37154 ++ vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
37155 ++ BUG_ON(vma && vma->vm_start < addr + len);
37156 + }
37157 +
37158 + /* Check against address space limits *after* clearing old maps... */
37159 +- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
37160 ++ if (!may_expand_vm(mm, charged))
37161 + return -ENOMEM;
37162 +
37163 + if (mm->map_count > sysctl_max_map_count)
37164 + return -ENOMEM;
37165 +
37166 +- if (security_vm_enough_memory(len >> PAGE_SHIFT))
37167 ++ if (security_vm_enough_memory(charged))
37168 + return -ENOMEM;
37169 +
37170 + /* Can we just expand an old private anonymous mapping? */
37171 +@@ -2057,10 +2458,21 @@ unsigned long do_brk(unsigned long addr,
37172 + */
37173 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
37174 + if (!vma) {
37175 +- vm_unacct_memory(len >> PAGE_SHIFT);
37176 ++ vm_unacct_memory(charged);
37177 + return -ENOMEM;
37178 + }
37179 +
37180 ++#ifdef CONFIG_PAX_SEGMEXEC
37181 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (flags & VM_EXEC)) {
37182 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
37183 ++ if (!vma_m) {
37184 ++ kmem_cache_free(vm_area_cachep, vma);
37185 ++ vm_unacct_memory(charged);
37186 ++ return -ENOMEM;
37187 ++ }
37188 ++ }
37189 ++#endif
37190 ++
37191 + vma->vm_mm = mm;
37192 + vma->vm_start = addr;
37193 + vma->vm_end = addr + len;
37194 +@@ -2069,11 +2481,12 @@ unsigned long do_brk(unsigned long addr,
37195 + vma->vm_page_prot = vm_get_page_prot(flags);
37196 + vma_link(mm, vma, prev, rb_link, rb_parent);
37197 + out:
37198 +- mm->total_vm += len >> PAGE_SHIFT;
37199 ++ mm->total_vm += charged;
37200 + if (flags & VM_LOCKED) {
37201 + if (!mlock_vma_pages_range(vma, addr, addr + len))
37202 +- mm->locked_vm += (len >> PAGE_SHIFT);
37203 ++ mm->locked_vm += charged;
37204 + }
37205 ++ track_exec_limit(mm, addr, addr + len, flags);
37206 + return addr;
37207 + }
37208 +
37209 +@@ -2114,8 +2527,10 @@ void exit_mmap(struct mm_struct *mm)
37210 + * Walk the list again, actually closing and freeing it,
37211 + * with preemption enabled, without holding any MM locks.
37212 + */
37213 +- while (vma)
37214 ++ while (vma) {
37215 ++ vma->vm_mirror = NULL;
37216 + vma = remove_vma(vma);
37217 ++ }
37218 +
37219 + BUG_ON(mm->nr_ptes > (FIRST_USER_ADDRESS+PMD_SIZE-1)>>PMD_SHIFT);
37220 + }
37221 +@@ -2129,6 +2544,10 @@ int insert_vm_struct(struct mm_struct *
37222 + struct vm_area_struct * __vma, * prev;
37223 + struct rb_node ** rb_link, * rb_parent;
37224 +
37225 ++#ifdef CONFIG_PAX_SEGMEXEC
37226 ++ struct vm_area_struct *vma_m = NULL;
37227 ++#endif
37228 ++
37229 + /*
37230 + * The vm_pgoff of a purely anonymous vma should be irrelevant
37231 + * until its first write fault, when page's anon_vma and index
37232 +@@ -2151,7 +2570,22 @@ int insert_vm_struct(struct mm_struct *
37233 + if ((vma->vm_flags & VM_ACCOUNT) &&
37234 + security_vm_enough_memory_mm(mm, vma_pages(vma)))
37235 + return -ENOMEM;
37236 ++
37237 ++#ifdef CONFIG_PAX_SEGMEXEC
37238 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
37239 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
37240 ++ if (!vma_m)
37241 ++ return -ENOMEM;
37242 ++ }
37243 ++#endif
37244 ++
37245 + vma_link(mm, vma, prev, rb_link, rb_parent);
37246 ++
37247 ++#ifdef CONFIG_PAX_SEGMEXEC
37248 ++ if (vma_m)
37249 ++ pax_mirror_vma(vma_m, vma);
37250 ++#endif
37251 ++
37252 + return 0;
37253 + }
37254 +
37255 +@@ -2169,6 +2603,8 @@ struct vm_area_struct *copy_vma(struct v
37256 + struct rb_node **rb_link, *rb_parent;
37257 + struct mempolicy *pol;
37258 +
37259 ++ BUG_ON(vma->vm_mirror);
37260 ++
37261 + /*
37262 + * If anonymous vma has not yet been faulted, update new pgoff
37263 + * to match new location, to increase its chance of merging.
37264 +@@ -2212,6 +2648,35 @@ struct vm_area_struct *copy_vma(struct v
37265 + return new_vma;
37266 + }
37267 +
37268 ++#ifdef CONFIG_PAX_SEGMEXEC
37269 ++void pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
37270 ++{
37271 ++ struct vm_area_struct *prev_m;
37272 ++ struct rb_node **rb_link_m, *rb_parent_m;
37273 ++ struct mempolicy *pol_m;
37274 ++
37275 ++ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
37276 ++ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
37277 ++ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
37278 ++ *vma_m = *vma;
37279 ++ pol_m = vma_policy(vma_m);
37280 ++ mpol_get(pol_m);
37281 ++ vma_set_policy(vma_m, pol_m);
37282 ++ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
37283 ++ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
37284 ++ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
37285 ++ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
37286 ++ if (vma_m->vm_file)
37287 ++ get_file(vma_m->vm_file);
37288 ++ if (vma_m->vm_ops && vma_m->vm_ops->open)
37289 ++ vma_m->vm_ops->open(vma_m);
37290 ++ find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
37291 ++ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
37292 ++ vma_m->vm_mirror = vma;
37293 ++ vma->vm_mirror = vma_m;
37294 ++}
37295 ++#endif
37296 ++
37297 + /*
37298 + * Return true if the calling process may expand its vm space by the passed
37299 + * number of pages
37300 +@@ -2222,7 +2687,7 @@ int may_expand_vm(struct mm_struct *mm,
37301 + unsigned long lim;
37302 +
37303 + lim = current->signal->rlim[RLIMIT_AS].rlim_cur >> PAGE_SHIFT;
37304 +-
37305 ++ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
37306 + if (cur + npages > lim)
37307 + return 0;
37308 + return 1;
37309 +@@ -2291,6 +2756,15 @@ int install_special_mapping(struct mm_st
37310 + vma->vm_start = addr;
37311 + vma->vm_end = addr + len;
37312 +
37313 ++#ifdef CONFIG_PAX_MPROTECT
37314 ++ if (mm->pax_flags & MF_PAX_MPROTECT) {
37315 ++ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
37316 ++ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
37317 ++ else
37318 ++ vm_flags &= ~(VM_WRITE | VM_MAYWRITE);
37319 ++ }
37320 ++#endif
37321 ++
37322 + vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
37323 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
37324 +
37325 +diff -urNp linux-2.6.28/mm/mprotect.c linux-2.6.28/mm/mprotect.c
37326 +--- linux-2.6.28/mm/mprotect.c 2008-12-24 18:26:37.000000000 -0500
37327 ++++ linux-2.6.28/mm/mprotect.c 2009-01-11 07:20:50.000000000 -0500
37328 +@@ -22,10 +22,17 @@
37329 + #include <linux/swap.h>
37330 + #include <linux/swapops.h>
37331 + #include <linux/mmu_notifier.h>
37332 ++#include <linux/grsecurity.h>
37333 ++
37334 ++#ifdef CONFIG_PAX_MPROTECT
37335 ++#include <linux/elf.h>
37336 ++#endif
37337 ++
37338 + #include <asm/uaccess.h>
37339 + #include <asm/pgtable.h>
37340 + #include <asm/cacheflush.h>
37341 + #include <asm/tlbflush.h>
37342 ++#include <asm/mmu_context.h>
37343 +
37344 + #ifndef pgprot_modify
37345 + static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
37346 +@@ -133,6 +140,48 @@ static void change_protection(struct vm_
37347 + flush_tlb_range(vma, start, end);
37348 + }
37349 +
37350 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
37351 ++/* called while holding the mmap semaphor for writing except stack expansion */
37352 ++void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
37353 ++{
37354 ++ unsigned long oldlimit, newlimit = 0UL;
37355 ++
37356 ++ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || nx_enabled)
37357 ++ return;
37358 ++
37359 ++ spin_lock(&mm->page_table_lock);
37360 ++ oldlimit = mm->context.user_cs_limit;
37361 ++ if ((prot & VM_EXEC) && oldlimit < end)
37362 ++ /* USER_CS limit moved up */
37363 ++ newlimit = end;
37364 ++ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
37365 ++ /* USER_CS limit moved down */
37366 ++ newlimit = start;
37367 ++
37368 ++ if (newlimit) {
37369 ++ mm->context.user_cs_limit = newlimit;
37370 ++
37371 ++#ifdef CONFIG_SMP
37372 ++ wmb();
37373 ++ cpus_clear(mm->context.cpu_user_cs_mask);
37374 ++ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
37375 ++#endif
37376 ++
37377 ++ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
37378 ++ }
37379 ++ spin_unlock(&mm->page_table_lock);
37380 ++ if (newlimit == end) {
37381 ++ struct vm_area_struct *vma = find_vma(mm, oldlimit);
37382 ++
37383 ++ for (; vma && vma->vm_start < end; vma = vma->vm_next)
37384 ++ if (is_vm_hugetlb_page(vma))
37385 ++ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
37386 ++ else
37387 ++ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
37388 ++ }
37389 ++}
37390 ++#endif
37391 ++
37392 + int
37393 + mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
37394 + unsigned long start, unsigned long end, unsigned long newflags)
37395 +@@ -145,6 +194,14 @@ mprotect_fixup(struct vm_area_struct *vm
37396 + int error;
37397 + int dirty_accountable = 0;
37398 +
37399 ++#ifdef CONFIG_PAX_SEGMEXEC
37400 ++ struct vm_area_struct *vma_m = NULL;
37401 ++ unsigned long start_m, end_m;
37402 ++
37403 ++ start_m = start + SEGMEXEC_TASK_SIZE;
37404 ++ end_m = end + SEGMEXEC_TASK_SIZE;
37405 ++#endif
37406 ++
37407 + if (newflags == oldflags) {
37408 + *pprev = vma;
37409 + return 0;
37410 +@@ -165,6 +222,38 @@ mprotect_fixup(struct vm_area_struct *vm
37411 + }
37412 + }
37413 +
37414 ++#ifdef CONFIG_PAX_SEGMEXEC
37415 ++ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
37416 ++ if (start != vma->vm_start) {
37417 ++ error = split_vma(mm, vma, start, 1);
37418 ++ if (error)
37419 ++ goto fail;
37420 ++ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
37421 ++ *pprev = (*pprev)->vm_next;
37422 ++ }
37423 ++
37424 ++ if (end != vma->vm_end) {
37425 ++ error = split_vma(mm, vma, end, 0);
37426 ++ if (error)
37427 ++ goto fail;
37428 ++ }
37429 ++
37430 ++ if (pax_find_mirror_vma(vma)) {
37431 ++ error = __do_munmap(mm, start_m, end_m - start_m);
37432 ++ if (error)
37433 ++ goto fail;
37434 ++ } else {
37435 ++ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
37436 ++ if (!vma_m) {
37437 ++ error = -ENOMEM;
37438 ++ goto fail;
37439 ++ }
37440 ++ vma->vm_flags = newflags;
37441 ++ pax_mirror_vma(vma_m, vma);
37442 ++ }
37443 ++ }
37444 ++#endif
37445 ++
37446 + /*
37447 + * First try to merge with previous and/or next vma.
37448 + */
37449 +@@ -196,8 +285,14 @@ success:
37450 + * held in write mode.
37451 + */
37452 + vma->vm_flags = newflags;
37453 ++
37454 ++#ifdef CONFIG_PAX_MPROTECT
37455 ++ if (current->binfmt && current->binfmt->handle_mprotect)
37456 ++ current->binfmt->handle_mprotect(vma, newflags);
37457 ++#endif
37458 ++
37459 + vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
37460 +- vm_get_page_prot(newflags));
37461 ++ vm_get_page_prot(vma->vm_flags));
37462 +
37463 + if (vma_wants_writenotify(vma)) {
37464 + vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
37465 +@@ -238,6 +333,17 @@ sys_mprotect(unsigned long start, size_t
37466 + end = start + len;
37467 + if (end <= start)
37468 + return -ENOMEM;
37469 ++
37470 ++#ifdef CONFIG_PAX_SEGMEXEC
37471 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
37472 ++ if (end > SEGMEXEC_TASK_SIZE)
37473 ++ return -EINVAL;
37474 ++ } else
37475 ++#endif
37476 ++
37477 ++ if (end > TASK_SIZE)
37478 ++ return -EINVAL;
37479 ++
37480 + if (!arch_validate_prot(prot))
37481 + return -EINVAL;
37482 +
37483 +@@ -245,7 +351,7 @@ sys_mprotect(unsigned long start, size_t
37484 + /*
37485 + * Does the application expect PROT_READ to imply PROT_EXEC:
37486 + */
37487 +- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
37488 ++ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
37489 + prot |= PROT_EXEC;
37490 +
37491 + vm_flags = calc_vm_prot_bits(prot);
37492 +@@ -277,6 +383,16 @@ sys_mprotect(unsigned long start, size_t
37493 + if (start > vma->vm_start)
37494 + prev = vma;
37495 +
37496 ++ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
37497 ++ error = -EACCES;
37498 ++ goto out;
37499 ++ }
37500 ++
37501 ++#ifdef CONFIG_PAX_MPROTECT
37502 ++ if (current->binfmt && current->binfmt->handle_mprotect)
37503 ++ current->binfmt->handle_mprotect(vma, vm_flags);
37504 ++#endif
37505 ++
37506 + for (nstart = start ; ; ) {
37507 + unsigned long newflags;
37508 +
37509 +@@ -300,6 +416,9 @@ sys_mprotect(unsigned long start, size_t
37510 + error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
37511 + if (error)
37512 + goto out;
37513 ++
37514 ++ track_exec_limit(current->mm, nstart, tmp, vm_flags);
37515 ++
37516 + nstart = tmp;
37517 +
37518 + if (nstart < prev->vm_end)
37519 +diff -urNp linux-2.6.28/mm/mremap.c linux-2.6.28/mm/mremap.c
37520 +--- linux-2.6.28/mm/mremap.c 2008-12-24 18:26:37.000000000 -0500
37521 ++++ linux-2.6.28/mm/mremap.c 2009-01-11 07:20:06.000000000 -0500
37522 +@@ -113,6 +113,12 @@ static void move_ptes(struct vm_area_str
37523 + continue;
37524 + pte = ptep_clear_flush(vma, old_addr, old_pte);
37525 + pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
37526 ++
37527 ++#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
37528 ++ if (!nx_enabled && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
37529 ++ pte = pte_exprotect(pte);
37530 ++#endif
37531 ++
37532 + set_pte_at(mm, new_addr, new_pte, pte);
37533 + }
37534 +
37535 +@@ -262,6 +268,7 @@ unsigned long do_mremap(unsigned long ad
37536 + struct vm_area_struct *vma;
37537 + unsigned long ret = -EINVAL;
37538 + unsigned long charged = 0;
37539 ++ unsigned long pax_task_size = TASK_SIZE;
37540 +
37541 + if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
37542 + goto out;
37543 +@@ -280,6 +287,15 @@ unsigned long do_mremap(unsigned long ad
37544 + if (!new_len)
37545 + goto out;
37546 +
37547 ++#ifdef CONFIG_PAX_SEGMEXEC
37548 ++ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
37549 ++ pax_task_size = SEGMEXEC_TASK_SIZE;
37550 ++#endif
37551 ++
37552 ++ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
37553 ++ old_len > pax_task_size || addr > pax_task_size-old_len)
37554 ++ goto out;
37555 ++
37556 + /* new_addr is only valid if MREMAP_FIXED is specified */
37557 + if (flags & MREMAP_FIXED) {
37558 + if (new_addr & ~PAGE_MASK)
37559 +@@ -287,16 +303,13 @@ unsigned long do_mremap(unsigned long ad
37560 + if (!(flags & MREMAP_MAYMOVE))
37561 + goto out;
37562 +
37563 +- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
37564 ++ if (new_addr > pax_task_size - new_len)
37565 + goto out;
37566 +
37567 + /* Check if the location we're moving into overlaps the
37568 + * old location at all, and fail if it does.
37569 + */
37570 +- if ((new_addr <= addr) && (new_addr+new_len) > addr)
37571 +- goto out;
37572 +-
37573 +- if ((addr <= new_addr) && (addr+old_len) > new_addr)
37574 ++ if (addr + old_len > new_addr && new_addr + new_len > addr)
37575 + goto out;
37576 +
37577 + ret = security_file_mmap(NULL, 0, 0, 0, new_addr, 1);
37578 +@@ -334,6 +347,14 @@ unsigned long do_mremap(unsigned long ad
37579 + ret = -EINVAL;
37580 + goto out;
37581 + }
37582 ++
37583 ++#ifdef CONFIG_PAX_SEGMEXEC
37584 ++ if (pax_find_mirror_vma(vma)) {
37585 ++ ret = -EINVAL;
37586 ++ goto out;
37587 ++ }
37588 ++#endif
37589 ++
37590 + /* We can't remap across vm area boundaries */
37591 + if (old_len > vma->vm_end - addr)
37592 + goto out;
37593 +@@ -367,7 +388,7 @@ unsigned long do_mremap(unsigned long ad
37594 + if (old_len == vma->vm_end - addr &&
37595 + !((flags & MREMAP_FIXED) && (addr != new_addr)) &&
37596 + (old_len != new_len || !(flags & MREMAP_MAYMOVE))) {
37597 +- unsigned long max_addr = TASK_SIZE;
37598 ++ unsigned long max_addr = pax_task_size;
37599 + if (vma->vm_next)
37600 + max_addr = vma->vm_next->vm_start;
37601 + /* can we just expand the current mapping? */
37602 +@@ -385,6 +406,7 @@ unsigned long do_mremap(unsigned long ad
37603 + addr + new_len);
37604 + }
37605 + ret = addr;
37606 ++ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
37607 + goto out;
37608 + }
37609 + }
37610 +@@ -395,8 +417,8 @@ unsigned long do_mremap(unsigned long ad
37611 + */
37612 + ret = -ENOMEM;
37613 + if (flags & MREMAP_MAYMOVE) {
37614 ++ unsigned long map_flags = 0;
37615 + if (!(flags & MREMAP_FIXED)) {
37616 +- unsigned long map_flags = 0;
37617 + if (vma->vm_flags & VM_MAYSHARE)
37618 + map_flags |= MAP_SHARED;
37619 +
37620 +@@ -411,7 +433,12 @@ unsigned long do_mremap(unsigned long ad
37621 + if (ret)
37622 + goto out;
37623 + }
37624 ++ map_flags = vma->vm_flags;
37625 + ret = move_vma(vma, addr, old_len, new_len, new_addr);
37626 ++ if (!(ret & ~PAGE_MASK)) {
37627 ++ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
37628 ++ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
37629 ++ }
37630 + }
37631 + out:
37632 + if (ret & ~PAGE_MASK)
37633 +diff -urNp linux-2.6.28/mm/nommu.c linux-2.6.28/mm/nommu.c
37634 +--- linux-2.6.28/mm/nommu.c 2008-12-24 18:26:37.000000000 -0500
37635 ++++ linux-2.6.28/mm/nommu.c 2009-01-11 07:20:06.000000000 -0500
37636 +@@ -459,15 +459,6 @@ struct vm_area_struct *find_vma(struct m
37637 + }
37638 + EXPORT_SYMBOL(find_vma);
37639 +
37640 +-/*
37641 +- * find a VMA
37642 +- * - we don't extend stack VMAs under NOMMU conditions
37643 +- */
37644 +-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
37645 +-{
37646 +- return find_vma(mm, addr);
37647 +-}
37648 +-
37649 + int expand_stack(struct vm_area_struct *vma, unsigned long address)
37650 + {
37651 + return -ENOMEM;
37652 +diff -urNp linux-2.6.28/mm/page_alloc.c linux-2.6.28/mm/page_alloc.c
37653 +--- linux-2.6.28/mm/page_alloc.c 2008-12-24 18:26:37.000000000 -0500
37654 ++++ linux-2.6.28/mm/page_alloc.c 2009-01-11 07:20:06.000000000 -0500
37655 +@@ -512,9 +512,20 @@ static void free_pages_bulk(struct zone
37656 +
37657 + static void free_one_page(struct zone *zone, struct page *page, int order)
37658 + {
37659 ++
37660 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
37661 ++ unsigned long index = 1UL << order;
37662 ++#endif
37663 ++
37664 + spin_lock(&zone->lock);
37665 + zone_clear_flag(zone, ZONE_ALL_UNRECLAIMABLE);
37666 + zone->pages_scanned = 0;
37667 ++
37668 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
37669 ++ for (; index; --index)
37670 ++ sanitize_highpage(page + index - 1);
37671 ++#endif
37672 ++
37673 + __free_one_page(page, zone, order);
37674 + spin_unlock(&zone->lock);
37675 + }
37676 +@@ -635,8 +646,10 @@ static int prep_new_page(struct page *pa
37677 + arch_alloc_page(page, order);
37678 + kernel_map_pages(page, 1 << order, 1);
37679 +
37680 ++#ifndef CONFIG_PAX_MEMORY_SANITIZE
37681 + if (gfp_flags & __GFP_ZERO)
37682 + prep_zero_page(page, order, gfp_flags);
37683 ++#endif
37684 +
37685 + if (order && (gfp_flags & __GFP_COMP))
37686 + prep_compound_page(page, order);
37687 +@@ -1009,6 +1022,11 @@ static void free_hot_cold_page(struct pa
37688 + list_add(&page->lru, &pcp->list);
37689 + set_page_private(page, get_pageblock_migratetype(page));
37690 + pcp->count++;
37691 ++
37692 ++#ifdef CONFIG_PAX_MEMORY_SANITIZE
37693 ++ sanitize_highpage(page);
37694 ++#endif
37695 ++
37696 + if (pcp->count >= pcp->high) {
37697 + free_pages_bulk(zone, pcp->batch, &pcp->list, 0);
37698 + pcp->count -= pcp->batch;
37699 +diff -urNp linux-2.6.28/mm/rmap.c linux-2.6.28/mm/rmap.c
37700 +--- linux-2.6.28/mm/rmap.c 2008-12-24 18:26:37.000000000 -0500
37701 ++++ linux-2.6.28/mm/rmap.c 2009-01-11 07:20:06.000000000 -0500
37702 +@@ -103,6 +103,10 @@ int anon_vma_prepare(struct vm_area_stru
37703 + struct mm_struct *mm = vma->vm_mm;
37704 + struct anon_vma *allocated;
37705 +
37706 ++#ifdef CONFIG_PAX_SEGMEXEC
37707 ++ struct vm_area_struct *vma_m;
37708 ++#endif
37709 ++
37710 + anon_vma = find_mergeable_anon_vma(vma);
37711 + allocated = NULL;
37712 + if (!anon_vma) {
37713 +@@ -116,6 +120,15 @@ int anon_vma_prepare(struct vm_area_stru
37714 + /* page_table_lock to protect against threads */
37715 + spin_lock(&mm->page_table_lock);
37716 + if (likely(!vma->anon_vma)) {
37717 ++
37718 ++#ifdef CONFIG_PAX_SEGMEXEC
37719 ++ vma_m = pax_find_mirror_vma(vma);
37720 ++ if (vma_m) {
37721 ++ vma_m->anon_vma = anon_vma;
37722 ++ __anon_vma_link(vma_m);
37723 ++ }
37724 ++#endif
37725 ++
37726 + vma->anon_vma = anon_vma;
37727 + list_add_tail(&vma->anon_vma_node, &anon_vma->head);
37728 + allocated = NULL;
37729 +diff -urNp linux-2.6.28/mm/shmem.c linux-2.6.28/mm/shmem.c
37730 +--- linux-2.6.28/mm/shmem.c 2008-12-24 18:26:37.000000000 -0500
37731 ++++ linux-2.6.28/mm/shmem.c 2009-01-11 05:47:05.000000000 -0500
37732 +@@ -2486,7 +2486,7 @@ static struct file_system_type tmpfs_fs_
37733 + .get_sb = shmem_get_sb,
37734 + .kill_sb = kill_litter_super,
37735 + };
37736 +-static struct vfsmount *shm_mnt;
37737 ++struct vfsmount *shm_mnt;
37738 +
37739 + static int __init init_tmpfs(void)
37740 + {
37741 +diff -urNp linux-2.6.28/mm/slab.c linux-2.6.28/mm/slab.c
37742 +--- linux-2.6.28/mm/slab.c 2008-12-24 18:26:37.000000000 -0500
37743 ++++ linux-2.6.28/mm/slab.c 2009-01-11 07:20:06.000000000 -0500
37744 +@@ -305,7 +305,7 @@ struct kmem_list3 {
37745 + * Need this for bootstrapping a per node allocator.
37746 + */
37747 + #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
37748 +-struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
37749 ++struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
37750 + #define CACHE_CACHE 0
37751 + #define SIZE_AC MAX_NUMNODES
37752 + #define SIZE_L3 (2 * MAX_NUMNODES)
37753 +@@ -654,14 +654,14 @@ struct cache_names {
37754 + static struct cache_names __initdata cache_names[] = {
37755 + #define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
37756 + #include <linux/kmalloc_sizes.h>
37757 +- {NULL,}
37758 ++ {NULL, NULL}
37759 + #undef CACHE
37760 + };
37761 +
37762 + static struct arraycache_init initarray_cache __initdata =
37763 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
37764 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
37765 + static struct arraycache_init initarray_generic =
37766 +- { {0, BOOT_CPUCACHE_ENTRIES, 1, 0} };
37767 ++ { {0, BOOT_CPUCACHE_ENTRIES, 1, 0}, {NULL} };
37768 +
37769 + /* internal cache of cache description objs */
37770 + static struct kmem_cache cache_cache = {
37771 +@@ -2997,7 +2997,7 @@ retry:
37772 + * there must be at least one object available for
37773 + * allocation.
37774 + */
37775 +- BUG_ON(slabp->inuse < 0 || slabp->inuse >= cachep->num);
37776 ++ BUG_ON(slabp->inuse >= cachep->num);
37777 +
37778 + while (slabp->inuse < cachep->num && batchcount--) {
37779 + STATS_INC_ALLOCED(cachep);
37780 +@@ -4491,10 +4491,12 @@ static const struct file_operations proc
37781 +
37782 + static int __init slab_proc_init(void)
37783 + {
37784 ++#if !defined(CONFIG_GRKERNSEC_PROC_ADD)
37785 + proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
37786 + #ifdef CONFIG_DEBUG_SLAB_LEAK
37787 + proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
37788 + #endif
37789 ++#endif
37790 + return 0;
37791 + }
37792 + module_init(slab_proc_init);
37793 +diff -urNp linux-2.6.28/mm/slub.c linux-2.6.28/mm/slub.c
37794 +--- linux-2.6.28/mm/slub.c 2008-12-24 18:26:37.000000000 -0500
37795 ++++ linux-2.6.28/mm/slub.c 2009-01-11 07:14:43.000000000 -0500
37796 +@@ -4508,7 +4508,9 @@ static const struct file_operations proc
37797 +
37798 + static int __init slab_proc_init(void)
37799 + {
37800 ++#if !defined(CONFIG_GRKERNSEC_PROC_ADD)
37801 + proc_create("slabinfo",S_IWUSR|S_IRUGO,NULL,&proc_slabinfo_operations);
37802 ++#endif
37803 + return 0;
37804 + }
37805 + module_init(slab_proc_init);
37806 +diff -urNp linux-2.6.28/mm/tiny-shmem.c linux-2.6.28/mm/tiny-shmem.c
37807 +--- linux-2.6.28/mm/tiny-shmem.c 2008-12-24 18:26:37.000000000 -0500
37808 ++++ linux-2.6.28/mm/tiny-shmem.c 2009-01-11 05:47:05.000000000 -0500
37809 +@@ -26,7 +26,7 @@ static struct file_system_type tmpfs_fs_
37810 + .kill_sb = kill_litter_super,
37811 + };
37812 +
37813 +-static struct vfsmount *shm_mnt;
37814 ++struct vfsmount *shm_mnt;
37815 +
37816 + static int __init init_tmpfs(void)
37817 + {
37818 +diff -urNp linux-2.6.28/mm/util.c linux-2.6.28/mm/util.c
37819 +--- linux-2.6.28/mm/util.c 2008-12-24 18:26:37.000000000 -0500
37820 ++++ linux-2.6.28/mm/util.c 2009-01-11 07:20:06.000000000 -0500
37821 +@@ -167,6 +167,12 @@ EXPORT_SYMBOL(strndup_user);
37822 + void arch_pick_mmap_layout(struct mm_struct *mm)
37823 + {
37824 + mm->mmap_base = TASK_UNMAPPED_BASE;
37825 ++
37826 ++#ifdef CONFIG_PAX_RANDMMAP
37827 ++ if (mm->pax_flags & MF_PAX_RANDMMAP)
37828 ++ mm->mmap_base += mm->delta_mmap;
37829 ++#endif
37830 ++
37831 + mm->get_unmapped_area = arch_get_unmapped_area;
37832 + mm->unmap_area = arch_unmap_area;
37833 + }
37834 +diff -urNp linux-2.6.28/mm/vmalloc.c linux-2.6.28/mm/vmalloc.c
37835 +--- linux-2.6.28/mm/vmalloc.c 2008-12-24 18:26:37.000000000 -0500
37836 ++++ linux-2.6.28/mm/vmalloc.c 2009-01-11 07:20:06.000000000 -0500
37837 +@@ -89,6 +89,11 @@ static int vmap_pte_range(pmd_t *pmd, un
37838 + unsigned long end, pgprot_t prot, struct page **pages, int *nr)
37839 + {
37840 + pte_t *pte;
37841 ++ int ret = -ENOMEM;
37842 ++
37843 ++#ifdef CONFIG_PAX_KERNEXEC
37844 ++ unsigned long cr0;
37845 ++#endif
37846 +
37847 + /*
37848 + * nr is a running index into the array which helps higher level
37849 +@@ -98,17 +103,33 @@ static int vmap_pte_range(pmd_t *pmd, un
37850 + pte = pte_alloc_kernel(pmd, addr);
37851 + if (!pte)
37852 + return -ENOMEM;
37853 ++
37854 ++#ifdef CONFIG_PAX_KERNEXEC
37855 ++ pax_open_kernel(cr0);
37856 ++#endif
37857 ++
37858 + do {
37859 + struct page *page = pages[*nr];
37860 +
37861 +- if (WARN_ON(!pte_none(*pte)))
37862 +- return -EBUSY;
37863 +- if (WARN_ON(!page))
37864 +- return -ENOMEM;
37865 ++ if (WARN_ON(!pte_none(*pte))) {
37866 ++ ret = -EBUSY;
37867 ++ goto out;
37868 ++ }
37869 ++ if (WARN_ON(!page)) {
37870 ++ ret = -ENOMEM;
37871 ++ goto out;
37872 ++ }
37873 + set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
37874 + (*nr)++;
37875 + } while (pte++, addr += PAGE_SIZE, addr != end);
37876 +- return 0;
37877 ++ ret = 0;
37878 ++out:
37879 ++
37880 ++#ifdef CONFIG_PAX_KERNEXEC
37881 ++ pax_close_kernel(cr0);
37882 ++#endif
37883 ++
37884 ++ return ret;
37885 + }
37886 +
37887 + static int vmap_pmd_range(pud_t *pud, unsigned long addr,
37888 +@@ -1011,6 +1032,16 @@ static struct vm_struct *__get_vm_area_n
37889 + unsigned long align = 1;
37890 +
37891 + BUG_ON(in_interrupt());
37892 ++
37893 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37894 ++ if (flags & VM_KERNEXEC) {
37895 ++ if (start != VMALLOC_START || end != VMALLOC_END)
37896 ++ return NULL;
37897 ++ start = (unsigned long)MODULES_VADDR;
37898 ++ end = (unsigned long)MODULES_END;
37899 ++ }
37900 ++#endif
37901 ++
37902 + if (flags & VM_IOREMAP) {
37903 + int bit = fls(size);
37904 +
37905 +@@ -1234,6 +1265,11 @@ void *vmap(struct page **pages, unsigned
37906 + if (count > num_physpages)
37907 + return NULL;
37908 +
37909 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37910 ++ if (!(pgprot_val(prot) & _PAGE_NX))
37911 ++ flags |= VM_KERNEXEC;
37912 ++#endif
37913 ++
37914 + area = get_vm_area_caller((count << PAGE_SHIFT), flags,
37915 + __builtin_return_address(0));
37916 + if (!area)
37917 +@@ -1330,6 +1366,13 @@ static void *__vmalloc_node(unsigned lon
37918 + if (!size || (size >> PAGE_SHIFT) > num_physpages)
37919 + return NULL;
37920 +
37921 ++#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37922 ++ if (!(pgprot_val(prot) & _PAGE_NX))
37923 ++ area = __get_vm_area_node(size, VM_ALLOC | VM_KERNEXEC, VMALLOC_START, VMALLOC_END,
37924 ++ node, gfp_mask, caller);
37925 ++ else
37926 ++#endif
37927 ++
37928 + area = __get_vm_area_node(size, VM_ALLOC, VMALLOC_START, VMALLOC_END,
37929 + node, gfp_mask, caller);
37930 +
37931 +@@ -1419,7 +1462,7 @@ EXPORT_SYMBOL(vmalloc_node);
37932 +
37933 + void *vmalloc_exec(unsigned long size)
37934 + {
37935 +- return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC);
37936 ++ return __vmalloc(size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC);
37937 + }
37938 +
37939 + #if defined(CONFIG_64BIT) && defined(CONFIG_ZONE_DMA32)
37940 +diff -urNp linux-2.6.28/net/bridge/br_stp_if.c linux-2.6.28/net/bridge/br_stp_if.c
37941 +--- linux-2.6.28/net/bridge/br_stp_if.c 2008-12-24 18:26:37.000000000 -0500
37942 ++++ linux-2.6.28/net/bridge/br_stp_if.c 2009-01-11 07:20:06.000000000 -0500
37943 +@@ -146,7 +146,7 @@ static void br_stp_stop(struct net_bridg
37944 + char *envp[] = { NULL };
37945 +
37946 + if (br->stp_enabled == BR_USER_STP) {
37947 +- r = call_usermodehelper(BR_STP_PROG, argv, envp, 1);
37948 ++ r = call_usermodehelper(BR_STP_PROG, argv, envp, UMH_WAIT_PROC);
37949 + printk(KERN_INFO "%s: userspace STP stopped, return code %d\n",
37950 + br->dev->name, r);
37951 +
37952 +diff -urNp linux-2.6.28/net/core/flow.c linux-2.6.28/net/core/flow.c
37953 +--- linux-2.6.28/net/core/flow.c 2008-12-24 18:26:37.000000000 -0500
37954 ++++ linux-2.6.28/net/core/flow.c 2009-01-11 07:20:06.000000000 -0500
37955 +@@ -39,7 +39,7 @@ atomic_t flow_cache_genid = ATOMIC_INIT(
37956 +
37957 + static u32 flow_hash_shift;
37958 + #define flow_hash_size (1 << flow_hash_shift)
37959 +-static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables) = { NULL };
37960 ++static DEFINE_PER_CPU(struct flow_cache_entry **, flow_tables);
37961 +
37962 + #define flow_table(cpu) (per_cpu(flow_tables, cpu))
37963 +
37964 +@@ -52,7 +52,7 @@ struct flow_percpu_info {
37965 + u32 hash_rnd;
37966 + int count;
37967 + };
37968 +-static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info) = { 0 };
37969 ++static DEFINE_PER_CPU(struct flow_percpu_info, flow_hash_info);
37970 +
37971 + #define flow_hash_rnd_recalc(cpu) \
37972 + (per_cpu(flow_hash_info, cpu).hash_rnd_recalc)
37973 +@@ -69,7 +69,7 @@ struct flow_flush_info {
37974 + atomic_t cpuleft;
37975 + struct completion completion;
37976 + };
37977 +-static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets) = { NULL };
37978 ++static DEFINE_PER_CPU(struct tasklet_struct, flow_flush_tasklets);
37979 +
37980 + #define flow_flush_tasklet(cpu) (&per_cpu(flow_flush_tasklets, cpu))
37981 +
37982 +diff -urNp linux-2.6.28/net/dccp/ccids/ccid3.c linux-2.6.28/net/dccp/ccids/ccid3.c
37983 +--- linux-2.6.28/net/dccp/ccids/ccid3.c 2008-12-24 18:26:37.000000000 -0500
37984 ++++ linux-2.6.28/net/dccp/ccids/ccid3.c 2009-01-11 07:20:06.000000000 -0500
37985 +@@ -43,7 +43,7 @@
37986 + static int ccid3_debug;
37987 + #define ccid3_pr_debug(format, a...) DCCP_PR_DEBUG(ccid3_debug, format, ##a)
37988 + #else
37989 +-#define ccid3_pr_debug(format, a...)
37990 ++#define ccid3_pr_debug(format, a...) do {} while (0)
37991 + #endif
37992 +
37993 + /*
37994 +diff -urNp linux-2.6.28/net/dccp/dccp.h linux-2.6.28/net/dccp/dccp.h
37995 +--- linux-2.6.28/net/dccp/dccp.h 2008-12-24 18:26:37.000000000 -0500
37996 ++++ linux-2.6.28/net/dccp/dccp.h 2009-01-11 07:20:06.000000000 -0500
37997 +@@ -43,8 +43,8 @@ extern int dccp_debug;
37998 + #define dccp_pr_debug(format, a...) DCCP_PR_DEBUG(dccp_debug, format, ##a)
37999 + #define dccp_pr_debug_cat(format, a...) DCCP_PRINTK(dccp_debug, format, ##a)
38000 + #else
38001 +-#define dccp_pr_debug(format, a...)
38002 +-#define dccp_pr_debug_cat(format, a...)
38003 ++#define dccp_pr_debug(format, a...) do {} while (0)
38004 ++#define dccp_pr_debug_cat(format, a...) do {} while (0)
38005 + #endif
38006 +
38007 + extern struct inet_hashinfo dccp_hashinfo;
38008 +diff -urNp linux-2.6.28/net/ipv4/inet_connection_sock.c linux-2.6.28/net/ipv4/inet_connection_sock.c
38009 +--- linux-2.6.28/net/ipv4/inet_connection_sock.c 2008-12-24 18:26:37.000000000 -0500
38010 ++++ linux-2.6.28/net/ipv4/inet_connection_sock.c 2009-01-11 05:47:05.000000000 -0500
38011 +@@ -15,6 +15,7 @@
38012 +
38013 + #include <linux/module.h>
38014 + #include <linux/jhash.h>
38015 ++#include <linux/grsecurity.h>
38016 +
38017 + #include <net/inet_connection_sock.h>
38018 + #include <net/inet_hashtables.h>
38019 +diff -urNp linux-2.6.28/net/ipv4/inet_hashtables.c linux-2.6.28/net/ipv4/inet_hashtables.c
38020 +--- linux-2.6.28/net/ipv4/inet_hashtables.c 2008-12-24 18:26:37.000000000 -0500
38021 ++++ linux-2.6.28/net/ipv4/inet_hashtables.c 2009-01-11 05:47:05.000000000 -0500
38022 +@@ -18,11 +18,14 @@
38023 + #include <linux/sched.h>
38024 + #include <linux/slab.h>
38025 + #include <linux/wait.h>
38026 ++#include <linux/grsecurity.h>
38027 +
38028 + #include <net/inet_connection_sock.h>
38029 + #include <net/inet_hashtables.h>
38030 + #include <net/ip.h>
38031 +
38032 ++extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
38033 ++
38034 + /*
38035 + * Allocate and initialize a new local port bind bucket.
38036 + * The bindhash mutex for snum's hash chain must be held here.
38037 +@@ -487,6 +490,8 @@ ok:
38038 + }
38039 + spin_unlock(&head->lock);
38040 +
38041 ++ gr_update_task_in_ip_table(current, inet_sk(sk));
38042 ++
38043 + if (tw) {
38044 + inet_twsk_deschedule(tw, death_row);
38045 + inet_twsk_put(tw);
38046 +diff -urNp linux-2.6.28/net/ipv4/netfilter/ipt_stealth.c linux-2.6.28/net/ipv4/netfilter/ipt_stealth.c
38047 +--- linux-2.6.28/net/ipv4/netfilter/ipt_stealth.c 1969-12-31 19:00:00.000000000 -0500
38048 ++++ linux-2.6.28/net/ipv4/netfilter/ipt_stealth.c 2009-01-11 05:47:05.000000000 -0500
38049 +@@ -0,0 +1,114 @@
38050 ++/* Kernel module to add stealth support.
38051 ++ *
38052 ++ * Copyright (C) 2002-2006 Brad Spengler <spender@××××××××××.net>
38053 ++ *
38054 ++ */
38055 ++
38056 ++#include <linux/kernel.h>
38057 ++#include <linux/module.h>
38058 ++#include <linux/skbuff.h>
38059 ++#include <linux/net.h>
38060 ++#include <linux/sched.h>
38061 ++#include <linux/inet.h>
38062 ++#include <linux/stddef.h>
38063 ++
38064 ++#include <net/ip.h>
38065 ++#include <net/sock.h>
38066 ++#include <net/tcp.h>
38067 ++#include <net/udp.h>
38068 ++#include <net/route.h>
38069 ++#include <net/inet_common.h>
38070 ++
38071 ++#include <linux/netfilter_ipv4/ip_tables.h>
38072 ++
38073 ++MODULE_LICENSE("GPL");
38074 ++
38075 ++extern struct sock *udp_v4_lookup(struct net *net, u32 saddr, u16 sport, u32 daddr, u16 dport, int dif);
38076 ++
38077 ++static bool
38078 ++match(const struct sk_buff *skb,
38079 ++ const struct net_device *in,
38080 ++ const struct net_device *out,
38081 ++ const struct xt_match *match,
38082 ++ const void *matchinfo,
38083 ++ int offset,
38084 ++ unsigned int protoff,
38085 ++ bool *hotdrop)
38086 ++{
38087 ++ struct iphdr *ip = ip_hdr(skb);
38088 ++ struct tcphdr th;
38089 ++ struct udphdr uh;
38090 ++ struct sock *sk = NULL;
38091 ++
38092 ++ if (!ip || offset) return false;
38093 ++
38094 ++ switch(ip->protocol) {
38095 ++ case IPPROTO_TCP:
38096 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &th, sizeof(th)) < 0) {
38097 ++ *hotdrop = true;
38098 ++ return false;
38099 ++ }
38100 ++ if (!(th.syn && !th.ack)) return false;
38101 ++ sk = inet_lookup_listener(dev_net(skb->dev), &tcp_hashinfo, ip->daddr, th.dest, inet_iif(skb));
38102 ++ break;
38103 ++ case IPPROTO_UDP:
38104 ++ if (skb_copy_bits(skb, (ip_hdr(skb))->ihl*4, &uh, sizeof(uh)) < 0) {
38105 ++ *hotdrop = true;
38106 ++ return false;
38107 ++ }
38108 ++ sk = udp_v4_lookup(dev_net(skb->dev), ip->saddr, uh.source, ip->daddr, uh.dest, skb->dev->ifindex);
38109 ++ break;
38110 ++ default:
38111 ++ return false;
38112 ++ }
38113 ++
38114 ++ if(!sk) // port is being listened on, match this
38115 ++ return true;
38116 ++ else {
38117 ++ sock_put(sk);
38118 ++ return false;
38119 ++ }
38120 ++}
38121 ++
38122 ++/* Called when user tries to insert an entry of this type. */
38123 ++static bool
38124 ++checkentry(const char *tablename,
38125 ++ const void *nip,
38126 ++ const struct xt_match *match,
38127 ++ void *matchinfo,
38128 ++ unsigned int hook_mask)
38129 ++{
38130 ++ const struct ipt_ip *ip = (const struct ipt_ip *)nip;
38131 ++
38132 ++ if(((ip->proto == IPPROTO_TCP && !(ip->invflags & IPT_INV_PROTO)) ||
38133 ++ ((ip->proto == IPPROTO_UDP) && !(ip->invflags & IPT_INV_PROTO)))
38134 ++ && (hook_mask & (1 << NF_INET_LOCAL_IN)))
38135 ++ return true;
38136 ++
38137 ++ printk("stealth: Only works on TCP and UDP for the INPUT chain.\n");
38138 ++
38139 ++ return false;
38140 ++}
38141 ++
38142 ++
38143 ++static struct xt_match stealth_match __read_mostly = {
38144 ++ .name = "stealth",
38145 ++ .family = AF_INET,
38146 ++ .match = match,
38147 ++ .checkentry = checkentry,
38148 ++ .destroy = NULL,
38149 ++ .me = THIS_MODULE
38150 ++};
38151 ++
38152 ++static int __init init(void)
38153 ++{
38154 ++ return xt_register_match(&stealth_match);
38155 ++}
38156 ++
38157 ++static void __exit fini(void)
38158 ++{
38159 ++ xt_unregister_match(&stealth_match);
38160 ++}
38161 ++
38162 ++module_init(init);
38163 ++module_exit(fini);
38164 +diff -urNp linux-2.6.28/net/ipv4/netfilter/Kconfig linux-2.6.28/net/ipv4/netfilter/Kconfig
38165 +--- linux-2.6.28/net/ipv4/netfilter/Kconfig 2008-12-24 18:26:37.000000000 -0500
38166 ++++ linux-2.6.28/net/ipv4/netfilter/Kconfig 2009-01-11 05:47:05.000000000 -0500
38167 +@@ -101,6 +101,21 @@ config IP_NF_MATCH_TTL
38168 +
38169 + To compile it as a module, choose M here. If unsure, say N.
38170 +
38171 ++config IP_NF_MATCH_STEALTH
38172 ++ tristate "stealth match support"
38173 ++ depends on IP_NF_IPTABLES
38174 ++ help
38175 ++ Enabling this option will drop all syn packets coming to unserved tcp
38176 ++ ports as well as all packets coming to unserved udp ports. If you
38177 ++ are using your system to route any type of packets (ie. via NAT)
38178 ++ you should put this module at the end of your ruleset, since it will
38179 ++ drop packets that aren't going to ports that are listening on your
38180 ++ machine itself, it doesn't take into account that the packet might be
38181 ++ destined for someone on your internal network if you're using NAT for
38182 ++ instance.
38183 ++
38184 ++ To compile it as a module, choose M here. If unsure, say N.
38185 ++
38186 + # `filter', generic and specific targets
38187 + config IP_NF_FILTER
38188 + tristate "Packet filtering"
38189 +@@ -395,4 +410,3 @@ config IP_NF_ARP_MANGLE
38190 + endif # IP_NF_ARPTABLES
38191 +
38192 + endmenu
38193 +-
38194 +diff -urNp linux-2.6.28/net/ipv4/netfilter/Makefile linux-2.6.28/net/ipv4/netfilter/Makefile
38195 +--- linux-2.6.28/net/ipv4/netfilter/Makefile 2008-12-24 18:26:37.000000000 -0500
38196 ++++ linux-2.6.28/net/ipv4/netfilter/Makefile 2009-01-11 05:47:05.000000000 -0500
38197 +@@ -61,6 +61,7 @@ obj-$(CONFIG_IP_NF_TARGET_MASQUERADE) +=
38198 + obj-$(CONFIG_IP_NF_TARGET_NETMAP) += ipt_NETMAP.o
38199 + obj-$(CONFIG_IP_NF_TARGET_REDIRECT) += ipt_REDIRECT.o
38200 + obj-$(CONFIG_IP_NF_TARGET_REJECT) += ipt_REJECT.o
38201 ++obj-$(CONFIG_IP_NF_MATCH_STEALTH) += ipt_stealth.o
38202 + obj-$(CONFIG_IP_NF_TARGET_TTL) += ipt_TTL.o
38203 + obj-$(CONFIG_IP_NF_TARGET_ULOG) += ipt_ULOG.o
38204 +
38205 +diff -urNp linux-2.6.28/net/ipv4/tcp_ipv4.c linux-2.6.28/net/ipv4/tcp_ipv4.c
38206 +--- linux-2.6.28/net/ipv4/tcp_ipv4.c 2008-12-24 18:26:37.000000000 -0500
38207 ++++ linux-2.6.28/net/ipv4/tcp_ipv4.c 2009-01-11 05:47:05.000000000 -0500
38208 +@@ -59,6 +59,7 @@
38209 + #include <linux/jhash.h>
38210 + #include <linux/init.h>
38211 + #include <linux/times.h>
38212 ++#include <linux/grsecurity.h>
38213 +
38214 + #include <net/net_namespace.h>
38215 + #include <net/icmp.h>
38216 +diff -urNp linux-2.6.28/net/ipv4/udp.c linux-2.6.28/net/ipv4/udp.c
38217 +--- linux-2.6.28/net/ipv4/udp.c 2008-12-24 18:26:37.000000000 -0500
38218 ++++ linux-2.6.28/net/ipv4/udp.c 2009-01-11 05:47:05.000000000 -0500
38219 +@@ -97,6 +97,7 @@
38220 + #include <linux/skbuff.h>
38221 + #include <linux/proc_fs.h>
38222 + #include <linux/seq_file.h>
38223 ++#include <linux/grsecurity.h>
38224 + #include <net/net_namespace.h>
38225 + #include <net/icmp.h>
38226 + #include <net/route.h>
38227 +@@ -104,6 +105,11 @@
38228 + #include <net/xfrm.h>
38229 + #include "udp_impl.h"
38230 +
38231 ++extern int gr_search_udp_recvmsg(const struct sock *sk,
38232 ++ const struct sk_buff *skb);
38233 ++extern int gr_search_udp_sendmsg(const struct sock *sk,
38234 ++ const struct sockaddr_in *addr);
38235 ++
38236 + /*
38237 + * Snmp MIB for the UDP layer
38238 + */
38239 +@@ -284,6 +290,13 @@ struct sock *udp4_lib_lookup(struct net
38240 + }
38241 + EXPORT_SYMBOL_GPL(udp4_lib_lookup);
38242 +
38243 ++struct sock *udp_v4_lookup(struct net *net, __be32 saddr, __be16 sport,
38244 ++ __be32 daddr, __be16 dport, int dif)
38245 ++{
38246 ++ return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif, udp_hash);
38247 ++}
38248 ++
38249 ++
38250 + static inline struct sock *udp_v4_mcast_next(struct net *net, struct sock *sk,
38251 + __be16 loc_port, __be32 loc_addr,
38252 + __be16 rmt_port, __be32 rmt_addr,
38253 +@@ -574,9 +587,16 @@ int udp_sendmsg(struct kiocb *iocb, stru
38254 + dport = usin->sin_port;
38255 + if (dport == 0)
38256 + return -EINVAL;
38257 ++
38258 ++ if (!gr_search_udp_sendmsg(sk, usin))
38259 ++ return -EPERM;
38260 + } else {
38261 + if (sk->sk_state != TCP_ESTABLISHED)
38262 + return -EDESTADDRREQ;
38263 ++
38264 ++ if (!gr_search_udp_sendmsg(sk, NULL))
38265 ++ return -EPERM;
38266 ++
38267 + daddr = inet->daddr;
38268 + dport = inet->dport;
38269 + /* Open fast path for connected socket.
38270 +@@ -842,6 +862,11 @@ try_again:
38271 + if (!skb)
38272 + goto out;
38273 +
38274 ++ if (!gr_search_udp_recvmsg(sk, skb)) {
38275 ++ err = -EPERM;
38276 ++ goto out_free;
38277 ++ }
38278 ++
38279 + ulen = skb->len - sizeof(struct udphdr);
38280 + copied = len;
38281 + if (copied > ulen)
38282 +diff -urNp linux-2.6.28/net/ipv6/exthdrs.c linux-2.6.28/net/ipv6/exthdrs.c
38283 +--- linux-2.6.28/net/ipv6/exthdrs.c 2008-12-24 18:26:37.000000000 -0500
38284 ++++ linux-2.6.28/net/ipv6/exthdrs.c 2009-01-11 07:20:06.000000000 -0500
38285 +@@ -630,7 +630,7 @@ static struct tlvtype_proc tlvprochopopt
38286 + .type = IPV6_TLV_JUMBO,
38287 + .func = ipv6_hop_jumbo,
38288 + },
38289 +- { -1, }
38290 ++ { -1, NULL }
38291 + };
38292 +
38293 + int ipv6_parse_hopopts(struct sk_buff *skb)
38294 +diff -urNp linux-2.6.28/net/ipv6/raw.c linux-2.6.28/net/ipv6/raw.c
38295 +--- linux-2.6.28/net/ipv6/raw.c 2008-12-24 18:26:37.000000000 -0500
38296 ++++ linux-2.6.28/net/ipv6/raw.c 2009-01-11 07:20:06.000000000 -0500
38297 +@@ -600,7 +600,7 @@ out:
38298 + return err;
38299 + }
38300 +
38301 +-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
38302 ++static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
38303 + struct flowi *fl, struct rt6_info *rt,
38304 + unsigned int flags)
38305 + {
38306 +diff -urNp linux-2.6.28/net/irda/ircomm/ircomm_tty.c linux-2.6.28/net/irda/ircomm/ircomm_tty.c
38307 +--- linux-2.6.28/net/irda/ircomm/ircomm_tty.c 2008-12-24 18:26:37.000000000 -0500
38308 ++++ linux-2.6.28/net/irda/ircomm/ircomm_tty.c 2009-01-11 07:20:06.000000000 -0500
38309 +@@ -371,7 +371,7 @@ static int ircomm_tty_open(struct tty_st
38310 + IRDA_DEBUG(2, "%s()\n", __func__ );
38311 +
38312 + line = tty->index;
38313 +- if ((line < 0) || (line >= IRCOMM_TTY_PORTS)) {
38314 ++ if (line >= IRCOMM_TTY_PORTS) {
38315 + return -ENODEV;
38316 + }
38317 +
38318 +diff -urNp linux-2.6.28/net/sctp/socket.c linux-2.6.28/net/sctp/socket.c
38319 +--- linux-2.6.28/net/sctp/socket.c 2008-12-24 18:26:37.000000000 -0500
38320 ++++ linux-2.6.28/net/sctp/socket.c 2009-01-11 07:20:06.000000000 -0500
38321 +@@ -1434,7 +1434,7 @@ SCTP_STATIC int sctp_sendmsg(struct kioc
38322 + struct sctp_sndrcvinfo *sinfo;
38323 + struct sctp_initmsg *sinit;
38324 + sctp_assoc_t associd = 0;
38325 +- sctp_cmsgs_t cmsgs = { NULL };
38326 ++ sctp_cmsgs_t cmsgs = { NULL, NULL };
38327 + int err;
38328 + sctp_scope_t scope;
38329 + long timeo;
38330 +@@ -5616,7 +5616,6 @@ pp_found:
38331 + */
38332 + int reuse = sk->sk_reuse;
38333 + struct sock *sk2;
38334 +- struct hlist_node *node;
38335 +
38336 + SCTP_DEBUG_PRINTK("sctp_get_port() found a possible match\n");
38337 + if (pp->fastreuse && sk->sk_reuse &&
38338 +diff -urNp linux-2.6.28/net/socket.c linux-2.6.28/net/socket.c
38339 +--- linux-2.6.28/net/socket.c 2008-12-24 18:26:37.000000000 -0500
38340 ++++ linux-2.6.28/net/socket.c 2009-01-11 05:47:05.000000000 -0500
38341 +@@ -87,6 +87,7 @@
38342 + #include <linux/audit.h>
38343 + #include <linux/wireless.h>
38344 + #include <linux/nsproxy.h>
38345 ++#include <linux/in.h>
38346 +
38347 + #include <asm/uaccess.h>
38348 + #include <asm/unistd.h>
38349 +@@ -97,6 +98,21 @@
38350 + #include <net/sock.h>
38351 + #include <linux/netfilter.h>
38352 +
38353 ++extern void gr_attach_curr_ip(const struct sock *sk);
38354 ++extern int gr_handle_sock_all(const int family, const int type,
38355 ++ const int protocol);
38356 ++extern int gr_handle_sock_server(const struct sockaddr *sck);
38357 ++extern int gr_handle_sock_server_other(const struct socket *sck);
38358 ++extern int gr_handle_sock_client(const struct sockaddr *sck);
38359 ++extern int gr_search_connect(const struct socket * sock,
38360 ++ const struct sockaddr_in * addr);
38361 ++extern int gr_search_bind(const struct socket * sock,
38362 ++ const struct sockaddr_in * addr);
38363 ++extern int gr_search_listen(const struct socket * sock);
38364 ++extern int gr_search_accept(const struct socket * sock);
38365 ++extern int gr_search_socket(const int domain, const int type,
38366 ++ const int protocol);
38367 ++
38368 + static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
38369 + static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
38370 + unsigned long nr_segs, loff_t pos);
38371 +@@ -300,7 +316,7 @@ static int sockfs_get_sb(struct file_sys
38372 + mnt);
38373 + }
38374 +
38375 +-static struct vfsmount *sock_mnt __read_mostly;
38376 ++struct vfsmount *sock_mnt __read_mostly;
38377 +
38378 + static struct file_system_type sock_fs_type = {
38379 + .name = "sockfs",
38380 +@@ -1235,6 +1251,16 @@ asmlinkage long sys_socket(int family, i
38381 + if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
38382 + flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
38383 +
38384 ++ if(!gr_search_socket(family, type, protocol)) {
38385 ++ retval = -EACCES;
38386 ++ goto out;
38387 ++ }
38388 ++
38389 ++ if (gr_handle_sock_all(family, type, protocol)) {
38390 ++ retval = -EACCES;
38391 ++ goto out;
38392 ++ }
38393 ++
38394 + retval = sock_create(family, type, protocol, &sock);
38395 + if (retval < 0)
38396 + goto out;
38397 +@@ -1374,6 +1400,12 @@ asmlinkage long sys_bind(int fd, struct
38398 + if (sock) {
38399 + err = move_addr_to_kernel(umyaddr, addrlen, (struct sockaddr *)&address);
38400 + if (err >= 0) {
38401 ++ if (!gr_search_bind(sock, (struct sockaddr_in *)&address) ||
38402 ++ gr_handle_sock_server((struct sockaddr *)&address)) {
38403 ++ err = -EACCES;
38404 ++ goto error;
38405 ++ }
38406 ++
38407 + err = security_socket_bind(sock,
38408 + (struct sockaddr *)&address,
38409 + addrlen);
38410 +@@ -1382,6 +1414,7 @@ asmlinkage long sys_bind(int fd, struct
38411 + (struct sockaddr *)
38412 + &address, addrlen);
38413 + }
38414 ++error:
38415 + fput_light(sock->file, fput_needed);
38416 + }
38417 + return err;
38418 +@@ -1405,10 +1438,17 @@ asmlinkage long sys_listen(int fd, int b
38419 + if ((unsigned)backlog > somaxconn)
38420 + backlog = somaxconn;
38421 +
38422 ++ if (gr_handle_sock_server_other(sock) ||
38423 ++ !gr_search_listen(sock)) {
38424 ++ err = -EPERM;
38425 ++ goto error;
38426 ++ }
38427 ++
38428 + err = security_socket_listen(sock, backlog);
38429 + if (!err)
38430 + err = sock->ops->listen(sock, backlog);
38431 +
38432 ++error:
38433 + fput_light(sock->file, fput_needed);
38434 + }
38435 + return err;
38436 +@@ -1451,6 +1491,13 @@ asmlinkage long sys_accept4(int fd, stru
38437 + newsock->type = sock->type;
38438 + newsock->ops = sock->ops;
38439 +
38440 ++ if (gr_handle_sock_server_other(sock) ||
38441 ++ !gr_search_accept(sock)) {
38442 ++ err = -EPERM;
38443 ++ sock_release(newsock);
38444 ++ goto out_put;
38445 ++ }
38446 ++
38447 + /*
38448 + * We don't need try_module_get here, as the listening socket (sock)
38449 + * has the protocol module (sock->ops->owner) held.
38450 +@@ -1494,6 +1541,7 @@ asmlinkage long sys_accept4(int fd, stru
38451 + err = newfd;
38452 +
38453 + security_socket_post_accept(sock, newsock);
38454 ++ gr_attach_curr_ip(newsock->sk);
38455 +
38456 + out_put:
38457 + fput_light(sock->file, fput_needed);
38458 +@@ -1532,6 +1580,7 @@ asmlinkage long sys_connect(int fd, stru
38459 + int addrlen)
38460 + {
38461 + struct socket *sock;
38462 ++ struct sockaddr *sck;
38463 + struct sockaddr_storage address;
38464 + int err, fput_needed;
38465 +
38466 +@@ -1542,6 +1591,13 @@ asmlinkage long sys_connect(int fd, stru
38467 + if (err < 0)
38468 + goto out_put;
38469 +
38470 ++ sck = (struct sockaddr *)&address;
38471 ++ if (!gr_search_connect(sock, (struct sockaddr_in *)sck) ||
38472 ++ gr_handle_sock_client(sck)) {
38473 ++ err = -EACCES;
38474 ++ goto out_put;
38475 ++ }
38476 ++
38477 + err =
38478 + security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
38479 + if (err)
38480 +@@ -1809,6 +1865,7 @@ asmlinkage long sys_shutdown(int fd, int
38481 + err = sock->ops->shutdown(sock, how);
38482 + fput_light(sock->file, fput_needed);
38483 + }
38484 ++
38485 + return err;
38486 + }
38487 +
38488 +diff -urNp linux-2.6.28/net/unix/af_unix.c linux-2.6.28/net/unix/af_unix.c
38489 +--- linux-2.6.28/net/unix/af_unix.c 2008-12-24 18:26:37.000000000 -0500
38490 ++++ linux-2.6.28/net/unix/af_unix.c 2009-01-11 05:56:36.000000000 -0500
38491 +@@ -114,6 +114,7 @@
38492 + #include <linux/mount.h>
38493 + #include <net/checksum.h>
38494 + #include <linux/security.h>
38495 ++#include <linux/grsecurity.h>
38496 +
38497 + static struct hlist_head unix_socket_table[UNIX_HASH_SIZE + 1];
38498 + static DEFINE_SPINLOCK(unix_table_lock);
38499 +@@ -727,6 +728,12 @@ static struct sock *unix_find_other(stru
38500 + err = -ECONNREFUSED;
38501 + if (!S_ISSOCK(inode->i_mode))
38502 + goto put_fail;
38503 ++
38504 ++ if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
38505 ++ err = -EACCES;
38506 ++ goto put_fail;
38507 ++ }
38508 ++
38509 + u = unix_find_socket_byinode(net, inode);
38510 + if (!u)
38511 + goto put_fail;
38512 +@@ -747,6 +754,13 @@ static struct sock *unix_find_other(stru
38513 + if (u) {
38514 + struct dentry *dentry;
38515 + dentry = unix_sk(u)->dentry;
38516 ++
38517 ++ if (!gr_handle_chroot_unix(u->sk_peercred.pid)) {
38518 ++ err = -EPERM;
38519 ++ sock_put(u);
38520 ++ goto fail;
38521 ++ }
38522 ++
38523 + if (dentry)
38524 + touch_atime(unix_sk(u)->mnt, dentry);
38525 + } else
38526 +@@ -829,10 +843,20 @@ static int unix_bind(struct socket *sock
38527 + err = mnt_want_write(nd.path.mnt);
38528 + if (err)
38529 + goto out_mknod_dput;
38530 ++
38531 ++ if (!gr_acl_handle_mknod(dentry, nd.path.dentry, nd.path.mnt, mode)) {
38532 ++ err = -EACCES;
38533 ++ mnt_drop_write(nd.path.mnt);
38534 ++ goto out_mknod_dput;
38535 ++ }
38536 ++
38537 + err = vfs_mknod(nd.path.dentry->d_inode, dentry, mode, 0);
38538 + mnt_drop_write(nd.path.mnt);
38539 + if (err)
38540 + goto out_mknod_dput;
38541 ++
38542 ++ gr_handle_create(dentry, nd.path.mnt);
38543 ++
38544 + mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
38545 + dput(nd.path.dentry);
38546 + nd.path.dentry = dentry;
38547 +@@ -850,6 +874,10 @@ static int unix_bind(struct socket *sock
38548 + goto out_unlock;
38549 + }
38550 +
38551 ++#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
38552 ++ sk->sk_peercred.pid = current->pid;
38553 ++#endif
38554 ++
38555 + list = &unix_socket_table[addr->hash];
38556 + } else {
38557 + list = &unix_socket_table[dentry->d_inode->i_ino & (UNIX_HASH_SIZE-1)];
38558 +diff -urNp linux-2.6.28/scripts/pnmtologo.c linux-2.6.28/scripts/pnmtologo.c
38559 +--- linux-2.6.28/scripts/pnmtologo.c 2008-12-24 18:26:37.000000000 -0500
38560 ++++ linux-2.6.28/scripts/pnmtologo.c 2009-01-11 07:20:06.000000000 -0500
38561 +@@ -237,14 +237,14 @@ static void write_header(void)
38562 + fprintf(out, " * Linux logo %s\n", logoname);
38563 + fputs(" */\n\n", out);
38564 + fputs("#include <linux/linux_logo.h>\n\n", out);
38565 +- fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
38566 ++ fprintf(out, "static unsigned char %s_data[] = {\n",
38567 + logoname);
38568 + }
38569 +
38570 + static void write_footer(void)
38571 + {
38572 + fputs("\n};\n\n", out);
38573 +- fprintf(out, "struct linux_logo %s __initdata = {\n", logoname);
38574 ++ fprintf(out, "struct linux_logo %s = {\n", logoname);
38575 + fprintf(out, " .type\t= %s,\n", logo_types[logo_type]);
38576 + fprintf(out, " .width\t= %d,\n", logo_width);
38577 + fprintf(out, " .height\t= %d,\n", logo_height);
38578 +@@ -374,7 +374,7 @@ static void write_logo_clut224(void)
38579 + fputs("\n};\n\n", out);
38580 +
38581 + /* write logo clut */
38582 +- fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
38583 ++ fprintf(out, "static unsigned char %s_clut[] = {\n",
38584 + logoname);
38585 + write_hex_cnt = 0;
38586 + for (i = 0; i < logo_clutsize; i++) {
38587 +diff -urNp linux-2.6.28/security/commoncap.c linux-2.6.28/security/commoncap.c
38588 +--- linux-2.6.28/security/commoncap.c 2008-12-24 18:26:37.000000000 -0500
38589 ++++ linux-2.6.28/security/commoncap.c 2009-01-11 05:47:05.000000000 -0500
38590 +@@ -26,10 +26,13 @@
38591 + #include <linux/sched.h>
38592 + #include <linux/prctl.h>
38593 + #include <linux/securebits.h>
38594 ++#include <linux/grsecurity.h>
38595 ++
38596 ++extern kernel_cap_t gr_cap_rtnetlink(struct sock *sk);
38597 +
38598 + int cap_netlink_send(struct sock *sk, struct sk_buff *skb)
38599 + {
38600 +- NETLINK_CB(skb).eff_cap = current->cap_effective;
38601 ++ NETLINK_CB(skb).eff_cap = gr_cap_rtnetlink(sk);
38602 + return 0;
38603 + }
38604 +
38605 +@@ -51,7 +54,15 @@ EXPORT_SYMBOL(cap_netlink_recv);
38606 + int cap_capable (struct task_struct *tsk, int cap)
38607 + {
38608 + /* Derived from include/linux/sched.h:capable. */
38609 +- if (cap_raised(tsk->cap_effective, cap))
38610 ++ if (cap_raised (tsk->cap_effective, cap))
38611 ++ return 0;
38612 ++ return -EPERM;
38613 ++}
38614 ++
38615 ++int cap_capable_nolog (struct task_struct *tsk, int cap)
38616 ++{
38617 ++ /* tsk = current for all callers */
38618 ++ if (cap_raised(tsk->cap_effective, cap) && gr_is_capable_nolog(cap))
38619 + return 0;
38620 + return -EPERM;
38621 + }
38622 +@@ -379,8 +390,11 @@ void cap_bprm_apply_creds (struct linux_
38623 + }
38624 + }
38625 +
38626 +- current->suid = current->euid = current->fsuid = bprm->e_uid;
38627 +- current->sgid = current->egid = current->fsgid = bprm->e_gid;
38628 ++ if (!gr_check_user_change(-1, bprm->e_uid, bprm->e_uid))
38629 ++ current->suid = current->euid = current->fsuid = bprm->e_uid;
38630 ++
38631 ++ if (!gr_check_group_change(-1, bprm->e_gid, bprm->e_gid))
38632 ++ current->sgid = current->egid = current->fsgid = bprm->e_gid;
38633 +
38634 + /* For init, we want to retain the capabilities set
38635 + * in the init_task struct. Thus we skip the usual
38636 +@@ -393,6 +407,8 @@ void cap_bprm_apply_creds (struct linux_
38637 + cap_clear(current->cap_effective);
38638 + }
38639 +
38640 ++ gr_handle_chroot_caps(current);
38641 ++
38642 + /* AUD: Audit candidate if current->cap_effective is set */
38643 +
38644 + current->securebits &= ~issecure_mask(SECURE_KEEP_CAPS);
38645 +@@ -705,7 +721,7 @@ int cap_vm_enough_memory(struct mm_struc
38646 + {
38647 + int cap_sys_admin = 0;
38648 +
38649 +- if (cap_capable(current, CAP_SYS_ADMIN) == 0)
38650 ++ if (cap_capable_nolog(current, CAP_SYS_ADMIN) == 0)
38651 + cap_sys_admin = 1;
38652 + return __vm_enough_memory(mm, pages, cap_sys_admin);
38653 + }
38654 +diff -urNp linux-2.6.28/security/Kconfig linux-2.6.28/security/Kconfig
38655 +--- linux-2.6.28/security/Kconfig 2008-12-24 18:26:37.000000000 -0500
38656 ++++ linux-2.6.28/security/Kconfig 2009-01-11 07:40:13.000000000 -0500
38657 +@@ -4,6 +4,447 @@
38658 +
38659 + menu "Security options"
38660 +
38661 ++source grsecurity/Kconfig
38662 ++
38663 ++menu "PaX"
38664 ++
38665 ++config PAX
38666 ++ bool "Enable various PaX features"
38667 ++ depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
38668 ++ help
38669 ++ This allows you to enable various PaX features. PaX adds
38670 ++ intrusion prevention mechanisms to the kernel that reduce
38671 ++ the risks posed by exploitable memory corruption bugs.
38672 ++
38673 ++menu "PaX Control"
38674 ++ depends on PAX
38675 ++
38676 ++config PAX_SOFTMODE
38677 ++ bool 'Support soft mode'
38678 ++ help
38679 ++ Enabling this option will allow you to run PaX in soft mode, that
38680 ++ is, PaX features will not be enforced by default, only on executables
38681 ++ marked explicitly. You must also enable PT_PAX_FLAGS support as it
38682 ++ is the only way to mark executables for soft mode use.
38683 ++
38684 ++ Soft mode can be activated by using the "pax_softmode=1" kernel command
38685 ++ line option on boot. Furthermore you can control various PaX features
38686 ++ at runtime via the entries in /proc/sys/kernel/pax.
38687 ++
38688 ++config PAX_EI_PAX
38689 ++ bool 'Use legacy ELF header marking'
38690 ++ help
38691 ++ Enabling this option will allow you to control PaX features on
38692 ++ a per executable basis via the 'chpax' utility available at
38693 ++ http://pax.grsecurity.net/. The control flags will be read from
38694 ++ an otherwise reserved part of the ELF header. This marking has
38695 ++ numerous drawbacks (no support for soft-mode, toolchain does not
38696 ++ know about the non-standard use of the ELF header) therefore it
38697 ++ has been deprecated in favour of PT_PAX_FLAGS support.
38698 ++
38699 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
38700 ++ program header then you MUST enable this option otherwise they
38701 ++ will not get any protection.
38702 ++
38703 ++ Note that if you enable PT_PAX_FLAGS marking support as well,
38704 ++ the PT_PAX_FLAG marks will override the legacy EI_PAX marks.
38705 ++
38706 ++config PAX_PT_PAX_FLAGS
38707 ++ bool 'Use ELF program header marking'
38708 ++ help
38709 ++ Enabling this option will allow you to control PaX features on
38710 ++ a per executable basis via the 'paxctl' utility available at
38711 ++ http://pax.grsecurity.net/. The control flags will be read from
38712 ++ a PaX specific ELF program header (PT_PAX_FLAGS). This marking
38713 ++ has the benefits of supporting both soft mode and being fully
38714 ++ integrated into the toolchain (the binutils patch is available
38715 ++ from http://pax.grsecurity.net).
38716 ++
38717 ++ If you have applications not marked by the PT_PAX_FLAGS ELF
38718 ++ program header then you MUST enable the EI_PAX marking support
38719 ++ otherwise they will not get any protection.
38720 ++
38721 ++ Note that if you enable the legacy EI_PAX marking support as well,
38722 ++ the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
38723 ++
38724 ++choice
38725 ++ prompt 'MAC system integration'
38726 ++ default PAX_HAVE_ACL_FLAGS
38727 ++ help
38728 ++ Mandatory Access Control systems have the option of controlling
38729 ++ PaX flags on a per executable basis, choose the method supported
38730 ++ by your particular system.
38731 ++
38732 ++ - "none": if your MAC system does not interact with PaX,
38733 ++ - "direct": if your MAC system defines pax_set_initial_flags() itself,
38734 ++ - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
38735 ++
38736 ++ NOTE: this option is for developers/integrators only.
38737 ++
38738 ++ config PAX_NO_ACL_FLAGS
38739 ++ bool 'none'
38740 ++
38741 ++ config PAX_HAVE_ACL_FLAGS
38742 ++ bool 'direct'
38743 ++
38744 ++ config PAX_HOOK_ACL_FLAGS
38745 ++ bool 'hook'
38746 ++endchoice
38747 ++
38748 ++endmenu
38749 ++
38750 ++menu "Non-executable pages"
38751 ++ depends on PAX
38752 ++
38753 ++config PAX_NOEXEC
38754 ++ bool "Enforce non-executable pages"
38755 ++ 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)
38756 ++ help
38757 ++ By design some architectures do not allow for protecting memory
38758 ++ pages against execution or even if they do, Linux does not make
38759 ++ use of this feature. In practice this means that if a page is
38760 ++ readable (such as the stack or heap) it is also executable.
38761 ++
38762 ++ There is a well known exploit technique that makes use of this
38763 ++ fact and a common programming mistake where an attacker can
38764 ++ introduce code of his choice somewhere in the attacked program's
38765 ++ memory (typically the stack or the heap) and then execute it.
38766 ++
38767 ++ If the attacked program was running with different (typically
38768 ++ higher) privileges than that of the attacker, then he can elevate
38769 ++ his own privilege level (e.g. get a root shell, write to files for
38770 ++ which he does not have write access to, etc).
38771 ++
38772 ++ Enabling this option will let you choose from various features
38773 ++ that prevent the injection and execution of 'foreign' code in
38774 ++ a program.
38775 ++
38776 ++ This will also break programs that rely on the old behaviour and
38777 ++ expect that dynamically allocated memory via the malloc() family
38778 ++ of functions is executable (which it is not). Notable examples
38779 ++ are the XFree86 4.x server, the java runtime and wine.
38780 ++
38781 ++config PAX_PAGEEXEC
38782 ++ bool "Paging based non-executable pages"
38783 ++ 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)
38784 ++ help
38785 ++ This implementation is based on the paging feature of the CPU.
38786 ++ On i386 without hardware non-executable bit support there is a
38787 ++ variable but usually low performance impact, however on Intel's
38788 ++ P4 core based CPUs it is very high so you should not enable this
38789 ++ for kernels meant to be used on such CPUs.
38790 ++
38791 ++ On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
38792 ++ with hardware non-executable bit support there is no performance
38793 ++ impact, on ppc the impact is negligible.
38794 ++
38795 ++ Note that several architectures require various emulations due to
38796 ++ badly designed userland ABIs, this will cause a performance impact
38797 ++ but will disappear as soon as userland is fixed (e.g., ppc users
38798 ++ can make use of the secure-plt feature found in binutils).
38799 ++
38800 ++config PAX_SEGMEXEC
38801 ++ bool "Segmentation based non-executable pages"
38802 ++ depends on !COMPAT_VDSO && PAX_NOEXEC && X86_32
38803 ++ help
38804 ++ This implementation is based on the segmentation feature of the
38805 ++ CPU and has a very small performance impact, however applications
38806 ++ will be limited to a 1.5 GB address space instead of the normal
38807 ++ 3 GB.
38808 ++
38809 ++config PAX_EMUTRAMP
38810 ++ bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || PPC32 || X86)
38811 ++ default y if PARISC || PPC32
38812 ++ help
38813 ++ There are some programs and libraries that for one reason or
38814 ++ another attempt to execute special small code snippets from
38815 ++ non-executable memory pages. Most notable examples are the
38816 ++ signal handler return code generated by the kernel itself and
38817 ++ the GCC trampolines.
38818 ++
38819 ++ If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
38820 ++ such programs will no longer work under your kernel.
38821 ++
38822 ++ As a remedy you can say Y here and use the 'chpax' or 'paxctl'
38823 ++ utilities to enable trampoline emulation for the affected programs
38824 ++ yet still have the protection provided by the non-executable pages.
38825 ++
38826 ++ On parisc and ppc you MUST enable this option and EMUSIGRT as
38827 ++ well, otherwise your system will not even boot.
38828 ++
38829 ++ Alternatively you can say N here and use the 'chpax' or 'paxctl'
38830 ++ utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
38831 ++ for the affected files.
38832 ++
38833 ++ NOTE: enabling this feature *may* open up a loophole in the
38834 ++ protection provided by non-executable pages that an attacker
38835 ++ could abuse. Therefore the best solution is to not have any
38836 ++ files on your system that would require this option. This can
38837 ++ be achieved by not using libc5 (which relies on the kernel
38838 ++ signal handler return code) and not using or rewriting programs
38839 ++ that make use of the nested function implementation of GCC.
38840 ++ Skilled users can just fix GCC itself so that it implements
38841 ++ nested function calls in a way that does not interfere with PaX.
38842 ++
38843 ++config PAX_EMUSIGRT
38844 ++ bool "Automatically emulate sigreturn trampolines"
38845 ++ depends on PAX_EMUTRAMP && (PARISC || PPC32)
38846 ++ default y
38847 ++ help
38848 ++ Enabling this option will have the kernel automatically detect
38849 ++ and emulate signal return trampolines executing on the stack
38850 ++ that would otherwise lead to task termination.
38851 ++
38852 ++ This solution is intended as a temporary one for users with
38853 ++ legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
38854 ++ Modula-3 runtime, etc) or executables linked to such, basically
38855 ++ everything that does not specify its own SA_RESTORER function in
38856 ++ normal executable memory like glibc 2.1+ does.
38857 ++
38858 ++ On parisc and ppc you MUST enable this option, otherwise your
38859 ++ system will not even boot.
38860 ++
38861 ++ NOTE: this feature cannot be disabled on a per executable basis
38862 ++ and since it *does* open up a loophole in the protection provided
38863 ++ by non-executable pages, the best solution is to not have any
38864 ++ files on your system that would require this option.
38865 ++
38866 ++config PAX_MPROTECT
38867 ++ bool "Restrict mprotect()"
38868 ++ depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && !PPC64
38869 ++ help
38870 ++ Enabling this option will prevent programs from
38871 ++ - changing the executable status of memory pages that were
38872 ++ not originally created as executable,
38873 ++ - making read-only executable pages writable again,
38874 ++ - creating executable pages from anonymous memory.
38875 ++
38876 ++ You should say Y here to complete the protection provided by
38877 ++ the enforcement of non-executable pages.
38878 ++
38879 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
38880 ++ this feature on a per file basis.
38881 ++
38882 ++config PAX_NOELFRELOCS
38883 ++ bool "Disallow ELF text relocations"
38884 ++ depends on PAX_MPROTECT && !PAX_ETEXECRELOCS && (IA64 || X86)
38885 ++ help
38886 ++ Non-executable pages and mprotect() restrictions are effective
38887 ++ in preventing the introduction of new executable code into an
38888 ++ attacked task's address space. There remain only two venues
38889 ++ for this kind of attack: if the attacker can execute already
38890 ++ existing code in the attacked task then he can either have it
38891 ++ create and mmap() a file containing his code or have it mmap()
38892 ++ an already existing ELF library that does not have position
38893 ++ independent code in it and use mprotect() on it to make it
38894 ++ writable and copy his code there. While protecting against
38895 ++ the former approach is beyond PaX, the latter can be prevented
38896 ++ by having only PIC ELF libraries on one's system (which do not
38897 ++ need to relocate their code). If you are sure this is your case,
38898 ++ then enable this option otherwise be careful as you may not even
38899 ++ be able to boot or log on your system (for example, some PAM
38900 ++ modules are erroneously compiled as non-PIC by default).
38901 ++
38902 ++ NOTE: if you are using dynamic ELF executables (as suggested
38903 ++ when using ASLR) then you must have made sure that you linked
38904 ++ your files using the PIC version of crt1 (the et_dyn.tar.gz package
38905 ++ referenced there has already been updated to support this).
38906 ++
38907 ++config PAX_ETEXECRELOCS
38908 ++ bool "Allow ELF ET_EXEC text relocations"
38909 ++ depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
38910 ++ default y
38911 ++ help
38912 ++ On some architectures there are incorrectly created applications
38913 ++ that require text relocations and would not work without enabling
38914 ++ this option. If you are an alpha, ia64 or parisc user, you should
38915 ++ enable this option and disable it once you have made sure that
38916 ++ none of your applications need it.
38917 ++
38918 ++config PAX_EMUPLT
38919 ++ bool "Automatically emulate ELF PLT"
38920 ++ depends on PAX_MPROTECT && (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
38921 ++ default y
38922 ++ help
38923 ++ Enabling this option will have the kernel automatically detect
38924 ++ and emulate the Procedure Linkage Table entries in ELF files.
38925 ++ On some architectures such entries are in writable memory, and
38926 ++ become non-executable leading to task termination. Therefore
38927 ++ it is mandatory that you enable this option on alpha, parisc,
38928 ++ ppc (if secure-plt is not used throughout in userland), sparc
38929 ++ and sparc64, otherwise your system would not even boot.
38930 ++
38931 ++ NOTE: this feature *does* open up a loophole in the protection
38932 ++ provided by the non-executable pages, therefore the proper
38933 ++ solution is to modify the toolchain to produce a PLT that does
38934 ++ not need to be writable.
38935 ++
38936 ++config PAX_DLRESOLVE
38937 ++ bool
38938 ++ depends on PAX_EMUPLT && (SPARC32 || SPARC64)
38939 ++ default y
38940 ++
38941 ++config PAX_SYSCALL
38942 ++ bool
38943 ++ depends on PAX_PAGEEXEC && PPC32
38944 ++ default y
38945 ++
38946 ++config PAX_KERNEXEC
38947 ++ bool "Enforce non-executable kernel pages"
38948 ++ depends on PAX_NOEXEC && X86 && !EFI && !COMPAT_VDSO && (!X86_32 || X86_WP_WORKS_OK) && !PARAVIRT
38949 ++ help
38950 ++ This is the kernel land equivalent of PAGEEXEC and MPROTECT,
38951 ++ that is, enabling this option will make it harder to inject
38952 ++ and execute 'foreign' code in kernel memory itself.
38953 ++
38954 ++endmenu
38955 ++
38956 ++menu "Address Space Layout Randomization"
38957 ++ depends on PAX
38958 ++
38959 ++config PAX_ASLR
38960 ++ bool "Address Space Layout Randomization"
38961 ++ depends on PAX_EI_PAX || PAX_PT_PAX_FLAGS || PAX_HAVE_ACL_FLAGS || PAX_HOOK_ACL_FLAGS
38962 ++ help
38963 ++ Many if not most exploit techniques rely on the knowledge of
38964 ++ certain addresses in the attacked program. The following options
38965 ++ will allow the kernel to apply a certain amount of randomization
38966 ++ to specific parts of the program thereby forcing an attacker to
38967 ++ guess them in most cases. Any failed guess will most likely crash
38968 ++ the attacked program which allows the kernel to detect such attempts
38969 ++ and react on them. PaX itself provides no reaction mechanisms,
38970 ++ instead it is strongly encouraged that you make use of Nergal's
38971 ++ segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
38972 ++ (http://www.grsecurity.net/) built-in crash detection features or
38973 ++ develop one yourself.
38974 ++
38975 ++ By saying Y here you can choose to randomize the following areas:
38976 ++ - top of the task's kernel stack
38977 ++ - top of the task's userland stack
38978 ++ - base address for mmap() requests that do not specify one
38979 ++ (this includes all libraries)
38980 ++ - base address of the main executable
38981 ++
38982 ++ It is strongly recommended to say Y here as address space layout
38983 ++ randomization has negligible impact on performance yet it provides
38984 ++ a very effective protection.
38985 ++
38986 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control
38987 ++ this feature on a per file basis.
38988 ++
38989 ++config PAX_RANDKSTACK
38990 ++ bool "Randomize kernel stack base"
38991 ++ depends on PAX_ASLR && X86_TSC && X86_32
38992 ++ help
38993 ++ By saying Y here the kernel will randomize every task's kernel
38994 ++ stack on every system call. This will not only force an attacker
38995 ++ to guess it but also prevent him from making use of possible
38996 ++ leaked information about it.
38997 ++
38998 ++ Since the kernel stack is a rather scarce resource, randomization
38999 ++ may cause unexpected stack overflows, therefore you should very
39000 ++ carefully test your system. Note that once enabled in the kernel
39001 ++ configuration, this feature cannot be disabled on a per file basis.
39002 ++
39003 ++config PAX_RANDUSTACK
39004 ++ bool "Randomize user stack base"
39005 ++ depends on PAX_ASLR
39006 ++ help
39007 ++ By saying Y here the kernel will randomize every task's userland
39008 ++ stack. The randomization is done in two steps where the second
39009 ++ one may apply a big amount of shift to the top of the stack and
39010 ++ cause problems for programs that want to use lots of memory (more
39011 ++ than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
39012 ++ For this reason the second step can be controlled by 'chpax' or
39013 ++ 'paxctl' on a per file basis.
39014 ++
39015 ++config PAX_RANDMMAP
39016 ++ bool "Randomize mmap() base"
39017 ++ depends on PAX_ASLR
39018 ++ help
39019 ++ By saying Y here the kernel will use a randomized base address for
39020 ++ mmap() requests that do not specify one themselves. As a result
39021 ++ all dynamically loaded libraries will appear at random addresses
39022 ++ and therefore be harder to exploit by a technique where an attacker
39023 ++ attempts to execute library code for his purposes (e.g. spawn a
39024 ++ shell from an exploited program that is running at an elevated
39025 ++ privilege level).
39026 ++
39027 ++ Furthermore, if a program is relinked as a dynamic ELF file, its
39028 ++ base address will be randomized as well, completing the full
39029 ++ randomization of the address space layout. Attacking such programs
39030 ++ becomes a guess game. You can find an example of doing this at
39031 ++ http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
39032 ++ http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
39033 ++
39034 ++ NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
39035 ++ feature on a per file basis.
39036 ++
39037 ++endmenu
39038 ++
39039 ++menu "Miscellaneous hardening features"
39040 ++
39041 ++config PAX_MEMORY_SANITIZE
39042 ++ bool "Sanitize all freed memory"
39043 ++ help
39044 ++ By saying Y here the kernel will erase memory pages as soon as they
39045 ++ are freed. This in turn reduces the lifetime of data stored in the
39046 ++ pages, making it less likely that sensitive information such as
39047 ++ passwords, cryptographic secrets, etc stay in memory for too long.
39048 ++
39049 ++ This is especially useful for programs whose runtime is short, long
39050 ++ lived processes and the kernel itself benefit from this as long as
39051 ++ they operate on whole memory pages and ensure timely freeing of pages
39052 ++ that may hold sensitive information.
39053 ++
39054 ++ The tradeoff is performance impact, on a single CPU system kernel
39055 ++ compilation sees a 3% slowdown, other systems and workloads may vary
39056 ++ and you are advised to test this feature on your expected workload
39057 ++ before deploying it.
39058 ++
39059 ++ Note that this feature does not protect data stored in live pages,
39060 ++ e.g., process memory swapped to disk may stay there for a long time.
39061 ++
39062 ++config PAX_MEMORY_UDEREF
39063 ++ bool "Prevent invalid userland pointer dereference"
39064 ++ depends on X86_32 && !COMPAT_VDSO && !UML_X86
39065 ++ help
39066 ++ By saying Y here the kernel will be prevented from dereferencing
39067 ++ userland pointers in contexts where the kernel expects only kernel
39068 ++ pointers. This is both a useful runtime debugging feature and a
39069 ++ security measure that prevents exploiting a class of kernel bugs.
39070 ++
39071 ++ The tradeoff is that some virtualization solutions may experience
39072 ++ a huge slowdown and therefore you should not enable this feature
39073 ++ for kernels meant to run in such environments. Whether a given VM
39074 ++ solution is affected or not is best determined by simply trying it
39075 ++ out, the performance impact will be obvious right on boot as this
39076 ++ mechanism engages from very early on. A good rule of thumb is that
39077 ++ VMs running on CPUs without hardware virtualization support (i.e.,
39078 ++ the majority of IA-32 CPUs) will likely experience the slowdown.
39079 ++
39080 ++config PAX_REFCOUNT
39081 ++ bool "Prevent various kernel object reference counter overflows"
39082 ++ depends on X86
39083 ++ help
39084 ++ By saying Y here the kernel will detect and prevent overflowing
39085 ++ various (but not all) kinds of object reference counters. Such
39086 ++ overflows can normally occur due to bugs only and are often, if
39087 ++ not always, exploitable.
39088 ++
39089 ++ The tradeoff is that data structures protected by an overflowed
39090 ++ refcount will never be freed and therefore will leak memory. Note
39091 ++ that this leak also happens even without this protection but in
39092 ++ that case the overflow can eventually trigger the freeing of the
39093 ++ data structure while it is still being used elsewhere, resulting
39094 ++ in the exploitable situation that this feature prevents.
39095 ++
39096 ++ Since this has a negligible performance impact, you should enable
39097 ++ this feature.
39098 ++endmenu
39099 ++
39100 ++endmenu
39101 ++
39102 + config KEYS
39103 + bool "Enable access key retention support"
39104 + help
39105 +diff -urNp linux-2.6.28/sound/core/oss/pcm_oss.c linux-2.6.28/sound/core/oss/pcm_oss.c
39106 +--- linux-2.6.28/sound/core/oss/pcm_oss.c 2008-12-24 18:26:37.000000000 -0500
39107 ++++ linux-2.6.28/sound/core/oss/pcm_oss.c 2009-01-11 07:20:06.000000000 -0500
39108 +@@ -2929,8 +2929,8 @@ static void snd_pcm_oss_proc_done(struct
39109 + }
39110 + }
39111 + #else /* !CONFIG_SND_VERBOSE_PROCFS */
39112 +-#define snd_pcm_oss_proc_init(pcm)
39113 +-#define snd_pcm_oss_proc_done(pcm)
39114 ++#define snd_pcm_oss_proc_init(pcm) do {} while (0)
39115 ++#define snd_pcm_oss_proc_done(pcm) do {} while (0)
39116 + #endif /* CONFIG_SND_VERBOSE_PROCFS */
39117 +
39118 + /*
39119 +diff -urNp linux-2.6.28/sound/core/seq/seq_lock.h linux-2.6.28/sound/core/seq/seq_lock.h
39120 +--- linux-2.6.28/sound/core/seq/seq_lock.h 2008-12-24 18:26:37.000000000 -0500
39121 ++++ linux-2.6.28/sound/core/seq/seq_lock.h 2009-01-11 07:20:06.000000000 -0500
39122 +@@ -23,10 +23,10 @@ void snd_use_lock_sync_helper(snd_use_lo
39123 + #else /* SMP || CONFIG_SND_DEBUG */
39124 +
39125 + typedef spinlock_t snd_use_lock_t; /* dummy */
39126 +-#define snd_use_lock_init(lockp) /**/
39127 +-#define snd_use_lock_use(lockp) /**/
39128 +-#define snd_use_lock_free(lockp) /**/
39129 +-#define snd_use_lock_sync(lockp) /**/
39130 ++#define snd_use_lock_init(lockp) do {} while (0)
39131 ++#define snd_use_lock_use(lockp) do {} while (0)
39132 ++#define snd_use_lock_free(lockp) do {} while (0)
39133 ++#define snd_use_lock_sync(lockp) do {} while (0)
39134 +
39135 + #endif /* SMP || CONFIG_SND_DEBUG */
39136 +
39137 +diff -urNp linux-2.6.28/sound/pci/ac97/ac97_patch.c linux-2.6.28/sound/pci/ac97/ac97_patch.c
39138 +--- linux-2.6.28/sound/pci/ac97/ac97_patch.c 2008-12-24 18:26:37.000000000 -0500
39139 ++++ linux-2.6.28/sound/pci/ac97/ac97_patch.c 2009-01-11 07:20:06.000000000 -0500
39140 +@@ -1498,7 +1498,7 @@ static const struct snd_ac97_res_table a
39141 + { AC97_VIDEO, 0x9f1f },
39142 + { AC97_AUX, 0x9f1f },
39143 + { AC97_PCM, 0x9f1f },
39144 +- { } /* terminator */
39145 ++ { 0, 0 } /* terminator */
39146 + };
39147 +
39148 + static int patch_ad1819(struct snd_ac97 * ac97)
39149 +@@ -3870,7 +3870,7 @@ static struct snd_ac97_res_table lm4550_
39150 + { AC97_AUX, 0x1f1f },
39151 + { AC97_PCM, 0x1f1f },
39152 + { AC97_REC_GAIN, 0x0f0f },
39153 +- { } /* terminator */
39154 ++ { 0, 0 } /* terminator */
39155 + };
39156 +
39157 + static int patch_lm4550(struct snd_ac97 *ac97)
39158 +diff -urNp linux-2.6.28/sound/pci/ens1370.c linux-2.6.28/sound/pci/ens1370.c
39159 +--- linux-2.6.28/sound/pci/ens1370.c 2008-12-24 18:26:37.000000000 -0500
39160 ++++ linux-2.6.28/sound/pci/ens1370.c 2009-01-11 07:20:06.000000000 -0500
39161 +@@ -452,7 +452,7 @@ static struct pci_device_id snd_audiopci
39162 + { 0x1274, 0x5880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* ES1373 - CT5880 */
39163 + { 0x1102, 0x8938, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Ectiva EV1938 */
39164 + #endif
39165 +- { 0, }
39166 ++ { 0, 0, 0, 0, 0, 0, 0 }
39167 + };
39168 +
39169 + MODULE_DEVICE_TABLE(pci, snd_audiopci_ids);
39170 +diff -urNp linux-2.6.28/sound/pci/intel8x0.c linux-2.6.28/sound/pci/intel8x0.c
39171 +--- linux-2.6.28/sound/pci/intel8x0.c 2008-12-24 18:26:37.000000000 -0500
39172 ++++ linux-2.6.28/sound/pci/intel8x0.c 2009-01-11 07:20:06.000000000 -0500
39173 +@@ -443,7 +443,7 @@ static struct pci_device_id snd_intel8x0
39174 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
39175 + { 0x1022, 0x7445, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD768 */
39176 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
39177 +- { 0, }
39178 ++ { 0, 0, 0, 0, 0, 0, 0 }
39179 + };
39180 +
39181 + MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
39182 +@@ -2088,7 +2088,7 @@ static struct ac97_quirk ac97_quirks[] _
39183 + .type = AC97_TUNE_HP_ONLY
39184 + },
39185 + #endif
39186 +- { } /* terminator */
39187 ++ { 0, 0, 0, 0, NULL, 0 } /* terminator */
39188 + };
39189 +
39190 + static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
39191 +diff -urNp linux-2.6.28/sound/pci/intel8x0m.c linux-2.6.28/sound/pci/intel8x0m.c
39192 +--- linux-2.6.28/sound/pci/intel8x0m.c 2008-12-24 18:26:37.000000000 -0500
39193 ++++ linux-2.6.28/sound/pci/intel8x0m.c 2009-01-11 07:20:06.000000000 -0500
39194 +@@ -239,7 +239,7 @@ static struct pci_device_id snd_intel8x0
39195 + { 0x1022, 0x746d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_INTEL }, /* AMD8111 */
39196 + { 0x10b9, 0x5455, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALI }, /* Ali5455 */
39197 + #endif
39198 +- { 0, }
39199 ++ { 0, 0, 0, 0, 0, 0, 0 }
39200 + };
39201 +
39202 + MODULE_DEVICE_TABLE(pci, snd_intel8x0m_ids);
39203 +@@ -1258,7 +1258,7 @@ static struct shortname_table {
39204 + { 0x5455, "ALi M5455" },
39205 + { 0x746d, "AMD AMD8111" },
39206 + #endif
39207 +- { 0 },
39208 ++ { 0, NULL },
39209 + };
39210 +
39211 + static int __devinit snd_intel8x0m_probe(struct pci_dev *pci,
39212 +diff -urNp linux-2.6.28/virt/kvm/kvm_main.c linux-2.6.28/virt/kvm/kvm_main.c
39213 +--- linux-2.6.28/virt/kvm/kvm_main.c 2008-12-24 18:26:37.000000000 -0500
39214 ++++ linux-2.6.28/virt/kvm/kvm_main.c 2009-01-11 07:20:06.000000000 -0500
39215 +@@ -1765,6 +1765,9 @@ static struct miscdevice kvm_dev = {
39216 + KVM_MINOR,
39217 + "kvm",
39218 + &kvm_chardev_ops,
39219 ++ {NULL, NULL},
39220 ++ NULL,
39221 ++ NULL
39222 + };
39223 +
39224 + static void hardware_enable(void *junk)
39225
39226 Added: hardened/2.6/tags/2.6.28-1/4421_grsec-remove-localversion-grsec.patch
39227 ===================================================================
39228 --- hardened/2.6/tags/2.6.28-1/4421_grsec-remove-localversion-grsec.patch (rev 0)
39229 +++ hardened/2.6/tags/2.6.28-1/4421_grsec-remove-localversion-grsec.patch 2009-01-25 09:03:04 UTC (rev 1486)
39230 @@ -0,0 +1,9 @@
39231 +From: Kerin Millar <kerframil@×××××.com>
39232 +
39233 +Remove grsecurity's localversion-grsec file as it is inconsistent with
39234 +Gentoo's kernel practices and naming scheme.
39235 +
39236 +--- a/localversion-grsec 2008-02-24 14:26:59.000000000 +0000
39237 ++++ b/localversion-grsec 1970-01-01 01:00:00.000000000 +0100
39238 +@@ -1 +0,0 @@
39239 +--grsec
39240
39241 Added: hardened/2.6/tags/2.6.28-1/4422_grsec-mute-warnings.patch
39242 ===================================================================
39243 --- hardened/2.6/tags/2.6.28-1/4422_grsec-mute-warnings.patch (rev 0)
39244 +++ hardened/2.6/tags/2.6.28-1/4422_grsec-mute-warnings.patch 2009-01-25 09:03:04 UTC (rev 1486)
39245 @@ -0,0 +1,28 @@
39246 +From: Gordon Malm <gengor@g.o>
39247 +
39248 +Updated patch for kernel series 2.6.24.
39249 +
39250 +The credits/description from the original version of this patch remain accurate
39251 +and are included below.
39252 +
39253 +---
39254 +From: Alexander Gabert <gaberta@××××××××.de>
39255 +
39256 +This patch removes the warnings introduced by grsec patch 2.1.9 and later.
39257 +It removes the -W options added by the patch and restores the original
39258 +warning flags of vanilla kernel versions.
39259 +
39260 +Acked-by: Christian Heim <phreak@g.o>
39261 +---
39262 +
39263 +--- a/Makefile
39264 ++++ b/Makefile
39265 +@@ -214,7 +214,7 @@
39266 +
39267 + HOSTCC = gcc
39268 + HOSTCXX = g++
39269 +-HOSTCFLAGS = -Wall -W -Wno-unused -Wno-sign-compare -Wstrict-prototypes -O2 -fomit-frame-pointer
39270 ++HOSTCFLAGS = -Wall -Wstrict-prototypes -O2 -fomit-frame-pointer
39271 + HOSTCXXFLAGS = -O2
39272 +
39273 + # Decide whether to build built-in, modular, or both.
39274
39275 Added: hardened/2.6/tags/2.6.28-1/4425_grsec-pax-without-grsec.patch
39276 ===================================================================
39277 --- hardened/2.6/tags/2.6.28-1/4425_grsec-pax-without-grsec.patch (rev 0)
39278 +++ hardened/2.6/tags/2.6.28-1/4425_grsec-pax-without-grsec.patch 2009-01-25 09:03:04 UTC (rev 1486)
39279 @@ -0,0 +1,60 @@
39280 +From: Gordon Malm <gengor@g.o>
39281 +
39282 +Allow PaX options to be selected without first selecting CONFIG_GRKERNSEC.
39283 +
39284 +This patch has been updated to keep current with newer kernel versions.
39285 +The original version of this patch contained no credits/description.
39286 +
39287 +--- a/arch/x86/mm/fault.c
39288 ++++ b/arch/x86/mm/fault.c
39289 +@@ -431,10 +431,12 @@ static void show_fault_oops(struct pt_re
39290 + if (init_mm.start_code <= address && address < init_mm.end_code)
39291 + #endif
39292 + {
39293 ++#ifdef CONFIG_GRKERNSEC
39294 + if (current->signal->curr_ip)
39295 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
39296 + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
39297 + else
39298 ++#endif
39299 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
39300 + current->comm, task_pid_nr(current), current->uid, current->euid);
39301 + }
39302 +--- a/fs/exec.c
39303 ++++ b/fs/exec.c
39304 +@@ -1693,9 +1693,11 @@ void pax_report_fault(struct pt_regs *re
39305 + }
39306 + up_read(&mm->mmap_sem);
39307 + }
39308 ++#ifdef CONFIG_GRKERNSEC
39309 + if (tsk->signal->curr_ip)
39310 + 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);
39311 + else
39312 ++#endif
39313 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
39314 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
39315 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
39316 +@@ -1710,10 +1712,12 @@ void pax_report_fault(struct pt_regs *re
39317 + #ifdef CONFIG_PAX_REFCOUNT
39318 + void pax_report_refcount_overflow(struct pt_regs *regs)
39319 + {
39320 ++#ifdef CONFIG_GRKERNSEC
39321 + if (current->signal->curr_ip)
39322 + printk(KERN_ERR "PAX: From %u.%u.%u.%u: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
39323 + NIPQUAD(current->signal->curr_ip), current->comm, task_pid_nr(current), current->uid, current->euid);
39324 + else
39325 ++#endif
39326 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
39327 + current->comm, task_pid_nr(current), current->uid, current->euid);
39328 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
39329 +--- a/security/Kconfig
39330 ++++ b/security/Kconfig
39331 +@@ -10,7 +10,7 @@ menu "PaX"
39332 +
39333 + config PAX
39334 + bool "Enable various PaX features"
39335 +- depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
39336 ++ depends on (ALPHA || ARM || AVR32 || IA64 || MIPS32 || MIPS64 || PARISC || PPC32 || PPC64 || SPARC32 || SPARC64 || X86)
39337 + help
39338 + This allows you to enable various PaX features. PaX adds
39339 + intrusion prevention mechanisms to the kernel that reduce
39340
39341 Added: hardened/2.6/tags/2.6.28-1/4430_grsec-kconfig-default-gids.patch
39342 ===================================================================
39343 --- hardened/2.6/tags/2.6.28-1/4430_grsec-kconfig-default-gids.patch (rev 0)
39344 +++ hardened/2.6/tags/2.6.28-1/4430_grsec-kconfig-default-gids.patch 2009-01-25 09:03:04 UTC (rev 1486)
39345 @@ -0,0 +1,76 @@
39346 +From: Kerin Millar <kerframil@×××××.com>
39347 +
39348 +grsecurity contains a number of options which allow certain protections
39349 +to be applied to or exempted from members of a given group. However, the
39350 +default GIDs specified in the upstream patch are entirely arbitrary and
39351 +there is no telling which (if any) groups the GIDs will correlate with
39352 +on an end-user's system. Because some users don't pay a great deal of
39353 +attention to the finer points of kernel configuration, it is probably
39354 +wise to specify some reasonable defaults so as to stop careless users
39355 +from shooting themselves in the foot.
39356 +
39357 +--- a/grsecurity/Kconfig
39358 ++++ b/grsecurity/Kconfig
39359 +@@ -352,7 +564,7 @@
39360 + config GRKERNSEC_PROC_GID
39361 + int "GID for special group"
39362 + depends on GRKERNSEC_PROC_USERGROUP
39363 +- default 1001
39364 ++ default 10
39365 +
39366 + config GRKERNSEC_PROC_ADD
39367 + bool "Additional restrictions"
39368 +@@ -547,7 +759,7 @@
39369 + config GRKERNSEC_AUDIT_GID
39370 + int "GID for auditing"
39371 + depends on GRKERNSEC_AUDIT_GROUP
39372 +- default 1007
39373 ++ default 100
39374 +
39375 + config GRKERNSEC_EXECLOG
39376 + bool "Exec logging"
39377 +@@ -700,7 +912,7 @@
39378 + config GRKERNSEC_TPE_GID
39379 + int "GID for untrusted users"
39380 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
39381 +- default 1005
39382 ++ default 100
39383 + help
39384 + If you have selected the "Invert GID option" above, setting this
39385 + GID determines what group TPE restrictions will be *disabled* for.
39386 +@@ -712,7 +924,7 @@
39387 + config GRKERNSEC_TPE_GID
39388 + int "GID for trusted users"
39389 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
39390 +- default 1005
39391 ++ default 10
39392 + help
39393 + If you have selected the "Invert GID option" above, setting this
39394 + GID determines what group TPE restrictions will be *disabled* for.
39395 +@@ -754,7 +966,7 @@
39396 + config GRKERNSEC_SOCKET_ALL_GID
39397 + int "GID to deny all sockets for"
39398 + depends on GRKERNSEC_SOCKET_ALL
39399 +- default 1004
39400 ++ default 65534
39401 + help
39402 + Here you can choose the GID to disable socket access for. Remember to
39403 + add the users you want socket access disabled for to the GID
39404 +@@ -775,7 +987,7 @@
39405 + config GRKERNSEC_SOCKET_CLIENT_GID
39406 + int "GID to deny client sockets for"
39407 + depends on GRKERNSEC_SOCKET_CLIENT
39408 +- default 1003
39409 ++ default 65534
39410 + help
39411 + Here you can choose the GID to disable client socket access for.
39412 + Remember to add the users you want client socket access disabled for to
39413 +@@ -793,7 +1005,7 @@
39414 + config GRKERNSEC_SOCKET_SERVER_GID
39415 + int "GID to deny server sockets for"
39416 + depends on GRKERNSEC_SOCKET_SERVER
39417 +- default 1002
39418 ++ default 65534
39419 + help
39420 + Here you can choose the GID to disable server socket access for.
39421 + Remember to add the users you want server socket access disabled for to
39422
39423 Added: hardened/2.6/tags/2.6.28-1/4435_grsec-kconfig-gentoo.patch
39424 ===================================================================
39425 --- hardened/2.6/tags/2.6.28-1/4435_grsec-kconfig-gentoo.patch (rev 0)
39426 +++ hardened/2.6/tags/2.6.28-1/4435_grsec-kconfig-gentoo.patch 2009-01-25 09:03:04 UTC (rev 1486)
39427 @@ -0,0 +1,243 @@
39428 +From: Gordon Malm <gengor@g.o>
39429 +From: Kerin Millar <kerframil@×××××.com>
39430 +
39431 +Add Hardened Gentoo [server/workstation] predefined grsecurity
39432 +levels. They're designed to provide a comparitively high level of
39433 +security while remaining generally suitable for as great a majority
39434 +of the userbase as possible (particularly new users).
39435 +
39436 +Make Hardened Gentoo [workstation] predefined grsecurity level the
39437 +default. The Hardened Gentoo [server] level is more restrictive
39438 +and conflicts with some software and thus would be less suitable.
39439 +
39440 +The original version of this patch was conceived and created by:
39441 +Ned Ludd <solar@g.o>
39442 +
39443 +--- a/grsecurity/Kconfig
39444 ++++ b/grsecurity/Kconfig
39445 +@@ -20,7 +20,7 @@ config GRKERNSEC
39446 + choice
39447 + prompt "Security Level"
39448 + depends on GRKERNSEC
39449 +- default GRKERNSEC_CUSTOM
39450 ++ default GRKERNSEC_HARDENED_WORKSTATION
39451 +
39452 + config GRKERNSEC_LOW
39453 + bool "Low"
39454 +@@ -183,6 +183,216 @@ config GRKERNSEC_HIGH
39455 + - Mount/unmount/remount logging
39456 + - Kernel symbol hiding
39457 + - Prevention of memory exhaustion-based exploits
39458 ++
39459 ++config GRKERNSEC_HARDENED_SERVER
39460 ++ bool "Hardened Gentoo [server]"
39461 ++ select GRKERNSEC_AUDIT_MOUNT
39462 ++ select GRKERNSEC_BRUTE
39463 ++ select GRKERNSEC_CHROOT
39464 ++ select GRKERNSEC_CHROOT_CAPS
39465 ++ select GRKERNSEC_CHROOT_CHDIR
39466 ++ select GRKERNSEC_CHROOT_CHMOD
39467 ++ select GRKERNSEC_CHROOT_DOUBLE
39468 ++ select GRKERNSEC_CHROOT_FCHDIR
39469 ++ select GRKERNSEC_CHROOT_FINDTASK
39470 ++ select GRKERNSEC_CHROOT_MKNOD
39471 ++ select GRKERNSEC_CHROOT_MOUNT
39472 ++ select GRKERNSEC_CHROOT_NICE
39473 ++ select GRKERNSEC_CHROOT_PIVOT
39474 ++ select GRKERNSEC_CHROOT_SHMAT
39475 ++ select GRKERNSEC_CHROOT_SYSCTL
39476 ++ select GRKERNSEC_CHROOT_UNIX
39477 ++ select GRKERNSEC_DMESG
39478 ++ select GRKERNSEC_EXECVE
39479 ++ select GRKERNSEC_FIFO
39480 ++ select GRKERNSEC_FORKFAIL
39481 ++ select GRKERNSEC_HIDESYM
39482 ++ select GRKERNSEC_IO if (X86)
39483 ++ select GRKERNSEC_KMEM
39484 ++ select GRKERNSEC_LINK
39485 ++ select GRKERNSEC_MODSTOP if (MODULES)
39486 ++ select GRKERNSEC_PROC
39487 ++ select GRKERNSEC_PROC_ADD
39488 ++ select GRKERNSEC_PROC_IPADDR
39489 ++ select GRKERNSEC_PROC_MEMMAP
39490 ++ select GRKERNSEC_PROC_USERGROUP
39491 ++ select GRKERNSEC_RANDNET
39492 ++ select GRKERNSEC_RESLOG
39493 ++ select GRKERNSEC_SIGNAL
39494 ++# select GRKERNSEC_SOCKET
39495 ++# select GRKERNSEC_SOCKET_SERVER
39496 ++ select GRKERNSEC_SYSCTL
39497 ++ select GRKERNSEC_SYSCTL_ON
39498 ++ select GRKERNSEC_TIME
39499 ++ select PAX
39500 ++ select PAX_ASLR
39501 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
39502 ++ select PAX_EI_PAX
39503 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
39504 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
39505 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
39506 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
39507 ++ select PAX_KERNEXEC if (X86 && !EFI && !COMPAT_VDSO && !PARAVIRT && (!X86_32 || X86_WP_WORKS_OK))
39508 ++ select PAX_MEMORY_SANITIZE
39509 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
39510 ++ select PAX_MPROTECT if (!PPC64)
39511 ++ select PAX_HAVE_ACL_FLAGS
39512 ++ select PAX_NOELFRELOCS if (X86)
39513 ++ select PAX_NOEXEC
39514 ++ select PAX_PAGEEXEC
39515 ++ select PAX_PT_PAX_FLAGS
39516 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
39517 ++ select PAX_RANDMMAP
39518 ++ select PAX_RANDUSTACK
39519 ++ select PAX_REFCOUNT if (X86)
39520 ++ select PAX_SEGMEXEC if (X86_32)
39521 ++ select PAX_SYSCALL if (PPC32)
39522 ++ help
39523 ++ If you say Y here, a configuration will be used that is endorsed by
39524 ++ the Hardened Gentoo project. Therefore, many of the protections
39525 ++ made available by grsecurity and PaX will be enabled.
39526 ++
39527 ++ Hardened Gentoo's pre-defined security levels are designed to provide
39528 ++ a high level of security while minimizing incompatibilities with the
39529 ++ majority of available software. For further information, please
39530 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
39531 ++ well as the Hardened Gentoo Primer at
39532 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
39533 ++
39534 ++ This Hardened Gentoo [server] level is identical to the
39535 ++ Hardened Gentoo [workstation] level, but with the GRKERNSEC_IO,
39536 ++ PAX_KERNEXEC and PAX_NOELFRELOCS security features enabled.
39537 ++ Accordingly, this is the preferred security level if the system will
39538 ++ not be utilizing software incompatible with the aforementioned
39539 ++ grsecurity/PaX features.
39540 ++
39541 ++ You may wish to emerge paxctl, a utility which allows you to toggle
39542 ++ PaX features on problematic binaries on an individual basis. Note that
39543 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
39544 ++ Translated, this means that if you wish to toggle PaX features on
39545 ++ binaries provided by applications that are distributed only in binary
39546 ++ format (rather than being built locally from sources), you will need to
39547 ++ run paxctl -C on the binaries beforehand so as to inject the missing
39548 ++ headers.
39549 ++
39550 ++ When this level is selected, some options cannot be changed. However,
39551 ++ you may opt to fully customize the options that are selected by
39552 ++ choosing "Custom" in the Security Level menu. You may find it helpful
39553 ++ to inherit the options selected by the "Hardened Gentoo [server]"
39554 ++ security level as a starting point for further configuration. To
39555 ++ accomplish this, select this security level then exit the menuconfig
39556 ++ interface, saving changes when prompted. Then, run make menuconfig
39557 ++ again and select the "Custom" level.
39558 ++
39559 ++ Note that this security level probably should not be used if the
39560 ++ target system is a 32bit x86 virtualized guest. If you intend to run
39561 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
39562 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
39563 ++ impact on performance.
39564 ++
39565 ++config GRKERNSEC_HARDENED_WORKSTATION
39566 ++ bool "Hardened Gentoo [workstation]"
39567 ++ select GRKERNSEC_AUDIT_MOUNT
39568 ++ select GRKERNSEC_BRUTE
39569 ++ select GRKERNSEC_CHROOT
39570 ++ select GRKERNSEC_CHROOT_CAPS
39571 ++ select GRKERNSEC_CHROOT_CHDIR
39572 ++ select GRKERNSEC_CHROOT_CHMOD
39573 ++ select GRKERNSEC_CHROOT_DOUBLE
39574 ++ select GRKERNSEC_CHROOT_FCHDIR
39575 ++ select GRKERNSEC_CHROOT_FINDTASK
39576 ++ select GRKERNSEC_CHROOT_MKNOD
39577 ++ select GRKERNSEC_CHROOT_MOUNT
39578 ++ select GRKERNSEC_CHROOT_NICE
39579 ++ select GRKERNSEC_CHROOT_PIVOT
39580 ++ select GRKERNSEC_CHROOT_SHMAT
39581 ++ select GRKERNSEC_CHROOT_SYSCTL
39582 ++ select GRKERNSEC_CHROOT_UNIX
39583 ++ select GRKERNSEC_DMESG
39584 ++ select GRKERNSEC_EXECVE
39585 ++ select GRKERNSEC_FIFO
39586 ++ select GRKERNSEC_FORKFAIL
39587 ++ select GRKERNSEC_HIDESYM
39588 ++ select GRKERNSEC_KMEM
39589 ++ select GRKERNSEC_LINK
39590 ++ select GRKERNSEC_MODSTOP if (MODULES)
39591 ++ select GRKERNSEC_PROC
39592 ++ select GRKERNSEC_PROC_ADD
39593 ++ select GRKERNSEC_PROC_IPADDR
39594 ++ select GRKERNSEC_PROC_MEMMAP
39595 ++ select GRKERNSEC_PROC_USERGROUP
39596 ++ select GRKERNSEC_RANDNET
39597 ++ select GRKERNSEC_RESLOG
39598 ++ select GRKERNSEC_SIGNAL
39599 ++# select GRKERNSEC_SOCKET
39600 ++# select GRKERNSEC_SOCKET_SERVER
39601 ++ select GRKERNSEC_SYSCTL
39602 ++ select GRKERNSEC_SYSCTL_ON
39603 ++ select GRKERNSEC_TIME
39604 ++ select PAX
39605 ++ select PAX_ASLR
39606 ++ select PAX_DLRESOLVE if (SPARC32 || SPARC64)
39607 ++ select PAX_EI_PAX
39608 ++ select PAX_EMUPLT if (ALPHA || PARISC || PPC32 || SPARC32 || SPARC64)
39609 ++ select PAX_EMUSIGRT if (PARISC || PPC32)
39610 ++ select PAX_EMUTRAMP if (PARISC || PPC32)
39611 ++ select PAX_ETEXECRELOCS if (ALPHA || IA64 || PARISC)
39612 ++ select PAX_MEMORY_SANITIZE
39613 ++ select PAX_MEMORY_UDEREF if (X86_32 && !COMPAT_VDSO && !UML_X86)
39614 ++ select PAX_MPROTECT if (!PPC64)
39615 ++ select PAX_HAVE_ACL_FLAGS
39616 ++ select PAX_NOEXEC
39617 ++ select PAX_PAGEEXEC
39618 ++ select PAX_PT_PAX_FLAGS
39619 ++ select PAX_RANDKSTACK if (X86_32 && X86_TSC)
39620 ++ select PAX_RANDMMAP
39621 ++ select PAX_RANDUSTACK
39622 ++ select PAX_REFCOUNT if (X86)
39623 ++ select PAX_SEGMEXEC if (X86_32)
39624 ++ select PAX_SYSCALL if (PPC32)
39625 ++ help
39626 ++ If you say Y here, a configuration will be used that is endorsed by
39627 ++ the Hardened Gentoo project. Therefore, many of the protections
39628 ++ made available by grsecurity and PaX will be enabled.
39629 ++
39630 ++ Hardened Gentoo's pre-defined security levels are designed to provide
39631 ++ a high level of security while minimizing incompatibilities with the
39632 ++ majority of available software. For further information, please
39633 ++ view <http://www.grsecurity.net> and <http://pax.grsecurity.net> as
39634 ++ well as the Hardened Gentoo Primer at
39635 ++ <http://www.gentoo.org/proj/en/hardened/primer.xml>.
39636 ++
39637 ++ This Hardened Gentoo [workstation] level is designed for machines
39638 ++ which are intended to run software not compatible with the
39639 ++ GRKERNSEC_IO, PAX_KERNEXEC and PAX_NOELFRELOCS features of grsecurity.
39640 ++ Accordingly, this security level is suitable for use with the X server
39641 ++ "Xorg" and/or any system that will act as host OS to the virtualization
39642 ++ softwares vmware-server or virtualbox.
39643 ++
39644 ++ You may wish to emerge paxctl, a utility which allows you to toggle
39645 ++ PaX features on problematic binaries on an individual basis. Note that
39646 ++ this only works for ELF binaries that contain a PT_PAX_FLAGS header.
39647 ++ Translated, this means that if you wish to toggle PaX features on
39648 ++ binaries provided by applications that are distributed only in binary
39649 ++ format (rather than being built locally from sources), you will need to
39650 ++ run paxctl -C on the binaries beforehand so as to inject the missing
39651 ++ headers.
39652 ++
39653 ++ When this level is selected, some options cannot be changed. However,
39654 ++ you may opt to fully customize the options that are selected by
39655 ++ choosing "Custom" in the Security Level menu. You may find it helpful
39656 ++ to inherit the options selected by the "Hardened Gentoo [workstation]"
39657 ++ security level as a starting point for further configuration. To
39658 ++ accomplish this, select this security level then exit the menuconfig
39659 ++ interface, saving changes when prompted. Then, run make menuconfig
39660 ++ again and select the "Custom" level.
39661 ++
39662 ++ Note that this security level probably should not be used if the
39663 ++ target system is a 32bit x86 virtualized guest. If you intend to run
39664 ++ the kernel in a 32bit x86 virtualized guest you will likely need to
39665 ++ disable the PAX_MEMORY_UDEREF option in order to avoid an unacceptable
39666 ++ impact on performance.
39667 ++
39668 + config GRKERNSEC_CUSTOM
39669 + bool "Custom"
39670 + help
39671
39672 Added: hardened/2.6/tags/2.6.28-1/4440_selinux-avc_audit-log-curr_ip.patch
39673 ===================================================================
39674 --- hardened/2.6/tags/2.6.28-1/4440_selinux-avc_audit-log-curr_ip.patch (rev 0)
39675 +++ hardened/2.6/tags/2.6.28-1/4440_selinux-avc_audit-log-curr_ip.patch 2009-01-25 09:03:04 UTC (rev 1486)
39676 @@ -0,0 +1,65 @@
39677 +From: Gordon Malm <gengor@g.o>
39678 +
39679 +This is a reworked version of the original
39680 +*_selinux-avc_audit-log-curr_ip.patch carried in earlier releases of
39681 +hardened-sources.
39682 +
39683 +Dropping the patch, or simply fixing the #ifdef of the original patch
39684 +could break automated logging setups so this route was necessary.
39685 +
39686 +Suggestions for improving the help text are welcome.
39687 +
39688 +The original patch's description is still accurate and included below.
39689 +
39690 +---
39691 +Provides support for a new field ipaddr within the SELinux
39692 +AVC audit log, relying in task_struct->curr_ip (ipv4 only)
39693 +provided by grSecurity patch to be applied before.
39694 +
39695 +Signed-off-by: Lorenzo Hernandez Garcia-Hierro <lorenzo@×××.org>
39696 +---
39697 +
39698 +--- a/grsecurity/Kconfig
39699 ++++ b/grsecurity/Kconfig
39700 +@@ -1044,6 +1044,27 @@ endmenu
39701 + menu "Logging Options"
39702 + depends on GRKERNSEC
39703 +
39704 ++config GRKERNSEC_SELINUX_AVC_LOG_IPADDR
39705 ++ def_bool n
39706 ++ prompt "Add source IP address to SELinux AVC log messages"
39707 ++ depends on GRKERNSEC && SECURITY_SELINUX
39708 ++ help
39709 ++ If you say Y here, a new field "ipaddr=" will be added to many SELinux
39710 ++ AVC log messages. The value of this field in any given message
39711 ++ represents the source IP address of the remote machine/user that created
39712 ++ the offending process.
39713 ++
39714 ++ This information is sourced from task_struct->curr_ip provided by
39715 ++ grsecurity's GRKERNSEC top-level configuration option. One limitation
39716 ++ is that only IPv4 is supported.
39717 ++
39718 ++ In many instances SELinux AVC log messages already log a superior level
39719 ++ of information that also includes source port and destination ip/port.
39720 ++ Additionally, SELinux's AVC log code supports IPv6.
39721 ++
39722 ++ However, grsecurity's task_struct->curr_ip will sometimes (often?)
39723 ++ provide the offender's IP address where stock SELinux logging fails to.
39724 ++
39725 + config GRKERNSEC_FLOODTIME
39726 + int "Seconds in between log messages (minimum)"
39727 + default 10
39728 +--- a/security/selinux/avc.c
39729 ++++ b/security/selinux/avc.c
39730 +@@ -202,6 +202,11 @@ static void avc_dump_query(struct audit_
39731 + char *scontext;
39732 + u32 scontext_len;
39733 +
39734 ++#ifdef CONFIG_GRKERNSEC_SELINUX_AVC_LOG_IPADDR
39735 ++ if (current->signal->curr_ip)
39736 ++ audit_log_format(ab, "ipaddr=%u.%u.%u.%u ", NIPQUAD(current->signal->curr_ip));
39737 ++#endif
39738 ++
39739 + rc = security_sid_to_context(ssid, &scontext, &scontext_len);
39740 + if (rc)
39741 + audit_log_format(ab, "ssid=%d", ssid);
39742
39743 Added: hardened/2.6/tags/2.6.28-1/4445_disable-compat_vdso.patch
39744 ===================================================================
39745 --- hardened/2.6/tags/2.6.28-1/4445_disable-compat_vdso.patch (rev 0)
39746 +++ hardened/2.6/tags/2.6.28-1/4445_disable-compat_vdso.patch 2009-01-25 09:03:04 UTC (rev 1486)
39747 @@ -0,0 +1,74 @@
39748 +From: Gordon Malm <gengor@g.o>
39749 +From: Kerin Millar <kerframil@×××××.com>
39750 +
39751 +COMPAT_VDSO is inappropriate for any modern Hardened Gentoo system. It
39752 +conflicts with various parts of PaX, crashing the system if enabled
39753 +while PaX's NOEXEC or UDEREF features are active. Moreover, it prevents
39754 +a number of important PaX options from appearing in the configuration
39755 +menu, including all PaX NOEXEC implementations. Unfortunately, the
39756 +reason for the disappearance of these PaX configuration options is
39757 +often far from obvious to inexperienced users.
39758 +
39759 +Therefore, we disable the COMPAT_VDSO menu entry entirely. However,
39760 +COMPAT_VDSO operation can still be enabled via bootparam and sysctl
39761 +interfaces. Consequently, we must also disable the ability to select
39762 +COMPAT_VDSO operation at boot or runtime. Here we patch the kernel so
39763 +that selecting COMPAT_VDSO operation at boot/runtime has no effect if
39764 +conflicting PaX options are enabled, leaving VDSO_ENABLED operation
39765 +intact.
39766 +
39767 +Closes bug: http://bugs.gentoo.org/show_bug.cgi?id=210138
39768 +
39769 +--- a/arch/x86/Kconfig
39770 ++++ b/arch/x86/Kconfig
39771 +@@ -1215,16 +1215,7 @@ config HOTPLUG_CPU
39772 +
39773 + config COMPAT_VDSO
39774 + def_bool n
39775 +- prompt "Compat VDSO support"
39776 + depends on (X86_32 || IA32_EMULATION) && !PAX_NOEXEC
39777 +- help
39778 +- Map the 32-bit VDSO to the predictable old-style address too.
39779 +- ---help---
39780 +- Say N here if you are running a sufficiently recent glibc
39781 +- version (2.3.3 or later), to remove the high-mapped
39782 +- VDSO mapping and to exclusively use the randomized VDSO.
39783 +-
39784 +- If unsure, say Y.
39785 +
39786 + endmenu
39787 +
39788 +--- a/arch/x86/vdso/vdso32-setup.c
39789 ++++ b/arch/x86/vdso/vdso32-setup.c
39790 +@@ -333,17 +333,21 @@ int arch_setup_additional_pages(struct l
39791 +
39792 + map_compat_vdso(compat);
39793 +
39794 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
39795 + if (compat)
39796 + addr = VDSO_HIGH_BASE;
39797 + else {
39798 ++#endif
39799 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
39800 + if (IS_ERR_VALUE(addr)) {
39801 + ret = addr;
39802 + goto up_fail;
39803 + }
39804 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
39805 + }
39806 +
39807 + if (compat_uses_vma || !compat) {
39808 ++#endif
39809 + /*
39810 + * MAYWRITE to allow gdb to COW and set breakpoints
39811 + *
39812 +@@ -361,7 +365,9 @@ int arch_setup_additional_pages(struct l
39813 +
39814 + if (ret)
39815 + goto up_fail;
39816 ++#if !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_MEMORY_UDEREF)
39817 + }
39818 ++#endif
39819 +
39820 + current->mm->context.vdso = addr;
39821 + current_thread_info()->sysenter_return =
39822
39823 Added: hardened/2.6/tags/2.6.28-1/4450_pax-2.6.28.1-test8-to-test10.patch
39824 ===================================================================
39825 --- hardened/2.6/tags/2.6.28-1/4450_pax-2.6.28.1-test8-to-test10.patch (rev 0)
39826 +++ hardened/2.6/tags/2.6.28-1/4450_pax-2.6.28.1-test8-to-test10.patch 2009-01-25 09:03:04 UTC (rev 1486)
39827 @@ -0,0 +1,33 @@
39828 +From: Gordon Malm <gengor@g.o>
39829 +
39830 +PaX: Add changes from pax-2.6.28.1-test9 and pax-2.6.28.1-test10
39831 +which are not yet integrated into main grsecurity-2.6.28.X patch.
39832 +
39833 +--- a/arch/x86/boot/compressed/relocs.c
39834 ++++ b/arch/x86/boot/compressed/relocs.c
39835 +@@ -399,7 +399,7 @@
39836 + for (j = 0; j < ehdr.e_phnum; j++) {
39837 + if (phdr[j].p_type != PT_LOAD )
39838 + continue;
39839 +- 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)
39840 ++ if (secs[sec->shdr.sh_info].shdr.sh_offset < phdr[j].p_offset || secs[sec->shdr.sh_info].shdr.sh_offset >= phdr[j].p_offset + phdr[j].p_filesz)
39841 + continue;
39842 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
39843 + break;
39844 +--- a/arch/x86/mm/fault.c
39845 ++++ b/arch/x86/mm/fault.c
39846 +@@ -839,8 +839,12 @@
39847 + * and pusha to work. ("enter $65535,$31" pushes
39848 + * 32 pointers and then decrements %sp by 65535.)
39849 + */
39850 +- if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp)
39851 +- goto bad_area;
39852 ++ if (address + 65536 + 32 * sizeof(unsigned long) < regs->sp) {
39853 ++ if (error_code & PF_USER)
39854 ++ goto bad_area;
39855 ++ printk(KERN_ERR "PAX: abnormal kernel stack expansion: %s(%d) %lx %lx-%lx\n", tsk->comm, task_pid_nr(tsk), address, vma->vm_start, vma->vm_end);
39856 ++ dump_stack();
39857 ++ }
39858 +
39859 + #ifdef CONFIG_PAX_SEGMEXEC
39860 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)