* [RFC] vsprintf: compile error on %09pK [not found] <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p3> @ 2023-04-03 10:46 ` Jaewon Kim 2023-04-03 12:18 ` Sergey Senozhatsky 2023-04-03 12:53 ` Petr Mladek 0 siblings, 2 replies; 10+ messages in thread From: Jaewon Kim @ 2023-04-03 10:46 UTC (permalink / raw) To: pmladek, senozhatsky Cc: linux-mm, linux-kernel, jaewon31.kim, GyeongHwan Hong Hello I've just changed %09lx to %09pK on my driver code to hide the address, but I faced compiler error. The %9pK without 0 worked. Is there restriction on %pK which does now allow %0 ? I've wondered whether I did wrong or it is a printk problem. To show easily I tried to add pr_info("%09pK\n", nodemask); in page_alloc.c Then here's what I did. $ ARCH=x86 make x86_64_defconfig ; make mm/page_alloc.o # # No change to .config # CALL scripts/checksyscalls.sh DESCEND objtool INSTALL libsubcmd_headers CC mm/page_alloc.o In file included from ./include/asm-generic/bug.h:22:0, from ./arch/x86/include/asm/bug.h:87, from ./include/linux/bug.h:5, from ./include/linux/mmdebug.h:5, from ./include/linux/mm.h:6, from mm/page_alloc.c:19: mm/page_alloc.c: In function ‘__alloc_pages’: ./include/linux/kern_levels.h:5:18: error: '0' flag used with ‘%p’ gnu_printf format [-Werror=format=] #define KERN_SOH "\001" /* ASCII Start Of Header */ ^ ./include/linux/printk.h:427:11: note: in definition of macro ‘printk_index_wrap’ _p_func(_fmt, ##__VA_ARGS__); \ ^ ./include/linux/printk.h:528:2: note: in expansion of macro ‘printk’ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) ^ ./include/linux/kern_levels.h:14:19: note: in expansion of macro ‘KERN_SOH’ #define KERN_INFO KERN_SOH "6" /* informational */ ^ ./include/linux/printk.h:528:9: note: in expansion of macro ‘KERN_INFO’ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) ^ mm/page_alloc.c:5564:2: note: in expansion of macro ‘pr_info’ pr_info("%09pK\n", nodemask); ^ Jaewon Kim ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] vsprintf: compile error on %09pK 2023-04-03 10:46 ` [RFC] vsprintf: compile error on %09pK Jaewon Kim @ 2023-04-03 12:18 ` Sergey Senozhatsky 2023-04-03 12:53 ` Petr Mladek 1 sibling, 0 replies; 10+ messages in thread From: Sergey Senozhatsky @ 2023-04-03 12:18 UTC (permalink / raw) To: Jaewon Kim Cc: pmladek, senozhatsky, linux-mm, linux-kernel, jaewon31.kim, GyeongHwan Hong On (23/04/03 19:46), Jaewon Kim wrote: > I've just changed %09lx to %09pK on my driver code to hide the address, but I > faced compiler error. The %9pK without 0 worked. > > Is there restriction on %pK which does now allow %0 ? I've wondered whether I > did wrong or it is a printk problem. I don't think this is %pK limitation. %p should not take modification flags. E.g. %3p doesn't make sense, we still should print the entire pointer. ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] vsprintf: compile error on %09pK 2023-04-03 10:46 ` [RFC] vsprintf: compile error on %09pK Jaewon Kim 2023-04-03 12:18 ` Sergey Senozhatsky @ 2023-04-03 12:53 ` Petr Mladek 2023-04-03 14:39 ` Jaewon Kim 1 sibling, 1 reply; 10+ messages in thread From: Petr Mladek @ 2023-04-03 12:53 UTC (permalink / raw) To: Jaewon Kim Cc: senozhatsky, linux-mm, linux-kernel, jaewon31.kim, GyeongHwan Hong On Mon 2023-04-03 19:46:17, Jaewon Kim wrote: > Hello > > I've just changed %09lx to %09pK on my driver code to hide the address, but I > faced compiler error. The %9pK without 0 worked. What exactly do you want to achieve, please? Note that printk() hashes pointers by default. It means that %p does not print the value but a hash based on the value. If you print the same pointer twice, you will see the same hash, so you know that the pointer is the same. But you do not see the address so that you could not use the value for a security attack. See Documentation/core-api/printk-formats.rst Anyway, the main question if it makes sense to print the pointer value at all. The address is not useful if it can't be compared with other pointers or if the data on the address could not be checked. > Is there restriction on %pK which does now allow %0 ? I've wondered whether I > did wrong or it is a printk problem. > > To show easily I tried to add pr_info("%09pK\n", nodemask); in page_alloc.c > Then here's what I did. > > $ ARCH=x86 make x86_64_defconfig ; make mm/page_alloc.o > # > # No change to .config > # > CALL scripts/checksyscalls.sh > DESCEND objtool > INSTALL libsubcmd_headers > CC mm/page_alloc.o > In file included from ./include/asm-generic/bug.h:22:0, > from ./arch/x86/include/asm/bug.h:87, > from ./include/linux/bug.h:5, > from ./include/linux/mmdebug.h:5, > from ./include/linux/mm.h:6, > from mm/page_alloc.c:19: > mm/page_alloc.c: In function ‘__alloc_pages’: > ./include/linux/kern_levels.h:5:18: error: '0' flag used with ‘%p’ gnu_printf format [-Werror=format=] > #define KERN_SOH "\001" /* ASCII Start Of Header */ As Sergey already wrote. %p does not support any modification flags. Best Regards, Petr ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] vsprintf: compile error on %09pK 2023-04-03 12:53 ` Petr Mladek @ 2023-04-03 14:39 ` Jaewon Kim 2023-04-03 15:34 ` Sergey Senozhatsky ` (3 more replies) 0 siblings, 4 replies; 10+ messages in thread From: Jaewon Kim @ 2023-04-03 14:39 UTC (permalink / raw) To: Petr Mladek Cc: Jaewon Kim, senozhatsky, linux-mm, linux-kernel, GyeongHwan Hong 2023년 4월 3일 (월) 오후 9:53, Petr Mladek <pmladek@suse.com>님이 작성: > > On Mon 2023-04-03 19:46:17, Jaewon Kim wrote: > > Hello > > > > I've just changed %09lx to %09pK on my driver code to hide the address, but I > > faced compiler error. The %9pK without 0 worked. > > What exactly do you want to achieve, please? Hello Thank you for your comment. I wanted to print phys_addr_t type value only when kptr_restrict sysctl is allowed. So I thought I could use %pK for that purpose. And the physical address is not that long. I wanted to make that length short like 9 hex. > > Note that printk() hashes pointers by default. It means that %p does not > print the value but a hash based on the value. > > If you print the same pointer twice, you will see the same hash, so > you know that the pointer is the same. But you do not see the address > so that you could not use the value for a security attack. > > See Documentation/core-api/printk-formats.rst > > Anyway, the main question if it makes sense to print the pointer value > at all. The address is not useful if it can't be compared with > other pointers or if the data on the address could not be checked. > > > Is there restriction on %pK which does now allow %0 ? I've wondered whether I > > did wrong or it is a printk problem. > > > > To show easily I tried to add pr_info("%09pK\n", nodemask); in page_alloc.c > > Then here's what I did. > > > > $ ARCH=x86 make x86_64_defconfig ; make mm/page_alloc.o > > # > > # No change to .config > > # > > CALL scripts/checksyscalls.sh > > DESCEND objtool > > INSTALL libsubcmd_headers > > CC mm/page_alloc.o > > In file included from ./include/asm-generic/bug.h:22:0, > > from ./arch/x86/include/asm/bug.h:87, > > from ./include/linux/bug.h:5, > > from ./include/linux/mmdebug.h:5, > > from ./include/linux/mm.h:6, > > from mm/page_alloc.c:19: > > mm/page_alloc.c: In function ‘__alloc_pages’: > > ./include/linux/kern_levels.h:5:18: error: '0' flag used with ‘%p’ gnu_printf format [-Werror=format=] > > #define KERN_SOH "\001" /* ASCII Start Of Header */ > > As Sergey already wrote. %p does not support any modification flags. Okay, then we can't use %09pK. I've just wondered because %9pK works. BR Jaewon Kim > > Best Regards, > Petr ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] vsprintf: compile error on %09pK 2023-04-03 14:39 ` Jaewon Kim @ 2023-04-03 15:34 ` Sergey Senozhatsky 2023-04-03 16:04 ` David Laight ` (2 subsequent siblings) 3 siblings, 0 replies; 10+ messages in thread From: Sergey Senozhatsky @ 2023-04-03 15:34 UTC (permalink / raw) To: Jaewon Kim Cc: Petr Mladek, Jaewon Kim, senozhatsky, linux-mm, linux-kernel, GyeongHwan Hong On (23/04/03 23:39), Jaewon Kim wrote: [..] > > Okay, then we can't use %09pK. I've just wondered because %9pK works. This is not per printk / kernel, Wformat warnings come from the compiler. Per C11 (7.21.6 6): 0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros (following any indication of sign or base) are used to pad to the field width rather than performing space padding ... For other conversions, the behavior is undefined. So using 0 for p should trigger an undefined behavior as far as the standard C concerned. Unless I'm missing something. ^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: [RFC] vsprintf: compile error on %09pK 2023-04-03 14:39 ` Jaewon Kim 2023-04-03 15:34 ` Sergey Senozhatsky @ 2023-04-03 16:04 ` David Laight [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p6> [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p5> 3 siblings, 0 replies; 10+ messages in thread From: David Laight @ 2023-04-03 16:04 UTC (permalink / raw) To: 'Jaewon Kim', Petr Mladek Cc: Jaewon Kim, senozhatsky, linux-mm, linux-kernel, GyeongHwan Hong From: Jaewon Kim > Sent: 03 April 2023 15:40 ... > I wanted to print phys_addr_t type value only when kptr_restrict sysctl is > allowed. So I thought I could use %pK for that purpose. And the physical > address is not that long. I wanted to make that length short like 9 hex. Isn't that is the wrong format for physical addresses anyway? They can be larger than virtual ones (eg x86 with PAE). David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p6>]
* RE: [RFC] vsprintf: compile error on %09pK [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p6> @ 2023-04-04 10:12 ` Jaewon Kim 2023-04-04 12:03 ` Petr Mladek [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p1> 0 siblings, 2 replies; 10+ messages in thread From: Jaewon Kim @ 2023-04-04 10:12 UTC (permalink / raw) To: David Laight, 'Jaewon Kim', Petr Mladek Cc: Jaewon Kim, senozhatsky, linux-mm, linux-kernel, GyeongHwan Hong >From: Jaewon Kim >> Sent: 03 April 2023 15:40 >... >> I wanted to print phys_addr_t type value only when kptr_restrict sysctl is >> allowed. So I thought I could use %pK for that purpose. And the physical >> address is not that long. I wanted to make that length short like 9 hex. > >Isn't that is the wrong format for physical addresses anyway? >They can be larger than virtual ones (eg x86 with PAE). Yeah, correct. I just used %pK to hide physical address, I thought it could be leak in security perspective. Could you give me advice how I can hide the address by default and look the address if kptr_restrict allow it? Jaewon Kim > > David ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [RFC] vsprintf: compile error on %09pK 2023-04-04 10:12 ` Jaewon Kim @ 2023-04-04 12:03 ` Petr Mladek [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p1> 1 sibling, 0 replies; 10+ messages in thread From: Petr Mladek @ 2023-04-04 12:03 UTC (permalink / raw) To: Jaewon Kim Cc: David Laight, 'Jaewon Kim', senozhatsky, linux-mm, linux-kernel, GyeongHwan Hong On Tue 2023-04-04 19:12:01, Jaewon Kim wrote: > >From: Jaewon Kim > >> Sent: 03 April 2023 15:40 > >... > >> I wanted to print phys_addr_t type value only when kptr_restrict sysctl is > >> allowed. So I thought I could use %pK for that purpose. And the physical > >> address is not that long. I wanted to make that length short like 9 hex. > > > >Isn't that is the wrong format for physical addresses anyway? > >They can be larger than virtual ones (eg x86 with PAE). > > Yeah, correct. I just used %pK to hide physical address, I thought it could be > leak in security perspective. Could you give me advice how I can hide the > address by default and look the address if kptr_restrict allow it? Could you please send a patch that would show what value you want to print? The initial mail mentioned converting %09lx to %09pK in some driver. Then it included a warning when compiling from mm/page_alloc.o Honestly, I think that you could just use %pK or %p. IMHO, it does not make sense to optimize it for the length. Anyway, there is still the question if the address is really worth printing. Will it really help to locate a potential problem? Best Regards, Petr ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p1>]
* RE: [RFC] vsprintf: compile error on %09pK [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p1> @ 2023-04-04 12:33 ` Jaewon Kim 0 siblings, 0 replies; 10+ messages in thread From: Jaewon Kim @ 2023-04-04 12:33 UTC (permalink / raw) To: Petr Mladek, Jaewon Kim Cc: David Laight, 'Jaewon Kim', senozhatsky, linux-mm, linux-kernel, GyeongHwan Hong >On Tue 2023-04-04 19:12:01, Jaewon Kim wrote: >> >From: Jaewon Kim >> >> Sent: 03 April 2023 15:40 >> >... >> >> I wanted to print phys_addr_t type value only when kptr_restrict sysctl is >> >> allowed. So I thought I could use %pK for that purpose. And the physical >> >> address is not that long. I wanted to make that length short like 9 hex. >> > >> >Isn't that is the wrong format for physical addresses anyway? >> >They can be larger than virtual ones (eg x86 with PAE). >> >> Yeah, correct. I just used %pK to hide physical address, I thought it could be >> leak in security perspective. Could you give me advice how I can hide the >> address by default and look the address if kptr_restrict allow it? > >Could you please send a patch that would show what value you want to print? > >The initial mail mentioned converting %09lx to %09pK in some driver. >Then it included a warning when compiling from mm/page_alloc.o > O Oh I just found something I'm interested. I was printing rmem->base and rmem->name and wanted to hide the rmem->base. The commit aeb9267eb6b1 ("of: reserved-mem: print out reserved-mem details during boot - v6.3-rc1") just used %pa. If %pa is not good enough in security perspecitve, I think I can use %pa. Yes it was just my curiosity. I don't actually need the length. I'm OK now. Thank you >Honestly, I think that you could just use %pK or %p. IMHO, it does not >make sense to optimize it for the length. > >Anyway, there is still the question if the address is really worth >printing. Will it really help to locate a potential problem? > >Best Regards, >Petr ^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p5>]
* RE: [RFC] vsprintf: compile error on %09pK [not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p5> @ 2023-04-04 10:16 ` Jaewon Kim 0 siblings, 0 replies; 10+ messages in thread From: Jaewon Kim @ 2023-04-04 10:16 UTC (permalink / raw) To: Sergey Senozhatsky, Jaewon Kim Cc: Petr Mladek, Jaewon Kim, linux-mm, linux-kernel, GyeongHwan Hong >[..] >> >> Okay, then we can't use %09pK. I've just wondered because %9pK works. > >This is not per printk / kernel, Wformat warnings come from the >compiler. > >Per C11 (7.21.6 6): > 0 For d, i, o, u, x, X, a, A, e, E, f, F, g, and G conversions, leading zeros > (following any indication of sign or base) are used to pad to the field width > rather than performing space padding > ... > For other conversions, the behavior is undefined. > >So using 0 for p should trigger an undefined behavior as far as the >standard C concerned. Unless I'm missing something. Thank your for the information about the leading 0 case. By the way do you know if there is policy for none 0 digit like %9pK? Jaewon Kim ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2023-04-04 12:33 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p3>
2023-04-03 10:46 ` [RFC] vsprintf: compile error on %09pK Jaewon Kim
2023-04-03 12:18 ` Sergey Senozhatsky
2023-04-03 12:53 ` Petr Mladek
2023-04-03 14:39 ` Jaewon Kim
2023-04-03 15:34 ` Sergey Senozhatsky
2023-04-03 16:04 ` David Laight
[not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p6>
2023-04-04 10:12 ` Jaewon Kim
2023-04-04 12:03 ` Petr Mladek
[not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p1>
2023-04-04 12:33 ` Jaewon Kim
[not found] ` <CGME20230403104617epcms1p383bacbca705c0d7e4fffca6833050e42@epcms1p5>
2023-04-04 10:16 ` Jaewon Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox