Skip to contentSkip to conversation

arch/powerpc/kernel: using %12.12s instead of %12s for avoiding memory overflow.

PATCH In review Chen Gang 2 participants 8 messages Jan 24, 2013 – Apr 24, 2013 PowerPC

lore
Share & tools
lore

Chen Gang

author
#0 lore raw

PATCH 1/1 arch/powerpc/kernel: using %12.12s instead of %12s for avoiding memory overflow.

for tmp_part->header.name:
it is "Terminating null required only for names < 12 chars". so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
 arch/powerpc/kernel/nvram_64.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
 	printk(KERN_WARNING "--------%s---------\n", label);
 	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
 	list_for_each_entry(tmp_part, &nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",
 		       tmp_part->index, tmp_part->header.signature,
 		       tmp_part->header.checksum, tmp_part->header.length,
 		       tmp_part->header.name);
Signature · 1 line
1.7.10.4
author
#1 lore raw

Hello relative members:

please give a glance to this patch, when you have time.

thanks.

:-)

gchen.

Quoted 33 lines · Chen Gang

for tmp_part->header.name:
it is "Terminating null required only for names < 12 chars". so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
 arch/powerpc/kernel/nvram_64.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
 	printk(KERN_WARNING "--------%s---------\n", label);
 	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
 	list_for_each_entry(tmp_part, &nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",
 		       tmp_part->index, tmp_part->header.signature,
 		       tmp_part->header.checksum, tmp_part->header.length,
 		       tmp_part->header.name);
Signature · 3 lines
Chen Gang

Asianux Corporation
author
#2 lore raw

Hello Maintainers:

could you help check this patch whether is ok ?

thanks.

Quoted 47 lines · Chen Gang

Hello relative members:

please give a glance to this patch, when you have time.

thanks.

:-)

gchen.

Quoted 33 lines · Chen Gang

for tmp_part->header.name:
it is "Terminating null required only for names < 12 chars". so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
 arch/powerpc/kernel/nvram_64.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
 	printk(KERN_WARNING "--------%s---------\n", label);
 	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
 	list_for_each_entry(tmp_part, &nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",
 		       tmp_part->index, tmp_part->header.signature,
 		       tmp_part->header.checksum, tmp_part->header.length,
 		       tmp_part->header.name);
Signature · 3 lines
Chen Gang

Asianux Corporation
author
#3 lore raw

Hello Vasant Hegde:

How about this patch, is it OK ?

Thanks.

Quoted 57 lines · Chen Gang

Hello Maintainers:

could you help check this patch whether is ok ?

thanks.

Quoted 47 lines · Chen Gang

Hello relative members:

please give a glance to this patch, when you have time.

thanks.

:-)

gchen.

Quoted 33 lines · Chen Gang

for tmp_part->header.name:
it is "Terminating null required only for names < 12 chars". so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
 arch/powerpc/kernel/nvram_64.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
 	printk(KERN_WARNING "--------%s---------\n", label);
 	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
 	list_for_each_entry(tmp_part, &nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",
 		       tmp_part->index, tmp_part->header.signature,
 		       tmp_part->header.checksum, tmp_part->header.length,
 		       tmp_part->header.name);
Signature · 3 lines
Chen Gang

Asianux Corporation
#4 lore raw
Quoted 47 lines · Chen Gang

Hello Vasant Hegde:

How about this patch, is it OK ?

Thanks.

Quoted 39 lines · Chen Gang

Hello Maintainers:

could you help check this patch whether is ok ?

thanks.

Quoted 31 lines · Chen Gang

Hello relative members:

please give a glance to this patch, when you have time.

   thanks.

   :-)

gchen.

Quoted 19 lines · Chen Gang

for tmp_part->header.name:
it is "Terminating null required only for names< 12 chars". so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
  arch/powerpc/kernel/nvram_64.c |    2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

arch/powerpc/kernel/nvram_64.c static void __init nvram_print_partitions(char * label) · line 205

Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
  	printk(KERN_WARNING "--------%s---------\n", label);
  	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
  	list_for_each_entry(tmp_part,&nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",

First, this code in inside NVRAM_DEBUG which is used only for debug purpose and AFAIK, all partition names are less than 20 character. So I don't think we need this patch.

-Vasant

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
arch/powerpc/kernel/nvram_64.c +0 -0
  		       tmp_part->index, tmp_part->header.signature,
  		       tmp_part->header.checksum, tmp_part->header.length,
  		       tmp_part->header.name);
