From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by sourceware.org (Postfix) with ESMTPS id C7D473858D1E for ; Wed, 4 Jan 2023 06:56:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C7D473858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 303JnJvT013588 for ; Wed, 4 Jan 2023 06:56:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : content-transfer-encoding : content-type : mime-version; s=corp-2022-7-12; bh=+uEh8dJ7hQrtxN8CCuyDYhF8Li5zEEl+FPim9wGLHJo=; b=rNEmd1HTeFtFOaMImmtWMNBDbJCZ5TRMitrghV7SdwwjK3Azyx6W1wQZSi3qviknpo9i npu9dh2tjt7sk/5BqFF0GsGPl/oSTcXHejmuohamrimQlkNH4U6UnDhdMpmjI+MNsM7I ACcAFQ01CittPHE98kgk6/SBNR0dyRogiBEex7lX0IQFn2w+9KBuo9HzCyQgGCDz+KZo wPGy4gwse7VBcEdjEKqTBe3vu+g2f8yzmg+2q7FNXl2tGANuoe9UpSFHuT8JaDevtxZp AI3Kc8OWk27/fN8iIN5pU5K1fvXHryIQclhsl1klhqKjDMLutts2JLNRP1T9EEG4MkoN Nw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3mtc0anuj3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 04 Jan 2023 06:56:56 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.5/8.17.1.5) with ESMTP id 3044wqZ1040266 for ; Wed, 4 Jan 2023 06:56:55 GMT Received: from nam12-bn8-obe.outbound.protection.outlook.com (mail-bn8nam12lp2171.outbound.protection.outlook.com [104.47.55.171]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3mw2wf39ar-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 04 Jan 2023 06:56:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P+xU70hnWz43M9TynZBFA75fpnTao7gefkoOSWsEp2nZ+jLIwvcJXwqVTXnGE3EgNXfI3lwpgMZDeEPBWUrkxRZkWTYnNaz7RdcKRuK6Q5lRPW4b4b7KZFCorKQql/BzCehmgJCi/eiLdlO4Vh3SROk6hUpZTNAKHpmFupiHehUf8RmicE71ibNnD9brRb3AVn/lXUrcmSc+JFYQS8x8ar715P+gFNQka0dh7UHeaaE8SpifY9GBJ1isA0NeDGR8vJVQgFMzfXQ7M1/+JbZueJqA37TgalU16+k8pdgtOmAFRbEJsPphAa68IVlx4vQXaXr5avyGbrFV1eIlFEsMHQ== 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=+uEh8dJ7hQrtxN8CCuyDYhF8Li5zEEl+FPim9wGLHJo=; b=cmxg51T6y8KIiSEz1r3luGbzQSRh8TIikC2e7da8rKMYNPyvHVrMecSi4MokehmdwfXwvhCKWT5yudJEntQyvePRsH5w8y7Eld7oYq/WOqY9AT0Uae2Zn/cWLmCei7Xb2huCBHK1OCJr+2ZxTmzwyj/nVszuS6/IRwU3w7yyzAMMiApUk0DMOmNq9gIZudwq06BHjd86cqjhZBdRdjr8YVpr1qC1M9+YllcHhgPh8kJCYuWFqE7O/kEEqV7mtAkhxQ/kahNvtqvK/qFSsIgQsrRVHa79X11jPbV9URND2zXzhsZRQz/Mqs6rEjIfeV3TSQd7GnlLeeUYZsGXDCu9oA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+uEh8dJ7hQrtxN8CCuyDYhF8Li5zEEl+FPim9wGLHJo=; b=b/9kVXEyOWrR2O8bmJ60C8WdwMC8Zt/cHolROfzQySkY1d0tKFMKlPkweWtsv9xHx8lIc8iykpJsQ/34J3Hmf7o8g58Ehbh3UejIbzONdY0I8fMjRQ8FFPmB9U6uhWkV6ibF4k3CswJdleJVy8OVBaAJ+pyJM7bvu+zMXSks5Jo= Received: from MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) by BN0PR10MB5302.namprd10.prod.outlook.com (2603:10b6:408:117::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Wed, 4 Jan 2023 06:56:53 +0000 Received: from MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc]) by MWHPR1001MB2158.namprd10.prod.outlook.com ([fe80::ee70:1952:4416:1bdc%5]) with mapi id 15.20.5944.019; Wed, 4 Jan 2023 06:56:53 +0000 From: Indu Bhagat To: binutils@sourceware.org Cc: Indu Bhagat Subject: [PATCH] libsframe: adjust an incorrect check in flip_sframe Date: Tue, 3 Jan 2023 22:56:11 -0800 Message-Id: <20230104065611.377771-1-indu.bhagat@oracle.com> X-Mailer: git-send-email 2.37.2 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: MW4PR03CA0342.namprd03.prod.outlook.com (2603:10b6:303:dc::17) To MWHPR1001MB2158.namprd10.prod.outlook.com (2603:10b6:301:2d::17) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2158:EE_|BN0PR10MB5302:EE_ X-MS-Office365-Filtering-Correlation-Id: 6781d382-549b-4015-bc7a-08daee20dc5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zgZrecBF9wHuPtXgK3EU1MV5EmV3HIoSAOUxogDGJUx5b+NWhJKxdLeYTSnJcaci1cNuTjitjJZ2qJwmTxf9f8//UqFBdGRBVcQstdvwRMd6NNazlmROuvav1tqSMQc9ufVDAdZ5Cto7UUIWc2kTi5/o1TqQOQpm8cLq1SzqLvHMzeVQYy/fkqOkSRANKc2b3wajkZ86svv5DHyilDj0uiEnVGceeK4rLLPKNJos03xvDOVhWKL039aMQdRpeVg17AJSKQlyYU2IwUeyxDo0bsGQqlBJ/DndnOM1vkWGRb1AwH4pKGj3S5TrT45AcfRCXjUnW5xFnTPG3iuTeJeky4+AJIRack4/1oUm+ZEFZW7k4WmEtMS8m1X+IpWeCkmO5D5zNfip3+iDn5ibh8Iv6n8BlpYVnK8yvxC1Ku+vPwxI5G3XDhMnUcivey11lOjfmB1saavIaoMwiVTvOqWRT1/3yPRLjGDz5RW3P5E7HUEfp9j/ZF1jG17ajVQyTnYbMtz9eLl8kS/4yyQNcG1dhW2OvPUfKDP2jwab6Hv9HfTJqYU20ktFT7C8PmnD0rr/IA+ikJLuTptGigvRctBvsM2u9D/9kW6ntzjNRHCp1Z1mNkSaYsypt3lgrsAnJBysFcmE7TXRci+6ktSB3SNURA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2158.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(396003)(136003)(346002)(376002)(39860400002)(366004)(451199015)(316002)(4326008)(6512007)(6506007)(2906002)(5660300002)(186003)(6916009)(44832011)(6666004)(6486002)(478600001)(41300700001)(107886003)(26005)(86362001)(83380400001)(2616005)(1076003)(38100700002)(66556008)(8676002)(8936002)(66946007)(36756003)(66476007);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?6QXSGLOGi5WOtlQtZ+TNS9TFK2u4eJ5eE7RAl5xgNCNvJ2hwk2QLnMUDkR4Y?= =?us-ascii?Q?5L/BNMDslL6beTUwsLXAxIUYWUza1BH7+YKj2papW/AcHJkUpbsgyTCqYViy?= =?us-ascii?Q?T1hB4RLEGsEbodQZxRUXVKI677vDMTVvSE178vS7q6tYk5A0rUzeR2h5HsrR?= =?us-ascii?Q?QVLRIOaQGdshujaiepBywZEPVunsNkH+z4/wFxSmTcTP168Bj2aH/L02Tr4g?= =?us-ascii?Q?4keA5TUe0h7w49JnzFoGwaBtXehKjvFrf/+ckK+gAzF53ckkLUSCqSxKoUDd?= =?us-ascii?Q?a/9b/KlFXAr9GW0cUvga4kYJjz15T0kL25TecZd7urJ3u9yUyUKj9Ux31y6J?= =?us-ascii?Q?Gi5RRlP7K/d07OBVxUS5jAUm0McduBLrlL74C2y+Hd9i+LbGbUAnk6hYpWEx?= =?us-ascii?Q?+qDuADWZ7ngzgQETFP7R4zdQ7cN2L1AcCs1TQwAhdmpVKUUpbIjzJSFl4O/9?= =?us-ascii?Q?rZnERXVWucyrje4nyiMyOzGux7iXODHByu/mkdzBA35rshRAXiXItkhY0pqg?= =?us-ascii?Q?EciXnndK0bqO2A2AN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-ascii?Q?SBZCV6CzSfmgmp/oPdHAcWTolrhuKpKEP9tFXDpUjTAKbtfLsX9Tzn7Qj39V?= =?us-ascii?Q?UQp4//9olB+fFQp9yxWQxuIcBNyJPxw5tMu/Hk9v/T+Fof9sS/zPbFeHy2MI?= =?us-ascii?Q?DpUYHmvh5lLYdMorEcZh5NTuqHgdn2ZrXtUjNyYG?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: 5ig5q7gwG7fAx9s03cxaZp3HhZelPnk9NmQI4psLqxhgXeFQ40UwYUuEdXQxpUqTi12pGSmh5LYK5zg0ArBixKsjrqDzmYT/iGIp6CnGYq1Y7lGP5t1elacjVlc82pcdpfkBlH8FRp7USssiulSWjiX+ETBN7fnMK2QSpt5VkgavV6B7kDE+M87QpZzTSuVx+16gMWgjKHcAp0mINjpKjgC0kHNx7hIr0nT+WT7um5xVKWww1n8AGegFGxVvRphMtWgiQtW/YK745sUybBX/PKYp1zqzNwLwBTfPLa3rzjTHRSQg3ExBOCCQ8WApe0MVkcrtaVaaN6WmMs+TcR2wHkC9iGWSpKvywG4EMGjK3IkR/f4y95trztZ1X4i36ihZkuHWTgSbD/GsVj5F7Ec6WmYdR0AqzAy+hWl5LS8j8nfvAlxOeSBN+UVACNLygUq1jlA+gS0sj4kI7r/5z9H9dLk1HNrRZ6RQ3Sg5LXwYCWyguicTfdt2X/j10IDNYcDjPfoX0DX+nFN7yuc3CFbXDgj16nCelRicUpsRJ7ntVVHSfLI2A8fcP+e1QJpkSdlKFsKY44ZxKJevOMIo8oPIBBGEgUKqKbR2G10K94DTb4n99EyRg86+52xnfF0L2GCh+BwGueNKupoCVoIo95wVfQ6sNh/a+O3VnrbFsDHvsfnfY52O9iePptzcF766gZS3FiihI7QnDQZgd2Q9mdbVoDM7AZb8lzduS1Jn/t7BtARIHatCYTdZ0DGyKIlJh6p9 X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6781d382-549b-4015-bc7a-08daee20dc5f X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2158.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Jan 2023 06:56:53.2472 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: d0asT/85y4MKLFi3f5PktYpPIUW9exMjujPyTl3YkMELRp4hGJJyEX8t5aarIzVM2BQaegmBYZDOOjiWnxGkGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB5302 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-04_03,2023-01-03_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 adultscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301040057 X-Proofpoint-GUID: jU4DPYM1NVBRDTVfoAbiRbe2rw4s5Ilg X-Proofpoint-ORIG-GUID: jU4DPYM1NVBRDTVfoAbiRbe2rw4s5Ilg X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, While testing the endian flipping code in libsframe, I tried a cross build with --target=x86_64-linux on a big-endian system (ppc64), and I ran into some SFrame testsuite failures: FAIL: SFrame Simple link FAIL: SFrame for plt0 and pltN The reason for failure is explained below in the commit log. This patch fixes the issue. Testing notes: - Reg tested native and cross builds on x86_64 and aarch64 (checked binutils, ld, gas, libctf, libsframe). - try bot shows no new regressions. - Tested ld, gas with a cross build: --target=x86_64-linux on ppc64 host. The two testcase failures are resolved with this patch. Before the patch: FAIL: SFrame Simple link FAIL: SFrame for plt0 and pltN === ld Summary === # of expected passes 1651 # of unexpected failures 2 # of expected failures 3 # of untested testcases 26 # of unsupported tests 134 After the patch: === ld Summary === # of expected passes 1653 # of expected failures 3 # of untested testcases 26 # of unsupported tests 134 OK for master and binutils-2_40-branch ? Thanks -------------------------------------- When sframe_encoder_write needs to flip the buffer containing the SFrame section before writing, it is not necessary that the SFrame FDES are in the order of their sfde_func_start_fre_off. On the contrary, SFrame FDEs will be sorted in the order of their start address. So, remove this incorrect assumption which is basically assuming that the last sfde_func_start_fre_off seen will help determine the end of the flipped buffer. The function now keeps track of the bytes_flipped and then compares it with the expected value. Also, added two more checks at appropriate places: - check that the SFrame FDE read is within bounds - check that the SFrame FRE read is within bounds ChangeLog: * libsframe/sframe.c (flip_sframe): Adjust an incorrect check. Add other checks to ensure reads are within the buffer size. --- libsframe/sframe.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/libsframe/sframe.c b/libsframe/sframe.c index 4aada1a25e0..d206780289a 100644 --- a/libsframe/sframe.c +++ b/libsframe/sframe.c @@ -401,7 +401,10 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) unsigned int fre_type = 0; uint32_t fre_offset = 0; size_t esz = 0; + size_t hdrsz = 0; int err = 0; + /* For error checking. */ + size_t bytes_flipped = 0; /* Header must be in host endianness at this time. */ ihp = (sframe_header *)frame_buf; @@ -411,14 +414,18 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) /* The contents of the SFrame header are safe to read. Get the number of FDEs and the first FDE in the buffer. */ + hdrsz = sframe_get_hdr_size (ihp); num_fdes = ihp->sfh_num_fdes; - fdes = frame_buf + sframe_get_hdr_size (ihp) + ihp->sfh_fdeoff; + fdes = frame_buf + hdrsz + ihp->sfh_fdeoff; fdep = (sframe_func_desc_entry *)fdes; j = 0; prev_frep_index = 0; for (i = 0; i < num_fdes; fdep++, i++) { + if ((char*)fdep >= (frame_buf + buf_size)) + goto bad; + if (to_foreign) { num_fres = fdep->sfde_func_num_fres; @@ -427,6 +434,7 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) } flip_fde (fdep); + bytes_flipped += sizeof (sframe_func_desc_entry); if (!to_foreign) { @@ -441,20 +449,16 @@ flip_sframe (char *frame_buf, size_t buf_size, uint32_t to_foreign) { if (flip_fre (fp, fre_type, &esz)) goto bad; + bytes_flipped += esz; - if (esz == 0) + if (esz == 0 || esz > buf_size) goto bad; fp += esz; } prev_frep_index = j; } - /* All FREs must have been endian flipped by now. */ - if (j != ihp->sfh_num_fres) - goto bad; - /* Contents, if any, must have been processed by now. - Recall that .sframe section with just a SFrame header may be generated by - GAS if no SFrame FDEs were found for the input file. */ - if (ihp->sfh_num_fres && ((frame_buf + buf_size) != (void*)fp)) + /* All FDEs and FREs must have been endian flipped by now. */ + if ((j != ihp->sfh_num_fres) || (bytes_flipped != (buf_size - hdrsz))) goto bad; /* Success. */ -- 2.37.2