From nobody Thu Apr 25 22:30:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1562338216; cv=none; d=zoho.com; s=zohoarc; b=GVENbtYS7LhjGg2IYmu83oPO3ME5KsBe+W+1OowdlLc7WL7WMcCMkB9JSA2qDBUVdaEdEMwg27ZF6MMyzzhz7QGRgTvNye9PGgiGPxiNqDcCK4/DhPQPmYFQO5dDHAA+GLIC9V8H8pXRG/FLd5gNOE00T+qRU9yUl4y9F/di9zU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562338216; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LO/9RmTsReX4XtCsOyfbeQ66eLoWiKu6xJRFpUGVAn0=; b=CjLsEVz6ozJKDcs84eYtd4P9nQ7JN056XXUjsAP2+X8MJugj9XUDs/u2TTrL5KCBHVUtIeg8QAoJ/O8knBL21fxs3Srb5g7vunRH+cJvXISP6ihjVvipmCcvrFsvhc6uTO9QVEq5yV78ZSkklufqkQzgpttIhcGj5YEfpkHksFY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1562338216237260.8428889076066; Fri, 5 Jul 2019 07:50:16 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hjPWL-00049b-AU; Fri, 05 Jul 2019 14:49:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hjPWJ-000496-W5 for xen-devel@lists.xenproject.org; Fri, 05 Jul 2019 14:49:04 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 068b6964-9f34-11e9-a202-7bc8371ce791; Fri, 05 Jul 2019 14:49:01 +0000 (UTC) X-Inumbo-ID: 068b6964-9f34-11e9-a202-7bc8371ce791 Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: eQ6JkDixZ3qwgmsoqGX/9xTgLYMVbsYsHecdLAUA5T5ploJhmcERqvhF7xcEgUFj4q7pT4ewRz Qt/okVSyMe6Bdc6Rw7/Zn9HwF8Th5wHGzbaw1UdeNLGlX+i5O7Xj5Y8c+7ktxKZXuiqQ1+lO7x ITOjM3hY9gkrFTj+jN9k2nCIKT9JLjh+FBPtNRRMihC40Zrm/Fc3mO62fwPFXgY0Z2PmqnP690 QmyjtPb3OndxTR2nRnUgliePpQndeylX5F4LZCKTS1YMcm8kNLZIJOrDo2l7dWEdhudWW0PC7V 0ek= X-SBRS: 2.7 X-MesageID: 2648991 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,455,1557201600"; d="scan'208";a="2648991" From: Paul Durrant To: Date: Fri, 5 Jul 2019 15:48:54 +0100 Message-ID: <20190705144855.15259-2-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190705144855.15259-1-paul.durrant@citrix.com> References: <20190705144855.15259-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 1/2] xmalloc: remove struct xmem_pool init_region X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch dispenses with the init_region. It's simply not necessary (pools will still happily grow and shrink on demand in its absence) and the code can be shortended by removing it. It also avoids the sole evaluation of ADD_REGION without holding the pool lock (which is unsafe). NOTE: The if statement that is removed from xmem_pool_destroy() has actually been bogus since commit 6009f4dd "Transcendent memory ("tmem") for Xen." when the allocation of the init_region was moved out of xmem_pool_create(). Signed-off-by: Paul Durrant Suggested-by: Jan Beulich Reviewed-by: Jan Beulich --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu v2: - remove init_region instead of fixing the locking --- xen/common/xmalloc_tlsf.c | 34 ++++------------------------------ xen/include/xen/xmalloc.h | 2 -- 2 files changed, 4 insertions(+), 32 deletions(-) diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index f585388dfa..e4e476a27c 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -101,7 +101,6 @@ struct xmem_pool { =20 spinlock_t lock; =20 - unsigned long init_size; unsigned long max_size; unsigned long grow_size; =20 @@ -115,7 +114,6 @@ struct xmem_pool { =20 struct list_head list; =20 - void *init_region; char name[MAX_POOL_NAME_LEN]; }; =20 @@ -287,14 +285,13 @@ struct xmem_pool *xmem_pool_create( const char *name, xmem_pool_get_memory get_mem, xmem_pool_put_memory put_mem, - unsigned long init_size, unsigned long max_size, unsigned long grow_size) { struct xmem_pool *pool; int pool_bytes, pool_order; =20 - BUG_ON(max_size && (max_size < init_size)); + BUG_ON(max_size && (max_size < grow_size)); =20 pool_bytes =3D ROUNDUP_SIZE(sizeof(*pool)); pool_order =3D get_order_from_bytes(pool_bytes); @@ -305,23 +302,18 @@ struct xmem_pool *xmem_pool_create( memset(pool, 0, pool_bytes); =20 /* Round to next page boundary */ - init_size =3D ROUNDUP_PAGE(init_size); max_size =3D ROUNDUP_PAGE(max_size); grow_size =3D ROUNDUP_PAGE(grow_size); =20 /* pool global overhead not included in used size */ pool->used_size =3D 0; =20 - pool->init_size =3D init_size; pool->max_size =3D max_size; pool->grow_size =3D grow_size; pool->get_mem =3D get_mem; pool->put_mem =3D put_mem; strlcpy(pool->name, name, sizeof(pool->name)); =20 - /* always obtain init_region lazily now to ensure it is get_mem'd - * in the same "context" as all other regions */ - spin_lock_init(&pool->lock); =20 spin_lock(&pool_list_lock); @@ -340,7 +332,6 @@ unsigned long xmem_pool_get_total_size(struct xmem_pool= *pool) { unsigned long total; total =3D ROUNDUP_SIZE(sizeof(*pool)) - + pool->init_size + (pool->num_regions - 1) * pool->grow_size; return total; } @@ -352,13 +343,6 @@ void xmem_pool_destroy(struct xmem_pool *pool) if ( pool =3D=3D NULL ) return; =20 - /* User is destroying without ever allocating from this pool */ - if ( xmem_pool_get_used_size(pool) =3D=3D BHDR_OVERHEAD ) - { - ASSERT(!pool->init_region); - pool->used_size -=3D BHDR_OVERHEAD; - } - /* Check for memory leaks in this pool */ if ( xmem_pool_get_used_size(pool) ) printk("memory leak in pool: %s (%p). " @@ -380,14 +364,6 @@ void *xmem_pool_alloc(unsigned long size, struct xmem_= pool *pool) int fl, sl; unsigned long tmp_size; =20 - if ( pool->init_region =3D=3D NULL ) - { - if ( (region =3D pool->get_mem(pool->init_size)) =3D=3D NULL ) - goto out; - ADD_REGION(region, pool->init_size, pool); - pool->init_region =3D region; - } - size =3D (size < MIN_BLOCK_SIZE) ? MIN_BLOCK_SIZE : ROUNDUP_SIZE(size); /* Rounding up the requested size and calculating fl and sl */ =20 @@ -401,8 +377,7 @@ void *xmem_pool_alloc(unsigned long size, struct xmem_p= ool *pool) /* Not found */ if ( size > (pool->grow_size - 2 * BHDR_OVERHEAD) ) goto out_locked; - if ( pool->max_size && (pool->init_size + - pool->num_regions * pool->grow_size + if ( pool->max_size && (pool->num_regions * pool->grow_size > pool->max_size) ) goto out_locked; spin_unlock(&pool->lock); @@ -551,9 +526,8 @@ static void *xmalloc_whole_pages(unsigned long size, un= signed long align) =20 static void tlsf_init(void) { - xenpool =3D xmem_pool_create( - "xmalloc", xmalloc_pool_get, xmalloc_pool_put, - PAGE_SIZE, 0, PAGE_SIZE); + xenpool =3D xmem_pool_create("xmalloc", xmalloc_pool_get, + xmalloc_pool_put, 0, PAGE_SIZE); BUG_ON(!xenpool); } =20 diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index b486fe4b06..f075d2da91 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -84,7 +84,6 @@ typedef void (xmem_pool_put_memory)(void *ptr); * @name: name of the pool * @get_mem: callback function used to expand pool * @put_mem: callback function used to shrink pool - * @init_size: inital pool size (in bytes) * @max_size: maximum pool size (in bytes) - set this as 0 for no limit * @grow_size: amount of memory (in bytes) added to pool whenever required * @@ -94,7 +93,6 @@ struct xmem_pool *xmem_pool_create( const char *name, xmem_pool_get_memory get_mem, xmem_pool_put_memory put_mem, - unsigned long init_size, unsigned long max_size, unsigned long grow_size); =20 --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel From nobody Thu Apr 25 22:30:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1562338209; cv=none; d=zoho.com; s=zohoarc; b=DTj3DvFCFnfhkHAiFrBgH+yhxBSTq8A5tehfEx7QPdg0Ad+xT5sbkPBzL7MAVM40KO5y04A6su4h+7bRovDhNGztVt8Y4QUSI62z0RLij0yXw1Qd4xq/RhPwY7Hy0dNFQYYmbut1JX/uvuFBxVvQxZgXVuGLsO3ANdg1SgDSDkQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562338209; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7zDusw5GhqksA4PyW+960YgfCxqKuWC3uqJHrtXVbFk=; b=TY8+yuNTGXgtVodpqwrN3hQCYgFkRYUv3IaJm84wsl4bu9dVoRLM0Rt2AlnLvUHNi6VZZymyKJpH0kWRsBkwCw7e8/S/BvnnFdpCvAxfJYyWUqOL3GoqcOKuEQJo3lYq6ckmPX2WawYNGrXxoyVErY0OwMvL1E+tJbJ04LGr75o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1562338209618740.2391405109574; Fri, 5 Jul 2019 07:50:09 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hjPWL-00049w-JQ; Fri, 05 Jul 2019 14:49:05 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hjPWJ-000495-W4 for xen-devel@lists.xenproject.org; Fri, 05 Jul 2019 14:49:04 +0000 Received: from esa1.hc3370-68.iphmx.com (unknown [216.71.145.142]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 0629f80a-9f34-11e9-a3b6-ef9406ccf374; Fri, 05 Jul 2019 14:49:00 +0000 (UTC) X-Inumbo-ID: 0629f80a-9f34-11e9-a3b6-ef9406ccf374 Authentication-Results: esa1.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=paul.durrant@citrix.com; spf=Pass smtp.mailfrom=Paul.Durrant@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of paul.durrant@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="paul.durrant@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa1.hc3370-68.iphmx.com: domain of Paul.Durrant@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="Paul.Durrant@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ~all" Received-SPF: None (esa1.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa1.hc3370-68.iphmx.com; envelope-from="Paul.Durrant@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: NC4It89LaybdiREW1N3XzylIZKOsMm/mT0QgHrHxGgx/dWs4GW2zyv9FQmBogakTt9f+QvelMU B0UGJy0GuzEYMO8nFXazKsqh4vrorWen3jOQrULuY6PocqE7wB6BDlowzWJJGjcrWJRjSeukpU +6EtiJ/lhRawR3mlB1VEK5j+GM/mSToyBv40z6nHnHdvFVuplGjlBlAEUjXKkftgcVTvFDlV2w 5kjjSjfQw7u7nKShUlRcZl9qubgdenCd3xhDxH+oDA306jCINtCl/4Vyi857tUnU2Z1cFtNQzZ E0k= X-SBRS: 2.7 X-MesageID: 2648989 X-Ironport-Server: esa1.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.63,455,1557201600"; d="scan'208";a="2648989" From: Paul Durrant To: Date: Fri, 5 Jul 2019 15:48:55 +0100 Message-ID: <20190705144855.15259-3-paul.durrant@citrix.com> X-Mailer: git-send-email 2.20.1.2.gb21ebb671 In-Reply-To: <20190705144855.15259-1-paul.durrant@citrix.com> References: <20190705144855.15259-1-paul.durrant@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 2/2] xmalloc: add a Kconfig option to poison free pool memory X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Julien Grall , Paul Durrant , Jan Beulich Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" This patch adds XMEM_POOL_POISON to the Kconfig DEBUG options. If set, free blocks (greater than MIN_BLOCK_SIZE) will be poisoned with 0xAA bytes which will then be verified when memory is subsequently allocated. This can help in spotting heap corruption, particularly use-after-free. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Andrew Cooper Cc: George Dunlap Cc: Ian Jackson Cc: Jan Beulich Cc: Julien Grall Cc: Konrad Rzeszutek Wilk Cc: Stefano Stabellini Cc: Tim Deegan Cc: Wei Liu v3: - #define the POISON_BYTE - Fix whitespace in Kconfig.debug v2: - Change Kconfig option name to XMEM_POOL_POISON - Add an implementation of memchr_inv() and use that --- xen/Kconfig.debug | 7 +++++++ xen/common/string.c | 20 ++++++++++++++++++++ xen/common/xmalloc_tlsf.c | 12 ++++++++++++ xen/include/xen/string.h | 2 ++ 4 files changed, 41 insertions(+) diff --git a/xen/Kconfig.debug b/xen/Kconfig.debug index daacf85141..e10e314e25 100644 --- a/xen/Kconfig.debug +++ b/xen/Kconfig.debug @@ -105,6 +105,13 @@ config DEBUG_TRACE either directly to the console or are printed to console in case of a system crash. =20 +config XMEM_POOL_POISON + bool "Poison free xenpool blocks" + default DEBUG + ---help--- + Poison free blocks with 0xAA bytes and verify them when a block is + allocated in order to spot use-after-free issues. + endif # DEBUG || EXPERT =20 endmenu diff --git a/xen/common/string.c b/xen/common/string.c index a2bbe7dc97..af3d96ad0f 100644 --- a/xen/common/string.c +++ b/xen/common/string.c @@ -423,6 +423,26 @@ void *(memchr)(const void *s, int c, size_t n) } #endif =20 +/** + * memchr_inv - Find an unmatching character in an area of memory. + * @s: The memory area + * @c: The byte that is expected + * @n: The size of the area. + * + * returns the address of the first occurrence of a character other than @= c, + * or %NULL if the whole buffer contains just @c. + */ +void *memchr_inv(const void *s, int c, size_t n) +{ + const unsigned char *p =3D s; + + while (n--) + if ((unsigned char)c !=3D *p++) + return (void *)(p - 1); + + return NULL; +} + /* * Local variables: * mode: C diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index e4e476a27c..a1acfceaf6 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -215,6 +215,8 @@ static inline void EXTRACT_BLOCK_HDR(struct bhdr *b, st= ruct xmem_pool *p, int fl b->ptr.free_ptr =3D (struct free_ptr) {NULL, NULL}; } =20 +#define POISON_BYTE 0xAA + /** * Removes block(b) from free list with indexes (fl, sl) */ @@ -238,6 +240,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struc= t xmem_pool *p, int fl, } } b->ptr.free_ptr =3D (struct free_ptr) {NULL, NULL}; +#ifdef CONFIG_XMEM_POOL_POISON + if ( (b->size & BLOCK_SIZE_MASK) > MIN_BLOCK_SIZE ) + ASSERT(!memchr_inv(b->ptr.buffer + MIN_BLOCK_SIZE, POISON_BYTE, + (b->size & BLOCK_SIZE_MASK) - MIN_BLOCK_SIZE)); +#endif /* CONFIG_XMEM_POOL_POISON */ } =20 /** @@ -245,6 +252,11 @@ static inline void EXTRACT_BLOCK(struct bhdr *b, struc= t xmem_pool *p, int fl, */ static inline void INSERT_BLOCK(struct bhdr *b, struct xmem_pool *p, int f= l, int sl) { +#ifdef CONFIG_XMEM_POOL_POISON + if ( (b->size & BLOCK_SIZE_MASK) > MIN_BLOCK_SIZE ) + memset(b->ptr.buffer + MIN_BLOCK_SIZE, POISON_BYTE, + (b->size & BLOCK_SIZE_MASK) - MIN_BLOCK_SIZE); +#endif /* CONFIG_XMEM_POOL_POISON */ b->ptr.free_ptr =3D (struct free_ptr) {NULL, p->matrix[fl][sl]}; if ( p->matrix[fl][sl] ) p->matrix[fl][sl]->ptr.free_ptr.prev =3D b; diff --git a/xen/include/xen/string.h b/xen/include/xen/string.h index 711cb60a7d..4b3b57e74f 100644 --- a/xen/include/xen/string.h +++ b/xen/include/xen/string.h @@ -106,6 +106,8 @@ void *memchr(const void *, int, size_t); #define memchr(s, c, n) __builtin_memchr(s, c, n) #endif =20 +void *memchr_inv(const void *, int, size_t); + #define is_char_array(x) __builtin_types_compatible_p(typeof(x), char[]) =20 /* safe_xxx always NUL-terminates and returns !=3D0 if result is truncated= . */ --=20 2.20.1.2.gb21ebb671 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel