1
0
Fork 0

ACPICA: Additional error checking for pathname utilities

Add error check after all calls to acpi_ns_get_pathname_length.
Add status return from acpi_ns_build_external_path and check after
all calls.  Add parameter validation to acpi_ut_initialize_buffer.

Reported by and initial patch by Ingo Molnar.
http://lkml.org/lkml/2008/7/21/176

Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Lin Ming <ming.m.lin@intel.com>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
wifi-calibration
Bob Moore 2008-08-04 11:13:01 +08:00 committed by Andi Kleen
parent d3ff268a01
commit 3c7db22a19
5 changed files with 40 additions and 20 deletions

View File

@ -56,13 +56,14 @@ ACPI_MODULE_NAME("nsnames")
* Size - Size of the pathname * Size - Size of the pathname
* *name_buffer - Where to return the pathname * *name_buffer - Where to return the pathname
* *
* RETURN: Places the pathname into the name_buffer, in external format * RETURN: Status
* Places the pathname into the name_buffer, in external format
* (name segments separated by path separators) * (name segments separated by path separators)
* *
* DESCRIPTION: Generate a full pathaname * DESCRIPTION: Generate a full pathaname
* *
******************************************************************************/ ******************************************************************************/
void acpi_status
acpi_ns_build_external_path(struct acpi_namespace_node *node, acpi_ns_build_external_path(struct acpi_namespace_node *node,
acpi_size size, char *name_buffer) acpi_size size, char *name_buffer)
{ {
@ -77,7 +78,7 @@ acpi_ns_build_external_path(struct acpi_namespace_node *node,
if (index < ACPI_NAME_SIZE) { if (index < ACPI_NAME_SIZE) {
name_buffer[0] = AML_ROOT_PREFIX; name_buffer[0] = AML_ROOT_PREFIX;
name_buffer[1] = 0; name_buffer[1] = 0;
return; return (AE_OK);
} }
/* Store terminator byte, then build name backwards */ /* Store terminator byte, then build name backwards */
@ -105,11 +106,13 @@ acpi_ns_build_external_path(struct acpi_namespace_node *node,
if (index != 0) { if (index != 0) {
ACPI_ERROR((AE_INFO, ACPI_ERROR((AE_INFO,
"Could not construct pathname; index=%X, size=%X, Path=%s", "Could not construct external pathname; index=%X, size=%X, Path=%s",
(u32) index, (u32) size, &name_buffer[size])); (u32) index, (u32) size, &name_buffer[size]));
return (AE_BAD_PARAMETER);
} }
return; return (AE_OK);
} }
#ifdef ACPI_DEBUG_OUTPUT #ifdef ACPI_DEBUG_OUTPUT
@ -129,6 +132,7 @@ acpi_ns_build_external_path(struct acpi_namespace_node *node,
char *acpi_ns_get_external_pathname(struct acpi_namespace_node *node) char *acpi_ns_get_external_pathname(struct acpi_namespace_node *node)
{ {
acpi_status status;
char *name_buffer; char *name_buffer;
acpi_size size; acpi_size size;
@ -138,8 +142,7 @@ char *acpi_ns_get_external_pathname(struct acpi_namespace_node *node)
size = acpi_ns_get_pathname_length(node); size = acpi_ns_get_pathname_length(node);
if (!size) { if (!size) {
ACPI_ERROR((AE_INFO, "Invalid node failure")); return (NULL);
return_PTR(NULL);
} }
/* Allocate a buffer to be returned to caller */ /* Allocate a buffer to be returned to caller */
@ -152,7 +155,11 @@ char *acpi_ns_get_external_pathname(struct acpi_namespace_node *node)
/* Build the path in the allocated buffer */ /* Build the path in the allocated buffer */
acpi_ns_build_external_path(node, size, name_buffer); status = acpi_ns_build_external_path(node, size, name_buffer);
if (ACPI_FAILURE(status)) {
return (NULL);
}
return_PTR(name_buffer); return_PTR(name_buffer);
} }
#endif #endif
@ -186,7 +193,7 @@ acpi_size acpi_ns_get_pathname_length(struct acpi_namespace_node *node)
while (next_node && (next_node != acpi_gbl_root_node)) { while (next_node && (next_node != acpi_gbl_root_node)) {
if (ACPI_GET_DESCRIPTOR_TYPE(next_node) != ACPI_DESC_TYPE_NAMED) { if (ACPI_GET_DESCRIPTOR_TYPE(next_node) != ACPI_DESC_TYPE_NAMED) {
ACPI_ERROR((AE_INFO, ACPI_ERROR((AE_INFO,
"Invalid NS Node (%p) while traversing path", "Invalid Namespace Node (%p) while traversing namespace",
next_node)); next_node));
return 0; return 0;
} }
@ -234,8 +241,7 @@ acpi_ns_handle_to_pathname(acpi_handle target_handle,
required_size = acpi_ns_get_pathname_length(node); required_size = acpi_ns_get_pathname_length(node);
if (!required_size) { if (!required_size) {
ACPI_ERROR((AE_INFO, "Invalid node failure")); return_ACPI_STATUS(AE_BAD_PARAMETER);
return_ACPI_STATUS(AE_ERROR);
} }
/* Validate/Allocate/Clear caller buffer */ /* Validate/Allocate/Clear caller buffer */
@ -247,7 +253,11 @@ acpi_ns_handle_to_pathname(acpi_handle target_handle,
/* Build the path in the caller buffer */ /* Build the path in the caller buffer */
acpi_ns_build_external_path(node, required_size, buffer->pointer); status =
acpi_ns_build_external_path(node, required_size, buffer->pointer);
if (ACPI_FAILURE(status)) {
return_ACPI_STATUS(status);
}
ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s [%X]\n", ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%s [%X]\n",
(char *)buffer->pointer, (u32) required_size)); (char *)buffer->pointer, (u32) required_size));

View File

@ -587,6 +587,9 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
} else { } else {
temp_size_needed += temp_size_needed +=
acpi_ns_get_pathname_length((*sub_object_list)->reference.node); acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
if (!temp_size_needed) {
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
} }
} else { } else {
/* /*

View File

@ -242,10 +242,12 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
{ {
acpi_status status = AE_OK; acpi_status status = AE_OK;
if (!required_length) { /* Parameter validation */
WARN_ON(1);
return AE_ERROR; if (!buffer || !required_length) {
return (AE_BAD_PARAMETER);
} }
switch (buffer->length) { switch (buffer->length) {
case ACPI_NO_BUFFER: case ACPI_NO_BUFFER:

View File

@ -425,6 +425,7 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
acpi_size * obj_length) acpi_size * obj_length)
{ {
acpi_size length; acpi_size length;
acpi_size size;
acpi_status status = AE_OK; acpi_status status = AE_OK;
ACPI_FUNCTION_TRACE_PTR(ut_get_simple_object_size, internal_object); ACPI_FUNCTION_TRACE_PTR(ut_get_simple_object_size, internal_object);
@ -484,10 +485,14 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
* Get the actual length of the full pathname to this object. * Get the actual length of the full pathname to this object.
* The reference will be converted to the pathname to the object * The reference will be converted to the pathname to the object
*/ */
length += size =
ACPI_ROUND_UP_TO_NATIVE_WORD acpi_ns_get_pathname_length(internal_object->
(acpi_ns_get_pathname_length reference.node);
(internal_object->reference.node)); if (!size) {
return_ACPI_STATUS(AE_BAD_PARAMETER);
}
length += ACPI_ROUND_UP_TO_NATIVE_WORD(size);
break; break;
default: default:

View File

@ -182,7 +182,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info);
*/ */
u32 acpi_ns_opens_scope(acpi_object_type type); u32 acpi_ns_opens_scope(acpi_object_type type);
void acpi_status
acpi_ns_build_external_path(struct acpi_namespace_node *node, acpi_ns_build_external_path(struct acpi_namespace_node *node,
acpi_size size, char *name_buffer); acpi_size size, char *name_buffer);