Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp625429lqp; Thu, 21 Mar 2024 10:32:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXsV8KI3NWQURtStDu67Jxco7gwn1ndqTlxM6M8YkP9mWUfDPc4I7hK5VWeIRr37nSFKD0uQs9q1lDzrNA65DQ2S+xPTdzjAVNVrL25nQ== X-Google-Smtp-Source: AGHT+IHrpu8mjqZnKjcRUNLTtxbsmzKSYa2WXYXYWS+hiIcqBRMF0cLlSUir7BJEw2QSiseU1Xa6 X-Received: by 2002:a05:6a21:594:b0:1a3:647b:b892 with SMTP id lw20-20020a056a21059400b001a3647bb892mr4965287pzb.15.1711042328907; Thu, 21 Mar 2024 10:32:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711042328; cv=pass; d=google.com; s=arc-20160816; b=fhV465PdMBC3C81iL3rhaBMpK7nFaov/GHEaIDqaDgY254UGYL5x/o7Elrt/Udw/dy 5EDHt//CuYOPDvxW6gpf0x8fGb8k3EESDZ3zmEG1RT4R/aTHWzZXU7YlLZSFT1yccTFV Mtmz1zqdMYnQ+uKbiXseAZxnuJKI/riqUPYPWzYYL+w41BhvDztkvBof4Qsa2uD2jfqc m7LgYdjwEwmdnbPHnV/HE6snXIPk+JyQ71OC5Ski59dG4Abqbe4s+/cEOn2+EmqBFobB gQWL2wP9YVTdW+ixjrTGMWWCXOp0kAY4hpNryR4yt5eL/xBXBFmQKxnOf4qr4ntbDpMl yqsA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=abV1KSQfMj1DzU4Wxs3gXedK8VwaffSMAGzyZA+mQ48=; fh=gxnBeMYFRlgqbE7OMFYqyTK6bfYeAsbUDGORghgqo0M=; b=ox3dF2F453fqi2tSv3W05ZrbJniCLJfW0LKxB/HMqsjNx1ADlPGaUzbPBzEr8j+m1K oq7TiLMVjkLvUS4Qc7qJW1Ojdk2nwbJZ+fPMDdVcwmVE3INGsUtqKCpSX9GlizXbiQvG paqpIh515hFPvAJ/+zwjPwSQl6/Rcj5GhsmSuVV4TwfBLRzOHp3fTNr9DPawFaaaVwY4 Huuhh+VfCNsrFt+xGWC0ynHS0nb1GedUyqrNvUnREiNqGmqzHE57v5i+QrepGWYWwQih C1Z97boFr+hSkcy2yTBKRJPLWFkkJZufKbUe6qkaAS3z+4j5q4YTP77Z+hD4xISslfwi 04ug==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fNCuajIk; 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-110461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110461-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m17-20020a656a11000000b005e42fc7a15asi189228pgu.348.2024.03.21.10.32.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=fNCuajIk; 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-110461-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110461-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 0EF47B23E87 for ; Thu, 21 Mar 2024 17:09:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C0ACE137777; Thu, 21 Mar 2024 17:05:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fNCuajIk" Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 3E665137757 for ; Thu, 21 Mar 2024 17:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040706; cv=none; b=Z+3ge0dn7JtANEX4ZkyVD6KWAL37DCrzDd3jrwJ739DGvttLmzuaai4xVtFQgZrx46Xb8P6Axbp7oxKjppNtj/fXtzIwqydIxhvBiaLVN+K7+39SuU/c/2EiWLKknYl4iTlE8YjRyrjaAYWDZ4KpySjYNr1po9gRVBZfm7J+TLw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040706; c=relaxed/simple; bh=F7BZPRrnGiUnAuBv0KvmsW8b1nfHOpvDFLxdGkrbpm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ozo9pOl1d5MnZL5TrWm/pfib/mmvLPBj2eEi1OJgSibFMvEmdwEbJnH0oQJeKH+jdovXMcudvQR/b/Y0e/ZTjq6e00w9kFsYhjk48R6g4hXy5BFCQKIe9ZHDsIelTXCGYl+Cn25KgTJqa4gemPdM2Gx6EJQSQOkoF/jC8vZN+vs= 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=fNCuajIk; arc=none smtp.client-ip=209.85.210.169 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-pf1-f169.google.com with SMTP id d2e1a72fcca58-6e8f76f18d3so999337b3a.0 for ; Thu, 21 Mar 2024 10:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711040703; x=1711645503; darn=vger.kernel.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=abV1KSQfMj1DzU4Wxs3gXedK8VwaffSMAGzyZA+mQ48=; b=fNCuajIkfUB0fTpb8UiK4C/yfMmbOvutmU/1Ppb6FePYcwb4lU2BnxCqo0vlNNniwg 180bQbGurOpKxEeR1LilXtOfvwIilSztCthOJb9wXUIYJ6Ycqr5v8zEL02FY1tmwT+YK Ujk2x1j6oHhqotvox6FVelVonE5C7hZYMDV/M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711040703; x=1711645503; 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=abV1KSQfMj1DzU4Wxs3gXedK8VwaffSMAGzyZA+mQ48=; b=hMMutmLQrQIVypUgXSkHLyNxjaKF7yFrPsz1dJSVWtuloOIV7ft8FdHgJyR1z8/uPa Ouy0yDVc1ae6ofAq6+MevOt8Kb2ZZn67FbV4dclu9bvxNDjoILfen7CZ08whFameUGxy KB7KYk7R3BIakn5gLlPWCOTvFfmj2QgQS0p5tJdLfthh5e56jnRvMWj+wUVBsZY88H+6 m8PT0xekL22soj1JTNE7nkDg4W4KWniF4hvWYLKKdYuJwvIE42p5nOtBiC59ts8q/pqJ oktTzyhsAvfR0OV64W+dqjcEOx9ypNwxq0ztf7O2kdSpNjLW5vUSf0jWMtHK5ZP7TV6B AbVA== X-Gm-Message-State: AOJu0YzIkCe+DD1zTs3AGRueVngw3mX2G1MAxTCMniQibvdKdMM3ZMNv OUEurGuAKEVNlzbQbmBGrkKTeRJIFfTvhuT4J4hdL9f35zVQ9DSxDZOcHoUv8U4gD7ZZhlkSItA = X-Received: by 2002:a05:6a00:3a05:b0:6e6:5291:1779 with SMTP id fj5-20020a056a003a0500b006e652911779mr4275257pfb.6.1711040703382; Thu, 21 Mar 2024 10:05:03 -0700 (PDT) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id t16-20020a62d150000000b006e731b44241sm73573pfl.42.2024.03.21.10.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:05:02 -0700 (PDT) Date: Thu, 21 Mar 2024 10:05:02 -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: <202403211004.19F5EE27F@keescook> References: <20240320182607.1472887-1-jcmvbkbc@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240320182607.1472887-1-jcmvbkbc@gmail.com> 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?) How did you encounter the problem? > > Cc: stable@vger.kernel.org > Signed-off-by: Max Filippov > --- > fs/exec.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/fs/exec.c b/fs/exec.c > index af4fbb61cd53..5ee2545c3e18 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -895,6 +895,7 @@ int transfer_args_to_stack(struct linux_binprm *bprm, > goto out; > } > > + bprm->exec += *sp_location - MAX_ARG_PAGES * PAGE_SIZE; > *sp_location = sp; > > out: > -- > 2.39.2 > -- Kees Cook