mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-06 10:57:46 +00:00
IB/hfi1: Check eeprom config partition validity
Relying on a trailing magic value is incorrect. There are instances where
this is not present as trailing magic value has a specific purpose which is
not partition validation. Instead use the header magic value which is
present in all variants of the platform configuration and is intended for
validation. This is also used in other locations in the driver.
Fixes: bc5214ee29
(IB/hfi1: Handle missing magic values in config file)
Reviewed-by: Jakub Byczkowski <jakub.byczkowski@intel.com>
Signed-off-by: Jan Sokolowski <jan.sokolowski@intel.com>
Signed-off-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
This commit is contained in:
parent
30e10527bc
commit
753b19afb1
1 changed files with 15 additions and 5 deletions
|
@ -204,7 +204,10 @@ int eprom_init(struct hfi1_devdata *dd)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* magic character sequence that trails an image */
|
/* magic character sequence that begins an image */
|
||||||
|
#define IMAGE_START_MAGIC "APO="
|
||||||
|
|
||||||
|
/* magic character sequence that might trail an image */
|
||||||
#define IMAGE_TRAIL_MAGIC "egamiAPO"
|
#define IMAGE_TRAIL_MAGIC "egamiAPO"
|
||||||
|
|
||||||
/* EPROM file types */
|
/* EPROM file types */
|
||||||
|
@ -250,6 +253,7 @@ static int read_partition_platform_config(struct hfi1_devdata *dd, void **data,
|
||||||
{
|
{
|
||||||
void *buffer;
|
void *buffer;
|
||||||
void *p;
|
void *p;
|
||||||
|
u32 length;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
buffer = kmalloc(P1_SIZE, GFP_KERNEL);
|
buffer = kmalloc(P1_SIZE, GFP_KERNEL);
|
||||||
|
@ -262,15 +266,21 @@ static int read_partition_platform_config(struct hfi1_devdata *dd, void **data,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* scan for image magic that may trail the actual data */
|
/* config partition is valid only if it starts with IMAGE_START_MAGIC */
|
||||||
p = strnstr(buffer, IMAGE_TRAIL_MAGIC, P1_SIZE);
|
if (memcmp(buffer, IMAGE_START_MAGIC, strlen(IMAGE_START_MAGIC))) {
|
||||||
if (!p) {
|
|
||||||
kfree(buffer);
|
kfree(buffer);
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* scan for image magic that may trail the actual data */
|
||||||
|
p = strnstr(buffer, IMAGE_TRAIL_MAGIC, P1_SIZE);
|
||||||
|
if (p)
|
||||||
|
length = p - buffer;
|
||||||
|
else
|
||||||
|
length = P1_SIZE;
|
||||||
|
|
||||||
*data = buffer;
|
*data = buffer;
|
||||||
*size = p - buffer;
|
*size = length;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue