From patchwork Fri Nov 15 09:28:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 844003 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAB2D18D621 for ; Fri, 15 Nov 2024 09:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662930; cv=none; b=KMLjda+4/1WfA5uU+KzJyxfBWpGpMmVv2/VPXVceRLlUJQC8LJkeE1FRjvKIOXOBcK1vtW1z1LvwFy3P46gJWEN3lQIg2Her69IH7RskBlgmDKIfTM6BSQwYLEV+t+3lauC/GnEpPhyBLxVLKbG8YERkP6Pa9fWUfOQNoa/nHM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662930; c=relaxed/simple; bh=kc535yvtQ8g1YGBB755uXai2x9MS7VjnGufa4hgeq+A=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=pnsAVXkXBv8HrsZknNbTn0nXRECyajygnvLUYzjZCGDcAwlgLk9wSGnkYDpx2FABsP7U/zebHRJ574qpyy7c0kjwAHwiYGvQHZrRgzkyF4dB7XOZIWm8fBiL4E0wmVRFvueFUlMYvNTBXRxl7jVT6557UOrBwazpZsjPcsxXyOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=JwJtOI5F; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="JwJtOI5F" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4315afcae6cso9416785e9.0 for ; Fri, 15 Nov 2024 01:28:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731662927; x=1732267727; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=zz9UmlLzjNzpLfdxnis/31bCV6XLCMazL0Yp99pwAUo=; b=JwJtOI5Fi/1ElDFeSPywQXEnqmkUtgMkyO+wBixVic6kiy8Zj9tyJUdcOKGOpvagwh Mx8UXqZa8yeMVmbpaHolck9H/ilZ1naU5l8I4jE+Rx6o+Zyev5UYZGVCyiVlXxRBT7ia 389vzFXEW+qwV6onx5Y72uNXC/FMQ4eOUrF5h8ZXt78qYKIVNGqqHdqmon9zUaYwnl3f EJVCRzLeSy2j+LPfPilXIeds6CptyQi05OpZZQ40tobj4/SgrKdyY4S9IMD5b4hNiqMS kkQxFlBIkYSwop1UiD0lcoEDD9NFJmdeyCvpLVmwa8SMoGd4bZvw5JukG3VfNvBXOUbn ir7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731662927; x=1732267727; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zz9UmlLzjNzpLfdxnis/31bCV6XLCMazL0Yp99pwAUo=; b=JU+lfe9tM/h10kiR+6hZgIO5NKxwEA1Sh4VEYYf4p5jpMSTrTMx4R3mOOF0BcGk83D z6j5CTYGIqGOgyakK/Bblki8a2eRwE+fvTu96hSfGx8kaUym20K55pZpaezUwIHbitgP uXS6BOtuAUm898LEdVfoqtaQ56WVSQU6qxfT13tBAiJ5So4dietKHZVlcViFRvoUxQ4/ KWU5XHUAkI8ajzfg4Ud/wig1Yro+cgUseDr7Ra6Uan1yAeB+QjGfXv56btHg6IHK+353 xQBaWG/pnOBhWrzV0EgMvGIeAoaADzkeBk9FfNqtKNettCmCnNNUdyxYLUWXiCFHpXoM ce9w== X-Gm-Message-State: AOJu0Yz8/gpgltQLmd2kbOs/aO25Imuwmuo40e+NpkxqgCNxodSkUNCO FlXUJHd0J4CwRObE0Yq+JfU+QfF/BpUByACtgiAHPvjdQSexiOWIgIYQ82ekO4nhH4/npF1ZGjS fswoYoSx4Df1QzkjcshmzM8nRqY8Xvtm2FsSpl1gPRaaDaU1HEIPIIxsJln4RjdyZRnPUuM8AuF IX+0SXYwgHbA9vRH78oJCrqu+3cA== X-Google-Smtp-Source: AGHT+IFkqsRj1WhtZlgLtSK70EvwfJDpM706KIIaZu1twLJoTT7LSZ87HeighjrEDzrVhHsmiYFtp4hA X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a7b:c00c:0:b0:431:49b2:777d with SMTP id 5b1f17b1804b1-432df0305dfmr450095e9.3.1731662927059; Fri, 15 Nov 2024 01:28:47 -0800 (PST) Date: Fri, 15 Nov 2024 10:28:39 +0100 Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1031; i=ardb@kernel.org; h=from:subject; bh=xICokFLOYPGeGiDHADAdShtwtVonvWxpwP0PLJz03nY=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId1cxD09SFT7z+xtO5+IO/dLOh49Fe0wP890n+HuPafr/ vrwuxztKGVhEONgkBVTZBGY/ffdztMTpWqdZ8nCzGFlAhnCwMUpABNZq8rI8KOyoPzfMU+vOYvk N66foMNv+URS9v3UrV2/Ur78LtscpsTIMHnlrt36e4XNQwvXf1gUYRs0ZyHPRjnrKc+3LN61L+k /Bz8A X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241115092838.3080857-5-ardb+git@google.com> Subject: [PATCH 1/4] efi/libstub: Free correct pointer on failure From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Jonathan Marek , Ard Biesheuvel From: Ard Biesheuvel cmdline_ptr is an out parameter, which is not allocated by the function itself, and likely points into the caller's stack. cmdline refers to the pool allocation that should be freed when cleaning up after a failure, so pass this instead to free_pool(). Fixes: 42c8ea3dca09 ("efi: libstub: Factor out EFI stub entrypoint ...") Cc: Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index f09e277ba210..fc71dcab43e0 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -148,7 +148,7 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr) return EFI_SUCCESS; fail_free_cmdline: - efi_bs_call(free_pool, cmdline_ptr); + efi_bs_call(free_pool, cmdline); return status; } From patchwork Fri Nov 15 09:28:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 843613 Received: from mail-wm1-f74.google.com (mail-wm1-f74.google.com [209.85.128.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 64BBB18785D for ; Fri, 15 Nov 2024 09:28:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662935; cv=none; b=t+1XaJVMEp2mAsSp1AHLmxn4a54zJwvIml7Il1NtGJcz/d3BQjamAXoE8vW8DoIi8DTRDLqlD+Lxpp9E3/KrADNndpYfV/1PJAEfyVZE7sM8Ze+DH/fGpYY7uirqdEmThNSvG67vd1UUj42xIiromW6oqPZhODBt96uT3xrVaCU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662935; c=relaxed/simple; bh=90tPx57ecYokCX8TFKoiDt+c5cNgo6hbf2UHFyjECIo=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=QfOZPtAaAuv6OW4/ez/EVQOoCmBtbgFZgb+EKrXBGPWdqCtetSZRAth1rauQ7Eri8xP9RsJK1Tr8g1vIFuGYDCJ/h3FAvfNtrzOJ5Oa0sXyOQPowvkkz8BdCh/RJBfRCeTiKnEvOxisOEs3TY69Y+t9ILBAKOZvHGQvS0oGKHoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=jaa8fHs2; arc=none smtp.client-ip=209.85.128.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="jaa8fHs2" Received: by mail-wm1-f74.google.com with SMTP id 5b1f17b1804b1-4316e2dde9eso14643685e9.2 for ; Fri, 15 Nov 2024 01:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731662932; x=1732267732; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=KDr83wTkAKDBKCmJsAmga2K6mdI7ocsaso6pmKyg8Jw=; b=jaa8fHs2n9zk7VvyBd5Kc9wFfOMy4DpNpKHjKT3wOKqVi11AePM9AsieByEHEIVyiR ZWz7gS6JA3b0m+VnVhno8BiwLE5P1HByTm7ejm7jh1B031crGl35zPnOqcDw2pPNxYlN S27ZFzuIhDaQJq3GaWXe2qa0Uq4QWR6Z/GsepTa+6qxFDARbygBbPqQ0BNTdaXp7GhJ9 KR30vm/Q8ZFu3xBzyNAzeyM3RZXMTVmB5AlMrYOInFQm41+LROTcYKYtzKjOPjdFW0X0 YsVQ/WTqDyfsZIxkBsZc5nN18V3aYcz+itPAYqlmg93pb/0SUkQZFnvl/fikk/ciiO4F jUvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731662932; x=1732267732; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=KDr83wTkAKDBKCmJsAmga2K6mdI7ocsaso6pmKyg8Jw=; b=PwyzRpZXfpM+rWn8WsqS3k7cqABJJXc9D0MHza0xs86/Tw5zNDd+tG1nT9QbKHdg5N uBkljcw4Zh1VqqAReXKf6bGuAAfm3Zib/d2yMBoDatSRj7Zd184F/QrWeaIeVZ8aPHYX /kDDb4wTcla7vxtWQqJqzp0lCecahKtwZSf4xuzz3Wr6hisyJ/Y9CHPyBZOgXbP8c9Vd MxaQZPawDnUjhlE5ioi4vbgAeHz4L3B5EzhlOPQck+4XCV/dyNvA31VpbeDMvkPgezsu EdLyo8Hdyi6Q0rZyl5MGr2zq2x4pAHuC3iBDMlHWsRbaWvLjVip9Ktqb0rxQhA1PbXHC ehPQ== X-Gm-Message-State: AOJu0YzfahXKjICPz2bhOFLoRUKmjuDUKtugEzqDVQ+feViy5/ipMRBa gaO003y1o+gHBSvPYcJgxwqq5KF9UgfPxbaRNGGVf6ELCjzERpqtJ1Cb3jV+toQVStBWt6c1Jk0 PSNwUnTeGSLIyuUPCC/5mftE5mq9EW11Z9svaZ1TFsefnsGEHXbGuX9ZC5FjUBW1bvmhmTjsk0w 22nfPV6+ccbtN0fHrzPCoa02S5qw== X-Google-Smtp-Source: AGHT+IGDaaj7JD5P8b86+te4zrGMjd4Lv0gMV1VsaNlSXu8ljJ9nAUBwwlTHMbe6bV7/CfGtWpYhu/ej X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a7b:c34f:0:b0:42c:a585:5ec3 with SMTP id 5b1f17b1804b1-432df78aa15mr15775e9.4.1731662931569; Fri, 15 Nov 2024 01:28:51 -0800 (PST) Date: Fri, 15 Nov 2024 10:28:40 +0100 In-Reply-To: <20241115092838.3080857-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241115092838.3080857-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2038; i=ardb@kernel.org; h=from:subject; bh=Od9s2orxtV/zBkZhZ0hqQkiFfS0N/e9PjgNv2GVoxvg=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId1cxP3k11et0Ul1b/f/erAh4suVHQzGKm8D53/RqLe71 pva9XlxRykLgxgHg6yYIovA7L/vdp6eKFXrPEsWZg4rE8gQBi5OAZjIbkmGf3ZPY+1uHRJ4JPqp eeOq8yosi3Xb9FW3unv+zmjR37O51ZXhn9HrtsPVp1I1zn67XTfjyb8Du1s8nbZMWH4wvlSvzIm /hAsA X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241115092838.3080857-6-ardb+git@google.com> Subject: [PATCH 2/4] efi/libstub: Parse builtin command line after bootloader provided one From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Jonathan Marek , Ard Biesheuvel From: Ard Biesheuvel When CONFIG_CMDLINE_EXTEND is set, the core kernel command line handling logic appends CONFIG_CMDLINE to the bootloader provided command line. The EFI stub does the opposite, and parses the builtin one first. The usual behavior of command line options is that the last one takes precedence if it appears multiple times, unless there is a meaningful way to combine them. In either case, parsing the builtin command line first while the core kernel does it in the opposite order is likely to produce inconsistent results in such cases. Therefore, switch the order in the stub to match the core kernel. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/efi-stub.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/firmware/efi/libstub/efi-stub.c b/drivers/firmware/efi/libstub/efi-stub.c index fc71dcab43e0..382b54f40603 100644 --- a/drivers/firmware/efi/libstub/efi-stub.c +++ b/drivers/firmware/efi/libstub/efi-stub.c @@ -126,28 +126,25 @@ efi_status_t efi_handle_cmdline(efi_loaded_image_t *image, char **cmdline_ptr) return EFI_OUT_OF_RESOURCES; } + if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { + status = efi_parse_options(cmdline); + if (status != EFI_SUCCESS) + goto fail_free_cmdline; + } + if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) || IS_ENABLED(CONFIG_CMDLINE_FORCE) || cmdline[0] == 0) { status = efi_parse_options(CONFIG_CMDLINE); - if (status != EFI_SUCCESS) { - efi_err("Failed to parse options\n"); - goto fail_free_cmdline; - } - } - - if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) { - status = efi_parse_options(cmdline); - if (status != EFI_SUCCESS) { - efi_err("Failed to parse options\n"); + if (status != EFI_SUCCESS) goto fail_free_cmdline; - } } *cmdline_ptr = cmdline; return EFI_SUCCESS; fail_free_cmdline: + efi_err("Failed to parse options\n"); efi_bs_call(free_pool, cmdline); return status; } From patchwork Fri Nov 15 09:28:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 844002 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1431418F2DF for ; Fri, 15 Nov 2024 09:28:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662938; cv=none; b=EyySxOJE2v15ylgOiJJ/wGxUv7L6bZFybfa7Sv6pS48egfN017YheFsR4BYLfsgZsJqFjOTMpnYrShq09G5R+bEG/Stv2bgy3ID8LGuVHwpUFESzWpJ/PV8gMWlaGxyapY0tPtk6NVCwFe6rJBQRyItqu+ZSuoBHm3BsWEunAqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662938; c=relaxed/simple; bh=iQh/kUEx5mLTNivlK5u38x0gMayvSDZuosv34V9o22A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DMOIbfEqUFTwS1kAM30lSKpMs+3D4lhgtl2jGmSBFeP8lqLx78+M+usIzh9WYlZnxfc5ovEmwKOgzIv+Je3omLEFT36wYkTtQkaJ0PsyFBpnXGT1A8Md0kFfeOWUhU+w0L4e2SW2PdSykaVDw/MUy0V6GDPdDWdjIR/NUOEmYBI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R3J71PUY; arc=none smtp.client-ip=209.85.128.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R3J71PUY" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6e9d6636498so10224767b3.2 for ; Fri, 15 Nov 2024 01:28:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731662936; x=1732267736; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4sekui0Rzn6acjcPm+2mnR/RCVbfrAoOiui+n+xR7G8=; b=R3J71PUYuXmb4JrZBAnjfle5CEyveeJ1PCV0i+MYB62ePtL3a1tu13qkDC2AYEM1wJ ulMdR7tRqS2cVJIDrHXvGJZdS6smfVYMH/q7EyZTBEc4OYGAkYB172gWsKdswfaZ3wSa fAw5Q2v3UEJMr79V+Rn7PjcYbxJPTaUdLSng+ja+CaukuLdlESOzsRCm6HYrEFkUTE0p sh1ANCgrVhgLIYUs68PGzxbQ0PnrVy4fGIDjlnN+/2NTLqdaocGlf2KFLCa2eNtosOlT HEU7a6H0BZcrWS64g+wvtR54bBhoh4TVmeiQ99vKlDq3/f0BB+kBWJEuiQc7MgLRzBr2 9IFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731662936; x=1732267736; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4sekui0Rzn6acjcPm+2mnR/RCVbfrAoOiui+n+xR7G8=; b=mQKC8vDRbBjK7GA2//4b+2Xfpi2se1xO4CfPXokCGyCKW5jzu5y+Zt2pd4XW7xxlTi k6Z0gP95qFMdZYuJTVqtdRt2gWLgOC2dBwVplYK5NrV4Hq6txNw+t/7prWREz2lUCd9r pvaidpXO8g7WSPBrXON1A7yCog2hCtSyUbxrgjWIDw/KQPmlXnXgWSb4ik35oZGvcu5e nZnszuFZuWj2vcS2zPiEAMz0Zj1h7/YG6rY+geVwFHHWHydIlXoClXo3uYAYVdkJWLRN 34Xk0WOZQ087JCcUhpBlK3JWnEs1tzb2MqYt7EE/h2+csaMkOG0iWt/vLSiF3wNNAXLZ nYOw== X-Gm-Message-State: AOJu0Yz04wEqZkpK2utDca3p51D3SX53hSPwe1s02VReWvSKgOOoA48l 7soOsbPRdAJRDnsuNZxNqGccvNWXeiHrgKMNBDwjXe0/3kcpt/P2F0CdxcBuby5b90tQHhUrJ9g dc0pS9uEPgIrl3754/p4MxZzpLhFVXFLUsYW3fdkayixXSj19TQ3yRZyL4FpE1J/SFEcPvj8iLe enH39EqOmW4ebTGdTgh0BdcYnAYQ== X-Google-Smtp-Source: AGHT+IF1QR6EiyriCz7QfNcUAu7JlB3LRWeTdcwBx5hedakCcuzaCo13aunL9UYQldnFew+tpB3rm25X X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:a05:690c:6585:b0:6e2:371f:4aef with SMTP id 00721157ae682-6ee55c95c78mr564817b3.3.1731662936179; Fri, 15 Nov 2024 01:28:56 -0800 (PST) Date: Fri, 15 Nov 2024 10:28:41 +0100 In-Reply-To: <20241115092838.3080857-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241115092838.3080857-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=2448; i=ardb@kernel.org; h=from:subject; bh=HAIqdILGN1fACR5AG6BEqTRu8a6kaqqL140MqGyYquM=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId1cxMNJhc+De7rWljI5bz6XSJNzsx+F9WYzbpyeY2Izb UZUXXJHKQuDGAeDrJgii8Dsv+92np4oVes8SxZmDisTyBAGLk4BmIh8LCPD/VcT5EOWvmwKilj0 MmOhieKXqKoH8qkpthNnFz+3iFh1n5FhT92NDNfYc+k7zlVtq13ud1Tb5kn34c2XTLu/Rrv773n EAAA= X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241115092838.3080857-7-ardb+git@google.com> Subject: [PATCH 3/4] efi/libstub: Fix command line fallback handling when loading files From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Jonathan Marek , Ard Biesheuvel From: Ard Biesheuvel CONFIG_CMDLINE, when set, is supposed to serve either as a fallback when no command line is provided by the bootloader, or to be taken into account unconditionally, depending on the configured options. The initrd and dtb loader ignores CONFIG_CMDLINE in either case, and only takes the EFI firmware provided load options into account. This means that configuring the kernel with initrd= or dtb= on the built-in command line does not produce the expected result. Fix this by doing a separate pass over the built-in command line when dealing with initrd= or dtb= options. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/file.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c index d6a025df07dc..17bf25dccc07 100644 --- a/drivers/firmware/efi/libstub/file.c +++ b/drivers/firmware/efi/libstub/file.c @@ -189,6 +189,7 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image, unsigned long *load_addr, unsigned long *load_size) { + const bool ignore_load_options = false; const efi_char16_t *cmdline = efi_table_attr(image, load_options); u32 cmdline_len = efi_table_attr(image, load_options_size); unsigned long efi_chunk_size = ULONG_MAX; @@ -197,6 +198,7 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image, unsigned long alloc_addr; unsigned long alloc_size; efi_status_t status; + bool twopass; int offset; if (!load_addr || !load_size) @@ -209,6 +211,21 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image, efi_chunk_size = EFI_READ_CHUNK_SIZE; alloc_addr = alloc_size = 0; + + if (!ignore_load_options && cmdline_len > 0) { + twopass = IS_ENABLED(CONFIG_CMDLINE_BOOL) || + IS_ENABLED(CONFIG_CMDLINE_EXTEND); + } else { +do_builtin: +#ifdef CONFIG_CMDLINE + static const efi_char16_t builtin_cmdline[] = L"" CONFIG_CMDLINE; + + cmdline = builtin_cmdline; + cmdline_len = ARRAY_SIZE(builtin_cmdline) - 1; +#endif + twopass = false; + } + do { struct finfo fi; unsigned long size; @@ -290,6 +307,9 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image, efi_call_proto(volume, close); } while (offset > 0); + if (twopass) + goto do_builtin; + *load_addr = alloc_addr; *load_size = alloc_size; From patchwork Fri Nov 15 09:28:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 843612 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A8CA18D621 for ; Fri, 15 Nov 2024 09:29:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662945; cv=none; b=uQW9Lbf9BIghaBvN91R7Pul8JspaCyyspbHwWT/xG7vM3GLSlS3BK+vc7a+ktVpdsOdlJPhbWOZPyiO1swXEJNZTVG1LjZfeLJ+gOTj+IAs7EF98UbXpcJ0yxAOvsb+75Cqz5ex15F34NRcqVQOUHrxsJBCHQbmxrfuQGjnEHNQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731662945; c=relaxed/simple; bh=bxKNKy+x/UttdmJzS38zLgxiwsrmMRUitTbKK744Gs8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=JCJW9eTex9Wu8xGZH9DkyIBke/pRp1SGCCKrju0Sha/4WWGhPivyLu0es/UHMmGXSMcxvixQHza2MfEYu3XX0YPD88LiYmZXQCyXAEFwZ8cacQ+g0Z1v8Yapa7lHZeIw8UHXCbdeIU2wttqY8GDlWVLH7iDpRIQ6sIGKOyoPIvE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=zEwVNLBN; arc=none smtp.client-ip=209.85.221.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--ardb.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="zEwVNLBN" Received: by mail-wr1-f74.google.com with SMTP id ffacd0b85a97d-37d4854fa0eso1018318f8f.2 for ; Fri, 15 Nov 2024 01:29:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1731662941; x=1732267741; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I36NvbzpYB+4pn0OOA4a7gl5c6PkC9vkt88/N2JLADs=; b=zEwVNLBNHZAFPC/jkdf7j1awAO+rzSbrS6Gf2VzyGqk4fN/RzifXlpvlPTDT9AiUoF Nmf9i18+aa1TVFp+LBkzrlNmDK4Ck9rs4P487EbmNdeEkVhbcctxX60NixbjeoB7vaL5 Wtsqi9ZspwvyxOZ6N6s29puKOXSWobgjjwbIbQM86J++CFlutOHB14hPRzXQ/WU1Ravi icxHa7qp7/9M/xl0H/MM17vtL/Amm2LhjCrGmzQckPthaLT+patJY5qIUmjZpeFBQfWU cXIAFGkjy63xMl27ECWZs3bAvUY4Ou8iCSHyE/VtYPTtmjr4nMpZ4XV2X3MFip+ylHQ2 rvmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731662941; x=1732267741; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I36NvbzpYB+4pn0OOA4a7gl5c6PkC9vkt88/N2JLADs=; b=ZX0kYKD+4ZIcHPl/r5y6i/4iijQLtR5QprrACLqQiFAbWgJ6eZWcScOSoR1LSSu/DV l/zUXAnbA2Wlw+4mo8hmTg2JrSCx9NKpmgQge9vyfMQN31qqxQOYoSzZnJth55JGeo+d mWDpDIIioq8pOklpdRt8YnlPwkOv+6dH55hZ0X7x/Tvty+u6HU3GNh8liHNHxAjZWKKa d56xrEZC2rEH0BUPHzHZEOe+ORq+TYyPlXv1s0Kh598RchKB/in4aTKbyvZeS2XUkPmz yNDmJhGADRl6XcoO/OVMi3PPGGS7R/CiaZeat/Z6GAy1/3PHTipvcL1b3NmTjiJJL3TG +epA== X-Gm-Message-State: AOJu0YzsfDPC7gk47UEC0OKeccdrNNhi2H+RIsqfa62nBXfKS2MYeJOj Uv0GbGgIoCDaYQZrxlVHnqlT6AkFMJ66hAYdYcnRBYdEInEPEo/vndmi4KXCvwaMVVbB2pDWgD2 iWpAQLoIli/MLTEXByANBP+uPrrn/MQMtLXX0PcTb1L4NTjLk1a/dXsmVu8TjdNm34ekWWHYlyN aFKaxICvqhDT/g7gSqBNmp5n32tA== X-Google-Smtp-Source: AGHT+IFW94hI0wAgH+GxHjCI2992OY8jthRU/+UgjaKYnoMoS+FMVWXTQDhPRG2RH3idUV1/V4tbLgPt X-Received: from palermo.c.googlers.com ([fda3:e722:ac3:cc00:7b:198d:ac11:8138]) (user=ardb job=sendgmr) by 2002:adf:ef50:0:b0:37d:45dd:dfbf with SMTP id ffacd0b85a97d-3822590612fmr1319f8f.4.1731662940947; Fri, 15 Nov 2024 01:29:00 -0800 (PST) Date: Fri, 15 Nov 2024 10:28:42 +0100 In-Reply-To: <20241115092838.3080857-5-ardb+git@google.com> Precedence: bulk X-Mailing-List: linux-efi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241115092838.3080857-5-ardb+git@google.com> X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-Developer-Signature: v=1; a=openpgp-sha256; l=1204; i=ardb@kernel.org; h=from:subject; bh=XMY0HDGBMeYwkWGjATAWo9goi0Uyg1ks4hbjHQr6n/I=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JId1cxHPNfcUmbcv4bqaIRslVK3alLjmUw6ibvM6loPzdl 6Da2EsdpSwMYhwMsmKKLAKz/77beXqiVK3zLFmYOaxMIEMYuDgFYCLXjzP8U1xuIdLy4ZmQWpZ1 78aN/+Pt8lh//3ncHlt408V7u5Hwb0aGXw+3z5SQFuVuvarFqXrdrl9i7Qlu3/XdaqvOKul+ztj EDQA= X-Mailer: git-send-email 2.47.0.338.g60cca15819-goog Message-ID: <20241115092838.3080857-8-ardb+git@google.com> Subject: [PATCH 4/4] efi/libstub: Take command line overrides into account for loaded files From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: Jonathan Marek , Ard Biesheuvel From: Ard Biesheuvel When CONFIG_CMDLINE_OVERRIDE or CONFIG_CMDLINE_FORCE are configured, the command line provided by the boot stack should be ignored, and only the built-in command line should be taken into account. Add the required handling of this when dealing with initrd= or dtb= command line options in the EFI stub. Signed-off-by: Ard Biesheuvel --- drivers/firmware/efi/libstub/file.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/efi/libstub/file.c b/drivers/firmware/efi/libstub/file.c index 17bf25dccc07..0e41b88238b1 100644 --- a/drivers/firmware/efi/libstub/file.c +++ b/drivers/firmware/efi/libstub/file.c @@ -189,7 +189,8 @@ efi_status_t handle_cmdline_files(efi_loaded_image_t *image, unsigned long *load_addr, unsigned long *load_size) { - const bool ignore_load_options = false; + const bool ignore_load_options = IS_ENABLED(CONFIG_CMDLINE_OVERRIDE) || + IS_ENABLED(CONFIG_CMDLINE_FORCE); const efi_char16_t *cmdline = efi_table_attr(image, load_options); u32 cmdline_len = efi_table_attr(image, load_options_size); unsigned long efi_chunk_size = ULONG_MAX;