From patchwork Sat Jun 19 03:43:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 463853 Delivered-To: patch@linaro.org Received: by 2002:a05:6638:102:0:0:0:0 with SMTP id x2csp533722jao; Fri, 18 Jun 2021 20:46:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzw1IATOVaaRo53ks6OwEpxTUxKnFdTSn6nqDQex2wIPkjJtm2S4XTJI/UKlooTFqqCDKMw X-Received: by 2002:a05:6e02:dc8:: with SMTP id l8mr9332790ilj.286.1624074404402; Fri, 18 Jun 2021 20:46:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624074404; cv=none; d=google.com; s=arc-20160816; b=K5/AHOwo3PtCnUcegoxqyFY1I6SkgSgwUlzf6Urvtw01UJEcALe7jTFAzGtnqIkfK6 nzrkGWSojc94iSkiA/dNh2MHfEb+jaAHVtFTDo1K/XL8PbB5l3F/9wlpVbfd2Sc9cReJ JQ6T9ZDioPB1Rp2fKrm2IpKVob8admOuD05SixPqrfitCVwk/XuGvZJXfWNOD0YavGuV kWkP7ChTsmNtzg4HlnUkCM+2hlSvnBA5Ql+BH32M9pgv6fY2YCl27/7FfMQY/XrQPmYj Ow+qCVSiMKRMC/qTWMU6Jid81PPDyut1uGE/cc4MKz9VDJ+uy5snPQ2J2kxfd0/KZxtz aIpQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=QrbeKgDr0Qimf/fLTiNrPtuYBtEMwhitINuZ4xKKmc01jdr4naWyuQYc14LzwgqkeC 0P39Ulxh7HmbCEhiUFL3oiSGrtGivYvahga23egACdg2hBrqk7yUudeKsrjN+hasIfuc Ltfd7OQ3KT2YZzJBE6kSPVXkLBxAVX66+q1Yv5Si/mcJwAphZPlLXVih08Hfu/KiEAcg sIJ8UhWij+GUAC45Ya8yo5NR4IJbIOVtQbLK3BpMDrR5UXcHtEe36ZHQA5j26zAJM0FR uvzshgof2jfvCu0uzb3MWvgCZx2QJDLUxGRcvDkdzv3I4ccTdE5bjSh46pslHQ9C0XxH Qfcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B7DgDyNs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g10si10173279iok.45.2021.06.18.20.46.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 18 Jun 2021 20:46:44 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=B7DgDyNs; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1luRwR-0005nE-Pp for patch@linaro.org; Fri, 18 Jun 2021 23:46:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33066) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1luRtW-00008S-J8 for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:42 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:44608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1luRtN-00081L-QD for qemu-devel@nongnu.org; Fri, 18 Jun 2021 23:43:42 -0400 Received: by mail-pl1-x62c.google.com with SMTP id x22so4133218pll.11 for ; Fri, 18 Jun 2021 20:43:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=B7DgDyNsPlzK/y/kHNSUjiAzoQ+BvbREj7iI3LOJH8DD5nkMFIa3ehRtPeedKUMFjH Iigd7J7UxHGzekuObvChgosi/3s7KeLKnPYmpP+F1+SlnIbIe+USHiKhGvN2nh4qTnHH 0fa8kNUf5r3Ib3QjcYj8w3FPmLsuL1zRZhwQLXibnXRDkvc8p1DUfZGKiq0xhqTZ7BDV UjlXAlBTF657xmCpupqVrnzuW1Gl/Ai4aM+coDhwuIY0aT60S9eRtbyQ/DcDc/aUIoD5 nBWe0NJ7G5onuyx36v6v57MVme+2dRzbQilWaLHpggWxhRzmJGvvgAB6I+KAP3Wq+02U US1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6XhZDg9Govvz9gc3VGnWdnVC8clvh9XH69vOvHyBLl0=; b=enxD4EweCsRrlzL4U/nzG/vB63CaBoY0n10C2rT6Rq8unowXNvl3uuW+u9kTCl+bGC Y51YE9BiXnhczCrdfJkfyfdo1AbLMDQOOdABdmdBP9SdVG1NklBvNsi7fXJ26m0EkEAX kelKT7Am4FK1KXIbmR0ANmfsIAv3kOCet8N0OKyb0DO1QB1XueoygMp/Ot4KQjsDKMdp pqlxtvGmNkJn6k8YhqZwuVEODMS5A684Yg1fxAiPX5YHAs5AVaWGx09VIoke8UH8Igvr AXMJAJ8802JFIZzd2sMklEySuKHM3u5AnZIXRTopsPBjYCov3LkxdpXwESgU2jAOqPrZ tvBQ== X-Gm-Message-State: AOAM530pex/2BnZM5w+h44VgW9YMLAjgugzJBmM1R2qv3SH/u8tcmXRt kCNbXu8/EWLSIUyBH+u9HrevpwA8SmhHcA== X-Received: by 2002:a17:90a:31c4:: with SMTP id j4mr25823220pjf.105.1624074212535; Fri, 18 Jun 2021 20:43:32 -0700 (PDT) Received: from localhost.localdomain ([71.212.149.176]) by smtp.gmail.com with ESMTPSA id z6sm10045154pgs.24.2021.06.18.20.43.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Jun 2021 20:43:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 03/12] linux-user: Tidy loader_exec Date: Fri, 18 Jun 2021 20:43:20 -0700 Message-Id: <20210619034329.532318-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210619034329.532318-1-richard.henderson@linaro.org> References: <20210619034329.532318-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alex.bennee@linaro.org, laurent@vivier.eu Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Reorg the if cases to reduce indentation. Test for 4 bytes in the file before checking the signatures. Signed-off-by: Richard Henderson --- linux-user/linuxload.c | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) -- 2.25.1 diff --git a/linux-user/linuxload.c b/linux-user/linuxload.c index 3b0bafc490..8b93b9704c 100644 --- a/linux-user/linuxload.c +++ b/linux-user/linuxload.c @@ -143,31 +143,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,