Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1446979rwd; Wed, 7 Jun 2023 16:53:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5OXnILDBNrplNQJShYNQQro3HsAdDktV3FDGd/WLrzhOtQUq6/I7sYN6LQB0drkLFo5eDh X-Received: by 2002:a05:6a00:22d1:b0:65b:351a:e70a with SMTP id f17-20020a056a0022d100b0065b351ae70amr4024919pfj.29.1686182039327; Wed, 07 Jun 2023 16:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686182039; cv=none; d=google.com; s=arc-20160816; b=jRSZo8xzcFUKSd0WMO8YODNWMzHrmFnCL9xotpTCg2eTnPVecFtP5mzJWHdy0V4Fgi nLRFs8WSl+VCohCgiYXiS/HFPCpnqpy84j21c6YgL6WiF/gmFwRfD8usfB/I79DXx6+w WWFPi40rRfMYB21Nj/1lkVPaiYCBtW45Q3i2GhFHEdlha0rL6tKFhB8oyZCILlzEKz7w CxqiMnB7pmwlKenCYC8TehvSmegJjV2/dqr9yksNaqZo4iPGRx+E/muhrHY56f5JlXSK 276yA0RnVmy52Esnu5pLdwzbxcHX47xTkKuyTui0CglSmD/S24s870EjLH1ceOD8OJaX Zqfw== 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=q85ALpObps5sc/UCVblmdlmcE0aIZmHRuMxmvi7ZvV4=; b=Gbl9kG02LTtICcwuPEa1sCcDekAxjZzRfQ0YufyQ1C44GYGwuWpVorgkmruJEtpB/M KmqdAgSeC57Uu5OPxvStUPtD6wKIiHkHQ2C8xFFofn2rQXmtiGZnYjrVCPBHzfa/BrxW q1LzjKugs1TkwXTVW5fXLhIIlfdG4e6uNL7GmU57WIdER05HVVZXGVGB6knnpVwgVJ/F w0K891ZG9x98Frujtr/MHqIKewvs26WHVFUYyBnk711ggwvwRSJ97A9lzhoVcCbV3+ZL lKQxyDs7BUVgBJRsUQmihmEwLuMy7UmEAD67tCCR4pfcU6fsPmbBF/WesXIhYnav+yq1 zdgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=lV8syWtj; 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 k190-20020a6384c7000000b00528b78ddbdesi70717pgd.63.2023.06.07.16.53.47; Wed, 07 Jun 2023 16:53:59 -0700 (PDT) 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=lV8syWtj; 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 S231415AbjFGXi0 (ORCPT + 99 others); Wed, 7 Jun 2023 19:38:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233353AbjFGXiV (ORCPT ); Wed, 7 Jun 2023 19:38:21 -0400 Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9630A270C for ; Wed, 7 Jun 2023 16:37:56 -0700 (PDT) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-65311774e52so3288965b3a.3 for ; Wed, 07 Jun 2023 16:37:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1686181076; x=1688773076; 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=q85ALpObps5sc/UCVblmdlmcE0aIZmHRuMxmvi7ZvV4=; b=lV8syWtj43Ff/kNItqdKE8y9KFBRtz3T741CER394a4RMHngbFtuX1OVIX0rOLruXT XkH5dqkCV3iSkoPeFmEZh8PwJCU/4Cdt3mBMneFJ3QGZyUUe1hEbZi9eVOiiXIZz4LRQ ymAYcwB9baokNEZhdcnTBgqOSyGwxz97Y5k6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686181076; x=1688773076; 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=q85ALpObps5sc/UCVblmdlmcE0aIZmHRuMxmvi7ZvV4=; b=cXlX67W0eyA1tLrv1d8ZkFFQEm4KGvgPBl+0vU7WYI8y5nHoQ8s2D90GCWHK179LYT fXzxmVB4Xr7EWuJ+ib8PsQ8tETAOndPkVZdMgPafxzv/jPvngFIOo0dJB2yoig8czjPA WoFDkDcl/qpDC0DDNgPYjY/hv4kVXCgYjlNrmSKoUDW6JRKp6ipNsgKUH10Jm8Xny9FY gq8ypL08qiFztO+Kfde/qXj9g56pIfiQomBScy0HOIUVLH05GiZnLDM7D89QHN3sYPJE XsQ4QP4t1zd6MUiGxd4dgR+DVnRLXq4gt0jowrd/g/Bz4dMxQ4S86CDVDkyTKhafZMA/ PPqg== X-Gm-Message-State: AC+VfDyjTm8/UB8ruUWpDrdO9g0GZ26KzmXHaDRjZLevEPkoBveCVHcZ CpIOFKv11+wrPtXVE7rrmKr1nA== X-Received: by 2002:a05:6a20:394a:b0:117:51fe:9b4c with SMTP id r10-20020a056a20394a00b0011751fe9b4cmr2792096pzg.7.1686181076046; Wed, 07 Jun 2023 16:37:56 -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 p19-20020aa78613000000b006414b2c9efasm8859392pfn.123.2023.06.07.16.37.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Jun 2023 16:37:55 -0700 (PDT) Date: Wed, 7 Jun 2023 16:37:55 -0700 From: Kees Cook To: Christian Marangi Cc: Alexander Viro , Christian Brauner , Eric Biederman , Mark Brown , Dave Martin , Catalin Marinas , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] binfmt_elf: dynamically allocate note.data in parse_elf_properties Message-ID: <202306071636.1C35171CC@keescook> References: <20230607144227.8956-1-ansuelsmth@gmail.com> <202306071417.79F70AC@keescook> <6480f938.1c0a0220.17a3a.0e1e@mx.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6480f938.1c0a0220.17a3a.0e1e@mx.google.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,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Wed, Jun 07, 2023 at 08:31:58PM +0200, Christian Marangi wrote: > On Wed, Jun 07, 2023 at 02:19:51PM -0700, Kees Cook wrote: > > On Wed, Jun 07, 2023 at 04:42:27PM +0200, Christian Marangi wrote: > > > Dynamically allocate note.data in parse_elf_properties to fix > > > compilation warning on some arch. > > > > I'd rather avoid dynamic allocation as much as possible in the exec > > path, but we can balance it against how much it may happen. > > > > I guess there isn't a good way to handle this other than static global > variables and kmalloc. But check the arch question for additional info > on the case. > > > > On some arch note.data exceed the stack limit for a single function and > > > this cause the following compilation warning: > > > fs/binfmt_elf.c: In function 'parse_elf_properties.isra': > > > fs/binfmt_elf.c:821:1: error: the frame size of 1040 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] > > > 821 | } > > > | ^ > > > cc1: all warnings being treated as errors > > > > Which architectures see this warning? > > > > This is funny. On OpenWRT we are enforcing WERROR and we had FRAME_WARN > hardcoded to 1024. (the option is set to 2048 on 64bit arch) Ah-ha. Okay, I was wondering how you got that. :) > ARCH_USE_GNU_PROPERTY is set only on arm64 that have a FRAME_WARN set to > 2048. > > So this was triggered by building arm64 with FRAME_WARN set to 1024. > > Now with the configuration of 2048 the stack warn is not triggered, but > I wonder if it may happen to have a 32bit system with > ARCH_USE_GNU_PROPERTY. That would effectively trigger the warning. > > So this is effectively a patch that fix a currently not possible > configuration, since: > > !IS_ENABLED(CONFIG_ARCH_USE_GNU_PROPERTY) will result in node.data > effectively never allocated by the compiler are the function will return > 0 on everything that doesn't have CONFIG_ARCH_USE_GNU_PROPERTY. > > > > Fix this by dynamically allocating the array. > > > Update the sizeof of the union to the biggest element allocated. > > > > How common are these notes? I assume they're very common; I see them > > even in /bin/true: > > > > $ readelf -lW /bin/true | grep PROP > > GNU_PROPERTY 0x000338 0x0000000000000338 0x0000000000000338 0x000030 0x000030 R 0x8 > > > > -- > > Is there a way to check if this kmalloc actually cause perf regression? I don't have a good benchmark besides just an exec loop. But since this isn't reachable in a regular config, I'd rather keep things how there already are. -Kees -- Kees Cook