From patchwork Wed Sep 27 03:42:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 13399844 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 46566E7F15B for ; Wed, 27 Sep 2023 03:42:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13B048D006E; Tue, 26 Sep 2023 23:42:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EC638D0002; Tue, 26 Sep 2023 23:42:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ECE1C8D006E; Tue, 26 Sep 2023 23:42:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DE8DA8D0002 for ; Tue, 26 Sep 2023 23:42:29 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id B3BC71A0ED4 for ; Wed, 27 Sep 2023 03:42:29 +0000 (UTC) X-FDA: 81280980018.15.AD112B8 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) by imf23.hostedemail.com (Postfix) with ESMTP id DE568140006 for ; Wed, 27 Sep 2023 03:42:27 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ManhKK7H; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.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=1695786147; 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=PGJfI+lZ4iSfQ93mihAmCKetWCxWqPDzFkg6Q6FWgBc=; b=bMpmRSB61NS3iBvmi006fj5ramZxJM+TnHT0PYvHGV2yE+gVqeY70DiH/f+tkk35XZx+FW gciSNvXu/6KGhipPj/rRc5hez3v/WJ8rVXurZ+Qnv0iqDD1vTMKr75RsmdOK/BaAI0DLwc GtOxuui9pMT2DkAtg+kpgyengXvCA1A= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=ManhKK7H; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf23.hostedemail.com: domain of keescook@chromium.org designates 209.85.214.173 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695786147; a=rsa-sha256; cv=none; b=yQJgFj0+CA9/yjV9ynq08NG1mtantpa2hOUgu9VoAnamYaj4cfRRC0dghNHhkZdeazJEfk TB7BbZiNJ33s9FQ8lkhz/jRHmdfAYF72QwqtTlo+mktVqwKLUI4Rp3rUnw1Nc1hZGh5yq1 a8CzgCQZqY2X/92x199MO1K5U67f9Vw= Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1c46b30a1ceso91357565ad.3 for ; Tue, 26 Sep 2023 20:42:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1695786147; x=1696390947; 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=PGJfI+lZ4iSfQ93mihAmCKetWCxWqPDzFkg6Q6FWgBc=; b=ManhKK7HIx4FX/Hb4hcwrBOX43/SxZagmD1omOSeIaL0A+F3lf4XhwNoU0HtvBWIZG c++27/Zh9Gz1nLzhqfeK+/So0wXVPF8QO9P6y9ntHbhuyaE1OssxJN51Bk0SlBLJoWou k83Av1WENzHBVsmWjYEygIe4qHXrOcSWlFSTA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695786147; x=1696390947; 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=PGJfI+lZ4iSfQ93mihAmCKetWCxWqPDzFkg6Q6FWgBc=; b=bGfIRI2vLn0Y1mjAmyISAeppKaP+lsDwwOL8UlX9gP53KCNXfpKnxfHVjutW4oeWnT iWVqh+vP6+NeWG0+qL490zUFc7bAM4djpuTLwtE6u/xAVadR+V6bgVxA74ejoY6Y+3HW i8PuB3YecMqWLaslJYD10n37egwEYglJRqJBc98bnL5wPE+yPDDjszTAmBIhrSKd+AwG 0UYcRNGeH0y+54wLV8arKkg/hM1DLTxkvfJURtpyk590q9HF9R6/n/D7cJFPWZLyexS8 tSTKG9I66jSjzVsBihqsUqIpme0D+kS9UQXIhojh6FZEIPcmpEb8I7kZ5ZCUYBco6wbf LtEQ== X-Gm-Message-State: AOJu0Yz8mjhNFAv92LTzReWiFfSQU0lufY2JPsKViQW/3HMe5ZpIlGb5 xn4OGZDYB4U89KH8U5WbGk21Ig== X-Google-Smtp-Source: AGHT+IG3vmw0qL9sWfrthHzlDQju/5u8n9c1TNnVsBUEHwDjOoLhNFzP4dPTCN3Xs5EKe3Hg9ILQZw== X-Received: by 2002:a17:902:c94f:b0:1bb:598a:14e5 with SMTP id i15-20020a170902c94f00b001bb598a14e5mr992121pla.43.1695786146709; Tue, 26 Sep 2023 20:42:26 -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 jj11-20020a170903048b00b001bdc6ca748esm11918838plb.185.2023.09.26.20.42.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 20:42:24 -0700 (PDT) From: Kees Cook To: Eric Biederman Cc: Kees Cook , Sebastian Ott , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , Al Viro , Christian Brauner , Pedro Falcato , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-hardening@vger.kernel.org Subject: [PATCH v3 0/4] binfmt_elf: Support segments with 0 filesz and misaligned starts Date: Tue, 26 Sep 2023 20:42:17 -0700 Message-Id: <20230927033634.make.602-kees@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=868; i=keescook@chromium.org; h=from:subject:message-id; bh=lOC6dIm6BOZ5YdJlYfTe2LeekCnJ++QGcs0vKnnP4ps=; b=owEBbQKS/ZANAwAKAYly9N/cbcAmAcsmYgBlE6ScQrYRvW7/cLoTymNp+QzCK4E5+g2pQV1h7 2TULnPSJZmJAjMEAAEKAB0WIQSlw/aPIp3WD3I+bhOJcvTf3G3AJgUCZROknAAKCRCJcvTf3G3A JoDCEACiqN/qgoJ0Ne6hePry6JkdekxC2ghpkyg+pmI99pumwTcgld+j67+ZMdlJ1uoiL+ZLTZW kpZQc19iF4kz/hS2BzF5fc3o9zbbnksf5M41zq8EHUWlTko2ebswjaLUUI/dADhqmcfsFOxdlYK a9Wn4Yo+Jsryxk8lZr8iC1UsqxoN2OD1JZ/IScy8PRDGyoj5SW/8KXm4YVbT+dUCx5rv/HJ+qzk n6mLTE09gnExRim0Wkug8xsfhXdnRLf3JEwhHm1uYDvLhIVG4jp9a/C/HyB52YRBBD0pM7HD93r eDzoVjwiGJLGETpwCEoKdJaiNrkBYYwZ4uS/OTgkBkxm/y/MykXwxzIH2FQRU6ex9YHjbc68Re4 abj6Ut8m5K8OBP497GvZJeM6fR4y1bL3UtMBqHGNipTauOPZtp14wuE26++n4jCcIdnbdo9FmYz GXg3/jNe4JkK4sHhwUXSCm07Gn3QavzFisWXca4G/AqBjF5k4hwBnYd8jg6ObkJgzPZgIHuZ+CN AiMdCAMOGj2d0N/Jlti27JIkfB5ifjxiV+OXygf99lkJgwVe18U6L6cPvdtxbYOW3xWLKUwxgqL mpHIt8n/rKLRvretb5VXJySNBh2q2kAngczfkZzyHdbxaj6wAKLbZiiVdt+WDa7CcxMhvKi9oot B6BlPROL CGrPl5w== X-Developer-Key: i=keescook@chromium.org; a=openpgp; fpr=A5C3F68F229DD60F723E6E138972F4DFDC6DC026 X-Rspamd-Queue-Id: DE568140006 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: ognrc9byqgyfxnjjsusq61mgd8q8ib4d X-HE-Tag: 1695786147-191897 X-HE-Meta: U2FsdGVkX189INXG9rh1CFaz4hAq7RjWp7CcTieMPSLwf+/t/ocIpqMu2fwNJHuIp/w1+PSp6/V4fEmQ1VEnEewVxmOMlmFymOnqT6BZw3sYSA/059R61jql1GEghPxpsN0MGlvH3ns0KX16Hl5gEoKkm1UT/2Lfi0PIbfjFICEjrYCMRU/5dOoVoj1XNIq/MKwr0IX55D6hX+EvJQ/YA+Z1lE2CXWGETzRBt7p54EE7i5awDguETi7aSc/3NipD/YI0WezNJkurUdzx23TdWCEmk3gQjKEtcfUyf0bZDLduEVsshmaFMqcsij6yzMAWETsYVRUYcmOJ7qFfvk3nz8AkmnMALSUqLQD9pPk8s+fWHCKK2SiKP+fON3A9Cf6RsFCBQ05luxJNWtxifvOJAPqfi0b5qtq4uSPsDUa68kKllxI55noZQj2Zj3PepReMILPsKUJxNqtDroL0yprgYx6p2LKudhAE69B32kvMYGK1djTjgebtgBAjtWXdjA3F0sP75ntTrdhD50hYM4eDgBEu7BTvTHpSX0ECmR0iFWa/XE/6dMTYkodeVDuxr/PRBO90RBrZ0VTO+f3dwGmleE2L61FIrzUOxhbS4+UlM0uLaV4bZPuz6FcjTPHwNRcPeWmSHU/Ds2WQvupIPzsuQVbCprt/ONqUqkDkSFF3GRQVqHbTo0q01hmlpUVUSz5X6s1MbzyolswwCsB8QQEFW08gYT9bz6sT+f0AtidO6zR0IcaAgzX9g57zNO2+eMHce/A/QcJy+2QA5mD80G4aKB555rIfj5DKxJEliAHaR7Ah/5kbS5R2SEheQ5/YATsGk9fJwHIB7G8kRLLvJ7FvlCIjP85S9Tt4da9O8fGUqsuEjOKs35sxrcahFfD0LDRlw4MuDiAdX60sHugCphX46Gtmkr3KGurzLQNtzVf4ayGKw5IaWx5OAoE9D/jpoo6wr5F659iUl1gHQiKgrKN CeMC4c2X UcYo2JyhBDV0oCddoAVa+I1JNMVnkFSXf0G8IiPw+ium9Bi+3XcwjoNI5omQbb3+ay237kLLvYvOA/7Ljh2sbt8CubPH2D4cTvZPyMP28XCdLh2UU7p94gxIBsridgDFQCB5tsfZvf4ZmbxyS4xNAkxqLm4G3MR+h61J2OJJSlV+Kw+Xd057Ivp/mzEQtSzAl+RvPhon4Zv1k+ejhtLTsZ64uZDDVKZdo3h9EjuAhW2SFdyrpFVBkrfIe0VQqqH+87L7EDXDQulpnOUtb4BFffVE9uLalTaeY8vKUjep2JPJIK4dl69XaZzmDPDtDk6CXAMvtrsBTNzm7q4oJ0a6Jtnqoa6NVk7045VN16wV10hb/B9tbqt4AJcZkIqE4AVnHSO0YRjmgM/FP/5hmFzWL12qfJL1q2gcTBi7BOr69w1Wz1pJ9pRAhbMPI4w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000193, 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 - report padzero() errors when PROT_WRITE is present - refactor load_elf_interp() to use elf_load() This passes my quick smoke tests, but I'm still trying to construct some more complete tests... -Kees Eric W. Biederman (1): binfmt_elf: Support segments with 0 filesz and misaligned starts Kees Cook (3): binfmt_elf: elf_bss no longer used by load_elf_binary() binfmt_elf: Provide prot bits as context for padzero() errors binfmt_elf: Use elf_load() for interpreter fs/binfmt_elf.c | 192 ++++++++++++++++++------------------------------ 1 file changed, 71 insertions(+), 121 deletions(-) Acked-by: "Eric W. Biederman"