#5 lore raw
Quoted 48 lines · Vasant Hegde
Quoted 47 lines · Chen Gang

Hello Vasant Hegde:

How about this patch, is it OK ?

Thanks.

Quoted 39 lines · Chen Gang

Hello Maintainers:

could you help check this patch whether is ok ?

thanks.

Quoted 31 lines · Chen Gang

Hello relative members:

please give a glance to this patch, when you have time.

thanks.

:-)

gchen.

Quoted 19 lines · Chen Gang

for tmp_part->header.name:
it is "Terminating null required only for names< 12 chars".
so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
   arch/powerpc/kernel/nvram_64.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines

arch/powerpc/kernel/nvram_64.c static void __init nvram_print_partitions(char * label) · line 205

Quoted 10 lines
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
   	printk(KERN_WARNING "--------%s---------\n", label);
   	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
   	list_for_each_entry(tmp_part,&nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",

First, this code in inside NVRAM_DEBUG which is used only for debug purpose and AFAIK, all partition names are less than 20 character. So I don't think we need

Sorry.. I meant 12 character.

-Vasant

Quoted 19 lines

this patch.

-Vasant

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

arch/powerpc/kernel/nvram_64.c static void __init nvram_print_partitions(char * label) · line 208

Quoted 4 lines
arch/powerpc/kernel/nvram_64.c +0 -0
   		tmp_part->index, tmp_part->header.signature,
   		       tmp_part->header.checksum, tmp_part->header.length,
   		       tmp_part->header.name);

_______________________________________________
Linuxppc-dev mailing list
[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev

author
#6 lore raw
Quoted 31 lines · Vasant Hegde
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
    for tmp_part->header.name:
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines

it is "Terminating null required only for names< 12 chars".
so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
   arch/powerpc/kernel/nvram_64.c |    2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
arch/powerpc/kernel/nvram_64.c +0 -0
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

arch/powerpc/kernel/nvram_64.c static void __init nvram_print_partitions(char * label) · line 205

Quoted 5 lines
arch/powerpc/kernel/nvram_64.c +1 -1
   	printk(KERN_WARNING "--------%s---------\n", label);
   	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
   	list_for_each_entry(tmp_part,&nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",

First, this code in inside NVRAM_DEBUG which is used only for debug purpose and AFAIK, all partition names are less than 20 character. So I don't think we need

Quoted 1 line

Sorry.. I meant 12 character.

Please see line 283:
"strncpy(part->header.name, "wwwwwwwwwwww", 12);" (it is not a NUL terminated string, and the length is 12)

And also, can we be sure that all partition names should be less than 12 characters ?

All together, I think we still need %12.12s to protect the memory.

Thanks.

Signature · 3 lines
Chen Gang

Asianux Corporation
author
#7 lore raw
In reply to Chen Gang

Hello Benjamin Herrenschmidt:

how about this patch ? is it correct ?

thanks.

:-)

gchen.

Quoted 33 lines · Chen Gang

for tmp_part->header.name:
it is "Terminating null required only for names < 12 chars". so need to limit the %.12s for it in printk

additional info:

%12s limit the width, not for the original string output length
if name length is more than 12, it still can be fully displayed. if name length is less than 12, the ' ' will be filled before name.

%.12s truly limit the original string output length (precision)

---
 arch/powerpc/kernel/nvram_64.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/powerpc/kernel/nvram_64.c +1 -1
index bec1e93..57bf6d2 100644
@@ -202,7 +202,7 @@ static void __init nvram_print_partitions(char * label)
 	printk(KERN_WARNING "--------%s---------\n", label);
 	printk(KERN_WARNING "indx\t\tsig\tchks\tlen\tname\n");
 	list_for_each_entry(tmp_part, &nvram_partitions, partition) {
-		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12s\n",
+		printk(KERN_WARNING "%4d    \t%02x\t%02x\t%d\t%12.12s\n",
 		       tmp_part->index, tmp_part->header.signature,
 		       tmp_part->header.checksum, tmp_part->header.length,
 		       tmp_part->header.name);
Signature · 3 lines
Chen Gang

Asianux Corporation