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

Commit 0224a4a3 authored by Heikki Krogerus's avatar Heikki Krogerus Committed by Rafael J. Wysocki
Browse files

device property: Avoid potential dereferences of invalid pointers



Since fwnode may hold ERR_PTR(-ENODEV) or it may be NULL,
the fwnode type checks is_of_node(), is_acpi_node() and is
is_pset_node() need to consider it. Using IS_ERR_OR_NULL()
to check it.

Fixes: 0d67e0fa (device property: fix for a case of use-after-free)
Reported-by: default avatarDan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
[ rjw: Subject & changelog ]
Signed-off-by: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 02da2d72
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@

static inline bool is_pset_node(struct fwnode_handle *fwnode)
{
	return fwnode && fwnode->type == FWNODE_PDATA;
	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_PDATA;
}

static inline struct property_set *to_pset_node(struct fwnode_handle *fwnode)
+2 −2
Original line number Diff line number Diff line
@@ -394,13 +394,13 @@ struct acpi_data_node {

static inline bool is_acpi_node(struct fwnode_handle *fwnode)
{
	return fwnode && (fwnode->type == FWNODE_ACPI
	return !IS_ERR_OR_NULL(fwnode) && (fwnode->type == FWNODE_ACPI
		|| fwnode->type == FWNODE_ACPI_DATA);
}

static inline bool is_acpi_device_node(struct fwnode_handle *fwnode)
{
	return fwnode && fwnode->type == FWNODE_ACPI;
	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_ACPI;
}

static inline struct acpi_device *to_acpi_device_node(struct fwnode_handle *fwnode)
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ void of_core_init(void);

static inline bool is_of_node(struct fwnode_handle *fwnode)
{
	return fwnode && fwnode->type == FWNODE_OF;
	return !IS_ERR_OR_NULL(fwnode) && fwnode->type == FWNODE_OF;
}

static inline struct device_node *to_of_node(struct fwnode_handle *fwnode)