From mboxrd@z Thu Jan 1 00:00:00 1970 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 70381C7EE29 for ; Wed, 7 Jun 2023 23:38:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A28F98E0001; Wed, 7 Jun 2023 19:37:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9D99E6B0074; Wed, 7 Jun 2023 19:37:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8A20F8E0001; Wed, 7 Jun 2023 19:37:59 -0400 (EDT) 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 7D09F6B0072 for ; Wed, 7 Jun 2023 19:37:59 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 3D23B803F0 for ; Wed, 7 Jun 2023 23:37:59 +0000 (UTC) X-FDA: 80877567078.21.166DC39 Received: from mail-pf1-f172.google.com (mail-pf1-f172.google.com [209.85.210.172]) by imf24.hostedemail.com (Postfix) with ESMTP id 51CDF18000B for ; Wed, 7 Jun 2023 23:37:57 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=lV8syWtj; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf24.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.172 as permitted sender) smtp.mailfrom=keescook@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1686181077; a=rsa-sha256; cv=none; b=0C41ZqgmBaxdZuuhyFIwlGYHqPOh3A8aguYfJ/Y1ohEaX1kSMnJik44legflu5o5MBCXOt HYxj6w1DLMEDscUkqBP7684oWpphhpb31qGW7zyCviwPk/8cnGN3ltIbhCkuYLgSnMqUye TTsIqmDuB+RK4V3TYkwxfs1ua3H4QDk= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=lV8syWtj; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf24.hostedemail.com: domain of keescook@chromium.org designates 209.85.210.172 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=1686181077; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=q85ALpObps5sc/UCVblmdlmcE0aIZmHRuMxmvi7ZvV4=; b=0ZEweDgL0xAbBYQdrlvHFuiIs2KWesFSFfzrvdEe6WJNqCafTO2yfntANVmjTSpIUpv0YK oOMZZc2T6QKXqLDerljox8KIiRm9bwPvs2rkPL2C2MZZT4eyDOy2NizbsFLPR15BSDqPMg CaCM4xprjkudyY5FkCe0ypLd1HuhNHQ= Received: by mail-pf1-f172.google.com with SMTP id d2e1a72fcca58-65311774e52so3288966b3a.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=REsZF73KvjdnugzrbP5/tF0+T+4GzaPp28jeiTkBXfL+D8n91et4/Byq039B+UVZeC 6yJDz98ZBJtI4EfjOTO3ccGRq4Si0/q0dPwfuY0K7YziTY6u5EJ1tKwUptiFvSfEknf3 3pU//TYlUL/Y8jgZeJM3O6kOy5CbNFdsX1laXhSd/5aaMUWyf2iL3r4ivx48xrJPnIMG 7SPa/uX0Kp2enX1mm3he5mNXhL6A8Yb5h4t+1Ts+1870eK2sMk3PeO0RZ/+6uHvPRl7y pAR/5DndcqERkNkycU/d1csKddMbrgEpF2xhfFNejogfFXIyezy+dgZBkZUi7DzIDLli qIdg== X-Gm-Message-State: AC+VfDwJhlbckpx5GKFUbM/YHsa5+FUhxiC3TOt1VynpTDhG3efUC76k bJz4X3M1lEI5GeqX663Vnifk7w== X-Google-Smtp-Source: ACHHUZ6ZXC7p4DKrsltkZH4GRsEhK/UFVuZ7UJv1bOQaR6JO3aYQPtnsPqCAKXnWT3JJJ9X0TBo+zA== 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-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 51CDF18000B X-Stat-Signature: oyhrd8fwarr4cuhsr1kh388ko81nmk9i X-HE-Tag: 1686181077-498477 X-HE-Meta: U2FsdGVkX1/NvEm8KuwstcrxVEZu4ACsZjDA4oXY6Bbp9MSFMtPDZ4pWwO5QJ+k2FbKNT5AfzOBDImPp6z9VUCCzeq+k6KXAMG18j5xpLQytlPdTQ+qRGjUfv2SGYUBkSlDrfNH2qZGGGp72nembTXTNoAeB0kEahArzHgFmcoiuTD5AlaZj8LNSo5n1D3zwOUlksanJIcjmobhdAT30IU35DUvxTsD4Cret5wLjgSqvZaPW6NI7JcA9UyLnegxW+gSl4w+cIe9pwZfmLyNgUEmBxeJcZYLptWPhaWWiaFDwRZC10hkQ8DKxnWQlFJ3v3dAaQjp+qWRh/G6B1ZtwawhlNBx0rH/JLQTwyssZJCE01J+7WVvufNK1d4z2tAgErU1cjPCsN6o+O+1Jm/PW5Ilh8JMBja9IIt0GtkvJi/KIxcw21b5PXFyGQpIwFm/6ymQTHf4hSC7nxUuV7Z2xpENepGrOVOQBgvZYGjN1fwUTvvOs+2VQC58guCItVdAtIu+mzj87gc9a+hjH4VggvWBbMWeuEaCuU1myjhVeYJQV/rPYlCDDpbwBh579sBylH6sBC9wGpqGcdhPpAxMpMQHpX0c6h4E2l0bHFOvMNnz60NlBNnp6DpEImvSb94aOQC0tLCEWeC4FQIlD+JLzvmKyo852h+f+QoTeqMaaMUQ2oNXMrospF+p2R2//H3e+xeh1VahiNyJCCDdp3gJyqLa68cNDYPyjJG5+/oCfeS34PUS1Ob5Dh/2S8S/ImOAhYwL9Lo+TUOHGx5sSx4JtSy2+JeiTe+1/A/fAm1Bx/C8HUAP6xClz4LpGjzieOCxI0oRSkP1kCMpFlV5vYmFbJVNxcoG16g96xvRWCyaWk5fF8Rjx8ZONKqz0M3TGj14zVR5UKO/RntuOQd1f+2+M+ri3CtpqDc+T7+z/65Dul41jHctQ4wCwrnu1ORYSoMTGO+4zFxu/w9X05hgNtQ5 myT0nGiq /N2sAqSUU5L6LlFH8Lfq7ROfajavpvE8gl+ZpYIuLWG9cF64YUBmMPdPLTfDMeN1RLHHMVtYWz8PCu7bwXJWmnSQAjPNFwESEARyxCD9LXXM0ItxPjdfEQaDq5wEYE/b4ofRNvwatgtc4RQA7sw7cwSHZj9eUiG7ag30r1JVbfuDA9MWv0x1eX2sR7nFOYftl/NsdcIBYFr/phsFBt/1J1dibM3qkuJ2v9rllcu6JTIK1rtOEXH/3EaY4/bw/uW2wYVnyW2EcZo1YtHied3FJmMCKtWTpysRd80rREm/X9NY+/5iIIMLZdQJXa3Sy4B+LnDmmjurgkCzmpQ/nvI+m4lY1w30YZsQVNK2b1EkVT0NJk13sO+fQBRov8uudWsgoj15eiywG+x+eJWCarISXURPvlw== 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: 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