From: David Malcolm <dmalcolm@redhat.com>
To: Szabolcs Nagy <szabolcs.nagy@arm.com>
Cc: Florian Weimer <fweimer@redhat.com>,
Szabolcs Nagy via Gcc <gcc@gcc.gnu.org>,
libc-alpha@sourceware.org, Mir Immad <mirimnan017@gmail.com>
Subject: Re: Adding file descriptor attribute(s) to gcc and glibc
Date: Thu, 14 Jul 2022 11:22:09 -0400 [thread overview]
Message-ID: <159ec66633a19d8b5cf038f45630e2e8ca8d6b6c.camel@redhat.com> (raw)
In-Reply-To: <Ys/UKN3/TBGM/M73@arm.com>
On Thu, 2022-07-14 at 09:30 +0100, Szabolcs Nagy wrote:
> The 07/13/2022 12:55, David Malcolm wrote:
> > On Wed, 2022-07-13 at 16:01 +0200, Florian Weimer wrote:
> > > * David Malcolm:
> > GCC trunk's -fanalyzer implements the new warnings via a state
> > machine
> > for file-descriptor values; it currently has rules for handling
> > "open",
> > "close", "read", and "write", and these functions are currently hard-
> > coded inside the analyzer.
> >
> > Here are some examples on Compiler Explorer of what it can/cannot
> > detect:
> > https://godbolt.org/z/nqPadvM4f
> >
> > Probably the most important one IMHO is the leak detection.
>
> nice.
>
> > Would it be helpful to have some kind of attribute for "returns a new
> > open FD"? Are there other ways to close a FD other than calling
> > "close" on it? (Would converting that to some kind of "closes"
> > attribute be a good idea?)
Thanks, lots of good ideas here; I've filed various RFEs about these;
I'm posting the details below for reference.
>
> dup2(oldfd, newfd)
> dup3(oldfd, newfd, flags)
>
> closes newfd (and also opens it to be a dup of oldfd)
> unless the call fails.
dup and friends probably need special-casing; I've filed this as:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106298
>
> close_range(first, last, flags)
close_range and closefrom would need special-casing, already filed as:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106283
>
> fclose(fdopen(fd, mode))
The analyzer now attempts to track both file descriptors and stdio
streams, so we probably need to special-case fdopen to capture the
various possible interactions between these two leak detectors; I've
filed this as:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106299
with an implementation idea there.
>
> but users can write all sorts of wrappers around close too.
Yeah. If the -fanalyzer leak detectors see a value "escape" into
unknown code, then they don't report leaks; see e.g.:
https://godbolt.org/z/n8fMhGTP5
where we don't report in test_2 about fd leaking due to the call to:
might_close (fd);
which is extern, and so we conservatively assume that fd doesn't leak.
>
> >
> > Are there any other "magic" values for file-descriptors we should be
> > aware of?
> >
>
> mmap may require fd==-1 for anonymous maps.
mmap is its own can of worms, which I've filed as:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106301
You also reminded me that we need to track other ways in which the user
could obtain an fd that could leak, which I've filed as:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106300
(covering creat, pipe and friends, dup and friends, fcntl, and socket).
I've added all of these to the top-level RFE for -fanalyzer tracking
file descriptors:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=analyzer-fd
which is now a tracker-bug:
https://gcc.gnu.org/bugzilla/showdependencytree.cgi?id=analyzer-fd
Thanks again for the ideas
Dave
next prev parent reply other threads:[~2022-07-14 15:22 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 [this message]
2022-07-14 17:07 ` Paul Eggert
2022-07-13 16:56 ` Mir Immad
2022-07-13 19:29 ` David Malcolm
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=159ec66633a19d8b5cf038f45630e2e8ca8d6b6c.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).