public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Sergey Bugaev <bugaevc@gmail.com>
To: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Cc: libc-alpha@sourceware.org
Subject: Re: [RFC PATCH 1/1] io: Add FORTIFY_SOURCE check for fcntl arguments
Date: Tue, 23 May 2023 22:43:34 +0300	[thread overview]
Message-ID: <CAN9u=Hc5UBFuuq_uY-OK+y1RVA30McD_Kxw62XRV2z9E041r7g@mail.gmail.com> (raw)
In-Reply-To: <0b512019-09ab-9f25-57d6-cf6fd19be8f3@linaro.org>

On Tue, May 23, 2023 at 10:09 PM Adhemerval Zanella Netto
<adhemerval.zanella@linaro.org> wrote:
> > +# ifndef __USE_FILE_OFFSET64
> > +/* Just fcntl ().  */
>
> Does this comment adds anything?  Also I think we avoid to use '()' on function
> definition on comments.

These comments were mainly for myself to keep track of the various
possible configurations -- I decided to leave them in since the reader
of the code might get a little overwhelmed by the combinatorial
explosion of the possible configuration variants as well.

I can remove these comments (or just this one?) if you would prefer that.

> > +__extern_always_inline int
>
> Should we use  __fortify_function also for this case?

I think __fortify_function is supposed to be used on the replacement
functions themselves, not their helpers? if that's not the case, sure.

> > +#ifdef __F_GETOWN_EX
> > +    case __F_GETOWN_EX:
> > +    case __F_SETOWN_EX:
> > +    case __F_SETSIG:
> > +#endif
>
> I think it would be better to condicionalize using __USE_GNU:
>
> #ifdef __USE_GNU
>     case F_GETOWN_EX:
>     case F_SETOWN_EX:
>     case F_SETSIG:
> #endif
>
> Since the double underscore symbols are implementation defined one and should
> not be used by the application.

But that would break on the Hurd, no?

I could do #ifdef F_GETOWN_EX (without the double underscore), but I
wanted to handle __F_GETOWN_EX etc. even if the user has not enabled
them (better handle them than not). In other words, this ifdef is
meant to check for Hurd vs Linux, not for __USE_GNU vs not.

> Should be worried that since we don't have const expressions like newer C++
> that large switch might ended being extra code on every fcntl call? I think
> the __builtin_constant_p check below gives compiler enough information to
> avoid it, but I am not sure.

Yes, __builtin_constant_p is, AFAIK, some compiler magic that
"guarantees" (quoted since I'm not sure if it's actually guaranteed,
but I've never seen it behave otherwise) that in the true branch the
value is treated as a compile-time constant.

In practice (see what the tst-fortify compiles to!), with -O2 this
whole thing is fully optimized away, and the generated code contains
the very same calls to fcntl (or fcntl64, or whatever) that it would
if there never was any fortification -- except you get compile-time
errors if you forget the argument when it's required. So there's zero
run-time cost.

If the cmd argument is a c-t const, that is -- otherwise it calls the
_2 versions and does the check at runtime, yes. But that's only extra
code (as in code size) once, in glibc, not at the call sites.

> > +      if (__fcntl_cmd_needs_arg (__cmd) && __va_arg_pack_len () < 1)
>
> No implicit check for function that do not return bool:
>
>   if (__fcntl_cmd_needs_arg (__cmd) == 1 ...)

Why? Is it just a code style thing?

> I think we need also to handle __USE_TIME_BITS64 and add another fcntl debug
> symbol to handle; even though for Linux now __fcntl_time64 is just a alias
> to __libc_fcntl64.
>
> It is because we even need to add a proper __fcntl_time64 implementation,
> the redirection now does:
>
>   fcntl -> __fcntl64_2 -> __libc_fcntl64
>
> Where it should be something like:
>
>   fcntl -> __fcntl_time64_2 -> __fcntl_time64

The idea here was that the 2-argument version of fcntl clearly does
not deal with time, either 32- or 64-bit...

Sergey

  reply	other threads:[~2023-05-23 19:43 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-19 21:30 [RFC PATCH 0/1] Attempt to detect missing fcntl argument at compile time Sergey Bugaev
2023-05-19 21:30 ` [RFC PATCH 1/1] io: Add FORTIFY_SOURCE check for fcntl arguments Sergey Bugaev
2023-05-19 21:55   ` Joseph Myers
2023-05-20 11:46     ` Sergey Bugaev
2023-05-20 18:21       ` [RFC PATCH] debug: Add tests for fortified fcntl () Sergey Bugaev
2023-05-23 18:40         ` Adhemerval Zanella Netto
2023-05-23 19:19           ` Sergey Bugaev
2023-05-23 19:48             ` Adhemerval Zanella Netto
2023-05-24  7:15               ` Sergey Bugaev
2023-05-24 12:15                 ` Adhemerval Zanella Netto
2023-05-23 19:09   ` [RFC PATCH 1/1] io: Add FORTIFY_SOURCE check for fcntl arguments Adhemerval Zanella Netto
2023-05-23 19:43     ` Sergey Bugaev [this message]
2023-05-23 19:56       ` Adhemerval Zanella Netto
2023-05-23 20:24         ` Sergey Bugaev
2023-05-23 20:44           ` Sergey Bugaev
2023-05-24 12:04           ` Adhemerval Zanella Netto
2023-05-23 19:15   ` Siddhesh Poyarekar
2023-05-23 20:01     ` Sergey Bugaev
2023-05-23 20:06       ` Sergey Bugaev
2023-05-23 21:46   ` Florian Weimer
2023-05-24  7:31     ` Sergey Bugaev
2023-05-24  8:29       ` Florian Weimer
2023-05-24 10:51         ` Sergey Bugaev
2023-05-24 11:18           ` Florian Weimer
2023-05-24 11:46             ` Siddhesh Poyarekar
2023-05-24 12:12               ` Andreas Schwab
2023-05-24 12:18                 ` Florian Weimer
2023-05-24 12:37                   ` Sergey Bugaev
2023-05-24 12:45                     ` Florian Weimer
2023-05-24 13:02                       ` Sergey Bugaev
2023-05-24 13:18                         ` Florian Weimer

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='CAN9u=Hc5UBFuuq_uY-OK+y1RVA30McD_Kxw62XRV2z9E041r7g@mail.gmail.com' \
    --to=bugaevc@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=libc-alpha@sourceware.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 read-only IMAP folder(s) and NNTP newsgroup(s).