Skip to contentSkip to conversation

elf: print userspace address with %lx

PATCH In review Alexey Dobriyan 2 participants 4 messages Mar 14, 2019 – Mar 16, 2019

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

PATCH 2/2 elf: print userspace address with %lx

Use %lx, save a cast.

"addr" is userspace address so using (and mangling) pointer was never necessary.

---

 fs/binfmt_elf.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/binfmt_elf.c +2 -2
@@ -376,8 +376,8 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
 		map_addr = vm_mmap(filep, addr, size, prot, type, off);
 
 	if ((type & MAP_FIXED_NOREPLACE) && map_addr == -EEXIST)
-		pr_info("%d (%s): Uhuuh, elf segment at %px requested but the memory is mapped already\n",
-			task_pid_nr(current), current->comm, (void *)addr);
+		pr_info("%d (%s): Uhuuh, elf segment at %lx requested but the memory is mapped already\n",
+			task_pid_nr(current), current->comm, addr);
 
 	return(map_addr);
 }
#1 lore raw
Quoted 4 lines · Alexey Dobriyan

Use %lx, save a cast.

"addr" is userspace address so using (and mangling) pointer was never necessary.

There shouldn't be any mangling AFAIU. Documentation for pointer() says

* - 'x' For printing the address. Equivalent to "%lx".

Quoted 20 lines

---

 fs/binfmt_elf.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/binfmt_elf.c +2 -2
@@ -376,8 +376,8 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
 		map_addr = vm_mmap(filep, addr, size, prot, type, off);
 
 	if ((type & MAP_FIXED_NOREPLACE) && map_addr == -EEXIST)
-		pr_info("%d (%s): Uhuuh, elf segment at %px requested but the memory is mapped already\n",
-			task_pid_nr(current), current->comm, (void *)addr);
+		pr_info("%d (%s): Uhuuh, elf segment at %lx requested but the memory is mapped already\n",
+			task_pid_nr(current), current->comm, addr);
 
 	return(map_addr);
 }
Signature · 2 lines
Michal Hocko
SUSE Labs
#2 lore raw
Quoted 10 lines · Michal Hocko
Quoted 4 lines · Alexey Dobriyan

Use %lx, save a cast.

"addr" is userspace address so using (and mangling) pointer was never necessary.

There shouldn't be any mangling AFAIU. Documentation for pointer() says

* - 'x' For printing the address. Equivalent to "%lx".

The implication of using %p/%px is that the address is kernel pointer which should or should not be mangled. But "map_addr" is not a kernel pointer. And it saves a cast.

Quoted 10 lines
Quoted 10 lines
fs/binfmt_elf.c +2 -2
@@ -376,8 +376,8 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
 		map_addr = vm_mmap(filep, addr, size, prot, type, off);
 
 	if ((type & MAP_FIXED_NOREPLACE) && map_addr == -EEXIST)
-		pr_info("%d (%s): Uhuuh, elf segment at %px requested but the memory is mapped already\n",
-			task_pid_nr(current), current->comm, (void *)addr);
+		pr_info("%d (%s): Uhuuh, elf segment at %lx requested but the memory is mapped already\n",
+			task_pid_nr(current), current->comm, addr);
#3 lore raw
Quoted 7 lines · Alexey Dobriyan
Quoted 6 lines · Michal Hocko
Quoted 4 lines · Alexey Dobriyan

Use %lx, save a cast.

"addr" is userspace address so using (and mangling) pointer was never necessary.

Quoted 7 lines
Quoted 4 lines

There shouldn't be any mangling AFAIU. Documentation for pointer() says

* - 'x' For printing the address. Equivalent to "%lx".

The implication of using %p/%px is that the address is kernel pointer which should or should not be mangled.

And px is not mangled AFAICS.

Quoted 1 line

But "map_addr" is not a kernel pointer.

Which should be irrelevant. It is a pointer and my understanding is that %p$FOO should be used preferably for any pointers.

Quoted 1 line

And it saves a cast.

Is this really such an improvement? Why?

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
fs/binfmt_elf.c +2 -2
@@ -376,8 +376,8 @@ static unsigned long elf_map(struct file *filep, unsigned long addr,
 		map_addr = vm_mmap(filep, addr, size, prot, type, off);
 
 	if ((type & MAP_FIXED_NOREPLACE) && map_addr == -EEXIST)
-		pr_info("%d (%s): Uhuuh, elf segment at %px requested but the memory is mapped already\n",
-			task_pid_nr(current), current->comm, (void *)addr);
+		pr_info("%d (%s): Uhuuh, elf segment at %lx requested but the memory is mapped already\n",
+			task_pid_nr(current), current->comm, addr);
Signature · 2 lines
Michal Hocko
SUSE Labs