* [PATCH] binfmt_elf_fdpic: clean up debug warnings @ 2023-09-27 13:29 Greg Ungerer 2023-09-27 15:59 ` Kees Cook 2023-09-29 17:58 ` Kees Cook 0 siblings, 2 replies; 5+ messages in thread From: Greg Ungerer @ 2023-09-27 13:29 UTC (permalink / raw) To: linux-fsdevel, linux-mm, linux-kernel Cc: palmer, keescook, ebiederm, brauner, viro, Greg Ungerer The binfmt_elf_fdpic loader has some debug trace that can be enabled at build time. The recent 64-bit additions cause some warnings if that debug is enabled, such as: fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file’: fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘Elf64_Addr’ {aka ‘long long unsigned int’} [-Wformat=] 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) | ^~~~~~~~ ./include/linux/printk.h:427:25: note: in definition of macro ‘printk_index_wrap’ 427 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~ Cast values to the largest possible type (which is equivilent to unsigned long long in this case) and use appropriate format specifiers to match. Fixes: b922bf04d2c1 ("binfmt_elf_fdpic: support 64-bit systems") Signed-off-by: Greg Ungerer <gerg@kernel.org> --- fs/binfmt_elf_fdpic.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c index 43b2a2851ba3..97c3e8551aac 100644 --- a/fs/binfmt_elf_fdpic.c +++ b/fs/binfmt_elf_fdpic.c @@ -900,10 +900,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, kdebug("- DYNAMIC[]: %lx", params->dynamic_addr); seg = loadmap->segs; for (loop = 0; loop < loadmap->nsegs; loop++, seg++) - kdebug("- LOAD[%d] : %08x-%08x [va=%x ms=%x]", + kdebug("- LOAD[%d] : %08llx-%08llx [va=%llx ms=%llx]", loop, - seg->addr, seg->addr + seg->p_memsz - 1, - seg->p_vaddr, seg->p_memsz); + (unsigned long long) seg->addr, + (unsigned long long) seg->addr + seg->p_memsz - 1, + (unsigned long long) seg->p_vaddr, + (unsigned long long) seg->p_memsz); return 0; @@ -1082,9 +1084,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, maddr = vm_mmap(file, maddr, phdr->p_memsz + disp, prot, flags, phdr->p_offset - disp); - kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx", - loop, phdr->p_memsz + disp, prot, flags, - phdr->p_offset - disp, maddr); + kdebug("mmap[%d] <file> sz=%llx pr=%x fl=%x of=%llx --> %08lx", + loop, (unsigned long long) phdr->p_memsz + disp, + prot, flags, (unsigned long long) phdr->p_offset - disp, + maddr); if (IS_ERR_VALUE(maddr)) return (int) maddr; @@ -1146,8 +1149,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, #else if (excess > 0) { - kdebug("clear[%d] ad=%lx sz=%lx", - loop, maddr + phdr->p_filesz, excess); + kdebug("clear[%d] ad=%llx sz=%lx", loop, + (unsigned long long) maddr + phdr->p_filesz, + excess); if (clear_user((void *) maddr + phdr->p_filesz, excess)) return -EFAULT; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] binfmt_elf_fdpic: clean up debug warnings 2023-09-27 13:29 [PATCH] binfmt_elf_fdpic: clean up debug warnings Greg Ungerer @ 2023-09-27 15:59 ` Kees Cook 2023-09-28 4:53 ` Greg Ungerer 2023-09-29 17:58 ` Kees Cook 1 sibling, 1 reply; 5+ messages in thread From: Kees Cook @ 2023-09-27 15:59 UTC (permalink / raw) To: Greg Ungerer Cc: linux-fsdevel, linux-mm, linux-kernel, palmer, ebiederm, brauner, viro On Wed, Sep 27, 2023 at 11:29:33PM +1000, Greg Ungerer wrote: > The binfmt_elf_fdpic loader has some debug trace that can be enabled at > build time. The recent 64-bit additions cause some warnings if that > debug is enabled, such as: > > fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file’: > fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘Elf64_Addr’ {aka ‘long long unsigned int’} [-Wformat=] > 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) > | ^~~~~~~~ > ./include/linux/printk.h:427:25: note: in definition of macro ‘printk_index_wrap’ > 427 | _p_func(_fmt, ##__VA_ARGS__); \ > | ^~~~ > > Cast values to the largest possible type (which is equivilent to unsigned > long long in this case) and use appropriate format specifiers to match. It seems like these should all just be "unsigned long", yes? -Kees > > Fixes: b922bf04d2c1 ("binfmt_elf_fdpic: support 64-bit systems") > Signed-off-by: Greg Ungerer <gerg@kernel.org> > --- > fs/binfmt_elf_fdpic.c | 20 ++++++++++++-------- > 1 file changed, 12 insertions(+), 8 deletions(-) > > diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c > index 43b2a2851ba3..97c3e8551aac 100644 > --- a/fs/binfmt_elf_fdpic.c > +++ b/fs/binfmt_elf_fdpic.c > @@ -900,10 +900,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, > kdebug("- DYNAMIC[]: %lx", params->dynamic_addr); > seg = loadmap->segs; > for (loop = 0; loop < loadmap->nsegs; loop++, seg++) > - kdebug("- LOAD[%d] : %08x-%08x [va=%x ms=%x]", > + kdebug("- LOAD[%d] : %08llx-%08llx [va=%llx ms=%llx]", > loop, > - seg->addr, seg->addr + seg->p_memsz - 1, > - seg->p_vaddr, seg->p_memsz); > + (unsigned long long) seg->addr, > + (unsigned long long) seg->addr + seg->p_memsz - 1, > + (unsigned long long) seg->p_vaddr, > + (unsigned long long) seg->p_memsz); > > return 0; > > @@ -1082,9 +1084,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, > maddr = vm_mmap(file, maddr, phdr->p_memsz + disp, prot, flags, > phdr->p_offset - disp); > > - kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx", > - loop, phdr->p_memsz + disp, prot, flags, > - phdr->p_offset - disp, maddr); > + kdebug("mmap[%d] <file> sz=%llx pr=%x fl=%x of=%llx --> %08lx", > + loop, (unsigned long long) phdr->p_memsz + disp, > + prot, flags, (unsigned long long) phdr->p_offset - disp, > + maddr); > > if (IS_ERR_VALUE(maddr)) > return (int) maddr; > @@ -1146,8 +1149,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, > > #else > if (excess > 0) { > - kdebug("clear[%d] ad=%lx sz=%lx", > - loop, maddr + phdr->p_filesz, excess); > + kdebug("clear[%d] ad=%llx sz=%lx", loop, > + (unsigned long long) maddr + phdr->p_filesz, > + excess); > if (clear_user((void *) maddr + phdr->p_filesz, excess)) > return -EFAULT; > } > -- > 2.25.1 > -- Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] binfmt_elf_fdpic: clean up debug warnings 2023-09-27 15:59 ` Kees Cook @ 2023-09-28 4:53 ` Greg Ungerer 2023-09-29 17:58 ` Kees Cook 0 siblings, 1 reply; 5+ messages in thread From: Greg Ungerer @ 2023-09-28 4:53 UTC (permalink / raw) To: Kees Cook Cc: linux-fsdevel, linux-mm, linux-kernel, palmer, ebiederm, brauner, viro Hi Kees, On 28/9/23 01:59, Kees Cook wrote: > On Wed, Sep 27, 2023 at 11:29:33PM +1000, Greg Ungerer wrote: >> The binfmt_elf_fdpic loader has some debug trace that can be enabled at >> build time. The recent 64-bit additions cause some warnings if that >> debug is enabled, such as: >> >> fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file’: >> fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘Elf64_Addr’ {aka ‘long long unsigned int’} [-Wformat=] >> 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) >> | ^~~~~~~~ >> ./include/linux/printk.h:427:25: note: in definition of macro ‘printk_index_wrap’ >> 427 | _p_func(_fmt, ##__VA_ARGS__); \ >> | ^~~~ >> >> Cast values to the largest possible type (which is equivilent to unsigned >> long long in this case) and use appropriate format specifiers to match. > > It seems like these should all just be "unsigned long", yes? Some of them yes, but not all. For example trying to use unsigned long in the last chunk of this patch: fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file_by_direct_mmap’: fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘long long unsigned int’ [-Wformat=] 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) | ^~~~~~~~ ./include/linux/printk.h:427:25: note: in definition of macro ‘printk_index_wrap’ 427 | _p_func(_fmt, ##__VA_ARGS__); \ | ^~~~ fs/binfmt_elf_fdpic.c:46:26: note: in expansion of macro ‘printk’ 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) | ^~~~~~ fs/binfmt_elf_fdpic.c:1152:25: note: in expansion of macro ‘kdebug’ 1152 | kdebug("clear[%d] ad=%lx sz=%lx", loop, | ^~~~~~ Regards Greg > -Kees > >> >> Fixes: b922bf04d2c1 ("binfmt_elf_fdpic: support 64-bit systems") >> Signed-off-by: Greg Ungerer <gerg@kernel.org> >> --- >> fs/binfmt_elf_fdpic.c | 20 ++++++++++++-------- >> 1 file changed, 12 insertions(+), 8 deletions(-) >> >> diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c >> index 43b2a2851ba3..97c3e8551aac 100644 >> --- a/fs/binfmt_elf_fdpic.c >> +++ b/fs/binfmt_elf_fdpic.c >> @@ -900,10 +900,12 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, >> kdebug("- DYNAMIC[]: %lx", params->dynamic_addr); >> seg = loadmap->segs; >> for (loop = 0; loop < loadmap->nsegs; loop++, seg++) >> - kdebug("- LOAD[%d] : %08x-%08x [va=%x ms=%x]", >> + kdebug("- LOAD[%d] : %08llx-%08llx [va=%llx ms=%llx]", >> loop, >> - seg->addr, seg->addr + seg->p_memsz - 1, >> - seg->p_vaddr, seg->p_memsz); >> + (unsigned long long) seg->addr, >> + (unsigned long long) seg->addr + seg->p_memsz - 1, >> + (unsigned long long) seg->p_vaddr, >> + (unsigned long long) seg->p_memsz); >> >> return 0; >> >> @@ -1082,9 +1084,10 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, >> maddr = vm_mmap(file, maddr, phdr->p_memsz + disp, prot, flags, >> phdr->p_offset - disp); >> >> - kdebug("mmap[%d] <file> sz=%lx pr=%x fl=%x of=%lx --> %08lx", >> - loop, phdr->p_memsz + disp, prot, flags, >> - phdr->p_offset - disp, maddr); >> + kdebug("mmap[%d] <file> sz=%llx pr=%x fl=%x of=%llx --> %08lx", >> + loop, (unsigned long long) phdr->p_memsz + disp, >> + prot, flags, (unsigned long long) phdr->p_offset - disp, >> + maddr); >> >> if (IS_ERR_VALUE(maddr)) >> return (int) maddr; >> @@ -1146,8 +1149,9 @@ static int elf_fdpic_map_file_by_direct_mmap(struct elf_fdpic_params *params, >> >> #else >> if (excess > 0) { >> - kdebug("clear[%d] ad=%lx sz=%lx", >> - loop, maddr + phdr->p_filesz, excess); >> + kdebug("clear[%d] ad=%llx sz=%lx", loop, >> + (unsigned long long) maddr + phdr->p_filesz, >> + excess); >> if (clear_user((void *) maddr + phdr->p_filesz, excess)) >> return -EFAULT; >> } >> -- >> 2.25.1 >> > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] binfmt_elf_fdpic: clean up debug warnings 2023-09-28 4:53 ` Greg Ungerer @ 2023-09-29 17:58 ` Kees Cook 0 siblings, 0 replies; 5+ messages in thread From: Kees Cook @ 2023-09-29 17:58 UTC (permalink / raw) To: Greg Ungerer Cc: linux-fsdevel, linux-mm, linux-kernel, palmer, ebiederm, brauner, viro On Thu, Sep 28, 2023 at 02:53:09PM +1000, Greg Ungerer wrote: > Hi Kees, > > On 28/9/23 01:59, Kees Cook wrote: > > On Wed, Sep 27, 2023 at 11:29:33PM +1000, Greg Ungerer wrote: > > > The binfmt_elf_fdpic loader has some debug trace that can be enabled at > > > build time. The recent 64-bit additions cause some warnings if that > > > debug is enabled, such as: > > > > > > fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file’: > > > fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘Elf64_Addr’ {aka ‘long long unsigned int’} [-Wformat=] > > > 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) > > > | ^~~~~~~~ > > > ./include/linux/printk.h:427:25: note: in definition of macro ‘printk_index_wrap’ > > > 427 | _p_func(_fmt, ##__VA_ARGS__); \ > > > | ^~~~ > > > > > > Cast values to the largest possible type (which is equivilent to unsigned > > > long long in this case) and use appropriate format specifiers to match. > > > > It seems like these should all just be "unsigned long", yes? > > Some of them yes, but not all. > For example trying to use unsigned long in the last chunk of this patch: > > fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file_by_direct_mmap’: > fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 3 has type ‘long long unsigned int’ [-Wformat=] Oh, something is actually using "long long" already. :P Gotcha. Thanks! -Kees -- Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] binfmt_elf_fdpic: clean up debug warnings 2023-09-27 13:29 [PATCH] binfmt_elf_fdpic: clean up debug warnings Greg Ungerer 2023-09-27 15:59 ` Kees Cook @ 2023-09-29 17:58 ` Kees Cook 1 sibling, 0 replies; 5+ messages in thread From: Kees Cook @ 2023-09-29 17:58 UTC (permalink / raw) To: linux-fsdevel, linux-mm, linux-kernel, Greg Ungerer Cc: Kees Cook, palmer, ebiederm, brauner, viro On Wed, 27 Sep 2023 23:29:33 +1000, Greg Ungerer wrote: > The binfmt_elf_fdpic loader has some debug trace that can be enabled at > build time. The recent 64-bit additions cause some warnings if that > debug is enabled, such as: > > fs/binfmt_elf_fdpic.c: In function ‘elf_fdpic_map_file’: > fs/binfmt_elf_fdpic.c:46:33: warning: format ‘%x’ expects argument of type ‘unsigned int’, but argument 3 has type ‘Elf64_Addr’ {aka ‘long long unsigned int’} [-Wformat=] > 46 | #define kdebug(fmt, ...) printk("FDPIC "fmt"\n" ,##__VA_ARGS__ ) > | ^~~~~~~~ > ./include/linux/printk.h:427:25: note: in definition of macro ‘printk_index_wrap’ > 427 | _p_func(_fmt, ##__VA_ARGS__); \ > | ^~~~ > > [...] Applied to for-next/execve, thanks! [1/1] binfmt_elf_fdpic: clean up debug warnings https://git.kernel.org/kees/c/35bcdcf3d50c Take care, -- Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-09-29 17:58 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-09-27 13:29 [PATCH] binfmt_elf_fdpic: clean up debug warnings Greg Ungerer 2023-09-27 15:59 ` Kees Cook 2023-09-28 4:53 ` Greg Ungerer 2023-09-29 17:58 ` Kees Cook 2023-09-29 17:58 ` Kees Cook
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).