From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7517B191 for ; Mon, 15 Jun 2026 00:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781481906; cv=none; b=Inn/HqvLfOiaQ5gdW89+EvcimNaI6lyP0N2Ccixmdnq774DxxzgQ/qxm3HrG7wNOQcMwymUZpF37v6rwNjAujgfgcc2GEaHMre2WCoOb44TXeKoekWmGHioiJ+TMandLD5BRpXzWhlWLk5IVcuDybxPxnP+xlBIBBZKFOwNdfdk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781481906; c=relaxed/simple; bh=+sKO4BRSMEHnKqnwGPSXTQjcdkJi213RCzRbiN8vh3E=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=JumrMeXa0bNEi6h6v1yAH19AAEFTOLS2lw96f/u/d5Y0fjjCTFnX9MSO3fw0B+xNQYQrU/YavpX9wbBeA8HTUz/+V7Etu7u0juECAzdWFIYQFUCOkcuTPSExRwirjuY94wF78h9eW+se4xZ1VNIiajRcSnX9FggdAQi4Z3WDGP0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=HzYUiAfH; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="HzYUiAfH" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-48633190849so1047583b6e.3 for ; Sun, 14 Jun 2026 17:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781481904; x=1782086704; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=49/WFGBQV+h5/Hr/WXvhLPsB3u7z9gZgu6pPYMhYOFQ=; b=HzYUiAfHmZKHyNcSj/2Oomygj6aJSqgSM2hLpwhugf90Qnp+MMn8UAaQAYc5LIqKfx wwUcPmc0TI0Nr+7r6OymSMLXQ1i87VoK7ZJTHbM6SMjZdfb08k+hae+Jkwtiq/zrw3ob 1B+SFkDJI1Njmd/K9kvG7JRysT0Vao+0ocSvBL8Pq8FUBNe5RjldSpjKXIYwyRbm4J7b krewGN3myL7EEvZZ3aWPgGWQGycWDt08GMHk8KEIyyONiN13bKOiu3QMQ/E7KKdG+S9K lKDet/lwF3af4a22gEAb4BtCBj32l0jDXnu4p5H+2kYHuqQ3RzJEtaJtiMgUPn3LcS3D fp+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781481904; x=1782086704; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=49/WFGBQV+h5/Hr/WXvhLPsB3u7z9gZgu6pPYMhYOFQ=; b=IcroqfuYpEhdJRg7pWL7jqzY5PG1Y17r9RyxEhMIZdtgZqM+eJ27rkrP5wZcltDLi/ BSu148crhJpGXtbp1n+POMwyXtSlWVDwCxZn7cAXmMh7j8dCdfMTK6LgGGZG2g+klX1e 4kxoMSdzb2GQLKJ3DcxekXEgAHRJEaY5YdFeoWIXHRx8ncWMX4Z9RYzGxzhknWlotoVs t/eoaJxW8R2NQuIxRISSOpO9SVamj0vxsYEv0YObdzxxlhsrfpRfcuusRWm3YO719A/H i22LbeNFpiPH+vKZWfUWty9gh35giHfX73txyvazOqa9gOjTQkbZcVBcfenBNQBdcUMR tqcQ== X-Forwarded-Encrypted: i=1; AFNElJ+3K86/YSHawNXJhaRdlJG4iBjE8yoK1LBAUkXeh8GOA6TYaIw8C4UPlsSRfNJZ5ME7imuoxMmGE9hEazY=@vger.kernel.org X-Gm-Message-State: AOJu0YwbuH0kZQyyTxhjXFisU3l6m0Ic6g7l1SxWdv3ZTcx/a32wPzTK hi/hYYYH8zRoWvgH5Z3Uq47tOnL9uF32GtmFBgFWvhYfGmQAMEVGVD+Q X-Gm-Gg: Acq92OE+ACDErjqh9H4swYH2gNTlGWd0s769r8BAa81As7oi1kIuFJhYJpBtp0ZOE28 Rcv04pYidb61g2gjwB5eroGk2nXMN5S0qju6LKdnXXZ7mmmrbHTQDE46mBNOkTNQt0ME2JgW7J8 uOstFyjA35O87IDsV0iWjVTrfuwG1kcMQJWFzJEm9JU7aAh2aWXJupFQnGn4x/R4l45mUYGB4Al oMh1eZVGgViGvtC9AUAFox0IBMD6+gGcSpM/Jq4w5qS3vP4tDgWJMFTklpDW0cPT4V2gZw6jen+ kKZ6VKZffxOXDyB8+pm7DfZ8DZK8yp7zMX8tad6FC9rCdcajs3za2LMTh3U3KgHIfMmlO/vUcD8 zgyv3EIcGtBYHJ+OkAUDTud0uQv8ljzTizZsnGgf/p6Q+7n/plNF1TTP4LoOShc8mo7Vin3m1sB z0e2dJQ2TWEBSJIcuon8H6FW43aFcSmShYqWJl62HaYghmn3suhqBxGdAaUJ6ThOzhqQeC2/Upo V9K673yVzjE5hBZ8w== X-Received: by 2002:a05:6808:1998:b0:47c:be93:9214 with SMTP id 5614622812f47-48741b03cc5mr7019470b6e.20.1781481904332; Sun, 14 Jun 2026 17:05:04 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:51::]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4875df7fc36sm1762551b6e.9.2026.06.14.17.05.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 14 Jun 2026 17:05:01 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Sun, 14 Jun 2026 17:05:00 -0700 Message-Id: Cc: "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Martin KaFai Lau" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "Shuah Khan" , , , , Subject: Re: [PATCH bpf v2 1/2] libbpf: Reject out-of-range linker relocation offsets From: "Alexei Starovoitov" To: "HyeongJun An" , "Andrii Nakryiko" , "Alexei Starovoitov" , "Daniel Borkmann" X-Mailer: aerc References: <20260614092616.165337-1-sammiee5311@gmail.com> <20260614092616.165337-2-sammiee5311@gmail.com> In-Reply-To: <20260614092616.165337-2-sammiee5311@gmail.com> On Sun Jun 14, 2026 at 2:26 AM PDT, HyeongJun An wrote: > The static linker sanity-checks relocation sections before appending them= , > but for executable target sections it only verifies that r_offset is > BPF-instruction aligned. It does not verify that the offset is inside th= e > relocated section. > > A malformed object can therefore pass an out-of-range offset through > linker_sanity_check_elf_relos(). When the relocation is against an > STT_SECTION symbol, linker_append_elf_relos() uses the unchecked offset t= o > find the instruction to adjust: > > insn =3D dst_linked_sec->raw_data + dst_rel->r_offset; > > and then reads insn->code and updates insn->imm. > > This is reproducible with bpftool's static linker by crafting a BPF objec= t > with a 16-byte executable section and a relocation in its .rel section > whose r_offset is 0x1000: libbpf trusts ELF. There are many way to crash libbpf and libelf, for that matter, with corrup= ted ELF. Please don't send such hardening patches. pw-bot: cr