Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp886626lqp; Thu, 21 Mar 2024 20:53:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWjypNQpLp7YO2qxSnuvMQrwhW9j4Izj0tZSJr3EJ6y9+aT9qNX3It5ClArZVW7rk3nlxi+LdZgBwqdbFZabxP31uaogz34gOMsiB0pNQ== X-Google-Smtp-Source: AGHT+IGTMC7zcmXOeZD6m4OlI8ngj8mesyqUzBbvX9wJo3CNS4PCWqR8NRKT9/Em3ugepO2PbgHa X-Received: by 2002:a17:906:4914:b0:a44:4c9e:8809 with SMTP id b20-20020a170906491400b00a444c9e8809mr763026ejq.32.1711079616300; Thu, 21 Mar 2024 20:53:36 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711079616; cv=pass; d=google.com; s=arc-20160816; b=S4XfEIGMIq38nId6QZEL+h9X2dMiZpyjdzrZeo0c87vbJvNQ9SUoc0LFqx3UV8nwJ3 2ZyXEQJ8VkzUAdKGOh6GZc/mHIO5iBzK75B7WqrqzNOtIzIISlFH8TReI1MOhhEhwFGZ 9ZeAkqZVvOvf6lOdhXaW/ocpofG8/6VrwHoz5p6CLJbGu/ZjTeagBUVHxwYY4+wNBdm5 Dmg9t55KuK1CEfnVlVXHPBMe5J7E1TQh2DGt7drpUXYBiZrx038+X64k6xf0xdETIcXe BU1iX153ZbhnfD6yVSLC6Ys1GO27VeGB8A43RefbIVzRngTIliyIFjmdoeokDEikZePc Ukbw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=mDi7jYxaJ9l+KBr/OHl27LOvhUXGML1wd1U7ONJ3R9g=; fh=gxnBeMYFRlgqbE7OMFYqyTK6bfYeAsbUDGORghgqo0M=; b=g2gWiSoWs6oEvdGtPuh7VsQFxVfuGps0gYCZZbhtcbh+UqlyoVrId4c27pVjg31OUR Mv9w30Q/JioSL7pK7uK1cslgzpDSxTIqDFu/1XEicyFuQum6hryKJJfV3s6dsD5PHhbZ MBA3hmj/gdjafi7e7eoagqVx/W2WgANCjIxPyturY+Wg5zm0P9HTPC+sClGRzbZvu1wO p0eOuQdlzqCRVxEyZWpX9qE8hLYNamq7ubFidqEkInFUIIQ8Ovx5MjtvM5I/ngweA1Gs tBt0S6h2Pp/7EROfXzAN6FZu2Qu7KtGIMk3pw8Z94JGuvRwsoVzqZcvaJO3VRuQ3B90+ TVxg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ftfhA7uM; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-110918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w6-20020a170906184600b00a46e12d208fsi525157eje.808.2024.03.21.20.53.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 20:53:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ftfhA7uM; arc=pass (i=1 spf=pass spfdomain=chromium.org dkim=pass dkdomain=chromium.org dmarc=pass fromdomain=chromium.org); spf=pass (google.com: domain of linux-kernel+bounces-110918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 0E4BB1F2483C for ; Fri, 22 Mar 2024 03:53:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C81F0C127; Fri, 22 Mar 2024 03:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="ftfhA7uM" Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 494CBBE4B for ; Fri, 22 Mar 2024 03:53:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711079609; cv=none; b=gH2/WJgkTYWGo2eQDpNHmXZdbYqZ92IOGMMK8ebUC/eFFrFgtHYTU/Hb14xJjfGX4hcMhluNQM3mk4EOBJNVHdq4eFpRs2QmAwVk7WEYRCdvliZEMBPQBmGF0EexIQsbVdcC84KMdpobkubTqeO0X7Fw/GjbUk9f+l5X6mU9xR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711079609; c=relaxed/simple; bh=khGq0+ZmZFLMVL0aXsjoH0lpg8FPMH55OjBwEzdFfjQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fOZ+XDHkzr5JvYUMKnGA6f0a1ulfZuEaO6cpkxNOv90nMxpw+6xzglXLF+FYYJOlRZcWX+FdVm9vLhb6GQZ+QTs7d+CR94w1BCdIAVlM6+R9rShyM3PwgR2J/X4xv9/8RYTS9Lokkr7OKOoEhTlrw0SUKwOvsy1rnerhB0q+Tuw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=ftfhA7uM; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5dbd519bde6so1078052a12.1 for ; Thu, 21 Mar 2024 20:53:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711079606; x=1711684406; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=mDi7jYxaJ9l+KBr/OHl27LOvhUXGML1wd1U7ONJ3R9g=; b=ftfhA7uMDrNsmwHpOXoy2wpmSW0m3dgxtgK5NiOZy2+wnhNtoEUczvj9CRDKdrifuG rZ41KY5tgxo6aDGDrcgPRCwCFHU9smYsTOZmu6GZdi8mwoUOHRNIPvsBgtunb9CRWKRo AIl8VJ9bNqKUQiBW/RqcFMHgIQFx1WSu4yehg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711079606; x=1711684406; h=in-reply-to:content-transfer-encoding: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=mDi7jYxaJ9l+KBr/OHl27LOvhUXGML1wd1U7ONJ3R9g=; b=ku9s5gkoySdQP8Cv2q2t5eUtIXpI6/kR80tfqBIFxob1jrkw2p5iwXGiocnkawQBkN 0/befSk52VmIA9675+NRBB1ksgYlxJuUqlHPdgbvUfqzgNlDwLhwTFyMM8oq3tP5xmbj 4vVE8r95yrHmxxm3xZrJ//yAENwKmq2lINVeK5ytWlTW5nAXoV9kvF2qQzQFRY/vmU0V Tr0F3+n9qK329iOdEY9iiFuD8NimSDX0z6B9/F4KjU3MKZTALTpfkVFVcLXw7n2+fTpC z2YJrbRb0CSQxc/HYPxL7Rmjag/BC0lD4+mL3InJlnMPYcyUQ4HCoX/+J3EhtS1guHuS NjEA== X-Gm-Message-State: AOJu0YzElziLsC+WRg1/zAFhvk4F68auenYOCITAGNkJuGUN0I65OIH0 cus5Et6pEajIQt4cbxC2ZGZBmVbVHshap6ZQL2S2W6t+KVNpCRx/iqcjsXCPyvW7paLr+DBQKlw = X-Received: by 2002:a05:6a20:9151:b0:1a3:59ac:a626 with SMTP id x17-20020a056a20915100b001a359aca626mr1814803pzc.41.1711079284701; Thu, 21 Mar 2024 20:48:04 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id u2-20020a17090ae00200b0029c693a1e6dsm782334pjy.17.2024.03.21.20.48.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 20:48:04 -0700 (PDT) Date: Thu, 21 Mar 2024 20:48:03 -0700 From: Kees Cook To: Max Filippov Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Eric Biederman , Alexander Viro , Christian Brauner , Jan Kara , Rich Felker , stable@vger.kernel.org Subject: Re: [PATCH] exec: fix linux_binprm::exec in transfer_args_to_stack() Message-ID: <202403212041.AEB471AC@keescook> References: <20240320182607.1472887-1-jcmvbkbc@gmail.com> <202403211004.19F5EE27F@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Mar 21, 2024 at 12:52:16PM -0700, Max Filippov wrote: > On Thu, Mar 21, 2024 at 10:05 AM Kees Cook wrote: > > > > On Wed, Mar 20, 2024 at 11:26:07AM -0700, Max Filippov wrote: > > > In NUMMU kernel the value of linux_binprm::p is the offset inside the > > > temporary program arguments array maintained in separate pages in the > > > linux_binprm::page. linux_binprm::exec being a copy of linux_binprm::p > > > thus must be adjusted when that array is copied to the user stack. > > > Without that adjustment the value passed by the NOMMU kernel to the ELF > > > program in the AT_EXECFN entry of the aux array doesn't make any sense > > > and it may break programs that try to access memory pointed to by that > > > entry. > > > > > > Adjust linux_binprm::exec before the successful return from the > > > transfer_args_to_stack(). > > > > What's the best way to test this? (Is there a qemu setup I can use to > > see the before/after of AT_EXECFN?) > > I put a readme with the steps to build such system here: > http://jcmvbkbc.org/~dumb/tmp/202403211236/README > it uses a prebuilt rootfs image and a 6.8 kernel branch with two > patches on top of it: one adds a dts and a defconfig and the other > is this fix. The rootfs boots successfully with this fix, but panics > if this fix is removed. Ah, perfect! Thanks for this. > The easiest way to actually see the AT_EXECFN is, I guess, to > do something like that: > ---8<--- > diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c > index fefc642541cb..22d34272a570 100644 > --- a/fs/binfmt_elf_fdpic.c > +++ b/fs/binfmt_elf_fdpic.c > @@ -659,6 +659,7 @@ static int create_elf_fdpic_tables(struct > linux_binprm *bprm, > NEW_AUX_ENT(AT_EGID, (elf_addr_t) > from_kgid_munged(cred->user_ns, cred->egid)); > NEW_AUX_ENT(AT_SECURE, bprm->secureexec); > NEW_AUX_ENT(AT_EXECFN, bprm->exec); > + pr_info("%s: AT_EXECFN = %#lx\n", __func__, bprm->exec); > > #ifdef ARCH_DLINFO > nr = 0; > ---8<--- Does musl have something like the LD_SHOW_AUXV env variable. With glibc, I usually explore auxv like so: $ LD_SHOW_AUXV=1 uname -a | grep EXECFN AT_EXECFN: /usr/bin/uname > > How did you encounter the problem? > > I'm doing xtensa FDPIC port of musl libc and this issue popped up when > I began testing it on qemu-system-xtensa with the real linux kernel. > Related post to the musl ML: > https://www.openwall.com/lists/musl/2024/03/20/2 Thanks! -- Kees Cook