From patchwork Sat Sep 30 02:15:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 13404894 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2FED6E7734D for ; Sat, 30 Sep 2023 02:17:38 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qmPWN-0000G5-7P; Fri, 29 Sep 2023 22:15:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qmPWB-0000C0-3l for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:43 -0400 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qmPW3-0001yh-Eq for qemu-devel@nongnu.org; Fri, 29 Sep 2023 22:15:42 -0400 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-57d086365f7so3244352eaf.0 for ; Fri, 29 Sep 2023 19:15:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696040133; x=1696644933; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=lTSXnstiUUa+YvcwiwLyH46SpdnYn0WvLHWje1DuMdehoHYom+kmGWkyoh6uNtySPn fP1/gwZddyqQkR6lwntvXyL4IGpQvUxECTifiA8yLViA5iAsmhqSOBh8kEqcKEtwkzix Baj0PV469geaN6p49h9drlc4kpLQ63yLD4oyBnjO+GpEm7ckgbbm8ySXYNvUS9d9sRrw NECr0yKqM/N9lgyHlz8ZL2O7iz22WpXvFVeVIpfBBRY/O0rJRqdJ9wQgBmA563dSGO9e 93Q26vlExSNehRz+bi/uhp20YTOuQ79dX5Zq6SkWHtCBWbJDl48H+t/VsafCHfUmLV8E OWWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696040133; x=1696644933; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RLZnYG6gB4JjRwsSZMPasIhTWijR/jDuID0FZ6WSuAE=; b=NzcujD7FTO36+F/IC5DFrWq43ZTrzOsnQ67oWQDqyYXn3domD9YNpvzLf/yfajMMoE YS7yiQRof5Du7klYtTs1UkHPYTAS2PCE/2yfPKqrdZJ+us3JqAXJ3HB0X1WQBYjpoFz9 mjP05LgujFblbJuSXuev2+M0yPJQS/q9mIrMR9kchNDWb+adfuAN5Z/k5CSk+DubmScy PunuTmJ0jqzCxkYIRUmeYCoBjEL18t7xcZR1xdaPDUUKWEq/H7P+eemXMtR63K3YZckg at1AcC4jI8cM/WUtLoM/lOWN3qAZRnU+wgq1Lf2cHAlTmEP3ipDPR3izifrS6N+A5aQl 5+sA== X-Gm-Message-State: AOJu0YwtaJeqsBbAzzOvxkiR+jL06JMgR2rbzmFgmKBpBVvncs47Ez3P FI6o239bJViaDudOpitv56d8AKGDB9x2n9fu8+o= X-Google-Smtp-Source: AGHT+IHpnivAN1sZtQWvydxBfqBw13rbL3KhqE5D9hyt9FmRFisq0XW7BTUta9zXZ3xabyMYTXAfWg== X-Received: by 2002:a05:6358:7e49:b0:142:dfc2:a441 with SMTP id p9-20020a0563587e4900b00142dfc2a441mr6732370rwm.8.1696040133172; Fri, 29 Sep 2023 19:15:33 -0700 (PDT) Received: from stoup.. ([71.212.149.95]) by smtp.gmail.com with ESMTPSA id fv21-20020a17090b0e9500b002775281b9easm2130692pjb.50.2023.09.29.19.15.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 19:15:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: alex.bennee@linaro.org, laurent@vivier.eu, =?utf-8?q?Philippe_Mathieu-Da?= =?utf-8?q?ud=C3=A9?= Subject: [PATCH v6 02/19] linux-user: Tidy loader_exec Date: Fri, 29 Sep 2023 19:15:12 -0700 Message-Id: <20230930021529.987950-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230930021529.987950-1-richard.henderson@linaro.org> References: <20230930021529.987950-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::c30; envelope-from=richard.henderson@linaro.org; helo=mail-oo1-xc30.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Reviewed-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3536dd8104..5b7e9ab983 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -154,31 +154,31 @@ int loader_exec(int fdexec, const char *filename, char **argv, char **envp, retval = prepare_binprm(bprm); - if (retval >= 0) { - if (bprm->buf[0] == 0x7f - && bprm->buf[1] == 'E' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'F') { - retval = load_elf_binary(bprm, infop); -#if defined(TARGET_HAS_BFLT) - } else if (bprm->buf[0] == 'b' - && bprm->buf[1] == 'F' - && bprm->buf[2] == 'L' - && bprm->buf[3] == 'T') { - retval = load_flt_binary(bprm, infop); -#endif - } else { - return -ENOEXEC; - } + if (retval < 4) { + return -ENOEXEC; } - - if (retval >= 0) { - /* success. Initialize important registers */ - do_init_thread(regs, infop); + if (bprm->buf[0] == 0x7f + && bprm->buf[1] == 'E' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'F') { + retval = load_elf_binary(bprm, infop); +#if defined(TARGET_HAS_BFLT) + } else if (bprm->buf[0] == 'b' + && bprm->buf[1] == 'F' + && bprm->buf[2] == 'L' + && bprm->buf[3] == 'T') { + retval = load_flt_binary(bprm, infop); +#endif + } else { + return -ENOEXEC; + } + if (retval < 0) { return retval; } - return retval; + /* Success. Initialize important registers. */ + do_init_thread(regs, infop); + return 0; } bool imgsrc_read(void *dst, off_t offset, size_t len,