Skip to contentSkip to conversation

dpll: sanitize possible null pointer dereference in dpll_pin_parent_pin_set()

PATCH Applied Jiri Pirko 3 participants 5 messages Dec 11, 2023 – Dec 13, 2023

Subsystems (3)
lore
Share & tools
lore

Jiri Pirko

author maintainer
#0 lore raw

PATCH 1/1 dpll: sanitize possible null pointer dereference in dpll_pin_parent_pin_set()

From: Jiri Pirko <[email protected]>

User may not pass DPLL_A_PIN_STATE attribute in the pin set operation message. Sanitize that by checking if the attr pointer is not null and process the passed state attribute value only in that case.

Fixes 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions")
---
 drivers/dpll/dpll_netlink.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/dpll/dpll_netlink.c +8 -5
index 442a0ebeb953..ce7cf736f020 100644
@@ -925,7 +925,6 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
 			struct netlink_ext_ack *extack)
 {
 	struct nlattr *tb[DPLL_A_PIN_MAX + 1];
-	enum dpll_pin_state state;
 	u32 ppin_idx;
 	int ret;
 
@@ -936,10 +935,14 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
 		return -EINVAL;
 	}
 	ppin_idx = nla_get_u32(tb[DPLL_A_PIN_PARENT_ID]);
-	state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
-	ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
-	if (ret)
-		return ret;
+
+	if (tb[DPLL_A_PIN_STATE]) {
+		enum dpll_pin_state state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
+
+		ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
+		if (ret)
+			return ret;
+	}
 
 	return 0;
 }
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 34 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

User may not pass DPLL_A_PIN_STATE attribute in the pin set operation message. Sanitize that by checking if the attr pointer is not null and process the passed state attribute value only in that case.

Fixes 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions")
---
  drivers/dpll/dpll_netlink.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
drivers/dpll/dpll_netlink.c +1 -5
index 442a0ebeb953..ce7cf736f020 100644
@@ -925,7 +925,6 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
  			struct netlink_ext_ack *extack)
  {
  	struct nlattr *tb[DPLL_A_PIN_MAX + 1];
-	enum dpll_pin_state state;
  	u32 ppin_idx;
  	int ret;
 
@@ -936,10 +935,14 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
  		return -EINVAL;
  	}
  	ppin_idx = nla_get_u32(tb[DPLL_A_PIN_PARENT_ID]);
-	state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
-	ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
-	if (ret)
-		return ret;
+

drivers/dpll/dpll_netlink.c dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest, · line 948

Quoted 10 lines
drivers/dpll/dpll_netlink.c +7 -0
+	if (tb[DPLL_A_PIN_STATE]) {
+		enum dpll_pin_state state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
+
+		ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
+		if (ret)
+			return ret;
+	}
 
  	return 0;
  }

I don't believe that "set" command without set value should return 0
meaning "request was completed successfully". Maybe it's better to add another check like for DPLL_A_PIN_PARENT_ID and fill extack with description?

author maintainer
#2 lore raw
Quoted 40 lines · Mon, Dec 11, 2023 at 11:46:24AM CET, [email protected] wrote:
Quoted 39 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

User may not pass DPLL_A_PIN_STATE attribute in the pin set operation message. Sanitize that by checking if the attr pointer is not null and process the passed state attribute value only in that case.

Fixes 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions")
---
  drivers/dpll/dpll_netlink.c | 13 ++++++++-----
  1 file changed, 8 insertions(+), 5 deletions(-)
drivers/dpll/dpll_netlink.c +7 -5
index 442a0ebeb953..ce7cf736f020 100644
@@ -925,7 +925,6 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
  			struct netlink_ext_ack *extack)
  {
  	struct nlattr *tb[DPLL_A_PIN_MAX + 1];
-	enum dpll_pin_state state;
  	u32 ppin_idx;
  	int ret;
@@ -936,10 +935,14 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
  		return -EINVAL;
  	}
  	ppin_idx = nla_get_u32(tb[DPLL_A_PIN_PARENT_ID]);
