On Thu, Feb 08, 2024 at 09:29:26AM +0000, Kevin Brodsky wrote:
%#lp results in the address being prefixed with 0x, like %#p, but not if the capability is null-derived. Make sure the prefix is used in all cases.
I think it was done on purpose as (per [1]): - "In addition, for null-derived capabilities (capabilities where the tag and upper attribute word are all zero), only the address is displayed (the Basic Format)." - Basic Format: ... "This should generally match the existing format used with integer pointers." - "Linux kernel displays integer pointers as hexadecimal without a 0x prefix), and p should match a platform's existing format."
And I think the reason why "%#p" works is just a coincidence as '#' is being supported by relevant formatting function (number) which is used when printing default integer pointers. It is not by 'design' as such.
--- [1] https://github.com/CTSRD-CHERI/cheri-c-programming/wiki/Displaying-Capabilit... --- BR Beata
Fixes: ("lib/vsprintf: Add support for architectural capabilities") Signed-off-by: Kevin Brodsky kevin.brodsky@arm.com
This is probably the result of some confusion during the review process for the original patch, as the first version never printed the prefix.
Review branch:
https://git.morello-project.org/kbrodsky-arm/linux/-/commits/morello/printk_...
lib/vsprintf.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c index 0b551cf89880..1a2a01843775 100644 --- a/lib/vsprintf.c +++ b/lib/vsprintf.c @@ -2550,13 +2550,9 @@ char *capability(const char *fmt, char *buf, char *end, void * __capability cap, * Same applies when hashing is active. */ if ((!cheri_tag_get(cap) && !__builtin_cheri_copy_from_high(cap)) ||
(likely(!no_hash_pointers) && *fmt != 'x')) {
/* Avoid adding prefix */
spec.flags &= ~SPECIAL;
return pointer(fmt, buf, end, (void *)cheri_address_get(cap), spec);(likely(!no_hash_pointers) && *fmt != 'x'))
- }
if (spec.flags & SPECIAL) { /* Simplified format for capabilities */ int orig_field_width = spec.field_width; -- 2.43.0