https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94527

David Malcolm <dmalcolm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmalcolm at gcc dot gnu.org

--- Comment #9 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
I hadn't seen this bug, but I've just posted:

  "[PATCH] RFC: add "deallocated_by" attribute for use by analyzer"
  https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555544.html

which does some of the things requested in this RFE, but purely within
-fanalyzer.  -fanalyzer is read-only w.r.t. GCC's internal representation, i.e.
it doesn't affect optimizations such as DSE.  Though I suppose the same
attribute could also be handled by optimization passes.

That patch has some big limitations, as I noted.  I attempted to use this to
mark up:

  extern struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags);
  extern void usb_free_urb(struct urb *urb);

as an acquire/release pair via:

  #define __deallocated_by(f)      __attribute__((deallocated_by(f)));

  extern struct urb *usb_alloc_urb(int iso_packets, gfp_t mem_flags)
      __deallocated_by(usb_free_urb);

in order to detect CVE-2019-19078, a leak of struct urb in an error-handling
path in linux <= 5.3.11 in drivers/net/wireless/ath/ath10k/usb.c, but I ran
into issues where, without LTO, the analyzer knows nothing about calls to:
  usb_fill_bulk_urb
  usb_anchor_urb
  usb_unanchor_urb
that occur along that path, and so it conservatively assumes it doesn't leak. 
(Caveat: I know nothing about those calls either; I'm a user-space developer
with little knowledge of linux internals).  I can get -fanalyzer to emit a leak
warning on that code path with that patch if I hack out those calls.

[To set expectations: I should mention that my initial implementation of
-fanalyzer in gcc 10 had some major design flaws that mean it couldn't scale;
I've fixed those flaws for gcc 11, and am working hard on scaling it up to be
usable on real-world C when gcc 11 ships, but I don't feel it's there yet.  In
particular, I don't expect the current version in git to be usable with LTO
other than on toy examples without some more fixes.  The -fanalyzer option has
found some bugs, including at least one CVE, but I don't recommend it yet other
than to adventurous early adopters.   As I said, I hope to have it in much
better shape when GCC 11 actually ships in about 6 months time]

Reply via email to