Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 278C8606A322 for ; Fri, 4 Dec 2026 09:04:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=citrix.com header.i=@citrix.com header.a=rsa-sha256 header.s=selector1 header.b=Yuq9vy/0 Received: from list by lists.xenproject.org with outflank-mailman.1513893.1705305 (Exim 4.92) (envelope-from ) id 1xZPCU-0007Fy-Tb; Fri, 04 Dec 2026 09:03:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1513893.1705305; Fri, 04 Dec 2026 09:03:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZPCU-0007Fr-Qm; Fri, 04 Dec 2026 09:03:30 +0000 Received: by outflank-mailman (input) for mailman id 1513893; Fri, 04 Dec 2026 09:03:29 +0000 Received: from mx.expurgate.net ([195.190.135.10]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1xZPCT-0007Fl-MY for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 09:03:29 +0000 Received: from mx.expurgate.net (helo=localhost) by mx.expurgate.net with esmtp id 1xZPCS-00FHbm-QV for xen-devel@lists.xenproject.org; Fri, 04 Dec 2026 10:03:28 +0100 Received: from [10.42.69.11] (helo=localhost) by localhost with ESMTP (eXpurgate MTA 0.9.1) (envelope-from ) id 6b1281d8-bab6-0a2a0a5309dd-0a2a450bc6aa-34 for ; Fri, 04 Dec 2026 10:03:28 +0100 Received: from [52.101.53.53] (helo=BL0PR03CU003.outbound.protection.outlook.com) by tlsNG-42698a.mxtls.expurgate.net with ESMTPS (eXpurgate 4.57.1) (envelope-from ) id 6b1281df-b7e8-0a2a450b0019-34653535cf3b-3 for ; Fri, 04 Dec 2026 10:03:28 +0100 Received: from CO1PR03MB7889.namprd03.prod.outlook.com (2603:10b6:303:275::14) by SA1PR03MB989246.namprd03.prod.outlook.com (2603:10b6:806:4f8::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.12; Fri, 4 Dec 2026 09:03:25 +0000 Received: from CO1PR03MB7889.namprd03.prod.outlook.com ([fe80::2d02:5605:87a2:6767]) by CO1PR03MB7889.namprd03.prod.outlook.com ([fe80::2d02:5605:87a2:6767%4]) with mapi id 15.21.0688.011; Fri, 4 Dec 2026 09:03:25 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Post: List-Help: List-Subscribe: , Precedence: list Sender: "Xen-devel" Authentication-Results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=pZRgpa/Kw+9ggWVMi/iod7/CcGdh1qIOPZSKiCX+F9rITTUWdEhH4iNoCW/teK7lihExls1KYhdgSTRguxXcpeXzXLZPxXbTCk4wIAKWig2XLtzXnRzEtof81k417d6f07TZqBHTvx+VHEs+e4nhTZAHscRu5kJiY1Bite92YGlwm2Wowxt/AzlGAL/gbW6CFmIRXJMy5e+8NjXKFX/107hFMRlUN9m9DauiuJcQQciUjvmyZzV5j8ksDRVlN+EswkPMOHl2nn/0uvXis8LM129k1HD7NJBnWYV38cUnEo7bQAXF1yRh3+WV70+uAXQXsL+A4QcoEvKk4EvZHXQCuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dJsn72hBVWrPtBGqjOp0q3QJuHqL4oIe/J3YX1R5vgU=; b=yTyK7GPxLd9Gm0dbieWqVmp00SFML6zzWpjGDwk9l5Ob0Nqn7UbUfefG3MTiTulfXNvqGH3x7mNF22f1Q8avmYeJFDVk5A1csNmMSPoZFmw1hQPECo3rk0UzV/ylbxKABcHbkldLIjj9HXdvRRiec2D5SH1Ht2jf1kEfC4sUHsz779aoguHt7k4FmjjTgcAEKzkufKGUkuAF5qVeVIGioDv++XrxpCvScqlYvlGytnqO/hJ/n4dKLsi4KsFD28GibgI/Kw1GwSeqSsl2PDb2d1hEzGQKfp+yMoOE3Hd6xtWn+AN4JpjJ4gz05KYxTwJCOUuzW4w2U47KzbAY1GR7Hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=citrix.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dJsn72hBVWrPtBGqjOp0q3QJuHqL4oIe/J3YX1R5vgU=; b=Yuq9vy/0YCQXSL16Ifko6VQfnfyY2H+y3app/oU/n/69m1A9MtFmRWWGXoI+OBMce9JSqf9JJ2Wt+/DnHTSmQELBHooUqaGDS3s75XjTn+UFKyHdHbD9YXwwjEZHB+dWtwtPFM7e8uVjJU/BUSd4CpTJeQsoi0SAipdOnPwpFHg= Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Stephen Cheng To: jbeulich@suse.com Cc: andrew.cooper3@citrix.com, anthony.perard@vates.tech, julien@xen.org, michal.orzel@amd.com, roger@xenproject.org, sstabellini@kernel.org, stephen.cheng@citrix.com, xen-devel@lists.xenproject.org Subject: Re: [PATCH v2] xmalloc: correct _xrealloc() for large or changing alignment Date: Fri, 4 Dec 2026 17:03:08 +0800 Message-ID: <20261204090308.28785-1-stephen.cheng@citrix.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: <2dfc3602-e4a0-423a-abcd-3ea95399cd33@suse.com> References: <20261204025555.436959-1-stephen.cheng@citrix.com> <2dfc3602-e4a0-423a-abcd-3ea95399cd33@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ClientProxiedBy: JN3P275CA0093.ZAFP275.PROD.OUTLOOK.COM (2603:1086:0:c8::7) To CO1PR03MB7889.namprd03.prod.outlook.com (2603:10b6:303:275::14) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1PR03MB7889:EE_|SA1PR03MB989246:EE_ X-MS-Office365-Filtering-Correlation-Id: 1df8f410-3beb-4da5-4718-08df51e57418 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016|23010399003|4143699003|11063799006|261009223027099003|22082099003|18002099003|10067099003|261028144727099003|261021121427099003|261102123227099003|261026121527099003|261026140227099003|261022105027099003|56012099006; X-Microsoft-Antispam-Message-Info: m9w6fA42D+WY/n8skWeOrqU0y09NbdtD43NF1AF5k8qSXW6TBFu0nOB6o/ZN5Mpc2HrftYSAiq5guTgDEko8qX+FVyLOLDcK5a2B7QQSdjOL/u0fmDEC/JraR6mQSgKCeqAlQ4XhXAJnjbqGOmQfwlSmc7P/P4OEBsLSqEzbhnXci2IbPCGXTqJIqBT62vM0grxkOp5yGDgAxnQYHrnUVkBPd7RsgfNR/zOZ9Ipw4jfopSZEqr3E41e/J2wgNG1Ed0vL2PLFNl+svQAmmJM2m+xdhd/2Sc0V2u1hD7R27zIqPiJ+UF22BxPIWBNP45vld/h8oI30xQcfvKSsQl38E4lsmw7g/uhuVHal8COs7qZTB9AEqmAyt+IuDmmjEK7Qse6XNReGdSks7xHCWOJa7WXQ8o94I/PvPknxJOc3qe9G6ZNh0dct2XbhqZ9+g3i8jqQUt5lTHAbfbuDn/BoyJOfg9ZADzERS6MjvIv1jW7ROgufOzjMpHyoa0Di2cZd1y+9I6lBX7qvrAGgNipoaLHuVNAGCZme2EDvyyIG6gf7w4gaU+xhOOoYNUEqaa/8QvOdO/WFlhyEw+CHdY0vyJ8sgBwp/43IQpQm+M1ioUvv2WMJ+kxgDQ8axMX8EnuLW15hOFs3DbmVulgYntRkkjdM7BaDQR6ca3YKH7miF8TY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR03MB7889.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(1800799024)(366016)(23010399003)(4143699003)(11063799006)(261009223027099003)(22082099003)(18002099003)(10067099003)(261028144727099003)(261021121427099003)(261102123227099003)(261026121527099003)(261026140227099003)(261022105027099003)(56012099006);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?Q1pyeHhGNnRKZDMvQzVYYVVNTFFoc2luOVd2czRhTlpRT21rdzJZWDd4RUto?= =?utf-8?B?Z0hwNksyV0FEQnUvbFFLQ2h3U29Md1lIMGNySy8xa2NXcHhnVy9VaGl1VEtW?= =?utf-8?B?V3ZPb3BEam93bE9teCtYeTdPYXlYdTVabW1qQ1ZlTFdsYkFZWkFCc25QaTc3?= =?utf-8?B?NFJSbWdROVRpeVlWQ3VQQ0NHY3F3aFVUd2ZLMHlOVTJMZXdESFBsbnZtOWJ6?= =?utf-8?B?ZlJGZmppMDIwcHNWdEFMcFl3RWc2WC84eFhrd3Z1MmFObUZneStsUjFhUjBo?= =?utf-8?B?dk9XNThnUUppaVAyOFVDcnFsQzlBZ0hCQ1JUbllUZXRieWNJd0U3ZjFuUjla?= =?utf-8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dG41QTBzaVAwaTFxU04rTVZ4OTdq?= =?utf-8?B?dEk0bExYVEhQd2lUTm5OSENncDY1R2RqWUJlV0x4VXlYTUN4KzFBZmpiQXBi?= =?utf-8?B?b1QrUk93ZzJQa09JK3VMNWplVTFZeVhaemsyVFdWSTJZSUN3TGlTQkRCWCtB?= =?utf-8?B?Tlc3ZWVlMmQ3YVJ2bEFaSU5OQ0xCNDVwTnRYcitVTHVoQVJMczczdz09?= X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1df8f410-3beb-4da5-4718-08df51e57418 X-MS-Exchange-CrossTenant-AuthSource: CO1PR03MB7889.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2026 09:03:25.1372 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335836de-42ef-43a2-b145-348c2ee9ca5b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: M82/6Wlit2yif1ZUSqTpa3AIHgN7a5mDOABZQWsH2TsLSRbNI1KAt57X3LnMrmG5KmspVDqcm5gzAPK8oMBuJNTZZdPiRaBVEZk7nbZ3y9M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR03MB989246 X-purgate-ID: tlsNG-42698a/1796375008-2C39B9EA-5F1A35E7/0/0 X-purgate-type: clean X-purgate-size: 2127 X-Spam-Status: No, score=-9.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS,UNPARSEABLE_RELAY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On 04/12/2026 08:11, Jan Beulich wrote: > Upon looking more closely, I think the code is correct as-is. curr_size > describes the full block (from p0), and what we want to subtract is the > padding size that add_padding() inserts. The (possible) amount of > (original) tail padding doesn't matter. Whether we read into tail > padding isn't overly important, I think - maybe that you you meant with > "harmless". If we wanted to be more precise no matter whether size grows > or shrinks, I think it would need to be > min(curr_size - min(p - p0, ptr - p0)). Yet that extra complexity > doesn't look warranted. Thanks for looking at it again. I also looked more closely after your reply, and I should not have said "harmless", sorry. As you said in your earlier reply, reading past the end of a block is rarely harmless. The read is not only into tail padding. When the pointer moves down, it can go up to (ptr - p) bytes past the end of the block. If the block is the last one in its pool page, that is past the end of the page. On x86 the directmap only maps RAM, so the next page may not be mapped. For example, _xmalloc(32, 64) gets an 80-byte block at p0 = 0x10, so the block ends at 0x60 and ptr = 0x40 (48 bytes of padding). Then _xrealloc(ptr, 80, MEM_ALIGN) re-uses the block with p = 0x10, and memmove() reads 80 bytes from 0x40, up to 0x90. That is 48 bytes past the end of the block: 0x10 0x40 0x60 0x90 +-------------+-------------+ - - - - - - - | padding | old data | next block +-------------+-------------+ - - - - - - - p0, new p ptr block end |<---- memmove() reads ---->| This needs the pointer to move down, the block to be the last one in its page, and the next page to be unmapped, so it is unlikely. But the fix is small. Unless I am missing something, min(curr_size - (ptr - p0), size) is enough in both directions: the re-use check already makes sure size fits after the new pointer, so only the old pointer needs the limit. But of course it is your call. Stephen