Skip to contentSkip to conversation

kexec-tools: Fix conversion overflow when compiling on 32-bit platforms

PATCH Applied Helge Deller 2 participants 8 messages Oct 1, 2019 – Oct 7, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kexec-tools: Fix conversion overflow when compiling on 32-bit platforms

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'

  805 |  *phys_off = UINT64_MAX;
      |              ^~~~~~~~~~

Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.

util_lib/elf_info.c +1 -1
index 2bce5cb..4d16983 100644
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
 {
 	int ret;
 
-	*phys_off = UINT64_MAX;
+	*phys_off = (unsigned long) UINT64_MAX;
 
 	ret = read_elf(fd);
 	if (!ret) {

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

#1 lore raw
Quoted 18 lines · Helge Deller

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'

  805 |  *phys_off = UINT64_MAX;
      |              ^~~~~~~~~~

Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.

util_lib/elf_info.c +0 -0
index 2bce5cb..4d16983 100644

util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805

Quoted 5 lines
util_lib/elf_info.c +1 -1
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
 {
 	int ret;
 
-	*phys_off = UINT64_MAX;
+	*phys_off = (unsigned long) UINT64_MAX;

This seems to mask the problem that UINT64_MAX is not the right initialiser for unsigned long values on 32-bit platforms.

Could we consider using UINT64_MAX from limits.h instead?

util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)

Quoted 4 lines
util_lib/elf_info.c +0 -0
 	ret = read_elf(fd);
 	if (!ret) {
 

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

#2 lore raw
Quoted 22 lines · Simon Horman
Quoted 21 lines · Helge Deller

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'

   805 |  *phys_off = UINT64_MAX;
       |              ^~~~~~~~~~

Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.

util_lib/elf_info.c +0 -0
index 2bce5cb..4d16983 100644
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
  {
  	int ret;
 
Quoted 6 lines

util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805

Quoted 2 lines
util_lib/elf_info.c +1 -1
-	*phys_off = UINT64_MAX;
+	*phys_off = (unsigned long) UINT64_MAX;

This seems to mask the problem that UINT64_MAX is not the right initialiser for unsigned long values on 32-bit platforms. Could we consider using UINT64_MAX from limits.h instead?

UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigning UINT32_MAX on a 32bit platform might be wrong. So I think the cast above is probably the best solution.

Helge

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

#3 lore raw
Quoted 30 lines · Helge Deller
Quoted 22 lines · Simon Horman
Quoted 21 lines · Helge Deller

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'

   805 |  *phys_off = UINT64_MAX;
       |              ^~~~~~~~~~

Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.

util_lib/elf_info.c +0 -0
index 2bce5cb..4d16983 100644
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
  {
  	int ret;
 
Quoted 6 lines

util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805

Quoted 2 lines
util_lib/elf_info.c +1 -1
-	*phys_off = UINT64_MAX;
+	*phys_off = (unsigned long) UINT64_MAX;

This seems to mask the problem that UINT64_MAX is not the right initialiser for unsigned long values on 32-bit platforms. Could we consider using UINT64_MAX from limits.h instead?

Quoted 4 lines

UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigning UINT32_MAX on a 32bit platform might be wrong. So I think the cast above is probably the best solution.

Sorry, I made a typo above.
What I meant is, can we consider using ULONG_MAX.

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

#4 lore raw
Quoted 31 lines · Simon Horman
Quoted 30 lines · Helge Deller
Quoted 28 lines · Simon Horman
Quoted 18 lines · Helge Deller

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'

    805 |  *phys_off = UINT64_MAX;
        |              ^~~~~~~~~~

Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.

util_lib/elf_info.c +0 -0
index 2bce5cb..4d16983 100644

util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805

Quoted 5 lines
util_lib/elf_info.c +1 -1
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
   {
   	int ret;
 
-	*phys_off = UINT64_MAX;
+	*phys_off = (unsigned long) UINT64_MAX;

This seems to mask the problem that UINT64_MAX is not the right initialiser for unsigned long values on 32-bit platforms. Could we consider using UINT64_MAX from limits.h instead?

Quoted 7 lines
Quoted 4 lines

UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigning UINT32_MAX on a 32bit platform might be wrong. So I think the cast above is probably the best solution.

Sorry, I made a typo above.
What I meant is, can we consider using ULONG_MAX.

Yes, that's probably ok.

Helge

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

#5 lore raw
Quoted 37 lines · Helge Deller
Quoted 36 lines · Simon Horman
Quoted 34 lines · Helge Deller
Quoted 22 lines · Simon Horman
Quoted 21 lines · Helge Deller

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to 'long unsigned int' changes value from '18446744073709551615' to '4294967295'

    805 |  *phys_off = UINT64_MAX;
        |              ^~~~~~~~~~

Fix it by casting UINT64_MAX to (unsigned long) before storing it to *phys_off.

util_lib/elf_info.c +0 -0
index 2bce5cb..4d16983 100644
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
   {
   	int ret;
 
Quoted 6 lines

util_lib/elf_info.c int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off) · line 805

Quoted 2 lines
util_lib/elf_info.c +1 -1
-	*phys_off = UINT64_MAX;
+	*phys_off = (unsigned long) UINT64_MAX;

This seems to mask the problem that UINT64_MAX is not the right initialiser for unsigned long values on 32-bit platforms. Could we consider using UINT64_MAX from limits.h instead?

UINT64 means it is a 64bit value, while "unsigned long" is either 32-bit, 64bit (or maybe in the future even 128bit?).
Even assigning UINT32_MAX on a 32bit platform might be wrong. So I think the cast above is probably the best solution.

Quoted 4 lines
Quoted 2 lines

Sorry, I made a typo above.
What I meant is, can we consider using ULONG_MAX.

Yes, that's probably ok.

Thanks. Will you send an updated patch?

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

#6 lore raw

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to

     'long unsigned int' changes value from '18446744073709551615' to '4294967295'

805 | *phys_off = UINT64_MAX;

Fix it by using ULONG_MAX instead of UINT64_MAX.

util_lib/elf_info.c +1 -1
index 2bce5cb..7803a94 100644
@@ -802,7 +802,7 @@ int read_phys_offset_elf_kcore(int fd, unsigned long *phys_off)
 {
 	int ret;
 
-	*phys_off = UINT64_MAX;
+	*phys_off = ULONG_MAX;
 
 	ret = read_elf(fd);
 	if (!ret) {

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

Applied
#7 lore raw
Quoted 4 lines · Helge Deller

When compiling kexec-tools on a 32-bit platform, assigning an (unsigned long long) value to an (unsigned long) variable creates this warning:

Quoted 8 lines

elf_info.c: In function 'read_phys_offset_elf_kcore':
elf_info.c:805:14: warning: conversion from 'long long unsigned int' to

     'long unsigned int' changes value from '18446744073709551615' to '4294967295'

805 | *phys_off = UINT64_MAX;

Fix it by using ULONG_MAX instead of UINT64_MAX.

Thanks, applied.

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