From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103980 invoked by alias); 22 May 2019 14:46:17 -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 103970 invoked by uid 89); 22 May 2019 14:46:17 -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.5 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.5 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: EUR01-HE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr130050.outbound.protection.outlook.com (HELO EUR01-HE1-obe.outbound.protection.outlook.com) (40.107.13.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 May 2019 14:46:15 +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=sorn90JA1nhVAFefizcYpKzN5ki4a5jUZuY6dB/o8Q8DWhQg4ue4g2x/4f+XZFUipgJSBNwJTL4tsxzRo4YoJvShus5I09eqGf9ChOAMn7U4US6pnctX3UaNbn3v1YCH/CH1UX3ptVIjt5fyCVRYlI4H7dIWsC2Ur6lMxf16ZIw= Received: from VI1PR0801MB2127.eurprd08.prod.outlook.com (10.168.62.22) by VI1PR0801MB1936.eurprd08.prod.outlook.com (10.173.73.150) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1900.16; Wed, 22 May 2019 14:46:11 +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:46:11 +0000 From: Wilco Dijkstra To: "libc-stable@sourceware.org" CC: nd Subject: [2.26 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Topic: [2.26 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Index: AQHVEK0R6q58XJtyPEKlKy1vE83mDA== 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: 34f669c7-bbfe-41fe-e2cc-08d6dec43b97 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:VI1PR0801MB1936; x-ms-traffictypediagnostic: VI1PR0801MB1936: 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)(346002)(376002)(396003)(366004)(39860400002)(136003)(189003)(199004)(7736002)(486006)(2501003)(476003)(5660300002)(8676002)(53936002)(72206003)(71200400001)(71190400001)(9686003)(55016002)(86362001)(66066001)(3846002)(6116002)(6436002)(4326008)(2906002)(5640700003)(305945005)(25786009)(33656002)(74316002)(256004)(14444005)(6916009)(316002)(64756008)(76116006)(66446008)(186003)(66946007)(73956011)(99286004)(66556008)(66476007)(7696005)(68736007)(2351001)(102836004)(14454004)(26005)(81166006)(6506007)(478600001)(81156014)(52536014)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0801MB1936;H:VI1PR0801MB2127.eurprd08.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A: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: /IWXPb0xWs5XFkRm/4sK0eilSjHwO6dcjbxfwNis6LNDN3GdhE0mHrfSiYsj8eyyfOgfjo685BVKYdIY0ZTY67hFu3Xe7XARhvK/0qzASsTulOERqeyfIXR8BIzBE8zFD8bMwPADODYhkBL5NG0GOstHMczNgECh7IVDGmb8jKCWcwWahg0/HGrnbnk1Fd3a/xruvh47ydfkFqa4v6pv6m9k0SjmHhjs3QmiF3wG4O64qdqKTwKdNZD+ervAz++ZXQaIgv/6Zc/cQvoP5XmAtSpFKQE9V5z8XzgAJtB0fz4hz5gBFxSaKSbO4qUUzIJKWNhae4yM500bIqX65iQc2cRUQAHhzAih3Su5TRqH4mjezIDUSAoykvBavw3dbJbkrXT4sV1MG1yYpBwTTVpb0TwGec3NeYFPoBYAkvxYvQ8= 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: 34f669c7-bbfe-41fe-e2cc-08d6dec43b97 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2019 14:46:11.3369 (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-Transport-CrossTenantHeadersStamped: VI1PR0801MB1936 X-SW-Source: 2019-05/txt/msg00015.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