From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21503 invoked by alias); 23 May 2014 13:08:20 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 21443 invoked by uid 48); 23 May 2014 13:08:16 -0000 From: "kcc at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug sanitizer/61293] New: asan can not find left buffer overflow of new[]-allocated buffer, frontend help needed Date: Fri, 23 May 2014 13:08:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: sanitizer X-Bugzilla-Version: 4.10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: kcc at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-05/txt/msg02078.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61293 Bug ID: 61293 Summary: asan can not find left buffer overflow of new[]-allocated buffer, frontend help needed Product: gcc Version: 4.10.0 Status: UNCONFIRMED Severity: enhancement Priority: P3 Component: sanitizer Assignee: unassigned at gcc dot gnu.org Reporter: kcc at gcc dot gnu.org CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org, jakub at gcc dot gnu.org, kcc at gcc dot gnu.org, timurrrr at google dot com asan does not detect the following case: TypeWithDtor *a = new TypeWithDtor[N]; a[-1] = ... https://code.google.com/p/address-sanitizer/issues/detail?id=314 That's because when we have new[] for a type with DTORs, the actual allocated size is greater. The code looks something like this: extra = max(sizeof(long), alignment_of(TypeWithDtor)); ptr = malloc(N + extra); *(long*)(ptr+extra-sizeof(long)) = N; return ptr + extra; // must be properly aligned for TypeWithDtor As the result, we will not detect overwrites of new[] cookie -- scary! I don't see how we can implement this w/o help from FE. First, we need to ensure alignment 8 even on 32-bits: extra = max(8, alignment_of(TypeWithDtor)); Second, we need to poison the first extra bytes. Lastly, we need to not instrument the legitimate loads/stores of the cookie generated by the frontend. All of this has to be done with the help from FE