Skip to content

Commit d8401f5

Browse files
keesJonathan Corbet
authored andcommitted
docs: deprecated.rst: Add %p to the list
Once in a while %p usage comes up, and I've needed to have a reference to point people to. Add %p details to deprecated.rst. Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/202003042301.F844A8C0EC@keescook Signed-off-by: Jonathan Corbet <[email protected]>
1 parent d442bbc commit d8401f5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

Documentation/process/deprecated.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,28 @@ the given limit of bytes to copy. This is inefficient and can lead to
109109
linear read overflows if a source string is not NUL-terminated. The
110110
safe replacement is :c:func:`strscpy`.
111111

112+
%p format specifier
113+
-------------------
114+
Traditionally, using "%p" in format strings would lead to regular address
115+
exposure flaws in dmesg, proc, sysfs, etc. Instead of leaving these to
116+
be exploitable, all "%p" uses in the kernel are being printed as a hashed
117+
value, rendering them unusable for addressing. New uses of "%p" should not
118+
be added to the kernel. For text addresses, using "%pS" is likely better,
119+
as it produces the more useful symbol name instead. For nearly everything
120+
else, just do not add "%p" at all.
121+
122+
Paraphrasing Linus's current `guidance <https://lore.kernel.org/lkml/CA+55aFwQEd_d40g4mUCSsVRZzrFPUJt74vc6PPpb675hYNXcKw@mail.gmail.com/>`_:
123+
124+
- If the hashed "%p" value is pointless, ask yourself whether the pointer
125+
itself is important. Maybe it should be removed entirely?
126+
- If you really think the true pointer value is important, why is some
127+
system state or user privilege level considered "special"? If you think
128+
you can justify it (in comments and commit log) well enough to stand
129+
up to Linus's scrutiny, maybe you can use "%px", along with making sure
130+
you have sensible permissions.
131+
132+
And finally, know that a toggle for "%p" hashing will `not be accepted <https://lore.kernel.org/lkml/CA+55aFwieC1-nAs+NFq9RTwaR8ef9hWa4MjNBWL41F-8wM49eA@mail.gmail.com/>`_.
133+
112134
Variable Length Arrays (VLAs)
113135
-----------------------------
114136
Using stack VLAs produces much worse machine code than statically

0 commit comments

Comments
 (0)