From: Nick Desaulniers <ndesaulniers@google.com>
To: Kees Cook <keescook@chromium.org>
Cc: Miguel Ojeda <ojeda@kernel.org>,
Nathan Chancellor <nathan@kernel.org>,
llvm@lists.linux.dev, George Burgess IV <gbiv@google.com>,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH v6 2/4] Compiler Attributes: Add __overloadable for Clang
Date: Thu, 3 Feb 2022 16:58:58 -0800 [thread overview]
Message-ID: <CAKwvOdnZJckq7svQfKTQUteDG9RozeCXAi8OtTnJsTifiLTnbQ@mail.gmail.com> (raw)
In-Reply-To: <202202031618.BC9EDA9D82@keescook>
On Thu, Feb 3, 2022 at 4:26 PM Kees Cook <keescook@chromium.org> wrote:
>
> On Thu, Feb 03, 2022 at 02:11:48PM -0800, Nick Desaulniers wrote:
> > On Thu, Feb 3, 2022 at 1:04 PM Kees Cook <keescook@chromium.org> wrote:
> > >
> > > On Thu, Feb 03, 2022 at 12:26:15PM -0800, Nick Desaulniers wrote:
> > > > On Thu, Feb 3, 2022 at 9:33 AM Kees Cook <keescook@chromium.org> wrote:
> > > > >
> > > > > must be marked as being overloadable (i.e. different prototypes).
> > > > > This allows the __pass_object_size versions to take precedence.
> > > >
> > > > Is this because of the `const` additions to the function signatures?
> > >
> > > That might be an issue, but the *real* issue is the implicit mutation of
> > > the function into an inline with _additional_ arguments. i.e.
> > >
> > > char *strcpy(char * POS p, const char * POS q)
> > >
> > > is really
> > >
> > > char *strcpy(char * const p, const char * const q, size_t __size_of_p, size_t __size_of_q)
> > >
> > > (i.e. what I was doing with macros, but all internally and still an
> > > extern inline)
> >
> > What do you mean "is really"? 4/4 doesn't change the number of
> > parameters in strcpy explicitly in the definition AFAICT.
>
> It really does change the number of parameters. See the IR difference:
>
> $ cat example.c
> #ifdef USE_POS
> # define POS __attribute__((pass_object_size(1)))
> #else
> # define POS
> #endif
>
> int func(void * const POS);
>
> struct foo
> {
> int a;
> char *b;
> };
>
> void usage(struct foo *example)
> {
> func(example);
> }
>
> $ IR="-O2 -Xclang -disable-llvm-passes -emit-llvm -S"
> $ clang example.c $IR -o normal.ll
> $ clang -DUSE_POS example.c $IR -o pos.ll
> $ diff -u normal.ll pos.ll
> --- normal.ll 2022-02-03 16:23:39.734065036 -0800
> +++ pos.ll 2022-02-03 16:23:49.518083451 -0800
> @@ -11,14 +11,19 @@
> store %struct.foo* %0, %struct.foo** %2, align 8, !tbaa !3
> %3 = load %struct.foo*, %struct.foo** %2, align 8, !tbaa !3
> %4 = bitcast %struct.foo* %3 to i8*
> - %5 = call i32 @func(i8* noundef %4)
> + %5 = call i64 @llvm.objectsize.i64.p0i8(i8* %4, i1 false, i1 true, i1 false)
> + %6 = call i32 @func(i8* noundef %4, i64 noundef %5)
> ret void
> }
> ...
Woah, that's fancy.
>
> This is basically doing internally exactly what I was doing in v4 and
> earlier with macros (passing in the caller's view of __bos(arg, 1)).
Yeah. Ok now it all makes sense to me.
With the s/inline extern/extern inline/:
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
--
Thanks,
~Nick Desaulniers
next prev parent reply other threads:[~2022-02-04 0:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-03 17:33 [PATCH v6 0/4] fortify: Add Clang support Kees Cook
2022-02-03 17:33 ` [PATCH v6 1/4] Compiler Attributes: Add __pass_object_size for Clang Kees Cook
2022-02-03 20:18 ` Nick Desaulniers
2022-02-03 20:58 ` Kees Cook
2022-02-03 22:01 ` Nick Desaulniers
2022-02-04 0:29 ` Kees Cook
2022-02-03 17:33 ` [PATCH v6 2/4] Compiler Attributes: Add __overloadable " Kees Cook
2022-02-03 20:26 ` Nick Desaulniers
2022-02-03 21:04 ` Kees Cook
2022-02-03 22:11 ` Nick Desaulniers
2022-02-04 0:26 ` Kees Cook
2022-02-04 0:58 ` Nick Desaulniers [this message]
2022-02-04 1:07 ` Miguel Ojeda
2022-02-03 17:33 ` [PATCH v6 3/4] Compiler Attributes: Add __diagnose_as " Kees Cook
2022-02-03 20:28 ` Nick Desaulniers
2022-02-03 17:33 ` [PATCH v6 4/4] fortify: Add Clang support Kees Cook
2022-02-03 20:37 ` Nick Desaulniers
2022-02-03 21:26 ` Kees Cook
2022-02-03 17:47 ` [PATCH v6 0/4] " Miguel Ojeda
2022-02-03 19:57 ` Kees Cook
2022-02-03 21:12 ` Miguel Ojeda
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=CAKwvOdnZJckq7svQfKTQUteDG9RozeCXAi8OtTnJsTifiLTnbQ@mail.gmail.com \
--to=ndesaulniers@google.com \
--cc=gbiv@google.com \
--cc=keescook@chromium.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=llvm@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=ojeda@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).