All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Cc: Kees Cook <kees@kernel.org>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Bill Wendling <morbo@google.com>,
	Justin Stitt <justinstitt@google.com>,
	David Laight <david.laight@aculab.com>,
	linux-hardening@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] fortify: turn strlen() into an inline function using __builtin_constant_p()
Date: Sat, 11 Jan 2025 16:58:44 +0000	[thread overview]
Message-ID: <20250111165844.6d95600f@pumpkin> (raw)
In-Reply-To: <CAMZ6RqJbinVpsGf6ADUtQTYPRRQN=D8Ne_n6pHtDUPXxED5ZvQ@mail.gmail.com>

On Sat, 11 Jan 2025 23:40:41 +0900
Vincent Mailhol <mailhol.vincent@wanadoo.fr> wrote:

> On Thu. 9 Jan 2025 at 16:52, Vincent Mailhol <mailhol.vincent@wanadoo.fr> wrote:
...
> Actually, I did more investigation and it is working for some strange
> reasons. Whenever the argument of a function named strlen() is a
> compile time constant, the compiler (both GCC and clang) will replace
> it with the string length on the argument, even if strlen() is
> programmed to return something else:
> 
>   https://godbolt.org/z/nK4b3fnM7
> 
> So it is only working because the compiler uses its builtin strlen()
> instead of the function we provided.

It depends on whether -ffreestanding is set.
If not set gcc/clang assume a lot of the basic libc functions have their expected
behaviour.

	David

  reply	other threads:[~2025-01-11 16:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-08 14:27 [PATCH] fortify: turn strlen() into an inline function using __builtin_constant_p() Vincent Mailhol
2025-01-08 21:46 ` Kees Cook
2025-01-09  7:52   ` Vincent Mailhol
2025-01-11 14:40     ` Vincent Mailhol
2025-01-11 16:58       ` David Laight [this message]
2025-01-11 18:05         ` Vincent Mailhol
2025-01-09 14:14 ` kernel test robot
2025-01-11  2:13 ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250111165844.6d95600f@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=david.laight@aculab.com \
    --cc=justinstitt@google.com \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=morbo@google.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.