-	state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
-	ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
-	if (ret)
-		return ret;
+
+	if (tb[DPLL_A_PIN_STATE]) {
+		enum dpll_pin_state state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
+
+		ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
+		if (ret)
+			return ret;
Quoted 8 lines

drivers/dpll/dpll_netlink.c dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest, · line 948

Quoted 3 lines
drivers/dpll/dpll_netlink.c +1 -0
+	}
  	return 0;
  }

I don't believe that "set" command without set value should return 0 meaning "request was completed successfully". Maybe it's better to add another check like for DPLL_A_PIN_PARENT_ID and fill extack with description?

Please see dpll_pin_parent_device_set(). State here is treated exactly the same as there. It makes sense during set operation to process only the attributes that are passed. In the future, dpll_pin_parent_pin_set() can process more attributes, lets be prepared for that.

maintainer Acked-by
#3 lore raw
Quoted 50 lines · Jiri Pirko
Quoted 40 lines · Mon, Dec 11, 2023 at 11:46:24AM CET, [email protected] wrote:
Quoted 39 lines · Jiri Pirko

From: Jiri Pirko <[email protected]>

User may not pass DPLL_A_PIN_STATE attribute in the pin set operation message. Sanitize that by checking if the attr pointer is not null and process the passed state attribute value only in that case.

Fixes 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions")
---
   drivers/dpll/dpll_netlink.c | 13 ++++++++-----
   1 file changed, 8 insertions(+), 5 deletions(-)
drivers/dpll/dpll_netlink.c +7 -5
index 442a0ebeb953..ce7cf736f020 100644
@@ -925,7 +925,6 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
   			struct netlink_ext_ack *extack)
   {
   	struct nlattr *tb[DPLL_A_PIN_MAX + 1];
-	enum dpll_pin_state state;
   	u32 ppin_idx;
   	int ret;
@@ -936,10 +935,14 @@ dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest,
   		return -EINVAL;
   	}
   	ppin_idx = nla_get_u32(tb[DPLL_A_PIN_PARENT_ID]);
-	state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
-	ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
-	if (ret)
-		return ret;
+
+	if (tb[DPLL_A_PIN_STATE]) {
+		enum dpll_pin_state state = nla_get_u32(tb[DPLL_A_PIN_STATE]);
+
+		ret = dpll_pin_on_pin_state_set(pin, ppin_idx, state, extack);
+		if (ret)
+			return ret;
Quoted 8 lines

drivers/dpll/dpll_netlink.c dpll_pin_parent_pin_set(struct dpll_pin *pin, struct nlattr *parent_nest, · line 948

Quoted 3 lines
drivers/dpll/dpll_netlink.c +1 -0
+	}
   	return 0;
   }

I don't believe that "set" command without set value should return 0 meaning "request was completed successfully". Maybe it's better to add another check like for DPLL_A_PIN_PARENT_ID and fill extack with description?

Quoted 4 lines

Please see dpll_pin_parent_device_set(). State here is treated exactly the same as there. It makes sense during set operation to process only the attributes that are passed. In the future, dpll_pin_parent_pin_set() can process more attributes, lets be prepared for that.

Ok, let's be ready.

#4 lore raw
In reply to Jiri Pirko
This patch was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Mon, 11 Dec 2023 09:37:58 +0100 you wrote:

From: Jiri Pirko <[email protected]>

User may not pass DPLL_A_PIN_STATE attribute in the pin set operation message. Sanitize that by checking if the attr pointer is not null and process the passed state attribute value only in that case.

Fixes 9d71b54b65b1 ("dpll: netlink: Add DPLL framework base functions")

[...]

Here is the summary with links:
- [net] dpll: sanitize possible null pointer dereference in dpll_pin_parent_pin_set()

    https://git.kernel.org/netdev/net/c/65c95f78917e

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html