From patchwork Wed Dec 13 09:00:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 177822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp7637345dys; Wed, 13 Dec 2023 01:00:44 -0800 (PST) X-Google-Smtp-Source: AGHT+IHLj0q6K5AgVWFT8ea2l/OiMt+EBSqkUcwzijPItJ0K6pqbqzr2naFwWqemTjS9E0Wk2YqB X-Received: by 2002:a05:6808:3190:b0:3ba:1287:f3dd with SMTP id cd16-20020a056808319000b003ba1287f3ddmr5776079oib.96.1702458044114; Wed, 13 Dec 2023 01:00:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702458044; cv=none; d=google.com; s=arc-20160816; b=uQQI2MyggmFbdOgy+uw8JWicDYeQO4ThLs91x4qxWuAMFEZB3zN10vVKpXTyD5nC9y SBoVMws1JK1b9sEvT/iELstPI2pvpiZ6rXaePHoXUMyOapDnqdj0BJ2c+kC3Ayfq7aJa /yfJhK4DeMHOgJofLSyLPojunYS0N2fqbsEQPBOq5OY06NaXai48+o2IAOGJLKq4sID5 BrRUt4n0jYnj3KbXetWk5ZdaVMfvg6asYZWtxHcZGBbY8yTvQT5OfpVIgoBbZ3pHP9GE Tto/3Ww0kXC6TwlIIid9Jgl5vFTUBXaacfM78XWuBmjLZ6k38BtjYHSatVd+G/IxMPnO Wddw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=U8cMDMa9YzBN4szcfl7doDUw5H0mUyUxaKMbJZAX8m0=; fh=reEjKSE5iVnrFj98TKNAuQQUub1faruVorHVuExVO+4=; b=NI8rVuZo+QCxS8q5ooWTO9/tTx1LgXeg9PbK1qiAzySVclt7p/R5p97T0RhdioGCTo LCoEVJMcSrty1+xd6m3Pn8HSrbhWsv3P8t8jkFANOAg1uup+AB9YTR7dxFDA8VV3jThe wyeaEHr6Eb8kTT46lnXYhOuWAqRCXcMCpXrPv+IsnyH6lQesTy93cYhZ47EPLxxbHsKQ kntSTFWoC7vOntN4LHhy/gj26SxbwPRT5UzsKd/JP4/YpalFJb82k78eqBKl3hz20rbm r3/CQwh+RC23ZmaUrD95D8ygdbD36nsjVYzIgL7+Gd8oVpf6MMNSmlGp5LZ18grQhwDD XjtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QRMKY1Cj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id g5-20020a636b05000000b005c685a1b3b4si9085975pgc.347.2023.12.13.01.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 01:00:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QRMKY1Cj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 0A76280732BE; Wed, 13 Dec 2023 01:00:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232125AbjLMJAS (ORCPT + 99 others); Wed, 13 Dec 2023 04:00:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjLMJAP (ORCPT ); Wed, 13 Dec 2023 04:00:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D736AD for ; Wed, 13 Dec 2023 01:00:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71122C433C9; Wed, 13 Dec 2023 09:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702458021; bh=KYg70uTTMCVbbybOUe4N/VTYl2TBfccDvrHX9QOYSpI=; h=From:To:Cc:Subject:Date:From; b=QRMKY1CjqdvbZ0fbr2tBAwGIzwJ4uuPaNCuYkelu9eHILPcC0WvZTScIzOI0dNK6V p1zR4KyknBgnnd5nC0szCG01DrkV10nVXhXEHNpRgKjg6a7oiP96Z57Ac5xlStWol6 NVYSF2Rjf0QHrI7WipJ/iT1qYwm5S7kVASmGKI9t0uZifTt31XCU1DFiWWkMMO6pBo un3hUZCgfnLgjKqP9Bhj6on6scYXyuwRyLSPZKGkH7na7rgPBgSx7s4aeZUv65A7kH eJgltZHbSlNr5p2rGIBgU9stsuQBnnQXq21MW1fKdlqy4KK3mgRuurRBFCKEoqMB66 f/f8r09VGOqxQ== From: Arnd Bergmann To: Alexander Viro , Christian Brauner Cc: Arnd Bergmann , Jan Kara , Ian Kent , Miklos Szeredi , "Seth Forshee (DigitalOcean)" , Dave Chinner , Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] statmount: reduce runtime stack usage Date: Wed, 13 Dec 2023 10:00:03 +0100 Message-Id: <20231213090015.518044-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 13 Dec 2023 01:00:28 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785156646267287544 X-GMAIL-MSGID: 1785156646267287544 From: Arnd Bergmann prepare_kstatmount() constructs a copy of 'struct kstatmount' on the stack and copies it into the local variable on the stack of its caller. Because of the size of this structure, this ends up overflowing the limit for a single function's stack frame when prepare_kstatmount() gets inlined and both copies are on the same frame without the compiler being able to collapse them into one: fs/namespace.c:4995:1: error: stack frame size (1536) exceeds limit (1024) in '__se_sys_statmount' [-Werror,-Wframe-larger-than] 4995 | SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req, Replace the assignment with an in-place memset() plus assignment that should always be more efficient for both stack usage and runtime cost. Fixes: 49889374ab92 ("statmount: simplify string option retrieval") Signed-off-by: Arnd Bergmann Reviewed-by: Ian Kent --- fs/namespace.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/fs/namespace.c b/fs/namespace.c index d036196f949c..159f1df379fc 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4957,15 +4957,12 @@ static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, if (!access_ok(buf, bufsize)) return -EFAULT; - *ks = (struct kstatmount){ - .mask = kreq->param, - .buf = buf, - .bufsize = bufsize, - .seq = { - .size = seq_size, - .buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT), - }, - }; + memset(ks, 0, sizeof(*ks)); + ks->mask = kreq->param; + ks->buf = buf; + ks->bufsize = bufsize; + ks->seq.size = seq_size; + ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT); if (!ks->seq.buf) return -ENOMEM; return 0;