Skip to contentSkip to conversation

platform/chrome: Fix off-by-one error in wilco_ec/debugfs.c

PATCH In review Nick Crews 3 participants 6 messages Feb 20, 2019 – Feb 21, 2019

Subsystems (2)
lore
Share & tools
lore

Nick Crews

author
#0 lore raw

PATCH 1/1 platform/chrome: Fix off-by-one error in wilco_ec/debugfs.c

Before, in debugfs.c it was possible to supply only the message type, and not supply any other arguments when sending raw commands. However, this is never used by the EC, and it led to an underflow error. Now, just don't allow too short of a command, we will never need that anyways.

Fixes 46c7fd06f8c9 ("platform/chrome: wilco_ec: Add support for raw commands in debugfs")
---
 drivers/platform/chrome/wilco_ec/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +3 -3
index 46ff3b6c46c7..c090db2cd5be 100644
@@ -136,8 +136,8 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
 	ret = parse_hex_sentence(buf, kcount, request_data, TYPE_AND_DATA_SIZE);
 	if (ret < 0)
 		return ret;
-	/* Need at least two bytes for message type */
-	if (ret < 2)
+	/* Need at least two bytes for message type and one for command */
+	if (ret < 3)
 		return -EINVAL;
 
 	/* Clear response data buffer */
@@ -145,7 +145,7 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
 
 	msg.type = request_data[0] << 8 | request_data[1];
 	msg.flags = WILCO_EC_FLAG_RAW;
-	msg.command = ret > 2 ? request_data[2] : 0;
+	msg.command = request_data[2];
 	msg.request_data = ret > 3 ? request_data + 3 : 0;
 	msg.request_size = ret - 3;
 	msg.response_data = debug_info->raw_data;
#1 lore raw

Hi Nick,

Thanks for the patch.

Quoted 7 lines · Nick Crews

Before, in debugfs.c it was possible to supply only the message type, and not supply any other arguments when sending raw commands. However, this is never used by the EC, and it led to an underflow error. Now, just don't allow too short of a command, we will never need that anyways.

Fixes 46c7fd06f8c9 ("platform/chrome: wilco_ec: Add support for raw commands in debugfs")

As this is -next material I'd like to squash the fix if you don't mind.

-- Enric

Quoted 30 lines
---
 drivers/platform/chrome/wilco_ec/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +3 -3
index 46ff3b6c46c7..c090db2cd5be 100644
@@ -136,8 +136,8 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
 	ret = parse_hex_sentence(buf, kcount, request_data, TYPE_AND_DATA_SIZE);
 	if (ret < 0)
 		return ret;
-	/* Need at least two bytes for message type */
-	if (ret < 2)
+	/* Need at least two bytes for message type and one for command */
+	if (ret < 3)
 		return -EINVAL;
 
 	/* Clear response data buffer */
@@ -145,7 +145,7 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
 
 	msg.type = request_data[0] << 8 | request_data[1];
 	msg.flags = WILCO_EC_FLAG_RAW;
-	msg.command = ret > 2 ? request_data[2] : 0;
+	msg.command = request_data[2];
 	msg.request_data = ret > 3 ? request_data + 3 : 0;
 	msg.request_size = ret - 3;
 	msg.response_data = debug_info->raw_data;
author
#2 lore raw

Hi Enric,

Quoted 12 lines · Enric Balletbo i Serra

Hi Nick,

Thanks for the patch.

Quoted 6 lines · Nick Crews

Before, in debugfs.c it was possible to supply only the message type, and not supply any other arguments when sending raw commands. However, this is never used by the EC, and it led to an underflow error. Now, just don't allow too short of a command, we will never need that anyways.

Quoted 3 lines
Quoted 1 line
Fixes 46c7fd06f8c9 ("platform/chrome: wilco_ec: Add support for raw commands in debugfs")

As this is -next material I'd like to squash the fix if you don't mind.

Please do. Fixing something after it's already in the tree was a new process for me,
so I tried to copy other people's examples. Please let me know if there's anything else I should do something different next time.

Nick

Quoted 33 lines

