From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="fNCuajIk" 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-Google-Smtp-Source: AGHT+IHjXoA11dA50WtbnjUSI44eAM2tLeRUNZtkfUInXbO/jmancQD+KVgSdBcSUYmuk5/U/6YV+A== 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