From patchwork Thu Jan 19 10:13:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihails Strasuns X-Patchwork-Id: 13107676 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 00E6AC00A5A for ; Thu, 19 Jan 2023 10:15:13 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.480911.745567 (Exim 4.92) (envelope-from ) id 1pIRwf-0000Tp-N0; Thu, 19 Jan 2023 10:14:57 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 480911.745567; Thu, 19 Jan 2023 10:14:57 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRwf-0000TX-Jn; Thu, 19 Jan 2023 10:14:57 +0000 Received: by outflank-mailman (input) for mailman id 480911; Thu, 19 Jan 2023 10:14:22 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRw6-0007Sb-Sz for xen-devel@lists.xenproject.org; Thu, 19 Jan 2023 10:14:22 +0000 Received: from smtp-fw-80007.amazon.com (smtp-fw-80007.amazon.com [99.78.197.218]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0985ffd9-97e2-11ed-91b6-6bf2151ebd3b; Thu, 19 Jan 2023 11:14:21 +0100 (CET) Received: from pdx4-co-svc-p1-lb2-vlan3.amazon.com (HELO email-inbound-relay-iad-1e-m6i4x-7dc0ecf1.us-east-1.amazon.com) ([10.25.36.214]) by smtp-border-fw-80007.pdx80.corp.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 10:14:17 +0000 Received: from EX13D45EUA003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1e-m6i4x-7dc0ecf1.us-east-1.amazon.com (Postfix) with ESMTPS id AFD1B83352 for ; Thu, 19 Jan 2023 10:14:15 +0000 (UTC) Received: from EX19D039EUA004.ant.amazon.com (10.252.50.95) by EX13D45EUA003.ant.amazon.com (10.43.165.71) with Microsoft SMTP Server (TLS) id 15.0.1497.45; Thu, 19 Jan 2023 10:14:13 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX19D039EUA004.ant.amazon.com (10.252.50.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.7; Thu, 19 Jan 2023 10:14:13 +0000 Received: from dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (172.19.92.214) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.45 via Frontend Transport; Thu, 19 Jan 2023 10:14:12 +0000 Received: by dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (Postfix, from userid 17415739) id 8126F21426; Thu, 19 Jan 2023 10:14:12 +0000 (UTC) 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 Sender: "Xen-devel" X-Inumbo-ID: 0985ffd9-97e2-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1674123262; x=1705659262; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4hf1x7Xe4bXRLb6h+Ksi8ZE8+Xk4HBnSsvCu7j+CUQ4=; b=nUKTLNs6VsJLVg0yLiH7j7Q9MHx6dzSiqZmmGoJxY8FxPds9AhAFBV4l qRSCRlKVGoO8rDABdOJf74K5UZ+prgZBd1rZ3uymNR3ZsRG+MWIwhDVTU TC7NmyI6qGtoLWWE+HVn6VS8L+I/3l+bLLOCr7QnWrJkPg9B+l1wjY+Xf s=; X-IronPort-AV: E=Sophos;i="5.97,228,1669075200"; d="scan'208";a="172738134" From: Mihails Strasuns To: CC: , Michael Kurth Subject: [PATCH v1 1/4] common.h: Flush stdout before writing to stderr Date: Thu, 19 Jan 2023 10:13:02 +0000 Message-ID: <2e89973f61bbd6e6ebb423ec6fe7a025d5404235.1673623880.git.mstrasun@amazon.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk Flush existing debug messages before writing an error to stderr. stderr is usually unbuffered and stdout is usually buffered. This results in odd looking output when an error occurs and both stderr/stdout are printed on the same console/file. More precisely, the error message is printed in the middle of previously emitted debug messages. Signed-off-by: Michael Kurth Reviewed-by: Ross Lagerwall --- common.h | 1 + 1 file changed, 1 insertion(+) diff --git a/common.h b/common.h index 02c9b7b..9a9da79 100644 --- a/common.h +++ b/common.h @@ -10,6 +10,7 @@ extern char *childobj; #define DIFF_FATAL(format, ...) \ ({ \ + fflush(stdout); \ fprintf(stderr, "ERROR: %s: " format "\n", childobj, ##__VA_ARGS__); \ error(2, 0, "unreconcilable difference"); \ }) From patchwork Thu Jan 19 10:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihails Strasuns X-Patchwork-Id: 13107673 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 8FD9BC004D4 for ; Thu, 19 Jan 2023 10:14:59 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.480913.745537 (Exim 4.92) (envelope-from ) id 1pIRwP-0007lT-RG; Thu, 19 Jan 2023 10:14:41 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 480913.745537; Thu, 19 Jan 2023 10:14:41 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRwP-0007lK-NZ; Thu, 19 Jan 2023 10:14:41 +0000 Received: by outflank-mailman (input) for mailman id 480913; Thu, 19 Jan 2023 10:14:40 +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 1pIRwO-0007kn-DI for xen-devel@lists.xenproject.org; Thu, 19 Jan 2023 10:14:40 +0000 Received: from smtp-fw-2101.amazon.com (smtp-fw-2101.amazon.com [72.21.196.25]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 140a99f7-97e2-11ed-b8d1-410ff93cb8f0; Thu, 19 Jan 2023 11:14:38 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-2101.iad2.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 10:14:34 +0000 Received: from EX13D50EUA002.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1a-m6i4x-96feee09.us-east-1.amazon.com (Postfix) with ESMTPS id 3D6C842F0E for ; Thu, 19 Jan 2023 10:14:34 +0000 (UTC) Received: from EX19D003EUA004.ant.amazon.com (10.252.50.128) by EX13D50EUA002.ant.amazon.com (10.43.165.201) with Microsoft SMTP Server (TLS) id 15.0.1497.45; Thu, 19 Jan 2023 10:14:33 +0000 Received: from EX13MTAUEE002.ant.amazon.com (10.43.62.24) by EX19D003EUA004.ant.amazon.com (10.252.50.128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.7; Thu, 19 Jan 2023 10:14:33 +0000 Received: from dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (172.19.92.214) by mail-relay.amazon.com (10.43.62.224) with Microsoft SMTP Server id 15.0.1497.45 via Frontend Transport; Thu, 19 Jan 2023 10:14:32 +0000 Received: by dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (Postfix, from userid 17415739) id 19BEB21426; Thu, 19 Jan 2023 10:14:32 +0000 (UTC) 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 Sender: "Xen-devel" X-Inumbo-ID: 140a99f7-97e2-11ed-b8d1-410ff93cb8f0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1674123278; x=1705659278; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2xU/uBcWEWbfzk2TqLk64mpRRkZpjZZO7FkjawvYQC8=; b=XwJ0oRAz/IEfDDBcyv6oPOgWj5WE8hqfb1DuEJZdQM2/DDx+iUhyJvVH 6G3VC0pnt37F1kgwwhmQ1MbihMrhGpI8aEDhooo8sbzOpGE3FuKDE7Fl7 bWHJXDm53j4046GY3cLLilt9HmAdlkWatYBtFz4L1QHhshjX2UUSr0UAO k=; X-IronPort-AV: E=Sophos;i="5.97,228,1669075200"; d="scan'208";a="284332618" From: Mihails Strasuns To: CC: , Raphael Ning , Bjoern Doebel , Martin Pohlack Subject: [PATCH v1 2/4] livepatch-build: Allow a patch to introduce new subdirs Date: Thu, 19 Jan 2023 10:13:04 +0000 Message-ID: <472bfbf92aba6d3409b2a101798f04a50c97f6e9.1673623880.git.mstrasun@amazon.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk From: Raphael Ning Fix a bug in create_patch() where cp, strip, etc. will fail if the new object file introduced by the patch is located in a new subdirectory: DEBUG: cp: cannot create regular file `output/xen/common/lu/lu.o': No such file or directory DEBUG: strip: 'output/xen/common/lu/lu.o': No such file In this example, xen/common/lu/ does not exist in the original (unpatched) Xen source tree. It needs to be created in output/ as well. Signed-off-by: Raphael Ning Reviewed-by: Bjoern Doebel Reviewed-by: Martin Pohlack Reviewed-by: Ross Lagerwall --- livepatch-build | 1 + 1 file changed, 1 insertion(+) diff --git a/livepatch-build b/livepatch-build index f7d6471..444daa9 100755 --- a/livepatch-build +++ b/livepatch-build @@ -232,6 +232,7 @@ function create_patch() NEW_FILES=$(comm -23 <(cd patched/xen && find . -type f -name '*.o' | sort) <(cd original/xen && find . -type f -name '*.o' | sort)) for i in $NEW_FILES; do + mkdir -p "output/$(dirname "$i")" cp "patched/$i" "output/$i" [[ $STRIP -eq 1 ]] && strip --strip-unneeded "output/$i" CHANGED=1 From patchwork Thu Jan 19 10:13:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihails Strasuns X-Patchwork-Id: 13107674 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 3DC95C38142 for ; Thu, 19 Jan 2023 10:15:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.480914.745547 (Exim 4.92) (envelope-from ) id 1pIRwX-00089y-2p; Thu, 19 Jan 2023 10:14:49 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 480914.745547; Thu, 19 Jan 2023 10:14:49 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRwW-00089r-VI; Thu, 19 Jan 2023 10:14:48 +0000 Received: by outflank-mailman (input) for mailman id 480914; Thu, 19 Jan 2023 10:14:47 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRwV-0007Sb-Ka for xen-devel@lists.xenproject.org; Thu, 19 Jan 2023 10:14:47 +0000 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 18968994-97e2-11ed-91b6-6bf2151ebd3b; Thu, 19 Jan 2023 11:14:46 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-iad-1d-m6i4x-d7759ebe.us-east-1.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 10:14:39 +0000 Received: from EX13D51EUB004.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan2.iad.amazon.com [10.40.163.34]) by email-inbound-relay-iad-1d-m6i4x-d7759ebe.us-east-1.amazon.com (Postfix) with ESMTPS id 7BB8B43948 for ; Thu, 19 Jan 2023 10:14:37 +0000 (UTC) Received: from EX19D029EUB004.ant.amazon.com (10.252.61.53) by EX13D51EUB004.ant.amazon.com (10.43.166.217) with Microsoft SMTP Server (TLS) id 15.0.1497.45; Thu, 19 Jan 2023 10:14:37 +0000 Received: from EX13MTAUEB002.ant.amazon.com (10.43.60.12) by EX19D029EUB004.ant.amazon.com (10.252.61.53) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.1118.7; Thu, 19 Jan 2023 10:14:36 +0000 Received: from dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (172.19.92.214) by mail-relay.amazon.com (10.43.60.234) with Microsoft SMTP Server id 15.0.1497.45 via Frontend Transport; Thu, 19 Jan 2023 10:14:35 +0000 Received: by dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (Postfix, from userid 17415739) id D06FE21426; Thu, 19 Jan 2023 10:14:35 +0000 (UTC) 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 Sender: "Xen-devel" X-Inumbo-ID: 18968994-97e2-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1674123287; x=1705659287; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7xjJSEeZVrQKBcQS6rbLeHu3TkZB46tvdM9kg8Ho5tM=; b=aNgiJynxj0bg3dDNDMgoWCjqWlJ0A/jbpo9W64C5Nk6+ybwbUuUIzkpl G2Wa6lQiLtBGqJqRMuHwUzIwwRIaNdQdA8eD0d4HPhOTFT5saVtPfQWFe N6KRDO2F7+5FS+iUMPVMA7d4/QTUVSrwYt8SDd1BsZYnFrsbZwsdcdnKu 8=; X-IronPort-AV: E=Sophos;i="5.97,228,1669075200"; d="scan'208";a="256252891" From: Mihails Strasuns To: CC: , Raphael Ning , Bjoern Doebel , Martin Pohlack Subject: [PATCH v1 3/4] livepatch-gcc: Ignore buildid.o Date: Thu, 19 Jan 2023 10:13:05 +0000 Message-ID: <477a6e0f0b0088c54f3f048bf2b4593eb4df18af.1673623880.git.mstrasun@amazon.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk From: Raphael Ning Not all .o files generated by the Xen build need to be passed to create-diff-object for analysis. The latest example is: Run create-diff-object on xen/arch/x86/efi/buildid.o Open base /usr/libexec/livepatch-build-tools/create-diff-object: ERROR: buildid.o: kpatch_create_section_list: 77: elf_getshdrnum This file is special, as it does not contain any sections. It is generated by objcopy from a magic string of bytes (see Xen commit eee5909e9d1e x86/EFI: use less crude a way of generating the build ID), which probably will never change. Therefore, livepatch-gcc should not copy it to the output directory. Signed-off-by: Raphael Ning Reviewed-by: Bjoern Doebel Reviewed-by: Martin Pohlack CR: https://code.amazon.com/reviews/CR-63147772 Reviewed-by: Ross Lagerwall --- livepatch-gcc | 1 + 1 file changed, 1 insertion(+) diff --git a/livepatch-gcc b/livepatch-gcc index 91333d5..e72cc8d 100755 --- a/livepatch-gcc +++ b/livepatch-gcc @@ -65,6 +65,7 @@ elif [[ "$TOOLCHAINCMD" =~ $OBJCOPY_RE ]] ; then version.o|\ debug.o|\ efi/check.o|\ + buildid.o|\ .*.o) ;; *.o) From patchwork Thu Jan 19 10:13:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihails Strasuns X-Patchwork-Id: 13107675 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 36F70C004D4 for ; Thu, 19 Jan 2023 10:15:06 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.480915.745557 (Exim 4.92) (envelope-from ) id 1pIRwY-0008R9-9b; Thu, 19 Jan 2023 10:14:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 480915.745557; Thu, 19 Jan 2023 10:14:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRwY-0008Qs-6q; Thu, 19 Jan 2023 10:14:50 +0000 Received: by outflank-mailman (input) for mailman id 480915; Thu, 19 Jan 2023 10:14:49 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pIRwW-0007Sb-VV for xen-devel@lists.xenproject.org; Thu, 19 Jan 2023 10:14:49 +0000 Received: from smtp-fw-33001.amazon.com (smtp-fw-33001.amazon.com [207.171.190.10]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 19f1060f-97e2-11ed-91b6-6bf2151ebd3b; Thu, 19 Jan 2023 11:14:47 +0100 (CET) Received: from iad12-co-svc-p1-lb1-vlan3.amazon.com (HELO email-inbound-relay-pdx-2a-m6i4x-8a14c045.us-west-2.amazon.com) ([10.43.8.6]) by smtp-border-fw-33001.sea14.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 19 Jan 2023 10:14:44 +0000 Received: from EX13D48EUA002.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-pdx-2a-m6i4x-8a14c045.us-west-2.amazon.com (Postfix) with ESMTPS id 3F2A383120 for ; Thu, 19 Jan 2023 10:14:42 +0000 (UTC) Received: from EX19D042EUA004.ant.amazon.com (10.252.50.16) by EX13D48EUA002.ant.amazon.com (10.43.165.27) with Microsoft SMTP Server (TLS) id 15.0.1497.45; Thu, 19 Jan 2023 10:14:40 +0000 Received: from EX13MTAUWB001.ant.amazon.com (10.43.161.207) by EX19D042EUA004.ant.amazon.com (10.252.50.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.1118.7; Thu, 19 Jan 2023 10:14:40 +0000 Received: from dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (172.19.92.214) by mail-relay.amazon.com (10.43.161.249) with Microsoft SMTP Server id 15.0.1497.45 via Frontend Transport; Thu, 19 Jan 2023 10:14:38 +0000 Received: by dev-dsk-mstrasun-1c-15417e94.eu-west-1.amazon.com (Postfix, from userid 17415739) id CB9DE21426; Thu, 19 Jan 2023 10:14:38 +0000 (UTC) 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 Sender: "Xen-devel" X-Inumbo-ID: 19f1060f-97e2-11ed-91b6-6bf2151ebd3b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1674123288; x=1705659288; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gXy2lSCqzAzPVhs9Pixrebyr+33aF5wrQ+8+7LICdlw=; b=RxuYz8n7hbLoIRnhaMyplwEpnpFgya/QnJazk6905YwuO7DvgY7yhpZG 8/czkV+UicRU/2zHvrwZ6SC8CoO0BlJ2WwNIjSi1FGRhLubPUKnMdvDcb HjQQWqpT2CVHlQ+pw3dPIrnbuGnFeZKn/IOQ5uQbLmflomVU+td5/p099 E=; X-IronPort-AV: E=Sophos;i="5.97,228,1669075200"; d="scan'208";a="256252906" From: Mihails Strasuns To: CC: , Stanislav Uschakow , "Bjoern Doebel" , Martin Pohlack Subject: [PATCH v1 4/4] create-diff-object: Add new symbols for relocation aliases Date: Thu, 19 Jan 2023 10:13:06 +0000 Message-ID: X-Mailer: git-send-email 2.38.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk From: Stanislav Uschakow This fixes an issue when stacking multiple hotpatches modifying the same function when there is also an internal call to that function within these patches. Two hotpatches touching the same subset of functions can result in a situation where the second hotpatch is loaded but the code is never executed. This happens when the symbol resolution of the first hotpatch calculates the target address for the relocation entries based on the hotpach instead of the original function. The resulting address for the relocation-target will become the patched function instead of the original one (A' -> B' instead of A' -> B). In this case the trampoline in the original function is not used. Patching this function again (B'') re-sets the trampoline to the newly patched method. Since callq points to the first patched function it never reaches the second version. 2nd patch | B'' 1st patch | A' -> B' original | A -> B This fix provides a solution for this problem by resolving the symbols during patch generation using xen-syms. The patch iterates over all relocation entries, and creates duplicates of all referenced symbols with the scope set to SHN_ABS and the address to the one resolved from xen-syms. This new symbol is prefixed with a unique string to generate a new name. This forces all calls to be directed to the original function which contains the trampoline. Signed-off-by: Stanislav Uschakow Signed-off-by: Mihails Strasuns Reviewed-by: Bjoern Doebel Reviewed-by: Martin Pohlack --- create-diff-object.c | 132 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/create-diff-object.c b/create-diff-object.c index a516670..808b288 100644 --- a/create-diff-object.c +++ b/create-diff-object.c @@ -1878,6 +1878,25 @@ static char *mangle_local_symbol(char *filename, char *symname) return s; } +/* + * For a given mangled symbol name allocates a copy with the filename and the + * unmangled symbol separated by a null terminator. + */ +static bool unmangle_local_symbol(const char *mangled, char **filename, + char **symname) +{ + if (filename == NULL || symname == NULL) + ERROR("Malformed output arguments passed to 'unmangle_local_symbol'"); + char *sep = strchr(mangled, '#'); + if (!sep) + return false; + int i = sep - mangled; + *filename = strdup(mangled); + (*filename)[i] = '\0'; + *symname = *filename + i + 1; + return true; +} + /* * Rename local symbols to the filename#symbol format used by Xen's "special" * symbol table. @@ -2290,6 +2309,116 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) return 0; } +/* + * For a given elf output target add a new entry to the symbol table + * which duplicates the provided source symbol. + */ +static struct symbol *insert_symbol_copy(struct kpatch_elf *elf, + struct symbol *src, int index, + char *new_name) +{ + struct symbol *new_sym; + ALLOC_LINK(new_sym, &elf->symbols); + new_sym->index = index; + new_sym->twin = NULL; + new_sym->sec = NULL; + new_sym->bind = src->bind; + new_sym->type = src->type; + new_sym->status = NEW; + new_sym->strip = 0; + new_sym->name = new_name; + /* The copy here will keep referring to the original symbol + name which is fine - it will be updated later during the final elf + generation. */ + new_sym->sym = src->sym; + return new_sym; +} + +/* + * In certain cases when 2 hotpatches are loaded patching the same subset of + * functions calling each other, the topmost hotpatch can become unreachable. + * This is caused by the loader when resolving symbols. If a symbol is both + * to be relocated and loaded (foo calls bar and both are patched to foo' and + * bar'), the callq target in foo' is set to bar' instead of the original bar. + * Patching bar again (bar'') cannot be reached from foo' because foo' does not + * use the trampoline in bar. + * + * This post-processing function fixes the problem by updating all + * non-livepatch relocation entries (i.e. originally created by a compiler) to + * be based on a special SHN_ABS with a fixed value resolved from xen-syms. + * These new symbols are not used by livepatch loader itself and only exist as + * a named constant for the relevant function address in the host process. + * + * All new symbols are prefixed with a scalpel-specific prefix string. As they + * are not used outside of a specific livepatch linking/relocation process, + * the prefix can be the same across multiple livepatches. + */ +void add_absolute_symbol_aliases(struct kpatch_elf *elf, + struct lookup_table *lookup) +{ + const char *prefix = "__livepatch_unique_"; + + int sym_count = 0; + struct symbol *sym; + list_for_each_entry (sym, &elf->symbols, list) + sym_count++; + + struct section *sec; + list_for_each_entry (sec, &elf->sections, list) { + if (!is_rela_section(sec)) + continue; + /* Ignore any relocation sections that are not related to a symbol + text sections: */ + if (strncmp(sec->name, ".rela.text.", 11) != 0) + continue; + + struct rela *rel; + list_for_each_entry (rel, &sec->relas, list) { + if ((rel->sym->type != STT_FUNC) && + (rel->sym->type != STT_OBJECT) && + (rel->sym->type != STT_NOTYPE)) + continue; + if (strlen(rel->sym->name) == 0) + ERROR("Unnamed symbol used in relocation"); + + struct lookup_result res = {0}; + bool found = false; + /* Static/local symbols are mangled to include a filename prefix, + thus need a special treatment for xen-syms lookup: */ + if (rel->sym->bind == STB_LOCAL) { + char *filename, *symname; + if (!unmangle_local_symbol(rel->sym->name, &filename, &symname)) + continue; + found = !lookup_local_symbol(lookup, symname, filename, &res); + } else + found = !lookup_global_symbol(lookup, rel->sym->name, &res); + + if (found) { + char *buf = malloc(strlen(prefix) + strlen(rel->sym->name) + 1); + if (!buf) + ERROR("Failed to allocate buffer\n"); + strcpy(buf, prefix); + strcpy(buf + strlen(prefix), rel->sym->name); + + struct symbol *new_sym = + insert_symbol_copy(elf, rel->sym, sym_count++, buf); + /* Override key fields after copying. GLOBAL/LOCAL binding + most likely doesn't matter here but forcing GLOBAL in case + linker tries to do something smart: */ + new_sym->bind = STB_GLOBAL; + new_sym->sym.st_value = res.value; + new_sym->sym.st_shndx = SHN_ABS; + new_sym->sym.st_info = GELF_ST_INFO(new_sym->bind, new_sym->type); + + /* TODO: translate X86_64_PC32 rel type to X86_64_64 and + validate that the relocation is still correvtly computed. */ + log_debug("Added '%s' alias for '%s'\n", buf, rel->sym->name); + rel->sym = new_sym; + } + } + } +} + static struct argp argp = { options, parse_opt, args_doc, 0 }; int main(int argc, char *argv[]) @@ -2434,6 +2563,9 @@ int main(int argc, char *argv[]) log_debug("Rename local symbols\n"); livepatch_rename_local_symbols(kelf_out, hint); + log_debug("Add absolute symbol aliases for internal calls\n"); + add_absolute_symbol_aliases(kelf_out, lookup); + /* * At this point, the set of output sections and symbols is * finalized. Reorder the symbols into linker-compliant