From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 99824 invoked by alias); 22 May 2019 14:44:59 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 99747 invoked by uid 89); 22 May 2019 14:44:58 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-17.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-17.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: EUR03-DB5-obe.outbound.protection.outlook.com Received: from mail-eopbgr40080.outbound.protection.outlook.com (HELO EUR03-DB5-obe.outbound.protection.outlook.com) (40.107.4.80) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 May 2019 14:44:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector2-armh-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VklxKjsg0P8LxzcljIjbJKjUzGeR/4d37WhHczT6rm8=; b=MKhX/yXbRbHux0GOIRtrD3MnaqtXNNzRIRG6IIUwG55pFJvUXow0Z3MXTn9LTCUOPKAzBOfBh3JzE3ohzCwN5ypoGjjFHSFU1sqG7oDcBs1BFcYh8jjBrK8D0l1GFn+14KS2vuultQb2Q7FdY4nJ+IzGXovgZzyJD8v/x9TC1Z0= Received: from VI1PR0801MB2127.eurprd08.prod.outlook.com (10.168.62.22) by VI1PR0801MB1853.eurprd08.prod.outlook.com (10.168.67.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1922.16; Wed, 22 May 2019 14:44:53 +0000 Received: from VI1PR0801MB2127.eurprd08.prod.outlook.com ([fe80::fd18:cb50:3e52:9878]) by VI1PR0801MB2127.eurprd08.prod.outlook.com ([fe80::fd18:cb50:3e52:9878%7]) with mapi id 15.20.1922.016; Wed, 22 May 2019 14:44:53 +0000 From: Wilco Dijkstra To: "libc-stable@sourceware.org" CC: nd Subject: [2.28 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Topic: [2.28 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Index: AQHVEKzYe5/yrxk4MkO+mNUJ5j0onw== Date: Tue, 01 Jan 2019 00:00:00 -0000 Message-ID: Accept-Language: en-GB, en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; x-originating-ip: [217.140.106.54] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ddec4e2e-2873-43e8-f320-08d6dec40d3f x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020);SRVR:VI1PR0801MB1853; x-ms-traffictypediagnostic: VI1PR0801MB1853: nodisclaimer: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:2887; x-forefront-prvs: 0045236D47 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(346002)(376002)(39860400002)(396003)(136003)(199004)(189003)(14454004)(55016002)(33656002)(305945005)(74316002)(7736002)(5640700003)(2501003)(6916009)(6436002)(4326008)(25786009)(53936002)(66066001)(6116002)(3846002)(2351001)(478600001)(2906002)(9686003)(72206003)(316002)(26005)(102836004)(99286004)(86362001)(186003)(7696005)(68736007)(6506007)(8936002)(52536014)(8676002)(486006)(81166006)(81156014)(66446008)(76116006)(66556008)(66476007)(66946007)(73956011)(64756008)(5660300002)(256004)(14444005)(71190400001)(476003)(71200400001);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0801MB1853;H:VI1PR0801MB2127.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: t2RfaZOOdft/S02joRkCY4NztHOzBla4M8dvrPea5l/hYiwp5UPwJAnhU9XHXA/Nq6xOBGm83ZWByyqfmj5nQ0WAb7DnowKW7OXB9WuImve4TgPzIaspgAkXO26XLzKOmlm8T1szDu5oqJCj6syIxGfQR/WIlQHnAilvVAgR8ns2+y3owtBYPleJf0N8FoXFJFbXdRIDpMM2G7K0ny83ZHUgr8ShS1YL0U2SXV9V59qmCU41gJ6s/LdvtuSU1i0Oqy4PlrfCm9DF2b19JzIt86sSMSHzAnRagFBKDen/1ym47ItqfYbLzirqoPFgSmT5V46XNMwgd+aZ5AhKzIaZ7rQmrQ5W9FTOivUCYZUInooagFLAsvzTDpRtfFbKVHbnL+chdzoNqug6XpQo2yLs9SF8GoDnjJey/vg5C4/Z8i4= Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: arm.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddec4e2e-2873-43e8-f320-08d6dec40d3f X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2019 14:44:53.5303 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: f34e5979-57d9-4aaa-ad4d-b122a662184d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Wilco.Dijkstra@arm.com X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1853 X-SW-Source: 2019-05/txt/msg00013.txt.bz2 The tcache counts[] array is a char, which has a very small range and thus may overflow. When setting tcache_count tunable, there is no overflow chec= k. However the tunable must not be larger than the maximum value of the tcache counts[] array, otherwise it can overflow when filling the tcache. [BZ #24531] * malloc/malloc.c (MAX_TCACHE_COUNT): New define. (do_set_tcache_count): Only update if count is small enough. * manual/tunables.texi (glibc.malloc.tcache_count): Document max va= lue. (cherry picked from commit 5ad533e8e65092be962e414e0417112c65d154fb) -- diff --git a/malloc/malloc.c b/malloc/malloc.c index ce77137..0abd653 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -2919,6 +2919,8 @@ typedef struct tcache_perthread_struct tcache_entry *entries[TCACHE_MAX_BINS]; } tcache_perthread_struct; =20 +#define MAX_TCACHE_COUNT 127 /* Maximum value of counts[] entries. */ + static __thread bool tcache_shutting_down =3D false; static __thread tcache_perthread_struct *tcache =3D NULL; =20 @@ -5124,8 +5126,11 @@ static inline int __always_inline do_set_tcache_count (size_t value) { - LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tcache_count); - mp_.tcache_count =3D value; + if (value <=3D MAX_TCACHE_COUNT) + { + LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tcache_count); + mp_.tcache_count =3D value; + } return 1; } =20 diff --git a/manual/tunables.texi b/manual/tunables.texi index af82082..8edfea4 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -189,8 +189,8 @@ per-thread cache. The default (and maximum) value is 1= 032 bytes on =20 @deftp Tunable glibc.malloc.tcache_count The maximum number of chunks of each size to cache. The default is 7. -There is no upper limit, other than available system memory. If set -to zero, the per-thread cache is effectively disabled. +The upper limit is 127. If set to zero, the per-thread cache is effective= ly +disabled. =20 The approximate maximum overhead of the per-thread cache is thus equal to the number of bins times the chunk count in each bin times the size