2021-10-13 16:48:01

by kernel test robot

[permalink] [raw]
Subject: [mcgrof:modules-next 1/1] include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Off' {aka 'unsigned int'}

tree: https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
head: 8b1185a4427b772b9f02376a08272c3019777581
commit: 8b1185a4427b772b9f02376a08272c3019777581 [1/1] module: change to print useful messages from elf_validity_check()
config: um-i386_defconfig (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce (this is a W=1 build):
# https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/commit/?id=8b1185a4427b772b9f02376a08272c3019777581
git remote add mcgrof https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git
git fetch --no-tags mcgrof modules-next
git checkout 8b1185a4427b772b9f02376a08272c3019777581
# save the attached .config to linux build tree
make W=1 ARCH=um SUBARCH=i386

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <[email protected]>

All warnings (new ones prefixed by >>):

In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
kernel/module.c: In function 'validate_section_offset':
>> include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Off' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:2953:3: note: in expansion of macro 'pr_err'
2953 | pr_err("Invalid ELF section offset/size: secend(%lu) < shdr->sh_offset(%llu) or secend(%lu) > e_shnum(%lu)\n",
| ^~~~~~
kernel/module.c:2953:77: note: format string is defined here
2953 | pr_err("Invalid ELF section offset/size: secend(%lu) < shdr->sh_offset(%llu) or secend(%lu) > e_shnum(%lu)\n",
| ~~~^
| |
| long long unsigned int
| %u
In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
kernel/module.c: In function 'elf_validity_check':
include/linux/kern_levels.h:5:18: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'unsigned int' [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:2974:3: note: in expansion of macro 'pr_err'
2974 | pr_err("Invalid ELF header len %lu < %lu\n", info->len,
| ^~~~~~
kernel/module.c:2974:42: note: format string is defined here
2974 | pr_err("Invalid ELF header len %lu < %lu\n", info->len,
| ~~^
| |
| long unsigned int
| %u
In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
include/linux/kern_levels.h:5:18: warning: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'unsigned int' [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:2994:3: note: in expansion of macro 'pr_err'
2994 | pr_err("Invalid ELF section header size %d != %lu\n",
| ^~~~~~
kernel/module.c:2994:51: note: format string is defined here
2994 | pr_err("Invalid ELF section header size %d != %lu\n",
| ~~^
| |
| long unsigned int
| %u
In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
>> include/linux/kern_levels.h:5:18: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'unsigned int' [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:3007:3: note: in expansion of macro 'pr_err'
3007 | pr_err("Invalid ELF section header overflow: %ld > %llu\n",
| ^~~~~~
kernel/module.c:3007:50: note: format string is defined here
3007 | pr_err("Invalid ELF section header overflow: %ld > %llu\n",
| ~~^
| |
| long int
| %d
In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
>> include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'long unsigned int' [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:3007:3: note: in expansion of macro 'pr_err'
3007 | pr_err("Invalid ELF section header overflow: %ld > %llu\n",
| ^~~~~~
kernel/module.c:3007:57: note: format string is defined here
3007 | pr_err("Invalid ELF section header overflow: %ld > %llu\n",
| ~~~^
| |
| long long unsigned int
| %lu
In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
>> include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Word' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:3049:3: note: in expansion of macro 'pr_err'
3049 | pr_err("ELF Spec violation: section 0 type!=SH_NULL(%d) or non-zero len(%llu) or addr(%llu)\n",
| ^~~~~~
kernel/module.c:3049:78: note: format string is defined here
3049 | pr_err("ELF Spec violation: section 0 type!=SH_NULL(%d) or non-zero len(%llu) or addr(%llu)\n",
| ~~~^
| |
| long long unsigned int
| %u
In file included from include/linux/kernel.h:19,
from include/linux/list.h:9,
from include/linux/module.h:12,
from include/linux/moduleloader.h:6,
from kernel/module.c:11:
>> include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 4 has type 'Elf32_Addr' {aka 'unsigned int'} [-Wformat=]
5 | #define KERN_SOH "\001" /* ASCII Start Of Header */
| ^~~~~~
include/linux/printk.h:418:11: note: in definition of macro 'printk_index_wrap'
418 | _p_func(_fmt, ##__VA_ARGS__); \
| ^~~~
include/linux/printk.h:489:2: note: in expansion of macro 'printk'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~
include/linux/kern_levels.h:11:18: note: in expansion of macro 'KERN_SOH'
11 | #define KERN_ERR KERN_SOH "3" /* error conditions */
| ^~~~~~~~
include/linux/printk.h:489:9: note: in expansion of macro 'KERN_ERR'
489 | printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
| ^~~~~~~~
kernel/module.c:3049:3: note: in expansion of macro 'pr_err'
3049 | pr_err("ELF Spec violation: section 0 type!=SH_NULL(%d) or non-zero len(%llu) or addr(%llu)\n",
| ^~~~~~
kernel/module.c:3049:92: note: format string is defined here
3049 | pr_err("ELF Spec violation: section 0 type!=SH_NULL(%d) or non-zero len(%llu) or addr(%llu)\n",
| ~~~^
| |
| long long unsigned int
| %u


vim +5 include/linux/kern_levels.h

314ba3520e513a Joe Perches 2012-07-30 4
04d2c8c83d0e3a Joe Perches 2012-07-30 @5 #define KERN_SOH "\001" /* ASCII Start Of Header */
04d2c8c83d0e3a Joe Perches 2012-07-30 6 #define KERN_SOH_ASCII '\001'
04d2c8c83d0e3a Joe Perches 2012-07-30 7

:::::: The code at line 5 was first introduced by commit
:::::: 04d2c8c83d0e3ac5f78aeede51babb3236200112 printk: convert the format for KERN_<LEVEL> to a 2 byte pattern

:::::: TO: Joe Perches <[email protected]>
:::::: CC: Linus Torvalds <[email protected]>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]


Attachments:
(No filename) (14.26 kB)
.config.gz (9.64 kB)
Download all attachments

2021-10-13 17:11:57

by Shuah Khan

[permalink] [raw]
Subject: Re: [mcgrof:modules-next 1/1] include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Off' {aka 'unsigned int'}

Hi Luis,

On 10/13/21 10:42 AM, kernel test robot wrote:
> tree: https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git modules-next
> head: 8b1185a4427b772b9f02376a08272c3019777581
> commit: 8b1185a4427b772b9f02376a08272c3019777581 [1/1] module: change to print useful messages from elf_validity_check()
> config: um-i386_defconfig (attached as .config)
> compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
> reproduce (this is a W=1 build):
> # https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git/commit/?id=8b1185a4427b772b9f02376a08272c3019777581
> git remote add mcgrof https://git.kernel.org/pub/scm/linux/kernel/git/mcgrof/linux.git
> git fetch --no-tags mcgrof modules-next
> git checkout 8b1185a4427b772b9f02376a08272c3019777581
> # save the attached .config to linux build tree
> make W=1 ARCH=um SUBARCH=i386
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <[email protected]>
>
> All warnings (new ones prefixed by >>):
>

All of these warnings can be fixed easily by leaving out the fields that
are the problem. I can send a patch for that.

This one is real issue though;

static int validate_section_offset(struct load_info *info, Elf_Shdr *shdr)
{
unsigned long secend; /* too short when sh_offset is Elf64_Off */

/*
* Check for both overflow and offset/size being
* too large.
*/
secend = shdr->sh_offset + shdr->sh_size;


secend is unsigned long which is too short when sh_offset is Elf64_Off

It appears to me that some sections of this elf validation code probably
needs to be arch specific. validate_section_offset() is one with this
potential for secend overflow.

We can introduce arch specific header print routine. Easy option is not
printing any info., which we know isn't very useful.

Let me know your thoughts.

thanks,
-- Shuah

2021-10-13 21:24:07

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [mcgrof:modules-next 1/1] include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Off' {aka 'unsigned int'}

On Wed, Oct 13, 2021 at 11:09:15AM -0600, Shuah Khan wrote:
> Hi Luis,
> We can introduce arch specific header print routine. Easy option is not
> printing any info., which we know isn't very useful.
>
> Let me know your thoughts.

You found an issue without the debug prints, and so you'd know better if
the effort is worth the trouble, so I'll let you decide.

Luis

2021-10-13 22:18:51

by Shuah Khan

[permalink] [raw]
Subject: Re: [mcgrof:modules-next 1/1] include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Off' {aka 'unsigned int'}

On 10/13/21 3:18 PM, Luis Chamberlain wrote:
> On Wed, Oct 13, 2021 at 11:09:15AM -0600, Shuah Khan wrote:
>> Hi Luis,
>> We can introduce arch specific header print routine. Easy option is not
>> printing any info., which we know isn't very useful.
>>
>> Let me know your thoughts.
>
> You found an issue without the debug prints, and so you'd know better if
> the effort is worth the trouble, so I'll let you decide.
>

Right the issue with validate_section_offset() is separate from the debug.
I will fix the pr_err warns first by tweaking the messages to not print
the variables that cause problems.

I will send a separate patch for validate_section_offset() which needs to
be arch specific similar to elf_check_arch().

Let me know if this plan sounds good.

thanks,
-- Shuah

2021-10-13 22:42:32

by Luis Chamberlain

[permalink] [raw]
Subject: Re: [mcgrof:modules-next 1/1] include/linux/kern_levels.h:5:18: warning: format '%llu' expects argument of type 'long long unsigned int', but argument 3 has type 'Elf32_Off' {aka 'unsigned int'}

On Wed, Oct 13, 2021 at 04:16:36PM -0600, Shuah Khan wrote:
> On 10/13/21 3:18 PM, Luis Chamberlain wrote:
> > On Wed, Oct 13, 2021 at 11:09:15AM -0600, Shuah Khan wrote:
> > > Hi Luis,
> > > We can introduce arch specific header print routine. Easy option is not
> > > printing any info., which we know isn't very useful.
> > >
> > > Let me know your thoughts.
> >
> > You found an issue without the debug prints, and so you'd know better if
> > the effort is worth the trouble, so I'll let you decide.
> >
>
> Right the issue with validate_section_offset() is separate from the debug.
> I will fix the pr_err warns first by tweaking the messages to not print
> the variables that cause problems.
>
> I will send a separate patch for validate_section_offset() which needs to
> be arch specific similar to elf_check_arch().
>
> Let me know if this plan sounds good.

Sounds good! Thanks for doing this work!

Luis