diff --git a/Documentation/dontdiff b/Documentation/dontdiff
-index b89a739..31509cb 100644
+index b89a739..e289b9b 100644
--- a/Documentation/dontdiff
+++ b/Documentation/dontdiff
@@ -2,9 +2,11 @@
r300_reg_safe.h
r420_reg_safe.h
r600_reg_safe.h
-+randstruct.seed
-+randstruct.hashed_seed
++randomize_layout_hash.h
++randomize_layout_seed.h
+realmode.lds
+realmode.relocs
recordmcount
pcd. [PARIDE]
diff --git a/Makefile b/Makefile
-index de4cda9..d1183df 100644
+index a7fd5d9..dc8e4db 100644
--- a/Makefile
+++ b/Makefile
@@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
# Decide whether to build built-in, modular, or both.
# Normally, just do built-in.
-@@ -417,8 +418,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
+@@ -311,9 +312,15 @@ endif
+ # If the user is running make -s (silent mode), suppress echoing of
+ # commands
+
++ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
++ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
++ quiet=silent_
++endif
++else # make-3.8x
+ ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
+ quiet=silent_
+ endif
++endif
+
+ export quiet Q KBUILD_VERBOSE
+
+@@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
# Rules shared between *config targets and build targets
# Basic helpers built in scripts/
$(Q)$(MAKE) $(build)=scripts/basic
$(Q)rm -f .tmp_quiet_recordmcount
-@@ -579,6 +580,76 @@ else
+@@ -579,6 +586,72 @@ else
KBUILD_CFLAGS += -O2
endif
+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
+endif
+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
-+GRKERNSEC_RANDSTRUCT_SEED := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gen-random-seed.sh)
+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
-+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-seed=$(GRKERNSEC_RANDSTRUCT_SEED)
-+RANDSTRUCT_HASHED_SEED := $(shell cat "$(srctree)/tools/gcc/randstruct.hashed_seed")
-+RANDSTRUCT_PLUGIN_CFLAGS += -DRANDSTRUCT_HASHED_SEED="\"$(RANDSTRUCT_HASHED_SEED)\""
-+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
++ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
+endif
+endif
include $(srctree)/arch/$(SRCARCH)/Makefile
ifdef CONFIG_READABLE_ASM
-@@ -754,7 +825,7 @@ export mod_sign_cmd
+@@ -619,7 +692,7 @@ endif
+
+ ifdef CONFIG_DEBUG_INFO
+ KBUILD_CFLAGS += -g
+-KBUILD_AFLAGS += -gdwarf-2
++KBUILD_AFLAGS += -Wa,--gdwarf-2
+ endif
+
+ ifdef CONFIG_DEBUG_INFO_REDUCED
+@@ -754,7 +827,7 @@ export mod_sign_cmd
ifeq ($(KBUILD_EXTMOD),)
vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
$(core-y) $(core-m) $(drivers-y) $(drivers-m) \
-@@ -803,6 +874,8 @@ endif
+@@ -803,6 +876,8 @@ endif
# The actual objects are generated when descending,
# make sure no implicit rule kicks in
$(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
# Handle descending into subdirectories listed in $(vmlinux-dirs)
-@@ -812,7 +885,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
+@@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
# Error messages still appears in the original language
PHONY += $(vmlinux-dirs)
$(Q)$(MAKE) $(build)=$@
define filechk_kernel.release
-@@ -855,10 +928,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
+@@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
archprepare: archheaders archscripts prepare1 scripts_basic
prepare: prepare0
# Generate some files
-@@ -966,6 +1042,8 @@ all: modules
+@@ -966,6 +1044,8 @@ all: modules
# using awk while concatenating to the final file.
PHONY += modules
modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
$(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
@$(kecho) ' Building modules, stage 2.';
-@@ -981,7 +1059,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
+@@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
# Target to prepare building external modules
PHONY += modules_prepare
# Target to install modules
PHONY += modules_install
-@@ -1047,7 +1125,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
+@@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
signing_key.priv signing_key.x509 x509.genkey \
extra_certificates signing_key.x509.keyid \
- signing_key.x509.signer
+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
-+ tools/gcc/randstruct.seed tools/gcc/randstruct.hashed_seed
++ tools/gcc/randomize_layout_seed.h
# clean - Delete most, but leave enough to build external modules
#
-@@ -1087,6 +1166,7 @@ distclean: mrproper
+@@ -1087,6 +1168,7 @@ distclean: mrproper
\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
-o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
-o -name '.*.rej' \
-o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
-type f -print | xargs rm -f
-@@ -1248,6 +1328,8 @@ PHONY += $(module-dirs) modules
+@@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
$(module-dirs): crmodverdir $(objtree)/Module.symvers
$(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
modules: $(module-dirs)
@$(kecho) ' Building modules, stage 2.';
$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
-@@ -1387,17 +1469,21 @@ else
+@@ -1387,17 +1471,21 @@ else
target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
endif
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
%.symtypes: %.c prepare scripts FORCE
$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
-@@ -1407,11 +1493,15 @@ endif
+@@ -1407,11 +1495,15 @@ endif
$(cmd_crmodverdir)
$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
$(build)=$(build-dir)
/* omap_hwmod_list contains all registered struct omap_hwmods */
static LIST_HEAD(omap_hwmod_list);
+diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
+index 95fee54..cfa9cf1 100644
+--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
++++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
+@@ -10,6 +10,7 @@
+
+ #include <linux/kernel.h>
+ #include <linux/init.h>
++#include <asm/pgtable.h>
+
+ #include "powerdomain.h"
+
+@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
+
+ void __init am43xx_powerdomains_init(void)
+ {
+- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
++ pax_open_kernel();
++ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
++ pax_close_kernel();
+ pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
+ pwrdm_register_pwrdms(powerdomains_am43xx);
+ pwrdm_complete_init();
diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
index d15c7bb..b2d1f0c 100644
--- a/arch/arm/mach-omap2/wd_timer.c
#endif
#endif /* _ASM_X86_THREAD_INFO_H */
diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
-index e6d90ba..0897f44 100644
+index e6d90ba..f81f114 100644
--- a/arch/x86/include/asm/tlbflush.h
+++ b/arch/x86/include/asm/tlbflush.h
@@ -17,18 +17,44 @@
}
static inline void __native_flush_tlb_global(void)
-@@ -49,6 +75,42 @@ static inline void __native_flush_tlb_global(void)
+@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
static inline void __native_flush_tlb_single(unsigned long addr)
{
-+
+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
+ u64 descriptor[2];
+
obj-y += proc.o capflags.o powerflags.o common.o
obj-y += rdrand.o
diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
-index bca023b..c544908 100644
+index 59bfebc..d8f27bd 100644
--- a/arch/x86/kernel/cpu/amd.c
+++ b/arch/x86/kernel/cpu/amd.c
-@@ -743,7 +743,7 @@ static void init_amd(struct cpuinfo_x86 *c)
+@@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
{
/* AMD errata T13 (order #21922) */
out:
diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
-index 775702f..737d4a9 100644
+index d86ff15..e77b023 100644
--- a/arch/x86/kvm/lapic.c
+++ b/arch/x86/kvm/lapic.c
@@ -55,7 +55,7 @@
vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
-index 5d004da..0802480 100644
+index d89d51b..f3c612a 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
-@@ -1788,8 +1788,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
+@@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
{
struct kvm *kvm = vcpu->kvm;
int lm = is_long_mode(vcpu);
u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
: kvm->arch.xen_hvm_config.blob_size_32;
u32 page_num = data & ~PAGE_MASK;
-@@ -2673,6 +2673,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
+@@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
if (n < msr_list.nmsrs)
goto out;
r = -EFAULT;
if (copy_to_user(user_msr_list->indices, &msrs_to_save,
num_msrs_to_save * sizeof(u32)))
goto out;
-@@ -5482,7 +5484,7 @@ static struct notifier_block pvclock_gtod_notifier = {
+@@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
};
#endif
unsigned long timeout_msec)
{
diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
-index 1393a58..3bf8cbe 100644
+index 1a3dbd1..dfc6e5c 100644
--- a/drivers/ata/libata-core.c
+++ b/drivers/ata/libata-core.c
@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
struct ata_force_param {
const char *name;
-@@ -4823,7 +4823,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
+@@ -4850,7 +4850,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
struct ata_port *ap;
unsigned int tag;
ap = qc->ap;
qc->flags = 0;
-@@ -4839,7 +4839,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
+@@ -4866,7 +4866,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
struct ata_port *ap;
struct ata_link *link;
WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
ap = qc->ap;
link = qc->dev->link;
-@@ -5958,6 +5958,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
+@@ -5985,6 +5985,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
return;
spin_lock(&lock);
for (cur = ops->inherits; cur; cur = cur->inherits) {
void **inherit = (void **)cur;
-@@ -5971,8 +5972,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
+@@ -5998,8 +5999,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
if (IS_ERR(*pp))
*pp = NULL;
spin_unlock(&lock);
}
-@@ -6165,7 +6167,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
+@@ -6192,7 +6194,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
/* give ports names and add SCSI hosts */
for (i = 0; i < host->n_ports; i++) {
}
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
-index 377eb88..8591b44 100644
+index ef8567d..8bdbd03 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
-@@ -4135,7 +4135,7 @@ int ata_sas_port_init(struct ata_port *ap)
+@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
if (rc)
return rc;
return -EINVAL;
}
+diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
+index 62d0ff3..073dbf3 100644
+--- a/drivers/gpu/drm/armada/armada_drv.c
++++ b/drivers/gpu/drm/armada/armada_drv.c
+@@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
+ {
+ struct armada_private *priv = dev->dev_private;
+
+- /*
+- * Yes, we really must jump through these hoops just to store a
+- * _pointer_ to something into the kfifo. This is utterly insane
+- * and idiotic, because it kfifo requires the _data_ pointed to by
+- * the pointer const, not the pointer itself. Not only that, but
+- * you have to pass a pointer _to_ the pointer you want stored.
+- */
+- const struct drm_framebuffer *silly_api_alert = fb;
+- WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
++ WARN_ON(!kfifo_put(&priv->fb_unref, fb));
+ schedule_work(&priv->fb_unref_work);
+ }
+
diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index d6cf77c..2842146 100644
--- a/drivers/gpu/drm/drm_crtc.c
err = drm_debugfs_create_files(dc->debugfs_files,
ARRAY_SIZE(debugfs_files),
+diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
+index 0cd9bc2..9759be4 100644
+--- a/drivers/gpu/drm/tegra/hdmi.c
++++ b/drivers/gpu/drm/tegra/hdmi.c
+@@ -57,7 +57,7 @@ struct tegra_hdmi {
+ bool stereo;
+ bool dvi;
+
+- struct drm_info_list *debugfs_files;
++ drm_info_list_no_const *debugfs_files;
+ struct drm_minor *minor;
+ struct dentry *debugfs;
+ };
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index c58eba33..83c2728 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
"c2port%d", c2dev->id);
+diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
+index 9c34e57..b981cda 100644
+--- a/drivers/misc/eeprom/sunxi_sid.c
++++ b/drivers/misc/eeprom/sunxi_sid.c
+@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
+
+ platform_set_drvdata(pdev, sid_data);
+
+- sid_bin_attr.size = sid_data->keysize;
++ pax_open_kernel();
++ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
++ pax_close_kernel();
+ if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
+ return -ENODEV;
+
diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
index 36f5d52..32311c3 100644
--- a/drivers/misc/kgdbts.c
mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
}
+diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
+index 1dcaf8a..025af25 100644
+--- a/drivers/mmc/host/sdhci-esdhc-imx.c
++++ b/drivers/mmc/host/sdhci-esdhc-imx.c
+@@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
+ host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
+ }
+
+- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
+- sdhci_esdhc_ops.platform_execute_tuning =
++ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
++ pax_open_kernel();
++ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
+ esdhc_executing_tuning;
++ pax_close_kernel();
++ }
+ boarddata = &imx_data->boarddata;
+ if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
+ if (!host->mmc->parent->platform_data) {
diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
index 6debda9..2ba7427 100644
--- a/drivers/mmc/host/sdhci-s3c.c
/* we will have to manufacture ethernet headers, prepare template */
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
-index ed384fe..9e3f4f4 100644
+index 0247973..088193a 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
-@@ -2617,7 +2617,7 @@ nla_put_failure:
+@@ -2615,7 +2615,7 @@ nla_put_failure:
return -EMSGSIZE;
}
data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
-index cde9c16..e485cfe 100644
+index f53ef83..5e34bcb 100644
--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
-@@ -1368,7 +1368,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
+@@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
char buf[8];
u32 reset_flag;
memset(buf, 0, sizeof(buf));
-@@ -1389,7 +1389,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
+@@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
{
struct iwl_trans *trans = file->private_data;
char buf[8];
uint32_t default_time2wait; /* Default Min time between
* relogins (+aens) */
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
-index a28d5e6..000a8af 100644
+index cf174a4..128a420 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
-@@ -3308,12 +3308,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
+@@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
*/
if (!iscsi_is_session_online(cls_sess)) {
/* Reset retry relogin timer */
ddb_entry->default_time2wait + 4));
set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
atomic_set(&ddb_entry->retry_relogin_timer,
-@@ -5455,7 +5455,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
+@@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
atomic_set(&ddb_entry->relogin_timer, 0);
ret = -EPERM;
goto reterr;
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
-index f7beb6e..8c0bbd0 100644
+index a673e5b..36e5d32 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -25,6 +25,7 @@
wake_up(&usb_kill_urb_queue);
usb_put_urb(urb);
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
-index bd9dc35..c04ae2f 100644
+index 07e6654..6420edf 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -27,6 +27,7 @@
#include <asm/uaccess.h>
#include <asm/byteorder.h>
-@@ -4463,6 +4464,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
+@@ -4442,6 +4443,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
goto done;
return;
}
spin_lock_init(&delayed_root->lock);
init_waitqueue_head(&delayed_root->wait);
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
-index 21da576..3551e09 100644
+index 9f831bb..14afde5 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
-@@ -3451,9 +3451,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
+@@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
for (i = 0; i < num_types; i++) {
struct btrfs_space_info *tmp;
info = NULL;
rcu_read_lock();
list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
-@@ -3475,10 +3478,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
+@@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
memcpy(dest, &space, sizeof(space));
dest++;
space_args.total_spaces++;
return 0;
while (nr) {
diff --git a/fs/dcache.c b/fs/dcache.c
-index cb4a106..b75581f 100644
+index fdbe230..ba17c1f 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
if (!dname) {
kmem_cache_free(dentry_cache, dentry);
return NULL;
-@@ -3429,7 +3429,8 @@ void __init vfs_caches_init(unsigned long mempages)
+@@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
mempages -= reserve;
names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
spin_lock(&inode->i_lock);
diff --git a/fs/mount.h b/fs/mount.h
-index d64c594..6c283db 100644
+index a17458c..e69fb5b 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -11,7 +11,7 @@ struct mnt_namespace {
kfree(s);
diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
new file mode 100644
-index 0000000..c2c7f17
+index 0000000..e98584b
--- /dev/null
+++ b/grsecurity/Kconfig
-@@ -0,0 +1,1146 @@
+@@ -0,0 +1,1147 @@
+#
+# grecurity configuration
+#
+ bool "Randomize layout of sensitive kernel structures"
+ default y if GRKERNSEC_CONFIG_AUTO
+ select GRKERNSEC_HIDESYM
++ select MODVERSIONS if MODULES
+ help
+ If you say Y here, the layouts of a number of sensitive kernel
+ structures (task, fs, cred, etc) and all structures composed entirely
+ Volatility against the system (unless the kernel source tree isn't
+ cleaned after kernel installation).
+
-+ The seed used for compilation is located at tools/gcc/randstruct.seed.
++ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
+ It remains after a make clean to allow for external modules to be compiled
+ with the existing seed and will be removed by a make mrproper or
+ make distclean.
+endmenu
diff --git a/grsecurity/Makefile b/grsecurity/Makefile
new file mode 100644
-index 0000000..d1344d2
+index 0000000..5307c8a
--- /dev/null
+++ b/grsecurity/Makefile
-@@ -0,0 +1,43 @@
-+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
-+# during 2001-2009 it has been completely redesigned by Brad Spengler
-+# into an RBAC system
+@@ -0,0 +1,54 @@
++# grsecurity – access control and security hardening for Linux
++# All code in this directory and various hooks located throughout the Linux kernel are
++# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
++# http://www.grsecurity.net spender@grsecurity.net
+#
-+# All code in this directory and various hooks inserted throughout the kernel
-+# are copyright Brad Spengler - Open Source Security, Inc., and released
-+# under the GPL v2
++# This program is free software; you can redistribute it and/or
++# modify it under the terms of the GNU General Public License version 2
++# as published by the Free Software Foundation.
++#
++# This program is distributed in the hope that it will be useful,
++# but WITHOUT ANY WARRANTY; without even the implied warranty of
++# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
++# GNU General Public License for more details.
++#
++# You should have received a copy of the GNU General Public License
++# along with this program; if not, write to the Free Software
++# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+KBUILD_CFLAGS += -Werror
+
+ @-chmod -f 500 /lib64/modules
+ @-chmod -f 500 /lib32/modules
+ @-chmod -f 700 .
++ @-chmod -f 700 $(objtree)
+ @echo ' grsec: protected kernel image paths'
+endif
diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
new file mode 100644
-index 0000000..7232a45
+index 0000000..19a5b7c
--- /dev/null
+++ b/grsecurity/gracl.c
-@@ -0,0 +1,2677 @@
+@@ -0,0 +1,2678 @@
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/sched.h>
+void
+gr_acl_handle_psacct(struct task_struct *task, const long code)
+{
-+ unsigned long runtime;
-+ unsigned long cputime;
++ unsigned long runtime, cputime;
++ cputime_t utime, stime;
+ unsigned int wday, cday;
+ __u8 whr, chr;
+ __u8 wmin, cmin;
+
+ do_posix_clock_monotonic_gettime(&timeval);
+ runtime = timeval.tv_sec - task->start_time.tv_sec;
-+ wday = runtime / (3600 * 24);
-+ runtime -= wday * (3600 * 24);
-+ whr = runtime / 3600;
-+ runtime -= whr * 3600;
++ wday = runtime / (60 * 60 * 24);
++ runtime -= wday * (60 * 60 * 24);
++ whr = runtime / (60 * 60);
++ runtime -= whr * (60 * 60);
+ wmin = runtime / 60;
+ runtime -= wmin * 60;
+ wsec = runtime;
+
-+ cputime = (task->utime + task->stime) / HZ;
-+ cday = cputime / (3600 * 24);
-+ cputime -= cday * (3600 * 24);
-+ chr = cputime / 3600;
-+ cputime -= chr * 3600;
++ task_cputime(task, &utime, &stime);
++ cputime = cputime_to_secs(utime + stime);
++ cday = cputime / (60 * 60 * 24);
++ cputime -= cday * (60 * 60 * 24);
++ chr = cputime / (60 * 60);
++ cputime -= chr * (60 * 60);
+ cmin = cputime / 60;
+ cputime -= cmin * 60;
+ csec = cputime;
struct crypto_instance {
struct crypto_alg alg;
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
-index 1d4a920..53a3229 100644
+index 1d4a920..da65658 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -66,6 +66,7 @@
/**
* Creates a driver or general drm_ioctl_desc array entry for the given
-@@ -1013,7 +1016,7 @@ struct drm_info_list {
+@@ -1013,7 +1016,8 @@ struct drm_info_list {
int (*show)(struct seq_file*, void*); /** show callback */
u32 driver_features; /**< Required driver features for this entry */
void *data;
-};
+} __do_const;
++typedef struct drm_info_list __no_const drm_info_list_no_const;
/**
* debugfs node structure. This structure represents a debugfs file.
-@@ -1097,7 +1100,7 @@ struct drm_device {
+@@ -1097,7 +1101,7 @@ struct drm_device {
/** \name Usage Counters */
/*@{ */
/**
* struct ttm_mem_global - Global memory accounting structure.
+diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
+index d1f61bf..2239439 100644
+--- a/include/drm/ttm/ttm_page_alloc.h
++++ b/include/drm/ttm/ttm_page_alloc.h
+@@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
+ */
+ extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
+
++struct device;
+ extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
+ extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
+
diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
index 4b840e8..155d235 100644
--- a/include/keys/asymmetric-subtype.h
int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
diff --git a/include/linux/libata.h b/include/linux/libata.h
-index 9b50337..712d748 100644
+index bec6dbe..2873d64 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
-@@ -973,7 +973,7 @@ struct ata_port_operations {
+@@ -975,7 +975,7 @@ struct ata_port_operations {
* fields must be pointers.
*/
const struct ata_port_operations *inherits;
#ifdef CONFIG_UTS_NS
diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
-index 6f8fbcf..e2a0e61 100644
+index 6f8fbcf..4efc177 100644
--- a/include/linux/vermagic.h
+++ b/include/linux/vermagic.h
-@@ -25,9 +25,41 @@
+@@ -25,9 +25,42 @@
#define MODULE_ARCH_VERMAGIC ""
#endif
+#endif
+
+#ifdef RANDSTRUCT_PLUGIN
++#include <generated/randomize_layout_hash.h>
+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
+#else
+#define MODULE_RANDSTRUCT_PLUGIN
default:
diff --git a/kernel/module.c b/kernel/module.c
-index f5a3b1e..1f5578b 100644
+index f5a3b1e..97ebb15 100644
--- a/kernel/module.c
+++ b/kernel/module.c
@@ -61,6 +61,7 @@
}
static struct module_attribute modinfo_initsize =
-@@ -1286,7 +1288,7 @@ resolve_symbol_wait(struct module *mod,
+@@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
+ goto bad_version;
+ }
+
++#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
++ /*
++ * avoid potentially printing jibberish on attempted load
++ * of a module randomized with a different seed
++ */
++ pr_warn("no symbol version for %s\n", symname);
++#else
+ pr_warn("%s: no symbol version for %s\n", mod->name, symname);
++#endif
+ return 0;
+
+ bad_version:
++#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
++ /*
++ * avoid potentially printing jibberish on attempted load
++ * of a module randomized with a different seed
++ */
++ printk("attempted module disagrees about version of symbol %s\n",
++ symname);
++#else
+ printk("%s: disagrees about version of symbol %s\n",
+ mod->name, symname);
++#endif
+ return 0;
+ }
+
+@@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
*/
#ifdef CONFIG_SYSFS
static inline bool sect_empty(const Elf_Shdr *sect)
{
return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
-@@ -1426,7 +1428,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
+@@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
{
unsigned int notes, loaded, i;
struct module_notes_attrs *notes_attrs;
/* failed to create section attributes, so can't create notes */
if (!mod->sect_attrs)
-@@ -1538,7 +1540,7 @@ static void del_usage_links(struct module *mod)
+@@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
static int module_add_modinfo_attrs(struct module *mod)
{
struct module_attribute *attr;
int error = 0;
int i;
-@@ -1759,21 +1761,21 @@ static void set_section_ro_nx(void *base,
+@@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
static void unset_module_core_ro_nx(struct module *mod)
{
set_memory_rw);
}
-@@ -1786,14 +1788,14 @@ void set_all_modules_text_rw(void)
+@@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
set_memory_rw);
}
}
-@@ -1809,14 +1811,14 @@ void set_all_modules_text_ro(void)
+@@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
list_for_each_entry_rcu(mod, &modules, list) {
if (mod->state == MODULE_STATE_UNFORMED)
continue;
set_memory_ro);
}
}
-@@ -1867,16 +1869,19 @@ static void free_module(struct module *mod)
+@@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
/* This may be NULL, but that's OK */
unset_module_init_ro_nx(mod);
#ifdef CONFIG_MPU
update_protections(current->mm);
-@@ -1945,9 +1950,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
+@@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
int ret = 0;
const struct kernel_symbol *ksym;
switch (sym[i].st_shndx) {
case SHN_COMMON:
/* We compiled with -fno-common. These are not
-@@ -1968,7 +1995,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
+@@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
ksym = resolve_symbol_wait(mod, info, name);
/* Ok if resolved. */
if (ksym && !IS_ERR(ksym)) {
break;
}
-@@ -1987,11 +2016,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
+@@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
secbase = (unsigned long)mod_percpu(mod);
else
secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
return ret;
}
-@@ -2075,22 +2113,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
+@@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
|| s->sh_entsize != ~0UL
|| strstarts(sname, ".init"))
continue;
}
pr_debug("Init section allocation order:\n");
-@@ -2104,23 +2132,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
+@@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
|| s->sh_entsize != ~0UL
|| !strstarts(sname, ".init"))
continue;
}
}
-@@ -2293,7 +2311,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
+@@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
/* Put symbol section at end of init part of module. */
symsect->sh_flags |= SHF_ALLOC;
info->index.sym) | INIT_OFFSET_MASK;
pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
-@@ -2310,13 +2328,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
+@@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
}
/* Append room for core symbols at end of core part. */
info->index.str) | INIT_OFFSET_MASK;
pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
}
-@@ -2334,12 +2352,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
+@@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
/* Make sure we get permanent strtab: don't use info->strtab. */
mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
src = mod->symtab;
for (ndst = i = 0; i < mod->num_symtab; i++) {
if (i == 0 ||
-@@ -2351,6 +2371,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
+@@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
}
}
mod->core_num_syms = ndst;
}
#else
static inline void layout_symtab(struct module *mod, struct load_info *info)
-@@ -2384,17 +2406,33 @@ void * __weak module_alloc(unsigned long size)
+@@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
return vmalloc_exec(size);
}
mutex_unlock(&module_mutex);
}
return ret;
-@@ -2667,8 +2705,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
+@@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
+ mod = (void *)info->sechdrs[info->index.mod].sh_addr;
+
+ if (info->index.sym == 0) {
++#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
++ /*
++ * avoid potentially printing jibberish on attempted load
++ * of a module randomized with a different seed
++ */
++ pr_warn("module has no symbols (stripped?)\n");
++#else
+ pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
++#endif
+ return ERR_PTR(-ENOEXEC);
+ }
+
+@@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
static int check_modinfo(struct module *mod, struct load_info *info, int flags)
{
const char *modmagic = get_modinfo(info, "vermagic");
if (flags & MODULE_INIT_IGNORE_VERMAGIC)
modmagic = NULL;
-@@ -2693,7 +2737,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
+@@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
}
/* Set up license info based on the info section */
return 0;
}
-@@ -2787,7 +2831,7 @@ static int move_module(struct module *mod, struct load_info *info)
+@@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
void *ptr;
/* Do the allocs. */
/*
* The pointer to this block is stored in the module structure
* which is inside the block. Just mark it as not being a
-@@ -2797,11 +2841,11 @@ static int move_module(struct module *mod, struct load_info *info)
+@@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
if (!ptr)
return -ENOMEM;
/*
* The pointer to this block is stored in the module structure
* which is inside the block. This block doesn't need to be
-@@ -2810,13 +2854,45 @@ static int move_module(struct module *mod, struct load_info *info)
+@@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
*/
kmemleak_ignore(ptr);
if (!ptr) {
/* Transfer each section which specifies SHF_ALLOC */
pr_debug("final section addresses:\n");
-@@ -2827,16 +2903,45 @@ static int move_module(struct module *mod, struct load_info *info)
+@@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
if (!(shdr->sh_flags & SHF_ALLOC))
continue;
pr_debug("\t0x%lx %s\n",
(long)shdr->sh_addr, info->secstrings + shdr->sh_name);
}
-@@ -2893,12 +2998,12 @@ static void flush_module_icache(const struct module *mod)
+@@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
* Do it before processing of module parameters, so the module
* can provide parameter accessor functions of its own.
*/
set_fs(old_fs);
}
-@@ -2955,8 +3060,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
+@@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
static void module_deallocate(struct module *mod, struct load_info *info)
{
percpu_modfree(mod);
}
int __weak module_finalize(const Elf_Ehdr *hdr,
-@@ -2969,7 +3076,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
+@@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
static int post_relocation(struct module *mod, const struct load_info *info)
{
/* Sort exception table now relocations are done. */
/* Copy relocated percpu area over. */
percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
-@@ -3023,16 +3132,16 @@ static int do_init_module(struct module *mod)
+@@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
MODULE_STATE_COMING, mod);
/* Set RO and NX regions for core */
do_mod_ctors(mod);
/* Start the module */
-@@ -3093,11 +3202,12 @@ static int do_init_module(struct module *mod)
+@@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
mod->strtab = mod->core_strtab;
#endif
unset_module_init_ro_nx(mod);
mutex_unlock(&module_mutex);
wake_up_all(&module_wq);
-@@ -3240,9 +3350,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
+@@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
if (err)
goto free_unload;
/* Fix up syms, so that st_value is a pointer to location. */
err = simplify_symbols(mod, info);
if (err < 0)
-@@ -3258,13 +3397,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
+@@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
flush_module_icache(mod);
dynamic_debug_setup(info->debug, info->num_debug);
/* Finally it's fully formed, ready to start executing. */
-@@ -3299,11 +3431,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
+@@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
ddebug_cleanup:
dynamic_debug_remove(info->debug);
synchronize_sched();
free_unload:
module_unload_free(mod);
unlink_mod:
-@@ -3386,10 +3517,16 @@ static const char *get_ksymbol(struct module *mod,
+@@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
unsigned long nextval;
/* At worse, next value is at end of module */
/* Scan for closest preceding symbol, and next symbol. (ELF
starts real symbols at 1). */
-@@ -3640,7 +3777,7 @@ static int m_show(struct seq_file *m, void *p)
+@@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
return 0;
seq_printf(m, "%s %u",
print_unload_info(m, mod);
/* Informative for users. */
-@@ -3649,7 +3786,7 @@ static int m_show(struct seq_file *m, void *p)
+@@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
mod->state == MODULE_STATE_COMING ? "Loading":
"Live");
/* Used by oprofile and other similar tools. */
/* Taints info */
if (mod->taints)
-@@ -3685,7 +3822,17 @@ static const struct file_operations proc_modules_operations = {
+@@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
static int __init proc_modules_init(void)
{
return 0;
}
module_init(proc_modules_init);
-@@ -3746,14 +3893,14 @@ struct module *__module_address(unsigned long addr)
+@@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
{
struct module *mod;
return mod;
}
return NULL;
-@@ -3788,11 +3935,20 @@ bool is_module_text_address(unsigned long addr)
+@@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
*/
struct module *__module_text_address(unsigned long addr)
{
mm = get_task_mm(tsk);
if (!mm)
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
-index 0cd2c4d..9558c83 100644
+index e1bd997..055f496 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
switch (ss->ss_family) {
diff --git a/net/compat.c b/net/compat.c
-index dd32e34..0529c9c 100644
+index f50161f..94fa415 100644
--- a/net/compat.c
+++ b/net/compat.c
@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
struct group_filter __user *kgf;
int __user *koptlen;
u32 interface, fmode, numsrc;
-@@ -783,7 +783,7 @@ asmlinkage long compat_sys_recvmmsg(int fd, struct compat_mmsghdr __user *mmsg,
- if (COMPAT_USE_64BIT_TIME)
- return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
- flags | MSG_CMSG_COMPAT,
-- (struct timespec *) timeout);
-+ (struct timespec __force_kernel *) timeout);
-
- if (timeout == NULL)
- return __sys_recvmmsg(fd, (struct mmsghdr __user *)mmsg, vlen,
-@@ -808,7 +808,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
+@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
if (call < SYS_SOCKET || call > SYS_SENDMMSG)
return -EINVAL;
#endif
if (dflt != &ipv4_devconf_dflt)
diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
-index d846304..d0622bb 100644
+index c7539e2..b455e51 100644
--- a/net/ipv4/fib_frontend.c
+++ b/net/ipv4/fib_frontend.c
@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
if (ifa->ifa_dev->ifa_list == NULL) {
/* Last address was deleted from this interface.
* Disable IP.
-@@ -1056,7 +1056,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
+@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
#ifdef CONFIG_IP_ROUTE_MULTIPATH
fib_sync_up(dev);
#endif
return -ENOMEM;
}
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
-index e560ef3..218c5c5 100644
+index d306360..1c1a1f1 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
+ [[ "$plugincc" =~ "$1" ]] && echo "$1"
+ [[ "$plugincc" =~ "$2" ]] && echo "$2"
+fi
-diff --git a/scripts/gen-random-seed.sh b/scripts/gen-random-seed.sh
-new file mode 100644
-index 0000000..17b3162
---- /dev/null
-+++ b/scripts/gen-random-seed.sh
-@@ -0,0 +1,8 @@
-+#!/bin/sh
-+
-+if [ ! -f 'tools/gcc/randstruct.seed' ]; then
-+ SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
-+ echo "$SEED" > tools/gcc/randstruct.seed
-+fi
-+cat tools/gcc/randstruct.seed | sha256sum | cut -d" " -f1 | tr -d "\n" > tools/gcc/randstruct.hashed_seed
-+cat tools/gcc/randstruct.seed
diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
index 5de5660..d3deb89 100644
--- a/scripts/headers_install.sh
unsigned int secindex_strings;
diff --git a/security/Kconfig b/security/Kconfig
-index e9c6ac7..9551ea7 100644
+index e9c6ac7..0ebde711 100644
--- a/security/Kconfig
+++ b/security/Kconfig
-@@ -4,6 +4,958 @@
+@@ -4,6 +4,959 @@
menu "Security options"
+ select PROC_FS
+ select STOP_MACHINE
+ select TTY
++ select DEBUG_KERNEL
+ select DEBUG_LIST
+ help
+ If you say Y here, you will be able to configure many features
source security/keys/Kconfig
config SECURITY_DMESG_RESTRICT
-@@ -103,7 +1055,7 @@ config INTEL_TXT
+@@ -103,7 +1056,7 @@ config INTEL_TXT
config LSM_MMAP_MIN_ADDR
int "Low address space for LSM to protect from user allocation"
depends on SECURITY && SECURITY_SELINUX
rtnl_lock();
for_each_net(net)
rt_genid_bump_all(net);
+diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
+index d106733..539aadd 100644
+--- a/security/selinux/ss/services.c
++++ b/security/selinux/ss/services.c
+@@ -1232,6 +1232,10 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
+ struct context context;
+ int rc = 0;
+
++ /* An empty security context is never valid. */
++ if (!scontext_len)
++ return -EINVAL;
++
+ if (!ss_initialized) {
+ int i;
+
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index b0be893..646bd94 100644
--- a/security/smack/smack_lsm.c
diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
new file mode 100644
-index 0000000..8eb55ca
+index 0000000..4c2c45c
--- /dev/null
+++ b/tools/gcc/.gitignore
-@@ -0,0 +1,3 @@
+@@ -0,0 +1,2 @@
++randomize_layout_seed.h
+size_overflow_hash.h
-+randstruct.seed
-+randstruct.hashed_seed
diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
new file mode 100644
-index 0000000..f8ef8a3
+index 0000000..0d1d9d3
--- /dev/null
+++ b/tools/gcc/Makefile
-@@ -0,0 +1,47 @@
+@@ -0,0 +1,54 @@
+#CC := gcc
+#PLUGIN_SOURCE_FILES := pax_plugin.c
+#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
+randomize_layout_plugin-objs := randomize_layout_plugin.o
+
+$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
++$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
+
+quiet_cmd_build_size_overflow_hash = GENHASH $@
+ cmd_build_size_overflow_hash = \
+$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
+ $(call if_changed,build_size_overflow_hash)
+
-+targets += size_overflow_hash.h
++quiet_cmd_create_randomize_layout_seed = GENSEED $@
++ cmd_create_randomize_layout_seed = \
++ $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
++$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
++ $(call if_changed,create_randomize_layout_seed)
++
++targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
new file mode 100644
index 0000000..5452feea
+}
diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
new file mode 100644
-index 0000000..986f39b
+index 0000000..312d3b6
--- /dev/null
+++ b/tools/gcc/gcc-common.h
-@@ -0,0 +1,267 @@
+@@ -0,0 +1,268 @@
+#ifndef GCC_COMMON_H_INCLUDED
+#define GCC_COMMON_H_INCLUDED
+
+#if BUILDING_GCC_VERSION >= 4009
+#include "tree-ssa-operands.h"
+#include "tree-phinodes.h"
++#include "tree-cfg.h"
+#include "gimple-iterator.h"
+#include "gimple-ssa.h"
+#include "ssa-iterators.h"
+#endif
+
+#endif
+diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
+new file mode 100644
+index 0000000..7514850
+--- /dev/null
++++ b/tools/gcc/gen-random-seed.sh
+@@ -0,0 +1,8 @@
++#!/bin/sh
++
++if [ ! -f "$1" ]; then
++ SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
++ echo "const char *randstruct_seed = \"$SEED\";" > "$1"
++ HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
++ echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
++fi
diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
new file mode 100644
index 0000000..e518932
+}
diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
new file mode 100644
-index 0000000..f04b680
+index 0000000..592b923
--- /dev/null
+++ b/tools/gcc/latent_entropy_plugin.c
@@ -0,0 +1,325 @@
+ }
+
+ register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
-+ register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
++ register_callback(plugin_name, PLUGIN_START_UNIT, &start_unit_callback, NULL);
+ register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
+ register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
+
+}
diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
new file mode 100644
-index 0000000..4aceb10
+index 0000000..fed12bf
--- /dev/null
+++ b/tools/gcc/randomize_layout_plugin.c
-@@ -0,0 +1,746 @@
+@@ -0,0 +1,902 @@
+/*
+ * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
+ * and PaX Team <pageexec@freemail.hu>
+ */
+
+#include "gcc-common.h"
++#include "randomize_layout_seed.h"
+
+#define ORIG_TYPE_NAME(node) \
+ (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
+static int performance_mode;
+
+static struct plugin_info randomize_layout_plugin_info = {
-+ .version = "201401251240",
++ .version = "201402061950",
+ .help = "disable\t\t\tdo not activate plugin\n"
-+ "seed\t\t\tprovide a required 64-byte seed in hex format\n"
+ "performance-mode\tenable cacheline-aware layout randomization\n"
+};
+
+ unsigned long i;
+ tree list;
+ tree variant;
++ expanded_location xloc;
+
+ if (TYPE_FIELDS(type) == NULL_TREE)
+ return 0;
+ lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
+ return 0;
+
++ /* throw out any structs in uapi */
++ xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
++
++ if (strstr(xloc.file, "/uapi/"))
++ error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
++
+ for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
+ gcc_assert(TREE_CODE(field) == FIELD_DECL);
+ newtree[i] = field;
+#endif
+}
+
++static void finish_decl(void *event_data, void *data)
++{
++ tree decl = (tree)event_data;
++ tree type;
++
++ if (decl == NULL_TREE || decl == error_mark_node)
++ return;
++
++ type = TREE_TYPE(decl);
++
++ if (TREE_CODE(decl) != VAR_DECL)
++ return;
++
++ if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
++ return;
++
++ if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
++ return;
++
++ relayout_decl(decl);
++}
++
+static void finish_type(void *event_data, void *data)
+{
+ tree type = (tree)event_data;
+ register_attribute(&randomize_performed_attr);
+}
+
++static void check_bad_casts_in_constructor(tree var, tree init)
++{
++ unsigned HOST_WIDE_INT idx;
++ tree field, val;
++ tree field_type, val_type;
++
++ FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
++ if (TREE_CODE(val) == CONSTRUCTOR) {
++ check_bad_casts_in_constructor(var, val);
++ continue;
++ }
++
++ field_type = TREE_TYPE(field);
++ val_type = TREE_TYPE(val);
++
++ if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
++ continue;
++
++ if (field_type == val_type)
++ continue;
++
++ field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
++ val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
++
++ if (field_type == void_type_node)
++ continue;
++ if (field_type == val_type)
++ continue;
++ if (TREE_CODE(val_type) != RECORD_TYPE)
++ continue;
++
++ if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
++ continue;
++ inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
++ }
++}
++
++/* derived from the constify plugin */
++static void check_global_variables(void *event_data, void *data)
++{
++ struct varpool_node *node;
++ tree init;
++
++ FOR_EACH_VARIABLE(node) {
++ tree var = NODE_DECL(node);
++ init = DECL_INITIAL(var);
++ if (init == NULL_TREE)
++ continue;
++
++ if (TREE_CODE(init) != CONSTRUCTOR)
++ continue;
++
++ check_bad_casts_in_constructor(var, init);
++ }
++}
++
++static bool dominated_by_is_err(const_tree rhs, basic_block bb)
++{
++ basic_block dom;
++ gimple dom_stmt;
++ gimple call_stmt;
++ const_tree dom_lhs;
++ const_tree poss_is_err_cond;
++ const_tree poss_is_err_func;
++ const_tree is_err_arg;
++
++ dom = get_immediate_dominator(CDI_DOMINATORS, bb);
++ if (!dom)
++ return false;
++
++ dom_stmt = last_stmt(dom);
++ if (!dom_stmt)
++ return false;
++
++ if (gimple_code(dom_stmt) != GIMPLE_COND)
++ return false;
++
++ if (gimple_cond_code(dom_stmt) != NE_EXPR)
++ return false;
++
++ if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
++ return false;
++
++ poss_is_err_cond = gimple_cond_lhs(dom_stmt);
++
++ if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
++ return false;
++
++ call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
++
++ if (gimple_code(call_stmt) != GIMPLE_CALL)
++ return false;
++
++ dom_lhs = gimple_get_lhs(call_stmt);
++ poss_is_err_func = gimple_call_fndecl(call_stmt);
++ if (!poss_is_err_func)
++ return false;
++ if (dom_lhs != poss_is_err_cond)
++ return false;
++ if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
++ return false;
++
++ is_err_arg = gimple_call_arg(call_stmt, 0);
++ if (!is_err_arg)
++ return false;
++
++ if (is_err_arg != rhs)
++ return false;
++
++ return true;
++}
++
++static void handle_local_var_initializers(void)
++{
++ tree var;
++ unsigned int i;
++
++ FOR_EACH_LOCAL_DECL(cfun, i, var) {
++ tree init = DECL_INITIAL(var);
++ if (!init)
++ continue;
++ if (TREE_CODE(init) != CONSTRUCTOR)
++ continue;
++ check_bad_casts_in_constructor(var, init);
++ }
++}
++
+/*
+ * iterate over all statements to find "bad" casts:
+ * those where the address of the start of a structure is cast
+{
+ basic_block bb;
+
-+ FOR_ALL_BB(bb) {
++ handle_local_var_initializers();
++
++ FOR_ALL_BB_FN(bb, cfun) {
+ gimple_stmt_iterator gsi;
+
+ for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
+ TREE_CODE(lhs_type) != POINTER_TYPE)
+ continue;
+
-+ ptr_lhs_type = strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type)));
-+ ptr_rhs_type = strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type)));
++ ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
++ ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
+
-+ if (TREE_CODE(ptr_lhs_type) != RECORD_TYPE)
++ if (ptr_rhs_type == void_type_node)
+ continue;
+
-+ if (ptr_rhs_type == void_type_node)
++ if (ptr_lhs_type == void_type_node)
++ continue;
++
++ if (dominated_by_is_err(rhs1, bb))
+ continue;
+
+ if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
+ if (TREE_CODE(op0) != VAR_DECL)
+ continue;
+
-+ op0_type = strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0)));
++ op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
+ if (op0_type == ptr_lhs_type)
+ continue;
+
+ .properties_provided = 0,
+ .properties_destroyed = 0,
+ .todo_flags_start = 0,
-+ .todo_flags_finish = TODO_dump_func | TODO_verify_ssa | TODO_verify_stmts | TODO_remove_unused_locals | TODO_update_ssa_no_phi | TODO_cleanup_cfg | TODO_ggc_collect | TODO_verify_flow
++ .todo_flags_finish = TODO_dump_func
+#if BUILDING_GCC_VERSION < 4009
+ }
+#endif
+ performance_mode = 1;
+ continue;
+ }
-+ if (!strcmp(argv[i].key, "seed")) {
-+ if (!argv[i].value) {
-+ error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
-+ continue;
-+ }
-+ if (strlen(argv[i].value) != 64) {
-+ error(G_("invalid value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
-+ continue;
-+ }
-+ obtained_seed = sscanf(argv[i].value, "%016llx%016llx%016llx%016llx",
-+ &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
-+ continue;
-+ }
+ error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
+ }
+
++ if (strlen(randstruct_seed) != 64) {
++ error(G_("invalid seed value supplied for %s plugin"), plugin_name);
++ return 1;
++ }
++ obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
++ &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
+ if (obtained_seed != 4) {
+ error(G_("Invalid seed supplied for %s plugin"), plugin_name);
+ return 1;
+
+ register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
+ if (enable) {
++ register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
+ register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
+ register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
++ register_callback(plugin_name, PLUGIN_FINISH_DECL, finish_decl, NULL);
+ }
+ register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
+
+nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
new file mode 100644
-index 0000000..94aa56d
+index 0000000..4a637ab
--- /dev/null
+++ b/tools/gcc/size_overflow_plugin.c
@@ -0,0 +1,4040 @@
+
+ register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
+ if (enable) {
-+ register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
++ register_callback(plugin_name, PLUGIN_START_UNIT, &start_unit_callback, NULL);
+ register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
+// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
+ register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);