Skip to contentSkip to conversation

drivers/isdn: checkng length to be sure not memory overflow

PATCH Superseded Chen Gang 3 participants 13 messages Feb 27, 2013 – Mar 8, 2013

Subsystems (2)
lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 drivers/isdn: checkng length to be sure not memory overflow

the length of cmd.parm.cmsg.para is 50 (MAX_CAPI_PARA_LEN). the strlen(msg) may be more than 50 (Modem-Commandbuffer, less than 255).
isdn_tty_send_msg is called by isdn_tty_parse_at
the relative parameter is m->mdmcmd (atemu *m)
the relative command may be "+M..."

so need check the length to be sure not memory overflow.

---
 drivers/isdn/i4l/isdn_tty.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/isdn/i4l/isdn_tty.c +1 -1
index d8a7d83..c3f0f99 100644
@@ -902,7 +902,7 @@ isdn_tty_send_msg(modem_info *info, atemu *m, char *msg)
 	int j;
 	int l;
 
-	l = strlen(msg);
+	l = min(strlen(msg), sizeof(cmd.parm.cmsg.para) - 2);
 	if (!l) {
 		isdn_tty_modem_result(RESULT_ERROR, info);
 		return;
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 20 lines · Chen Gang

the length of cmd.parm.cmsg.para is 50 (MAX_CAPI_PARA_LEN). the strlen(msg) may be more than 50 (Modem-Commandbuffer, less than 255).
isdn_tty_send_msg is called by isdn_tty_parse_at
the relative parameter is m->mdmcmd (atemu *m)
the relative command may be "+M..."

so need check the length to be sure not memory overflow.

---
 drivers/isdn/i4l/isdn_tty.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/isdn/i4l/isdn_tty.c +0 -0
index d8a7d83..c3f0f99 100644

drivers/isdn/i4l/isdn_tty.c isdn_tty_send_msg(modem_info *info, atemu *m, char *msg) · line 908

Quoted 8 lines
drivers/isdn/i4l/isdn_tty.c +1 -1
@@ -902,7 +902,7 @@ isdn_tty_send_msg(modem_info *info, atemu *m, char *msg)
 	int j;
 	int l;
 
-	l = strlen(msg);
+	l = min(strlen(msg), sizeof(cmd.parm.cmsg.para) - 2);
 	if (!l) {
 		isdn_tty_modem_result(RESULT_ERROR, info);
 		return;

Yeah, looks sensible from the buffer overflow POV. I have no idea if this is correct from the ISDN POV as we drop the end of the buffer. But who cares, when nobody noticed in the past decade...

thanks,

Signature · 2 lines
js
suse labs
author
#2 lore raw
Quoted 2 lines · Jiri Slaby

I have no idea if
this is correct from the ISDN POV as we drop the end of the buffer

pardon ? what about "ISDN POV".
excuse me, my English is not quite well, I am either not quite
familiar with ISDN.

thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation
#3 lore raw
Quoted 5 lines · Chen Gang
Quoted 2 lines · Jiri Slaby

I have no idea if
this is correct from the ISDN POV as we drop the end of the buffer

pardon ? what about "ISDN POV".

"point of view" aka POV.

Hmm, "also known as" alias "aka" :).

Signature · 2 lines
js
suse labs
author
#4 lore raw
Quoted 9 lines · Jiri Slaby
Quoted 5 lines · Chen Gang
Quoted 5 lines
Quoted 2 lines · Jiri Slaby
Quoted 2 lines

I have no idea if
this is correct from the ISDN POV as we drop the end of the buffer

pardon ? what about "ISDN POV".

"point of view" aka POV.

Hmm, "also known as" alias "aka" :).

sorry, I still not quite understand (I am really not familiar with ISDN)

so I have to bother you with 2 questions, please help reply, thanks.

A) is our current patch OK ?
a. yes, ok, need do nothing for it, just is waiting for Acked-by or applying. b. no, need improving (e.g. additional consideration, comments, or others) c. no, it is useless patch.

B) does "ISDN POV" point to another issue ?
if yes:
I will read source code or search document on net, and should not bother you again. if possible, I can try to send relative patches, next.
else (no):
could you please say more details again ?
I should improve current patch (also need let you as Signed-of-By)

