Skip to contentSkip to conversation

vmcore-dmesg stack smashing happend in extreme case

PATCH Superseded arthur 3 participants 3 messages Mar 12, 2014

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

arthur

author
#0 lore raw

PATCH v2 1/1 vmcore-dmesg stack smashing happend in extreme case

Description
in dump_dmesg_structured() the out_buf size is 4096, and if the length is less than 4080( 4096-16 ) it won't really write out. Normally, after writing one or four chars to the out_buf, it will check the length of out_buf. But in extreme cases, 19 chars was written to the out_buf before checking the length. This may cause the stack corruption. If the length was 4079 (won't realy write out), and then write 19 chars to it. the out_buf will overflow.

Solution
Change 16 to 64 thus can make sure that always have 64bytes before moving to next records. why using 64 is that a long long int can take 20 bytes. so the length of timestamp can be 44 ('[','.',']',' ') in extreme case.

---
 vmcore-dmesg/vmcore-dmesg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vmcore-dmesg/vmcore-dmesg.c +1 -1
index 0345660..e15cd91 100644
@@ -674,7 +674,7 @@ static void dump_dmesg_structured(int fd)
 			else
 				out_buf[len++] = c;
 
-			if (len >= OUT_BUF_SIZE - 16) {
+			if (len >= OUT_BUF_SIZE - 64) {
 				write_to_stdout(out_buf, len);
 				len = 0;
 			}
Signature · 7 lines
1.8.4.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec
Acked-by on v2 1/1
#1 lore raw
Quoted 9 lines · arthur

Description
in dump_dmesg_structured() the out_buf size is 4096, and if the length is less than 4080( 4096-16 ) it won't really write out. Normally, after writing one or four chars to the out_buf, it will check the length of out_buf. But in extreme cases, 19 chars was written to the out_buf before checking the length. This may cause the stack corruption. If the length was 4079 (won't realy write out), and then write 19 chars to it. the out_buf will overflow.

Quoted 8 lines

Solution
Change 16 to 64 thus can make sure that always have 64bytes before moving to next records. why using 64 is that a long long int can take 20 bytes. so the length of timestamp can be 44 ('[','.',']',' ') in extreme case.

---

Looks good to me.

Thanks
Vivek

Quoted 24 lines
 vmcore-dmesg/vmcore-dmesg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vmcore-dmesg/vmcore-dmesg.c +1 -1
index 0345660..e15cd91 100644
@@ -674,7 +674,7 @@ static void dump_dmesg_structured(int fd)
 			else
 				out_buf[len++] = c;
 
-			if (len >= OUT_BUF_SIZE - 16) {
+			if (len >= OUT_BUF_SIZE - 64) {
 				write_to_stdout(out_buf, len);
 				len = 0;
 			}
Signature · 7 lines
1.8.4.2


_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

#2 lore raw
Quoted 10 lines · Vivek Goyal
Quoted 9 lines · arthur

Description
in dump_dmesg_structured() the out_buf size is 4096, and if the length is less than 4080( 4096-16 ) it won't really write out. Normally, after writing one or four chars to the out_buf, it will check the length of out_buf. But in extreme cases, 19 chars was written to the out_buf before checking the length. This may cause the stack corruption. If the length was 4079 (won't realy write out), and then write 19 chars to it. the out_buf will overflow.

Quoted 7 lines
Quoted 7 lines

Solution
Change 16 to 64 thus can make sure that always have 64bytes before moving to next records. why using 64 is that a long long int can take 20 bytes. so the length of timestamp can be 44 ('[','.',']',' ') in extreme case.

Please include your given and family name in the From address and Signed-off-by line unless you only have one name.

Quoted 29 lines
Quoted 1 line

---

Looks good to me.

Thanks
Vivek

Quoted 20 lines
 vmcore-dmesg/vmcore-dmesg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
vmcore-dmesg/vmcore-dmesg.c +1 -1
index 0345660..e15cd91 100644
@@ -674,7 +674,7 @@ static void dump_dmesg_structured(int fd)
 			else
 				out_buf[len++] = c;
 
-			if (len >= OUT_BUF_SIZE - 16) {
+			if (len >= OUT_BUF_SIZE - 64) {
 				write_to_stdout(out_buf, len);
 				len = 0;
 			}
Signature · 1 line
1.8.4.2
Quoted 10 lines
Quoted 4 lines

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec

_______________________________________________
kexec mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/kexec