From: Sergey Bugaev <bugaevc@gmail.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [RFC PATCH 1/1] io: Add FORTIFY_SOURCE check for fcntl arguments
Date: Wed, 24 May 2023 13:51:15 +0300 [thread overview]
Message-ID: <CAN9u=HfZn5Ld2W1LfFAWUshcRr=ZxE_MBjHkwkQSkkKaD+rcPg@mail.gmail.com> (raw)
In-Reply-To: <87fs7myvxm.fsf@oldenburg.str.redhat.com>
On Wed, May 24, 2023 at 11:29 AM Florian Weimer <fweimer@redhat.com> wrote:>
> I'm attaching my broken patch. It's based on commit ef4f97648dc9584
> (from 2016).
Thank you, that's helpful.
A couple more issues with your patch (I understand that it's WIP and broken):
1. You're doing
int __fcntl_chk (int, int, ...);
int __REDIRECT (__fcntl_int, (int, int, int __arg), __fcntl_chk);
This is not OK, the ABI may be different between vararg- and
non-vararg functions.
2. It doesn't do the runtime check if called with 2 args and non-c-t-const cmd.
> IIRC, it doesn't quite work because __builtin_choose_expression only
> suppresses errors, but not warnings, in the branch that wasn't chosen. 8-(
>
> Maybe this is something that could be fixed with _Generic, using
> __builtin_choose_expression for the __fcntl_is_void check only.
Yes -- I've sketched something up using _Generic and it appears to
work great: https://godbolt.org/z/8zdzo3T5Y
It does do preprocessor trickery ("friendship ended with
__builtin_va_arg_pack_len, now __VA_OPT__ is my best friend") and does
not use __builtin_choose_expr at all, so should be C++-compatible too
(try with -xc++).
This, too, is obviously a prototype, and does not do runtime _2
checking nor 64-bit handling and so on.
What do you think? Is this direction worth pursuing?
Sergey
next prev parent reply other threads:[~2023-05-24 10:51 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
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 [this message]
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=HfZn5Ld2W1LfFAWUshcRr=ZxE_MBjHkwkQSkkKaD+rcPg@mail.gmail.com' \
--to=bugaevc@gmail.com \
--cc=fweimer@redhat.com \
--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).