From patchwork Fri Apr 14 15:19:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Roger_Pau_Monn=C3=A9?= X-Patchwork-Id: 13211673 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AF91C77B72 for ; Fri, 14 Apr 2023 15:20:38 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.521147.809492 (Exim 4.92) (envelope-from ) id 1pnLDd-0006aD-BM; Fri, 14 Apr 2023 15:20:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 521147.809492; Fri, 14 Apr 2023 15:20:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pnLDd-0006a6-83; Fri, 14 Apr 2023 15:20:09 +0000 Received: by outflank-mailman (input) for mailman id 521147; Fri, 14 Apr 2023 15:20:07 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pnLDb-0006Zp-Bf for xen-devel@lists.xenproject.org; Fri, 14 Apr 2023 15:20:07 +0000 Received: from esa2.hc3370-68.iphmx.com (esa2.hc3370-68.iphmx.com [216.71.145.153]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id d3691e90-dad7-11ed-8611-37d641c3527e; Fri, 14 Apr 2023 17:20:03 +0200 (CEST) Received: from mail-bn8nam04lp2043.outbound.protection.outlook.com (HELO NAM04-BN8-obe.outbound.protection.outlook.com) ([104.47.74.43]) by ob1.hc3370-68.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 14 Apr 2023 11:19:59 -0400 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) by PH7PR03MB7223.namprd03.prod.outlook.com (2603:10b6:510:243::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6277.34; Fri, 14 Apr 2023 15:19:54 +0000 Received: from SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::bb8d:7344:7172:6ee]) by SJ0PR03MB6423.namprd03.prod.outlook.com ([fe80::bb8d:7344:7172:6ee%3]) with mapi id 15.20.6277.038; Fri, 14 Apr 2023 15:19:54 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d3691e90-dad7-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1681485603; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=KZASkSgfwqRxMeZvPhT1iszvELyMTNOOjVdR7aVlPNk=; b=gx/grlOM4nFEmctYR7eZkuK3/21fHsDwRkA7b/SnppcspBLA8Xnc6hGB tNcwAiDVOQJyfgDIed49uX1WNTle/LZVrxkdrI4UsgLLg+GOnKH5TNAuS B3EN5qtTzbc0V+VuPK0Fcszz0PyHUWGyf8V+8n/iARSRY+GrBCasWjVIU A=; X-IronPort-RemoteIP: 104.47.74.43 X-IronPort-MID: 105442746 X-IronPort-Reputation: None X-IronPort-Listener: OutboundMail X-IronPort-SenderGroup: RELAY_O365 X-IronPort-MailFlowPolicy: $RELAYED IronPort-Data: A9a23:PMUg7aD6EOmkpxVW/x3iw5YqxClBgxIJ4kV8jS/XYbTApD0h1zRUz 2tKWWqAPP+LN2ajedt2a97g9UpS6M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w4auu99m91x/nzmfWq7hGhdf7zdNHJcqUzuwYMC/lhAqEbJloH5eCoDc2iuey70tCqq iFnz4Qe+BIr1/BdGC8phXgnyHmzTYV8nfnjXuVm2Hqr8DVTC8zT5Mpv/MRTjLpr24b+P1s2q NC2GyU87JREBP7hSz4o/zFTQtjmEaYqWcr1cQTk3tce40Db6I5l/1owGplVLM7WA7q4oEuF+ djSOna+fZtaFufK0vUu2F+qebcLEgbL1OjeAwvq8aV2z9ZkDRS1E0D3vESmX8G6dYUV4REz/ 6sCNUmqJh+CustKY5tDuYIRsW6TkbXRwjXDW6UKVP7UIkaJnP2rYLt6rld3pDnRHUx9upypH 39aiIZiYZrEHieSvFmnac7vywleV/NEwgEkaplltpEUr6VfsuZDcTMciFqryKamYRgPiTqYY fOBHtoOY6dEYKXI/cu4+TfYegmFZBMarxghv8LH3Szn+nsFqrG8sTmTde7HsucLd9jYBK0Pk c+ X-Talos-CUID: 9a23:dKHvXG7k280+QGZHVNss9HMoRMd0bULm90yLDW+JNF9nRq+8RgrF X-Talos-MUID: 9a23:1smJzAnYnR5Fggo7No9HdnpYMvU4xPX+NXswurAd45ePbjZhPGeS2WE= X-IronPort-AV: E=Sophos;i="5.99,197,1677560400"; d="scan'208";a="105442746" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dYN+lxuu97RJHO2KlJdpI6kgwB6sLFE0RXADMxGi2OwqKy7f9forBs0JSw0nViXUe0r1ufJY9yFz7tbVIpZMIzGy+RNRdVz8LiaY8L+WuHkE6lZIITNwj9dDNg3CJ5VBf4++IzyFk4nXOMIVSC8OAqtIq9DyAYH8HbQDh/fi4s8nh9n5qbglLVfoisW13SmKZbt20+K9uYuLw2t9eGyQqqZAAG8jCdsVRaJR9Y9V11z2YI5NbKw0k4M77vgEBmNujuOeAzStj6wd4dXO3mHm9+RSmU2hw5MzFMRpOGoB5/DXhdeGPxqMUGqAE7y9OMJ6xyk7d13qIsCk033bd931EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=1p+jVcCxqzh6neMgNDhH9OkgSf5UEdomAAqkuunpqpE=; b=ZGEm+0IDixL5x2Rii4qzaksWrl1r3eH1HH+dMiYCvJgYOSypVIzYxXzcums3XA7tVufYQmklpUKm8HbviKAD1RzT/k+IyHZNekyzEYrS2bYukFt653pnkzt9Rj/Q6Ofy3qGNJqEzv6tem7wM9cW5h+wReOFn7JLtCHZbnNxJO8cuII74xqm/sSIhV4kPTiaSDZKwlvEUtOEkfl4dOpO3O2NOJ+knqX205wgaq+iG5iOmdudatw+PxT6lf+zTo4ud1hzf6XRxb5SoxGEA1LApd+rklGWzvPi28/4SvZyiHmzR0uJX3tVIlLGI3LEsYyhKWCqR/uOk151YYt+9pBNxzA== 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.onmicrosoft.com; s=selector2-citrix-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1p+jVcCxqzh6neMgNDhH9OkgSf5UEdomAAqkuunpqpE=; b=c0nl3uUaW82dStoUESvSzuPfx6dzPwB9RIcoXGkWCBX6rMrLAs7gj+8uyu9Dq6fY01Q58oovQcMdjMhBWooEzRGHoJYOrKGnX/59YOE/1gUEcmicV6iIjjGlkR/t9hwYZvDEGuxGYvD3j+VsG04FNj6dVTVjmRKFj55CDhYylAg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com; From: Roger Pau Monne To: xen-devel@lists.xenproject.org Cc: Josh Poimboeuf , =?utf-8?q?Roger_Pau_Monn=C3=A9?= , Konrad Rzeszutek Wilk , Ross Lagerwall Subject: [PATCH] create-diff-object: handle missing padding at end of special section Date: Fri, 14 Apr 2023 17:19:33 +0200 Message-Id: <20230414151933.53851-1-roger.pau@citrix.com> X-Mailer: git-send-email 2.40.0 X-ClientProxiedBy: LO4P265CA0204.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:318::14) To SJ0PR03MB6423.namprd03.prod.outlook.com (2603:10b6:a03:38d::21) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR03MB6423:EE_|PH7PR03MB7223:EE_ X-MS-Office365-Filtering-Correlation-Id: d35c8331-6aaa-47cd-d3a5-08db3cfbb2eb X-LD-Processed: 335836de-42ef-43a2-b145-348c2ee9ca5b,ExtAddr,ExtFwd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GPnMOhTNJGjqYRWEdqdljf5rBh2dDiFcQzR9osoM4QwKEUBCqxGCnOXgRQaOXFd7nazPTO+2YYKvn83gnSgLDEOyVc9+Bdpyo3g6bRvYC99sUOmut63FkX+5j89Bd9JPeUnanId3kaGS221nTH9UYmDSsILK2tSHt3h5pqC/lBhhBlxAKci4csHqppoWDwzpKmPTLhFss+r7zz3whzJKZ+QinJi05IeK2wEAzdQIpZ2V7kGtmo6Z+9nM3xLyE2E61xIM/bTdBFLQL8GS5n5E/qoo8bASi+aSGEBTY/kwTomrTVR4DkxADd+yKyAUDpAyl07dCuFblu9fQ4VOyIgtoQxRBVUp5PslHa21Qp06e/g1zWtvUYJoclhWD3rTHWOiABcW2lULHMW5fs15oagUi7wnyLjH7vFWc/0R4IlCx0Bmw6UJ7thOuDuBqfK73lqmAPTJfpyYDoxn6gEkSBmI3En1gPMg+Leq9tR9zvsg28JvwCLtdd4/N8xOqk6jrwc727O6E4ZYy6RPTOQZSgLLgfDaBr5GjvdpXlrUTaZUjF4Kn3GQBWerVPSuaFcCPVLg X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR03MB6423.namprd03.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(366004)(346002)(376002)(39860400002)(396003)(136003)(451199021)(36756003)(6486002)(4326008)(41300700001)(6916009)(66946007)(54906003)(66556008)(478600001)(8676002)(66476007)(316002)(86362001)(2616005)(6506007)(1076003)(83380400001)(6666004)(6512007)(107886003)(26005)(2906002)(5660300002)(82960400001)(8936002)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?qmFTydTkdEXddsxb2gN7lKsWwoD1?= =?utf-8?q?nb6L5Q1P8JbsMTe9ZkQMsxyg3m3C/+AFHfEkCp02Jq8GnNKtljDmHFmpce/f+XZKp?= =?utf-8?q?Wx72cbjkEBlJJTinPHTKaKK0S3+/A81i/rp0SJUdMIYgP+zJ+QHjaOsKcSz4c08ch?= =?utf-8?q?s2BQiS92aYFUTNvLa/8j4XC3hdrgiwko7NbW6GI4o61Bn0GUUvX+a/SVF2xXWNN6H?= =?utf-8?q?1kByevor7ivJRTAlY49gMlNXq1iNqJveex2YHqdngqpdErpP4b7VOYYxoKh8VKnf2?= =?utf-8?q?ZkDJ+Ybz07/DsbqweaKqkdawuFJ5wKzSzNfWOj9l7jEpv4aucVqgmiGxBCHCdGC1X?= =?utf-8?q?AhAZ8/z052nk0aMEAXgNE1B8sTyQCFyoXI5+3Io3p49UVObJFFHGB35cNaJaylphm?= =?utf-8?q?f2i2C1wC8IspOS7jiUIfkULT5rUSy6AftMlKRkZyq8ZvQMrae9v3i1761x1ZWh8UE?= =?utf-8?q?cKLK9j8xDwUpkbX2oKF1Z0zkGqGI1ghrH9LdzDW13z7uRaJsPluaihnRQB4V4QoY5?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+Jqxr0zVQFlpGXCjJg6zBng== X-OriginatorOrg: citrix.com X-MS-Exchange-CrossTenant-Network-Message-Id: d35c8331-6aaa-47cd-d3a5-08db3cfbb2eb X-MS-Exchange-CrossTenant-AuthSource: SJ0PR03MB6423.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 14 Apr 2023 15:19:54.4118 (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: 9GfrlnQDQuZLeQeIenbIie23AMmGLK34uptR1JDTZGp/D0uBbkwheuqr+s6wNI4FlqC58LH0LYC5bcEM0YU3KQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR03MB7223 From: Josh Poimboeuf The paravirt_patch_site struct has 12 bytes of data and 4 bytes of padding, for a total of 16 bytes. However, when laying out the structs in the .parainstructions section, the vmlinux script only aligns before each struct's data, not after. So the last entry doesn't have the 4-byte padding, which breaks kpatch_regenerate_special_section()'s assumption of a 16-byte struct, resulting in a memcpy past the end of the section. Fixes #747. Signed-off-by: Josh Poimboeuf This is commit: c2dc3836e862 create-diff-object: handle missing padding at end of special section In kpatch repository. I've seen the .fixup section get an alignment of 16 but a size of 81, which makes the error removed in this patch trigger. Overall I'm not sure why the original alignment check was done against the size of the section, the alignment applies to the address of the section, not its size. Signed-off-by: Roger Pau Monné Acked-by: Andrew Cooper Reviewed-by: Ross Lagerwall --- Cc: Konrad Rzeszutek Wilk Cc: Ross Lagerwall --- create-diff-object.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/create-diff-object.c b/create-diff-object.c index d8a003216096..67784642bcd7 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1204,7 +1204,7 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, { struct rela *rela, *safe; char *src, *dest; - int group_size, src_offset, dest_offset, include, align, aligned_size; + int group_size, src_offset, dest_offset, include; LIST_HEAD(newrelas); @@ -1234,6 +1234,18 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, for ( ; src_offset < sec->base->sh.sh_size; src_offset += group_size) { group_size = special->group_size(kelf, src_offset); + + /* + * In some cases the struct has padding at the end to ensure + * that all structs after it are properly aligned. But the + * last struct in the section may not be padded. In that case, + * shrink the group_size such that it still (hopefully) + * contains the data but doesn't go past the end of the + * section. + */ + if (src_offset + group_size > sec->base->sh.sh_size) + group_size = sec->base->sh.sh_size - src_offset; + include = should_keep_rela_group(sec, src_offset, group_size); if (!include) @@ -1269,12 +1281,6 @@ static void kpatch_regenerate_special_section(struct kpatch_elf *kelf, dest_offset += group_size; } - /* verify that group_size is a divisor of aligned section size */ - align = sec->base->sh.sh_addralign; - aligned_size = ((sec->base->sh.sh_size + align - 1) / align) * align; - if (src_offset != aligned_size) - ERROR("group size mismatch for section %s\n", sec->base->name); - if (!dest_offset) { /* no changed or global functions referenced */ sec->status = sec->base->status = SAME;