thanks.

:-)

Signature · 3 lines
Chen Gang

Asianux Corporation
#5 lore raw
Quoted 21 lines · Chen Gang
Quoted 9 lines · Jiri Slaby
Quoted 5 lines · Chen Gang
Quoted 5 lines
Quoted 2 lines · Jiri Slaby
Quoted 2 lines

I have no idea if
this is correct from the ISDN POV as we drop the end of the buffer

pardon ? what about "ISDN POV".

"point of view" aka POV.

Hmm, "also known as" alias "aka" :).

sorry, I still not quite understand (I am really not familiar with ISDN)

so I have to bother you with 2 questions, please help reply, thanks.

A) is our current patch OK ?
a. yes, ok, need do nothing for it, just is waiting for Acked-by or applying. b. no, need improving (e.g. additional consideration, comments, or others) c. no, it is useless patch.

Quoted 6 lines

B) does "ISDN POV" point to another issue ?
if yes:
I will read source code or search document on net, and should not bother you again. if possible, I can try to send relative patches, next.
else (no):
could you please say more details again ?

No, the sentence was "I have no idea if this is correct from the ISDN point of view because we drop the end of the buffer." I don't think there are piles of people to care about ISDN much nowadays. So we can close that it is correct to drop the rest of the buffer. In a hope that +M is not followed by text longer than 50-or-so chars.

There is nothing more to fix. (Well, there is, but not in this context.)

Signature · 2 lines
js
suse labs
author
#6 lore raw
Quoted 1 line · Jiri Slaby

I don't think there are piles of people to care about ISDN much nowadays.

I don't think either.
(I found it through reading the source code, by search strncpy)

if this is quite minor:
I suggest to delete this module.
the reason is:
it can not provide contributes, any more.
but may give a chance to the hacker which want to make an attack.

:-)

Quoted 3 lines

So we can
close that it is correct to drop the rest of the buffer. In a hope that +M is not followed by text longer than 50-or-so chars.

can we be sure that "+M..." is no more than 100+ chars ?
(I guess the sizeof (isdn_ctrl.parm) is 80+, but less than 100)
if we can not be sure:
do we need check and limit the length ? (I prefer to give a check) if the module will really be delete,
I still suggest to maintain previous versions (for security issue)

thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation
#7 lore raw
Quoted 8 lines · Chen Gang
Quoted 1 line · Jiri Slaby

I don't think there are piles of people to care about ISDN much nowadays.

I don't think either.
(I found it through reading the source code, by search strncpy)

if this is quite minor:
I suggest to delete this module.

Nah, there *are* still people using ISDN.

Quoted 7 lines
Quoted 3 lines

So we can
close that it is correct to drop the rest of the buffer. In a hope that +M is not followed by text longer than 50-or-so chars.

can we be sure that "+M..." is no more than 100+ chars ?
(I guess the sizeof (isdn_ctrl.parm) is 80+, but less than 100)
if we can not be sure:

No, we cannot be sure that a user gives us less than that. Your patch just throws the rest to fix that overflow, right? What I'm saying I wouldn't fix more than that.

Signature · 2 lines
js
suse labs
author
#8 lore raw
Quoted 3 lines · Jiri Slaby

Nah, there *are* still people using ISDN.

ok, thanks.

it seems, we need maintaining ISDN:
need fix bugs.
need not add new features.
need keep current features no touch.

Quoted 3 lines

No, we cannot be sure that a user gives us less than that. Your patch just throws the rest to fix that overflow, right? What I'm saying I wouldn't fix more than that.

what you said is: this patch need improving, is it correct ?
if it is correct.
I still prefer to throw the rest contents (but need improving, too)
for maintaining, we need fix bug, but not need add new features
so what we should do:
a) fix the bug (should not memory overflow)
b) keep the original buffer length no touch
it is not sizeof(cmd.parm.cmsg.para) - 2)
it should be sizeof(cmd.param) - sizeof(cmd.param.cmsg) + sizeof(cmd.param.cmsg.para) - 2
c) need complete the relative document to export the limitation.

