From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E839539518AA; Tue, 6 Oct 2020 13:04:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E839539518AA From: "dmalcolm at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/94527] RFE: Add an __attribute__ that marks a function as freeing an object Date: Tue, 06 Oct 2020 13:04:53 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: dmalcolm at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: msebor at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.0 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Oct 2020 13:04:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94527 David Malcolm changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |dmalcolm at gcc dot gnu.org --- Comment #9 from David Malcolm --- 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 <=3D 5.3.11 in drivers/net/wireless/ath/ath10k/usb.c, but I r= an 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 lea= k.=20 (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 scal= e; 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 o= ther 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]=