Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c7db22a authored by Bob Moore's avatar Bob Moore Committed by Andi Kleen
Browse files

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: default avatarBob Moore <robert.moore@intel.com>
Signed-off-by: default avatarLin Ming <ming.m.lin@intel.com>
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
parent d3ff268a
Loading
Loading
Loading
Loading
+22 −12
Original line number Diff line number Diff line
@@ -56,13 +56,14 @@ ACPI_MODULE_NAME("nsnames")
 *              Size            - Size of 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)
 *
 * DESCRIPTION: Generate a full pathaname
 *
 ******************************************************************************/
void
acpi_status
acpi_ns_build_external_path(struct acpi_namespace_node *node,
			    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) {
		name_buffer[0] = AML_ROOT_PREFIX;
		name_buffer[1] = 0;
		return;
		return (AE_OK);
	}

	/* Store terminator byte, then build name backwards */
@@ -105,11 +106,13 @@ acpi_ns_build_external_path(struct acpi_namespace_node *node,

	if (index != 0) {
		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]));

		return (AE_BAD_PARAMETER);
	}

	return;
	return (AE_OK);
}

#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)
{
	acpi_status status;
	char *name_buffer;
	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);
	if (!size) {
		ACPI_ERROR((AE_INFO, "Invalid node failure"));
		return_PTR(NULL);
		return (NULL);
	}

	/* 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 */

	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);
}
#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)) {
		if (ACPI_GET_DESCRIPTOR_TYPE(next_node) != ACPI_DESC_TYPE_NAMED) {
			ACPI_ERROR((AE_INFO,
				    "Invalid NS Node (%p) while traversing path",
				    "Invalid Namespace Node (%p) while traversing namespace",
				    next_node));
			return 0;
		}
@@ -234,8 +241,7 @@ acpi_ns_handle_to_pathname(acpi_handle target_handle,

	required_size = acpi_ns_get_pathname_length(node);
	if (!required_size) {
		ACPI_ERROR((AE_INFO, "Invalid node failure"));
		return_ACPI_STATUS(AE_ERROR);
		return_ACPI_STATUS(AE_BAD_PARAMETER);
	}

	/* 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 */

	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",
			  (char *)buffer->pointer, (u32) required_size));
+3 −0
Original line number Diff line number Diff line
@@ -587,6 +587,9 @@ acpi_rs_get_pci_routing_table_length(union acpi_operand_object *package_object,
			} else {
				temp_size_needed +=
				    acpi_ns_get_pathname_length((*sub_object_list)->reference.node);
				if (!temp_size_needed) {
					return_ACPI_STATUS(AE_BAD_PARAMETER);
				}
			}
		} else {
			/*
+5 −3
Original line number Diff line number Diff line
@@ -242,10 +242,12 @@ acpi_ut_initialize_buffer(struct acpi_buffer * buffer,
{
	acpi_status status = AE_OK;

	if (!required_length) {
		WARN_ON(1);
		return AE_ERROR;
	/* Parameter validation */

	if (!buffer || !required_length) {
		return (AE_BAD_PARAMETER);
	}

	switch (buffer->length) {
	case ACPI_NO_BUFFER:

+9 −4
Original line number Diff line number Diff line
@@ -425,6 +425,7 @@ acpi_ut_get_simple_object_size(union acpi_operand_object *internal_object,
			       acpi_size * obj_length)
{
	acpi_size length;
	acpi_size size;
	acpi_status status = AE_OK;

	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.
			 * The reference will be converted to the pathname to the object
			 */
			length +=
			    ACPI_ROUND_UP_TO_NATIVE_WORD
			    (acpi_ns_get_pathname_length
			     (internal_object->reference.node));
			size =
			    acpi_ns_get_pathname_length(internal_object->
							reference.node);
			if (!size) {
				return_ACPI_STATUS(AE_BAD_PARAMETER);
			}

			length += ACPI_ROUND_UP_TO_NATIVE_WORD(size);
			break;

		default:
+1 −1
Original line number Diff line number Diff line
@@ -182,7 +182,7 @@ acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info);
 */
u32 acpi_ns_opens_scope(acpi_object_type type);

void
acpi_status
acpi_ns_build_external_path(struct acpi_namespace_node *node,
			    acpi_size size, char *name_buffer);