device property: set fwnode->secondary to NULL in fwnode_init()
Subsystems (4)
PATCH 1/1 device property: set fwnode->secondary to NULL in fwnode_init()
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL nor IS_ERR() and so may end up being dereferenced (for
example: in dev_to_swnode()). Set fwnode->secondary to NULL on initialization.
--- include/linux/fwnode.h | 1 + 1 file changed, 1 insertion(+)
include/linux/fwnode.h +1 -0
@@ -208,6 +208,7 @@ struct fwnode_operations {static inline void fwnode_init (struct fwnode_handle *fwnode,const struct fwnode_operations *ops) { + fwnode->secondary =NULL ; fwnode->ops = ops;INIT_LIST_HEAD (&fwnode->consumers);INIT_LIST_HEAD (&fwnode->suppliers);
Signature · 1 line
2.47.3
Quoted 7 lines · Bartosz Golaszewski
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using
fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL norIS_ERR()and so may end up being dereferenced (for
example: indev_to_swnode()). Setfwnode->secondaryto NULL on initialization.
Hmm... Are you going to use that outside of fw_devlink?
The patch itself looks good to me, but I'm not sure I understand how it's related to all the work you are doing WRT fwnode core implementation.
FWIW,
But Saravana is the best person to actually tell if this patch makes sense.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Bartosz Golaszewski
reviewerQuoted 12 lines · Andy Shevchenko
Quoted 7 lines · Bartosz Golaszewski
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using
fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL norIS_ERR()and so may end up being dereferenced (for
example: indev_to_swnode()). Setfwnode->secondaryto NULL on initialization.Hmm... Are you going to use that outside of
fw_devlink?
Quoted 8 lines
The patch itself looks good to me, but I'm not sure I understand how it's related to all the work you are doing WRT fwnode core implementation.
FWIW,
Reviewed-by Andy Shevchenko <[email protected]>But Saravana is the best person to actually tell if this patch makes sense.
I just stumbled upon this crash working on adding support for fw_devlink for software nodes. I figured it makes sense fixing it even if we have never hit it before.
Bart
Quoted 9 lines · Bartosz Golaszewski
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using
fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL norIS_ERR()and so may end up being dereferenced (for
example: indev_to_swnode()). Setfwnode->secondaryto NULL on initialization.
Quoted 3 lines
Fixes 01bb86b380a3 ("driver core: Add fwnode_init()")Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 20 lines
--- include/linux/fwnode.h | 1 + 1 file changed, 1 insertion(+)include/linux/fwnode.h +1
-1@@ -208,6 +208,7 @@ struct fwnode_operations {static inline void fwnode_init (struct fwnode_handle *fwnode,const struct fwnode_operations *ops) { + fwnode->secondary =NULL ; fwnode->ops = ops;INIT_LIST_HEAD (&fwnode->consumers);INIT_LIST_HEAD (&fwnode->suppliers); --2.47.3
Quoted 11 lines · Bartosz Golaszewski
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using
fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL norIS_ERR()and so may end up being dereferenced (for
example: indev_to_swnode()). Setfwnode->secondaryto NULL on initialization.Fixes 01bb86b380a3 ("driver core: Add fwnode_init()")Signed-off-by Bartosz Golaszewski <[email protected]>
Signature · 1 line
Sakari Ailus
Danilo Krummrich
maintainerQuoted 5 lines · Bartosz Golaszewski
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using
fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL norIS_ERR().
I see why secondary is generally more prone to this, but if the justification of this change is to not rely on the caller to zero out the memory, then we might just want to initialize all fields.
For instance, if the caller is allowed to not zero-initialize the memory then having flags with a random value isn't correct either; all accessors are atomic bitwise operations that never zero the whole field.
Greg Kroah-Hartman
maintainerQuoted 7 lines · Danilo Krummrich
Quoted 5 lines · Bartosz Golaszewski
If a firmware node is allocated on the stack (for instance: temporary software node whose life-time we control) or on the heap - but using a non-zeroing allocation function - and initialized using
fwnode_init(), its secondary pointer will contain uninitalized memory which likely will be neither NULL norIS_ERR().
Quoted 8 lines
I see why secondary is generally more prone to this, but if the justification of this change is to not rely on the caller to zero out the memory, then we might just want to initialize all fields.
For instance, if the caller is allowed to not zero-initialize the memory then having flags with a random value isn't correct either; all accessors are atomic bitwise operations that never zero the whole field.
Sure, but for now I'll go take this one.
thanks,
greg k-h
Danilo Krummrich
maintainerQuoted 1 line · Greg Kroah-Hartman
Sure, but for now I'll go take this one.
The follow-up commit 7eba000621ff ("device property: initialize the remaining fields of fwnode_handle in fwnode_init()") is already in driver-core-next.
Danilo Krummrich
maintainerQuoted 4 lines · Danilo Krummrich
Quoted 1 line · Greg Kroah-Hartman
Sure, but for now I'll go take this one.
The follow-up commit
7eba000621ff("device property: initialize the remaining fields offwnode_handleinfwnode_init()") is already in driver-core-next.
s/follow-up/v2/
Greg Kroah-Hartman
maintainerQuoted 10 lines · Danilo Krummrich
Quoted 4 lines · Danilo Krummrich
Quoted 1 line · Greg Kroah-Hartman
Sure, but for now I'll go take this one.
The follow-up commit
7eba000621ff("device property: initialize the remaining fields offwnode_handleinfwnode_init()") is already in driver-core-next.s/follow-up/v2/
Ugh, ok, we will have a merge conflict, but at least the bugfix will propagate to stable trees :)
thanks,
greg "digging out from a huge email backlog" k-h
Bartosz Golaszewski
reviewerQuoted 13 lines · Greg Kroah-Hartman
Quoted 10 lines · Danilo Krummrich
Quoted 4 lines · Danilo Krummrich
Quoted 1 line · Greg Kroah-Hartman
Sure, but for now I'll go take this one.
The follow-up commit
7eba000621ff("device property: initialize the remaining fields offwnode_handleinfwnode_init()") is already in driver-core-next.s/follow-up/v2/
Quoted 6 lines
Ugh, ok, we will have a merge conflict, but at least the bugfix will propagate to stable trees :)
thanks,
greg "digging out from a huge email backlog" k-h
There's no need for you to queue this one, the v2 Danilo linked contains this change and some more hardening on top for consistency.
Bart