linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] software node: bug fixes
@ 2025-04-10 13:12 Zijun Hu
  2025-04-10 13:12 ` [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node() Zijun Hu
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Zijun Hu @ 2025-04-10 13:12 UTC (permalink / raw)
  To: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
  Cc: Zijun Hu, linux-acpi, linux-kernel, Zijun Hu

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
Zijun Hu (2):
      software node: Add comment for the first ERR_CAST() in fwnode_create_software_node()
      software node: Correct a OOB check in software_node_get_reference_args()

 drivers/base/swnode.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
base-commit: 0af2f6be1b4281385b618cb86ad946eded089ac8
change-id: 20250410-fix_swnode-4986ff1b3534

Best regards,
-- 
Zijun Hu <quic_zijuhu@quicinc.com>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node()
  2025-04-10 13:12 [PATCH 0/2] software node: bug fixes Zijun Hu
@ 2025-04-10 13:12 ` Zijun Hu
  2025-04-14  8:00   ` Andy Shevchenko
  2025-04-10 13:12 ` [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args() Zijun Hu
  2025-04-14  7:23 ` [PATCH 0/2] software node: bug fixes Andy Shevchenko
  2 siblings, 1 reply; 10+ messages in thread
From: Zijun Hu @ 2025-04-10 13:12 UTC (permalink / raw)
  To: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
  Cc: Zijun Hu, linux-acpi, linux-kernel, Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

ERR_CAST() is normally used to cast an error-valued pointer type to
another different type, But the first ERR_CAST() is to cast away the
const in fwnode_create_software_node().

Add comment for this unusual ERR_CAST() usage.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/swnode.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index b1726a3515f6fbe13c2186af1f74479263798e42..67040fff99b02c43999b175c2ba7e6d04322a446 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -933,6 +933,7 @@ fwnode_create_software_node(const struct property_entry *properties,
 	struct software_node *node;
 	struct swnode *p;
 
+	/* Only cast away the const by ERR_CAST() */
 	if (IS_ERR(parent))
 		return ERR_CAST(parent);
 

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args()
  2025-04-10 13:12 [PATCH 0/2] software node: bug fixes Zijun Hu
  2025-04-10 13:12 ` [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node() Zijun Hu
@ 2025-04-10 13:12 ` Zijun Hu
  2025-04-14  8:08   ` Andy Shevchenko
  2025-04-14  8:45   ` Sakari Ailus
  2025-04-14  7:23 ` [PATCH 0/2] software node: bug fixes Andy Shevchenko
  2 siblings, 2 replies; 10+ messages in thread
From: Zijun Hu @ 2025-04-10 13:12 UTC (permalink / raw)
  To: Andy Shevchenko, Daniel Scally, Heikki Krogerus, Sakari Ailus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich
  Cc: Zijun Hu, linux-acpi, linux-kernel, Zijun Hu

From: Zijun Hu <quic_zijuhu@quicinc.com>

software_node_get_reference_args() wants to get @index-th element, so
the property value requires at least '(index + 1) * sizeof(*ref)' bytes.

Correct the check to avoid OOB access.

Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>
---
 drivers/base/swnode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
index 67040fff99b02c43999b175c2ba7e6d04322a446..efaac07f8ba38fae55214b71c2ecee15b5a711b1 100644
--- a/drivers/base/swnode.c
+++ b/drivers/base/swnode.c
@@ -529,7 +529,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
 	if (prop->is_inline)
 		return -EINVAL;
 
-	if (index * sizeof(*ref) >= prop->length)
+	if ((index + 1) * sizeof(*ref) > prop->length)
 		return -ENOENT;
 
 	ref_array = prop->pointer;

-- 
2.34.1


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH 0/2] software node: bug fixes
  2025-04-10 13:12 [PATCH 0/2] software node: bug fixes Zijun Hu
  2025-04-10 13:12 ` [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node() Zijun Hu
  2025-04-10 13:12 ` [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args() Zijun Hu
@ 2025-04-14  7:23 ` Andy Shevchenko
  2 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2025-04-14  7:23 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, linux-acpi, linux-kernel,
	Zijun Hu

On Thu, Apr 10, 2025 at 09:12:10PM +0800, Zijun Hu wrote:

If it's a series, cover letter is on purpose. Please, explain what's going on here.

> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node()
  2025-04-10 13:12 ` [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node() Zijun Hu
@ 2025-04-14  8:00   ` Andy Shevchenko
  2025-04-14 11:10     ` Zijun Hu
  0 siblings, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2025-04-14  8:00 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, linux-acpi, linux-kernel,
	Zijun Hu

On Thu, Apr 10, 2025 at 09:12:11PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> ERR_CAST() is normally used to cast an error-valued pointer type to
> another different type, But the first ERR_CAST() is to cast away the
> const in fwnode_create_software_node().
> 
> Add comment for this unusual ERR_CAST() usage.

...

> +	/* Only cast away the const by ERR_CAST() */
>  	if (IS_ERR(parent))
>  		return ERR_CAST(parent);

TBH, I don't see the value of this comment. And looking into the code, I would
rather drop this part. The current users do not rely on the any specific code
to be returned and also they check parent to be valid beforehand.

But let's hear others first.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args()
  2025-04-10 13:12 ` [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args() Zijun Hu
@ 2025-04-14  8:08   ` Andy Shevchenko
  2025-04-14 11:12     ` Zijun Hu
  2025-04-14  8:45   ` Sakari Ailus
  1 sibling, 1 reply; 10+ messages in thread
From: Andy Shevchenko @ 2025-04-14  8:08 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, linux-acpi, linux-kernel,
	Zijun Hu

On Thu, Apr 10, 2025 at 09:12:12PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> software_node_get_reference_args() wants to get @index-th element, so
> the property value requires at least '(index + 1) * sizeof(*ref)' bytes.
> 
> Correct the check to avoid OOB access.

Any real traceback?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args()
  2025-04-10 13:12 ` [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args() Zijun Hu
  2025-04-14  8:08   ` Andy Shevchenko
@ 2025-04-14  8:45   ` Sakari Ailus
  1 sibling, 0 replies; 10+ messages in thread
From: Sakari Ailus @ 2025-04-14  8:45 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Andy Shevchenko, Daniel Scally, Heikki Krogerus,
	Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	linux-acpi, linux-kernel, Zijun Hu

On Thu, Apr 10, 2025 at 09:12:12PM +0800, Zijun Hu wrote:
> From: Zijun Hu <quic_zijuhu@quicinc.com>
> 
> software_node_get_reference_args() wants to get @index-th element, so
> the property value requires at least '(index + 1) * sizeof(*ref)' bytes.
> 
> Correct the check to avoid OOB access.
> 
> Signed-off-by: Zijun Hu <quic_zijuhu@quicinc.com>

Reviewed-by: Sakari Ailus <sakari.ailus@linux.intel.com>

> ---
>  drivers/base/swnode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c
> index 67040fff99b02c43999b175c2ba7e6d04322a446..efaac07f8ba38fae55214b71c2ecee15b5a711b1 100644
> --- a/drivers/base/swnode.c
> +++ b/drivers/base/swnode.c
> @@ -529,7 +529,7 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode,
>  	if (prop->is_inline)
>  		return -EINVAL;
>  
> -	if (index * sizeof(*ref) >= prop->length)
> +	if ((index + 1) * sizeof(*ref) > prop->length)
>  		return -ENOENT;
>  
>  	ref_array = prop->pointer;
> 
> -- 
> 2.34.1
> 

-- 
Sakari Ailus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node()
  2025-04-14  8:00   ` Andy Shevchenko
@ 2025-04-14 11:10     ` Zijun Hu
  0 siblings, 0 replies; 10+ messages in thread
From: Zijun Hu @ 2025-04-14 11:10 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, linux-acpi, linux-kernel,
	Zijun Hu

On 2025/4/14 16:00, Andy Shevchenko wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> ERR_CAST() is normally used to cast an error-valued pointer type to
>> another different type, But the first ERR_CAST() is to cast away the
>> const in fwnode_create_software_node().
>>
>> Add comment for this unusual ERR_CAST() usage.
> ...
> 
>> +	/* Only cast away the const by ERR_CAST() */
>>  	if (IS_ERR(parent))
>>  		return ERR_CAST(parent);
> TBH, I don't see the value of this comment. And looking into the code, I would

thank you Andy for comments.
will drop this patch in v2.

> rather drop this part. The current users do not rely on the any specific code
> to be returned and also they check parent to be valid beforehand.
> 
> But let's hear others first.


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args()
  2025-04-14  8:08   ` Andy Shevchenko
@ 2025-04-14 11:12     ` Zijun Hu
  2025-04-15  6:42       ` Andy Shevchenko
  0 siblings, 1 reply; 10+ messages in thread
From: Zijun Hu @ 2025-04-14 11:12 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, linux-acpi, linux-kernel,
	Zijun Hu

On 2025/4/14 16:08, Andy Shevchenko wrote:
> On Thu, Apr 10, 2025 at 09:12:12PM +0800, Zijun Hu wrote:
>> From: Zijun Hu <quic_zijuhu@quicinc.com>
>>
>> software_node_get_reference_args() wants to get @index-th element, so
>> the property value requires at least '(index + 1) * sizeof(*ref)' bytes.
>>
>> Correct the check to avoid OOB access.
> Any real traceback?

no, find this issue during reading code.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args()
  2025-04-14 11:12     ` Zijun Hu
@ 2025-04-15  6:42       ` Andy Shevchenko
  0 siblings, 0 replies; 10+ messages in thread
From: Andy Shevchenko @ 2025-04-15  6:42 UTC (permalink / raw)
  To: Zijun Hu
  Cc: Daniel Scally, Heikki Krogerus, Sakari Ailus, Greg Kroah-Hartman,
	Rafael J. Wysocki, Danilo Krummrich, linux-acpi, linux-kernel,
	Zijun Hu

On Mon, Apr 14, 2025 at 07:12:27PM +0800, Zijun Hu wrote:
> On 2025/4/14 16:08, Andy Shevchenko wrote:
> > On Thu, Apr 10, 2025 at 09:12:12PM +0800, Zijun Hu wrote:
> >> From: Zijun Hu <quic_zijuhu@quicinc.com>
> >>
> >> software_node_get_reference_args() wants to get @index-th element, so
> >> the property value requires at least '(index + 1) * sizeof(*ref)' bytes.
> >>
> >> Correct the check to avoid OOB access.
> > Any real traceback?
> 
> no, find this issue during reading code.

Please, mention this in the commit message.

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2025-04-15  6:42 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-10 13:12 [PATCH 0/2] software node: bug fixes Zijun Hu
2025-04-10 13:12 ` [PATCH 1/2] software node: Add comment for the first ERR_CAST() in fwnode_create_software_node() Zijun Hu
2025-04-14  8:00   ` Andy Shevchenko
2025-04-14 11:10     ` Zijun Hu
2025-04-10 13:12 ` [PATCH 2/2] software node: Correct a OOB check in software_node_get_reference_args() Zijun Hu
2025-04-14  8:08   ` Andy Shevchenko
2025-04-14 11:12     ` Zijun Hu
2025-04-15  6:42       ` Andy Shevchenko
2025-04-14  8:45   ` Sakari Ailus
2025-04-14  7:23 ` [PATCH 0/2] software node: bug fixes Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).