linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scripts: Fix size mismatch of kexec_purgatory_size
@ 2016-07-04 13:55 Tautschnig, Michael
  2016-07-06  8:45 ` Dave Young
  0 siblings, 1 reply; 3+ messages in thread
From: Tautschnig, Michael @ 2016-07-04 13:55 UTC (permalink / raw)
  To: linux-kbuild, kexec, linux-kernel; +Cc: Michal Marek, Vivek Goyal

bin2c is used to create a valid C file out of a binary file where two
symbols will be globally defined: <name> and <name>_size. <name> is
passed as the first parameter of the host binary.

Building using goto-cc reported that the purgatory binary code (the only
current user of this utility) declares kexec_purgatory_size as 'size_t'
where bin2c generate <name>_size to be 'int' so in a 64-bit host where
sizeof(size_t) > sizeof(int) this type mismatch will always yield the
wrong value for big-endian architectures while for little-endian it will
be wrong if the object laid in memory directly after
kexec_purgatory_size contains non-zero value at the time of reading.

This commit changes <name>_size to be size_t instead.

Note:

Another way to fix the problem is to change the type of
kexec_purgatory_size to be 'int' as there's this check in code:
(kexec_purgatory_size <= 0)

Signed-off-by: Michael Tautschnig <tautschn@amazon.com>
Cc: Michal Marek <mmarek@suse.com>
Cc: Vivek Goyal <vgoyal@redhat.com>
---
 scripts/basic/bin2c.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/scripts/basic/bin2c.c b/scripts/basic/bin2c.c
index af187e6..c3d7eef 100644
--- a/scripts/basic/bin2c.c
+++ b/scripts/basic/bin2c.c
@@ -29,7 +29,8 @@ int main(int argc, char *argv[])
 	} while (ch != EOF);

 	if (argc > 1)
-		printf("\t;\n\nconst int %s_size = %d;\n", argv[1], total);
+		printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
+		       argv[1], total);

 	return 0;
 }
--
2.7.3.AMZN

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: Fix size mismatch of kexec_purgatory_size
  2016-07-04 13:55 [PATCH] scripts: Fix size mismatch of kexec_purgatory_size Tautschnig, Michael
@ 2016-07-06  8:45 ` Dave Young
  2016-07-22 12:06   ` Michal Marek
  0 siblings, 1 reply; 3+ messages in thread
From: Dave Young @ 2016-07-06  8:45 UTC (permalink / raw)
  To: Tautschnig, Michael
  Cc: linux-kbuild, kexec, linux-kernel, Michal Marek, Vivek Goyal

On 07/04/16 at 01:55pm, Tautschnig, Michael wrote:
> bin2c is used to create a valid C file out of a binary file where two
> symbols will be globally defined: <name> and <name>_size. <name> is
> passed as the first parameter of the host binary.
> 
> Building using goto-cc reported that the purgatory binary code (the only
> current user of this utility) declares kexec_purgatory_size as 'size_t'
> where bin2c generate <name>_size to be 'int' so in a 64-bit host where
> sizeof(size_t) > sizeof(int) this type mismatch will always yield the
> wrong value for big-endian architectures while for little-endian it will
> be wrong if the object laid in memory directly after
> kexec_purgatory_size contains non-zero value at the time of reading.
> 
> This commit changes <name>_size to be size_t instead.
> 
> Note:
> 
> Another way to fix the problem is to change the type of
> kexec_purgatory_size to be 'int' as there's this check in code:
> (kexec_purgatory_size <= 0)
> 
> Signed-off-by: Michael Tautschnig <tautschn@amazon.com>
> Cc: Michal Marek <mmarek@suse.com>
> Cc: Vivek Goyal <vgoyal@redhat.com>
> ---
>  scripts/basic/bin2c.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/basic/bin2c.c b/scripts/basic/bin2c.c
> index af187e6..c3d7eef 100644
> --- a/scripts/basic/bin2c.c
> +++ b/scripts/basic/bin2c.c
> @@ -29,7 +29,8 @@ int main(int argc, char *argv[])
>  	} while (ch != EOF);
> 
>  	if (argc > 1)
> -		printf("\t;\n\nconst int %s_size = %d;\n", argv[1], total);
> +		printf("\t;\n\n#include <linux/types.h>\n\nconst size_t %s_size = %d;\n",
> +		       argv[1], total);
> 
>  	return 0;
>  }
> --
> 2.7.3.AMZN
> 
> _______________________________________________
> kexec mailing list
> kexec@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/kexec

Acked-by: Dave Young <dyoung@redhat.com>

Thanks
Dave

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: Fix size mismatch of kexec_purgatory_size
  2016-07-06  8:45 ` Dave Young
@ 2016-07-22 12:06   ` Michal Marek
  0 siblings, 0 replies; 3+ messages in thread
From: Michal Marek @ 2016-07-22 12:06 UTC (permalink / raw)
  To: Dave Young, Tautschnig, Michael
  Cc: linux-kbuild, kexec, linux-kernel, Vivek Goyal

On 2016-07-06 10:45, Dave Young wrote:
> On 07/04/16 at 01:55pm, Tautschnig, Michael wrote:
>> bin2c is used to create a valid C file out of a binary file where two
>> symbols will be globally defined: <name> and <name>_size. <name> is
>> passed as the first parameter of the host binary.
>>
>> Building using goto-cc reported that the purgatory binary code (the only
>> current user of this utility) declares kexec_purgatory_size as 'size_t'
>> where bin2c generate <name>_size to be 'int' so in a 64-bit host where
>> sizeof(size_t) > sizeof(int) this type mismatch will always yield the
>> wrong value for big-endian architectures while for little-endian it will
>> be wrong if the object laid in memory directly after
>> kexec_purgatory_size contains non-zero value at the time of reading.
>>
>> This commit changes <name>_size to be size_t instead.
>>
>> Note:
>>
>> Another way to fix the problem is to change the type of
>> kexec_purgatory_size to be 'int' as there's this check in code:
>> (kexec_purgatory_size <= 0)
>>
>> Signed-off-by: Michael Tautschnig <tautschn@amazon.com>
>> Cc: Michal Marek <mmarek@suse.com>
>> Cc: Vivek Goyal <vgoyal@redhat.com>
[...]
> Acked-by: Dave Young <dyoung@redhat.com>

Applied to kbuild.git#kbuild.

Michal

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-07-22 12:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-04 13:55 [PATCH] scripts: Fix size mismatch of kexec_purgatory_size Tautschnig, Michael
2016-07-06  8:45 ` Dave Young
2016-07-22 12:06   ` Michal Marek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).