From patchwork Wed Oct 12 02:23:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shung-Hsi Yu X-Patchwork-Id: 13004599 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DACDAC433FE for ; Wed, 12 Oct 2022 02:24:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbiJLCYQ (ORCPT ); Tue, 11 Oct 2022 22:24:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiJLCYQ (ORCPT ); Tue, 11 Oct 2022 22:24:16 -0400 Received: from EUR02-AM5-obe.outbound.protection.outlook.com (mail-eopbgr00044.outbound.protection.outlook.com [40.107.0.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7ECA43E59 for ; Tue, 11 Oct 2022 19:24:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XZVktbnfqvvoNB7Hv7V5JpqdPtERiY1iidC+BjzCh8ekhglBJupGwglnNmhEfJaprLGIEYxHSKkXI0PLeToWXmYvCTmANLnBYeh3Vax5GpxzXYD0TCdBt339OgaWkFzYtqX6JMbPY8rkXK35ry6syjVY8kz0rcDksDaRMs+4IhfR4Rs/P4Wttkc6QMPsInNGGBg/a5WC6KcXO76eLaGWLtof4LwwXo2fijA0/o0y08CxFkObPIvBFfIe5uuhGTVsqeAtKNhQOs9wqlQt2C9CdNBI+QTHWd9K3pA4VXcSaZNnrUHZxjsVgIdFHFPc4UgzpE1EvB+tY09T1AU28IT7nQ== 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=eRzGIxx/5yV44lnsH0i/nVQAs8363ytxsMW7EQO8cp8=; b=YTyvJjukZZkNbTToulSlBRYE3oKO2bc72mrA2YJ2Kry4Id2TZ+6KRn7TyrVs4SO3EGU5z2pLkHP9APrQG3cCgGk1ifcl1vg+83f3KT7UwJK7bGI26eML7QchuIVoQxDuN5LOfIMvavHmGedkniz+ZbcEpLZnjE8mj5tOUSuIAFyt+azy6jrjl2N9tVcf12gjN4uDh2ao7ztb7M3dZ3DD7yZIGnBqft8m5Pu1pvvkobqWhp9wEKBnZNDZwVBZyw2LiBQ24KLJTdg0AKPkgjh21T2zlSqlYaA0mMRd0DdR/6kbvEJInSQgxGw+LEXRc6npHaBByYKeKsiexTCu808PRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eRzGIxx/5yV44lnsH0i/nVQAs8363ytxsMW7EQO8cp8=; b=5UT0RrdKjWfHTyxo2i7XAAlaDDCyYb5QjptXlA8zTpIH0AgA2/mVZ3et8MoMjUNzWNCnr5wcsy3sYM9frLdoHACFkKqwhTHChmGeWlrMNtqmltEwal2XHQyRW8uCNCSymHTtGGp5eiPsf3oPOubzv3TEvZoJ4U2DS82PT1ccr8l3QZ4lVd2v23Su3Z0VJMnNHgPz/2csEZCxWf4kuxDAEzSkoj8e+LBL+9V4Hb3bdk+sAUV4xnHwhkEPmFTFjQsl7QfeQ7zv+YOO+wLoK0yesERF1OqMwCd9SDyKoooGq5v5aGd8gHJvMr6/jnWlY36XQJDNwTZ51fjOtJDtYD4L8Q== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DB9PR04MB8107.eurprd04.prod.outlook.com (2603:10a6:10:243::20) by PAXPR04MB9204.eurprd04.prod.outlook.com (2603:10a6:102:227::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5709.15; Wed, 12 Oct 2022 02:24:10 +0000 Received: from DB9PR04MB8107.eurprd04.prod.outlook.com ([fe80::37bc:916c:55e:c0a2]) by DB9PR04MB8107.eurprd04.prod.outlook.com ([fe80::37bc:916c:55e:c0a2%5]) with mapi id 15.20.5709.021; Wed, 12 Oct 2022 02:24:10 +0000 From: Shung-Hsi Yu To: bpf@vger.kernel.org, Andrii Nakryiko Cc: Shung-Hsi Yu , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Subject: [PATCH bpf-next v2 0/3] libbpf: fix fuzzer-reported issues Date: Wed, 12 Oct 2022 10:23:50 +0800 Message-Id: <20221012022353.7350-1-shung-hsi.yu@suse.com> X-Mailer: git-send-email 2.37.3 X-ClientProxiedBy: FR3P281CA0013.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1d::18) To DB9PR04MB8107.eurprd04.prod.outlook.com (2603:10a6:10:243::20) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB9PR04MB8107:EE_|PAXPR04MB9204:EE_ X-MS-Office365-Filtering-Correlation-Id: ca94faf1-0e2a-4fe5-973f-08daabf8d89e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oZXRwqluX+O6seBq1qSGKbjZH2H2sWAfkAKW3rcWIGR9U/CE4TpzbS9KMJprpt/KTG1SyAElq2HsV8NRVPN+lLbxUqy9R1dWFzZn7IR0jfY0M9TJ8jqev5yWjdMnc9VoruOIlb5K/0TYfujq7TLxZv0nnHxeLYuLFQ/dt7pC0PbQz2iDWLJwzVHYp5QVNDjlfE3zGWO0Kd1K6X8CNTf9d/bWj8GYRpk8JM4RJnLhLYvyK3lTiWYh6DvH5iAsAG1tNPWr9KnvMVS82ZnBUV7ONtwb3bw/+whv+1pS41bqZQOn8NGByYIOb9xEc0VVjboUaSC7LrEGkLMKSIUZjDHMlHWzDkxwKTkw0FZGTnNxZSS1kDbo3vcHq5a8W/LoJmW7JJ7mnp5faKVbsjGDj0I9rOB/EXHMLQHlYQ76FOPDSw374iPsOTedzkQqjW+NdxlaRrfbGYSpl5Gl1MPUQkBnI88yMfC3AGI02ZtMhB7GMq2KV56atAw8HLDEtNBhnN125hOXna0NLFSU9QVRbIFiG2T4TRmxsrW8syHngE8E2T+167NWHIMw3nhDx/qRM1fXFcwewE2sF9DAo223u796UQVVNK4OL/MZTJABEwvZFVLbOEAV1sAEDsgIfQb5NA1bt78KhWRMtx50UxRv+slcl+bvDo80UMsL76aGqyR6M3K79FsO0cciwtkrC463HPzZJAbdvqVpY9JpY/I9uaBodtez3+oSAWdRUcQwwi3Z2G8= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB9PR04MB8107.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(39860400002)(396003)(136003)(376002)(346002)(366004)(451199015)(1076003)(6512007)(26005)(66899015)(186003)(316002)(38100700002)(966005)(6486002)(54906003)(36756003)(478600001)(6916009)(86362001)(8676002)(6666004)(2616005)(6506007)(83380400001)(5660300002)(7416002)(4326008)(8936002)(66556008)(66946007)(66476007)(41300700001)(2906002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5a2tTbfY3Ws0xzF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39OY9BDuReFh6vs4oTDMfqFNMpgxpGst0srlTHTRrT9s1XnUqUUN12b4XtntDZu/boBU9LZL9RYU+2PF20ONR30HpOPh0TjK7329RBijNI/DlXkUl6ask9p7QkFIwswmvpm3ufeC5wJkhSoGb1UnvUYm3bb/VbK4Ir4Uk33ssHbeql2s1JfjklIjQDIvXUbObo9wSXC+N4fMH4Wyr1l8BYasiMBi3u2lSNu8hsjfDc+DzVWHbCBOq0egsIsY/1v1gu4rsFTi+TLzxD7zDWVAAeZ0AOxVxpEY4+nJXicJIv9DUvz7ZVvIE1hKm5uv3ThaMGzRK/VzLLFNOceQaysWMluWK78TRbsMBemDCAZflH4g8vf88H7WQhZGbNlZL7jcRgA3UgQ3H+RQkrELIoSgvAyjjQ9yL3683QnEKEsek7MLWAGAeq2A7dgjunOpSySqg4uaRCqBFRKIMYOS9MJKIWNymOBQz84q+xiqc X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca94faf1-0e2a-4fe5-973f-08daabf8d89e X-MS-Exchange-CrossTenant-AuthSource: DB9PR04MB8107.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Oct 2022 02:24:10.2419 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xGCoNI9ofxsFSh7dDaAn3/TSEHULnmzF+RlgRzrN1ZQH2vASDOUbrHFbX6LpfBCwQTGX1cV+quN7Ap4xZNoySQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9204 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Hi, this patch set fixes several fuzzer-reported issues of libbpf when dealing with (malformed) BPF object file: - patch #1 fix out-of-bound heap write reported by oss-fuzz (currently incorrectly marked as fixed) - patch #2 and #3 fix null-pointer dereference found by locally-run fuzzer. v2: - Rebase to bpf-next - Move elf_getshdrnum() closer to where it's result is used in patch #1, as suggested by Andrii - Touch up the comment in bpf_object__elf_collect(), replacing mention of e_shnum with elf_getshdrnum() - Minor wording change in commit message of patch #1 to for better readability - Remove extra note that comes after commit message in patch #1 v1: https://lore.kernel.org/bpf/20221007174816.17536-1-shung-hsi.yu@suse.com/ Shung-Hsi Yu (3): libbpf: use elf_getshdrnum() instead of e_shnum libbpf: deal with section with no data gracefully libbpf: fix null-pointer dereference in find_prog_by_sec_insn() tools/lib/bpf/libbpf.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) base-commit: 0326074ff4652329f2a1a9c8685104576bd8d131 --- 2.37.3