is it ok ?
(if it is not ok, welcome to provide suggestion or completion)

thanks.

:-)

Signature · 3 lines
Chen Gang

Asianux Corporation
#9 lore raw
Quoted 28 lines · Chen Gang
Quoted 3 lines · Jiri Slaby

Nah, there *are* still people using ISDN.

ok, thanks.

it seems, we need maintaining ISDN:
need fix bugs.
need not add new features.
need keep current features no touch.

Quoted 3 lines

No, we cannot be sure that a user gives us less than that. Your patch just throws the rest to fix that overflow, right? What I'm saying I wouldn't fix more than that.

what you said is: this patch need improving, is it correct ?
if it is correct.
I still prefer to throw the rest contents (but need improving, too)
for maintaining, we need fix bug, but not need add new features
so what we should do:
a) fix the bug (should not memory overflow)
b) keep the original buffer length no touch
it is not sizeof(cmd.parm.cmsg.para) - 2)
it should be sizeof(cmd.param) - sizeof(cmd.param.cmsg) + sizeof(cmd.param.cmsg.para) - 2
c) need complete the relative document to export the limitation.

Quoted 1 line

is it ok ?

Yes, it is -- just fix the bug with minimal effort.

Signature · 2 lines
js
suse labs
author
#10 lore raw
Quoted 11 lines · Jiri Slaby
Quoted 11 lines

what you said is: this patch need improving, is it correct ?

Quoted 10 lines

if it is correct.
I still prefer to throw the rest contents (but need improving, too)
for maintaining, we need fix bug, but not need add new features
so what we should do:
a) fix the bug (should not memory overflow)
b) keep the original buffer length no touch
it is not sizeof(cmd.parm.cmsg.para) - 2)
it should be sizeof(cmd.param) - sizeof(cmd.param.cmsg) + sizeof(cmd.param.cmsg.para) - 2
c) need complete the relative document to export the limitation.

Quoted 2 lines
Quoted 1 line
Quoted 1 line

is it ok ?

Yes, it is -- just fix the bug with minimal effort.

ok, I will send patch v2 for it.

:-)

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#11 lore raw

PATCH v2 1/1 drivers/isdn: checkng length to be sure not memory overflow

sizeof (cmd.parm.cmsg.para) is 50 (MAX_CAPI_PARA_LEN). sizeof (cmd.parm) is 80+, but less than 100.
strlen(msg) may be more than 80+ (Modem-Commandbuffer, less than 255).
isdn_tty_send_msg is called by isdn_tty_parse_at
the relative parameter is m->mdmcmd (atemu *m)
the relative command may be "+M..."

so need check the length to be sure not memory overflow.
cmd.parm is a union, and need keep original valid buffer length no touch

---
 drivers/isdn/i4l/isdn_tty.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
drivers/isdn/i4l/isdn_tty.c +3 -1
index d8a7d83..ebaebdf 100644
@@ -902,7 +902,9 @@ isdn_tty_send_msg(modem_info *info, atemu *m, char *msg)
 	int j;
 	int l;
 
-	l = strlen(msg);
+	l = min(strlen(msg), sizeof(cmd.parm) - sizeof(cmd.parm.cmsg)
+		+ sizeof(cmd.parm.cmsg.para) - 2);
+
 	if (!l) {
 		isdn_tty_modem_result(RESULT_ERROR, info);
 		return;
Signature · 1 line
1.7.7.6
maintainer Applied
#12 lore raw

From: Chen Gang <[email protected]>
Date: Fri, 08 Mar 2013 12:25:41 +0800

Quoted 8 lines

sizeof (cmd.parm.cmsg.para) is 50 (MAX_CAPI_PARA_LEN). sizeof (cmd.parm) is 80+, but less than 100.
strlen(msg) may be more than 80+ (Modem-Commandbuffer, less than 255).
isdn_tty_send_msg is called by isdn_tty_parse_at
the relative parameter is m->mdmcmd (atemu *m)
the relative command may be "+M..."

Quoted 5 lines

so need check the length to be sure not memory overflow.
cmd.parm is a union, and need keep original valid buffer length no touch

Applied.