From patchwork Sat Feb 17 06:25:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13561254 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF37AC48BC3 for ; Sat, 17 Feb 2024 06:25:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E49246B006E; Sat, 17 Feb 2024 01:25:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E1FFE6B0071; Sat, 17 Feb 2024 01:25:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C99776B007B; Sat, 17 Feb 2024 01:25:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id B6D026B0071 for ; Sat, 17 Feb 2024 01:25:51 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 74BD3120188 for ; Sat, 17 Feb 2024 06:25:51 +0000 (UTC) X-FDA: 81800310102.14.B369154 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf30.hostedemail.com (Postfix) with ESMTP id A5E2580010 for ; Sat, 17 Feb 2024 06:25:48 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gDxObcmj; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.177 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708151148; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=PfIR0fBKHcHTu35XI9I/l5YesMfUJfSS9sUu5LMaD84=; b=jU6T4Oj2PsAoJtbFAb4f3rZ/w7qCAdQNMSjtLMRhGemKtvkElx9gEkb+edDzAQILqAfYFh 0S9N03XHyWn7WXmaiiUfhuhn1EdrqKarn0fprmq87nbMMNRai7qAeLHrwSGAcJl1UePJaW hJ8EJ+z85vxOU8c6Z2FdldbU6KdEINI= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=gDxObcmj; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf30.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.177 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708151148; a=rsa-sha256; cv=none; b=rye714A9N4M+8Y8ADFzsllqNFutvRDoVw2VBWzrav5va1KtSHUX+JkPiJlL/TCRyYPRoMe EcDTBvujoqsbDnO4dzostctPE195Lztii0OiqKhp5qeuwlJqNv2CgspkFHcJcgjgIIoNAh nQupw4qqYmVk48x/Rj+zhfG4Ld+hsvs= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6e08dd0fa0bso2340953b3a.1 for ; Fri, 16 Feb 2024 22:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708151147; x=1708755947; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PfIR0fBKHcHTu35XI9I/l5YesMfUJfSS9sUu5LMaD84=; b=gDxObcmjIstvAGoFqesuYR/Ed4Kl1VsSRWGxUnbd/UMZp2sMsHNp7/JGlzRcgtT1si j/39bBTodsJeX3FwcBl6oFrGjSi/I3sHR2OllcMYfyKS6m13mnwvHbyw+uaJ9BaoE3+C 0tHBYkXrMf7XpVoC49plSUdUdIFCsglENQ0Mw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708151147; x=1708755947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PfIR0fBKHcHTu35XI9I/l5YesMfUJfSS9sUu5LMaD84=; b=qz8cZ4xVUTdUanGg0xb4bsvh7w1opzOV8Vt3C9vNbyQGMGqOGroWN+JsOSAB73R5l0 pYKYe4eq9+l9zgX92jdAmxVnDPF/RDp/aYNtuqbe37Rv9nbdXFRYaw0UucI14BxtIuOL GpLzKKbj7vV8Mj8zKUDsheUC8+zWQWcINuT22geUIlg29jFKDMMNlgryJF16vd6W6bci GzTiMy/j/9X32Hd1jHk+eaHdp0ofdNMT9o+nLUAO8ilgHxaIZxiAvYKTu74P/3TXlJ5q UR4x5RA1nR70n1kMQdV29d6uaFm3360wW+6GGJ7j6E9d0i89zoMUaf/ykDBWyfcuyJIB JyzA== X-Forwarded-Encrypted: i=1; AJvYcCX/ah7sVOyHIlEyx+gHJpvUQLoVUt5zC1SFuzuO6qhXI0FzRw1WedHbWDx5aTDmKMGqlnPBkXjESQo9FFqBbnL8IeM= X-Gm-Message-State: AOJu0YxvCO2SrThIVA3K2wf+SuIn66XJHAdWy1rK8FS/KUcxK8UOYA+Q hZn9Gl/DYXdH/1qa+0PP4Yz2zGQZ8K5QIQai4Z7XMqpbvEhF2bsPji0zoitY3A== X-Google-Smtp-Source: AGHT+IEN7kra6nhd0C/U//cqra0sN9TAy99jtLP7gl6N1oR+rsshp77a8Yk2AxFV0aGXX6usEqGwwA== X-Received: by 2002:a05:6a00:2292:b0:6e0:8c11:9878 with SMTP id f18-20020a056a00229200b006e08c119878mr13296297pfe.7.1708151147635; Fri, 16 Feb 2024 22:25:47 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id p9-20020aa79e89000000b006e35c1aceeesm233949pfq.197.2024.02.16.22.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 22:25:46 -0800 (PST) From: Kees Cook To: Jiri Kosina Cc: Kees Cook , y0un9n132@gmail.com, Geert Uytterhoeven , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Qi Zheng , Alexandre Ghiti , x86@kernel.org, Al Viro , Christian Brauner , Jan Kara , Eric Biederman , Christophe Leroy , Josh Poimboeuf , "Kirill A. Shutemov" , Rick Edgecombe , Brian Gerst , Bjorn Helgaas , Tony Battersby , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: [PATCH 1/2] x86: Increase brk randomness entropy on x86_64 Date: Fri, 16 Feb 2024 22:25:43 -0800 Message-Id: <20240217062545.1631668-1-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217062035.work.493-kees@kernel.org> References: <20240217062035.work.493-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1595; i=keescook@chromium.org; h=from:subject; bh=J8yZ3FuS1LWrR5jVIrwba2SyB7GFZoxGQ5Gq7wzczYA=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBl0FFofylSSc0zctidXuws91GIZAfUD3EvfMTgD C7ILFWiQEWJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZdBRaAAKCRCJcvTf3G3A JuvKD/0YST+WQlVawQvhCb3pQXdND3wneO4rAAc1MIaPKKYFGzOMCeSQYBifV0JEeFHph1WsrQC n4+hCw/MTLwSm24DnSu1EEevAaPtL2voVeq16UMZrkG/yapEWn3+250s3daI8qSEHpaTs+lqmrY 20PeyS18a3NDnzD6VRtlc/Ud4NM4lTrD59tsR9Zypsk8QkTOW11SzkDOU36Vewr5lvz9WlASgCb uX115bQ6YNYuZQkpWi0z4MlnmeNcdOuQnupP0FwTKJDVMHrN+vvFac+rR68LNoQtHQMqb0yZKXr iaQfIX0RbdI1t7Ns/XMSdQQfLgvkslY3PnQ7KanuL/2iVQSA+qYKaUHT1q5rU9VB+w3Dck4Dmye Mw0zNvdQB8Y4A4EnGY6HYyO6ucLRSQtEfIuXbYYszYSq6wZmHI2F8gQrXTQN6dKrHavZBh6DOSY Ep4Xtnl5207P/j3tkJ2WlgxPesAECiupJebylL9V96dhr12EkUmNs83ixnDjhgIhd/q1C66ZLuD gOP5XrfxOIcEw0QQFj8sFRcjpHdAnouwZruQruo4ED1IAeSMX2ThvD6Di09uNBuIX4r27aUDkF4 PMMxi3r0jO2Iy/OhTCP2lOG3dtuz7BSAH3EaHzmxqr7QyGazjc6Mux/rumcsyyFjQTLaXMsCYg5 3MpCUeeX8WL+hxg== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspam-User: X-Stat-Signature: qbmxfyqo6mcgnmrnw375fdduofd9pirs X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: A5E2580010 X-HE-Tag: 1708151148-72191 X-HE-Meta: U2FsdGVkX1/gv+jaSQamqKWoG5dPmMpu6MYI65nYk3ar8qLxFVHZ9KTwHvMUVqyVVs0e/dSzxS0APY6DuxIxhCghtTGXBLtH6FFpADLdN2YF+BLfWpuqov6bdHfX98H5/phFiSl8sHszVWHZxLvvFDb/qiSBKVVOzUG+CiffMlop6JjBDYYSUWrrXE9s7wFLtO8BdnKNxj7l3gpIW5uvcLpwiTdvYKxfos96NhZHTfsPL+vEYM7oKbXtVtN0UdphABlH1U4Fmbrg0x6Ras0c0HpTAQR0xMDZc8WUjpl7RdzeEYVmwoMq2eLkd2EKqCrIH1rxhbVBeBZpYrfLnJ1EdUAPrRSeSGvPZpCzODJnw1PtyCZjg4J5h+iC9COiV+4rZsuxMwTuSVVDG+aC3Lr+Ld3aRFM3G8GTOea4YUc0P+8CpXqwMNA3k92gzNExkDZFQK8PdrplfIiZpX94IGlNDY8CWfMavT4oX41WiNbNO7ysrdOYOyapdrvrRF6I4IN1RMIilXnYBnkFXdVVpw8wT0jadGuRk2eOOau6mf4nSDCAwi1uGQ7VnUH93ay4RSHwOQPhVGtoxhb9cLN8l7+ZpZC3UpADaaScL2nvU7R6p6s2Kty4bzrLctAxcDD9rsChddJyI5XhnmZ+engRh5YqL38bKQw21L7BwMELSUD0DaEjT4cH/9eHssb/4xZw77XJuHsrS7AhdM6xOdibJv/BkBZ+j0dOiTIXPL2MtsHuUoBRxbXw/5empVB/Go6b/HZOXtATX4oJUj9YRmKYen+rpHY+5fQox/j4VzmzRkyYaqysmEkqIXI46e0lbqGGgWTFz3XAYYFCT0EU3R053wAeYWblQ5KyM0yoEpTvlbvVQvDW2WmEGQkI2ie7X7lzFt9anTztj5jscIs3JPZJxu4moaXbY8VhyDmW22cqh+Zbt/tI79Q0HDLrqeS227c1gkOVNELiss4A/W2iOEL2cM8 k04rJZ11 4lVV/hY6ZJRStIWfiezJX+bVoc9HZEI3ss9QW8l6Vo7Cev4iDgBOCf/DZD8Jkel2QFDWGgJ7ZNLJp1RjuNQojHxfH7VZhjUGJ0Fj7ym07uYezmjeCCqv9ZFGgKdA9WgZtxIElvVAzXO93G+JGv8MnbE828qn1cgJ3Xavp2WBl96BZ1qI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In commit c1d171a00294 ("x86: randomize brk"), arch_randomize_brk() was defined to use a 32MB range (13 bits of entropy), but was never increased when moving to 64-bit. The default arch_randomize_brk() uses 32MB for 32-bit tasks, and 1GB (18 bits of entropy) for 64-bit tasks. Update x86_64 to match the entropy used by arm64 and other 64-bit architectures. Reported-by: y0un9n132@gmail.com Closes: https://lore.kernel.org/linux-hardening/CA+2EKTVLvc8hDZc+2Yhwmus=dzOUG5E4gV7ayCbu0MPJTZzWkw@mail.gmail.com/ Signed-off-by: Kees Cook --- Cc: Jiri Kosina Cc: Geert Uytterhoeven Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: "H. Peter Anvin" Cc: Peter Zijlstra Cc: Qi Zheng Cc: Alexandre Ghiti Cc: x86@kernel.org --- arch/x86/kernel/process.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index ab49ade31b0d..45a9d496fe2a 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -1030,7 +1030,10 @@ unsigned long arch_align_stack(unsigned long sp) unsigned long arch_randomize_brk(struct mm_struct *mm) { - return randomize_page(mm->brk, 0x02000000); + if (mmap_is_ia32()) + return randomize_page(mm->brk, SZ_32M); + + return randomize_page(mm->brk, SZ_1G); } /* From patchwork Sat Feb 17 06:25:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13561255 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25C63C48BF6 for ; Sat, 17 Feb 2024 06:25:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C82C6B0072; Sat, 17 Feb 2024 01:25:52 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 10AE46B0071; Sat, 17 Feb 2024 01:25:52 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D357E6B0072; Sat, 17 Feb 2024 01:25:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id B62476B006E for ; Sat, 17 Feb 2024 01:25:51 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 6EC1C1C0099 for ; Sat, 17 Feb 2024 06:25:51 +0000 (UTC) X-FDA: 81800310102.16.F10892C Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf08.hostedemail.com (Postfix) with ESMTP id 8F471160006 for ; Sat, 17 Feb 2024 06:25:48 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bFe6mOFC; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708151148; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=E2RXdELjA1+Y5TPLiUTm0d2mhfp+RAxxenDK5Rv9UCY=; b=GXKiU4liDgfbC7mUAdSetj/m2nAuZGExELnUMqGNdsKYxjExb1oGXxJY1P5RVymbMOiJXP 8rjYaSJ9DpYp6oE5uvZ0fjP3aaX4QiNiG8FAOns77ET/X51UPmVL2e0csRN5EA7T4xfqYf ZvF+lROkg1BEiJLjTUaWg9TJlxx102M= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bFe6mOFC; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf08.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708151148; a=rsa-sha256; cv=none; b=UV4bvsafpM3qmZ+dyfniT8+HswxOMJEoyu6xOPTzCM/zdJdbEaAtpyPaQcAsmNbUfL4dWU rjqlS311qAHQkxY6a/seaqEJQDWGjBvfTNmsKWanng0mG7HFvCnKVHDsrj5rkrDNVLZlTJ ty8Yc2ddSJUm721G6p/33i0N3RB3hMw= Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-5d8ddbac4fbso2295403a12.0 for ; Fri, 16 Feb 2024 22:25:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1708151147; x=1708755947; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=E2RXdELjA1+Y5TPLiUTm0d2mhfp+RAxxenDK5Rv9UCY=; b=bFe6mOFCHWeWR49JRhtGxW0rv21CMV3vqE/s6wufO3RXIJ0+fyU8qdkgCkpNFs5cUy V1XHB7VNxFCHUkdJf/9PTpxxqBTAqHmq/wJBrxe9YHKoVGUf2CZTuLxpav8QQXQJE7TR 73yA9a+R5yQQAhGF7YZRflssBld/wL8p4M65Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708151147; x=1708755947; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=E2RXdELjA1+Y5TPLiUTm0d2mhfp+RAxxenDK5Rv9UCY=; b=dO3Ild8c2kyiF1lbTaawqMrXBCAylBNWVQDR4mKOWdTb+j954T0aSmu5eOXf40qaF8 cI88z8wY9aMF/KES4cbrxZDyndRB5rm1euCAnNbcitk4NF03qkRYbr1phT0cWYbJ4B0l gXIY3YeDjs/tzzijBTONGfRCzK8J51/koAIn9Rq3pgNtuenzwU82VKpm769C6j0nDEJ2 2S+6db1uDoN2Zcll0rnd/Eg0yKh5VqcLh5ROfQVslkO6DnlgYuhlUbzceyGCv4Euu2BM rvmKKYt8CM8UTWVi0QznHs30yC9C4MsgsuWsspfCHGv+LtRTtV2gtg75UDO7qla9+kUK 4N2Q== X-Forwarded-Encrypted: i=1; AJvYcCVg8XaIHspE8KqKMjh65SWSyTOZxiRs87b07PFmhG7KbGqE05THr7ySjkojZV4nQvpzVy9Ef1htZR297C3oA69yZKc= X-Gm-Message-State: AOJu0Yyvmytajwv+8PC1WAaPl4ocjaYi8QqbPJzG+ezZk5DJ3wPsTPzZ lHON0SfGeP2gG/s4aeSDAugfNPF5P9BmdS45d01CKm80z96rCyYYZT1ySUYGqQ== X-Google-Smtp-Source: AGHT+IFmbsrgSelSyVzmXuB/u0yC3Rb3JZKRSRjPThoVTEFLQ9HMIMVjPwpT7DE29BVipx3A1VGplg== X-Received: by 2002:a17:902:e80d:b0:1d9:427a:991 with SMTP id u13-20020a170902e80d00b001d9427a0991mr8385363plg.20.1708151147280; Fri, 16 Feb 2024 22:25:47 -0800 (PST) Received: from www.outflux.net ([198.0.35.241]) by smtp.gmail.com with ESMTPSA id mm11-20020a1709030a0b00b001db6da30331sm788247plb.86.2024.02.16.22.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 22:25:46 -0800 (PST) From: Kees Cook To: Jiri Kosina Cc: Kees Cook , y0un9n132@gmail.com, Geert Uytterhoeven , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Christophe Leroy , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Peter Zijlstra , Qi Zheng , Alexandre Ghiti , Josh Poimboeuf , "Kirill A. Shutemov" , Rick Edgecombe , Brian Gerst , Bjorn Helgaas , Tony Battersby , linux-kernel@vger.kernel.org, x86@kernel.org, linux-hardening@vger.kernel.org Subject: [PATCH 2/2] binfmt_elf: Leave a gap between .bss and brk Date: Fri, 16 Feb 2024 22:25:44 -0800 Message-Id: <20240217062545.1631668-2-keescook@chromium.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217062035.work.493-kees@kernel.org> References: <20240217062035.work.493-kees@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1512; i=keescook@chromium.org; h=from:subject; bh=Y9GWQSNdeMe/TiCQJCjXENrVrfi7E3amSjOSWzM2S1o=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBl0FFoSMLWKnRZV/Xpg3nYIyPCuv0NWoUMuFI3f ssQMNwOx8mJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZdBRaAAKCRCJcvTf3G3A JvXFD/0ZGY+pv/RW0jEwUr/fOJKrMeYvRA+q8dAhwBU4yZf/9WvOK1OItaQt6erwqczIQcGDsKX RWFEhlQbXwgzOXrwCvEVU3X/MwTvOZFnZ0wTXOJZIuqX6uhvJuDZYq+kDfDixzSf+vvZ5N5gZBO TJzXBbBFV7TqO+okj4IS3xOJWZewgGjhNT8vbeQcPdzj69HDDkXXfpLkoSfygpZcWqlp9XDZiNy vXK3r7lesiRP3IhhoJj7l67XzCYktFTMcgxwx7uHCkePYddv5NSQpYuV1e3GrWYPneqbU/ta/RX cWwsnNmxh2abzRU47UKh05W/uYImIbey5l0CSZI/7QN6m152TAREIrmIXwl2k22fjZgwgd+Apv8 4oW4U/bqzoG9w1PMnHKDMQ9jsdEQB9hjMCKn8XCd+7Gv1wyNPPDXV5RFfLYuFJeaPMBdmXP7zFy E345+0/LhEK6UZl9XBsjpHxXtro8hrLNXyQJNR0dzipAEXd7VeizjMBrL4dibLwpq9Vt5GEwcbV rdHrk6W8yGkeyTm7dflKIXZxINWwAC8JEcnyTOaMiaSf+7Trt7zTSHdjJwqs75llY8Q2hwdTTG3 H4HQ8+CnaTwekWZMYV2AJy4oOxU2TWbO/56rrPwpm2xEE837qZM9Jz9EeaTLbA9t0NKKZotRk7n IeAJGDC3TTWSd+A== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspam-User: X-Stat-Signature: 9eipyeizbw5y9etpaqqk71x75kkc8jy8 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8F471160006 X-HE-Tag: 1708151148-19543 X-HE-Meta: U2FsdGVkX1/d6aEw74wmE2+s12r6QPf2JtBBdoJPa15Sbdp/lB0eMqZe3zrFw89jR5roT8iAtBumdLujfk7DGyzXSj8mDGStM2nJUCa8horgN4L98NF5oNJD3mZrkMwWTw4P73L/hHJ/L25N7QoqUqUw3GAeCT5NN1gnW5D+mbqb7C0PJSTYziEBjfwORtcPpYT58PinOyJSjQSoycnFFW9D6+8pAf9iqgouW+Xyx41DZ3c8Lz/WTrrijzsZ9I7RSCEIM88BVfuuDC/hnm428GrtmmdkyCazMTWREuFVdwVXfUUKYQFfD+UUjdRIz84L+2S+18jXpaxe5cgPDepQlaFPTUR6f28WkfSkUHneLYxj+W1zY1ntqrqxodE56xo4qdgCKPkTiydJsU3HE1XRvyN4YScvDrRbE1XcjQTbJjyvewP0nvwL3bm9l5O34SibBiKgMKGAzp3jBgfRzPgzD7Qzlawu7t+rZxNaDGSiep8W4wNs6B8LP+PjZBiwqOOv65EUbLtk8GepgXtV+ckjT2RsfA1e6ECO1/qJERVmKKE5epEXWct0zxJ9fFweL6GRpWisilMtp0jKEyrjY7Mu61UvWnM0QEevMUd5fCo4Xg3izGHkTyGctztdbd9uOmJmzMt6YYkoNqqgRindELiKHbWBVcWrUoFmpB7np1voHauAFI+5hjpvzoWYXqg/t9Qw5Dncb386OKC0UgHw0+89j6Q1vju79NGfk/6ht9seEXKEWSh1QW1f5Y0Fg7jeyzNhVqlTaV6NgFic9b9xGLLWW8kccsaqlxS7C3Iu0yIDk7a8iAaC95BCEOqdeFjXzMH+0R/pv+7gaLkfJX2wkwpN7ut8kW5MjEvXijwSyF6TcFNzQ7GLcyVuj9JXXld1aosfnaFANt2GmWwjw9GPPA2J2EaBxQjQ2GOPQozxHf4u5ueMH+NkNGD6mGl7SB1Io+ZcbiT6DnYzaiiAjVMWt3a GsXIoP7x JRLEMz4n8/WC5FItHps8unPx3AseHL5nwe99MyLCT0CBTLgJ+ZKKkRU1jlapyNEA/rYDjfbaTJIHSHZajjRxRf3VPax+XvQHnVf9xS26L24y5vBcvykvKc2RrH0gclelE9g41jaXGmFRjLB8QkNpPhmGJg9ZespBmmrWIFNtqylfdoqk= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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: y0un9n132@gmail.com Closes: https://lore.kernel.org/linux-hardening/CA+2EKTVLvc8hDZc+2Yhwmus=dzOUG5E4gV7ayCbu0MPJTZzWkw@mail.gmail.com/ Signed-off-by: Kees Cook --- Cc: Jiri Kosina Cc: Geert Uytterhoeven Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Christophe Leroy Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org --- fs/binfmt_elf.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c index 5397b552fbeb..7862962f7a85 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);