Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp1473869lqb; Sun, 26 May 2024 02:44:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXN9IbMpO3M0e1cbo3rsFdT8oBKepgUXOrRJfYOJ3V3+5/M/S8ZBKqPjfGfB8ncNcLpYNuTdZpxPKrk0gGxDMfcxxn9xIkcV3vIrOJ/Aw== X-Google-Smtp-Source: AGHT+IHvbeznPbwi5JOdih7Z3j8cnkLLATJrM4GlLrkB+7e1Rx/loj3Uke13z70Kg+3Gqq6Y9Gla X-Received: by 2002:a05:6359:a3a3:b0:18d:7755:8214 with SMTP id e5c5f4694b2df-197e5669a6fmr886793355d.28.1716716668112; Sun, 26 May 2024 02:44:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716716668; cv=pass; d=google.com; s=arc-20160816; b=PwQq6wXwhXnT0r4puKKjsrSFpQlyQSz5BSSQCvC8NWjVnM95f0d5ieLqFhaTzVuma/ z+N2xZvuAHEiVEbhOG7Awma+JEbydJuhEQuTp+MV4zHm82y3IR5eORP8KU/T8tzK4Pwn 9CrQQhvS3IXqKGIilnBVqXqQWtWxuRURGNy4SPvYQISMlktJ2QpPh3JWXGccI078H0wP IJdh/yN23Zj+TO/CnO5BBGpYYfE9GPraSW+A3zwh/TQHD13zhjeowLywQ2mVYruKvNKT Ddst3oV1JzHFlnO+x6UUvdlzUlk9MscN9LJlBG7yG1tc2UrITu7Xk49l792iC5fz+Eh9 5EpA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=352LmnSBMkQVNFhzL75k+s9Ob5KXFLRxFIY+DNquD+k=; fh=Rcf+lijjX9jGItPLq7LX+0mfR1qVQVVFX/OwGUicOfs=; b=OMFVN6+FRwcoGu4YYmZL83gLr4i2MrM8bW82fax0lVDtD6RsLkG3h8/k3ZoJGPhUMr e6W+sw9eW2kJGzuwa8gcU1eUTGOsZFeu+C/ZwbRwqN9M8PqtmW+UoBeIQ6v5G1YlPCb7 8eh2Okmrr6Ucpi7LYUzjXF+PXTfss1qDaDd/7KKc8juxI6xQ+ENXf3TGl4e4pY7H5SCb seHp9yQzr1TESiIoYO30XQf4yac+I8u+ROh9AoyapJgfIufD0BebzOmhFF6rvLDryEV4 6aVlvgETcnNScnWaf3My9ALYyhlPUIHRcRI5PzYrUpDGfJfWY0K58fxotuvalQ072UpN bb0Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZyiIzPDD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189653-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6822779bfc5si4376470a12.408.2024.05.26.02.44.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 May 2024 02:44:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-189653-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZyiIzPDD; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-189653-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-189653-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id D3031282081 for ; Sun, 26 May 2024 09:44:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A43FB29CE6; Sun, 26 May 2024 09:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZyiIzPDD" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5BA628383; Sun, 26 May 2024 09:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716716531; cv=none; b=fQm5sYtf1FSgC/dlmUH2ZKhK9Qdvbgevi1d5kYEDKZibQ9a4/9wJLuVhn2gzX0DUS26kCUE5tdRtkwIET/5lH8v1RHUR/zl31qpKOon2KQTBT2uOzJaMpilxDdeMrPOFciFKcbQWBAwV2co+JXqNUXap/k1124xoehRReho0VGs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716716531; c=relaxed/simple; bh=OQ+fq/qWEXzONvHCfi5eHyNulhHelfhdcuRZeYfz8DA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I/cUIXQG9dz+M6y2E6seBTBLUfomeVbQMYwf1HyNw2xxKtbBpDMLmaiA/Cc+WkrNYfwGLST2CHfiXcQL75MKPK8NLh9BXkUbbdcebfo1pEBKDoX467WHmj2KM700Q1ue4dtkbIkIZ7jwqx0xH9rpyeMs8jCy4attfeLfgGhHsYc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZyiIzPDD; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAE27C32781; Sun, 26 May 2024 09:42:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716716531; bh=OQ+fq/qWEXzONvHCfi5eHyNulhHelfhdcuRZeYfz8DA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZyiIzPDDsTGz8jRFgYVCd8PtAL85Ywt244irg6bdyodQlFbHKBQ84PKRpcMvJDBM5 VGe6eSVwYNDSeaY5q5nDwUb4GZ3B23dr9j0Saejy5GKMIn4uXHj6M/dLih2F9FLKJN aAMCFCh0MsTwNWcE3pz2rLAgOUUReuLnahbU++Hs4qIPe9fcuIsdnPxKD+YeoypaQQ wfKqSXu79h66zGuv0gv07Xx+s2rXmAnFg6MedPf9mzM4LuHqzmV1rsIfp7vCvcTbOe j81KeM4C7y1tsZv46vZDq46jygicUY/8rkO0lLEXOSJWLfJWCpEhVAojHPdtNol++k 68FWqzAe1JOsw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , y0un9n132@gmail.com, Sasha Levin , viro@zeniv.linux.org.uk, brauner@kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH AUTOSEL 6.9 12/15] binfmt_elf: Leave a gap between .bss and brk Date: Sun, 26 May 2024 05:41:44 -0400 Message-ID: <20240526094152.3412316-12-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240526094152.3412316-1-sashal@kernel.org> References: <20240526094152.3412316-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.9.1 Content-Transfer-Encoding: 8bit From: Kees Cook [ Upstream commit 2a5eb9995528441447d33838727f6ec1caf08139 ] Currently the brk starts its randomization immediately after .bss, which means there is a chance that when the random offset is 0, linear overflows from .bss can reach into the brk area. Leave at least a single page gap between .bss and brk (when it has not already been explicitly relocated into the mmap range). Reported-by: Closes: https://lore.kernel.org/linux-hardening/CA+2EKTVLvc8hDZc+2Yhwmus=dzOUG5E4gV7ayCbu0MPJTZzWkw@mail.gmail.com/ Link: https://lore.kernel.org/r/20240217062545.1631668-2-keescook@chromium.org Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- fs/binfmt_elf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 5397b552fbeb5..7862962f7a859 100644 --- a/fs/binfmt_elf.c +++ b/fs/binfmt_elf.c @@ -1262,6 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm) if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) && elf_ex->e_type == ET_DYN && !interpreter) { mm->brk = mm->start_brk = ELF_ET_DYN_BASE; + } else { + /* Otherwise leave a gap between .bss and brk. */ + mm->brk = mm->start_brk = mm->brk + PAGE_SIZE; } mm->brk = mm->start_brk = arch_randomize_brk(mm); -- 2.43.0