get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/110612/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 110612,
    "url": "http://patchwork.dpdk.org/api/patches/110612/?format=api",
    "web_url": "http://patchwork.dpdk.org/project/dpdk/patch/54f5fe8c3e8ba5412dc34bace1409c44efd6035a.1651674707.git.anatoly.burakov@intel.com/",
    "project": {
        "id": 1,
        "url": "http://patchwork.dpdk.org/api/projects/1/?format=api",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk",
        "list_archive_url": "https://inbox.dpdk.org/dev",
        "list_archive_url_format": "https://inbox.dpdk.org/dev/{}",
        "commit_url_format": ""
    },
    "msgid": "<54f5fe8c3e8ba5412dc34bace1409c44efd6035a.1651674707.git.anatoly.burakov@intel.com>",
    "list_archive_url": "https://inbox.dpdk.org/dev/54f5fe8c3e8ba5412dc34bace1409c44efd6035a.1651674707.git.anatoly.burakov@intel.com",
    "date": "2022-05-04T14:31:58",
    "name": "[v2,1/1] malloc: fix ASan handling for unmapped memory",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": true,
    "hash": "037d1259e8fea229674d1b6e02ca044c09a6d9a0",
    "submitter": {
        "id": 4,
        "url": "http://patchwork.dpdk.org/api/people/4/?format=api",
        "name": "Burakov, Anatoly",
        "email": "anatoly.burakov@intel.com"
    },
    "delegate": {
        "id": 24651,
        "url": "http://patchwork.dpdk.org/api/users/24651/?format=api",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": "david.marchand@redhat.com"
    },
    "mbox": "http://patchwork.dpdk.org/project/dpdk/patch/54f5fe8c3e8ba5412dc34bace1409c44efd6035a.1651674707.git.anatoly.burakov@intel.com/mbox/",
    "series": [
        {
            "id": 22775,
            "url": "http://patchwork.dpdk.org/api/series/22775/?format=api",
            "web_url": "http://patchwork.dpdk.org/project/dpdk/list/?series=22775",
            "date": "2022-05-04T14:31:58",
            "name": "[v2,1/1] malloc: fix ASan handling for unmapped memory",
            "version": 2,
            "mbox": "http://patchwork.dpdk.org/series/22775/mbox/"
        }
    ],
    "comments": "http://patchwork.dpdk.org/api/patches/110612/comments/",
    "check": "success",
    "checks": "http://patchwork.dpdk.org/api/patches/110612/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<dev-bounces@dpdk.org>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Received": [
            "from mails.dpdk.org (mails.dpdk.org [217.70.189.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 2C5E5A04FF;\n\tWed,  4 May 2022 16:32:05 +0200 (CEST)",
            "from [217.70.189.124] (localhost [127.0.0.1])\n\tby mails.dpdk.org (Postfix) with ESMTP id C416B40E2D;\n\tWed,  4 May 2022 16:32:04 +0200 (CEST)",
            "from mga14.intel.com (mga14.intel.com [192.55.52.115])\n by mails.dpdk.org (Postfix) with ESMTP id 0C5B94069F;\n Wed,  4 May 2022 16:32:02 +0200 (CEST)",
            "from orsmga004.jf.intel.com ([10.7.209.38])\n by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 04 May 2022 07:32:02 -0700",
            "from silpixa00401191.ir.intel.com ([10.55.128.75])\n by orsmga004.jf.intel.com with ESMTP; 04 May 2022 07:32:00 -0700"
        ],
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1651674723; x=1683210723;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=3pinGzk0JzeBaWVTW5Px43HgRprhJdLpmTKXH1jlwT0=;\n b=JjwnsAT/QFId4vzNaw4nLs4sK0A/ZA7O/FFsVcFFy2SIdCq00qpdaKO9\n tZSjehYmfqtzCfdQTciGW+Hv6JUGvrAZhdfGlUJHk/tGdyMyqI6hMR8yP\n upiQ/J2jM/KmnYsgwc5Cn9OSQBgCEwSFIv+1oMZz56aPxYqBCJXqVr6c6\n DYjVpGqkpXD1FzjnV4teBN5vi/cXwrojYFYhTH/gXlFDCNMEZ+Piqogo8\n gmuEISrbdOf9VfLDs63sFcmz9yW+zZgFxj+bpoQHexh3aCvKNaxkMR/NY\n jxRZnobTCLrVOozoUGOT9icMGVn075zLliTYuX0lS0NBoTmrEwZ8qBdVE A==;",
        "X-IronPort-AV": [
            "E=McAfee;i=\"6400,9594,10337\"; a=\"267935870\"",
            "E=Sophos;i=\"5.91,198,1647327600\"; d=\"scan'208\";a=\"267935870\"",
            "E=Sophos;i=\"5.91,198,1647327600\"; d=\"scan'208\";a=\"694093442\""
        ],
        "X-ExtLoop1": "1",
        "From": "Anatoly Burakov <anatoly.burakov@intel.com>",
        "To": "dev@dpdk.org, Xueqin Lin <xueqin.lin@intel.com>,\n Zhihong Peng <zhihongx.peng@intel.com>",
        "Cc": "vladimir.medvedkin@intel.com, david.marchand@redhat.com, stable@dpdk.org",
        "Subject": "[PATCH v2 1/1] malloc: fix ASan handling for unmapped memory",
        "Date": "Wed,  4 May 2022 14:31:58 +0000",
        "Message-Id": "\n <54f5fe8c3e8ba5412dc34bace1409c44efd6035a.1651674707.git.anatoly.burakov@intel.com>",
        "X-Mailer": "git-send-email 2.25.1",
        "In-Reply-To": "\n <e24732663167d8ddc2b129e2b490166209f09ddb.1651671644.git.anatoly.burakov@intel.com>",
        "References": "\n <e24732663167d8ddc2b129e2b490166209f09ddb.1651671644.git.anatoly.burakov@intel.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-BeenThere": "dev@dpdk.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "Errors-To": "dev-bounces@dpdk.org"
    },
    "content": "Currently, when we free previously allocated memory, we mark the area as\n\"freed\" for ASan purposes (flag 0xfd). However, sometimes, freeing a\nmalloc element will cause pages to be unmapped from memory and re-backed\nwith anonymous memory again. This may cause ASan's \"use-after-free\"\nerror down the line, because the allocator will try to write into\nmemory areas recently marked as \"freed\".\n\nTo fix this, we need to mark the unmapped memory area as \"available\",\nand fixup surrounding malloc element header/trailers to enable later\nmalloc routines to safely write into new malloc elements' headers or\ntrailers.\n\nFixes: 6cc51b1293ce (\"mem: instrument allocator for ASan\")\nCc: zhihongx.peng@intel.com\nCc: stable@dpdk.org\n\nSigned-off-by: Anatoly Burakov <anatoly.burakov@intel.com>\n---\n\nNotes:\n    v2:\n    - Add missing dummy implementation for `asan_set_zone()`\n\n lib/eal/common/malloc_elem.h |  4 ++++\n lib/eal/common/malloc_heap.c | 35 +++++++++++++++++++++++++++++++++++\n 2 files changed, 39 insertions(+)",
    "diff": "diff --git a/lib/eal/common/malloc_elem.h b/lib/eal/common/malloc_elem.h\nindex f2aa98821b..c5f65895e1 100644\n--- a/lib/eal/common/malloc_elem.h\n+++ b/lib/eal/common/malloc_elem.h\n@@ -278,6 +278,10 @@ old_malloc_size(struct malloc_elem *elem)\n \n #define __rte_no_asan\n \n+static inline void\n+asan_set_zone(void *ptr __rte_unused, size_t len __rte_unused,\n+\t\tuint32_t val __rte_unused) { }\n+\n static inline void\n asan_set_freezone(void *ptr __rte_unused, size_t size __rte_unused) { }\n \ndiff --git a/lib/eal/common/malloc_heap.c b/lib/eal/common/malloc_heap.c\nindex 6c572b6f2c..a3d26fcbea 100644\n--- a/lib/eal/common/malloc_heap.c\n+++ b/lib/eal/common/malloc_heap.c\n@@ -861,6 +861,7 @@ malloc_heap_free(struct malloc_elem *elem)\n \tstruct rte_memseg_list *msl;\n \tunsigned int i, n_segs, before_space, after_space;\n \tint ret;\n+\tbool unmapped = false;\n \tconst struct internal_config *internal_conf =\n \t\teal_get_internal_configuration();\n \n@@ -1027,6 +1028,9 @@ malloc_heap_free(struct malloc_elem *elem)\n \t\trequest_to_primary(&req);\n \t}\n \n+\t/* we didn't exit early, meaning we have unmapped some pages */\n+\tunmapped = true;\n+\n \tRTE_LOG(DEBUG, EAL, \"Heap on socket %d was shrunk by %zdMB\\n\",\n \t\tmsl->socket_id, aligned_len >> 20ULL);\n \n@@ -1034,6 +1038,37 @@ malloc_heap_free(struct malloc_elem *elem)\n free_unlock:\n \tasan_set_freezone(asan_ptr, asan_data_len);\n \n+\t/* if we unmapped some memory, we need to do additional work for ASan */\n+\tif (unmapped) {\n+\t\tvoid *asan_end = RTE_PTR_ADD(asan_ptr, asan_data_len);\n+\t\tvoid *aligned_end = RTE_PTR_ADD(aligned_start, aligned_len);\n+\t\tvoid *aligned_trailer = RTE_PTR_SUB(aligned_start,\n+\t\t\t\tMALLOC_ELEM_TRAILER_LEN);\n+\n+\t\t/*\n+\t\t * There was a memory area that was unmapped. This memory area\n+\t\t * will have to be marked as available for ASan, because we will\n+\t\t * want to use it next time it gets mapped again. The OS memory\n+\t\t * protection should trigger a fault on access to these areas\n+\t\t * anyway, so we are not giving up any protection.\n+\t\t */\n+\t\tasan_set_zone(aligned_start, aligned_len, 0x00);\n+\n+\t\t/*\n+\t\t * ...however, when we unmap pages, we create new free elements\n+\t\t * which might have been marked as \"freed\" with an earlier\n+\t\t * `asan_set_freezone` call. So, if there is an area past the\n+\t\t * unmapped space that was marked as freezone for ASan, we need\n+\t\t * to mark the malloc header as available.\n+\t\t */\n+\t\tif (asan_end > aligned_end)\n+\t\t\tasan_set_zone(aligned_end, MALLOC_ELEM_HEADER_LEN, 0x00);\n+\n+\t\t/* if there's space before unmapped memory, mark as available */\n+\t\tif (asan_ptr < aligned_start)\n+\t\t\tasan_set_zone(aligned_trailer, MALLOC_ELEM_TRAILER_LEN, 0x00);\n+\t}\n+\n \trte_spinlock_unlock(&(heap->lock));\n \treturn ret;\n }\n",
    "prefixes": [
        "v2",
        "1/1"
    ]
}