From mboxrd@z Thu Jan 1 00:00:00 1970 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D3ABC4167B for ; Sun, 10 Dec 2023 11:45:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 507636B006E; Sun, 10 Dec 2023 06:45:26 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4B69D6B007B; Sun, 10 Dec 2023 06:45:26 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 358796B007D; Sun, 10 Dec 2023 06:45:26 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 226F36B007B for ; Sun, 10 Dec 2023 06:45:26 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id E3A21805A2 for ; Sun, 10 Dec 2023 11:45:25 +0000 (UTC) X-FDA: 81550728210.08.A16D609 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf05.hostedemail.com (Postfix) with ESMTP id 1541B10000B for ; Sun, 10 Dec 2023 11:45:22 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HZmbLPw4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of adobriyan@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=adobriyan@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1702208723; a=rsa-sha256; cv=none; b=FCB872u9Jw8wBv0E5RyXuTiomN72p23VsvUCkRd/3QeKLgGLStcbRqUTeZPW4CQyJtuIgJ 9a3ddApzZS5OPFoU9purTrsrWYve1BYJHlFUBaqu//6e60K3Xn1XQ0dlsFczmPQb/rreq1 VtzbBKau5alisdfHm6EPqo+eGMGqt+8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=HZmbLPw4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf05.hostedemail.com: domain of adobriyan@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=adobriyan@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1702208723; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Yp3hxbGdS2eZBPtlqCepXeiPKyyCDAaMr2U9ZBJTXkg=; b=jtbakWbXVuK79J1WPLpBlCwzz8WsgbIhCi86ZJsw2OSfUnR+MovKrHuhEvoXVox+zseWQ6 N5WdpxHaP0dlsAJnLr2lGkH46qNYS/FqZ1mycaOOrHTGPNy8ulnrT3P6P+DoCBYjPJYXwT jgk8zVFiCA6kTDZPMC5yDr0MogkQNZc= Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-54dccf89cfdso4414610a12.0 for ; Sun, 10 Dec 2023 03:45:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1702208721; x=1702813521; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Yp3hxbGdS2eZBPtlqCepXeiPKyyCDAaMr2U9ZBJTXkg=; b=HZmbLPw4ssozByuRFrtWcUSuE8R4/zT0/R4ml4HwAJ17jA+7EONkEzr9xCbJpCbjYy 0Ru3BFvQusLE0vNOCFV4v2EvOlPQMoJwEdltDMqdn4nKqjWMWArgDPwftmNEycTMbPdk sv8FhRRsyVFPtqDAopGp9BvYdgHkTbVp/9yUTTzrQ3nlGpmQUhkw2q5+vszmnwIccdbK yU1DEobgdcoxVV+1JGOF6vy4SplBKb/I1G6B2QC3jtBZpFopYNAeFhAy2YFc/6VTkUWz GfPdKxaG/ZE8HjOp3cWt90I+yh2bRZRFR+80noUabz8B+24PuKCB4uvPcKzCiRkbFO+q 6w5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702208721; x=1702813521; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Yp3hxbGdS2eZBPtlqCepXeiPKyyCDAaMr2U9ZBJTXkg=; b=wWuHo7lk4aKoIUkWTW06X35HhT8vb7eDyxMZKfW1tyb/vxEk3H+aHj53Cun+MiK+Br XVxdm6xOGDaZsjCJ5vTJxiXhOsb8e751T9I/AGAf2SSjjCxpAof4D7BZScdCzHHvpY4c cb6PKuuIDp6vnDUb9p+w/00zipFmXBpBNHETI8u1D3GNq0XUmHqicVuZLKsXFACSlpTj ooXRmJM/yaKP//tYvXntRQoA4gz/A5CG6hbcpNGXjdxyB9Nl/NsHcCJCLy6w0zHtWzTw C2Y7DRm8ulx0A6qe0jU345odNR/5PfT5XDBdvQgsrUAIlIBt4gSWuhskJyW0IJzjxuIY 4qYg== X-Gm-Message-State: AOJu0YwwQN2oFo6gsvvi4Q3mIT2eIMAclE/JGAkwOMeeBrm+6RZPcypv 7PLLYh1HICXcx2BufofTsQ== X-Google-Smtp-Source: AGHT+IEqCsZ7ZXLuWOmv3maORdUwlfQjqZozZP+afPI3r5sYdATksOhbu8geeOgTbY1EoEt+o4ZFWg== X-Received: by 2002:a17:906:512:b0:a19:a1ba:8cb6 with SMTP id j18-20020a170906051200b00a19a1ba8cb6mr1279246eja.84.1702208721021; Sun, 10 Dec 2023 03:45:21 -0800 (PST) Received: from p183 ([46.53.250.155]) by smtp.gmail.com with ESMTPSA id fj8-20020a1709069c8800b00a1d5c342674sm3295540ejc.27.2023.12.10.03.45.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 03:45:20 -0800 (PST) Date: Sun, 10 Dec 2023 14:45:18 +0300 From: Alexey Dobriyan To: "Eric W. Biederman" Cc: Kees Cook , akpm@linux-foundation.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Randy Dunlap , Bagas Sanjaya , Jonathan Corbet , linux-mm@kvack.org Subject: Re: [PATCH v3] ELF: document some de-facto PT_* ABI quirks Message-ID: <57f5aa9d-79c5-4f65-b90f-204600edfb80@p183> References: <2acb586c-08a9-42d9-a41e-7986cc1383ea@p183> <87edp7jyu4.fsf@meer.lwn.net> <88d3f1bb-f4e0-4c40-9304-3843513a1262@p183> <202312061456.2103DA1@keescook> <874jgugilq.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <874jgugilq.fsf@email.froward.int.ebiederm.org> X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1541B10000B X-Stat-Signature: 64nhfn7nw119ogwnya6jiby71gmn854a X-HE-Tag: 1702208722-229771 X-HE-Meta: U2FsdGVkX18eTLqDLkWndJWPd9FbsT5LjLMOM3gtv59cjPw0wb+n141nVaAlweIjQCUMBaCyyqqZt8b28NjURGgKi9t2u5YeAqFzGhHErum90ThrSYalVonOS0gDjk4tT8Hlcfez967AJ4x5UUPcTesqmb6ds74MdshaLQL2bdQ9o+acSAbQinGSSQs+NxMK4IjshrXgCD7wwgrJMfpGLy0paO5Dq6OtoVLkYyhY/xAN3F90pmyUVGJgU5fWg2+gn0D6jaJ22hj2AszXdNny2RWElNKgcsf/PgwxiPBpHOyjV4tvAonr7AL8yxPUBH403qZ7mn65KFXn/iDHrRXBqlWjz1Atk11tzDqWyyUmpo8KogqfRScSGlXmkGQiH4fy0eE3+cmt7CEeJ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bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Thu, Dec 07, 2023 at 09:03:45AM -0600, Eric W. Biederman wrote: > Kees Cook writes: > > > *thread necromancy* Question below... > > > > On Sat, Apr 15, 2023 at 08:37:29PM +0300, Alexey Dobriyan wrote: > >> Turns out rules about PT_INTERP, PT_GNU_STACK and PT_GNU_PROPERTY > >> program headers are slightly different. > >> > >> Signed-off-by: Alexey Dobriyan > >> --- > >> > >> v3: move to Documentation/userspace-api/ > >> v2: integrate into documentation build system > >> > >> Documentation/userspace-api/ELF.rst | 34 ++++++++++++++++++++++++++++++++++ > >> Documentation/userspace-api/index.rst | 1 + > >> 2 files changed, 35 insertions(+) > >> > >> new file mode 100644 > >> --- /dev/null > >> +++ b/Documentation/userspace-api/ELF.rst > >> @@ -0,0 +1,34 @@ > >> +.. SPDX-License-Identifier: GPL-2.0 > >> + > >> +================================= > >> +Linux-specific ELF idiosyncrasies > >> +================================= > >> + > >> +Definitions > >> +=========== > >> + > >> +"First" program header is the one with the smallest offset in the file: > >> +e_phoff. > > Confusing e_phoff is the defined location of the array of program > headers. > > Perhaps the "First" in that array with the lowest e_phnum? > > >> +"Last" program header is the one with the biggest offset in the file: > >> +e_phoff + (e_phnum - 1) * sizeof(Elf_Phdr). > > Ditto the "Last" in the array with the largest array index. > > I nit pick this because it sounded at first like you were talking about > p_offset. Which is a value contained in the program header entry. > > >> +PT_INTERP > >> +========= > >> + > >> +First PT_INTERP program header is used to locate the filename of ELF > >> +interpreter. Other PT_INTERP headers are ignored (since Linux 2.4.11). > >> + > >> +PT_GNU_STACK > >> +============ > >> + > >> +Last PT_GNU_STACK program header defines userspace stack executability > >> +(since Linux 2.6.6). Other PT_GNU_STACK headers are ignored. > >> + > >> +PT_GNU_PROPERTY > >> +=============== > >> + > >> +ELF interpreter's last PT_GNU_PROPERTY program header is used (since > >> +Linux 5.8). If interpreter doesn't have one, then the last PT_GNU_PROPERTY > >> +program header of an executable is used. Other PT_GNU_PROPERTY headers > >> +are ignored. > > A more interesting property to document is that PT_GNU_PROPERTY must > precede PT_INTERP in the linux implementation, otherwise we ignore it. > > > Should we perhaps solve some of these in some way? What would folks > > prefer the behaviors be? (I like to have things been "as expected", but > > it's not very obvious here for redundant headers...) > > All of these are really headers that should appear only once. Yes. > Quite frankly if we are going to do something with this my sense is that > we should fail the execve with a clear error code as userspace should > not be doing this, and accepting a malformed executable will hide > errors, and perhaps hide someone causing problems. Maybe do it for PT_GNU_PROPERTY which is relatively new. > I really don't think having multiple copies of these headers with > different values is something we should encourage. > > It looks like -ELIBBAD is the documented way to fail and report > a bad file format. It is obvious you don't know how much will break. > For PT_GNU_PROPTERTY perhaps we should accept it anywhere, instead of > silently ignoring it depending upon it's location? > > I thinking change the code to talk one pass through the program headers > to identify the interesting headers, and then with the interesting > headers all identified we go do something with them. > > Anyway just my opinion, but that is what it feels like to me. _Not_ checking for duplicates will result in the simplest and fastest exec. which is what current code does.