public inbox for linux-man@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] malloc_usable_size.3: Warn about _FORTIFY_SOURCE interaction
@ 2023-04-04  5:52 Mingye Wang
  2023-04-04 11:42 ` Siddhesh Poyarekar
  2023-04-05  2:41 ` Alejandro Colomar
  0 siblings, 2 replies; 6+ messages in thread
From: Mingye Wang @ 2023-04-04  5:52 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: linux-man, siddhesh

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

Hi all,

In (somewhat) recent discussions about _FORTIFY_SOURCE level 3, a
common snag to hit seems to be abuse of malloc_usable_size(). The
attached patch is my attempt at making the situation easier to sort
through.

See siddhesh's comment on GitHub.[0] I wonder if the language needs to
be stronger.
  [0]: https://github.com/systemd/systemd/issues/22801#issuecomment-1343041481

Best,
Mingye Wang (Artoria2e5)

[-- Attachment #2: 0001-malloc_usable_size.3-Warn-about-_FORTIFY_SOURCE-inte.patch --]
[-- Type: application/octet-stream, Size: 1122 bytes --]

From f061522764ec417e80622db557853c2d7493bbb7 Mon Sep 17 00:00:00 2001
From: Mingye Wang <arthur200126@gmail.com>
Date: Tue, 4 Apr 2023 13:43:39 +0800
Subject: [PATCH] malloc_usable_size.3: Warn about _FORTIFY_SOURCE interaction

Abuse of malloc_usable_size() is common enough to snap up Redhat's
trials of -D_FORTIFY_SOURCE=3.  Warn against this to ease debugging.

Signed-Off-by: Mingye Wang <arthur200126@gmail.com>
---
 man3/malloc_usable_size.3 | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/man3/malloc_usable_size.3 b/man3/malloc_usable_size.3
index 754b255de..1361e6f1e 100644
--- a/man3/malloc_usable_size.3
+++ b/man3/malloc_usable_size.3
@@ -62,5 +62,14 @@ the number of excess bytes in an allocation depends on
 the underlying implementation.
 .PP
 The main use of this function is for debugging and introspection.
+.PP
+.BR Warning :
+Some programs abuse
+.BR malloc_usable_size ()
+to reduce the number of calls to
+.BR realloc (3).
+Such use will confuse
+.BR _FORTIFY_SOURCE
+level 3, as it only keeps track of the original requested size.
 .SH SEE ALSO
 .BR malloc (3)
-- 
2.40.0.windows.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-04-05 13:14 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-04  5:52 [RFC PATCH] malloc_usable_size.3: Warn about _FORTIFY_SOURCE interaction Mingye Wang
2023-04-04 11:42 ` Siddhesh Poyarekar
2023-04-05  0:51   ` Sam James
2023-04-05  2:35   ` Alejandro Colomar
2023-04-05 12:58     ` Siddhesh Poyarekar
2023-04-05  2:41 ` Alejandro Colomar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox