Skip to contentSkip to conversation

drivers/char/ipmi: memcpy, need additional 2 bytes to avoid memory overflow

PATCH In review Chen Gang 2 participants 3 messages Mar 29, 2013 – Mar 30, 2013 IPMI

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 drivers/char/ipmi: memcpy, need additional 2 bytes to avoid memory overflow

when calling memcpy, read_data and write_data need additional 2 bytes.

write_data:
for checking: "if (size > IPMI_MAX_MSG_LENGTH)"
for operating: "memcpy(bt->write_data + 3, data + 1, size - 1)"

  read_data:
    for checking:  "if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH)"
    for operating: "memcpy(data + 2, bt->read_data + 4, msg_len - 2)"
---
 drivers/char/ipmi/ipmi_bt_sm.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/ipmi/ipmi_bt_sm.c +2 -2
index cdd4c09f..a22a7a5 100644
@@ -95,9 +95,9 @@ struct si_sm_data {
 	enum bt_states	state;
 	unsigned char	seq;		/* BT sequence number */
 	struct si_sm_io	*io;
-	unsigned char	write_data[IPMI_MAX_MSG_LENGTH];
+	unsigned char	write_data[IPMI_MAX_MSG_LENGTH + 2]; /* +2 for memcpy */
 	int		write_count;
-	unsigned char	read_data[IPMI_MAX_MSG_LENGTH];
+	unsigned char	read_data[IPMI_MAX_MSG_LENGTH + 2]; /* +2 for memcpy */
 	int		read_count;
 	int		truncated;
 	long		timeout;	/* microseconds countdown */
Signature · 1 line
1.7.7.6
#1 lore raw

Yes, this is correct, I've pulled it into my tree.

-corey

Quoted 32 lines · Chen Gang
   when calling memcpy, read_data and write_data need additional 2 bytes.

   write_data:
     for checking:  "if (size > IPMI_MAX_MSG_LENGTH)"
     for operating: "memcpy(bt->write_data + 3, data + 1, size - 1)"

   read_data:
     for checking:  "if (msg_len < 3 || msg_len > IPMI_MAX_MSG_LENGTH)"
     for operating: "memcpy(data + 2, bt->read_data + 4, msg_len - 2)"
---
  drivers/char/ipmi/ipmi_bt_sm.c |    4 ++--
  1 files changed, 2 insertions(+), 2 deletions(-)
drivers/char/ipmi/ipmi_bt_sm.c +2 -2
index cdd4c09f..a22a7a5 100644
@@ -95,9 +95,9 @@ struct si_sm_data {
  	enum bt_states	state;
  	unsigned char	seq;		/* BT sequence number */
  	struct si_sm_io	*io;
-	unsigned char	write_data[IPMI_MAX_MSG_LENGTH];
+	unsigned char	write_data[IPMI_MAX_MSG_LENGTH + 2]; /* +2 for memcpy */
  	int		write_count;
-	unsigned char	read_data[IPMI_MAX_MSG_LENGTH];
+	unsigned char	read_data[IPMI_MAX_MSG_LENGTH + 2]; /* +2 for memcpy */
  	int		read_count;
  	int		truncated;
  	long		timeout;	/* microseconds countdown */
author
#2 lore raw
Quoted 1 line · Corey Minyard

Yes, this is correct, I've pulled it into my tree.

thanks.

:-)

Signature · 3 lines
Chen Gang

Asianux Corporation