From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71943 invoked by alias); 22 May 2019 13:29:25 -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 71932 invoked by uid 89); 22 May 2019 13:29:24 -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.2 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=HX-Languages-Length:2098 X-Spam-Status: No, score=-17.2 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: EUR02-VE1-obe.outbound.protection.outlook.com Received: from mail-eopbgr20068.outbound.protection.outlook.com (HELO EUR02-VE1-obe.outbound.protection.outlook.com) (40.107.2.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 May 2019 13:29:23 +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=i66EMJwg73N/Kgc2lTQPuLv1IGjjZw1t67lsbShK9x9np0W8UI8/6nvgRjT+NbOmAlQ475Q4jsLGegl4in2PzxYk2pbDcuvq5EMGT2mY/i9N1P/ocIYXjBxCevHN3ETrgng065FaQMk74StIk3BoPZdFwg+KdmNovtOx1VC9hBU= Received: from VI1PR0801MB2127.eurprd08.prod.outlook.com (10.168.62.22) by VI1PR0801MB1823.eurprd08.prod.outlook.com (10.168.67.15) 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 13:29:20 +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 13:29:20 +0000 From: Wilco Dijkstra To: "libc-stable@sourceware.org" CC: nd Subject: [2.29 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Topic: [2.29 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Index: AQHVEKGjnIs/C/NAKUOSvOj+mVZzUg== 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: 7d044219-7b1c-452b-2ec7-08d6deb97f31 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:VI1PR0801MB1823; x-ms-traffictypediagnostic: VI1PR0801MB1823: 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)(376002)(39860400002)(346002)(396003)(136003)(366004)(199004)(189003)(476003)(73956011)(76116006)(2501003)(66476007)(66946007)(66556008)(66446008)(486006)(64756008)(478600001)(4326008)(316002)(25786009)(72206003)(14454004)(2906002)(2351001)(6116002)(3846002)(5660300002)(53936002)(52536014)(8936002)(81166006)(81156014)(8676002)(74316002)(68736007)(186003)(7696005)(99286004)(6506007)(26005)(6916009)(102836004)(66066001)(71200400001)(71190400001)(86362001)(256004)(14444005)(6436002)(5640700003)(305945005)(9686003)(33656002)(55016002)(7736002);DIR:OUT;SFP:1101;SCL:1;SRVR:VI1PR0801MB1823;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: 3nm8/uT49iTvFKtl10sZ76xCR+1riB5LJJ5s4j7W7eQU6mFAkNZpcKhfFBQGyumpKsU7ip4s/uWjYdS9GbpYcjdhf6uCzmRFMGJuj6a5rFfuI7J24aY0DLgF5oNZXJ76VUbfCaKCojCDy2xd0WCSwpLiKebDq8tvFJHh+AR+mGON7Ug+eYgWwQj8WrWtY1Qj17Bw33hhoaV18otNTprKH4XJB7O85BFHpNr9q3cxO5zYKVL6xN4UyV/hpVfkT3eZfCCRdIyxBIi1Z8tn22qP8jzsljVSXG1QU8Cp4hRdOHRYB0+Raj+0WLSvjdKerRLVSQl9SF9wKt/A1lWuX1o0ouzvD/EouPTIPTkB1cLfGacamaUdA/zOtoeh5xWXP1zADjWawcO2xGot65W09Dhe0cCEOUfFwUPTYhsPzcAfSWA= 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: 7d044219-7b1c-452b-2ec7-08d6deb97f31 X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2019 13:29:20.2528 (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: VI1PR0801MB1823 X-SW-Source: 2019-05/txt/msg00012.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