Commit 47b3bc90 authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull x86 fixes from Peter Anvin:
 "Several boot fixes (MacBook, legacy EFI bootloaders), another
  please-don't-brick fix, and some minor stuff."

* 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  x86: Do not try to sync identity map for non-mapped pages
  x86, doc: Be explicit about what the x86 struct boot_params requires
  x86: Don't clear efi_info even if the sentinel hits
  x86, mm: Make sure to find a 2M free block for the first mapped area
  x86: Fix 32-bit *_cpu_data initializers
  efivarfs: return accurate error code in efivarfs_fill_super()
  efivars: efivarfs_valid_name() should handle pstore syntax
  efi: be more paranoid about available space when creating variables
  iommu, x86: Add DMA remap fault reason
  x86, smpboot: Remove unused variable
parents af2841cd cc677088
...@@ -14,13 +14,29 @@ ...@@ -14,13 +14,29 @@
* analysis of kexec-tools; if other broken bootloaders initialize a * analysis of kexec-tools; if other broken bootloaders initialize a
* different set of fields we will need to figure out how to disambiguate. * different set of fields we will need to figure out how to disambiguate.
* *
* Note: efi_info is commonly left uninitialized, but that field has a
* private magic, so it is better to leave it unchanged.
*/ */
static void sanitize_boot_params(struct boot_params *boot_params) static void sanitize_boot_params(struct boot_params *boot_params)
{ {
/*
* IMPORTANT NOTE TO BOOTLOADER AUTHORS: do not simply clear
* this field. The purpose of this field is to guarantee
* compliance with the x86 boot spec located in
* Documentation/x86/boot.txt . That spec says that the
* *whole* structure should be cleared, after which only the
* portion defined by struct setup_header (boot_params->hdr)
* should be copied in.
*
* If you're having an issue because the sentinel is set, you
* need to change the whole structure to be cleared, not this
* (or any other) individual field, or you will soon have
* problems again.
*/
if (boot_params->sentinel) { if (boot_params->sentinel) {
/*fields in boot_params are not valid, clear them */ /* fields in boot_params are left uninitialized, clear them */
memset(&boot_params->olpc_ofw_header, 0, memset(&boot_params->olpc_ofw_header, 0,
(char *)&boot_params->alt_mem_k - (char *)&boot_params->efi_info -
(char *)&boot_params->olpc_ofw_header); (char *)&boot_params->olpc_ofw_header);
memset(&boot_params->kbd_status, 0, memset(&boot_params->kbd_status, 0,
(char *)&boot_params->hdr - (char *)&boot_params->hdr -
......
...@@ -171,9 +171,15 @@ static struct resource bss_resource = { ...@@ -171,9 +171,15 @@ static struct resource bss_resource = {
#ifdef CONFIG_X86_32 #ifdef CONFIG_X86_32
/* cpu data as detected by the assembly code in head.S */ /* cpu data as detected by the assembly code in head.S */
struct cpuinfo_x86 new_cpu_data __cpuinitdata = {0, 0, 0, 0, -1, 1, 0, 0, -1}; struct cpuinfo_x86 new_cpu_data __cpuinitdata = {
.wp_works_ok = -1,
.fdiv_bug = -1,
};
/* common cpu data for all cpus */ /* common cpu data for all cpus */
struct cpuinfo_x86 boot_cpu_data __read_mostly = {0, 0, 0, 0, -1, 1, 0, 0, -1}; struct cpuinfo_x86 boot_cpu_data __read_mostly = {
.wp_works_ok = -1,
.fdiv_bug = -1,
};
EXPORT_SYMBOL(boot_cpu_data); EXPORT_SYMBOL(boot_cpu_data);
unsigned int def_to_bigsmp; unsigned int def_to_bigsmp;
......
...@@ -1365,9 +1365,8 @@ static inline void mwait_play_dead(void) ...@@ -1365,9 +1365,8 @@ static inline void mwait_play_dead(void)
unsigned int eax, ebx, ecx, edx; unsigned int eax, ebx, ecx, edx;
unsigned int highest_cstate = 0; unsigned int highest_cstate = 0;
unsigned int highest_subcstate = 0; unsigned int highest_subcstate = 0;
int i;
void *mwait_ptr; void *mwait_ptr;
struct cpuinfo_x86 *c = __this_cpu_ptr(&cpu_info); int i;
if (!this_cpu_has(X86_FEATURE_MWAIT)) if (!this_cpu_has(X86_FEATURE_MWAIT))
return; return;
......
...@@ -410,9 +410,8 @@ void __init init_mem_mapping(void) ...@@ -410,9 +410,8 @@ void __init init_mem_mapping(void)
/* the ISA range is always mapped regardless of memory holes */ /* the ISA range is always mapped regardless of memory holes */
init_memory_mapping(0, ISA_END_ADDRESS); init_memory_mapping(0, ISA_END_ADDRESS);
/* xen has big range in reserved near end of ram, skip it at first */ /* xen has big range in reserved near end of ram, skip it at first.*/
addr = memblock_find_in_range(ISA_END_ADDRESS, end, PMD_SIZE, addr = memblock_find_in_range(ISA_END_ADDRESS, end, PMD_SIZE, PMD_SIZE);
PAGE_SIZE);
real_end = addr + PMD_SIZE; real_end = addr + PMD_SIZE;
/* step_size need to be small so pgt_buf from BRK could cover it */ /* step_size need to be small so pgt_buf from BRK could cover it */
......
...@@ -563,6 +563,13 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags) ...@@ -563,6 +563,13 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
if (base > __pa(high_memory-1)) if (base > __pa(high_memory-1))
return 0; return 0;
/*
* some areas in the middle of the kernel identity range
* are not mapped, like the PCI space.
*/
if (!page_is_ram(base >> PAGE_SHIFT))
return 0;
id_sz = (__pa(high_memory-1) <= base + size) ? id_sz = (__pa(high_memory-1) <= base + size) ?
__pa(high_memory) - base : __pa(high_memory) - base :
size; size;
......
...@@ -426,6 +426,44 @@ get_var_data(struct efivars *efivars, struct efi_variable *var) ...@@ -426,6 +426,44 @@ get_var_data(struct efivars *efivars, struct efi_variable *var)
return status; return status;
} }
static efi_status_t
check_var_size_locked(struct efivars *efivars, u32 attributes,
unsigned long size)
{
u64 storage_size, remaining_size, max_size;
efi_status_t status;
const struct efivar_operations *fops = efivars->ops;
if (!efivars->ops->query_variable_info)
return EFI_UNSUPPORTED;
status = fops->query_variable_info(attributes, &storage_size,
&remaining_size, &max_size);
if (status != EFI_SUCCESS)
return status;
if (!storage_size || size > remaining_size || size > max_size ||
(remaining_size - size) < (storage_size / 2))
return EFI_OUT_OF_RESOURCES;
return status;
}
static efi_status_t
check_var_size(struct efivars *efivars, u32 attributes, unsigned long size)
{
efi_status_t status;
unsigned long flags;
spin_lock_irqsave(&efivars->lock, flags);
status = check_var_size_locked(efivars, attributes, size);
spin_unlock_irqrestore(&efivars->lock, flags);
return status;
}
static ssize_t static ssize_t
efivar_guid_read(struct efivar_entry *entry, char *buf) efivar_guid_read(struct efivar_entry *entry, char *buf)
{ {
...@@ -547,6 +585,11 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count) ...@@ -547,6 +585,11 @@ efivar_store_raw(struct efivar_entry *entry, const char *buf, size_t count)
} }
spin_lock_irq(&efivars->lock); spin_lock_irq(&efivars->lock);
status = check_var_size_locked(efivars, new_var->Attributes,
new_var->DataSize + utf16_strsize(new_var->VariableName, 1024));
if (status == EFI_SUCCESS || status == EFI_UNSUPPORTED)
status = efivars->ops->set_variable(new_var->VariableName, status = efivars->ops->set_variable(new_var->VariableName,
&new_var->VendorGuid, &new_var->VendorGuid,
new_var->Attributes, new_var->Attributes,
...@@ -702,8 +745,7 @@ static ssize_t efivarfs_file_write(struct file *file, ...@@ -702,8 +745,7 @@ static ssize_t efivarfs_file_write(struct file *file,
u32 attributes; u32 attributes;
struct inode *inode = file->f_mapping->host; struct inode *inode = file->f_mapping->host;
unsigned long datasize = count - sizeof(attributes); unsigned long datasize = count - sizeof(attributes);
unsigned long newdatasize; unsigned long newdatasize, varsize;
u64 storage_size, remaining_size, max_size;
ssize_t bytes = 0; ssize_t bytes = 0;
if (count < sizeof(attributes)) if (count < sizeof(attributes))
...@@ -722,27 +764,17 @@ static ssize_t efivarfs_file_write(struct file *file, ...@@ -722,27 +764,17 @@ static ssize_t efivarfs_file_write(struct file *file,
* amounts of memory. Pick a default size of 64K if * amounts of memory. Pick a default size of 64K if
* QueryVariableInfo() isn't supported by the firmware. * QueryVariableInfo() isn't supported by the firmware.
*/ */
spin_lock_irq(&efivars->lock);
if (!efivars->ops->query_variable_info) varsize = datasize + utf16_strsize(var->var.VariableName, 1024);
status = EFI_UNSUPPORTED; status = check_var_size(efivars, attributes, varsize);
else {
const struct efivar_operations *fops = efivars->ops;
status = fops->query_variable_info(attributes, &storage_size,
&remaining_size, &max_size);
}
spin_unlock_irq(&efivars->lock);
if (status != EFI_SUCCESS) { if (status != EFI_SUCCESS) {
if (status != EFI_UNSUPPORTED) if (status != EFI_UNSUPPORTED)
return efi_status_to_err(status); return efi_status_to_err(status);
remaining_size = 65536; if (datasize > 65536)
}
if (datasize > remaining_size)
return -ENOSPC; return -ENOSPC;
}
data = kmalloc(datasize, GFP_KERNEL); data = kmalloc(datasize, GFP_KERNEL);
if (!data) if (!data)
...@@ -765,6 +797,19 @@ static ssize_t efivarfs_file_write(struct file *file, ...@@ -765,6 +797,19 @@ static ssize_t efivarfs_file_write(struct file *file,
*/ */
spin_lock_irq(&efivars->lock); spin_lock_irq(&efivars->lock);
/*
* Ensure that the available space hasn't shrunk below the safe level
*/
status = check_var_size_locked(efivars, attributes, varsize);
if (status != EFI_SUCCESS && status != EFI_UNSUPPORTED) {
spin_unlock_irq(&efivars->lock);
kfree(data);
return efi_status_to_err(status);
}
status = efivars->ops->set_variable(var->var.VariableName, status = efivars->ops->set_variable(var->var.VariableName,
&var->var.VendorGuid, &var->var.VendorGuid,
attributes, datasize, attributes, datasize,
...@@ -929,8 +974,8 @@ static bool efivarfs_valid_name(const char *str, int len) ...@@ -929,8 +974,8 @@ static bool efivarfs_valid_name(const char *str, int len)
if (len < GUID_LEN + 2) if (len < GUID_LEN + 2)
return false; return false;
/* GUID should be right after the first '-' */ /* GUID must be preceded by a '-' */
if (s - 1 != strchr(str, '-')) if (*(s - 1) != '-')
return false; return false;
/* /*
...@@ -1118,15 +1163,22 @@ static struct dentry_operations efivarfs_d_ops = { ...@@ -1118,15 +1163,22 @@ static struct dentry_operations efivarfs_d_ops = {
static struct dentry *efivarfs_alloc_dentry(struct dentry *parent, char *name) static struct dentry *efivarfs_alloc_dentry(struct dentry *parent, char *name)
{ {
struct dentry *d;
struct qstr q; struct qstr q;
int err;
q.name = name; q.name = name;
q.len = strlen(name); q.len = strlen(name);
if (efivarfs_d_hash(NULL, NULL, &q)) err = efivarfs_d_hash(NULL, NULL, &q);
return NULL; if (err)
return ERR_PTR(err);
return d_alloc(parent, &q); d = d_alloc(parent, &q);
if (d)
return d;
return ERR_PTR(-ENOMEM);
} }
static int efivarfs_fill_super(struct super_block *sb, void *data, int silent) static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
...@@ -1136,6 +1188,7 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1136,6 +1188,7 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
struct efivar_entry *entry, *n; struct efivar_entry *entry, *n;
struct efivars *efivars = &__efivars; struct efivars *efivars = &__efivars;
char *name; char *name;
int err = -ENOMEM;
efivarfs_sb = sb; efivarfs_sb = sb;
...@@ -1186,8 +1239,10 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1186,8 +1239,10 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
goto fail_name; goto fail_name;
dentry = efivarfs_alloc_dentry(root, name); dentry = efivarfs_alloc_dentry(root, name);
if (!dentry) if (IS_ERR(dentry)) {
err = PTR_ERR(dentry);
goto fail_inode; goto fail_inode;
}
/* copied by the above to local storage in the dentry. */ /* copied by the above to local storage in the dentry. */
kfree(name); kfree(name);
...@@ -1214,7 +1269,7 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent) ...@@ -1214,7 +1269,7 @@ static int efivarfs_fill_super(struct super_block *sb, void *data, int silent)
fail_name: fail_name:
kfree(name); kfree(name);
fail: fail:
return -ENOMEM; return err;
} }
static struct dentry *efivarfs_mount(struct file_system_type *fs_type, static struct dentry *efivarfs_mount(struct file_system_type *fs_type,
...@@ -1345,7 +1400,6 @@ static int efi_pstore_write(enum pstore_type_id type, ...@@ -1345,7 +1400,6 @@ static int efi_pstore_write(enum pstore_type_id type,
efi_guid_t vendor = LINUX_EFI_CRASH_GUID; efi_guid_t vendor = LINUX_EFI_CRASH_GUID;
struct efivars *efivars = psi->data; struct efivars *efivars = psi->data;
int i, ret = 0; int i, ret = 0;
u64 storage_space, remaining_space, max_variable_size;
efi_status_t status = EFI_NOT_FOUND; efi_status_t status = EFI_NOT_FOUND;
unsigned long flags; unsigned long flags;
...@@ -1365,11 +1419,11 @@ static int efi_pstore_write(enum pstore_type_id type, ...@@ -1365,11 +1419,11 @@ static int efi_pstore_write(enum pstore_type_id type,
* size: a size of logging data * size: a size of logging data
* DUMP_NAME_LEN * 2: a maximum size of variable name * DUMP_NAME_LEN * 2: a maximum size of variable name
*/ */
status = efivars->ops->query_variable_info(PSTORE_EFI_ATTRIBUTES,
&storage_space, status = check_var_size_locked(efivars, PSTORE_EFI_ATTRIBUTES,
&remaining_space, size + DUMP_NAME_LEN * 2);
&max_variable_size);
if (status || remaining_space < size + DUMP_NAME_LEN * 2) { if (status) {
spin_unlock_irqrestore(&efivars->lock, flags); spin_unlock_irqrestore(&efivars->lock, flags);
*id = part; *id = part;
return -ENOSPC; return -ENOSPC;
...@@ -1544,6 +1598,14 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj, ...@@ -1544,6 +1598,14 @@ static ssize_t efivar_create(struct file *filp, struct kobject *kobj,
return -EINVAL; return -EINVAL;
} }
status = check_var_size_locked(efivars, new_var->Attributes,
new_var->DataSize + utf16_strsize(new_var->VariableName, 1024));
if (status && status != EFI_UNSUPPORTED) {
spin_unlock_irq(&efivars->lock);
return efi_status_to_err(status);
}
/* now *really* create the variable via EFI */ /* now *really* create the variable via EFI */
status = efivars->ops->set_variable(new_var->VariableName, status = efivars->ops->set_variable(new_var->VariableName,
&new_var->VendorGuid, &new_var->VendorGuid,
......
...@@ -1083,6 +1083,7 @@ static const char *dma_remap_fault_reasons[] = ...@@ -1083,6 +1083,7 @@ static const char *dma_remap_fault_reasons[] =
"non-zero reserved fields in RTP", "non-zero reserved fields in RTP",
"non-zero reserved fields in CTP", "non-zero reserved fields in CTP",
"non-zero reserved fields in PTE", "non-zero reserved fields in PTE",
"PCE for translation request specifies blocking",
}; };
static const char *irq_remap_fault_reasons[] = static const char *irq_remap_fault_reasons[] =
......
...@@ -125,6 +125,63 @@ test_open_unlink() ...@@ -125,6 +125,63 @@ test_open_unlink()
./open-unlink $file ./open-unlink $file
} }
# test that we can create a range of filenames
test_valid_filenames()
{
local attrs='\x07\x00\x00\x00'
local ret=0
local file_list="abc dump-type0-11-1-1362436005 1234 -"
for f in $file_list; do
local file=$efivarfs_mount/$f-$test_guid
printf "$attrs\x00" > $file
if [ ! -e $file ]; then
echo "$file could not be created" >&2
ret=1
else
rm $file
fi
done
exit $ret
}
test_invalid_filenames()
{
local attrs='\x07\x00\x00\x00'
local ret=0
local file_list="
-1234-1234-1234-123456789abc
foo
foo-bar
-foo-
foo-barbazba-foob-foob-foob-foobarbazfoo
foo-------------------------------------
-12345678-1234-1234-1234-123456789abc
a-12345678=1234-1234-1234-123456789abc
a-12345678-1234=1234-1234-123456789abc
a-12345678-1234-1234=1234-123456789abc
a-12345678-1234-1234-1234=123456789abc
1112345678-1234-1234-1234-123456789abc"
for f in $file_list; do
local file=$efivarfs_mount/$f
printf "$attrs\x00" 2>/dev/null > $file
if [ -e $file ]; then
echo "Creating $file should have failed" >&2
rm $file
ret=1
fi
done
exit $ret
}
check_prereqs check_prereqs
rc=0 rc=0
...@@ -135,5 +192,7 @@ run_test test_create_read ...@@ -135,5 +192,7 @@ run_test test_create_read
run_test test_delete run_test test_delete
run_test test_zero_size_delete run_test test_zero_size_delete
run_test test_open_unlink run_test test_open_unlink
run_test test_valid_filenames
run_test test_invalid_filenames
exit $rc exit $rc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment