Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1143218rwb; Sun, 6 Nov 2022 20:16:17 -0800 (PST) X-Google-Smtp-Source: AMsMyM4ekGvP1AdXM9GS9t2ynPKcooTbZ8q2NrCo+r00Ra87EtHcybQajwLiOX0yycRgwNCDR6Ml X-Received: by 2002:a17:90a:4888:b0:213:d512:f034 with SMTP id b8-20020a17090a488800b00213d512f034mr42981296pjh.133.1667794576916; Sun, 06 Nov 2022 20:16:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667794576; cv=none; d=google.com; s=arc-20160816; b=OZUAeSJcVoENTTTktpL09VzMFM4nJrXjKjXVRBlKX2QtcZTZem6ft3QtV2Qo3ghlnV mFX6rkF9eutzGEAHc7WHRh69Xc7BxH/w6xfAKXnk6Cen4FnhKisQeqHdM8BatghlxcIf RA4V9FD+54eMjxtrFZg6ZeiG0lAHsL8LgC9ICLIOV2LmPnn5XmG4nUHqUBM/HyByE+LX 8dcVR2JE3yn9/AdMaHjoYRevrlgPNNY+AuC+3CaLvTKcYBBSfg4dU6QgxQOH1l2l+uzE wq8NDWLwalnWC9zlItmBunUlsOLIcWkmaQgocO2FWgEF6IHPtq8U23RC+R4M1nm9l4PU aL+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=tK5YyOubJwfiTVmlG1/f7tjG17kEPCWvBahIEcz+8l4=; b=OriGfCLiBkY0MMZ3sppiVJRRF8fnc48AtVEyHh5ERie9KkeQmbXdpFMZTl1OShlDbb G70O+geTGr90RIZ+dHmDmxALJ/Wb62IF5IMBOJaSTOhNStOBYVeNe8G9q3KYOdwQEJ6m lGSEKcU9ayTssyyoIuoJ9LH/cVq/8VOAXlFKXZDwU+J+I9lxbZuwY2u3swrGlPxisgNS RKe9+3JIFuJ66KyoBsjikJ8TVY1IAB4qgdm5vaincDQ0VrvMXJgIRE2qKAZkLDvDI52Z 5f5MFbQJ7gU9I6hvvRW8hjFI4Gk+QeRKff8WpyeF+YX2KHSwkt4hzElM5o76vm/8WHKE DAog== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="ZyitcS/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b5-20020a17090a550500b0020388f845e9si12533719pji.52.2022.11.06.20.16.04; Sun, 06 Nov 2022 20:16:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="ZyitcS/3"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230302AbiKGD7o (ORCPT + 96 others); Sun, 6 Nov 2022 22:59:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbiKGD7m (ORCPT ); Sun, 6 Nov 2022 22:59:42 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC039C62 for ; Sun, 6 Nov 2022 19:59:41 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id e7-20020a17090a77c700b00216928a3917so8491889pjs.4 for ; Sun, 06 Nov 2022 19:59:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=tK5YyOubJwfiTVmlG1/f7tjG17kEPCWvBahIEcz+8l4=; b=ZyitcS/3gs3aZQiGqG/Q7GbVOlc1TqzvFtgbdhE/AqyUaP1LLQq7PHRtclmapVQ8vj 8GKLXAi+Yh/h0uNE8dbF0XQ5AzmseEysJikeo/ZeIDRKV+Il03kMhToc8viko9/AmYul zcQ5Eeefg16RBLveRSsNajatDmqhu8tm32z4Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=tK5YyOubJwfiTVmlG1/f7tjG17kEPCWvBahIEcz+8l4=; b=iZ+fe2Z/F7UXvdZE9PgpVlQDZtXu/GYcglnyppdddvVxuflrceGUHRv6Y4gIYwyK2i B33s85HezpJzu/ZOof1A8WPgLhD686LoB8ClUCJITbPdS552MwSNEVNvOq2RVjGs3ssf 1hq3AqStvxX3QNXv7JsJh+P575A797fJWKH8ZtBeF9UsdwkrwvTrpnrpkFWv+jrIR4Uo uLOLT7jJhEGYGuDoFAG9jtVjrSiMYP+b2eunpW7OPTXD4G5eBJ5ZJHiEW8z+UH19BF1e E/15IoGXt7RX/FzD3RaKQP7xpbuCtRXOjGG79dBxB5WeKOMeEJUqD5N26p9piPMS+fD+ lGZw== X-Gm-Message-State: ACrzQf0DeWMGYAYhPDV53c7SmWjI6K28dJ9EniXGuJp6OYgk6rJtpC5h y0WbTig7x+FzX+iyWyP3ZOpURA== X-Received: by 2002:a17:903:1207:b0:185:4042:23d2 with SMTP id l7-20020a170903120700b00185404223d2mr47766328plh.143.1667793581465; Sun, 06 Nov 2022 19:59:41 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id w13-20020a1709027b8d00b00186c5e8b1d0sm3807639pll.149.2022.11.06.19.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Nov 2022 19:59:41 -0800 (PST) Date: Sun, 6 Nov 2022 19:59:40 -0800 From: Kees Cook To: Pedro Falcato , David Gow Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, sam@gentoo.org, Alexander Viro , Eric Biederman , linux-fsdevel@vger.kernel.org, Rich Felker , linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com Subject: Re: [PATCH] fs/binfmt_elf: Fix memsz > filesz handling Message-ID: <202211061948.46D3F78@keescook> References: <20221106021657.1145519-1-pedro.falcato@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221106021657.1145519-1-pedro.falcato@gmail.com> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 06, 2022 at 02:16:57AM +0000, Pedro Falcato wrote: > The old code for ELF interpreter loading could only handle > 1 memsz > filesz segment. This is incorrect, as evidenced > by the elf program loading code, which could handle multiple > such segments. > > This patch fixes memsz > filesz handling for elf interpreters > and refactors interpreter/program BSS clearing into a common > codepath. > > This bug was uncovered on builds of ppc64le musl libc with > llvm lld 15.0.0, since ppc64 does not allocate file space > for its .plt. > > Cc: Rich Felker > Signed-off-by: Pedro Falcato Thanks for the patch! I need to triple-check this logic, as there have been some overlapping (or out-of-order) LOAD bugs in the past too, and I want to make sure we don't accidentally zero things that already got loaded, etc. David, has there been any work on adding a way to instantiate userspace VMAs in a KUnit test? I tried to write this myself, but I couldn't figure out how to make the userspace memory mappings appear. Here's my fumbling attempt: https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/log/?h=devel/kunit/usercopy I really wish KUnit had userspace mapping support -- I have a bunch of unit tests that need to get built up around checking for regressions here, etc. Anyway, I'll test this patch and get it applied and likely backported to earlier kernels in the next few days. -Kees -- Kees Cook