From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 103509 invoked by alias); 22 May 2019 14:45:39 -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 103497 invoked by uid 89); 22 May 2019 14:45:39 -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.4 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,SPF_PASS autolearn=ham version=3.3.1 spammy= X-Spam-Status: No, score=-17.4 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,SPF_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-AM5-obe.outbound.protection.outlook.com Received: from mail-eopbgr30060.outbound.protection.outlook.com (HELO EUR03-AM5-obe.outbound.protection.outlook.com) (40.107.3.60) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 May 2019 14:45:37 +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=swx4Z09ZfH5HQa6mG7KNIlHSF3pa9oww8U5thwxWsy8=; b=Pj5i+y4pBP0A8hSg2YuBDnm+BmTu+nA9jIcHGDYmo0b1CYPRh9s0J3tp3ZG2m0UFwybJzwesFiZmwZ52bxmwA23nIWI3feRY+/z9+I8f58b9DiquejILmGBxv+XFQRSsYmeyNKDe+LONKrABpDMOgcyXdsCV5nzSu9tPVe0e6jI= 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:45:34 +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:45:34 +0000 From: Wilco Dijkstra To: "libc-stable@sourceware.org" CC: nd Subject: [2.27 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Topic: [2.27 COMMITTED] Fix tcache count maximum (BZ #24531) Thread-Index: AQHVEK0DLiZwktCdv0aQ3taM51/19Q== 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: 462c2512-257f-4b87-5b0d-08d6dec425bb 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: meH7vsADEMntWG4LXREEY2WHG3E425Zg6hahnpdnVWj/Q83A394/fAUa/NOHZdAyagpiO7+cambCJCn/UZQydPlnPzZRbpXXLsOTS4ASwfXG+zgX20DXjPCBJ2g1hFvkeGkkDE8fwknAcLknLsBMC6Ao1dq7JnGG5uqb/8SH87f2IuMY0AYqrrUl4Z7npbROzuK/OI8YBva5k89QgA49LBjMm4GpwgILvW7S9gTFYmapm624uAAaMokH+Sj/4NpzZfRJ6LPorKG+nNd6/fc8frlh/yGXcA6i5iPBZfNIe3DtLokiGQQJpNcIC8X5E2jD49kNdO5dwBTXg0KAIDRZTjjX+TIN2516OX1V7LfEJ0ZIUm8aGxm5jHFV8JMPTYhL2tJ6E0A44/0Jpj1BWAqzlw2egdgF5Yc57Dfn7m96M/M= 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: 462c2512-257f-4b87-5b0d-08d6dec425bb X-MS-Exchange-CrossTenant-originalarrivaltime: 22 May 2019 14:45:34.6174 (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/msg00014.txt.bz2 The tcache counts[] array is a char, which has a very small range and thus may overflow.=A0 When setting tcache_count tunable, there is no overflow ch= eck. However the tunable must not be larger than the maximum value of the tcache counts[] array, otherwise it can overflow when filling the tcache. =A0=A0=A0=A0=A0=A0=A0 [BZ #24531] =A0=A0=A0=A0=A0=A0=A0 * malloc/malloc.c (MAX_TCACHE_COUNT): New define. =A0=A0=A0=A0=A0=A0=A0 (do_set_tcache_count): Only update if count is small = enough. =A0=A0=A0=A0=A0=A0=A0 * manual/tunables.texi (glibc.malloc.tcache_count): D= ocument max value. (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 =A0=A0 tcache_entry *entries[TCACHE_MAX_BINS]; =A0} tcache_perthread_struct; =A0 +#define MAX_TCACHE_COUNT 127=A0=A0 /* Maximum value of counts[] entries.= =A0 */ + =A0static __thread bool tcache_shutting_down =3D false; =A0static __thread tcache_perthread_struct *tcache =3D NULL; =A0 @@ -5124,8 +5126,11 @@ static inline int =A0__always_inline =A0do_set_tcache_count (size_t value) =A0{ -=A0 LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tcache_count); -=A0 mp_.tcache_count =3D value; +=A0 if (value <=3D MAX_TCACHE_COUNT) +=A0=A0=A0 { +=A0=A0=A0=A0=A0 LIBC_PROBE (memory_tunable_tcache_count, 2, value, mp_.tca= che_count); +=A0=A0=A0=A0=A0 mp_.tcache_count =3D value; +=A0=A0=A0 } =A0=A0 return 1; =A0} =A0 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.=A0 The default (and maximum) value is= 1032 bytes on =A0 =A0@deftp Tunable glibc.malloc.tcache_count =A0The maximum number of chunks of each size to cache. The default is 7. -There is no upper limit, other than available system memory.=A0 If set -to zero, the per-thread cache is effectively disabled. +The upper limit is 127.=A0 If set to zero, the per-thread cache is effecti= vely +disabled. =A0 =A0The approximate maximum overhead of the per-thread cache is thus equal =A0to the number of bins times the chunk count in each bin times the size