-- Enric

Quoted 30 lines
---
 drivers/platform/chrome/wilco_ec/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +3 -3
index 46ff3b6c46c7..c090db2cd5be 100644
@@ -136,8 +136,8 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
      ret = parse_hex_sentence(buf, kcount, request_data, TYPE_AND_DATA_SIZE);
      if (ret < 0)
              return ret;
-     /* Need at least two bytes for message type */
-     if (ret < 2)
+     /* Need at least two bytes for message type and one for command */
+     if (ret < 3)
              return -EINVAL;
 
      /* Clear response data buffer */
@@ -145,7 +145,7 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
 
      msg.type = request_data[0] << 8 | request_data[1];
      msg.flags = WILCO_EC_FLAG_RAW;
-     msg.command = ret > 2 ? request_data[2] : 0;
+     msg.command = request_data[2];
      msg.request_data = ret > 3 ? request_data + 3 : 0;
      msg.request_size = ret - 3;
      msg.response_data = debug_info->raw_data;
#3 lore raw

Hi,

Quoted 18 lines · Nick Crews

Hi Enric,

Quoted 14 lines · Enric Balletbo i Serra

Hi Nick,

Thanks for the patch.

Quoted 7 lines · Nick Crews

Before, in debugfs.c it was possible to supply only the message type, and not supply any other arguments when sending raw commands. However, this is never used by the EC, and it led to an underflow error. Now, just don't allow too short of a command, we will never need that anyways.

Fixes 46c7fd06f8c9 ("platform/chrome: wilco_ec: Add support for raw commands in debugfs")
Quoted 8 lines
Quoted 1 line

As this is -next material I'd like to squash the fix if you don't mind.

Please do. Fixing something after it's already in the tree was a new process for me,
so I tried to copy other people's examples. Please let me know if there's anything else I should do something different next time.

Squashed and pushed for 5.1

Thanks,
Enric

Quoted 35 lines

Nick

Quoted 33 lines

-- Enric

Quoted 30 lines
---
 drivers/platform/chrome/wilco_ec/debugfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/platform/chrome/wilco_ec/debugfs.c +3 -3
index 46ff3b6c46c7..c090db2cd5be 100644
@@ -136,8 +136,8 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
      ret = parse_hex_sentence(buf, kcount, request_data, TYPE_AND_DATA_SIZE);
      if (ret < 0)
              return ret;
-     /* Need at least two bytes for message type */
-     if (ret < 2)
+     /* Need at least two bytes for message type and one for command */
+     if (ret < 3)
              return -EINVAL;
 
      /* Clear response data buffer */
@@ -145,7 +145,7 @@ static ssize_t raw_write(struct file *file, const char __user *user_buf,
 
      msg.type = request_data[0] << 8 | request_data[1];
      msg.flags = WILCO_EC_FLAG_RAW;
-     msg.command = ret > 2 ? request_data[2] : 0;
+     msg.command = request_data[2];
      msg.request_data = ret > 3 ? request_data + 3 : 0;
      msg.request_size = ret - 3;
      msg.response_data = debug_info->raw_data;
#4 lore raw
In reply to Nick Crews
Quoted 4 lines · Nick Crews

Fixing something after it's already in the tree was a new process for me, so I tried to copy other people's examples. Please let me know if there's anything else I should do something different next time.

I seldom mention how much I like Reported-by tags because it makes me seem needy... Also in this case it doesn't matter because it's going to get folded into the original patch so it's going to be lost anyway. But since you're asking process questions, the Reported-by cookie is nice.

regards,
dan carpenter

author
#5 lore raw

Thanks Dan, noted.

Quoted 17 lines · Dan Carpenter
Quoted 4 lines · Nick Crews

Fixing something after it's already in the tree was a new process for me, so I tried to copy other people's examples. Please let me know if there's anything else I should do something different next time.

I seldom mention how much I like Reported-by tags because it makes me seem needy... Also in this case it doesn't matter because it's going to get folded into the original patch so it's going to be lost anyway. But since you're asking process questions, the Reported-by cookie is nice.

regards,
dan carpenter