From: David Malcolm <dmalcolm@redhat.com>
To: Mir Immad <mirimnan017@gmail.com>, Florian Weimer <fweimer@redhat.com>
Cc: Szabolcs Nagy via Gcc <gcc@gcc.gnu.org>,
Szabolcs Nagy <szabolcs.nagy@arm.com>,
libc-alpha@sourceware.org
Subject: Re: Adding file descriptor attribute(s) to gcc and glibc
Date: Wed, 13 Jul 2022 15:29:18 -0400 [thread overview]
Message-ID: <08c32347c4b433645875eb9ec283d72f915ab3d6.camel@redhat.com> (raw)
In-Reply-To: <CAE1-7ow+wScZLkXjJGbZC2_-s4jMpS_nF8ef7UnVaiHqJQ=X=g@mail.gmail.com>
On Wed, 2022-07-13 at 22:26 +0530, Mir Immad wrote:
> Hi everyone,
>
> Reading through the thread, I feel the following attributes look good
> and
> similar to what I've done:
>
> __attribute__ ((fd_arg(N)))
> __attribute__ ((fd_arg_read(N)))
> __attribute__ ((fd_arg_write(N)))
>
> I believe how to annotate the glibc headers is a separate discussion.
>
> Dave: From the GCC side of things, these three attributes are basic
> functionalities that can be useful for any piece of code that passes
> around
> file descriptors.
Immad: sounds good. Please use the above names/syntax for the next
iteration of your patch to -fanalyzer.
Thanks!
Dave
>
> Thanks
> Immad
>
>
> On Wed, Jul 13, 2022 at 7:31 PM Florian Weimer <fweimer@redhat.com>
> wrote:
>
> > * David Malcolm:
> >
> > > On Wed, 2022-07-13 at 14:05 +0200, Florian Weimer wrote:
> > > > * Szabolcs Nagy via Gcc:
> > >
> > > [adding Immad back to the CC list]
> > >
> > > >
> > > > > to be honest, i'd expect interesting fd bugs to be
> > > > > dynamic and not easy to statically analyze.
> > > > > the use-after-unchecked-open maybe useful. i would
> > > > > not expect the access direction to catch many bugs.
> > > >
> > > > You might be right. But I think the annotations could help to
> > > > catch
> > > > use-after-close errors.
> > > >
> > > > By the way, I think it would help us if we didn't have to
> > > > special-
> > > > case
> > > > AT_FDCWD using inline wrappers.
> > >
> > > Florian: I confess I wasn't familiar with AT_FDCWD until I read
> > > your
> > > email and did a little reading a few minutes ago; it seems to be
> > > a
> > > "magic number" for an FD that has special meaning; on my system
> > > it has
> > > the value -100.
> > >
> > > GCC's current implementation of the various -Wanalyzer-fd-*
> > > warnings
> > > will track state for constant integer values as well as symbolic
> > > values; it doesn't have any special meanings for specific integer
> > > values. So e.g. it doesn't assume that 0, 1, and 2 have specific
> > > meaning or are opened with specific flags (the analysis doesn't
> > > necessarily begin its execution path at the start of "main", so
> > > there's
> > > no guarantee that the standard FDs have their standard meaning).
> >
> > Ahh. It might be useful to detect close (-1) etc. as a form of
> > double-close, and ther AT_FDCWD is exceptional.
> >
> > > Presumably if someone attempts
> > > close (AT_FDCWD);
> > > they'll get -1 and errno set to EBADFD, right?
> >
> > Correct
> >
> > > I don't think GCC's -fanalyzer needs to check for that.
> >
> > Not sure …
> >
> > > -fanalyzer's filedescriptor support doesn't yet have a concept of
> > > "directory filedescriptors". Should it? (similarly, it doesn't
> > > yet
> > > know about sockets)
> > >
> > > A possible way to annotate "openat":
> > >
> > > int openat(int dirfd, const char *pathname, int flags)
> > > __attr_fd_arg(1);
> >
> > openat is not the most general interface in this regard. We have
> > other
> > *at functions which accept an O_PATH descriptor (or maybe even a
> > different kind of non-directory descriptor) with pathname == "" and
> > AT_EMPTY_PATH. I'm not sure if modeling all this is beneficial.
> >
> > Thanks,
> > Florian
> >
> >
next prev parent reply other threads:[~2022-07-13 19:29 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-12 17:31 [PATCH] filedescriptor attribute Immad Mir
2022-07-12 17:33 ` Mir Immad
2022-07-12 22:16 ` Adding file descriptor attribute(s) to gcc and glibc David Malcolm
2022-07-12 22:25 ` David Malcolm
2022-07-13 8:37 ` Szabolcs Nagy
2022-07-13 8:46 ` Andreas Schwab
2022-07-13 12:05 ` Florian Weimer
2022-07-13 13:33 ` David Malcolm
2022-07-13 14:01 ` Florian Weimer
2022-07-13 16:55 ` David Malcolm
2022-07-14 8:30 ` Szabolcs Nagy
2022-07-14 15:22 ` David Malcolm
2022-07-14 17:07 ` Paul Eggert
2022-07-13 16:56 ` Mir Immad
2022-07-13 19:29 ` David Malcolm [this message]
2022-07-13 12:57 ` David Malcolm
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=08c32347c4b433645875eb9ec283d72f915ab3d6.camel@redhat.com \
--to=dmalcolm@redhat.com \
--cc=fweimer@redhat.com \
--cc=gcc@gcc.gnu.org \
--cc=libc-alpha@sourceware.org \
--cc=mirimnan017@gmail.com \
--cc=szabolcs.nagy@arm.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 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).