linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ardb@kernel.org>
To: linux-efi@vger.kernel.org, Ingo Molnar <mingo@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Cc: Ard Biesheuvel <ardb@kernel.org>,
	linux-kernel@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	Arvind Sankar <nivedita@alum.mit.edu>,
	Borislav Petkov <bp@suse.de>,
	Colin Ian King <colin.king@canonical.com>,
	Gary Lin <glin@suse.com>, Jiri Slaby <jslaby@suse.cz>,
	Sergey Shatunov <me@prok.pw>, Takashi Iwai <tiwai@suse.de>
Subject: [PATCH 7/9] efi/libstub/file: merge filename buffers to reduce stack usage
Date: Thu,  9 Apr 2020 15:04:32 +0200	[thread overview]
Message-ID: <20200409130434.6736-8-ardb@kernel.org> (raw)
In-Reply-To: <20200409130434.6736-1-ardb@kernel.org>

Arnd reports that commit

  9302c1bb8e47 ("efi/libstub: Rewrite file I/O routine")

reworks the file I/O routines in a way that triggers the following
warning:

  drivers/firmware/efi/libstub/file.c:240:1: warning: the frame size
            of 1200 bytes is larger than 1024 bytes [-Wframe-larger-than=]

We can work around this issue dropping an instance of efi_char16_t[256]
from the stack frame, and reusing the 'filename' field of the file info
struct that we use to obtain file information from EFI (which contains
the filename even though we already know it since we used it to open
the file in the first place)

Reported-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
---
 drivers/firmware/efi/libstub/file.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c
index d4c7e5f59d2c..ea66b1f16a79 100644
--- a/drivers/firmware/efi/libstub/file.c
+++ b/drivers/firmware/efi/libstub/file.c
@@ -29,30 +29,31 @@
  */
 #define EFI_READ_CHUNK_SIZE	SZ_1M
 
+struct finfo {
+	efi_file_info_t info;
+	efi_char16_t	filename[MAX_FILENAME_SIZE];
+};
+
 static efi_status_t efi_open_file(efi_file_protocol_t *volume,
-				  efi_char16_t *filename_16,
+				  struct finfo *fi,
 				  efi_file_protocol_t **handle,
 				  unsigned long *file_size)
 {
-	struct {
-		efi_file_info_t info;
-		efi_char16_t	filename[MAX_FILENAME_SIZE];
-	} finfo;
 	efi_guid_t info_guid = EFI_FILE_INFO_ID;
 	efi_file_protocol_t *fh;
 	unsigned long info_sz;
 	efi_status_t status;
 
-	status = volume->open(volume, &fh, filename_16, EFI_FILE_MODE_READ, 0);
+	status = volume->open(volume, &fh, fi->filename, EFI_FILE_MODE_READ, 0);
 	if (status != EFI_SUCCESS) {
 		pr_efi_err("Failed to open file: ");
-		efi_char16_printk(filename_16);
+		efi_char16_printk(fi->filename);
 		efi_printk("\n");
 		return status;
 	}
 
-	info_sz = sizeof(finfo);
-	status = fh->get_info(fh, &info_guid, &info_sz, &finfo);
+	info_sz = sizeof(struct finfo);
+	status = fh->get_info(fh, &info_guid, &info_sz, fi);
 	if (status != EFI_SUCCESS) {
 		pr_efi_err("Failed to get file info\n");
 		fh->close(fh);
@@ -60,7 +61,7 @@ static efi_status_t efi_open_file(efi_file_protocol_t *volume,
 	}
 
 	*handle = fh;
-	*file_size = finfo.info.file_size;
+	*file_size = fi->info.file_size;
 	return EFI_SUCCESS;
 }
 
@@ -146,13 +147,13 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
 
 	alloc_addr = alloc_size = 0;
 	do {
-		efi_char16_t filename[MAX_FILENAME_SIZE];
+		struct finfo fi;
 		unsigned long size;
 		void *addr;
 
 		offset = find_file_option(cmdline, cmdline_len,
 					  optstr, optstr_size,
-					  filename, ARRAY_SIZE(filename));
+					  fi.filename, ARRAY_SIZE(fi.filename));
 
 		if (!offset)
 			break;
@@ -166,7 +167,7 @@ static efi_status_t handle_cmdline_files(efi_loaded_image_t *image,
 				return status;
 		}
 
-		status = efi_open_file(volume, filename, &file, &size);
+		status = efi_open_file(volume, &fi, &file, &size);
 		if (status != EFI_SUCCESS)
 			goto err_close_volume;
 
-- 
2.17.1


  parent reply	other threads:[~2020-04-09 13:05 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-09 13:04 [GIT PULL 0/9] EFI fixes for v5.7-rc Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 1/9] efi/cper: Use scnprintf() for avoiding potential buffer overflow Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 2/9] efi/libstub/x86: remove redundant assignment to pointer hdr Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 3/9] efi/x86: Move efi stub globals from .bss to .data Ard Biesheuvel
2020-04-09 20:05   ` Brian Gerst
2020-04-09 20:53     ` Brian Gerst
2020-04-09 21:08       ` Arvind Sankar
2020-04-10  8:20         ` Ard Biesheuvel
2020-04-10 15:16           ` Arvind Sankar
2020-04-10 16:03             ` Ard Biesheuvel
2020-04-10 18:01               ` Arvind Sankar
2020-04-10 18:03                 ` Ard Biesheuvel
2020-04-10 19:03                   ` Arvind Sankar
2020-04-11  1:03                   ` Arvind Sankar
2020-04-09 13:04 ` [PATCH 4/9] efi/x86: Always relocate the kernel for EFI handover entry Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 5/9] efi/arm: Deal with ADR going out of range in efi_enter_kernel() Ard Biesheuvel
2020-04-14  8:20   ` [tip: efi/urgent] " tip-bot2 for Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 6/9] Documentation: efi/x86: clarify EFI handover protocol and its requirements Ard Biesheuvel
2020-04-14  8:20   ` [tip: efi/urgent] Documentation/x86, efi/x86: Clarify " tip-bot2 for Ard Biesheuvel
2020-04-09 13:04 ` Ard Biesheuvel [this message]
2020-04-14  8:20   ` [tip: efi/urgent] efi/libstub/file: Merge file name buffers to reduce stack usage tip-bot2 for Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 8/9] efi/x86: Fix the deletion of variables in mixed mode Ard Biesheuvel
2020-04-09 13:04 ` [PATCH 9/9] efi/x86: Don't remap text<->rodata gap read-only for " Ard Biesheuvel
2020-04-14  8:20   ` [tip: efi/urgent] " tip-bot2 for Ard Biesheuvel
2020-04-09 19:01 ` [GIT PULL 0/9] EFI fixes for v5.7-rc Theodore Y. Ts'o
2020-04-09 19:04   ` Ard Biesheuvel
2020-04-09 20:16     ` Theodore Y. Ts'o
2020-04-09 21:29       ` Ard Biesheuvel
2020-04-09 23:57         ` Theodore Y. Ts'o
2020-04-10  7:08           ` Ard Biesheuvel
2020-04-10 13:54             ` Dave Young
2020-04-11 19:43               ` Theodore Y. Ts'o
2020-04-12  3:51                 ` Dave Young
2020-04-13 14:07 ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200409130434.6736-8-ardb@kernel.org \
    --to=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=bp@suse.de \
    --cc=colin.king@canonical.com \
    --cc=glin@suse.com \
    --cc=jslaby@suse.cz \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=me@prok.pw \
    --cc=mingo@kernel.org \
    --cc=nivedita@alum.mit.edu \
    --cc=tglx@linutronix.de \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).