From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) (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 18CBC1369BD for ; Thu, 21 Mar 2024 17:05:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040705; cv=none; b=RlRznHGL0/tO6qXbbvxtkEWGNYTs915yeruWmgyNoGUImpxsCVU5oBlWncYYIBObaTJXj/c46U/mGqw6/nbcT0/ZEhWlJE6+LT9n+8jjGLU7/rv8APaCZlzVRUsYByYx8Lo34q25LbLVzvpTPPkpOkGqMNuSlqSPJ2+yOCwzRAs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040705; c=relaxed/simple; bh=F7BZPRrnGiUnAuBv0KvmsW8b1nfHOpvDFLxdGkrbpm0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l89eZPMq3woKR6l7yiWNj864+GVW5j5OJS8ZxvJna4Ieh3oqJJIVhwVrhJUYlvrh/K2oA+xVRFB6OT1gMltKTlKegQAC41eHwxeFsxbBLTq07VVrv9/YGmMyv/iGneVg7BTtv4gaCiJJS+CO1OmHUDYo6h5z+SxUH7Q2EuxHy/4= 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.180 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-f180.google.com with SMTP id d2e1a72fcca58-6e8f76f18d3so999335b3a.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=FfMUSO/Hpk3YLNeXBxniCRdb0tSLVdKXKNAcTlIdRozuMdj4iHxoR0DywYqu3RmsSn RFwVxMjSt6k0m2yblxtH4Wry12LC5sJaIe96spffUPZ0N2ZiPgXDBuEunY/Ax/sAXBpE SH6TypQZwWklYn0YHRmVJDxp6Lj3T5wjybGne/pm0+Osh+gbSQan4FpjQhazST7m5bF3 olxBRu5mjjfgdyPB5K2UN7/hqaXKuHUxlOopW4XtD5UvUNgJIJ3rlJfa1Tiu2gAxcnaP BwvHo8U3vJlxg7euCSUmv7d1HYGouYQ3+X2GyUGabxvyQmKpNpmC1fAhRZg+JxmWwTsd qsXw== X-Forwarded-Encrypted: i=1; AJvYcCXaQDI0Gkb7nP927Ju1rmaeX7pCcknbr92Lqf++2FDUzeIuKuJm51yPo1FPpzLxwynubMe33aTIGQTV4Wb6MEF7BsOAnjQN X-Gm-Message-State: AOJu0Yw16fRxHr2BzNBC2ll2brLtRnwUjzmQ9VUEGCqGFuuC1N8LzjgY YDSoblxbG3umUGoC9KVTs1dxPMjnTGcvO2tayVfE60uxsrkT6YBxVQ5YMfcMfA== 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: stable@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