From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vibhav Pant Newsgroups: gmane.emacs.devel Subject: feature/asan-gc-poisoning: Better memory checks using AddressSanitizer Date: Tue, 6 Dec 2022 02:05:36 +0530 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39073"; mail-complaints-to="usenet@ciao.gmane.io" To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Dec 05 21:36:43 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p2ICf-0009zY-Ed for ged-emacs-devel@m.gmane-mx.org; Mon, 05 Dec 2022 21:36:41 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p2IBx-0007V3-NY; Mon, 05 Dec 2022 15:35:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p2IBs-0007Uj-Ib for emacs-devel@gnu.org; Mon, 05 Dec 2022 15:35:52 -0500 Original-Received: from mail-qv1-xf32.google.com ([2607:f8b0:4864:20::f32]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p2IBr-0003dN-2x for emacs-devel@gnu.org; Mon, 05 Dec 2022 15:35:52 -0500 Original-Received: by mail-qv1-xf32.google.com with SMTP id h10so9041479qvq.7 for ; Mon, 05 Dec 2022 12:35:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=ek4XSogwvjpjwYCckMzX/owj/4DQFyq20Q1axpEe4go=; b=NJ0FBfWlbPqWvwBYVAeZEnUf4uo40o2fjuPEjcDVTrv8TkDXSEzptG/1+gSMMhx1Gz mnC38ZEJOa5r3JRU2eVrcCffsBu5tKuUWBwR4i1tml3H2KHiKHJJHuFDySWYPZeoSXTp t2UvnezUaw6x7dsVSfaEkv3bJUDw0s7DXjlnWZ9eiB+M3WWT9vwqQdDLGJThNDsnNokQ BOI4PNxR3y9Bclp8ST1BYOreDZNns8INlrZbIWWSWsngBxwfVgTj2vMEO979rFHN+Eyc A+i6o/cxAGYe9tfD6WUv1AIhz00iFbWGcmpTeTpzfl6rE+/iWieUUs0WLGTAPd385Xo3 kyHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ek4XSogwvjpjwYCckMzX/owj/4DQFyq20Q1axpEe4go=; b=0h2mgMS6e09HPN5aTK8VOP2RykjjVOanbgs425qbCFUC+AEuEK/1HOm0Noigd22R+y J8+XT49LeD4A2+769BtbEi44zG1ZW8W1NPacvcyIjWuLpn0PX2vU7voZUM7p+WN/KTIB nGjcY0l7DLnrpu0/SOg0IsEFraxKIzq+u3780wlHfluztG9czWuTEEVz79eKZHwI7Ao8 KHmngyjAJns1BW31mUGa77lveH6tfFjX0AChLwFuaK0ki29PfUpquAqm5JhLotpJozng 1SLDbsmhJuz3JJQ41PCllGw6H9iWaiukRyhyYub4Pj7Ngy7GiVyHisC5GW2Dv0Wun8BZ U0ew== X-Gm-Message-State: ANoB5pmLW3WH34W1v479jOB7LGcPXOnViN9q4GOqsPuY8o2QafhPHYjq ISsY/MGPyOcOGZzh3fK7Vg4fr4bZVQuPcqWBXKW7tkGRAoWiLQ== X-Google-Smtp-Source: AA0mqf69KfyUSatVtkTUQpUJxdNO50/MkAxhZyIBeegyF1QLfoMKdvmoMsWdzfy51+rwqDtEkH4DhzEuPNhHQuwPAlo= X-Received: by 2002:a0c:ef0b:0:b0:4c6:e904:3582 with SMTP id t11-20020a0cef0b000000b004c6e9043582mr42682217qvr.112.1670272549305; Mon, 05 Dec 2022 12:35:49 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::f32; envelope-from=vibhavp@gmail.com; helo=mail-qv1-xf32.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:300939 Archived-At: As part of trying to debug the deluge of GC borks in scratch/comp-static-data, I took a slight detour through Emacs' memory management code and the sanity checks that it optionally comes with. The changes in feature/asan-gc-poisoning attempt to augment the latter, specifically when Emacs is built with '-fsanitize=address'. When enabled, almost all memory management operations are instrumented with calls to ASan's "(un)poisoning" functions, which allow ASan to mark allocated but not freed addresses as "poisoned", triggering errors whenever they have been accessed. The idea behind this is to add another layer of checks against code that makes use of free lists and arena based allocators, only allowing access to regions of the memory that are actually intended to be accessible (aka "unpoisoned" in ASan parlance) by non alloc-related C code. An instance of this is any object on a free list, or a vectorlike with the type PVEC_FREE (we do abort whenever we come across such a vector, but this ideally catches the bug way earlier in the flow, and therefore closer to the source of the actual problem). Additional documentation explaining this feature is available both on src/alloc.c and the "Running Emacs with address sanitization" section in etc/DEBUG. The branch bootstraps successfully both with native-comp enabled and disabled, and passes everything on the test suite on my machine. Because enabling Address Sanitizer comes with a significant performance + memory overhead, using it as a daily driver isn't without a decent bit of sluggishness, although building with -O2 and native compilation seems to help, at least a little. I plan to get install this in `master` soon, so both feedback and testing from other users would be greatly appreciated. The current codebase quite likely does everything alloc related correctly, so an ASan error might be indicative of a snag in this branch instead of Emacs itself (fingers crossed for the opposite, however :)). Thanks, Vibhav -- Vibhav Pant vibhavp@gmail.com GPG: 7ED1 D48C 513C A024 BE3A 785F E3FB 28CB 6AB5 9598