From patchwork Fri Sep 29 03:24:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13403632 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 39CC6E743DB for ; Fri, 29 Sep 2023 03:24:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ACC838D0099; Thu, 28 Sep 2023 23:24:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A7E3A8D0002; Thu, 28 Sep 2023 23:24:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 94E6C8D0099; Thu, 28 Sep 2023 23:24:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 81E158D0002 for ; Thu, 28 Sep 2023 23:24:40 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4F9BB41080 for ; Fri, 29 Sep 2023 03:24:40 +0000 (UTC) X-FDA: 81288192720.09.A7193BB Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf29.hostedemail.com (Postfix) with ESMTP id 5D96012000E for ; Fri, 29 Sep 2023 03:24:38 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bnUWn7XD; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf29.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.178 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=1695957878; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=DZpy/gLfnuMsQ3zYwfMZFr7l/UudGqfvJfNYCKkC6BA=; b=lwVtbyhljakrlBAjs82V29xHS98E7IMKKEKwghBS4zYRcnRxyimuD/DRItFwcYZacviXUS tKzNDPa6aAf0EUU+baYsKuNMk7U4CX8yfJKHyKCIKJdbvgr1l7hREMokWnVy/yoKRXdbeM CdhjxVd6L0tLyelVu0DwCiN1sxBziAw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bnUWn7XD; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf29.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.178 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695957878; a=rsa-sha256; cv=none; b=niVuom3fTwGdI7B8jWPT/wMCKN7k76mErawPwn+JwFT+O4HzB2HwQ+jDKIQC3fjeLtTnkF oOKKSdK5MetORJp7BMKAPYsjhmRHov+slUiDSNnSYZY5c0II+y2jkpqpvUJ1f2IWM977fF t9VoGieMMRxrCUAMAdM3Sb+eUB46WfU= Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1c4194f769fso102694025ad.3 for ; Thu, 28 Sep 2023 20:24:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695957877; x=1696562677; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DZpy/gLfnuMsQ3zYwfMZFr7l/UudGqfvJfNYCKkC6BA=; b=bnUWn7XDYYbrZpwbsojS9WZPK6gVLhz3IuFPxb12DPEwmvRrTA9c831tJ+h+qnkh9r BIhqFej2tKf5l7HSQW7EaTSBigfW9Y997beVKUFTvJ9zyEL0HaiYBd3ejIVvoEFpwXQ5 gwFYbrM477Q5RptbjD/5xKlBAjuSd84Kovknw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695957877; x=1696562677; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=DZpy/gLfnuMsQ3zYwfMZFr7l/UudGqfvJfNYCKkC6BA=; b=NHjyKpn6l4vRvs7kcXFpvD16a1fGLaV/Voe3NnK08uPu4zK26xBZ4l/6eZMU7U4yFW 1JbkOR8Jy8baYm6Ir2JEmoL958liUYFiyRHuDj68KRUDyVhc9CRFkzRNw2tX4GL2+ZPB K0AFYgcaEObD39thS9DXglYu7awlMY9eSwQ5FMdGGCZEBSOB4OHZ0llreeC8qBzaZoJV gK1ddex563Pe75nLqj8qj8gKLN7fQf/SwYWRI0oBBIQBTHfLXeTX7P+0T0IM83wK5CD3 FL51J3C3QTvv9FA4SsU7QnoudYmXgq9YqE5z+wOR3jRtXolraQwa1Rbvo4nSkFiEMRye mvlQ== X-Gm-Message-State: AOJu0YwTbWEpM3J/I9sB5m6kVMKcg4m1Gx4SZ9LO+PsqpbS3BObbG5rN nPeOvLXlmNDe+ylHJv/09OftNQ== X-Google-Smtp-Source: AGHT+IG9cnWbn0hVG+1LR+a11ImsezJeyyFe0SBw+gyrL4qhOuJ5PkqXrWcVlge8k9fcAkF9UBo6zA== X-Received: by 2002:a17:903:1cf:b0:1b8:94e9:e7b0 with SMTP id e15-20020a17090301cf00b001b894e9e7b0mr3606862plh.9.1695957877031; Thu, 28 Sep 2023 20:24:37 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id iw12-20020a170903044c00b001bf574dd1fesm6250537plb.141.2023.09.28.20.24.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 20:24:36 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Sebastian Ott , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Pedro Falcato , Al Viro , Christian Brauner , Andrew Morton , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: [PATCH v4 0/6] binfmt_elf: Support segments with 0 filesz and misaligned starts Date: Thu, 28 Sep 2023 20:24:28 -0700 Message-Id: <20230929031716.it.155-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1382; i=keescook@chromium.org; h=from:subject:message-id; bh=uV4AJsRv4n/gB4mSOC9KIOnGOAI8uNiU0zUGBP7t1x8=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlFkNxLv+WtDGXS3EGA7QG2806nd9yzM662vbJz Z/QF9lP7jqJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZRZDcQAKCRCJcvTf3G3A Jl1KD/4w77J7PmG0TdHjUB7lH4ZlBX43xi8xD755lb9vhHxLRTtI3hqQ+JvyAc97r4JGaph3Jk3 +kKf02DqkcBcEm0W7oeO0JKZtqIfM8XEHkHQ9/pE8mKfalwC5DCFnIJbNcsdxr9SSwhz0POUO3E QaUEJZjccKFkHTwDKLd3XRvNdDZ3jll5HxQfWEKXvyjNCHVTG5jgC+GQB8d+RSZPwp1CGvEWqN5 4GDF1tB2l1DHa4lX6yI8qPhawqRzZuJFTO3SSse+E2IPkgfkt6VfJ8cWyqDd6AMALfIOl3hIq7E u0hVjNyK8WcQSmSzMHbrAHi1hVxdRRZzfKJw49k9mbc3zUKx2iTEbJRitqjEQOXaE9xDtpENZ8z ACRF8mJ3ewqtPtv5N3XhiB9SiOUGIBaWR5qCcgL989zLDhLf7IdBgj6pCpz+35BH+8Jx3ioPlse tvWvLx1KjocOYMQWqde+FJQsJokrG/P2gt8jKDPp96b16uQlble+qU64f0zUbbTRQXjRaGP9JE6 lUxI28L4rZ/qPL2gFq6pMGTT2offlDs6i1y5OBptudXqWdphur4s1n/ctL4RlT89tTT81h/qPgm T2AB0n5jBX6DQm4Ji0DI78f0/MRN0aAbjeLYg7EiWO86oDL4JmXSqgzGwkWXgxhXTqngX8Gnzoc dw/DwpD vMJ3XKAQ== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Queue-Id: 5D96012000E X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: nmy1xmm4ou6t3u43g4qs83xn1someape X-HE-Tag: 1695957878-28917 X-HE-Meta: U2FsdGVkX1+uSxbCISn4S/OFVnWZTE3WLowttT8CtthdNyQ+l8e/xcvtE50D8WnKJGjsjdAFYJemOrw5mDAL1dyxYZR/9tqG70J0sm4t6pvhmm09oHN0UrF+WfVreS7BayXMsv0HICj/33SrHw6QUarwcb238jgcuKTOUJcYXUqx8HBML46fMlxB+P4Ae0QAMfrW1do5w+kWRwK3+q/1dWDfBpfxQdmAjprnEnvkBo69Elh6+exOo/TQ4JIxmeGlyOHHsfCs2KEf5uCHEuwVIyWCfOol6gyIOB3mfNRJsEzpnVmsINBb34bvyaWImetimBEE9p1s+5OnFveejVdF8LVr+7DOwrOLe/mXhOobqkY57kVecKhaxu8wGFNoZvm/6WqyEj40a5PMpVIcJK88BvoLzn6hwB1NxMOclrAWds+BkO0QcZ+qwHc0rBVEi2fx/HXHPK3/cyk17EJ8rPmzETEsxv1EpPWeFElxapcpEfuo79RGEZII48Mpxy/Qi6fEsEbJ3zytvGOkSOTfRZsp2dZbs4NqNogXKXi6Qrhmdg4g8Mud8okt0iNqbV6Ah4lPrO3wPeR6HthTLYMxXSf4+vrTH6IcNFgBH4ESdiaPrGqQEhSaRueqWjjPm36XrDfz/LE3uqKRb2OYdmQZ+2NtJg8J4TC3PrPBQoFUqNymBb17ivmFvWSsnmn5IgeRk6zwre+ThSnzZX4gGKV0EdOdQFqkG9uIHG8gdaR+SwHbGIaQjC6bZ+gX5Pmijl1UJiwYPOKl4qPg6s2yfivkQHUIp3MHBmVBm/nM4eI3Ccfk+DXWK2UywyAAg5XNWWuc5UPEW3dmVXMs4xyLidgI6u043ZxEO5H84TW8w/TL9ZefVaozkTY32Q2vXke8i64FSrRoVAhyO9x8lZ7IhejmYYMEF5o0D463nHDD8De0jXWxWR33A3cdNEffYoWWx3LIhzCVo2q5IHmfwKPlGoJseQS HINRCv5v 0ogyEMtkhBu0Us1nMBC5oi2+IiHJhCTaYH65nrnYFYzsAOj8Qlf5O39i5V5YZlfJllfZfy3ErlLEJ41kyjT8YBLSEEBUbe2Ah7Y2wCtGZk1Hsc/L2KLLF9+9MvACxqWU6T6ALJ5N5oiiGj5W4GT97LYoIO6dSgqhYFU6ZNen9OOHFr086LKj2w2v0hgl0tH+B20WNvE+UPg5aSzVRB41KC+J62ket5JWM5KcYPUMEkp5DPKovI2T0Fh9PQTHAQHE2gLQDbDoTyjba6C+cfqM+Bu6gYpptJz5UelDfLhF6oJg1NvslYHuu8Q+NLrMXBY0DSFZwZcDG/n8XavRB8J69/Ysg4Z6fSR4rJYp5Tp3snbuptM/PgR24HOtvVZeB7li5/M9x33qPJiVRBEiq8y3P9sCIzPmmA1V6/fSNNbMVS1h+7iwExnm4hCydZ96Hy4k7G1zczo0dszdIe2lcS7vnGurXeYaz6nsnTYlDNosoCbzJFWQ8RapbLXTuKJgvzmpZN2NrCfXo78izBCapooC1oYVRI8ZUgf9OjrhRl3IcIbFJjck= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Hi, This is the continuation of the work Eric started for handling "p_memsz > p_filesz" in arbitrary segments (rather than just the last, BSS, segment). I've added the suggested changes: - drop unused "elf_bss" variable - refactor load_elf_interp() to use elf_load() - refactor load_elf_library() to use elf_load() - report padzero() errors when PROT_WRITE is present - drop vm_brk() Thanks! -Kees v4: - refactor load_elf_library() too - don't refactor padzero(), just test in the only remaining caller - drop now-unused vm_brk() v3: https://lore.kernel.org/all/20230927033634.make.602-kees@kernel.org v2: https://lore.kernel.org/lkml/87sf71f123.fsf@email.froward.int.ebiederm.org v1: https://lore.kernel.org/lkml/87jzsemmsd.fsf_-_@email.froward.int.ebiederm.org Eric W. Biederman (1): binfmt_elf: Support segments with 0 filesz and misaligned starts Kees Cook (5): binfmt_elf: elf_bss no longer used by load_elf_binary() binfmt_elf: Use elf_load() for interpreter binfmt_elf: Use elf_load() for library binfmt_elf: Only report padzero() errors when PROT_WRITE mm: Remove unused vm_brk() fs/binfmt_elf.c | 214 ++++++++++++++++----------------------------- include/linux/mm.h | 3 +- mm/mmap.c | 6 -- mm/nommu.c | 5 -- 4 files changed, 76 insertions(+), 152 deletions(-) Signed-off-by: Sebastian Ott Tested-by: Pedro Falcato Reviewed-by: Kees Cook